1
0

BxBaseModGeneralModule.php 29 KB

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