1
0

BxBaseModGeneralMenuSnippetMeta.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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::getInstanceMagic($this->_aContentInfo[$CNF['FIELD_AUTHOR']]);
  41. return $this->_oTemplate->getUnitMetaItemLink($oProfile->getDisplayName(), array(
  42. 'href' => $oProfile->getUrl(),
  43. 'class' => 'bx-base-text-unit-author'
  44. ));
  45. }
  46. protected function _getMenuItemDate($aItem)
  47. {
  48. $CNF = &$this->_oModule->_oConfig->CNF;
  49. return $this->_oTemplate->getUnitMetaItemText(bx_time_js($this->_aContentInfo[$CNF['FIELD_ADDED']], BX_FORMAT_DATE));
  50. }
  51. protected function _getMenuItemCategory($aItem)
  52. {
  53. $CNF = &$this->_oModule->_oConfig->CNF;
  54. if(empty($CNF['OBJECT_CATEGORY']) || empty($CNF['FIELD_CATEGORY']) || empty($this->_aContentInfo[$CNF['FIELD_CATEGORY']]))
  55. return false;
  56. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  57. if(!$oCategory)
  58. return false;
  59. $sTitle = $oCategory->getCategoryTitle($this->_aContentInfo[$CNF['FIELD_CATEGORY']]);
  60. return $this->_oTemplate->getUnitMetaItemCustom($oCategory->getCategoryLink($sTitle, $this->_aContentInfo[$CNF['FIELD_CATEGORY']]));
  61. }
  62. protected function _getMenuItemTags($aItem)
  63. {
  64. $CNF = &$this->_oModule->_oConfig->CNF;
  65. if(empty($CNF['OBJECT_METATAGS']))
  66. return false;
  67. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  68. if(!$oMetatags || !$oMetatags->keywordsIsEnabled())
  69. return false;
  70. return $this->_oTemplate->getUnitMetaItemCustom($oMetatags->getKeywordsList($this->_aContentInfo[$CNF['FIELD_ID']], 3));
  71. }
  72. protected function _getMenuItemViews($aItem)
  73. {
  74. $CNF = &$this->_oModule->_oConfig->CNF;
  75. if(empty($CNF['FIELD_VIEWS']) || (empty($this->_aContentInfo[$CNF['FIELD_VIEWS']]) && !$this->_bShowZeros))
  76. return false;
  77. return $this->_oTemplate->getUnitMetaItemText(_t('_view_n_views', $this->_aContentInfo[$CNF['FIELD_VIEWS']]));
  78. }
  79. protected function _getMenuItemRating($aItem)
  80. {
  81. $CNF = &$this->_oModule->_oConfig->CNF;
  82. if(empty($CNF['OBJECT_VOTES_STARS']))
  83. return false;
  84. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_STARS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  85. if(!$oVotes)
  86. return false;
  87. return $this->_oTemplate->getUnitMetaItemCustom($oVotes->getElementInline(array('show_counter' => true)));
  88. }
  89. protected function _getMenuItemComments($aItem)
  90. {
  91. $CNF = &$this->_oModule->_oConfig->CNF;
  92. if(empty($CNF['OBJECT_COMMENTS']) || empty($CNF['FIELD_COMMENTS']) || (empty($this->_aContentInfo[$CNF['FIELD_COMMENTS']]) && !$this->_bShowZeros))
  93. return false;
  94. $oComments = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  95. if(!$oComments || !$oComments->isEnabled())
  96. return false;
  97. return $this->_oTemplate->getUnitMetaItemLink(_t('_cmt_txt_n_comments', $this->_aContentInfo[$CNF['FIELD_COMMENTS']]), array(
  98. 'href' => $oComments->getListUrl()
  99. ));
  100. }
  101. protected function _getMenuItemDefault($aItem)
  102. {
  103. $sResult = '';
  104. if(!empty($aItem['link']))
  105. $sResult = $this->_oTemplate->getUnitMetaItemLink($aItem['title'], array(
  106. 'href' => $aItem['link']
  107. ));
  108. else if(!empty($aItem['onclick']))
  109. $sResult = $this->_oTemplate->getUnitMetaItemButtonSmall($aItem['title'], array(
  110. 'onclick' => $aItem['onclick']
  111. ));
  112. else
  113. $sResult = $this->_oTemplate->getUnitMetaItemText($aItem['title']);
  114. return $sResult;
  115. }
  116. }
  117. /** @} */