idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
23,000
protected function checkSafeMode ( ) { $ safeMode = Config :: get ( 'cms.enableSafeMode' , null ) ; if ( $ safeMode === null ) { $ safeMode = ! Config :: get ( 'app.debug' , false ) ; } if ( $ safeMode && $ this -> isDirty ( 'code' ) && strlen ( trim ( $ this -> code ) ) ) { throw new ApplicationException ( Lang :: get...
This method checks if safe mode is enabled by config and the code attribute is modified and populated . If so an exception is thrown .
23,001
public function runComponents ( ) { foreach ( $ this -> components as $ component ) { if ( $ event = $ component -> fireEvent ( 'component.beforeRun' , [ ] , true ) ) { return $ event ; } if ( $ result = $ component -> onRun ( ) ) { return $ result ; } if ( $ event = $ component -> fireEvent ( 'component.run' , [ ] , t...
Runs components defined in the settings Process halts if a component returns a value
23,002
public function getComponent ( $ componentName ) { if ( ! ( $ componentSection = $ this -> hasComponent ( $ componentName ) ) ) { return null ; } return ComponentManager :: instance ( ) -> makeComponent ( $ componentName , null , $ this -> settings [ 'components' ] [ $ componentSection ] ) ; }
Returns a component by its name . This method is used only in the back - end and for internal system needs when the standard way to access components is not an option .
23,003
public function hasComponent ( $ componentName ) { $ componentManager = ComponentManager :: instance ( ) ; $ componentName = $ componentManager -> resolve ( $ componentName ) ; foreach ( $ this -> settings [ 'components' ] as $ sectionName => $ values ) { $ result = $ sectionName ; if ( $ sectionName == $ componentName...
Checks if the object has a component with the specified name .
23,004
public function getComponentProperties ( $ componentName ) { $ key = md5 ( $ this -> theme -> getPath ( ) ) . 'component-properties' ; if ( self :: $ objectComponentPropertyMap !== null ) { $ objectComponentMap = self :: $ objectComponentPropertyMap ; } else { $ cached = Cache :: get ( $ key , false ) ; $ unserialized ...
Returns component property names and values . This method implements caching and can be used in the run - time on the front - end .
23,005
public function getViewBag ( ) { if ( $ this -> viewBagCache !== false ) { return $ this -> viewBagCache ; } $ componentName = 'viewBag' ; if ( ! isset ( $ this -> settings [ 'components' ] [ $ componentName ] ) ) { $ viewBag = new ViewBag ( null , [ ] ) ; $ viewBag -> name = $ componentName ; return $ this -> viewBagC...
Returns the configured view bag component . This method is used only in the back - end and for internal system needs when the standard way to access components is not an option .
23,006
protected function fillViewBagArray ( ) { $ viewBag = $ this -> getViewBag ( ) ; foreach ( $ viewBag -> getProperties ( ) as $ name => $ value ) { $ this -> viewBag [ $ name ] = $ value ; } $ this -> fireEvent ( 'cmsObject.fillViewBagArray' ) ; }
Copies view bag properties to the view bag array . This is required for the back - end editors .
23,007
public function getTwigNodeTree ( $ markup = false ) { $ loader = new TwigLoader ( ) ; $ twig = new Twig_Environment ( $ loader , [ ] ) ; $ twig -> addExtension ( new CmsTwigExtension ( ) ) ; $ twig -> addExtension ( new SystemTwigExtension ) ; $ stream = $ twig -> tokenize ( new Twig_Source ( $ markup === false ? $ th...
Returns Twig node tree generated from the object s markup . This method is used by the system internally and shouldn t participate in the front - end request processing .
23,008
public static function exists ( $ dirName ) { $ theme = static :: load ( $ dirName ) ; $ path = $ theme -> getPath ( ) ; return File :: isDirectory ( $ path ) ; }
Determines if a theme with given directory name exists
23,009
public static function getActiveTheme ( ) { if ( self :: $ activeThemeCache !== false ) { return self :: $ activeThemeCache ; } $ theme = static :: load ( static :: getActiveThemeCode ( ) ) ; if ( ! File :: isDirectory ( $ theme -> getPath ( ) ) ) { return self :: $ activeThemeCache = null ; } return self :: $ activeTh...
Returns the active theme object .
23,010
public static function setActiveTheme ( $ code ) { self :: resetCache ( ) ; Parameter :: set ( self :: ACTIVE_KEY , $ code ) ; Event :: fire ( 'cms.theme.setActiveTheme' , compact ( 'code' ) ) ; }
Sets the active theme . The active theme code is stored in the database and overrides the configuration cms . activeTheme parameter .
23,011
public static function getEditTheme ( ) { if ( self :: $ editThemeCache !== false ) { return self :: $ editThemeCache ; } $ theme = static :: load ( static :: getEditThemeCode ( ) ) ; if ( ! File :: isDirectory ( $ theme -> getPath ( ) ) ) { return self :: $ editThemeCache = null ; } return self :: $ editThemeCache = $...
Returns the edit theme .
23,012
public static function all ( ) { $ it = new DirectoryIterator ( themes_path ( ) ) ; $ it -> rewind ( ) ; $ result = [ ] ; foreach ( $ it as $ fileinfo ) { if ( ! $ fileinfo -> isDir ( ) || $ fileinfo -> isDot ( ) ) { continue ; } $ theme = static :: load ( $ fileinfo -> getFilename ( ) ) ; $ result [ ] = $ theme ; } re...
Returns a list of all themes .
23,013
public function getConfig ( ) { if ( $ this -> configCache !== null ) { return $ this -> configCache ; } $ path = $ this -> getPath ( ) . '/theme.yaml' ; if ( ! File :: exists ( $ path ) ) { return $ this -> configCache = [ ] ; } $ config = Yaml :: parseFile ( $ path ) ; Event :: fire ( 'cms.theme.extendConfig' , [ $ t...
Reads the theme . yaml file and returns the theme configuration values .
23,014
public function getFormConfig ( ) { $ config = $ this -> getConfigArray ( 'form' ) ; Event :: fire ( 'cms.theme.extendFormConfig' , [ $ this -> getDirName ( ) , & $ config ] ) ; return $ config ; }
Themes have a dedicated form option that provide form fields for customization this is an immutable accessor for that and also an solid anchor point for extension .
23,015
public function getConfigArray ( $ name ) { $ result = array_get ( $ this -> getConfig ( ) , $ name , [ ] ) ; if ( is_string ( $ result ) ) { $ fileName = File :: symbolizePath ( $ result ) ; if ( File :: isLocalPath ( $ fileName ) ) { $ path = $ fileName ; } else { $ path = $ this -> getPath ( ) . '/' . $ result ; } i...
Returns an array value from the theme configuration file by its name . If the value is a string it is treated as a YAML file and loaded .
23,016
public function writeConfig ( $ values = [ ] , $ overwrite = false ) { if ( ! $ overwrite ) { $ values = $ values + ( array ) $ this -> getConfig ( ) ; } $ path = $ this -> getPath ( ) . '/theme.yaml' ; if ( ! File :: exists ( $ path ) ) { throw new ApplicationException ( 'Path does not exist: ' . $ path ) ; } $ conten...
Writes to the theme . yaml file with the supplied array values .
23,017
public function getPreviewImageUrl ( ) { $ previewPath = $ this -> getConfigValue ( 'previewImage' , 'assets/images/theme-preview.png' ) ; if ( File :: exists ( $ this -> getPath ( ) . '/' . $ previewPath ) ) { return Url :: asset ( 'themes/' . $ this -> getDirName ( ) . '/' . $ previewPath ) ; } return Url :: asset ( ...
Returns the theme preview image URL . If the image file doesn t exist returns the placeholder image URL .
23,018
public static function resetCache ( ) { self :: $ activeThemeCache = false ; self :: $ editThemeCache = false ; Cache :: forget ( self :: ACTIVE_KEY ) ; Cache :: forget ( self :: EDIT_KEY ) ; }
Resets any memory or cache involved with the active or edit theme .
23,019
public function registerHalyconDatasource ( ) { $ resolver = App :: make ( 'halcyon' ) ; if ( ! $ resolver -> hasDatasource ( $ this -> dirName ) ) { $ datasource = new FileDatasource ( $ this -> getPath ( ) , App :: make ( 'files' ) ) ; $ resolver -> addDatasource ( $ this -> dirName , $ datasource ) ; } }
Ensures this theme is registered as a Halcyon them datasource .
23,020
protected function validateFileType ( $ name ) { $ extension = strtolower ( File :: extension ( $ name ) ) ; if ( ! in_array ( $ extension , $ this -> assetExtensions ) ) { return false ; } return true ; }
Check for valid asset file extension
23,021
public function getSourceContext ( $ name ) { if ( ! $ this -> validateCmsObject ( $ name ) ) { return parent :: getSourceContext ( $ name ) ; } $ content = $ this -> obj -> getTwigContent ( ) ; $ dataHolder = ( object ) [ 'content' => $ content ] ; Event :: fire ( 'cms.template.processTwigContent' , [ $ this -> obj , ...
Returns the Twig content string . This step is cached internally by Twig .
23,022
public function getCacheKey ( $ name ) { if ( ! $ this -> validateCmsObject ( $ name ) ) { return parent :: getCacheKey ( $ name ) ; } return $ this -> obj -> getTwigCacheKey ( ) ; }
Returns the Twig cache key .
23,023
public function isFresh ( $ name , $ time ) { if ( ! $ this -> validateCmsObject ( $ name ) ) { return parent :: isFresh ( $ name , $ time ) ; } return $ this -> obj -> mtime <= $ time ; }
Determines if the content is fresh .
23,024
public function getFilename ( $ name ) { if ( ! $ this -> validateCmsObject ( $ name ) ) { return parent :: getFilename ( $ name ) ; } return $ this -> obj -> getFilePath ( ) ; }
Returns the file name of the loaded template .
23,025
public function exists ( $ name ) { if ( ! $ this -> validateCmsObject ( $ name ) ) { return parent :: exists ( $ name ) ; } return $ this -> obj -> exists ; }
Checks that the template exists .
23,026
protected function validateCmsObject ( $ name ) { if ( $ name === $ this -> obj -> getFilePath ( ) ) { return true ; } if ( $ fallbackObj = $ this -> findFallbackObject ( $ name ) ) { $ this -> obj = $ fallbackObj ; return true ; } return false ; }
Internal method that checks if the template name matches the loaded object with fallback support to partials .
23,027
protected function findFallbackObject ( $ name ) { if ( strpos ( $ name , '::' ) !== false ) { return false ; } if ( array_key_exists ( $ name , $ this -> fallbackCache ) ) { return $ this -> fallbackCache [ $ name ] ; } return $ this -> fallbackCache [ $ name ] = CmsPartial :: find ( $ name ) ; }
Looks up a fallback CMS partial object .
23,028
protected function getRelationModel ( ) { list ( $ model , $ attribute ) = $ this -> resolveModelAttribute ( $ this -> valueFrom ) ; if ( ! $ model ) { throw new ApplicationException ( Lang :: get ( 'backend::lang.model.missing_relation' , [ 'class' => get_class ( $ this -> model ) , 'relation' => $ this -> valueFrom ]...
Returns the model of a relation type supports nesting via HTML array .
23,029
protected function getRelationObject ( ) { list ( $ model , $ attribute ) = $ this -> resolveModelAttribute ( $ this -> valueFrom ) ; if ( ! $ model ) { throw new ApplicationException ( Lang :: get ( 'backend::lang.model.missing_relation' , [ 'class' => get_class ( $ this -> model ) , 'relation' => $ this -> valueFrom ...
Returns the value as a relation object from the model supports nesting via HTML array .
23,030
protected function getRelationType ( ) { list ( $ model , $ attribute ) = $ this -> resolveModelAttribute ( $ this -> valueFrom ) ; return $ model -> getRelationType ( $ attribute ) ; }
Returns the value as a relation type from the model supports nesting via HTML array .
23,031
public function update ( ) { $ firstUp = ! Schema :: hasTable ( $ this -> getMigrationTableName ( ) ) ; if ( $ firstUp ) { $ this -> repository -> createRepository ( ) ; $ this -> note ( 'Migration table created' ) ; } $ modules = Config :: get ( 'cms.loadModules' , [ ] ) ; foreach ( $ modules as $ module ) { $ this ->...
Creates the migration table and updates
23,032
public function uninstall ( ) { $ plugins = $ this -> pluginManager -> getPlugins ( ) ; foreach ( $ plugins as $ name => $ plugin ) { $ this -> rollbackPlugin ( $ name ) ; } $ paths = [ ] ; $ modules = Config :: get ( 'cms.loadModules' , [ ] ) ; foreach ( $ modules as $ module ) { $ paths [ ] = $ path = base_path ( ) ....
Roll back all modules and plugins .
23,033
public function setBuildNumberManually ( ) { $ postData = [ ] ; if ( Config :: get ( 'cms.edgeUpdates' , false ) ) { $ postData [ 'edge' ] = 1 ; } $ result = $ this -> requestServerData ( 'ping' , $ postData ) ; $ build = ( int ) array_get ( $ result , 'pong' , 420 ) ; $ this -> setBuild ( $ build ) ; return $ build ; ...
Asks the gateway for the lastest build number and stores it .
23,034
public function migrateModule ( $ module ) { $ this -> migrator -> run ( base_path ( ) . '/modules/' . strtolower ( $ module ) . '/database/migrations' ) ; $ this -> note ( $ module ) ; foreach ( $ this -> migrator -> getNotes ( ) as $ note ) { $ this -> note ( ' - ' . $ note ) ; } return $ this ; }
Run migrations on a single module
23,035
public function seedModule ( $ module ) { $ className = '\\' . $ module . '\Database\Seeds\DatabaseSeeder' ; if ( ! class_exists ( $ className ) ) { return ; } $ seeder = App :: make ( $ className ) ; $ seeder -> run ( ) ; $ this -> note ( sprintf ( '<info>Seeded %s</info> ' , $ module ) ) ; return $ this ; }
Run seeds on a module
23,036
public function extractCore ( ) { $ filePath = $ this -> getFilePath ( 'core' ) ; if ( ! Zip :: extract ( $ filePath , $ this -> baseDirectory ) ) { throw new ApplicationException ( Lang :: get ( 'system::lang.zip.extract_failed' , [ 'file' => $ filePath ] ) ) ; } @ unlink ( $ filePath ) ; }
Extracts the core after it has been downloaded .
23,037
public function setBuild ( $ build , $ hash = null ) { $ params = [ 'system::core.build' => $ build ] ; if ( $ hash ) { $ params [ 'system::core.hash' ] = $ hash ; } Parameter :: set ( $ params ) ; }
Sets the build number and hash
23,038
public function updatePlugin ( $ name ) { if ( ! ( $ plugin = $ this -> pluginManager -> findByIdentifier ( $ name ) ) ) { $ this -> note ( '<error>Unable to find:</error> ' . $ name ) ; return ; } $ this -> note ( $ name ) ; $ this -> versionManager -> resetNotes ( ) -> setNotesOutput ( $ this -> notesOutput ) ; if ( ...
Runs update on a single plugin
23,039
public function rollbackPlugin ( $ name ) { if ( ! ( $ plugin = $ this -> pluginManager -> findByIdentifier ( $ name ) ) && $ this -> versionManager -> purgePlugin ( $ name ) ) { $ this -> note ( '<info>Purged from database:</info> ' . $ name ) ; return $ this ; } if ( $ this -> versionManager -> removePlugin ( $ plugi...
Removes an existing plugin
23,040
public function downloadPlugin ( $ name , $ hash , $ installation = false ) { $ fileCode = $ name . $ hash ; $ this -> requestServerFile ( 'plugin/get' , $ fileCode , $ hash , [ 'name' => $ name , 'installation' => $ installation ? 1 : 0 ] ) ; }
Downloads a plugin from the update server .
23,041
public function extractPlugin ( $ name , $ hash ) { $ fileCode = $ name . $ hash ; $ filePath = $ this -> getFilePath ( $ fileCode ) ; if ( ! Zip :: extract ( $ filePath , $ this -> baseDirectory . '/plugins/' ) ) { throw new ApplicationException ( Lang :: get ( 'system::lang.zip.extract_failed' , [ 'file' => $ filePat...
Extracts a plugin after it has been downloaded .
23,042
public function downloadTheme ( $ name , $ hash ) { $ fileCode = $ name . $ hash ; $ this -> requestServerFile ( 'theme/get' , $ fileCode , $ hash , [ 'name' => $ name ] ) ; }
Downloads a theme from the update server .
23,043
public function extractTheme ( $ name , $ hash ) { $ fileCode = $ name . $ hash ; $ filePath = $ this -> getFilePath ( $ fileCode ) ; if ( ! Zip :: extract ( $ filePath , $ this -> baseDirectory . '/themes/' ) ) { throw new ApplicationException ( Lang :: get ( 'system::lang.zip.extract_failed' , [ 'file' => $ filePath ...
Extracts a theme after it has been downloaded .
23,044
public function requestPopularProducts ( $ type = null ) { if ( $ type != 'plugin' && $ type != 'theme' ) { $ type = 'plugin' ; } $ cacheKey = 'system-updates-popular-' . $ type ; if ( Cache :: has ( $ cacheKey ) ) { return @ unserialize ( @ base64_decode ( Cache :: get ( $ cacheKey ) ) ) ? : [ ] ; } $ data = $ this ->...
Returns popular themes found on the marketplace .
23,045
protected function note ( $ message ) { if ( $ this -> notesOutput !== null ) { $ this -> notesOutput -> writeln ( $ message ) ; } else { $ this -> notes [ ] = $ message ; } return $ this ; }
Raise a note event for the migrator .
23,046
public function requestServerData ( $ uri , $ postData = [ ] ) { $ result = Http :: post ( $ this -> createServerUrl ( $ uri ) , function ( $ http ) use ( $ postData ) { $ this -> applyHttpAttributes ( $ http , $ postData ) ; } ) ; if ( $ result -> code == 404 ) { throw new ApplicationException ( Lang :: get ( 'system:...
Contacts the update server for a response .
23,047
public function requestServerFile ( $ uri , $ fileCode , $ expectedHash , $ postData = [ ] ) { $ filePath = $ this -> getFilePath ( $ fileCode ) ; $ result = Http :: post ( $ this -> createServerUrl ( $ uri ) , function ( $ http ) use ( $ postData , $ filePath ) { $ this -> applyHttpAttributes ( $ http , $ postData ) ;...
Downloads a file from the update server .
23,048
protected function createServerUrl ( $ uri ) { $ gateway = Config :: get ( 'cms.updateServer' , 'http://gateway.octobercms.com/api' ) ; if ( substr ( $ gateway , - 1 ) != '/' ) { $ gateway .= '/' ; } return $ gateway . $ uri ; }
Create a complete gateway server URL from supplied URI
23,049
protected function applyHttpAttributes ( $ http , $ postData ) { $ postData [ 'protocol_version' ] = '1.1' ; $ postData [ 'client' ] = 'october' ; $ postData [ 'server' ] = base64_encode ( serialize ( [ 'php' => PHP_VERSION , 'url' => Url :: to ( '/' ) , 'since' => PluginVersion :: orderBy ( 'created_at' ) -> value ( '...
Modifies the Network HTTP object with common attributes .
23,050
protected function createSignature ( $ data , $ secret ) { return base64_encode ( hash_hmac ( 'sha512' , http_build_query ( $ data , '' , '&' ) , base64_decode ( $ secret ) , true ) ) ; }
Create a unique signature for transmission .
23,051
public function get ( $ code = null ) { try { return $ this -> findFileObject ( $ code ) -> output ( 'inline' , true ) ; } catch ( Exception $ ex ) { } return Response :: make ( View :: make ( 'backend::404' ) , 404 ) ; }
Output file or fall back on the 404 page
23,052
public function thumb ( $ code = null , $ width = 100 , $ height = 100 , $ mode = 'auto' , $ extension = 'auto' ) { try { return $ this -> findFileObject ( $ code ) -> outputThumb ( $ width , $ height , compact ( 'mode' , 'extension' ) , true ) ; } catch ( Exception $ ex ) { } return Response :: make ( View :: make ( '...
Output thumbnail or fall back on the 404 page
23,053
public static function getThumbUrl ( $ file , $ width , $ height , $ options ) { return Backend :: url ( 'backend/files/thumb/' . self :: getUniqueCode ( $ file ) ) . '/' . $ width . '/' . $ height . '/' . $ options [ 'mode' ] . '/' . $ options [ 'extension' ] ; }
Returns the URL for downloading a system file .
23,054
public static function getUniqueCode ( $ file ) { if ( ! $ file ) { return null ; } $ hash = md5 ( $ file -> file_name . '!' . $ file -> disk_name ) ; return base64_encode ( $ file -> id . '!' . $ hash ) ; }
Returns a unique code used for masking the file identifier .
23,055
protected function findFileObject ( $ code ) { if ( ! $ code ) { throw new ApplicationException ( 'Missing code' ) ; } $ parts = explode ( '!' , base64_decode ( $ code ) ) ; if ( count ( $ parts ) < 2 ) { throw new ApplicationException ( 'Invalid code' ) ; } list ( $ id , $ hash ) = $ parts ; if ( ! $ file = FileModel ...
Locates a file model based on the unique code .
23,056
public function formExtendFields ( $ form ) { $ model = $ form -> model ; $ theme = $ this -> findThemeObject ( $ model -> theme ) ; $ config = $ theme -> getFormConfig ( ) ; if ( $ fields = array_get ( $ config , 'fields' ) ) { $ form -> addFields ( $ fields ) ; } if ( $ fields = array_get ( $ config , 'tabs.fields' )...
Add form fields defined in theme . yaml
23,057
protected function getDirName ( $ dirName = null ) { if ( $ dirName && ! $ this -> user -> hasAccess ( 'cms.manage_themes' ) ) { $ dirName = null ; } if ( $ dirName === null ) { $ dirName = CmsTheme :: getActiveThemeCode ( ) ; } return $ dirName ; }
Default to the active theme if user doesn t have access to manage all themes
23,058
protected function evalToolbarButtons ( ) { $ buttons = $ this -> toolbarButtons ; if ( is_string ( $ buttons ) ) { $ buttons = array_map ( function ( $ button ) { return strlen ( $ button ) ? $ button : '|' ; } , explode ( '|' , $ buttons ) ) ; } return $ buttons ; }
Determine the toolbar buttons to use based on config .
23,059
protected function getValidEditorLang ( ) { $ locale = App :: getLocale ( ) ; if ( $ locale == 'en' ) { return null ; } $ locale = str_replace ( '-' , '_' , strtolower ( $ locale ) ) ; $ path = base_path ( 'modules/backend/formwidgets/richeditor/assets/vendor/froala/js/languages/' . $ locale . '.js' ) ; return File :: ...
Returns a valid language code for Redactor .
23,060
protected function getPageLinkTypes ( ) { $ result = [ ] ; $ apiResult = Event :: fire ( 'backend.richeditor.listTypes' ) ; if ( is_array ( $ apiResult ) ) { foreach ( $ apiResult as $ typeList ) { if ( ! is_array ( $ typeList ) ) { continue ; } foreach ( $ typeList as $ typeCode => $ typeName ) { $ result [ $ typeCode...
Returns a list of registered page link types . This is reserved functionality for separating the links by type .
23,061
protected function getPageLinksArray ( ) { $ links = [ ] ; $ types = $ this -> getPageLinkTypes ( ) ; $ links [ ] = [ 'name' => Lang :: get ( 'backend::lang.pagelist.select_page' ) , 'url' => false ] ; $ iterator = function ( $ links , $ level = 0 ) use ( & $ iterator ) { $ result = [ ] ; foreach ( $ links as $ linkUrl...
Returns a single collection of available page links . This implementation has room to place links under different groups based on the link type .
23,062
protected function getPromptText ( ) { if ( $ this -> prompt === null ) { $ isMulti = ends_with ( $ this -> getDisplayMode ( ) , 'multi' ) ; $ this -> prompt = $ isMulti ? 'backend::lang.fileupload.upload_file' : 'backend::lang.fileupload.default_prompt' ; } return str_replace ( '%s' , '<i class="icon-upload"></i>' , e...
Returns the escaped and translated prompt text to display according to the type .
23,063
protected function getCssDimensions ( $ mode = null ) { if ( ! $ this -> imageWidth && ! $ this -> imageHeight ) { return '' ; } $ cssDimensions = '' ; if ( $ mode == 'block' ) { $ cssDimensions .= $ this -> imageWidth ? 'width: ' . $ this -> imageWidth . 'px;' : 'width: ' . $ this -> imageHeight . 'px;' ; $ cssDimensi...
Returns the CSS dimensions for the uploaded image uses auto where no dimension is provided .
23,064
public function onRemoveAttachment ( ) { $ fileModel = $ this -> getRelationModel ( ) ; if ( ( $ fileId = post ( 'file_id' ) ) && ( $ file = $ fileModel :: find ( $ fileId ) ) ) { $ this -> getRelationObject ( ) -> remove ( $ file , $ this -> sessionKey ) ; } }
Removes a file attachment .
23,065
public function onSortAttachments ( ) { if ( $ sortData = post ( 'sortOrder' ) ) { $ ids = array_keys ( $ sortData ) ; $ orders = array_values ( $ sortData ) ; $ fileModel = $ this -> getRelationModel ( ) ; $ fileModel -> setSortableOrder ( $ ids , $ orders ) ; } }
Sorts file attachments .
23,066
public function onLoadAttachmentConfig ( ) { $ fileModel = $ this -> getRelationModel ( ) ; if ( ( $ fileId = post ( 'file_id' ) ) && ( $ file = $ fileModel :: find ( $ fileId ) ) ) { $ file = $ this -> decorateFileAttributes ( $ file ) ; $ this -> vars [ 'file' ] = $ file ; $ this -> vars [ 'displayMode' ] = $ this ->...
Loads the configuration form for an attachment allowing title and description to be set .
23,067
public function onSaveAttachmentConfig ( ) { try { $ fileModel = $ this -> getRelationModel ( ) ; if ( ( $ fileId = post ( 'file_id' ) ) && ( $ file = $ fileModel :: find ( $ fileId ) ) ) { $ file -> title = post ( 'title' ) ; $ file -> description = post ( 'description' ) ; $ file -> save ( ) ; return [ 'displayName' ...
Commit the changes of the attachment configuration form .
23,068
protected function decorateFileAttributes ( $ file ) { if ( ! $ file -> isPublic ( ) ) { $ path = $ thumb = FilesController :: getDownloadUrl ( $ file ) ; if ( $ this -> imageWidth || $ this -> imageHeight ) { $ thumb = FilesController :: getThumbUrl ( $ file , $ this -> imageWidth , $ this -> imageHeight , $ this -> t...
Adds the bespoke attributes used internally by this widget . - thumbUrl - pathUrl
23,069
public function index ( ) { $ this -> addJs ( '/modules/cms/assets/js/october.cmspage.js' , 'core' ) ; $ this -> addJs ( '/modules/cms/assets/js/october.dragcomponents.js' , 'core' ) ; $ this -> addJs ( '/modules/cms/assets/js/october.tokenexpander.js' , 'core' ) ; $ this -> addCss ( '/modules/cms/assets/css/october.co...
Index page action
23,070
public function index_onOpenTemplate ( ) { $ this -> validateRequestTheme ( ) ; $ type = Request :: input ( 'type' ) ; $ template = $ this -> loadTemplate ( $ type , Request :: input ( 'path' ) ) ; $ widget = $ this -> makeTemplateFormWidget ( $ type , $ template ) ; $ this -> vars [ 'templatePath' ] = Request :: input...
Opens an existing template from the index page
23,071
public function onSave ( ) { $ this -> validateRequestTheme ( ) ; $ type = Request :: input ( 'templateType' ) ; $ templatePath = trim ( Request :: input ( 'templatePath' ) ) ; $ template = $ templatePath ? $ this -> loadTemplate ( $ type , $ templatePath ) : $ this -> createTemplate ( $ type ) ; $ formWidget = $ this ...
Saves the template currently open
23,072
public function onCreateTemplate ( ) { $ type = Request :: input ( 'type' ) ; $ template = $ this -> createTemplate ( $ type ) ; if ( $ type === 'asset' ) { $ template -> fileName = $ this -> widget -> assetList -> getCurrentRelativePath ( ) ; } $ widget = $ this -> makeTemplateFormWidget ( $ type , $ template ) ; $ th...
Create a new template
23,073
public function onDeleteTemplates ( ) { $ this -> validateRequestTheme ( ) ; $ type = Request :: input ( 'type' ) ; $ templates = Request :: input ( 'template' ) ; $ error = null ; $ deleted = [ ] ; try { foreach ( $ templates as $ path => $ selected ) { if ( $ selected ) { $ this -> loadTemplate ( $ type , $ path ) ->...
Deletes multiple templates at the same time
23,074
public function onDelete ( ) { $ this -> validateRequestTheme ( ) ; $ type = Request :: input ( 'templateType' ) ; $ this -> loadTemplate ( $ type , trim ( Request :: input ( 'templatePath' ) ) ) -> delete ( ) ; $ this -> fireSystemEvent ( 'cms.template.delete' , [ $ type ] ) ; }
Deletes a template
23,075
public function onGetTemplateList ( ) { $ this -> validateRequestTheme ( ) ; $ page = Page :: inTheme ( $ this -> theme ) ; return [ 'layouts' => $ page -> getLayoutOptions ( ) ] ; }
Returns list of available templates
23,076
public function onExpandMarkupToken ( ) { if ( ! $ alias = post ( 'tokenName' ) ) { throw new ApplicationException ( trans ( 'cms::lang.component.no_records' ) ) ; } if ( ( ! $ type = post ( 'tokenType' ) ) && $ type !== 'component' ) { return ; } if ( ! ( $ names = ( array ) post ( 'component_names' ) ) || ! ( $ alias...
Remembers an open or closed state for a supplied token for example component folders .
23,077
protected function resolveTypeClassName ( $ type ) { $ types = [ 'page' => Page :: class , 'partial' => Partial :: class , 'layout' => Layout :: class , 'content' => Content :: class , 'asset' => Asset :: class ] ; if ( ! array_key_exists ( $ type , $ types ) ) { throw new ApplicationException ( trans ( 'cms::lang.temp...
Reolves a template type to its class name
23,078
protected function loadTemplate ( $ type , $ path ) { $ class = $ this -> resolveTypeClassName ( $ type ) ; if ( ! ( $ template = call_user_func ( [ $ class , 'load' ] , $ this -> theme , $ path ) ) ) { throw new ApplicationException ( trans ( 'cms::lang.template.not_found' ) ) ; } $ this -> fireSystemEvent ( 'cms.temp...
Returns an existing template of a given type
23,079
protected function createTemplate ( $ type ) { $ class = $ this -> resolveTypeClassName ( $ type ) ; if ( ! ( $ template = $ class :: inTheme ( $ this -> theme ) ) ) { throw new ApplicationException ( trans ( 'cms::lang.template.not_found' ) ) ; } return $ template ; }
Creates a new template of a given type
23,080
protected function getTabTitle ( $ type , $ template ) { if ( $ type === 'page' ) { $ result = $ template -> title ? : $ template -> getFileName ( ) ; if ( ! $ result ) { $ result = trans ( 'cms::lang.page.new' ) ; } return $ result ; } if ( $ type === 'partial' || $ type === 'layout' || $ type === 'content' || $ type ...
Returns the text for a template tab
23,081
protected function makeTemplateFormWidget ( $ type , $ template , $ alias = null ) { $ formConfigs = [ 'page' => '~/modules/cms/classes/page/fields.yaml' , 'partial' => '~/modules/cms/classes/partial/fields.yaml' , 'layout' => '~/modules/cms/classes/layout/fields.yaml' , 'content' => '~/modules/cms/classes/content/fiel...
Returns a form widget for a specified template type .
23,082
protected function upgradeSettings ( $ settings ) { $ componentProperties = post ( 'component_properties' ) ; $ componentNames = post ( 'component_names' ) ; $ componentAliases = post ( 'component_aliases' ) ; if ( $ componentProperties !== null ) { if ( $ componentNames === null || $ componentAliases === null ) { thro...
Processes the component settings so they are ready to be saved
23,083
protected function bindFormWidgetToController ( ) { $ alias = Request :: input ( 'formWidgetAlias' ) ; $ type = Request :: input ( 'templateType' ) ; $ object = $ this -> loadTemplate ( $ type , Request :: input ( 'templatePath' ) ) ; $ widget = $ this -> makeTemplateFormWidget ( $ type , $ object , $ alias ) ; $ widge...
Binds the active form widget to the controller
23,084
protected function checkPermissionRedirect ( ) { if ( ! $ this -> user -> hasAccess ( 'backend.access_dashboard' ) ) { $ true = function ( ) { return true ; } ; if ( $ first = array_first ( BackendMenu :: listMainMenuItems ( ) , $ true ) ) { return Redirect :: intended ( $ first -> url ) ; } } }
Custom permissions check that will redirect to the next available menu item if permission to this page is denied .
23,085
public function addViewPath ( $ path ) { $ this -> viewPath = ( array ) $ this -> viewPath ; if ( is_array ( $ path ) ) { $ this -> viewPath = array_merge ( $ path , $ this -> viewPath ) ; } else { array_unshift ( $ this -> viewPath , $ path ) ; } }
Prepends a path on the available view path locations .
23,086
public function makePartial ( $ partial , $ params = [ ] , $ throwException = true ) { $ notRealPath = realpath ( $ partial ) === false || is_dir ( $ partial ) === true ; if ( ! File :: isPathSymbol ( $ partial ) && $ notRealPath ) { $ folder = strpos ( $ partial , '/' ) !== false ? dirname ( $ partial ) . '/' : '' ; $...
Render a partial file contents located in the views folder .
23,087
public function makeView ( $ view ) { $ viewPath = $ this -> getViewPath ( strtolower ( $ view ) . '.htm' ) ; $ contents = $ this -> makeFileContents ( $ viewPath ) ; return $ this -> makeViewContent ( $ contents ) ; }
Loads a view with the name specified . Applies layout if its name is provided by the parent object . The view file must be situated in the views directory and has the extension htm .
23,088
public function makeViewContent ( $ contents , $ layout = null ) { if ( $ this -> suppressLayout || $ this -> layout == '' ) { return $ contents ; } Block :: set ( 'undefinedBlock' , $ contents ) ; Block :: append ( 'body' , Block :: get ( 'undefinedBlock' ) ) ; return $ this -> makeLayout ( $ layout ) ; }
Renders supplied contents inside a layout .
23,089
public function makeLayout ( $ name = null , $ params = [ ] , $ throwException = true ) { $ layout = $ name ?? $ this -> layout ; if ( $ layout == '' ) { return '' ; } $ layoutPath = $ this -> getViewPath ( $ layout . '.htm' , $ this -> layoutPath ) ; if ( ! File :: exists ( $ layoutPath ) ) { if ( $ throwException ) {...
Render a layout .
23,090
public function makeLayoutPartial ( $ partial , $ params = [ ] ) { if ( ! File :: isLocalPath ( $ partial ) && ! File :: isPathSymbol ( $ partial ) ) { $ folder = strpos ( $ partial , '/' ) !== false ? dirname ( $ partial ) . '/' : '' ; $ partial = $ folder . '_' . strtolower ( basename ( $ partial ) ) ; } return $ thi...
Renders a layout partial
23,091
public function makeFileContents ( $ filePath , $ extraParams = [ ] ) { if ( ! strlen ( $ filePath ) || ! File :: isFile ( $ filePath ) || ( ! File :: isLocalPath ( $ filePath ) && Config :: get ( 'cms.restrictBaseDir' , true ) ) ) { return '' ; } if ( ! is_array ( $ extraParams ) ) { $ extraParams = [ ] ; } $ vars = a...
Includes a file path using output buffering . Ensures that vars are available .
23,092
protected function getConfigFile ( $ name = 'app' ) { $ env = $ this -> option ( 'env' ) ? $ this -> option ( 'env' ) . '/' : '' ; $ name .= '.php' ; $ contents = File :: get ( $ path = $ this -> laravel [ 'path.config' ] . "/{$env}{$name}" ) ; return $ path ; }
Get a config file and contents .
23,093
protected function stripVendorDir ( $ path , $ vendorDir ) { $ path = realpath ( $ path ) ; $ vendorDir = realpath ( $ vendorDir ) ; if ( strpos ( $ path , $ vendorDir ) === 0 ) { $ path = substr ( $ path , strlen ( $ vendorDir ) ) ; } return $ path ; }
Removes the vendor directory from a path .
23,094
public function addRawContentToMailer ( $ message , $ content , $ data ) { $ template = new MailTemplate ; $ template -> fillFromContent ( $ content ) ; $ this -> addContentToMailerInternal ( $ message , $ template , $ data ) ; return true ; }
Same as addContentToMailer except with raw content .
23,095
public function addContentToMailer ( $ message , $ code , $ data , $ plainOnly = false ) { if ( isset ( $ this -> templateCache [ $ code ] ) ) { $ template = $ this -> templateCache [ $ code ] ; } else { $ this -> templateCache [ $ code ] = $ template = MailTemplate :: findOrMakeTemplate ( $ code ) ; } if ( ! $ templat...
This function hijacks the addContent method of the October \ Rain \ Mail \ Mailer class using the mailer . beforeAddContent event .
23,096
protected function addContentToMailerInternal ( $ message , $ template , $ data , $ plainOnly = false ) { $ this -> startTwig ( ) ; $ globalVars = ViewHelper :: getGlobalVars ( ) ; if ( ! empty ( $ globalVars ) ) { $ data = ( array ) $ data + $ globalVars ; } $ swiftMessage = $ message -> getSwiftMessage ( ) ; if ( emp...
Internal method used to share logic between addRawContentToMailer and addContentToMailer
23,097
protected function renderTwig ( $ content , $ data = [ ] ) { if ( $ this -> isTwigStarted ) { return Twig :: parse ( $ content , $ data ) ; } $ this -> startTwig ( ) ; $ result = Twig :: parse ( $ content , $ data ) ; $ this -> stopTwig ( ) ; return $ result ; }
Internal helper for rendering Twig
23,098
protected function startTwig ( ) { if ( $ this -> isTwigStarted ) { return ; } $ this -> isTwigStarted = true ; $ markupManager = MarkupManager :: instance ( ) ; $ markupManager -> beginTransaction ( ) ; $ markupManager -> registerTokenParsers ( [ new MailPartialTokenParser ] ) ; }
Temporarily registers mail based token parsers with Twig .
23,099
protected function stopTwig ( ) { if ( ! $ this -> isTwigStarted ) { return ; } $ markupManager = MarkupManager :: instance ( ) ; $ markupManager -> endTransaction ( ) ; $ this -> isTwigStarted = false ; }
Indicates that we are finished with Twig .