BxAdsModule.php 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  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 Ads Ads
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_ADS_OFFER_STATUS_ACCEPTED', 'accepted');
  12. define('BX_ADS_OFFER_STATUS_AWAITING', 'awaiting');
  13. define('BX_ADS_OFFER_STATUS_DECLINED', 'declined');
  14. /**
  15. * Ads module
  16. */
  17. class BxAdsModule extends BxBaseModTextModule
  18. {
  19. protected $_aOfferStatuses;
  20. function __construct(&$aModule)
  21. {
  22. parent::__construct($aModule);
  23. $this->_oConfig->init($this->_oDb);
  24. $CNF = &$this->_oConfig->CNF;
  25. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  26. $CNF['FIELD_CATEGORY_VIEW'],
  27. $CNF['FIELD_CATEGORY_SELECT']
  28. ));
  29. $this->_aOfferStatuses = array(
  30. BX_ADS_OFFER_STATUS_ACCEPTED,
  31. BX_ADS_OFFER_STATUS_AWAITING,
  32. BX_ADS_OFFER_STATUS_DECLINED
  33. );
  34. }
  35. public function actionGetCategoryForm()
  36. {
  37. if(bx_get('category') === false)
  38. return echoJson(array());
  39. return echoJson(array(
  40. 'content' => $this->serviceGetCreatePostForm(array(
  41. 'absolute_action_url' => true,
  42. 'dynamic_mode' => true
  43. ))
  44. ));
  45. }
  46. public function actionCheckName()
  47. {
  48. $CNF = &$this->_oConfig->CNF;
  49. $iId = (int)bx_get($CNF['FIELD_ID']);
  50. $sTitle = bx_process_input(bx_get($CNF['FIELD_TITLE']));
  51. echoJson($this->serviceCheckName($sTitle, $iId));
  52. }
  53. public function actionInterested()
  54. {
  55. $CNF = &$this->_oConfig->CNF;
  56. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  57. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  58. if(empty($aContentInfo) || !is_array($aContentInfo))
  59. return echoJson(array());
  60. $iViewer = bx_get_logged_profile_id();
  61. $oViewer = BxDolProfile::getInstance($iViewer);
  62. if(!$oViewer)
  63. return echoJson(array());
  64. $iContentAuthor = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  65. if($iContentAuthor == $iViewer)
  66. return echoJson(array('msg' => _t('_bx_ads_txt_err_your_own')));
  67. if($this->_oDb->isInterested($iContentId, $iViewer))
  68. return echoJson(array('msg' => _t('_bx_ads_txt_err_duplicate')));
  69. $iInterestId = $this->_oDb->insertInterested(array('entry_id' => $iContentId, 'profile_id' => $iViewer));
  70. if(!$iInterestId)
  71. return echoJson(array('msg' => _t('_bx_ads_txt_err_cannot_perform_action')));
  72. bx_alert($this->getName(), 'doInterest', $iContentId, $iViewer, array(
  73. 'subobject_id' => $iInterestId,
  74. 'subobject_author_id' => $iViewer,
  75. 'object_author_id' => $iContentAuthor
  76. ));
  77. if(getParam($CNF['PARAM_USE_IIN']) == 'on')
  78. sendMailTemplate($CNF['ETEMPLATE_INTERESTED'], 0, $iContentAuthor, array(
  79. 'viewer_name' => $oViewer->getDisplayName(),
  80. 'viewer_url' => $oViewer->getUrl(),
  81. 'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  82. 'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  83. 'i' => $CNF['URI_VIEW_ENTRY'],
  84. $CNF['FIELD_ID'] => $iContentId
  85. ))
  86. ));
  87. return echoJson(array('msg' => _t('_bx_ads_txt_msg_author_notified')));
  88. }
  89. public function actionMakeOffer()
  90. {
  91. $CNF = &$this->_oConfig->CNF;
  92. $sJsObject = $this->_oConfig->getJsObject('entry');
  93. $iAuthorId = bx_get_logged_profile_id();
  94. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  95. if(empty($iAuthorId))
  96. return echoJson(array('code' => 1, 'eval' => 'window.open("' . BxDolPermalinks::getInstance()->permalink('page.php?i=login') . '", "_self");'));
  97. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  98. if(empty($aContentInfo) || !is_array($aContentInfo))
  99. return echoJson(array());
  100. $aOffer = $this->_oDb->getOffersBy(array(
  101. 'type' => 'content_and_author_ids',
  102. 'content_id' => $iContentId,
  103. 'author_id' => $iAuthorId,
  104. 'status' => BX_ADS_OFFER_STATUS_AWAITING
  105. ));
  106. if(!empty($aOffer) && is_array($aOffer))
  107. return echoJson(array('code' => 2, 'msg' => _t('_bx_ads_txt_err_duplicate')));
  108. $aOffer = $this->_oDb->getOffersBy(array(
  109. 'type' => 'content_and_author_ids',
  110. 'content_id' => $iContentId,
  111. 'author_id' => $iAuthorId,
  112. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  113. ));
  114. if(!empty($aOffer) && is_array($aOffer))
  115. return echoJson(array('code' => 3, 'msg' => _t('_bx_ads_txt_err_offer_accepted')));
  116. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_OFFER'], $CNF['OBJECT_FORM_OFFER_DISPLAY_ADD']);
  117. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'make_offer', array('id' => $iContentId));
  118. $oForm->initChecker();
  119. if($oForm->isSubmittedAndValid()) {
  120. $aValToAdd = array('content_id' => $iContentId, 'author_id' => $iAuthorId);
  121. $iId = (int)$oForm->insert($aValToAdd);
  122. if($iId != 0)
  123. $aResult = array('code' => 0, 'msg' => _t('_bx_ads_txt_msg_offer_added'), 'eval' => $sJsObject . '.onMakeOffer(oData);', 'id' => $iId);
  124. else
  125. $aResult = array('code' => 4, 'msg' => _t('_bx_ads_txt_err_cannot_perform_action'));
  126. $this->onOfferAdded($iId);
  127. return echoJson($aResult);
  128. }
  129. $sContent = BxTemplFunctions::getInstance()->transBox($this->_oConfig->getHtmlIds('offer_popup'), $this->_oTemplate->parseHtmlByName('offer_popup.html', array(
  130. 'form_id' => $oForm->getId(),
  131. 'form' => $oForm->getCode(true)
  132. )));
  133. return echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false, 'removeOnClose' => true))));
  134. }
  135. public function actionDelivered()
  136. {
  137. return echoJson($this->_actionMarkAs('delivered'));
  138. }
  139. public function actionReceived()
  140. {
  141. return echoJson($this->_actionMarkAs('received'));
  142. }
  143. public function serviceGetSafeServices()
  144. {
  145. $a = parent::serviceGetSafeServices();
  146. return array_merge($a, array (
  147. 'EntityReviews' => '',
  148. 'EntityReviewsRating' => '',
  149. 'CategoriesList' => '',
  150. 'BrowseCategory' => '',
  151. ));
  152. }
  153. public function serviceCheckName($sTitle, $iId = 0)
  154. {
  155. $CNF = &$this->_oConfig->CNF;
  156. if(empty($sTitle))
  157. return array();
  158. $sName = '';
  159. if(!empty($iId)) {
  160. $aEntry = $this->_oDb->getContentInfoById($iId);
  161. if(strcmp($sTitle, $aEntry[$CNF['FIELD_NAME']]) == 0)
  162. $sName = $sTitle;
  163. }
  164. return array(
  165. 'title' => $sTitle,
  166. 'name' => !empty($sName) ? $sName : $this->_oConfig->getEntryName($sTitle, $iId)
  167. );
  168. }
  169. public function serviceUpdateCategoriesStats()
  170. {
  171. $aStats = $this->_oDb->getCategories(array('type' => 'collect_stats'));
  172. if(empty($aStats) || !is_array($aStats))
  173. return true;
  174. $iUpdated = 0;
  175. foreach($aStats as $aStat)
  176. if($this->_oDb->updateCategory(array('items' => $aStat['count']), array('id' => $aStat['id'])))
  177. $iUpdated++;
  178. return count($aStats) == $iUpdated;
  179. }
  180. public function serviceGetCategoryOptions($iParentId, $bPleaseSelect = false)
  181. {
  182. $aValues = array();
  183. if($bPleaseSelect)
  184. $aValues[] = array('key' => '', 'value' => _t('_sys_please_select'));
  185. $this->_getCategoryOptions($iParentId, $aValues);
  186. return $aValues;
  187. }
  188. public function serviceGetSearchableFields($aInputsAdd = array())
  189. {
  190. $CNF = &$this->_oConfig->CNF;
  191. $aResult = parent::serviceGetSearchableFields(array_merge($aInputsAdd, $this->_getSearchableFields()));
  192. unset($aResult[$CNF['FIELD_NOTES_PURCHASED']]);
  193. unset($aResult[$CNF['FIELD_CATEGORY_VIEW']], $aResult[$CNF['FIELD_CATEGORY_SELECT']]);
  194. unset($aResult[$CNF['FIELD_PRICE']], $aResult[$CNF['FIELD_YEAR']]);
  195. return $aResult;
  196. }
  197. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  198. {
  199. $CNF = &$this->_oConfig->CNF;
  200. $aInputsAdd = array_merge($aInputsAdd, $this->_getSearchableFields());
  201. if(isset($aInputsAdd[$CNF['FIELD_CATEGORY']])) {
  202. $aInputsAdd[$CNF['FIELD_CATEGORY']]['type'] = 'select';
  203. $aInputsAdd[$CNF['FIELD_CATEGORY']]['values_src'] = BxDolService::getSerializedService($this->_oConfig->getName(), 'get_category_options', array(0));
  204. }
  205. if(isset($aInputsAdd[$CNF['FIELD_PRICE']])) {
  206. $aInputsAdd[$CNF['FIELD_PRICE']]['search_type'] = 'text_range';
  207. $aInputsAdd[$CNF['FIELD_PRICE']]['search_operator'] = 'between';
  208. }
  209. if(isset($aInputsAdd[$CNF['FIELD_YEAR']])) {
  210. $aInputsAdd[$CNF['FIELD_YEAR']]['search_type'] = 'text_range';
  211. $aInputsAdd[$CNF['FIELD_YEAR']]['search_operator'] = 'between';
  212. }
  213. return parent::serviceGetSearchableFieldsExtended($aInputsAdd);
  214. }
  215. public function serviceEntityCreate ($sParams = false)
  216. {
  217. if(($sDisplay = $this->getCategoryDisplay('add')) !== false) {
  218. if(empty($sParams) || !is_array($sParams))
  219. $sParams = array();
  220. $sParams['display'] = $sDisplay;
  221. }
  222. return parent::serviceEntityCreate($sParams);
  223. }
  224. /**
  225. * @page service Service Calls
  226. * @section bx_ads Ads
  227. * @subsection bx_ads-page_blocks Page Blocks
  228. * @subsubsection bx_ads-entity_reviews entity_reviews
  229. *
  230. * @code bx_srv('bx_ads', 'entity_reviews', [...]); @endcode
  231. *
  232. * Get reviews for particular content
  233. * @param $iContentId content ID
  234. *
  235. * @see BxAdsModule::serviceEntityReviews
  236. */
  237. /**
  238. * @ref bx_ads-entity_reviews "entity_reviews"
  239. */
  240. public function serviceEntityReviews($iContentId = 0)
  241. {
  242. $CNF = &$this->_oConfig->CNF;
  243. if(empty($CNF['OBJECT_REVIEWS']))
  244. return false;
  245. return $this->_entityComments($CNF['OBJECT_REVIEWS'], $iContentId);
  246. }
  247. /**
  248. * @page service Service Calls
  249. * @section bx_ads Ads
  250. * @subsection bx_ads-page_blocks Page Blocks
  251. * @subsubsection bx_ads-entity_reviews_rating entity_reviews_rating
  252. *
  253. * @code bx_srv('bx_ads', 'entity_reviews_rating', [...]); @endcode
  254. *
  255. * Get reviews rating for particular content
  256. * @param $iContentId content ID
  257. *
  258. * @see BxAdsModule::serviceEntityReviewsRating
  259. */
  260. /**
  261. * @ref bx_ads-entity_reviews_rating "entity_reviews_rating"
  262. */
  263. public function serviceEntityReviewsRating($iContentId = 0)
  264. {
  265. $CNF = &$this->_oConfig->CNF;
  266. if(empty($CNF['OBJECT_REVIEWS']))
  267. return false;
  268. if(!$iContentId)
  269. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  270. if(!$iContentId)
  271. return false;
  272. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_REVIEWS'], $iContentId);
  273. if (!$oCmts || !$oCmts->isEnabled())
  274. return false;
  275. return $oCmts->getRatingBlock(array('in_designbox' => false));
  276. }
  277. /**
  278. * @page service Service Calls
  279. * @section bx_ads Ads
  280. * @subsection bx_ads-page_blocks Page Blocks
  281. * @subsubsection bx_ads-categories_list categories_list
  282. *
  283. * @code bx_srv('bx_ads', 'categories_list', [...]); @endcode
  284. *
  285. * Get reviews rating for particular content
  286. * @param $aParams additional params array, such as 'show_empty'
  287. *
  288. * @see BxAdsModule::serviceCategoriesList
  289. */
  290. /**
  291. * @ref bx_ads-categories_list "categories_list"
  292. */
  293. public function serviceCategoriesList($aParams = array())
  294. {
  295. if(!isset($aParams['show_empty']))
  296. $aParams['show_empty'] = true;
  297. return $this->_oTemplate->categoriesList($aParams);
  298. }
  299. /**
  300. * @page service Service Calls
  301. * @section bx_ads Ads
  302. * @subsection bx_ads-browse Browse
  303. * @subsubsection bx_ads-browse_category browse_category
  304. *
  305. * @code bx_srv('bx_ads', 'browse_category', [...]); @endcode
  306. *
  307. * Get reviews rating for particular content
  308. * @param $iCategoryId category ID
  309. * @param $aParams additional params array, such as empty_message, ajax_paginate, etc
  310. *
  311. * @see BxAdsModule::serviceBrowseCategory
  312. */
  313. /**
  314. * @ref bx_ads-browse_category "browse_category"
  315. */
  316. public function serviceBrowseCategory($iCategoryId = 0, $aParams = array())
  317. {
  318. $sParamName = $sParamGet = 'category';
  319. if(!$iCategoryId && bx_get($sParamGet) !== false)
  320. $iCategoryId = bx_process_input(bx_get($sParamGet), BX_DATA_INT);
  321. $bEmptyMessage = true;
  322. if(isset($aParams['empty_message'])) {
  323. $bEmptyMessage = (bool)$aParams['empty_message'];
  324. unset($aParams['empty_message']);
  325. }
  326. $bAjaxPaginate = true;
  327. if(isset($aParams['ajax_paginate'])) {
  328. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  329. unset($aParams['ajax_paginate']);
  330. }
  331. $aBlock = $this->_serviceBrowse ($sParamName, array_merge(array($sParamName => $iCategoryId), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  332. if(!empty($aBlock['content'])) {
  333. $aCategory = $this->_oDb->getCategories(array('type' => 'id', 'id' => $iCategoryId));
  334. if(!empty($aCategory['title']))
  335. $aBlock['title'] = _t('_bx_ads_page_block_title_entries_by_category_mask', _t($aCategory['title']));
  336. }
  337. return $aBlock;
  338. }
  339. public function serviceGetNotificationsData()
  340. {
  341. $sModule = $this->_aModule['name'];
  342. $sEventPrivacy = $sModule . '_allow_view_event_to';
  343. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  344. $sEventPrivacy = '';
  345. $aResult = parent::serviceGetNotificationsData();
  346. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  347. array('group' => $sModule . '_interest', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doInterest', 'module_name' => $sModule, 'module_method' => 'get_notifications_interest', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy)
  348. ));
  349. $aResult['settings'] = array_merge($aResult['settings'], array(
  350. array('group' => 'interest', 'unit' => $sModule, 'action' => 'doInterest', 'types' => array('personal'))
  351. ));
  352. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  353. array('unit' => $sModule, 'action' => 'doInterest')
  354. ));
  355. return $aResult;
  356. }
  357. public function serviceGetNotificationsInterest($aEvent)
  358. {
  359. $CNF = &$this->_oConfig->CNF;
  360. $iContentId = (int)$aEvent['object_id'];
  361. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  362. if(empty($aContentInfo) || !is_array($aContentInfo))
  363. return array();
  364. $iInterestedId = (int)$aEvent['subobject_id'];
  365. $aInterestedInfo = $this->_oDb->getInterested(array('type' => 'id', 'id' => $iInterestedId));
  366. if(empty($aInterestedInfo) || !is_array($aInterestedInfo))
  367. return array();
  368. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  369. return array(
  370. 'entry_sample' => $CNF['T']['txt_sample_single'],
  371. 'entry_url' => $sEntryUrl,
  372. 'entry_caption' => $aContentInfo[$CNF['FIELD_TITLE']],
  373. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  374. 'subentry_sample' => $CNF['T']['txt_sample_interest_single'],
  375. 'subentry_url' => '',
  376. 'lang_key' => '_bx_ads_txt_ntfs_subobject_interested', //may be empty or not specified. In this case the default one from Notification module will be used.
  377. );
  378. }
  379. /**
  380. * @page service Service Calls
  381. * @section bx_ads Ads
  382. * @subsection bx_ads-page_blocks Page Blocks
  383. * @subsubsection bx_ads-block_licenses block_licenses
  384. *
  385. * @code bx_srv('bx_ads', 'block_licenses', [...]); @endcode
  386. *
  387. * Get page block with a list of licenses purchased by currently logged member.
  388. *
  389. * @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.
  390. *
  391. * @see BxAdsModule::serviceBlockLicenses
  392. */
  393. /**
  394. * @ref bx_ads-block_licenses "block_licenses"
  395. */
  396. public function serviceBlockLicenses()
  397. {
  398. return $this->_getBlockLicenses();
  399. }
  400. /**
  401. * @page service Service Calls
  402. * @section bx_ads Ads
  403. * @subsection bx_ads-page_blocks Page Blocks
  404. * @subsubsection bx_ads-block_licenses_administration block_licenses_administration
  405. *
  406. * @code bx_srv('bx_ads', 'block_licenses_administration', [...]); @endcode
  407. *
  408. * Get page block with a list of all licenses. It's needed for moderators/administrators.
  409. *
  410. * @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.
  411. *
  412. * @see BxAdsModule::serviceBlockLicensesAdministration
  413. */
  414. /**
  415. * @ref bx_ads-block_licenses "block_licenses"
  416. */
  417. public function serviceBlockLicensesAdministration()
  418. {
  419. return $this->_getBlockLicenses('administration');
  420. }
  421. /**
  422. * @page service Service Calls
  423. * @section bx_ads Ads
  424. * @subsection bx_ads-page_blocks Page Blocks
  425. * @subsubsection bx_ads-block_licenses_note block_licenses_note
  426. *
  427. * @code bx_srv('bx_ads', 'block_licenses_note', [...]); @endcode
  428. *
  429. * Get page block with a notice for licenses usage.
  430. *
  431. * @return HTML string with block content to display on the site.
  432. *
  433. * @see BxAdsModule::serviceBlockLicensesNote
  434. */
  435. /**
  436. * @ref bx_ads-block_licenses_note "block_licenses_note"
  437. */
  438. public function serviceBlockLicensesNote()
  439. {
  440. return MsgBox(_t('_bx_ads_page_block_content_licenses_note'));
  441. }
  442. /**
  443. * @page service Service Calls
  444. * @section bx_ads Ads
  445. * @subsection bx_ads-payments Payments
  446. * @subsubsection bx_ads-get_payment_data get_payment_data
  447. *
  448. * @code bx_srv('bx_ads', 'get_payment_data', [...]); @endcode
  449. *
  450. * Get an array with module's description. Is needed for payments processing module.
  451. *
  452. * @return an array with module's description.
  453. *
  454. * @see BxAdsModule::serviceGetPaymentData
  455. */
  456. /**
  457. * @ref bx_ads-get_payment_data "get_payment_data"
  458. */
  459. public function serviceGetPaymentData()
  460. {
  461. $CNF = &$this->_oConfig->CNF;
  462. $oPermalink = BxDolPermalinks::getInstance();
  463. $aResult = $this->_aModule;
  464. $aResult['url_browse_order_common'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_LICENSES_COMMON'], array('filter' => '{order}'));
  465. $aResult['url_browse_order_administration'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_LICENSES_ADMINISTRATION'], array('filter' => '{order}'));
  466. return $aResult;
  467. }
  468. /**
  469. * @page service Service Calls
  470. * @section bx_ads Ads
  471. * @subsection bx_ads-payments Payments
  472. * @subsubsection bx_ads-get_cart_item get_cart_item
  473. *
  474. * @code bx_srv('bx_ads', 'get_cart_item', [...]); @endcode
  475. *
  476. * Get an array with prodict's description. Is used in Shopping Cart in payments processing module.
  477. *
  478. * @param $mixedItemId product's ID or Unique Name.
  479. * @return an array with prodict's description. Empty array is returned if something is wrong.
  480. *
  481. * @see BxAdsModule::serviceGetCartItem
  482. */
  483. /**
  484. * @ref bx_ads-get_cart_item "get_cart_item"
  485. */
  486. public function serviceGetCartItem($mixedItemId)
  487. {
  488. $CNF = &$this->_oConfig->CNF;
  489. if(!$mixedItemId)
  490. return array();
  491. if(is_numeric($mixedItemId))
  492. $aItem = $this->_oDb->getContentInfoById((int)$mixedItemId);
  493. else
  494. $aItem = $this->_oDb->getContentInfoByName($mixedItemId);
  495. if(empty($aItem) || !is_array($aItem))
  496. return array();
  497. $iItemId = (int)$aItem[$CNF['FIELD_ID']];
  498. $fItemPrice = (float)$aItem[$CNF['FIELD_PRICE']];
  499. if($this->isAuction($aItem)) {
  500. $iUserId = bx_get_logged_profile_id();
  501. $aOffer = $this->_oDb->getOffersBy(array(
  502. 'type' => 'content_and_author_ids',
  503. 'content_id' => $iItemId,
  504. 'author_id' => $iUserId,
  505. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  506. ));
  507. if(!empty($aOffer) && is_array($aOffer))
  508. $fItemPrice = (float)$aOffer[$CNF['FIELD_OFR_AMOUNT']];
  509. }
  510. return array (
  511. 'id' => $iItemId,
  512. 'author_id' => $aItem[$CNF['FIELD_AUTHOR']],
  513. 'name' => $aItem[$CNF['FIELD_NAME']],
  514. 'title' => $aItem[$CNF['FIELD_TITLE']],
  515. 'description' => $aItem[$CNF['FIELD_TEXT']],
  516. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aItem[$CNF['FIELD_ID']])),
  517. 'price_single' => $fItemPrice,
  518. 'price_recurring' => '',
  519. 'period_recurring' => 0,
  520. 'period_unit_recurring' => '',
  521. 'trial_recurring' => ''
  522. );
  523. }
  524. /**
  525. * @page service Service Calls
  526. * @section bx_ads Ads
  527. * @subsection bx_ads-payments Payments
  528. * @subsubsection bx_ads-get_cart_items get_cart_items
  529. *
  530. * @code bx_srv('bx_ads', 'get_cart_items', [...]); @endcode
  531. *
  532. * Get an array with prodicts' descriptions by seller. Is used in Manual Order Processing in payments processing module.
  533. *
  534. * @param $iSellerId seller ID.
  535. * @return an array with prodicts' descriptions. Empty array is returned if something is wrong or seller doesn't have any products.
  536. *
  537. * @see BxAdsModule::serviceGetCartItems
  538. */
  539. /**
  540. * @ref bx_ads-get_cart_items "get_cart_items"
  541. */
  542. public function serviceGetCartItems($iSellerId)
  543. {
  544. $CNF = &$this->_oConfig->CNF;
  545. $iSellerId = (int)$iSellerId;
  546. if(empty($iSellerId))
  547. return array();
  548. $aItems = $this->_oDb->getEntriesByAuthor($iSellerId);
  549. $aResult = array();
  550. foreach($aItems as $aItem)
  551. $aResult[] = array(
  552. 'id' => $aItem[$CNF['FIELD_ID']],
  553. 'author_id' => $aItem[$CNF['FIELD_AUTHOR']],
  554. 'name' => $aItem[$CNF['FIELD_NAME']],
  555. 'title' => $aItem[$CNF['FIELD_TITLE']],
  556. 'description' => $aItem[$CNF['FIELD_TEXT']],
  557. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aItem[$CNF['FIELD_ID']])),
  558. 'price_single' => $aItem[$CNF['FIELD_PRICE_SINGLE']],
  559. 'price_recurring' => '',
  560. 'period_recurring' => 0,
  561. 'period_unit_recurring' => '',
  562. 'trial_recurring' => ''
  563. );
  564. return $aResult;
  565. }
  566. /**
  567. * @page service Service Calls
  568. * @section bx_ads Ads
  569. * @subsection bx_ads-payments Payments
  570. * @subsubsection bx_ads-register_cart_item register_cart_item
  571. *
  572. * @code bx_srv('bx_ads', 'register_cart_item', [...]); @endcode
  573. *
  574. * Register a processed single time payment inside the Ads module. Is called with payment processing module after the payment was registered there.
  575. *
  576. * @param $iClientId client ID.
  577. * @param $iSellerId seller ID
  578. * @param $iItemId item ID.
  579. * @param $iItemCount the number of purchased items.
  580. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  581. * @param $sLicense license number genereted with payment processing module for internal usage
  582. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  583. *
  584. * @see BxAdsModule::serviceRegisterCartItem
  585. */
  586. /**
  587. * @ref bx_ads-register_cart_item "register_cart_item"
  588. */
  589. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  590. {
  591. $CNF = &$this->_oConfig->CNF;
  592. $aItem = $this->serviceGetCartItem($iItemId);
  593. if(empty($aItem) || !is_array($aItem))
  594. return array();
  595. $aEntry = $this->_oDb->getContentInfoById($iItemId);
  596. if(empty($aEntry) || !is_array($aEntry) || (int)$aEntry[$CNF['FIELD_QUANTITY']] <= 0)
  597. return array();
  598. if(!$this->_oDb->registerLicense($iClientId, $iItemId, $iItemCount, $sOrder, $sLicense))
  599. return array();
  600. $this->_oDb->updateEntriesBy(array($CNF['FIELD_QUANTITY'] => (int)$aEntry[$CNF['FIELD_QUANTITY']] - $iItemCount), array($CNF['FIELD_ID'] => $iItemId));
  601. bx_alert($this->getName(), 'license_register', 0, false, array(
  602. 'product_id' => $iItemId,
  603. 'profile_id' => $iClientId,
  604. 'order' => $sOrder,
  605. 'license' => $sLicense,
  606. 'count' => $iItemCount
  607. ));
  608. $oClient = BxDolProfile::getInstanceMagic($iClientId);
  609. $oSeller = BxDolProfile::getInstanceMagic($iSellerId);
  610. $sSellerUrl = $oSeller->getUrl();
  611. $sSellerName = $oSeller->getDisplayName();
  612. $sNote = $aEntry[$CNF['FIELD_NOTES_PURCHASED']];
  613. if(empty($sNote))
  614. $sNote = _t('_bx_ads_txt_purchased_note', $sSellerUrl, $sSellerName);
  615. sendMailTemplate($CNF['ETEMPLATE_PURCHASED'], 0, $iClientId, array(
  616. 'client_name' => $oClient->getDisplayName(),
  617. 'entry_name' => $aEntry[$CNF['FIELD_TITLE']],
  618. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'], array('id' => $aEntry[$CNF['FIELD_ID']])),
  619. 'vendor_url' => $sSellerUrl,
  620. 'vendor_name' => $sSellerName,
  621. 'count' => (int)$iItemCount,
  622. 'license' => $sLicense,
  623. 'notes' => $sNote,
  624. ));
  625. return $aItem;
  626. }
  627. /**
  628. * @page service Service Calls
  629. * @section bx_ads Ads
  630. * @subsection bx_ads-payments Payments
  631. * @subsubsection bx_ads-register_subscription_item register_subscription_item
  632. *
  633. * @code bx_srv('bx_ads', 'register_subscription_item', [...]); @endcode
  634. *
  635. * Register a processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was registered there.
  636. *
  637. * @param $iClientId client ID.
  638. * @param $iSellerId seller ID
  639. * @param $iItemId item ID.
  640. * @param $iItemCount the number of purchased items.
  641. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  642. * @param $sLicense license number genereted with payment processing module for internal usage
  643. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  644. *
  645. * @see BxAdsModule::serviceRegisterSubscriptionItem
  646. */
  647. /**
  648. * @ref bx_ads-register_subscription_item "register_subscription_item"
  649. */
  650. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  651. {
  652. return array();
  653. }
  654. /**
  655. * @page service Service Calls
  656. * @section bx_ads Ads
  657. * @subsection bx_ads-payments Payments
  658. * @subsubsection bx_ads-reregister_cart_item reregister_cart_item
  659. *
  660. * @code bx_srv('bx_ads', 'reregister_cart_item', [...]); @endcode
  661. *
  662. * Reregister a single time payment inside the Ads module. Is called with payment processing module after the payment was reregistered there.
  663. *
  664. * @param $iClientId client ID.
  665. * @param $iSellerId seller ID
  666. * @param $iItemIdOld old item ID.
  667. * @param $iItemIdNew new item ID.
  668. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  669. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  670. *
  671. * @see BxAdsModule::serviceReregisterCartItem
  672. */
  673. /**
  674. * @ref bx_ads-reregister_cart_item "reregister_cart_item"
  675. */
  676. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  677. {
  678. return array();
  679. }
  680. /**
  681. * @page service Service Calls
  682. * @section bx_ads Ads
  683. * @subsection bx_ads-payments Payments
  684. * @subsubsection bx_ads-reregister_subscription_item reregister_subscription_item
  685. *
  686. * @code bx_srv('bx_ads', 'reregister_subscription_item', [...]); @endcode
  687. *
  688. * Reregister a subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was reregistered there.
  689. *
  690. * @param $iClientId client ID.
  691. * @param $iSellerId seller ID
  692. * @param $iItemIdOld old item ID.
  693. * @param $iItemIdNew new item ID.
  694. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  695. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  696. *
  697. * @see BxAdsModule::serviceReregisterSubscriptionItem
  698. */
  699. /**
  700. * @ref bx_ads-reregister_subscription_item "reregister_subscription_item"
  701. */
  702. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  703. {
  704. return array();
  705. }
  706. /**
  707. * @page service Service Calls
  708. * @section bx_ads Ads
  709. * @subsection bx_ads-payments Payments
  710. * @subsubsection bx_ads-unregister_cart_item unregister_cart_item
  711. *
  712. * @code bx_srv('bx_ads', 'unregister_cart_item', [...]); @endcode
  713. *
  714. * Unregister an earlier processed single time payment inside the Ads module. Is called with payment processing module after the payment was unregistered there.
  715. *
  716. * @param $iClientId client ID.
  717. * @param $iSellerId seller ID
  718. * @param $iItemId item ID.
  719. * @param $iItemCount the number of purchased items.
  720. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  721. * @param $sLicense license number genereted with payment processing module for internal usage
  722. * @return boolean value determining where the payment was unregistered or not.
  723. *
  724. * @see BxAdsModule::serviceUnregisterCartItem
  725. */
  726. /**
  727. * @ref bx_ads-unregister_cart_item "unregister_cart_item"
  728. */
  729. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  730. {
  731. if(!$this->_oDb->unregisterLicense($iClientId, $iItemId, $sOrder, $sLicense))
  732. return false;
  733. bx_alert($this->getName(), 'license_unregister', 0, false, array(
  734. 'product_id' => $iItemId,
  735. 'profile_id' => $iClientId,
  736. 'order' => $sOrder,
  737. 'license' => $sLicense,
  738. 'count' => $iItemCount
  739. ));
  740. return true;;
  741. }
  742. /**
  743. * @page service Service Calls
  744. * @section bx_ads Ads
  745. * @subsection bx_ads-payments Payments
  746. * @subsubsection bx_ads-unregister_subscription_item unregister_subscription_item
  747. *
  748. * @code bx_srv('bx_ads', 'unregister_subscription_item', [...]); @endcode
  749. *
  750. * Unregister an earlier processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was unregistered there.
  751. *
  752. * @param $iClientId client ID.
  753. * @param $iSellerId seller ID
  754. * @param $iItemId item ID.
  755. * @param $iItemCount the number of purchased items.
  756. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  757. * @param $sLicense license number genereted with payment processing module for internal usage
  758. * @return boolean value determining where the subscription was unregistered or not.
  759. *
  760. * @see BxAdsModule::serviceUnregisterSubscriptionItem
  761. */
  762. /**
  763. * @ref bx_ads-unregister_subscription_item "unregister_subscription_item"
  764. */
  765. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  766. {
  767. return true;
  768. }
  769. /**
  770. * @page service Service Calls
  771. * @section bx_ads Ads
  772. * @subsection bx_ads-payments Payments
  773. * @subsubsection bx_ads-cancel_subscription_item cancel_subscription_item
  774. *
  775. * @code bx_srv('bx_ads', 'cancel_subscription_item', [...]); @endcode
  776. *
  777. * Cancel an earlier processed subscription (recurring payment) inside the Ads module. Is called with payment processing module after the subscription was canceled there.
  778. *
  779. * @param $iClientId client ID.
  780. * @param $iSellerId seller ID
  781. * @param $iItemId item ID.
  782. * @param $iItemCount the number of purchased items.
  783. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  784. * @return boolean value determining where the subscription was canceled or not.
  785. *
  786. * @see BxAdsModule::serviceCancelSubscriptionItem
  787. */
  788. /**
  789. * @ref bx_ads-cancel_subscription_item "cancel_subscription_item"
  790. */
  791. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  792. {
  793. return true;
  794. }
  795. public function serviceGetOffersCount($sStatus = '')
  796. {
  797. if(!$this->_oConfig->isAuction())
  798. return 0;
  799. if(empty($sStatus) || !in_array($sStatus, $this->_aOfferStatuses))
  800. $sStatus = BX_ADS_OFFER_STATUS_AWAITING;
  801. $iUserId = bx_get_logged_profile_id();
  802. return $this->_oDb->getOffersBy(array('type' => 'content_author_id', 'author_id' => $iUserId, 'status' => $sStatus, 'count' => true));
  803. }
  804. public function serviceGetLiveUpdates($sStatus, $aMenuItemParent, $aMenuItemChild, $iCount = 0)
  805. {
  806. if(!in_array($sStatus, $this->_aOfferStatuses))
  807. return false;
  808. $iUserId = bx_get_logged_profile_id();
  809. $iCountNew = $this->_oDb->getOffersBy(array('type' => 'content_author_id', 'author_id' => $iUserId, 'status' => $sStatus, 'count' => true));
  810. if($iCountNew == $iCount)
  811. return false;
  812. return array(
  813. 'count' => $iCountNew, // required
  814. 'method' => 'bx_menu_show_live_update(oData)', // required
  815. 'data' => array(
  816. 'code' => BxDolTemplate::getInstance()->parseHtmlByTemplateName('menu_item_addon', array(
  817. 'content' => '{count}'
  818. )),
  819. 'mi_parent' => $aMenuItemParent,
  820. 'mi_child' => $aMenuItemChild
  821. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  822. );
  823. }
  824. public function serviceOffers()
  825. {
  826. $CNF = &$this->_oConfig->CNF;
  827. if(!$this->_oConfig->isAuction())
  828. return '';
  829. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_OFFERS_ALL']);
  830. if(!$oGrid)
  831. return '';
  832. return $oGrid->getCode();
  833. }
  834. public function serviceEntityOffers($iContentId = 0)
  835. {
  836. $CNF = &$this->_oConfig->CNF;
  837. if(!$this->_oConfig->isAuction())
  838. return '';
  839. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_OFFERS']);
  840. if(!$oGrid)
  841. return '';
  842. if(empty($iContentId) && ($_iContentId = bx_get('id')) !== false)
  843. $iContentId = (int)$_iContentId;
  844. $oGrid->setContentId($iContentId);
  845. return $oGrid->getCode();
  846. }
  847. public function serviceEntityOfferAccepted($iContentId = 0)
  848. {
  849. $CNF = &$this->_oConfig->CNF;
  850. if(!$this->_oConfig->isAuction())
  851. return '';
  852. $iUserId = bx_get_logged_profile_id();
  853. if(empty($iContentId) && ($_iContentId = bx_get('id')) !== false)
  854. $iContentId = (int)$_iContentId;
  855. $aContent = $this->_oDb->getContentInfoById($iContentId);
  856. if(empty($aContent) || !is_array($aContent) || $aContent[$CNF['FIELD_QUANTITY']] <= 0)
  857. return '';
  858. $aOffer = $this->_oDb->getOffersBy(array(
  859. 'type' => 'content_and_author_ids',
  860. 'content_id' => $iContentId,
  861. 'author_id' => $iUserId,
  862. 'status' => BX_ADS_OFFER_STATUS_ACCEPTED
  863. ));
  864. if(empty($aOffer) || !is_array($aOffer))
  865. return '';
  866. return $this->_oTemplate->entryOfferAccepted($iUserId, $aContent, $aOffer);
  867. }
  868. public function isAuction($aContentInfo)
  869. {
  870. $CNF = &$this->_oConfig->CNF;
  871. return $this->_oConfig->isAuction() && (int)$aContentInfo[$CNF['FIELD_AUCTION']] != 0;
  872. }
  873. public function isAllowedMakeOffer($mixedContent, $isPerformAction = false)
  874. {
  875. return $this->checkAllowedMakeOffer($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  876. }
  877. public function checkAllowedMakeOffer($mixedContent, $isPerformAction = false)
  878. {
  879. $CNF = &$this->_oConfig->CNF;
  880. $sTxtError = '_sys_txt_access_denied';
  881. if(!is_array($mixedContent))
  882. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  883. if(empty($mixedContent) || !is_array($mixedContent))
  884. return _t($sTxtError);
  885. if(!$this->isAuction($mixedContent) || (int)$mixedContent[$CNF['FIELD_QUANTITY']] <= 0)
  886. return _t($sTxtError);
  887. if($mixedContent[$CNF['FIELD_AUTHOR']] != bx_get_logged_profile_id())
  888. return CHECK_ACTION_RESULT_ALLOWED;
  889. return _t($sTxtError);
  890. }
  891. public function isAllowedViewOffers($mixedContent, $isPerformAction = false)
  892. {
  893. return $this->checkAllowedViewOffers($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  894. }
  895. public function checkAllowedViewOffers($mixedContent, $isPerformAction = false)
  896. {
  897. $CNF = &$this->_oConfig->CNF;
  898. $sTxtError = '_sys_txt_access_denied';
  899. if(!is_array($mixedContent))
  900. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  901. if(empty($mixedContent) || !is_array($mixedContent))
  902. return _t($sTxtError);
  903. if(!$this->isAuction($mixedContent))
  904. return _t($sTxtError);
  905. if($this->_isModerator())
  906. return CHECK_ACTION_RESULT_ALLOWED;
  907. if($mixedContent[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id())
  908. return CHECK_ACTION_RESULT_ALLOWED;
  909. return _t($sTxtError);
  910. }
  911. public function isAllowedMarkDelivered($mixedContent, $isPerformAction = false)
  912. {
  913. return $this->checkAllowedMarkDelivered($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  914. }
  915. public function checkAllowedMarkDelivered($mixedContent, $isPerformAction = false)
  916. {
  917. $CNF = &$this->_oConfig->CNF;
  918. $sTxtError = '_sys_txt_access_denied';
  919. if(!is_array($mixedContent))
  920. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  921. if(empty($mixedContent) || !is_array($mixedContent))
  922. return _t($sTxtError);
  923. if((int)$mixedContent[$CNF['FIELD_DELIVERED']] != 0 || $mixedContent[$CNF['FIELD_AUTHOR']] != bx_get_logged_profile_id())
  924. return _t($sTxtError);
  925. return CHECK_ACTION_RESULT_ALLOWED;
  926. }
  927. public function isAllowedMarkReceived($mixedContent, $isPerformAction = false)
  928. {
  929. return $this->checkAllowedMarkReceived($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  930. }
  931. public function checkAllowedMarkReceived($mixedContent, $isPerformAction = false)
  932. {
  933. $CNF = &$this->_oConfig->CNF;
  934. $sTxtError = '_sys_txt_access_denied';
  935. if(!is_array($mixedContent))
  936. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  937. if(empty($mixedContent) || !is_array($mixedContent))
  938. return _t($sTxtError);
  939. if((int)$mixedContent[$CNF['FIELD_RECEIVED']] != 0 || !$this->_oDb->hasLicense(bx_get_logged_profile_id(), $mixedContent[$CNF['FIELD_ID']]))
  940. return _t($sTxtError);
  941. return CHECK_ACTION_RESULT_ALLOWED;
  942. }
  943. public function onOfferAdded($iOfferId)
  944. {
  945. $CNF = &$this->_oConfig->CNF;
  946. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  947. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  948. return;
  949. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  950. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  951. if(empty($aContentInfo) || !is_array($aContentInfo))
  952. return;
  953. $iViewer = bx_get_logged_profile_id();
  954. $oViewer = BxDolProfile::getInstanceMagic($iViewer);
  955. sendMailTemplate($CNF['ETEMPLATE_OFFER_ADDED'], 0, $aContentInfo[$CNF['FIELD_AUTHOR']], array(
  956. 'viewer_name' => $oViewer->getDisplayName(),
  957. 'viewer_url' => $oViewer->getUrl(),
  958. 'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  959. 'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  960. 'i' => $CNF['URI_VIEW_ENTRY'],
  961. $CNF['FIELD_ID'] => $iContentId
  962. ))
  963. ));
  964. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  965. bx_alert($this->getName(), 'offer_added', $iOfferId, $aOfferInfo[$CNF['FIELD_OFR_AUTHOR']], $aParams);
  966. }
  967. public function onOfferAccepted($iOfferId)
  968. {
  969. $CNF = &$this->_oConfig->CNF;
  970. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  971. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  972. return;
  973. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  974. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  975. if(empty($aContentInfo) || !is_array($aContentInfo))
  976. return;
  977. $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
  978. $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
  979. sendMailTemplate($CNF['ETEMPLATE_OFFER_ACCEPTED'], 0, $iOfferer, array(
  980. 'offerer_name' => $oOfferer->getDisplayName(),
  981. 'offerer_url' => $oOfferer->getUrl(),
  982. 'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  983. 'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  984. 'i' => $CNF['URI_VIEW_ENTRY'],
  985. $CNF['FIELD_ID'] => $iContentId
  986. ))
  987. ));
  988. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  989. bx_alert($this->getName(), 'offer_accepted', $iOfferId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  990. }
  991. public function onOfferDeclined($iOfferId)
  992. {
  993. $CNF = &$this->_oConfig->CNF;
  994. $aOfferInfo = $this->_oDb->getOffersBy(array('type' => 'id', 'id' => $iOfferId));
  995. if(empty($aOfferInfo) || !is_array($aOfferInfo))
  996. return;
  997. $iContentId = (int)$aOfferInfo[$CNF['FIELD_OFR_CONTENT']];
  998. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  999. if(empty($aContentInfo) || !is_array($aContentInfo))
  1000. return;
  1001. $iOfferer = (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']];
  1002. $oOfferer = BxDolProfile::getInstanceMagic($iOfferer);
  1003. sendMailTemplate($CNF['ETEMPLATE_OFFER_DECLINED'], 0, $iOfferer, array(
  1004. 'offerer_name' => $oOfferer->getDisplayName(),
  1005. 'offerer_url' => $oOfferer->getUrl(),
  1006. 'ad_name' => $aContentInfo[$CNF['FIELD_TITLE']],
  1007. 'ad_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  1008. 'i' => $CNF['URI_VIEW_ENTRY'],
  1009. $CNF['FIELD_ID'] => $iContentId
  1010. ))
  1011. ));
  1012. $aParams = $this->_alertParamsOffer($aContentInfo, $aOfferInfo);
  1013. bx_alert($this->getName(), 'offer_declined', $iOfferId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  1014. }
  1015. /**
  1016. * Common methods.
  1017. */
  1018. public function processMetasAdd($iContentId)
  1019. {
  1020. if(!parent::processMetasAdd($iContentId))
  1021. return false;
  1022. $CNF = &$this->_oConfig->CNF;
  1023. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1024. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1025. $aCategoryTypes = $this->_oDb->getCategoryTypes(array('type' => 'all'));
  1026. foreach($aCategoryTypes as $aCategoryType)
  1027. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $aCategoryType['display_add']);
  1028. return true;
  1029. }
  1030. public function processMetasEdit($iContentId, $oForm)
  1031. {
  1032. if(!parent::processMetasEdit($iContentId, $oForm))
  1033. return false;
  1034. $CNF = &$this->_oConfig->CNF;
  1035. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1036. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1037. $aCategoryTypes = $this->_oDb->getCategoryTypes(array('type' => 'all'));
  1038. foreach($aCategoryTypes as $aCategoryType)
  1039. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $aCategoryType['display_edit']);
  1040. return true;
  1041. }
  1042. public function getCategoryDisplay($sDisplayType, $iCategory = 0)
  1043. {
  1044. if(empty($iCategory) && bx_get('category') !== false)
  1045. $iCategory = (int)bx_get('category');
  1046. if(empty($iCategory))
  1047. return false;
  1048. $aCategory = $this->_oDb->getCategories(array('type' => 'id_full', 'id' => $iCategory));
  1049. $sKey = 'type_display_' . $sDisplayType;
  1050. if(empty($aCategory[$sKey]))
  1051. return false;
  1052. return $aCategory[$sKey];
  1053. }
  1054. /**
  1055. * Internal methods.
  1056. */
  1057. protected function _actionMarkAs($sAction)
  1058. {
  1059. $CNF = &$this->_oConfig->CNF;
  1060. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1061. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1062. $sMethodCheck = 'checkAllowedMark' . bx_gen_method_name($sAction);
  1063. if(!method_exists($this, $sMethodCheck))
  1064. return array();
  1065. if(($mixedCheckResult = $this->$sMethodCheck($aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
  1066. return array('msg' => $mixedCheckResult);
  1067. if((int)$this->_oDb->updateEntriesBy(array($CNF['FIELD_' . strtoupper($sAction)] => time()), array($CNF['FIELD_ID'] => $iContentId)) == 0)
  1068. return array('msg' => _t('_bx_ads_txt_err_cannot_perform_action'));
  1069. $this->$sMethodCheck($aContentInfo, true);
  1070. return array(
  1071. 'reload' => 1
  1072. );
  1073. }
  1074. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  1075. {
  1076. $CNF = &$this->_oConfig->CNF;
  1077. $mixedContent = $this->_getContent($iContentId, true);
  1078. if($mixedContent === false)
  1079. return false;
  1080. list($iContentId, $aContentInfo) = $mixedContent;
  1081. $sDisplayType = false;
  1082. switch($sFormMethod) {
  1083. case 'editDataForm':
  1084. $sDisplayType = 'edit';
  1085. break;
  1086. case 'viewDataForm':
  1087. case 'viewDataEntry':
  1088. $sDisplayType = 'view';
  1089. break;
  1090. }
  1091. if($sDisplayType !== false && ($sDisplayNew = $this->getCategoryDisplay($sDisplayType, $aContentInfo[$CNF['FIELD_CATEGORY']])) !== false)
  1092. $sDisplay = $sDisplayNew;
  1093. return parent::_serviceEntityForm ($sFormMethod, $iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  1094. }
  1095. protected function _getCategoryOptions($iParentId, &$aValues)
  1096. {
  1097. $aCategories = $this->_oDb->getCategories(array('type' => 'parent_id', 'parent_id' => $iParentId, 'active' => true));
  1098. foreach($aCategories as $aCategory) {
  1099. $aValues[] = array('key' => $aCategory['id'], 'value' => str_repeat('--', (int)$aCategory['level']) . ' ' . _t($aCategory['title']));
  1100. $this->_getCategoryOptions($aCategory['id'], $aValues);
  1101. }
  1102. }
  1103. protected function _getSearchableFields($mixedDisplayType = '')
  1104. {
  1105. $CNF = &$this->_oConfig->CNF;
  1106. if(empty($mixedDisplayType))
  1107. $mixedDisplayType = array('add', 'edit');
  1108. $aResult = array();
  1109. $aDisplays = $this->_oDb->getDisplays($this->_oConfig->getName() . '_entry', $mixedDisplayType);
  1110. foreach($aDisplays as $aDisplay) {
  1111. if($aDisplay['display_name'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])
  1112. continue;
  1113. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $aDisplay['display_name'], $this->_oTemplate);
  1114. if(!$oForm)
  1115. continue;
  1116. $aResult = array_merge($aResult, $oForm->aInputs);
  1117. }
  1118. return $aResult;
  1119. }
  1120. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  1121. {
  1122. $CNF = &$this->_oConfig->CNF;
  1123. $bDynamic = isset($aBrowseParams['dynamic_mode']) && (bool)$aBrowseParams['dynamic_mode'] === true;
  1124. $sCategory = '';
  1125. if(!empty($CNF['FIELD_CATEGORY']) && !empty($aContentInfo[$CNF['FIELD_CATEGORY']])) {
  1126. $iCategory = (int)$aContentInfo[$CNF['FIELD_CATEGORY']];
  1127. $aCategory = $this->_oDb->getCategories(array('type' => 'id', 'id' => $iCategory));
  1128. $sCategory = _t($aCategory['title']);
  1129. $sCategoryLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_CATEGORIES'], array($CNF['GET_PARAM_CATEGORY'] => $iCategory));
  1130. }
  1131. $sPrice = _t('_bx_ads_txt_free');
  1132. if(!empty($CNF['FIELD_PRICE']) && !empty($aContentInfo[$CNF['FIELD_PRICE']]))
  1133. $sPrice = _t_format_currency((float)$aContentInfo[$CNF['FIELD_PRICE']]);
  1134. $sInclude = $this->_oTemplate->addCss(array('timeline.css'), $bDynamic);
  1135. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  1136. $aResult['text'] = $this->_oTemplate->parseHtmlByName('timeline_post_text.html', array(
  1137. 'category_link' => $sCategoryLink,
  1138. 'category_title' => $sCategory,
  1139. 'category_title_attr' => bx_html_attribute($sCategory),
  1140. 'price' => $sPrice,
  1141. 'text' => $aResult['text']
  1142. )) . ($bDynamic ? $sInclude : '');
  1143. return $aResult;
  1144. }
  1145. protected function _getBlockLicenses($sType = '')
  1146. {
  1147. $CNF = &$this->_oConfig->CNF;
  1148. $sGrid = $CNF['OBJECT_GRID_LICENSES' . (!empty($sType) ? '_' . strtoupper($sType) : '')];
  1149. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  1150. if(!$oGrid)
  1151. return '';
  1152. $this->_oDb->updateLicense(array('new' => 0), array('profile_id' => bx_get_logged_profile_id(), 'new' => 1));
  1153. $this->_oTemplate->addJs(array('licenses.js'));
  1154. return array(
  1155. 'content' => $this->_oTemplate->getJsCode('licenses', array('sObjNameGrid' => $sGrid)) . $oGrid->getCode(),
  1156. 'menu' => $CNF['OBJECT_MENU_LICENSES']
  1157. );
  1158. }
  1159. protected function _alertParamsOffer($aContentInfo, $aOfferInfo)
  1160. {
  1161. $CNF = &$this->_oConfig->CNF;
  1162. $aParams = array(
  1163. 'object_id' => (int)$aContentInfo[$CNF['FIELD_ID']],
  1164. 'object_author_id' => (int)$aContentInfo[$CNF['FIELD_AUTHOR']],
  1165. 'offer_id' => (int)$aOfferInfo[$CNF['FIELD_OFR_ID']],
  1166. 'offer_author_id' => (int)$aOfferInfo[$CNF['FIELD_OFR_AUTHOR']],
  1167. );
  1168. if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  1169. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  1170. return $aParams;
  1171. }
  1172. }
  1173. /** @} */