idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
10,300
public function trackAttempt ( $ username , $ password ) { if ( ! $ this -> config -> get ( 'concrete.user.deactivation.authentication_failure.enabled' , false ) ) { return $ this ; } $ user = $ this -> resolveUser ( $ username ) ; if ( ! $ user ) { return ; } $ attempt = new LoginAttempt ( ) ; $ attempt -> setUtcDate ( Carbon :: now ( 'UTC' ) ) ; $ attempt -> setUserId ( $ user -> getUserID ( ) ) ; $ this -> entityManager -> persist ( $ attempt ) ; $ this -> batch [ ] = $ attempt ; $ this -> pruneAttempts ( ) ; return $ this ; }
Track a login attempt for a user
10,301
public function remainingAttempts ( $ username ) { $ config = $ this -> config -> get ( 'concrete.user.deactivation.authentication_failure' ) ; $ allowed = ( int ) array_get ( $ config , 'amount' , 0 ) ; $ duration = ( int ) array_get ( $ config , 'duration' , 0 ) ; $ after = Carbon :: now ( 'UTC' ) -> subSeconds ( $ duration ) ; $ user = $ this -> resolveUser ( $ username ) ; if ( ! $ user ) { return $ allowed ; } $ repository = $ this -> entityManager -> getRepository ( LoginAttempt :: class ) ; $ attempts = $ repository -> after ( $ after , $ user , true ) ; return max ( 0 , $ allowed - $ attempts ) ; }
Determine the amount of attempts remaining for a username
10,302
public function deactivate ( $ username ) { if ( ! $ this -> config -> get ( 'concrete.user.deactivation.authentication_failure.enabled' , false ) ) { return ; } $ user = $ this -> resolveUser ( $ username ) ; if ( ! $ user ) { throw new InvalidArgumentException ( t ( 'Unable to find and deactivate given user' ) ) ; } $ event = DeactivateUser :: create ( $ user ) ; $ this -> director -> dispatch ( 'on_before_user_deactivate' , $ event ) ; $ this -> entityManager -> transactional ( function ( EntityManagerInterface $ localManager ) use ( $ user ) { $ user = $ localManager -> merge ( $ user ) ; $ user -> setUserIsActive ( false ) ; } ) ; $ this -> director -> dispatch ( 'on_after_user_deactivate' , $ event ) ; }
Deactivate a given username
10,303
public function pruneAttempts ( DateTime $ before = null ) { if ( ! $ before ) { $ duration = ( int ) $ this -> config -> get ( 'concrete.user.deactivation.authentication_failure.duration' ) ; $ before = Carbon :: now ( 'UTC' ) -> subSeconds ( $ duration ) ; } $ repository = $ this -> entityManager -> getRepository ( LoginAttempt :: class ) ; $ results = $ repository -> before ( $ before ) ; $ batch = [ ] ; $ max = 50 ; foreach ( $ results as $ result ) { $ this -> entityManager -> remove ( $ result ) ; $ batch [ ] = $ result ; $ batch = $ this -> manageBatch ( $ batch , $ max ) ; } $ this -> manageBatch ( $ batch ) ; }
Prune old login attempts
10,304
private function manageBatch ( array $ batch , $ max = 0 ) { if ( count ( $ batch ) >= $ max ) { $ this -> entityManager -> flush ( ) ; $ batch = [ ] ; } return $ batch ; }
Manage a batched ORM operation
10,305
public function storeData ( $ key , $ data , $ expiration ) { $ path = $ this -> makePath ( $ key ) ; if ( strlen ( $ path ) > 259 && stripos ( PHP_OS , 'WIN' ) === 0 ) { throw new WindowsPathMaxLengthException ( ) ; } if ( ! file_exists ( $ path ) ) { $ dirname = dirname ( $ path ) ; if ( ! is_dir ( $ dirname ) ) { if ( ! @ mkdir ( $ dirname , $ this -> dirPermissions , true ) ) { if ( ! is_dir ( $ dirname ) ) { return false ; } } } if ( ! ( touch ( $ path ) && chmod ( $ path , $ this -> filePermissions ) ) ) { return false ; } } $ storeString = $ this -> getEncoder ( ) -> serialize ( $ this -> makeKeyString ( $ key ) , $ data , $ expiration ) ; $ result = file_put_contents ( $ path , $ storeString , LOCK_EX ) ; if ( function_exists ( 'opcache_invalidate' ) ) { $ invalidate = true ; if ( $ restrictedDirectory = ini_get ( 'opcache.restrict_api' ) ) { if ( strpos ( __FILE__ , $ restrictedDirectory ) !== 0 ) { $ invalidate = false ; } } if ( $ invalidate ) { @ opcache_invalidate ( $ path , true ) ; } } return false !== $ result ; }
This function takes the data and stores it to the path specified . If the directory leading up to the path does not exist it creates it .
10,306
public static function getApplicationUpdateInformation ( ) { $ app = Application :: getFacadeApplication ( ) ; $ cache = $ app -> make ( 'cache' ) ; $ r = $ cache -> getItem ( 'APP_UPDATE_INFO' ) ; if ( $ r -> isMiss ( ) ) { $ r -> lock ( ) ; $ result = static :: getLatestAvailableUpdate ( ) ; $ r -> set ( $ result ) -> save ( ) ; } else { $ result = $ r -> get ( ) ; } return $ result ; }
Retrieves the info about the latest available information . The effective request to the remote server is done just once per request .
10,307
public function getLocalAvailableUpdates ( ) { $ app = Application :: getFacadeApplication ( ) ; $ fh = $ app -> make ( 'helper/file' ) ; $ updates = [ ] ; $ contents = @ $ fh -> getDirectoryContents ( DIR_CORE_UPDATES ) ; foreach ( $ contents as $ con ) { if ( is_dir ( DIR_CORE_UPDATES . '/' . $ con ) ) { $ obj = ApplicationUpdate :: get ( $ con ) ; if ( is_object ( $ obj ) ) { if ( version_compare ( $ obj -> getUpdateVersion ( ) , APP_VERSION , '>' ) ) { $ updates [ ] = $ obj ; } } } } usort ( $ updates , function ( $ a , $ b ) { return version_compare ( $ a -> getUpdateVersion ( ) , $ b -> getUpdateVersion ( ) ) ; } ) ; return $ updates ; }
Looks in the designated updates location for all directories ascertains what version they represent and finds all versions greater than the currently installed version of concrete5 .
10,308
public static function isCurrentVersionNewerThanDatabaseVersion ( ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ config = $ app -> make ( 'config' ) ; $ database = $ db -> fetchColumn ( 'select max(version) from SystemDatabaseMigrations' ) ; $ code = $ config -> get ( 'concrete.version_db' ) ; return $ database < $ code ; }
Checks migrations to see if the current code DB version is greater than that registered in the database .
10,309
protected function getAnnotationReader ( ) { if ( $ this -> packageSupportsLegacyCore ( ) ) { $ reader = $ this -> getLegacyAnnotationReader ( ) ; } else { $ reader = $ this -> getStandardAnnotationReader ( ) ; } return $ reader ; }
Get the correct AnnotationReader based on the packages support for LegacyCore
10,310
public function recordLogin ( ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app [ 'database' ] -> connection ( ) ; $ uLastLogin = $ db -> getOne ( "select uLastLogin from Users where uID = ?" , array ( $ this -> uID ) ) ; $ iph = $ app -> make ( 'helper/validation/ip' ) ; $ ip = $ iph -> getRequestIP ( ) ; $ db -> query ( "update Users set uLastIP = ?, uLastLogin = ?, uPreviousLogin = ?, uNumLogins = uNumLogins + 1 where uID = ?" , array ( ( $ ip === false ) ? ( '' ) : ( $ ip -> getIp ( ) ) , time ( ) , $ uLastLogin , $ this -> uID ) ) ; }
Increment number of logins and update login timestamps .
10,311
public function setUserDefaultLanguage ( $ lang ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app [ 'database' ] -> connection ( ) ; $ session = $ app [ 'session' ] ; $ this -> uDefaultLanguage = $ lang ; $ session -> set ( 'uDefaultLanguage' , $ lang ) ; $ db -> Execute ( 'update Users set uDefaultLanguage = ? where uID = ?' , array ( $ lang , $ this -> getUserID ( ) ) ) ; }
Sets a default language for a user record .
10,312
public function getUserLanguageToDisplay ( ) { if ( $ this -> getUserDefaultLanguage ( ) != '' ) { return $ this -> getUserDefaultLanguage ( ) ; } else { $ app = Application :: getFacadeApplication ( ) ; $ config = $ app [ 'config' ] ; return $ config -> get ( 'concrete.locale' ) ; } }
Checks to see if the current user object is registered . If so it queries that records default language . Otherwise it falls back to sitewide settings .
10,313
public function inGroup ( $ g ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app [ 'database' ] -> connection ( ) ; $ v = array ( $ this -> uID ) ; $ cnt = $ db -> GetOne ( "select Groups.gID from UserGroups inner join " . $ db -> getDatabasePlatform ( ) -> quoteSingleIdentifier ( 'Groups' ) . " on UserGroups.gID = Groups.gID where uID = ? and gPath like " . $ db -> quote ( $ g -> getGroupPath ( ) . '%' ) , $ v ) ; return $ cnt > 0 ; }
Return true if user is in Group .
10,314
public function loadCollectionEdit ( & $ c ) { $ c -> refreshCache ( ) ; if ( $ c -> isCheckedOut ( ) ) { return false ; } $ app = Application :: getFacadeApplication ( ) ; $ db = $ app [ 'database' ] -> connection ( ) ; $ cID = $ c -> getCollectionID ( ) ; $ this -> unloadCollectionEdit ( false ) ; $ q = 'select cIsCheckedOut, cCheckedOutDatetime from Pages where cID = ?' ; $ r = $ db -> executeQuery ( $ q , array ( $ cID ) ) ; if ( $ r ) { $ row = $ r -> fetchRow ( ) ; if ( ! $ row [ 'cIsCheckedOut' ] ) { $ app [ 'session' ] -> set ( 'editCID' , $ cID ) ; $ uID = $ this -> getUserID ( ) ; $ dh = $ app -> make ( 'helper/date' ) ; $ datetime = $ dh -> getOverridableNow ( ) ; $ q2 = 'update Pages set cIsCheckedOut = ?, cCheckedOutUID = ?, cCheckedOutDatetime = ?, cCheckedOutDatetimeLastEdit = ? where cID = ?' ; $ r2 = $ db -> executeQuery ( $ q2 , array ( 1 , $ uID , $ datetime , $ datetime , $ cID ) ) ; $ c -> cIsCheckedOut = 1 ; $ c -> cCheckedOutUID = $ uID ; $ c -> cCheckedOutDatetime = $ datetime ; $ c -> cCheckedOutDatetimeLastEdit = $ datetime ; } } return true ; }
Loads a page in edit mode .
10,315
public function persist ( $ cache_interface = true ) { $ this -> refreshUserGroups ( ) ; $ app = Application :: getFacadeApplication ( ) ; $ session = $ app [ 'session' ] ; $ session -> set ( 'uID' , $ this -> getUserID ( ) ) ; $ session -> set ( 'uName' , $ this -> getUserName ( ) ) ; $ session -> set ( 'uBlockTypesSet' , false ) ; $ session -> set ( 'uGroups' , $ this -> getUserGroups ( ) ) ; $ session -> set ( 'uLastOnline' , $ this -> getLastOnline ( ) ) ; $ session -> set ( 'uTimezone' , $ this -> getUserTimezone ( ) ) ; $ session -> set ( 'uDefaultLanguage' , $ this -> getUserDefaultLanguage ( ) ) ; $ session -> set ( 'uLastPasswordChange' , $ this -> getLastPasswordChange ( ) ) ; $ cookie = $ app [ 'cookie' ] ; $ cookie -> set ( sprintf ( '%s_LOGIN' , $ app [ 'config' ] -> get ( 'concrete.session.name' ) ) , 1 ) ; if ( $ cache_interface ) { $ app -> make ( 'helper/concrete/ui' ) -> cacheInterfaceItems ( ) ; } }
Manage user session writing .
10,316
public static function getList ( ) { $ db = Database :: connection ( ) ; $ handles = $ db -> GetCol ( 'select cnvRatingTypeHandle from ConversationRatingTypes order by cnvRatingTypeHandle asc' ) ; $ types = array ( ) ; foreach ( $ handles as $ handle ) { $ ratingType = static :: getByHandle ( $ handle ) ; if ( is_object ( $ ratingType ) ) { $ types [ ] = $ ratingType ; } } return $ types ; }
Returns the list of all conversation rating types
10,317
public function getEditionByID ( $ cID ) { if ( ! $ this -> hasConnectionError ( ) ) { $ fileService = new File ( ) ; $ appVersion = Config :: get ( 'concrete.version' ) ; $ cfToken = Marketplace :: getSiteToken ( ) ; $ path = Config :: get ( 'concrete.urls.newsflow' ) . '/' . DISPATCHER_FILENAME . '/?_ccm_view_external=1&appVersion=' . $ appVersion . '&cID=' . rawurlencode ( $ cID ) . '&cfToken=' . rawurlencode ( $ cfToken ) ; $ response = $ fileService -> getContents ( $ path ) ; $ ni = new NewsflowItem ( ) ; $ obj = $ ni -> parseResponse ( $ response ) ; return $ obj ; } return false ; }
Retrieves a NewsflowItem object for a given collection ID .
10,318
public function getSlotContents ( ) { if ( $ this -> slots === null ) { $ fileService = new File ( ) ; $ appVersion = Config :: get ( 'concrete.version' ) ; $ cfToken = Marketplace :: getSiteToken ( ) ; $ url = Config :: get ( 'concrete.urls.newsflow' ) . Config :: get ( 'concrete.urls.paths.newsflow_slot_content' ) ; $ path = $ url . '?cfToken=' . rawurlencode ( $ cfToken ) . '&appVersion=' . $ appVersion ; $ response = $ fileService -> getContents ( $ path ) ; $ nsi = new NewsflowSlotItem ( ) ; $ this -> slots = $ nsi -> parseResponse ( $ response ) ; } return $ this -> slots ; }
Retrieves an array of NewsflowSlotItems .
10,319
protected static function getAssetContentsByRoute ( $ route ) { $ result = null ; try { $ app = Application :: getFacadeApplication ( ) ; $ router = $ app -> make ( RouterInterface :: class ) ; $ context = new RequestContext ( ) ; $ context -> fromRequest ( $ app -> make ( Request :: class ) ) ; $ context -> setMethod ( 'GET' ) ; $ matched = $ router -> getRouteByPath ( $ route , $ context ) ; $ controller = $ matched -> getAction ( ) ; $ callable = null ; if ( is_string ( $ controller ) ) { $ chunks = explode ( '::' , $ controller , 2 ) ; if ( count ( $ chunks ) === 2 ) { if ( class_exists ( $ chunks [ 0 ] ) ) { $ array = [ $ app -> make ( $ chunks [ 0 ] ) , $ chunks [ 1 ] ] ; if ( is_callable ( $ array ) ) { $ callable = $ array ; } } } else { if ( class_exists ( $ controller ) && method_exists ( $ controller , '__invoke' ) ) { $ callable = $ app -> make ( $ controller ) ; } } } elseif ( is_callable ( $ controller ) ) { $ callable = $ controller ; } if ( $ callable !== null ) { ob_start ( ) ; $ r = call_user_func ( $ callable , false ) ; if ( $ r instanceof Response ) { $ result = $ r -> getContent ( ) ; } elseif ( $ r !== false ) { $ result = ob_get_contents ( ) ; } ob_end_clean ( ) ; } } catch ( Exception $ x ) { } return $ result ; }
Get the contents of an asset given its route .
10,320
public function addMiddleware ( MiddlewareInterface $ middleware , $ priority = 10 ) { $ this -> stack = $ this -> stack -> withMiddleware ( $ middleware , $ priority ) ; return $ this ; }
Add a middleware to the stack
10,321
public function removeMiddleware ( MiddlewareInterface $ middleware ) { $ this -> stack = $ this -> stack -> withoutMiddleware ( $ middleware ) ; return $ this ; }
Remove a middleware from the stack
10,322
public function handleRequest ( SymfonyRequest $ request ) { $ stack = $ this -> stack ; if ( $ stack instanceof MiddlewareStack ) { $ stack = $ stack -> withDispatcher ( $ this -> app -> make ( DispatcherDelegate :: class , [ $ this -> dispatcher ] ) ) ; } return $ stack -> process ( $ request ) ; }
Take a request and pass it through middleware then return the response
10,323
private function forgetCollection ( Collection $ collection ) { $ query_builder = $ this -> manager -> createQueryBuilder ( ) ; $ query_builder -> delete ( StackUsageRecord :: class , 'r' ) -> where ( 'r.collection_id = :collection_id' ) -> setParameter ( 'collection_id' , $ collection -> getCollectionID ( ) ) -> getQuery ( ) -> execute ( ) ; }
Forget about a collection object
10,324
public function validateAuthorization ( ServerRequestInterface $ request ) { $ user = $ this -> app -> make ( User :: class ) ; return $ this -> validator -> validateAuthorization ( $ request ) ; }
Determine the access token in the authorization header and append OAUth properties to the request as attributes .
10,325
public function getWorkflowObject ( ) { if ( $ this -> wfID > 0 ) { $ wf = Workflow :: getByID ( $ this -> wfID ) ; } else { $ wf = new EmptyWorkflow ( ) ; } return $ wf ; }
Gets the Workflow object attached to this WorkflowProgress object .
10,326
public function getWorkflowRequestObject ( ) { if ( $ this -> wrID > 0 ) { $ cat = WorkflowProgressCategory :: getByID ( $ this -> wpCategoryID ) ; $ handle = $ cat -> getWorkflowProgressCategoryHandle ( ) ; $ class = '\\Core\\Workflow\\Request\\' . Core :: make ( 'helper/text' ) -> camelcase ( $ handle ) . 'Request' ; $ pkHandle = $ cat -> getPackageHandle ( ) ; $ class = core_class ( $ class , $ pkHandle ) ; $ wr = $ class :: getByID ( $ this -> wrID ) ; if ( is_object ( $ wr ) ) { $ wr -> setCurrentWorkflowProgressObject ( $ this ) ; return $ wr ; } } }
Get the WorkflowRequest object for the current WorkflowProgress object .
10,327
public static function create ( $ wpCategoryHandle , Workflow $ wf , WorkflowRequest $ wr ) { $ db = Database :: connection ( ) ; $ wpDateAdded = Core :: make ( 'helper/date' ) -> getOverridableNow ( ) ; $ wpCategoryID = $ db -> fetchColumn ( 'select wpCategoryID from WorkflowProgressCategories where wpCategoryHandle = ?' , array ( $ wpCategoryHandle ) ) ; $ db -> executeQuery ( 'insert into WorkflowProgress (wfID, wrID, wpDateAdded, wpCategoryID) values (?, ?, ?, ?)' , array ( $ wf -> getWorkflowID ( ) , $ wr -> getWorkflowRequestID ( ) , $ wpDateAdded , $ wpCategoryID , ) ) ; $ wp = self :: getByID ( $ db -> lastInsertId ( ) ) ; $ wp -> addWorkflowProgressHistoryObject ( $ wr ) ; if ( ! ( $ wf instanceof EmptyWorkflow ) ) { $ application = \ Core :: getFacadeApplication ( ) ; $ type = $ application -> make ( 'manager/notification/types' ) -> driver ( 'workflow_progress' ) ; $ notifier = $ type -> getNotifier ( ) ; $ subscription = $ type -> getSubscription ( $ wp ) ; $ notified = $ notifier -> getUsersToNotify ( $ subscription , $ wp ) ; $ notification = $ type -> createNotification ( $ wp ) ; $ notifier -> notify ( $ notified , $ notification ) ; } return $ wp ; }
Creates a WorkflowProgress object ( which will be assigned to a Page File etc ... in our system .
10,328
public function start ( ) { $ wf = $ this -> getWorkflowObject ( ) ; if ( is_object ( $ wf ) ) { $ r = $ wf -> start ( $ this ) ; $ this -> updateOnAction ( $ wf ) ; } return $ r ; }
The function that is automatically run when a workflowprogress object is started .
10,329
public function runTask ( $ task , $ args = array ( ) ) { $ wf = $ this -> getWorkflowObject ( ) ; if ( in_array ( $ task , $ wf -> getAllowedTasks ( ) ) ) { $ wpr = call_user_func_array ( array ( $ wf , $ task ) , array ( $ this , $ args ) ) ; $ this -> updateOnAction ( $ wf ) ; } if ( ! ( $ wpr instanceof Response ) ) { $ wpr = new Response ( ) ; } $ event = new GenericEvent ( ) ; $ event -> setArgument ( 'response' , $ wpr ) ; Events :: dispatch ( 'workflow_progressed' , $ event ) ; return $ wpr ; }
Attempts to run a workflow task on the bound WorkflowRequest object first then if that doesn t exist attempts to run it on the current WorkflowProgress object .
10,330
public function action ( $ action , $ task = null ) { return $ this -> app -> make ( ResolverManagerInterface :: class ) -> resolve ( func_get_args ( ) ) ; }
Returns an action suitable for including in a form action property .
10,331
public function hidden ( $ key , $ value = null , $ miscFields = [ ] ) { $ requestValue = $ this -> getRequestValue ( $ key ) ; if ( $ requestValue !== false && ( ! is_array ( $ requestValue ) ) ) { $ value = $ requestValue ; } return '<input type="hidden" id="' . $ key . '" name="' . $ key . '"' . $ this -> parseMiscFields ( '' , $ miscFields ) . ' value="' . $ value . '" />' ; }
Creates a hidden form field .
10,332
public function checkbox ( $ key , $ value , $ isChecked = false , $ miscFields = [ ] ) { if ( substr ( $ key , - 2 ) == '[]' ) { $ _field = substr ( $ key , 0 , - 2 ) ; $ id = $ _field . '_' . $ value ; } else { $ _field = $ key ; $ id = $ key ; } $ checked = false ; if ( $ isChecked && $ this -> getRequest ( ) -> get ( $ _field ) === null && $ this -> getRequest ( ) -> getMethod ( ) !== 'POST' ) { $ checked = true ; } else { $ requestValue = $ this -> getRequestValue ( $ key ) ; if ( $ requestValue !== false ) { if ( is_array ( $ requestValue ) ) { if ( in_array ( $ value , $ requestValue ) ) { $ checked = true ; } } elseif ( $ requestValue == $ value ) { $ checked = true ; } } } $ checked = $ checked ? ' checked="checked"' : '' ; return '<input type="checkbox" id="' . $ id . '" name="' . $ key . '"' . $ this -> parseMiscFields ( 'ccm-input-checkbox' , $ miscFields ) . ' value="' . $ value . '"' . $ checked . ' />' ; }
Generates a checkbox .
10,333
public function textarea ( $ key , $ valueOrMiscFields = '' , $ miscFields = [ ] ) { if ( is_array ( $ valueOrMiscFields ) ) { $ value = '' ; $ miscFields = $ valueOrMiscFields ; } else { $ value = $ valueOrMiscFields ; } $ requestValue = $ this -> getRequestValue ( $ key ) ; if ( is_string ( $ requestValue ) ) { $ value = $ requestValue ; } return '<textarea id="' . $ key . '" name="' . $ key . '"' . $ this -> parseMiscFields ( 'form-control' , $ miscFields ) . '>' . $ value . '</textarea>' ; }
Creates a textarea field .
10,334
public function radio ( $ key , $ value , $ checkedValueOrMiscFields = '' , $ miscFields = [ ] ) { if ( is_array ( $ checkedValueOrMiscFields ) ) { $ checkedValue = '' ; $ miscFields = $ checkedValueOrMiscFields ; } else { $ checkedValue = $ checkedValueOrMiscFields ; } $ checked = false ; $ requestValue = $ this -> getRequestValue ( $ key ) ; if ( $ requestValue !== false ) { if ( $ requestValue == $ value ) { $ checked = true ; } } else { if ( $ checkedValue == $ value ) { $ checked = true ; } } $ id = null ; if ( isset ( $ miscFields [ 'id' ] ) ) { $ id = $ miscFields [ 'id' ] ; unset ( $ miscFields [ 'id' ] ) ; } $ id = $ id ? : $ key . $ this -> radioIndex ; $ str = '<input type="radio" id="' . $ id . '" name="' . $ key . '" value="' . $ value . '"' ; $ str .= $ this -> parseMiscFields ( 'ccm-input-radio' , $ miscFields ) ; if ( $ checked ) { $ str .= ' checked="checked"' ; } $ str .= ' />' ; ++ $ this -> radioIndex ; return $ str ; }
Generates a radio button .
10,335
public function select ( $ key , $ optionValues , $ valueOrMiscFields = '' , $ miscFields = [ ] ) { if ( ! is_array ( $ optionValues ) ) { $ optionValues = [ ] ; } if ( is_array ( $ valueOrMiscFields ) ) { $ selectedValue = '' ; $ miscFields = $ valueOrMiscFields ; } else { $ selectedValue = ( string ) $ valueOrMiscFields ; } if ( $ selectedValue !== '' ) { $ miscFields [ 'ccm-passed-value' ] = h ( $ selectedValue ) ; } $ requestValue = $ this -> getRequestValue ( $ key ) ; if ( is_array ( $ requestValue ) && isset ( $ requestValue [ 0 ] ) && is_string ( $ requestValue [ 0 ] ) ) { $ selectedValue = ( string ) $ requestValue [ 0 ] ; } elseif ( $ requestValue !== false ) { if ( ! is_array ( $ requestValue ) ) { $ selectedValue = ( string ) $ requestValue ; } else { $ selectedValue = '' ; } } if ( substr ( $ key , - 2 ) == '[]' ) { $ _key = substr ( $ key , 0 , - 2 ) ; $ id = $ _key . $ this -> selectIndex ; ++ $ this -> selectIndex ; } else { $ id = $ key ; } $ str = '<select id="' . $ id . '" name="' . $ key . '"' . $ this -> parseMiscFields ( 'form-control' , $ miscFields ) . '>' ; foreach ( $ optionValues as $ k => $ text ) { if ( is_array ( $ text ) ) { $ str .= '<optgroup label="' . h ( $ k ) . '">' ; foreach ( $ text as $ optionValue => $ optionText ) { $ str .= '<option value="' . h ( $ optionValue ) . '"' ; if ( ( string ) $ optionValue === ( string ) $ selectedValue ) { $ str .= ' selected="selected"' ; } $ str .= '>' . h ( $ optionText ) . '</option>' ; } $ str .= '</optgroup>' ; } else { $ str .= '<option value="' . h ( $ k ) . '"' ; if ( ( string ) $ k === ( string ) $ selectedValue ) { $ str .= ' selected="selected"' ; } $ str .= '>' . $ text . '</option>' ; } } $ str .= '</select>' ; return $ str ; }
Renders a select field .
10,336
public function selectMultiple ( $ key , $ optionValues , $ defaultValues = false , $ miscFields = [ ] ) { $ requestValue = $ this -> getRequestValue ( $ key . '[]' ) ; if ( $ requestValue !== false ) { $ selectedValues = $ requestValue ; } else { $ selectedValues = $ defaultValues ; } if ( ! is_array ( $ selectedValues ) ) { if ( isset ( $ selectedValues ) && ( $ selectedValues !== false ) ) { $ selectedValues = ( array ) $ selectedValues ; } else { $ selectedValues = [ ] ; } } if ( ! is_array ( $ optionValues ) ) { $ optionValues = [ ] ; } $ str = "<select id=\"$key\" name=\"{$key}[]\" multiple=\"multiple\"" . $ this -> parseMiscFields ( 'form-control' , $ miscFields ) . '>' ; foreach ( $ optionValues as $ k => $ text ) { $ str .= '<option value="' . h ( $ k ) . '"' ; if ( in_array ( $ k , $ selectedValues ) ) { $ str .= ' selected="selected"' ; } $ str .= '>' . $ text . '</option>' ; } $ str .= '</select>' ; return $ str ; }
Renders a multiple select box .
10,337
protected function parseMiscFields ( $ defaultClass , $ attributes ) { $ attributes = ( array ) $ attributes ; if ( $ defaultClass ) { $ attributes [ 'class' ] = trim ( ( isset ( $ attributes [ 'class' ] ) ? $ attributes [ 'class' ] : '' ) . ' ' . $ defaultClass ) ; } $ attr = '' ; foreach ( $ attributes as $ k => $ v ) { $ attr .= " $k=\"$v\"" ; } return $ attr ; }
Create an HTML fragment of attribute values merging any CSS class names as necessary .
10,338
public static function getByVersionNumber ( $ version ) { $ updates = id ( new Update ( ) ) -> getLocalAvailableUpdates ( ) ; foreach ( $ updates as $ up ) { if ( $ up -> getUpdateVersion ( ) == $ version ) { return $ up ; } } }
Returns an ApplicationUpdate instance given its version string .
10,339
public static function get ( $ dir ) { $ version_file = DIR_CORE_UPDATES . "/{$dir}/" . DIRNAME_CORE . '/config/concrete.php' ; $ concrete = @ include $ version_file ; if ( $ concrete [ 'version' ] != false ) { $ obj = new self ( ) ; $ obj -> version = $ concrete [ 'version' ] ; $ obj -> identifier = $ dir ; return $ obj ; } }
Parse an update dir and returns an ApplicationUpdate instance .
10,340
public function getDiagnosticObject ( ) { $ app = Application :: getFacadeApplication ( ) ; $ client = $ app -> make ( 'http/client' ) ; $ request = $ client -> getRequest ( ) ; $ request -> setUri ( Config :: get ( 'concrete.updates.services.inspect_update' ) ) ; $ request -> setMethod ( 'POST' ) ; $ request -> getPost ( ) -> set ( 'current_version' , Config :: get ( 'concrete.version_installed' ) ) ; $ request -> getPost ( ) -> set ( 'requested_version' , $ this -> getVersion ( ) ) ; $ request -> getPost ( ) -> set ( 'site_url' , ( string ) \ Core :: getApplicationURL ( ) ) ; $ mi = Marketplace :: getInstance ( ) ; if ( $ mi -> isConnected ( ) && ! $ mi -> hasConnectionError ( ) ) { $ config = \ Core :: make ( 'config/database' ) ; $ request -> getPost ( ) -> set ( 'marketplace_token' , $ config -> get ( 'concrete.marketplace.token' ) ) ; $ list = Package :: getInstalledList ( ) ; $ packages = [ ] ; foreach ( $ list as $ pkg ) { $ packages [ ] = [ 'version' => $ pkg -> getPackageVersion ( ) , 'handle' => $ pkg -> getPackageHandle ( ) ] ; } $ request -> getPost ( ) -> set ( 'packages' , $ packages ) ; } $ info = \ Core :: make ( '\Concrete\Core\System\Info' ) ; $ overrides = $ info -> getOverrideList ( ) ; $ request -> getPost ( ) -> set ( 'overrides' , $ overrides ) ; $ info = $ info -> getJSONOBject ( ) ; $ request -> getPost ( ) -> set ( 'environment' , json_encode ( $ info ) ) ; $ client -> setMethod ( 'POST' ) ; $ response = $ client -> send ( ) ; $ body = $ response -> getBody ( ) ; $ diagnostic = DiagnosticFactory :: getFromJSON ( $ body ) ; return $ diagnostic ; }
Given the current update object sends information to concrete5 . org to determine updatability .
10,341
public function addGroup ( $ name , $ fields = [ ] ) { $ group = new Group ( ) ; $ group -> setName ( $ name ) ; $ group -> setFields ( $ fields ) ; $ this -> addGroupObject ( $ group ) ; }
Add a group of fields .
10,342
public function saveAuthenticationType ( $ args ) { $ passedUrl = trim ( $ args [ 'url' ] ) ; if ( $ passedUrl ) { try { $ url = Url :: createFromUrl ( $ passedUrl ) ; if ( ! ( string ) $ url -> getScheme ( ) || ! ( string ) $ url -> getHost ( ) ) { throw new InvalidArgumentException ( 'No scheme or host provided.' ) ; } } catch ( \ Exception $ e ) { throw new InvalidArgumentException ( 'Invalid URL.' ) ; } } $ passedName = trim ( $ args [ 'displayName' ] ) ; if ( ! $ passedName ) { throw new InvalidArgumentException ( 'Invalid display name' ) ; } $ this -> authenticationType -> setAuthenticationTypeName ( $ passedName ) ; $ config = $ this -> app -> make ( Repository :: class ) ; $ config -> save ( 'auth.external_concrete5.url' , $ args [ 'url' ] ) ; $ config -> save ( 'auth.external_concrete5.appid' , $ args [ 'apikey' ] ) ; $ config -> save ( 'auth.external_concrete5.secret' , $ args [ 'apisecret' ] ) ; $ config -> save ( 'auth.external_concrete5.registration.enabled' , ( bool ) $ args [ 'registration_enabled' ] ) ; $ config -> save ( 'auth.external_concrete5.registration.group' , intval ( $ args [ 'registration_group' ] , 10 ) ) ; }
Save data for this authentication type This method is called when the type_form . php submits . It stores client details and configuration for connecting
10,343
public function edit ( ) { $ config = $ this -> app -> make ( Repository :: class ) ; $ this -> set ( 'form' , $ this -> app -> make ( 'helper/form' ) ) ; $ this -> set ( 'data' , $ config -> get ( 'auth.external_concrete5' , [ ] ) ) ; $ this -> set ( 'redirectUri' , $ this -> urlResolver -> resolve ( [ '/ccm/system/authentication/oauth2/external_concrete5/callback' ] ) ) ; $ list = $ this -> app -> make ( GroupList :: class ) ; $ list -> includeAllGroups ( ) ; $ this -> set ( 'groups' , $ list -> getResults ( ) ) ; }
Controller method for type_form This method is called just before rendering type_form . php use it to set data for that template
10,344
private function setData ( ) { $ data = $ this -> config -> get ( 'auth.external_concrete5' , '' ) ; $ authUrl = $ this -> urlResolver -> resolve ( [ '/ccm/system/authentication/oauth2/external_concrete5/attempt_auth' ] ) ; $ attachUrl = $ this -> urlResolver -> resolve ( [ '/ccm/system/authentication/oauth2/external_concrete5/attempt_attach' ] ) ; $ baseUrl = $ this -> urlResolver -> resolve ( [ '/' ] ) ; $ path = $ baseUrl -> getPath ( ) ; $ path -> remove ( 'index.php' ) ; $ name = trim ( ( string ) array_get ( $ data , 'name' , t ( 'External concrete5' ) ) ) ; $ this -> set ( 'data' , $ data ) ; $ this -> set ( 'authUrl' , $ authUrl ) ; $ this -> set ( 'attachUrl' , $ attachUrl ) ; $ this -> set ( 'baseUrl' , $ baseUrl ) ; $ this -> set ( 'assetBase' , $ baseUrl -> setPath ( $ path ) ) ; $ this -> set ( 'name' , $ name ) ; $ this -> set ( 'user' , $ this -> app -> make ( User :: class ) ) ; }
Method for setting general data for all views
10,345
public function handleEvent ( Event $ event ) { if ( ! $ event instanceof UserInfoWithPassword ) { throw new InvalidArgumentException ( t ( 'Invalid event type provided. Event type must be "UserInfoWithPassword".' ) ) ; } $ this -> tracker -> trackUse ( $ event -> getUserPassword ( ) , $ event -> getUserInfoObject ( ) ) ; }
Event handler for on_user_change_password events
10,346
private function detectFromPHPInfo ( $ value ) { $ result = null ; if ( is_string ( $ value ) && preg_match ( '/\bApache\/(\d+(\.\d+)+)/i' , $ value , $ m ) ) { $ result = $ m [ 1 ] ; } return $ result ; }
Detect using PHPInfo .
10,347
public function route ( $ data ) { if ( is_array ( $ data ) ) { $ path = $ data [ 0 ] ; $ pkg = $ data [ 1 ] ; } else { $ path = $ data ; } $ path = trim ( $ path , '/' ) ; $ pkgHandle = null ; if ( $ pkg ) { if ( is_object ( $ pkg ) ) { $ pkgHandle = $ pkg -> getPackageHandle ( ) ; } else { $ pkgHandle = $ pkg ; } } $ route = '/ccm' ; if ( $ pkgHandle ) { $ route .= "/{$pkgHandle}" ; } else { $ route .= '/system' ; } $ route .= "/{$path}" ; return $ route ; }
Returns a route string based on data . DO NOT USE THIS .
10,348
public function deliver ( PageCacheRecord $ record ) { $ response = new Response ( ) ; $ headers = [ ] ; if ( defined ( 'APP_CHARSET' ) ) { $ headers [ 'Content-Type' ] = 'text/html; charset=' . APP_CHARSET ; } $ headers = array_merge ( $ headers , $ record -> getCacheRecordHeaders ( ) ) ; $ response -> headers -> add ( $ headers ) ; $ response -> setContent ( $ record -> getCacheRecordContent ( ) ) ; return $ response ; }
Build a Response object starting from a cached page .
10,349
public static function getLibrary ( ) { if ( ! self :: $ library ) { $ app = Application :: getFacadeApplication ( ) ; $ config = $ app -> make ( 'config' ) ; $ adapter = $ config -> get ( 'concrete.cache.page.adapter' ) ; $ class = overrideable_core_class ( 'Core\\Cache\\Page\\' . camelcase ( $ adapter ) . 'PageCache' , DIRNAME_CLASSES . '/Cache/Page/' . camelcase ( $ adapter ) . 'PageCache.php' ) ; self :: $ library = $ app -> build ( $ class ) ; } return self :: $ library ; }
Get the page cache library .
10,350
public function shouldCheckCache ( Request $ req ) { if ( $ req -> getMethod ( ) === $ req :: METHOD_POST ) { return false ; } $ app = Application :: getFacadeApplication ( ) ; $ config = $ app -> make ( 'config' ) ; $ cookie = $ app -> make ( 'cookie' ) ; $ loginCookie = sprintf ( '%s_LOGIN' , $ config -> get ( 'concrete.session.name' ) ) ; if ( $ cookie -> has ( $ loginCookie ) && $ cookie -> get ( $ loginCookie ) ) { return false ; } return true ; }
Determine if we should check if a page is in the cache .
10,351
public function outputCacheHeaders ( ConcretePage $ c ) { foreach ( $ this -> getCacheHeaders ( $ c ) as $ header ) { header ( $ header ) ; } }
Send the cache - related HTTP headers for a page to the current response .
10,352
public function getCacheHeaders ( ConcretePage $ c ) { $ lifetime = $ c -> getCollectionFullPageCachingLifetimeValue ( ) ; $ expires = gmdate ( 'D, d M Y H:i:s' , time ( ) + $ lifetime ) . ' GMT' ; $ headers = [ 'Pragma' => 'public' , 'Cache-Control' => 'max-age=' . $ lifetime . ',s-maxage=' . $ lifetime , 'Expires' => $ expires , ] ; return $ headers ; }
Get the cache - related HTTP headers for a page .
10,353
public function shouldAddToCache ( PageView $ v ) { $ c = $ v -> getPageObject ( ) ; if ( ! is_object ( $ c ) ) { return false ; } $ cp = new Checker ( $ c ) ; if ( ! $ cp -> canViewPage ( ) ) { return false ; } if ( is_object ( $ v -> controller ) ) { $ allowedControllerActions = [ 'view' ] ; if ( ! in_array ( $ v -> controller -> getAction ( ) , $ allowedControllerActions ) ) { return false ; } if ( $ c -> isGeneratedCollection ( ) && ! $ v -> controller -> supportsPageCache ( ) ) { return false ; } } if ( ! $ c -> getCollectionFullPageCaching ( ) ) { return false ; } $ app = Application :: getFacadeApplication ( ) ; $ request = $ app -> make ( Request :: class ) ; if ( $ request -> getMethod ( ) === $ request :: METHOD_POST ) { return false ; } $ u = $ app -> make ( User :: class ) ; if ( $ u -> isRegistered ( ) ) { return false ; } $ config = $ app -> make ( 'config' ) ; if ( $ c -> getCollectionFullPageCaching ( ) == 1 || $ config -> get ( 'concrete.cache.pages' ) === 'all' ) { return true ; } if ( $ config -> get ( 'concrete.cache.pages' ) !== 'blocks' ) { return false ; } $ blocks = $ c -> getBlocks ( ) ; $ blocks = array_merge ( $ c -> getGlobalBlocks ( ) , $ blocks ) ; foreach ( $ blocks as $ b ) { if ( ! $ b -> cacheBlockOutput ( ) ) { return false ; } } return true ; }
Check if a page contained in a PageView should be stored in the cache .
10,354
public function getCacheKey ( $ mixed ) { if ( $ mixed instanceof ConcretePage ) { $ collectionPath = trim ( ( string ) $ mixed -> getCollectionPath ( ) , '/' ) ; if ( $ collectionPath !== '' ) { return urlencode ( $ collectionPath ) ; } $ cID = $ mixed -> getCollectionID ( ) ; if ( $ cID && $ cID == ConcretePage :: getHomePageID ( ) ) { return '!' . $ cID ; } } elseif ( $ mixed instanceof Request ) { $ path = trim ( ( string ) $ mixed -> getPath ( ) , '/' ) ; if ( $ path !== '' ) { return urlencode ( $ path ) ; } return '!' . ConcretePage :: getHomePageID ( ) ; } elseif ( $ mixed instanceof PageCacheRecord ) { return $ mixed -> getCacheRecordKey ( ) ; } }
Get the key that identifies the cache entry for a page or a request .
10,355
protected function canMoveStacks ( $ parent ) { $ page = ( $ parent instanceof \ Concrete \ Core \ Page \ Page ) ? $ parent : $ parent -> getPage ( ) ; $ cpc = new Permissions ( $ page ) ; return ( bool ) $ cpc -> canMoveOrCopyPage ( ) ; }
Check if stacks in a Page or StackFolder can be moved .
10,356
public function getContext ( ) { return [ 'username' => $ this -> username , 'requestPath' => $ this -> requestPath , 'errors' => $ this -> errors , 'groups' => $ this -> groups , 'successful' => ! $ this -> errors ] ; }
Get the added context for the log entry
10,357
public function filterByPageTemplate ( TemplateEntity $ template ) { $ this -> query -> andWhere ( 'cv.pTemplateID = :pTemplateID' ) ; $ this -> query -> setParameter ( 'pTemplateID' , $ template -> getPageTemplateID ( ) ) ; }
Filters by page template .
10,358
public function filterByNumberOfChildren ( $ number , $ comparison = '>' ) { $ number = intval ( $ number ) ; if ( $ this -> includeAliases ) { $ this -> query -> andWhere ( $ this -> query -> expr ( ) -> orX ( $ this -> query -> expr ( ) -> comparison ( 'p.cChildren' , $ comparison , ':cChildren' ) , $ this -> query -> expr ( ) -> comparison ( 'pa.cChildren' , $ comparison , ':cChildren' ) ) ) ; } else { $ this -> query -> andWhere ( $ this -> query -> expr ( ) -> comparison ( 'p.cChildren' , $ comparison , ':cChildren' ) ) ; } $ this -> query -> setParameter ( 'cChildren' , $ number ) ; }
Filter by number of children .
10,359
public function filterByDateLastModified ( $ date , $ comparison = '=' ) { $ this -> query -> andWhere ( $ this -> query -> expr ( ) -> comparison ( 'c.cDateModified' , $ comparison , $ this -> query -> createNamedParameter ( $ date ) ) ) ; }
Filter by last modified date .
10,360
public function filterByPageTypeID ( $ ptID ) { $ db = \ Database :: get ( ) ; if ( is_array ( $ ptID ) ) { $ this -> query -> andWhere ( $ this -> query -> expr ( ) -> in ( 'pt.ptID' , array_map ( [ $ db , 'quote' ] , $ ptID ) ) ) ; } else { $ this -> query -> andWhere ( $ this -> query -> expr ( ) -> comparison ( 'pt.ptID' , '=' , ':ptID' ) ) ; $ this -> query -> setParameter ( 'ptID' , $ ptID , \ PDO :: PARAM_INT ) ; } }
Filters by page type ID .
10,361
public function filterByParentID ( $ cParentID ) { $ db = \ Database :: get ( ) ; if ( is_array ( $ cParentID ) ) { $ this -> query -> andWhere ( $ this -> query -> expr ( ) -> in ( 'p.cParentID' , array_map ( [ $ db , 'quote' ] , $ cParentID ) ) ) ; } else { $ this -> query -> andWhere ( 'p.cParentID = :cParentID' ) ; $ this -> query -> setParameter ( 'cParentID' , $ cParentID , \ PDO :: PARAM_INT ) ; } }
Filters by parent ID .
10,362
public function filterByName ( $ name , $ exact = false ) { if ( $ exact ) { $ this -> query -> andWhere ( 'cv.cvName = :cvName' ) ; $ this -> query -> setParameter ( 'cvName' , $ name ) ; } else { $ this -> query -> andWhere ( $ this -> query -> expr ( ) -> like ( 'cv.cvName' , ':cvName' ) ) ; $ this -> query -> setParameter ( 'cvName' , '%' . $ name . '%' ) ; } }
Filters a list by page name .
10,363
public function filterByPath ( $ path , $ includeAllChildren = true ) { if ( ! $ includeAllChildren ) { $ this -> query -> andWhere ( 'pp.cPath = :cPath' ) ; $ this -> query -> setParameter ( 'cPath' , $ path ) ; } else { $ this -> query -> andWhere ( $ this -> query -> expr ( ) -> like ( 'pp.cPath' , ':cPath' ) ) ; $ this -> query -> setParameter ( 'cPath' , $ path . '/%' ) ; } $ this -> query -> andWhere ( 'pp.ppIsCanonical = 1' ) ; }
Filter a list by page path .
10,364
public function filterByKeywords ( $ keywords ) { $ expressions = [ $ this -> query -> expr ( ) -> like ( 'psi.cName' , ':keywords' ) , $ this -> query -> expr ( ) -> like ( 'psi.cDescription' , ':keywords' ) , $ this -> query -> expr ( ) -> like ( 'psi.content' , ':keywords' ) , ] ; $ keys = \ CollectionAttributeKey :: getSearchableIndexedList ( ) ; foreach ( $ keys as $ ak ) { $ cnt = $ ak -> getController ( ) ; $ expressions [ ] = $ cnt -> searchKeywords ( $ keywords , $ this -> query ) ; } $ expr = $ this -> query -> expr ( ) ; $ this -> query -> andWhere ( call_user_func_array ( [ $ expr , 'orX' ] , $ expressions ) ) ; $ this -> query -> setParameter ( 'keywords' , '%' . $ keywords . '%' ) ; }
Filters keyword fields by keywords ( including name description content and attributes .
10,365
protected function getOptions ( Repository $ config ) { $ result = $ config -> get ( 'app.http_client' ) ; if ( ! is_array ( $ result ) ) { $ result = [ ] ; } $ result [ 'proxyhost' ] = $ config -> get ( 'concrete.proxy.host' ) ; $ result [ 'proxyport' ] = $ config -> get ( 'concrete.proxy.port' ) ; $ result [ 'proxyuser' ] = $ config -> get ( 'concrete.proxy.user' ) ; $ result [ 'proxypass' ] = $ config -> get ( 'concrete.proxy.password' ) ; return $ result ; }
Read the HTTP Client configuration .
10,366
protected function transformKey ( $ key ) { $ key = sprintf ( 'site.sites.%s.%s' , $ this -> site -> getSiteHandle ( ) , $ key ) ; return parent :: transformKey ( $ key ) ; }
Prepend the site config group and the current site handle
10,367
public function getViewportHTML ( ) { $ added_data = array ( 'handle' , 'name' , 'brand' , 'width' , 'height' , 'ratio' , 'agent' , ) ; $ datas = array ( ) ; foreach ( $ added_data as $ key ) { $ datas [ ] = sprintf ( 'data-device-%s="%s"' , $ key , h ( $ this -> { $ key } ) ) ; } return sprintf ( '<div class="ccm-device-viewport" %s style="width:%spx;height:%spx">%s</div>' , implode ( ' ' , $ datas ) , floor ( $ this -> getWidth ( ) / $ this -> getPixelRatio ( ) ) , floor ( $ this -> getHeight ( ) / $ this -> getPixelRatio ( ) ) , '<iframe class="ccm-display-frame"></iframe>' ) ; }
Get the HTML for this device s viewport .
10,368
public function index ( $ page ) { if ( $ page = $ this -> getPage ( $ page ) ) { if ( $ page -> getVersionObject ( ) ) { return $ page -> reindex ( $ this -> search , true ) ; } } return false ; }
Add a page to the index
10,369
public function forget ( $ page ) { if ( $ page = $ this -> getPage ( $ page ) ) { $ database = $ this -> app [ 'database' ] -> connection ( ) ; $ database -> executeQuery ( 'DELETE FROM PageSearchIndex WHERE cID=?' , [ $ page -> getCollectionID ( ) ] ) ; } return false ; }
Remove a page from the index
10,370
protected function getPage ( $ page ) { if ( is_numeric ( $ page ) ) { return Page :: getByID ( $ page ) ; } if ( is_string ( $ page ) ) { return Page :: getByPath ( $ page ) ; } if ( $ page instanceof Page ) { return $ page ; } if ( $ page instanceof Collection ) { return $ this -> getPage ( $ page -> getCollectionID ( ) ) ; } }
Get a page based on criteria
10,371
public function csv_export ( $ treeNodeParentID = null ) { $ me = $ this ; $ parent = $ me -> getParentNode ( $ treeNodeParentID ) ; $ entity = $ me -> getEntity ( $ parent ) ; $ permissions = new \ Permissions ( $ entity ) ; if ( ! $ permissions -> canViewExpressEntries ( ) ) { throw new \ Exception ( t ( 'Access Denied' ) ) ; } $ headers = [ 'Content-Type' => 'text/csv' , 'Content-Disposition' => 'attachment; filename=' . $ entity -> getHandle ( ) . '.csv' , ] ; $ config = $ this -> app -> make ( 'config' ) ; $ bom = $ config -> get ( 'concrete.export.csv.include_bom' ) ? $ config -> get ( 'concrete.charset_bom' ) : '' ; return StreamedResponse :: create ( function ( ) use ( $ entity , $ me , $ bom ) { $ entryList = new EntryList ( $ entity ) ; $ writer = new CsvWriter ( $ this -> app -> make ( WriterFactory :: class ) -> createFromPath ( 'php://output' , 'w' ) , new Date ( ) ) ; echo $ bom ; $ writer -> insertHeaders ( $ entity ) ; $ writer -> insertEntryList ( $ entryList ) ; } , 200 , $ headers ) ; }
Export Express entries into a CSV .
10,372
public function insertObject ( ObjectInterface $ object ) { $ this -> writer -> insertOne ( iterator_to_array ( $ this -> projectObject ( $ object ) ) ) ; return $ this ; }
Insert a row for a specific object instance .
10,373
public function insertList ( ItemList $ list ) { $ this -> writer -> insertAll ( $ this -> projectList ( $ list ) ) ; return $ this ; }
Insert one row for every object in a database list .
10,374
protected function projectHeaders ( ) { foreach ( $ this -> getStaticHeaders ( ) as $ header ) { yield $ header ; } foreach ( $ this -> getAttributeKeysAndControllers ( ) as list ( $ attributeKey , $ attributeController ) ) { $ handle = 'a:' . $ attributeKey -> getAttributeKeyHandle ( ) ; if ( $ attributeController instanceof SimpleTextExportableAttributeInterface ) { yield $ handle ; } elseif ( $ attributeController instanceof MulticolumnTextExportableAttributeInterface ) { foreach ( $ attributeController -> getAttributeTextRepresentationHeaders ( ) as $ subHeader ) { yield $ handle . '[' . $ subHeader . ']' ; } } } }
A generator that returns all headers .
10,375
protected function projectObject ( ObjectInterface $ object ) { foreach ( $ this -> getStaticFieldValues ( $ object ) as $ value ) { yield $ value ; } foreach ( $ this -> getAttributeKeysAndControllers ( ) as list ( $ attributeKey , $ attributeController ) ) { $ value = $ object -> getAttributeValueObject ( $ attributeKey , false ) ; $ attributeController -> setAttributeValue ( $ value ) ; if ( $ attributeController instanceof SimpleTextExportableAttributeInterface ) { yield $ attributeController -> getAttributeValueTextRepresentation ( ) ; } elseif ( $ attributeController instanceof MulticolumnTextExportableAttributeInterface ) { foreach ( $ attributeController -> getAttributeValueTextRepresentation ( ) as $ part ) { yield $ part ; } } } }
A generator that returns all fields of an object instance .
10,376
protected function projectList ( ItemList $ list ) { $ sth = $ list -> deliverQueryObject ( ) -> execute ( ) ; foreach ( $ sth as $ row ) { $ listResult = $ list -> getResult ( $ row ) ; $ object = $ this -> getObjectFromListResult ( $ list , $ listResult ) ; yield iterator_to_array ( $ this -> projectObject ( $ object ) ) ; $ this -> tick ( ) ; } }
A generator that returns all the rows for an object list .
10,377
protected function unloadDoctrineEntities ( ) { $ this -> attributeKeysAndControllers = null ; $ app = Application :: getFacadeApplication ( ) ; $ entityManager = $ app -> make ( EntityManagerInterface :: class ) ; $ entityManager -> clear ( ) ; $ category = $ this -> getCategory ( ) ; if ( $ category !== null ) { $ categoryClass = ClassUtils :: getClass ( $ category ) ; if ( ! $ entityManager -> getMetadataFactory ( ) -> isTransient ( $ categoryClass ) ) { $ entityManager -> merge ( $ category ) ; } } }
Unload every Doctrine entites and reset the state of this instance .
10,378
public function setSessionPostLoginUrl ( $ url ) { $ normalized = null ; if ( $ url instanceof Page ) { if ( ! $ url -> isError ( ) ) { $ cID = ( int ) $ url -> getCollectionID ( ) ; if ( $ cID > 0 ) { $ normalized = $ cID ; } } } elseif ( $ this -> valn -> integer ( $ url , 1 ) ) { $ normalized = ( int ) $ url ; } else { $ url = ( string ) $ url ; if ( strpos ( $ url , '/' ) !== false ) { $ normalized = $ url ; } } $ this -> resetSessionPostLoginUrl ( ) ; if ( $ normalized !== null ) { $ this -> session -> set ( static :: POSTLOGIN_SESSION_KEY , $ normalized ) ; } }
Store in the session the post - login URL or page .
10,379
public function getSessionPostLoginUrl ( $ resetSessionPostLoginUrl = false ) { $ result = '' ; $ normalized = $ this -> session -> get ( static :: POSTLOGIN_SESSION_KEY ) ; if ( $ this -> valn -> integer ( $ normalized , 1 ) ) { $ page = Page :: getByID ( $ normalized ) ; if ( $ page && ! $ page -> isError ( ) ) { $ result = ( string ) $ this -> resolverManager -> resolve ( [ $ page ] ) ; } } elseif ( strpos ( ( string ) $ normalized , '/' ) !== false ) { $ result = $ normalized ; } if ( $ resetSessionPostLoginUrl ) { $ this -> resetSessionPostLoginUrl ( ) ; } return $ result ; }
Get the post - login URL as stored in the session .
10,380
public function getDefaultPostLoginUrl ( ) { $ result = '' ; $ loginRedirectMode = ( string ) $ this -> config -> get ( 'concrete.misc.login_redirect' ) ; switch ( $ loginRedirectMode ) { case 'CUSTOM' : $ loginRedirectCollectionID = $ this -> config -> get ( 'concrete.misc.login_redirect_cid' ) ; if ( $ this -> valn -> integer ( $ loginRedirectCollectionID , 1 ) ) { $ page = Page :: getByID ( $ loginRedirectCollectionID ) ; if ( $ page && ! $ page -> isError ( ) ) { $ result = ( string ) $ this -> resolverManager -> resolve ( [ $ page ] ) ; } } break ; case 'DESKTOP' : $ desktop = DesktopList :: getMyDesktop ( ) ; if ( $ desktop && ! $ desktop -> isError ( ) ) { $ result = ( string ) $ this -> resolverManager -> resolve ( [ $ desktop ] ) ; } break ; } return $ result ; }
Get the default post - login URL .
10,381
public function getPostLoginUrl ( $ resetSessionPostLoginUrl = false ) { $ result = $ this -> getSessionPostLoginUrl ( $ resetSessionPostLoginUrl ) ; if ( $ result === '' ) { $ result = $ this -> getDefaultPostLoginUrl ( ) ; if ( $ result === '' ) { $ result = $ this -> getFallbackPostLoginUrl ( ) ; } } return $ result ; }
Get the post - login URL .
10,382
public function getPostLoginRedirectResponse ( $ resetSessionPostLoginUrl = false ) { $ result = $ this -> responseFactory -> redirect ( $ this -> getPostLoginUrl ( $ resetSessionPostLoginUrl ) , Response :: HTTP_FOUND ) ; $ result = $ result -> setMaxAge ( 0 ) -> setSharedMaxAge ( 0 ) -> setPrivate ( ) ; $ result -> headers -> addCacheControlDirective ( 'must-revalidate' , true ) ; $ result -> headers -> addCacheControlDirective ( 'no-store' , true ) ; return $ result ; }
Create a Response that redirects the user to the configured URL .
10,383
public function registerImporterRoutine ( RoutineInterface $ routine ) { if ( in_array ( $ routine , $ this -> routines ) ) { $ this -> routines [ array_search ( $ routine , $ this -> routines ) ] = $ routine ; } else { $ this -> routines [ ] = $ routine ; } }
Registers a core importer routine . Add - on developers should use addImporterRoutine You can use this if you want to swap out a core routine .
10,384
public function validateAttributeValue ( ) { $ at = $ this -> attributeType ; $ at -> getController ( ) -> setAttributeKey ( $ this -> attributeKey ) ; $ e = true ; if ( method_exists ( $ at -> getController ( ) , 'validateValue' ) ) { $ e = $ at -> getController ( ) -> validateValue ( ) ; } return $ e ; }
Validates the current attribute value to see if it fulfills the requirement portion of an attribute .
10,385
protected function filterSpecialCharacters ( array $ characters ) { foreach ( $ characters as $ str ) { if ( 1 != strlen ( $ str ) ) { throw new InvalidArgumentException ( sprintf ( 'The submitted string %s must be a single character' , $ str ) ) ; } } return $ characters ; }
Filter submitted special characters .
10,386
protected function escapeField ( $ cell ) { if ( ! $ this -> isStringable ( $ cell ) ) { return $ cell ; } $ str_cell = ( string ) $ cell ; if ( isset ( $ str_cell [ 0 ] , $ this -> special_chars [ $ str_cell [ 0 ] ] ) ) { return $ this -> escape . $ str_cell ; } return $ cell ; }
Escape a CSV cell .
10,387
protected function filterQueries ( $ queries ) { $ app = Application :: getFacadeApplication ( ) ; $ config = $ app -> make ( 'config' ) ; $ textIndexDrops = [ ] ; foreach ( $ config -> get ( 'database.text_indexes' ) as $ indexTable => $ indexDefinition ) { foreach ( array_keys ( $ indexDefinition ) as $ indexName ) { $ textIndexDrops [ ] = strtolower ( "DROP INDEX {$indexName} ON {$indexTable}" ) ; } } $ returnQueries = [ ] ; foreach ( $ queries as $ query ) { $ queryLowerCase = strtolower ( $ query ) ; if ( ! in_array ( $ queryLowerCase , $ textIndexDrops , true ) ) { $ returnQueries [ ] = $ query ; } } return $ returnQueries ; }
Filter out all the queries that are platform specific that Doctrine doens t give us a good way to deal with . This is mostly index lengths that are set in installation that Doctrine doesn t support .
10,388
public function trim ( $ value ) { $ result = '' ; $ value = ( string ) $ value ; if ( $ value !== '' ) { $ sign = $ value [ 0 ] ; if ( $ sign === '-' || $ sign === '+' ) { $ value = substr ( $ value , 1 ) ; } else { $ sign = '' ; } if ( $ value !== '' ) { $ value = ltrim ( $ value , '0' ) ; if ( $ value === '' || $ value [ 0 ] === '.' ) { $ value = '0' . $ value ; } if ( strpos ( $ value , '.' ) !== false ) { $ value = rtrim ( rtrim ( $ value , '0' ) , '.' ) ; } $ result = $ sign . $ value ; } } return $ result ; }
Remove superfluous zeroes from a string containing a number .
10,389
public function getNewToken ( ClientEntityInterface $ clientEntity , array $ scopes , $ userIdentifier = null ) { $ token = new AccessToken ( ) ; $ token -> setUserIdentifier ( $ userIdentifier ) ; return $ token ; }
Create a new access token
10,390
public function persistNewAccessToken ( AccessTokenEntityInterface $ accessTokenEntity ) { $ this -> getEntityManager ( ) -> transactional ( function ( EntityManagerInterface $ em ) use ( $ accessTokenEntity ) { $ em -> persist ( $ accessTokenEntity ) ; } ) ; }
Persists a new access token to permanent storage .
10,391
public function isAccessTokenRevoked ( $ tokenId ) { $ token = $ this -> find ( $ tokenId ) ; if ( ! $ token ) { return true ; } $ now = new \ DateTime ( 'now' ) ; if ( $ token && $ token -> getExpiryDateTime ( ) < $ now ) { return true ; } return false ; }
Check if the access token has been revoked .
10,392
public function setupSiteInterfaceLocalization ( Page $ c = null ) { $ app = Facade :: getFacadeApplication ( ) ; $ loc = $ app -> make ( Localization :: class ) ; $ locale = null ; if ( $ c === null ) { $ c = Page :: getCurrentPage ( ) ; } if ( $ c ) { $ pageController = $ c -> getPageController ( ) ; if ( is_callable ( [ $ pageController , 'useUserLocale' ] ) ) { $ useUserLocale = $ pageController -> useUserLocale ( ) ; } else { $ dh = $ app -> make ( 'helper/concrete/dashboard' ) ; $ useUserLocale = $ dh -> inDashboard ( $ c ) ; } if ( $ useUserLocale ) { $ u = new User ( ) ; $ locale = $ u -> getUserLanguageToDisplay ( ) ; } else { if ( $ this -> isEnabled ( ) ) { $ ms = Section :: getBySectionOfSite ( $ c ) ; if ( ! $ ms ) { $ ms = static :: getPreferredSection ( ) ; } if ( $ ms ) { $ locale = $ ms -> getLocale ( ) ; if ( $ this -> canSetSessionValue ( ) ) { $ app -> make ( 'session' ) -> set ( 'multilingual_default_locale' , $ locale ) ; } } } if ( ! $ locale ) { $ siteTree = $ c -> getSiteTreeObject ( ) ; if ( $ siteTree ) { $ locale = $ siteTree -> getLocale ( ) -> getLocale ( ) ; } } } } if ( ! $ locale ) { $ locale = $ app -> make ( 'config' ) -> get ( 'concrete.locale' ) ; } $ loc -> setContextLocale ( Localization :: CONTEXT_SITE , $ locale ) ; }
Set the locale associated to the site localization context .
10,393
public static function isEnabled ( ) { $ app = Facade :: getFacadeApplication ( ) ; $ cache = $ app -> make ( 'cache/request' ) ; $ item = $ cache -> getItem ( 'multilingual/enabled' ) ; if ( ! $ item -> isMiss ( ) ) { return $ item -> get ( ) ; } $ item -> lock ( ) ; $ result = false ; if ( $ app -> isInstalled ( ) ) { $ site = $ app -> make ( 'site' ) -> getSite ( ) ; if ( count ( $ site -> getLocales ( ) ) > 1 ) { $ result = true ; } } $ cache -> save ( $ item -> set ( $ result ) ) ; return $ result ; }
Check if there s some multilingual section .
10,394
private function trackLimit ( ) { ++ $ this -> sent ; if ( $ this -> sent >= $ this -> limit ) { $ this -> sent = 0 ; $ this -> transport -> disconnect ( ) ; } }
Increment the counter of sent messages and disconnect the underlying transport if needed .
10,395
protected function getErrorString ( $ code , $ value , $ default = null ) { if ( array_key_exists ( $ code , $ this -> translatable_errors ) ) { $ resolver = $ this -> translatable_errors [ $ code ] ; if ( $ resolver instanceof Closure ) { return $ resolver ( $ this , $ code , $ value ) ; } else { return $ resolver ; } } return $ default ; }
Get an error string given a code and a passed value .
10,396
public function getFormattedMessageBody ( ) { $ msgBody = $ this -> getMessageBody ( ) ; $ txt = Loader :: helper ( 'text' ) ; $ repliedPos = strpos ( $ msgBody , $ this -> getMessageDelimiter ( ) ) ; if ( $ repliedPos > - 1 ) { $ repliedText = substr ( $ msgBody , $ repliedPos ) ; $ messageText = substr ( $ msgBody , 0 , $ repliedPos ) ; $ msgBody = $ messageText . '<div class="ccm-profile-message-replied">' . nl2br ( $ txt -> entities ( $ repliedText ) ) . '</div>' ; $ msgBody = str_replace ( $ this -> getMessageDelimiter ( ) , '<hr />' , $ msgBody ) ; } else { $ msgBody = nl2br ( $ txt -> entities ( $ msgBody ) ) ; } return $ msgBody ; }
Responsible for converting line breaks to br tags perhaps running bbcode as well as making the older replied - to messages gray .
10,397
public function addTracker ( $ tracker , callable $ creator ) { $ this -> creators [ $ tracker ] = $ creator ; $ this -> map [ ] = $ tracker ; if ( isset ( $ this -> trackers [ $ tracker ] ) ) { unset ( $ this -> trackers [ $ tracker ] ) ; } return $ this ; }
Register a custom tracker creator Closure .
10,398
public function tracker ( $ tracker ) { if ( $ cached = array_get ( $ this -> trackers , $ tracker ) ) { return $ cached ; } if ( $ creator = array_get ( $ this -> creators , $ tracker ) ) { $ created = $ this -> app -> call ( $ creator ) ; $ this -> trackers [ $ tracker ] = $ created ; unset ( $ this -> creators [ $ tracker ] ) ; return $ created ; } throw new InvalidArgumentException ( "Tracker [$tracker] not supported." ) ; }
Get a tracker by handle
10,399
public function reconnect ( $ name = null ) { $ this -> disconnect ( $ name = $ name ? : $ this -> getDefaultConnection ( ) ) ; if ( ! isset ( $ this -> connections [ $ name ] ) ) { return $ this -> connection ( $ name ) ; } else { return $ this -> refreshPdoConnections ( $ name ) ; } }
Reconnect to the given database .