idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
11,400
|
public function getHeader ( $ keyName ) { $ headers = $ this -> getHeaders ( ) ; $ keyName = self :: normalizeHeaderKeyName ( $ keyName ) ; if ( array_key_exists ( $ keyName , $ headers ) ) { return $ headers [ $ keyName ] ; } return ; }
|
Get the value of the request header keyname .
|
11,401
|
public function getHeaders ( ) { $ headers = [ ] ; foreach ( $ this -> srv as $ k => $ v ) { $ headers [ self :: normalizeHeaderKeyName ( $ k ) ] = $ v ; } return $ headers ; }
|
Get the HTTP headers .
|
11,402
|
public static function doDelete ( $ values , ConnectionInterface $ con = null ) { if ( null === $ con ) { $ con = Propel :: getServiceContainer ( ) -> getWriteConnection ( CustomerCustomerGroupTableMap :: DATABASE_NAME ) ; } if ( $ values instanceof Criteria ) { $ criteria = $ values ; } elseif ( $ values instanceof \ CustomerGroup \ Model \ CustomerCustomerGroup ) { $ criteria = $ values -> buildPkeyCriteria ( ) ; } else { $ criteria = new Criteria ( CustomerCustomerGroupTableMap :: DATABASE_NAME ) ; if ( count ( $ values ) == count ( $ values , COUNT_RECURSIVE ) ) { $ values = array ( $ values ) ; } foreach ( $ values as $ value ) { $ criterion = $ criteria -> getNewCriterion ( CustomerCustomerGroupTableMap :: CUSTOMER_ID , $ value [ 0 ] ) ; $ criterion -> addAnd ( $ criteria -> getNewCriterion ( CustomerCustomerGroupTableMap :: CUSTOMER_GROUP_ID , $ value [ 1 ] ) ) ; $ criteria -> addOr ( $ criterion ) ; } } $ query = CustomerCustomerGroupQuery :: create ( ) -> mergeWith ( $ criteria ) ; if ( $ values instanceof Criteria ) { CustomerCustomerGroupTableMap :: clearInstancePool ( ) ; } elseif ( ! is_object ( $ values ) ) { foreach ( ( array ) $ values as $ singleval ) { CustomerCustomerGroupTableMap :: removeInstanceFromPool ( $ singleval ) ; } } return $ query -> delete ( $ con ) ; }
|
Performs a DELETE on the database given a CustomerCustomerGroup or Criteria object OR a primary key value .
|
11,403
|
public static function invokeSafe ( callable $ function , array $ args , callable $ onError ) { $ prev = \ set_error_handler ( static function ( $ severity , $ message , $ file ) use ( $ onError , & $ prev ) { if ( $ file === __FILE__ && $ onError ( $ message , $ severity ) !== false ) { return null ; } if ( $ prev ) { return \ call_user_func_array ( $ prev , \ func_get_args ( ) ) ; } return false ; } ) ; try { $ res = \ call_user_func_array ( $ function , $ args ) ; \ restore_error_handler ( ) ; return $ res ; } catch ( \ Throwable $ e ) { \ restore_error_handler ( ) ; throw $ e ; } }
|
Invokes internal PHP function with own error handler .
|
11,404
|
public static function get ( $ key , $ default = "default" ) { if ( self :: $ config == array ( ) ) self :: load ( ) ; $ env = Kernel :: getEnvironment ( ) ; $ position = self :: $ config [ $ env ] ; $ token = strtok ( $ key , '.' ) ; while ( $ token !== false ) { $ nextToken = strtok ( '.' ) ; if ( ! isset ( $ position [ $ token ] ) ) return $ default ; if ( $ nextToken === false ) return $ position [ $ token ] ; $ position = & $ position [ $ token ] ; $ token = $ nextToken ; } return $ default ; }
|
Get a configuration entry
|
11,405
|
private function getMode ( $ tokens ) { switch ( $ tokens -> getQueryMode ( ) ) { case 'find' : return QueryBuilderResult :: RESULT_SELECT_MULTIPLE ; case 'get' : return QueryBuilderResult :: RESULT_SELECT_SINGLE ; case 'delete' : return QueryBuilderResult :: RESULT_DELETE ; } throw new DslSyntaxException ( 'No query could be built for ' . $ tokens -> getMethodName ( ) . ': Unknown query mode [' . $ tokens -> getQueryMode ( ) . ']' , DATADO_ILLEGAL_RESULT_MODE ) ; }
|
Get the result type for a MethodNameToken .
|
11,406
|
private function getFields ( $ tokens , $ namingConvention , $ class ) { $ fields = [ ] ; $ prefix = '' ; foreach ( $ tokens -> getTokens ( ) as $ token ) { if ( $ token instanceof ByToken ) { return $ prefix . $ this -> fieldsToSQL ( $ fields , $ class , $ namingConvention ) ; } if ( $ token instanceof AllToken ) { return $ prefix . $ this -> fieldsToSQL ( [ ] , $ class , $ namingConvention ) ; } if ( $ token instanceof DistinctToken ) { $ prefix .= 'DISTINCT ' ; continue ; } if ( $ token instanceof AndToken ) { continue ; } if ( ! ( $ token instanceof ValueToken ) ) { throw new DslSyntaxException ( 'Unexpected token ' . $ token -> getName ( ) . ' in field selector' , DATADO_UNEXPECTED_TOKEN ) ; } $ fields [ ] = lcfirst ( $ token -> getSource ( ) ) ; } return $ prefix . $ this -> fieldsToSQL ( $ fields , $ class , $ namingConvention ) ; }
|
Build the SQL string for the fields from a MethodNameToken
|
11,407
|
private function tokenToColumn ( $ token , $ namingConvention , $ class ) { $ property = null ; foreach ( $ class -> getProperties ( ) as $ prop ) { if ( strcasecmp ( $ token -> getSource ( ) , $ prop -> getName ( ) ) === 0 ) { $ property = $ prop ; break ; } } if ( $ property === null ) { throw new DslSyntaxException ( 'No matching property found for ' . $ token -> getSource ( ) ) ; } return $ namingConvention -> propertyToColumnName ( $ property ) ; }
|
Get the column name for a token .
|
11,408
|
public static function unflatten ( array $ array , $ delimiter = '.' ) { $ unflattenedArray = array ( ) ; foreach ( $ array as $ key => $ value ) { $ keyList = explode ( $ delimiter , $ key ) ; $ firstKey = array_shift ( $ keyList ) ; if ( sizeof ( $ keyList ) > 0 ) { $ subArray = static :: unflatten ( array ( implode ( $ delimiter , $ keyList ) => $ value ) , $ delimiter ) ; foreach ( $ subArray as $ subArrayKey => $ subArrayValue ) { $ unflattenedArray [ $ firstKey ] [ $ subArrayKey ] = $ subArrayValue ; } } else { $ unflattenedArray [ $ firstKey ] = $ value ; } } return $ unflattenedArray ; }
|
Unflattens a single stacked array back into a multidimensional array .
|
11,409
|
public function getCoupons ( $ code = null ) { $ requestData = new Get \ RequestData ( $ code ) ; $ request = new Get \ Request ( $ requestData ) ; $ apiResponse = $ this -> sendRequest ( $ request , Get \ ApiResponse :: class ) ; $ response = $ apiResponse -> getResponse ( ) ; foreach ( $ response -> getCoupons ( ) as $ coupon ) { $ validFrom = $ coupon -> getValidFrom ( ) ; if ( $ validFrom !== null ) { $ validFrom -> setTime ( 0 , 0 , 0 ) ; } $ validTo = $ coupon -> getValidTo ( ) ; if ( $ validTo !== null ) { $ validTo -> setTime ( 0 , 0 , 0 ) ; } } return $ apiResponse ; }
|
Get the coupons .
|
11,410
|
public function checkCoupon ( $ code , $ articleNumber ) { $ requestData = new Check \ RequestData ( $ code , $ articleNumber ) ; $ request = new Check \ Request ( $ requestData ) ; return $ this -> sendRequest ( $ request , Check \ ApiResponse :: class ) ; }
|
Check a coupon .
|
11,411
|
public function addStore ( $ storeName , $ builderName , array $ options = array ( ) ) { $ this -> storeRegistryBuilder -> addStore ( $ storeName , $ builderName , $ options ) ; }
|
Adds a store to the builder
|
11,412
|
private function dispenseToken ( ) { $ token = bin2hex ( random_bytes ( $ this -> config -> getTokenLength ( ) ) ) ; $ arr = array ( 'token' => $ token , 'expires' => time ( ) + $ this -> config -> getTokenTtl ( ) ) ; $ plain = Spyc :: YAMLDump ( $ arr ) ; $ encrypted = Encryption :: encrypt ( $ plain , $ this -> config -> getSecretKey ( ) ) ; file_put_contents ( $ this -> config -> getSessionFileName ( ) , $ encrypted ) ; return $ token ; }
|
Dispenses a randomly generated authentication token .
|
11,413
|
private function validateToken ( $ token ) { if ( ! file_exists ( $ this -> config -> getSessionFileName ( ) ) ) { return false ; } $ encrypted = file_get_contents ( $ this -> config -> getSessionFileName ( ) ) ; $ plain = Encryption :: decrypt ( $ encrypted , $ this -> config -> getSecretKey ( ) ) ; $ file = Spyc :: YAMLLoadString ( $ plain ) ; return $ token == $ file [ 'token' ] && time ( ) < $ file [ 'expires' ] ; }
|
Returns true if the given authentication token is valid otherwise returns false .
|
11,414
|
public function getCookieToken ( ) { if ( $ this -> cookieToken !== null ) { return $ this -> cookieToken ; } $ name = $ this -> config -> getCookieName ( ) ; $ plain = '' ; if ( isset ( $ _COOKIE [ $ name ] ) ) { $ encrypted = $ _COOKIE [ $ name ] ; $ plain = Encryption :: decrypt ( $ encrypted , $ this -> config -> getSecretKey ( ) ) ; } $ this -> cookieToken = $ plain ; return $ plain ; }
|
Decrypts the stored authentication token out of the authentication cookie and returns it .
|
11,415
|
public function setCookieToken ( $ token ) { $ this -> cookieToken = $ token ; $ encrypted = Encryption :: encrypt ( $ token , $ this -> config -> getSecretKey ( ) ) ; setcookie ( $ this -> config -> getCookieName ( ) , $ encrypted , time ( ) + $ this -> config -> getTokenTtl ( ) , '/' , '' , $ this -> config -> getCookieSslOnly ( ) , $ this -> config -> getCookieHttpOnly ( ) ) ; }
|
Encrypts an authentication token into the authentication cookie .
|
11,416
|
public function authenticate ( $ email , $ password ) { if ( $ this -> config -> getCookieSslOnly ( ) && ! isset ( $ _SERVER [ 'HTTPS' ] ) ) { echo 'Connection is insecure, login cannot proceed.' ; die ( ) ; } if ( $ this -> config -> getAdminEmail ( ) != $ email || ! Encryption :: verify ( $ password , $ this -> config -> getAdminPasswordHash ( ) ) ) { return false ; } $ this -> setCookieToken ( $ this -> dispenseToken ( ) ) ; return true ; }
|
Authenticates the given e - mail address password pair .
|
11,417
|
public function isAuthenticated ( ) { $ authenticated = $ this -> validateToken ( $ this -> getCookieToken ( ) ) ; if ( $ authenticated ) { $ this -> setCookieToken ( $ this -> dispenseToken ( ) ) ; } return $ authenticated ; }
|
Checks whether or not the current user is authenticated .
|
11,418
|
public function logout ( ) { setcookie ( $ this -> config -> getCookieName ( ) , '' , time ( ) - 3600 ) ; unlink ( $ this -> config -> getSessionFileName ( ) ) ; }
|
Logs the currently authenticated user out .
|
11,419
|
public function getSourceModelName ( $ type = null ) { $ type = $ type ? : $ this -> source_type ; return source_model_name ( $ type , true ) ; }
|
Returns the source model name
|
11,420
|
public static function newWithType ( $ locale , $ type ) { $ nodeSource = new static ( ) ; $ sourceModel = $ nodeSource -> getNewSourceModel ( $ type ) ; $ nodeSource -> setTemporarySource ( $ sourceModel ) ; $ nodeSource -> setAttribute ( 'locale' , $ locale ) ; $ nodeSource -> setAttribute ( 'source_type' , $ type ) ; return $ nodeSource ; }
|
Create new node source with locale and type
|
11,421
|
public function getSource ( ) { if ( ! is_null ( $ this -> tempSource ) ) { return $ this -> tempSource ; } if ( ! $ this -> isSourceRelationLoaded ( ) ) { $ this -> load ( 'source' ) ; } return $ this -> relations [ 'source' ] ; }
|
Getter for source data
|
11,422
|
protected function saveSource ( ) { if ( ! is_null ( $ this -> tempSource ) ) { $ saved = $ this -> source ( ) -> save ( $ this -> tempSource ) ; $ this -> load ( 'source' ) ; $ this -> flushTemporarySource ( ) ; return ! is_null ( $ saved ) ; } return $ this -> source -> save ( ) ; }
|
Saves the source model
|
11,423
|
public function setAttribute ( $ key , $ value ) { if ( $ this -> isBaseAttribute ( $ key ) ) { return parent :: setAttribute ( $ key , $ value ) ; } else { return $ this -> getSource ( ) -> setAttribute ( $ key , $ value ) ; } }
|
Sets a model attribute
|
11,424
|
public function setExtensionNodeId ( $ id , $ save = true ) { $ source = $ this -> getSource ( ) -> setNodeId ( $ id ) ; if ( $ save ) { $ source -> save ( ) ; } }
|
Sets the extension node id
|
11,425
|
protected function event ( HttpException $ event , Context $ context = null ) { $ code = $ event -> getCode ( ) ; if ( isset ( $ this -> events [ $ code ] ) ) { $ context -> error = $ event ; $ context -> response -> code = $ event -> getCode ( ) ; $ this -> logger -> debug ( 'kernel.event: http ' . $ code . ' event raised, has callback' ) ; return $ context -> forward ( $ this -> events [ $ code ] , $ event ) ; } $ this -> logger -> debug ( 'kernel.event: http ' . $ code . ' event raised, no callback' ) ; throw $ event ; }
|
Handle http event
|
11,426
|
public function joinChannels ( $ dummy , EventQueueInterface $ queue ) { $ queue -> ircJoin ( $ this -> channels , $ this -> keys ) ; }
|
Joins the provided list of channels .
|
11,427
|
protected function getClient ( array $ auth ) { $ this -> cookieFile = storage_path ( ) . '/guzzlehttp/cookies/vonage/' . $ auth [ 'username' ] . '.txt' ; $ cookieJar = new FileCookieJar ( $ this -> cookieFile , true ) ; $ this -> client = new Client ( array ( 'base_uri' => $ this -> base_uri , 'cookies' => $ cookieJar ) ) ; $ response = $ this -> client -> get ( $ this -> base_uri . '/appserver/rest/user/null' , [ 'cookies' => $ cookieJar , 'query' => [ 'htmlLogin' => $ auth [ 'username' ] , 'htmlPassword' => $ auth [ 'password' ] ] , 'headers' => [ 'X-Vonage' => 'vonage' ] ] ) ; return $ this -> client ; }
|
Get the vonage client .
|
11,428
|
public function initialize ( AgaviContext $ context , array $ parameters = array ( ) ) { parent :: initialize ( $ context , $ parameters ) ; $ this -> plugin_dir = $ this -> getParameter ( 'plugin_dir' , $ this -> plugin_dir ) ; }
|
Initialize this Renderer .
|
11,429
|
public function compilerFactory ( ) { if ( class_exists ( 'Dwoo_Compiler' , false ) === false ) { include DWOO_DIRECTORY . 'Dwoo/Compiler.php' ; } $ compiler = Dwoo_Compiler :: compilerFactory ( ) ; $ compiler -> setAutoEscape ( ( bool ) $ this -> getParameter ( 'auto_escape' , false ) ) ; return $ compiler ; }
|
provides a custom compiler to the dwoo renderer with optional settings you can set in the agavi output_types . xml config file
|
11,430
|
protected function getEngine ( ) { if ( $ this -> dwoo ) { return $ this -> dwoo ; } if ( ! class_exists ( 'Dwoo' ) ) { if ( file_exists ( dirname ( __FILE__ ) . '/../../../dwooAutoload.php' ) ) { require dirname ( __FILE__ ) . '/../../../dwooAutoload.php' ; } else { require 'dwooAutoload.php' ; } } $ parentMode = fileperms ( AgaviConfig :: get ( 'core.cache_dir' ) ) ; $ compileDir = AgaviConfig :: get ( 'core.cache_dir' ) . DIRECTORY_SEPARATOR . self :: COMPILE_DIR . DIRECTORY_SEPARATOR . self :: COMPILE_SUBDIR ; AgaviToolkit :: mkdir ( $ compileDir , $ parentMode , true ) ; $ cacheDir = AgaviConfig :: get ( 'core.cache_dir' ) . DIRECTORY_SEPARATOR . self :: CACHE_DIR ; AgaviToolkit :: mkdir ( $ cacheDir , $ parentMode , true ) ; $ this -> dwoo = new Dwoo ( $ compileDir , $ cacheDir ) ; if ( ! empty ( $ this -> plugin_dir ) ) { $ this -> dwoo -> getLoader ( ) -> addDirectory ( $ this -> plugin_dir ) ; } $ this -> dwoo -> setDefaultCompilerFactory ( 'file' , array ( $ this , 'compilerFactory' ) ) ; return $ this -> dwoo ; }
|
Grab a cleaned up dwoo instance .
|
11,431
|
public function render ( AgaviTemplateLayer $ layer , array & $ attributes = array ( ) , array & $ slots = array ( ) , array & $ moreAssigns = array ( ) ) { $ engine = $ this -> getEngine ( ) ; $ data = array ( ) ; if ( $ this -> extractVars ) { $ data = $ attributes ; } else { $ data [ $ this -> varName ] = & $ attributes ; } $ data [ $ this -> slotsVarName ] = & $ slots ; foreach ( $ this -> assigns as $ key => $ getter ) { $ data [ $ key ] = $ this -> context -> $ getter ( ) ; } foreach ( $ moreAssigns as $ key => & $ value ) { if ( isset ( $ this -> moreAssignNames [ $ key ] ) ) { $ key = $ this -> moreAssignNames [ $ key ] ; } $ data [ $ key ] = & $ value ; } return $ engine -> get ( $ layer -> getResourceStreamIdentifier ( ) , $ data ) ; }
|
Render the presentation and return the result .
|
11,432
|
public function execute ( ProjectDescriptor $ project ) { Dispatcher :: getInstance ( ) -> dispatch ( self :: EVENT_PRE_TRANSFORM , PreTransformEvent :: createInstance ( $ this ) -> setProject ( $ project ) ) ; $ transformations = $ this -> getTemplates ( ) -> getTransformations ( ) ; $ this -> initializeWriters ( $ project , $ transformations ) ; $ this -> transformProject ( $ project , $ transformations ) ; Dispatcher :: getInstance ( ) -> dispatch ( self :: EVENT_POST_TRANSFORM , PostTransformEvent :: createInstance ( $ this ) ) ; $ this -> log ( 'Finished transformation process' ) ; }
|
Transforms the given project into a series of artifacts as provided by the templates .
|
11,433
|
public function generateFilename ( $ name ) { if ( substr ( $ name , - 4 ) == '.php' ) { $ name = substr ( $ name , 0 , - 4 ) ; } return trim ( str_replace ( array ( DIRECTORY_SEPARATOR , '\\' ) , '.' , trim ( $ name , DIRECTORY_SEPARATOR . '.' ) ) , '.' ) . '.html' ; }
|
Converts a source file name to the name used for generating the end result .
|
11,434
|
public function debug ( $ message ) { Dispatcher :: getInstance ( ) -> dispatch ( 'system.debug' , DebugEvent :: createInstance ( $ this ) -> setMessage ( $ message ) ) ; }
|
Dispatches a logging request to log a debug message .
|
11,435
|
private function initializeWriters ( ProjectDescriptor $ project , $ transformations ) { $ isInitialized = array ( ) ; foreach ( $ transformations as $ transformation ) { $ writerName = $ transformation -> getWriter ( ) ; if ( in_array ( $ writerName , $ isInitialized ) ) { continue ; } $ isInitialized [ ] = $ writerName ; $ writer = $ this -> writers [ $ writerName ] ; $ this -> initializeWriter ( $ writer , $ project ) ; } }
|
Initializes all writers that are used during this transformation .
|
11,436
|
private function initializeWriter ( WriterAbstract $ writer , ProjectDescriptor $ project ) { $ event = WriterInitializationEvent :: createInstance ( $ this ) -> setWriter ( $ writer ) ; Dispatcher :: getInstance ( ) -> dispatch ( self :: EVENT_PRE_INITIALIZATION , $ event ) ; if ( $ writer instanceof Initializable ) { $ writer -> initialize ( $ project ) ; } Dispatcher :: getInstance ( ) -> dispatch ( self :: EVENT_POST_INITIALIZATION , $ event ) ; }
|
Initializes the given writer using the provided project meta - data .
|
11,437
|
private function transformProject ( ProjectDescriptor $ project , $ transformations ) { foreach ( $ transformations as $ transformation ) { $ transformation -> setTransformer ( $ this ) ; $ this -> applyTransformationToProject ( $ transformation , $ project ) ; } }
|
Applies all given transformations to the provided project .
|
11,438
|
private function applyTransformationToProject ( Transformation $ transformation , ProjectDescriptor $ project ) { $ this -> log ( sprintf ( ' Writer %s %s on %s' , $ transformation -> getWriter ( ) , ( $ transformation -> getQuery ( ) ? ' using query "' . $ transformation -> getQuery ( ) . '"' : '' ) , $ transformation -> getArtifact ( ) ) ) ; $ preTransformationEvent = PreTransformationEvent :: createInstance ( $ this ) -> setTransformation ( $ transformation ) ; Dispatcher :: getInstance ( ) -> dispatch ( self :: EVENT_PRE_TRANSFORMATION , $ preTransformationEvent ) ; $ writer = $ this -> writers [ $ transformation -> getWriter ( ) ] ; $ writer -> transform ( $ project , $ transformation ) ; $ postTransformationEvent = PostTransformationEvent :: createInstance ( $ this ) ; Dispatcher :: getInstance ( ) -> dispatch ( self :: EVENT_POST_TRANSFORMATION , $ postTransformationEvent ) ; }
|
Applies the given transformation to the provided project .
|
11,439
|
public function getFilterColumns ( FormView $ formView , int $ numColumns = 3 ) : array { $ columns = [ ] ; $ i = 0 ; foreach ( $ formView as $ formItem ) { $ columns [ $ i % $ numColumns ] [ ] = $ formItem ; ++ $ i ; } return $ columns ; }
|
Simple function to split form widgets in as many columns as wanted
|
11,440
|
public function get ( $ url , $ options = [ ] , $ body = null , $ raw = true ) { return $ this -> httpRequest ( 'GET' , $ this -> createUrl ( $ url , $ options ) , $ body , $ raw ) ; }
|
Performs GET HTTP request
|
11,441
|
public function head ( $ url , $ options = [ ] , $ body = null ) { return $ this -> httpRequest ( 'HEAD' , $ this -> createUrl ( $ url , $ options ) , $ body ) ; }
|
Performs HEAD HTTP request
|
11,442
|
public static function installRequiredFiles ( ) { $ htaccess = [ __DIR__ . '/../../../../../../app/.htaccess' , __DIR__ . '/../../../../../../src/.htaccess' , __DIR__ . '/../../../../../../web/.htaccess' , ] ; $ fileSystem = new Filesystem ( ) ; try { if ( false === $ fileSystem -> exists ( $ htaccess ) ) { $ fileSystem -> copy ( $ htaccess [ 0 ] . '.dist' , $ htaccess [ 0 ] ) ; $ fileSystem -> copy ( $ htaccess [ 1 ] . '.dist' , $ htaccess [ 1 ] ) ; $ fileSystem -> copy ( $ htaccess [ 2 ] . '.dist' , $ htaccess [ 2 ] ) ; } } catch ( \ Exception $ exception ) { echo sprintf ( "Something wrong happens during process: \n%s\n" , $ exception -> getMessage ( ) ) ; } }
|
Static method that creates . htaccess files if they do not exist .
|
11,443
|
public function isUploadField ( $ key ) { return array_key_exists ( $ key , $ this -> uploadGetKeys ) || array_key_exists ( $ key , $ this -> uploadSetKeys ) ; }
|
Determine if a set mutator exists for an attribute .
|
11,444
|
public static function serve ( $ context = null ) { if ( empty ( $ context ) ) $ context = getenv ( 'ERDIKO_CONTEXT' ) ; $ routes = static :: getRoutes ( $ context ) ; Toro :: serve ( $ routes ) ; }
|
Serve your site Loads routes based off of context and serves up the current request
|
11,445
|
public static function getView ( $ viewName , $ data = null , $ templateRootFolder = null ) { $ view = new \ erdiko \ core \ View ( $ viewName , $ data ) ; if ( $ templateRootFolder !== null ) { $ view -> setTemplateRootFolder ( $ templateRootFolder ) ; } return $ view -> toHtml ( ) ; }
|
Load a view from the current theme with the given data
|
11,446
|
public static function getConfigFile ( $ filename ) { $ filename = addslashes ( $ filename ) ; if ( is_file ( $ filename ) ) { $ data = str_replace ( "\\" , "\\\\" , file_get_contents ( $ filename ) ) ; $ json = json_decode ( $ data , true ) ; if ( empty ( $ json ) ) { throw new \ Exception ( "Config file has a json parse error, $filename" ) ; } } else { throw new \ Exception ( "Config file not found, $filename" ) ; } return $ json ; }
|
Read JSON config file and return array
|
11,447
|
public static function getRoutes ( $ context = null ) { if ( $ context == null ) $ context = getenv ( 'ERDIKO_CONTEXT' ) ; $ file = ERDIKO_APP . "/config/{$context}/routes.json" ; $ applicationConfig = static :: getConfigFile ( $ file ) ; return $ applicationConfig [ 'routes' ] ; }
|
Get the compiled application routes from the config files
|
11,448
|
public static function log ( $ level , $ message , array $ context = array ( ) ) { if ( static :: $ _logObject == null ) { $ erdikoContext = getenv ( 'ERDIKO_CONTEXT' ) ; $ config = static :: getConfig ( "application" , $ erdikoContext ) ; $ logFiles = $ config [ "logs" ] [ "files" ] [ 0 ] ; $ logDir = $ config [ "logs" ] [ "path" ] ; static :: $ _logObject = new \ erdiko \ core \ Logger ( $ logFiles , $ logDir ) ; } if ( empty ( $ level ) ) $ level = \ Psr \ Log \ LogLevel :: DEBUG ; return static :: $ _logObject -> log ( $ level , $ message , $ context ) ; }
|
log message to log file If you enter null for level it will default to debug
|
11,449
|
public static function getCache ( $ cacheType = "default" ) { $ context = getenv ( 'ERDIKO_CONTEXT' ) ; $ config = static :: getConfig ( "application" ) ; if ( isset ( $ config [ "cache" ] [ $ cacheType ] ) ) { $ cacheConfig = $ config [ "cache" ] [ $ cacheType ] ; $ class = "erdiko\core\cache\\" . $ cacheConfig [ "type" ] ; return new $ class ; } else { return false ; } }
|
Get the configured cache instance using name
|
11,450
|
public static function initialize ( ) { $ paths = array_merge ( array_filter ( glob ( 'src/*' ) , 'is_dir' ) , array_filter ( glob ( 'src-*/*' ) , 'is_dir' ) , array_filter ( glob ( __DIR__ . '/../../*/src/*/' ) , 'is_dir' ) ) ; $ db_params = array ( "url" => Configuration :: get ( "database.uri" , "sqlite:///:memory:" ) ) ; $ cache = null ; if ( Configuration :: get ( "database.cache" , "false" ) == "false" ) $ cache = new \ Doctrine \ Common \ Cache \ ArrayCache ; $ config = Setup :: createAnnotationMetadataConfiguration ( $ paths , Configuration :: get ( "debug.database" , "false" ) == "true" , "cache" , $ cache ) ; foreach ( Modules :: getAll ( ) as $ module ) $ config -> addEntityNamespace ( $ module -> getShortName ( ) , $ module -> getNamespace ( ) . "\\Models" ) ; self :: $ entity_manager = EntityManager :: create ( $ db_params , $ config ) ; }
|
Initialize the Doctrine database engine .
|
11,451
|
public static function getRepository ( ) { if ( self :: $ entity_manager == null ) self :: initialize ( ) ; return call_user_func_array ( array ( self :: $ entity_manager , "getRepository" ) , func_get_args ( ) ) ; }
|
Wrapper to the Doctrine2 getRepository function .
|
11,452
|
public static function find ( ) { if ( self :: $ entity_manager == null ) self :: initialize ( ) ; return call_user_func_array ( array ( self :: $ entity_manager , "find" ) , func_get_args ( ) ) ; }
|
Wrapper to the Doctrine2 find function .
|
11,453
|
public static function flush ( ) { if ( self :: $ entity_manager == null ) self :: initialize ( ) ; return call_user_func_array ( array ( self :: $ entity_manager , "flush" ) , func_get_args ( ) ) ; }
|
Wrapper to the Doctrine2 flush function .
|
11,454
|
public static function persist ( ) { if ( self :: $ entity_manager == null ) self :: initialize ( ) ; return call_user_func_array ( array ( self :: $ entity_manager , "persist" ) , func_get_args ( ) ) ; }
|
Wrapper to the Doctrine2 persist function .
|
11,455
|
public static function remove ( ) { if ( self :: $ entity_manager == null ) self :: initialize ( ) ; return call_user_func_array ( array ( self :: $ entity_manager , "remove" ) , func_get_args ( ) ) ; }
|
Wrapper to the Doctrine2 remove function .
|
11,456
|
public static function createQuery ( ) { if ( self :: $ entity_manager == null ) self :: initialize ( ) ; return call_user_func_array ( array ( self :: $ entity_manager , "createQuery" ) , func_get_args ( ) ) ; }
|
Wrapper to the Doctrine2 createQuery function .
|
11,457
|
public static function createQueryBuilder ( ) { if ( self :: $ entity_manager == null ) self :: initialize ( ) ; return call_user_func_array ( array ( self :: $ entity_manager , "createQueryBuilder" ) , func_get_args ( ) ) ; }
|
Wrapper to the Doctrine2 createQueryBuilder function .
|
11,458
|
public static function createNativeQuery ( ) { if ( self :: $ entity_manager == null ) self :: initialize ( ) ; return call_user_func_array ( array ( self :: $ entity_manager , "createNativeQuery" ) , func_get_args ( ) ) ; }
|
Wrapper to the Doctrine2 createNativeQuery function .
|
11,459
|
public static function getReference ( ) { if ( self :: $ entity_manager == null ) self :: initialize ( ) ; return call_user_func_array ( array ( self :: $ entity_manager , "getReference" ) , func_get_args ( ) ) ; }
|
Wrapper to the Doctrine2 getReference function .
|
11,460
|
private function _login ( $ id ) { if ( $ this -> check ( ) && $ id ) { $ this -> _authenticate ( $ id ) -> _user_info ( ) -> _init_dir ( true ) -> save_session ( ) ; } return $ this ; }
|
initialize and saves session
|
11,461
|
private function _user_info ( ) { if ( $ this -> get_id ( ) ) { if ( ! empty ( $ this -> get_session ( 'cfg' ) ) ) { $ this -> cfg = $ this -> get_session ( 'cfg' ) ; $ this -> id_group = $ this -> get_session ( 'id_group' ) ; } else if ( $ d = $ this -> db -> rselect ( $ this -> class_cfg [ 'tables' ] [ 'users' ] , array_unique ( array_values ( $ this -> fields ) ) , x :: merge_arrays ( $ this -> class_cfg [ 'conditions' ] , [ $ this -> fields [ 'active' ] => 1 ] , [ $ this -> fields [ 'id' ] => $ this -> id ] ) ) ) { $ r = [ ] ; foreach ( $ d as $ key => $ val ) { $ this -> $ key = $ val ; $ r [ $ key ] = $ key === $ this -> fields [ 'cfg' ] ? json_decode ( $ val , true ) : $ val ; } $ this -> cfg = $ r [ 'cfg' ] ? : [ ] ; $ this -> id_group = $ r [ 'id_group' ] ; $ this -> session -> set ( $ r , self :: $ un ) ; $ this -> save_session ( ) ; } } return $ this ; }
|
Gathers all the information about a user and puts it in the session The user s table data can be sent as argument if it has already been fetched
|
11,462
|
private function _sess_info ( $ id_session = null ) { if ( ! str :: is_uid ( $ id_session ) ) { $ id_session = $ this -> get_id_session ( ) ; } else { $ cfg = $ this -> _get_session ( 'cfg' ) ; } if ( empty ( $ cfg ) && str :: is_uid ( $ id_session ) && ( $ id = $ this -> get_session ( 'id' ) ) && ( $ d = $ this -> db -> rselect ( $ this -> class_cfg [ 'tables' ] [ 'sessions' ] , $ this -> class_cfg [ 'arch' ] [ 'sessions' ] , [ $ this -> class_cfg [ 'arch' ] [ 'sessions' ] [ 'id' ] => $ id_session , $ this -> class_cfg [ 'arch' ] [ 'sessions' ] [ 'id_user' ] => $ id , $ this -> class_cfg [ 'arch' ] [ 'sessions' ] [ 'opened' ] => 1 , ] ) ) ) { $ cfg = json_decode ( $ d [ 'cfg' ] , true ) ; } if ( \ is_array ( $ cfg ) ) { $ this -> sess_cfg = $ cfg ; } else { $ this -> set_error ( 14 ) ; } return $ this ; }
|
Gathers all the information about the user s session The session s table data can be sent as argument if it has already been fetched
|
11,463
|
private function _retrieve_session ( ) { if ( ! $ this -> id ) { $ id_session = $ this -> get_id_session ( ) ; $ id = $ this -> get_session ( 'id' ) ; if ( $ id_session && $ id ) { $ this -> _sess_info ( $ id_session ) ; if ( isset ( $ this -> sess_cfg [ 'fingerprint' ] ) && ( $ this -> get_print ( $ this -> _get_session ( 'fingerprint' ) ) === $ this -> sess_cfg [ 'fingerprint' ] ) ) { $ this -> _authenticate ( $ id ) -> _user_info ( ) -> _init_dir ( ) -> save_session ( ) ; } else { $ this -> set_error ( 19 ) ; } } else { } } return $ this ; }
|
Retrieves all user info from its session and populates the object
|
11,464
|
private function _init_session ( ) { $ this -> session = user \ session :: get_instance ( ) ; if ( ! $ this -> session ) { $ this -> session = new user \ session ( ) ; } if ( $ id_session = $ this -> get_id_session ( ) ) { $ this -> sess_cfg = json_decode ( $ this -> db -> select_one ( $ this -> class_cfg [ 'tables' ] [ 'sessions' ] , $ this -> class_cfg [ 'arch' ] [ 'sessions' ] [ 'cfg' ] , [ $ this -> class_cfg [ 'arch' ] [ 'sessions' ] [ 'id' ] => $ id_session ] ) , true ) ; } else { $ salt = self :: make_fingerprint ( ) ; $ fingerprint = self :: make_fingerprint ( ) ; $ p = & $ this -> class_cfg [ 'arch' ] [ 'sessions' ] ; $ this -> sess_cfg = [ 'fingerprint' => $ this -> get_print ( $ fingerprint ) , 'last_renew' => time ( ) ] ; if ( $ this -> db -> insert ( $ this -> class_cfg [ 'tables' ] [ 'sessions' ] , [ $ p [ 'sess_id' ] => $ this -> session -> get_id ( ) , $ p [ 'ip_address' ] => $ this -> ip_address , $ p [ 'user_agent' ] => $ this -> user_agent , $ p [ 'opened' ] => 1 , $ p [ 'last_activity' ] => date ( 'Y-m-d H:i:s' ) , $ p [ 'creation' ] => date ( 'Y-m-d H:i:s' ) , $ p [ 'cfg' ] => json_encode ( $ this -> sess_cfg ) ] ) ) { $ id_session = $ this -> db -> last_id ( ) ; $ this -> session -> set ( [ 'fingerprint' => $ fingerprint , 'tokens' => [ ] , 'id_session' => $ id_session , 'salt' => $ salt ] , self :: $ sn ) ; $ this -> save_session ( ) ; } else { $ this -> set_error ( 16 ) ; } } return $ this ; }
|
Sets the user s session for the first time and creates the session s DB row
|
11,465
|
private function _set_session ( $ attr ) { if ( $ this -> session -> has ( self :: $ sn ) ) { $ args = \ func_get_args ( ) ; if ( ( \ count ( $ args ) === 2 ) && \ is_string ( $ args [ 0 ] ) ) { $ attr = [ $ args [ 0 ] => $ args [ 1 ] ] ; } foreach ( $ attr as $ key => $ val ) { if ( \ is_string ( $ key ) ) { $ this -> session -> set ( $ val , self :: $ sn , $ key ) ; } } } return $ this ; }
|
Sets the session part of the session
|
11,466
|
private function _get_session ( $ attr ) { if ( $ this -> session -> has ( self :: $ sn ) ) { return $ attr ? $ this -> session -> get ( self :: $ sn , $ attr ) : $ this -> session -> get ( self :: $ sn ) ; } }
|
Gets the session part of the session
|
11,467
|
private function _check_credentials ( $ params ) { if ( $ this -> check ( ) ) { $ f = & $ this -> class_cfg [ 'fields' ] ; if ( ! isset ( $ params [ $ f [ 'salt' ] ] ) ) { $ this -> set_error ( 11 ) ; } else { if ( ! $ this -> check_salt ( $ params [ $ f [ 'salt' ] ] ) ) { $ this -> set_error ( 17 ) ; } } if ( $ this -> check ( ) ) { if ( isset ( $ params [ $ f [ 'user' ] ] , $ params [ $ f [ 'pass' ] ] ) ) { $ arch = & $ this -> class_cfg [ 'arch' ] ; $ this -> just_login = 1 ; if ( $ id = $ this -> db -> select_one ( $ this -> class_cfg [ 'tables' ] [ 'users' ] , $ this -> fields [ 'id' ] , x :: merge_arrays ( $ this -> class_cfg [ 'conditions' ] , [ $ arch [ 'users' ] [ 'active' ] => 1 ] , [ ( $ arch [ 'users' ] [ 'login' ] ?? $ arch [ 'users' ] [ 'email' ] ) => $ params [ $ f [ 'user' ] ] ] ) ) ) { $ pass = $ this -> db -> select_one ( $ this -> class_cfg [ 'tables' ] [ 'passwords' ] , $ arch [ 'passwords' ] [ 'pass' ] , [ $ arch [ 'passwords' ] [ 'id_user' ] => $ id ] , [ $ arch [ 'passwords' ] [ 'added' ] => 'DESC' ] ) ; if ( $ this -> _check_password ( $ params [ $ f [ 'pass' ] ] , $ pass ) ) { $ this -> _login ( $ id ) ; } else { $ this -> record_attempt ( ) ; $ this -> set_error ( $ this -> check_attempts ( ) ? 6 : 4 ) ; } } else { $ this -> set_error ( 6 ) ; } } else { $ this -> set_error ( 12 ) ; } } } else { die ( var_dump ( $ this -> get_error ( ) ) ) ; } return $ this -> auth ; }
|
Checks the credentials of a user
|
11,468
|
private function _init_dir ( $ create = false ) { if ( \ defined ( 'BBN_DATA_PATH' ) && $ this -> get_id ( ) ) { $ this -> path = BBN_DATA_PATH . 'users/' . $ this -> get_id ( ) . '/' ; if ( ! \ defined ( 'BBN_USER_PATH' ) ) { define ( 'BBN_USER_PATH' , $ this -> path ) ; } if ( $ create ) { file \ dir :: create_path ( BBN_USER_PATH . 'tmp' ) ; file \ dir :: delete ( BBN_USER_PATH . 'tmp' , false ) ; } } return $ this ; }
|
If BBN_DATA_PATH is defined creates a directory and removes temp files
|
11,469
|
public function get_error ( ) { if ( $ this -> error ) { return [ 'code' => $ this -> error , 'text' => $ this -> class_cfg [ 'errors' ] [ $ this -> error ] ] ; } return false ; }
|
Returns the last known error and false if there was no error
|
11,470
|
protected function get_print ( string $ fp = null ) { if ( ! $ fp ) { $ fp = $ this -> _get_session ( 'fingerprint' ) ; } if ( $ fp ) { return sha1 ( $ this -> user_agent . $ this -> accept_lang . $ fp ) ; } return false ; }
|
Returns a print ie an identifier based on the user agent
|
11,471
|
protected function record_attempt ( ) { $ this -> cfg [ 'num_attempts' ] = isset ( $ this -> cfg [ 'num_attempts' ] ) ? $ this -> cfg [ 'num_attempts' ] + 1 : 1 ; $ this -> _set_session ( 'num_attempts' , $ this -> cfg [ 'num_attempts' ] ) ; $ this -> save_session ( ) ; return $ this ; }
|
Increment the num_attempt variable
|
11,472
|
public function get_cfg ( $ attr = '' ) { if ( $ this -> check ( ) ) { if ( ! $ this -> cfg ) { $ this -> cfg = $ this -> session -> get ( 'cfg' ) ; } if ( empty ( $ attr ) ) { return $ this -> cfg ; } if ( isset ( $ this -> cfg [ $ attr ] ) ) { return $ this -> cfg [ $ attr ] ; } return false ; } }
|
Returns the current user s configuration .
|
11,473
|
public function get_fields ( string $ table = '' ) : ? array { if ( ! empty ( $ this -> class_cfg ) ) { if ( $ table ) { return $ this -> class_cfg [ 'arch' ] [ $ table ] ?? null ; } return $ this -> class_cfg [ 'arch' ] ; } return null ; }
|
Returns the list of fields of the given table and if empty the list of fields for each table .
|
11,474
|
public function update_info ( array $ d ) { if ( $ this -> check_session ( ) ) { $ update = [ ] ; foreach ( $ d as $ key => $ val ) { if ( ( $ key !== $ this -> fields [ 'id' ] ) && ( $ key !== $ this -> fields [ 'cfg' ] ) && ( $ key !== 'auth' ) && ( $ key !== 'pass' ) && \ in_array ( $ key , $ this -> fields ) ) { $ update [ $ key ] = $ val ; } } if ( \ count ( $ update ) > 0 ) { $ r = $ this -> db -> update ( $ this -> class_cfg [ 'tables' ] [ 'users' ] , $ update , [ $ this -> fields [ 'id' ] => $ this -> id ] ) ; $ this -> set_session ( [ 'cfg' => false ] ) ; $ this -> _user_info ( ) ; return $ r ; } } return false ; }
|
Changes the data in the user s table .
|
11,475
|
public function get_session ( $ attr = null ) { if ( $ this -> session -> has ( self :: $ un ) ) { return $ attr ? $ this -> session -> get ( self :: $ un , $ attr ) : $ this -> session -> get ( self :: $ un ) ; } }
|
Returns session property from the session s user array .
|
11,476
|
public function save_session ( ) : self { $ id_session = $ this -> get_id_session ( ) ; if ( $ id_session && $ this -> check ( ) ) { $ p = & $ this -> class_cfg [ 'arch' ] [ 'sessions' ] ; $ this -> db -> update ( $ this -> class_cfg [ 'tables' ] [ 'sessions' ] , [ $ p [ 'id_user' ] => $ this -> id , $ p [ 'sess_id' ] => $ this -> session -> get_id ( ) , $ p [ 'ip_address' ] => $ this -> ip_address , $ p [ 'user_agent' ] => $ this -> user_agent , $ p [ 'opened' ] => 1 , $ p [ 'last_activity' ] => date ( 'Y-m-d H:i:s' ) , $ p [ 'cfg' ] => json_encode ( $ this -> sess_cfg ) ] , [ $ p [ 'id' ] => $ id_session ] ) ; } else { $ this -> set_error ( 13 ) ; } return $ this ; }
|
Saves the session config in the database .
|
11,477
|
public function check_attempts ( ) : bool { if ( ! isset ( $ this -> cfg ) ) { return false ; } if ( isset ( $ this -> cfg [ 'num_attempts' ] ) && $ this -> cfg [ 'num_attempts' ] > $ this -> class_cfg [ 'max_attempts' ] ) { return false ; } return true ; }
|
Returns false if the max number of connections attempts has been reached
|
11,478
|
public function save_cfg ( ) { if ( $ this -> check ( ) ) { $ this -> db -> update ( $ this -> class_cfg [ 'tables' ] [ 'users' ] , [ $ this -> fields [ 'cfg' ] => json_encode ( $ this -> cfg ) ] , [ $ this -> fields [ 'id' ] => $ this -> id ] ) ; } return $ this ; }
|
Saves the user s config in the cfg field of the users table return connection
|
11,479
|
public function set_password ( $ old_pass , $ new_pass ) { if ( $ this -> auth ) { $ pwt = $ this -> class_cfg [ 'tables' ] [ 'passwords' ] ; $ pwa = $ this -> class_cfg [ 'arch' ] [ 'passwords' ] ; $ stored_pass = $ this -> db -> select_one ( $ pwt , $ pwa [ 'pass' ] , [ $ this -> class_cfg [ 'arch' ] [ 'passwords' ] [ 'id_user' ] => $ this -> id ] , [ $ this -> class_cfg [ 'arch' ] [ 'passwords' ] [ 'added' ] => 'DESC' ] ) ; if ( $ this -> _check_password ( $ old_pass , $ stored_pass ) ) { return $ this -> force_password ( $ new_pass , $ this -> get_id ( ) ) ; } } return false ; }
|
Change the password in the database after checking the current one
|
11,480
|
public function force_password ( $ pass , $ id ) { if ( $ this -> check ( ) ) { return $ this -> db -> insert ( $ this -> class_cfg [ 'tables' ] [ 'passwords' ] , [ $ this -> class_cfg [ 'arch' ] [ 'passwords' ] [ 'pass' ] => $ this -> _crypt ( $ pass ) , $ this -> class_cfg [ 'arch' ] [ 'passwords' ] [ 'id_user' ] => $ id , $ this -> class_cfg [ 'arch' ] [ 'passwords' ] [ 'added' ] => date ( 'Y-m-d H:i:s' ) ] ) ; } return false ; }
|
Change the password in the database
|
11,481
|
public function get_name ( $ usr = null ) { if ( $ this -> auth ) { if ( \ is_null ( $ usr ) ) { $ usr = $ this -> get_session ( ) ; } else if ( str :: is_uid ( $ usr ) ) { $ mgr = $ this -> get_manager ( ) ; $ usr = $ mgr -> get_user ( $ usr ) ; } if ( isset ( $ usr [ $ this -> class_cfg [ 'show' ] ] ) ) { return $ usr [ $ this -> class_cfg [ 'show' ] ] ; } } return false ; }
|
Returns the written name of this or a user
|
11,482
|
public static function get_active_metaplates ( ) { global $ post ; if ( empty ( $ post ) ) { return ; } $ metaplates = self :: get_registry ( ) ; $ meta_stack = array ( ) ; if ( is_array ( $ metaplates ) ) { foreach ( $ metaplates as $ metaplate_try ) { $ is_plate = self :: get_metaplate ( $ metaplate_try [ 'id' ] ) ; if ( ! empty ( $ is_plate [ 'post_type' ] [ $ post -> post_type ] ) ) { switch ( $ is_plate [ 'page_type' ] ) { case 'single' : if ( is_single ( ) || is_page ( ) ) { $ meta_stack [ ] = $ is_plate ; } break ; case 'archive' : if ( ( is_archive ( ) || is_front_page ( ) ) && ( ! is_page ( ) || ! is_single ( ) ) ) { $ meta_stack [ ] = $ is_plate ; } break ; default : $ meta_stack [ ] = $ is_plate ; break ; } } } } return $ meta_stack ; }
|
Get the metaplates for the post
|
11,483
|
public static function get_custom_field_data ( $ post_id ) { global $ post ; if ( ! is_object ( $ post ) ) { $ post = get_post ( $ post_id ) ; } $ raw_data = get_post_meta ( $ post_id ) ; if ( ! is_array ( $ raw_data ) ) { return ; } $ template_data = array ( ) ; $ taxonomies = get_object_taxonomies ( $ post ) ; if ( ! empty ( $ taxonomies ) ) { foreach ( $ taxonomies as $ taxonomy_name ) { $ taxonomy = get_taxonomy ( $ taxonomy_name ) ; $ template_data [ 'taxonomy' ] [ $ taxonomy_name ] = $ template_data [ $ taxonomy_name ] = wp_get_post_terms ( $ post -> ID , $ taxonomy_name , array ( "fields" => "all" ) ) ; } } foreach ( $ raw_data as $ meta_key => $ meta_data ) { if ( count ( $ meta_data ) === 1 ) { if ( strlen ( trim ( $ meta_data [ 0 ] ) ) > 0 ) { $ template_data [ $ meta_key ] = trim ( $ meta_data [ 0 ] ) ; } } else { $ template_data [ $ meta_key ] = $ meta_data ; } } if ( class_exists ( 'acf' ) ) { $ fields = get_fields ( $ post -> ID ) ; if ( is_array ( $ fields ) && ! empty ( $ fields ) ) { $ template_data = array_merge ( $ template_data , $ fields ) ; } } if ( class_exists ( 'Custom_Field_Suite' ) ) { $ fields = CFS ( ) -> get ( ) ; if ( is_array ( $ fields ) && ! empty ( $ fields ) ) { $ template_data = array_merge ( $ template_data , $ fields ) ; } } if ( class_exists ( 'Pods' ) && false != ( $ pods = pods ( $ post -> post_type , $ post -> ID , true ) ) ) { $ fields = $ pods -> export ( ) ; if ( is_array ( $ fields ) && ! empty ( $ fields ) ) { $ template_data = array_merge ( $ template_data , $ fields ) ; } } if ( ! empty ( $ post ) ) { foreach ( $ post as $ post_key => $ post_value ) { $ template_data [ $ post_key ] = $ post_value ; } $ template_data [ 'post_author' ] = get_userdata ( $ template_data [ 'post_author' ] ) ; $ template_data [ 'permalink' ] = get_permalink ( $ post -> ID ) ; $ template_data [ 'post_format' ] = get_post_format ( $ post ) ; } return $ template_data ; }
|
Merge in Custom field data meta and post data
|
11,484
|
public static function get_metaplate ( $ id ) { $ metaplates = self :: get_registry ( ) ; if ( array_key_exists ( $ id , $ metaplates ) ) { $ metaplate = get_option ( $ id ) ; } else { $ metaplate = self :: get_metaplate_id_by_slug ( $ id ) ; if ( is_string ( $ metaplate ) ) { $ metaplate = self :: get_metaplate ( $ metaplate ) ; } } if ( is_string ( $ metaplate ) ) { $ metaplate = json_decode ( $ metaplate , ARRAY_A ) ; } if ( is_object ( $ metaplate ) ) { $ metaplate = ( array ) $ metaplate ; } $ metaplate = self :: code ( $ metaplate ) ; return ( array ) $ metaplate ; }
|
Get a metaplate by ID or slug
|
11,485
|
private static function code ( $ metaplate ) { foreach ( array ( 'html' , 'js' , 'css' ) as $ field ) { if ( isset ( $ metaplate [ $ field ] ) ) { if ( is_object ( $ metaplate [ $ field ] ) ) { $ value = $ metaplate [ $ field ] ; $ value = $ value -> code ; unset ( $ metaplate [ $ field ] ) ; $ metaplate [ $ field ] [ 'code' ] = $ value ; } } else { $ metaplate [ $ field ] [ 'code' ] = 1 ; } } return $ metaplate ; }
|
Make sure the code fields are arrays not objects and are set
|
11,486
|
public static function get_metaplate_id_by_slug ( $ slug , $ metaplates = null ) { if ( is_null ( $ metaplates ) ) { $ metaplates = self :: get_registry ( ) ; } if ( is_array ( $ metaplates ) ) { $ search = wp_list_pluck ( $ metaplates , 'slug' ) ; return array_search ( $ slug , $ search ) ; } return false ; }
|
Get a metaplate s ID using its slug
|
11,487
|
public static function update_registry ( $ new_value , $ id ) { $ registry = self :: get_registry ( ) ; $ registry [ $ id ] = $ new_value ; return update_option ( self :: $ registry_option_name , $ registry ) ; }
|
Update registry of metaplates
|
11,488
|
public function whatProvides ( $ name , LinkConstraintInterface $ constraint = null , $ mustMatchName = false ) { $ key = ( ( int ) $ mustMatchName ) . $ constraint ; if ( isset ( $ this -> providerCache [ $ name ] [ $ key ] ) ) { return $ this -> providerCache [ $ name ] [ $ key ] ; } return $ this -> providerCache [ $ name ] [ $ key ] = $ this -> computeWhatProvides ( $ name , $ constraint , $ mustMatchName ) ; }
|
Searches all packages providing the given package name and match the constraint
|
11,489
|
private function match ( $ candidate , $ name , LinkConstraintInterface $ constraint = null ) { $ candidateName = $ candidate -> getName ( ) ; $ candidateVersion = $ candidate -> getVersion ( ) ; $ isDev = $ candidate -> getStability ( ) === 'dev' ; $ isAlias = $ candidate instanceof AliasPackage ; if ( ! $ isDev && ! $ isAlias && isset ( $ this -> filterRequires [ $ name ] ) ) { $ requireFilter = $ this -> filterRequires [ $ name ] ; } else { $ requireFilter = new EmptyConstraint ; } if ( $ candidateName === $ name ) { $ pkgConstraint = new VersionConstraint ( '==' , $ candidateVersion ) ; if ( $ constraint === null || $ constraint -> matches ( $ pkgConstraint ) ) { return $ requireFilter -> matches ( $ pkgConstraint ) ? self :: MATCH : self :: MATCH_FILTERED ; } return self :: MATCH_NAME ; } $ provides = $ candidate -> getProvides ( ) ; $ replaces = $ candidate -> getReplaces ( ) ; if ( isset ( $ replaces [ 0 ] ) || isset ( $ provides [ 0 ] ) ) { foreach ( $ provides as $ link ) { if ( $ link -> getTarget ( ) === $ name && ( $ constraint === null || $ constraint -> matches ( $ link -> getConstraint ( ) ) ) ) { return $ requireFilter -> matches ( $ link -> getConstraint ( ) ) ? self :: MATCH_PROVIDE : self :: MATCH_FILTERED ; } } foreach ( $ replaces as $ link ) { if ( $ link -> getTarget ( ) === $ name && ( $ constraint === null || $ constraint -> matches ( $ link -> getConstraint ( ) ) ) ) { return $ requireFilter -> matches ( $ link -> getConstraint ( ) ) ? self :: MATCH_REPLACE : self :: MATCH_FILTERED ; } } return self :: MATCH_NONE ; } if ( isset ( $ provides [ $ name ] ) && ( $ constraint === null || $ constraint -> matches ( $ provides [ $ name ] -> getConstraint ( ) ) ) ) { return $ requireFilter -> matches ( $ provides [ $ name ] -> getConstraint ( ) ) ? self :: MATCH_PROVIDE : self :: MATCH_FILTERED ; } if ( isset ( $ replaces [ $ name ] ) && ( $ constraint === null || $ constraint -> matches ( $ replaces [ $ name ] -> getConstraint ( ) ) ) ) { return $ requireFilter -> matches ( $ replaces [ $ name ] -> getConstraint ( ) ) ? self :: MATCH_REPLACE : self :: MATCH_FILTERED ; } return self :: MATCH_NONE ; }
|
Checks if the package matches the given constraint directly or through provided or replaced packages
|
11,490
|
public static function fromNode ( $ node , $ parent ) { if ( is_null ( $ node [ "value" ] ) ) return new Feature ( $ node , $ parent , $ node -> children ( ) ) ; else return new ValueFeature ( $ node , $ parent , $ node -> children ( ) ) ; }
|
Creates a feature from an XML node .
|
11,491
|
public static function findByName ( $ features , $ featureName , $ permissive = false ) { if ( $ permissive ) $ featureName = self :: _getPermissiveName ( $ featureName ) ; return fphp \ Helper \ _Array :: findByKey ( $ features , $ permissive ? "getPermissiveName" : "getName" , $ featureName ) ; }
|
Finds a feature by its name in a list of features . Permissive search ignores case and substitutes hyphens .
|
11,492
|
public static function GetItemInfo ( $ itemname , $ itemchunks ) { $ retval = "-" ; for ( $ i = 0 ; $ i < count ( $ itemchunks ) ; $ i ++ ) if ( strcasecmp ( $ itemchunks [ $ i ] , $ itemname ) == 0 ) $ retval = $ itemchunks [ $ i + 1 ] ; return $ retval ; }
|
A Helper Function . Returns Item Info from chunk .
|
11,493
|
public static function FontCodes ( $ text , $ advanced = TRUE , $ charset = 'utf-8' ) { $ text = htmlspecialchars ( $ text , ENT_QUOTES , $ charset ) ; $ basic_bbcode = array ( '[b]' , '[/b]' , '[i]' , '[/i]' , '[u]' , '[/u]' , '[B]' , '[/B]' , '[I]' , '[/I]' , '[U]' , '[/U]' , ) ; $ basic_html = array ( '<b>' , '</b>' , '<i>' , '</i>' , '<u>' , '</u>' , '<b>' , '</b>' , '<i>' , '</i>' , '<u>' , '</u>' , ) ; $ text = str_replace ( $ basic_bbcode , $ basic_html , $ text ) ; if ( $ advanced ) { $ advanced_bbcode = array ( '/\[c=([0-9a-fA-F]{6})\](.+)(\[\\c\])?/i' , ) ; $ advanced_html = array ( "<span style='color: #$1'>$2</span>" , ) ; $ text = htmlspecialchars ( preg_replace ( $ advanced_bbcode , $ advanced_html , $ text ) ) ; } return $ text ; }
|
Helper Function Convery SWAT4 Server font codes into html tags
|
11,494
|
public static function FixNickname ( $ nick ) { $ nick = str_replace ( '&' , '&' , $ nick ) ; $ nick = str_replace ( '<' , '<' , $ nick ) ; $ nick = str_replace ( '>' , '>' , $ nick ) ; return $ nick ; }
|
Helper Function Returns fixed names for html .
|
11,495
|
public static function SortPlayers ( $ a , $ b , $ co , $ jak ) { if ( $ co == "name" ) { $ a2 = strtolower ( $ a [ 'name' ] ) ; $ b2 = strtolower ( $ b [ 'name' ] ) ; if ( $ a2 == $ b2 ) return 0 ; if ( ( ( $ jak == "+" ) && ( $ a2 > $ b2 ) ) || ( ( $ jak == "-" ) && ( $ a2 < $ b2 ) ) ) return 1 ; else return - 1 ; } else { if ( $ a [ $ co ] == $ b [ $ co ] ) return 0 ; if ( ( ( $ jak == "+" ) && ( $ a [ $ co ] > $ b [ $ co ] ) ) || ( ( $ jak == "-" ) && ( $ a [ $ co ] < $ b [ $ co ] ) ) ) return 1 ; else return - 1 ; } }
|
A Helper Function This function will sort players .
|
11,496
|
function LinkImageSort ( $ _by , $ sby , $ soby , $ soby2 , $ stitle ) { if ( $ _by == $ sby ) return <<<EOF <a href="{$_SERVER['PHP_SELF']}?sort={$soby}&by={$sby}" class="formfont" onmouseover="if(document.getElementById('so{$sby}')){ document.getElementById('so{$sby}').src='./swat4query/images/server_{$soby}.gif'; }" onmouseout="if(document.getElementById('so{$sby}')){ document.getElementById('so{$sby}').src='./swat4query/images/server_{$soby2}.gif'; }"><b>{$stitle}</b> <img src="./swat4query/images/server_{$soby2}.gif" width="11" height="9" border="0" alt="{$soby}" id="so{$sby}" />EOF ; else return '<a href="' . $ _SERVER [ 'PHP_SELF' ] . '?sort=' . $ soby . '&by=' . $ sby . '" class="formfont"><b>' . $ stitle . '</b>' ; }
|
Helper Function Can be used to created a link to sort data accordingly .
|
11,497
|
public function render ( $ delimiter = null , $ no_additions = false ) { $ delimiter = is_null ( $ delimiter ) ? config ( 'laravel-title.delimiter' ) : $ delimiter ; $ suffix = $ no_additions ? '' : config ( 'laravel-title.suffix' ) ; $ prefix = $ no_additions ? '' : config ( 'laravel-title.prefix' ) ; $ on_empty = $ no_additions ? '' : config ( 'laravel-title.on_empty' ) ; return $ this -> make ( $ this -> segments , $ delimiter , $ suffix , $ prefix , $ on_empty ) ; }
|
Implode all segments into one string .
|
11,498
|
public function make ( array $ segments , $ delimiter = ' - ' , $ suffix = '' , $ prefix = '' , $ on_empty = '' ) { $ result = implode ( $ delimiter , $ segments ) ; if ( $ this -> has ( ) ) { return $ prefix . $ result . $ suffix ; } else { return $ on_empty ; } }
|
Check if any segments added
|
11,499
|
public static function recursiveRemove ( $ path ) { if ( is_dir ( $ path ) ) { $ files = scandir ( $ path ) ; foreach ( $ files as $ file ) { if ( $ file != "." && $ file != ".." ) { self :: recursiveRemove ( "$path/$file" ) ; } } if ( ! rmdir ( $ path ) ) { throw new IOException ( "Cannot rmdir '$path'" , 0 , null , $ path ) ; } } elseif ( file_exists ( $ path ) ) { if ( ! unlink ( $ path ) ) { throw new IOException ( "Cannot unlink '$path'" , 0 , null , $ path ) ; } } }
|
rm - r path
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.