1
0

BxBaseModProfileMenuViewMeta.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. $aMembership = $oAcl->getMemberMembershipInfo($this->_oContentProfile->id());
  66. $aLevelInfo = $oAcl->getMembershipInfo($aMembership['id']);
  67. if($this->_bIsApi)
  68. return $this->_getMenuItemAPI($aItem, ['display' => 'button'], [
  69. 'title' => _t($aMembership['name'])
  70. ]);
  71. $oTemplate = BxDolTemplate::getInstance();
  72. 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;
  73. }
  74. protected function _getMenuItemBadges($aItem)
  75. {
  76. if($this->_bIsApi)
  77. return false;
  78. $sResult = $this->_oModule->serviceGetBadges($this->_iContentId);
  79. if(!empty($sResult))
  80. $sResult = $this->getUnitMetaItemText($sResult, ['class' => 'bx-base-bages-container']);
  81. return $sResult;
  82. }
  83. protected function _getMenuItemFriends($aItem)
  84. {
  85. $CNF = &$this->_oModule->_oConfig->CNF;
  86. if(!$this->_bContentPublic || !$this->_oContentProfile)
  87. return false;
  88. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends');
  89. if(!$oConnection)
  90. return false;
  91. $iContentProfileId = $this->_oContentProfile->id();
  92. if($this->_bIsApi) {
  93. $aCounter = $oConnection->getCounterAPI($iContentProfileId, true, ['caption' => $aItem['title']], BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  94. return $this->_getMenuItemAPI($aItem, ['display' => 'button'], [
  95. 'title' => $aCounter['countf'],
  96. ]);
  97. }
  98. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  99. return $oConnection->getCounter($iContentProfileId, true, ['caption' => $aItem['title'], 'custom_icon' => $sIcon], BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  100. }
  101. protected function _getMenuItemSubscribers($aItem)
  102. {
  103. $CNF = &$this->_oModule->_oConfig->CNF;
  104. if(!$this->_bContentPublic || !$this->_oContentProfile)
  105. return false;
  106. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  107. if(!$oConnection)
  108. return false;
  109. $iContentProfileId = $this->_oContentProfile->id();
  110. if($this->_bIsApi) {
  111. $aCounter = $oConnection->getCounterAPI($iContentProfileId, false, ['caption' => $aItem['title']], BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  112. return $this->_getMenuItemAPI($aItem, ['display' => 'button'], [
  113. 'title' => $aCounter['countf'],
  114. ]);
  115. }
  116. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  117. return $oConnection->getCounter($iContentProfileId, false, ['caption' => $aItem['title'], 'custom_icon' => $sIcon], BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  118. }
  119. protected function _getMenuItemViews($aItem)
  120. {
  121. $CNF = &$this->_oModule->_oConfig->CNF;
  122. if($this->_bIsApi)
  123. return false;
  124. if(empty($CNF['OBJECT_VIEWS']) || empty($CNF['FIELD_VIEWS']) || (empty($this->_aContentInfo[$CNF['FIELD_VIEWS']]) && !$this->_bShowZeros))
  125. return false;
  126. $oObject = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $this->_aContentInfo[$CNF['FIELD_ID']]) : null;
  127. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  128. return $oObject ? $oObject->getCounter(['show_counter_empty' => false, 'show_counter_in_brackets' => false, 'dynamic_mode' => true, 'caption' => '_view_n_views', 'custom_icon' => $sIcon]) : '';
  129. }
  130. protected function _getMenuItemVotes($aItem)
  131. {
  132. $CNF = &$this->_oModule->_oConfig->CNF;
  133. if($this->_bIsApi)
  134. return false;
  135. if(empty($CNF['OBJECT_VOTES']) || empty($CNF['FIELD_VOTES']) || (empty($this->_aContentInfo[$CNF['FIELD_VOTES']]) && !$this->_bShowZeros))
  136. return false;
  137. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  138. $oObject = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $this->_aContentInfo[$CNF['FIELD_ID']]) : null;
  139. return $oObject ? $oObject->getCounter(['show_counter_label_icon' => true, 'show_counter_empty' => false, 'dynamic_mode' => true, 'caption' => '_vote_n_votes', 'custom_icon' => $sIcon]) : '';
  140. }
  141. protected function _getMenuItemReactions($aItem)
  142. {
  143. $CNF = &$this->_oModule->_oConfig->CNF;
  144. if($this->_bIsApi)
  145. return false;
  146. if(empty($CNF['OBJECT_REACTIONS']))
  147. return false;
  148. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  149. if(!$oVotes)
  150. return false;
  151. return $this->getUnitMetaItemCustom($oVotes->getElementInline(array('show_counter' => false)));
  152. }
  153. protected function _getMenuItemScores($aItem)
  154. {
  155. $CNF = &$this->_oModule->_oConfig->CNF;
  156. if($this->_bIsApi)
  157. return false;
  158. if(empty($CNF['OBJECT_SCORES']))
  159. return false;
  160. $oScores = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  161. if(!$oScores)
  162. return false;
  163. return $this->getUnitMetaItemCustom($oScores->getElementInline(array('show_counter' => false)));
  164. }
  165. protected function _getMenuItemComments($aItem)
  166. {
  167. $CNF = &$this->_oModule->_oConfig->CNF;
  168. if($this->_bIsApi)
  169. return false;
  170. if(empty($CNF['OBJECT_COMMENTS']) || empty($CNF['FIELD_COMMENTS']) || (empty($this->_aContentInfo[$CNF['FIELD_COMMENTS']]) && !$this->_bShowZeros))
  171. return false;
  172. $oComments = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  173. if(!$oComments || !$oComments->isEnabled())
  174. return false;
  175. $oObject = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]) : null;
  176. return $oObject ? $oObject->getCounter([
  177. 'overwrite_counter_link_onclick' => 'javascript:void(0)',
  178. 'show_counter_empty' => false,
  179. 'recalculate_counter' => true,
  180. 'dynamic_mode' => true,
  181. 'caption' => '_cmt_txt_n_comments',
  182. 'custom_icon' => BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '')
  183. ]) : '';
  184. }
  185. protected function _retrieveContentId()
  186. {
  187. if(bx_get('id') !== false)
  188. $this->setContentId(bx_process_input(bx_get('id'), BX_DATA_INT));
  189. if(empty($this->_iContentId) && bx_get('profile_id') !== false)
  190. $this->setContentId(BxDolProfile::getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT))->getContentId());
  191. }
  192. }
  193. /** @} */