BxBaseModGeneralModule.php 37 KB

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