1
0

BxBaseStudioStore.php 43 KB

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