BxBaseCmts.php 59 KB

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