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