BxBaseCmts.php 61 KB

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