BxBaseModGeneralModule.php 31 KB

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