PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/Quản lý website bán mỹ phẩm PHP/plugins/system/jcomments/jcomments.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 181 lines | 129 code | 33 blank | 19 comment | 51 complexity | 0ab9ec1073055847927c9058d881abc0 MD5 | raw file
  1. <?php
  2. /**
  3. * JComments - Joomla Comment System
  4. *
  5. * System plugin for attaching JComments CSS & JavaScript to HEAD tag
  6. *
  7. * @version 2.3
  8. * @package JComments
  9. * @author Sergey M. Litvinov (smart@joomlatune.ru)
  10. * @copyright (C) 2006-2012 by Sergey M. Litvinov (http://www.joomlatune.ru)
  11. * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
  12. *
  13. **/
  14. defined('_JEXEC') or die;
  15. jimport('joomla.plugin.plugin');
  16. class plgSystemJComments extends JPlugin
  17. {
  18. function plgSystemJComments(&$subject, $config)
  19. {
  20. parent::__construct($subject, $config);
  21. if (!isset($this->params)) {
  22. $this->params = new JParameter('');
  23. }
  24. // small hack to allow CAPTCHA display even if any notice or warning occurred
  25. $option = JRequest::getCmd('option');
  26. $task = JRequest::getCmd('task');
  27. if ($option == 'com_jcomments' && $task == 'captcha') {
  28. @ob_start();
  29. }
  30. if (isset($_REQUEST['jtxf'])) {
  31. if ($this->params->get('disable_error_reporting', 0) == 1) {
  32. // turn off all error reporting for AJAX call
  33. @error_reporting(0);
  34. }
  35. }
  36. }
  37. function onAfterRender()
  38. {
  39. if ($this->params->get('clear_rss', 0) == 1) {
  40. $option = JRequest::getCmd('option');
  41. if ($option == 'com_content') {
  42. $document = JFactory::getDocument();
  43. if ($document->getType() == 'feed') {
  44. $buffer = JResponse::getBody();
  45. $buffer = preg_replace('#{jcomments\s+(off|on|lock)}#is', '', $buffer);
  46. JResponse::setBody($buffer);
  47. }
  48. }
  49. }
  50. if ((defined('JCOMMENTS_CSS') || defined('JCOMMENTS_JS')) && !defined('JCOMMENTS_SHOW')) {
  51. $app = JFactory::getApplication();
  52. if ($app->getName() == 'site') {
  53. $buffer = JResponse::getBody();
  54. $regexpJS = '#(\<script(\stype=\"text\/javascript\")? src="[^\"]*\/com_jcomments\/[^\>]*\>\<\/script\>[\s\r\n]*?)#ismU';
  55. $regexpCSS = '#(\<link rel="stylesheet" href="[^\"]*\/com_jcomments\/[^>]*>[\s\r\n]*?)#ismU';
  56. $jcommentsTestJS = '#(JCommentsEditor|new JComments)#ismU';
  57. $jcommentsTestCSS = '#(comment-link|jcomments-links)#ismU';
  58. $jsFound = preg_match($jcommentsTestJS, $buffer);
  59. $cssFound = preg_match($jcommentsTestCSS, $buffer);
  60. if (!$jsFound) {
  61. // remove JavaScript if JComments isn't loaded
  62. $buffer = preg_replace($regexpJS, '', $buffer);
  63. }
  64. if (!$cssFound && !$jsFound) {
  65. // remove CSS if JComments isn't loaded
  66. $buffer = preg_replace($regexpCSS, '', $buffer);
  67. }
  68. if ($buffer != '') {
  69. JResponse::setBody($buffer);
  70. }
  71. }
  72. }
  73. return true;
  74. }
  75. function onAfterRoute()
  76. {
  77. $legacyFile = JPATH_ROOT . '/components/com_jcomments/jcomments.legacy.php';
  78. if (!is_file($legacyFile)) {
  79. return;
  80. }
  81. include_once ($legacyFile);
  82. $mainframe = JFactory::getApplication('site');
  83. $mainframe->getRouter();
  84. $document = JFactory::getDocument();
  85. if ($document->getType() == 'html') {
  86. if ($mainframe->isAdmin()) {
  87. $document->addStyleSheet(JURI::base() . 'components/com_jcomments/assets/icon.css?v=2');
  88. $option = JAdministratorHelper::findOption();
  89. $task = JRequest::getCmd('task');
  90. $type = JRequest::getCmd('type', '', 'post');
  91. // remove comments if content item deleted from trash
  92. if ($option == 'com_trash' && $task == 'delete' && $type == 'content') {
  93. $cid = JRequest::getVar('cid', array(0), 'post', 'array');
  94. JArrayHelper::toInteger($cid, array(0));
  95. include_once (JPATH_ROOT . '/components/com_jcomments/jcomments.php');
  96. JCommentsModel::deleteComments($cid, 'com_content');
  97. }
  98. } else {
  99. $option = JRequest::getCmd('option');
  100. if ($option == 'com_content' || $option == 'com_alphacontent' || $option == 'com_multicategories') {
  101. include_once (JCOMMENTS_BASE . '/jcomments.class.php');
  102. include_once (JCOMMENTS_BASE . '/jcomments.config.php');
  103. include_once (JCOMMENTS_HELPERS . '/system.php');
  104. // include JComments CSS
  105. if ($this->params->get('disable_template_css', 0) == 0) {
  106. $document->addStyleSheet(JCommentsSystemPluginHelper::getCSS());
  107. $language = JFactory::getLanguage();
  108. if ($language->isRTL()) {
  109. $rtlCSS = JCommentsSystemPluginHelper::getCSS(true);
  110. if ($rtlCSS != '') {
  111. $document->addStyleSheet($rtlCSS);
  112. }
  113. }
  114. }
  115. if (!defined('JCOMMENTS_CSS')) {
  116. define('JCOMMENTS_CSS', 1);
  117. }
  118. // include JComments JavaScript library
  119. $document->addScript(JCommentsSystemPluginHelper::getCoreJS());
  120. if (!defined('JOOMLATUNE_AJAX_JS')) {
  121. $document->addScript(JCommentsSystemPluginHelper::getAjaxJS());
  122. define('JOOMLATUNE_AJAX_JS', 1);
  123. }
  124. if (!defined('JCOMMENTS_JS')) {
  125. define('JCOMMENTS_JS', 1);
  126. }
  127. }
  128. }
  129. }
  130. }
  131. function onJCommentsShow($object_id, $object_group, $object_title)
  132. {
  133. $coreFile = JPATH_ROOT . '/components/com_jcomments/jcomments.php';
  134. if (is_file($coreFile)) {
  135. include_once ($coreFile);
  136. echo JComments::show($object_id, $object_group, $object_title);
  137. }
  138. }
  139. function onJCommentsCount($object_id, $object_group)
  140. {
  141. $coreFile = JPATH_ROOT . '/components/com_jcomments/jcomments.php';
  142. if (is_file($coreFile)) {
  143. include_once ($coreFile);
  144. echo JComments::getCommentsCount($object_id, $object_group);
  145. }
  146. }
  147. }
  148. ?>