BxBaseCmts.php 69 KB

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