BxBaseModProfileMenuViewMeta.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * View entry meta menu
  13. */
  14. class BxBaseModProfileMenuViewMeta extends BxTemplMenuUnitMeta
  15. {
  16. protected $_sModule;
  17. protected $_oModule;
  18. protected $_bShowZeros;
  19. protected $_iContentId;
  20. protected $_aContentInfo;
  21. protected $_bContentPublic;
  22. protected $_oContentProfile;
  23. protected $_aContentProfileInfo;
  24. public function __construct($aObject, $oTemplate = false)
  25. {
  26. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  27. parent::__construct($aObject, $oTemplate);
  28. $this->_bShowZeros = false;
  29. $this->_iContentId = 0;
  30. $this->_aContentInfo = [];
  31. $this->_bContentPublic = false;
  32. $this->_oContentProfile = null;
  33. $this->_aContentProfileInfo = [];
  34. }
  35. public function setContentId($iContentId)
  36. {
  37. $this->_iContentId = $iContentId;
  38. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iContentId);
  39. if(empty($this->_aContentInfo) || !is_array($this->_aContentInfo))
  40. return;
  41. $this->_oContentProfile = BxDolProfile::getInstanceByContentAndType($this->_iContentId, $this->_sModule);
  42. if(!$this->_oContentProfile)
  43. return;
  44. $this->_aContentProfileInfo = $this->_oContentProfile->getInfo();
  45. $this->addMarkers($this->_aContentProfileInfo);
  46. $this->addMarkers(array(
  47. 'profile_id' => $this->_oContentProfile->id()
  48. ));
  49. }
  50. public function setContentPublic($bContentPublic)
  51. {
  52. $this->_bContentPublic = $bContentPublic;
  53. }
  54. public function getCode()
  55. {
  56. if(empty($this->_iContentId))
  57. $this->_retrieveContentId();
  58. return parent::getCode();
  59. }
  60. protected function _getMenuItemMembership($aItem)
  61. {
  62. if(!$this->_bContentPublic || !$this->_oContentProfile)
  63. return false;
  64. $oAcl = BxDolAcl::getInstance();
  65. $oTemplate = BxDolTemplate::getInstance();
  66. $aMembership = $oAcl->getMemberMembershipInfo($this->_oContentProfile->id());
  67. $aLevelInfo = $oAcl->getMembershipInfo($aMembership['id']);
  68. return $aMembership ? $this->getUnitMetaItemText($oTemplate->parseHtmlByName('menu_meta_item.html', ['icon' => $oTemplate->getImage($aLevelInfo['icon'], array('class' => 'bx-acl-m-thumbnail')), 'caption' => _t($aMembership['name'])])): false;
  69. }
  70. protected function _getMenuItemBadges($aItem)
  71. {
  72. $sResult = $this->_oModule->serviceGetBadges($this->_iContentId);
  73. if(!empty($sResult))
  74. $sResult = $this->getUnitMetaItemText($sResult, ['class' => 'bx-base-bages-container']);
  75. return $sResult;
  76. }
  77. protected function _getMenuItemFriends($aItem)
  78. {
  79. $CNF = &$this->_oModule->_oConfig->CNF;
  80. if(!$this->_bContentPublic || !$this->_oContentProfile)
  81. return false;
  82. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends');
  83. if(!$oConnection)
  84. return false;
  85. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  86. return $oConnection->getCounter($this->_oContentProfile->id(), true, ['caption' => '_sys_menu_item_title_sm_friends', 'custom_icon' => $sIcon], BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  87. }
  88. protected function _getMenuItemSubscribers($aItem)
  89. {
  90. $CNF = &$this->_oModule->_oConfig->CNF;
  91. if(!$this->_bContentPublic || !$this->_oContentProfile)
  92. return false;
  93. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  94. if(!$oConnection)
  95. return false;
  96. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  97. return $oConnection->getCounter($this->_oContentProfile->id(), false, ['caption' => '_sys_menu_item_title_sm_subscribers', 'custom_icon' => $sIcon], BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  98. }
  99. protected function _getMenuItemViews($aItem)
  100. {
  101. $CNF = &$this->_oModule->_oConfig->CNF;
  102. if(empty($CNF['OBJECT_VIEWS']) || empty($CNF['FIELD_VIEWS']) || (empty($this->_aContentInfo[$CNF['FIELD_VIEWS']]) && !$this->_bShowZeros))
  103. return false;
  104. $oObject = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $this->_aContentInfo[$CNF['FIELD_ID']]) : null;
  105. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  106. return $oObject ? $oObject->getCounter(['show_counter_empty' => false, 'show_counter_in_brackets' => false, 'dynamic_mode' => true, 'caption' => '_view_n_views', 'custom_icon' => $sIcon]) : '';
  107. }
  108. protected function _getMenuItemVotes($aItem)
  109. {
  110. $CNF = &$this->_oModule->_oConfig->CNF;
  111. if(empty($CNF['OBJECT_VOTES']) || empty($CNF['FIELD_VOTES']) || (empty($this->_aContentInfo[$CNF['FIELD_VOTES']]) && !$this->_bShowZeros))
  112. return false;
  113. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  114. $oObject = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $this->_aContentInfo[$CNF['FIELD_ID']]) : null;
  115. return $oObject ? $oObject->getCounter(['show_counter_label_icon' => true, 'show_counter_empty' => false, 'dynamic_mode' => true, 'caption' => '_vote_n_votes', 'custom_icon' => $sIcon]) : '';
  116. }
  117. protected function _getMenuItemReactions($aItem)
  118. {
  119. $CNF = &$this->_oModule->_oConfig->CNF;
  120. if(empty($CNF['OBJECT_REACTIONS']))
  121. return false;
  122. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  123. if(!$oVotes)
  124. return false;
  125. return $this->getUnitMetaItemCustom($oVotes->getElementInline(array('show_counter' => false)));
  126. }
  127. protected function _getMenuItemScores($aItem)
  128. {
  129. $CNF = &$this->_oModule->_oConfig->CNF;
  130. if(empty($CNF['OBJECT_SCORES']))
  131. return false;
  132. $oScores = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  133. if(!$oScores)
  134. return false;
  135. return $this->getUnitMetaItemCustom($oScores->getElementInline(array('show_counter' => false)));
  136. }
  137. protected function _getMenuItemComments($aItem)
  138. {
  139. $CNF = &$this->_oModule->_oConfig->CNF;
  140. if(empty($CNF['OBJECT_COMMENTS']) || empty($CNF['FIELD_COMMENTS']) || (empty($this->_aContentInfo[$CNF['FIELD_COMMENTS']]) && !$this->_bShowZeros))
  141. return false;
  142. $oComments = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  143. if(!$oComments || !$oComments->isEnabled())
  144. return false;
  145. $oObject = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]) : null;
  146. return $oObject ? $oObject->getCounter([
  147. 'overwrite_counter_link_onclick' => 'javascript:void(0)',
  148. 'show_counter_empty' => false,
  149. 'recalculate_counter' => true,
  150. 'dynamic_mode' => true,
  151. 'caption' => '_cmt_txt_n_comments',
  152. 'custom_icon' => BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '')
  153. ]) : '';
  154. }
  155. protected function _retrieveContentId()
  156. {
  157. if(bx_get('id') !== false)
  158. $this->setContentId(bx_process_input(bx_get('id'), BX_DATA_INT));
  159. if(empty($this->_iContentId) && bx_get('profile_id') !== false)
  160. $this->setContentId(BxDolProfile::getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT))->getContentId());
  161. }
  162. }
  163. /** @} */