idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
48,200
public function beforeSave ( Event $ event , Entity $ entity , ArrayObject $ options = null ) { $ this -> _saveRevision ( $ entity ) ; $ this -> _ensureStatus ( $ entity ) ; return true ; }
This callback performs two action saving revisions and checking publishing constraints .
48,201
protected function _saveRevision ( Entity $ entity ) { if ( $ entity -> isNew ( ) ) { return ; } try { $ prev = TableRegistry :: get ( 'Content.Contents' ) -> get ( $ entity -> id ) ; $ hash = $ this -> _calculateHash ( $ prev ) ; $ exists = $ this -> ContentRevisions -> exists ( [ 'ContentRevisions.content_id' => $ entity -> id , 'ContentRevisions.hash' => $ hash , ] ) ; if ( ! $ exists ) { $ revision = $ this -> ContentRevisions -> newEntity ( [ 'content_id' => $ prev -> id , 'summary' => $ entity -> get ( 'edit_summary' ) , 'data' => $ prev , 'hash' => $ hash , ] ) ; if ( ! $ this -> ContentRevisions -> hasBehavior ( 'Timestamp' ) ) { $ this -> ContentRevisions -> addBehavior ( 'Timestamp' ) ; } $ this -> ContentRevisions -> save ( $ revision ) ; } } catch ( \ Exception $ ex ) { } }
Tries to create a revision for the given content .
48,202
protected function _ensureStatus ( Entity $ entity ) { if ( ! $ entity -> has ( 'status' ) ) { return ; } if ( ! $ entity -> has ( 'content_type' ) && ( $ entity -> has ( 'content_type_id' ) || $ entity -> has ( 'content_type_slug' ) ) ) { if ( $ entity -> has ( 'content_type_id' ) ) { $ type = $ this -> ContentTypes -> get ( $ entity -> get ( 'content_type_id' ) ) ; } else { $ type = $ this -> ContentTypes -> find ( ) -> where ( [ 'content_type_slug' => $ entity -> get ( 'content_type_id' ) ] ) -> limit ( 1 ) -> first ( ) ; } } else { $ type = $ entity -> get ( 'content_type' ) ; } if ( $ type && ! $ type -> userAllowed ( 'publish' ) ) { if ( $ entity -> isNew ( ) ) { $ entity -> set ( 'status' , false ) ; } else { $ entity -> unsetProperty ( 'status' ) ; } } }
Ensures that content content has the correct publishing status based in content type restrictions .
48,203
public function operatorPromote ( Query $ query , TokenInterface $ token ) { $ value = strtolower ( $ token -> value ( ) ) ; $ conjunction = $ token -> negated ( ) ? '<>' : '' ; $ conditions = [ ] ; if ( $ value === 'true' ) { $ conditions = [ "Contents.promote {$conjunction}" => 1 ] ; } elseif ( $ value === 'false' ) { $ conditions = [ 'Contents.promote {$conjunction}' => 0 ] ; } if ( ! empty ( $ conditions ) ) { if ( $ token -> where ( ) === 'or' ) { $ query -> orWhere ( $ conditions ) ; } elseif ( $ token -> where ( ) === 'and' ) { $ query -> andWhere ( $ conditions ) ; } else { $ query -> where ( $ conditions ) ; } } return $ query ; }
Handles promote search operator .
48,204
public function operatorAuthor ( Query $ query , TokenInterface $ token ) { $ value = explode ( ',' , $ token -> value ( ) ) ; if ( ! empty ( $ value ) ) { $ conjunction = $ token -> negated ( ) ? 'NOT IN' : 'IN' ; $ subQuery = TableRegistry :: get ( 'User.Users' ) -> find ( ) -> select ( [ 'id' ] ) -> where ( [ "Users.username {$conjunction}" => $ value ] ) ; if ( $ token -> where ( ) === 'or' ) { $ query -> orWhere ( [ 'Contents.created_by IN' => $ subQuery ] ) ; } elseif ( $ token -> where ( ) === 'and' ) { $ query -> andWhere ( [ 'Contents.created_by IN' => $ subQuery ] ) ; } else { $ query -> where ( [ 'Contents.created_by IN' => $ subQuery ] ) ; } } return $ query ; }
Handles author search operator .
48,205
public function operatorterm ( Query $ query , TokenInterface $ token ) { $ terms = explode ( ',' , strtolower ( $ token -> value ( ) ) ) ; $ conjunction = $ token -> negated ( ) ? 'NOT IN' : 'IN' ; if ( empty ( $ terms ) ) { return $ query ; } $ conditions = [ "Contents.id {$conjunction}" => TableRegistry :: get ( 'Taxonomy.EntitiesTerms' ) -> find ( ) -> select ( [ 'EntitiesTerms.entity_id' ] ) -> where ( [ 'EntitiesTerms.table_alias' => $ this -> alias ( ) ] ) -> matching ( 'Terms' , function ( $ q ) use ( $ terms ) { return $ q -> where ( [ 'Terms.slug IN' => $ terms ] ) ; } ) ] ; if ( ! empty ( $ conditions ) ) { if ( $ token -> where ( ) === 'or' ) { $ query -> orWhere ( $ conditions ) ; } elseif ( $ token -> where ( ) === 'and' ) { $ query -> andWhere ( $ conditions ) ; } else { $ query -> where ( $ conditions ) ; } } return $ query ; }
Handles term search operator .
48,206
protected function _calculateHash ( $ entity ) { $ hash = [ ] ; foreach ( $ entity -> visibleProperties ( ) as $ property ) { if ( strpos ( $ property , 'created' ) === false && strpos ( $ property , 'created_by' ) === false && strpos ( $ property , 'modified' ) === false && strpos ( $ property , 'modified_by' ) === false ) { if ( $ property == '_fields' ) { foreach ( $ entity -> get ( '_fields' ) as $ field ) { if ( $ field instanceof \ Field \ Model \ Entity \ Field ) { $ hash [ ] = is_object ( $ field -> value ) || is_array ( $ field -> value ) ? md5 ( serialize ( $ field -> value ) ) : md5 ( $ field -> value ) ; } } } else { $ hash [ ] = $ entity -> get ( $ property ) ; } } } return md5 ( serialize ( $ hash ) ) ; }
Generates a unique hash for the given entity .
48,207
protected function init ( ) { if ( ! ( $ this -> options [ 'host' ] || $ this -> options [ 'socket' ] ) || ! $ this -> options [ 'user' ] || ! $ this -> options [ 'pass' ] || ! $ this -> options [ 'db' ] || ! $ this -> options [ 'path' ] || ! $ this -> options [ 'files_table' ] ) { return false ; } $ this -> db = new mysqli ( $ this -> options [ 'host' ] , $ this -> options [ 'user' ] , $ this -> options [ 'pass' ] , $ this -> options [ 'db' ] , $ this -> options [ 'port' ] , $ this -> options [ 'socket' ] ) ; if ( $ this -> db -> connect_error || @ mysqli_connect_error ( ) ) { return false ; } $ this -> db -> set_charset ( 'utf8' ) ; if ( $ res = $ this -> db -> query ( 'SHOW TABLES' ) ) { while ( $ row = $ res -> fetch_array ( ) ) { if ( $ row [ 0 ] == $ this -> options [ 'files_table' ] ) { $ this -> tbf = $ this -> options [ 'files_table' ] ; break ; } } } if ( ! $ this -> tbf ) { return false ; } $ this -> updateCache ( $ this -> options [ 'path' ] , $ this -> _stat ( $ this -> options [ 'path' ] ) ) ; return true ; }
Prepare driver before mount volume . Connect to db check required tables and fetch root path
48,208
protected function configure ( ) { parent :: configure ( ) ; if ( ( $ tmp = $ this -> options [ 'tmpPath' ] ) ) { if ( ! file_exists ( $ tmp ) ) { if ( @ mkdir ( $ tmp ) ) { @ chmod ( $ tmp , $ this -> options [ 'tmbPathMode' ] ) ; } } $ this -> tmpPath = is_dir ( $ tmp ) && is_writable ( $ tmp ) ? $ tmp : false ; } if ( ! $ this -> tmpPath && $ this -> tmbPath && $ this -> tmbPathWritable ) { $ this -> tmpPath = $ this -> tmbPath ; } $ this -> mimeDetect = 'internal' ; }
Set tmp path
48,209
protected function query ( $ sql ) { $ this -> sqlCnt ++ ; $ res = $ this -> db -> query ( $ sql ) ; if ( ! $ res ) { $ this -> dbError = $ this -> db -> error ; } return $ res ; }
Perform sql query and return result . Increase sqlCnt and save error if occured
48,210
protected function make ( $ path , $ name , $ mime ) { $ sql = 'INSERT INTO %s (`parent_id`, `name`, `size`, `mtime`, `mime`, `content`, `read`, `write`) VALUES ("%s", "%s", 0, %d, "%s", "", "%d", "%d")' ; $ sql = sprintf ( $ sql , $ this -> tbf , $ path , $ this -> db -> real_escape_string ( $ name ) , time ( ) , $ mime , $ this -> defaults [ 'read' ] , $ this -> defaults [ 'write' ] ) ; return $ this -> query ( $ sql ) && $ this -> db -> affected_rows > 0 ; }
Create empty object with required mimetype
48,211
protected function loadFilePath ( $ path ) { $ realPath = realpath ( $ path ) ; if ( DIRECTORY_SEPARATOR == '\\' ) { $ realPath = str_replace ( '\\' , '\\\\' , $ realPath ) ; } return $ this -> db -> real_escape_string ( $ realPath ) ; }
Return correct file path for LOAD_FILE method
48,212
protected function _joinPath ( $ dir , $ name ) { $ sql = 'SELECT id FROM ' . $ this -> tbf . ' WHERE parent_id="' . $ dir . '" AND name="' . $ this -> db -> real_escape_string ( $ name ) . '"' ; if ( ( $ res = $ this -> query ( $ sql ) ) && ( $ r = $ res -> fetch_assoc ( ) ) ) { $ this -> updateCache ( $ r [ 'id' ] , $ this -> _stat ( $ r [ 'id' ] ) ) ; return $ r [ 'id' ] ; } return - 1 ; }
Join dir name and file name and return full path
48,213
public static function columnName ( $ column ) { list ( $ tableName , $ fieldName ) = pluginSplit ( ( string ) $ column ) ; if ( ! $ fieldName ) { $ fieldName = $ tableName ; } $ fieldName = preg_replace ( '/\s{2,}/' , ' ' , $ fieldName ) ; list ( $ fieldName , ) = explode ( ' ' , trim ( $ fieldName ) ) ; return $ fieldName ; }
Gets a clean column name from query expression .
48,214
public function attributes ( $ bundle = null ) { $ key = empty ( $ bundle ) ? '@all' : $ bundle ; if ( isset ( $ this -> _attributes [ $ key ] ) ) { return $ this -> _attributes [ $ key ] ; } $ this -> _attributes [ $ key ] = [ ] ; $ cacheKey = $ this -> _table -> table ( ) . '_' . $ key ; $ attrs = Cache :: read ( $ cacheKey , 'eav_table_attrs' ) ; if ( empty ( $ attrs ) ) { $ conditions = [ 'EavAttributes.table_alias' => $ this -> _table -> table ( ) ] ; if ( ! empty ( $ bundle ) ) { $ conditions [ 'EavAttributes.bundle' ] = $ bundle ; } $ attrs = TableRegistry :: get ( 'Eav.EavAttributes' ) -> find ( ) -> where ( $ conditions ) -> all ( ) -> toArray ( ) ; Cache :: write ( $ cacheKey , $ attrs , 'eav_table_attrs' ) ; } foreach ( $ attrs as $ attr ) { $ this -> _attributes [ $ key ] [ $ attr -> get ( 'name' ) ] = $ attr ; } return $ this -> attributes ( $ bundle ) ; }
Gets all attributes added to this table .
48,215
public function getAttributeIds ( $ bundle = null ) { $ attributes = $ this -> attributes ( $ bundle ) ; $ ids = [ ] ; foreach ( $ attributes as $ name => $ info ) { $ ids [ ] = $ info [ 'id' ] ; } return $ ids ; }
Gets a list of attribute IDs .
48,216
public function extractEntityIds ( CollectionInterface $ results ) { $ entityIds = [ ] ; $ results -> each ( function ( $ entity ) use ( & $ entityIds ) { if ( $ entity instanceof EntityInterface ) { $ entityIds [ ] = $ this -> getEntityId ( $ entity ) ; } } ) ; return $ entityIds ; }
Given a collection of entities gets the ID of all of them .
48,217
public function getEntityId ( EntityInterface $ entity ) { $ pk = [ ] ; $ keys = $ this -> _table -> primaryKey ( ) ; $ keys = ! is_array ( $ keys ) ? [ $ keys ] : $ keys ; foreach ( $ keys as $ key ) { $ pk [ ] = $ entity -> get ( $ key ) ; } return implode ( ':' , $ pk ) ; }
Calculates entity s primary key .
48,218
public function pluginFile ( ) { if ( ! empty ( $ this -> request -> query [ 'file' ] ) ) { $ path = $ this -> request -> query [ 'file' ] ; $ path = str_replace_once ( '#' , '' , $ path ) ; $ file = str_replace ( '//' , '/' , ROOT . "/plugins/{$path}" ) ; if ( ( strpos ( $ file , 'webroot' ) !== false || strpos ( $ file , '.tmb' ) !== false ) && file_exists ( $ file ) ) { $ this -> response -> file ( $ file ) ; return $ this -> response ; } } die ; }
Returns the given plugin s file within webroot directory .
48,219
protected function _setName ( $ value ) { $ value = strip_tags ( $ value ) ; $ value = str_replace ( [ "\n" , "\r" ] , '' , $ value ) ; return trim ( $ value ) ; }
Removes any invalid characters from term s name .
48,220
public function language ( ) { $ languages = [ 'en_US' => [ 'url' => '/installer/startup/requirements?locale=en_US' , 'welcome' => 'Welcome to QuickAppsCMS' , 'action' => 'Click here to install in English' ] ] ; $ Folder = new Folder ( Plugin :: classPath ( 'Installer' ) . 'Locale' ) ; foreach ( $ Folder -> read ( false , true , true ) [ 0 ] as $ path ) { $ code = basename ( $ path ) ; $ file = $ path . '/installer.po' ; if ( is_readable ( $ file ) ) { I18n :: locale ( $ code ) ; $ languages [ $ code ] = [ 'url' => "/installer/startup/requirements?locale={$code}" , 'welcome' => __d ( 'installer' , 'Welcome to QuickAppsCMS' ) , 'action' => __d ( 'installer' , 'Click here to install in English' ) ] ; } } I18n :: locale ( 'en_US' ) ; $ this -> title ( 'Welcome to QuickAppsCMS' ) ; $ this -> set ( 'languages' , $ languages ) ; $ this -> _step ( ) ; }
First step of the installation process .
48,221
public function requirements ( ) { if ( ! $ this -> _step ( 'language' ) ) { $ this -> redirect ( [ 'plugin' => 'Installer' , 'controller' => 'startup' , 'action' => 'language' ] ) ; } $ tests = $ this -> _getTester ( ) ; $ errors = $ tests -> errors ( ) ; if ( empty ( $ errors ) ) { $ this -> _step ( ) ; } $ this -> title ( __d ( 'installer' , 'Server Requirements' ) ) ; $ this -> set ( 'errors' , $ errors ) ; }
Second step of the installation process .
48,222
public function license ( ) { if ( ! $ this -> _step ( 'requirements' ) ) { $ this -> redirect ( [ 'plugin' => 'Installer' , 'controller' => 'startup' , 'action' => 'requirements' ] ) ; } $ this -> title ( __d ( 'installer' , 'License Agreement' ) ) ; $ this -> _step ( ) ; }
Third step of the installation process .
48,223
public function database ( ) { if ( ! $ this -> _step ( 'license' ) ) { $ this -> redirect ( [ 'plugin' => 'Installer' , 'controller' => 'startup' , 'action' => 'license' ] ) ; } if ( ! empty ( $ this -> request -> data ) ) { $ dbInstaller = new DatabaseInstaller ( ) ; if ( $ dbInstaller -> install ( $ this -> request -> data ( ) ) ) { $ this -> _step ( ) ; $ this -> redirect ( [ 'plugin' => 'Installer' , 'controller' => 'startup' , 'action' => 'account' ] ) ; } else { $ errors = '' ; foreach ( $ dbInstaller -> errors ( ) as $ error ) { $ errors .= "\t<li>{$error}</li>\n" ; } $ this -> Flash -> danger ( "<ul>\n{$errors}</ul>\n" ) ; } } $ this -> title ( __d ( 'installer' , 'Database Configuration' ) ) ; }
Fourth step of the installation process .
48,224
public function account ( ) { if ( ! $ this -> _step ( 'database' ) ) { $ this -> redirect ( [ 'plugin' => 'Installer' , 'controller' => 'startup' , 'action' => 'database' ] ) ; } $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> newEntity ( ) ; if ( $ this -> request -> data ( ) ) { $ data = $ this -> request -> data ; $ data [ 'roles' ] = [ '_ids' => [ 1 ] ] ; $ user = $ this -> Users -> newEntity ( $ data ) ; if ( $ this -> Users -> save ( $ user ) ) { $ this -> Flash -> success ( __d ( 'installer' , 'Account created you can now login!' ) ) ; $ this -> _step ( ) ; $ this -> redirect ( [ 'plugin' => 'Installer' , 'controller' => 'startup' , 'action' => 'finish' ] ) ; } else { $ this -> Flash -> danger ( __d ( 'installer' , 'Account could not be created, please check your information.' ) ) ; } } $ this -> title ( __d ( 'installer' , 'Create New Account' ) ) ; $ this -> set ( 'user' , $ user ) ; }
Fifth step of the installation process .
48,225
public function finish ( ) { if ( $ this -> request -> data ( ) ) { if ( rename ( ROOT . '/config/settings.php.tmp' , ROOT . '/config/settings.php' ) ) { snapshot ( ) ; $ this -> request -> session ( ) -> delete ( 'Startup' ) ; if ( ! empty ( $ this -> request -> data [ 'home' ] ) ) { $ this -> redirect ( '/' ) ; } else { $ this -> redirect ( '/admin' ) ; } } else { $ this -> Flash -> danger ( __d ( 'installer' , 'Unable to continue, check write permission for the "/config" directory.' ) ) ; } } $ this -> title ( __d ( 'installer' , 'Finish Installation' ) ) ; }
Last step of the installation process .
48,226
protected function _step ( $ check = null ) { $ _steps = ( array ) $ this -> request -> session ( ) -> read ( 'Startup._steps' ) ; if ( $ check === null ) { $ _steps [ ] = $ this -> request -> params [ 'action' ] ; $ _steps = array_unique ( $ _steps ) ; $ this -> request -> session ( ) -> write ( 'Startup._steps' , $ _steps ) ; } elseif ( is_string ( $ check ) ) { return in_array ( $ check , $ _steps ) ; } return false ; }
Check if the given step name was completed . Or marks current step as completed .
48,227
protected function _prepareLayout ( ) { $ menu = [ __d ( 'installer' , 'Welcome' ) => [ 'url' => [ 'plugin' => 'Installer' , 'controller' => 'startup' , 'action' => 'language' ] , 'active' => ( $ this -> request -> action === 'language' ) ] , __d ( 'installer' , 'System Requirements' ) => [ 'url' => [ 'plugin' => 'Installer' , 'controller' => 'startup' , 'action' => 'requirements' ] , 'active' => ( $ this -> request -> action === 'requirements' ) ] , __d ( 'installer' , 'License Agreement' ) => [ 'url' => [ 'plugin' => 'Installer' , 'controller' => 'startup' , 'action' => 'license' ] , 'active' => ( $ this -> request -> action === 'license' ) ] , __d ( 'installer' , 'Database Setup' ) => [ 'url' => [ 'plugin' => 'Installer' , 'controller' => 'startup' , 'action' => 'database' ] , 'active' => ( $ this -> request -> action === 'database' ) ] , __d ( 'installer' , 'Your Account' ) => [ 'url' => [ 'plugin' => 'Installer' , 'controller' => 'startup' , 'action' => 'account' ] , 'active' => ( $ this -> request -> action === 'account' ) ] , __d ( 'installer' , 'Finish' ) => [ 'url' => [ 'plugin' => 'Installer' , 'controller' => 'startup' , 'action' => 'finish' ] , 'active' => ( $ this -> request -> action === 'finish' ) ] , ] ; $ this -> set ( 'menu' , $ menu ) ; }
Sets some view - variables used across all steps .
48,228
public function index ( ) { $ this -> loadModel ( 'User.Users' ) ; $ users = $ this -> Users -> find ( ) -> contain ( [ 'Roles' ] ) ; if ( ! empty ( $ this -> request -> query [ 'filter' ] ) ) { $ this -> Users -> search ( $ this -> request -> query [ 'filter' ] , $ users ) ; } $ this -> title ( __d ( 'user' , 'Users List' ) ) ; $ this -> set ( 'users' , $ this -> paginate ( $ users ) ) ; $ this -> Breadcrumb -> push ( '/admin/user/manage' ) ; }
Shows a list of all registered users .
48,229
public function add ( ) { $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> newEntity ( ) ; $ user = $ this -> Users -> attachFields ( $ user ) ; $ languages = LocaleToolbox :: languagesList ( ) ; $ roles = $ this -> Users -> Roles -> find ( 'list' , [ 'conditions' => [ 'id NOT IN' => [ ROLE_ID_AUTHENTICATED , ROLE_ID_ANONYMOUS ] ] ] ) ; if ( $ this -> request -> data ( ) ) { $ user -> accessible ( 'id' , false ) ; $ data = $ this -> request -> data ; if ( isset ( $ data [ 'welcome_message' ] ) ) { $ sendWelcomeMessage = ( bool ) $ data [ 'welcome_message' ] ; unset ( $ data [ 'welcome_message' ] ) ; } else { $ sendWelcomeMessage = false ; } $ user = $ this -> Users -> patchEntity ( $ user , $ data ) ; if ( $ this -> Users -> save ( $ user ) ) { if ( $ sendWelcomeMessage ) { NotificationManager :: welcome ( $ user ) -> send ( ) ; } $ this -> Flash -> success ( __d ( 'user' , 'User successfully registered!' ) ) ; $ this -> redirect ( [ 'plugin' => 'User' , 'controller' => 'manage' , 'action' => 'edit' , $ user -> id ] ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'User could not be registered, please check your information.' ) ) ; } } $ this -> title ( __d ( 'user' , 'Register New User' ) ) ; $ this -> set ( compact ( 'user' , 'roles' , 'languages' ) ) ; $ this -> Breadcrumb -> push ( '/admin/user/manage' ) ; }
Adds a new user .
48,230
public function edit ( $ id ) { $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> get ( $ id , [ 'contain' => [ 'Roles' ] ] ) ; $ languages = LocaleToolbox :: languagesList ( ) ; $ roles = $ this -> Users -> Roles -> find ( 'list' , [ 'conditions' => [ 'id NOT IN' => [ ROLE_ID_AUTHENTICATED , ROLE_ID_ANONYMOUS ] ] ] ) ; if ( $ this -> request -> data ( ) ) { $ user -> accessible ( [ 'id' , 'username' ] , false ) ; $ user = $ this -> Users -> patchEntity ( $ user , $ this -> request -> data ) ; if ( $ this -> Users -> save ( $ user ) ) { $ this -> Flash -> success ( __d ( 'user' , 'User information successfully updated!' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'User information could not be saved, please check your information.' ) ) ; } } $ this -> title ( __d ( 'user' , 'Editing User' ) ) ; $ this -> set ( compact ( 'user' , 'roles' , 'languages' ) ) ; $ this -> Breadcrumb -> push ( '/admin/user/manage' ) ; }
Edits the given user s information .
48,231
public function block ( $ id ) { $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> get ( $ id , [ 'fields' => [ 'id' , 'name' , 'email' ] , 'contain' => [ 'Roles' ] , ] ) ; if ( ! in_array ( ROLE_ID_ADMINISTRATOR , $ user -> role_ids ) ) { if ( $ this -> Users -> updateAll ( [ 'status' => 0 ] , [ 'id' => $ user -> id ] ) ) { $ this -> Flash -> success ( __d ( 'user' , 'User {0} was successfully blocked!' , $ user -> name ) ) ; $ user -> updateToken ( ) ; NotificationManager :: blocked ( $ user ) -> send ( ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'User could not be blocked, please try again.' ) ) ; } } else { $ this -> Flash -> warning ( __d ( 'user' , 'Administrator users cannot be blocked.' ) ) ; } $ this -> title ( __d ( 'user' , 'Block User Account' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Blocks the given user account .
48,232
public function activate ( $ id ) { $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> get ( $ id , [ 'fields' => [ 'id' , 'name' , 'email' ] ] ) ; if ( $ this -> Users -> updateAll ( [ 'status' => 1 ] , [ 'id' => $ user -> id ] ) ) { NotificationManager :: activated ( $ user ) -> send ( ) ; $ this -> Flash -> success ( __d ( 'user' , 'User {0} was successfully activated!' , $ user -> name ) ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'User could not be activated, please try again.' ) ) ; } $ this -> title ( __d ( 'user' , 'Unblock User Account' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Activates the given user account .
48,233
public function passwordInstructions ( $ id ) { $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> get ( $ id , [ 'fields' => [ 'id' , 'name' , 'email' ] ] ) ; if ( $ user ) { NotificationManager :: passwordRequest ( $ user ) -> send ( ) ; $ this -> Flash -> success ( __d ( 'user' , 'Instructions we successfully sent to {0}' , $ user -> name ) ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'User was not found.' ) ) ; } $ this -> title ( __d ( 'user' , 'Recovery Instructions' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Sends password recovery instructions to the given user .
48,234
public function delete ( $ id ) { $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> get ( $ id , [ 'contain' => [ 'Roles' ] ] ) ; if ( in_array ( ROLE_ID_ADMINISTRATOR , $ user -> role_ids ) && $ this -> Users -> countAdministrators ( ) === 1 ) { $ this -> Flash -> danger ( __d ( 'user' , 'You cannot remove this user as it is the last administrator available.' ) ) ; } else { if ( $ this -> Users -> delete ( $ user ) ) { NotificationManager :: canceled ( $ user ) -> send ( ) ; $ this -> Flash -> success ( __d ( 'user' , 'User successfully removed!' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'User could not be removed.' ) ) ; } } $ this -> title ( __d ( 'user' , 'Remove User Account' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Removes the given user .
48,235
public function isAllowed ( $ aco ) { $ cacheKey = 'isAllowed(' . $ this -> get ( 'id' ) . ", {$aco})" ; $ cache = static :: cache ( $ cacheKey ) ; if ( $ cache === null ) { $ cache = TableRegistry :: get ( 'User.Permissions' ) -> check ( $ this , $ aco ) ; static :: cache ( $ cacheKey , $ cache ) ; } return $ cache ; }
Verifies this user is allowed access the given ACO .
48,236
public function avatar ( $ options = [ ] ) { $ options = ( array ) $ options ; $ options += [ 's' => 80 , 'd' => 'mm' , 'r' => 'g' ] ; $ url = 'http://www.gravatar.com/avatar/' ; $ url .= md5 ( strtolower ( trim ( $ this -> get ( 'email' ) ) ) ) ; $ url .= "?s={$options['s']}&d={$options['d']}&r={$options['r']}" ; return $ url ; }
Gets user avatar image s URL .
48,237
protected function _getRoleIds ( ) { $ ids = [ ] ; if ( ! $ this -> has ( 'roles' ) ) { return $ ids ; } foreach ( $ this -> roles as $ k => $ role ) { $ ids [ ] = $ role -> id ; } return $ ids ; }
Gets an array list of role IDs this user belongs to .
48,238
protected function _getCancelCode ( ) { if ( ! $ this -> has ( 'password' ) && ! $ this -> has ( 'id' ) ) { throw new FatalErrorException ( __d ( 'user' , 'Cannot generated cancel code for this user: unknown user ID.' ) ) ; } if ( ! $ this -> has ( 'password' ) ) { $ password = TableRegistry :: get ( 'User.Users' ) -> get ( $ this -> id , [ 'fields' => [ 'password' ] ] ) -> get ( 'password' ) ; } else { $ password = $ this -> password ; } return Security :: hash ( $ password , 'md5' , true ) ; }
Generates cancel code for this user .
48,239
public function addColumn ( $ name , array $ options = [ ] , $ errors = true ) { if ( in_array ( $ name , ( array ) $ this -> _table -> schema ( ) -> columns ( ) ) ) { throw new FatalErrorException ( __d ( 'eav' , 'The column name "{0}" cannot be used as it is already defined in the table "{1}"' , $ name , $ this -> _table -> alias ( ) ) ) ; } $ data = $ options + [ 'type' => 'string' , 'bundle' => null , 'searchable' => true , 'overwrite' => false , ] ; $ data [ 'type' ] = $ this -> _toolbox -> mapType ( $ data [ 'type' ] ) ; if ( ! in_array ( $ data [ 'type' ] , EavToolbox :: $ types ) ) { throw new FatalErrorException ( __d ( 'eav' , 'The column {0}({1}) could not be created as "{2}" is not a valid type.' , $ name , $ data [ 'type' ] , $ data [ 'type' ] ) ) ; } $ data [ 'name' ] = $ name ; $ data [ 'table_alias' ] = $ this -> _table -> table ( ) ; $ attr = TableRegistry :: get ( 'Eav.EavAttributes' ) -> find ( ) -> where ( [ 'name' => $ data [ 'name' ] , 'table_alias' => $ data [ 'table_alias' ] , 'bundle IS' => $ data [ 'bundle' ] , ] ) -> limit ( 1 ) -> first ( ) ; if ( $ attr && ! $ data [ 'overwrite' ] ) { throw new FatalErrorException ( __d ( 'eav' , 'Virtual column "{0}" already defined, use the "overwrite" option if you want to change it.' , $ name ) ) ; } if ( $ attr ) { $ attr = TableRegistry :: get ( 'Eav.EavAttributes' ) -> patchEntity ( $ attr , $ data ) ; } else { $ attr = TableRegistry :: get ( 'Eav.EavAttributes' ) -> newEntity ( $ data ) ; } $ success = ( bool ) TableRegistry :: get ( 'Eav.EavAttributes' ) -> save ( $ attr ) ; Cache :: clear ( false , 'eav_table_attrs' ) ; if ( $ errors ) { return ( array ) $ attr -> errors ( ) ; } return ( bool ) $ success ; }
Defines a new virtual - column or update if already defined .
48,240
public function dropColumn ( $ name , $ bundle = null ) { $ attr = TableRegistry :: get ( 'Eav.EavAttributes' ) -> find ( ) -> where ( [ 'name' => $ name , 'table_alias' => $ this -> _table -> table ( ) , 'bundle IS' => $ bundle , ] ) -> limit ( 1 ) -> first ( ) ; Cache :: clear ( false , 'eav_table_attrs' ) ; if ( $ attr ) { return ( bool ) TableRegistry :: get ( 'Eav.EavAttributes' ) -> delete ( $ attr ) ; } return false ; }
Drops an existing column .
48,241
public function listColumns ( $ bundle = null ) { $ columns = [ ] ; foreach ( $ this -> _toolbox -> attributes ( $ bundle ) as $ name => $ attr ) { $ columns [ $ name ] = [ 'id' => $ attr -> get ( 'id' ) , 'bundle' => $ attr -> get ( 'bundle' ) , 'name' => $ name , 'type' => $ attr -> get ( 'type' ) , 'searchable ' => $ attr -> get ( 'searchable' ) , 'extra ' => $ attr -> get ( 'extra' ) , ] ; } return $ columns ; }
Gets a list of virtual columns attached to this table .
48,242
public function beforeFind ( Event $ event , Query $ query , ArrayObject $ options , $ primary ) { $ status = array_key_exists ( 'eav' , $ options ) ? $ options [ 'eav' ] : $ this -> config ( 'status' ) ; if ( $ status ) { $ options [ 'bundle' ] = ! isset ( $ options [ 'bundle' ] ) ? null : $ options [ 'bundle' ] ; $ this -> _initScopes ( ) ; if ( empty ( $ this -> _queryScopes [ 'Eav\\Model\\Behavior\\QueryScope\\SelectScope' ] ) ) { return $ query ; } $ selectedVirtual = $ this -> _queryScopes [ 'Eav\\Model\\Behavior\\QueryScope\\SelectScope' ] -> getVirtualColumns ( $ query , $ options [ 'bundle' ] ) ; $ args = compact ( 'options' , 'primary' , 'selectedVirtual' ) ; $ query = $ this -> _scopeQuery ( $ query , $ options [ 'bundle' ] ) ; return $ query -> formatResults ( function ( $ results ) use ( $ args ) { return $ this -> _hydrateEntities ( $ results , $ args ) ; } , Query :: PREPEND ) ; } }
Attaches virtual properties to entities .
48,243
protected function _hydrateEntities ( CollectionInterface $ entities , array $ args ) { $ values = $ this -> _prepareSetValues ( $ entities , $ args ) ; return $ entities -> map ( function ( $ entity ) use ( $ values ) { if ( $ entity instanceof EntityInterface ) { $ entity = $ this -> _prepareCachedColumns ( $ entity ) ; $ entityId = $ this -> _toolbox -> getEntityId ( $ entity ) ; $ entityValues = isset ( $ values [ $ entityId ] ) ? $ values [ $ entityId ] : [ ] ; $ hydrator = $ this -> config ( 'hydrator' ) ; $ entity = $ hydrator ( $ entity , $ entityValues ) ; if ( $ entity === null ) { $ entity = self :: NULL_ENTITY ; } } return $ entity ; } ) -> filter ( function ( $ entity ) { return $ entity !== self :: NULL_ENTITY ; } ) ; }
Attach EAV attributes for every entity in the provided result - set .
48,244
public function hydrateEntity ( EntityInterface $ entity , array $ values ) { foreach ( $ values as $ value ) { if ( ! $ this -> _toolbox -> propertyExists ( $ entity , $ value [ 'property_name' ] ) ) { $ entity -> set ( $ value [ 'property_name' ] , $ value [ 'value' ] ) ; $ entity -> dirty ( $ value [ 'property_name' ] , false ) ; } } if ( $ this -> config ( 'cacheMap' ) ) { foreach ( $ this -> config ( 'cacheMap' ) as $ column => $ fields ) { if ( $ this -> _toolbox -> propertyExists ( $ entity , $ column ) && ! ( $ entity -> get ( $ column ) instanceof Entity ) ) { $ entity -> set ( $ column , new Entity ) ; } } } return $ entity ; }
Hydrates a single entity and returns it .
48,245
public function buildMarshalMap ( $ marshaller , $ map , $ options ) { $ bundle = ! empty ( $ options [ 'bundle' ] ) ? $ options [ 'bundle' ] : null ; $ attrs = $ this -> _toolbox -> attributes ( $ bundle ) ; $ map = [ ] ; foreach ( $ attrs as $ name => $ info ) { $ map [ $ name ] = function ( $ value , $ entity ) use ( $ info ) { return $ this -> _toolbox -> marshal ( $ value , $ info [ 'type' ] ) ; } ; } return $ map ; }
Ensures that virtual properties are included in the marshalling process .
48,246
public function afterDelete ( Event $ event , EntityInterface $ entity , ArrayObject $ options ) { if ( ! $ options [ 'atomic' ] ) { throw new FatalErrorException ( __d ( 'eav' , 'Entities in fieldable tables can only be deleted using transactions. Set [atomic = true]' ) ) ; } $ valuesToDelete = TableRegistry :: get ( 'Eav.EavValues' ) -> find ( ) -> contain ( 'EavAttribute' ) -> where ( [ 'EavAttribute.table_alias' => $ this -> _table -> table ( ) , 'EavValues.entity_id' => $ this -> _toolbox -> getEntityId ( $ entity ) , ] ) ; foreach ( $ valuesToDelete as $ value ) { TableRegistry :: get ( 'Eav.EavValues' ) -> delete ( $ value ) ; } }
After an entity was removed from database . Here is when EAV values are removed from DB .
48,247
protected function _scopeQuery ( Query $ query , $ bundle = null ) { $ this -> _initScopes ( ) ; foreach ( $ this -> _queryScopes as $ scope ) { if ( $ scope instanceof QueryScopeInterface ) { $ query = $ scope -> scope ( $ query , $ bundle ) ; } } return $ query ; }
Look for virtual columns in some query s clauses .
48,248
protected function _initScopes ( ) { foreach ( ( array ) $ this -> config ( 'queryScope' ) as $ className ) { if ( ! empty ( $ this -> _queryScopes [ $ className ] ) ) { continue ; } if ( class_exists ( $ className ) ) { $ instance = new $ className ( $ this -> _table ) ; if ( $ instance instanceof QueryScopeInterface ) { $ this -> _queryScopes [ $ className ] = $ instance ; } } } }
Initializes the scope objects
48,249
protected function _getHandlerName ( ) { $ handler = $ this -> get ( 'handler' ) ; if ( class_exists ( $ handler ) ) { $ handler = new $ handler ( ) ; $ info = $ handler -> info ( ) ; if ( ! empty ( $ info [ 'name' ] ) ) { return $ info [ 'name' ] ; } } return $ this -> get ( 'handler' ) ; }
Gets a human - readable name of the field handler class .
48,250
public function beforeSave ( Event $ event , User $ user ) { if ( ! $ user -> isNew ( ) && $ user -> has ( 'password' ) && empty ( $ user -> password ) ) { $ user -> unsetProperty ( 'password' ) ; $ user -> dirty ( 'password' , false ) ; } }
If not password is sent means user is not changing it .
48,251
public function updateToken ( User $ user ) { if ( ! $ user -> has ( 'id' ) ) { throw new FatalErrorException ( __d ( 'user' , 'UsersTable::updateToken(), no ID was found for the given entity.' ) ) ; } $ token = md5 ( uniqid ( $ user -> id , true ) ) ; $ count = $ this -> find ( ) -> where ( [ 'Users.token' => $ token ] ) -> limit ( 1 ) -> count ( ) ; while ( $ count > 0 ) { $ token = str_shuffle ( md5 ( uniqid ( $ user -> id , true ) . rand ( 1 , 9999 ) ) ) ; $ count = $ this -> find ( ) -> where ( [ 'Users.token' => $ token ] ) -> limit ( 1 ) -> count ( ) ; } $ user -> set ( 'token' , $ token ) ; $ user -> set ( 'token_expiration' , time ( ) + USER_TOKEN_EXPIRATION ) ; $ this -> updateAll ( [ 'token' => $ user -> get ( 'token' ) , 'token_expiration' => $ user -> get ( 'token_expiration' ) , ] , [ 'id' => $ user -> id ] ) ; return $ user ; }
Generates a unique token for the given user entity . The generated token is automatically persisted on DB .
48,252
protected function _applyPasswordPolicies ( Validator $ validator ) { $ rules = [ ] ; if ( plugin ( 'User' ) -> settings ( 'password_min_length' ) ) { $ len = intval ( plugin ( 'User' ) -> settings ( 'password_min_length' ) ) ; $ rules [ 'length' ] = [ 'rule' => function ( $ value , $ context ) use ( $ len ) { return mb_strlen ( $ this -> _getRawPassword ( $ context ) ) >= $ len ; } , 'message' => __d ( 'user' , 'Password must be at least {0} characters long.' , $ len ) , ] ; } if ( plugin ( 'User' ) -> settings ( 'password_uppercase' ) ) { $ rules [ 'uppercase' ] = [ 'rule' => function ( $ value , $ context ) { return ( bool ) preg_match ( '/[\p{Lu}]/u' , $ this -> _getRawPassword ( $ context ) ) ; } , 'message' => __d ( 'user' , 'Password must contain at least one uppercase character (A-Z).' ) , ] ; } if ( plugin ( 'User' ) -> settings ( 'password_lowercase' ) ) { $ rules [ 'lowercase' ] = [ 'rule' => function ( $ value , $ context ) { return ( bool ) preg_match ( '/[\p{Ll}]/u' , $ this -> _getRawPassword ( $ context ) ) ; } , 'message' => __d ( 'user' , 'Password must contain at least one lowercase character (a-z).' ) , ] ; } if ( plugin ( 'User' ) -> settings ( 'password_number' ) ) { $ rules [ 'number' ] = [ 'rule' => function ( $ value , $ context ) { return ( bool ) preg_match ( '/[\p{N}]/u' , $ this -> _getRawPassword ( $ context ) ) ; } , 'message' => __d ( 'user' , 'Password must contain at least one numeric character (1-9).' ) , ] ; } if ( plugin ( 'User' ) -> settings ( 'password_non_alphanumeric' ) ) { $ rules [ 'non_alphanumeric' ] = [ 'rule' => function ( $ value , $ context ) { return ( bool ) preg_match ( '/[^\p{L}\p{N}]/u' , $ this -> _getRawPassword ( $ context ) ) ; } , 'message' => __d ( 'user' , 'Password must contain at least one non-alphanumeric character (e.g. #%?).' ) , ] ; } $ validator -> add ( 'password' , $ rules ) ; return $ validator ; }
Alters validator object and applies password constraints .
48,253
public function afterSave ( Event $ event , EntityInterface $ entity , ArrayObject $ options ) { $ isNew = $ entity -> isNew ( ) ; if ( ( $ this -> config ( 'on' ) === 'update' && $ isNew ) || ( $ this -> config ( 'on' ) === 'insert' && ! $ isNew ) || ( isset ( $ options [ 'index' ] ) && $ options [ 'index' ] === false ) ) { return ; } $ this -> _table -> dispatchEvent ( 'Model.beforeIndex' , compact ( 'entity' ) ) ; $ success = $ this -> searchEngine ( ) -> index ( $ entity ) ; $ this -> _table -> dispatchEvent ( 'Model.afterIndex' , compact ( 'entity' , 'success' ) ) ; }
Generates a list of words after each entity is saved .
48,254
public function beforeDelete ( Event $ event , EntityInterface $ entity , ArrayObject $ options ) { $ this -> _table -> dispatchEvent ( 'Model.beforeRemoveIndex' , compact ( 'entity' ) ) ; $ success = $ this -> searchEngine ( ) -> delete ( $ entity ) ; $ this -> _table -> dispatchEvent ( 'Model.afterRemoveIndex' , compact ( 'entity' , 'success' ) ) ; return $ success ; }
Prepares entity to delete its words - index .
48,255
public function search ( $ criteria , Query $ query = null , array $ options = [ ] ) { if ( $ query === null ) { $ query = $ this -> _table -> find ( ) ; } return $ this -> searchEngine ( ) -> search ( $ criteria , $ query , $ options ) ; }
Gets entities matching the given search criteria .
48,256
public function addSearchOperator ( $ name , $ handler , array $ options = [ ] ) { $ name = Inflector :: underscore ( $ name ) ; $ operator = [ 'name' => $ name , 'handler' => false , 'options' => [ ] , ] ; if ( is_string ( $ handler ) ) { if ( method_exists ( $ this -> _table , $ handler ) ) { $ operator [ 'handler' ] = $ handler ; } else { list ( $ plugin , $ class ) = pluginSplit ( $ handler ) ; if ( $ plugin ) { $ className = $ plugin === 'Search' ? "Search\\Operator\\{$class}Operator" : "{$plugin}\\Model\\Search\\{$class}Operator" ; $ className = str_replace ( 'OperatorOperator' , 'Operator' , $ className ) ; } else { $ className = $ class ; } $ operator [ 'handler' ] = $ className ; $ operator [ 'options' ] = $ options ; } } elseif ( is_object ( $ handler ) || is_callable ( $ handler ) ) { $ operator [ 'handler' ] = $ handler ; } $ this -> config ( "operators.{$name}" , $ operator ) ; }
Registers a new operator method .
48,257
public function enableSearchOperator ( $ name ) { if ( isset ( $ this -> _config [ 'operators' ] [ ":{$name}" ] ) ) { $ this -> _config [ 'operators' ] [ $ name ] = $ this -> _config [ 'operators' ] [ ":{$name}" ] ; unset ( $ this -> _config [ 'operators' ] [ ":{$name}" ] ) ; } }
Enables a an operator .
48,258
public function disableSearchOperator ( $ name ) { if ( isset ( $ this -> _config [ 'operators' ] [ $ name ] ) ) { $ this -> _config [ 'operators' ] [ ":{$name}" ] = $ this -> _config [ 'operators' ] [ $ name ] ; unset ( $ this -> _config [ 'operators' ] [ $ name ] ) ; } }
Disables an operator .
48,259
public function applySearchOperator ( Query $ query , TokenInterface $ token ) { if ( ! $ token -> isOperator ( ) ) { return $ query ; } $ callable = $ this -> _operatorCallable ( $ token -> name ( ) ) ; if ( is_callable ( $ callable ) ) { $ query = $ callable ( $ query , $ token ) ; if ( ! ( $ query instanceof Query ) ) { throw new FatalErrorException ( __d ( 'search' , 'Error while processing the "{0}" token in the search criteria.' , $ operator ) ) ; } } else { $ result = $ this -> _triggerOperator ( $ query , $ token ) ; if ( $ result instanceof Query ) { $ query = $ result ; } } return $ query ; }
Given a query instance applies the provided token representing a search operator .
48,260
protected function _triggerOperator ( Query $ query , TokenInterface $ token ) { $ eventName = 'Search.' . ( string ) Inflector :: variable ( 'operator_' . $ token -> name ( ) ) ; $ event = new Event ( $ eventName , $ this -> _table , compact ( 'query' , 'token' ) ) ; return EventManager :: instance ( ) -> dispatch ( $ event ) -> result ; }
Triggers an event for handling undefined operators . Event listeners may capture this event and provide operator handling logic such listeners should alter the provided Query object and then return it back .
48,261
protected function _operatorCallable ( $ name ) { $ operator = $ this -> config ( "operators.{$name}" ) ; if ( $ operator ) { $ handler = $ operator [ 'handler' ] ; if ( is_callable ( $ handler ) ) { return function ( $ query , $ token ) use ( $ handler ) { return $ handler ( $ query , $ token ) ; } ; } elseif ( $ handler instanceof BaseOperator ) { return function ( $ query , $ token ) use ( $ handler ) { return $ handler -> scope ( $ query , $ token ) ; } ; } elseif ( is_string ( $ handler ) && method_exists ( $ this -> _table , $ handler ) ) { return function ( $ query , $ token ) use ( $ handler ) { return $ this -> _table -> $ handler ( $ query , $ token ) ; } ; } elseif ( is_string ( $ handler ) && is_subclass_of ( $ handler , '\Search\Operator\BaseOperator' ) ) { return function ( $ query , $ token ) use ( $ operator ) { $ instance = new $ operator [ 'handler' ] ( $ this -> _table , $ operator [ 'options' ] ) ; return $ instance -> scope ( $ query , $ token ) ; } ; } } return false ; }
Gets the callable method for a given operator method .
48,262
public function install ( ) { if ( $ this -> request -> data ( ) ) { $ task = false ; $ uploadError = false ; if ( isset ( $ this -> request -> data [ 'download' ] ) ) { $ task = ( bool ) WebShellDispatcher :: run ( "Installer.plugins install -s \"{$this->request->data['url']}\" --theme -a" ) ; } elseif ( isset ( $ this -> request -> data [ 'file_system' ] ) ) { $ task = ( bool ) WebShellDispatcher :: run ( "Installer.plugins install -s \"{$this->request->data['path']}\" --theme -a" ) ; } else { $ uploader = new PackageUploader ( $ this -> request -> data [ 'file' ] ) ; if ( $ uploader -> upload ( ) ) { $ task = ( bool ) WebShellDispatcher :: run ( 'Installer.plugins install -s "' . $ uploader -> dst ( ) . '" --theme -a' ) ; } else { $ uploadError = true ; $ this -> Flash -> set ( __d ( 'system' , 'Plugins installed but some errors occur' ) , [ 'element' => 'System.installer_errors' , 'params' => [ 'errors' => $ uploader -> errors ( ) , 'type' => 'warning' ] , ] ) ; } } if ( $ task ) { $ this -> Flash -> success ( __d ( 'system' , 'Theme successfully installed!' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } elseif ( ! $ task && ! $ uploadError ) { $ this -> Flash -> set ( __d ( 'system' , 'Theme could not be installed' ) , [ 'element' => 'System.installer_errors' , 'params' => [ 'errors' => WebShellDispatcher :: output ( ) ] , ] ) ; } } $ this -> title ( __d ( 'system' , 'Install Theme' ) ) ; $ this -> Breadcrumb -> push ( '/admin/system/themes' ) -> push ( __d ( 'system' , 'Install new theme' ) , '#' ) ; }
Install a new theme .
48,263
public function uninstall ( $ themeName ) { $ theme = plugin ( $ themeName ) ; if ( ! in_array ( $ themeName , [ option ( 'front_theme' ) , option ( 'back_theme' ) ] ) ) { if ( ! $ theme -> requiredBy ( ) -> isEmpty ( ) ) { $ this -> Flash -> danger ( __d ( 'system' , 'You cannot remove this theme!' ) ) ; } else { $ task = ( bool ) WebShellDispatcher :: run ( "Installer.plugins uninstall -p {$theme->name}" ) ; if ( $ task ) { $ this -> Flash -> success ( __d ( 'system' , 'Theme successfully removed!' ) ) ; } else { $ this -> Flash -> set ( __d ( 'system' , 'Theme could not be removed' ) , [ 'element' => 'System.installer_errors' , 'params' => [ 'errors' => WebShellDispatcher :: output ( ) ] , ] ) ; } } } else { $ this -> Flash -> danger ( __d ( 'system' , 'This theme cannot be removed as it is currently being used.' ) ) ; } $ this -> title ( __d ( 'system' , 'Uninstall Theme' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Removes the given theme .
48,264
public function details ( $ themeName ) { $ theme = plugin ( $ themeName ) ; $ this -> title ( __d ( 'system' , 'Theme Information' ) ) ; $ this -> set ( compact ( 'theme' ) ) ; $ this -> Breadcrumb -> push ( '/admin/system/themes' ) -> push ( $ theme -> humanName , '#' ) -> push ( __d ( 'system' , 'Details' ) , '#' ) ; }
Detailed theme s information .
48,265
public function screenshot ( $ themeName ) { $ theme = plugin ( $ themeName ) ; $ this -> response -> file ( "{$theme->path}/webroot/screenshot.png" ) ; return $ this -> response ; }
Renders theme s screenshot . png
48,266
public function beforeFind ( Event $ event , Query $ query , ArrayObject $ options , $ primary ) { $ status = array_key_exists ( 'fieldable' , $ options ) ? $ options [ 'fieldable' ] : $ this -> config ( 'status' ) ; if ( ! $ status ) { return ; } if ( array_key_exists ( 'eav' , $ options ) ) { unset ( $ options [ 'eav' ] ) ; } return parent :: beforeFind ( $ event , $ query , $ options , $ primary ) ; }
Modifies the query object in order to merge custom fields records into each entity under the _fields property .
48,267
public function beforeSave ( Event $ event , EntityInterface $ entity , ArrayObject $ options ) { if ( ! $ this -> config ( 'status' ) ) { return true ; } if ( ! $ options [ 'atomic' ] ) { throw new FatalErrorException ( __d ( 'field' , 'Entities in fieldable tables can only be saved using transaction. Set [atomic = true]' ) ) ; } if ( ! $ this -> _validation ( $ entity ) ) { return false ; } $ this -> _cache [ 'createValues' ] = [ ] ; foreach ( $ this -> _attributesForEntity ( $ entity ) as $ attr ) { if ( ! $ this -> _toolbox -> propertyExists ( $ entity , $ attr -> get ( 'name' ) ) ) { continue ; } $ field = $ this -> _prepareMockField ( $ entity , $ attr ) ; $ result = $ field -> beforeSave ( $ this -> _fetchPost ( $ field ) ) ; if ( $ result === false ) { $ this -> attachEntityFields ( $ entity ) ; return false ; } $ data = [ 'eav_attribute_id' => $ field -> get ( 'metadata' ) -> get ( 'attribute_id' ) , 'entity_id' => $ this -> _toolbox -> getEntityId ( $ entity ) , "value_{$field->metadata['type']}" => $ field -> get ( 'value' ) , 'extra' => $ field -> get ( 'extra' ) , ] ; if ( $ field -> get ( 'metadata' ) -> get ( 'value_id' ) ) { $ valueEntity = TableRegistry :: get ( 'Eav.EavValues' ) -> get ( $ field -> get ( 'metadata' ) -> get ( 'value_id' ) ) ; $ valueEntity = TableRegistry :: get ( 'Eav.EavValues' ) -> patchEntity ( $ valueEntity , $ data , [ 'validate' => false ] ) ; } else { $ valueEntity = TableRegistry :: get ( 'Eav.EavValues' ) -> newEntity ( $ data , [ 'validate' => false ] ) ; } if ( $ entity -> isNew ( ) || $ valueEntity -> isNew ( ) ) { $ this -> _cache [ 'createValues' ] [ ] = $ valueEntity ; } elseif ( ! TableRegistry :: get ( 'Eav.EavValues' ) -> save ( $ valueEntity ) ) { $ this -> attachEntityFields ( $ entity ) ; $ event -> stopPropagation ( ) ; return false ; } } $ this -> attachEntityFields ( $ entity ) ; return true ; }
Before an entity is saved .
48,268
public function afterSave ( Event $ event , EntityInterface $ entity , ArrayObject $ options ) { if ( ! $ this -> config ( 'status' ) ) { return true ; } if ( ! empty ( $ this -> _cache [ 'createValues' ] ) ) { foreach ( $ this -> _cache [ 'createValues' ] as $ valueEntity ) { $ valueEntity -> set ( 'entity_id' , $ this -> _toolbox -> getEntityId ( $ entity ) ) ; $ valueEntity -> unsetProperty ( 'id' ) ; TableRegistry :: get ( 'Eav.EavValues' ) -> save ( $ valueEntity ) ; } $ this -> _cache [ 'createValues' ] = [ ] ; } foreach ( $ this -> _attributesForEntity ( $ entity ) as $ attr ) { $ field = $ this -> _prepareMockField ( $ entity , $ attr ) ; $ field -> afterSave ( ) ; } if ( $ this -> config ( 'cacheMap' ) ) { $ this -> updateEavCache ( $ entity ) ; } return true ; }
After an entity is saved .
48,269
public function beforeDelete ( Event $ event , EntityInterface $ entity , ArrayObject $ options ) { if ( ! $ this -> config ( 'status' ) ) { return true ; } if ( ! $ options [ 'atomic' ] ) { throw new FatalErrorException ( __d ( 'field' , 'Entities in fieldable tables can only be deleted using transaction. Set [atomic = true]' ) ) ; } foreach ( $ this -> _attributesForEntity ( $ entity ) as $ attr ) { $ field = $ this -> _prepareMockField ( $ entity , $ attr ) ; $ result = $ field -> beforeDelete ( ) ; if ( $ result === false ) { $ event -> stopPropagation ( ) ; return false ; } $ this -> _cache [ 'afterDelete' ] [ ] = $ field ; } return true ; }
Deletes an entity from a fieldable table .
48,270
public function afterDelete ( Event $ event , EntityInterface $ entity , ArrayObject $ options ) { if ( ! $ this -> config ( 'status' ) ) { return ; } if ( ! $ options [ 'atomic' ] ) { throw new FatalErrorException ( __d ( 'field' , 'Entities in fieldable tables can only be deleted using transactions. Set [atomic = true]' ) ) ; } if ( ! empty ( $ this -> _cache [ 'afterDelete' ] ) ) { foreach ( ( array ) $ this -> _cache [ 'afterDelete' ] as $ field ) { $ field -> afterDelete ( ) ; } $ this -> _cache [ 'afterDelete' ] = [ ] ; } parent :: afterDelete ( $ event , $ entity , $ options ) ; }
After an entity was removed from database .
48,271
public function attachEntityFields ( EntityInterface $ entity ) { $ _fields = [ ] ; foreach ( $ this -> _attributesForEntity ( $ entity ) as $ attr ) { $ field = $ this -> _prepareMockField ( $ entity , $ attr ) ; if ( $ entity -> has ( $ field -> get ( 'name' ) ) ) { $ this -> _fetchPost ( $ field ) ; } $ field -> fieldAttached ( ) ; $ _fields [ ] = $ field ; } $ entity -> set ( '_fields' , new FieldCollection ( $ _fields ) ) ; return $ entity ; }
The method which actually fetches custom fields .
48,272
protected function _attributesForEntity ( EntityInterface $ entity ) { $ bundle = $ this -> _resolveBundle ( $ entity ) ; $ attrs = $ this -> _toolbox -> attributes ( $ bundle ) ; $ attrByIds = [ ] ; $ attrByNames = [ ] ; foreach ( $ attrs as $ name => $ attr ) { $ attrByNames [ $ name ] = $ attr ; $ attrByIds [ $ attr -> get ( 'id' ) ] = $ attr ; $ attr -> set ( ':value' , null ) ; } if ( ! empty ( $ attrByIds ) ) { $ instances = $ this -> Attributes -> Instance -> find ( ) -> where ( [ 'eav_attribute_id IN' => array_keys ( $ attrByIds ) ] ) -> all ( ) ; foreach ( $ instances as $ instance ) { if ( ! empty ( $ attrByIds [ $ instance -> get ( 'eav_attribute_id' ) ] ) ) { $ attr = $ attrByIds [ $ instance -> get ( 'eav_attribute_id' ) ] ; if ( ! $ attr -> has ( 'instance' ) ) { $ attr -> set ( 'instance' , $ instance ) ; } } } } $ values = $ this -> _fetchValues ( $ entity , array_keys ( $ attrByNames ) ) ; foreach ( $ values as $ value ) { if ( ! empty ( $ attrByNames [ $ value -> get ( 'eav_attribute' ) -> get ( 'name' ) ] ) ) { $ attrByNames [ $ value -> get ( 'eav_attribute' ) -> get ( 'name' ) ] -> set ( ':value' , $ value ) ; } } return $ this -> _toolbox -> attributes ( $ bundle ) ; }
Gets all attributes that should be attached to the given entity this entity will be used as context to calculate the proper bundle .
48,273
protected function _fetchValues ( EntityInterface $ entity , array $ attrNames = [ ] ) { $ bundle = $ this -> _resolveBundle ( $ entity ) ; $ conditions = [ 'EavAttribute.table_alias' => $ this -> _table -> table ( ) , 'EavValues.entity_id' => $ entity -> get ( ( string ) $ this -> _table -> primaryKey ( ) ) , ] ; if ( $ bundle ) { $ conditions [ 'EavAttribute.bundle' ] = $ bundle ; } if ( ! empty ( $ attrNames ) ) { $ conditions [ 'EavAttribute.name IN' ] = $ attrNames ; } $ storedValues = TableRegistry :: get ( 'Eav.EavValues' ) -> find ( ) -> contain ( [ 'EavAttribute' ] ) -> where ( $ conditions ) -> all ( ) ; return $ storedValues ; }
Retrieves stored values for all virtual properties by name . This gets all values at once .
48,274
protected function _prepareMockField ( EntityInterface $ entity , EntityInterface $ attribute ) { $ type = $ this -> _toolbox -> mapType ( $ attribute -> get ( 'type' ) ) ; if ( ! $ attribute -> has ( ':value' ) ) { $ bundle = $ this -> _resolveBundle ( $ entity ) ; $ conditions = [ 'EavAttribute.table_alias' => $ this -> _table -> table ( ) , 'EavAttribute.name' => $ attribute -> get ( 'name' ) , 'EavValues.entity_id' => $ entity -> get ( ( string ) $ this -> _table -> primaryKey ( ) ) , ] ; if ( $ bundle ) { $ conditions [ 'EavAttribute.bundle' ] = $ bundle ; } $ storedValue = TableRegistry :: get ( 'Eav.EavValues' ) -> find ( ) -> contain ( [ 'EavAttribute' ] ) -> select ( [ 'id' , "value_{$type}" , 'extra' ] ) -> where ( $ conditions ) -> limit ( 1 ) -> first ( ) ; } else { $ storedValue = $ attribute -> get ( ':value' ) ; } $ mockField = new Field ( [ 'name' => $ attribute -> get ( 'name' ) , 'label' => $ attribute -> get ( 'instance' ) -> get ( 'label' ) , 'value' => null , 'extra' => null , 'metadata' => new Entity ( [ 'value_id' => null , 'instance_id' => $ attribute -> get ( 'instance' ) -> get ( 'id' ) , 'attribute_id' => $ attribute -> get ( 'id' ) , 'entity_id' => $ this -> _toolbox -> getEntityId ( $ entity ) , 'table_alias' => $ attribute -> get ( 'table_alias' ) , 'type' => $ type , 'bundle' => $ attribute -> get ( 'bundle' ) , 'handler' => $ attribute -> get ( 'instance' ) -> get ( 'handler' ) , 'required' => $ attribute -> get ( 'instance' ) -> required , 'description' => $ attribute -> get ( 'instance' ) -> description , 'settings' => $ attribute -> get ( 'instance' ) -> settings , 'view_modes' => $ attribute -> get ( 'instance' ) -> view_modes , 'entity' => $ entity , 'errors' => [ ] , ] ) , ] ) ; if ( $ storedValue ) { $ mockField -> set ( 'value' , $ this -> _toolbox -> marshal ( $ storedValue -> get ( "value_{$type}" ) , $ type ) ) ; $ mockField -> set ( 'extra' , $ storedValue -> get ( 'extra' ) ) ; $ mockField -> metadata -> set ( 'value_id' , $ storedValue -> id ) ; } $ mockField -> isNew ( $ entity -> isNew ( ) ) ; return $ mockField ; }
Creates a new Virtual Field to be attached to the given entity .
48,275
protected function _scandir ( $ path ) { $ s3path = preg_replace ( "/^\//" , "" , $ path ) . '/' ; $ files = $ this -> s3 -> ListBucket ( array ( 'Bucket' => $ this -> options [ 'bucket' ] , 'delimiter' => '/' , 'Prefix' => $ s3path ) ) -> ListBucketResponse -> Contents ; $ finalfiles = array ( ) ; foreach ( $ files as $ file ) { if ( preg_match ( "|^" . $ s3path . "[^/]*/?$|" , $ file -> Key ) ) { $ fname = preg_replace ( "/\/$/" , "" , $ file -> Key ) ; $ fname = $ file -> Key ; if ( $ fname != preg_replace ( "/\/$/" , "" , $ s3path ) ) { } $ finalfiles [ ] = $ fname ; } } sort ( $ finalfiles ) ; return $ finalfiles ; }
Return files list in directory
48,276
protected function sign ( $ operation ) { $ params = array ( 'AWSAccessKeyId' => $ this -> accesskey , 'Timestamp' => gmdate ( 'Y-m-d\TH:i:s.000\Z' ) , ) ; $ sign_str = 'AmazonS3' . $ operation . $ params [ 'Timestamp' ] ; $ params [ 'Signature' ] = base64_encode ( hash_hmac ( 'sha1' , $ sign_str , $ this -> secretkey , TRUE ) ) ; return $ params ; }
Generating signature and timestamp for specified S3 operation
48,277
public function logout ( Event $ event , array $ user ) { $ controller = $ this -> _registry -> getController ( ) ; if ( empty ( $ controller -> Cookie ) ) { $ controller -> loadComponent ( 'Cookie' ) ; } $ controller -> Cookie -> delete ( 'User.Cookie' ) ; }
Removes remember me cookie .
48,278
public function shortcodeRandom ( Event $ event , array $ atts , $ content , $ tag ) { if ( strpos ( $ content , ',' ) === false ) { return '' ; } $ elements = explode ( ',' , trim ( $ content ) ) ; $ elements = array_map ( 'trim' , $ elements ) ; $ c = count ( $ elements ) ; if ( $ c == 2 && is_numeric ( $ elements [ 0 ] ) && is_numeric ( $ elements [ 1 ] ) ) { return rand ( $ elements [ 0 ] , $ elements [ 1 ] ) ; } return $ elements [ array_rand ( $ elements ) ] ; }
Implements the random shortcode .
48,279
public function shortcodeTranslate ( Event $ event , array $ atts , $ content , $ tag ) { if ( ! empty ( $ atts [ 'domain' ] ) ) { return __d ( $ atts [ 'domain' ] , $ content ) ; } else { return __ ( $ content ) ; } }
Implements the t shortcode .
48,280
public function shortcodeUrl ( Event $ event , array $ atts , $ content , $ tag ) { try { $ url = Router :: url ( $ content , true ) ; } catch ( \ Exception $ e ) { $ url = '' ; } return $ url ; }
Implements the url shortcode .
48,281
public function shortcodeDate ( Event $ event , array $ atts , $ content , $ tag ) { if ( ! empty ( $ atts [ 'format' ] ) && ! empty ( $ content ) ) { if ( is_numeric ( $ content ) ) { return date ( $ atts [ 'format' ] , $ content ) ; } else { return date ( $ atts [ 'format' ] , strtotime ( $ content ) ) ; } } return '' ; }
Implements the date shortcode .
48,282
public function shortcodeLocale ( Event $ event , array $ atts , $ content , $ tag ) { $ option = array_keys ( ( array ) $ atts ) ; $ locale = I18n :: locale ( ) ; $ languages = quickapps ( 'languages' ) ; $ out = '' ; if ( ! isset ( $ languages [ $ locale ] ) ) { return $ out ; } if ( empty ( $ option ) ) { $ option = 'code' ; } else { $ option = $ option [ 0 ] ; } if ( $ info = $ languages [ $ locale ] ) { switch ( $ option ) { case 'code' : $ out = $ info [ 'code' ] ; break ; case 'name' : $ out = $ info [ 'name' ] ; break ; case 'direction' : $ out = $ info [ 'direction' ] ; break ; } } return $ out ; }
Implements the locale shortcode .
48,283
protected function _getTitle ( ) { if ( $ this -> _getIsPlugin ( ) ) { try { return plugin ( $ this -> alias ) -> humanName ; } catch ( \ Exception $ e ) { return $ this -> alias ; } } return $ this -> alias ; }
For usage as part of MenuHelper .
48,284
public function beforeDispatch ( Event $ event ) { parent :: beforeDispatch ( $ event ) ; $ request = Router :: getRequest ( ) ; if ( empty ( $ request ) ) { throw new InternalErrorException ( __d ( 'cms' , 'No request object could be found.' ) ) ; } $ locales = array_keys ( quickapps ( 'languages' ) ) ; $ localesPattern = '(' . implode ( '|' , array_map ( 'preg_quote' , $ locales ) ) . ')' ; $ rawUrl = str_replace_once ( $ request -> base , '' , env ( 'REQUEST_URI' ) ) ; $ normalizedURL = str_replace ( '//' , '/' , "/{$rawUrl}" ) ; if ( ! empty ( $ request -> query [ 'locale' ] ) && in_array ( $ request -> query [ 'locale' ] , $ locales ) ) { $ request -> session ( ) -> write ( 'locale' , $ request -> query [ 'locale' ] ) ; I18n :: locale ( $ request -> session ( ) -> read ( 'locale' ) ) ; } elseif ( option ( 'url_locale_prefix' ) && preg_match ( "/\/{$localesPattern}\//" , $ normalizedURL , $ matches ) ) { I18n :: locale ( $ matches [ 1 ] ) ; } elseif ( $ request -> session ( ) -> check ( 'locale' ) && in_array ( $ request -> session ( ) -> read ( 'locale' ) , $ locales ) ) { I18n :: locale ( $ request -> session ( ) -> read ( 'locale' ) ) ; } elseif ( $ request -> is ( 'userLoggedIn' ) && in_array ( user ( ) -> locale , $ locales ) ) { I18n :: locale ( user ( ) -> locale ) ; } elseif ( in_array ( option ( 'default_language' ) , $ locales ) ) { I18n :: locale ( option ( 'default_language' ) ) ; } else { I18n :: locale ( CORE_LOCALE ) ; } if ( option ( 'url_locale_prefix' ) && ! $ request -> is ( 'home' ) && ! preg_match ( "/\/{$localesPattern}\//" , $ normalizedURL ) ) { $ url = Router :: url ( '/' . I18n :: locale ( ) . $ normalizedURL , true ) ; http_response_code ( 303 ) ; header ( "Location: {$url}" ) ; die ; } }
Prepares the default language to use by the script .
48,285
protected function _getType ( ) { $ name = __d ( 'content' , '(unknown)' ) ; if ( $ this -> has ( 'content_type' ) && $ this -> get ( 'content_type' ) -> has ( 'name' ) ) { $ name = $ this -> get ( 'content_type' ) -> get ( 'name' ) ; } return $ name ; }
Gets content type .
48,286
protected function _getUrl ( ) { $ url = Router :: getRequest ( ) -> base ; if ( option ( 'url_locale_prefix' ) ) { $ url .= '/' . I18n :: locale ( ) ; } $ url .= "/{$this->content_type_slug}/{$this->slug}" ; return Router :: normalize ( $ url ) . CONTENT_EXTENSION ; }
Gets content s details page URL .
48,287
protected function _getAuthor ( ) { if ( $ this -> created_by instanceof User ) { return $ this -> created_by ; } return new User ( [ 'username' => __d ( 'content' , 'unknown' ) , 'name' => __d ( 'content' , 'Unknown' ) , 'web' => __d ( 'content' , '(no website)' ) , 'email' => __d ( 'content' , 'Unknown' ) , ] ) ; }
Gets content s author as an User entity .
48,288
public function parent ( ) { if ( ! $ this -> has ( 'slug' ) ) { throw new FatalErrorException ( __d ( 'content' , "Missing property 'slug', make sure to include it using Query::select()." ) ) ; } return TableRegistry :: get ( 'Content.Contents' ) -> find ( ) -> select ( [ 'id' , 'slug' , 'content_type_slug' , 'language' ] ) -> where ( [ 'id' => $ this -> translation_for , 'status' => 1 , ] ) -> first ( ) ; }
Gets the parent content for which this content is a translation of .
48,289
public function translation ( $ locale = null ) { if ( ! $ this -> has ( 'id' ) || ! $ this -> has ( 'content_type_slug' ) ) { throw new FatalErrorException ( __d ( 'content' , "Missing properties 'id' or 'content_type_slug', make sure to include them using Query::select()." ) ) ; } if ( $ locale === null ) { $ locale = I18n :: locale ( ) ; } return TableRegistry :: get ( 'Content.Contents' ) -> find ( ) -> select ( [ 'id' , 'slug' , 'content_type_slug' , 'language' ] ) -> where ( [ 'translation_for' => $ this -> id , 'language' => $ locale , 'status' => 1 , ] ) -> first ( ) ; }
Find if this content has a translation to the given locale code .
48,290
public function setDefaults ( $ type = false ) { if ( ! $ type ) { if ( ! $ this -> has ( 'content_type_slug' ) && ! $ this -> has ( 'id' ) ) { throw new FatalErrorException ( __d ( 'content' , 'Unable to get Content-Type information.' ) ) ; } if ( ! $ this -> has ( 'content_type_slug' ) ) { $ contentTypeSlug = TableRegistry :: get ( 'Content.Contents' ) -> find ( ) -> select ( [ 'content_type_slug' ] ) -> where ( [ 'id' => $ this -> get ( 'id' ) ] ) -> first ( ) ; $ contentTypeSlug = $ contentTypeSlug -> content_type_slug ; } else { $ contentTypeSlug = $ this -> get ( 'content_type_slug' ) ; } $ type = TableRegistry :: get ( 'Content.ContentTypes' ) -> find ( ) -> where ( [ 'slug' => $ contentTypeSlug ] ) -> first ( ) ; } if ( ! ( $ type instanceof ContentType ) || ! $ type -> has ( 'defaults' ) ) { throw new FatalErrorException ( __d ( 'content' , "Content::setDefaults() was unable to get Content Type defaults values." ) ) ; } $ this -> set ( 'language' , $ type -> defaults [ 'language' ] ) ; $ this -> set ( 'comment_status' , $ type -> defaults [ 'comment_status' ] ) ; $ this -> set ( 'status' , $ type -> defaults [ 'status' ] ) ; $ this -> set ( 'promote' , $ type -> defaults [ 'promote' ] ) ; $ this -> set ( 'sticky' , $ type -> defaults [ 'sticky' ] ) ; }
Set defaults content settings based on parent content type .
48,291
public function commandExists ( $ cmd ) { return $ this -> loaded && isset ( $ this -> commands [ $ cmd ] ) && method_exists ( $ this , $ cmd ) ; }
Return true if command exists
48,292
public function realpath ( $ hash ) { if ( ( $ volume = $ this -> volume ( $ hash ) ) == false ) { return false ; } return $ volume -> realpath ( $ hash ) ; }
Return file real path
48,293
protected function getNetVolumes ( ) { return isset ( $ _SESSION [ $ this -> netVolumesSessionKey ] ) && is_array ( $ _SESSION [ $ this -> netVolumesSessionKey ] ) ? $ _SESSION [ $ this -> netVolumesSessionKey ] : array ( ) ; }
Return network volumes config .
48,294
public function error ( ) { $ errors = array ( ) ; foreach ( func_get_args ( ) as $ msg ) { if ( is_array ( $ msg ) ) { $ errors = array_merge ( $ errors , $ msg ) ; } else { $ errors [ ] = $ msg ; } } return count ( $ errors ) ? $ errors : array ( self :: ERROR_UNKNOWN ) ; }
Normalize error messages
48,295
protected function tree ( $ args ) { $ target = $ args [ 'target' ] ; if ( ( $ volume = $ this -> volume ( $ target ) ) == false || ( $ tree = $ volume -> tree ( $ target ) ) == false ) { return array ( 'error' => $ this -> error ( self :: ERROR_OPEN , '#' . $ target ) ) ; } return array ( 'tree' => $ tree ) ; }
Return subdirs for required directory
48,296
protected function tmb ( $ args ) { $ result = array ( 'images' => array ( ) ) ; $ targets = $ args [ 'targets' ] ; foreach ( $ targets as $ target ) { if ( ( $ volume = $ this -> volume ( $ target ) ) != false && ( ( $ tmb = $ volume -> tmb ( $ target ) ) != false ) ) { $ result [ 'images' ] [ $ target ] = $ tmb ; } } return $ result ; }
Return new created thumbnails list
48,297
protected function file ( $ args ) { $ target = $ args [ 'target' ] ; $ download = ! empty ( $ args [ 'download' ] ) ; $ h403 = 'HTTP/1.x 403 Access Denied' ; $ h404 = 'HTTP/1.x 404 Not Found' ; if ( ( $ volume = $ this -> volume ( $ target ) ) == false ) { return array ( 'error' => 'File not found' , 'header' => $ h404 , 'raw' => true ) ; } if ( ( $ file = $ volume -> file ( $ target ) ) == false ) { return array ( 'error' => 'File not found' , 'header' => $ h404 , 'raw' => true ) ; } if ( ! $ file [ 'read' ] ) { return array ( 'error' => 'Access denied' , 'header' => $ h403 , 'raw' => true ) ; } if ( ( $ fp = $ volume -> open ( $ target ) ) == false ) { return array ( 'error' => 'File not found' , 'header' => $ h404 , 'raw' => true ) ; } if ( $ download ) { $ disp = 'attachment' ; $ mime = 'application/force-download' ; } else { $ disp = preg_match ( '/^(image|text)/i' , $ file [ 'mime' ] ) || $ file [ 'mime' ] == 'application/x-shockwave-flash' ? 'inline' : 'attachment' ; $ mime = $ file [ 'mime' ] ; } $ filenameEncoded = rawurlencode ( $ file [ 'name' ] ) ; if ( strpos ( $ filenameEncoded , '%' ) === false ) { $ filename = 'filename="' . $ file [ 'name' ] . '"' ; } else { $ ua = $ _SERVER [ "HTTP_USER_AGENT" ] ; if ( preg_match ( '/MSIE [4-8]/' , $ ua ) ) { $ filename = 'filename="' . $ filenameEncoded . '"' ; } elseif ( strpos ( $ ua , 'Chrome' ) === false && strpos ( $ ua , 'Safari' ) !== false ) { $ filename = 'filename="' . str_replace ( '"' , '' , $ file [ 'name' ] ) . '"' ; } else { $ filename = 'filename*=UTF-8\'\'' . $ filenameEncoded ; } } $ result = array ( 'volume' => $ volume , 'pointer' => $ fp , 'info' => $ file , 'header' => array ( 'Content-Type: ' . $ mime , 'Content-Disposition: ' . $ disp . '; ' . $ filename , 'Content-Location: ' . $ file [ 'name' ] , 'Content-Transfer-Encoding: binary' , 'Content-Length: ' . $ file [ 'size' ] , 'Connection: close' ) ) ; return $ result ; }
Required to output file in browser when volume URL is not set Return array contains opened file pointer root itself and required headers
48,298
protected function size ( $ args ) { $ size = 0 ; foreach ( $ args [ 'targets' ] as $ target ) { if ( ( $ volume = $ this -> volume ( $ target ) ) == false || ( $ file = $ volume -> file ( $ target ) ) == false || ! $ file [ 'read' ] ) { return array ( 'error' => $ this -> error ( self :: ERROR_OPEN , '#' . $ target ) ) ; } $ size += $ volume -> size ( $ target ) ; } return array ( 'size' => $ size ) ; }
Count total files size
48,299
protected function mkfile ( $ args ) { $ target = $ args [ 'target' ] ; $ name = $ args [ 'name' ] ; if ( ( $ volume = $ this -> volume ( $ target ) ) == false ) { return array ( 'error' => $ this -> error ( self :: ERROR_MKFILE , $ name , self :: ERROR_TRGDIR_NOT_FOUND , '#' . $ target ) ) ; } return ( $ file = $ volume -> mkfile ( $ target , $ args [ 'name' ] ) ) == false ? array ( 'error' => $ this -> error ( self :: ERROR_MKFILE , $ name , $ volume -> error ( ) ) ) : array ( 'added' => array ( $ file ) ) ; }
Create empty file