BxBaseCmts.php 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * @see BxDolCmts
  11. */
  12. class BxBaseCmts extends BxDolCmts
  13. {
  14. protected static $_sTmplContentElementBlock;
  15. protected static $_sTmplContentElementInline;
  16. protected static $_sTmplContentDoCommentLabel;
  17. protected static $_sTmplContentCounter;
  18. protected $_sTmplNameItem;
  19. protected $_sTmplNameItemContent;
  20. protected $_sJsObjClass;
  21. protected $_sJsObjName;
  22. protected $_sStylePrefix;
  23. protected $_aHtmlIds;
  24. protected $_aAclId2Name;
  25. function __construct( $sSystem, $iId, $iInit = true, $oTemplate = false)
  26. {
  27. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  28. if (empty($sSystem))
  29. return;
  30. $this->_sTmplNameItem = 'comment.html';
  31. $this->_sTmplNameItemContent = 'comment_content.html';
  32. $this->_sJsObjClass = 'BxDolCmts';
  33. $this->_sJsObjName = 'oCmts' . bx_gen_method_name($sSystem, array('_' , '-')) . '_' .str_replace('-', 'n', $iId);
  34. $this->_sStylePrefix = isset($this->_aSystem['root_style_prefix']) ? $this->_aSystem['root_style_prefix'] : 'cmt';
  35. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sSystem) . '-' . $iId;
  36. $this->_aHtmlIds = array(
  37. 'main' => 'bx-cmt-' . $sHtmlId,
  38. 'counter' => 'bx-cmt-counter-' . $sHtmlId
  39. );
  40. $this->_aElementDefaults = [
  41. 'show_do_comment_as_button' => false,
  42. 'show_do_comment_as_button_small' => false,
  43. 'show_do_comment_icon' => true,
  44. 'show_do_comment_label' => false,
  45. 'show_counter' => true,
  46. 'show_counter_only' => true,
  47. 'show_counter_empty' => false,
  48. 'show_counter_reversed' => false,
  49. 'recalculate_counter' => false
  50. ];
  51. $this->_aElementDefaultsApi = array_merge($this->_aElementDefaults, [
  52. 'show_counter' => true,
  53. ]);
  54. $this->_aElementParamsApi = [];
  55. $this->_aAclId2Name = array();
  56. $aAclLevels = BxDolAcl::getInstance()->getMemberships(false, false, false);
  57. foreach($aAclLevels as $iAclId => $sAclName)
  58. $this->_aAclId2Name[$iAclId] = str_replace('_', '-', str_replace('_adm_prm_txt_level_', '', $sAclName));
  59. if(empty(self::$_sTmplContentElementBlock))
  60. self::$_sTmplContentElementBlock = $this->_oTemplate->getHtml('comment_element_block.html');
  61. if(empty(self::$_sTmplContentElementInline))
  62. self::$_sTmplContentElementInline = $this->_oTemplate->getHtml('comment_element_inline.html');
  63. if(empty(self::$_sTmplContentDoCommentLabel))
  64. self::$_sTmplContentDoCommentLabel = $this->_oTemplate->getHtml('comment_do_comment_label.html');
  65. if(empty(self::$_sTmplContentCounter))
  66. self::$_sTmplContentCounter = $this->_oTemplate->getHtml('comment_counter.html');
  67. $this->_oTemplate->addJsTranslation('_sys_txt_cmt_loading');
  68. }
  69. /**
  70. * Add comments CSS/JS
  71. */
  72. public function addCssJs ()
  73. {
  74. $oForm = BxDolForm::getObjectInstance($this->_sFormObject, $this->_sFormDisplayPost);
  75. $oForm->addCssJs();
  76. $this->_oTemplate->addCss(array(
  77. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'photo-swipe/|photoswipe.css',
  78. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'photo-swipe/default-skin/|default-skin.css',
  79. ));
  80. $this->_oTemplate->addJs(array(
  81. 'photo-swipe/photoswipe.min.js',
  82. 'photo-swipe/photoswipe-ui-default.min.js',
  83. ));
  84. }
  85. public function getJsObjectName()
  86. {
  87. return $this->_sJsObjName;
  88. }
  89. /**
  90. * Get initialization section of comments box
  91. *
  92. * @return string
  93. */
  94. public function getJsScript($aBp = [], $aDp = [])
  95. {
  96. $bMinPostForm = isset($aDp['min_post_form']) ? $aDp['min_post_form'] : $this->_bMinPostForm;
  97. $aParams = [
  98. 'sObjName' => $this->_sJsObjName,
  99. 'sRootUrl' => BX_DOL_URL_ROOT,
  100. 'sSystem' => $this->getSystemName(),
  101. 'iAuthorId' => $this->_getAuthorId(),
  102. 'iObjId' => $this->getId(),
  103. 'sBaseUrl' => $this->getBaseUrl(),
  104. 'sSocket' => $this->getSocketName(),
  105. 'sPostFormPosition' => $this->_aSystem['post_form_position'],
  106. 'sBrowseType' => $this->_sBrowseType,
  107. 'sDisplayType' => $this->_sDisplayType,
  108. 'iDisplayStructure' => isset($aDp['structure']) && !empty($aDp['structure']) ? 1 : 0,
  109. 'iMinPostForm' => $bMinPostForm ? 1 : 0,
  110. 'sStylePrefix' => $this->_sStylePrefix,
  111. 'aHtmlIds' => $this->_aHtmlIds,
  112. ];
  113. $this->addCssJs();
  114. return $this->_oTemplate->_wrapInTagJsCode("if(window['" . $this->_sJsObjName . "'] == undefined) var " . $this->_sJsObjName . " = new " . $this->_sJsObjClass . "(" . json_encode($aParams) . "); " . $this->_sJsObjName . ".cmtInit();");
  115. }
  116. function getCommentsBlockAPI($aParams, $aBp = [], $aDp = ['in_designbox' => false, 'show_empty' => false])
  117. {
  118. $mixedResult = $this->isViewAllowed();
  119. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  120. return $mixedResult; // TODO: error checking
  121. $aBp['type'] = 'head';
  122. $this->_getParams($aBp, $aDp);
  123. $this->_prepareParams($aBp, $aDp);
  124. $aBp['order']['way'] = 'desc';
  125. $aBp['order_way'] = 'desc';
  126. $aBp['start'] = 0 ;
  127. $aPp = $aBp['per_view'];
  128. $aBp['per_view'] = $aBp['per_view'] + 1;
  129. $aCmts = [];
  130. if (!isset($aParams['comment_id']))
  131. $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp[($aBp['init_view'] != -1 ? 'init' : 'per') . '_view']);
  132. else
  133. $aCmts = [['cmt_id' => $aParams['comment_id']]];
  134. $aParams['start_from'] = 0;
  135. if (count($aCmts) == $aBp['per_view']){
  136. $aBp['per_view'] = $aPp;
  137. $aCmts = array_slice($aCmts, 0, $aBp['per_view']);
  138. $aParams['start_from'] = $aBp['start'] + $aBp['per_view'];
  139. }
  140. $aCmtsRv = [];
  141. foreach ($aCmts as $aCmt) {
  142. $aCmtsRv[] = $this->getCommentStructure($aCmt['cmt_id'], $aBp, $aDp);
  143. }
  144. return [
  145. 'unit' => 'comments',
  146. 'start' => 0,
  147. 'order' => 'a',
  148. 'module' => $this->_sSystem,
  149. 'object_id' => $this->_iId,
  150. 'data' => $aCmtsRv,
  151. ];
  152. }
  153. /**
  154. * get full comments block with initializations
  155. */
  156. function getCommentsBlock($aBp = [], $aDp = [])
  157. {
  158. $mixedResult = $this->isViewAllowed();
  159. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  160. return $mixedResult;
  161. $this->_getParams($aBp, $aDp);
  162. $oSockets = BxDolSockets::getInstance();
  163. $bSockets = $oSockets->isEnabled();
  164. if(!$bSockets) {
  165. //add live update
  166. $this->actionResumeLiveUpdate();
  167. if(($oLiveUpdates = BxDolLiveUpdates::getInstance())!== false) {
  168. $sServiceCall = BxDolService::getSerializedService('system', 'get_live_update', [$this->_sSystem, $this->_iId, $this->_getAuthorId(), '{count}'], 'TemplCmtsServices');
  169. $oLiveUpdates->add($this->_sSystem . '_live_updates_cmts_' . $this->_iId, 1, $sServiceCall);
  170. }
  171. //add live update
  172. }
  173. $sComments = $this->getComments($aBp, $aDp);
  174. $sCommentsPinned = $this->getCommentsPinned(array_merge($aBp, ['pinned' => 1]), $aDp);
  175. $sContentBefore = $this->_getContentBefore($aBp, $aDp);
  176. $sContentAfter = $this->_getContentAfter($aBp, $aDp);
  177. if($bSockets)
  178. $sContentAfter .= $this->getLiveUpdateButton();
  179. $sPostFormTop = $this->getFormBoxPost($aBp, array_merge($aDp, ['type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_TOP]));
  180. $sPostFormBottom = $this->getFormBoxPost($aBp, array_merge($aDp, ['type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_BOTTOM]));
  181. $sJsContent = $this->getJsScript($aBp, $aDp);
  182. $sBlockTitle = _t($this->_aT['block_comments_title'], $this->getCommentsCountAll(0, true));
  183. $sBlockMenu = $this->_getControlsBox();
  184. bx_alert('system', 'view_comments', 0, 0, [
  185. 'object' => $this,
  186. 'system' => $this->_sSystem,
  187. 'id' => $this->getId(),
  188. 'params_browse' => $aBp,
  189. 'params_display' => $aDp,
  190. 'post_form_top' => &$sPostFormTop,
  191. 'content_before' => &$sContentBefore,
  192. 'comments' => &$sComments,
  193. 'comments_pinned' => &$sCommentsPinned,
  194. 'content_after' => &$sContentAfter,
  195. 'post_form_bottom' => &$sPostFormBottom,
  196. 'js_content' => &$sJsContent,
  197. 'block_title' => &$sBlockTitle,
  198. 'block_menu' => &$sBlockMenu,
  199. ]);
  200. $sContent = $this->_oTemplate->parseHtmlByName('comments_block.html', [
  201. 'style_prefix' => $this->_sStylePrefix,
  202. 'js_object' => $this->_sJsObjName,
  203. 'system' => $this->_sSystem,
  204. 'list_anchor' => $this->getListAnchor(),
  205. 'id' => $this->getId(),
  206. 'content_before' => $sContentBefore,
  207. 'comments' => $sComments,
  208. 'comments_pinned' => $sCommentsPinned,
  209. 'bx_if:show_divider_hidden' => [
  210. 'condition' => empty($sCommentsPinned),
  211. 'content' => []
  212. ],
  213. 'content_after' => $sContentAfter,
  214. 'post_form_top' => $sPostFormTop,
  215. 'post_form_bottom' => $sPostFormBottom,
  216. 'image_preview' => $this->_oTemplate->parseHtmlByName('comments_photoswipe.html', []),
  217. 'script' => $sJsContent
  218. ]);
  219. return $aDp['in_designbox'] ? DesignBoxContent($sBlockTitle, $sContent, BX_DB_DEF, $sBlockMenu) : [
  220. 'title' => $sBlockTitle,
  221. 'content' => $sContent,
  222. 'menu' => $sBlockMenu,
  223. ];
  224. }
  225. /**
  226. * get comments list for specified parent comment
  227. *
  228. * @param array $aBp - browse params array
  229. * @param array $aDp - display params array
  230. *
  231. */
  232. function getComments($aBp = [], $aDp = [])
  233. {
  234. $this->_prepareParams($aBp, $aDp);
  235. $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp[($aBp['init_view'] != -1 ? 'init' : 'per') . '_view']);
  236. if(empty($aCmts) || !is_array($aCmts))
  237. return isset($aDp['show_empty']) && $aDp['show_empty'] === true ? $this->_getEmpty($aDp) : '';
  238. $sCmts = '';
  239. foreach($aCmts as $k => $aCmt)
  240. $sCmts .= $this->getComment($aCmt, $aBp, $aDp);
  241. $sCmts = $this->_getMoreLink($sCmts, $aBp, $aDp);
  242. return $sCmts;
  243. }
  244. function getCommentsPinned($aBp = [], $aDp = [])
  245. {
  246. $this->_prepareParams($aBp, $aDp);
  247. $aCmts = $this->getCommentsArray($aBp['vparent_id'], BX_CMT_FILTER_PINNED, $aBp['order'], 0, -1);
  248. if(empty($aCmts) || !is_array($aCmts))
  249. return '';
  250. $sCmts = '';
  251. foreach($aCmts as $k => $aCmt)
  252. $sCmts .= $this->getComment($aCmt, $aBp, $aDp);
  253. return $sCmts;
  254. }
  255. public function getCommentsByStructure($aBp = array(), $aDp = array())
  256. {
  257. if(empty($aDp['structure']))
  258. return isset($aDp['show_empty']) && $aDp['show_empty'] === true ? $this->_getEmpty($aDp) : '';
  259. $aBp['count'] = count($aDp['structure']);
  260. $this->_prepareParams($aBp, $aDp);
  261. $aDp['structure'] = array_slice($aDp['structure'], $aBp['start'], $aBp[($aBp['init_view'] != -1 ? 'init' : 'per') . '_view'], true);
  262. $sCmts = '';
  263. foreach($aDp['structure'] as $iCmtId => $aCmt)
  264. $sCmts .= $this->getComment($iCmtId, $aBp, $aDp);
  265. $sCmts = $this->_getMoreLink($sCmts, $aBp, $aDp);
  266. return $sCmts;
  267. }
  268. /**
  269. * get comment view block with initializations
  270. */
  271. function getCommentBlock($iCmtId = 0, $aBp = array(), $aDp = array())
  272. {
  273. $mixedResult = $this->isViewAllowed();
  274. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  275. return $mixedResult;
  276. $aBp = array_merge(array('type' => $this->_sBrowseType), $aBp);
  277. $aDp = array_merge(array('type' => BX_CMT_DISPLAY_THREADED), $aDp);
  278. //--- Beg: Using pregenerated structure
  279. $mixedStructure = $this->getCommentStructure((int)$iCmtId, $aBp, $aDp);
  280. if($mixedStructure !== false)
  281. $aDp['structure'] = $mixedStructure;
  282. //--- End: Using pregenerated structure
  283. $sComment = $this->getComment($iCmtId, $aBp, $aDp);
  284. if (!$sComment)
  285. return '';
  286. BxDolTemplate::getInstance()->addInjection ('injection_footer', 'text', $this->_oTemplate->parseHtmlByName('comments_photoswipe.html', []));
  287. return $this->_oTemplate->parseHtmlByName('comment_block.html', array(
  288. 'system' => $this->_sSystem,
  289. 'id' => $this->getId(),
  290. 'comment' => $sComment,
  291. 'script' => $this->getJsScript($aBp, $aDp)
  292. ));
  293. }
  294. /**
  295. * get one just posted comment
  296. *
  297. * @param int $iCmtId - comment id
  298. * @return string
  299. */
  300. function getComment($mixedCmt, $aBp = array(), $aDp = array())
  301. {
  302. $iUserId = $this->_getAuthorId();
  303. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  304. if (!$aCmt)
  305. return '';
  306. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  307. $sClass = $sClassCnt = '';
  308. if(isset($aCmt['vote_rate']) && (float)$aCmt['vote_rate'] < $this->_aSystem['viewing_threshold']) {
  309. $this->_oTemplate->pareseHtmlByName('comment_hidden.html', array(
  310. 'js_object' => $this->_sJsObjName,
  311. 'id' => $aCmt['cmt_id'],
  312. 'title' => bx_process_output(_t('_hidden_comment', $sAuthorName)),
  313. 'bx_if:show_replies' => array(
  314. 'condition' => $aCmt['cmt_replies'] > 0,
  315. 'content' => array(
  316. 'replies' => _t('_Show N replies', $aCmt['cmt_replies'])
  317. )
  318. )
  319. ));
  320. $sClass = ' ' . $this->_sStylePrefix . '-hidden';
  321. }
  322. if($aCmt['cmt_author_id'] == $iUserId)
  323. $sClass .= ' ' . $this->_sStylePrefix . '-mine';
  324. $aAuthorAcl = BxDolAcl::getInstance()->getMemberMembershipInfo($aCmt['cmt_author_id']);
  325. if(!empty($aAuthorAcl) && isset($this->_aAclId2Name[$aAuthorAcl['id']]))
  326. $sClass .= ' ' . $this->_sStylePrefix . '-aml-' . $this->_aAclId2Name[$aAuthorAcl['id']];
  327. if(!empty($aDp['blink']) && in_array($aCmt['cmt_id'], $aDp['blink']))
  328. $sClass .= ' ' . $this->_sStylePrefix . '-blink';
  329. if(!empty($aDp['class_comment']))
  330. $sClass .= ' ' . $aDp['class_comment'];
  331. if(!empty($aDp['class_comment_content']))
  332. $sClassCnt .= ' ' . $aDp['class_comment_content'];
  333. $sActions = $this->_getActionsBox($aCmt, $aBp, $aDp);
  334. $aTmplReplyTo = array();
  335. if((int)$aCmt['cmt_parent_id'] != 0) {
  336. $aParent = $this->getCommentRow($aCmt['cmt_parent_id']);
  337. if(!empty($aParent) && is_array($aParent)) {
  338. $oProfile = $this->_getAuthorObject($aParent['cmt_author_id']);
  339. $sParAuthorName = $oProfile->getDisplayName();
  340. $sParAuthorUnit = $oProfile->getUnit(0, array('template' => array('name' => 'unit_wo_info_links', 'size' => 'icon')));
  341. $aTmplReplyTo = array(
  342. 'style_prefix' => $this->_sStylePrefix,
  343. 'par_cmt_link' => $this->getItemUrl($aCmt['cmt_parent_id']),
  344. 'par_cmt_title' => bx_html_attribute(_t('_in_reply_to_x', $sParAuthorName)),
  345. 'par_cmt_author' => $sParAuthorName,
  346. 'par_cmt_author_unit' => $sParAuthorUnit
  347. );
  348. }
  349. }
  350. $sReplies = '';
  351. if(!(isset($aBp['pinned']) && (int)$aBp['pinned'] != 0 && (int)$aCmt['cmt_pinned'] != 0) && !empty($aDp)) {
  352. $aDp['show_empty'] = false;
  353. if(!empty($aDp['structure'][$aCmt['cmt_id']]) && is_array($aDp['structure'][$aCmt['cmt_id']])) {
  354. if(!empty($aDp['structure'][$aCmt['cmt_id']]['items'])) {
  355. $aDp['structure'] = $aDp['structure'][$aCmt['cmt_id']]['items'];
  356. $sReplies = $this->getCommentsByStructure(array('parent_id' => $aCmt['cmt_id'], 'type' => $aBp['type']), $aDp);
  357. }
  358. }
  359. else if((int)$aCmt['cmt_replies'] > 0 && $aDp['type'] == BX_CMT_DISPLAY_THREADED)
  360. $sReplies = $this->getComments(array('parent_id' => $aCmt['cmt_id'], 'vparent_id' => $aCmt['cmt_id'], 'type' => $aBp['type']), $aDp);
  361. }
  362. $aTmplVarsMeta = array();
  363. if(!empty($this->_sMenuObjMeta)) {
  364. $oMenuMeta = BxDolMenu::getObjectInstance($this->_sMenuObjMeta, $this->_oTemplate);
  365. if($oMenuMeta) {
  366. $oMenuMeta->setCmtsData($this, $aCmt['cmt_id']);
  367. $aTmplVarsMeta = array(
  368. 'style_prefix' => $this->_sStylePrefix,
  369. 'meta' => $oMenuMeta->getCode()
  370. );
  371. }
  372. }
  373. if($this->_isShowContent($aCmt)) {
  374. $sContent = $this->_getContent($aCmt, $aBp, $aDp);
  375. }
  376. else {
  377. $sClass .= ' cmt-author-not-active';
  378. $sContent = _t('_hidden_comment', BxDolProfileUndefined::getInstance()->getDisplayName());
  379. }
  380. $aVars = array_merge(array(
  381. 'system' => $this->_sSystem,
  382. 'style_prefix' => $this->_sStylePrefix,
  383. 'js_object' => $this->_sJsObjName,
  384. 'id' => $aCmt['cmt_id'],
  385. 'anchor' => $this->getItemAnchor($aCmt['cmt_id']),
  386. 'class' => $sClass,
  387. 'class_cnt' => $sClassCnt,
  388. 'bx_if:show_reply_to' => array(
  389. 'condition' => !empty($aTmplReplyTo),
  390. 'content' => $aTmplReplyTo
  391. ),
  392. 'bx_if:meta' => array(
  393. 'condition' => !empty($aTmplVarsMeta),
  394. 'content' => $aTmplVarsMeta
  395. ),
  396. 'bx_if:show_pinned' => array(
  397. 'condition' => (int)$aCmt['cmt_pinned'] > 0,
  398. 'content' => array(
  399. 'style_prefix' => $this->_sStylePrefix,
  400. )
  401. ),
  402. 'content' => $sContent,
  403. 'actions' => $sActions,
  404. 'replies' => $sReplies,
  405. ), $this->_getTmplVarsAuthor($aCmt), $this->_getTmplVarsNotes($aCmt));
  406. $sResult = $this->_oTemplate->parseHtmlByName($this->_sTmplNameItem, $aVars);
  407. 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));
  408. return $sResult;
  409. }
  410. public function getCommentStructure($iCmtId, $aBp = array(), $aDp = array())
  411. {
  412. $aRoot = $this->getCommentRow((int)$iCmtId);
  413. $aBps = $aBp;
  414. if(!empty($aRoot))
  415. $aBps['parent_id'] = $aRoot['cmt_id'];
  416. $this->_prepareStructureBp($aDp['type'], $aBps);
  417. $iLevel = 0;
  418. $aStructure = array();
  419. $this->{'_getStructure' . ($this->_bIsApi ? 'API' : '')}($aRoot, $aBps, $iLevel, $aStructure);
  420. return !empty($aStructure) && is_array($aStructure) ? $aStructure : false;
  421. }
  422. function getCommentSearch($iCmtId, &$sAddon)
  423. {
  424. $aBp = array();
  425. $aDp = array(
  426. 'type' => BX_CMT_DISPLAY_FLAT,
  427. 'view_only' => true
  428. );
  429. if(empty($sAddon))
  430. $sAddon = $this->getJsScript($aBp, $aDp);
  431. BxDolTemplate::getInstance()->addInjection ('injection_footer', 'text', $this->_oTemplate->parseHtmlByName('comments_photoswipe.html', []));
  432. return $this->_oTemplate->parseHtmlByName('comment_search.html', array(
  433. 'comment' => $this->getComment($iCmtId, $aBp, $aDp),
  434. ));
  435. }
  436. /**
  437. * get one comment for "Live Search"
  438. *
  439. * @param int $iCmtId - comment id
  440. * @return string
  441. */
  442. function getCommentLiveSearch($mixedCmt, $aParams = array())
  443. {
  444. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  445. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  446. $bAuthorIcon = !empty($sAuthorIcon);
  447. $sViewLink = $this->getViewUrl($aCmt['cmt_id']);
  448. if(empty($sViewLink))
  449. $sViewLink = '#';
  450. return $this->_oTemplate->parseHtmlByName('comment_live_search.html', array(
  451. 'bx_if:show_icon' => array(
  452. 'condition' => $bAuthorIcon,
  453. 'content' => array(
  454. 'author_icon' => $sAuthorIcon,
  455. 'view_link' => $sViewLink
  456. )
  457. ),
  458. 'bx_if:show_icon_empty' => array(
  459. 'condition' => !$bAuthorIcon,
  460. 'content' => array()
  461. ),
  462. 'view_link' => $sViewLink,
  463. 'text' => BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($aCmt['cmt_text']), $this->_sSnippetLenthLiveSearch),
  464. 'sample' => isset($aParams['txt_sample_single']) ? _t($aParams['txt_sample_single']) : ''
  465. ));
  466. }
  467. function getFormBoxPost($aBp = array(), $aDp = array())
  468. {
  469. return $this->_getFormBox(BX_CMT_ACTION_POST, $aBp, $aDp);
  470. }
  471. function getFormBoxEdit($aBp = array(), $aDp = array())
  472. {
  473. return $this->_getFormBox(BX_CMT_ACTION_EDIT, $aBp, $aDp);
  474. }
  475. function getFormPost($iCmtParentId = 0, $aDp = array())
  476. {
  477. return $this->_getFormPost($iCmtParentId, $aDp);
  478. }
  479. function getFormEdit($iCmtId, $aDp = array())
  480. {
  481. return $this->_getFormEdit($iCmtId, $aDp);
  482. }
  483. function getControlsBox()
  484. {
  485. return $this->_getControlsBox();
  486. }
  487. function getLiveUpdate($iCountOld = 0, $iCountNew = 0)
  488. {
  489. $iCount = (int)$iCountNew - (int)$iCountOld;
  490. if($iCount < 0)
  491. return '';
  492. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  493. if(empty($aComments) || !is_array($aComments))
  494. return '';
  495. $aComment = array_shift($aComments);
  496. if(empty($aComment) || !is_array($aComment))
  497. return '';
  498. return $this->getLiveUpdateButton($aComment['cmt_id']);
  499. }
  500. function getLiveUpdateButton($iCommentId = 0)
  501. {
  502. $sJsObject = $this->getJsObjectName();
  503. $bComment = is_numeric($iCommentId) && (int)$iCommentId != 0;
  504. return $this->_oTemplate->parseHtmlByName('comments_lu_button.html', array(
  505. 'style_prefix' => $this->_sStylePrefix,
  506. 'class' => !$bComment ? 'hidden' : '',
  507. 'onclick_show' => "javascript:" . $sJsObject . ".goToBtn(this, '" . ($bComment ? $this->getItemAnchor($iCommentId) : '{cmt_anchor}') . "', '" . ($bComment ? $iCommentId : '{cmt_id}') . "');",
  508. ));
  509. }
  510. function getLiveUpdates($iCountOld = 0, $iCountNew = 0)
  511. {
  512. $bShowAll = true;
  513. $bShowActions = false;
  514. $iCount = (int)$iCountNew - (int)$iCountOld;
  515. if($iCount < 0)
  516. return '';
  517. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  518. if(empty($aComments) || !is_array($aComments))
  519. return '';
  520. $sJsObject = $this->getJsObjectName();
  521. $iUserId = $this->_getAuthorId();
  522. $bModerator = $this->isModerator();
  523. $aComments = array_reverse($aComments);
  524. $iComments = count($aComments);
  525. $aTmplVarsNotifs = array();
  526. foreach($aComments as $iIndex => $aComment) {
  527. $iCommentId = $aComment['cmt_id'];
  528. $sShowOnClick = "javascript:" . $sJsObject . ".goTo(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  529. $sReplyOnClick = "javascript:" . $sJsObject . ".goToAndReply(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  530. $iAuthorId = (int)$aComment['cmt_author_id'];
  531. if($iAuthorId < 0) {
  532. if(abs($iAuthorId) == $iUserId)
  533. continue;
  534. else if($bModerator)
  535. $iAuthorId *= -1;
  536. }
  537. $oAuthor = $this->_getAuthorObject($iAuthorId);
  538. $sAuthorName = $oAuthor->getDisplayName();
  539. $aTmplVarsNotifs[] = array(
  540. 'bx_if:show_as_hidden' => array(
  541. 'condition' => !$bShowAll && $iIndex < ($iComments - 1),
  542. 'content' => array(),
  543. ),
  544. 'item' => $this->_oTemplate->parseHtmlByName('comments_lu_notifications.html', array(
  545. 'style_prefix' => $this->_sStylePrefix,
  546. 'onclick_show' => $sShowOnClick,
  547. 'onclick_reply' => $sReplyOnClick,
  548. 'author_link' => $oAuthor->getUrl(),
  549. 'author_title' => bx_html_attribute($sAuthorName),
  550. 'author_name' => $sAuthorName,
  551. 'author_unit' => $oAuthor->getUnit(0, array('template' => 'unit_wo_info_links')),
  552. 'text' => _t('_cmt_txt_added_sample')
  553. )),
  554. 'bx_if:show_previous' => array(
  555. 'condition' => $bShowActions && $iIndex > 0,
  556. 'content' => array(
  557. 'onclick_previous' => $sJsObject . '.previousLiveUpdate(this)'
  558. )
  559. ),
  560. 'bx_if:show_close' => array(
  561. 'condition' => $bShowActions,
  562. 'content' => array(
  563. 'onclick_close' => $sJsObject . '.hideLiveUpdate(this)'
  564. )
  565. )
  566. );
  567. }
  568. return $this->_oTemplate->parseHtmlByName('popup_chain.html', array(
  569. 'html_id' => $this->getNotificationId(),
  570. 'bx_repeat:items' => $aTmplVarsNotifs
  571. ));
  572. }
  573. public function getElementBlock($aParams = array())
  574. {
  575. $aParams['usage'] = BX_CMT_USAGE_BLOCK;
  576. return $this->getElement($aParams);
  577. }
  578. public function getElementInline($aParams = array())
  579. {
  580. $aParams['usage'] = BX_CMT_USAGE_INLINE;
  581. return $this->getElement($aParams);
  582. }
  583. public function getElement($aParams = array())
  584. {
  585. $aParams = array_merge($this->_aElementDefaults, $aParams);
  586. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  587. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  588. $bShowCounterEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  589. $bRecalculateCounter = isset($aParams['recalculate_counter']) && $aParams['recalculate_counter'] == true;
  590. $iObjectId = $this->getId();
  591. $iAuthorId = $this->_getAuthorId();
  592. $iAuthorIp = $this->_getAuthorIp();
  593. $iCount = $this->getCommentsCountAll(0, $bRecalculateCounter);
  594. $bCount = (int)$iCount != 0;
  595. $isAllowedComment = $this->isPostAllowed();
  596. //--- Do Comment
  597. $bTmplVarsDoComment = $this->_isShowDoComment($aParams, $isAllowedComment, $bCount);
  598. $aTmplVarsDoComment = [];
  599. if($bTmplVarsDoComment)
  600. $aTmplVarsDoComment = [
  601. 'style_prefix' => $this->_sStylePrefix,
  602. 'do_comment' => $this->_getDoComment($aParams, $isAllowedComment),
  603. ];
  604. //--- Counter
  605. $bTmplVarsCounter = $this->_isShowCounter($aParams, $isAllowedComment, $bCount);
  606. $aTmplVarsCounter = array();
  607. if($bTmplVarsCounter)
  608. $aTmplVarsCounter = array(
  609. 'style_prefix' => $this->_sStylePrefix,
  610. 'bx_if:show_hidden' => array(
  611. 'condition' => !$bShowCounterEmpty && !$bCount,
  612. 'content' => array()
  613. ),
  614. 'counter' => $this->getCounter(array_merge($aParams, [
  615. 'show_counter_only' => false
  616. ]))
  617. );
  618. if(!$bTmplVarsDoComment && !$bTmplVarsCounter)
  619. return '';
  620. $sTmplName = $this->{'_getTmplElement' . bx_gen_method_name(!empty($aParams['usage']) ? $aParams['usage'] : BX_CMT_USAGE_DEFAULT)}();
  621. return $this->_oTemplate->parseHtmlByContent($sTmplName, array(
  622. 'style_prefix' => $this->_sStylePrefix,
  623. 'html_id' => $this->_aHtmlIds['main'],
  624. 'class' => $this->_sStylePrefix . ($bShowDoCommentAsButton ? '-button' : '') . ($bShowDoCommentAsButtonSmall ? '-button-small' : ''),
  625. 'count' => $iCount,
  626. 'bx_if:show_do_comment' => array(
  627. 'condition' => $bTmplVarsDoComment,
  628. 'content' => $aTmplVarsDoComment
  629. ),
  630. 'bx_if:show_counter' => array(
  631. 'condition' => $bTmplVarsCounter,
  632. 'content' => $aTmplVarsCounter
  633. ),
  634. 'script' => ''
  635. ));
  636. }
  637. public function getElementAPI($aParams = [])
  638. {
  639. if(!$this->_bIsApi)
  640. return;
  641. if(!$this->isEnabled())
  642. return bx_api_get_msg('_cmt_err_not_enabled');
  643. $aParams = array_merge($this->_aElementDefaultsApi, $aParams);
  644. $bRecalculateCounter = isset($aParams['recalculate_counter']) && $aParams['recalculate_counter'] == true;
  645. $iObjectId = $this->getId();
  646. $iAuthorId = $this->_getAuthorId();
  647. $iCount = $this->getCommentsCountAll(0, $bRecalculateCounter);
  648. $bCount = (int)$iCount != 0;
  649. $isAllowedComment = $this->isPostAllowed();
  650. $aParams['count'] = $iCount;
  651. //--- Do Comment
  652. $bDoComment = $this->_isShowDoComment($aParams, $isAllowedComment, $bCount);
  653. $aDoComment = $bDoComment ? $this->_getDoComment($aParams, $isAllowedComment) : [];
  654. //--- Counter
  655. $bCounter = $this->_isShowCounter($aParams, $isAllowedComment, $bCount);
  656. $aCounter = $bCounter ? $this->getCounterAPI(array_merge($aParams, [
  657. 'show_counter_only' => false,
  658. ])) : [];
  659. if(!$bDoComment && !$bCounter)
  660. return bx_api_get_msg('');
  661. return [
  662. 'type' => $this->_sType,
  663. 'system' => $this->_sSystem,
  664. 'object_id' => $this->_iId,
  665. 'params' => array_intersect_key($aParams, array_flip($this->_aElementParamsApi)),
  666. 'action' => $aDoComment,
  667. 'counter' => $aCounter
  668. ];
  669. }
  670. public function getCounter($aParams = [])
  671. {
  672. $aParams = array_merge($this->_aElementDefaults, $aParams);
  673. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  674. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  675. $bShowEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  676. $bShowReversed = isset($aParams['show_counter_reversed']) && $aParams['show_counter_reversed'] == true;
  677. $bShowScript = !isset($aParams['show_script']) || (bool)$aParams['show_script'] === true;
  678. $bRecalculateCounter = isset($aParams['recalculate_counter']) && $aParams['recalculate_counter'] == true;
  679. $sClass = 'sys-action-counter';
  680. if(isset($aParams['show_counter_only']) && (bool)$aParams['show_counter_only'] === true)
  681. $sClass .= ' sys-ac-only';
  682. $iCount = (int)$this->getCommentsCountAll(0, $bRecalculateCounter);
  683. if($iCount == 0 && !$bShowEmpty)
  684. $sClass .= ' sys-ac-hidden';
  685. $sClass .= ' ' . $this->_sStylePrefix . '-counter';
  686. if($bShowDoCommentAsButtonSmall)
  687. $sClass .= ' bx-btn-small-height';
  688. if($bShowDoCommentAsButton)
  689. $sClass .= ' bx-btn-height';
  690. $iCmtsLimit = 5;
  691. $aCmts = $this->_getCounterItems($iCmtsLimit);
  692. if(!$bShowReversed)
  693. $aCmts = array_reverse($aCmts);
  694. $aTmplVarsProfiles = [];
  695. foreach($aCmts as $aCmt) {
  696. $iAuthor = (int)$aCmt['cmt_author_id'];
  697. if(array_key_exists($iAuthor, $aTmplVarsProfiles))
  698. continue;
  699. $oAuthor = BxDolProfile::getInstanceMagic($iAuthor);
  700. if(!$oAuthor)
  701. continue;
  702. $aTmplVarsProfiles[$iAuthor] = [
  703. 'icon' => $oAuthor->getUnit(0, ['template' => ['name' => 'unit_wo_info_links', 'size' => 'icon']])
  704. ];
  705. if(count($aTmplVarsProfiles) >= $iCmtsLimit)
  706. break;
  707. }
  708. $aTmplVarsProfiles = array_values($aTmplVarsProfiles);
  709. $sHref = !empty($aParams['overwrite_counter_link_href']) ? $aParams['overwrite_counter_link_href'] : $this->getListUrl();
  710. $sOnclick = '';
  711. if(!empty($aParams['overwrite_counter_link_onclick']))
  712. $sOnclick = $aParams['overwrite_counter_link_onclick'];
  713. return $this->_oTemplate->parseHtmlByContent($this->_getTmplCounter(), [
  714. 'style_prefix' => $this->_sStylePrefix,
  715. 'id' => $this->_aHtmlIds['counter'],
  716. 'class' => $sClass,
  717. 'href' => $sHref,
  718. 'bx_if:show_onclick' => [
  719. 'condition' => !empty($sOnclick),
  720. 'content' => [
  721. 'onclick' => $sOnclick
  722. ]
  723. ],
  724. 'content' => $this->_getCounterLabel($iCount, $aParams),
  725. 'bx_repeat:profiles' => $aTmplVarsProfiles,
  726. 'bx_if:show_icon' => [
  727. 'condition' => ($bShowEmpty || !empty($aTmplVarsProfiles)) && (!isset($aParams['show_icon']) || $aParams['show_icon']),
  728. 'content' => [
  729. 'style_prefix' => $this->_sStylePrefix,
  730. 'icon' => !empty($aParams['custom_icon']) ? $aParams['custom_icon'] : $this->_oTemplate->getImageAuto('comment|' . $this->_sStylePrefix . '-counter-icon')
  731. ]
  732. ],
  733. 'script' => $this->getJsScript()
  734. ]);
  735. }
  736. public function getCounterApi($aParams = [])
  737. {
  738. $aParams = array_merge($this->_aElementDefaultsApi, $aParams);
  739. $bShowReversed = isset($aParams['show_counter_reversed']) && $aParams['show_counter_reversed'] == true;
  740. $bRecalculateCounter = isset($aParams['recalculate_counter']) && $aParams['recalculate_counter'] == true;
  741. $iCount = (int)$this->getCommentsCountAll(0, $bRecalculateCounter);
  742. $iCmtsLimit = 5;
  743. $aCmts = $this->_getCounterItems($iCmtsLimit);
  744. if(!$bShowReversed)
  745. $aCmts = array_reverse($aCmts);
  746. $aCmtsAuthors = [];
  747. foreach($aCmts as $aCmt) {
  748. $iAuthor = (int)$aCmt['cmt_author_id'];
  749. if(array_key_exists($iAuthor, $aCmtsAuthors))
  750. continue;
  751. $aCmtsAuthors[$iAuthor] = BxDolProfile::getData($iAuthor);
  752. if(count($aCmtsAuthors) >= $iCmtsLimit)
  753. break;
  754. }
  755. $aCmtsAuthors = array_values($aCmtsAuthors);
  756. return [
  757. 'count' => $iCount,
  758. 'authors' => $aCmtsAuthors
  759. ];
  760. }
  761. protected function _getCounterItems($iCmtsLimit, $iCmtsStart = 0)
  762. {
  763. return $this->_oQuery->getCommentsBy(array('type' => 'object_id', 'object_id' => $this->getId(), 'order_way' => 'desc', 'start' => $iCmtsStart, 'per_page' => $iCmtsLimit * 4));
  764. }
  765. protected function _getLabelDo($aParams = [])
  766. {
  767. return $this->_oTemplate->parseHtmlByContent($this->_getTmplLabelDo(), [
  768. 'style_prefix' => $this->_sStylePrefix,
  769. 'bx_if:show_icon' => [
  770. 'condition' => isset($aParams['show_do_comment_icon']) && $aParams['show_do_comment_icon'] == true,
  771. 'content' => [
  772. 'style_prefix' => $this->_sStylePrefix,
  773. 'icon' => $this->_oTemplate->getImageAuto($this->_getIconDo())
  774. ]
  775. ],
  776. 'bx_if:show_text' => [
  777. 'condition' => isset($aParams['show_do_comment_label']) && $aParams['show_do_comment_label'] == true,
  778. 'content' => [
  779. 'style_prefix' => $this->_sStylePrefix,
  780. 'text' => _t($this->_getTitleDo())
  781. ]
  782. ]
  783. ]);
  784. }
  785. protected function _getCounterLabel($iCount, $aParams = [])
  786. {
  787. $aParams = array_merge($this->_aElementDefaults, $aParams);
  788. $sResult = '';
  789. if((int)$iCount != 0)
  790. $sResult = _t(isset($aParams['caption']) ? $aParams['caption'] : '_cmt_txt_counter', $iCount);
  791. else
  792. $sResult = _t(isset($aParams['caption_empty']) ? $aParams['caption_empty'] : '_cmt_txt_counter_empty');
  793. return $sResult;
  794. }
  795. protected function _getTmplElementBlock()
  796. {
  797. return self::$_sTmplContentElementBlock;
  798. }
  799. protected function _getTmplElementInline()
  800. {
  801. return self::$_sTmplContentElementInline;
  802. }
  803. protected function _getTmplLabelDo()
  804. {
  805. return self::$_sTmplContentDoCommentLabel;
  806. }
  807. protected function _getTmplCounter()
  808. {
  809. return self::$_sTmplContentCounter;
  810. }
  811. protected function _isShowContent($aCmt)
  812. {
  813. $oProfileAuthor = BxDolProfile::getInstance(abs($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 bx_is_api() ? bx_api_get_msg(_t('_No such comment')) : array('msg' => _t('_No such comment'));
  1112. $iCmtAuthorId = $this->_getAuthorId();
  1113. if(!$this->isEditAllowed($aCmt)){
  1114. $sMsg = $aCmt['cmt_author_id'] == $iCmtAuthorId ? strip_tags($this->msgErrEditAllowed()) : _t('_Access denied');
  1115. return bx_is_api() ? bx_api_get_msg($sMsg) : array('msg' => $sMsg);
  1116. }
  1117. $oForm = $this->_getForm(BX_CMT_ACTION_EDIT, $aCmt['cmt_id']);
  1118. $oForm->initChecker($aCmt);
  1119. if($oForm->isSubmittedAndValid()) {
  1120. $sCmtText = $oForm->getCleanValue('cmt_text');
  1121. if($oForm->update($iCmtId) !== false) {
  1122. $iCmtUniqId = $this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId, [
  1123. 'author_id' => (int)$aCmt['cmt_author_id']
  1124. ]);
  1125. $sStatusAdmin = $this->getStatusAdmin();
  1126. if($sStatusAdmin !== BX_CMT_STATUS_ACTIVE)
  1127. $this->_oQuery->updateUniqId(['status_admin' => $sStatusAdmin], ['id' => $iCmtUniqId]);
  1128. if($this->isAttachImageEnabled())
  1129. $oForm->processImages($this, 'cmt_image', $iCmtUniqId, $iCmtId, $iCmtAuthorId, false);
  1130. $this->isEditAllowed($aCmt, true);
  1131. if($this->_sMetatagsObj && ($oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj)) !== false)
  1132. $oMetatags->metaAdd($iCmtUniqId, $sCmtText);
  1133. if(($mixedResult = $this->onEditAfter($iCmtId, $aDp)) !== false){
  1134. if (bx_is_api()){
  1135. $this->_unsetFormObject(BX_CMT_ACTION_POST);
  1136. return ['form' => $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId), 'res' => $iCmtId];
  1137. }
  1138. else{
  1139. return $mixedResult;
  1140. }
  1141. }
  1142. }
  1143. return bx_is_api() ? bx_api_get_msg(_t('_cmt_err_cannot_perform_action')) : array('msg' => _t('_cmt_err_cannot_perform_action'));
  1144. }
  1145. return bx_is_api() ? ['form' => $oForm, 'res' => 0] : 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. return [
  1388. 'style_prefix' => $this->_sStylePrefix,
  1389. 'text' => $this->_prepareTextForOutput($aCmt['cmt_text'], $aCmt['cmt_id'])
  1390. ];
  1391. }
  1392. protected function _getDoComment($aParams = [], $isAllowedComment = true)
  1393. {
  1394. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  1395. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  1396. $iCount = isset($aParams['count']) ? (int)$aParams['count'] : 0;
  1397. $bDisabled = !$isAllowedComment;
  1398. $sClass = '';
  1399. if($bShowDoCommentAsButton)
  1400. $sClass = 'bx-btn';
  1401. else if ($bShowDoCommentAsButtonSmall)
  1402. $sClass = 'bx-btn bx-btn-small';
  1403. if(!$isAllowedComment)
  1404. $sClass .= $bShowDoCommentAsButton || $bShowDoCommentAsButtonSmall ? ' bx-btn-disabled' : 'bx-cmts-disabled';
  1405. if($this->_bIsApi)
  1406. return [
  1407. 'is_disabled' => $bDisabled,
  1408. 'count' => $iCount,
  1409. 'link' => bx_api_get_relative_url($this->getListUrl()),
  1410. 'title' => _t($this->_getTitleDo(), $iCount)
  1411. ];
  1412. return $this->_oTemplate->parseLink($this->getListUrl(), $this->_getLabelDo($aParams), [
  1413. 'class' => $this->_sStylePrefix . '-do-comment ' . $this->_sStylePrefix . '-dc ' . $sClass,
  1414. 'title' => _t($this->_getTitleDo(), $iCount)
  1415. ]);
  1416. }
  1417. }
  1418. /** @} */