BxBaseCmts.php 70 KB

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