BxMarketModule.php 48 KB

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