BxBaseModGeneralMenuSnippetMeta.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 _getMenuItemRating($aItem)
  83. {
  84. $CNF = &$this->_oModule->_oConfig->CNF;
  85. if(empty($CNF['OBJECT_VOTES_STARS']))
  86. return false;
  87. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_STARS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  88. if(!$oVotes)
  89. return false;
  90. return $this->getUnitMetaItemCustom($oVotes->getElementInline(array('show_counter' => true)));
  91. }
  92. protected function _getMenuItemComments($aItem)
  93. {
  94. $CNF = &$this->_oModule->_oConfig->CNF;
  95. if(empty($CNF['OBJECT_COMMENTS']) || empty($CNF['FIELD_COMMENTS']) || (empty($this->_aContentInfo[$CNF['FIELD_COMMENTS']]) && !$this->_bShowZeros))
  96. return false;
  97. $oComments = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  98. if(!$oComments || !$oComments->isEnabled())
  99. return false;
  100. return $this->getUnitMetaItemLink(_t('_cmt_txt_n_comments', $this->_aContentInfo[$CNF['FIELD_COMMENTS']]), array(
  101. 'href' => $oComments->getListUrl()
  102. ));
  103. }
  104. protected function _getMenuItemDefault($aItem)
  105. {
  106. $sResult = false;
  107. $a = array(
  108. 'res' => &$sResult,
  109. 'menu' => $this->_sObject,
  110. 'menu_object' => $this,
  111. 'item' => $aItem,
  112. 'module' => $this->_sModule,
  113. 'content_id' => $this->_iContentId,
  114. 'content_data' => $this->_aContentInfo,
  115. );
  116. bx_alert($this->_sModule, 'menu_custom_item', 0, 0, $a);
  117. bx_alert('menu', 'menu_custom_item', 0, 0, $a);
  118. if (false !== $sResult)
  119. return $sResult;
  120. return parent::_getMenuItemDefault($aItem);
  121. }
  122. }
  123. /** @} */