BxBaseStudioStore.php 42 KB

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