BxBaseCmts.php 68 KB

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