BxMarketModule.php 33 KB

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