BxBaseCmts.php 63 KB

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