BxBaseStudioStore.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentView Trident Studio Representation classes
  7. * @ingroup TridentStudio
  8. * @{
  9. */
  10. class BxBaseStudioStore extends BxDolStudioStore
  11. {
  12. protected $iPerPageDefault = 24;
  13. function __construct($sPage = "")
  14. {
  15. parent::__construct($sPage);
  16. }
  17. function getPageCss()
  18. {
  19. return array_merge(parent::getPageCss(), array('modules.css', 'store.css', 'store-media-tablet.css', 'store-media-desktop.css'));
  20. }
  21. function getPageJs()
  22. {
  23. BxDolStudioTemplate::getInstance()->addJsTranslation(array('_adm_btn_queued_submit'));
  24. return array_merge(parent::getPageJs(), array('fancybox/jquery.fancybox.pack.js', 'store.js'));
  25. }
  26. function getPageJsObject()
  27. {
  28. return 'oBxDolStudioStore';
  29. }
  30. function getPageMenu($aMenu = array(), $aMarkers = array())
  31. {
  32. $sJsObject = $this->getPageJsObject();
  33. $oTemplate = BxDolStudioTemplate::getInstance();
  34. $aMenu = array();
  35. $aMenuItems = array(
  36. 'goodies' => array('icon' => 'home'),
  37. 'featured' => array('icon' => 'thumbs-up'),
  38. 'purchases' => array('icon' => 'shopping-cart'),
  39. 'updates' => array('icon' => 'refresh'),
  40. 'checkout' => array('icon' => 'credit-card'),
  41. 'downloaded' => array('icon' => 'list')
  42. );
  43. foreach($aMenuItems as $sMenuItem => $aItem)
  44. $aMenu[] = array(
  45. 'name' => $sMenuItem,
  46. 'icon' => $aItem['icon'],
  47. 'link' => BX_DOL_URL_STUDIO . 'store.php?page=' . $sMenuItem,
  48. 'title' => _t('_adm_lmi_cpt_' . $sMenuItem),
  49. 'selected' => $sMenuItem == $this->sPage
  50. );
  51. $iCounter = BxDolStudioCart::getInstance()->getCount();
  52. $aMarkers = array(
  53. 'checkout_counter' => $oTemplate->parseHtmlByName('menu_side_counter.html', array(
  54. 'bx_if:hide_counter' => array(
  55. 'condition' => $iCounter <= 0,
  56. 'content' => array()
  57. ),
  58. 'counter' => $iCounter
  59. ))
  60. );
  61. return parent::getPageMenu($aMenu, $aMarkers);
  62. }
  63. function getPageCode($bHidden = false)
  64. {
  65. $sMethod = 'get' . ucfirst($this->sPage) . 'List';
  66. if(!method_exists($this, $sMethod))
  67. return '';
  68. return $this->$sMethod();
  69. }
  70. function getPageContent()
  71. {
  72. $sMethod = 'get' . ucfirst($this->sPage) . 'List';
  73. if(!method_exists($this, $sMethod))
  74. return '';
  75. return $this->$sMethod(false);
  76. }
  77. protected function getGoodiesList()
  78. {
  79. $sJsObject = $this->getPageJsObject();
  80. $oTemplate = BxDolStudioTemplate::getInstance();
  81. $mixedResult = BxDolStudioInstallerUtils::getInstance()->getAccessObject(true)->doAuthorize();
  82. if($mixedResult === true) {
  83. $aProducts = $this->loadGoodies();
  84. $sContent = "";
  85. foreach($aProducts as $aBlock) {
  86. $aBlock['items'] = $oTemplate->parseHtmlByName('str_products.html', array(
  87. 'list' => $this->displayProducts($aBlock['items']),
  88. 'paginate' => ''
  89. ));
  90. $sContent .= $this->getBlockCode($aBlock);
  91. }
  92. }
  93. else
  94. $sContent = $this->getBlockCode(array(
  95. 'caption' => '_adm_block_cpt_goodies',
  96. 'items' => $mixedResult,
  97. ));
  98. return $oTemplate->parseHtmlByName('store.html', array(
  99. 'js_object' => $sJsObject,
  100. 'content' => $sContent
  101. ));
  102. }
  103. protected function getFeaturedList($bWrapInBlock = true)
  104. {
  105. $sJsObject = $this->getPageJsObject();
  106. $oTemplate = BxDolStudioTemplate::getInstance();
  107. $mixedResult = BxDolStudioInstallerUtils::getInstance()->getAccessObject(true)->doAuthorize();
  108. if($mixedResult === true) {
  109. $iStart = (int)bx_get('str_start');
  110. $iPerPage = (int)bx_get('str_per_page');
  111. if(empty($iPerPage))
  112. $iPerPage = $this->iPerPageDefault;
  113. $aProducts = $this->loadFeatured($iStart, $iPerPage + 1);
  114. $oPaginate = new BxTemplPaginate(array(
  115. 'start' => $iStart,
  116. 'per_page' => $iPerPage,
  117. 'on_change_page' => $sJsObject . ".changePagePaginate(this, 'featured', {start}, {per_page})"
  118. ));
  119. $oPaginate->setNumFromDataArray($aProducts);
  120. $sContent = $oTemplate->parseHtmlByName('str_products.html', array(
  121. 'list' => $this->displayProducts($aProducts),
  122. 'paginate' => $oPaginate->getSimplePaginate()
  123. ));
  124. }
  125. else
  126. $sContent = $mixedResult;
  127. if(!$bWrapInBlock)
  128. return $sContent;
  129. return $oTemplate->parseHtmlByName('store.html', array(
  130. 'js_object' => $sJsObject,
  131. 'content' => $this->getBlockCode(array(
  132. 'caption' => '_adm_block_cpt_featured',
  133. 'items' => $sContent
  134. ))
  135. ));
  136. }
  137. protected function getExtensionsList($bWrapInBlock = true)
  138. {
  139. return $this->getCategory('extensions', $bWrapInBlock);
  140. }
  141. protected function getTemplatesList($bWrapInBlock = true)
  142. {
  143. return $this->getCategory('templates', $bWrapInBlock);
  144. }
  145. protected function getTranslationsList($bWrapInBlock = true)
  146. {
  147. return $this->getCategory('translations', $bWrapInBlock);
  148. }
  149. protected function getTag($sLabel, $bWrapInBlock = true)
  150. {
  151. return $this->getLabel('tag', $sLabel, $bWrapInBlock);
  152. }
  153. protected function getCategory($sLabel, $bWrapInBlock = true)
  154. {
  155. return $this->getLabel('category', $sLabel, $bWrapInBlock);
  156. }
  157. protected function getLabel($sType, $sLabel, $bWrapInBlock = true)
  158. {
  159. $sJsObject = $this->getPageJsObject();
  160. $oTemplate = BxDolStudioTemplate::getInstance();
  161. $iStart = (int)bx_get('str_start');
  162. $iPerPage = (int)bx_get('str_per_page');
  163. if(empty($iPerPage))
  164. $iPerPage = $this->iPerPageDefault;
  165. $sMethod = 'load' . bx_gen_method_name($sType);
  166. $aProducts = $this->$sMethod($sLabel, $iStart, $iPerPage + 1);
  167. $oPaginate = new BxTemplPaginate(array(
  168. 'start' => $iStart,
  169. 'per_page' => $iPerPage,
  170. 'on_change_page' => $sJsObject . ".changePagePaginate(this, '" . $sLabel . "', {start}, {per_page})"
  171. ));
  172. $oPaginate->setNumFromDataArray($aProducts);
  173. $sContent = $oTemplate->parseHtmlByName('str_products.html', array(
  174. 'list' => $this->displayProducts($aProducts),
  175. 'paginate' => $oPaginate->getSimplePaginate()
  176. ));
  177. if(!$bWrapInBlock)
  178. return $sContent;
  179. return $oTemplate->parseHtmlByName('store.html', array(
  180. 'js_object' => $sJsObject,
  181. 'content' => $this->getBlockCode(array(
  182. 'caption' => '_adm_block_cpt_' . $sLabel,
  183. 'items' => $sContent,
  184. ))
  185. ));
  186. }
  187. protected function getPurchasesList()
  188. {
  189. $oTemplate = BxDolStudioTemplate::getInstance();
  190. $aProducts = $this->loadPurchases();
  191. return $oTemplate->parseHtmlByName('store.html', array(
  192. 'js_object' => $this->getPageJsObject(),
  193. 'content' => $this->getBlockCode(array(
  194. 'caption' => '_adm_block_cpt_purchases',
  195. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  196. 'list' => $this->displayProducts($aProducts),
  197. 'paginate' => ''
  198. ))
  199. ))
  200. ));
  201. }
  202. protected function getUpdatesList()
  203. {
  204. $oTemplate = BxDolStudioTemplate::getInstance();
  205. $aUpdates = $this->loadUpdates();
  206. return $oTemplate->parseHtmlByName('store.html', array(
  207. 'js_object' => $this->getPageJsObject(),
  208. 'content' => $this->getBlockCode(array(
  209. 'caption' => '_adm_block_cpt_updates',
  210. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  211. 'list' => $this->displayUpdates($aUpdates),
  212. 'paginate' => ''
  213. ))
  214. ))
  215. ));
  216. }
  217. protected function getCheckoutList()
  218. {
  219. $sJsObject = $this->getPageJsObject();
  220. $oTemplate = BxDolStudioTemplate::getInstance();
  221. //--- Empty cart by vendor if the payment was accepted.
  222. $mixedVendor = bx_get('vendor');
  223. $mixedProducts = bx_get('products');
  224. if($mixedVendor !== false && $mixedProducts !== false) {
  225. $oCart = BxDolStudioCart::getInstance();
  226. $aProducts = explode(',', base64_decode($mixedProducts));
  227. foreach($aProducts as $iId)
  228. $oCart->delete($mixedVendor, $iId);
  229. return $this->getMessage('_adm_block_cpt_checkout', '_adm_msg_modules_success_checkouted');
  230. }
  231. $aVendors = $this->loadCheckout();
  232. if(empty($aVendors))
  233. return $this->getMessage('_adm_block_cpt_checkout', '_Empty');
  234. $sContent = '';
  235. foreach($aVendors as $sName => $aInfo) {
  236. $fTotal = 0;
  237. $sCurrency = '';
  238. foreach($aInfo['products'] as $aProduct) {
  239. $iCount = isset($aInfo['counts'][$aProduct['id']]) ? (int)$aInfo['counts'][$aProduct['id']] : 1;
  240. $fTotal += $iCount * $aProduct['price'];
  241. if($sCurrency == '' && isset($aProduct['currency_sign']))
  242. $sCurrency = $aProduct['currency_sign'];
  243. }
  244. $aMenu = array(
  245. array('id' => 'checkout-' . $sName, 'name' => 'checkout-' . $sName, 'link' => 'javascript:void(0)', 'onclick' => $sJsObject . ".checkoutCart('" . $sName . "', this);", 'target' => '_self', 'title' => '_adm_action_cpt_checkout', 'active' => 1),
  246. array('id' => 'delete-all-' . $sName, 'name' => 'delete-all-' . $sName, 'link' => 'javascript:void(0)', 'onclick' => $sJsObject . ".deleteAllFromCart('" . $sName . "', this)", 'target' => '_self', 'title' => '_adm_action_cpt_delete_all', 'active' => 1)
  247. );
  248. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_buttons_hor.html', 'menu_id'=> 'timeline-view-all', 'menu_items' => $aMenu));
  249. $sContent .= $this->getBlockCode(array(
  250. 'caption' => _t('_adm_block_cpt_checkout_by_vendor_csign', $sName, $sCurrency, $fTotal),
  251. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  252. 'list' => $this->displayProducts($aInfo['products'], array('is_shopping_cart' => true, 'counts' => $aInfo['counts'])),
  253. 'paginate' => ''
  254. )),
  255. 'panel_bottom' => $oMenu->getCode()
  256. ));
  257. }
  258. return $oTemplate->parseHtmlByName('store.html', array(
  259. 'js_object' => $sJsObject,
  260. 'content' => $sContent
  261. ));
  262. }
  263. protected function getDownloadedList()
  264. {
  265. $sJsObject = $this->getPageJsObject();
  266. $oTemplate = BxDolStudioTemplate::getInstance();
  267. $sContent = $sModules = $sUpdates = "";
  268. $aProducts = $this->loadDownloaded();
  269. //--- Prepare modules.
  270. foreach($aProducts['modules'] as $aModule) {
  271. $sIcon = BxDolStudioUtils::getModuleIcon($aModule, 'store');
  272. $bIcon = strpos($sIcon, '.') === false;
  273. $bInstalled = $aModule['installed'];
  274. $bQueued = !$bInstalled && $this->oDb->isQueued('action', $aModule['dir']);
  275. $sModules .= $oTemplate->parseHtmlByName('str_product_v1.html', array(
  276. 'js_object' => $sJsObject,
  277. 'name' => $aModule['name'],
  278. 'bx_if:icon' => array (
  279. 'condition' => $bIcon,
  280. 'content' => array('icon' => $sIcon),
  281. ),
  282. 'bx_if:image' => array (
  283. 'condition' => !$bIcon,
  284. 'content' => array('icon_url' => $sIcon),
  285. ),
  286. 'title' => $aModule['title'],
  287. 'vendor' => $aModule['vendor'],
  288. 'version' => $aModule['version'],
  289. 'dir' => $aModule['dir'],
  290. 'bx_if:hide_install' => array(
  291. 'condition' => $bInstalled || $bQueued,
  292. 'content' => array()
  293. ),
  294. 'bx_if:hide_queued' => array(
  295. 'condition' => !$bQueued,
  296. 'content' => array()
  297. ),
  298. 'bx_if:hide_installed' => array(
  299. 'condition' => !$bInstalled || $bQueued,
  300. 'content' => array()
  301. )
  302. ));
  303. }
  304. //--- Prepare updates.
  305. foreach($aProducts['updates'] as $aUpdate) {
  306. $sIcon = BxDolStudioUtils::getModuleIcon(array('type' => $aUpdate['module_type'], 'name' => $aUpdate['module_name'], 'dir' => $aUpdate['module_dir']), 'store');
  307. $bIcon = strpos($sIcon, '.') === false;
  308. $sUpdates .= $oTemplate->parseHtmlByName('str_update_v1.html', array(
  309. 'js_object' => $sJsObject,
  310. 'name' => $aUpdate['module_name'],
  311. 'bx_if:icon' => array (
  312. 'condition' => $bIcon,
  313. 'content' => array('icon' => $sIcon),
  314. ),
  315. 'bx_if:image' => array (
  316. 'condition' => !$bIcon,
  317. 'content' => array('icon_url' => $sIcon),
  318. ),
  319. 'title' => $aUpdate['title'],
  320. 'vendor' => $aUpdate['vendor'],
  321. 'versions' => _t('_adm_str_txt_update_from_to', $aUpdate['version_from'], $aUpdate['version_to']),
  322. 'dir' => $aUpdate['dir']
  323. ));
  324. }
  325. if(!empty($sModules))
  326. $sContent .= $this->getBlockCode(array(
  327. 'caption' => '_adm_block_cpt_downloaded_modules',
  328. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  329. 'list' => $sModules,
  330. 'paginate' => ''
  331. )),
  332. ));
  333. if(!empty($sUpdates))
  334. $sContent .= $this->getBlockCode(array(
  335. 'caption' => '_adm_block_cpt_downloaded_updates',
  336. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  337. 'list' => $sUpdates,
  338. 'paginate' => ''
  339. )),
  340. ));
  341. return $oTemplate->parseHtmlByName('store.html', array(
  342. 'js_object' => $sJsObject,
  343. 'content' => $sContent
  344. ));
  345. }
  346. protected function getMessage($sCaption, $sContent, $aActions = array())
  347. {
  348. return BxDolStudioTemplate::getInstance()->parseHtmlByName('store.html', array(
  349. 'js_object' => $this->getPageJsObject(),
  350. 'content' => $this->getBlockCode(array(
  351. 'caption' => $sCaption,
  352. 'actions' => $aActions,
  353. 'items' => MsgBox(_t($sContent))
  354. ))
  355. ));
  356. }
  357. protected function getProduct($sModuleName)
  358. {
  359. $sJsObject = $this->getPageJsObject();
  360. $oTemplate = BxDolStudioTemplate::getInstance();
  361. $aProduct = $this->loadProduct($sModuleName);
  362. if(empty($aProduct) || !is_array($aProduct))
  363. return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($aProduct) ? $aProduct : _t('_adm_str_err_no_product_info')));
  364. $aDownloaded = $this->getDownloadedModules(false);
  365. $bFree = (int)$aProduct['is_free'] == 1;
  366. $bPurchased = (int)$aProduct['is_purchased'] == 1;
  367. $bPurchase = !$bFree && !$bPurchased;
  368. $bInCart = $bPurchase && BxDolStudioCart::getInstance()->exists($aProduct['author_name'], $aProduct['id']);
  369. $bDownloadable = (int)$aProduct['is_file'] == 1;
  370. $bDownloaded = array_key_exists($sModuleName, $aDownloaded);
  371. $bDownload = ($bFree || $bPurchased) && $bDownloadable;
  372. $bDiscount = !empty($aProduct['discount']);
  373. $sVersion = $bDownloaded && version_compare($aDownloaded[$sModuleName]['version'], $aProduct['version']) != 0 ? _t('_adm_str_txt_pv_version_mask', $aDownloaded[$sModuleName]['version'], $aProduct['version']) : $aProduct['version'];
  374. $iScreenshots = 0;
  375. $aScreenshots = array();
  376. $bScreenshots = is_array($aProduct['screenshots']) && !empty($aProduct['screenshots']);
  377. if($bScreenshots) {
  378. $iScreenshots = count($aProduct['screenshots']);
  379. foreach($aProduct['screenshots'] as $aScreenshot)
  380. $aScreenshots[] = array(
  381. 'view_url' => $aProduct['url'],
  382. 'image_url' => $aScreenshot['big']
  383. );
  384. }
  385. $sContent = $oTemplate->parseHtmlByname('str_product_view.html', array(
  386. 'id' => $aProduct['id'],
  387. 'title' => $aProduct['title'],
  388. 'url' => $aProduct['url'],
  389. 'author_name' => $aProduct['author_name'],
  390. 'author_url' => $aProduct['author_url'],
  391. 'version' => $sVersion,
  392. 'price' => !$bFree ? _t('_adm_str_txt_price_csign', $aProduct['author_currency_sign'], $aProduct['price']) : _t('_adm_str_txt_price_free'),
  393. 'bx_if:show_discount' => array(
  394. 'condition' => !$bFree && $bDiscount,
  395. 'content' => array(
  396. 'discount' => $bDiscount ? _t('_adm_str_txt_pv_discount_off_csign', $aProduct['discount']['percent'], $aProduct['author_currency_sign'], $aProduct['discount']['save']) : ''
  397. )
  398. ),
  399. 'category' => $aProduct['category'],
  400. 'category_url' => $aProduct['category_url'],
  401. 'tags' => implode(', ', explode(',', $aProduct['tags'])),
  402. 'reviews' => _t('_adm_str_txt_pv_stats_reviews', $aProduct['reviews_cnt']),
  403. 'reviews_url' => $aProduct['reviews_url'],
  404. 'likes' => _t('_adm_str_txt_pv_stats_likes', $aProduct['likes_cnt']),
  405. 'views' => _t('_adm_str_txt_pv_stats_views', $aProduct['views_cnt']),
  406. 'created' => bx_time_js($aProduct['created']),
  407. 'updated' => bx_time_js($aProduct['updated']),
  408. 'description' => $aProduct['description'],
  409. 'bx_if:show_screenshots' => array(
  410. 'condition' => $bScreenshots,
  411. 'content' => array(
  412. 'width' => 222 * $iScreenshots - 20,
  413. 'bx_repeat:screenshots' => $aScreenshots
  414. )
  415. ),
  416. 'bx_if:show_purchase' => array(
  417. 'condition' => $bPurchase && !$bInCart,
  418. 'content' => array(
  419. 'js_object' => $sJsObject,
  420. 'id' => $aProduct['id'],
  421. 'vendor' => $aProduct['author_name'],
  422. )
  423. ),
  424. 'bx_if:show_checkout' => array(
  425. 'condition' => $bPurchase,
  426. 'content' => array(
  427. 'js_object' => $sJsObject,
  428. 'id' => $aProduct['id'],
  429. 'vendor' => $aProduct['author_name'],
  430. 'bx_if:show_as_hidden' => array(
  431. 'condition' => !$bInCart,
  432. 'content' => array()
  433. )
  434. )
  435. ),
  436. 'bx_if:show_download' => array(
  437. 'condition' => $bDownload && !$bDownloaded,
  438. 'content' => array(
  439. 'js_object' => $sJsObject,
  440. 'file_id' => $aProduct['file_id'],
  441. )
  442. ),
  443. 'bx_if:show_download_disabled' => array(
  444. 'condition' => $bDownload && $bDownloaded,
  445. 'content' => array()
  446. ),
  447. ));
  448. return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => '', 'popup' => PopupBox('bx-std-str-popup-product', $aProduct['title'], $sContent, true), 'screenshots' => $iScreenshots);
  449. }
  450. protected function getFile($iFileId)
  451. {
  452. $mixedResult = $this->loadFile($iFileId);
  453. if($mixedResult === true)
  454. return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => _t('_adm_str_msg_download_successfully'));
  455. if(is_string($mixedResult))
  456. return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
  457. if(is_array($mixedResult))
  458. return array_merge(array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_str_err_download_failed')), $mixedResult);
  459. }
  460. protected function getUpdate($sModuleName, $bAutoUpdate = false)
  461. {
  462. $mixedResult = $this->loadUpdate($sModuleName, $bAutoUpdate);
  463. if($mixedResult === true)
  464. return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => _t('_adm_str_msg_download' . ($bAutoUpdate ? '_and_install' : '') . '_successfully'));
  465. if(is_string($mixedResult))
  466. return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
  467. if(is_array($mixedResult))
  468. return array_merge(array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_str_err_download_failed')), $mixedResult);
  469. }
  470. protected function displayProducts($mixedItems, $aParams = array())
  471. {
  472. if(!is_array($mixedItems))
  473. return MsgBox($mixedItems);
  474. $sJsObject = $this->getPageJsObject();
  475. $oTemplate = BxDolStudioTemplate::getInstance();
  476. $aDownloaded = $this->getDownloadedModules();
  477. $bShoppingCart = isset($aParams['is_shopping_cart']) && $aParams['is_shopping_cart'];
  478. $sResult = '';
  479. foreach($mixedItems as $aItem) {
  480. $bFree = (int)$aItem['is_free'] == 1;
  481. $bPurchased = (int)$aItem['is_purchased'] == 1;
  482. $bPurchase = !$bShoppingCart && !$bFree && !$bPurchased;
  483. $bInCart = $bPurchase && BxDolStudioCart::getInstance()->exists($aItem['author'], $aItem['id']);
  484. $bDownloadable = (int)$aItem['is_file'] == 1;
  485. $bDownloaded = in_array($aItem['name'], $aDownloaded);
  486. $bDownload = !$bShoppingCart && ($bFree || $bPurchased) && $bDownloadable;
  487. $bQueued = $this->oDb->isQueued('download', $aItem['name']);
  488. $sPrice = !$bFree ? _t('_adm_str_txt_price_csign', $aItem['currency_sign'], $aItem['price']) : _t('_adm_str_txt_price_free');
  489. $sDiscount = !$bFree && !empty($aItem['discount']) ? _t('_adm_str_txt_discount_csign', $aItem['currency_sign'], $aItem['discount']['price']) : '';
  490. $sIcon = !empty($aItem['thumbnail']['big']) ? $aItem['thumbnail']['big'] : BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  491. $bIcon = strpos($sIcon, '.') === false;
  492. $sResult .= $oTemplate->parseHtmlByName('str_product_v2.html', array(
  493. 'js_object' => $sJsObject,
  494. 'id' => $aItem['id'],
  495. 'name' => $aItem['name'],
  496. 'url' => $aItem['url'],
  497. 'bx_if:icon' => array (
  498. 'condition' => $bIcon,
  499. 'content' => array('icon' => $sIcon),
  500. ),
  501. 'bx_if:image' => array (
  502. 'condition' => !$bIcon,
  503. 'content' => array('icon_url' => $sIcon),
  504. ),
  505. 'title' => $aItem['title'],
  506. 'bx_if:show_vendor_price' => array(
  507. 'condition' => !$bShoppingCart,
  508. 'content' => array(
  509. 'vendor' => $aItem['author'],
  510. 'price' => $sPrice,
  511. 'discount' => $sDiscount,
  512. )
  513. ),
  514. 'bx_if:show_count_price' => array(
  515. 'condition' => $bShoppingCart,
  516. 'content' => array(
  517. 'count' => isset($aParams['counts'][$aItem['id']]) ? (int)$aParams['counts'][$aItem['id']] : 1,
  518. 'price' => $sPrice,
  519. 'discount' => $sDiscount,
  520. )
  521. ),
  522. 'bx_if:show_purchase' => array(
  523. 'condition' => $bPurchase && !$bInCart,
  524. 'content' => array(
  525. 'js_object' => $sJsObject,
  526. 'id' => $aItem['id'],
  527. 'vendor' => $aItem['author']
  528. )
  529. ),
  530. 'bx_if:show_checkout' => array(
  531. 'condition' => $bPurchase,
  532. 'content' => array(
  533. 'js_object' => $sJsObject,
  534. 'id' => $aItem['id'],
  535. 'vendor' => $aItem['author'],
  536. 'bx_if:show_as_hidden' => array(
  537. 'condition' => !$bInCart,
  538. 'content' => array()
  539. )
  540. )
  541. ),
  542. 'bx_if:show_download' => array(
  543. 'condition' => $bDownload && !$bQueued && !$bDownloaded,
  544. 'content' => array(
  545. 'js_object' => $sJsObject,
  546. 'file_id' => $aItem['file_id']
  547. )
  548. ),
  549. 'bx_if:show_download_disabled' => array(
  550. 'condition' => $bDownload && !$bQueued && $bDownloaded,
  551. 'content' => array()
  552. ),
  553. 'bx_if:show_queued_disabled' => array(
  554. 'condition' => $bDownload && $bQueued && !$bDownloaded,
  555. 'content' => array()
  556. ),
  557. 'bx_if:show_delete' => array(
  558. 'condition' => $bShoppingCart,
  559. 'content' => array(
  560. 'js_object' => $sJsObject,
  561. 'id' => $aItem['id'],
  562. 'vendor' => $aItem['author']
  563. )
  564. )
  565. ));
  566. }
  567. return $sResult;
  568. }
  569. protected function displayUpdates($mixedItems, $aParams = array())
  570. {
  571. if(!is_array($mixedItems))
  572. return MsgBox($mixedItems);
  573. if(empty($mixedItems))
  574. return MsgBox(_t('_Empty'));
  575. $sJsObject = $this->getPageJsObject();
  576. $oTemplate = BxDolStudioTemplate::getInstance();
  577. $sResult = '';
  578. foreach($mixedItems as $aItem) {
  579. $bDownloadable = (int)$aItem['is_file'] == 1;
  580. $sIcon = !empty($aItem['thumbnail']['big']) ? $aItem['thumbnail']['big'] : BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  581. $bIcon = strpos($sIcon, '.') === false;
  582. $sResult .= $oTemplate->parseHtmlByName('str_update_v2.html', array(
  583. 'js_object' => $sJsObject,
  584. 'id' => $aItem['id'],
  585. 'name' => $aItem['name'],
  586. 'url' => $aItem['url'],
  587. 'bx_if:icon' => array (
  588. 'condition' => $bIcon,
  589. 'content' => array('icon' => $sIcon),
  590. ),
  591. 'bx_if:image' => array (
  592. 'condition' => !$bIcon,
  593. 'content' => array('icon_url' => $sIcon),
  594. ),
  595. 'title' => $aItem['title'],
  596. 'vendor' => $aItem['author'],
  597. 'versions' => _t('_adm_str_txt_update_from_to', $aItem['file_version'], $aItem['file_version_to']),
  598. 'bx_if:show_download' => array(
  599. 'condition' => $bDownloadable,
  600. 'content' => array(
  601. 'caption' => _t($this->bAuthAccessUpdates ? '_adm_btn_download_submit' : '_adm_btn_install_submit'),
  602. 'on_click' => $sJsObject . "." . ($this->bAuthAccessUpdates ? "getFile(" . $aItem['file_id'] . ", this)" : "getUpdateAndInstall('" . $aItem['name'] . "', this)")
  603. )
  604. )
  605. ));
  606. }
  607. return $sResult;
  608. }
  609. private function getDownloadedModules($bNamesOnly = true)
  610. {
  611. $aModules = BxDolStudioInstallerUtils::getInstance()->getModules(false);
  612. return $bNamesOnly ? array_keys($aModules) : $aModules;
  613. }
  614. }
  615. /** @} */