1
0

BxBaseStudioStore.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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 DolphinView Dolphin Studio Representation classes
  7. * @ingroup DolphinStudio
  8. * @{
  9. */
  10. bx_import('BxDolStudioStore');
  11. bx_import('BxTemplStudioFunctions');
  12. class BxBaseStudioStore extends BxDolStudioStore
  13. {
  14. protected $iPerPageDefault = 24;
  15. function __construct($sPage = "")
  16. {
  17. parent::__construct($sPage);
  18. }
  19. function getPageCss()
  20. {
  21. return array_merge(parent::getPageCss(), array('modules.css', 'store.css', 'store-media-tablet.css', 'store-media-desktop.css'));
  22. }
  23. function getPageJs()
  24. {
  25. return array_merge(parent::getPageJs(), array('jquery.fancybox.pack.js', 'store.js'));
  26. }
  27. function getPageJsObject()
  28. {
  29. return 'oBxDolStudioStore';
  30. }
  31. function getPageMenu($aMenu = array(), $aMarkers = array())
  32. {
  33. $sJsObject = $this->getPageJsObject();
  34. $oTemplate = BxDolStudioTemplate::getInstance();
  35. $aMenu = array();
  36. $aMenuItems = array(
  37. 'goodies' => array('icon' => 'home'),
  38. 'featured' => array('icon' => 'thumbs-up'),
  39. 'purchases' => array('icon' => 'shopping-cart'),
  40. 'updates' => array('icon' => 'refresh'),
  41. 'checkout' => array('icon' => 'credit-card'),
  42. 'downloaded' => array('icon' => 'list')
  43. );
  44. foreach($aMenuItems as $sMenuItem => $aItem)
  45. $aMenu[] = array(
  46. 'name' => $sMenuItem,
  47. 'icon' => $aItem['icon'],
  48. 'link' => BX_DOL_URL_STUDIO . 'store.php?page=' . $sMenuItem,
  49. 'title' => _t('_adm_lmi_cpt_' . $sMenuItem),
  50. 'selected' => $sMenuItem == $this->sPage
  51. );
  52. bx_import('BxDolStudioCart');
  53. $iCounter = BxDolStudioCart::getInstance()->getCount();
  54. $aMarkers = array(
  55. 'checkout_counter' => $oTemplate->parseHtmlByName('menu_side_counter.html', array(
  56. 'bx_if:hide_counter' => array(
  57. 'condition' => $iCounter <= 0,
  58. 'content' => array()
  59. ),
  60. 'counter' => $iCounter
  61. ))
  62. );
  63. return parent::getPageMenu($aMenu, $aMarkers);
  64. }
  65. function getPageCode($bHidden = false)
  66. {
  67. $sMethod = 'get' . ucfirst($this->sPage) . 'List';
  68. if(!method_exists($this, $sMethod))
  69. return '';
  70. return $this->$sMethod();
  71. }
  72. function getPageContent()
  73. {
  74. $sMethod = 'get' . ucfirst($this->sPage) . 'List';
  75. if(!method_exists($this, $sMethod))
  76. return '';
  77. return $this->$sMethod(false);
  78. }
  79. protected function getGoodiesList()
  80. {
  81. $sJsObject = $this->getPageJsObject();
  82. $oTemplate = BxDolStudioTemplate::getInstance();
  83. $aProducts = $this->loadGoodies();
  84. $aTmplVars = array(
  85. 'js_object' => $sJsObject,
  86. 'bx_repeat:blocks' => array()
  87. );
  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. return $oTemplate->parseHtmlByName('store.html', $aTmplVars);
  102. }
  103. protected function getFeaturedList($bWrapInBlock = true)
  104. {
  105. $sJsObject = $this->getPageJsObject();
  106. $oTemplate = BxDolStudioTemplate::getInstance();
  107. $iStart = (int)bx_get('str_start');
  108. $iPerPage = (int)bx_get('str_per_page');
  109. if(empty($iPerPage))
  110. $iPerPage = $this->iPerPageDefault;
  111. $aProducts = $this->loadFeatured($iStart, $iPerPage + 1);
  112. bx_import('BxTemplPaginate');
  113. $oPaginate = new BxTemplPaginate(array(
  114. 'start' => $iStart,
  115. 'per_page' => $iPerPage,
  116. 'on_change_page' => $sJsObject . ".changePagePaginate(this, 'featured', {start}, {per_page})"
  117. ));
  118. $oPaginate->setNumFromDataArray($aProducts);
  119. $sContent = $oTemplate->parseHtmlByName('str_products.html', array(
  120. 'list' => $this->displayProducts($aProducts),
  121. 'paginate' => $oPaginate->getSimplePaginate()
  122. ));
  123. if(!$bWrapInBlock)
  124. return $sContent;
  125. return $oTemplate->parseHtmlByName('store.html', array(
  126. 'js_object' => $sJsObject,
  127. 'bx_repeat:blocks' => array(
  128. array(
  129. 'caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_featured'), 'actions' => array())),
  130. 'panel_top' => '',
  131. 'items' => $sContent,
  132. 'panel_bottom' => ''
  133. )
  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. bx_import('BxTemplPaginate');
  159. $oPaginate = new BxTemplPaginate(array(
  160. 'start' => $iStart,
  161. 'per_page' => $iPerPage,
  162. 'on_change_page' => $sJsObject . ".changePagePaginate(this, '" . $sTag . "', {start}, {per_page})"
  163. ));
  164. $oPaginate->setNumFromDataArray($aProducts);
  165. $sContent = $oTemplate->parseHtmlByName('str_products.html', array(
  166. 'list' => $this->displayProducts($aProducts),
  167. 'paginate' => $oPaginate->getSimplePaginate()
  168. ));
  169. if(!$bWrapInBlock)
  170. return $sContent;
  171. return $oTemplate->parseHtmlByName('store.html', array(
  172. 'js_object' => $sJsObject,
  173. 'bx_repeat:blocks' => array(
  174. array(
  175. 'caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_' . $sTag), 'actions' => array())),
  176. 'panel_top' => '',
  177. 'items' => $sContent,
  178. 'panel_bottom' => ''
  179. )
  180. )
  181. ));
  182. }
  183. protected function getPurchasesList()
  184. {
  185. $sJsObject = $this->getPageJsObject();
  186. $oTemplate = BxDolStudioTemplate::getInstance();
  187. $aProducts = $this->loadPurchases();
  188. $aTmplVars = array(
  189. 'js_object' => $sJsObject,
  190. 'bx_repeat:blocks' => array(
  191. array(
  192. 'caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_purchases'), 'actions' => array())),
  193. 'panel_top' => '',
  194. 'items' => $this->displayProducts($aProducts),
  195. 'panel_bottom' => ''
  196. )
  197. )
  198. );
  199. return $oTemplate->parseHtmlByName('store.html', $aTmplVars);
  200. }
  201. protected function getUpdatesList()
  202. {
  203. $sJsObject = $this->getPageJsObject();
  204. $oTemplate = BxDolStudioTemplate::getInstance();
  205. $aUpdates = $this->loadUpdates();
  206. $aTmplVars = array(
  207. 'js_object' => $sJsObject,
  208. 'bx_repeat:blocks' => array(
  209. array(
  210. 'caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_updates'), 'actions' => array())),
  211. 'panel_top' => '',
  212. 'items' => $this->displayUpdates($aUpdates),
  213. 'panel_bottom' => '',
  214. )
  215. )
  216. );
  217. return $oTemplate->parseHtmlByName('store.html', $aTmplVars);
  218. }
  219. protected function getCheckoutList()
  220. {
  221. $sJsObject = $this->getPageJsObject();
  222. $oTemplate = BxDolStudioTemplate::getInstance();
  223. //--- Empty cart by vendor if the payment was accepted.
  224. $mixedVendor = bx_get('vendor');
  225. $mixedProducts = bx_get('products');
  226. if($mixedVendor !== false && $mixedProducts !== false) {
  227. bx_import('BxDolStudioCart');
  228. $oCart = BxDolStudioCart::getInstance();
  229. $aProducts = explode(',', base64_decode($mixedProducts));
  230. foreach($aProducts as $iId)
  231. $oCart->delete($mixedVendor, $iId);
  232. return $this->getMessage('_adm_block_cpt_checkout', '_adm_msg_modules_success_checkouted');
  233. }
  234. $aVendors = $this->loadCheckout();
  235. $aTmplVarsBlocks = array();
  236. foreach($aVendors as $sName => $aInfo) {
  237. $fTotal = 0;
  238. $sCurrency = '';
  239. foreach($aInfo['products'] as $aProduct) {
  240. $iCount = isset($aInfo['counts'][$aProduct['id']]) ? (int)$aInfo['counts'][$aProduct['id']] : 1;
  241. $fTotal += $iCount * $aProduct['price'];
  242. if($sCurrency == '' && isset($aProduct['currency_sign']))
  243. $sCurrency = $aProduct['currency_sign'];
  244. }
  245. $aActions = array(
  246. array('name' => 'checkout-' . $sName, 'caption' => '_adm_action_cpt_checkout', 'url' => 'javascript:void(0)', 'onclick' => $sJsObject . ".checkoutCart('" . $sName . "', this);"),
  247. array('name' => 'delete-all-' . $sName, 'caption' => '_adm_action_cpt_delete_all', 'url' => 'javascript:void(0)', 'onclick' => $sJsObject . ".deleteAllFromCart('" . $sName . "', this)")
  248. );
  249. $aTmplVarsBlocks[] = array(
  250. 'caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_checkout_by_vendor_csign', $sName, $sCurrency, $fTotal), 'actions' => $aActions)),
  251. 'panel_top' => '',
  252. 'items' => $this->displayProducts($aInfo['products'], array('is_shopping_cart' => true, 'counts' => $aInfo['counts'])),
  253. 'panel_bottom' => ''
  254. );
  255. }
  256. if(empty($aTmplVarsBlocks))
  257. return $this->getMessage('_adm_block_cpt_checkout', '_Empty');
  258. return $oTemplate->parseHtmlByName('store.html', array(
  259. 'js_object' => $sJsObject,
  260. 'bx_repeat:blocks' => $aTmplVarsBlocks
  261. ));
  262. }
  263. protected function getDownloadedList()
  264. {
  265. $sJsObject = $this->getPageJsObject();
  266. $oTemplate = BxDolStudioTemplate::getInstance();
  267. $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. $sModules .= $oTemplate->parseHtmlByName('str_product_v1.html', array(
  274. 'js_object' => $sJsObject,
  275. 'name' => $aModule['name'],
  276. 'bx_if:icon' => array (
  277. 'condition' => $bIcon,
  278. 'content' => array('icon' => $sIcon),
  279. ),
  280. 'bx_if:image' => array (
  281. 'condition' => !$bIcon,
  282. 'content' => array('icon_url' => $sIcon),
  283. ),
  284. 'title' => $aModule['title'],
  285. 'vendor' => $aModule['vendor'],
  286. 'version' => $aModule['version'],
  287. 'dir' => $aModule['dir'],
  288. 'bx_if:hide_install' => array(
  289. 'condition' => $aModule['installed'],
  290. 'content' => array()
  291. ),
  292. 'bx_if:hide_installed' => array(
  293. 'condition' => !$aModule['installed'],
  294. 'content' => array()
  295. )
  296. ));
  297. }
  298. //--- Prepare updates.
  299. foreach($aProducts['updates'] as $aUpdate) {
  300. $sIcon = BxDolStudioUtils::getModuleIcon(array('type' => $aUpdate['module_type'], 'name' => $aUpdate['module_name'], 'dir' => $aUpdate['module_dir']), 'store');
  301. $bIcon = strpos($sIcon, '.') === false;
  302. $sUpdates .= $oTemplate->parseHtmlByName('str_update_v1.html', array(
  303. 'js_object' => $sJsObject,
  304. 'name' => $aUpdate['module_name'],
  305. 'bx_if:icon' => array (
  306. 'condition' => $bIcon,
  307. 'content' => array('icon' => $sIcon),
  308. ),
  309. 'bx_if:image' => array (
  310. 'condition' => !$bIcon,
  311. 'content' => array('icon_url' => $sIcon),
  312. ),
  313. 'title' => $aUpdate['title'],
  314. 'vendor' => $aUpdate['vendor'],
  315. 'versions' => _t('_adm_str_txt_update_from_to', $aUpdate['version_from'], $aUpdate['version_to']),
  316. 'dir' => $aUpdate['dir']
  317. ));
  318. }
  319. $aTmplVars = array(
  320. 'js_object' => $sJsObject,
  321. 'bx_repeat:blocks' => array(
  322. array(
  323. 'caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_downloaded_modules'), 'actions' => array())),
  324. 'panel_top' => '',
  325. 'items' => $sModules,
  326. 'panel_bottom' => ''
  327. )
  328. )
  329. );
  330. if(!empty($sUpdates))
  331. $aTmplVars['bx_repeat:blocks'][] = array(
  332. 'caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_downloaded_updates'), 'actions' => array())),
  333. 'panel_top' => '',
  334. 'items' => $sUpdates,
  335. 'panel_bottom' => ''
  336. );
  337. return $oTemplate->parseHtmlByName('store.html', $aTmplVars);
  338. }
  339. protected function getMessage($sCaption, $sContent, $aActions = array())
  340. {
  341. $sJsObject = $this->getPageJsObject();
  342. $oTemplate = BxDolStudioTemplate::getInstance();
  343. return $oTemplate->parseHtmlByName('store.html', array(
  344. 'js_object' => $sJsObject,
  345. 'bx_repeat:blocks' => array(
  346. array(
  347. 'caption' => $this->getBlockCaption(array('caption' => _t($sCaption), 'actions' => $aActions)),
  348. 'panel_top' => '',
  349. 'items' => MsgBox(_t($sContent)),
  350. 'panel_bottom' => ''
  351. )
  352. )
  353. ));
  354. }
  355. protected function getProduct($sModuleName)
  356. {
  357. $sJsObject = $this->getPageJsObject();
  358. $oTemplate = BxDolStudioTemplate::getInstance();
  359. $aProduct = $this->loadProduct($sModuleName);
  360. if(empty($aProduct) || !is_array($aProduct))
  361. return array('code' => 1, 'message' => (!empty($aProduct) ? $aProduct : _t('_adm_str_err_no_product_info')));
  362. $aDownloaded = $this->getDownloadedModules(false);
  363. $bFree = (int)$aProduct['is_free'] == 1;
  364. $bPurchased = (int)$aProduct['is_purchased'] == 1;
  365. $bDownloadable = (int)$aProduct['is_file'] == 1;
  366. $bDownloaded = array_key_exists($sModuleName, $aDownloaded);
  367. $bDownload = ($bFree || $bPurchased) && $bDownloadable;
  368. $bDiscount = !empty($aProduct['discount']);
  369. $sVersion = $bDownloaded && version_compare($aDownloaded[$sModuleName]['version'], $aProduct['version']) != 0 ? _t('_adm_str_txt_pv_version_mask', $aDownloaded[$sModuleName]['version'], $aProduct['version']) : $aProduct['version'];
  370. $iScreenshots = 0;
  371. $aScreenshots = array();
  372. $bScreenshots = is_array($aProduct['screenshots']) && !empty($aProduct['screenshots']);
  373. if($bScreenshots) {
  374. $iScreenshots = count($aProduct['screenshots']);
  375. foreach($aProduct['screenshots'] as $aScreenshot)
  376. $aScreenshots[] = array(
  377. 'view_url' => $aProduct['url'],
  378. 'image_url' => $aScreenshot['big']
  379. );
  380. }
  381. $sContent = $oTemplate->parseHtmlByname('str_product_view.html', array(
  382. 'id' => $aProduct['id'],
  383. 'title' => $aProduct['title'],
  384. 'url' => $aProduct['url'],
  385. 'author_name' => $aProduct['author_name'],
  386. 'author_url' => $aProduct['author_url'],
  387. 'version' => $sVersion,
  388. 'price' => !$bFree ? _t('_adm_str_txt_price_csign', $aProduct['author_currency_sign'], $aProduct['price']) : _t('_adm_str_txt_price_free'),
  389. 'bx_if:show_discount' => array(
  390. 'condition' => !$bFree && $bDiscount,
  391. 'content' => array(
  392. 'discount' => $bDiscount ? _t('_adm_str_txt_pv_discount_off_csign', $aProduct['discount']['percent'], $aProduct['author_currency_sign'], $aProduct['discount']['save']) : ''
  393. )
  394. ),
  395. 'category' => $aProduct['category'],
  396. 'category_url' => $aProduct['category_url'],
  397. 'tags' => implode(', ', explode(',', $aProduct['tags'])),
  398. 'reviews' => _t('_adm_str_txt_pv_stats_reviews', $aProduct['reviews_cnt']),
  399. 'reviews_url' => $aProduct['reviews_url'],
  400. 'likes' => _t('_adm_str_txt_pv_stats_likes', $aProduct['likes_cnt']),
  401. 'views' => _t('_adm_str_txt_pv_stats_views', $aProduct['views_cnt']),
  402. 'created' => $aProduct['created'],
  403. 'updated' => $aProduct['updated'],
  404. 'description' => $aProduct['description'],
  405. 'bx_if:show_screenshots' => array(
  406. 'condition' => $bScreenshots,
  407. 'content' => array(
  408. 'width' => 222 * $iScreenshots - 20,
  409. 'bx_repeat:screenshots' => $aScreenshots
  410. )
  411. ),
  412. 'bx_if:show_purchase' => array(
  413. 'condition' => !$bFree && !$bPurchased,
  414. 'content' => array(
  415. 'js_object' => $sJsObject,
  416. 'id' => $aProduct['id'],
  417. 'vendor' => $aProduct['author_name'],
  418. )
  419. ),
  420. 'bx_if:show_download' => array(
  421. 'condition' => $bDownload && !$bDownloaded,
  422. 'content' => array(
  423. 'js_object' => $sJsObject,
  424. 'file_id' => $aProduct['file_id'],
  425. )
  426. ),
  427. 'bx_if:show_download_disabled' => array(
  428. 'condition' => $bDownload && $bDownloaded,
  429. 'content' => array()
  430. ),
  431. ));
  432. return array('code' => 0, 'message' => '', 'popup' => PopupBox('bx-std-str-popup-product', $aProduct['title'], $sContent, true), 'screenshots' => $iScreenshots);
  433. }
  434. /*
  435. * NOTE. Is needed for download popup selector. Isn't used for now.
  436. */
  437. protected function getFiles($iId, $sType)
  438. {
  439. $sJsObject = $this->getPageJsObject();
  440. $oTemplate = BxDolStudioTemplate::getInstance();
  441. $aFiles = $this->loadFiles($iId, $sType);
  442. if(!is_array($aFiles))
  443. return array('code' => 1, 'message' => (!empty($aFiles) ? $aFiles : _t('_adm_str_err_no_files')));
  444. $aTmplVarsFiles = array();
  445. foreach($aFiles as $aFile)
  446. $aTmplVarsFiles[] = array(
  447. 'js_object' => $sJsObject,
  448. 'id' => $aFile['id'],
  449. 'title' => $aFile['name'],
  450. 'version' => empty($aFile['version_to']) ? $aFile['version'] : _t('_adm_str_txt_update_from_to', $aFile['version'], $aFile['version_to']),
  451. );
  452. $sContent = $oTemplate->parseHtmlByName('str_files.html', array(
  453. 'bx_repeat:files' => $aTmplVarsFiles
  454. ));
  455. return array('code' => 0, 'message' => $sContent);
  456. }
  457. protected function getFile($iFileId)
  458. {
  459. $mixedResult = $this->loadFile($iFileId);
  460. if($mixedResult !== true)
  461. return array('code' => 1, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
  462. return array('code' => 0, 'message' => _t('_adm_str_msg_download_successfully'));
  463. }
  464. protected function getUpdate($sModuleName, $bAutoUpdate = false)
  465. {
  466. $mixedResult = $this->loadUpdate($sModuleName, $bAutoUpdate);
  467. if($mixedResult !== true)
  468. return array('code' => 1, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
  469. return array('code' => 0, 'message' => _t('_adm_str_msg_download' . ($bAutoUpdate ? '_and_install' : '') . '_successfully'));
  470. }
  471. protected function displayProducts($aItems, $aParams = array())
  472. {
  473. if(!is_array($aItems))
  474. return $aItems;
  475. $sJsObject = $this->getPageJsObject();
  476. $oTemplate = BxDolStudioTemplate::getInstance();
  477. $aDownloaded = $this->getDownloadedModules();
  478. $bShoppingCart = isset($aParams['is_shopping_cart']) && $aParams['is_shopping_cart'];
  479. $sResult = '';
  480. foreach($aItems as $aItem) {
  481. $bFree = (int)$aItem['is_free'] == 1;
  482. $bPurchased = (int)$aItem['is_purchased'] == 1;
  483. $bDownloadable = (int)$aItem['is_file'] == 1;
  484. $bDownloaded = in_array($aItem['name'], $aDownloaded);
  485. $bDownload = !$bShoppingCart && ($bFree || $bPurchased) && $bDownloadable;
  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 && !$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 && $bDownloaded,
  537. 'content' => array()
  538. ),
  539. 'bx_if:show_delete' => array(
  540. 'condition' => $bShoppingCart,
  541. 'content' => array(
  542. 'js_object' => $sJsObject,
  543. 'id' => $aItem['id'],
  544. 'vendor' => $aItem['author']
  545. )
  546. )
  547. ));
  548. }
  549. return $sResult;
  550. }
  551. protected function displayUpdates($aItems, $aParams = array())
  552. {
  553. if(!is_array($aItems))
  554. return $aItems;
  555. if(empty($aItems))
  556. return MsgBox(_t('_Empty'));
  557. $sJsObject = $this->getPageJsObject();
  558. $oTemplate = BxDolStudioTemplate::getInstance();
  559. $sResult = '';
  560. foreach($aItems as $aItem) {
  561. $bDownloadable = (int)$aItem['is_file'] == 1;
  562. $sIcon = !empty($aItem['thumbnail']['big']) ? $aItem['thumbnail']['big'] : BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  563. $bIcon = strpos($sIcon, '.') === false;
  564. $sResult .= $oTemplate->parseHtmlByName('str_update_v2.html', array(
  565. 'js_object' => $sJsObject,
  566. 'id' => $aItem['id'],
  567. 'name' => $aItem['name'],
  568. 'url' => $aItem['url'],
  569. 'bx_if:icon' => array (
  570. 'condition' => $bIcon,
  571. 'content' => array('icon' => $sIcon),
  572. ),
  573. 'bx_if:image' => array (
  574. 'condition' => !$bIcon,
  575. 'content' => array('icon_url' => $sIcon),
  576. ),
  577. 'title' => $aItem['title'],
  578. 'vendor' => $aItem['author'],
  579. 'versions' => _t('_adm_str_txt_update_from_to', $aItem['file_version'], $aItem['file_version_to']),
  580. 'bx_if:show_download' => array(
  581. 'condition' => $bDownloadable,
  582. 'content' => array(
  583. 'caption' => _t($this->bAuthAccessUpdates ? '_adm_btn_download_submit' : '_adm_btn_install_submit'),
  584. 'on_click' => $sJsObject . "." . ($this->bAuthAccessUpdates ? "getFile(" . $aItem['file_id'] . ", this)" : "getUpdateAndInstall('" . $aItem['name'] . "', this)")
  585. )
  586. )
  587. ));
  588. }
  589. return $sResult;
  590. }
  591. private function getDownloadedModules($bNamesOnly = true)
  592. {
  593. bx_import('BxDolStudioInstallerUtils');
  594. $aModules = BxDolStudioInstallerUtils::getInstance()->getModules(false);
  595. return $bNamesOnly ? array_keys($aModules) : $aModules;
  596. }
  597. }
  598. /** @} */