idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
11,300
|
protected function checkUserClass ( ) { $ userClass = $ this -> userClass ; if ( ! class_exists ( $ userClass ) ) { throw new Exception ( 'User Class Invalid.' ) ; } if ( ! ( ( new $ userClass ( ) ) instanceof User ) ) { throw new Exception ( 'User Class(' . $ userClass . ') does not inherited from `\rhosocial\user\User`.' ) ; } return $ userClass ; }
|
Check and get valid User .
|
11,301
|
protected function getUser ( $ user ) { $ userClass = $ this -> checkUserClass ( ) ; if ( is_numeric ( $ user ) ) { $ user = $ userClass :: find ( ) -> id ( $ user ) -> one ( ) ; } elseif ( is_string ( $ user ) && strlen ( $ user ) ) { $ user = $ userClass :: find ( ) -> guid ( $ user ) -> one ( ) ; } if ( ! $ user || $ user -> getIsNewRecord ( ) ) { throw new Exception ( 'User Not Registered.' ) ; } return $ user ; }
|
Get user from database .
|
11,302
|
public function actionRegister ( $ password , $ nickname = null , $ firstName = null , $ lastName = null ) { $ userClass = $ this -> checkUserClass ( ) ; $ user = new $ userClass ( [ 'password' => $ password ] ) ; $ profile = $ user -> createProfile ( [ 'nickname' => $ nickname , 'first_name' => $ firstName , 'last_name' => $ lastName , ] ) ; try { is_null ( $ profile ) ? $ user -> register ( ) : $ user -> register ( [ $ profile ] ) ; } catch ( \ Exception $ ex ) { throw new Exception ( $ ex -> getMessage ( ) ) ; } echo "User Registered:\n" ; return $ this -> actionShow ( $ user ) ; }
|
Register new User .
|
11,303
|
public function actionDeregister ( $ user ) { $ user = $ this -> getUser ( $ user ) ; if ( $ user -> deregister ( ) ) { echo "User (" . $ user -> getID ( ) . ") Deregistered.\n" ; return static :: EXIT_CODE_NORMAL ; } return static :: EXIT_CODE_ERROR ; }
|
Deregister user .
|
11,304
|
public function actionShow ( $ user , $ guid = false , $ passHash = false , $ accessToken = false , $ authKey = false ) { $ user = $ this -> getUser ( $ user ) ; echo Yii :: t ( 'app' , 'User' ) . " (" . $ user -> getID ( ) . "), " . Yii :: t ( 'app' , 'registered at' ) . " (" . $ user -> getCreatedAt ( ) . ")" . ( $ user -> getCreatedAt ( ) == $ user -> getUpdatedAt ( ) ? "" : ", " . Yii :: t ( 'app' , 'last updated at' ) . " (" . $ user -> getUpdatedAt ( ) . ")" ) . ".\n" ; if ( $ guid ) { echo "GUID: " . $ user -> getGUID ( ) . "\n" ; } if ( $ passHash ) { echo "Password Hash: " . $ user -> { $ user -> passwordHashAttribute } . "\n" ; } if ( $ accessToken ) { echo "Access Token: " . $ user -> getAccessToken ( ) . "\n" ; } if ( $ authKey ) { echo "Authentication Key: " . $ user -> getAuthKey ( ) . "\n" ; } return static :: EXIT_CODE_NORMAL ; }
|
Show User Information .
|
11,305
|
public function actionStat ( $ user = null ) { if ( $ user === null ) { $ count = User :: find ( ) -> count ( ) ; echo "Total number of user(s): " . $ count . "\n" ; if ( $ count == 0 ) { return static :: EXIT_CODE_NORMAL ; } $ last = User :: find ( ) -> orderByCreatedAt ( SORT_DESC ) -> one ( ) ; echo "Latest user (" . $ last -> getID ( ) . ") registered at " . $ last -> getCreatedAt ( ) . "\n" ; return static :: EXIT_CODE_NORMAL ; } $ user = $ this -> getUser ( $ user ) ; return static :: EXIT_CODE_NORMAL ; }
|
Show statistics .
|
11,306
|
public function actionRole ( $ user , $ operation , $ role ) { $ user = $ this -> getUser ( $ user ) ; $ role = Yii :: $ app -> authManager -> getRole ( $ role ) ; if ( $ operation == 'assign' ) { try { $ assignment = Yii :: $ app -> authManager -> assign ( $ role , $ user ) ; } catch ( \ yii \ db \ IntegrityException $ ex ) { echo "Failed to assign `" . $ role -> name . "`.\n" ; echo "Maybe the role has been assigned.\n" ; return static :: EXIT_CODE_ERROR ; } if ( $ assignment ) { echo "`$role->name`" . " assigned to User (" . $ user -> getID ( ) . ") successfully.\n" ; } else { echo "Failed to assign `" . $ role -> name . "`.\n" ; } return static :: EXIT_CODE_NORMAL ; } if ( $ operation == 'revoke' ) { $ assignment = Yii :: $ app -> authManager -> revoke ( $ role , $ user ) ; if ( $ assignment ) { echo "`$role->name`" . " revoked from User (" . $ user -> getID ( ) . ").\n" ; } else { echo "Failed to revoke `" . $ role -> name . "`.\n" ; echo "Maybe the role has not been assigned yet.\n" ; } return static :: EXIT_CODE_NORMAL ; } echo "Unrecognized operation: $operation.\n" ; echo "The accepted operations are `assign` and `revoke`.\n" ; return static :: EXIT_CODE_ERROR ; }
|
Assign a role to user or revoke a role .
|
11,307
|
public function actionPermission ( $ user , $ operation , $ permission ) { $ user = $ this -> getUser ( $ user ) ; $ permission = Yii :: $ app -> authManager -> getPermission ( $ permission ) ; if ( $ operation == 'assign' ) { try { $ assignment = Yii :: $ app -> authManager -> assign ( $ permission , $ user ) ; } catch ( \ yii \ db \ IntegrityException $ ex ) { echo "Failed to assign `" . $ permission -> name . "`.\n" ; echo "Maybe the permission has been assigned.\n" ; return static :: EXIT_CODE_ERROR ; } if ( $ assignment ) { echo "`$permission->name`" . " assigned to User (" . $ user -> getID ( ) . ") successfully.\n" ; } else { echo "Failed to assign `" . $ permission -> name . "`.\n" ; } return static :: EXIT_CODE_NORMAL ; } if ( $ operation == 'revoke' ) { $ assignment = Yii :: $ app -> authManager -> revoke ( $ permission , $ user ) ; if ( $ assignment ) { echo "`$permission->name`" . " revoked from User (" . $ user -> getID ( ) . ").\n" ; } else { echo "Failed to revoke `" . $ permission -> name . "`.\n" ; echo "Maybe the permission has not been assigned yet.\n" ; } return static :: EXIT_CODE_NORMAL ; } echo "Unrecognized operation: $operation.\n" ; echo "The accepted operations are `assign` and `revoke`.\n" ; return static :: EXIT_CODE_ERROR ; }
|
Assign a permission to user or revoke a permission .
|
11,308
|
public function actionPassword ( $ user , $ password ) { $ user = $ this -> getUser ( $ user ) ; $ user -> applyForNewPassword ( ) ; $ result = $ user -> resetPassword ( $ password , $ user -> getPasswordResetToken ( ) ) ; if ( $ result ) { echo "Password changed.\n" ; } else { echo "Password not changed.\n" ; } return static :: EXIT_CODE_NORMAL ; }
|
Change password directly .
|
11,309
|
public function actionConfirmPasswordHistory ( $ user , $ password ) { $ user = $ this -> getUser ( $ user ) ; $ passwordHistory = $ user -> passwordHistories ; $ passwordInHistory = 0 ; foreach ( $ passwordHistory as $ pass ) { if ( $ pass -> validatePassword ( $ password ) ) { $ passwordInHistory ++ ; echo "This password was created at " . $ pass -> getCreatedAt ( ) . ".\n" ; } } if ( $ passwordInHistory ) { echo "$passwordInHistory matched.\n" ; return static :: EXIT_CODE_NORMAL ; } echo "No password matched.\n" ; return static :: EXIT_CODE_ERROR ; }
|
Confirm password in history . This command will list all matching passwords in reverse order .
|
11,310
|
function debug ( $ str , $ TYPE = 0 , $ file = "" , $ line = 0 ) { if ( $ this -> debug ) { echo "<br>[$file:$line:" . ( $ this -> getDiffTime ( ) ) . "]$str" ; flush ( ) ; if ( $ TYPE == 1 ) { exit ; } } }
|
Show Debugging information
|
11,311
|
function Get32s ( $ val1 , $ val2 , $ val3 , $ val4 ) { $ val1 = ord ( $ val1 ) ; $ val2 = ord ( $ val2 ) ; $ val3 = ord ( $ val3 ) ; $ val4 = ord ( $ val4 ) ; if ( $ this -> MotorolaOrder ) { return ( ( $ val1 << 24 ) | ( $ val2 << 16 ) | ( $ val3 << 8 ) | ( $ val4 << 0 ) ) ; } else { return ( ( $ val4 << 24 ) | ( $ val3 << 16 ) | ( $ val2 << 8 ) | ( $ val1 << 0 ) ) ; } }
|
Converts 4 - byte number into its equivalent integer
|
11,312
|
function get32u ( $ val1 , $ val2 , $ val3 , $ val4 ) { return ( $ this -> Get32s ( $ val1 , $ val2 , $ val3 , $ val4 ) & 0xffffffff ) ; }
|
Converts 4 - byte number into its equivalent integer with the help of Get32s
|
11,313
|
protected function setJobInstanceIfNecessary ( Job $ job , $ instance ) { if ( in_array ( InteractsWithQueue :: class , class_uses_recursive ( get_class ( $ instance ) ) ) ) { $ instance -> setJob ( $ job ) ; } return $ instance ; }
|
Set the job instance of the given class if necessary .
|
11,314
|
public function formatPrice ( float $ price , $ baseCurrency = null , $ targetCurrency = null , $ locale = null , $ quantity = 1 ) : string { return $ this -> helper -> convertAndFormat ( $ price , $ baseCurrency , $ targetCurrency , $ quantity , $ locale ) ; }
|
Formats the given amount
|
11,315
|
public function convertPrice ( float $ price , $ baseCurrency = null , $ targetCurrency = null , $ quantity = 1 ) : string { return $ this -> helper -> convert ( $ price , $ baseCurrency , $ targetCurrency , $ quantity ) ; }
|
Converts the given amount
|
11,316
|
public function getRelations ( ) : array { $ relations = array_unique ( array_merge ( $ this -> getAvailableIncludes ( ) , $ this -> relations ) ) ; return array_filter ( $ relations , function ( $ relation ) { return $ relation !== '*' ; } ) ; }
|
Get relations set on the transformer .
|
11,317
|
public function setRelations ( $ relations ) { $ this -> setAvailableIncludes ( array_unique ( array_merge ( $ this -> availableIncludes , ( array ) $ relations ) ) ) ; return $ this ; }
|
Set relations on the transformer .
|
11,318
|
protected function includePivot ( Pivot $ pivot ) { if ( ! method_exists ( $ this , 'transformPivot' ) ) { return false ; } return app ( Responder :: class ) -> transform ( $ pivot , function ( $ pivot ) { return $ this -> transformPivot ( $ pivot ) ; } ) -> getResource ( ) ; }
|
Include pivot table data to the response .
|
11,319
|
private function _set_cfg ( ) { if ( \ is_array ( $ this -> cfg ) ) { $ p = & $ this -> cfg [ 'params' ] ; $ components = false ; if ( ! empty ( $ p [ 'components' ] ) ) { $ components = explode ( ',' , $ p [ 'components' ] ) ; } $ this -> cfg = bbn \ x :: merge_arrays ( $ this -> cfg , [ 'test' => ! empty ( $ p [ 'test' ] ) , 'lang' => empty ( $ p [ 'lang' ] ) ? self :: $ default_language : $ p [ 'lang' ] , 'nocompil' => ! empty ( $ p [ 'nocompil' ] ) , 'has_css' => ! isset ( $ p [ 'css' ] ) || $ p [ 'css' ] , 'has_dep' => ! isset ( $ p [ 'dep' ] ) || $ p [ 'dep' ] , 'latest' => isset ( $ p [ 'latest' ] ) ? 1 : false , 'is_component' => ! empty ( $ p [ 'components' ] ) , 'components' => $ components ] ) ; } }
|
Returns an array with all the - default or no - config parameters based on the sent ones
|
11,320
|
public function getPriority ( $ as_string = true ) { $ nodes = $ this -> doc -> getElementsByTagName ( 'priority' ) ; $ node = $ nodes -> item ( 0 ) ; if ( $ node ) { if ( $ as_string ) { return $ node -> nodeValue ; } else { return $ node ; } } else { return '' ; } }
|
Gets the priority value of a presence packet
|
11,321
|
public function setStatus ( $ status ) { $ node = $ this -> getStatus ( false ) ; if ( ! $ node ) { $ node = $ this -> createElement ( 'status' ) ; $ this -> doc -> appendChild ( $ node ) ; } $ node -> nodeValue = htmlspecialchars ( $ status ) ; }
|
Set the status of the presence packet
|
11,322
|
public function setShow ( $ show ) { if ( $ show == 'unavailable' ) { $ this -> setType ( $ show ) ; } $ node = $ this -> getShow ( false ) ; if ( ! $ node ) { $ node = $ this -> createElement ( 'show' ) ; $ this -> doc -> appendChild ( $ node ) ; } $ node -> nodeValue = htmlspecialchars ( $ show ) ; }
|
Shows the status of the bot
|
11,323
|
public function setPriority ( $ priority = 1 ) { $ node = $ this -> getPriority ( false ) ; if ( ! $ node ) { $ node = $ this -> createElement ( 'priority' ) ; $ this -> doc -> appendChild ( $ node ) ; } $ node -> nodeValue = htmlspecialchars ( $ priority ) ; }
|
Sets the priority of the presence
|
11,324
|
public function setType ( $ type ) { $ attr = $ this -> createAttribute ( 'type' ) ; $ this -> doc -> appendChild ( $ attr ) ; $ attr -> appendChild ( $ this -> createTextNode ( $ type ) ) ; }
|
Sets the presence type
|
11,325
|
public function createFailure ( string $ description ) { $ exception = new AssertionException ( $ description ) ; $ suiteClass = $ this -> suiteClass ; $ suiteClass :: current ( ) -> assert ( [ 'handler' => function ( ) use ( $ exception ) { throw $ exception ; } , 'type' => AssertionException :: class , ] ) ; }
|
Create a new assertion failure exception .
|
11,326
|
public static function encode ( $ data , $ prettyPrint = false , $ xmlVersion = '1.0' , $ encoding = 'utf-8' ) { $ domDocument = new DOMDocument ( $ xmlVersion , $ encoding ) ; $ domDocument = self :: loopEncode ( $ data , $ domDocument ) ; if ( $ prettyPrint ) { $ domDocument -> preserveWhiteSpace = false ; $ domDocument -> formatOutput = true ; } $ resultString = $ domDocument -> saveXML ( ) ; if ( ! $ prettyPrint ) { $ resultStringLines = explode ( PHP_EOL , $ resultString ) ; $ documentLine = array_shift ( $ resultStringLines ) ; $ resultString = $ documentLine . PHP_EOL . implode ( '' , $ resultStringLines ) ; } else { $ resultString = trim ( $ resultString , PHP_EOL ) ; } return $ resultString ; }
|
Encodes an array to xml strutcture
|
11,327
|
protected static function loopEncode ( $ data , $ domElement ) { if ( is_array ( $ data ) ) { foreach ( $ data as $ index => $ mixedElement ) { if ( is_int ( $ index ) ) { if ( $ index == 0 ) { $ node = $ domElement ; } else { $ node = new DOMElement ( $ domElement -> tagName ) ; $ domElement -> parentNode -> appendChild ( $ node ) ; } } else { $ node = new DOMElement ( $ index ) ; $ domElement -> appendChild ( $ node ) ; } self :: loopEncode ( $ mixedElement , $ node ) ; } } else { $ domElement -> appendChild ( new DOMText ( $ data ) ) ; } return $ domElement ; }
|
Lets loop through our data
|
11,328
|
protected static function loopDecode ( $ data ) { if ( is_array ( $ data ) ) { foreach ( $ data as & $ value ) { $ value = self :: loopDecode ( $ value ) ; } } elseif ( is_object ( $ data ) ) { return self :: loopDecode ( ( array ) $ data ) ; } return $ data ; }
|
Turns all the objects into arrays
|
11,329
|
public function read ( $ byte_count = null ) { $ this -> log ( 'read from socket' ) ; $ buffer = '' ; if ( ! is_null ( $ byte_count ) ) { $ buffer .= fgets ( $ this -> socket , 1024 ) ; } else { while ( ! feof ( $ this -> socket ) ) { $ buffer .= fgets ( $ this -> socket , 1024 ) ; } } return $ buffer ; }
|
Read data from the socket
|
11,330
|
public function import ( array $ classes ) { foreach ( $ classes as $ class => $ alias ) { if ( is_integer ( $ class ) ) { $ class = $ alias ; $ alias = ClassHelper :: getSimpleName ( $ class ) ; } if ( isset ( $ this -> imports [ $ alias ] ) ) { throw new \ RuntimeException ( "Alias $alias for $class exists, previous is " . $ this -> imports [ $ alias ] ) ; } $ this -> imports [ $ alias ] = $ class ; } return $ this ; }
|
Imports annotation classes
|
11,331
|
public function get ( $ class ) { $ annotations = $ this -> getCache ( ) -> get ( '_PHX.annotations.' . $ class ) ; if ( ! isset ( $ annotations ) ) { $ annotations = $ this -> getAnnotations ( $ class ) ; $ this -> getCache ( ) -> save ( '_PHX.annotations.' . $ class , $ annotations ) ; } return $ annotations ; }
|
Gets all annotations in the class
|
11,332
|
private function getAnnotations ( $ class ) { $ parsed = $ this -> getParser ( ) -> parse ( $ class ) ; if ( ! is_array ( $ parsed ) ) { return [ ] ; } $ context = [ 'class' => $ class , 'declaringClass' => $ class , 'type' => Context :: TYPE_CLASS , 'name' => $ class ] ; $ annotations = [ ] ; if ( ! empty ( $ parsed [ 'class' ] ) ) { foreach ( $ parsed [ 'class' ] as $ value ) { $ anno = $ this -> create ( $ value , $ context ) ; if ( $ anno ) { $ annotations [ ] = $ anno ; } } } $ map = [ 'methods' => Context :: TYPE_METHOD , 'properties' => Context :: TYPE_PROPERTY ] ; $ reflection = new \ ReflectionClass ( $ class ) ; foreach ( $ map as $ type_name => $ type ) { if ( ! empty ( $ parsed [ $ type_name ] ) ) { foreach ( $ parsed [ $ type_name ] as $ name => $ values ) { $ reflType = $ type == 'method' ? $ reflection -> getMethod ( $ name ) : $ reflection -> getProperty ( $ name ) ; $ context [ 'type' ] = $ type ; $ context [ 'name' ] = $ name ; $ context [ 'declaringClass' ] = $ reflType -> getDeclaringClass ( ) -> getName ( ) ; foreach ( $ values as $ value ) { $ anno = $ this -> create ( $ value , $ context ) ; if ( $ anno ) { $ annotations [ ] = $ anno ; } } } } } return $ annotations ; }
|
parse all annotations from class
|
11,333
|
private function create ( $ annotation , $ context ) { $ logger = $ this -> getLogger ( ) ; $ name = $ annotation [ 'name' ] ; if ( ! $ this -> isValidName ( $ name ) ) { return null ; } $ annotationClass = $ this -> resolveClassName ( $ name , $ context [ 'declaringClass' ] ) ; if ( ! $ annotationClass ) { if ( isset ( $ this -> imports [ $ name ] ) ) { $ annotationClass = $ this -> imports [ $ name ] ; } else { $ logger -> warning ( "Unknown annotation '$name' at {$annotation['file']}:{$annotation['line']}" ) ; return null ; } } if ( ! class_exists ( $ annotationClass ) ) { $ logger -> warning ( "Annotation class '$annotationClass' does not exist" . " at {$annotation['file']}:{$annotation['line']}" ) ; return null ; } if ( ! is_subclass_of ( $ annotationClass , Annotation :: class ) ) { $ logger -> warning ( "Annotation class '$annotationClass' at {$annotation['file']}:{$annotation['line']}" . " is not subclass of " . Annotation :: class ) ; return null ; } $ context [ 'file' ] = $ annotation [ 'file' ] ; $ context [ 'line' ] = $ annotation [ 'line' ] ; $ args = ( new PhalconAnnotation ( $ annotation ) ) -> getArguments ( ) ? : [ ] ; return new $ annotationClass ( $ args , new Context ( $ context ) ) ; }
|
create annotation object
|
11,334
|
private function updateAddressFromComponent ( Address $ address , $ component ) : Address { foreach ( $ component -> types as $ type ) { switch ( $ type ) { case 'postal_code' : $ address -> setPostalCode ( $ component -> long_name ) ; break ; case 'locality' : case 'postal_town' : $ address -> setLocality ( $ component -> long_name ) ; break ; case 'country' : $ address -> setCountry ( $ component -> long_name ) ; $ address -> setCountryCode ( $ component -> short_name ) ; break ; case 'street_number' : $ address -> setStreetNumber ( $ component -> long_name ) ; break ; case 'route' : $ address -> setStreetName ( $ component -> long_name ) ; break ; case 'administrative_area_level_1' : case 'administrative_area_level_2' : case 'administrative_area_level_3' : case 'administrative_area_level_4' : case 'administrative_area_level_5' : case 'sublocality' : case 'sublocality_level_1' : case 'sublocality_level_2' : case 'sublocality_level_3' : case 'sublocality_level_4' : case 'sublocality_level_5' : case 'street_address' : case 'intersection' : case 'political' : case 'colloquial_area' : case 'ward' : case 'neighborhood' : case 'premise' : case 'subpremise' : case 'natural_feature' : case 'airport' : case 'park' : case 'point_of_interest' : case 'establishment' : break ; default : } } return $ address ; }
|
update address from google address component
|
11,335
|
protected function clearDir ( $ dir ) { $ iterator = new \ DirectoryIterator ( $ dir ) ; foreach ( $ iterator as $ file ) { if ( $ file -> isDir ( ) && ! $ file -> isDot ( ) && ! preg_match ( "~\.~" , $ file ) ) { $ this -> clearDir ( $ file -> getPathname ( ) ) ; if ( ! \ rmdir ( $ file -> getPathname ( ) ) ) { return false ; } } elseif ( $ file -> isFile ( ) ) { if ( ! \ unlink ( $ file -> getPathname ( ) ) ) { return false ; } } } return true ; }
|
Clears out the contents of a cache directory
|
11,336
|
protected function catalogKeyDelete ( $ key ) { $ catalog = $ this -> fetch ( $ this -> catalog_key ) ; $ catalog = \ is_array ( $ catalog ) ? $ catalog : Array ( ) ; if ( isset ( $ catalog [ $ key ] ) ) { unset ( $ catalog [ $ key ] ) ; } ; return $ this -> store ( '/sb_Cache_Catalog' , $ catalog ) ; }
|
Deletes a key from the catalog
|
11,337
|
protected function listConfiguration ( array $ contents , array $ rawContents , OutputInterface $ output , $ k = null ) { $ origK = $ k ; foreach ( $ contents as $ key => $ value ) { if ( $ k === null && ! in_array ( $ key , array ( 'config' , 'repositories' ) ) ) { continue ; } $ rawVal = isset ( $ rawContents [ $ key ] ) ? $ rawContents [ $ key ] : null ; if ( is_array ( $ value ) && ( ! is_numeric ( key ( $ value ) ) || ( $ key === 'repositories' && null === $ k ) ) ) { $ k .= preg_replace ( '{^config\.}' , '' , $ key . '.' ) ; $ this -> listConfiguration ( $ value , $ rawVal , $ output , $ k ) ; if ( substr_count ( $ k , '.' ) > 1 ) { $ k = str_split ( $ k , strrpos ( $ k , '.' , - 2 ) ) ; $ k = $ k [ 0 ] . '.' ; } else { $ k = $ origK ; } continue ; } if ( is_array ( $ value ) ) { $ value = array_map ( function ( $ val ) { return is_array ( $ val ) ? json_encode ( $ val ) : $ val ; } , $ value ) ; $ value = '[' . implode ( ', ' , $ value ) . ']' ; } if ( is_bool ( $ value ) ) { $ value = var_export ( $ value , true ) ; } if ( is_string ( $ rawVal ) && $ rawVal != $ value ) { $ this -> getIO ( ) -> write ( '[<comment>' . $ k . $ key . '</comment>] <info>' . $ rawVal . ' (' . $ value . ')</info>' ) ; } else { $ this -> getIO ( ) -> write ( '[<comment>' . $ k . $ key . '</comment>] <info>' . $ value . '</info>' ) ; } } }
|
Display the contents of the file in a pretty formatted way
|
11,338
|
public function set ( $ orig , $ dest = '' ) { if ( ! empty ( $ dest ) ) { copy ( $ orig , $ dest ) ; $ orig = $ dest ; } $ this -> path = $ orig ; $ this -> getInfo ( ) ; }
|
Sets the image being edited
|
11,339
|
public function getInfo ( ) { $ file_info = @ getimagesize ( $ this -> path ) ; $ this -> width [ 'orig' ] = $ file_info [ '0' ] ; $ this -> height [ 'orig' ] = $ file_info [ '1' ] ; switch ( $ file_info [ 2 ] ) { case "1" : $ this -> type = "gif" ; break ; case "2" : $ this -> type = "jpg" ; break ; case "3" : $ this -> type = "png" ; break ; } $ this -> original = imagecreatefromstring ( file_get_contents ( $ this -> path ) ) ; }
|
Gets the image file type width and height
|
11,340
|
public function resize ( $ width , $ height ) { if ( $ width == - 1 ) { $ this -> width [ 'dest' ] = ( $ height * $ this -> width [ 'orig' ] ) / $ this -> height [ 'orig' ] ; $ this -> height [ 'dest' ] = $ height ; } elseif ( $ height == - 1 ) { $ this -> width [ 'dest' ] = $ width ; $ this -> height [ 'dest' ] = ( $ width * $ this -> height [ 'orig' ] ) / $ this -> width [ 'orig' ] ; } else { $ this -> width [ 'dest' ] = $ width ; $ this -> height [ 'dest' ] = $ height ; } switch ( $ this -> type ) { case "gif" : $ this -> edited = imagecreate ( $ this -> width [ 'dest' ] , $ this -> height [ 'dest' ] ) ; imagecopyresampled ( $ this -> edited , $ this -> original , 0 , 0 , 0 , 0 , $ this -> width [ 'dest' ] , $ this -> height [ 'dest' ] , $ this -> width [ 'orig' ] , $ this -> height [ 'orig' ] ) ; break ; case "jpg" : $ this -> edited = imagecreatetruecolor ( $ this -> width [ 'dest' ] , $ this -> height [ 'dest' ] ) ; imagecopyresampled ( $ this -> edited , $ this -> original , 0 , 0 , 0 , 0 , $ this -> width [ 'dest' ] , $ this -> height [ 'dest' ] , $ this -> width [ 'orig' ] , $ this -> height [ 'orig' ] ) ; break ; case "png" : $ this -> edited = imagecreatetruecolor ( $ this -> width [ 'dest' ] , $ this -> height [ 'dest' ] ) ; imagealphablending ( $ this -> edited , false ) ; imagesavealpha ( $ this -> edited , true ) ; imagecopyresampled ( $ this -> edited , $ this -> original , 0 , 0 , 0 , 0 , $ this -> width [ 'dest' ] , $ this -> height [ 'dest' ] , $ this -> width [ 'orig' ] , $ this -> height [ 'orig' ] ) ; break ; } }
|
Resizes an the edited image to the specified width and height
|
11,341
|
public function toGrayscale ( ) { $ this -> getInfo ( ) ; $ this -> edited = imagecreate ( $ this -> width [ 'orig' ] , $ this -> height [ 'orig' ] ) ; for ( $ c = 0 ; $ c < 256 ; $ c ++ ) { $ palette [ $ c ] = imagecolorallocate ( $ this -> edited , $ c , $ c , $ c ) ; } for ( $ y = 0 ; $ y < $ this -> height [ 'orig' ] ; $ y ++ ) { for ( $ x = 0 ; $ x < $ this -> width [ 'orig' ] ; $ x ++ ) { $ rgb = imagecolorat ( $ this -> original , $ x , $ y ) ; $ r = ( $ rgb >> 16 ) & 0xFF ; $ g = ( $ rgb >> 8 ) & 0xFF ; $ b = $ rgb & 0xFF ; $ gs = $ this -> colorToGray ( $ r , $ g , $ b ) ; imagesetpixel ( $ this -> edited , $ x , $ y , $ palette [ $ gs ] ) ; } } }
|
Converts the image being edited to grayscale
|
11,342
|
public function write ( $ text , $ params = array ( ) ) { $ color = ( isset ( $ params [ 'color' ] ) ) ? $ params [ 'color' ] : array ( 0 , 0 , 0 ) ; $ color = imagecolorallocate ( $ this -> edited , $ color [ 0 ] , $ color [ 1 ] , $ color [ 2 ] ) ; $ size = ( isset ( $ params [ 'size' ] ) ) ? $ params [ 'size' ] : 5 ; $ x = ( isset ( $ params [ 'x' ] ) ) ? $ params [ 'x' ] : 2 ; $ y = ( isset ( $ params [ 'y' ] ) ) ? $ params [ 'y' ] : 2 ; imagestring ( $ this -> edited , $ size , $ x , $ y , $ text , $ color ) ; }
|
Write text onto an image
|
11,343
|
public function toFile ( ) { if ( $ this -> type == "jpg" ) { $ this -> toJpg ( ) ; } elseif ( $ this -> type == "png" ) { $ this -> toPng ( ) ; } elseif ( $ this -> type == "gif" ) { $ this -> toGif ( ) ; } }
|
Saves the edited image as a file based on the original images file type
|
11,344
|
public function display ( ) { if ( isset ( $ this -> edited ) ) { $ image = $ this -> edited ; } else { $ image = $ this -> original ; } if ( $ this -> type == "jpg" ) { header ( "Content-type: image/jpeg" ) ; imagejpeg ( $ image ) ; } elseif ( $ this -> type == "png" ) { header ( "Content-type: image/png" ) ; imagepng ( $ image ) ; } elseif ( $ this -> type == "gif" ) { header ( "Content-type: image/gif" ) ; imagegif ( $ image ) ; } }
|
Displays the edited image to screen as a dynamic image file
|
11,345
|
public function forceDownload ( ) { if ( $ this -> type == "jpg" ) { $ this -> toJpg ( ) ; } elseif ( $ this -> type == "png" ) { $ this -> toPng ( ) ; } elseif ( $ this -> type == "gif" ) { $ this -> toGif ( ) ; } header ( 'Content-Description: File Transfer' ) ; header ( "Content-Type: application/octet-stream" ) ; header ( 'Content-Length: ' . filesize ( $ this -> path ) ) ; header ( 'Content-Disposition: attachment; filename="' . basename ( $ this -> path . '"' ) ) ; readfile ( $ this -> path ) ; unlink ( $ this -> path ) ; }
|
Forces the image being manipulated to the user as a force download
|
11,346
|
private function parseTexturesProperties ( $ propertiesArray ) { foreach ( $ propertiesArray as $ property ) { if ( $ property [ 'name' ] == 'textures' ) { $ texturesJSON = json_decode ( base64_decode ( $ property [ 'value' ] ) , true ) ; $ properties = new PlayerProperties ( $ texturesJSON [ 'timestamp' ] , $ texturesJSON [ 'profileId' ] , $ texturesJSON [ 'profileName' ] ) ; if ( isset ( $ texturesJSON [ 'isPublic' ] ) ) { $ properties -> setPublic ( $ texturesJSON [ 'isPublic' ] ) ; } if ( array_key_exists ( 'SKIN' , $ texturesJSON [ 'textures' ] ) ) { $ properties -> setSkinTexture ( $ texturesJSON [ 'textures' ] [ 'SKIN' ] [ 'url' ] ) ; } if ( array_key_exists ( 'CAPE' , $ texturesJSON [ 'textures' ] ) ) { $ properties -> setCapeTexture ( $ texturesJSON [ 'textures' ] [ 'CAPE' ] [ 'url' ] ) ; } return $ properties ; } } return null ; }
|
Checks the array for a properties with name textures and creates a PlayerProperties for it
|
11,347
|
private function getResponse ( $ url , $ options , $ post ) { if ( $ post ) { $ response = $ this -> httpClient -> post ( $ url , $ options ) ; } else { $ response = $ this -> httpClient -> get ( $ url , $ options ) ; } if ( $ response -> getStatusCode ( ) != 200 ) { $ json = $ response -> json ( ) ; $ short = $ json [ 'error' ] ; $ error = $ json [ 'errorMessage' ] ; $ cause = $ json [ 'cause' ] ; throw new APIRequestException ( $ short == null ? 'Unknown Error' : $ short , $ error == null ? 'Unknown Error' : $ error , $ cause == null ? '' : $ cause ) ; } return $ response -> json ( ) ; }
|
Get a response from the given subURL via POST with the given JSON data . Sets header Content - Type for JSON
|
11,348
|
public function get ( $ property ) { return isset ( $ this -> data [ $ property ] ) ? $ this -> data [ $ property ] : null ; }
|
Returns the value of a given property .
|
11,349
|
public function connect ( ) { if ( isset ( $ this -> _connection ) ) { $ this -> disconnect ( ) ; } $ function = $ this -> _config [ 'persistent' ] ? 'pfsockopen' : 'fsockopen' ; $ params = [ $ this -> _config [ 'host' ] , $ this -> _config [ 'port' ] , & $ errNum , & $ errStr ] ; if ( $ this -> _config [ 'timeout' ] ) { $ params [ ] = $ this -> _config [ 'timeout' ] ; } $ this -> _connection = @ call_user_func_array ( $ function , $ params ) ; if ( ! empty ( $ errNum ) || ! empty ( $ errStr ) ) { throw new ConnectionException ( "{$errNum}: {$errStr} (connecting to {$this->_config['host']}:{$this->_config['port']})" ) ; } $ this -> connected = is_resource ( $ this -> _connection ) ; if ( ! $ this -> connected ) { throw new ConnectionException ( 'Connected failed.' ) ; } stream_set_timeout ( $ this -> _connection , $ this -> _config [ 'socket_timeout' ] ) ; return $ this -> connected ; }
|
Initiates a socket connection to the beanstalk server . The resulting stream will not have any timeout set on it . Which means it can wait an unlimited amount of time until a packet becomes available . This is required for doing blocking reads .
|
11,350
|
public function delete ( $ id ) { $ this -> _write ( sprintf ( 'delete %d' , $ id ) ) ; $ status = $ this -> _read ( ) ; switch ( $ status ) { case 'DELETED' : return true ; case 'NOT_FOUND' : return false ; default : throw new ServerException ( 'Delete error: ' . $ status ) ; } }
|
Removes a job from the server entirely .
|
11,351
|
public function kickJob ( $ id ) { $ this -> _write ( sprintf ( 'kick-job %d' , $ id ) ) ; $ status = strtok ( $ this -> _read ( ) , ' ' ) ; switch ( $ status ) { case 'KICKED' : return true ; case 'NOT_FOUND' : return false ; default : throw new ServerException ( 'Kick error: ' . $ status ) ; } }
|
This is a variant of the kick command that operates with a single job identified by its job id . If the given job id exists and is in a buried or delayed state it will be moved to the ready queue of the the same tube where it currently belongs .
|
11,352
|
public function setType ( $ type = null ) { $ type = $ this -> calculateTypeValue ( $ type ) ; if ( ! is_int ( $ type ) || ( $ type < 0 ) || ( $ type > self :: ALL ) ) { throw new Exception \ InvalidArgumentException ( 'Unknown type' ) ; } $ this -> options [ 'type' ] = $ type ; return $ this ; }
|
Sets types of values that are to be considered empty .
|
11,353
|
public function addRules ( $ rules ) { if ( $ rules instanceof RiskyRulesAwareInterface && $ rules -> isRisky ( ) ) { $ this -> setRiskyAllowed ( true ) ; } if ( $ rules instanceof \ Traversable ) { $ rules = iterator_to_array ( $ rules ) ; } if ( ! is_array ( $ rules ) ) { throw new \ InvalidArgumentException ( 'Expected rules to be an iterable.' ) ; } $ rules = array_replace ( $ this -> getRules ( ) , $ rules ) ; $ this -> setRules ( $ rules ) ; return $ this ; }
|
Add to the current rules . Overrides existing rules .
|
11,354
|
public function initialize ( Controller $ controller ) { if ( $ this -> settings [ 'isTest' ] ) { return ; } $ this -> user = $ this -> Session -> read ( "{$this->settings['path']}" ) ; $ this -> routes = Permit :: $ routes ; Permit :: $ user = $ this -> user ; $ this -> request = $ controller -> request ; foreach ( array ( 'controller' , 'plugin' ) as $ inflected ) { if ( isset ( $ this -> request -> params [ $ inflected ] ) ) { $ this -> request -> params [ $ inflected ] = strtolower ( Inflector :: underscore ( $ this -> request -> params [ $ inflected ] ) ) ; } } }
|
Initializes SanctionComponent for use in the controller
|
11,355
|
public function startup ( Controller $ controller ) { if ( $ this -> settings [ 'isTest' ] ) { return ; } foreach ( $ this -> routes as $ route ) { if ( ! $ this -> _parse ( $ route [ 'route' ] ) ) { continue ; } if ( ! $ this -> _execute ( $ route ) ) { break ; } $ this -> Session -> write ( 'Sanction.referer' , $ this -> request -> here ( ) ) ; return $ this -> redirect ( $ controller , $ route ) ; } }
|
Main execution method . Handles redirecting of invalid users and saving of request url as Sanction . referer
|
11,356
|
protected function _parse ( $ route ) { if ( is_string ( $ route ) ) { $ this -> _ensureHere ( ) ; $ url = parse_url ( $ route ) ; $ _path = rtrim ( $ url [ 'path' ] , '/' ) ; if ( $ _path . '?' . Hash :: get ( $ url , 'query' ) === $ this -> _hereQuery ) { return true ; } if ( $ _path === $ this -> _here ) { return true ; } return false ; } $ count = count ( $ route ) ; if ( $ count == 0 ) { return false ; } foreach ( $ route as $ key => $ value ) { if ( array_key_exists ( $ key , $ this -> request -> params ) ) { $ values = ( array ) $ value ; $ check = ( array ) $ this -> request -> params [ $ key ] ; $ hasNullValues = ( count ( $ values ) != count ( array_filter ( $ values ) ) || count ( $ values ) == 0 ) ; $ currentValueIsNullish = ( in_array ( null , $ check ) || in_array ( '' , $ check ) || count ( $ check ) == 0 ) ; if ( $ hasNullValues && $ currentValueIsNullish ) { $ count -- ; continue ; } if ( in_array ( $ key , array ( 'controller' , 'plugin' ) ) ) { foreach ( $ check as $ k => $ _check ) { $ check [ $ k ] = Inflector :: underscore ( strtolower ( $ _check ) ) ; } } else { foreach ( $ check as $ k => $ _check ) { $ check [ $ k ] = strtolower ( $ _check ) ; } } if ( count ( $ values ) > 0 ) { foreach ( $ values as $ k => $ v ) { if ( in_array ( strtolower ( $ v ) , $ check ) ) { $ count -- ; break ; } } } elseif ( count ( $ check ) === 0 ) { $ count -- ; } } elseif ( is_numeric ( $ key ) && isset ( $ this -> request -> params [ 'pass' ] ) ) { if ( is_array ( $ this -> request -> params [ 'pass' ] ) ) { if ( Hash :: contains ( $ this -> request -> params [ 'pass' ] , $ value ) ) { $ count -- ; } } } } return ( $ count == 0 ) ; }
|
Parses a given Permit route to see if it matches the current request
|
11,357
|
protected function _execute ( $ route ) { Permit :: $ executed = $ this -> executed = $ route ; if ( empty ( $ route [ 'rules' ] ) ) { return false ; } if ( isset ( $ route [ 'rules' ] [ 'deny' ] ) ) { return $ route [ 'rules' ] [ 'deny' ] == true ; } if ( ! isset ( $ route [ 'rules' ] [ 'auth' ] ) ) { return false ; } if ( is_bool ( $ route [ 'rules' ] [ 'auth' ] ) ) { $ isAuthed = $ this -> Session -> read ( "{$this->settings['path']}.{$this->settings['check']}" ) ; if ( $ route [ 'rules' ] [ 'auth' ] == true && ! $ isAuthed ) { return true ; } if ( $ route [ 'rules' ] [ 'auth' ] == false && $ isAuthed ) { return true ; } return false ; } elseif ( ! is_array ( $ route [ 'rules' ] [ 'auth' ] ) ) { return false ; } if ( $ this -> user == false ) { return true ; } $ fieldsBehavior = 'and' ; if ( ! empty ( $ route [ 'rules' ] [ 'fields_behavior' ] ) ) { $ fieldsBehavior = strtolower ( $ route [ 'rules' ] [ 'fields_behavior' ] ) ; } if ( ! in_array ( $ fieldsBehavior , array ( 'and' , 'or' ) ) ) { $ fieldsBehavior = 'and' ; } $ count = count ( Set :: flatten ( $ route [ 'rules' ] [ 'auth' ] ) ) ; foreach ( $ route [ 'rules' ] [ 'auth' ] as $ path => $ condition ) { $ path = '/' . str_replace ( '.' , '/' , $ path ) ; $ path = preg_replace ( '/^([\/]+)/' , '/' , $ path ) ; $ check = $ condition ; $ continue = false ; $ decrement = 1 ; $ values = Set :: extract ( $ path , $ this -> user ) ; foreach ( array ( 'or' , 'OR' ) as $ anOr ) { if ( is_array ( $ condition ) && array_key_exists ( $ anOr , $ condition ) ) { $ check = $ condition [ $ anOr ] ; $ continue = true ; $ decrement = count ( $ check ) ; } } if ( $ fieldsBehavior == 'or' ) { $ check = $ condition ; $ continue = true ; $ decrement = count ( $ check ) ; } foreach ( ( array ) $ check as $ cond ) { if ( in_array ( $ cond , ( array ) $ values ) ) { $ count -= $ decrement ; if ( $ continue ) { continue 2 ; } } } } return $ count !== 0 ; }
|
Determines whether the given user is authorized to perform an action . The result of a failed request depends upon the options for the route
|
11,358
|
public function redirect ( Controller $ Controller , $ route ) { if ( $ route [ 'message' ] != null ) { $ message = $ route [ 'message' ] ; $ element = $ route [ 'element' ] ; $ params = $ route [ 'params' ] ; $ this -> Session -> write ( "Message.{$route['key']}" , compact ( 'message' , 'element' , 'params' ) ) ; } $ Controller -> redirect ( $ route [ 'redirect' ] ) ; }
|
Performs a redirect based upon a given route
|
11,359
|
public function setDefaultArguments ( $ default_settings ) { foreach ( $ default_settings as $ setting => $ val ) { if ( property_exists ( get_class ( ) , $ setting ) ) { $ this -> $ setting = $ val ; } } }
|
Overrides the default settings for all requests
|
11,360
|
public function setAuthentication ( $ uname = '' , $ pass = '' , $ type = 'basic' ) { $ this -> authentication [ 'uname' ] = $ uname ; $ this -> authentication [ 'pass' ] = $ pass ; $ this -> authentication [ 'type' ] = $ type ; }
|
Sets the authentication type used
|
11,361
|
public function runQueued ( InputInterface $ input , OutputInterface $ output ) { $ smileCrons = $ this -> listQueued ( ) ; $ crons = $ this -> getCrons ( ) ; $ cronAlias = array ( ) ; foreach ( $ crons as $ cron ) { $ cronAlias [ $ cron -> getAlias ( ) ] = $ cron ; } if ( $ smileCrons ) { foreach ( $ smileCrons as $ smileCron ) { if ( isset ( $ cronAlias [ $ smileCron -> getAlias ( ) ] ) ) { $ this -> run ( $ smileCron ) ; $ status = $ cronAlias [ $ smileCron -> getAlias ( ) ] -> run ( $ input , $ output ) ; $ this -> end ( $ smileCron , $ status ) ; } } } }
|
List cron commands identified as queued
|
11,362
|
public function listCronsStatus ( ) { $ smileCrons = $ this -> repository -> listCrons ( ) ; $ crons = $ this -> getCrons ( ) ; $ cronAlias = array ( ) ; foreach ( $ crons as $ cron ) { $ cronAlias [ $ cron -> getAlias ( ) ] = $ cron ; } if ( $ smileCrons ) { foreach ( $ smileCrons as $ smileCron ) { if ( isset ( $ cronAlias [ $ smileCron -> getAlias ( ) ] ) ) { $ cronAlias [ $ smileCron -> getAlias ( ) ] = $ smileCron ; } } } return $ cronAlias ; }
|
Return cron list and status
|
11,363
|
public function analyze_php ( string $ file ) : array { $ res = [ ] ; $ php = file_get_contents ( $ file ) ; if ( $ tmp = \ Gettext \ Translations :: fromPhpCodeString ( $ php , [ 'functions' => [ '_' => 'gettext' ] , 'file' => $ file ] ) ) { foreach ( $ tmp -> getIterator ( ) as $ r => $ tr ) { $ res [ ] = $ tr -> getOriginal ( ) ; } $ this -> parser -> mergeWith ( $ tmp ) ; } return array_unique ( $ res ) ; }
|
Returns the strings contained in the given php file
|
11,364
|
public function analyze_js ( string $ file ) : array { $ res = [ ] ; $ js = file_get_contents ( $ file ) ; if ( $ tmp = \ Gettext \ Translations :: fromJsCodeString ( $ js , [ 'functions' => [ '_' => 'gettext' , 'bbn._' => 'gettext' ] , 'file' => $ file ] ) ) { foreach ( $ tmp -> getIterator ( ) as $ r => $ tr ) { $ res [ ] = $ tr -> getOriginal ( ) ; } $ this -> parser -> mergeWith ( $ tmp ) ; } return array_unique ( $ res ) ; }
|
Returns the strings contained in the given js file
|
11,365
|
public function analyze_file ( string $ file ) : array { $ res = [ ] ; $ ext = bbn \ str :: file_ext ( $ file ) ; if ( \ in_array ( $ ext , self :: $ extensions , true ) && is_file ( $ file ) ) { switch ( $ ext ) { case 'html' : $ res = $ this -> analyze_php ( $ file ) ; break ; case 'php' : $ res = $ this -> analyze_php ( $ file ) ; break ; case 'js' : $ res = $ this -> analyze_js ( $ file ) ; break ; } } return $ res ; }
|
Returns the strings contained in the given file
|
11,366
|
public function analyze_folder ( string $ folder = '.' , bool $ deep = false ) : array { $ res = [ ] ; if ( \ is_dir ( $ folder ) ) { $ files = $ deep ? bbn \ file \ dir :: scan ( $ folder , 'file' ) : bbn \ file \ dir :: get_files ( $ folder ) ; foreach ( $ files as $ f ) { $ words = $ this -> analyze_file ( $ f ) ; foreach ( $ words as $ word ) { if ( ! isset ( $ res [ $ word ] ) ) { $ res [ $ word ] = [ ] ; } if ( ! in_array ( $ f , $ res [ $ word ] ) ) { $ res [ $ word ] [ ] = $ f ; } } } } return $ res ; }
|
Returns an array containing the strings found in the given folder
|
11,367
|
public function get_id_project ( $ id_option , $ projects ) { foreach ( $ projects as $ i => $ p ) { foreach ( $ projects [ $ i ] [ 'path' ] as $ idx => $ pa ) { if ( $ projects [ $ i ] [ 'path' ] [ $ idx ] [ 'id_option' ] === $ id_option ) { return $ projects [ $ i ] [ 'id' ] ; } } } }
|
get the id of the project from the id_option of a path
|
11,368
|
public function get_primaries_langs ( ) { $ uid_languages = self :: get_appui_option_id ( 'languages' ) ; $ languages = options :: get_instance ( ) -> full_tree ( $ uid_languages ) ; $ primaries = array_values ( array_filter ( $ languages [ 'items' ] , function ( $ v ) { return ! empty ( $ v [ 'primary' ] ) ; } ) ) ; return $ primaries ; }
|
Gets primaries langs from option
|
11,369
|
public function get_po_files ( $ id_option ) { if ( ! empty ( $ id_option ) && ( $ o = options :: get_instance ( ) -> option ( $ id_option ) ) && ( $ parent = options :: get_instance ( ) -> parent ( $ id_option ) ) && defined ( $ parent [ 'code' ] ) ) { $ tmp = [ ] ; $ to_explore = constant ( $ parent [ 'code' ] ) . $ o [ 'code' ] ; $ locale_dir = dirname ( $ to_explore ) . '/locale' ; $ dirs = \ bbn \ file \ dir :: get_dirs ( $ locale_dir ) ? : [ ] ; $ languages = array_map ( function ( $ a ) { return basename ( $ a ) ; } , $ dirs ) ? : [ ] ; if ( ! empty ( $ languages ) ) { foreach ( $ languages as $ lng ) { $ idx = is_file ( $ locale_dir . '/index.txt' ) ? file_get_contents ( $ locale_dir . '/index.txt' ) : '' ; if ( is_file ( $ locale_dir . '/' . $ lng . '/LC_MESSAGES/' . $ o [ 'text' ] . $ idx . '.po' ) ) { $ tmp [ $ lng ] = $ locale_dir . '/' . $ lng . '/LC_MESSAGES/' . $ o [ 'text' ] . $ idx . '.po' ; } } } return $ tmp ; } }
|
Returns an array containing the po files found for the id_option
|
11,370
|
public function count_translations_db ( $ id_option ) { $ count = [ ] ; $ po = $ this -> get_po_files ( $ id_option ) ; if ( ! empty ( $ po ) ) { foreach ( $ po as $ lang => $ file ) { $ fileHandler = new \ Sepia \ PoParser \ SourceHandler \ FileSystem ( $ file ) ; $ poParser = new \ Sepia \ PoParser \ Parser ( $ fileHandler ) ; $ Catalog = \ Sepia \ PoParser \ Parser :: parseFile ( $ file ) ; $ fromPo = $ Catalog -> getEntries ( ) ; $ source_language = $ this -> get_language ( $ id_option ) ; $ count [ $ lang ] = 0 ; foreach ( $ fromPo as $ o ) { if ( $ exp = $ o -> getMsgId ( ) ) { $ id = $ this -> db -> select_one ( 'bbn_i18n' , 'id' , [ 'exp' => $ exp , 'lang' => $ source_language ] ) ; if ( $ string = $ this -> db -> select_one ( 'bbn_i18n_exp' , 'expression' , [ 'id_exp' => $ id , 'lang' => $ lang ] ) ) { $ count [ $ lang ] ++ ; } } } } } return $ count ; }
|
Count how many of the strings contained in po files are already in database
|
11,371
|
function write ( $ text , $ format = 'r' ) { $ fw = Base :: instance ( ) ; $ fw -> write ( $ this -> file , date ( $ format ) . ( isset ( $ _SERVER [ 'REMOTE_ADDR' ] ) ? ( ' [' . $ _SERVER [ 'REMOTE_ADDR' ] . ']' ) : '' ) . ' ' . trim ( $ text ) . PHP_EOL , TRUE ) ; }
|
Write specified text to log file
|
11,372
|
public static function remove ( $ itemName ) { $ returnVar = true ; if ( ! is_dir ( $ itemName ) && file_exists ( $ itemName ) ) { unlink ( $ itemName ) ; return true ; } if ( ! file_exists ( $ itemName ) ) { return true ; } $ dir = dir ( $ itemName ) ; $ item = $ dir -> read ( ) ; while ( $ item !== false ) { if ( $ item != '.' && $ item != '..' ) { self :: remove ( $ dir -> path . DIRECTORY_SEPARATOR . $ item ) ; $ returnVar = false ; } $ item = $ dir -> read ( ) ; } $ dir -> close ( ) ; $ returnVar = rmdir ( $ itemName ) && $ returnVar ? true : false ; return $ returnVar ; }
|
Recursively removes a directory and its contents or a file .
|
11,373
|
protected function createOn ( $ meta , $ fromIndex , $ relatedMeta , $ toIndex ) { if ( ! isset ( $ meta -> indexes [ $ fromIndex ] ) ) { throw new Exception ( "Index $fromIndex does not exist on {$meta->id}" ) ; } if ( ! isset ( $ relatedMeta -> indexes [ $ toIndex ] ) ) { throw new Exception ( "Index $toIndex does not exist on {$relatedMeta->id}" ) ; } $ on = [ ] ; foreach ( $ meta -> indexes [ $ fromIndex ] [ 'fields' ] as $ idx => $ fromField ) { if ( ! isset ( $ relatedMeta -> indexes [ $ toIndex ] [ 'fields' ] [ $ idx ] ) ) { break ; } $ on [ $ fromField ] = $ relatedMeta -> indexes [ $ toIndex ] [ 'fields' ] [ $ idx ] ; } return $ on ; }
|
to be interfered with yet .
|
11,374
|
public function store ( $ id , $ data , $ attributes = array ( ) ) { $ filename = $ this -> properties [ 'location' ] . $ this -> generateIdentifier ( $ id , $ attributes ) ; if ( file_exists ( $ filename ) ) { if ( unlink ( $ filename ) === false ) { throw new ezcBaseFilePermissionException ( $ filename , ezcBaseFileException :: WRITE , 'Could not delete existsing cache file.' ) ; } } $ dataStr = $ this -> prepareData ( $ data ) ; $ dirname = dirname ( $ filename ) ; if ( ! is_dir ( $ dirname ) && ! mkdir ( $ dirname , 0777 , true ) ) { throw new ezcBaseFilePermissionException ( $ dirname , ezcBaseFileException :: WRITE , 'Could not create directory to stor cache file.' ) ; } $ this -> storeRawData ( $ filename , $ dataStr ) ; if ( ezcBaseFeatures :: os ( ) !== "Windows" ) { chmod ( $ filename , $ this -> options -> permissions ) ; } return $ id ; }
|
Store data to the cache storage . This method stores the given cache data into the cache assigning the ID given to it .
|
11,375
|
protected function storeRawData ( $ filename , $ data ) { if ( file_put_contents ( $ filename , $ data ) !== strlen ( $ data ) ) { throw new ezcBaseFileIoException ( $ filename , ezcBaseFileException :: WRITE , 'Could not write data to cache file.' ) ; } }
|
Actually stores the given data .
|
11,376
|
public function delete ( $ id = null , $ attributes = array ( ) , $ search = false ) { $ filename = $ this -> properties [ 'location' ] . $ this -> generateIdentifier ( $ id , $ attributes ) ; $ filesToDelete = array ( ) ; if ( file_exists ( $ filename ) ) { $ filesToDelete [ ] = $ filename ; } else if ( $ search === true ) { $ filesToDelete = $ this -> search ( $ id , $ attributes ) ; } $ deletedIds = array ( ) ; foreach ( $ filesToDelete as $ filename ) { if ( unlink ( $ filename ) === false ) { throw new ezcBaseFilePermissionException ( $ filename , ezcBaseFileException :: WRITE , 'Could not unlink cache file.' ) ; } $ deleted = $ this -> extractIdentifier ( $ filename ) ; $ deletedIds [ ] = $ deleted [ 'id' ] ; } return $ deletedIds ; }
|
Delete data from the cache . Purges the cached data for a given ID and or attributes . Using an ID purges only the cache data for just this ID .
|
11,377
|
public function purge ( $ limit = null ) { $ purgeCount = 0 ; return $ this -> purgeRecursive ( $ this -> properties [ 'location' ] , $ limit , $ purgeCount ) ; }
|
Purges the given number of cache items .
|
11,378
|
private function purgeRecursive ( $ dir , $ limit , & $ purgeCount ) { $ purgedIds = array ( ) ; if ( ( $ files = glob ( "{$dir}*{$this->properties['options']->extension}" ) ) === false ) { throw new ezcBaseFileNotFoundException ( $ dir , 'cache location' , 'Produced an error while globbing for files.' ) ; } foreach ( $ files as $ file ) { if ( $ this -> calcLifetime ( $ file ) == 0 ) { if ( @ unlink ( $ file ) === false ) { throw new ezcBaseFilePermissionException ( $ file , ezcBaseFileException :: WRITE , 'Could not unlink cache file.' ) ; } $ fileInfo = $ this -> extractIdentifier ( $ file ) ; $ purgedIds [ ] = $ fileInfo [ 'id' ] ; ++ $ purgeCount ; } if ( $ limit !== null && $ purgeCount >= $ limit ) { return $ purgedIds ; } } if ( ( $ dirs = glob ( "$dir*" , GLOB_ONLYDIR | GLOB_MARK ) ) === false ) { throw new ezcBaseFileNotFoundException ( $ dir , 'cache location' , 'Produced an error while globbing for directories.' ) ; } foreach ( $ dirs as $ dir ) { $ purgedIds = array_merge ( $ purgedIds , $ this -> purgeRecursive ( $ dir , $ limit , $ purgeCount ) ) ; if ( $ limit !== null && $ purgeCount >= $ limit ) { return $ purgedIds ; } } return $ purgedIds ; }
|
Recursively purge cache items .
|
11,379
|
public function reset ( ) { $ files = glob ( "{$this->properties['location']}*" ) ; foreach ( $ files as $ file ) { if ( is_dir ( $ file ) ) { ezcBaseFile :: removeRecursive ( $ file ) ; } else { if ( @ unlink ( $ file ) === false ) { throw new ezcBaseFilePermissionException ( $ file , ezcBaseFileException :: REMOVE , 'Could not unlink cache file.' ) ; } } } }
|
Resets the whole storage .
|
11,380
|
protected function search ( $ id = null , $ attributes = array ( ) ) { $ globArr = explode ( "-" , $ this -> generateIdentifier ( $ id , $ attributes ) , 2 ) ; if ( sizeof ( $ globArr ) > 1 ) { $ glob = $ globArr [ 0 ] . "-" . strtr ( $ globArr [ 1 ] , array ( '-' => '*' , '.' => '*' ) ) ; } else { $ glob = strtr ( $ globArr [ 0 ] , array ( '-' => '*' , '.' => '*' ) ) ; } $ glob = ( $ id === null ? '*' : '' ) . $ glob ; return $ this -> searchRecursive ( $ glob , $ this -> properties [ 'location' ] ) ; }
|
Search the storage for data .
|
11,381
|
protected function searchRecursive ( $ pattern , $ directory ) { $ itemArr = glob ( $ directory . $ pattern ) ; $ dirArr = glob ( $ directory . "*" , GLOB_ONLYDIR ) ; foreach ( $ dirArr as $ dirEntry ) { $ result = $ this -> searchRecursive ( $ pattern , "$dirEntry/" ) ; $ itemArr = array_merge ( $ itemArr , $ result ) ; } return $ itemArr ; }
|
Search the storage for data recursively .
|
11,382
|
public function generateIdentifier ( $ id , $ attributes = null ) { $ filename = ( string ) $ id ; $ illegalFileNameChars = array ( ' ' => '_' , '/' => DIRECTORY_SEPARATOR , '\\' => DIRECTORY_SEPARATOR , ) ; $ filename = strtr ( $ filename , $ illegalFileNameChars ) ; $ illegalChars = array ( '-' => '#' , ' ' => '%' , '=' => '+' , '.' => '+' , ) ; if ( is_array ( $ attributes ) && count ( $ attributes ) > 0 ) { ksort ( $ attributes ) ; foreach ( $ attributes as $ key => $ val ) { $ attrStr = '-' . strtr ( $ key , $ illegalChars ) . '=' . strtr ( $ val , $ illegalChars ) ; if ( strlen ( $ filename . $ attrStr ) > 250 ) { break ; } $ filename .= $ attrStr ; } } else { $ filename .= '-' ; } return $ filename . $ this -> properties [ 'options' ] [ 'extension' ] ; }
|
Generate the storage internal identifier from ID and attributes .
|
11,383
|
private function extractIdentifier ( $ filename ) { $ regex = '( (?:' . preg_quote ( $ this -> properties [ 'location' ] ) . ') (?P<id>.*) (?P<attr>(?:-[^-=]+=[^-]+)*) -? # This is added if no attributes are supplied. For whatever reason... (?P<ext>' . preg_quote ( $ this -> options -> extension ) . ') )Ux' ; if ( preg_match ( $ regex , $ filename , $ matches ) !== 1 ) { return array ( 'id' => '' , 'attributes' => '' , 'extension' => $ this -> options -> extension , ) ; } else { return array ( 'id' => $ matches [ 'id' ] , 'attributes' => $ matches [ 'attr' ] , 'extension' => $ matches [ 'ext' ] , ) ; } }
|
Extracts ID attributes and the file extension from a filename .
|
11,384
|
public static function initialize ( ) { if ( defined ( 'DACHI_KERNEL' ) ) return false ; define ( 'DACHI_KERNEL' , true ) ; require_once ( 'Kernel.functions.php' ) ; getExecutionTime ( ) ; date_default_timezone_set ( Configuration :: get ( 'dachi.timezone' ) ) ; error_reporting ( - 1 ) ; define ( 'WORKING_DIRECTORY' , getcwd ( ) ) ; Session :: start ( Configuration :: get ( 'sessions.name' ) , Configuration :: get ( 'sessions.domain' , false ) , Configuration :: get ( 'sessions.secure' , false ) ) ; }
|
Initialize the Dachi kernel .
|
11,385
|
public static function getEnvironment ( $ forceCheck = false ) { if ( self :: $ environment && ! $ forceCheck ) return self :: $ environment ; self :: $ environment = "local" ; if ( file_exists ( "dachi_environment" ) ) self :: $ environment = trim ( file_get_contents ( "dachi_environment" ) ) ; return self :: $ environment ; }
|
Get the current environment we are executing in .
|
11,386
|
public static function getGitHash ( $ forceCheck = false ) { if ( self :: $ git_hash && ! $ forceCheck ) return self :: $ git_hash ; self :: $ git_hash = "ffffff" ; if ( file_exists ( "dachi_git_hash" ) ) self :: $ git_hash = trim ( file_get_contents ( "dachi_git_hash" ) ) ; return self :: $ git_hash ; }
|
Get the current short git hash for the revision of code we are executing .
|
11,387
|
public static function getVersion ( $ fullVersion = false ) { return ( $ fullVersion ? ( "v" . self :: $ version . "." . self :: $ version_patch ) : self :: $ version ) ; }
|
Get the Dachi version .
|
11,388
|
protected function convertLogLevel ( $ level ) { $ map = [ Propel :: LOG_EMERG => LogLevel :: EMERGENCY , Propel :: LOG_ALERT => LogLevel :: ALERT , Propel :: LOG_CRIT => LogLevel :: CRITICAL , Propel :: LOG_ERR => LogLevel :: ERROR , Propel :: LOG_WARNING => LogLevel :: WARNING , Propel :: LOG_NOTICE => LogLevel :: NOTICE , Propel :: LOG_DEBUG => LogLevel :: DEBUG , ] ; return $ map [ $ level ] ; }
|
Converts Propel log levels to PSR log levels
|
11,389
|
protected function parseAndLogSqlQuery ( $ message ) { $ parts = explode ( '|' , $ message , 4 ) ; $ sql = trim ( $ parts [ 3 ] ) ; $ duration = 0 ; if ( preg_match ( '/([0-9]+\.[0-9]+)/' , $ parts [ 1 ] , $ matches ) ) { $ duration = ( float ) $ matches [ 1 ] ; } $ memory = 0 ; if ( preg_match ( '/([0-9]+\.[0-9]+) ([A-Z]{1,2})/' , $ parts [ 2 ] , $ matches ) ) { $ memory = ( float ) $ matches [ 1 ] ; if ( $ matches [ 2 ] == 'KB' ) { $ memory *= 1024 ; } elseif ( $ matches [ 2 ] == 'MB' ) { $ memory *= 1024 * 1024 ; } } $ this -> statements [ ] = [ 'sql' => $ sql , 'is_success' => true , 'duration' => $ duration , 'duration_str' => $ this -> formatDuration ( $ duration ) , 'memory' => $ memory , 'memory_str' => $ this -> formatBytes ( $ memory ) , ] ; $ this -> accumulatedTime += $ duration ; $ this -> peakMemory = max ( $ this -> peakMemory , $ memory ) ; return [ $ sql , $ this -> formatDuration ( $ duration ) ] ; }
|
Parse a log line to extract query information
|
11,390
|
public function load ( $ templatePath , $ userConfigurationPath , $ class = 'phpDocumentor\Configuration' ) { $ userConfigFilePath = $ this -> fetchUserConfigFileFromCommandLineOptions ( ) ; if ( $ this -> isValidFile ( $ userConfigFilePath ) ) { chdir ( dirname ( $ userConfigFilePath ) ) ; } else { $ userConfigFilePath = null ; } return $ this -> createConfigurationObject ( $ templatePath , $ userConfigurationPath , $ userConfigFilePath , $ class ) ; }
|
Loads the configuration from the provided paths and returns a populated configuration object .
|
11,391
|
private function createConfigurationObject ( $ templatePath , $ defaultUserConfigPath , $ customUserConfigPath , $ class ) { $ config = $ this -> serializer -> deserialize ( file_get_contents ( $ templatePath ) , $ class , 'xml' ) ; $ customUserConfigPath = $ customUserConfigPath ? : $ defaultUserConfigPath ; if ( $ customUserConfigPath !== null && is_readable ( $ customUserConfigPath ) ) { $ userConfigFile = $ this -> serializer -> deserialize ( file_get_contents ( $ customUserConfigPath ) , $ class , 'xml' ) ; $ config = $ this -> merger -> run ( $ config , $ userConfigFile ) ; } return $ config ; }
|
Combines the given configuration files and serializes a new Configuration object from them .
|
11,392
|
public function render ( \ WP_Post $ post = null ) { $ required = $ this -> get_required ( $ post ) ; $ label = esc_html ( $ this -> label ) ; $ desc_str = $ this -> description ; $ desc = ! empty ( $ desc_str ) ? sprintf ( '<p class="description">%s</p>' , $ this -> description ) : '' ; $ input = $ this -> get_field ( $ post ) ; echo $ this -> render_row ( $ label , $ required , $ input , $ desc , $ post ) ; }
|
Render input field
|
11,393
|
public function update ( $ value , \ WP_Post $ post = null ) { if ( $ this -> validate ( $ value ) ) { $ this -> save ( $ value , $ post ) ; } }
|
Save data as value
|
11,394
|
public function setCustomerData ( $ nombre_cliente = " " , $ documento = " " , $ respo_iva = 'C' , $ tipo_documento = " " , $ domicilio = '-' ) { $ nombre_cliente = substr ( $ nombre_cliente , 0 , 45 ) ; $ respo_iva = strtoupper ( $ respo_iva ) ; $ tipo_documento = strtoupper ( $ tipo_documento ) ; if ( $ respo_iva == 'I' || $ respo_iva == 'E' || $ respo_iva == 'A' || $ respo_iva == 'C' || $ respo_iva == 'T' ) { if ( $ tipo_documento == 'C' || $ tipo_documento == 'L' || $ tipo_documento == '0' || $ tipo_documento == '1' || $ tipo_documento == '2' || $ tipo_documento == '3' || $ tipo_documento == '4' ) { $ comando = "b" . $ this -> cm ( 'FS' ) . $ nombre_cliente . $ this -> cm ( 'FS' ) . $ documento . $ this -> cm ( 'FS' ) . $ respo_iva . $ this -> cm ( 'FS' ) . $ tipo_documento ; if ( $ domicilio ) { $ comando .= $ this -> cm ( 'FS' ) . $ domicilio ; } } else { return - 1 ; } } else { return - 2 ; } return $ comando ; }
|
Setea los datos del Cliente por lo general se usa para hacer factura A
|
11,395
|
public function getSingularForm ( $ root ) { $ singularForm = $ root ; if ( ! is_string ( $ root ) ) { throw new \ InvalidArgumentException ( 'The pluralizer expects a string.' ) ; } if ( ! in_array ( strtolower ( $ root ) , $ this -> uncountable ) ) { if ( null !== $ replacement = $ this -> checkIrregularForm ( $ root , array_flip ( $ this -> irregular ) ) ) { $ singularForm = $ replacement ; } elseif ( null !== $ replacement = $ this -> checkIrregularSuffix ( $ root , $ this -> singular ) ) { $ singularForm = $ replacement ; } elseif ( ! $ this -> isSingular ( $ root ) ) { return substr ( $ root , 0 , - 1 ) ; } } return $ singularForm ; }
|
Generate a singular name based on the passed in root .
|
11,396
|
protected function getDeprecatedCounter ( ProjectDescriptor $ project ) { $ deprecatedCounter = 0 ; foreach ( $ project -> getIndexes ( ) -> get ( 'elements' ) as $ element ) { if ( $ element -> isDeprecated ( ) ) { $ deprecatedCounter += 1 ; } } return $ deprecatedCounter ; }
|
Get number of deprecated elements .
|
11,397
|
public function allowPhpFunction ( $ func ) { if ( is_array ( $ func ) ) foreach ( $ func as $ fname ) $ this -> allowedPhpFunctions [ strtolower ( $ fname ) ] = true ; else $ this -> allowedPhpFunctions [ strtolower ( $ func ) ] = true ; }
|
adds a php function to the allowed list
|
11,398
|
public function allowDirectory ( $ path ) { if ( is_array ( $ path ) ) foreach ( $ path as $ dir ) $ this -> allowedDirectories [ realpath ( $ dir ) ] = true ; else $ this -> allowedDirectories [ realpath ( $ path ) ] = true ; }
|
adds a directory to the safelist for includes and other file - access plugins
|
11,399
|
public function disallowDirectory ( $ path ) { if ( is_array ( $ path ) ) foreach ( $ path as $ dir ) unset ( $ this -> allowedDirectories [ realpath ( $ dir ) ] ) ; else unset ( $ this -> allowedDirectories [ realpath ( $ path ) ] ) ; }
|
removes a directory from the safelist
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.