BxBaseCmts.php 69 KB

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