idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
3,000
protected function get_src_path ( $ path = '' ) { return rtrim ( $ this -> get_path ( $ this -> options -> src_dir ) , '/' ) . ( strlen ( $ path ) ? '/' . $ path : '' ) ; }
Get full src path to the path .
3,001
protected function load_textdomain ( ) { $ domain = $ this -> options -> domain ; if ( empty ( $ domain ) ) { return ; } $ path = $ this -> options -> lang_path ; if ( empty ( $ path ) ) { $ path = $ this -> get_path ( $ this -> options -> lang_dir ) ; } $ path = sprintf ( '%s/%s-%s.mo' , rtrim ( $ path , '/' ) , $ domain , get_locale ( ) ) ; load_textdomain ( $ domain , $ path ) ; }
Load textdomain .
3,002
public static function make ( $ base_path ) { $ name = plugin_basename ( $ base_path ) ; if ( ! isset ( self :: $ instances [ $ name ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Identifier `%s` is not defined' , $ name ) ) ; } return self :: $ instances [ $ name ] ; }
Get the instance from base path .
3,003
protected function register_autoload ( ) { $ src_dir = $ this -> get_src_path ( ) ; if ( file_exists ( $ src_dir ) ) { register_wp_autoload ( $ this -> options -> namespace , $ src_dir ) ; } }
Register autoload .
3,004
protected function set_base_path ( $ base_path ) { if ( ! is_string ( $ base_path ) ) { throw new InvalidArgumentException ( 'Invalid argument. `$base_path` must be string.' ) ; } if ( strpos ( $ base_path , '.php' ) !== false ) { $ base_path = preg_replace ( '/[^\/]*$/' , '' , $ base_path ) ; } $ this -> base_path = rtrim ( $ base_path , '/' ) ; }
Set base path . Remove file name if it exists .
3,005
protected function set_namespace ( ) { if ( empty ( $ this -> options -> instance ) || ! empty ( $ this -> options -> namespace ) ) { return ; } $ namespace = $ this -> options -> namespace ; $ namespace = explode ( '\\' , $ namespace ) ; array_pop ( $ namespace ) ; $ this -> options -> namespace = implode ( '\\' , $ namespace ) ; }
Set namespace if instance exists and namespace is empty .
3,006
public function editAction ( ) { $ this -> view -> disable ( ) ; $ id = $ this -> request -> getPost ( "hidden_id" ) ; $ banner = Banner :: findFirst ( $ id ) ; $ msg = "" ; if ( $ this -> request -> hasFiles ( ) !== false ) { if ( ! empty ( $ _FILE [ 'file' ] [ 'tmp_name' ] ) ) { if ( ! empty ( $ banner -> file ) ) { unlink ( "upload/banner/" . $ banner -> file ) ; } } $ uploader = new \ Uploader \ Uploader ( [ 'directory' => "upload/banner/" , 'mimes' => [ 'image/gif' , 'image/jpeg' , 'image/png' , ] , 'extensions' => [ 'gif' , 'jpeg' , 'jpg' , 'png' , ] , 'sanitize' => true , 'hash' => 'md5' ] ) ; if ( $ uploader -> isValid ( ) === true ) { $ uploader -> move ( ) ; $ file = $ uploader -> getInfo ( ) ; $ alert = "sukses" ; $ msg .= $ file [ 0 ] [ 'filename' ] ; $ _file = $ file [ 0 ] [ 'filename' ] ; } else { $ alert = "error" ; $ msg .= $ uploader -> getErrors ( ) ; $ _file = "" ; } } if ( isset ( $ _file ) ) { $ banner -> file = $ _file ; } $ banner -> order = $ this -> request -> getPost ( "order" ) ; $ banner -> publish = $ this -> request -> getPost ( "publish" ) ; $ banner -> description = $ this -> request -> getPost ( "description" ) ; $ banner -> description1 = $ this -> request -> getPost ( "description1" ) ; $ banner -> link = $ this -> request -> getPost ( "link" ) ; $ banner -> update_user = $ this -> auth -> getIdentity ( ) [ 'id' ] ; if ( ! $ banner -> save ( ) ) { $ alert = "error" ; foreach ( $ banner -> getMessages ( ) as $ message ) { $ msg .= $ message . " " ; } } else { $ alert = "sukses" ; $ msg .= "Banner was edit successfully" ; } $ response = new \ Phalcon \ Http \ Response ( ) ; $ response -> setContentType ( 'application/json' , 'UTF-8' ) ; $ response -> setJsonContent ( array ( '_id' => $ id , 'alert' => $ alert , 'msg' => $ msg ) ) ; return $ response -> send ( ) ; }
Edits a banner
3,007
public function createAction ( ) { $ this -> view -> disable ( ) ; $ msg = "" ; if ( ! is_dir ( "upload/banner/" ) ) { if ( ! mkdir ( $ this -> path , 0777 , true ) ) { die ( 'Failed to create folders...' ) ; } } if ( $ this -> request -> hasFiles ( ) !== false ) { $ uploader = new \ Uploader \ Uploader ( [ 'directory' => "upload/banner/" , 'mimes' => [ 'image/gif' , 'image/jpeg' , 'image/png' , ] , 'extensions' => [ 'gif' , 'jpeg' , 'jpg' , 'png' , ] , 'sanitize' => true , 'hash' => 'md5' ] ) ; if ( $ uploader -> isValid ( ) === true ) { $ uploader -> move ( ) ; $ file = $ uploader -> getInfo ( ) ; $ alert = "sukses" ; $ msg .= $ file [ 0 ] [ 'filename' ] . " " ; $ _file = $ file [ 0 ] [ 'filename' ] ; } else { $ alert = "error" ; $ msg .= $ uploader -> getErrors ( ) [ 0 ] ; $ _file = " " ; } } $ banner = new Banner ( ) ; $ banner -> order = $ this -> request -> getPost ( "order" ) ; $ banner -> publish = $ this -> request -> getPost ( "publish" ) ; $ banner -> description = $ this -> request -> getPost ( "description" ) ; $ banner -> description1 = $ this -> request -> getPost ( "description1" ) ; $ banner -> link = $ this -> request -> getPost ( "link" ) ; $ banner -> file = $ _file ; $ banner -> create_user = $ this -> auth -> getIdentity ( ) [ 'id' ] ; if ( ! $ banner -> save ( ) ) { $ alert = "error" ; foreach ( $ banner -> getMessages ( ) as $ message ) { $ msg .= $ message . " " ; } } else { $ alert = "sukses" ; $ msg .= "Banner was created successfully" ; } $ response = new \ Phalcon \ Http \ Response ( ) ; $ response -> setContentType ( 'application/json' , 'UTF-8' ) ; $ response -> setJsonContent ( array ( '_id' => $ _file , 'alert' => $ alert , 'msg' => $ msg ) ) ; return $ response -> send ( ) ; }
Creates a new banner
3,008
public function deleteAction ( $ id ) { $ this -> view -> disable ( ) ; $ banner = Banner :: findFirstByid ( $ id ) ; if ( ! $ banner ) { $ alert = "error" ; $ msg = "banner not Found" ; } if ( ! empty ( $ banner -> file ) ) { if ( file_exists ( $ this -> path . $ banner -> file ) ) { unlink ( $ this -> path . $ banner -> file ) ; } } if ( ! $ banner -> delete ( ) ) { $ alert = "error" ; $ msg = " " ; foreach ( $ banner -> getMessages ( ) as $ message ) { $ msg .= $ message . " " ; } } else { $ alert = "sukses" ; $ msg = "banner was deleted " ; } $ response = new \ Phalcon \ Http \ Response ( ) ; $ response -> setContentType ( 'application/json' , 'UTF-8' ) ; $ response -> setJsonContent ( array ( '_id' => $ id , 'alert' => $ alert , 'msg' => $ msg ) ) ; return $ response -> send ( ) ; }
Deletes a banner
3,009
public static function exists ( string $ link = '' ) : bool { $ link = static :: normalizePath ( $ link ) ; return static :: verifyPath ( $ link ) && \ file_exists ( $ link ) && \ is_link ( $ link ) ; }
Checks whether link exists .
3,010
public static function create ( string $ link = '' , string $ target = '' ) : bool { $ ret = true ; $ link = static :: normalizePath ( $ link ) ; $ target = static :: normalizePath ( $ target ) ; if ( static :: verifyPath ( $ link ) && static :: verifyPath ( $ target ) && Directory :: create ( \ dirname ( $ link ) ) && ! \ file_exists ( $ link ) && \ file_exists ( $ target ) ) { $ ret = @ \ symlink ( $ target , $ link ) ; @ \ chmod ( $ link , static :: $ newSymlinkMode ) ; } return $ ret ; }
Creates a symbolic link .
3,011
public static function read ( string $ link = '' ) : string { $ link = static :: normalizePath ( $ link ) ; if ( static :: exists ( $ link ) ) { return @ \ readlink ( $ link ) ; } return '' ; }
Returns a target of specified symbolic link
3,012
public static function remove ( string $ link = '' ) : bool { $ link = static :: normalizePath ( $ link ) ; if ( static :: exists ( $ link ) ) { return @ \ unlink ( $ link ) ; } return false ; }
Removes a symbolic link
3,013
public static function getInstance ( \ FreeFW \ Application \ Config $ p_config , \ Psr \ Log \ LoggerInterface $ p_logger ) { if ( self :: $ instance === null ) { self :: $ instance = new static ( $ p_config , $ p_logger ) ; } return self :: $ instance ; }
Get Application instance
3,014
protected function send ( \ Psr \ Http \ Message \ ResponseInterface $ p_response ) { $ http_line = sprintf ( 'HTTP/%s %s %s' , $ p_response -> getProtocolVersion ( ) , $ p_response -> getStatusCode ( ) , $ p_response -> getReasonPhrase ( ) ) ; header ( $ http_line , true , $ p_response -> getStatusCode ( ) ) ; foreach ( $ p_response -> getHeaders ( ) as $ name => $ values ) { foreach ( $ values as $ value ) { header ( "$name: $value" , false ) ; } } $ stream = $ p_response -> getBody ( ) ; if ( $ stream -> isSeekable ( ) ) { $ stream -> rewind ( ) ; } while ( ! $ stream -> eof ( ) ) { echo $ stream -> read ( 1024 * 8 ) ; } }
Send an HTTP response
3,015
public static function translateByArray ( $ string ) { return preg_replace ( array_keys ( self :: $ ascii ) , array_values ( self :: $ ascii ) , $ string ) ; }
Replace special characters with english chars
3,016
public function getAvailableValues ( $ query = '' ) { $ dataRequest = new DataRequest ( 0 , 0 , $ this -> fieldName , 'ASC' ) ; if ( $ query != '' ) { $ dataRequest -> addFilter ( new Filter ( $ this -> fieldName , '*' . $ query . '*' , 'LIKE' ) ) ; } $ values = $ this -> dataSourceManager -> find ( $ dataRequest ) ; return $ values ; }
Returns the available values
3,017
protected function getObjectOr404 ( $ createOnNoId = false ) { $ objectId = static :: getObjectId ( ) ; $ object = null ; if ( $ objectId !== null ) { $ object = $ this -> getQuery ( ) -> findOneByPrimaryKey ( $ objectId ) ; } elseif ( $ createOnNoId === true ) { $ object = $ this -> getQuery ( ) -> createObject ( ) ; } if ( $ object === null ) { http_response_code ( 404 ) ; throw new \ Exception ( 'Object not found.' ) ; } return $ object ; }
Finds an object with the given id in this ObjectManager s query .
3,018
public function refresh ( $ refresh = true ) { $ this -> unitOfWorkHints [ Query :: HINT_REFRESH ] = ( boolean ) $ refresh ; return $ this ; }
Set whether to refresh hydrated documents that are already in the identity map .
3,019
public function header ( array $ headers ) { $ formattedHeaders = [ ] ; $ combinedHeaders = array_change_key_case ( array_merge ( $ this -> header , $ headers ) ) ; foreach ( $ combinedHeaders as $ key => $ val ) $ formattedHeaders [ ] = trim ( strtolower ( $ key ) ) . ':' . $ val ; $ this -> header = $ formattedHeaders ; return $ this ; }
Setting header head
3,020
public function cookieFile ( string $ cookieFile ) { curl_setopt ( self :: $ handle , CURLOPT_COOKIEJAR , $ cookieFile ) ; curl_setopt ( self :: $ handle , CURLOPT_COOKIEFILE , $ cookieFile ) ; return $ this ; }
Set cookie file storage path
3,021
public function create ( SiteInterface $ site ) { return $ this -> formFactory -> create ( 'silvestra_site' , $ site , array ( 'action' => $ this -> router -> getContext ( ) -> getPathInfo ( ) ) ) ; }
Create site form .
3,022
private function cache ( $ offset , $ limit ) { $ items = $ this -> adapter -> getItems ( $ offset , $ limit ) ; $ i = $ offset ; foreach ( $ items as $ item ) { $ this -> cached [ $ i ++ ] = $ item ; } if ( count ( $ items ) < $ limit ) { $ this -> lastItemPos = $ i - 1 ; } }
Fetches the given range of items from the adapter and stores them in the cache array .
3,023
private function fromCache ( $ offset , $ limit ) { $ items = array ( ) ; for ( $ i = $ offset ; $ i < ( $ offset + $ limit ) ; $ i ++ ) { if ( ! array_key_exists ( $ i , $ this -> cached ) ) { break ; } $ items [ ] = $ this -> cached [ $ i ] ; } return $ items ; }
Returns the range from previously cached items .
3,024
protected static function mcryptOptions ( $ options ) { $ options_default = array ( 'cipher' => MCRYPT_RIJNDAEL_128 , 'mode' => MCRYPT_MODE_CBC , 'return_base64' => true , 'rand_src' => MCRYPT_RAND , 'padding' => 'PKCS5' , 'iv' => null , 'iv_return' => true , ) ; $ options = array_merge ( $ options_default , $ options ) ; $ options [ 'iv_size' ] = mcrypt_get_iv_size ( $ options [ 'cipher' ] , $ options [ 'mode' ] ) ; $ options [ 'key_size' ] = mcrypt_get_key_size ( $ options [ 'cipher' ] , $ options [ 'mode' ] ) ; $ options [ 'block_size' ] = mcrypt_get_block_size ( $ options [ 'cipher' ] , $ options [ 'mode' ] ) ; return $ options ; }
get mcrypt options
3,025
protected static function mcryptKey ( $ key , $ options ) { $ debug = \ bdk \ Debug :: getInstance ( ) ; if ( Str :: isBase64Encoded ( $ key ) && ( strlen ( $ key ) >= $ options [ 'key_size' ] * 1.333 && strlen ( $ key ) <= $ options [ 'key_size' ] * 1.5 ) ) { $ debug -> log ( 'base64 decoding key' ) ; $ key = base64_decode ( $ key ) ; } $ ascii = true ; for ( $ i = 0 ; $ i < strlen ( $ key ) ; $ i ++ ) { if ( 0x80 & ord ( $ key { $ i } ) ) { $ ascii = false ; break ; } } if ( $ ascii ) { $ debug -> log ( 'hashing ascii key' ) ; $ new_key = '' ; $ num_segs = ceil ( $ options [ 'key_size' ] / 20 ) ; $ seg_length = ceil ( strlen ( $ key ) / $ num_segs ) ; for ( $ i = 0 ; $ i < $ num_segs ; $ i ++ ) { $ substr = substr ( $ key , $ i * $ seg_length , $ seg_length ) ; $ new_key .= sha1 ( $ substr , true ) ; } $ key = $ new_key ; } if ( strlen ( $ key ) > $ options [ 'key_size' ] ) { $ debug -> log ( 'sizing key' ) ; $ key = substr ( $ key , 0 , $ options [ 'key_size' ] ) ; } return $ key ; }
base64 decodes key hashes ascii key keeps key size < = key_size
3,026
public static function rmd5 ( $ action , $ key , $ str ) { $ ret = '' ; $ ctr = 0 ; if ( $ action == 'encrypt' ) { srand ( ( double ) microtime ( ) * 1000000 ) ; $ salt = md5 ( rand ( 0 , 32000 ) ) ; for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i ++ ) { if ( $ ctr == strlen ( $ salt ) ) { $ ctr = 0 ; } $ ret .= substr ( $ salt , $ ctr , 1 ) . ( substr ( $ str , $ i , 1 ) ^ substr ( $ salt , $ ctr , 1 ) ) ; $ ctr ++ ; } $ ret = self :: rmd5 ( 'keyed' , $ key , $ ret ) ; $ ret = base64_encode ( $ ret ) ; } elseif ( $ action == 'decrypt' ) { $ str = base64_decode ( $ str ) ; $ str = self :: rmd5 ( 'keyed' , $ key , $ str ) ; for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i += 2 ) { $ ret .= substr ( $ str , $ i , 1 ) ^ substr ( $ str , $ i + 1 , 1 ) ; } } elseif ( $ action == 'keyed' ) { $ key = md5 ( $ key ) ; for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i ++ ) { if ( $ ctr == strlen ( $ key ) ) { $ ctr = 0 ; } $ ret .= substr ( $ str , $ i , 1 ) ^ substr ( $ key , $ ctr , 1 ) ; $ ctr ++ ; } } return $ ret ; }
R - MD5 This algorithm is basically a two - level XOR .
3,027
public function createToken ( Request $ request , $ providerKey ) { if ( ! $ this -> secret ) { return null ; } $ authorizationHeader = $ request -> headers -> get ( 'Authorization' ) ; if ( $ authorizationHeader === null ) { return null ; } if ( 0 !== stripos ( $ authorizationHeader , 'Bearer ' ) ) { return null ; } $ authToken = substr ( $ authorizationHeader , 7 ) ; try { $ token = $ this -> decodeToken ( $ authToken ) ; } catch ( \ Exception $ exception ) { return null ; } return new JavascriptWebToken ( $ token , $ providerKey ) ; }
Create the token .
3,028
public function authenticateToken ( TokenInterface $ token , UserProviderInterface $ userProvider , $ providerKey ) { if ( ! $ this -> secret ) { throw new \ LogicException ( 'Config does not contain a secret.' ) ; } if ( ( null === ( $ credentials = $ token -> getCredentials ( ) ) ) || ! is_object ( $ credentials ) ) { throw new AuthenticationException ( sprintf ( 'Invalid token - no or invalid credentials.' ) ) ; } $ user = $ userProvider -> loadUserByUsername ( $ credentials -> username ) ; if ( ! $ user ) { throw new AuthenticationException ( sprintf ( 'Invalid token - could not derive user from credentials.' ) ) ; } return new JavascriptWebToken ( $ credentials , $ providerKey , $ user , $ user -> getRoles ( ) ) ; }
Authenticate the passed token .
3,029
public function onAuthenticationFailure ( Request $ request , AuthenticationException $ exception ) { return new Response ( 'Authentication Failed: ' . $ exception -> getMessage ( ) , Response :: HTTP_UNAUTHORIZED ) ; }
Generate a proper unauthorized response .
3,030
private function decodeToken ( $ jwt ) { $ decodedToken = \ JWT :: decode ( $ jwt , $ this -> secret , [ 'HS256' ] ) ; $ aud = property_exists ( $ decodedToken , 'aud' ) ? $ decodedToken -> aud : null ; if ( $ aud !== $ this -> localId ) { throw new \ UnexpectedValueException ( 'This token is not intended for us.' ) ; } return $ decodedToken ; }
Decode a token .
3,031
private function encode ( $ lifetime , $ customPayload = null ) { $ time = time ( ) ; $ payload = [ 'iat' => $ time ] ; if ( null !== $ customPayload ) { $ payload = array_merge ( $ customPayload , $ payload ) ; } $ jti = md5 ( json_encode ( $ payload ) ) ; $ payload [ 'jti' ] = $ jti ; if ( null !== $ this -> localId ) { $ payload [ 'aud' ] = $ this -> localId ; } if ( null !== $ lifetime ) { $ payload [ 'exp' ] = ( $ time + $ lifetime ) ; } $ jwt = \ JWT :: encode ( $ payload , $ this -> secret ) ; return $ jwt ; }
Encode a token .
3,032
public function checkAccess ( array $ permissions = [ ] , bool $ force = false ) : bool { if ( $ this -> isGuest ( ) ) { return false ; } if ( empty ( $ permissions ) ) { return true ; } if ( $ this -> isAdmin ( ) ) { return true ; } if ( count ( array_intersect ( $ permissions , $ this -> perissions ) ) > 0 ) { return true ; } return false ; }
Checks user access by permissions
3,033
public function getClassAnnotations ( ) { $ reflector = new ReflectionClass ( $ this -> className ) ; $ doc = $ reflector -> getDocComment ( ) ; if ( ! $ doc ) { return ; } $ annotations = [ ] ; foreach ( $ this -> filteringList as $ filter ) { preg_match_all ( '#@' . $ filter . '(.*?)\n#s' , $ doc , $ annotation ) ; if ( count ( $ annotation [ 1 ] ) > 0 ) { $ annotations [ $ filter ] = $ annotation [ 1 ] ; } } $ this -> annotationObject -> mergeClassAnnotations ( $ annotations ) ; }
Collect the class specific annotations from the class documentation .
3,034
public function getAllMethodAnnotations ( ) { $ data = [ ] ; $ methods = self :: listMethodsFromClass ( $ this -> className ) ; $ this -> annotationObject -> mergeMethodList ( $ methods ) ; foreach ( $ methods as $ method ) { $ annotations = self :: getMethodAnnotations ( $ method -> name ) ; if ( ! empty ( $ annotations ) ) { $ data [ $ method -> name ] = $ annotations ; } } $ this -> annotationObject -> mergeMethodAnnotations ( $ data ) ; }
A loop for get annotations from a Class to all of it s child methods .
3,035
public function getMethodAnnotations ( $ method ) { $ reflector = new ReflectionClass ( $ this -> className ) ; $ doc = $ reflector -> getMethod ( $ method ) -> getDocComment ( ) ; $ annotations = [ ] ; foreach ( $ this -> filteringList as $ filter ) { preg_match_all ( '#@' . $ filter . '(.*?)\n#s' , $ doc , $ annotation ) ; if ( ! empty ( $ annotation [ 1 ] ) ) { $ annotations [ $ filter ] = $ annotation [ 1 ] ; } } return $ annotations ; }
Get the annotations from a given method .
3,036
public static function listMethodsFromClass ( $ class ) { $ filteredMethods = array ( ) ; $ reflection = new ReflectionClass ( $ class ) ; $ methods = $ reflection -> getMethods ( ) ; foreach ( $ methods as $ method ) { if ( $ class === $ method -> class ) { $ filteredMethods [ ] = $ method ; } } return $ filteredMethods ; }
Get a list of the methods from a class .
3,037
public function find_all_files ( $ dir ) { $ root = scandir ( $ dir ) ; if ( count ( $ root ) == 0 ) return ; foreach ( $ root as $ value ) { if ( $ value === '.' || $ value === '..' ) { continue ; } if ( is_file ( "$dir/$value" ) ) { $ result [ ] = "$dir/$value" ; $ this -> pages [ ] = $ this -> read ( "$dir/$value" , $ value ) ; continue ; } foreach ( $ this -> find_all_files ( "$dir/$value" ) as $ value ) { $ result [ ] = $ value ; } } return $ result ; }
Find All file on asset dir and create array of Model \ Page
3,038
public function setBody ( $ file , $ body ) { if ( array_pop ( explode ( '.' , $ file ) ) == 'markdown' ) return Markdown :: defaultTransform ( $ body ) ; else return $ body ; }
Set body of Page . If body is markdown text formatted then it must be transform first to HTML
3,039
public function request ( $ url , $ payload = array ( ) , $ curlOptions = array ( ) , $ method = Curl :: Get ) { $ _response = null ; if ( $ this -> _hostPort ) { Curl :: setHostPort ( $ this -> _hostPort ) ; } if ( $ this -> _userName ) { Curl :: setUserName ( $ this -> _userName ) ; if ( $ this -> _password ) { Curl :: setPassword ( $ this -> _password ) ; } } return Curl :: request ( $ method , $ url , $ payload , $ curlOptions ) ; }
Makes a service request
3,040
final public function run ( ) { if ( isset ( $ this -> response ) ) { Yii :: info ( "Response configured as '" . gettype ( $ this -> response ) . "': " . VarDumper :: dumpAsString ( $ this -> response ) , __METHOD__ ) ; return $ this -> response ; } if ( $ response = $ this -> runInternal ( ) ) { $ this -> response = $ response ; } if ( isset ( $ this -> response ) ) { Yii :: info ( 'Response exists before rendering stage, action execution completed' . PHP_EOL . VarDumper :: dumpAsString ( $ this -> response , 2 ) , __METHOD__ ) ; } else { if ( is_callable ( $ this -> beforeRenderCallback ) ) { Yii :: info ( 'Executing before render callback' , __METHOD__ ) ; call_user_func ( $ this -> beforeRenderCallback , $ this ) ; } $ this -> render ( ) ; } if ( is_callable ( $ this -> afterCallback ) ) { Yii :: info ( 'Executing after callback' , __METHOD__ ) ; $ this -> response = call_user_func ( $ this -> afterCallback , $ this ) ; } return $ this -> response ; }
Basic Run action method implementation
3,041
protected function ensureModel ( ) { Yii :: trace ( 'Model ensuring' , __METHOD__ ) ; if ( $ this -> multiple ) { if ( empty ( $ this -> model ) || ! is_array ( $ this -> model ) ) { $ this -> model = [ $ this -> model ] ; } foreach ( $ this -> model as $ model ) { $ this -> ensureModelInternal ( $ model ) ; } return ; } $ this -> ensureModelInternal ( $ this -> model ) ; }
Ensure model stage
3,042
protected function setupFlushCache ( ) { do_action ( "before_theme_setup_flush_cache" ) ; add_action ( 'admin_bar_menu' , function ( $ wp_admin_bar ) { $ args = array ( 'id' => 'cache_flush_link' , 'title' => 'Flush cache' , 'href' => get_admin_url ( ) . '?flushCache' , 'meta' => array ( 'class' => 'cache-flush-link' ) ) ; $ wp_admin_bar -> add_node ( $ args ) ; } , 999 ) ; if ( isset ( $ _GET [ "flushCache" ] ) && is_admin ( ) && is_user_logged_in ( ) ) : $ this -> flushCache ( ) ; $ this -> doNotice ( __ ( "Cache has been flushed." ) ) ; endif ; do_action ( "after_theme_setup_flush_cache" ) ; }
Registers link & action for it on admin bar to flush cache
3,043
protected function flushOldCache ( ) { do_action ( "before_theme_flush_old_cache" ) ; $ files = glob ( $ this -> cachePath . "*" ) ; $ files = ( is_array ( $ files ) && $ files ? $ files : array ( ) ) ; $ cache_config = $ this -> getConfig ( "cache" ) ; foreach ( $ files as $ file ) : if ( file_exists ( $ file ) && ( time ( ) - filemtime ( $ file ) > $ cache_config [ "lifetime" ] ) ) : unlink ( $ file ) ; endif ; endforeach ; do_action ( "after_ntl_flush_old_cache" ) ; }
Clears all cached files that is older than specified cache lifetime because sometimes bots are requesting urls that is visited only once and after a while there will be thousands of files without any reason .
3,044
public function getCacheFile ( $ cacheKey ) { do_action ( "before_theme_get_cache_file" , $ cacheKey ) ; $ filename = md5 ( $ _SERVER [ "HTTP_HOST" ] . $ _SERVER [ "REQUEST_URI" ] . "-" . $ cacheKey ) ; do_action ( "after_theme_get_cache_file" , $ filename ) ; return $ this -> cachePath . $ filename ; }
Get absolute path of cache file
3,045
public function doCache ( $ sectionKey , & $ section ) { do_action ( "before_theme_do_cache" , $ sectionKey ) ; $ cacheKey = $ this -> getCacheKey ( $ sectionKey , $ section ) ; $ file = $ this -> getCacheFile ( $ cacheKey ) ; ob_start ( ) ; $ section -> init ( ) ; $ section -> render ( ) ; $ cacheConfig = $ this -> getConfig ( "cache" ) ; if ( $ cacheConfig [ "minify" ] ) : $ cache = str_replace ( [ " " , "\n" , "\t" ] , [ "" , "" , "" ] , ob_get_clean ( ) ) ; else : $ cache = ob_get_clean ( ) ; endif ; if ( $ cacheConfig [ "type" ] == "wp_cache" ) : wp_cache_add ( basename ( $ file ) , $ cache , "sections_cache" , $ cacheConfig [ "lifetime" ] ) ; else : if ( file_exists ( $ file ) ) : unlink ( $ file ) ; endif ; if ( ! empty ( $ cache ) || $ cache != "" ) : file_put_contents ( $ file , $ cache ) ; endif ; endif ; do_action ( "after_theme_do_cache" , $ cache ) ; return $ cache ; }
Create the cache
3,046
public function getCache ( $ sectionKey , & $ section ) { do_action ( "before_theme_get_cache" , $ sectionKey ) ; $ cacheKey = $ this -> getCacheKey ( $ sectionKey , $ section ) ; $ file = $ this -> getCacheFile ( $ cacheKey ) ; $ cache = false ; $ cacheConfig = $ this -> getConfig ( "cache" ) ; if ( $ cacheConfig [ "type" ] == "wp_cache" ) : $ cache = wp_cache_get ( basename ( $ file ) , "sections_cache" ) ; else : if ( file_exists ( $ file ) && ( time ( ) - filemtime ( $ file ) < $ cacheConfig [ "lifetime" ] ) ) : $ cache = file_get_contents ( $ file ) ; endif ; endif ; do_action ( "after_ntl_get_cache" , $ cache ) ; return $ cache ; }
Get cached html
3,047
protected function ensureGroupsLoaded ( $ action ) { if ( $ action !== $ this -> action ) { $ this -> action = $ action ; $ this -> groups = \ array_flip ( $ this -> processorBag -> getActionGroups ( $ action ) ) ; } }
Makes sure groups are loaded
3,048
private static function _traverse ( self $ instance , array $ array , string $ key ) { $ keys = explode ( '.' , $ key ) ; $ firstKey = $ keys [ 0 ] ; if ( count ( $ keys ) === 1 ) { if ( $ firstKey === '*' ) { return $ array ; } else if ( array_key_exists ( $ firstKey , $ array ) === true ) { return $ array [ $ firstKey ] ; } else { $ instance -> keys [ ] = $ firstKey ; throw new OutOfBoundsException ( "Undefined offset: {$instance->_key()}" ) ; } } else { $ instance -> keys [ ] = $ firstKey ; $ otherKeysList = array_slice ( $ keys , 1 ) ; $ otherKeys = implode ( '.' , $ otherKeysList ) ; if ( $ firstKey === '*' ) { $ value = [ ] ; foreach ( $ array as $ item ) { if ( is_array ( $ item ) === false ) { $ instance -> keys [ ] = $ otherKeysList [ 0 ] ; throw new OutOfBoundsException ( "Undefined offset: {$instance->_key()}" ) ; } array_push ( $ value , static :: _traverse ( $ instance , $ item , $ otherKeys ) ) ; } return $ value ; } else if ( is_numeric ( $ firstKey ) === true && is_int ( ( int ) $ firstKey ) === true ) { if ( array_key_exists ( $ firstKey , $ array ) === true ) { $ value = $ array [ $ firstKey ] ; return static :: _traverse ( $ instance , $ value , $ otherKeys ) ; } else { throw new OutOfBoundsException ( "Undefined offset: {$instance->_key()}" ) ; } } else { if ( array_key_exists ( $ firstKey , $ array ) === true ) { $ value = $ array [ $ firstKey ] ; if ( is_array ( $ value ) === false ) { $ instance -> keys [ ] = $ otherKeysList [ 0 ] ; throw new OutOfBoundsException ( "Undefined offset: {$instance->_key()}" ) ; } return static :: _traverse ( $ instance , $ value , $ otherKeys ) ; } else { throw new OutOfBoundsException ( "Undefined offset: {$instance->_key()}" ) ; } } } }
Traverse an array using a key and return the value .
3,049
public function getRawValue ( $ key ) { if ( ! array_key_exists ( $ key , $ this -> data ( ) ) ) { throw new \ InvalidArgumentException ( sprintf ( 'key [%s] is not present in response array.' , $ key ) ) ; } return $ this -> data ( ) [ $ key ] ; }
Return value in response array of the response .
3,050
public function vote ( $ candidates , Request $ request ) { $ this -> candidates = $ candidates ; $ this -> request = $ request ; $ this -> prioritseCandidates ( ) ; for ( $ i = $ this -> priority ; $ i >= 0 ; $ i -- ) { if ( isset ( $ this -> prioritised [ $ i ] ) && ! empty ( $ this -> prioritised [ $ i ] ) ) { return $ this -> prioritised [ $ i ] [ 0 ] ; } } throw new ResourceNotFoundException ( sprintf ( 'No routes found for path %s and method %s.' , $ this -> request -> getPathInfo ( ) , $ this -> request -> getMethod ( ) ) , 404 ) ; }
Votes on candidates and returns Route that matches the path closest
3,051
public function addFunction ( $ function ) { $ arguments = func_get_args ( ) ; array_shift ( $ arguments ) ; $ content = new HtmlFromFunction ( ) ; $ content -> functionPointer = $ function ; $ content -> parameters = $ arguments ; $ this -> children [ ] = $ content ; return $ this ; }
Adds some content to the block by calling the function passed in parameter .
3,052
public function addText ( $ text ) { $ content = new HtmlString ( ) ; $ content -> htmlString = $ text ; $ this -> children [ ] = $ content ; return $ this ; }
Adds some content to the block by displaying the text passed in parameter .
3,053
public function singleFragment ( $ name , $ configuration , ProviderInterface $ provider ) { foreach ( $ this -> types as $ type => $ class ) { if ( ! empty ( $ configuration [ $ type ] ) ) { return $ this -> instance ( $ class , $ name , $ configuration , $ provider ) ; } } return $ this -> instance ( $ this -> default , $ name , $ configuration , $ provider ) ; }
Creates a single feature instance from a configuration fragment
3,054
protected function instance ( $ class , $ name , array $ configuration , ProviderInterface $ provider ) { $ feature = new $ class ( $ name , $ configuration [ 'enabled' ] , $ provider ) ; $ feature -> configure ( $ configuration ) ; return $ feature ; }
Creates a feature instance from a fragment of normalized configuration
3,055
public function verifyFile ( ) { if ( ! $ this -> file ) return array ( 'error' => Yii :: t ( 'ciims.misc' , 'No files were uploaded.' ) ) ; $ size = $ this -> file -> size ; if ( $ size == 0 ) return array ( 'error' => Yii :: t ( 'ciims.misc' , 'File is empty' ) ) ; if ( $ size > $ this -> sizeLimit ) return array ( 'error' => Yii :: t ( 'ciims.misc' , 'File is too large' ) ) ; $ pathinfo = pathinfo ( $ this -> file -> name ) ; $ filename = $ pathinfo [ 'filename' ] ; $ ext = $ pathinfo [ 'extension' ] ; if ( ! in_array ( strtolower ( $ ext ) , $ this -> allowedExtensions ) ) { $ these = implode ( ', ' , $ this -> allowedExtensions ) ; return array ( 'error' => Yii :: t ( 'ciims.misc' , "File has an invalid extension, it should be one of {{these}}." , array ( '{{these}}' => $ these ) ) ) ; } return array ( 'success' => $ filename ) ; }
Verifies that a file is valid
3,056
private function checkServerSettings ( ) { $ postSize = $ this -> toBytes ( ini_get ( 'post_max_size' ) ) ; $ uploadSize = $ this -> toBytes ( ini_get ( 'upload_max_filesize' ) ) ; if ( $ postSize < $ this -> sizeLimit || $ uploadSize < $ this -> sizeLimit ) { $ size = max ( 1 , $ this -> sizeLimit / 1024 / 1024 ) . 'M' ; throw new CException ( Yii :: t ( 'ciims.misc' , 'Increase post_max_size and upload_max_filesize to {{size}}' , array ( '{{size}}' => $ size ) ) ) ; } return true ; }
Checks that the server size settings are implemented appropriatly
3,057
static public function declination ( $ number , $ suffix ) { $ keys = array ( 2 , 0 , 1 , 1 , 1 , 2 ) ; $ mod = $ number % 100 ; $ suffix_key = ( $ mod > 7 && $ mod < 20 ) ? 2 : $ keys [ min ( $ mod % 10 , 5 ) ] ; return $ suffix [ $ suffix_key ] ; }
Declination of words .
3,058
public function render ( ) { $ codeFormat = '$.toast(%s, %s);' ; $ items = array ( ) ; $ js = '' ; foreach ( $ this -> container as $ toast ) { $ items [ ] = sprintf ( $ codeFormat , Json :: encode ( $ toast -> getMessage ( ) ) , Json :: encode ( $ toast -> getOptions ( ) ) ) ; } if ( ! empty ( $ items ) ) { $ js = '<script type="text/javascript">//<![CDATA[' . "\n" . 'jQuery(function($) {' . "\n" . implode ( "\n" , $ items ) . "\n" . "});\n" . '//]]></script>' ; } return $ js ; }
Render the javascript code
3,059
protected function setLogic ( string $ logic ) : void { file_put_contents ( GPIO :: ROOT_FILESYSTEM . GPIO :: GPIO . $ this -> linuxNumber . '/' . GPIO :: ACTIVE_LOW , GPIO :: ACTIVE_LOW === $ logic ? 1 : 0 ) ; }
Set logic for HIGH level
3,060
protected function export ( ) : void { $ this -> unexport ( ) ; file_put_contents ( static :: ROOT_FILESYSTEM . static :: EXPORT , "{$this->linuxNumber}" ) ; if ( ! file_exists ( static :: ROOT_FILESYSTEM . static :: GPIO . $ this -> linuxNumber ) ) { throw new ExportException ( "Problem with export. GPIO {$this->linuxNumber} not found" ) ; } $ this -> isExported = TRUE ; }
Export GPIO to make it accessible in program userspace
3,061
public function updateSearchForm ( Form $ form ) { if ( $ this -> isVersioned ( ) ) { $ fields = $ form -> Fields ( ) ; $ filter = DropdownField :: create ( 'q[FilterClass]' , $ this -> owner -> getStatusFieldTitle ( ) , $ this -> getFilterClassOptions ( ) , $ this -> getFilterClass ( ) ) -> setForm ( $ form ) ; if ( $ this -> owner -> StatusFieldBefore ) { $ fields -> insertBefore ( sprintf ( 'q[%s]' , $ this -> owner -> StatusFieldBefore ) , $ filter ) ; } elseif ( $ this -> owner -> StatusFieldAfter ) { $ fields -> insertAfter ( sprintf ( 'q[%s]' , $ this -> owner -> StatusFieldAfter ) , $ filter ) ; } else { $ fields -> push ( $ filter ) ; } } }
Updates the given search form object .
3,062
public function updateList ( DataList & $ list ) { if ( $ this -> isVersioned ( ) ) { if ( $ filter = $ this -> getFilter ( $ list ) ) { $ list = $ filter -> apply ( ) ; } } }
Updates the given data list object .
3,063
protected function getFilter ( DataList $ list ) { if ( $ class = $ this -> getFilterClass ( ) ) { return Injector :: inst ( ) -> create ( $ class , $ list , $ this -> getParams ( ) ) ; } return DefaultFilter :: create ( $ list , $ this -> getParams ( ) ) ; }
Answers the filter object selected by the user or the default filter object .
3,064
protected function getFilterClassOptions ( ) { $ options = [ ] ; $ filters = ClassInfo :: subclassesFor ( Filter :: class ) ; array_shift ( $ filters ) ; foreach ( $ filters as $ filter ) { $ options [ $ filter ] = $ filter :: singleton ( ) -> getTitle ( ) ; } uasort ( $ options , function ( $ a , $ b ) { return ( $ a === DefaultFilter :: singleton ( ) -> getTitle ( ) ) ? - 1 : strcasecmp ( $ a , $ b ) ; } ) ; return $ options ; }
Answers an array of options for the filter class field .
3,065
public function get ( ) { $ this -> provider -> enumKey ( $ this -> root , $ this -> path , $ keys = new Variant ( ) ) ; $ formatted = [ ] ; $ i = 0 ; foreach ( $ keys as $ key ) { $ formatted [ $ i ] = $ key ; $ i ++ ; } return $ formatted ; }
Returns the list of keys available from the registry .
3,066
public function getValue ( $ key ) { $ status = $ this -> provider -> getStringValue ( $ this -> root , $ this -> path , $ key , $ value = new Variant ( ) ) ; if ( $ status === 0 ) { return ( string ) $ value ; } return null ; }
Returns the value of a specific key in the current root and path of the registry .
3,067
public function assemble ( ) { $ query = "DELETE FROM {$this->getManager()->protect($this->getTable())}" ; $ query .= $ this -> assembleWhere ( ) ; $ order = $ this -> parseOrder ( ) ; if ( ! empty ( $ order ) ) { $ query .= " order by {$order}" ; } $ query .= $ this -> assembleLimit ( ) ; return $ query ; }
Joins together DELETE FROM WHERE ORDER and LIMIT parts of SQL query
3,068
public function hasContentAccessPriviledges ( $ gid , $ uoid ) { if ( ! UOID :: isValid ( $ uoid ) && $ uoid ) throw new AccessControlManagerException ( 'Illegal argument UOID: ' . $ uoid ) ; try { $ rules = $ this -> loadAccessControlRulesForUOID ( $ gid , $ uoid ) ; return $ this -> executeAccessControlRules ( $ gid , $ rules ) ; } catch ( AccessControlManagerException $ e ) { if ( $ this -> baseDirectiveInterface == AccessControlManager :: DIRECTIVE_DENY ) return false ; else return true ; } }
determines if a globalID has access priviledges for a specific resource
3,069
public function hasInterfaceAccessPriviledges ( $ owner , $ gid , $ interface , $ accessMethod = '*' ) { if ( $ interface == '' ) $ interface = '*' ; try { $ rules = $ this -> loadAccessControlRulesForInterface ( $ owner , $ gid , $ interface ) ; if ( $ accessMethod == AccessControlRuleObject :: ACCESS_TYPE_WRITE ) { foreach ( $ rules as $ id => $ rule ) { if ( $ rule -> getAccessType ( ) == AccessControlRuleObject :: ACCESS_TYPE_READ ) unset ( $ rules [ $ id ] ) ; } } elseif ( $ accessMethod == AccessControlRuleObject :: ACCESS_TYPE_READ ) { foreach ( $ rules as $ id => $ rule ) { if ( $ rule -> getAccessType ( ) == AccessControlRuleObject :: ACCESS_TYPE_WRITE ) unset ( $ rules [ $ id ] ) ; } } return $ this -> executeAccessControlRules ( $ gid , $ rules ) ; } catch ( AccessControlManagerException $ e ) { if ( $ this -> baseDirectiveInterface == AccessControlManager :: DIRECTIVE_DENY ) return false ; else return true ; } }
determines if a globalID has access priviledges for a specific interface
3,070
public function jscan ( $ count = 50 , array $ queues = [ ] , array $ states = [ ] , $ format = JScanIterator :: FORMAT_ID ) { $ iterator = new JScanIterator ( $ this -> stream , $ this -> log ) ; $ iterator -> setCount ( $ count ) ; $ iterator -> setQueues ( $ queues ) ; $ iterator -> setStates ( $ states ) ; $ iterator -> setFormat ( $ format ) ; return $ iterator ; }
Retrieve an Iterator over available jobs on the connected Disque node .
3,071
public function createNew ( string $ slug , string $ attribute ) : array { return $ this -> sendPost ( sprintf ( '/profiles/%s/flags' , $ this -> userName ) , [ ] , [ 'slug' => $ slug , 'attribute' => $ attribute ] ) ; }
Creates a new flag for the given user .
3,072
public function add ( $ content , $ level = '' , $ timeout = 0 , $ priority = 0 , $ dismissable = true , $ area = '' ) { $ area = $ area ? : is_array ( $ content ) && isset ( $ content [ 'area' ] ) ? $ content [ 'area' ] : $ this -> workingArea ? : $ this -> defaultArea ; $ level = $ level ? : $ this -> defaultLevel ; if ( ! $ this -> canView ( $ area ) ) { return $ this ; } $ content = is_array ( $ content ) ? $ content : [ 'content' => $ content , 'level' => $ level , 'timeout' => $ timeout , 'priority' => $ priority , 'dismissable' => $ dismissable , ] ; if ( $ this -> blocker ( ) -> isBlocked ( $ content ) ) { return ; } $ this -> style ( $ area ) ; $ messages = ( array ) Session :: get ( $ this -> id . '.' . $ area ) ; if ( $ dismissable && ! isset ( $ content [ 'dismiss_link' ] ) ) { $ content [ 'dismiss_link' ] = singleton ( 'Milkyway\SS\FlashMessage\Controller' ) -> Link ( 'dismiss' . '?' . http_build_query ( [ 'area' => $ area , 'id' => empty ( $ content [ 'id' ] ) ? '' : $ content [ 'id' ] , 'content' => empty ( $ content [ 'content' ] ) ? '' : $ content [ 'content' ] , ] ) ) ; } array_unshift ( $ messages , $ content ) ; Session :: set ( $ this -> id . '.' . $ area , $ messages ) ; $ this -> clearWorking ( ) ; return $ this ; }
Add a message to the notifier
3,073
public function remove ( $ content = null , $ level = '' , $ area = '' ) { $ area = $ area ? : $ this -> workingArea ? : $ this -> defaultArea ; $ level = $ level ? : $ this -> defaultLevel ; $ this -> clear ( is_array ( $ content ) ? $ content : [ 'content' => $ content , 'level' => $ level , 'area' => $ area , ] ) ; $ this -> clearWorking ( ) ; return $ this ; }
Remove a message from the notifier
3,074
public function clear ( $ params = [ ] ) { if ( isset ( $ params [ 'level' ] ) || isset ( $ params [ 'content' ] ) ) { $ level = isset ( $ params [ 'level' ] ) ? $ params [ 'level' ] : '' ; $ content = isset ( $ params [ 'content' ] ) ? $ params [ 'content' ] : '' ; $ area = isset ( $ params [ 'area' ] ) ? $ params [ 'area' ] : '' ; $ messages = $ area ? ( array ) Session :: get ( $ this -> id . '.' . $ area ) : ( array ) Session :: get ( $ this -> id ) ; $ adjust = function ( $ messages ) use ( $ content , $ level ) { $ new = [ ] ; foreach ( $ messages as $ message ) { if ( $ content && $ level && $ message [ 'content' ] != $ content && $ message [ 'level' ] != $ level ) { $ new [ ] = $ message ; } else { if ( $ content && ! $ level && $ message [ 'content' ] != $ content ) { $ new [ ] = $ message ; } else { if ( ! $ content && $ level && $ message [ 'level' ] != $ level ) { $ new [ ] = $ message ; } } } } return $ new ; } ; if ( $ area ) { Session :: set ( $ this -> id . '.' . $ area , $ adjust ( $ messages ) ) ; } else { foreach ( $ messages as $ area => $ areaMessages ) { Session :: set ( $ this -> id . '.' . $ area , $ adjust ( $ areaMessages ) ) ; } } } else { if ( isset ( $ params [ 'area' ] ) ) { Session :: clear ( $ this -> id . '.' . $ params [ 'area' ] ) ; } } return $ this ; }
Clear a message that matches a set of params
3,075
public function get ( $ area = '' ) { $ area = $ area ? : $ this -> workingArea ? : $ this -> defaultArea ; $ messages = ( array ) Session :: get ( $ this -> id . '.' . $ area ) ; Session :: clear ( $ this -> id . '.' . $ area ) ; $ this -> clearWorking ( ) ; if ( $ this -> unique ) { $ content = [ ] ; $ messages = array_filter ( $ messages , function ( $ message ) use ( & $ content ) { if ( in_array ( $ message [ 'content' ] , $ content ) ) { return false ; } else { array_push ( $ content , $ message [ 'content' ] ) ; return true ; } } ) ; } $ messages = array_filter ( $ messages , function ( $ message ) use ( $ area ) { $ params = $ message ; $ params [ 'area' ] = $ area ; return ! $ this -> blocker ( ) -> isBlocked ( $ params ) ; } ) ; return $ messages ; }
Get messages for an area
3,076
public function before ( $ link , $ area = '' ) { $ area = $ area ? : $ this -> workingArea ? : '' ; if ( isset ( $ this -> before [ $ link ] ) ) { $ this -> before [ $ link ] = array_merge ( $ this -> before [ $ link ] , explode ( ',' , $ area ) ) ; } else { $ this -> before [ $ link ] = explode ( ',' , $ area ) ; } $ this -> clearWorking ( ) ; }
Add a link to execute before messages are added
3,077
public function style ( $ area ) { if ( in_array ( $ area , $ this -> jsIncluded ) || singleton ( 'env' ) -> get ( 'messages.exclude_js' ) || singleton ( 'env' ) -> get ( 'messages.exclude_' . $ area . '_js' ) ) { return ; } $ params = [ 'Before' => '' , 'Link' => singleton ( 'Milkyway\SS\FlashMessage\Controller' ) -> Link ( $ area ) , ] ; foreach ( $ this -> before as $ link => $ areas ) { if ( empty ( $ areas ) || in_array ( $ area , $ areas ) ) { $ params [ 'Before' ] .= $ link . ',' ; } } $ params [ 'Before' ] = trim ( $ params [ 'Before' ] , ',' ) ; Requirements :: javascriptTemplate ( singleton ( 'env' ) -> get ( 'messages.dir' ) . '/js/mwm.flash-messages.link.js' , $ params , singleton ( 'env' ) -> get ( 'messages.dir' ) . '/js/mwm.flash-messages.link.js:' . $ area ) ; $ this -> jsIncluded [ ] = $ area ; if ( ! singleton ( 'env' ) -> get ( 'messages.exclude_lib_js' ) ) { Requirements :: javascript ( THIRDPARTY_DIR . '/jquery/jquery.js' ) ; Requirements :: javascript ( singleton ( 'env' ) -> get ( 'messages.dir' ) . '/js/mwm.flash-messages.js' ) ; } if ( ! singleton ( 'env' ) -> get ( 'messages.exclude_lib_css' ) ) { Requirements :: css ( singleton ( 'env' ) -> get ( 'messages.dir' ) . '/css/mwm.flash-messages.css' ) ; } }
Include JS and CSS for flash messages
3,078
protected function canView ( $ area ) { $ notifierController = singleton ( 'Milkyway\\SS\\FlashMessage\\Controller' ) ; if ( Control :: curr ( ) instanceof $ notifierController ) { return true ; } $ mapping = ( array ) singleton ( 'env' ) -> get ( 'messages.mapping' ) ; if ( isset ( $ mapping [ $ area ] ) ) { $ allowed = array_filter ( ( array ) $ mapping [ $ area ] ) ; foreach ( $ allowed as $ controller ) { if ( is_a ( Control :: curr ( ) , $ controller ) ) { return true ; } } return false ; } return true ; }
Check whether the area is limited by controller type
3,079
private function getAuthenticatedVisitorsRatio ( $ visitors ) { $ ratio = [ 'authenticated' => 0 , 'guest' => 0 , ] ; foreach ( $ visitors as $ visitor ) { $ visitor -> hasUser ( ) ? $ ratio [ 'authenticated' ] += 1 : $ ratio [ 'guest' ] += 1 ; } return collect ( $ ratio ) -> transform ( function ( $ count , $ key ) { return [ 'name' => trans ( "tracker::visitors.$key" ) , 'count' => $ count , ] ; } ) ; }
Get the authenticated visitors ratio .
3,080
public function setLocalIpAddress ( $ address ) { if ( ! filter_var ( $ address , FILTER_VALIDATE_IP ) ) { throw new \ InvalidArgumentException ( 'Invalid ip address' ) ; } $ this -> networkIpVersion = ( strpos ( $ address , ':' ) === false ) ? NetworkNodeInterface :: IP_V4 : NetworkNodeInterface :: IP_V6 ; $ this -> networkLocalIp = $ address ; }
Sets listening address .
3,081
public function setLocalPort ( $ port ) { if ( $ port < 0 || $ port > 65535 || ! is_integer ( $ port ) ) { throw new \ InvalidArgumentException ( 'Invalid port' ) ; } $ this -> networkLocalPort = $ port ; }
Sets listening port .
3,082
function giveClient ( \ Predis \ Client $ client ) { if ( $ this -> client ) throw new exImmutable ; $ this -> client = $ client ; return $ this ; }
Set Redis Client Instance
3,083
function capture ( $ templateFullPathname , array $ __vars = array ( ) ) { if ( $ this -> _curr__captureVars === null ) $ this -> _curr__captureVars = $ __vars ; else ( ! empty ( $ __vars ) ) ? : $ __vars = $ this -> _curr__captureVars ; if ( ! file_exists ( $ templateFullPathname ) ) { $ backTrace = debug_backtrace ( ) [ 0 ] ; if ( isset ( $ backTrace [ 'file' ] ) ) { $ tInclude = dirname ( $ backTrace [ 'file' ] ) . '/' . trim ( $ templateFullPathname , '/' ) ; ( ! is_file ( $ tInclude ) ) ? : $ templateFullPathname = $ tInclude ; unset ( $ backTrace ) ; unset ( $ tInclude ) ; } } if ( ! is_file ( $ templateFullPathname ) || ! is_readable ( $ templateFullPathname ) ) throw new exTemplateNotFound ( sprintf ( 'Cant include (%s).' , $ templateFullPathname ) ) ; $ this -> __file_to_include = $ templateFullPathname ; unset ( $ templateFullPathname ) ; extract ( $ __vars ) ; unset ( $ __vars ) ; try { ob_start ( ) ; if ( 1 === $ result = include $ this -> __file_to_include ) $ result = ob_get_clean ( ) ; else ob_end_clean ( ) ; } catch ( \ Exception $ e ) { ob_end_clean ( ) ; throw $ e ; } unset ( $ this -> __file_to_include ) ; return $ result ; }
Capture Included File Into This Object
3,084
public function process ( ContainerBuilder $ container ) { $ parameterBag = $ container -> getParameterBag ( ) ; foreach ( $ container -> getDefinitions ( ) as $ id => $ definition ) { try { $ definition -> setClass ( $ parameterBag -> resolveValue ( $ definition -> getClass ( ) ) ) ; $ definition -> setFile ( $ parameterBag -> resolveValue ( $ definition -> getFile ( ) ) ) ; $ definition -> setArguments ( $ parameterBag -> resolveValue ( $ definition -> getArguments ( ) ) ) ; $ factory = $ definition -> getFactory ( ) ; if ( is_array ( $ factory ) && isset ( $ factory [ 0 ] ) ) { $ factory [ 0 ] = $ parameterBag -> resolveValue ( $ factory [ 0 ] ) ; $ definition -> setFactory ( $ factory ) ; } $ calls = array ( ) ; foreach ( $ definition -> getMethodCalls ( ) as $ name => $ arguments ) { $ calls [ $ parameterBag -> resolveValue ( $ name ) ] = $ parameterBag -> resolveValue ( $ arguments ) ; } $ definition -> setMethodCalls ( $ calls ) ; $ definition -> setProperties ( $ parameterBag -> resolveValue ( $ definition -> getProperties ( ) ) ) ; } catch ( ParameterNotFoundException $ e ) { $ e -> setSourceId ( $ id ) ; throw $ e ; } } $ aliases = array ( ) ; foreach ( $ container -> getAliases ( ) as $ name => $ target ) { $ aliases [ $ parameterBag -> resolveValue ( $ name ) ] = $ parameterBag -> resolveValue ( $ target ) ; } $ container -> setAliases ( $ aliases ) ; $ parameterBag -> resolve ( ) ; }
Processes the ContainerBuilder to resolve parameter placeholders .
3,085
public function gcj_encrypt ( $ wgsLat , $ wgsLon ) { if ( ! $ this -> isInChina ( $ wgsLat , $ wgsLon ) ) return array ( 'lat' => $ wgsLat , 'lon' => $ wgsLon ) ; $ d = $ this -> delta ( $ wgsLat , $ wgsLon ) ; return array ( 'lat' => $ wgsLat + $ d [ 'lat' ] , 'lon' => $ wgsLon + $ d [ 'lon' ] ) ; }
WGS - 84 to GCJ - 02
3,086
public function gcj_decrypt ( $ gcjLat , $ gcjLon ) { if ( ! $ this -> isInChina ( $ gcjLat , $ gcjLon ) ) return array ( 'lat' => $ gcjLat , 'lon' => $ gcjLon ) ; $ d = $ this -> delta ( $ gcjLat , $ gcjLon ) ; return array ( 'lat' => $ gcjLat - $ d [ 'lat' ] , 'lon' => $ gcjLon - $ d [ 'lon' ] ) ; }
GCJ - 02 to WGS - 84
3,087
public function gcj_decrypt_exact ( $ gcjLat , $ gcjLon ) { $ initDelta = 0.01 ; $ threshold = 0.000000001 ; $ dLat = $ initDelta ; $ dLon = $ initDelta ; $ mLat = $ gcjLat - $ dLat ; $ mLon = $ gcjLon - $ dLon ; $ pLat = $ gcjLat + $ dLat ; $ pLon = $ gcjLon + $ dLon ; $ wgsLat = 0 ; $ wgsLon = 0 ; $ i = 0 ; while ( TRUE ) { $ wgsLat = ( $ mLat + $ pLat ) / 2 ; $ wgsLon = ( $ mLon + $ pLon ) / 2 ; $ tmp = $ this -> gcj_encrypt ( $ wgsLat , $ wgsLon ) ; $ dLat = $ tmp [ 'lat' ] - $ gcjLat ; $ dLon = $ tmp [ 'lon' ] - $ gcjLon ; if ( ( abs ( $ dLat ) < $ threshold ) && ( abs ( $ dLon ) < $ threshold ) ) break ; if ( $ dLat > 0 ) $ pLat = $ wgsLat ; else $ mLat = $ wgsLat ; if ( $ dLon > 0 ) $ pLon = $ wgsLon ; else $ mLon = $ wgsLon ; if ( ++ $ i > 10000 ) break ; } return array ( 'lat' => $ wgsLat , 'lon' => $ wgsLon ) ; }
GCJ - 02 to WGS - 84 exactly
3,088
public function bd_encrypt ( $ gcjLat , $ gcjLon ) { $ x = $ gcjLon ; $ y = $ gcjLat ; $ z = sqrt ( $ x * $ x + $ y * $ y ) + 0.00002 * sin ( $ y * $ this -> x_pi ) ; $ theta = atan2 ( $ y , $ x ) + 0.000003 * cos ( $ x * $ this -> x_pi ) ; $ bdLon = $ z * cos ( $ theta ) + 0.0065 ; $ bdLat = $ z * sin ( $ theta ) + 0.006 ; return array ( 'lat' => $ bdLat , 'lon' => $ bdLon ) ; }
GCJ - 02 to BD - 09
3,089
public function distance ( $ latA , $ lonA , $ latB , $ lonB ) { $ earthR = 6371000. ; $ x = cos ( $ latA * $ this -> PI / 180. ) * cos ( $ latB * $ this -> PI / 180. ) * cos ( ( $ lonA - $ lonB ) * $ this -> PI / 180 ) ; $ y = sin ( $ latA * $ this -> PI / 180. ) * sin ( $ latB * $ this -> PI / 180. ) ; $ s = $ x + $ y ; if ( $ s > 1 ) $ s = 1 ; if ( $ s < - 1 ) $ s = - 1 ; $ alpha = acos ( $ s ) ; $ distance = $ alpha * $ earthR ; return $ distance ; }
two point s distance
3,090
public function sendResponse ( ResponseInterface $ response ) { $ e = $ this -> getEvent ( ) ; $ e -> setResponse ( $ response ) ; $ e -> getApplication ( ) -> getEventManager ( ) -> trigger ( MvcEvent :: EVENT_FINISH , $ e ) ; exit ( ) ; }
Sends the response and terminates .
3,091
protected static function track ( ) { $ result = '' ; if ( config ( 'lumos.tracking' ) ) { $ result .= ' * @author ' . config ( 'app.owner' ) . "\n" ; $ result .= ' * creation time : ' . DateTime :: now ( ) . ' (' . time ( ) . ')' . "\n" ; } return $ result ; }
Add Tracking doc bloc .
3,092
protected function buildMessage ( $ body , EmailInterface $ email ) { $ message = "To: " . $ email -> getTo ( ) . "\r\n" ; $ message .= "Subject: " . $ email -> getSubject ( ) . "\r\n" ; $ message .= $ this -> buildHeaders ( $ email ) . "\r\n" ; $ message .= $ body ; return $ message ; }
Constructs a single string from the email body and headers .
3,093
public function logException ( FlattenException $ exception , Request $ request ) { $ ex = new Exception5xx ( ) ; $ ex -> setStatusCode ( $ this -> getStatusCode ( $ exception ) ) ; $ ex -> setFile ( $ exception -> getFile ( ) ) ; $ ex -> setLine ( $ exception -> getLine ( ) ) ; $ ex -> setTrace ( $ this -> getTrace ( $ exception -> getTrace ( ) ) ) ; $ ex -> setMessage ( $ exception -> getMessage ( ) ) ; $ ex -> setRequestUrl ( $ request -> getRequestUri ( ) ) ; $ ex -> setReferrer ( $ request -> server -> get ( 'HTTP_REFERER' ) ) ; $ ex -> setUserAgent ( $ request -> server -> get ( 'HTTP_USER_AGENT' ) ) ; $ ex -> setRemoteIp ( $ request -> server -> get ( 'REMOTE_ADDR' ) ) ; $ ex -> setMethod ( $ request -> server -> get ( 'REQUEST_METHOD' ) ) ; $ ex -> setQueryString ( $ request -> server -> get ( 'QUERY_STRING' ) ) ; $ ex -> setHostname ( $ request -> getHttpHost ( ) ) ; $ ex -> setRequest ( Flattener :: flattenArrayToString ( $ request -> request -> all ( ) ) ) ; $ ex -> setLogged ( new \ DateTime ( "now" ) ) ; try { $ manager = $ this -> registry -> getManagerForClass ( 'EXSErrorBundle:Exception5xx' ) ; $ manager -> persist ( $ ex ) ; $ manager -> flush ( $ ex ) ; } catch ( \ Exception $ e ) { } }
Log the actual exception
3,094
public static function check ( ) { if ( Session :: has ( self :: ENVIRONMENT_NAME ) ) { return true ; } Session :: forget ( self :: ENVIRONMENT_NAME ) ; return false ; }
Check if the session exists
3,095
public function registerEvents ( ) { Event :: listen ( 'auth.login' , function ( $ user ) { Session :: put ( 'kinvey' , $ user -> _kmd [ 'authtoken' ] ) ; } ) ; Event :: listen ( 'auth.logout' , function ( $ user ) { Session :: forget ( 'kinvey' ) ; } ) ; }
Register events for this service provider .
3,096
protected function magicGetName ( ) { if ( property_exists ( $ this , 'magicName' ) && ( ! empty ( $ this -> magicName ) ) ) { return $ this -> magicName ; } return get_class ( $ this ) ; }
Returns the name of the container
3,097
public function readDemPackage ( $ pathToDemFile , $ pathToDemNode ) { $ json = file_get_contents ( $ pathToDemFile ) ; $ data = json_decode ( $ json , true ) ; $ paths = explode ( self :: PS , $ pathToDemNode ) ; foreach ( $ paths as $ path ) { if ( strlen ( trim ( $ path ) ) > 0 ) { if ( isset ( $ data [ $ path ] ) ) { $ data = $ data [ $ path ] ; } else { throw new \ Exception ( "Cannot find DEM node '$pathToDemNode' in file '$pathToDemFile'." ) ; } } } $ result = new Data ( $ data ) ; return $ result ; }
Read JSON file with DEM extract and return DEM node as an associative array .
3,098
protected function loadComposerData ( $ composerFile ) { if ( ! is_readable ( $ composerFile ) ) { throw new ExceptionPackageInfo ( 'Could not read composer data.' ) ; } $ this -> composerJson = json_decode ( file_get_contents ( $ composerFile ) , true ) ; }
Reads the composer data .
3,099
protected function guessBaseDir ( $ hintLocation , $ composerFileName ) { do { $ f = $ hintLocation . '/' . $ composerFileName ; if ( is_file ( $ f ) ) { return $ hintLocation ; } $ prevLocation = $ hintLocation ; $ hintLocation = $ this -> sanitisePaths ( dirname ( $ hintLocation ) ) ; $ ranOut = ( $ prevLocation === $ hintLocation ) ; } while ( ! $ ranOut ) ; throw new ExceptionPackageInfo ( 'The trail went cold. Could not determine the location of the composer file and ran out of places to look.' ) ; }
Try to figure out root directory .