idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
23,100
public function loadRegisteredTemplates ( ) { foreach ( $ this -> callbacks as $ callback ) { $ callback ( $ this ) ; } $ plugins = PluginManager :: instance ( ) -> getPlugins ( ) ; foreach ( $ plugins as $ pluginId => $ pluginObj ) { $ layouts = $ pluginObj -> registerMailLayouts ( ) ; if ( is_array ( $ layouts ) ) { ...
Loads registered mail templates from modules and plugins
23,101
public function registerMailTemplates ( array $ definitions ) { if ( ! $ this -> registeredTemplates ) { $ this -> registeredTemplates = [ ] ; } if ( ! isset ( $ definitions [ 0 ] ) ) { $ definitions = array_keys ( $ definitions ) ; } $ definitions = array_combine ( $ definitions , $ definitions ) ; $ this -> registere...
Registers mail views and manageable templates .
23,102
public function onFilterUpdate ( ) { $ this -> defineFilterScopes ( ) ; if ( ! $ scope = post ( 'scopeName' ) ) { return ; } $ scope = $ this -> getScope ( $ scope ) ; switch ( $ scope -> type ) { case 'group' : $ active = $ this -> optionsFromAjax ( post ( 'options.active' ) ) ; $ this -> setScopeValue ( $ scope , $ a...
Update a filter scope value .
23,103
public function onFilterGetOptions ( ) { $ this -> defineFilterScopes ( ) ; $ searchQuery = post ( 'search' ) ; if ( ! $ scopeName = post ( 'scopeName' ) ) { return ; } $ scope = $ this -> getScope ( $ scopeName ) ; $ activeKeys = $ scope -> value ? array_keys ( $ scope -> value ) : [ ] ; $ available = $ this -> getAva...
Returns available options for group scope type .
23,104
protected function getAvailableOptions ( $ scope , $ searchQuery = null ) { if ( $ scope -> options ) { return $ this -> getOptionsFromArray ( $ scope , $ searchQuery ) ; } $ available = [ ] ; $ nameColumn = $ this -> getScopeNameFrom ( $ scope ) ; $ options = $ this -> getOptionsFromModel ( $ scope , $ searchQuery ) ;...
Returns the available options a scope can use either from the model relation or from a supplied array . Optionally apply a search constraint to the options .
23,105
protected function filterActiveOptions ( array $ activeKeys , array & $ availableOptions ) { $ active = [ ] ; foreach ( $ availableOptions as $ id => $ option ) { if ( ! in_array ( $ id , $ activeKeys ) ) { continue ; } $ active [ $ id ] = $ option ; unset ( $ availableOptions [ $ id ] ) ; } return $ active ; }
Removes any already selected options from the available options returns a newly built array .
23,106
protected function getOptionsFromModel ( $ scope , $ searchQuery = null ) { $ model = $ this -> scopeModels [ $ scope -> scopeName ] ; $ query = $ model -> newQuery ( ) ; $ query -> limit ( 500 ) ; $ this -> fireSystemEvent ( 'backend.filter.extendQuery' , [ $ query , $ scope ] ) ; if ( ! $ searchQuery ) { return $ que...
Looks at the model for defined scope items .
23,107
protected function getOptionsFromArray ( $ scope , $ searchQuery = null ) { $ options = $ scope -> options ; if ( is_scalar ( $ options ) ) { $ model = $ this -> scopeModels [ $ scope -> scopeName ] ; $ methodName = $ options ; if ( ! $ model -> methodExists ( $ methodName ) ) { throw new ApplicationException ( Lang ::...
Look at the defined set of options for scope items or the model method .
23,108
protected function filterOptionsBySearch ( $ options , $ query ) { $ filteredOptions = [ ] ; $ optionMatchesSearch = function ( $ words , $ option ) { foreach ( $ words as $ word ) { $ word = trim ( $ word ) ; if ( ! strlen ( $ word ) ) { continue ; } if ( ! Str :: contains ( Str :: lower ( $ option ) , $ word ) ) { re...
Filters an array of options by a search term .
23,109
protected function defineFilterScopes ( ) { if ( $ this -> scopesDefined ) { return ; } $ this -> fireSystemEvent ( 'backend.filter.extendScopesBefore' ) ; if ( ! isset ( $ this -> scopes ) || ! is_array ( $ this -> scopes ) ) { $ this -> scopes = [ ] ; } $ this -> addScopes ( $ this -> scopes ) ; $ this -> fireSystemE...
Creates a flat array of filter scopes from the configuration .
23,110
public function addScopes ( array $ scopes ) { foreach ( $ scopes as $ name => $ config ) { $ scopeObj = $ this -> makeFilterScope ( $ name , $ config ) ; if ( $ scopeObj -> context !== null ) { $ context = is_array ( $ scopeObj -> context ) ? $ scopeObj -> context : [ $ scopeObj -> context ] ; if ( ! in_array ( $ this...
Programatically add scopes used internally and for extensibility .
23,111
protected function makeFilterScope ( $ name , $ config ) { $ label = $ config [ 'label' ] ?? null ; $ scopeType = $ config [ 'type' ] ?? null ; $ scope = new FilterScope ( $ name , $ label ) ; $ scope -> displayAs ( $ scopeType , $ config ) ; $ scope -> value = $ this -> getScopeValue ( $ scope , @ $ config [ 'default'...
Creates a filter scope object from name and configuration .
23,112
public function applyAllScopesToQuery ( $ query ) { $ this -> defineFilterScopes ( ) ; foreach ( $ this -> allScopes as $ scope ) { $ this -> applyScopeToQuery ( $ scope , $ query ) ; } return $ query ; }
Applies all scopes to a DB query .
23,113
public function getScopeValue ( $ scope , $ default = null ) { if ( is_string ( $ scope ) ) { $ scope = $ this -> getScope ( $ scope ) ; } $ cacheKey = 'scope-' . $ scope -> scopeName ; return $ this -> getSession ( $ cacheKey , $ default ) ; }
Returns a scope value for this widget instance .
23,114
public function setScopeValue ( $ scope , $ value ) { if ( is_string ( $ scope ) ) { $ scope = $ this -> getScope ( $ scope ) ; } $ cacheKey = 'scope-' . $ scope -> scopeName ; $ this -> putSession ( $ cacheKey , $ value ) ; $ scope -> value = $ value ; }
Sets an scope value for this widget instance .
23,115
public function getScope ( $ scope ) { if ( ! isset ( $ this -> allScopes [ $ scope ] ) ) { throw new ApplicationException ( 'No definition for scope ' . $ scope ) ; } return $ this -> allScopes [ $ scope ] ; }
Get a specified scope object
23,116
public function getScopeNameFrom ( $ scope ) { if ( is_string ( $ scope ) ) { $ scope = $ this -> getScope ( $ scope ) ; } return $ scope -> nameFrom ; }
Returns the display name column for a scope .
23,117
protected function datesFromAjax ( $ ajaxDates ) { $ dates = [ ] ; $ dateRegex = '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/' ; if ( null !== $ ajaxDates ) { if ( ! is_array ( $ ajaxDates ) ) { if ( preg_match ( $ dateRegex , $ ajaxDates ) ) { $ dates = [ $ ajaxDates ] ; } } else { foreach ( $ ajaxDates as $ i => $ date ) {...
Convert an array from the posted dates
23,118
protected function numbersFromAjax ( $ ajaxNumbers ) { $ numbers = [ ] ; $ numberRegex = '/\d/' ; if ( ! empty ( $ ajaxNumbers ) ) { if ( ! is_array ( $ ajaxNumbers ) && preg_match ( $ numberRegex , $ ajaxNumbers ) ) { $ numbers = [ $ ajaxNumbers ] ; } else { foreach ( $ ajaxNumbers as $ i => $ number ) { if ( preg_mat...
Convert an array from the posted numbers
23,119
public function getFieldOptions ( ) { $ options = $ this -> formField -> options ( ) ; if ( ! $ options && $ this -> mode === static :: MODE_RELATION ) { $ options = $ this -> getRelationModel ( ) -> lists ( $ this -> nameFrom ) ; } return $ options ; }
Returns defined field options or from the relation if available .
23,120
public function getDataTableOptions ( $ field , $ data ) { $ methodName = 'get' . studly_case ( $ this -> fieldName ) . 'DataTableOptions' ; if ( ! $ this -> model -> methodExists ( $ methodName ) && ! $ this -> model -> methodExists ( 'getDataTableOptions' ) ) { throw new ApplicationException ( Lang :: get ( 'backend:...
Looks at the model for getXXXDataTableOptions or getDataTableOptions methods to obtain values for autocomplete field types .
23,121
public function handleError ( $ exception ) { $ errorMessage = ErrorHandler :: getDetailedMessage ( $ exception ) ; $ this -> fatalError = $ errorMessage ; $ this -> vars [ 'fatalError' ] = $ errorMessage ; }
Sets standard page variables in the case of a controller error .
23,122
public function combineAssets ( array $ assets , $ localPath = '' ) { if ( empty ( $ assets ) ) { return '' ; } $ assetPath = ! empty ( $ localPath ) ? $ localPath : $ this -> assetPath ; return Url :: to ( CombineAssets :: combine ( $ assets , $ assetPath ) ) ; }
Run the provided assets through the Asset Combiner
23,123
public function getAssetPaths ( ) { $ this -> removeDuplicates ( ) ; $ assets = [ ] ; foreach ( $ this -> assets as $ type => $ collection ) { $ assets [ $ type ] = [ ] ; foreach ( $ collection as $ asset ) { $ assets [ $ type ] [ ] = $ this -> getAssetEntryBuildPath ( $ asset ) ; } } return $ assets ; }
Returns an array of all registered asset paths .
23,124
public function getAssetPath ( $ fileName , $ assetPath = null ) { if ( starts_with ( $ fileName , [ '//' , 'http://' , 'https://' ] ) ) { return $ fileName ; } if ( ! $ assetPath ) { $ assetPath = $ this -> assetPath ; } if ( substr ( $ fileName , 0 , 1 ) == '/' || $ assetPath === null ) { return $ fileName ; } return...
Locates a file based on it s definition . If the file starts with a forward slash it will be returned in context of the application public path otherwise it will be returned in context of the asset path .
23,125
protected function getAssetEntryBuildPath ( $ asset ) { $ path = $ asset [ 'path' ] ; if ( isset ( $ asset [ 'attributes' ] [ 'build' ] ) ) { $ build = $ asset [ 'attributes' ] [ 'build' ] ; if ( $ build == 'core' ) { $ build = 'v' . Parameter :: get ( 'system::core.build' , 1 ) ; } elseif ( $ pluginVersion = PluginVer...
Internal helper attaches a build code to an asset path
23,126
protected function getAssetScheme ( $ asset ) { if ( starts_with ( $ asset , [ '//' , 'http://' , 'https://' ] ) ) { return $ asset ; } if ( substr ( $ asset , 0 , 1 ) == '/' ) { $ asset = Url :: asset ( $ asset ) ; } return $ asset ; }
Internal helper get asset scheme
23,127
protected function removeDuplicates ( ) { foreach ( $ this -> assets as $ type => & $ collection ) { $ pathCache = [ ] ; foreach ( $ collection as $ key => $ asset ) { if ( ! $ path = array_get ( $ asset , 'path' ) ) { continue ; } if ( isset ( $ pathCache [ $ path ] ) ) { array_forget ( $ collection , $ key ) ; contin...
Removes duplicate assets from the entire collection .
23,128
public static function render ( $ pageFile , $ parameters = [ ] , $ theme = null ) { if ( ! $ theme && ( ! $ theme = Theme :: getActiveTheme ( ) ) ) { throw new CmsException ( Lang :: get ( 'cms::lang.theme.active.not_found' ) ) ; } $ controller = new static ( $ theme ) ; $ controller -> getRouter ( ) -> setParameters ...
Renders a page in its entirety including component initialization . AJAX will be disabled for this process .
23,129
protected function execPageCycle ( ) { if ( $ event = $ this -> fireSystemEvent ( 'cms.page.start' ) ) { return $ event ; } if ( $ this -> layoutObj ) { CmsException :: mask ( $ this -> layout , 300 ) ; $ response = ( ( $ result = $ this -> layoutObj -> onStart ( ) ) || ( $ result = $ this -> layout -> runComponents ( ...
Executes the page life cycle . Creates an object from the PHP sections of the page and it s layout then executes their life cycle functions .
23,130
protected function postProcessResult ( $ page , $ url , $ content ) { $ content = MediaViewHelper :: instance ( ) -> processHtml ( $ content ) ; $ dataHolder = ( object ) [ 'content' => $ content ] ; $ this -> fireSystemEvent ( 'cms.page.postprocess' , [ $ url , $ page , $ dataHolder ] ) ; return $ dataHolder -> conten...
Post - processes page HTML code before it s sent to the client . Note for pre - processing see cms . template . processTwigContent event .
23,131
protected function initTwigEnvironment ( ) { $ this -> loader = new TwigLoader ; $ useCache = ! Config :: get ( 'cms.twigNoCache' ) ; $ isDebugMode = Config :: get ( 'app.debug' , false ) ; $ strictVariables = Config :: get ( 'cms.enableTwigStrictVariables' , false ) ; $ strictVariables = $ strictVariables ?? $ isDebug...
Initializes the Twig environment and loader . Registers the \ Cms \ Twig \ Extension object with Twig .
23,132
protected function initCustomObjects ( ) { $ this -> layoutObj = null ; if ( ! $ this -> layout -> isFallBack ( ) ) { CmsException :: mask ( $ this -> layout , 300 ) ; $ parser = new CodeParser ( $ this -> layout ) ; $ this -> layoutObj = $ parser -> source ( $ this -> page , $ this -> layout , $ this ) ; CmsException ...
Initializes the custom layout and page objects .
23,133
protected function initComponents ( ) { if ( ! $ this -> layout -> isFallBack ( ) ) { foreach ( $ this -> layout -> settings [ 'components' ] as $ component => $ properties ) { list ( $ name , $ alias ) = strpos ( $ component , ' ' ) ? explode ( ' ' , $ component ) : [ $ component , $ component ] ; $ this -> addCompone...
Initializes the components for the layout and page .
23,134
public function getAjaxHandler ( ) { if ( ! Request :: ajax ( ) || Request :: method ( ) != 'POST' ) { return null ; } if ( $ handler = Request :: header ( 'X_OCTOBER_REQUEST_HANDLER' ) ) { return trim ( $ handler ) ; } return null ; }
Returns the AJAX handler for the current request if available .
23,135
protected function execAjaxHandlers ( ) { if ( $ handler = $ this -> getAjaxHandler ( ) ) { try { if ( ! preg_match ( '/^(?:\w+\:{2})?on[A-Z]{1}[\w+]*$/' , $ handler ) ) { throw new CmsException ( Lang :: get ( 'cms::lang.ajax_handler.invalid_name' , [ 'name' => $ handler ] ) ) ; } if ( $ partialList = trim ( Request :...
Executes the page layout component and plugin AJAX handlers .
23,136
protected function runAjaxHandler ( $ handler ) { if ( $ event = $ this -> fireSystemEvent ( 'cms.ajax.beforeRunHandler' , [ $ handler ] ) ) { return $ event ; } if ( strpos ( $ handler , '::' ) ) { list ( $ componentName , $ handlerName ) = explode ( '::' , $ handler ) ; $ componentObj = $ this -> findComponentByName ...
Tries to find and run an AJAX handler in the page layout components and plugins . The method stops as soon as the handler is found .
23,137
public function renderPage ( ) { $ contents = $ this -> pageContents ; if ( $ event = $ this -> fireSystemEvent ( 'cms.page.render' , [ $ contents ] ) ) { return $ event ; } return $ contents ; }
Renders a requested page . The framework uses this method internally .
23,138
public function renderContent ( $ name , $ parameters = [ ] ) { if ( $ event = $ this -> fireSystemEvent ( 'cms.page.beforeRenderContent' , [ $ name ] ) ) { $ content = $ event ; } elseif ( ( $ content = Content :: loadCached ( $ this -> theme , $ name ) ) === null ) { throw new CmsException ( Lang :: get ( 'cms::lang....
Renders a requested content file . The framework uses this method internally .
23,139
public function renderComponent ( $ name , $ parameters = [ ] ) { $ result = null ; $ previousContext = $ this -> componentContext ; if ( $ componentObj = $ this -> findComponentByName ( $ name ) ) { $ componentObj -> id = uniqid ( $ name ) ; $ componentObj -> setProperties ( array_merge ( $ componentObj -> getProperti...
Renders a component s default content preserves the previous component context .
23,140
public function currentPageUrl ( $ parameters = [ ] , $ routePersistence = true ) { if ( ! $ currentFile = $ this -> page -> getFileName ( ) ) { return null ; } return $ this -> pageUrl ( $ currentFile , $ parameters , $ routePersistence ) ; }
Looks up the current page URL with supplied parameters and route persistence .
23,141
public function themeUrl ( $ url = null ) { $ themeDir = $ this -> getTheme ( ) -> getDirName ( ) ; if ( is_array ( $ url ) ) { $ _url = Url :: to ( CombineAssets :: combine ( $ url , themes_path ( ) . '/' . $ themeDir ) ) ; } else { $ _url = Config :: get ( 'cms.themesPath' , '/themes' ) . '/' . $ themeDir ; if ( $ ur...
Converts supplied URL to a theme URL relative to the website root . If the URL provided is an array then the files will be combined .
23,142
public function addComponent ( $ name , $ alias , $ properties , $ addToLayout = false ) { $ manager = ComponentManager :: instance ( ) ; if ( $ addToLayout ) { if ( ! $ componentObj = $ manager -> makeComponent ( $ name , $ this -> layoutObj , $ properties ) ) { throw new CmsException ( Lang :: get ( 'cms::lang.compon...
Adds a component to the page object
23,143
public function findComponentByName ( $ name ) { if ( isset ( $ this -> page -> components [ $ name ] ) ) { return $ this -> page -> components [ $ name ] ; } if ( isset ( $ this -> layout -> components [ $ name ] ) ) { return $ this -> layout -> components [ $ name ] ; } $ partialComponent = $ this -> partialStack -> ...
Searches the layout and page components by an alias
23,144
public function findComponentByHandler ( $ handler ) { foreach ( $ this -> page -> components as $ component ) { if ( $ component -> methodExists ( $ handler ) ) { return $ component ; } } foreach ( $ this -> layout -> components as $ component ) { if ( $ component -> methodExists ( $ handler ) ) { return $ component ;...
Searches the layout and page components by an AJAX handler
23,145
public function findComponentByPartial ( $ partial ) { foreach ( $ this -> page -> components as $ component ) { if ( ComponentPartial :: check ( $ component , $ partial ) ) { return $ component ; } } foreach ( $ this -> layout -> components as $ component ) { if ( ComponentPartial :: check ( $ component , $ partial ) ...
Searches the layout and page components by a partial file
23,146
public function getLoadValue ( ) { if ( $ this -> formField -> value !== null ) { return $ this -> formField -> value ; } $ defaultValue = ! $ this -> model -> exists ? $ this -> formField -> getDefaultFromData ( $ this -> data ? : $ this -> model ) : null ; return $ this -> formField -> getValueFromData ( $ this -> da...
Returns the value for this form field supports nesting via HTML array .
23,147
public function instance ( ) { if ( isset ( self :: $ instances [ $ this -> recordCode ] ) ) { return self :: $ instances [ $ this -> recordCode ] ; } if ( ! $ item = $ this -> getSettingsRecord ( ) ) { $ this -> model -> initSettingsData ( ) ; $ item = $ this -> model ; } return self :: $ instances [ $ this -> recordC...
Create an instance of the settings model intended as a static method
23,148
protected function getCacheKey ( ) { $ item = UserPreference :: forUser ( ) ; $ userId = $ item -> userContext ? $ item -> userContext -> id : 0 ; return $ this -> recordCode . '-userpreference-' . $ userId ; }
Returns a cache key for this record .
23,149
public function onSearch ( ) { $ this -> setSearchTerm ( Input :: get ( 'search' ) ) ; $ this -> prepareVars ( ) ; return [ '#' . $ this -> getId ( 'item-list' ) => $ this -> makePartial ( 'item-list' ) , '#' . $ this -> getId ( 'folder-path' ) => $ this -> makePartial ( 'folder-path' ) ] ; }
Perform search AJAX handler
23,150
public function onGoToFolder ( ) { $ path = Input :: get ( 'path' ) ; if ( Input :: get ( 'clearCache' ) ) { MediaLibrary :: instance ( ) -> resetCache ( ) ; } if ( Input :: get ( 'resetSearch' ) ) { $ this -> setSearchTerm ( null ) ; } $ this -> setCurrentFolder ( $ path ) ; $ this -> prepareVars ( ) ; return [ '#' . ...
Change view AJAX handler
23,151
public function onGenerateThumbnails ( ) { $ batch = Input :: get ( 'batch' ) ; if ( ! is_array ( $ batch ) ) { return ; } $ result = [ ] ; foreach ( $ batch as $ thumbnailInfo ) { $ result [ ] = $ this -> generateThumbnail ( $ thumbnailInfo ) ; } return [ 'generatedThumbnails' => $ result ] ; }
Generate thumbnail AJAX handler
23,152
public function onGetSidebarThumbnail ( ) { $ path = Input :: get ( 'path' ) ; $ lastModified = Input :: get ( 'lastModified' ) ; $ thumbnailParams = $ this -> getThumbnailParams ( ) ; $ thumbnailParams [ 'width' ] = 300 ; $ thumbnailParams [ 'height' ] = 255 ; $ thumbnailParams [ 'mode' ] = 'auto' ; $ path = MediaLibr...
Get thumbnail AJAX handler
23,153
public function onChangeView ( ) { $ viewMode = Input :: get ( 'view' ) ; $ path = Input :: get ( 'path' ) ; $ this -> setViewMode ( $ viewMode ) ; $ this -> setCurrentFolder ( $ path ) ; $ this -> prepareVars ( ) ; return [ '#' . $ this -> getId ( 'item-list' ) => $ this -> makePartial ( 'item-list' ) , '#' . $ this -...
Set view preference AJAX handler
23,154
public function onSetFilter ( ) { $ filter = Input :: get ( 'filter' ) ; $ path = Input :: get ( 'path' ) ; $ this -> setFilter ( $ filter ) ; $ this -> setCurrentFolder ( $ path ) ; $ this -> prepareVars ( ) ; return [ '#' . $ this -> getId ( 'item-list' ) => $ this -> makePartial ( 'item-list' ) , '#' . $ this -> get...
Set filter preference AJAX handler
23,155
public function onSetSorting ( ) { $ sortBy = Input :: get ( 'sortBy' , $ this -> getSortBy ( ) ) ; $ sortDirection = Input :: get ( 'sortDirection' , $ this -> getSortDirection ( ) ) ; $ path = Input :: get ( 'path' ) ; $ this -> setSortBy ( $ sortBy ) ; $ this -> setSortDirection ( $ sortDirection ) ; $ this -> setCu...
Set sorting preference AJAX handler
23,156
public function onDeleteItem ( ) { $ this -> abortIfReadOnly ( ) ; $ paths = Input :: get ( 'paths' ) ; if ( ! is_array ( $ paths ) ) { throw new ApplicationException ( 'Invalid input data' ) ; } $ library = MediaLibrary :: instance ( ) ; $ filesToDelete = [ ] ; foreach ( $ paths as $ pathInfo ) { $ path = array_get ( ...
Delete library item AJAX handler
23,157
public function onLoadRenamePopup ( ) { $ this -> abortIfReadOnly ( ) ; $ path = Input :: get ( 'path' ) ; $ path = MediaLibrary :: validatePath ( $ path ) ; $ this -> vars [ 'originalPath' ] = $ path ; $ this -> vars [ 'name' ] = basename ( $ path ) ; $ this -> vars [ 'listId' ] = Input :: get ( 'listId' ) ; $ this ->...
Show rename item popup AJAX handler
23,158
public function onApplyName ( ) { $ this -> abortIfReadOnly ( ) ; $ newName = trim ( Input :: get ( 'name' ) ) ; if ( ! strlen ( $ newName ) ) { throw new ApplicationException ( Lang :: get ( 'cms::lang.asset.name_cant_be_empty' ) ) ; } if ( ! $ this -> validateFileName ( $ newName ) ) { throw new ApplicationException ...
Reanem library item AJAX handler
23,159
public function onCreateFolder ( ) { $ this -> abortIfReadOnly ( ) ; $ name = trim ( Input :: get ( 'name' ) ) ; if ( ! strlen ( $ name ) ) { throw new ApplicationException ( Lang :: get ( 'cms::lang.asset.name_cant_be_empty' ) ) ; } if ( ! $ this -> validateFileName ( $ name ) ) { throw new ApplicationException ( Lang...
Create library folder AJAX handler
23,160
public function onLoadMovePopup ( ) { $ this -> abortIfReadOnly ( ) ; $ exclude = Input :: get ( 'exclude' , [ ] ) ; if ( ! is_array ( $ exclude ) ) { throw new ApplicationException ( 'Invalid input data' ) ; } $ folders = MediaLibrary :: instance ( ) -> listAllDirectories ( $ exclude ) ; $ folderList = [ ] ; foreach (...
Show move item popup AJAX handler
23,161
public function onMoveItems ( ) { $ this -> abortIfReadOnly ( ) ; $ dest = trim ( Input :: get ( 'dest' ) ) ; if ( ! strlen ( $ dest ) ) { throw new ApplicationException ( Lang :: get ( 'backend::lang.media.please_select_move_dest' ) ) ; } $ dest = MediaLibrary :: validatePath ( $ dest ) ; if ( $ dest == Input :: get (...
Move library item AJAX handler
23,162
public function onLoadPopup ( ) { $ this -> bottomToolbar = Input :: get ( 'bottomToolbar' , $ this -> bottomToolbar ) ; $ this -> cropAndInsertButton = Input :: get ( 'cropAndInsertButton' , $ this -> cropAndInsertButton ) ; return $ this -> makePartial ( 'popup-body' ) ; }
Start image cropping session AJAX handler
23,163
public function onLoadImageCropPopup ( ) { $ this -> abortIfReadOnly ( ) ; $ path = Input :: get ( 'path' ) ; $ path = MediaLibrary :: validatePath ( $ path ) ; $ cropSessionKey = md5 ( FormHelper :: getSessionKey ( ) ) ; $ selectionParams = $ this -> getSelectionParams ( ) ; $ urlAndSize = $ this -> getCropEditImageUr...
Load image for cropping AJAX handler
23,164
public function onEndCroppingSession ( ) { $ this -> abortIfReadOnly ( ) ; $ cropSessionKey = Input :: get ( 'cropSessionKey' ) ; if ( ! preg_match ( '/^[0-9a-z]+$/' , $ cropSessionKey ) ) { throw new ApplicationException ( 'Invalid input data' ) ; } $ this -> removeCropEditDir ( $ cropSessionKey ) ; }
End crop session AJAX handler
23,165
public function onCropImage ( ) { $ this -> abortIfReadOnly ( ) ; $ imageSrcPath = trim ( Input :: get ( 'img' ) ) ; $ selectionData = Input :: get ( 'selection' ) ; $ cropSessionKey = Input :: get ( 'cropSessionKey' ) ; $ path = Input :: get ( 'path' ) ; $ path = MediaLibrary :: validatePath ( $ path ) ; if ( ! strlen...
Crop image AJAX handler
23,166
public function onResizeImage ( ) { $ this -> abortIfReadOnly ( ) ; $ cropSessionKey = Input :: get ( 'cropSessionKey' ) ; if ( ! preg_match ( '/^[0-9a-z]+$/' , $ cropSessionKey ) ) { throw new ApplicationException ( 'Invalid input data' ) ; } $ width = trim ( Input :: get ( 'width' ) ) ; if ( ! strlen ( $ width ) || !...
Resize image AJAX handler
23,167
protected function prepareVars ( ) { clearstatcache ( ) ; $ folder = $ this -> getCurrentFolder ( ) ; $ viewMode = $ this -> getViewMode ( ) ; $ filter = $ this -> getFilter ( ) ; $ sortBy = $ this -> getSortBy ( ) ; $ sortDirection = $ this -> getSortDirection ( ) ; $ searchTerm = $ this -> getSearchTerm ( ) ; $ searc...
Internal method to prepare view variables .
23,168
protected function findFiles ( $ searchTerm , $ filter , $ sortBy ) { $ filter = $ filter !== self :: FILTER_EVERYTHING ? $ filter : null ; return MediaLibrary :: instance ( ) -> findFiles ( $ searchTerm , $ sortBy , $ filter ) ; }
Finds files from within the media library based on supplied criteria returns an array of MediaLibraryItem objects .
23,169
protected function setFilter ( $ filter ) { if ( ! in_array ( $ filter , [ self :: FILTER_EVERYTHING , MediaLibraryItem :: FILE_TYPE_IMAGE , MediaLibraryItem :: FILE_TYPE_AUDIO , MediaLibraryItem :: FILE_TYPE_DOCUMENT , MediaLibraryItem :: FILE_TYPE_VIDEO ] ) ) { throw new ApplicationException ( 'Invalid input data' ) ...
Sets the user filter from the session state
23,170
protected function setSortBy ( $ sortBy ) { if ( ! in_array ( $ sortBy , [ MediaLibrary :: SORT_BY_TITLE , MediaLibrary :: SORT_BY_SIZE , MediaLibrary :: SORT_BY_MODIFIED ] ) ) { throw new ApplicationException ( 'Invalid input data' ) ; } $ this -> putSession ( 'media_sort_by' , $ sortBy ) ; }
Sets the user sort column from the session state
23,171
protected function setSortDirection ( $ sortDirection ) { if ( ! in_array ( $ sortDirection , [ MediaLibrary :: SORT_DIRECTION_ASC , MediaLibrary :: SORT_DIRECTION_DESC ] ) ) { throw new ApplicationException ( 'Invalid input data' ) ; } $ this -> putSession ( 'media_sort_direction' , $ sortDirection ) ; }
Sets the user sort direction from the session state
23,172
protected function getSelectionParams ( ) { $ result = $ this -> getSession ( 'media_crop_selection_params' ) ; if ( $ result ) { if ( ! isset ( $ result [ 'mode' ] ) ) { $ result [ 'mode' ] = self :: SELECTION_MODE_NORMAL ; } if ( ! isset ( $ result [ 'width' ] ) ) { $ result [ 'width' ] = null ; } if ( ! isset ( $ re...
Gets the user selection parameters from the session state
23,173
protected function setSelectionParams ( $ selectionMode , $ selectionWidth , $ selectionHeight ) { if ( ! in_array ( $ selectionMode , [ self :: SELECTION_MODE_NORMAL , self :: SELECTION_MODE_FIXED_RATIO , self :: SELECTION_MODE_FIXED_SIZE ] ) ) { throw new ApplicationException ( 'Invalid input data' ) ; } if ( strlen ...
Stores the user selection parameters in the session state
23,174
protected function itemTypeToIconClass ( $ item , $ itemType ) { if ( $ item -> type == MediaLibraryItem :: TYPE_FOLDER ) { return 'icon-folder' ; } switch ( $ itemType ) { case MediaLibraryItem :: FILE_TYPE_IMAGE : return "icon-picture-o" ; case MediaLibraryItem :: FILE_TYPE_VIDEO : return "icon-video-camera" ; case M...
Returns an icon for the item type
23,175
protected function splitPathToSegments ( $ path ) { $ path = MediaLibrary :: validatePath ( $ path , true ) ; $ path = explode ( '/' , ltrim ( $ path , '/' ) ) ; $ result = [ ] ; while ( count ( $ path ) > 0 ) { $ folder = array_pop ( $ path ) ; $ result [ $ folder ] = implode ( '/' , $ path ) . '/' . $ folder ; if ( s...
Splits a path in to segments
23,176
protected function setViewMode ( $ viewMode ) { if ( ! in_array ( $ viewMode , [ self :: VIEW_MODE_GRID , self :: VIEW_MODE_LIST , self :: VIEW_MODE_TILES ] ) ) { throw new ApplicationException ( 'Invalid input data' ) ; } $ this -> putSession ( 'view_mode' , $ viewMode ) ; }
Stores a view mode in the session
23,177
protected function getThumbnailParams ( $ viewMode = null ) { $ result = [ 'mode' => 'crop' , 'ext' => 'png' ] ; if ( $ viewMode ) { if ( $ viewMode == self :: VIEW_MODE_LIST ) { $ result [ 'width' ] = 75 ; $ result [ 'height' ] = 75 ; } else { $ result [ 'width' ] = 165 ; $ result [ 'height' ] = 165 ; } } return $ res...
Returns thumbnail parameters
23,178
protected function getThumbnailImagePath ( $ thumbnailParams , $ itemPath , $ lastModified ) { $ itemSignature = md5 ( $ itemPath ) . $ lastModified ; $ thumbFile = 'thumb_' . $ itemSignature . '_' . $ thumbnailParams [ 'width' ] . 'x' . $ thumbnailParams [ 'height' ] . '_' . $ thumbnailParams [ 'mode' ] . '.' . $ thum...
Generates a thumbnail image path
23,179
protected function thumbnailExists ( $ thumbnailParams , $ itemPath , $ lastModified ) { $ thumbnailPath = $ this -> getThumbnailImagePath ( $ thumbnailParams , $ itemPath , $ lastModified ) ; $ fullPath = temp_path ( ltrim ( $ thumbnailPath , '/' ) ) ; if ( File :: exists ( $ fullPath ) ) { return $ thumbnailPath ; } ...
Check if a thumbnail exists
23,180
protected function thumbnailIsError ( $ thumbnailPath ) { $ fullPath = temp_path ( ltrim ( $ thumbnailPath , '/' ) ) ; return hash_file ( 'crc32' , $ fullPath ) == $ this -> getBrokenImageHash ( ) ; }
Check if a thumbnail has caused an error
23,181
protected function getLocalTempFilePath ( $ fileName ) { $ fileName = md5 ( $ fileName . uniqid ( ) . microtime ( ) ) ; $ mediaFolder = Config :: get ( 'cms.storage.media.folder' , 'media' ) ; $ path = temp_path ( ) . MediaLibrary :: validatePath ( $ mediaFolder , true ) ; if ( ! File :: isDirectory ( $ path ) ) { File...
Get temporary local file path
23,182
protected function getBrokenImageHash ( ) { if ( $ this -> brokenImageHash ) { return $ this -> brokenImageHash ; } $ fullPath = $ this -> getBrokenImagePath ( ) ; return $ this -> brokenImageHash = hash_file ( 'crc32' , $ fullPath ) ; }
Returns a CRC32 hash for a broken image
23,183
protected function copyBrokenImage ( $ path ) { try { $ thumbnailDir = dirname ( $ path ) ; if ( ! File :: isDirectory ( $ thumbnailDir ) && File :: makeDirectory ( $ thumbnailDir , 0777 , true ) === false ) { return ; } File :: copy ( $ this -> getBrokenImagePath ( ) , $ path ) ; } catch ( Exception $ ex ) { traceLog ...
Copy broken image to destination
23,184
protected function getTargetDimensions ( $ width , $ height , $ originalImagePath ) { $ originalDimensions = [ $ width , $ height ] ; try { $ dimensions = getimagesize ( $ originalImagePath ) ; if ( ! $ dimensions ) { return $ originalDimensions ; } if ( $ dimensions [ 0 ] > $ width || $ dimensions [ 1 ] > $ height ) {...
Get target dimensions
23,185
protected function checkUploadPostback ( ) { if ( $ this -> readOnly ) { return ; } $ fileName = null ; $ quickMode = false ; if ( ( ! ( $ uniqueId = Request :: header ( 'X-OCTOBER-FILEUPLOAD' ) ) || $ uniqueId != $ this -> getId ( ) ) && ( ! $ quickMode = post ( 'X_OCTOBER_MEDIA_MANAGER_QUICK_UPLOAD' ) ) ) { return ; ...
Detect the upload post flag
23,186
protected function validateFileName ( $ name ) { if ( ! preg_match ( '/^[\w@\.\s_\-]+$/iu' , $ name ) ) { return false ; } if ( strpos ( $ name , '..' ) !== false ) { return false ; } return true ; }
Validate a proposed media item file name .
23,187
protected function getCropEditImageUrlAndSize ( $ path , $ cropSessionKey , $ params = null ) { $ sessionDirectoryPath = $ this -> getCropSessionDirPath ( $ cropSessionKey ) ; $ fullSessionDirectoryPath = temp_path ( $ sessionDirectoryPath ) ; $ sessionDirectoryCreated = false ; if ( ! File :: isDirectory ( $ fullSessi...
Prepares an image for cropping and returns payload containing a URL
23,188
protected function removeCropEditDir ( $ cropSessionKey ) { $ sessionDirectoryPath = $ this -> getCropSessionDirPath ( $ cropSessionKey ) ; $ fullSessionDirectoryPath = temp_path ( $ sessionDirectoryPath ) ; if ( File :: isDirectory ( $ fullSessionDirectoryPath ) ) { @ File :: deleteDirectory ( $ fullSessionDirectoryPa...
Cleans up the directory used for cropping based on the session key
23,189
public static function listAllTemplates ( ) { $ fileTemplates = ( array ) MailManager :: instance ( ) -> listRegisteredTemplates ( ) ; $ dbTemplates = ( array ) self :: lists ( 'code' , 'code' ) ; $ templates = $ fileTemplates + $ dbTemplates ; ksort ( $ templates ) ; return $ templates ; }
Returns an array of template codes and descriptions .
23,190
public static function allTemplates ( ) { $ result = [ ] ; $ codes = array_keys ( self :: listAllTemplates ( ) ) ; foreach ( $ codes as $ code ) { $ result [ ] = self :: findOrMakeTemplate ( $ code ) ; } return $ result ; }
Returns a list of all mail templates .
23,191
public static function syncAll ( ) { MailLayout :: createLayouts ( ) ; MailPartial :: createPartials ( ) ; $ templates = MailManager :: instance ( ) -> listRegisteredTemplates ( ) ; $ dbTemplates = self :: lists ( 'is_custom' , 'code' ) ; $ newTemplates = array_diff_key ( $ templates , $ dbTemplates ) ; foreach ( $ dbT...
Syncronise all file templates to the database .
23,192
protected function getRecords ( ) { $ query = $ this -> prepareQuery ( ) ; if ( $ this -> showTree ) { $ records = $ query -> getNested ( ) ; } elseif ( $ this -> showPagination ) { $ method = $ this -> showPageNumbers ? 'paginate' : 'simplePaginate' ; $ currentPageNumber = $ this -> getCurrentPageNumber ( $ query ) ; ...
Returns all the records from the supplied model after filtering .
23,193
protected function getCurrentPageNumber ( $ query ) { $ currentPageNumber = $ this -> currentPageNumber ; if ( ! $ currentPageNumber && empty ( $ this -> searchTerm ) ) { $ currentPageNumber = $ this -> getSession ( 'lastVisitedPage' ) ; } $ currentPageNumber = intval ( $ currentPageNumber ) ; if ( $ currentPageNumber ...
Returns the current page number for the list .
23,194
public function getRecordUrl ( $ record ) { if ( isset ( $ this -> recordOnClick ) ) { return 'javascript:;' ; } if ( ! isset ( $ this -> recordUrl ) ) { return null ; } $ url = RouterHelper :: replaceParameters ( $ record , $ this -> recordUrl ) ; return Backend :: url ( $ url ) ; }
Returns the record URL address for a list row .
23,195
public function getRecordOnClick ( $ record ) { if ( ! isset ( $ this -> recordOnClick ) ) { return null ; } $ recordOnClick = RouterHelper :: replaceParameters ( $ record , $ this -> recordOnClick ) ; return Html :: attributes ( [ 'onclick' => $ recordOnClick ] ) ; }
Returns the onclick event for a list row .
23,196
public function getVisibleColumns ( ) { $ definitions = $ this -> defineListColumns ( ) ; $ columns = [ ] ; if ( $ this -> columnOverride === null ) { $ this -> columnOverride = $ this -> getSession ( 'visible' , null ) ; } if ( $ this -> columnOverride && is_array ( $ this -> columnOverride ) ) { $ invalidColumns = ar...
Returns the list columns that are visible by list settings or default
23,197
protected function defineListColumns ( ) { if ( ! isset ( $ this -> columns ) || ! is_array ( $ this -> columns ) || ! count ( $ this -> columns ) ) { $ class = get_class ( $ this -> model instanceof Model ? $ this -> model : $ this -> controller ) ; throw new ApplicationException ( Lang :: get ( 'backend::lang.list.mi...
Builds an array of list columns with keys as the column name and values as a ListColumn object .
23,198
public function addColumns ( array $ columns ) { foreach ( $ columns as $ columnName => $ config ) { $ this -> allColumns [ $ columnName ] = $ this -> makeListColumn ( $ columnName , $ config ) ; } }
Programatically add columns used internally and for extensibility .
23,199
protected function makeListColumn ( $ name , $ config ) { if ( is_string ( $ config ) ) { $ label = $ config ; } elseif ( isset ( $ config [ 'label' ] ) ) { $ label = $ config [ 'label' ] ; } else { $ label = studly_case ( $ name ) ; } if ( starts_with ( $ name , 'pivot[' ) && strpos ( $ name , ']' ) !== false ) { $ _n...
Creates a list column object from it s name and configuration .