BxBaseModGeneralMenuViewActions.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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->_bShowAsButton = true;
  37. $this->_bShowTitle = true;
  38. $this->_sClassMiSa = 'bx-base-general-ea-sa';
  39. }
  40. public function addMarkers($a)
  41. {
  42. $bResult = parent::addMarkers($a);
  43. if($bResult && !empty($this->_oMenuSocialSharing))
  44. $this->_oMenuSocialSharing->addMarkers($a);
  45. return $bResult;
  46. }
  47. public function setContentId($iContentId)
  48. {
  49. $this->_iContentId = (int)$iContentId;
  50. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iContentId);
  51. if($this->_aContentInfo)
  52. $this->addMarkers(array('content_id' => (int)$this->_iContentId));
  53. }
  54. /**
  55. * Check if menu items is visible with extended checking linked to "allow*" method of particular module
  56. * Associated "allow*" method with particular menu item is stored in module config in MENU_ITEM_TO_METHOD array.
  57. * @param $a menu item array
  58. * @return boolean
  59. */
  60. protected function _isVisible($a)
  61. {
  62. return $this->_oModule->isMenuItemVisible($this->_sObject, $a, $this->_aContentInfo);
  63. }
  64. protected function _getMenuItemDefault($aItem)
  65. {
  66. $aItem['class_wrp'] = 'bx-base-general-entity-action' . (!empty($aItem['class_wrp']) ? ' ' . $aItem['class_wrp'] : '');
  67. if($this->_bShowAsButton)
  68. $aItem['class_link'] = 'bx-btn' . (!empty($aItem['class_link']) ? ' ' . $aItem['class_link'] : '');
  69. if(!$this->_bShowTitle)
  70. $aItem['bx_if:title']['condition'] = false;
  71. return parent::_getMenuItemDefault ($aItem);
  72. }
  73. protected function _getMenuItemView($aItem, $aParams = array())
  74. {
  75. $CNF = &$this->_oModule->_oConfig->CNF;
  76. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  77. if(empty($sObject) && !empty($CNF['OBJECT_VIEWS']))
  78. $sObject = $CNF['OBJECT_VIEWS'];
  79. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  80. if(empty($iId))
  81. $iId = $this->_iContentId;
  82. $oObject = !empty($sObject) ? BxDolView::getObjectInstance($sObject, $iId) : false;
  83. if(!$oObject || !$oObject->isEnabled())
  84. return '';
  85. $sResult = $oObject->getElementBlock(array(
  86. 'dynamic_mode' => $this->_bDynamicMode,
  87. 'show_do_view_as_button' => $this->_bShowAsButton,
  88. 'show_do_view_label' => $this->_bShowTitle
  89. ));
  90. if(empty($sResult))
  91. return '';
  92. return array($sResult, $this->_sClassMiSa);
  93. }
  94. protected function _getMenuItemComment($aItem, $aParams = array())
  95. {
  96. $CNF = &$this->_oModule->_oConfig->CNF;
  97. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  98. if(empty($sObject) && !empty($CNF['OBJECT_COMMENTS']))
  99. $sObject = $CNF['OBJECT_COMMENTS'];
  100. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  101. if(empty($iId))
  102. $iId = $this->_iContentId;
  103. $oObject = !empty($sObject) ? BxTemplCmts::getObjectInstance($sObject, $iId) : false;
  104. if(!$oObject || !$oObject->isEnabled())
  105. return '';
  106. $sResult = $oObject->getElementBlock(array(
  107. 'dynamic_mode' => $this->_bDynamicMode,
  108. 'show_do_comment_as_button' => $this->_bShowAsButton,
  109. 'show_do_comment_label' => $this->_bShowTitle
  110. ));
  111. if(empty($sResult))
  112. return '';
  113. return array($sResult, $this->_sClassMiSa);
  114. }
  115. protected function _getMenuItemVote($aItem, $aParams = array())
  116. {
  117. $CNF = &$this->_oModule->_oConfig->CNF;
  118. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  119. if(empty($sObject) && !empty($CNF['OBJECT_VOTES']))
  120. $sObject = $CNF['OBJECT_VOTES'];
  121. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  122. if(empty($iId))
  123. $iId = $this->_iContentId;
  124. $oObject = !empty($sObject) ? BxDolVote::getObjectInstance($sObject, $iId) : false;
  125. if(!$oObject || !$oObject->isEnabled())
  126. return '';
  127. $sResult = $oObject->getElementBlock(array(
  128. 'dynamic_mode' => $this->_bDynamicMode,
  129. 'show_do_vote_as_button' => $this->_bShowAsButton,
  130. 'show_do_vote_label' => $this->_bShowTitle
  131. ));
  132. if(empty($sResult))
  133. return '';
  134. return array($sResult, $this->_sClassMiSa);
  135. }
  136. protected function _getMenuItemScore($aItem, $aParams = array())
  137. {
  138. $CNF = &$this->_oModule->_oConfig->CNF;
  139. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  140. if(empty($sObject) && !empty($CNF['OBJECT_SCORES']))
  141. $sObject = $CNF['OBJECT_SCORES'];
  142. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  143. if(empty($iId))
  144. $iId = $this->_iContentId;
  145. $oObject = !empty($sObject) ? BxDolScore::getObjectInstance($sObject, $iId) : false;
  146. if(!$oObject || !$oObject->isEnabled())
  147. return '';
  148. $sResult = $oObject->getElementBlock(array(
  149. 'dynamic_mode' => $this->_bDynamicMode,
  150. 'show_do_vote_as_button' => $this->_bShowAsButton,
  151. 'show_do_vote_label' => $this->_bShowTitle
  152. ));
  153. if(empty($sResult))
  154. return '';
  155. return array($sResult, $this->_sClassMiSa);
  156. }
  157. protected function _getMenuItemFavorite($aItem, $aParams = array())
  158. {
  159. $CNF = &$this->_oModule->_oConfig->CNF;
  160. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  161. if(empty($sObject) && !empty($CNF['OBJECT_FAVORITES']))
  162. $sObject = $CNF['OBJECT_FAVORITES'];
  163. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  164. if(empty($iId))
  165. $iId = $this->_iContentId;
  166. $oObject = !empty($sObject) ? BxDolFavorite::getObjectInstance($sObject, $iId) : false;
  167. if(!$oObject || !$oObject->isEnabled())
  168. return '';
  169. $sResult = $oObject->getElementBlock(array(
  170. 'dynamic_mode' => $this->_bDynamicMode,
  171. 'show_do_favorite_as_button' => $this->_bShowAsButton,
  172. 'show_do_favorite_label' => $this->_bShowTitle
  173. ));
  174. if(empty($sResult))
  175. return '';
  176. return array($sResult, $this->_sClassMiSa);
  177. }
  178. protected function _getMenuItemFeature($aItem, $aParams = array())
  179. {
  180. $CNF = &$this->_oModule->_oConfig->CNF;
  181. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  182. if(empty($sObject) && !empty($CNF['OBJECT_FEATURED']))
  183. $sObject = $CNF['OBJECT_FEATURED'];
  184. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  185. if(empty($iId))
  186. $iId = $this->_iContentId;
  187. $oObject = !empty($sObject) ? BxDolFeature::getObjectInstance($sObject, $iId) : false;
  188. if(!$oObject || !$oObject->isEnabled())
  189. return '';
  190. $sResult = $oObject->getElementBlock(array(
  191. 'dynamic_mode' => $this->_bDynamicMode,
  192. 'show_do_feature_as_button' => $this->_bShowAsButton,
  193. 'show_do_feature_label' => $this->_bShowTitle
  194. ));
  195. if(empty($sResult))
  196. return '';
  197. return array($sResult, $this->_sClassMiSa);
  198. }
  199. protected function _getMenuItemRepost($aItem, $aParams = array())
  200. {
  201. $CNF = &$this->_oModule->_oConfig->CNF;
  202. $sAction = !empty($aParams['action']) ? $aParams['action'] : '';
  203. if(empty($sAction))
  204. $sAction = 'added';
  205. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  206. if(empty($iId))
  207. $iId = $this->_iContentId;
  208. if(!empty($CNF['FIELD_ALLOW_VIEW_TO'])) {
  209. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
  210. if(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)))
  211. return '';
  212. }
  213. if(!BxDolRequest::serviceExists('bx_timeline', 'get_repost_element_block'))
  214. return '';
  215. $sResult = BxDolService::call('bx_timeline', 'get_repost_element_block', array(bx_get_logged_profile_id(), $this->_oModule->_oConfig->getName(), $sAction, $iId, array(
  216. 'show_do_repost_as_button' => $this->_bShowAsButton,
  217. 'show_do_repost_text' => $this->_bShowTitle
  218. )));
  219. if(empty($sResult))
  220. return '';
  221. return array($sResult, $this->_sClassMiSa);
  222. }
  223. protected function _getMenuItemReport($aItem, $aParams = array())
  224. {
  225. $CNF = &$this->_oModule->_oConfig->CNF;
  226. $sObject = !empty($aParams['object']) ? $aParams['object'] : '';
  227. if(empty($sObject) && !empty($CNF['OBJECT_REPORTS']))
  228. $sObject = $CNF['OBJECT_REPORTS'];
  229. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  230. if(empty($iId))
  231. $iId = $this->_iContentId;
  232. $oObject = !empty($sObject) ? BxDolReport::getObjectInstance($sObject, $iId) : false;
  233. if(!$oObject || !$oObject->isEnabled())
  234. return '';
  235. $sResult = $oObject->getElementBlock(array(
  236. 'dynamic_mode' => $this->_bDynamicMode,
  237. 'show_do_report_as_button' => $this->_bShowAsButton,
  238. 'show_do_report_label' => $this->_bShowTitle
  239. ));
  240. if(empty($sResult))
  241. return '';
  242. return array($sResult, $this->_sClassMiSa);
  243. }
  244. protected function _getMenuItemSocialSharingFacebook($aItem)
  245. {
  246. return $this->_getMenuItemByNameSocialSharing($aItem);
  247. }
  248. protected function _getMenuItemSocialSharingGoogleplus($aItem)
  249. {
  250. return $this->_getMenuItemByNameSocialSharing($aItem);
  251. }
  252. protected function _getMenuItemSocialSharingTwitter($aItem)
  253. {
  254. return $this->_getMenuItemByNameSocialSharing($aItem);
  255. }
  256. protected function _getMenuItemSocialSharingPinterest($aItem)
  257. {
  258. return $this->_getMenuItemByNameSocialSharing($aItem);
  259. }
  260. protected function _getMenuItemByNameActions($aItem, $aParams = array())
  261. {
  262. $CNF = &$this->_oModule->_oConfig->CNF;
  263. if(empty($this->_oMenuActions)) {
  264. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  265. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']))
  266. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'];
  267. if(empty($sObjectMenu))
  268. return '';
  269. $this->_oMenuActions = BxDolMenu::getObjectInstance($sObjectMenu);
  270. if(!$this->_oMenuActions)
  271. return '';
  272. $this->_oMenuActions->setContentId($this->_iContentId);
  273. $this->addMarkers($this->_oMenuActions->getMarkers());
  274. }
  275. $aItem = $this->_oMenuActions->getMenuItem($aItem['name']);
  276. if(empty($aItem) || !is_array($aItem))
  277. return false;
  278. return $this->_getMenuItemDefault($aItem);
  279. }
  280. protected function _getMenuItemByNameSocialSharing($aItem, $aParams = array())
  281. {
  282. if(empty($this->_oMenuSocialSharing)) {
  283. $this->_oMenuSocialSharing = BxDolMenu::getObjectInstance('sys_social_sharing');
  284. $this->_oMenuSocialSharing->addMarkers($this->_aMarkers);
  285. }
  286. $aItem = $this->_oMenuSocialSharing->getMenuItem($aItem['name']);
  287. if(empty($aItem) || !is_array($aItem))
  288. return false;
  289. return $this->_getMenuItemDefault($aItem);
  290. }
  291. protected function _getMenuItemByNameActionsMore($aItem)
  292. {
  293. $CNF = &$this->_oModule->_oConfig->CNF;
  294. if(empty($this->_oMenuActionsMore)) {
  295. if(empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']))
  296. return '';
  297. $this->_oMenuActionsMore = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  298. if(!$this->_oMenuActionsMore)
  299. return '';
  300. $this->_oMenuActionsMore->setContentId($this->_iContentId);
  301. $this->addMarkers($this->_oMenuActionsMore->getMarkers());
  302. }
  303. $aItem = $this->_oMenuActionsMore->getMenuItem($aItem['name']);
  304. if(empty($aItem) || !is_array($aItem))
  305. return false;
  306. return $this->_getMenuItemDefault($aItem);
  307. }
  308. }
  309. /** @} */