BxBaseStudioStore.php 36 KB

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