Permalink
Browse files

# [#28826] System Debug plug-in doesn't show for non logged-in user.

Thanks Shaun
  • Loading branch information...
1 parent 0591536 commit 13921d69be1ee630661c7c8bfaa1cfed1c13bf09 Shaun Maunder committed with infograf768 Sep 20, 2012
Showing with 80 additions and 32 deletions.
  1. +9 −2 administrator/includes/application.php
  2. +9 −1 includes/application.php
  3. +1 −0 installation/CHANGELOG
  4. +61 −29 plugins/system/debug/debug.php
@@ -47,13 +47,20 @@ public function __construct($config = array())
public function initialise($options = array())
{
$config = JFactory::getConfig();
+ $user = JFactory::getUser();
+
+ // If the user is a guest we populate it with the guest user group.
+ if ($user->guest)
+ {
+ $guestUsergroup = JComponentHelper::getParams('com_users')->get('guest_usergroup', 1);
+ $user->groups = array($guestUsergroup);
+ }
// if a language was specified it has priority
// otherwise use user or default language settings
if (empty($options['language']))
{
- $user = JFactory::getUser();
- $lang = $user->getParam('admin_language');
+ $lang = $user->getParam('admin_language');
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
@@ -55,6 +55,14 @@ public function __construct($config = array())
public function initialise($options = array())
{
$config = JFactory::getConfig();
+ $user = JFactory::getUser();
+
+ // If the user is a guest we populate it with the guest user group.
+ if ($user->guest)
+ {
+ $guestUsergroup = JComponentHelper::getParams('com_users')->get('guest_usergroup', 1);
+ $user->groups = array($guestUsergroup);
+ }
// if a language was specified it has priority
// otherwise use user or default language settings
@@ -78,7 +86,7 @@ public function initialise($options = array())
if (empty($options['language'])) {
// Detect user language
- $lang = JFactory::getUser()->getParam('language');
+ $lang = $user->getParam('language');
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
@@ -31,6 +31,7 @@ $ -> Language fix or change
# [#29214] Module's menu assignment always shown. Thanks Stephane Deluce
# [#29137] Address in single contact rendering incorrectly. Thanks Elin
#$ Correcting various spelling issues in en-GB. Thanks Brian.
+ # [#28826] System Debug plug-in doesn't show for non logged-in user. Thanks Shaun
19-Sep-2012 Jean-Marie Simonet
# [#29176] Call to undefined method JHtmlTabs::getJSObject() (Sync with platform). Thanks Elin
@@ -21,6 +21,14 @@ class plgSystemDebug extends JPlugin
protected $linkFormat = '';
/**
+ * True if debug lang is on.
+ *
+ * @var boolean
+ * @since 3.0
+ */
+ private $debugLang = false;
+
+ /**
* Constructor.
*
* @param object &$subject The object to observe
@@ -38,8 +46,10 @@ public function __construct(&$subject, $config)
JLog::addLogger(array('text_file' => 'deprecated.php'), JLog::ALL, array('deprecated'));
}
+ $this->debugLang = JFactory::getApplication()->getCfg('debug_lang');
+
// Only if debugging or language debug is enabled
- if (JDEBUG || JFactory::getApplication()->getCfg('debug_lang'))
+ if (JDEBUG || $this->debugLang)
{
JFactory::getConfig()->set('gzip', 0);
ob_start();
@@ -60,7 +70,7 @@ public function __construct(&$subject, $config)
public function onAfterDispatch()
{
// Only if debugging or language debug is enabled
- if (JDEBUG || JFactory::getApplication()->getCfg('debug_lang'))
+ if ((JDEBUG || $this->debugLang) && $this->isAuthorisedDisplayDebug())
{
JHtml::_('stylesheet', 'cms/debug.css', array(), true);
}
@@ -74,49 +84,37 @@ public function onAfterDispatch()
public function __destruct()
{
// Do not render if debugging or language debug is not enabled
- if (!JDEBUG && !JFactory::getApplication()->getCfg('debug_lang'))
+ if (!JDEBUG && !$this->debugLang)
{
return;
}
- // Load the language
- $this->loadLanguage();
-
- // Capture output
- $contents = ob_get_contents();
- ob_end_clean();
-
- // No debug for Safari and Chrome redirection
- if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'webkit') !== false
- && substr($contents, 0, 50) == '<html><head><meta http-equiv="refresh" content="0;')
+ // User has to be authorised to see the debug information
+ if (!$this->isAuthorisedDisplayDebug())
{
- echo $contents;
return;
}
// Only render for HTML output
- if ('html' !== JFactory::getDocument()->getType())
+ if (JFactory::getDocument()->getType() !== 'html')
{
- echo $contents;
return;
}
- // If the user is not allowed to view the output then end here
- $filterGroups = (array) $this->params->get('filter_groups', null);
+ // Capture output
+ $contents = ob_get_contents();
+ ob_end_clean();
- if (!empty($filterGroups))
+ // No debug for Safari and Chrome redirection
+ if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'webkit') !== false
+ && substr($contents, 0, 50) == '<html><head><meta http-equiv="refresh" content="0;')
{
- $userGroups = JFactory::getUser()->get('groups');
-
- if (!array_intersect($filterGroups, $userGroups))
- {
- echo $contents;
- return;
- }
+ echo $contents;
+ return;
}
- // Load language file
- $this->loadLanguage('plg_system_debug');
+ // Load language
+ $this->loadLanguage();
$html = '';
@@ -155,7 +153,7 @@ public function __destruct()
}
}
- if (JFactory::getApplication()->getCfg('debug_lang'))
+ if ($this->debugLang)
{
if ($this->params->get('language_errorfiles', 1))
{
@@ -180,6 +178,40 @@ public function __destruct()
}
/**
+ * Method to check if the current user is allowed to see the debug information or not.
+ *
+ * @return boolean True is access is allowed
+ *
+ * @since 3.0
+ */
+ private function isAuthorisedDisplayDebug()
+ {
+ static $result = null;
+
+ if (!is_null($result))
+ {
+ return $result;
+ }
+
+ // If the user is not allowed to view the output then end here
+ $filterGroups = (array) $this->params->get('filter_groups', null);
+
+ if (!empty($filterGroups))
+ {
+ $userGroups = JFactory::getUser()->get('groups');
+
+ if (!array_intersect($filterGroups, $userGroups))
+ {
+ $result = false;
+ return false;
+ }
+ }
+
+ $result = true;
+ return true;
+ }
+
+ /**
* General display method.
*
* @param string $item The item to display

0 comments on commit 13921d6

Please sign in to comment.