BxBaseCmts.php 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  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. 'style_prefix' => $this->_sStylePrefix,
  202. 'js_object' => $this->_sJsObjName,
  203. 'system' => $this->_sSystem,
  204. 'list_anchor' => $this->getListAnchor(),
  205. 'id' => $this->getId(),
  206. 'content_before' => $sContentBefore,
  207. 'comments' => $sComments,
  208. 'comments_pinned' => $sCommentsPinned,
  209. 'bx_if:show_divider_hidden' => [
  210. 'condition' => empty($sCommentsPinned),
  211. 'content' => []
  212. ],
  213. 'content_after' => $sContentAfter,
  214. 'post_form_top' => $sPostFormTop,
  215. 'post_form_bottom' => $sPostFormBottom,
  216. 'image_preview' => $this->_oTemplate->parseHtmlByName('comments_photoswipe.html', []),
  217. 'script' => $sJsContent
  218. ]);
  219. return $aDp['in_designbox'] ? DesignBoxContent($sBlockTitle, $sContent, BX_DB_DEF, $sBlockMenu) : [
  220. 'title' => $sBlockTitle,
  221. 'content' => $sContent,
  222. 'menu' => $sBlockMenu,
  223. ];
  224. }
  225. /**
  226. * get comments list for specified parent comment
  227. *
  228. * @param array $aBp - browse params array
  229. * @param array $aDp - display params array
  230. *
  231. */
  232. function getComments($aBp = [], $aDp = [])
  233. {
  234. $this->_prepareParams($aBp, $aDp);
  235. $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp[($aBp['init_view'] != -1 ? 'init' : 'per') . '_view']);
  236. if(empty($aCmts) || !is_array($aCmts))
  237. return isset($aDp['show_empty']) && $aDp['show_empty'] === true ? $this->_getEmpty($aDp) : '';
  238. $sCmts = '';
  239. foreach($aCmts as $k => $aCmt)
  240. $sCmts .= $this->getComment($aCmt, $aBp, $aDp);
  241. $sCmts = $this->_getMoreLink($sCmts, $aBp, $aDp);
  242. return $sCmts;
  243. }
  244. function getCommentsPinned($aBp = [], $aDp = [])
  245. {
  246. $this->_prepareParams($aBp, $aDp);
  247. $aCmts = $this->getCommentsArray($aBp['vparent_id'], BX_CMT_FILTER_PINNED, $aBp['order'], 0, -1);
  248. if(empty($aCmts) || !is_array($aCmts))
  249. return '';
  250. $sCmts = '';
  251. foreach($aCmts as $k => $aCmt)
  252. $sCmts .= $this->getComment($aCmt, $aBp, $aDp);
  253. return $sCmts;
  254. }
  255. public function getCommentsByStructure($aBp = array(), $aDp = array())
  256. {
  257. if(empty($aDp['structure']))
  258. return isset($aDp['show_empty']) && $aDp['show_empty'] === true ? $this->_getEmpty($aDp) : '';
  259. $aBp['count'] = count($aDp['structure']);
  260. $this->_prepareParams($aBp, $aDp);
  261. $aDp['structure'] = array_slice($aDp['structure'], $aBp['start'], $aBp[($aBp['init_view'] != -1 ? 'init' : 'per') . '_view'], true);
  262. $sCmts = '';
  263. foreach($aDp['structure'] as $iCmtId => $aCmt)
  264. $sCmts .= $this->getComment($iCmtId, $aBp, $aDp);
  265. $sCmts = $this->_getMoreLink($sCmts, $aBp, $aDp);
  266. return $sCmts;
  267. }
  268. /**
  269. * get comment view block with initializations
  270. */
  271. function getCommentBlock($iCmtId = 0, $aBp = array(), $aDp = array())
  272. {
  273. $mixedResult = $this->isViewAllowed();
  274. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  275. return $mixedResult;
  276. $aBp = array_merge(array('type' => $this->_sBrowseType), $aBp);
  277. $aDp = array_merge(array('type' => BX_CMT_DISPLAY_THREADED), $aDp);
  278. //--- Beg: Using pregenerated structure
  279. $mixedStructure = $this->getCommentStructure((int)$iCmtId, $aBp, $aDp);
  280. if($mixedStructure !== false)
  281. $aDp['structure'] = $mixedStructure;
  282. //--- End: Using pregenerated structure
  283. $sComment = $this->getComment($iCmtId, $aBp, $aDp);
  284. if (!$sComment)
  285. return '';
  286. BxDolTemplate::getInstance()->addInjection ('injection_footer', 'text', $this->_oTemplate->parseHtmlByName('comments_photoswipe.html', []));
  287. return $this->_oTemplate->parseHtmlByName('comment_block.html', array(
  288. 'style_prefix' => $this->_sStylePrefix,
  289. 'js_object' => $this->_sJsObjName,
  290. 'system' => $this->_sSystem,
  291. 'id' => $this->getId(),
  292. 'comment' => $sComment,
  293. 'script' => $this->getJsScript($aBp, $aDp)
  294. ));
  295. }
  296. /**
  297. * get one just posted comment
  298. *
  299. * @param int $iCmtId - comment id
  300. * @return string
  301. */
  302. function getComment($mixedCmt, $aBp = array(), $aDp = array())
  303. {
  304. $iUserId = $this->_getAuthorId();
  305. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  306. if (!$aCmt)
  307. return '';
  308. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  309. $sClass = $sClassCnt = '';
  310. if(isset($aCmt['vote_rate']) && (float)$aCmt['vote_rate'] < $this->_aSystem['viewing_threshold']) {
  311. $this->_oTemplate->pareseHtmlByName('comment_hidden.html', array(
  312. 'js_object' => $this->_sJsObjName,
  313. 'id' => $aCmt['cmt_id'],
  314. 'title' => bx_process_output(_t('_hidden_comment', $sAuthorName)),
  315. 'bx_if:show_replies' => array(
  316. 'condition' => $aCmt['cmt_replies'] > 0,
  317. 'content' => array(
  318. 'replies' => _t('_Show N replies', $aCmt['cmt_replies'])
  319. )
  320. )
  321. ));
  322. $sClass = ' ' . $this->_sStylePrefix . '-hidden';
  323. }
  324. if($aCmt['cmt_author_id'] == $iUserId)
  325. $sClass .= ' ' . $this->_sStylePrefix . '-mine';
  326. $aAuthorAcl = BxDolAcl::getInstance()->getMemberMembershipInfo($aCmt['cmt_author_id']);
  327. if(!empty($aAuthorAcl) && isset($this->_aAclId2Name[$aAuthorAcl['id']]))
  328. $sClass .= ' ' . $this->_sStylePrefix . '-aml-' . $this->_aAclId2Name[$aAuthorAcl['id']];
  329. if(!empty($aDp['blink']) && in_array($aCmt['cmt_id'], $aDp['blink']))
  330. $sClass .= ' ' . $this->_sStylePrefix . '-blink';
  331. if(!empty($aDp['class_comment']))
  332. $sClass .= ' ' . $aDp['class_comment'];
  333. if(!empty($aDp['class_comment_content']))
  334. $sClassCnt .= ' ' . $aDp['class_comment_content'];
  335. $sActions = $this->_getActionsBox($aCmt, $aBp, $aDp);
  336. $aTmplReplyTo = array();
  337. if((int)$aCmt['cmt_parent_id'] != 0) {
  338. $aParent = $this->getCommentRow($aCmt['cmt_parent_id']);
  339. if(!empty($aParent) && is_array($aParent)) {
  340. $oProfile = $this->_getAuthorObject($aParent['cmt_author_id']);
  341. $sParAuthorName = $oProfile->getDisplayName();
  342. $sParAuthorUnit = $oProfile->getUnit(0, array('template' => array('name' => 'unit_wo_info_links', 'size' => 'icon')));
  343. $aTmplReplyTo = array(
  344. 'style_prefix' => $this->_sStylePrefix,
  345. 'par_cmt_link' => $this->getItemUrl($aCmt['cmt_parent_id']),
  346. 'par_cmt_title' => bx_html_attribute(_t('_in_reply_to_x', $sParAuthorName)),
  347. 'par_cmt_author' => $sParAuthorName,
  348. 'par_cmt_author_unit' => $sParAuthorUnit
  349. );
  350. }
  351. }
  352. $sReplies = '';
  353. if(!(isset($aBp['pinned']) && (int)$aBp['pinned'] != 0 && (int)$aCmt['cmt_pinned'] != 0) && !empty($aDp)) {
  354. $aDp['show_empty'] = false;
  355. if(!empty($aDp['structure'][$aCmt['cmt_id']]) && is_array($aDp['structure'][$aCmt['cmt_id']])) {
  356. if(!empty($aDp['structure'][$aCmt['cmt_id']]['items'])) {
  357. $aDp['structure'] = $aDp['structure'][$aCmt['cmt_id']]['items'];
  358. $sReplies = $this->getCommentsByStructure(array('parent_id' => $aCmt['cmt_id'], 'type' => $aBp['type']), $aDp);
  359. }
  360. }
  361. else if((int)$aCmt['cmt_replies'] > 0 && $aDp['type'] == BX_CMT_DISPLAY_THREADED)
  362. $sReplies = $this->getComments(['parent_id' => $aCmt['cmt_id'], 'vparent_id' => $aCmt['cmt_id'], 'type' => $aBp['type'], 'order_way' => BX_CMT_ORDER_WAY_ASC], $aDp);
  363. }
  364. $aTmplVarsMeta = array();
  365. if(!empty($this->_sMenuObjMeta)) {
  366. $oMenuMeta = BxDolMenu::getObjectInstance($this->_sMenuObjMeta, $this->_oTemplate);
  367. if($oMenuMeta) {
  368. $oMenuMeta->setCmtsData($this, $aCmt['cmt_id']);
  369. $aTmplVarsMeta = array(
  370. 'style_prefix' => $this->_sStylePrefix,
  371. 'meta' => $oMenuMeta->getCode()
  372. );
  373. }
  374. }
  375. if($this->_isShowContent($aCmt)) {
  376. $sContent = $this->_getContent($aCmt, $aBp, $aDp);
  377. }
  378. else {
  379. $sClass .= ' cmt-author-not-active';
  380. $sContent = _t('_hidden_comment', BxDolProfileUndefined::getInstance()->getDisplayName());
  381. }
  382. $aVars = array_merge(array(
  383. 'system' => $this->_sSystem,
  384. 'style_prefix' => $this->_sStylePrefix,
  385. 'js_object' => $this->_sJsObjName,
  386. 'id' => $aCmt['cmt_id'],
  387. 'anchor' => $this->getItemAnchor($aCmt['cmt_id']),
  388. 'class' => $sClass,
  389. 'class_cnt' => $sClassCnt,
  390. 'bx_if:show_reply_to' => array(
  391. 'condition' => !empty($aTmplReplyTo),
  392. 'content' => $aTmplReplyTo
  393. ),
  394. 'bx_if:meta' => array(
  395. 'condition' => !empty($aTmplVarsMeta),
  396. 'content' => $aTmplVarsMeta
  397. ),
  398. 'bx_if:show_pinned' => array(
  399. 'condition' => (int)$aCmt['cmt_pinned'] > 0,
  400. 'content' => array(
  401. 'style_prefix' => $this->_sStylePrefix,
  402. )
  403. ),
  404. 'content' => $sContent,
  405. 'actions' => $sActions,
  406. 'replies' => $sReplies,
  407. ), $this->_getTmplVarsAuthor($aCmt), $this->_getTmplVarsNotes($aCmt));
  408. $sResult = $this->_oTemplate->parseHtmlByName($this->_sTmplNameItem, $aVars);
  409. 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));
  410. return $sResult;
  411. }
  412. public function getCommentStructure($iCmtId, $aBp = array(), $aDp = array())
  413. {
  414. $aRoot = $this->getCommentRow((int)$iCmtId);
  415. $aBps = $aBp;
  416. if(!empty($aRoot))
  417. $aBps['parent_id'] = $aRoot['cmt_id'];
  418. $this->_prepareStructureBp($aDp['type'], $aBps);
  419. $iLevel = 0;
  420. $aStructure = array();
  421. $this->{'_getStructure' . ($this->_bIsApi ? 'API' : '')}($aRoot, $aBps, $iLevel, $aStructure);
  422. return !empty($aStructure) && is_array($aStructure) ? $aStructure : false;
  423. }
  424. function getCommentSearch($iCmtId, &$sAddon)
  425. {
  426. $aBp = array();
  427. $aDp = array(
  428. 'type' => BX_CMT_DISPLAY_FLAT,
  429. 'view_only' => true
  430. );
  431. if(empty($sAddon))
  432. $sAddon = $this->getJsScript($aBp, $aDp);
  433. BxDolTemplate::getInstance()->addInjection ('injection_footer', 'text', $this->_oTemplate->parseHtmlByName('comments_photoswipe.html', []));
  434. return $this->_oTemplate->parseHtmlByName('comment_search.html', array(
  435. 'comment' => $this->getComment($iCmtId, $aBp, $aDp),
  436. ));
  437. }
  438. /**
  439. * get one comment for "Live Search"
  440. *
  441. * @param int $iCmtId - comment id
  442. * @return string
  443. */
  444. function getCommentLiveSearch($mixedCmt, $aParams = array())
  445. {
  446. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  447. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  448. $bAuthorIcon = !empty($sAuthorIcon);
  449. $sViewLink = $this->getViewUrl($aCmt['cmt_id']);
  450. if(empty($sViewLink))
  451. $sViewLink = '#';
  452. return $this->_oTemplate->parseHtmlByName('comment_live_search.html', array(
  453. 'bx_if:show_icon' => array(
  454. 'condition' => $bAuthorIcon,
  455. 'content' => array(
  456. 'author_icon' => $sAuthorIcon,
  457. 'view_link' => $sViewLink
  458. )
  459. ),
  460. 'bx_if:show_icon_empty' => array(
  461. 'condition' => !$bAuthorIcon,
  462. 'content' => array()
  463. ),
  464. 'view_link' => $sViewLink,
  465. 'text' => BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($aCmt['cmt_text']), $this->_sSnippetLenthLiveSearch),
  466. 'sample' => isset($aParams['txt_sample_single']) ? _t($aParams['txt_sample_single']) : ''
  467. ));
  468. }
  469. function getFormBoxPost($aBp = array(), $aDp = array())
  470. {
  471. return $this->_getFormBox(BX_CMT_ACTION_POST, $aBp, $aDp);
  472. }
  473. function getFormBoxEdit($aBp = array(), $aDp = array())
  474. {
  475. return $this->_getFormBox(BX_CMT_ACTION_EDIT, $aBp, $aDp);
  476. }
  477. function getFormPost($iCmtParentId = 0, $aDp = array())
  478. {
  479. return $this->_getFormPost($iCmtParentId, $aDp);
  480. }
  481. function getFormEdit($iCmtId, $aDp = array())
  482. {
  483. return $this->_getFormEdit($iCmtId, $aDp);
  484. }
  485. function getControlsBox()
  486. {
  487. return $this->_getControlsBox();
  488. }
  489. function getLiveUpdate($iCountOld = 0, $iCountNew = 0)
  490. {
  491. $iCount = (int)$iCountNew - (int)$iCountOld;
  492. if($iCount < 0)
  493. return '';
  494. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  495. if(empty($aComments) || !is_array($aComments))
  496. return '';
  497. $aComment = array_shift($aComments);
  498. if(empty($aComment) || !is_array($aComment))
  499. return '';
  500. return $this->getLiveUpdateButton($aComment['cmt_id']);
  501. }
  502. function getLiveUpdateButton($iCommentId = 0)
  503. {
  504. $sJsObject = $this->getJsObjectName();
  505. $bComment = is_numeric($iCommentId) && (int)$iCommentId != 0;
  506. return $this->_oTemplate->parseHtmlByName('comments_lu_button.html', array(
  507. 'style_prefix' => $this->_sStylePrefix,
  508. 'class' => !$bComment ? 'hidden' : '',
  509. 'onclick_show' => "javascript:" . $sJsObject . ".goToBtn(this, '" . ($bComment ? $this->getItemAnchor($iCommentId) : '{cmt_anchor}') . "', '" . ($bComment ? $iCommentId : '{cmt_id}') . "');",
  510. ));
  511. }
  512. function getLiveUpdates($iCountOld = 0, $iCountNew = 0)
  513. {
  514. $bShowAll = true;
  515. $bShowActions = false;
  516. $iCount = (int)$iCountNew - (int)$iCountOld;
  517. if($iCount < 0)
  518. return '';
  519. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  520. if(empty($aComments) || !is_array($aComments))
  521. return '';
  522. $sJsObject = $this->getJsObjectName();
  523. $iUserId = $this->_getAuthorId();
  524. $bModerator = $this->isModerator();
  525. $aComments = array_reverse($aComments);
  526. $iComments = count($aComments);
  527. $aTmplVarsNotifs = array();
  528. foreach($aComments as $iIndex => $aComment) {
  529. $iCommentId = $aComment['cmt_id'];
  530. $sShowOnClick = "javascript:" . $sJsObject . ".goTo(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  531. $sReplyOnClick = "javascript:" . $sJsObject . ".goToAndReply(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  532. $iAuthorId = (int)$aComment['cmt_author_id'];
  533. if($iAuthorId < 0) {
  534. if(abs($iAuthorId) == $iUserId)
  535. continue;
  536. else if($bModerator)
  537. $iAuthorId *= -1;
  538. }
  539. $oAuthor = $this->_getAuthorObject($iAuthorId);
  540. $sAuthorName = $oAuthor->getDisplayName();
  541. $aTmplVarsNotifs[] = array(
  542. 'bx_if:show_as_hidden' => array(
  543. 'condition' => !$bShowAll && $iIndex < ($iComments - 1),
  544. 'content' => array(),
  545. ),
  546. 'item' => $this->_oTemplate->parseHtmlByName('comments_lu_notifications.html', array(
  547. 'style_prefix' => $this->_sStylePrefix,
  548. 'onclick_show' => $sShowOnClick,
  549. 'onclick_reply' => $sReplyOnClick,
  550. 'author_link' => $oAuthor->getUrl(),
  551. 'author_title' => bx_html_attribute($sAuthorName),
  552. 'author_name' => $sAuthorName,
  553. 'author_unit' => $oAuthor->getUnit(0, array('template' => 'unit_wo_info_links')),
  554. 'text' => _t('_cmt_txt_added_sample')
  555. )),
  556. 'bx_if:show_previous' => array(
  557. 'condition' => $bShowActions && $iIndex > 0,
  558. 'content' => array(
  559. 'onclick_previous' => $sJsObject . '.previousLiveUpdate(this)'
  560. )
  561. ),
  562. 'bx_if:show_close' => array(
  563. 'condition' => $bShowActions,
  564. 'content' => array(
  565. 'onclick_close' => $sJsObject . '.hideLiveUpdate(this)'
  566. )
  567. )
  568. );
  569. }
  570. return $this->_oTemplate->parseHtmlByName('popup_chain.html', array(
  571. 'html_id' => $this->getNotificationId(),
  572. 'bx_repeat:items' => $aTmplVarsNotifs
  573. ));
  574. }
  575. public function getElementBlock($aParams = array())
  576. {
  577. $aParams['usage'] = BX_CMT_USAGE_BLOCK;
  578. return $this->getElement($aParams);
  579. }
  580. public function getElementInline($aParams = array())
  581. {
  582. $aParams['usage'] = BX_CMT_USAGE_INLINE;
  583. return $this->getElement($aParams);
  584. }
  585. public function getElement($aParams = array())
  586. {
  587. $aParams = array_merge($this->_aElementDefaults, $aParams);
  588. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  589. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  590. $bShowCounterEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  591. $bRecalculateCounter = isset($aParams['recalculate_counter']) && $aParams['recalculate_counter'] == true;
  592. $iObjectId = $this->getId();
  593. $iAuthorId = $this->_getAuthorId();
  594. $iAuthorIp = $this->_getAuthorIp();
  595. $iCount = $this->getCommentsCountAll(0, $bRecalculateCounter);
  596. $bCount = (int)$iCount != 0;
  597. $isAllowedComment = $this->isPostAllowed();
  598. //--- Do Comment
  599. $bTmplVarsDoComment = $this->_isShowDoComment($aParams, $isAllowedComment, $bCount);
  600. $aTmplVarsDoComment = [];
  601. if($bTmplVarsDoComment)
  602. $aTmplVarsDoComment = [
  603. 'style_prefix' => $this->_sStylePrefix,
  604. 'do_comment' => $this->_getDoComment($aParams, $isAllowedComment),
  605. ];
  606. //--- Counter
  607. $bTmplVarsCounter = $this->_isShowCounter($aParams, $isAllowedComment, $bCount);
  608. $aTmplVarsCounter = array();
  609. if($bTmplVarsCounter)
  610. $aTmplVarsCounter = array(
  611. 'style_prefix' => $this->_sStylePrefix,
  612. 'bx_if:show_hidden' => array(
  613. 'condition' => !$bShowCounterEmpty && !$bCount,
  614. 'content' => array()
  615. ),
  616. 'counter' => $this->getCounter(array_merge($aParams, [
  617. 'show_counter_only' => false
  618. ]))
  619. );
  620. if(!$bTmplVarsDoComment && !$bTmplVarsCounter)
  621. return '';
  622. $sTmplName = $this->{'_getTmplElement' . bx_gen_method_name(!empty($aParams['usage']) ? $aParams['usage'] : BX_CMT_USAGE_DEFAULT)}();
  623. return $this->_oTemplate->parseHtmlByContent($sTmplName, array(
  624. 'style_prefix' => $this->_sStylePrefix,
  625. 'html_id' => $this->_aHtmlIds['main'],
  626. 'class' => $this->_sStylePrefix . ($bShowDoCommentAsButton ? '-button' : '') . ($bShowDoCommentAsButtonSmall ? '-button-small' : ''),
  627. 'count' => $iCount,
  628. 'bx_if:show_do_comment' => array(
  629. 'condition' => $bTmplVarsDoComment,
  630. 'content' => $aTmplVarsDoComment
  631. ),
  632. 'bx_if:show_counter' => array(
  633. 'condition' => $bTmplVarsCounter,
  634. 'content' => $aTmplVarsCounter
  635. ),
  636. 'script' => ''
  637. ));
  638. }
  639. public function getElementAPI($aParams = [])
  640. {
  641. if(!$this->_bIsApi)
  642. return;
  643. if(!$this->isEnabled())
  644. return bx_api_get_msg('_cmt_err_not_enabled');
  645. $aParams = array_merge($this->_aElementDefaultsApi, $aParams);
  646. $bRecalculateCounter = isset($aParams['recalculate_counter']) && $aParams['recalculate_counter'] == true;
  647. $iObjectId = $this->getId();
  648. $iAuthorId = $this->_getAuthorId();
  649. $iCount = $this->getCommentsCountAll(0, $bRecalculateCounter);
  650. $bCount = (int)$iCount != 0;
  651. $isAllowedComment = $this->isPostAllowed();
  652. $aParams['count'] = $iCount;
  653. //--- Do Comment
  654. $bDoComment = $this->_isShowDoComment($aParams, $isAllowedComment, $bCount);
  655. $aDoComment = $bDoComment ? $this->_getDoComment($aParams, $isAllowedComment) : [];
  656. //--- Counter
  657. $bCounter = $this->_isShowCounter($aParams, $isAllowedComment, $bCount);
  658. $aCounter = $bCounter ? $this->getCounterAPI(array_merge($aParams, [
  659. 'show_counter_only' => false,
  660. ])) : [];
  661. if(!$bDoComment && !$bCounter)
  662. return bx_api_get_msg('');
  663. return [
  664. 'type' => $this->_sType,
  665. 'system' => $this->_sSystem,
  666. 'object_id' => $this->_iId,
  667. 'params' => array_intersect_key($aParams, array_flip($this->_aElementParamsApi)),
  668. 'action' => $aDoComment,
  669. 'counter' => $aCounter
  670. ];
  671. }
  672. public function getCounter($aParams = [])
  673. {
  674. $aParams = array_merge($this->_aElementDefaults, $aParams);
  675. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  676. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  677. $bShowEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  678. $bShowReversed = isset($aParams['show_counter_reversed']) && $aParams['show_counter_reversed'] == true;
  679. $bShowScript = !isset($aParams['show_script']) || (bool)$aParams['show_script'] === true;
  680. $bRecalculateCounter = isset($aParams['recalculate_counter']) && $aParams['recalculate_counter'] == true;
  681. $sClass = 'sys-action-counter';
  682. if(isset($aParams['show_counter_only']) && (bool)$aParams['show_counter_only'] === true)
  683. $sClass .= ' sys-ac-only';
  684. $iCount = (int)$this->getCommentsCountAll(0, $bRecalculateCounter);
  685. if($iCount == 0 && !$bShowEmpty)
  686. $sClass .= ' sys-ac-hidden';
  687. $sClass .= ' ' . $this->_sStylePrefix . '-counter';
  688. if($bShowDoCommentAsButtonSmall)
  689. $sClass .= ' bx-btn-small-height';
  690. if($bShowDoCommentAsButton)
  691. $sClass .= ' bx-btn-height';
  692. $iCmtsLimit = 5;
  693. $aCmts = $this->_getCounterItems($iCmtsLimit);
  694. if(!$bShowReversed)
  695. $aCmts = array_reverse($aCmts);
  696. $aTmplVarsProfiles = [];
  697. foreach($aCmts as $aCmt) {
  698. $iAuthor = (int)$aCmt['cmt_author_id'];
  699. if(array_key_exists($iAuthor, $aTmplVarsProfiles))
  700. continue;
  701. $oAuthor = BxDolProfile::getInstanceMagic($iAuthor);
  702. if(!$oAuthor)
  703. continue;
  704. $aTmplVarsProfiles[$iAuthor] = [
  705. 'icon' => $oAuthor->getUnit(0, ['template' => ['name' => 'unit_wo_info_links', 'size' => 'icon']])
  706. ];
  707. if(count($aTmplVarsProfiles) >= $iCmtsLimit)
  708. break;
  709. }
  710. $aTmplVarsProfiles = array_values($aTmplVarsProfiles);
  711. $sHref = !empty($aParams['overwrite_counter_link_href']) ? $aParams['overwrite_counter_link_href'] : $this->getListUrl();
  712. $sOnclick = '';
  713. if(!empty($aParams['overwrite_counter_link_onclick']))
  714. $sOnclick = $aParams['overwrite_counter_link_onclick'];
  715. return $this->_oTemplate->parseHtmlByContent($this->_getTmplCounter(), [
  716. 'style_prefix' => $this->_sStylePrefix,
  717. 'id' => $this->_aHtmlIds['counter'],
  718. 'class' => $sClass,
  719. 'href' => $sHref,
  720. 'bx_if:show_onclick' => [
  721. 'condition' => !empty($sOnclick),
  722. 'content' => [
  723. 'onclick' => $sOnclick
  724. ]
  725. ],
  726. 'content' => $this->_getCounterLabel($iCount, $aParams),
  727. 'bx_repeat:profiles' => $aTmplVarsProfiles,
  728. 'bx_if:show_icon' => [
  729. 'condition' => ($bShowEmpty || !empty($aTmplVarsProfiles)) && (!isset($aParams['show_icon']) || $aParams['show_icon']),
  730. 'content' => [
  731. 'style_prefix' => $this->_sStylePrefix,
  732. 'icon' => !empty($aParams['custom_icon']) ? $aParams['custom_icon'] : $this->_oTemplate->getImageAuto('comment|' . $this->_sStylePrefix . '-counter-icon')
  733. ]
  734. ],
  735. 'script' => $this->getJsScript()
  736. ]);
  737. }
  738. public function getCounterApi($aParams = [])
  739. {
  740. $aParams = array_merge($this->_aElementDefaultsApi, $aParams);
  741. $bShowReversed = isset($aParams['show_counter_reversed']) && $aParams['show_counter_reversed'] == true;
  742. $bRecalculateCounter = isset($aParams['recalculate_counter']) && $aParams['recalculate_counter'] == true;
  743. $iCount = (int)$this->getCommentsCountAll(0, $bRecalculateCounter);
  744. $iCmtsLimit = 5;
  745. $aCmts = $this->_getCounterItems($iCmtsLimit);
  746. if(!$bShowReversed)
  747. $aCmts = array_reverse($aCmts);
  748. $aCmtsAuthors = [];
  749. foreach($aCmts as $aCmt) {
  750. $iAuthor = (int)$aCmt['cmt_author_id'];
  751. if(array_key_exists($iAuthor, $aCmtsAuthors))
  752. continue;
  753. $aCmtsAuthors[$iAuthor] = BxDolProfile::getData($iAuthor);
  754. if(count($aCmtsAuthors) >= $iCmtsLimit)
  755. break;
  756. }
  757. $aCmtsAuthors = array_values($aCmtsAuthors);
  758. return [
  759. 'count' => $iCount,
  760. 'authors' => $aCmtsAuthors
  761. ];
  762. }
  763. protected function _getCounterItems($iCmtsLimit, $iCmtsStart = 0)
  764. {
  765. return $this->_oQuery->getCommentsBy(array('type' => 'object_id', 'object_id' => $this->getId(), 'order_way' => 'desc', 'start' => $iCmtsStart, 'per_page' => $iCmtsLimit * 4));
  766. }
  767. protected function _getLabelDo($aParams = [])
  768. {
  769. return $this->_oTemplate->parseHtmlByContent($this->_getTmplLabelDo(), [
  770. 'style_prefix' => $this->_sStylePrefix,
  771. 'bx_if:show_icon' => [
  772. 'condition' => isset($aParams['show_do_comment_icon']) && $aParams['show_do_comment_icon'] == true,
  773. 'content' => [
  774. 'style_prefix' => $this->_sStylePrefix,
  775. 'icon' => $this->_oTemplate->getImageAuto($this->_getIconDo())
  776. ]
  777. ],
  778. 'bx_if:show_text' => [
  779. 'condition' => isset($aParams['show_do_comment_label']) && $aParams['show_do_comment_label'] == true,
  780. 'content' => [
  781. 'style_prefix' => $this->_sStylePrefix,
  782. 'text' => _t($this->_getTitleDo())
  783. ]
  784. ]
  785. ]);
  786. }
  787. protected function _getCounterLabel($iCount, $aParams = [])
  788. {
  789. $aParams = array_merge($this->_aElementDefaults, $aParams);
  790. $sResult = '';
  791. if((int)$iCount != 0)
  792. $sResult = _t(isset($aParams['caption']) ? $aParams['caption'] : '_cmt_txt_counter', $iCount);
  793. else
  794. $sResult = _t(isset($aParams['caption_empty']) ? $aParams['caption_empty'] : '_cmt_txt_counter_empty');
  795. return $sResult;
  796. }
  797. protected function _getTmplElementBlock()
  798. {
  799. return self::$_sTmplContentElementBlock;
  800. }
  801. protected function _getTmplElementInline()
  802. {
  803. return self::$_sTmplContentElementInline;
  804. }
  805. protected function _getTmplLabelDo()
  806. {
  807. return self::$_sTmplContentDoCommentLabel;
  808. }
  809. protected function _getTmplCounter()
  810. {
  811. return self::$_sTmplContentCounter;
  812. }
  813. protected function _isShowContent($aCmt)
  814. {
  815. $oProfileAuthor = BxDolProfile::getInstance(abs($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 bx_is_api() ? bx_api_get_msg(_t('_No such comment')) : array('msg' => _t('_No such comment'));
  1114. $iCmtAuthorId = $this->_getAuthorId();
  1115. if(!$this->isEditAllowed($aCmt)){
  1116. $sMsg = $aCmt['cmt_author_id'] == $iCmtAuthorId ? strip_tags($this->msgErrEditAllowed()) : _t('_Access denied');
  1117. return bx_is_api() ? bx_api_get_msg($sMsg) : array('msg' => $sMsg);
  1118. }
  1119. $oForm = $this->_getForm(BX_CMT_ACTION_EDIT, $aCmt['cmt_id']);
  1120. $oForm->initChecker($aCmt);
  1121. if($oForm->isSubmittedAndValid()) {
  1122. $sCmtText = $oForm->getCleanValue('cmt_text');
  1123. if($oForm->update($iCmtId) !== false) {
  1124. $iCmtUniqId = $this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId, [
  1125. 'author_id' => (int)$aCmt['cmt_author_id']
  1126. ]);
  1127. $sStatusAdmin = $this->getStatusAdmin();
  1128. if($sStatusAdmin !== BX_CMT_STATUS_ACTIVE)
  1129. $this->_oQuery->updateUniqId(['status_admin' => $sStatusAdmin], ['id' => $iCmtUniqId]);
  1130. if($this->isAttachImageEnabled())
  1131. $oForm->processImages($this, 'cmt_image', $iCmtUniqId, $iCmtId, $iCmtAuthorId, false);
  1132. $this->isEditAllowed($aCmt, true);
  1133. if($this->_sMetatagsObj && ($oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj)) !== false)
  1134. $oMetatags->metaAdd($iCmtUniqId, $sCmtText);
  1135. if(($mixedResult = $this->onEditAfter($iCmtId, $aDp)) !== false){
  1136. if (bx_is_api()){
  1137. $this->_unsetFormObject(BX_CMT_ACTION_POST);
  1138. return ['form' => $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId), 'res' => $iCmtId];
  1139. }
  1140. else{
  1141. return $mixedResult;
  1142. }
  1143. }
  1144. }
  1145. return bx_is_api() ? bx_api_get_msg(_t('_cmt_err_cannot_perform_action')) : array('msg' => _t('_cmt_err_cannot_perform_action'));
  1146. }
  1147. return bx_is_api() ? ['form' => $oForm, 'res' => 0] : array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  1148. }
  1149. protected function _getForm($sAction, $iId)
  1150. {
  1151. $oForm = $this->_getFormObject($sAction);
  1152. $oForm->setId(sprintf($oForm->getAttributeMask('id'), $sAction, $this->_sSystem, $this->_iId, $iId));
  1153. $oForm->setName(sprintf($oForm->getAttributeMask('name'), $sAction, $this->_sSystem, $this->_iId, $iId));
  1154. $oForm->aParams['db']['table'] = $this->_aSystem['table'];
  1155. $oForm->aInputs['sys']['value'] = $this->_sSystem;
  1156. $oForm->aInputs['id']['value'] = $this->_iId;
  1157. $oForm->aInputs['action']['value'] = 'Submit' . ucfirst($sAction) . 'Form';
  1158. if(!$this->isAttachImageEnabled())
  1159. unset($oForm->aInputs['cmt_image']);
  1160. if(isset($oForm->aInputs['cmt_text'])) {
  1161. $oForm->aInputs['cmt_text']['html'] = $this->_aSystem['html'];
  1162. $oForm->aInputs['cmt_text']['db']['pass'] = $this->isHtml() ? 'XssHtml' : 'XssMultiline';
  1163. if(isset($oForm->aInputs['cmt_text']['checker']['func']) && strtolower($oForm->aInputs['cmt_text']['checker']['func']) == 'length') {
  1164. $iCmtTextMin = (int)$this->_aSystem['chars_post_min'];
  1165. $iCmtTextMax = (int)$this->_aSystem['chars_post_max'];
  1166. $oForm->aInputs['cmt_text']['checker']['params'] = array($iCmtTextMin, $iCmtTextMax);
  1167. $oForm->aInputs['cmt_text']['checker']['error'] = _t('_Please enter n1-n2 characters', $iCmtTextMin, $iCmtTextMax);
  1168. }
  1169. }
  1170. if($sAction == BX_CMT_ACTION_EDIT && isset($oForm->aInputs['cmt_controls']))
  1171. foreach($oForm->aInputs['cmt_controls'] as $mixedKey => $mixedValue) {
  1172. if(!is_numeric($mixedKey) || empty($mixedValue['name']) || $mixedValue['name'] != 'cmt_cancel')
  1173. continue;
  1174. if(!isset($oForm->aInputs['cmt_controls'][$mixedKey]['attrs']))
  1175. $oForm->aInputs['cmt_controls'][$mixedKey]['attrs'] = array();
  1176. $oForm->aInputs['cmt_controls'][$mixedKey]['attrs']['onclick'] = $this->_sJsObjName . '.cmtEdit(this, ' . $iId . ', false)';
  1177. }
  1178. return $oForm;
  1179. }
  1180. protected function _getContent($aCmt, $aBp = [], $aDp = [])
  1181. {
  1182. $bDynamicMode = isset($aDp['dynamic_mode']) && $aDp['dynamic_mode'] === true;
  1183. $sAttachments = $this->_getAttachments($aCmt);
  1184. $oMenuCounters = BxDolMenu::getObjectInstance($this->_sMenuObjCounters);
  1185. $oMenuCounters->setCmtsData($this, $aCmt['cmt_id'], $aBp, $aDp);
  1186. $oMenuCounters->setDynamicMode($bDynamicMode);
  1187. return $this->_oTemplate->parseHtmlByName($this->_sTmplNameItemContent, array_merge(array(
  1188. 'style_prefix' => $this->_sStylePrefix,
  1189. 'js_object' => $this->_sJsObjName,
  1190. 'bx_if:show_attached' => array(
  1191. 'condition' => !empty($sAttachments),
  1192. 'content' => array(
  1193. 'style_prefix' => $this->_sStylePrefix,
  1194. 'attached' => $sAttachments
  1195. )
  1196. ),
  1197. 'counters' => $oMenuCounters->getCode(),
  1198. ), $this->_getTmplVarsText($aCmt)));
  1199. }
  1200. protected function _getMoreLink($sCmts, $aBp = array(), $aDp = array())
  1201. {
  1202. $iStart = $iPerView = 0;
  1203. switch($aBp['type']) {
  1204. case BX_CMT_BROWSE_HEAD:
  1205. case BX_CMT_BROWSE_POPULAR:
  1206. case BX_CMT_BROWSE_CONNECTION:
  1207. $iPerView = $aBp['per_view'];
  1208. $iStart = $aBp['start'] + $iPerView;
  1209. if($iStart >= $aBp['count'])
  1210. return $sCmts;
  1211. break;
  1212. case BX_CMT_BROWSE_TAIL:
  1213. $iPerView = $aBp['per_view'];
  1214. $iStart = $aBp['start'] - $iPerView;
  1215. if($iStart < 0) {
  1216. $iPerView += $iStart;
  1217. $iStart = 0;
  1218. }
  1219. if($iStart == 0 && $iPerView == 0)
  1220. return $sCmts;
  1221. break;
  1222. }
  1223. $sParentKey = isset($aBp['vparent_id']) ? 'vparent_id' : 'parent_id';
  1224. $bRoot = (int)$aBp[$sParentKey] <= 0;
  1225. $sMore = $this->_oTemplate->parseHtmlByName('comment_more.html', array(
  1226. 'js_object' => $this->_sJsObjName,
  1227. 'style_prefix' => $this->_sStylePrefix,
  1228. 'bx_if:is_root' => array(
  1229. 'condition' => $bRoot,
  1230. 'content' => array()
  1231. ),
  1232. 'parent_id' => $aBp[$sParentKey],
  1233. 'start' => $iStart,
  1234. 'per_view' => $iPerView,
  1235. 'title' => _t('_cmt_load_more_' . ($aBp[$sParentKey] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
  1236. ));
  1237. switch($aBp['type']) {
  1238. case BX_CMT_BROWSE_HEAD:
  1239. case BX_CMT_BROWSE_POPULAR:
  1240. case BX_CMT_BROWSE_CONNECTION:
  1241. $sCmts .= $sMore;
  1242. break;
  1243. case BX_CMT_BROWSE_TAIL:
  1244. $sCmts = $sMore . $sCmts;
  1245. break;
  1246. }
  1247. return $sCmts;
  1248. }
  1249. protected function _getEmpty($aDp = array())
  1250. {
  1251. $sClass = '';
  1252. if(!empty($aDp['class']))
  1253. $sClass .= ' ' . $aDp['class'];
  1254. return $this->_oTemplate->parseHtmlByName('comment_empty.html', array(
  1255. 'style_prefix' => $this->_sStylePrefix,
  1256. 'class' => $sClass,
  1257. 'content' => MsgBox(_t('_Empty'))
  1258. ));
  1259. }
  1260. protected function _getAttachments($aCmt)
  1261. {
  1262. $aTmplImages = array();
  1263. if(!$this->isAttachImageEnabled())
  1264. return '';
  1265. $aFiles = $this->_oQuery->getFiles($this->_aSystem['system_id'], $aCmt['cmt_id']);
  1266. if(!empty($aFiles) && is_array($aFiles)) {
  1267. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  1268. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->getTranscoderPreviewName());
  1269. foreach($aFiles as $aFile) {
  1270. $sFile = $oStorage->getFileUrlById($aFile['image_id']);
  1271. $bImage = $oTranscoder && $oTranscoder->isMimeTypeSupported($aFile['mime_type']);
  1272. $sPreview = '';
  1273. $iWidth = $iHeight = 0;
  1274. if($bImage) {
  1275. if(!$this->_bIsApi && $oTranscoder)
  1276. $sPreview = $oTranscoder->getFileUrl($aFile['image_id']);
  1277. if(empty($aFile['dimensions'])) {
  1278. $aFileInfo = $oStorage->getFile($aFile['image_id']);
  1279. if(!empty($aFileInfo['dimensions']))
  1280. $aFile['dimensions'] = $aFileInfo['dimensions'];
  1281. }
  1282. if(!empty($aFile['dimensions']))
  1283. list($iWidth, $iHeight) = explode('x', $aFile['dimensions']);
  1284. }
  1285. if(!$this->_bIsApi && !$sPreview)
  1286. $sPreview = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFile['file_name']));
  1287. $aTmplVarsFile = array(
  1288. 'js_object' => $this->_sJsObjName,
  1289. 'preview' => $sPreview,
  1290. 'file' => $sFile,
  1291. 'file_id' => $aFile['id'],
  1292. 'file_name' => $aFile['file_name'],
  1293. 'file_icon' => $oStorage->getFontIconNameByFileName($aFile['file_name']),
  1294. 'file_size' => _t_format_size($aFile['size']),
  1295. 'w' => $iWidth,
  1296. 'h' => $iHeight
  1297. );
  1298. if($this->_bIsApi){
  1299. $aTmplImages[] = array(
  1300. 'is_image' => $bImage,
  1301. 'file' => $aTmplVarsFile['file'],
  1302. 'file_id' => $aTmplVarsFile['file_id'],
  1303. 'file_name' => $aTmplVarsFile['file_name'],
  1304. 'file_icon' => $aTmplVarsFile['file_icon'],
  1305. 'file_size' => $aTmplVarsFile['file_size'],
  1306. 'width' => $aTmplVarsFile['w'],
  1307. 'height' => $aTmplVarsFile['h'],
  1308. );
  1309. }
  1310. else{
  1311. $aTmplImages[] = array(
  1312. 'style_prefix' => $this->_sStylePrefix,
  1313. 'bx_if:show_image' => array(
  1314. 'condition' => $bImage,
  1315. 'content' => $aTmplVarsFile
  1316. ),
  1317. 'bx_if:show_file' => array(
  1318. 'condition' => !$bImage,
  1319. 'content' => $aTmplVarsFile
  1320. ),
  1321. );
  1322. }
  1323. }
  1324. }
  1325. if (bx_is_api()){
  1326. return $aTmplImages;
  1327. }
  1328. return $this->_oTemplate->parseHtmlByName('comment_attachments.html', array(
  1329. 'bx_repeat:attached' => $aTmplImages
  1330. ));
  1331. }
  1332. protected function _getTmplVarsNotes($aCmt)
  1333. {
  1334. $aTmplVars = array();
  1335. //--- Pending status related notes.
  1336. if($aCmt['cmt_status_admin'] == BX_CMT_STATUS_PENDING)
  1337. $aTmplVars[] = [
  1338. 'style_prefix' => $this->_sStylePrefix,
  1339. 'bx_if:show_note_color' => [
  1340. 'condition' => true,
  1341. 'content' => [
  1342. 'item_note_color' => 'red3'
  1343. ]
  1344. ],
  1345. 'item_note' => _t('_cmt_txt_note_approve_pending')
  1346. ];
  1347. return [
  1348. 'bx_if:show_notes' => [
  1349. 'condition' => !empty($aTmplVars),
  1350. 'content' => [
  1351. 'style_prefix' => $this->_sStylePrefix,
  1352. 'bx_repeat:notes' => $aTmplVars
  1353. ]
  1354. ],
  1355. ];
  1356. }
  1357. protected function _getTmplVarsAuthor($aCmt)
  1358. {
  1359. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  1360. $bAuthorIcon = !empty($sAuthorIcon);
  1361. return array(
  1362. 'author_unit' => $sAuthorUnit,
  1363. 'bx_if:show_icon' => array(
  1364. 'condition' => $bAuthorIcon,
  1365. 'content' => array(
  1366. 'author_icon' => $sAuthorIcon
  1367. )
  1368. ),
  1369. 'bx_if:show_icon_empty' => array(
  1370. 'condition' => !$bAuthorIcon,
  1371. 'content' => array()
  1372. ),
  1373. 'bx_if:show_author_link' => array(
  1374. 'condition' => !empty($sAuthorLink),
  1375. 'content' => array(
  1376. 'author_link' => $sAuthorLink,
  1377. 'author_title' => bx_html_attribute($sAuthorName),
  1378. 'author_name' => $sAuthorName
  1379. )
  1380. ),
  1381. 'bx_if:show_author_text' => array(
  1382. 'condition' => empty($sAuthorLink),
  1383. 'content' => array(
  1384. 'author_name' => $sAuthorName
  1385. )
  1386. ),
  1387. );
  1388. }
  1389. protected function _getTmplVarsText($aCmt)
  1390. {
  1391. return [
  1392. 'style_prefix' => $this->_sStylePrefix,
  1393. 'text' => $this->_prepareTextForOutput($aCmt['cmt_text'], $aCmt['cmt_id'])
  1394. ];
  1395. }
  1396. protected function _getDoComment($aParams = [], $isAllowedComment = true)
  1397. {
  1398. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  1399. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  1400. $iCount = isset($aParams['count']) ? (int)$aParams['count'] : 0;
  1401. $bDisabled = !$isAllowedComment;
  1402. $sClass = '';
  1403. if($bShowDoCommentAsButton)
  1404. $sClass = 'bx-btn';
  1405. else if ($bShowDoCommentAsButtonSmall)
  1406. $sClass = 'bx-btn bx-btn-small';
  1407. if(!$isAllowedComment)
  1408. $sClass .= $bShowDoCommentAsButton || $bShowDoCommentAsButtonSmall ? ' bx-btn-disabled' : 'bx-cmts-disabled';
  1409. if($this->_bIsApi)
  1410. return [
  1411. 'is_disabled' => $bDisabled,
  1412. 'count' => $iCount,
  1413. 'link' => bx_api_get_relative_url($this->getListUrl()),
  1414. 'title' => _t($this->_getTitleDo(), $iCount)
  1415. ];
  1416. return $this->_oTemplate->parseLink($this->getListUrl(), $this->_getLabelDo($aParams), [
  1417. 'class' => $this->_sStylePrefix . '-do-comment ' . $this->_sStylePrefix . '-dc ' . $sClass,
  1418. 'title' => _t($this->_getTitleDo(), $iCount)
  1419. ]);
  1420. }
  1421. }
  1422. /** @} */