idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
6,300
public function hasPermissions ( $ permissions ) { if ( $ this -> user ( ) === null ) { return null ; } if ( ! is_array ( $ permissions ) ) { $ permissions = func_get_args ( ) ; } return count ( array_intersect ( $ permissions , $ this -> permissions ) ) === count ( $ permissions ) ; }
Check if authenticated user has all permission passed by parameter
6,301
public function isBlocked ( ) { if ( $ this -> user ( ) === null ) { return null ; } if ( $ this -> user instanceof User ) { return $ this -> user -> blocked ; } return false ; }
Return if current user is blocked
6,302
function addPlayerInTeam ( $ login , $ teamId ) { switch ( $ teamId ) { case 0 : if ( array_search ( $ login , $ this -> team2 ) ) { throw new \ InvalidArgumentException ( ) ; } if ( ! array_search ( $ login , $ this -> team1 ) ) { $ this -> team1 [ ] = $ login ; } break ; case 1 : if ( array_search ( $ login , $ this -> team1 ) ) { throw new \ InvalidArgumentException ( ) ; } if ( ! array_search ( $ login , $ this -> team2 ) ) { $ this -> team2 [ ] = $ login ; } break ; default : throw new \ InvalidArgumentException ( ) ; } }
add a login in a team throw an exception if the login is already teamed or if the team does not exist
6,303
public function enableTracy ( $ logDirectory = null , $ email = null ) { Tracy \ Debugger :: $ strictMode = true ; Tracy \ Debugger :: enable ( $ this -> mode , $ logDirectory , $ email ) ; }
Enable Tracy Tools .
6,304
public function createAutoload ( $ path ) { $ loader = new Loaders \ RobotLoader ; $ loader -> setCacheStorage ( new Caching \ Storages \ FileStorage ( $ this -> temp ) ) ; $ loader -> addDirectory ( $ path ) -> register ( ) ; return $ loader ; }
Autoloading classes .
6,305
protected static function buildQueryStatement ( & $ objQueryBuilder , iCondition $ objConditions , $ objOptionalClauses , $ mixParameterArray , $ blnCountOnly ) { $ objDatabase = static :: getDatabase ( ) ; $ strTableName = static :: getTableName ( ) ; $ objQueryBuilder = new Builder ( $ objDatabase , $ strTableName ) ; $ blnAddAllFieldsToSelect = true ; if ( $ objDatabase -> OnlyFullGroupBy ) { if ( $ objOptionalClauses instanceof iClause ) { if ( $ objOptionalClauses instanceof Clause \ AggregationBase || $ objOptionalClauses instanceof Clause \ GroupBy ) { $ blnAddAllFieldsToSelect = false ; } } else { if ( is_array ( $ objOptionalClauses ) ) { foreach ( $ objOptionalClauses as $ objClause ) { if ( $ objClause instanceof Clause \ AggregationBase || $ objClause instanceof Clause \ GroupBy ) { $ blnAddAllFieldsToSelect = false ; break ; } } } } } $ objQueryBuilder -> addFromItem ( $ strTableName ) ; if ( $ blnCountOnly ) { $ objQueryBuilder -> setCountOnlyFlag ( ) ; } if ( $ objConditions ) { try { $ objConditions -> updateQueryBuilder ( $ objQueryBuilder ) ; } catch ( Caller $ objExc ) { $ objExc -> incrementOffset ( ) ; $ objExc -> incrementOffset ( ) ; throw $ objExc ; } } if ( $ objOptionalClauses ) { if ( $ objOptionalClauses instanceof iClause ) { try { $ objOptionalClauses -> updateQueryBuilder ( $ objQueryBuilder ) ; } catch ( Caller $ objExc ) { $ objExc -> incrementOffset ( ) ; $ objExc -> incrementOffset ( ) ; throw $ objExc ; } } else { if ( is_array ( $ objOptionalClauses ) ) { foreach ( $ objOptionalClauses as $ objClause ) { try { $ objClause -> updateQueryBuilder ( $ objQueryBuilder ) ; } catch ( Caller $ objExc ) { $ objExc -> incrementOffset ( ) ; $ objExc -> incrementOffset ( ) ; throw $ objExc ; } } } else { throw new Caller ( 'Optional Clauses must be a iClause object or an array of iClause objects' ) ; } } } $ objSelectClauses = QQ :: extractSelectClause ( $ objOptionalClauses ) ; if ( $ objSelectClauses || $ blnAddAllFieldsToSelect ) { static :: baseNode ( ) -> putSelectFields ( $ objQueryBuilder , null , $ objSelectClauses ) ; } $ strQuery = $ objQueryBuilder -> getStatement ( ) ; if ( $ mixParameterArray ) { if ( is_array ( $ mixParameterArray ) ) { if ( count ( $ mixParameterArray ) ) { $ strQuery = $ objDatabase -> prepareStatement ( $ strQuery , $ mixParameterArray ) ; } if ( strpos ( $ strQuery , chr ( Node \ NamedValue :: DELIMITER_CODE ) . '{' ) !== false ) { throw new Caller ( 'Unresolved named parameters in the query' ) ; } } else { throw new Caller ( 'Parameter Array must be an array of name-value parameter pairs' ) ; } } return $ strQuery ; }
Takes a query builder object and outputs the sql query that corresponds to its structure and the given parameters .
6,306
protected static function _QueryArray ( iCondition $ objConditions , $ objOptionalClauses = null , $ mixParameterArray = null ) { try { $ strQuery = static :: buildQueryStatement ( $ objQueryBuilder , $ objConditions , $ objOptionalClauses , $ mixParameterArray , false ) ; } catch ( Caller $ objExc ) { $ objExc -> incrementOffset ( ) ; throw $ objExc ; } $ objDbResult = $ objQueryBuilder -> Database -> query ( $ strQuery ) ; return static :: instantiateDbResult ( $ objDbResult , $ objQueryBuilder -> ExpandAsArrayNode , $ objQueryBuilder -> ColumnAliasArray ) ; }
Static Qcubed Query method to query for an array of objects . Uses BuildQueryStatment to perform most of the work . Is called by QueryArray function of each object so that the correct return type will be put in the comments .
6,307
public static function queryCursor ( iCondition $ objConditions , $ objOptionalClauses = null , $ mixParameterArray = null ) { try { $ strQuery = static :: buildQueryStatement ( $ objQueryBuilder , $ objConditions , $ objOptionalClauses , $ mixParameterArray , false ) ; } catch ( Caller $ objExc ) { $ objExc -> incrementOffset ( ) ; throw $ objExc ; } $ objExpandAsArrayNode = $ objQueryBuilder -> ExpandAsArrayNode ; if ( ! empty ( $ objExpandAsArrayNode ) ) { throw new Caller ( "Cannot use QueryCursor with ExpandAsArray" ) ; } $ objDbResult = $ objQueryBuilder -> Database -> query ( $ strQuery ) ; $ objDbResult -> ColumnAliasArray = $ objQueryBuilder -> ColumnAliasArray ; return $ objDbResult ; }
Static Qcubed query method to issue a query and get a cursor to progressively fetch its results . Uses BuildQueryStatment to perform most of the work .
6,308
public static function queryCount ( iCondition $ objConditions , $ objOptionalClauses = null , $ mixParameterArray = null ) { try { $ strQuery = static :: buildQueryStatement ( $ objQueryBuilder , $ objConditions , $ objOptionalClauses , $ mixParameterArray , true ) ; } catch ( Caller $ objExc ) { $ objExc -> incrementOffset ( ) ; throw $ objExc ; } $ objDbResult = $ objQueryBuilder -> Database -> query ( $ strQuery ) ; $ blnGrouped = false ; if ( $ objOptionalClauses ) { if ( $ objOptionalClauses instanceof iClause ) { if ( $ objOptionalClauses instanceof Clause \ GroupBy ) { $ blnGrouped = true ; } } else { if ( is_array ( $ objOptionalClauses ) ) { foreach ( $ objOptionalClauses as $ objClause ) { if ( $ objClause instanceof Clause \ GroupBy ) { $ blnGrouped = true ; break ; } } } else { throw new Caller ( 'Optional Clauses must be a iClause object or an array of iClause objects' ) ; } } } if ( $ blnGrouped ) { return $ objDbResult -> countRows ( ) ; } else { $ strDbRow = $ objDbResult -> fetchRow ( ) ; return ( integer ) $ strDbRow [ 0 ] ; } }
Static Qcubed Query method to query for a count of objects . Uses BuildQueryStatment to perform most of the work .
6,309
public static function expandArray ( $ objDbRow , $ strAliasPrefix , $ objNode , $ objPreviousItemArray , $ strColumnAliasArray ) { if ( ! $ objNode -> ChildNodeArray ) { return null ; } $ blnExpanded = null ; $ pk = static :: getRowPrimaryKey ( $ objDbRow , $ strAliasPrefix , $ strColumnAliasArray ) ; foreach ( $ objPreviousItemArray as $ objPreviousItem ) { if ( $ pk != $ objPreviousItem -> primaryKey ( ) ) { continue ; } foreach ( $ objNode -> ChildNodeArray as $ objChildNode ) { $ strPropName = $ objChildNode -> _PropertyName ; $ strClassName = $ objChildNode -> _ClassName ; $ strLongAlias = $ objChildNode -> fullAlias ( ) ; $ blnExpandAsArray = false ; if ( $ objChildNode -> ExpandAsArray ) { $ strPostfix = 'Array' ; $ blnExpandAsArray = true ; } else { $ strPostfix = '' ; } $ nodeType = $ objChildNode -> _Type ; if ( $ nodeType == 'reverse_reference' ) { $ strPrefix = '_obj' ; } elseif ( $ nodeType == 'association' ) { $ objChildNode = $ objChildNode -> firstChild ( ) ; if ( $ objChildNode -> IsType ) { $ strPrefix = '_int' ; } else { $ strPrefix = '_obj' ; } } else { $ strPrefix = 'obj' ; } $ strVarName = $ strPrefix . $ strPropName . $ strPostfix ; if ( $ blnExpandAsArray ) { if ( null === $ objPreviousItem -> $ strVarName ) { $ objPreviousItem -> $ strVarName = array ( ) ; } if ( count ( $ objPreviousItem -> $ strVarName ) ) { $ objPreviousChildItems = $ objPreviousItem -> $ strVarName ; $ nextAlias = $ objChildNode -> fullAlias ( ) . '__' ; $ objChildItem = $ strClassName :: instantiateDbRow ( $ objDbRow , $ nextAlias , $ objChildNode , $ objPreviousChildItems , $ strColumnAliasArray , true ) ; if ( $ objChildItem ) { $ objPreviousItem -> { $ strVarName } [ ] = $ objChildItem ; $ blnExpanded = true ; } elseif ( $ objChildItem === false ) { $ blnExpanded = true ; } } } elseif ( ! $ objChildNode -> IsType ) { if ( null === $ objPreviousItem -> $ strVarName ) { return false ; } $ objPreviousChildItems = array ( $ objPreviousItem -> $ strVarName ) ; $ blnResult = $ strClassName :: expandArray ( $ objDbRow , $ strLongAlias . '__' , $ objChildNode , $ objPreviousChildItems , $ strColumnAliasArray ) ; if ( $ blnResult ) { $ blnExpanded = true ; } } } } return $ blnExpanded ; }
Do a possible array expansion on the given node . If the node is an ExpandAsArray node it will add to the corresponding array in the object . Otherwise it will follow the node so that any leaf expansions can be handled .
6,310
protected function getTableFields ( Table $ table ) { $ fileds = [ ] ; foreach ( $ table -> getColumns ( ) as $ column ) { $ fileds [ ] = [ 'name' => $ column -> getName ( ) , 'type' => $ column -> getType ( ) -> getName ( ) , 'not_null' => $ column -> getNotnull ( ) , 'length' => $ column -> getLength ( ) , 'unsigned' => $ column -> getUnsigned ( ) , 'autoincrement' => $ column -> getAutoincrement ( ) , 'primary_key' => $ this -> isPrimaryKey ( $ table , $ column ) , 'foreign_key' => $ this -> isForeignKey ( $ table , $ column ) ] ; } return $ fileds ; }
get database fileds
6,311
protected function isPrimaryKey ( Table $ table , Column $ column ) { if ( $ table -> hasPrimaryKey ( ) ) { $ primaryKeys = $ table -> getPrimaryKey ( ) -> getColumns ( ) ; return in_array ( $ column -> getName ( ) , $ primaryKeys ) ; } return false ; }
check is column primary key
6,312
protected function isForeignKey ( Table $ table , Column $ column ) { $ foreignKey = false ; foreach ( $ table -> getIndexes ( ) as $ key => $ index ) { if ( $ key !== 'primary' ) { try { $ fkConstrain = $ table -> getForeignkey ( $ key ) ; $ foreignKey = in_array ( $ column -> getName ( ) , $ fkConstrain -> getColumns ( ) ) ; } catch ( Exception $ e ) { } } } return $ foreignKey ; }
check is column foreign key
6,313
public function getFields ( $ table ) { if ( isset ( $ this -> tables [ $ table ] ) ) { return new Collection ( $ this -> tables [ $ table ] ) ; } }
get table fields
6,314
public function isFieldExists ( $ table , $ field ) { if ( isset ( $ this -> tables [ $ table ] ) ) { $ fields = $ this -> getFields ( $ table ) ; return $ fields -> where ( 'name' , $ field ) -> count ( ) > 0 ; } return false ; }
check is model table exists
6,315
public function filter ( $ value , array $ options = [ ] ) { if ( ! is_string ( $ value ) ) return $ value ; $ value = trim ( $ value ) ; if ( ! Str :: startsWith ( $ value , [ 'http://' , 'https://' ] ) ) { $ value = "http://$value" ; } return filter_var ( $ value , FILTER_SANITIZE_URL ) ; }
Sanitize url of the given string .
6,316
public static function add ( $ key , $ value , $ expires ) { $ cache = self :: instance ( ) ; if ( $ cache && $ value != null ) { $ cache -> set ( $ key , $ value , $ expires * 60 ) ; } }
Adds a value to cache .
6,317
public static function has ( $ key ) { $ cache = self :: instance ( ) ; if ( $ cache ) { return $ cache -> isExisting ( $ key ) ; } return false ; }
Returns flag if a given key has a value in cache or not .
6,318
public static function remember ( $ key , $ expires , Closure $ closure ) { $ cache = self :: instance ( ) ; if ( $ cache ) { if ( $ cache -> isExisting ( $ key ) ) { return $ cache -> get ( $ key ) ; } else if ( $ closure != null ) { $ value = $ closure ( ) ; $ cache -> set ( $ key , $ value , $ expires * 60 ) ; return $ value ; } } return $ closure ( ) ; }
Returns the value of a given key . If it doesn t exist then the value pass by is returned .
6,319
protected function defineActivationHooks ( ) : void { $ backend = $ this -> getBackend ( ) ; $ pluginName = $ this -> getFilename ( ) ; $ handlers = [ "activate" , "deactivate" , "uninstall" ] ; foreach ( $ handlers as $ handler ) { $ hook = $ handler . "_" . $ pluginName ; $ this -> loader -> addAction ( $ hook , $ backend , $ handler ) ; } }
Defines hooks using the Backend object for the activate deactivate and uninstall actions of this plugin .
6,320
private function _createEntries ( array $ data ) { foreach ( $ data as $ row ) { $ mandatories = array ( 'title' , 'link' , 'description' ) ; foreach ( $ mandatories as $ mandatory ) { if ( ! isset ( $ row [ $ mandatory ] ) ) { require_once 'Zend/Feed/Builder/Exception.php' ; throw new Zend_Feed_Builder_Exception ( "$mandatory key is missing" ) ; } } $ entry = new Zend_Feed_Builder_Entry ( $ row [ 'title' ] , $ row [ 'link' ] , $ row [ 'description' ] ) ; if ( isset ( $ row [ 'author' ] ) ) { $ entry -> setAuthor ( $ row [ 'author' ] ) ; } if ( isset ( $ row [ 'guid' ] ) ) { $ entry -> setId ( $ row [ 'guid' ] ) ; } if ( isset ( $ row [ 'content' ] ) ) { $ entry -> setContent ( $ row [ 'content' ] ) ; } if ( isset ( $ row [ 'lastUpdate' ] ) ) { $ entry -> setLastUpdate ( $ row [ 'lastUpdate' ] ) ; } if ( isset ( $ row [ 'comments' ] ) ) { $ entry -> setCommentsUrl ( $ row [ 'comments' ] ) ; } if ( isset ( $ row [ 'commentRss' ] ) ) { $ entry -> setCommentsRssUrl ( $ row [ 'commentRss' ] ) ; } if ( isset ( $ row [ 'source' ] ) ) { $ mandatories = array ( 'title' , 'url' ) ; foreach ( $ mandatories as $ mandatory ) { if ( ! isset ( $ row [ 'source' ] [ $ mandatory ] ) ) { require_once 'Zend/Feed/Builder/Exception.php' ; throw new Zend_Feed_Builder_Exception ( "$mandatory key of source property is missing" ) ; } } $ entry -> setSource ( $ row [ 'source' ] [ 'title' ] , $ row [ 'source' ] [ 'url' ] ) ; } if ( isset ( $ row [ 'category' ] ) ) { $ entry -> setCategories ( $ row [ 'category' ] ) ; } if ( isset ( $ row [ 'enclosure' ] ) ) { $ entry -> setEnclosures ( $ row [ 'enclosure' ] ) ; } $ this -> _entries [ ] = $ entry ; } }
Create the array of article entries
6,321
private function getAttrAsArray ( \ DOMElement $ element ) { $ return = [ ] ; for ( $ i = 0 ; $ i < $ element -> attributes -> length ; ++ $ i ) { $ return [ $ element -> attributes -> item ( $ i ) -> nodeName ] = $ element -> attributes -> item ( $ i ) -> nodeValue ; } return $ return ; }
Get element attributes as array .
6,322
private function setCover ( Item $ item , $ id , $ type ) { $ item -> setCover ( self :: NAME . '/' . $ id . '/1.jpg' ) ; return $ this -> uploadImage ( $ this -> getCoverUrl ( $ id , $ type ) , $ item ) ; }
Get cover from source id .
6,323
private function getGenreByName ( $ name ) { if ( isset ( $ this -> genres [ $ name ] ) ) { return $ this -> doctrine -> getRepository ( 'AnimeDbCatalogBundle:Genre' ) -> findOneByName ( $ this -> genres [ $ name ] ) ; } }
Get real genre by name .
6,324
private function getTypeByName ( $ name ) { if ( isset ( $ this -> types [ $ name ] ) ) { return $ this -> doctrine -> getRepository ( 'AnimeDbCatalogBundle:Type' ) -> find ( $ this -> types [ $ name ] ) ; } }
Get real type by name .
6,325
public function getFrames ( $ id , $ type ) { $ dom = $ this -> browser -> getDom ( '/' . $ type . '/' . $ type . '_photos.php?id=' . $ id ) ; if ( ! $ dom ) { return [ ] ; } $ images = ( new \ DOMXPath ( $ dom ) ) -> query ( '//table//table//table//img' ) ; $ frames = [ ] ; foreach ( $ images as $ image ) { $ src = $ this -> getAttrAsArray ( $ image ) [ 'src' ] ; $ entity = new Image ( ) ; if ( $ type == self :: ITEM_TYPE_ANIMATION ) { $ src = str_replace ( 'optimize_b' , 'optimize_d' , $ src ) ; if ( strpos ( $ src , 'http://' ) === false ) { $ src = $ this -> browser -> getHost ( ) . '/' . $ type . '/' . $ src ; } if ( preg_match ( '/\-(?<image>\d+)\-optimize_d(?<ext>\.jpe?g|png|gif)/' , $ src , $ mat ) ) { $ entity -> setSource ( self :: NAME . '/' . $ id . '/' . $ mat [ 'image' ] . $ mat [ 'ext' ] ) ; if ( $ this -> uploadImage ( $ src , $ entity ) ) { $ frames [ ] = $ entity ; } } } elseif ( preg_match ( '/_(?<round>\d+)\/.+\/(?<id>\d+)-(?<image>\d+)-.+(?<ext>\.jpe?g|png|gif)/' , $ src , $ mat ) ) { $ src = $ this -> browser -> getHost ( ) . '/' . $ type . '/img/' . $ mat [ 'round' ] . '/' . $ mat [ 'id' ] . '/' . $ mat [ 'image' ] . $ mat [ 'ext' ] ; $ entity -> setSource ( self :: NAME . '/' . $ id . '/' . $ mat [ 'image' ] . $ mat [ 'ext' ] ) ; if ( $ this -> uploadImage ( $ src , $ entity ) ) { $ frames [ ] = $ entity ; } } } return $ frames ; }
Get item frames .
6,326
private function getNodeValueAsText ( \ DOMNode $ node ) { $ text = $ node -> ownerDocument -> saveHTML ( $ node ) ; $ text = str_replace ( [ "<br>\n" , "\n" , '<br>' ] , [ '<br>' , ' ' , "\n" ] , $ text ) ; return trim ( strip_tags ( $ text ) ) ; }
Get node value as text .
6,327
private function getStudio ( \ DOMXPath $ xpath , \ DOMNode $ body ) { $ studios = $ xpath -> query ( '//img[starts-with(@src,"http://www.world-art.ru/img/company_new/")]' , $ body ) ; if ( $ studios -> length ) { foreach ( $ studios as $ studio ) { $ url = $ studio -> attributes -> getNamedItem ( 'src' ) -> nodeValue ; if ( preg_match ( '/\/(\d+)\./' , $ url , $ mat ) && isset ( $ this -> studios [ $ mat [ 1 ] ] ) ) { return $ this -> doctrine -> getRepository ( 'AnimeDbCatalogBundle:Studio' ) -> findOneByName ( $ this -> studios [ $ mat [ 1 ] ] ) ; } } } }
Get item studio .
6,328
public function getItemType ( $ url ) { if ( strpos ( $ url , self :: ITEM_TYPE_ANIMATION . '/' . self :: ITEM_TYPE_ANIMATION ) !== false ) { return self :: ITEM_TYPE_ANIMATION ; } elseif ( strpos ( $ url , self :: ITEM_TYPE_CINEMA . '/' . self :: ITEM_TYPE_CINEMA ) !== false ) { return self :: ITEM_TYPE_CINEMA ; } else { return ; } }
Get item type by URL .
6,329
protected function fillAnimationNames ( Item $ item , \ DOMXPath $ xpath , \ DOMElement $ head ) { $ names = $ xpath -> query ( 'table[1]/tr/td' , $ head ) -> item ( 0 ) -> nodeValue ; $ names = explode ( "\n" , trim ( $ names ) ) ; $ name = preg_replace ( '/\[\d{4}\]/' , '' , array_shift ( $ names ) ) ; $ name = preg_replace ( '/\[?(ТВ|OVA|ONA)(\-\d)?\]?/', ' , $ a me); / $ name = preg_replace ( '/\(фильм \w+\)/u', '', na m ) ; // e $ name = preg_replace ( '/ - Фильм$/iu', '', na m ) ; // e $ item -> setName ( trim ( $ name ) ) ; foreach ( $ names as $ name ) { $ name = trim ( preg_replace ( '/(\(\d+\))?/' , '' , $ name ) ) ; $ item -> addName ( ( new Name ( ) ) -> setName ( $ name ) ) ; } return $ item ; }
Fill names for Animation type .
6,330
public function getCoverUrl ( $ id , $ type ) { switch ( $ type ) { case self :: ITEM_TYPE_ANIMATION : return $ this -> browser -> getHost ( ) . '/' . $ type . '/img/' . ( ceil ( $ id / 1000 ) * 1000 ) . '/' . $ id . '/1.jpg' ; case self :: ITEM_TYPE_CINEMA : return $ this -> browser -> getHost ( ) . '/' . $ type . '/img/' . ( ceil ( $ id / 10000 ) * 10000 ) . '/' . $ id . '/1.jpg' ; default : return ; } }
Get cover URL .
6,331
public function preSend ( Event $ e ) { $ validator = new NotEmpty ( ) ; if ( ! isset ( $ this -> options [ 'tokenOrLogin' ] ) || ! $ validator -> isValid ( $ this -> options [ 'tokenOrLogin' ] ) ) { throw new Exception \ InvalidArgumentException ( 'You need to set OAuth token!' ) ; } $ request = $ e -> getTarget ( ) ; $ query = $ request -> getQuery ( ) ; $ query -> set ( 'access_token' , $ this -> options [ 'tokenOrLogin' ] ) ; }
Add access token to Request Parameters
6,332
final protected function initPostStatusesTrait ( ) : void { $ postStatuses = $ this -> getPostStatuses ( ) ; $ options = [ ] ; foreach ( $ postStatuses as $ postStatus ) { $ args = $ this -> getPostStatusArguments ( $ postStatus ) ; add_action ( "init" , function ( ) use ( $ postStatus , $ args ) { register_post_status ( $ postStatus , $ args ) ; } ) ; $ options [ $ postStatus ] = $ args [ "label" ] ; } add_action ( "post_submitbox_misc_actions" , function ( \ WP_Post $ post ) use ( $ options ) { $ jsonOptions = "{" ; $ optionFormat = '"%s": { "display": "%s", "selected": %d },' ; foreach ( $ options as $ status => $ display ) { $ selected = ( int ) $ post -> post_status === $ status ; $ jsonOptions .= sprintf ( $ optionFormat , $ status , $ display , $ selected ) ; } $ jsonOptions = preg_replace ( "/,$/" , "}" , $ jsonOptions ) ; ob_start ( ) ; ?> <script id="php7BoilerplateAddPostStatuses"> (function ($) { // we'll add our statuses into the scope of this // anonymous functions. that way, it's accessible // to the other functions, anonymous or otherwise, // herein. but, it won't conflict with any other // variable named statuses outside this scope. var statuses = <?= $ jsonOptions ?> ; $(document).ready(function () { var statusSelect = $("#post_status"); if (statusSelect.length > 0) { // as long as we have a status <select> in // the DOM, we'll want to do some work to make // our custom statuses work. setDisplayedStatus(statusSelect); $(".save-post-status").click(setHiddenStatus); addCustomStatuses(statusSelect); } }); function setDisplayedStatus(statusSelect) { var status = statusSelect.val(); // as long as our status is in our list of custom // statuses, we want to make sure that the on- // screen display of the posts's status matches // the display of the selected option. if ($.inArray(status, statuses)) { var display = statusSelect.find("option[value=" + status + "]").text(); $("#post-status-display").text(display); } } function setHiddenStatus() { var status = $("#post_status").val(); // as long as the status that's selected is a part // of our list of statuses, we'll want to set the // the value of the #hidden_post_status field to // the selected status. if ($.inArray(status, statuses)) { $("#hidden_post_status").val(status); } } function addCustomStatuses(statusSelect) { for(status in statuses) { if (statuses.hasOwnProperty(status)) { // for each of our custom statuses, we // create an <option>. if our status is // selected, then we set that property. // otherwise, we set various attributes // and then append it to our <select> // element. var option = $("<option>") .prop("selected", statuses[status].selected) .text(statuses[status].display) .attr("value", status) .data("custom", true); statusSelect.append(option); } } // in case we need to do anything else after we've // changed the DOM, we fire this event, too. then, // other JS can watch for it and handle any clean // up or whatever when it's caught. var event = new jQuery.Event("postStatusesAdded"); statusSelect.trigger(event); } })(jQuery); </script> <?php echo ob_get_clean ( ) ; } ) ; }
When we initialize this trait we want to register our post statuses and ensure that they appear in the status drop - downs throughout Word - Press core .
6,333
public static function insert ( $ table , $ values = array ( ) , $ handler = null ) { return Query_Insert :: create ( $ table , $ handler ) -> values ( $ values ) ; }
Create an insert
6,334
public function or_where ( $ column , $ param1 = null , $ param2 = null ) { return $ this -> where ( $ column , $ param1 , $ param2 , 'or' ) ; }
Create an or where statement
6,335
public function getLogManager ( ) : ? LogManager { if ( ! $ this -> hasLogManager ( ) ) { $ this -> setLogManager ( $ this -> getDefaultLogManager ( ) ) ; } return $ this -> logManager ; }
Get log manager
6,336
public static function bundle ( $ name , $ path = null ) { static :: $ bundles [ $ name ] = $ path ; static :: $ namespaces [ $ name ] = $ path . CCDIR_CLASS ; }
Add a bundle A bundle is a CCF style package with classes controllers views etc .
6,337
public static function map ( $ name , $ path = null ) { if ( is_array ( $ name ) ) { static :: $ namespaces = array_merge ( static :: $ namespaces , $ name ) ; return ; } static :: $ namespaces [ $ name ] = $ path ; }
Add one or more maps A map is simply a class namepsace
6,338
public static function shadow ( $ name , $ namespace , $ path = null ) { static :: $ shadows [ $ name ] = $ class = $ namespace . "\\" . $ name ; if ( ! is_null ( $ path ) ) { static :: bind ( $ name , $ class ) ; } }
Add a shadow class A shadow class is a global class and gets liftet to the global namespace .
6,339
public static function alias ( $ name , $ path = null ) { if ( is_array ( $ name ) ) { static :: $ aliases = array_merge ( static :: $ aliases , $ name ) ; return ; } static :: $ aliases [ $ name ] = $ path ; }
Add one or more aliases An alias can overwrite an shadow . This way we can extend other classes .
6,340
public static function bind ( $ name , $ path = null ) { if ( is_array ( $ name ) ) { static :: $ classes = array_merge ( static :: $ classes , $ name ) ; return ; } static :: $ classes [ $ name ] = $ path ; }
Add one or more class to the autoloader
6,341
public static function package ( $ dir , $ classes ) { foreach ( $ classes as $ name => $ path ) { static :: $ classes [ $ name ] = $ dir . $ path ; } }
This simply adds some classes with a prefix
6,342
public static function shadow_package ( $ dir , $ namespace , $ shadows ) { foreach ( $ shadows as $ name => $ path ) { static :: $ shadows [ $ name ] = $ class = $ namespace . "\\" . $ name ; static :: $ classes [ $ class ] = $ dir . $ path ; } }
This simply adds some shadows with a prefix
6,343
public function setData ( $ data , $ key = null ) { if ( is_array ( $ data ) && $ key === null ) { $ this -> data = $ data ; return $ this ; } if ( $ key === null ) $ key = 'data' ; $ this -> data [ $ key ] = $ data ; return $ this ; }
setting data to add for the logging action
6,344
public function body ( CryptographyEngine $ cryptographyEngine ) { $ body = array ( 'hash' => $ cryptographyEngine -> hash ( $ this -> email ) , 'action' => $ this -> action , ) ; if ( ! empty ( $ this -> scope ) ) $ body [ 'scope' ] = $ this -> scope ; if ( ! empty ( $ this -> data ) ) $ body [ 'data' ] = $ cryptographyEngine -> encrypt ( json_encode ( $ this -> data ) , $ this -> email ) ; if ( ! empty ( $ this -> ip ) ) $ body [ 'ip' ] = $ this -> ip ; if ( ! empty ( $ this -> useragent ) ) $ body [ 'useragent' ] = $ this -> useragent ; if ( ! empty ( $ this -> created_at ) ) $ body [ 'created_at' ] = $ this -> created_at ; return json_encode ( $ body ) ; }
returns the body
6,345
public function getPath ( $ id ) { $ node = $ this -> getNode ( $ id ) ; if ( ! $ node ) { return [ ] ; } $ left = $ this -> getConfig ( 'leftField' ) ; $ right = $ this -> getConfig ( 'rightField' ) ; return $ this -> getRepository ( ) -> select ( ) -> where ( $ left , '<' , $ node [ $ left ] ) -> where ( $ right , '>' , $ node [ $ right ] ) -> orderBy ( $ left , 'asc' ) -> all ( ) ; }
Return the hierarchical path to the current node .
6,346
public function getTree ( $ id = null ) { $ parent = $ this -> getConfig ( 'parentField' ) ; $ left = $ this -> getConfig ( 'leftField' ) ; $ right = $ this -> getConfig ( 'rightField' ) ; $ query = $ this -> getRepository ( ) -> select ( ) -> orderBy ( $ left , 'asc' ) ; if ( $ id ) { if ( $ parentNode = $ this -> getNode ( $ id ) ) { $ query -> where ( $ left , 'between' , [ $ parentNode [ $ left ] , $ parentNode [ $ right ] ] ) ; } else { return [ ] ; } } $ nodes = $ query -> all ( ) ; if ( $ nodes -> isEmpty ( ) ) { return [ ] ; } $ map = [ ] ; $ stack = [ ] ; $ pk = $ this -> getRepository ( ) -> getPrimaryKey ( ) ; foreach ( $ nodes as $ node ) { if ( $ node [ $ parent ] && $ node [ $ pk ] != $ id ) { $ map [ $ node [ $ parent ] ] [ ] = $ node ; } else { $ stack [ ] = $ node ; } } $ results = $ this -> mapTree ( $ stack , $ map ) ; if ( $ id ) { return $ results [ 0 ] ; } return $ results ; }
Return a tree of nested nodes . If no ID is provided the top level root will be used .
6,347
public function mapList ( array $ nodes , $ key , $ value , $ spacer ) { $ tree = [ ] ; $ stack = [ ] ; $ key = $ key ? : $ this -> getRepository ( ) -> getPrimaryKey ( ) ; $ value = $ value ? : $ this -> getRepository ( ) -> getDisplayField ( ) ; $ right = $ this -> getConfig ( 'rightField' ) ; foreach ( $ nodes as $ node ) { $ count = count ( $ stack ) ; while ( $ count && $ stack [ $ count - 1 ] < $ node [ $ right ] ) { array_pop ( $ stack ) ; $ count -- ; } $ tree [ $ node [ $ key ] ] = str_repeat ( $ spacer , $ count ) . $ node [ $ value ] ; $ stack [ ] = $ node [ $ right ] ; } return $ tree ; }
Map a nested tree using the primary key and display field as the values to populate the list . Nested lists will be prepended with a spacer to indicate indentation .
6,348
public function mapTree ( array $ nodes , array $ mappedNodes = [ ] ) { if ( ! $ mappedNodes ) { return $ nodes ; } $ tree = [ ] ; $ pk = $ this -> getRepository ( ) -> getPrimaryKey ( ) ; foreach ( $ nodes as $ node ) { $ id = $ node [ $ pk ] ; if ( isset ( $ mappedNodes [ $ id ] ) ) { $ node [ $ this -> getConfig ( 'treeField' ) ? : 'Nodes' ] = $ this -> mapTree ( $ mappedNodes [ $ id ] , $ mappedNodes ) ; } $ tree [ ] = $ node ; } return $ tree ; }
Map a nested tree of arrays using the parent node stack and the mapped nodes by parent ID .
6,349
public function preDelete ( Event $ event , Query $ query , $ id ) { if ( ! $ this -> getConfig ( 'onDelete' ) ) { return true ; } if ( $ node = $ this -> getNode ( $ id ) ) { $ count = $ this -> getRepository ( ) -> select ( ) -> where ( $ this -> getConfig ( 'parentField' ) , $ id ) -> count ( ) ; if ( $ count ) { return false ; } $ this -> _deleteIndex = $ node [ $ this -> getConfig ( 'leftField' ) ] ; } return true ; }
Before a delete fetch the node and save its left index . If a node has children the delete will fail .
6,350
public function postDelete ( Event $ event , $ id , $ count ) { if ( ! $ this -> getConfig ( 'onDelete' ) || ! $ this -> _deleteIndex ) { return ; } $ this -> _removeNode ( $ id , $ this -> _deleteIndex ) ; $ this -> _deleteIndex = null ; }
After a delete shift all nodes up using the base index .
6,351
public function postSave ( Event $ event , $ id , $ count ) { if ( ! $ this -> getConfig ( 'onSave' ) || ! $ this -> _saveIndex ) { return ; } $ this -> _insertNode ( $ id , $ this -> _saveIndex ) ; $ this -> _saveIndex = null ; }
After an insert shift all nodes down using the base index .
6,352
protected function _moveNode ( Closure $ callback , array $ data ) { return $ this -> getRepository ( ) -> updateMany ( $ data , $ callback , [ 'before' => false , 'after' => false ] ) ; }
Move a node or nodes by applying a where clause to an update query and saving data . Disable before and after callbacks to recursive events don t trigger .
6,353
protected function _removeNode ( $ id , $ index ) { $ pk = $ this -> getRepository ( ) -> getPrimaryKey ( ) ; foreach ( [ $ this -> getConfig ( 'leftField' ) , $ this -> getConfig ( 'rightField' ) ] as $ field ) { $ this -> _moveNode ( function ( Query $ query ) use ( $ field , $ index , $ id , $ pk ) { $ query -> where ( $ field , '>=' , $ index ) ; if ( $ id ) { $ query -> where ( $ pk , '!=' , $ id ) ; } } , [ $ field => Query :: expr ( $ field , '-' , 2 ) ] ) ; } }
Prepares a node for removal by moving all following nodes up .
6,354
protected function _reOrder ( $ parent_id , $ left , array $ order = [ ] ) { $ parent = $ this -> getConfig ( 'parentField' ) ; $ repo = $ this -> getRepository ( ) ; $ pk = $ repo -> getPrimaryKey ( ) ; $ right = $ left + 1 ; $ children = $ repo -> select ( ) -> where ( $ parent , $ parent_id ) -> orderBy ( $ order ) -> all ( ) ; foreach ( $ children as $ child ) { $ right = $ this -> _reOrder ( $ child [ $ pk ] , $ right , $ order ) ; } if ( $ parent_id ) { $ this -> _moveNode ( function ( Query $ query ) use ( $ pk , $ parent_id ) { $ query -> where ( $ pk , $ parent_id ) ; } , [ $ this -> getConfig ( 'leftField' ) => $ left , $ this -> getConfig ( 'rightField' ) => $ right ] ) ; } return $ right + 1 ; }
Re - order the tree by recursively looping through all parents and children ordering the results and generating the correct left and right indexes .
6,355
public function getPath ( $ node ) { $ qb = $ this -> createQueryBuilder ( 'node' ) ; $ qb -> where ( $ qb -> expr ( ) -> lte ( 'node.lft' , $ node -> getLft ( ) ) ) -> andWhere ( $ qb -> expr ( ) -> gte ( 'node.rgt' , $ node -> getRgt ( ) ) ) -> andWhere ( 'node.context = :context' ) -> orderBy ( 'node.lft' , 'ASC' ) ; $ query = $ qb -> getQuery ( ) -> setParameter ( 'context' , $ node -> getContext ( ) ) ; return $ query -> getResult ( ) ; }
Get the path of a node
6,356
public function menu ( array $ links , array $ options = array ( ) ) { $ align = ( isset ( $ options [ 'pull' ] ) ) ? ' navbar-' . $ options [ 'pull' ] : '' ; unset ( $ options [ 'pull' ] ) ; return "\n\t" . '<ul class="nav navbar-nav' . $ align . '">' . $ this -> links ( 'li' , $ links , $ options ) . '</ul>' ; }
Create a menu of links across your navbar .
6,357
public function text ( $ string , $ pull = false ) { $ align = ( in_array ( $ pull , array ( 'left' , 'right' ) ) ) ? ' navbar-' . $ pull : '' ; return "\n\t" . '<p class="navbar-text' . $ align . '">' . $ this -> addClass ( $ string , array ( 'a' => 'navbar-link' ) ) . '</p>' ; }
Add a string of text to your navbar .
6,358
public function assets ( $ type = 'css' ) { $ output = [ ] ; $ assets = $ this -> Assets -> getAssets ( $ type ) ; foreach ( $ assets as $ asset ) { $ output [ ] = $ asset [ 'output' ] ; } return implode ( $ this -> eol , $ output ) ; }
Get assets fot layout render .
6,359
public function beforeLayout ( Event $ event , $ layoutFile ) { $ pluginEvent = Plugin :: getData ( 'Core' , 'View.beforeLayout' ) ; if ( is_callable ( $ pluginEvent -> find ( 0 ) ) && Plugin :: hasManifestEvent ( 'View.beforeLayout' ) ) { call_user_func_array ( $ pluginEvent -> find ( 0 ) , [ $ this -> _View , $ event , $ layoutFile ] ) ; } }
Is called before layout rendering starts . Receives the layout filename as an argument .
6,360
public function beforeRenderFile ( Event $ event , $ viewFile ) { $ pluginEvent = Plugin :: getData ( 'Core' , 'View.beforeRenderFile' ) ; if ( is_callable ( $ pluginEvent -> find ( 0 ) ) && Plugin :: hasManifestEvent ( 'View.beforeRenderFile' ) ) { call_user_func_array ( $ pluginEvent -> find ( 0 ) , [ $ this -> _View , $ event , $ viewFile ] ) ; } }
Is called before each view file is rendered . This includes elements views parent views and layouts .
6,361
public function getBodyClasses ( ) { $ prefix = ( $ this -> request -> getParam ( 'prefix' ) ) ? 'prefix-' . $ this -> request -> getParam ( 'prefix' ) : 'prefix-site' ; $ classes = [ $ prefix , 'theme-' . Str :: low ( $ this -> _View -> theme ) , 'plugin-' . Str :: low ( $ this -> _View -> plugin ) , 'view-' . Str :: low ( $ this -> _View -> name ) , 'tmpl-' . Str :: low ( $ this -> _View -> template ) , 'layout-' . Str :: low ( $ this -> _View -> layout ) ] ; $ pass = ( array ) $ this -> request -> getParam ( 'pass' ) ; if ( count ( $ pass ) ) { $ classes [ ] = 'item-id-' . array_shift ( $ pass ) ; } return implode ( ' ' , $ classes ) ; }
Get body classes by view data .
6,362
public function head ( ) { $ output = [ 'meta' => $ this -> _View -> fetch ( 'meta' ) , 'assets' => $ this -> assets ( 'css' ) , 'fetch_css' => $ this -> _View -> fetch ( 'css' ) , 'fetch_css_bottom' => $ this -> _View -> fetch ( 'css_bottom' ) , ] ; return implode ( '' , $ output ) ; }
Create head for layout .
6,363
public function lang ( $ isLang = true ) { list ( $ lang , $ region ) = explode ( '_' , $ this -> locale ) ; return ( $ isLang ) ? Str :: low ( $ lang ) : Str :: low ( $ region ) ; }
Site language .
6,364
public function meta ( array $ rows , $ block = null ) { $ output = [ ] ; foreach ( $ rows as $ row ) { $ output [ ] = trim ( $ row ) ; } $ output = implode ( $ this -> eol , $ output ) . $ this -> eol ; if ( $ block !== null ) { $ this -> _View -> append ( $ block , $ output ) ; return null ; } return $ output ; }
Creates a link to an external resource and handles basic meta tags .
6,365
public function type ( ) { $ lang = $ this -> lang ( ) ; $ html = [ '<!doctype html>' , '<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7 ie6" ' . 'lang="' . $ lang . '" dir="' . $ this -> dir . '"> <![endif] , '<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8 ie7" ' . 'lang="' . $ lang . '" dir="' . $ this -> dir . '"> <![endif] , '<!--[if IE 8]><html class="no-js lt-ie9 ie8" ' . 'lang="' . $ lang . '" dir="' . $ this -> dir . '"> <![endif] , '<!--[if gt IE 8]><! . 'lang="' . $ lang . '" dir="' . $ this -> dir . '" ' . 'prefix="og: http://ogp.me/ns#" ' . '> <!--<![endif] , ] ; return implode ( $ this -> eol , $ html ) . $ this -> eol ; }
Create html 5 document type .
6,366
protected function _assignMeta ( $ key ) { if ( Arr :: key ( $ key , $ this -> _View -> viewVars ) ) { $ this -> _View -> assign ( $ key , $ this -> _View -> viewVars [ $ key ] ) ; } return $ this ; }
Assign data from view vars .
6,367
public static function select ( $ type , $ sql , $ binds = null ) { if ( in_array ( $ type , self :: $ types ) == false ) { $ exception = bootstrap :: get_library ( 'exception' ) ; throw new $ exception ( 'unknown select type' ) ; } $ results = self :: query ( $ sql , $ binds ) ; return self :: { 'as_' . $ type } ( $ results ) ; }
executes a SELECT statement and returns the result as array row or single field
6,368
public static function query ( $ sql , $ binds = null ) { if ( ! empty ( $ binds ) ) { $ sql = self :: merge ( $ sql , $ binds ) ; } if ( preg_match ( '{^(UPDATE|DELETE)\s}' , $ sql ) && preg_match ( '{\s(WHERE|LIMIT)\s}' , $ sql ) == false ) { $ exception = bootstrap :: get_library ( 'exception' ) ; throw new $ exception ( 'unsafe UPDATE/DELETE statement, use a WHERE/LIMIT clause' ) ; } return self :: raw ( $ sql ) ; }
executes any query on the database
6,369
private static function merge ( $ sql , $ binds ) { if ( is_array ( $ binds ) == false ) { $ binds = ( array ) $ binds ; } if ( is_null ( self :: $ connection ) ) { $ exception = bootstrap :: get_library ( 'exception' ) ; $ response = bootstrap :: get_library ( 'response' ) ; throw new $ exception ( 'no db connection' , $ response :: STATUS_SERVICE_UNAVAILABLE ) ; } foreach ( $ binds as & $ argument ) { $ argument = self :: $ connection -> real_escape_string ( $ argument ) ; } return vsprintf ( $ sql , $ binds ) ; }
merges bind values while escaping them
6,370
protected function registerPlugin ( ) { $ id = $ this -> options [ 'id' ] ; $ view = $ this -> getView ( ) ; MasonryAsset :: register ( $ view ) ; ImagesLoadedAsset :: register ( $ view ) ; $ js = [ ] ; $ js [ ] = "var mscontainer$id = $('#$id');" ; $ js [ ] = "mscontainer$id.imagesLoaded(function(){mscontainer$id.masonry()});" ; $ view -> registerJs ( implode ( "\n" , $ js ) , View :: POS_END ) ; }
Registers the widget and the related events
6,371
public static function getError ( $ unset = false ) { JLog :: add ( 'JError::getError() is deprecated.' , JLog :: WARNING , 'deprecated' ) ; if ( ! isset ( self :: $ stack [ 0 ] ) ) { return false ; } if ( $ unset ) { $ error = array_shift ( self :: $ stack ) ; } else { $ error = & self :: $ stack [ 0 ] ; } return $ error ; }
Method for retrieving the last exception object in the error stack
6,372
public static function addToStack ( JException & $ e ) { JLog :: add ( 'JError::addToStack() is deprecated.' , JLog :: WARNING , 'deprecated' ) ; self :: $ stack [ ] = & $ e ; }
Method to add non - JError thrown JExceptions to the JError stack for debugging purposes
6,373
public static function raise ( $ level , $ code , $ msg , $ info = null , $ backtrace = false ) { JLog :: add ( 'JError::raise() is deprecated.' , JLog :: WARNING , 'deprecated' ) ; $ class = $ code == 404 ? 'JExceptionNotFound' : 'JException' ; $ exception = new $ class ( $ msg , $ code , $ level , $ info , $ backtrace ) ; return self :: throwError ( $ exception ) ; }
Create a new JException object given the passed arguments
6,374
public static function setErrorHandling ( $ level , $ mode , $ options = null ) { JLog :: add ( 'JError::setErrorHandling() is deprecated.' , JLog :: WARNING , 'deprecated' ) ; $ levels = self :: $ levels ; $ function = 'handle' . ucfirst ( $ mode ) ; if ( ! is_callable ( array ( 'JError' , $ function ) ) ) { return self :: raiseError ( E_ERROR , 'JError:' . JERROR_ILLEGAL_MODE , 'Error Handling mode is not known' , 'Mode: ' . $ mode . ' is not implemented.' ) ; } foreach ( $ levels as $ eLevel => $ eTitle ) { if ( ( $ level & $ eLevel ) != $ eLevel ) { continue ; } if ( $ mode == 'callback' ) { if ( ! is_array ( $ options ) ) { return self :: raiseError ( E_ERROR , 'JError:' . JERROR_ILLEGAL_OPTIONS , 'Options for callback not valid' ) ; } if ( ! is_callable ( $ options ) ) { $ tmp = array ( 'GLOBAL' ) ; if ( is_array ( $ options ) ) { $ tmp [ 0 ] = $ options [ 0 ] ; $ tmp [ 1 ] = $ options [ 1 ] ; } else { $ tmp [ 1 ] = $ options ; } return self :: raiseError ( E_ERROR , 'JError:' . JERROR_CALLBACK_NOT_CALLABLE , 'Function is not callable' , 'Function:' . $ tmp [ 1 ] . ' scope ' . $ tmp [ 0 ] . '.' ) ; } } self :: $ handlers [ $ eLevel ] = array ( 'mode' => $ mode ) ; if ( $ options != null ) { self :: $ handlers [ $ eLevel ] [ 'options' ] = $ options ; } } return true ; }
Method to set the way the JError will handle different error levels . Use this if you want to override the default settings .
6,375
public static function registerErrorLevel ( $ level , $ name , $ handler = 'ignore' ) { JLog :: add ( 'JError::registerErrorLevel() is deprecated.' , JLog :: WARNING , 'deprecated' ) ; if ( isset ( self :: $ levels [ $ level ] ) ) { return false ; } self :: $ levels [ $ level ] = $ name ; self :: setErrorHandling ( $ level , $ handler ) ; return true ; }
Method to register a new error level for handling errors
6,376
public static function handleEcho ( & $ error , $ options ) { JLog :: add ( 'JError::handleEcho() is deprecated.' , JLog :: WARNING , 'deprecated' ) ; $ level_human = self :: translateErrorLevel ( $ error -> get ( 'level' ) ) ; if ( JDEBUG ) { $ backtrace = $ error -> getTrace ( ) ; $ trace = '' ; for ( $ i = count ( $ backtrace ) - 1 ; $ i >= 0 ; $ i -- ) { if ( isset ( $ backtrace [ $ i ] [ 'class' ] ) ) { $ trace .= sprintf ( "\n%s %s %s()" , $ backtrace [ $ i ] [ 'class' ] , $ backtrace [ $ i ] [ 'type' ] , $ backtrace [ $ i ] [ 'function' ] ) ; } else { $ trace .= sprintf ( "\n%s()" , $ backtrace [ $ i ] [ 'function' ] ) ; } if ( isset ( $ backtrace [ $ i ] [ 'file' ] ) ) { $ trace .= sprintf ( ' @ %s:%d' , $ backtrace [ $ i ] [ 'file' ] , $ backtrace [ $ i ] [ 'line' ] ) ; } } } if ( isset ( $ _SERVER [ 'HTTP_HOST' ] ) ) { echo "<br /><b>jos-$level_human</b>: " . $ error -> get ( 'message' ) . "<br />\n" . ( JDEBUG ? nl2br ( $ trace ) : '' ) ; } else { if ( defined ( 'STDERR' ) ) { fwrite ( STDERR , "J$level_human: " . $ error -> get ( 'message' ) . "\n" ) ; if ( JDEBUG ) { fwrite ( STDERR , $ trace ) ; } } else { echo "J$level_human: " . $ error -> get ( 'message' ) . "\n" ; if ( JDEBUG ) { echo $ trace ; } } } return $ error ; }
Echo error handler - Echos the error message to output
6,377
public static function handleVerbose ( & $ error , $ options ) { JLog :: add ( 'JError::handleVerbose() is deprecated.' , JLog :: WARNING , 'deprecated' ) ; $ level_human = self :: translateErrorLevel ( $ error -> get ( 'level' ) ) ; $ info = $ error -> get ( 'info' ) ; if ( isset ( $ _SERVER [ 'HTTP_HOST' ] ) ) { echo "<br /><b>J$level_human</b>: " . $ error -> get ( 'message' ) . "<br />\n" ; if ( $ info != null ) { echo "&#160;&#160;&#160;" . $ info . "<br />\n" ; } echo $ error -> getBacktrace ( true ) ; } else { echo "J$level_human: " . $ error -> get ( 'message' ) . "\n" ; if ( $ info != null ) { echo "\t" . $ info . "\n" ; } } return $ error ; }
Verbose error handler - Echos the error message to output as well as related info
6,378
public static function handleDie ( & $ error , $ options ) { JLog :: add ( 'JError::handleDie() is deprecated.' , JLog :: WARNING , 'deprecated' ) ; $ level_human = self :: translateErrorLevel ( $ error -> get ( 'level' ) ) ; if ( isset ( $ _SERVER [ 'HTTP_HOST' ] ) ) { jexit ( "<br /><b>J$level_human</b>: " . $ error -> get ( 'message' ) . "<br />\n" ) ; } else { if ( defined ( 'STDERR' ) ) { fwrite ( STDERR , "J$level_human: " . $ error -> get ( 'message' ) . "\n" ) ; jexit ( ) ; } else { jexit ( "J$level_human: " . $ error -> get ( 'message' ) . "\n" ) ; } } return $ error ; }
Die error handler - Echos the error message to output and then dies
6,379
public static function handleMessage ( & $ error , $ options ) { JLog :: add ( 'JError::hanleMessage() is deprecated.' , JLog :: WARNING , 'deprecated' ) ; $ appl = JFactory :: getApplication ( ) ; $ type = ( $ error -> get ( 'level' ) == E_NOTICE ) ? 'notice' : 'error' ; $ appl -> enqueueMessage ( $ error -> get ( 'message' ) , $ type ) ; return $ error ; }
Message error handler Enqueues the error message into the system queue
6,380
public static function handleLog ( & $ error , $ options ) { JLog :: add ( 'JError::handleLog() is deprecated.' , JLog :: WARNING , 'deprecated' ) ; static $ log ; if ( $ log == null ) { $ options [ 'text_file' ] = date ( 'Y-m-d' ) . '.error.log' ; $ options [ 'format' ] = "{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}" ; JLog :: addLogger ( $ options , JLog :: ALL , array ( 'error' ) ) ; } $ entry = new JLogEntry ( str_replace ( array ( "\r" , "\n" ) , array ( '' , '\\n' ) , $ error -> get ( 'message' ) ) , $ error -> get ( 'level' ) , 'error' ) ; $ entry -> code = $ error -> get ( 'code' ) ; JLog :: add ( $ entry ) ; return $ error ; }
Log error handler Logs the error message to a system log file
6,381
public static function handleCallback ( & $ error , $ options ) { JLog :: add ( 'JError::handleCallback() is deprecated.' , JLog :: WARNING , 'deprecated' ) ; return call_user_func ( $ options , $ error ) ; }
Callback error handler - Send the error object to a callback method for error handling
6,382
public static function customErrorHandler ( $ level , $ msg ) { JLog :: add ( 'JError::customErrorHandler() is deprecated.' , JLog :: WARNING , 'deprecated' ) ; self :: raise ( $ level , '' , $ msg ) ; }
Display a message to the user
6,383
public function getDefaultStorage ( ) : ? Filesystem { $ manager = Storage :: getFacadeRoot ( ) ; if ( isset ( $ manager ) ) { return $ manager -> disk ( ) ; } return $ manager ; }
Get a default storage value if any is available
6,384
protected function buildEndpoint ( $ type , $ resource , $ datetime ) { $ accountType = $ this -> isSubAccount ? 'SubAccounts' : 'Accounts' ; $ sig = strtoupper ( md5 ( $ this -> accountSid . $ this -> accountToken . $ datetime ) ) ; return sprintf ( self :: ENDPOINT_TEMPLATE , self :: SERVER_IP , self :: SERVER_PORT , self :: SDK_VERSION , $ accountType , $ this -> accountSid , $ type , $ resource , $ sig ) ; }
Build endpoint url .
6,385
public function add ( $ field , $ op , $ value ) { $ param = new Expr ( $ field , $ op , $ value ) ; $ this -> _params [ ] = $ param ; if ( $ param -> useValue ( ) ) { $ this -> addBinding ( $ field , $ value ) ; } return $ this ; }
Process a parameter before adding it to the list . Set the primary predicate type if it has not been set .
6,386
public function also ( Closure $ callback ) { $ predicate = new Predicate ( self :: ALSO ) ; $ predicate -> bindCallback ( $ callback ) ; $ this -> _params [ ] = $ predicate ; $ this -> addBinding ( null , $ predicate ) ; return $ this ; }
Generate a new sub - grouped AND predicate .
6,387
public function between ( $ field , $ start , $ end ) { $ this -> add ( $ field , Expr :: BETWEEN , [ $ start , $ end ] ) ; return $ this ; }
Adds a between range BETWEEN expression .
6,388
public function bindCallback ( Closure $ callback , $ query = null ) { call_user_func_array ( $ callback , [ $ this , $ query ] ) ; return $ this ; }
Bind a Closure callback to this predicate and execute it .
6,389
public function either ( Closure $ callback ) { $ predicate = new Predicate ( self :: EITHER ) ; $ predicate -> bindCallback ( $ callback ) ; $ this -> _params [ ] = $ predicate ; $ this -> addBinding ( null , $ predicate ) ; return $ this ; }
Generate a new sub - grouped OR predicate .
6,390
public function eq ( $ field , $ value ) { if ( is_array ( $ value ) ) { $ this -> in ( $ field , $ value ) ; } else if ( $ value === null ) { $ this -> null ( $ field ) ; } else { $ this -> add ( $ field , '=' , $ value ) ; } return $ this ; }
Adds an equals = expression .
6,391
public function hasParam ( $ field ) { foreach ( $ this -> getParams ( ) as $ param ) { if ( $ param instanceof Expr && $ param -> getField ( ) === $ field ) { return true ; } } return false ; }
Return true if a field has been used in a param .
6,392
public function like ( $ field , $ value ) { $ this -> add ( $ field , Expr :: LIKE , $ value ) ; return $ this ; }
Adds a like wildcard LIKE expression .
6,393
public function maybe ( Closure $ callback ) { $ predicate = new Predicate ( self :: MAYBE ) ; $ predicate -> bindCallback ( $ callback ) ; $ this -> _params [ ] = $ predicate ; $ this -> addBinding ( null , $ predicate ) ; return $ this ; }
Generate a new sub - grouped XOR predicate .
6,394
public function neither ( Closure $ callback ) { $ predicate = new Predicate ( self :: NEITHER ) ; $ predicate -> bindCallback ( $ callback ) ; $ this -> _params [ ] = $ predicate ; $ this -> addBinding ( null , $ predicate ) ; return $ this ; }
Generate a new sub - grouped NOR predicate .
6,395
public function notBetween ( $ field , $ start , $ end ) { $ this -> add ( $ field , Expr :: NOT_BETWEEN , [ $ start , $ end ] ) ; return $ this ; }
Adds a not between range NOT BETWEEN expression .
6,396
public function notEq ( $ field , $ value ) { if ( is_array ( $ value ) ) { $ this -> notIn ( $ field , $ value ) ; } else if ( $ value === null ) { $ this -> notNull ( $ field ) ; } else { $ this -> add ( $ field , '!=' , $ value ) ; } return $ this ; }
Adds a not equals ! = expression .
6,397
public function notLike ( $ field , $ value ) { $ this -> add ( $ field , Expr :: NOT_LIKE , $ value ) ; return $ this ; }
Adds a not like wildcard LIKE expression .
6,398
public function getTimezoneHourOffset ( $ origin_tz = 'UTC' , $ format = 'h' ) { $ remote_tz = 'UTC' ; if ( $ origin_tz === 'UTC' ) { return 0 . 'h' ; } $ origin_dtz = new \ DateTimeZone ( $ origin_tz ) ; $ remote_dtz = new \ DateTimeZone ( $ remote_tz ) ; $ origin_dt = new \ DateTime ( "now" , $ origin_dtz ) ; $ remote_dt = new \ DateTime ( "now" , $ remote_dtz ) ; $ offset = $ remote_dtz -> getOffset ( $ remote_dt ) - $ origin_dtz -> getOffset ( $ origin_dt ) ; return $ offset / 3600 . $ format ; }
Get timezone offset in hours
6,399
public function arrayMultiSearch ( $ needle , $ haystack ) { foreach ( $ haystack as $ key => $ data ) { if ( in_array ( $ needle , $ data ) ) { return $ key ; } } return false ; }
Find key by sub value