1
0

BxBaseModGeneralModule.php 29 KB

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