BxBaseCmts.php 64 KB

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