BxMarketModule.php 38 KB

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