1
0

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