BxMarketModule.php 50 KB

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