idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
50,200
public function jsonSerialize ( ) { if ( ! $ this -> originalFilename ( ) ) { return [ ] ; } $ data = [ ] ; foreach ( $ this -> variants ( true ) as $ variant ) { $ data [ $ variant ] = [ 'path' => $ this -> variantPath ( $ variant ) , 'url' => $ this -> url ( $ variant ) ] ; } return $ data ; }
Return a JSON representation of this class .
50,201
protected function getOrMakeTargetInstance ( ) { if ( $ this -> target ) { return $ this -> target ; } $ this -> target = new InterpolatingTarget ( $ this -> interpolator , $ this , $ this -> config -> path ( ) , $ this -> config -> variantPath ( ) ) ; $ this -> target -> setVariantFilenames ( $ this -> variantFilenames ( ) ) ; $ this -> target -> setVariantExtensions ( $ this -> variantExtensions ( ) ) ; return $ this -> target ; }
Returns the target instance to be passed to the file handler .
50,202
protected function makeTargetInstanceWithCurrentData ( ) { $ this -> target = new InterpolatingTarget ( $ this -> interpolator , $ this -> getCurrentAttachmentData ( ) , $ this -> config -> path ( ) , $ this -> config -> variantPath ( ) ) ; $ this -> target -> setVariantFilenames ( $ this -> variantFilenames ( ) ) ; $ this -> target -> setVariantExtensions ( $ this -> variantExtensions ( ) ) ; return $ this -> target ; }
Returns a target instance with fixed historical data for the current state .
50,203
protected function variantFilenames ( ) { $ names = [ ] ; foreach ( $ this -> variants ( ) as $ variant ) { $ names [ $ variant ] = $ this -> variantFilename ( $ variant ) ; } return $ names ; }
Returns filenames keyed by variant .
50,204
protected function variantExtensions ( ) { $ extensions = $ this -> config -> variantExtensions ( ) ; $ variants = $ this -> variantsAttribute ( ) ; if ( ! empty ( $ variants ) ) { foreach ( $ this -> variants ( ) as $ variant ) { $ extension = Arr :: get ( $ variants , "{$variant}.ext" ) ; if ( $ extension ) { $ extensions [ $ variant ] = $ extension ; continue ; } } } return $ extensions ; }
Returns alternative extensions keyed by variant .
50,205
public function afterSave ( AttachableInterface $ instance ) { $ this -> instance = $ instance ; $ this -> save ( ) ; $ this -> performCallableHookAfterProcessing ( ) ; }
Processes the write queue .
50,206
public function beforeDelete ( AttachableInterface $ instance ) { $ this -> instance = $ instance ; if ( ! $ this -> config -> preserveFiles ( ) ) { $ this -> clear ( ) ; } }
Queues up this attachments files for deletion .
50,207
protected function flushWrites ( ) { if ( ! $ this -> queuedForWrite ) { return ; } $ target = $ this -> getOrMakeTargetInstance ( ) ; $ storedFiles = $ this -> handler -> process ( $ this -> uploadedFile , $ target , $ this -> config -> toArray ( ) ) ; if ( $ this -> shouldVariantInformationBeStored ( ) ) { $ originalExtension = pathinfo ( $ this -> originalFilename ( ) , PATHINFO_EXTENSION ) ; $ originalMimeType = $ this -> contentType ( ) ; $ variantInformation = [ ] ; foreach ( $ storedFiles as $ variant => $ storedFile ) { if ( $ storedFile -> extension ( ) == $ originalExtension && $ storedFile -> mimeType ( ) == $ originalMimeType ) { continue ; } $ variantInformation [ $ variant ] = [ 'ext' => $ storedFile -> extension ( ) , 'type' => $ storedFile -> mimeType ( ) , ] ; } $ this -> instanceWrite ( 'variants' , json_encode ( $ variantInformation ) ) ; $ this -> instance -> save ( ) ; } $ this -> queuedForWrite = false ; }
Process the queuedForWrite queue .
50,208
protected function flushDeletes ( ) { if ( ! $ this -> deleteTarget ) { return ; } foreach ( $ this -> queuedForDelete as $ variant ) { $ this -> handler -> deleteVariant ( $ this -> deleteTarget , $ variant ) ; } $ this -> queuedForDelete = [ ] ; }
Process the queuedForDeletion queue .
50,209
protected function getCurrentAttachmentData ( ) { $ attributes = [ 'file_name' => $ this -> originalFilename ( ) , 'file_size' => $ this -> size ( ) , 'content_type' => $ this -> contentType ( ) , 'updated_at' => $ this -> updatedAt ( ) , 'created_at' => $ this -> createdAt ( ) , 'variants' => $ this -> variantsAttribute ( ) , ] ; $ variants = [ ] ; foreach ( $ this -> variants ( ) as $ variant ) { $ variants [ $ variant ] = [ 'file_name' => $ this -> variantFilename ( $ variant ) , 'content_type' => $ this -> variantContentType ( $ variant ) , 'extension' => $ this -> variantExtension ( $ variant ) , ] ; } return new AttachmentData ( $ this -> name , $ this -> getConfig ( ) , $ attributes , $ variants , $ this -> getInstanceKey ( ) , $ this -> getInstanceClass ( ) ) ; }
Returns the current attachment state data .
50,210
public function clearAttributes ( ) { $ this -> instanceWrite ( 'file_name' , null ) ; $ this -> instanceWrite ( 'file_size' , null ) ; $ this -> instanceWrite ( 'content_type' , null ) ; $ this -> instanceWrite ( 'updated_at' , null ) ; $ this -> instanceWrite ( 'variants' , null ) ; }
Clears all attachment related model attributes .
50,211
public function instanceWrite ( $ property , $ value ) { if ( $ property !== 'file_name' && ! $ this -> config -> attributeProperty ( $ property ) ) { return ; } $ this -> instance -> setAttribute ( "{$this->name}_{$property}" , $ value ) ; }
Sets an attachment property on the model instance .
50,212
private function attach ( ) { try { $ this -> semaphore = sem_get ( $ this -> key ) ; $ this -> mutex = new SemaphoreMutex ( $ this -> semaphore ) ; } catch ( \ InvalidArgumentException $ e ) { throw new StorageException ( "Could not get semaphore id." , 0 , $ e ) ; } $ this -> memory = shm_attach ( $ this -> key , 128 ) ; if ( ! is_resource ( $ this -> memory ) ) { throw new StorageException ( "Failed to attach to shared memory." ) ; } }
Attaches the shared memory segment .
50,213
private function forVendor ( array $ map , $ default = "" ) { $ vendor = $ this -> pdo -> getAttribute ( \ PDO :: ATTR_DRIVER_NAME ) ; return isset ( $ map [ $ vendor ] ) ? $ map [ $ vendor ] : $ default ; }
Returns a vendor specific dialect value .
50,214
private function querySingleValue ( $ sql , $ parameters = [ ] ) { try { $ statement = $ this -> pdo -> prepare ( $ sql ) ; $ statement -> execute ( $ parameters ) ; $ value = $ statement -> fetchColumn ( ) ; $ statement -> closeCursor ( ) ; if ( $ value === false ) { throw new StorageException ( "The query returned no result." ) ; } return $ value ; } catch ( \ PDOException $ e ) { throw new StorageException ( "The query failed." , 0 , $ e ) ; } }
Returns one value from a query .
50,215
private function onErrorRollback ( callable $ code ) { if ( ! $ this -> pdo -> inTransaction ( ) ) { return call_user_func ( $ code ) ; } $ this -> pdo -> exec ( "SAVEPOINT onErrorRollback" ) ; try { $ result = call_user_func ( $ code ) ; } catch ( \ Exception $ e ) { $ this -> pdo -> exec ( "ROLLBACK TO SAVEPOINT onErrorRollback" ) ; throw $ e ; } $ this -> pdo -> exec ( "RELEASE SAVEPOINT onErrorRollback" ) ; return $ result ; }
Rollback to an implicit savepoint .
50,216
public function convertMicrotimeToTokens ( $ microtime ) { $ delta = bcsub ( microtime ( true ) , $ microtime , $ this -> bcScale ) ; return $ this -> convertSecondsToTokens ( $ delta ) ; }
Converts a timestamp into tokens .
50,217
public static function unpack ( $ string ) { if ( strlen ( $ string ) !== 8 ) { throw new StorageException ( "The string is not 64 bit long." ) ; } $ unpack = unpack ( "d" , $ string ) ; if ( ! is_array ( $ unpack ) || ! array_key_exists ( 1 , $ unpack ) ) { throw new StorageException ( "Could not unpack string." ) ; } return $ unpack [ 1 ] ; }
Unpacks a 64 bit double from an 8 byte string .
50,218
private function open ( ) { $ this -> fileHandle = fopen ( $ this -> path , "c+" ) ; if ( ! is_resource ( $ this -> fileHandle ) ) { throw new StorageException ( "Could not open '$this->path'." ) ; } $ this -> mutex = new FlockMutex ( $ this -> fileHandle ) ; }
Opens the file and initializes the mutex .
50,219
public function consume ( $ tokens ) { $ timedOut = is_null ( $ this -> timeout ) ? null : ( microtime ( true ) + $ this -> timeout ) ; while ( ! $ this -> bucket -> consume ( $ tokens , $ seconds ) ) { self :: throwTimeoutIfExceeded ( $ timedOut ) ; $ seconds = self :: keepSecondsWithinTimeout ( $ seconds , $ timedOut ) ; if ( $ seconds > 1 ) { $ sleepSeconds = ( ( int ) $ seconds ) - 1 ; sleep ( $ sleepSeconds ) ; $ seconds -= $ sleepSeconds ; } usleep ( max ( 1000 , $ seconds * 1000000 ) ) ; } }
Consumes tokens .
50,220
private static function keepSecondsWithinTimeout ( $ seconds , $ timedOut ) { if ( is_null ( $ timedOut ) ) { return $ seconds ; } $ remainingSeconds = max ( $ timedOut - microtime ( true ) , 0 ) ; return min ( $ remainingSeconds , $ seconds ) ; }
Adjusts the wait seconds to be within the timeout .
50,221
public function bootstrap ( $ tokens = 0 ) { try { if ( $ tokens > $ this -> capacity ) { throw new \ LengthException ( "Initial token amount ($tokens) is larger than the capacity ($this->capacity)." ) ; } if ( $ tokens < 0 ) { throw new \ InvalidArgumentException ( "Initial token amount ($tokens) should be greater than 0." ) ; } $ this -> storage -> getMutex ( ) -> check ( function ( ) { return ! $ this -> storage -> isBootstrapped ( ) ; } ) -> then ( function ( ) use ( $ tokens ) { $ this -> storage -> bootstrap ( $ this -> tokenConverter -> convertTokensToMicrotime ( $ tokens ) ) ; } ) ; } catch ( MutexException $ e ) { throw new StorageException ( "Could not lock bootstrapping" , 0 , $ e ) ; } }
Bootstraps the storage with an initial amount of tokens .
50,222
public function consume ( $ tokens , & $ seconds = 0 ) { try { if ( $ tokens > $ this -> capacity ) { throw new \ LengthException ( "Token amount ($tokens) is larger than the capacity ($this->capacity)." ) ; } if ( $ tokens <= 0 ) { throw new \ InvalidArgumentException ( "Token amount ($tokens) should be greater than 0." ) ; } return $ this -> storage -> getMutex ( ) -> synchronized ( function ( ) use ( $ tokens , & $ seconds ) { $ tokensAndMicrotime = $ this -> loadTokensAndTimestamp ( ) ; $ microtime = $ tokensAndMicrotime [ "microtime" ] ; $ availableTokens = $ tokensAndMicrotime [ "tokens" ] ; $ delta = $ availableTokens - $ tokens ; if ( $ delta < 0 ) { $ this -> storage -> letMicrotimeUnchanged ( ) ; $ passed = microtime ( true ) - $ microtime ; $ seconds = max ( 0 , $ this -> tokenConverter -> convertTokensToSeconds ( $ tokens ) - $ passed ) ; return false ; } else { $ microtime += $ this -> tokenConverter -> convertTokensToSeconds ( $ tokens ) ; $ this -> storage -> setMicrotime ( $ microtime ) ; $ seconds = 0 ; return true ; } } ) ; } catch ( MutexException $ e ) { throw new StorageException ( "Could not lock token consumption." , 0 , $ e ) ; } }
Consumes tokens from the bucket .
50,223
private function loadTokensAndTimestamp ( ) { $ microtime = $ this -> storage -> getMicrotime ( ) ; $ minMicrotime = $ this -> tokenConverter -> convertTokensToMicrotime ( $ this -> capacity ) ; if ( $ minMicrotime > $ microtime ) { $ microtime = $ minMicrotime ; } $ tokens = $ this -> tokenConverter -> convertMicrotimeToTokens ( $ microtime ) ; return [ "tokens" => $ tokens , "microtime" => $ microtime ] ; }
Loads the stored timestamp and its respective amount of tokens .
50,224
private function updateResult ( string $ value ) : string { $ value = str_replace ( self :: $ foundEntitiesCache [ 0 ] , self :: $ foundEntitiesCache [ 1 ] , $ value ) ; if ( strstr ( $ value , 'html5-dom-document-internal-entity' ) !== false ) { $ search = [ ] ; $ replace = [ ] ; $ matches = [ ] ; preg_match_all ( '/html5-dom-document-internal-entity([12])-(.*?)-end/' , $ value , $ matches ) ; $ matches [ 0 ] = array_unique ( $ matches [ 0 ] ) ; foreach ( $ matches [ 0 ] as $ i => $ match ) { $ search [ ] = $ match ; $ replace [ ] = html_entity_decode ( ( $ matches [ 1 ] [ $ i ] === '1' ? '&' : '&#' ) . $ matches [ 2 ] [ $ i ] . ';' ) ; } $ value = str_replace ( $ search , $ replace , $ value ) ; self :: $ foundEntitiesCache [ 0 ] = array_merge ( self :: $ foundEntitiesCache [ 0 ] , $ search ) ; self :: $ foundEntitiesCache [ 1 ] = array_merge ( self :: $ foundEntitiesCache [ 1 ] , $ replace ) ; unset ( $ search ) ; unset ( $ replace ) ; unset ( $ matches ) ; } return $ value ; }
Updates the result value before returning it .
50,225
public function getAttribute ( $ name ) : string { if ( $ this -> attributes -> length === 0 ) { return '' ; } $ value = parent :: getAttribute ( $ name ) ; return $ value !== '' ? ( strstr ( $ value , 'html5-dom-document-internal-entity' ) !== false ? $ this -> updateResult ( $ value ) : $ value ) : '' ; }
Returns the value for the attribute name specified .
50,226
public function getAttributes ( ) : array { $ attributes = [ ] ; foreach ( $ this -> attributes as $ attributeName => $ attribute ) { $ value = $ attribute -> value ; $ attributes [ $ attributeName ] = $ value !== '' ? ( strstr ( $ value , 'html5-dom-document-internal-entity' ) !== false ? $ this -> updateResult ( $ value ) : $ value ) : '' ; } return $ attributes ; }
Returns an array containing all attributes .
50,227
private function addHtmlElementIfMissing ( ) : bool { if ( $ this -> getElementsByTagName ( 'html' ) -> length === 0 ) { if ( ! isset ( self :: $ newObjectsCache [ 'htmlelement' ] ) ) { self :: $ newObjectsCache [ 'htmlelement' ] = new \ DOMElement ( 'html' ) ; } $ this -> appendChild ( clone ( self :: $ newObjectsCache [ 'htmlelement' ] ) ) ; return true ; } return false ; }
Adds the HTML tag to the document if missing .
50,228
private function addHeadElementIfMissing ( ) : bool { if ( $ this -> getElementsByTagName ( 'head' ) -> length === 0 ) { $ htmlElement = $ this -> getElementsByTagName ( 'html' ) -> item ( 0 ) ; if ( ! isset ( self :: $ newObjectsCache [ 'headelement' ] ) ) { self :: $ newObjectsCache [ 'headelement' ] = new \ DOMElement ( 'head' ) ; } $ headElement = clone ( self :: $ newObjectsCache [ 'headelement' ] ) ; if ( $ htmlElement -> firstChild === null ) { $ htmlElement -> appendChild ( $ headElement ) ; } else { $ htmlElement -> insertBefore ( $ headElement , $ htmlElement -> firstChild ) ; } return true ; } return false ; }
Adds the HEAD tag to the document if missing .
50,229
private function addBodyElementIfMissing ( ) : bool { if ( $ this -> getElementsByTagName ( 'body' ) -> length === 0 ) { if ( ! isset ( self :: $ newObjectsCache [ 'bodyelement' ] ) ) { self :: $ newObjectsCache [ 'bodyelement' ] = new \ DOMElement ( 'body' ) ; } $ this -> getElementsByTagName ( 'html' ) -> item ( 0 ) -> appendChild ( clone ( self :: $ newObjectsCache [ 'bodyelement' ] ) ) ; return true ; } return false ; }
Adds the BODY tag to the document if missing .
50,230
public function saveHTMLFile ( $ filename ) { if ( ! is_writable ( $ filename ) ) { return false ; } $ result = $ this -> saveHTML ( ) ; file_put_contents ( $ filename , $ result ) ; $ bytesWritten = filesize ( $ filename ) ; if ( $ bytesWritten === strlen ( $ result ) ) { return $ bytesWritten ; } return false ; }
Dumps the internal document into a file using HTML formatting .
50,231
public function createInsertTarget ( string $ name ) { if ( ! $ this -> loaded ) { $ this -> loadHTML ( '' ) ; } $ element = $ this -> createElement ( 'html5-dom-document-insert-target' ) ; $ element -> setAttribute ( 'name' , $ name ) ; return $ element ; }
Creates an element that will be replaced by the new body in insertHTML .
50,232
public function item ( int $ index ) { return $ this -> offsetExists ( $ index ) ? $ this -> offsetGet ( $ index ) : null ; }
Returns the item at the specified index .
50,233
public function add ( string ... $ tokens ) { if ( count ( $ tokens ) === 0 ) { return ; } foreach ( $ tokens as $ t ) { if ( in_array ( $ t , $ this -> tokens ) ) { continue ; } $ this -> tokens [ ] = $ t ; } $ this -> setAttributeValue ( ) ; }
Adds the given tokens to the list .
50,234
public function remove ( string ... $ tokens ) { if ( count ( $ tokens ) === 0 ) { return ; } if ( count ( $ this -> tokens ) === 0 ) { return ; } foreach ( $ tokens as $ t ) { $ i = array_search ( $ t , $ this -> tokens ) ; if ( $ i === false ) { continue ; } array_splice ( $ this -> tokens , $ i , 1 ) ; } $ this -> setAttributeValue ( ) ; }
Removes the specified tokens from the list . If the string does not exist in the list no error is thrown .
50,235
public function toggle ( string $ token , bool $ force = null ) : bool { $ this -> tokenize ( ) ; $ isThereAfter = false ; $ i = array_search ( $ token , $ this -> tokens ) ; if ( is_null ( $ force ) ) { if ( $ i === false ) { $ this -> tokens [ ] = $ token ; $ isThereAfter = true ; } else { array_splice ( $ this -> tokens , $ i , 1 ) ; } } else { if ( $ force ) { if ( $ i === false ) { $ this -> tokens [ ] = $ token ; } $ isThereAfter = true ; } else { if ( $ i !== false ) { array_splice ( $ this -> tokens , $ i , 1 ) ; } } } $ this -> setAttributeValue ( ) ; return $ isThereAfter ; }
Removes a given token from the list and returns false . If token doesn t exist it s added and the function returns true .
50,236
public function contains ( string $ token ) : bool { $ this -> tokenize ( ) ; return in_array ( $ token , $ this -> tokens ) ; }
Returns true if the list contains the given token otherwise false .
50,237
public function replace ( string $ old , string $ new ) { if ( $ old === $ new ) { return ; } $ this -> tokenize ( ) ; $ i = array_search ( $ old , $ this -> tokens ) ; if ( $ i !== false ) { $ j = array_search ( $ new , $ this -> tokens ) ; if ( $ j === false ) { $ this -> tokens [ $ i ] = $ new ; } else { array_splice ( $ this -> tokens , $ i , 1 ) ; } $ this -> setAttributeValue ( ) ; } }
Replaces an existing token with a new token .
50,238
protected function getParametersAliases ( ) { return array_merge ( parent :: getParametersAliases ( ) , array ( "login" => GenerisRdf :: PROPERTY_USER_LOGIN , "password" => GenerisRdf :: PROPERTY_USER_PASSWORD , "guiLg" => GenerisRdf :: PROPERTY_USER_UILG , "dataLg" => GenerisRdf :: PROPERTY_USER_DEFLG , "firstName" => GenerisRdf :: PROPERTY_USER_FIRSTNAME , "lastName" => GenerisRdf :: PROPERTY_USER_LASTNAME , "mail" => GenerisRdf :: PROPERTY_USER_MAIL , "type" => OntologyRdf :: RDF_TYPE ) ) ; }
Optionnaly a specific rest controller may declare aliases for parameters used for the rest communication
50,239
protected function initCors ( ) { $ headers = Yii :: $ app -> getResponse ( ) -> getHeaders ( ) ; $ headers -> set ( 'Access-Control-Allow-Headers' , implode ( ', ' , [ 'Content-Type' , $ this -> apiKeyParam , 'Authorization' , ] ) ) ; $ headers -> set ( 'Access-Control-Allow-Methods' , 'GET, POST, DELETE, PUT' ) ; $ headers -> set ( 'Access-Control-Allow-Origin' , '*' ) ; }
Init cors .
50,240
function setCharset ( $ charset ) { $ locale = setlocale ( LC_CTYPE , 0 ) ; setlocale ( LC_CTYPE , 'en_US' ) ; $ this -> _charset = strtolower ( $ charset ) ; setlocale ( LC_CTYPE , $ locale ) ; }
Sets the charset of the provided table data .
50,241
function setBorder ( $ border ) { if ( $ border === self :: CONSOLE_TABLE_BORDER_ASCII ) { $ intersection = '+' ; $ horizontal = '-' ; $ vertical = '|' ; } else { if ( is_string ( $ border ) ) { $ intersection = $ horizontal = $ vertical = $ border ; } else { if ( $ border == '' ) { $ intersection = $ horizontal = $ vertical = '' ; } else { extract ( $ border ) ; } } } $ this -> _border = array ( 'intersection' => $ intersection , 'horizontal' => $ horizontal , 'vertical' => $ vertical , ) ; }
Set the table border settings
50,242
function setBorderVisibility ( $ visibility ) { $ this -> _borderVisibility = array_merge ( $ this -> _borderVisibility , array_intersect_key ( $ visibility , $ this -> _borderVisibility ) ) ; }
Set which borders shall be shown .
50,243
function setAlign ( $ col_id , $ align = self :: CONSOLE_TABLE_ALIGN_LEFT ) { switch ( $ align ) { case self :: CONSOLE_TABLE_ALIGN_CENTER : $ pad = STR_PAD_BOTH ; break ; case self :: CONSOLE_TABLE_ALIGN_RIGHT : $ pad = STR_PAD_LEFT ; break ; default : $ pad = STR_PAD_RIGHT ; break ; } $ this -> _col_align [ $ col_id ] = $ pad ; }
Sets the alignment for the columns .
50,244
function insertRow ( $ row , $ row_id = 0 ) { array_splice ( $ this -> _data , $ row_id , 0 , array ( $ row ) ) ; $ this -> _updateRowsCols ( $ row ) ; }
Inserts a row after a given row number in the table .
50,245
function addData ( $ data , $ col_id = 0 , $ row_id = 0 ) { foreach ( $ data as $ row ) { if ( $ row === self :: CONSOLE_TABLE_HORIZONTAL_RULE ) { $ this -> _data [ $ row_id ] = self :: CONSOLE_TABLE_HORIZONTAL_RULE ; $ row_id ++ ; continue ; } $ starting_col = $ col_id ; foreach ( $ row as $ cell ) { $ this -> _data [ $ row_id ] [ $ starting_col ++ ] = $ cell ; } $ this -> _updateRowsCols ( ) ; $ this -> _max_cols = max ( $ this -> _max_cols , $ starting_col ) ; $ row_id ++ ; } }
Adds data to the table .
50,246
function _calculateTotals ( ) { if ( empty ( $ this -> _calculateTotals ) ) { return ; } $ this -> addSeparator ( ) ; $ totals = array ( ) ; foreach ( $ this -> _data as $ row ) { if ( is_array ( $ row ) ) { foreach ( $ this -> _calculateTotals as $ columnID ) { $ totals [ $ columnID ] += $ row [ $ columnID ] ; } } } $ this -> _data [ ] = $ totals ; $ this -> _updateRowsCols ( ) ; }
Calculates totals for columns .
50,247
function _validateTable ( ) { if ( ! empty ( $ this -> _headers ) ) { $ this -> _calculateRowHeight ( - 1 , $ this -> _headers [ 0 ] ) ; } for ( $ i = 0 ; $ i < $ this -> _max_rows ; $ i ++ ) { for ( $ j = 0 ; $ j < $ this -> _max_cols ; $ j ++ ) { if ( ! isset ( $ this -> _data [ $ i ] [ $ j ] ) && ( ! isset ( $ this -> _data [ $ i ] ) || $ this -> _data [ $ i ] !== self :: CONSOLE_TABLE_HORIZONTAL_RULE ) ) { $ this -> _data [ $ i ] [ $ j ] = '' ; } } $ this -> _calculateRowHeight ( $ i , $ this -> _data [ $ i ] ) ; if ( $ this -> _data [ $ i ] !== self :: CONSOLE_TABLE_HORIZONTAL_RULE ) { ksort ( $ this -> _data [ $ i ] ) ; } } $ this -> _splitMultilineRows ( ) ; for ( $ i = 0 ; $ i < count ( $ this -> _headers ) ; $ i ++ ) { $ this -> _calculateCellLengths ( $ this -> _headers [ $ i ] ) ; } for ( $ i = 0 ; $ i < $ this -> _max_rows ; $ i ++ ) { $ this -> _calculateCellLengths ( $ this -> _data [ $ i ] ) ; } ksort ( $ this -> _data ) ; }
Ensures that column and row counts are correct .
50,248
function _splitMultilineRows ( ) { ksort ( $ this -> _data ) ; $ sections = array ( & $ this -> _headers , & $ this -> _data ) ; $ max_rows = array ( count ( $ this -> _headers ) , $ this -> _max_rows ) ; $ row_height_offset = array ( - 1 , 0 ) ; for ( $ s = 0 ; $ s <= 1 ; $ s ++ ) { $ inserted = 0 ; $ new_data = $ sections [ $ s ] ; for ( $ i = 0 ; $ i < $ max_rows [ $ s ] ; $ i ++ ) { $ height = $ this -> _row_heights [ $ i + $ row_height_offset [ $ s ] ] ; if ( $ height > 1 ) { $ split = array ( ) ; for ( $ j = 0 ; $ j < $ this -> _max_cols ; $ j ++ ) { $ split [ $ j ] = preg_split ( '/\r?\n|\r/' , $ sections [ $ s ] [ $ i ] [ $ j ] ) ; } $ new_rows = array ( ) ; for ( $ i2 = 0 ; $ i2 < $ height ; $ i2 ++ ) { for ( $ j = 0 ; $ j < $ this -> _max_cols ; $ j ++ ) { $ new_rows [ $ i2 ] [ $ j ] = ! isset ( $ split [ $ j ] [ $ i2 ] ) ? '' : $ split [ $ j ] [ $ i2 ] ; } } array_splice ( $ new_data , $ i + $ inserted , 1 , $ new_rows ) ; $ inserted += count ( $ new_rows ) - 1 ; } } if ( $ inserted > 0 ) { $ sections [ $ s ] = $ new_data ; $ this -> _updateRowsCols ( ) ; } } }
Splits multiline rows into many smaller one - line rows .
50,249
function _buildTable ( ) { if ( ! count ( $ this -> _data ) ) { return '' ; } $ vertical = $ this -> _border [ 'vertical' ] ; $ separator = $ this -> _getSeparator ( ) ; $ return = array ( ) ; for ( $ i = 0 ; $ i < count ( $ this -> _data ) ; $ i ++ ) { for ( $ j = 0 ; $ j < count ( $ this -> _data [ $ i ] ) ; $ j ++ ) { if ( $ this -> _data [ $ i ] !== self :: CONSOLE_TABLE_HORIZONTAL_RULE && $ this -> _strlen ( $ this -> _data [ $ i ] [ $ j ] ) < $ this -> _cell_lengths [ $ j ] ) { $ this -> _data [ $ i ] [ $ j ] = $ this -> _strpad ( $ this -> _data [ $ i ] [ $ j ] , $ this -> _cell_lengths [ $ j ] , ' ' , $ this -> _col_align [ $ j ] ) ; } } if ( $ this -> _data [ $ i ] !== self :: CONSOLE_TABLE_HORIZONTAL_RULE ) { $ row_begin = $ this -> _borderVisibility [ 'left' ] ? $ vertical . str_repeat ( ' ' , $ this -> _padding ) : '' ; $ row_end = $ this -> _borderVisibility [ 'right' ] ? str_repeat ( ' ' , $ this -> _padding ) . $ vertical : '' ; $ implode_char = str_repeat ( ' ' , $ this -> _padding ) . $ vertical . str_repeat ( ' ' , $ this -> _padding ) ; $ return [ ] = $ row_begin . implode ( $ implode_char , $ this -> _data [ $ i ] ) . $ row_end ; } elseif ( ! empty ( $ separator ) ) { $ return [ ] = $ separator ; } } $ return = implode ( PHP_EOL , $ return ) ; if ( ! empty ( $ separator ) ) { if ( $ this -> _borderVisibility [ 'inner' ] ) { $ return = $ separator . PHP_EOL . $ return ; } if ( $ this -> _borderVisibility [ 'bottom' ] ) { $ return .= PHP_EOL . $ separator ; } } $ return .= PHP_EOL ; if ( ! empty ( $ this -> _headers ) ) { $ return = $ this -> _getHeaderLine ( ) . PHP_EOL . $ return ; } return $ return ; }
Builds the table .
50,250
function _getHeaderLine ( ) { for ( $ j = 0 ; $ j < count ( $ this -> _headers ) ; $ j ++ ) { for ( $ i = 0 ; $ i < $ this -> _max_cols ; $ i ++ ) { if ( ! isset ( $ this -> _headers [ $ j ] [ $ i ] ) ) { $ this -> _headers [ $ j ] [ $ i ] = '' ; } } } for ( $ j = 0 ; $ j < count ( $ this -> _headers ) ; $ j ++ ) { for ( $ i = 0 ; $ i < count ( $ this -> _headers [ $ j ] ) ; $ i ++ ) { if ( $ this -> _strlen ( $ this -> _headers [ $ j ] [ $ i ] ) < $ this -> _cell_lengths [ $ i ] ) { $ this -> _headers [ $ j ] [ $ i ] = $ this -> _strpad ( $ this -> _headers [ $ j ] [ $ i ] , $ this -> _cell_lengths [ $ i ] , ' ' , $ this -> _col_align [ $ i ] ) ; } } } $ vertical = $ this -> _border [ 'vertical' ] ; $ row_begin = $ this -> _borderVisibility [ 'left' ] ? $ vertical . str_repeat ( ' ' , $ this -> _padding ) : '' ; $ row_end = $ this -> _borderVisibility [ 'right' ] ? str_repeat ( ' ' , $ this -> _padding ) . $ vertical : '' ; $ implode_char = str_repeat ( ' ' , $ this -> _padding ) . $ vertical . str_repeat ( ' ' , $ this -> _padding ) ; $ separator = $ this -> _getSeparator ( ) ; if ( ! empty ( $ separator ) && $ this -> _borderVisibility [ 'top' ] ) { $ return [ ] = $ separator ; } for ( $ j = 0 ; $ j < count ( $ this -> _headers ) ; $ j ++ ) { $ return [ ] = $ row_begin . implode ( $ implode_char , $ this -> _headers [ $ j ] ) . $ row_end ; } return implode ( PHP_EOL , $ return ) ; }
Returns the header line for the table .
50,251
function _updateRowsCols ( $ rowdata = null ) { $ this -> _max_cols = max ( $ this -> _max_cols , count ( $ rowdata ) ) ; ksort ( $ this -> _data ) ; $ keys = array_keys ( $ this -> _data ) ; $ this -> _max_rows = end ( $ keys ) + 1 ; switch ( $ this -> _defaultAlign ) { case self :: CONSOLE_TABLE_ALIGN_CENTER : $ pad = STR_PAD_BOTH ; break ; case self :: CONSOLE_TABLE_ALIGN_RIGHT : $ pad = STR_PAD_LEFT ; break ; default : $ pad = STR_PAD_RIGHT ; break ; } for ( $ i = 0 ; $ i < $ this -> _max_cols ; $ i ++ ) { if ( ! isset ( $ this -> _col_align [ $ i ] ) ) { $ this -> _col_align [ $ i ] = $ pad ; } } }
Updates values for maximum columns and rows .
50,252
function _calculateCellLengths ( $ row ) { for ( $ i = 0 ; $ i < count ( $ row ) ; $ i ++ ) { if ( ! isset ( $ this -> _cell_lengths [ $ i ] ) ) { $ this -> _cell_lengths [ $ i ] = 0 ; } $ this -> _cell_lengths [ $ i ] = max ( $ this -> _cell_lengths [ $ i ] , $ this -> _strlen ( $ row [ $ i ] ) ) ; } }
Calculates the maximum length for each column of a row .
50,253
function _calculateRowHeight ( $ row_number , $ row ) { if ( ! isset ( $ this -> _row_heights [ $ row_number ] ) ) { $ this -> _row_heights [ $ row_number ] = 1 ; } if ( $ row === self :: CONSOLE_TABLE_HORIZONTAL_RULE ) { return ; } for ( $ i = 0 , $ c = count ( $ row ) ; $ i < $ c ; ++ $ i ) { $ lines = preg_split ( '/\r?\n|\r/' , $ row [ $ i ] ) ; $ this -> _row_heights [ $ row_number ] = max ( $ this -> _row_heights [ $ row_number ] , count ( $ lines ) ) ; } }
Calculates the maximum height for all columns of a row .
50,254
function _strlen ( $ str ) { static $ mbstring ; if ( ! isset ( $ mbstring ) ) { $ mbstring = function_exists ( 'mb_strwidth' ) ; } if ( $ mbstring ) { return mb_strwidth ( $ str , $ this -> _charset ) ; } return strlen ( $ str ) ; }
Returns the character length of a string .
50,255
function _strpad ( $ input , $ length , $ pad = ' ' , $ type = STR_PAD_RIGHT ) { $ mb_length = $ this -> _strlen ( $ input ) ; $ sb_length = strlen ( $ input ) ; $ pad_length = $ this -> _strlen ( $ pad ) ; if ( $ mb_length >= $ length ) { return $ input ; } if ( $ mb_length == $ sb_length && $ pad_length == strlen ( $ pad ) ) { return str_pad ( $ input , $ length , $ pad , $ type ) ; } switch ( $ type ) { case STR_PAD_LEFT : $ left = $ length - $ mb_length ; $ output = $ this -> _substr ( str_repeat ( $ pad , ceil ( $ left / $ pad_length ) ) , 0 , $ left , $ this -> _charset ) . $ input ; break ; case STR_PAD_BOTH : $ left = floor ( ( $ length - $ mb_length ) / 2 ) ; $ right = ceil ( ( $ length - $ mb_length ) / 2 ) ; $ output = $ this -> _substr ( str_repeat ( $ pad , ceil ( $ left / $ pad_length ) ) , 0 , $ left , $ this -> _charset ) . $ input . $ this -> _substr ( str_repeat ( $ pad , ceil ( $ right / $ pad_length ) ) , 0 , $ right , $ this -> _charset ) ; break ; case STR_PAD_RIGHT : $ right = $ length - $ mb_length ; $ output = $ input . $ this -> _substr ( str_repeat ( $ pad , ceil ( $ right / $ pad_length ) ) , 0 , $ right , $ this -> _charset ) ; break ; } return $ output ; }
Returns a string padded to a certain length with another string .
50,256
public static function track ( ) { $ ip = Request :: server ( 'REMOTE_ADDR' ) ; $ online = time ( ) ; $ url = URL :: full ( ) ; $ path = Request :: path ( ) ; $ visited = static :: whereIp ( $ ip ) -> today ( ) -> first ( ) ; if ( ! empty ( $ visited ) ) { $ visited -> update ( [ 'online' => $ online , 'hits' => $ visited -> hits + 1 , 'url' => $ url , 'path' => $ path , ] ) ; } else { static :: createNewVisitor ( ) ; } }
Track hits online visitors .
50,257
public function gravatar ( $ size = 60 , $ default = 'mm' , $ rating = 'g' ) { $ email = $ this -> email ; return 'http://www.gravatar.com/avatar/' . md5 ( strtolower ( trim ( $ email ) ) ) . "?s={$size}&d={$default}&r={$rating}" ; }
Get gravatar url .
50,258
public function update ( Update $ request , $ id ) { try { $ permission = $ this -> repository -> findById ( $ id ) ; $ data = $ request -> all ( ) ; $ permission -> update ( $ data ) ; return $ this -> redirect ( 'permissions.index' ) ; } catch ( ModelNotFoundException $ e ) { return $ this -> redirectNotFound ( ) ; } }
Update the specified permission in storage .
50,259
protected function installPackage ( ) { if ( $ this -> confirm ( 'Do you want publish the pingpong/admin\'s migrations ?' ) ) { $ this -> call ( 'admin:migration' ) ; } if ( $ this -> confirm ( 'Do you want publish the pingpong/trusty\'s migrations ?' ) ) { $ this -> call ( 'vendor:publish' , [ '--provider' => 'Pingpong\Trusty\TrustyServiceProvider' , ] ) ; } if ( $ this -> confirm ( 'Do you want run all migrations now ?' ) ) { $ this -> call ( 'migrate' ) ; } if ( $ this -> confirm ( 'Do you want run the pingpong/admin\'s seeders now ?' ) ) { $ this -> call ( 'admin:seed' ) ; } if ( $ this -> confirm ( 'Do you want publish configuration files from pingpong/admin package ?' ) ) { $ this -> call ( 'vendor:publish' , [ '--provider' => 'Pingpong\Admin\AdminServiceProvider' , [ '--tag' => [ 'config' ] ] , ] ) ; } if ( $ this -> confirm ( 'Do you want publish assets from pingpong/admin package ?' ) ) { $ this -> call ( 'vendor:publish' , [ '--provider' => 'Pingpong\Admin\AdminServiceProvider' , [ '--tag' => [ 'assets' ] ] , ] ) ; } if ( $ this -> confirm ( 'Do you want create the app/menus.php file ?' ) ) { $ this -> installMenus ( ) ; } $ this -> call ( 'optimize' ) ; }
Install the package .
50,260
protected function installMenus ( ) { $ file = app_path ( 'menus.php' ) ; if ( ! file_exists ( $ file ) ) { $ contents = $ this -> laravel [ 'files' ] -> get ( __DIR__ . '/stubs/menus.txt' ) ; $ this -> laravel [ 'files' ] -> put ( $ file , $ contents ) ; $ this -> info ( "Created : {$file}" ) ; } else { $ this -> error ( "File already exists at path : {$file}" ) ; } }
Create the menus . php file in app directory if that file does not exist .
50,261
public function redirect ( $ route , $ parameters = array ( ) , $ status = 302 , $ headers = array ( ) ) { return Redirect :: route ( 'admin.' . $ route , $ parameters , $ status , $ headers ) ; }
Redirect to a route .
50,262
public function index ( Request $ request ) { $ categories = $ this -> repository -> allOrSearch ( $ request -> get ( 'q' ) ) ; $ no = $ categories -> firstItem ( ) ; return $ this -> view ( 'categories.index' , compact ( 'categories' , 'no' ) ) ; }
Display a listing of categories .
50,263
public function store ( Create $ request ) { $ data = $ request -> all ( ) ; $ category = Category :: create ( $ data ) ; return $ this -> redirect ( 'categories.index' ) ; }
Store a newly created category in storage .
50,264
public function show ( $ id ) { try { $ category = $ this -> repository -> findById ( $ id ) ; return $ this -> view ( 'categories.show' , compact ( 'category' ) ) ; } catch ( ModelNotFoundException $ e ) { return $ this -> redirectNotFound ( ) ; } }
Display the specified category .
50,265
public function destroy ( $ id ) { try { $ this -> repository -> delete ( $ id ) ; return $ this -> redirect ( 'categories.index' ) ; } catch ( ModelNotFoundException $ e ) { return $ this -> redirectNotFound ( ) ; } }
Remove the specified category from storage .
50,266
public function index ( ) { $ articles = $ this -> repository -> allOrSearch ( Input :: get ( 'q' ) ) ; $ no = $ articles -> firstItem ( ) ; return $ this -> view ( 'articles.index' , compact ( 'articles' , 'no' ) ) ; }
Display a listing of articles .
50,267
public function updateSettings ( ) { $ settings = \ Input :: all ( ) ; foreach ( $ settings as $ key => $ value ) { $ option = str_replace ( '_' , '.' , $ key ) ; Option :: findByKey ( $ option ) -> update ( [ 'value' => $ value , ] ) ; } return \ Redirect :: back ( ) -> withFlashMessage ( 'Settings has been successfully updated!' ) ; }
Update the settings .
50,268
public function showArticle ( $ id ) { try { $ post = Article :: with ( 'user' , 'category' ) -> whereId ( intval ( $ id ) ) -> orWhere ( 'slug' , $ id ) -> firstOrFail ( ) ; $ view = \ Config :: get ( 'admin.views.post' ) ; return \ View :: make ( $ view , compact ( 'post' ) ) ; } catch ( ModelNotFoundException $ e ) { return \ App :: abort ( 404 ) ; } }
Show article .
50,269
public function reconnect ( ) { @ ftp_close ( $ this -> resource ) ; foreach ( $ this -> state as $ name => $ args ) { call_user_func_array ( array ( $ this , $ name ) , $ args ) ; } }
Reconnects to FTP server .
50,270
public function isDir ( $ dir ) { $ current = $ this -> pwd ( ) ; try { $ this -> chdir ( $ dir ) ; } catch ( FtpException $ e ) { } $ this -> chdir ( $ current ) ; return empty ( $ e ) ; }
Checks if directory exists .
50,271
public function mkDirRecursive ( $ dir ) { $ parts = explode ( '/' , $ dir ) ; $ path = '' ; while ( ! empty ( $ parts ) ) { $ path .= array_shift ( $ parts ) ; try { if ( $ path !== '' ) $ this -> mkdir ( $ path ) ; } catch ( FtpException $ e ) { if ( ! $ this -> isDir ( $ path ) ) { throw new FtpException ( "Cannot create directory '$path'." ) ; } } $ path .= '/' ; } }
Recursive creates directories .
50,272
public function deleteRecursive ( $ path ) { if ( ! $ this -> tryDelete ( $ path ) ) { foreach ( ( array ) $ this -> nlist ( $ path ) as $ file ) { if ( $ file !== '.' && $ file !== '..' ) { $ this -> deleteRecursive ( strpos ( $ file , '/' ) === FALSE ? "$path/$file" : $ file ) ; } } $ this -> rmdir ( $ path ) ; } }
Recursive deletes path .
50,273
protected function registerSecurity ( ) { $ this -> app -> singleton ( 'security' , function ( Container $ app ) { $ evil = $ app -> config -> get ( 'security.evil' ) ; return new Security ( $ evil ) ; } ) ; $ this -> app -> alias ( 'security' , Security :: class ) ; }
Register the security class .
50,274
public function add ( $ id , $ name , $ price , $ quantity , $ options = [ ] ) { $ cartItem = new CartItem ( $ id , $ name , $ price , $ quantity , $ options ) ; $ uniqueId = $ cartItem -> getUniqueId ( ) ; if ( $ this -> content -> has ( $ uniqueId ) ) { $ cartItem -> quantity += $ this -> content -> get ( $ uniqueId ) -> quantity ; } $ this -> content -> put ( $ uniqueId , $ cartItem ) ; return $ cartItem ; }
Add an item to the shopping cart .
50,275
public function remove ( $ uniqueId ) { if ( $ cartItem = $ this -> get ( $ uniqueId ) ) { $ this -> content -> pull ( $ cartItem -> getUniqueId ( ) ) ; return true ; } return false ; }
Remove the item with the specified unique id from shopping cart .
50,276
public function setQuantity ( $ uniqueId , $ quantity ) { if ( $ cartItem = $ this -> get ( $ uniqueId ) ) { $ cartItem -> quantity = $ quantity ; $ this -> content -> put ( $ cartItem -> getUniqueId ( ) , $ cartItem ) ; return true ; } return false ; }
Get the quantity of the cart item with specified unique id .
50,277
public function getTotalWithCoupons ( ) { $ total = $ this -> getTotal ( ) ; $ totalWithCoupons = $ total ; $ this -> coupons -> each ( function ( Coupon $ coupon ) use ( $ total , & $ totalWithCoupons ) { $ totalWithCoupons -= $ coupon -> apply ( $ total ) ; } ) ; return $ totalWithCoupons ; }
Get total price with coupons .
50,278
public function instance ( $ name ) { $ name = $ name ? : self :: DEFAULT_INSTANCE_NAME ; $ name = str_replace ( 'shopping-cart.' , '' , $ name ) ; $ this -> instanceName = sprintf ( '%s.%s' , 'shopping-cart' , $ name ) ; return $ this ; }
Set shopping cart instance name .
50,279
public function store ( $ id ) { $ this -> repo -> createOrUpdate ( $ id , $ this -> instanceName , json_encode ( serialize ( [ 'content' => $ this -> content , 'coupons' => $ this -> coupons , ] ) ) ) ; return $ this ; }
Store the current instance of the cart .
50,280
public function restore ( $ id ) { $ cart = $ this -> repo -> findByIdAndInstanceName ( $ id , $ this -> instanceName ) ; if ( $ cart === null ) { return ; } $ unserialized = unserialize ( json_decode ( $ cart -> content ) ) ; $ this -> content = $ unserialized [ 'content' ] ; $ this -> coupons = $ unserialized [ 'coupons' ] ; $ this -> instance ( $ cart -> instance ) ; return $ this ; }
Store the specified instance of the cart .
50,281
protected function generateUniqueId ( ) { ksort ( $ this -> options ) ; return md5 ( $ this -> id . serialize ( $ this -> options ) ) ; }
Generate a unique id for the cart item .
50,282
public function remove ( $ id , $ instanceName ) { $ this -> getConnection ( ) -> table ( $ this -> getTableName ( ) ) -> where ( 'id' , $ id ) -> where ( 'instance' , $ instanceName ) -> delete ( ) ; }
Remove shopping cart by its identifier and instance name .
50,283
protected function create ( $ id , $ instanceName , $ content ) { $ this -> getConnection ( ) -> table ( $ this -> getTableName ( ) ) -> insert ( [ 'id' => $ id , 'instance' => $ instanceName , 'content' => $ content , ] ) ; }
Create shopping cart instance .
50,284
protected function update ( $ id , $ instanceName , $ content ) { $ this -> getConnection ( ) -> table ( $ this -> getTableName ( ) ) -> where ( 'id' , $ id ) -> where ( 'instance' , $ instanceName ) -> update ( [ 'content' => $ content ] ) ; }
Update shopping cart instance .
50,285
protected function exists ( $ id , $ instanceName ) { return $ this -> getConnection ( ) -> table ( $ this -> getTableName ( ) ) -> where ( 'id' , $ id ) -> where ( 'instance' , $ instanceName ) -> exists ( ) ; }
Check if shopping cart instance exitsts .
50,286
public static function contentToCatalogue ( $ content , $ locale , $ domain ) { $ loader = new XliffLoader ( ) ; $ catalogue = new MessageCatalogue ( $ locale ) ; $ loader -> extractFromContent ( $ content , $ catalogue , $ domain ) ; return $ catalogue ; }
Create a catalogue from the contents of a XLIFF file .
50,287
private function writeCatalogue ( MessageCatalogueInterface $ catalogue , $ locale , $ domain ) { $ resources = $ catalogue -> getResources ( ) ; $ options = $ this -> options ; $ written = false ; foreach ( $ resources as $ resource ) { $ path = ( string ) $ resource ; if ( preg_match ( '|/' . $ domain . '\.' . $ locale . '\.([a-z]+)$|' , $ path , $ matches ) ) { $ options [ 'path' ] = str_replace ( $ matches [ 0 ] , '' , $ path ) ; $ this -> writer -> write ( $ catalogue , $ matches [ 1 ] , $ options ) ; $ written = true ; } } if ( $ written ) { return ; } $ options [ 'path' ] = reset ( $ this -> dir ) ; $ format = isset ( $ options [ 'default_output_format' ] ) ? $ options [ 'default_output_format' ] : 'xlf' ; $ this -> writer -> write ( $ catalogue , $ format , $ options ) ; }
Save catalogue back to file .
50,288
private function loadCatalogue ( $ locale , array $ dirs ) { $ currentCatalogue = new MessageCatalogue ( $ locale ) ; foreach ( $ dirs as $ path ) { if ( is_dir ( $ path ) ) { $ this -> reader -> read ( $ path , $ currentCatalogue ) ; } } $ this -> catalogues [ $ locale ] = $ currentCatalogue ; }
Load catalogue from files .
50,289
public function rpoplpush ( string $ sourceList , string $ destinationList ) { $ rpopValue = $ this -> rpop ( $ sourceList ) ; if ( null !== $ rpopValue ) { $ this -> lpush ( $ destinationList , $ rpopValue ) ; } return $ rpopValue ; }
Mock the rpoplpush command
50,290
public function formatted_page ( $ doctype = 'html5' , $ externalcss = true , $ title = '' , $ lang = 'en' ) { switch ( $ doctype ) { case 'html5' : $ doctype_output = '<!DOCTYPE html>' ; break ; case 'xhtml1.0strict' : $ doctype_output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' ; break ; case 'xhtml1.1' : default : $ doctype_output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' ; break ; } $ output = $ cssparsed = '' ; $ this -> output_css_plain = & $ output ; $ output .= $ doctype_output . "\n" . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $ lang . '"' ; $ output .= ( $ doctype === 'xhtml1.1' ) ? '>' : ' lang="' . $ lang . '">' ; $ output .= "\n<head>\n <title>$title</title>" ; if ( $ externalcss ) { $ output .= "\n <style type=\"text/css\">\n" ; $ cssparsed = file_get_contents ( 'cssparsed.css' ) ; $ output .= $ cssparsed ; $ output .= "\n</style>" ; } else { $ output .= "\n" . ' <link rel="stylesheet" type="text/css" href="cssparsed.css" />' ; } $ output .= "\n</head>\n<body><code id=\"copytext\">" ; $ output .= $ this -> formatted ( ) ; $ output .= '</code>' . "\n" . '</body></html>' ; return $ this -> output_css_plain ; }
Returns the formatted CSS code to make a complete webpage
50,291
public function get_ratio ( ) { if ( ! $ this -> output_css_plain ) { $ this -> formatted ( ) ; } return round ( ( strlen ( $ this -> input_css ) - strlen ( $ this -> output_css_plain ) ) / strlen ( $ this -> input_css ) , 3 ) * 100 ; }
Get compression ratio
50,292
public function get_diff ( ) { if ( ! $ this -> output_css_plain ) { $ this -> formatted ( ) ; } $ diff = strlen ( $ this -> output_css_plain ) - strlen ( $ this -> input_css ) ; if ( $ diff > 0 ) { return '+' . $ diff ; } elseif ( $ diff == 0 ) { return '+-' . $ diff ; } return $ diff ; }
Get difference between the old and new code in bytes and prints the code if necessary .
50,293
public function size ( $ loc = 'output' ) { if ( $ loc === 'output' && ! $ this -> output_css ) { $ this -> formatted ( ) ; } if ( $ loc === 'input' ) { return ( strlen ( $ this -> input_css ) / 1000 ) ; } else { return ( strlen ( $ this -> output_css_plain ) / 1000 ) ; } }
Get the size of either input or output CSS in KB
50,294
public function subvalue ( ) { $ replace_colors = & $ this -> parser -> data [ 'csstidy' ] [ 'replace_colors' ] ; $ this -> sub_value = trim ( $ this -> sub_value ) ; if ( $ this -> sub_value == '' ) { return ; } $ important = '' ; if ( $ this -> parser -> is_important ( $ this -> sub_value ) ) { $ important = '!important' ; } $ this -> sub_value = $ this -> parser -> gvw_important ( $ this -> sub_value ) ; if ( $ this -> property === 'font-weight' && $ this -> parser -> get_cfg ( 'compress_font-weight' ) ) { if ( $ this -> sub_value === 'bold' ) { $ this -> sub_value = '700' ; $ this -> parser -> log ( 'Optimised font-weight: Changed "bold" to "700"' , 'Information' ) ; } elseif ( $ this -> sub_value === 'normal' ) { $ this -> sub_value = '400' ; $ this -> parser -> log ( 'Optimised font-weight: Changed "normal" to "400"' , 'Information' ) ; } } $ temp = $ this -> compress_numbers ( $ this -> sub_value ) ; if ( strcasecmp ( $ temp , $ this -> sub_value ) !== 0 ) { if ( strlen ( $ temp ) > strlen ( $ this -> sub_value ) ) { $ this -> parser -> log ( 'Fixed invalid number: Changed "' . $ this -> sub_value . '" to "' . $ temp . '"' , 'Warning' ) ; } else { $ this -> parser -> log ( 'Optimised number: Changed "' . $ this -> sub_value . '" to "' . $ temp . '"' , 'Information' ) ; } $ this -> sub_value = $ temp ; } if ( $ this -> parser -> get_cfg ( 'compress_colors' ) ) { $ temp = $ this -> cut_color ( $ this -> sub_value ) ; if ( $ temp !== $ this -> sub_value ) { if ( isset ( $ replace_colors [ $ this -> sub_value ] ) ) { $ this -> parser -> log ( 'Fixed invalid color name: Changed "' . $ this -> sub_value . '" to "' . $ temp . '"' , 'Warning' ) ; } else { $ this -> parser -> log ( 'Optimised color: Changed "' . $ this -> sub_value . '" to "' . $ temp . '"' , 'Information' ) ; } $ this -> sub_value = $ temp ; } } $ this -> sub_value .= $ important ; }
Optimises a sub - value
50,295
public function compress_important ( & $ string ) { if ( $ this -> parser -> is_important ( $ string ) ) { $ important = $ this -> parser -> get_cfg ( 'space_before_important' ) ? ' !important' : '!important' ; $ string = $ this -> parser -> gvw_important ( $ string ) . $ important ; } return $ string ; }
Removes unnecessary whitespace in ! important
50,296
public function AnalyseCssNumber ( $ string ) { if ( strlen ( $ string ) == 0 || ctype_alpha ( $ string { 0 } ) ) { return false ; } $ units = & $ this -> parser -> data [ 'csstidy' ] [ 'units' ] ; $ return = array ( 0 , '' ) ; $ return [ 0 ] = floatval ( $ string ) ; if ( abs ( $ return [ 0 ] ) > 0 && abs ( $ return [ 0 ] ) < 1 ) { if ( $ return [ 0 ] < 0 ) { $ return [ 0 ] = '-' . ltrim ( substr ( $ return [ 0 ] , 1 ) , '0' ) ; } else { $ return [ 0 ] = ltrim ( $ return [ 0 ] , '0' ) ; } } foreach ( $ units as $ unit ) { $ expectUnitAt = strlen ( $ string ) - strlen ( $ unit ) ; if ( ! ( $ unitInString = stristr ( $ string , $ unit ) ) ) { continue ; } $ actualPosition = strpos ( $ string , $ unitInString ) ; if ( $ expectUnitAt === $ actualPosition ) { $ return [ 1 ] = $ unit ; $ string = substr ( $ string , 0 , - strlen ( $ unit ) ) ; break ; } } if ( ! is_numeric ( $ string ) ) { return false ; } return $ return ; }
Checks if a given string is a CSS valid number . If it is an array containing the value and unit is returned
50,297
public function discard_invalid_selectors ( & $ array ) { $ invalid = array ( '+' => true , '~' => true , ',' => true , '>' => true ) ; foreach ( $ array as $ selector => $ decls ) { $ ok = true ; $ selectors = array_map ( 'trim' , explode ( ',' , $ selector ) ) ; foreach ( $ selectors as $ s ) { $ simple_selectors = preg_split ( '/\s*[+>~\s]\s*/' , $ s ) ; foreach ( $ simple_selectors as $ ss ) { if ( $ ss === '' ) $ ok = false ; } } if ( ! $ ok ) unset ( $ array [ $ selector ] ) ; } }
Removes invalid selectors and their corresponding rule - sets as defined by 4 . 1 . 7 in REC - CSS2 . This is a very rudimentary check and should be replaced by a full - blown parsing algorithm or regular expression
50,298
public function merge_bg ( $ input_css ) { $ background_prop_default = & $ this -> parser -> data [ 'csstidy' ] [ 'background_prop_default' ] ; $ number_of_values = @ max ( count ( $ this -> explode_ws ( ',' , $ input_css [ 'background-image' ] ) ) , count ( $ this -> explode_ws ( ',' , $ input_css [ 'background-color' ] ) ) , 1 ) ; $ bg_img_array = @ $ this -> explode_ws ( ',' , $ this -> parser -> gvw_important ( $ input_css [ 'background-image' ] ) ) ; $ new_bg_value = '' ; $ important = '' ; if ( isset ( $ input_css [ 'background' ] ) && $ input_css [ 'background' ] ) return $ input_css ; for ( $ i = 0 ; $ i < $ number_of_values ; $ i ++ ) { foreach ( $ background_prop_default as $ bg_property => $ default_value ) { if ( ! isset ( $ input_css [ $ bg_property ] ) ) { continue ; } $ cur_value = $ input_css [ $ bg_property ] ; if ( stripos ( $ cur_value , 'gradient(' ) !== false ) return $ input_css ; if ( ( ! isset ( $ bg_img_array [ $ i ] ) || $ bg_img_array [ $ i ] === 'none' ) && ( $ bg_property === 'background-size' || $ bg_property === 'background-position' || $ bg_property === 'background-attachment' || $ bg_property === 'background-repeat' ) ) { continue ; } if ( $ this -> parser -> is_important ( $ cur_value ) ) { $ important = ' !important' ; $ cur_value = $ this -> parser -> gvw_important ( $ cur_value ) ; } if ( $ cur_value === $ default_value ) { continue ; } $ temp = $ this -> explode_ws ( ',' , $ cur_value ) ; if ( isset ( $ temp [ $ i ] ) ) { if ( $ bg_property === 'background-size' ) { $ new_bg_value .= '(' . $ temp [ $ i ] . ') ' ; } else { $ new_bg_value .= $ temp [ $ i ] . ' ' ; } } } $ new_bg_value = trim ( $ new_bg_value ) ; if ( $ i != $ number_of_values - 1 ) $ new_bg_value .= ',' ; } foreach ( $ background_prop_default as $ bg_property => $ default_value ) { unset ( $ input_css [ $ bg_property ] ) ; } if ( $ new_bg_value !== '' ) $ input_css [ 'background' ] = $ new_bg_value . $ important ; elseif ( isset ( $ input_css [ 'background' ] ) ) $ input_css [ 'background' ] = 'none' ; return $ input_css ; }
Merges all background properties
50,299
public function merge_font ( $ input_css ) { $ font_prop_default = & $ this -> parser -> data [ 'csstidy' ] [ 'font_prop_default' ] ; $ new_font_value = '' ; $ important = '' ; if ( isset ( $ input_css [ 'font-family' ] ) && isset ( $ input_css [ 'font-size' ] ) && $ input_css [ 'font-family' ] != 'inherit' ) { if ( isset ( $ input_css [ 'font-family' ] ) ) { $ families = explode ( ',' , $ input_css [ 'font-family' ] ) ; $ result_families = array ( ) ; foreach ( $ families as $ family ) { $ family = trim ( $ family ) ; $ len = strlen ( $ family ) ; if ( strpos ( $ family , ' ' ) && ! ( ( $ family { 0 } === '"' && $ family { $ len - 1 } === '"' ) || ( $ family { 0 } === "'" && $ family { $ len - 1 } === "'" ) ) ) { $ family = '"' . $ family . '"' ; } $ result_families [ ] = $ family ; } $ input_css [ 'font-family' ] = implode ( ',' , $ result_families ) ; } foreach ( $ font_prop_default as $ font_property => $ default_value ) { if ( ! isset ( $ input_css [ $ font_property ] ) ) { continue ; } $ cur_value = $ input_css [ $ font_property ] ; if ( $ cur_value === $ default_value ) { continue ; } if ( $ this -> parser -> is_important ( $ cur_value ) ) { $ important = '!important' ; $ cur_value = $ this -> parser -> gvw_important ( $ cur_value ) ; } $ new_font_value .= $ cur_value ; $ new_font_value .= ( $ font_property === 'font-size' && isset ( $ input_css [ 'line-height' ] ) ) ? '/' : ' ' ; } $ new_font_value = trim ( $ new_font_value ) ; foreach ( $ font_prop_default as $ font_property => $ default_value ) { if ( $ font_property !== 'font' || ! $ new_font_value ) unset ( $ input_css [ $ font_property ] ) ; } if ( $ new_font_value !== '' ) { $ input_css [ 'font' ] = $ new_font_value . $ important ; } } return $ input_css ; }
Merges all fonts properties