BxMarketModule.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  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 Market Market
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_MARKET_LICENSE_TYPE_SINGLE', 'single'); //--- one-time payment license
  12. define('BX_MARKET_LICENSE_TYPE_RECURRING', 'recurring'); //--- recurring payment license
  13. define('BX_MARKET_FILE_TYPE_VERSION', 'version');
  14. define('BX_MARKET_FILE_TYPE_UPDATE', 'update');
  15. /**
  16. * Market module
  17. */
  18. class BxMarketModule extends BxBaseModTextModule
  19. {
  20. function __construct(&$aModule)
  21. {
  22. parent::__construct($aModule);
  23. $CNF = &$this->_oConfig->CNF;
  24. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  25. $CNF['FIELD_NAME'],
  26. $CNF['FIELD_PRICE_SINGLE'],
  27. $CNF['FIELD_PRICE_RECURRING'],
  28. $CNF['FIELD_DURATION_RECURRING'],
  29. $CNF['FIELD_TRIAL_RECURRING'],
  30. $CNF['FIELD_ALLOW_PURCHASE_TO'],
  31. $CNF['FIELD_ALLOW_COMMENT_TO'],
  32. $CNF['FIELD_ALLOW_VOTE_TO']
  33. ));
  34. }
  35. public function actionPerform()
  36. {
  37. $CNF = &$this->_oConfig->CNF;
  38. $aContentInfo = $this->_getContentInfo();
  39. if(empty($aContentInfo) || !is_array($aContentInfo))
  40. return echoJson(array('code' => 1));
  41. $sAction = bx_process_input(bx_get('action'));
  42. if(empty($CNF['MENU_ITEM_TO_METHOD'][$CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']][$sAction]))
  43. return echoJson(array('code' => 2));
  44. $sMethodCheck = $CNF['MENU_ITEM_TO_METHOD'][$CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']][$sAction];
  45. $sMethodPerform = '_perform' . bx_gen_method_name($sAction, array('-', '_'));
  46. if(!method_exists($this, $sMethodCheck) || $this->$sMethodCheck($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED || !method_exists($this, $sMethodPerform))
  47. return echoJson(array('code' => 3, 'msg' => _t('_sys_txt_access_denied')));
  48. return $this->$sMethodPerform($aContentInfo);
  49. }
  50. public function actionCheckName()
  51. {
  52. $CNF = &$this->_oConfig->CNF;
  53. $sName = '';
  54. $sTitle = bx_process_input(bx_get('title'));
  55. if(empty($sTitle))
  56. return echoJson(array());
  57. $iId = (int)bx_get('id');
  58. if(!empty($iId)) {
  59. $aEntry = $this->_oDb->getContentInfoById($iId);
  60. if(strcmp($sTitle, $aEntry[$CNF['FIELD_NAME']]) == 0)
  61. $sName = $sTitle;
  62. }
  63. echoJson(array(
  64. 'title' => $sTitle,
  65. 'name' => !empty($sName) ? $sName : $this->_oConfig->getEntryName($sTitle, $iId)
  66. ));
  67. }
  68. public function actionGetSubentries()
  69. {
  70. $CNF = &$this->_oConfig->CNF;
  71. $sTerm = bx_get('term');
  72. $iLimit = (int)bx_get('limit');
  73. if(empty($iLimit))
  74. $iLimit = 10;
  75. $aResult = array();
  76. $aEntries = $this->_oDb->searchByAuthorTerm($this->_iProfileId, $sTerm, $iLimit);
  77. foreach ($aEntries as $aEntry)
  78. $aResult[] = array('value' => $aEntry[$CNF['FIELD_ID']], 'label' => $aEntry[$CNF['FIELD_TITLE']]);
  79. // sort result
  80. usort($aResult, function($r1, $r2) {
  81. return strcmp($r1['label'], $r2['label']);
  82. });
  83. echoJson(array_slice($aResult, 0, $iLimit));
  84. }
  85. /**
  86. * @page service Service Calls
  87. * @section bx_market Market
  88. * @subsection bx_market-other Other
  89. * @subsubsection bx_market-get_searchable_fields get_searchable_fields
  90. *
  91. * @code bx_srv('bx_market', 'get_searchable_fields', [...]); @endcode
  92. *
  93. * Get a list of searchable fields. Is used in common search engine.
  94. *
  95. * @return an array with a list of searchable fields.
  96. *
  97. * @see BxMarketModule::serviceGetSearchableFields
  98. */
  99. /**
  100. * @ref bx_market-get_searchable_fields "get_searchable_fields"
  101. */
  102. public function serviceGetSearchableFields ()
  103. {
  104. $CNF = &$this->_oConfig->CNF;
  105. $aResult = parent::serviceGetSearchableFields();
  106. unset($aResult[$CNF['FIELD_PRICE_SINGLE']], $aResult[$CNF['FIELD_TRIAL_RECURRING']]);
  107. return $aResult;
  108. }
  109. /**
  110. * @page service Service Calls
  111. * @section bx_market Market
  112. * @subsection bx_market-page_blocks Page Blocks
  113. * @subsubsection bx_market-entity_create entity_create
  114. *
  115. * @code bx_srv('bx_market', 'entity_create', [...]); @endcode
  116. *
  117. * Get page block with product creation form or an error message if something wasn't configured correctly.
  118. *
  119. * @param $sDisplay form display name to use
  120. * @return HTML string with block content to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  121. *
  122. * @see BxMarketModule::serviceEntityCreate
  123. */
  124. /**
  125. * @ref bx_market-entity_create "entity_create"
  126. */
  127. public function serviceEntityCreate ($sDisplay = false)
  128. {
  129. $oPayments = BxDolPayments::getInstance();
  130. if(!$oPayments->isActive())
  131. return MsgBox(_t('_bx_market_err_no_payments'));
  132. if(!$oPayments->isAcceptingPayments($this->_iProfileId))
  133. return MsgBox(_t('_bx_market_err_not_accept_payments', $oPayments->getDetailsUrl()));
  134. return parent::serviceEntityCreate($sDisplay);
  135. }
  136. /**
  137. * @page service Service Calls
  138. * @section bx_market Market
  139. * @subsection bx_market-page_blocks Page Blocks
  140. * @subsubsection bx_market-entity_download entity_download
  141. *
  142. * @code bx_srv('bx_market', 'entity_download', [...]); @endcode
  143. *
  144. * Get page block with a list of downloadable packages attached to the product. If something is wrong an error message is returned.
  145. *
  146. * @param $iContentId (optional) product's ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  147. * @return an array describing a block to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  148. *
  149. * @see BxMarketModule::serviceEntityDownload
  150. */
  151. /**
  152. * @ref bx_market-entity_download "entity_download"
  153. */
  154. public function serviceEntityDownload ($iContentId = 0)
  155. {
  156. $CNF = &$this->_oConfig->CNF;
  157. if(!$iContentId)
  158. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  159. if(!$iContentId)
  160. return false;
  161. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  162. if(empty($aContentInfo) || !is_array($aContentInfo))
  163. return MsgBox(_t('_sys_txt_error_occured'));
  164. if($this->checkAllowedDownload($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  165. return MsgBox(_t('_bx_market_err_access_denied'));
  166. $sJsObject = $this->_oConfig->getJsObject('entry');
  167. $oMenu = new BxTemplMenu(array('template' => 'menu_vertical.html', 'menu_id'=> 'bx-market-downloads', 'menu_items' => array(
  168. array('id' => 'bx-market-show-more', 'name' => 'bx-market-show-more', 'class' => '', 'link' => 'javascript:void(0)', 'target' => '_self', 'onclick' => 'javascript:' . $sJsObject . '.showMore();', 'title' => _t('_bx_market_menu_item_title_downloads_more')),
  169. )));
  170. return array(
  171. 'menu' => $oMenu,
  172. 'content' => $this->_oTemplate->entryAttachmentsByStorage($CNF['OBJECT_STORAGE_FILES'], $aContentInfo, array(
  173. 'filter_field' => ''
  174. ))
  175. );
  176. }
  177. /**
  178. * @page service Service Calls
  179. * @section bx_market Market
  180. * @subsection bx_market-page_blocks Page Blocks
  181. * @subsubsection bx_market-entity_rating entity_rating
  182. *
  183. * @code bx_srv('bx_market', 'entity_rating', [...]); @endcode
  184. *
  185. * Get page block with Stars based product's rating.
  186. *
  187. * @param $iContentId (optional) product's ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  188. * @return HTML string with block content to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  189. *
  190. * @see BxMarketModule::serviceEntityRating
  191. */
  192. /**
  193. * @ref bx_market-entity_rating "entity_rating"
  194. */
  195. public function serviceEntityRating($iContentId = 0)
  196. {
  197. return $this->_serviceTemplateFunc ('entryRating', $iContentId);
  198. }
  199. /**
  200. * @page service Service Calls
  201. * @section bx_market Market
  202. * @subsection bx_market-page_blocks Page Blocks
  203. * @subsubsection bx_market-entity_author_entities entity_author_entities
  204. *
  205. * @code bx_srv('bx_market', 'entity_author_entities', [...]); @endcode
  206. *
  207. * Get page block with a list of other products of the same author.
  208. *
  209. * @param $iContentId (optional) product's ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  210. * @return an array describing a block to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  211. *
  212. * @see BxMarketModule::serviceEntityAuthorEntities
  213. */
  214. /**
  215. * @ref bx_market-entity_author_entities "entity_author_entities"
  216. */
  217. public function serviceEntityAuthorEntities($iContentId = 0)
  218. {
  219. $CNF = &$this->_oConfig->CNF;
  220. $aContentInfo = $this->_getContentInfo($iContentId);
  221. if($aContentInfo === false)
  222. return false;
  223. $oProfile = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]);
  224. if (!$oProfile)
  225. $oProfile = BxDolProfileUndefined::getInstance();
  226. $aBlock = $this->_serviceBrowse ('author', array('author' => $aContentInfo[$CNF['FIELD_AUTHOR']], 'except' => array($iContentId), 'per_page' => 2), BX_DB_PADDING_DEF, true);
  227. $aBlock['title'] = _t('_bx_market_page_block_title_entry_author_entries', $oProfile->getDisplayName());
  228. return $aBlock;
  229. }
  230. /**
  231. * @page service Service Calls
  232. * @section bx_market Market
  233. * @subsection bx_market-page_blocks Page Blocks
  234. * @subsubsection bx_market-block_licenses block_licenses
  235. *
  236. * @code bx_srv('bx_market', 'block_licenses', [...]); @endcode
  237. *
  238. * Get page block with a list of licenses purchased by currently logged member.
  239. *
  240. * @return an array describing a block to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  241. *
  242. * @see BxMarketModule::serviceBlockLicenses
  243. */
  244. /**
  245. * @ref bx_market-block_licenses "block_licenses"
  246. */
  247. public function serviceBlockLicenses()
  248. {
  249. return $this->_getBlockLicenses();
  250. }
  251. /**
  252. * @page service Service Calls
  253. * @section bx_market Market
  254. * @subsection bx_market-page_blocks Page Blocks
  255. * @subsubsection bx_market-block_licenses_administration block_licenses_administration
  256. *
  257. * @code bx_srv('bx_market', 'block_licenses_administration', [...]); @endcode
  258. *
  259. * Get page block with a list of all licenses. It's needed for moderators/administrators.
  260. *
  261. * @return an array describing a block to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  262. *
  263. * @see BxMarketModule::serviceBlockLicensesAdministration
  264. */
  265. /**
  266. * @ref bx_market-block_licenses "block_licenses"
  267. */
  268. public function serviceBlockLicensesAdministration()
  269. {
  270. return $this->_getBlockLicenses('administration');
  271. }
  272. /**
  273. * @page service Service Calls
  274. * @section bx_market Market
  275. * @subsection bx_market-page_blocks Page Blocks
  276. * @subsubsection bx_market-block_licenses_note block_licenses_note
  277. *
  278. * @code bx_srv('bx_market', 'block_licenses_note', [...]); @endcode
  279. *
  280. * Get page block with a notice for licenses usage.
  281. *
  282. * @return HTML string with block content to display on the site.
  283. *
  284. * @see BxMarketModule::serviceBlockLicensesNote
  285. */
  286. /**
  287. * @ref bx_market-block_licenses_note "block_licenses_note"
  288. */
  289. public function serviceBlockLicensesNote()
  290. {
  291. return MsgBox(_t('_bx_market_page_block_content_licenses_note'));
  292. }
  293. /**
  294. * @page service Service Calls
  295. * @section bx_market Market
  296. * @subsection bx_market-licenses Licenses
  297. * @subsubsection bx_market-get_unused_licenses_num get_unused_licenses_num
  298. *
  299. * @code bx_srv('bx_market', 'get_unused_licenses_num', [...]); @endcode
  300. *
  301. * Get number of unused licenses for some profile. It can be used in menus with "alert" counters.
  302. *
  303. * @param $iProfileId profile to get unused licenses for, if omitted then currently logged in profile is used
  304. * @return an integer value with a number of unused licenses.
  305. *
  306. * @see BxMarketModule::serviceGetUnusedLicensesNum
  307. */
  308. /**
  309. * @ref bx_market-get_unused_licenses_num "get_unused_licenses_num"
  310. */
  311. public function serviceGetUnusedLicensesNum ($iProfileId = 0)
  312. {
  313. if(!$iProfileId)
  314. $iProfileId = bx_get_logged_profile_id();
  315. $aLicenses = $this->_oDb->getLicense(array('type' => 'new', 'profile_id' => (int)$iProfileId));
  316. return !empty($aLicenses) && is_array($aLicenses) ? count($aLicenses) : 0;
  317. }
  318. /**
  319. * @page service Service Calls
  320. * @section bx_market Market
  321. * @subsection bx_market-licenses Licenses
  322. * @subsubsection bx_market-has_license has_license
  323. *
  324. * @code bx_srv('bx_market', 'has_license', [...]); @endcode
  325. *
  326. * Check whether a profile has a license for specified product. Domain on which the license is used can be attached to checking.
  327. *
  328. * @param $iProfileId profile which ownership will be checked.
  329. * @param $iProductId product which the license(s) will be searched for.
  330. * @param $sDomain (optional) domain name on which the license is used.
  331. * @return boolean value determining where the license is available or not.
  332. *
  333. * @see BxMarketModule::serviceHasLicense
  334. */
  335. /**
  336. * @ref bx_market-has_license "has_license"
  337. */
  338. public function serviceHasLicense ($iProfileId, $iProductId, $sDomain = '')
  339. {
  340. return $this->_oDb->hasLicense($iProfileId, $iProductId, $sDomain);
  341. }
  342. /**
  343. * @page service Service Calls
  344. * @section bx_market Market
  345. * @subsection bx_market-licenses Licenses
  346. * @subsubsection bx_market-get_license get_license
  347. *
  348. * @code bx_srv('bx_market', 'has_license', [...]); @endcode
  349. *
  350. * Get a list of licenses which meet requirements provided in the input array.
  351. *
  352. * @param $aParams array of requirements which will be used for searching.
  353. * @return an array of licenses which meet requirements.
  354. *
  355. * @see BxMarketModule::serviceGetLicense
  356. */
  357. /**
  358. * @ref bx_market-get_license "get_license"
  359. */
  360. public function serviceGetLicense ($aParams)
  361. {
  362. return $this->_oDb->getLicense($aParams);
  363. }
  364. /**
  365. * @page service Service Calls
  366. * @section bx_market Market
  367. * @subsection bx_market-licenses Licenses
  368. * @subsubsection bx_market-update_license update_license
  369. *
  370. * @code bx_srv('bx_market', 'update_license', [...]); @endcode
  371. *
  372. * Update license(s) changing necessary fields. Updatable license(s) should meet requirements provided in the input array.
  373. *
  374. * @param $aSet an array of data to be saved
  375. * @param $aWhere an array of requirements which will be used for searching.
  376. * @return an array of licenses which meet requirements.
  377. *
  378. * @see BxMarketModule::serviceUpdateLicense
  379. */
  380. /**
  381. * @ref bx_market-update_license "update_license"
  382. */
  383. public function serviceUpdateLicense ($aSet, $aWhere)
  384. {
  385. return $this->_oDb->updateLicense($aSet, $aWhere);
  386. }
  387. /**
  388. * @page service Service Calls
  389. * @section bx_market Market
  390. * @subsection bx_market-browsing Browsing
  391. * @subsubsection bx_market-get_entry_by get_entry_by
  392. *
  393. * @code bx_srv('bx_market', 'get_entry_by', [...]); @endcode
  394. *
  395. * Get entry (product) which meets requirements.
  396. *
  397. * @param $sType string with search type.
  398. * @param $mixedValue mixed value to be used for searching.
  399. * @return an array describing a product which meets requirements.
  400. *
  401. * @see BxMarketModule::serviceGetEntryBy
  402. */
  403. /**
  404. * @ref bx_market-get_entry_by "get_entry_by"
  405. */
  406. public function serviceGetEntryBy($sType, $mixedValue)
  407. {
  408. return $this->_oDb->getContentInfoBy(array('type' => $sType, 'value' => $mixedValue));
  409. }
  410. /**
  411. * @page service Service Calls
  412. * @section bx_market Market
  413. * @subsection bx_market-browsing Browsing
  414. * @subsubsection bx_market-get_entries_by get_entries_by
  415. *
  416. * @code bx_srv('bx_market', 'get_entries_by', [...]); @endcode
  417. *
  418. * Get an array of entries (products) which meet requirements.
  419. *
  420. * @param $aParams an array of requirements which will be used for searching.
  421. * @return an array of products which meets requirements.
  422. *
  423. * @see BxMarketModule::serviceGetEntriesBy
  424. */
  425. /**
  426. * @ref bx_market-get_entries_by "get_entries_by"
  427. */
  428. public function serviceGetEntriesBy($aParams)
  429. {
  430. return $this->_oDb->getContentInfoBy($aParams);
  431. }
  432. /**
  433. * @page service Service Calls
  434. * @section bx_market Market
  435. * @subsection bx_market-entry Entry
  436. * @subsubsection bx_market-get_thumbnail get_thumbnail
  437. *
  438. * @code bx_srv('bx_market', 'get_thumbnail', [...]); @endcode
  439. *
  440. * Get an array of image URLs for the product's thumbnail. Returned images have different dimensions ('small' and 'big').
  441. *
  442. * @param $iPhotoId photo ID which is attached to a product as thumbnail.
  443. * @return an array of image URLs.
  444. *
  445. * @see BxMarketModule::serviceGetThumbnail
  446. */
  447. /**
  448. * @ref bx_market-get_thumbnail "get_thumbnail"
  449. */
  450. public function serviceGetThumbnail($iPhotoId)
  451. {
  452. $CNF = &$this->_oConfig->CNF;
  453. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  454. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  455. return array(
  456. 'small' => $oImagesTranscoder ? $oImagesTranscoder->getFileUrl($iPhotoId) : '',
  457. 'big' => $oStorage ? $oStorage->getFileUrlById($iPhotoId) : ''
  458. );
  459. }
  460. /**
  461. * @page service Service Calls
  462. * @section bx_market Market
  463. * @subsection bx_market-entry Entry
  464. * @subsubsection bx_market-get_cover get_cover
  465. *
  466. * @code bx_srv('bx_market', 'get_cover', [...]); @endcode
  467. *
  468. * Get an array of image URLs for the product's cover. Returned images have different dimensions ('small', 'large' and 'big').
  469. *
  470. * @param $iPhotoId photo ID which is attached to a product as cover.
  471. * @return an array of image URLs.
  472. *
  473. * @see BxMarketModule::serviceGetCover
  474. */
  475. /**
  476. * @ref bx_market-get_cover "get_cover"
  477. */
  478. public function serviceGetCover($iPhotoId)
  479. {
  480. $CNF = &$this->_oConfig->CNF;
  481. $oTiGallery = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  482. $oTiPage = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_COVER']);
  483. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  484. return array(
  485. 'medium' => $oTiGallery ? $oTiGallery->getFileUrl($iPhotoId) : '',
  486. 'large' => $oTiPage ? $oTiPage->getFileUrl($iPhotoId) : '',
  487. 'big' => $oStorage ? $oStorage->getFileUrlById($iPhotoId) : ''
  488. );
  489. }
  490. /**
  491. * @page service Service Calls
  492. * @section bx_market Market
  493. * @subsection bx_market-entry Entry
  494. * @subsubsection bx_market-get_file get_file
  495. *
  496. * @code bx_srv('bx_market', 'get_file', [...]); @endcode
  497. *
  498. * Get an array with file's description.
  499. *
  500. * @param $iFileId file ID which is attached to a product as package (version, update, etc).
  501. * @return an array with file's description.
  502. *
  503. * @see BxMarketModule::serviceGetFile
  504. */
  505. /**
  506. * @ref bx_market-get_file "get_file"
  507. */
  508. public function serviceGetFile($iFileId)
  509. {
  510. $CNF = &$this->_oConfig->CNF;
  511. $aFile = $this->_oDb->getFile(array(
  512. 'type' => 'file_id_ext',
  513. 'file_id' => $iFileId
  514. ));
  515. if(!empty($aFile) && is_array($aFile)) {
  516. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
  517. $aFile['file_url'] = $oStorage ? $oStorage->getFileUrlById($iFileId) : '';
  518. }
  519. return $aFile;
  520. }
  521. /**
  522. * @page service Service Calls
  523. * @section bx_market Market
  524. * @subsection bx_market-entry Entry
  525. * @subsubsection bx_market-get_updates get_updates
  526. *
  527. * @code bx_srv('bx_market', 'get_updates', [...]); @endcode
  528. *
  529. * Get an array with update(s)' description(s).
  530. *
  531. * @param $iContentId product's ID.
  532. * @param $sVersion (optional) if version is specified then it will be used for searching as 'Version From'.
  533. * @return an array with update(s)' description(s).
  534. *
  535. * @see BxMarketModule::serviceGetUpdates
  536. */
  537. /**
  538. * @ref bx_market-get_updates "get_updates"
  539. */
  540. public function serviceGetUpdates($iContentId, $sVersion = '')
  541. {
  542. $CNF = &$this->_oConfig->CNF;
  543. $aFile = $this->_oDb->getFile(array(
  544. 'type' => 'content_id_and_type',
  545. 'content_id' => $iContentId,
  546. 'file_type' => 'update',
  547. 'version' => $sVersion
  548. ));
  549. if(!empty($aFile) && is_array($aFile)) {
  550. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
  551. $aFile['file_url'] = $oStorage ? $oStorage->getFileUrlById($aFile['file_id']) : '';
  552. }
  553. return $aFile;
  554. }
  555. /**
  556. * @page service Service Calls
  557. * @section bx_market Market
  558. * @subsection bx_market-entry Entry
  559. * @subsubsection bx_market-get_screenshots get_screenshots
  560. *
  561. * @code bx_srv('bx_market', 'get_screenshots', [...]); @endcode
  562. *
  563. * Get an array with screenshots' descriptions.
  564. *
  565. * @param $iItemId product's ID.
  566. * @return an array with screenshots' descriptions.
  567. *
  568. * @see BxMarketModule::serviceGetScreenshots
  569. */
  570. /**
  571. * @ref bx_market-get_screenshots "get_screenshots"
  572. */
  573. public function serviceGetScreenshots($iItemId)
  574. {
  575. $CNF = &$this->_oConfig->CNF;
  576. if(!$iItemId)
  577. return array();
  578. $aData = $this->_oDb->getContentInfoById($iItemId);
  579. $aPhotos = $this->_oDb->getPhoto(array('type' => 'content_id', 'content_id' => $aData[$CNF['FIELD_ID']], 'except' => array($aData[$CNF['FIELD_THUMB']], $aData[$CNF['FIELD_COVER']])));
  580. if(empty($aPhotos) || !is_array($aPhotos))
  581. return array();
  582. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  583. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_SCREENSHOT']);
  584. $aResult = array();
  585. foreach($aPhotos as $aPhoto)
  586. $aResult[] = array(
  587. 'id' => $aPhoto['file_id'],
  588. 'url_sm' => $oImagesTranscoder ? $oImagesTranscoder->getFileUrl($aPhoto['file_id']) : '',
  589. 'url_bg' => $oStorage ? $oStorage->getFileUrlById($aPhoto['file_id']) : ''
  590. );
  591. return $aResult;
  592. }
  593. /**
  594. * @page service Service Calls
  595. * @section bx_market Market
  596. * @subsection bx_market-payments Payments
  597. * @subsubsection bx_market-get_payment_data get_payment_data
  598. *
  599. * @code bx_srv('bx_market', 'get_payment_data', [...]); @endcode
  600. *
  601. * Get an array with module's description. Is needed for payments processing module.
  602. *
  603. * @return an array with module's description.
  604. *
  605. * @see BxMarketModule::serviceGetPaymentData
  606. */
  607. /**
  608. * @ref bx_market-get_payment_data "get_payment_data"
  609. */
  610. public function serviceGetPaymentData()
  611. {
  612. $CNF = &$this->_oConfig->CNF;
  613. $oPermalink = BxDolPermalinks::getInstance();
  614. $aResult = $this->_aModule;
  615. $aResult['url_browse_order_common'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_LICENSES_COMMON'], array('filter' => '{order}'));
  616. $aResult['url_browse_order_administration'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_LICENSES_ADMINISTRATION'], array('filter' => '{order}'));
  617. return $aResult;
  618. }
  619. /**
  620. * @page service Service Calls
  621. * @section bx_market Market
  622. * @subsection bx_market-payments Payments
  623. * @subsubsection bx_market-get_cart_item get_cart_item
  624. *
  625. * @code bx_srv('bx_market', 'get_cart_item', [...]); @endcode
  626. *
  627. * Get an array with prodict's description. Is used in Shopping Cart in payments processing module.
  628. *
  629. * @param $iItemId product's ID.
  630. * @return an array with prodict's description. Empty array is returned if something is wrong.
  631. *
  632. * @see BxMarketModule::serviceGetCartItem
  633. */
  634. /**
  635. * @ref bx_market-get_cart_item "get_cart_item"
  636. */
  637. public function serviceGetCartItem($iItemId)
  638. {
  639. $CNF = &$this->_oConfig->CNF;
  640. if(!$iItemId)
  641. return array();
  642. $aItem = $this->_oDb->getContentInfoById($iItemId);
  643. if(empty($aItem) || !is_array($aItem))
  644. return array();
  645. return array (
  646. 'id' => $aItem[$CNF['FIELD_ID']],
  647. 'author_id' => $aItem[$CNF['FIELD_AUTHOR']],
  648. 'name' => $aItem[$CNF['FIELD_NAME']],
  649. 'title' => $aItem[$CNF['FIELD_TITLE']],
  650. 'description' => $aItem[$CNF['FIELD_TEXT']],
  651. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=view-product&id=' . $aItem[$CNF['FIELD_ID']]),
  652. 'price_single' => $aItem[$CNF['FIELD_PRICE_SINGLE']],
  653. 'price_recurring' => $aItem[$CNF['FIELD_PRICE_RECURRING']],
  654. 'period_recurring' => 1,
  655. 'period_unit_recurring' => $aItem[$CNF['FIELD_DURATION_RECURRING']],
  656. 'trial_recurring' => $aItem[$CNF['FIELD_TRIAL_RECURRING']]
  657. );
  658. }
  659. /**
  660. * @page service Service Calls
  661. * @section bx_market Market
  662. * @subsection bx_market-payments Payments
  663. * @subsubsection bx_market-get_cart_items get_cart_items
  664. *
  665. * @code bx_srv('bx_market', 'get_cart_items', [...]); @endcode
  666. *
  667. * Get an array with prodicts' descriptions by seller. Is used in Manual Order Processing in payments processing module.
  668. *
  669. * @param $iSellerId seller ID.
  670. * @return an array with prodicts' descriptions. Empty array is returned if something is wrong or seller doesn't have any products.
  671. *
  672. * @see BxMarketModule::serviceGetCartItems
  673. */
  674. /**
  675. * @ref bx_market-get_cart_items "get_cart_items"
  676. */
  677. public function serviceGetCartItems($iSellerId)
  678. {
  679. $CNF = &$this->_oConfig->CNF;
  680. $iSellerId = (int)$iSellerId;
  681. if(empty($iSellerId))
  682. return array();
  683. $aItems = $this->_oDb->getEntriesByAuthor($iSellerId);
  684. $aResult = array();
  685. foreach($aItems as $aItem)
  686. $aResult[] = array(
  687. 'id' => $aItem[$CNF['FIELD_ID']],
  688. 'author_id' => $aItem[$CNF['FIELD_AUTHOR']],
  689. 'name' => $aItem[$CNF['FIELD_NAME']],
  690. 'title' => $aItem[$CNF['FIELD_TITLE']],
  691. 'description' => $aItem[$CNF['FIELD_TEXT']],
  692. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=view-product&id=' . $aItem[$CNF['FIELD_ID']]),
  693. 'price_single' => $aItem[$CNF['FIELD_PRICE_SINGLE']],
  694. 'price_recurring' => $aItem[$CNF['FIELD_PRICE_RECURRING']],
  695. 'period_recurring' => 1,
  696. 'period_unit_recurring' => $aItem[$CNF['FIELD_DURATION_RECURRING']],
  697. 'trial_recurring' => $aItem[$CNF['FIELD_TRIAL_RECURRING']]
  698. );
  699. return $aResult;
  700. }
  701. /**
  702. * @page service Service Calls
  703. * @section bx_market Market
  704. * @subsection bx_market-payments Payments
  705. * @subsubsection bx_market-register_cart_item register_cart_item
  706. *
  707. * @code bx_srv('bx_market', 'register_cart_item', [...]); @endcode
  708. *
  709. * Register a processed single time payment inside the Market module. Is called with payment processing module after the payment was registered there.
  710. *
  711. * @param $iClientId client ID.
  712. * @param $iSellerId seller ID
  713. * @param $iItemId item ID.
  714. * @param $iItemCount the number of purchased items.
  715. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  716. * @param $sLicense license number genereted with payment processing module for internal usage
  717. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  718. *
  719. * @see BxMarketModule::serviceRegisterCartItem
  720. */
  721. /**
  722. * @ref bx_market-register_cart_item "register_cart_item"
  723. */
  724. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  725. {
  726. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_MARKET_LICENSE_TYPE_SINGLE);
  727. }
  728. /**
  729. * @page service Service Calls
  730. * @section bx_market Market
  731. * @subsection bx_market-payments Payments
  732. * @subsubsection bx_market-register_subscription_item register_subscription_item
  733. *
  734. * @code bx_srv('bx_market', 'register_subscription_item', [...]); @endcode
  735. *
  736. * Register a processed subscription (recurring payment) inside the Market module. Is called with payment processing module after the subscription was registered there.
  737. *
  738. * @param $iClientId client ID.
  739. * @param $iSellerId seller ID
  740. * @param $iItemId item ID.
  741. * @param $iItemCount the number of purchased items.
  742. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  743. * @param $sLicense license number genereted with payment processing module for internal usage
  744. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  745. *
  746. * @see BxMarketModule::serviceRegisterSubscriptionItem
  747. */
  748. /**
  749. * @ref bx_market-register_subscription_item "register_subscription_item"
  750. */
  751. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  752. {
  753. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_MARKET_LICENSE_TYPE_RECURRING);
  754. }
  755. /**
  756. * @page service Service Calls
  757. * @section bx_market Market
  758. * @subsection bx_market-payments Payments
  759. * @subsubsection bx_market-reregister_cart_item reregister_cart_item
  760. *
  761. * @code bx_srv('bx_market', 'reregister_cart_item', [...]); @endcode
  762. *
  763. * Reregister a single time payment inside the Market module. Is called with payment processing module after the payment was reregistered there.
  764. *
  765. * @param $iClientId client ID.
  766. * @param $iSellerId seller ID
  767. * @param $iItemIdOld old item ID.
  768. * @param $iItemIdNew new item ID.
  769. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  770. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  771. *
  772. * @see BxMarketModule::serviceReregisterCartItem
  773. */
  774. /**
  775. * @ref bx_market-reregister_cart_item "reregister_cart_item"
  776. */
  777. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  778. {
  779. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder, BX_MARKET_LICENSE_TYPE_SINGLE);
  780. }
  781. /**
  782. * @page service Service Calls
  783. * @section bx_market Market
  784. * @subsection bx_market-payments Payments
  785. * @subsubsection bx_market-reregister_subscription_item reregister_subscription_item
  786. *
  787. * @code bx_srv('bx_market', 'reregister_subscription_item', [...]); @endcode
  788. *
  789. * Reregister a subscription (recurring payment) inside the Market module. Is called with payment processing module after the subscription was reregistered there.
  790. *
  791. * @param $iClientId client ID.
  792. * @param $iSellerId seller ID
  793. * @param $iItemIdOld old item ID.
  794. * @param $iItemIdNew new item ID.
  795. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  796. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  797. *
  798. * @see BxMarketModule::serviceReregisterSubscriptionItem
  799. */
  800. /**
  801. * @ref bx_market-reregister_subscription_item "reregister_subscription_item"
  802. */
  803. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  804. {
  805. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder, BX_MARKET_LICENSE_TYPE_RECURRING);
  806. }
  807. /**
  808. * @page service Service Calls
  809. * @section bx_market Market
  810. * @subsection bx_market-payments Payments
  811. * @subsubsection bx_market-unregister_cart_item unregister_cart_item
  812. *
  813. * @code bx_srv('bx_market', 'unregister_cart_item', [...]); @endcode
  814. *
  815. * Unregister an earlier processed single time payment inside the Market module. Is called with payment processing module after the payment was unregistered there.
  816. *
  817. * @param $iClientId client ID.
  818. * @param $iSellerId seller ID
  819. * @param $iItemId item ID.
  820. * @param $iItemCount the number of purchased items.
  821. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  822. * @param $sLicense license number genereted with payment processing module for internal usage
  823. * @return boolean value determining where the payment was unregistered or not.
  824. *
  825. * @see BxMarketModule::serviceUnregisterCartItem
  826. */
  827. /**
  828. * @ref bx_market-unregister_cart_item "unregister_cart_item"
  829. */
  830. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  831. {
  832. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_MARKET_LICENSE_TYPE_SINGLE);
  833. }
  834. /**
  835. * @page service Service Calls
  836. * @section bx_market Market
  837. * @subsection bx_market-payments Payments
  838. * @subsubsection bx_market-unregister_subscription_item unregister_subscription_item
  839. *
  840. * @code bx_srv('bx_market', 'unregister_subscription_item', [...]); @endcode
  841. *
  842. * Unregister an earlier processed subscription (recurring payment) inside the Market module. Is called with payment processing module after the subscription was unregistered there.
  843. *
  844. * @param $iClientId client ID.
  845. * @param $iSellerId seller ID
  846. * @param $iItemId item ID.
  847. * @param $iItemCount the number of purchased items.
  848. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  849. * @param $sLicense license number genereted with payment processing module for internal usage
  850. * @return boolean value determining where the subscription was unregistered or not.
  851. *
  852. * @see BxMarketModule::serviceUnregisterSubscriptionItem
  853. */
  854. /**
  855. * @ref bx_market-unregister_subscription_item "unregister_subscription_item"
  856. */
  857. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  858. {
  859. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_MARKET_LICENSE_TYPE_RECURRING);
  860. }
  861. /**
  862. * @page service Service Calls
  863. * @section bx_market Market
  864. * @subsection bx_market-payments Payments
  865. * @subsubsection bx_market-cancel_subscription_item cancel_subscription_item
  866. *
  867. * @code bx_srv('bx_market', 'cancel_subscription_item', [...]); @endcode
  868. *
  869. * Cancel an earlier processed subscription (recurring payment) inside the Market module. Is called with payment processing module after the subscription was canceled there.
  870. *
  871. * @param $iClientId client ID.
  872. * @param $iSellerId seller ID
  873. * @param $iItemId item ID.
  874. * @param $iItemCount the number of purchased items.
  875. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  876. * @return boolean value determining where the subscription was canceled or not.
  877. *
  878. * @see BxMarketModule::serviceCancelSubscriptionItem
  879. */
  880. /**
  881. * @ref bx_market-cancel_subscription_item "cancel_subscription_item"
  882. */
  883. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  884. {
  885. //TODO: Do something if it's necessary.
  886. return true;
  887. }
  888. protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType)
  889. {
  890. $aItem = $this->serviceGetCartItem($iItemId);
  891. if(empty($aItem) || !is_array($aItem))
  892. return array();
  893. $iTrial = 0;
  894. $sDuration = '';
  895. $sAction = 'register';
  896. if($sType == BX_MARKET_LICENSE_TYPE_RECURRING) {
  897. $aProduct = $this->_oDb->getContentInfoById($iItemId);
  898. $iTrial = $aProduct[$this->_oConfig->CNF['FIELD_TRIAL_RECURRING']];
  899. $sDuration = $aProduct[$this->_oConfig->CNF['FIELD_DURATION_RECURRING']];
  900. if($this->_oDb->hasLicenseByOrder($iClientId, $iItemId, $sOrder))
  901. $sAction = 'prolong';
  902. }
  903. if(!$this->_oDb->{$sAction . 'License'}($iClientId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType, $sDuration, $iTrial))
  904. return array();
  905. bx_alert($this->getName(), 'license_' . $sAction, 0, false, array(
  906. 'product_id' => $iItemId,
  907. 'profile_id' => $iClientId,
  908. 'order' => $sOrder,
  909. 'license' => $sLicense,
  910. 'type' => $sType,
  911. 'count' => $iItemCount,
  912. 'duration' => $sDuration,
  913. 'trial' => $iTrial
  914. ));
  915. return $aItem;
  916. }
  917. protected function _serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder, $sType)
  918. {
  919. $aItemNew = $this->serviceGetCartItem($iItemIdNew);
  920. if(empty($aItemNew) || !is_array($aItemNew))
  921. return array();
  922. if(!$this->_oDb->hasLicenseByOrder($iClientId, $iItemIdOld, $sOrder))
  923. return array();
  924. if(!$this->_oDb->updateLicense(array('product_id' => $iItemIdNew), array('profile_id' => $iClientId, 'product_id' => $iItemIdOld, 'order' => $sOrder)))
  925. return array();
  926. bx_alert($this->getName(), 'license_reregister', 0, false, array(
  927. 'product_id_old' => $iItemIdOld,
  928. 'product_id_new' => $iItemIdNew,
  929. 'profile_id' => $iClientId,
  930. 'order' => $sOrder,
  931. 'type' => $sType
  932. ));
  933. return $aItemNew;
  934. }
  935. protected function _serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType)
  936. {
  937. if(!$this->_oDb->unregisterLicense($iClientId, $iItemId, $sOrder, $sLicense, $sType))
  938. return false;
  939. bx_alert($this->getName(), 'license_unregister', 0, false, array(
  940. 'product_id' => $iItemId,
  941. 'profile_id' => $iClientId,
  942. 'order' => $sOrder,
  943. 'license' => $sLicense,
  944. 'type' => $sType,
  945. 'count' => $iItemCount
  946. ));
  947. return true;
  948. }
  949. public function getGhostTemplateVars($aFile, $iProfileId, $iContentId, $oStorage, $oImagesTranscoder)
  950. {
  951. $CNF = &$this->_oConfig->CNF;
  952. $sMethod = '';
  953. $sStorage = $oStorage->getObject();
  954. switch($sStorage) {
  955. case $CNF['OBJECT_STORAGE']:
  956. $sMethod = 'getPhoto';
  957. break;
  958. case $CNF['OBJECT_STORAGE_FILES']:
  959. $sMethod = 'getFile';
  960. break;
  961. }
  962. $aFileInfo = $this->_oDb->$sMethod(array('type' => 'file_id', 'file_id' => $aFile['id']));
  963. $bFileInfo = !empty($aFileInfo) && is_array($aFileInfo);
  964. $bFileInfoTitle = $bFileInfo && isset($aFileInfo['title']);
  965. $aTmplVars = array(
  966. 'file_title' => $bFileInfoTitle ? $aFileInfo['title'] : '',
  967. 'file_title_attr' => $bFileInfoTitle ? bx_html_attribute($aFileInfo['title']) : '',
  968. );
  969. if($sStorage == $CNF['OBJECT_STORAGE'])
  970. return $aTmplVars;
  971. $bFileInfoVersion = $bFileInfo && isset($aFileInfo['version']);
  972. $bFileInfoTypeVersion = !$bFileInfo || ($bFileInfo && isset($aFileInfo['type']) && $aFileInfo['type'] == BX_MARKET_FILE_TYPE_VERSION);
  973. $bFileInfoTypeUpdate = $bFileInfo && isset($aFileInfo['type']) && $aFileInfo['type'] == BX_MARKET_FILE_TYPE_UPDATE;
  974. $aVersions = $this->_oDb->$sMethod(array('type' => 'content_id', 'content_id' => $iContentId));
  975. $aTmplVars = array_merge($aTmplVars, array(
  976. 'file_version' => $bFileInfoVersion ? $aFileInfo['version'] : '',
  977. 'file_version_attr' => $bFileInfoVersion ? bx_html_attribute($aFileInfo['version']) : '',
  978. 'file_type_version_selected' => $bFileInfoTypeVersion ? ' selected="selected"' : '',
  979. 'file_type_update_selected' => $bFileInfoTypeUpdate ? ' selected="selected"' : '',
  980. 'file_type_version_elements' => !$bFileInfoTypeVersion ? ' style="display:none;"' : '',
  981. 'file_type_update_elements' => !$bFileInfoTypeUpdate ? ' style="display:none;"' : '',
  982. 'file_version_from_options' => $this->_oTemplate->getGhostTemplateFileOptions('version', $aFileInfo, $aVersions),
  983. 'file_version_to_options' => $this->_oTemplate->getGhostTemplateFileOptions('version_to', $aFileInfo, $aVersions)
  984. ));
  985. return $aTmplVars;
  986. }
  987. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  988. {
  989. $CNF = &$this->_oConfig->CNF;
  990. if($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId) {
  991. $aLicenses = $this->_oDb->getLicense(array('type' => 'product_id', 'product_id' => $aDataEntry[$CNF['FIELD_ID']]));
  992. if(is_array($aLicenses) && count($aLicenses) > 0)
  993. return _t('_sys_txt_access_denied');
  994. }
  995. return parent::checkAllowedDelete($aDataEntry, $isPerformAction);
  996. }
  997. public function checkAllowedSetCover ()
  998. {
  999. $aCheck = checkActionModule($this->_iProfileId, 'set cover', $this->getName(), false);
  1000. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1001. return $aCheck[CHECK_ACTION_MESSAGE];
  1002. return CHECK_ACTION_RESULT_ALLOWED;
  1003. }
  1004. public function checkAllowedSetSubentries ()
  1005. {
  1006. $aCheck = checkActionModule($this->_iProfileId, 'set subentries', $this->getName(), false);
  1007. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1008. return $aCheck[CHECK_ACTION_MESSAGE];
  1009. return CHECK_ACTION_RESULT_ALLOWED;
  1010. }
  1011. public function checkAllowedDownload($aDataEntry, $isPerformAction = false)
  1012. {
  1013. $CNF = &$this->_oConfig->CNF;
  1014. // moderator and owner always have access
  1015. if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  1016. return CHECK_ACTION_RESULT_ALLOWED;
  1017. // check ACL
  1018. $aCheck = checkActionModule($this->_iProfileId, 'download entry', $this->getName(), $isPerformAction);
  1019. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1020. return $aCheck[CHECK_ACTION_MESSAGE];
  1021. if((float)$aDataEntry[$CNF['FIELD_PRICE_SINGLE']] == 0 && (float)$aDataEntry[$CNF['FIELD_PRICE_RECURRING']] == 0)
  1022. return CHECK_ACTION_RESULT_ALLOWED;
  1023. if(!$this->_oDb->hasLicense($this->_iProfileId, $aDataEntry[$CNF['FIELD_ID']]))
  1024. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  1025. return CHECK_ACTION_RESULT_ALLOWED;
  1026. }
  1027. public function checkAllowedHide($aDataEntry, $isPerformAction = false)
  1028. {
  1029. $CNF = &$this->_oConfig->CNF;
  1030. if($aDataEntry[$CNF['FIELD_STATUS']] != 'active')
  1031. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  1032. // moderator and owner always have access
  1033. if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  1034. return CHECK_ACTION_RESULT_ALLOWED;
  1035. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  1036. }
  1037. public function checkAllowedUnhide($aDataEntry, $isPerformAction = false)
  1038. {
  1039. $CNF = &$this->_oConfig->CNF;
  1040. if($aDataEntry[$CNF['FIELD_STATUS']] == 'active')
  1041. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  1042. // moderator and owner always have access
  1043. if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  1044. return CHECK_ACTION_RESULT_ALLOWED;
  1045. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  1046. }
  1047. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  1048. {
  1049. $CNF = &$this->_oConfig->CNF;
  1050. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  1051. $oMenu->setContentId($aDataEntry[$CNF['FIELD_ID']]);
  1052. if(!$oMenu || !$oMenu->isVisible())
  1053. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  1054. return CHECK_ACTION_RESULT_ALLOWED;
  1055. }
  1056. protected function _getBlockLicenses($sType = '')
  1057. {
  1058. $CNF = &$this->_oConfig->CNF;
  1059. $sGrid = $this->_oConfig->getGridObject('licenses' . (!empty($sType) ? '_' . $sType : ''));
  1060. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  1061. if(!$oGrid)
  1062. return '';
  1063. $this->_oDb->updateLicense(array('new' => 0), array('profile_id' => bx_get_logged_profile_id(), 'new' => 1));
  1064. $this->_oTemplate->addJs(array('licenses.js'));
  1065. return array(
  1066. 'content' => $this->_oTemplate->getJsCode('licenses', array('sObjNameGrid' => $sGrid)) . $oGrid->getCode(),
  1067. 'menu' => $CNF['OBJECT_MENU_LICENSES']
  1068. );
  1069. }
  1070. protected function _getContentInfo($iContentId = 0)
  1071. {
  1072. if(!$iContentId)
  1073. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1074. if(!$iContentId)
  1075. return false;
  1076. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1077. if(!$aContentInfo)
  1078. return false;
  1079. return $aContentInfo;
  1080. }
  1081. protected function _performHideProduct($aDataEntry) {
  1082. $CNF = &$this->_oConfig->CNF;
  1083. if(!$this->_oDb->updateContentInfoBy(array($CNF['FIELD_STATUS'] => 'hidden'), array($CNF['FIELD_ID'] => $aDataEntry[$CNF['FIELD_ID']])))
  1084. return echoJson(array());
  1085. $this->checkAllowedHide($aDataEntry, true);
  1086. return echoJson(array('reload' => 1));
  1087. }
  1088. protected function _performUnhideProduct($aDataEntry) {
  1089. $CNF = &$this->_oConfig->CNF;
  1090. if(!$this->_oDb->updateContentInfoBy(array($CNF['FIELD_STATUS'] => 'active'), array($CNF['FIELD_ID'] => $aDataEntry[$CNF['FIELD_ID']])))
  1091. return echoJson(array());
  1092. $this->checkAllowedHide($aDataEntry, true);
  1093. return echoJson(array('reload' => 1));
  1094. }
  1095. }
  1096. /** @} */