BxBaseModGeneralModule.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  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. /**
  91. * Display entries favored by a member
  92. * @return HTML string
  93. */
  94. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  95. {
  96. $oProfile = null;
  97. if((int)$iProfileId)
  98. $oProfile = BxDolProfile::getInstance($iProfileId);
  99. if(!$oProfile && bx_get('profile_id') !== false)
  100. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  101. if(!$oProfile)
  102. $oProfile = BxDolProfile::getInstance();
  103. if(!$oProfile)
  104. return '';
  105. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, true);
  106. }
  107. public function serviceFormsHelper ()
  108. {
  109. bx_import('FormsEntryHelper', $this->_aModule);
  110. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  111. return new $sClass($this);
  112. }
  113. /**
  114. * Add entry form
  115. * @return HTML string
  116. */
  117. public function serviceEntityCreate ()
  118. {
  119. bx_import('FormsEntryHelper', $this->_aModule);
  120. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  121. $oFormsHelper = new $sClass($this);
  122. return $oFormsHelper->addDataForm();
  123. }
  124. public function serviceEntityEdit ($iContentId = 0)
  125. {
  126. return $this->_serviceEntityForm ('editDataForm', $iContentId);
  127. }
  128. public function serviceEntityDelete ($iContentId = 0)
  129. {
  130. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  131. }
  132. public function serviceEntityTextBlock ($iContentId = 0)
  133. {
  134. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  135. }
  136. public function serviceEntityInfo ($iContentId = 0)
  137. {
  138. return $this->_serviceEntityForm ('viewDataForm', $iContentId);
  139. }
  140. public function serviceEntityInfoFull ($iContentId = 0)
  141. {
  142. $CNF = &$this->_oConfig->CNF;
  143. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  144. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  145. }
  146. public function serviceEntityInfoExtended ($iContentId = 0)
  147. {
  148. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  149. }
  150. /**
  151. * Entry location info
  152. */
  153. public function serviceEntityLocation ($iContentId = 0)
  154. {
  155. if (!$iContentId)
  156. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  157. if (!$iContentId)
  158. return false;
  159. return $this->_oTemplate->entryLocation ($iContentId);
  160. }
  161. /**
  162. * Delete content entry
  163. * @param $iContentId content id
  164. * @return error message or empty string on success
  165. */
  166. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  167. {
  168. bx_import('FormsEntryHelper', $this->_aModule);
  169. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  170. $oFormsHelper = new $sClass($this);
  171. return $oFormsHelper->$sFuncDelete($iContentId);
  172. }
  173. /**
  174. * Entry actions and social sharing block
  175. */
  176. public function serviceEntityAllActions ($iContentId = 0)
  177. {
  178. return $this->_oTemplate->entryAllActions('', $this->serviceEntitySocialSharing($iContentId));
  179. }
  180. /**
  181. * Entry actions block
  182. */
  183. public function serviceEntityActions ($iContentId = 0)
  184. {
  185. if (!$iContentId)
  186. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  187. if (!$iContentId)
  188. return false;
  189. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  190. return $oMenu ? $oMenu->getCode() : false;
  191. }
  192. /**
  193. * Entry social sharing block
  194. */
  195. public function serviceEntitySocialSharing ($iContentId = 0)
  196. {
  197. if (!$iContentId)
  198. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  199. if (!$iContentId)
  200. return false;
  201. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  202. if (!$aContentInfo)
  203. return false;
  204. $CNF = &$this->_oConfig->CNF;
  205. return $this->_entitySocialSharing ($iContentId, array(
  206. 'id_timeline' => $iContentId,
  207. 'id_thumb' => !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : '',
  208. 'title' => !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  209. 'object_storage' => !empty($CNF['OBJECT_STORAGE']) ? $CNF['OBJECT_STORAGE'] : '',
  210. 'object_transcoder' => false,
  211. 'object_vote' => !empty($CNF['OBJECT_VOTES']) ? $CNF['OBJECT_VOTES'] : '',
  212. 'object_favorite' => !empty($CNF['OBJECT_FAVORITES']) ? $CNF['OBJECT_FAVORITES'] : '',
  213. 'object_report' => !empty($CNF['OBJECT_REPORTS']) ? $CNF['OBJECT_REPORTS'] : '',
  214. 'uri_view_entry' => !empty($CNF['URI_VIEW_ENTRY']) ? $CNF['URI_VIEW_ENTRY'] : '',
  215. ));
  216. }
  217. /**
  218. * Data for Notifications module
  219. */
  220. public function serviceGetNotificationsData()
  221. {
  222. $sModule = $this->_aModule['name'];
  223. $sEventPrivacy = $sModule . '_allow_view_event_to';
  224. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  225. $sEventPrivacy = '';
  226. return array(
  227. 'handlers' => array(
  228. 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),
  229. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  230. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  231. 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),
  232. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  233. 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),
  234. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  235. ),
  236. 'alerts' => array(
  237. array('unit' => $sModule, 'action' => 'added'),
  238. array('unit' => $sModule, 'action' => 'edited'),
  239. array('unit' => $sModule, 'action' => 'deleted'),
  240. array('unit' => $sModule, 'action' => 'commentPost'),
  241. array('unit' => $sModule, 'action' => 'commentRemoved'),
  242. array('unit' => $sModule, 'action' => 'doVote'),
  243. array('unit' => $sModule, 'action' => 'undoVote'),
  244. )
  245. );
  246. }
  247. /**
  248. * Entry post for Notifications module
  249. */
  250. public function serviceGetNotificationsPost($aEvent)
  251. {
  252. $CNF = &$this->_oConfig->CNF;
  253. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  254. if(empty($aContentInfo) || !is_array($aContentInfo))
  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. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  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 comment for Notifications module
  269. */
  270. public function serviceGetNotificationsComment($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. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  278. if(!$oComment || !$oComment->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_comment_single'],
  288. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  289. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  290. );
  291. }
  292. /**
  293. * Entry post vote for Notifications module
  294. */
  295. public function serviceGetNotificationsVote($aEvent)
  296. {
  297. $CNF = &$this->_oConfig->CNF;
  298. $iContentId = (int)$aEvent['object_id'];
  299. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  300. if(empty($aContentInfo) || !is_array($aContentInfo))
  301. return array();
  302. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  303. if(!$oVote || !$oVote->isEnabled())
  304. return array();
  305. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  306. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  307. return array(
  308. 'entry_sample' => $CNF['T']['txt_sample_single'],
  309. 'entry_url' => $sEntryUrl,
  310. 'entry_caption' => $sEntryCaption,
  311. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  312. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  313. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  314. );
  315. }
  316. public function _serviceGetNotification($aEvent, $sLangKey)
  317. {
  318. $CNF = &$this->_oConfig->CNF;
  319. $iContentId = (int)$aEvent['object_id'];
  320. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  321. if (!$oGroupProfile)
  322. return false;
  323. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  324. if(empty($aContentInfo) || !is_array($aContentInfo))
  325. return array();
  326. $oProfile = BxDolProfile::getInstance((int)$aEvent['subobject_id']);
  327. if (!$oProfile)
  328. return false;
  329. return array(
  330. 'entry_sample' => $CNF['T']['txt_sample_single'],
  331. 'entry_url' => $oGroupProfile->getUrl(),
  332. 'entry_caption' => $oGroupProfile->getDisplayName(),
  333. 'entry_author' => $oGroupProfile->id(),
  334. 'subentry_sample' => $oProfile->getDisplayName(),
  335. 'subentry_url' => $oProfile->getUrl(),
  336. 'lang_key' => $sLangKey,
  337. );
  338. }
  339. /**
  340. * Data for Timeline module
  341. */
  342. public function serviceGetTimelineData()
  343. {
  344. $sModule = $this->_aModule['name'];
  345. return array(
  346. 'handlers' => array(
  347. 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' => ''),
  348. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  349. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  350. ),
  351. 'alerts' => array(
  352. array('unit' => $sModule, 'action' => 'added'),
  353. array('unit' => $sModule, 'action' => 'edited'),
  354. array('unit' => $sModule, 'action' => 'deleted'),
  355. )
  356. );
  357. }
  358. /**
  359. * Entry post for Timeline module
  360. */
  361. public function serviceGetTimelinePost($aEvent)
  362. {
  363. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  364. if(empty($aContentInfo) || !is_array($aContentInfo))
  365. return '';
  366. $CNF = &$this->_oConfig->CNF;
  367. //--- Votes
  368. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aEvent['object_id']) : null;
  369. $aVotes = array();
  370. if ($oVotes && $oVotes->isEnabled())
  371. $aVotes = array(
  372. 'system' => $CNF['OBJECT_VOTES'],
  373. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  374. 'count' => $aContentInfo['votes']
  375. );
  376. //--- Reports
  377. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aEvent['object_id']) : null;
  378. $aReports = array();
  379. if ($oReports && $oReports->isEnabled())
  380. $aReports = array(
  381. 'system' => $CNF['OBJECT_REPORTS'],
  382. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  383. 'count' => $aContentInfo['reports']
  384. );
  385. //--- Comments
  386. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']) : null;
  387. $aComments = array();
  388. if($oCmts && $oCmts->isEnabled())
  389. $aComments = array(
  390. 'system' => $CNF['OBJECT_COMMENTS'],
  391. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  392. 'count' => $aContentInfo['comments']
  393. );
  394. return array(
  395. 'owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  396. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  397. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  398. 'sample_action' => isset($CNF['T']['txt_sample_single_action']) ? $CNF['T']['txt_sample_single_action'] : '',
  399. 'content' => $this->_getContentForTimelinePost($aEvent, $aContentInfo), //a string to display or array to parse default template before displaying.
  400. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  401. 'votes' => $aVotes,
  402. 'reports' => $aReports,
  403. 'comments' => $aComments,
  404. 'title' => '', //may be empty.
  405. 'description' => '' //may be empty.
  406. );
  407. }
  408. // ====== PERMISSION METHODS
  409. /**
  410. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  411. */
  412. public function checkAllowedBrowse ()
  413. {
  414. return CHECK_ACTION_RESULT_ALLOWED;
  415. }
  416. /**
  417. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  418. */
  419. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  420. {
  421. $CNF = &$this->_oConfig->CNF;
  422. // moderator and owner always have access
  423. if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  424. return CHECK_ACTION_RESULT_ALLOWED;
  425. // check ACL
  426. $aCheck = checkActionModule($this->_iProfileId, 'view entry', $this->getName(), $isPerformAction);
  427. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  428. return $aCheck[CHECK_ACTION_MESSAGE];
  429. // check privacy
  430. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  431. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  432. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]))
  433. return _t('_sys_access_denied_to_private_content');
  434. }
  435. return CHECK_ACTION_RESULT_ALLOWED;
  436. }
  437. /**
  438. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  439. */
  440. public function checkAllowedAdd ($isPerformAction = false)
  441. {
  442. // check ACL
  443. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  444. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  445. return $aCheck[CHECK_ACTION_MESSAGE];
  446. return CHECK_ACTION_RESULT_ALLOWED;
  447. }
  448. /**
  449. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  450. */
  451. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  452. {
  453. // moderator and owner always have access
  454. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  455. return CHECK_ACTION_RESULT_ALLOWED;
  456. return _t('_sys_txt_access_denied');
  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 checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  462. {
  463. // moderator always has access
  464. if ($this->_isModerator($isPerformAction))
  465. return CHECK_ACTION_RESULT_ALLOWED;
  466. // check ACL
  467. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  468. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  469. return CHECK_ACTION_RESULT_ALLOWED;
  470. return _t('_sys_txt_access_denied');
  471. }
  472. /**
  473. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  474. */
  475. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  476. {
  477. // admin always has access
  478. if (isAdmin())
  479. return CHECK_ACTION_RESULT_ALLOWED;
  480. // check ACL
  481. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  482. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  483. return $aCheck[CHECK_ACTION_MESSAGE];
  484. return CHECK_ACTION_RESULT_ALLOWED;
  485. }
  486. /**
  487. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  488. */
  489. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  490. {
  491. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  492. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  493. return CHECK_ACTION_RESULT_ALLOWED;
  494. return _t('_sys_txt_access_denied');
  495. }
  496. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  497. {
  498. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  499. return MsgBox($sMsg);
  500. bx_import($sClassSearchResult, $this->_aModule);
  501. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  502. $o = new $sClass($sMode, $aParams);
  503. $o->setDesignBoxTemplateId($iDesignBox);
  504. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  505. $o->setAjaxPaginate($bAjaxPaginate);
  506. $o->setUnitParams(array('context' => $sMode));
  507. if ($o->isError)
  508. return '';
  509. if ($s = $o->processing())
  510. return $s;
  511. else
  512. return '';
  513. }
  514. // ====== COMMON METHODS
  515. public function getProfileId()
  516. {
  517. return bx_get_logged_profile_id();
  518. }
  519. public function getProfileInfo($iUserId = 0)
  520. {
  521. $oProfile = $this->getObjectUser($iUserId);
  522. $oAccount = $oProfile->getAccountObject();
  523. return array(
  524. 'id' => $oProfile->id(),
  525. 'name' => $oProfile->getDisplayName(),
  526. 'email' => $oAccount->getEmail(),
  527. 'link' => $oProfile->getUrl(),
  528. 'icon' => $oProfile->getIcon(),
  529. 'unit' => $oProfile->getUnit(),
  530. 'active' => $oProfile->isActive(),
  531. );
  532. }
  533. public function getObjectUser($iUserId = 0)
  534. {
  535. bx_import('BxDolProfile');
  536. $oProfile = BxDolProfile::getInstance($iUserId);
  537. if (!$oProfile) {
  538. bx_import('BxDolProfileUndefined');
  539. $oProfile = BxDolProfileUndefined::getInstance();
  540. }
  541. return $oProfile;
  542. }
  543. public function getObjectFavorite($sSystem = '', $iId = 0)
  544. {
  545. $CNF = &$this->_oConfig->CNF;
  546. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  547. $sSystem = $CNF['OBJECT_FAVORITES'];
  548. if(empty($sSystem))
  549. return false;
  550. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  551. if(!$oFavorite->isEnabled())
  552. return false;
  553. return $oFavorite;
  554. }
  555. public function getUserId()
  556. {
  557. return isLogged() ? bx_get_logged_profile_id() : 0;
  558. }
  559. public function getUserIp()
  560. {
  561. return getVisitorIP();
  562. }
  563. public function getUserInfo($iUserId = 0)
  564. {
  565. $oProfile = BxDolProfile::getInstance($iUserId);
  566. if (!$oProfile)
  567. $oProfile = BxDolProfileUndefined::getInstance();
  568. return array(
  569. $oProfile->getDisplayName(),
  570. $oProfile->getUrl(),
  571. $oProfile->getThumb(),
  572. $oProfile->getUnit()
  573. );
  574. }
  575. // ====== PROTECTED METHODS
  576. protected function _isModerator ($isPerformAction = false)
  577. {
  578. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
  579. }
  580. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false)
  581. {
  582. if (!$iContentId)
  583. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  584. if (!$iContentId)
  585. return false;
  586. bx_import('FormsEntryHelper', $this->_aModule);
  587. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  588. $oFormsHelper = new $sClass($this);
  589. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay);
  590. }
  591. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  592. {
  593. if (!$iContentId)
  594. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  595. if (!$iContentId)
  596. return false;
  597. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  598. if (!$aContentInfo)
  599. return false;
  600. return $this->_oTemplate->$sFunc($aContentInfo);
  601. }
  602. protected function _rss ($aArgs, $sClass = 'SearchResult')
  603. {
  604. $sMode = array_shift($aArgs);
  605. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  606. $this->_oTemplate->displayAccessDenied ($sMsg);
  607. exit;
  608. }
  609. $aParams = $this->_buildRssParams($sMode, $aArgs);
  610. bx_import ($sClass, $this->_aModule);
  611. $sClass = $this->_aModule['class_prefix'] . $sClass;
  612. $o = new $sClass($sMode, $aParams);
  613. if ($o->isError)
  614. $this->_oTemplate->displayPageNotFound ();
  615. else
  616. $o->outputRSS();
  617. exit;
  618. }
  619. protected function _getContentForTimelinePost($aEvent, $aContentInfo)
  620. {
  621. $CNF = &$this->_oConfig->CNF;
  622. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  623. //--- Image(s)
  624. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl);
  625. return array(
  626. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  627. 'sample_action' => isset($CNF['T']['txt_sample_single_action']) ? $CNF['T']['txt_sample_single_action'] : '',
  628. 'url' => $sUrl,
  629. 'title' => isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] :
  630. (isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...') : ''),
  631. 'text' => isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '',
  632. 'images' => $aImages,
  633. );
  634. }
  635. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl)
  636. {
  637. $CNF = &$this->_oConfig->CNF;
  638. $sImage = '';
  639. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
  640. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_COVER'])) {
  641. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_COVER']);
  642. if($oTranscoder)
  643. $sImage = $oTranscoder->getFileUrl($aContentInfo[$CNF['FIELD_COVER']]);
  644. }
  645. if($sImage == '' && !empty($CNF['OBJECT_IMAGES_TRANSCODER_THUMB'])) {
  646. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_THUMB']);
  647. if($oTranscoder)
  648. $sImage = $oTranscoder->getFileUrl($aContentInfo[$CNF['FIELD_COVER']]);
  649. }
  650. }
  651. if($sImage == '' && isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']]) {
  652. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_THUMB'])) {
  653. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_THUMB']);
  654. if($oTranscoder)
  655. $sImage = $oTranscoder->getFileUrl($aContentInfo[$CNF['FIELD_THUMB']]);
  656. }
  657. if($sImage == '' && !empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'])) {
  658. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  659. if($oTranscoder)
  660. $sImage = $oTranscoder->getFileUrl($aContentInfo[$CNF['FIELD_THUMB']]);
  661. }
  662. }
  663. if(empty($sImage))
  664. return array();
  665. return array(
  666. array('url' => $sUrl, 'src' => $sImage),
  667. );
  668. }
  669. protected function _entitySocialSharing ($iId, $aParams = array())
  670. {
  671. $sUrl = !empty($aParams['uri_view_entry']) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $aParams['uri_view_entry'] . '&id=' . $iId) : '';
  672. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  673. //--- Comments
  674. $sComments = '';
  675. $oComments = !empty($aParams['object_comments']) ? BxTemplCmts::getObjectInstance($aParams['object_comments'], $iId) : false;
  676. if ($oComments) {
  677. $iNum = $oComments->getCommentsCountAll();
  678. $sComments = $this->_oTemplate->parseHtmlByName('comments-item.html', array (
  679. 'url' => $sUrl . '#' . $oComments->getListAnchor(),
  680. 'bx_if:comments' => array (
  681. 'condition' => $iNum,
  682. 'content' => array (
  683. 'num' => $iNum,
  684. ),
  685. ),
  686. ));
  687. }
  688. $aCustomParams = false;
  689. $iIdThumb = isset($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  690. $bSocialSharing = isset($aParams['social_sharing']) ? (bool)$aParams['social_sharing'] : true;
  691. if ($iIdThumb && $bSocialSharing) {
  692. if(!empty($aParams['object_transcoder']))
  693. $o = BxDolTranscoder::getObjectInstance($aParams['object_transcoder']);
  694. else if(!empty($aParams['object_storage']))
  695. $o = BxDolStorage::getObjectInstance($aParams['object_storage']);
  696. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  697. if($sImgUrl)
  698. $aCustomParams = array (
  699. 'img_url' => $sImgUrl,
  700. 'img_url_encoded' => rawurlencode($sImgUrl),
  701. );
  702. }
  703. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
  704. //--- Votes
  705. $sVotes = '';
  706. $oVotes = !empty($aParams['object_vote']) ? BxDolVote::getObjectInstance($aParams['object_vote'], $iId) : false;
  707. if ($oVotes)
  708. $sVotes = $oVotes->getElementBlock(array('show_do_vote_as_button' => true));
  709. //--- Favorite
  710. $sFavorites = '';
  711. $oFavorites = !empty($aParams['object_favorite']) ? BxDolFavorite::getObjectInstance($aParams['object_favorite'], $iId) : false;
  712. if ($oFavorites)
  713. $sFavorites = $oFavorites->getElementBlock(array('show_do_favorite_as_button' => true));
  714. //--- Timeline Repost (Internal Share)
  715. $sShare = '';
  716. $iIdTimeline = isset($aParams['id_timeline']) ? (int)$aParams['id_timeline'] : $iId;
  717. if ($iIdTimeline && BxDolRequest::serviceExists('bx_timeline', 'get_share_element_block'))
  718. $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)));
  719. //--- Report
  720. $sReport = '';
  721. $oReport = !empty($aParams['object_report']) ? BxDolReport::getObjectInstance($aParams['object_report'], $iId) : false;
  722. if ($oReport)
  723. $sReport = $oReport->getElementBlock(array('show_do_report_as_button' => true));
  724. $sSocial = $bSocialSharing ? BxTemplSocialSharing::getInstance()->getCode($iId, $this->_aModule['name'], BX_DOL_URL_ROOT . $sUrl, $sTitle, $aCustomParams) : '';
  725. if(empty($sComments) && empty($sVotes) && empty($sFavorites) && empty($sShare) && empty($sReport) && empty($sSocial))
  726. return '';
  727. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  728. 'comments' => $sComments,
  729. 'vote' => $sVotes,
  730. 'favorite' => $sFavorites,
  731. 'share' => $sShare,
  732. 'report' => $sReport,
  733. 'social' => $sSocial,
  734. ));
  735. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
  736. }
  737. }
  738. /** @} */