BxBaseModGeneralMenuSnippetMeta.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModGeneralMenuSnippetMeta extends BxTemplMenuUnitMeta
  12. {
  13. protected $_bShowZeros;
  14. protected $_sModule;
  15. protected $_oModule;
  16. protected $_iContentId;
  17. protected $_aContentInfo;
  18. public function __construct($aObject, $oTemplate = false)
  19. {
  20. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  21. if(empty($oTemplate))
  22. $oTemplate = $this->_oModule->_oTemplate;
  23. parent::__construct($aObject, $oTemplate);
  24. $this->_sStylePrefix = 'bx-base-general-unit-meta';
  25. $this->_bShowZeros = false;
  26. }
  27. public function getCode()
  28. {
  29. if(empty($this->_aContentInfo) || !is_array($this->_aContentInfo))
  30. return '';
  31. return parent::getCode();
  32. }
  33. public function setContentId($iContentId)
  34. {
  35. $this->_iContentId = (int)$iContentId;
  36. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iContentId);
  37. if($this->_aContentInfo)
  38. $this->addMarkers(array('content_id' => (int)$this->_iContentId));
  39. }
  40. protected function _getMenuItemAuthor($aItem)
  41. {
  42. $CNF = &$this->_oModule->_oConfig->CNF;
  43. $oProfile = BxDolProfile::getInstanceMagic($this->_aContentInfo[$CNF['FIELD_AUTHOR']]);
  44. return $this->getUnitMetaItemLink($oProfile->getDisplayName(), array(
  45. 'href' => $oProfile->getUrl(),
  46. 'class' => 'bx-base-text-unit-author'
  47. ));
  48. }
  49. protected function _getMenuItemDate($aItem)
  50. {
  51. $CNF = &$this->_oModule->_oConfig->CNF;
  52. if ($aItem['icon'] == '')
  53. return $this->getUnitMetaItemText(bx_time_js($this->_aContentInfo[$CNF['FIELD_ADDED']], BX_FORMAT_DATE));
  54. else
  55. return $this->getUnitMetaItemExtended(bx_time_js($this->_aContentInfo[$CNF['FIELD_ADDED']], BX_FORMAT_DATE), $aItem['icon'], '');
  56. }
  57. protected function _getMenuItemCategory($aItem)
  58. {
  59. $CNF = &$this->_oModule->_oConfig->CNF;
  60. if(empty($CNF['OBJECT_CATEGORY']) || empty($CNF['FIELD_CATEGORY']) || empty($this->_aContentInfo[$CNF['FIELD_CATEGORY']]))
  61. return false;
  62. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  63. if(!$oCategory)
  64. return false;
  65. $sTitle = $oCategory->getCategoryTitle($this->_aContentInfo[$CNF['FIELD_CATEGORY']]);
  66. return $this->getUnitMetaItemCustom($oCategory->getCategoryLink($sTitle, $this->_aContentInfo[$CNF['FIELD_CATEGORY']]));
  67. }
  68. protected function _getMenuItemTags($aItem)
  69. {
  70. $CNF = &$this->_oModule->_oConfig->CNF;
  71. if(empty($CNF['OBJECT_METATAGS']))
  72. return false;
  73. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  74. if(!$oMetatags || !$oMetatags->keywordsIsEnabled())
  75. return false;
  76. return $this->getUnitMetaItemCustom($oMetatags->getKeywordsList($this->_aContentInfo[$CNF['FIELD_ID']], 3));
  77. }
  78. protected function _getMenuItemViews($aItem)
  79. {
  80. $CNF = &$this->_oModule->_oConfig->CNF;
  81. if(empty($CNF['FIELD_VIEWS']) || (empty($this->_aContentInfo[$CNF['FIELD_VIEWS']]) && !$this->_bShowZeros))
  82. return false;
  83. return $this->getUnitMetaItemText(_t('_view_n_views', $this->_aContentInfo[$CNF['FIELD_VIEWS']]));
  84. }
  85. protected function _getMenuItemVotes($aItem)
  86. {
  87. $CNF = &$this->_oModule->_oConfig->CNF;
  88. if(empty($CNF['OBJECT_VOTES']) || (empty($this->_aContentInfo[$CNF['FIELD_VOTES']]) && !$this->_bShowZeros))
  89. return false;
  90. return $this->getUnitMetaItemText(_t('_vote_n_votes', $this->_aContentInfo[$CNF['FIELD_VOTES']]));
  91. }
  92. protected function _getMenuItemRating($aItem)
  93. {
  94. $CNF = &$this->_oModule->_oConfig->CNF;
  95. if(empty($CNF['OBJECT_VOTES_STARS']))
  96. return false;
  97. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_STARS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  98. if(!$oVotes)
  99. return false;
  100. return $this->getUnitMetaItemCustom($oVotes->getElementInline(array('show_counter' => true)));
  101. }
  102. protected function _getMenuItemReactions($aItem)
  103. {
  104. $CNF = &$this->_oModule->_oConfig->CNF;
  105. if(empty($CNF['OBJECT_REACTIONS']))
  106. return false;
  107. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  108. if(!$oVotes)
  109. return false;
  110. return $this->getUnitMetaItemCustom($oVotes->getElementInline(array('show_counter' => false)));
  111. }
  112. protected function _getMenuItemComments($aItem)
  113. {
  114. $CNF = &$this->_oModule->_oConfig->CNF;
  115. if(empty($CNF['OBJECT_COMMENTS']) || empty($CNF['FIELD_COMMENTS']) || (empty($this->_aContentInfo[$CNF['FIELD_COMMENTS']]) && !$this->_bShowZeros))
  116. return false;
  117. $oComments = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  118. if(!$oComments || !$oComments->isEnabled())
  119. return false;
  120. return $this->getUnitMetaItemLink(_t('_cmt_txt_n_comments', $this->_aContentInfo[$CNF['FIELD_COMMENTS']]), array(
  121. 'href' => $oComments->getListUrl()
  122. ));
  123. }
  124. protected function _getMenuItemDefault($aItem)
  125. {
  126. $sResult = false;
  127. $a = array(
  128. 'res' => &$sResult,
  129. 'menu' => $this->_sObject,
  130. 'menu_object' => $this,
  131. 'item' => $aItem,
  132. 'module' => $this->_sModule,
  133. 'content_id' => $this->_iContentId,
  134. 'content_data' => $this->_aContentInfo,
  135. );
  136. bx_alert($this->_sModule, 'menu_custom_item', 0, 0, $a);
  137. bx_alert('menu', 'menu_custom_item', 0, 0, $a);
  138. if (false !== $sResult)
  139. return $sResult;
  140. return parent::_getMenuItemDefault($aItem);
  141. }
  142. }
  143. /** @} */