1
0

BxBaseModGeneralModule.php 30 KB

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