BxBaseModGeneralModule.php 27 KB

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