BxBaseModGeneralMenuSnippetMeta.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 BxTemplMenuCustom
  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. parent::__construct($aObject, $oTemplate);
  21. $this->_bShowZeros = false;
  22. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  23. }
  24. public function getCode()
  25. {
  26. if(empty($this->_aContentInfo) || !is_array($this->_aContentInfo))
  27. return '';
  28. return parent::getCode();
  29. }
  30. public function setContentId($iContentId)
  31. {
  32. $this->_iContentId = (int)$iContentId;
  33. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iContentId);
  34. if($this->_aContentInfo)
  35. $this->addMarkers(array('content_id' => (int)$this->_iContentId));
  36. }
  37. protected function _getMenuItemAuthor($aItem)
  38. {
  39. $CNF = &$this->_oModule->_oConfig->CNF;
  40. $oProfile = BxDolProfile::getInstance($this->_aContentInfo[$CNF['FIELD_AUTHOR']]);
  41. if(!$oProfile)
  42. $oProfile = BxDolProfileUndefined::getInstance();
  43. return $this->_oTemplate->getUnitMetaItemLink($oProfile->getDisplayName(), array(
  44. 'href' => $oProfile->getUrl(),
  45. 'class' => 'bx-base-text-unit-author'
  46. ));
  47. }
  48. protected function _getMenuItemDate($aItem)
  49. {
  50. $CNF = &$this->_oModule->_oConfig->CNF;
  51. return $this->_oTemplate->getUnitMetaItemText(bx_time_js($this->_aContentInfo[$CNF['FIELD_ADDED']], BX_FORMAT_DATE));
  52. }
  53. protected function _getMenuItemCategory($aItem)
  54. {
  55. $CNF = &$this->_oModule->_oConfig->CNF;
  56. if(empty($CNF['OBJECT_CATEGORY']) || empty($CNF['FIELD_CATEGORY']) || empty($this->_aContentInfo[$CNF['FIELD_CATEGORY']]))
  57. return false;
  58. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  59. if(!$oCategory)
  60. return false;
  61. $sTitle = $oCategory->getCategoryTitle($this->_aContentInfo[$CNF['FIELD_CATEGORY']]);
  62. return $this->_oTemplate->getUnitMetaItemCustom($oCategory->getCategoryLink($sTitle, $this->_aContentInfo[$CNF['FIELD_CATEGORY']]));
  63. }
  64. protected function _getMenuItemTags($aItem)
  65. {
  66. $CNF = &$this->_oModule->_oConfig->CNF;
  67. if(empty($CNF['OBJECT_METATAGS']))
  68. return false;
  69. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  70. if(!$oMetatags || !$oMetatags->keywordsIsEnabled())
  71. return false;
  72. return $this->_oTemplate->getUnitMetaItemCustom($oMetatags->getKeywordsList($this->_aContentInfo[$CNF['FIELD_ID']], 3));
  73. }
  74. protected function _getMenuItemViews($aItem)
  75. {
  76. $CNF = &$this->_oModule->_oConfig->CNF;
  77. if(empty($CNF['FIELD_VIEWS']) || (empty($this->_aContentInfo[$CNF['FIELD_VIEWS']]) && !$this->_bShowZeros))
  78. return false;
  79. return $this->_oTemplate->getUnitMetaItemText(_t('_view_n_views', $this->_aContentInfo[$CNF['FIELD_VIEWS']]));
  80. }
  81. protected function _getMenuItemRating($aItem)
  82. {
  83. $CNF = &$this->_oModule->_oConfig->CNF;
  84. if(empty($CNF['OBJECT_VOTES_STARS']))
  85. return false;
  86. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_STARS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  87. if(!$oVotes)
  88. return false;
  89. return $this->_oTemplate->getUnitMetaItemCustom($oVotes->getElementInline(array('show_counter' => true)));
  90. }
  91. protected function _getMenuItemComments($aItem)
  92. {
  93. $CNF = &$this->_oModule->_oConfig->CNF;
  94. if(empty($CNF['OBJECT_COMMENTS']) || empty($CNF['FIELD_COMMENTS']) || (empty($this->_aContentInfo[$CNF['FIELD_COMMENTS']]) && !$this->_bShowZeros))
  95. return false;
  96. $oComments = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  97. if(!$oComments || !$oComments->isEnabled())
  98. return false;
  99. return $this->_oTemplate->getUnitMetaItemLink(_t('_cmt_txt_n_comments', $this->_aContentInfo[$CNF['FIELD_COMMENTS']]), array(
  100. 'href' => $oComments->getListUrl()
  101. ));
  102. }
  103. protected function _getMenuItemDefault($aItem)
  104. {
  105. $sResult = '';
  106. if(!empty($aItem['link']))
  107. $sResult = $this->_oTemplate->getUnitMetaItemLink($aItem['title'], array(
  108. 'href' => $aItem['link']
  109. ));
  110. else if(!empty($aItem['onclick']))
  111. $sResult = $this->_oTemplate->getUnitMetaItemButtonSmall($aItem['title'], array(
  112. 'onclick' => $aItem['onclick']
  113. ));
  114. else
  115. $sResult = $this->_oTemplate->getUnitMetaItemText($aItem['title']);
  116. return $sResult;
  117. }
  118. }
  119. /** @} */