BxAdsModule.php 60 KB

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