| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581 |
- <?php
- /**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup DolphinView Dolphin Studio Representation classes
- * @ingroup DolphinStudio
- * @{
- */
- defined('BX_DOL') or die('hack attempt');
- bx_import('BxDolStudioStore');
- bx_import('BxTemplStudioFunctions');
- class BxBaseStudioStore extends BxDolStudioStore {
- protected $iPerPageDefault = 24;
- function BxBaseStudioStore($sPage = "") {
- parent::BxDolStudioStore($sPage);
- }
- function getPageCss() {
- return array_merge(parent::getPageCss(), array('store.css'));
- }
- function getPageJs() {
- return array_merge(parent::getPageJs(), array('jquery.migrate.js', 'jquery.fancybox.js', 'store.js'));
- }
- function getPageJsObject() {
- return 'oBxDolStudioStore';
- }
- function getPageMenu($aMenu = array(), $aMarkers = array()) {
- $sJsObject = $this->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);
- if(!method_exists($this, $sMethod))
- return '';
- return $this->$sMethod();
- }
- function getPageContent() {
- $sMethod = 'get' . ucfirst($this->sPage);
- if(!method_exists($this, $sMethod))
- return '';
- return $this->$sMethod(false);
- }
- protected function getGoodies() {
- $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 getFeatured($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 getModules($bWrapInBlock = true) {
- return $this->getTag('modules', $bWrapInBlock);
- }
- protected function getTemplates($bWrapInBlock = true) {
- return $this->getTag('templates', $bWrapInBlock);
- }
- protected function getLanguages($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 getPurchases() {
- $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 getUpdates() {
- $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 getCheckout() {
- $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 getDownloaded() {
- $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;
- }
- }
- /** @} */
|