BxBaseStudioStore.php 36 KB

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