BxBaseModGeneralModule.php 36 KB

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