BxBaseStudioStore.php 41 KB

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