BxBaseCmts.php 64 KB

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