1
0

BxBaseModProfileMenuViewMeta.php 13 KB

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