BxBaseModGeneralMenuViewActions.php 7.6 KB

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