1
0

BxBaseModGeneralModule.php 27 KB

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