BxBaseModGeneralMenuViewActions.php 19 KB

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