BxBaseStudioStore.php 27 KB

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