BxBaseStudioStore.php 25 KB

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