BxForumTemplate.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 Forum Forum
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Module representation.
  13. */
  14. class BxForumTemplate extends BxBaseModTextTemplate
  15. {
  16. /**
  17. * Constructor
  18. */
  19. function __construct(&$oConfig, &$oDb)
  20. {
  21. $this->MODULE = 'bx_forum';
  22. parent::__construct($oConfig, $oDb);
  23. }
  24. public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
  25. {
  26. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  27. $oPermalink = BxDolPermalinks::getInstance();
  28. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  29. $aTmplVarsItems = array(array(
  30. 'url' => bx_append_url_params($oPermalink->permalink('page.php?i=' . $CNF['URI_CATEGORY_ENTRIES']), array(
  31. 'category' => $aContentInfo[$CNF['FIELD_CATEGORY']]
  32. )),
  33. 'title' => $oCategory->getCategoryTitle($aContentInfo[$CNF['FIELD_CATEGORY']])
  34. ), array(
  35. 'url' => $oPermalink->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  36. 'title' => bx_process_output($aContentInfo[$CNF['FIELD_TITLE']])
  37. ));
  38. return parent::entryBreadcrumb($aContentInfo, $aTmplVarsItems);
  39. }
  40. public function entryParticipants($aContentInfo, $iMaxVisible = 2, $sFloat = 'left')
  41. {
  42. $oModule = BxDolModule::getInstance($this->MODULE);
  43. $CNF = &$oModule->_oConfig->CNF;
  44. $iAuthorId = $aContentInfo[$CNF['FIELD_AUTHOR']];
  45. $aParticipants = $this->_oDb->getComments(array('type' => 'author_comments', 'object_id' => $aContentInfo[$CNF['FIELD_ID']]));
  46. $aParticipants[$iAuthorId] = !empty($aParticipants[$iAuthorId]) ? $aParticipants[$iAuthorId] + 1 : 1;
  47. // sort participants: first - current user, second - last replier, third - author, all others sorted by max number of posts
  48. $aParticipants = $oModule->sortParticipants($aParticipants, $aContentInfo['lr_profile_id'], $iAuthorId);
  49. $iParticipantsNum = count($aParticipants);
  50. // prepare template variables
  51. $aVarsPopup = array (
  52. 'float' => 'none',
  53. 'bx_repeat:participants' => array(),
  54. 'bx_if:participants_more' => array(
  55. 'condition' => false,
  56. 'content' => array(),
  57. ),
  58. );
  59. $aVars = array (
  60. 'float' => $sFloat,
  61. 'bx_repeat:participants' => array(),
  62. 'bx_if:participants_more' => array(
  63. 'condition' => $iParticipantsNum > $iMaxVisible,
  64. 'content' => array(
  65. 'popup' => '',
  66. 'title_more' => _t('_bx_forum_more', $iParticipantsNum - $iMaxVisible),
  67. 'float' => $sFloat,
  68. 'id' => $this->MODULE . '-popup-' . $aContentInfo[$CNF['FIELD_ID']],
  69. ),
  70. ),
  71. );
  72. $i = 0;
  73. foreach ($aParticipants as $iProfileId => $iComments) {
  74. $oProfile = BxDolProfile::getInstanceMagic($iProfileId);
  75. $aParticipant = array (
  76. 'id' => $oProfile->id(),
  77. 'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  78. 'float' => $sFloat,
  79. 'class' => $iAuthorId == $iProfileId ? 'bx-forum-participant-author' : '',
  80. 'bx_if:replies_count' => array(
  81. 'condition' => $iComments > 0,
  82. 'content' => array(
  83. 'count' => $iComments
  84. )
  85. ),
  86. 'bx_if:last_replier' => array (
  87. 'condition' => ($aContentInfo['lr_profile_id'] == $iProfileId),
  88. 'content' => array (
  89. 'id' => $oProfile->id(),
  90. 'title' => bx_html_attribute(_t('_bx_forum_participant_last_replier')),
  91. ),
  92. ),
  93. 'bx_if:author' => array (
  94. 'condition' => $iAuthorId == $iProfileId,
  95. 'content' => array (
  96. 'id' => $oProfile->id(),
  97. 'title' => bx_html_attribute(_t('_bx_forum_participant_author')),
  98. ),
  99. ),
  100. );
  101. if ($i < $iMaxVisible)
  102. $aVars['bx_repeat:participants'][] = $aParticipant;
  103. if ($i >= $iMaxVisible)
  104. $aVarsPopup['bx_repeat:participants'][] = $aParticipant;
  105. ++$i;
  106. }
  107. if ($aVarsPopup['bx_repeat:participants']) {
  108. $aVars['bx_if:participants_more']['content']['popup'] = BxTemplFunctions::getInstance()->transBox('', '<div class="bx-def-padding">' . $this->parseHtmlByName('participants.html', $aVarsPopup) . '</div>');
  109. }
  110. return $this->parseHtmlByName('participants.html', $aVars);
  111. }
  112. function getEntryAuthor($aRow)
  113. {
  114. $oProfileAuthor = BxDolProfile::getInstanceMagic($aRow['author']);
  115. return $this->parseHtmlByName('entry-author.html', array(
  116. 'unit' => $oProfileAuthor->getUnit(0, array('template' => 'unit_wo_info')),
  117. ));
  118. }
  119. function getEntryPreview($aRow, $aParams = [])
  120. {
  121. $oModule = BxDolModule::getInstance($this->MODULE);
  122. $CNF = &$oModule->_oConfig->CNF;
  123. if($this->_oModule->checkAllowedView($aRow) !== CHECK_ACTION_RESULT_ALLOWED)
  124. return $this->parseHtmlByName('entry-preview-private.html', []);
  125. $oProfileLast = BxDolProfile::getInstanceMagic($aRow['lr_profile_id']);
  126. $sTitle = $aRow[$CNF['FIELD_TITLE']];
  127. $aMetas = array('main' => false, 'counters' => false, 'reply' => false);
  128. foreach(array_keys($aMetas) as $sMeta) {
  129. $sKey = 'OBJECT_MENU_SNIPPET_META_' . strtoupper($sMeta);
  130. if(empty($CNF[$sKey]))
  131. continue;
  132. $oMenuMeta = BxDolMenu::getObjectInstance($CNF[$sKey], $this);
  133. if(!$oMenuMeta)
  134. continue;
  135. $oMenuMeta->setContentId($aRow[$CNF['FIELD_ID']]);
  136. $sMenuMeta = $oMenuMeta->getCode();
  137. if(empty($sMenuMeta))
  138. continue;
  139. $aMetas[$sMeta] = array(
  140. 'content' => $sMenuMeta
  141. );
  142. }
  143. $oObject = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aRow[$CNF['FIELD_ID']]) : null;
  144. $sParticipants = $oObject ? $oObject->getCounter([
  145. 'caption' => '',
  146. 'caption_empty' => '',
  147. 'show_icon' => false,
  148. 'show_counter' => false,
  149. 'show_counter_empty' => true,
  150. 'show_counter_style' => 'simple',
  151. 'show_counter_reversed' => true,
  152. 'dynamic_mode' => true
  153. ]) : '';
  154. $sImage = '';
  155. $mixedImage = $this->_getHeaderImage($aRow);
  156. if($mixedImage !== false) {
  157. if(!empty($mixedImage['object']))
  158. $o = BxDolStorage::getObjectInstance($mixedImage['object']);
  159. else if(!empty($mixedImage['transcoder']))
  160. $o = BxDolTranscoder::getObjectInstance($mixedImage['transcoder']);
  161. if($o)
  162. $sImage = $o->getFileUrlById($mixedImage['id']);
  163. }
  164. return $this->parseHtmlByName('entry-preview.html', array(
  165. 'bx_if:show_stick' => array(
  166. 'condition' => (int)$aRow[$CNF['FIELD_STICK']] == 1,
  167. 'content' => array()
  168. ),
  169. 'bx_if:show_lock' => array(
  170. 'condition' => (int)$aRow[$CNF['FIELD_LOCK']] == 1,
  171. 'content' => array()
  172. ),
  173. 'url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']])),
  174. 'title' => $sTitle ? $sTitle : _t('_Empty'),
  175. 'participants' => $sParticipants,
  176. 'badges' => $this->_oModule->serviceGetBadges($aRow[$CNF['FIELD_ID']]),
  177. 'image' => $sImage,
  178. 'bx_if:meta_main' => array(
  179. 'condition' => $aMetas['main'] !== false && (!isset($aParams['show_meta_main']) || $aParams['show_meta_main']),
  180. 'content' => $aMetas['main']
  181. ),
  182. 'bx_if:image' => array(
  183. 'condition' => $sImage != '',
  184. 'content' => ['image' => $sImage]
  185. ),
  186. 'bx_if:meta_counters' => array(
  187. 'condition' => $aMetas['counters'] !== false && (!isset($aParams['show_meta_counters']) || $aParams['show_meta_counters']),
  188. 'content' => $aMetas['counters']
  189. ),
  190. 'bx_if:meta_reply' => array(
  191. 'condition' => $aMetas['reply'] !== false && (!isset($aParams['show_meta_reply']) || $aParams['show_meta_reply']),
  192. 'content' => $aMetas['reply']
  193. )
  194. ));
  195. }
  196. public function getJsCode($sType, $aParams = array(), $mixedWrap = true)
  197. {
  198. $CNF = $this->_oModule->_oConfig->CNF;
  199. if ($sType == 'main'){
  200. $aParams = array_merge(array(
  201. 'sObjNameGrid' => $CNF['OBJECT_GRID'],
  202. ), $aParams);
  203. }
  204. return parent::getJsCode($sType, $aParams);
  205. }
  206. function getAuthorDesc ($aData, $oProfile)
  207. {
  208. return '';
  209. }
  210. function getAuthorAddon ($aData, $oProfile)
  211. {
  212. return '';
  213. }
  214. protected function getUnit ($aData, $aParams = array())
  215. {
  216. $aTmplVars = parent::getUnit($aData, $aParams);
  217. $CNF = $this->_oModule->_oConfig->CNF;
  218. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  219. $sIcon = $this->_oModule->_oTemplate->parseHtmlByName('default_category.html', []);
  220. $aCategoryData = $this->_oModule->_oDb->getCategories(array('type' => 'by_category', 'category' => $aData[$CNF['FIELD_CATEGORY']]));
  221. if(isset($aCategoryData['icon']))
  222. $sIcon = $this->getImage($aCategoryData['icon'], array('class' => 'sys-icon'));
  223. $oProfile = BxDolProfile::getInstanceMagic($aData[$CNF['FIELD_AUTHOR']]);
  224. $aTmplVars['author'] = $oProfile->getUnit();
  225. $aTmplVars['category'] = $oCategory->getCategoryTitle($aData[$CNF['FIELD_CATEGORY']]);
  226. $aTmplVars['category_icon'] = $sIcon;
  227. $aTmplVars['bx_if:thumb']['content']['badges'] = $aTmplVars['badges'];
  228. $aTmplVars['bx_if:no_thumb']['content']['badges'] = $aTmplVars['badges'];
  229. $aTmplVars['bx_if:no_thumb']['content']['title'] = $aTmplVars['title'];
  230. $aTmplVars['bx_if:no_thumb']['content']['summary_attr'] = $aTmplVars['bx_if:thumb']['content']['summary_attr'];
  231. return $aTmplVars;
  232. }
  233. }
  234. /** @} */