1
0

BxBaseModGeneralModule.php 25 KB

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