1
0

BxBaseModGeneralModule.php 26 KB

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