BxBaseModGeneralModule.php 37 KB

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