BxBaseModGeneralMenuViewActions.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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('BxDolPrivacy');
  12. /**
  13. * View entry social actions menu
  14. */
  15. class BxBaseModGeneralMenuViewActions extends BxTemplMenuCustom
  16. {
  17. protected $_sModule;
  18. protected $_oModule;
  19. protected $_oMenuActions;
  20. protected $_oMenuActionsMore;
  21. protected $_oMenuSocialSharing;
  22. protected $_iContentId;
  23. protected $_aContentInfo;
  24. protected $_bDynamicMode;
  25. protected $_bShowAsButton;
  26. protected $_bShowTitle;
  27. protected $_sClassMiSa; // Separate class for Social Actions (View, Vote, Comment, Report, etc) menu items.
  28. public function __construct($aObject, $oTemplate = false)
  29. {
  30. parent::__construct($aObject, $oTemplate);
  31. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  32. $this->setContentId(bx_process_input(bx_get('id'), BX_DATA_INT));
  33. $this->_oMenuActions = null;
  34. $this->_oMenuActionsMore = null;
  35. $this->_oMenuSocialSharing = null;
  36. $this->_sTmplContent = $this->_oTemplate->getHtml($this->getTemplateName('menu_custom_actions.html'));
  37. $this->_sTmplContentItem = $this->_oTemplate->getHtml($this->getTemplateNameItem('menu_custom_item_actions.html'));
  38. $this->_bShowAsButton = true;
  39. $this->_bShowTitle = true;
  40. $this->_sClassMiSa = 'bx-base-general-ea-sa';
  41. $this->addMarkers(array(
  42. 'module' => $this->_oModule->_oConfig->getName(),
  43. 'module_uri' => $this->_oModule->_oConfig->getUri(),
  44. ));
  45. }
  46. public function addMarkers($a)
  47. {
  48. $bResult = parent::addMarkers($a);
  49. if($bResult) {
  50. if(empty($this->_oMenuSocialSharing))
  51. $this->_initMenuSocialSharing();
  52. //it still may be false in case the sys_social_sharing menu is turned off
  53. if (!empty($this->_oMenuSocialSharing)) {
  54. $this->_oMenuSocialSharing->addMarkers($a);
  55. parent::addMarkers($this->_oMenuSocialSharing->getMarkers());
  56. }
  57. }
  58. return $bResult;
  59. }
  60. public function setContentId($iContentId)
  61. {
  62. $this->_iContentId = (int)$iContentId;
  63. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iContentId);
  64. if($this->_aContentInfo)
  65. $this->addMarkers(array('content_id' => (int)$this->_iContentId));
  66. }
  67. public function setShowAsButton($bShowAsButton)
  68. {
  69. $this->_bShowAsButton = $bShowAsButton;
  70. }
  71. /**
  72. * Check if menu items is visible with extended checking linked to "allow*" method of particular module
  73. * Associated "allow*" method with particular menu item is stored in module config in MENU_ITEM_TO_METHOD array.
  74. * @param $a menu item array
  75. * @return boolean
  76. */
  77. protected function _isVisible($a)
  78. {
  79. if(!parent::_isVisible($a))
  80. return false;
  81. return $this->_oModule->isMenuItemVisible($this->_sObject, $a, $this->_aContentInfo);
  82. }
  83. protected function _isContentPublic($iContentId, $aPublicGroups = [])
  84. {
  85. $CNF = &$this->_oModule->_oConfig->CNF;
  86. if(empty($CNF['FIELD_ALLOW_VIEW_TO']))
  87. return true;
  88. $aContentInfo = $iContentId == $this->_iContentId ? $this->_aContentInfo : $this->_oModule->_oDb->getContentInfoById($iContentId);
  89. if(!isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  90. return true;
  91. if(empty($aPublicGroups))
  92. $aPublicGroups = [BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS];
  93. return in_array($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']], $aPublicGroups);
  94. }
  95. protected function _initMenuSocialSharing()
  96. {
  97. $this->_oMenuSocialSharing = BxDolMenu::getObjectInstance('sys_social_sharing');
  98. if(!$this->_oMenuSocialSharing)
  99. return false;
  100. /**
  101. * Adding current markers to social sharing menu object to force it to generate its own markers.
  102. * Getting generated social sharing markers back and adding all of them to current menu object. So, now these markers can be parsed for any menu item.
  103. */
  104. $this->_oMenuSocialSharing->addMarkers($this->_aMarkers);
  105. $this->addMarkers($this->_oMenuSocialSharing->getMarkers());
  106. return true;
  107. }
  108. protected function _getMenuItemDefault($aItem)
  109. {
  110. if(empty($this->_oMenuSocialSharing))
  111. $this->_initMenuSocialSharing();
  112. if(($mixedResult = $this->_rewriteMenuItem($aItem)) !== false)
  113. return $mixedResult;
  114. if($this->_bIsApi)
  115. return $aItem;
  116. $aItem['class_wrp'] = 'bx-base-general-entity-action' . (!empty($aItem['class_wrp']) ? ' ' . $aItem['class_wrp'] : '');
  117. if($this->_bShowAsButton)
  118. $aItem['class_link'] = 'bx-btn' . (isset($aItem['primary']) && (int)$aItem['primary'] == 1 ? ' bx-btn-primary' : '') . (!empty($aItem['class_link']) ? ' ' . $aItem['class_link'] : '');
  119. if(!$this->_bShowTitle)
  120. $aItem['bx_if:title']['condition'] = false;
  121. return parent::_getMenuItemDefault ($aItem);
  122. }
  123. protected function _getMenuItemDefaultApi($aItem)
  124. {
  125. if(($mixedResult = $this->_rewriteMenuItem($aItem)) !== false)
  126. return $mixedResult;
  127. return parent::_getMenuItemDefaultApi($aItem);
  128. }
  129. protected function _getMenuItemView($aItem, $aParams = array())
  130. {
  131. $CNF = &$this->_oModule->_oConfig->CNF;
  132. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  133. if(empty($sObject) && !empty($CNF['OBJECT_VIEWS']))
  134. $sObject = $CNF['OBJECT_VIEWS'];
  135. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  136. if(empty($iId))
  137. $iId = $this->_iContentId;
  138. $oObject = !empty($sObject) ? BxDolView::getObjectInstance($sObject, $iId) : false;
  139. if(!$oObject || !$oObject->isEnabled())
  140. return '';
  141. $aObjectOptions = array(
  142. 'dynamic_mode' => $this->_bDynamicMode,
  143. 'show_do_view_as_button' => $this->_bShowAsButton,
  144. 'show_do_view_label' => $this->_bShowTitle
  145. );
  146. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  147. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  148. if($this->_bIsApi)
  149. return $oObject->getElementApi($aObjectOptions);
  150. $sResult = $oObject->getElementBlock($aObjectOptions);
  151. if(empty($sResult))
  152. return '';
  153. return array($sResult, $this->_sClassMiSa);
  154. }
  155. protected function _getMenuItemComment($aItem, $aParams = array())
  156. {
  157. $CNF = &$this->_oModule->_oConfig->CNF;
  158. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  159. if(empty($sObject) && !empty($CNF['OBJECT_COMMENTS']))
  160. $sObject = $CNF['OBJECT_COMMENTS'];
  161. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  162. if(empty($iId))
  163. $iId = $this->_iContentId;
  164. $oObject = !empty($sObject) ? BxTemplCmts::getObjectInstance($sObject, $iId) : false;
  165. if(!$oObject || !$oObject->isEnabled())
  166. return '';
  167. $aObjectOptions = array(
  168. 'dynamic_mode' => $this->_bDynamicMode,
  169. 'show_do_comment_as_button' => $this->_bShowAsButton,
  170. 'show_do_comment_label' => $this->_bShowTitle,
  171. 'show_counter' => false
  172. );
  173. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  174. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  175. if($this->_bIsApi)
  176. return $oObject->getElementApi($aObjectOptions);
  177. $sResult = $oObject->getElementBlock($aObjectOptions);
  178. if(empty($sResult))
  179. return '';
  180. return array($sResult, $this->_sClassMiSa);
  181. }
  182. protected function _getMenuItemVote($aItem, $aParams = array())
  183. {
  184. $CNF = &$this->_oModule->_oConfig->CNF;
  185. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  186. if(empty($sObject) && !empty($CNF['OBJECT_VOTES']))
  187. $sObject = $CNF['OBJECT_VOTES'];
  188. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  189. if(empty($iId))
  190. $iId = $this->_iContentId;
  191. $oObject = !empty($sObject) ? BxDolVote::getObjectInstance($sObject, $iId) : false;
  192. if(!$oObject || !$oObject->isEnabled())
  193. return '';
  194. $aObjectOptions = array(
  195. 'dynamic_mode' => $this->_bDynamicMode,
  196. 'show_do_vote_as_button' => $this->_bShowAsButton,
  197. 'show_do_vote_label' => $this->_bShowTitle
  198. );
  199. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  200. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  201. if($this->_bIsApi)
  202. return [
  203. 'id' => $aItem['id'],
  204. 'name' => $aItem['name'],
  205. 'display_type' => 'element',
  206. 'data' => $oObject->getElementApi($aObjectOptions)
  207. ];
  208. $sResult = $oObject->getElementBlock($aObjectOptions);
  209. if(empty($sResult))
  210. return '';
  211. return array($sResult, $this->_sClassMiSa);
  212. }
  213. protected function _getMenuItemReaction($aItem, $aParams = array())
  214. {
  215. $CNF = &$this->_oModule->_oConfig->CNF;
  216. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  217. if(empty($sObject) && !empty($CNF['OBJECT_REACTIONS']))
  218. $sObject = $CNF['OBJECT_REACTIONS'];
  219. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  220. if(empty($iId))
  221. $iId = $this->_iContentId;
  222. $oObject = !empty($sObject) ? BxDolVote::getObjectInstance($sObject, $iId) : false;
  223. if(!$oObject || !$oObject->isEnabled())
  224. return '';
  225. $aObjectOptions = array(
  226. 'dynamic_mode' => $this->_bDynamicMode,
  227. 'show_do_vote_as_button' => $this->_bShowAsButton,
  228. 'show_do_vote_label' => $this->_bShowTitle
  229. );
  230. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  231. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  232. if($this->_bIsApi)
  233. return [
  234. 'id' => $aItem['id'],
  235. 'name' => $aItem['name'],
  236. 'display_type' => 'element',
  237. 'data' => $oObject->getElementApi($aObjectOptions)
  238. ];
  239. $sResult = $oObject->getElementBlock($aObjectOptions);
  240. if(empty($sResult))
  241. return '';
  242. return array($sResult, $this->_sClassMiSa);
  243. }
  244. protected function _getMenuItemScore($aItem, $aParams = array())
  245. {
  246. $CNF = &$this->_oModule->_oConfig->CNF;
  247. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  248. if(empty($sObject) && !empty($CNF['OBJECT_SCORES']))
  249. $sObject = $CNF['OBJECT_SCORES'];
  250. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  251. if(empty($iId))
  252. $iId = $this->_iContentId;
  253. $oObject = !empty($sObject) ? BxDolScore::getObjectInstance($sObject, $iId) : false;
  254. if(!$oObject || !$oObject->isEnabled())
  255. return '';
  256. $aObjectOptions = array(
  257. 'dynamic_mode' => $this->_bDynamicMode,
  258. 'show_do_vote_as_button' => $this->_bShowAsButton,
  259. 'show_do_vote_label' => $this->_bShowTitle
  260. );
  261. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  262. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  263. if($this->_bIsApi)
  264. return [
  265. 'id' => $aItem['id'],
  266. 'name' => $aItem['name'],
  267. 'display_type' => 'element',
  268. 'data' => $oObject->getElementApi($aObjectOptions)
  269. ];
  270. $sResult = $oObject->getElementBlock($aObjectOptions);
  271. if(empty($sResult))
  272. return '';
  273. return array($sResult, $this->_sClassMiSa);
  274. }
  275. protected function _getMenuItemFavorite($aItem, $aParams = array())
  276. {
  277. $CNF = &$this->_oModule->_oConfig->CNF;
  278. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  279. if(empty($sObject) && !empty($CNF['OBJECT_FAVORITES']))
  280. $sObject = $CNF['OBJECT_FAVORITES'];
  281. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  282. if(empty($iId))
  283. $iId = $this->_iContentId;
  284. $oObject = !empty($sObject) ? BxDolFavorite::getObjectInstance($sObject, $iId) : false;
  285. if(!$oObject || !$oObject->isEnabled())
  286. return '';
  287. $aObjectOptions = array(
  288. 'dynamic_mode' => $this->_bDynamicMode,
  289. 'show_do_favorite_as_button' => $this->_bShowAsButton,
  290. 'show_do_favorite_label' => $this->_bShowTitle
  291. );
  292. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  293. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  294. if($this->_bIsApi)
  295. return [
  296. 'id' => $aItem['id'],
  297. 'name' => $aItem['name'],
  298. 'display_type' => 'element',
  299. 'data' => $oObject->getElementApi($aObjectOptions)
  300. ];
  301. $sResult = $oObject->getElementBlock($aObjectOptions);
  302. if(empty($sResult))
  303. return '';
  304. return array($sResult, $this->_sClassMiSa);
  305. }
  306. protected function _getMenuItemFeature($aItem, $aParams = array())
  307. {
  308. $CNF = &$this->_oModule->_oConfig->CNF;
  309. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  310. if(empty($sObject) && !empty($CNF['OBJECT_FEATURED']))
  311. $sObject = $CNF['OBJECT_FEATURED'];
  312. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  313. if(empty($iId))
  314. $iId = $this->_iContentId;
  315. if(!$this->_isContentPublic($iId))
  316. return '';
  317. $oObject = !empty($sObject) ? BxDolFeature::getObjectInstance($sObject, $iId) : false;
  318. if(!$oObject || !$oObject->isEnabled())
  319. return '';
  320. $aObjectOptions = array(
  321. 'dynamic_mode' => $this->_bDynamicMode,
  322. 'show_do_feature_as_button' => $this->_bShowAsButton,
  323. 'show_do_feature_label' => $this->_bShowTitle
  324. );
  325. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  326. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  327. if($this->_bIsApi)
  328. return [
  329. 'id' => $aItem['id'],
  330. 'name' => $aItem['name'],
  331. 'display_type' => 'element',
  332. 'data' => $oObject->getElementApi($aObjectOptions)
  333. ];
  334. $sResult = $oObject->getElementBlock($aObjectOptions);
  335. if(empty($sResult))
  336. return '';
  337. return array($sResult, $this->_sClassMiSa);
  338. }
  339. protected function _getMenuItemRepost($aItem, $aParams = array())
  340. {
  341. $CNF = &$this->_oModule->_oConfig->CNF;
  342. $sAction = !empty($aParams['action']) ? $aParams['action'] : '';
  343. if(empty($sAction))
  344. $sAction = 'added';
  345. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  346. if(empty($iId))
  347. $iId = $this->_iContentId;
  348. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
  349. if(!empty($CNF['FIELD_PUBLISHED']) && isset($aContentInfo[$CNF['FIELD_PUBLISHED']]) && (int)$aContentInfo[$CNF['FIELD_PUBLISHED']] > time())
  350. return '';
  351. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] > 0 && !in_array((int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']], array(BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS)))
  352. return '';
  353. $sStatus = 'active';
  354. if(!empty($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] != $sStatus)
  355. return '';
  356. if(!empty($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != $sStatus)
  357. return '';
  358. $sRepostDo = !empty($aParams['do']) ? $aParams['do'] : 'repost';
  359. $aRepostParams = [
  360. 'do' => $sRepostDo,
  361. 'show_do_repost_as_button' => $this->_bShowAsButton,
  362. 'show_do_repost_text' => $this->_bShowTitle
  363. ];
  364. if(!empty($aItem['title']))
  365. $aRepostParams['text_do_' . $sRepostDo] = $aItem['title'];
  366. if(!empty($aItem['icon']))
  367. $aRepostParams['icon_do_' . $sRepostDo] = $aItem['icon'];
  368. $aSrvParams = [bx_get_logged_profile_id(), $this->_oModule->_oConfig->getName(), $sAction, $iId, $aRepostParams];
  369. if($this->_bIsApi && bx_is_srv('bx_timeline', 'get_repost_element_block_api'))
  370. return [
  371. 'id' => $aItem['id'],
  372. 'name' => $aItem['name'],
  373. 'display_type' => 'element',
  374. 'data' => bx_srv('bx_timeline', 'get_repost_element_block_api', $aSrvParams)
  375. ];
  376. if(!bx_is_srv('bx_timeline', 'get_repost_element_block'))
  377. return '';
  378. $sResult = bx_srv('bx_timeline', 'get_repost_element_block', $aSrvParams);
  379. if(empty($sResult))
  380. return '';
  381. return array($sResult, $this->_sClassMiSa);
  382. }
  383. protected function _getMenuItemRepostWithText($aItem, $aParams = [])
  384. {
  385. return $this->_getMenuItemRepost($aItem, array_merge($aParams, [
  386. 'do' => 'repost_with'
  387. ]));
  388. }
  389. protected function _getMenuItemRepostToContext($aItem, $aParams = [])
  390. {
  391. return $this->_getMenuItemRepost($aItem, array_merge($aParams, [
  392. 'do' => 'repost_to'
  393. ]));
  394. }
  395. protected function _getMenuItemReport($aItem, $aParams = array())
  396. {
  397. $CNF = &$this->_oModule->_oConfig->CNF;
  398. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  399. if(empty($sObject) && !empty($CNF['OBJECT_REPORTS']))
  400. $sObject = $CNF['OBJECT_REPORTS'];
  401. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  402. if(empty($iId))
  403. $iId = $this->_iContentId;
  404. $oObject = !empty($sObject) ? BxDolReport::getObjectInstance($sObject, $iId) : false;
  405. if(!$oObject || !$oObject->isEnabled())
  406. return '';
  407. $aObjectOptions = array(
  408. 'dynamic_mode' => $this->_bDynamicMode,
  409. 'show_do_report_as_button' => $this->_bShowAsButton,
  410. 'show_do_report_label' => $this->_bShowTitle
  411. );
  412. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  413. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  414. if($this->_bIsApi)
  415. return [
  416. 'id' => $aItem['id'],
  417. 'name' => $aItem['name'],
  418. 'display_type' => 'element',
  419. 'data' => $oObject->getElementApi($aObjectOptions)
  420. ];
  421. $sResult = $oObject->getElementBlock($aObjectOptions);
  422. if(empty($sResult))
  423. return '';
  424. return array($sResult, $this->_sClassMiSa);
  425. }
  426. protected function _getMenuItemSocialSharing($aItem, $aParams = array())
  427. {
  428. if(!$this->_bIsApi)
  429. return true;
  430. if(empty($this->_oMenuSocialSharing) && !$this->_initMenuSocialSharing())
  431. return [];
  432. return [
  433. 'id' => $aItem['id'],
  434. 'name' => $aItem['name'],
  435. 'display_type' => 'element',
  436. 'data' => [
  437. 'type' => 'shares',
  438. 'system' => $this->_sModule,
  439. 'object_id' => $this->_iContentId,
  440. 'params' => [],
  441. 'action' => [
  442. 'url' => bx_replace_markers('{url_encoded}', $this->_aMarkers)
  443. ]
  444. ]
  445. ];
  446. }
  447. protected function _getMenuItemNotes($aItem, $aParams = array())
  448. {
  449. $CNF = &$this->_oModule->_oConfig->CNF;
  450. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  451. if(empty($sObject) && !empty($CNF['OBJECT_NOTES']))
  452. $sObject = $CNF['OBJECT_NOTES'];
  453. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  454. if(empty($iId))
  455. $iId = $this->_iContentId;
  456. if(!$this->_oModule->_isModerator())
  457. return false;
  458. $this->addMarkers(array(
  459. 'content_id' => $iId
  460. ));
  461. return true;
  462. }
  463. protected function _getMenuItemByNameActions($aItem, $aParams = array())
  464. {
  465. $CNF = &$this->_oModule->_oConfig->CNF;
  466. if(empty($this->_oMenuActions)) {
  467. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  468. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']))
  469. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'];
  470. if(empty($sObjectMenu))
  471. return '';
  472. $this->_oMenuActions = BxDolMenu::getObjectInstance($sObjectMenu);
  473. if(!$this->_oMenuActions)
  474. return '';
  475. $this->_oMenuActions->setContentId($this->_iContentId);
  476. $this->_oMenuActions->addMarkers($this->getMarkers());
  477. $this->addMarkers($this->_oMenuActions->getMarkers());
  478. }
  479. $aItem = $this->_oMenuActions->getMenuItem($aItem['name']);
  480. if(empty($aItem) || !is_array($aItem))
  481. return false;
  482. if($this->_bIsApi)
  483. return $aItem;
  484. else
  485. return $this->_getMenuItemDefault($aItem);
  486. }
  487. protected function _getMenuItemByNameSocialSharing($aItem, $aParams = array())
  488. {
  489. if(empty($this->_oMenuSocialSharing) && !$this->_initMenuSocialSharing())
  490. return false;
  491. $aItem = $this->_oMenuSocialSharing->getMenuItem($aItem['name']);
  492. if(empty($aItem) || !is_array($aItem))
  493. return false;
  494. if($this->_bIsApi)
  495. return $aItem;
  496. else
  497. return $this->_getMenuItemDefault($aItem);
  498. }
  499. protected function _getMenuItemByNameActionDelete($aItem)
  500. {
  501. $oProfile = $this->_oModule->getProfileObject(($this->_iContentId));
  502. if (!$this->_oModule->isAllowDeleteOrDisable(bx_get_logged_profile_id(), $oProfile->id()))
  503. return false;
  504. return $this->_getMenuItemByNameActionsMore($aItem);
  505. }
  506. protected function _getMenuItemByNameActionsMore($aItem)
  507. {
  508. $CNF = &$this->_oModule->_oConfig->CNF;
  509. if(empty($this->_oMenuActionsMore)) {
  510. if(empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']))
  511. return '';
  512. $this->_oMenuActionsMore = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  513. if(!$this->_oMenuActionsMore)
  514. return '';
  515. $this->_oMenuActionsMore->setContentId($this->_iContentId);
  516. $this->addMarkers($this->_oMenuActionsMore->getMarkers());
  517. }
  518. $aItem = $this->_oMenuActionsMore->getMenuItem($aItem['name']);
  519. if(empty($aItem) || !is_array($aItem))
  520. return false;
  521. if($this->_bIsApi)
  522. return $aItem;
  523. else
  524. return $this->_getMenuItemDefault($aItem);
  525. }
  526. protected function _rewriteMenuItem($aItem, $aExtrasAddon = [])
  527. {
  528. return parent::_rewriteMenuItem($aItem, [
  529. 'module' => $this->_sModule,
  530. 'content_id' => $this->_iContentId,
  531. 'content_data' => $this->_aContentInfo,
  532. ]);
  533. }
  534. }
  535. /** @} */