BxBaseCmts.php 63 KB

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