BxBaseStudioStore.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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 getModulesList($bWrapInBlock = true)
  138. {
  139. return $this->getTag('modules', $bWrapInBlock);
  140. }
  141. protected function getTemplatesList($bWrapInBlock = true)
  142. {
  143. return $this->getTag('templates', $bWrapInBlock);
  144. }
  145. protected function getLanguagesList($bWrapInBlock = true)
  146. {
  147. return $this->getTag('languages', $bWrapInBlock);
  148. }
  149. protected function getTag($sTag, $bWrapInBlock = true)
  150. {
  151. $sJsObject = $this->getPageJsObject();
  152. $oTemplate = BxDolStudioTemplate::getInstance();
  153. $iStart = (int)bx_get('str_start');
  154. $iPerPage = (int)bx_get('str_per_page');
  155. if(empty($iPerPage))
  156. $iPerPage = $this->iPerPageDefault;
  157. $aProducts = $this->loadTag($sTag, $iStart, $iPerPage + 1);
  158. $oPaginate = new BxTemplPaginate(array(
  159. 'start' => $iStart,
  160. 'per_page' => $iPerPage,
  161. 'on_change_page' => $sJsObject . ".changePagePaginate(this, '" . $sTag . "', {start}, {per_page})"
  162. ));
  163. $oPaginate->setNumFromDataArray($aProducts);
  164. $sContent = $oTemplate->parseHtmlByName('str_products.html', array(
  165. 'list' => $this->displayProducts($aProducts),
  166. 'paginate' => $oPaginate->getSimplePaginate()
  167. ));
  168. if(!$bWrapInBlock)
  169. return $sContent;
  170. return $oTemplate->parseHtmlByName('store.html', array(
  171. 'js_object' => $sJsObject,
  172. 'content' => $this->getBlockCode(array(
  173. 'caption' => '_adm_block_cpt_' . $sTag,
  174. 'items' => $sContent,
  175. ))
  176. ));
  177. }
  178. protected function getPurchasesList()
  179. {
  180. $oTemplate = BxDolStudioTemplate::getInstance();
  181. $aProducts = $this->loadPurchases();
  182. return $oTemplate->parseHtmlByName('store.html', array(
  183. 'js_object' => $this->getPageJsObject(),
  184. 'content' => $this->getBlockCode(array(
  185. 'caption' => '_adm_block_cpt_purchases',
  186. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  187. 'list' => $this->displayProducts($aProducts),
  188. 'paginate' => ''
  189. ))
  190. ))
  191. ));
  192. }
  193. protected function getUpdatesList()
  194. {
  195. $oTemplate = BxDolStudioTemplate::getInstance();
  196. $aUpdates = $this->loadUpdates();
  197. return $oTemplate->parseHtmlByName('store.html', array(
  198. 'js_object' => $this->getPageJsObject(),
  199. 'content' => $this->getBlockCode(array(
  200. 'caption' => '_adm_block_cpt_updates',
  201. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  202. 'list' => $this->displayUpdates($aUpdates),
  203. 'paginate' => ''
  204. ))
  205. ))
  206. ));
  207. }
  208. protected function getCheckoutList()
  209. {
  210. $sJsObject = $this->getPageJsObject();
  211. $oTemplate = BxDolStudioTemplate::getInstance();
  212. //--- Empty cart by vendor if the payment was accepted.
  213. $mixedVendor = bx_get('vendor');
  214. $mixedProducts = bx_get('products');
  215. if($mixedVendor !== false && $mixedProducts !== false) {
  216. $oCart = BxDolStudioCart::getInstance();
  217. $aProducts = explode(',', base64_decode($mixedProducts));
  218. foreach($aProducts as $iId)
  219. $oCart->delete($mixedVendor, $iId);
  220. return $this->getMessage('_adm_block_cpt_checkout', '_adm_msg_modules_success_checkouted');
  221. }
  222. $aVendors = $this->loadCheckout();
  223. if(empty($aVendors))
  224. return $this->getMessage('_adm_block_cpt_checkout', '_Empty');
  225. $sContent = '';
  226. foreach($aVendors as $sName => $aInfo) {
  227. $fTotal = 0;
  228. $sCurrency = '';
  229. foreach($aInfo['products'] as $aProduct) {
  230. $iCount = isset($aInfo['counts'][$aProduct['id']]) ? (int)$aInfo['counts'][$aProduct['id']] : 1;
  231. $fTotal += $iCount * $aProduct['price'];
  232. if($sCurrency == '' && isset($aProduct['currency_sign']))
  233. $sCurrency = $aProduct['currency_sign'];
  234. }
  235. $aMenu = array(
  236. 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),
  237. 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)
  238. );
  239. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_buttons_hor.html', 'menu_id'=> 'timeline-view-all', 'menu_items' => $aMenu));
  240. $sContent .= $this->getBlockCode(array(
  241. 'caption' => _t('_adm_block_cpt_checkout_by_vendor_csign', $sName, $sCurrency, $fTotal),
  242. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  243. 'list' => $this->displayProducts($aInfo['products'], array('is_shopping_cart' => true, 'counts' => $aInfo['counts'])),
  244. 'paginate' => ''
  245. )),
  246. 'panel_bottom' => $oMenu->getCode()
  247. ));
  248. }
  249. return $oTemplate->parseHtmlByName('store.html', array(
  250. 'js_object' => $sJsObject,
  251. 'content' => $sContent
  252. ));
  253. }
  254. protected function getDownloadedList()
  255. {
  256. $sJsObject = $this->getPageJsObject();
  257. $oTemplate = BxDolStudioTemplate::getInstance();
  258. $sContent = $sModules = $sUpdates = "";
  259. $aProducts = $this->loadDownloaded();
  260. //--- Prepare modules.
  261. foreach($aProducts['modules'] as $aModule) {
  262. $sIcon = BxDolStudioUtils::getModuleIcon($aModule, 'store');
  263. $bIcon = strpos($sIcon, '.') === false;
  264. $bInstalled = $aModule['installed'];
  265. $bQueued = !$bInstalled && $this->oDb->isQueued('action', $aModule['dir']);
  266. $sModules .= $oTemplate->parseHtmlByName('str_product_v1.html', array(
  267. 'js_object' => $sJsObject,
  268. 'name' => $aModule['name'],
  269. 'bx_if:icon' => array (
  270. 'condition' => $bIcon,
  271. 'content' => array('icon' => $sIcon),
  272. ),
  273. 'bx_if:image' => array (
  274. 'condition' => !$bIcon,
  275. 'content' => array('icon_url' => $sIcon),
  276. ),
  277. 'title' => $aModule['title'],
  278. 'vendor' => $aModule['vendor'],
  279. 'version' => $aModule['version'],
  280. 'dir' => $aModule['dir'],
  281. 'bx_if:hide_install' => array(
  282. 'condition' => $bInstalled || $bQueued,
  283. 'content' => array()
  284. ),
  285. 'bx_if:hide_queued' => array(
  286. 'condition' => !$bQueued,
  287. 'content' => array()
  288. ),
  289. 'bx_if:hide_installed' => array(
  290. 'condition' => !$bInstalled || $bQueued,
  291. 'content' => array()
  292. )
  293. ));
  294. }
  295. //--- Prepare updates.
  296. foreach($aProducts['updates'] as $aUpdate) {
  297. $sIcon = BxDolStudioUtils::getModuleIcon(array('type' => $aUpdate['module_type'], 'name' => $aUpdate['module_name'], 'dir' => $aUpdate['module_dir']), 'store');
  298. $bIcon = strpos($sIcon, '.') === false;
  299. $sUpdates .= $oTemplate->parseHtmlByName('str_update_v1.html', array(
  300. 'js_object' => $sJsObject,
  301. 'name' => $aUpdate['module_name'],
  302. 'bx_if:icon' => array (
  303. 'condition' => $bIcon,
  304. 'content' => array('icon' => $sIcon),
  305. ),
  306. 'bx_if:image' => array (
  307. 'condition' => !$bIcon,
  308. 'content' => array('icon_url' => $sIcon),
  309. ),
  310. 'title' => $aUpdate['title'],
  311. 'vendor' => $aUpdate['vendor'],
  312. 'versions' => _t('_adm_str_txt_update_from_to', $aUpdate['version_from'], $aUpdate['version_to']),
  313. 'dir' => $aUpdate['dir']
  314. ));
  315. }
  316. if(!empty($sModules))
  317. $sContent .= $this->getBlockCode(array(
  318. 'caption' => '_adm_block_cpt_downloaded_modules',
  319. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  320. 'list' => $sModules,
  321. 'paginate' => ''
  322. )),
  323. ));
  324. if(!empty($sUpdates))
  325. $sContent .= $this->getBlockCode(array(
  326. 'caption' => '_adm_block_cpt_downloaded_updates',
  327. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  328. 'list' => $sUpdates,
  329. 'paginate' => ''
  330. )),
  331. ));
  332. return $oTemplate->parseHtmlByName('store.html', array(
  333. 'js_object' => $sJsObject,
  334. 'content' => $sContent
  335. ));
  336. }
  337. protected function getMessage($sCaption, $sContent, $aActions = array())
  338. {
  339. return BxDolStudioTemplate::getInstance()->parseHtmlByName('store.html', array(
  340. 'js_object' => $this->getPageJsObject(),
  341. 'content' => $this->getBlockCode(array(
  342. 'caption' => $sCaption,
  343. 'actions' => $aActions,
  344. 'items' => MsgBox(_t($sContent))
  345. ))
  346. ));
  347. }
  348. protected function getProduct($sModuleName)
  349. {
  350. $sJsObject = $this->getPageJsObject();
  351. $oTemplate = BxDolStudioTemplate::getInstance();
  352. $aProduct = $this->loadProduct($sModuleName);
  353. if(empty($aProduct) || !is_array($aProduct))
  354. return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($aProduct) ? $aProduct : _t('_adm_str_err_no_product_info')));
  355. $aDownloaded = $this->getDownloadedModules(false);
  356. $bFree = (int)$aProduct['is_free'] == 1;
  357. $bPurchased = (int)$aProduct['is_purchased'] == 1;
  358. $bPurchase = !$bFree && !$bPurchased;
  359. $bInCart = $bPurchase && BxDolStudioCart::getInstance()->exists($aProduct['author_name'], $aProduct['id']);
  360. $bDownloadable = (int)$aProduct['is_file'] == 1;
  361. $bDownloaded = array_key_exists($sModuleName, $aDownloaded);
  362. $bDownload = ($bFree || $bPurchased) && $bDownloadable;
  363. $bDiscount = !empty($aProduct['discount']);
  364. $sVersion = $bDownloaded && version_compare($aDownloaded[$sModuleName]['version'], $aProduct['version']) != 0 ? _t('_adm_str_txt_pv_version_mask', $aDownloaded[$sModuleName]['version'], $aProduct['version']) : $aProduct['version'];
  365. $iScreenshots = 0;
  366. $aScreenshots = array();
  367. $bScreenshots = is_array($aProduct['screenshots']) && !empty($aProduct['screenshots']);
  368. if($bScreenshots) {
  369. $iScreenshots = count($aProduct['screenshots']);
  370. foreach($aProduct['screenshots'] as $aScreenshot)
  371. $aScreenshots[] = array(
  372. 'view_url' => $aProduct['url'],
  373. 'image_url' => $aScreenshot['big']
  374. );
  375. }
  376. $sContent = $oTemplate->parseHtmlByname('str_product_view.html', array(
  377. 'id' => $aProduct['id'],
  378. 'title' => $aProduct['title'],
  379. 'url' => $aProduct['url'],
  380. 'author_name' => $aProduct['author_name'],
  381. 'author_url' => $aProduct['author_url'],
  382. 'version' => $sVersion,
  383. 'price' => !$bFree ? _t('_adm_str_txt_price_csign', $aProduct['author_currency_sign'], $aProduct['price']) : _t('_adm_str_txt_price_free'),
  384. 'bx_if:show_discount' => array(
  385. 'condition' => !$bFree && $bDiscount,
  386. 'content' => array(
  387. 'discount' => $bDiscount ? _t('_adm_str_txt_pv_discount_off_csign', $aProduct['discount']['percent'], $aProduct['author_currency_sign'], $aProduct['discount']['save']) : ''
  388. )
  389. ),
  390. 'category' => $aProduct['category'],
  391. 'category_url' => $aProduct['category_url'],
  392. 'tags' => implode(', ', explode(',', $aProduct['tags'])),
  393. 'reviews' => _t('_adm_str_txt_pv_stats_reviews', $aProduct['reviews_cnt']),
  394. 'reviews_url' => $aProduct['reviews_url'],
  395. 'likes' => _t('_adm_str_txt_pv_stats_likes', $aProduct['likes_cnt']),
  396. 'views' => _t('_adm_str_txt_pv_stats_views', $aProduct['views_cnt']),
  397. 'created' => $aProduct['created'],
  398. 'updated' => $aProduct['updated'],
  399. 'description' => $aProduct['description'],
  400. 'bx_if:show_screenshots' => array(
  401. 'condition' => $bScreenshots,
  402. 'content' => array(
  403. 'width' => 222 * $iScreenshots - 20,
  404. 'bx_repeat:screenshots' => $aScreenshots
  405. )
  406. ),
  407. 'bx_if:show_purchase' => array(
  408. 'condition' => $bPurchase && !$bInCart,
  409. 'content' => array(
  410. 'js_object' => $sJsObject,
  411. 'id' => $aProduct['id'],
  412. 'vendor' => $aProduct['author_name'],
  413. )
  414. ),
  415. 'bx_if:show_checkout' => array(
  416. 'condition' => $bPurchase,
  417. 'content' => array(
  418. 'js_object' => $sJsObject,
  419. 'id' => $aProduct['id'],
  420. 'vendor' => $aProduct['author_name'],
  421. 'bx_if:show_as_hidden' => array(
  422. 'condition' => !$bInCart,
  423. 'content' => array()
  424. )
  425. )
  426. ),
  427. 'bx_if:show_download' => array(
  428. 'condition' => $bDownload && !$bDownloaded,
  429. 'content' => array(
  430. 'js_object' => $sJsObject,
  431. 'file_id' => $aProduct['file_id'],
  432. )
  433. ),
  434. 'bx_if:show_download_disabled' => array(
  435. 'condition' => $bDownload && $bDownloaded,
  436. 'content' => array()
  437. ),
  438. ));
  439. return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => '', 'popup' => PopupBox('bx-std-str-popup-product', $aProduct['title'], $sContent, true), 'screenshots' => $iScreenshots);
  440. }
  441. protected function getFile($iFileId)
  442. {
  443. $mixedResult = $this->loadFile($iFileId);
  444. if($mixedResult === true)
  445. return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => _t('_adm_str_msg_download_successfully'));
  446. if(is_string($mixedResult))
  447. return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
  448. if(is_array($mixedResult))
  449. return array_merge(array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_str_err_download_failed')), $mixedResult);
  450. }
  451. protected function getUpdate($sModuleName, $bAutoUpdate = false)
  452. {
  453. $mixedResult = $this->loadUpdate($sModuleName, $bAutoUpdate);
  454. if($mixedResult === true)
  455. return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => _t('_adm_str_msg_download' . ($bAutoUpdate ? '_and_install' : '') . '_successfully'));
  456. if(is_string($mixedResult))
  457. return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
  458. if(is_array($mixedResult))
  459. return array_merge(array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_str_err_download_failed')), $mixedResult);
  460. }
  461. protected function displayProducts($mixedItems, $aParams = array())
  462. {
  463. if(!is_array($mixedItems))
  464. return MsgBox($mixedItems);
  465. $sJsObject = $this->getPageJsObject();
  466. $oTemplate = BxDolStudioTemplate::getInstance();
  467. $aDownloaded = $this->getDownloadedModules();
  468. $bShoppingCart = isset($aParams['is_shopping_cart']) && $aParams['is_shopping_cart'];
  469. $sResult = '';
  470. foreach($mixedItems as $aItem) {
  471. $bFree = (int)$aItem['is_free'] == 1;
  472. $bPurchased = (int)$aItem['is_purchased'] == 1;
  473. $bPurchase = !$bShoppingCart && !$bFree && !$bPurchased;
  474. $bInCart = $bPurchase && BxDolStudioCart::getInstance()->exists($aItem['author'], $aItem['id']);
  475. $bDownloadable = (int)$aItem['is_file'] == 1;
  476. $bDownloaded = in_array($aItem['name'], $aDownloaded);
  477. $bDownload = !$bShoppingCart && ($bFree || $bPurchased) && $bDownloadable;
  478. $bQueued = $this->oDb->isQueued('download', $aItem['name']);
  479. $sPrice = !$bFree ? _t('_adm_str_txt_price_csign', $aItem['currency_sign'], $aItem['price']) : _t('_adm_str_txt_price_free');
  480. $sDiscount = !$bFree && !empty($aItem['discount']) ? _t('_adm_str_txt_discount_csign', $aItem['currency_sign'], $aItem['discount']['price']) : '';
  481. $sIcon = !empty($aItem['thumbnail']['big']) ? $aItem['thumbnail']['big'] : BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  482. $bIcon = strpos($sIcon, '.') === false;
  483. $sResult .= $oTemplate->parseHtmlByName('str_product_v2.html', array(
  484. 'js_object' => $sJsObject,
  485. 'id' => $aItem['id'],
  486. 'name' => $aItem['name'],
  487. 'url' => $aItem['url'],
  488. 'bx_if:icon' => array (
  489. 'condition' => $bIcon,
  490. 'content' => array('icon' => $sIcon),
  491. ),
  492. 'bx_if:image' => array (
  493. 'condition' => !$bIcon,
  494. 'content' => array('icon_url' => $sIcon),
  495. ),
  496. 'title' => $aItem['title'],
  497. 'bx_if:show_vendor_price' => array(
  498. 'condition' => !$bShoppingCart,
  499. 'content' => array(
  500. 'vendor' => $aItem['author'],
  501. 'price' => $sPrice,
  502. 'discount' => $sDiscount,
  503. )
  504. ),
  505. 'bx_if:show_count_price' => array(
  506. 'condition' => $bShoppingCart,
  507. 'content' => array(
  508. 'count' => isset($aParams['counts'][$aItem['id']]) ? (int)$aParams['counts'][$aItem['id']] : 1,
  509. 'price' => $sPrice,
  510. 'discount' => $sDiscount,
  511. )
  512. ),
  513. 'bx_if:show_purchase' => array(
  514. 'condition' => $bPurchase && !$bInCart,
  515. 'content' => array(
  516. 'js_object' => $sJsObject,
  517. 'id' => $aItem['id'],
  518. 'vendor' => $aItem['author']
  519. )
  520. ),
  521. 'bx_if:show_checkout' => array(
  522. 'condition' => $bPurchase,
  523. 'content' => array(
  524. 'js_object' => $sJsObject,
  525. 'id' => $aItem['id'],
  526. 'vendor' => $aItem['author'],
  527. 'bx_if:show_as_hidden' => array(
  528. 'condition' => !$bInCart,
  529. 'content' => array()
  530. )
  531. )
  532. ),
  533. 'bx_if:show_download' => array(
  534. 'condition' => $bDownload && !$bQueued && !$bDownloaded,
  535. 'content' => array(
  536. 'js_object' => $sJsObject,
  537. 'file_id' => $aItem['file_id']
  538. )
  539. ),
  540. 'bx_if:show_download_disabled' => array(
  541. 'condition' => $bDownload && !$bQueued && $bDownloaded,
  542. 'content' => array()
  543. ),
  544. 'bx_if:show_queued_disabled' => array(
  545. 'condition' => $bDownload && $bQueued && !$bDownloaded,
  546. 'content' => array()
  547. ),
  548. 'bx_if:show_delete' => array(
  549. 'condition' => $bShoppingCart,
  550. 'content' => array(
  551. 'js_object' => $sJsObject,
  552. 'id' => $aItem['id'],
  553. 'vendor' => $aItem['author']
  554. )
  555. )
  556. ));
  557. }
  558. return $sResult;
  559. }
  560. protected function displayUpdates($mixedItems, $aParams = array())
  561. {
  562. if(!is_array($mixedItems))
  563. return MsgBox($mixedItems);
  564. if(empty($mixedItems))
  565. return MsgBox(_t('_Empty'));
  566. $sJsObject = $this->getPageJsObject();
  567. $oTemplate = BxDolStudioTemplate::getInstance();
  568. $sResult = '';
  569. foreach($mixedItems as $aItem) {
  570. $bDownloadable = (int)$aItem['is_file'] == 1;
  571. $sIcon = !empty($aItem['thumbnail']['big']) ? $aItem['thumbnail']['big'] : BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  572. $bIcon = strpos($sIcon, '.') === false;
  573. $sResult .= $oTemplate->parseHtmlByName('str_update_v2.html', array(
  574. 'js_object' => $sJsObject,
  575. 'id' => $aItem['id'],
  576. 'name' => $aItem['name'],
  577. 'url' => $aItem['url'],
  578. 'bx_if:icon' => array (
  579. 'condition' => $bIcon,
  580. 'content' => array('icon' => $sIcon),
  581. ),
  582. 'bx_if:image' => array (
  583. 'condition' => !$bIcon,
  584. 'content' => array('icon_url' => $sIcon),
  585. ),
  586. 'title' => $aItem['title'],
  587. 'vendor' => $aItem['author'],
  588. 'versions' => _t('_adm_str_txt_update_from_to', $aItem['file_version'], $aItem['file_version_to']),
  589. 'bx_if:show_download' => array(
  590. 'condition' => $bDownloadable,
  591. 'content' => array(
  592. 'caption' => _t($this->bAuthAccessUpdates ? '_adm_btn_download_submit' : '_adm_btn_install_submit'),
  593. 'on_click' => $sJsObject . "." . ($this->bAuthAccessUpdates ? "getFile(" . $aItem['file_id'] . ", this)" : "getUpdateAndInstall('" . $aItem['name'] . "', this)")
  594. )
  595. )
  596. ));
  597. }
  598. return $sResult;
  599. }
  600. private function getDownloadedModules($bNamesOnly = true)
  601. {
  602. $aModules = BxDolStudioInstallerUtils::getInstance()->getModules(false);
  603. return $bNamesOnly ? array_keys($aModules) : $aModules;
  604. }
  605. }
  606. /** @} */