BxBaseCmts.php 62 KB

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