BxBaseModProfileMenuViewMeta.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. $oTemplate = BxDolTemplate::getInstance();
  65. $iProfileId = $this->_oContentProfile->id();
  66. $oAcl = BxDolAcl::getInstance();
  67. $aMembership = $oAcl->getMemberMembershipInfo($iProfileId);
  68. $aLevelInfo = $oAcl->getMembershipInfo($aMembership['id']);
  69. if($this->_bIsApi)
  70. return $this->_getMenuItemAPI($aItem, ['display' => 'button'], [
  71. 'title' => _t($aMembership['name']),
  72. 'icon' => $oTemplate->getImage($aLevelInfo['icon'], ['wrap_in_tag' => false])
  73. ]);
  74. $sMembership = '';
  75. if($aMembership)
  76. $sMembership = $oTemplate->parseHtmlByName('menu_meta_item.html', [
  77. 'icon' => $oTemplate->getImage($aLevelInfo['icon'], ['class' => 'bx-acl-m-thumbnail']),
  78. 'caption' => _t($aMembership['name'])
  79. ]);
  80. return $aMembership ? $this->getUnitMetaItemText($sMembership, ['id' => 'sys-mi-acl-' . $iProfileId]) : false;
  81. }
  82. protected function _getMenuItemBadges($aItem)
  83. {
  84. if($this->_bIsApi)
  85. return false;
  86. $sResult = $this->_oModule->serviceGetBadges($this->_iContentId);
  87. if(!empty($sResult))
  88. $sResult = $this->getUnitMetaItemText($sResult, ['class' => 'bx-base-bages-container']);
  89. return $sResult;
  90. }
  91. protected function _getMenuItemFriends($aItem)
  92. {
  93. $CNF = &$this->_oModule->_oConfig->CNF;
  94. if(!$this->_oModule->_oConfig->isFriends() || !$this->_bContentPublic || !$this->_oContentProfile)
  95. return false;
  96. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends');
  97. if(!$oConnection)
  98. return false;
  99. $iContentProfileId = $this->_oContentProfile->id();
  100. if($this->_bIsApi) {
  101. $aCounter = $oConnection->getCounterAPI($iContentProfileId, true, [
  102. 'content_type' => BX_CONNECTIONS_CONTENT_TYPE_INITIATORS,
  103. 'caption' => $aItem['title']
  104. ]);
  105. $sUrl = $this->_oContentProfile->getUrl();
  106. if(!empty($CNF['URI_VIEW_FRIENDS']))
  107. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_FRIENDS'] . '&profile_id=' . $iContentProfileId));
  108. return $this->_getMenuItemAPI($aItem, ['display' => 'button'], [
  109. 'title' => $aCounter['countf'],
  110. 'link' => bx_api_get_relative_url($sUrl),
  111. 'list' => $oConnection->getConnectedListAPI($iContentProfileId, true, BX_CONNECTIONS_CONTENT_TYPE_CONTENT)
  112. ]);
  113. }
  114. return $oConnection->getCounter($iContentProfileId, true, [
  115. 'content_type' => BX_CONNECTIONS_CONTENT_TYPE_INITIATORS,
  116. 'caption' => $aItem['title'],
  117. 'custom_icon' => BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '')
  118. ]);
  119. }
  120. protected function _getMenuItemSubscribers($aItem)
  121. {
  122. $CNF = &$this->_oModule->_oConfig->CNF;
  123. if(!$this->_bContentPublic || !$this->_oContentProfile)
  124. return false;
  125. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  126. if(!$oConnection)
  127. return false;
  128. $iContentProfileId = $this->_oContentProfile->id();
  129. if($this->_bIsApi) {
  130. $aCounter = $oConnection->getCounterAPI($iContentProfileId, false, [
  131. 'content_type' => BX_CONNECTIONS_CONTENT_TYPE_INITIATORS,
  132. 'caption' => $aItem['title']
  133. ]);
  134. $sUrl = $this->_oContentProfile->getUrl();
  135. if(!empty($CNF['URI_VIEW_SUBSCRIPTIONS']))
  136. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_SUBSCRIPTIONS'] . '&profile_id=' . $iContentProfileId));
  137. return $this->_getMenuItemAPI($aItem, ['display' => 'button'], [
  138. 'title' => $aCounter['countf'],
  139. 'link' => bx_api_get_relative_url($sUrl),
  140. 'list' => $oConnection->getConnectedListAPI($iContentProfileId, false, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS)
  141. ]);
  142. }
  143. return $oConnection->getCounter($iContentProfileId, false, [
  144. 'content_type' => BX_CONNECTIONS_CONTENT_TYPE_INITIATORS,
  145. 'caption' => $aItem['title'],
  146. 'custom_icon' => BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '')
  147. ]);
  148. }
  149. protected function _getMenuItemRelations($aItem)
  150. {
  151. $CNF = &$this->_oModule->_oConfig->CNF;
  152. if(!$this->_bContentPublic || !$this->_oContentProfile)
  153. return false;
  154. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_relations');
  155. if(!$oConnection)
  156. return false;
  157. $iContentProfileId = $this->_oContentProfile->id();
  158. if($this->_bIsApi) {
  159. $aCounter = $oConnection->getCounterAPI($iContentProfileId, false, [
  160. 'content_type' => BX_CONNECTIONS_CONTENT_TYPE_INITIATORS,
  161. 'caption' => $aItem['title']
  162. ]);
  163. $sUrl = $this->_oContentProfile->getUrl();
  164. if(!empty($CNF['URI_VIEW_RELATIONS']))
  165. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_RELATIONS'] . '&profile_id=' . $iContentProfileId));
  166. return $this->_getMenuItemAPI($aItem, ['display' => 'button'], [
  167. 'title' => $aCounter['countf'],
  168. 'link' => bx_api_get_relative_url($sUrl),
  169. 'list' => $oConnection->getConnectedListAPI($iContentProfileId, false, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS)
  170. ]);
  171. }
  172. return $oConnection->getCounter($iContentProfileId, true, [
  173. 'content_type' => BX_CONNECTIONS_CONTENT_TYPE_INITIATORS,
  174. 'caption' => $aItem['title'],
  175. 'custom_icon' => BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '')
  176. ]);
  177. }
  178. protected function _getMenuItemViews($aItem)
  179. {
  180. $CNF = &$this->_oModule->_oConfig->CNF;
  181. if($this->_bIsApi)
  182. return false;
  183. if(empty($CNF['OBJECT_VIEWS']) || empty($CNF['FIELD_VIEWS']) || (empty($this->_aContentInfo[$CNF['FIELD_VIEWS']]) && !$this->_bShowZeros))
  184. return false;
  185. $oObject = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $this->_aContentInfo[$CNF['FIELD_ID']]) : null;
  186. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  187. return $oObject ? $oObject->getCounter(['show_counter_empty' => false, 'show_counter_in_brackets' => false, 'dynamic_mode' => true, 'caption' => '_view_n_views', 'custom_icon' => $sIcon]) : '';
  188. }
  189. protected function _getMenuItemVotes($aItem)
  190. {
  191. $CNF = &$this->_oModule->_oConfig->CNF;
  192. if($this->_bIsApi)
  193. return false;
  194. if(empty($CNF['OBJECT_VOTES']) || empty($CNF['FIELD_VOTES']) || (empty($this->_aContentInfo[$CNF['FIELD_VOTES']]) && !$this->_bShowZeros))
  195. return false;
  196. $sIcon = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '');
  197. $oObject = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  198. if(!$oObject || !$oObject->isEnabled())
  199. return '';
  200. return $oObject->getCounter([
  201. 'show_counter_label_icon' => true,
  202. 'show_counter_empty' => false,
  203. 'dynamic_mode' => true,
  204. 'caption' => '_vote_n_votes',
  205. 'custom_icon' => $sIcon
  206. ]);
  207. }
  208. protected function _getMenuItemReactions($aItem)
  209. {
  210. $CNF = &$this->_oModule->_oConfig->CNF;
  211. if($this->_bIsApi)
  212. return false;
  213. $sKo = 'OBJECT_REACTIONS';
  214. if(($sKf = 'FIELD_REACTIONS') && (empty($CNF[$sKo]) || empty($CNF[$sKf]) || (empty($this->_aContentInfo[$CNF[$sKf]]) && !$this->_bShowZeros)))
  215. return false;
  216. $oObject = BxDolVote::getObjectInstance($CNF[$sKo], $this->_aContentInfo[$CNF['FIELD_ID']]);
  217. if(!$oObject || !$oObject->isEnabled())
  218. return false;
  219. return $oObject->getCounter([
  220. 'show_counter_style' => 'compound',
  221. 'show_counter_empty' => false,
  222. 'dynamic_mode' => true
  223. ]);
  224. }
  225. protected function _getMenuItemScores($aItem)
  226. {
  227. $CNF = &$this->_oModule->_oConfig->CNF;
  228. if($this->_bIsApi)
  229. return false;
  230. $sKo = 'OBJECT_SCORES';
  231. 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)))
  232. return false;
  233. $oObject = BxDolScore::getObjectInstance($CNF[$sKo], $this->_aContentInfo[$CNF['FIELD_ID']]);
  234. if(!$oObject || !$oObject->isEnabled())
  235. return false;
  236. return $oObject->getCounter([
  237. 'show_counter_label_icon' => true,
  238. 'show_counter_empty' => false,
  239. 'dynamic_mode' => true,
  240. ]);
  241. }
  242. protected function _getMenuItemComments($aItem)
  243. {
  244. $CNF = &$this->_oModule->_oConfig->CNF;
  245. if($this->_bIsApi)
  246. return false;
  247. if(empty($CNF['OBJECT_COMMENTS']) || empty($CNF['FIELD_COMMENTS']) || (empty($this->_aContentInfo[$CNF['FIELD_COMMENTS']]) && !$this->_bShowZeros))
  248. return false;
  249. $oComments = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  250. if(!$oComments || !$oComments->isEnabled())
  251. return false;
  252. $oObject = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]) : null;
  253. return $oObject ? $oObject->getCounter([
  254. 'overwrite_counter_link_onclick' => 'javascript:void(0)',
  255. 'show_counter_empty' => false,
  256. 'recalculate_counter' => true,
  257. 'dynamic_mode' => true,
  258. 'caption' => '_cmt_txt_n_comments',
  259. 'custom_icon' => BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconAsHtml(!empty($aItem['icon']) ? $aItem['icon'] : '')
  260. ]) : '';
  261. }
  262. protected function _retrieveContentId()
  263. {
  264. if(bx_get('id') !== false)
  265. $this->setContentId(bx_process_input(bx_get('id'), BX_DATA_INT));
  266. if(empty($this->_iContentId) && bx_get('profile_id') !== false)
  267. $this->setContentId(BxDolProfile::getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT))->getContentId());
  268. }
  269. }
  270. /** @} */