BxBaseCmts.php 62 KB

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