BxBaseStudioStore.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioStore extends BxDolStudioStore
  11. {
  12. protected $iPerPageDefault = 24;
  13. function __construct($sPage = "")
  14. {
  15. parent::__construct($sPage);
  16. }
  17. function getPageCss()
  18. {
  19. return array_merge(parent::getPageCss(), array('modules.css', 'store.css', 'store-media-tablet.css', 'store-media-desktop.css'));
  20. }
  21. function getPageJs()
  22. {
  23. BxDolStudioTemplate::getInstance()->addJsTranslation(array('_adm_btn_queued_submit'));
  24. return array_merge(parent::getPageJs(), array('fancybox/jquery.fancybox.pack.js', 'store.js'));
  25. }
  26. function getPageJsObject()
  27. {
  28. return 'oBxDolStudioStore';
  29. }
  30. function getPageMenu($aMenu = array(), $aMarkers = array())
  31. {
  32. $sJsObject = $this->getPageJsObject();
  33. $oTemplate = BxDolStudioTemplate::getInstance();
  34. $aMenu = array();
  35. $aMenuItems = array(
  36. 'goodies' => array('icon' => 'home'),
  37. /*
  38. //TODO: Uncomment 'featured' when "Mark As Featured" functionality will be ready.
  39. 'featured' => array('icon' => 'thumbs-up'),
  40. */
  41. 'purchases' => array('icon' => 'shopping-cart'),
  42. 'updates' => array('icon' => 'refresh'),
  43. 'checkout' => array('icon' => 'credit-card'),
  44. 'downloaded' => array('icon' => 'list')
  45. );
  46. foreach($aMenuItems as $sMenuItem => $aItem)
  47. $aMenu[] = array(
  48. 'name' => $sMenuItem,
  49. 'icon' => $aItem['icon'],
  50. 'link' => BX_DOL_URL_STUDIO . 'store.php?page=' . $sMenuItem,
  51. 'title' => _t('_adm_lmi_cpt_' . $sMenuItem),
  52. 'selected' => $sMenuItem == $this->sPage
  53. );
  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. $mixedResult = BxDolStudioInstallerUtils::getInstance()->getAccessObject(true)->doAuthorize();
  85. if($mixedResult === true) {
  86. $aProducts = $this->loadGoodies();
  87. $sContent = "";
  88. foreach($aProducts as $aBlock) {
  89. $aBlock['items'] = $oTemplate->parseHtmlByName('str_products.html', array(
  90. 'list' => $this->displayProducts($aBlock['items']),
  91. 'paginate' => ''
  92. ));
  93. $sContent .= $this->getBlockCode($aBlock);
  94. }
  95. }
  96. else
  97. $sContent = $this->getBlockCode(array(
  98. 'caption' => '_adm_block_cpt_goodies',
  99. 'items' => MsgBox($mixedResult),
  100. ));
  101. return $oTemplate->parseHtmlByName('store.html', array(
  102. 'js_object' => $sJsObject,
  103. 'content' => $sContent
  104. ));
  105. }
  106. protected function getFeaturedList($bWrapInBlock = true)
  107. {
  108. $sJsObject = $this->getPageJsObject();
  109. $oTemplate = BxDolStudioTemplate::getInstance();
  110. $mixedResult = BxDolStudioInstallerUtils::getInstance()->getAccessObject(true)->doAuthorize();
  111. if($mixedResult === true) {
  112. $iStart = (int)bx_get('str_start');
  113. $iPerPage = (int)bx_get('str_per_page');
  114. if(empty($iPerPage))
  115. $iPerPage = $this->iPerPageDefault;
  116. $aProducts = $this->loadFeatured($iStart, $iPerPage + 1);
  117. $oPaginate = new BxTemplPaginate(array(
  118. 'start' => $iStart,
  119. 'per_page' => $iPerPage,
  120. 'on_change_page' => $sJsObject . ".changePagePaginate(this, 'featured', {start}, {per_page})"
  121. ));
  122. $oPaginate->setNumFromDataArray($aProducts);
  123. $sContent = $oTemplate->parseHtmlByName('str_products.html', array(
  124. 'list' => $this->displayProducts($aProducts),
  125. 'paginate' => $oPaginate->getSimplePaginate()
  126. ));
  127. }
  128. else
  129. $sContent = MsgBox($mixedResult);
  130. if(!$bWrapInBlock)
  131. return $sContent;
  132. return $oTemplate->parseHtmlByName('store.html', array(
  133. 'js_object' => $sJsObject,
  134. 'content' => $this->getBlockCode(array(
  135. 'caption' => '_adm_block_cpt_featured',
  136. 'items' => $sContent
  137. ))
  138. ));
  139. }
  140. protected function getExtensionsList($bWrapInBlock = true)
  141. {
  142. return $this->getCategory('extensions', $bWrapInBlock);
  143. }
  144. protected function getTemplatesList($bWrapInBlock = true)
  145. {
  146. return $this->getCategory('templates', $bWrapInBlock);
  147. }
  148. protected function getTranslationsList($bWrapInBlock = true)
  149. {
  150. return $this->getCategory('translations', $bWrapInBlock);
  151. }
  152. protected function getTag($sLabel, $bWrapInBlock = true)
  153. {
  154. return $this->getLabel('tag', $sLabel, $bWrapInBlock);
  155. }
  156. protected function getCategory($sLabel, $bWrapInBlock = true)
  157. {
  158. return $this->getLabel('category', $sLabel, $bWrapInBlock);
  159. }
  160. protected function getLabel($sType, $sLabel, $bWrapInBlock = true)
  161. {
  162. $sJsObject = $this->getPageJsObject();
  163. $oTemplate = BxDolStudioTemplate::getInstance();
  164. $iStart = (int)bx_get('str_start');
  165. $iPerPage = (int)bx_get('str_per_page');
  166. if(empty($iPerPage))
  167. $iPerPage = $this->iPerPageDefault;
  168. $sMethod = 'load' . bx_gen_method_name($sType);
  169. $aProducts = $this->$sMethod($sLabel, $iStart, $iPerPage + 1);
  170. $oPaginate = new BxTemplPaginate(array(
  171. 'start' => $iStart,
  172. 'per_page' => $iPerPage,
  173. 'on_change_page' => $sJsObject . ".changePagePaginate(this, '" . $sLabel . "', {start}, {per_page})"
  174. ));
  175. $oPaginate->setNumFromDataArray($aProducts);
  176. $sContent = $oTemplate->parseHtmlByName('str_products.html', array(
  177. 'list' => $this->displayProducts($aProducts),
  178. 'paginate' => $oPaginate->getSimplePaginate()
  179. ));
  180. if(!$bWrapInBlock)
  181. return $sContent;
  182. return $oTemplate->parseHtmlByName('store.html', array(
  183. 'js_object' => $sJsObject,
  184. 'content' => $this->getBlockCode(array(
  185. 'caption' => '_adm_block_cpt_' . $sLabel,
  186. 'items' => $sContent,
  187. ))
  188. ));
  189. }
  190. protected function getPurchasesList()
  191. {
  192. $oTemplate = BxDolStudioTemplate::getInstance();
  193. $aProducts = $this->loadPurchases();
  194. return $oTemplate->parseHtmlByName('store.html', array(
  195. 'js_object' => $this->getPageJsObject(),
  196. 'content' => $this->getBlockCode(array(
  197. 'caption' => '_adm_block_cpt_purchases',
  198. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  199. 'list' => $this->displayProducts($aProducts),
  200. 'paginate' => ''
  201. ))
  202. ))
  203. ));
  204. }
  205. protected function getUpdatesList()
  206. {
  207. $oTemplate = BxDolStudioTemplate::getInstance();
  208. $aUpdates = $this->loadUpdates();
  209. return $oTemplate->parseHtmlByName('store.html', array(
  210. 'js_object' => $this->getPageJsObject(),
  211. 'content' => $this->getBlockCode(array(
  212. 'caption' => '_adm_block_cpt_updates',
  213. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  214. 'list' => $this->displayUpdates($aUpdates),
  215. 'paginate' => ''
  216. ))
  217. ))
  218. ));
  219. }
  220. protected function getCheckoutList()
  221. {
  222. $sJsObject = $this->getPageJsObject();
  223. $oTemplate = BxDolStudioTemplate::getInstance();
  224. //--- Empty cart by vendor if the payment was accepted.
  225. $mixedVendor = bx_get('vendor');
  226. $mixedProducts = bx_get('products');
  227. if($mixedVendor !== false && $mixedProducts !== false) {
  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. if(empty($aVendors))
  236. return $this->getMessage('_adm_block_cpt_checkout', '_Empty');
  237. $sContent = '';
  238. foreach($aVendors as $iVendor => $aInfo) {
  239. $fTotal = 0;
  240. $sVendor = $sCurrency = '';
  241. foreach($aInfo['products'] as $aProduct) {
  242. $iCount = isset($aInfo['counts'][$aProduct['id']]) ? (int)$aInfo['counts'][$aProduct['id']] : 1;
  243. $fTotal += $iCount * $aProduct['price_single'];
  244. if($sVendor == '' && isset($aProduct['author_name']))
  245. $sVendor = $aProduct['author_name'];
  246. if($sCurrency == '' && isset($aProduct['author_currency_sign']))
  247. $sCurrency = $aProduct['author_currency_sign'];
  248. }
  249. $aMenu = array(
  250. array('id' => 'checkout-' . $iVendor, 'name' => 'checkout-' . $iVendor, 'link' => 'javascript:void(0)', 'onclick' => $sJsObject . ".checkoutCart(" . $iVendor . ", this);", 'target' => '_self', 'title' => '_adm_action_cpt_checkout', 'active' => 1),
  251. array('id' => 'delete-all-' . $iVendor, 'name' => 'delete-all-' . $iVendor, 'link' => 'javascript:void(0)', 'onclick' => $sJsObject . ".deleteAllFromCart(" . $iVendor . ", this)", 'target' => '_self', 'title' => '_adm_action_cpt_delete_all', 'active' => 1)
  252. );
  253. $oMenu = new BxTemplMenu(array('object'=> 'adm-std-checkout', 'template' => 'menu_buttons_hor.html', 'menu_items' => $aMenu));
  254. $sContent .= $this->getBlockCode(array(
  255. 'caption' => _t('_adm_block_cpt_checkout_by_vendor_csign', $sVendor, $sCurrency, $fTotal),
  256. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  257. 'list' => $this->displayProducts($aInfo['products'], array('is_shopping_cart' => true, 'counts' => $aInfo['counts'])),
  258. 'paginate' => ''
  259. )),
  260. 'panel_bottom' => $oMenu->getCode()
  261. ));
  262. }
  263. return $oTemplate->parseHtmlByName('store.html', array(
  264. 'js_object' => $sJsObject,
  265. 'content' => $sContent
  266. ));
  267. }
  268. protected function getDownloadedList()
  269. {
  270. $sJsObject = $this->getPageJsObject();
  271. $oTemplate = BxDolStudioTemplate::getInstance();
  272. $sContent = $sModules = $sUpdates = "";
  273. $aProducts = $this->loadDownloaded();
  274. //--- Prepare modules.
  275. foreach($aProducts['modules'] as $aModule) {
  276. $sIcon = BxDolStudioUtils::getModuleIcon($aModule, 'store');
  277. $bIcon = strpos($sIcon, '.') !== false;
  278. $bInstalled = $aModule['installed'];
  279. $bQueued = !$bInstalled && $this->oDb->isQueued('action', $aModule['dir']);
  280. $sModules .= $oTemplate->parseHtmlByName('str_product_v1.html', array(
  281. 'js_object' => $sJsObject,
  282. 'name' => $aModule['name'],
  283. 'bx_if:no_icon' => array (
  284. 'condition' => !$bIcon,
  285. 'content' => array(
  286. 'icon' => $sIcon
  287. ),
  288. ),
  289. 'bx_if:icon' => array (
  290. 'condition' => $bIcon,
  291. 'content' => array(
  292. 'icon_url' => $sIcon,
  293. ),
  294. ),
  295. 'title' => $aModule['title'],
  296. 'vendor' => $aModule['vendor'],
  297. 'version' => $aModule['version'],
  298. 'dir' => $aModule['dir'],
  299. 'bx_if:hide_install' => array(
  300. 'condition' => $bInstalled || $bQueued,
  301. 'content' => array()
  302. ),
  303. 'bx_if:hide_queued' => array(
  304. 'condition' => !$bQueued,
  305. 'content' => array()
  306. ),
  307. 'bx_if:hide_installed' => array(
  308. 'condition' => !$bInstalled || $bQueued,
  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:no_icon' => array (
  321. 'condition' => !$bIcon,
  322. 'content' => array(
  323. 'icon' => $sIcon
  324. ),
  325. ),
  326. 'bx_if:icon' => array (
  327. 'condition' => $bIcon,
  328. 'content' => array(
  329. 'icon_url' => $sIcon,
  330. ),
  331. ),
  332. 'title' => $aUpdate['title'],
  333. 'vendor' => $aUpdate['vendor'],
  334. 'versions' => _t('_adm_str_txt_update_from_to', $aUpdate['version_from'], $aUpdate['version_to']),
  335. 'dir' => $aUpdate['dir']
  336. ));
  337. }
  338. if(!empty($sModules))
  339. $sContent .= $this->getBlockCode(array(
  340. 'caption' => '_adm_block_cpt_downloaded_modules',
  341. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  342. 'list' => $sModules,
  343. 'paginate' => ''
  344. )),
  345. ));
  346. if(!empty($sUpdates))
  347. $sContent .= $this->getBlockCode(array(
  348. 'caption' => '_adm_block_cpt_downloaded_updates',
  349. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  350. 'list' => $sUpdates,
  351. 'paginate' => ''
  352. )),
  353. ));
  354. return $oTemplate->parseHtmlByName('store.html', array(
  355. 'js_object' => $sJsObject,
  356. 'content' => $sContent
  357. ));
  358. }
  359. protected function getMessage($sCaption, $sContent, $aActions = array())
  360. {
  361. return BxDolStudioTemplate::getInstance()->parseHtmlByName('store.html', array(
  362. 'js_object' => $this->getPageJsObject(),
  363. 'content' => $this->getBlockCode(array(
  364. 'caption' => $sCaption,
  365. 'actions' => $aActions,
  366. 'items' => MsgBox(_t($sContent))
  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' => BX_DOL_STUDIO_IU_RC_FAILED, '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. $bPurchaseSingle = !$bFree && !$bPurchased && (float)$aProduct['price_single'] != 0;
  381. $bInCart = $bPurchaseSingle && BxDolStudioCart::getInstance()->exists($aProduct['author_id'], $aProduct['id']);
  382. $bPurchaseRecurring = !$bFree && !$bPurchased && (float)$aProduct['price_recurring'] != 0;
  383. $bDownloadable = (int)$aProduct['is_file'] == 1;
  384. $bDownloaded = array_key_exists($sModuleName, $aDownloaded);
  385. $bDownload = ($bFree || $bPurchased) && $bDownloadable;
  386. $bDiscount = !empty($aProduct['discount_single']);
  387. $sVersion = $bDownloaded && version_compare($aDownloaded[$sModuleName]['version'], $aProduct['version']) != 0 ? _t('_adm_str_txt_pv_version_mask', $aDownloaded[$sModuleName]['version'], $aProduct['version']) : $aProduct['version'];
  388. $iScreenshots = 0;
  389. $aScreenshots = array();
  390. $bScreenshots = is_array($aProduct['screenshots']) && !empty($aProduct['screenshots']);
  391. if($bScreenshots) {
  392. $iScreenshots = count($aProduct['screenshots']);
  393. foreach($aProduct['screenshots'] as $aScreenshot)
  394. $aScreenshots[] = array(
  395. 'view_url' => $aProduct['url'],
  396. 'image_url' => $aScreenshot['big']
  397. );
  398. }
  399. $sContent = $oTemplate->parseHtmlByname('str_product_view.html', array(
  400. 'id' => $aProduct['id'],
  401. 'title' => $aProduct['title'],
  402. 'url' => $aProduct['url'],
  403. 'author_name' => $aProduct['author_name'],
  404. 'author_url' => $aProduct['author_url'],
  405. 'version' => $sVersion,
  406. 'bx_if:show_price_single' => array(
  407. 'condition' => $bFree || (float)$aProduct['price_single'] != 0,
  408. 'content' => array(
  409. 'price_single' => !$bFree ? _t('_adm_str_txt_price_single', $aProduct['author_currency_sign'], $aProduct['price_single']) : _t('_adm_str_txt_price_free'),
  410. 'bx_if:show_discount' => array(
  411. 'condition' => !$bFree && $bDiscount,
  412. 'content' => array(
  413. 'discount_single' => $bDiscount ? _t('_adm_str_txt_pv_discount_off_csign', $aProduct['discount_single']['percent'], $aProduct['author_currency_sign'], $aProduct['discount_single']['save']) : ''
  414. )
  415. )
  416. )
  417. ),
  418. 'bx_if:show_price_recurring' => array(
  419. 'condition' => (float)$aProduct['price_recurring'] != 0,
  420. 'content' => array(
  421. 'price_recurring' => _t('_adm_str_txt_price_recurring', $aProduct['author_currency_sign'], $aProduct['price_recurring'], _t('_adm_str_txt_per_' . $aProduct['duration_recurring']))
  422. )
  423. ),
  424. 'category' => $aProduct['category'],
  425. 'category_url' => $aProduct['category_url'],
  426. 'tags' => implode(', ', explode(',', $aProduct['tags'])),
  427. 'reviews' => _t('_adm_str_txt_pv_stats_reviews', $aProduct['reviews_cnt']),
  428. 'reviews_url' => $aProduct['reviews_url'],
  429. 'votes' => _t('_adm_str_txt_pv_stats_votes', $aProduct['votes_cnt']),
  430. 'views' => _t('_adm_str_txt_pv_stats_views', $aProduct['views_cnt']),
  431. 'created' => bx_time_js($aProduct['created']),
  432. 'updated' => bx_time_js($aProduct['updated']),
  433. 'description' => $aProduct['description'],
  434. 'bx_if:show_screenshots' => array(
  435. 'condition' => $bScreenshots,
  436. 'content' => array(
  437. 'width' => 222 * $iScreenshots - 20,
  438. 'bx_repeat:screenshots' => $aScreenshots
  439. )
  440. ),
  441. 'bx_if:show_purchase' => array(
  442. 'condition' => $bPurchaseSingle || $bPurchaseRecurring,
  443. 'content' => array(
  444. 'bx_if:show_purchase_single' => array(
  445. 'condition' => $bPurchaseSingle && !$bInCart,
  446. 'content' => array(
  447. 'js_object' => $sJsObject,
  448. 'id' => $aProduct['id'],
  449. 'vendor_id' => $aProduct['author_id'],
  450. 'price_single' => _t('_adm_str_txt_price_single', $aProduct['author_currency_sign'], $aProduct['price_single'])
  451. )
  452. ),
  453. 'bx_if:show_checkout_single' => array(
  454. 'condition' => $bPurchaseSingle,
  455. 'content' => array(
  456. 'js_object' => $sJsObject,
  457. 'id' => $aProduct['id'],
  458. 'vendor_id' => $aProduct['author_id'],
  459. 'bx_if:show_as_hidden' => array(
  460. 'condition' => !$bInCart,
  461. 'content' => array()
  462. )
  463. )
  464. ),
  465. 'bx_if:show_purchase_recurring' => array(
  466. 'condition' => $bPurchaseRecurring,
  467. 'content' => array(
  468. 'js_object' => $sJsObject,
  469. 'id' => $aProduct['id'],
  470. 'vendor_id' => $aProduct['author_id'],
  471. 'price_recurring' => _t('_adm_str_txt_price_recurring', $aProduct['author_currency_sign'], $aProduct['price_recurring'], _t('_adm_str_txt_per_' . $aProduct['duration_recurring']))
  472. )
  473. )
  474. )
  475. ),
  476. 'bx_if:show_download' => array(
  477. 'condition' => $bDownload && !$bDownloaded,
  478. 'content' => array(
  479. 'js_object' => $sJsObject,
  480. 'file_id' => $aProduct['file_id'],
  481. )
  482. ),
  483. 'bx_if:show_download_disabled' => array(
  484. 'condition' => $bDownload && $bDownloaded,
  485. 'content' => array()
  486. ),
  487. ));
  488. return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => '', 'popup' => PopupBox('bx-std-str-popup-product', $aProduct['title'], $sContent, true), 'screenshots' => $iScreenshots);
  489. }
  490. protected function getFile($iFileId)
  491. {
  492. $mixedResult = $this->loadFile($iFileId);
  493. if($mixedResult === true)
  494. return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => _t('_adm_str_msg_download_successfully'));
  495. if(is_string($mixedResult))
  496. return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
  497. if(is_array($mixedResult))
  498. return array_merge(array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_str_err_download_failed')), $mixedResult);
  499. }
  500. protected function getUpdate($sModuleName, $bAutoUpdate = false)
  501. {
  502. $mixedResult = $this->loadUpdate($sModuleName, $bAutoUpdate);
  503. if($mixedResult === true)
  504. return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => _t('_adm_str_msg_download' . ($bAutoUpdate ? '_and_install' : '') . '_successfully'));
  505. if(is_string($mixedResult))
  506. return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
  507. if(is_array($mixedResult))
  508. return array_merge(array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_str_err_download_failed')), $mixedResult);
  509. }
  510. protected function displayProducts($mixedItems, $aParams = array())
  511. {
  512. if(!is_array($mixedItems))
  513. return MsgBox($mixedItems);
  514. $sJsObject = $this->getPageJsObject();
  515. $oTemplate = BxDolStudioTemplate::getInstance();
  516. $aDownloaded = $this->getDownloadedModules();
  517. $bShoppingCart = isset($aParams['is_shopping_cart']) && $aParams['is_shopping_cart'];
  518. $sResult = '';
  519. foreach($mixedItems as $aItem) {
  520. $bFree = (int)$aItem['is_free'] == 1;
  521. $bPurchased = (int)$aItem['is_purchased'] == 1;
  522. $bPurchaseSingle = !$bShoppingCart && !$bFree && !$bPurchased && (float)$aItem['price_single'] != 0;
  523. $bInCart = $bPurchaseSingle && BxDolStudioCart::getInstance()->exists($aItem['author_id'], $aItem['id']);
  524. $bPurchaseRecurring = !$bShoppingCart && !$bFree && !$bPurchased && (float)$aItem['price_recurring'] != 0;
  525. $bDownloadable = (int)$aItem['is_file'] == 1;
  526. $bDownloaded = in_array($aItem['name'], $aDownloaded);
  527. $bDownload = !$bShoppingCart && ($bFree || $bPurchased) && $bDownloadable;
  528. $bQueued = $this->oDb->isQueued('download', $aItem['name']);
  529. $sPrice = !$bFree ? _t('_adm_str_txt_price_single', $aItem['author_currency_sign'], $aItem['price_single']) : _t('_adm_str_txt_price_free');
  530. $sDiscount = !$bFree && !empty($aItem['discount_single']) ? _t('_adm_str_txt_discount_csign', $aItem['author_currency_sign'], $aItem['discount_single']['price']) : '';
  531. $sIcon = !empty($aItem['thumbnail']['small']) ? $aItem['thumbnail']['small'] : BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  532. $bIcon = strpos($sIcon, '.') !== false;
  533. $sImage = !empty($aItem['cover']['big']) ? $aItem['cover']['big'] : '';
  534. $bImage = strpos($sImage, '.') !== false;
  535. $sResult .= $oTemplate->parseHtmlByName('str_product_v2.html', array(
  536. 'js_object' => $sJsObject,
  537. 'id' => $aItem['id'],
  538. 'name' => $aItem['name'],
  539. 'url' => $aItem['url'],
  540. 'description_plain_attr' => bx_html_attribute($aItem['description_plain']),
  541. 'bx_if:no_icon' => array (
  542. 'condition' => !$bIcon,
  543. 'content' => array(
  544. 'icon' => $sIcon
  545. ),
  546. ),
  547. 'bx_if:icon' => array (
  548. 'condition' => $bIcon,
  549. 'content' => array(
  550. 'icon_url' => $sIcon,
  551. ),
  552. ),
  553. 'bx_if:no_image' => array (
  554. 'condition' => !$bImage,
  555. 'content' => array(
  556. 'description_plain' => $aItem['description_plain'],
  557. 'strecher' => mb_strlen($aItem['description_plain']) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($aItem['description_plain'])) / 6))
  558. ),
  559. ),
  560. 'bx_if:image' => array (
  561. 'condition' => $bImage,
  562. 'content' => array(
  563. 'image_url' => $sImage,
  564. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40)
  565. ),
  566. ),
  567. 'title' => $aItem['title'],
  568. 'bx_if:show_vendor' => array(
  569. 'condition' => !$bShoppingCart,
  570. 'content' => array(
  571. 'vendor_name' => $aItem['author_name'],
  572. 'vendor_url' => $aItem['author_url'],
  573. 'bx_if:show_version' => array(
  574. 'condition' => !empty($aItem['file_version']),
  575. 'content' => array(
  576. 'version' => $aItem['file_version'],
  577. )
  578. ),
  579. )
  580. ),
  581. 'bx_if:show_count_price' => array(
  582. 'condition' => $bShoppingCart,
  583. 'content' => array(
  584. 'count' => isset($aParams['counts'][$aItem['id']]) ? (int)$aParams['counts'][$aItem['id']] : 1,
  585. 'price_single' => $sPrice,
  586. 'discount_single' => $sDiscount,
  587. )
  588. ),
  589. 'rate' => !$bShoppingCart ? $this->getVoteStars($aItem) : '',
  590. 'votes_cnt' => !$bShoppingCart && (int)$aItem['votes_cnt'] > 0 ? (int)$aItem['votes_cnt'] : '',
  591. 'bx_if:show_purchase_single' => array(
  592. 'condition' => $bPurchaseSingle && !$bInCart,
  593. 'content' => array(
  594. 'js_object' => $sJsObject,
  595. 'id' => $aItem['id'],
  596. 'vendor_id' => $aItem['author_id'],
  597. 'price_single' => _t('_adm_str_txt_price_single', $aItem['author_currency_sign'], $aItem['price_single'])
  598. )
  599. ),
  600. 'bx_if:show_checkout_single' => array(
  601. 'condition' => $bPurchaseSingle,
  602. 'content' => array(
  603. 'js_object' => $sJsObject,
  604. 'id' => $aItem['id'],
  605. 'vendor_id' => $aItem['author_id'],
  606. 'bx_if:show_as_hidden' => array(
  607. 'condition' => !$bInCart,
  608. 'content' => array()
  609. )
  610. )
  611. ),
  612. 'bx_if:show_purchase_recurring' => array(
  613. 'condition' => $bPurchaseRecurring,
  614. 'content' => array(
  615. 'js_object' => $sJsObject,
  616. 'id' => $aItem['id'],
  617. 'vendor_id' => $aItem['author_id'],
  618. 'price_recurring' => _t('_adm_str_txt_price_recurring', $aItem['author_currency_sign'], $aItem['price_recurring'], _t('_adm_str_txt_per_' . $aItem['duration_recurring'] . '_short'))
  619. )
  620. ),
  621. 'bx_if:show_download' => array(
  622. 'condition' => $bDownload && !$bQueued && !$bDownloaded,
  623. 'content' => array(
  624. 'js_object' => $sJsObject,
  625. 'file_id' => $aItem['file_id']
  626. )
  627. ),
  628. 'bx_if:show_download_disabled' => array(
  629. 'condition' => $bDownload && !$bQueued && $bDownloaded,
  630. 'content' => array()
  631. ),
  632. 'bx_if:show_queued_disabled' => array(
  633. 'condition' => $bDownload && $bQueued && !$bDownloaded,
  634. 'content' => array()
  635. ),
  636. 'bx_if:show_delete' => array(
  637. 'condition' => $bShoppingCart,
  638. 'content' => array(
  639. 'js_object' => $sJsObject,
  640. 'id' => $aItem['id'],
  641. 'vendor_id' => $aItem['author_id']
  642. )
  643. )
  644. ));
  645. }
  646. return $sResult;
  647. }
  648. protected function displayUpdates($mixedItems, $aParams = array())
  649. {
  650. if(!is_array($mixedItems))
  651. return MsgBox($mixedItems);
  652. if(empty($mixedItems))
  653. return MsgBox(_t('_Empty'));
  654. $sJsObject = $this->getPageJsObject();
  655. $oTemplate = BxDolStudioTemplate::getInstance();
  656. $sResult = '';
  657. foreach($mixedItems as $aItem) {
  658. $bDownloadable = (int)$aItem['is_file'] == 1;
  659. $sIcon = !empty($aItem['thumbnail']['big']) ? $aItem['thumbnail']['big'] : BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  660. $bIcon = strpos($sIcon, '.') !== false;
  661. $sImage = !empty($aItem['cover']['big']) ? $aItem['cover']['big'] : '';
  662. $bImage = strpos($sImage, '.') !== false;
  663. $sResult .= $oTemplate->parseHtmlByName('str_update_v2.html', array(
  664. 'js_object' => $sJsObject,
  665. 'id' => $aItem['id'],
  666. 'name' => $aItem['name'],
  667. 'url' => $aItem['url'],
  668. 'bx_if:no_icon' => array (
  669. 'condition' => !$bIcon,
  670. 'content' => array(
  671. 'icon' => $sIcon
  672. ),
  673. ),
  674. 'bx_if:icon' => array (
  675. 'condition' => $bIcon,
  676. 'content' => array(
  677. 'icon_url' => $sIcon,
  678. ),
  679. ),
  680. 'bx_if:no_image' => array (
  681. 'condition' => !$bImage,
  682. 'content' => array(
  683. 'note' => $aItem['description_plain'],
  684. 'strecher' => mb_strlen($aItem['description_plain']) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($aItem['description_plain'])) / 6))
  685. ),
  686. ),
  687. 'bx_if:image' => array (
  688. 'condition' => $bImage,
  689. 'content' => array(
  690. 'image_url' => $sImage,
  691. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40)
  692. ),
  693. ),
  694. 'title' => $aItem['title'],
  695. 'vendor' => $aItem['author_name'],
  696. 'versions' => _t('_adm_str_txt_update_from_to', $aItem['file_version'], $aItem['file_version_to']),
  697. 'bx_if:show_download' => array(
  698. 'condition' => $bDownloadable,
  699. 'content' => array(
  700. 'caption' => _t($this->bAuthAccessUpdates ? '_adm_btn_download_submit' : '_adm_btn_install_submit'),
  701. 'on_click' => $sJsObject . "." . ($this->bAuthAccessUpdates ? "getFile(" . $aItem['file_id'] . ", this)" : "getUpdateAndInstall('" . $aItem['name'] . "', this)")
  702. )
  703. )
  704. ));
  705. }
  706. return $sResult;
  707. }
  708. private function getDownloadedModules($bNamesOnly = true)
  709. {
  710. $aModules = BxDolStudioInstallerUtils::getInstance()->getModules(false);
  711. return $bNamesOnly ? array_keys($aModules) : $aModules;
  712. }
  713. private function getVoteStars($aItem)
  714. {
  715. $aTmplVarsStars = array();
  716. for($i = (int)$aItem['rate_min']; $i <= (int)$aItem['rate_max']; $i++)
  717. $aTmplVarsStars[] = array('value' => $i);
  718. return BxDolStudioTemplate::getInstance()->parseHtmlByName('str_vote_stars.html', array(
  719. 'id' => $aItem['id'],
  720. 'value' => (float)$aItem['rate'],
  721. 'bx_repeat:stars' => $aTmplVarsStars,
  722. 'bx_repeat:slider' => $aTmplVarsStars,
  723. ));
  724. }
  725. }
  726. /** @} */