BxBaseCmts.php 68 KB

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