BxBaseCmts.php 64 KB

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