idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
47,900 | public static function allInstanceOf ( array $ array , $ class ) { if ( ! is_string ( $ class ) ) { throw new \ InvalidArgumentException ( '$class must be a string.' ) ; } if ( ! class_exists ( $ class ) ) { throw new \ InvalidArgumentException ( "Class with name $class not found." ) ; } foreach ( $ array as $ val ) { if ( ! self :: instanceOfClass ( $ val , $ class ) ) { return false ; } } return true ; } | Checks whether every value in an array is an instance of a class . |
47,901 | public function add ( $ key , $ value , $ flag = null , $ expire = 0 ) { if ( is_null ( $ key ) ) { return false ; } try { $ set_results = MemcacheUtils :: setMultiWithPolicy ( array ( $ key => $ value ) , $ expire , SetPolicy :: ADD ) ; } catch ( Error $ e ) { return false ; } return $ set_results [ 0 ] == SetStatusCode :: STORED ; } | Adds a new item to the cache . Will fail if the key is already present in the cache . |
47,902 | public function flush ( ) { $ request = new MemcacheFlushRequest ( ) ; $ response = new MemcacheFlushResponse ( ) ; try { ApiProxy :: makeSyncCall ( 'memcache' , 'FlushAll' , $ request , $ response ) ; } catch ( Error $ e ) { return false ; } return true ; } | Removes all items from cache . |
47,903 | public function get ( $ keys , $ flags = null ) { if ( is_array ( $ keys ) ) { $ return_value = $ this -> getMulti ( $ keys , $ flags ) ; if ( empty ( $ return_value ) ) { return false ; } else { return $ return_value ; } } else { try { $ return_value = $ this -> getMulti ( array ( $ keys ) , array ( $ flags ) ) ; } catch ( Error $ e ) { return false ; } if ( array_key_exists ( $ keys , $ return_value ) ) { return $ return_value [ $ keys ] ; } else { return false ; } } } | Fetches previously stored data from the cache . |
47,904 | public function replace ( $ key , $ value , $ flag = null , $ expire = 0 ) { if ( is_null ( $ key ) ) { return false ; } try { $ set_results = MemcacheUtils :: setMultiWithPolicy ( array ( $ key => $ value ) , $ expire , SetPolicy :: REPLACE ) ; } catch ( Error $ e ) { return false ; } return $ set_results [ 0 ] == SetStatusCode :: STORED ; } | Replaces an existing item in the cache . Will fail if the key is not already present in the cache . |
47,905 | public function set ( $ key , $ value , $ flag = null , $ expire = 0 ) { if ( is_null ( $ key ) ) { return false ; } try { $ set_results = MemcacheUtils :: setMultiWithPolicy ( array ( $ key => $ value ) , $ expire , SetPolicy :: SET ) ; } catch ( Error $ e ) { return false ; } return $ set_results [ 0 ] == SetStatusCode :: STORED ; } | Sets the value of a key in the cache regardless of whether it is currently present or not . |
47,906 | public function addContent ( $ campaignId , $ contentData = [ ] , $ params = [ ] ) { $ endpoint = $ this -> endpoint . '/' . $ campaignId . '/content' ; $ response = $ this -> restClient -> put ( $ endpoint , $ contentData ) ; return $ response [ 'body' ] ; } | Add custom html to campaign |
47,907 | public function get ( $ type = 'sent' , $ fields = [ '*' ] ) { $ type = in_array ( $ type , [ 'sent' , 'draft' , 'outbox' ] ) ? $ type : 'sent' ; $ params = $ this -> prepareParams ( ) ; if ( ! empty ( $ fields ) && is_array ( $ fields ) && $ fields != [ '*' ] ) { $ params [ 'fields' ] = $ fields ; } $ response = $ this -> restClient -> get ( $ this -> endpoint . '/' . $ type , $ params ) ; $ entities = $ this -> generateCollection ( $ response [ 'body' ] ) ; return $ entities ; } | Get collection of items |
47,908 | protected function send ( $ method , $ endpointUri , $ body = null , array $ headers = [ ] ) { $ headers = array_merge ( $ headers , self :: getDefaultHeaders ( ) ) ; $ endpointUrl = $ this -> baseUrl . $ endpointUri ; $ request = new Request ( $ method , $ endpointUrl , $ headers , json_encode ( $ body ) ) ; $ response = $ this -> getHttpClient ( ) -> sendRequest ( $ request ) ; return $ this -> handleResponse ( $ response ) ; } | Execute HTTP request |
47,909 | protected function handleResponse ( ResponseInterface $ response ) { $ status = $ response -> getStatusCode ( ) ; $ data = ( string ) $ response -> getBody ( ) ; $ jsonResponseData = json_decode ( $ data , false ) ; $ body = $ data && $ jsonResponseData === null ? $ data : $ jsonResponseData ; return [ 'status_code' => $ status , 'body' => $ body ] ; } | Handle HTTP response |
47,910 | public function where ( $ column , $ operator = null , $ value = null , $ boolean = 'and' ) { if ( is_array ( $ column ) ) { $ this -> _where = $ column ; } return $ this ; } | Set where conditions |
47,911 | protected function prepareParams ( ) { $ params = [ ] ; if ( ! empty ( $ this -> _where ) && is_array ( $ this -> _where ) ) { $ params [ 'filters' ] = $ this -> _where ; } if ( ! empty ( $ this -> _offset ) ) { $ params [ 'offset' ] = $ this -> _offset ; } if ( ! empty ( $ this -> _limit ) ) { $ params [ 'limit' ] = $ this -> _limit ; } if ( ! empty ( $ this -> _orders ) && is_array ( $ this -> _orders ) ) { foreach ( $ this -> _orders as $ field => $ order ) { $ params [ 'order_by' ] [ $ field ] = $ order ; } } return $ params ; } | Prepare query parameters |
47,912 | public function setWebhooks ( $ shop ) { $ endpoint = $ this -> endpoint . '/webhooks' ; $ params = array_merge ( $ this -> prepareParams ( ) , [ 'shop' => $ shop ] ) ; return $ this -> restClient -> post ( $ endpoint , $ params ) ; } | Currenty not in use as this is meant to save webhooks for created and updated orders however now we re instead listening for the event in the plugin so no need for webhooks |
47,913 | public function saveOrder ( $ orderData , $ shop ) { $ endpoint = 'woocommerce/alternative_save_order' ; $ params = array_merge ( $ this -> prepareParams ( ) , [ 'order_data' => $ orderData , 'shop' => $ shop ] ) ; return $ this -> restClient -> post ( $ endpoint , $ params ) ; } | Sends the completed order data to the api |
47,914 | public function toggleShopConnection ( $ shop , $ activeState ) { $ shopName = parse_url ( $ shop , PHP_URL_HOST ) ; $ endpoint = 'woocommerce/toggle_shop_connection' ; $ params = array_merge ( $ this -> prepareParams ( ) , [ 'active_state' => $ activeState , 'shop' => $ shopName ] ) ; return $ this -> restClient -> post ( $ endpoint , $ params ) ; } | Calls api endpoint that will toggle shop s active state in our db |
47,915 | public static function make ( $ items ) { if ( is_null ( $ items ) ) { return new static ; } if ( $ items instanceof Collection ) { return $ items ; } return new static ( is_array ( $ items ) ? $ items : [ $ items ] ) ; } | Create a new collection instance if the value isn t one already . |
47,916 | public function getSubscribers ( $ groupId , $ type = null , $ params = [ ] ) { $ endpoint = $ this -> endpoint . '/' . $ groupId . '/subscribers' ; if ( $ type !== null ) { $ endpoint .= '/' . $ type ; } $ params = array_merge ( $ this -> prepareParams ( ) , $ params ) ; $ response = $ this -> restClient -> get ( $ endpoint , $ params ) ; return $ response [ 'body' ] ; } | Get subscribers from group |
47,917 | public function getSubscriber ( $ groupId , $ subscriberId ) { $ endpoint = $ this -> endpoint . '/' . $ groupId . '/subscribers/' . urlencode ( $ subscriberId ) ; $ response = $ this -> restClient -> get ( $ endpoint ) ; return $ response [ 'body' ] ; } | Get single subscriber from group |
47,918 | public function addSubscriber ( $ groupId , $ subscriberData = [ ] , $ params = [ ] ) { $ endpoint = $ this -> endpoint . '/' . $ groupId . '/subscribers' ; $ response = $ this -> restClient -> post ( $ endpoint , $ subscriberData ) ; return $ response [ 'body' ] ; } | Add single subscriber to group |
47,919 | public function removeSubscriber ( $ groupId , $ subscriberId ) { $ endpoint = $ this -> endpoint . '/' . $ groupId . '/subscribers/' . urlencode ( $ subscriberId ) ; $ response = $ this -> restClient -> delete ( $ endpoint ) ; return $ response [ 'body' ] ; } | Remove subscriber from group |
47,920 | public function importSubscribers ( $ groupId , $ subscribers , $ options = [ 'resubscribe' => false , 'autoresponders' => false ] ) { $ endpoint = $ this -> endpoint . '/' . $ groupId . '/subscribers/import' ; $ response = $ this -> restClient -> post ( $ endpoint , array_merge ( [ 'subscribers' => $ subscribers ] , $ options ) ) ; return $ response [ 'body' ] ; } | Batch add subscribers to group |
47,921 | public function getGroups ( $ subscriberId , $ params = [ ] ) { $ endpoint = $ this -> endpoint . '/' . urlencode ( $ subscriberId ) . '/groups' ; $ params = array_merge ( $ this -> prepareParams ( ) , $ params ) ; $ response = $ this -> restClient -> get ( $ endpoint , $ params ) ; return $ response [ 'body' ] ; } | Get groups subscriber belongs to |
47,922 | public function getActivity ( $ subscriberId , $ type = null , $ params = [ ] ) { $ endpoint = $ this -> endpoint . '/' . urlencode ( $ subscriberId ) . '/activity' ; if ( $ type !== null ) { $ endpoint .= '/' . $ type ; } $ params = array_merge ( $ this -> prepareParams ( ) , $ params ) ; $ response = $ this -> restClient -> get ( $ endpoint , $ params ) ; return $ response [ 'body' ] ; } | Get activity of subscriber |
47,923 | public function search ( $ query ) { $ endpoint = $ this -> endpoint . '/search' ; $ params = array_merge ( $ this -> prepareParams ( ) , [ 'query' => $ query ] ) ; $ response = $ this -> restClient -> get ( $ endpoint , $ params ) ; return $ response [ 'body' ] ; } | Seach for a subscriber by email or custom field value |
47,924 | public function getDoubleOptin ( ) { $ endpoint = $ this -> endpoint . '/double_optin' ; $ response = $ this -> restClient -> get ( $ endpoint ) ; return $ response [ 'body' ] ; } | Retrieve double opt in status |
47,925 | public function index ( ) { $ this -> loadModel ( 'Taxonomy.Vocabularies' ) ; $ vocabularies = $ this -> Vocabularies -> find ( ) -> order ( [ 'ordering' => 'ASC' ] ) -> all ( ) ; $ this -> title ( __d ( 'taxonomy' , 'Vocabularies' ) ) ; $ this -> set ( compact ( 'vocabularies' ) ) ; $ this -> Breadcrumb -> push ( '/admin/system/structure' ) -> push ( __d ( 'taxonomy' , 'Taxonomy' ) , '/admin/taxonomy/manage' ) -> push ( __d ( 'taxonomy' , 'Vocabularies' ) , '#' ) ; } | Shows a list of all vocabularies . |
47,926 | public function edit ( $ id ) { $ this -> loadModel ( 'Taxonomy.Vocabularies' ) ; $ vocabulary = $ this -> Vocabularies -> get ( $ id ) ; if ( $ this -> request -> data ( ) ) { $ vocabulary = $ this -> Vocabularies -> patchEntity ( $ vocabulary , $ this -> request -> data , [ 'fieldList' => [ 'name' , 'description' , ] , ] ) ; if ( $ this -> Vocabularies -> save ( $ vocabulary , [ 'atomic' => true ] ) ) { $ this -> Flash -> success ( __d ( 'taxonomy' , 'Vocabulary has been saved!' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } else { $ this -> Flash -> danger ( __d ( 'taxonomy' , 'Vocabulary could not be saved, please check your information' ) ) ; } } $ this -> title ( __d ( 'taxonomy' , 'Editing Vocabulary' ) ) ; $ this -> set ( 'vocabulary' , $ vocabulary ) ; $ this -> Breadcrumb -> push ( '/admin/system/structure' ) -> push ( __d ( 'taxonomy' , 'Taxonomy' ) , '/admin/taxonomy/manage' ) -> push ( __d ( 'taxonomy' , 'Vocabularies' ) , [ 'plugin' => 'Taxonomy' , 'controller' => 'vocabularies' , 'action' => 'index' ] ) -> push ( __d ( 'taxonomy' , 'Editing vocabulary' ) , '#' ) ; } | Edits the given vocabulary by ID . |
47,927 | public function delete ( $ id ) { $ this -> loadModel ( 'Taxonomy.Vocabularies' ) ; $ vocabulary = $ this -> Vocabularies -> get ( $ id , [ 'conditions' => [ 'locked' => 0 ] ] ) ; if ( $ this -> Vocabularies -> delete ( $ vocabulary ) ) { $ this -> Flash -> success ( __d ( 'taxonomy' , 'Vocabulary has been successfully deleted!' ) ) ; } else { $ this -> Flash -> danger ( __d ( 'taxonomy' , 'Vocabulary could not be deleted, please try again' ) ) ; } $ this -> title ( __d ( 'taxonomy' , 'Delete Vocabulary' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } | Removes the given vocabulary by ID . |
47,928 | public function home ( ) { $ this -> loadModel ( 'Content.Contents' ) ; $ contents = $ this -> Contents -> find ( 'all' ) -> where ( [ 'Contents.promote' => 1 , 'Contents.status >' => 0 , 'Contents.language IN' => [ '' , null , I18n :: locale ( ) ] ] ) -> order ( [ 'Contents.sticky' => 'DESC' , 'Contents.created' => 'DESC' ] ) -> limit ( ( int ) option ( 'site_contents_home' ) ) ; $ this -> set ( 'contents' , $ contents ) ; $ this -> viewMode ( 'teaser' ) ; } | Site s home page . |
47,929 | public function details ( $ contentTypeSlug , $ contentSlug ) { $ this -> loadModel ( 'Content.Contents' ) ; $ conditions = [ 'Contents.slug' => $ contentSlug , 'Contents.content_type_slug' => $ contentTypeSlug , ] ; if ( ! $ this -> request -> is ( 'userAdmin' ) ) { $ conditions [ 'Contents.status >' ] = 0 ; } $ content = $ this -> Contents -> find ( ) -> where ( $ conditions ) -> contain ( [ 'ContentTypes' , 'Roles' ] ) -> first ( ) ; if ( ! $ content ) { throw new ContentNotFoundException ( __d ( 'content' , 'The requested page was not found.' ) ) ; } elseif ( ! $ content -> isAccessibleByUser ( ) ) { throw new ForbiddenException ( __d ( 'content' , 'You have not sufficient permissions to see this page.' ) ) ; } if ( ! empty ( $ content -> language ) && $ content -> language != I18n :: locale ( ) ) { if ( $ redirect = $ this -> _calculateRedirection ( $ content ) ) { $ this -> redirect ( $ redirect ) ; return $ this -> response ; } throw new ContentNotFoundException ( __d ( 'content' , 'The requested page was not found.' ) ) ; } if ( $ content -> comment_status > 0 ) { $ content -> set ( 'comments' , $ this -> Contents -> find ( 'comments' , [ 'for' => $ content -> id ] ) ) ; $ this -> Comment -> config ( 'visibility' , $ content -> comment_status ) ; $ this -> Comment -> post ( $ content ) ; } $ this -> set ( 'content' , $ content ) ; $ this -> viewMode ( 'full' ) ; } | Content s detail page . |
47,930 | public function search ( $ criteria ) { $ this -> loadModel ( 'Content.Contents' ) ; try { $ contents = $ this -> Contents -> search ( $ criteria ) ; if ( $ contents -> clause ( 'limit' ) ) { $ this -> paginate [ 'limit' ] = $ contents -> clause ( 'limit' ) ; } if ( strpos ( $ criteria , 'language:' ) === false ) { $ contents = $ contents -> where ( [ 'Contents.status >' => 0 , 'Contents.language IN' => [ '' , null , I18n :: locale ( ) ] ] ) ; } $ contents = $ this -> paginate ( $ contents ) ; } catch ( \ Exception $ e ) { $ contents = new Collection ( [ ] ) ; } $ this -> set ( compact ( 'contents' , 'criteria' ) ) ; $ this -> viewMode ( 'search-result' ) ; } | Contents search engine page . |
47,931 | public function rss ( $ criteria ) { $ this -> loadModel ( 'Content.Contents' ) ; try { $ contents = $ this -> Contents -> search ( $ criteria ) -> limit ( 10 ) ; } catch ( \ Exception $ e ) { $ contents = [ ] ; } $ this -> set ( compact ( 'contents' , 'criteria' ) ) ; $ this -> viewMode ( 'rss' ) ; $ this -> RequestHandler -> renderAs ( $ this , 'rss' ) ; $ this -> RequestHandler -> respondAs ( 'xml' ) ; } | RSS feeder . |
47,932 | protected function _calculateRedirection ( EntityInterface $ content ) { foreach ( [ 'translation' , 'parent' ] as $ method ) { if ( $ has = $ content -> { $ method } ( ) ) { return option ( 'url_locale_prefix' ) ? '/' . $ has -> get ( 'language' ) . stripLanguagePrefix ( $ has -> get ( 'url' ) ) : $ has -> get ( 'url' ) ; } } return '' ; } | Calculates the URL to which visitor should be redirected according to content s & visitor s language . |
47,933 | public function configure ( $ id ) { $ instance = $ this -> _getOrThrow ( $ id , [ 'locked' => false ] ) ; $ arrayContext = [ 'schema' => [ ] , 'defaults' => [ ] , 'errors' => [ ] , ] ; if ( $ this -> request -> data ( ) ) { $ instance -> accessible ( '*' , true ) ; $ instance -> accessible ( [ 'id' , 'eav_attribute' , 'handler' , 'ordering' ] , false ) ; foreach ( $ this -> request -> data as $ k => $ v ) { if ( str_starts_with ( $ k , '_' ) ) { $ instance -> set ( str_replace_once ( '_' , '' , $ k ) , $ v ) ; unset ( $ this -> request -> data [ $ k ] ) ; } } $ validator = $ this -> FieldInstances -> validator ( 'settings' ) ; $ instance -> validateSettings ( $ this -> request -> data ( ) , $ validator ) ; $ errors = $ validator -> errors ( $ this -> request -> data ( ) , false ) ; if ( empty ( $ errors ) ) { $ instance -> set ( 'settings' , $ this -> request -> data ( ) ) ; $ save = $ this -> FieldInstances -> save ( $ instance ) ; if ( $ save ) { $ this -> Flash -> success ( __d ( 'field' , 'Field information was saved.' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } else { $ this -> Flash -> danger ( __d ( 'field' , 'Your information could not be saved.' ) ) ; } } else { $ this -> Flash -> danger ( __d ( 'field' , 'Field settings could not be saved.' ) ) ; foreach ( $ errors as $ field => $ message ) { $ arrayContext [ 'errors' ] [ $ field ] = $ message ; } } } else { $ arrayContext [ 'defaults' ] = ( array ) $ instance -> settings ; $ this -> request -> data = $ arrayContext [ 'defaults' ] ; } $ this -> title ( __d ( 'field' , 'Configure Field' ) ) ; $ this -> set ( compact ( 'arrayContext' , 'instance' ) ) ; } | Handles a single field instance configuration parameters . |
47,934 | public function attach ( ) { $ this -> loadModel ( 'Field.FieldInstances' ) ; if ( $ this -> request -> data ( ) ) { $ handler = $ this -> request -> data ( 'handler' ) ; $ info = fieldsInfo ( $ handler ) ; $ type = ! empty ( $ info [ 'type' ] ) ? $ info [ 'type' ] : null ; $ data = $ this -> request -> data ( ) ; $ data [ 'eav_attribute' ] = array_merge ( [ 'table_alias' => $ this -> _tableAlias , 'bundle' => $ this -> _getBundle ( ) , 'type' => $ type , ] , ( array ) $ this -> request -> data ( 'eav_attribute' ) ) ; $ fieldInstance = $ this -> FieldInstances -> newEntity ( $ data , [ 'associated' => [ 'EavAttribute' ] ] ) ; $ this -> _validateSlug ( $ fieldInstance ) ; $ instanceErrors = $ fieldInstance -> errors ( ) ; $ attributeErrors = $ fieldInstance -> get ( 'eav_attribute' ) -> errors ( ) ; $ success = empty ( $ instanceErrors ) && empty ( $ attributeErrors ) ; if ( $ success ) { $ success = $ this -> FieldInstances -> save ( $ fieldInstance , [ 'associated' => [ 'EavAttribute' ] ] ) ; if ( $ success ) { $ this -> Flash -> success ( __d ( 'field' , 'Field attached!' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } } if ( ! $ success ) { $ this -> Flash -> danger ( __d ( 'field' , 'Field could not be attached' ) ) ; } } else { $ fieldInstance = $ this -> FieldInstances -> newEntity ( ) ; } $ fieldsInfoCollection = fieldsInfo ( ) ; $ fieldsList = $ fieldsInfoCollection -> combine ( 'handler' , 'name' ) -> toArray ( ) ; $ fieldsInfo = $ fieldsInfoCollection -> toArray ( ) ; $ this -> title ( __d ( 'field' , 'Attach New Field' ) ) ; $ this -> set ( 'fieldsList' , $ fieldsList ) ; $ this -> set ( 'fieldsInfo' , $ fieldsInfo ) ; $ this -> set ( 'fieldInstance' , $ fieldInstance ) ; } | Attach action . |
47,935 | public function detach ( $ id ) { $ instance = $ this -> _getOrThrow ( $ id , [ 'locked' => false ] ) ; $ this -> loadModel ( 'Field.FieldInstances' ) ; if ( $ this -> FieldInstances -> delete ( $ instance ) ) { $ this -> Flash -> success ( __d ( 'field' , 'Field detached successfully!' ) ) ; } else { $ this -> Flash -> danger ( __d ( 'field' , 'Field could not be detached' ) ) ; } $ this -> title ( __d ( 'field' , 'Detach Field' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } | Detach action . |
47,936 | public function viewModeList ( $ viewMode ) { $ this -> _validateViewMode ( $ viewMode ) ; $ this -> loadModel ( 'Field.FieldInstances' ) ; $ instances = $ this -> _getInstances ( ) ; if ( count ( $ instances ) === 0 ) { $ this -> Flash -> warning ( __d ( 'field' , 'There are no field attached yet.' ) ) ; } else { $ instances = $ instances -> sortBy ( function ( $ fieldInstance ) use ( $ viewMode ) { if ( isset ( $ fieldInstance -> view_modes [ $ viewMode ] [ 'ordering' ] ) ) { return $ fieldInstance -> view_modes [ $ viewMode ] [ 'ordering' ] ; } return 0 ; } , SORT_ASC ) ; } $ this -> title ( __d ( 'field' , 'View Modes' ) ) ; $ this -> set ( 'instances' , $ instances ) ; $ this -> set ( 'viewMode' , $ viewMode ) ; $ this -> set ( 'viewModeInfo' , $ this -> viewModes ( $ viewMode ) ) ; } | View modes . |
47,937 | public function viewModeEdit ( $ viewMode , $ id ) { $ this -> _validateViewMode ( $ viewMode ) ; $ instance = $ this -> _getOrThrow ( $ id ) ; $ arrayContext = [ 'schema' => [ 'label_visibility' => [ 'type' => 'string' ] , 'shortcodes' => [ 'type' => 'boolean' ] , 'hidden' => [ 'type' => 'boolean' ] , ] , 'defaults' => [ 'label_visibility' => 'hidden' , 'shortcodes' => false , 'hidden' => false , ] , 'errors' => [ ] ] ; $ viewModeInfo = $ this -> viewModes ( $ viewMode ) ; if ( $ this -> request -> data ( ) ) { $ validator = $ this -> FieldInstances -> validator ( 'viewMode' ) ; $ instance -> validateViewModeSettings ( $ this -> request -> data ( ) , $ validator , $ viewMode ) ; $ errors = $ validator -> errors ( $ this -> request -> data ( ) , false ) ; if ( empty ( $ errors ) ) { $ instance -> accessible ( '*' , true ) ; $ viewModes = $ instance -> get ( 'view_modes' ) ; $ viewModes [ $ viewMode ] = array_merge ( $ viewModes [ $ viewMode ] , $ this -> request -> data ( ) ) ; $ instance -> set ( 'view_modes' , $ viewModes ) ; if ( $ this -> FieldInstances -> save ( $ instance ) ) { $ this -> Flash -> success ( __d ( 'field' , 'Field information was saved.' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } else { $ this -> Flash -> danger ( __d ( 'field' , 'Your information could not be saved.' ) ) ; } } else { $ this -> Flash -> danger ( __d ( 'field' , 'View mode settings could not be saved.' ) ) ; foreach ( $ errors as $ field => $ message ) { $ arrayContext [ 'errors' ] [ $ field ] = $ message ; } } } else { $ arrayContext [ 'defaults' ] = ( array ) $ instance -> view_modes [ $ viewMode ] ; $ this -> request -> data = $ arrayContext [ 'defaults' ] ; } $ this -> title ( __d ( 'field' , 'Configure View Mode' ) ) ; $ instance -> accessible ( 'settings' , true ) ; $ this -> set ( compact ( 'arrayContext' , 'viewMode' , 'viewModeInfo' , 'instance' ) ) ; } | Handles field instance rendering settings for a particular view mode . |
47,938 | public function viewModeMove ( $ viewMode , $ id , $ direction ) { $ this -> _validateViewMode ( $ viewMode ) ; $ instance = $ this -> _getOrThrow ( $ id ) ; $ unordered = [ ] ; $ position = false ; $ k = 0 ; $ list = $ this -> _getInstances ( ) -> sortBy ( function ( $ fieldInstance ) use ( $ viewMode ) { if ( isset ( $ fieldInstance -> view_modes [ $ viewMode ] [ 'ordering' ] ) ) { return $ fieldInstance -> view_modes [ $ viewMode ] [ 'ordering' ] ; } return 0 ; } , SORT_ASC ) ; foreach ( $ list as $ field ) { if ( $ field -> id === $ instance -> id ) { $ position = $ k ; } $ unordered [ ] = $ field ; $ k ++ ; } if ( $ position !== false ) { $ ordered = array_move ( $ unordered , $ position , $ direction ) ; $ before = md5 ( serialize ( $ unordered ) ) ; $ after = md5 ( serialize ( $ ordered ) ) ; if ( $ before != $ after ) { foreach ( $ ordered as $ k => $ field ) { $ viewModes = $ field -> view_modes ; $ viewModes [ $ viewMode ] [ 'ordering' ] = $ k ; $ field -> set ( 'view_modes' , $ viewModes ) ; $ this -> FieldInstances -> save ( $ field ) ; } } } $ this -> title ( __d ( 'field' , 'Change Field Order' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } | Moves a field up or down within a view mode . |
47,939 | public function move ( $ id , $ direction ) { $ instance = $ this -> _getOrThrow ( $ id ) ; $ unordered = [ ] ; $ direction = ! in_array ( $ direction , [ 'up' , 'down' ] ) ? 'up' : $ direction ; $ position = false ; $ list = $ this -> _getInstances ( ) ; foreach ( $ list as $ k => $ field ) { if ( $ field -> id === $ instance -> id ) { $ position = $ k ; } $ unordered [ ] = $ field ; } if ( $ position !== false ) { $ ordered = array_move ( $ unordered , $ position , $ direction ) ; $ before = md5 ( serialize ( $ unordered ) ) ; $ after = md5 ( serialize ( $ ordered ) ) ; if ( $ before != $ after ) { foreach ( $ ordered as $ k => $ field ) { $ field -> set ( 'ordering' , $ k ) ; $ this -> FieldInstances -> save ( $ field ) ; } } } $ this -> title ( __d ( 'field' , 'Reorder Field' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; } | Moves a field up or down . |
47,940 | protected function _getInstances ( ) { $ conditions = [ 'EavAttribute.table_alias' => $ this -> _tableAlias ] ; if ( ! empty ( $ this -> _bundle ) ) { $ conditions [ 'EavAttribute.bundle' ] = $ this -> _bundle ; } $ this -> loadModel ( 'Field.FieldInstances' ) ; return $ this -> FieldInstances -> find ( ) -> contain ( [ 'EavAttribute' ] ) -> where ( $ conditions ) -> order ( [ 'FieldInstances.ordering' => 'ASC' ] ) -> all ( ) ; } | Returns all field instances attached to the table being managed . |
47,941 | protected function _validateSlug ( $ instance ) { $ slug = $ instance -> get ( 'eav_attribute' ) -> get ( 'name' ) ; $ columns = $ this -> _table -> schema ( ) -> columns ( ) ; if ( in_array ( $ slug , $ columns ) ) { $ instance -> get ( 'eav_attribute' ) -> errors ( 'name' , __d ( 'field' , 'The name "{0}" cannot be used as it collides with table column names.' , $ slug ) ) ; } } | Checks that the given instance s slug do not collide with table s real column names . |
47,942 | protected function _getOrThrow ( $ id , $ conditions = [ ] ) { $ this -> loadModel ( 'Field.FieldInstances' ) ; $ conditions = array_merge ( [ 'id' => $ id ] , $ conditions ) ; $ instance = $ this -> FieldInstances -> find ( ) -> where ( $ conditions ) -> limit ( 1 ) -> first ( ) ; if ( ! $ instance ) { throw new RecordNotFoundException ( __d ( 'field' , 'The requested field does not exists.' ) ) ; } return $ instance ; } | Gets the given field instance by ID or throw if not exists . |
47,943 | public function upload ( ) { if ( ! isset ( $ this -> _package [ 'tmp_name' ] ) || ! is_readable ( $ this -> _package [ 'tmp_name' ] ) ) { $ this -> _error ( __d ( 'installer' , 'Invalid package.' ) ) ; return false ; } elseif ( ! isset ( $ this -> _package [ 'name' ] ) || ! str_ends_with ( strtolower ( $ this -> _package [ 'name' ] ) , '.zip' ) ) { $ this -> _error ( __d ( 'installer' , 'Invalid package format, it is not a ZIP package.' ) ) ; return false ; } else { $ dst = normalizePath ( TMP . $ this -> _package [ 'name' ] ) ; if ( is_readable ( $ dst ) ) { $ file = new File ( $ dst ) ; $ file -> delete ( ) ; } if ( move_uploaded_file ( $ this -> _package [ 'tmp_name' ] , $ dst ) ) { $ this -> _dst = $ dst ; return true ; } } $ this -> _error ( __d ( 'installer' , 'Package could not be uploaded, please check write permissions on /tmp directory.' ) ) ; return false ; } | Uploads a ZIP package to the server . |
47,944 | protected function _runTransactional ( ) { snapshot ( ) ; if ( ! $ this -> _init ( ) ) { return $ this -> _reset ( ) ; } if ( ! $ this -> params [ 'no-callbacks' ] ) { $ this -> _attachListeners ( $ this -> _plugin [ 'name' ] , "{$this->_workingDir}/" ) ; try { $ event = $ this -> trigger ( "Plugin.{$this->_plugin['name']}.beforeInstall" ) ; if ( $ event -> isStopped ( ) || $ event -> result === false ) { $ this -> err ( __d ( 'installer' , 'Task was explicitly rejected by {0}.' , ( $ this -> _plugin [ 'type' ] == 'plugin' ? __d ( 'installer' , 'the plugin' ) : __d ( 'installer' , 'the theme' ) ) ) ) ; return $ this -> _reset ( ) ; } } catch ( \ Exception $ ex ) { $ this -> err ( __d ( 'installer' , 'Internal error, {0} did not respond to "beforeInstall" callback correctly.' , ( $ this -> _plugin [ 'type' ] == 'plugin' ? __d ( 'installer' , 'plugin' ) : __d ( 'installer' , 'theme' ) ) ) ) ; return $ this -> _reset ( ) ; } } $ this -> loadModel ( 'System.Plugins' ) ; $ entity = $ this -> Plugins -> newEntity ( [ 'name' => $ this -> _plugin [ 'name' ] , 'package' => $ this -> _plugin [ 'packageName' ] , 'settings' => [ ] , 'status' => 0 , 'ordering' => 0 , ] , [ 'validate' => false ] ) ; if ( ! $ this -> _copyPackage ( ) ) { return $ this -> _reset ( ) ; } if ( ! $ this -> _addOptions ( ) ) { $ this -> _rollbackCopyPackage ( ) ; return $ this -> _reset ( ) ; } if ( ! $ this -> Plugins -> save ( $ entity ) ) { $ this -> _rollbackCopyPackage ( ) ; return $ this -> _reset ( ) ; } $ pluginName = $ this -> _plugin [ 'name' ] ; $ pluginType = $ this -> _plugin [ 'type' ] ; $ this -> _finish ( ) ; if ( $ this -> params [ 'activate' ] ) { $ this -> dispatchShell ( "Installer.plugins toggle -p {$pluginName} -s enable" ) ; } if ( ! $ this -> params [ 'no-callbacks' ] ) { try { $ event = $ this -> trigger ( "Plugin.{$pluginName}.afterInstall" ) ; } catch ( \ Exception $ ex ) { $ this -> err ( __d ( 'installer' , '{0} was installed but some errors occur.' , ( $ pluginType == 'plugin' ? __d ( 'installer' , 'The plugin' ) : __d ( 'installer' , 'The theme' ) ) ) ) ; } } return true ; } | Runs installation logic inside a safe transactional thread . This prevent DB inconsistencies on install failure . |
47,945 | protected function _rollbackCopyPackage ( ) { if ( ! empty ( $ this -> _plugin [ 'name' ] ) ) { $ destinationPath = normalizePath ( ROOT . "/plugins/{$this->_plugin['name']}/" ) ; if ( is_dir ( $ destinationPath ) && is_writable ( $ destinationPath ) ) { $ dst = new Folder ( $ destinationPath ) ; $ dst -> delete ( ) ; } } } | Deletes the directory that was copied to its final destination . |
47,946 | protected function _addOptions ( ) { if ( ! empty ( $ this -> _plugin [ 'composer' ] [ 'extra' ] [ 'options' ] ) ) { $ this -> loadModel ( 'System.Options' ) ; foreach ( $ this -> _plugin [ 'composer' ] [ 'extra' ] [ 'options' ] as $ index => $ option ) { if ( empty ( $ option [ 'name' ] ) ) { $ this -> err ( __d ( 'installer' , 'Unable to register {0} option, invalid option #{1}.' , ( $ this -> _plugin [ 'type' ] == 'plugin' ? __d ( 'installer' , 'plugin' ) : __d ( 'installer' , 'theme' ) ) , $ index ) ) ; return false ; } $ entity = $ this -> Options -> newEntity ( [ 'name' => $ option [ 'name' ] , 'value' => ! empty ( $ option [ 'value' ] ) ? $ option [ 'value' ] : null , 'autoload' => isset ( $ option [ 'autoload' ] ) ? ( bool ) $ option [ 'autoload' ] : false , ] ) ; $ errors = $ entity -> errors ( ) ; if ( empty ( $ errors ) ) { if ( ! $ this -> Options -> save ( $ entity ) ) { $ this -> err ( __d ( 'installer' , 'Unable to register option "{0}".' , [ $ option [ 'name' ] ] ) ) ; return false ; } $ this -> _addedOptions [ ] = $ option [ 'name' ] ; } else { $ this -> err ( __d ( 'installer' , 'Some errors were found while trying to register {0} options values, see below:' , ( $ this -> _plugin [ 'type' ] == 'plugin' ? __d ( 'installer' , 'plugin' ) : __d ( 'installer' , 'theme' ) ) ) ) ; foreach ( $ errors as $ error ) { $ this -> err ( __d ( 'installer' , ' - {0}' , [ $ error ] ) ) ; } return false ; } } } return true ; } | Register on options table any declared option is plugin s composer . json . |
47,947 | protected function _reset ( ) { if ( $ this -> _sourceType !== self :: TYPE_DIR && $ this -> _workingDir ) { $ source = new Folder ( $ this -> _workingDir ) ; $ source -> delete ( ) ; } $ this -> _addedOptions = [ ] ; $ this -> _workingDir = null ; $ this -> _sourceType = null ; $ this -> _plugin = [ 'name' => '' , 'packageName' => '' , 'type' => '' , 'composer' => [ ] , ] ; Plugin :: dropCache ( ) ; $ this -> _detachListeners ( ) ; return false ; } | Discards the install operation . Restores this class s status to its initial state . |
47,948 | protected function _finish ( ) { global $ classLoader ; snapshot ( ) ; Plugin :: dropCache ( ) ; $ classLoader -> addPsr4 ( $ this -> _plugin [ 'name' ] . "\\" , normalizePath ( ROOT . "/plugins/{$this->_plugin['name']}/src" ) , true ) ; AcoManager :: buildAcos ( $ this -> _plugin [ 'name' ] ) ; $ this -> _reset ( ) ; } | After installation is completed . |
47,949 | protected function _copyPackage ( $ clearDestination = false ) { $ source = new Folder ( $ this -> _workingDir ) ; $ destinationPath = normalizePath ( ROOT . "/plugins/{$this->_plugin['name']}/" ) ; if ( $ this -> _workingDir === $ destinationPath ) { return true ; } if ( ! $ clearDestination && is_readable ( $ destinationPath ) ) { $ this -> err ( __d ( 'installer' , 'Destination directory already exists, please delete manually this directory: {0}' , $ destinationPath ) ) ; return false ; } elseif ( $ clearDestination && is_readable ( $ destinationPath ) ) { $ destination = new Folder ( $ destinationPath ) ; if ( ! $ destination -> delete ( ) ) { $ this -> err ( __d ( 'installer' , 'Destination directory could not be cleared, please check write permissions: {0}' , $ destinationPath ) ) ; return false ; } } if ( $ source -> copy ( [ 'to' => $ destinationPath ] ) ) { return true ; } $ this -> err ( __d ( 'installer' , 'Error when moving package content.' ) ) ; return false ; } | Copies the extracted package to its final destination . |
47,950 | protected function _getFromFile ( ) { $ file = new File ( $ this -> params [ 'source' ] ) ; if ( $ this -> _unzip ( $ file -> pwd ( ) ) ) { return $ this -> _validateContent ( ) ; } $ this -> err ( __d ( 'installer' , 'Unable to extract the package.' ) ) ; return false ; } | Prepares install from ZIP file . |
47,951 | protected function _getFromUrl ( ) { try { $ http = new Client ( [ 'redirect' => 3 ] ) ; $ response = $ http -> get ( $ this -> params [ 'source' ] , [ ] , [ 'headers' => [ 'X-Requested-With' => 'XMLHttpRequest' ] ] ) ; } catch ( \ Exception $ ex ) { $ response = false ; $ this -> err ( __d ( 'installer' , 'Could not download the package. Details: {0}' , $ ex -> getMessage ( ) ) ) ; return false ; } if ( $ response && $ response -> isOk ( ) ) { $ this -> params [ 'source' ] = TMP . substr ( md5 ( $ this -> params [ 'source' ] ) , 24 ) . '.zip' ; $ file = new File ( $ this -> params [ 'source' ] ) ; $ responseBody = $ response -> body ( ) ; if ( is_readable ( $ file -> pwd ( ) ) ) { $ file -> delete ( ) ; } if ( ! empty ( $ responseBody ) && $ file -> create ( ) && $ file -> write ( $ responseBody , 'w+' , true ) ) { $ file -> close ( ) ; return $ this -> _getFromFile ( ) ; $ this -> err ( __d ( 'installer' , 'Unable to extract the package.' ) ) ; return false ; } $ this -> err ( __d ( 'installer' , 'Unable to download the file, check write permission on "{0}" directory.' , [ TMP ] ) ) ; return false ; } $ this -> err ( __d ( 'installer' , 'Could not download the package, no .ZIP file was found at the given URL.' ) ) ; return false ; } | Prepares install from remote URL . |
47,952 | protected function _unzip ( $ file ) { include_once Plugin :: classPath ( 'Installer' ) . 'Lib/pclzip.lib.php' ; $ File = new File ( $ file ) ; $ to = normalizePath ( $ File -> folder ( ) -> pwd ( ) . '/' . $ File -> name ( ) . '_unzip/' ) ; if ( is_readable ( $ to ) ) { $ folder = new Folder ( $ to ) ; $ folder -> delete ( ) ; } else { $ folder = new Folder ( $ to , true ) ; } $ PclZip = new \ PclZip ( $ file ) ; $ PclZip -> delete ( PCLZIP_OPT_BY_EREG , '/__MACOSX/' ) ; $ PclZip -> delete ( PCLZIP_OPT_BY_EREG , '/\.DS_Store$/' ) ; if ( $ PclZip -> extract ( PCLZIP_OPT_PATH , $ to ) ) { list ( $ directories , $ files ) = $ folder -> read ( false , false , true ) ; if ( count ( $ directories ) === 1 && empty ( $ files ) ) { $ container = new Folder ( $ directories [ 0 ] ) ; $ container -> move ( [ 'to' => $ to ] ) ; } $ this -> _workingDir = $ to ; return true ; } $ this -> err ( __d ( 'installer' , 'Unzip error: {0}' , [ $ PclZip -> errorInfo ( true ) ] ) ) ; return false ; } | Extracts the current ZIP package . |
47,953 | protected function _attachListeners ( $ plugin , $ path ) { $ path = normalizePath ( "{$path}/" ) ; $ eventsPath = normalizePath ( "{$path}/src/Event/" ) ; if ( is_readable ( $ eventsPath ) && is_dir ( $ eventsPath ) ) { $ EventManager = EventManager :: instance ( ) ; $ eventsFolder = new Folder ( $ eventsPath ) ; Plugin :: load ( $ plugin , [ 'autoload' => true , 'bootstrap' => false , 'routes' => false , 'path' => $ path , 'classBase' => 'src' , 'ignoreMissing' => true , ] ) ; foreach ( $ eventsFolder -> read ( false , false , true ) [ 1 ] as $ classPath ) { $ className = preg_replace ( '/\.php$/i' , '' , basename ( $ classPath ) ) ; $ fullClassName = implode ( '\\' , [ $ plugin , 'Event' , $ className ] ) ; if ( class_exists ( $ fullClassName ) ) { $ handler = new $ fullClassName ; $ this -> _listeners [ ] = $ handler ; $ EventManager -> on ( $ handler ) ; } } } } | Loads and registers plugin s namespace and loads its event listeners classes . |
47,954 | protected function _enable ( ) { $ disabledPlugins = plugin ( ) -> filter ( function ( $ plugin ) { return ! $ plugin -> status && ! $ plugin -> isTheme ; } ) -> toArray ( ) ; if ( ! count ( $ disabledPlugins ) ) { $ this -> err ( __d ( 'installer' , '<info>There are no disabled plugins!</info>' ) ) ; $ this -> out ( ) ; return ; } $ index = 1 ; $ this -> out ( ) ; foreach ( $ disabledPlugins as $ plugin ) { $ disabledPlugins [ $ index ] = $ plugin ; $ this -> out ( __d ( 'installer' , '[{0, number, integer}] {1}' , [ $ index , $ plugin -> humanName ] ) ) ; $ index ++ ; } $ this -> out ( ) ; $ message = __d ( 'installer' , "Which plugin would you like to activate?\n[Q]uit" ) ; while ( true ) { $ in = $ this -> in ( $ message ) ; if ( strtoupper ( $ in ) === 'Q' ) { $ this -> err ( __d ( 'installer' , 'Operation aborted' ) ) ; break ; } elseif ( intval ( $ in ) < 1 || ! isset ( $ disabledPlugins [ intval ( $ in ) ] ) ) { $ this -> err ( __d ( 'installer' , 'Invalid option' ) ) ; } else { $ task = $ this -> dispatchShell ( "Installer.plugins toggle -p {$disabledPlugins[$in]->name} -s enable" ) ; if ( $ task === 0 ) { $ this -> out ( __d ( 'installer' , 'Plugin enabled!' ) ) ; Plugin :: dropCache ( ) ; } else { $ this -> err ( __d ( 'installer' , 'Plugin could not be enabled.' ) , 2 ) ; $ this -> out ( ) ; } break ; } } $ this -> out ( ) ; } | Activates a plugin . |
47,955 | public function eventManager ( EventManager $ eventManager = null ) { if ( $ eventManager !== null ) { $ this -> _eventManager = $ eventManager ; } return $ this -> _eventManager ; } | Gets or sets event manager instance associated to this dispatcher . |
47,956 | public static function instance ( $ name = 'default' ) { if ( ! isset ( static :: $ _instances [ $ name ] ) ) { static :: $ _instances [ $ name ] = new EventDispatcher ( ) ; } return static :: $ _instances [ $ name ] ; } | Gets an instance of this class . |
47,957 | public function trigger ( $ eventName ) { $ data = func_get_args ( ) ; array_shift ( $ data ) ; $ event = $ this -> _prepareEvent ( $ eventName , $ data ) ; $ this -> _log ( $ event -> name ( ) ) ; $ this -> _eventManager -> dispatch ( $ event ) ; return $ event ; } | Trigger the given event name . |
47,958 | public function triggered ( $ eventName = null , $ sort = true ) { if ( $ eventName === null ) { if ( $ sort ) { arsort ( $ this -> _log , SORT_NATURAL ) ; } return $ this -> _log ; } if ( isset ( $ this -> _log [ $ eventName ] ) ) { return $ this -> _log [ $ eventName ] ; } return 0 ; } | Retrieves the number of times an event was triggered or the complete list of events that were triggered . |
47,959 | protected function _prepareEvent ( $ eventName , array $ data = [ ] ) { if ( is_array ( $ eventName ) ) { list ( $ eventName , $ subject ) = $ eventName ; } else { $ subject = new EventDispatcher ( ) ; } return new Event ( $ eventName , $ subject , $ data ) ; } | Prepares the event object to be triggered . |
47,960 | protected function _log ( $ eventName ) { if ( isset ( $ this -> _log [ $ eventName ] ) ) { $ this -> _log [ $ eventName ] ++ ; } else { $ this -> _log [ $ eventName ] = 1 ; } } | Logs the given event . |
47,961 | public function subject ( $ subject = null ) { if ( $ subject !== null ) { $ this -> _subject = $ subject ; return $ this ; } return $ this -> _subject ; } | Gets or sets message s subject . |
47,962 | public function body ( $ body = null ) { if ( $ body !== null ) { $ this -> _body = $ body ; return $ this ; } return $ this -> _body ; } | Gets or sets message s body . |
47,963 | public function send ( ) { if ( ! $ this -> _user -> has ( 'email' ) || ! $ this -> _user -> has ( 'name' ) ) { throw new BadMethodCallException ( __d ( 'user' , 'Missing "name" or "email" property when trying to send the email.' ) ) ; } if ( $ this -> config ( 'updateToken' ) === true ) { $ this -> loadModel ( 'User.Users' ) ; $ this -> _user -> updateToken ( ) ; } $ subject = $ this -> _parseVariables ( ( string ) $ this -> subject ( ) ) ; $ body = $ this -> _parseVariables ( ( string ) $ this -> body ( ) ) ; if ( empty ( $ subject ) || empty ( $ body ) ) { return false ; } $ sender = new Email ( $ this -> config ( 'emailConfig' ) ) ; $ sent = false ; try { $ sent = $ sender -> to ( $ this -> _user -> get ( 'email' ) , $ this -> _user -> get ( 'name' ) ) -> subject ( $ subject ) -> send ( $ body ) ; } catch ( \ Exception $ e ) { return false ; } return $ sent ; } | Sends email message to user . |
47,964 | public function upload ( $ name ) { $ instance = $ this -> _getInstance ( $ name ) ; require_once Plugin :: classPath ( 'Field' ) . 'Lib/class.upload.php' ; $ uploader = new \ upload ( $ this -> request -> data [ 'Filedata' ] ) ; if ( ! empty ( $ instance -> settings [ 'extensions' ] ) ) { $ exts = explode ( ',' , $ instance -> settings [ 'extensions' ] ) ; $ exts = array_map ( 'trim' , $ exts ) ; $ exts = array_map ( 'strtolower' , $ exts ) ; if ( ! in_array ( strtolower ( $ uploader -> file_src_name_ext ) , $ exts ) ) { $ this -> _error ( __d ( 'field' , 'Invalid file extension.' ) , 501 ) ; } } $ response = '' ; $ uploader -> file_overwrite = false ; $ folder = normalizePath ( WWW_ROOT . "/files/{$instance->settings['upload_folder']}/" ) ; $ url = normalizePath ( "/files/{$instance->settings['upload_folder']}/" , '/' ) ; $ uploader -> process ( $ folder ) ; if ( $ uploader -> processed ) { $ response = json_encode ( [ 'file_url' => Router :: url ( $ url . $ uploader -> file_dst_name , true ) , 'file_size' => FileToolbox :: bytesToSize ( $ uploader -> file_src_size ) , 'file_name' => $ uploader -> file_dst_name , 'mime_icon' => FileToolbox :: fileIcon ( $ uploader -> file_src_mime ) , ] ) ; } else { $ this -> _error ( __d ( 'field' , 'File upload error, details: {0}' , $ uploader -> error ) , 502 ) ; } $ this -> viewBuilder ( ) -> layout ( 'ajax' ) ; $ this -> title ( __d ( 'field' , 'Upload File' ) ) ; $ this -> set ( compact ( 'response' ) ) ; } | Uploads a new file for the given FileField instance . |
47,965 | public function delete ( $ name ) { $ this -> loadModel ( 'Field.FieldInstances' ) ; $ instance = $ this -> _getInstance ( $ name ) ; if ( $ instance && ! empty ( $ this -> request -> query [ 'file' ] ) ) { $ file = normalizePath ( WWW_ROOT . "/files/{$instance->settings['upload_folder']}/{$this->request->query['file']}" , DS ) ; $ file = new File ( $ file ) ; $ file -> delete ( ) ; } $ response = '' ; $ this -> viewBuilder ( ) -> layout ( 'ajax' ) ; $ this -> title ( __d ( 'field' , 'Delete File' ) ) ; $ this -> set ( compact ( 'response' ) ) ; } | Deletes a file for the given FileField instance . |
47,966 | protected function _getInstance ( $ name ) { $ this -> loadModel ( 'Field.FieldInstances' ) ; $ instance = $ this -> FieldInstances -> find ( ) -> contain ( [ 'EavAttribute' ] ) -> where ( [ 'EavAttribute.name' => $ name ] ) -> first ( ) ; if ( ! $ instance ) { $ this -> _error ( __d ( 'field' , 'Invalid field instance.' ) , 504 ) ; } return $ instance ; } | Get field instance information . |
47,967 | protected function _error ( $ message , $ code ) { header ( "HTTP/1.0 {$code} {$message}" ) ; echo $ message ; TableRegistry :: get ( 'Field.FieldInstances' ) -> connection ( ) -> disconnect ( ) ; exit ( 0 ) ; } | Sends a JSON message error . |
47,968 | public function prepareTheme ( ) { $ this -> viewBuilder ( ) -> layout ( 'default' ) ; if ( ! empty ( $ this -> request -> params [ 'prefix' ] ) && strtolower ( $ this -> request -> params [ 'prefix' ] ) === 'admin' ) { $ this -> viewBuilder ( ) -> theme ( option ( 'back_theme' ) ) ; } else { $ this -> viewBuilder ( ) -> theme ( option ( 'front_theme' ) ) ; } if ( $ this -> request -> isAjax ( ) ) { $ this -> viewBuilder ( ) -> layout ( 'ajax' ) ; } if ( $ this -> request -> isHome ( ) ) { $ this -> viewBuilder ( ) -> layout ( 'home' ) ; } if ( $ this -> request -> isDashboard ( ) ) { $ this -> viewBuilder ( ) -> layout ( 'dashboard' ) ; } } | Sets the theme to use . |
47,969 | public function checkMaintenanceMode ( ) { if ( option ( 'site_maintenance' ) && ! $ this -> request -> isUserAdmin ( ) && ! in_array ( strtolower ( "{$this->request->plugin}:{$this->request->controller}:{$this->request->action}" ) , [ 'user:gateway:login' , 'user:gateway:logout' ] ) ) { $ allowedIps = ( array ) array_filter ( array_map ( 'trim' , explode ( ',' , option ( 'site_maintenance_ip' ) ) ) ) ; if ( ! in_array ( env ( 'REMOTE_ADDR' ) , $ allowedIps ) ) { throw new SiteUnderMaintenanceException ( option ( 'site_maintenance_message' ) ) ; } } } | Checks if maintenance is enabled and renders the corresponding maintenance message . |
47,970 | public function render ( $ items , $ config = [ ] ) { if ( $ this -> _rendering ) { throw new FatalErrorException ( __d ( 'menu' , 'Loop detected, MenuHelper already rendering.' ) ) ; } $ items = $ this -> _prepareItems ( $ items ) ; if ( empty ( $ items ) ) { return '' ; } list ( $ config , $ attrs ) = $ this -> _prepareOptions ( $ config ) ; $ this -> _rendering = true ; $ this -> countItems ( $ items ) ; $ this -> config ( $ config ) ; if ( $ this -> config ( 'breadcrumbGuessing' ) ) { $ this -> Link -> config ( [ 'breadcrumbGuessing' => $ this -> config ( 'breadcrumbGuessing' ) ] ) ; } $ out = '' ; if ( intval ( $ this -> config ( 'split' ) ) > 1 ) { $ out .= $ this -> _renderPart ( $ items , $ config , $ attrs ) ; } else { $ out .= $ this -> formatTemplate ( 'root' , [ 'attrs' => $ this -> templater ( ) -> formatAttributes ( $ attrs ) , 'content' => $ this -> _render ( $ items ) ] ) ; } if ( $ this -> config ( 'beautify' ) ) { include_once Plugin :: classPath ( 'Menu' ) . 'Lib/htmLawed.php' ; $ tidy = is_bool ( $ this -> config ( 'beautify' ) ) ? '1t0n' : $ this -> config ( 'beautify' ) ; $ out = htmLawed ( $ out , compact ( 'tidy' ) ) ; } $ this -> _clear ( ) ; return $ out ; } | Renders a nested menu . |
47,971 | public function countItems ( $ items ) { if ( $ this -> _count ) { return $ this -> _count ; } $ this -> _count ( $ items ) ; return $ this -> _count ; } | Counts items in menu . |
47,972 | protected function _prepareItemAttrs ( $ item , array $ info , array $ options ) { $ options = Hash :: merge ( $ options , [ 'childAttrs' => [ 'class' => [ ] ] , 'linkAttrs' => [ 'class' => [ ] ] , ] ) ; $ childAttrs = $ options [ 'childAttrs' ] ; $ linkAttrs = $ options [ 'linkAttrs' ] ; if ( is_string ( $ childAttrs [ 'class' ] ) ) { $ childAttrs [ 'class' ] = [ $ childAttrs [ 'class' ] ] ; } if ( is_string ( $ linkAttrs [ 'class' ] ) ) { $ linkAttrs [ 'class' ] = [ $ linkAttrs [ 'class' ] ] ; } if ( $ info [ 'index' ] === 1 ) { $ childAttrs [ 'class' ] [ ] = $ this -> config ( 'firstClass' ) ; } if ( $ info [ 'index' ] === $ info [ 'total' ] ) { $ childAttrs [ 'class' ] [ ] = $ this -> config ( 'lastClass' ) ; } if ( $ info [ 'hasChildren' ] ) { $ childAttrs [ 'class' ] [ ] = $ this -> config ( 'hasChildrenClass' ) ; if ( $ this -> config ( 'dropdown' ) ) { $ childAttrs [ 'class' ] [ ] = 'dropdown' ; $ linkAttrs [ 'data-toggle' ] = 'dropdown' ; } } if ( ! empty ( $ item -> description ) ) { $ linkAttrs [ 'title' ] = $ item -> description ; } if ( ! empty ( $ item -> target ) ) { $ linkAttrs [ 'target' ] = $ item -> target ; } if ( $ info [ 'active' ] ) { $ childAttrs [ 'class' ] [ ] = $ this -> config ( 'activeClass' ) ; $ linkAttrs [ 'class' ] [ ] = $ this -> config ( 'activeClass' ) ; } $ id = $ this -> _calculateItemId ( $ item ) ; if ( ! empty ( $ id ) ) { $ childAttrs [ 'class' ] [ ] = "menu-link-{$id}" ; } $ childAttrs [ 'class' ] = array_unique ( $ childAttrs [ 'class' ] ) ; $ linkAttrs [ 'class' ] = array_unique ( $ linkAttrs [ 'class' ] ) ; return [ 'link' => $ linkAttrs , 'child' => $ childAttrs , ] ; } | Prepares item s attributes for rendering . |
47,973 | protected function _calculateItemId ( EntityInterface $ item ) { if ( $ item -> has ( 'id' ) ) { return $ item -> id ; } if ( is_array ( $ item -> url ) ) { return Inflector :: slug ( strtolower ( implode ( ' ' , array_values ( $ item -> url ) ) ) ) ; } return Inflector :: slug ( strtolower ( $ item -> url ) ) ; } | Calculates an item s ID |
47,974 | protected function _render ( $ items , $ depth = 0 ) { $ content = '' ; $ formatter = $ this -> config ( 'formatter' ) ; foreach ( $ items as $ item ) { $ children = '' ; if ( is_array ( $ item ) ) { $ item = new Entity ( $ item ) ; } if ( $ item -> has ( 'children' ) && ! empty ( $ item -> children ) && $ item -> expanded ) { $ children = $ this -> formatTemplate ( 'parent' , [ 'attrs' => $ this -> templater ( ) -> formatAttributes ( [ 'class' => ( $ this -> config ( 'dropdown' ) ? 'dropdown-menu multi-level' : '' ) , 'role' => 'menu' ] ) , 'content' => $ this -> _render ( $ item -> children , $ depth + 1 ) ] ) ; } $ this -> _index ++ ; $ info = [ 'index' => $ this -> _index , 'total' => $ this -> _count , 'active' => $ this -> Link -> isActive ( $ item ) , 'depth' => $ depth , 'hasChildren' => ! empty ( $ children ) , 'children' => $ children , ] ; $ content .= $ formatter ( $ item , $ info ) ; } return $ content ; } | Internal method to recursively generate the menu . |
47,975 | protected function _count ( $ items ) { foreach ( $ items as $ item ) { $ this -> _count ++ ; $ item = is_array ( $ item ) ? new Entity ( $ item ) : $ item ; if ( $ item -> has ( 'children' ) && ! empty ( $ item -> children ) && $ item -> expanded ) { $ this -> _count ( $ item -> children ) ; } } } | Internal method for counting items in menu . |
47,976 | protected function _clear ( ) { $ this -> _index = 0 ; $ this -> _count = 0 ; $ this -> _rendering = false ; $ this -> config ( $ this -> _defaultConfig ) ; $ this -> Link -> config ( [ 'breadcrumbGuessing' => $ this -> _defaultConfig [ 'breadcrumbGuessing' ] ] ) ; $ this -> resetTemplates ( ) ; } | Clears all temporary variables used when rendering a menu so they do not interfere when rendering other menus . |
47,977 | public function renderComment ( Event $ event , $ comment , $ options = [ ] ) { $ View = $ event -> subject ( ) ; $ html = $ View -> element ( 'Comment.render_comment' , compact ( 'comment' , 'options' ) ) ; return $ html ; } | Renders a single Comment . |
47,978 | public function settingsDefaults ( Event $ event ) { return [ 'visibility' => 0 , 'auto_approve' => false , 'allow_anonymous' => false , 'anonymous_name' => false , 'anonymous_name_required' => true , 'anonymous_email' => false , 'anonymous_email_required' => true , 'anonymous_web' => false , 'anonymous_web_required' => true , 'text_processing' => 'plain' , 'use_ayah' => false , 'ayah_publisher_key' => '' , 'ayah_scoring_key' => '' , 'use_akismet' => false , 'akismet_key' => '' , 'akismet_action' => 'mark' , ] ; } | Defaults settings for Comment s settings form . |
47,979 | protected function _packages ( ) { $ installed = static :: cache ( '_composerPackages' ) ; if ( is_array ( $ installed ) ) { return $ installed ; } $ jsonPath = VENDOR_INCLUDE_PATH . 'composer/installed.json' ; $ installed = [ ] ; if ( is_readable ( $ jsonPath ) ) { $ json = ( array ) json_decode ( file_get_contents ( $ jsonPath ) , true ) ; foreach ( $ json as $ pkg ) { $ installed [ $ pkg [ 'name' ] ] = [ 'name' => $ pkg [ 'name' ] , 'version' => $ pkg [ 'version' ] , 'version_normalized' => $ pkg [ 'version_normalized' ] , ] ; } } return static :: cache ( '_composerPackages' , $ installed ) ; } | Gets a list of all packages installed using composer . |
47,980 | protected function configure ( ) { $ path = $ this -> options [ 'tmbPath' ] ; if ( $ path ) { if ( ! file_exists ( $ path ) ) { if ( @ mkdir ( $ path ) ) { chmod ( $ path , $ this -> options [ 'tmbPathMode' ] ) ; } else { $ path = '' ; } } if ( is_dir ( $ path ) && is_readable ( $ path ) ) { $ this -> tmbPath = $ path ; $ this -> tmbPathWritable = is_writable ( $ path ) ; } } $ type = preg_match ( '/^(imagick|gd|auto)$/i' , $ this -> options [ 'imgLib' ] ) ? strtolower ( $ this -> options [ 'imgLib' ] ) : 'auto' ; if ( ( $ type == 'imagick' || $ type == 'auto' ) && extension_loaded ( 'imagick' ) ) { $ this -> imgLib = 'imagick' ; } else { $ this -> imgLib = function_exists ( 'gd_info' ) ? 'gd' : '' ; } } | Configure after successfull mount . By default set thumbnails path and image manipulation library . |
47,981 | public function getOptionsPlugin ( $ name = '' ) { if ( $ name ) { return isset ( $ this -> options [ 'plugin' ] [ $ name ] ) ? $ this -> options [ 'plugin' ] [ $ name ] : array ( ) ; } else { return $ this -> options [ 'plugin' ] ; } } | Get plugin values of this options |
47,982 | public function mimeAccepted ( $ mime , $ mimes = array ( ) , $ empty = true ) { $ mimes = ! empty ( $ mimes ) ? $ mimes : $ this -> onlyMimes ; if ( empty ( $ mimes ) ) { return $ empty ; } return $ mime == 'directory' || in_array ( 'all' , $ mimes ) || in_array ( 'All' , $ mimes ) || in_array ( $ mime , $ mimes ) || in_array ( substr ( $ mime , 0 , strpos ( $ mime , '/' ) ) , $ mimes ) ; } | Return true if mime is required mimes list |
47,983 | public function path ( $ hash ) { return $ this -> convEncOut ( $ this -> _path ( $ this -> convEncIn ( $ this -> decode ( $ hash ) ) ) ) ; } | Return file path related to root with convert encoging |
47,984 | public function realpath ( $ hash ) { $ path = $ this -> decode ( $ hash ) ; return $ this -> stat ( $ path ) ? $ path : false ; } | Return file real path if file exists |
47,985 | public function dir ( $ hash , $ resolveLink = false ) { if ( ( $ dir = $ this -> file ( $ hash ) ) == false ) { return $ this -> setError ( elFinder :: ERROR_DIR_NOT_FOUND ) ; } if ( $ resolveLink && ! empty ( $ dir [ 'thash' ] ) ) { $ dir = $ this -> file ( $ dir [ 'thash' ] ) ; } return $ dir && $ dir [ 'mime' ] == 'directory' && empty ( $ dir [ 'hidden' ] ) ? $ dir : $ this -> setError ( elFinder :: ERROR_NOT_DIR ) ; } | Return folder info |
47,986 | public function scandir ( $ hash ) { if ( ( $ dir = $ this -> dir ( $ hash ) ) == false ) { return false ; } return $ dir [ 'read' ] ? $ this -> getScandir ( $ this -> decode ( $ hash ) ) : $ this -> setError ( elFinder :: ERROR_PERM_DENIED ) ; } | Return directory content or false on error |
47,987 | public function parents ( $ hash , $ lineal = false ) { if ( ( $ current = $ this -> dir ( $ hash ) ) == false ) { return false ; } $ path = $ this -> decode ( $ hash ) ; $ tree = array ( ) ; while ( $ path && $ path != $ this -> root ) { $ path = $ this -> dirnameCE ( $ path ) ; $ stat = $ this -> stat ( $ path ) ; if ( ! empty ( $ stat [ 'hidden' ] ) || ! $ stat [ 'read' ] ) { return false ; } array_unshift ( $ tree , $ stat ) ; if ( ! $ lineal ) { foreach ( $ this -> gettree ( $ path , 0 ) as $ dir ) { if ( ! in_array ( $ dir , $ tree ) ) { $ tree [ ] = $ dir ; } } } } return $ tree ? $ tree : array ( $ current ) ; } | Return part of dirs tree from required dir up to root dir |
47,988 | public function tmb ( $ hash ) { $ path = $ this -> decode ( $ hash ) ; $ stat = $ this -> stat ( $ path ) ; if ( isset ( $ stat [ 'tmb' ] ) ) { return $ stat [ 'tmb' ] == "1" ? $ this -> createTmb ( $ path , $ stat ) : $ stat [ 'tmb' ] ; } return false ; } | Create thumbnail for required file and return its name of false on failed |
47,989 | public function getContents ( $ hash ) { $ file = $ this -> file ( $ hash ) ; if ( ! $ file ) { return $ this -> setError ( elFinder :: ERROR_FILE_NOT_FOUND ) ; } if ( $ file [ 'mime' ] == 'directory' ) { return $ this -> setError ( elFinder :: ERROR_NOT_FILE ) ; } if ( ! $ file [ 'read' ] ) { return $ this -> setError ( elFinder :: ERROR_PERM_DENIED ) ; } return $ this -> convEncOut ( $ this -> _getContents ( $ this -> convEncIn ( $ this -> decode ( $ hash ) ) ) ) ; } | Return file contents |
47,990 | public function getTempPath ( ) { if ( @ $ this -> tmpPath ) { return $ this -> tmpPath ; } else if ( @ $ this -> tmp ) { return $ this -> tmp ; } else if ( function_exists ( 'sys_get_temp_dir' ) ) { return sys_get_temp_dir ( ) ; } else if ( @ $ this -> tmbPath ) { return $ this -> tmbPath ; } else { return null ; } } | Return temp path |
47,991 | protected function setError ( $ error ) { $ this -> error = array ( ) ; foreach ( func_get_args ( ) as $ err ) { if ( is_array ( $ err ) ) { $ this -> error = array_merge ( $ this -> error , $ err ) ; } else { $ this -> error [ ] = $ err ; } } return false ; } | Save error message |
47,992 | protected function encode ( $ path ) { if ( $ path !== '' ) { $ p = $ this -> relpathCE ( $ path ) ; if ( $ p === '' ) { $ p = DIRECTORY_SEPARATOR ; } $ hash = $ this -> crypt ( $ p ) ; $ hash = strtr ( base64_encode ( $ hash ) , '+/=' , '-_.' ) ; $ hash = rtrim ( $ hash , '.' ) ; return $ this -> id . $ hash ; } } | Encode path into hash |
47,993 | public function convEncIn ( $ var = null , $ restoreLocale = false , $ unknown = '_' ) { return ( ! $ this -> encoding ) ? $ var : $ this -> convEnc ( $ var , 'UTF-8' , $ this -> encoding , $ this -> options [ 'locale' ] , $ restoreLocale , $ unknown ) ; } | Converts character encoding from UTF - 8 to server s one |
47,994 | public function convEncOut ( $ var = null , $ restoreLocale = true , $ unknown = '_' ) { return ( ! $ this -> encoding ) ? $ var : $ this -> convEnc ( $ var , $ this -> encoding , 'UTF-8' , $ this -> options [ 'locale' ] , $ restoreLocale , $ unknown ) ; } | Converts character encoding from server s one to UTF - 8 |
47,995 | protected function getWorkFile ( $ path ) { if ( $ work = $ this -> getTempFile ( ) ) { if ( $ wfp = fopen ( $ work , 'wb' ) ) { if ( $ fp = $ this -> _fopen ( $ path ) ) { while ( ! feof ( $ fp ) ) { fwrite ( $ wfp , fread ( $ fp , 8192 ) ) ; } $ this -> _fclose ( $ fp , $ path ) ; fclose ( $ wfp ) ; return $ work ; } } } return false ; } | File path of local server side work file path |
47,996 | public function getImageSize ( $ path , $ mime = '' ) { $ size = false ; if ( $ mime === '' || strtolower ( substr ( $ mime , 0 , 5 ) ) === 'image' ) { if ( $ work = $ this -> getWorkFile ( $ path ) ) { if ( $ size = @ getimagesize ( $ work ) ) { $ size [ 'dimensions' ] = $ size [ 0 ] . 'x' . $ size [ 1 ] ; } } is_file ( $ work ) && @ unlink ( $ work ) ; } return $ size ; } | Get image size array with dimensions |
47,997 | protected function delTree ( $ localpath ) { foreach ( $ this -> _scandir ( $ localpath ) as $ p ) { @ set_time_limit ( 30 ) ; $ stat = $ this -> stat ( $ this -> convEncOut ( $ p ) ) ; $ this -> convEncIn ( ) ; ( $ stat [ 'mime' ] === 'directory' ) ? $ this -> delTree ( $ p ) : $ this -> _unlink ( $ p ) ; } return $ this -> _rmdir ( $ localpath ) ; } | Delete dirctory trees |
47,998 | protected function allowCreate ( $ dir , $ name , $ isDir = null ) { $ path = $ this -> joinPathCE ( $ dir , $ name ) ; $ perm = null ; if ( $ this -> access ) { $ perm = call_user_func ( $ this -> access , 'write' , $ path , $ this -> options [ 'accessControlData' ] , $ this , $ isDir ) ; if ( $ perm !== null ) { return ! ! $ perm ; } } $ testPath = $ this -> separator . $ this -> relpathCE ( $ path ) ; for ( $ i = 0 , $ c = count ( $ this -> attributes ) ; $ i < $ c ; $ i ++ ) { $ attrs = $ this -> attributes [ $ i ] ; if ( isset ( $ attrs [ 'write' ] ) && isset ( $ attrs [ 'pattern' ] ) && preg_match ( $ attrs [ 'pattern' ] , $ testPath ) ) { $ perm = $ attrs [ 'write' ] ; } } return $ perm === null ? true : $ perm ; } | Return true if file with given name can be created in given folder . |
47,999 | protected function cacheDir ( $ path ) { $ this -> dirsCache [ $ path ] = array ( ) ; foreach ( $ this -> scandirCE ( $ path ) as $ p ) { if ( ( $ stat = $ this -> stat ( $ p ) ) && empty ( $ stat [ 'hidden' ] ) ) { $ this -> dirsCache [ $ path ] [ ] = $ p ; } } } | Get stat for folder content and put in cache |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.