1
0

BxBaseModGeneralModule.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup TridentModules
  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 serviceManageTools($sType = 'common')
  35. {
  36. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
  37. if(!$oGrid)
  38. return '';
  39. $CNF = &$this->_oConfig->CNF;
  40. $sMenu = '';
  41. if(BxDolAcl::getInstance()->isMemberLevelInSet(192)) {
  42. $oPermalink = BxDolPermalinks::getInstance();
  43. $aMenuItems = array();
  44. if(!empty($CNF['OBJECT_GRID_COMMON']) && !empty($CNF['T']['menu_item_manage_my']))
  45. $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);
  46. if(!empty($CNF['OBJECT_GRID_ADMINISTRATION']) && !empty($CNF['T']['menu_item_manage_all']))
  47. $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);
  48. if(count($aMenuItems) > 1) {
  49. $oMenu = new BxTemplMenu(array(
  50. 'template' => 'menu_vertical.html',
  51. 'menu_items' => $aMenuItems
  52. ), $this->_oTemplate);
  53. $oMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
  54. $sMenu = $oMenu->getCode();
  55. }
  56. }
  57. if(!empty($CNF['OBJECT_MENU_SUBMENU'])) {
  58. BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
  59. }
  60. $this->_oTemplate->addCss(array('manage_tools.css'));
  61. $this->_oTemplate->addJs(array('manage_tools.js'));
  62. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  63. return array(
  64. 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
  65. 'menu' => $sMenu
  66. );
  67. }
  68. public function serviceGetMenuAddonManageTools()
  69. {
  70. return 0;
  71. }
  72. public function serviceGetMenuAddonManageToolsProfileStats()
  73. {
  74. return 0;
  75. }
  76. public function serviceFormsHelper ()
  77. {
  78. bx_import('FormsEntryHelper', $this->_aModule);
  79. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  80. return new $sClass($this);
  81. }
  82. /**
  83. * Add entry form
  84. * @return HTML string
  85. */
  86. public function serviceEntityCreate ()
  87. {
  88. bx_import('FormsEntryHelper', $this->_aModule);
  89. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  90. $oFormsHelper = new $sClass($this);
  91. return $oFormsHelper->addDataForm();
  92. }
  93. public function serviceEntityEdit ($iContentId = 0)
  94. {
  95. return $this->_serviceEntityForm ('editDataForm', $iContentId);
  96. }
  97. public function serviceEntityDelete ($iContentId = 0)
  98. {
  99. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  100. }
  101. public function serviceEntityTextBlock ($iContentId = 0)
  102. {
  103. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  104. }
  105. public function serviceEntityInfo ($iContentId = 0)
  106. {
  107. return $this->_serviceEntityForm ('viewDataForm', $iContentId);
  108. }
  109. public function serviceEntityInfoFull ($iContentId = 0)
  110. {
  111. $CNF = &$this->_oConfig->CNF;
  112. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  113. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  114. }
  115. public function serviceEntityInfoExtended ($iContentId = 0)
  116. {
  117. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  118. }
  119. /**
  120. * Delete content entry
  121. * @param $iContentId content id
  122. * @return error message or empty string on success
  123. */
  124. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  125. {
  126. bx_import('FormsEntryHelper', $this->_aModule);
  127. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  128. $oFormsHelper = new $sClass($this);
  129. return $oFormsHelper->$sFuncDelete($iContentId);
  130. }
  131. /**
  132. * Entry actions block
  133. */
  134. public function serviceEntityActions ($iContentId = 0)
  135. {
  136. if (!$iContentId)
  137. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  138. if (!$iContentId)
  139. return false;
  140. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  141. return $oMenu ? $oMenu->getCode() : false;
  142. }
  143. /**
  144. * Entry social sharing block
  145. */
  146. public function serviceEntitySocialSharing ($iContentId = 0)
  147. {
  148. if (!$iContentId)
  149. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  150. if (!$iContentId)
  151. return false;
  152. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  153. if (!$aContentInfo)
  154. return false;
  155. $CNF = &$this->_oConfig->CNF;
  156. return $this->_entitySocialSharing ($iContentId, $iContentId, $aContentInfo[$CNF['FIELD_THUMB']], $aContentInfo[$CNF['FIELD_TITLE']], $CNF['OBJECT_STORAGE'], false, $CNF['OBJECT_VOTES'], $CNF['OBJECT_REPORTS'], $CNF['URI_VIEW_ENTRY']);
  157. }
  158. /**
  159. * Data for Notifications module
  160. */
  161. public function serviceGetNotificationsData()
  162. {
  163. $sModule = $this->_aModule['name'];
  164. $sEventPrivacy = $sModule . '_allow_view_event_to';
  165. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  166. $sEventPrivacy = '';
  167. return array(
  168. 'handlers' => array(
  169. 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),
  170. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  171. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  172. 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),
  173. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  174. 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),
  175. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  176. ),
  177. 'alerts' => array(
  178. array('unit' => $sModule, 'action' => 'added'),
  179. array('unit' => $sModule, 'action' => 'edited'),
  180. array('unit' => $sModule, 'action' => 'deleted'),
  181. array('unit' => $sModule, 'action' => 'commentPost'),
  182. array('unit' => $sModule, 'action' => 'commentRemoved'),
  183. array('unit' => $sModule, 'action' => 'doVote'),
  184. array('unit' => $sModule, 'action' => 'undoVote'),
  185. )
  186. );
  187. }
  188. /**
  189. * Entry post for Notifications module
  190. */
  191. public function serviceGetNotificationsPost($aEvent)
  192. {
  193. $CNF = &$this->_oConfig->CNF;
  194. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  195. if(empty($aContentInfo) || !is_array($aContentInfo))
  196. return array();
  197. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  198. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  199. return array(
  200. 'entry_sample' => $CNF['T']['txt_sample_single'],
  201. 'entry_url' => $sEntryUrl,
  202. 'entry_caption' => $sEntryCaption,
  203. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  204. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  205. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  206. );
  207. }
  208. /**
  209. * Entry post comment for Notifications module
  210. */
  211. public function serviceGetNotificationsComment($aEvent)
  212. {
  213. $CNF = &$this->_oConfig->CNF;
  214. $iContentId = (int)$aEvent['object_id'];
  215. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  216. if(empty($aContentInfo) || !is_array($aContentInfo))
  217. return array();
  218. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  219. if(!$oComment || !$oComment->isEnabled())
  220. return array();
  221. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  222. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  223. return array(
  224. 'entry_sample' => $CNF['T']['txt_sample_single'],
  225. 'entry_url' => $sEntryUrl,
  226. 'entry_caption' => $sEntryCaption,
  227. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  228. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  229. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  230. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  231. );
  232. }
  233. /**
  234. * Entry post vote for Notifications module
  235. */
  236. public function serviceGetNotificationsVote($aEvent)
  237. {
  238. $CNF = &$this->_oConfig->CNF;
  239. $iContentId = (int)$aEvent['object_id'];
  240. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  241. if(empty($aContentInfo) || !is_array($aContentInfo))
  242. return array();
  243. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  244. if(!$oVote || !$oVote->isEnabled())
  245. return array();
  246. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  247. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  248. return array(
  249. 'entry_sample' => $CNF['T']['txt_sample_single'],
  250. 'entry_url' => $sEntryUrl,
  251. 'entry_caption' => $sEntryCaption,
  252. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  253. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  254. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  255. );
  256. }
  257. public function _serviceGetNotification($aEvent, $sLangKey)
  258. {
  259. $CNF = &$this->_oConfig->CNF;
  260. $iContentId = (int)$aEvent['object_id'];
  261. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  262. if (!$oGroupProfile)
  263. return false;
  264. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  265. if(empty($aContentInfo) || !is_array($aContentInfo))
  266. return array();
  267. $oProfile = BxDolProfile::getInstance((int)$aEvent['subobject_id']);
  268. if (!$oProfile)
  269. return false;
  270. return array(
  271. 'entry_sample' => $CNF['T']['txt_sample_single'],
  272. 'entry_url' => $oGroupProfile->getUrl(),
  273. 'entry_caption' => $oGroupProfile->getDisplayName(),
  274. 'entry_author' => $oGroupProfile->id(),
  275. 'subentry_sample' => $oProfile->getDisplayName(),
  276. 'subentry_url' => $oProfile->getUrl(),
  277. 'lang_key' => $sLangKey,
  278. );
  279. }
  280. /**
  281. * Data for Timeline module
  282. */
  283. public function serviceGetTimelineData()
  284. {
  285. $sModule = $this->_aModule['name'];
  286. return array(
  287. 'handlers' => array(
  288. 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' => ''),
  289. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  290. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  291. ),
  292. 'alerts' => array(
  293. array('unit' => $sModule, 'action' => 'added'),
  294. array('unit' => $sModule, 'action' => 'edited'),
  295. array('unit' => $sModule, 'action' => 'deleted'),
  296. )
  297. );
  298. }
  299. /**
  300. * Entry post for Timeline module
  301. */
  302. public function serviceGetTimelinePost($aEvent)
  303. {
  304. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  305. if(empty($aContentInfo) || !is_array($aContentInfo))
  306. return '';
  307. $CNF = &$this->_oConfig->CNF;
  308. //--- Votes
  309. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aEvent['object_id']) : null;
  310. $aVotes = array();
  311. if ($oVotes && $oVotes->isEnabled())
  312. $aVotes = array(
  313. 'system' => $CNF['OBJECT_VOTES'],
  314. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  315. 'count' => $aContentInfo['votes']
  316. );
  317. //--- Reports
  318. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aEvent['object_id']) : null;
  319. $aReports = array();
  320. if ($oReports && $oReports->isEnabled())
  321. $aReports = array(
  322. 'system' => $CNF['OBJECT_REPORTS'],
  323. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  324. 'count' => $aContentInfo['reports']
  325. );
  326. //--- Comments
  327. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']) : null;
  328. $aComments = array();
  329. if($oCmts && $oCmts->isEnabled())
  330. $aComments = array(
  331. 'system' => $CNF['OBJECT_COMMENTS'],
  332. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  333. 'count' => $aContentInfo['comments']
  334. );
  335. return array(
  336. 'owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  337. 'content' => $this->_getContentForTimelinePost($aEvent, $aContentInfo), //a string to display or array to parse default template before displaying.
  338. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  339. 'votes' => $aVotes,
  340. 'reports' => $aReports,
  341. 'comments' => $aComments,
  342. 'title' => '', //may be empty.
  343. 'description' => '' //may be empty.
  344. );
  345. }
  346. // ====== PERMISSION METHODS
  347. /**
  348. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  349. */
  350. public function checkAllowedBrowse ()
  351. {
  352. return CHECK_ACTION_RESULT_ALLOWED;
  353. }
  354. /**
  355. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  356. */
  357. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  358. {
  359. $CNF = &$this->_oConfig->CNF;
  360. // moderator and owner always have access
  361. if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  362. return CHECK_ACTION_RESULT_ALLOWED;
  363. // check ACL
  364. $aCheck = checkActionModule($this->_iProfileId, 'view entry', $this->getName(), $isPerformAction);
  365. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  366. return $aCheck[CHECK_ACTION_MESSAGE];
  367. // check privacy
  368. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  369. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  370. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]))
  371. return _t('_sys_access_denied_to_private_content');
  372. }
  373. return CHECK_ACTION_RESULT_ALLOWED;
  374. }
  375. /**
  376. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  377. */
  378. public function checkAllowedAdd ($isPerformAction = false)
  379. {
  380. // check ACL
  381. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  382. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  383. return $aCheck[CHECK_ACTION_MESSAGE];
  384. return CHECK_ACTION_RESULT_ALLOWED;
  385. }
  386. /**
  387. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  388. */
  389. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  390. {
  391. // moderator and owner always have access
  392. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  393. return CHECK_ACTION_RESULT_ALLOWED;
  394. return _t('_sys_txt_access_denied');
  395. }
  396. /**
  397. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  398. */
  399. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  400. {
  401. // moderator always has access
  402. if ($this->_isModerator($isPerformAction))
  403. return CHECK_ACTION_RESULT_ALLOWED;
  404. // check ACL
  405. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  406. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  407. return CHECK_ACTION_RESULT_ALLOWED;
  408. return _t('_sys_txt_access_denied');
  409. }
  410. /**
  411. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  412. */
  413. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  414. {
  415. // admin always has access
  416. if (isAdmin())
  417. return CHECK_ACTION_RESULT_ALLOWED;
  418. // check ACL
  419. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  420. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  421. return $aCheck[CHECK_ACTION_MESSAGE];
  422. return CHECK_ACTION_RESULT_ALLOWED;
  423. }
  424. /**
  425. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  426. */
  427. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  428. {
  429. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  430. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  431. return CHECK_ACTION_RESULT_ALLOWED;
  432. return _t('_sys_txt_access_denied');
  433. }
  434. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  435. {
  436. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  437. return MsgBox($sMsg);
  438. bx_import($sClassSearchResult, $this->_aModule);
  439. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  440. $o = new $sClass($sMode, $aParams);
  441. $o->setDesignBoxTemplateId($iDesignBox);
  442. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  443. $o->setAjaxPaginate($bAjaxPaginate);
  444. $o->setUnitParams(array('context' => $sMode));
  445. if ($o->isError)
  446. return '';
  447. if ($s = $o->processing())
  448. return $s;
  449. else
  450. return '';
  451. }
  452. // ====== PROTECTED METHODS
  453. protected function _isModerator ($isPerformAction = false)
  454. {
  455. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
  456. }
  457. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false)
  458. {
  459. if (!$iContentId)
  460. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  461. if (!$iContentId)
  462. return false;
  463. bx_import('FormsEntryHelper', $this->_aModule);
  464. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  465. $oFormsHelper = new $sClass($this);
  466. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay);
  467. }
  468. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  469. {
  470. if (!$iContentId)
  471. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  472. if (!$iContentId)
  473. return false;
  474. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  475. if (!$aContentInfo)
  476. return false;
  477. return $this->_oTemplate->$sFunc($aContentInfo);
  478. }
  479. protected function _rss ($aArgs, $sClass = 'SearchResult')
  480. {
  481. $sMode = array_shift($aArgs);
  482. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  483. $this->_oTemplate->displayAccessDenied ($sMsg);
  484. exit;
  485. }
  486. $aParams = $this->_buildRssParams($sMode, $aArgs);
  487. bx_import ($sClass, $this->_aModule);
  488. $sClass = $this->_aModule['class_prefix'] . $sClass;
  489. $o = new $sClass($sMode, $aParams);
  490. if ($o->isError)
  491. $this->_oTemplate->displayPageNotFound ();
  492. else
  493. $o->outputRSS();
  494. exit;
  495. }
  496. protected function _getContentForTimelinePost($aEvent, $aContentInfo)
  497. {
  498. $CNF = &$this->_oConfig->CNF;
  499. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  500. //--- Image(s)
  501. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl);
  502. return array(
  503. 'sample' => _t($CNF['T']['txt_sample_single']),
  504. 'url' => $sUrl,
  505. 'title' => isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] :
  506. (isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...') : ''),
  507. 'text' => isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '',
  508. 'images' => $aImages,
  509. );
  510. }
  511. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl)
  512. {
  513. $CNF = &$this->_oConfig->CNF;
  514. $sImage = '';
  515. if (isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']]) {
  516. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  517. if($oTranscoder)
  518. $sImage = $oTranscoder->getFileUrl($aContentInfo[$CNF['FIELD_THUMB']]);
  519. }
  520. if (empty($sImage))
  521. return array();
  522. return array(
  523. array('url' => $sUrl, 'src' => $sImage),
  524. );
  525. }
  526. protected function _entitySocialSharing ($iId, $iIdForTimeline, $iIdThumb, $sTitle, $sObjectStorage, $sObjectTranscoder, $sObjectVote, $sObjectReport, $sUriViewEntry, $sCommentsObject = '', $bEnableSocialSharing = true)
  527. {
  528. $sUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUriViewEntry . '&id=' . $iId);
  529. $sComments = '';
  530. if ($sCommentsObject && ($oComments = BxTemplCmts::getObjectInstance($sCommentsObject, $iId))) {
  531. $iNum = $oComments->getCommentsCountAll();
  532. $sComments = $this->_oTemplate->parseHtmlByName('comments-item.html', array (
  533. 'url' => $sUrl . '#' . $oComments->getListAnchor(),
  534. 'bx_if:comments' => array (
  535. 'condition' => $iNum,
  536. 'content' => array (
  537. 'num' => $iNum,
  538. ),
  539. ),
  540. ));
  541. }
  542. $aCustomParams = false;
  543. if ($iIdThumb && $bEnableSocialSharing) {
  544. if ($sObjectTranscoder)
  545. $o = BxDolTranscoder::getObjectInstance($sObjectTranscoder);
  546. else
  547. $o = BxDolStorage::getObjectInstance($sObjectStorage);
  548. if ($sImgUrl = $o->getFileUrlById($iIdThumb)) {
  549. $aCustomParams = array (
  550. 'img_url' => $sImgUrl,
  551. 'img_url_encoded' => rawurlencode($sImgUrl),
  552. );
  553. }
  554. }
  555. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
  556. $sVotes = '';
  557. $oVotes = BxDolVote::getObjectInstance($sObjectVote, $iId);
  558. if ($oVotes)
  559. $sVotes = $oVotes->getElementBlock(array('show_do_vote_as_button' => true));
  560. $sShare = '';
  561. if ($iIdForTimeline && BxDolRequest::serviceExists('bx_timeline', 'get_share_element_block'))
  562. $sShare = BxDolService::call('bx_timeline', 'get_share_element_block', array(bx_get_logged_profile_id(), $this->_aModule['name'], 'added', $iIdForTimeline, array('show_do_share_as_button' => true)));
  563. $sReport = '';
  564. $oReport = BxDolReport::getObjectInstance($sObjectReport, $iId);
  565. if ($oReport)
  566. $sReport = $oReport->getElementBlock(array('show_do_report_as_button' => true));
  567. $sSocial = $bEnableSocialSharing ? BxTemplSocialSharing::getInstance()->getCode($iId, $this->_aModule['name'], BX_DOL_URL_ROOT . $sUrl, $sTitle, $aCustomParams) : '';
  568. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  569. 'comments' => $sComments,
  570. 'vote' => $sVotes,
  571. 'share' => $sShare,
  572. 'report' => $sReport,
  573. 'social' => $sSocial,
  574. ));
  575. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
  576. }
  577. }
  578. /** @} */