BxBaseModGeneralMenuViewActions.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. public function __construct($aObject, $oTemplate = false)
  27. {
  28. parent::__construct($aObject, $oTemplate);
  29. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  30. $this->setContentId(bx_process_input(bx_get('id'), BX_DATA_INT));
  31. $this->_oMenuActions = null;
  32. $this->_oMenuActionsMore = null;
  33. $this->_oMenuSocialSharing = null;
  34. $this->_bShowAsButton = true;
  35. $this->_bShowTitle = false;
  36. }
  37. public function setContentId($iContentId)
  38. {
  39. $this->_iContentId = (int)$iContentId;
  40. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iContentId);
  41. if($this->_aContentInfo)
  42. $this->addMarkers(array('content_id' => (int)$this->_iContentId));
  43. }
  44. protected function _getMenuItemDefault ($aItem)
  45. {
  46. $aItem['class_wrp'] = 'bx-base-general-entity-action' . (!empty($aItem['class_wrp']) ? ' ' . $aItem['class_wrp'] : '');
  47. if($this->_bShowAsButton)
  48. $aItem['class_link'] = 'bx-btn' . (!empty($aItem['class_link']) ? ' ' . $aItem['class_link'] : '');
  49. if(!$this->_bShowTitle)
  50. $aItem['bx_if:title']['condition'] = false;
  51. return parent::_getMenuItemDefault ($aItem);
  52. }
  53. protected function _getMenuItemView($aItem)
  54. {
  55. $CNF = &$this->_oModule->_oConfig->CNF;
  56. $oObject = !empty($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $this->_iContentId) : false;
  57. if(!$oObject || !$oObject->isEnabled())
  58. return '';
  59. return $oObject->getElementBlock(array(
  60. 'dynamic_mode' => $this->_bDynamicMode,
  61. 'show_do_view_as_button' => $this->_bShowAsButton,
  62. 'show_do_view_label' => $this->_bShowTitle
  63. ));
  64. }
  65. protected function _getMenuItemComment($aItem)
  66. {
  67. $CNF = &$this->_oModule->_oConfig->CNF;
  68. $oObject = !empty($CNF['OBJECT_COMMENTS']) ? BxTemplCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_iContentId) : false;
  69. if(!$oObject || !$oObject->isEnabled())
  70. return '';
  71. return $oObject->getElementBlock(array(
  72. 'dynamic_mode' => $this->_bDynamicMode,
  73. 'show_do_comment_as_button' => $this->_bShowAsButton,
  74. 'show_do_comment_label' => $this->_bShowTitle
  75. ));
  76. }
  77. protected function _getMenuItemVote($aItem)
  78. {
  79. $CNF = &$this->_oModule->_oConfig->CNF;
  80. $oObject = !empty($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $this->_iContentId) : false;
  81. if(!$oObject || !$oObject->isEnabled())
  82. return '';
  83. return $oObject->getElementBlock(array(
  84. 'dynamic_mode' => $this->_bDynamicMode,
  85. 'show_do_vote_as_button' => $this->_bShowAsButton,
  86. 'show_do_vote_label' => $this->_bShowTitle
  87. ));
  88. }
  89. protected function _getMenuItemScore($aItem)
  90. {
  91. $CNF = &$this->_oModule->_oConfig->CNF;
  92. $oObject = !empty($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $this->_iContentId) : false;
  93. if(!$oObject || !$oObject->isEnabled())
  94. return '';
  95. return $oObject->getElementBlock(array(
  96. 'dynamic_mode' => $this->_bDynamicMode,
  97. 'show_do_vote_as_button' => $this->_bShowAsButton,
  98. 'show_do_vote_label' => $this->_bShowTitle
  99. ));
  100. }
  101. protected function _getMenuItemFavorite($aItem)
  102. {
  103. $CNF = &$this->_oModule->_oConfig->CNF;
  104. $oObject = !empty($CNF['OBJECT_FAVORITES']) ? BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], $this->_iContentId) : false;
  105. if(!$oObject || !$oObject->isEnabled())
  106. return '';
  107. return $oObject->getElementBlock(array(
  108. 'dynamic_mode' => $this->_bDynamicMode,
  109. 'show_do_favorite_as_button' => $this->_bShowAsButton,
  110. 'show_do_favorite_label' => $this->_bShowTitle
  111. ));
  112. }
  113. protected function _getMenuItemFeature($aItem)
  114. {
  115. $CNF = &$this->_oModule->_oConfig->CNF;
  116. $oObject = !empty($CNF['OBJECT_FEATURED']) ? BxDolFeature::getObjectInstance($CNF['OBJECT_FEATURED'], $this->_iContentId) : false;
  117. if(!$oObject || !$oObject->isEnabled())
  118. return '';
  119. return $oObject->getElementBlock(array(
  120. 'dynamic_mode' => $this->_bDynamicMode,
  121. 'show_do_feature_as_button' => $this->_bShowAsButton,
  122. 'show_do_feature_label' => $this->_bShowTitle
  123. ));
  124. }
  125. protected function _getMenuItemRepost($aItem)
  126. {
  127. $CNF = &$this->_oModule->_oConfig->CNF;
  128. if(!BxDolRequest::serviceExists('bx_timeline', 'get_repost_element_block'))
  129. return '';
  130. return BxDolService::call('bx_timeline', 'get_repost_element_block', array(bx_get_logged_profile_id(), $this->_oModule->_oConfig->getName(), 'added', $this->_iContentId, array(
  131. 'show_do_repost_as_button' => $this->_bShowAsButton,
  132. 'show_do_repost_text' => $this->_bShowTitle
  133. )));
  134. }
  135. protected function _getMenuItemReport($aItem)
  136. {
  137. $CNF = &$this->_oModule->_oConfig->CNF;
  138. $oObject = !empty($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $this->_iContentId) : false;
  139. if(!$oObject || !$oObject->isEnabled())
  140. return '';
  141. return $oObject->getElementBlock(array(
  142. 'dynamic_mode' => $this->_bDynamicMode,
  143. 'show_do_report_as_button' => $this->_bShowAsButton,
  144. 'show_do_report_label' => $this->_bShowTitle
  145. ));
  146. }
  147. protected function _getMenuItemSocialSharingFacebook($aItem)
  148. {
  149. return $this->_getMenuItemByNameSocialSharing($aItem);
  150. }
  151. protected function _getMenuItemSocialSharingGoogleplus($aItem)
  152. {
  153. return $this->_getMenuItemByNameSocialSharing($aItem);
  154. }
  155. protected function _getMenuItemSocialSharingTwitter($aItem)
  156. {
  157. return $this->_getMenuItemByNameSocialSharing($aItem);
  158. }
  159. protected function _getMenuItemSocialSharingPinterest($aItem)
  160. {
  161. return $this->_getMenuItemByNameSocialSharing($aItem);
  162. }
  163. protected function _getMenuItemByNameActions($aItem)
  164. {
  165. $CNF = &$this->_oModule->_oConfig->CNF;
  166. if(empty($this->_oMenuActions)) {
  167. if(empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']))
  168. return '';
  169. $this->_oMenuActions = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  170. $this->_oMenuActions->setContentId($this->_iContentId);
  171. }
  172. $aItem = $this->_oMenuActions->getMenuItem($aItem['name']);
  173. if(empty($aItem) || !is_array($aItem))
  174. return false;
  175. return $this->_getMenuItemDefault($aItem);
  176. }
  177. protected function _getMenuItemByNameSocialSharing($aItem)
  178. {
  179. if(empty($this->_oMenuSocialSharing)) {
  180. $this->_oMenuSocialSharing = BxDolMenu::getObjectInstance('sys_social_sharing');
  181. $this->_oMenuSocialSharing->addMarkers(array_merge($this->_aMarkers, array(
  182. 'id' => $this->_iContentId,
  183. 'module' => $this->_oModule->_oConfig->getName(),
  184. )));
  185. }
  186. $aItem = $this->_oMenuSocialSharing->getMenuItem($aItem['name']);
  187. if(empty($aItem) || !is_array($aItem))
  188. return false;
  189. return $this->_getMenuItemDefault($aItem);
  190. }
  191. protected function _getMenuItemByNameActionsMore($aItem)
  192. {
  193. $CNF = &$this->_oModule->_oConfig->CNF;
  194. if(empty($this->_oMenuActionsMore)) {
  195. if(empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']))
  196. return '';
  197. $this->_oMenuActionsMore = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  198. $this->_oMenuActionsMore->setContentId($this->_iContentId);
  199. }
  200. $aItem = $this->_oMenuActionsMore->getMenuItem($aItem['name']);
  201. if(empty($aItem) || !is_array($aItem))
  202. return false;
  203. return $this->_getMenuItemDefault($aItem);
  204. }
  205. }
  206. /** @} */