idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
800
public function setLimit ( $ limit ) { $ this -> limit = $ limit > 0 ? $ limit : 1 ; $ this -> setPage ( $ this -> page ) ; }
Sets the results limit for one page .
801
public function getNextPage ( ) { $ lastPage = $ this -> getLastPage ( ) ; return $ this -> page < $ lastPage ? $ this -> page + 1 : $ lastPage ; }
Returns the next page number .
802
public function getLastPage ( ) { return $ this -> hasResults ( ) ? ceil ( $ this -> adapter -> getTotalResults ( ) / $ this -> limit ) : $ this -> getFirstPage ( ) ; }
Returns the last page number .
803
public function getResults ( ) { return $ this -> hasResults ( ) ? $ this -> adapter -> getResults ( $ this -> getOffset ( ) , $ this -> limit ) : [ ] ; }
Returns results list for the current page and limit .
804
public function addAttributes ( $ arrAttributes ) { foreach ( $ arrAttributes as $ key => $ val ) { $ this -> attributes [ $ key ] = $ val ; } }
Adds the supplied array of attributes
805
public function generateCode ( ) { $ content = "" ; foreach ( $ this -> arrTemplates as $ template ) { if ( ! file_exists ( $ template ) ) { continue ; } $ content .= file_get_contents ( $ template ) ; } foreach ( $ this -> attributes as $ key => $ val ) { $ content = str_replace ( $ this -> placeHolderStart . $ key . $ this -> placeHolderEnd , $ val , $ content ) ; } return $ content ; }
Generates the File content
806
public function generate ( ) { if ( ! $ this -> filePath ) { throw new Exception ( 'Trying to save file without path' ) ; } $ tempDir = codemonkey_pathTempDir ; $ content = $ this -> generateCode ( ) ; $ this -> checkIfTempFolderExists ( ) ; $ this -> checkIfFoldersExist ( ) ; try { $ fp = fopen ( $ tempDir . $ this -> filePath , 'w' ) ; fputs ( $ fp , $ content ) ; fclose ( $ fp ) ; chmod ( $ tempDir . $ this -> filePath , 0775 ) ; } catch ( Exception $ e ) { echo "Could not generate file " . $ this -> filePath . "<br />\n" . $ e -> getMessage ( ) . "<br />\n" ; } }
Creates the file in the temp folder
807
protected function checkIfFoldersExist ( ) { $ arrFilePath = explode ( DIRECTORY_SEPARATOR , $ this -> filePath ) ; array_pop ( $ arrFilePath ) ; if ( count ( $ arrFilePath ) > 0 ) { $ folderPath = implode ( DIRECTORY_SEPARATOR , $ arrFilePath ) ; $ folder = new Folder ( ) ; $ folder -> createFolderIfNotExists ( $ folderPath ) ; } }
Create folders if not existing
808
public static function each ( ORM & $ model , Request $ request , $ data = null ) { if ( ! is_null ( $ data ) ) { foreach ( $ data as $ key ) { $ model -> $ key = $ request -> $ $ key ; } } else { foreach ( $ request -> all ( ) as $ key => $ value ) { if ( in_array ( $ key , $ model -> _columns ) ) { $ model -> $ key = $ request -> $ key ; } } } }
Set each properties of model from request .
809
public function run ( callable $ callback , array $ argsCollection ) { $ this -> collector -> init ( ) ; $ children = [ ] ; foreach ( $ argsCollection as $ key => $ args ) { $ pid = pcntl_fork ( ) ; switch ( $ pid ) { case - 1 : throw new \ RuntimeException ( sprintf ( 'Unable to fork process %d of %d' , $ key , count ( $ argsCollection ) ) ) ; case 0 : $ this -> collector -> setValue ( $ key , call_user_func_array ( $ callback , $ args ) ) ; exit ( 0 ) ; default : $ children [ ] = $ pid ; } } foreach ( $ children as $ child ) { do { pcntl_waitpid ( $ child , $ status ) ; } while ( ! pcntl_wifexited ( $ status ) ) ; } return $ this -> collector -> getValues ( array_keys ( $ argsCollection ) ) ; }
Run a callback in parallel processes
810
public function getTable ( ) { $ this -> _resetSizes ( ) ; $ this -> _repadAllLines ( ) ; return array ( 'title' => $ this -> getTitle ( ) , 'head' => $ this -> getHeader ( ) , 'body' => $ this -> getBody ( ) , 'foot' => $ this -> getFooter ( ) , ) ; }
Get the full table array
811
public function getTableIterator ( $ part = 'body' , $ iterator_flag = self :: ITERATE_ON_LINES ) { $ this -> _repadAllLines ( ) ; $ table = $ this -> getTable ( ) ; unset ( $ table [ 'title' ] ) ; if ( ! empty ( $ part ) ) { if ( isset ( $ table [ $ part ] ) ) { if ( $ iterator_flag & self :: ITERATE_ON_COLUMNS ) { $ columns = array ( ) ; foreach ( $ table [ $ part ] as $ i => $ line ) { foreach ( $ line as $ j => $ cell ) { if ( ! isset ( $ columns [ $ j ] ) ) { $ columns [ $ j ] = array ( ) ; } $ columns [ $ j ] [ $ i ] = $ cell ; } } return new ArrayIterator ( $ columns ) ; } else { return new ArrayIterator ( $ table [ $ part ] ) ; } } else { throw new InvalidArgumentException ( sprintf ( 'Unknown table part "%s"!' , $ part ) ) ; } } else { $ lines = array ( ) ; foreach ( self :: $ _table_parts as $ _part ) { if ( isset ( $ this -> { $ _part } ) && ! empty ( $ this -> { $ _part } ) ) { foreach ( $ this -> { $ _part } as $ line ) { $ lines [ ] = $ line ; } } } if ( $ iterator_flag & self :: ITERATE_ON_COLUMNS ) { $ columns = array ( ) ; foreach ( $ lines as $ i => $ line ) { foreach ( $ line as $ j => $ cell ) { if ( ! isset ( $ columns [ $ j ] ) ) { $ columns [ $ j ] = array ( ) ; } $ columns [ $ j ] [ $ i ] = $ cell ; } } return new ArrayIterator ( $ columns ) ; } else { return new ArrayIterator ( $ lines ) ; } } }
Get the full table or a part of the table as an ArrayIterator object
812
public function addLine ( $ contents = null , $ default = null ) { $ this -> addBodyLine ( is_array ( $ contents ) ? $ contents : array ( $ contents ) , null , $ default ) ; return $ this ; }
Add a new line in the table body
813
public function setHeaderLine ( array $ contents , $ line_index = null , $ default = null ) { $ this -> _setPartLine ( $ contents , $ line_index , $ default , 'thead' ) ; return $ this ; }
Set a table header line
814
public function addHeaderLine ( array $ contents , $ line_index = null , $ default = null ) { $ this -> _setPartLine ( $ contents , $ line_index , $ default , 'thead' , 'insert' ) ; return $ this ; }
Add a new table header line
815
public function setHeaderColumn ( array $ contents = array ( ) , $ column_index = null , $ default = null ) { $ this -> _setPartColumn ( $ contents , $ column_index , $ default , 'thead' ) ; return $ this ; }
Set a column in the table header
816
public function addHeaderColumn ( array $ contents = array ( ) , $ column_index = null , $ default = null ) { $ this -> _setPartColumn ( $ contents , $ column_index , $ default , 'thead' , 'insert' ) ; return $ this ; }
Add a new column in the table header
817
public function setHeaderCell ( $ content , $ line_index = null , $ cell_index = null ) { $ this -> _setPartCell ( $ content , $ line_index , $ cell_index , 'thead' ) ; return $ this ; }
Set a table header cell
818
public function addHeaderCell ( $ content , $ line_index = null , $ cell_index = null ) { $ this -> _setPartCell ( $ content , $ line_index , $ cell_index , 'thead' , 'insert' ) ; return $ this ; }
Add a new table header cell
819
public function setBodyColumn ( array $ contents = array ( ) , $ column_index = null , $ default = null ) { $ this -> _setPartColumn ( $ contents , $ column_index , $ default , 'tbody' ) ; return $ this ; }
Set a column in the table body
820
public function setBodyCell ( $ content , $ line_index = null , $ cell_index = null ) { $ this -> _setPartCell ( $ content , $ line_index , $ cell_index , 'tbody' ) ; return $ this ; }
Set a table body cell
821
public function addBodyCell ( $ content , $ line_index = null , $ cell_index = null ) { $ this -> _setPartCell ( $ content , $ line_index , $ cell_index , 'tbody' , 'insert' ) ; return $ this ; }
Add a new table body cell
822
public function setFooterColumn ( array $ contents = array ( ) , $ column_index = null , $ default = null ) { $ this -> _setPartColumn ( $ contents , $ column_index , $ default , 'tfoot' ) ; return $ this ; }
Set a column in the table footers
823
public function addFooterColumn ( array $ contents = array ( ) , $ column_index = null , $ default = null ) { $ this -> _setPartColumn ( $ contents , $ column_index , $ default , 'tfoot' , 'insert' ) ; return $ this ; }
Add a new column in the table footers
824
public function setFooterCell ( $ content , $ line_index = null , $ cell_index = null ) { $ this -> _setPartCell ( $ content , $ line_index , $ cell_index , 'tfoot' ) ; return $ this ; }
Set a table footer cell
825
public function addFooterCell ( $ content , $ line_index = null , $ cell_index = null ) { $ this -> _setPartCell ( $ content , $ line_index , $ cell_index , 'tfoot' , 'insert' ) ; return $ this ; }
Add a new table footer cell
826
public function getTableColumnSize ( ) { if ( $ this -> column_size === 0 && $ this -> line_size === 0 && $ this -> cell_size === 0 ) { $ this -> _parseTableSizes ( ) ; } return $ this -> column_size ; }
Get the table columns size
827
public function getTableLineSize ( ) { if ( $ this -> column_size === 0 && $ this -> line_size === 0 && $ this -> cell_size === 0 ) { $ this -> _parseTableSizes ( ) ; } return $ this -> line_size ; }
Get the table lines size
828
public function getTableCellSize ( ) { if ( $ this -> column_size === 0 && $ this -> line_size === 0 && $ this -> cell_size === 0 ) { $ this -> _parseTableSizes ( ) ; } return $ this -> cell_size ; }
Get the table cells size
829
public function getSizesInfos ( ) { if ( $ this -> column_size === 0 && $ this -> line_size === 0 && $ this -> cell_size === 0 ) { $ this -> _parseTableSizes ( ) ; } return sprintf ( self :: $ default_foot_mask , $ this -> getColumnSize ( ) , $ this -> getLineSize ( ) , $ this -> getCellSize ( ) ) ; }
Get a string information presenting an overview of the table
830
protected function _setPart ( array $ contents , $ part ) { if ( property_exists ( $ this , $ part ) ) { $ this -> { $ part } = $ this -> _getSetOfLines ( $ contents ) ; $ this -> _parseTableSizes ( true ) ; } elseif ( ! in_array ( $ part , self :: $ _table_parts ) ) { throw new InvalidArgumentException ( sprintf ( 'Unknown table part "%s"!' , $ part ) ) ; } }
Set a table part lines
831
protected function _setPartLine ( array $ contents , $ line_index , $ part , $ action = 'replace' ) { if ( property_exists ( $ this , $ part ) ) { if ( is_null ( $ line_index ) ) { end ( $ this -> { $ part } ) ; $ line_index = key ( $ this -> { $ part } ) + 1 ; } else { $ line_index -- ; } if ( $ line_index < $ this -> getLineSize ( ) && 'insert' === $ action ) { $ table_part = $ this -> { $ part } ; array_splice ( $ table_part , $ line_index , 0 , array ( $ this -> _getPaddedLine ( $ contents ) ) ) ; $ this -> { $ part } = $ table_part ; $ this -> _repadAllLines ( ) ; } else { $ this -> { $ part } [ $ line_index ] = $ this -> _getPaddedLine ( $ contents ) ; } $ this -> _parseTableSizes ( true ) ; } elseif ( ! in_array ( $ part , self :: $ _table_parts ) ) { throw new InvalidArgumentException ( sprintf ( 'Unknown table part "%s"!' , $ part ) ) ; } }
Set a single table part line
832
protected function _setPartColumn ( array $ contents , $ column_index , $ default , $ part , $ action = 'replace' ) { if ( property_exists ( $ this , $ part ) ) { if ( is_null ( $ column_index ) || $ column_index > $ this -> getColumnSize ( ) ) { $ column_index = $ this -> getColumnSize ( ) ; } else { $ column_index -- ; } foreach ( $ this -> { $ part } as $ i => $ line ) { $ value = isset ( $ contents [ $ i ] ) ? $ contents [ $ i ] : $ default ; if ( $ column_index < $ this -> getColumnSize ( ) && 'insert' === $ action ) { array_splice ( $ line , $ column_index , 0 , array ( $ value ) ) ; $ this -> { $ part } [ $ i ] = $ line ; } else { $ line [ $ column_index ] = $ value ; $ this -> { $ part } [ $ i ] = $ line ; } } $ this -> _repadAllLines ( ) ; } elseif ( ! in_array ( $ part , self :: $ _table_parts ) ) { throw new InvalidArgumentException ( sprintf ( 'Unknown table part "%s"!' , $ part ) ) ; } }
Set a single table part column
833
protected function _setPartCell ( $ content , $ line_index , $ cell_index , $ part , $ action = 'replace' ) { if ( property_exists ( $ this , $ part ) ) { if ( is_null ( $ line_index ) ) { end ( $ this -> { $ part } ) ; $ line_index = key ( $ this -> { $ part } ) ; } else { $ line_index -- ; } if ( is_null ( $ cell_index ) ) { if ( isset ( $ this -> { $ part } [ $ line_index ] ) ) { end ( $ this -> { $ part } [ $ line_index ] ) ; $ cell_index = key ( $ this -> { $ part } [ $ line_index ] ) ; } else { $ cell_index = 0 ; } } else { $ cell_index -- ; } if ( $ cell_index < $ this -> getCellSize ( ) && 'insert' === $ action ) { $ line = $ this -> { $ part } [ $ line_index ] ; array_splice ( $ line , $ cell_index , 0 , array ( $ content ) ) ; $ this -> { $ part } [ $ i ] = $ line ; $ this -> _repadAllLines ( ) ; } else { $ this -> { $ part } [ $ line_index ] [ $ cell_index ] = $ content ; } $ this -> _parseTableSizes ( true ) ; } elseif ( ! in_array ( $ part , self :: $ _table_parts ) ) { throw new InvalidArgumentException ( sprintf ( 'Unknown table part "%s"!' , $ part ) ) ; } }
Set a single table part cell
834
protected function _getPart ( $ part ) { if ( property_exists ( $ this , $ part ) ) { return $ this -> { $ part } ; } elseif ( ! in_array ( $ part , self :: $ _table_parts ) ) { throw new InvalidArgumentException ( sprintf ( 'Unknown table part "%s"!' , $ part ) ) ; } }
Get a table part lines array
835
protected function _getPartLine ( $ line_index , $ part ) { if ( property_exists ( $ this , $ part ) ) { if ( is_null ( $ line_index ) ) { $ column_index = $ this -> getLineSize ( ) ; } else { $ line_index -- ; } return isset ( $ this -> { $ part } [ $ line_index ] ) ? $ this -> { $ part } [ $ line_index ] : null ; } elseif ( ! in_array ( $ part , self :: $ _table_parts ) ) { throw new InvalidArgumentException ( sprintf ( 'Unknown table part "%s"!' , $ part ) ) ; } }
Get a single table part line
836
protected function _getPartColumn ( $ column_index , $ part ) { if ( property_exists ( $ this , $ part ) ) { if ( is_null ( $ column_index ) ) { $ column_index = $ this -> getColumnSize ( ) ; } else { $ column_index -- ; } $ column = array ( ) ; foreach ( $ this -> tbody as $ line ) { $ column [ ] = isset ( $ line [ $ column_index ] ) ? $ line [ $ column_index ] : '' ; } return $ column ; } elseif ( ! in_array ( $ part , self :: $ _table_parts ) ) { throw new InvalidArgumentException ( sprintf ( 'Unknown table part "%s"!' , $ part ) ) ; } }
Get a column of the table body
837
protected function _getPartCell ( $ line_index , $ cell_index , $ part ) { if ( property_exists ( $ this , $ part ) ) { if ( is_null ( $ line_index ) ) { $ line_index = $ this -> getLineSize ( ) ; } else { $ line_index -- ; } if ( is_null ( $ cell_index ) ) { if ( isset ( $ this -> { $ part } [ $ line_index ] ) ) { end ( $ this -> { $ part } [ $ line_index ] ) ; $ cell_index = key ( $ this -> { $ part } [ $ line_index ] ) ; } else { $ cell_index = 0 ; } } else { $ cell_index -- ; } return isset ( $ this -> { $ part } [ $ line_index ] [ $ cell_index ] ) ? $ this -> { $ part } [ $ line_index ] [ $ cell_index ] : null ; } elseif ( ! in_array ( $ part , self :: $ _table_parts ) ) { throw new InvalidArgumentException ( sprintf ( 'Unknown table part "%s"!' , $ part ) ) ; } }
Get a single table part cell
838
protected function _getSetOfLines ( $ content ) { if ( ! is_array ( $ content ) ) $ content = array ( $ content ) ; reset ( $ content ) ; if ( ! is_array ( current ( $ content ) ) ) { $ content = array ( 0 => $ content ) ; } return $ content ; }
This rebuilds an array to a multi - dimensional array of arrays if necessary
839
protected function _repadAllLines ( ) { $ this -> _parseTableSizes ( true ) ; foreach ( self :: $ _table_parts as $ part ) { if ( ! empty ( $ this -> { $ part } ) && is_array ( $ this -> { $ part } ) ) { foreach ( $ this -> { $ part } as $ l => $ part_line ) { if ( ! empty ( $ part_line ) && count ( $ part_line ) !== $ this -> getColumnSize ( ) ) { $ this -> { $ part } [ $ l ] = $ this -> _getPaddedLine ( $ part_line ) ; } } } } }
Recalculation of each line when the cell count has changed
840
protected function _getPaddedLine ( $ content ) { if ( ! is_array ( $ content ) ) $ content = array ( $ content ) ; if ( $ this -> column_size === 0 && $ this -> line_size === 0 && $ this -> cell_size === 0 ) { $ this -> _parseTableSizes ( ) ; } if ( count ( $ content ) > $ this -> getColumnSize ( ) ) { $ this -> _repadAllLines ( ) ; } elseif ( count ( $ content ) < $ this -> getColumnSize ( ) && ( $ this -> getPadFlag ( ) & self :: PAD_BY_EMPTY_CELLS ) ) { $ content = array_pad ( $ content , $ this -> getColumnSize ( ) , '' ) ; } return $ content ; }
This completes a line if necessary with empty cells
841
protected function _parseTableSizes ( $ reset = false ) { if ( $ reset ) $ this -> _resetSizes ( ) ; $ this -> line_size = count ( $ this -> tbody ) ; foreach ( self :: $ _table_parts as $ part ) { if ( ! empty ( $ this -> { $ part } ) && is_array ( $ this -> { $ part } ) ) { foreach ( $ this -> { $ part } as $ part_line ) { $ line_cells_count = 0 ; foreach ( $ part_line as $ part_cell ) { $ line_length = strlen ( $ part_cell ) + 2 ; if ( $ line_length > $ this -> cell_size ) { $ this -> cell_size = $ line_length ; } $ line_cells_count ++ ; } if ( $ line_cells_count > $ this -> column_size ) { $ this -> column_size = $ line_cells_count ; } } } } }
Calculation of all table sizes
842
public function render ( $ str_pad_flag = STR_PAD_RIGHT ) { $ stacks = array ( ) ; if ( $ this -> column_size === 0 && $ this -> line_size === 0 && $ this -> cell_size === 0 ) { $ this -> _parseTableSizes ( ) ; } foreach ( self :: $ _table_parts as $ part ) { if ( ! empty ( $ this -> { $ part } ) && is_array ( $ this -> { $ part } ) ) { $ stacks [ ] = 'hseparator' ; foreach ( $ this -> { $ part } as $ part_line ) { $ stack_line = array ( ) ; $ stack_line [ ] = 'vseparator' ; foreach ( $ part_line as $ i => $ part_cell ) { if ( count ( $ part_line ) < $ this -> getColumnSize ( ) && $ i === count ( $ part_line ) - 1 ) { $ stack_line [ ] = str_pad ( ' ' . $ part_cell , ( ( $ this -> getColumnSize ( ) - count ( $ part_line ) + 1 ) * $ this -> getCellSize ( ) ) + ( $ this -> getColumnSize ( ) - count ( $ part_line ) ) , ' ' , $ str_pad_flag ) ; } else { $ stack_line [ ] = ' ' . $ part_cell . ' ' ; } $ stack_line [ ] = 'vseparator' ; } $ stacks [ ] = $ stack_line ; } } } $ stacks [ ] = 'hseparator' ; if ( ! count ( $ this -> tfoot ) ) { $ stacks [ ] = array ( 'vseparator' , str_pad ( ' ' . $ this -> getSizesInfos ( ) , ( $ this -> getColumnSize ( ) * $ this -> getCellSize ( ) ) + ( $ this -> getColumnSize ( ) - 1 ) , ' ' , $ str_pad_flag ) , 'vseparator' ) ; $ stacks [ ] = 'hseparator' ; } $ str = '' ; if ( ! empty ( $ this -> title ) ) { $ str .= $ this -> title . "\n" ; } foreach ( $ stacks as $ line ) { $ str .= "\n" ; if ( is_array ( $ line ) ) { foreach ( $ line as $ cell ) { if ( 'vseparator' === $ cell ) { $ str .= '|' ; } else { $ str .= str_pad ( $ cell , $ this -> getCellSize ( ) , ' ' , $ str_pad_flag ) ; } } } elseif ( 'hseparator' === $ line ) { for ( $ i = 0 ; $ i < $ this -> getColumnSize ( ) ; $ i ++ ) { $ str .= str_pad ( '+' , ( $ this -> getCellSize ( ) + 1 ) , '-' ) ; } $ str .= '+' ; } } return $ str ; }
Plain text rendering of the table
843
public function add ( $ pField , $ pType , $ pValue = NULL ) { if ( $ pField == ItemInterface :: IDFIELD ) { if ( ! is_array ( $ pValue ) and ! $ pValue instanceof Id ) { $ id = new Id ( $ pValue ) ; $ pValue = $ id -> getOrig ( ) ; } else if ( is_array ( $ pValue ) ) { if ( empty ( $ pValue ) ) { throw new Exception ( "Trying to set an invalid condition value (`$pField`)" ) ; } foreach ( $ pValue as & $ value ) { if ( ! $ value instanceof Id ) { $ id = new Id ( $ value ) ; $ value = $ id -> getOrig ( ) ; } } } } if ( $ pType !== static :: IN and $ pType !== static :: NOTIN ) { $ pValue = ( string ) $ pValue ; } else if ( ( $ pType === static :: IN or $ pType === static :: NOTIN ) and ! is_array ( $ pValue ) ) { throw new Exception ( "Trying to set an invalid condition value (`$pField`)" ) ; } if ( static :: EQ == $ pType ) { $ this -> _conditions [ $ pField ] = $ pValue ; } else { $ this -> _conditions [ $ pField ] = array ( $ pType => $ pValue ) ; } return $ this ; }
Add a new condition .
844
public function firstOrCreate ( array $ where ) { $ this -> applyCriteria ( ) ; $ this -> applyScope ( ) ; $ model = $ this -> model -> firstOrCreate ( $ where ) ; $ this -> resetModel ( ) ; event ( new RepositoryEntityCreated ( $ this , $ model ) ) ; return $ this -> parserResult ( $ model ) ; }
Find data by multiple fields or create if not exists .
845
public function createOrUpdate ( array $ where , array $ attributes ) { $ this -> applyCriteria ( ) ; $ this -> applyScope ( ) ; $ _skipPresenter = $ this -> skipPresenter ; $ this -> skipPresenter ( true ) ; $ model = $ this -> model -> firstOrCreate ( $ where ) ; $ model -> fill ( $ attributes ) ; $ model -> save ( ) ; $ this -> skipPresenter ( $ _skipPresenter ) ; $ this -> resetModel ( ) ; event ( new RepositoryEntityUpdated ( $ this , $ model ) ) ; return $ this -> parserResult ( $ model ) ; }
Find data by multiple fields and update or create if not exists .
846
public function onKernelRequest ( ) { $ token = $ this -> tokenStorage -> getToken ( ) ; if ( ! $ token ) { return ; } if ( ! $ token instanceof UsernamePasswordToken ) { return ; } if ( $ token -> getProviderKey ( ) != 'backoffice' ) { return ; } $ filter = $ this -> entityManager -> getFilters ( ) -> enable ( 'node_publication_filter' ) ; $ filter -> setApplyPublication ( false ) ; }
Enable the NodePublicationFilter when not in the backoffice ..
847
public static function GetPhpIniSizeLimit ( $ iniVarName ) { $ rawIniValue = @ ini_get ( $ iniVarName ) ; if ( $ rawIniValue === FALSE ) { return 0 ; } else if ( $ rawIniValue === NULL ) { return NULL ; } $ unit = strtoupper ( substr ( $ rawIniValue , - 1 ) ) ; $ multiplier = ( $ unit == 'M' ? 1048576 : ( $ unit == 'K' ? 1024 : ( $ unit == 'G' ? 1073741824 : 1 ) ) ) ; return intval ( $ multiplier * floatval ( $ rawIniValue ) ) ; }
Get PHP data limit as integer value by given PHP INI variable name .
848
public static function & GetById ( $ formId ) { if ( isset ( self :: $ instances [ $ formId ] ) ) { return self :: $ instances [ $ formId ] ; } else { throw new \ RuntimeException ( 'No form instance exists under form id `' . $ formId . '`.' . ' Check if searched form instance has been already initialized' . ' or if form id has been already set.' ) ; } }
Get form instance by form id string . If no form instance found thrown an RuntimeException .
849
public static function & GetAutoFocusedFormField ( $ formId , $ fieldName ) { if ( self :: $ autoFocusedFormField ) { list ( $ currentFormId , $ currentFieldName ) = self :: $ autoFocusedFormField ; return self :: GetById ( $ currentFormId ) -> GetField ( $ currentFieldName ) ; } return NULL ; }
Get form field instance with defined autofocus boolean attribute . If there is no field in any form with this attribute return NULL .
850
public function mergeFeatures ( array $ features ) { foreach ( $ features as $ feature ) { $ this -> storeToAll ( $ feature ) ; $ this -> storeToCanonical ( $ feature ) ; } }
Merges the given features into this set
851
protected function storeToAll ( FeatureInterface $ feature ) { $ name = $ feature -> getName ( ) ; if ( ! isset ( $ this -> all [ $ name ] ) ) { $ this -> all [ $ name ] = [ ] ; } $ this -> all [ $ name ] [ $ feature -> getProvider ( ) -> getName ( ) ] = $ feature ; }
Stores the given feature to the array of all encountered features
852
protected function storeToCanonical ( FeatureInterface $ feature ) { $ name = $ feature -> getName ( ) ; $ was = $ this -> getFeature ( $ name ) ; $ new = $ feature -> resolve ( $ was ) ; $ this -> canonical [ $ name ] = $ new ; if ( $ was !== $ new ) { $ this -> logger -> debug ( 'New canonical feature: {feature} from {provider}, {was} -> {new}' , [ 'feature' => $ name , 'provider' => $ feature -> getProvider ( ) -> getName ( ) , 'was' => Status :: $ messages [ $ was -> getStatus ( ) ] , 'new' => Status :: $ messages [ $ this -> canonical [ $ name ] -> getStatus ( ) ] ] ) ; } }
Conditionally marks a feature instance as canonical for a name
853
public function exportList ( Array $ list ) { $ that = $ this ; return sprintf ( 'array(%s)' , A :: implode ( $ list , ',' , function ( $ item ) use ( $ that ) { if ( is_array ( $ item ) ) { return $ that -> exportList ( $ item ) ; } elseif ( $ item instanceof \ stdClass ) { return $ that -> exportStdClass ( $ item , 'list' ) ; } else { return $ that -> exportValue ( $ item ) ; } } ) ) ; }
Nimmt einen Array und exportiert diesen in einer Zeile
854
public function exportKeyList ( Array $ array , $ type = 'keyList' ) { $ that = $ this ; return sprintf ( 'array(%s)' , A :: implode ( $ array , ',' , function ( $ item , $ key ) use ( $ that , $ type ) { if ( is_array ( $ item ) ) { $ value = $ type === 'keyList' ? $ that -> exportKeyList ( $ item ) : $ that -> exportList ( $ item ) ; } elseif ( $ item instanceof \ stdClass ) { $ value = $ that -> exportStdClass ( $ item , 'keyList' ) ; } else { $ value = $ that -> exportValue ( $ item ) ; } return sprintf ( '%s=>%s' , var_export ( ( string ) $ key , TRUE ) , $ value ) ; } ) ) ; }
Sowie exportList jedoch setzt dieses auch die Keys
855
public function getOrderForSeller ( Profile $ seller ) { foreach ( $ this -> getOrders ( ) as $ order ) { if ( $ order -> getSeller ( ) -> getId ( ) == $ seller -> getId ( ) ) { return $ order ; } } return $ this -> createOrderForSeller ( $ seller ) ; }
Get Order for given Seller
856
public function createOrderForSeller ( Profile $ seller ) { $ order = new Order ( ) ; $ order -> setSeller ( $ seller ) ; if ( $ this -> getBuyer ( ) ) { $ order -> setBuyer ( $ this -> getBuyer ( ) ) ; } $ this -> addOrder ( $ order ) ; return $ order ; }
Create Order for given Seller
857
public function load ( $ resource , $ type = null ) { $ configs = Yaml :: parse ( $ resource ) ; return $ this -> createSchemas ( $ configs ) ; }
Loads the schemas configurations resource file .
858
public function getTable ( ) { if ( isset ( $ this -> table ) ) { return $ this -> table ; } return snake_case ( array_pop ( explode ( '\\' , get_class ( $ this ) ) ) ) ; }
When automapping the table name use singular case rather than plural .
859
public function getType ( $ kebabCase = false ) { if ( $ kebabCase ) { return strtolower ( str_replace ( '_' , '-' , $ this -> getTable ( ) ) ) ; } return strtoupper ( $ this -> getTable ( ) ) ; }
Get this Entity s type .
860
private static function isValidOrigin ( RequestInterface $ request ) : bool { if ( ! self :: compareHeaderUrl ( $ request , 'Origin' ) ) { return false ; } if ( ! self :: compareHeaderUrl ( $ request , 'Referer' ) ) { return false ; } return true ; }
Checks if the request has valid origin headers present .
861
private static function compareHeaderUrl ( RequestInterface $ request , string $ headerName ) : bool { $ headerValue = $ request -> getHeader ( $ headerName ) ; if ( $ headerValue === null ) { return true ; } $ headerUrl = Url :: tryParse ( $ headerValue ) ; if ( $ headerUrl === null ) { return false ; } return $ headerUrl -> getHost ( ) -> equals ( $ request -> getUrl ( ) -> getHost ( ) ) ; }
Compares a header url with the url in the request .
862
public function encode ( JWT $ jwt ) { $ this -> jwt = $ jwt ; $ token = Codec :: encode ( $ jwt -> getClaims ( ) , $ this -> secret ) ; return $ token ; }
Encodes given JWT
863
public function decode ( $ token ) { $ jwt = new JWT ( ) ; try { $ decoded = Codec :: decode ( $ token , $ this -> secret , [ 'HS256' ] ) ; } catch ( \ Firebase \ JWT \ SignatureInvalidException $ e ) { $ jwt -> setSignatureValid ( false ) ; } catch ( \ Exception $ e ) { } list ( $ header , $ payload , $ signature ) = explode ( "." , $ token ) ; $ header = base64_decode ( $ header ) ; $ payload = json_decode ( base64_decode ( $ payload ) ) ; $ signature = base64_decode ( $ signature ) ; $ jwt -> setStart ( new \ DateTime ( '@' . $ payload -> nbf ) ) ; $ jwt -> setEnd ( new \ Datetime ( '@' . $ payload -> exp ) ) ; foreach ( $ payload -> data as $ key => $ value ) { $ jwt -> set ( $ key , $ value ) ; } return $ jwt ; }
Decodes given token
864
public function savePriority ( ) { $ ITER = 1 ; $ metaTable = TableRegistry :: get ( 'CmsContentMeta' ) ; if ( $ this -> request -> is ( 'post' ) ) : $ items = explode ( ',' , $ this -> request -> data [ 'order' ] ) ; foreach ( $ items as $ id ) : $ meta = $ metaTable -> get ( $ id ) ; $ meta -> priority = $ ITER ++ ; $ metaTable -> save ( $ meta ) ; endforeach ; endif ; exit ( 'ok' ) ; }
This function is invoked in AJAX to save the priority sorting
865
public function actionIndex ( $ page = 1 ) { $ sort = [ ] ; $ params = Yii :: $ app -> request -> queryParams ; if ( empty ( $ params [ 'sort' ] ) ) { $ sort [ 'defaultOrder' ] = [ 'parent_uid' => SORT_ASC , 'module_id' => SORT_ASC ] ; } else { if ( $ params [ 'sort' ] == 'module_id' ) { $ sort [ 'defaultOrder' ] = [ 'parent_uid' => SORT_ASC , 'module_id' => SORT_ASC ] ; unset ( $ params [ 'sort' ] ) ; } else if ( $ params [ 'sort' ] == '-module_id' ) { $ sort [ 'defaultOrder' ] = [ 'parent_uid' => SORT_DESC , 'module_id' => SORT_DESC ] ; unset ( $ params [ 'sort' ] ) ; } Yii :: $ app -> request -> setQueryParams ( $ params ) ; } $ dataProvider = new ActiveDataProvider ( [ 'query' => Modmgr :: find ( ) , 'sort' => $ sort , ] ) ; $ pager = $ dataProvider -> getPagination ( ) ; $ pager -> pageSize = $ this -> pageSize ; $ pager -> page = $ page - 1 ; return $ this -> render ( 'index' , [ 'dataProvider' => $ dataProvider , ] ) ; }
Lists all Modmgr models .
866
public function actionRebuildDefaultConfig ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ configDefault = $ model -> buildDefaultConfig ( $ model -> module_class ) ; $ model -> config_default = var_export ( $ configDefault , true ) ; $ model -> save ( true , [ 'config_default' ] ) ; return $ model -> config_default ; }
Rebuild default module config . Use in ajax request .
867
public function actionCreate ( $ parent = 0 ) { $ installModel = new CreateModule ( [ 'tc' => $ this -> module -> tcModule ] ) ; $ post = Yii :: $ app -> request -> post ( ) ; if ( empty ( $ post ) ) { $ installModel -> loadDefaultValues ( ) ; $ installModel -> parentUid = ModulesManager :: numberedIdFromDbId ( $ parent ) ; } else { $ installModel -> load ( $ post ) ; $ installModel -> moduleClassFile = UploadedFile :: getInstance ( $ installModel , 'moduleClassFile' ) ; $ result = $ installModel -> validate ( ) ; if ( $ result ) { $ modelManager = new Modmgr ( ) ; $ modelManager -> loadData ( $ installModel ) ; if ( ! $ modelManager -> hasErrors ( ) && $ modelManager -> save ( ) ) { return $ this -> redirect ( [ 'update' , 'id' => $ modelManager -> id ] ) ; } foreach ( $ modelManager -> errors as $ attribute => $ errors ) { if ( $ attribute == 'module_id' ) { foreach ( $ errors as $ error ) $ installModel -> addError ( 'moduleId' , $ error ) ; } elseif ( $ attribute == 'module_class' ) { foreach ( $ errors as $ error ) $ installModel -> addError ( 'moduleClassFile' , $ error ) ; } else { foreach ( $ errors as $ error ) $ installModel -> addError ( 'moduleClassFile' , $ error ) ; } } } } return $ this -> render ( 'create' , [ 'model' => $ installModel , ] ) ; }
Creates a new Modmgr model . If creation is successful the browser will be redirected to the view page .
868
public function actionUpdate ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ oldSubmodulesParentUid = $ model -> parent_uid . '/{' . $ model -> id . '}' ; $ post = Yii :: $ app -> request -> post ( ) ; $ loaded = $ model -> load ( $ post ) ; if ( $ loaded && $ model -> save ( ) ) { $ newSubmodulesParentUid = $ model -> parent_uid . '/{' . $ model -> id . '}' ; $ model -> correctParents ( $ oldSubmodulesParentUid , $ newSubmodulesParentUid ) ; return $ this -> redirect ( [ 'index' , 'id' => $ model -> id ] ) ; } else { return $ this -> render ( 'update' , [ 'model' => $ model , ] ) ; } }
Updates an existing Modmgr model . If update is successful the browser will be redirected to the view page .
869
public function actionDelete ( $ id ) { $ model = $ this -> findModel ( $ id ) ; if ( $ model -> is_active == false ) { $ model -> delete ( ) ; Yii :: $ app -> session -> setFlash ( 'success' , Yii :: t ( $ this -> tcModule , "Module has been deleted" ) ) ; } else { Yii :: $ app -> session -> setFlash ( 'error' , Yii :: t ( $ this -> tcModule , "Can't delete active module" ) ) ; } $ params = Yii :: $ app -> request -> getQueryParams ( ) ; $ params [ 'id' ] = $ model -> id ; $ params [ ] = 'index' ; return $ this -> redirect ( $ params ) ; }
Deletes an existing Modmgr model . If deletion is successful the browser will be redirected to the index page .
870
public function actionChangeActive ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ model -> is_active = $ model -> is_active ? false : true ; $ model -> save ( ) ; Yii :: $ app -> session -> setFlash ( 'success' , Yii :: t ( $ this -> tcModule , "Module's activity has been changed" ) ) ; $ params = Yii :: $ app -> request -> getQueryParams ( ) ; $ params [ 'id' ] = $ model -> id ; $ params [ ] = 'index' ; return $ this -> redirect ( $ params ) ; }
Change is_active model attribute .
871
public function setModelName ( $ modelName ) { if ( ! class_exists ( $ modelName ) ) throw new Exception ( "Model '{$modelName}' could not be found" ) ; $ model = new \ ReflectionClass ( $ modelName ) ; if ( ! $ model -> implementsInterface ( '\Phalcon\Mvc\ModelInterface' ) ) throw new Exception ( "'{$modelName}' must be an instance of Phalcon\Mvc\ModelInterface" ) ; $ this -> modelname = $ modelName ; return $ this ; }
Set Modelname - must implement Phalcon \ Mvc \ ModelInterface
872
public function getThumbnail ( $ originalImagePath , $ type ) { if ( array_key_exists ( $ type , $ this -> getTypes ( ) ) ) { return preg_replace ( '#^(.*)\.(' . implode ( '|' , $ this -> getAllowedExtensions ( ) ) . ')$#' , '$1-' . $ this -> getThumbnailPrefix ( ) . '-' . $ type . '.$2' , $ originalImagePath ) ; } return false ; }
Get thumbnail path from original image path
873
public function cleanThumbnails ( $ path = '' ) { $ cleanPathInfo = new SplFileInfo ( realpath ( $ this -> getDocumentRoot ( ) . DIRECTORY_SEPARATOR . $ path ) ) ; if ( strpos ( $ cleanPathInfo -> getRealPath ( ) , $ this -> getDocumentRoot ( ) ) === 0 ) { if ( $ cleanPathInfo -> isDir ( ) ) { $ dirIterator = new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ cleanPathInfo -> getRealPath ( ) ) , RecursiveIteratorIterator :: SELF_FIRST ) ; foreach ( $ dirIterator as $ path => $ splFileObject ) { if ( ! in_array ( $ splFileObject -> getBasename ( ) , [ '.' , '..' ] ) && preg_match ( '#.*-' . $ this -> getThumbnailPrefix ( ) . '-([\w\d]+)\.(' . implode ( '|' , $ this -> getAllowedExtensions ( ) ) . ')$#' , $ splFileObject -> getBasename ( ) ) ) { unlink ( $ splFileObject -> getRealPath ( ) ) ; } } return true ; } elseif ( $ cleanPathInfo -> isFile ( ) && in_array ( $ cleanPathInfo -> getExtension ( ) , $ this -> getAllowedExtensions ( ) ) ) { $ imagePathRemExt = $ cleanPathInfo -> getPath ( ) . DIRECTORY_SEPARATOR . $ cleanPathInfo -> getBasename ( '.' . $ cleanPathInfo -> getExtension ( ) ) ; $ thumbnails = glob ( $ imagePathRemExt . '-' . $ this -> getThumbnailPrefix ( ) . '-*' ) ; foreach ( $ thumbnails as $ thumbnailPath ) { unlink ( $ thumbnailPath ) ; } return true ; } } return false ; }
Clean thumbnails for specified thumbnails directory or image Directory or image must exist
874
public function get ( $ name ) { if ( $ this -> cache -> has ( $ name ) ) { return $ this -> loader -> load ( $ this -> cache -> get ( $ name ) ) ; } if ( ! $ this -> cache -> isFresh ( ) ) { $ this -> refresh ( ) ; return $ this -> get ( $ name ) ; } throw new \ InvalidArgumentException ( sprintf ( 'Unknown resource named "%s" for the host "%s"' , $ name , $ this -> host ) ) ; }
Return the definition for the given resource name
875
public function keys ( ) { $ names = $ this -> cache -> keys ( ) ; if ( empty ( $ names ) && ! $ this -> cache -> isFresh ( ) ) { $ this -> refresh ( ) ; return $ this -> keys ( ) ; } return $ names ; }
Return all the resource names
876
public function refresh ( ) { $ url = $ this -> resolver -> resolve ( $ this -> host , '/*' ) ; $ response = $ this -> http -> options ( $ url , [ 'headers' => [ 'Accept' => 'application/json' , ] , ] ) ; if ( $ response -> getStatusCode ( ) !== 200 || ! $ response -> hasHeader ( 'Link' ) ) { throw new CapabilitiesException ( sprintf ( 'Couldn\'t retrieve "%s" capabilities' , $ this -> host ) ) ; } foreach ( $ this -> cache -> keys ( ) as $ key ) { $ this -> cache -> remove ( $ key ) ; } $ links = Response :: parseHeader ( $ response , 'Link' ) ; foreach ( $ links as $ link ) { if ( isset ( $ link [ 'rel' ] ) && $ link [ 'rel' ] === 'endpoint' ) { $ url = $ this -> resolver -> resolve ( $ this -> host , substr ( $ link [ 0 ] , 1 , - 1 ) ) ; $ this -> cache -> save ( $ link [ 'name' ] , $ url ) ; } } return $ this ; }
Reload all the resource names available for the server
877
public function createField ( $ dbQuery , $ entity , $ param = null , $ identifier = null ) { if ( class_exists ( $ this -> fieldClass ) ) { $ this -> field = new $ this -> fieldClass ( $ dbQuery , $ entity , $ param , $ identifier ) ; } else { e ( 'Class (##) not found' , E_SAMSON_CORE_ERROR , $ this -> fieldClass ) ; } return $ this ; }
Create field class instance
878
public function __async_save ( ) { $ response = array ( 'status' => 0 ) ; if ( isset ( $ _POST ) ) { $ entity = & $ _POST [ '__entity' ] ; $ param = & $ _POST [ '__param' ] ; $ identifier = & $ _POST [ '__obj_id' ] ; $ value = & $ _POST [ '__value' ] ; if ( ! isset ( $ value ) ) { e ( 'CMSField - no "value" is passed for saving' , E_SAMSON_CORE_ERROR ) ; } if ( ! isset ( $ entity ) ) { e ( 'CMSField - no "entity" is passed for saving' , E_SAMSON_CORE_ERROR ) ; } if ( ! isset ( $ identifier ) ) { e ( 'CMSField - no "object identifier" is passed for saving' , E_SAMSON_CORE_ERROR ) ; } if ( ! isset ( $ param ) ) { e ( 'CMSField - no "object field name" is passed for saving' , E_SAMSON_CORE_ERROR ) ; } $ this -> createField ( new dbQuery ( ) , $ entity , $ param , $ identifier ) ; $ response [ 'status' ] = 1 ; $ this -> field -> save ( $ value , $ response ) ; } return $ response ; }
Save handler for CMS Field input
879
final public function ormToEntity ( $ data = [ ] , $ entity = '' ) { $ entities = [ ] ; foreach ( $ data as $ value ) { if ( $ entity != '' ) { $ entityName = '\entity\\' . $ entity ; $ entityObject = new $ entityName ( Database :: instance ( ) -> db ( ) ) ; foreach ( $ value as $ key => $ value2 ) { $ entityObject -> $ key = $ value2 ; } } else { $ entityObject = new Multiple ( $ data ) ; } array_push ( $ entities , $ entityObject ) ; } return $ entities ; }
transform sql data in Entity
880
public static function chainToCamel ( $ chain ) { self :: verifyString ( $ chain ) ; return lcfirst ( preg_replace ( '/ /' , '' , ucwords ( preg_replace ( '/[-]/' , ' ' , $ chain ) ) ) ) ; }
Converts chain - case to camelCase .
881
public function has_required_properties ( ) { return ( ! empty ( $ this -> plural_name ) && ! empty ( $ this -> post_type ) && ! empty ( $ this -> singular_name ) && ! empty ( $ this -> slug ) ) ; }
Determines if required properties are populated or not .
882
public function enumerateLinks ( $ alcontinue = false , $ alfrom = null , $ alto = null , $ alprefix = null , $ alunique = null , array $ alprop = null , $ alnamespace = null , $ allimit = null ) { $ path = '?action=query&meta=siteinfo' ; if ( $ alcontinue ) { $ path .= '&alcontinue=' ; } if ( isset ( $ alfrom ) ) { $ path .= '&alfrom=' . $ alfrom ; } if ( isset ( $ alto ) ) { $ path .= '&alto=' . $ alto ; } if ( isset ( $ alprefix ) ) { $ path .= '&alprefix=' . $ alprefix ; } if ( isset ( $ alunique ) ) { $ path .= '&alunique=' . $ alunique ; } if ( isset ( $ alprop ) ) { $ path .= '&alprop=' . $ this -> buildParameter ( $ alprop ) ; } if ( isset ( $ alnamespace ) ) { $ path .= '&alnamespace=' . $ alnamespace ; } if ( isset ( $ allimit ) ) { $ path .= '&allimit=' . $ allimit ; } $ response = $ this -> client -> get ( $ this -> fetchUrl ( $ path ) ) ; return $ this -> validateResponse ( $ response ) ; }
Method to enumerate all links that point to a given namespace .
883
public function saveMultiple ( array $ objects ) { array_walk ( $ objects , [ $ this , 'assertObjectInstance' ] ) ; return $ this -> manager -> getDriver ( ) -> inTransaction ( function ( Driver $ driver , array $ objects ) { return array_map ( [ $ this , 'save' ] , $ objects ) ; } , $ objects ) ; }
Save multiple objects into database
884
public function save ( $ object ) { $ this -> assertObjectInstance ( $ object ) ; $ state = $ this -> getState ( $ object ) ; if ( $ state -> isReadOnly ( ) ) { return null ; } $ relationsIterator = new \ ArrayIterator ( $ this -> getRelations ( ) ) ; $ modifiedManyManyRelations = $ this -> handleManyManyRelations ( $ state , $ relationsIterator ) ; $ this -> handleHasManyRelations ( $ state , $ relationsIterator ) ; $ this -> handleHasOneRelations ( $ state , $ relationsIterator ) ; switch ( $ state -> getObjectState ( ) ) { case EntityState :: STATE_NEW : $ primaryKey = $ this -> insert ( $ object ) ; break ; case EntityState :: STATE_NEW_WITH_PRIMARY_KEY : $ pkField = $ this -> getPrimaryKey ( ) ; $ primaryKey = $ state -> getOriginalFieldData ( $ pkField ) ; if ( $ this -> exists ( $ primaryKey ) ) { $ data = $ this -> toArray ( $ object ) ; if ( $ data [ $ pkField ] === $ primaryKey ) { unset ( $ data [ $ pkField ] ) ; } $ primaryKey = $ this -> update ( $ object , $ data ) ; } else { $ primaryKey = $ this -> insert ( $ object ) ; } break ; default : $ data = $ state -> getChangedFields ( ) ; $ primaryKey = $ this -> update ( $ object , $ data ) ; break ; } $ state -> setState ( EntityState :: STATE_HANDLED ) ; $ state -> refreshOriginalData ( ) ; $ this -> updateManyToManyRelations ( $ modifiedManyManyRelations , $ primaryKey ) ; return $ primaryKey ; }
Save an object to the database
885
static function init ( ) { elgg_register_event_handler ( 'pagesetup' , 'system' , array ( __CLASS__ , 'pagesetup' ) ) ; elgg_register_plugin_hook_handler ( 'register' , "menu:admin_control_panel" , array ( __CLASS__ , 'handlerAdminButtonsMenuRegister' ) ) ; elgg_register_action ( 'backup/db/save' , elgg_get_config ( 'pluginspath' ) . __CLASS__ . '/actions/backup/db/save.php' , 'admin' ) ; elgg_register_action ( 'backup/db/load' , elgg_get_config ( 'pluginspath' ) . __CLASS__ . '/actions/backup/db/load.php' , 'admin' ) ; }
Fired on system init
886
static function pagesetup ( ) { $ parent_id = 'administer_utilities' ; $ section = 'administer' ; if ( $ parent_id && ! elgg_is_menu_item_registered ( 'page' , $ parent_id ) ) { elgg_register_admin_menu_item ( $ section , $ parent_id ) ; } elgg_register_menu_item ( 'page' , array ( 'name' => 'backup/database' , 'href' => 'admin/backup/database' , 'text' => elgg_echo ( 'admin:backup:database' ) , 'context' => 'admin' , 'parent_name' => $ parent_id , 'section' => $ section , ) ) ; }
Fired on system pagesetup
887
static function handlerAdminButtonsMenuRegister ( $ hook , $ type , $ menu , $ params ) { elgg_trigger_plugin_hook ( 'register' , "menu:$menu_name" , $ vars , $ menu ) ; $ menu [ ] = ElggMenuItem :: factory ( array ( 'name' => 'backup/db/save' , 'href' => elgg_add_action_tokens_to_url ( 'action/backup/db/save' ) , 'text' => elgg_echo ( 'db_backup:button:quick' ) , 'link_class' => 'elgg-button elgg-button-action' , ) ) ; return $ menu ; }
Fired on admin_control_panel menu registration
888
static function execSystemCommand ( $ cmd , & $ return_code ) { if ( ! function_exists ( 'proc_open' ) || ! function_exists ( 'proc_close' ) ) { throw new RuntimeException ( "Process execution functions are missing!" ) ; } $ proc = proc_open ( $ cmd , array ( 0 => array ( 'pipe' , 'r' ) , 1 => array ( 'pipe' , 'w' ) , 2 => array ( 'pipe' , 'w' ) , ) , $ pipes ) ; if ( $ proc === false ) { throw new IOException ( "Error while calling proc_open" ) ; } $ output = stream_get_contents ( $ pipes [ 1 ] ) . ' ' . stream_get_contents ( $ pipes [ 2 ] ) ; $ return_code = proc_close ( $ proc ) ; return $ output ; }
Executes system command when possible
889
public static function registerSettingsGroup ( $ groupName , $ options ) { foreach ( $ options as $ section ) { add_settings_section ( $ section [ 'id' ] , $ section [ 'title' ] , $ section [ 'callback' ] , $ section [ 'page' ] ) ; foreach ( $ section [ 'fields' ] as $ field ) { register_setting ( $ groupName , $ field [ 'id' ] ) ; $ args = array ( 'label_for' => $ field [ 'id' ] , 'id' => $ field [ 'id' ] , 'type' => $ field [ 'type' ] , ) ; add_settings_field ( $ field [ 'id' ] , $ field [ 'title' ] , function ( $ args ) { if ( isset ( $ args [ 'type' ] ) ) { $ value = get_option ( $ args [ 'id' ] ) ; $ extraParams = '' ; switch ( $ args [ 'type' ] ) { case 'text' : case 'password' : case 'number' : break ; case 'checkbox' : $ extraParams = sprintf ( ' %s' , $ value ? 'checked="checked"' : '' ) ; $ value = 1 ; break ; default : $ args [ 'type' ] = 'text' ; break ; } } else { $ args [ 'type' ] = 'text' ; } echo sprintf ( '<input id="%s" type="%s" name="%s" value="%s" size="80" %s />' , $ args [ 'id' ] , $ args [ 'type' ] , $ args [ 'id' ] , $ value , $ extraParams ) ; } , $ section [ 'page' ] , $ section [ 'id' ] , $ args ) ; } } }
Scaffolds settings group sections and fields
890
private static function generateBytes ( $ length ) { $ bytes = '' ; for ( $ i = 1 ; $ i <= $ length ; $ i ++ ) { $ bytes = \ chr ( \ mt_rand ( 0 , 255 ) ) . $ bytes ; } return $ bytes ; }
Generates random bytes for use in version 4 UUIDs
891
protected function saveXML ( & $ data ) { $ this -> validateParameters ( ) ; $ xmldoc = new \ DOMDocument ( "1.0" , "UTF-8" ) ; $ xmldoc -> formatOutput = true ; $ root = $ xmldoc -> createElement ( "array" ) ; $ root = $ xmldoc -> appendChild ( $ root ) ; array_to_dom ( $ root , $ data ) ; $ xml = $ xmldoc -> saveXML ( ) ; if ( ! empty ( $ this -> save_encrypted ) ) { $ xml = aes_256_encrypt ( $ xml , $ this -> salt_key ) ; } if ( file_put_contents ( $ this -> save_path , $ xml ) === false ) { throw new \ Exception ( sprintf ( "The config file '%s' cannot be written!" , $ this -> save_path ) ) ; } return true ; }
This is internal auxiliary function for converting the settings to XML and storing it to the target file defined by the iniailization .
892
protected function loadXML ( & $ data ) { $ this -> validateParameters ( ) ; if ( ! file_exists ( $ this -> save_path ) && empty ( $ this -> config_file_must_exist ) ) { return true ; } if ( ! file_exists ( $ this -> save_path ) || ! is_readable ( $ this -> save_path ) ) { throw new \ Exception ( sprintf ( "The config file '%s' cannot be read!" , $ this -> save_path ) ) ; } $ xml = file_get_contents ( $ this -> save_path ) ; if ( $ xml === false ) { throw new \ Exception ( sprintf ( "The config file '%s' cannot be read!" , $ this -> save_path ) ) ; } if ( ! empty ( $ this -> save_encrypted ) ) { $ xml = aes_256_decrypt ( $ xml , $ this -> salt_key ) ; } $ xmldoc = new \ DOMDocument ( ) ; if ( ! @ $ xmldoc -> loadXML ( $ xml ) ) { throw new \ Exception ( sprintf ( "The config file '%s' is invalid!" , $ this -> save_path ) ) ; } dom_to_array ( $ xmldoc -> documentElement , $ data ) ; return true ; }
This is internal auxiliary function for loading the settings from the target file defined by the iniailization .
893
public function setParameter ( $ name , $ value ) { $ this -> temp_settings [ $ name ] = $ value ; $ this -> temp_settings [ "__dirty" ] [ $ this -> context ] = true ; }
Sets a settings parameter .
894
public function getParameter ( $ name , $ get_dirty = false , $ default = null ) { if ( $ get_dirty && $ this -> isDirty ( ) ) { if ( empty ( $ this -> temp_settings [ $ name ] ) ) { return null ; } return $ this -> temp_settings [ $ name ] ; } if ( ! isset ( $ this -> settings [ $ name ] ) ) { return $ default ; } return $ this -> settings [ $ name ] ; }
Returns the value of a settings parameter .
895
public function validateSettings ( ) { if ( empty ( $ this -> validator ) ) { return true ; } return $ this -> validator -> validate ( $ this , $ this -> context ) ; }
Validates the current settings values .
896
public function loadSettings ( ) { if ( $ this -> isDirty ( true ) ) { return true ; } $ this -> loadXML ( $ this -> settings ) ; $ this -> temp_settings = $ this -> settings ; unset ( $ this -> temp_settings [ "__dirty" ] ) ; return true ; }
Loads the settings from the target file .
897
public function saveSettings ( ) { $ old_dirty_state = $ this -> temp_settings [ "__dirty" ] ; unset ( $ this -> temp_settings [ "__dirty" ] ) ; try { $ this -> saveXML ( $ this -> temp_settings ) ; $ this -> settings = $ this -> temp_settings ; return true ; } catch ( \ Exception $ ex ) { $ this -> temp_settings [ "__dirty" ] = $ old_dirty_state ; throw new \ Exception ( $ ex -> getMessage ( ) , $ ex -> getErrorCode ( ) ) ; } }
Saves the settings from to the target file .
898
public function addManyToSet ( array $ values ) { $ this -> requiresCurrentField ( ) ; $ this -> newObj [ '$addToSet' ] [ $ this -> currentField ] = array ( '$each' => $ values ) ; return $ this ; }
Append multiple values to the current array field only if they do not already exist in the array .
899
public function push ( $ valueOrExpression ) { if ( $ valueOrExpression instanceof Expr ) { $ valueOrExpression = array_merge ( array ( '$each' => array ( ) ) , $ valueOrExpression -> getQuery ( ) ) ; } $ this -> requiresCurrentField ( ) ; $ this -> newObj [ '$push' ] [ $ this -> currentField ] = $ valueOrExpression ; return $ this ; }
Append one or more values to the current array field .