idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
10,700
public function delete_user_option ( string $ id_option , string $ id_user = null ) : ? int { if ( $ id_option = $ this -> _get_id_option ( $ id_option ) ) { return $ this -> db -> delete ( $ this -> class_cfg [ 'table' ] , [ $ this -> fields [ 'id_option' ] => $ id_option , $ this -> fields [ 'id_user' ] => $ id_user ? : $ this -> id_user ] ) ; } return null ; }
Deletes all the given or current user s permissions for the given option
10,701
public function delete_group_option ( string $ id_option , string $ id_group ) : ? int { if ( $ id_option = $ this -> _get_id_option ( $ id_option ) ) { return $ this -> db -> delete ( $ this -> class_cfg [ 'table' ] , [ $ this -> fields [ 'id_option' ] => $ id_option , $ this -> fields [ 'id_group' ] => $ id_group ] ) ; } return null ; }
Deletes all the given group s permissions for the given option
10,702
public function get_shared ( string $ id ) : ? array { if ( bbn \ str :: is_uid ( $ id ) ) { return $ this -> db -> rselect_all ( $ this -> class_table , [ $ this -> fields [ 'id' ] , $ this -> fields [ 'id_user' ] , $ this -> fields [ 'id_group' ] ] , [ $ this -> fields [ 'id_alias' ] => $ id ] ) ; } return null ; }
Returns an array
10,703
public function add_bit ( string $ id_usr_opt , array $ cfg ) : ? string { if ( ( $ id_usr_opt = $ this -> _get_id_option ( $ id_usr_opt ) ) && ( $ c = $ this -> class_cfg [ 'arch' ] [ 'user_options_bits' ] ) ) { $ to_cfg = $ this -> get_bit_cfg ( null , $ cfg ) ; if ( isset ( $ to_cfg [ 'items' ] ) ) { unset ( $ to_cfg [ 'items' ] ) ; } if ( ! empty ( $ to_cfg ) ) { if ( ! empty ( $ cfg [ $ c [ 'cfg' ] ] ) ) { if ( \ bbn \ str :: is_json ( $ cfg [ $ c [ 'cfg' ] ] ) ) { $ cfg [ $ c [ 'cfg' ] ] = json_decode ( $ cfg [ $ c [ 'cfg' ] ] , true ) ; } if ( \ is_array ( $ cfg [ $ c [ 'cfg' ] ] ) ) { $ cfg [ $ c [ 'cfg' ] ] = array_merge ( $ cfg [ $ c [ 'cfg' ] ] , $ to_cfg ) ; } else { $ cfg [ $ c [ 'cfg' ] ] = $ to_cfg ; } } else { $ cfg [ $ c [ 'cfg' ] ] = $ to_cfg ; } $ cfg [ $ c [ 'cfg' ] ] = json_encode ( $ cfg [ $ c [ 'cfg' ] ] ) ; } if ( $ this -> db -> insert ( $ this -> class_cfg [ 'tables' ] [ 'user_options_bits' ] , [ $ c [ 'id_user_option' ] => $ id_usr_opt , $ c [ 'id_parent' ] => $ cfg [ $ c [ 'id_parent' ] ] ?? NULL , $ c [ 'id_option' ] => $ cfg [ $ c [ 'id_option' ] ] ?? NULL , $ c [ 'num' ] => $ cfg [ $ c [ 'num' ] ] ?? NULL , $ c [ 'text' ] => $ cfg [ $ c [ 'text' ] ] ?? '' , $ c [ 'cfg' ] => $ cfg [ $ c [ 'cfg' ] ] ?? '' , ] ) ) { return $ this -> db -> last_id ( ) ; } } return null ; }
Adds a bit to a preference
10,704
public function delete_bit ( string $ id ) : ? int { if ( \ bbn \ str :: is_uid ( $ id ) ) { return $ this -> db -> delete ( $ this -> class_cfg [ 'tables' ] [ 'user_options_bits' ] , [ $ this -> class_cfg [ 'arch' ] [ 'user_options_bits' ] [ 'id' ] => $ id ] ) ; } return null ; }
Deletes a preference s bit
10,705
public function update_bit ( string $ id , array $ cfg , $ merge_config = false ) : ? int { if ( \ bbn \ str :: is_uid ( $ id ) ) { $ c = $ this -> class_cfg [ 'arch' ] [ 'user_options_bits' ] ; $ fields = array_values ( $ c ) ; if ( \ array_key_exists ( $ c [ 'id' ] , $ cfg ) ) { unset ( $ cfg [ $ c [ 'id' ] ] ) ; } $ to_cfg = $ this -> get_bit_cfg ( null , $ cfg ) ; if ( isset ( $ to_cfg [ 'items' ] ) ) { unset ( $ to_cfg [ 'items' ] ) ; } if ( ! empty ( $ to_cfg ) ) { if ( ! empty ( $ merge_config ) && ! empty ( $ cfg [ $ c [ 'cfg' ] ] ) ) { if ( \ bbn \ str :: is_json ( $ cfg [ $ c [ 'cfg' ] ] ) ) { $ cfg [ $ c [ 'cfg' ] ] = json_decode ( $ cfg [ $ c [ 'cfg' ] ] , true ) ; } if ( \ is_array ( $ cfg [ $ c [ 'cfg' ] ] ) ) { $ cfg [ $ c [ 'cfg' ] ] = array_merge ( $ cfg [ $ c [ 'cfg' ] ] , $ to_cfg ) ; } else { $ cfg [ $ c [ 'cfg' ] ] = $ to_cfg ; } } else { $ cfg [ $ c [ 'cfg' ] ] = $ to_cfg ; } $ cfg [ $ c [ 'cfg' ] ] = json_encode ( $ cfg [ $ c [ 'cfg' ] ] ) ; } return $ this -> db -> update ( $ this -> class_cfg [ 'tables' ] [ 'user_options_bits' ] , [ $ c [ 'id_parent' ] => $ cfg [ $ c [ 'id_parent' ] ] ?? NULL , $ c [ 'id_option' ] => $ cfg [ $ c [ 'id_option' ] ] ?? NULL , $ c [ 'num' ] => $ cfg [ $ c [ 'num' ] ] ?? NULL , $ c [ 'text' ] => $ cfg [ $ c [ 'text' ] ] ?? '' , $ c [ 'cfg' ] => $ cfg [ $ c [ 'cfg' ] ] ?? '' , ] , [ $ c [ 'id' ] => $ id ] ) ; } return null ; }
Updates a preference s bit
10,706
public function get_bit ( string $ id , bool $ with_config = true ) : array { if ( \ bbn \ str :: is_uid ( $ id ) && ( $ bit = $ this -> db -> rselect ( $ this -> class_cfg [ 'tables' ] [ 'user_options_bits' ] , [ ] , [ $ this -> class_cfg [ 'arch' ] [ 'user_options_bits' ] [ 'id' ] => $ id ] ) ) ) { if ( ! empty ( $ with_config ) ) { return $ this -> explode_bit_cfg ( $ bit ) ; } return $ bit ; } return [ ] ; }
Returns a single preference s bit
10,707
public function get_bits ( string $ id_usr_opt , $ id_parent = false , bool $ with_config = true ) : array { $ c = $ this -> class_cfg [ 'arch' ] [ 'user_options_bits' ] ; $ t = $ this ; $ where = [ $ c [ 'id_user_option' ] => $ id_usr_opt ] ; if ( is_null ( $ id_parent ) || \ bbn \ str :: is_uid ( $ id_parent ) ) { $ where [ $ c [ 'id_parent' ] ] = $ id_parent ; } if ( \ bbn \ str :: is_uid ( $ id_usr_opt ) && ( $ bits = $ this -> db -> rselect_all ( $ this -> class_cfg [ 'tables' ] [ 'user_options_bits' ] , [ ] , $ where , [ $ c [ 'num' ] => 'ASC' ] ) ) ) { if ( ! empty ( $ with_config ) ) { return array_map ( function ( $ b ) use ( $ t ) { return $ t -> explode_bit_cfg ( $ b ) ; } , $ bits ) ; } return $ bits ; } return [ ] ; }
Returns the bits list of a preference
10,708
public function get_full_bits ( string $ id_usr_opt , string $ id_parent = null , bool $ with_config = true ) : array { if ( \ bbn \ str :: is_uid ( $ id_usr_opt ) ) { $ c = $ this -> class_cfg [ 'arch' ] [ 'user_options_bits' ] ; $ t = $ this ; return array_map ( function ( $ b ) use ( $ t , $ c , $ id_usr_opt , $ with_config ) { if ( ! empty ( $ with_config ) ) { $ b = $ t -> explode_bit_cfg ( $ b ) ; } $ b [ 'items' ] = $ t -> get_full_bits ( $ id_usr_opt , $ b [ $ c [ 'id' ] ] , $ with_config ) ; return $ b ; } , $ this -> db -> rselect_all ( [ 'table' => $ this -> class_cfg [ 'tables' ] [ 'user_options_bits' ] , 'fields' => [ ] , 'where' => [ 'conditions' => [ [ 'field' => $ c [ 'id_user_option' ] , 'value' => $ id_usr_opt ] , [ 'field' => $ c [ 'id_parent' ] , empty ( $ id_parent ) ? 'operator' : 'value' => $ id_parent ? : 'isnull' ] ] ] , 'order' => [ $ c [ 'num' ] => 'ASC' ] ] ) ) ; } return [ ] ; }
Returns the hierarchical bits list of a preference
10,709
public function get_tree ( string $ id , bool $ with_config = true ) : array { if ( \ bbn \ str :: is_uid ( $ id ) && ( $ p = $ this -> get ( $ id , $ with_config ) ) ) { $ p [ 'items' ] = $ this -> get_full_bits ( $ id , null , $ with_config ) ; return $ p ; } return [ ] ; }
Returns a preference and its hierarchical bits list
10,710
public function order_bit ( string $ id , int $ pos ) : ? bool { if ( \ bbn \ str :: is_uid ( $ id ) && ( $ cf = $ this -> get_class_cfg ( ) ) && ( $ cfg = $ cf [ 'arch' ] [ 'user_options_bits' ] ) && ( $ bit = $ this -> get_bit ( $ id ) ) && ( $ old = ( int ) $ bit [ $ cfg [ 'num' ] ] ) && ! empty ( $ pos ) && ( $ old !== $ pos ) && ( $ bits = $ this -> get_bits ( $ bit [ $ cfg [ 'id_user_option' ] ] , $ bit [ $ cfg [ 'id_parent' ] ] ? : false ) ) ) { $ past_new = false ; $ past_old = false ; $ p = 1 ; $ changed = 0 ; foreach ( $ bits as $ ele ) { $ upd = [ ] ; if ( $ past_old && ! $ past_new ) { $ upd [ $ cfg [ 'num' ] ] = $ p - 1 ; } else if ( ! $ past_old && $ past_new ) { $ upd [ $ cfg [ 'num' ] ] = $ p + 1 ; } if ( $ id === $ ele [ 'id' ] ) { $ upd [ $ cfg [ 'num' ] ] = $ pos ; $ past_old = 1 ; } else if ( $ p === $ pos ) { $ upd [ $ cfg [ 'num' ] ] = $ p + ( $ pos > $ old ? - 1 : 1 ) ; $ past_new = 1 ; } if ( ! empty ( $ upd ) ) { $ changed += $ this -> db -> update ( $ cf [ 'tables' ] [ 'user_options_bits' ] , $ upd , [ $ cfg [ 'id' ] => $ ele [ 'id' ] ] ) ; } if ( $ past_new && $ past_old ) { break ; } $ p ++ ; } return ! ! $ changed ; } return null ; }
Orders a bit .
10,711
public function move_bit ( string $ id , string $ id_parent = null ) : ? bool { if ( \ bbn \ str :: is_uid ( $ id ) && ( ( \ bbn \ str :: is_uid ( $ id_parent ) && $ this -> get_bit ( $ id_parent ) ) || \ is_null ( $ id_parent ) ) && ( $ bit = $ this -> get_bit ( $ id ) ) && ( $ cf = $ this -> get_class_cfg ( ) ) && ( $ cfg = $ cf [ 'arch' ] [ 'user_options_bits' ] ) ) { $ upd = [ $ cfg [ 'id_parent' ] => $ id_parent , $ cfg [ 'num' ] => $ this -> get_max_bit_num ( $ bit [ $ cfg [ 'id_user_option' ] ] , $ id_parent , true ) ] ; return ! ! $ this -> db -> update ( $ cf [ 'tables' ] [ 'user_options_bits' ] , $ upd , [ $ cfg [ 'id' ] => $ id ] ) ; } return null ; }
Moves a bit .
10,712
public function get_max_bit_num ( string $ id_user_option , string $ id_parent = null , bool $ incr = false ) : int { if ( \ bbn \ str :: is_uid ( $ id_user_option ) && ( \ bbn \ str :: is_uid ( $ id_parent ) || is_null ( $ id_parent ) ) && ( $ cf = $ this -> get_class_cfg ( ) ) && ( $ cfg = $ cf [ 'arch' ] [ 'user_options_bits' ] ) ) { if ( $ max = $ this -> db -> select_one ( [ 'table' => $ cf [ 'tables' ] [ 'user_options_bits' ] , 'fields' => [ "MAX($cfg[num])" ] , 'where' => [ 'conditions' => [ [ 'field' => $ cfg [ 'id_user_option' ] , 'value' => $ id_user_option ] , [ 'field' => $ cfg [ 'id_parent' ] , empty ( $ id_parent ) ? 'operator' : 'value' => $ id_parent ? : 'isnull' ] ] ] ] ) ) { $ max = ( int ) $ max ; return $ incr ? $ max + 1 : $ max ; } return 0 ; } }
Gets the maximum num value of the user option s bits .
10,713
public function get_by_bit ( string $ id ) : ? array { $ t = & $ this ; if ( \ bbn \ str :: is_uid ( $ id ) ) { return $ this -> db -> rselect ( [ 'table' => $ this -> class_cfg [ 'table' ] , 'fields' => array_map ( function ( $ v ) use ( $ t ) { return $ this -> class_cfg [ 'table' ] . '.' . $ v ; } , array_values ( $ this -> class_cfg [ 'arch' ] [ 'user_options' ] ) ) , 'join' => [ [ 'table' => $ this -> class_cfg [ 'tables' ] [ 'user_options_bits' ] , 'on' => [ 'conditions' => [ [ 'field' => $ this -> class_cfg [ 'arch' ] [ 'user_options_bits' ] [ 'id_user_option' ] , 'exp' => $ this -> class_cfg [ 'table' ] . '.' . $ this -> fields [ 'id' ] ] ] ] ] ] , 'where' => [ $ this -> class_cfg [ 'tables' ] [ 'user_options_bits' ] . '.' . $ this -> class_cfg [ 'arch' ] [ 'user_options_bits' ] [ 'id' ] => $ id ] ] ) ; } }
Gets a preference row from a bit ID
10,714
public function get_id_by_bit ( string $ id ) : ? string { if ( \ bbn \ str :: is_uid ( $ id ) && ( $ p = $ this -> get_by_bit ( $ id ) ) ) { return $ p [ $ this -> fields [ 'id' ] ] ; } return null ; }
Gets the preference s ID from a bit ID
10,715
private function selectRestVersion ( $ channelXml , $ supportedVersions ) { $ channelXml -> registerXPathNamespace ( 'ns' , self :: CHANNEL_NS ) ; foreach ( $ supportedVersions as $ version ) { $ xpathTest = "ns:servers/ns:primary/ns:rest/ns:baseurl[@type='{$version}']" ; $ testResult = $ channelXml -> xpath ( $ xpathTest ) ; if ( count ( $ testResult ) > 0 ) { return array ( 'version' => $ version , 'baseUrl' => ( string ) $ testResult [ 0 ] ) ; } } return null ; }
Reads channel supported REST interfaces and selects one of them
10,716
public function get ( $ id ) { return $ this -> _sendPayload ( $ this -> _getService ( $ this -> _pageServiceKey ) -> getActiveTemplateSections ( $ id ) ) ; }
Get template sections
10,717
public function update ( $ id , $ data ) { $ sections = empty ( $ data [ 'sections' ] ) ? [ ] : $ data [ 'sections' ] ; return $ this -> _sendPayload ( $ this -> _getService ( $ this -> _pageServiceKey ) -> updateTemplateSections ( $ id , $ sections ) ) ; }
Update section details
10,718
public function getRowUrl ( $ item ) { if ( ! $ item instanceof Varien_Object ) { return parent :: getRowUrl ( $ item ) ; } $ rowUrlRoute = trim ( $ this -> getRowUrlRoute ( ) ) ; if ( empty ( $ rowUrlRoute ) ) { return parent :: getRowUrl ( $ item ) ; } $ params = [ ] ; $ rowUrlParams = $ this -> getRowUrlParams ( ) ; $ rowUrlParams = ( is_array ( $ rowUrlParams ) ? $ rowUrlParams : explode ( ',' , $ rowUrlParams ) ) ; $ rowUrlParams = array_filter ( array_map ( 'trim' , $ rowUrlParams ) ) ; foreach ( $ rowUrlParams as $ key => $ value ) { if ( strpos ( $ value , '{{' ) === 0 && strrpos ( $ value , '}}' ) === ( strlen ( $ value ) - 2 ) ) { $ value = $ item -> getDataUsingMethod ( substr ( $ value , 2 , - 2 ) ) ; } $ params [ $ key ] = $ value ; } $ rowUrlQueryParams = $ this -> getRowUrlQueryParams ( ) ; $ rowUrlQueryParams = ( is_array ( $ rowUrlQueryParams ) ? $ rowUrlQueryParams : explode ( ',' , $ rowUrlQueryParams ) ) ; $ rowUrlQueryParams = array_filter ( array_map ( 'trim' , $ rowUrlQueryParams ) ) ; foreach ( $ rowUrlQueryParams as $ key => $ value ) { if ( strpos ( $ value , '{{' ) === 0 && strrpos ( $ value , '}}' ) === ( strlen ( $ value ) - 2 ) ) { $ value = $ item -> getDataUsingMethod ( substr ( $ value , 1 , - 1 ) ) ; } $ params [ '_query' ] [ $ key ] = $ value ; } return $ this -> getUrl ( $ rowUrlRoute , $ params ) ; }
Return row url for js event handlers
10,719
public function sortColumnsByOrder ( ) { $ columns = $ this -> _columns ; foreach ( $ this -> getColumnsOrder ( ) as $ columnId => $ after ) { if ( $ after [ 0 ] === '-' ) { $ before = substr ( $ after , 1 ) ; $ after = null ; } else { $ before = null ; } if ( $ after !== null && isset ( $ columns [ $ after ] ) ) { $ currentPosition = array_search ( $ columnId , array_keys ( $ columns ) ) ; $ value = array_splice ( $ columns , $ currentPosition , 1 ) ; $ destPosition = array_search ( $ after , array_keys ( $ columns ) ) + 1 ; $ columns = array_slice ( $ columns , 0 , $ destPosition ) + $ value + array_slice ( $ columns , $ destPosition ) ; } elseif ( $ before !== null && $ columns [ $ before ] ) { $ currentPosition = array_search ( $ columnId , array_keys ( $ columns ) ) ; $ value = array_splice ( $ columns , $ currentPosition , 1 ) ; $ destPosition = array_search ( $ before , array_keys ( $ columns ) ) ; $ columns = array_slice ( $ columns , 0 , $ destPosition ) + $ value + array_slice ( $ columns , $ destPosition ) ; } } $ this -> _columns = $ columns ; end ( $ this -> _columns ) ; $ this -> _lastColumnId = key ( $ this -> _columns ) ; return $ this ; }
Sort columns by predefined order
10,720
public function updateColumn ( $ columnId , $ key , $ value ) { if ( isset ( $ this -> _columns [ $ columnId ] ) && $ this -> _columns [ $ columnId ] instanceof Varien_Object ) { $ this -> _columns [ $ columnId ] -> setData ( $ key , $ value ) ; } return $ this ; }
Modify grid column
10,721
public function getCurrentProject ( ) { return $ this -> createInstance ( $ this -> environment -> getProjectType ( ) , $ this -> environment , $ this -> configuration , $ this -> fileSystem ) ; }
Get a project plugin for the current environment settings .
10,722
public function getKeyValue ( $ key ) { return empty ( $ this -> _data [ $ key ] ) ? null : $ this -> _data [ $ key ] ; }
Get data value by key
10,723
public function setThemeTemplate ( $ template ) { $ this -> _themeTemplate = $ template ; if ( $ this -> getTheme ( ) != null ) { $ this -> getTheme ( ) -> setTemplate ( $ this -> _themeTemplate ) ; } }
Set Theme Template
10,724
public function getProcessedFields ( ) { return [ 'page' => $ this -> getPage ( ) , 'perPage' => $ this -> getPerPage ( ) , 'filter' => $ this -> filter , 'orderBy' => $ this -> orderBy , 'query' => $ this -> searchQuery ] ; }
Returns array with all processed fields
10,725
private function processFilterParams ( $ key , $ param ) { $ this -> filter [ ] = [ $ key , '=' , ( is_numeric ( $ param ) ) ? ( float ) $ param : $ param ] ; }
Process filter params
10,726
public function draw ( $ text , $ size = 12 , $ x = 0 , $ y = 0 ) { imagettftext ( $ this -> image , $ size , $ this -> rotation , $ x , $ y , $ this -> text_color , $ this -> font , $ text ) ; return $ this -> image ; }
Draws the text onto the image
10,727
final public static function get_instance ( array $ setting = [ ] ) { $ class_name = get_called_class ( ) ; if ( ! isset ( self :: $ instances [ $ class_name ] ) ) { self :: $ instances [ $ class_name ] = new $ class_name ( $ setting ) ; } return self :: $ instances [ $ class_name ] ; }
Singleton initialize method
10,728
public static function getColumns ( array $ array , array $ columns , $ allRowsMustHaveAllColumns = false ) { foreach ( $ array as $ key => $ row ) { if ( ! is_array ( $ row ) ) { throw new UnexpectedValueException ( 'Array element "' . $ key . '" is not an array' ) ; } } foreach ( $ columns as $ key => $ column ) { if ( ! is_string ( $ column ) && ! is_numeric ( $ column ) ) { throw new InvalidArgumentException ( 'Invalid column type in columns array, index "' . $ key . '"' ) ; } } if ( ! is_bool ( $ allRowsMustHaveAllColumns ) ) { throw new InvalidArgumentException ( 'allRowsMustHaveAllColumns flag must be boolean' ) ; } $ return = array_fill_keys ( $ columns , array ( ) ) ; foreach ( $ array as $ key => $ row ) { foreach ( $ columns as $ column ) { if ( isset ( $ row [ $ column ] ) || array_key_exists ( $ column , $ row ) ) { $ return [ $ column ] [ $ key ] = $ row [ $ column ] ; } elseif ( $ allRowsMustHaveAllColumns ) { throw new UnexpectedValueException ( 'Row "' . $ key . '" is missing column: "' . $ column . '"' ) ; } } } return $ return ; }
Extracts a column from an array
10,729
public static function getRectangularDimensions ( array $ array ) { $ return = - 1 ; $ allArrays = array_map ( 'is_array' , $ array ) ; if ( self :: allElementsEqual ( $ allArrays , true ) ) { $ elementsPerArray = array ( ) ; foreach ( $ array as $ row ) { $ noElements = self :: getRectangularDimensions ( $ row ) ; if ( $ noElements == - 1 ) { return $ noElements ; } $ elementsPerArray [ ] = $ noElements ; } if ( ! self :: allElementsEqual ( $ elementsPerArray ) ) { return - 1 ; } else { $ return = reset ( $ elementsPerArray ) ; $ return [ ] = count ( $ elementsPerArray ) ; } } elseif ( self :: allElementsEqual ( $ allArrays , false ) ) { $ return = array ( 0 => count ( $ array ) ) ; } return $ return ; }
Checks if an array is rectangular array and returns dimensions or - 1 if it s not rectangular
10,730
public static function selectRandomArrayElements ( array $ array , $ numberOfRequiredElements ) { if ( ! self :: isLogicallyCastableToInt ( $ numberOfRequiredElements ) ) { throw new InvalidArgumentException ( 'Number of requested elements parameter must be a positive integer' ) ; } if ( $ numberOfRequiredElements <= 0 ) { throw new InvalidArgumentException ( 'Number of requested elements parameter must be a positive integer' ) ; } $ selected = $ array ; if ( count ( $ array ) > $ numberOfRequiredElements ) { $ selectedKeys = array_rand ( $ array , $ numberOfRequiredElements ) ; $ selectedKeys = $ numberOfRequiredElements == 1 ? [ $ selectedKeys ] : $ selectedKeys ; $ selected = array_intersect_key ( $ array , array_fill_keys ( $ selectedKeys , null ) ) ; } return $ selected ; }
Selects random sub array
10,731
protected function parseUri ( $ uriString = '' ) { $ status = @ preg_match ( "~^((//)([^/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?$~" , $ uriString , $ matches ) ; if ( $ status === FALSE ) { throw new Exception ( "URI scheme-specific decomposition failed" ) ; } if ( ! $ status ) return ; $ this -> path = ( isset ( $ matches [ 4 ] ) ) ? $ matches [ 4 ] : '' ; $ this -> query = ( isset ( $ matches [ 6 ] ) ) ? $ matches [ 6 ] : '' ; $ this -> fragment = ( isset ( $ matches [ 8 ] ) ) ? $ matches [ 8 ] : '' ; $ status = @ preg_match ( "~^(([^:@]*)(:([^@]*))?@)?((?(?=[[])[[][^]]+[]]|[^:]+))(:(.*))?$~" , ( isset ( $ matches [ 3 ] ) ) ? $ matches [ 3 ] : "" , $ matches ) ; if ( $ status === FALSE ) { throw new Exception ( "URI scheme-specific authority decomposition failed" ) ; } if ( ! $ status ) return ; $ this -> user = isset ( $ matches [ 2 ] ) ? $ matches [ 2 ] : "" ; $ this -> pass = isset ( $ matches [ 4 ] ) ? $ matches [ 4 ] : "" ; $ this -> host = isset ( $ matches [ 5 ] ) === TRUE ? preg_replace ( '~^\[([^]]+)\]$~' , '\1' , $ matches [ 5 ] ) : "" ; $ this -> port = isset ( $ matches [ 7 ] ) ? $ matches [ 7 ] : "" ; }
Parses the scheme - specific portion of the URI and place its parts into instance variables .
10,732
public static function check ( $ uri ) { try { $ uri = new self ( strval ( $ uri ) ) ; } catch ( \ Exception $ e ) { return FALSE ; } return $ uri -> valid ( ) ; }
Returns TRUE if a given URI is valid .
10,733
public function checkPath ( $ path = null ) { if ( $ path === null ) { $ path = $ this -> path ; } if ( strlen ( $ path ) == 0 ) { return TRUE ; } $ pattern = "/^" . $ this -> regex [ "path" ] . "$/" ; $ status = @ preg_match ( $ pattern , $ path ) ; if ( $ status === FALSE ) { throw new Exception ( "URI path validation failed" ) ; } return ( $ status == 1 ) ; }
Returns TRUE if the path is valid .
10,734
public static function getHostUri ( ) { $ sheme = ( self :: getHostParam ( "HTTPS" ) == "on" ) ? "https" : "http" ; $ serverName = new Str ( self :: getHostParam ( "HTTP_HOST" ) ) ; $ serverPort = self :: getHostParam ( "SERVER_PORT" ) ; $ serverPort = ( $ serverPort != 80 && $ serverPort != 443 ) ? ":" . $ serverPort : "" ; if ( $ serverName -> endsWith ( $ serverPort ) ) { $ serverName = $ serverName -> replace ( $ serverPort , "" ) ; } return new Str ( $ sheme . "://" . $ serverName . $ serverPort ) ; }
Returns the applications host address .
10,735
public function parseBody ( $ line ) { $ line = rtrim ( $ line , "\r\n" ) ; if ( $ this -> text === null ) { $ this -> text = $ line ; } else { $ this -> text .= "\n" . $ line ; } }
Adds each line to the body of the text part .
10,736
public function finish ( ) { $ charset = "us-ascii" ; if ( isset ( $ this -> headers [ 'Content-Type' ] ) ) { preg_match ( '/\s*charset\s?=\s?"?([^;"\s]*);?/' , $ this -> headers [ 'Content-Type' ] , $ parameters ) ; if ( count ( $ parameters ) > 0 ) { $ charset = strtolower ( trim ( $ parameters [ 1 ] , '"' ) ) ; } } $ encoding = strtolower ( $ this -> headers [ 'Content-Transfer-Encoding' ] ) ; if ( $ encoding == ezcMail :: QUOTED_PRINTABLE ) { $ this -> text = quoted_printable_decode ( $ this -> text ) ; } else if ( $ encoding == ezcMail :: BASE64 ) { $ this -> text = base64_decode ( $ this -> text ) ; } $ this -> text = ezcMailCharsetConverter :: convertToUTF8 ( $ this -> text , $ charset ) ; $ part = new ezcMailText ( $ this -> text , 'utf-8' , ezcMail :: EIGHT_BIT , $ charset ) ; $ part -> subType = $ this -> subType ; $ part -> setHeaders ( $ this -> headers -> getCaseSensitiveArray ( ) ) ; ezcMailPartParser :: parsePartHeaders ( $ this -> headers , $ part ) ; $ part -> size = strlen ( $ this -> text ) ; return $ part ; }
Returns the ezcMailText part corresponding to the parsed message .
10,737
public static function load ( $ class ) { $ file = static :: normalizePath ( $ class ) ; if ( file_exists ( $ path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $ file ) ) { require $ path ; return true ; } foreach ( static :: $ directories as $ directory ) { if ( file_exists ( $ path = $ directory . DIRECTORY_SEPARATOR . $ file ) ) { require $ path ; return true ; } } if ( static :: $ aliases [ $ class ] ) { class_alias ( static :: $ aliases [ $ class ] , $ class ) ; return true ; } return false ; }
Search and Include a Class by class name like Qlake \ Router \ Route .
10,738
private function createWord ( ) { $ this -> word = '' ; for ( $ x = 0 ; $ x < rand ( 5 , 7 ) ; $ x ++ ) { $ this -> word .= $ this -> allowed_characters [ rand ( 0 , strlen ( $ this -> allowed_characters ) - 1 ) ] ; } return $ this -> word ; }
Creates the word from the allowed characters
10,739
public function addInterference ( ) { for ( $ i = 0 ; $ i < 20 ; $ i ++ ) { $ radius = rand ( 0 , 150 ) ; imageellipse ( $ this -> image , rand ( 0 , 200 ) , rand ( 0 , 200 ) , $ radius , $ radius , $ this -> ink_color ) ; } }
Adds interference as circles int he backgroun the make it more difficult to parse . This is optional
10,740
public function draw ( $ filters = Array ( ) ) { $ word = $ this -> createWord ( ) ; for ( $ j = 0 ; $ j < 5 ; $ j ++ ) { if ( file_exists ( $ this -> font ) ) { imagettftext ( $ this -> image , rand ( 8 , 18 ) , rand ( 0 , 30 ) , rand ( 0 , 200 ) , rand ( 0 , 200 ) , $ this -> ink_color , $ this -> font , 'not the code' ) ; } else { imagestring ( $ this -> image , rand ( 1 , 3 ) , rand ( 0 , 200 ) , rand ( 0 , 200 ) , 'not the word' , $ this -> ink_color ) ; } } if ( file_exists ( $ this -> font ) ) { imagettftext ( $ this -> image , 30 , rand ( - 45 , 45 ) , rand ( 10 , 80 ) , rand ( 80 , 120 ) , $ this -> ink_color , $ this -> font , $ this -> word ) ; } else { imagestring ( $ this -> image , 5 , rand ( 10 , 80 ) , rand ( 80 , 120 ) , $ this -> word , $ this -> ink_color ) ; } foreach ( $ filters as $ filter ) { imagefilter ( $ this -> image , $ filter ) ; } return $ this -> image ; }
Draws the wor text on the image using the true type font specified . If no font is specified than
10,741
public function nonce_field ( $ key = '_wpnonce' , $ referrer = false , $ echo = true ) { return wp_nonce_field ( $ this -> action , $ key , $ referrer , $ echo ) ; }
Echo nonce field
10,742
public static function view ( $ slug , $ name = '' , array $ args = [ ] ) { $ class_name = get_called_class ( ) ; $ instance = $ class_name :: get_instance ( ) ; $ instance -> lazy_scripts ( ) ; $ instance -> load_template ( $ slug , $ name , $ args ) ; }
Load view template with arguments
10,743
private function getExtendableFile ( $ specification ) { $ target = $ specification -> getTarget ( ) ; if ( ! array_key_exists ( $ target , $ this -> extendableFiles ) ) { if ( ! $ specification -> mayCreate ( ) ) return null ; $ this -> extendableFiles [ $ target ] = $ this -> getExtendableFileFromSpecification ( $ specification ) ; $ this -> logFile -> log ( null , "added file \"{$specification->getTarget()}\"" ) ; } return $ this -> extendableFiles [ $ target ] ; }
Creates an extendable file from a specification . If the extendable file was already created returns the cached extendable file . If the extendable file does not yet exist create it if it may be created from this specification .
10,744
private function generateFilesForArtifacts ( $ artifacts , $ fileSettingsGetter , $ extend ) { foreach ( $ artifacts as $ artifact ) { $ settings = $ artifact -> getGeneratorSettings ( static :: getKey ( ) ) ; foreach ( call_user_func ( array ( $ this , $ fileSettingsGetter ) , $ settings ) as $ file ) { $ specification = $ this -> getSpecification ( $ file , $ settings , $ artifact ) ; $ extendableFile = $ this -> getExtendableFile ( $ specification ) ; if ( $ extendableFile && $ extend ) { $ places = $ extendableFile -> extend ( $ specification ) ; foreach ( $ places as $ placePair ) { if ( ! is_array ( $ placePair ) ) $ placePair = array ( new \ FeaturePhp \ Artifact \ SettingsPlace ( $ artifact ) , $ placePair ) ; $ this -> tracingLinks [ ] = new fphp \ Artifact \ TracingLink ( static :: getKey ( ) === "template" ? "rule" : "chunk" , $ artifact , $ placePair [ 0 ] , $ placePair [ 1 ] ) ; } $ this -> logFile -> log ( $ artifact , "extended file \"{$specification->getTarget()}\"" ) ; } } } }
Generates the extendable files for a set of artifacts and file settings .
10,745
protected function _generateFiles ( ) { $ this -> generateFilesForArtifacts ( $ this -> selectedArtifacts , "getFileSettingsForSelected" , false ) ; $ this -> generateFilesForArtifacts ( $ this -> deselectedArtifacts , "getFileSettingsForDeselected" , false ) ; $ this -> generateFilesForArtifacts ( $ this -> selectedArtifacts , "getFileSettingsForSelected" , true ) ; $ this -> generateFilesForArtifacts ( $ this -> deselectedArtifacts , "getFileSettingsForDeselected" , true ) ; foreach ( $ this -> extendableFiles as $ extendableFile ) $ this -> files [ ] = $ extendableFile ; }
Generates the extendable files .
10,746
final public function compile ( Buffer $ buffer ) { $ buffer -> writeln ( "Phar::mapPhar('z.phar');" ) -> writeln ( "define('ZPREFIX', 'phar://z.phar/');" ) -> writeln ( "require_once 'phar://z.phar/vendor/autoload.php';" ) ; $ this -> compileInitialization ( $ buffer ) ; $ buffer -> writeln ( '$app->run();' ) -> writeln ( '__HALT_COMPILER();' ) ; }
Compiles into the specified buffer .
10,747
private function createNode ( $ nodeName , $ nodeValue , $ cdata = false ) { $ node = $ this -> createElement ( $ nodeName ) ; if ( $ cdata ) { $ text = $ this -> createCDATASection ( $ nodeValue ) ; } else { $ text = $ this -> createTextNode ( $ nodeValue ) ; } $ node -> appendChild ( $ text ) ; return $ node ; }
Creates and returns a new node with textNode ready for appending
10,748
private function appendItem ( \ sb \ RSS \ Item $ item ) { $ new_item = $ this -> createElement ( "item" ) ; foreach ( get_object_vars ( $ item ) as $ key => $ val ) { if ( $ item -> { $ key } instanceof \ sb \ RSS \ ItemEnclosure ) { $ enclosure = $ this -> createElement ( 'enclosure' ) ; foreach ( $ item -> { $ key } as $ n => $ v ) { $ enclosure -> setAttribute ( $ n , $ v ) ; } $ new_item -> appendChild ( $ enclosure ) ; } if ( $ key == 'categories' ) { foreach ( $ item -> { $ key } as $ category ) { $ new_item -> appendChild ( $ this -> createNode ( 'category' , $ category ) ) ; } } if ( is_string ( $ val ) && ! empty ( $ val ) ) { $ new_item -> appendChild ( $ this -> createNode ( $ key , $ val , $ key == 'description' ) ) ; } } if ( empty ( $ item -> guid ) ) { $ new_item -> appendChild ( $ this -> createNode ( 'guid' , $ item -> link ) ) ; } $ this -> channel -> appendChild ( $ new_item ) ; }
Takes an \ sb \ RSS \ Item and converts it into a DOMM node followed by inserting it into the feed DOM
10,749
private function channelPropertiesToDOM ( ) { foreach ( get_object_vars ( $ this ) as $ key => $ val ) { if ( is_string ( $ val ) && ! empty ( $ val ) ) { $ this -> channel -> appendChild ( $ this -> createNode ( $ key , $ val , $ key == 'description' ) ) ; } elseif ( $ this -> { $ key } instanceof \ sb \ RSS \ Image ) { $ image = $ this -> createElement ( 'image' ) ; foreach ( $ this -> { $ key } as $ n => $ v ) { $ image -> appendChild ( $ this -> createNode ( $ n , $ v ) ) ; } $ image -> appendChild ( $ this -> createNode ( 'link' , $ this -> link ) ) ; $ this -> channel -> appendChild ( $ image ) ; } elseif ( $ this -> { $ key } instanceof \ sb \ RSS_Cloud ) { $ cloud = $ this -> createElement ( 'cloud' ) ; foreach ( $ this -> { $ key } as $ n => $ v ) { $ cloud -> setAttribute ( $ n , $ v ) ; } $ this -> channel -> appendChild ( $ cloud ) ; } elseif ( $ key == 'categories' ) { foreach ( $ this -> { $ key } as $ category ) { $ this -> channel -> appendChild ( $ this -> createNode ( 'category' , $ category ) ) ; } } elseif ( $ key == 'skipHours' || $ key == 'skipDays' ) { $ node = $ this -> createElement ( $ key ) ; $ nodeName = ( $ key == 'skipHours' ) ? 'hour' : 'day' ; foreach ( $ this -> { $ key } as $ value ) { $ node -> appendChild ( $ this -> createNode ( $ nodeName , ucwords ( $ value ) ) ) ; } $ this -> channel -> appendChild ( $ node ) ; } } }
Converts all the feed object properties into RSS DOM nodes and adds them to the channel node
10,750
public function unescapeCharacter ( $ value ) { switch ( $ value { 1 } ) { case '0' : return "\x0" ; case 'a' : return "\x7" ; case 'b' : return "\x8" ; case 't' : return "\t" ; case "\t" : return "\t" ; case 'n' : return "\n" ; case 'v' : return "\xb" ; case 'f' : return "\xc" ; case 'r' : return "\xd" ; case 'e' : return "\x1b" ; case ' ' : return ' ' ; case '"' : return '"' ; case '/' : return '/' ; case '\\' : return '\\' ; case 'N' : return $ this -> convertEncoding ( "\x00\x85" , self :: ENCODING , 'UCS-2BE' ) ; case '_' : return $ this -> convertEncoding ( "\x00\xA0" , self :: ENCODING , 'UCS-2BE' ) ; case 'L' : return $ this -> convertEncoding ( "\x20\x28" , self :: ENCODING , 'UCS-2BE' ) ; case 'P' : return $ this -> convertEncoding ( "\x20\x29" , self :: ENCODING , 'UCS-2BE' ) ; case 'x' : $ char = pack ( 'n' , hexdec ( substr ( $ value , 2 , 2 ) ) ) ; return $ this -> convertEncoding ( $ char , self :: ENCODING , 'UCS-2BE' ) ; case 'u' : $ char = pack ( 'n' , hexdec ( substr ( $ value , 2 , 4 ) ) ) ; return $ this -> convertEncoding ( $ char , self :: ENCODING , 'UCS-2BE' ) ; case 'U' : $ char = pack ( 'N' , hexdec ( substr ( $ value , 2 , 8 ) ) ) ; return $ this -> convertEncoding ( $ char , self :: ENCODING , 'UCS-4BE' ) ; } }
Unescapes a character that was found in a double - quoted string
10,751
public function toggle ( $ flag , $ name ) { switch ( $ flag ) { case 'on' : $ onoff = true ; break ; case 'off' : $ onoff = false ; break ; default : throw new \ InvalidArgumentException ( "Flag must be 'on' or 'off'" ) ; } switch ( $ name ) { case 'debug' : $ this -> debug = $ onoff ; break ; case 'info' : $ this -> info = $ onoff ; break ; case 'notice' : $ this -> notice = $ onoff ; break ; case 'warn' : $ this -> warn = $ onoff ; break ; case 'error' : $ this -> error = $ onoff ; break ; case 'critical' : $ this -> critical = $ onoff ; break ; case 'alert' : $ this -> alert = $ onoff ; break ; case 'emergency' : $ this -> emergency = $ onoff ; break ; default : throw new \ InvalidArgumentException ( "Name must be on (debug|info|notice|warn|error|critical|alert|emergency)" ) ; } }
Sets the named attribute to true or false
10,752
private function audioCanBeEncoded ( $ resolution , $ metainfo ) { return $ resolution [ 'audio_sample_rate' ] >= $ metainfo [ 'sample_rate' ] && $ resolution [ 'audio_bitrate' ] <= $ metainfo [ 'max_bit_rate' ] || filter_var ( $ resolution [ 'allow_lower_audio_bitrate' ] , FILTER_VALIDATE_BOOLEAN ) ; }
determines if the the audiotrack meets minimum standards to be encoded
10,753
private function getMediaType ( $ metainfo ) { if ( $ metainfo [ 'audio' ] != false && ( $ metainfo [ 'video' ] == false || $ metainfo [ 'video' ] [ 'codec_name' ] == 'png' || $ metainfo [ 'video' ] [ 'codec_name' ] == 'jpg' ) ) { return $ this :: MEDIA_TYPE_AUDIO ; } if ( $ metainfo [ 'video' ] != false && $ metainfo [ 'audio' ] == false ) { return $ this :: MEDIA_TYPE_VIDEO_ONLY ; } if ( $ metainfo [ 'video' ] != false && $ metainfo [ 'audio' ] != false ) { return $ this :: MEDIA_TYPE_VIDEO ; } return $ this :: MEDIA_TYPE_UNKNOWN ; }
returns the mediatype depending on given metainfos MEDIA_TYPE_AUDIO if soundfile MEDIA_TYPE_VIDEO if videofile MEDIA_TYPE_VIDEO_ONLY if videofile without soundstream .
10,754
private function getMetainfoForEpisode ( $ episode ) { $ uri = $ this -> bprs_asset_helper -> getAbsoluteUrl ( $ episode -> getVideo ( ) ) ; if ( ! $ uri ) { $ this -> logbook -> error ( 'oktolab_media.episode_encode_no_streams' , [ ] , $ episode -> getUniqID ( ) ) ; return false ; } $ metainfo = json_decode ( shell_exec ( sprintf ( 'ffprobe -v error -show_streams -print_format json %s' , $ uri ) ) , true ) ; $ metadata = [ 'video' => false , 'audio' => false ] ; foreach ( $ metainfo [ 'streams' ] as $ stream ) { if ( $ metadata [ 'video' ] && $ metadata [ 'audio' ] ) { break ; } if ( $ stream [ 'codec_type' ] == "audio" && $ metadata [ 'audio' ] == false ) { $ metadata [ 'audio' ] = $ stream ; if ( ! array_key_exists ( 'max_bit_rate' , $ metadata [ 'audio' ] ) && array_key_exists ( 'tags' , $ metadata [ 'audio' ] ) ) { $ metadata [ 'audio' ] [ 'max_bit_rate' ] = $ metadata [ 'tags' ] [ 'BPS' ] ; } } if ( $ stream [ 'codec_type' ] == "video" ) { $ metadata [ 'video' ] = $ stream ; if ( ! array_key_exists ( 'duration' , $ metadata [ 'video' ] ) ) { $ metadata [ 'video' ] [ 'duration' ] = 0 ; } else { $ episode -> setDuration ( $ metadata [ 'video' ] [ 'duration' ] ) ; } } } return $ metadata ; }
extracts streaminformations of an episode from its video .
10,755
public function init ( ) { if ( ! post_type_exists ( $ this -> post_type ) ) { $ post_type = register_post_type ( $ this -> post_type , $ this -> args ) ; if ( is_wp_error ( $ post_type ) ) { return $ post_type ; } } if ( '' !== $ this -> title_placeholder ) { add_filter ( 'enter_title_here' , array ( $ this , 'update_placeholder' ) ) ; } }
Function that register the CPT first tests if there is no such CPT on the site .
10,756
public function set_labels ( $ labels ) { $ this -> merge ( $ this -> labels , $ labels ) ; $ this -> update_arg ( 'labels' , $ this -> labels ) ; }
Allows to overwrite any of the default labels for this CPT just send an associate array with the value you want to update .
10,757
private function set_default_labels ( ) { $ this -> labels = array ( 'name' => $ this -> interpolate ( '%s' , $ this -> plural ) , 'singular_name' => $ this -> interpolate ( '%s' , $ this -> singular ) , 'add_new' => $ this -> interpolate ( 'Add New' ) , 'all_items' => $ this -> interpolate ( 'All %s' , $ this -> plural ) , 'new_item' => $ this -> interpolate ( 'New %s' , $ this -> singular ) , 'edit_item' => $ this -> interpolate ( 'Edit %s' , $ this -> singular ) , 'add_new_item' => $ this -> interpolate ( 'Add New %s' , $ this -> singular ) , 'view_item' => $ this -> interpolate ( 'View %S' , $ this -> singular ) , 'menu_name' => $ this -> interpolate ( '%s' , $ this -> plural ) , 'search_items' => $ this -> interpolate ( 'Search %s' , $ this -> plural ) , 'not_found' => $ this -> interpolate ( 'No %s found.' , $ this -> plural ) , 'not_found_in_trash' => $ this -> interpolate ( 'No %s found in trash.' , $ this -> plural ) , ) ; }
Creates the default labels to be used with this CPT .
10,758
public function set_supports ( $ support ) { if ( is_array ( $ support ) ) { $ this -> supports = $ support ; $ this -> update_arg ( 'supports' , $ this -> supports ) ; } }
Allow to update the default supports values for the CPT .
10,759
protected function detectFsRoot ( ) { Eresus_Kernel :: log ( __METHOD__ , LOG_DEBUG , 'start' ) ; switch ( true ) { case Eresus_Kernel :: isCLI ( ) : $ path = reset ( $ GLOBALS [ 'argv' ] ) ; Eresus_Kernel :: log ( __METHOD__ , LOG_DEBUG , 'Using global $argv variable: %s' , $ path ) ; $ path = dirname ( $ path ) ; break ; default : Eresus_Kernel :: log ( __METHOD__ , LOG_DEBUG , 'Using $_SERVER["SCRIPT_FILENAME"]: %s' , $ _SERVER [ 'SCRIPT_FILENAME' ] ) ; $ path = dirname ( $ _SERVER [ 'SCRIPT_FILENAME' ] ) ; } $ path = Eresus_FS_Tool :: normalize ( $ path ) ; Eresus_Kernel :: log ( __METHOD__ , LOG_DEBUG , '"%s"' , $ path ) ; return $ path ; }
Trying to determine application root directory
10,760
protected function resolvePath ( array $ originalPaths ) { $ paths = array ( ) ; foreach ( $ originalPaths as $ key => $ path ) { if ( count ( explode ( 'templates' , $ path ) ) == 1 ) { $ path = $ path . DIRECTORY_SEPARATOR . 'templates' ; } if ( realpath ( $ path ) ) { $ paths [ $ key ] = realpath ( $ path ) ; } } return array_unique ( $ paths ) ; }
Build an array for templates path directory
10,761
public function setLayout ( $ layout , array $ data = array ( ) ) { if ( is_null ( $ layout ) ) { $ this -> layout = null ; return ; } $ this -> layout = $ this -> make ( $ this -> resolve ( $ layout ) , $ data ) ; }
Manually set the layout
10,762
public function fetch ( $ template , $ data = array ( ) ) { $ view = $ this -> render ( $ template , $ data ) ; return ( $ view ) ? $ view -> render ( ) : '' ; }
Return the contents of a rendered template file
10,763
protected function render ( $ template , $ data = array ( ) ) { $ view = null ; $ data = array_merge_recursive ( $ this -> all ( ) , $ data ) ; $ data [ 'app' ] = $ this -> app ; $ template = $ this -> resolve ( $ template ) ; if ( ! $ template ) { return ; } if ( ! $ this -> layout ) { $ view = $ this -> make ( $ template , $ data ) ; } else { $ view = $ this -> layout -> nest ( 'content' , $ template , $ data ) ; } return $ view ; }
This method will output the rendered template content
10,764
public function resolve ( $ path ) { $ path = str_replace ( '/' , '.' , preg_replace ( '/\/:\w+/' , '' , $ path ) ) ; $ finder = $ this -> container [ 'view.finder' ] ; try { $ finder -> find ( $ path ) ; } catch ( InvalidArgumentException $ e ) { $ explodedPath = explode ( '.' , $ path ) ; if ( $ explodedPath [ 0 ] === 'static' ) { return null ; } if ( count ( $ explodedPath ) > 1 ) { $ explodedPath [ 0 ] = 'shared' ; $ explodedPath = array ( 'shared' , end ( $ explodedPath ) ) ; try { $ finder -> find ( implode ( '.' , $ explodedPath ) ) ; $ path = implode ( '.' , $ explodedPath ) ; } catch ( InvalidArgumentException $ e ) { $ this -> app -> error ( $ e ) ; } } } return $ path ; }
This method will try to find the existing of template file
10,765
public function rules ( ) { $ module = UsersModule :: module ( ) ; $ rules = [ [ [ 'phone' ] , 'safe' , ] , [ [ 'password' , ] , 'safe' , 'on' => self :: SCENARIO_DEFAULT , ] , [ [ 'password' , ] , 'required' , 'on' => self :: SCENARIO_PASSWORD_RESET , ] , [ 'username' , 'unique' , ] , [ 'email' , 'unique' , ] , 'standardEmailRules' => [ [ 'email' , ] , 'email' , 'checkDNS' => $ module -> authorizationScenario ( ) -> emailCheckDNS , 'enableIDN' => $ module -> authorizationScenario ( ) -> emailEnableIDN , 'skipOnEmpty' => true , 'on' => self :: SCENARIO_PROFILE_UPDATE , ] , 'trimEmail' => [ [ 'email' , ] , 'filter' , 'filter' => 'trim' , 'on' => self :: SCENARIO_PROFILE_UPDATE , ] , [ [ 'username_is_temporary' , 'password_is_temporary' , 'is_active' , ] , 'filter' , 'filter' => 'boolval' , ] ] ; $ property_rules = $ this -> propertiesRules ( ) ; if ( ! empty ( $ property_rules ) ) { $ rules = array_merge ( $ rules , $ property_rules ) ; } if ( count ( UsersModule :: module ( ) -> requiredUserAttributes ) > 0 ) { $ rules [ 'requiredAttributes' ] = [ UsersModule :: module ( ) -> requiredUserAttributes , 'required' , 'on' => self :: SCENARIO_PROFILE_UPDATE , ] ; } return $ rules ; }
Validation rules for this model .
10,766
public function afterFind ( ) { parent :: afterFind ( ) ; $ this -> username_is_temporary = boolval ( $ this -> username_is_temporary ) ; $ this -> is_active = boolval ( $ this -> is_active ) ; }
Performs after find action and casts attributes to proper type
10,767
public function register ( ) { if ( $ this -> getIsNewRecord ( ) == false ) { throw new \ RuntimeException ( 'Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user' ) ; } $ module = UsersModule :: module ( ) ; if ( empty ( $ this -> password ) === true ) { $ this -> password = PasswordHelper :: generate ( $ module -> generatedPasswordLength ) ; } if ( $ module -> emailConfirmationNeeded === false ) { $ this -> is_active = true ; } $ event = new RegistrationEvent ( ) ; $ this -> trigger ( self :: EVENT_BEFORE_REGISTER , $ event ) ; if ( $ event -> isValid === false ) { return false ; } if ( ! $ this -> save ( ) ) { return false ; } $ this -> trigger ( self :: EVENT_AFTER_REGISTER , $ event ) ; return $ this ; }
This method is used to register new user account .
10,768
public function login ( $ loginDuration = 0 ) { $ loginStatus = Yii :: $ app -> getUser ( ) -> login ( $ this , $ loginDuration ) ; if ( $ loginStatus ) { $ this -> trigger ( User :: EVENT_LOGIN ) ; } return $ loginStatus ; }
Login user .
10,769
protected function getFileKey ( $ basePath , \ SplFileInfo $ file ) { $ baseLength = strlen ( rtrim ( $ basePath , DIRECTORY_SEPARATOR ) ) ; return substr ( $ file -> getPath ( ) , $ baseLength ) . DIRECTORY_SEPARATOR . $ file -> getBasename ( '.' . $ file -> getExtension ( ) ) ; }
Get relative key for a file
10,770
protected function isOutOfDate ( $ source , $ destination , array $ includes = null ) { $ includes = ( array ) $ includes ; $ extensions = $ this -> compiler -> getExtensions ( ) ; if ( ! file_exists ( $ destination ) ) { return true ; } if ( is_file ( $ source ) && is_file ( $ destination ) ) { $ sourceFiles = array ( new \ SplFileInfo ( $ source ) ) ; $ destinationFiles = array ( new \ SplFileInfo ( $ destination ) ) ; } else { $ sourceFiles = $ this -> scanDirectory ( $ source , $ extensions ) ; $ destinationFiles = $ this -> scanDirectory ( $ destination , array ( 'css' ) ) ; } $ youngest = time ( ) ; foreach ( $ sourceFiles as $ key => $ file ) { if ( array_key_exists ( $ key , $ destinationFiles ) ) { if ( $ file -> getMTime ( ) > $ destinationFiles [ $ key ] -> getMTime ( ) ) { return true ; } if ( $ file -> getMTime ( ) < $ youngest ) { $ youngest = $ file -> getMTime ( ) ; } } else { return true ; } } foreach ( $ includes as $ include ) { $ includeFiles = $ this -> scanDirectory ( $ include , $ extensions ) ; foreach ( $ includeFiles as $ file ) { if ( $ file -> getMTime ( ) > $ youngest ) { return true ; } } } return false ; }
Test is destination file or folder is out of date from the source .
10,771
protected function scanDirectory ( $ path , $ extensions ) { if ( is_file ( $ path ) ) { $ file = new \ SplFileInfo ( $ path ) ; return array ( $ this -> getFileKey ( $ file -> getPath ( ) , $ file ) => $ file ) ; } $ files = array ( ) ; $ extensions = ( array ) $ extensions ; $ iterator = new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ path , \ FileSystemIterator :: SKIP_DOTS | \ FileSystemIterator :: CURRENT_AS_FILEINFO ) ) ; foreach ( $ iterator as $ file ) { if ( in_array ( $ file -> getExtension ( ) , $ extensions ) ) { $ files [ $ this -> getFileKey ( $ path , $ file ) ] = $ file ; } } return $ files ; }
Scan a directory and return a list of files with matching extenstions
10,772
public function actionCreate ( ) { $ model = new Address ( [ 'scenario' => 'create' ] ) ; Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { if ( $ model -> validate ( ) ) { if ( $ model -> save ( false ) ) { return $ this -> tree ( $ model ) ; } else { Yii :: $ app -> response -> setStatusCode ( 500 ) ; return \ Yii :: t ( 'net_frenzel_address' , 'FRONTEND_FLASH_FAIL_CREATE' ) ; } } elseif ( Yii :: $ app -> request -> isAjax ) { Yii :: $ app -> response -> setStatusCode ( 400 ) ; return ActiveForm :: validate ( $ model ) ; } } }
Create Address .
10,773
public function actionUpdate ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ model -> setScenario ( 'update' ) ; Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { if ( $ model -> validate ( ) ) { if ( $ model -> save ( false ) ) { return $ this -> renderAjax ( '@vendor/frenzelgmbh/cm-address/views/widgets/views/_index_single_item' , [ 'model' => $ model ] ) ; } else { Yii :: $ app -> response -> setStatusCode ( 500 ) ; return \ Yii :: t ( 'net_frenzel_address' , 'FRONTEND_FLASH_FAIL_UPDATE' ) ; } } elseif ( Yii :: $ app -> request -> isAjax ) { Yii :: $ app -> response -> setStatusCode ( 400 ) ; return ActiveForm :: validate ( $ model ) ; } } }
Update Communication .
10,774
public function actionFetch ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ model -> setScenario ( 'update' ) ; Yii :: $ app -> response -> format = Response :: FORMAT_HTML ; return $ this -> renderAjax ( '@vendor/frenzelgmbh/cm-address/views/widgets/views/_form_update' , [ 'model' => $ model ] ) ; }
fetch Communication .
10,775
public function hotfixStart ( $ options = [ 'semversion' => null , 'type' => 'patch' ] ) { if ( empty ( $ options [ 'semversion' ] ) ) { $ version = $ this -> getVersion ( ) -> increment ( $ options [ 'type' ] ) ; } else { $ version = $ options [ 'semversion' ] ; } return $ this -> taskHotfixStart ( ( string ) $ version ) -> run ( ) ; }
Start a new hotfix
10,776
public function hotfixFinish ( $ options = [ 'semversion' => null , 'type' => 'patch' ] ) { if ( empty ( $ options [ 'semversion' ] ) ) { $ version = $ this -> getVersion ( ) -> increment ( $ options [ 'type' ] ) ; } else { $ version = $ options [ 'semversion' ] ; } return $ this -> taskHotfixFinish ( ( string ) $ version ) -> run ( ) ; }
Finish a hotfix
10,777
public function releaseStart ( $ options = [ 'semversion' => null , 'type' => 'minor' ] ) { if ( empty ( $ options [ 'semversion' ] ) ) { $ version = $ this -> getVersion ( ) -> increment ( $ options [ 'type' ] ) ; } else { $ version = $ options [ 'semversion' ] ; } return $ this -> taskReleaseStart ( ( string ) $ version ) -> run ( ) ; }
Start a new release
10,778
public function releaseFinish ( $ options = [ 'semversion' => null , 'type' => 'minor' ] ) { if ( empty ( $ options [ 'semversion' ] ) ) { $ version = $ this -> getVersion ( ) -> increment ( $ options [ 'type' ] ) ; } else { $ version = $ options [ 'semversion' ] ; } return $ this -> taskReleaseFinish ( ( string ) $ version ) -> run ( ) ; }
Finish a release
10,779
protected function getVersion ( ) { $ cmd = new Command ( 'git' ) ; $ cmd = $ cmd -> arg ( 'tag' ) -> execute ( ) ; $ output = explode ( PHP_EOL , trim ( $ cmd -> getOutput ( ) ) ) ; $ currentVersion = '0.0.0' ; foreach ( $ output as $ tag ) { if ( preg_match ( SemanticVersion :: REGEX , $ tag ) ) { if ( version_compare ( $ currentVersion , $ tag , '<' ) ) { $ currentVersion = $ tag ; } } } return new SemanticVersion ( $ currentVersion ) ; }
Return current version
10,780
protected function getAvailableHandle ( ) { foreach ( $ this -> handles as $ h ) { if ( ! in_array ( $ h , $ this -> groups , true ) ) { return $ h ; } } $ handle = new CurlMulti ( ) ; $ handle -> setEventDispatcher ( $ this -> getEventDispatcher ( ) ) ; $ this -> handles [ ] = $ handle ; return $ handle ; }
Get an existing available CurlMulti handle or create a new one
10,781
public static function getConfiguration ( string $ input ) { list ( $ oldrev , $ newrev , $ refname ) = explode ( ' ' , $ input ) ; list ( , , $ branch ) = explode ( '/' , $ refname ) ; return new ParserVariableConfiguration ( $ oldrev , $ newrev , $ refname , $ branch ) ; }
Extracts data from the post - receive hook as configuration for easy use .
10,782
public static function getEnvironmentVariables ( ) { $ dir = shell_exec ( 'pwd' ) ; $ dir_parts = explode ( DIRECTORY_SEPARATOR , $ dir ) ; $ project = trim ( array_pop ( $ dir_parts ) ) ; $ client = trim ( array_pop ( $ dir_parts ) ) ; $ dir = $ dir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'project' . DIRECTORY_SEPARATOR . $ client . DIRECTORY_SEPARATOR . $ project ; $ environment_file = file_get_contents ( $ dir . DIRECTORY_SEPARATOR . 'environment.yml' ) ; if ( ! $ environment_file ) { throw new MissingEnvironmentConfigurationException ( "The environment configuration is missing, please contact your administrator." ) ; } return new EnvironmentVariables ( Yaml :: parse ( $ environment_file ) ) ; }
Bootstraps the environment variables .
10,783
public static function collectServices ( ContainerBuilder $ container , \ Traversable $ namespaces ) { $ service_directories = [ ] ; foreach ( $ namespaces as $ directory ) { $ service_directories [ ] = $ directory . DIRECTORY_SEPARATOR . '..' ; } $ loader = new PhpFileLoader ( $ container , new FileLocator ( $ service_directories ) ) ; $ loader -> load ( 'services.php' ) ; }
Iterate through all namespace dirs and add services to the container .
10,784
public static function getValidParsers ( ProjectTypeInterface $ project , ParserDictionary $ parserDictionary , EventDispatcherInterface $ dispatcher ) { $ parserSet = $ project :: getFileParsers ( $ parserDictionary ) ; $ event = new ParserSetEvent ( $ project , $ parserSet ) ; $ dispatcher -> dispatch ( ProjectTypeInterface :: COLLECT_PARSER_SET , $ event ) ; $ plugins = [ ] ; foreach ( $ event -> getParserDefinitionSet ( ) as $ parserDefinition ) { $ plugins [ ] = $ parserDictionary -> createInstance ( $ parserDefinition -> getPluginId ( ) , $ parserDefinition , $ project ) ; } return $ plugins ; }
Gets an array of valid parser plugins for the project type .
10,785
public function offsetSet ( $ offset , $ value ) { if ( is_null ( $ offset ) ) { throw new \ Exception ( 'Must supply key to modify an associative array.' ) ; } else { if ( $ this -> _isFillable ( $ offset ) ) { $ this -> _args [ $ offset ] = $ value ; } else { throw new \ Exception ( 'Cannot modify element \'' . $ offset . '\'. Not fillable.' ) ; } } }
Override the offsetSet function to enforce the list of restricted keys .
10,786
public function setSeedQuery ( $ key , $ value ) { $ index = $ this -> getSeedQueryIndex ( ) ; $ this -> seedQueries [ $ index ] [ $ key ] = $ value ; }
The stter for the seed queries class property .
10,787
protected function getWordpressDatabaseInstance ( ) { global $ wpdb ; if ( ( ! \ class_exists ( 'wpdb' ) ) || ( ! $ wpdb ) || ( ! $ wpdb instanceof \ wpdb ) ) { throw InvalidDatabaseInstanceException :: wordpressDatabaseIsNotSet ( ) ; } $ this -> db = $ wpdb ; }
Tightly coupled to the wordpress database instance .
10,788
public function table ( $ name , $ callback = null ) { if ( ! $ callback instanceof \ Closure ) { throw InvalidArgumentPassedException :: isNotClosure ( ) ; } $ this -> setTableName ( $ name ) ; $ callback ( $ this ) ; $ tableNamePrefixed = $ this -> getTableNamePrefix ( $ this -> getTableName ( ) ) ; $ tableStructure = \ substr ( $ this -> getColumnsQuery ( ) . $ this -> getPrimaryKeyQuery ( ) , 0 , - 2 ) ; $ tableCharsetCollate = $ this -> getCharacterSetCollate ( ) ; $ this -> buildCreateTableQuery ( $ tableNamePrefixed , $ tableStructure , $ tableCharsetCollate ) ; $ this -> flushColumns ( ) ; $ this -> flushPrimaryKey ( ) ; }
The composer of the database table schema .
10,789
protected function buildCreateTableQuery ( $ name , $ struture , $ charsetCollate ) { $ total = $ this -> totalQueries ( ) ; $ this -> queries [ $ total ] = "CREATE TABLE `{$name}` ({$struture}) {$charsetCollate};" ; }
Build a create table query base on the complete details given .
10,790
public function tableSeed ( $ tableName , $ callback ) { if ( ! is_array ( $ callback ) && ! ( $ callback instanceof \ Closure ) ) { throw InvalidArgumentPassedException :: isNotArrayOrClosure ( ) ; } $ this -> setTableName ( $ tableName ) ; $ this -> flushSeedQueryIndex ( ) ; if ( $ callback instanceof \ Closure ) { $ obj = ( object ) array ( ) ; $ callback = ( array ) $ callback ( $ obj ) ; } $ seeds = array ( ) ; foreach ( $ callback as $ column => $ value ) { $ seeds [ $ column ] = $ value ; } $ this -> setSeedQueryIndex ( $ this -> totalSeedQueries ( ) ) ; $ this -> setSeedQuery ( 'table' , $ this -> getTableNamePrefix ( $ this -> getTableName ( ) ) ) ; $ this -> setSeedQuery ( 'record' , $ seeds ) ; return $ this ; }
The composer for seeding the given table name .
10,791
public function iterate ( $ counter ) { if ( ! \ is_numeric ( $ counter ) ) { throw InvalidArgumentPassedException :: isNotNumeric ( ) ; } $ this -> setSeedQuery ( 'iterate' , \ round ( $ counter ) ) ; }
The repetition that will apply for the given record .
10,792
public function rawQuery ( $ query = '' ) { if ( ! \ is_string ( $ query ) ) { throw InvalidArgumentPassedException :: isNotString ( ) ; } $ total = $ this -> totalQueries ( ) ; $ this -> queries [ $ total ] = \ trim ( $ query ) ; }
Allow to compose raw database query .
10,793
protected function processQueries ( ) { if ( ! \ function_exists ( 'dbDelta' ) ) { throw WPDatabaseUpdateFunctionsNotFoundException :: dbDeltaIsNotExist ( ) ; } $ queries = '' ; foreach ( $ this -> getQueries ( ) as $ index => $ query ) { $ queries .= \ trim ( $ query ) ; } \ dbDelta ( $ queries ) ; }
Process the queries using the wordpress dbDelta . This function is tightly coupled to the wordpress dbDelta .
10,794
protected function processTableSeeds ( ) { foreach ( $ this -> getSeedQueries ( ) as $ index => $ query ) { if ( isset ( $ query [ 'iterate' ] ) ) { for ( $ x = 1 ; $ x <= $ query [ 'iterate' ] ; $ x ++ ) { $ this -> db -> insert ( $ query [ 'table' ] , $ query [ 'record' ] ) ; } continue ; } $ this -> db -> insert ( $ query [ 'table' ] , $ query [ 'record' ] ) ; } }
Process the seed queries using the wordpress database insert .
10,795
public function dropTable ( $ tableName ) { $ this -> db -> query ( 'SET FOREIGN_KEY_CHECKS = 0;' ) ; $ this -> db -> query ( "DROP TABLE IF EXISTS `{$this->getTableNamePrefix($tableName)}`;" ) ; $ this -> db -> query ( 'SET FOREIGN_KEY_CHECKS = 1;' ) ; }
Process the drop table base on the given table name . Foreign key checks disable before processing the drop action and enable it back again after the process .
10,796
public static function encode ( $ data ) : string { if ( PHP_VERSION_ID >= 50400 ) { return json_encode ( $ data , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ; } return json_encode ( $ data ) ; }
encode data to json
10,797
public function parse ( ) { foreach ( $ this -> parser -> parse ( $ this -> inputFile ) as $ item ) { $ writer = WriterFactory :: create ( $ item [ 'type' ] , $ this -> config ) ; if ( $ writer ) { $ writer -> write ( $ item ) ; } } }
Calls the parser and generates the files
10,798
protected function registerEntityAuditConfigurations ( Repository $ config ) { $ this -> app -> afterResolving ( IlluminateRegistry :: class , function ( $ registry ) use ( $ config ) { $ table = $ config -> get ( 'entity_audit.global.table' ) ; $ users = $ config -> get ( 'entity_audit.global.username_for' ) ; $ columns = $ config -> get ( 'entity_audit.global.ignore_columns' ) ; $ auditRegistry = $ this -> app -> make ( AuditRegistry :: class ) ; foreach ( $ config -> get ( 'entity_audit.entity_managers' , [ ] ) as $ emName => $ emConfig ) { $ users = array_merge ( $ users , data_get ( $ emConfig , 'username_for' , [ ] ) ) ; $ metadata = new MetadataFactory ( data_get ( $ emConfig , 'entities' , [ ] ) ) ; $ auditConfig = new AuditConfiguration ( new UserResolver ( $ this -> app -> make ( Guard :: class ) , $ users [ 'unknown_authenticated_user' ] , $ users [ 'unknown_unauthenticated_user' ] ) , new TableConfiguration ( array_merge ( $ table , data_get ( $ emConfig , 'table' , [ ] ) ) ) , data_get ( $ emConfig , 'ignore_columns' , $ columns ) ) ; $ em = $ registry -> getManager ( $ emName ) ; $ reader = new AuditReader ( $ em , $ auditConfig , $ metadata ) ; $ manager = new AuditManager ( $ auditConfig , $ metadata , $ reader ) ; $ em -> getEventManager ( ) -> addEventSubscriber ( new CreateSchemaListener ( $ manager ) ) ; $ em -> getEventManager ( ) -> addEventSubscriber ( new LogRevisionsListener ( $ manager ) ) ; $ auditRegistry -> add ( $ emName , $ manager ) ; $ this -> app -> instance ( sprintf ( 'entity_audit.%s.manager' , $ emName ) , $ manager ) ; $ this -> app -> instance ( sprintf ( 'entity_audit.%s.reader' , $ emName ) , $ reader ) ; } } ) ; }
Registers auditing to the specified entity managers
10,799
protected function parseConfigFiles ( Finder $ files ) { $ config = [ ] ; foreach ( $ files as $ file ) { $ path = $ file -> getRealPath ( ) ; if ( ! file_exists ( dirname ( $ path ) . '/RoboFile.php' ) ) { continue ; } $ this -> printTaskInfo ( sprintf ( 'Parsing config from %s.' , $ path ) ) ; $ contents = file_get_contents ( $ path ) ; $ this -> printTaskDebug ( sprintf ( 'Parsing %s' , $ contents ) ) ; $ config += Yaml :: parse ( $ contents ) ; } return $ config ; }
Helper function to parse config files .