1
0

BxBaseModProfileMenuViewMeta.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. $sUrl = $this->_oContentProfile->getUrl();
  95. if(!empty($CNF['URI_VIEW_FRIENDS']))
  96. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_FRIENDS'] . '&profile_id=' . $iContentProfileId));
  97. return $this->_getMenuItemAPI($aItem, ['display' => 'button'], [
  98. 'title' => $aCounter['countf'],
  99. 'link' => bx_api_get_relative_url($sUrl),
  100. 'list' => $oConnection->getConnectedListAPI($iContentProfileId, true, BX_CONNECTIONS_CONTENT_TYPE_CONTENT)
  101. ]);
  102. }
  103. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  104. return $oConnection->getCounter($iContentProfileId, true, ['caption' => $aItem['title'], 'custom_icon' => $sIcon], BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  105. }
  106. protected function _getMenuItemSubscribers($aItem)
  107. {
  108. $CNF = &$this->_oModule->_oConfig->CNF;
  109. if(!$this->_bContentPublic || !$this->_oContentProfile)
  110. return false;
  111. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  112. if(!$oConnection)
  113. return false;
  114. $iContentProfileId = $this->_oContentProfile->id();
  115. if($this->_bIsApi) {
  116. $aCounter = $oConnection->getCounterAPI($iContentProfileId, false, ['caption' => $aItem['title']], BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  117. $sUrl = $this->_oContentProfile->getUrl();
  118. if(!empty($CNF['URI_VIEW_SUBSCRIPTIONS']))
  119. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_SUBSCRIPTIONS'] . '&profile_id=' . $iContentProfileId));
  120. return $this->_getMenuItemAPI($aItem, ['display' => 'button'], [
  121. 'title' => $aCounter['countf'],
  122. 'link' => bx_api_get_relative_url($sUrl),
  123. 'list' => $oConnection->getConnectedListAPI($iContentProfileId, false, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS)
  124. ]);
  125. }
  126. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  127. return $oConnection->getCounter($iContentProfileId, false, ['caption' => $aItem['title'], 'custom_icon' => $sIcon], BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  128. }
  129. protected function _getMenuItemRelations($aItem)
  130. {
  131. $CNF = &$this->_oModule->_oConfig->CNF;
  132. if(!$this->_bContentPublic || !$this->_oContentProfile)
  133. return false;
  134. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_relations');
  135. if(!$oConnection)
  136. return false;
  137. $iContentProfileId = $this->_oContentProfile->id();
  138. if($this->_bIsApi) {
  139. $aCounter = $oConnection->getCounterAPI($iContentProfileId, false, ['caption' => $aItem['title']], BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  140. $sUrl = $this->_oContentProfile->getUrl();
  141. if(!empty($CNF['URI_VIEW_RELATIONS']))
  142. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_RELATIONS'] . '&profile_id=' . $iContentProfileId));
  143. return $this->_getMenuItemAPI($aItem, ['display' => 'button'], [
  144. 'title' => $aCounter['countf'],
  145. 'link' => bx_api_get_relative_url($sUrl),
  146. 'list' => $oConnection->getConnectedListAPI($iContentProfileId, false, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS)
  147. ]);
  148. }
  149. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  150. return $oConnection->getCounter($iContentProfileId, true, ['caption' => $aItem['title'], 'custom_icon' => $sIcon], BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  151. }
  152. protected function _getMenuItemViews($aItem)
  153. {
  154. $CNF = &$this->_oModule->_oConfig->CNF;
  155. if($this->_bIsApi)
  156. return false;
  157. if(empty($CNF['OBJECT_VIEWS']) || empty($CNF['FIELD_VIEWS']) || (empty($this->_aContentInfo[$CNF['FIELD_VIEWS']]) && !$this->_bShowZeros))
  158. return false;
  159. $oObject = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $this->_aContentInfo[$CNF['FIELD_ID']]) : null;
  160. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  161. return $oObject ? $oObject->getCounter(['show_counter_empty' => false, 'show_counter_in_brackets' => false, 'dynamic_mode' => true, 'caption' => '_view_n_views', 'custom_icon' => $sIcon]) : '';
  162. }
  163. protected function _getMenuItemVotes($aItem)
  164. {
  165. $CNF = &$this->_oModule->_oConfig->CNF;
  166. if($this->_bIsApi)
  167. return false;
  168. if(empty($CNF['OBJECT_VOTES']) || empty($CNF['FIELD_VOTES']) || (empty($this->_aContentInfo[$CNF['FIELD_VOTES']]) && !$this->_bShowZeros))
  169. return false;
  170. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  171. $oObject = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  172. if(!$oObject || !$oObject->isEnabled())
  173. return '';
  174. return $oObject->getCounter([
  175. 'show_counter_label_icon' => true,
  176. 'show_counter_empty' => false,
  177. 'dynamic_mode' => true,
  178. 'caption' => '_vote_n_votes',
  179. 'custom_icon' => $sIcon
  180. ]);
  181. }
  182. protected function _getMenuItemReactions($aItem)
  183. {
  184. $CNF = &$this->_oModule->_oConfig->CNF;
  185. if($this->_bIsApi)
  186. return false;
  187. $sKo = 'OBJECT_REACTIONS';
  188. if(($sKf = 'FIELD_REACTIONS') && (empty($CNF[$sKo]) || empty($CNF[$sKf]) || (empty($this->_aContentInfo[$CNF[$sKf]]) && !$this->_bShowZeros)))
  189. return false;
  190. $oObject = BxDolVote::getObjectInstance($CNF[$sKo], $this->_aContentInfo[$CNF['FIELD_ID']]);
  191. if(!$oObject || !$oObject->isEnabled())
  192. return false;
  193. return $oObject->getCounter([
  194. 'show_counter_style' => 'compound',
  195. 'show_counter_empty' => false,
  196. 'dynamic_mode' => true
  197. ]);
  198. }
  199. protected function _getMenuItemScores($aItem)
  200. {
  201. $CNF = &$this->_oModule->_oConfig->CNF;
  202. if($this->_bIsApi)
  203. return false;
  204. $sKo = 'OBJECT_SCORES';
  205. if(($sKfu = 'FIELD_SCORE_UP') && ($sKfd = 'FIELD_SCORE_DOWN') && (empty($CNF[$sKo]) || empty($CNF[$sKfu]) || empty($CNF[$sKfd]) || (empty($this->_aContentInfo[$CNF[$sKfu]]) && empty($this->_aContentInfo[$CNF[$sKfd]]) && !$this->_bShowZeros)))
  206. return false;
  207. $oObject = BxDolScore::getObjectInstance($CNF[$sKo], $this->_aContentInfo[$CNF['FIELD_ID']]);
  208. if(!$oObject || !$oObject->isEnabled())
  209. return false;
  210. return $oObject->getCounter([
  211. 'show_counter_label_icon' => true,
  212. 'show_counter_empty' => false,
  213. 'dynamic_mode' => true,
  214. ]);
  215. }
  216. protected function _getMenuItemComments($aItem)
  217. {
  218. $CNF = &$this->_oModule->_oConfig->CNF;
  219. if($this->_bIsApi)
  220. return false;
  221. if(empty($CNF['OBJECT_COMMENTS']) || empty($CNF['FIELD_COMMENTS']) || (empty($this->_aContentInfo[$CNF['FIELD_COMMENTS']]) && !$this->_bShowZeros))
  222. return false;
  223. $oComments = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  224. if(!$oComments || !$oComments->isEnabled())
  225. return false;
  226. $oObject = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]) : null;
  227. return $oObject ? $oObject->getCounter([
  228. 'overwrite_counter_link_onclick' => 'javascript:void(0)',
  229. 'show_counter_empty' => false,
  230. 'recalculate_counter' => true,
  231. 'dynamic_mode' => true,
  232. 'caption' => '_cmt_txt_n_comments',
  233. 'custom_icon' => BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '')
  234. ]) : '';
  235. }
  236. protected function _retrieveContentId()
  237. {
  238. if(bx_get('id') !== false)
  239. $this->setContentId(bx_process_input(bx_get('id'), BX_DATA_INT));
  240. if(empty($this->_iContentId) && bx_get('profile_id') !== false)
  241. $this->setContentId(BxDolProfile::getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT))->getContentId());
  242. }
  243. }
  244. /** @} */