idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
21,500
public function setInitialState ( ) { foreach ( $ this -> states as $ status ) { if ( $ status -> getType ( ) == StatusInterface :: TYPE_INITIAL ) { $ this -> currentStatus = $ status ; return ; } } throw new WorkflowException ( 'No initial state found for the workflow' , 90 , NULL ) ; }
Set the initial state
21,501
public function getStatus ( $ name ) { foreach ( $ this -> states as $ status ) { if ( $ status -> getName ( ) == $ name ) { return $ status ; } } throw new WorkflowException ( 'No status found with the name ' . $ name , 70 , NULL ) ; }
Get the status of the workflow by its name .
21,502
protected function addToLog ( $ state , $ return = NULL ) { $ data [ 'name' ] = $ state ; if ( NULL !== $ return ) { $ data [ 'return' ] = $ return ; } $ this -> log [ ] = $ data ; }
The log will create .
21,503
public function run ( $ args = [ ] , $ saveLog = false ) { $ this -> reset ( ) ; $ this -> args = $ args ; $ continueExecution = true ; $ nextState = $ this -> currentStatus ; while ( true === $ continueExecution ) { if ( $ nextState -> getType ( ) == StatusInterface :: TYPE_FINAL ) { $ continueExecution = false ; } try { $ this -> executeMethod ( 'preDispatch' ) ; $ condition = $ this -> executeMethod ( $ nextState -> getName ( ) ) ; $ this -> executeMethod ( 'postDispatch' ) ; } catch ( \ Exception $ e ) { if ( method_exists ( $ this , 'exception' ) ) { call_user_func ( [ $ this , 'exception' ] , [ $ e ] ) ; $ nextState = $ this -> getNextStateFrom ( 'exception' ) ; $ this -> setState ( $ nextState ) ; continue ; } else { throw $ e ; } } if ( true === $ saveLog ) { $ this -> addToLog ( $ nextState -> getName ( ) , $ condition ) ; } if ( false === $ continueExecution ) { continue ; } $ nextState = $ this -> getNextStateFrom ( $ nextState -> getName ( ) , $ condition ) ; $ this -> setState ( $ nextState ) ; } if ( true === $ saveLog ) { return $ this -> log ; } }
The main method which processes the state machine .
21,504
private function executeMethod ( $ method , $ args = [ ] ) { if ( method_exists ( $ this , $ method ) ) { return call_user_func_array ( [ $ this , $ method ] , $ args ) ; } }
Helper method for executing .
21,505
private function getStatusIndex ( $ statusname ) { $ status_count = count ( $ this -> states ) ; for ( $ i = 0 ; $ i < $ status_count ; ++ $ i ) { if ( $ this -> states [ $ i ] -> getName ( ) == $ statusname ) { return $ i ; } } }
Get the position of a state .
21,506
public function getLastLoggedIn ( ) { $ lastTime = LoginAttempt :: get ( ) -> filter ( [ 'MemberID' => $ this -> owner -> ID , 'Status' => 'Success' , ] ) -> sort ( 'Created' , 'DESC' ) -> first ( ) ; if ( $ lastTime ) { return $ lastTime -> dbObject ( 'Created' ) -> format ( DBDatetime :: ISO_DATETIME ) ; } return _t ( __CLASS__ . '.NEVER' , 'Never' ) ; }
Retrieves the most recent successful LoginAttempt
21,507
public function getGroupsDescription ( ) { if ( class_exists ( Subsite :: class ) ) { Subsite :: disable_subsite_filter ( true ) ; } $ groups = $ this -> owner -> Groups ( ) ; if ( $ groups -> Count ( ) ) { $ groupNames = array ( ) ; foreach ( $ groups as $ group ) { $ groupNames [ ] = html_entity_decode ( $ group -> getTreeTitle ( ) ) ; } $ result = preg_replace ( "#</?[^>]>#" , '' , implode ( ', ' , $ groupNames ) ) ; } else { $ result = _t ( __CLASS__ . '.NOGROUPS' , 'Not in a Security Group' ) ; } if ( class_exists ( Subsite :: class ) ) { Subsite :: disable_subsite_filter ( false ) ; } return $ result ; }
Builds a comma separated list of member group names for a given Member .
21,508
public function getPermissionsDescription ( ) { if ( class_exists ( Subsite :: class ) ) { Subsite :: disable_subsite_filter ( true ) ; } $ permissionsUsr = Permission :: permissions_for_member ( $ this -> owner -> ID ) ; $ permissionsSrc = Permission :: get_codes ( true ) ; sort ( $ permissionsUsr ) ; $ permissionNames = array ( ) ; foreach ( $ permissionsUsr as $ code ) { $ code = strtoupper ( $ code ) ; foreach ( $ permissionsSrc as $ k => $ v ) { if ( isset ( $ v [ $ code ] ) ) { $ name = empty ( $ v [ $ code ] [ 'name' ] ) ? _t ( __CLASS__ . '.UNKNOWN' , 'Unknown' ) : $ v [ $ code ] [ 'name' ] ; $ permissionNames [ ] = $ name ; } } } $ result = $ permissionNames ? implode ( ', ' , $ permissionNames ) : _t ( __CLASS__ . '.NOPERMISSIONS' , 'No Permissions' ) ; if ( class_exists ( Subsite :: class ) ) { Subsite :: disable_subsite_filter ( false ) ; } return $ result ; }
Builds a comma separated list of human - readbale permissions for a given Member .
21,509
public function createSerializerFor ( $ serialization ) { $ serializer = new SerializerEasyRdf ( $ serialization ) ; if ( in_array ( $ serialization , $ serializer -> getSupportedSerializations ( ) ) ) { return $ serializer ; } else { throw new \ Exception ( 'No serializer for requested serialization available: ' . $ serialization . '. ' . 'Supported serializations are: ' . implode ( ', ' , $ this -> getSupportedSerializations ( ) ) ) ; } }
Creates a Serializer instance for a given serialization if available .
21,510
public static function parseArray ( array $ values ) { $ output = [ ] ; foreach ( $ values as $ key => $ value ) { if ( null === $ value ) { continue ; } if ( true === is_array ( $ value ) ) { $ buffer = trim ( implode ( " " , $ value ) ) ; } else { $ buffer = trim ( $ value ) ; } if ( "" !== $ buffer ) { $ output [ ] = $ key . "=\"" . preg_replace ( "/\s+/" , " " , $ buffer ) . "\"" ; } } return implode ( " " , $ output ) ; }
Parse an array .
21,511
public function get ( string $ type ) : array { if ( isset ( $ this -> messages [ $ type ] ) ) { $ messages = $ this -> messages [ $ type ] ; $ this -> clear ( $ type ) ; return $ messages ; } else { return [ ] ; } }
Get all messages for given type and clear flash bag of them .
21,512
public function clear ( string $ type = null ) : FlashBag { if ( is_null ( $ type ) ) { $ this -> messages = [ ] ; } else { if ( isset ( $ this -> messages [ $ type ] ) ) { unset ( $ this -> messages [ $ type ] ) ; } } $ this -> saveToSession ( ) ; return $ this ; }
Clear messages in flash bag .
21,513
protected function decodeDate ( $ str ) { $ date = DateTime :: createFromFormat ( "!" . self :: DATE_FORMAT , $ str ) ; return false === $ date ? null : $ date ; }
Decode a date string .
21,514
protected function decodeDateTime ( $ str ) { $ date = DateTime :: createFromFormat ( self :: DATETIME_FORMAT , $ str ) ; return false === $ date ? null : $ date ; }
Decode a datetime string .
21,515
protected function encodeDate ( DateTime $ value = null ) { return null === $ value ? "" : $ value -> format ( self :: DATE_FORMAT ) ; }
Encode a date value .
21,516
protected function encodeDateTime ( DateTime $ value = null ) { return null === $ value ? "" : $ value -> format ( self :: DATETIME_FORMAT ) ; }
Encode a datetime value .
21,517
protected function encodeInteger ( $ value , $ length ) { $ format = "%'.0" . $ length . "d" ; $ output = null === $ value ? "" : sprintf ( $ format , $ value ) ; if ( $ length < strlen ( $ output ) ) { throw new TooLongDataException ( $ value , $ length ) ; } return $ output ; }
Encode an integer value .
21,518
protected function encodeString ( $ value , $ length = - 1 ) { if ( - 1 !== $ length && $ length < strlen ( $ value ) ) { throw new TooLongDataException ( $ value , $ length ) ; } return "\"" . substr ( $ value , 0 , ( - 1 === $ length ? strlen ( $ value ) : $ length ) ) . "\"" ; }
Encode a string value .
21,519
protected static function getIconSizes ( $ entity , $ icon_sizes = array ( ) ) { $ type = $ entity -> getType ( ) ; $ subtype = $ entity -> getSubtype ( ) ; $ defaults = array ( 'master' => array ( 'h' => 370 , 'w' => 1000 , 'upscale' => true , 'square' => false , ) ) ; if ( is_array ( $ icon_sizes ) ) { $ icon_sizes = array_merge ( $ defaults , $ icon_sizes ) ; } else { $ icon_sizes = $ defaults ; } return elgg_trigger_plugin_hook ( 'entity:cover:sizes' , $ type , array ( 'entity' => $ entity , 'subtype' => $ subtype , ) , $ icon_sizes ) ; }
Get cover size config
21,520
protected function rdfPhpToStatementIterator ( array $ rdfPhp ) { $ statements = [ ] ; foreach ( $ rdfPhp as $ subject => $ predicates ) { foreach ( $ predicates as $ property => $ objects ) { foreach ( $ objects as $ object ) { if ( true === $ this -> RdfHelpers -> simpleCheckURI ( $ subject ) ) { $ s = $ this -> nodeFactory -> createNamedNode ( $ subject ) ; } elseif ( true === $ this -> RdfHelpers -> simpleCheckBlankNodeId ( $ subject ) ) { $ s = $ this -> nodeFactory -> createBlankNode ( $ subject ) ; } else { throw new \ Exception ( 'Only URIs and blank nodes are allowed as subjects.' ) ; } if ( true === $ this -> RdfHelpers -> simpleCheckURI ( $ property ) ) { $ p = $ this -> nodeFactory -> createNamedNode ( $ property ) ; } elseif ( true === $ this -> RdfHelpers -> simpleCheckBlankNodeId ( $ property ) ) { $ p = $ this -> nodeFactory -> createBlankNode ( $ property ) ; } else { throw new \ Exception ( 'Only URIs and blank nodes are allowed as predicates.' ) ; } if ( $ this -> RdfHelpers -> simpleCheckURI ( $ object [ 'value' ] ) ) { $ o = $ this -> nodeFactory -> createNamedNode ( $ object [ 'value' ] ) ; } elseif ( isset ( $ object [ 'datatype' ] ) ) { $ o = $ this -> nodeFactory -> createLiteral ( $ object [ 'value' ] , $ object [ 'datatype' ] ) ; } elseif ( isset ( $ object [ 'lang' ] ) ) { $ o = $ this -> nodeFactory -> createLiteral ( $ object [ 'value' ] , 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString' , $ object [ 'lang' ] ) ; } else { $ o = $ this -> nodeFactory -> createLiteral ( $ object [ 'value' ] ) ; } $ statements [ ] = $ this -> statementFactory -> createStatement ( $ s , $ p , $ o ) ; } } } return $ this -> statementIteratorFactory -> createStatementIteratorFromArray ( $ statements ) ; }
Transforms a statement array given by EasyRdf to a Saft StatementIterator instance .
21,521
public function getTableRateCollection ( $ storeId = null ) { return $ this -> tableRateCollection -> setWebsiteFilter ( $ this -> storeManager -> getStore ( $ storeId ) -> getWebsiteId ( ) ) ; }
Retrieve the table rate collection filtered by store s website
21,522
public function init ( ) { elgg_register_plugin_hook_handler ( 'entity:icon:url' , 'all' , new Handlers \ EntityIconUrlHook ( ) ) ; elgg_register_plugin_hook_handler ( 'graph:properties' , 'all' , new Handlers \ PropertiesHook ( ) ) ; elgg_register_plugin_hook_handler ( 'graph:properties' , 'user' , new Handlers \ UserPropertiesHook ( ) ) ; elgg_register_plugin_hook_handler ( 'graph:properties' , 'group' , new Handlers \ GroupPropertiesHook ( ) ) ; elgg_register_plugin_hook_handler ( 'graph:properties' , 'site' , new Handlers \ SitePropertiesHook ( ) ) ; elgg_register_plugin_hook_handler ( 'graph:properties' , 'object' , new Handlers \ ObjectPropertiesHook ( ) ) ; elgg_register_plugin_hook_handler ( 'graph:properties' , 'object:blog' , new Handlers \ BlogPropertiesHook ( ) ) ; elgg_register_plugin_hook_handler ( 'graph:properties' , 'object:file' , new Handlers \ FilePropertiesHook ( ) ) ; elgg_register_plugin_hook_handler ( 'graph:properties' , 'object:messages' , new Handlers \ MessagePropertiesHook ( ) ) ; elgg_register_plugin_hook_handler ( 'graph:properties' , 'metadata' , new Handlers \ ExtenderPropertiesHook ( ) ) ; elgg_register_plugin_hook_handler ( 'graph:properties' , 'annotation' , new Handlers \ ExtenderPropertiesHook ( ) ) ; elgg_register_plugin_hook_handler ( 'graph:properties' , 'relationship' , new Handlers \ RelationshipPropertiesHook ( ) ) ; elgg_register_plugin_hook_handler ( 'graph:properties' , 'river:item' , new Handlers \ RiverPropertiesHook ( ) ) ; }
init system callback
21,523
public function setCoupon ( ) { foreach ( $ this -> cart -> getExternalCoupons ( ) as $ coupon ) { $ this -> setCouponToQuote ( $ coupon ) ; } return $ this -> quote ; }
Sets coupon to quote
21,524
public function parseActionName ( ) { $ uri = trim ( get_input ( '__elgg_uri' , '' ) , '/' ) ; $ segments = explode ( '/' , $ uri ) ; $ handler = array_shift ( $ segments ) ; if ( $ handler == 'action' ) { return implode ( '/' , $ segments ) ; } return $ uri ; }
Parses action name
21,525
public function getItemsWithUnhandledErrors ( ) { $ list = [ ] ; foreach ( $ this -> getItems ( ) as $ item ) { if ( $ item -> hasUnhandledError ( ) ) { $ list [ ] = $ item ; } } return $ list ; }
Returns cart items with errors
21,526
public function setItems ( $ list ) { if ( ! is_array ( $ list ) ) { $ this -> items = null ; return ; } $ items = [ ] ; foreach ( $ list as $ index => $ element ) { if ( ( ! is_object ( $ element ) || ! ( $ element instanceof \ ShopgateOrderItem ) ) && ! is_array ( $ element ) ) { unset ( $ list [ $ index ] ) ; continue ; } if ( $ element instanceof \ ShopgateOrderItem ) { $ element = $ element -> toArray ( ) ; } $ item = $ this -> itemFactory -> create ( ) ; $ item -> loadArray ( $ element ) ; $ items [ $ item -> getItemNumber ( ) ] = $ item ; } $ this -> items = $ items ; }
Rewrite of the original just to swap out the objects into our custom item classes
21,527
public function customFieldsToArray ( ) { $ result = [ ] ; foreach ( $ this -> getCustomFields ( ) as $ field ) { $ result [ $ field -> getInternalFieldName ( ) ] = $ field -> getValue ( ) ; } return $ result ; }
Returns fields in array format ready for magento import
21,528
public function toArray ( ) { return array_filter ( array ( 'name' => $ this -> getAttributeName ( ) , 'required' => $ this -> required , 'type' => $ this -> type , 'enum' => $ this -> getEnumOptions ( ) , 'default' => $ this -> default , ) ) ; }
Exports property to an array
21,529
private function registerNotifyService ( ) { $ this -> singleton ( Contracts \ Notify :: class , function ( $ app ) { $ config = $ app [ 'config' ] ; return new Notify ( $ app [ Contracts \ SessionStore :: class ] , $ config -> get ( 'notify.session.prefix' , 'notifier' ) ) ; } ) ; }
Register the Notify service .
21,530
public function isConcrete ( ) { if ( $ this -> isQuad ( ) && ! $ this -> getGraph ( ) -> isConcrete ( ) ) { return false ; } return $ this -> getSubject ( ) -> isConcrete ( ) && $ this -> getPredicate ( ) -> isConcrete ( ) && $ this -> getObject ( ) -> isConcrete ( ) ; }
Returns true if neither subject predicate object nor if available graph are patterns .
21,531
public function toNQuads ( ) { if ( $ this -> isConcrete ( ) ) { if ( $ this -> isQuad ( ) ) { return $ this -> getSubject ( ) -> toNQuads ( ) . ' ' . $ this -> getPredicate ( ) -> toNQuads ( ) . ' ' . $ this -> getObject ( ) -> toNQuads ( ) . ' ' . $ this -> getGraph ( ) -> toNQuads ( ) . ' .' ; } else { return $ this -> getSubject ( ) -> toNQuads ( ) . ' ' . $ this -> getPredicate ( ) -> toNQuads ( ) . ' ' . $ this -> getObject ( ) -> toNQuads ( ) . ' .' ; } } else { throw new \ Exception ( 'A Statement has to be concrete in N-Quads.' ) ; } }
Transforms content of the Statement to n - quads form .
21,532
public function toNTriples ( ) { if ( $ this -> isConcrete ( ) ) { return $ this -> getSubject ( ) -> toNQuads ( ) . ' ' . $ this -> getPredicate ( ) -> toNQuads ( ) . ' ' . $ this -> getObject ( ) -> toNQuads ( ) . ' .' ; } else { throw new \ Exception ( 'A Statement has to be concrete in N-Triples.' ) ; } }
Transforms content of the Statement to n - triples form .
21,533
public function equals ( Statement $ toTest ) { if ( $ toTest instanceof Statement && $ this -> getSubject ( ) -> equals ( $ toTest -> getSubject ( ) ) && $ this -> getPredicate ( ) -> equals ( $ toTest -> getPredicate ( ) ) && $ this -> getObject ( ) -> equals ( $ toTest -> getObject ( ) ) ) { if ( $ this -> isQuad ( ) && $ toTest -> isQuad ( ) && $ this -> getGraph ( ) -> equals ( $ toTest -> getGraph ( ) ) ) { return true ; } elseif ( $ this -> isTriple ( ) && $ toTest -> isTriple ( ) ) { return true ; } } return false ; }
Checks if a given statement is equal to this instance .
21,534
public function matches ( Statement $ toTest ) { if ( $ this -> isConcrete ( ) && $ this -> equals ( $ toTest ) ) { return true ; } if ( $ toTest instanceof Statement && $ this -> getSubject ( ) -> matches ( $ toTest -> getSubject ( ) ) && $ this -> getPredicate ( ) -> matches ( $ toTest -> getPredicate ( ) ) && $ this -> getObject ( ) -> matches ( $ toTest -> getObject ( ) ) ) { if ( $ this -> isQuad ( ) && $ toTest -> isQuad ( ) && $ this -> getGraph ( ) -> matches ( $ toTest -> getGraph ( ) ) ) { return true ; } elseif ( $ this -> isQuad ( ) && $ this -> getGraph ( ) -> isPattern ( ) ) { return true ; } elseif ( $ this -> isTriple ( ) && $ toTest -> isTriple ( ) ) { return true ; } } return false ; }
Checks if this instance matches a given instance .
21,535
public function append ( $ line , $ newline = true , $ indentOffset = 0 ) { $ line = trim ( $ line ) ; if ( strlen ( $ line ) > 0 ) { parent :: append ( self :: COMMENT_LINE_PREFIX . ' ' . $ line , $ newline , $ indentOffset ) ; } else { parent :: append ( self :: COMMENT_LINE_PREFIX , $ newline , $ indentOffset ) ; } return $ this ; }
Appends new comment line to block
21,536
public function getStandardizedType ( ) { foreach ( $ this -> getStandardizedTypes ( ) as $ standardizedType ) { if ( $ this -> is ( $ standardizedType ) ) { return $ standardizedType ; } } return self :: UNKNOWN_TYPE ; }
Depending on the type returns a standardized type a constant value of XXX_TYPE . Note that if the type is a class name object type is returned .
21,537
private function getTypeMapping ( $ standardizeType ) { if ( ! isset ( $ this -> getTypeMappingList ( ) [ $ standardizeType ] ) ) { throw new InvalidArgumentException ( sprintf ( '$standardizeType not valid. Should be on of the values: %s. "%s" given.' , json_encode ( $ this -> getStandardizedTypes ( ) ) , $ standardizeType ) ) ; } return $ this -> getTypeMappingList ( ) [ $ standardizeType ] ; }
Returns a type mapping .
21,538
public function shuffle ( ) : Collection { $ keys = array_keys ( $ this -> list ) ; shuffle ( $ keys ) ; $ newList = [ ] ; foreach ( $ keys as $ key ) { $ newList [ $ key ] = $ this -> list [ $ key ] ; } $ this -> list = $ newList ; return $ this ; }
Shuffle list and preserve keys .
21,539
public function offsetSet ( $ offset , $ value ) : void { if ( $ this -> isValidEntity ( $ value ) ) { if ( is_null ( $ offset ) || mb_strlen ( $ offset ) == 0 ) { $ this -> list [ ] = $ value ; } else { $ this -> list [ $ offset ] = $ value ; } } else { throw new \ InvalidArgumentException ( sprintf ( 'This collection does\'t accept this entity "%s"' , gettype ( $ value ) ) ) ; } }
Assign a value to the specified offset .
21,540
public function isValidEntity ( $ mixed ) : bool { if ( empty ( $ this -> entityClasses ) ) { return true ; } else { if ( is_object ( $ mixed ) ) { foreach ( $ this -> entityClasses as $ entityClass ) { if ( is_a ( $ mixed , $ entityClass , true ) ) { return true ; } } } } return false ; }
Check if element is valid for the list .
21,541
public function mergeWith ( Collection $ collection ) : Collection { $ calledClass = get_called_class ( ) ; if ( $ collection instanceof $ calledClass ) { foreach ( $ collection as $ key => $ object ) { $ this [ $ key ] = $ object ; } } else { throw new \ InvalidArgumentException ( sprintf ( '%s::mergeWith() method require an same type of Collection.' , get_class ( $ this ) ) ) ; } return $ this ; }
Merge another Collection with this .
21,542
public function execute ( \ Magento \ Framework \ Event \ Observer $ observer ) { $ additional = $ observer -> getAdditional ( ) ; $ conditions = ( array ) $ additional -> getConditions ( ) ; $ conditions = array_merge_recursive ( $ conditions , [ $ this -> getShopgateCondition ( ) ] ) ; $ additional -> setConditions ( $ conditions ) ; return $ this ; }
Execute observer .
21,543
public function determineEntityType ( $ entity ) { if ( '<' == substr ( $ entity , 0 , 1 ) ) { $ entity = str_replace ( [ '>' , '<' ] , '' , $ entity ) ; } if ( true === $ this -> rdfHelpers -> simpleCheckURI ( $ entity ) ) { return 'uri' ; } elseif ( false !== strpos ( $ entity , '"^^<' ) || ( '"' == substr ( $ entity , 0 , 1 ) && '"' == substr ( $ entity , strlen ( $ entity ) - 1 , 1 ) ) ) { return 'typed-literal' ; } elseif ( false !== strpos ( $ entity , '_:' ) ) { return 'blanknode' ; } elseif ( false !== strpos ( $ entity , ':' ) ) { return 'uri' ; } elseif ( false !== strpos ( $ entity , '"@' ) ) { return 'literal' ; } elseif ( true === is_string ( $ entity ) ) { return 'var' ; } else { return null ; } }
Determines type of a entity .
21,544
public function determineObjectDatatype ( $ objectString ) { $ datatype = null ; $ arrowPos = strpos ( $ objectString , '"^^<' ) ; if ( '"' === substr ( $ objectString , 0 , 1 ) && false !== $ arrowPos ) { $ datatype = substr ( $ objectString , $ arrowPos + 4 ) ; return substr ( $ datatype , 0 , strlen ( $ datatype ) - 1 ) ; } elseif ( '"' == substr ( $ objectString , 0 , 1 ) && '"' == substr ( $ objectString , strlen ( $ objectString ) - 1 , 1 ) ) { return 'http://www.w3.org/2001/XMLSchema#string' ; } else { return null ; } }
Determines SPARQL datatype of a given string usually of an object value .
21,545
public function extractNamespacesFromQuery ( $ query ) { preg_match_all ( '/\<([a-zA-Z\\\.\/\-\#\:0-9]+)\>/' , $ query , $ matches ) ; $ uris = [ ] ; foreach ( $ matches [ 1 ] as $ match ) { $ hashPos = strrpos ( $ match , '#' ) ; if ( false !== $ hashPos ) { $ uri = substr ( $ match , 0 , $ hashPos + 1 ) ; } else { if ( 7 < strlen ( $ match ) ) { $ slashPos = strrpos ( $ match , '/' , 7 ) ; if ( false !== $ slashPos ) { $ uri = substr ( $ match , 0 , $ slashPos + 1 ) ; } else { continue ; } } else { continue ; } } $ uris [ $ uri ] = $ uri ; } $ uris = array_values ( $ uris ) ; $ prefixes = [ ] ; $ uriSet = false ; $ prefixNumber = 0 ; foreach ( $ uris as $ uri ) { $ uriSet = false ; foreach ( $ this -> commonNamespaces as $ prefix => $ _uri ) { if ( $ uri == $ _uri ) { $ prefixes [ $ prefix ] = $ uri ; $ uriSet = true ; break ; } } if ( false === $ uriSet ) { $ prefixes [ 'ns-' . $ prefixNumber ++ ] = $ uri ; } } return $ prefixes ; }
Extracts prefixes from a given query .
21,546
public function extractPrefixesFromQuery ( $ query ) { preg_match_all ( '/PREFIX\s+([a-z0-9]+)\:\s*\<([a-z0-9\:\/\.\#\-]+)\>/' , $ query , $ matches ) ; $ prefixes = [ ] ; foreach ( $ matches [ 1 ] as $ index => $ key ) { $ prefixes [ $ key ] = $ matches [ 2 ] [ $ index ] ; } return $ prefixes ; }
Extracts prefixes from the prologue part of the given query .
21,547
public function extractQuads ( $ query ) { $ quads = [ ] ; $ result = preg_match_all ( '/GRAPH\s*\<(.*?)\>\s*\{\n*\s*(.*?)\s*\n*\}/si' , $ query , $ matches ) ; if ( false !== $ result && true === isset ( $ matches [ 1 ] ) && true === isset ( $ matches [ 2 ] ) ) { foreach ( $ matches [ 1 ] as $ key => $ graph ) { $ triplePattern = $ this -> extractTriplePattern ( $ matches [ 2 ] [ $ key ] ) ; if ( 0 == count ( $ triplePattern ) ) { throw new \ Exception ( 'Quad related part of the query is invalid: ' . $ matches [ 2 ] [ $ key ] ) ; } $ quad = $ triplePattern [ 0 ] ; $ quad [ 'g' ] = $ graph ; $ quad [ 'g_type' ] = 'uri' ; $ quads [ ] = $ quad ; } } return $ quads ; }
Extracts quads from query if available .
21,548
public function replacePrefixWithUri ( $ prefixedString , $ prefixes ) { if ( false !== strpos ( $ prefixedString , ':' ) && false === strpos ( $ prefixedString , '<' ) && false === strpos ( $ prefixedString , '>' ) ) { $ prefix = substr ( $ prefixedString , 0 , strpos ( $ prefixedString , ':' ) ) ; if ( true === isset ( $ prefixes [ $ prefix ] ) ) { $ prefixedString = str_replace ( $ prefix . ':' , $ prefixes [ $ prefix ] , $ prefixedString ) ; } } return $ prefixedString ; }
Replaces the prefix in a string with the original URI .
21,549
public function importFromLocal ( $ overwrite = true , $ delete = false ) { $ path = $ this -> _data ; $ file = new File ( $ path ) ; $ target = $ this -> findDestination ( $ file , $ overwrite ) ; if ( copy ( $ path , $ target ) ) { if ( $ delete ) { $ file -> delete ( ) ; } $ this -> _file = new File ( $ target ) ; return true ; } throw new IoException ( sprintf ( 'Failed to copy %s to new location' , $ file -> basename ( ) ) ) ; }
Copy a local file to the temp directory and return a File object .
21,550
public function importFromRemote ( $ overwrite = true , array $ options = array ( ) ) { if ( ! function_exists ( 'curl_init' ) ) { throw new RuntimeException ( 'The cURL module is required for remote file importing' ) ; } $ url = $ this -> _data ; $ name = pathinfo ( parse_url ( $ url , PHP_URL_PATH ) , PATHINFO_BASENAME ) ; if ( ! $ name ) { $ name = md5 ( microtime ( true ) ) ; } $ options = $ options + array ( CURLOPT_RETURNTRANSFER => true , CURLOPT_FOLLOWLOCATION => true , CURLOPT_FAILONERROR => true , CURLOPT_SSL_VERIFYPEER => false ) ; $ curl = curl_init ( $ url ) ; curl_setopt_array ( $ curl , $ options ) ; $ response = curl_exec ( $ curl ) ; $ error = curl_error ( $ curl ) ; curl_close ( $ curl ) ; if ( ! $ error ) { $ target = $ this -> findDestination ( $ name , $ overwrite ) ; if ( file_put_contents ( $ target , $ response ) ) { $ this -> _file = new File ( $ target ) ; return true ; } } throw new IoException ( sprintf ( 'Failed to import %s from remote location: %s' , $ name , $ error ) ) ; }
Copy a remote file to the temp directory and return a File object .
21,551
public function importFromStream ( $ overwrite = true ) { $ target = $ this -> findDestination ( $ this -> _data , $ overwrite ) ; $ input = fopen ( 'php://input' , 'r' ) ; $ output = fopen ( $ target , 'w' ) ; $ size = stream_copy_to_stream ( $ input , $ output ) ; fclose ( $ input ) ; fclose ( $ output ) ; if ( $ size <= 0 ) { @ unlink ( $ target ) ; throw new IoException ( 'No file detected in input stream' ) ; } $ this -> _file = new File ( $ target ) ; return $ size ; }
Copy a file from the input stream into the temp directory and return a File object . Primarily used for Javascript AJAX file uploads .
21,552
public function rollback ( ) { if ( $ files = $ this -> getAllFiles ( ) ) { foreach ( $ files as $ file ) { if ( $ file instanceof File ) { $ file -> delete ( ) ; } } } $ this -> _file = null ; $ this -> _files = array ( ) ; return $ this ; }
Rollback and delete all uploaded and transformed files .
21,553
public function setDirectory ( $ path ) { if ( substr ( $ path , - 1 ) !== '/' ) { $ path .= '/' ; } if ( ! file_exists ( $ path ) ) { mkdir ( $ path , 0777 , true ) ; } else if ( ! is_writable ( $ path ) ) { chmod ( $ path , 0777 ) ; } $ this -> _directory = $ path ; return $ this ; }
Set the temporary directory and create it if it does not exist .
21,554
public function transform ( ) { $ originalFile = $ this -> getOriginalFile ( ) ; $ transformedFiles = array ( ) ; $ error = null ; if ( ! $ originalFile ) { throw new IoException ( 'No original file detected' ) ; } if ( $ this -> _selfTransformers ) { foreach ( $ this -> _selfTransformers as $ transformer ) { try { $ originalFile = $ transformer -> transform ( $ originalFile , true ) ; } catch ( Exception $ e ) { $ error = $ e -> getMessage ( ) ; break ; } } $ originalFile -> reset ( ) ; } if ( $ this -> _transformers && ! $ error ) { foreach ( $ this -> _transformers as $ transformer ) { try { $ transformedFiles [ ] = $ transformer -> transform ( $ originalFile , false ) ; } catch ( Exception $ e ) { $ error = $ e -> getMessage ( ) ; break ; } } } $ this -> _file = $ originalFile ; $ this -> _files = $ transformedFiles ; if ( $ error ) { $ this -> rollback ( ) ; throw new TransformationException ( $ error ) ; } return true ; }
Apply transformations to the original file and generate new transformed files .
21,555
public function transport ( array $ config = array ( ) ) { if ( ! $ this -> _transporter ) { throw new InvalidArgumentException ( 'No Transporter has been defined' ) ; } $ localFiles = $ this -> getAllFiles ( ) ; $ transportedFiles = array ( ) ; $ error = null ; if ( ! $ localFiles ) { throw new IoException ( 'No files to transport' ) ; } foreach ( $ localFiles as $ i => $ file ) { try { $ tempConfig = $ config ; if ( isset ( $ tempConfig [ $ i ] ) ) { $ tempConfig = array_merge ( $ tempConfig , $ tempConfig [ $ i ] ) ; } $ transportedFiles [ ] = $ this -> getTransporter ( ) -> transport ( $ file , $ tempConfig ) ; } catch ( Exception $ e ) { $ error = $ e -> getMessage ( ) ; break ; } } if ( $ error ) { $ this -> rollback ( ) ; if ( $ transportedFiles ) { foreach ( $ transportedFiles as $ path ) { $ this -> getTransporter ( ) -> delete ( $ path ) ; } } throw new TransportationException ( $ error ) ; } return $ transportedFiles ; }
Transport the file using the Transporter object . An array of configuration can be passed to override the transporter configuration . If the configuration is numerically indexed individual file overrides can be set .
21,556
public function upload ( $ overwrite = false ) { $ data = $ this -> _data ; if ( empty ( $ data [ 'tmp_name' ] ) ) { throw new ValidationException ( 'Invalid file detected for upload' ) ; } if ( $ data [ 'error' ] > 0 || ! $ this -> _isUploadedFile ( $ data [ 'tmp_name' ] ) ) { switch ( $ data [ 'error' ] ) { case UPLOAD_ERR_INI_SIZE : case UPLOAD_ERR_FORM_SIZE : $ error = 'File exceeds the maximum file size' ; break ; case UPLOAD_ERR_PARTIAL : $ error = 'File was only partially uploaded' ; break ; case UPLOAD_ERR_NO_FILE : $ error = 'No file was found for upload' ; break ; default : $ error = 'File failed to upload' ; break ; } throw new ValidationException ( $ error ) ; } if ( $ validator = $ this -> getValidator ( ) ) { $ validator -> setFile ( new File ( $ data ) ) -> validate ( ) ; } $ target = $ this -> findDestination ( $ data [ 'name' ] , $ overwrite ) ; if ( $ this -> _moveUploadedFile ( $ data [ 'tmp_name' ] , $ target ) ) { $ data [ 'name' ] = basename ( $ target ) ; $ data [ 'tmp_name' ] = $ target ; $ this -> _file = new File ( $ data ) ; return true ; } throw new ValidationException ( 'An unknown error has occurred' ) ; }
Upload the file to the target directory .
21,557
public function add_validator_by_key ( ValidatorInterface $ validator , $ key ) { if ( ! is_scalar ( $ key ) ) { throw new Exception \ InvalidArgumentException ( 'key should be a scalar value.' ) ; } $ key = ( string ) $ key ; if ( ! isset ( $ this -> validators_by_key [ $ key ] ) ) { $ this -> validators_by_key [ $ key ] = [ ] ; } $ this -> validators_by_key [ $ key ] [ ] = $ validator ; return $ this ; }
Adding a validator grouped by array key .
21,558
private function validate ( $ values ) { $ is_valid = TRUE ; foreach ( $ values as $ key => $ value ) { if ( ! is_scalar ( $ value ) ) { continue ; } foreach ( $ this -> validators as $ validator ) { $ is_valid = $ validator -> is_valid ( $ value ) ; if ( ! $ is_valid ) { $ this -> error_messages [ $ key ] = $ validator -> get_error_messages ( ) ; break ; } } if ( ! $ is_valid ) { break ; } } return $ is_valid ; }
Validates all values .
21,559
protected function validate_by_key ( $ values ) { $ is_valid = TRUE ; if ( count ( $ this -> validators_by_key ) < 1 ) { return $ is_valid ; } foreach ( $ values as $ key => $ value ) { if ( ! is_scalar ( $ value ) || ! isset ( $ this -> validators_by_key [ $ key ] ) ) { continue ; } $ validators = $ this -> validators_by_key [ $ key ] ; foreach ( $ validators as $ validator ) { $ is_valid = $ validator -> is_valid ( $ value ) ; if ( ! $ is_valid ) { $ this -> error_messages [ $ key ] = $ validator -> get_error_messages ( ) ; break ; } } if ( ! $ is_valid ) { break ; } } return $ is_valid ; }
Validates all values by array - key .
21,560
public function convertToCommunityId ( $ id ) { switch ( self :: getTypeOfId ( $ id ) ) { case USER_ID_TYPE_COMMUNITY : return $ id ; case USER_ID_TYPE_VANITY : $ api_interface = new ISteamUser ( ) ; return $ api_interface -> ResolveVanityURL ( $ id ) ; case USER_ID_TYPE_STEAM : return self :: steamIdToCommunityId ( $ id ) ; default : return FALSE ; } }
Converts User ID into Community ID
21,561
public function getTypeOfId ( $ id ) { if ( self :: validateUserId ( $ id , USER_ID_TYPE_COMMUNITY ) ) return USER_ID_TYPE_COMMUNITY ; if ( self :: validateUserId ( $ id , USER_ID_TYPE_STEAM ) ) return USER_ID_TYPE_STEAM ; if ( self :: validateUserId ( $ id , USER_ID_TYPE_VANITY ) ) return USER_ID_TYPE_VANITY ; return FALSE ; }
Returns type of supplied ID
21,562
public function communityIdToSteamId ( $ community_id , $ is_short = FALSE ) { $ temp = intval ( $ community_id ) - 76561197960265728 ; $ odd_id = $ temp % 2 ; $ temp = floor ( $ temp / 2 ) ; if ( $ is_short ) { return $ odd_id . ':' . $ temp ; } else { return 'STEAM_0:' . $ odd_id . ':' . $ temp ; } }
Converts Community ID to Steam ID
21,563
public static function fromArray ( $ array , $ save_indexes = true ) { $ circular = new self ( count ( $ array ) ) ; foreach ( $ array as $ key => $ value ) { $ circular [ $ key ] = $ value ; } return $ circular ; }
Convert a simple array to fixed circular array
21,564
public static function contains ( TimeSlot $ a , TimeSlot $ b ) { $ c1 = DateTimeHelper :: isBetween ( $ b -> getStartDate ( ) , $ a -> getStartDate ( ) , $ a -> getEndDate ( ) ) ; $ c2 = DateTimeHelper :: isBetween ( $ b -> getEndDate ( ) , $ a -> getStartDate ( ) , $ a -> getEndDate ( ) ) ; return $ c1 && $ c2 ; }
Determines if a time slot A contains a time slot b .
21,565
public static function equals ( TimeSlot $ a , TimeSlot $ b ) { if ( false === DateTimeHelper :: equals ( $ a -> getStartDate ( ) , $ b -> getStartDate ( ) ) ) { return false ; } if ( false === DateTimeHelper :: equals ( $ a -> getEndDate ( ) , $ b -> getEndDate ( ) ) ) { return false ; } if ( count ( $ a -> getTimeSlots ( ) ) !== count ( $ b -> getTimeSlots ( ) ) ) { return false ; } for ( $ i = count ( $ a -> getTimeSlots ( ) ) - 1 ; 0 <= $ i ; -- $ i ) { if ( false === static :: equals ( $ a -> getTimeSlots ( ) [ $ i ] , $ b -> getTimeSlots ( ) [ $ i ] ) ) { return false ; } } return true ; }
Determines if two time slots are equals .
21,566
public static function fullJoin ( TimeSlot $ a , TimeSlot $ b ) { if ( false === static :: hasFullJoin ( $ a , $ b ) ) { return null ; } $ startDate = DateTimeHelper :: getSmaller ( $ a -> getStartDate ( ) , $ b -> getStartDate ( ) ) ; $ endDate = DateTimeHelper :: getGreater ( $ a -> getEndDate ( ) , $ b -> getEndDate ( ) ) ; return new TimeSlot ( clone $ startDate , clone $ endDate ) ; }
Full join two time slots .
21,567
public static function fullJoinWithout ( TimeSlot $ a , TimeSlot $ b ) { $ leftJoins = static :: leftJoinWithout ( $ a , $ b ) ; $ rightJoins = static :: rightJoinWithout ( $ a , $ b ) ; if ( null === $ leftJoins && null === $ rightJoins ) { return null ; } if ( null === $ leftJoins ) { return $ rightJoins ; } if ( null === $ rightJoins ) { return $ leftJoins ; } return static :: sort ( array_merge ( $ leftJoins , $ rightJoins ) ) ; }
Full join two time slots without time slots intersection .
21,568
public static function hasInnerJoin ( TimeSlot $ a , TimeSlot $ b ) { $ c1 = DateTimeHelper :: isBetween ( $ b -> getStartDate ( ) , $ a -> getStartDate ( ) , $ a -> getEndDate ( ) ) ; $ c2 = DateTimeHelper :: isBetween ( $ b -> getEndDate ( ) , $ a -> getStartDate ( ) , $ a -> getEndDate ( ) ) ; $ c3 = DateTimeHelper :: isBetween ( $ a -> getStartDate ( ) , $ b -> getStartDate ( ) , $ b -> getEndDate ( ) ) ; $ c4 = DateTimeHelper :: isBetween ( $ a -> getEndDate ( ) , $ b -> getStartDate ( ) , $ b -> getEndDate ( ) ) ; return $ c1 || $ c2 || $ c3 || $ c4 ; }
Determines if a time slot A has an inner join with time slot B .
21,569
public static function innerJoin ( TimeSlot $ a , TimeSlot $ b ) { if ( false === static :: hasInnerJoin ( $ a , $ b ) ) { return null ; } $ startDate = DateTimeHelper :: getGreater ( $ a -> getStartDate ( ) , $ b -> getStartDate ( ) ) ; $ endDate = DateTimeHelper :: getSmaller ( $ a -> getEndDate ( ) , $ b -> getEndDate ( ) ) ; return new TimeSlot ( clone $ startDate , clone $ endDate ) ; }
Inner join two time slots .
21,570
public static function leftJoin ( TimeSlot $ a , TimeSlot $ b ) { if ( false === static :: hasInnerJoin ( $ a , $ b ) ) { return null ; } return new TimeSlot ( clone $ a -> getStartDate ( ) , clone $ a -> getEndDate ( ) ) ; }
Left join two time slots .
21,571
public static function leftJoinWithout ( TimeSlot $ a , TimeSlot $ b ) { if ( false === static :: hasInnerJoin ( $ a , $ b ) || true === static :: contains ( $ b , $ a ) ) { return null ; } if ( true === static :: contains ( $ a , $ b ) ) { return static :: sort ( [ new TimeSlot ( clone $ a -> getStartDate ( ) , clone $ b -> getStartDate ( ) ) , new TimeSlot ( clone $ b -> getEndDate ( ) , clone $ a -> getEndDate ( ) ) , ] ) ; } $ startDate = true === DateTimeHelper :: isLessThan ( $ a -> getStartDate ( ) , $ b -> getStartDate ( ) ) ? $ a -> getStartDate ( ) : $ b -> getEndDate ( ) ; $ endDate = true === DateTimeHelper :: isGreaterThan ( $ a -> getEndDate ( ) , $ b -> getEndDate ( ) ) ? $ a -> getEndDate ( ) : $ b -> getStartDate ( ) ; return [ new TimeSlot ( clone $ startDate , clone $ endDate ) , ] ; }
Left join two time slots without time slot B intersection .
21,572
public static function sort ( array $ timeSlots ) { $ sorter = new QuickSort ( $ timeSlots , new TimeSlotFunctor ( ) ) ; $ sorter -> sort ( ) ; return $ sorter -> getValues ( ) ; }
Sort time slots .
21,573
public function columns ( ) { $ columns = self :: config ( ) -> columns ; if ( ! Security :: config ( ) -> get ( 'login_recording' ) ) { unset ( $ columns [ 'LastLoggedIn' ] ) ; } return $ columns ; }
Returns the column names of the report
21,574
public function addAsset ( array $ Asset ) { if ( isset ( $ Asset [ 'name' ] ) && ! array_key_exists ( $ Asset [ 'name' ] , $ this -> holder ) ) { $ this -> holder [ $ Asset [ 'name' ] ] = $ Asset ; } }
adds the asset to the main holder
21,575
public function delAsset ( array $ Asset ) { if ( isset ( $ Asset [ 'name' ] ) && array_key_exists ( $ Asset [ 'name' ] , $ this -> holder ) ) { unset ( $ this -> holder [ $ Asset [ 'name' ] ] ) ; } }
delete the asset from the main holder
21,576
public function addCss ( $ link ) { if ( ! empty ( $ link ) ) { if ( ! is_array ( $ link ) ) { $ link = [ $ link ] ; } $ this -> css = array_merge ( $ this -> css , $ link ) ; } }
adds css to the css list
21,577
public function addJs ( $ link ) { if ( ! empty ( $ link ) ) { if ( ! is_array ( $ link ) ) { $ link = [ $ link ] ; } $ this -> js = array_merge ( $ this -> js , $ link ) ; } }
adds js to the js list
21,578
public function delCss ( $ link ) { if ( ! empty ( $ link ) ) { if ( ! is_array ( $ link ) ) { $ link = [ $ link ] ; } if ( ! isset ( $ this -> obsolete [ 'css' ] ) ) { $ this -> obsolete [ 'css' ] = [ ] ; } $ this -> obsolete [ 'css' ] = array_merge ( $ this -> obsolete [ 'css' ] , $ link ) ; } }
deleted css from the css list
21,579
public function delJs ( $ link ) { if ( ! empty ( $ link ) ) { if ( ! is_array ( $ link ) ) { $ link = [ $ link ] ; } if ( ! isset ( $ this -> obsolete [ 'js' ] ) ) { $ this -> obsolete [ 'js' ] = [ ] ; } $ this -> obsolete [ 'js' ] = array_merge ( $ this -> obsolete [ 'js' ] , $ link ) ; } }
deletes js from the js list
21,580
private function addScriptBefore ( $ script ) { $ script = trim ( $ script ) ; if ( $ script != '' ) { if ( strpos ( $ this -> script , $ script ) === false ) { $ this -> script = " {$script} {$this->script}" ; } } }
this method add the init script into the first of scripts
21,581
public function reset ( ) { $ this -> script = '' ; $ this -> style = '' ; $ this -> js = [ ] ; $ this -> css = [ ] ; $ this -> obsolete = [ ] ; $ this -> holder = [ ] ; $ this -> run = false ; }
removes all the added style scripts & assets
21,582
private function runCopy ( ) { if ( ! $ this -> run ) { foreach ( $ this -> holder as $ name => $ contents ) { if ( array_key_exists ( 'copy' , $ contents ) ) { if ( ! array_key_exists ( 'forceCopy' , $ contents ) ) { $ contents [ 'forceCopy' ] = false ; } if ( ! array_key_exists ( 'chmod' , $ contents ) ) { $ contents [ 'chmod' ] = 0777 ; } foreach ( $ contents [ 'copy' ] as $ from => $ to ) { $ this -> copy ( $ from , $ to , $ contents [ 'forceCopy' ] , $ contents [ 'chmod' ] ) ; } } if ( array_key_exists ( 'script' , $ contents ) ) { $ this -> addScriptBefore ( $ contents [ 'script' ] ) ; } if ( array_key_exists ( 'style' , $ contents ) ) { $ this -> addStyle ( $ contents [ 'style' ] ) ; } if ( array_key_exists ( 'css' , $ contents ) ) { $ this -> addCss ( $ contents [ 'css' ] ) ; } if ( array_key_exists ( 'js' , $ contents ) ) { $ this -> addJs ( $ contents [ 'js' ] ) ; } } if ( array_key_exists ( 'css' , $ this -> obsolete ) ) { $ this -> css = array_diff ( $ this -> css , $ this -> obsolete [ 'css' ] ) ; } $ this -> css = array_unique ( $ this -> css ) ; if ( array_key_exists ( 'js' , $ this -> obsolete ) ) { $ this -> js = array_diff ( $ this -> js , $ this -> obsolete [ 'js' ] ) ; } $ this -> js = array_unique ( $ this -> js ) ; if ( array_key_exists ( 'script' , $ this -> obsolete ) ) { $ this -> script = str_replace ( $ this -> obsolete [ 'script' ] , '' , $ this -> script ) ; } if ( array_key_exists ( 'style' , $ this -> obsolete ) ) { $ this -> style = str_replace ( $ this -> obsolete [ 'style' ] , '' , $ this -> style ) ; } $ this -> run = true ; } }
does all the copying and making the last cleaned arrays for use this method run only once per request
21,583
public function _pre_set_site_transient_update_themes ( $ transient ) { $ current = wp_get_theme ( $ this -> theme_name ) ; $ api_data = $ this -> _get_transient_api_data ( ) ; if ( is_wp_error ( $ api_data ) ) { $ this -> _set_notice_error_about_github_api ( ) ; return $ transient ; } if ( ! isset ( $ api_data -> tag_name ) ) { return $ transient ; } if ( ! $ this -> _should_update ( $ current [ 'Version' ] , $ api_data -> tag_name ) ) { return $ transient ; } $ package = $ this -> _get_zip_url ( $ api_data ) ; $ http_status_code = $ this -> _get_http_status_code ( $ package ) ; if ( ! $ package || ! in_array ( $ http_status_code , [ 200 , 302 ] ) ) { error_log ( 'Inc2734_WP_GitHub_Theme_Updater error. zip url not found. ' . $ http_status_code . ' ' . $ package ) ; return $ transient ; } $ transient -> response [ $ this -> theme_name ] = [ 'theme' => $ this -> theme_name , 'new_version' => $ api_data -> tag_name , 'url' => ( ! empty ( $ this -> fields [ 'homepage' ] ) ) ? $ this -> fields [ 'homepage' ] : '' , 'package' => $ package , ] ; return $ transient ; }
Overwirte site_transient_update_themes from GitHub API
21,584
protected function _set_notice_error_about_github_api ( ) { $ api_data = $ this -> _get_transient_api_data ( ) ; if ( ! is_wp_error ( $ api_data ) ) { return ; } add_action ( 'admin_notices' , function ( ) use ( $ api_data ) { ?> <div class="notice notice-error"> <p> <?php echo esc_html ( $ api_data -> get_error_message ( ) ) ; ?> </p> </div> <?php } ) ; }
Set notice error about GitHub API using admin_notice hook
21,585
protected function _get_zip_url ( $ remote ) { $ url = false ; if ( ! empty ( $ remote -> assets ) && is_array ( $ remote -> assets ) ) { if ( ! empty ( $ remote -> assets [ 0 ] ) && is_object ( $ remote -> assets [ 0 ] ) ) { if ( ! empty ( $ remote -> assets [ 0 ] -> browser_download_url ) ) { $ url = $ remote -> assets [ 0 ] -> browser_download_url ; } } } $ tag_name = isset ( $ remote -> tag_name ) ? $ remote -> tag_name : null ; if ( ! $ url && $ tag_name ) { $ url = sprintf ( 'https://github.com/%1$s/%2$s/archive/%3$s.zip' , $ this -> user_name , $ this -> repository , $ tag_name ) ; } return apply_filters ( sprintf ( 'inc2734_github_theme_updater_zip_url_%1$s/%2$s' , $ this -> user_name , $ this -> repository ) , $ url , $ this -> user_name , $ this -> repository , $ tag_name ) ; }
Return URL of new zip file
21,586
protected function _get_transient_api_data ( ) { $ transient_name = sprintf ( 'wp_github_theme_updater_%1$s' , $ this -> theme_name ) ; $ transient = get_transient ( $ transient_name ) ; if ( false !== $ transient ) { return $ transient ; } $ api_data = $ this -> _get_github_api_data ( ) ; set_transient ( $ transient_name , $ api_data , 60 * 5 ) ; return $ api_data ; }
Return the data from the Transient API or GitHub API .
21,587
protected function _get_github_api_data ( ) { $ response = $ this -> _request_github_api ( ) ; if ( is_wp_error ( $ response ) ) { return $ response ; } $ response_code = wp_remote_retrieve_response_code ( $ response ) ; $ body = json_decode ( wp_remote_retrieve_body ( $ response ) ) ; if ( 200 == $ response_code ) { return $ body ; } return new \ WP_Error ( $ response_code , 'Inc2734_WP_GitHub_Theme_Updater error. ' . $ body -> message ) ; }
Return the data from the GitHub API .
21,588
protected function _request_github_api ( ) { global $ wp_version ; $ url = sprintf ( 'https://api.github.com/repos/%1$s/%2$s/releases/latest' , $ this -> user_name , $ this -> repository ) ; return wp_remote_get ( apply_filters ( sprintf ( 'inc2734_github_theme_updater_request_url_%1$s/%2$s' , $ this -> user_name , $ this -> repository ) , $ url , $ this -> user_name , $ this -> repository ) , [ 'user-agent' => 'WordPress/' . $ wp_version , 'headers' => [ 'Accept-Encoding' => '' , ] , ] ) ; }
Get request to GitHub API
21,589
protected function _should_update ( $ current_version , $ remote_version ) { return version_compare ( $ this -> _sanitize_version ( $ current_version ) , $ this -> _sanitize_version ( $ remote_version ) , '<' ) ; }
If remote version is newer return true
21,590
protected function isUsingQueue ( ) { $ queue = false ; $ driver = 'mail' ; if ( $ this -> memory instanceof Provider ) { $ queue = $ this -> memory -> get ( 'email.queue' , false ) ; $ driver = $ this -> memory -> get ( 'email.driver' ) ; } return $ queue || \ in_array ( $ driver , [ 'mailgun' , 'mandrill' , 'log' ] ) ; }
Determine if mailer using queue .
21,591
public function getMageShippingCountries ( $ storeId = null ) { return $ this -> countryCollection -> loadByStore ( $ this -> storeManager -> getStore ( $ storeId ) ) -> getColumnValues ( 'country_id' ) ; }
Retrieves magento s allowed shipping countries
21,592
public function getActiveCarriers ( $ storeId = null ) { return $ this -> carrierConfig -> getActiveCarriers ( $ this -> storeManager -> getStore ( $ storeId ) ) ; }
Retrieves all carriers that are currently set to active in magento
21,593
public function getPhpType ( ) { if ( isset ( self :: $ _phpTypesByProtobufType [ $ this -> getType ( ) ] ) ) { return self :: $ _phpTypesByProtobufType [ $ this -> getType ( ) ] ; } else { return null ; } }
Returns PHP type
21,594
public function delete ( $ id ) { $ config = $ this -> getConfig ( ) ; try { $ this -> getClient ( ) -> deleteArchive ( array_filter ( array ( 'vaultName' => $ config [ 'vault' ] , 'accountId' => $ config [ 'accountId' ] , 'archiveId' => $ id ) ) ) ; } catch ( GlacierException $ e ) { return false ; } return true ; }
Delete a file from Amazon Glacier using the archive ID .
21,595
public function transport ( File $ file , array $ config = array ( ) ) { $ config = $ config + $ this -> getConfig ( ) ; $ response = null ; if ( $ file -> size ( ) >= ( 100 * Size :: MB ) ) { $ uploader = UploadBuilder :: newInstance ( ) -> setClient ( $ this -> getClient ( ) ) -> setSource ( $ file -> path ( ) ) -> setVaultName ( $ config [ 'vault' ] ) -> setAccountId ( $ config [ 'accountId' ] ? : '-' ) -> setPartSize ( 10 * Size :: MB ) -> build ( ) ; try { $ response = $ uploader -> upload ( ) ; } catch ( MultipartUploadException $ e ) { $ uploader -> abort ( ) ; } } else { $ response = $ this -> getClient ( ) -> uploadArchive ( array_filter ( array ( 'vaultName' => $ config [ 'vault' ] , 'accountId' => $ config [ 'accountId' ] , 'body' => EntityBody :: factory ( fopen ( $ file -> path ( ) , 'r' ) ) , ) ) ) ; } if ( $ response ) { $ config [ 'removeLocal' ] && $ file -> delete ( ) ; return $ response -> getPath ( 'archiveId' ) ; } throw new TransportationException ( sprintf ( 'Failed to transport %s to Amazon Glacier' , $ file -> basename ( ) ) ) ; }
Transport the file to Amazon Glacier and return the archive ID .
21,596
public function preRequest ( \ SS_HTTPRequest $ request , \ Session $ session , \ DataModel $ model ) { $ this -> registerGlobalHandlers ( ) ; return true ; }
This hook function is executed from RequestProcessor before the request starts
21,597
public function postRequest ( \ SS_HTTPRequest $ request , \ SS_HTTPResponse $ response , \ DataModel $ model ) { $ this -> deregisterGlobalHandlers ( ) ; return true ; }
This hook function is executed from RequestProcessor after the request ends
21,598
public function registerGlobalHandlers ( ) { if ( ! $ this -> registered ) { $ this -> registerErrorHandler ( ) ; $ this -> registerExceptionHandler ( ) ; if ( $ this -> registered === null ) { $ this -> registerFatalErrorHandler ( ) ; if ( $ this -> isSuhosinRelevant ( ) ) { $ this -> ensureSuhosinMemory ( ) ; } } $ this -> registered = true ; } }
Registers global error handlers
21,599
public function deregisterGlobalHandlers ( ) { if ( $ this -> registered ) { set_error_handler ( is_callable ( $ this -> errorHandler ) ? $ this -> errorHandler : function ( ) { } ) ; set_exception_handler ( is_callable ( $ this -> exceptionHandler ) ? $ this -> exceptionHandler : function ( ) { } ) ; $ this -> registered = false ; } }
Removes handlers we have added and restores others if possible