idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
10,000
public function create ( ) { $ this -> add ( ) ; $ this -> validateIntegrationRequest ( ) ; if ( ! $ this -> token -> validate ( 'create' ) ) { $ this -> error -> add ( $ this -> token -> getErrorMessage ( ) ) ; } if ( $ this -> error -> has ( ) ) { return ; } $ factory = $ this -> app -> make ( ClientFactory :: class ) ; $ credentials = $ factory -> generateCredentials ( ) ; $ client = $ factory -> createClient ( $ this -> request -> request -> get ( 'name' ) , $ this -> request -> request -> get ( 'redirect' ) , [ ] , $ credentials -> getKey ( ) , password_hash ( $ credentials -> getSecret ( ) , PASSWORD_DEFAULT ) ) ; $ this -> entityManager -> persist ( $ client ) ; $ this -> entityManager -> flush ( ) ; $ this -> flash ( 'success' , t ( 'Integration saved successfully.' ) ) ; $ this -> flash ( 'clientSecret' , $ credentials -> getSecret ( ) ) ; return $ this -> redirect ( '/dashboard/system/api/integrations/' , 'view_client' , $ client -> getIdentifier ( ) ) ; }
Request handler to create new client objects
10,001
public function getString ( ) { $ html = '' ; if ( $ this -> error -> has ( ) ) { $ html .= '<ul class="ccm-error">' ; foreach ( $ this -> error -> getList ( ) as $ error ) { $ html .= '<li>' ; if ( $ error instanceof HtmlAwareErrorInterface && $ error -> messageContainsHtml ( ) ) { $ html .= ( string ) $ error ; } else { $ html .= nl2br ( h ( ( string ) $ error ) ) ; } $ html .= '</li>' ; } $ html .= '</ul>' ; } return $ html ; }
Build an HTML - formatted string describing the errors .
10,002
public function view ( $ strStatus = false ) { $ config = $ this -> app -> make ( 'config' ) ; $ strStatus = ( string ) $ strStatus ; $ intLogErrors = $ config -> get ( 'concrete.log.errors' ) == 1 ? 1 : 0 ; $ intLogEmails = $ config -> get ( 'concrete.log.emails' ) == 1 ? 1 : 0 ; $ this -> set ( 'fh' , Loader :: helper ( 'form' ) ) ; $ this -> set ( 'intLogErrors' , $ intLogErrors ) ; $ this -> set ( 'intLogEmails' , $ intLogEmails ) ; if ( $ strStatus == 'logging_saved' ) { $ this -> set ( 'message' , t ( 'Logging configuration saved.' ) ) ; } $ levels = [ 'DEBUG' => t ( 'Debug' ) , 'INFO' => t ( 'Info' ) , 'NOTICE' => t ( 'Notice' ) , 'WARNING' => t ( 'Warning' ) , 'ERROR' => t ( 'Error' ) , 'CRITICAL' => t ( 'Critical' ) , 'ALERT' => t ( 'Alert' ) , 'EMERGENCY' => t ( 'Emergency' ) , ] ; $ handlers = [ 'database' => t ( 'Database' ) , 'file' => t ( 'File' ) , ] ; $ this -> set ( 'enableDashboardReport' , ! ! $ config -> get ( 'concrete.log.enable_dashboard_report' ) ) ; $ this -> set ( 'levels' , $ levels ) ; $ this -> set ( 'handlers' , $ handlers ) ; $ this -> set ( 'loggingMode' , $ config -> get ( 'concrete.log.configuration.mode' ) ) ; $ this -> set ( 'coreLoggingLevel' , $ config -> get ( 'concrete.log.configuration.simple.core_logging_level' ) ) ; $ this -> set ( 'handler' , $ config -> get ( 'concrete.log.configuration.simple.handler' ) ) ; $ this -> set ( 'logFile' , $ config -> get ( 'concrete.log.configuration.simple.file.file' ) ) ; }
Dasboard page view .
10,003
public function update_logging ( ) { $ config = $ this -> app -> make ( 'config' ) ; if ( ! $ this -> token -> validate ( 'update_logging' ) ) { $ this -> error -> add ( $ this -> token -> getErrorMessage ( ) ) ; } if ( $ this -> request -> request -> get ( 'handler' ) == 'file' && $ this -> request -> request -> get ( 'logging_mode' ) ) { $ logFile = $ this -> request -> request -> get ( 'logFile' ) ; $ filesystem = new Filesystem ( ) ; $ directory = dirname ( $ logFile ) ; if ( $ filesystem -> isFile ( $ logFile ) && ! $ filesystem -> isWritable ( $ logFile ) ) { $ this -> error -> add ( t ( 'Log file exists but is not writable by the web server.' ) ) ; } if ( ! $ filesystem -> isFile ( $ logFile ) && ( ! $ filesystem -> isDirectory ( $ directory ) || ! $ filesystem -> isWritable ( $ directory ) ) ) { $ this -> error -> add ( t ( 'Log file does not exist on the server. The directory of the file provided must exist and be writable on the web server.' ) ) ; } $ filename = basename ( $ logFile ) ; if ( ! $ filename || substr ( $ filename , - 4 ) != '.log' ) { $ this -> error -> add ( t ( 'The filename provided must be a valid filename and end with .log' ) ) ; } } if ( ! $ this -> error -> has ( ) ) { $ intLogErrorsPost = $ this -> post ( 'ENABLE_LOG_ERRORS' ) == 1 ? 1 : 0 ; $ intLogEmailsPost = $ this -> post ( 'ENABLE_LOG_EMAILS' ) == 1 ? 1 : 0 ; $ config -> save ( 'concrete.log.errors' , $ intLogErrorsPost ) ; $ config -> save ( 'concrete.log.emails' , $ intLogEmailsPost ) ; $ mode = $ this -> request -> request -> get ( 'logging_mode' ) ; if ( $ mode != 'advanced' ) { $ mode = 'simple' ; $ config -> save ( 'concrete.log.configuration.simple.core_logging_level' , $ this -> request -> request -> get ( 'logging_level' ) ) ; $ config -> save ( 'concrete.log.configuration.simple.handler' , $ this -> request -> request -> get ( 'handler' ) ) ; $ config -> save ( 'concrete.log.configuration.simple.file.file' , $ this -> request -> request -> get ( 'logFile' ) ) ; } $ config -> save ( 'concrete.log.enable_dashboard_report' , $ this -> request -> request -> get ( 'enable_dashboard_report' ) ? true : false ) ; $ config -> save ( 'concrete.log.configuration.mode' , $ mode ) ; $ this -> redirect ( '/dashboard/system/environment/logging' , 'logging_saved' ) ; } $ this -> view ( ) ; }
Updates logging settings .
10,004
public function createConnection ( ) { $ pdoCheck = $ this -> application -> make ( PdoMysqlExtension :: class ) -> performCheck ( ) ; if ( $ pdoCheck -> getState ( ) !== PreconditionResult :: STATE_PASSED ) { throw new UserMessageException ( $ pdoCheck -> getMessage ( ) ) ; } $ databaseConfiguration = $ this -> getDefaultConnectionConfiguration ( ) ; if ( $ databaseConfiguration === null ) { throw new UserMessageException ( t ( 'The configuration is missing the required database connection parameters.' ) ) ; } $ databaseManager = $ this -> application -> make ( DatabaseManager :: class ) ; try { $ connection = $ databaseManager -> getFactory ( ) -> createConnection ( $ databaseConfiguration ) ; } catch ( Exception $ x ) { throw new UserMessageException ( $ x -> getMessage ( ) , $ x -> getCode ( ) , $ x ) ; } catch ( Throwable $ x ) { throw new UserMessageException ( $ x -> getMessage ( ) , $ x -> getCode ( ) ) ; } $ connection = $ this -> setPreferredCharsetCollation ( $ connection ) ; return $ connection ; }
Create a new Connection instance using the values specified in the options .
10,005
public function getStartingPoint ( $ fallbackToDefault ) { $ handle = $ this -> getOptions ( ) -> getStartingPointHandle ( ) ; if ( $ handle === '' ) { if ( ! $ fallbackToDefault ) { throw new UserMessageException ( t ( 'The starting point has not been defined.' ) ) ; } $ handle = static :: DEFAULT_STARTING_POINT ; } $ result = StartingPointPackage :: getClass ( $ handle ) ; if ( $ result === null ) { throw new UserMessageException ( t ( 'Invalid starting point: %s' , $ handle ) ) ; } $ result -> setInstallerOptions ( $ this -> getOptions ( ) ) ; return $ result ; }
Get the StartingPointPackage instance .
10,006
protected function getTranslationsStats ( Translations $ translations , DateTime $ defaultUpdatedOn ) { $ result = null ; foreach ( $ translations as $ translation ) { if ( $ translation -> hasTranslation ( ) ) { $ result = [ 'version' => '' , 'updatedOn' => $ defaultUpdatedOn , ] ; break ; } } if ( $ result !== null ) { $ h = $ translations -> getHeader ( 'Project-Id-Version' ) ; if ( $ h && preg_match ( '/\s([\S]*\d[\S]*)$/' , $ h , $ m ) ) { $ result [ 'version' ] = $ m [ 1 ] ; } $ h = $ translations -> getHeader ( 'PO-Revision-Date' ) ; if ( $ h ) { try { $ result [ 'updatedOn' ] = new DateTime ( $ h ) ; } catch ( Exception $ x ) { } catch ( Throwable $ x ) { } } } return $ result ; }
Get stats for a \ Gettext \ Translations instance .
10,007
protected function getMoFileStats ( $ moFile ) { if ( $ this -> fs -> isFile ( $ moFile ) ) { $ lastModifiedTimestamp = $ this -> fs -> lastModified ( $ moFile ) ; if ( $ this -> cache -> isEnabled ( ) ) { $ cacheItem = $ this -> cache -> getItem ( self :: CACHE_PREFIX . '/' . md5 ( $ moFile ) . '_' . $ lastModifiedTimestamp ) ; } else { $ cacheItem = null ; } if ( $ cacheItem === null || $ cacheItem -> isMiss ( ) ) { $ stats = $ this -> getTranslationsStats ( Translations :: fromMoFile ( $ moFile ) , new DateTime ( '@' . $ lastModifiedTimestamp ) ) ; if ( $ cacheItem !== null ) { $ cacheItem -> set ( $ stats ) -> expiresAfter ( self :: CACHE_DURATION ) -> save ( ) ; } } else { $ stats = $ cacheItem -> get ( ) ; } } else { $ stats = null ; } return new Stats ( 'mo' , $ moFile , ( $ stats === null ) ? '' : $ stats [ 'version' ] , ( $ stats === null ) ? null : $ stats [ 'updatedOn' ] ) ; }
Get stats for a gettext . mo file .
10,008
public function get ( $ itemsToGet = 100 , $ offset = 0 ) { $ userInfos = array ( ) ; $ this -> createQuery ( ) ; $ r = parent :: get ( $ itemsToGet , intval ( $ offset ) ) ; foreach ( $ r as $ row ) { $ ui = UserInfo :: getByID ( $ row [ 'uID' ] ) ; $ userInfos [ ] = $ ui ; } return $ userInfos ; }
Returns an array of userInfo objects based on current filter settings .
10,009
public function getUserIDs ( $ itemsToGet = 100 , $ offset = 0 ) { $ this -> createQuery ( ) ; $ userIDs = array ( ) ; $ r = parent :: get ( $ itemsToGet , intval ( $ offset ) ) ; foreach ( $ r as $ row ) { $ userIDs [ ] = $ row [ 'uID' ] ; } return $ userIDs ; }
Similar to get except it returns an array of userIDs . Much faster than getting a UserInfo object for each result if all you need is the user s id .
10,010
public function setIp ( $ ipAddress , $ isHex = false ) { if ( $ isHex ) { $ this -> ipHex = $ ipAddress ; } else { $ ipAddress = preg_replace ( '/\[(.*?)\].*/' , '$1' , $ ipAddress ) ; if ( strpos ( $ ipAddress , '.' ) !== false ) { $ ipAddress = preg_replace ( '/(.*?(?:\d{1,3}\.?){4}).*/' , "$1" , $ ipAddress ) ; } $ this -> ipHex = bin2hex ( inet_pton ( $ ipAddress ) ) ; } return $ this ; }
Sets the current IP Address .
10,011
public function getIp ( $ format = self :: FORMAT_HEX ) { if ( $ this -> ipHex === null ) { return null ; } elseif ( $ format === self :: FORMAT_HEX ) { return $ this -> ipHex ; } elseif ( $ format === self :: FORMAT_IP_STRING ) { return inet_ntop ( $ this -> hex2bin ( $ this -> ipHex ) ) ; } throw new \ Exception ( 'Invalid IP format' ) ; }
Returns the IPAddress string null if no ip address has been set .
10,012
public function isLoopBack ( ) { if ( ! $ this -> isIpSet ( ) ) { throw new \ Exception ( 'No IP Set' ) ; } if ( $ this -> isIPv4 ( ) && strpos ( $ this -> ipHex , '7f' ) === 0 ) { return true ; } elseif ( $ this -> ipHex === '00000000000000000000000000000001' || $ this -> ipHex === '00000000000000000000ffff7f000001' ) { return true ; } return false ; }
Used to check of the current IP is a loopback IP address .
10,013
public function isPrivate ( ) { if ( ! $ this -> isIpSet ( ) ) { throw new \ Exception ( 'No IP Set' ) ; } if ( ( $ this -> isIPv4 ( ) && ( strpos ( $ this -> ipHex , '0a' ) === 0 || strpos ( $ this -> ipHex , 'ac1' ) === 0 || strpos ( $ this -> ipHex , 'c0a8' ) === 0 ) ) || ( $ this -> isIPv6 ( ) && ( strpos ( $ this -> ipHex , 'fc' ) === 0 || strpos ( $ this -> ipHex , 'fd' ) === 0 || strpos ( $ this -> ipHex , 'ffff0a' ) === 20 || strpos ( $ this -> ipHex , 'ffffac1' ) === 20 || strpos ( $ this -> ipHex , 'ffffc0a8' ) === 20 ) ) ) { return true ; } return false ; }
Returns true if the IP address belongs to a private network false if it is not .
10,014
public function getWorkflowProgressCurrentStatusNum ( WorkflowProgress $ wp ) { $ req = $ wp -> getWorkflowRequestObject ( ) ; if ( is_object ( $ req ) ) { return $ req -> getWorkflowRequestStatusNum ( ) ; } }
we do this so that we can order things by most important etc ...
10,015
public function before ( DateTime $ before , $ user = null , $ count = false ) { $ before = $ this -> validateTimezone ( $ before ) ; $ user = $ this -> validateUser ( $ user ) ; $ qb = $ this -> createQueryBuilder ( 'a' ) ; if ( $ count ) { $ qb -> select ( 'count(a)' ) ; } else { $ qb -> select ( ) ; } $ qb -> where ( 'a.utcDate < :before' ) -> setParameter ( 'before' , $ before ) ; if ( $ user ) { $ qb -> andWhere ( 'a.userId=:user' ) -> setParameter ( 'user' , $ user ) ; } if ( $ count ) { try { return $ qb -> getQuery ( ) -> getSingleScalarResult ( ) ; } catch ( UnexpectedResultException $ e ) { return 0 ; } } else { return $ qb -> getQuery ( ) -> iterate ( ) ; } }
Get a list of login attempts prior to a date
10,016
private function validateUser ( $ user , $ requireValue = false ) { if ( ! $ user && ! $ requireValue ) { return null ; } if ( $ user instanceof User || $ user instanceof UserInfo ) { return ( int ) $ user -> getUserID ( ) ; } if ( is_numeric ( $ user ) ) { return ( int ) $ user ; } throw new \ InvalidArgumentException ( 'Invalid user value passed, must be User instance or int' ) ; }
Validate a passed user value and resolve the ID
10,017
public function persistNewAuthCode ( AuthCodeEntityInterface $ authCodeEntity ) { $ this -> getEntityManager ( ) -> transactional ( function ( EntityManagerInterface $ entityManager ) use ( $ authCodeEntity ) { $ entityManager -> persist ( $ authCodeEntity ) ; } ) ; }
Persists a new auth code to permanent storage .
10,018
public function revokeAuthCode ( $ codeId ) { $ code = $ this -> find ( $ codeId ) ; if ( ! $ code ) { throw new \ InvalidArgumentException ( 'Invalid auth token code' ) ; } $ this -> getEntityManager ( ) -> transactional ( function ( EntityManagerInterface $ em ) use ( $ code ) { $ code = $ em -> merge ( $ code ) ; if ( $ code ) { $ em -> remove ( $ code ) ; } } ) ; }
Revoke an auth code .
10,019
public function getItemsPerPage ( ) { $ query = $ this -> getSessionCurrentQuery ( ) ; if ( $ query ) { return $ query -> getItemsPerPage ( ) ; } else { return $ this -> entity -> getItemsPerPage ( ) ; } }
Returns the number of items per page .
10,020
protected function getQueueId ( $ name ) { $ r = $ this -> db -> fetchColumn ( 'select queue_id from Queues where queue_name = ? limit 1' , [ $ name ] ) ; if ( $ r === false ) { throw new RuntimeException ( t ( 'Queue does not exist: %s' , $ name ) ) ; } $ count = ( int ) $ r ; return $ count ; }
Get the identifier of a queue given its name .
10,021
public static function encodePath ( $ path ) { if ( mb_strpos ( $ path , '/' ) !== false ) { $ path = explode ( '/' , $ path ) ; $ path = array_map ( 'rawurlencode' , $ path ) ; $ newPath = implode ( '/' , $ path ) ; } else { if ( is_null ( $ path ) ) { $ newPath = null ; } else { $ newPath = rawurlencode ( $ path ) ; } } $ path = str_replace ( '%21' , '!' , $ newPath ) ; return $ path ; }
URL - encodes collection path .
10,022
public function slugSafeString ( $ handle , $ maxlength = 128 ) { $ handle = preg_replace ( '/[^\\p{L}\\p{Nd}\-_]+/u' , ' ' , $ handle ) ; $ handle = preg_replace ( '/[-\s]+/' , '-' , $ handle ) ; return trim ( Utf8 :: substr ( $ handle , 0 , $ maxlength ) , '-' ) ; }
Remove unsafe characters for URL slug .
10,023
public function sanitize ( $ string , $ max_length = 0 , $ allowed = '' ) { $ text = trim ( strip_tags ( $ string , $ allowed ) ) ; if ( $ max_length > 0 ) { if ( function_exists ( 'mb_substr' ) ) { $ text = mb_substr ( $ text , 0 , $ max_length , APP_CHARSET ) ; } else { $ text = substr ( $ text , 0 , $ max_length ) ; } } if ( $ text == null ) { return "" ; } return $ text ; }
Strips tags and optionally reduces string to specified length .
10,024
public function makenice ( $ input ) { $ output = strip_tags ( $ input ) ; $ output = $ this -> autolink ( $ output ) ; $ output = nl2br ( $ output ) ; return $ output ; }
Runs a number of text functions including autolink nl2br strip_tags . Assumes that you want simple text comments but with a few niceties .
10,025
public function autolink ( $ input , $ newWindow = false , $ defaultProtocol = 'http://' ) { $ target = $ newWindow ? ' target="_blank"' : '' ; $ output = preg_replace_callback ( '/(http:\/\/|https:\/\/|(www\.))(([^\s<]{4,80})[^\s<]*)/' , function ( array $ matches ) use ( $ target , $ defaultProtocol ) { $ protocol = strpos ( $ matches [ 1 ] , ':' ) ? $ matches [ 1 ] : $ defaultProtocol ; return "<a href=\"{$protocol}{$matches[2]}{$matches[3]}\"{$target} rel=\"nofollow\">{$matches[2]}{$matches[4]}</a>" ; } , $ input ) ; return $ output ; }
Scans passed text and automatically hyperlinks any URL inside it .
10,026
public function handle ( $ handle , $ leaveSlashes = false ) { $ handle = $ this -> sanitizeFileSystem ( $ handle , $ leaveSlashes ) ; return str_replace ( '-' , '_' , $ handle ) ; }
Takes a string and turns it into a handle .
10,027
public function urlify ( $ handle , $ max_length = null , $ locale = '' , $ removeExcludedWords = true ) { if ( $ max_length === null ) { $ max_length = Config :: get ( 'concrete.seo.segment_max_length' ) ; } $ text = strtolower ( str_replace ( array ( "\r" , "\n" , "\t" ) , ' ' , $ this -> asciify ( $ handle , $ locale ) ) ) ; if ( $ removeExcludedWords ) { $ excludeSeoWords = Config :: get ( 'concrete.seo.exclude_words' ) ; if ( is_string ( $ excludeSeoWords ) ) { if ( strlen ( $ excludeSeoWords ) ) { $ remove_list = explode ( ',' , $ excludeSeoWords ) ; $ remove_list = array_map ( 'trim' , $ remove_list ) ; $ remove_list = array_filter ( $ remove_list , 'strlen' ) ; } else { $ remove_list = array ( ) ; } } else { $ remove_list = URLify :: $ remove_list ; } if ( count ( $ remove_list ) ) { $ text = preg_replace ( '/\b(' . implode ( '|' , $ remove_list ) . ')\b/i' , '' , $ text ) ; } } $ text = preg_replace ( '/[^-\w\s]/' , '' , $ text ) ; $ text = str_replace ( '_' , ' ' , $ text ) ; $ text = preg_replace ( '/^\s+|\s+$/' , '' , $ text ) ; $ text = preg_replace ( '/[-\s]+/' , '-' , $ text ) ; $ text = strtolower ( $ text ) ; return trim ( substr ( $ text , 0 , $ max_length ) , '-' ) ; }
Takes text and returns it in the lowercase - and - dashed - with - no - punctuation format .
10,028
public function highlightSearch ( $ value , $ searchString ) { if ( strlen ( $ value ) < 1 || strlen ( $ searchString ) < 1 ) { return $ value ; } preg_match_all ( "/$searchString+/i" , $ value , $ matches ) ; if ( is_array ( $ matches [ 0 ] ) && count ( $ matches [ 0 ] ) > 0 ) { return str_replace ( $ matches [ 0 ] [ 0 ] , '<em class="ccm-highlight-search">' . $ matches [ 0 ] [ 0 ] . '</em>' , $ value ) ; } return $ value ; }
Highlights a string within a string with the class ccm - highlight - search .
10,029
public function appendXML ( \ SimpleXMLElement $ root , \ SimpleXMLElement $ new ) { $ node = $ root -> addChild ( $ new -> getName ( ) , ( string ) $ new ) ; foreach ( $ new -> attributes ( ) as $ attr => $ value ) { $ node -> addAttribute ( $ attr , $ value ) ; } foreach ( $ new -> children ( ) as $ ch ) { $ this -> appendXML ( $ node , $ ch ) ; } }
Appends a SimpleXMLElement to a SimpleXMLElement .
10,030
public function submit ( $ text , $ formID = false , $ buttonAlign = 'right' , $ innerClass = null , $ args = [ ] ) { if ( 'right' == $ buttonAlign ) { $ innerClass .= ' pull-right' ; } elseif ( 'left' == $ buttonAlign ) { $ innerClass .= ' pull-left' ; } if ( ! $ formID ) { $ formID = 'button' ; } $ argsstr = '' ; foreach ( $ args as $ k => $ v ) { $ argsstr .= $ k . '="' . $ v . '" ' ; } return '<input type="submit" class="btn ' . $ innerClass . '" value="' . $ text . '" id="ccm-submit-' . $ formID . '" name="ccm-submit-' . $ formID . '" ' . $ argsstr . ' />' ; }
Generates a submit button in the Concrete style .
10,031
public function button ( $ text , $ href , $ buttonAlign = 'right' , $ innerClass = null , $ args = [ ] ) { if ( 'right' == $ buttonAlign ) { $ innerClass .= ' pull-right' ; } elseif ( 'left' == $ buttonAlign ) { $ innerClass .= ' pull-left' ; } $ argsstr = '' ; foreach ( $ args as $ k => $ v ) { $ argsstr .= $ k . '="' . $ v . '" ' ; } return '<a href="' . $ href . '" class="btn btn-default ' . $ innerClass . '" ' . $ argsstr . '>' . $ text . '</a>' ; }
Generates a simple link button in the Concrete style .
10,032
public function buttonJs ( $ text , $ onclick , $ buttonAlign = 'right' , $ innerClass = null , $ args = [ ] ) { if ( 'right' == $ buttonAlign ) { $ innerClass .= ' pull-right' ; } elseif ( 'left' == $ buttonAlign ) { $ innerClass .= ' pull-left' ; } $ argsstr = '' ; foreach ( $ args as $ k => $ v ) { $ argsstr .= $ k . '="' . $ v . '" ' ; } return '<input type="button" class="btn btn-default ' . $ innerClass . '" value="' . $ text . '" onclick="' . $ onclick . '" ' . $ buttonAlign . ' ' . $ argsstr . ' />' ; }
Generates a JavaScript function button in the Concrete style .
10,033
public function showHelpOverlay ( ) { $ result = false ; if ( Config :: get ( 'concrete.misc.help_overlay' ) ) { $ u = new ConcreteUser ( ) ; $ timestamp = $ u -> config ( 'MAIN_HELP_LAST_VIEWED' ) ; if ( ! $ timestamp ) { $ result = true ; } } return $ result ; }
Shall we show the introductive help overlay?
10,034
public function getProcessedBody ( ) { $ r = preg_split ( MailImporter :: getMessageBodyHashRegularExpression ( ) , $ this -> body ) ; $ message = $ r [ 0 ] ; $ r = preg_replace ( array ( '/^On (.*) at (.*), (.*) wrote:/sm' , '/[\n\r\s\>]*\Z/i' , ) , '' , $ message ) ; return $ r ; }
Returns the relevant content of the email message minus any quotations and the line that includes the validation hash .
10,035
public function validate ( ) { if ( ! $ this -> validationHash ) { return false ; } $ db = Database :: connection ( ) ; $ row = $ db -> GetRow ( "select * from MailValidationHashes where mHash = ? order by mDateGenerated desc limit 1" , $ this -> validationHash ) ; if ( $ row [ 'mvhID' ] > 0 ) { return $ row [ 'mDateRedeemed' ] == 0 ; } }
Validates the email message - checks the validation hash found in the body with one in the database . Checks the from address as well .
10,036
public function isSendError ( ) { $ message = $ this -> getOriginalMessageObject ( ) ; $ headers = $ message -> getHeaders ( ) ; $ isSendError = false ; if ( is_array ( $ headers ) && count ( $ headers ) ) { foreach ( array_keys ( $ headers ) as $ key ) { if ( strstr ( $ key , 'x-fail' ) !== false ) { $ isSendError = true ; break ; } } } return $ isSendError ; }
checks to see if the message is a bounce or delivery failure .
10,037
protected function getLoggedInUser ( ) { if ( ! $ this -> user ) { $ this -> user = $ this -> app -> make ( User :: class ) ; } return $ this -> user ; }
Resolve a user intance from the IOC container and cache it
10,038
public static function loadAll ( ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ permissionkeys = [ ] ; $ txt = $ app -> make ( 'helper/text' ) ; $ e = $ db -> executeQuery ( <<<'EOT'select pkID, pkName, pkDescription, pkHandle, pkCategoryHandle, pkCanTriggerWorkflow, pkHasCustomClass, PermissionKeys.pkCategoryID, PermissionKeyCategories.pkgIDfrom PermissionKeysinner join PermissionKeyCategories on PermissionKeyCategories.pkCategoryID = PermissionKeys.pkCategoryIDEOT ) ; while ( ( $ r = $ e -> fetch ( PDO :: FETCH_ASSOC ) ) !== false ) { if ( $ r [ 'pkHasCustomClass' ] ) { $ class = '\\Core\\Permission\\Key\\' . $ txt -> camelcase ( $ r [ 'pkHandle' ] . '_' . $ r [ 'pkCategoryHandle' ] ) . 'Key' ; } else { $ class = '\\Core\\Permission\\Key\\' . $ txt -> camelcase ( $ r [ 'pkCategoryHandle' ] ) . 'Key' ; } $ pkgHandle = $ r [ 'pkgID' ] ? PackageList :: getHandle ( $ r [ 'pkgID' ] ) : null ; $ class = core_class ( $ class , $ pkgHandle ) ; $ pk = $ app -> make ( $ class ) ; $ pk -> setPropertiesFromArray ( $ r ) ; $ permissionkeys [ $ r [ 'pkHandle' ] ] = $ pk ; $ permissionkeys [ $ r [ 'pkID' ] ] = $ pk ; } $ cache = $ app -> make ( 'cache/request' ) ; if ( $ cache -> isEnabled ( ) ) { $ cache -> getItem ( 'permission_keys' ) -> set ( $ permissionkeys ) -> save ( ) ; } return $ permissionkeys ; }
Get the list of all the defined permission keys .
10,039
public function getPackageHandle ( ) { $ pkgID = $ this -> getPackageID ( ) ; return $ pkgID ? PackageList :: getHandle ( $ this -> pkgID ) : null ; }
Get the handle of the package that defines this permission key .
10,040
public static function getList ( $ pkCategoryHandle , $ filters = [ ] ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ q = 'select pkID from PermissionKeys inner join PermissionKeyCategories on PermissionKeys.pkCategoryID = PermissionKeyCategories.pkCategoryID where pkCategoryHandle = ?' ; foreach ( $ filters as $ key => $ value ) { $ q .= ' and ' . $ key . ' = ' . $ value . ' ' ; } $ r = $ db -> executeQuery ( $ q , [ $ pkCategoryHandle ] ) ; $ list = [ ] ; while ( ( $ pkID = $ r -> fetchColumn ( ) ) !== false ) { $ pk = self :: load ( $ pkID ) ; if ( $ pk ) { $ list [ ] = $ pk ; } } return $ list ; }
Returns the list of all permissions of this category .
10,041
public function export ( $ axml ) { $ category = PermissionKeyCategory :: getByID ( $ this -> pkCategoryID ) -> getPermissionKeyCategoryHandle ( ) ; $ pkey = $ axml -> addChild ( 'permissionkey' ) ; $ pkey -> addAttribute ( 'handle' , $ this -> getPermissionKeyHandle ( ) ) ; $ pkey -> addAttribute ( 'name' , $ this -> getPermissionKeyName ( ) ) ; $ pkey -> addAttribute ( 'description' , $ this -> getPermissionKeyDescription ( ) ) ; $ pkey -> addAttribute ( 'package' , $ this -> getPackageHandle ( ) ) ; $ pkey -> addAttribute ( 'category' , $ category ) ; $ this -> exportAccess ( $ pkey ) ; return $ pkey ; }
Export this permission key to a SimpleXMLElement instance .
10,042
public static function exportList ( $ xml ) { $ categories = PermissionKeyCategory :: getList ( ) ; $ pxml = $ xml -> addChild ( 'permissionkeys' ) ; foreach ( $ categories as $ cat ) { $ permissions = static :: getList ( $ cat -> getPermissionKeyCategoryHandle ( ) ) ; foreach ( $ permissions as $ p ) { $ p -> export ( $ pxml ) ; } } }
Export the list of all permissions of this category to a SimpleXMLElement instance .
10,043
public static function getListByPackage ( $ pkg ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ kina = [ '-1' ] ; $ rs = $ db -> executeQuery ( 'select pkCategoryID from PermissionKeyCategories where pkgID = ?' , [ $ pkg -> getPackageID ( ) ] ) ; while ( ( $ pkCategoryID = $ rs -> fetchColumn ( ) ) !== false ) { $ kina [ ] = $ pkCategoryID ; } $ kinstr = implode ( ',' , $ kina ) ; $ categories = [ ] ; $ list = [ ] ; $ r = $ db -> executeQuery ( 'select pkID, pkCategoryID from PermissionKeys where (pkgID = ? or pkCategoryID in (' . $ kinstr . ')) order by pkID asc' , [ $ pkg -> getPackageID ( ) ] ) ; while ( ( $ row = $ r -> fetch ( PDO :: FETCH_ASSOC ) ) !== false ) { if ( ! isset ( $ categories [ $ row [ 'pkCategoryID' ] ] ) ) { $ categories [ $ row [ 'pkCategoryID' ] ] = PermissionKeyCategory :: getByID ( $ row [ 'pkCategoryID' ] ) ; } $ pkc = $ categories [ $ row [ 'pkCategoryID' ] ] ; $ pk = $ pkc -> getPermissionKeyByID ( $ row [ 'pkID' ] ) ; $ list [ ] = $ pk ; } return $ list ; }
Get the list of permission keys defined by a package . Note this queries both the pkgID found on the PermissionKeys table AND any permission keys of a special type installed by that package and any in categories by that package .
10,044
public static function import ( SimpleXMLElement $ pk ) { if ( $ pk [ 'package' ] ) { $ app = Application :: getFacadeApplication ( ) ; $ pkg = $ app -> make ( PackageService :: class ) -> getByHandle ( $ pk [ 'package' ] ) ; } else { $ pkg = null ; } return self :: add ( $ pk [ 'category' ] , $ pk [ 'handle' ] , $ pk [ 'name' ] , $ pk [ 'description' ] , $ pk [ 'can-trigger-workflow' ] ? 1 : 0 , $ pk [ 'has-custom-class' ] ? 1 : 0 , $ pkg ) ; }
Import a permission key from a SimpleXMLElement element .
10,045
public static function getByID ( $ pkID ) { $ keys = null ; $ app = Application :: getFacadeApplication ( ) ; $ cache = $ app -> make ( 'cache/request' ) ; if ( $ cache -> isEnabled ( ) ) { $ item = $ cache -> getItem ( 'permission_keys' ) ; if ( ! $ item -> isMiss ( ) ) { $ keys = $ item -> get ( ) ; } } if ( $ keys === null ) { $ keys = self :: loadAll ( ) ; } return isset ( $ keys [ $ pkID ] ) ? $ keys [ $ pkID ] : null ; }
Get a permission key given its ID .
10,046
public static function getByHandle ( $ pkHandle ) { $ keys = null ; $ app = Application :: getFacadeApplication ( ) ; $ cache = $ app -> make ( 'cache/request' ) ; if ( $ cache -> isEnabled ( ) ) { $ item = $ cache -> getItem ( 'permission_keys' ) ; if ( ! $ item -> isMiss ( ) ) { $ keys = $ item -> get ( ) ; } } if ( $ keys === null ) { $ keys = self :: loadAll ( ) ; } return isset ( $ keys [ $ pkHandle ] ) ? $ keys [ $ pkHandle ] : null ; }
Get a permission key given its handle .
10,047
public static function add ( $ pkCategoryHandle , $ pkHandle , $ pkName , $ pkDescription , $ pkCanTriggerWorkflow , $ pkHasCustomClass , $ pkg = false ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ pkCategoryID = $ db -> fetchColumn ( 'select pkCategoryID from PermissionKeyCategories where pkCategoryHandle = ?' , [ $ pkCategoryHandle ] ) ; $ db -> insert ( 'PermissionKeys' , [ 'pkHandle' => $ pkHandle , 'pkName' => $ pkName , 'pkDescription' => $ pkDescription , 'pkCategoryID' => $ pkCategoryID , 'pkCanTriggerWorkflow' => $ pkCanTriggerWorkflow ? 1 : 0 , 'pkHasCustomClass' => $ pkHasCustomClass ? 1 : 0 , 'pkgID' => is_object ( $ pkg ) ? $ pkg -> getPackageID ( ) : 0 , ] ) ; $ pkID = $ db -> lastInsertId ( ) ; $ keys = self :: loadAll ( ) ; return $ keys [ $ pkID ] ; }
Adds an permission key .
10,048
public function delete ( ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ db -> executeQuery ( 'delete from PermissionKeys where pkID = ?' , [ $ this -> getPermissionKeyID ( ) ] ) ; self :: loadAll ( ) ; }
Delete this permission key .
10,049
public function getAccessListItems ( ) { $ obj = $ this -> getPermissionAccessObject ( ) ; if ( ! $ obj ) { return [ ] ; } $ args = func_get_args ( ) ; switch ( count ( $ args ) ) { case 0 : return $ obj -> getAccessListItems ( ) ; case 1 : return $ obj -> getAccessListItems ( $ args [ 0 ] ) ; case 2 : return $ obj -> getAccessListItems ( $ args [ 0 ] , $ args [ 1 ] ) ; case 3 : return $ obj -> getAccessListItems ( $ args [ 0 ] , $ args [ 1 ] , $ args [ 2 ] ) ; default : return call_user_func_array ( [ $ obj , 'getAccessListItems' ] , $ args ) ; } }
A shortcut for grabbing the current assignment and passing into that object .
10,050
public static function exportTranslations ( ) { $ translations = new Translations ( ) ; $ categories = PermissionKeyCategory :: getList ( ) ; foreach ( $ categories as $ cat ) { $ permissions = static :: getList ( $ cat -> getPermissionKeyCategoryHandle ( ) ) ; foreach ( $ permissions as $ p ) { $ translations -> insert ( 'PermissionKeyName' , $ p -> getPermissionKeyName ( ) ) ; if ( $ p -> getPermissionKeyDescription ( ) ) { $ translations -> insert ( 'PermissionKeyDescription' , $ p -> getPermissionKeyDescription ( ) ) ; } } } return $ translations ; }
Export the strings that should be translated .
10,051
public function boot ( ) { $ booter = $ this -> getBooter ( ) ; if ( $ response = $ booter -> boot ( ) ) { $ this -> sendResponse ( $ response ) ; } else { $ this -> status = self :: STATUS_ACTIVE ; } }
Initialize the environment and prepare for running .
10,052
public function getService ( $ handle , $ version = '' ) { $ result = null ; if ( $ this -> has ( $ handle ) ) { $ key = $ handle ; $ version = ( string ) $ version ; if ( $ version !== '' ) { $ key .= "@$version" ; } if ( ! isset ( $ this -> services [ $ key ] ) ) { $ abstract = $ this -> extensions [ $ handle ] ; $ service = $ this -> buildService ( $ abstract , $ version ) ; if ( $ service === null ) { throw new \ RuntimeException ( 'Invalid service binding.' ) ; } $ this -> services [ $ key ] = $ service ; } $ result = $ this -> services [ $ key ] ; } return $ result ; }
Get the driver for this handle .
10,053
private function buildService ( $ abstract , $ version = '' ) { $ resolved = null ; if ( is_string ( $ abstract ) ) { $ resolved = $ this -> app -> make ( $ abstract , array ( $ version ) ) ; } elseif ( is_callable ( $ abstract ) ) { $ resolved = $ abstract ( $ version , $ this -> app , $ this ) ; } return $ resolved ; }
Build a service from an abstract .
10,054
public function getAllServices ( ) { $ result = array ( ) ; foreach ( $ this -> getExtensions ( ) as $ handle ) { $ result [ $ handle ] = $ this -> getService ( $ handle ) ; } return $ result ; }
Returns all the available services .
10,055
public function getActiveServices ( ) { $ active = array ( ) ; foreach ( $ this -> getExtensions ( ) as $ handle ) { $ service = $ this -> getService ( $ handle ) ; $ version = $ service -> getDetector ( ) -> detect ( ) ; if ( $ version !== null ) { $ active [ ] = $ this -> getService ( $ handle , $ version ) ; } } return $ active ; }
Loops through the bound services and returns the ones that are active .
10,056
protected function getEscapeMap ( ) { if ( $ this -> escapeMap === null ) { $ escapeMap = [ $ this -> anyCharacterWildcard => $ this -> escapeCharacter . $ this -> anyCharacterWildcard , $ this -> oneCharacterWildcard => $ this -> escapeCharacter . $ this -> oneCharacterWildcard , $ this -> escapeCharacter => $ this -> escapeCharacter . $ this -> escapeCharacter , ] ; foreach ( $ this -> otherWildcards as $ otherWildcard ) { $ escapeMap [ $ otherWildcard ] = $ this -> escapeCharacter . $ otherWildcard ; } $ this -> escapeMap = $ escapeMap ; } return $ this -> escapeMap ; }
Get the string mapping used to escape special characters .
10,057
public function escapeForLike ( $ string , $ wildcardAtStart = true , $ wildcardAtEnd = true ) { if ( $ wildcardAtStart ) { $ result = $ this -> anyCharacterWildcard ; } else { $ result = '' ; } $ result .= strtr ( ( string ) $ string , $ this -> getEscapeMap ( ) ) ; if ( $ wildcardAtEnd && $ result !== $ this -> anyCharacterWildcard ) { $ result .= $ this -> anyCharacterWildcard ; } return $ result ; }
Escape a string to be safely used as a parameter for a LIKE query .
10,058
public function splitKeywordsForLike ( $ string , $ wordSeparators = '\s' , $ addWildcards = true ) { $ result = null ; if ( is_string ( $ string ) ) { $ words = preg_split ( '/[' . $ wordSeparators . ']+/ms' , $ string ) ; foreach ( $ words as $ word ) { if ( $ word !== '' ) { $ result [ ] = $ this -> escapeForLike ( $ word , $ addWildcards , $ addWildcards ) ; } } } return $ result ; }
Split a string into words and format them to be used in LIKE queries .
10,059
private function returnThumbnailObjectFromResolver ( $ obj , $ maxWidth , $ maxHeight , $ crop = false ) { return $ this -> processThumbnail ( true , $ obj , $ maxWidth , $ maxHeight , $ crop ) ; }
Checks thumbnail resolver for filename schedule for creation via ajax if necessary .
10,060
private function checkForThumbnailAndCreateIfNecessary ( $ obj , $ maxWidth , $ maxHeight , $ crop = false ) { return $ this -> processThumbnail ( false , $ obj , $ maxWidth , $ maxHeight , $ crop ) ; }
Checks filesystem for thumbnail and if file doesn t exist will create it immediately . concrete5 s default behavior from the beginning up to 8 . 1 .
10,061
public function getResults ( ) { $ results = array ( ) ; $ this -> debugStart ( ) ; $ executeResults = $ this -> executeGetResults ( ) ; $ this -> debugStop ( ) ; foreach ( $ executeResults as $ result ) { $ r = $ this -> getResult ( $ result ) ; if ( $ r != null ) { $ results [ ] = $ r ; } } return $ results ; }
Returns a full array of results .
10,062
public function setNameSpace ( $ nameSpace ) { $ this -> paginationPageParameter .= '_' . $ nameSpace ; $ this -> sortColumnParameter .= '_' . $ nameSpace ; $ this -> sortDirectionParameter .= '_' . $ nameSpace ; }
Allow to modify the auto - pagination parameters and the auto - sorting parameters
10,063
public function describeVar ( $ name , $ value ) { return $ this -> indentation . '/** @var ' . $ this -> getVarType ( $ value ) . ' ' . ( $ name [ 0 ] === '$' ? '' : '$' ) . $ name . " */\n" ; }
Generate the PHPDoc to describe a variable .
10,064
public function describeVars ( array $ vars , $ sortByName = true ) { $ result = '' ; if ( $ sortByName ) { ksort ( $ vars , SORT_NATURAL ) ; } foreach ( $ vars as $ name => $ value ) { $ result .= $ this -> describeVar ( $ name , $ value ) ; } return $ result ; }
Generate the PHPDoc to describe a list of variables .
10,065
protected function getVarType ( $ var , $ arrayLevel = 0 ) { $ phpType = gettype ( $ var ) ; switch ( $ phpType ) { case 'boolean' : $ result = 'bool' ; break ; case 'integer' : $ result = 'int' ; break ; case 'double' : $ result = 'float' ; break ; case 'string' : $ result = 'string' ; break ; case 'array' : if ( $ arrayLevel > 1 ) { $ result = 'array' ; } else { $ result = null ; $ first = true ; foreach ( $ var as $ item ) { $ itemType = $ this -> getVarType ( $ item , $ arrayLevel + 1 ) ; if ( $ first ) { $ result = $ itemType ; $ commonObjectDescriptors = $ this -> getObjectDescriptors ( $ item ) ; $ first = false ; } else { if ( $ result !== $ itemType ) { $ result = null ; if ( empty ( $ commonObjectDescriptors ) ) { break ; } if ( ! empty ( $ commonObjectDescriptors ) ) { $ commonObjectDescriptors = array_intersect ( $ commonObjectDescriptors , $ this -> getObjectDescriptors ( $ item ) ) ; } } } } if ( $ result !== null ) { $ result .= '[]' ; } elseif ( ! empty ( $ commonObjectDescriptors ) ) { $ result = array_shift ( $ commonObjectDescriptors ) . '[]' ; } else { $ result = 'array' ; } } break ; case 'object' : $ result = get_class ( $ var ) ; if ( $ result === false ) { $ result = 'mixed' ; } else { if ( $ this -> insideNamespace ) { $ result = '\\' . $ result ; } } break ; case 'resource' : $ result = 'resource' ; break ; case 'NULL' : $ result = 'null' ; break ; case 'unknown type' : default : $ result = 'mixed' ; break ; } return $ result ; }
Get the PHPDoc type name of a variable .
10,066
public static function getByHandle ( $ handle ) { $ list = Type :: getVersionList ( ) ; foreach ( $ list as $ version ) { if ( $ version -> getHandle ( ) == $ handle ) { return $ version ; } } }
Get a thumbnail type version given its handle .
10,067
public function shouldExistFor ( $ imageWidth , $ imageHeight , File $ file = null ) { $ result = false ; $ imageWidth = ( int ) $ imageWidth ; $ imageHeight = ( int ) $ imageHeight ; if ( $ imageWidth > 0 && $ imageHeight > 0 ) { $ thumbnailWidth = ( int ) $ this -> getWidth ( ) ? : 0 ; $ thumbnailHeight = ( int ) $ this -> getHeight ( ) ? : 0 ; switch ( $ this -> getSizingMode ( ) ) { case ThumbnailType :: RESIZE_EXACT : if ( $ thumbnailWidth > 0 && $ thumbnailHeight > 0 ) { if ( $ this -> isUpscalingEnabled ( ) ) { $ result = true ; } else { if ( $ thumbnailWidth <= $ imageWidth && $ thumbnailHeight <= $ imageHeight ) { if ( $ thumbnailWidth !== $ imageWidth || $ thumbnailHeight !== $ imageHeight ) { $ result = true ; } } } } break ; case ThumbnailType :: RESIZE_PROPORTIONAL : default : if ( $ thumbnailWidth > 0 || $ thumbnailHeight > 0 ) { if ( $ this -> isUpscalingEnabled ( ) ) { $ result = true ; } else { if ( $ thumbnailWidth > 0 && $ thumbnailHeight > 0 ) { if ( $ thumbnailWidth < $ imageWidth || $ thumbnailHeight < $ imageHeight ) { $ result = true ; } } elseif ( $ thumbnailWidth > 0 ) { if ( $ thumbnailWidth < $ imageWidth ) { $ result = true ; } } elseif ( $ thumbnailHeight > 0 ) { if ( $ thumbnailHeight < $ imageHeight ) { $ result = true ; } } } } break ; } if ( $ result === true && $ file !== null ) { $ fileSetIDs = $ this -> getAssociatedFileSetIDs ( ) ; if ( $ this -> isLimitedToFileSets ( ) ) { if ( empty ( $ fileSetIDs ) ) { $ result = false ; } else { $ valid = array_intersect ( $ fileSetIDs , $ file -> getFileSetIDs ( ) ) ; if ( empty ( $ valid ) ) { $ result = false ; } } } else { if ( ! empty ( $ fileSetIDs ) ) { $ blocking = array_intersect ( $ fileSetIDs , $ file -> getFileSetIDs ( ) ) ; if ( ! empty ( $ blocking ) ) { $ result = false ; } } } } } return $ result ; }
Check if this thumbnail type version should exist for an image with the specified dimensions .
10,068
public function getCountries ( ) { if ( ! array_key_exists ( Localization :: activeLocale ( ) , $ this -> countries ) ) { $ this -> loadCountries ( ) ; } return $ this -> countries [ Localization :: activeLocale ( ) ] ; }
Returns an array of countries with their short name as the key and their full name as the value
10,069
public function getCountriesForLanguage ( $ languageCode , $ languageStatuses = 'orfm' ) { $ territories = [ ] ; foreach ( \ Punic \ Territory :: getTerritoriesForLanguage ( $ languageCode ) as $ territory ) { $ territoryLanguages = \ Punic \ Territory :: getLanguages ( $ territory , $ languageStatuses , true ) ; if ( in_array ( $ languageCode , $ territoryLanguages ) ) { $ territories [ ] = $ territory ; } } $ validCountryCodes = array_keys ( $ this -> getCountries ( ) ) ; $ result = array_intersect ( $ territories , $ validCountryCodes ) ; return array_values ( $ result ) ; }
Return a list of territory codes where a specific language is spoken sorted by the total number of people speaking that language .
10,070
protected function validateAction ( ) { $ token = ( isset ( $ this -> validationToken ) ) ? $ this -> validationToken : get_class ( $ this ) ; if ( ! $ this -> app -> make ( 'token' ) -> validate ( $ token ) ) { $ this -> error -> add ( $ this -> app -> make ( 'token' ) -> getErrorMessage ( ) ) ; return false ; } if ( ! $ this -> canAccess ( ) ) { return false ; } return true ; }
Check whether the token is valid and if the current page be accessed .
10,071
private function resolveRoute ( $ route_handle , $ route_parameters ) { $ list = $ this -> getRouteList ( ) ; $ generator = $ this -> getGenerator ( ) ; if ( $ route = $ list -> get ( $ route_handle ) ) { if ( $ path = $ generator -> generate ( $ route_handle , $ route_parameters , UrlGeneratorInterface :: ABSOLUTE_PATH ) ) { return $ this -> pathUrlResolver -> resolve ( array ( $ path ) ) ; } } }
Resolve the route .
10,072
public function setError ( $ code , $ message = '' , Exception $ innerException = null ) { if ( $ code == static :: ERR_NONE && ! $ message && $ innerException === null ) { $ this -> errorCode = static :: ERR_NONE ; $ this -> errorMessage = '' ; $ this -> innerException = null ; } else { $ code = ( int ) $ code ; $ this -> errorCode = $ code === static :: ERR_NONE ? static :: ERR_OTHER : $ code ; $ message = trim ( ( string ) $ message ) ; if ( $ message === '' ) { switch ( $ this -> errorCode ) { case static :: ERR_NOCURRENTLIBRARY : $ this -> errorMessage = t ( "There's no current geolocation library" ) ; break ; case static :: ERR_NOCURRENTIPADDRESS : $ this -> errorMessage = t ( 'The IP address of the current client is not available' ) ; break ; case static :: ERR_IPNOTPUBLIC : $ this -> errorMessage = t ( 'The IP address is not in the public IP address ranges' ) ; break ; case static :: ERR_MISCONFIGURED : $ this -> errorMessage = t ( 'The geolocation library is misconfigured' ) ; break ; case static :: ERR_NETWORK : $ this -> errorMessage = t ( 'A network error occurred during the geolocalization' ) ; break ; case static :: ERR_LIBRARYSPECIFIC : $ this -> errorMessage = t ( 'An unspecified error occurred in the geolocation library' ) ; break ; default : $ this -> errorMessage = t ( 'An unexpected error occurred in the geolocation library' ) ; } } else { $ this -> errorMessage = $ message ; } $ this -> innerException = $ innerException ; } }
Set the error state .
10,073
public function setLatitude ( $ value ) { if ( is_float ( $ value ) || is_int ( $ value ) || ( is_string ( $ value ) && is_numeric ( $ value ) ) ) { $ this -> latitude = ( float ) $ value ; } else { $ this -> latitude = null ; } return $ this ; }
Set the latitude .
10,074
public function setLongitude ( $ value ) { if ( is_float ( $ value ) || is_int ( $ value ) || ( is_string ( $ value ) && is_numeric ( $ value ) ) ) { $ this -> longitude = ( float ) $ value ; } else { $ this -> longitude = null ; } return $ this ; }
Set the longitude .
10,075
public function hasData ( ) { return $ this -> countryCode !== '' || $ this -> countryName !== '' || $ this -> stateProvinceCode !== '' || $ this -> stateProvinceName !== '' || $ this -> cityName !== '' || $ this -> postalCode !== '' || $ this -> latitude !== null || $ this -> longitude !== null ; }
Does this instance contain some geolocalized data?
10,076
protected function getDestinationFolder ( ) { if ( $ this -> destinationFolder === false ) { $ replacingFile = $ this -> getFileToBeReplaced ( ) ; if ( $ replacingFile !== null ) { $ folder = $ replacingFile -> getFileFolderObject ( ) ; } else { $ treeNodeID = $ this -> request -> request -> get ( 'currentFolder' ) ; if ( $ treeNodeID ) { $ treeNodeID = is_scalar ( $ treeNodeID ) ? ( int ) $ treeNodeID : 0 ; $ folder = $ treeNodeID === 0 ? null : Node :: getByID ( $ treeNodeID ) ; } else { $ filesystem = new Filesystem ( ) ; $ folder = $ filesystem -> getRootFolder ( ) ; } } if ( ! $ folder instanceof FileFolder ) { throw new UserMessageException ( t ( 'Unable to find the specified folder.' ) ) ; } if ( $ replacingFile === null ) { $ fp = new Checker ( $ folder ) ; if ( ! $ fp -> canAddFiles ( ) ) { throw new UserMessageException ( t ( 'Unable to add files.' ) , 400 ) ; } } $ this -> destinationFolder = $ folder ; } return $ this -> destinationFolder ; }
Get the destination folder where the uploaded files should be placed .
10,077
protected function downloadRemoteURL ( $ url , $ temporaryDirectory ) { $ client = $ this -> app -> make ( 'http/client' ) ; $ request = $ client -> getRequest ( ) -> setUri ( $ url ) ; $ response = $ client -> send ( ) ; if ( ! $ response -> isSuccess ( ) ) { throw new UserMessageException ( t ( 'There was an error downloading "%1$s": %2$s' , $ url , $ response -> getReasonPhrase ( ) . ' (' . $ response -> getStatusCode ( ) . ')' ) ) ; } $ headers = $ response -> getHeaders ( ) ; $ matches = null ; if ( preg_match ( '/^[^#\?]+[\\/]([-\w%]+\.[-\w%]+)($|\?|#)/' , $ request -> getUri ( ) , $ matches ) ) { $ filename = $ matches [ 1 ] ; } else { $ contentType = $ headers -> get ( 'ContentType' ) -> getFieldValue ( ) ; if ( $ contentType ) { list ( $ mimeType ) = explode ( ';' , $ contentType , 2 ) ; $ mimeType = trim ( $ mimeType ) ; $ extension = $ this -> app -> make ( 'helper/mime' ) -> mimeToExtension ( $ mimeType ) ; if ( $ extension === false ) { throw new UserMessageException ( t ( 'Unknown mime-type: %s' , h ( $ mimeType ) ) ) ; } $ filename = date ( 'Y-m-d_H-i_' ) . mt_rand ( 100 , 999 ) . '.' . $ extension ; } else { throw new UserMessageException ( t ( 'Could not determine the name of the file at %s' , $ url ) ) ; } } $ fullFilename = $ temporaryDirectory . '/' . $ filename ; $ handle = fopen ( $ fullFilename , 'wb' ) ; fwrite ( $ handle , $ response -> getBody ( ) ) ; fclose ( $ handle ) ; return $ fullFilename ; }
Download an URL to the temporary directory .
10,078
public function shouldEnableLegacyNamespace ( ) { if ( isset ( $ this -> pkgAutoloaderMapCoreExtensions ) && $ this -> pkgAutoloaderMapCoreExtensions ) { return false ; } $ concrete5 = '7.9.9' ; $ package = $ this -> getApplicationVersionRequired ( ) ; if ( version_compare ( $ package , $ concrete5 , '>' ) ) { return false ; } return $ this -> pkgEnableLegacyNamespace ; }
Should this package enable legacy namespaces?
10,079
public function getDatabaseConfig ( ) { if ( ! $ this -> config ) { $ this -> config = new Liaison ( $ this -> app -> make ( 'config/database' ) , $ this -> getPackageHandle ( ) ) ; } return $ this -> config ; }
Get the database configuration liaison .
10,080
public function getFileConfig ( ) { if ( ! $ this -> fileConfig ) { $ this -> fileConfig = new Liaison ( $ this -> app -> make ( 'config' ) , $ this -> getPackageHandle ( ) ) ; } return $ this -> fileConfig ; }
Get the filesystem configuration liaison .
10,081
public function getPackagePath ( ) { $ packageHandle = $ this -> getPackageHandle ( ) ; $ result = $ this -> DIR_PACKAGES . '/' . $ packageHandle ; if ( ! is_dir ( $ result ) ) { $ result = $ this -> DIR_PACKAGES_CORE . '/' . $ packageHandle ; } return $ result ; }
Get the absolute path to the package .
10,082
public function getRelativePath ( ) { $ packageHandle = $ this -> getPackageHandle ( ) ; if ( is_dir ( $ this -> DIR_PACKAGES . '/' . $ packageHandle ) ) { $ result = $ this -> REL_DIR_PACKAGES . '/' . $ packageHandle ; } else { $ result = $ this -> REL_DIR_PACKAGES_CORE . '/' . $ packageHandle ; } return $ result ; }
Get the path to the package relative to the web root .
10,083
public function getChangelogContents ( ) { $ prefix = $ this -> getPackagePath ( ) . '/' ; foreach ( [ 'CHANGELOG' , 'CHANGELOG.txt' , 'CHANGELOG.md' ] as $ name ) { $ file = $ prefix . $ name ; if ( is_file ( $ file ) ) { $ contents = $ this -> app -> make ( 'helper/file' ) -> getContents ( $ file ) ; return nl2br ( h ( $ contents ) ) ; } } return '' ; }
Get the contents of the package s CHANGELOG file .
10,084
public function backup ( ) { $ packageHandle = $ this -> getPackageHandle ( ) ; $ errors = $ this -> app -> make ( 'error' ) ; if ( $ packageHandle === '' || ! is_dir ( DIR_PACKAGES . '/' . $ packageHandle ) ) { $ errors -> add ( $ this -> getErrorText ( self :: E_PACKAGE_NOT_FOUND ) ) ; } else { $ config = $ this -> app -> make ( 'config' ) ; $ trash = $ config -> get ( 'concrete.misc.package_backup_directory' ) ; if ( ! is_dir ( $ trash ) ) { @ mkdir ( $ trash , $ config -> get ( 'concrete.filesystem.permissions.directory' ) ) ; } if ( ! is_dir ( $ trash ) ) { $ errors -> add ( $ this -> getErrorText ( self :: E_PACKAGE_MIGRATE_BACKUP ) ) ; } else { $ trashName = $ trash . '/' . $ packageHandle . '_' . date ( 'YmdHis' ) ; if ( ! @ rename ( DIR_PACKAGES . '/' . $ this -> getPackageHandle ( ) , $ trashName ) ) { $ errors -> add ( $ this -> getErrorText ( self :: E_PACKAGE_MIGRATE_BACKUP ) ) ; } else { $ this -> backedUpFname = $ trashName ; } } } return $ errors -> has ( ) ? $ errors : $ this ; }
Move the current package directory to the trash directory and rename it with the package handle and a date code .
10,085
public static function installDB ( $ xmlFile ) { if ( file_exists ( $ xmlFile ) ) { $ app = ApplicationFacade :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ db -> beginTransaction ( ) ; $ parser = Schema :: getSchemaParser ( simplexml_load_file ( $ xmlFile ) ) ; $ parser -> setIgnoreExistingTables ( false ) ; $ toSchema = $ parser -> parse ( $ db ) ; $ fromSchema = $ db -> getSchemaManager ( ) -> createSchema ( ) ; $ comparator = new SchemaComparator ( ) ; $ schemaDiff = $ comparator -> compare ( $ fromSchema , $ toSchema ) ; $ saveQueries = $ schemaDiff -> toSaveSql ( $ db -> getDatabasePlatform ( ) ) ; foreach ( $ saveQueries as $ query ) { $ db -> query ( $ query ) ; } $ db -> commit ( ) ; $ result = new stdClass ( ) ; $ result -> result = false ; } else { $ result = false ; } return $ result ; }
Installs a package database from an XML file .
10,086
public function upgradeCoreData ( ) { $ entity = $ this -> getPackageEntity ( ) ; if ( $ entity !== null ) { $ em = $ this -> app -> make ( EntityManagerInterface :: class ) ; $ entity -> setPackageName ( $ this -> getPackageName ( ) ) ; $ entity -> setPackageDescription ( $ this -> getPackageDescription ( ) ) ; $ entity -> setPackageVersion ( $ this -> getPackageVersion ( ) ) ; $ em -> persist ( $ entity ) ; $ em -> flush ( ) ; } }
Updates the package entity name description and version using the current class properties .
10,087
public function upgrade ( ) { $ this -> upgradeDatabase ( ) ; $ manager = new Manager ( $ this -> app ) ; $ items = $ manager -> driver ( 'block_type' ) -> getItems ( $ this -> getPackageEntity ( ) ) ; foreach ( $ items as $ item ) { $ item -> refresh ( ) ; } Localization :: clearCache ( ) ; }
Upgrades a package s database and refreshes all blocks .
10,088
public function upgradeDatabase ( ) { $ em = $ this -> getPackageEntityManager ( ) ; if ( $ em !== null ) { $ this -> destroyProxyClasses ( $ em ) ; $ this -> installEntitiesDatabase ( ) ; } static :: installDB ( $ this -> getPackagePath ( ) . '/' . FILENAME_PACKAGE_DB ) ; }
Updates a package s database using entities and a db . xml .
10,089
public function getPackageEntityManager ( ) { $ providerFactory = new PackageProviderFactory ( $ this -> app , $ this ) ; $ provider = $ providerFactory -> getEntityManagerProvider ( ) ; $ drivers = $ provider -> getDrivers ( ) ; if ( empty ( $ drivers ) ) { $ result = null ; } else { $ config = Setup :: createConfiguration ( true , $ this -> app -> make ( 'config' ) -> get ( 'database.proxy_classes' ) ) ; $ driverImpl = new MappingDriverChain ( ) ; $ coreDriver = new CoreDriver ( $ this -> app ) ; $ packages = $ this -> app -> make ( PackageService :: class ) -> getInstalledList ( ) ; foreach ( $ packages as $ package ) { $ existingProviderFactory = new PackageProviderFactory ( $ this -> app , $ package -> getController ( ) ) ; $ existingProvider = $ existingProviderFactory -> getEntityManagerProvider ( ) ; $ existingDrivers = $ existingProvider -> getDrivers ( ) ; if ( ! empty ( $ existingDrivers ) ) { foreach ( $ existingDrivers as $ existingDriver ) { $ driverImpl -> addDriver ( $ existingDriver -> getDriver ( ) , $ existingDriver -> getNamespace ( ) ) ; } } } $ driverImpl -> addDriver ( $ coreDriver -> getDriver ( ) , $ coreDriver -> getNamespace ( ) ) ; foreach ( $ drivers as $ driver ) { $ driverImpl -> addDriver ( $ driver -> getDriver ( ) , $ driver -> getNamespace ( ) ) ; } $ config -> setMetadataDriverImpl ( $ driverImpl ) ; $ db = $ this -> app -> make ( Connection :: class ) ; $ result = EntityManager :: create ( $ db , $ config ) ; } return $ result ; }
Create an entity manager used for the package install upgrade and unistall process .
10,090
protected function getErrorText ( $ errorCode ) { if ( is_array ( $ errorCode ) ) { $ code = array_shift ( $ errorCode ) ; $ result = vsprintf ( $ this -> getErrorText ( $ code ) , $ errorCode ) ; } else { $ config = $ this -> app -> make ( 'config' ) ; $ dictionary = [ self :: E_PACKAGE_INSTALLED => t ( "You've already installed that package." ) , self :: E_PACKAGE_NOT_FOUND => t ( 'Invalid Package.' ) , self :: E_PACKAGE_VERSION => t ( 'This package requires concrete5 version %s or greater.' ) , self :: E_PACKAGE_DOWNLOAD => t ( 'An error occurred while downloading the package.' ) , self :: E_PACKAGE_SAVE => t ( 'concrete5 was not able to save the package after download.' ) , self :: E_PACKAGE_UNZIP => t ( 'An error occurred while trying to unzip the package.' ) , self :: E_PACKAGE_INSTALL => t ( 'An error occurred while trying to install the package.' ) , self :: E_PACKAGE_MIGRATE_BACKUP => t ( 'Unable to backup old package directory to %s' , $ config -> get ( 'concrete.misc.package_backup_directory' ) ) , self :: E_PACKAGE_INVALID_APP_VERSION => t ( 'This package isn\'t currently available for this version of concrete5. Please contact the maintainer of this package for assistance.' ) , self :: E_PACKAGE_THEME_ACTIVE => t ( 'This package contains the active site theme, please change the theme before uninstalling.' ) , ] ; if ( isset ( $ dictionary [ $ errorCode ] ) ) { $ result = $ dictionary [ $ errorCode ] ; } else { $ result = ( string ) $ errorCode ; } } return $ result ; }
Get the error text corresponsing to an error code .
10,091
protected function destroyProxyClasses ( EntityManagerInterface $ em ) { $ config = $ em -> getConfiguration ( ) ; $ proxyGenerator = new ProxyGenerator ( $ config -> getProxyDir ( ) , $ config -> getProxyNamespace ( ) ) ; $ classes = $ em -> getMetadataFactory ( ) -> getAllMetadata ( ) ; foreach ( $ classes as $ class ) { if ( strpos ( $ class -> getName ( ) , 'Concrete\Core\Entity' ) === 0 ) { continue ; } $ proxyFileName = $ proxyGenerator -> getProxyFileName ( $ class -> getName ( ) , $ config -> getProxyDir ( ) ) ; if ( file_exists ( $ proxyFileName ) ) { @ unlink ( $ proxyFileName ) ; } } }
Destroys all proxies related to a package .
10,092
public function getByHandle ( $ akCategoryHandle ) { $ r = $ this -> entityManager -> getRepository ( Category :: class ) ; return $ r -> findOneBy ( [ 'akCategoryHandle' => $ akCategoryHandle ] ) ; }
Get a attribute category given its handle .
10,093
public function getByID ( $ akCategoryID ) { $ r = $ this -> entityManager -> getRepository ( Category :: class ) ; return $ r -> findOneBy ( [ 'akCategoryID' => $ akCategoryID ] ) ; }
Get a attribute category given its ID .
10,094
public function getListByPackage ( Package $ pkg ) { $ r = $ this -> entityManager -> getRepository ( Category :: class ) ; return $ r -> findByPackage ( $ pkg ) ; }
Get all the available attribute categories created by a package .
10,095
public function add ( $ akCategoryHandle , $ allowSets = StandardSetManager :: ASET_ALLOW_SINGLE , $ pkg = null ) { $ category = new Category ( ) ; $ category -> setAttributeKeyCategoryHandle ( $ akCategoryHandle ) ; $ category -> setAllowAttributeSets ( $ allowSets ) ; if ( $ pkg ) { $ category -> setPackage ( $ pkg ) ; } $ this -> entityManager -> persist ( $ category ) ; $ this -> entityManager -> flush ( ) ; $ indexer = $ category -> getController ( ) -> getSearchIndexer ( ) ; if ( is_object ( $ indexer ) ) { $ indexer -> createRepository ( $ category -> getController ( ) ) ; } return $ category -> getController ( ) ; }
Create a new attribute category .
10,096
public static function getByID ( $ btsID ) { $ result = null ; $ btsID = ( int ) $ btsID ; if ( $ btsID !== 0 ) { $ app = Application :: getFacadeApplication ( ) ; $ cache = $ app -> make ( 'cache/request' ) ; $ identifier = sprintf ( 'block/type/set/%s' , $ btsID ) ; $ item = $ cache -> getItem ( $ identifier ) ; if ( $ item -> isMiss ( ) ) { $ item -> lock ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ row = $ db -> fetchAssoc ( 'select btsID, btsHandle, pkgID, btsName from BlockTypeSets where btsID = ?' , [ $ btsID ] ) ; if ( $ row !== false ) { $ result = new static ( ) ; $ result -> setPropertiesFromArray ( $ row ) ; } $ item -> set ( $ result ) -> save ( ) ; } else { $ result = $ item -> get ( ) ; } } return $ result ; }
Get a block type set given its ID .
10,097
public static function getByHandle ( $ btsHandle ) { $ result = null ; $ btsHandle = ( string ) $ btsHandle ; if ( $ btsHandle !== '' ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ row = $ db -> fetchAssoc ( 'select btsID, btsHandle, pkgID, btsName from BlockTypeSets where btsHandle = ?' , [ $ btsHandle ] ) ; if ( $ row !== false ) { $ result = new static ( ) ; $ result -> setPropertiesFromArray ( $ row ) ; } } return $ result ; }
Get a block type set given its handle .
10,098
public static function getListByPackage ( $ pkg ) { $ result = [ ] ; $ pkgID = ( int ) ( is_object ( $ pkg ) ? $ pkg -> getPackageID ( ) : $ pkg ) ; if ( $ pkgID !== 0 ) { $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; $ rs = $ db -> executeQuery ( 'select btsID from BlockTypeSets where pkgID = ? order by btsID asc' , [ $ pkgID ] ) ; while ( ( $ btsID = $ rs -> fetchColumn ( ) ) !== false ) { $ result [ ] = static :: getByID ( $ btsID ) ; } } return $ result ; }
Get the list of block type sets defined by a package .
10,099
public static function getList ( $ excluded = [ 'core_desktop' ] ) { $ result = [ ] ; $ app = Application :: getFacadeApplication ( ) ; $ db = $ app -> make ( Connection :: class ) ; if ( empty ( $ excluded ) ) { $ rs = $ db -> executeQuery ( 'select btsID from BlockTypeSets order by btsDisplayOrder asc' ) ; } else { $ rs = $ db -> executeQuery ( 'select btsID from BlockTypeSets where btsHandle not in (?) order by btsDisplayOrder asc' , [ $ excluded ] , [ Connection :: PARAM_STR_ARRAY ] ) ; } while ( ( $ btsID = $ rs -> fetchColumn ( ) ) !== false ) { $ result [ ] = static :: getByID ( $ btsID ) ; } return $ result ; }
Get the list of block type sets .