1
0

BxBaseModGeneralMenuSnippetMeta.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. return $this->getUnitMetaItemText(bx_time_js($this->_aContentInfo[$CNF['FIELD_ADDED']], BX_FORMAT_DATE));
  53. }
  54. protected function _getMenuItemCategory($aItem)
  55. {
  56. $CNF = &$this->_oModule->_oConfig->CNF;
  57. if(empty($CNF['OBJECT_CATEGORY']) || empty($CNF['FIELD_CATEGORY']) || empty($this->_aContentInfo[$CNF['FIELD_CATEGORY']]))
  58. return false;
  59. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  60. if(!$oCategory)
  61. return false;
  62. $sTitle = $oCategory->getCategoryTitle($this->_aContentInfo[$CNF['FIELD_CATEGORY']]);
  63. return $this->getUnitMetaItemCustom($oCategory->getCategoryLink($sTitle, $this->_aContentInfo[$CNF['FIELD_CATEGORY']]));
  64. }
  65. protected function _getMenuItemTags($aItem)
  66. {
  67. $CNF = &$this->_oModule->_oConfig->CNF;
  68. if(empty($CNF['OBJECT_METATAGS']))
  69. return false;
  70. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  71. if(!$oMetatags || !$oMetatags->keywordsIsEnabled())
  72. return false;
  73. return $this->getUnitMetaItemCustom($oMetatags->getKeywordsList($this->_aContentInfo[$CNF['FIELD_ID']], 3));
  74. }
  75. protected function _getMenuItemViews($aItem)
  76. {
  77. $CNF = &$this->_oModule->_oConfig->CNF;
  78. if(empty($CNF['FIELD_VIEWS']) || (empty($this->_aContentInfo[$CNF['FIELD_VIEWS']]) && !$this->_bShowZeros))
  79. return false;
  80. return $this->getUnitMetaItemText(_t('_view_n_views', $this->_aContentInfo[$CNF['FIELD_VIEWS']]));
  81. }
  82. protected function _getMenuItemVotes($aItem)
  83. {
  84. $CNF = &$this->_oModule->_oConfig->CNF;
  85. if(empty($CNF['OBJECT_VOTES']) || (empty($this->_aContentInfo[$CNF['FIELD_VOTES']]) && !$this->_bShowZeros))
  86. return false;
  87. return $this->getUnitMetaItemText(_t('_vote_n_votes', $this->_aContentInfo[$CNF['FIELD_VOTES']]));
  88. }
  89. protected function _getMenuItemRating($aItem)
  90. {
  91. $CNF = &$this->_oModule->_oConfig->CNF;
  92. if(empty($CNF['OBJECT_VOTES_STARS']))
  93. return false;
  94. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_STARS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  95. if(!$oVotes)
  96. return false;
  97. return $this->getUnitMetaItemCustom($oVotes->getElementInline(array('show_counter' => true)));
  98. }
  99. protected function _getMenuItemReactions($aItem)
  100. {
  101. $CNF = &$this->_oModule->_oConfig->CNF;
  102. if(empty($CNF['OBJECT_REACTIONS']))
  103. return false;
  104. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  105. if(!$oVotes)
  106. return false;
  107. return $this->getUnitMetaItemCustom($oVotes->getElementInline(array('show_counter' => false)));
  108. }
  109. protected function _getMenuItemComments($aItem)
  110. {
  111. $CNF = &$this->_oModule->_oConfig->CNF;
  112. if(empty($CNF['OBJECT_COMMENTS']) || empty($CNF['FIELD_COMMENTS']) || (empty($this->_aContentInfo[$CNF['FIELD_COMMENTS']]) && !$this->_bShowZeros))
  113. return false;
  114. $oComments = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  115. if(!$oComments || !$oComments->isEnabled())
  116. return false;
  117. return $this->getUnitMetaItemLink(_t('_cmt_txt_n_comments', $this->_aContentInfo[$CNF['FIELD_COMMENTS']]), array(
  118. 'href' => $oComments->getListUrl()
  119. ));
  120. }
  121. protected function _getMenuItemDefault($aItem)
  122. {
  123. $sResult = false;
  124. $a = array(
  125. 'res' => &$sResult,
  126. 'menu' => $this->_sObject,
  127. 'menu_object' => $this,
  128. 'item' => $aItem,
  129. 'module' => $this->_sModule,
  130. 'content_id' => $this->_iContentId,
  131. 'content_data' => $this->_aContentInfo,
  132. );
  133. bx_alert($this->_sModule, 'menu_custom_item', 0, 0, $a);
  134. bx_alert('menu', 'menu_custom_item', 0, 0, $a);
  135. if (false !== $sResult)
  136. return $sResult;
  137. return parent::_getMenuItemDefault($aItem);
  138. }
  139. }
  140. /** @} */