1
0

BxBaseModGeneralModule.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. /**
  13. * Base module class.
  14. */
  15. class BxBaseModGeneralModule extends BxDolModule
  16. {
  17. protected $_iProfileId;
  18. function __construct(&$aModule)
  19. {
  20. parent::__construct($aModule);
  21. $this->_iProfileId = bx_get_logged_profile_id();
  22. }
  23. // ====== ACTIONS METHODS
  24. public function actionRss ()
  25. {
  26. $aArgs = func_get_args();
  27. $this->_rss($aArgs);
  28. }
  29. // ====== SERVICE METHODS
  30. public function serviceGetAuthor ($iContentId)
  31. {
  32. $mixedResult = $this->_getFieldValue('FIELD_AUTHOR', $iContentId);
  33. return $mixedResult !== false ? (int)$mixedResult : 0;
  34. }
  35. public function serviceGetDateAdded ($iContentId)
  36. {
  37. $mixedResult = $this->_getFieldValue('FIELD_ADDED', $iContentId);
  38. return $mixedResult !== false ? (int)$mixedResult : 0;
  39. }
  40. public function serviceGetDateChanged ($iContentId)
  41. {
  42. $mixedResult = $this->_getFieldValue('FIELD_CHANGED', $iContentId);
  43. return $mixedResult !== false ? (int)$mixedResult : 0;
  44. }
  45. public function serviceGetLink ($iContentId)
  46. {
  47. $CNF = &$this->_oConfig->CNF;
  48. if(empty($CNF['URI_VIEW_ENTRY']))
  49. return '';
  50. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  51. if(empty($aContentInfo))
  52. return '';
  53. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  54. }
  55. public function serviceGetTitle ($iContentId)
  56. {
  57. $mixedResult = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  58. return $mixedResult !== false ? $mixedResult : '';
  59. }
  60. public function serviceGetText ($iContentId)
  61. {
  62. $mixedResult = $this->_getFieldValue('FIELD_TEXT', $iContentId);
  63. return $mixedResult !== false ? $mixedResult : '';
  64. }
  65. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  66. {
  67. $CNF = &$this->_oConfig->CNF;
  68. $aContentInfo = $this->_getFields($iContentId);
  69. if(empty($aContentInfo))
  70. return array();
  71. if(!$bSearchableFieldsOnly)
  72. return $aContentInfo;
  73. if(empty($CNF['PARAM_SEARCHABLE_FIELDS']))
  74. return array();
  75. $aFields = explode(',', getParam($CNF['PARAM_SEARCHABLE_FIELDS']));
  76. if(empty($aFields))
  77. return array();
  78. $aResult = array();
  79. foreach($aFields as $sField)
  80. if(isset($aContentInfo[$sField]))
  81. $aResult[$sField] = $aContentInfo[$sField];
  82. return $aResult;
  83. }
  84. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  85. {
  86. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  87. if(empty($aContentInfo))
  88. return '';
  89. if(empty($sUnitTemplate))
  90. $sUnitTemplate = 'unit.html';
  91. return $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
  92. }
  93. public function serviceGetAll ($aParams = array())
  94. {
  95. if(empty($aParams) || !is_array($aParams))
  96. $aParams = array('type' => 'all');
  97. return $this->_oDb->getEntriesBy($aParams);
  98. }
  99. public function serviceModuleIcon ()
  100. {
  101. return isset($this->_oConfig->CNF['ICON']) ? $this->_oConfig->CNF['ICON'] : '';
  102. }
  103. public function serviceGetSearchableFields ()
  104. {
  105. $CNF = $this->_oConfig->CNF;
  106. if (!isset($CNF['PARAM_SEARCHABLE_FIELDS']) || !isset($CNF['OBJECT_FORM_ENTRY']) || !isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
  107. return array();
  108. $aTextTypes = array('text', 'textarea');
  109. $aTextFields = array();
  110. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  111. foreach ($oForm->aInputs as $r) {
  112. if (in_array($r['type'], $aTextTypes))
  113. $aTextFields[$r['name']] = $r['caption'];
  114. }
  115. return $aTextFields;
  116. }
  117. public function serviceManageTools($sType = 'common')
  118. {
  119. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
  120. if(!$oGrid)
  121. return '';
  122. $CNF = &$this->_oConfig->CNF;
  123. $sMenu = '';
  124. if(BxDolAcl::getInstance()->isMemberLevelInSet(192)) {
  125. $oPermalink = BxDolPermalinks::getInstance();
  126. $aMenuItems = array();
  127. if(!empty($CNF['OBJECT_GRID_COMMON']) && !empty($CNF['T']['menu_item_manage_my']))
  128. $aMenuItems[] = array('id' => 'manage-common', 'name' => 'manage-common', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_MANAGE_COMMON']), 'target' => '_self', 'title' => _t($CNF['T']['menu_item_manage_my']), 'active' => 1);
  129. if(!empty($CNF['OBJECT_GRID_ADMINISTRATION']) && !empty($CNF['T']['menu_item_manage_all']))
  130. $aMenuItems[] = array('id' => 'manage-administration', 'name' => 'manage-administration', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_MANAGE_ADMINISTRATION']), 'target' => '_self', 'title' => _t($CNF['T']['menu_item_manage_all']), 'active' => 1);
  131. if(count($aMenuItems) > 1) {
  132. $oMenu = new BxTemplMenu(array(
  133. 'template' => 'menu_vertical.html',
  134. 'menu_items' => $aMenuItems
  135. ), $this->_oTemplate);
  136. $oMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
  137. $sMenu = $oMenu->getCode();
  138. }
  139. }
  140. if(!empty($CNF['OBJECT_MENU_SUBMENU'])) {
  141. BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
  142. }
  143. $this->_oTemplate->addCss(array('manage_tools.css'));
  144. $this->_oTemplate->addJs(array('manage_tools.js'));
  145. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  146. return array(
  147. 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
  148. 'menu' => $sMenu
  149. );
  150. }
  151. public function serviceGetMenuAddonManageTools()
  152. {
  153. return 0;
  154. }
  155. public function serviceGetMenuAddonManageToolsProfileStats()
  156. {
  157. return 0;
  158. }
  159. /**
  160. * Display featured entries
  161. * @return HTML string
  162. */
  163. public function serviceBrowseFeatured ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  164. {
  165. return $this->_serviceBrowse ('featured', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  166. }
  167. /**
  168. * Display entries favored by a member
  169. * @return HTML string
  170. */
  171. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  172. {
  173. $oProfile = null;
  174. if((int)$iProfileId)
  175. $oProfile = BxDolProfile::getInstance($iProfileId);
  176. if(!$oProfile && bx_get('profile_id') !== false)
  177. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  178. if(!$oProfile)
  179. $oProfile = BxDolProfile::getInstance();
  180. if(!$oProfile)
  181. return '';
  182. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, true);
  183. }
  184. public function serviceFormsHelper ()
  185. {
  186. bx_import('FormsEntryHelper', $this->_aModule);
  187. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  188. return new $sClass($this);
  189. }
  190. /**
  191. * Add entry using provided fields' values.
  192. * @return HTML string
  193. */
  194. public function serviceEntityAdd ($iAccount, $aValues)
  195. {
  196. bx_import('FormsEntryHelper', $this->_aModule);
  197. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  198. $oFormsHelper = new $sClass($this);
  199. return $oFormsHelper->addData($iAccount, $aValues);
  200. }
  201. /**
  202. * Create entry form
  203. * @return HTML string
  204. */
  205. public function serviceEntityCreate ()
  206. {
  207. bx_import('FormsEntryHelper', $this->_aModule);
  208. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  209. $oFormsHelper = new $sClass($this);
  210. return $oFormsHelper->addDataForm();
  211. }
  212. public function serviceEntityEdit ($iContentId = 0)
  213. {
  214. return $this->_serviceEntityForm ('editDataForm', $iContentId);
  215. }
  216. public function serviceEntityDelete ($iContentId = 0)
  217. {
  218. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  219. }
  220. public function serviceEntityTextBlock ($iContentId = 0)
  221. {
  222. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  223. }
  224. public function serviceEntityInfo ($iContentId = 0)
  225. {
  226. return $this->_serviceEntityForm ('viewDataForm', $iContentId);
  227. }
  228. public function serviceEntityInfoFull ($iContentId = 0)
  229. {
  230. $CNF = &$this->_oConfig->CNF;
  231. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  232. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  233. }
  234. public function serviceEntityInfoExtended ($iContentId = 0)
  235. {
  236. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  237. }
  238. /**
  239. * Entry location info
  240. */
  241. public function serviceEntityLocation ($iContentId = 0)
  242. {
  243. if (!$iContentId)
  244. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  245. if (!$iContentId)
  246. return false;
  247. return $this->_oTemplate->entryLocation ($iContentId);
  248. }
  249. /**
  250. * Delete content entry
  251. * @param $iContentId content id
  252. * @return error message or empty string on success
  253. */
  254. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  255. {
  256. bx_import('FormsEntryHelper', $this->_aModule);
  257. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  258. $oFormsHelper = new $sClass($this);
  259. return $oFormsHelper->$sFuncDelete($iContentId);
  260. }
  261. /**
  262. * Entry actions and social sharing block
  263. */
  264. public function serviceEntityAllActions ($iContentId = 0)
  265. {
  266. return $this->_oTemplate->entryAllActions('', $this->serviceEntitySocialSharing($iContentId));
  267. }
  268. /**
  269. * Entry actions block
  270. */
  271. public function serviceEntityActions ($iContentId = 0)
  272. {
  273. if (!$iContentId)
  274. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  275. if (!$iContentId)
  276. return false;
  277. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  278. return $oMenu ? $oMenu->getCode() : false;
  279. }
  280. /**
  281. * Entry social sharing block
  282. */
  283. public function serviceEntitySocialSharing ($iContentId = 0)
  284. {
  285. if (!$iContentId)
  286. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  287. if (!$iContentId)
  288. return false;
  289. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  290. if (!$aContentInfo)
  291. return false;
  292. $CNF = &$this->_oConfig->CNF;
  293. return $this->_entitySocialSharing ($iContentId, array(
  294. 'id_timeline' => $iContentId,
  295. 'id_thumb' => !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : '',
  296. 'title' => !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  297. 'object_storage' => !empty($CNF['OBJECT_STORAGE']) ? $CNF['OBJECT_STORAGE'] : '',
  298. 'object_transcoder' => false,
  299. 'object_view' => !empty($CNF['OBJECT_VIEWS']) ? $CNF['OBJECT_VIEWS'] : '',
  300. 'object_vote' => !empty($CNF['OBJECT_VOTES']) ? $CNF['OBJECT_VOTES'] : '',
  301. 'object_favorite' => !empty($CNF['OBJECT_FAVORITES']) ? $CNF['OBJECT_FAVORITES'] : '',
  302. 'object_feature' => !empty($CNF['OBJECT_FEATURED']) ? $CNF['OBJECT_FEATURED'] : '',
  303. 'object_report' => !empty($CNF['OBJECT_REPORTS']) ? $CNF['OBJECT_REPORTS'] : '',
  304. 'uri_view_entry' => !empty($CNF['URI_VIEW_ENTRY']) ? $CNF['URI_VIEW_ENTRY'] : '',
  305. ));
  306. }
  307. /**
  308. * Data for Notifications module
  309. */
  310. public function serviceGetNotificationsData()
  311. {
  312. $sModule = $this->_aModule['name'];
  313. $sEventPrivacy = $sModule . '_allow_view_event_to';
  314. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  315. $sEventPrivacy = '';
  316. return array(
  317. 'handlers' => array(
  318. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  319. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  320. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  321. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  322. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  323. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  324. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  325. ),
  326. 'alerts' => array(
  327. array('unit' => $sModule, 'action' => 'added'),
  328. array('unit' => $sModule, 'action' => 'edited'),
  329. array('unit' => $sModule, 'action' => 'deleted'),
  330. array('unit' => $sModule, 'action' => 'commentPost'),
  331. array('unit' => $sModule, 'action' => 'commentRemoved'),
  332. array('unit' => $sModule, 'action' => 'doVote'),
  333. array('unit' => $sModule, 'action' => 'undoVote'),
  334. )
  335. );
  336. }
  337. /**
  338. * Entry post for Notifications module
  339. */
  340. public function serviceGetNotificationsPost($aEvent)
  341. {
  342. $CNF = &$this->_oConfig->CNF;
  343. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  344. if(empty($aContentInfo) || !is_array($aContentInfo))
  345. return array();
  346. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  347. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  348. return array(
  349. 'entry_sample' => $CNF['T']['txt_sample_single'],
  350. 'entry_url' => $sEntryUrl,
  351. 'entry_caption' => $sEntryCaption,
  352. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  353. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  354. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  355. );
  356. }
  357. /**
  358. * Entry post comment for Notifications module
  359. */
  360. public function serviceGetNotificationsComment($aEvent)
  361. {
  362. $CNF = &$this->_oConfig->CNF;
  363. $iContentId = (int)$aEvent['object_id'];
  364. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  365. if(empty($aContentInfo) || !is_array($aContentInfo))
  366. return array();
  367. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  368. if(!$oComment || !$oComment->isEnabled())
  369. return array();
  370. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  371. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  372. return array(
  373. 'entry_sample' => $CNF['T']['txt_sample_single'],
  374. 'entry_url' => $sEntryUrl,
  375. 'entry_caption' => $sEntryCaption,
  376. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  377. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  378. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  379. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  380. );
  381. }
  382. /**
  383. * Entry post vote for Notifications module
  384. */
  385. public function serviceGetNotificationsVote($aEvent)
  386. {
  387. $CNF = &$this->_oConfig->CNF;
  388. $iContentId = (int)$aEvent['object_id'];
  389. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  390. if(empty($aContentInfo) || !is_array($aContentInfo))
  391. return array();
  392. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  393. if(!$oVote || !$oVote->isEnabled())
  394. return array();
  395. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  396. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  397. return array(
  398. 'entry_sample' => $CNF['T']['txt_sample_single'],
  399. 'entry_url' => $sEntryUrl,
  400. 'entry_caption' => $sEntryCaption,
  401. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  402. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  403. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  404. );
  405. }
  406. public function _serviceGetNotification($aEvent, $sLangKey)
  407. {
  408. $CNF = &$this->_oConfig->CNF;
  409. $iContentId = (int)$aEvent['object_id'];
  410. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  411. if (!$oGroupProfile)
  412. return false;
  413. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  414. if(empty($aContentInfo) || !is_array($aContentInfo))
  415. return array();
  416. $oProfile = BxDolProfile::getInstance((int)$aEvent['subobject_id']);
  417. if (!$oProfile)
  418. return false;
  419. return array(
  420. 'entry_sample' => $CNF['T']['txt_sample_single'],
  421. 'entry_url' => $oGroupProfile->getUrl(),
  422. 'entry_caption' => $oGroupProfile->getDisplayName(),
  423. 'entry_author' => $oGroupProfile->id(),
  424. 'subentry_sample' => $oProfile->getDisplayName(),
  425. 'subentry_url' => $oProfile->getUrl(),
  426. 'lang_key' => $sLangKey,
  427. );
  428. }
  429. /**
  430. * Data for Timeline module
  431. */
  432. public function serviceGetTimelineData()
  433. {
  434. $sModule = $this->_aModule['name'];
  435. return array(
  436. 'handlers' => array(
  437. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'module_name' => $sModule, 'module_method' => 'get_timeline_post', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
  438. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  439. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  440. ),
  441. 'alerts' => array(
  442. array('unit' => $sModule, 'action' => 'added'),
  443. array('unit' => $sModule, 'action' => 'edited'),
  444. array('unit' => $sModule, 'action' => 'deleted'),
  445. )
  446. );
  447. }
  448. /**
  449. * Entry post for Timeline module
  450. */
  451. public function serviceGetTimelinePost($aEvent)
  452. {
  453. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  454. if(empty($aContentInfo) || !is_array($aContentInfo))
  455. return '';
  456. $CNF = &$this->_oConfig->CNF;
  457. //--- Views
  458. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aEvent['object_id']) : null;
  459. $aViews = array();
  460. if ($oViews && $oViews->isEnabled())
  461. $aViews = array(
  462. 'system' => $CNF['OBJECT_VIEWS'],
  463. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  464. 'count' => $aContentInfo['views']
  465. );
  466. //--- Votes
  467. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aEvent['object_id']) : null;
  468. $aVotes = array();
  469. if ($oVotes && $oVotes->isEnabled())
  470. $aVotes = array(
  471. 'system' => $CNF['OBJECT_VOTES'],
  472. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  473. 'count' => $aContentInfo['votes']
  474. );
  475. //--- Reports
  476. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aEvent['object_id']) : null;
  477. $aReports = array();
  478. if ($oReports && $oReports->isEnabled())
  479. $aReports = array(
  480. 'system' => $CNF['OBJECT_REPORTS'],
  481. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  482. 'count' => $aContentInfo['reports']
  483. );
  484. //--- Comments
  485. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']) : null;
  486. $aComments = array();
  487. if($oCmts && $oCmts->isEnabled())
  488. $aComments = array(
  489. 'system' => $CNF['OBJECT_COMMENTS'],
  490. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  491. 'count' => $aContentInfo['comments']
  492. );
  493. //--- Title & Description
  494. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  495. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  496. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  497. return array(
  498. 'owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  499. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  500. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  501. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  502. 'sample_action' => isset($CNF['T']['txt_sample_single_action']) ? $CNF['T']['txt_sample_single_action'] : '',
  503. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  504. 'content' => $this->_getContentForTimelinePost($aEvent, $aContentInfo), //a string to display or array to parse default template before displaying.
  505. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  506. 'views' => $aViews,
  507. 'votes' => $aVotes,
  508. 'reports' => $aReports,
  509. 'comments' => $aComments,
  510. 'title' => $sTitle, //may be empty.
  511. 'description' => '' //may be empty.
  512. );
  513. }
  514. // ====== PERMISSION METHODS
  515. /**
  516. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  517. */
  518. public function checkAllowedBrowse ()
  519. {
  520. return CHECK_ACTION_RESULT_ALLOWED;
  521. }
  522. /**
  523. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  524. */
  525. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  526. {
  527. $CNF = &$this->_oConfig->CNF;
  528. // moderator and owner always have access
  529. if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  530. return CHECK_ACTION_RESULT_ALLOWED;
  531. // check ACL
  532. $aCheck = checkActionModule($this->_iProfileId, 'view entry', $this->getName(), $isPerformAction);
  533. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  534. return $aCheck[CHECK_ACTION_MESSAGE];
  535. // check privacy
  536. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  537. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  538. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]))
  539. return _t('_sys_access_denied_to_private_content');
  540. }
  541. return CHECK_ACTION_RESULT_ALLOWED;
  542. }
  543. /**
  544. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  545. */
  546. public function checkAllowedAdd ($isPerformAction = false)
  547. {
  548. // check ACL
  549. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  550. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  551. return $aCheck[CHECK_ACTION_MESSAGE];
  552. return CHECK_ACTION_RESULT_ALLOWED;
  553. }
  554. /**
  555. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  556. */
  557. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  558. {
  559. // moderator and owner always have access
  560. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  561. return CHECK_ACTION_RESULT_ALLOWED;
  562. return _t('_sys_txt_access_denied');
  563. }
  564. /**
  565. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  566. */
  567. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  568. {
  569. // moderator always has access
  570. if ($this->_isModerator($isPerformAction))
  571. return CHECK_ACTION_RESULT_ALLOWED;
  572. // check ACL
  573. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  574. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  575. return CHECK_ACTION_RESULT_ALLOWED;
  576. return _t('_sys_txt_access_denied');
  577. }
  578. /**
  579. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  580. */
  581. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  582. {
  583. // admin always has access
  584. if (isAdmin())
  585. return CHECK_ACTION_RESULT_ALLOWED;
  586. // check ACL
  587. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  588. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  589. return $aCheck[CHECK_ACTION_MESSAGE];
  590. return CHECK_ACTION_RESULT_ALLOWED;
  591. }
  592. /**
  593. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  594. */
  595. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  596. {
  597. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  598. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  599. return CHECK_ACTION_RESULT_ALLOWED;
  600. return _t('_sys_txt_access_denied');
  601. }
  602. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  603. {
  604. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  605. return MsgBox($sMsg);
  606. bx_import($sClassSearchResult, $this->_aModule);
  607. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  608. $o = new $sClass($sMode, $aParams);
  609. $o->setDesignBoxTemplateId($iDesignBox);
  610. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  611. $o->setAjaxPaginate($bAjaxPaginate);
  612. $o->setUnitParams(array('context' => $sMode));
  613. if ($o->isError)
  614. return '';
  615. if ($s = $o->processing())
  616. return $s;
  617. else
  618. return '';
  619. }
  620. // ====== COMMON METHODS
  621. public function getProfileId()
  622. {
  623. return bx_get_logged_profile_id();
  624. }
  625. public function getProfileInfo($iUserId = 0)
  626. {
  627. $oProfile = $this->getObjectUser($iUserId);
  628. $oAccount = null;
  629. if($oProfile && !($oProfile instanceof BxDolProfileUndefined))
  630. $oAccount = $oProfile->getAccountObject();
  631. $bAccount = !empty($oAccount);
  632. return array(
  633. 'id' => $oProfile->id(),
  634. 'name' => $oProfile->getDisplayName(),
  635. 'email' => $bAccount ? $oAccount->getEmail() : '',
  636. 'link' => $oProfile->getUrl(),
  637. 'icon' => $oProfile->getIcon(),
  638. 'thumb' => $oProfile->getThumb(),
  639. 'avatar' => $oProfile->getAvatar(),
  640. 'unit' => $oProfile->getUnit(),
  641. 'active' => $oProfile->isActive(),
  642. );
  643. }
  644. public function getObjectUser($iUserId = 0)
  645. {
  646. bx_import('BxDolProfile');
  647. $oProfile = BxDolProfile::getInstance($iUserId);
  648. if (!$oProfile) {
  649. bx_import('BxDolProfileUndefined');
  650. $oProfile = BxDolProfileUndefined::getInstance();
  651. }
  652. return $oProfile;
  653. }
  654. public function getObjectFavorite($sSystem = '', $iId = 0)
  655. {
  656. $CNF = &$this->_oConfig->CNF;
  657. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  658. $sSystem = $CNF['OBJECT_FAVORITES'];
  659. if(empty($sSystem))
  660. return false;
  661. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  662. if(!$oFavorite->isEnabled())
  663. return false;
  664. return $oFavorite;
  665. }
  666. public function getUserId()
  667. {
  668. return isLogged() ? bx_get_logged_profile_id() : 0;
  669. }
  670. public function getUserIp()
  671. {
  672. return getVisitorIP();
  673. }
  674. public function getUserInfo($iUserId = 0)
  675. {
  676. $oProfile = BxDolProfile::getInstance($iUserId);
  677. if (!$oProfile)
  678. $oProfile = BxDolProfileUndefined::getInstance();
  679. return array(
  680. $oProfile->getDisplayName(),
  681. $oProfile->getUrl(),
  682. $oProfile->getThumb(),
  683. $oProfile->getUnit()
  684. );
  685. }
  686. // ====== PROTECTED METHODS
  687. protected function _isModerator ($isPerformAction = false)
  688. {
  689. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
  690. }
  691. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false)
  692. {
  693. if (!$iContentId)
  694. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  695. if (!$iContentId)
  696. return false;
  697. bx_import('FormsEntryHelper', $this->_aModule);
  698. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  699. $oFormsHelper = new $sClass($this);
  700. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay);
  701. }
  702. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  703. {
  704. if (!$iContentId)
  705. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  706. if (!$iContentId)
  707. return false;
  708. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  709. if (!$aContentInfo)
  710. return false;
  711. return $this->_oTemplate->$sFunc($aContentInfo);
  712. }
  713. protected function _rss ($aArgs, $sClass = 'SearchResult')
  714. {
  715. $sMode = array_shift($aArgs);
  716. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  717. $this->_oTemplate->displayAccessDenied ($sMsg);
  718. exit;
  719. }
  720. $aParams = $this->_buildRssParams($sMode, $aArgs);
  721. bx_import ($sClass, $this->_aModule);
  722. $sClass = $this->_aModule['class_prefix'] . $sClass;
  723. $o = new $sClass($sMode, $aParams);
  724. if ($o->isError)
  725. $this->_oTemplate->displayPageNotFound ();
  726. else
  727. $o->outputRSS();
  728. exit;
  729. }
  730. protected function _getContentForTimelinePost($aEvent, $aContentInfo)
  731. {
  732. $CNF = &$this->_oConfig->CNF;
  733. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  734. //--- Image(s)
  735. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl);
  736. return array(
  737. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  738. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  739. 'sample_action' => isset($CNF['T']['txt_sample_single_action']) ? $CNF['T']['txt_sample_single_action'] : '',
  740. 'url' => $sUrl,
  741. 'title' => isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] :
  742. (isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...') : ''),
  743. 'text' => isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '',
  744. 'images' => $aImages,
  745. );
  746. }
  747. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl)
  748. {
  749. $CNF = &$this->_oConfig->CNF;
  750. $sImage = '';
  751. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
  752. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_COVER'])) {
  753. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_COVER']);
  754. if($oTranscoder)
  755. $sImage = $oTranscoder->getFileUrl($aContentInfo[$CNF['FIELD_COVER']]);
  756. }
  757. if($sImage == '' && !empty($CNF['OBJECT_IMAGES_TRANSCODER_THUMB'])) {
  758. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_THUMB']);
  759. if($oTranscoder)
  760. $sImage = $oTranscoder->getFileUrl($aContentInfo[$CNF['FIELD_COVER']]);
  761. }
  762. }
  763. if($sImage == '' && isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']]) {
  764. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_THUMB'])) {
  765. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_THUMB']);
  766. if($oTranscoder)
  767. $sImage = $oTranscoder->getFileUrl($aContentInfo[$CNF['FIELD_THUMB']]);
  768. }
  769. if($sImage == '' && !empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'])) {
  770. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  771. if($oTranscoder)
  772. $sImage = $oTranscoder->getFileUrl($aContentInfo[$CNF['FIELD_THUMB']]);
  773. }
  774. }
  775. if(empty($sImage))
  776. return array();
  777. return array(
  778. array('url' => $sUrl, 'src' => $sImage),
  779. );
  780. }
  781. protected function _entitySocialSharing ($iId, $aParams = array())
  782. {
  783. $sUrl = !empty($aParams['uri_view_entry']) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $aParams['uri_view_entry'] . '&id=' . $iId) : '';
  784. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  785. //--- Comments
  786. $sComments = '';
  787. $oComments = !empty($aParams['object_comments']) ? BxTemplCmts::getObjectInstance($aParams['object_comments'], $iId) : false;
  788. if ($oComments) {
  789. $iNum = $oComments->getCommentsCountAll();
  790. $sComments = $this->_oTemplate->parseHtmlByName('comments-item.html', array (
  791. 'url' => $sUrl . '#' . $oComments->getListAnchor(),
  792. 'bx_if:comments' => array (
  793. 'condition' => $iNum,
  794. 'content' => array (
  795. 'num' => $iNum,
  796. ),
  797. ),
  798. ));
  799. }
  800. $aCustomParams = array();
  801. $iIdThumb = isset($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  802. $bSocialSharing = isset($aParams['social_sharing']) ? (bool)$aParams['social_sharing'] : true;
  803. if ($iIdThumb && $bSocialSharing) {
  804. if(!empty($aParams['object_transcoder']))
  805. $o = BxDolTranscoder::getObjectInstance($aParams['object_transcoder']);
  806. else if(!empty($aParams['object_storage']))
  807. $o = BxDolStorage::getObjectInstance($aParams['object_storage']);
  808. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  809. if($sImgUrl)
  810. $aCustomParams = array (
  811. 'img_url' => $sImgUrl,
  812. 'img_url_encoded' => rawurlencode($sImgUrl),
  813. );
  814. }
  815. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
  816. //--- Views
  817. $sViews = '';
  818. $oViews = !empty($aParams['object_view']) ? BxDolView::getObjectInstance($aParams['object_view'], $iId) : false;
  819. if ($oViews)
  820. $sViews = $oViews->getElementBlock(array('show_do_view_as_button' => true));
  821. //--- Votes
  822. $sVotes = '';
  823. $oVotes = !empty($aParams['object_vote']) ? BxDolVote::getObjectInstance($aParams['object_vote'], $iId) : false;
  824. if ($oVotes)
  825. $sVotes = $oVotes->getElementBlock(array('show_do_vote_as_button' => true));
  826. //--- Favorite
  827. $sFavorites = '';
  828. $oFavorites = !empty($aParams['object_favorite']) ? BxDolFavorite::getObjectInstance($aParams['object_favorite'], $iId) : false;
  829. if ($oFavorites)
  830. $sFavorites = $oFavorites->getElementBlock(array('show_do_favorite_as_button' => true));
  831. //--- Featured
  832. $sFeatured = '';
  833. $oFeatured = !empty($aParams['object_feature']) ? BxDolFeature::getObjectInstance($aParams['object_feature'], $iId) : false;
  834. if ($oFeatured)
  835. $sFeatured = $oFeatured->getElementBlock(array('show_do_feature_as_button' => true));
  836. //--- Timeline Repost
  837. $sRepost = '';
  838. $iIdTimeline = isset($aParams['id_timeline']) ? (int)$aParams['id_timeline'] : $iId;
  839. if ($iIdTimeline && BxDolRequest::serviceExists('bx_timeline', 'get_repost_element_block'))
  840. $sRepost = BxDolService::call('bx_timeline', 'get_repost_element_block', array(bx_get_logged_profile_id(), $this->_aModule['name'], 'added', $iIdTimeline, array('show_do_repost_as_button' => true)));
  841. //--- Report
  842. $sReport = '';
  843. $oReport = !empty($aParams['object_report']) ? BxDolReport::getObjectInstance($aParams['object_report'], $iId) : false;
  844. if ($oReport)
  845. $sReport = $oReport->getElementBlock(array('show_do_report_as_button' => true));
  846. $sSocial = '';
  847. if($bSocialSharing) {
  848. $oSocial = BxDolMenu::getObjectInstance('sys_social_sharing');
  849. $oSocial->addMarkers(array_merge(array(
  850. 'id' => $iId,
  851. 'module' => $this->_aModule['name'],
  852. 'url' => BX_DOL_URL_ROOT . $sUrl,
  853. 'title' => $sTitle,
  854. ), $aCustomParams));
  855. $sSocial = $oSocial->getCode();
  856. }
  857. if(empty($sComments) && empty($sViews) && empty($sVotes) && empty($sFavorites) && empty($sFeatured) && empty($sRepost) && empty($sReport) && empty($sSocial))
  858. return '';
  859. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  860. 'comments' => $sComments,
  861. 'view' => $sViews,
  862. 'vote' => $sVotes,
  863. 'favorite' => $sFavorites,
  864. 'feature' => $sFeatured,
  865. 'repost' => $sRepost,
  866. 'report' => $sReport,
  867. 'social' => $sSocial,
  868. ));
  869. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Repost, etc.
  870. }
  871. protected function _getFields($iContentId)
  872. {
  873. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  874. if(empty($aContentInfo))
  875. return array();
  876. return BxDolContentInfo::formatFields($aContentInfo);
  877. }
  878. protected function _getFieldValue($sField, $iContentId)
  879. {
  880. $CNF = &$this->_oConfig->CNF;
  881. if(empty($CNF[$sField]))
  882. return false;
  883. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  884. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  885. return false;
  886. return $aContentInfo[$CNF[$sField]];
  887. }
  888. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  889. {
  890. $CNF = &$this->_oConfig->CNF;
  891. if(empty($sTranscoder) || empty($CNF[$sField]))
  892. return false;
  893. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  894. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  895. return false;
  896. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  897. if(!$oImagesTranscoder)
  898. return false;
  899. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  900. }
  901. }
  902. /** @} */