idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
7,600
public static function action ( $ action = '' , $ params = array ( ) , $ retain = false ) { if ( $ action == 'index' ) { $ action = '' ; } if ( CCRequest :: current ( ) && ( $ route = CCRequest :: current ( ) -> route ) ) { $ uri = $ route -> uri ; if ( ! is_null ( $ route -> action ) ) { $ uri = substr ( $ uri , 0 , strlen ( $ route -> action ) * - 1 ) ; } if ( substr ( $ uri , - 1 ) != '/' ) { $ uri .= '/' ; } return static :: to ( $ uri . $ action , $ params , $ retain ) ; } throw new CCException ( 'CCUrl::action - There has been no route executed yet.' ) ; }
Get the url to a action of the current route
7,601
public static function active ( $ url ) { $ url = parse_url ( $ url , PHP_URL_PATH ) ; if ( empty ( $ url ) ) { return false ; } if ( $ url [ 0 ] !== '/' ) { $ url = static :: to ( $ url ) ; } if ( $ url === '/' ) { return static :: current ( ) == $ url ; } $ cut = substr ( static :: current ( ) , 0 , strlen ( $ url ) ) ; return $ cut == $ url ; }
Is the given url active? This function ignores the domain and the parameters if the uri matches the current uri true will be returned .
7,602
public static function getData ( $ plugin , $ key = null ) { $ data = self :: _checkData ( $ plugin ) ; if ( empty ( $ data ) && $ path = self :: getManifestPath ( $ plugin ) ) { if ( FS :: isFile ( $ path ) ) { $ plgData = include $ path ; $ plgData = ( array ) $ plgData ; if ( ! empty ( $ plgData ) ) { self :: $ _data [ $ plugin ] = $ plgData ; $ data = $ plgData ; } } } return self :: _getPluginData ( $ data , $ key ) ; }
Get plugin manifest data .
7,603
public static function getManifestPath ( $ plugin ) { if ( self :: loaded ( $ plugin ) ) { return FS :: clean ( self :: path ( $ plugin ) . DS . self :: PLUGIN_MANIFEST ) ; } return null ; }
Get absolute plugin manifest file path .
7,604
public static function loadList ( array $ plugins ) { foreach ( $ plugins as $ name ) { if ( self :: loaded ( $ name ) ) { continue ; } if ( $ path = self :: _findPlugin ( $ name ) ) { self :: load ( $ name , self :: _getConfigForLoad ( $ path ) ) ; } } }
Load list plugin .
7,605
public static function manifestEvent ( ) { $ args = func_get_args ( ) ; $ callback = array_shift ( $ args ) ; if ( Arr :: key ( $ callback , self :: $ _eventList ) ) { $ callbacks = self :: $ _eventList [ $ callback ] ; foreach ( $ callbacks as $ method ) { call_user_func_array ( $ method , $ args ) ; } } }
Call plugin manifest callbacks .
7,606
public static function unload ( $ plugin = null ) { if ( self :: loaded ( $ plugin ) ) { $ locales = Configure :: read ( 'App.paths.locales' ) ; foreach ( $ locales as $ key => $ path ) { if ( $ path == self :: getLocalePath ( $ plugin ) ) { unset ( $ locales [ $ key ] ) ; } } Configure :: write ( 'App.paths.locales' , $ locales ) ; } parent :: unload ( $ plugin ) ; }
Unload the plugin .
7,607
protected static function _addManifestCallback ( $ plugin ) { $ data = Plugin :: getData ( $ plugin ) ; foreach ( $ data as $ name => $ callback ) { if ( self :: _isCallablePluginData ( $ name , $ plugin , $ callback ) && $ plugin !== 'Core' ) { self :: $ _eventList [ $ name ] [ $ plugin ] = $ callback ; } } }
Registration plugin manifest callbacks .
7,608
protected static function _checkData ( $ plugin ) { return ( Arr :: in ( $ plugin , self :: $ _data ) ) ? self :: $ _data [ $ plugin ] : [ ] ; }
Check plugin data .
7,609
protected static function _findPlugin ( $ name ) { $ output = null ; $ paths = App :: path ( 'Plugin' ) ; $ plugin = Configure :: read ( 'plugins.' . $ name ) ; if ( $ plugin !== null ) { return $ plugin ; } foreach ( $ paths as $ path ) { $ plgPath = $ path . $ name . DS ; if ( FS :: isDir ( $ plgPath ) ) { $ output = $ plgPath ; break ; } } return $ output ; }
Find plugin dir in registered paths .
7,610
protected static function _getConfigForLoad ( $ path ) { $ config = [ 'autoload' => true ] ; $ routes = $ path . 'config' . DS . Plugin :: FILE_ROUTES ; $ bootstrap = $ path . 'config' . DS . Plugin :: FILE_BOOTSTRAP ; if ( FS :: isFile ( $ bootstrap ) ) { $ config [ 'bootstrap' ] = true ; } if ( FS :: isFile ( $ routes ) ) { $ config [ 'routes' ] = true ; } $ config [ 'path' ] = $ path ; return $ config ; }
Get plugin configuration for load plugin .
7,611
protected static function _getPluginData ( array $ data , $ key = null ) { if ( isset ( $ data [ $ key ] ) ) { $ data = $ data [ $ key ] ; } return new Data ( $ data ) ; }
Get current plugin data .
7,612
protected static function _isCallablePluginData ( $ name , $ plugin , $ callback ) { if ( Arr :: in ( $ name , self :: $ _manifestEvents ) && ! isset ( self :: $ _eventList [ $ name ] [ $ plugin ] ) && is_callable ( $ callback ) ) { return true ; } return false ; }
Check manifest param on callable .
7,613
public static function generate ( $ length ) : string { $ sets = [ 'abcdefghjkmnpqrstuvwxyz' , 'ABCDEFGHJKMNPQRSTUVWXYZ' , '23456789' ] ; $ all = '' ; $ password = '' ; foreach ( $ sets as $ set ) { $ password .= $ set [ array_rand ( str_split ( $ set ) ) ] ; $ all .= $ set ; } $ all = str_split ( $ all ) ; for ( $ i = 0 ; $ i < $ length - count ( $ sets ) ; $ i ++ ) { $ password .= $ all [ array_rand ( $ all ) ] ; } $ password = str_shuffle ( $ password ) ; return $ password ; }
Generates user - friendly random password containing at least one lower case letter one uppercase letter and one digit . The remaining characters in the password are chosen at random from those three sets .
7,614
public function stop ( $ marker ) { if ( array_key_exists ( $ marker , $ this -> timers ) ) { $ this -> timers [ $ marker ] -> stop ( ) ; } }
Stop timer with a specific marker .
7,615
public function build ( ) { foreach ( $ this -> timers as $ marker => $ timer ) { $ this -> markers [ $ marker ] = $ timer -> time ( ) ; } arsort ( $ this -> markers ) ; return $ this -> markers ; }
Return sorted times .
7,616
public function calculateTotal ( ) { $ this -> calculateAdjustmentsTotal ( ) ; $ this -> total = ( $ this -> quantity * $ this -> unitPrice ) + $ this -> adjustmentsTotal ; if ( $ this -> total < 0 ) { $ this -> total = 0 ; } return $ this ; }
Calculates the total for the item
7,617
public function addItem ( PricedItemInterface $ item ) { if ( $ this -> hasItem ( $ item ) ) { return $ this ; } foreach ( $ this -> items as $ existingItem ) { if ( $ item -> equals ( $ existingItem ) ) { $ existingItem -> merge ( $ item , false ) ; $ this -> itemsTotal = null ; $ this -> total = null ; return $ this ; } } $ item -> setContainer ( $ this ) ; $ this -> items -> add ( $ item ) ; $ this -> itemsTotal = null ; $ this -> total = null ; return $ this ; }
Add an item
7,618
public function removeItem ( PricedItemInterface $ item ) { if ( $ this -> hasItem ( $ item ) ) { $ item -> setContainer ( null ) ; $ this -> items -> removeElement ( $ item ) ; $ this -> itemsTotal = null ; $ this -> total = null ; } return $ this ; }
Remove a given item
7,619
public function calculateItemsTotal ( ) { $ itemsTotal = 0 ; foreach ( $ this -> items as $ item ) { $ itemsTotal += $ item -> getTotal ( ) ; } $ this -> itemsTotal = $ itemsTotal ; return $ this ; }
Calculate the total price for all the items
7,620
public function calculateTotal ( ) { $ this -> total = $ this -> getItemsTotal ( ) + $ this -> getAdjustmentTotal ( ) ; if ( $ this -> total < 0 ) { $ this -> total = 0 ; } return $ this ; }
Calculate the total amount for the whole container
7,621
public function serve401 ( ) { $ response = new Response ( ) ; $ response -> setStatusCode ( Response :: HTTP_UNAUTHORIZED ) ; return $ this -> render ( 'Errors/401' , [ ] , $ response ) ; }
Affichage page 401
7,622
public function serve404 ( ) { $ response = new Response ( ) ; $ response -> setStatusCode ( Response :: HTTP_NOT_FOUND ) ; return $ this -> render ( 'Errors/404' , [ ] , $ response ) ; }
Affichage page 404
7,623
public function serve503 ( ) { $ response = new Response ( ) ; $ response -> setStatusCode ( Response :: HTTP_SERVICE_UNAVAILABLE ) ; $ response -> headers -> set ( 'Retry-After' , 3600 ) ; return $ this -> render ( 'Errors/503' , [ ] , $ response ) ; }
Affichage page 503
7,624
public function removeTrailingSlash ( ) { $ pathInfo = $ this -> app [ 'request' ] -> getPathInfo ( ) ; $ requestUri = $ this -> app [ 'request' ] -> getRequestUri ( ) ; $ url = str_replace ( $ pathInfo , rtrim ( $ pathInfo , ' /' ) , $ requestUri ) ; return $ this -> redirect ( $ url , Response :: HTTP_MOVED_PERMANENTLY ) ; }
Remove trailing slash and redirect permanent
7,625
public function repair_expression ( $ exp ) { $ commands = explode ( ' ' , $ exp ) ; $ commands = array_filter ( $ commands , function ( $ value ) { return ! is_null ( $ value ) ; } ) ; if ( in_array ( $ commands [ 0 ] , $ this -> bracket_starting_commands ) ) { if ( $ commands [ 0 ] == 'each' ) { $ commands [ 0 ] = 'foreach' ; } elseif ( $ commands [ 0 ] == 'loop' ) { $ commands [ 0 ] = 'for' ; $ commands [ 1 ] = '$i=0;$i<' . $ commands [ 1 ] . ';$i++' ; } end ( $ commands ) ; $ key = key ( $ commands ) ; if ( substr ( $ commands [ $ key ] , - 1 ) == ':' ) { $ commands [ $ key ] = substr ( $ commands [ $ key ] , 0 , - 1 ) ; if ( $ commands [ $ key ] == ' ' || empty ( $ commands [ $ key ] ) ) { unset ( $ commands [ $ key ] ) ; } } if ( substr ( $ commands [ 1 ] , 0 , 1 ) != '(' ) { $ commands [ 1 ] = '( ' . $ commands [ 1 ] ; end ( $ commands ) ; $ key = key ( $ commands ) ; $ commands [ $ key ] .= ' )' ; } $ commands [ ] = ':' ; } elseif ( count ( $ commands == 1 ) && in_array ( $ commands [ 0 ] , $ this -> bracket_ending_commands ) ) { if ( $ commands [ 0 ] == 'endeach' ) { $ commands [ 0 ] = 'endforeach' ; } elseif ( $ commands [ 0 ] == 'endloop' ) { $ commands [ 0 ] = 'endfor' ; } if ( substr ( $ commands [ 0 ] , 0 , 1 ) != ';' ) { $ commands [ 0 ] .= ';' ; } } elseif ( count ( $ commands == 1 ) && in_array ( $ commands [ 0 ] , $ this -> bracket_continue_commands ) ) { end ( $ commands ) ; $ key = key ( $ commands ) ; if ( substr ( $ commands [ $ key ] , - 1 ) == ':' ) { $ commands [ $ key ] = substr ( $ commands [ $ key ] , 0 , - 1 ) ; if ( $ commands [ $ key ] == ' ' || empty ( $ commands [ $ key ] ) ) { unset ( $ commands [ $ key ] ) ; } } $ commands [ ] = ':' ; } return implode ( ' ' , $ commands ) ; }
Repair an expression
7,626
private function compile_phptag ( $ view ) { $ that = $ this ; return preg_replace_callback ( '/\{\%(.*?)\%\}/s' , function ( $ match ) use ( $ that ) { $ expression = trim ( $ match [ 1 ] ) ; $ expression = $ that -> repair_expression ( $ expression ) ; return '<?php ' . $ expression . ' ?>' ; } , $ view ) ; }
Search and replace for shortcuts of the php tag
7,627
private function compile_arrays ( $ view ) { $ tokens = token_get_all ( $ view ) ; $ tags = array ( 0 => '' ) ; $ tag_index = 0 ; $ in_tag = false ; foreach ( $ tokens as $ token ) { if ( is_array ( $ token ) ) { if ( $ token [ 0 ] === T_OPEN_TAG ) { $ in_tag = true ; } if ( $ in_tag && ! in_array ( $ token [ 0 ] , array ( T_INLINE_HTML ) ) ) { $ tags [ $ tag_index ] .= $ token [ 1 ] ; } if ( $ token [ 0 ] === T_CLOSE_TAG ) { $ in_tag = false ; $ tag_index ++ ; } } else { if ( $ in_tag ) { $ tags [ $ tag_index ] .= $ token ; } } } $ tags = array_flip ( $ tags ) ; foreach ( $ tags as $ search => & $ replace ) { $ replace = preg_replace_callback ( '/(\$[a-zA-Z0-9\_\.\-\>\;]+)/s' , function ( $ match ) { $ var = $ match [ 1 ] ; if ( strpos ( $ var , '.' ) !== false ) { $ buffer = '' ; $ length = strlen ( $ var ) ; $ inside_arr = false ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ char = $ var [ $ i ] ; if ( $ char == '.' && ! $ inside_arr ) { $ buffer .= "['" ; $ inside_arr = true ; } else { if ( $ inside_arr && in_array ( $ char , array ( ';' , '-' , ',' ) ) ) { $ buffer .= "']" ; $ inside_arr = false ; } if ( $ char == '.' ) { $ buffer .= "']['" ; $ inside_arr = true ; } else { $ buffer .= $ char ; } } } if ( $ inside_arr ) { $ buffer .= "']" ; } $ var = $ buffer ; } return $ var ; } , $ search ) ; } return CCStr :: replace ( $ view , $ tags ) ; }
Search and replace vars with . array access
7,628
protected function performInsert ( Builder $ query ) { $ encryptedFields = static :: getEncryptedFields ( ) ; if ( count ( $ encryptedFields ) && ! $ this -> getEncryptKey ( ) ) { throw new \ RuntimeException ( "No encryption key specified" ) ; } $ originalAttributes = $ this -> attributes ; foreach ( $ encryptedFields as $ encryptedField ) { if ( isset ( $ this -> attributes [ $ encryptedField ] ) ) { $ this -> attributes [ $ encryptedField ] = DB :: raw ( static :: getEncryptionService ( ) -> getEncryptExpression ( $ this -> attributes [ $ encryptedField ] , static :: getEncryptKey ( ) ) ) ; } } $ inserted = parent :: performInsert ( $ query ) ; foreach ( $ encryptedFields as $ encryptedField ) { if ( isset ( $ this -> attributes [ $ encryptedField ] ) ) { $ this -> attributes [ $ encryptedField ] = $ originalAttributes [ $ encryptedField ] ; } } return $ inserted ; }
Perform insert with encryption
7,629
protected function newBaseQueryBuilder ( ) { $ connection = $ this -> getConnection ( ) ; return new DatabaseEncryptionQueryBuilder ( $ connection , $ connection -> getQueryGrammar ( ) , $ connection -> getPostProcessor ( ) ) ; }
Get a new query builder instance for the connection . Use the package s DatabaseEncryptionQueryBuilder .
7,630
public static function installed_ships ( ) { $ ships = static :: $ data -> get ( 'installed' , array ( ) ) ; foreach ( $ ships as $ key => $ ship ) { $ ships [ $ key ] = CCROOT . $ ship ; } return $ ships ; }
return all installed ships
7,631
public static function enter ( $ path ) { if ( ! is_array ( $ path ) ) { $ path = array ( $ path ) ; } foreach ( $ path as $ ship ) { $ ship = CCOrbit_Ship :: create ( $ ship ) ; if ( array_key_exists ( $ ship -> name , static :: $ ships ) ) { throw new CCException ( "CCOrbit::enter - {$ship->name} ship already entered." ) ; } if ( $ ship -> wake !== false ) { $ ship -> event ( $ ship -> wake ) ; } CCProfiler :: check ( "CCOrbit - ship {$ship->name} launched." ) ; static :: $ ships [ $ ship -> name ] = $ ship ; } }
Add a ship this loads the ship loader file
7,632
public function setId ( $ givenId ) { if ( ! isset ( $ this -> id ) ) { $ this -> id = $ givenId ; } return $ this -> id ; }
Set id of model .
7,633
public function dump ( ) { $ attributes = array ( ) ; if ( $ this -> id ) { $ attributes [ '$id' ] = $ this -> id ; } foreach ( $ this -> attributes as $ key => $ value ) { $ schema = $ this -> schema ( $ key ) ; if ( ! empty ( $ schema [ 'transient' ] ) ) { continue ; } $ attributes [ $ key ] = $ value ; } return $ attributes ; }
Dump attributes raw data .
7,634
public function add ( $ key , $ value ) { if ( ! isset ( $ this -> attributes [ $ key ] ) ) { $ this -> attributes [ $ key ] = array ( ) ; } $ this -> attributes [ $ key ] [ ] = $ value ; return $ this ; }
Add an attributes data .
7,635
public function clear ( $ key = null ) { if ( func_num_args ( ) === 0 ) { $ this -> attributes = array ( ) ; } elseif ( $ key === '$id' ) { throw new Exception ( '[Norm/Model] Restricting clear for $id.' ) ; } else { unset ( $ this -> attributes [ $ key ] ) ; } return $ this ; }
Clear attributes value .
7,636
public function sync ( $ attributes ) { if ( isset ( $ attributes [ '$id' ] ) ) { $ this -> state = static :: STATE_ATTACHED ; $ this -> id = $ attributes [ '$id' ] ; } else { foreach ( $ this -> schema ( ) as $ key => $ field ) { if ( $ field -> has ( 'default' ) ) { $ attributes [ $ key ] = $ field [ 'default' ] ; } } $ this -> state = static :: STATE_DETACHED ; } $ this -> set ( $ attributes ) ; $ this -> populateOld ( ) ; }
Sync the existing attributes with new values . After update or insert this method used to modify the existing attributes .
7,637
public function prepare ( $ key , $ value , $ schema = null ) { if ( $ this -> collection ) { return $ this -> collection -> prepare ( $ key , $ value , $ schema ) ; } else { return $ value ; } }
Prepare model to be sync d .
7,638
public function toArray ( $ fetchType = Model :: FETCH_ALL ) { if ( $ fetchType === Model :: FETCH_RAW ) { return $ this -> attributes ; } $ attributes = array ( ) ; if ( empty ( $ this -> attributes ) ) { $ this -> attributes = array ( ) ; } if ( $ fetchType === Model :: FETCH_ALL or $ fetchType === Model :: FETCH_HIDDEN ) { $ attributes [ '$type' ] = $ this -> getClass ( ) ; $ attributes [ '$id' ] = $ this -> getId ( ) ; foreach ( $ this -> attributes as $ key => $ value ) { if ( $ key [ 0 ] === '$' ) { $ attributes [ $ key ] = $ value ; } } } if ( $ fetchType === Model :: FETCH_ALL or $ fetchType === Model :: FETCH_PUBLISHED ) { foreach ( $ this -> attributes as $ key => $ value ) { if ( $ key [ 0 ] !== '$' ) { $ attributes [ $ key ] = $ value ; } } } return $ attributes ; }
Get array structure of model
7,639
public function jsonSerialize ( ) { if ( ! Norm :: options ( 'include' ) ) { return $ this -> toArray ( ) ; } $ destination = array ( ) ; $ source = $ this -> toArray ( ) ; $ schema = $ this -> collection -> schema ( ) ; foreach ( $ source as $ key => $ value ) { if ( isset ( $ schema [ $ key ] ) and isset ( $ value ) ) { $ destination [ $ key ] = $ schema [ $ key ] -> toJSON ( $ value ) ; } else { $ destination [ $ key ] = $ value ; } $ destination [ $ key ] = JsonKit :: replaceObject ( $ destination [ $ key ] ) ; } return $ destination ; }
Implement the json serializer normalizing the data structures .
7,640
public function previous ( $ key = null ) { if ( is_null ( $ key ) ) { return $ this -> oldAttributes ; } return $ this -> oldAttributes [ $ key ] ; }
Get original attributes
7,641
public function schemaByIndex ( $ index ) { $ schema = array ( ) ; foreach ( $ this -> collection -> schema ( ) as $ value ) { $ schema [ ] = $ value ; } return ( empty ( $ schema [ $ index ] ) ) ? null : $ schema [ $ index ] ; }
Get schema configuration by offset name .
7,642
public function format ( $ field = null , $ format = null ) { $ numArgs = func_num_args ( ) ; if ( $ numArgs === 0 ) { $ formatter = $ this -> collection -> option ( 'format' ) ; if ( is_null ( $ formatter ) ) { $ schema = $ this -> schemaByIndex ( 0 ) ; if ( ! is_null ( $ schema ) ) { return ( isset ( $ this [ $ schema [ 'name' ] ] ) ) ? val ( $ this [ $ schema [ 'name' ] ] ) : null ; } else { return '-- no formatter and schema --' ; } } else { if ( $ formatter instanceof Closure ) { return $ formatter ( $ this ) ; } elseif ( is_string ( $ formatter ) ) { $ result = preg_replace_callback ( '/{(\w+)}/' , function ( $ matches ) { return $ this -> format ( $ matches [ 1 ] ) ; } , $ formatter ) ; return $ result ; } else { throw new Exception ( 'Unknown format for Model formatter.' ) ; } } } else { $ format = $ format ? : 'plain' ; $ schema = $ this -> schema ( $ field ) ; if ( is_null ( $ schema ) ) { throw new Exception ( "[Norm/Model] No formatter [$format] for field [$field]." ) ; } else { $ value = isset ( $ this [ $ field ] ) ? val ( $ this [ $ field ] ) : null ; return $ schema -> format ( $ format , $ value , $ this ) ; } } }
Format the model to HTML file . Bind it s attributes to view .
7,643
public function endBodyToolbar ( ) { $ this -> _setBeginning ( false ) ; $ toolbar = trim ( ob_get_clean ( ) ) ; if ( is_string ( $ this -> bodyToolbar ) ) { $ this -> bodyToolbar = [ $ this -> bodyToolbar ] ; } $ this -> bodyToolbar [ ] = [ 'body' => $ toolbar , 'options' => $ this -> _bodyToolbarLastOptions , ] ; $ this -> _bodyToolbarLastOptions = [ ] ; }
End Body Toolbar
7,644
private function _getBodyToolbar ( ) { if ( $ this -> bodyToolbar !== null ) { Html :: addCssClass ( $ this -> bodyToolbarOptions , 'widget-body-toolbar' ) ; $ toolbars = is_string ( $ this -> bodyToolbar ) ? [ $ this -> bodyToolbar ] : $ this -> bodyToolbar ; foreach ( $ toolbars as $ toolbar ) { if ( is_array ( $ toolbar ) ) { $ body = isset ( $ toolbar [ 'body' ] ) ? $ toolbar [ 'body' ] : null ; $ options = isset ( $ toolbar [ 'options' ] ) ? $ toolbar [ 'options' ] : [ ] ; Html :: addCssClass ( $ options , 'widget-body-toolbar' ) ; echo Html :: tag ( 'div' , $ body , $ options ) ; } else { echo Html :: tag ( 'div' , $ toolbar , $ this -> bodyToolbarOptions ) ; } } } }
Get body toolbar
7,645
private function getFromConst ( $ line ) { $ eq_pos = strpos ( $ line , '=' ) ; $ semicolon_pos = strrpos ( $ line , ';' ) ; $ constant_name = trim ( substr ( $ line , 6 , $ eq_pos - 6 ) ) ; $ value = trim ( substr ( $ line , $ eq_pos + 1 , $ semicolon_pos - $ eq_pos - 1 ) ) ; return [ $ constant_name , $ this -> getNativeValueFromDefinition ( $ value ) ] ; }
Return single option from const DB_XYZ defition line
7,646
public function getOptionNameFromDefinition ( $ constant_name ) { if ( $ this -> strStartsWith ( $ constant_name , "'" ) && $ this -> strEndsWith ( $ constant_name , "'" ) ) { return trim ( trim ( $ constant_name , "'" ) ) ; } else { if ( $ this -> strStartsWith ( $ constant_name , '"' ) && $ this -> strEndsWith ( $ constant_name , '"' ) ) { return trim ( trim ( $ constant_name , '"' ) ) ; } else { return $ constant_name ; } } }
Return config option name from defintiion string
7,647
private function getNativeValueFromDefinition ( $ value ) { if ( $ this -> strStartsWith ( $ value , "'" ) && $ this -> strEndsWith ( $ value , "'" ) ) { $ value = trim ( trim ( $ value , "'" ) ) ; } else { if ( $ this -> strStartsWith ( $ value , '"' ) && $ this -> strEndsWith ( $ value , '"' ) ) { $ value = trim ( trim ( $ value , '"' ) ) ; } else { if ( $ value == 'true' ) { $ value = true ; } else { if ( $ value == 'false' ) { $ value = false ; } else { if ( is_numeric ( $ value ) ) { if ( ctype_digit ( $ value ) ) { return ( integer ) $ value ; } else { return ( float ) $ value ; } } } } } } return $ value ; }
Cast declared value to internal type
7,648
private function strStartsWith ( $ string , $ niddle ) { return mb_strtolower ( substr ( $ string , 0 , mb_strlen ( $ niddle ) ) ) == mb_strtolower ( $ niddle ) ; }
Case insensitive string begins with
7,649
private function strEndsWith ( $ string , $ niddle ) { return mb_substr ( $ string , mb_strlen ( $ string ) - mb_strlen ( $ niddle ) , mb_strlen ( $ niddle ) ) == $ niddle ; }
Case insensitive string ends with
7,650
public static function vCard ( $ name , $ address = '' , $ locality = '' , $ state = '' , $ zip = '' , $ email = '' ) { $ items = array ( ) ; $ items [ ] = \ CHtml :: tag ( 'li' , array ( 'class' => 'fn' ) , $ name ) ; $ items [ ] = \ CHtml :: tag ( 'li' , array ( 'class' => 'street-address' ) , $ address ) ; $ items [ ] = \ CHtml :: tag ( 'li' , array ( 'class' => 'locality' ) , $ locality ) ; $ sub = array ( ) ; $ sub [ ] = \ CHtml :: tag ( 'span' , array ( 'class' => 'state' ) , $ state ) ; $ sub [ ] = \ CHtml :: tag ( 'span' , array ( 'class' => 'zip' ) , $ zip ) ; $ items [ ] = \ CHtml :: tag ( 'li' , array ( ) , implode ( ", " , $ sub ) ) ; $ items [ ] = \ CHtml :: tag ( 'li' , array ( 'class' => 'email' ) , $ email ) ; return \ CHtml :: tag ( 'ul' , array ( 'class' => 'vcard' ) , implode ( "\n" , $ items ) ) ; }
Renders a handy microformat - friendly list for addresses
7,651
public static function inlineList ( $ items , $ htmlOptions = array ( ) ) { $ listItems = array ( ) ; Html :: addCssClass ( $ htmlOptions , 'inline-list' ) ; foreach ( $ items as $ item ) { $ listItems [ ] = \ CHtml :: tag ( 'li' , $ htmlOptions , $ item ) ; } if ( ! empty ( $ listItems ) ) { return \ CHtml :: tag ( 'ul' , $ htmlOptions , implode ( "\n" , $ listItems ) ) ; } }
Renders and inline list
7,652
public static function label ( $ text , $ htmlOptions = array ( ) ) { ArrayHelper :: addValue ( 'class' , 'label' , $ htmlOptions ) ; return \ CHtml :: tag ( 'span' , $ htmlOptions , $ text ) ; }
Renders a Foundation label
7,653
protected function modelHasBeenSaved ( $ saved , $ type , $ request ) { if ( ! $ saved ) { return response ( ) -> json ( [ 'message' => 'Failed to ' . $ type . ' resource' , 'code' => 422 ] , 422 ) ; } $ status = $ request -> ajax ( ) ? 202 : 200 ; if ( $ request -> ajax ( ) ) { return response ( ) -> json ( [ 'message' => 'Successfully ' . $ type . ' resource' , 'code' => $ status ] , $ status ) ; } if ( $ request -> has ( '_redirect' ) ) { return $ this -> returnRedirect ( 'Successfully ' . $ type . ' resource' , $ request ) ; } return redirect ( ) -> back ( ) -> with ( [ 'message' => 'Successfully ' . $ type . ' resource' ] ) ; }
This method handles how submitted quests are handle the main related methods for it are POST and .
7,654
public function validatePut ( $ input , $ model , $ model_name ) { return collect ( $ input ) -> filter ( function ( $ value , $ key ) use ( $ model , $ input ) { if ( ! isset ( $ value ) || $ key === '_token' ) { return false ; } if ( isset ( $ model -> $ key ) ) { if ( $ model -> $ key === $ value ) { return false ; } } if ( $ this -> doesModelRelate ( $ model , $ key , $ value ) ) { return false ; } if ( ( ( stripos ( $ key , 'password' ) !== false ) || ( stripos ( $ key , 'passwd' ) !== false ) ) && ! empty ( $ model -> $ key ) ) { if ( \ Hash :: check ( $ value , $ model -> $ key ) ) { return false ; } else { $ user_model = config ( 'kregel.warden.models.user.model' ) ; $ user = new $ user_model ( ) ; if ( empty ( $ user -> hashable ) ) { $ input [ $ key ] = bcrypt ( $ value ) ; return true ; } } } return true ; } ) ; }
This Checks for any values and the _token for csrf and removes it from any blank values and it also removes the _token from the input . If there is a password within the request it will compare it to the current hash .
7,655
private function resolveOrder ( $ routes , $ order ) { if ( isset ( $ routes [ $ order ] ) ) { return $ this -> resolveOrder ( $ routes , $ order + 1 ) ; } else { return $ order ; } }
recursive function to resolve the order of a array of routes . If the order chosen in routing . yml is already in used find the first next order available .
7,656
static public function normaliseValues ( $ array ) { $ array = self :: arrayize ( $ array ) ; if ( ! $ array ) return $ array ; $ minValue = min ( $ array ) ; $ maxValue = max ( $ array ) ; if ( $ maxValue == $ minValue ) { $ minValue -= 1 ; } foreach ( $ array as $ index => $ value ) { $ array [ $ index ] = ( $ value - $ minValue ) / ( $ maxValue - $ minValue ) ; } return $ array ; }
Normalizuje hodnoty v poli do rozsahu &lt ; 0 - 1&gt ;
7,657
public static function get_by_email ( $ email_address ) { $ mysql = bootstrap :: get_library ( 'mysql' ) ; $ sql = "SELECT * FROM `login_passwords` WHERE `email_address` = '%s';" ; $ login = $ mysql :: select ( 'row' , $ sql , $ email_address ) ; if ( empty ( $ login ) ) { return false ; } return new static ( $ login [ 'id' ] ) ; }
checks whether the given email address match one on file
7,658
public function is_valid ( $ password , $ check_rehash = true ) { if ( password_verify ( $ password , $ this -> data [ 'hash' ] ) == false ) { return false ; } if ( $ check_rehash && password_needs_rehash ( $ this -> data [ 'hash' ] , PASSWORD_DEFAULT ) ) { $ new_hash = self :: hash_password ( $ password ) ; $ this -> set_new_hash ( $ this -> data [ 'user_id' ] , $ this -> data [ 'email_address' ] , $ new_hash ) ; } return true ; }
check if the password gives access to the login also re - hashes the password hash if the algorithm is out of date
7,659
public function add ( $ user_id , $ email_address , $ password ) { $ mysql = bootstrap :: get_library ( 'mysql' ) ; $ sql = "INSERT INTO `login_passwords` SET `user_id` = %d, `email_address` = '%s';" ; $ binds = [ $ user_id , $ email_address ] ; $ mysql :: query ( $ sql , $ binds ) ; $ login = new static ( $ mysql :: $ insert_id ) ; $ hash = self :: hash_password ( $ password ) ; $ login -> set_new_hash ( $ hash ) ; }
adds a login
7,660
public function set_new_hash ( $ new_hash ) { $ mysql = bootstrap :: get_library ( 'mysql' ) ; $ sql = "UPDATE `login_passwords` SET `hash` = '%s' WHERE `id` = %d;" ; $ binds = [ $ new_hash , $ this -> data [ 'id' ] ] ; $ mysql :: query ( $ sql , $ binds ) ; $ this -> data [ 'hash' ] = $ new_hash ; }
stores a new hash for the current login
7,661
public static function hash_password ( $ password ) { $ exception = bootstrap :: get_library ( 'exception' ) ; if ( mb_strlen ( $ password ) < self :: MINIMUM_LENGTH ) { throw new $ exception ( 'passwords need a minimum length of ' . self :: MINIMUM_LENGTH ) ; } $ hash = password_hash ( $ password , PASSWORD_DEFAULT ) ; if ( empty ( $ hash ) ) { throw new $ exception ( 'unable to hash password' ) ; } return $ hash ; }
generates a new hash for the given password we wrap the native method to ensure a successful hash
7,662
public function requirementsAction ( ) { $ sAppPath = $ this -> getParameter ( 'kernel.root_dir' ) ; require_once $ sAppPath . '/SymfonyRequirements.php' ; $ symfonyRequirements = new \ SymfonyRequirements ( ) ; $ symfonyRequirements -> addRequirement ( extension_loaded ( 'mcrypt' ) , "Check if mcrypt ist loaded for RSA encryption" , "Please enable mcrypt-Extension. See <a href='http://php.net/manual/de/mcrypt.setup.php'>http://php.net/manual/de/mcrypt.setup.php</a>" ) ; $ aRequirements = $ symfonyRequirements -> getRequirements ( ) ; $ aRecommendations = $ symfonyRequirements -> getRecommendations ( ) ; $ aFailedRequirements = $ symfonyRequirements -> getFailedRequirements ( ) ; $ aFailedRecommendations = $ symfonyRequirements -> getFailedRecommendations ( ) ; $ iniPath = $ symfonyRequirements -> getPhpIniConfigPath ( ) ; return $ this -> render ( 'SlashworksBackendBundle:Install:requirements.html.twig' , array ( "iniPath" => $ iniPath , "requirements" => $ aRequirements , "recommendations" => $ aRecommendations , "failedrequirements" => $ aFailedRequirements , "failedrecommendations" => $ aFailedRecommendations ) ) ; }
Check System Requirements
7,663
public function installAction ( ) { $ form = $ this -> createForm ( new InstallType ( ) , null , array ( 'action' => $ this -> generateUrl ( 'install_process' ) ) ) ; if ( $ this -> container -> getParameter ( 'database_password' ) !== null ) { return $ this -> redirect ( $ this -> generateUrl ( 'login' ) ) ; } else { return $ this -> render ( 'SlashworksBackendBundle:Install:install.html.twig' , array ( "error" => false , "errorMessage" => false , "form" => $ form -> createView ( ) ) ) ; } }
Display install form
7,664
public function processInstallAction ( Request $ request ) { $ sAppPath = $ this -> getParameter ( 'kernel.root_dir' ) ; require_once $ sAppPath . '/SymfonyRequirements.php' ; if ( $ this -> container -> getParameter ( 'database_password' ) !== null ) { return $ this -> redirect ( $ this -> generateUrl ( 'login' ) ) ; } $ form = $ this -> createForm ( new InstallType ( ) , null , array ( 'action' => $ this -> generateUrl ( 'install_process' ) ) ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { try { $ aData = $ request -> request -> all ( ) ; InstallHelper :: doInstall ( $ this -> container , $ aData ) ; return $ this -> redirect ( $ this -> generateUrl ( 'login' ) ) ; } catch ( \ Exception $ e ) { return $ this -> render ( 'SlashworksBackendBundle:Install:install.html.twig' , array ( "form" => $ form -> createView ( ) , "error" => true , "errorMessage" => $ e -> getMessage ( ) ) ) ; } } else { return $ this -> render ( 'SlashworksBackendBundle:Install:install.html.twig' , array ( "form" => $ form -> createView ( ) , "error" => true , "errorMessage" => false ) ) ; } }
Process provided informations and perform installation
7,665
public static function getVar ( $ name , $ default = null , $ hash = 'default' , $ type = 'none' , $ mask = 0 ) { $ hash = strtoupper ( $ hash ) ; if ( $ hash === 'METHOD' ) { $ hash = strtoupper ( $ _SERVER [ 'REQUEST_METHOD' ] ) ; } $ type = strtoupper ( $ type ) ; $ sig = $ hash . $ type . $ mask ; switch ( $ hash ) { case 'GET' : $ input = & $ _GET ; break ; case 'POST' : $ input = & $ _POST ; break ; case 'FILES' : $ input = & $ _FILES ; break ; case 'COOKIE' : $ input = & $ _COOKIE ; break ; case 'ENV' : $ input = & $ _ENV ; break ; case 'SERVER' : $ input = & $ _SERVER ; break ; default : $ input = & $ _REQUEST ; $ hash = 'REQUEST' ; break ; } if ( isset ( $ GLOBALS [ '_JREQUEST' ] [ $ name ] [ 'SET.' . $ hash ] ) && ( $ GLOBALS [ '_JREQUEST' ] [ $ name ] [ 'SET.' . $ hash ] === true ) ) { $ var = ( isset ( $ input [ $ name ] ) && $ input [ $ name ] !== null ) ? $ input [ $ name ] : $ default ; $ var = self :: _cleanVar ( $ var , $ mask , $ type ) ; } elseif ( ! isset ( $ GLOBALS [ '_JREQUEST' ] [ $ name ] [ $ sig ] ) ) { if ( isset ( $ input [ $ name ] ) && $ input [ $ name ] !== null ) { $ var = self :: _cleanVar ( $ input [ $ name ] , $ mask , $ type ) ; $ GLOBALS [ '_JREQUEST' ] [ $ name ] [ $ sig ] = $ var ; } elseif ( $ default !== null ) { $ var = self :: _cleanVar ( $ default , $ mask , $ type ) ; } else { $ var = $ default ; } } else { $ var = $ GLOBALS [ '_JREQUEST' ] [ $ name ] [ $ sig ] ; } return $ var ; }
Fetches and returns a given variable .
7,666
public static function get ( $ hash = 'default' , $ mask = 0 ) { $ hash = strtoupper ( $ hash ) ; if ( $ hash === 'METHOD' ) { $ hash = strtoupper ( $ _SERVER [ 'REQUEST_METHOD' ] ) ; } switch ( $ hash ) { case 'GET' : $ input = $ _GET ; break ; case 'POST' : $ input = $ _POST ; break ; case 'FILES' : $ input = $ _FILES ; break ; case 'COOKIE' : $ input = $ _COOKIE ; break ; case 'ENV' : $ input = & $ _ENV ; break ; case 'SERVER' : $ input = & $ _SERVER ; break ; default : $ input = $ _REQUEST ; break ; } $ result = self :: _cleanVar ( $ input , $ mask ) ; return $ result ; }
Fetches and returns a request array .
7,667
public static function set ( $ array , $ hash = 'default' , $ overwrite = true ) { foreach ( $ array as $ key => $ value ) { self :: setVar ( $ key , $ value , $ hash , $ overwrite ) ; } }
Sets a request variable .
7,668
protected static function _cleanVar ( $ var , $ mask = 0 , $ type = null ) { if ( ! ( $ mask & 1 ) && is_string ( $ var ) ) { $ var = trim ( $ var ) ; } if ( $ mask & 2 ) { $ var = $ var ; } elseif ( $ mask & 4 ) { $ safeHtmlFilter = JFilterInput :: getInstance ( null , null , 1 , 1 ) ; $ var = $ safeHtmlFilter -> clean ( $ var , $ type ) ; } else { $ noHtmlFilter = JFilterInput :: getInstance ( ) ; $ var = $ noHtmlFilter -> clean ( $ var , $ type ) ; } return $ var ; }
Clean up an input variable .
7,669
public function dpi ( EntityMeta $ entityMeta , DCPackage $ dc ) { $ this -> entityMeta = $ entityMeta ; $ this -> dc = $ dc ; return $ this ; }
EntityMeta der Bild - Klasse
7,670
function modify ( & $ tpl , & $ operatorName , & $ operatorParameters , & $ rootNamespace , & $ currentNamespace , & $ operatorValue , & $ namedParameters ) { switch ( $ operatorName ) { case 'opengraph' : { $ operatorValue = $ this -> generateOpenGraphTags ( $ namedParameters [ 'nodeid' ] ) ; break ; } case 'language_code' : { $ operatorValue = eZLocale :: instance ( ) -> httpLocaleCode ( ) ; break ; } } }
Executes the operators
7,671
function generateOpenGraphTags ( $ nodeID ) { $ this -> ogIni = eZINI :: instance ( 'ngopengraph.ini' ) ; $ this -> facebookCompatible = $ this -> ogIni -> variable ( 'General' , 'FacebookCompatible' ) ; $ this -> debug = $ this -> ogIni -> variable ( 'General' , 'Debug' ) == 'enabled' ; $ availableClasses = $ this -> ogIni -> variable ( 'General' , 'Classes' ) ; if ( $ nodeID instanceof eZContentObjectTreeNode ) { $ contentNode = $ nodeID ; } else { $ contentNode = eZContentObjectTreeNode :: fetch ( $ nodeID ) ; if ( ! $ contentNode instanceof eZContentObjectTreeNode ) { return array ( ) ; } } $ contentObject = $ contentNode -> object ( ) ; if ( ! $ contentObject instanceof eZContentObject || ! in_array ( $ contentObject -> contentClassIdentifier ( ) , $ availableClasses ) ) { return array ( ) ; } $ returnArray = $ this -> processGenericData ( $ contentNode ) ; $ returnArray = $ this -> processObject ( $ contentObject , $ returnArray ) ; if ( $ this -> checkRequirements ( $ returnArray ) ) { return $ returnArray ; } else { if ( $ this -> debug ) { eZDebug :: writeDebug ( 'No' , 'Facebook Compatible?' ) ; } return array ( ) ; } }
Executes opengraph operator
7,672
function processGenericData ( $ contentNode ) { $ returnArray = array ( ) ; $ siteName = trim ( eZINI :: instance ( ) -> variable ( 'SiteSettings' , 'SiteName' ) ) ; if ( ! empty ( $ siteName ) ) { $ returnArray [ 'og:site_name' ] = $ siteName ; } $ urlAlias = $ contentNode -> urlAlias ( ) ; eZURI :: transformURI ( $ urlAlias , false , 'full' ) ; $ returnArray [ 'og:url' ] = $ urlAlias ; if ( $ this -> facebookCompatible == 'true' ) { $ appID = trim ( $ this -> ogIni -> variable ( 'GenericData' , 'app_id' ) ) ; if ( ! empty ( $ appID ) ) { $ returnArray [ 'fb:app_id' ] = $ appID ; } $ defaultAdmin = trim ( $ this -> ogIni -> variable ( 'GenericData' , 'default_admin' ) ) ; $ data = '' ; if ( ! empty ( $ defaultAdmin ) ) { $ data = $ defaultAdmin ; $ admins = $ this -> ogIni -> variable ( 'GenericData' , 'admins' ) ; if ( ! empty ( $ admins ) ) { $ admins = trim ( implode ( ',' , $ admins ) ) ; $ data = $ data . ',' . $ admins ; } } if ( ! empty ( $ data ) ) { $ returnArray [ 'fb:admins' ] = $ data ; } } return $ returnArray ; }
Processes literal Open Graph metadata
7,673
function processObject ( $ contentObject , $ returnArray ) { if ( $ this -> ogIni -> hasVariable ( $ contentObject -> contentClassIdentifier ( ) , 'LiteralMap' ) ) { $ literalValues = $ this -> ogIni -> variable ( $ contentObject -> contentClassIdentifier ( ) , 'LiteralMap' ) ; if ( $ this -> debug ) { eZDebug :: writeDebug ( $ literalValues , 'LiteralMap' ) ; } if ( $ literalValues ) { foreach ( $ literalValues as $ key => $ value ) { if ( ! empty ( $ value ) ) { $ returnArray [ $ key ] = $ value ; } } } } if ( $ this -> ogIni -> hasVariable ( $ contentObject -> contentClassIdentifier ( ) , 'AttributeMap' ) ) { $ attributeValues = $ this -> ogIni -> variableArray ( $ contentObject -> contentClassIdentifier ( ) , 'AttributeMap' ) ; if ( $ this -> debug ) { eZDebug :: writeDebug ( $ attributeValues , 'AttributeMap' ) ; } if ( $ attributeValues ) { foreach ( $ attributeValues as $ key => $ value ) { $ contentObjectAttributeArray = $ contentObject -> fetchAttributesByIdentifier ( array ( $ value [ 0 ] ) ) ; if ( ! is_array ( $ contentObjectAttributeArray ) ) { continue ; } $ contentObjectAttributeArray = array_values ( $ contentObjectAttributeArray ) ; $ contentObjectAttribute = $ contentObjectAttributeArray [ 0 ] ; if ( $ contentObjectAttribute instanceof eZContentObjectAttribute ) { $ openGraphHandler = ngOpenGraphBase :: getInstance ( $ contentObjectAttribute ) ; if ( count ( $ value ) == 1 ) { $ data = $ openGraphHandler -> getData ( ) ; } else if ( count ( $ value ) == 2 ) { $ data = $ openGraphHandler -> getDataMember ( $ value [ 1 ] ) ; } else { $ data = "" ; } if ( ! empty ( $ data ) ) { $ returnArray [ $ key ] = $ data ; } } } } } return $ returnArray ; }
Processes Open Graph metadata from object attributes
7,674
function checkRequirements ( $ returnArray ) { $ arrayKeys = array_keys ( $ returnArray ) ; if ( ! in_array ( 'og:title' , $ arrayKeys ) || ! in_array ( 'og:type' , $ arrayKeys ) || ! in_array ( 'og:image' , $ arrayKeys ) || ! in_array ( 'og:url' , $ arrayKeys ) ) { if ( $ this -> debug ) { eZDebug :: writeError ( $ arrayKeys , 'Missing an OG required field: title, image, type, or url' ) ; } return false ; } if ( $ this -> facebookCompatible == 'true' ) { if ( ! in_array ( 'og:site_name' , $ arrayKeys ) || ( ! in_array ( 'fb:app_id' , $ arrayKeys ) && ! in_array ( 'fb:admins' , $ arrayKeys ) ) ) { if ( $ this -> debug ) { eZDebug :: writeError ( $ arrayKeys , 'Missing a FB required field (in ngopengraph.ini): app_id, DefaultAdmin, or site name (site.ini)' ) ; } return false ; } } return true ; }
Checks if all required Open Graph metadata are present
7,675
public function scanFilesInPath ( $ sourcePath ) { $ filePattern = $ this -> filePattern ; if ( strpos ( $ sourcePath , str_replace ( '*' , null , $ filePattern ) ) ) { $ filePattern = $ this -> coverFishHelper -> getFileNameFromPath ( $ sourcePath ) ; } $ facade = new FinderFacade ( array ( $ sourcePath ) , $ this -> filePatternExclude , array ( $ filePattern ) ) ; return $ this -> removeExcludedPath ( $ facade -> findFiles ( ) , $ this -> testExcludePath ) ; }
scan all files by given path recursively if one php file will be provided within given path this file will be returned in finder format
7,676
public static function & getAuth ( $ instance ) { static $ instances ; if ( ! isset ( $ instances ) ) { $ instances = array ( ) ; } if ( ! isset ( $ instances [ $ instance ] ) ) { $ name = static :: getNameFromInstance ( $ instance ) ; static :: pluginAutoLoad ( $ name ) ; $ class = '\JFusion\Plugins\\' . $ name . '\Auth' ; if ( ! class_exists ( $ class ) ) { $ class = '\JFusion\Plugin\Auth' ; } $ instances [ $ instance ] = new $ class ( $ instance ) ; } return $ instances [ $ instance ] ; }
Gets an Authentication Class for the JFusion Plugin
7,677
public static function & getUser ( $ instance ) { static $ instances ; if ( ! isset ( $ instances ) ) { $ instances = array ( ) ; } if ( ! isset ( $ instances [ $ instance ] ) ) { $ name = static :: getNameFromInstance ( $ instance ) ; static :: pluginAutoLoad ( $ name ) ; $ class = '\JFusion\Plugins\\' . $ name . '\User' ; if ( ! class_exists ( $ class ) ) { $ class = '\JFusion\Plugin\User' ; } $ instances [ $ instance ] = new $ class ( $ instance ) ; } return $ instances [ $ instance ] ; }
Gets an User Class for the JFusion Plugin
7,678
public static function & getPlatform ( $ platform , $ instance ) { static $ instances ; if ( ! isset ( $ instances ) ) { $ instances = array ( ) ; } $ platform = ucfirst ( strtolower ( $ platform ) ) ; if ( ! isset ( $ instances [ $ platform ] [ $ instance ] ) ) { $ name = static :: getNameFromInstance ( $ instance ) ; static :: pluginAutoLoad ( $ name ) ; $ class = '\JFusion\Plugins\\' . $ name . '\Platform\\' . $ platform . '\\Platform' ; if ( ! class_exists ( $ class ) ) { $ class = '\JFusion\Plugin\Platform\\' . $ platform ; } if ( ! class_exists ( $ class ) ) { $ class = '\JFusion\Plugin\Platform' ; } $ instances [ $ platform ] [ $ instance ] = new $ class ( $ instance ) ; } return $ instances [ $ platform ] [ $ instance ] ; }
Gets a Forum Class for the JFusion Plugin
7,679
public static function & getHelper ( $ instance ) { static $ instances ; if ( ! isset ( $ instances ) ) { $ instances = array ( ) ; } if ( ! isset ( $ instances [ $ instance ] ) ) { $ name = static :: getNameFromInstance ( $ instance ) ; static :: pluginAutoLoad ( $ name ) ; $ class = '\JFusion\Plugins\\' . $ name . '\Helper' ; if ( ! class_exists ( $ class ) ) { $ instances [ $ instance ] = false ; } else { $ instances [ $ instance ] = new $ class ( $ instance ) ; } } return $ instances [ $ instance ] ; }
Gets a Helper Class for the JFusion Plugin which is only used internally by the plugin
7,680
public static function & getDatabase ( $ jname ) { static $ instances ; if ( ! isset ( $ instances ) ) { $ instances = array ( ) ; } if ( ! isset ( $ instances [ $ jname ] ) ) { if ( $ jname == 'joomla_int' ) { $ db = self :: getDBO ( ) ; } else { $ params = static :: getParams ( $ jname ) ; $ host = $ params -> get ( 'database_host' ) ; $ user = $ params -> get ( 'database_user' ) ; $ password = $ params -> get ( 'database_password' ) ; $ database = $ params -> get ( 'database_name' ) ; $ prefix = $ params -> get ( 'database_prefix' , '' ) ; $ driver = $ params -> get ( 'database_type' ) ; $ charset = $ params -> get ( 'database_charset' , 'utf8' ) ; $ options = array ( 'driver' => $ driver , 'host' => $ host , 'user' => $ user , 'password' => $ password , 'database' => $ database , 'prefix' => $ prefix ) ; $ db = DatabaseFactory :: getInstance ( ) -> getDriver ( $ driver , $ options ) ; if ( $ driver != 'sqlite' ) { $ db -> setQuery ( 'SET names ' . $ db -> quote ( $ charset ) ) ; $ db -> execute ( ) ; } $ db -> setDebug ( Config :: get ( ) -> get ( 'debug' ) ) ; } $ instances [ $ jname ] = $ db ; } return $ instances [ $ jname ] ; }
Gets an Database Connection for the JFusion Plugin
7,681
public static function & getParams ( $ jname , $ reset = false ) { static $ instances ; if ( ! isset ( $ instances ) ) { $ instances = array ( ) ; } try { if ( ! isset ( $ instances [ $ jname ] ) || $ reset ) { $ db = self :: getDBO ( ) ; $ query = $ db -> getQuery ( true ) -> select ( 'params' ) -> from ( '#__jfusion' ) -> where ( 'name = ' . $ db -> quote ( $ jname ) ) ; $ db -> setQuery ( $ query ) ; $ params = $ db -> loadResult ( ) ; $ instances [ $ jname ] = new Registry ( $ params ) ; } return $ instances [ $ jname ] ; } catch ( Exception $ e ) { return new Registry ( ) ; } }
Gets an Parameter Object for the JFusion Plugin
7,682
public static function getPlugins ( $ criteria = 'both' , $ exclude = false , $ status = 2 ) { static $ instances ; if ( ! isset ( $ instances ) ) { $ instances = array ( ) ; } $ db = self :: getDBO ( ) ; $ query = $ db -> getQuery ( true ) -> select ( '*' ) -> from ( '#__jfusion' ) ; $ key = $ criteria . '_' . $ exclude . '_' . $ status ; if ( ! isset ( $ instances [ $ key ] ) ) { if ( $ exclude !== false ) { $ query -> where ( 'name NOT LIKE ' . $ db -> quote ( $ exclude ) ) ; } $ query -> where ( 'status >= ' . ( int ) $ status ) ; $ query -> order ( 'ordering' ) ; $ db -> setQuery ( $ query ) ; $ list = $ db -> loadObjectList ( ) ; switch ( $ criteria ) { case 'slave' : if ( isset ( $ list [ 0 ] ) ) { unset ( $ list [ 0 ] ) ; } break ; case 'master' : if ( isset ( $ list [ 0 ] ) ) { $ list = $ list [ 0 ] ; } else { $ list = null ; } break ; } $ instances [ $ key ] = $ list ; } return $ instances [ $ key ] ; }
returns array of plugins depending on the arguments
7,683
public static function getPluginNodeId ( $ jname ) { $ params = static :: getParams ( $ jname ) ; $ source_url = $ params -> get ( 'source_url' ) ; return strtolower ( rtrim ( parse_url ( $ source_url , PHP_URL_HOST ) . parse_url ( $ source_url , PHP_URL_PATH ) , '/' ) ) ; }
Gets the jnode_id for the JFusion Plugin
7,684
public static function & getCookies ( ) { static $ instance ; if ( ! isset ( $ instance ) ) { $ instance = new Cookies ( Config :: get ( ) -> get ( 'apikey' ) ) ; } return $ instance ; }
Gets an JFusion cross domain cookie object
7,685
public static function getDbo ( ) { if ( ! self :: $ database ) { $ host = Config :: get ( ) -> get ( 'database.host' ) ; $ user = Config :: get ( ) -> get ( 'database.user' ) ; $ password = Config :: get ( ) -> get ( 'database.password' ) ; $ database = Config :: get ( ) -> get ( 'database.name' ) ; $ prefix = Config :: get ( ) -> get ( 'database.prefix' ) ; $ driver = Config :: get ( ) -> get ( 'database.driver' ) ; $ debug = Config :: get ( ) -> get ( 'database.debug' ) ; $ options = array ( 'driver' => $ driver , 'host' => $ host , 'user' => $ user , 'password' => $ password , 'database' => $ database , 'prefix' => $ prefix ) ; self :: $ database = DatabaseFactory :: getInstance ( ) -> getDriver ( $ driver , $ options ) ; self :: $ database -> setDebug ( Config :: get ( ) -> get ( 'debug' ) ) ; } return self :: $ database ; }
Get a database object .
7,686
public static function getLanguage ( ) { if ( ! self :: $ language ) { $ locale = Config :: get ( ) -> get ( 'language.language' ) ; $ debug = Config :: get ( ) -> get ( 'language.debug' ) ; self :: $ language = Language :: getInstance ( $ locale , $ debug ) ; Text :: setLanguage ( self :: $ language ) ; } return self :: $ language ; }
Get a language object .
7,687
public static function _init ( ) { static :: filter ( 'any' , '[a-zA-Z0-9' . ClanCats :: $ config -> get ( 'router.allowed_special_chars' ) . ']' ) ; static :: filter ( 'num' , '[0-9]' ) ; static :: filter ( 'alpha' , '[a-zA-Z]' ) ; static :: filter ( 'alphanum' , '[a-zA-Z0-9]' ) ; CCRouter :: on ( '#404' , function ( ) { return CCResponse :: create ( CCView :: create ( 'Core::CCF/404' ) -> render ( ) , 404 ) ; } ) ; }
Set up the basic uri filters in our static init and also add a default 404 response
7,688
public static function alias ( $ key , $ to = null ) { if ( is_null ( $ to ) || is_array ( $ to ) ) { if ( array_key_exists ( $ key , static :: $ aliases ) ) { if ( is_array ( $ to ) ) { $ return = static :: $ aliases [ $ key ] ; foreach ( $ to as $ rpl ) { $ return = preg_replace ( "/\[\w+\]/" , $ rpl , $ return , 1 ) ; } return $ return ; } return static :: $ aliases [ $ key ] ; } return false ; } static :: $ aliases [ $ key ] = $ to ; }
Creates an alias to a route or gets one
7,689
public static function events_matching ( $ event , $ rule ) { if ( ! array_key_exists ( $ event , static :: $ events ) ) { return array ( ) ; } $ callbacks = array ( ) ; foreach ( static :: $ events [ $ event ] as $ route => $ events ) { $ rgx = "~^" . str_replace ( '*' , '(.*)' , $ route ) . "$~" ; if ( preg_match ( $ rgx , $ rule ) ) { $ callbacks = array_merge ( $ callbacks , $ events ) ; } } return $ callbacks ; }
Get all events matching a rule
7,690
protected static function prepare ( $ routes ) { if ( ClanCats :: $ config -> get ( 'router.flatten_routes' ) ) { $ routes = static :: flatten ( $ routes ) ; } foreach ( $ routes as $ uri => $ route ) { if ( is_string ( $ route ) ) { if ( substr ( $ route , 0 , 1 ) == '#' ) { $ route = static :: $ privates [ $ route ] ; } } if ( strpos ( $ uri , '@' ) !== false ) { if ( $ uri [ 0 ] == '@' ) { static :: $ aliases [ substr ( $ uri , 1 ) ] = $ route ; } else { list ( $ uri , $ alias ) = explode ( '@' , $ uri ) ; static :: $ aliases [ $ alias ] = $ uri ; } } if ( substr ( $ uri , 0 , 1 ) == '#' ) { static :: $ privates [ $ uri ] = $ route ; } else { static :: $ routes [ $ uri ] = $ route ; } } }
Prepare the routes assing them to their containers
7,691
protected static function flatten ( $ routes , $ param_prefix = '' ) { $ flattened = array ( ) ; foreach ( $ routes as $ prefix => $ route ) { if ( is_array ( $ route ) && ! is_callable ( $ route ) ) { $ flattened = array_merge ( static :: flatten ( $ route , $ param_prefix . $ prefix . '/' ) , $ flattened ) ; } else { if ( $ prefix == '/' ) { $ prefix = '' ; $ param_prefix = substr ( $ param_prefix , 0 , - 1 ) ; $ flattened [ $ param_prefix . $ prefix ] = $ route ; $ param_prefix .= '/' ; } else { $ flattened [ $ param_prefix . $ prefix ] = $ route ; } } } return $ flattened ; }
Flatten the routes
7,692
protected static function configure ( $ route , $ raw_route ) { if ( is_null ( $ raw_route ) ) { return false ; } if ( is_string ( $ raw_route ) ) { if ( strpos ( $ raw_route , '?' ) !== false ) { $ route -> params = explode ( ',' , CCStr :: suffix ( $ raw_route , '?' ) ) ; $ raw_route = CCStr :: cut ( $ raw_route , '?' ) ; } if ( strpos ( $ raw_route , '@' ) !== false ) { $ route -> action = CCStr :: suffix ( $ raw_route , '@' ) ; $ raw_route = CCStr :: cut ( $ raw_route , '@' ) ; } $ controller = CCController :: create ( $ raw_route ) ; $ route -> callback = array ( $ controller , 'execute' ) ; } elseif ( is_callable ( $ raw_route ) ) { $ route -> callback = $ raw_route ; } return $ route ; }
Check and complete a route
7,693
protected function selectionHandler ( ) { $ userCount = count ( $ this -> choices ) ; if ( $ userCount > static :: MAX_USER_CHOICES ) { $ this -> autocomplete ( ) ; } elseif ( $ userCount > 1 ) { $ this -> selector ( ) ; } elseif ( 1 === $ userCount ) { $ this -> editor ( $ this -> choices [ 0 ] ) ; } }
Handle user selection depending on options and user count in db
7,694
protected function selector ( & $ choices = null ) { $ choices = $ choices ? $ choices : $ this -> choices ; $ choices = $ this -> userEditor -> getChoicesAsEmailUsername ( $ choices ) ; $ question = new ChoiceQuestion ( static :: PLEASE_SELECT_A_USER , $ choices ) ; $ selectedUser = $ this -> ask ( $ question ) ; $ user = $ this -> getChoiceBySelection ( $ selectedUser ) ; if ( $ user ) { $ this -> editor ( $ user ) ; } }
Multiple choices user select
7,695
protected function autocomplete ( ) { $ question = new Question ( static :: PLEASE_SELECT_A_USER ) ; $ question -> setAutocompleterValues ( $ this -> userEditor -> getChoicesAsSeparateEmailUsername ( $ this -> choices ) ) ; $ selectedUser = $ this -> ask ( $ question ) ; if ( '' === $ selectedUser ) { return ; } $ user = $ this -> getChoiceByUsernameOrEmail ( $ selectedUser ) ; if ( ! is_null ( $ user ) ) { $ this -> editor ( $ user ) ; } else { $ choices = $ this -> userEditor -> getChoices ( $ selectedUser , $ selectedUser , true , static :: MAX_USER_CHOICES ) ; $ this -> selector ( $ choices ) ; } }
Autocomplete user select
7,696
protected function editor ( User $ user ) { $ oldProps = new UserUpdater ( $ user ) ; $ newProps = $ this -> getNewValues ( $ user ) ; $ ln = <<<EOLSummary-------Username: "{$newProps->getUsername()}"Email: "{$newProps->getEmail()}"Password: "{$newProps->getPassword()}"EOL ; $ this -> logger -> block ( $ ln ) ; $ changedValues = $ oldProps -> getChanged ( $ newProps ) ; if ( empty ( $ changedValues ) ) { $ this -> logger -> note ( 'Nothing changed, exiting.' ) ; return ; } if ( $ persist = $ this -> ask ( new ConfirmationQuestion ( 'Confirm user update?' ) ) ) { $ this -> userEditor -> updateUser ( $ user , $ newProps ) ; $ this -> logger -> success ( 'User updated!' ) ; } if ( $ persist ) { $ dontSend = 'Don\'t send' ; $ emailChoices = [ $ dontSend , $ oldProps -> getEmail ( ) ] ; if ( isset ( $ changedValues [ 'email' ] ) ) { $ emailChoices [ ] = $ changedValues [ 'email' ] ; } $ to = $ this -> ask ( new ChoiceQuestion ( 'Send notification to' , $ emailChoices ) ) ; if ( $ to !== $ dontSend ) { $ this -> sendNotification ( $ to , $ changedValues ) ; } } }
Show user editor
7,697
protected function sendNotification ( $ to , array $ changedValues ) { $ message = \ Swift_Message :: newInstance ( ) -> setSubject ( 'User details updated' ) -> setFrom ( $ this -> getContainer ( ) -> getParameter ( 'fos_user.resetting.email.from_email' ) ) -> setTo ( $ to ) -> setBody ( $ this -> getContainer ( ) -> get ( 'twig' ) -> render ( '@WebtownKunstmaanExtension/email/user_edit.html.twig' , [ 'changes' => $ changedValues ] ) , 'text/html' ) ; $ this -> getContainer ( ) -> get ( 'mailer' ) -> send ( $ message ) ; }
Send email notification about changes
7,698
protected function getChoiceBySelection ( $ selection ) { preg_match ( '/^[^(]+\(([^\)]+)\)$/' , $ selection , $ matches ) ; if ( count ( $ matches ) < 2 ) { return ; } $ username = $ matches [ 1 ] ; foreach ( $ this -> choices as $ item ) { if ( $ item -> getUsername ( ) === $ username ) { return $ item ; } } return ; }
Find User by username
7,699
protected function getChoiceByUsernameOrEmail ( $ selection ) { foreach ( $ this -> choices as $ item ) { if ( $ item -> getUsername ( ) === $ selection ) { return $ item ; } if ( $ item -> getEmail ( ) === $ selection ) { return $ item ; } } return ; }
Find User by username or email