idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
48,100
public function fieldAttached ( ) { $ handler = $ this -> get ( 'metadata' ) -> get ( 'handler' ) ; if ( class_exists ( $ handler ) ) { $ handler = new $ handler ( ) ; return $ handler -> fieldAttached ( $ this ) ; } return true ; }
Triggers entity s fieldAttached callback .
48,101
public function beforeFind ( array $ options , $ primary ) { $ handler = $ this -> get ( 'metadata' ) -> get ( 'handler' ) ; if ( class_exists ( $ handler ) ) { $ handler = new $ handler ( ) ; return $ handler -> beforeFind ( $ this , $ options , $ primary ) ; } return true ; }
Triggers entity s beforeFind callback . Returning NULL will remove the entity from resulting collection returning FALSE will halt the entire find operation .
48,102
public function validate ( Validator $ validator ) { $ handler = $ this -> get ( 'metadata' ) -> get ( 'handler' ) ; if ( class_exists ( $ handler ) ) { $ handler = new $ handler ( ) ; return $ handler -> validate ( $ this , $ validator ) ; } }
Triggers entity s validate callback .
48,103
public function beforeSave ( $ post ) { $ handler = $ this -> get ( 'metadata' ) -> get ( 'handler' ) ; if ( class_exists ( $ handler ) ) { $ handler = new $ handler ( ) ; return $ handler -> beforeSave ( $ this , $ post ) ; } return true ; }
Triggers entity s beforeSave callback . Returning FALSE will halt the save operation .
48,104
public function afterSave ( ) { $ handler = $ this -> get ( 'metadata' ) -> get ( 'handler' ) ; if ( class_exists ( $ handler ) ) { $ handler = new $ handler ( ) ; return $ handler -> afterSave ( $ this ) ; } }
Triggers entity s afterSave callback .
48,105
public function beforeDelete ( ) { $ handler = $ this -> get ( 'metadata' ) -> get ( 'handler' ) ; if ( class_exists ( $ handler ) ) { $ handler = new $ handler ( ) ; return $ handler -> beforeDelete ( $ this ) ; } return true ; }
Triggers entity s beforeDelete callback . Returning FALSE will halt the delete operation .
48,106
public function index ( ) { $ this -> loadModel ( 'User.Acos' ) ; $ roles = $ this -> Acos -> Roles -> find ( ) -> all ( ) ; $ this -> title ( __d ( 'user' , 'User Roles List' ) ) ; $ this -> set ( compact ( 'roles' ) ) ; $ this -> Breadcrumb -> push ( '/admin/user/manage' ) -> push ( __d ( 'user' , 'Roles' ) , [ 'plugin' => 'User' , 'controller' => 'roles' , 'action' => 'index' ] ) ; }
Shows a list of all available roles .
48,107
public function edit ( $ id ) { $ this -> loadModel ( 'User.Roles' ) ; $ role = $ this -> Roles -> get ( $ id ) ; if ( $ this -> request -> data ( ) ) { if ( empty ( $ this -> request -> data [ 'regenerate_slug' ] ) ) { $ this -> Roles -> behaviors ( ) -> Sluggable -> config ( [ 'on' => 'create' ] ) ; } $ role = $ this -> Roles -> patchEntity ( $ role , $ this -> request -> data ( ) , [ 'fieldList' => 'name' ] ) ; if ( $ this -> Roles -> save ( $ role ) ) { $ this -> Flash -> success ( __d ( 'user' , 'Role successfully updated.' ) ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'Role could not be updated.' ) ) ; } } $ this -> title ( __d ( 'user' , 'Editing User Role' ) ) ; $ this -> set ( compact ( 'role' ) ) ; $ this -> Breadcrumb -> push ( '/admin/user/manage' ) -> push ( __d ( 'user' , 'Roles' ) , [ 'plugin' => 'User' , 'controller' => 'roles' , 'action' => 'index' ] ) -> push ( __d ( 'user' , 'Edit role' ) , '' ) ; }
Edits the given role .
48,108
public function beforeRender ( Event $ event ) { $ plugin = ( string ) Inflector :: camelize ( $ event -> subject ( ) -> request -> params [ 'plugin' ] ) ; $ controller = Inflector :: camelize ( $ event -> subject ( ) -> request -> params [ 'controller' ] ) ; $ action = Inflector :: underscore ( $ event -> subject ( ) -> request -> params [ 'action' ] ) ; $ prefix = '' ; if ( ! empty ( $ event -> subject ( ) -> request -> params [ 'prefix' ] ) ) { $ prefix = Inflector :: camelize ( $ event -> subject ( ) -> request -> params [ 'prefix' ] ) . '/' ; } $ templatePath = Plugin :: classPath ( $ plugin ) . "Template/{$prefix}{$controller}/{$action}.ctp" ; if ( ! is_readable ( $ templatePath ) ) { $ alternativeTemplatePath = Plugin :: classPath ( 'Comment' ) . 'Template/CommentUI' ; if ( is_readable ( "{$alternativeTemplatePath}/{$action}.ctp" ) ) { $ this -> plugin = 'Comment' ; $ this -> viewBuilder ( ) -> templatePath ( 'CommentUI' ) ; } } parent :: beforeRender ( $ event ) ; }
Fallback for template location when extending Comment UI API .
48,109
public function edit ( $ id ) { $ this -> loadModel ( 'Comment.Comments' ) ; $ comment = $ this -> Comments -> find ( ) -> contain ( [ 'Users' ] ) -> where ( [ 'Comments.id' => $ id , 'Comments.table_alias' => $ this -> _manageTable ] ) -> first ( ) ; if ( ! $ comment ) { throw new RecordNotFoundException ( __d ( 'comment' , 'Comment could not be found.' ) ) ; } if ( $ this -> request -> data ( ) ) { $ comment -> accessible ( '*' , false ) ; $ comment -> accessible ( [ 'subject' , 'body' , 'author_name' , 'author_email' , 'author_web' , 'status' ] , true ) ; $ validator = $ comment -> user_id ? 'default' : 'anonymous' ; $ this -> Comments -> patchEntity ( $ comment , $ this -> request -> data ( ) , [ 'validate' => $ validator ] ) ; $ errors = $ comment -> errors ( ) ; if ( empty ( $ errors ) ) { $ this -> Comments -> save ( $ comment , [ 'associated' => false ] ) ; $ this -> Flash -> success ( __d ( 'comment' , 'Comment saved!.' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } else { $ this -> Flash -> danger ( __d ( 'comment' , 'Comment could not be saved, please check your information.' ) ) ; } } $ this -> title ( __d ( 'comment' , 'Editing Comment' ) ) ; $ this -> set ( 'comment' , $ comment ) ; }
Edit form for given comment .
48,110
public function status ( $ id , $ status ) { if ( in_array ( $ status , [ 'pending' , 'approved' , 'spam' , 'trash' ] ) ) { $ this -> loadModel ( 'Comment.Comments' ) ; if ( $ comment = $ this -> Comments -> get ( $ id ) ) { $ comment -> set ( 'status' , $ status ) ; $ this -> Comments -> save ( $ comment ) ; } } $ this -> title ( __d ( 'comment' , 'Change Comment Status' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Changes the status of the given comment .
48,111
public function delete ( $ id ) { $ this -> loadModel ( 'Comment.Comments' ) ; $ comment = $ this -> Comments -> find ( ) -> where ( [ 'Comments.id' => $ id , 'Comments.table_alias' => $ this -> _manageTable ] ) -> first ( ) ; if ( $ comment ) { if ( $ this -> Comments -> delete ( $ comment ) ) { $ this -> Flash -> success ( __d ( 'comment' , 'Comment was successfully deleted!' ) ) ; } else { $ this -> Flash -> danger ( __d ( 'comment' , 'Comment could not be deleted, please try again.' ) ) ; } } else { $ this -> Flash -> danger ( __d ( 'comment' , 'Invalid comment, comment was not found.' ) ) ; } $ this -> title ( __d ( 'comment' , 'Delete Comment' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Permanently deletes the given comment .
48,112
public function emptyTrash ( ) { $ this -> loadModel ( 'Comment.Comments' ) ; $ this -> Comments -> deleteAll ( [ 'Comments.status' => 'trash' , 'Comments.table_alias' => $ this -> _manageTable ] ) ; $ this -> Flash -> success ( __d ( 'comment' , 'All comments in trash were successfully removed!' ) ) ; $ this -> title ( __d ( 'comment' , 'Empty Trash' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Permanently deletes all comments marked as trash .
48,113
protected function _subQuery ( $ column , $ bundle = null ) { $ alias = $ this -> _table -> alias ( ) ; $ pk = $ this -> _table -> primaryKey ( ) ; $ type = $ this -> _toolbox -> getType ( $ column ) ; $ subConditions = [ 'EavAttribute.table_alias' => $ this -> _table -> table ( ) , 'EavValues.entity_id' => "{$alias}.{$pk}" , 'EavAttribute.name' => $ column , ] ; if ( ! empty ( $ bundle ) ) { $ subConditions [ 'EavAttribute.bundle' ] = $ bundle ; } $ subQuery = TableRegistry :: get ( 'Eav.EavValues' ) -> find ( ) -> contain ( [ 'EavAttribute' ] ) -> select ( [ "EavValues.value_{$type}" ] ) -> where ( $ subConditions ) -> sql ( ) ; return str_replace ( [ ':c0' , ':c1' , ':c2' , ':c3' ] , [ '"' . $ this -> _table -> table ( ) . '"' , "{$alias}.{$pk}" , '"' . $ column . '"' , '"' . $ bundle . '"' ] , $ subQuery ) ; }
Generates a SQL sub - query for replacing in ORDER BY clause .
48,114
public function parseConstraints ( $ constraints ) { $ prettyConstraint = $ constraints ; if ( preg_match ( '{^([^,\s]*?)@(' . implode ( '|' , array_keys ( BasePackage :: $ stabilities ) ) . ')$}i' , $ constraints , $ match ) ) { $ constraints = empty ( $ match [ 1 ] ) ? '*' : $ match [ 1 ] ; } if ( preg_match ( '{^(dev-[^,\s@]+?|[^,\s@]+?\.x-dev)#.+$}i' , $ constraints , $ match ) ) { $ constraints = $ match [ 1 ] ; } $ orConstraints = preg_split ( '{\s*\|\|?\s*}' , trim ( $ constraints ) ) ; $ orGroups = [ ] ; foreach ( $ orConstraints as $ constraints ) { $ andConstraints = preg_split ( '{(?<!^|as|[=>< ,]) *(?<!-)[, ](?!-) *(?!,|as|$)}' , $ constraints ) ; if ( count ( $ andConstraints ) > 1 ) { $ constraintObjects = [ ] ; foreach ( $ andConstraints as $ constraint ) { $ constraintObjects = array_merge ( $ constraintObjects , $ this -> parseConstraint ( $ constraint ) ) ; } } else { $ constraintObjects = $ this -> parseConstraint ( $ andConstraints [ 0 ] ) ; } if ( 1 === count ( $ constraintObjects ) ) { $ constraint = $ constraintObjects [ 0 ] ; } else { $ constraint = new MultiConstraint ( $ constraintObjects ) ; } $ orGroups [ ] = $ constraint ; } if ( 1 === count ( $ orGroups ) ) { $ constraint = $ orGroups [ 0 ] ; } else { $ constraint = new MultiConstraint ( $ orGroups , false ) ; } $ constraint -> setPrettyString ( $ prettyConstraint ) ; return $ constraint ; }
Parses as constraint string into LinkConstraint objects
48,115
public function manipulateVersionString ( $ matches , $ position , $ increment = 0 , $ pad = '0' ) { for ( $ i = 4 ; $ i > 0 ; $ i -- ) { if ( $ i > $ position ) { $ matches [ $ i ] = $ pad ; } elseif ( $ i == $ position && $ increment ) { $ matches [ $ i ] += $ increment ; if ( $ matches [ $ i ] < 0 ) { $ matches [ $ i ] = $ pad ; $ position -- ; if ( $ i == 1 ) { return ; } } } } return $ matches [ 1 ] . '.' . $ matches [ 2 ] . '.' . $ matches [ 3 ] . '.' . $ matches [ 4 ] ; }
Increment decrement or simply pad a version number .
48,116
public function buildRules ( RulesChecker $ rules ) { $ rules -> addCreate ( function ( $ instance , $ options ) { $ info = ( array ) $ instance -> info ( ) ; if ( isset ( $ info [ 'maxInstances' ] ) && $ info [ 'maxInstances' ] > 0 ) { if ( ! $ instance -> get ( 'eav_attribute' ) ) { return false ; } $ count = $ this -> find ( ) -> select ( [ 'FieldInstances.id' , 'FieldInstances.handler' , 'EavAttribute.id' , 'EavAttribute.table_alias' ] ) -> contain ( [ 'EavAttribute' ] ) -> where ( [ 'EavAttribute.table_alias' => $ instance -> get ( 'eav_attribute' ) -> get ( 'table_alias' ) , 'FieldInstances.handler' => $ instance -> get ( 'handler' ) , ] ) -> count ( ) ; return ( $ count <= ( intval ( $ info [ 'maxInstances' ] ) - 1 ) ) ; } return true ; } , 'maxInstances' , [ 'errorField' => 'label' , 'message' => __d ( 'field' , 'No more instances of this field can be attached, limit reached.' ) , ] ) ; return $ rules ; }
Application rules .
48,117
public function beforeFind ( Event $ event , Query $ query , ArrayObject $ options , $ primary ) { $ viewModes = $ this -> viewModes ( ) ; $ query -> formatResults ( function ( $ results ) use ( $ viewModes ) { return $ results -> map ( function ( $ instance ) use ( $ viewModes ) { if ( ! is_object ( $ instance ) ) { return $ instance ; } foreach ( $ viewModes as $ viewMode ) { $ instanceViewModes = $ instance -> view_modes ; $ viewModeDefaults = array_merge ( [ 'label_visibility' => 'above' , 'shortcodes' => false , 'hidden' => false , 'ordering' => 0 , ] , ( array ) $ instance -> defaultViewModeSettings ( $ viewMode ) ) ; if ( ! isset ( $ instanceViewModes [ $ viewMode ] ) ) { $ instanceViewModes [ $ viewMode ] = [ ] ; } $ instanceViewModes [ $ viewMode ] = array_merge ( $ viewModeDefaults , $ instanceViewModes [ $ viewMode ] ) ; $ instance -> set ( 'view_modes' , $ instanceViewModes ) ; } $ settingsDefaults = ( array ) $ instance -> defaultSettings ( ) ; if ( ! empty ( $ settingsDefaults ) ) { $ instanceSettings = $ instance -> get ( 'settings' ) ; foreach ( $ settingsDefaults as $ k => $ v ) { if ( ! isset ( $ instanceSettings [ $ k ] ) ) { $ instanceSettings [ $ k ] = $ v ; } } $ instance -> set ( 'settings' , $ instanceSettings ) ; } return $ instance ; } ) ; } ) ; }
Here we set default values for each view mode if they were not defined before .
48,118
public function beforeSave ( Event $ event , FieldInstance $ instance , ArrayObject $ options = null ) { $ result = $ instance -> beforeAttach ( ) ; if ( $ result === false ) { return false ; } return true ; }
Triggers the callback beforeAttach if a new instance is being created .
48,119
public function afterSave ( Event $ event , FieldInstance $ instance , ArrayObject $ options = null ) { if ( $ instance -> isNew ( ) ) { $ instance -> afterAttach ( ) ; } }
Triggers the callback afterAttach if a new instance was created .
48,120
public function beforeDelete ( Event $ event , FieldInstance $ instance , ArrayObject $ options = null ) { $ result = $ instance -> beforeDetach ( ) ; if ( $ result === false ) { return false ; } $ this -> _deleted = $ this -> get ( $ instance -> get ( 'id' ) , [ 'contain' => [ 'EavAttribute' ] ] ) ; return true ; }
Triggers the callback beforeDetach .
48,121
public function afterDelete ( Event $ event , FieldInstance $ instance , ArrayObject $ options = null ) { if ( ! empty ( $ this -> _deleted ) ) { TableRegistry :: get ( 'Eav.EavAttributes' ) -> delete ( $ this -> _deleted -> get ( 'eav_attribute' ) ) ; $ instance -> afterDetach ( ) ; $ this -> _deleted = null ; } }
Triggers the callback afterDetach it also deletes all associated records in the field_values table .
48,122
public function unused ( ) { $ ids = [ ] ; foreach ( [ $ this -> inFrontTheme ( ) , $ this -> inBackTheme ( ) ] as $ bundle ) { foreach ( $ bundle as $ region => $ blocks ) { foreach ( $ blocks as $ block ) { $ ids [ ] = $ block -> get ( 'id' ) ; } } } $ notIn = array_unique ( $ ids ) ; $ notIn = empty ( $ notIn ) ? [ '0' ] : $ notIn ; return $ this -> find ( ) -> where ( [ 'OR' => [ 'Blocks.id NOT IN' => $ notIn , 'Blocks.status' => 0 , ] ] ) -> all ( ) -> filter ( function ( $ block ) { return $ block -> renderable ( ) ; } ) ; }
Gets a list of all blocks that are NOT renderable .
48,123
public function validationCustom ( Validator $ validator ) { return $ this -> validationWidget ( $ validator ) -> requirePresence ( 'body' ) -> add ( 'body' , [ 'notBlank' => [ 'rule' => 'notBlank' , 'message' => __d ( 'block' , "You need to provide a content for block's body." ) , ] , 'length' => [ 'rule' => [ 'minLength' , 3 ] , 'message' => __d ( 'block' , "Block's body need to be at least 3 characters long." ) , ] , ] ) ; }
Validation rules for custom blocks .
48,124
public function settingsValidate ( Event $ event , array $ data , ArrayObject $ options ) { if ( ! empty ( $ options [ 'entity' ] ) && $ options [ 'entity' ] -> has ( 'handler' ) ) { $ block = $ options [ 'entity' ] ; if ( ! $ block -> isCustom ( ) ) { $ validator = new Validator ( ) ; $ block -> validateSettings ( $ data , $ validator ) ; $ errors = $ validator -> errors ( ( array ) $ data ) ; foreach ( $ errors as $ k => $ v ) { $ block -> errors ( "settings:{$k}" , $ v ) ; } } } }
Validates block settings before persisted in DB .
48,125
public function beforeSave ( Event $ event , Block $ block , ArrayObject $ options = null ) { $ result = $ block -> beforeSave ( ) ; if ( $ result === false ) { return false ; } return true ; }
Triggered before block is persisted in DB .
48,126
public function afterSave ( Event $ event , Block $ block , ArrayObject $ options = null ) { $ block -> afterSave ( ) ; $ this -> clearCache ( ) ; }
Triggered after block was persisted in DB .
48,127
public function alterTextarea ( MethodInvocation $ invocation ) { $ helper = $ invocation -> getThis ( ) ; list ( $ fieldName , $ options ) = array_pad ( $ invocation -> getArguments ( ) , 2 , null ) ; if ( ! empty ( $ options [ 'class' ] ) && strpos ( $ options [ 'class' ] , 'ckeditor' ) !== false && $ helper instanceof FormHelper ) { static :: $ _counter ++ ; $ editorId = 'ck-editor-' . static :: $ _counter ; $ options [ 'class' ] .= ' ' . $ editorId ; $ view = $ this -> getProperty ( $ helper , '_View' ) ; if ( ! static :: $ _scriptsLoaded ) { static :: $ _scriptsLoaded = true ; $ filebrowserBrowseUrl = $ view -> Url -> build ( [ 'plugin' => 'Wysiwyg' , 'controller' => 'finder' ] ) ; $ view -> Html -> script ( 'Wysiwyg./ckeditor/ckeditor.js' , [ 'block' => true ] ) ; $ view -> Html -> script ( 'Wysiwyg./ckeditor/adapters/jquery.js' , [ 'block' => true ] ) ; $ view -> Html -> scriptBlock ( '$(document).ready(function () { CKEDITOR.editorConfig = function(config) { config.filebrowserBrowseUrl = "' . $ filebrowserBrowseUrl . '"; }; });' , [ 'block' => true ] ) ; $ this -> _includeLinksToContents ( $ view ) ; } } $ this -> setProperty ( $ invocation , 'arguments' , [ $ fieldName , $ options ] ) ; return $ invocation -> proceed ( ) ; }
Converts the given text area into a WYSIWYG editor .
48,128
protected function _includeLinksToContents ( $ view ) { $ items = [ ] ; $ contents = TableRegistry :: get ( 'Content.Contents' ) -> find ( 'all' , [ 'fieldable' => false ] ) -> contain ( [ 'ContentTypes' ] ) -> where ( [ 'status' => 1 ] ) -> order ( [ 'sticky' => 'DESC' , 'modified' => 'DESC' ] ) ; foreach ( $ contents as $ content ) { $ items [ ] = [ "{$content->type}: " . h ( $ content -> title ) , $ view -> Url -> build ( $ content -> url , true ) ] ; } $ view -> Html -> scriptBlock ( 'var linksToContentsItems = ' . json_encode ( $ items ) . ';' , [ 'block' => true ] ) ; $ view -> Html -> scriptBlock ( 'var linksToContentsLabel = "' . __d ( 'wysiwyg' , 'Link to content' ) . '";' , [ 'block' => true ] ) ; $ view -> Html -> script ( 'Wysiwyg.ckeditor.content.links.js' , [ 'block' => true ] ) ; }
Alters CKEditor s link plugin .
48,129
protected function _prepareConjunction ( TokenInterface $ token ) { $ value = $ token -> value ( ) ; $ conjunction = strtolower ( $ this -> config ( 'conjunction' ) ) ; if ( $ conjunction == 'auto' ) { $ conjunction = strpos ( $ value , ',' ) !== false ? 'in' : 'like' ; } if ( $ conjunction == 'in' ) { $ value = array_slice ( explode ( ',' , $ value ) , 0 , $ this -> config ( 'inSlice' ) ) ; $ conjunction = $ token -> negated ( ) ? 'NOT IN' : 'IN' ; } elseif ( $ conjunction == 'like' ) { $ value = str_replace ( [ '*' , '!' ] , [ '%' , '_' ] , $ value ) ; $ conjunction = $ token -> negated ( ) ? 'NOT LIKE' : 'LIKE' ; } elseif ( $ conjunction == '=' ) { $ conjunction = $ token -> negated ( ) ? '<>' : '' ; } elseif ( $ conjunction == '<>' ) { $ conjunction = $ token -> negated ( ) ? '' : '<>' ; } return [ $ conjunction , $ value ] ; }
Calculates the conjunction to use and the value to use with such conjunction based on the given token .
48,130
public static function get ( $ plugin = null ) { $ cacheKey = "get({$plugin})" ; $ cache = static :: cache ( $ cacheKey ) ; if ( $ cache !== null ) { return $ cache ; } if ( $ plugin === null ) { $ collection = [ ] ; foreach ( ( array ) quickapps ( 'plugins' ) as $ plugin ) { $ plugin = PackageFactory :: create ( $ plugin [ 'name' ] ) ; if ( $ plugin instanceof PluginPackage ) { $ collection [ ] = $ plugin ; } } return static :: cache ( $ cacheKey , collection ( $ collection ) ) ; } $ package = PackageFactory :: create ( $ plugin ) ; if ( $ package instanceof PluginPackage ) { return static :: cache ( $ cacheKey , $ package ) ; } throw new FatalErrorException ( __d ( 'cms' , 'Plugin "{0}" was not found' , $ plugin ) ) ; }
Get the given plugin as an object or a collection of objects if not specified .
48,131
public static function validateJson ( $ json , $ errorMessages = false ) { if ( is_string ( $ json ) && is_readable ( $ json ) && ! is_dir ( $ json ) ) { $ json = json_decode ( ( new File ( $ json ) ) -> read ( ) , true ) ; } $ errors = [ ] ; if ( ! is_array ( $ json ) || empty ( $ json ) ) { $ errors [ ] = __d ( 'cms' , 'Corrupt JSON information.' ) ; } else { if ( ! isset ( $ json [ 'type' ] ) ) { $ errors [ ] = __d ( 'cms' , 'Missing field: "{0}"' , 'type' ) ; } if ( ! isset ( $ json [ 'name' ] ) ) { $ errors [ ] = __d ( 'cms' , 'Missing field: "{0}"' , 'name' ) ; } elseif ( ! preg_match ( '/^(.+)\/(.+)+$/' , $ json [ 'name' ] ) ) { $ errors [ ] = __d ( 'cms' , 'Invalid field: "{0}" ({1}). It should be: {2}' , 'name' , $ json [ 'name' ] , '{author-name}/{package-name}' ) ; } elseif ( str_ends_with ( strtolower ( $ json [ 'name' ] ) , 'theme' ) ) { if ( ! isset ( $ json [ 'extra' ] [ 'regions' ] ) ) { $ errors [ ] = __d ( 'cms' , 'Missing field: "{0}"' , 'extra.regions' ) ; } } } if ( $ errorMessages ) { return $ errors ; } return empty ( $ errors ) ; }
Validates a composer . json file .
48,132
public static function languagesList ( $ full = false , $ sort = true ) { $ languages = [ ] ; if ( $ full ) { foreach ( static :: $ _catalog as $ code => $ info ) { $ languages [ $ code ] = $ info [ 'language' ] ; } } else { foreach ( quickapps ( 'languages' ) as $ code => $ data ) { $ languages [ $ code ] = $ data [ 'name' ] ; } } if ( $ sort ) { asort ( $ languages ) ; } return $ languages ; }
Gets a list of languages suitable for select boxes .
48,133
public static function flagsList ( ) { $ flags = [ ] ; $ Folder = new Folder ( Plugin :: path ( 'Locale' ) . 'webroot/img/flags/' ) ; foreach ( $ Folder -> read ( ) [ 1 ] as $ icon ) { $ value = $ icon ; $ label = str_replace_last ( '.gif' , '' , $ icon ) ; $ flags [ $ value ] = $ label ; } asort ( $ flags ) ; return $ flags ; }
Gets a list of counties flags suitable for select boxes .
48,134
public function search ( $ vocabularyId ) { $ this -> loadModel ( 'Taxonomy.Terms' ) ; $ out = [ ] ; $ text = $ this -> request -> query [ 'q' ] ; $ terms = $ this -> Terms -> find ( ) -> select ( [ 'id' , 'name' ] ) -> where ( [ 'name LIKE' => "%%{$text}%%" , 'vocabulary_id' => $ vocabularyId ] ) -> limit ( 10 ) -> all ( ) ; foreach ( $ terms as $ term ) { $ out [ ] = [ 'id' => $ term -> id , 'name' => $ term -> name ] ; } die ( json_encode ( $ out ) ) ; }
Shows a list of matching terms .
48,135
public function netunmount ( $ netVolumes , $ key ) { $ count = 0 ; $ dropboxUid = '' ; if ( isset ( $ netVolumes [ $ key ] ) ) { $ dropboxUid = $ netVolumes [ $ key ] [ 'dropboxUid' ] ; } foreach ( $ netVolumes as $ volume ) { if ( @ $ volume [ 'host' ] === 'dropbox' && @ $ volume [ 'dropboxUid' ] === $ dropboxUid ) { $ count ++ ; } } if ( $ count === 1 ) { $ this -> DB -> exec ( 'drop table ' . $ this -> DB_TableName ) ; foreach ( glob ( rtrim ( $ this -> options [ 'tmbPath' ] , '\\/' ) . DIRECTORY_SEPARATOR . $ this -> tmbPrefix . '*.png' ) as $ tmb ) { unlink ( $ tmb ) ; } } return true ; }
process of on netunmount Drop table dropbox & rm thumbs
48,136
private function getConnectorUrl ( ) { $ url = ( ( isset ( $ _SERVER [ 'HTTPS' ] ) && strtolower ( $ _SERVER [ 'HTTPS' ] ) !== 'off' ) ? 'https://' : 'http://' ) . $ _SERVER [ 'SERVER_NAME' ] . ( $ _SERVER [ 'SERVER_PORT' ] == 80 ? '' : ':' . $ _SERVER [ 'SERVER_PORT' ] ) . $ _SERVER [ 'REQUEST_URI' ] ; list ( $ url ) = explode ( '?' , $ url ) ; return $ url ; }
Get script url
48,137
private function checkDB ( ) { $ res = $ this -> query ( 'select * from sqlite_master where type=\'table\' and name=\'dropbox\'; ' ) ; if ( ! $ res ) { try { $ this -> DB -> exec ( 'create table ' . $ this -> DB_TableName . '(path text, fname text, dat blob, isdir integer);' ) ; $ this -> DB -> exec ( 'create index nameidx on ' . $ this -> DB_TableName . '(path, fname)' ) ; $ this -> DB -> exec ( 'create index isdiridx on ' . $ this -> DB_TableName . '(isdir)' ) ; } catch ( PDOException $ e ) { return $ this -> setError ( $ e -> getMessage ( ) ) ; } } return true ; }
Check DB for delta cache
48,138
private function query ( $ sql ) { if ( $ sth = $ this -> DB -> query ( $ sql ) ) { $ res = $ sth -> fetchAll ( PDO :: FETCH_COLUMN ) ; } else { $ res = false ; } return $ res ; }
DB query and fetchAll
48,139
private function getHttpResponseHeader ( $ url ) { if ( function_exists ( 'curl_exec' ) ) { $ c = curl_init ( ) ; curl_setopt ( $ c , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ c , CURLOPT_CUSTOMREQUEST , 'HEAD' ) ; curl_setopt ( $ c , CURLOPT_HEADER , 1 ) ; curl_setopt ( $ c , CURLOPT_NOBODY , true ) ; curl_setopt ( $ c , CURLOPT_URL , $ url ) ; $ res = curl_exec ( $ c ) ; } else { require_once 'HTTP/Request2.php' ; try { $ request2 = new HTTP_Request2 ( ) ; $ request2 -> setConfig ( array ( 'ssl_verify_peer' => false , 'ssl_verify_host' => false ) ) ; $ request2 -> setUrl ( $ url ) ; $ request2 -> setMethod ( HTTP_Request2 :: METHOD_HEAD ) ; $ result = $ request2 -> send ( ) ; $ res = array ( ) ; $ res [ ] = 'HTTP/' . $ result -> getVersion ( ) . ' ' . $ result -> getStatus ( ) . ' ' . $ result -> getReasonPhrase ( ) ; foreach ( $ result -> getHeader ( ) as $ key => $ val ) { $ res [ ] = $ key . ': ' . $ val ; } $ res = join ( "\r\n" , $ res ) ; } catch ( HTTP_Request2_Exception $ e ) { $ res = '' ; } catch ( Exception $ e ) { $ res = '' ; } } return $ res ; }
Get HTTP request response header string
48,140
public function addInputPrefix ( MethodInvocation $ invocation ) { $ helper = $ invocation -> getThis ( ) ; $ args = $ invocation -> getArguments ( ) ; if ( ! empty ( $ args [ 0 ] ) && is_string ( $ args [ 0 ] ) && $ helper instanceof FormHelper ) { $ args [ 0 ] = $ this -> _fieldName ( $ helper , $ args [ 0 ] ) ; } $ this -> setProperty ( $ invocation , 'arguments' , $ args ) ; return $ invocation -> proceed ( ) ; }
Adds prefix to every input element that may have a name attribute .
48,141
public function index ( ) { $ this -> loadModel ( 'User.Acos' ) ; $ tree = $ this -> Acos -> find ( 'threaded' ) -> order ( [ 'lft' => 'ASC' ] ) -> all ( ) ; $ this -> title ( __d ( 'user' , 'Permissions' ) ) ; $ this -> set ( compact ( 'tree' ) ) ; $ this -> Breadcrumb -> push ( '/admin/user/manage' ) -> push ( __d ( 'user' , 'Permissions' ) , [ 'plugin' => 'User' , 'controller' => 'permissions' , 'action' => 'index' ] ) ; }
Shows tree list of ACOS grouped by plugin .
48,142
public function aco ( $ acoId ) { $ this -> loadModel ( 'User.Acos' ) ; $ aco = $ this -> Acos -> get ( $ acoId , [ 'contain' => [ 'Roles' ] ] ) ; $ path = $ this -> Acos -> find ( 'path' , [ 'for' => $ acoId ] ) -> extract ( 'alias' ) -> toArray ( ) ; if ( ! empty ( $ this -> request -> data [ 'roles' ] ) ) { $ aco = $ this -> Acos -> patchEntity ( $ aco , $ this -> request -> data ) ; $ save = $ this -> Acos -> save ( $ aco ) ; if ( ! $ this -> request -> isAjax ( ) ) { if ( $ save ) { $ this -> Flash -> success ( __d ( 'user' , 'Permissions were successfully saved!' ) ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'Permissions could not be saved' ) ) ; } } } $ roles = $ this -> Acos -> Roles -> find ( 'list' ) -> where ( [ 'Roles.id <>' => ROLE_ID_ADMINISTRATOR ] ) ; $ this -> title ( __d ( 'user' , 'Permissions' ) ) ; $ this -> set ( compact ( 'aco' , 'roles' , 'path' ) ) ; }
Shows the permissions table for the given ACO .
48,143
public function update ( ) { $ sync = ! empty ( $ this -> request -> query [ 'sync' ] ) ? true : false ; if ( AcoManager :: buildAcos ( null , $ sync ) ) { $ this -> Flash -> success ( __d ( 'user' , 'Permissions tree was successfully updated!' ) ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'Some errors occur while updating permissions tree.' ) ) ; } $ this -> title ( __d ( 'user' , 'Update Permissions' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Analyzes each plugin and adds any missing ACO path to the tree . It won t remove any invalid ACO unless sync GET parameter is present in URL .
48,144
public function export ( ) { $ this -> loadModel ( 'User.Acos' ) ; $ out = [ ] ; $ permissions = $ this -> Acos -> Permissions -> find ( ) -> contain ( [ 'Acos' , 'Roles' ] ) -> all ( ) ; foreach ( $ permissions as $ permission ) { if ( ! isset ( $ out [ $ permission -> role -> slug ] ) ) { $ out [ $ permission -> role -> slug ] = [ ] ; } $ out [ $ permission -> role -> slug ] [ ] = implode ( '/' , $ this -> Acos -> find ( 'path' , [ 'for' => $ permission -> aco -> id ] ) -> extract ( 'alias' ) -> toArray ( ) ) ; } $ this -> title ( __d ( 'user' , 'Export Permissions' ) ) ; $ this -> response -> body ( json_encode ( $ out , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ) ; $ this -> response -> type ( 'json' ) ; $ this -> response -> download ( 'permissions_' . date ( 'Y-m-d@H:i:s-\U\TC' , time ( ) ) . '.json' ) ; return $ this -> response ; }
Exports all permissions as a JSON file .
48,145
protected function _getRegion ( ) { if ( isset ( $ this -> _matchingData [ 'BlockRegions' ] ) ) { return $ this -> _matchingData [ 'BlockRegions' ] ; } if ( isset ( $ this -> _properties [ 'region' ] ) ) { return $ this -> _properties [ 'region' ] ; } }
Tries to get block s region .
48,146
public static function process ( $ content , $ processor ) { switch ( $ processor ) { case 'plain' : $ content = static :: plainProcessor ( $ content ) ; break ; case 'filtered' : $ content = static :: filteredProcessor ( $ content ) ; break ; case 'markdown' : $ content = static :: markdownProcessor ( $ content ) ; break ; } return $ content ; }
Process the given text to its corresponding format .
48,147
public static function plainProcessor ( $ text ) { $ text = static :: emailToLink ( $ text ) ; $ text = static :: urlToLink ( $ text ) ; $ text = nl2br ( $ text ) ; return $ text ; }
Process text in plain mode .
48,148
public static function filteredProcessor ( $ text ) { $ text = static :: emailToLink ( $ text ) ; $ text = static :: urlToLink ( $ text ) ; $ text = strip_tags ( $ text , '<a><em><strong><cite><blockquote><code><ul><ol><li><dl><dt><dd>' ) ; return $ text ; }
Process text in filtered HTML mode .
48,149
public static function markdownProcessor ( $ text ) { $ MarkdownParser = static :: getMarkdownParser ( ) ; $ text = $ MarkdownParser -> parse ( $ text ) ; $ text = static :: emailToLink ( $ text ) ; $ text = str_replace ( '<p>h' , '<p> h' , $ text ) ; $ text = static :: urlToLink ( $ text ) ; return $ text ; }
Process text in markdown mode .
48,150
public static function closeOpenTags ( $ html ) { preg_match_all ( "#<([a-z]+)( .*)?(?!/)>#iU" , $ html , $ result ) ; $ openedTags = $ result [ 1 ] ; preg_match_all ( "#</([a-z]+)>#iU" , $ html , $ result ) ; $ closedTags = $ result [ 1 ] ; $ lenOpened = count ( $ openedTags ) ; if ( count ( $ closedTags ) == $ lenOpened ) { return $ html ; } $ openedTags = array_reverse ( $ openedTags ) ; for ( $ i = 0 ; $ i < $ lenOpened ; $ i ++ ) { if ( ! in_array ( $ openedTags [ $ i ] , $ closedTags ) ) { $ html .= '</' . $ openedTags [ $ i ] . '>' ; } else { unset ( $ closedTags [ array_search ( $ openedTags [ $ i ] , $ closedTags ) ] ) ; } } return $ html ; }
Attempts to close any unclosed HTML tag .
48,151
public static function emailToLink ( $ text ) { preg_match_all ( "/([\\\a-z0-9_\-\.]+)@([a-z0-9-]{1,64})\.([a-z]{2,10})/iu" , $ text , $ emails ) ; foreach ( $ emails [ 0 ] as $ email ) { $ email = trim ( $ email ) ; if ( $ email [ 0 ] == '\\' ) { $ text = str_replace ( $ email , mb_substr ( $ email , 1 ) , $ text ) ; } else { $ text = str_replace ( $ email , static :: emailObfuscator ( $ email ) , $ text ) ; } } return $ text ; }
Convert any email to a mailto link .
48,152
public static function emailObfuscator ( $ email ) { $ link = str_rot13 ( '<a href="mailto:' . $ email . '" rel="nofollow">' . $ email . '</a>' ) ; $ out = '<script type="text/javascript">' . "\n" ; $ out .= ' document.write(\'' . $ link . '\'.replace(/[a-zA-Z]/g, function(c) {' . "\n" ; $ out .= ' return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);' . "\n" ; $ out .= ' }));' . "\n" ; $ out .= '</script>' . "\n" ; $ out .= '<noscript>[' . __d ( 'field' , 'Turn on JavaScript to see the email address.' ) . ']</noscript>' . "\n" ; return $ out ; }
Protects email address so bots can not read it .
48,153
public static function trimmer ( $ text , $ len = false , $ ellipsis = ' ...' ) { if ( ! preg_match ( '/[0-9]+/i' , $ len ) ) { $ parts = explode ( $ len , $ text ) ; return static :: closeOpenTags ( $ parts [ 0 ] ) ; } $ len = $ len === false || ! is_numeric ( $ len ) || $ len <= 0 ? 600 : $ len ; $ text = static :: filterText ( $ text ) ; $ textLen = mb_strlen ( $ text ) ; if ( $ textLen > $ len ) { return mb_substr ( $ text , 0 , $ len ) . $ ellipsis ; } return $ text ; }
Safely trim a text .
48,154
public function update ( $ name , $ value , $ autoload = null , $ callbacks = true ) { $ option = $ this -> find ( ) -> where ( [ 'name' => $ name ] ) -> first ( ) ; if ( ! $ option ) { return null ; } if ( $ callbacks ) { $ option -> set ( 'value' , $ value ) ; if ( $ autoload !== null ) { $ option -> set ( 'autoload' , $ autoload ) ; } return $ this -> save ( $ option , [ 'callbacks' => false ] ) ; } return $ this -> updateAll ( [ 'value' => $ value ] , [ 'name' => $ name ] ) ; }
Updates the given option .
48,155
public function render ( Entity $ entity ) { if ( ! isset ( $ this -> _View -> viewVars [ '__commentComponentLoaded__' ] ) ) { throw new InternalErrorException ( __d ( 'comment' , 'Illegal usage of \Comment\View\Helper\CommentHelper.' ) ) ; } $ this -> config ( 'entity' , $ entity ) ; $ event = $ this -> trigger ( [ 'CommentHelper.beforeRender' , $ this -> _View ] ) ; if ( $ event -> isStopped ( ) ) { return $ event -> result ; } $ out = '' ; if ( $ this -> config ( 'visibility' ) > 0 ) { $ out .= $ this -> _View -> element ( 'Comment.render_comments_list' ) ; if ( $ this -> config ( 'visibility' ) === 1 ) { $ out .= $ this -> _View -> element ( 'Comment.render_comments_form' ) ; } } $ event = $ this -> trigger ( [ 'CommentHelper.afterRender' , $ this -> _View ] , $ out ) ; if ( $ event -> isStopped ( ) ) { return $ event -> result ; } return $ out ; }
Renders a comments section for given entity .
48,156
public function optionsForInput ( $ input ) { $ options = [ 'author_name' => [ 'label' => ( $ this -> config ( 'anonymous_name_required' ) ? __d ( 'comment' , 'Name (required)' ) : __d ( 'comment' , 'Name' ) ) ] , 'author_email' => [ 'label' => ( $ this -> config ( 'anonymous_email_required' ) ? __d ( 'comment' , 'e-Mail (required)' ) : __d ( 'comment' , 'e-Mail' ) ) ] , 'author_web' => [ 'label' => ( $ this -> config ( 'anonymous_web_required' ) ? __d ( 'comment' , 'Website (required)' ) : __d ( 'comment' , 'Website' ) ) ] , 'subject' => [ 'label' => __d ( 'comment' , 'Subject (required)' ) , 'required' , ] , 'body' => [ 'type' => 'textarea' , 'label' => __d ( 'comment' , 'Message (required)' ) , 'required' , ] , ] ; if ( isset ( $ options [ $ input ] ) ) { if ( in_array ( $ input , [ 'author_name' , 'author_email' , 'author_web' ] ) && $ this -> config ( $ input . '_required' ) ) { $ options [ $ input ] [ 'required' ] = 'required' ; } return $ options [ $ input ] ; } return [ ] ; }
Shortcut for generate form - input s options .
48,157
public function remove ( $ path ) { $ contents = $ this -> Acos -> node ( $ path ) ; if ( ! $ contents ) { return false ; } $ content = $ contents -> first ( ) ; $ this -> Acos -> removeFromTree ( $ content ) ; $ this -> Acos -> delete ( $ content ) ; return true ; }
Removes the given ACO and its permissions .
48,158
public static function buildAcos ( $ for = null , $ sync = false ) { if ( function_exists ( 'ini_set' ) ) { ini_set ( 'max_execution_time' , 300 ) ; } elseif ( function_exists ( 'set_time_limit' ) ) { set_time_limit ( 300 ) ; } if ( $ for === null ) { $ plugins = plugin ( ) -> toArray ( ) ; } else { try { $ plugins = [ plugin ( $ for ) ] ; } catch ( \ Exception $ e ) { return false ; } } $ added = [ ] ; foreach ( $ plugins as $ plugin ) { if ( ! Plugin :: exists ( $ plugin -> name ) ) { continue ; } $ aco = new AcoManager ( $ plugin -> name ) ; $ controllerDir = normalizePath ( "{$plugin->path}/src/Controller/" ) ; $ folder = new Folder ( $ controllerDir ) ; $ controllers = $ folder -> findRecursive ( '.*Controller\.php' ) ; foreach ( $ controllers as $ controller ) { $ controller = str_replace ( [ $ controllerDir , '.php' ] , '' , $ controller ) ; $ className = $ plugin -> name . '\\' . 'Controller\\' . str_replace ( DS , '\\' , $ controller ) ; $ methods = static :: _controllerMethods ( $ className ) ; if ( ! empty ( $ methods ) ) { $ path = explode ( 'Controller\\' , $ className ) [ 1 ] ; $ path = str_replace_last ( 'Controller' , '' , $ path ) ; $ path = str_replace ( '\\' , '/' , $ path ) ; foreach ( $ methods as $ method ) { if ( $ aco -> add ( "{$path}/{$method}" ) ) { $ added [ ] = "{$plugin->name}/{$path}/{$method}" ; } } } } } if ( $ sync && isset ( $ aco ) ) { $ aco -> Acos -> recover ( ) ; $ existingPaths = static :: paths ( $ for ) ; foreach ( $ existingPaths as $ exists ) { if ( ! in_array ( $ exists , $ added ) ) { $ aco -> remove ( $ exists ) ; } } $ validLeafs = $ aco -> Acos -> find ( ) -> select ( [ 'id' ] ) -> where ( [ 'id NOT IN' => $ aco -> Acos -> find ( ) -> select ( [ 'parent_id' ] ) -> where ( [ 'parent_id IS NOT' => null ] ) ] ) ; $ aco -> Acos -> Permissions -> deleteAll ( [ 'aco_id NOT IN' => $ validLeafs ] ) ; } return true ; }
This method should never be used unless you know what are you doing .
48,159
public static function paths ( $ for = null ) { if ( $ for !== null ) { try { $ for = plugin ( $ for ) -> name ; } catch ( \ Exception $ e ) { return [ ] ; } } $ cacheKey = "paths({$for})" ; $ paths = static :: cache ( $ cacheKey ) ; if ( $ paths === null ) { $ paths = [ ] ; $ aco = new AcoManager ( '__dummy__' ) ; $ aco -> loadModel ( 'User.Acos' ) ; $ leafs = $ aco -> Acos -> find ( 'all' ) -> select ( [ 'id' ] ) -> where ( [ 'Acos.id NOT IN' => $ aco -> Acos -> find ( ) -> select ( [ 'parent_id' ] ) -> where ( [ 'parent_id IS NOT' => null ] ) ] ) ; foreach ( $ leafs as $ leaf ) { $ path = $ aco -> Acos -> find ( 'path' , [ 'for' => $ leaf -> id ] ) -> extract ( 'alias' ) -> toArray ( ) ; $ path = implode ( '/' , $ path ) ; if ( $ for === null || ( $ for !== null && str_starts_with ( $ path , "{$for}/" ) ) ) { $ paths [ ] = $ path ; } } static :: cache ( $ cacheKey , $ paths ) ; } return $ paths ; }
Gets a list of existing ACO paths for the given plugin or the entire list if no plugin is given .
48,160
protected static function _controllerMethods ( $ className ) { if ( ! class_exists ( $ className ) ) { return [ ] ; } $ methods = ( array ) get_this_class_methods ( $ className ) ; $ actions = [ ] ; foreach ( $ methods as $ methodName ) { try { $ method = new ReflectionMethod ( $ className , $ methodName ) ; if ( $ method -> isPublic ( ) ) { $ actions [ ] = $ methodName ; } } catch ( \ ReflectionException $ e ) { } } return $ actions ; }
Extracts method names of the given controller class .
48,161
protected function _parseAco ( $ aco , $ string = true ) { $ aco = preg_replace ( '/\/{2,}/' , '/' , trim ( $ aco , '/' ) ) ; $ parts = explode ( '/' , $ aco ) ; if ( empty ( $ parts ) ) { return false ; } if ( count ( $ parts ) === 1 ) { $ controller = Inflector :: camelize ( $ parts [ 0 ] ) ; return [ 'prefix' => '' , 'controller' => $ controller , 'action' => 'index' , ] ; } $ prefixes = $ this -> _routerPrefixes ( ) ; $ prefix = Inflector :: camelize ( $ parts [ 0 ] ) ; if ( ! in_array ( $ prefix , $ prefixes ) ) { $ prefix = '' ; } else { array_shift ( $ parts ) ; } if ( count ( $ parts ) == 2 ) { list ( $ controller , $ action ) = $ parts ; } else { $ controller = array_shift ( $ parts ) ; $ action = 'index' ; } $ plugin = $ this -> _pluginName ; $ result = compact ( 'plugin' , 'prefix' , 'controller' , 'action' ) ; if ( $ string ) { $ result = implode ( '/' , array_values ( $ result ) ) ; $ result = str_replace ( '//' , '/' , $ result ) ; } return $ result ; }
Sanitizes the given ACO path .
48,162
protected function _routerPrefixes ( ) { $ cache = static :: cache ( '_routerPrefixes' ) ; if ( ! $ cache ) { $ prefixes = [ ] ; foreach ( Router :: routes ( ) as $ route ) { if ( empty ( $ route -> defaults [ 'prefix' ] ) ) { continue ; } else { $ prefix = Inflector :: camelize ( $ route -> defaults [ 'prefix' ] ) ; if ( ! in_array ( $ prefix , $ prefixes ) ) { $ prefixes [ ] = $ prefix ; } } } $ cache = static :: cache ( '_routerPrefixes' , $ prefixes ) ; } return $ cache ; }
Gets a CamelizedList of all existing router prefixes .
48,163
public function permissions ( ) { if ( is_array ( $ this -> _permissions ) ) { return $ this -> _permissions ; } $ out = [ ] ; $ acosTable = TableRegistry :: get ( 'User.Acos' ) ; $ permissions = $ acosTable -> Permissions -> find ( ) -> where ( [ 'Acos.plugin' => $ this -> name ] ) -> contain ( [ 'Acos' , 'Roles' ] ) -> all ( ) ; foreach ( $ permissions as $ permission ) { if ( ! isset ( $ out [ $ permission -> role -> slug ] ) ) { $ out [ $ permission -> role -> slug ] = [ ] ; } $ out [ $ permission -> role -> slug ] [ ] = implode ( '/' , $ acosTable -> find ( 'path' , [ 'for' => $ permission -> aco -> id ] ) -> extract ( 'alias' ) -> toArray ( ) ) ; } $ this -> _permissions = $ out ; return $ out ; }
Gets plugin s permissions tree .
48,164
public function & info ( $ key = null ) { $ plugin = $ this -> name ( ) ; if ( empty ( $ this -> _info ) ) { $ this -> _info = ( array ) quickapps ( "plugins.{$plugin}" ) ; } $ parts = explode ( '.' , $ key ) ; $ getComposer = in_array ( 'composer' , $ parts ) || $ key === null ; $ getSettings = in_array ( 'settings' , $ parts ) || $ key === null ; $ getPermissions = in_array ( 'permissions' , $ parts ) || $ key === null ; if ( $ getComposer && ! isset ( $ this -> _info [ 'composer' ] ) ) { $ this -> _info [ 'composer' ] = $ this -> composer ( ) ; } if ( $ getSettings && ! isset ( $ this -> _info [ 'settings' ] ) ) { $ this -> _info [ 'settings' ] = ( array ) $ this -> settings ( ) ; } if ( $ getPermissions && ! isset ( $ this -> _info [ 'permissions' ] ) ) { $ this -> _info [ 'permissions' ] = ( array ) $ this -> permissions ( ) ; } if ( $ key === null ) { return $ this -> _info ; } return $ this -> _getKey ( $ parts ) ; }
Gets information for this plugin .
48,165
protected function & _getKey ( $ key ) { $ default = null ; $ parts = is_string ( $ key ) ? explode ( '.' , $ key ) : $ key ; switch ( count ( $ parts ) ) { case 1 : if ( isset ( $ this -> _info [ $ parts [ 0 ] ] ) ) { return $ this -> _info [ $ parts [ 0 ] ] ; } return $ default ; case 2 : if ( isset ( $ this -> _info [ $ parts [ 0 ] ] [ $ parts [ 1 ] ] ) ) { return $ this -> _info [ $ parts [ 0 ] ] [ $ parts [ 1 ] ] ; } return $ default ; case 3 : if ( isset ( $ this -> _info [ $ parts [ 0 ] ] [ $ parts [ 1 ] ] [ $ parts [ 2 ] ] ) ) { return $ this -> _info [ $ parts [ 0 ] ] [ $ parts [ 1 ] ] [ $ parts [ 2 ] ] ; } return $ default ; case 4 : if ( isset ( $ this -> _info [ $ parts [ 0 ] ] [ $ parts [ 1 ] ] [ $ parts [ 2 ] ] [ $ parts [ 3 ] ] ) ) { return $ this -> _info [ $ parts [ 0 ] ] [ $ parts [ 1 ] ] [ $ parts [ 2 ] ] [ $ parts [ 3 ] ] ; } return $ default ; default : $ data = $ this -> _info ; foreach ( $ parts as $ key ) { if ( is_array ( $ data ) && isset ( $ data [ $ key ] ) ) { $ data = $ data [ $ key ] ; } else { return $ default ; } } } return $ data ; }
Gets info value for the given key .
48,166
public function settings ( $ key = null ) { $ plugin = $ this -> name ( ) ; if ( $ cache = $ this -> config ( 'settings' ) ) { if ( $ key !== null ) { $ cache = isset ( $ cache [ $ key ] ) ? $ cache [ $ key ] : null ; } return $ cache ; } $ pluginsTable = TableRegistry :: get ( 'System.Plugins' ) ; $ settings = [ ] ; $ dbInfo = $ pluginsTable -> find ( ) -> cache ( "{$plugin}_settings" , 'plugins' ) -> select ( [ 'name' , 'settings' ] ) -> where ( [ 'name' => $ plugin ] ) -> limit ( 1 ) -> first ( ) ; if ( $ dbInfo ) { $ settings = ( array ) $ dbInfo -> settings ; } if ( empty ( $ settings ) ) { $ settings = ( array ) $ pluginsTable -> trigger ( "Plugin.{$plugin}.settingsDefaults" ) -> result ; } $ this -> config ( 'settings' , $ settings ) ; if ( $ key !== null ) { $ settings = isset ( $ settings [ $ key ] ) ? $ settings [ $ key ] : null ; } return $ settings ; }
Gets settings from DB for this plugin . Or reads a single settings key value .
48,167
public function requiredBy ( ) { if ( $ cache = $ this -> config ( 'required_by' ) ) { return collection ( $ cache ) ; } Plugin :: dropCache ( ) ; $ out = [ ] ; $ plugins = Plugin :: get ( ) -> filter ( function ( $ v , $ k ) { return $ v -> name ( ) !== $ this -> name ( ) ; } ) ; foreach ( $ plugins as $ plugin ) { if ( $ dependencies = $ plugin -> dependencies ( $ plugin -> name ) ) { $ packages = array_map ( function ( $ item ) { list ( , $ package ) = packageSplit ( $ item , true ) ; return strtolower ( $ package ) ; } , array_keys ( $ dependencies ) ) ; if ( in_array ( strtolower ( $ this -> name ( ) ) , $ packages ) ) { $ out [ ] = $ plugin ; } } } $ this -> config ( 'required_by' , $ out ) ; return collection ( $ out ) ; }
Gets a collection list of plugin that depends on this plugin .
48,168
public function requestPath ( Request $ request , $ path = '/:plugin/:prefix/:controller/:action' ) { $ plugin = empty ( $ request [ 'plugin' ] ) ? null : Inflector :: camelize ( $ request [ 'plugin' ] ) . '/' ; $ prefix = empty ( $ request -> params [ 'prefix' ] ) ? '' : Inflector :: camelize ( $ request -> params [ 'prefix' ] ) . '/' ; $ path = str_replace ( [ ':controller' , ':action' , ':plugin/' , ':prefix/' ] , [ Inflector :: camelize ( $ request [ 'controller' ] ) , $ request [ 'action' ] , $ plugin , $ prefix ] , $ path ) ; $ path = str_replace ( '//' , '/' , $ path ) ; return trim ( $ path , '/' ) ; }
Gets an ACO path for current request .
48,169
public function index ( ) { $ this -> loadModel ( 'Content.Contents' ) ; $ this -> Contents -> CreatedBy -> fieldable ( false ) ; $ this -> Contents -> ModifiedBy -> fieldable ( false ) ; $ contents = $ this -> Contents -> find ( 'all' , [ 'fieldable' => false ] ) -> contain ( [ 'ContentTypes' , 'CreatedBy' , 'ModifiedBy' ] ) ; if ( ! empty ( $ this -> request -> query [ 'filter' ] ) && $ contents instanceof Query ) { $ this -> Contents -> search ( $ this -> request -> query [ 'filter' ] , $ contents ) ; } $ this -> title ( __d ( 'content' , 'Contents List' ) ) ; $ this -> set ( 'contents' , $ this -> paginate ( $ contents ) ) ; $ this -> Breadcrumb -> push ( '/admin/content/manage' ) ; }
Shows a list of all the contents .
48,170
public function create ( ) { $ this -> loadModel ( 'Content.ContentTypes' ) ; $ types = $ this -> ContentTypes -> find ( ) -> select ( [ 'id' , 'slug' , 'name' , 'description' ] ) -> all ( ) ; $ this -> title ( __d ( 'content' , 'Create New Content' ) ) ; $ this -> set ( 'types' , $ types ) ; $ this -> Breadcrumb -> push ( '/admin/content/manage' ) -> push ( __d ( 'content' , 'Create new content' ) , '' ) ; }
Content - type selection screen .
48,171
public function add ( $ typeSlug ) { $ this -> loadModel ( 'Content.ContentTypes' ) ; $ this -> loadModel ( 'Content.Contents' ) ; $ this -> Contents -> unbindComments ( ) ; $ type = $ this -> ContentTypes -> find ( ) -> where ( [ 'slug' => $ typeSlug ] ) -> limit ( 1 ) -> first ( ) ; if ( ! $ type ) { throw new ContentTypeNotFoundException ( __d ( 'content' , 'The specified content type ({0}) does not exists.' , $ type ) ) ; } if ( ! $ type -> userAllowed ( 'create' ) ) { throw new ContentCreateException ( __d ( 'content' , 'You are not allowed to create contents of this type ({0}).' , $ type -> name ) ) ; } if ( $ this -> request -> data ( ) ) { $ data = $ this -> request -> data ( ) ; $ data [ 'content_type_slug' ] = $ type -> slug ; $ data [ 'content_type_id' ] = $ type -> id ; $ content = $ this -> Contents -> newEntity ( $ data ) ; if ( $ this -> Contents -> save ( $ content ) ) { if ( ! $ type -> userAllowed ( 'publish' ) ) { $ this -> Flash -> warning ( __d ( 'content' , 'Content created, but awaiting moderation before publishing it.' ) ) ; } else { $ this -> Flash -> success ( __d ( 'content' , 'Content created!.' ) ) ; } $ this -> redirect ( [ 'plugin' => 'Content' , 'controller' => 'manage' , 'action' => 'edit' , 'prefix' => 'admin' , $ content -> id ] ) ; } else { $ this -> Flash -> danger ( __d ( 'content' , 'Something went wrong, please check your information.' ) ) ; } } else { $ content = $ this -> Contents -> newEntity ( [ 'content_type_slug' => $ type -> slug ] ) ; $ content -> setDefaults ( $ type ) ; } $ content -> set ( 'content_type' , $ type ) ; $ content = $ this -> Contents -> attachFields ( $ content ) ; $ languages = LocaleToolbox :: languagesList ( ) ; $ roles = $ this -> Contents -> Roles -> find ( 'list' ) ; $ this -> title ( __d ( 'content' , 'Create New Content <small>({0})</small>' , $ type -> slug ) ) ; $ this -> set ( compact ( 'content' , 'type' , 'languages' , 'roles' ) ) ; $ this -> Breadcrumb -> push ( '/admin/content/manage' ) -> push ( __d ( 'content' , 'Create new content' ) , [ 'plugin' => 'Content' , 'controller' => 'manage' , 'action' => 'create' ] ) -> push ( $ type -> name , '' ) ; }
Shows the new content form .
48,172
public function delete ( $ contentId ) { $ this -> loadModel ( 'Content.Contents' ) ; $ content = $ this -> Contents -> get ( $ contentId , [ 'contain' => [ 'ContentTypes' ] ] ) ; if ( ! $ content || empty ( $ content -> content_type ) ) { throw new ContentNotFoundException ( __d ( 'content' , 'The requested page was not found.' ) ) ; } if ( ! $ content -> content_type -> userAllowed ( 'translate' ) ) { throw new ContentDeleteException ( __d ( 'content' , 'You are not allowed to delete contents of this type ({0}).' , $ content -> content_type -> name ) ) ; } if ( $ this -> Contents -> delete ( $ content , [ 'atomic' => true ] ) ) { $ this -> Flash -> success ( __d ( 'content' , 'Content was successfully removed!' ) ) ; } else { $ this -> Flash -> danger ( __d ( 'content' , 'Unable to remove this content, please try again.' ) ) ; } $ this -> title ( __d ( 'content' , 'Delete Content' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Deletes the given content by ID .
48,173
public function deleteRevision ( $ contentId , $ revisionId ) { $ this -> loadModel ( 'Content.ContentRevisions' ) ; $ revision = $ this -> ContentRevisions -> find ( ) -> where ( [ 'id' => $ revisionId , 'content_id' => $ contentId ] ) -> first ( ) ; if ( $ this -> ContentRevisions -> delete ( $ revision , [ 'atomic' => true ] ) ) { $ this -> Flash -> success ( __d ( 'content' , 'Revision was successfully removed!' ) ) ; } else { $ this -> Flash -> danger ( __d ( 'content' , 'Unable to remove this revision, please try again.' ) ) ; } $ this -> title ( __d ( 'content' , 'Editing Content Revision' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Removes the given revision of the given content .
48,174
public function isKeyValid ( ) { $ response = $ this -> sendRequest ( 'key=' . $ this -> wordPressAPIKey . '&blog=' . $ this -> blogURL , $ this -> akismetServer , '/' . $ this -> akismetVersion . '/verify-key' ) ; return $ response [ 1 ] == 'valid' ; }
Makes a request to the Akismet service to see if the API key passed to the constructor is valid .
48,175
public function send ( ) { $ this -> response = '' ; $ fs = fsockopen ( $ this -> host , $ this -> port , $ this -> errorNumber , $ this -> errorString , 3 ) ; if ( $ this -> errorNumber != 0 ) { throw new Exception ( 'Error connecting to host: ' . $ this -> host . ' Error number: ' . $ this -> errorNumber . ' Error message: ' . $ this -> errorString ) ; } if ( $ fs !== false ) { @ fwrite ( $ fs , $ this -> request ) ; while ( ! feof ( $ fs ) ) { $ this -> response .= fgets ( $ fs , $ this -> responseLength ) ; } fclose ( $ fs ) ; } }
Sends the data to the remote host .
48,176
public function add ( ) { $ this -> loadModel ( 'Content.ContentTypes' ) ; $ this -> loadModel ( 'User.Roles' ) ; $ type = $ this -> ContentTypes -> newEntity ( ) ; if ( $ this -> request -> data ( ) ) { $ type = $ this -> ContentTypes -> patchEntity ( $ type , $ this -> request -> data ( ) ) ; $ errors = $ type -> errors ( ) ; $ success = empty ( $ errors ) ; if ( $ success ) { $ success = $ this -> ContentTypes -> save ( $ type ) ; if ( $ success ) { $ this -> Flash -> success ( __d ( 'content' , 'Content type created, now attach some fields.' ) ) ; $ this -> redirect ( [ 'plugin' => 'Content' , 'controller' => 'fields' , 'type' => $ type -> slug ] ) ; } } if ( ! $ success ) { $ this -> Flash -> danger ( __d ( 'content' , 'Content type could not be created, check your information.' ) ) ; } } $ roles = $ this -> Roles -> find ( 'list' ) ; $ this -> title ( __d ( 'content' , 'Define New Content Type' ) ) ; $ this -> set ( compact ( 'type' , 'roles' ) ) ; $ this -> set ( 'languages' , LocaleToolbox :: languagesList ( ) ) ; $ this -> Breadcrumb -> push ( '/admin/content/manage' ) -> push ( __d ( 'content' , 'Content Types' ) , '/admin/content/types' ) -> push ( __d ( 'content' , 'Creating Content Type' ) , '#' ) ; }
Create new content type .
48,177
public function edit ( $ slug ) { $ this -> loadModel ( 'Content.ContentTypes' ) ; $ this -> loadModel ( 'User.Roles' ) ; $ type = $ this -> ContentTypes -> find ( ) -> where ( [ 'slug' => $ slug ] ) -> first ( ) ; if ( ! $ type ) { throw new NotFoundException ( __d ( 'content' , 'Content type was not found!' ) ) ; } if ( $ this -> request -> data ( ) ) { $ type -> accessible ( [ 'id' , 'slug' ] , false ) ; $ data = $ this -> request -> data ( ) ; $ type = $ this -> ContentTypes -> patchEntity ( $ type , $ data ) ; if ( $ this -> ContentTypes -> save ( $ type , [ 'associated' => [ 'Roles' ] ] ) ) { $ this -> Flash -> success ( __d ( 'content' , 'Content type updated!' ) ) ; $ this -> redirect ( [ 'plugin' => 'Content' , 'controller' => 'types' , 'action' => 'edit' , $ type -> slug ] ) ; } else { $ this -> Flash -> danger ( __d ( 'content' , 'Content type could not be updated, check your information.' ) ) ; } } else { $ this -> request -> data = $ type -> toArray ( ) ; } $ roles = $ this -> Roles -> find ( 'list' ) ; $ this -> title ( __d ( 'content' , 'Configure Content Type' ) ) ; $ this -> set ( compact ( 'type' , 'roles' ) ) ; $ this -> set ( 'languages' , LocaleToolbox :: languagesList ( ) ) ; $ this -> Breadcrumb -> push ( '/admin/content/manage' ) -> push ( __d ( 'content' , 'Content Types' ) , '/admin/content/types' ) -> push ( __d ( 'content' , 'Editing "{0}" Content Type' , $ type -> name ) , '' ) ; }
Edit content type settings .
48,178
public function delete ( $ slug ) { $ this -> loadModel ( 'Content.ContentTypes' ) ; $ type = $ this -> ContentTypes -> find ( ) -> where ( [ 'slug' => $ slug ] ) -> first ( ) ; if ( ! $ type ) { throw new NotFoundException ( __d ( 'content' , 'Content type was not found!' ) ) ; } if ( $ this -> ContentTypes -> delete ( $ type ) ) { $ this -> Flash -> success ( __d ( 'content' , 'Content was deleted!' ) ) ; } else { $ $ this -> Flash -> danger ( __d ( 'content' , 'Content type could not be deleted, please try again.' ) ) ; } $ this -> title ( __d ( 'content' , 'Delete Content Type' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Remove content type .
48,179
public function blocks ( Collection $ blocks = null ) { if ( $ blocks ) { $ this -> _blocks = $ blocks ; $ this -> homogenize ( ) ; } elseif ( $ this -> _blocks === null ) { $ this -> _prepareBlocks ( ) ; } return $ this -> _blocks ; }
Gets or sets the block collection of this region .
48,180
public function blockLimit ( $ number = null ) { $ number = $ number !== null ? intval ( $ number ) : $ number ; $ this -> _blockLimit = $ number ; return $ this ; }
Limits the number of blocks in this region .
48,181
public function merge ( Region $ region , $ homogenize = true ) { if ( $ region -> name ( ) !== $ this -> name ( ) ) { $ blocks1 = $ this -> blocks ( ) ; $ blocks2 = $ region -> blocks ( ) ; $ combined = $ blocks1 -> append ( $ blocks2 ) -> toArray ( false ) ; $ this -> blocks ( collection ( $ combined ) ) ; if ( $ homogenize ) { $ this -> homogenize ( ) ; } } return $ this ; }
Merge blocks from another region .
48,182
public function homogenize ( ) { $ this -> _blocks = $ this -> blocks ( ) -> map ( function ( $ block ) { $ block -> region -> set ( 'region' , $ this -> _machineName ) ; return $ block ; } ) ; return $ this ; }
Makes sure that every block in this region is actually marked as it belongs to this region .
48,183
public function render ( ) { $ html = '' ; $ i = 0 ; foreach ( $ this -> blocks ( ) as $ block ) { if ( $ this -> _blockLimit !== null && $ i === $ this -> _blockLimit ) { break ; } $ html .= $ block -> render ( $ this -> _View ) ; $ i ++ ; } return $ html ; }
Render all the blocks within this region .
48,184
protected function _prepareBlocks ( ) { $ cacheKey = "{$this->_View->theme}_{$this->_machineName}" ; $ blocks = TableRegistry :: get ( 'Block.Blocks' ) -> find ( 'all' ) -> cache ( $ cacheKey , 'blocks' ) -> contain ( [ 'Roles' , 'BlockRegions' ] ) -> matching ( 'BlockRegions' , function ( $ q ) { return $ q -> where ( [ 'BlockRegions.theme' => $ this -> _View -> theme ( ) , 'BlockRegions.region' => $ this -> _machineName , ] ) ; } ) -> where ( [ 'Blocks.status' => 1 ] ) -> order ( [ 'BlockRegions.ordering' => 'ASC' ] ) ; $ blocks -> sortBy ( function ( $ block ) { return $ block -> region -> ordering ; } , SORT_ASC ) ; $ blocks = $ blocks -> filter ( function ( $ block ) { return $ this -> _filterBlock ( $ block ) && $ block -> renderable ( ) ; } ) ; $ this -> blocks ( $ blocks ) ; }
Fetches all block entities that could be rendered within this region .
48,185
protected function _filterBlock ( Block $ block ) { $ cacheKey = "allowed_{$block->id}" ; $ cache = static :: cache ( $ cacheKey ) ; if ( $ cache !== null ) { return $ cache ; } if ( ! empty ( $ block -> locale ) && ! in_array ( I18n :: locale ( ) , ( array ) $ block -> locale ) ) { return static :: cache ( $ cacheKey , false ) ; } if ( ! $ block -> isAccessibleByUser ( ) ) { return static :: cache ( $ cacheKey , false ) ; } $ allowed = false ; switch ( $ block -> visibility ) { case 'except' : $ allowed = ! $ this -> _urlMatch ( $ block -> pages ) ; break ; case 'only' : $ allowed = $ this -> _urlMatch ( $ block -> pages ) ; break ; case 'php' : $ allowed = php_eval ( $ block -> pages , [ 'view' => & $ this -> _View , 'block' => & $ block ] ) === true ; break ; } if ( ! $ allowed ) { return static :: cache ( $ cacheKey , false ) ; } return static :: cache ( $ cacheKey , true ) ; }
Checks if the given block can be rendered .
48,186
protected function _urlMatch ( $ patterns ) { if ( empty ( $ patterns ) ) { return false ; } $ url = urldecode ( $ this -> _View -> request -> url ) ; $ path = str_starts_with ( $ url , '/' ) ? str_replace_once ( '/' , '' , $ url ) : $ url ; if ( option ( 'url_locale_prefix' ) ) { $ patterns = explode ( "\n" , $ patterns ) ; $ locales = array_keys ( quickapps ( 'languages' ) ) ; $ localesPattern = '(' . implode ( '|' , array_map ( 'preg_quote' , $ locales ) ) . ')' ; foreach ( $ patterns as & $ p ) { if ( ! preg_match ( "/^{$localesPattern}\//" , $ p ) ) { $ p = I18n :: locale ( ) . '/' . $ p ; $ p = str_replace ( '//' , '/' , $ p ) ; } } $ patterns = implode ( "\n" , $ patterns ) ; } $ toReplace = [ '/(\r\n?|\n)/' , '/\\\\\*/' , '/(^|\|)\/($|\|)/' ] ; $ replacements = [ '|' , '.*' , '\1' . preg_quote ( $ this -> _View -> Url -> build ( '/' ) , '/' ) . '\2' ] ; $ patternsQuoted = preg_quote ( $ patterns , '/' ) ; $ patterns = '/^(' . preg_replace ( $ toReplace , $ replacements , $ patternsQuoted ) . ')$/' ; return ( bool ) preg_match ( $ patterns , $ path ) ; }
Check if a current URL matches any pattern in a set of patterns .
48,187
public function afterSave ( Event $ event , BlockRegion $ blockRegion , ArrayObject $ options = null ) { $ this -> clearCache ( ) ; }
Clears blocks cache after assignment changes .
48,188
protected function _getLib ( ) { require_once Plugin :: classPath ( 'Captcha' ) . 'Lib/ayah.php' ; return new \ AYAH ( [ 'publisher_key' => $ this -> config ( 'publisherKey' ) , 'scoring_key' => $ this -> config ( 'scoringKey' ) , 'web_service_host' => 'ws.areyouahuman.com' , 'use_curl' => true , 'debug_mode' => Configure :: read ( 'debug' ) , ] ) ; }
Gets an instance of AYAH library .
48,189
public function afterSave ( Event $ event , Menu $ menu , ArrayObject $ options = null ) { if ( $ menu -> isNew ( ) ) { $ block = TableRegistry :: get ( 'Block.Blocks' ) -> newEntity ( [ 'title' => $ menu -> title . ' ' . __d ( 'menu' , '[menu: {0}]' , $ menu -> id ) , 'handler' => 'Menu\Widget\MenuWidget' , 'description' => ( ! empty ( $ menu -> description ) ? $ menu -> description : __d ( 'menu' , 'Associated block for "{0}" menu.' , $ menu -> title ) ) , 'visibility' => 'except' , 'pages' => null , 'locale' => null , 'status' => 0 , 'settings' => [ 'menu_id' => $ menu -> id ] ] , [ 'validate' => false ] ) ; TableRegistry :: get ( 'Block.Blocks' ) -> save ( $ block ) ; } $ this -> clearCache ( ) ; }
Triggered after menu was persisted in DB .
48,190
public function afterDelete ( Event $ event , Menu $ menu , ArrayObject $ options = null ) { $ blocks = TableRegistry :: get ( 'Block.Blocks' ) -> find ( 'all' ) -> select ( [ 'id' , 'handler' , 'settings' ] ) -> where ( [ 'handler' => 'Menu\Widget\MenuWidget' ] ) ; foreach ( $ blocks as $ block ) { if ( ! empty ( $ menu -> settings [ 'menu_id' ] ) && $ menu -> settings [ 'menu_id' ] == $ menu -> id ) { TableRegistry :: get ( 'Block.Blocks' ) -> delete ( $ block ) ; return ; } } $ this -> clearCache ( ) ; }
Triggered after menu was removed from DB .
48,191
protected function _mockValidator ( ) { $ validator = new Validator ( ) ; return $ validator -> requirePresence ( 'site_title' ) -> add ( 'site_title' , 'length' , [ 'rule' => [ 'minLength' , 3 ] , 'message' => __d ( 'system' , "Site's name must be at least 3 characters long." ) , ] ) -> requirePresence ( 'site_email' ) -> add ( 'site_email' , 'validEmail' , [ 'rule' => 'email' , 'message' => __d ( 'system' , 'Invalid e-Mail.' ) , ] ) ; }
Created a mock validator object used when validating options
48,192
public function forgot ( ) { if ( ! empty ( $ this -> request -> data [ 'username' ] ) ) { $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> find ( ) -> where ( [ 'Users.username' => $ this -> request -> data [ 'username' ] ] ) -> orWhere ( [ 'Users.email' => $ this -> request -> data [ 'username' ] ] ) -> first ( ) ; if ( $ user ) { $ emailSent = NotificationManager :: passwordRequest ( $ user ) -> send ( ) ; if ( $ emailSent ) { $ this -> Flash -> success ( __d ( 'user' , 'Further instructions have been sent to your e-mail address.' ) ) ; } else { $ this -> Flash -> warning ( __d ( 'user' , 'Instructions could not been sent to your e-mail address, please try again later.' ) ) ; } } else { $ this -> Flash -> danger ( __d ( 'user' , 'Sorry, "{0}" is not recognized as a user name or an e-mail address.' , $ this -> request -> data [ 'username' ] ) ) ; } } $ this -> title ( __d ( 'user' , 'Password Recovery' ) ) ; }
Starts the password recovery process .
48,193
public function cancelRequest ( ) { $ user = user ( ) ; $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> get ( $ user -> id ) ; $ emailSent = NotificationManager :: cancelRequest ( $ user ) -> send ( ) ; if ( $ emailSent ) { $ this -> Flash -> success ( __d ( 'user' , 'Further instructions have been sent to your e-mail address.' ) ) ; } else { $ this -> Flash -> warning ( __d ( 'user' , 'Instructions could not been sent to your e-mail address, please try again later.' ) ) ; } $ this -> title ( __d ( 'user' , 'Account Cancellation' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Here is where users can request to remove their accounts .
48,194
public function cancel ( $ userId , $ code ) { $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> find ( ) -> where ( [ 'id' => $ userId ] ) -> contain ( [ 'Roles' ] ) -> limit ( 1 ) -> first ( ) ; if ( in_array ( ROLE_ID_ADMINISTRATOR , $ user -> role_ids ) && $ this -> Users -> countAdministrators ( ) === 1 ) { $ this -> Flash -> warning ( __d ( 'user' , 'You are the last administrator in the system, your account cannot be canceled.' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } if ( $ user && $ code == $ user -> cancel_code ) { if ( $ this -> Users -> delete ( $ user ) ) { NotificationManager :: canceled ( $ user ) -> send ( ) ; $ this -> Flash -> success ( __d ( 'user' , 'Account successfully canceled' ) ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'Account could not be canceled due to an internal error, please try again later.' ) ) ; } } else { $ this -> Flash -> warning ( __d ( 'user' , 'Not user was found, invalid cancellation URL.' ) ) ; } $ this -> title ( __d ( 'user' , 'Account Cancellation' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Here is where user s account is actually removed .
48,195
public function activationEmail ( ) { $ this -> loadModel ( 'User.Users' ) ; $ sent = false ; if ( ! empty ( $ this -> request -> data [ 'username' ] ) ) { $ user = $ this -> Users -> find ( ) -> where ( [ 'OR' => [ 'username' => $ this -> request -> data [ 'username' ] , 'email' => $ this -> request -> data [ 'username' ] , ] , 'status' => 0 ] ) -> limit ( 1 ) -> first ( ) ; if ( $ user ) { NotificationManager :: welcome ( $ user ) -> send ( ) ; $ this -> Flash -> success ( __d ( 'user' , 'Instructions have been sent to your e-mail address.' ) , [ 'key' => 'activation_email' ] ) ; $ sent = true ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'No account was found matching the given username/email.' ) , [ 'key' => 'activation_email' ] ) ; } } $ this -> title ( __d ( 'user' , 'Activation Request' ) ) ; $ this -> set ( compact ( 'sent' ) ) ; }
Users can request to re - send activation instructions to their email address .
48,196
public function activate ( $ token = null ) { $ activated = false ; if ( $ token === null ) { $ this -> redirect ( '/' ) ; } $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> find ( ) -> select ( [ 'id' , 'name' , 'token' ] ) -> where ( [ 'status' => 0 , 'token' => $ token ] ) -> limit ( 1 ) -> first ( ) ; if ( $ user ) { if ( $ this -> Users -> updateAll ( [ 'status' => 1 ] , [ 'id' => $ user -> id ] ) ) { NotificationManager :: activated ( $ user ) -> send ( ) ; $ activated = true ; $ this -> Flash -> success ( __d ( 'user' , 'Account successfully activated.' ) , [ 'key' => 'activate' ] ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'Account could not be activated, please try again later.' ) , [ 'key' => 'activate' ] ) ; } } else { $ this -> Flash -> warning ( __d ( 'user' , 'Account not found or is already active.' ) , [ 'key' => 'activate' ] ) ; } $ this -> title ( __d ( 'user' , 'Account Activation' ) ) ; $ this -> set ( compact ( 'activated' , 'token' ) ) ; }
Activates a registered user .
48,197
public function unauthorized ( ) { $ this -> loadModel ( 'User.Users' ) ; if ( $ this -> request -> is ( 'post' ) ) { $ user = $ this -> Auth -> identify ( ) ; if ( $ user ) { $ this -> Auth -> setUser ( $ user ) ; return $ this -> redirect ( $ this -> Auth -> redirectUrl ( ) ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'Username or password is incorrect' ) ) ; } } }
Renders the unauthorized screen when an user attempts to access to a restricted area .
48,198
public function me ( ) { $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> get ( user ( ) -> id , [ 'conditions' => [ 'status' => 1 ] ] ) ; $ languages = LocaleToolbox :: languagesList ( ) ; if ( $ this -> request -> data ( ) ) { $ user -> accessible ( [ 'id' , 'username' , 'roles' , 'status' ] , false ) ; $ user = $ this -> Users -> patchEntity ( $ user , $ this -> request -> data ) ; if ( $ this -> Users -> save ( $ user ) ) { $ this -> Flash -> success ( __d ( 'user' , 'User information successfully updated!' ) , [ 'key' => 'user_profile' ] ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'User information could not be saved, please check your information.' ) , [ 'key' => 'user_profile' ] ) ; } } $ this -> title ( __d ( 'user' , 'Account' ) ) ; $ this -> set ( compact ( 'user' , 'languages' ) ) ; $ this -> viewMode ( 'full' ) ; }
Renders user s my profile form .
48,199
public function renderContent ( Event $ event , Content $ content , $ options = [ ] ) { $ View = $ event -> subject ( ) ; $ viewMode = $ View -> viewMode ( ) ; $ try = [ "Content.render_content_{$content->content_type_slug}_{$viewMode}_{$content->slug}" , "Content.render_content_{$content->content_type_slug}_{$content->slug}" , "Content.render_content_{$viewMode}_{$content->slug}" , "Content.render_content_{$content->slug}" , "Content.render_content_{$content->content_type_slug}_{$viewMode}" , "Content.render_content_{$content->content_type_slug}" , "Content.render_content_{$viewMode}" , 'Content.render_content' , ] ; foreach ( $ try as $ element ) { if ( $ View -> elementExists ( $ element ) ) { return $ View -> element ( $ element , compact ( 'content' , 'options' ) ) ; } } return '' ; }
Renders a single Content Entity .