BxBaseCmts.php 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565
  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. * @see BxDolCmts
  11. */
  12. class BxBaseCmts extends BxDolCmts
  13. {
  14. protected static $_sTmplContentElementBlock;
  15. protected static $_sTmplContentElementInline;
  16. protected static $_sTmplContentDoCommentLabel;
  17. protected static $_sTmplContentCounter;
  18. protected $_sTmplNameItem;
  19. protected $_sTmplNameItemContent;
  20. protected $_sJsObjClass;
  21. protected $_sJsObjName;
  22. protected $_sStylePrefix;
  23. protected $_aHtmlIds;
  24. protected $_aElementDefaults;
  25. protected $_aAclId2Name;
  26. function __construct( $sSystem, $iId, $iInit = true, $oTemplate = false)
  27. {
  28. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  29. if (empty($sSystem))
  30. return;
  31. $this->_sTmplNameItem = 'comment.html';
  32. $this->_sTmplNameItemContent = 'comment_content.html';
  33. $this->_sJsObjClass = 'BxDolCmts';
  34. $this->_sJsObjName = 'oCmts' . bx_gen_method_name($sSystem, array('_' , '-')) . '_' .str_replace('-', 'n', $iId);
  35. $this->_sStylePrefix = isset($this->_aSystem['root_style_prefix']) ? $this->_aSystem['root_style_prefix'] : 'cmt';
  36. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sSystem) . '-' . $iId;
  37. $this->_aHtmlIds = array(
  38. 'main' => 'bx-cmt-' . $sHtmlId,
  39. 'counter' => 'bx-cmt-counter-' . $sHtmlId
  40. );
  41. $this->_aElementDefaults = array(
  42. 'show_do_comment_as_button' => false,
  43. 'show_do_comment_as_button_small' => false,
  44. 'show_do_comment_icon' => true,
  45. 'show_do_comment_label' => false,
  46. 'show_counter' => true,
  47. 'show_counter_only' => true,
  48. 'show_counter_empty' => false,
  49. 'recalculate_counter' => false
  50. );
  51. $this->_aAclId2Name = array();
  52. $aAclLevels = BxDolAcl::getInstance()->getMemberships(false, false, false);
  53. foreach($aAclLevels as $iAclId => $sAclName)
  54. $this->_aAclId2Name[$iAclId] = str_replace('_', '-', str_replace('_adm_prm_txt_level_', '', $sAclName));
  55. if(empty(self::$_sTmplContentElementBlock))
  56. self::$_sTmplContentElementBlock = $this->_oTemplate->getHtml('comment_element_block.html');
  57. if(empty(self::$_sTmplContentElementInline))
  58. self::$_sTmplContentElementInline = $this->_oTemplate->getHtml('comment_element_inline.html');
  59. if(empty(self::$_sTmplContentDoCommentLabel))
  60. self::$_sTmplContentDoCommentLabel = $this->_oTemplate->getHtml('comment_do_comment_label.html');
  61. if(empty(self::$_sTmplContentCounter))
  62. self::$_sTmplContentCounter = $this->_oTemplate->getHtml('comment_counter.html');
  63. $this->_oTemplate->addJsTranslation('_sys_txt_cmt_loading');
  64. }
  65. /**
  66. * Add comments CSS/JS
  67. */
  68. public function addCssJs ()
  69. {
  70. $oForm = BxDolForm::getObjectInstance($this->_sFormObject, $this->_sFormDisplayPost);
  71. $oForm->addCssJs();
  72. $this->_oTemplate->addCss(array(
  73. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'photo-swipe/|photoswipe.css',
  74. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'photo-swipe/default-skin/|default-skin.css',
  75. ));
  76. $this->_oTemplate->addJs(array(
  77. 'photo-swipe/photoswipe.min.js',
  78. 'photo-swipe/photoswipe-ui-default.min.js',
  79. ));
  80. }
  81. public function getJsObjectName()
  82. {
  83. return $this->_sJsObjName;
  84. }
  85. /**
  86. * Get initialization section of comments box
  87. *
  88. * @return string
  89. */
  90. public function getJsScript($aBp = array(), $aDp = array())
  91. {
  92. $bMinPostForm = isset($aDp['min_post_form']) ? $aDp['min_post_form'] : $this->_bMinPostForm;
  93. $aParams = array(
  94. 'sObjName' => $this->_sJsObjName,
  95. 'sRootUrl' => BX_DOL_URL_ROOT,
  96. 'sSystem' => $this->getSystemName(),
  97. 'iAuthorId' => $this->_getAuthorId(),
  98. 'iObjId' => $this->getId(),
  99. 'sBaseUrl' => $this->getBaseUrl(),
  100. 'sPostFormPosition' => $this->_aSystem['post_form_position'],
  101. 'sBrowseType' => $this->_sBrowseType,
  102. 'sDisplayType' => $this->_sDisplayType,
  103. 'iDisplayStructure' => isset($aDp['structure']) && !empty($aDp['structure']) ? 1 : 0,
  104. 'iMinPostForm' => $bMinPostForm ? 1 : 0,
  105. 'sStylePrefix' => $this->_sStylePrefix,
  106. );
  107. $this->addCssJs();
  108. return $this->_oTemplate->_wrapInTagJsCode("if(window['" . $this->_sJsObjName . "'] == undefined) var " . $this->_sJsObjName . " = new " . $this->_sJsObjClass . "(" . json_encode($aParams) . "); " . $this->_sJsObjName . ".cmtInit();");
  109. }
  110. function getCommentsBlockAPI($aBp = [], $aDp = [])
  111. {
  112. $mixedResult = $this->isViewAllowed();
  113. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  114. return $mixedResult; // TODO: error checking
  115. $this->_getParams($aBp, $aDp);
  116. $this->_prepareParams($aBp, $aDp);
  117. $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp[($aBp['init_view'] != -1 ? 'init' : 'per') . '_view']);
  118. return [
  119. 'unit' => 'comments',
  120. 'data' => $this->decodeData($aCmts),
  121. ];
  122. }
  123. function decodeData ($a)
  124. {
  125. foreach ($a as $i => $r) {
  126. if (isset($r['cmt_author_id']))
  127. $a[$i]['author_data'] = $this->decodeDataAuthor($r);
  128. }
  129. return $a;
  130. }
  131. function decodeDataAuthor ($r) // TODO: get rid of duplicate code here and in BxBaseModGeneralSearchResult
  132. {
  133. $oProfile = BxDolProfile::getInstanceMagic($r['cmt_author_id']);
  134. return [
  135. 'display_name' => $oProfile->getDisplayName(),
  136. 'url' => $oProfile->getUrl(),
  137. 'url_avatar' => $oProfile->getAvatar(),
  138. ];
  139. }
  140. /**
  141. * get full comments block with initializations
  142. */
  143. function getCommentsBlock($aBp = [], $aDp = [])
  144. {
  145. $mixedResult = $this->isViewAllowed();
  146. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  147. return $mixedResult;
  148. $this->_getParams($aBp, $aDp);
  149. //add live update
  150. $this->actionResumeLiveUpdate();
  151. $sServiceCall = BxDolService::getSerializedService('system', 'get_live_update', [$this->_sSystem, $this->_iId, $this->_getAuthorId(), '{count}'], 'TemplCmtsServices');
  152. BxDolLiveUpdates::getInstance()->add($this->_sSystem . '_live_updates_cmts_' . $this->_iId, 1, $sServiceCall);
  153. //add live update
  154. $sComments = $this->getComments($aBp, $aDp);
  155. $sCommentsPinned = $this->getCommentsPinned(array_merge($aBp, ['pinned' => 1]), $aDp);
  156. $sContentBefore = $this->_getContentBefore($aBp, $aDp);
  157. $sContentAfter = $this->_getContentAfter($aBp, $aDp);
  158. $sPostFormTop = $this->getFormBoxPost($aBp, array_merge($aDp, ['type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_TOP]));
  159. $sPostFormBottom = $this->getFormBoxPost($aBp, array_merge($aDp, ['type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_BOTTOM]));
  160. $sJsContent = $this->getJsScript($aBp, $aDp);
  161. $sBlockTitle = _t($this->_aT['block_comments_title'], $this->getCommentsCountAll(0, true));
  162. $sBlockMenu = $this->_getControlsBox();
  163. bx_alert('system', 'view_comments', 0, 0, [
  164. 'object' => $this,
  165. 'system' => $this->_sSystem,
  166. 'id' => $this->getId(),
  167. 'params_browse' => $aBp,
  168. 'params_display' => $aDp,
  169. 'post_form_top' => &$sPostFormTop,
  170. 'content_before' => &$sContentBefore,
  171. 'comments' => &$sComments,
  172. 'comments_pinned' => &$sCommentsPinned,
  173. 'content_after' => &$sContentAfter,
  174. 'post_form_bottom' => &$sPostFormBottom,
  175. 'js_content' => &$sJsContent,
  176. 'block_title' => &$sBlockTitle,
  177. 'block_menu' => &$sBlockMenu,
  178. ]);
  179. $sContent = $this->_oTemplate->parseHtmlByName('comments_block.html', [
  180. 'system' => $this->_sSystem,
  181. 'list_anchor' => $this->getListAnchor(),
  182. 'id' => $this->getId(),
  183. 'content_before' => $sContentBefore,
  184. 'comments' => $sComments,
  185. 'comments_pinned' => $sCommentsPinned,
  186. 'bx_if:show_divider_hidden' => [
  187. 'condition' => empty($sCommentsPinned),
  188. 'content' => []
  189. ],
  190. 'content_after' => $sContentAfter,
  191. 'post_form_top' => $sPostFormTop,
  192. 'post_form_bottom' => $sPostFormBottom,
  193. 'image_preview' => $this->_oTemplate->parseHtmlByName('comments_photoswipe.html', []),
  194. 'script' => $sJsContent
  195. ]);
  196. return $aDp['in_designbox'] ? DesignBoxContent($sBlockTitle, $sContent, BX_DB_DEF, $sBlockMenu) : [
  197. 'title' => $sBlockTitle,
  198. 'content' => $sContent,
  199. 'menu' => $sBlockMenu,
  200. ];
  201. }
  202. /**
  203. * get comments list for specified parent comment
  204. *
  205. * @param array $aBp - browse params array
  206. * @param array $aDp - display params array
  207. *
  208. */
  209. function getComments($aBp = array(), $aDp = array())
  210. {
  211. $this->_prepareParams($aBp, $aDp);
  212. $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp[($aBp['init_view'] != -1 ? 'init' : 'per') . '_view']);
  213. if(empty($aCmts) || !is_array($aCmts)) {
  214. if((int)$aBp['parent_id'] == 0 && !$this->isPostAllowed()) {
  215. $oPermalink = BxDolPermalinks::getInstance();
  216. return MsgBox(_t('_cmt_msg_login_required', $oPermalink->permalink('page.php?i=login'), $oPermalink->permalink('page.php?i=create-account')));
  217. }
  218. return isset($aDp['show_empty']) && $aDp['show_empty'] === true ? $this->_getEmpty($aDp) : '';
  219. }
  220. $sCmts = '';
  221. foreach($aCmts as $k => $aCmt)
  222. $sCmts .= $this->getComment($aCmt, $aBp, $aDp);
  223. $sCmts = $this->_getMoreLink($sCmts, $aBp, $aDp);
  224. return $sCmts;
  225. }
  226. function getCommentsPinned($aBp = array(), $aDp = array())
  227. {
  228. $this->_prepareParams($aBp, $aDp);
  229. $aCmts = $this->getCommentsArray($aBp['vparent_id'], BX_CMT_FILTER_PINNED, $aBp['order'], 0, -1);
  230. if(empty($aCmts) || !is_array($aCmts))
  231. return '';
  232. $sCmts = '';
  233. foreach($aCmts as $k => $aCmt)
  234. $sCmts .= $this->getComment($aCmt, $aBp, $aDp);
  235. return $sCmts;
  236. }
  237. public function getCommentsByStructure($aBp = array(), $aDp = array())
  238. {
  239. if(empty($aDp['structure']))
  240. return isset($aDp['show_empty']) && $aDp['show_empty'] === true ? $this->_getEmpty($aDp) : '';
  241. $aBp['count'] = count($aDp['structure']);
  242. $this->_prepareParams($aBp, $aDp);
  243. $aDp['structure'] = array_slice($aDp['structure'], $aBp['start'], $aBp[($aBp['init_view'] != -1 ? 'init' : 'per') . '_view'], true);
  244. $sCmts = '';
  245. foreach($aDp['structure'] as $iCmtId => $aCmt)
  246. $sCmts .= $this->getComment($iCmtId, $aBp, $aDp);
  247. $sCmts = $this->_getMoreLink($sCmts, $aBp, $aDp);
  248. return $sCmts;
  249. }
  250. /**
  251. * get comment view block with initializations
  252. */
  253. function getCommentBlock($iCmtId = 0, $aBp = array(), $aDp = array())
  254. {
  255. $mixedResult = $this->isViewAllowed();
  256. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  257. return $mixedResult;
  258. $aBp = array_merge(array('type' => $this->_sBrowseType), $aBp);
  259. $aDp = array_merge(array('type' => BX_CMT_DISPLAY_THREADED), $aDp);
  260. //--- Beg: Using pregenerated structure
  261. $mixedStructure = $this->getCommentStructure((int)$iCmtId, $aBp, $aDp);
  262. if($mixedStructure !== false)
  263. $aDp['structure'] = $mixedStructure;
  264. //--- End: Using pregenerated structure
  265. $sComment = $this->getComment($iCmtId, $aBp, $aDp);
  266. if (!$sComment)
  267. return '';
  268. BxDolTemplate::getInstance()->addInjection ('injection_footer', 'text', $this->_oTemplate->parseHtmlByName('comments_photoswipe.html', []));
  269. return $this->_oTemplate->parseHtmlByName('comment_block.html', array(
  270. 'system' => $this->_sSystem,
  271. 'id' => $this->getId(),
  272. 'comment' => $sComment,
  273. 'script' => $this->getJsScript($aBp, $aDp)
  274. ));
  275. }
  276. /**
  277. * get one just posted comment
  278. *
  279. * @param int $iCmtId - comment id
  280. * @return string
  281. */
  282. function getComment($mixedCmt, $aBp = array(), $aDp = array())
  283. {
  284. $iUserId = $this->_getAuthorId();
  285. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  286. if (!$aCmt)
  287. return '';
  288. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  289. $sClass = $sClassCnt = '';
  290. if(isset($aCmt['vote_rate']) && (float)$aCmt['vote_rate'] < $this->_aSystem['viewing_threshold']) {
  291. $this->_oTemplate->pareseHtmlByName('comment_hidden.html', array(
  292. 'js_object' => $this->_sJsObjName,
  293. 'id' => $aCmt['cmt_id'],
  294. 'title' => bx_process_output(_t('_hidden_comment', $sAuthorName)),
  295. 'bx_if:show_replies' => array(
  296. 'condition' => $aCmt['cmt_replies'] > 0,
  297. 'content' => array(
  298. 'replies' => _t('_Show N replies', $aCmt['cmt_replies'])
  299. )
  300. )
  301. ));
  302. $sClass = ' ' . $this->_sStylePrefix . '-hidden';
  303. }
  304. if($aCmt['cmt_author_id'] == $iUserId)
  305. $sClass .= ' ' . $this->_sStylePrefix . '-mine';
  306. $aAuthorAcl = BxDolAcl::getInstance()->getMemberMembershipInfo($aCmt['cmt_author_id']);
  307. if(!empty($aAuthorAcl) && isset($this->_aAclId2Name[$aAuthorAcl['id']]))
  308. $sClass .= ' ' . $this->_sStylePrefix . '-aml-' . $this->_aAclId2Name[$aAuthorAcl['id']];
  309. if(!empty($aDp['blink']) && in_array($aCmt['cmt_id'], $aDp['blink']))
  310. $sClass .= ' ' . $this->_sStylePrefix . '-blink';
  311. if(!empty($aDp['class_comment']))
  312. $sClass .= ' ' . $aDp['class_comment'];
  313. if(!empty($aDp['class_comment_content']))
  314. $sClassCnt .= ' ' . $aDp['class_comment_content'];
  315. $sActions = $this->_getActionsBox($aCmt, $aBp, $aDp);
  316. $aTmplReplyTo = array();
  317. if((int)$aCmt['cmt_parent_id'] != 0) {
  318. $aParent = $this->getCommentRow($aCmt['cmt_parent_id']);
  319. if(!empty($aParent) && is_array($aParent)) {
  320. $oProfile = $this->_getAuthorObject($aParent['cmt_author_id']);
  321. $sParAuthorName = $oProfile->getDisplayName();
  322. $sParAuthorUnit = $oProfile->getUnit(0, array('template' => array('name' => 'unit_wo_info_links', 'size' => 'icon')));
  323. $aTmplReplyTo = array(
  324. 'style_prefix' => $this->_sStylePrefix,
  325. 'par_cmt_link' => $this->getItemUrl($aCmt['cmt_parent_id']),
  326. 'par_cmt_title' => bx_html_attribute(_t('_in_reply_to_x', $sParAuthorName)),
  327. 'par_cmt_author' => $sParAuthorName,
  328. 'par_cmt_author_unit' => $sParAuthorUnit
  329. );
  330. }
  331. }
  332. $sReplies = '';
  333. if(!empty($aDp)) {
  334. $aDp['show_empty'] = false;
  335. if(!empty($aDp['structure'][$aCmt['cmt_id']]) && is_array($aDp['structure'][$aCmt['cmt_id']])) {
  336. if(!empty($aDp['structure'][$aCmt['cmt_id']]['items'])) {
  337. $aDp['structure'] = $aDp['structure'][$aCmt['cmt_id']]['items'];
  338. $sReplies = $this->getCommentsByStructure(array('parent_id' => $aCmt['cmt_id'], 'type' => $aBp['type']), $aDp);
  339. }
  340. }
  341. else if((int)$aCmt['cmt_replies'] > 0 && $aDp['type'] == BX_CMT_DISPLAY_THREADED)
  342. $sReplies = $this->getComments(array('parent_id' => $aCmt['cmt_id'], 'vparent_id' => $aCmt['cmt_id'], 'type' => $aBp['type']), $aDp);
  343. }
  344. $aTmplVarsMeta = array();
  345. if(!empty($this->_sMenuObjMeta)) {
  346. $oMenuMeta = BxDolMenu::getObjectInstance($this->_sMenuObjMeta, $this->_oTemplate);
  347. if($oMenuMeta) {
  348. $oMenuMeta->setCmtsData($this, $aCmt['cmt_id']);
  349. $aTmplVarsMeta = array(
  350. 'style_prefix' => $this->_sStylePrefix,
  351. 'meta' => $oMenuMeta->getCode()
  352. );
  353. }
  354. }
  355. $oProfileAuthor = BxDolProfile::getInstance($aCmt['cmt_author_id']);
  356. if($this->_isShowContent($aCmt)) {
  357. $sContent = $this->_getContent($aCmt, $aBp, $aDp);
  358. }
  359. else {
  360. $sClass .= ' cmt-author-not-active';
  361. $sContent = _t('_hidden_comment', BxDolProfileUndefined::getInstance()->getDisplayName());
  362. }
  363. $aVars = array_merge(array(
  364. 'system' => $this->_sSystem,
  365. 'style_prefix' => $this->_sStylePrefix,
  366. 'js_object' => $this->_sJsObjName,
  367. 'id' => $aCmt['cmt_id'],
  368. 'anchor' => $this->getItemAnchor($aCmt['cmt_id']),
  369. 'class' => $sClass,
  370. 'class_cnt' => $sClassCnt,
  371. 'bx_if:show_reply_to' => array(
  372. 'condition' => !empty($aTmplReplyTo),
  373. 'content' => $aTmplReplyTo
  374. ),
  375. 'bx_if:meta' => array(
  376. 'condition' => !empty($aTmplVarsMeta),
  377. 'content' => $aTmplVarsMeta
  378. ),
  379. 'bx_if:show_pinned' => array(
  380. 'condition' => (int)$aCmt['cmt_pinned'] > 0,
  381. 'content' => array(
  382. 'style_prefix' => $this->_sStylePrefix,
  383. )
  384. ),
  385. 'content' => $sContent,
  386. 'actions' => $sActions,
  387. 'replies' => $sReplies,
  388. ), $this->_getTmplVarsAuthor($aCmt), $this->_getTmplVarsNotes($aCmt));
  389. $sResult = $this->_oTemplate->parseHtmlByName($this->_sTmplNameItem, $aVars);
  390. bx_alert('system', 'view_comment', $aCmt['cmt_id'], 0, array('comment' => $aCmt, 'system' => $this->_sSystem, 'tmpl_name' => $this->_sTmplNameItem, 'tmpl_vars' => $aVars, 'override_result' => &$sResult));
  391. return $sResult;
  392. }
  393. public function getCommentStructure($iCmtId, $aBp = array(), $aDp = array())
  394. {
  395. $aRoot = $this->getCommentRow((int)$iCmtId);
  396. $aBps = $aBp;
  397. if(!empty($aRoot))
  398. $aBps['parent_id'] = $aRoot['cmt_id'];
  399. $this->_prepareStructureBp($aDp['type'], $aBps);
  400. $iLevel = 0;
  401. $aStructure = array();
  402. $this->_getStructure($aRoot, $aBps, $iLevel, $aStructure);
  403. return !empty($aStructure) && is_array($aStructure) ? $aStructure : false;
  404. }
  405. function getCommentSearch($iCmtId, &$sAddon)
  406. {
  407. $aBp = array();
  408. $aDp = array(
  409. 'type' => BX_CMT_DISPLAY_FLAT,
  410. 'view_only' => true
  411. );
  412. if(empty($sAddon))
  413. $sAddon = $this->getJsScript($aBp, $aDp);
  414. BxDolTemplate::getInstance()->addInjection ('injection_footer', 'text', $this->_oTemplate->parseHtmlByName('comments_photoswipe.html', []));
  415. return $this->_oTemplate->parseHtmlByName('comment_search.html', array(
  416. 'comment' => $this->getComment($iCmtId, $aBp, $aDp),
  417. ));
  418. }
  419. /**
  420. * get one comment for "Live Search"
  421. *
  422. * @param int $iCmtId - comment id
  423. * @return string
  424. */
  425. function getCommentLiveSearch($mixedCmt, $aParams = array())
  426. {
  427. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  428. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  429. $bAuthorIcon = !empty($sAuthorIcon);
  430. $sViewLink = $this->getViewUrl($aCmt['cmt_id']);
  431. if(empty($sViewLink))
  432. $sViewLink = '#';
  433. return $this->_oTemplate->parseHtmlByName('comment_live_search.html', array(
  434. 'bx_if:show_icon' => array(
  435. 'condition' => $bAuthorIcon,
  436. 'content' => array(
  437. 'author_icon' => $sAuthorIcon,
  438. 'view_link' => $sViewLink
  439. )
  440. ),
  441. 'bx_if:show_icon_empty' => array(
  442. 'condition' => !$bAuthorIcon,
  443. 'content' => array()
  444. ),
  445. 'view_link' => $sViewLink,
  446. 'text' => BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($aCmt['cmt_text']), $this->_sSnippetLenthLiveSearch),
  447. 'sample' => isset($aParams['txt_sample_single']) ? _t($aParams['txt_sample_single']) : ''
  448. ));
  449. }
  450. function getFormBoxPost($aBp = array(), $aDp = array())
  451. {
  452. return $this->_getFormBox(BX_CMT_ACTION_POST, $aBp, $aDp);
  453. }
  454. function getFormBoxEdit($aBp = array(), $aDp = array())
  455. {
  456. return $this->_getFormBox(BX_CMT_ACTION_EDIT, $aBp, $aDp);
  457. }
  458. function getFormPost($iCmtParentId = 0, $aDp = array())
  459. {
  460. return $this->_getFormPost($iCmtParentId, $aDp);
  461. }
  462. function getFormEdit($iCmtId, $aDp = array())
  463. {
  464. return $this->_getFormEdit($iCmtId, $aDp);
  465. }
  466. function getControlsBox()
  467. {
  468. return $this->_getControlsBox();
  469. }
  470. function getLiveUpdate($iCountOld = 0, $iCountNew = 0)
  471. {
  472. $iCount = (int)$iCountNew - (int)$iCountOld;
  473. if($iCount < 0)
  474. return '';
  475. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  476. if(empty($aComments) || !is_array($aComments))
  477. return '';
  478. $aComment = array_shift($aComments);
  479. if(empty($aComment) || !is_array($aComment))
  480. return '';
  481. $sJsObject = $this->getJsObjectName();
  482. return $this->_oTemplate->parseHtmlByName('comments_lu_button.html', array(
  483. 'style_prefix' => $this->_sStylePrefix,
  484. 'html_id' => $this->getNotificationId(),
  485. 'onclick_show' => "javascript:" . $sJsObject . ".goToBtn(this, '" . $this->getItemAnchor($aComment['cmt_id']) . "', '" . $aComment['cmt_id'] . "');",
  486. ));
  487. }
  488. function getLiveUpdates($iCountOld = 0, $iCountNew = 0)
  489. {
  490. $bShowAll = true;
  491. $bShowActions = false;
  492. $iCount = (int)$iCountNew - (int)$iCountOld;
  493. if($iCount < 0)
  494. return '';
  495. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  496. if(empty($aComments) || !is_array($aComments))
  497. return '';
  498. $sJsObject = $this->getJsObjectName();
  499. $iUserId = $this->_getAuthorId();
  500. $bModerator = $this->isModerator();
  501. $aComments = array_reverse($aComments);
  502. $iComments = count($aComments);
  503. $aTmplVarsNotifs = array();
  504. foreach($aComments as $iIndex => $aComment) {
  505. $iCommentId = $aComment['cmt_id'];
  506. $sShowOnClick = "javascript:" . $sJsObject . ".goTo(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  507. $sReplyOnClick = "javascript:" . $sJsObject . ".goToAndReply(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  508. $iAuthorId = (int)$aComment['cmt_author_id'];
  509. if($iAuthorId < 0) {
  510. if(abs($iAuthorId) == $iUserId)
  511. continue;
  512. else if($bModerator)
  513. $iAuthorId *= -1;
  514. }
  515. $oAuthor = $this->_getAuthorObject($iAuthorId);
  516. $sAuthorName = $oAuthor->getDisplayName();
  517. $aTmplVarsNotifs[] = array(
  518. 'bx_if:show_as_hidden' => array(
  519. 'condition' => !$bShowAll && $iIndex < ($iComments - 1),
  520. 'content' => array(),
  521. ),
  522. 'item' => $this->_oTemplate->parseHtmlByName('comments_lu_notifications.html', array(
  523. 'style_prefix' => $this->_sStylePrefix,
  524. 'onclick_show' => $sShowOnClick,
  525. 'onclick_reply' => $sReplyOnClick,
  526. 'author_link' => $oAuthor->getUrl(),
  527. 'author_title' => bx_html_attribute($sAuthorName),
  528. 'author_name' => $sAuthorName,
  529. 'author_unit' => $oAuthor->getUnit(0, array('template' => 'unit_wo_info_links')),
  530. 'text' => _t('_cmt_txt_added_sample')
  531. )),
  532. 'bx_if:show_previous' => array(
  533. 'condition' => $bShowActions && $iIndex > 0,
  534. 'content' => array(
  535. 'onclick_previous' => $sJsObject . '.previousLiveUpdate(this)'
  536. )
  537. ),
  538. 'bx_if:show_close' => array(
  539. 'condition' => $bShowActions,
  540. 'content' => array(
  541. 'onclick_close' => $sJsObject . '.hideLiveUpdate(this)'
  542. )
  543. )
  544. );
  545. }
  546. return $this->_oTemplate->parseHtmlByName('popup_chain.html', array(
  547. 'html_id' => $this->getNotificationId(),
  548. 'bx_repeat:items' => $aTmplVarsNotifs
  549. ));
  550. }
  551. public function getElementBlock($aParams = array())
  552. {
  553. $aParams['usage'] = BX_CMT_USAGE_BLOCK;
  554. return $this->getElement($aParams);
  555. }
  556. public function getElementInline($aParams = array())
  557. {
  558. $aParams['usage'] = BX_CMT_USAGE_INLINE;
  559. return $this->getElement($aParams);
  560. }
  561. public function getElement($aParams = array())
  562. {
  563. $aParams = array_merge($this->_aElementDefaults, $aParams);
  564. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  565. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  566. $bShowCounterEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  567. $bRecalculateCounter = isset($aParams['recalculate_counter']) && $aParams['recalculate_counter'] == true;
  568. $iObjectId = $this->getId();
  569. $iAuthorId = $this->_getAuthorId();
  570. $iAuthorIp = $this->_getAuthorIp();
  571. $iCount = $this->getCommentsCountAll(0, $bRecalculateCounter);
  572. $bCount = (int)$iCount != 0;
  573. $isAllowedComment = $this->isPostAllowed();
  574. //--- Do Comment
  575. $bTmplVarsDoComment = $this->_isShowDoComment($aParams, $isAllowedComment, $bCount);
  576. $aTmplVarsDoComment = array();
  577. if($bTmplVarsDoComment) {
  578. $sClass = '';
  579. if($bShowDoCommentAsButton)
  580. $sClass = 'bx-btn';
  581. else if ($bShowDoCommentAsButtonSmall)
  582. $sClass = 'bx-btn bx-btn-small';
  583. if(!$isAllowedComment)
  584. $sClass .= $bShowDoCommentAsButton || $bShowDoCommentAsButtonSmall ? ' bx-btn-disabled' : 'bx-cmts-disabled';
  585. $aTmplVarsDoComment = array(
  586. 'style_prefix' => $this->_sStylePrefix,
  587. 'do_comment' => $this->_oTemplate->parseLink($this->getListUrl(), $this->_getLabelDo($aParams), array(
  588. 'class' => $this->_sStylePrefix . '-do-comment ' . $this->_sStylePrefix . '-dc ' . $sClass,
  589. 'title' => _t($this->_getTitleDo())
  590. )),
  591. );
  592. }
  593. //--- Counter
  594. $bTmplVarsCounter = $this->_isShowCounter($aParams, $isAllowedComment, $bCount);
  595. $aTmplVarsCounter = array();
  596. if($bTmplVarsCounter)
  597. $aTmplVarsCounter = array(
  598. 'style_prefix' => $this->_sStylePrefix,
  599. 'bx_if:show_hidden' => array(
  600. 'condition' => !$bShowCounterEmpty && !$bCount,
  601. 'content' => array()
  602. ),
  603. 'counter' => $this->getCounter(array_merge($aParams, [
  604. 'show_counter_only' => false
  605. ]))
  606. );
  607. if(!$bTmplVarsDoComment && !$bTmplVarsCounter)
  608. return '';
  609. $sTmplName = $this->{'_getTmplElement' . bx_gen_method_name(!empty($aParams['usage']) ? $aParams['usage'] : BX_CMT_USAGE_DEFAULT)}();
  610. return $this->_oTemplate->parseHtmlByContent($sTmplName, array(
  611. 'style_prefix' => $this->_sStylePrefix,
  612. 'html_id' => $this->_aHtmlIds['main'],
  613. 'class' => $this->_sStylePrefix . ($bShowDoCommentAsButton ? '-button' : '') . ($bShowDoCommentAsButtonSmall ? '-button-small' : ''),
  614. 'count' => $iCount,
  615. 'bx_if:show_do_comment' => array(
  616. 'condition' => $bTmplVarsDoComment,
  617. 'content' => $aTmplVarsDoComment
  618. ),
  619. 'bx_if:show_counter' => array(
  620. 'condition' => $bTmplVarsCounter,
  621. 'content' => $aTmplVarsCounter
  622. ),
  623. 'script' => ''
  624. ));
  625. }
  626. protected function _getCounterItems($iCmtsLimit, $iCmtsStart = 0)
  627. {
  628. return $this->_oQuery->getCommentsBy(array('type' => 'object_id', 'object_id' => $this->getId(), 'order_way' => 'desc', 'start' => $iCmtsStart, 'per_page' => $iCmtsLimit * 4));
  629. }
  630. private function _isShowContent($aCmt)
  631. {
  632. $oProfileAuthor = BxDolProfile::getInstance($aCmt['cmt_author_id']);
  633. return (int)$aCmt['cmt_author_id'] == 0 || ($oProfileAuthor && $oProfileAuthor->isActive()) || isAdmin() || BxDolAcl::getInstance()->isMemberLevelInSet([MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR]);
  634. }
  635. public function getCounter($aParams = [])
  636. {
  637. $aParams = array_merge($this->_aElementDefaults, $aParams);
  638. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  639. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  640. $bShowEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  641. $bRecalculateCounter = isset($aParams['recalculate_counter']) && $aParams['recalculate_counter'] == true;
  642. $iCount = (int)$this->getCommentsCountAll(0, $bRecalculateCounter);
  643. if($iCount == 0 && !$bShowEmpty)
  644. return '';
  645. $sClass = 'sys-action-counter';
  646. if(isset($aParams['show_counter_only']) && (bool)$aParams['show_counter_only'] === true)
  647. $sClass .= ' sys-ac-only';
  648. $sClass .= ' ' . $this->_sStylePrefix . '-counter';
  649. if($bShowDoCommentAsButtonSmall)
  650. $sClass .= ' bx-btn-small-height';
  651. if($bShowDoCommentAsButton)
  652. $sClass .= ' bx-btn-height';
  653. $iCmtsLimit = 5;
  654. $aCmts = $this->_getCounterItems($iCmtsLimit);
  655. $aCmts = array_reverse($aCmts);
  656. $aTmplVarsProfiles = array();
  657. foreach($aCmts as $aCmt) {
  658. $iAuthor = (int)$aCmt['cmt_author_id'];
  659. if(array_key_exists($iAuthor, $aTmplVarsProfiles))
  660. continue;
  661. $oAuthor = BxDolProfile::getInstanceMagic($iAuthor);
  662. if(!$oAuthor)
  663. continue;
  664. $aTmplVarsProfiles[$iAuthor] = array(
  665. 'icon' => $oAuthor->getUnit(0, array('template' => array('name' => 'unit_wo_info_links', 'size' => 'icon')))
  666. );
  667. if(count($aTmplVarsProfiles) >= $iCmtsLimit)
  668. break;
  669. }
  670. $aTmplVarsProfiles = array_values($aTmplVarsProfiles);
  671. $sHref = !empty($aParams['overwrite_counter_link_href']) ? $aParams['overwrite_counter_link_href'] : $this->getListUrl();
  672. $sOnclick = '';
  673. if(!empty($aParams['overwrite_counter_link_onclick']))
  674. $sOnclick = $aParams['overwrite_counter_link_onclick'];
  675. return $this->_oTemplate->parseHtmlByContent($this->_getTmplCounter(), array(
  676. 'style_prefix' => $this->_sStylePrefix,
  677. 'id' => $this->_aHtmlIds['counter'],
  678. 'class' => $sClass,
  679. 'href' => $sHref,
  680. 'bx_if:show_onclick' => array(
  681. 'condition' => !empty($sOnclick),
  682. 'content' => array(
  683. 'onclick' => $sOnclick
  684. )
  685. ),
  686. 'content' => $this->_getCounterLabel($iCount, $aParams),
  687. 'bx_repeat:profiles' => $aTmplVarsProfiles,
  688. 'bx_if:show_icon' => array(
  689. 'condition' => ($bShowEmpty || !empty($aTmplVarsProfiles)) && (!isset($aParams['show_icon']) || $aParams['show_icon']),
  690. 'content' => array(
  691. 'style_prefix' => $this->_sStylePrefix,
  692. 'icon' => !empty($aParams['custom_icon']) ? $aParams['custom_icon'] : $this->_oTemplate->getImageAuto('comment|' . $this->_sStylePrefix . '-counter-icon')
  693. )
  694. )
  695. ));
  696. }
  697. protected function _getLabelDo($aParams = array())
  698. {
  699. return $this->_oTemplate->parseHtmlByContent($this->_getTmplLabelDo(), array(
  700. 'style_prefix' => $this->_sStylePrefix,
  701. 'bx_if:show_icon' => array(
  702. 'condition' => isset($aParams['show_do_comment_icon']) && $aParams['show_do_comment_icon'] == true,
  703. 'content' => array(
  704. 'style_prefix' => $this->_sStylePrefix,
  705. 'icon' => $this->_oTemplate->getImageAuto($this->_getIconDo())
  706. )
  707. ),
  708. 'bx_if:show_text' => array(
  709. 'condition' => isset($aParams['show_do_comment_label']) && $aParams['show_do_comment_label'] == true,
  710. 'content' => array(
  711. 'style_prefix' => $this->_sStylePrefix,
  712. 'text' => _t($this->_getTitleDo())
  713. )
  714. )
  715. ));
  716. }
  717. protected function _getCounterLabel($iCount, $aParams = array())
  718. {
  719. return (int)$iCount != 0 ? _t(isset($aParams['caption']) ? $aParams['caption'] : '_cmt_txt_counter', $iCount) : _t(isset($aParams['caption_empty']) ? $aParams['caption_empty'] : '_cmt_txt_counter_empty').'';
  720. }
  721. protected function _getTmplElementBlock()
  722. {
  723. return self::$_sTmplContentElementBlock;
  724. }
  725. protected function _getTmplElementInline()
  726. {
  727. return self::$_sTmplContentElementInline;
  728. }
  729. protected function _getTmplLabelDo()
  730. {
  731. return self::$_sTmplContentDoCommentLabel;
  732. }
  733. protected function _getTmplCounter()
  734. {
  735. return self::$_sTmplContentCounter;
  736. }
  737. /**
  738. * private functions
  739. */
  740. protected function _getContentBefore($aBp = array(), $aDp = array())
  741. {
  742. return '';
  743. }
  744. protected function _getContentAfter($aBp = array(), $aDp = array())
  745. {
  746. return '';
  747. }
  748. protected function _getControlsBox()
  749. {
  750. $sDisplay = '';
  751. $bDisplay = (int)$this->_aSystem['is_display_switch'] == 1;
  752. if($bDisplay) {
  753. $aDisplayLinks = array(
  754. array('id' => $this->_sSystem . '-flat', 'name' => $this->_sSystem . '-flat', 'class' => '', 'title' => '_cmt_display_flat', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'flat\');'),
  755. array('id' => $this->_sSystem . '-threaded', 'name' => $this->_sSystem . '-threaded', 'class' => '', 'title' => '_cmt_display_threaded', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'threaded\');')
  756. );
  757. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-display', 'menu_items' => $aDisplayLinks));
  758. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sDisplayType);
  759. $sDisplay = $oMenu->getCode();
  760. }
  761. $sBrowseType = '';
  762. $bBrowseType = (int)$this->_aSystem['is_browse_switch'] == 1;
  763. if($bBrowseType) {
  764. $aBrowseLinks = array(
  765. array('id' => $this->_sSystem . '-tail', 'name' => $this->_sSystem . '-tail', 'class' => '', 'title' => '_cmt_browse_tail', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'tail\');'),
  766. array('id' => $this->_sSystem . '-head', 'name' => $this->_sSystem . '-head', 'class' => '', 'title' => '_cmt_browse_head', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'head\');'),
  767. array('id' => $this->_sSystem . '-popular', 'name' => $this->_sSystem . '-popular', 'class' => '', 'title' => '_cmt_browse_popular', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'popular\');'),
  768. );
  769. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-browse', 'menu_items' => $aBrowseLinks));
  770. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseType);
  771. $sBrowseType = $oMenu->getCode();
  772. }
  773. $sBrowseFilter = '';
  774. $bBrowseFilter = (int)$this->_aSystem['is_browse_filter'] == 1;
  775. if($bBrowseFilter) {
  776. $aFilterLinks = array(
  777. array('id' => $this->_sSystem . '-all', 'name' => $this->_sSystem . '-all', 'class' => '', 'title' => '_cmt_browse_all', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'all\');'),
  778. array('id' => $this->_sSystem . '-friends', 'name' => $this->_sSystem . '-friends', 'class' => '', 'title' => '_cmt_browse_friends', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'friends\');'),
  779. array('id' => $this->_sSystem . '-subscriptions', 'name' => $this->_sSystem . '-subscriptions', 'class' => '', 'title' => '_cmt_browse_subscriptions', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'subscriptions\');')
  780. );
  781. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-filter', 'menu_items' => $aFilterLinks));
  782. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseFilter);
  783. $sBrowseFilter = $oMenu->getCode();
  784. }
  785. return $this->_oTemplate->parseHtmlByName('comments_controls.html', array(
  786. 'display_switcher' => $bDisplay ? $sDisplay : '',
  787. 'bx_if:is_divider_1' => array(
  788. 'condition' => $bDisplay && $bBrowseType,
  789. 'content' => array(
  790. 'style_prefix' => $this->_sStylePrefix,
  791. )
  792. ),
  793. 'browse_switcher' => $bBrowseType ? $sBrowseType : '',
  794. 'bx_if:is_divider_2' => array(
  795. 'condition' => $bBrowseType && $bBrowseFilter,
  796. 'content' => array(
  797. 'style_prefix' => $this->_sStylePrefix,
  798. )
  799. ),
  800. 'filter_switcher' => $bBrowseFilter ? $sBrowseFilter : '',
  801. ));
  802. }
  803. protected function _getActionsBox(&$aCmt, $aBp = [], $aDp = [])
  804. {
  805. $bViewOnly = isset($aDp['view_only']) && $aDp['view_only'] === true;
  806. $bDynamicMode = isset($aDp['dynamic_mode']) && $aDp['dynamic_mode'] === true;
  807. $sMenuActions = '';
  808. if(!$bViewOnly) {
  809. $oMenuActions = BxDolMenu::getObjectInstance($this->_sMenuObjActions);
  810. $oMenuActions->setCmtsData($this, $aCmt['cmt_id'], $aBp, $aDp);
  811. $oMenuActions->setDynamicMode($bDynamicMode);
  812. $sMenuActions = $oMenuActions->getCode();
  813. }
  814. return $this->_oTemplate->parseHtmlByName('comment_actions.html', array(
  815. 'id' => $aCmt['cmt_id'],
  816. 'js_object' => $this->_sJsObjName,
  817. 'style_prefix' => $this->_sStylePrefix,
  818. 'menu_actions' => $sMenuActions,
  819. ));
  820. }
  821. protected function _getFormBox($sType, $aBp, $aDp)
  822. {
  823. $iCmtParentId = isset($aBp['parent_id']) ? (int)$aBp['parent_id'] : 0;
  824. $sPosition = isset($aDp['position']) ? $aDp['position'] : '';
  825. $bQuote = isset($aDp['quote']) && (bool)$aDp['quote'];
  826. $bFormMin = $iCmtParentId == 0 && isset($aDp['min_post_form']) && (bool)$aDp['min_post_form'];
  827. $sPositionSystem = $this->_aSystem['post_form_position'];
  828. if(!empty($sPosition) && $sPositionSystem != $sPosition)
  829. return '';
  830. $sClass = '';
  831. if(!empty($sPosition))
  832. $sClass .= ' ' . $this->_sStylePrefix . '-reply-' . $sPosition;
  833. if($bQuote)
  834. $sClass .= ' ' . $this->_sStylePrefix . '-reply-quote';
  835. if($bFormMin)
  836. $sClass .= ' ' . $this->_sStylePrefix . '-reply-min';
  837. if(!empty($aDp['class']))
  838. $sClass .= ' ' . $aDp['class'];
  839. $sClassBody = '';
  840. if(!empty($aDp['class_body']))
  841. $sClassBody .= ' ' . $aDp['class_body'];
  842. $aTmplVarsFormMin = array();
  843. if($bFormMin) {
  844. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($this->_getAuthorId());
  845. $oForm = new BxTemplFormView(array());
  846. $aInputPlaceholder = array(
  847. 'type' => 'text',
  848. 'name' => 'comment',
  849. 'caption' => '',
  850. 'attrs' => array(
  851. 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtShowForm(this)',
  852. 'placeholder' => _t($this->_aT['txt_min_form_placeholder'], $sAuthorName),
  853. 'autocomplete' => 'off',
  854. 'readonly' => 'readonly'
  855. ),
  856. 'value' => '',
  857. );
  858. $sClassBodyMin = '';
  859. if(!empty($aDp['class_body_min']))
  860. $sClassBodyMin .= ' ' . $aDp['class_body_min'];
  861. $aTmplVarsFormMin = array(
  862. 'js_object' => $this->_sJsObjName,
  863. 'class_body_min' => $sClassBodyMin,
  864. 'style_prefix' => $this->_sStylePrefix,
  865. 'author_unit' => $sAuthorUnit,
  866. 'placeholder' => $oForm->genRow($aInputPlaceholder)
  867. );
  868. }
  869. $aForm = $this->{'_getForm' . ucfirst($sType)}($iCmtParentId, $aDp);
  870. if(empty($aForm['form']))
  871. return !empty($aForm['msg']) && (isLogged() || $iCmtParentId != 0 || $this->getCommentsCount() > 0) ? MsgBox($aForm['msg']) : '';
  872. return $this->_oTemplate->parseHtmlByName('comment_reply_box.html', array(
  873. 'js_object' => $this->_sJsObjName,
  874. 'style_prefix' => $this->_sStylePrefix,
  875. 'class' => $sClass,
  876. 'class_body' => $sClassBody,
  877. 'bx_if:show_form_min' => array(
  878. 'condition' => $bFormMin,
  879. 'content' => $aTmplVarsFormMin
  880. ),
  881. 'form' => $aForm['form'],
  882. 'form_id' => $aForm['form_id'],
  883. ));
  884. }
  885. protected function _getFormAdd($aValues)
  886. {
  887. $iCmtAuthorId = isset($aValues['cmt_author_id']) ? (int)$aValues['cmt_author_id'] : $this->_getAuthorId();
  888. $iCmtParentId = isset($aValues['cmt_parent_id']) ? (int)$aValues['cmt_parent_id'] : 0;
  889. $oForm = $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId);
  890. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  891. $oForm->aParams['csrf']['disable'] = true;
  892. $oForm->aInputs['cmt_parent_id']['value'] = $iCmtParentId;
  893. if(!empty($oForm->aParams['db']['submit_name'])) {
  894. $sSubmitName = false;
  895. if(is_array($oForm->aParams['db']['submit_name']))
  896. foreach($oForm->aParams['db']['submit_name'] as $sVal) {
  897. if(isset($oForm->aInputs[$sVal])) {
  898. $sSubmitName = $sVal;
  899. break;
  900. }
  901. }
  902. else
  903. $sSubmitName = $oForm->aParams['db']['submit_name'];
  904. if($sSubmitName && isset($oForm->aInputs[$sSubmitName]))
  905. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  906. }
  907. $oForm->initChecker(array(), $aValues);
  908. if(!$oForm->isSubmittedAndValid())
  909. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  910. $iLevel = 0;
  911. $iCmtVisualParentId = 0;
  912. if((int)$iCmtParentId > 0) {
  913. $aParent = $this->getCommentRow($iCmtParentId);
  914. $iLevel = (int)$aParent['cmt_level'] + 1;
  915. $iCmtVisualParentId = $iLevel > $this->getMaxLevel() ? $aParent['cmt_vparent_id'] : $iCmtParentId;
  916. }
  917. $iCmtId = (int)$oForm->insert(array('cmt_vparent_id' => $iCmtVisualParentId, 'cmt_object_id' => $this->_iId, 'cmt_author_id' => $iCmtAuthorId, 'cmt_level' => $iLevel, 'cmt_time' => time()));
  918. if(!$iCmtId) {
  919. if(!$oForm->isValid())
  920. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  921. else
  922. return array('code' => 2, 'message' => '_cmt_err_cannot_perform_action');
  923. }
  924. $iCmtUniqId = $this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId, [
  925. 'author_id' => $iCmtAuthorId,
  926. 'status_admin' => $this->getStatusAdmin()
  927. ]);
  928. if($iCmtParentId) {
  929. $this->_oQuery->updateRepliesCount($iCmtParentId, 1);
  930. if(!BxDolModuleQuery::getInstance()->isEnabledByName('bx_notifications'))
  931. $this->_sendNotificationEmail($iCmtId, $iCmtParentId);
  932. }
  933. $this->_triggerComment();
  934. if($this->_sMetatagsObj && ($oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj)) !== false)
  935. $oMetatags->metaAdd($iCmtUniqId, $aValues['cmt_text']);
  936. $mixedResult = $this->onPostAfter($iCmtId);
  937. if($mixedResult === false)
  938. return array('code' => 2, 'message' => '_cmt_err_cannot_perform_action');
  939. return $mixedResult;
  940. }
  941. protected function _getFormPost($iCmtParentId = 0, $aDp = [])
  942. {
  943. $bCmtParentId = !empty($iCmtParentId);
  944. if(!$bCmtParentId && !$this->isPostAllowed())
  945. return array('msg' => $this->msgErrPostAllowed());
  946. if($bCmtParentId && !$this->isReplyAllowed($iCmtParentId))
  947. return array('msg' => $this->msgErrReplyAllowed());
  948. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  949. $bQuote = isset($aDp['quote']) && (bool)$aDp['quote'];
  950. $oForm = $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId);
  951. $oForm->aInputs['cmt_parent_id']['value'] = $iCmtParentId;
  952. if($bQuote) {
  953. $aCmtParent = $this->getCommentRow((int)$iCmtParentId);
  954. if(!empty($aCmtParent['cmt_text']))
  955. $oForm->aInputs['cmt_text']['value'] = $this->_oTemplate->parseHtmlByName('comment_quote.html', array(
  956. 'content' => $aCmtParent['cmt_text']
  957. ));
  958. }
  959. $oForm->initChecker();
  960. if($oForm->isSubmittedAndValid()) {
  961. $iCmtAuthorId = $this->_getAuthorId();
  962. $iCmtParentId = (int)$oForm->getCleanValue('cmt_parent_id');
  963. //--- Process Text ---//
  964. $sCmtText = $oForm->getCleanValue('cmt_text');
  965. $bCmtText = !empty($sCmtText);
  966. //--- Process Media ---//
  967. $aImageIds = $oForm->getCleanValue('cmt_image');
  968. $bImageIds = !empty($aImageIds) && is_array($aImageIds);
  969. if(!$bCmtText && !$bImageIds) {
  970. $oForm->aInputs['cmt_text']['error'] = _t('_Please enter characters');
  971. $oForm->setValid(false);
  972. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  973. }
  974. $aParent = array();
  975. if($iCmtParentId > 0) {
  976. $aParent = $this->getCommentRow($iCmtParentId);
  977. if(empty($aParent) || !is_array($aParent)) {
  978. $iCmtParentId = 0;
  979. $oForm->setSubmittedValue('cmt_parent_id', $iCmtParentId, $oForm->aFormAttrs['method']);
  980. }
  981. }
  982. $iLevel = 0;
  983. $iCmtVisualParentId = 0;
  984. if($iCmtParentId > 0) {
  985. $iLevel = (int)$aParent['cmt_level'] + 1;
  986. $iCmtVisualParentId = $iLevel > $this->getMaxLevel() ? $aParent['cmt_vparent_id'] : $iCmtParentId;
  987. }
  988. $iCmtId = (int)$oForm->insert(array('cmt_vparent_id' => $iCmtVisualParentId, 'cmt_object_id' => $this->_iId, 'cmt_author_id' => $iCmtAuthorId, 'cmt_level' => $iLevel, 'cmt_time' => time()));
  989. if($iCmtId != 0) {
  990. $iCmtUniqId = $this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId, [
  991. 'author_id' => $iCmtAuthorId,
  992. 'status_admin' => $this->getStatusAdmin()
  993. ]);
  994. if($this->isAttachImageEnabled())
  995. $oForm->processImages($this, 'cmt_image', $iCmtUniqId, $iCmtId, $iCmtAuthorId, true);
  996. if($iCmtParentId > 0) {
  997. $this->_oQuery->updateRepliesCount($iCmtParentId, 1);
  998. if(!BxDolModuleQuery::getInstance()->isEnabledByName('bx_notifications'))
  999. $this->_sendNotificationEmail($iCmtId, $iCmtParentId);
  1000. }
  1001. $this->_triggerComment();
  1002. if($iCmtParentId > 0)
  1003. $this->isReplyAllowed($iCmtParentId, true);
  1004. else
  1005. $this->isPostAllowed(true);
  1006. if($this->_sMetatagsObj && ($oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj)) !== false)
  1007. $oMetatags->metaAdd($iCmtUniqId, $sCmtText);
  1008. if(($mixedResult = $this->onPostAfter($iCmtId, $aDp)) !== false)
  1009. return $mixedResult;
  1010. }
  1011. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  1012. }
  1013. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  1014. }
  1015. protected function _getFormEdit($iCmtId, $aDp = [])
  1016. {
  1017. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  1018. $aCmt = $this->getCommentSimple($iCmtId);
  1019. if(!$aCmt)
  1020. return array('msg' => _t('_No such comment'));
  1021. $iCmtAuthorId = $this->_getAuthorId();
  1022. if(!$this->isEditAllowed($aCmt))
  1023. return array('msg' => $aCmt['cmt_author_id'] == $iCmtAuthorId ? strip_tags($this->msgErrEditAllowed()) : _t('_Access denied'));
  1024. $oForm = $this->_getForm(BX_CMT_ACTION_EDIT, $aCmt['cmt_id']);
  1025. $oForm->initChecker($aCmt);
  1026. if($oForm->isSubmittedAndValid()) {
  1027. $sCmtText = $oForm->getCleanValue('cmt_text');
  1028. if($oForm->update($iCmtId) !== false) {
  1029. $iCmtUniqId = $this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId, [
  1030. 'author_id' => (int)$aCmt['cmt_author_id']
  1031. ]);
  1032. $sStatusAdmin = $this->getStatusAdmin();
  1033. if($sStatusAdmin !== BX_CMT_STATUS_ACTIVE)
  1034. $this->_oQuery->updateUniqId(['status_admin' => $sStatusAdmin], ['id' => $iCmtUniqId]);
  1035. if($this->isAttachImageEnabled())
  1036. $oForm->processImages($this, 'cmt_image', $iCmtUniqId, $iCmtId, $iCmtAuthorId, false);
  1037. $this->isEditAllowed($aCmt, true);
  1038. if($this->_sMetatagsObj && ($oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj)) !== false)
  1039. $oMetatags->metaAdd($iCmtUniqId, $sCmtText);
  1040. if(($mixedResult = $this->onEditAfter($iCmtId, $aDp)) !== false)
  1041. return $mixedResult;
  1042. }
  1043. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  1044. }
  1045. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  1046. }
  1047. protected function _getForm($sAction, $iId)
  1048. {
  1049. $oForm = $this->_getFormObject($sAction);
  1050. $oForm->setId(sprintf($oForm->getAttributeMask('id'), $sAction, $this->_sSystem, $this->_iId, $iId));
  1051. $oForm->setName(sprintf($oForm->getAttributeMask('name'), $sAction, $this->_sSystem, $this->_iId, $iId));
  1052. $oForm->aParams['db']['table'] = $this->_aSystem['table'];
  1053. $oForm->aInputs['sys']['value'] = $this->_sSystem;
  1054. $oForm->aInputs['id']['value'] = $this->_iId;
  1055. $oForm->aInputs['action']['value'] = 'Submit' . ucfirst($sAction) . 'Form';
  1056. if(!$this->isAttachImageEnabled())
  1057. unset($oForm->aInputs['cmt_image']);
  1058. if(isset($oForm->aInputs['cmt_text'])) {
  1059. $oForm->aInputs['cmt_text']['html'] = $this->_aSystem['html'];
  1060. $oForm->aInputs['cmt_text']['db']['pass'] = $this->isHtml() ? 'XssHtml' : 'XssMultiline';
  1061. if(isset($oForm->aInputs['cmt_text']['checker']['func']) && strtolower($oForm->aInputs['cmt_text']['checker']['func']) == 'length') {
  1062. $iCmtTextMin = (int)$this->_aSystem['chars_post_min'];
  1063. $iCmtTextMax = (int)$this->_aSystem['chars_post_max'];
  1064. $oForm->aInputs['cmt_text']['checker']['params'] = array($iCmtTextMin, $iCmtTextMax);
  1065. $oForm->aInputs['cmt_text']['checker']['error'] = _t('_Please enter n1-n2 characters', $iCmtTextMin, $iCmtTextMax);
  1066. }
  1067. }
  1068. if($sAction == BX_CMT_ACTION_EDIT && isset($oForm->aInputs['cmt_controls']))
  1069. foreach($oForm->aInputs['cmt_controls'] as $mixedKey => $mixedValue) {
  1070. if(!is_numeric($mixedKey) || empty($mixedValue['name']) || $mixedValue['name'] != 'cmt_cancel')
  1071. continue;
  1072. if(!isset($oForm->aInputs['cmt_controls'][$mixedKey]['attrs']))
  1073. $oForm->aInputs['cmt_controls'][$mixedKey]['attrs'] = array();
  1074. $oForm->aInputs['cmt_controls'][$mixedKey]['attrs']['onclick'] = $this->_sJsObjName . '.cmtEdit(this, ' . $iId . ', false)';
  1075. }
  1076. return $oForm;
  1077. }
  1078. protected function _getContent($aCmt, $aBp = [], $aDp = [])
  1079. {
  1080. $bDynamicMode = isset($aDp['dynamic_mode']) && $aDp['dynamic_mode'] === true;
  1081. $sAttachments = $this->_getAttachments($aCmt);
  1082. $oMenuCounters = BxDolMenu::getObjectInstance($this->_sMenuObjCounters);
  1083. $oMenuCounters->setCmtsData($this, $aCmt['cmt_id'], $aBp, $aDp);
  1084. $oMenuCounters->setDynamicMode($bDynamicMode);
  1085. return $this->_oTemplate->parseHtmlByName($this->_sTmplNameItemContent, array_merge(array(
  1086. 'style_prefix' => $this->_sStylePrefix,
  1087. 'js_object' => $this->_sJsObjName,
  1088. 'bx_if:show_attached' => array(
  1089. 'condition' => !empty($sAttachments),
  1090. 'content' => array(
  1091. 'style_prefix' => $this->_sStylePrefix,
  1092. 'attached' => $sAttachments
  1093. )
  1094. ),
  1095. 'counters' => $oMenuCounters->getCode(),
  1096. ), $this->_getTmplVarsText($aCmt)));
  1097. }
  1098. protected function _getMoreLink($sCmts, $aBp = array(), $aDp = array())
  1099. {
  1100. $iStart = $iPerView = 0;
  1101. switch($aBp['type']) {
  1102. case BX_CMT_BROWSE_HEAD:
  1103. case BX_CMT_BROWSE_POPULAR:
  1104. case BX_CMT_BROWSE_CONNECTION:
  1105. $iPerView = $aBp['per_view'];
  1106. $iStart = $aBp['start'] + $iPerView;
  1107. if($iStart >= $aBp['count'])
  1108. return $sCmts;
  1109. break;
  1110. case BX_CMT_BROWSE_TAIL:
  1111. $iPerView = $aBp['per_view'];
  1112. $iStart = $aBp['start'] - $iPerView;
  1113. if($iStart < 0) {
  1114. $iPerView += $iStart;
  1115. $iStart = 0;
  1116. }
  1117. if($iStart == 0 && $iPerView == 0)
  1118. return $sCmts;
  1119. break;
  1120. }
  1121. $sParentKey = isset($aBp['vparent_id']) ? 'vparent_id' : 'parent_id';
  1122. $bRoot = (int)$aBp[$sParentKey] <= 0;
  1123. $sMore = $this->_oTemplate->parseHtmlByName('comment_more.html', array(
  1124. 'js_object' => $this->_sJsObjName,
  1125. 'style_prefix' => $this->_sStylePrefix,
  1126. 'bx_if:is_root' => array(
  1127. 'condition' => $bRoot,
  1128. 'content' => array()
  1129. ),
  1130. 'parent_id' => $aBp[$sParentKey],
  1131. 'start' => $iStart,
  1132. 'per_view' => $iPerView,
  1133. 'title' => _t('_cmt_load_more_' . ($aBp[$sParentKey] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
  1134. ));
  1135. switch($aBp['type']) {
  1136. case BX_CMT_BROWSE_HEAD:
  1137. case BX_CMT_BROWSE_POPULAR:
  1138. case BX_CMT_BROWSE_CONNECTION:
  1139. $sCmts .= $sMore;
  1140. break;
  1141. case BX_CMT_BROWSE_TAIL:
  1142. $sCmts = $sMore . $sCmts;
  1143. break;
  1144. }
  1145. return $sCmts;
  1146. }
  1147. protected function _getEmpty($aDp = array())
  1148. {
  1149. $sClass = '';
  1150. if(!empty($aDp['class']))
  1151. $sClass .= ' ' . $aDp['class'];
  1152. return $this->_oTemplate->parseHtmlByName('comment_empty.html', array(
  1153. 'style_prefix' => $this->_sStylePrefix,
  1154. 'class' => $sClass,
  1155. 'content' => MsgBox(_t('_Empty'))
  1156. ));
  1157. }
  1158. protected function _getAttachments($aCmt)
  1159. {
  1160. $aTmplImages = array();
  1161. if(!$this->isAttachImageEnabled())
  1162. return '';
  1163. $aFiles = $this->_oQuery->getFiles($this->_aSystem['system_id'], $aCmt['cmt_id']);
  1164. if(!empty($aFiles) && is_array($aFiles)) {
  1165. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  1166. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->getTranscoderPreviewName());
  1167. foreach($aFiles as $aFile) {
  1168. $sFile = $oStorage->getFileUrlById($aFile['image_id']);
  1169. $bImage = $oTranscoder && $oTranscoder->isMimeTypeSupported($aFile['mime_type']);
  1170. $sPreview = '';
  1171. $iWidth = $iHeight = 0;
  1172. if($bImage) {
  1173. if($oTranscoder)
  1174. $sPreview = $oTranscoder->getFileUrl($aFile['image_id']);
  1175. $aImageInfo = BxDolImageResize::getInstance()->getImageSize($sFile);
  1176. if(isset($aImageInfo['w']))
  1177. $iWidth = (int)$aImageInfo['w'];
  1178. if(isset($aImageInfo['h']))
  1179. $iHeight = (int)$aImageInfo['h'];
  1180. }
  1181. if(!$sPreview)
  1182. $sPreview = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFile['file_name']));
  1183. $aTmplVarsFile = array(
  1184. 'js_object' => $this->_sJsObjName,
  1185. 'preview' => $sPreview,
  1186. 'file' => $sFile,
  1187. 'file_id' => $aFile['id'],
  1188. 'file_name' => $aFile['file_name'],
  1189. 'file_icon' => $oStorage->getFontIconNameByFileName($aFile['file_name']),
  1190. 'file_size' => _t_format_size($aFile['size']),
  1191. 'w' => $iWidth,
  1192. 'h' => $iHeight
  1193. );
  1194. $aTmplImages[] = array(
  1195. 'style_prefix' => $this->_sStylePrefix,
  1196. 'bx_if:show_image' => array(
  1197. 'condition' => $bImage,
  1198. 'content' => $aTmplVarsFile
  1199. ),
  1200. 'bx_if:show_file' => array(
  1201. 'condition' => !$bImage,
  1202. 'content' => $aTmplVarsFile
  1203. ),
  1204. );
  1205. }
  1206. }
  1207. return $this->_oTemplate->parseHtmlByName('comment_attachments.html', array(
  1208. 'bx_repeat:attached' => $aTmplImages
  1209. ));
  1210. }
  1211. protected function _getTmplVarsNotes($aCmt)
  1212. {
  1213. $aTmplVars = array();
  1214. //--- Pending status related notes.
  1215. if($aCmt['cmt_status_admin'] == BX_CMT_STATUS_PENDING)
  1216. $aTmplVars[] = [
  1217. 'style_prefix' => $this->_sStylePrefix,
  1218. 'bx_if:show_note_color' => [
  1219. 'condition' => true,
  1220. 'content' => [
  1221. 'item_note_color' => 'red3'
  1222. ]
  1223. ],
  1224. 'item_note' => _t('_cmt_txt_note_approve_pending')
  1225. ];
  1226. return [
  1227. 'bx_if:show_notes' => [
  1228. 'condition' => !empty($aTmplVars),
  1229. 'content' => [
  1230. 'style_prefix' => $this->_sStylePrefix,
  1231. 'bx_repeat:notes' => $aTmplVars
  1232. ]
  1233. ],
  1234. ];
  1235. }
  1236. protected function _getTmplVarsAuthor($aCmt)
  1237. {
  1238. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  1239. $bAuthorIcon = !empty($sAuthorIcon);
  1240. return array(
  1241. 'author_unit' => $sAuthorUnit,
  1242. 'bx_if:show_icon' => array(
  1243. 'condition' => $bAuthorIcon,
  1244. 'content' => array(
  1245. 'author_icon' => $sAuthorIcon
  1246. )
  1247. ),
  1248. 'bx_if:show_icon_empty' => array(
  1249. 'condition' => !$bAuthorIcon,
  1250. 'content' => array()
  1251. ),
  1252. 'bx_if:show_author_link' => array(
  1253. 'condition' => !empty($sAuthorLink),
  1254. 'content' => array(
  1255. 'author_link' => $sAuthorLink,
  1256. 'author_title' => bx_html_attribute($sAuthorName),
  1257. 'author_name' => $sAuthorName
  1258. )
  1259. ),
  1260. 'bx_if:show_author_text' => array(
  1261. 'condition' => empty($sAuthorLink),
  1262. 'content' => array(
  1263. 'author_name' => $sAuthorName
  1264. )
  1265. ),
  1266. );
  1267. }
  1268. protected function _getTmplVarsText($aCmt)
  1269. {
  1270. $sText = $aCmt['cmt_text'];
  1271. $sTextMore = '';
  1272. if(!$this->isHtml()) {
  1273. $iMaxLength = (int)$this->_aSystem['chars_display_max'];
  1274. if(strlen($sText) > $iMaxLength) {
  1275. $iLength = strpos($sText, ' ', $iMaxLength);
  1276. $sTextMore = trim(substr($sText, $iLength));
  1277. $sText = trim(substr($sText, 0, $iLength));
  1278. }
  1279. }
  1280. $sText = $this->_prepareTextForOutput($sText, $aCmt['cmt_id']);
  1281. $sTextMore = $this->_prepareTextForOutput($sTextMore, $aCmt['cmt_id']);
  1282. return array(
  1283. 'text' => $sText,
  1284. 'bx_if:show_more' => array(
  1285. 'condition' => !empty($sTextMore),
  1286. 'content' => array(
  1287. 'style_prefix' => $this->_sStylePrefix,
  1288. 'js_object' => $this->_sJsObjName,
  1289. 'text_more' => $sTextMore
  1290. )
  1291. ),
  1292. );
  1293. }
  1294. }
  1295. /** @} */