BxBaseModGeneralMenuViewActions.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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 $_oMenuAction;
  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 && !empty($this->_oMenuSocialSharing))
  50. $this->_oMenuSocialSharing->addMarkers($a);
  51. return $bResult;
  52. }
  53. public function setContentId($iContentId)
  54. {
  55. $this->_iContentId = (int)$iContentId;
  56. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iContentId);
  57. if($this->_aContentInfo)
  58. $this->addMarkers(array('content_id' => (int)$this->_iContentId));
  59. }
  60. public function setShowAsButton($bShowAsButton)
  61. {
  62. $this->_bShowAsButton = $bShowAsButton;
  63. }
  64. /**
  65. * Check if menu items is visible with extended checking linked to "allow*" method of particular module
  66. * Associated "allow*" method with particular menu item is stored in module config in MENU_ITEM_TO_METHOD array.
  67. * @param $a menu item array
  68. * @return boolean
  69. */
  70. protected function _isVisible($a)
  71. {
  72. if(!parent::_isVisible($a))
  73. return false;
  74. return $this->_oModule->isMenuItemVisible($this->_sObject, $a, $this->_aContentInfo);
  75. }
  76. protected function _isContentPublic($iContentId)
  77. {
  78. $CNF = &$this->_oModule->_oConfig->CNF;
  79. if(empty($CNF['FIELD_ALLOW_VIEW_TO']))
  80. return true;
  81. $aContentInfo = $iContentId == $this->_iContentId ? $this->_aContentInfo : $this->_oModule->_oDb->getContentInfoById($iContentId);
  82. if(!isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  83. return true;
  84. return in_array($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']], array(BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS));
  85. }
  86. protected function _getMenuItemDefault($aItem)
  87. {
  88. if(empty($this->_oMenuSocialSharing)) {
  89. $this->_oMenuSocialSharing = BxDolMenu::getObjectInstance('sys_social_sharing');
  90. if($this->_oMenuSocialSharing) {
  91. $this->_oMenuSocialSharing->addMarkers($this->_aMarkers); // adding current markers to social sharing menu object to force it to generate its own markers
  92. $aSocialSharingMarkers = $this->_oMenuSocialSharing->getMarkers(); // getting generated social sharing markers back
  93. $this->addMarkers($aSocialSharingMarkers); // adding all of these to current menu object so now these markers can be parsed for any menu item
  94. }
  95. }
  96. $aItem['class_wrp'] = 'bx-base-general-entity-action' . (!empty($aItem['class_wrp']) ? ' ' . $aItem['class_wrp'] : '');
  97. if($this->_bShowAsButton)
  98. $aItem['class_link'] = 'bx-btn' . (isset($aItem['primary']) && (int)$aItem['primary'] == 1 ? ' bx-btn-primary' : '') . (!empty($aItem['class_link']) ? ' ' . $aItem['class_link'] : '');
  99. if(!$this->_bShowTitle)
  100. $aItem['bx_if:title']['condition'] = false;
  101. return parent::_getMenuItemDefault ($aItem);
  102. }
  103. protected function _getMenuItemView($aItem, $aParams = array())
  104. {
  105. $CNF = &$this->_oModule->_oConfig->CNF;
  106. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  107. if(empty($sObject) && !empty($CNF['OBJECT_VIEWS']))
  108. $sObject = $CNF['OBJECT_VIEWS'];
  109. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  110. if(empty($iId))
  111. $iId = $this->_iContentId;
  112. $oObject = !empty($sObject) ? BxDolView::getObjectInstance($sObject, $iId) : false;
  113. if(!$oObject || !$oObject->isEnabled())
  114. return '';
  115. $aObjectOptions = array(
  116. 'dynamic_mode' => $this->_bDynamicMode,
  117. 'show_do_view_as_button' => $this->_bShowAsButton,
  118. 'show_do_view_label' => $this->_bShowTitle
  119. );
  120. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  121. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  122. $sResult = $oObject->getElementBlock($aObjectOptions);
  123. if(empty($sResult))
  124. return '';
  125. return array($sResult, $this->_sClassMiSa);
  126. }
  127. protected function _getMenuItemComment($aItem, $aParams = array())
  128. {
  129. $CNF = &$this->_oModule->_oConfig->CNF;
  130. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  131. if(empty($sObject) && !empty($CNF['OBJECT_COMMENTS']))
  132. $sObject = $CNF['OBJECT_COMMENTS'];
  133. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  134. if(empty($iId))
  135. $iId = $this->_iContentId;
  136. $oObject = !empty($sObject) ? BxTemplCmts::getObjectInstance($sObject, $iId) : false;
  137. if(!$oObject || !$oObject->isEnabled())
  138. return '';
  139. $aObjectOptions = array(
  140. 'dynamic_mode' => $this->_bDynamicMode,
  141. 'show_do_comment_as_button' => $this->_bShowAsButton,
  142. 'show_do_comment_label' => $this->_bShowTitle,
  143. 'show_counter' => false
  144. );
  145. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  146. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  147. $sResult = $oObject->getElementBlock($aObjectOptions);
  148. if(empty($sResult))
  149. return '';
  150. return array($sResult, $this->_sClassMiSa);
  151. }
  152. protected function _getMenuItemVote($aItem, $aParams = array())
  153. {
  154. $CNF = &$this->_oModule->_oConfig->CNF;
  155. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  156. if(empty($sObject) && !empty($CNF['OBJECT_VOTES']))
  157. $sObject = $CNF['OBJECT_VOTES'];
  158. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  159. if(empty($iId))
  160. $iId = $this->_iContentId;
  161. $oObject = !empty($sObject) ? BxDolVote::getObjectInstance($sObject, $iId) : false;
  162. if(!$oObject || !$oObject->isEnabled())
  163. return '';
  164. $aObjectOptions = array(
  165. 'dynamic_mode' => $this->_bDynamicMode,
  166. 'show_do_vote_as_button' => $this->_bShowAsButton,
  167. 'show_do_vote_label' => $this->_bShowTitle
  168. );
  169. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  170. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  171. $sResult = $oObject->getElementBlock($aObjectOptions);
  172. if(empty($sResult))
  173. return '';
  174. return array($sResult, $this->_sClassMiSa);
  175. }
  176. protected function _getMenuItemReaction($aItem, $aParams = array())
  177. {
  178. $CNF = &$this->_oModule->_oConfig->CNF;
  179. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  180. if(empty($sObject) && !empty($CNF['OBJECT_REACTIONS']))
  181. $sObject = $CNF['OBJECT_REACTIONS'];
  182. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  183. if(empty($iId))
  184. $iId = $this->_iContentId;
  185. $oObject = !empty($sObject) ? BxDolVote::getObjectInstance($sObject, $iId) : false;
  186. if(!$oObject || !$oObject->isEnabled())
  187. return '';
  188. $aObjectOptions = array(
  189. 'dynamic_mode' => $this->_bDynamicMode,
  190. 'show_do_vote_as_button' => $this->_bShowAsButton,
  191. 'show_do_vote_label' => $this->_bShowTitle
  192. );
  193. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  194. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  195. $sResult = $oObject->getElementBlock($aObjectOptions);
  196. if(empty($sResult))
  197. return '';
  198. return array($sResult, $this->_sClassMiSa);
  199. }
  200. protected function _getMenuItemScore($aItem, $aParams = array())
  201. {
  202. $CNF = &$this->_oModule->_oConfig->CNF;
  203. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  204. if(empty($sObject) && !empty($CNF['OBJECT_SCORES']))
  205. $sObject = $CNF['OBJECT_SCORES'];
  206. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  207. if(empty($iId))
  208. $iId = $this->_iContentId;
  209. $oObject = !empty($sObject) ? BxDolScore::getObjectInstance($sObject, $iId) : false;
  210. if(!$oObject || !$oObject->isEnabled())
  211. return '';
  212. $aObjectOptions = array(
  213. 'dynamic_mode' => $this->_bDynamicMode,
  214. 'show_do_vote_as_button' => $this->_bShowAsButton,
  215. 'show_do_vote_label' => $this->_bShowTitle
  216. );
  217. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  218. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  219. $sResult = $oObject->getElementBlock($aObjectOptions);
  220. if(empty($sResult))
  221. return '';
  222. return array($sResult, $this->_sClassMiSa);
  223. }
  224. protected function _getMenuItemFavorite($aItem, $aParams = array())
  225. {
  226. $CNF = &$this->_oModule->_oConfig->CNF;
  227. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  228. if(empty($sObject) && !empty($CNF['OBJECT_FAVORITES']))
  229. $sObject = $CNF['OBJECT_FAVORITES'];
  230. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  231. if(empty($iId))
  232. $iId = $this->_iContentId;
  233. $oObject = !empty($sObject) ? BxDolFavorite::getObjectInstance($sObject, $iId) : false;
  234. if(!$oObject || !$oObject->isEnabled())
  235. return '';
  236. $aObjectOptions = array(
  237. 'dynamic_mode' => $this->_bDynamicMode,
  238. 'show_do_favorite_as_button' => $this->_bShowAsButton,
  239. 'show_do_favorite_label' => $this->_bShowTitle
  240. );
  241. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  242. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  243. $sResult = $oObject->getElementBlock($aObjectOptions);
  244. if(empty($sResult))
  245. return '';
  246. return array($sResult, $this->_sClassMiSa);
  247. }
  248. protected function _getMenuItemFeature($aItem, $aParams = array())
  249. {
  250. $CNF = &$this->_oModule->_oConfig->CNF;
  251. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  252. if(empty($sObject) && !empty($CNF['OBJECT_FEATURED']))
  253. $sObject = $CNF['OBJECT_FEATURED'];
  254. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  255. if(empty($iId))
  256. $iId = $this->_iContentId;
  257. if(!$this->_isContentPublic($iId))
  258. return '';
  259. $oObject = !empty($sObject) ? BxDolFeature::getObjectInstance($sObject, $iId) : false;
  260. if(!$oObject || !$oObject->isEnabled())
  261. return '';
  262. $aObjectOptions = array(
  263. 'dynamic_mode' => $this->_bDynamicMode,
  264. 'show_do_feature_as_button' => $this->_bShowAsButton,
  265. 'show_do_feature_label' => $this->_bShowTitle
  266. );
  267. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  268. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  269. $sResult = $oObject->getElementBlock($aObjectOptions);
  270. if(empty($sResult))
  271. return '';
  272. return array($sResult, $this->_sClassMiSa);
  273. }
  274. protected function _getMenuItemRepost($aItem, $aParams = array())
  275. {
  276. $CNF = &$this->_oModule->_oConfig->CNF;
  277. $sAction = !empty($aParams['action']) ? $aParams['action'] : '';
  278. if(empty($sAction))
  279. $sAction = 'added';
  280. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  281. if(empty($iId))
  282. $iId = $this->_iContentId;
  283. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
  284. if(!empty($CNF['FIELD_PUBLISHED']) && isset($aContentInfo[$CNF['FIELD_PUBLISHED']]) && (int)$aContentInfo[$CNF['FIELD_PUBLISHED']] > time())
  285. return '';
  286. 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)))
  287. return '';
  288. $sStatus = 'active';
  289. if(!empty($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] != $sStatus)
  290. return '';
  291. if(!empty($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != $sStatus)
  292. return '';
  293. if(!BxDolRequest::serviceExists('bx_timeline', 'get_repost_element_block'))
  294. return '';
  295. $sResult = BxDolService::call('bx_timeline', 'get_repost_element_block', array(bx_get_logged_profile_id(), $this->_oModule->_oConfig->getName(), $sAction, $iId, array(
  296. 'show_do_repost_as_button' => $this->_bShowAsButton,
  297. 'show_do_repost_text' => $this->_bShowTitle
  298. )));
  299. if(empty($sResult))
  300. return '';
  301. return array($sResult, $this->_sClassMiSa);
  302. }
  303. protected function _getMenuItemReport($aItem, $aParams = array())
  304. {
  305. $CNF = &$this->_oModule->_oConfig->CNF;
  306. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  307. if(empty($sObject) && !empty($CNF['OBJECT_REPORTS']))
  308. $sObject = $CNF['OBJECT_REPORTS'];
  309. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  310. if(empty($iId))
  311. $iId = $this->_iContentId;
  312. $oObject = !empty($sObject) ? BxDolReport::getObjectInstance($sObject, $iId) : false;
  313. if(!$oObject || !$oObject->isEnabled())
  314. return '';
  315. $aObjectOptions = array(
  316. 'dynamic_mode' => $this->_bDynamicMode,
  317. 'show_do_report_as_button' => $this->_bShowAsButton,
  318. 'show_do_report_label' => $this->_bShowTitle
  319. );
  320. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  321. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  322. $sResult = $oObject->getElementBlock($aObjectOptions);
  323. if(empty($sResult))
  324. return '';
  325. return array($sResult, $this->_sClassMiSa);
  326. }
  327. protected function _getMenuItemNotes($aItem, $aParams = array())
  328. {
  329. $CNF = &$this->_oModule->_oConfig->CNF;
  330. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  331. if(empty($sObject) && !empty($CNF['OBJECT_NOTES']))
  332. $sObject = $CNF['OBJECT_NOTES'];
  333. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  334. if(empty($iId))
  335. $iId = $this->_iContentId;
  336. if(!$this->_oModule->_isModerator())
  337. return false;
  338. $this->addMarkers(array(
  339. 'content_id' => $iId
  340. ));
  341. return true;
  342. }
  343. protected function _getMenuItemByNameActions($aItem, $aParams = array())
  344. {
  345. $CNF = &$this->_oModule->_oConfig->CNF;
  346. if(empty($this->_oMenuActions)) {
  347. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  348. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']))
  349. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'];
  350. if(empty($sObjectMenu))
  351. return '';
  352. $this->_oMenuActions = BxDolMenu::getObjectInstance($sObjectMenu);
  353. if(!$this->_oMenuActions)
  354. return '';
  355. $this->_oMenuActions->setContentId($this->_iContentId);
  356. $this->addMarkers($this->_oMenuActions->getMarkers());
  357. }
  358. $aItem = $this->_oMenuActions->getMenuItem($aItem['name']);
  359. if(empty($aItem) || !is_array($aItem))
  360. return false;
  361. return $this->_getMenuItemDefault($aItem);
  362. }
  363. protected function _getMenuItemByNameSocialSharing($aItem, $aParams = array())
  364. {
  365. if(empty($this->_oMenuSocialSharing)) {
  366. $this->_oMenuSocialSharing = BxDolMenu::getObjectInstance('sys_social_sharing');
  367. if(!$this->_oMenuSocialSharing)
  368. return false;
  369. $this->_oMenuSocialSharing->addMarkers($this->_aMarkers);
  370. $this->addMarkers($this->_oMenuSocialSharing->getMarkers());
  371. }
  372. $aItem = $this->_oMenuSocialSharing->getMenuItem($aItem['name']);
  373. if(empty($aItem) || !is_array($aItem))
  374. return false;
  375. return $this->_getMenuItemDefault($aItem);
  376. }
  377. protected function _getMenuItemByNameActionDelete($aItem)
  378. {
  379. $oProfile = $this->_oModule->getProfileObject(($this->_iContentId));
  380. if (!$this->_oModule->isAllowDeleteOrDisable(bx_get_logged_profile_id(), $oProfile->id()))
  381. return false;
  382. return $this->_getMenuItemByNameActionsMore($aItem);
  383. }
  384. protected function _getMenuItemByNameActionsMore($aItem)
  385. {
  386. $CNF = &$this->_oModule->_oConfig->CNF;
  387. if(empty($this->_oMenuActionsMore)) {
  388. if(empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']))
  389. return '';
  390. $this->_oMenuActionsMore = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  391. if(!$this->_oMenuActionsMore)
  392. return '';
  393. $this->_oMenuActionsMore->setContentId($this->_iContentId);
  394. $this->addMarkers($this->_oMenuActionsMore->getMarkers());
  395. }
  396. $aItem = $this->_oMenuActionsMore->getMenuItem($aItem['name']);
  397. if(empty($aItem) || !is_array($aItem))
  398. return false;
  399. return $this->_getMenuItemDefault($aItem);
  400. }
  401. }
  402. /** @} */