idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
18,600 | private function createColumnDef ( $ dbtype , $ nullDefault = false ) { $ column = Db :: typeDef ( $ dbtype ) ; if ( $ column === null ) { throw new \ InvalidArgumentException ( "Unknown type '$dbtype'." , 500 ) ; } if ( $ column [ 'dbtype' ] === 'bool' && in_array ( $ nullDefault , [ true , false ] , true ) ) { $ column [ 'allowNull' ] = false ; $ column [ 'default' ] = $ nullDefault ; } elseif ( $ column [ 'dbtype' ] === 'timestamp' && empty ( $ column [ 'default' ] ) ) { $ column [ 'default' ] = 'current_timestamp' ; } elseif ( $ nullDefault === null || $ nullDefault === true ) { $ column [ 'allowNull' ] = true ; } elseif ( $ nullDefault === false ) { $ column [ 'allowNull' ] = false ; } else { $ column [ 'allowNull' ] = false ; $ column [ 'default' ] = $ nullDefault ; } return $ column ; } | Get an array column def from a structured function call . |
18,601 | public function setPrimaryKey ( $ name , $ type = 'int' ) { $ column = $ this -> createColumnDef ( $ type , false ) ; $ column [ 'autoIncrement' ] = true ; $ column [ 'primary' ] = true ; $ this -> columns [ $ name ] = $ column ; $ this -> addIndex ( Db :: INDEX_PK , $ name ) ; return $ this ; } | Define the primary key in the database . |
18,602 | public function addIndex ( $ type , ... $ columns ) { if ( empty ( $ columns ) ) { throw new \ InvalidArgumentException ( "An index must contain at least one column." , 500 ) ; } $ type = strtolower ( $ type ) ; $ currentIndex = null ; foreach ( $ this -> indexes as $ i => $ index ) { if ( $ type !== $ index [ 'type' ] ) { continue ; } if ( $ type === Db :: INDEX_PK || array_diff ( $ index [ 'columns' ] , $ columns ) == [ ] ) { $ currentIndex = & $ this -> indexes [ $ i ] ; break ; } } if ( $ currentIndex ) { $ currentIndex [ 'columns' ] = $ columns ; } else { $ indexDef = [ 'type' => $ type , 'columns' => $ columns , ] ; $ this -> indexes [ ] = $ indexDef ; } return $ this ; } | Add or update an index . |
18,603 | protected function promoteSingleStrings ( array $ string ) { $ newString = [ ] ; foreach ( $ string as $ element ) { if ( is_array ( $ element ) && count ( $ element ) === 1 ) { $ newString = array_merge ( $ newString , $ element [ 0 ] ) ; } else { $ newString [ ] = $ element ; } } return $ newString ; } | Promote single strings found inside given string |
18,604 | protected function indexCheckboxFilters ( ) : array { $ oGroupModel = Factory :: model ( 'UserGroup' , 'nails/module-auth' ) ; $ aGroups = $ oGroupModel -> getAll ( ) ; return array_merge ( parent :: indexCheckboxFilters ( ) , [ Factory :: factory ( 'IndexFilter' , 'nails/module-admin' ) -> setLabel ( 'Group' ) -> setColumn ( 'group_id' ) -> addOptions ( array_map ( function ( $ oGroup ) { return Factory :: factory ( 'IndexFilterOption' , 'nails/module-admin' ) -> setLabel ( $ oGroup -> label ) -> setValue ( $ oGroup -> id ) -> setIsSelected ( true ) ; } , $ aGroups ) ) , Factory :: factory ( 'IndexFilter' , 'nails/module-admin' ) -> setLabel ( 'Suspended' ) -> setColumn ( 'is_suspended' ) -> addOptions ( [ Factory :: factory ( 'IndexFilterOption' , 'nails/module-admin' ) -> setLabel ( 'Yes' ) -> setValue ( true ) , Factory :: factory ( 'IndexFilterOption' , 'nails/module-admin' ) -> setLabel ( 'No' ) -> setValue ( false ) -> setIsSelected ( true ) , ] ) , ] ) ; } | Returns the available checkbox filters |
18,605 | public function suspend ( ) : void { if ( ! userHasPermission ( 'admin:auth:accounts:suspend' ) ) { unauthorised ( ) ; } $ oUri = Factory :: service ( 'Uri' ) ; $ oInput = Factory :: service ( 'Input' ) ; $ oSession = Factory :: service ( 'Session' , 'nails/module-auth' ) ; $ oUserModel = Factory :: model ( 'User' , 'nails/module-auth' ) ; $ iUserId = $ oUri -> segment ( 5 ) ; $ oUser = $ oUserModel -> getById ( $ iUserId ) ; $ bOldValue = $ oUser -> is_suspended ; if ( ! isSuperuser ( ) && userHasPermission ( 'superuser' , $ oUser ) ) { $ oSession -> setFlashData ( 'error' , lang ( 'accounts_edit_error_noteditable' ) ) ; $ this -> returnToIndex ( ) ; } $ oUserModel -> suspend ( $ iUserId ) ; $ oUser = $ oUserModel -> getById ( $ iUserId ) ; $ bNewValue = $ oUser -> is_suspended ; if ( ! $ oUser -> is_suspended ) { $ oSession -> setFlashData ( 'error' , lang ( 'accounts_suspend_error' , title_case ( $ oUser -> first_name . ' ' . $ oUser -> last_name ) ) ) ; } else { $ oSession -> setFlashData ( 'success' , lang ( 'accounts_suspend_success' , title_case ( $ oUser -> first_name . ' ' . $ oUser -> last_name ) ) ) ; } $ this -> oChangeLogModel -> add ( 'suspended' , 'a' , 'user' , $ iUserId , '#' . number_format ( $ iUserId ) . ' ' . $ oUser -> first_name . ' ' . $ oUser -> last_name , 'admin/auth/accounts/edit/' . $ iUserId , 'is_suspended' , $ bOldValue , $ bNewValue , false ) ; $ this -> returnToIndex ( ) ; } | Suspend a user |
18,606 | public function delete_profile_img ( ) : void { $ oUri = Factory :: service ( 'Uri' ) ; if ( $ oUri -> segment ( 5 ) != activeUser ( 'id' ) && ! userHasPermission ( 'admin:auth:accounts:editOthers' ) ) { unauthorised ( ) ; } $ oInput = Factory :: service ( 'Input' ) ; $ oSession = Factory :: service ( 'Session' , 'nails/module-auth' ) ; $ oUserModel = Factory :: model ( 'User' , 'nails/module-auth' ) ; $ iUserId = $ oUri -> segment ( 5 ) ; $ oUser = $ oUserModel -> getById ( $ iUserId ) ; $ sReturnTo = $ oInput -> get ( 'return_to' ) ? $ oInput -> get ( 'return_to' ) : 'admin/auth/accounts/edit/' . $ iUserId ; if ( ! $ oUser ) { $ oSession -> setFlashData ( 'error' , lang ( 'accounts_delete_img_error_noid' ) ) ; redirect ( 'admin/auth/accounts' ) ; } else { if ( ! isSuperuser ( ) && userHasPermission ( 'superuser' , $ oUser ) ) { $ oSession -> setFlashData ( 'error' , lang ( 'accounts_edit_error_noteditable' ) ) ; redirect ( $ sReturnTo ) ; } if ( $ oUser -> profile_img ) { $ oCdn = Factory :: service ( 'Cdn' , 'nails/module-cdn' ) ; if ( $ oCdn -> objectDelete ( $ oUser -> profile_img , 'profile-images' ) ) { $ oUserModel -> update ( $ iUserId , [ 'profile_img' => null ] ) ; $ sStatus = 'notice' ; $ sMessage = lang ( 'accounts_delete_img_success' ) ; } else { $ sStatus = 'error' ; $ sMessage = lang ( 'accounts_delete_img_error' , implode ( '", "' , $ oCdn -> getErrors ( ) ) ) ; } } else { $ sStatus = 'notice' ; $ sMessage = lang ( 'accounts_delete_img_error_noimg' ) ; } $ oSession -> setFlashData ( $ sStatus , $ sMessage ) ; redirect ( $ sReturnTo ) ; } } | Delete a user s profile image |
18,607 | public function execute ( Arguments $ args , ConsoleIo $ io ) { $ this -> loadModel ( 'MeCms.UsersGroups' ) ; $ groups = $ this -> UsersGroups -> find ( ) -> map ( function ( UsersGroup $ group ) { return $ group -> extract ( [ 'id' , 'name' , 'label' , 'user_count' ] ) ; } ) ; if ( $ groups -> isEmpty ( ) ) { $ io -> error ( __d ( 'me_cms' , 'There are no user groups' ) ) ; return null ; } $ header = [ I18N_ID , I18N_NAME , I18N_LABEL , I18N_USERS ] ; $ io -> helper ( 'table' ) -> output ( array_merge ( [ $ header ] , $ groups -> toList ( ) ) ) ; return null ; } | Lists user groups |
18,608 | protected function checkLastSearch ( $ id = false ) { $ interval = getConfig ( 'security.search_interval' ) ; if ( ! $ interval ) { return true ; } $ id = $ id ? md5 ( $ id ) : false ; $ lastSearch = $ this -> request -> getSession ( ) -> read ( 'last_search' ) ; if ( $ lastSearch ) { if ( $ id && ! empty ( $ lastSearch [ 'id' ] ) && $ id === $ lastSearch [ 'id' ] ) { return true ; } elseif ( ( $ lastSearch [ 'time' ] + $ interval ) > time ( ) ) { return false ; } } $ this -> request -> getSession ( ) -> write ( 'last_search' , compact ( 'id' ) + [ 'time' => time ( ) ] ) ; return true ; } | Checks if the latest search has been executed out of the minimum interval |
18,609 | public function load ( ObjectManager $ manager ) { $ userRole = new Role ( ) ; $ userRole -> setRoleId ( 'user' ) ; $ manager -> persist ( $ userRole ) ; $ manager -> flush ( ) ; $ adminRole = new Role ( ) ; $ adminRole -> setRoleId ( 'admin' ) ; $ adminRole -> setParent ( $ userRole ) ; $ manager -> persist ( $ adminRole ) ; $ manager -> flush ( ) ; $ supervisorRole = new Role ( ) ; $ supervisorRole -> setRoleId ( 'supervisor' ) ; $ supervisorRole -> setParent ( $ userRole ) ; $ manager -> persist ( $ supervisorRole ) ; $ manager -> flush ( ) ; $ gameManagerRole = new Role ( ) ; $ gameManagerRole -> setRoleId ( 'game-manager' ) ; $ gameManagerRole -> setParent ( $ supervisorRole ) ; $ manager -> persist ( $ gameManagerRole ) ; $ manager -> flush ( ) ; $ this -> addReference ( 'admin-role' , $ adminRole ) ; $ this -> addReference ( 'supervisor-role' , $ supervisorRole ) ; $ this -> addReference ( 'game-role' , $ gameManagerRole ) ; } | Load Role types |
18,610 | public function submitMessage ( ) { $ messageMapper = ( $ this -> container -> dataMapper ) ( 'MessageMapper' ) ; $ email = $ this -> container -> emailHandler ; if ( 'alt@example.com' === $ this -> request -> getParsedBodyParam ( 'alt-email' ) ) { $ message = $ messageMapper -> make ( ) ; $ message -> name = $ this -> request -> getParsedBodyParam ( 'name' ) ; $ message -> email = $ this -> request -> getParsedBodyParam ( 'email' ) ; $ message -> message = $ this -> request -> getParsedBodyParam ( 'message' ) ; $ messageMapper -> save ( $ message ) ; $ siteName = empty ( $ this -> siteSettings [ 'displayName' ] ) ? 'PitonCMS' : $ this -> siteSettings [ 'displayName' ] ; $ email -> setTo ( $ this -> siteSettings [ 'contactFormEmail' ] , '' ) -> setSubject ( "New Contact Message to $siteName" ) -> setMessage ( "From: {$message->email}\n\n{$message->message}" ) -> send ( ) ; } $ r = $ this -> response -> withHeader ( 'Content-Type' , 'application/json' ) ; return $ r -> write ( json_encode ( [ "response" => $ this -> siteSettings [ 'contactFormAcknowledgement' ] ] ) ) ; } | Submit Contact Message |
18,611 | public function add ( $ char , $ expr ) { $ split = $ this -> input -> split ( $ char ) ; if ( count ( $ split ) !== 1 ) { throw new InvalidArgumentException ( 'Meta-characters must be represented by exactly one character' ) ; } if ( @ preg_match ( '(' . $ expr . ')u' , '' ) === false ) { throw new InvalidArgumentException ( "Invalid expression '" . $ expr . "'" ) ; } $ inputValue = $ split [ 0 ] ; $ metaValue = $ this -> computeValue ( $ expr ) ; $ this -> exprs [ $ metaValue ] = $ expr ; $ this -> meta [ $ inputValue ] = $ metaValue ; } | Add a meta - character to the list |
18,612 | public function getExpression ( $ metaValue ) { if ( ! isset ( $ this -> exprs [ $ metaValue ] ) ) { throw new InvalidArgumentException ( 'Invalid meta value ' . $ metaValue ) ; } return $ this -> exprs [ $ metaValue ] ; } | Get the expression associated with a meta value |
18,613 | public function replaceMeta ( array $ strings ) { foreach ( $ strings as & $ string ) { foreach ( $ string as & $ value ) { if ( isset ( $ this -> meta [ $ value ] ) ) { $ value = $ this -> meta [ $ value ] ; } } } return $ strings ; } | Replace values from meta - characters in a list of strings with their meta value |
18,614 | protected function computeValue ( $ expr ) { $ properties = [ 'exprIsChar' => self :: IS_CHAR , 'exprIsQuantifiable' => self :: IS_QUANTIFIABLE ] ; $ value = ( 1 + count ( $ this -> meta ) ) * - pow ( 2 , count ( $ properties ) ) ; foreach ( $ properties as $ methodName => $ bitValue ) { if ( $ this -> $ methodName ( $ expr ) ) { $ value |= $ bitValue ; } } return $ value ; } | Compute and return a value for given expression |
18,615 | protected function exprIsQuantifiable ( $ expr ) { $ regexps = [ '(^(?:\\.|\\\\R)$)D' , '(^\\[\\^?(?:([^\\\\\\]]|\\\\.)(?:-(?-1))?)++\\]$)D' ] ; return $ this -> matchesAny ( $ expr , $ regexps ) || $ this -> exprIsChar ( $ expr ) ; } | Test whether given expression is quantifiable |
18,616 | protected function matchesAny ( $ expr , array $ regexps ) { foreach ( $ regexps as $ regexp ) { if ( preg_match ( $ regexp , $ expr ) ) { return true ; } } return false ; } | Test whether given expression matches any of the given regexps |
18,617 | public function getCurrentRealmsAffections ( ) : array { $ realmsAffections = [ ] ; foreach ( $ this -> getRealmsAffectionsSum ( ) as $ periodName => $ periodSum ) { $ realmsAffections [ $ periodName ] = new RealmsAffection ( [ $ periodSum , $ periodName ] ) ; } return $ realmsAffections ; } | Daily monthly and lifetime affections of realms |
18,618 | public function getCurrentSpellRadius ( ) : ? SpellRadius { $ radiusWithAddition = $ this -> getRadiusWithAddition ( ) ; if ( ! $ radiusWithAddition ) { return null ; } $ radiusModifiersChange = $ this -> getParameterBonusFromModifiers ( ModifierMutableSpellParameterCode :: SPELL_RADIUS ) ; if ( ! $ radiusModifiersChange ) { return new SpellRadius ( [ $ radiusWithAddition -> getValue ( ) , 0 ] , $ this -> tables ) ; } return new SpellRadius ( [ $ radiusWithAddition -> getValue ( ) + $ radiusModifiersChange , 0 ] , $ this -> tables ) ; } | Final radius including direct formula change and all its active traits and modifiers . |
18,619 | private function getRadiusWithAddition ( ) : ? SpellRadius { $ baseSpellRadius = $ this -> tables -> getFormulasTable ( ) -> getSpellRadius ( $ this -> formulaCode ) ; if ( $ baseSpellRadius === null ) { return null ; } return $ baseSpellRadius -> getWithAddition ( $ this -> formulaSpellParameterChanges [ FormulaMutableSpellParameterCode :: SPELL_RADIUS ] ) ; } | Formula radius extended by direct formula change |
18,620 | public function getCurrentSpellAttack ( ) : ? SpellAttack { $ spellAttackWithAddition = $ this -> getSpellAttackWithAddition ( ) ; if ( ! $ spellAttackWithAddition ) { return null ; } return new SpellAttack ( [ $ spellAttackWithAddition -> getValue ( ) + ( int ) $ this -> getParameterBonusFromModifiers ( ModifierMutableSpellParameterCode :: SPELL_ATTACK ) , 0 ] , Tables :: getIt ( ) ) ; } | Attack can be only increased not added . |
18,621 | public static function getCategory ( $ publish = null , $ array = true ) { $ criteria = new CDbCriteria ; if ( $ publish != null ) $ criteria -> compare ( 't.publish' , $ publish ) ; $ model = self :: model ( ) -> findAll ( $ criteria ) ; if ( $ array == true ) { $ items = array ( ) ; if ( $ model != null ) { foreach ( $ model as $ key => $ val ) { $ items [ $ val -> cat_id ] = $ val -> title -> message ; } return $ items ; } else return false ; } else return $ model ; } | getCategory 0 = unpublish 1 = publish |
18,622 | public function addMissingProperty ( MetaEntityInterface $ metaEntity , RelationMetaPropertyInterface $ property ) { $ inversedBy = $ property -> getInversedBy ( ) ; $ mappedBy = $ property -> getMappedBy ( ) ; if ( $ newPropertyName = $ mappedBy ? : $ inversedBy ) { $ inversedType = MetaPropertyFactory :: getInversedType ( $ property -> getOrmType ( ) ) ; $ newProperty = $ this -> metaPropertyFactory -> createMetaProperty ( $ metaEntity , $ inversedType , $ newPropertyName ) ; $ newProperty -> setTargetEntity ( $ property -> getMetaEntity ( ) ) ; if ( $ inversedBy ) { $ newProperty -> setMappedBy ( $ property -> getName ( ) ) ; } else { $ newProperty -> setInversedBy ( $ property -> getName ( ) ) ; } } } | Adds missing field for inversedBy or mappedBy |
18,623 | public function user ( $ key = null ) { if ( empty ( $ this -> user ) ) { return null ; } return $ key ? Hash :: get ( $ this -> user , $ key ) : $ this -> user ; } | Get the current user from storage |
18,624 | public function isAuthorized ( $ user = null ) { if ( ! $ this -> request -> getParam ( 'prefix' ) ) { return true ; } if ( $ this -> request -> isAdmin ( ) ) { return $ this -> Auth -> isGroup ( [ 'admin' , 'manager' ] ) ; } return false ; } | Checks if the user is authorized for the request |
18,625 | protected function setUploadError ( $ error ) { $ this -> response = $ this -> response -> withStatus ( 500 ) ; $ this -> set ( compact ( 'error' ) ) ; $ this -> set ( '_serialize' , [ 'error' ] ) ; } | Internal method to set an upload error . |
18,626 | public function newElementForm ( ) { $ parsedBody = $ this -> request -> getParsedBody ( ) ; $ form [ 'block_key' ] = $ parsedBody [ 'blockKey' ] ; $ form [ 'definition' ] = $ parsedBody [ 'elementType' ] ; $ form [ 'element_sort' ] = 1 ; if ( ! empty ( $ parsedBody [ 'elementTypeOptions' ] ) ) { $ form [ 'elementTypeOptions' ] = explode ( ',' , $ parsedBody [ 'elementTypeOptions' ] ) ; } $ template = '{% import "@admin/editElementMacro.html" as form %}' ; $ template .= ' {{ form.elementForm(element, element.block_key, element.elementTypeOptions) }}' ; $ elementFormHtml = $ this -> container -> view -> fetchFromString ( $ template , [ 'element' => $ form ] ) ; $ r = $ this -> response -> withHeader ( 'Content-Type' , 'application/json' ) ; return $ r -> write ( json_encode ( [ "html" => $ elementFormHtml ] ) ) ; } | New Element Form |
18,627 | public function revoke ( $ iUserId , $ mToken ) { if ( is_string ( $ mToken ) ) { $ oToken = $ this -> getByToken ( $ mToken ) ; } else { $ oToken = $ mToken ; } if ( $ oToken ) { if ( $ oToken -> user_id === $ iUserId ) { return $ this -> delete ( $ oToken -> id ) ; } else { $ this -> setError ( 'Not authorised to revoke that token.' ) ; return false ; } } else { return false ; } } | Revoke an access token for a user |
18,628 | public function hasScope ( $ mToken , $ sScope ) { if ( is_numeric ( $ mToken ) ) { $ oToken = $ this -> getById ( $ mToken ) ; } else { $ oToken = $ mToken ; } if ( $ oToken ) { return in_array ( $ sScope , $ oToken -> scope ) ; } else { return false ; } } | Determines whether a token has a given scope |
18,629 | public static function setDb ( $ db , $ connection_name = self :: DEFAULT_CONNECTION ) { static :: _initDbConfigWithDefaultVals ( $ connection_name ) ; static :: $ _db [ $ connection_name ] = $ db ; } | Set the PDO object used by DBConnector to communicate with the database . This is public in case the DBConnector should use a ready - instantiated PDO object as its database connection . Accepts an optional string key to identify the connection if multiple connections are used . |
18,630 | public function dbFetchOne ( $ select_query , $ parameters = array ( ) ) { $ bool_and_statement = static :: _execute ( $ select_query , $ parameters , true , $ this -> _connection_name ) ; $ statement = array_pop ( $ bool_and_statement ) ; return $ statement -> fetch ( \ PDO :: FETCH_ASSOC ) ; } | Tell the DBConnector that you are expecting a single result back from your query and execute it . Will return a single instance of the DBConnector class or false if no rows were returned . As a shortcut you may supply an ID as a parameter to this method . This will perform a primary key lookup on the table . |
18,631 | public function setSmtpSecurity ( $ security ) { $ security = strtoupper ( $ security ) ; $ validSecurity = [ '' , 'TLS' , 'SSL' ] ; if ( ! in_array ( $ security , $ validSecurity ) ) { throw new InvalidArgumentException ( 'SMTP Security is not valid. Must be "", "TLS" or "SSL".' ) ; } $ this -> smtpSecurity = $ security ; return $ this ; } | Set the SMTP security type to be used . |
18,632 | public static function validDomains ( $ url , $ domains ) { $ theDomain = parse_url ( $ url ) ; foreach ( $ domains as $ domain ) { $ check = strpos ( $ theDomain [ 'host' ] , $ domain -> client_domain ) ; if ( $ check || $ check === 0 ) { return true ; } } return false ; } | Check that a URL can belong to a list of available domains |
18,633 | public function postalcodeToCoordinates ( array $ postalData , $ shouldRunC2A = false ) { $ this -> shouldRunC2A = ( $ this -> shouldRunC2A ) ? true : $ shouldRunC2A ; $ this -> returnLocationData = array_merge ( $ this -> returnLocationData , array_only ( $ postalData , [ 'street_number' , 'postal_code' ] ) ) ; return $ this ; } | Get the coordinates from a postal code |
18,634 | public function addressToCoordinates ( array $ addressData = [ ] ) { $ this -> returnLocationData = array_merge ( $ this -> returnLocationData , array_only ( $ addressData , [ 'country' , 'region' , 'city' , 'street' , 'street_number' ] ) ) ; return $ this ; } | Get coordinates from an address |
18,635 | public function coordinatesToAddress ( array $ coordinates = [ ] ) { $ this -> shouldRunC2A = true ; $ this -> returnLocationData = array_merge ( $ this -> returnLocationData , array_only ( $ coordinates , [ 'latitude' , 'longitude' ] ) ) ; return $ this ; } | Get the address from coordinates |
18,636 | public function ipToCoordinates ( $ ip = null , $ shouldRunC2A = false ) { $ this -> shouldRunC2A = ( $ this -> shouldRunC2A ) ? true : $ shouldRunC2A ; if ( ! $ ip ) { $ ip = Request :: ip ( ) ; } $ this -> ip = $ ip ; return $ this ; } | Get coordinates from an ip |
18,637 | public function get ( $ toObject = false ) { if ( ! env ( 'GOOGLE_KEY' ) ) { throw new Exception ( "Need an env key for geo request" , 401 ) ; } $ this -> response = null ; $ this -> error = null ; if ( $ this -> c2a ( ) ) { $ response = $ this -> template ( $ toObject ) ; } elseif ( $ this -> a2c ( ) ) { $ response = $ this -> template ( $ toObject ) ; } elseif ( $ this -> i2c ( ) ) { $ response = $ this -> template ( $ toObject ) ; } elseif ( $ this -> p2c ( ) ) { $ response = $ this -> template ( $ toObject ) ; } if ( $ response ) { $ this -> reset ( ) ; return $ response ; } throw new Exception ( trans ( 'location::errors.not_enough_data' ) ) ; } | Return the results |
18,638 | private function template ( $ toObject ) { if ( $ toObject ) { $ response = new StdClass ; foreach ( $ this -> returnLocationData as $ key => $ value ) { $ response -> { $ key } = $ value ; } return $ response ; } return $ this -> returnLocationData ; } | Return the template as array or object |
18,639 | private function p2c ( ) { if ( $ this -> returnLocationData [ 'postal_code' ] && ! $ this -> returnLocationData [ 'latitude' ] ) { $ this -> method = 'GET' ; $ this -> updateResponseWithResults ( $ this -> gateway ( $ this -> createAddressUrl ( ) ) ) ; if ( $ this -> shouldRunC2A ) { $ this -> c2a ( ) ; } return true ; } } | postal code to coordinate |
18,640 | private function i2c ( ) { if ( $ this -> ip && ! $ this -> returnLocationData [ 'latitude' ] ) { $ this -> method = 'POST' ; $ this -> updateResponseWithResults ( $ this -> gateway ( $ this -> createGeoUrl ( ) ) ) ; if ( $ this -> shouldRunC2A ) { $ this -> c2a ( ) ; } return true ; } } | ip to coordinates |
18,641 | private function createAddressUrl ( ) { $ urlVariables = [ 'language' => $ this -> locale , ] ; if ( count ( $ this -> isos ) ) { $ urlVariables [ 'components' ] = 'country:' . implode ( ',' , $ this -> isos ) ; } if ( $ this -> returnLocationData [ 'latitude' ] && $ this -> returnLocationData [ 'longitude' ] ) { $ urlVariables [ 'latlng' ] = $ this -> returnLocationData [ 'latitude' ] . ',' . $ this -> returnLocationData [ 'longitude' ] ; return $ this -> buildUrl ( $ urlVariables ) ; } if ( $ this -> returnLocationData [ 'city' ] && $ this -> returnLocationData [ 'country' ] ) { $ urlVariables [ 'address' ] = $ this -> returnLocationData [ 'city' ] . ', ' . $ this -> returnLocationData [ 'country' ] ; return $ this -> buildUrl ( $ urlVariables ) ; } if ( $ this -> returnLocationData [ 'postal_code' ] ) { $ urlVariables [ 'address' ] = $ this -> returnLocationData [ 'postal_code' ] . ( ( $ this -> returnLocationData [ 'street_number' ] ) ? ' ' . $ this -> returnLocationData [ 'street_number' ] : '' ) ; return $ this -> buildUrl ( $ urlVariables ) ; } } | create the url to connect to for maps api |
18,642 | private function buildUrl ( $ urlVariables ) { $ url = '' ; foreach ( $ urlVariables as $ variable => $ value ) { $ url .= '&' . $ variable . '=' . ( $ value ) ; } return config ( 'location.google-maps-url' ) . env ( 'GOOGLE_KEY' ) . $ url ; } | Build the request url |
18,643 | private function updateResponseWithResults ( $ json ) { $ response = $ this -> jsonToArray ( $ json ) ; if ( isset ( $ response [ 'results' ] [ 0 ] ) ) { $ this -> response = $ response [ 'results' ] [ 0 ] ; if ( @ $ response [ 'results' ] [ 0 ] [ 'partial_match' ] && $ this -> excludePartials ) { throw new Exception ( trans ( 'location::errors.no_results' ) ) ; } if ( ! $ this -> returnLocationData [ 'country' ] ) { $ this -> returnLocationData [ 'country' ] = $ this -> findInGoogleSet ( $ response , [ 'country' ] ) ; $ this -> returnLocationData [ 'iso' ] = $ this -> findInGoogleSet ( $ response , [ 'country' ] , 'short_name' ) ; } if ( ! $ this -> returnLocationData [ 'region' ] ) { $ this -> returnLocationData [ 'region' ] = $ this -> findInGoogleSet ( $ response , [ 'administrative_area_level_1' ] ) ; } if ( ! $ this -> returnLocationData [ 'city' ] ) { $ this -> returnLocationData [ 'city' ] = $ this -> findInGoogleSet ( $ response , [ 'administrative_area_level_2' ] ) ; } if ( ! $ this -> returnLocationData [ 'street' ] ) { $ this -> returnLocationData [ 'street' ] = $ this -> findInGoogleSet ( $ response , [ 'route' ] ) ; } if ( ! $ this -> returnLocationData [ 'street_number' ] ) { $ this -> returnLocationData [ 'street_number' ] = $ this -> findInGoogleSet ( $ response , [ 'street_number' ] ) ; } if ( ! $ this -> returnLocationData [ 'postal_code' ] ) { $ this -> returnLocationData [ 'postal_code' ] = $ this -> findInGoogleSet ( $ response , [ 'postal_code' ] ) ; } if ( ! $ this -> returnLocationData [ 'latitude' ] ) { $ this -> returnLocationData [ 'latitude' ] = $ response [ 'results' ] [ 0 ] [ 'geometry' ] [ 'location' ] [ 'lat' ] ; } if ( ! $ this -> returnLocationData [ 'longitude' ] ) { $ this -> returnLocationData [ 'longitude' ] = $ response [ 'results' ] [ 0 ] [ 'geometry' ] [ 'location' ] [ 'lng' ] ; } } elseif ( @ $ response [ 'location' ] ) { $ this -> returnLocationData [ 'latitude' ] = $ response [ 'location' ] [ 'lat' ] ; $ this -> returnLocationData [ 'longitude' ] = $ response [ 'location' ] [ 'lng' ] ; } else { throw new Exception ( trans ( 'location::errors.no_results' ) ) ; } } | fill the response with usefull data as far as we can find |
18,644 | private function findInGoogleSet ( $ response , array $ find = [ ] , $ type = 'long_name' ) { try { foreach ( $ response [ 'results' ] [ 0 ] [ 'address_components' ] as $ data ) { foreach ( $ data [ 'types' ] as $ key ) { if ( in_array ( $ key , $ find ) ) { return $ data [ $ type ] ; } } } return '' ; } catch ( Exception $ e ) { $ this -> error = $ e ; return '' ; } } | Find a value in a response from google |
18,645 | private function jsonToArray ( $ json ) { try { $ data = json_decode ( $ json , true ) ; if ( is_array ( $ data ) ) { return $ data ; } else { $ this -> error = 'The given data string was not json' ; return [ ] ; } } catch ( Exception $ e ) { $ this -> error = $ e ; } } | Convert json string to an array if the syntax is right |
18,646 | private function reset ( ) { $ this -> returnLocationData = $ this -> locationDataTemplate ; $ this -> locale = ( config ( 'location.language' ) ) ? config ( 'location.language' ) : App :: getLocale ( ) ; $ this -> ip = null ; $ this -> client = null ; } | Reset the class |
18,647 | protected function convert ( array $ value ) { $ return = array ( ) ; foreach ( $ value as $ name => $ elements ) { if ( is_array ( $ elements ) ) { if ( isset ( $ elements [ '__all__' ] ) ) { if ( '0' == $ elements [ '__all__' ] ) { $ return [ ] = $ name ; continue ; } else { unset ( $ elements [ '__all__' ] ) ; } } $ result = $ this -> convert ( $ elements ) ; if ( count ( $ result ) ) { $ return [ $ name ] = $ result ; } continue ; } if ( '0' == $ elements ) { $ return [ ] = $ name ; } } return $ return ; } | Converts an element value array to config array recursively . |
18,648 | public function buildRules ( RulesChecker $ rules ) { return $ rules -> add ( $ rules -> existsIn ( [ 'category_id' ] , 'Categories' , I18N_SELECT_VALID_OPTION ) ) -> add ( $ rules -> existsIn ( [ 'user_id' ] , 'Users' , I18N_SELECT_VALID_OPTION ) ) -> add ( $ rules -> isUnique ( [ 'slug' ] , I18N_VALUE_ALREADY_USED ) ) -> add ( $ rules -> isUnique ( [ 'title' ] , I18N_VALUE_ALREADY_USED ) ) ; } | Returns a rules checker object that will be used for validating application integrity |
18,649 | public function getRelated ( Post $ post , $ limit = 5 , $ images = true ) { key_exists_or_fail ( [ 'id' , 'tags' ] , $ post -> toArray ( ) , __d ( 'me_cms' , 'ID or tags of the post are missing' ) ) ; $ cache = sprintf ( 'related_%s_posts_for_%s' , $ limit , $ post -> id ) ; if ( $ images ) { $ cache .= '_with_images' ; } return Cache :: remember ( $ cache , function ( ) use ( $ images , $ limit , $ post ) { $ related = [ ] ; if ( $ post -> has ( 'tags' ) ) { $ tags = collection ( $ post -> tags ) -> sortBy ( 'post_count' ) -> take ( $ limit ) -> toList ( ) ; $ exclude [ ] = $ post -> id ; foreach ( array_reverse ( $ tags ) as $ tag ) { $ post = $ this -> queryForRelated ( $ tag -> id , $ images ) -> where ( [ sprintf ( '%s.id NOT IN' , $ this -> getAlias ( ) ) => $ exclude ] ) -> first ( ) ; if ( $ post ) { $ related [ ] = $ post ; $ exclude [ ] = $ post -> id ; } } } return $ related ; } , $ this -> getCacheName ( ) ) ; } | Gets the related posts for a post |
18,650 | public function queryForRelated ( $ tagId , $ images = true ) { $ query = $ this -> find ( 'active' ) -> select ( [ 'id' , 'title' , 'preview' , 'slug' , 'text' ] ) -> matching ( 'Tags' , function ( Query $ q ) use ( $ tagId ) { return $ q -> where ( [ sprintf ( '%s.id' , $ this -> Tags -> getAlias ( ) ) => $ tagId ] ) ; } ) ; if ( $ images ) { $ query -> where ( [ sprintf ( '%s.preview NOT IN' , $ this -> getAlias ( ) ) => [ null , [ ] ] ] ) ; } return $ query ; } | Gets the query for related posts from a tag ID |
18,651 | public static function getPublicPhrase ( $ select = null ) { $ criteria = new CDbCriteria ; $ criteria -> condition = 'phrase_id > :first AND phrase_id < :last' ; $ criteria -> params = array ( ':first' => 1000 , ':last' => 1500 , ) ; if ( $ select != null ) $ criteria -> select = $ select ; $ model = self :: model ( ) -> findAll ( $ criteria ) ; return $ model ; } | get public phrase |
18,652 | protected function pruneRelationships ( ) { $ cli = $ this -> climate ( ) ; $ ask = $ this -> interactive ( ) ; $ dry = $ this -> dryRun ( ) ; $ verb = $ this -> verbose ( ) ; $ mucho = ( $ dry || $ verb ) ; $ attach = $ this -> modelFactory ( ) -> get ( Attachment :: class ) ; $ pivot = $ this -> modelFactory ( ) -> get ( Join :: class ) ; $ source = $ attach -> source ( ) ; $ db = $ source -> db ( ) ; $ defaultBinds = [ '%pivotTable' => $ pivot -> source ( ) -> table ( ) , '%sourceType' => 'object_type' , '%sourceId' => 'object_id' , ] ; $ sql = 'SELECT DISTINCT `%sourceType` FROM `%pivotTable`;' ; $ rows = $ db -> query ( strtr ( $ sql , $ binds ) , PDO :: FETCH_ASSOC ) ; if ( $ rows -> rowCount ( ) ) { error_log ( get_called_class ( ) . '::' . __FUNCTION__ ) ; foreach ( $ rows as $ row ) { try { $ model = $ this -> modelFactory ( ) -> get ( $ row [ 'object_type' ] ) ; } catch ( Exception $ e ) { unset ( $ e ) ; $ model = $ row [ 'object_type' ] ; } if ( $ model instanceof ModelInterface ) { $ sql = 'SELECT p.* FROM `%pivotTable` AS p WHERE p.`%sourceType` = :objType AND p.`%sourceId` NOT IN ( SELECT o.`%objectKey` FROM `%objectTable` AS o );' ; $ binds = array_merge ( $ defaultBinds , [ '%objectTable' => $ model -> source ( ) -> table ( ) , '%objectKey' => $ model -> key ( ) , ] ) ; $ rows = $ source -> dbQuery ( strtr ( $ sql , $ binds ) , [ 'objType' => $ row [ 'object_type' ] ] ) ; } elseif ( is_string ( $ model ) ) { $ sql = 'SELECT p.* FROM `%pivotTable` AS p WHERE p.`%sourceType` = :objType;' ; $ rows = $ source -> dbQuery ( strtr ( $ sql , $ defaultBinds ) , [ 'objType' => $ model ] ) ; } } $ this -> conclude ( ) ; } return $ this ; } | Prune relationships of dead objects . |
18,653 | protected function conclude ( ) { $ cli = $ this -> climate ( ) ; if ( count ( $ this -> messages ) ) { $ cli -> out ( implode ( ' ' , $ this -> messages ) ) ; $ this -> messages = [ ] ; } else { $ cli -> info ( 'Done!' ) ; } return $ this ; } | Display stored messages or a generic conclusion . |
18,654 | protected function describeCount ( $ count , $ plural , $ singular , $ zero ) { if ( ! is_int ( $ count ) ) { throw new InvalidArgumentException ( sprintf ( 'Must be an integer' , is_object ( $ count ) ? get_class ( $ count ) : gettype ( $ count ) ) ) ; } $ cli = $ this -> climate ( ) ; if ( $ count === 0 ) { $ cli -> info ( sprintf ( $ zero , $ count ) ) ; return false ; } elseif ( $ count === 1 ) { $ cli -> comment ( sprintf ( $ singular , $ count ) ) ; } else { $ cli -> comment ( sprintf ( $ plural , $ count ) ) ; } $ cli -> br ( ) ; return true ; } | Describe the given object count . |
18,655 | public function attachmentsAsRows ( ) { $ rows = [ ] ; if ( $ this -> hasAttachments ( ) ) { $ rows = array_chunk ( $ this -> attachments ( ) -> values ( ) , $ this -> numColumns ) ; array_walk ( $ rows , function ( & $ value , $ key ) { $ value = [ 'columns' => $ value , 'isFirst' => $ key === 0 ] ; } ) ; } return $ rows ; } | Retrieve the container s attachments as rows containing columns . |
18,656 | protected static function getAllPaths ( ) { $ paths = Cache :: read ( 'paths' , 'static_pages' ) ; if ( empty ( $ paths ) ) { $ paths = collection ( Plugin :: all ( ) ) -> map ( function ( $ plugin ) { return self :: getPluginPath ( $ plugin ) ; } ) -> filter ( function ( $ path ) { return file_exists ( $ path ) ; } ) -> toList ( ) ; array_unshift ( $ paths , self :: getAppPath ( ) ) ; Cache :: write ( 'paths' , $ paths , 'static_pages' ) ; } return $ paths ; } | Internal method to get all paths for static pages |
18,657 | protected static function getSlug ( $ path , $ relativePath ) { if ( string_starts_with ( $ path , $ relativePath ) ) { $ path = substr ( $ path , strlen ( Folder :: slashTerm ( $ relativePath ) ) ) ; } $ path = preg_replace ( sprintf ( '/\.[^\.]+$/' ) , null , $ path ) ; return DS == '/' ? $ path : str_replace ( DS , '/' , $ path ) ; } | Internal method to get the slug . |
18,658 | public static function all ( ) { foreach ( self :: getAllPaths ( ) as $ path ) { $ files = ( new Folder ( $ path ) ) -> findRecursive ( '^.+\.ctp$' , true ) ; foreach ( $ files as $ file ) { $ pages [ ] = new Entity ( [ 'filename' => pathinfo ( $ file , PATHINFO_FILENAME ) , 'path' => rtr ( $ file ) , 'slug' => self :: getSlug ( $ file , $ path ) , 'title' => self :: title ( pathinfo ( $ file , PATHINFO_FILENAME ) ) , 'modified' => new FrozenTime ( filemtime ( $ file ) ) , ] ) ; } } return $ pages ; } | Gets all static pages |
18,659 | public static function get ( $ slug ) { $ locale = I18n :: getLocale ( ) ; $ slug = array_filter ( explode ( '/' , $ slug ) ) ; $ cache = sprintf ( 'page_%s_locale_%s' , md5 ( serialize ( $ slug ) ) , $ locale ) ; $ page = Cache :: read ( $ cache , 'static_pages' ) ; if ( empty ( $ page ) ) { $ filename = implode ( DS , $ slug ) ; $ patterns = [ $ filename . '-' . $ locale ] ; if ( preg_match ( '/^(\w+)_\w+$/' , $ locale , $ matches ) ) { $ patterns [ ] = $ filename . '-' . $ matches [ 1 ] ; } $ patterns [ ] = $ filename ; foreach ( $ patterns as $ pattern ) { $ filename = self :: getAppPath ( ) . $ pattern . '.ctp' ; if ( is_readable ( $ filename ) ) { $ page = DS . 'StaticPages' . DS . $ pattern ; break ; } } foreach ( Plugin :: all ( ) as $ plugin ) { foreach ( $ patterns as $ pattern ) { $ filename = self :: getPluginPath ( $ plugin ) . $ pattern . '.ctp' ; if ( is_readable ( $ filename ) ) { $ page = $ plugin . '.' . DS . 'StaticPages' . DS . $ pattern ; break ; } } } Cache :: write ( $ cache , $ page , 'static_pages' ) ; } return $ page ; } | Gets a static page |
18,660 | public static function title ( $ slugOrPath ) { $ slugOrPath = pathinfo ( $ slugOrPath , PATHINFO_FILENAME ) ; $ slugOrPath = str_replace ( '-' , '_' , $ slugOrPath ) ; return Inflector :: humanize ( $ slugOrPath ) ; } | Gets the title for a static page from its slug or path |
18,661 | public static function applyCurrentTheme ( $ module = null ) { $ theme = Yii :: app ( ) -> theme -> name ; Yii :: app ( ) -> theme = $ theme ; if ( $ module !== null ) { $ themePath = Yii :: getPathOfAlias ( 'webroot.themes.' . $ theme . '.views.layouts' ) ; $ module -> setLayoutPath ( $ themePath ) ; } } | Refer layout path to current applied theme . |
18,662 | public static function getActiveDefaultColumns ( $ columns ) { $ column = array ( ) ; foreach ( $ columns as $ val ) { $ keyIndex = self :: getKeyIndex ( $ val ) ; if ( $ keyIndex ) $ column [ ] = $ keyIndex ; } return $ column ; } | Generates key index defaultColumns in models |
18,663 | public static function getUrlTitle ( $ str , $ separator = '-' , $ lowercase = true ) { if ( $ separator === 'dash' ) { $ separator = '-' ; } elseif ( $ separator === 'underscore' ) { $ separator = '_' ; } $ qSeparator = preg_quote ( $ separator , '#' ) ; $ trans = array ( '&.+?:;' => '' , '[^a-z0-9 _-]' => '' , '\s+' => $ separator , '(' . $ qSeparator . ')+' => $ separator ) ; $ str = strip_tags ( $ str ) ; foreach ( $ trans as $ key => $ val ) { $ str = preg_replace ( '#' . $ key . '#i' , $ val , $ str ) ; } if ( $ lowercase === true ) { $ str = strtolower ( $ str ) ; } return trim ( trim ( $ str , $ separator ) ) ; } | Create URL Title |
18,664 | public static function deleteFolder ( $ path ) { if ( file_exists ( $ path ) ) { $ fh = dir ( $ path ) ; while ( false !== ( $ files = $ fh -> read ( ) ) ) { @ unlink ( $ fh -> path . '/' . $ files ) ; } $ fh -> close ( ) ; @ rmdir ( $ path ) ; return true ; } else return false ; } | remove folder and file |
18,665 | public static function recursiveDelete ( $ path ) { if ( is_file ( $ path ) ) { @ unlink ( $ path ) ; } else { $ it = new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ path ) , RecursiveIteratorIterator :: CHILD_FIRST ) ; foreach ( $ it as $ file ) { if ( in_array ( $ file -> getBasename ( ) , array ( '.' , '..' ) ) ) { continue ; } elseif ( $ file -> isDir ( ) ) { rmdir ( $ file -> getPathname ( ) ) ; } elseif ( $ file -> isFile ( ) || $ file -> isLink ( ) ) { unlink ( $ file -> getPathname ( ) ) ; } } rmdir ( $ path ) ; } return false ; } | Delete files and folder recursively |
18,666 | public static function getConnected ( $ serverOptions ) { if ( Yii :: app ( ) -> params [ 'server_options' ] [ 'default' ] == true ) $ connectedUrl = Yii :: app ( ) -> params [ 'server_options' ] [ 'default_host' ] ; else { $ connectedUrl = 'neither-connected' ; foreach ( $ serverOptions as $ val ) { if ( self :: isServerAvailible ( $ val ) ) { $ connectedUrl = $ val ; break ; } } file_put_contents ( 'assets/utility_server_actived.txt' , $ connectedUrl ) ; } return $ connectedUrl ; } | get alternatif connected domain for inlis sso server |
18,667 | public static function isServerAvailible ( $ domain ) { if ( Yii :: app ( ) -> params [ 'server_options' ] [ 'status' ] == true ) { if ( ! filter_var ( $ domain , FILTER_VALIDATE_URL ) ) return false ; $ curlInit = curl_init ( $ domain ) ; curl_setopt ( $ curlInit , CURLOPT_CONNECTTIMEOUT , 10 ) ; curl_setopt ( $ curlInit , CURLOPT_HEADER , true ) ; curl_setopt ( $ curlInit , CURLOPT_NOBODY , true ) ; curl_setopt ( $ curlInit , CURLOPT_RETURNTRANSFER , true ) ; $ response = curl_exec ( $ curlInit ) ; curl_close ( $ curlInit ) ; if ( $ response ) return true ; return false ; } else return false ; } | returns true if domain is availible false if not |
18,668 | public static function getLocalDayName ( $ date , $ short = true ) { $ dayName = date ( 'N' , strtotime ( $ date ) ) ; switch ( $ dayName ) { case 0 : return ( $ short ? 'Min' : 'Minggu' ) ; break ; case 1 : return ( $ short ? 'Sen' : 'Senin' ) ; break ; case 2 : return ( $ short ? 'Sel' : 'Selasa' ) ; break ; case 3 : return ( $ short ? 'Rab' : 'Rabu' ) ; break ; case 4 : return ( $ short ? 'Kam' : 'Kamis' ) ; break ; case 5 : return ( $ short ? 'Jum' : 'Jumat' ) ; break ; case 6 : return ( $ short ? 'Sab' : 'Sabtu' ) ; break ; } } | Mengembalikan nama hari dalam bahasa indonesia . |
18,669 | public static function hardDecode ( $ string ) { $ data = htmlspecialchars_decode ( $ string ) ; $ data = html_entity_decode ( $ data ) ; $ data = strip_tags ( $ data ) ; $ data = chop ( Utility :: convert_smart_quotes ( $ data ) ) ; $ data = str_replace ( array ( "\r" , "\n" , " " ) , "" , $ data ) ; return ( $ data ) ; } | Super Cleaning for decode and strip all html tag |
18,670 | public static function cleanImageContent ( $ content ) { $ posImg = strpos ( $ content , '<img' ) ; $ result = $ content ; if ( $ posImg !== false ) { $ posClosedImg = strpos ( $ content , '/>' , $ posImg ) + 2 ; $ img = substr ( $ content , $ posImg , ( $ posClosedImg - $ posImg ) ) ; $ result = str_replace ( $ img , '' , $ content ) ; } return $ result ; } | Ambil isi berita dan buang image darinya . |
18,671 | private static function resolveBaseService ( ) { $ cachedServices = Config :: get ( 'service-classes.cached_services.classes' , null ) ; $ baseService = $ cachedServices [ static :: class ] ?? static :: translateBaseService ( ) ; return resolve ( $ baseService ) ; } | Resolve the base service for the cached service . |
18,672 | private static function translateBaseService ( ) { $ cachedServicePrefix = Config :: get ( 'service-classes.cached_services.prefix' ) ; $ cachedServiceNamespace = '\\' . Config :: get ( 'service-classes.cached_services.namespace' ) ; return str_replace ( [ $ cachedServicePrefix , $ cachedServiceNamespace ] , [ '' , '' ] , static :: class ) ; } | Translate the cached service name to the base service name . |
18,673 | public function getBundleName ( ) : ? string { if ( $ this -> getBundleNamespace ( ) === static :: NO_BUNDLE_NAMESPACE ) { return null ; } if ( strpos ( '\\' , $ this -> getBundleNamespace ( ) ) !== false ) { $ parts = explode ( '\\' , $ this -> getBundleNamespace ( ) ) ; return array_pop ( $ parts ) ; } return $ this -> getBundleNamespace ( ) ; } | Gets bundle name by retrieving the last part of the bundleNamespace |
18,674 | public function match ( $ url ) { if ( ! $ this -> schemes ) { return true ; } foreach ( $ this -> schemes as $ scheme ) { if ( $ scheme -> match ( $ url ) ) { return true ; } } return false ; } | Check whether the given URL match one of the provider s schemes |
18,675 | static public function factory ( $ object ) { if ( ! isset ( $ object -> type ) ) { throw new ObjectException ( 'The object has no type.' ) ; } $ type = ( string ) $ object -> type ; if ( ! isset ( self :: $ types [ $ type ] ) ) { throw new NoSupportException ( sprintf ( 'The object type "%s" is unknown or invalid.' , $ type ) ) ; } $ class = '\\Omlex\\Object\\' . self :: $ types [ $ type ] ; if ( ! class_exists ( $ class ) ) { throw new ObjectException ( sprintf ( 'The object class "%s" is invalid or not found.' , $ class ) ) ; } $ instance = new $ class ( $ object ) ; return $ instance ; } | Create an Omlex object from result |
18,676 | public function setConfig ( $ config ) { if ( is_array ( $ config ) ) { $ this -> config = $ this -> createConfig ( $ config ) ; } elseif ( $ config instanceof ConfigInterface ) { $ this -> config = $ config ; } else { throw new InvalidArgumentException ( 'Configuration must be an array or a ConfigInterface object.' ) ; } return $ this ; } | Set the object s configuration container . |
18,677 | public function config ( $ key = null ) { if ( $ this -> config === null ) { $ this -> config = $ this -> createConfig ( ) ; } if ( $ key !== null ) { return $ this -> config -> get ( $ key ) ; } else { return $ this -> config ; } } | Retrieve the object s configuration container or one of its entry . |
18,678 | protected function mergePresets ( array $ data ) { if ( isset ( $ data [ 'attachable_objects' ] ) ) { $ data [ 'attachable_objects' ] = $ this -> mergePresetAttachableObjects ( $ data [ 'attachable_objects' ] ) ; } if ( isset ( $ data [ 'default_attachable_objects' ] ) ) { $ data [ 'attachable_objects' ] = $ this -> mergePresetAttachableObjects ( $ data [ 'default_attachable_objects' ] ) ; } if ( isset ( $ data [ 'preset' ] ) ) { $ data = $ this -> mergePresetWidget ( $ data ) ; } return $ data ; } | Parse the given data and recursively merge presets from attachments config . |
18,679 | private function mergePresetWidget ( array $ data ) { if ( ! isset ( $ data [ 'preset' ] ) || ! is_string ( $ data [ 'preset' ] ) ) { return $ data ; } $ widgetIdent = $ data [ 'preset' ] ; if ( $ this instanceof ObjectContainerInterface ) { if ( $ this -> hasObj ( ) ) { $ widgetIdent = $ this -> obj ( ) -> render ( $ widgetIdent ) ; } } elseif ( $ this instanceof ModelInterface ) { $ widgetIdent = $ this -> render ( $ widgetIdent ) ; } $ presetWidgets = $ this -> config ( 'widgets' ) ; if ( ! isset ( $ presetWidgets [ $ widgetIdent ] ) ) { return $ data ; } $ widgetData = $ presetWidgets [ $ widgetIdent ] ; if ( isset ( $ widgetData [ 'attachable_objects' ] ) ) { $ widgetData [ 'attachable_objects' ] = $ this -> mergePresetAttachableObjects ( $ widgetData [ 'attachable_objects' ] ) ; } if ( isset ( $ widgetData [ 'default_attachable_objects' ] ) ) { $ widgetData [ 'attachable_objects' ] = $ this -> mergePresetAttachableObjects ( $ widgetData [ 'default_attachable_objects' ] ) ; } return array_replace_recursive ( $ widgetData , $ data ) ; } | Parse the given data and merge the widget preset . |
18,680 | private function mergePresetAttachableObjects ( $ data ) { if ( is_string ( $ data ) ) { $ groupIdent = $ data ; if ( $ this instanceof ObjectContainerInterface ) { if ( $ this -> hasObj ( ) ) { $ groupIdent = $ this -> obj ( ) -> render ( $ groupIdent ) ; } } elseif ( $ this instanceof ModelInterface ) { $ groupIdent = $ this -> render ( $ groupIdent ) ; } $ presetGroups = $ this -> config ( 'groups' ) ; if ( isset ( $ presetGroups [ $ groupIdent ] ) ) { $ data = $ presetGroups [ $ groupIdent ] ; } } if ( is_array ( $ data ) ) { $ presetTypes = $ this -> config ( 'attachables' ) ; $ attachables = [ ] ; foreach ( $ data as $ attType => $ attStruct ) { if ( is_string ( $ attStruct ) ) { $ attType = $ attStruct ; $ attStruct = [ ] ; } if ( ! is_string ( $ attType ) ) { throw new InvalidArgumentException ( 'The attachment type must be a string' ) ; } if ( ! is_array ( $ attStruct ) ) { throw new InvalidArgumentException ( sprintf ( 'The attachment structure for "%s" must be an array' , $ attType ) ) ; } if ( isset ( $ presetTypes [ $ attType ] ) ) { $ attStruct = array_replace_recursive ( $ presetTypes [ $ attType ] , $ attStruct ) ; } $ attachables [ $ attType ] = $ attStruct ; } $ data = $ attachables ; } return $ data ; } | Parse the given data and merge the preset attachment types . |
18,681 | public function call ( $ presenter , array $ data = [ ] ) { if ( $ presenter instanceof PresenterInterface ) { return $ this -> callPresenter ( [ $ presenter , '__invoke' ] , $ data ) ; } if ( is_callable ( $ presenter ) ) { return $ this -> callPresenter ( $ presenter , $ data ) ; } if ( $ resolver = $ this -> builder -> getContainer ( ) ) { return $ this -> callPresenter ( $ resolver -> get ( $ presenter ) , $ data ) ; } throw new \ BadMethodCallException ( 'cannot resolve a presenter.' ) ; } | calls the presenter to create a view to respond . |
18,682 | public function isAjax ( ) : bool { if ( isset ( $ _SERVER [ 'HTTP_X_REQUESTED_WITH' ] ) ) { return ( strtolower ( $ _SERVER [ 'HTTP_X_REQUESTED_WITH' ] ) == 'xmlhttprequest' ) ; } if ( isset ( $ _SERVER [ 'HTTP_X_AJAX' ] ) ) { return ( strtolower ( $ _SERVER [ 'HTTP_X_AJAX' ] ) == 'true' || $ _SERVER [ 'HTTP_X_AJAX' ] == '1' ) ; } return false ; } | Is ajax . |
18,683 | public function index ( ) { $ render = $ this -> request -> getQuery ( 'render' , $ this -> request -> getCookie ( 'render-photos' ) ) ; $ query = $ this -> Photos -> find ( ) -> contain ( [ 'Albums' => [ 'fields' => [ 'id' , 'slug' , 'title' ] ] ] ) ; $ this -> paginate [ 'order' ] = [ 'Photos.created' => 'DESC' ] ; if ( $ render === 'grid' ) { $ this -> paginate [ 'limit' ] = $ this -> paginate [ 'maxLimit' ] = getConfigOrFail ( 'admin.photos' ) ; $ this -> viewBuilder ( ) -> setTemplate ( 'index_as_grid' ) ; } $ this -> set ( 'photos' , $ this -> paginate ( $ this -> Photos -> queryFromFilter ( $ query , $ this -> request -> getQueryParams ( ) ) ) ) ; if ( $ render ) { $ this -> response = $ this -> response -> withCookie ( ( new Cookie ( 'render-photos' , $ render ) ) -> withNeverExpire ( ) ) ; } } | Lists photos . |
18,684 | public function showMedia ( ) { $ mediaMapper = ( $ this -> container -> dataMapper ) ( 'MediaMapper' ) ; $ mediaCategoryMapper = ( $ this -> container -> dataMapper ) ( 'MediaCategoryMapper' ) ; $ data [ 'media' ] = $ mediaMapper -> find ( ) ; $ data [ 'categories' ] = $ mediaCategoryMapper -> findCategories ( ) ; $ cats = $ mediaCategoryMapper -> findAllMediaCategoryAssignments ( ) ; foreach ( $ data [ 'media' ] as $ key => & $ medium ) { $ medium -> category = [ ] ; foreach ( $ cats as $ cat ) { if ( $ medium -> id === $ cat -> media_id ) { $ medium -> category [ $ cat -> category_id ] = 'on' ; } } } return $ this -> render ( 'media/media.html' , $ data ) ; } | Show All Media |
18,685 | public function getMedia ( ) { $ mediaMapper = ( $ this -> container -> dataMapper ) ( 'MediaMapper' ) ; $ data = $ mediaMapper -> find ( ) ; $ template = <<<HTML {% import "@admin/media/_mediaCardMacro.html" as file %} <div class="card-wrapper"> {% for media in page.media %} {{ file.mediaCard(media) }} {% endfor %} </div>HTML ; $ mediaHtml = $ this -> container -> view -> fetchFromString ( $ template , [ 'page' => [ 'media' => $ data ] ] ) ; $ response = $ this -> response -> withHeader ( 'Content-Type' , 'application/json' ) ; return $ response -> write ( json_encode ( [ "html" => $ mediaHtml ] ) ) ; } | Get All Media |
18,686 | public function editMediaCategories ( ) { $ mediaCategoryMapper = ( $ this -> container -> dataMapper ) ( 'MediaCategoryMapper' ) ; $ data = $ mediaCategoryMapper -> find ( ) ; return $ this -> render ( 'media/mediaCategories.html' , [ 'categories' => $ data ] ) ; } | Edit Media Categories |
18,687 | public function saveMediaCategories ( ) { $ mediaCategoryMapper = ( $ this -> container -> dataMapper ) ( 'MediaCategoryMapper' ) ; $ categoriesPost = $ this -> request -> getParsedBody ( ) ; foreach ( $ categoriesPost [ 'category' ] as $ key => $ cat ) { if ( empty ( $ cat ) ) { continue ; } $ category = $ mediaCategoryMapper -> make ( ) ; $ category -> id = $ categoriesPost [ 'id' ] [ $ key ] ; if ( isset ( $ categoriesPost [ 'delete' ] [ $ key ] ) && ! empty ( $ categoriesPost [ 'id' ] [ $ key ] ) ) { $ mediaCategoryMapper -> delete ( $ category ) ; } $ category -> category = $ cat ; $ mediaCategoryMapper -> save ( $ category ) ; } return $ this -> redirect ( 'adminEditMediaCategories' ) ; } | Save Media Categories |
18,688 | protected function getTitleForLayout ( ) { if ( ! empty ( $ this -> titleForLayout ) ) { return $ this -> titleForLayout ; } $ title = getConfigOrFail ( 'main.title' ) ; if ( $ this -> request -> isUrl ( [ '_name' => 'homepage' ] ) ) { return $ title ; } if ( $ this -> get ( 'title' ) ) { $ title = sprintf ( '%s - %s' , $ this -> get ( 'title' ) , $ title ) ; } elseif ( $ this -> fetch ( 'title' ) ) { $ title = sprintf ( '%s - %s' , $ this -> fetch ( 'title' ) , $ title ) ; } return $ this -> titleForLayout = $ title ; } | Gets the title for layout |
18,689 | private function getSearchQueryResult ( array $ where = [ ] , array $ orderBy = [ ] , $ limit = - 1 , $ offset = 0 ) { $ query = ( new Query ( $ this -> getPdo ( ) , $ this -> getActiveRecordTable ( ) ) ) -> select ( ) ; $ this -> getSearchQueryWhere ( $ query , $ where ) ; $ this -> getSearchQueryOrderBy ( $ query , $ orderBy ) ; $ this -> getSearchQueryLimit ( $ query , $ limit , $ offset ) ; return $ query -> execute ( ) ; } | Returns the search query result with the given where order by limit and offset clauses . |
18,690 | private function getSearchQueryWhere ( $ query , $ where ) { foreach ( $ where as $ key => $ value ) { $ query -> where ( $ value [ 0 ] , $ value [ 1 ] , $ value [ 2 ] ) ; } return $ query ; } | Returns the given query after adding the given where conditions . |
18,691 | private function getSearchQueryOrderBy ( $ query , $ orderBy ) { foreach ( $ orderBy as $ key => $ value ) { $ query -> orderBy ( $ key , $ value ) ; } return $ query ; } | Returns the given query after adding the given order by conditions . |
18,692 | private function getSearchQueryLimit ( $ query , $ limit , $ offset ) { if ( $ limit > - 1 ) { $ query -> limit ( $ limit ) ; $ query -> offset ( $ offset ) ; } return $ query ; } | Returns the given query after adding the given limit and offset conditions . |
18,693 | public function attachmentsMetadata ( ) { if ( $ this -> attachmentsMetadata === null ) { $ this -> attachmentsMetadata = [ ] ; $ metadata = $ this -> metadata ( ) ; if ( isset ( $ metadata [ 'attachments' ] ) ) { $ this -> attachmentsMetadata = $ this -> mergePresets ( $ metadata [ 'attachments' ] ) ; } } return $ this -> attachmentsMetadata ; } | Retrieve the attachments configuration from this object s metadata . |
18,694 | public function attachmentGroup ( ) { if ( $ this -> group === null ) { $ config = $ this -> attachmentsMetadata ( ) ; $ group = AttachmentContainerInterface :: DEFAULT_GROUPING ; if ( isset ( $ config [ 'group' ] ) ) { $ group = $ config [ 'group' ] ; } elseif ( isset ( $ config [ 'default_group' ] ) ) { $ group = $ config [ 'default_group' ] ; } elseif ( isset ( $ config [ 'default_widget' ] ) ) { $ widget = $ config [ 'default_widget' ] ; $ metadata = $ this -> metadata ( ) ; $ found = false ; if ( isset ( $ metadata [ 'admin' ] [ 'form_groups' ] [ $ widget ] [ 'group' ] ) ) { $ group = $ metadata [ 'admin' ] [ 'form_groups' ] [ $ widget ] [ 'group' ] ; $ found = true ; } if ( ! $ found && isset ( $ metadata [ 'admin' ] [ 'forms' ] ) ) { foreach ( $ metadata [ 'admin' ] [ 'forms' ] as $ form ) { if ( isset ( $ form [ 'groups' ] [ $ widget ] [ 'group' ] ) ) { $ group = $ form [ 'groups' ] [ $ widget ] [ 'group' ] ; $ found = true ; break ; } } } if ( ! $ found && isset ( $ metadata [ 'admin' ] [ 'dashboards' ] ) ) { foreach ( $ metadata [ 'admin' ] [ 'dashboards' ] as $ dashboard ) { if ( isset ( $ dashboard [ 'widgets' ] [ $ widget ] [ 'group' ] ) ) { $ group = $ dashboard [ 'widgets' ] [ $ widget ] [ 'group' ] ; $ found = true ; break ; } } } } if ( ! is_string ( $ group ) ) { throw new UnexpectedValueException ( 'The attachment grouping must be a string.' ) ; } $ this -> group = $ group ; } return $ this -> group ; } | Retrieve the widget s attachment grouping . |
18,695 | public function attachableObjects ( ) { if ( $ this -> attachableObjects === null ) { $ this -> attachableObjects = [ ] ; $ config = $ this -> attachmentsMetadata ( ) ; if ( isset ( $ config [ 'attachable_objects' ] ) ) { foreach ( $ config [ 'attachable_objects' ] as $ attType => $ attMeta ) { if ( isset ( $ attMeta [ 'active' ] ) && ! $ attMeta [ 'active' ] ) { continue ; } if ( isset ( $ attMeta [ 'attachment_type' ] ) ) { $ attType = $ attMeta [ 'attachment_type' ] ; } else { $ attMeta [ 'attachment_type' ] = $ attType ; } $ attMeta [ 'attachmentType' ] = $ attMeta [ 'attachment_type' ] ; if ( isset ( $ attMeta [ 'label' ] ) ) { $ attMeta [ 'label' ] = $ this -> translator ( ) -> translation ( $ attMeta [ 'label' ] ) ; } else { $ attMeta [ 'label' ] = ucfirst ( basename ( $ attType ) ) ; } $ faIcon = '' ; if ( isset ( $ attMeta [ 'fa_icon' ] ) && ! empty ( $ attMeta [ 'fa_icon' ] ) ) { $ faIcon = 'fa fa-' . $ attMeta [ 'fa_icon' ] ; } elseif ( $ this -> attachmentWidget ( ) ) { $ attParts = explode ( '/' , $ attType ) ; $ defaultIcons = $ this -> attachmentWidget ( ) -> defaultIcons ( ) ; if ( isset ( $ defaultIcons [ end ( $ attParts ) ] ) ) { $ faIcon = 'fa fa-' . $ defaultIcons [ end ( $ attParts ) ] ; } } $ attMeta [ 'faIcon' ] = $ faIcon ; $ attMeta [ 'hasFaIcon' ] = ! ! $ faIcon ; if ( isset ( $ attMeta [ 'form_ident' ] ) ) { $ attMeta [ 'formIdent' ] = $ attMeta [ 'form_ident' ] ; } else { $ attMeta [ 'formIdent' ] = null ; } if ( isset ( $ attMeta [ 'quick_form_ident' ] ) ) { $ attMeta [ 'quickFormIdent' ] = $ attMeta [ 'quick_form_ident' ] ; } else { $ attMeta [ 'quickFormIdent' ] = null ; } $ this -> attachableObjects [ $ attType ] = $ attMeta ; } } } return $ this -> attachableObjects ; } | Returns attachable objects |
18,696 | public static function pages ( ) { if ( ! getConfig ( 'sitemap.pages' ) ) { return [ ] ; } $ table = TableRegistry :: get ( 'MeCms.PagesCategories' ) ; $ url = Cache :: read ( 'sitemap' , $ table -> getCacheName ( ) ) ; if ( ! $ url ) { $ alias = $ table -> Pages -> getAlias ( ) ; $ categories = $ table -> find ( 'active' ) -> select ( [ 'id' , 'lft' , 'slug' ] ) -> contain ( $ alias , function ( Query $ q ) use ( $ alias ) { return $ q -> find ( 'active' ) -> select ( [ 'category_id' , 'slug' , 'modified' ] ) -> order ( [ sprintf ( '%s.modified' , $ alias ) => 'DESC' ] ) ; } ) -> order ( [ 'lft' => 'ASC' ] ) ; if ( $ categories -> isEmpty ( ) ) { return [ ] ; } $ url [ ] = self :: parse ( [ '_name' => 'pagesCategories' ] ) ; foreach ( $ categories as $ category ) { $ url [ ] = self :: parse ( [ '_name' => 'pagesCategory' , $ category -> slug ] , [ 'lastmod' => array_value_first ( $ category -> pages ) -> modified ] ) ; foreach ( $ category -> pages as $ page ) { $ url [ ] = self :: parse ( [ '_name' => 'page' , $ page -> slug ] , [ 'lastmod' => $ page -> modified ] ) ; } } Cache :: write ( 'sitemap' , $ url , $ table -> getCacheName ( ) ) ; } return $ url ; } | Returns pages urls |
18,697 | public static function photos ( ) { if ( ! getConfig ( 'sitemap.photos' ) ) { return [ ] ; } $ table = TableRegistry :: get ( 'MeCms.PhotosAlbums' ) ; $ url = Cache :: read ( 'sitemap' , $ table -> getCacheName ( ) ) ; if ( ! $ url ) { $ alias = $ table -> Photos -> getAlias ( ) ; $ albums = $ table -> find ( 'active' ) -> select ( [ 'id' , 'slug' ] ) -> contain ( $ alias , function ( Query $ q ) use ( $ alias ) { return $ q -> find ( 'active' ) -> select ( [ 'id' , 'album_id' , 'modified' ] ) -> order ( [ sprintf ( '%s.modified' , $ alias ) => 'DESC' ] ) ; } ) ; if ( $ albums -> isEmpty ( ) ) { return [ ] ; } $ latest = $ table -> Photos -> find ( 'active' ) -> select ( [ 'modified' ] ) -> order ( [ sprintf ( '%s.modified' , $ alias ) => 'DESC' ] ) -> firstOrFail ( ) ; $ url [ ] = self :: parse ( [ '_name' => 'albums' ] , [ 'lastmod' => $ latest -> modified ] ) ; foreach ( $ albums as $ album ) { $ url [ ] = self :: parse ( [ '_name' => 'album' , $ album -> slug ] , [ 'lastmod' => array_value_first ( $ album -> photos ) -> modified ] ) ; foreach ( $ album -> photos as $ photo ) { $ url [ ] = self :: parse ( [ '_name' => 'photo' , 'slug' => $ album -> slug , 'id' => $ photo -> id ] , [ 'lastmod' => $ photo -> modified ] ) ; } } Cache :: write ( 'sitemap' , $ url , $ table -> getCacheName ( ) ) ; } return $ url ; } | Returns photos urls |
18,698 | public static function posts ( ) { if ( ! getConfig ( 'sitemap.posts' ) ) { return [ ] ; } $ table = TableRegistry :: get ( 'MeCms.PostsCategories' ) ; $ url = Cache :: read ( 'sitemap' , $ table -> getCacheName ( ) ) ; if ( ! $ url ) { $ alias = $ table -> Posts -> getAlias ( ) ; $ categories = $ table -> find ( 'active' ) -> select ( [ 'id' , 'lft' , 'slug' ] ) -> contain ( $ alias , function ( Query $ q ) use ( $ alias ) { return $ q -> find ( 'active' ) -> select ( [ 'category_id' , 'slug' , 'modified' ] ) -> order ( [ sprintf ( '%s.modified' , $ alias ) => 'DESC' ] ) ; } ) -> order ( [ 'lft' => 'ASC' ] ) ; if ( $ categories -> isEmpty ( ) ) { return [ ] ; } $ latest = $ table -> Posts -> find ( 'active' ) -> select ( [ 'modified' ] ) -> order ( [ sprintf ( '%s.modified' , $ alias ) => 'DESC' ] ) -> firstOrFail ( ) ; $ url [ ] = self :: parse ( [ '_name' => 'posts' ] , [ 'lastmod' => $ latest -> modified ] ) ; $ url [ ] = self :: parse ( [ '_name' => 'postsCategories' ] ) ; $ url [ ] = self :: parse ( [ '_name' => 'postsSearch' ] , [ 'priority' => '0.2' ] ) ; foreach ( $ categories as $ category ) { $ url [ ] = self :: parse ( [ '_name' => 'postsCategory' , $ category -> slug ] , [ 'lastmod' => array_value_first ( $ category -> posts ) -> modified ] ) ; foreach ( $ category -> posts as $ post ) { $ url [ ] = self :: parse ( [ '_name' => 'post' , $ post -> slug ] , [ 'lastmod' => $ post -> modified ] ) ; } } Cache :: write ( 'sitemap' , $ url , $ table -> getCacheName ( ) ) ; } return $ url ; } | Returns posts urls |
18,699 | public static function postsTags ( ) { if ( ! getConfig ( 'sitemap.posts_tags' ) ) { return [ ] ; } $ table = TableRegistry :: get ( 'MeCms.Tags' ) ; $ url = Cache :: read ( 'sitemap' , $ table -> getCacheName ( ) ) ; if ( ! $ url ) { $ tags = $ table -> find ( 'active' ) -> select ( [ 'tag' , 'modified' ] ) -> order ( [ 'tag' => 'ASC' ] ) ; if ( $ tags -> isEmpty ( ) ) { return [ ] ; } $ latest = $ table -> find ( ) -> select ( [ 'modified' ] ) -> order ( [ 'modified' => 'DESC' ] ) -> firstOrFail ( ) ; $ url [ ] = self :: parse ( [ '_name' => 'postsTags' ] , [ 'lastmod' => $ latest -> modified ] ) ; foreach ( $ tags as $ tag ) { $ url [ ] = self :: parse ( [ '_name' => 'postsTag' , $ tag -> slug ] , [ 'lastmod' => $ tag -> modified ] ) ; } Cache :: write ( 'sitemap' , $ url , $ table -> getCacheName ( ) ) ; } return $ url ; } | Returns posts tags urls |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.