BxBaseStudioStore.php 34 KB

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