1
0

BxBaseCmts.php 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519
  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(array_merge($aBp, ['pinned' => 1]), $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(0, true));
  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. BxDolTemplate::getInstance()->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. BxDolTemplate::getInstance()->addInjection ('injection_footer', 'text', $this->_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, $aBp, $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. $oProfileAuthor = BxDolProfile::getInstance($aCmt['cmt_author_id']);
  325. if ($oProfileAuthor->isActive() || isAdmin() || BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR))) {
  326. $sContent = $this->_getContent($aCmt);
  327. }
  328. else {
  329. $sClass .= ' cmt-author-not-active';
  330. $sContent = _t('_hidden_comment', BxDolProfileUndefined::getInstance()->getDisplayName());
  331. }
  332. $aVars = array_merge(array(
  333. 'system' => $this->_sSystem,
  334. 'style_prefix' => $this->_sStylePrefix,
  335. 'js_object' => $this->_sJsObjName,
  336. 'id' => $aCmt['cmt_id'],
  337. 'anchor' => $this->getItemAnchor($aCmt['cmt_id']),
  338. 'class' => $sClass,
  339. 'class_cnt' => $sClassCnt,
  340. 'bx_if:show_reply_to' => array(
  341. 'condition' => !empty($aTmplReplyTo),
  342. 'content' => $aTmplReplyTo
  343. ),
  344. 'bx_if:meta' => array(
  345. 'condition' => !empty($aTmplVarsMeta),
  346. 'content' => $aTmplVarsMeta
  347. ),
  348. 'bx_if:show_pinned' => array(
  349. 'condition' => (int)$aCmt['cmt_pinned'] > 0,
  350. 'content' => array(
  351. 'style_prefix' => $this->_sStylePrefix,
  352. )
  353. ),
  354. 'content' => $sContent,
  355. 'actions' => $sActions,
  356. 'replies' => $sReplies,
  357. ), $this->_getTmplVarsAuthor($aCmt), $this->_getTmplVarsNotes($aCmt));
  358. $sResult = $this->_oTemplate->parseHtmlByName($this->_sTmplNameItem, $aVars);
  359. bx_alert('system', 'view_comment', $aCmt['cmt_id'], 0, array('comment' => $aCmt, 'system' => $this->_sSystem, 'tmpl_name' => $this->_sTmplNameItem, 'tmpl_vars' => $aVars, 'override_result' => &$sResult));
  360. return $sResult;
  361. }
  362. public function getCommentStructure($iCmtId, $aBp = array(), $aDp = array())
  363. {
  364. $aRoot = $this->getCommentRow((int)$iCmtId);
  365. $aBps = $aBp;
  366. if(!empty($aRoot))
  367. $aBps['parent_id'] = $aRoot['cmt_id'];
  368. $this->_prepareStructureBp($aDp['type'], $aBps);
  369. $iLevel = 0;
  370. $aStructure = array();
  371. $this->_getStructure($aRoot, $aBps, $iLevel, $aStructure);
  372. return !empty($aStructure) && is_array($aStructure) ? $aStructure : false;
  373. }
  374. function getCommentSearch($iCmtId, &$sAddon)
  375. {
  376. $aBp = array();
  377. $aDp = array(
  378. 'type' => BX_CMT_DISPLAY_FLAT,
  379. 'view_only' => true
  380. );
  381. if(empty($sAddon))
  382. $sAddon = $this->getJsScript($aBp, $aDp);
  383. BxDolTemplate::getInstance()->addInjection ('injection_footer', 'text', $this->_oTemplate->parseHtmlByName('comments_photoswipe.html', []));
  384. return $this->_oTemplate->parseHtmlByName('comment_search.html', array(
  385. 'comment' => $this->getComment($iCmtId, $aBp, $aDp),
  386. ));
  387. }
  388. /**
  389. * get one comment for "Live Search"
  390. *
  391. * @param int $iCmtId - comment id
  392. * @return string
  393. */
  394. function getCommentLiveSearch($mixedCmt, $aParams = array())
  395. {
  396. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  397. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  398. $bAuthorIcon = !empty($sAuthorIcon);
  399. $sViewLink = $this->getViewUrl($aCmt['cmt_id']);
  400. if(empty($sViewLink))
  401. $sViewLink = '#';
  402. return $this->_oTemplate->parseHtmlByName('comment_live_search.html', array(
  403. 'bx_if:show_icon' => array(
  404. 'condition' => $bAuthorIcon,
  405. 'content' => array(
  406. 'author_icon' => $sAuthorIcon,
  407. 'view_link' => $sViewLink
  408. )
  409. ),
  410. 'bx_if:show_icon_empty' => array(
  411. 'condition' => !$bAuthorIcon,
  412. 'content' => array()
  413. ),
  414. 'view_link' => $sViewLink,
  415. 'text' => BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($aCmt['cmt_text']), $this->_sSnippetLenthLiveSearch),
  416. 'sample' => isset($aParams['txt_sample_single']) ? _t($aParams['txt_sample_single']) : ''
  417. ));
  418. }
  419. function getFormBoxPost($aBp = array(), $aDp = array())
  420. {
  421. return $this->_getFormBox(BX_CMT_ACTION_POST, $aBp, $aDp);
  422. }
  423. function getFormBoxEdit($aBp = array(), $aDp = array())
  424. {
  425. return $this->_getFormBox(BX_CMT_ACTION_EDIT, $aBp, $aDp);
  426. }
  427. function getFormPost($iCmtParentId = 0, $aDp = array())
  428. {
  429. return $this->_getFormPost($iCmtParentId, $aDp);
  430. }
  431. function getFormEdit($iCmtId, $aDp = array())
  432. {
  433. return $this->_getFormEdit($iCmtId, $aDp);
  434. }
  435. function getControlsBox()
  436. {
  437. return $this->_getControlsBox();
  438. }
  439. function getLiveUpdate($iCountOld = 0, $iCountNew = 0)
  440. {
  441. $iCount = (int)$iCountNew - (int)$iCountOld;
  442. if($iCount < 0)
  443. return '';
  444. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  445. if(empty($aComments) || !is_array($aComments))
  446. return '';
  447. $aComment = array_shift($aComments);
  448. if(empty($aComment) || !is_array($aComment))
  449. return '';
  450. $sJsObject = $this->getJsObjectName();
  451. return $this->_oTemplate->parseHtmlByName('comments_lu_button.html', array(
  452. 'style_prefix' => $this->_sStylePrefix,
  453. 'html_id' => $this->getNotificationId(),
  454. 'onclick_show' => "javascript:" . $sJsObject . ".goToBtn(this, '" . $this->getItemAnchor($aComment['cmt_id']) . "', '" . $aComment['cmt_id'] . "');",
  455. ));
  456. }
  457. function getLiveUpdates($iCountOld = 0, $iCountNew = 0)
  458. {
  459. $bShowAll = true;
  460. $bShowActions = false;
  461. $iCount = (int)$iCountNew - (int)$iCountOld;
  462. if($iCount < 0)
  463. return '';
  464. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  465. if(empty($aComments) || !is_array($aComments))
  466. return '';
  467. $sJsObject = $this->getJsObjectName();
  468. $iUserId = $this->_getAuthorId();
  469. $bModerator = $this->isModerator();
  470. $aComments = array_reverse($aComments);
  471. $iComments = count($aComments);
  472. $aTmplVarsNotifs = array();
  473. foreach($aComments as $iIndex => $aComment) {
  474. $iCommentId = $aComment['cmt_id'];
  475. $sShowOnClick = "javascript:" . $sJsObject . ".goTo(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  476. $sReplyOnClick = "javascript:" . $sJsObject . ".goToAndReply(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  477. $iAuthorId = (int)$aComment['cmt_author_id'];
  478. if($iAuthorId < 0) {
  479. if(abs($iAuthorId) == $iUserId)
  480. continue;
  481. else if($bModerator)
  482. $iAuthorId *= -1;
  483. }
  484. $oAuthor = $this->_getAuthorObject($iAuthorId);
  485. $sAuthorName = $oAuthor->getDisplayName();
  486. $aTmplVarsNotifs[] = array(
  487. 'bx_if:show_as_hidden' => array(
  488. 'condition' => !$bShowAll && $iIndex < ($iComments - 1),
  489. 'content' => array(),
  490. ),
  491. 'item' => $this->_oTemplate->parseHtmlByName('comments_lu_notifications.html', array(
  492. 'style_prefix' => $this->_sStylePrefix,
  493. 'onclick_show' => $sShowOnClick,
  494. 'onclick_reply' => $sReplyOnClick,
  495. 'author_link' => $oAuthor->getUrl(),
  496. 'author_title' => bx_html_attribute($sAuthorName),
  497. 'author_name' => $sAuthorName,
  498. 'author_unit' => $oAuthor->getUnit(0, array('template' => 'unit_wo_info_links')),
  499. 'text' => _t('_cmt_txt_added_sample')
  500. )),
  501. 'bx_if:show_previous' => array(
  502. 'condition' => $bShowActions && $iIndex > 0,
  503. 'content' => array(
  504. 'onclick_previous' => $sJsObject . '.previousLiveUpdate(this)'
  505. )
  506. ),
  507. 'bx_if:show_close' => array(
  508. 'condition' => $bShowActions,
  509. 'content' => array(
  510. 'onclick_close' => $sJsObject . '.hideLiveUpdate(this)'
  511. )
  512. )
  513. );
  514. }
  515. return $this->_oTemplate->parseHtmlByName('popup_chain.html', array(
  516. 'html_id' => $this->getNotificationId(),
  517. 'bx_repeat:items' => $aTmplVarsNotifs
  518. ));
  519. }
  520. public function getElementBlock($aParams = array())
  521. {
  522. $aParams['usage'] = BX_CMT_USAGE_BLOCK;
  523. return $this->getElement($aParams);
  524. }
  525. public function getElementInline($aParams = array())
  526. {
  527. $aParams['usage'] = BX_CMT_USAGE_INLINE;
  528. return $this->getElement($aParams);
  529. }
  530. public function getElement($aParams = array())
  531. {
  532. $aParams = array_merge($this->_aElementDefaults, $aParams);
  533. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  534. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  535. $bShowCounterEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  536. $iObjectId = $this->getId();
  537. $iAuthorId = $this->_getAuthorId();
  538. $iAuthorIp = $this->_getAuthorIp();
  539. $iCount = $this->getCommentsCountAll();
  540. $bCount = (int)$iCount != 0;
  541. $isAllowedComment = $this->isPostAllowed();
  542. //--- Do Comment
  543. $bTmplVarsDoComment = $this->_isShowDoComment($aParams, $isAllowedComment, $bCount);
  544. $aTmplVarsDoComment = array();
  545. if($bTmplVarsDoComment) {
  546. $sClass = '';
  547. if($bShowDoCommentAsButton)
  548. $sClass = 'bx-btn';
  549. else if ($bShowDoCommentAsButtonSmall)
  550. $sClass = 'bx-btn bx-btn-small';
  551. if(!$isAllowedComment)
  552. $sClass .= $bShowDoCommentAsButton || $bShowDoCommentAsButtonSmall ? ' bx-btn-disabled' : 'bx-cmts-disabled';
  553. $aTmplVarsDoComment = array(
  554. 'style_prefix' => $this->_sStylePrefix,
  555. 'do_comment' => $this->_oTemplate->parseLink($this->getListUrl(), $this->_getLabelDo($aParams), array(
  556. 'class' => $this->_sStylePrefix . '-do-comment ' . $this->_sStylePrefix . '-dc ' . $sClass,
  557. 'title' => _t($this->_getTitleDo())
  558. )),
  559. );
  560. }
  561. //--- Counter
  562. $bTmplVarsCounter = $this->_isShowCounter($aParams, $isAllowedComment, $bCount);
  563. $aTmplVarsCounter = array();
  564. if($bTmplVarsCounter)
  565. $aTmplVarsCounter = array(
  566. 'style_prefix' => $this->_sStylePrefix,
  567. 'bx_if:show_hidden' => array(
  568. 'condition' => !$bShowCounterEmpty && !$bCount,
  569. 'content' => array()
  570. ),
  571. 'counter' => $this->getCounter($aParams)
  572. );
  573. if(!$bTmplVarsDoComment && !$bTmplVarsCounter)
  574. return '';
  575. $sTmplName = $this->{'_getTmplElement' . bx_gen_method_name(!empty($aParams['usage']) ? $aParams['usage'] : BX_CMT_USAGE_DEFAULT)}();
  576. return $this->_oTemplate->parseHtmlByContent($sTmplName, array(
  577. 'style_prefix' => $this->_sStylePrefix,
  578. 'html_id' => $this->_aHtmlIds['main'],
  579. 'class' => $this->_sStylePrefix . ($bShowDoCommentAsButton ? '-button' : '') . ($bShowDoCommentAsButtonSmall ? '-button-small' : ''),
  580. 'count' => $iCount,
  581. 'bx_if:show_do_comment' => array(
  582. 'condition' => $bTmplVarsDoComment,
  583. 'content' => $aTmplVarsDoComment
  584. ),
  585. 'bx_if:show_counter' => array(
  586. 'condition' => $bTmplVarsCounter,
  587. 'content' => $aTmplVarsCounter
  588. ),
  589. 'script' => ''
  590. ));
  591. }
  592. protected function _getCounterItems($iCmtsLimit, $iCmtsStart = 0)
  593. {
  594. return $this->_oQuery->getCommentsBy(array('type' => 'object_id', 'object_id' => $this->getId(), 'order_way' => 'desc', 'start' => $iCmtsStart, 'per_page' => $iCmtsLimit * 4));
  595. }
  596. public function getCounter($aParams = array())
  597. {
  598. $bShowEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  599. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  600. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  601. $iCount = (int)$this->getCommentsCountAll();
  602. if($iCount == 0 && !$bShowEmpty)
  603. return '';
  604. $sClass = $this->_sStylePrefix . '-counter';
  605. if($bShowDoCommentAsButtonSmall)
  606. $sClass .= ' bx-btn-small-height';
  607. if($bShowDoCommentAsButton)
  608. $sClass .= ' bx-btn-height';
  609. $iCmtsLimit = 5;
  610. $aCmts = $this->_getCounterItems($iCmtsLimit);
  611. $aCmts = array_reverse($aCmts);
  612. $aTmplVarsProfiles = array();
  613. foreach($aCmts as $aCmt) {
  614. $iAuthor = (int)$aCmt['cmt_author_id'];
  615. if(array_key_exists($iAuthor, $aTmplVarsProfiles))
  616. continue;
  617. $oAuthor = BxDolProfile::getInstanceMagic($iAuthor);
  618. if(!$oAuthor)
  619. continue;
  620. $aTmplVarsProfiles[$iAuthor] = array(
  621. 'icon' => $oAuthor->getUnit(0, array('template' => array('name' => 'unit_wo_info_links', 'size' => 'icon')))
  622. );
  623. if(count($aTmplVarsProfiles) >= $iCmtsLimit)
  624. break;
  625. }
  626. $aTmplVarsProfiles = array_values($aTmplVarsProfiles);
  627. $sHref = !empty($aParams['overwrite_counter_link_href']) ? $aParams['overwrite_counter_link_href'] : $this->getListUrl();
  628. $sOnclick = '';
  629. if(!empty($aParams['overwrite_counter_link_onclick']))
  630. $sOnclick = $aParams['overwrite_counter_link_onclick'];
  631. return $this->_oTemplate->parseHtmlByContent($this->_getTmplCounter(), array(
  632. 'id' => $this->_aHtmlIds['counter'],
  633. 'class' => $sClass,
  634. 'href' => $sHref,
  635. 'bx_if:show_onclick' => array(
  636. 'condition' => !empty($sOnclick),
  637. 'content' => array(
  638. 'onclick' => $sOnclick
  639. )
  640. ),
  641. 'content' => $this->_getCounterLabel($iCount, $aParams),
  642. 'bx_repeat:profiles' => $aTmplVarsProfiles,
  643. 'bx_if:show_icon' => array(
  644. 'condition' => ($bShowEmpty || !empty($aTmplVarsProfiles)) && (!isset($aParams['show_icon']) || $aParams['show_icon']),
  645. 'content' => array(
  646. 'style_prefix' => $this->_sStylePrefix,
  647. 'icon' => !empty($aParams['custom_icon']) ? $aParams['custom_icon'] : BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getFontIconAsHtml('comment', $this->_sStylePrefix . '-counter-icon sys-icon')
  648. )
  649. )
  650. ));
  651. }
  652. protected function _getLabelDo($aParams = array())
  653. {
  654. return $this->_oTemplate->parseHtmlByContent($this->_getTmplLabelDo(), array(
  655. 'style_prefix' => $this->_sStylePrefix,
  656. 'bx_if:show_image' => array(
  657. 'condition' => isset($aParams['show_do_comment_image']) && $aParams['show_do_comment_image'] == true,
  658. 'content' => array(
  659. 'style_prefix' => $this->_sStylePrefix,
  660. 'src' => $this->_getImageDo()
  661. )
  662. ),
  663. 'bx_if:show_icon' => array(
  664. 'condition' => isset($aParams['show_do_comment_icon']) && $aParams['show_do_comment_icon'] == true,
  665. 'content' => array(
  666. 'style_prefix' => $this->_sStylePrefix,
  667. 'name' => $this->_getIconDo()
  668. )
  669. ),
  670. 'bx_if:show_text' => array(
  671. 'condition' => isset($aParams['show_do_comment_label']) && $aParams['show_do_comment_label'] == true,
  672. 'content' => array(
  673. 'style_prefix' => $this->_sStylePrefix,
  674. 'text' => _t($this->_getTitleDo())
  675. )
  676. )
  677. ));
  678. }
  679. protected function _getCounterLabel($iCount, $aParams = array())
  680. {
  681. 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').'';
  682. }
  683. protected function _getTmplElementBlock()
  684. {
  685. return self::$_sTmplContentElementBlock;
  686. }
  687. protected function _getTmplElementInline()
  688. {
  689. return self::$_sTmplContentElementInline;
  690. }
  691. protected function _getTmplLabelDo()
  692. {
  693. return self::$_sTmplContentDoCommentLabel;
  694. }
  695. protected function _getTmplCounter()
  696. {
  697. return self::$_sTmplContentCounter;
  698. }
  699. /**
  700. * private functions
  701. */
  702. protected function _getContentBefore($aBp = array(), $aDp = array())
  703. {
  704. return '';
  705. }
  706. protected function _getContentAfter($aBp = array(), $aDp = array())
  707. {
  708. return '';
  709. }
  710. protected function _getControlsBox()
  711. {
  712. $sDisplay = '';
  713. $bDisplay = (int)$this->_aSystem['is_display_switch'] == 1;
  714. if($bDisplay) {
  715. $aDisplayLinks = array(
  716. array('id' => $this->_sSystem . '-flat', 'name' => $this->_sSystem . '-flat', 'class' => '', 'title' => '_cmt_display_flat', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'flat\');'),
  717. array('id' => $this->_sSystem . '-threaded', 'name' => $this->_sSystem . '-threaded', 'class' => '', 'title' => '_cmt_display_threaded', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'threaded\');')
  718. );
  719. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-display', 'menu_items' => $aDisplayLinks));
  720. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sDisplayType);
  721. $sDisplay = $oMenu->getCode();
  722. }
  723. $sBrowseType = '';
  724. $bBrowseType = (int)$this->_aSystem['is_browse_switch'] == 1;
  725. if($bBrowseType) {
  726. $aBrowseLinks = array(
  727. array('id' => $this->_sSystem . '-tail', 'name' => $this->_sSystem . '-tail', 'class' => '', 'title' => '_cmt_browse_tail', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'tail\');'),
  728. array('id' => $this->_sSystem . '-head', 'name' => $this->_sSystem . '-head', 'class' => '', 'title' => '_cmt_browse_head', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'head\');'),
  729. array('id' => $this->_sSystem . '-popular', 'name' => $this->_sSystem . '-popular', 'class' => '', 'title' => '_cmt_browse_popular', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'popular\');'),
  730. );
  731. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-browse', 'menu_items' => $aBrowseLinks));
  732. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseType);
  733. $sBrowseType = $oMenu->getCode();
  734. }
  735. $sBrowseFilter = '';
  736. $bBrowseFilter = (int)$this->_aSystem['is_browse_filter'] == 1;
  737. if($bBrowseFilter) {
  738. $aFilterLinks = array(
  739. array('id' => $this->_sSystem . '-all', 'name' => $this->_sSystem . '-all', 'class' => '', 'title' => '_cmt_browse_all', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'all\');'),
  740. array('id' => $this->_sSystem . '-friends', 'name' => $this->_sSystem . '-friends', 'class' => '', 'title' => '_cmt_browse_friends', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'friends\');'),
  741. array('id' => $this->_sSystem . '-subscriptions', 'name' => $this->_sSystem . '-subscriptions', 'class' => '', 'title' => '_cmt_browse_subscriptions', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'subscriptions\');')
  742. );
  743. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-filter', 'menu_items' => $aFilterLinks));
  744. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseFilter);
  745. $sBrowseFilter = $oMenu->getCode();
  746. }
  747. return $this->_oTemplate->parseHtmlByName('comments_controls.html', array(
  748. 'display_switcher' => $bDisplay ? $sDisplay : '',
  749. 'bx_if:is_divider_1' => array(
  750. 'condition' => $bDisplay && $bBrowseType,
  751. 'content' => array(
  752. 'style_prefix' => $this->_sStylePrefix,
  753. )
  754. ),
  755. 'browse_switcher' => $bBrowseType ? $sBrowseType : '',
  756. 'bx_if:is_divider_2' => array(
  757. 'condition' => $bBrowseType && $bBrowseFilter,
  758. 'content' => array(
  759. 'style_prefix' => $this->_sStylePrefix,
  760. )
  761. ),
  762. 'filter_switcher' => $bBrowseFilter ? $sBrowseFilter : '',
  763. ));
  764. }
  765. protected function _getActionsBox(&$aCmt, $aBp = [], $aDp = [])
  766. {
  767. $bViewOnly = isset($aDp['view_only']) && $aDp['view_only'] === true;
  768. $bDynamicMode = isset($aDp['dynamic_mode']) && $aDp['dynamic_mode'] === true;
  769. $sMenuActions = '';
  770. if(!$bViewOnly) {
  771. $oMenuActions = BxDolMenu::getObjectInstance($this->_sMenuObjActions);
  772. $oMenuActions->setCmtsData($this, $aCmt['cmt_id'], $aBp, $aDp);
  773. $oMenuActions->setDynamicMode($bDynamicMode);
  774. $sMenuActions = $oMenuActions->getCode();
  775. }
  776. return $this->_oTemplate->parseHtmlByName('comment_actions.html', array(
  777. 'id' => $aCmt['cmt_id'],
  778. 'js_object' => $this->_sJsObjName,
  779. 'style_prefix' => $this->_sStylePrefix,
  780. 'menu_actions' => $sMenuActions,
  781. ));
  782. }
  783. protected function _getFormBox($sType, $aBp, $aDp)
  784. {
  785. $iCmtParentId = isset($aBp['parent_id']) ? (int)$aBp['parent_id'] : 0;
  786. $sPosition = isset($aDp['position']) ? $aDp['position'] : '';
  787. $bQuote = isset($aDp['quote']) && (bool)$aDp['quote'];
  788. $bFormMin = $iCmtParentId == 0 && isset($aDp['min_post_form']) && (bool)$aDp['min_post_form'];
  789. $sPositionSystem = $this->_aSystem['post_form_position'];
  790. if(!empty($sPosition) && $sPositionSystem != $sPosition)
  791. return '';
  792. $sClass = '';
  793. if(!empty($sPosition))
  794. $sClass .= ' ' . $this->_sStylePrefix . '-reply-' . $sPosition;
  795. if($bQuote)
  796. $sClass .= ' ' . $this->_sStylePrefix . '-reply-quote';
  797. if($bFormMin)
  798. $sClass .= ' ' . $this->_sStylePrefix . '-reply-min';
  799. if(!empty($aDp['class']))
  800. $sClass .= ' ' . $aDp['class'];
  801. $sClassBody = '';
  802. if(!empty($aDp['class_body']))
  803. $sClassBody .= ' ' . $aDp['class_body'];
  804. $aTmplVarsFormMin = array();
  805. if($bFormMin) {
  806. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($this->_getAuthorId());
  807. $oForm = new BxTemplFormView(array());
  808. $aInputPlaceholder = array(
  809. 'type' => 'text',
  810. 'name' => 'comment',
  811. 'caption' => '',
  812. 'attrs' => array(
  813. 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtShowForm(this)',
  814. 'placeholder' => _t($this->_aT['txt_min_form_placeholder'], $sAuthorName),
  815. 'autocomplete' => 'off',
  816. 'readonly' => 'readonly'
  817. ),
  818. 'value' => '',
  819. );
  820. $sClassBodyMin = '';
  821. if(!empty($aDp['class_body_min']))
  822. $sClassBodyMin .= ' ' . $aDp['class_body_min'];
  823. $aTmplVarsFormMin = array(
  824. 'js_object' => $this->_sJsObjName,
  825. 'class_body_min' => $sClassBodyMin,
  826. 'style_prefix' => $this->_sStylePrefix,
  827. 'author_unit' => $sAuthorUnit,
  828. 'placeholder' => $oForm->genRow($aInputPlaceholder)
  829. );
  830. }
  831. $aForm = $this->{'_getForm' . ucfirst($sType)}($iCmtParentId, $aDp);
  832. if(empty($aForm['form']))
  833. return !empty($aForm['msg']) && (isLogged() || $iCmtParentId != 0 || $this->getCommentsCount() > 0) ? MsgBox($aForm['msg']) : '';
  834. return $this->_oTemplate->parseHtmlByName('comment_reply_box.html', array(
  835. 'js_object' => $this->_sJsObjName,
  836. 'style_prefix' => $this->_sStylePrefix,
  837. 'class' => $sClass,
  838. 'class_body' => $sClassBody,
  839. 'bx_if:show_form_min' => array(
  840. 'condition' => $bFormMin,
  841. 'content' => $aTmplVarsFormMin
  842. ),
  843. 'form' => $aForm['form'],
  844. 'form_id' => $aForm['form_id'],
  845. ));
  846. }
  847. protected function _getFormAdd($aValues)
  848. {
  849. $iCmtAuthorId = isset($aValues['cmt_author_id']) ? (int)$aValues['cmt_author_id'] : $this->_getAuthorId();
  850. $iCmtParentId = isset($aValues['cmt_parent_id']) ? (int)$aValues['cmt_parent_id'] : 0;
  851. $oForm = $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId);
  852. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  853. $oForm->aParams['csrf']['disable'] = true;
  854. $oForm->aInputs['cmt_parent_id']['value'] = $iCmtParentId;
  855. if(!empty($oForm->aParams['db']['submit_name'])) {
  856. $sSubmitName = false;
  857. if(is_array($oForm->aParams['db']['submit_name']))
  858. foreach($oForm->aParams['db']['submit_name'] as $sVal) {
  859. if(isset($oForm->aInputs[$sVal])) {
  860. $sSubmitName = $sVal;
  861. break;
  862. }
  863. }
  864. else
  865. $sSubmitName = $oForm->aParams['db']['submit_name'];
  866. if($sSubmitName && isset($oForm->aInputs[$sSubmitName]))
  867. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  868. }
  869. $oForm->initChecker(array(), $aValues);
  870. if(!$oForm->isSubmittedAndValid())
  871. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  872. $iLevel = 0;
  873. $iCmtVisualParentId = 0;
  874. if((int)$iCmtParentId > 0) {
  875. $aParent = $this->getCommentRow($iCmtParentId);
  876. $iLevel = (int)$aParent['cmt_level'] + 1;
  877. $iCmtVisualParentId = $iLevel > $this->getMaxLevel() ? $aParent['cmt_vparent_id'] : $iCmtParentId;
  878. }
  879. $iCmtId = (int)$oForm->insert(array('cmt_vparent_id' => $iCmtVisualParentId, 'cmt_object_id' => $this->_iId, 'cmt_author_id' => $iCmtAuthorId, 'cmt_level' => $iLevel, 'cmt_time' => time()));
  880. if(!$iCmtId) {
  881. if(!$oForm->isValid())
  882. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  883. else
  884. return array('code' => 2, 'message' => '_cmt_err_cannot_perform_action');
  885. }
  886. $iCmtUniqId = $this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId, [
  887. 'author_id' => $iCmtAuthorId,
  888. 'status_admin' => $this->getStatusAdmin()
  889. ]);
  890. if($iCmtParentId) {
  891. $this->_oQuery->updateRepliesCount($iCmtParentId, 1);
  892. if(!BxDolModuleQuery::getInstance()->isEnabledByName('bx_notifications'))
  893. $this->_sendNotificationEmail($iCmtId, $iCmtParentId);
  894. }
  895. $this->_triggerComment();
  896. if($this->_sMetatagsObj && ($oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj)) !== false)
  897. $oMetatags->metaAdd($iCmtUniqId, $aValues['cmt_text']);
  898. $mixedResult = $this->onPostAfter($iCmtId);
  899. if($mixedResult === false)
  900. return array('code' => 2, 'message' => '_cmt_err_cannot_perform_action');
  901. return $mixedResult;
  902. }
  903. protected function _getFormPost($iCmtParentId = 0, $aDp = array())
  904. {
  905. $bCmtParentId = !empty($iCmtParentId);
  906. if(!$bCmtParentId && !$this->isPostAllowed())
  907. return array('msg' => $this->msgErrPostAllowed());
  908. if($bCmtParentId && !$this->isReplyAllowed($iCmtParentId))
  909. return array('msg' => $this->msgErrReplyAllowed());
  910. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  911. $bQuote = isset($aDp['quote']) && (bool)$aDp['quote'];
  912. $oForm = $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId);
  913. $oForm->aInputs['cmt_parent_id']['value'] = $iCmtParentId;
  914. if($bQuote) {
  915. $aCmtParent = $this->getCommentRow((int)$iCmtParentId);
  916. if(!empty($aCmtParent['cmt_text']))
  917. $oForm->aInputs['cmt_text']['value'] = $this->_oTemplate->parseHtmlByName('comment_quote.html', array(
  918. 'content' => $aCmtParent['cmt_text']
  919. ));
  920. }
  921. $oForm->initChecker();
  922. if($oForm->isSubmittedAndValid()) {
  923. $iCmtAuthorId = $this->_getAuthorId();
  924. $iCmtParentId = (int)$oForm->getCleanValue('cmt_parent_id');
  925. //--- Process Text ---//
  926. $sCmtText = $oForm->getCleanValue('cmt_text');
  927. $bCmtText = !empty($sCmtText);
  928. //--- Process Media ---//
  929. $aImageIds = $oForm->getCleanValue('cmt_image');
  930. $bImageIds = !empty($aImageIds) && is_array($aImageIds);
  931. if(!$bCmtText && !$bImageIds) {
  932. $oForm->aInputs['cmt_text']['error'] = _t('_Please enter characters');
  933. $oForm->setValid(false);
  934. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  935. }
  936. $aParent = array();
  937. if($iCmtParentId > 0) {
  938. $aParent = $this->getCommentRow($iCmtParentId);
  939. if(empty($aParent) || !is_array($aParent)) {
  940. $iCmtParentId = 0;
  941. $oForm->setSubmittedValue('cmt_parent_id', $iCmtParentId, $oForm->aFormAttrs['method']);
  942. }
  943. }
  944. $iLevel = 0;
  945. $iCmtVisualParentId = 0;
  946. if($iCmtParentId > 0) {
  947. $iLevel = (int)$aParent['cmt_level'] + 1;
  948. $iCmtVisualParentId = $iLevel > $this->getMaxLevel() ? $aParent['cmt_vparent_id'] : $iCmtParentId;
  949. }
  950. $iCmtId = (int)$oForm->insert(array('cmt_vparent_id' => $iCmtVisualParentId, 'cmt_object_id' => $this->_iId, 'cmt_author_id' => $iCmtAuthorId, 'cmt_level' => $iLevel, 'cmt_time' => time()));
  951. if($iCmtId != 0) {
  952. $iCmtUniqId = $this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId, [
  953. 'author_id' => $iCmtAuthorId,
  954. 'status_admin' => $this->getStatusAdmin()
  955. ]);
  956. if($this->isAttachImageEnabled())
  957. $oForm->processImages($this, 'cmt_image', $iCmtUniqId, $iCmtId, $iCmtAuthorId, true);
  958. if($iCmtParentId > 0) {
  959. $this->_oQuery->updateRepliesCount($iCmtParentId, 1);
  960. if(!BxDolModuleQuery::getInstance()->isEnabledByName('bx_notifications'))
  961. $this->_sendNotificationEmail($iCmtId, $iCmtParentId);
  962. }
  963. $this->_triggerComment();
  964. if($iCmtParentId > 0)
  965. $this->isReplyAllowed($iCmtParentId, true);
  966. else
  967. $this->isPostAllowed(true);
  968. if($this->_sMetatagsObj && ($oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj)) !== false)
  969. $oMetatags->metaAdd($iCmtUniqId, $sCmtText);
  970. if(($mixedResult = $this->onPostAfter($iCmtId)) !== false)
  971. return $mixedResult;
  972. }
  973. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  974. }
  975. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  976. }
  977. protected function _getFormEdit($iCmtId, $aDp = array())
  978. {
  979. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  980. $aCmt = $this->getCommentSimple($iCmtId);
  981. if(!$aCmt)
  982. return array('msg' => _t('_No such comment'));
  983. $iCmtAuthorId = $this->_getAuthorId();
  984. if(!$this->isEditAllowed($aCmt))
  985. return array('msg' => $aCmt['cmt_author_id'] == $iCmtAuthorId ? strip_tags($this->msgErrEditAllowed()) : _t('_Access denied'));
  986. $oForm = $this->_getForm(BX_CMT_ACTION_EDIT, $aCmt['cmt_id']);
  987. $oForm->initChecker($aCmt);
  988. if($oForm->isSubmittedAndValid()) {
  989. $sCmtText = $oForm->getCleanValue('cmt_text');
  990. if($oForm->update($iCmtId) !== false) {
  991. $iCmtUniqId = $this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId, [
  992. 'author_id' => (int)$aCmt['cmt_author_id']
  993. ]);
  994. $sStatusAdmin = $this->getStatusAdmin();
  995. if($sStatusAdmin !== BX_CMT_STATUS_ACTIVE)
  996. $this->_oQuery->updateUniqId(['status_admin' => $sStatusAdmin], ['id' => $iCmtUniqId]);
  997. if($this->isAttachImageEnabled())
  998. $oForm->processImages($this, 'cmt_image', $iCmtUniqId, $iCmtId, $iCmtAuthorId, false);
  999. $this->isEditAllowed($aCmt, true);
  1000. if($this->_sMetatagsObj && ($oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj)) !== false)
  1001. $oMetatags->metaAdd($iCmtUniqId, $sCmtText);
  1002. if(($mixedResult = $this->onEditAfter($iCmtId)) !== false)
  1003. return $mixedResult;
  1004. }
  1005. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  1006. }
  1007. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  1008. }
  1009. protected function _getForm($sAction, $iId)
  1010. {
  1011. $oForm = $this->_getFormObject($sAction);
  1012. $oForm->setId(sprintf($oForm->getAttributeMask('id'), $sAction, $this->_sSystem, $this->_iId, $iId));
  1013. $oForm->setName(sprintf($oForm->getAttributeMask('name'), $sAction, $this->_sSystem, $this->_iId, $iId));
  1014. $oForm->aParams['db']['table'] = $this->_aSystem['table'];
  1015. $oForm->aInputs['sys']['value'] = $this->_sSystem;
  1016. $oForm->aInputs['id']['value'] = $this->_iId;
  1017. $oForm->aInputs['action']['value'] = 'Submit' . ucfirst($sAction) . 'Form';
  1018. if(!$this->isAttachImageEnabled())
  1019. unset($oForm->aInputs['cmt_image']);
  1020. if(isset($oForm->aInputs['cmt_text'])) {
  1021. $oForm->aInputs['cmt_text']['html'] = $this->_aSystem['html'];
  1022. $oForm->aInputs['cmt_text']['db']['pass'] = $this->isHtml() ? 'XssHtml' : 'XssMultiline';
  1023. if(isset($oForm->aInputs['cmt_text']['checker']['func']) && strtolower($oForm->aInputs['cmt_text']['checker']['func']) == 'length') {
  1024. $iCmtTextMin = (int)$this->_aSystem['chars_post_min'];
  1025. $iCmtTextMax = (int)$this->_aSystem['chars_post_max'];
  1026. $oForm->aInputs['cmt_text']['checker']['params'] = array($iCmtTextMin, $iCmtTextMax);
  1027. $oForm->aInputs['cmt_text']['checker']['error'] = _t('_Please enter n1-n2 characters', $iCmtTextMin, $iCmtTextMax);
  1028. }
  1029. }
  1030. if($sAction == BX_CMT_ACTION_EDIT && isset($oForm->aInputs['cmt_controls']))
  1031. foreach($oForm->aInputs['cmt_controls'] as $mixedKey => $mixedValue) {
  1032. if(!is_numeric($mixedKey) || empty($mixedValue['name']) || $mixedValue['name'] != 'cmt_cancel')
  1033. continue;
  1034. if(!isset($oForm->aInputs['cmt_controls'][$mixedKey]['attrs']))
  1035. $oForm->aInputs['cmt_controls'][$mixedKey]['attrs'] = array();
  1036. $oForm->aInputs['cmt_controls'][$mixedKey]['attrs']['onclick'] = $this->_sJsObjName . '.cmtEdit(this, ' . $iId . ', false)';
  1037. }
  1038. return $oForm;
  1039. }
  1040. protected function _getContent($aCmt)
  1041. {
  1042. $sAttachments = $this->_getAttachments($aCmt);
  1043. $sReactions = '';
  1044. if(($oReaction = $this->getReactionObject($aCmt['cmt_unique_id'])) !== false)
  1045. $sReactions = $oReaction->getCounter(array(
  1046. 'show_counter' => true
  1047. ));
  1048. return $this->_oTemplate->parseHtmlByName($this->_sTmplNameItemContent, array_merge(array(
  1049. 'style_prefix' => $this->_sStylePrefix,
  1050. 'js_object' => $this->_sJsObjName,
  1051. 'bx_if:show_attached' => array(
  1052. 'condition' => !empty($sAttachments),
  1053. 'content' => array(
  1054. 'style_prefix' => $this->_sStylePrefix,
  1055. 'attached' => $sAttachments
  1056. )
  1057. ),
  1058. 'reactions' => $sReactions,
  1059. ), $this->_getTmplVarsText($aCmt)));
  1060. }
  1061. protected function _getMoreLink($sCmts, $aBp = array(), $aDp = array())
  1062. {
  1063. $iStart = $iPerView = 0;
  1064. switch($aBp['type']) {
  1065. case BX_CMT_BROWSE_HEAD:
  1066. case BX_CMT_BROWSE_POPULAR:
  1067. case BX_CMT_BROWSE_CONNECTION:
  1068. $iPerView = $aBp['per_view'];
  1069. $iStart = $aBp['start'] + $iPerView;
  1070. if($iStart >= $aBp['count'])
  1071. return $sCmts;
  1072. break;
  1073. case BX_CMT_BROWSE_TAIL:
  1074. $iPerView = $aBp['per_view'];
  1075. $iStart = $aBp['start'] - $iPerView;
  1076. if($iStart < 0) {
  1077. $iPerView += $iStart;
  1078. $iStart = 0;
  1079. }
  1080. if($iStart == 0 && $iPerView == 0)
  1081. return $sCmts;
  1082. break;
  1083. }
  1084. $sParentKey = isset($aBp['vparent_id']) ? 'vparent_id' : 'parent_id';
  1085. $bRoot = (int)$aBp[$sParentKey] <= 0;
  1086. $sMore = $this->_oTemplate->parseHtmlByName('comment_more.html', array(
  1087. 'js_object' => $this->_sJsObjName,
  1088. 'style_prefix' => $this->_sStylePrefix,
  1089. 'bx_if:is_root' => array(
  1090. 'condition' => $bRoot,
  1091. 'content' => array()
  1092. ),
  1093. 'parent_id' => $aBp[$sParentKey],
  1094. 'start' => $iStart,
  1095. 'per_view' => $iPerView,
  1096. 'title' => _t('_cmt_load_more_' . ($aBp[$sParentKey] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
  1097. ));
  1098. switch($aBp['type']) {
  1099. case BX_CMT_BROWSE_HEAD:
  1100. case BX_CMT_BROWSE_POPULAR:
  1101. case BX_CMT_BROWSE_CONNECTION:
  1102. $sCmts .= $sMore;
  1103. break;
  1104. case BX_CMT_BROWSE_TAIL:
  1105. $sCmts = $sMore . $sCmts;
  1106. break;
  1107. }
  1108. return $sCmts;
  1109. }
  1110. protected function _getEmpty($aDp = array())
  1111. {
  1112. $sClass = '';
  1113. if(!empty($aDp['class']))
  1114. $sClass .= ' ' . $aDp['class'];
  1115. return $this->_oTemplate->parseHtmlByName('comment_empty.html', array(
  1116. 'style_prefix' => $this->_sStylePrefix,
  1117. 'class' => $sClass,
  1118. 'content' => MsgBox(_t('_Empty'))
  1119. ));
  1120. }
  1121. protected function _getAttachments($aCmt)
  1122. {
  1123. $aTmplImages = array();
  1124. if(!$this->isAttachImageEnabled())
  1125. return '';
  1126. $aFiles = $this->_oQuery->getFiles($this->_aSystem['system_id'], $aCmt['cmt_id']);
  1127. if(!empty($aFiles) && is_array($aFiles)) {
  1128. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  1129. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->getTranscoderPreviewName());
  1130. foreach($aFiles as $aFile) {
  1131. $sFile = $oStorage->getFileUrlById($aFile['image_id']);
  1132. $bImage = $oTranscoder && $oTranscoder->isMimeTypeSupported($aFile['mime_type']);
  1133. $sPreview = '';
  1134. $iWidth = $iHeight = 0;
  1135. if($bImage) {
  1136. if($oTranscoder)
  1137. $sPreview = $oTranscoder->getFileUrl($aFile['image_id']);
  1138. $aImageInfo = BxDolImageResize::getInstance()->getImageSize($sFile);
  1139. if(isset($aImageInfo['w']))
  1140. $iWidth = (int)$aImageInfo['w'];
  1141. if(isset($aImageInfo['h']))
  1142. $iHeight = (int)$aImageInfo['h'];
  1143. }
  1144. if(!$sPreview)
  1145. $sPreview = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFile['file_name']));
  1146. $aTmplVarsFile = array(
  1147. 'js_object' => $this->_sJsObjName,
  1148. 'preview' => $sPreview,
  1149. 'file' => $sFile,
  1150. 'file_id' => $aFile['id'],
  1151. 'file_name' => $aFile['file_name'],
  1152. 'file_icon' => $oStorage->getFontIconNameByFileName($aFile['file_name']),
  1153. 'file_size' => _t_format_size($aFile['size']),
  1154. 'w' => $iWidth,
  1155. 'h' => $iHeight
  1156. );
  1157. $aTmplImages[] = array(
  1158. 'style_prefix' => $this->_sStylePrefix,
  1159. 'bx_if:show_image' => array(
  1160. 'condition' => $bImage,
  1161. 'content' => $aTmplVarsFile
  1162. ),
  1163. 'bx_if:show_file' => array(
  1164. 'condition' => !$bImage,
  1165. 'content' => $aTmplVarsFile
  1166. ),
  1167. );
  1168. }
  1169. }
  1170. return $this->_oTemplate->parseHtmlByName('comment_attachments.html', array(
  1171. 'bx_repeat:attached' => $aTmplImages
  1172. ));
  1173. }
  1174. protected function _getTmplVarsNotes($aCmt)
  1175. {
  1176. $aTmplVars = array();
  1177. //--- Pending status related notes.
  1178. if($aCmt['cmt_status_admin'] == BX_CMT_STATUS_PENDING)
  1179. $aTmplVars[] = [
  1180. 'style_prefix' => $this->_sStylePrefix,
  1181. 'bx_if:show_note_color' => [
  1182. 'condition' => true,
  1183. 'content' => [
  1184. 'item_note_color' => 'red3'
  1185. ]
  1186. ],
  1187. 'item_note' => _t('_cmt_txt_note_approve_pending')
  1188. ];
  1189. return [
  1190. 'bx_if:show_notes' => [
  1191. 'condition' => !empty($aTmplVars),
  1192. 'content' => [
  1193. 'style_prefix' => $this->_sStylePrefix,
  1194. 'bx_repeat:notes' => $aTmplVars
  1195. ]
  1196. ],
  1197. ];
  1198. }
  1199. protected function _getTmplVarsAuthor($aCmt)
  1200. {
  1201. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  1202. $bAuthorIcon = !empty($sAuthorIcon);
  1203. return array(
  1204. 'author_unit' => $sAuthorUnit,
  1205. 'bx_if:show_icon' => array(
  1206. 'condition' => $bAuthorIcon,
  1207. 'content' => array(
  1208. 'author_icon' => $sAuthorIcon
  1209. )
  1210. ),
  1211. 'bx_if:show_icon_empty' => array(
  1212. 'condition' => !$bAuthorIcon,
  1213. 'content' => array()
  1214. ),
  1215. 'bx_if:show_author_link' => array(
  1216. 'condition' => !empty($sAuthorLink),
  1217. 'content' => array(
  1218. 'author_link' => $sAuthorLink,
  1219. 'author_title' => bx_html_attribute($sAuthorName),
  1220. 'author_name' => $sAuthorName
  1221. )
  1222. ),
  1223. 'bx_if:show_author_text' => array(
  1224. 'condition' => empty($sAuthorLink),
  1225. 'content' => array(
  1226. 'author_name' => $sAuthorName
  1227. )
  1228. ),
  1229. );
  1230. }
  1231. protected function _getTmplVarsText($aCmt)
  1232. {
  1233. $sText = $aCmt['cmt_text'];
  1234. $sTextMore = '';
  1235. if(!$this->isHtml()) {
  1236. $iMaxLength = (int)$this->_aSystem['chars_display_max'];
  1237. if(strlen($sText) > $iMaxLength) {
  1238. $iLength = strpos($sText, ' ', $iMaxLength);
  1239. $sTextMore = trim(substr($sText, $iLength));
  1240. $sText = trim(substr($sText, 0, $iLength));
  1241. }
  1242. }
  1243. $sText = $this->_prepareTextForOutput($sText, $aCmt['cmt_id']);
  1244. $sTextMore = $this->_prepareTextForOutput($sTextMore, $aCmt['cmt_id']);
  1245. return array(
  1246. 'text' => $sText,
  1247. 'bx_if:show_more' => array(
  1248. 'condition' => !empty($sTextMore),
  1249. 'content' => array(
  1250. 'style_prefix' => $this->_sStylePrefix,
  1251. 'js_object' => $this->_sJsObjName,
  1252. 'text_more' => $sTextMore
  1253. )
  1254. ),
  1255. );
  1256. }
  1257. }
  1258. /** @} */