BxBaseCmts.php 63 KB

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