idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
54,900
|
public function getList ( ) { $ result = & gplcart_static ( 'product.compare.list' ) ; if ( isset ( $ result ) ) { return ( array ) $ result ; } $ this -> hook -> attach ( 'product.compare.list.before' , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( array ) $ result ; } $ cookie = $ this -> request -> cookie ( 'product_compare' , '' , 'string' ) ; $ result = array_filter ( array_map ( 'trim' , explode ( '|' , urldecode ( $ cookie ) ) ) , 'ctype_digit' ) ; $ this -> hook -> attach ( 'product.compare.list.after' , $ result , $ this ) ; return $ result ; }
|
Returns an array of product ID to be compared
|
54,901
|
public function add ( $ product_id ) { $ result = null ; $ this -> hook -> attach ( 'product.compare.add.before' , $ product_id , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( bool ) $ result ; } $ product_ids = $ this -> getList ( ) ; if ( in_array ( $ product_id , $ product_ids ) ) { return false ; } array_unshift ( $ product_ids , $ product_id ) ; $ this -> controlLimit ( $ product_ids ) ; $ result = $ this -> set ( $ product_ids ) ; $ this -> hook -> attach ( 'product.compare.add.after' , $ product_id , $ result , $ this ) ; return ( bool ) $ result ; }
|
Adds a product to comparison
|
54,902
|
public function delete ( $ product_id ) { $ result = null ; $ this -> hook -> attach ( 'product.compare.delete.before' , $ product_id , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( bool ) $ result ; } $ compared = $ this -> getList ( ) ; if ( empty ( $ compared ) ) { return false ; } $ product_ids = array_flip ( $ compared ) ; unset ( $ product_ids [ $ product_id ] ) ; $ result = $ this -> set ( array_keys ( $ product_ids ) ) ; $ this -> hook -> attach ( 'product.compare.delete.after' , $ product_id , $ result , $ this ) ; return ( bool ) $ result ; }
|
Removes a products from comparison
|
54,903
|
public function set ( array $ product_ids ) { $ lifespan = $ this -> getCookieLifespan ( ) ; $ result = $ this -> request -> setCookie ( 'product_compare' , implode ( '|' , ( array ) $ product_ids ) , $ lifespan ) ; gplcart_static_clear ( ) ; return $ result ; }
|
Saves an array of product ID in cookie
|
54,904
|
protected function controlLimit ( array & $ product_ids ) { $ limit = $ this -> getLimit ( ) ; if ( ! empty ( $ limit ) ) { $ product_ids = array_slice ( $ product_ids , 0 , $ limit ) ; } }
|
Reduces a number of items to save
|
54,905
|
public function parseParams ( $ argv ) { if ( is_string ( $ argv ) ) { $ argv = gplcart_string_explode_whitespace ( $ argv ) ; } array_shift ( $ argv ) ; $ out = array ( ) ; for ( $ i = 0 , $ j = count ( $ argv ) ; $ i < $ j ; $ i ++ ) { $ key = null ; $ arg = $ argv [ $ i ] ; if ( substr ( $ arg , 0 , 2 ) === '--' ) { $ pos = strpos ( $ arg , '=' ) ; if ( $ pos === false ) { $ key = substr ( $ arg , 2 ) ; if ( $ i + 1 < $ j && $ argv [ $ i + 1 ] [ 0 ] !== '-' ) { $ value = $ argv [ $ i + 1 ] ; $ i ++ ; } else { $ value = isset ( $ out [ $ key ] ) ? $ out [ $ key ] : true ; } $ out [ $ key ] = $ value ; continue ; } $ key = substr ( $ arg , 2 , $ pos - 2 ) ; $ value = substr ( $ arg , $ pos + 1 ) ; $ out [ $ key ] = $ value ; continue ; } if ( substr ( $ arg , 0 , 1 ) === '-' ) { if ( substr ( $ arg , 2 , 1 ) === '=' ) { $ key = substr ( $ arg , 1 , 1 ) ; $ value = substr ( $ arg , 3 ) ; $ out [ $ key ] = $ value ; continue ; } foreach ( str_split ( substr ( $ arg , 1 ) ) as $ char ) { $ key = $ char ; $ value = isset ( $ out [ $ key ] ) ? $ out [ $ key ] : true ; $ out [ $ key ] = $ value ; } if ( $ i + 1 < $ j && $ argv [ $ i + 1 ] [ 0 ] !== '-' ) { $ out [ $ key ] = $ argv [ $ i + 1 ] ; $ i ++ ; } continue ; } $ value = $ arg ; $ out [ ] = $ value ; } return $ out ; }
|
Parses command line parameters
|
54,906
|
public function in ( $ format = '' ) { if ( empty ( $ format ) ) { $ line = fgets ( STDIN ) ; } else { $ line = fscanf ( STDIN , $ format . PHP_EOL , $ line ) ; } return trim ( $ line ) ; }
|
Reads a user input
|
54,907
|
public function prompt ( $ question , $ default = null , $ marker = ': ' ) { if ( isset ( $ default ) && strpos ( $ question , '[' ) === false ) { $ question .= ' [default: ' . $ default . ']' ; } $ this -> out ( $ question . $ marker ) ; $ input = $ this -> in ( ) ; if ( $ input === '' ) { return $ default ; } return $ input ; }
|
Displays an input prompt
|
54,908
|
public function menu ( $ items , $ default = null , $ title = 'Choose an item' ) { if ( isset ( $ items [ $ default ] ) && strpos ( $ title , '[' ) === false ) { $ title .= ' [default: ' . $ items [ $ default ] . ']' ; } $ this -> line ( sprintf ( '%s: ' , $ title ) ) ; $ i = 1 ; $ keys = array ( ) ; foreach ( $ items as $ key => $ item ) { $ keys [ $ i ] = $ key ; $ this -> line ( sprintf ( ' %d. %s' , $ i , $ item ) ) ; $ i ++ ; } $ selected = $ this -> in ( ) ; if ( $ selected === '' ) { return $ default ; } if ( isset ( $ keys [ $ selected ] ) ) { return $ keys [ $ selected ] ; } return $ selected ; }
|
Displays a menu where a user can enter a number to choose an option
|
54,909
|
public function choose ( $ question , $ choice = 'yn' , $ default = 'n' ) { if ( ! is_string ( $ choice ) ) { $ choice = implode ( '' , $ choice ) ; } $ lowercase = str_ireplace ( $ default , strtoupper ( $ default ) , strtolower ( $ choice ) ) ; $ choices = trim ( implode ( '/' , preg_split ( '//' , $ lowercase ) ) , '/' ) ; $ line = $ this -> prompt ( sprintf ( '%s [%s]' , $ question , $ choices ) , $ default , '' ) ; if ( stripos ( $ choice , $ line ) !== false ) { return strtolower ( $ line ) ; } return strtolower ( $ default ) ; }
|
Presents a user with a multiple choice questions
|
54,910
|
public function get ( $ name = null , $ default = '' , $ sanitize = true ) { if ( ! isset ( $ name ) ) { return $ this -> server ; } if ( ! array_key_exists ( $ name , $ this -> server ) ) { return $ default ; } if ( is_array ( $ this -> server [ $ name ] ) ) { gplcart_array_trim ( $ this -> server [ $ name ] , $ sanitize ) ; } else { $ this -> server [ $ name ] = trim ( $ this -> server [ $ name ] ) ; if ( $ sanitize ) { $ this -> server [ $ name ] = filter_var ( $ this -> server [ $ name ] , FILTER_SANITIZE_STRING ) ; } } return $ this -> server [ $ name ] ; }
|
Returns a server data
|
54,911
|
public function header ( $ name , $ default = null , $ sanitize = true ) { $ headers = $ this -> headers ( ) ; $ name = ucfirst ( strtolower ( $ name ) ) ; if ( array_key_exists ( $ name , $ headers ) ) { return $ sanitize ? filter_var ( $ headers [ $ name ] , FILTER_SANITIZE_STRING ) : $ headers [ $ name ] ; } return $ default ; }
|
Returns an HTTP header
|
54,912
|
public function get ( $ key ) { $ key = strtolower ( $ key ) ; if ( ! isset ( $ this -> services [ $ key ] ) ) { throw new \ InvalidArgumentException ( 'Service not found: ' . $ key ) ; } if ( isset ( $ this -> loadedService [ $ key ] ) ) { return $ this -> loadedService [ $ key ] ; } if ( ! $ this -> services [ $ key ] instanceof Service ) { $ this -> loadedService [ $ key ] = $ this -> services [ $ key ] ; return $ this -> loadedService [ $ key ] ; } if ( ! $ this -> services [ $ key ] -> hasClassName ( ) ) { throw new \ Exception ( 'Unable to find class name from definition: ' . $ key ) ; } $ className = $ this -> services [ $ key ] -> getClassName ( ) ; $ instance = new $ className ( ) ; if ( $ this -> services [ $ key ] -> hasFactoryMethod ( ) ) { call_user_func ( $ instance , $ this -> services [ $ key ] -> getFactoryMethod ( ) ) ; } $ this -> loadedService [ $ key ] = $ instance ; return $ this -> loadedService [ $ key ] ; }
|
Get a registered service by its name .
|
54,913
|
public function listCategory ( ) { $ this -> setTitleListCategory ( ) ; $ this -> setBreadcrumbListCategory ( ) ; $ this -> setData ( 'categories' , $ this -> data_categories ) ; $ this -> outputListCategory ( ) ; }
|
Page callback Displays the catalog page
|
54,914
|
public function indexCategory ( $ category_id ) { $ this -> setCategory ( $ category_id ) ; $ this -> setTitleIndexCategory ( ) ; $ this -> setBreadcrumbIndexCategory ( ) ; $ this -> setHtmlFilterIndexCategory ( ) ; $ this -> setTotalIndexCategory ( ) ; $ this -> setFilterIndexCategory ( ) ; $ this -> setPagerIndexCategory ( ) ; $ this -> setListProductCategory ( ) ; $ this -> setChildrenCategory ( ) ; $ this -> setData ( 'category' , $ this -> data_category ) ; $ this -> setDataMenuIndexCategory ( ) ; $ this -> setDataImagesIndexCategory ( ) ; $ this -> setDataNavbarIndexCategory ( ) ; $ this -> setDataProductsIndexCategory ( ) ; $ this -> setDataChildrenIndexCategory ( ) ; $ this -> setMetaIndexCategory ( ) ; $ this -> outputIndexCategory ( ) ; }
|
Page callback Displays the category page
|
54,915
|
protected function setFilterIndexCategory ( ) { $ default = array ( 'view' => $ this -> configTheme ( 'catalog_view' , 'grid' ) , 'sort' => $ this -> configTheme ( 'catalog_sort' , 'price' ) , 'order' => $ this -> configTheme ( 'catalog_order' , 'asc' ) ) ; $ this -> setFilter ( array ( ) , $ this -> getFilterQuery ( $ default ) ) ; }
|
Sets filter on the category page
|
54,916
|
protected function setTotalIndexCategory ( ) { $ options = $ this -> query_filter ; $ options [ 'count' ] = true ; $ options [ 'category_id' ] = $ this -> data_category [ 'category_id' ] ; return $ this -> data_total = ( int ) $ this -> product -> getList ( $ options ) ; }
|
Sets a total number of products found for the category
|
54,917
|
protected function setDataImagesIndexCategory ( ) { $ options = array ( 'imagestyle' => $ this -> configTheme ( 'image_style_category' , 3 ) ) ; $ this -> setItemThumb ( $ this -> data_category , $ this -> image , $ options ) ; $ this -> setData ( 'images' , $ this -> render ( 'category/images' , array ( 'category' => $ this -> data_category ) ) ) ; }
|
Sets the category images
|
54,918
|
protected function setDataNavbarIndexCategory ( ) { $ data = array ( 'total' => $ this -> data_total , 'view' => $ this -> query_filter [ 'view' ] , 'quantity' => count ( $ this -> data_products ) , 'sort' => "{$this->query_filter['sort']}-{$this->query_filter['order']}" ) ; $ this -> setData ( 'navbar' , $ this -> render ( 'category/navbar' , $ data ) ) ; }
|
Sets navigation bar on the category page
|
54,919
|
protected function setListProductCategory ( ) { $ options = $ this -> query_filter ; $ options [ 'placeholder' ] = true ; $ conditions = array ( 'limit' => $ this -> data_limit , 'category_id' => $ this -> data_category [ 'category_id' ] ) + $ this -> query_filter ; $ this -> data_products = $ this -> getProducts ( $ conditions , $ options ) ; }
|
Sets an array of products for the category
|
54,920
|
protected function setMetaIndexCategory ( ) { $ this -> setMetaEntity ( $ this -> data_category ) ; if ( empty ( $ this -> data_children ) && empty ( $ this -> data_products ) ) { $ this -> setMeta ( array ( 'name' => 'robots' , 'content' => 'noindex' ) ) ; } }
|
Sets the meta tags on the category page
|
54,921
|
protected function setChildrenCategory ( ) { $ this -> data_children = array ( ) ; foreach ( $ this -> data_categories as $ item ) { if ( in_array ( $ this -> data_category [ 'category_id' ] , $ item [ 'parents' ] ) ) { $ this -> data_children [ ] = $ item ; } } }
|
Sets an array of children categories for the given category
|
54,922
|
protected function setTitleIndexCategory ( ) { $ metatitle = $ this -> data_category [ 'meta_title' ] ; if ( empty ( $ metatitle ) ) { $ metatitle = $ this -> data_category [ 'title' ] ; } $ this -> setTitle ( $ metatitle , false ) ; $ this -> setPageTitle ( $ this -> data_category [ 'title' ] ) ; }
|
Sets titles on the category page
|
54,923
|
protected function setCategory ( $ category_id ) { $ options = array ( 'category_id' => $ category_id , 'language' => $ this -> langcode , 'store_id' => $ this -> store_id ) ; $ this -> data_category = $ this -> category -> get ( $ options ) ; if ( empty ( $ this -> data_category [ 'status' ] ) ) { $ this -> outputHttpStatus ( 404 ) ; } $ this -> prepareCategory ( $ this -> data_category ) ; }
|
Sets a category data
|
54,924
|
public function indexFront ( ) { $ this -> setTitleIndexFront ( ) ; $ this -> setDataCollectionFront ( 'page' ) ; $ this -> setDataCollectionFront ( 'file' ) ; $ this -> setDataCollectionFront ( 'product' ) ; $ this -> outputIndexFront ( ) ; }
|
Displays the store front page
|
54,925
|
protected function setDataCollectionFront ( $ type ) { $ collection_id = $ this -> getStore ( "data.collection_$type" ) ; if ( ! empty ( $ collection_id ) ) { $ conditions = array ( 'collection_id' => $ collection_id ) ; $ options = array ( 'imagestyle' => $ this -> configTheme ( "image_style_collection_$type" ) ) ; $ items = $ this -> getCollectionItems ( $ conditions , array_filter ( $ options ) , $ this -> collection_item ) ; $ this -> setData ( "collection_$type" , $ this -> getWidgetCollection ( $ items ) ) ; } }
|
Adds a collection block
|
54,926
|
public function add ( array $ product , array $ data ) { $ result = array ( ) ; $ this -> hook -> attach ( 'product.compare.add.product.before' , $ product , $ data , $ result , $ this ) ; if ( ! empty ( $ result ) ) { return ( array ) $ result ; } if ( ! $ this -> compare -> add ( $ product [ 'product_id' ] ) ) { return $ this -> getResultError ( ) ; } $ result = $ this -> getResultAdded ( ) ; $ this -> hook -> attach ( 'product.compare.add.product.after' , $ product , $ data , $ result , $ this ) ; return ( array ) $ result ; }
|
Adds a product to comparison and returns an array of results
|
54,927
|
public function delete ( $ product_id ) { $ result = null ; $ this -> hook -> attach ( 'product.compare.delete.product.before' , $ product_id , $ result , $ this ) ; if ( ! empty ( $ result ) ) { return ( array ) $ result ; } if ( ! $ this -> compare -> delete ( $ product_id ) ) { return $ this -> getResultError ( ) ; } $ result = $ this -> getResultDeleted ( ) ; $ this -> hook -> attach ( 'product.compare.delete.product.after' , $ product_id , $ result , $ this ) ; return ( array ) $ result ; }
|
Removes a product from comparison and returns an array of result data
|
54,928
|
protected function getResultAdded ( ) { $ quantity = count ( $ this -> compare -> getList ( ) ) ; if ( $ quantity < $ this -> compare -> getLimit ( ) ) { $ quantity ++ ; } $ message = $ this -> translation -> text ( 'Product has been added to <a href="@url">comparison</a>' , array ( '@url' => $ this -> url -> get ( 'compare' ) ) ) ; return array ( 'redirect' => '' , 'severity' => 'success' , 'quantity' => $ quantity , 'message' => $ message ) ; }
|
Returns an array of resulting data when a product has been added to comparison
|
54,929
|
public function countryCode ( array $ values ) { $ existing = array_filter ( $ values , function ( $ code ) { $ country = $ this -> country -> get ( $ code ) ; return isset ( $ country [ 'code' ] ) ; } ) ; if ( count ( $ values ) != count ( $ existing ) ) { return $ this -> translation -> text ( '@name is unavailable' , array ( '@name' => $ this -> translation -> text ( 'Country' ) ) ) ; } return true ; }
|
Validates the country code condition
|
54,930
|
public function stateId ( array $ values ) { $ count = count ( $ values ) ; $ ids = array_filter ( $ values , 'ctype_digit' ) ; if ( $ count != count ( $ ids ) ) { return $ this -> translation -> text ( '@field has invalid value' , array ( '@field' => $ this -> translation -> text ( 'Condition' ) ) ) ; } $ existing = array_filter ( $ values , function ( $ state_id ) { $ state = $ this -> state -> get ( $ state_id ) ; return isset ( $ state [ 'state_id' ] ) ; } ) ; if ( $ count != count ( $ existing ) ) { return $ this -> translation -> text ( '@name is unavailable' , array ( '@name' => $ this -> translation -> text ( 'Country state' ) ) ) ; } return true ; }
|
Validates the country state condition
|
54,931
|
public function zoneId ( array $ values , $ operator ) { if ( ! in_array ( $ operator , array ( '=' , '!=' ) ) ) { return $ this -> translation -> text ( 'Unsupported operator' ) ; } $ zone = $ this -> zone -> get ( reset ( $ values ) ) ; if ( empty ( $ zone ) ) { return $ this -> translation -> text ( '@name is unavailable' , array ( '@name' => $ this -> translation -> text ( 'Condition' ) ) ) ; } return true ; }
|
Validates a zone ID condition
|
54,932
|
public function listPage ( ) { $ this -> actionPage ( ) ; $ this -> setTitleListPage ( ) ; $ this -> setBreadcrumbListPage ( ) ; $ this -> setFilterListPage ( ) ; $ this -> setPagerListPage ( ) ; $ this -> setData ( 'pages' , $ this -> getListPage ( ) ) ; $ this -> outputListPage ( ) ; }
|
Displays the page overview
|
54,933
|
protected function actionPage ( ) { list ( $ selected , $ action , $ value ) = $ this -> getPostedAction ( ) ; $ deleted = $ updated = 0 ; foreach ( $ selected as $ page_id ) { if ( $ this -> access ( 'page_edit' ) ) { if ( $ action === 'status' ) { $ updated += ( int ) $ this -> page -> update ( $ page_id , array ( 'status' => $ value ) ) ; } else if ( $ action === 'blog_post' ) { $ updated += ( int ) $ this -> page -> update ( $ page_id , array ( 'blog_post' => $ value ) ) ; } } if ( $ action === 'delete' && $ this -> access ( 'page_delete' ) ) { $ deleted += ( int ) $ this -> page -> delete ( $ page_id ) ; } } if ( $ updated > 0 ) { $ this -> setMessage ( $ this -> text ( 'Updated %num item(s)' , array ( '%num' => $ updated ) ) , 'success' ) ; } if ( $ deleted > 0 ) { $ this -> setMessage ( $ this -> text ( 'Deleted %num item(s)' , array ( '%num' => $ deleted ) ) , 'success' ) ; } }
|
Applies an action to the selected pages
|
54,934
|
public function editPage ( $ page_id = null ) { $ this -> setPage ( $ page_id ) ; $ this -> setTitleEditPage ( ) ; $ this -> setBreadcrumbEditPage ( ) ; $ this -> setData ( 'page' , $ this -> data_page ) ; $ this -> setData ( 'languages' , $ this -> language -> getList ( array ( 'enabled' => true ) ) ) ; $ this -> submitEditPage ( ) ; $ this -> setDataImagesEditPage ( ) ; $ this -> setDataCategoriesEditPage ( ) ; $ this -> outputEditPage ( ) ; }
|
Displays the page edit form
|
54,935
|
protected function setPage ( $ page_id ) { $ this -> data_page = array ( ) ; if ( is_numeric ( $ page_id ) ) { $ conditions = array ( 'language' => 'und' , 'page_id' => $ page_id ) ; $ this -> data_page = $ this -> page -> get ( $ conditions ) ; if ( empty ( $ this -> data_page ) ) { $ this -> outputHttpStatus ( 404 ) ; } $ this -> preparePage ( $ this -> data_page ) ; } }
|
Set a page data
|
54,936
|
protected function preparePage ( array & $ page ) { $ user = $ this -> user -> get ( $ page [ 'user_id' ] ) ; $ this -> setItemAlias ( $ page , 'page' , $ this -> alias ) ; $ this -> setItemImages ( $ page , 'page' , $ this -> image ) ; $ this -> setItemTranslation ( $ page , 'page' , $ this -> translation_entity ) ; if ( ! empty ( $ page [ 'images' ] ) ) { foreach ( $ page [ 'images' ] as & $ file ) { $ this -> setItemTranslation ( $ file , 'file' , $ this -> translation_entity ) ; } } $ page [ 'author' ] = isset ( $ user [ 'email' ] ) ? $ user [ 'email' ] : $ this -> text ( 'Unknown' ) ; }
|
Prepares an array of page data
|
54,937
|
protected function submitEditPage ( ) { if ( $ this -> isPosted ( 'delete' ) ) { $ this -> deletePage ( ) ; } else if ( $ this -> isPosted ( 'save' ) && $ this -> validateEditPage ( ) ) { $ this -> deleteImagesPage ( ) ; if ( isset ( $ this -> data_page [ 'page_id' ] ) ) { $ this -> updatePage ( ) ; } else { $ this -> addPage ( ) ; } } }
|
Handles a submitted page
|
54,938
|
protected function deleteImagesPage ( ) { $ this -> controlAccess ( 'page_edit' ) ; $ file_ids = $ this -> getPosted ( 'delete_images' , array ( ) , true , 'array' ) ; return $ this -> image -> delete ( $ file_ids ) ; }
|
Delete page images
|
54,939
|
protected function validateEditPage ( ) { $ this -> setSubmitted ( 'page' , null , false ) ; $ this -> setSubmitted ( 'form' , true ) ; $ this -> setSubmitted ( 'update' , $ this -> data_page ) ; $ this -> setSubmittedBool ( 'status' ) ; $ this -> setSubmittedBool ( 'blog_post' ) ; if ( empty ( $ this -> data_page [ 'page_id' ] ) ) { $ this -> setSubmitted ( 'user_id' , $ this -> uid ) ; } $ this -> validateComponent ( 'page' ) ; return ! $ this -> hasErrors ( ) ; }
|
Validates a submitted page
|
54,940
|
protected function deletePage ( ) { $ this -> controlAccess ( 'page_delete' ) ; if ( $ this -> page -> delete ( $ this -> data_page [ 'page_id' ] ) ) { $ this -> redirect ( 'admin/content/page' , $ this -> text ( 'Page has been deleted' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Page has not been deleted' ) , 'warning' ) ; }
|
Deletes a page
|
54,941
|
protected function setDataImagesEditPage ( ) { $ options = array ( 'entity' => 'page' , 'images' => $ this -> getData ( 'page.images' , array ( ) ) ) ; $ this -> setItemThumb ( $ options , $ this -> image ) ; $ this -> setData ( 'attached_images' , $ this -> getWidgetImages ( $ this -> language , $ options ) ) ; }
|
Adds images on the page edit form
|
54,942
|
protected function setDataCategoriesEditPage ( ) { $ op = array ( 'store_id' => $ this -> getData ( 'page.store_id' , $ this -> store -> getDefault ( ) ) ) ; $ categories = $ this -> getCategoryOptionsByStore ( $ this -> category , $ this -> category_group , $ op ) ; $ this -> setData ( 'categories' , $ categories ) ; }
|
Adds list of categories on the page edit form
|
54,943
|
protected function setTitleEditPage ( ) { if ( isset ( $ this -> data_page [ 'page_id' ] ) ) { $ title = $ this -> text ( 'Edit %name' , array ( '%name' => $ this -> data_page [ 'title' ] ) ) ; } else { $ title = $ this -> text ( 'Add page' ) ; } $ this -> setTitle ( $ title ) ; }
|
Sets titles on the page edit
|
54,944
|
protected function setBreadcrumbEditPage ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'text' => $ this -> text ( 'Pages' ) , 'url' => $ this -> url ( 'admin/content/page' ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
|
Sets breadcrumbs on the page edit
|
54,945
|
public function addIndex ( $ text , $ entity , $ entity_id , $ language ) { $ values = array ( 'text' => $ text , 'entity' => $ entity , 'language' => $ language , 'entity_id' => $ entity_id ) ; return ( bool ) $ this -> db -> insert ( 'search_index' , $ values ) ; }
|
Adds an item to the search index
|
54,946
|
public function deleteIndex ( $ entity , $ entity_id , $ language ) { $ values = array ( 'entity' => $ entity , 'language' => $ language , 'entity_id' => $ entity_id ) ; return ( bool ) $ this -> db -> delete ( 'search_index' , $ values ) ; }
|
Deletes an item from the search index
|
54,947
|
public function setIndex ( $ text , $ entity , $ entity_id , $ language ) { $ this -> deleteIndex ( $ entity , $ entity_id , $ language ) ; if ( empty ( $ text ) ) { return false ; } return $ this -> addIndex ( $ text , $ entity , $ entity_id , $ language ) ; }
|
Sets an item to the search index
|
54,948
|
public function index ( $ handler_id , $ data ) { $ result = null ; $ this -> hook -> attach ( 'search.index' , $ handler_id , $ data , $ result , $ this ) ; if ( isset ( $ result ) ) { return $ result ; } return $ this -> callHandler ( $ handler_id , 'index' , array ( $ data , $ this ) ) ; }
|
Indexes an item
|
54,949
|
public function search ( $ handler_id , $ query , array $ options = array ( ) ) { if ( ! isset ( $ options [ 'language' ] ) ) { $ options [ 'language' ] = 'und' ; } $ result = null ; $ this -> hook -> attach ( 'search' , $ handler_id , $ query , $ options , $ result , $ this ) ; if ( isset ( $ result ) ) { return $ result ; } $ filtered = $ this -> filterStopwords ( $ query , $ options [ 'language' ] ) ; if ( empty ( $ filtered ) ) { return null ; } return $ this -> callHandler ( $ handler_id , 'search' , array ( $ filtered , $ options , $ this ) ) ; }
|
Returns an array of items found for the search query
|
54,950
|
public function callHandler ( $ handler_id , $ method , array $ args ) { try { $ handlers = $ this -> getHandlers ( ) ; return Handler :: call ( $ handlers , $ handler_id , $ method , $ args ) ; } catch ( Exception $ ex ) { return null ; } }
|
Calls a search handler
|
54,951
|
public function getSnippet ( array $ data , $ language ) { $ parts = array ( ) ; if ( isset ( $ data [ 'title' ] ) ) { $ parts = array ( $ data [ 'title' ] , $ data [ 'title' ] ) ; } if ( isset ( $ data [ 'description' ] ) ) { $ parts [ ] = strip_tags ( $ data [ 'description' ] ) ; } $ snippet = $ this -> filterStopwords ( implode ( ' ' , $ parts ) , $ language ) ; $ this -> hook -> attach ( 'search.index.snippet' , $ data , $ language , $ snippet ) ; return $ snippet ; }
|
Returns a text string to be saved in the index table
|
54,952
|
public function filterStopwords ( $ string , $ language ) { $ prepared = trim ( strip_tags ( $ string ) ) ; if ( $ prepared === '' ) { return '' ; } $ stopwords = array ( ) ; $ path = GC_DIR_PRIVATE . "/stopwords/$language.txt" ; if ( is_readable ( $ path ) ) { $ stopwords = array_map ( 'trim' , file ( $ path , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ) ) ; } return implode ( ' ' , array_diff ( explode ( ' ' , $ prepared ) , $ stopwords ) ) ; }
|
Filters out stop - words for a given language
|
54,953
|
protected function parseAllowCredentials ( ServerRequestInterface $ request ) : bool { $ item = $ this -> settings [ 'allowCredentials' ] ; if ( true === is_callable ( $ item ) ) { $ item = call_user_func ( $ item , $ request ) ; } if ( false === is_bool ( $ item ) ) { throw new \ InvalidArgumentException ( 'allowCredentials should be a boolean value' ) ; } return $ item ; }
|
Parse the allow credentials setting .
|
54,954
|
protected function parseMaxAge ( ServerRequestInterface $ request ) : int { $ item = $ this -> settings [ 'maxAge' ] ; if ( true === is_callable ( $ item ) ) { $ item = call_user_func ( $ item , $ request ) ; } if ( false === is_int ( $ item ) ) { throw new \ InvalidArgumentException ( 'maxAge should be an int value' ) ; } if ( $ item < 0 ) { throw new \ InvalidArgumentException ( 'maxAge should be 0 or more' ) ; } return $ item ; }
|
Parse the maxAge setting .
|
54,955
|
protected function addProtocolPortIfNeeded ( string $ matched , array $ parsed ) : string { if ( '' === $ matched || '*' === $ matched ) { $ return = $ matched ; return $ return ; } $ protocol = 'https://' ; $ port = 0 ; if ( true === isset ( $ parsed [ 'scheme' ] ) ) { $ this -> addLog ( 'Parsed a protocol from origin: ' . $ parsed [ 'scheme' ] ) ; $ protocol = $ parsed [ 'scheme' ] . '://' ; } else { $ this -> addLog ( 'Unable to parse protocol/scheme from origin' ) ; } if ( true === isset ( $ parsed [ 'port' ] ) ) { $ this -> addLog ( 'Parsed a port from origin: ' . $ parsed [ 'port' ] ) ; $ port = ( int ) $ parsed [ 'port' ] ; } else { $ this -> addLog ( 'Unable to parse port from origin' ) ; } if ( 0 === $ port ) { if ( 'https://' === $ protocol ) { $ port = 443 ; } else { $ port = 80 ; } } if ( ( 'http://' === $ protocol && 80 === $ port ) || ( 'https://' === $ protocol && 443 === $ port ) ) { $ return = $ protocol . $ matched ; } else { $ return = $ protocol . $ matched . ':' . $ port ; } return $ return ; }
|
Returns the protocol if needed .
|
54,956
|
public function indexProduct ( $ product_id ) { $ this -> setProduct ( $ product_id ) ; $ this -> setMetaIndexProduct ( ) ; $ this -> setTitleIndexProduct ( ) ; $ this -> setBreadcrumbIndexProduct ( ) ; $ this -> setHtmlFilterIndexProduct ( ) ; $ this -> setData ( 'product' , $ this -> data_product ) ; $ this -> setDataSummaryIndexProduct ( ) ; $ this -> setDataImagesIndexProduct ( ) ; $ this -> setDataCartFormIndexProduct ( ) ; $ this -> setDataRatingWidgetIndexProduct ( ) ; $ this -> setDataDescriptionIndexProduct ( ) ; $ this -> setDataAttributesIndexProduct ( ) ; $ this -> setDataReviewsIndexProduct ( ) ; $ this -> setDataRecentIndexProduct ( ) ; $ this -> setDataRelatedIndexProduct ( ) ; $ this -> setDataBundledIndexProduct ( ) ; $ this -> setJsIndexProduct ( ) ; $ this -> outputIndexProduct ( ) ; }
|
Displays the product page
|
54,957
|
protected function setDataSummaryIndexProduct ( ) { $ summary = '' ; if ( ! empty ( $ this -> data_product [ 'description' ] ) ) { $ exploded = $ this -> explodeText ( $ this -> data_product [ 'description' ] ) ; $ summary = strip_tags ( $ exploded [ 0 ] ) ; } $ this -> setData ( 'summary' , $ summary ) ; }
|
Sets the description summary on the product page
|
54,958
|
protected function setDataCartFormIndexProduct ( ) { $ data = array ( 'product' => $ this -> data_product , 'share' => $ this -> getWidgetShare ( ) ) ; $ this -> setData ( 'cart_form' , $ this -> render ( 'cart/add' , $ data , true ) ) ; }
|
Sets the Add to cart form
|
54,959
|
protected function setDataRatingWidgetIndexProduct ( ) { $ data = array ( 'product' => $ this -> data_product , 'rating' => $ this -> rating -> getByProduct ( $ this -> data_product [ 'product_id' ] ) ) ; $ this -> setData ( 'rating' , $ this -> render ( 'common/rating/static' , $ data ) ) ; }
|
Sets the product rating widget
|
54,960
|
protected function setDataDescriptionIndexProduct ( ) { $ description = $ this -> data_product [ 'description' ] ; if ( ! empty ( $ description ) ) { $ exploded = $ this -> explodeText ( $ description ) ; if ( ! empty ( $ exploded [ 1 ] ) ) { $ description = $ exploded [ 1 ] ; } } $ rendered = $ this -> render ( 'product/description' , array ( 'description' => $ description ) ) ; $ this -> setData ( 'description' , $ rendered ) ; }
|
Sets the product description
|
54,961
|
protected function setDataReviewsIndexProduct ( ) { if ( $ this -> config ( 'review_enabled' , 1 ) && ! empty ( $ this -> data_product [ 'total_reviews' ] ) ) { $ pager_options = array ( 'key' => 'rep' , 'total' => $ this -> data_product [ 'total_reviews' ] , 'limit' => ( int ) $ this -> config ( 'review_limit' , 5 ) ) ; $ pager = $ this -> getPager ( $ pager_options ) ; $ data = array ( 'product' => $ this -> data_product , 'pager' => $ pager [ 'rendered' ] , 'reviews' => $ this -> getReviewsProduct ( $ pager [ 'limit' ] ) ) ; $ this -> setData ( 'reviews' , $ this -> render ( 'review/list' , $ data , true ) ) ; } }
|
Sets the product reviews
|
54,962
|
protected function setDataRecentIndexProduct ( ) { $ products = $ this -> getRecentProduct ( ) ; if ( ! empty ( $ products ) ) { $ pager_options = array ( 'key' => 'pwp' , 'total' => count ( $ products ) , 'limit' => $ this -> config ( 'product_view_pager_limit' , 4 ) ) ; $ pager = $ this -> getPager ( $ pager_options ) ; if ( ! empty ( $ pager [ 'limit' ] ) ) { list ( $ from , $ to ) = $ pager [ 'limit' ] ; $ products = array_slice ( $ products , $ from , $ to , true ) ; } $ data = array ( 'pager' => $ pager [ 'rendered' ] , 'products' => $ products ) ; $ this -> setData ( 'recent' , $ this -> render ( 'product/recent' , $ data ) ) ; } }
|
Sets the recent products block
|
54,963
|
protected function setDataRelatedIndexProduct ( ) { $ products = $ this -> getRelatedProduct ( ) ; if ( ! empty ( $ products ) ) { $ pager_options = array ( 'key' => 'rlp' , 'total' => count ( $ products ) , 'limit' => $ this -> config ( 'related_pager_limit' , 4 ) ) ; $ pager = $ this -> getPager ( $ pager_options ) ; if ( ! empty ( $ pager [ 'limit' ] ) ) { list ( $ from , $ to ) = $ pager [ 'limit' ] ; $ products = array_slice ( $ products , $ from , $ to ) ; } $ data = array ( 'products' => $ products , 'pager' => $ pager [ 'rendered' ] ) ; $ this -> setData ( 'related' , $ this -> render ( 'product/related' , $ data ) ) ; } }
|
Sets the related products
|
54,964
|
protected function prepareReviewsProduct ( array & $ reviews ) { if ( ! empty ( $ reviews ) ) { $ users = array ( ) ; foreach ( $ reviews as $ review ) { $ users [ ] = $ review [ 'user_id' ] ; } $ ratings = null ; if ( ! empty ( $ users ) ) { $ ratings = $ this -> rating -> getByUser ( $ this -> data_product [ 'product_id' ] , $ users ) ; } foreach ( $ reviews as & $ review ) { $ rating = array ( 'rating' => 0 ) ; if ( isset ( $ ratings [ $ review [ 'user_id' ] ] [ 'rating' ] ) ) { $ rating [ 'rating' ] = $ ratings [ $ review [ 'user_id' ] ] [ 'rating' ] ; } $ review [ 'rating' ] = $ rating [ 'rating' ] ; $ review [ 'rating_formatted' ] = $ this -> render ( 'common/rating/static' , array ( 'rating' => $ rating ) ) ; } } }
|
Prepare an array of reviews
|
54,965
|
protected function getReviewsProduct ( array $ limit ) { $ options = array ( 'status' => 1 , 'limit' => $ limit , 'user_status' => 1 , 'sort' => 'created' , 'order' => 'desc' , 'product_id' => $ this -> data_product [ 'product_id' ] ) ; $ options += $ this -> query ; $ list = ( array ) $ this -> review -> getList ( $ options ) ; $ this -> prepareReviewsProduct ( $ list ) ; return $ list ; }
|
Returns an array of reviews for the product
|
54,966
|
protected function setBreadcrumbIndexProduct ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( '/' ) , 'text' => $ this -> text ( 'Home' ) ) ; $ categories = $ this -> getCategorytBreadcrumbsProduct ( $ this -> data_product [ 'category_id' ] ) ; $ this -> setBreadcrumbs ( array_merge ( $ breadcrumbs , $ categories ) ) ; }
|
Sets breadcrumbs on the product page
|
54,967
|
protected function buildCategoryBreadcrumbsProduct ( $ category_id , array & $ breadcrumbs ) { if ( ! empty ( $ this -> data_categories [ $ category_id ] [ 'parents' ] ) ) { $ category = $ this -> data_categories [ $ category_id ] ; $ parent = reset ( $ category [ 'parents' ] ) ; $ url = empty ( $ category [ 'alias' ] ) ? "category/$category_id" : $ category [ 'alias' ] ; $ breadcrumb = array ( 'url' => $ this -> url ( $ url ) , 'text' => $ category [ 'title' ] ) ; array_unshift ( $ breadcrumbs , $ breadcrumb ) ; $ this -> buildCategoryBreadcrumbsProduct ( $ parent , $ breadcrumbs ) ; } }
|
Builds an array of breadcrumbs containing all parent categories
|
54,968
|
protected function getTotalReviewsProduct ( array $ product ) { $ options = array ( 'status' => 1 , 'count' => true , 'user_status' => 1 , 'product_id' => $ product [ 'product_id' ] ) ; return ( int ) $ this -> review -> getList ( $ options ) ; }
|
Returns a total number of reviews for the product
|
54,969
|
protected function controlAccessProduct ( ) { if ( empty ( $ this -> data_product [ 'store_id' ] ) || $ this -> data_product [ 'store_id' ] != $ this -> store_id ) { $ this -> outputHttpStatus ( 403 ) ; } if ( empty ( $ this -> data_product [ 'status' ] ) && ! $ this -> access ( 'product' ) ) { $ this -> outputHttpStatus ( 403 ) ; } }
|
Controls access to the product
|
54,970
|
protected function getSelectedCombinationProduct ( array $ product ) { $ field_value_ids = array ( ) ; if ( ! empty ( $ product [ 'default_field_values' ] ) ) { $ field_value_ids = $ product [ 'default_field_values' ] ; } $ selected = $ this -> sku -> selectCombination ( $ product , $ field_value_ids ) ; $ selected += $ product ; return $ selected ; }
|
Returns selected product combination
|
54,971
|
protected function unshiftSelectedImageProduct ( $ selected , & $ product ) { if ( isset ( $ selected [ 'combination' ] [ 'file_id' ] ) && isset ( $ product [ 'images' ] [ $ selected [ 'combination' ] [ 'file_id' ] ] ) ) { $ image = $ product [ 'images' ] [ $ selected [ 'combination' ] [ 'file_id' ] ] ; unset ( $ product [ 'images' ] [ $ selected [ 'combination' ] [ 'file_id' ] ] ) ; $ product [ 'images' ] = array ( $ image [ 'file_id' ] => $ image ) + $ product [ 'images' ] ; } }
|
Put default selected image on the first position
|
54,972
|
protected function getRelatedProduct ( ) { $ options = array ( 'status' => 1 , 'store_id' => $ this -> store_id , 'product_id' => $ this -> data_product [ 'product_id' ] , 'limit' => array ( 0 , $ this -> config ( 'related_limit' , 12 ) ) ) ; $ product_ids = ( array ) $ this -> product -> getRelated ( $ options ) ; $ products = array ( ) ; if ( ! empty ( $ product_ids ) ) { $ products = ( array ) $ this -> product -> getList ( array ( 'product_id' => $ product_ids ) ) ; } $ this -> prepareEntityItems ( $ products , array ( 'entity' => 'product' ) ) ; return $ products ; }
|
Returns an array of related products
|
54,973
|
protected function getRecentProduct ( ) { $ items = $ this -> product_view -> set ( $ this -> data_product [ 'product_id' ] , $ this -> cart_uid ) ; $ product_ids = array ( ) ; foreach ( ( array ) $ items as $ id => $ item ) { if ( $ item [ 'product_id' ] != $ this -> data_product [ 'product_id' ] ) { $ product_ids [ $ id ] = $ item [ 'product_id' ] ; } } if ( empty ( $ product_ids ) ) { return array ( ) ; } $ products = $ this -> getProducts ( array ( 'product_id' => $ product_ids ) ) ; uksort ( $ products , function ( $ key1 , $ key2 ) use ( $ product_ids ) { return ( array_search ( $ key1 , $ product_ids ) < array_search ( $ key2 , $ product_ids ) ) ; } ) ; return $ products ; }
|
Returns an array of recent products
|
54,974
|
protected function setBackendInstances ( ) { $ this -> job = $ this -> getInstance ( 'gplcart\\core\\models\\Job' ) ; $ this -> help = $ this -> getInstance ( 'gplcart\\core\\models\\Help' ) ; $ this -> bookmark = $ this -> getInstance ( 'gplcart\\core\\models\\Bookmark' ) ; }
|
Sets default class instances
|
54,975
|
protected function setBackendData ( ) { $ this -> data [ '_job' ] = $ this -> getWidgetJob ( $ this -> job ) ; $ this -> data [ '_stores' ] = ( array ) $ this -> store -> getList ( ) ; $ this -> data [ '_menu' ] = $ this -> getWidgetAdminMenu ( $ this -> route ) ; $ this -> data [ '_help' ] = $ this -> help -> getByPattern ( $ this -> current_route [ 'simple_pattern' ] , $ this -> langcode ) ; $ bookmarks = $ this -> bookmark -> getList ( array ( 'user_id' => $ this -> uid ) ) ; $ this -> data [ '_is_bookmarked' ] = isset ( $ bookmarks [ $ this -> path ] ) ; $ this -> data [ '_bookmarks' ] = array_splice ( $ bookmarks , 0 , $ this -> config ( 'bookmark_limit' , 5 ) ) ; }
|
Sets default variables for backend templates
|
54,976
|
protected function setCron ( ) { $ interval = ( int ) $ this -> config ( 'cron_interval' , 24 * 60 * 60 ) ; if ( ! empty ( $ interval ) && ( GC_TIME - $ this -> config ( 'cron_last_run' , 0 ) ) > $ interval ) { $ url = $ this -> url ( 'cron' , array ( 'key' => $ this -> config ( 'cron_key' , '' ) ) ) ; $ this -> setJs ( "\$(function(){\$.get('$url', function(data){});});" , array ( 'position' => 'bottom' ) ) ; } }
|
Set up self - executing CRON
|
54,977
|
protected function getPostedAction ( $ message = true ) { $ action = $ this -> getPosted ( 'action' , array ( ) , true , 'array' ) ; if ( ! empty ( $ action ) ) { if ( empty ( $ action [ 'name' ] ) ) { $ error = $ this -> text ( 'An error occurred' ) ; } else if ( empty ( $ action [ 'items' ] ) ) { $ error = $ this -> text ( 'Please select at least one item' ) ; } else { $ parts = explode ( '|' , $ action [ 'name' ] , 2 ) ; return array ( $ action [ 'items' ] , $ parts [ 0 ] , isset ( $ parts [ 1 ] ) ? $ parts [ 1 ] : null ) ; } if ( isset ( $ error ) && $ message ) { $ this -> setMessage ( $ error , 'warning' ) ; } } return array ( array ( ) , null , null ) ; }
|
Returns an array of submitted bulk action
|
54,978
|
public function createService ( ServiceLocatorInterface $ serviceLocator ) { $ em = new EventManager ( ) ; $ em -> setSharedManager ( $ serviceLocator -> get ( 'SharedEventManager' ) ) ; return $ em ; }
|
Create an EventManager instance .
|
54,979
|
public function field ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateField ( ) ; $ this -> validateTitle ( ) ; $ this -> validateWeight ( ) ; $ this -> validateTranslation ( ) ; $ this -> validateTypeField ( ) ; $ this -> validateWidgetField ( ) ; $ this -> unsetSubmitted ( 'update' ) ; return $ this -> getResult ( ) ; }
|
Performs full field data validation
|
54,980
|
protected function validateField ( ) { $ id = $ this -> getUpdatingId ( ) ; if ( $ id === false ) { return null ; } $ data = $ this -> field -> get ( $ id ) ; if ( empty ( $ data ) ) { $ this -> setErrorUnavailable ( 'update' , $ this -> translation -> text ( 'Field' ) ) ; return false ; } $ this -> setUpdating ( $ data ) ; return true ; }
|
Validates a field to be updated
|
54,981
|
protected function validateWidgetField ( ) { $ field = 'widget' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( $ this -> isUpdating ( ) && ! isset ( $ value ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } $ label = $ this -> translation -> text ( 'Widget' ) ; if ( empty ( $ value ) ) { $ this -> setErrorRequired ( $ field , $ label ) ; return false ; } $ types = $ this -> field -> getWidgetTypes ( ) ; if ( empty ( $ types [ $ value ] ) ) { $ this -> setErrorUnavailable ( $ field , $ label ) ; return false ; } return true ; }
|
Validates a field widget type
|
54,982
|
public function uploadMultiple ( $ files , $ handler , $ path = null ) { $ return = array ( 'errors' => array ( ) , 'transferred' => array ( ) ) ; if ( ! gplcart_file_multi_upload ( $ files ) ) { return $ return ; } foreach ( $ files as $ key => $ file ) { $ result = $ this -> upload ( $ file , $ handler , $ path ) ; if ( $ result === true ) { $ return [ 'transferred' ] [ $ key ] = $ this -> getTransferred ( true ) ; } else { $ return [ 'errors' ] [ $ key ] = ( string ) $ result ; } } return $ return ; }
|
Multiple file upload
|
54,983
|
public function download ( $ url , $ handler , $ path = null ) { $ result = $ this -> transferred = null ; $ this -> hook -> attach ( 'file.download.before' , $ url , $ handler , $ path , $ result , $ this ) ; if ( isset ( $ result ) ) { return $ result ; } $ this -> setHandler ( $ handler ) ; $ this -> setDestination ( $ path ) ; try { $ temp = $ this -> downloadTempFile ( $ url ) ; } catch ( Exception $ ex ) { return $ ex -> getMessage ( ) ; } try { $ this -> validateHandler ( $ temp ) ; } catch ( Exception $ ex ) { unlink ( $ temp ) ; return $ ex -> getMessage ( ) ; } try { $ result = $ this -> finalize ( $ temp , $ this -> destination , false ) ; } catch ( Exception $ ex ) { $ result = $ ex -> getMessage ( ) ; } $ this -> hook -> attach ( 'file.download.after' , $ url , $ handler , $ temp , $ result , $ this ) ; return $ result ; }
|
Downloads a file from a remote URL
|
54,984
|
protected function downloadTempFile ( $ url ) { $ temp = $ this -> file -> getTempFile ( ) ; $ fh = fopen ( $ temp , "w" ) ; if ( ! is_resource ( $ fh ) ) { throw new UnexpectedValueException ( $ this -> translation -> text ( 'File handle is not a valid resource' ) ) ; } $ response = $ this -> http -> request ( $ url ) ; fwrite ( $ fh , $ response [ 'data' ] ) ; fclose ( $ fh ) ; return $ temp ; }
|
Writes a temporary file from a remote file
|
54,985
|
protected function finalize ( $ temp , $ to , $ upload ) { if ( ! isset ( $ this -> destination ) ) { $ this -> transferred = $ temp ; return true ; } $ directory = gplcart_file_absolute ( gplcart_file_relative ( $ this -> destination ) ) ; $ pathinfo = $ upload ? pathinfo ( $ to ) : pathinfo ( $ directory ) ; if ( $ upload ) { $ filename = $ this -> prepareFileName ( $ pathinfo [ 'filename' ] , $ pathinfo [ 'extension' ] ) ; } else { $ filename = $ pathinfo [ 'basename' ] ; $ directory = $ pathinfo [ 'dirname' ] ; } if ( ! file_exists ( $ directory ) && ! mkdir ( $ directory , 0775 , true ) ) { unlink ( $ temp ) ; throw new UnexpectedValueException ( $ this -> translation -> text ( 'Unable to create @name' , array ( '@name' => $ directory ) ) ) ; } $ destination = "$directory/$filename" ; if ( $ upload ) { $ destination = gplcart_file_unique ( $ destination ) ; } $ copied = copy ( $ temp , $ destination ) ; unlink ( $ temp ) ; if ( ! $ copied ) { throw new UnexpectedValueException ( $ this -> translation -> text ( 'Unable to move @source to @destination' , array ( '@source' => $ temp , '@destination' => $ destination ) ) ) ; } chmod ( $ destination , 0644 ) ; $ this -> transferred = $ destination ; return true ; }
|
Finalize file transfer
|
54,986
|
protected function prepareFileName ( $ filename , $ extension ) { if ( $ this -> config -> get ( 'file_upload_translit' , 1 ) ) { $ filename = $ this -> language -> translit ( $ filename , null ) ; } $ suffix = gplcart_string_random ( 6 ) ; $ clean = gplcart_file_sanitize ( $ filename ) ; return "$clean-$suffix.$extension" ; }
|
Sanitize and transliterate a filename
|
54,987
|
public function validate ( $ path , $ filename = null ) { $ pathinfo = isset ( $ filename ) ? pathinfo ( $ filename ) : pathinfo ( $ path ) ; if ( empty ( $ pathinfo [ 'filename' ] ) ) { return $ this -> translation -> text ( 'Unknown filename' ) ; } if ( empty ( $ pathinfo [ 'extension' ] ) ) { return $ this -> translation -> text ( 'Unknown file extension' ) ; } if ( $ this -> handler === false ) { return true ; } if ( ! isset ( $ this -> handler ) ) { try { $ this -> setHandlerByExtension ( $ pathinfo [ 'extension' ] ) ; } catch ( Exception $ ex ) { return $ ex -> getMessage ( ) ; } } if ( ! isset ( $ this -> destination ) && isset ( $ this -> handler [ 'path' ] ) ) { $ this -> destination = $ this -> handler [ 'path' ] ; } try { return $ this -> validateHandler ( $ path , $ pathinfo [ 'extension' ] ) ; } catch ( Exception $ ex ) { return $ ex -> getMessage ( ) ; } }
|
Validate a file
|
54,988
|
protected function validateHandler ( $ file , $ extension = null ) { if ( empty ( $ this -> handler [ 'validator' ] ) ) { throw new UnexpectedValueException ( $ this -> translation -> text ( 'Unknown handler' ) ) ; } if ( ! empty ( $ this -> handler [ 'extensions' ] ) && isset ( $ extension ) && ! in_array ( $ extension , $ this -> handler [ 'extensions' ] ) ) { throw new RuntimeException ( $ this -> translation -> text ( 'Unsupported file extension' ) ) ; } if ( isset ( $ this -> handler [ 'filesize' ] ) && filesize ( $ file ) > $ this -> handler [ 'filesize' ] ) { throw new RuntimeException ( $ this -> translation -> text ( 'File size exceeds %num bytes' , array ( '%num' => $ this -> handler [ 'filesize' ] ) ) ) ; } $ result = $ this -> validator -> run ( $ this -> handler [ 'validator' ] , $ file , $ this -> handler ) ; if ( $ result !== true ) { throw new UnexpectedValueException ( $ result ) ; } return true ; }
|
Validates a file using a validator
|
54,989
|
public function setHandler ( $ id ) { if ( is_string ( $ id ) ) { $ this -> handler = $ this -> file -> getHandler ( $ id ) ; } else { $ this -> handler = $ id ; } return $ this ; }
|
Sets the current transfer handler
|
54,990
|
protected function setHandlerByExtension ( $ extension ) { if ( ! in_array ( $ extension , $ this -> file -> supportedExtensions ( ) ) ) { throw new RuntimeException ( $ this -> translation -> text ( 'Unsupported file extension' ) ) ; } return $ this -> handler = $ this -> file -> getHandler ( ".$extension" ) ; }
|
Find and set handler by a file extension
|
54,991
|
public function listReportLibrary ( ) { $ this -> setTitleListReportLibrary ( ) ; $ this -> setBreadcrumbListReportLibrary ( ) ; $ this -> setFilterListReportLibrary ( ) ; $ this -> setPagerListReportLibrary ( ) ; $ this -> setData ( 'types' , $ this -> getTypesLibrary ( ) ) ; $ this -> setData ( 'libraries' , ( array ) $ this -> getListReportLibrary ( ) ) ; $ this -> outputListReportLibrary ( ) ; }
|
Displays the library overview page
|
54,992
|
protected function prepareListLibrary ( array & $ list ) { foreach ( $ list as & $ item ) { $ item [ 'status' ] = empty ( $ item [ 'errors' ] ) ; $ item [ 'has_dependencies' ] = ! empty ( $ item [ 'requires' ] ) || ! empty ( $ item [ 'required_by' ] ) ; } }
|
Prepare an array of libraries
|
54,993
|
protected function getTypesLibrary ( ) { $ types = array ( ) ; foreach ( array_keys ( $ this -> library -> getTypes ( ) ) as $ id ) { $ types [ $ id ] = $ this -> text ( ucfirst ( $ id ) ) ; } return $ types ; }
|
Returns an array of library type names
|
54,994
|
public function validateDependencies ( array & $ items , $ enabled = false ) { foreach ( $ items as & $ item ) { $ this -> validateDependency ( $ item , $ items , $ enabled ) ; } return $ items ; }
|
Validates dependency for an array of items
|
54,995
|
protected function validateDependency ( & $ item , $ items , $ enabled = false ) { if ( empty ( $ item [ 'dependencies' ] ) ) { return null ; } foreach ( $ item [ 'dependencies' ] as $ id => $ version ) { if ( ! isset ( $ items [ $ id ] ) ) { $ item [ 'errors' ] [ ] = array ( 'Unknown dependency @id' , array ( '@id' => $ id ) ) ; continue ; } if ( $ enabled && empty ( $ items [ $ id ] [ 'status' ] ) ) { $ item [ 'errors' ] [ ] = array ( 'Requires @id to be enabled' , array ( '@id' => $ items [ $ id ] [ 'name' ] ) ) ; continue ; } $ components = $ this -> getVersionComponents ( $ version ) ; if ( empty ( $ components ) ) { $ item [ 'errors' ] [ ] = array ( 'Unknown version of @name' , array ( '@name' => $ id ) ) ; continue ; } list ( $ operator , $ number ) = $ components ; if ( $ operator === '=' && strpos ( $ number , 'x' ) !== false ) { $ allowed = version_compare ( $ items [ $ id ] [ 'version' ] , $ number ) ; } else { $ allowed = version_compare ( $ items [ $ id ] [ 'version' ] , $ number , $ operator ) ; } if ( ! $ allowed ) { $ item [ 'errors' ] [ ] = array ( 'Requires incompatible version of @name' , array ( '@name' => $ id ) ) ; } } return null ; }
|
Validates dependency for a single item
|
54,996
|
public function getVersionComponents ( $ data ) { $ string = str_replace ( ' ' , '' , $ data ) ; $ matches = array ( ) ; preg_match_all ( '/(^(==|=|!=|<>|>|<|>=|<=)?(?=\d))(.*)/' , $ string , $ matches ) ; if ( empty ( $ matches [ 3 ] [ 0 ] ) ) { return array ( ) ; } $ operator = empty ( $ matches [ 2 ] [ 0 ] ) ? '=' : $ matches [ 2 ] [ 0 ] ; return array ( $ operator , $ matches [ 3 ] [ 0 ] ) ; }
|
Extracts an array of components from strings like > = 1 . 0 . 0
|
54,997
|
public function getDynamicProperty ( $ name , $ default = null ) { return isset ( $ this -> dynamicProperties [ $ name ] ) ? $ this -> dynamicProperties [ $ name ] : $ default ; }
|
Read dynamic property
|
54,998
|
protected function reset ( ) { $ this -> open = null ; $ this -> close = null ; $ this -> model = null ; $ this -> style = $ this -> config -> get ( 'style' ) ; $ this -> elements = [ ] ; }
|
Reset all of the properties
|
54,999
|
public function set ( $ type = null , $ key = null , $ value = null ) { if ( isset ( $ type ) ) { $ this -> request [ $ type ] [ "$key" ] = $ value ; } else { $ this -> request = array ( 'get' => $ _GET , 'post' => $ _POST , 'files' => $ _FILES , 'cookie' => $ _COOKIE ) ; } return $ this ; }
|
Sets a request parameter
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.