BxBaseStudioStore.php 40 KB

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