BxBaseModGeneralMenuViewActions.php 13 KB

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