idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
48,300
protected function duplicate ( $ args ) { $ targets = is_array ( $ args [ 'targets' ] ) ? $ args [ 'targets' ] : array ( ) ; $ result = array ( 'added' => array ( ) ) ; $ suffix = empty ( $ args [ 'suffix' ] ) ? 'copy' : $ args [ 'suffix' ] ; foreach ( $ targets as $ target ) { if ( ( $ volume = $ this -> volume ( $ target ) ) == false || ( $ src = $ volume -> file ( $ target ) ) == false ) { $ result [ 'warning' ] = $ this -> error ( self :: ERROR_COPY , '#' . $ target , self :: ERROR_FILE_NOT_FOUND ) ; break ; } if ( ( $ file = $ volume -> duplicate ( $ target , $ suffix ) ) == false ) { $ result [ 'warning' ] = $ this -> error ( $ volume -> error ( ) ) ; break ; } $ result [ 'added' ] [ ] = $ file ; } return $ result ; }
Duplicate file - create copy with copy %d suffix
48,301
protected function parse_data_scheme ( $ str , $ extTable ) { $ data = $ name = '' ; if ( $ fp = fopen ( 'data://' . substr ( $ str , 5 ) , 'rb' ) ) { if ( $ data = stream_get_contents ( $ fp ) ) { $ meta = stream_get_meta_data ( $ fp ) ; $ ext = isset ( $ extTable [ $ meta [ 'mediatype' ] ] ) ? '.' . $ extTable [ $ meta [ 'mediatype' ] ] : '' ; $ name = substr ( md5 ( $ data ) , 0 , 8 ) . $ ext ; } fclose ( $ fp ) ; } return array ( $ data , $ name ) ; }
Parse Data URI scheme
48,302
protected function detectFileExtension ( $ path ) { static $ type , $ finfo , $ extTable ; if ( ! $ type ) { $ keys = array_keys ( $ this -> volumes ) ; $ volume = $ this -> volumes [ $ keys [ 0 ] ] ; $ extTable = array_flip ( array_unique ( $ volume -> getMimeTable ( ) ) ) ; if ( class_exists ( 'finfo' ) ) { $ tmpFileInfo = @ explode ( ';' , @ finfo_file ( finfo_open ( FILEINFO_MIME ) , __FILE__ ) ) ; } else { $ tmpFileInfo = false ; } $ regexp = '/text\/x\-(php|c\+\+)/' ; if ( $ tmpFileInfo && preg_match ( $ regexp , array_shift ( $ tmpFileInfo ) ) ) { $ type = 'finfo' ; $ finfo = finfo_open ( FILEINFO_MIME ) ; } elseif ( function_exists ( 'mime_content_type' ) && preg_match ( $ regexp , array_shift ( explode ( ';' , mime_content_type ( __FILE__ ) ) ) ) ) { $ type = 'mime_content_type' ; } elseif ( function_exists ( 'getimagesize' ) ) { $ type = 'getimagesize' ; } else { $ type = 'none' ; } } $ mime = '' ; if ( $ type === 'finfo' ) { $ mime = @ finfo_file ( $ finfo , $ path ) ; } elseif ( $ type === 'mime_content_type' ) { $ mime = mime_content_type ( $ path ) ; } elseif ( $ type === 'getimagesize' ) { if ( $ img = @ getimagesize ( $ path ) ) { $ mime = $ img [ 'mime' ] ; } } if ( $ mime ) { $ mime = explode ( ';' , $ mime ) ; $ mime = trim ( $ mime [ 0 ] ) ; if ( in_array ( $ mime , array ( 'application/x-empty' , 'inode/x-empty' ) ) ) { $ mime = 'text/plain' ; } elseif ( $ mime == 'application/x-zip' ) { $ mime = 'application/zip' ; } } return ( $ mime && isset ( $ extTable [ $ mime ] ) ) ? ( '.' . $ extTable [ $ mime ] ) : '' ; }
Detect file type extension by local path
48,303
private function checkChunkedFile ( $ tmpname , $ chunk , $ cid , $ tempDir ) { if ( preg_match ( '/^(.+)(\.\d+_(\d+))\.part$/s' , $ chunk , $ m ) ) { $ encname = md5 ( $ cid . '_' . $ m [ 1 ] ) ; $ part = $ tempDir . '/ELF' . $ encname . $ m [ 2 ] ; if ( is_null ( $ tmpname ) ) { foreach ( glob ( $ tempDir . '/ELF' . $ encname . '*' ) as $ cf ) { @ unlink ( $ cf ) ; } return ; } if ( move_uploaded_file ( $ tmpname , $ part ) ) { @ chmod ( $ part , 0600 ) ; $ total = $ m [ 3 ] ; $ parts = array ( ) ; for ( $ i = 0 ; $ i <= $ total ; $ i ++ ) { $ name = $ tempDir . '/ELF' . $ encname . '.' . $ i . '_' . $ total ; if ( is_readable ( $ name ) ) { $ parts [ ] = $ name ; } else { $ parts = null ; break ; } } if ( $ parts ) { $ check = $ tempDir . '/ELF' . $ encname ; if ( ! is_file ( $ check ) ) { touch ( $ check ) ; if ( $ resfile = tempnam ( $ tempDir , 'ELF' ) ) { $ target = fopen ( $ resfile , 'wb' ) ; foreach ( $ parts as $ f ) { $ fp = fopen ( $ f , 'rb' ) ; while ( ! feof ( $ fp ) ) { fwrite ( $ target , fread ( $ fp , 8192 ) ) ; } fclose ( $ fp ) ; unlink ( $ f ) ; } fclose ( $ target ) ; unlink ( $ check ) ; return array ( $ resfile , $ m [ 1 ] ) ; } unlink ( $ check ) ; } } } } return array ( '' , '' ) ; }
Check chunked upload files
48,304
private function getTempDir ( $ volumeTempPath = null ) { $ testDirs = array ( ) ; if ( function_exists ( 'sys_get_temp_dir' ) ) { $ testDirs [ ] = sys_get_temp_dir ( ) ; } if ( $ volumeTempPath ) { $ testDirs [ ] = rtrim ( realpath ( $ volumeTempPath ) , DIRECTORY_SEPARATOR ) ; } $ tempDir = '' ; $ test = DIRECTORY_SEPARATOR . microtime ( true ) ; foreach ( $ testDirs as $ testDir ) { if ( ! $ testDir ) continue ; $ testFile = $ testDir . $ test ; if ( touch ( $ testFile ) ) { unlink ( $ testFile ) ; $ tempDir = $ testDir ; $ gc = time ( ) - 3600 ; foreach ( glob ( $ tempDir . '/ELF*' ) as $ cf ) { if ( filemtime ( $ cf ) < $ gc ) { @ unlink ( $ cf ) ; } } break ; } } return $ tempDir ; }
Get temporary dirctroy path
48,305
protected function put ( $ args ) { $ target = $ args [ 'target' ] ; if ( ( $ volume = $ this -> volume ( $ target ) ) == false || ( $ file = $ volume -> file ( $ target ) ) == false ) { return array ( 'error' => $ this -> error ( self :: ERROR_SAVE , '#' . $ target , self :: ERROR_FILE_NOT_FOUND ) ) ; } if ( ( $ file = $ volume -> putContents ( $ target , $ args [ 'content' ] ) ) == false ) { return array ( 'error' => $ this -> error ( self :: ERROR_SAVE , $ volume -> path ( $ target ) , $ volume -> error ( ) ) ) ; } return array ( 'changed' => array ( $ file ) ) ; }
Save content into text file
48,306
protected function dim ( $ args ) { $ target = $ args [ 'target' ] ; if ( ( $ volume = $ this -> volume ( $ target ) ) != false ) { $ dim = $ volume -> dimensions ( $ target ) ; return $ dim ? array ( 'dim' => $ dim ) : array ( ) ; } return array ( ) ; }
Return image dimmensions
48,307
protected function callback ( $ args ) { $ checkReg = '/[^a-zA-Z0-9;._-]/' ; $ node = ( isset ( $ args [ 'node' ] ) && ! preg_match ( $ checkReg , $ args [ 'node' ] ) ) ? $ args [ 'node' ] : '' ; $ json = ( isset ( $ args [ 'json' ] ) && @ json_decode ( $ args [ 'json' ] ) ) ? $ args [ 'json' ] : '{}' ; $ bind = ( isset ( $ args [ 'bind' ] ) && ! preg_match ( $ checkReg , $ args [ 'bind' ] ) ) ? $ args [ 'bind' ] : '' ; $ done = ( ! empty ( $ args [ 'done' ] ) ) ; while ( ob_get_level ( ) ) { if ( ! ob_end_clean ( ) ) { break ; } } if ( $ done || ! $ this -> callbackWindowURL ) { $ script = '' ; if ( $ node ) { $ script .= ' var w = window.opener || weindow.parent || window var elf = w.document.getElementById(\'' . $ node . '\').elfinder; if (elf) { var data = ' . $ json . '; data.warning && elf.error(data.warning); data.removed && data.removed.length && elf.remove(data); data.added && data.added.length && elf.add(data); data.changed && data.changed.length && elf.change(data);' ; if ( $ bind ) { $ script .= ' elf.trigger(\'' . $ bind . '\', data);' ; } $ script .= ' data.sync && elf.sync(); }' ; } $ script .= 'window.close();' ; $ out = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><script>' . $ script . '</script></head><body><a href="#" onlick="window.close();return false;">Close this window</a></body></html>' ; header ( 'Content-Type: text/html; charset=utf-8' ) ; header ( 'Content-Length: ' . strlen ( $ out ) ) ; header ( 'Cache-Control: private' ) ; header ( 'Pragma: no-cache' ) ; echo $ out ; } else { $ url = $ this -> callbackWindowURL ; $ url .= ( ( strpos ( $ url , '?' ) === false ) ? '?' : '&' ) . '&node=' . rawurlencode ( $ node ) . ( ( $ json !== '{}' ) ? ( '&json=' . rawurlencode ( $ json ) ) : '' ) . ( $ bind ? ( '&bind=' . rawurlencode ( $ bind ) ) : '' ) . '&done=1' ; header ( 'Location: ' . $ url ) ; } exit ( ) ; }
Output callback result with JavaScript that control elFinder or HTTP redirect to callbackWindowURL
48,308
protected function volume ( $ hash ) { foreach ( $ this -> volumes as $ id => $ v ) { if ( strpos ( '' . $ hash , $ id ) === 0 ) { return $ this -> volumes [ $ id ] ; } } return false ; }
Return root - file s owner
48,309
protected function filter ( $ files ) { foreach ( $ files as $ i => $ file ) { if ( ! empty ( $ file [ 'hidden' ] ) || ! $ this -> default -> mimeAccepted ( $ file [ 'mime' ] ) ) { unset ( $ files [ $ i ] ) ; } } return array_merge ( $ files , array ( ) ) ; }
Remove from files list hidden files and files with required mime types
48,310
public static function uses ( $ slug ) { if ( empty ( static :: $ _modes [ $ slug ] ) ) { throw new InternalErrorException ( __d ( 'cms' , 'Illegal usage of ViewModeRegistry::uses(), view mode "{0}" was not found.' , $ slug ) ) ; } static :: $ _current = $ slug ; }
Marks as in use the given view mode .
48,311
public static function remove ( $ slug = null ) { if ( $ slug === null ) { static :: $ _current = null ; static :: $ _modes = [ ] ; } else { if ( isset ( static :: $ _modes [ $ slug ] ) ) { unset ( static :: $ _modes [ $ slug ] ) ; } } }
Unregisters the given view - mode or all of them if first parameter is null .
48,312
public static function current ( $ full = false ) { if ( empty ( static :: $ _current ) ) { return '' ; } elseif ( $ full === false ) { return static :: $ _current ; } return static :: $ _modes [ static :: $ _current ] ; }
Gets the in use view - mode information .
48,313
public function beforeSave ( Event $ event , Aco $ aco ) { if ( $ aco -> isNew ( ) ) { $ aco -> set ( 'alias_hash' , md5 ( $ aco -> alias ) ) ; } }
We create a hash of alias property so we can perform case sensitive SQL comparisons .
48,314
public function node ( $ ref ) { $ type = $ this -> alias ( ) ; $ table = $ this -> table ( ) ; $ path = [ ] ; if ( is_array ( $ ref ) ) { $ path = implode ( '/' , array_values ( array_filter ( $ ref ) ) ) ; $ path = explode ( '/' , $ path ) ; } elseif ( is_string ( $ ref ) ) { $ path = explode ( '/' , $ ref ) ; } if ( empty ( $ path ) ) { return false ; } $ start = $ path [ 0 ] ; unset ( $ path [ 0 ] ) ; $ queryData = [ 'conditions' => [ "{$type}.lft" . ' <= ' . "{$type}0.lft" , "{$type}.rght" . ' >= ' . "{$type}0.rght" , ] , 'fields' => [ 'id' , 'parent_id' , 'alias' ] , 'join' => [ [ 'table' => $ table , 'alias' => "{$type}0" , 'type' => 'INNER' , 'conditions' => [ "{$type}0.alias_hash" => md5 ( $ start ) , "{$type}0.plugin = {$type}.plugin" , ] ] ] , 'order' => "{$type}.lft" . ' DESC' ] ; foreach ( $ path as $ i => $ alias ) { $ j = $ i - 1 ; $ queryData [ 'join' ] [ ] = [ 'table' => $ table , 'alias' => "{$type}{$i}" , 'type' => 'INNER' , 'conditions' => [ "{$type}{$i}.lft" . ' > ' . "{$type}{$j}.lft" , "{$type}{$i}.rght" . ' < ' . "{$type}{$j}.rght" , "{$type}{$i}.alias_hash" => md5 ( $ alias ) , "{$type}{$i}.plugin = {$type}{$i}.plugin" , "{$type}{$j}.id" . ' = ' . "{$type}{$i}.parent_id" ] ] ; $ queryData [ 'conditions' ] = [ 'OR' => [ "{$type}.lft" . ' <= ' . "{$type}0.lft" . ' AND ' . "{$type}.rght" . ' >= ' . "{$type}0.rght" , "{$type}.lft" . ' <= ' . "{$type}{$i}.lft" . ' AND ' . "{$type}.rght" . ' >= ' . "{$type}{$i}.rght" ] ] ; } $ query = $ this -> find ( 'all' , $ queryData ) ; $ result = $ query -> toArray ( ) ; $ path = array_values ( $ path ) ; if ( ! isset ( $ result [ 0 ] ) || ( ! empty ( $ path ) && $ result [ 0 ] -> alias !== $ path [ count ( $ path ) - 1 ] ) || ( empty ( $ path ) && $ result [ 0 ] -> alias !== $ start ) ) { return false ; } return $ query ; }
Retrieves the ACO contents for the given ACO path .
48,315
public function add ( $ vocabularyId ) { $ this -> loadModel ( 'Taxonomy.Vocabularies' ) ; $ vocabulary = $ this -> Vocabularies -> get ( $ vocabularyId ) ; $ term = $ this -> Vocabularies -> Terms -> newEntity ( [ 'vocabulary_id' => $ vocabulary -> id ] , [ 'validate' => false ] ) ; $ this -> Vocabularies -> Terms -> addBehavior ( 'Tree' , [ 'scope' => [ 'vocabulary_id' => $ vocabulary -> id ] ] ) ; if ( $ this -> request -> data ( ) ) { $ term = $ this -> Vocabularies -> Terms -> patchEntity ( $ term , $ this -> request -> data , [ 'fieldList' => [ 'parent_id' , 'name' , ] ] ) ; if ( $ this -> Vocabularies -> Terms -> save ( $ term ) ) { $ this -> Flash -> success ( __d ( 'taxonomy' , 'Term has been created.' ) ) ; if ( ! empty ( $ this -> request -> data [ 'action_vocabulary' ] ) ) { $ this -> redirect ( [ 'plugin' => 'Taxonomy' , 'controller' => 'terms' , 'action' => 'vocabulary' , $ vocabulary -> id ] ) ; } elseif ( ! empty ( $ this -> request -> data [ 'action_add' ] ) ) { $ this -> redirect ( [ 'plugin' => 'Taxonomy' , 'controller' => 'terms' , 'action' => 'add' , $ vocabulary -> id ] ) ; } } else { $ this -> Flash -> danger ( __d ( 'taxonomy' , 'Term could not be created, please check your information.' ) ) ; } } $ parentsTree = $ this -> Vocabularies -> Terms -> find ( 'treeList' , [ 'spacer' => '--' ] ) -> map ( function ( $ link ) { if ( strpos ( $ link , '-' ) !== false ) { $ link = str_replace_last ( '-' , '- ' , $ link ) ; } return $ link ; } ) ; $ this -> title ( __d ( 'taxonomy' , 'Create New Term' ) ) ; $ this -> set ( compact ( 'vocabulary' , 'term' , 'parentsTree' ) ) ; $ this -> Breadcrumb -> push ( '/admin/system/structure' ) -> push ( __d ( 'taxonomy' , 'Taxonomy' ) , '/admin/taxonomy/manage' ) -> push ( __d ( 'taxonomy' , 'Vocabularies' ) , [ 'plugin' => 'Taxonomy' , 'controller' => 'vocabularies' , 'action' => 'index' ] ) -> push ( "\"{$vocabulary->name}\"" , [ 'plugin' => 'Taxonomy' , 'controller' => 'vocabularies' , 'action' => 'edit' , $ vocabulary -> id ] ) -> push ( __d ( 'taxonomy' , 'Terms' ) , [ 'plugin' => 'Taxonomy' , 'controller' => 'terms' , 'action' => 'vocabulary' , $ vocabulary -> id ] ) -> push ( __d ( 'taxonomy' , 'Add new term' ) , '#' ) ; }
Adds a new terms within the given vocabulary .
48,316
public function edit ( $ id ) { $ this -> loadModel ( 'Taxonomy.Terms' ) ; $ term = $ this -> Terms -> get ( $ id , [ 'contain' => [ 'Vocabularies' ] ] ) ; $ vocabulary = $ term -> vocabulary ; if ( $ this -> request -> data ( ) ) { $ term = $ this -> Terms -> patchEntity ( $ term , $ this -> request -> data ( ) , [ 'fieldList' => [ 'name' ] ] ) ; $ errors = $ term -> errors ( ) ; if ( empty ( $ errors ) ) { $ this -> Terms -> save ( $ term , [ 'associated' => false ] ) ; $ this -> Flash -> success ( __d ( 'taxonomy' , 'Term has been updated' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } else { $ this -> Flash -> danger ( __d ( 'taxonomy' , 'Term could not be updated, please check your information' ) ) ; } } $ this -> title ( __d ( 'taxonomy' , 'Editing Term' ) ) ; $ this -> set ( 'term' , $ term ) ; $ this -> Breadcrumb -> push ( '/admin/system/structure' ) -> push ( __d ( 'taxonomy' , 'Taxonomy' ) , '/admin/taxonomy/manage' ) -> push ( __d ( 'taxonomy' , 'Vocabularies' ) , [ 'plugin' => 'Taxonomy' , 'controller' => 'vocabularies' , 'action' => 'index' ] ) -> push ( "\"{$vocabulary->name}\"" , [ 'plugin' => 'Taxonomy' , 'controller' => 'vocabularies' , 'action' => 'edit' , $ vocabulary -> id ] ) -> push ( __d ( 'taxonomy' , 'Terms' ) , [ 'plugin' => 'Taxonomy' , 'controller' => 'terms' , 'action' => 'vocabulary' , $ vocabulary -> id ] ) -> push ( __d ( 'taxonomy' , 'Editing term' ) , '#' ) ; }
Edits the given vocabulary s term by ID .
48,317
public function delete ( $ id ) { $ this -> loadModel ( 'Taxonomy.Terms' ) ; $ term = $ this -> Terms -> get ( $ id ) ; $ this -> Terms -> addBehavior ( 'Tree' , [ 'scope' => [ 'vocabulary_id' => $ term -> vocabulary_id ] ] ) ; $ this -> Terms -> removeFromTree ( $ term ) ; if ( $ this -> Terms -> delete ( $ term ) ) { $ this -> Flash -> success ( __d ( 'taxonomy' , 'Term successfully removed!' ) ) ; } else { $ this -> Flash -> danger ( __d ( 'taxonomy' , 'Term could not be removed, please try again' ) ) ; } $ this -> title ( __d ( 'taxonomy' , 'Delete Term' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Deletes the given term .
48,318
protected function _parseRange ( $ value ) { $ range = parent :: _parseRange ( $ value ) ; $ lower = $ this -> _normalize ( $ range [ 'lower' ] ) ; $ upper = $ this -> _normalize ( $ range [ 'upper' ] ) ; if ( strtotime ( $ lower ) > strtotime ( $ upper ) ) { list ( $ lower , $ upper ) = [ $ upper , $ lower ] ; } return [ 'lower' => $ lower , 'upper' => $ upper , ] ; }
Parses and extracts lower and upper date values from the given range given as lower .. upper .
48,319
protected function _normalize ( $ date ) { $ date = preg_replace ( '/[^0-9\-]/' , '' , $ date ) ; $ parts = explode ( '-' , $ date ) ; $ year = date ( 'Y' ) ; $ month = 1 ; $ day = 1 ; if ( ! empty ( $ parts [ 0 ] ) && 1 <= intval ( $ parts [ 0 ] ) && intval ( $ parts [ 0 ] ) <= 32767 ) { $ year = intval ( $ parts [ 0 ] ) ; } if ( ! empty ( $ parts [ 1 ] ) && 1 <= intval ( $ parts [ 1 ] ) && intval ( $ parts [ 1 ] ) <= 12 ) { $ month = intval ( $ parts [ 1 ] ) ; } if ( ! empty ( $ parts [ 2 ] ) && 1 <= intval ( $ parts [ 2 ] ) && intval ( $ parts [ 2 ] ) <= 31 ) { $ day = intval ( $ parts [ 2 ] ) ; } return date ( 'Y-m-d' , strtotime ( "{$year}-{$month}-{$day}" ) ) ; }
Normalizes the given date .
48,320
public function info ( ) { $ handler = $ this -> get ( 'handler' ) ; if ( class_exists ( $ handler ) ) { $ handler = new $ handler ( ) ; return $ handler -> info ( ) ; } return [ ] ; }
Gets handler information .
48,321
public function viewModeSettings ( View $ view , $ viewMode ) { $ handler = $ this -> get ( 'handler' ) ; if ( class_exists ( $ handler ) ) { $ handler = new $ handler ( ) ; return $ handler -> viewModeSettings ( $ this , $ view , $ viewMode ) ; } return '' ; }
Renders view - mode s settings form elements .
48,322
public function defaultViewModeSettings ( $ viewMode ) { $ handler = $ this -> get ( 'handler' ) ; if ( class_exists ( $ handler ) ) { $ handler = new $ handler ( ) ; return $ handler -> defaultViewModeSettings ( $ this , $ viewMode ) ; } return [ ] ; }
Gets default settings for the given view - mode .
48,323
private function input_filter ( $ args ) { static $ magic_quotes_gpc = NULL ; if ( $ magic_quotes_gpc === NULL ) $ magic_quotes_gpc = ( version_compare ( PHP_VERSION , '5.4' , '<' ) && get_magic_quotes_gpc ( ) ) ; if ( is_array ( $ args ) ) { return array_map ( array ( & $ this , 'input_filter' ) , $ args ) ; } $ res = str_replace ( "\0" , '' , $ args ) ; $ magic_quotes_gpc && ( $ res = stripslashes ( $ res ) ) ; return $ res ; }
Remove null & stripslashes applies on magic_quotes_gpc
48,324
public static function create ( $ package ) { static :: _init ( ) ; foreach ( static :: $ _detectors as $ name => $ callable ) { $ result = $ callable ( $ package ) ; if ( $ result instanceof BasePackage ) { return $ result ; } } return new GenericPackage ( $ package , '' , '' ) ; }
Given a full package name returns an instance of an object representing that package .
48,325
protected static function _init ( ) { if ( static :: $ _initialized ) { return ; } static :: $ _detectors [ 'plugin' ] = function ( $ package ) { return static :: _getPlugin ( $ package ) ; } ; static :: $ _detectors [ 'library' ] = function ( $ package ) { return static :: _getLibrary ( $ package ) ; } ; static :: $ _detectors [ 'thirdParty' ] = function ( $ package ) { return static :: _getThirdParty ( $ package ) ; } ; static :: $ _initialized = true ; }
Initializes this class .
48,326
protected static function _getPlugin ( $ package ) { list ( , $ plugin ) = packageSplit ( $ package , true ) ; if ( Plugin :: exists ( $ plugin ) ) { return new PluginPackage ( quickapps ( "plugins.{$plugin}.name" ) , quickapps ( "plugins.{$plugin}.path" ) ) ; } return false ; }
Tries to get a QuickAppsCMS plugin .
48,327
protected static function _getThirdParty ( $ package ) { list ( $ vendor , $ packageName ) = packageSplit ( $ package ) ; $ packageJson = normalizePath ( VENDOR_INCLUDE_PATH . "/{$vendor}/{$packageName}/composer.json" ) ; if ( is_readable ( $ packageJson ) ) { $ installedJson = normalizePath ( VENDOR_INCLUDE_PATH . "composer/installed.json" ) ; if ( is_readable ( $ installedJson ) ) { $ json = ( array ) json_decode ( file_get_contents ( $ installedJson ) , true ) ; foreach ( $ json as $ pkg ) { if ( strtolower ( $ pkg [ 'name' ] ) === strtolower ( $ package ) ) { return new ThirdPartyPackage ( $ package , dirname ( $ packageJson ) , $ pkg [ 'version' ] ) ; } } } } return false ; }
Tries to get package that represents a third party library .
48,328
public static function run ( $ args , $ extra = [ ] ) { static :: $ _out = '' ; $ argv = explode ( ' ' , "dummy-shell.php {$args}" ) ; $ dispatcher = new WebShellDispatcher ( $ argv ) ; ob_start ( ) ; $ response = $ dispatcher -> dispatch ( $ extra ) ; static :: $ _out = ob_get_clean ( ) ; return ( int ) ( $ response === 0 ) ; }
Run the dispatcher .
48,329
protected function _createShell ( $ className , $ shortName ) { $ instance = parent :: _createShell ( $ className , $ shortName ) ; $ webIo = new ConsoleIo ( new WebConsoleOutput ( ) , new WebConsoleOutput ( ) , new WebConsoleInput ( ) ) ; $ instance -> io ( $ webIo ) ; return $ instance ; }
Create the given shell name and set the plugin property .
48,330
public function tables ( ) { $ db = ConnectionManager :: get ( 'default' ) ; $ db -> connect ( ) ; $ schemaCollection = $ db -> schemaCollection ( ) ; $ tables = $ schemaCollection -> listTables ( ) ; foreach ( $ tables as $ table ) { $ this -> out ( sprintf ( '- %s' , $ table ) ) ; } }
Displays a list of all table names in database .
48,331
public function connection ( ) { $ db = ConnectionManager :: get ( 'default' ) ; foreach ( $ db -> config ( ) as $ key => $ value ) { if ( is_array ( $ value ) ) { continue ; } $ this -> out ( sprintf ( '- %s: %s' , $ key , $ value ) ) ; } }
Display database connection information .
48,332
public function load ( $ options = [ ] ) { if ( Configure :: read ( 'debug' ) ) { return $ this -> _View -> Html -> script ( 'Jquery.jquery-1.11.2.js' , $ options ) ; } return $ this -> _View -> Html -> script ( 'Jquery.jquery-1.11.2.min.js' , $ options ) ; }
Loads jQuery s core library .
48,333
public function ui ( ) { $ args = func_get_args ( ) ; $ files = [ ] ; $ options = [ ] ; $ out = '' ; foreach ( $ args as $ file ) { if ( is_array ( $ file ) ) { $ options = $ file ; continue ; } $ file = 'Jquery.ui/' . strtolower ( $ file ) ; if ( ! str_ends_with ( $ file , '.js' ) ) { $ file .= '.js' ; } if ( $ file != 'Jquery.ui/core.js' ) { $ files [ ] = $ file ; } } if ( empty ( $ files ) ) { $ files [ ] = Configure :: read ( 'debug' ) ? 'Jquery.jquery-ui.js' : 'Jquery.jquery-ui.min.js' ; } else { array_unshift ( $ files , 'Jquery.ui/core.js' ) ; } foreach ( $ files as $ file ) { $ out .= ( string ) $ this -> _View -> Html -> script ( $ file , $ options ) ; } if ( empty ( $ out ) ) { return null ; } return $ out ; }
Loads the given jQuery UI components JS files .
48,334
public function theme ( $ themeName = null , array $ options = [ ] ) { if ( is_array ( $ themeName ) ) { $ options = $ themeName ; $ themeName = null ; } if ( $ themeName === null ) { $ default = Configure :: read ( 'jQueryUI.defaultTheme' ) ; $ themeName = $ default ? $ default : 'Jquery.ui-lightness' ; } $ out = '' ; list ( $ plugin , $ theme ) = pluginSplit ( $ themeName ) ; $ plugin = ! $ plugin ? 'Jquery' : $ plugin ; $ out .= ( string ) $ this -> _View -> Html -> css ( "{$plugin}.ui/{$theme}/theme.css" , $ options ) ; if ( Configure :: read ( 'debug' ) ) { $ out .= ( string ) $ this -> _View -> Html -> css ( "{$plugin}.ui/{$theme}/jquery-ui.css" , $ options ) ; } else { $ out .= ( string ) $ this -> _View -> Html -> css ( "{$plugin}.ui/{$theme}/jquery-ui.min.css" , $ options ) ; } if ( empty ( $ out ) ) { return ; } return $ out ; }
Loads all CSS and JS files for the given UI theme .
48,335
protected function _inspectExpression ( ExpressionInterface $ expression , $ bundle , Query $ query ) { if ( $ expression instanceof Comparison ) { $ expression = $ this -> _inspectComparisonExpression ( $ expression , $ bundle , $ query ) ; } elseif ( $ expression instanceof UnaryExpression ) { $ expression = $ this -> _inspectUnaryExpression ( $ expression , $ bundle , $ query ) ; } return $ expression ; }
Analyzes the given WHERE expression looks for virtual columns and alters the expressions according .
48,336
protected function _inspectComparisonExpression ( Comparison $ expression , $ bundle , Query $ query ) { $ field = $ expression -> getField ( ) ; $ column = is_string ( $ field ) ? $ this -> _toolbox -> columnName ( $ field ) : '' ; if ( empty ( $ column ) || in_array ( $ column , ( array ) $ this -> _table -> schema ( ) -> columns ( ) ) || ! in_array ( $ column , $ this -> _toolbox -> getAttributeNames ( ) ) || ! $ this -> _toolbox -> isSearchable ( $ column ) ) { return $ expression ; } $ attr = $ this -> _toolbox -> attributes ( $ bundle ) [ $ column ] ; $ value = $ expression -> getValue ( ) ; $ type = $ this -> _toolbox -> getType ( $ column ) ; $ conjunction = $ expression -> getOperator ( ) ; $ conditions = [ 'EavValues.eav_attribute_id' => $ attr [ 'id' ] , "EavValues.value_{$type} {$conjunction}" => $ value , ] ; $ subQuery = TableRegistry :: get ( 'Eav.EavValues' ) -> find ( ) -> select ( 'EavValues.entity_id' ) -> where ( $ conditions ) -> order ( [ 'EavValues.id' => 'DESC' ] ) ; $ pk = $ this -> _tablePrimaryKey ( ) ; $ driverClass = $ this -> _toolbox -> driver ( $ query ) ; switch ( $ driverClass ) { case 'sqlite' : $ concat = implode ( ' || ' , $ pk ) ; $ field = "({$concat} || '')" ; break ; case 'sqlserver' : $ pk = array_map ( function ( $ keyPart ) { return "CAST({$keyPart} AS VARCHAR)" ; } , $ pk ) ; $ concat = implode ( ' + ' , $ pk ) ; $ field = "({$concat} + '')" ; break ; case 'mysql' : case 'postgres' : default : $ concat = implode ( ', ' , $ pk ) ; $ field = "CONCAT({$concat}, '')" ; break ; } $ ids = $ subQuery -> all ( ) -> extract ( 'entity_id' ) -> toArray ( ) ; $ ids = empty ( $ ids ) ? [ '-1' ] : $ ids ; $ expression -> setField ( $ field ) ; $ expression -> setValue ( $ ids ) ; $ expression -> setOperator ( 'IN' ) ; $ class = new \ ReflectionClass ( $ expression ) ; $ property = $ class -> getProperty ( '_type' ) ; $ property -> setAccessible ( true ) ; $ property -> setValue ( $ expression , 'string' ) ; $ property = $ class -> getProperty ( '_isMultiple' ) ; $ property -> setAccessible ( true ) ; $ property -> setValue ( $ expression , true ) ; return $ expression ; }
Analyzes the given comparison expression and alters it according .
48,337
protected function _inspectUnaryExpression ( UnaryExpression $ expression , $ bundle , Query $ query ) { $ class = new \ ReflectionClass ( $ expression ) ; $ property = $ class -> getProperty ( '_value' ) ; $ property -> setAccessible ( true ) ; $ value = $ property -> getValue ( $ expression ) ; if ( $ value instanceof IdentifierExpression ) { $ field = $ value -> getIdentifier ( ) ; $ column = is_string ( $ field ) ? $ this -> _toolbox -> columnName ( $ field ) : '' ; if ( empty ( $ column ) || in_array ( $ column , ( array ) $ this -> _table -> schema ( ) -> columns ( ) ) || ! in_array ( $ column , $ this -> _toolbox -> getAttributeNames ( $ bundle ) ) || ! $ this -> _toolbox -> isSearchable ( $ column ) ) { return $ expression ; } $ pk = $ this -> _tablePrimaryKey ( ) ; $ driverClass = $ this -> _toolbox -> driver ( $ query ) ; switch ( $ driverClass ) { case 'sqlite' : $ concat = implode ( ' || ' , $ pk ) ; $ field = "({$concat} || '')" ; break ; case 'mysql' : case 'postgres' : case 'sqlserver' : default : $ concat = implode ( ', ' , $ pk ) ; $ field = "CONCAT({$concat}, '')" ; break ; } $ attr = $ this -> _toolbox -> attributes ( $ bundle ) [ $ column ] ; $ type = $ this -> _toolbox -> getType ( $ column ) ; $ subQuery = TableRegistry :: get ( 'Eav.EavValues' ) -> find ( ) -> select ( "EavValues.value_{$type}" ) -> where ( [ 'EavValues.entity_id' => $ field , 'EavValues.eav_attribute_id' => $ attr [ 'id' ] ] ) -> order ( [ 'EavValues.id' => 'DESC' ] ) -> limit ( 1 ) -> sql ( ) ; $ subQuery = str_replace ( [ ':c0' , ':c1' ] , [ $ field , $ attr [ 'id' ] ] , $ subQuery ) ; $ property -> setValue ( $ expression , "({$subQuery})" ) ; } return $ expression ; }
Analyzes the given unary expression and alters it according .
48,338
protected function _tablePrimaryKey ( ) { $ alias = $ this -> _table -> alias ( ) ; $ pk = $ this -> _table -> primaryKey ( ) ; if ( ! is_array ( $ pk ) ) { $ pk = [ $ pk ] ; } $ pk = array_map ( function ( $ key ) use ( $ alias ) { return "{$alias}.{$key}" ; } , $ pk ) ; return $ pk ; }
Gets table s PK as an array .
48,339
public function region ( $ name , $ options = [ ] , $ force = false ) { if ( empty ( $ this -> _regions [ $ name ] ) || $ force ) { $ this -> _regions [ $ name ] = new Region ( $ this , $ name , $ options ) ; } return $ this -> _regions [ $ name ] ; }
Defines a new theme region to be rendered .
48,340
protected function _setTitle ( ) { if ( empty ( $ this -> viewVars [ 'title_for_layout' ] ) ) { $ title = option ( 'site_title' ) ; $ this -> assign ( 'title' , $ title ) ; $ this -> set ( 'title_for_layout' , $ title ) ; } else { $ this -> assign ( 'title' , $ this -> viewVars [ 'title_for_layout' ] ) ; } }
Sets title for layout .
48,341
protected function _setDescription ( ) { if ( empty ( $ this -> viewVars [ 'description_for_layout' ] ) ) { $ description = option ( 'site_description' ) ; $ this -> assign ( 'description' , $ description ) ; $ this -> set ( 'description_for_layout' , $ description ) ; $ this -> append ( 'meta' , $ this -> Html -> meta ( 'description' , $ description ) ) ; } else { $ this -> assign ( 'description' , $ this -> viewVars [ 'description_for_layout' ] ) ; } }
Sets meta - description for layout .
48,342
public function beforeFilter ( Event $ event ) { $ this -> _controller -> set ( '__commentComponentLoaded__' , true ) ; $ this -> _controller -> set ( '_commentFormContext' , $ this -> config ( 'arrayContext' ) ) ; }
Called before the controller s beforeFilter method .
48,343
public function post ( EntityInterface $ entity ) { $ pk = ( string ) TableRegistry :: get ( $ entity -> source ( ) ) -> primaryKey ( ) ; if ( empty ( $ this -> _controller -> request -> data [ 'comment' ] ) || $ this -> config ( 'settings.visibility' ) !== 1 || ! $ entity -> has ( $ pk ) ) { return false ; } $ this -> _controller -> loadModel ( 'Comment.Comments' ) ; $ data = $ this -> _getRequestData ( $ entity ) ; $ this -> _controller -> Comments -> validator ( 'commentValidation' , $ this -> _createValidator ( ) ) ; $ comment = $ this -> _controller -> Comments -> newEntity ( $ data , [ 'validate' => 'commentValidation' ] ) ; $ errors = $ comment -> errors ( ) ; $ errors = ! empty ( $ errors ) ; if ( ! $ errors ) { $ persist = true ; $ saved = true ; $ this -> _controller -> Comments -> addBehavior ( 'Tree' , [ 'scope' => [ 'entity_id' => $ data [ 'entity_id' ] , 'table_alias' => $ data [ 'table_alias' ] , ] ] ) ; if ( $ this -> config ( 'settings.use_akismet' ) ) { $ newStatus = $ this -> _akismetStatus ( $ data ) ; $ comment -> set ( 'status' , $ newStatus ) ; if ( $ newStatus == 'spam' && $ this -> config ( 'settings.akismet_action' ) != 'mark' ) { $ persist = false ; } } if ( $ persist ) { $ saved = $ this -> _controller -> Comments -> save ( $ comment ) ; } if ( $ saved ) { $ this -> _afterSave ( $ comment ) ; return true ; } else { $ errors = true ; } } if ( $ errors ) { $ this -> _setErrors ( $ comment ) ; $ errorMessage = $ this -> config ( 'errorMessage' ) ; if ( is_callable ( $ errorMessage ) ) { $ errorMessage = $ errorMessage ( $ comment , $ this -> _controller ) ; } $ this -> _controller -> Flash -> danger ( $ errorMessage , [ 'key' => 'commentsForm' ] ) ; } return false ; }
Adds a new comment for the given entity .
48,344
protected function _akismetStatus ( $ data ) { require_once Plugin :: classPath ( 'Comment' ) . 'Lib/Akismet.php' ; try { $ akismet = new \ Akismet ( Router :: url ( '/' ) , $ this -> config ( 'settings.akismet_key' ) ) ; if ( ! empty ( $ data [ 'author_name' ] ) ) { $ akismet -> setCommentAuthor ( $ data [ 'author_name' ] ) ; } if ( ! empty ( $ data [ 'author_email' ] ) ) { $ akismet -> setCommentAuthorEmail ( $ data [ 'author_email' ] ) ; } if ( ! empty ( $ data [ 'author_web' ] ) ) { $ akismet -> setCommentAuthorURL ( $ data [ 'author_web' ] ) ; } if ( ! empty ( $ data [ 'body' ] ) ) { $ akismet -> setCommentContent ( $ data [ 'body' ] ) ; } if ( $ akismet -> isCommentSpam ( ) ) { return 'spam' ; } } catch ( \ Exception $ ex ) { return 'pending' ; } return $ data [ 'status' ] ; }
Calculates comment s status using akismet .
48,345
protected function _afterSave ( EntityInterface $ comment ) { $ successMessage = $ this -> config ( 'successMessage' ) ; if ( is_callable ( $ successMessage ) ) { $ successMessage = $ successMessage ( $ comment , $ this -> _controller ) ; } $ this -> _controller -> Flash -> success ( $ successMessage , [ 'key' => 'commentsForm' ] ) ; if ( $ this -> config ( 'redirectOnSuccess' ) ) { $ redirectTo = $ this -> config ( 'redirectOnSuccess' ) === true ? $ this -> _controller -> referer ( ) : $ this -> config ( 'redirectOnSuccess' ) ; $ this -> _controller -> redirect ( $ redirectTo ) ; } }
Logic triggered after comment was successfully saved .
48,346
protected function _getRequestData ( EntityInterface $ entity ) { $ pk = ( string ) TableRegistry :: get ( $ entity -> source ( ) ) -> primaryKey ( ) ; $ data = $ this -> _controller -> request -> data ( 'comment' ) ; $ return = [ 'parent_id' => null , 'subject' => '' , 'body' => '' , 'status' => 'pending' , 'author_name' => null , 'author_email' => null , 'author_web' => null , 'author_ip' => $ this -> _controller -> request -> clientIp ( ) , 'table_alias' => $ this -> _getTableAlias ( $ entity ) , 'entity_id' => $ entity -> get ( $ pk ) , ] ; if ( ! empty ( $ this -> _controller -> request -> data [ 'comment' ] ) ) { $ data = $ this -> _controller -> request -> data [ 'comment' ] ; } if ( $ this -> _controller -> request -> is ( 'userLoggedIn' ) ) { $ return [ 'user_id' ] = user ( ) -> id ; $ return [ 'author_name' ] = null ; $ return [ 'author_email' ] = null ; $ return [ 'author_web' ] = null ; } else { $ return [ 'author_name' ] = ! empty ( $ data [ 'author_name' ] ) ? h ( $ data [ 'author_name' ] ) : null ; $ return [ 'author_email' ] = ! empty ( $ data [ 'author_email' ] ) ? h ( $ data [ 'author_email' ] ) : null ; $ return [ 'author_web' ] = ! empty ( $ data [ 'author_web' ] ) ? h ( $ data [ 'author_web' ] ) : null ; } if ( ! empty ( $ data [ 'subject' ] ) ) { $ return [ 'subject' ] = h ( $ data [ 'subject' ] ) ; } if ( ! empty ( $ data [ 'parent_id' ] ) ) { $ return [ 'parent_id' ] = $ data [ 'parent_id' ] ; } if ( ! empty ( $ data [ 'body' ] ) ) { $ return [ 'body' ] = TextToolbox :: process ( $ data [ 'body' ] , $ this -> config ( 'settings.text_processing' ) ) ; } if ( $ this -> config ( 'settings.auto_approve' ) || $ this -> _controller -> request -> is ( 'userAdmin' ) ) { $ return [ 'status' ] = 'approved' ; } return $ return ; }
Extract data from request and prepares for inserting a new comment for the given entity .
48,347
protected function _getTableAlias ( EntityInterface $ entity ) { $ alias = $ entity -> source ( ) ; if ( mb_strpos ( $ alias , '.' ) !== false ) { $ parts = explode ( '.' , $ alias ) ; $ alias = array_pop ( $ parts ) ; } return strtolower ( $ alias ) ; }
Get table alias for the given entity .
48,348
protected function _setErrors ( Comment $ comment ) { $ arrayContext = $ this -> config ( 'arrayContext' ) ; foreach ( ( array ) $ comment -> errors ( ) as $ field => $ msg ) { $ arrayContext [ 'errors' ] [ 'comment' ] [ $ field ] = $ msg ; } $ this -> config ( 'arrayContext' , $ arrayContext ) ; $ this -> _controller -> set ( '_commentFormContext' , $ this -> config ( 'arrayContext' ) ) ; }
Prepares error messages for FormHelper .
48,349
protected function _loadSettings ( ) { $ settings = plugin ( 'Comment' ) -> settings ( ) ; foreach ( $ settings as $ k => $ v ) { $ this -> config ( "settings.{$k}" , $ v ) ; } }
Fetch settings from data base and merges with this component s configuration .
48,350
protected function _createValidator ( ) { $ config = $ this -> config ( ) ; if ( $ config [ 'validator' ] instanceof Validator ) { return $ config [ 'validator' ] ; } $ this -> _controller -> loadModel ( 'Comment.Comments' ) ; if ( $ this -> _controller -> request -> is ( 'userLoggedIn' ) ) { $ validator = $ this -> _controller -> Comments -> validationDefault ( new Validator ( ) ) ; $ validator -> requirePresence ( 'user_id' ) -> notEmpty ( 'user_id' , __d ( 'comment' , 'Invalid user.' ) ) -> add ( 'user_id' , 'checkUserId' , [ 'rule' => function ( $ value , $ context ) { if ( ! empty ( $ value ) ) { $ valid = TableRegistry :: get ( 'User.Users' ) -> find ( ) -> where ( [ 'Users.id' => $ value , 'Users.status' => 1 ] ) -> count ( ) === 1 ; return $ valid ; } return false ; } , 'message' => __d ( 'comment' , 'Invalid user, please try again.' ) , 'provider' => 'table' , ] ) ; } elseif ( $ this -> config ( 'settings.allow_anonymous' ) ) { $ validator = $ this -> _controller -> Comments -> validator ( 'anonymous' ) ; } else { $ validator = new Validator ( ) ; } if ( $ this -> config ( 'settings.use_captcha' ) ) { $ validator -> add ( 'body' , 'humanCheck' , [ 'rule' => function ( $ value , $ context ) { return CaptchaManager :: adapter ( ) -> validate ( $ this -> _controller -> request ) ; } , 'message' => __d ( 'comment' , 'We were not able to verify you as human. Please try again.' ) , 'provider' => 'table' , ] ) ; } return $ validator ; }
Creates a validation object on the fly .
48,351
protected function _getViewModeSettings ( ) { $ viewMode = $ this -> viewMode ( ) ; $ settings = [ ] ; if ( ! empty ( $ this -> metadata -> view_modes [ $ viewMode ] ) ) { $ settings = $ this -> metadata -> view_modes [ $ viewMode ] ; } return $ settings ; }
Gets field s View Mode s settings for the in - use View Mode .
48,352
protected function _install ( ) { $ message = __d ( 'installer' , "Please provide a theme source, it can be either an URL or a filesystem path to a ZIP/directory within your server?\n[Q]uit" ) ; while ( true ) { $ source = $ this -> in ( $ message ) ; if ( strtoupper ( $ source ) === 'Q' ) { $ this -> err ( __d ( 'installer' , 'Installation aborted' ) ) ; break ; } else { $ this -> out ( __d ( 'installer' , 'Starting installation...' ) , 0 ) ; $ task = $ this -> dispatchShell ( "Installer.plugins install -s \"{$source}\" --theme -a" ) ; if ( $ task === 0 ) { $ this -> _io -> overwrite ( __d ( 'installer' , 'Starting installation... successfully installed!' ) , 2 ) ; $ this -> out ( ) ; break ; } else { $ this -> _io -> overwrite ( __d ( 'installer' , 'Starting installation... failed!' ) , 2 ) ; $ this -> out ( ) ; } } } $ this -> out ( ) ; }
Installs a new theme .
48,353
protected function _uninstall ( ) { $ allThemes = plugin ( ) -> filter ( function ( $ plugin ) { return $ plugin -> isTheme ; } ) -> toArray ( ) ; $ index = 1 ; $ this -> out ( ) ; foreach ( $ allThemes as $ plugin ) { $ allThemes [ $ index ] = $ plugin ; $ this -> out ( __d ( 'installer' , '[{0, number}] {1}' , [ $ index , $ plugin -> humanName ] ) ) ; $ index ++ ; } $ this -> out ( ) ; $ message = __d ( 'installer' , "Which theme would you like to uninstall?\n[Q]uit" ) ; while ( true ) { $ in = trim ( $ this -> in ( $ message ) ) ; if ( strtoupper ( $ in ) === 'Q' ) { $ this -> err ( __d ( 'installer' , 'Operation aborted' ) ) ; break ; } elseif ( intval ( $ in ) < 1 || ! isset ( $ allThemes [ intval ( $ in ) ] ) ) { $ this -> err ( __d ( 'installer' , 'Invalid option' ) ) ; } else { $ plugin = plugin ( $ allThemes [ $ in ] -> name ( ) ) ; $ this -> hr ( ) ; $ this -> out ( __d ( 'installer' , '<info>The following theme will be uninstalled</info>' ) ) ; $ this -> hr ( ) ; $ this -> out ( __d ( 'installer' , 'Name: {0}' , $ plugin -> name ) ) ; $ this -> out ( __d ( 'installer' , 'Description: {0}' , $ plugin -> composer [ 'description' ] ) ) ; $ this -> out ( __d ( 'installer' , 'Path: {0}' , $ plugin -> path ) ) ; $ this -> hr ( ) ; $ this -> out ( ) ; $ confirm = $ this -> in ( __d ( 'installer' , 'Please type in "{0}" to uninstall' , $ allThemes [ $ in ] -> name ) ) ; if ( $ confirm === $ allThemes [ $ in ] -> name ) { $ task = $ this -> dispatchShell ( "Installer.plugins uninstall -p {$allThemes[$in]->name}" ) ; if ( $ task === 0 ) { $ this -> out ( __d ( 'installer' , 'Plugin uninstalled!' ) ) ; Plugin :: dropCache ( ) ; } else { $ this -> err ( __d ( 'installer' , 'Plugin could not be uninstalled.' ) , 2 ) ; $ this -> out ( ) ; } } else { $ this -> err ( __d ( 'installer' , 'Confirmation failure, operation aborted!' ) ) ; } break ; } } $ this -> out ( ) ; }
Removes an existing theme .
48,354
protected function _scopeOperator ( Query $ query , TokenInterface $ token ) { return $ this -> _table -> applySearchOperator ( $ query , $ token ) ; }
Scopes the given query using the given operator token .
48,355
protected function _scopeWords ( Query $ query , TokenInterface $ token ) { if ( $ this -> _isFullTextEnabled ( ) ) { return $ this -> _scopeWordsInFulltext ( $ query , $ token ) ; } $ like = 'LIKE' ; if ( $ token -> negated ( ) ) { $ like = 'NOT LIKE' ; } $ value = str_replace ( [ '*' , '!' ] , [ '%' , '_' ] , $ token -> value ( ) ) ; if ( $ token -> where ( ) === 'or' ) { $ query -> orWhere ( [ "SearchDatasets.words {$like}" => "%{$value}%" ] ) ; } elseif ( $ token -> where ( ) === 'and' ) { $ query -> andWhere ( [ "SearchDatasets.words {$like}" => "%{$value}%" ] ) ; } else { $ query -> where ( [ "SearchDatasets.words {$like}" => "%{$value}%" ] ) ; } return $ query ; }
Scopes the given query using the given words token .
48,356
protected function _scopeWordsInFulltext ( Query $ query , TokenInterface $ token ) { $ value = str_replace ( [ '*' , '!' ] , [ '*' , '*' ] , $ token -> value ( ) ) ; $ value = mb_strpos ( $ value , '+' ) === 0 ? mb_substr ( $ value , 1 ) : $ value ; if ( empty ( $ value ) || in_array ( $ value , $ this -> _stopWords ( ) ) ) { return $ query ; } $ not = $ token -> negated ( ) ? 'NOT' : '' ; $ value = str_replace ( [ "'" , '@' ] , [ '"' , ' ' ] , $ value ) ; $ conditions = [ "{$not} MATCH(SearchDatasets.words) AGAINST('{$value}' IN BOOLEAN MODE) > 0" ] ; if ( $ token -> where ( ) === 'or' ) { $ query -> orWhere ( $ conditions ) ; } elseif ( $ token -> where ( ) === 'and' ) { $ query -> andWhere ( $ conditions ) ; } else { $ query -> where ( $ conditions ) ; } return $ query ; }
Similar to _scopeWords but using MySQL s fulltext indexes .
48,357
protected function _isFullTextEnabled ( ) { if ( ! $ this -> config ( 'fulltext' ) ) { return false ; } static $ enabled = null ; if ( $ enabled !== null ) { return $ enabled ; } list ( , $ driverClass ) = namespaceSplit ( strtolower ( get_class ( $ this -> _table -> connection ( ) -> driver ( ) ) ) ) ; if ( $ driverClass != 'mysql' ) { $ enabled = false ; return false ; } $ schema = $ this -> _table -> SearchDatasets -> schema ( ) ; foreach ( $ schema -> indexes ( ) as $ index ) { $ info = $ schema -> index ( $ index ) ; if ( in_array ( 'words' , $ info [ 'columns' ] ) && strtolower ( $ info [ 'type' ] ) == 'fulltext' ) { $ enabled = true ; return true ; } } $ enabled = false ; return false ; }
Whether FullText index is available or not and should be used .
48,358
protected function _stopWords ( ) { $ conn = $ this -> _table -> find ( ) -> connection ( ) ; $ cacheKey = $ conn -> configName ( ) . '_generic_engine_stopwords_list' ; if ( $ cache = Cache :: read ( $ cacheKey , '_cake_model_' ) ) { return ( array ) $ cache ; } $ words = [ ] ; $ sql = $ conn -> execute ( 'SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_DEFAULT_STOPWORD' ) -> fetchAll ( 'assoc' ) ; foreach ( ( array ) $ sql as $ row ) { if ( ! empty ( $ row [ 'value' ] ) ) { $ words [ ] = $ row [ 'value' ] ; } } Cache :: write ( $ cacheKey , $ words , '_cake_model_' ) ; return $ words ; }
Gets a list of storage engine s stopwords . That is words that is considered common or Trivial enough that it is omitted from the search index and ignored in search queries
48,359
public function extractEntityWords ( EntityInterface $ entity ) { $ text = '' ; $ entityArray = $ entity -> toArray ( ) ; $ entityArray = Hash :: flatten ( $ entityArray ) ; foreach ( $ entityArray as $ key => $ value ) { if ( is_string ( $ value ) || is_numeric ( $ value ) ) { $ text .= " {$value}" ; } } $ text = str_replace ( [ "\n" , "\r" ] , '' , trim ( ( string ) $ text ) ) ; $ text = strip_tags ( $ text ) ; $ strict = $ this -> config ( 'strict' ) ; if ( ! empty ( $ strict ) ) { $ pattern = is_string ( $ strict ) ? $ strict : '[^\p{L}\p{N}\s\@\.\,\-\_\/\\0-9]' ; $ text = preg_replace ( '/' . $ pattern . '/ui' , ' ' , $ text ) ; } $ text = trim ( preg_replace ( '/\s{2,}/i' , ' ' , $ text ) ) ; $ text = mb_strtolower ( $ text ) ; $ text = $ this -> _filterText ( $ text ) ; $ text = iconv ( 'UTF-8' , 'UTF-8//IGNORE' , mb_convert_encoding ( $ text , 'UTF-8' ) ) ; return trim ( $ text ) ; }
Extracts a list of words to by indexed for given entity .
48,360
protected function _filterText ( $ text ) { if ( is_callable ( $ this -> config ( 'bannedWords' ) ) ) { $ isBanned = function ( $ word ) { $ callable = $ this -> config ( 'bannedWords' ) ; return $ callable ( $ word ) ; } ; } else { $ isBanned = function ( $ word ) { return in_array ( $ word , ( array ) $ this -> config ( 'bannedWords' ) ) || empty ( $ word ) ; } ; } $ words = explode ( ' ' , $ text ) ; foreach ( $ words as $ i => $ w ) { if ( $ isBanned ( $ w ) ) { unset ( $ words [ $ i ] ) ; } } return implode ( ' ' , $ words ) ; }
Removes any invalid word from the given text .
48,361
public static function formatField ( Field $ field ) { $ timestamp = $ field -> value ? $ field -> value -> getTimestamp ( ) : 0 ; return DateToolbox :: formatDate ( $ field -> view_mode_settings [ 'format' ] , $ timestamp ) ; }
Formats the given DateField accordingly to current view - mode .
48,362
public static function formatDate ( $ format , $ timestamp ) { static $ datesPatterns = null ; static $ timesPatterns = null ; if ( $ datesPatterns === null || $ timesPatterns === null ) { $ datesPatterns = "/\b(" . implode ( '|' , array_keys ( static :: $ _map [ 'date' ] ) ) . ")\b(?![^']*'(?:(?:[^']*'){2})*[^']*$)/i" ; $ timesPatterns = "/\b(" . implode ( '|' , array_keys ( static :: $ _map [ 'time' ] ) ) . ")\b(?![^']*'(?:(?:[^']*'){2})*[^']*$)/i" ; } $ result = preg_replace_callback ( $ datesPatterns , function ( $ matches ) use ( $ timestamp ) { return date ( static :: $ _map [ 'date' ] [ $ matches [ 1 ] ] , $ timestamp ) ; } , trim ( $ format ) ) ; $ result = preg_replace_callback ( $ timesPatterns , function ( $ matches ) use ( $ timestamp ) { return date ( static :: $ _map [ 'time' ] [ $ matches [ 1 ] ] , $ timestamp ) ; } , $ result ) ; return str_replace ( '\'' , '' , $ result ) ; }
Formats then given UNIX timestamp using the given jQuery format .
48,363
public static function validateDateFormat ( $ format ) { $ format = str_replace ( array_keys ( static :: $ _map [ 'date' ] ) , '' , $ format ) ; $ format = preg_replace ( "/'(.*)'/" , '' , $ format ) ; $ format = preg_replace ( '/[^a-z]/i' , '' , $ format ) ; $ format = trim ( $ format ) ; return empty ( $ format ) ; }
Validates a date format for jQuery s datepicker widget .
48,364
public static function validateTimeFormat ( $ format ) { $ format = str_replace ( array_keys ( static :: $ _map [ 'time' ] ) , '' , $ format ) ; $ format = preg_replace ( "/'(.*)'/" , '' , $ format ) ; $ format = preg_replace ( '/[^a-z]/i' , '' , $ format ) ; $ format = trim ( $ format ) ; return empty ( $ format ) ; }
Validates a time format for jQuery s datepicker widget .
48,365
public static function getPHPFormat ( EntityInterface $ field ) { $ settings = $ field -> metadata -> settings ; $ format = empty ( $ settings [ 'format' ] ) ? 'yy-mm-dd' : $ settings [ 'format' ] ; if ( $ settings [ 'timepicker' ] ) { $ format .= ' ' ; if ( empty ( $ settings [ 'time_format' ] ) ) { $ format .= 'H:mm' ; $ format .= empty ( $ settings [ 'time_seconds' ] ) ? : ':ss' ; } else { $ format .= $ settings [ 'time_format' ] ; } } return static :: normalizeFormat ( $ format ) ; }
Given a DateField instance gets its PHP s date - format .
48,366
protected function _removeOptions ( ) { $ options = [ ] ; if ( ! empty ( $ this -> _plugin -> composer [ 'extra' ] [ 'options' ] ) ) { $ this -> loadModel ( 'System.Options' ) ; $ options = $ this -> _plugin -> composer [ 'extra' ] [ 'options' ] ; } foreach ( $ options as $ option ) { if ( ! empty ( $ option [ 'name' ] ) ) { $ this -> Options -> deleteAll ( [ 'name' => $ option [ 'name' ] ] ) ; } } }
Removes from options table any entry registered by the plugin .
48,367
protected function _clearAcoPaths ( ) { $ this -> loadModel ( 'User.Acos' ) ; $ nodes = $ this -> Acos -> find ( ) -> where ( [ 'plugin' => $ this -> params [ 'plugin' ] ] ) -> order ( [ 'lft' => 'ASC' ] ) -> all ( ) ; foreach ( $ nodes as $ node ) { $ this -> Acos -> removeFromTree ( $ node ) ; $ this -> Acos -> delete ( $ node ) ; } AcoManager :: buildAcos ( null , true ) ; }
Removes all ACOs created by the plugin being uninstall .
48,368
public function validationDefault ( Validator $ validator ) { $ validator -> add ( 'subject' , [ 'notBlank' => [ 'rule' => 'notBlank' , 'message' => __d ( 'comment' , 'You need to provide a comment subject.' ) , ] , 'length' => [ 'rule' => [ 'minLength' , 5 ] , 'message' => 'Comment subject need to be at least 5 characters long' , ] ] ) -> add ( 'body' , [ 'notBlank' => [ 'rule' => 'notBlank' , 'message' => __d ( 'comment' , 'Your comment message cannot be empty' ) ] , 'length' => [ 'rule' => [ 'minLength' , 5 ] , 'message' => 'Comment message need to be at least 5 characters long' , ] ] ) -> allowEmpty ( 'user_id' ) -> allowEmpty ( 'parent_id' ) -> add ( 'parent_id' , 'checkParentId' , [ 'rule' => function ( $ value , $ context ) { if ( ! empty ( $ value ) ) { $ conditions = [ 'id' => $ value , 'entity_id' => $ context [ 'data' ] [ 'entity_id' ] , 'table_alias' => $ context [ 'data' ] [ 'table_alias' ] , ] ; return TableRegistry :: get ( 'Comment.Comments' ) -> find ( ) -> where ( $ conditions ) -> count ( ) > 0 ; } else { $ context [ 'data' ] [ 'parent_id' ] = null ; } return true ; } , 'message' => __d ( 'comment' , 'Invalid parent comment!.' ) , 'provider' => 'table' , ] ) ; return $ validator ; }
Basic validation set of rules .
48,369
public function validationAnonymous ( Validator $ validator ) { $ settings = Plugin :: get ( 'Comment' ) -> settings ; $ validator = $ this -> validationDefault ( $ validator ) ; if ( $ settings [ 'allow_anonymous' ] ) { if ( $ settings [ 'anonymous_name' ] ) { $ validator -> requirePresence ( 'author_name' ) -> add ( 'author_name' , 'nameLength' , [ 'rule' => [ 'minLength' , 3 ] , 'message' => __d ( 'comment' , 'Your name need to be at least 3 characters long.' ) , ] ) ; if ( $ settings [ 'anonymous_name_required' ] ) { $ validator -> notEmpty ( 'author_name' , __d ( 'comment' , 'You must provide your name.' ) ) ; } else { $ validator -> allowEmpty ( 'author_name' ) ; } } if ( $ settings [ 'anonymous_email' ] ) { $ validator -> requirePresence ( 'author_email' ) -> add ( 'author_email' , 'validEmail' , [ 'rule' => 'email' , 'message' => __d ( 'comment' , 'e-Mail must be valid.' ) , ] ) ; if ( $ settings [ 'anonymous_email_required' ] ) { $ validator -> notEmpty ( 'author_email' , __d ( 'comment' , 'You must provide an email.' ) ) ; } else { $ validator -> allowEmpty ( 'anonymous_email' ) ; } } if ( $ settings [ 'anonymous_web' ] ) { $ validator -> requirePresence ( 'author_web' ) -> add ( 'author_web' , 'validURL' , [ 'rule' => 'url' , 'message' => __d ( 'comment' , 'Website must be a valid URL.' ) , ] ) ; if ( $ settings [ 'anonymous_web_required' ] ) { $ validator -> notEmpty ( 'author_web' , __d ( 'comment' , 'You must provide a website URL.' ) ) ; } else { $ validator -> allowEmpty ( 'author_web' ) ; } } } return $ validator ; }
Validation rules when editing a comment in backend .
48,370
public function name ( $ name = null ) { if ( $ name !== null ) { $ this -> config ( 'name' , $ name ) ; } return $ this -> config ( 'name' ) ; }
Gets or set Adapter s name .
48,371
protected function _tokenLogin ( Request $ request ) { if ( ! empty ( $ request -> query [ 'token' ] ) ) { $ token = $ request -> query [ 'token' ] ; $ Users = TableRegistry :: get ( 'User.Users' ) ; $ exists = $ Users -> find ( ) -> select ( [ 'id' , 'username' ] ) -> where ( [ 'token' => $ token , 'token_expiration <=' => time ( ) ] ) -> limit ( 1 ) -> first ( ) ; if ( $ exists ) { $ user = $ this -> _findUser ( $ exists -> username ) ; if ( is_array ( $ user ) ) { $ controller = $ this -> _registry -> getController ( ) ; if ( isset ( $ user [ 'password' ] ) ) { unset ( $ user [ 'password' ] ) ; } $ controller -> Auth -> setUser ( $ user ) ; $ exists -> updateToken ( ) ; return true ; } } } return false ; }
Tries to login user using token .
48,372
protected function _rolePermissions ( $ roleId ) { $ Acos = TableRegistry :: get ( 'User.Acos' ) ; $ Permissions = TableRegistry :: get ( 'User.Permissions' ) ; $ out = [ ] ; $ acoIds = $ Permissions -> find ( ) -> select ( [ 'aco_id' ] ) -> where ( [ 'role_id' => $ roleId ] ) -> all ( ) -> extract ( 'aco_id' ) -> toArray ( ) ; foreach ( $ acoIds as $ acoId ) { $ path = $ Acos -> find ( 'path' , [ 'for' => $ acoId ] ) ; if ( ! $ path ) { continue ; } $ path = implode ( '/' , $ path -> extract ( 'alias' ) -> toArray ( ) ) ; if ( $ path ) { $ out [ $ path ] = true ; } } return $ out ; }
Gets all permissions available for the given role .
48,373
protected function init ( ) { if ( DIRECTORY_SEPARATOR !== '/' ) { foreach ( array ( 'path' , 'tmbPath' , 'quarantine' ) as $ key ) { if ( $ this -> options [ $ key ] ) { $ this -> options [ $ key ] = str_replace ( '/' , DIRECTORY_SEPARATOR , $ this -> options [ $ key ] ) ; } } } return true ; }
Prepare driver before mount volume . Return true if volume is ready .
48,374
protected function readlink ( $ path ) { if ( ! ( $ target = @ readlink ( $ path ) ) ) { return false ; } if ( substr ( $ target , 0 , 1 ) != DIRECTORY_SEPARATOR ) { $ target = dirname ( $ path ) . DIRECTORY_SEPARATOR . $ target ; } if ( $ this -> _inpath ( $ target , $ this -> aroot ) ) { $ atarget = realpath ( $ target ) ; return $ this -> _normpath ( $ this -> root . DIRECTORY_SEPARATOR . substr ( $ atarget , strlen ( $ this -> aroot ) + 1 ) ) ; } return false ; }
Return symlink target file
48,375
public function settingsValidate ( Event $ event , array $ data , ArrayObject $ options ) { if ( ! empty ( $ options [ 'entity' ] ) && $ options [ 'entity' ] -> has ( 'name' ) ) { $ validator = new Validator ( ) ; $ this -> trigger ( "Plugin.{$options['entity']->name}.settingsValidate" , $ data , $ validator ) ; $ errors = $ validator -> errors ( $ data , $ options [ 'entity' ] -> isNew ( ) ) ; if ( ! empty ( $ errors ) ) { foreach ( $ errors as $ k => $ v ) { $ options [ 'entity' ] -> errors ( "settings:{$k}" , $ v ) ; } } } }
Validates plugin settings before persisted in DB .
48,376
public function settingsDefaultValues ( Event $ event , Entity $ plugin ) { if ( $ plugin -> has ( 'name' ) ) { return ( array ) $ this -> trigger ( "Plugin.{$plugin->name}.settingsDefaults" , $ plugin ) -> result ; } return [ ] ; }
Here we set default values for plugin s settings .
48,377
public function beforeSave ( Event $ event , Entity $ plugin , ArrayObject $ options = null ) { if ( $ plugin -> isNew ( ) ) { $ max = $ this -> find ( ) -> order ( [ 'ordering' => 'DESC' ] ) -> limit ( 1 ) -> first ( ) ; $ plugin -> set ( 'ordering' , $ max -> ordering + 1 ) ; } }
Set plugin s load ordering to LAST if it s a new plugin being installed .
48,378
public function afterSave ( Event $ event , Entity $ plugin , ArrayObject $ options = null ) { snapshot ( ) ; $ this -> clearCache ( ) ; }
This method automatically regenerates system s snapshot .
48,379
public function offsetGet ( $ index ) { if ( is_string ( $ index ) && isset ( $ this -> _keysMap [ $ index ] ) ) { $ index = $ this -> _keysMap [ $ index ] ; } return parent :: offsetGet ( $ index ) ; }
Allows access fields by numeric index or by machine - name .
48,380
public function sortByViewMode ( $ viewMode , $ dir = SORT_ASC ) { $ items = [ ] ; $ sorted = $ this -> sortBy ( function ( $ field ) use ( $ viewMode ) { if ( isset ( $ field -> metadata -> view_modes [ $ viewMode ] ) ) { return $ field -> metadata -> view_modes [ $ viewMode ] [ 'ordering' ] ; } return 0 ; } , $ dir ) ; foreach ( $ sorted as $ item ) { $ items [ ] = $ item ; } return new FieldCollection ( $ items ) ; }
Sorts the list of fields by view mode ordering .
48,381
public function beforeFind ( Event $ event , Query $ query , ArrayObject $ options , $ primary ) { $ query -> formatResults ( function ( $ results ) { return $ results -> map ( function ( $ revision ) { try { if ( isset ( $ revision -> data -> content_type_id ) ) { $ contentType = TableRegistry :: get ( 'Content.ContentTypes' ) -> find ( ) -> where ( [ 'id' => $ revision -> data -> content_type_id ] ) -> first ( ) ; $ revision -> data -> set ( 'content_type' , $ contentType ) ; } } catch ( \ Exception $ e ) { $ revision -> data -> set ( 'content_type' , false ) ; } return $ revision ; } ) ; } ) ; return $ query ; }
Attaches ContentType information to each content revision .
48,382
public static function escape ( $ text ) { $ tagregexp = implode ( '|' , array_map ( 'preg_quote' , static :: _list ( ) ) ) ; preg_match_all ( '/(.?){(' . $ tagregexp . ')\b(.*?)(?:(\/))?}(?:(.+?){\/\2})?(.?)/s' , $ text , $ matches ) ; foreach ( $ matches [ 0 ] as $ ht ) { $ replace = str_replace_once ( '{' , '{{' , $ ht ) ; $ replace = str_replace_last ( '}' , '}}' , $ replace ) ; $ text = str_replace ( $ ht , $ replace , $ text ) ; } return $ text ; }
Escapes all shortcodes from the given content .
48,383
protected static function _list ( ) { if ( empty ( static :: $ _listeners ) ) { $ manager = EventDispatcher :: instance ( 'Shortcode' ) -> eventManager ( ) ; static :: $ _listeners = listeners ( $ manager ) ; } return static :: $ _listeners ; }
Returns a list of all registered shortcodes .
48,384
protected static function _getDefaultContext ( ) { if ( ! static :: $ _defaultContext ) { static :: $ _defaultContext = new View ( Router :: getRequest ( ) , null , EventManager :: instance ( ) , [ ] ) ; } return static :: $ _defaultContext ; }
Gets default context to use .
48,385
protected static function _doShortcode ( $ m ) { if ( $ m [ 1 ] == '{' && $ m [ 6 ] == '}' ) { return substr ( $ m [ 0 ] , 1 , - 1 ) ; } $ tag = $ m [ 2 ] ; $ atts = static :: _parseAttributes ( $ m [ 3 ] ) ; $ listeners = EventDispatcher :: instance ( 'Shortcode' ) -> eventManager ( ) -> listeners ( $ tag ) ; if ( ! empty ( $ listeners ) ) { $ options = [ 'atts' => ( array ) $ atts , 'content' => null , 'tag' => $ tag ] ; if ( isset ( $ m [ 5 ] ) ) { $ options [ 'content' ] = $ m [ 5 ] ; } $ result = EventDispatcher :: instance ( 'Shortcode' ) -> triggerArray ( [ $ tag , static :: cache ( 'context' ) ] , $ options ) -> result ; return $ m [ 1 ] . $ result . $ m [ 6 ] ; } return '' ; }
Invokes shortcode lister method for the given shortcode .
48,386
protected function _enable ( PluginPackage $ plugin ) { $ checker = new RuleChecker ( ( array ) $ plugin -> composer [ 'require' ] ) ; if ( ! $ checker -> check ( ) ) { $ this -> err ( __d ( 'installer' , 'Plugin "{0}" cannot be enabled as some dependencies are disabled or not installed: {1}' , $ plugin -> humanName , $ checker -> fail ( true ) ) ) ; return false ; } if ( ! $ this -> params [ 'no-callbacks' ] ) { $ this -> _attachListeners ( $ plugin -> name , "{$plugin->path}/" ) ; $ trigger = $ this -> _triggerBeforeEvents ( $ plugin ) ; if ( ! $ trigger ) { return false ; } } return $ this -> _finish ( $ plugin ) ; }
Activates the given plugin .
48,387
protected function _disable ( PluginPackage $ plugin ) { $ requiredBy = Plugin :: checkReverseDependency ( $ plugin -> name ) ; if ( ! empty ( $ requiredBy ) ) { $ names = [ ] ; foreach ( $ requiredBy as $ p ) { $ names [ ] = $ p -> name ( ) ; } $ this -> err ( __d ( 'installer' , 'Plugin "{0}" cannot be disabled as it is required by: {1}' , $ plugin -> humanName , implode ( ', ' , $ names ) ) ) ; return false ; } if ( ! $ this -> params [ 'no-callbacks' ] ) { $ trigger = $ this -> _triggerBeforeEvents ( $ plugin ) ; if ( ! $ trigger ) { return false ; } } return $ this -> _finish ( $ plugin ) ; }
Disables the given plugin .
48,388
protected function _finish ( PluginPackage $ plugin ) { $ pluginEntity = $ this -> Plugins -> find ( ) -> where ( [ 'name' => $ plugin -> name ] ) -> first ( ) ; $ pluginEntity -> set ( 'status' , $ this -> params [ 'status' ] === 'enable' ? true : false ) ; if ( ! $ this -> Plugins -> save ( $ pluginEntity ) ) { if ( $ this -> params [ 'status' ] === 'enable' ) { $ this -> err ( __d ( 'installer' , 'Plugin "{0}" could not be enabled due to an internal error.' , $ plugin -> humanName ) ) ; } else { $ this -> err ( __d ( 'installer' , 'Plugin "{0}" could not be disabled due to an internal error.' , $ plugin -> humanName ) ) ; } return false ; } snapshot ( ) ; if ( ! $ this -> params [ 'no-callbacks' ] ) { $ this -> _triggerAfterEvents ( $ plugin ) ; } return true ; }
Finish this task .
48,389
public static function cache ( $ key = null , $ value = null ) { if ( $ key === null && $ value === null ) { return static :: $ _cache ; } elseif ( $ key !== null && $ value === null ) { if ( isset ( static :: $ _cache [ $ key ] ) ) { return static :: $ _cache [ $ key ] ; } return null ; } if ( $ key !== null && $ value !== null ) { static :: $ _cache [ $ key ] = $ value ; return $ value ; } else { if ( ! empty ( static :: $ _cache ) ) { foreach ( static :: $ _cache as $ k => $ v ) { if ( $ v === $ value ) { return $ k ; } } } return null ; } }
Reads writes or search internal class s cache .
48,390
public static function dropCache ( $ key = null ) { if ( $ key !== null && isset ( static :: $ _cache [ $ key ] ) ) { unset ( static :: $ _cache [ $ key ] ) ; } else { static :: $ _cache = [ ] ; } }
Drops the entire cache or a specific key .
48,391
protected function _classFileHeader ( $ className ) { $ header = <<<TEXT<?php/** * Licensed under The GPL-3.0 License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @since 2.0.0 * @author Christopher Castro <chris@quickapps.es> * @link http://www.quickappscms.org * @license http://opensource.org/licenses/gpl-3.0.html GPL-3.0 License */TEXT ; if ( $ this -> params [ 'fixture' ] ) { $ header .= <<<TEXTnamespace CMS\Test\Fixture;use Cake\TestSuite\Fixture\TestFixture;TEXT ; } $ header .= $ this -> params [ 'fixture' ] ? "class {$className} extends TestFixture\n" : "\nclass {$className}\n" ; return $ header ; }
Returns correct class file header .
48,392
protected function _arrayToString ( array $ var ) { foreach ( $ var as $ rowIndex => $ row ) { foreach ( $ row as $ k => $ v ) { if ( is_resource ( $ var [ $ rowIndex ] [ $ k ] ) ) { $ var [ $ rowIndex ] [ $ k ] = stream_get_contents ( $ v ) ; } } } $ var = json_decode ( str_replace ( [ '(' , ')' ] , [ '&#40' , '&#41' ] , json_encode ( $ var ) ) , true ) ; $ var = var_export ( $ var , true ) ; return str_replace ( [ 'array (' , ')' , '&#40' , '&#41' ] , [ '[' , ']' , '(' , ')' ] , $ var ) ; }
Converts an array to code - string representation .
48,393
public function base_url ( $ base_url = '' , $ preserve_query_string = true ) { $ base_url = ( $ base_url == '' ? $ _SERVER [ 'REQUEST_URI' ] : $ base_url ) ; $ parsed_url = parse_url ( $ base_url ) ; $ this -> _properties [ 'base_url' ] = $ parsed_url [ 'path' ] ; $ this -> _properties [ 'base_url_query' ] = isset ( $ parsed_url [ 'query' ] ) ? $ parsed_url [ 'query' ] : '' ; parse_str ( $ this -> _properties [ 'base_url_query' ] , $ this -> _properties [ 'base_url_query' ] ) ; $ this -> _properties [ 'preserve_query_string' ] = $ preserve_query_string ; }
The base URL to be used when generating the navigation links .
48,394
public function css_classes ( $ css_classes ) { if ( ! is_array ( $ css_classes ) || empty ( $ css_classes ) || array_keys ( $ css_classes ) != array_filter ( array_keys ( $ css_classes ) , function ( $ value ) { return in_array ( $ value , array ( 'list' , 'list_item' , 'anchor' ) , true ) ; } ) ) trigger_error ( 'Invalid argument. Method <strong>classes()</strong> accepts as argument an associative array with one or more of the following keys: <em>list, list_item, anchor</em>' , E_USER_ERROR ) ; $ this -> _properties [ 'css_classes' ] = array_merge ( $ this -> _properties [ 'css_classes' ] , $ css_classes ) ; }
Sets the CSS class names to be applied to the unorderd list list item and anchors that make up the HTML markup of the pagination links .
48,395
public function get_page ( ) { if ( ! $ this -> _properties [ 'page_set' ] ) { if ( $ this -> _properties [ 'method' ] == 'url' && preg_match ( '/\b' . preg_quote ( $ this -> _properties [ 'variable_name' ] ) . '([0-9]+)\b/i' , $ _SERVER [ 'REQUEST_URI' ] , $ matches ) > 0 ) $ this -> set_page ( ( int ) $ matches [ 1 ] ) ; elseif ( isset ( $ _GET [ $ this -> _properties [ 'variable_name' ] ] ) ) $ this -> set_page ( ( int ) $ _GET [ $ this -> _properties [ 'variable_name' ] ] ) ; } if ( $ this -> _properties [ 'reverse' ] && $ this -> _properties [ 'records' ] == '' ) trigger_error ( 'When showing records in reverse order you must specify the total number of records (by calling the "records" method) *before* the first use of the "get_page" method!' , E_USER_ERROR ) ; if ( $ this -> _properties [ 'reverse' ] && $ this -> _properties [ 'records_per_page' ] == '' ) trigger_error ( 'When showing records in reverse order you must specify the number of records per page (by calling the "records_per_page" method) *before* the first use of the "get_page" method!' , E_USER_ERROR ) ; $ this -> _properties [ 'total_pages' ] = $ this -> get_pages ( ) ; if ( $ this -> _properties [ 'total_pages' ] > 0 ) { if ( $ this -> _properties [ 'page' ] > $ this -> _properties [ 'total_pages' ] ) $ this -> _properties [ 'page' ] = $ this -> _properties [ 'total_pages' ] ; elseif ( $ this -> _properties [ 'page' ] < 1 ) $ this -> _properties [ 'page' ] = 1 ; } if ( ! $ this -> _properties [ 'page_set' ] && $ this -> _properties [ 'reverse' ] ) $ this -> set_page ( $ this -> _properties [ 'total_pages' ] ) ; return $ this -> _properties [ 'page' ] ; }
Returns the current page s number .
48,396
public function render ( $ return_output = false ) { $ this -> get_page ( ) ; if ( $ this -> _properties [ 'total_pages' ] <= 1 ) return '' ; $ output = '<div class="Zebra_Pagination"><ul' . ( $ this -> _properties [ 'css_classes' ] [ 'list' ] != '' ? ' class="' . trim ( $ this -> _properties [ 'css_classes' ] [ 'list' ] ) . '"' : '' ) . '>' ; if ( $ this -> _properties [ 'reverse' ] ) { if ( $ this -> _properties [ 'navigation_position' ] == 'left' ) $ output .= $ this -> _show_next ( ) . $ this -> _show_previous ( ) . $ this -> _show_pages ( ) ; elseif ( $ this -> _properties [ 'navigation_position' ] == 'right' ) $ output .= $ this -> _show_pages ( ) . $ this -> _show_next ( ) . $ this -> _show_previous ( ) ; else $ output .= $ this -> _show_next ( ) . $ this -> _show_pages ( ) . $ this -> _show_previous ( ) ; } else { if ( $ this -> _properties [ 'navigation_position' ] == 'left' ) $ output .= $ this -> _show_previous ( ) . $ this -> _show_next ( ) . $ this -> _show_pages ( ) ; elseif ( $ this -> _properties [ 'navigation_position' ] == 'right' ) $ output .= $ this -> _show_pages ( ) . $ this -> _show_previous ( ) . $ this -> _show_next ( ) ; else $ output .= $ this -> _show_previous ( ) . $ this -> _show_pages ( ) . $ this -> _show_next ( ) ; } $ output .= '</ul></div>' ; if ( $ return_output ) return $ output ; echo $ output ; }
Generates the output .
48,397
public function set_page ( $ page ) { $ this -> _properties [ 'page' ] = ( int ) $ page ; if ( $ this -> _properties [ 'page' ] < 1 ) $ this -> _properties [ 'page' ] = 1 ; $ this -> _properties [ 'page_set' ] = true ; }
Sets the current page .
48,398
private function _build_uri ( $ page ) { if ( $ this -> _properties [ 'method' ] == 'url' ) { if ( preg_match ( '/\b' . $ this -> _properties [ 'variable_name' ] . '([0-9]+)\b/i' , $ this -> _properties [ 'base_url' ] ) > 0 ) { $ url = str_replace ( '//' , '/' , preg_replace ( '/\b' . $ this -> _properties [ 'variable_name' ] . '([0-9]+)\b/i' , ( $ page == 1 ? '' : $ this -> _properties [ 'variable_name' ] . $ page ) , $ this -> _properties [ 'base_url' ] ) ) ; } else $ url = rtrim ( $ this -> _properties [ 'base_url' ] , '/' ) . '/' . ( $ this -> _properties [ 'variable_name' ] . $ page ) ; $ url = rtrim ( $ url , '/' ) . ( $ this -> _properties [ 'trailing_slash' ] ? '/' : '' ) ; if ( ! $ this -> _properties [ 'preserve_query_string' ] ) $ query = implode ( '&' , $ this -> _properties [ 'base_url_query' ] ) ; else $ query = $ _SERVER [ 'QUERY_STRING' ] ; return $ url . ( $ query != '' ? '?' . $ query : '' ) ; } else { if ( ! $ this -> _properties [ 'preserve_query_string' ] ) $ query = $ this -> _properties [ 'base_url_query' ] ; else parse_str ( $ _SERVER [ 'QUERY_STRING' ] , $ query ) ; if ( ! $ this -> _properties [ 'avoid_duplicate_content' ] || ( $ page != ( $ this -> _properties [ 'reverse' ] ? $ this -> _properties [ 'total_pages' ] : 1 ) ) ) $ query [ $ this -> _properties [ 'variable_name' ] ] = $ page ; elseif ( $ this -> _properties [ 'avoid_duplicate_content' ] && $ page == ( $ this -> _properties [ 'reverse' ] ? $ this -> _properties [ 'total_pages' ] : 1 ) ) unset ( $ query [ $ this -> _properties [ 'variable_name' ] ] ) ; return htmlspecialchars ( html_entity_decode ( $ this -> _properties [ 'base_url' ] ) . ( ! empty ( $ query ) ? '?' . urldecode ( http_build_query ( $ query ) ) : '' ) ) ; } }
Generate the link for the page given as argument .
48,399
private function _show_previous ( ) { $ output = '' ; if ( $ this -> _properties [ 'always_show_navigation' ] || $ this -> _properties [ 'total_pages' ] > $ this -> _properties [ 'selectable_pages' ] ) { $ css_classes = isset ( $ this -> _properties [ 'css_classes' ] [ 'list_item' ] ) && $ this -> _properties [ 'css_classes' ] [ 'list_item' ] != '' ? array ( trim ( $ this -> _properties [ 'css_classes' ] [ 'list_item' ] ) ) : array ( ) ; if ( $ this -> _properties [ 'page' ] == 1 ) $ css_classes [ ] = 'disabled' ; $ output = '<li' . ( ! empty ( $ css_classes ) ? ' class="' . implode ( ' ' , $ css_classes ) . '"' : '' ) . '><a href="' . ( $ this -> _properties [ 'page' ] == 1 ? 'javascript:void(0)' : $ this -> _build_uri ( $ this -> _properties [ 'page' ] - 1 ) ) . '"' . ( isset ( $ this -> _properties [ 'css_classes' ] [ 'anchor' ] ) && $ this -> _properties [ 'css_classes' ] [ 'anchor' ] != '' ? ' class="' . trim ( $ this -> _properties [ 'css_classes' ] [ 'anchor' ] ) . '"' : '' ) . ' rel="prev">' . ( $ this -> _properties [ 'reverse' ] ? $ this -> _properties [ 'next' ] : $ this -> _properties [ 'previous' ] ) . '</a></li>' ; } return $ output ; }
Generates the previous page link depending on whether the pagination links are shown in natural or reversed order .