BxBaseStudioStore.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  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. foreach($aProducts['modules'] as $aModule) {
  416. $sIcon = BxDolStudioUtils::getModuleIcon($aModule, 'store');
  417. $bIcon = strpos($sIcon, '.') !== false;
  418. $bInstalled = $aModule['installed'];
  419. $bQueued = !$bInstalled && $this->oDb->isQueued('action', $aModule['dir']);
  420. $sModules .= $oTemplate->parseHtmlByName('str_product_v1.html', array(
  421. 'js_object' => $sJsObject,
  422. 'name' => $aModule['name'],
  423. 'bx_if:no_icon' => array (
  424. 'condition' => !$bIcon,
  425. 'content' => array(
  426. 'icon' => $sIcon
  427. ),
  428. ),
  429. 'bx_if:icon' => array (
  430. 'condition' => $bIcon,
  431. 'content' => array(
  432. 'icon_url' => $sIcon,
  433. ),
  434. ),
  435. 'title' => $aModule['title'],
  436. 'vendor' => $aModule['vendor'],
  437. 'version' => $aModule['version'],
  438. 'dir' => $aModule['dir'],
  439. 'bx_if:hide_install' => array(
  440. 'condition' => $bInstalled || $bQueued,
  441. 'content' => array()
  442. ),
  443. 'bx_if:hide_queued' => array(
  444. 'condition' => !$bQueued,
  445. 'content' => array()
  446. ),
  447. 'bx_if:hide_installed' => array(
  448. 'condition' => !$bInstalled || $bQueued,
  449. 'content' => array()
  450. )
  451. ));
  452. }
  453. //--- Prepare updates.
  454. foreach($aProducts['updates'] as $aUpdate) {
  455. $sIcon = BxDolStudioUtils::getModuleIcon(array('type' => $aUpdate['module_type'], 'name' => $aUpdate['module_name'], 'dir' => $aUpdate['module_dir']), 'store');
  456. $bIcon = strpos($sIcon, '.') !== false;
  457. $sUpdates .= $oTemplate->parseHtmlByName('str_update_v1.html', array(
  458. 'js_object' => $sJsObject,
  459. 'name' => $aUpdate['module_name'],
  460. 'bx_if:no_icon' => array (
  461. 'condition' => !$bIcon,
  462. 'content' => array(
  463. 'icon' => $sIcon
  464. ),
  465. ),
  466. 'bx_if:icon' => array (
  467. 'condition' => $bIcon,
  468. 'content' => array(
  469. 'icon_url' => $sIcon,
  470. ),
  471. ),
  472. 'title' => $aUpdate['title'],
  473. 'vendor' => $aUpdate['vendor'],
  474. 'versions' => _t('_adm_str_txt_update_from_to', $aUpdate['version_from'], $aUpdate['version_to']),
  475. 'dir' => $aUpdate['dir']
  476. ));
  477. }
  478. if(!empty($sModules))
  479. $sContent .= $this->getBlockCode(array(
  480. 'caption' => '_adm_block_cpt_downloaded_modules',
  481. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  482. 'list' => $sModules,
  483. 'paginate' => ''
  484. )),
  485. ));
  486. if(!empty($sUpdates))
  487. $sContent .= $this->getBlockCode(array(
  488. 'caption' => '_adm_block_cpt_downloaded_updates',
  489. 'items' => $oTemplate->parseHtmlByName('str_products.html', array(
  490. 'list' => $sUpdates,
  491. 'paginate' => ''
  492. )),
  493. ));
  494. return $oTemplate->parseHtmlByName('store.html', array(
  495. 'js_object' => $sJsObject,
  496. 'content' => $sContent
  497. ));
  498. }
  499. protected function getMessage($sCaption, $sContent, $aActions = array())
  500. {
  501. return BxDolStudioTemplate::getInstance()->parseHtmlByName('store.html', array(
  502. 'js_object' => $this->getPageJsObject(),
  503. 'content' => $this->getBlockCode(array(
  504. 'caption' => $sCaption,
  505. 'actions' => $aActions,
  506. 'items' => MsgBox(_t($sContent))
  507. ))
  508. ));
  509. }
  510. protected function getProduct($sModuleName)
  511. {
  512. $bShowRating = true;
  513. $sJsObject = $this->getPageJsObject();
  514. $oTemplate = BxDolStudioTemplate::getInstance();
  515. $aProduct = $this->loadProduct($sModuleName);
  516. if(empty($aProduct) || !is_array($aProduct))
  517. return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($aProduct) ? $aProduct : _t('_adm_str_err_no_product_info')));
  518. $aDownloaded = $this->getDownloadedModules(false);
  519. $bFree = (int)$aProduct['is_free'] == 1;
  520. $bPurchased = (int)$aProduct['is_purchased'] == 1;
  521. $bPurchaseSingle = !$bFree && !$bPurchased && (float)$aProduct['price_single'] != 0;
  522. $bInCart = $bPurchaseSingle && BxDolStudioCart::getInstance()->exists($aProduct['author_id'], $aProduct['id']);
  523. $bPurchaseRecurring = !$bFree && !$bPurchased && (float)$aProduct['price_recurring'] != 0;
  524. $bDownloadable = (int)$aProduct['is_file'] == 1;
  525. $bDownloaded = array_key_exists($sModuleName, $aDownloaded);
  526. $bDownload = ($bFree || $bPurchased) && $bDownloadable;
  527. $bDiscount = !empty($aProduct['discount_single']);
  528. $sVersion = $bDownloaded && version_compare($aDownloaded[$sModuleName]['version'], $aProduct['version']) != 0 ? _t('_adm_str_txt_pv_version_mask', $aDownloaded[$sModuleName]['version'], $aProduct['version']) : $aProduct['version'];
  529. $iScreenshots = 0;
  530. $aScreenshots = array();
  531. $bScreenshots = is_array($aProduct['screenshots']) && !empty($aProduct['screenshots']);
  532. if($bScreenshots) {
  533. $iScreenshots = count($aProduct['screenshots']);
  534. foreach($aProduct['screenshots'] as $aScreenshot)
  535. $aScreenshots[] = array(
  536. 'view_url' => $aProduct['url'],
  537. 'image_url' => $aScreenshot['big']
  538. );
  539. }
  540. $bTmplVarsRate = $bShowRating;
  541. if($bTmplVarsRate)
  542. $aTmplVarsRate = array(
  543. 'rate' => $this->getVoteStars($aProduct)
  544. );
  545. $aTmplVarsVotes = array();
  546. $bTmplVarsVotes = $bShowRating && (int)$aProduct['votes_cnt'] > 0;
  547. if($bTmplVarsVotes)
  548. $aTmplVarsVotes = array(
  549. 'count' => (int)$aProduct['votes_cnt']
  550. );
  551. $sContent = $oTemplate->parseHtmlByname('str_product_view.html', array(
  552. 'id' => $aProduct['id'],
  553. 'title' => $aProduct['title'],
  554. 'url' => $aProduct['url'],
  555. 'author_name' => $aProduct['author_name'],
  556. 'author_url' => $aProduct['author_url'],
  557. 'version' => $sVersion,
  558. 'bx_if:show_price_single' => array(
  559. 'condition' => $bFree || (float)$aProduct['price_single'] != 0,
  560. 'content' => array(
  561. 'price_single' => !$bFree ? _t('_adm_str_txt_price_single', $aProduct['author_currency_sign'], $aProduct['price_single']) : _t('_adm_str_txt_price_free'),
  562. 'bx_if:show_discount' => array(
  563. 'condition' => !$bFree && $bDiscount,
  564. 'content' => array(
  565. 'discount_single' => $bDiscount ? _t('_adm_str_txt_pv_discount_off_csign', $aProduct['discount_single']['percent'], $aProduct['author_currency_sign'], $aProduct['discount_single']['save']) : ''
  566. )
  567. )
  568. )
  569. ),
  570. 'bx_if:show_price_recurring' => array(
  571. 'condition' => (float)$aProduct['price_recurring'] != 0,
  572. 'content' => array(
  573. 'price_recurring' => _t('_adm_str_txt_price_recurring', $aProduct['author_currency_sign'], $aProduct['price_recurring'], _t('_adm_str_txt_per_' . $aProduct['duration_recurring']))
  574. )
  575. ),
  576. 'bx_if:show_rate' => array(
  577. 'condition' => $bTmplVarsRate,
  578. 'content' => $aTmplVarsRate
  579. ),
  580. 'bx_if:show_votes' => array(
  581. 'condition' => $bTmplVarsVotes,
  582. 'content' => $aTmplVarsVotes
  583. ),
  584. 'category' => $aProduct['category'],
  585. 'category_url' => $aProduct['category_url'],
  586. 'tags' => implode(', ', explode(',', $aProduct['tags'])),
  587. 'reviews' => _t('_adm_str_txt_pv_stats_reviews', $aProduct['reviews_cnt']),
  588. 'reviews_url' => $aProduct['reviews_url'],
  589. 'votes' => _t('_adm_str_txt_pv_stats_votes', $aProduct['votes_cnt']),
  590. 'views' => _t('_adm_str_txt_pv_stats_views', $aProduct['views_cnt']),
  591. 'created' => bx_time_js($aProduct['created']),
  592. 'updated' => bx_time_js($aProduct['updated']),
  593. 'description' => $aProduct['description'],
  594. 'bx_if:show_screenshots' => array(
  595. 'condition' => $bScreenshots,
  596. 'content' => array(
  597. 'width' => 222 * $iScreenshots - 20,
  598. 'bx_repeat:screenshots' => $aScreenshots
  599. )
  600. ),
  601. 'bx_if:show_purchase' => array(
  602. 'condition' => $bPurchaseSingle || $bPurchaseRecurring,
  603. 'content' => array(
  604. 'bx_if:show_purchase_single' => array(
  605. 'condition' => $bPurchaseSingle && !$bInCart,
  606. 'content' => array(
  607. 'js_object' => $sJsObject,
  608. 'id' => $aProduct['id'],
  609. 'vendor_id' => $aProduct['author_id'],
  610. 'price_single' => _t('_adm_str_txt_price_single', $aProduct['author_currency_sign'], $aProduct['price_single'])
  611. )
  612. ),
  613. 'bx_if:show_checkout_single' => array(
  614. 'condition' => $bPurchaseSingle,
  615. 'content' => array(
  616. 'js_object' => $sJsObject,
  617. 'id' => $aProduct['id'],
  618. 'vendor_id' => $aProduct['author_id'],
  619. 'bx_if:show_as_hidden' => array(
  620. 'condition' => !$bInCart,
  621. 'content' => array()
  622. )
  623. )
  624. ),
  625. 'bx_if:show_purchase_recurring' => array(
  626. 'condition' => $bPurchaseRecurring,
  627. 'content' => array(
  628. 'js_object' => $sJsObject,
  629. 'id' => $aProduct['id'],
  630. 'vendor_id' => $aProduct['author_id'],
  631. 'price_recurring' => _t('_adm_str_txt_price_recurring', $aProduct['author_currency_sign'], $aProduct['price_recurring'], _t('_adm_str_txt_per_' . $aProduct['duration_recurring']))
  632. )
  633. )
  634. )
  635. ),
  636. 'bx_if:show_download' => array(
  637. 'condition' => $bDownload && !$bDownloaded,
  638. 'content' => array(
  639. 'js_object' => $sJsObject,
  640. 'file_id' => $aProduct['file_id'],
  641. )
  642. ),
  643. 'bx_if:show_download_disabled' => array(
  644. 'condition' => $bDownload && $bDownloaded,
  645. 'content' => array()
  646. ),
  647. ));
  648. return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => '', 'popup' => PopupBox('bx-std-str-popup-product', $aProduct['title'], $sContent, true), 'screenshots' => $iScreenshots);
  649. }
  650. protected function getFile($iFileId)
  651. {
  652. $mixedResult = $this->loadFile($iFileId);
  653. if($mixedResult === true)
  654. return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => _t('_adm_str_msg_download_successfully'));
  655. if(is_string($mixedResult))
  656. return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
  657. if(is_array($mixedResult))
  658. return array_merge(array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_str_err_download_failed')), $mixedResult);
  659. }
  660. protected function getUpdate($sModuleName, $bApplyUpdate = false)
  661. {
  662. $mixedResult = $this->loadUpdate($sModuleName, $bApplyUpdate);
  663. if($mixedResult === true)
  664. return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => _t('_adm_str_msg_download' . ($bApplyUpdate ? '_and_install' : '') . '_successfully'));
  665. if(is_string($mixedResult))
  666. return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
  667. if(is_array($mixedResult))
  668. return array_merge(array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_str_err_download_failed')), $mixedResult);
  669. }
  670. protected function displayProducts($mixedItems, $aParams = array())
  671. {
  672. $bShowRating = false;
  673. if(!is_array($mixedItems))
  674. return MsgBox($mixedItems);
  675. $sJsObject = $this->getPageJsObject();
  676. $oTemplate = BxDolStudioTemplate::getInstance();
  677. $aDownloaded = $this->getDownloadedModules();
  678. $bShoppingCart = isset($aParams['is_shopping_cart']) && $aParams['is_shopping_cart'];
  679. $sResult = '';
  680. foreach($mixedItems as $aItem) {
  681. $bFree = (int)$aItem['is_free'] == 1;
  682. $bPurchased = (int)$aItem['is_purchased'] == 1;
  683. $bPurchaseSingle = !$bShoppingCart && !$bFree && !$bPurchased && (float)$aItem['price_single'] != 0;
  684. $bInCart = $bPurchaseSingle && BxDolStudioCart::getInstance()->exists($aItem['author_id'], $aItem['id']);
  685. $bPurchaseRecurring = !$bShoppingCart && !$bFree && !$bPurchased && (float)$aItem['price_recurring'] != 0;
  686. $bDownloadable = (int)$aItem['is_file'] == 1;
  687. $bDownloaded = in_array($aItem['name'], $aDownloaded);
  688. $bDownload = !$bShoppingCart && ($bFree || $bPurchased) && $bDownloadable;
  689. $bQueued = $this->oDb->isQueued('download', $aItem['name']);
  690. $sPrice = !$bFree ? _t('_adm_str_txt_price_single', $aItem['author_currency_sign'], $aItem['price_single']) : _t('_adm_str_txt_price_free');
  691. $sDiscount = !$bFree && !empty($aItem['discount_single']) ? _t('_adm_str_txt_discount_csign', $aItem['author_currency_sign'], $aItem['discount_single']['price']) : '';
  692. $sIcon = !empty($aItem['thumbnail']['small']) ? $aItem['thumbnail']['small'] : BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  693. $bIcon = strpos($sIcon, '.') !== false;
  694. $sImage = '';
  695. if(!empty($aItem['cover']['medium']))
  696. $sImage = $aItem['cover']['medium'];
  697. else if(!empty($aItem['cover']['large']))
  698. $sImage = $aItem['cover']['large'];
  699. else if(!empty($aItem['cover']['big']))
  700. $sImage = $aItem['cover']['big'];
  701. $bImage = !empty($sImage) && strpos($sImage, '.') !== false;
  702. $aTmplVarsRate = array();
  703. $bTmplVarsRate = $bShowRating && !$bShoppingCart;
  704. if($bTmplVarsRate)
  705. $aTmplVarsRate = array(
  706. 'rate' => $this->getVoteStars($aItem)
  707. );
  708. $aTmplVarsVotes = array();
  709. $bTmplVarsVotes = $bShowRating && !$bShoppingCart && (int)$aItem['votes_cnt'] > 0;
  710. if($bTmplVarsVotes)
  711. $aTmplVarsVotes = array(
  712. 'count' => (int)$aItem['votes_cnt']
  713. );
  714. $sResult .= $oTemplate->parseHtmlByName('str_product_v2.html', array(
  715. 'js_object' => $sJsObject,
  716. 'id' => $aItem['id'],
  717. 'name' => $aItem['name'],
  718. 'url' => $aItem['url'],
  719. 'description_plain_attr' => bx_html_attribute($aItem['description_plain']),
  720. 'bx_if:no_icon' => array (
  721. 'condition' => !$bIcon,
  722. 'content' => array(
  723. 'icon' => $sIcon
  724. ),
  725. ),
  726. 'bx_if:icon' => array (
  727. 'condition' => $bIcon,
  728. 'content' => array(
  729. 'icon_url' => $sIcon,
  730. ),
  731. ),
  732. 'bx_if:no_image' => array (
  733. 'condition' => !$bImage,
  734. 'content' => array(
  735. 'description_plain' => $aItem['description_plain'],
  736. 'strecher' => mb_strlen($aItem['description_plain']) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($aItem['description_plain'])) / 6))
  737. ),
  738. ),
  739. 'bx_if:image' => array (
  740. 'condition' => $bImage,
  741. 'content' => array(
  742. 'image_url' => $sImage,
  743. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40)
  744. ),
  745. ),
  746. 'title' => $aItem['title'],
  747. 'bx_if:show_vendor' => array(
  748. 'condition' => !$bShoppingCart,
  749. 'content' => array(
  750. 'vendor_name' => $aItem['author_name'],
  751. 'vendor_url' => $aItem['author_url'],
  752. 'bx_if:show_version' => array(
  753. 'condition' => !empty($aItem['file_version']),
  754. 'content' => array(
  755. 'version' => $aItem['file_version'],
  756. )
  757. ),
  758. )
  759. ),
  760. 'bx_if:show_count_price' => array(
  761. 'condition' => $bShoppingCart,
  762. 'content' => array(
  763. 'count' => isset($aParams['counts'][$aItem['id']]) ? (int)$aParams['counts'][$aItem['id']] : 1,
  764. 'price_single' => $sPrice,
  765. 'discount_single' => $sDiscount,
  766. )
  767. ),
  768. 'bx_if:show_rate' => array(
  769. 'condition' => $bTmplVarsRate,
  770. 'content' => $aTmplVarsRate
  771. ),
  772. 'bx_if:show_votes' => array(
  773. 'condition' => $bTmplVarsVotes,
  774. 'content' => $aTmplVarsVotes
  775. ),
  776. 'bx_if:show_purchase_single' => array(
  777. 'condition' => $bPurchaseSingle && !$bInCart,
  778. 'content' => array(
  779. 'js_object' => $sJsObject,
  780. 'id' => $aItem['id'],
  781. 'vendor_id' => $aItem['author_id'],
  782. 'price_single' => _t('_adm_str_txt_price_single', $aItem['author_currency_sign'], $aItem['price_single'])
  783. )
  784. ),
  785. 'bx_if:show_checkout_single' => array(
  786. 'condition' => $bPurchaseSingle,
  787. 'content' => array(
  788. 'js_object' => $sJsObject,
  789. 'id' => $aItem['id'],
  790. 'vendor_id' => $aItem['author_id'],
  791. 'bx_if:show_as_hidden' => array(
  792. 'condition' => !$bInCart,
  793. 'content' => array()
  794. )
  795. )
  796. ),
  797. 'bx_if:show_purchase_recurring' => array(
  798. 'condition' => $bPurchaseRecurring,
  799. 'content' => array(
  800. 'js_object' => $sJsObject,
  801. 'id' => $aItem['id'],
  802. 'vendor_id' => $aItem['author_id'],
  803. 'price_recurring' => _t('_adm_str_txt_price_recurring', $aItem['author_currency_sign'], $aItem['price_recurring'], _t('_adm_str_txt_per_' . $aItem['duration_recurring'] . '_short'))
  804. )
  805. ),
  806. 'bx_if:show_download' => array(
  807. 'condition' => $bDownload && !$bQueued && !$bDownloaded,
  808. 'content' => array(
  809. 'js_object' => $sJsObject,
  810. 'file_id' => $aItem['file_id']
  811. )
  812. ),
  813. 'bx_if:show_download_disabled' => array(
  814. 'condition' => $bDownload && !$bQueued && $bDownloaded,
  815. 'content' => array()
  816. ),
  817. 'bx_if:show_queued_disabled' => array(
  818. 'condition' => $bDownload && $bQueued && !$bDownloaded,
  819. 'content' => array()
  820. ),
  821. 'bx_if:show_delete' => array(
  822. 'condition' => $bShoppingCart,
  823. 'content' => array(
  824. 'js_object' => $sJsObject,
  825. 'id' => $aItem['id'],
  826. 'vendor_id' => $aItem['author_id']
  827. )
  828. )
  829. ));
  830. }
  831. return $sResult;
  832. }
  833. protected function displayUpdates($mixedItems, $aParams = array())
  834. {
  835. if(!is_array($mixedItems))
  836. return MsgBox($mixedItems);
  837. if(empty($mixedItems))
  838. return MsgBox(_t('_Empty'));
  839. $sJsObject = $this->getPageJsObject();
  840. $oTemplate = BxDolStudioTemplate::getInstance();
  841. $sResult = '';
  842. foreach($mixedItems as $aItem) {
  843. $bDownloadable = (int)$aItem['is_file'] == 1;
  844. $sIcon = !empty($aItem['thumbnail']['big']) ? $aItem['thumbnail']['big'] : BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  845. $bIcon = strpos($sIcon, '.') !== false;
  846. $sImage = !empty($aItem['cover']['big']) ? $aItem['cover']['big'] : '';
  847. $bImage = strpos($sImage, '.') !== false;
  848. $sResult .= $oTemplate->parseHtmlByName('str_update_v2.html', array(
  849. 'js_object' => $sJsObject,
  850. 'id' => $aItem['id'],
  851. 'name' => $aItem['name'],
  852. 'url' => $aItem['url'],
  853. 'bx_if:no_icon' => array (
  854. 'condition' => !$bIcon,
  855. 'content' => array(
  856. 'icon' => $sIcon
  857. ),
  858. ),
  859. 'bx_if:icon' => array (
  860. 'condition' => $bIcon,
  861. 'content' => array(
  862. 'icon_url' => $sIcon,
  863. ),
  864. ),
  865. 'bx_if:no_image' => array (
  866. 'condition' => !$bImage,
  867. 'content' => array(
  868. 'note' => $aItem['description_plain'],
  869. 'strecher' => mb_strlen($aItem['description_plain']) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($aItem['description_plain'])) / 6))
  870. ),
  871. ),
  872. 'bx_if:image' => array (
  873. 'condition' => $bImage,
  874. 'content' => array(
  875. 'image_url' => $sImage,
  876. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40)
  877. ),
  878. ),
  879. 'title' => $aItem['title'],
  880. 'vendor' => $aItem['author_name'],
  881. 'versions' => _t('_adm_str_txt_update_from_to', $aItem['file_version'], $aItem['file_version_to']),
  882. 'bx_if:show_download' => array(
  883. 'condition' => $bDownloadable,
  884. 'content' => array(
  885. 'caption' => _t($this->bAuthAccessUpdates ? '_adm_btn_download_submit' : '_adm_btn_install_submit'),
  886. 'on_click' => $sJsObject . "." . ($this->bAuthAccessUpdates ? "getFile(" . $aItem['file_id'] . ", this)" : "getUpdateAndInstall('" . $aItem['name'] . "', this)")
  887. )
  888. )
  889. ));
  890. }
  891. return $sResult;
  892. }
  893. protected function displayCategories($aCategories)
  894. {
  895. foreach($aCategories['bx_repeat:cats'] as $iKey => $aItem)
  896. $aCategories['bx_repeat:cats'][$iKey]['url'] = $this->getBaseUrl(array('page' => 'category', 'value' => $aItem['value'], 'title' => urlencode($aItem['name'])));
  897. return BxDolStudioTemplate::getInstance()->parseHtmlByName('str_lbl_categories.html', $aCategories);
  898. }
  899. protected function displayTags($aTags)
  900. {
  901. foreach($aTags['bx_repeat:units'] as $iKey => $aItem)
  902. $aTags['bx_repeat:units'][$iKey]['href'] = $this->getBaseUrl(array('page' => 'tag', 'value' => $aItem['keyword']));
  903. return BxDolStudioTemplate::getInstance()->parseHtmlByName('str_lbl_tags.html', $aTags);
  904. }
  905. protected function displayNonOwnerNotification()
  906. {
  907. if(BxDolStudioOAuth::isAuthorizedOwner())
  908. return;
  909. $oSession = BxDolSession::getInstance();
  910. if($oSession->getValue($this->sSessionKeyNonOwnerNotified) === true)
  911. return;
  912. $oSession->setValue($this->sSessionKeyNonOwnerNotified, true);
  913. return $this->getJsResultBy(array(
  914. 'message' => '_adm_msg_oauth_non_owner_logged',
  915. 'translate' => array(BX_DOL_MARKET_URL_ROOT),
  916. 'on_page_load' => true
  917. ));
  918. }
  919. private function getDownloadedModules($bNamesOnly = true)
  920. {
  921. $aModules = BxDolStudioInstallerUtils::getInstance()->getModules(false);
  922. return $bNamesOnly ? array_keys($aModules) : $aModules;
  923. }
  924. private function getVoteStars($aItem)
  925. {
  926. $aTmplVarsStars = array();
  927. for($i = (int)$aItem['rate_min']; $i <= (int)$aItem['rate_max']; $i++)
  928. $aTmplVarsStars[] = array('value' => $i);
  929. return BxDolStudioTemplate::getInstance()->parseHtmlByName('str_vote_stars.html', array(
  930. 'id' => $aItem['id'],
  931. 'value' => (float)$aItem['rate'],
  932. 'bx_repeat:stars' => $aTmplVarsStars,
  933. 'bx_repeat:slider' => $aTmplVarsStars,
  934. ));
  935. }
  936. }
  937. /** @} */