idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
9,800
public function displayPaging ( $ script = false , $ return = false , $ additionalVars = array ( ) ) { $ summary = $ this -> getSummary ( ) ; $ paginator = $ this -> getPagination ( $ script , $ additionalVars ) ; if ( $ summary -> pages > 1 ) { $ html = '<div class="ccm-spacer"></div>' ; $ html .= '<div class="ccm-pagination">' ; $ html .= '<span class="ccm-page-left">' . $ paginator -> getPrevious ( ) . '</span>' ; $ html .= $ paginator -> getPages ( ) ; $ html .= '<span class="ccm-page-right">' . $ paginator -> getNext ( ) . '</span>' ; $ html .= '</div>' ; } if ( isset ( $ html ) ) { if ( $ return ) { return $ html ; } else { echo $ html ; } } }
Gets standard HTML to display paging
9,801
public function getSummary ( ) { $ ss = new \ stdClass ( ) ; $ ss -> chunk = $ this -> itemsPerPage ; $ ss -> order = $ this -> sortByDirection ; $ ss -> startAt = $ this -> start ; $ ss -> total = $ this -> getTotal ( ) ; $ ss -> startAt = ( $ ss -> startAt < $ ss -> chunk ) ? '0' : $ ss -> startAt ; $ itc = intval ( $ ss -> total / $ ss -> chunk ) ; if ( $ ss -> total == $ ss -> chunk ) { $ itc = 0 ; } $ ss -> pages = $ itc + 1 ; if ( $ ss -> startAt > 0 ) { $ ss -> current = ( $ ss -> startAt / $ ss -> chunk ) + 1 ; } else { $ ss -> current = '1' ; } $ ss -> previous = ( $ ss -> startAt >= $ ss -> chunk ) ? ( $ ss -> current - 2 ) * $ ss -> chunk : - 1 ; $ ss -> next = ( ( $ ss -> total - $ ss -> startAt ) >= $ ss -> chunk ) ? $ ss -> current * $ ss -> chunk : '' ; $ ss -> last = ( ( $ ss -> total - $ ss -> startAt ) >= $ ss -> chunk ) ? ( $ ss -> pages - 1 ) * $ ss -> chunk : '' ; $ ss -> currentStart = ( $ ss -> current > 1 ) ? ( ( ( $ ss -> current - 1 ) * $ ss -> chunk ) + 1 ) : '1' ; $ ss -> currentEnd = ( ( ( $ ss -> current + $ ss -> chunk ) - 1 ) <= $ ss -> last ) ? ( $ ss -> currentStart + $ ss -> chunk ) - 1 : $ ss -> total ; $ ss -> needsPaging = ( $ ss -> total > $ ss -> chunk ) ? true : false ; return $ ss ; }
Returns an object with properties useful for paging .
9,802
protected function parseRuleOptions ( InputInterface $ input ) { $ ruleOptions = [ ] ; foreach ( $ input -> getArgument ( 'rule-options' ) as $ keyValuePair ) { list ( $ key , $ value ) = explode ( '=' , $ keyValuePair , 2 ) ; $ key = trim ( $ key ) ; if ( substr ( $ key , - 2 ) === '[]' ) { $ isArray = true ; $ key = rtrim ( substr ( $ key , 0 , - 2 ) ) ; } else { $ isArray = false ; } if ( $ key === '' || ! isset ( $ value ) ) { throw new Exception ( sprintf ( "Unable to parse the rule option '%s': it must be in the form of key=value" , $ keyValuePair ) ) ; } if ( isset ( $ ruleOptions [ $ key ] ) ) { if ( ! ( $ isArray && is_array ( $ ruleOptions [ $ key ] ) ) ) { throw new Exception ( sprintf ( "Duplicated rule option '%s'" , $ key ) ) ; } $ ruleOptions [ $ key ] [ ] = $ value ; } else { $ ruleOptions [ $ key ] = $ isArray ? ( ( array ) $ value ) : $ value ; } } return $ ruleOptions ; }
Parse the rule - options input argument .
9,803
public function forceMaxInitialMigration ( ) { $ forcedInitialMigration = null ; foreach ( array_reverse ( $ this -> getMigrations ( ) ) as $ migration ) { if ( $ migration -> isMigrated ( ) && ! $ migration -> getMigration ( ) instanceof RepeatableMigrationInterface ) { break ; } $ forcedInitialMigration = $ migration ; } $ this -> forcedInitialMigration = $ forcedInitialMigration ; }
Force the initial migration to be the least recent repeatable one .
9,804
public function forceInitialMigration ( $ reference , $ criteria = self :: FORCEDMIGRATION_INCLUSIVE ) { $ reference = trim ( ( string ) $ reference ) ; if ( $ reference === '' ) { throw new Exception ( t ( 'Invalid initial migration reference.' ) ) ; } if ( ! in_array ( $ criteria , [ static :: FORCEDMIGRATION_INCLUSIVE , static :: FORCEDMIGRATION_EXCLUSIVE ] , true ) ) { throw new Exception ( t ( 'Invalid initial migration criteria.' ) ) ; } $ reference = str_replace ( 'Version' , '' , $ reference ) ; $ migration = $ this -> findInitialMigration ( $ reference , $ criteria ) ; if ( $ migration === null ) { throw new Exception ( t ( 'Unable to find a migration with identifier %s' , $ reference ) ) ; } $ this -> forcedInitialMigration = $ migration ; }
Force the initial migration using a specific point .
9,805
public function registerPreviousMigratedVersions ( ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; try { $ minimum = $ db -> fetchColumn ( 'select min(version) from SystemDatabaseMigrations' ) ; } catch ( Exception $ e ) { return ; } $ migrations = $ this -> getMigrations ( ) ; $ keys = array_keys ( $ migrations ) ; if ( $ keys [ 0 ] == $ minimum ) { return ; } else { foreach ( $ migrations as $ key => $ migration ) { if ( $ key < $ minimum ) { $ migration -> markMigrated ( ) ; } } } }
This is a stupid requirement but basically we grab the lowest version number in our system database migrations table and we loop through all migrations in our file system and for any of those LOWER than the lowest one in the table we can assume they are included in this migration . We then manually insert these rows into the SystemDatabaseMigrations table so Doctrine isn t stupid and attempt to apply them .
9,806
protected function findInitialMigrationByCoreVersion ( $ coreVersion , $ criteria ) { $ coreVersionNormalized = preg_replace ( '/(\.0+)+$/' , '' , $ coreVersion ) ; if ( version_compare ( $ coreVersionNormalized , '5.7' ) < 0 ) { throw new Exception ( t ( 'Invalid version specified (%s).' , $ coreVersion ) ) ; } $ migrations = $ this -> getMigrations ( ) ; $ migrationIdentifiers = array_keys ( $ migrations ) ; $ maxMigrationIndex = count ( $ migrationIdentifiers ) - 1 ; $ result = null ; foreach ( $ migrations as $ identifier => $ migration ) { $ migrationCoreVersionNormalized = preg_replace ( '/(\.0+)+$/' , '' , $ migration -> getMigration ( ) -> getDescription ( ) ) ; if ( $ migrationCoreVersionNormalized !== '' ) { $ cmp = version_compare ( $ migrationCoreVersionNormalized , $ coreVersionNormalized ) ; if ( $ cmp <= 0 || $ result === null ) { switch ( $ criteria ) { case static :: FORCEDMIGRATION_INCLUSIVE : $ result = $ migration ; break ; case static :: FORCEDMIGRATION_EXCLUSIVE : $ migrationIndex = array_search ( $ identifier , $ migrationIdentifiers , false ) ; $ result = $ migrationIndex === $ maxMigrationIndex ? null : $ migrations [ $ migrationIdentifiers [ $ migrationIndex + 1 ] ] ; break ; default : throw new Exception ( t ( 'Invalid initial migration criteria.' ) ) ; } } if ( $ cmp >= 0 ) { break ; } } } return $ result ; }
Get the initial migration starting from a core version .
9,807
protected function getFinalHrefLang ( ) { $ result = $ this -> getOverriddenHrefLang ( ) ; if ( $ result === '' ) { $ result = strtolower ( str_replace ( '_' , '-' , $ this -> getSection ( ) -> getLocale ( ) ) ) ; } return $ result ; }
Get the final value of the href lang .
9,808
public function generateGatheringItems ( ) { $ configuredDataSources = $ this -> getConfiguredGatheringDataSources ( ) ; $ items = array ( ) ; foreach ( $ configuredDataSources as $ configuration ) { $ dataSource = $ configuration -> getGatheringDataSourceObject ( ) ; $ dataSourceItems = $ dataSource -> createGatheringItems ( $ configuration ) ; $ items = array_merge ( $ dataSourceItems , $ items ) ; } $ agiBatchTimestamp = time ( ) ; $ db = Loader :: db ( ) ; foreach ( $ items as $ it ) { $ it -> setGatheringItemBatchTimestamp ( $ agiBatchTimestamp ) ; $ it -> setAutomaticGatheringItemSlotWidth ( ) ; $ it -> setAutomaticGatheringItemSlotHeight ( ) ; } $ agiBatchDisplayOrder = 0 ; $ r = $ db -> Execute ( 'select gaiID from GatheringItems where gaID = ? and gaiBatchTimestamp = ? order by gaiPublicDateTime desc' , array ( $ this -> getGatheringID ( ) , $ agiBatchTimestamp ) ) ; while ( $ row = $ r -> FetchRow ( ) ) { $ db -> Execute ( 'update GatheringItems set gaiBatchDisplayOrder = ? where gaiID = ?' , array ( $ agiBatchDisplayOrder , $ row [ 'gaiID' ] ) ) ; ++ $ agiBatchDisplayOrder ; } $ date = Loader :: helper ( 'date' ) -> getOverridableNow ( ) ; $ db -> Execute ( 'update Gatherings set gaDateLastUpdated = ? where gaID = ?' , array ( $ date , $ this -> gaID ) ) ; }
Runs through all active gathering data sources creates GatheringItem objects .
9,809
public function areEqual ( RepetitionInterface $ r1 , RepetitionInterface $ r2 ) { if ( $ r1 -> getStartDate ( ) != $ r2 -> getStartDate ( ) ) { return false ; } if ( $ r1 -> getTimezone ( ) -> getName ( ) != $ r2 -> getTimezone ( ) -> getName ( ) ) { return false ; } if ( $ r1 -> getEndDate ( ) != $ r2 -> getEndDate ( ) ) { return false ; } if ( $ r1 -> isStartDateAllDay ( ) != $ r2 -> isStartDateAllDay ( ) ) { return false ; } if ( $ r1 -> isEndDateAllDay ( ) != $ r2 -> isEndDateAllDay ( ) ) { return false ; } if ( $ r1 -> getRepeatPeriod ( ) != $ r2 -> getRepeatPeriod ( ) ) { return false ; } if ( $ r1 -> getRepeatMonthBy ( ) != $ r2 -> getRepeatMonthBy ( ) ) { return false ; } if ( $ r1 -> getRepeatEveryNum ( ) != $ r2 -> getRepeatEveryNum ( ) ) { return false ; } if ( $ r1 -> getRepeatPeriodEnd ( ) != $ r2 -> getRepeatPeriodEnd ( ) ) { return false ; } foreach ( $ r1 -> getRepeatPeriodWeekDays ( ) as $ weekDay ) { if ( ! in_array ( $ weekDay , $ r2 -> getRepeatPeriodWeekDays ( ) ) ) { return false ; } } if ( $ r1 -> getRepeatPeriodWeekDays ( ) != $ r2 -> getRepeatPeriodWeekDays ( ) ) { } return true ; }
Returns true if the two repetitions are equal .
9,810
public function process ( Request $ request , DelegateInterface $ frame ) { $ response = $ frame -> next ( $ request ) ; if ( $ response && $ this -> app -> isInstalled ( ) && $ this -> config -> get ( 'concrete.misc.basic_thumbnailer_generation_strategy' ) == 'now' ) { $ responseStatusCode = ( int ) $ response -> getStatusCode ( ) ; if ( $ responseStatusCode === 200 || $ responseStatusCode === 404 ) { $ database = $ this -> tryGetConnection ( ) ; if ( $ database !== null ) { if ( $ responseStatusCode === 404 ) { $ searchThumbnailPath = $ request -> getRequestUri ( ) ; } else { $ searchThumbnailPath = null ; } $ thumbnail = $ this -> getThumbnailToGenerate ( $ database , $ searchThumbnailPath ) ; if ( $ thumbnail !== null ) { $ this -> markThumbnailAsBuilt ( $ database , $ thumbnail ) ; if ( $ this -> generateThumbnail ( $ thumbnail ) ) { if ( $ this -> couldBeTheRequestedThumbnail ( $ thumbnail , $ searchThumbnailPath ) ) { $ response = $ this -> buildRedirectToThumbnailResponse ( $ request ) ; } } } } } } return $ response ; }
Process the request and return a response .
9,811
private function generateThumbnail ( array $ thumbnail ) { $ file = $ this -> getEntityManager ( ) -> find ( File :: class , $ thumbnail [ 'fileID' ] ) ; if ( $ this -> attemptBuild ( $ file , $ thumbnail ) ) { $ result = true ; } else { $ this -> failBuild ( $ file , $ thumbnail ) ; $ result = false ; } return $ result ; }
Generate a thumbnail .
9,812
private function markThumbnailAsBuilt ( Connection $ connection , array $ thumbnail , $ built = true ) { $ key = $ thumbnail ; unset ( $ key [ 'lockID' ] ) ; unset ( $ key [ 'lockExpires' ] ) ; unset ( $ key [ 'path' ] ) ; unset ( $ key [ 'isBuilt' ] ) ; $ connection -> update ( 'FileImageThumbnailPaths' , [ 'isBuilt' => $ built ? 1 : 0 ] , $ key ) ; }
Mark a thumbnail as built or not .
9,813
private function failBuild ( File $ file , array $ thumbnail ) { $ this -> app -> make ( LoggerInterface :: class ) -> critical ( 'Failed to generate or locate the thumbnail for file "' . $ file -> getFileID ( ) . '"' ) ; }
Mark the build failed .
9,814
public function action ( $ action ) { $ a = func_get_args ( ) ; $ controllerPath = $ this -> controller -> getControllerActionPath ( ) ; array_unshift ( $ a , $ controllerPath ) ; $ ret = call_user_func_array ( [ $ this , 'url' ] , $ a ) ; return $ ret ; }
A shortcut to posting back to the current page with a task and optional parameters . Only works in the context of .
9,815
protected function loadViewThemeObject ( ) { $ env = Environment :: get ( ) ; $ app = Facade :: getFacadeApplication ( ) ; $ tmpTheme = $ app -> make ( ThemeRouteCollection :: class ) -> getThemeByRoute ( $ this -> getViewPath ( ) ) ; if ( isset ( $ tmpTheme [ 0 ] ) ) { $ this -> themeHandle = $ tmpTheme [ 0 ] ; } if ( $ this -> themeHandle ) { switch ( $ this -> themeHandle ) { case VIEW_CORE_THEME : $ this -> themeObject = new \ Concrete \ Theme \ Concrete \ PageTheme ( ) ; $ this -> pkgHandle = false ; break ; case 'dashboard' : $ this -> themeObject = new \ Concrete \ Theme \ Dashboard \ PageTheme ( ) ; $ this -> pkgHandle = false ; break ; default : if ( ! isset ( $ this -> themeObject ) ) { $ this -> themeObject = PageTheme :: getByHandle ( $ this -> themeHandle ) ; $ this -> themePkgHandle = $ this -> themeObject -> getPackageHandle ( ) ; } } $ this -> themeAbsolutePath = $ env -> getPath ( DIRNAME_THEMES . '/' . $ this -> themeHandle , $ this -> themePkgHandle ) ; $ this -> themeRelativePath = $ env -> getURL ( DIRNAME_THEMES . '/' . $ this -> themeHandle , $ this -> themePkgHandle ) ; } }
Load all the theme - related variables for which theme to use for this request . May update the themeHandle property on the view based on themeByRoute settings .
9,816
public function view ( ) { $ this -> set ( 'trustedProxyUrl' , $ this -> urls -> resolve ( [ '/dashboard/system/permissions/trusted_proxies' ] ) ) ; $ this -> set ( 'invalidateOnIPMismatch' , $ this -> config -> get ( self :: ITEM_IP ) ) ; $ this -> set ( 'invalidateOnUserAgentMismatch' , $ this -> config -> get ( self :: ITEM_USER_AGENT ) ) ; $ this -> set ( 'invalidateInactiveUsers' , $ this -> config -> get ( self :: ITEM_INVALIDATE_INACTIVE_USERS ) ) ; $ this -> set ( 'inactiveTime' , $ this -> config -> get ( self :: ITEM_INVALIDATE_INACTIVE_USERS_TIME ) ) ; $ this -> set ( 'saveAction' , $ this -> action ( 'save' ) ) ; $ this -> set ( 'invalidateAction' , $ this -> action ( 'invalidate_sessions' , $ this -> token -> generate ( 'invalidate_sessions' ) ) ) ; $ this -> set ( 'confirmInvalidateString' , t ( 'invalidate' ) ) ; }
Main view function for the controller . This method is called when no other action matches the request
9,817
public function save ( ) { if ( ! $ this -> token -> validate ( 'save_automated_logout' ) ) { $ this -> error -> add ( $ this -> token -> getErrorMessage ( ) ) ; $ this -> flash ( 'error' , $ this -> error ) ; return $ this -> factory -> redirect ( $ this -> action ( ) ) ; } $ post = $ this -> request -> request ; $ this -> config -> save ( self :: ITEM_IP , filter_var ( $ post -> get ( 'invalidateOnIPMismatch' ) , FILTER_VALIDATE_BOOLEAN ) ) ; $ this -> config -> save ( self :: ITEM_USER_AGENT , filter_var ( $ post -> get ( 'invalidateOnUserAgentMismatch' ) , FILTER_VALIDATE_BOOLEAN ) ) ; $ this -> config -> save ( self :: ITEM_INVALIDATE_INACTIVE_USERS , filter_var ( $ post -> get ( 'invalidateInactiveUsers' ) , FILTER_VALIDATE_BOOLEAN ) ) ; $ this -> config -> save ( self :: ITEM_INVALIDATE_INACTIVE_USERS_TIME , filter_var ( $ post -> get ( 'inactiveTime' ) , FILTER_VALIDATE_INT ) ) ; $ this -> flash ( 'message' , t ( 'Successfully saved Session Security settings' ) ) ; return $ this -> factory -> redirect ( $ this -> action ( ) ) ; }
An action for saving the Session Security form This method will manage saving settings and redirecting to the appropriate results page
9,818
public function invalidate_sessions ( $ token = '' ) { if ( ! $ this -> token -> validate ( 'invalidate_sessions' , $ token ) ) { $ this -> error -> add ( $ this -> token -> getErrorMessage ( ) ) ; $ this -> flash ( 'error' , $ this -> error ) ; return $ this -> factory -> redirect ( $ this -> action ( ) ) ; } $ this -> invalidateSessions ( ) ; $ this -> flash ( 'error' , t ( 'All sessions have been invalidated. You must log back in to continue.' ) ) ; return $ this -> factory -> redirect ( $ this -> urls -> resolve ( [ '/login' ] ) ) ; }
An action for invalidating all active sessions
9,819
protected function invalidateSessions ( ) { $ this -> config -> save ( self :: ITEM_SESSION_INVALIDATE , Carbon :: now ( 'utc' ) -> getTimestamp ( ) ) ; $ this -> app -> make ( 'session' ) -> invalidate ( ) ; }
Invalidate all user sessions
9,820
public function filterByApprovedAfter ( \ DateTime $ date ) { $ this -> query -> andWhere ( 'cv.cvDateApproved >= ' . $ this -> query -> createNamedParameter ( $ date -> format ( 'Y-m-d H:i-s' ) ) ) ; }
Filter versions that are approved after a certain date .
9,821
public function filterByApprovedBefore ( \ DateTime $ date ) { $ this -> query -> andWhere ( 'cv.cvDateApproved <= ' . $ this -> query -> createNamedParameter ( $ date -> format ( 'Y-m-d H:i-s' ) ) ) ; }
Filter versions that are approved before a certain date .
9,822
public function persist ( StorageLocationEntity $ storageLocation ) { return $ this -> entityManager -> transactional ( function ( EntityManagerInterface $ em ) use ( $ storageLocation ) { if ( $ storageLocation -> isDefault ( ) ) { $ qb = $ em -> createQueryBuilder ( ) -> update ( StorageLocationEntity :: class , 'l' ) -> set ( 'l.fslIsDefault' , 0 ) ; if ( $ storageLocation -> getID ( ) ) { $ qb -> andWhere ( 'l.fslID <> :id' ) -> setParameter ( 'id' , $ storageLocation -> getID ( ) ) ; } $ qb -> getQuery ( ) -> execute ( ) ; } $ em -> persist ( $ storageLocation ) ; return $ storageLocation ; } ) ; }
Store a created storage location to the database
9,823
protected function bindContainer ( Application $ app ) { $ this -> app -> when ( PasswordUsageTracker :: class ) -> needs ( '$maxReuse' ) -> give ( function ( ) { return $ this -> app [ 'config' ] -> get ( 'concrete.user.password.reuse.track' , 5 ) ; } ) ; $ this -> app -> bindShared ( 'user/registration' , function ( ) use ( $ app ) { return $ app -> make ( 'Concrete\Core\User\RegistrationService' ) ; } ) ; $ this -> app -> bindShared ( 'user/avatar' , function ( ) use ( $ app ) { return $ app -> make ( 'Concrete\Core\User\Avatar\AvatarService' ) ; } ) ; $ this -> app -> bindShared ( 'user/status' , function ( ) use ( $ app ) { return $ app -> make ( 'Concrete\Core\User\StatusService' ) ; } ) ; $ this -> app -> bind ( 'Concrete\Core\User\RegistrationServiceInterface' , function ( ) use ( $ app ) { return $ app -> make ( 'user/registration' ) ; } ) ; $ this -> app -> bind ( 'Concrete\Core\User\StatusServiceInterface' , function ( ) use ( $ app ) { return $ app -> make ( 'user/status' ) ; } ) ; $ this -> app -> bind ( 'Concrete\Core\User\Avatar\AvatarServiceInterface' , function ( ) use ( $ app ) { return $ app -> make ( 'user/avatar' ) ; } ) ; }
Bind things to the container
9,824
public function handleEvent ( Event $ event , UserNotificationEventHandler $ service ) { if ( ! $ event instanceof DeactivateUser ) { return ; } $ entity = $ event -> getUserEntity ( ) ; if ( $ entity ) { $ service -> deactivated ( $ event ) ; } }
Handle routing bound events
9,825
public static function getAvailableThemes ( $ filterInstalled = true ) { $ db = Loader :: db ( ) ; $ dh = Loader :: helper ( 'file' ) ; $ themes = $ dh -> getDirectoryContents ( DIR_FILES_THEMES ) ; if ( $ filterInstalled ) { $ handles = $ db -> GetCol ( 'select pThemeHandle from PageThemes' ) ; $ themesTemp = [ ] ; foreach ( $ themes as $ t ) { if ( ! in_array ( $ t , $ handles ) ) { $ themesTemp [ ] = $ t ; } } $ themes = $ themesTemp ; } if ( count ( $ themes ) > 0 ) { $ themesTemp = [ ] ; foreach ( $ themes as $ t ) { $ th = static :: getByFileHandle ( $ t ) ; if ( ! empty ( $ th ) ) { $ themesTemp [ ] = $ th ; } } $ themes = $ themesTemp ; } return $ themes ; }
scans the directory for available themes . For those who don t want to go through the hassle of uploading .
9,826
public function getThemeCustomizableStyleList ( ) { if ( ! isset ( $ this -> styleList ) ) { $ env = Environment :: get ( ) ; $ r = $ env -> getRecord ( DIRNAME_THEMES . '/' . $ this -> getThemeHandle ( ) . '/' . DIRNAME_CSS . '/' . FILENAME_STYLE_CUSTOMIZER_STYLES , $ this -> getPackageHandle ( ) ) ; $ this -> styleList = \ Concrete \ Core \ StyleCustomizer \ StyleList :: loadFromXMLFile ( $ r -> file ) ; } return $ this -> styleList ; }
Gets the style list object for this theme .
9,827
public function getThemeCustomizablePreset ( $ handle ) { $ env = Environment :: get ( ) ; if ( $ this -> isThemeCustomizable ( ) ) { $ file = $ env -> getRecord ( DIRNAME_THEMES . '/' . $ this -> getThemeHandle ( ) . '/' . DIRNAME_CSS . '/' . DIRNAME_STYLE_CUSTOMIZER_PRESETS . '/' . $ handle . static :: THEME_CUSTOMIZABLE_STYLESHEET_EXTENSION , $ this -> getPackageHandle ( ) ) ; if ( $ file -> exists ( ) ) { $ urlroot = $ env -> getURL ( DIRNAME_THEMES . '/' . $ this -> getThemeHandle ( ) . '/' . DIRNAME_CSS , $ this -> getPackageHandle ( ) ) ; $ preset = Preset :: getFromFile ( $ file -> file , $ urlroot ) ; return $ preset ; } } }
Gets a preset for this theme by handle .
9,828
public function getThemeCustomizableStylePresets ( ) { $ presets = [ ] ; $ env = Environment :: get ( ) ; if ( $ this -> isThemeCustomizable ( ) ) { $ directory = $ env -> getPath ( DIRNAME_THEMES . '/' . $ this -> getThemeHandle ( ) . '/' . DIRNAME_CSS . '/' . DIRNAME_STYLE_CUSTOMIZER_PRESETS , $ this -> getPackageHandle ( ) ) ; $ urlroot = $ env -> getURL ( DIRNAME_THEMES . '/' . $ this -> getThemeHandle ( ) . '/' . DIRNAME_CSS , $ this -> getPackageHandle ( ) ) ; $ dh = Loader :: helper ( 'file' ) ; $ files = $ dh -> getDirectoryContents ( $ directory ) ; foreach ( $ files as $ f ) { if ( strrchr ( $ f , '.' ) == static :: THEME_CUSTOMIZABLE_STYLESHEET_EXTENSION ) { $ preset = Preset :: getFromFile ( $ directory . '/' . $ f , $ urlroot ) ; if ( is_object ( $ preset ) ) { $ presets [ ] = $ preset ; } } } } usort ( $ presets , function ( $ a , $ b ) { if ( $ a -> isDefaultPreset ( ) ) { return - 1 ; } else { return strcasecmp ( $ a -> getPresetDisplayName ( 'text' ) , $ b -> getPresetDisplayName ( 'text' ) ) ; } } ) ; return $ presets ; }
Gets all presets available to this theme .
9,829
public function getStylesheet ( $ stylesheet ) { $ stylesheet = $ this -> getStylesheetObject ( $ stylesheet ) ; $ styleValues = $ this -> getThemeCustomStyleObjectValues ( ) ; if ( ! is_null ( $ styleValues ) ) { $ stylesheet -> setValueList ( $ styleValues ) ; } if ( ! $ this -> isThemePreviewRequest ( ) ) { if ( ! $ stylesheet -> outputFileExists ( ) || ! Config :: get ( 'concrete.cache.theme_css' ) ) { $ stylesheet -> output ( ) ; } } $ path = $ stylesheet -> getOutputRelativePath ( ) ; if ( $ this -> isThemePreviewRequest ( ) ) { $ path .= '?ts=' . time ( ) ; } else { $ path .= '?ts=' . filemtime ( $ stylesheet -> getOutputPath ( ) ) ; } return $ path ; }
Looks into the current CSS directory and returns a fully compiled stylesheet when passed a LESS stylesheet . Also serves up custom value list values for the stylesheet if they exist .
9,830
public function getThemeCustomStyleObject ( ) { $ db = Loader :: db ( ) ; $ row = $ db -> FetchAssoc ( 'select * from PageThemeCustomStyles where pThemeID = ?' , [ $ this -> getThemeID ( ) ] ) ; if ( isset ( $ row [ 'pThemeID' ] ) ) { $ o = new \ Concrete \ Core \ Page \ CustomStyle ( ) ; $ o -> setThemeID ( $ this -> getThemeID ( ) ) ; $ o -> setValueListID ( $ row [ 'scvlID' ] ) ; $ o -> setPresetHandle ( $ row [ 'preset' ] ) ; $ o -> setCustomCssRecordID ( $ row [ 'sccRecordID' ] ) ; return $ o ; } }
Returns a Custom Style Object for the theme if one exists .
9,831
public function getFilesInTheme ( ) { $ dh = Loader :: helper ( 'file' ) ; $ templateList = PageTemplate :: getList ( ) ; $ pts = [ ] ; foreach ( $ templateList as $ pt ) { $ pts [ ] = $ pt -> getPageTemplateHandle ( ) ; } $ files = [ ] ; $ filesTmp = $ dh -> getDirectoryContents ( $ this -> pThemeDirectory ) ; foreach ( $ filesTmp as $ f ) { if ( strrchr ( $ f , '.' ) == static :: THEME_EXTENSION ) { $ fHandle = substr ( $ f , 0 , strpos ( $ f , '.' ) ) ; if ( $ f == FILENAME_THEMES_VIEW ) { $ type = PageThemeFile :: TFTYPE_VIEW ; } elseif ( $ f == FILENAME_THEMES_CLASS ) { $ type = PageThemeFile :: TFTYPE_PAGE_CLASS ; } else { if ( $ f == FILENAME_THEMES_DEFAULT ) { $ type = PageThemeFile :: TFTYPE_DEFAULT ; } else { if ( in_array ( $ f , SinglePage :: getThemeableCorePages ( ) ) ) { $ type = PageThemeFile :: TFTYPE_SINGLE_PAGE ; } else { if ( in_array ( $ fHandle , $ pts ) ) { $ type = PageThemeFile :: TFTYPE_PAGE_TEMPLATE_EXISTING ; } else { $ type = PageThemeFile :: TFTYPE_PAGE_TEMPLATE_NEW ; } } } } $ pf = new PageThemeFile ( ) ; $ pf -> setFilename ( $ f ) ; $ pf -> setType ( $ type ) ; $ files [ ] = $ pf ; } } return $ files ; }
lists them out by type allowing people to install them as page type etc ...
9,832
public function generate ( $ table , $ key , $ length = 12 , $ lowercase = false ) { $ foundHash = false ; $ db = Application :: make ( Connection :: class ) ; while ( $ foundHash == false ) { $ string = $ this -> getString ( $ length ) ; if ( $ lowercase ) { $ string = strtolower ( $ string ) ; } $ cnt = $ db -> GetOne ( "select count(" . $ key . ") as total from " . $ table . " where " . $ key . " = ?" , array ( $ string ) ) ; if ( $ cnt < 1 ) { $ foundHash = true ; } } return $ string ; }
Generates a unique identifier for an item in a database table . Used among other places in generating User hashes for email validation .
9,833
public function getString ( $ length = 12 ) { $ size = ceil ( $ length / 2 ) ; try { if ( function_exists ( 'random_bytes' ) ) { $ bytes = random_bytes ( $ size ) ; } else { $ hash = new PasswordHash ( 8 , false ) ; $ bytes = $ hash -> get_random_bytes ( $ size ) ; } } catch ( \ Exception $ e ) { die ( 'Could not generate a random string.' ) ; } return substr ( bin2hex ( $ bytes ) , 0 , $ length ) ; }
Generate a cryptographically secure random string
9,834
public static function decrypt ( $ text ) { if ( function_exists ( 'mcrypt_decrypt' ) ) { $ iv_size = mcrypt_get_iv_size ( MCRYPT_XTEA , MCRYPT_MODE_ECB ) ; $ iv = mcrypt_create_iv ( $ iv_size , MCRYPT_RAND ) ; $ len = mcrypt_get_key_size ( MCRYPT_XTEA , MCRYPT_MODE_ECB ) ; $ config = \ Core :: make ( 'config/database' ) ; $ text = trim ( mcrypt_decrypt ( MCRYPT_XTEA , substr ( $ config -> get ( 'concrete.security.token.encryption' ) , 0 , $ len ) , base64_decode ( $ text ) , MCRYPT_MODE_ECB , $ iv ) ) ; } return $ text ; }
Takes encrypted text and decrypts it .
9,835
public static function encrypt ( $ text ) { if ( function_exists ( 'mcrypt_encrypt' ) ) { $ iv_size = mcrypt_get_iv_size ( MCRYPT_XTEA , MCRYPT_MODE_ECB ) ; $ iv = mcrypt_create_iv ( $ iv_size , MCRYPT_RAND ) ; $ len = mcrypt_get_key_size ( MCRYPT_XTEA , MCRYPT_MODE_ECB ) ; $ config = \ Core :: make ( 'config/database' ) ; $ text = base64_encode ( mcrypt_encrypt ( MCRYPT_XTEA , substr ( $ config -> get ( 'concrete.security.token.encryption' ) , 0 , $ len ) , $ text , MCRYPT_MODE_ECB , $ iv ) ) ; } return $ text ; }
Takes un - encrypted text and encrypts it .
9,836
public function trackUse ( $ string , $ subject ) { $ id = $ this -> resolveUserID ( $ subject ) ; if ( ! $ id ) { return false ; } if ( ! is_string ( $ string ) ) { throw new \ InvalidArgumentException ( t ( 'Invalid mixed value provided. Must be a string.' ) ) ; } if ( $ this -> maxReuse ) { $ this -> entityManager -> transactional ( function ( EntityManagerInterface $ em ) use ( $ id , $ string ) { $ reuse = new UsedString ( ) ; $ reuse -> setDate ( Carbon :: now ( ) ) ; $ reuse -> setSubject ( $ id ) ; $ reuse -> setUsedString ( password_hash ( $ string , PASSWORD_DEFAULT ) ) ; $ em -> persist ( $ reuse ) ; } ) ; } $ this -> pruneUses ( $ id ) ; return true ; }
Track a string being used
9,837
private function pruneUses ( $ subject ) { $ repository = $ this -> entityManager -> getRepository ( UsedString :: class ) ; $ usedStrings = $ repository -> findBy ( [ 'subject' => $ subject ] , [ 'id' => 'desc' ] ) ; if ( count ( $ usedStrings ) > $ this -> maxReuse ) { array_map ( [ $ this -> entityManager , 'remove' ] , array_slice ( $ usedStrings , $ this -> maxReuse ) ) ; $ this -> entityManager -> flush ( ) ; } }
Prune uses for a specific subject
9,838
public function getImagePath ( $ uo , $ withNoCacheStr = true ) { if ( ! $ uo -> hasAvatar ( ) ) { return false ; } $ avatar = $ uo -> getUserAvatar ( ) ; return $ avatar -> getPath ( ) ; }
gets the image path for a users avatar .
9,839
protected function pagesToQueue ( ) { $ qb = $ this -> connection -> createQueryBuilder ( ) ; $ timeout = intval ( $ this -> app [ 'config' ] -> get ( 'concrete.misc.page_search_index_lifetime' ) ) ; $ query = $ qb -> select ( 'p.cID' ) -> from ( 'Pages' , 'p' ) -> leftJoin ( 'p' , 'CollectionSearchIndexAttributes' , 'a' , 'p.cID = a.cID' ) -> leftJoin ( 'p' , 'Collections' , 'c' , 'p.cID = c.cID' ) -> leftJoin ( 'p' , 'PageSearchIndex' , 's' , 'p.cID = s.cID' ) -> where ( 'cIsActive = 1' ) -> andWhere ( $ qb -> expr ( ) -> orX ( 'a.ak_exclude_search_index is null' , 'a.ak_exclude_search_index = 0' ) ) -> andWhere ( $ qb -> expr ( ) -> orX ( 'cDateModified > s.cDateLastIndexed' , "(UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(s.cDateLastIndexed) > {$timeout})" , 's.cID is null' , 's.cDateLastIndexed is null' ) ) -> execute ( ) ; while ( $ id = $ query -> fetchColumn ( ) ) { yield $ id ; } }
Get Pages to add to the queue
9,840
public static function key ( $ group , $ id ) { if ( ! empty ( $ id ) ) { return trim ( $ group , '/' ) . '/' . trim ( $ id , '/' ) ; } else { return trim ( $ group , '/' ) ; } }
Creates a cache key based on the group and id by running it through md5 .
9,841
protected function log ( $ level , $ message , array $ context = [ ] ) { if ( $ this -> logger ) { $ metadata = $ this -> getMetadataBag ( ) ; $ context [ 'metadata' ] = [ 'created' => $ metadata -> getCreated ( ) , 'lifetime' => $ metadata -> getLifetime ( ) , 'lastused' => $ metadata -> getLastUsed ( ) , 'name' => $ metadata -> getName ( ) , ] ; if ( $ this -> isStarted ( ) ) { $ attributes = $ this -> getBag ( 'attributes' ) ; if ( $ attributes instanceof SessionBagProxy ) { $ attributes = $ attributes -> getBag ( ) ; } if ( $ attributes instanceof AttributeBagInterface ) { $ context [ 'metadata' ] [ 'uID' ] = $ attributes -> get ( 'uID' , null ) ; $ context [ 'metadata' ] [ 'uGroups' ] = array_values ( $ attributes -> get ( 'uGroups' , [ ] ) ) ; } } $ this -> logger -> log ( $ level , $ message , $ context ) ; } }
Log details if possible
9,842
public function clear ( ) { $ this -> logInfo ( 'Clearing Session.' ) ; $ metadata = $ this -> getMetadataBag ( ) ; $ lifetime = $ metadata -> getLifetime ( ) ; $ lastUsed = $ metadata -> getLastUsed ( ) ; if ( $ lifetime && time ( ) > $ lastUsed + $ lifetime ) { $ this -> logInfo ( 'Session expired.' ) ; } return $ this -> wrappedStorage -> clear ( ) ; }
Clear all session data in memory .
9,843
protected function getFileRecord ( $ file ) { $ result = null ; $ segment = implode ( '/' , [ DIRNAME_GEOLOCATION , $ this -> geolocator -> getGeolocatorHandle ( ) , $ file ] ) ; $ fileLocator = $ this -> app -> make ( FileLocator :: class ) ; $ package = $ this -> geolocator -> getGeolocatorPackage ( ) ; if ( $ package !== null ) { $ fileLocator -> addPackageLocation ( $ package -> getPackageHandle ( ) ) ; } return $ fileLocator -> getRecord ( $ segment ) ; }
Get the path to a geolocator file .
9,844
protected function getCaches ( ) { foreach ( $ this -> caches as $ key => $ cache ) { if ( ! $ cache instanceof FlushableInterface ) { $ cache = $ this -> application -> make ( $ cache ) ; } if ( $ cache instanceof FlushableInterface ) { yield $ key => $ cache ; } } }
A generator that populates the cache objects from the container
9,845
protected function clearCacheDirectory ( $ directory ) { foreach ( $ this -> filesToClear ( $ directory ) as $ file ) { if ( $ file -> isDir ( ) ) { $ this -> filesystem -> deleteDirectory ( $ file -> getPathname ( ) ) ; } else { $ this -> filesystem -> delete ( $ file -> getPathname ( ) ) ; } } }
Clear out items from the cache directory
9,846
public function getPlaceHolderText ( $ handle ) { $ pageValues = $ this -> getAvailablePageValues ( ) ; if ( in_array ( $ handle , array_keys ( $ pageValues ) ) ) { $ placeHolder = $ pageValues [ $ handle ] ; } else { $ attributeKey = CollectionAttributeKey :: getByHandle ( $ handle ) ; if ( is_object ( $ attributeKey ) ) { $ placeHolder = $ attributeKey -> getAttributeKeyName ( ) ; } } return "[" . $ placeHolder . "]" ; }
Returns a place holder for pages that are new or when editing default page types .
9,847
public function alphanum ( $ value , $ allowSpaces = false , $ allowDashes = false ) { $ allowedCharsRegex = 'A-Za-z0-9' ; if ( $ allowSpaces ) { $ allowedCharsRegex .= ' ' ; } if ( $ allowDashes ) { $ allowedCharsRegex .= '\-' ; } return $ this -> notempty ( $ value ) && ! preg_match ( '/[^' . $ allowedCharsRegex . ']/' , $ value ) ; }
Returns true on whether the passed string is completely alpha - numeric if the value is not a string or is an empty string false will be returned .
9,848
public function min ( $ str , $ length ) { return $ this -> notempty ( $ str ) && strlen ( trim ( $ str ) ) >= $ length ; }
Returns true on whether the passed string is larger or equal to the passed length .
9,849
public function max ( $ str , $ length ) { return $ this -> notempty ( $ str ) && strlen ( trim ( $ str ) ) <= $ length ; }
Returns true on whether the passed is smaller or equal to the passed length .
9,850
public function setInstalledPackages ( array $ installedPackages ) { $ dictionary = [ ] ; foreach ( $ installedPackages as $ installedPackage ) { $ dictionary [ $ installedPackage -> getPackageHandle ( ) ] = $ installedPackage ; } $ this -> installedPackages = $ dictionary ; return $ this ; }
Set the list of installed packages .
9,851
protected function getInstalledPackages ( ) { if ( $ this -> installedPackages === null ) { $ installedPackages = [ ] ; $ packageService = $ this -> application -> make ( PackageService :: class ) ; foreach ( $ packageService -> getInstalledHandles ( ) as $ packageHandle ) { $ installedPackages [ $ packageHandle ] = $ packageService -> getClass ( $ packageHandle ) ; } $ this -> installedPackages = $ installedPackages ; } return $ this -> installedPackages ; }
Get the list of installed packages .
9,852
protected function getPackageRequirementsForPackage ( Package $ package , Package $ otherPackage ) { $ dependencies = $ package -> getPackageDependencies ( ) ; $ otherPackageHandle = $ otherPackage -> getPackageHandle ( ) ; return isset ( $ dependencies [ $ otherPackageHandle ] ) ? $ dependencies [ $ otherPackageHandle ] : null ; }
Get the requirements for a package in respect to another package .
9,853
public function getAreaLayoutColumnOffsetEditClass ( ) { $ gf = $ this -> arLayout -> getThemeGridFrameworkObject ( ) ; if ( is_object ( $ gf ) ) { $ class = $ gf -> getPageThemeGridFrameworkColumnAdditionalClasses ( ) ; if ( $ class ) { $ class .= ' ' ; } $ class .= $ gf -> getPageThemeGridFrameworkColumnClassForSpan ( $ this -> arLayoutColumnOffset ) ; return $ class ; } }
this returns offsets in the form of spans .
9,854
protected function getInstaller ( ) { if ( $ this -> installer === null ) { $ this -> installer = $ this -> app -> make ( Installer :: class ) ; } return $ this -> installer ; }
Get the installer instance .
9,855
public function load ( $ environment , $ group , $ namespace = null ) { $ result = array ( ) ; $ db = Database :: getActiveConnection ( ) ; $ query = $ db -> createQueryBuilder ( ) ; $ query -> select ( 'configValue' , 'configItem' ) -> from ( 'Config' , 'c' ) -> where ( 'configGroup = ?' ) -> setParameter ( 0 , $ group ) ; if ( $ namespace ) { $ query -> andWhere ( 'configNamespace = ?' ) -> setParameter ( 1 , $ namespace ) ; } else { $ query -> andWhere ( 'configNamespace = ? OR configNamespace IS NULL' ) -> setParameter ( 1 , '' ) ; } $ results = $ query -> execute ( ) ; while ( $ row = $ results -> fetch ( ) ) { array_set ( $ result , $ row [ 'configItem' ] , $ row [ 'configValue' ] ) ; } return $ result ; }
Load the given configuration group . Because it s the database we ignore the environment .
9,856
public function getNamespaces ( ) { $ db = Database :: getActiveConnection ( ) ; $ results = $ db -> createQueryBuilder ( ) -> select ( 'configNamespace' ) -> from ( 'Config' , 'c' ) -> where ( 'configNamespace != ""' ) -> groupBy ( 'configNamespace' ) -> execute ( ) ; return array_map ( 'array_shift' , $ results -> fetchAll ( ) ) ; }
Returns all registered namespaces with the config loader .
9,857
public function boot ( ) { $ app = $ this -> app ; Facade :: setFacadeApplication ( $ app ) ; require_once DIR_BASE_CORE . '/bootstrap/paths.php' ; $ this -> initializeEnvironmentDetection ( $ app ) ; $ config = $ this -> initializeConfig ( $ app ) ; $ this -> setupErrorReporting ( $ config ) ; $ this -> initializeLocalization ( $ app ) ; require DIR_BASE_CORE . '/bootstrap/paths_configured.php' ; $ this -> initializeClassAliases ( $ config ) ; $ this -> initializeLegacyDefinitions ( $ config , $ app ) ; $ this -> initializeServiceProviders ( $ app , $ config ) ; $ app -> setupFilesystem ( ) ; $ this -> initializeAssets ( $ config ) ; $ this -> initializeRoutes ( $ config ) ; $ this -> initializeFileTypes ( $ config ) ; if ( ! $ this -> app -> isRunThroughCommandLineInterface ( ) ) { return $ this -> bootHttpSapi ( $ config , $ app ) ; } }
Boot up Return a response if we re ready to output .
9,858
private function initializeConfig ( Application $ app ) { $ config_provider = $ app -> make ( 'Concrete\Core\Config\ConfigServiceProvider' ) ; $ config_provider -> register ( ) ; $ config = $ app -> make ( 'config' ) ; return $ config ; }
Enable configuration .
9,859
private function setupErrorReporting ( Repository $ config ) { $ error_reporting = $ config -> get ( 'concrete.debug.error_reporting' ) ; if ( ( string ) $ error_reporting !== '' ) { error_reporting ( ( int ) $ error_reporting ) ; } }
Setup the configured error reporting .
9,860
private function validateDatabaseDetails ( $ environment ) { $ db_config = [ ] ; $ configFile = DIR_CONFIG_SITE . '/database.php' ; $ environmentConfig = DIR_CONFIG_SITE . "/{$environment}.database.php" ; if ( file_exists ( $ configFile ) ) { $ db_config = include DIR_CONFIG_SITE . '/database.php' ; } if ( file_exists ( $ environmentConfig ) ) { $ db_config = array_merge ( $ db_config , include $ environmentConfig ) ; } $ defaultConnection = array_get ( $ db_config , 'default-connection' ) ; $ connection = array_get ( $ db_config , "connections.{$defaultConnection}" ) ; return $ defaultConnection && $ connection && array_get ( $ connection , 'database' ) && array_get ( $ connection , 'username' ) && array_get ( $ connection , 'server' ) ; }
Check whether an environment has well formed database credentials defined
9,861
private function checkInstall ( Application $ app , Request $ request ) { if ( ! $ app -> isInstalled ( ) ) { if ( ! $ request -> matches ( '/install/*' ) && $ request -> getPath ( ) != '/install' && ! $ request -> matches ( '/ccm/assets/localization/*' ) ) { $ manager = $ app -> make ( 'Concrete\Core\Url\Resolver\Manager\ResolverManager' ) ; $ response = new RedirectResponse ( $ manager -> resolve ( [ 'install' ] ) ) ; return $ response ; } } }
If we haven t installed and we re not looking at the install directory redirect .
9,862
public function getGatheringItemTemplateSlotWidth ( GatheringItem $ item ) { if ( $ this -> getGatheringItemTemplateFixedSlotWidth ( ) ) { return $ this -> getGatheringItemTemplateFixedSlotWidth ( ) ; } $ w = 0 ; $ handles = $ this -> getGatheringItemTemplateFeatureHandles ( ) ; $ assignments = \ Concrete \ Core \ Feature \ Assignment \ GatheringItemAssignment :: getList ( $ item ) ; foreach ( $ assignments as $ as ) { if ( in_array ( $ as -> getFeatureDetailHandle ( ) , $ handles ) ) { $ fd = $ as -> getFeatureDetailObject ( ) ; if ( $ fd -> getGatheringItemSuggestedSlotWidth ( ) > 0 && $ fd -> getGatheringItemSuggestedSlotWidth ( ) > $ w ) { $ w = $ fd -> getGatheringItemSuggestedSlotWidth ( ) ; } } } if ( $ w ) { return $ w ; } $ wb = $ this -> getGatheringItemTemplateMinimumSlotWidth ( $ item ) ; $ wt = $ this -> getGatheringItemTemplateMaximumSlotWidth ( $ item ) ; return mt_rand ( $ wb , $ wt ) ; }
This method is called by GatheringItem when setting defaults .
9,863
public function clearNamespace ( $ namespace ) { $ paths = $ this -> getNamespaceDefaultPaths ( $ namespace ) ; foreach ( $ paths as $ path ) { if ( $ this -> files -> isDirectory ( $ path ) ) { $ this -> files -> deleteDirectory ( $ path ) ; } } }
Clear groups in a namespace .
9,864
private function projectList ( UserList $ list ) { $ statement = $ list -> deliverQueryObject ( ) -> execute ( ) ; foreach ( $ statement as $ result ) { $ user = $ list -> getResult ( $ result ) ; yield iterator_to_array ( $ this -> projectUser ( $ user ) ) ; } }
A generator that takes a UserList and converts it to CSV rows
9,865
private function projectUser ( UserInfo $ user ) { yield $ user -> getUserName ( ) ; yield $ user -> getUserEmail ( ) ; $ userRegistrationDate = $ user -> getUserDateAdded ( ) ; yield $ this -> date -> formatCustom ( \ DateTime :: ATOM , $ userRegistrationDate ) ; list ( $ active , $ inactive ) = $ this -> getTranslatedStatus ( ) ; yield $ user -> isActive ( ) ? $ active : $ inactive ; yield $ user -> getNumLogins ( ) ; $ attributes = $ this -> getAttributeKeys ( ) ; foreach ( $ attributes as $ attribute ) { $ value = $ user -> getAttributeValueObject ( $ attribute ) ; yield $ value ? $ value -> getPlainTextValue ( ) : '' ; } }
Turn a user into an array
9,866
private function getAttributeKeys ( ) { if ( ! isset ( $ this -> attributeKeys ) ) { $ this -> attributeKeys = $ this -> category -> getList ( ) ; } return $ this -> attributeKeys ; }
Memoize the attribute keys so that we aren t looking them up over and over
9,867
private function getTranslatedStatus ( ) { if ( $ this -> status === null ) { $ this -> status = [ t ( 'Active' ) , t ( 'Inactive' ) ] ; } return $ this -> status ; }
Get the translated status texts
9,868
public function report ( $ content , $ author , $ email , $ ip , $ ua , $ additionalArgs = array ( ) ) { $ args [ 'content' ] = $ content ; $ args [ 'author' ] = $ author ; $ args [ 'author_email' ] = $ email ; $ args [ 'ip_address' ] = $ ip ; $ args [ 'user_agent' ] = $ ua ; foreach ( $ additionalArgs as $ key => $ value ) { $ args [ $ key ] = $ value ; } if ( method_exists ( $ this -> controller , 'report' ) ) { $ this -> controller -> report ( $ args ) ; } $ u = new User ( ) ; \ Log :: info ( t ( 'Content %s (author %s, %s) flagged as spam by user %s' , $ content , $ author , $ email , $ u -> getUserName ( ) ) ) ; }
Report some content with the poster s information to the AntiSpam service .
9,869
public function run ( ) { $ console = $ this -> console ; $ this -> app -> instance ( 'console' , $ console ) ; $ this -> loadBootstrap ( ) ; $ this -> initializeSystemTimezone ( ) ; $ input = new ArgvInput ( ) ; if ( $ input -> getFirstArgument ( ) !== 'c5:update' ) { if ( $ this -> app -> isInstalled ( ) ) { $ this -> app -> setupPackageAutoloaders ( ) ; $ this -> app -> setupPackages ( ) ; } } if ( method_exists ( $ console , 'setupDefaultCommands' ) ) { $ console -> setupDefaultCommands ( ) ; } \ Events :: dispatch ( 'on_before_console_run' ) ; $ console -> run ( $ input ) ; \ Events :: dispatch ( 'on_after_console_run' ) ; }
Run the runtime .
9,870
protected function getConfiguredRule ( $ configuration , RuleInterface $ rule ) { $ configurationNormalized = str_replace ( array ( "\r\n" , "\r" ) , "\n" , ( string ) $ configuration ) ; $ rxSearch = '/' ; $ rxSearch .= '(^|\n)' ; $ commentsBefore = $ rule -> getCommentsBefore ( ) ; if ( $ commentsBefore !== '' ) { $ rxSearch .= '(\s*' . preg_quote ( $ commentsBefore , '/' ) . '\s*\n+)?' ; } $ rxSearch .= '\s*' . preg_replace ( "/\n\s*/" , "\\s*\\n\\s*" , preg_quote ( $ rule -> getCode ( ) , '/' ) ) . '\s*' ; $ commentsAfter = $ rule -> getCommentsAfter ( ) ; if ( $ commentsAfter !== '' ) { $ rxSearch .= '(\n\s*' . preg_quote ( $ commentsAfter , '/' ) . '\s*)?' ; } $ rxSearch .= '(\n|$)' ; $ rxSearch .= '/' ; return preg_match ( $ rxSearch , $ configurationNormalized , $ match ) ? $ match [ 0 ] : '' ; }
Gets the rule if present in a configuration .
9,871
public static function getByID ( $ cID , $ cvID = 'RECENT' ) { $ entity = self :: getLocaleFromHomePageID ( $ cID ) ; if ( $ entity ) { $ obj = parent :: getByID ( $ cID , $ cvID ) ; $ obj -> setLocale ( $ entity ) ; return $ obj ; } return false ; }
Returns an instance of MultilingualSection for the given page ID .
9,872
public static function getCurrentSection ( ) { static $ lang ; if ( ! isset ( $ lang ) ) { $ c = Page :: getCurrentPage ( ) ; if ( $ c instanceof Page ) { $ lang = self :: getBySectionOfSite ( $ c ) ; } } return $ lang ; }
Gets the MultilingualSection object for the current section of the site .
9,873
public function getTranslatedPageID ( $ page ) { $ ids = static :: getIDList ( ) ; if ( in_array ( $ page -> getCollectionID ( ) , $ ids ) ) { return $ this -> locale -> getSiteTree ( ) -> getSiteHomePageID ( ) ; } $ mpRelationID = self :: getMultilingualPageRelationID ( $ page -> getCollectionID ( ) ) ; if ( $ mpRelationID ) { $ cID = self :: getCollectionIDForLocale ( $ mpRelationID , $ this -> getLocale ( ) ) ; return $ cID ; } }
Receives a page in a different language tree and tries to return the corresponding page in the current language tree .
9,874
public function getSectionInterfaceTranslations ( $ untranslatedFirst = false ) { $ translations = new Translations ( ) ; $ translations -> setLanguage ( $ this -> getLocale ( ) ) ; $ translations -> setPluralForms ( $ this -> getNumberOfPluralForms ( ) , $ this -> getPluralsRule ( ) ) ; $ db = \ Database :: get ( ) ; $ r = $ db -> query ( "select * from MultilingualTranslations where mtSectionID = ? order by " . ( $ untranslatedFirst ? "if(ifnull(msgstr, '') = '', 0, 1), " : "" ) . "mtID" , [ $ this -> getCollectionID ( ) ] ) ; while ( $ row = $ r -> fetch ( ) ) { $ t = Translation :: getByRow ( $ row ) ; if ( isset ( $ t ) ) { $ translations [ ] = $ t ; } } return $ translations ; }
Loads the translations of this multilingual section .
9,875
public function generatePageList ( ) { $ this -> now = new DateTime ( ) ; $ siteTreeIDList = array_merge ( [ 0 ] , $ this -> getSiteTreesIDList ( ) ) ; $ connection = $ this -> getConnection ( ) ; $ rs = $ connection -> executeQuery ( 'select cID from Pages where siteTreeID is null or siteTreeID in (' . implode ( ', ' , $ siteTreeIDList ) . ')' ) ; while ( ( $ cID = $ rs -> fetchColumn ( ) ) !== false ) { $ page = Page :: getByID ( $ cID , 'ACTIVE' ) ; if ( $ page && $ this -> canIncludePageInSitemap ( $ page ) ) { yield $ page ; } } }
Generate the list of pages that should be included in the sitemap .
9,876
public function isMultilingualEnabled ( ) { if ( $ this -> isMultilingualEnabled === null ) { $ this -> isMultilingualEnabled = count ( $ this -> getMultilingualSections ( ) ) > 1 ; } return $ this -> isMultilingualEnabled ; }
Check if the current site has more than one multilingual section .
9,877
public function getMultilingualSections ( ) { if ( $ this -> multilingualSections === null ) { $ site = $ this -> getSite ( ) ; if ( $ site === null ) { $ this -> multilingualSections = [ ] ; } else { $ list = [ ] ; foreach ( MultilingualSection :: getList ( $ site ) as $ section ) { $ list [ $ section -> getCollectionID ( ) ] = $ section ; } $ this -> multilingualSections = $ list ; } } return $ this -> multilingualSections ; }
Get the list of multilingual sections defined for the current site .
9,878
public function canIncludePageInSitemap ( Page $ page ) { $ result = false ; if ( $ this -> isPageStandard ( $ page ) ) { if ( $ this -> isPagePublished ( $ page ) ) { if ( ! $ this -> isPageExcludedFromSitemap ( $ page ) ) { if ( $ this -> isPageAccessible ( $ page ) ) { $ result = true ; } } } } return $ result ; }
Should a page be included in the sitemap?
9,879
public function getSite ( ) { if ( $ this -> site === false ) { $ this -> site = $ this -> app -> make ( 'site' ) -> getDefault ( ) ; } return $ this -> site ; }
Get the currently used site .
9,880
public function setSite ( Site $ site ) { if ( $ this -> site !== $ site ) { $ this -> site = $ site ; $ this -> multilingualSections = null ; $ this -> isMultilingualEnabled = null ; } return $ this ; }
Set the currently used site .
9,881
public function swapContent ( Package $ package , $ options ) { if ( $ this -> validateClearSiteContents ( $ options ) ) { \ Core :: make ( 'cache/request' ) -> disable ( ) ; $ pl = new PageList ( ) ; $ pages = $ pl -> getResults ( ) ; foreach ( $ pages as $ c ) { $ c -> delete ( ) ; } $ fl = new FileList ( ) ; $ files = $ fl -> getResults ( ) ; foreach ( $ files as $ f ) { $ f -> delete ( ) ; } $ sl = new StackList ( ) ; foreach ( $ sl -> get ( ) as $ c ) { $ c -> delete ( ) ; } $ home = \ Page :: getByID ( \ Page :: getHomePageID ( ) ) ; $ blocks = $ home -> getBlocks ( ) ; foreach ( $ blocks as $ b ) { $ b -> deleteBlock ( ) ; } $ pageTypes = Type :: getList ( ) ; foreach ( $ pageTypes as $ ct ) { $ ct -> delete ( ) ; } $ home = Page :: getByID ( \ Page :: getHomePageID ( ) ) ; $ home -> setPageType ( null ) ; if ( is_dir ( $ package -> getPackagePath ( ) . '/content_files' ) ) { $ ch = new ContentImporter ( ) ; $ computeThumbnails = true ; if ( $ package -> contentProvidesFileThumbnails ( ) ) { $ computeThumbnails = false ; } $ ch -> importFiles ( $ package -> getPackagePath ( ) . '/content_files' , $ computeThumbnails ) ; } $ ci = new ContentImporter ( ) ; $ ci -> importContentFile ( $ package -> getPackagePath ( ) . '/content.xml' ) ; \ Core :: make ( 'cache/request' ) -> enable ( ) ; } }
Removes any existing pages files stacks block and page types and installs content from the package .
9,882
protected function resolveMethods ( ) { $ methods = $ this -> reflectionClass -> getMethods ( ) ; if ( $ this -> isFacade ( ) ) { $ methods = array_merge ( $ methods , $ this -> getFacadeReflectionClass ( ) -> getMethods ( ) ) ; } foreach ( $ methods as $ method ) { $ this -> methods [ ] = new MethodSymbol ( $ this , $ method ) ; } }
Get the methods .
9,883
public function render ( $ eol = "\n" , $ padding = ' ' , $ methodFilter = null ) { $ rendered = '' ; $ comment = $ this -> comment ; if ( $ comment !== false ) { $ comment = trim ( $ comment ) ; if ( $ comment !== '' ) { $ rendered .= str_replace ( $ eol . '*' , $ eol . ' *' , implode ( $ eol , array_map ( 'trim' , explode ( "\n" , $ comment ) ) ) ) . $ eol ; } } if ( $ this -> reflectionClass -> isAbstract ( ) ) { $ rendered .= 'abstract ' ; } $ rendered .= 'class ' . $ this -> aliasBasename . ' extends \\' . $ this -> fqn . "{$eol}{{$eol}" ; $ firstMethod = true ; foreach ( $ this -> methods as $ method ) { if ( is_callable ( $ methodFilter ) && ( call_user_func ( $ methodFilter , $ this , $ method ) === false ) ) { continue ; } if ( $ firstMethod ) { $ firstMethod = false ; if ( $ this -> isFacade ( ) ) { $ rendered .= $ padding . '/**' . $ eol . $ padding . ' * @var ' . $ this -> fqn . $ eol . $ padding . ' */' . $ eol ; $ rendered .= $ padding . 'protected static $instance;' . $ eol ; } } $ rendered_method = $ method -> render ( $ eol , $ padding ) ; if ( $ rendered_method !== '' ) { $ rendered .= $ padding . rtrim ( str_replace ( $ eol , $ eol . $ padding , $ rendered_method ) ) . $ eol ; } } $ rendered .= "}{$eol}" ; return $ rendered ; }
Render Class with methods .
9,884
public function getCompatibleTimezones ( ) { $ validTimezones = [ ] ; foreach ( $ this -> dateHelper -> getTimezones ( ) as $ timezoneID => $ timezoneName ) { if ( $ this -> getDeltaTimezone ( $ timezoneID ) === null ) { $ validTimezones [ $ timezoneID ] = $ timezoneName ; } } return $ validTimezones ; }
Get a list of time zones that are compatible with the database .
9,885
public function getDeltaTimezone ( $ phpTimezone ) { if ( ! ( $ phpTimezone instanceof DateTimeZone ) ) { $ phpTimezone = new DateTimeZone ( $ phpTimezone ) ; } $ data = $ this -> getDatabaseTimestamps ( ) ; extract ( $ data ) ; $ sometimesSame = false ; $ maxDeltaMinutes = 0 ; foreach ( $ timestamps as $ index => $ timestamp ) { $ databaseValue = new DateTime ( $ databaseDatetimes [ $ index ] , $ phpTimezone ) ; $ phpValue = DateTime :: createFromFormat ( 'U' , $ timestamp , $ phpTimezone ) ; $ deltaMinutes = ( int ) floor ( ( $ phpValue -> getTimestamp ( ) - $ databaseValue -> getTimestamp ( ) ) / 60 ) ; if ( $ deltaMinutes === 0 ) { $ sometimesSame = true ; } else { if ( abs ( $ deltaMinutes ) > abs ( $ maxDeltaMinutes ) ) { $ maxDeltaMinutes = $ deltaMinutes ; } } } if ( $ maxDeltaMinutes === 0 ) { return null ; } else { return [ 'dstProblems' => $ sometimesSame , 'maxDeltaMinutes' => $ maxDeltaMinutes , ] ; } }
Check if a PHP time zone is compatible with the database timezone .
9,886
public function getItemsPerPageSession ( ) { $ variable = 'search/' . $ this -> getSessionNamespace ( ) . '/items_per_page' ; if ( $ this -> session -> has ( $ variable ) ) { return ( int ) $ this -> session -> get ( $ variable ) ; } return null ; }
Retrieve the items per page option from the session .
9,887
private function attemptBuild ( File $ file , array $ thumbnail ) { try { if ( $ this -> isBuilt ( $ file , $ thumbnail ) ) { return true ; } if ( $ dimensions = $ this -> getDimensions ( $ thumbnail ) ) { list ( $ width , $ height , $ crop ) = $ dimensions ; $ type = new CustomThumbnail ( $ width , $ height , $ thumbnail [ 'path' ] , $ crop ) ; $ fv = $ file -> getVersion ( $ thumbnail [ 'fileVersionID' ] ) ; if ( $ fv -> getTypeObject ( ) -> supportsThumbnails ( ) ) { $ fv -> generateThumbnail ( $ type ) ; $ fv -> releaseImagineImage ( ) ; } } elseif ( $ type = Version :: getByHandle ( $ thumbnail [ 'thumbnailTypeHandle' ] ) ) { $ fv = $ file -> getVersion ( $ thumbnail [ 'fileVersionID' ] ) ; if ( $ fv -> getTypeObject ( ) -> supportsThumbnails ( ) ) { $ fv -> generateThumbnail ( $ type ) ; $ fv -> releaseImagineImage ( ) ; } } } catch ( \ Exception $ e ) { return false ; } return $ this -> isBuilt ( $ file , $ thumbnail ) ; }
Try building an unbuilt thumbnail .
9,888
private function getDimensions ( $ thumbnail ) { $ matches = null ; if ( preg_match ( '/^ccm_(\d+)x(\d+)(?:_([10]))?$/' , $ thumbnail [ 'thumbnailTypeHandle' ] , $ matches ) ) { return array_pad ( array_slice ( $ matches , 1 ) , 3 , 0 ) ; } }
Get the dimensions out of a thumbnail array .
9,889
protected function selectNearestValue ( array $ values , $ wantedValue ) { if ( in_array ( $ wantedValue , $ values ) ) { $ result = $ wantedValue ; } else { $ result = null ; $ minDelta = PHP_INT_MAX ; foreach ( $ values as $ value ) { $ delta = abs ( $ value - $ wantedValue ) ; if ( $ delta < $ minDelta ) { $ minDelta = $ delta ; $ result = $ value ; } } } return $ result ; }
Choose an array value nearest to a specified value . Useful when we work with time resolutions .
9,890
public function getNewUsernameFromUserDetails ( $ email , $ suggestedUsername = '' , $ firstName = '' , $ lastName = '' ) { $ baseUsername = $ this -> stringToUsernameChunk ( $ suggestedUsername ) ; if ( $ baseUsername === '' ) { $ firstName = $ this -> stringToUsernameChunk ( $ firstName ) ; $ lastName = $ this -> stringToUsernameChunk ( $ lastName ) ; if ( $ firstName !== '' || $ lastName !== '' ) { $ baseUsername = trim ( $ firstName . '_' . $ lastName , '_' ) ; } else { $ mailbox = strstr ( ( string ) $ email , '@' , true ) ; $ baseUsername = $ this -> stringToUsernameChunk ( $ mailbox ) ; } if ( $ baseUsername === '' ) { $ baseUsername = 'user' ; } } $ username = $ baseUsername ; $ suffix = 1 ; while ( $ this -> userInfoRepository -> getByName ( $ username ) !== null ) { $ username = $ baseUsername . '_' . $ suffix ; ++ $ suffix ; } return $ username ; }
Create an unused username starting from user details .
9,891
public function getIndexes ( $ type , $ includeGlobal = true ) { if ( isset ( $ this -> indexes [ $ type ] ) ) { foreach ( $ this -> indexes [ $ type ] as $ index ) { yield $ type => $ this -> inflateIndex ( $ index ) ; } } $ all = self :: TYPE_ALL ; if ( $ type !== $ all && $ includeGlobal ) { if ( isset ( $ this -> indexes [ $ all ] ) ) { foreach ( $ this -> indexes [ $ all ] as $ key => $ index ) { yield $ all => $ this -> inflateIndex ( $ index ) ; } } } }
Get the indexes for a type
9,892
protected function inflateIndex ( $ class ) { if ( $ class instanceof IndexInterface ) { return $ class ; } if ( ! isset ( $ this -> inflated [ $ class ] ) ) { $ this -> inflated [ $ class ] = $ this -> app -> make ( $ class ) ; } return $ this -> inflated [ $ class ] ; }
Get the proper index from the stored value
9,893
public function getAllIndexes ( ) { foreach ( $ this -> indexes as $ type => $ indexList ) { if ( $ type == self :: TYPE_ALL ) { continue ; } foreach ( $ this -> getIndexes ( $ type , false ) as $ index ) { yield $ type => $ index ; } } foreach ( $ this -> getIndexes ( self :: TYPE_ALL ) as $ index ) { yield self :: TYPE_ALL => $ index ; } }
Get all indexes registered against this manager
9,894
public function addIndex ( $ type , $ index ) { if ( ! isset ( $ this -> indexes [ $ type ] ) ) { $ this -> indexes [ $ type ] = [ ] ; } $ this -> indexes [ $ type ] [ ] = $ index ; }
Add an index to this manager
9,895
public function index ( $ type , $ object ) { foreach ( $ this -> getIndexes ( $ type ) as $ index ) { $ index -> index ( $ object ) ; } }
Index an object
9,896
public function forget ( $ type , $ object ) { foreach ( $ this -> getIndexes ( $ type ) as $ index ) { $ index -> forget ( $ object ) ; } }
Forget an object
9,897
private function deleteFormAnswers ( $ qsID ) { $ db = Loader :: db ( ) ; $ v = [ intval ( $ qsID ) ] ; $ q = 'SELECT asID FROM btFormAnswerSet WHERE questionSetId = ?' ; $ r = $ db -> query ( $ q , $ v ) ; while ( $ row = $ r -> fetchRow ( ) ) { $ asID = $ row [ 'asID' ] ; $ this -> deleteAnswers ( $ asID ) ; } }
DELETE A FORM ANSWERS
9,898
private function deleteForm ( $ bID , $ qsID ) { $ db = Loader :: db ( ) ; $ this -> deleteFormAnswers ( $ qsID ) ; $ v = [ intval ( $ bID ) ] ; $ q = 'DELETE FROM btFormQuestions WHERE bID = ?' ; $ r = $ db -> query ( $ q , $ v ) ; $ q = 'DELETE FROM btForm WHERE bID = ?' ; $ r = $ db -> query ( $ q , $ v ) ; $ q = 'DELETE FROM Blocks WHERE bID = ?' ; $ r = $ db -> query ( $ q , $ v ) ; }
DELETE FORMS AND ALL SUBMISSIONS
9,899
private function viewRequiresJqueryUI ( ) { $ whereInputTypes = "inputType = 'date' OR inputType = 'datetime'" ; $ sql = "SELECT COUNT(*) FROM {$this->btQuestionsTablename} WHERE questionSetID = ? AND bID = ? AND ({$whereInputTypes})" ; $ vals = [ intval ( $ this -> questionSetId ) , intval ( $ this -> bID ) ] ; $ JQUIFieldCount = Database :: connection ( ) -> GetOne ( $ sql , $ vals ) ; return ( bool ) $ JQUIFieldCount ; }
Internal helper function .