- md5
- b58d75b3a0900c023231cb6b617c0f1a
- sha1
- c16cddec948d13529e812a543e9fe22a3ab3effa
- sha256
- 9cb3fee65554bbe6ca76117846c8f240a9dcd12caa2616193dc9af065a2761ee
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
<?php
/**
* @package Joomla.Plugin
* @subpackage System.Debug
*
* @copyright Copyright (C) 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\System\Debug;
use DebugBar\DebugBar;
use DebugBar\JavascriptRenderer as DebugBarJavascriptRenderer;
use Joomla\CMS\Factory;
/**
* Custom JavascriptRenderer for DebugBar
*
* @since 4.0.0
*/
class JavascriptRenderer extends DebugBarJavascriptRenderer
{
/**
* Class constructor.
*
* @param \DebugBar\DebugBar $debugBar DebugBar instance
* @param string $baseUrl The base URL from which assets will be served
* @param string $basePath The path which assets are relative to
*
* @since 4.0.0
*/
public function __construct(DebugBar $debugBar, $baseUrl = null, $basePath = null)
{
parent::__construct($debugBar, $baseUrl, $basePath);
// Disable features that loaded by Joomla! API, or not in use
$this->setEnableJqueryNoConflict(false);
$this->disableVendor('jquery');
$this->disableVendor('fontawesome');
}
/**
* Renders the html to include needed assets
*
* Only useful if Assetic is not used
*
* @return string
*
* @since 4.0.0
*/
public function renderHead()
{
list($cssFiles, $jsFiles, $inlineCss, $inlineJs, $inlineHead) = $this->getAssets(null, self::RELATIVE_URL);
$html = '';
$doc = Factory::getApplication()->getDocument();
foreach ($cssFiles as $file)
{
$html .= sprintf('<link rel="stylesheet" type="text/css" href="%s">' . "\n", $file);
}
foreach ($inlineCss as $content)
{
$html .= sprintf('<style type="text/css">%s</style>' . "\n", $content);
}
foreach ($jsFiles as $file)
{
$html .= sprintf('<script type="text/javascript" src="%s" defer></script>' . "\n", $file);
}
$nonce = '';
if ($doc->cspNonce)
{
$nonce = ' nonce="' . $doc->cspNonce . '"';
}
foreach ($inlineJs as $content)
{
$html .= sprintf('<script type="module"%s>%s</script>' . "\n", $nonce, $content);
}
foreach ($inlineHead as $content)
{
$html .= $content . "\n";
}
return $html;
}
/**
* Returns the code needed to display the debug bar
*
* AJAX request should not render the initialization code.
*
* @param boolean $initialize Whether or not to render the debug bar initialization code
* @param boolean $renderStackedData Whether or not to render the stacked data
*
* @return string
*
* @since 4.0.0
*/
public function render($initialize = true, $renderStackedData = true)
{
$js = '';
$doc = Factory::getApplication()->getDocument();
if ($initialize)
{
$js = $this->getJsInitializationCode();
}
if ($renderStackedData && $this->debugBar->hasStackedData())
{
foreach ($this->debugBar->getStackedData() as $id => $data)
{
$js .= $this->getAddDatasetCode($id, $data, '(stacked)');
}
}
$suffix = !$initialize ? '(ajax)' : null;
$js .= $this->getAddDatasetCode($this->debugBar->getCurrentRequestId(), $this->debugBar->getData(), $suffix);
$nonce = '';
if ($doc->cspNonce)
{
$nonce = ' nonce="' . $doc->cspNonce . '"';
}
if ($this->useRequireJs)
{
return "<script type=\"module\"$nonce>\nrequire(['debugbar'], function(PhpDebugBar){ $js });\n</script>\n";
}
else
{
return "<script type=\"module\"$nonce>\n$js\n</script>\n";
}
}
}
The same content is in 5 releases, Joomla 4.0.0-beta to 4.0.0-beta5. See them all, or every version of this file.