BxBaseStudioStore.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  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(strtolower($aDownloaded[$sModuleName]['version']), strtolower($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. $aResult = array();
  663. $mixedResult = $this->loadUpdate($sModuleName, $bApplyUpdate);
  664. if($mixedResult === true)
  665. $aResult = array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => _t('_adm_str_msg_download' . ($bApplyUpdate ? '_and_install' : '') . '_successfully'));
  666. else if(is_string($mixedResult))
  667. $aResult = array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
  668. else if(is_array($mixedResult))
  669. $aResult = array_merge(array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_str_err_download_failed')), $mixedResult);
  670. $aResult['reload'] = 3000;
  671. return $aResult;
  672. }
  673. protected function displayProducts($mixedItems, $aParams = array())
  674. {
  675. $bShowRating = false;
  676. if(!is_array($mixedItems))
  677. return MsgBox($mixedItems);
  678. $sJsObject = $this->getPageJsObject();
  679. $oTemplate = BxDolStudioTemplate::getInstance();
  680. $aDownloaded = $this->getDownloadedModules();
  681. $bShoppingCart = isset($aParams['is_shopping_cart']) && $aParams['is_shopping_cart'];
  682. $sResult = '';
  683. foreach($mixedItems as $aItem) {
  684. $bFree = (int)$aItem['is_free'] == 1;
  685. $bPurchased = (int)$aItem['is_purchased'] == 1;
  686. $bPurchaseSingle = !$bShoppingCart && !$bFree && !$bPurchased && (float)$aItem['price_single'] != 0;
  687. $bInCart = $bPurchaseSingle && BxDolStudioCart::getInstance()->exists($aItem['author_id'], $aItem['id']);
  688. $bPurchaseRecurring = !$bShoppingCart && !$bFree && !$bPurchased && (float)$aItem['price_recurring'] != 0;
  689. $bDownloadable = (int)$aItem['is_file'] == 1;
  690. $bDownloaded = in_array($aItem['name'], $aDownloaded);
  691. $bDownload = !$bShoppingCart && ($bFree || $bPurchased) && $bDownloadable;
  692. $bQueued = $this->oDb->isQueued('download', $aItem['name']);
  693. $sPrice = !$bFree ? _t('_adm_str_txt_price_single', $aItem['author_currency_sign'], $aItem['price_single']) : _t('_adm_str_txt_price_free');
  694. $sDiscount = !$bFree && !empty($aItem['discount_single']) ? _t('_adm_str_txt_discount_csign', $aItem['author_currency_sign'], $aItem['discount_single']['price']) : '';
  695. $sIcon = !empty($aItem['thumbnail']['small']) ? $aItem['thumbnail']['small'] : BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  696. $bIcon = strpos($sIcon, '.') !== false;
  697. $sImage = '';
  698. if(!empty($aItem['cover']['medium']))
  699. $sImage = $aItem['cover']['medium'];
  700. else if(!empty($aItem['cover']['large']))
  701. $sImage = $aItem['cover']['large'];
  702. else if(!empty($aItem['cover']['big']))
  703. $sImage = $aItem['cover']['big'];
  704. $bImage = !empty($sImage) && strpos($sImage, '.') !== false;
  705. $aTmplVarsRate = array();
  706. $bTmplVarsRate = $bShowRating && !$bShoppingCart;
  707. if($bTmplVarsRate)
  708. $aTmplVarsRate = array(
  709. 'rate' => $this->getVoteStars($aItem)
  710. );
  711. $aTmplVarsVotes = array();
  712. $bTmplVarsVotes = $bShowRating && !$bShoppingCart && (int)$aItem['votes_cnt'] > 0;
  713. if($bTmplVarsVotes)
  714. $aTmplVarsVotes = array(
  715. 'count' => (int)$aItem['votes_cnt']
  716. );
  717. $sResult .= $oTemplate->parseHtmlByName('str_product_v2.html', array(
  718. 'js_object' => $sJsObject,
  719. 'id' => $aItem['id'],
  720. 'name' => $aItem['name'],
  721. 'url' => $aItem['url'],
  722. 'description_plain_attr' => bx_html_attribute($aItem['description_plain']),
  723. 'bx_if:no_icon' => array (
  724. 'condition' => !$bIcon,
  725. 'content' => array(
  726. 'icon' => $sIcon
  727. ),
  728. ),
  729. 'bx_if:icon' => array (
  730. 'condition' => $bIcon,
  731. 'content' => array(
  732. 'icon_url' => $sIcon,
  733. ),
  734. ),
  735. 'bx_if:no_image' => array (
  736. 'condition' => !$bImage,
  737. 'content' => array(
  738. 'description_plain' => $aItem['description_plain'],
  739. 'strecher' => mb_strlen($aItem['description_plain']) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($aItem['description_plain'])) / 6))
  740. ),
  741. ),
  742. 'bx_if:image' => array (
  743. 'condition' => $bImage,
  744. 'content' => array(
  745. 'image_url' => $sImage,
  746. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40)
  747. ),
  748. ),
  749. 'title' => $aItem['title'],
  750. 'bx_if:show_vendor' => array(
  751. 'condition' => !$bShoppingCart,
  752. 'content' => array(
  753. 'vendor_name' => $aItem['author_name'],
  754. 'vendor_url' => $aItem['author_url'],
  755. 'bx_if:show_version' => array(
  756. 'condition' => !empty($aItem['file_version']),
  757. 'content' => array(
  758. 'version' => $aItem['file_version'],
  759. )
  760. ),
  761. )
  762. ),
  763. 'bx_if:show_count_price' => array(
  764. 'condition' => $bShoppingCart,
  765. 'content' => array(
  766. 'count' => isset($aParams['counts'][$aItem['id']]) ? (int)$aParams['counts'][$aItem['id']] : 1,
  767. 'price_single' => $sPrice,
  768. 'discount_single' => $sDiscount,
  769. )
  770. ),
  771. 'bx_if:show_rate' => array(
  772. 'condition' => $bTmplVarsRate,
  773. 'content' => $aTmplVarsRate
  774. ),
  775. 'bx_if:show_votes' => array(
  776. 'condition' => $bTmplVarsVotes,
  777. 'content' => $aTmplVarsVotes
  778. ),
  779. 'bx_if:show_purchase_single' => array(
  780. 'condition' => $bPurchaseSingle && !$bInCart,
  781. 'content' => array(
  782. 'js_object' => $sJsObject,
  783. 'id' => $aItem['id'],
  784. 'vendor_id' => $aItem['author_id'],
  785. 'price_single' => _t('_adm_str_txt_price_single', $aItem['author_currency_sign'], $aItem['price_single'])
  786. )
  787. ),
  788. 'bx_if:show_checkout_single' => array(
  789. 'condition' => $bPurchaseSingle,
  790. 'content' => array(
  791. 'js_object' => $sJsObject,
  792. 'id' => $aItem['id'],
  793. 'vendor_id' => $aItem['author_id'],
  794. 'bx_if:show_as_hidden' => array(
  795. 'condition' => !$bInCart,
  796. 'content' => array()
  797. )
  798. )
  799. ),
  800. 'bx_if:show_purchase_recurring' => array(
  801. 'condition' => $bPurchaseRecurring,
  802. 'content' => array(
  803. 'js_object' => $sJsObject,
  804. 'id' => $aItem['id'],
  805. 'vendor_id' => $aItem['author_id'],
  806. 'price_recurring' => _t('_adm_str_txt_price_recurring', $aItem['author_currency_sign'], $aItem['price_recurring'], _t('_adm_str_txt_per_' . $aItem['duration_recurring'] . '_short'))
  807. )
  808. ),
  809. 'bx_if:show_download' => array(
  810. 'condition' => $bDownload && !$bQueued && !$bDownloaded,
  811. 'content' => array(
  812. 'js_object' => $sJsObject,
  813. 'file_id' => $aItem['file_id']
  814. )
  815. ),
  816. 'bx_if:show_download_disabled' => array(
  817. 'condition' => $bDownload && !$bQueued && $bDownloaded,
  818. 'content' => array()
  819. ),
  820. 'bx_if:show_queued_disabled' => array(
  821. 'condition' => $bDownload && $bQueued && !$bDownloaded,
  822. 'content' => array()
  823. ),
  824. 'bx_if:show_delete' => array(
  825. 'condition' => $bShoppingCart,
  826. 'content' => array(
  827. 'js_object' => $sJsObject,
  828. 'id' => $aItem['id'],
  829. 'vendor_id' => $aItem['author_id']
  830. )
  831. )
  832. ));
  833. }
  834. return $sResult;
  835. }
  836. protected function displayUpdates($mixedItems, $aParams = array())
  837. {
  838. if(!is_array($mixedItems))
  839. return MsgBox($mixedItems);
  840. if(empty($mixedItems))
  841. return MsgBox(_t('_Empty'));
  842. $sJsObject = $this->getPageJsObject();
  843. $oTemplate = BxDolStudioTemplate::getInstance();
  844. $sResult = '';
  845. foreach($mixedItems as $aItem) {
  846. $bDownloadable = (int)$aItem['is_file'] == 1;
  847. $bQueued = $this->oDb->isQueued('download', $aItem['name']);
  848. $sIcon = !empty($aItem['thumbnail']['big']) ? $aItem['thumbnail']['big'] : BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  849. $bIcon = strpos($sIcon, '.') !== false;
  850. $sImage = !empty($aItem['cover']['big']) ? $aItem['cover']['big'] : '';
  851. $bImage = strpos($sImage, '.') !== false;
  852. $sResult .= $oTemplate->parseHtmlByName('str_update_v2.html', array(
  853. 'js_object' => $sJsObject,
  854. 'id' => $aItem['id'],
  855. 'name' => $aItem['name'],
  856. 'url' => $aItem['url'],
  857. 'bx_if:no_icon' => array (
  858. 'condition' => !$bIcon,
  859. 'content' => array(
  860. 'icon' => $sIcon
  861. ),
  862. ),
  863. 'bx_if:icon' => array (
  864. 'condition' => $bIcon,
  865. 'content' => array(
  866. 'icon_url' => $sIcon,
  867. ),
  868. ),
  869. 'bx_if:no_image' => array (
  870. 'condition' => !$bImage,
  871. 'content' => array(
  872. 'note' => $aItem['description_plain'],
  873. 'strecher' => mb_strlen($aItem['description_plain']) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($aItem['description_plain'])) / 6))
  874. ),
  875. ),
  876. 'bx_if:image' => array (
  877. 'condition' => $bImage,
  878. 'content' => array(
  879. 'image_url' => $sImage,
  880. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40)
  881. ),
  882. ),
  883. 'title' => $aItem['title'],
  884. 'vendor' => $aItem['author_name'],
  885. 'versions' => _t('_adm_str_txt_update_from_to', $aItem['file_version'], $aItem['file_version_to']),
  886. 'bx_if:show_download' => array(
  887. 'condition' => $bDownloadable && !$bQueued,
  888. 'content' => array(
  889. 'caption' => _t($this->bAuthAccessUpdates ? '_adm_btn_download_submit' : '_adm_btn_install_submit'),
  890. 'on_click' => $sJsObject . "." . ($this->bAuthAccessUpdates ? "getFile(" . $aItem['file_id'] . ", this)" : "getUpdateAndInstall('" . $aItem['name'] . "', this)")
  891. )
  892. ),
  893. 'bx_if:show_queued_disabled' => array(
  894. 'condition' => $bDownloadable && $bQueued,
  895. 'content' => array()
  896. )
  897. ));
  898. }
  899. return $sResult;
  900. }
  901. protected function displayCategories($aCategories)
  902. {
  903. foreach($aCategories['bx_repeat:cats'] as $iKey => $aItem)
  904. $aCategories['bx_repeat:cats'][$iKey]['url'] = $this->getBaseUrl(array('page' => 'category', 'value' => $aItem['value'], 'title' => urlencode($aItem['name'])));
  905. return BxDolStudioTemplate::getInstance()->parseHtmlByName('str_lbl_categories.html', $aCategories);
  906. }
  907. protected function displayTags($aTags)
  908. {
  909. foreach($aTags['bx_repeat:units'] as $iKey => $aItem)
  910. $aTags['bx_repeat:units'][$iKey]['href'] = $this->getBaseUrl(array('page' => 'tag', 'value' => $aItem['keyword']));
  911. return BxDolStudioTemplate::getInstance()->parseHtmlByName('str_lbl_tags.html', $aTags);
  912. }
  913. protected function displayNonOwnerNotification()
  914. {
  915. if(BxDolStudioOAuth::isAuthorizedOwner())
  916. return;
  917. $oSession = BxDolSession::getInstance();
  918. if($oSession->getValue($this->sSessionKeyNonOwnerNotified) === true)
  919. return;
  920. $oSession->setValue($this->sSessionKeyNonOwnerNotified, true);
  921. return $this->getJsResultBy(array(
  922. 'message' => '_adm_msg_oauth_non_owner_logged',
  923. 'translate' => array(BX_DOL_MARKET_URL_ROOT),
  924. 'on_page_load' => true
  925. ));
  926. }
  927. private function getDownloadedModules($bNamesOnly = true)
  928. {
  929. $aModules = BxDolStudioInstallerUtils::getInstance()->getModules(false);
  930. return $bNamesOnly ? array_keys($aModules) : $aModules;
  931. }
  932. private function getVoteStars($aItem)
  933. {
  934. $aTmplVarsStars = array();
  935. for($i = (int)$aItem['rate_min']; $i <= (int)$aItem['rate_max']; $i++)
  936. $aTmplVarsStars[] = array('value' => $i);
  937. return BxDolStudioTemplate::getInstance()->parseHtmlByName('str_vote_stars.html', array(
  938. 'id' => $aItem['id'],
  939. 'value' => (float)$aItem['rate'],
  940. 'bx_repeat:stars' => $aTmplVarsStars,
  941. 'bx_repeat:slider' => $aTmplVarsStars,
  942. ));
  943. }
  944. }
  945. /** @} */