1
0

BxBaseCmtsMenuUnitMeta.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Menu representation.
  11. * @see BxDolMenu
  12. */
  13. class BxBaseCmtsMenuUnitMeta extends BxTemplMenuUnitMeta
  14. {
  15. protected $_oCmts;
  16. protected $_aCmtsSystem;
  17. protected $_aCmt;
  18. protected $_sCmtStylePrefix;
  19. public function __construct ($aObject, $oTemplate)
  20. {
  21. parent::__construct ($aObject, $oTemplate);
  22. }
  23. public function setCmtsData($oCmts, $iCmtId)
  24. {
  25. if(empty($oCmts) || empty($iCmtId))
  26. return;
  27. $this->_oCmts = $oCmts;
  28. $this->_aCmtsSystem = $oCmts->getSystemInfo();
  29. $this->_aCmt = $oCmts->getCommentRow($iCmtId);
  30. $this->_sCmtStylePrefix = (!empty($this->_aCmtsSystem['root_style_prefix']) ? $this->_aCmtsSystem['root_style_prefix'] : 'cmt');
  31. $this->_sStylePrefix = $this->_sCmtStylePrefix . '-meta bx-base-general-unit-meta';
  32. $this->addMarkers(array(
  33. 'cmt_system' => $this->_oCmts->getSystemName(),
  34. 'cmt_object_id' => $this->_oCmts->getId(),
  35. 'cmt_id' => $iCmtId,
  36. 'content_id' => $iCmtId,
  37. ));
  38. }
  39. protected function _getMenuItemInReplyTo($aItem)
  40. {
  41. if((int)$this->_aCmt['cmt_parent_id'] == 0)
  42. return '';
  43. $aParent = $this->_oCmts->getCommentRow($this->_aCmt['cmt_parent_id']);
  44. if(empty($aParent) || !is_array($aParent))
  45. return '';
  46. $oProfile = BxDolProfile::getInstanceMagic((int)$aParent['cmt_author_id']);
  47. $sParAuthorName = $oProfile->getDisplayName();
  48. $sParAuthorUnit = $oProfile->getUnit(0, array('template' => array('name' => 'unit_wo_info_links', 'size' => 'icon')));
  49. $sResult = $this->_oTemplate->parseHtmlByName('comment_reply_to.html', array(
  50. 'style_prefix' => $this->_sCmtStylePrefix,
  51. 'par_cmt_link' => $this->_oCmts->getItemUrl($this->_aCmt['cmt_parent_id']),
  52. 'par_cmt_title' => bx_html_attribute(_t('_in_reply_to_x', $sParAuthorName)),
  53. 'par_cmt_author' => $sParAuthorName,
  54. 'par_cmt_author_unit' => $sParAuthorUnit
  55. ));
  56. return $this->getUnitMetaItemCustom($sResult);
  57. }
  58. protected function _getMenuItemAuthor($aItem)
  59. {
  60. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit, $sAuthorBadges) = $this->_oCmts->getAuthorInfo($this->_aCmt['cmt_author_id']);
  61. $sResult = '';
  62. if(!empty($sAuthorLink))
  63. $sResult = $this->getUnitMetaItemLink($sAuthorName, array(
  64. 'href' => $sAuthorLink,
  65. 'class' => $this->_sStylePrefix . '-username',
  66. 'title' => bx_html_attribute($sAuthorName),
  67. )). $sAuthorBadges;
  68. else
  69. $sResult = $this->getUnitMetaItemText($sAuthorName, array(
  70. 'class' => $this->_sStylePrefix . '-username'
  71. )). $sAuthorBadges;
  72. return $sResult;
  73. }
  74. protected function _getMenuItemDate($aItem)
  75. {
  76. $sAgo = bx_time_js($this->_aCmt['cmt_time']);
  77. if(!empty($this->_aCmtsSystem['trigger_field_title']))
  78. return $this->getUnitMetaItemLink($sAgo, array(
  79. 'href' => $this->_oCmts->getViewUrl($this->_aCmt['cmt_id']),
  80. 'class' => $this->_sStylePrefix . '-ago'
  81. ));
  82. else
  83. return $this->getUnitMetaItemText($sAgo, array(
  84. 'class' => $this->_sStylePrefix . '-ago'
  85. ));
  86. }
  87. protected function _getMenuItemMembership($aItem)
  88. {
  89. $iUserId = bx_get_logged_profile_id();
  90. $iAuthorId = (int)$this->_aCmt['cmt_author_id'];
  91. if($iAuthorId < 0 && (abs($iAuthorId) == $iUserId || $this->_oCmts->isModerator()))
  92. $iAuthorId *= -1;
  93. $aMembership = BxDolAcl::getInstance()->getMemberMembershipInfo($iAuthorId);
  94. if(empty($aMembership) || !is_array($aMembership))
  95. return '';
  96. return $this->getUnitMetaItemText($iAuthorId < 0 ? _t('_anonymous') : _t($aMembership['name']), array(
  97. 'class' => $this->_sStylePrefix . '-membership'
  98. ));
  99. }
  100. protected function _getMenuItemDefault($aItem)
  101. {
  102. $sResult = false;
  103. /**
  104. * @hooks
  105. * @hookdef hook-comment-menu_custom_item 'comment', 'menu_custom_item' - hook to override menu item
  106. * - $unit_name - equals `comment`
  107. * - $action - equals `menu_custom_item`
  108. * - $object_id - not used
  109. * - $sender_id - not used
  110. * - $extra_params - array of additional params with the following array keys:
  111. * - `res` - [string] by ref, menu item code, can be overridden in hook processing
  112. * - `menu` - [string] menu name
  113. * - `menu_object` - [object] an instance of menu, @see BxDolMenu
  114. * - `item` - [array] menu item array as key&value pairs
  115. * - `content_id` - [int] content id
  116. * - `content_data` - [array] content info array as key&value pairs
  117. * - `cmts_object` - [object] an instance of comments, @see BxDolCmts
  118. * @hook @ref hook-comment-menu_custom_item
  119. */
  120. bx_alert('comment', 'menu_custom_item', 0, 0, [
  121. 'res' => &$sResult,
  122. 'menu' => $this->_sObject,
  123. 'menu_object' => $this,
  124. 'item' => $aItem,
  125. 'content_id' => $this->_aCmt['cmt_id'],
  126. 'content_data' => $this->_aCmt,
  127. 'cmts_object' => $this->_oCmts
  128. ]);
  129. if (false !== $sResult)
  130. return $sResult;
  131. return parent::_getMenuItemDefault($aItem);
  132. }
  133. }
  134. /** @} */