BxBaseStudioStore.php 26 KB

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