BxBaseCmts.php 64 KB

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