idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
31,300 | public function resizeAspectRatio ( $ newX , $ newY , $ fillRed = 255 , $ fillGreen = 255 , $ fillBlue = 255 ) { if ( ! is_numeric ( $ newX ) || ! is_numeric ( $ newY ) ) { throw new ImageUtilException ( 'There are no valid values' ) ; } $ image = $ this -> image ; if ( imagesy ( $ image ) >= $ newY || imagesx ( $ image ) >= $ newX ) { if ( imagesx ( $ image ) >= imagesy ( $ image ) ) { $ curX = $ newX ; $ curY = ( $ curX * imagesy ( $ image ) ) / imagesx ( $ image ) ; $ yyy = - ( $ curY - $ newY ) / 2 ; $ xxx = 0 ; } else { $ curY = $ newY ; $ curX = ( $ curY * imagesx ( $ image ) ) / imagesy ( $ image ) ; $ xxx = - ( $ curX - $ newX ) / 2 ; $ yyy = 0 ; } } else { $ curX = imagesx ( $ image ) ; $ curY = imagesy ( $ image ) ; $ yyy = 0 ; $ xxx = 0 ; } $ imw = imagecreatetruecolor ( $ newX , $ newY ) ; $ color = imagecolorallocate ( $ imw , $ fillRed , $ fillGreen , $ fillBlue ) ; imagefill ( $ imw , 0 , 0 , $ color ) ; imagealphablending ( $ imw , false ) ; imagecopyresampled ( $ imw , $ image , $ xxx , $ yyy , 0 , 0 , $ curX , $ curY , imagesx ( $ image ) , imagesy ( $ image ) ) ; $ this -> image = $ imw ; return $ this ; } | Resize the image but the aspect ratio is respected . The spaces left are filled with the RGB color provided . |
31,301 | public function writeText ( $ text , $ point , $ size , $ angle , $ font , $ maxwidth = 0 , $ rgbAr = null , $ textAlignment = 1 ) { if ( ! is_readable ( $ font ) ) { throw new ImageUtilException ( 'Error: The specified font not found' ) ; } if ( ! is_array ( $ rgbAr ) ) { $ rgbAr = [ 0 , 0 , 0 ] ; } $ color = imagecolorallocate ( $ this -> image , $ rgbAr [ 0 ] , $ rgbAr [ 1 ] , $ rgbAr [ 2 ] ) ; if ( ( $ maxwidth > 0 ) && ( $ angle == 0 ) ) { $ words = explode ( ' ' , $ text ) ; $ lines = [ $ words [ 0 ] ] ; $ currentLine = 0 ; $ numberOfWords = count ( $ words ) ; for ( $ i = 1 ; $ i < $ numberOfWords ; $ i ++ ) { $ lineSize = imagettfbbox ( $ size , 0 , $ font , $ lines [ $ currentLine ] . ' ' . $ words [ $ i ] ) ; if ( $ lineSize [ 2 ] - $ lineSize [ 0 ] < $ maxwidth ) { $ lines [ $ currentLine ] .= ' ' . $ words [ $ i ] ; } else { $ currentLine ++ ; $ lines [ $ currentLine ] = $ words [ $ i ] ; } } } else { $ lines = [ $ text ] ; } $ curX = $ point [ 0 ] ; $ curY = $ point [ 1 ] ; foreach ( $ lines as $ text ) { $ bbox = imagettfbbox ( $ size , $ angle , $ font , $ text ) ; switch ( $ textAlignment ) { case TextAlignment :: RIGHT : $ curX = $ point [ 0 ] - abs ( $ bbox [ 2 ] - $ bbox [ 0 ] ) ; break ; case TextAlignment :: CENTER : $ curX = $ point [ 0 ] - ( abs ( $ bbox [ 2 ] - $ bbox [ 0 ] ) / 2 ) ; break ; } imagettftext ( $ this -> image , $ size , $ angle , $ curX , $ curY , $ color , $ font , $ text ) ; $ curY += ( $ size * 1.35 ) ; } } | Writes a text on the image . |
31,302 | public function restore ( ) { $ this -> image = imagecreatetruecolor ( imagesx ( $ this -> orgImage ) , imagesy ( $ this -> orgImage ) ) ; imagecopy ( $ this -> image , $ this -> orgImage , 0 , 0 , 0 , 0 , imagesx ( $ this -> orgImage ) , imagesy ( $ this -> orgImage ) ) ; return $ this ; } | Discard any changes made to the image and restore the original state |
31,303 | public function makeTransparent ( $ transpRed = 255 , $ transpGreen = 255 , $ transpBlue = 255 ) { $ curX = imagesx ( $ this -> image ) ; $ curY = imagesy ( $ this -> image ) ; $ imw = imagecreatetruecolor ( $ curX , $ curY ) ; $ color = imagecolorallocate ( $ imw , $ transpRed , $ transpGreen , $ transpBlue ) ; imagefill ( $ imw , 0 , 0 , $ color ) ; imagecolortransparent ( $ imw , $ color ) ; imagecopyresampled ( $ imw , $ this -> image , 0 , 0 , 0 , 0 , $ curX , $ curY , $ curX , $ curY ) ; $ this -> image = $ imw ; return $ this ; } | Make transparent the image . The transparent color must be provided |
31,304 | public function define ( string $ definitionID , callable $ handler ) : \ BearFramework \ Tasks { $ this -> definitions [ $ definitionID ] = $ handler ; return $ this ; } | Defines a new task . |
31,305 | public function add ( string $ definitionID , $ data = null , array $ options = [ ] ) : \ BearFramework \ Tasks { $ app = App :: get ( ) ; $ taskID = isset ( $ options [ 'id' ] ) ? ( string ) $ options [ 'id' ] : uniqid ( ) ; $ listID = isset ( $ options [ 'listID' ] ) ? ( string ) $ options [ 'listID' ] : '' ; $ startTime = isset ( $ options [ 'startTime' ] ) ? ( int ) $ options [ 'startTime' ] : null ; $ this -> lockList ( $ listID ) ; $ list = $ this -> getListData ( $ listID ) ; if ( isset ( $ list [ $ taskID ] ) ) { $ this -> unlockList ( $ listID ) ; throw new \ Exception ( 'A task with the id "' . $ taskID . '" already exists in list named \'' . $ listID . '\'!' ) ; } $ list [ $ taskID ] = [ 1 , $ startTime ] ; $ this -> setListData ( $ listID , $ list ) ; $ taskData = [ 1 , $ definitionID , $ data ] ; $ app -> data -> setValue ( $ this -> getTaskDataKey ( $ taskID , $ listID ) , gzcompress ( json_encode ( $ taskData ) ) ) ; $ this -> unlockList ( $ listID ) ; $ this -> dispatchEvent ( 'addTask' ) ; return $ this ; } | Adds a new tasks . |
31,306 | public function addMultiple ( array $ tasks ) : \ BearFramework \ Tasks { $ taskLists = [ ] ; foreach ( $ tasks as $ index => $ task ) { if ( ! isset ( $ task [ 'definitionID' ] ) ) { throw new \ Exception ( 'The definitionID key is missing for task with index ' . $ index ) ; } if ( ! is_string ( $ task [ 'definitionID' ] ) ) { throw new \ Exception ( 'The definitionID key must be of type string for index ' . $ index ) ; } $ listID = '' ; $ startTime = null ; if ( isset ( $ task [ 'options' ] ) ) { if ( is_array ( $ task [ 'options' ] ) ) { if ( isset ( $ task [ 'options' ] [ 'listID' ] ) ) { $ listID = ( string ) $ task [ 'options' ] [ 'listID' ] ; } if ( isset ( $ task [ 'options' ] [ 'startTime' ] ) ) { $ startTime = ( int ) $ task [ 'options' ] [ 'startTime' ] ; } } else { throw new \ Exception ( 'The \'options\' key must be of type array for index ' . $ index ) ; } } if ( ! isset ( $ taskLists [ $ listID ] ) ) { $ taskLists [ $ listID ] = [ 'minStartTime' => null , 'data' => [ ] ] ; } if ( $ startTime !== null && ( $ taskLists [ $ listID ] [ 'minStartTime' ] === null || $ startTime < $ taskLists [ $ listID ] [ 'minStartTime' ] ) ) { $ taskLists [ $ listID ] [ 'minStartTime' ] = $ startTime ; } $ taskLists [ $ listID ] [ 'data' ] [ ] = $ task ; } foreach ( $ taskLists as $ listID => $ taskListData ) { $ options = [ ] ; $ options [ 'listID' ] = $ listID ; if ( $ taskListData [ 'minStartTime' ] !== null ) { $ options [ 'startTime' ] = $ taskListData [ 'minStartTime' ] ; } $ this -> add ( '--internal-add-multiple-task-definition' , $ taskListData [ 'data' ] , $ options ) ; } return $ this ; } | Adds multiple tasks . |
31,307 | public function exists ( string $ taskID , string $ listID = '' ) : bool { $ list = $ this -> getListData ( $ listID ) ; if ( isset ( $ list [ $ taskID ] ) ) { $ app = App :: get ( ) ; return $ app -> data -> exists ( $ this -> getTaskDataKey ( $ taskID , $ listID ) ) ; } return false ; } | Checks if a task exists . |
31,308 | public function getMinStartTime ( string $ listID = '' ) : ? int { $ list = $ this -> getListData ( $ listID ) ; if ( empty ( $ list ) ) { return null ; } $ minStartTime = null ; $ hasTaskWithoutStartDate = false ; foreach ( $ list as $ taskListData ) { if ( $ taskListData [ 0 ] === 1 ) { if ( $ taskListData [ 1 ] === null ) { $ hasTaskWithoutStartDate = true ; } else { if ( $ minStartTime === null || $ taskListData [ 1 ] < $ minStartTime ) { $ minStartTime = $ taskListData [ 1 ] ; } } } } $ currentTime = time ( ) ; if ( $ minStartTime === null ) { return $ currentTime ; } if ( $ hasTaskWithoutStartDate ) { return $ minStartTime < $ currentTime ? $ minStartTime : $ currentTime ; } else { return $ minStartTime ; } } | Returns the minimum start time of the tasks in the list specified . |
31,309 | public function getStats ( string $ listID = '' ) : array { $ result = [ ] ; $ result [ 'upcomingTasksCount' ] = 0 ; $ result [ 'upcomingTasks' ] = [ ] ; $ result [ 'nextTaskStartTime' ] = null ; $ currentTime = time ( ) ; $ list = $ this -> getListData ( $ listID ) ; foreach ( $ list as $ taskID => $ taskListData ) { $ result [ 'upcomingTasksCount' ] ++ ; if ( $ taskListData [ 0 ] === 1 ) { $ startTime = $ taskListData [ 1 ] ; $ result [ 'upcomingTasks' ] [ ] = [ 'id' => $ taskID , 'startTime' => $ startTime ] ; $ tempStartTime = $ startTime === null ? $ currentTime : $ startTime ; if ( $ result [ 'nextTaskStartTime' ] === null || $ result [ 'nextTaskStartTime' ] > $ tempStartTime ) { $ result [ 'nextTaskStartTime' ] = $ tempStartTime ; } } } return $ result ; } | Returns information about the tasks in the list specified . |
31,310 | public function isResponsible ( int $ level , string $ message , string $ file = null , int $ line = null , array $ context = [ ] ) : bool { return true ; } | checks whether this error handler is responsible for the given error |
31,311 | public function isSupressable ( int $ level , string $ message , string $ file = null , int $ line = null , array $ context = [ ] ) : bool { return false ; } | checks whether this error is supressable |
31,312 | public function handle ( int $ level , string $ message , string $ file = null , int $ line = null , array $ context = [ ] ) : bool { $ logData = date ( 'Y-m-d H:i:s' ) . '|' . $ level ; $ logData .= '|' . ( self :: $ levelStrings [ $ level ] ?? 'unknown' ) ; $ logData .= '|' . $ message ; $ logData .= '|' . $ file ; $ logData .= '|' . $ line ; $ logDir = $ this -> buildLogDir ( ) ; if ( ! file_exists ( $ logDir ) ) { mkdir ( $ logDir , $ this -> filemode , true ) ; } error_log ( $ logData . "\n" , 3 , $ logDir . DIRECTORY_SEPARATOR . 'php-error-' . date ( 'Y-m-d' ) . '.log' ) ; return ErrorHandler :: STOP_ERROR_HANDLING ; } | handles the given error |
31,313 | static function get ( $ name ) { $ name = StringHelper :: toLittleCamelCase ( $ name ) ; $ value = null ; if ( method_exists ( get_called_class ( ) , $ name ) ) { $ value = static :: $ name ( ) ; } if ( is_array ( $ value ) ) { $ value = implode ( '<br>' , $ value ) ; } return $ value ; } | get help text |
31,314 | public function queryAssoc ( $ statement , $ params = array ( ) ) { $ start = microtime ( true ) ; $ query = $ this -> prepare ( $ statement ) ; try { $ query -> execute ( $ params ) ; } catch ( \ PDOException $ e ) { $ this -> error ( $ e -> getMessage ( ) , array ( 'File' => __FILE__ , 'Line' => __LINE__ - 4 , 'Query' => $ statement . '' , 'Params' => $ params , 'Trace' => $ e -> getTraceAsString ( ) ) ) ; return null ; } $ r = $ query -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; $ this -> debug ( $ statement . '' , array ( 'params' => $ params , 'intoArray' => 'assoc' , 'rows' => count ( $ r ) , 'time' => microtime ( true ) - $ start , 'dns' => $ this -> dns ) ) ; return $ r ; } | Select rows from table and return them as an associative array ; |
31,315 | public function execQuery ( $ statement , $ params = array ( ) ) { $ start = microtime ( true ) ; $ query = $ this -> prepare ( $ statement . '' ) ; try { $ query -> execute ( $ params ) ; } catch ( \ PDOException $ e ) { $ this -> error ( $ e -> getMessage ( ) , array ( 'File' => __FILE__ , 'Line' => __LINE__ - 4 , 'Query' => $ statement . '' , 'Params' => $ params , 'Trace' => $ e -> getTraceAsString ( ) ) ) ; return 0 ; } $ this -> debug ( $ statement , array ( 'params' => $ params , 'execute' => true , 'rows' => $ count = $ query -> rowCount ( ) , 'time' => microtime ( true ) - $ start , 'dns' => $ this -> dns ) ) ; return $ count ; } | Executes a statement and returns the number of affected rows . |
31,316 | public function getTablePk ( $ tableName ) { $ details = $ this -> getTableColumns ( $ tableName ) ; $ pk = [ ] ; foreach ( $ details as $ column ) { if ( $ column [ 'Key' ] == 'PRI' ) { $ pk [ ] = $ column [ 'Field' ] ; } } if ( 1 == count ( $ pk ) ) { return $ pk [ 0 ] ; } elseif ( count ( $ pk ) ) { return $ pk ; } return null ; } | Get column used as primary key . |
31,317 | public function getTableColumns ( $ tableName ) { if ( ! $ this -> tableColumns ) { if ( App :: get ( ) -> cacheExists ( 'mpf:PDOConnection:tableColumns' ) ) { $ this -> tableColumns = App :: get ( ) -> cacheValue ( 'mpf:PDOConnection:tableColumns' ) ; } } if ( ! isset ( $ this -> tableColumns [ $ tableName ] ) ) { $ this -> tableColumns [ $ tableName ] = $ this -> queryAssoc ( "SHOW COLUMNS FROM `$tableName`" ) ; App :: get ( ) -> cacheSet ( 'mpf:PDOConnection:tableColumns' , $ this -> tableColumns ) ; } return $ this -> tableColumns [ $ tableName ] ; } | Return a list of details about table columns ; |
31,318 | public function getColumnOptions ( $ tableName , $ columnName ) { if ( ! in_array ( $ this -> getColumnType ( $ tableName , $ columnName ) , array ( 'enum' , 'set' ) ) ) return null ; $ columns = $ this -> getTableColumns ( $ tableName ) ; foreach ( $ columns as $ column ) { if ( $ column [ 'Field' ] != $ columnName ) continue ; $ options = explode ( '(' , $ column [ 'Type' ] , 2 ) ; $ options = substr ( $ options [ 1 ] , 0 , strlen ( $ options [ 1 ] ) - 1 ) ; $ options = str_getcsv ( $ options , ',' , "'" ) ; $ fOptions = [ ] ; foreach ( $ options as $ opt ) { $ fOptions [ $ opt ] = $ opt ; } return $ fOptions ; } throw new \ Exception ( "Column `$columnName` not found in table `$tableName`!" ) ; } | If column exists in table and it s enum or set it will return all available options . If column exists but it s another type it will return NULL . If the column doesn t exist it will trow an Exception ; |
31,319 | public function getColumnType ( $ tableName , $ columnName ) { $ columns = $ this -> getTableColumns ( $ tableName ) ; foreach ( $ columns as $ column ) { if ( $ column [ 'Field' ] != $ columnName ) continue ; $ type = explode ( '(' , $ column [ 'Type' ] , 2 ) ; return $ type [ 0 ] ; } throw new \ Exception ( "Column `$columnName` not found in table `$tableName`!" ) ; } | Returns column type . |
31,320 | public function getColumnDefaultValue ( $ tableName , $ columnName ) { $ columns = $ this -> getTableColumns ( $ tableName ) ; foreach ( $ columns as $ column ) { if ( $ column [ 'Field' ] != $ columnName ) continue ; return $ column [ 'Default' ] ; } throw new \ Exception ( "Column `$columnName` not found in table `$tableName`!" ) ; } | Returns default value for selected column or NULL if there is no default ; |
31,321 | public function tableExists ( $ tableName ) { $ cache = [ ] ; if ( App :: get ( ) -> cacheExists ( 'mpf:PDOConnection:tableList' ) ) { $ cache = App :: get ( ) -> cacheValue ( 'mpf:PDOConnection:tableList' ) ; if ( ! is_array ( $ cache ) ) { $ cache = [ ] ; } if ( isset ( $ cache [ $ tableName ] ) ) { return $ cache [ $ tableName ] ; } } $ res = $ this -> queryAssoc ( "SHOW TABLES LIKE :table" , array ( ':table' => $ tableName ) ) ; $ cache [ $ tableName ] = ( bool ) $ res ; App :: get ( ) -> cacheSet ( 'mpf:PDOConnection:tableList' , $ cache ) ; return ( bool ) $ res ; } | Check if selected table exists . |
31,322 | protected function initDefaults ( ) { if ( $ this -> properties [ 'header' ] === null ) { $ this -> setHeader ( $ this -> name ) ; } if ( $ this -> properties [ 'type' ] === null ) { $ this -> setType ( ColumnType :: createType ( ColumnType :: TYPE_STRING ) ) ; } } | This method ensure some properties are defaulted . For example header with name and type is string . |
31,323 | public function setType ( $ type ) { if ( is_string ( $ type ) ) { $ type = ColumnType :: createType ( $ type ) ; } elseif ( ! $ type instanceof AbstractType ) { throw new Exception \ InvalidArgumentException ( __METHOD__ . ' setType() accepts only AbstractType or string.' ) ; } $ this -> properties [ 'type' ] = $ type ; return $ this ; } | Set column datatype . |
31,324 | public function setProperties ( array $ properties ) { foreach ( $ properties as $ key => $ value ) { if ( array_key_exists ( $ key , $ this -> properties ) ) { $ method = 'set' . ucfirst ( $ key ) ; $ this -> $ method ( $ value ) ; } else { throw new Exception \ InvalidArgumentException ( __METHOD__ . " property '$key' is not supported in column." ) ; } } return $ this ; } | Set properties for the column . |
31,325 | protected function _compareEmployeeInfo ( array & $ emploeeDbGuidCache , array & $ extendInfo = [ ] , $ employeeInfoLdap = null , $ useBlockEmployee = false , $ useBlockDepartment = false ) { if ( empty ( $ employeeInfoLdap ) ) { return false ; } $ extendInfoDefault = [ 'employeeInfoLocal' => [ ] , 'employeeDbDnCache' => [ ] , 'departmentCache' => [ ] , 'defaultValueFields' => [ ] , 'deleteBindData' => [ ] , ] ; $ extendInfo = array_intersect_key ( $ extendInfo , $ extendInfoDefault ) ; $ extendInfo += $ extendInfoDefault ; $ guid = $ employeeInfoLdap [ CAKE_LDAP_LDAP_ATTRIBUTE_OBJECT_GUID ] ; if ( isset ( $ emploeeDbGuidCache [ $ guid ] ) ) { $ extendInfo [ 'employeeInfoLocal' ] = $ emploeeDbGuidCache [ $ guid ] ; unset ( $ emploeeDbGuidCache [ $ guid ] ) ; } else { $ extendInfo [ 'employeeInfoLocal' ] = [ ] ; } $ employeeInfoLdap = $ this -> _prepareEmployeeData ( $ employeeInfoLdap , $ extendInfo , $ useBlockDepartment ) ; if ( $ employeeInfoLdap === false ) { return false ; } $ diffInfo = Hash :: diff ( $ employeeInfoLdap , $ extendInfo [ 'employeeInfoLocal' ] ) ; if ( empty ( $ diffInfo ) ) { if ( ! $ useBlockEmployee || ( $ useBlockEmployee && ! $ employeeInfoLdap [ 'Employee' ] [ 'block' ] ) ) { return true ; } } if ( $ useBlockEmployee ) { $ employeeInfoLdap [ 'Employee' ] [ 'block' ] = false ; } if ( isset ( $ employeeInfoLdap [ 'Department' ] ) ) { if ( empty ( $ employeeInfoLdap [ 'Department' ] [ 'value' ] ) ) { unset ( $ employeeInfoLdap [ 'Department' ] ) ; } elseif ( $ useBlockDepartment ) { $ employeeInfoLdap [ 'Department' ] [ 'block' ] = false ; } } $ resultData = $ employeeInfoLdap ; return $ resultData ; } | Compare information about employee from Active Directory and from database . |
31,326 | public function drawPage ( ) { $ this -> preFlight ( ) ; if ( $ this -> preprocess ( ) ) { if ( $ this -> window_dressing ) { echo $ this -> getHeader ( ) ; } if ( $ this -> readinessCheck ( ) !== false ) { $ body = $ this -> bodyContent ( ) ; } else { $ body = $ this -> errorContent ( ) ; } if ( $ this -> window_dressing ) { echo $ body ; echo $ this -> getFooter ( ) ; } else { $ body = str_ireplace ( '</html>' , '' , $ body ) ; $ body = str_ireplace ( '</body>' , '' , $ body ) ; echo $ body ; } $ this -> writeJS ( ) ; echo array_reduce ( $ this -> css_files , function ( $ carry , $ css_url ) { return $ carry . sprintf ( '<link rel="stylesheet" type="text/css" href="%s">' . "\n" , $ css_url ) ; } , '' ) ; $ page_css = $ this -> css_content ( ) ; if ( ! empty ( $ page_css ) ) { echo '<style type="text/css">' ; echo $ page_css ; echo '</style>' ; } $ this -> postFlight ( ) ; echo '</body></html>' ; } else { $ this -> postFlight ( ) ; } } | Check for input and display the page |
31,327 | public function start ( ) { if ( $ this -> config -> exists ( 'database' ) ) { $ this -> db = new DB \ Connection ( $ this -> config ) ; } $ this -> router = new Router ( $ this -> klein , $ this -> config ) ; } | Visibly start the Frame engine |
31,328 | public function auth ( ) { $ user = isset ( $ _SERVER [ 'PHP_AUTH_USER' ] ) ? $ _SERVER [ 'PHP_AUTH_USER' ] : null ; $ password = isset ( $ _SERVER [ 'PHP_AUTH_PW' ] ) ? $ _SERVER [ 'PHP_AUTH_PW' ] : null ; if ( is_null ( $ user ) || ! ( bool ) call_user_func ( $ this -> verify , $ user , $ password ) ) { header ( sprintf ( 'WWW-Authenticate: Basic realm="%s"' , $ this -> realm ) ) ; header ( 'HTTP/1.0 401 Unauthorized' ) ; if ( $ this -> deny ) { call_user_func ( $ this -> deny , $ user ) ; } exit ; } $ this -> user = $ user ; $ this -> password = $ password ; return $ this ; } | Process the basic auth |
31,329 | public function whichDB ( $ db_name ) { if ( $ this -> connection -> tableExists ( $ db_name . $ this -> connection -> sep ( ) . $ this -> name ) ) { $ this -> fq_name = $ db_name . $ this -> connection -> sep ( ) . $ this -> name ; return true ; } else { return false ; } } | Manually set which database contains this table . Normally this is autodetected by the constructor . |
31,330 | protected function filterColumn ( $ col , $ val , $ op , $ literal = false ) { $ valid_op = $ this -> validateOp ( $ op ) ; if ( $ valid_op === false ) { throw new Exception ( 'Invalid operator: ' . $ op ) ; } $ this -> filters [ ] = array ( 'left' => $ col , 'right' => $ val , 'op' => $ valid_op , 'rightIsLiteral' => $ literal , ) ; } | Add column WHERE condition |
31,331 | protected function identifierEscape ( $ dbms , $ name ) { return $ dbms === 'postgres9' ? $ this -> connection -> identifierEscape ( strtolower ( $ name ) ) : $ this -> connection -> identifierEscape ( $ name ) ; } | Don t escape column and table names with postgres . Postgres heavily favors case insensitivity and escaping identifiers with capital letters makes a mess later |
31,332 | public function createIfNeeded ( $ db_name ) { $ this -> fq_name = $ db_name . $ this -> connection -> sep ( ) . $ this -> name ; $ ret = array ( 'db' => $ db_name , 'struct' => $ this -> name , 'error' => 0 , 'error_msg' => '' ) ; $ exists = $ this -> connection -> tableExists ( $ this -> fq_name ) ; if ( ! $ exists && ! $ this -> create ( ) ) { $ ret [ 'error' ] = 1 ; $ ret [ 'error_msg' ] = $ this -> connection -> error ( $ db_name ) ; $ reflect = new \ ReflectionClass ( $ this ) ; $ ret [ 'query' ] = $ reflect -> getName ( ) . '::create()' ; } return $ ret ; } | Create structure only if it does not exist |
31,333 | public function getMeta ( $ type , $ dbms ) { if ( ! isset ( $ this -> meta_types [ strtoupper ( $ type ) ] ) ) { return $ type ; } $ meta = $ this -> meta_types [ strtoupper ( $ type ) ] ; return isset ( $ meta [ $ dbms ] ) ? $ meta [ $ dbms ] : $ meta [ 'default' ] ; } | Get database - specific type |
31,334 | protected function insertRecord ( ) { $ sql = 'INSERT INTO ' . $ this -> fq_name ; $ cols = '(' ; $ vals = '(' ; $ args = array ( ) ; $ table_def = $ this -> getDefinition ( ) ; foreach ( $ this -> instance as $ column => $ value ) { if ( isset ( $ this -> columns [ $ column ] [ 'increment' ] ) && $ this -> columns [ $ column ] [ 'increment' ] ) { continue ; } else if ( ! isset ( $ table_def [ $ column ] ) ) { continue ; } $ cols .= $ this -> connection -> identifierEscape ( $ column ) . ',' ; $ vals .= '?,' ; $ args [ ] = $ value ; } $ cols = substr ( $ cols , 0 , strlen ( $ cols ) - 1 ) . ')' ; $ vals = substr ( $ vals , 0 , strlen ( $ vals ) - 1 ) . ')' ; $ sql .= ' ' . $ cols . ' VALUES ' . $ vals ; $ prep = $ this -> connection -> prepare ( $ sql ) ; $ result = $ this -> connection -> execute ( $ prep , $ args ) ; if ( $ result ) { $ this -> record_changed = false ; foreach ( $ this -> columns as $ name => $ info ) { if ( isset ( $ info [ 'increment' ] ) && $ info [ 'increment' ] === true ) { $ new_id = $ this -> connection -> insertID ( ) ; if ( $ new_id !== false ) { $ result = $ new_id ; break ; } } } } return $ result ; } | Helper . Build & execute insert query |
31,335 | protected function updateRecord ( ) { $ sql = 'UPDATE ' . $ this -> fq_name ; $ sets = '' ; $ where = '1=1' ; $ set_args = array ( ) ; $ where_args = array ( ) ; $ table_def = $ this -> getDefinition ( ) ; foreach ( $ this -> instance as $ column => $ value ) { if ( in_array ( $ column , $ this -> unique ) ) { $ where .= ' AND ' . $ this -> connection -> identifierEscape ( $ column ) . ' = ?' ; $ where_args [ ] = $ value ; } else { if ( isset ( $ this -> columns [ $ column ] [ 'increment' ] ) && $ this -> columns [ $ column ] [ 'increment' ] ) { continue ; } else if ( ! isset ( $ table_def [ $ column ] ) ) { continue ; } $ sets .= ' ' . $ this -> connection -> identifierEscape ( $ column ) . ' = ?,' ; $ set_args [ ] = $ value ; } } $ sets = substr ( $ sets , 0 , strlen ( $ sets ) - 1 ) ; $ sql .= ' SET ' . $ sets . ' WHERE ' . $ where ; $ all_args = $ set_args ; foreach ( $ where_args as $ a ) { $ all_args [ ] = $ a ; } $ prep = $ this -> connection -> prepare ( $ sql ) ; $ result = $ this -> connection -> execute ( $ prep , $ all_args ) ; if ( $ result ) { $ this -> record_changed = false ; } return $ result ? true : false ; } | Helper . Build & execute update query |
31,336 | public function columnsDoc ( ) { $ ret = str_pad ( 'Name' , 25 , ' ' ) . '|' . str_pad ( 'Type' , 15 , ' ' ) . '|Info' . "\n" ; $ ret .= str_repeat ( '-' , 25 ) . '|' . str_repeat ( '-' , 15 ) . '|' . str_repeat ( '-' , 10 ) . "\n" ; foreach ( $ this -> columns as $ name => $ info ) { $ ret .= str_pad ( $ name , 25 , ' ' ) . '|' ; $ ret .= str_pad ( $ info [ 'type' ] , 15 , ' ' ) . '|' ; if ( isset ( $ info [ 'primary_key' ] ) ) { $ ret .= 'PK ' ; } if ( isset ( $ info [ 'index' ] ) ) { $ ret .= 'Indexed ' ; } if ( isset ( $ info [ 'increment' ] ) ) { $ ret .= 'Increment ' ; } if ( isset ( $ info [ 'default' ] ) ) { $ ret .= 'Default=' . $ info [ 'default' ] ; } $ ret .= "\n" ; } return $ ret ; } | Return a Github - flavored markdown table of information about the model s column structure |
31,337 | public function trans ( $ value , array $ parameters = [ ] , $ domain = null , $ locale = null ) { $ domain = true === $ domain ? 'messages' : $ domain ; if ( $ this -> isString ( $ value ) && $ this -> isString ( $ domain ) ) { $ value = $ this -> translator -> trans ( $ value , $ parameters , $ domain , $ locale ) ; } return $ value ; } | Translate the value only if the domain is defined . |
31,338 | function Field ( $ name ) { if ( ! array_key_exists ( $ name , $ this -> fields ) ) throw new \ InvalidArgumentException ( $ name . ' is not a valid field for ' . $ this -> name ) ; return $ this -> fields [ $ name ] ; } | Gets the Field with given name . Alias is NOT allowed . |
31,339 | public function getLdapQuery ( $ conditions = null , $ objectClass = null ) { if ( ! empty ( $ objectClass ) ) { $ objectClass = mb_strtolower ( $ objectClass ) ; } else { $ objectClass = 'user' ; } $ baseQuery = '(!(useraccountcontrol:1.2.840.113556.1.4.803:=2))(objectClass=' . $ objectClass . ')' ; if ( $ objectClass === 'user' ) { $ baseQuery .= '(userAccountControl:1.2.840.113556.1.4.803:=512)' ; } if ( empty ( $ conditions ) || ! is_array ( $ conditions ) ) { return $ baseQuery ; } $ result = '(&' . $ baseQuery ; foreach ( $ conditions as $ attribute => $ value ) { list ( , $ attributeName ) = pluginSplit ( $ attribute ) ; if ( empty ( $ value ) ) { continue ; } switch ( $ attributeName ) { case CAKE_LDAP_LDAP_DISTINGUISHED_NAME : $ attributeName = CAKE_LDAP_LDAP_ATTRIBUTE_DISTINGUISHED_NAME ; break ; case CAKE_LDAP_LDAP_ATTRIBUTE_OBJECT_GUID : $ value = GuidStringToLdap ( $ value ) ; break ; } $ result .= '(' . $ attributeName . '=' . ( string ) $ value . ')' ; } $ result .= ')' ; return $ result ; } | Return LDAP query string builded by array condition |
31,340 | public static function sites ( String $ uri = NULL ) : String { return str_replace ( SSL_STATUS , Http :: fix ( true ) , self :: site ( $ uri ) ) ; } | Get site URLs |
31,341 | public static function unregister ( ) { self :: $ registered = false ; in_array ( vfsStream :: SCHEME , stream_get_wrappers ( ) ) and stream_wrapper_unregister ( vfsStream :: SCHEME ) ; } | Unregister the virtual filesystem stream wrapper |
31,342 | protected function parse ( ) { try { $ this -> getFlags ( ) -> parse ( ) ; $ this -> longs ( $ this -> getFlags ( ) -> longs ( ) ) -> shorts ( $ this -> getFlags ( ) -> shorts ( ) ) -> arguments ( $ this -> getFlags ( ) -> args ( ) ) ; } catch ( InvalidFlagParamException $ e ) { $ this -> showHelp ( $ e -> getMessage ( ) ) ; } catch ( InvalidFlagTypeException $ e ) { $ this -> showHelp ( $ e -> getMessage ( ) ) ; } return $ this ; } | Parses the arguments from CLI . |
31,343 | protected function showHelp ( $ error = null ) { if ( $ error !== null ) { $ this -> showError ( $ error ) ; } $ message = 'Available commands:' ; echo PHP_EOL . PHP_EOL . $ message . PHP_EOL . $ this -> getFlags ( ) -> getDefaults ( ) . PHP_EOL ; exit ; } | Shows help screen with available commands on demand or on error . |
31,344 | protected function showVersion ( ) { echo PHP_EOL . $ this -> colorize ( $ this -> getName ( ) , '%y' ) . ' - ' . $ this -> colorize ( 'Version' , '%g' ) . ': ' . $ this -> getVersion ( ) . PHP_EOL ; exit ; } | Shows version of this CLI . |
31,345 | protected function getFlagConfiguration ( $ key = null ) { if ( null !== $ key ) { $ result = ( isset ( $ this -> flagConfiguration [ $ key ] ) ) ? $ this -> flagConfiguration [ $ key ] : null ; } else { $ result = $ this -> flagConfiguration ; } return $ result ; } | Getter for flagConfiguration . |
31,346 | public static function has ( string $ key ) : bool { if ( ( new Cache ) -> retrieve ( $ key ) == null ) return false ; return true ; } | Check if item is cached |
31,347 | public static function pull ( string $ key ) { if ( Self :: has ( $ key ) ) { $ value = Self :: get ( $ key ) ; Self :: forget ( $ key ) ; return $ value ; } return null ; } | Retrieve and remove |
31,348 | public static function partial ( $ function , array $ fixedArgs = array ( ) ) { return function ( ) use ( $ function , $ fixedArgs ) { $ partialArgs = func_get_args ( ) ; $ fullArgs = array ( ) ; $ totalArgs = count ( $ partialArgs ) + count ( $ fixedArgs ) ; for ( $ i = 0 ; $ i < $ totalArgs ; $ i ++ ) { $ fullArgs [ ] = isset ( $ fixedArgs [ $ i ] ) ? $ fixedArgs [ $ i ] : array_shift ( $ partialArgs ) ; } return call_user_func_array ( $ function , $ fullArgs ) ; } ; } | Get a partial version of a function i . e . fix some arguments and returns a function of the remaining arguments . |
31,349 | public static function combine ( ) { $ functions = func_get_args ( ) ; foreach ( $ functions as $ function ) { static :: validate ( $ function ) ; } return function ( ) use ( $ functions ) { $ result = array ( ) ; $ args = func_get_args ( ) ; foreach ( $ functions as $ function ) { $ result [ ] = call_user_func_array ( $ function , $ args ) ; } return $ result ; } ; } | Combine an arbitrary long list of functions into a single function that returns an array in which the n - th element is the result of the n - th function . |
31,350 | public function getSecond ( $ timestamp = false ) { if ( ! $ timestamp ) { $ timestamp = $ this -> dateTime -> getTimestamp ( ) ; } return ( int ) date ( 's' , $ timestamp ) ; } | This method is intend to return the current seconds . |
31,351 | public function getMinute ( $ timestamp = false ) { if ( ! $ timestamp ) { $ timestamp = $ this -> dateTime -> getTimestamp ( ) ; } return date ( 'i' , $ timestamp ) ; } | This method is intend to return the current minutes . |
31,352 | public function getHour ( $ timestamp = false ) { if ( ! $ timestamp ) { $ timestamp = $ this -> dateTime -> getTimestamp ( ) ; } return date ( 'G' , $ timestamp ) ; } | This method is intend to return the current hour . |
31,353 | public function getDay ( $ timestamp = false ) { if ( ! $ timestamp ) { $ timestamp = $ this -> dateTime -> getTimestamp ( ) ; } return date ( 'j' , $ timestamp ) ; } | This method is intend to return the current day . |
31,354 | public function getWeek ( $ timestamp = false ) { if ( ! $ timestamp ) { $ timestamp = $ this -> dateTime -> getTimestamp ( ) ; } return ( int ) date ( 'W' , $ timestamp ) ; } | This method is intend to return the current week . |
31,355 | public function getWeekday ( $ timestamp = false ) { if ( ! $ timestamp ) { $ timestamp = $ this -> dateTime -> getTimestamp ( ) ; } return date ( 'w' , $ timestamp ) ; } | This method is intend to return the current weekday . |
31,356 | public function getMonth ( $ timestamp = false ) { if ( ! $ timestamp ) { $ timestamp = $ this -> dateTime -> getTimestamp ( ) ; } return date ( 'n' , $ timestamp ) ; } | This method is intend to return the current month . |
31,357 | public function getYear ( $ timestamp = false ) { if ( ! $ timestamp ) { $ timestamp = $ this -> dateTime -> getTimestamp ( ) ; } return date ( 'Y' , $ timestamp ) ; } | returns current year |
31,358 | protected function formatDate ( $ date , $ format = 'H/i/s/m/d/Y' , $ separator = '/' ) { $ date = date ( $ format , strtotime ( $ date ) ) ; return explode ( $ separator , $ date ) ; } | formats a date by given format |
31,359 | public static function createFromError ( $ message , $ code = 0 ) { if ( ! is_numeric ( $ code ) ) { $ message = trim ( "{$code} {$message}" ) ; $ code = - 1 ; } return new self ( $ message , $ code ) ; } | Create Exception using error code |
31,360 | static public function editor ( $ value = null ) { if ( $ value ) { } $ value = str_replace ( [ chr ( 13 ) . chr ( 10 ) , chr ( 13 ) , chr ( 10 ) ] , '<br>' , $ value ) ; return static :: _common ( $ value ) ; } | editor string needn t html_entities |
31,361 | static public function keywords ( $ value = null ) { if ( $ value ) { $ value = StringHelper :: str_cut ( strip_tags ( $ value ) , 100 ) ; } return static :: input ( trim ( $ value ) ) ; } | keywords field input handle |
31,362 | public function removeDuplicateUsers ( ) { $ this -> db -> query ( "DELETE FROM " . $ this -> db -> users . " WHERE id NOT IN ( SELECT * FROM ( SELECT MIN(id) FROM " . $ this -> db -> users . " GROUP BY user_login ) temp )" ) ; wp_cache_flush ( ) ; } | Deletes duplicate users |
31,363 | public function removeOphanUserMeta ( ) { $ this -> db -> query ( "DELETE FROM " . $ this -> db -> usermeta . " WHERE NOT EXISTS ( SELECT * FROM " . $ this -> db -> users . " WHERE " . $ this -> db -> usermeta . ".user_id = " . $ this -> db -> users . ".ID )" ) ; wp_cache_flush ( ) ; } | Deletes Orphaned meta |
31,364 | public function removeEmptyCapabilities ( ) { $ this -> db -> query ( "DELETE FROM " . $ this -> db -> usermeta . " WHERE meta_key LIKE '%" . $ this -> db -> base_prefix . "_%capabilities%' AND meta_value = 'a:0:{}'" ) ; wp_cache_flush ( ) ; } | Deletes empty capabilities |
31,365 | public static function toInteger ( $ array , $ default = null ) { if ( is_numeric ( $ array ) ) { return array ( $ array ) ; } elseif ( is_string ( $ array ) ) { $ array = preg_split ( '/[,|\s]/' , $ array ) ; } if ( is_array ( $ array ) ) { $ array = array_map ( 'intval' , $ array ) ; } else { if ( $ default === null ) { $ array = array ( ) ; } elseif ( is_array ( $ default ) ) { $ array = self :: toInteger ( $ default , null ) ; } else { $ array = array ( ( int ) $ default ) ; } } return $ array ; } | convert to array integer values |
31,366 | static public function addslashes ( $ data ) { if ( ! is_array ( $ data ) ) return addslashes ( $ data ) ; foreach ( $ data as $ key => $ val ) { $ data [ $ key ] = static :: addslashes ( $ val ) ; } return $ data ; } | addslashes to the array or string |
31,367 | static public function callback ( $ array , $ callback ) { if ( is_array ( $ array ) ) foreach ( $ array as $ k => $ v ) { if ( is_array ( $ v ) ) { $ array [ $ k ] = static :: callback ( $ v , $ callback ) ; } else { $ array [ $ k ] = $ callback ( $ v ) ; } } return $ array ; } | handle array value by callable |
31,368 | static public function toLowerCaseKey ( array $ array ) { $ res = [ ] ; if ( $ array ) { foreach ( $ array as $ k => $ v ) { if ( is_array ( $ v ) ) { $ v = static :: toLowerCaseKey ( $ v ) ; } $ res [ strtolower ( $ k ) ] = $ v ; } } return $ res ; } | array key to lowercase |
31,369 | public function hasTranslation ( $ language = null ) { $ translation = $ this -> getTranslation ( $ language ) ; return $ translation && $ this -> isTranslationActive ( $ translation ) ; } | Model has translation to the language |
31,370 | public function getAvailableLanguages ( ) { if ( ! empty ( $ this -> owner -> { $ this -> translationsAttribute } ) ) { return array_keys ( $ this -> owner -> { $ this -> translationsAttribute } ) ; } return null ; } | Returns array of available languages . Populated models will be used if its set otherwise query will be used . |
31,371 | public function loadWithTranslations ( $ data , $ languages , $ formName = null , $ translationFormName = null ) { if ( $ this -> owner -> load ( $ data , $ formName ) ) { if ( ! $ languages ) { throw new InvalidParamException ( 'Languages must be set.' ) ; } foreach ( $ languages as $ language ) { $ modelI18n = static :: getTranslation ( $ language ) ; $ modelI18n -> load ( $ data , $ translationFormName ) ; } return true ; } return false ; } | Load owner model and translation models from data . |
31,372 | private function isTranslationActive ( $ model ) { if ( ! $ model ) { return false ; } if ( is_array ( $ this -> requiredAttributes ) && ! empty ( $ this -> requiredAttributes ) ) { foreach ( $ this -> requiredAttributes as $ attribute ) { if ( $ model -> { $ attribute } && ! empty ( $ model -> { $ attribute } ) ) { return true ; } } } else { return true ; } return false ; } | Translation is active or just empty model? |
31,373 | protected function prepOutputDir ( ) { if ( ! is_dir ( $ this -> output_dir . $ this -> prefix ) ) { $ this -> filesystem -> mkdir ( $ this -> output_dir . $ this -> prefix ) ; } } | Prepare the output directory . |
31,374 | public function thumbnail ( $ image , $ width = 150 , $ height = 150 , $ crop = false ) { if ( ! isset ( $ this -> completed [ $ image ] [ $ width ] [ $ height ] [ $ crop ] [ 'filename' ] ) ) { $ this -> prepOutputDir ( ) ; $ this -> imanee -> load ( $ this -> source_dir . '/' . $ image ) -> thumbnail ( $ width , $ height , $ crop ) ; $ thumb_name = vsprintf ( '%s-%sx%s%s.%s' , array ( md5 ( $ image ) , $ width , $ height , ( $ crop ? '-cropped' : '' ) , strtolower ( $ this -> imanee -> getFormat ( ) ) ) ) ; file_put_contents ( $ this -> output_dir . $ this -> prefix . '/' . $ thumb_name , $ this -> imanee -> output ( ) ) ; $ this -> completed [ $ image ] [ $ width ] [ $ height ] [ $ crop ] [ 'filename' ] = $ thumb_name ; } return $ this -> prefix . '/' . $ this -> completed [ $ image ] [ $ width ] [ $ height ] [ $ crop ] [ 'filename' ] ; } | Generate a thumbnail |
31,375 | public function mset ( array $ items , $ ttl = null ) { foreach ( $ items as $ key => $ item ) { $ this -> set ( $ key , $ item , $ ttl ) ; } return true ; } | set multi items |
31,376 | public function addOwners ( ) { foreach ( $ this -> attributes as $ attr ) { if ( $ mediafile = $ this -> loadModel ( $ this -> owner -> $ attr ) ) { $ mediafile -> addOwner ( $ this -> owner -> primaryKey , $ this -> name , $ attr ) ; } } } | Add owners to mediafile |
31,377 | public function updateOwners ( ) { foreach ( $ this -> attributes as $ attr ) { Mediafile :: removeOwner ( $ this -> owner -> primaryKey , $ this -> name , $ attr ) ; if ( $ mediafile = $ this -> loadModel ( $ this -> owner -> $ attr ) ) { $ mediafile -> addOwner ( $ this -> owner -> primaryKey , $ this -> name , $ attr ) ; } } } | Update owners of mediafile |
31,378 | public function index ( ) { $ groupActions = [ 'group-data-del' => __d ( 'cake_settings_app' , 'Delete selected tasks' ) ] ; $ conditions = $ this -> Filter -> getFilterConditions ( 'CakeTheme' ) ; $ usePost = true ; if ( $ this -> request -> is ( 'post' ) ) { $ groupAction = $ this -> Filter -> getGroupAction ( array_keys ( $ groupActions ) ) ; $ resultGroupProcess = $ this -> QueueInfo -> processGroupAction ( $ groupAction , $ conditions ) ; if ( $ resultGroupProcess !== null ) { if ( $ resultGroupProcess ) { $ conditions = null ; $ this -> Flash -> success ( __d ( 'cake_settings_app' , 'Selected tasks has been deleted.' ) ) ; } else { $ this -> Flash -> error ( __d ( 'cake_settings_app' , 'Selected tasks could not be deleted. Please, try again.' ) ) ; } } } else { if ( ! empty ( $ conditions ) ) { $ usePost = false ; } } $ this -> Paginator -> settings = $ this -> paginate ; $ queue = $ this -> Paginator -> paginate ( 'QueueInfo' , $ conditions ) ; $ taskStateList = $ this -> QueueInfo -> getListTaskState ( ) ; $ stateData = [ ] ; if ( $ usePost ) { $ stateData = $ this -> QueueInfo -> getBarStateInfo ( ) ; } $ pageHeader = __d ( 'cake_settings_app' , 'Queue of tasks' ) ; $ headerMenuActions = [ ] ; if ( ! empty ( $ queue ) ) { $ headerMenuActions [ ] = [ 'fas fa-trash-alt' , __d ( 'cake_settings_app' , 'Clear queue of tasks' ) , [ 'controller' => 'queues' , 'action' => 'clear' , 'plugin' => 'cake_settings_app' , 'prefix' => false ] , [ 'title' => __d ( 'cake_settings_app' , 'Clear queue of tasks' ) , 'action-type' => 'confirm-post' , 'data-confirm-msg' => __d ( 'cake_settings_app' , 'Are you sure you wish to clear queue of tasks?' ) , ] ] ; } $ breadCrumbs = $ this -> Setting -> getBreadcrumbInfo ( ) ; $ breadCrumbs [ ] = __d ( 'cake_settings_app' , 'Queue of tasks' ) ; $ this -> set ( compact ( 'queue' , 'groupActions' , 'taskStateList' , 'stateData' , 'usePost' , 'pageHeader' , 'headerMenuActions' , 'breadCrumbs' ) ) ; } | Action index . Used to view queue of task |
31,379 | public function delete ( ) { $ this -> request -> allowMethod ( 'post' , 'delete' ) ; $ data = $ this -> request -> query ; if ( empty ( $ data ) ) { throw new InternalErrorException ( __d ( 'cake_settings_app' , 'Invalid task' ) ) ; } if ( $ this -> QueueInfo -> deleteTasks ( $ data ) ) { $ this -> Flash -> success ( __d ( 'cake_settings_app' , 'The task has been deleted.' ) ) ; } else { $ this -> Flash -> error ( __d ( 'cake_settings_app' , 'The task could not be deleted. Please, try again.' ) ) ; } $ urlRedirect = [ 'plugin' => 'cake_settings_app' , 'controller' => 'queues' , 'action' => 'index' ] ; return $ this -> redirect ( $ urlRedirect ) ; } | Action delete . Used to delete task from queue |
31,380 | public function clear ( ) { $ this -> request -> allowMethod ( 'post' , 'delete' ) ; $ ds = $ this -> QueueInfo -> getDataSource ( ) ; if ( $ ds -> truncate ( $ this -> QueueInfo ) ) { $ this -> Flash -> success ( __d ( 'cake_settings_app' , 'The task queue has been cleared.' ) ) ; } else { $ this -> Flash -> error ( __d ( 'cake_settings_app' , 'The task queue could not be cleared. Please, try again.' ) ) ; } $ urlRedirect = [ 'plugin' => 'cake_settings_app' , 'controller' => 'queues' , 'action' => 'index' ] ; return $ this -> redirect ( $ urlRedirect ) ; } | Action clear . Used to clear queue of tasks |
31,381 | protected function setCompletePage ( array $ order , $ model , $ controller ) { if ( $ order [ 'payment' ] === 'stripe' ) { $ this -> order = $ model ; $ this -> data_order = $ order ; $ this -> controller = $ controller ; $ this -> submitPayment ( ) ; $ controller -> setJs ( 'https://js.stripe.com/v2' ) ; $ controller -> setJs ( 'system/modules/stripe/js/common.js' ) ; $ controller -> setJsSettings ( 'stripe' , array ( 'key' => $ this -> getPublicKey ( ) ) ) ; } } | Set up order complete page |
31,382 | public function getGateway ( ) { $ module = $ this -> module -> getInstance ( 'omnipay_library' ) ; $ gateway = $ module -> getGatewayInstance ( 'Stripe' ) ; if ( ! $ gateway instanceof Gateway ) { throw new UnexpectedValueException ( 'Gateway must be instance of Omnipay\Stripe\Gateway' ) ; } return $ gateway ; } | Returns Stripe gateway object |
31,383 | protected function getStatus ( ) { if ( ! $ this -> getModuleSetting ( 'status' ) ) { return false ; } if ( $ this -> getModuleSetting ( 'test' ) ) { return $ this -> getModuleSetting ( 'test_key' ) && $ this -> getModuleSetting ( 'test_public_key' ) ; } return $ this -> getModuleSetting ( 'live_key' ) && $ this -> getModuleSetting ( 'live_public_key' ) ; } | Returns the current status of the payment method |
31,384 | protected function processResponse ( ) { if ( $ this -> response -> isSuccessful ( ) ) { $ this -> updateOrderStatus ( ) ; $ this -> addTransaction ( ) ; $ this -> redirectSuccess ( ) ; } else if ( $ this -> response -> isRedirect ( ) ) { $ this -> response -> redirect ( ) ; } else { $ this -> controller -> redirect ( '' , $ this -> response -> getMessage ( ) , 'warning' , true ) ; } } | Processes gateway response |
31,385 | protected function redirectSuccess ( ) { $ vars = array ( '@num' => $ this -> data_order [ 'order_id' ] , '@status' => $ this -> order -> getStatusName ( $ this -> data_order [ 'status' ] ) ) ; $ message = $ this -> controller -> text ( 'Thank you! Payment has been made. Order #@num, status: @status' , $ vars ) ; $ this -> controller -> redirect ( '/' , $ message , 'success' , true ) ; } | Redirect on successful transaction |
31,386 | protected function addTransaction ( ) { $ model = gplcart_instance_model ( 'Transaction' ) ; $ transaction = array ( 'total' => $ this -> data_order [ 'total' ] , 'order_id' => $ this -> data_order [ 'order_id' ] , 'currency' => $ this -> data_order [ 'currency' ] , 'payment_method' => $ this -> data_order [ 'payment' ] , 'gateway_transaction_id' => $ this -> response -> getTransactionReference ( ) ) ; return $ model -> add ( $ transaction ) ; } | Adds a transaction |
31,387 | private function newKey ( $ hash , $ length , $ key = '' ) { $ generated = $ this -> hasReq ( Hash :: secure ( $ length ) ) ; if ( $ hash == 'base64' ) { $ key = 'base64:' . base64_encode ( $ generated ) ; } else { $ key = $ hash . ':' . $ generated ; } return $ key ; } | Generate a new key |
31,388 | private function setKey ( $ key ) { $ env = file_get_contents ( config ( 'app.dir' ) . '.env' ) ; $ new = str_replace ( 'APP_KEY=' . config ( 'app.key' ) , 'APP_KEY=' . $ key , $ env ) ; if ( $ env == '' || $ env == null ) { return false ; } if ( ! file_exists ( config ( 'app.dir' ) . '.env' ) ) return false ; file_put_contents ( config ( 'app.dir' ) . '.env' , $ new ) ; return true ; } | Update the old key |
31,389 | private function hasReq ( $ generated ) { if ( in_array ( str_split ( '0123456789' ) , array_values ( str_split ( $ generated ) ) ) ) { $ generated = str_shuffle ( $ generated .= 1 ) ; } if ( in_array ( str_split ( 'abcdefghijklmnopqrstuvwxyz' ) , array_values ( str_split ( $ generated ) ) ) ) { $ generated = str_shuffle ( $ generated .= 'b' ) ; } if ( in_array ( str_split ( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) , array_values ( str_split ( $ generated ) ) ) ) { $ generated = str_shuffle ( $ generated .= 'B' ) ; } if ( in_array ( str_split ( '~!@#$%^&*()_-=+<>/\?;:{}[]|,.' ) , array_values ( str_split ( $ generated ) ) ) ) { $ generated = str_shuffle ( $ generated .= '!' ) ; } return $ generated ; } | Check if key has all the required stuff |
31,390 | function Copy ( ) { return new Date ( $ this -> Day ( ) , $ this -> Month ( ) , $ this -> Year ( ) , $ this -> Hour ( ) , $ this -> Minute ( ) , $ this -> Second ( ) ) ; } | A copy that points to the same time . |
31,391 | static function Today ( ) { $ now = new Date ( ) ; return new Date ( $ now -> Day ( ) , $ now -> Month ( ) , $ now -> Year ( ) , 0 , 0 , 0 ) ; } | The current day midnight . |
31,392 | static function Parse ( $ format , $ dateTimeString ) { $ dt = \ DateTime :: createFromFormat ( $ format , $ dateTimeString ) ; if ( ! $ dt ) return null ; return self :: FromDateTime ( $ dt ) ; } | Creates date time from a format string and string representation |
31,393 | private static function toModuleName ( $ module ) { $ module = str_replace ( '-' , ' ' , $ module ) ; $ module = explode ( ' ' , ucwords ( $ module ) ) ; $ module = implode ( '' , $ module ) ; return $ module ; } | Converts a kebab cased string into CamelCased format |
31,394 | public function getRuleProviderDefault ( ) : RuleProviderInterface { $ container = Dependency :: container ( ) ; return $ container -> has ( 'validate' ) ? $ container -> get ( 'validate' ) : Validate :: getInstance ( ) ; } | Get default rule provider from dependency injection container or first instance of the Validate class . |
31,395 | public function unsetLimit ( $ unset_offset = true ) : self { $ this -> limit = null ; if ( $ unset_offset ) { $ this -> offset = null ; } return $ this ; } | Unset limit of results Provides fluent interface . |
31,396 | public function formatKey ( $ key , $ hasAlias = false ) { $ key = trim ( $ key ) ; if ( empty ( $ key ) ) return $ key ; if ( strpos ( $ key , ',' ) > 0 ) { $ arr = explode ( ',' , $ key ) ; foreach ( $ arr as $ k => $ v ) { $ arr [ $ k ] = $ this -> formatKey ( $ v , $ hasAlias ) ; } $ key = implode ( ',' , $ arr ) ; unset ( $ arr ) ; } elseif ( preg_match ( '/([\s\+\-\*\/\%])+/' , $ key , $ matches ) ) { $ arr = explode ( $ matches [ 1 ] , $ key , 2 ) ; $ key = $ this -> formatKey ( $ arr [ 0 ] , $ hasAlias ) . $ matches [ 1 ] . $ arr [ 1 ] ; unset ( $ arr , $ matches ) ; } elseif ( strpos ( $ key , '.' ) > 0 ) { $ arr = explode ( '.' , $ key ) ; $ key = static :: formatKey ( $ arr [ 0 ] , true ) . '.' . static :: formatKey ( $ arr [ 1 ] , false ) ; unset ( $ arr ) ; } elseif ( ! $ hasAlias && ! preg_match ( '/[,\'\"\*\(\)`\s]/' , $ key ) ) { $ key = '`' . $ key . '`' ; } return $ key ; } | format field or table |
31,397 | public function _encode ( ) { $ data = "" ; foreach ( $ this -> byteArray as $ byte ) { $ data .= chr ( $ byte ) ; } return array ( '__type' => 'Bytes' , 'base64' => base64_encode ( $ data ) ) ; } | Encode to associative array representation |
31,398 | static public function formatSettings ( $ settings = null ) { if ( isset ( $ settings [ 'data_source' ] ) ) { if ( is_string ( $ settings [ 'data_source' ] ) ) { $ data = explode ( ',' , $ settings [ 'data_source' ] ) ; $ tdata = [ ] ; foreach ( $ data as $ k => $ v ) { if ( strpos ( $ v , '|' ) ) { $ tmp = explode ( '|' , $ v ) ; $ tdata [ trim ( $ tmp [ 0 ] ) ] = trim ( $ tmp [ 1 ] ) ; } else { $ tdata [ trim ( $ v ) ] = trim ( $ v ) ; } } $ settings [ 'data_source' ] = $ tdata ; } if ( ! isset ( $ settings [ 'fields' ] ) ) { $ settings [ 'fields' ] = [ 'id' , 'title' , 'depth' ] ; } else { $ settings [ 'fields' ] = DataHelper :: explode ( '\,\|' , $ settings [ 'fields' ] ) ; } } if ( isset ( $ settings [ 'id' ] ) ) { $ settings [ 'id' ] = static :: formatId ( $ settings [ 'id' ] ) ; } if ( isset ( $ settings [ 'readonly' ] ) && $ settings [ 'readonly' ] ) { $ settings [ 'readonly' ] = "readonly" ; } return $ settings ; } | format settings can parse data source |
31,399 | static public function auto ( $ name , $ value = null , $ settings = [ ] ) { ! isset ( $ settings [ 'form_type' ] ) && $ settings [ 'form_type' ] = 'text' ; if ( isset ( $ settings [ 'with_multi' ] ) && $ settings [ 'with_multi' ] ) { $ method = 'multi' ; } else { $ method = $ settings [ 'form_type' ] ; } return call_user_func_array ( get_called_class ( ) . '::' . $ method , [ $ name , $ value , $ settings ] ) ; } | auto build form element by form type |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.