1
0

BxBaseStudioStore.php 42 KB

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