1
0

BxBaseModGeneralModule.php 41 KB

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