BxBaseCmtsMenuUnitMeta.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. $bAuthorLink = !empty($sAuthorLink);
  62. $sResult = $this->_oTemplate->parseHtmlByName('comment_author.html', [
  63. 'style_prefix' => $this->_sCmtStylePrefix,
  64. 'bx_if:show_link' => [
  65. 'condition' => $bAuthorLink,
  66. 'content' => [
  67. 'style_prefix' => $this->_sCmtStylePrefix,
  68. 'href' => $sAuthorLink,
  69. 'title' => bx_html_attribute($sAuthorName),
  70. 'content' => $sAuthorName
  71. ]
  72. ],
  73. 'bx_if:show_text' => [
  74. 'condition' => !$bAuthorLink,
  75. 'content' => [
  76. 'style_prefix' => $this->_sCmtStylePrefix,
  77. 'content' => $sAuthorName
  78. ]
  79. ],
  80. 'badges' => $sAuthorBadges
  81. ]);
  82. return $this->getUnitMetaItemCustom($sResult);
  83. }
  84. protected function _getMenuItemDate($aItem)
  85. {
  86. $sAgo = bx_time_js($this->_aCmt['cmt_time']);
  87. if(!empty($this->_aCmtsSystem['trigger_field_title']))
  88. return $this->getUnitMetaItemLink($sAgo, array(
  89. 'href' => $this->_oCmts->getViewUrl($this->_aCmt['cmt_id']),
  90. 'class' => $this->_sStylePrefix . '-ago'
  91. ));
  92. else
  93. return $this->getUnitMetaItemText($sAgo, array(
  94. 'class' => $this->_sStylePrefix . '-ago'
  95. ));
  96. }
  97. protected function _getMenuItemMembership($aItem)
  98. {
  99. $iUserId = bx_get_logged_profile_id();
  100. $iAuthorId = (int)$this->_aCmt['cmt_author_id'];
  101. if($iAuthorId < 0 && (abs($iAuthorId) == $iUserId || $this->_oCmts->isModerator()))
  102. $iAuthorId *= -1;
  103. $aMembership = BxDolAcl::getInstance()->getMemberMembershipInfo($iAuthorId);
  104. if(empty($aMembership) || !is_array($aMembership))
  105. return '';
  106. return $this->getUnitMetaItemText($iAuthorId < 0 ? _t('_anonymous') : _t($aMembership['name']), array(
  107. 'class' => $this->_sStylePrefix . '-membership'
  108. ));
  109. }
  110. protected function _getMenuItemDefault($aItem)
  111. {
  112. $sResult = false;
  113. /**
  114. * @hooks
  115. * @hookdef hook-comment-menu_custom_item 'comment', 'menu_custom_item' - hook to override menu item
  116. * - $unit_name - equals `comment`
  117. * - $action - equals `menu_custom_item`
  118. * - $object_id - not used
  119. * - $sender_id - not used
  120. * - $extra_params - array of additional params with the following array keys:
  121. * - `res` - [string] by ref, menu item code, can be overridden in hook processing
  122. * - `menu` - [string] menu name
  123. * - `menu_object` - [object] an instance of menu, @see BxDolMenu
  124. * - `item` - [array] menu item array as key&value pairs
  125. * - `content_id` - [int] content id
  126. * - `content_data` - [array] content info array as key&value pairs
  127. * - `cmts_object` - [object] an instance of comments, @see BxDolCmts
  128. * @hook @ref hook-comment-menu_custom_item
  129. */
  130. bx_alert('comment', 'menu_custom_item', 0, 0, [
  131. 'res' => &$sResult,
  132. 'menu' => $this->_sObject,
  133. 'menu_object' => $this,
  134. 'item' => $aItem,
  135. 'content_id' => $this->_aCmt['cmt_id'],
  136. 'content_data' => $this->_aCmt,
  137. 'cmts_object' => $this->_oCmts
  138. ]);
  139. if (false !== $sResult)
  140. return $sResult;
  141. return parent::_getMenuItemDefault($aItem);
  142. }
  143. }
  144. /** @} */