BxBaseStudioStore.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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('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();
  363. $bFree = (int)$aProduct['is_free'] == 1;
  364. $bPurchased = (int)$aProduct['is_purchased'] == 1;
  365. $bDownloadable = (int)$aProduct['is_file'] == 1;
  366. $bDownloaded = in_array($aProduct['name'], $aDownloaded);
  367. $bDownload = ($bFree || $bPurchased) && $bDownloadable;
  368. $bDiscount = !empty($aProduct['discount']);
  369. $bScreenshots = is_array($aProduct['screenshots']) && !empty($aProduct['screenshots']);
  370. $iScreenshots = 0;
  371. $aScreenshots = array();
  372. if($bScreenshots) {
  373. $iScreenshots = count($aProduct['screenshots']);
  374. foreach($aProduct['screenshots'] as $aScreenshot)
  375. $aScreenshots[] = array(
  376. 'view_url' => $aProduct['url'],
  377. 'image_url' => $aScreenshot['big']
  378. );
  379. }
  380. $sContent = $oTemplate->parseHtmlByname('str_product_view.html', array(
  381. 'id' => $aProduct['id'],
  382. 'title' => $aProduct['title'],
  383. 'url' => $aProduct['url'],
  384. 'author_name' => $aProduct['author_name'],
  385. 'author_url' => $aProduct['author_url'],
  386. 'version' => $aProduct['version'],
  387. 'price' => !$bFree ? _t('_adm_str_txt_price_csign', $aProduct['author_currency_sign'], $aProduct['price']) : _t('_adm_str_txt_price_free'),
  388. 'bx_if:show_discount' => array(
  389. 'condition' => !$bFree && $bDiscount,
  390. 'content' => array(
  391. 'discount' => $bDiscount ? _t('_adm_str_txt_pv_discount_off_csign', $aProduct['discount']['percent'], $aProduct['author_currency_sign'], $aProduct['discount']['save']) : ''
  392. )
  393. ),
  394. 'category' => $aProduct['category'],
  395. 'category_url' => $aProduct['category_url'],
  396. 'tags' => implode(', ', explode(',', $aProduct['tags'])),
  397. 'reviews' => _t('_adm_str_txt_pv_stats_reviews', $aProduct['reviews_cnt']),
  398. 'reviews_url' => $aProduct['reviews_url'],
  399. 'likes' => _t('_adm_str_txt_pv_stats_likes', $aProduct['likes_cnt']),
  400. 'views' => _t('_adm_str_txt_pv_stats_views', $aProduct['views_cnt']),
  401. 'created' => $aProduct['created'],
  402. 'updated' => $aProduct['updated'],
  403. 'description' => $aProduct['description'],
  404. 'bx_if:show_screenshots' => array(
  405. 'condition' => $bScreenshots,
  406. 'content' => array(
  407. 'width' => 222 * $iScreenshots - 20,
  408. 'bx_repeat:screenshots' => $aScreenshots
  409. )
  410. ),
  411. 'bx_if:show_purchase' => array(
  412. 'condition' => !$bFree && !$bPurchased,
  413. 'content' => array(
  414. 'js_object' => $sJsObject,
  415. 'id' => $aProduct['id'],
  416. 'vendor' => $aProduct['author_name'],
  417. )
  418. ),
  419. 'bx_if:show_download' => array(
  420. 'condition' => $bDownload && !$bDownloaded,
  421. 'content' => array(
  422. 'js_object' => $sJsObject,
  423. 'file_id' => $aProduct['file_id'],
  424. )
  425. ),
  426. 'bx_if:show_download_disabled' => array(
  427. 'condition' => $bDownload && $bDownloaded,
  428. 'content' => array()
  429. ),
  430. ));
  431. return array('code' => 0, 'message' => '', 'popup' => PopupBox('bx-std-str-popup-product', $aProduct['title'], $sContent, true), 'screenshots' => $iScreenshots);
  432. }
  433. /*
  434. * NOTE. Is needed for download popup selector. Isn't used for now.
  435. */
  436. protected function getFiles($iId, $sType)
  437. {
  438. $sJsObject = $this->getPageJsObject();
  439. $oTemplate = BxDolStudioTemplate::getInstance();
  440. $aFiles = $this->loadFiles($iId, $sType);
  441. if(!is_array($aFiles))
  442. return array('code' => 1, 'message' => (!empty($aFiles) ? $aFiles : _t('_adm_str_err_no_files')));
  443. $aTmplVarsFiles = array();
  444. foreach($aFiles as $aFile)
  445. $aTmplVarsFiles[] = array(
  446. 'js_object' => $sJsObject,
  447. 'id' => $aFile['id'],
  448. 'title' => $aFile['name'],
  449. 'version' => empty($aFile['version_to']) ? $aFile['version'] : _t('_adm_str_txt_update_from_to', $aFile['version'], $aFile['version_to']),
  450. );
  451. $sContent = $oTemplate->parseHtmlByName('str_files.html', array(
  452. 'bx_repeat:files' => $aTmplVarsFiles
  453. ));
  454. return array('code' => 0, 'message' => $sContent);
  455. }
  456. protected function getFile($iFileId)
  457. {
  458. $mixedResult = $this->loadFile($iFileId);
  459. if($mixedResult !== true)
  460. return array('code' => 1, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
  461. return array('code' => 0, 'message' => _t('_adm_str_msg_download_successfully'));
  462. }
  463. protected function getUpdate($sModuleName)
  464. {
  465. $mixedResult = $this->loadUpdate($sModuleName);
  466. if($mixedResult !== true)
  467. return array('code' => 1, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
  468. return array('code' => 0, 'message' => _t('_adm_str_msg_download_successfully'));
  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. $sPrice = !$bFree ? _t('_adm_str_txt_price_csign', $aItem['currency_sign'], $aItem['price']) : _t('_adm_str_txt_price_free');
  486. $sDiscount = !$bFree && !empty($aItem['discount']) ? _t('_adm_str_txt_discount_csign', $aItem['currency_sign'], $aItem['discount']['price']) : '';
  487. $sIcon = !empty($aItem['thumbnail']['big']) ? $aItem['thumbnail']['big'] : BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  488. $bIcon = strpos($sIcon, '.') === false;
  489. $sResult .= $oTemplate->parseHtmlByName('str_product_v2.html', array(
  490. 'js_object' => $sJsObject,
  491. 'id' => $aItem['id'],
  492. 'name' => $aItem['name'],
  493. 'url' => $aItem['url'],
  494. 'bx_if:icon' => array (
  495. 'condition' => $bIcon,
  496. 'content' => array('icon' => $sIcon),
  497. ),
  498. 'bx_if:image' => array (
  499. 'condition' => !$bIcon,
  500. 'content' => array('icon_url' => $sIcon),
  501. ),
  502. 'title' => $aItem['title'],
  503. 'bx_if:show_vendor_price' => array(
  504. 'condition' => !$bShoppingCart,
  505. 'content' => array(
  506. 'vendor' => $aItem['author'],
  507. 'price' => $sPrice,
  508. 'discount' => $sDiscount,
  509. )
  510. ),
  511. 'bx_if:show_count_price' => array(
  512. 'condition' => $bShoppingCart,
  513. 'content' => array(
  514. 'count' => isset($aParams['counts'][$aItem['id']]) ? (int)$aParams['counts'][$aItem['id']] : 1,
  515. 'price' => $sPrice,
  516. 'discount' => $sDiscount,
  517. )
  518. ),
  519. 'bx_if:show_purchase' => array(
  520. 'condition' => !$bShoppingCart && !$bFree && !$bPurchased,
  521. 'content' => array(
  522. 'js_object' => $sJsObject,
  523. 'id' => $aItem['id'],
  524. 'vendor' => $aItem['author']
  525. )
  526. ),
  527. 'bx_if:show_download' => array(
  528. 'condition' => $bDownload && !$bDownloaded,
  529. 'content' => array(
  530. 'js_object' => $sJsObject,
  531. 'file_id' => $aItem['file_id']
  532. )
  533. ),
  534. 'bx_if:show_download_disabled' => array(
  535. 'condition' => $bDownload && $bDownloaded,
  536. 'content' => array()
  537. ),
  538. 'bx_if:show_delete' => array(
  539. 'condition' => $bShoppingCart,
  540. 'content' => array(
  541. 'js_object' => $sJsObject,
  542. 'id' => $aItem['id'],
  543. 'vendor' => $aItem['author']
  544. )
  545. )
  546. ));
  547. }
  548. return $sResult;
  549. }
  550. protected function displayUpdates($aItems, $aParams = array())
  551. {
  552. if(!is_array($aItems))
  553. return $aItems;
  554. if(empty($aItems))
  555. return MsgBox(_t('_Empty'));
  556. $sJsObject = $this->getPageJsObject();
  557. $oTemplate = BxDolStudioTemplate::getInstance();
  558. $sResult = '';
  559. foreach($aItems as $aItem) {
  560. $bDownloadable = (int)$aItem['is_file'] == 1;
  561. $sIcon = !empty($aItem['thumbnail']['big']) ? $aItem['thumbnail']['big'] : BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  562. $bIcon = strpos($sIcon, '.') === false;
  563. $sResult .= $oTemplate->parseHtmlByName('str_update_v2.html', array(
  564. 'js_object' => $sJsObject,
  565. 'id' => $aItem['id'],
  566. 'name' => $aItem['name'],
  567. 'url' => $aItem['url'],
  568. 'bx_if:icon' => array (
  569. 'condition' => $bIcon,
  570. 'content' => array('icon' => $sIcon),
  571. ),
  572. 'bx_if:image' => array (
  573. 'condition' => !$bIcon,
  574. 'content' => array('icon_url' => $sIcon),
  575. ),
  576. 'title' => $aItem['title'],
  577. 'vendor' => $aItem['author'],
  578. 'versions' => _t('_adm_str_txt_update_from_to', $aItem['file_version'], $aItem['file_version_to']),
  579. 'bx_if:show_download' => array(
  580. 'condition' => $bDownloadable,
  581. 'content' => array(
  582. 'on_click' => $sJsObject . "." . ($this->bAuthAccessUpdates ? "getFile(" . $aItem['file_id'] . ", this)" : "getUpdate('" . $aItem['name'] . "', this)")
  583. )
  584. )
  585. ));
  586. }
  587. return $sResult;
  588. }
  589. private function getDownloadedModules()
  590. {
  591. bx_import('BxDolStudioInstallerUtils');
  592. return array_keys(BxDolStudioInstallerUtils::getInstance()->getModules(false));
  593. }
  594. }
  595. /** @} */