BxBaseCmts.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  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 $_sJsObjName;
  19. protected $_sStylePrefix;
  20. protected $_aHtmlIds;
  21. protected $_aElementDefaults;
  22. function __construct( $sSystem, $iId, $iInit = true, $oTemplate = false)
  23. {
  24. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  25. if (empty($sSystem))
  26. return;
  27. $this->_sJsObjName = 'oCmts' . bx_gen_method_name($sSystem, array('_' , '-')) . $iId;
  28. $this->_sStylePrefix = isset($this->_aSystem['root_style_prefix']) ? $this->_aSystem['root_style_prefix'] : 'cmt';
  29. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sSystem) . '-' . $iId;
  30. $this->_aHtmlIds = array(
  31. 'main' => 'bx-cmt-' . $sHtmlId,
  32. 'counter' => 'bx-cmt-counter-' . $sHtmlId
  33. );
  34. $this->_aElementDefaults = array(
  35. 'show_do_comment_as_button' => false,
  36. 'show_do_comment_as_button_small' => false,
  37. 'show_do_comment_image' => false,
  38. 'show_do_comment_icon' => true,
  39. 'show_do_comment_label' => false,
  40. 'show_counter' => true,
  41. 'show_counter_empty' => false
  42. );
  43. if(empty(self::$_sTmplContentElementBlock))
  44. self::$_sTmplContentElementBlock = $this->_oTemplate->getHtml('comment_element_block.html');
  45. if(empty(self::$_sTmplContentElementInline))
  46. self::$_sTmplContentElementInline = $this->_oTemplate->getHtml('comment_element_inline.html');
  47. if(empty(self::$_sTmplContentDoCommentLabel))
  48. self::$_sTmplContentDoCommentLabel = $this->_oTemplate->getHtml('comment_do_comment_label.html');
  49. if(empty(self::$_sTmplContentCounter))
  50. self::$_sTmplContentCounter = $this->_oTemplate->getHtml('comment_counter.html');
  51. $this->_oTemplate->addJsTranslation('_sys_txt_cmt_loading');
  52. }
  53. /**
  54. * Add comments CSS/JS
  55. */
  56. public function addCssJs ()
  57. {
  58. $oForm = BxDolForm::getObjectInstance($this->_sFormObject, $this->_sFormDisplayPost);
  59. $oForm->addCssJs();
  60. }
  61. public function getJsObjectName()
  62. {
  63. return $this->_sJsObjName;
  64. }
  65. /**
  66. * Get initialization section of comments box
  67. *
  68. * @return string
  69. */
  70. public function getJsScript($aBp = array(), $aDp = array())
  71. {
  72. $bMinPostForm = isset($aDp['min_post_form']) ? $aDp['min_post_form'] : $this->_bMinPostForm;
  73. $aParams = array(
  74. 'sObjName' => $this->_sJsObjName,
  75. 'sRootUrl' => BX_DOL_URL_ROOT,
  76. 'sSystem' => $this->getSystemName(),
  77. 'iAuthorId' => $this->_getAuthorId(),
  78. 'iObjId' => $this->getId(),
  79. 'sBaseUrl' => $this->getBaseUrl(),
  80. 'sPostFormPosition' => $this->_aSystem['post_form_position'],
  81. 'sBrowseType' => $this->_sBrowseType,
  82. 'sDisplayType' => $this->_sDisplayType,
  83. 'iMinPostForm' => $bMinPostForm ? 1 : 0,
  84. );
  85. $this->addCssJs();
  86. return $this->_oTemplate->_wrapInTagJsCode("if(window['" . $this->_sJsObjName . "'] == undefined) var " . $this->_sJsObjName . " = new BxDolCmts(" . json_encode($aParams) . ");");
  87. }
  88. /**
  89. * get full comments block with initializations
  90. */
  91. function getCommentsBlock($aBp = array(), $aDp = array())
  92. {
  93. $this->_getParams($aBp, $aDp);
  94. //add live update
  95. $this->actionResumeLiveUpdate();
  96. $sServiceCall = BxDolService::getSerializedService('system', 'get_live_updates_comments', array($this->_sSystem, $this->_iId, $this->_getAuthorId(), '{count}'), 'TemplCmtsServices');
  97. BxDolLiveUpdates::getInstance()->add($this->_sSystem . '_live_updates_cmts_' . $this->_iId, 1, $sServiceCall);
  98. //add live update
  99. $sCaption = _t($this->_aT['block_comments_title'], $this->getCommentsCountAll());
  100. $sContent = $this->_oTemplate->parseHtmlByName('comments_block.html', array(
  101. 'system' => $this->_sSystem,
  102. 'list_anchor' => $this->getListAnchor(),
  103. 'id' => $this->getId(),
  104. 'comments' => $this->getComments($aBp, $aDp),
  105. 'post_form_top' => $this->getFormBoxPost($aBp, array_merge($aDp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_TOP))),
  106. 'post_form_bottom' => $this->getFormBoxPost($aBp, array_merge($aDp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_BOTTOM))),
  107. 'view_image_popup' => $this->_getViewImagePopup(),
  108. 'script' => $this->getJsScript($aBp, $aDp)
  109. ));
  110. return $aDp['in_designbox'] ? DesignBoxContent($sCaption, $sContent, BX_DB_DEF, $this->_getControlsBox()) : array(
  111. 'title' => $sCaption,
  112. 'content' => $sContent,
  113. 'menu' => $this->_getControlsBox(),
  114. );
  115. }
  116. /**
  117. * get comments list for specified parent comment
  118. *
  119. * @param array $aBp - browse params array
  120. * @param array $aDp - display params array
  121. *
  122. */
  123. function getComments($aBp = array(), $aDp = array())
  124. {
  125. $this->_prepareParams($aBp, $aDp);
  126. $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp['per_view']);
  127. if(empty($aCmts) || !is_array($aCmts)) {
  128. if((int)$aBp['parent_id'] == 0 && !isLogged()) {
  129. $oPermalink = BxDolPermalinks::getInstance();
  130. return MsgBox(_t('_cmt_msg_login_required', $oPermalink->permalink('page.php?i=login'), $oPermalink->permalink('page.php?i=create-account')));
  131. }
  132. return isset($aDp['show_empty']) && $aDp['show_empty'] === true ? $this->_getEmpty() : '';
  133. }
  134. $sCmts = '';
  135. foreach($aCmts as $k => $aCmt)
  136. $sCmts .= $this->getComment($aCmt, $aBp, $aDp);
  137. $sCmts = $this->_getMoreLink($sCmts, $aBp, $aDp);
  138. return $sCmts;
  139. }
  140. /**
  141. * get comment view block with initializations
  142. */
  143. function getCommentBlock($iCmtId = 0, $aBp = array(), $aDp = array())
  144. {
  145. $mixedResult = $this->isViewAllowed();
  146. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  147. return $mixedResult;
  148. $aBp = array_merge(array('type' => $this->_sBrowseType), $aBp);
  149. $aDp = array_merge(array('type' => BX_CMT_DISPLAY_THREADED), $aDp);
  150. $sComment = $this->getComment($iCmtId, $aBp, $aDp);
  151. if (!$sComment)
  152. return '';
  153. return $this->_oTemplate->parseHtmlByName('comment_block.html', array(
  154. 'system' => $this->_sSystem,
  155. 'id' => $this->getId(),
  156. 'comment' => $sComment,
  157. 'view_image_popup' => $this->_getViewImagePopup(),
  158. 'script' => $this->getJsScript($aBp, $aDp)
  159. ));
  160. }
  161. /**
  162. * get one just posted comment
  163. *
  164. * @param int $iCmtId - comment id
  165. * @return string
  166. */
  167. function getComment($mixedCmt, $aBp = array(), $aDp = array())
  168. {
  169. $iUserId = $this->_getAuthorId();
  170. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  171. if (!$aCmt)
  172. return '';
  173. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  174. $sClass = $sClassCnt = '';
  175. if(isset($aCmt['vote_rate']) && (float)$aCmt['vote_rate'] < $this->_aSystem['viewing_threshold']) {
  176. $this->_oTemplate->pareseHtmlByName('comment_hidden.html', array(
  177. 'js_object' => $this->_sJsObjName,
  178. 'id' => $aCmt['cmt_id'],
  179. 'title' => bx_process_output(_t('_hidden_comment', $sAuthorName)),
  180. 'bx_if:show_replies' => array(
  181. 'condition' => $aCmt['cmt_replies'] > 0,
  182. 'content' => array(
  183. 'replies' => _t('_Show N replies', $aCmt['cmt_replies'])
  184. )
  185. )
  186. ));
  187. $sClass = ' ' . $this->_sStylePrefix . '-hidden';
  188. }
  189. if($aCmt['cmt_author_id'] == $iUserId)
  190. $sClass .= ' ' . $this->_sStylePrefix . '-mine';
  191. if(!empty($aDp['blink']) && in_array($aCmt['cmt_id'], $aDp['blink']))
  192. $sClass .= ' ' . $this->_sStylePrefix . '-blink';
  193. if(!empty($aDp['class_comment']))
  194. $sClass .= ' ' . $aDp['class_comment'];
  195. if(!empty($aDp['class_comment_content']))
  196. $sClassCnt .= ' ' . $aDp['class_comment_content'];
  197. $sActions = $this->_getActionsBox($aCmt, $aDp);
  198. $aTmplReplyTo = array();
  199. if((int)$aCmt['cmt_parent_id'] != 0) {
  200. $aParent = $this->getCommentRow($aCmt['cmt_parent_id']);
  201. list($sParAuthorName, $sParAuthorLink, $sParAuthorIcon) = $this->_getAuthorInfo($aParent['cmt_author_id']);
  202. $aTmplReplyTo = array(
  203. 'style_prefix' => $this->_sStylePrefix,
  204. 'par_cmt_link' => $this->getItemUrl($aCmt['cmt_parent_id']),
  205. 'par_cmt_title' => bx_html_attribute(_t('_in_reply_to', $sParAuthorName)),
  206. 'par_cmt_author' => $sParAuthorName
  207. );
  208. }
  209. $sAttachments = $this->_getAttachments($aCmt);
  210. $sReplies = '';
  211. if((int)$aCmt['cmt_replies'] > 0 && !empty($aDp) && $aDp['type'] == BX_CMT_DISPLAY_THREADED) {
  212. $aDp['show_empty'] = false;
  213. $sReplies = $this->getComments(array('parent_id' => $aCmt['cmt_id'], 'vparent_id' => $aCmt['cmt_id'], 'type' => $aBp['type']), $aDp);
  214. }
  215. $aTmplVarsMeta = array();
  216. if(!empty($this->_sMenuObjMeta)) {
  217. $oMenuMeta = BxDolMenu::getObjectInstance($this->_sMenuObjMeta, $this->_oTemplate);
  218. if($oMenuMeta) {
  219. $oMenuMeta->setCmtsData($this, $aCmt['cmt_id']);
  220. $aTmplVarsMeta = array(
  221. 'style_prefix' => $this->_sStylePrefix,
  222. 'meta' => $oMenuMeta->getCode()
  223. );
  224. }
  225. }
  226. return $this->_oTemplate->parseHtmlByName('comment.html', array_merge(array(
  227. 'system' => $this->_sSystem,
  228. 'style_prefix' => $this->_sStylePrefix,
  229. 'js_object' => $this->_sJsObjName,
  230. 'id' => $aCmt['cmt_id'],
  231. 'anchor' => $this->getItemAnchor($aCmt['cmt_id']),
  232. 'class' => $sClass,
  233. 'class_cnt' => $sClassCnt,
  234. 'bx_if:show_reply_to' => array(
  235. 'condition' => !empty($aTmplReplyTo),
  236. 'content' => $aTmplReplyTo
  237. ),
  238. 'bx_if:meta' => array(
  239. 'condition' => !empty($aTmplVarsMeta),
  240. 'content' => $aTmplVarsMeta
  241. ),
  242. 'bx_if:show_attached' => array(
  243. 'condition' => !empty($sAttachments),
  244. 'content' => array(
  245. 'style_prefix' => $this->_sStylePrefix,
  246. 'attached' => $sAttachments
  247. )
  248. ),
  249. 'actions' => $sActions,
  250. 'replies' => $sReplies
  251. ), $this->_getTmplVarsAuthor($aCmt), $this->_getTmplVarsText($aCmt)));
  252. }
  253. function getCommentSearch($iCmtId, &$sAddon)
  254. {
  255. $aBp = array();
  256. $aDp = array(
  257. 'type' => BX_CMT_DISPLAY_FLAT,
  258. 'view_only' => true
  259. );
  260. if(empty($sAddon))
  261. $sAddon = $this->getJsScript($aBp, $aDp);
  262. return $this->_oTemplate->parseHtmlByName('comment_search.html', array(
  263. 'comment' => $this->getComment($iCmtId, $aBp, $aDp),
  264. 'view_image_popup' => $this->_getViewImagePopup(),
  265. ));
  266. }
  267. /**
  268. * get one comment for "Live Search"
  269. *
  270. * @param int $iCmtId - comment id
  271. * @return string
  272. */
  273. function getCommentLiveSearch($mixedCmt, $aParams = array())
  274. {
  275. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  276. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  277. $bAuthorIcon = !empty($sAuthorIcon);
  278. $sViewLink = $this->getViewUrl($aCmt['cmt_id']);
  279. if(empty($sViewLink))
  280. $sViewLink = '#';
  281. return $this->_oTemplate->parseHtmlByName('comment_live_search.html', array(
  282. 'bx_if:show_icon' => array(
  283. 'condition' => $bAuthorIcon,
  284. 'content' => array(
  285. 'author_icon' => $sAuthorIcon,
  286. 'view_link' => $sViewLink
  287. )
  288. ),
  289. 'bx_if:show_icon_empty' => array(
  290. 'condition' => !$bAuthorIcon,
  291. 'content' => array()
  292. ),
  293. 'view_link' => $sViewLink,
  294. 'text' => BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($aCmt['cmt_text']), $this->_sSnippetLenthLiveSearch),
  295. 'sample' => isset($aParams['txt_sample_single']) ? _t($aParams['txt_sample_single']) : ''
  296. ));
  297. }
  298. function getFormBoxPost($aBp = array(), $aDp = array())
  299. {
  300. if(!$this->isPostReplyAllowed())
  301. return '';
  302. return $this->_getFormBox(BX_CMT_ACTION_POST, $aBp, $aDp);
  303. }
  304. function getFormBoxEdit($aBp = array(), $aDp = array())
  305. {
  306. return $this->_getFormBox(BX_CMT_ACTION_EDIT, $aBp, $aDp);
  307. }
  308. function getFormPost($iCmtParentId = 0, $aDp = array())
  309. {
  310. return $this->_getFormPost($iCmtParentId, $aDp);
  311. }
  312. function getFormEdit($iCmtId, $aDp = array())
  313. {
  314. return $this->_getFormEdit($iCmtId, $aDp);
  315. }
  316. function getNotification($iCountOld = 0, $iCountNew = 0)
  317. {
  318. $bShowAll = true;
  319. $bShowActions = false;
  320. $iCount = (int)$iCountNew - (int)$iCountOld;
  321. if($iCount < 0)
  322. return '';
  323. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  324. if(empty($aComments) || !is_array($aComments))
  325. return '';
  326. $sJsObject = $this->getJsObjectName();
  327. $iUserId = $this->_getAuthorId();
  328. $bModerator = $this->isModerator();
  329. $aComments = array_reverse($aComments);
  330. $iComments = count($aComments);
  331. $aTmplVarsNotifs = array();
  332. foreach($aComments as $iIndex => $aComment) {
  333. $iCommentId = $aComment['cmt_id'];
  334. $sShowOnClick = "javascript:" . $sJsObject . ".goTo(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  335. $sReplyOnClick = "javascript:" . $sJsObject . ".goToAndReply(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  336. $iAuthorId = (int)$aComment['cmt_author_id'];
  337. if($iAuthorId < 0) {
  338. if(abs($iAuthorId) == $iUserId)
  339. continue;
  340. else if($bModerator)
  341. $iAuthorId *= -1;
  342. }
  343. $oAuthor = $this->_getAuthorObject($iAuthorId);
  344. $sAuthorName = $oAuthor->getDisplayName();
  345. $aTmplVarsNotifs[] = array(
  346. 'bx_if:show_as_hidden' => array(
  347. 'condition' => !$bShowAll && $iIndex < ($iComments - 1),
  348. 'content' => array(),
  349. ),
  350. 'item' => $this->_oTemplate->parseHtmlByName('comments_notification.html', array(
  351. 'style_prefix' => $this->_sStylePrefix,
  352. 'onclick_show' => $sShowOnClick,
  353. 'onclick_reply' => $sReplyOnClick,
  354. 'author_link' => $oAuthor->getUrl(),
  355. 'author_title' => bx_html_attribute($sAuthorName),
  356. 'author_name' => $sAuthorName,
  357. 'author_unit' => $oAuthor->getUnit(0, array('template' => 'unit_wo_info_links')),
  358. 'text' => _t('_cmt_txt_added_sample')
  359. )),
  360. 'bx_if:show_previous' => array(
  361. 'condition' => $bShowActions && $iIndex > 0,
  362. 'content' => array(
  363. 'onclick_previous' => $sJsObject . '.previousLiveUpdate(this)'
  364. )
  365. ),
  366. 'bx_if:show_close' => array(
  367. 'condition' => $bShowActions,
  368. 'content' => array(
  369. 'onclick_close' => $sJsObject . '.hideLiveUpdate(this)'
  370. )
  371. )
  372. );
  373. }
  374. return $this->_oTemplate->parseHtmlByName('popup_chain.html', array(
  375. 'html_id' => $this->getNotificationId(),
  376. 'bx_repeat:items' => $aTmplVarsNotifs
  377. ));
  378. }
  379. public function getElementBlock($aParams = array())
  380. {
  381. $aParams['usage'] = BX_CMT_USAGE_BLOCK;
  382. return $this->getElement($aParams);
  383. }
  384. public function getElementInline($aParams = array())
  385. {
  386. $aParams['usage'] = BX_CMT_USAGE_INLINE;
  387. return $this->getElement($aParams);
  388. }
  389. public function getElement($aParams = array())
  390. {
  391. $aParams = array_merge($this->_aElementDefaults, $aParams);
  392. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  393. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  394. $bShowCounterEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  395. $iObjectId = $this->getId();
  396. $iAuthorId = $this->_getAuthorId();
  397. $iAuthorIp = $this->_getAuthorIp();
  398. $iCount = $this->getCommentsCountAll();
  399. $bCount = (int)$iCount != 0;
  400. $isAllowedComment = $this->isPostReplyAllowed();
  401. //--- Do Comment
  402. $bTmplVarsDoComment = $this->_isShowDoComment($aParams, $isAllowedComment, $bCount);
  403. $aTmplVarsDoComment = array();
  404. if($bTmplVarsDoComment) {
  405. $sClass = '';
  406. if($bShowDoCommentAsButton)
  407. $sClass = 'bx-btn';
  408. else if ($bShowDoCommentAsButtonSmall)
  409. $sClass = 'bx-btn bx-btn-small';
  410. if(!$isAllowedComment)
  411. $sClass .= $bShowDoCommentAsButton || $bShowDoCommentAsButtonSmall ? ' bx-btn-disabled' : 'bx-cmts-disabled';
  412. $aTmplVarsDoComment = array(
  413. 'style_prefix' => $this->_sStylePrefix,
  414. 'do_comment' => $this->_oTemplate->parseLink($this->getListUrl(), $this->_getLabelDo($aParams), array(
  415. 'class' => $this->_sStylePrefix . '-do-comment ' . $this->_sStylePrefix . '-dc ' . $sClass,
  416. 'title' => _t($this->_getTitleDo())
  417. )),
  418. );
  419. }
  420. //--- Counter
  421. $bTmplVarsCounter = $this->_isShowCounter($aParams, $isAllowedComment, $bCount);
  422. $aTmplVarsCounter = array();
  423. if($bTmplVarsCounter)
  424. $aTmplVarsCounter = array(
  425. 'style_prefix' => $this->_sStylePrefix,
  426. 'bx_if:show_hidden' => array(
  427. 'condition' => !$bShowCounterEmpty && !$bCount,
  428. 'content' => array()
  429. ),
  430. 'counter' => $this->getCounter($aParams)
  431. );
  432. if(!$bTmplVarsDoComment && !$bTmplVarsCounter)
  433. return '';
  434. $sTmplName = $this->{'_getTmplElement' . bx_gen_method_name(!empty($aParams['usage']) ? $aParams['usage'] : BX_DOL_SCORE_USAGE_DEFAULT)}();
  435. return $this->_oTemplate->parseHtmlByContent($sTmplName, array(
  436. 'style_prefix' => $this->_sStylePrefix,
  437. 'html_id' => $this->_aHtmlIds['main'],
  438. 'class' => $this->_sStylePrefix . ($bShowDoCommentAsButton ? '-button' : '') . ($bShowDoCommentAsButtonSmall ? '-button-small' : ''),
  439. 'count' => $iCount,
  440. 'bx_if:show_do_comment' => array(
  441. 'condition' => $bTmplVarsDoComment,
  442. 'content' => $aTmplVarsDoComment
  443. ),
  444. 'bx_if:show_counter' => array(
  445. 'condition' => $bTmplVarsCounter,
  446. 'content' => $aTmplVarsCounter
  447. ),
  448. 'script' => ''
  449. ));
  450. }
  451. public function getCounter($aParams = array())
  452. {
  453. $bShowEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  454. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  455. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  456. $iCount = (int)$this->getCommentsCountAll();
  457. $sClass = $this->_sStylePrefix . '-counter';
  458. if($bShowDoCommentAsButtonSmall)
  459. $sClass .= ' bx-btn-small-height';
  460. if($bShowDoCommentAsButton)
  461. $sClass .= ' bx-btn-height';
  462. return $this->_oTemplate->parseHtmlByContent($this->_getTmplCounter(), array(
  463. 'id' => $this->_aHtmlIds['counter'],
  464. 'class' => $sClass,
  465. 'content' => $iCount != 0 || $bShowEmpty ? $this->_getLabelCounter($iCount) : ''
  466. ));
  467. }
  468. protected function _getLabelDo($aParams = array())
  469. {
  470. return $this->_oTemplate->parseHtmlByContent($this->_getTmplLabelDo(), array(
  471. 'bx_if:show_image' => array(
  472. 'condition' => isset($aParams['show_do_comment_image']) && $aParams['show_do_comment_image'] == true,
  473. 'content' => array(
  474. 'src' => $this->_getImageDo()
  475. )
  476. ),
  477. 'bx_if:show_icon' => array(
  478. 'condition' => isset($aParams['show_do_comment_icon']) && $aParams['show_do_comment_icon'] == true,
  479. 'content' => array(
  480. 'name' => $this->_getIconDo()
  481. )
  482. ),
  483. 'bx_if:show_text' => array(
  484. 'condition' => isset($aParams['show_do_comment_label']) && $aParams['show_do_comment_label'] == true,
  485. 'content' => array(
  486. 'text' => _t($this->_getTitleDo())
  487. )
  488. )
  489. ));
  490. }
  491. protected function _getLabelCounter($iCount)
  492. {
  493. return (int)$iCount != 0 ? _t('_cmt_txt_counter', $iCount) : _t('_cmt_txt_counter_empty');
  494. }
  495. protected function _getTmplElementBlock()
  496. {
  497. return self::$_sTmplContentElementBlock;
  498. }
  499. protected function _getTmplElementInline()
  500. {
  501. return self::$_sTmplContentElementInline;
  502. }
  503. protected function _getTmplLabelDo()
  504. {
  505. return self::$_sTmplContentDoCommentLabel;
  506. }
  507. protected function _getTmplCounter()
  508. {
  509. return self::$_sTmplContentCounter;
  510. }
  511. /**
  512. * private functions
  513. */
  514. protected function _getControlsBox()
  515. {
  516. $sDisplay = '';
  517. $bDisplay = (int)$this->_aSystem['is_display_switch'] == 1;
  518. if($bDisplay) {
  519. $aDisplayLinks = array(
  520. array('id' => $this->_sSystem . '-flat', 'name' => $this->_sSystem . '-flat', 'class' => '', 'title' => '_cmt_display_flat', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'flat\');'),
  521. array('id' => $this->_sSystem . '-threaded', 'name' => $this->_sSystem . '-threaded', 'class' => '', 'title' => '_cmt_display_threaded', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'threaded\');')
  522. );
  523. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-display', 'menu_items' => $aDisplayLinks));
  524. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sDisplayType);
  525. $sDisplay = $oMenu->getCode();
  526. }
  527. $sBrowseType = '';
  528. $bBrowseType = (int)$this->_aSystem['is_browse_switch'] == 1;
  529. if($bBrowseType) {
  530. $aBrowseLinks = array(
  531. array('id' => $this->_sSystem . '-tail', 'name' => $this->_sSystem . '-tail', 'class' => '', 'title' => '_cmt_browse_tail', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'tail\');'),
  532. array('id' => $this->_sSystem . '-head', 'name' => $this->_sSystem . '-head', 'class' => '', 'title' => '_cmt_browse_head', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'head\');'),
  533. array('id' => $this->_sSystem . '-popular', 'name' => $this->_sSystem . '-popular', 'class' => '', 'title' => '_cmt_browse_popular', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'popular\');'),
  534. );
  535. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-browse', 'menu_items' => $aBrowseLinks));
  536. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseType);
  537. $sBrowseType = $oMenu->getCode();
  538. }
  539. $sBrowseFilter = '';
  540. $bBrowseFilter = (int)$this->_aSystem['is_browse_filter'] == 1;
  541. if($bBrowseFilter) {
  542. $aFilterLinks = array(
  543. array('id' => $this->_sSystem . '-all', 'name' => $this->_sSystem . '-all', 'class' => '', 'title' => '_cmt_browse_all', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'all\');'),
  544. array('id' => $this->_sSystem . '-friends', 'name' => $this->_sSystem . '-friends', 'class' => '', 'title' => '_cmt_browse_friends', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'friends\');'),
  545. array('id' => $this->_sSystem . '-subscriptions', 'name' => $this->_sSystem . '-subscriptions', 'class' => '', 'title' => '_cmt_browse_subscriptions', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'subscriptions\');')
  546. );
  547. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-filter', 'menu_items' => $aFilterLinks));
  548. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseFilter);
  549. $sBrowseFilter = $oMenu->getCode();
  550. }
  551. return $this->_oTemplate->parseHtmlByName('comments_controls.html', array(
  552. 'display_switcher' => $bDisplay ? $sDisplay : '',
  553. 'bx_if:is_divider_1' => array(
  554. 'condition' => $bDisplay && $bBrowseType,
  555. 'content' => array(
  556. 'style_prefix' => $this->_sStylePrefix,
  557. )
  558. ),
  559. 'browse_switcher' => $bBrowseType ? $sBrowseType : '',
  560. 'bx_if:is_divider_2' => array(
  561. 'condition' => $bBrowseType && $bBrowseFilter,
  562. 'content' => array(
  563. 'style_prefix' => $this->_sStylePrefix,
  564. )
  565. ),
  566. 'filter_switcher' => $bBrowseFilter ? $sBrowseFilter : '',
  567. ));
  568. }
  569. protected function _getActionsBox(&$aCmt, $aDp = array())
  570. {
  571. $bViewOnly = isset($aDp['view_only']) && $aDp['view_only'] === true;
  572. $bDynamicMode = isset($aDp['dynamic_mode']) && $aDp['dynamic_mode'] === true;
  573. $sMenuActions = '';
  574. if(!$bViewOnly) {
  575. $oMenuActions = BxDolMenu::getObjectInstance($this->_sMenuObjActions);
  576. $oMenuActions->setCmtsData($this, $aCmt['cmt_id']);
  577. $oMenuActions->setDynamicMode($bDynamicMode);
  578. $sMenuActions = $oMenuActions->getCode();
  579. }
  580. return $this->_oTemplate->parseHtmlByName('comment_actions.html', array(
  581. 'id' => $aCmt['cmt_id'],
  582. 'js_object' => $this->_sJsObjName,
  583. 'style_prefix' => $this->_sStylePrefix,
  584. 'menu_actions' => $sMenuActions,
  585. ));
  586. }
  587. protected function _getFormBox($sType, $aBp, $aDp)
  588. {
  589. $iCmtParentId = isset($aBp['parent_id']) ? (int)$aBp['parent_id'] : 0;
  590. $sPosition = isset($aDp['position']) ? $aDp['position'] : '';
  591. $bFormMin = $iCmtParentId == 0 && isset($aDp['min_post_form']) ? $aDp['min_post_form'] : false;
  592. $sPositionSystem = $this->_aSystem['post_form_position'];
  593. if(!empty($sPosition) && $sPositionSystem != $sPosition)
  594. return '';
  595. $sClass = '';
  596. if(!empty($sPosition))
  597. $sClass .= ' ' . $this->_sStylePrefix . '-reply-' . $sPosition;
  598. if($bFormMin)
  599. $sClass .= ' ' . $this->_sStylePrefix . '-reply-min';
  600. $aTmplVarsFormMin = array();
  601. if($bFormMin) {
  602. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($this->_getAuthorId());
  603. $aTmplVarsFormMin = array(
  604. 'js_object' => $this->_sJsObjName,
  605. 'style_prefix' => $this->_sStylePrefix,
  606. 'author_unit' => $sAuthorUnit,
  607. 'placeholder' => _t('_cmt_txt_min_form_placeholder', $sAuthorName)
  608. );
  609. }
  610. $sMethod = '_getForm' . ucfirst($sType);
  611. $aForm = $this->$sMethod($iCmtParentId, $aDp);
  612. return $this->_oTemplate->parseHtmlByName('comment_reply_box.html', array(
  613. 'js_object' => $this->_sJsObjName,
  614. 'style_prefix' => $this->_sStylePrefix,
  615. 'class' => $sClass,
  616. 'bx_if:show_form_min' => array(
  617. 'condition' => $bFormMin,
  618. 'content' => $aTmplVarsFormMin
  619. ),
  620. 'form' => $aForm['form'],
  621. 'form_id' => $aForm['form_id'],
  622. ));
  623. }
  624. protected function _getFormPost($iCmtParentId = 0, $aDp = array())
  625. {
  626. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  627. $oForm = $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId);
  628. $oForm->aInputs['cmt_parent_id']['value'] = $iCmtParentId;
  629. $oForm->initChecker();
  630. if($oForm->isSubmittedAndValid()) {
  631. $iCmtAuthorId = $this->_getAuthorId();
  632. $iCmtParentId = $oForm->getCleanValue('cmt_parent_id');
  633. $sCmtText = $oForm->getCleanValue('cmt_text');
  634. $iLevel = 0;
  635. $iCmtVisualParentId = 0;
  636. if((int)$iCmtParentId > 0) {
  637. $aParent = $this->getCommentRow($iCmtParentId);
  638. $iLevel = (int)$aParent['cmt_level'] + 1;
  639. $iCmtVisualParentId = $iLevel > $this->getMaxLevel() ? $aParent['cmt_vparent_id'] : $iCmtParentId;
  640. }
  641. $iCmtId = (int)$oForm->insert(array('cmt_vparent_id' => $iCmtVisualParentId, 'cmt_object_id' => $this->_iId, 'cmt_author_id' => $iCmtAuthorId, 'cmt_level' => $iLevel, 'cmt_time' => time()));
  642. if($iCmtId != 0) {
  643. if($this->isAttachImageEnabled()) {
  644. $aImages = $oForm->getCleanValue('cmt_image');
  645. if(!empty($aImages) && is_array($aImages)) {
  646. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  647. foreach($aImages as $iImageId)
  648. if($this->_oQuery->saveImages($this->_aSystem['system_id'], $iCmtId, $iImageId))
  649. $oStorage->afterUploadCleanup($iImageId, $iCmtAuthorId);
  650. }
  651. }
  652. if($iCmtParentId) {
  653. $this->_oQuery->updateRepliesCount($iCmtParentId, 1);
  654. if(!BxDolModuleQuery::getInstance()->isEnabledByName('bx_notifications'))
  655. $this->_sendNotificationEmail($iCmtId, $iCmtParentId);
  656. }
  657. $this->_triggerComment();
  658. $this->isPostReplyAllowed(true);
  659. if ($this->_sMetatagsObj) {
  660. $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
  661. $oMetatags->metaAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
  662. }
  663. $this->onPostAfter($iCmtId);
  664. return array('id' => $iCmtId, 'parent_id' => $iCmtParentId);
  665. }
  666. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  667. }
  668. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  669. }
  670. protected function _getFormEdit($iCmtId, $aDp = array())
  671. {
  672. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  673. $aCmt = $this->_oQuery->getCommentSimple ((int)$this->getId(), $iCmtId);
  674. if(!$aCmt)
  675. return array('msg' => _t('_No such comment'));
  676. $iCmtAuthorId = $this->_getAuthorId();
  677. if(!$this->isEditAllowed($aCmt))
  678. return array('msg' => $aCmt['cmt_author_id'] == $iCmtAuthorId ? strip_tags($this->msgErrEditAllowed()) : _t('_Access denied'));
  679. $oForm = $this->_getForm(BX_CMT_ACTION_EDIT, $aCmt['cmt_id']);
  680. $oForm->initChecker($aCmt);
  681. if($oForm->isSubmittedAndValid()) {
  682. $sCmtText = $oForm->getCleanValue('cmt_text');
  683. if($oForm->update($iCmtId) !== false) {
  684. $this->isEditAllowed($aCmt, true);
  685. if ($this->_sMetatagsObj) {
  686. $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
  687. $oMetatags->metaAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
  688. }
  689. $this->onEditAfter($iCmtId);
  690. return array('id' => $iCmtId, 'text' => $this->_prepareTextForOutput($sCmtText, $iCmtId));
  691. }
  692. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  693. }
  694. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  695. }
  696. protected function _getForm($sAction, $iId)
  697. {
  698. $oForm = $this->_getFormObject($sAction);
  699. $oForm->setId(sprintf($oForm->getAttributeMask('id'), $sAction, $this->_sSystem, $iId));
  700. $oForm->setName(sprintf($oForm->getAttributeMask('name'), $sAction, $this->_sSystem, $iId));
  701. $oForm->aParams['db']['table'] = $this->_aSystem['table'];
  702. $oForm->aInputs['sys']['value'] = $this->_sSystem;
  703. $oForm->aInputs['id']['value'] = $this->_iId;
  704. $oForm->aInputs['action']['value'] = 'Submit' . ucfirst($sAction) . 'Form';
  705. if(!$this->isAttachImageEnabled())
  706. unset($oForm->aInputs['cmt_image']);
  707. if(isset($oForm->aInputs['cmt_text'])) {
  708. $oForm->aInputs['cmt_text']['html'] = $this->_aSystem['html'];
  709. $oForm->aInputs['cmt_text']['db']['pass'] = $this->isHtml() ? 'XssHtml' : 'XssMultiline';
  710. $iCmtTextMin = (int)$this->_aSystem['chars_post_min'];
  711. $iCmtTextMax = (int)$this->_aSystem['chars_post_max'];
  712. $oForm->aInputs['cmt_text']['checker']['params'] = array($iCmtTextMin, $iCmtTextMax);
  713. $oForm->aInputs['cmt_text']['checker']['error'] = _t('_Please enter n1-n2 characters', $iCmtTextMin, $iCmtTextMax);
  714. }
  715. return $oForm;
  716. }
  717. protected function _getMoreLink($sCmts, $aBp = array(), $aDp = array())
  718. {
  719. $iStart = $iPerView = 0;
  720. switch($aBp['type']) {
  721. case BX_CMT_BROWSE_HEAD:
  722. case BX_CMT_BROWSE_POPULAR:
  723. case BX_CMT_BROWSE_CONNECTION:
  724. $iPerView = $aBp['per_view'];
  725. $iStart = $aBp['start'] + $iPerView;
  726. if($iStart >= $aBp['count'])
  727. return $sCmts;
  728. break;
  729. case BX_CMT_BROWSE_TAIL:
  730. $iPerView = $aBp['per_view'];
  731. $iStart = $aBp['start'] - $iPerView;
  732. if($iStart < 0) {
  733. $iPerView += $iStart;
  734. $iStart = 0;
  735. }
  736. if($iStart == 0 && $iPerView == 0)
  737. return $sCmts;
  738. break;
  739. }
  740. $bRoot = (int)$aBp['vparent_id'] <= 0;
  741. $sMore = $this->_oTemplate->parseHtmlByName('comment_more.html', array(
  742. 'js_object' => $this->_sJsObjName,
  743. 'style_prefix' => $this->_sStylePrefix,
  744. 'bx_if:is_root' => array(
  745. 'condition' => $bRoot,
  746. 'content' => array()
  747. ),
  748. 'parent_id' => $aBp['vparent_id'],
  749. 'start' => $iStart,
  750. 'per_view' => $iPerView,
  751. 'title' => _t('_cmt_load_more_' . ($aBp['vparent_id'] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
  752. ));
  753. switch($aBp['type']) {
  754. case BX_CMT_BROWSE_HEAD:
  755. case BX_CMT_BROWSE_POPULAR:
  756. case BX_CMT_BROWSE_CONNECTION:
  757. $sCmts .= $sMore;
  758. break;
  759. case BX_CMT_BROWSE_TAIL:
  760. $sCmts = $sMore . $sCmts;
  761. break;
  762. }
  763. return $sCmts;
  764. }
  765. protected function _getEmpty()
  766. {
  767. return $this->_oTemplate->parseHtmlByName('comment_empty.html', array(
  768. 'style_prefix' => $this->_sStylePrefix,
  769. 'content' => MsgBox(_t('_Empty'))
  770. ));
  771. }
  772. protected function _getViewImagePopup()
  773. {
  774. $sViewImagePopupId = 'cmts-box-' . $this->_sSystem . '-' . $this->getId() . '-view-image-popup' ;
  775. $sViewImagePopupContent = $this->_oTemplate->parseHtmlByName('popup_image.html', array(
  776. 'image_url' => ''
  777. ));
  778. return BxTemplFunctions::getInstance()->transBox($sViewImagePopupId, $sViewImagePopupContent, true);
  779. }
  780. protected function _getAttachments($aCmt)
  781. {
  782. $aTmplImages = array();
  783. if(!$this->isAttachImageEnabled())
  784. return '';
  785. $aFiles = $this->_oQuery->getFiles($this->_aSystem['system_id'], $aCmt['cmt_id']);
  786. if(!empty($aFiles) && is_array($aFiles)) {
  787. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  788. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->getTranscoderPreviewName());
  789. foreach($aFiles as $aFile) {
  790. $bImage = $oTranscoder && $oTranscoder->isMimeTypeSupported($aFile['mime_type']);
  791. $sPreview = '';
  792. if($oTranscoder && $bImage)
  793. $sPreview = $oTranscoder->getFileUrl($aFile['image_id']);
  794. if(!$sPreview)
  795. $sPreview = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFile['file_name']));
  796. $aTmplVarsFile = array(
  797. 'js_object' => $this->_sJsObjName,
  798. 'preview' => $sPreview,
  799. 'file' => $oStorage->getFileUrlById($aFile['image_id']),
  800. 'file_name' => $aFile['file_name'],
  801. 'file_icon' => $oStorage->getFontIconNameByFileName($aFile['file_name']),
  802. 'file_size' => _t_format_size($aFile['size']),
  803. );
  804. $aTmplImages[] = array(
  805. 'style_prefix' => $this->_sStylePrefix,
  806. 'bx_if:show_image' => array(
  807. 'condition' => $bImage,
  808. 'content' => $aTmplVarsFile
  809. ),
  810. 'bx_if:show_file' => array(
  811. 'condition' => !$bImage,
  812. 'content' => $aTmplVarsFile
  813. ),
  814. );
  815. }
  816. }
  817. return $this->_oTemplate->parseHtmlByName('comment_attachments.html', array(
  818. 'bx_repeat:attached' => $aTmplImages
  819. ));
  820. }
  821. protected function _getTmplVarsAuthor($aCmt)
  822. {
  823. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  824. $bAuthorIcon = !empty($sAuthorIcon);
  825. return array(
  826. 'author_unit' => $sAuthorUnit,
  827. 'bx_if:show_icon' => array(
  828. 'condition' => $bAuthorIcon,
  829. 'content' => array(
  830. 'author_icon' => $sAuthorIcon
  831. )
  832. ),
  833. 'bx_if:show_icon_empty' => array(
  834. 'condition' => !$bAuthorIcon,
  835. 'content' => array()
  836. ),
  837. 'bx_if:show_author_link' => array(
  838. 'condition' => !empty($sAuthorLink),
  839. 'content' => array(
  840. 'author_link' => $sAuthorLink,
  841. 'author_title' => bx_html_attribute($sAuthorName),
  842. 'author_name' => $sAuthorName
  843. )
  844. ),
  845. 'bx_if:show_author_text' => array(
  846. 'condition' => empty($sAuthorLink),
  847. 'content' => array(
  848. 'author_name' => $sAuthorName
  849. )
  850. ),
  851. );
  852. }
  853. protected function _getTmplVarsText($aCmt)
  854. {
  855. $sText = $aCmt['cmt_text'];
  856. $sTextMore = '';
  857. if(!$this->isHtml()) {
  858. $iMaxLength = (int)$this->_aSystem['chars_display_max'];
  859. if(strlen($sText) > $iMaxLength) {
  860. $iLength = strpos($sText, ' ', $iMaxLength);
  861. $sTextMore = trim(substr($sText, $iLength));
  862. $sText = trim(substr($sText, 0, $iLength));
  863. }
  864. }
  865. $sText = $this->_prepareTextForOutput($sText, $aCmt['cmt_id']);
  866. $sTextMore = $this->_prepareTextForOutput($sTextMore, $aCmt['cmt_id']);
  867. return array(
  868. 'text' => $sText,
  869. 'bx_if:show_more' => array(
  870. 'condition' => !empty($sTextMore),
  871. 'content' => array(
  872. 'style_prefix' => $this->_sStylePrefix,
  873. 'js_object' => $this->_sJsObjName,
  874. 'text_more' => $sTextMore
  875. )
  876. ),
  877. );
  878. }
  879. }
  880. /** @} */