1
0

BxBaseModGeneralMenuSnippetMeta.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 $_sModule;
  14. protected $_oModule;
  15. protected $_iContentId;
  16. protected $_aContentInfo;
  17. public function __construct($aObject, $oTemplate = false)
  18. {
  19. parent::__construct($aObject, $oTemplate);
  20. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  21. }
  22. public function getCode()
  23. {
  24. if(empty($this->_aContentInfo) || !is_array($this->_aContentInfo))
  25. return '';
  26. return parent::getCode();
  27. }
  28. public function setContentId($iContentId)
  29. {
  30. $this->_iContentId = (int)$iContentId;
  31. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iContentId);
  32. if($this->_aContentInfo)
  33. $this->addMarkers(array('content_id' => (int)$this->_iContentId));
  34. }
  35. protected function _getMenuItemAuthor($aItem)
  36. {
  37. $CNF = &$this->_oModule->_oConfig->CNF;
  38. $oProfile = BxDolProfile::getInstance($this->_aContentInfo[$CNF['FIELD_AUTHOR']]);
  39. if(!$oProfile)
  40. $oProfile = BxDolProfileUndefined::getInstance();
  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']]))
  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']]))
  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. }
  102. /** @} */