getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); $aMenu = array(); $aMenuItems = array('goodies', 'featured', 'purchases', 'updates', 'checkout', 'downloaded'); foreach($aMenuItems as $sMenuItem) $aMenu[] = array( 'name' => $sMenuItem, 'icon' => 'mi-str-' . $sMenuItem . '.png', 'link' => BX_DOL_URL_STUDIO . 'store.php?page=' . $sMenuItem, 'title' => _t('_adm_lmi_cpt_' . $sMenuItem), 'selected' => $sMenuItem == $this->sPage ); bx_import('BxDolStudioCart'); $iCounter = BxDolStudioCart::getInstance()->getCount(); $aMarkers = array( 'checkout_counter' => $oTemplate->parseHtmlByName('menu_side_counter.html', array( 'bx_if:hide_counter' => array( 'condition' => $iCounter <= 0, 'content' => array() ), 'counter' => $iCounter )) ); return parent::getPageMenu($aMenu, $aMarkers); } function getPageCode($bHidden = false) { $sMethod = 'get' . ucfirst($this->sPage) . 'List'; if(!method_exists($this, $sMethod)) return ''; return $this->$sMethod(); } function getPageContent() { $sMethod = 'get' . ucfirst($this->sPage) . 'List'; if(!method_exists($this, $sMethod)) return ''; return $this->$sMethod(false); } protected function getGoodiesList() { $sJsObject = $this->getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); $aProducts = $this->loadGoodies(); $aTmplVars = array( 'js_object' => $sJsObject, 'bx_repeat:blocks' => array() ); $sActions = ""; foreach($aProducts as $aBlock) { $sItems = $this->displayProducts($aBlock['items']); $aTmplVars['bx_repeat:blocks'][] = array( 'caption' => $this->getBlockCaption($aBlock), 'items' => $sItems ); } return $oTemplate->parseHtmlByName('store.html', $aTmplVars); } protected function getFeaturedList($bWrapInBlock = true) { $sJsObject = $this->getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); $iStart = (int)bx_get('str_start'); $iPerPage = (int)bx_get('str_per_page'); if(empty($iPerPage)) $iPerPage = $this->iPerPageDefault; $aProducts = $this->loadFeatured($iStart, $iPerPage + 1); bx_import('BxTemplPaginate'); $oPaginate = new BxTemplPaginate(array( 'start' => $iStart, 'per_page' => $iPerPage, 'on_change_page' => $sJsObject . ".changePagePaginate(this, 'featured', {start}, {per_page})" )); $oPaginate->setNumFromDataArray($aProducts); $sContent = $oTemplate->parseHtmlByName('str_products.html', array( 'list' => $this->displayProducts($aProducts), 'paginate' => $oPaginate->getSimplePaginate() )); if(!$bWrapInBlock) return $sContent; return $oTemplate->parseHtmlByName('store.html', array( 'js_object' => $sJsObject, 'bx_repeat:blocks' => array( array( 'caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_featured'), 'actions' => array())), 'items' => $sContent ) ) )); } protected function getModulesList($bWrapInBlock = true) { return $this->getTag('modules', $bWrapInBlock); } protected function getTemplatesList($bWrapInBlock = true) { return $this->getTag('templates', $bWrapInBlock); } protected function getLanguagesList($bWrapInBlock = true) { return $this->getTag('languages', $bWrapInBlock); } protected function getTag($sTag, $bWrapInBlock = true) { $sJsObject = $this->getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); $iStart = (int)bx_get('str_start'); $iPerPage = (int)bx_get('str_per_page'); if(empty($iPerPage)) $iPerPage = $this->iPerPageDefault; $aProducts = $this->loadTag($sTag, $iStart, $iPerPage + 1); bx_import('BxTemplPaginate'); $oPaginate = new BxTemplPaginate(array( 'start' => $iStart, 'per_page' => $iPerPage, 'on_change_page' => $sJsObject . ".changePagePaginate(this, '" . $sTag . "', {start}, {per_page})" )); $oPaginate->setNumFromDataArray($aProducts); $sContent = $oTemplate->parseHtmlByName('str_products.html', array( 'list' => $this->displayProducts($aProducts), 'paginate' => $oPaginate->getSimplePaginate() )); if(!$bWrapInBlock) return $sContent; return $oTemplate->parseHtmlByName('store.html', array( 'js_object' => $sJsObject, 'bx_repeat:blocks' => array( array( 'caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_' . $sTag), 'actions' => array())), 'items' => $sContent ) ) )); } protected function getPurchasesList() { $sJsObject = $this->getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); $aProducts = $this->loadPurchases(); $aTmplVars = array( 'js_object' => $sJsObject, 'bx_repeat:blocks' => array( array( 'caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_purchases'), 'actions' => array())), 'items' => $this->displayProducts($aProducts) ) ) ); return $oTemplate->parseHtmlByName('store.html', $aTmplVars); } protected function getUpdatesList() { $sJsObject = $this->getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); $aUpdates = $this->loadUpdates(); $aTmplVars = array( 'js_object' => $sJsObject, 'bx_repeat:blocks' => array( array( 'caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_updates'), 'actions' => array())), 'items' => $this->displayUpdates($aUpdates) ) ) ); return $oTemplate->parseHtmlByName('store.html', $aTmplVars); } protected function getCheckoutList() { $sJsObject = $this->getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); //--- Empty cart by vendor if the payment was accepted. $mixedVendor = bx_get('vendor'); $mixedProducts = bx_get('products'); if($mixedVendor !== false && $mixedProducts !== false) { bx_import('BxDolStudioCart'); $oCart = BxDolStudioCart::getInstance(); $aProducts = explode(',', base64_decode($mixedProducts)); foreach($aProducts as $iId) $oCart->delete($mixedVendor, $iId); return $this->getMessage('_adm_block_cpt_checkout', '_adm_msg_modules_success_checkouted'); } $aVendors = $this->loadCheckout(); $aTmplVarsBlocks = array(); foreach($aVendors as $sName => $aInfo) { $fTotal = 0; $sCurrency = ''; foreach($aInfo['products'] as $aProduct) { $iCount = isset($aInfo['counts'][$aProduct['id']]) ? (int)$aInfo['counts'][$aProduct['id']] : 1; $fTotal += $iCount * $aProduct['price']; if($sCurrency == '' && isset($aProduct['currency_sign'])) $sCurrency = $aProduct['currency_sign']; } $aActions = array( array('name' => 'checkout-' . $sName, 'caption' => '_adm_action_cpt_checkout', 'url' => 'javascript:void(0)', 'onclick' => $sJsObject . ".checkoutCart('" . $sName . "', this);"), array('name' => 'delete-all-' . $sName, 'caption' => '_adm_action_cpt_delete_all', 'url' => 'javascript:void(0)', 'onclick' => $sJsObject . ".deleteAllFromCart('" . $sName . "', this)") ); $aTmplVarsBlocks[] = array( 'caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_checkout_by_vendor_csign', $sName, $sCurrency, $fTotal), 'actions' => $aActions)), 'items' => $this->displayProducts($aInfo['products'], array('is_shopping_cart' => true, 'counts' => $aInfo['counts'])) ); } if(empty($aTmplVarsBlocks)) return $this->getMessage('_adm_block_cpt_checkout', '_Empty'); return $oTemplate->parseHtmlByName('store.html', array( 'js_object' => $sJsObject, 'bx_repeat:blocks' => $aTmplVarsBlocks )); } protected function getDownloadedList() { $sJsObject = $this->getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); $sModules = $sUpdates = ""; $aProducts = $this->loadDownloaded(); //--- Prepare modules. foreach($aProducts['modules'] as $aModule) { $sIcon = $oTemplate->getIconUrl($aModule['name'] . '@modules/' . $aModule['dir'] . '|std-si.png'); if(empty($sIcon)) $sIcon = $oTemplate->getIconUrl('pi-str-dump.png'); $sModules .= $oTemplate->parseHtmlByName('str_product_v1.html', array( 'js_object' => $sJsObject, 'url' => $aModule['link_market'], 'icon' => $sIcon, 'title' => $aModule['title'], 'vendor' => $aModule['vendor'], 'version' => $aModule['version'], 'dir' => $aModule['dir'], 'bx_if:hide_install' => array( 'condition' => $aModule['installed'], 'content' => array() ), 'bx_if:hide_installed' => array( 'condition' => !$aModule['installed'], 'content' => array() ) )); } //--- Prepare updates. foreach($aProducts['updates'] as $aUpdate) { $sIcon = $oTemplate->getIconUrl($aUpdate['module_name'] . '@modules/' . $aUpdate['module_dir'] . '|std-si.png'); if(empty($sIcon)) $sIcon = $oTemplate->getIconUrl('pi-str-dump.png'); $sUpdates .= $oTemplate->parseHtmlByName('str_update_v1.html', array( 'js_object' => $sJsObject, 'url' => $aUpdate['module_link_market'], 'icon' => $sIcon, 'title' => $aUpdate['title'], 'vendor' => $aUpdate['vendor'], 'versions' => _t('_adm_str_txt_update_from_to', $aUpdate['version_from'], $aUpdate['version_to']), 'dir' => $aUpdate['dir'] )); } $aTmplVars = array( 'js_object' => $sJsObject, 'bx_repeat:blocks' => array( array( 'caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_downloaded_modules'), 'actions' => array())), 'items' => $sModules ) ) ); if(!empty($sUpdates)) $aTmplVars['bx_repeat:blocks'][] = array( 'caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_downloaded_updates'), 'actions' => array())), 'items' => $sUpdates ); return $oTemplate->parseHtmlByName('store.html', $aTmplVars); } protected function getMessage($sCaption, $sContent, $aActions = array()) { $sJsObject = $this->getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); return $oTemplate->parseHtmlByName('store.html', array( 'js_object' => $sJsObject, 'bx_repeat:blocks' => array( array( 'caption' => $this->getBlockCaption(array('caption' => _t($sCaption), 'actions' => $aActions)), 'items' => MsgBox(_t($sContent)) ) ) )); } protected function getProduct($iId) { $sJsObject = $this->getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); $aProduct = $this->loadProduct($iId); if(!is_array($aProduct)) return array('code' => 1, 'message' => (!empty($aProduct) ? $aProduct : _t('_adm_str_err_no_product_info'))); $bFree = (int)$aProduct['is_free'] == 1; $bPurchased = (int)$aProduct['is_purchased'] == 1; $bDownloadable = (int)$aProduct['is_file'] == 1; $bDiscount = !empty($aProduct['discount']); $bScreenshots = is_array($aProduct['screenshots']) && !empty($aProduct['screenshots']); $iScreenshots = 0; $aScreenshots = array(); if($bScreenshots) { $iScreenshots = count($aProduct['screenshots']); foreach($aProduct['screenshots'] as $aScreenshot) $aScreenshots[] = array( 'view_url' => $aProduct['url'], 'image_url' => $aScreenshot['big'] ); } $sContent = $oTemplate->parseHtmlByname('str_product_view.html', array( 'id' => $aProduct['id'], 'title' => $aProduct['title'], 'url' => $aProduct['url'], 'author_name' => $aProduct['author_name'], 'author_url' => $aProduct['author_url'], 'version' => $aProduct['version'], 'price' => !$bFree ? _t('_adm_str_txt_price_csign', $aProduct['author_currency_sign'], $aProduct['price']) : _t('_adm_str_txt_price_free'), 'bx_if:show_discount' => array( 'condition' => !$bFree && $bDiscount, 'content' => array( 'discount' => $bDiscount ? _t('_adm_str_txt_pv_discount_off_csign', $aProduct['discount']['percent'], $aProduct['author_currency_sign'], $aProduct['discount']['save']) : '' ) ), 'category' => $aProduct['category'], 'category_url' => $aProduct['category_url'], 'tags' => implode(', ', explode(',', $aProduct['tags'])), 'reviews' => _t('_adm_str_txt_pv_stats_reviews', $aProduct['reviews_cnt']), 'reviews_url' => $aProduct['reviews_url'], 'likes' => _t('_adm_str_txt_pv_stats_likes', $aProduct['likes_cnt']), 'views' => _t('_adm_str_txt_pv_stats_views', $aProduct['views_cnt']), 'created' => $aProduct['created'], 'updated' => $aProduct['updated'], 'description' => $aProduct['description'], 'bx_if:show_screenshots' => array( 'condition' => $bScreenshots, 'content' => array( 'width' => 222 * $iScreenshots - 20, 'bx_repeat:screenshots' => $aScreenshots ) ), 'bx_if:show_purchase' => array( 'condition' => !$bFree && !$bPurchased, 'content' => array( 'js_object' => $sJsObject, 'id' => $aProduct['id'], 'vendor' => $aProduct['author_name'], ) ), 'bx_if:show_download' => array( 'condition' => ($bFree || $bPurchased) && $bDownloadable, 'content' => array( 'js_object' => $sJsObject, 'id' => $aProduct['id'], 'file_id' => $aProduct['file_id'], ) ) )); return array('code' => 0, 'message' => '', 'popup' => PopupBox('bx-std-str-popup-product', $aProduct['title'], $sContent, true), 'screenshots' => $iScreenshots); } /* * NOTE. Is needed for download popup selector. Isn't used for now. */ protected function getFiles($iId, $sType) { $sJsObject = $this->getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); $aFiles = $this->loadFiles($iId, $sType); if(!is_array($aFiles)) return array('code' => 1, 'message' => (!empty($aFiles) ? $aFiles : _t('_adm_str_err_no_files'))); $aTmplVarsFiles = array(); foreach($aFiles as $aFile) $aTmplVarsFiles[] = array( 'js_object' => $sJsObject, 'product_id' => $iId, 'id' => $aFile['id'], 'title' => $aFile['name'], 'version' => empty($aFile['version_to']) ? $aFile['version'] : _t('_adm_str_txt_update_from_to', $aFile['version'], $aFile['version_to']), ); $sContent = $oTemplate->parseHtmlByName('str_files.html', array( 'bx_repeat:files' => $aTmplVarsFiles )); return array('code' => 0, 'message' => $sContent); } protected function getFile($iId) { $mixedResult = $this->loadFile($iId); if($mixedResult !== true) return array('code' => 1, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed'))); return array('code' => 0, 'message' => _t('_adm_str_msg_download_successfully')); } protected function displayProducts($aItems, $aParams = array()) { if(!is_array($aItems)) return $aItems; $sJsObject = $this->getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); $bShoppingCart = isset($aParams['is_shopping_cart']) && $aParams['is_shopping_cart']; $sResult = ''; foreach($aItems as $aItem) { $bFree = (int)$aItem['is_free'] == 1; $bPurchased = (int)$aItem['is_purchased'] == 1; $bDownloadable = (int)$aItem['is_file'] == 1; $sPrice = !$bFree ? _t('_adm_str_txt_price_csign', $aItem['currency_sign'], $aItem['price']) : _t('_adm_str_txt_price_free'); $sDiscount = !$bFree && !empty($aItem['discount']) ? _t('_adm_str_txt_discount_csign', $aItem['currency_sign'], $aItem['discount']['price']) : ''; $sResult .= $oTemplate->parseHtmlByName('str_product_v2.html', array( 'js_object' => $sJsObject, 'id' => $aItem['id'], 'url' => $aItem['url'], 'icon' => !empty($aItem['thumbnail']['medium']) ? $aItem['thumbnail']['medium'] : $oTemplate->getIconUrl('pi-str-dump.png'), 'title' => $aItem['title'], 'bx_if:show_vendor_price' => array( 'condition' => !$bShoppingCart, 'content' => array( 'vendor' => $aItem['author'], 'price' => $sPrice, 'discount' => $sDiscount, ) ), 'bx_if:show_count_price' => array( 'condition' => $bShoppingCart, 'content' => array( 'count' => isset($aParams['counts'][$aItem['id']]) ? (int)$aParams['counts'][$aItem['id']] : 1, 'price' => $sPrice, 'discount' => $sDiscount, ) ), 'bx_if:show_purchase' => array( 'condition' => !$bShoppingCart && !$bFree && !$bPurchased, 'content' => array( 'js_object' => $sJsObject, 'id' => $aItem['id'], 'vendor' => $aItem['author'] ) ), 'bx_if:show_download' => array( 'condition' => !$bShoppingCart && ($bFree || $bPurchased) && $bDownloadable, 'content' => array( 'js_object' => $sJsObject, 'id' => $aItem['id'], 'file_id' => $aItem['file_id'], ) ), 'bx_if:show_delete' => array( 'condition' => $bShoppingCart, 'content' => array( 'js_object' => $sJsObject, 'id' => $aItem['id'], 'vendor' => $aItem['author'] ) ) )); } return $sResult; } protected function displayUpdates($aItems, $aParams = array()) { if(!is_array($aItems)) return $aItems; $sJsObject = $this->getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); $sResult = ''; foreach($aItems as $aItem) { $bDownloadable = (int)$aItem['is_file'] == 1; $sResult .= $oTemplate->parseHtmlByName('str_update_v2.html', array( 'js_object' => $sJsObject, 'id' => $aItem['id'], 'url' => $aItem['url'], 'icon' => !empty($aItem['thumbnail']['medium']) ? $aItem['thumbnail']['medium'] : $oTemplate->getIconUrl('pi-str-dump.png'), 'title' => $aItem['title'], 'vendor' => $aItem['author'], 'versions' => _t('_adm_str_txt_update_from_to', $aItem['file_version'], $aItem['file_version_to']), 'bx_if:show_download' => array( 'condition' => $bDownloadable, 'content' => array( 'js_object' => $sJsObject, 'id' => $aItem['id'], 'file_id' => $aItem['file_id'], ) ) )); } return $sResult; } } /** @} */