[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Plugin 5 * @subpackage System.Debug 6 * 7 * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Plugin\System\Debug; 12 13 use DebugBar\DebugBar; 14 use DebugBar\JavascriptRenderer as DebugBarJavascriptRenderer; 15 use Joomla\CMS\Factory; 16 17 // phpcs:disable PSR1.Files.SideEffects 18 \defined('_JEXEC') or die; 19 // phpcs:enable PSR1.Files.SideEffects 20 21 /** 22 * Custom JavascriptRenderer for DebugBar 23 * 24 * @since 4.0.0 25 */ 26 class JavascriptRenderer extends DebugBarJavascriptRenderer 27 { 28 /** 29 * Class constructor. 30 * 31 * @param \DebugBar\DebugBar $debugBar DebugBar instance 32 * @param string $baseUrl The base URL from which assets will be served 33 * @param string $basePath The path which assets are relative to 34 * 35 * @since 4.0.0 36 */ 37 public function __construct(DebugBar $debugBar, $baseUrl = null, $basePath = null) 38 { 39 parent::__construct($debugBar, $baseUrl, $basePath); 40 41 // Disable features that loaded by Joomla! API, or not in use 42 $this->setEnableJqueryNoConflict(false); 43 $this->disableVendor('jquery'); 44 $this->disableVendor('fontawesome'); 45 } 46 47 /** 48 * Renders the html to include needed assets 49 * 50 * Only useful if Assetic is not used 51 * 52 * @return string 53 * 54 * @since 4.0.0 55 */ 56 public function renderHead() 57 { 58 list($cssFiles, $jsFiles, $inlineCss, $inlineJs, $inlineHead) = $this->getAssets(null, self::RELATIVE_URL); 59 $html = ''; 60 $doc = Factory::getApplication()->getDocument(); 61 62 foreach ($cssFiles as $file) { 63 $html .= sprintf('<link rel="stylesheet" type="text/css" href="%s">' . "\n", $file); 64 } 65 66 foreach ($inlineCss as $content) { 67 $html .= sprintf('<style>%s</style>' . "\n", $content); 68 } 69 70 foreach ($jsFiles as $file) { 71 $html .= sprintf('<script type="text/javascript" src="%s" defer></script>' . "\n", $file); 72 } 73 74 $nonce = ''; 75 76 if ($doc->cspNonce) { 77 $nonce = ' nonce="' . $doc->cspNonce . '"'; 78 } 79 80 foreach ($inlineJs as $content) { 81 $html .= sprintf('<script type="module"%s>%s</script>' . "\n", $nonce, $content); 82 } 83 84 foreach ($inlineHead as $content) { 85 $html .= $content . "\n"; 86 } 87 88 return $html; 89 } 90 91 /** 92 * Returns the code needed to display the debug bar 93 * 94 * AJAX request should not render the initialization code. 95 * 96 * @param boolean $initialize Whether or not to render the debug bar initialization code 97 * @param boolean $renderStackedData Whether or not to render the stacked data 98 * 99 * @return string 100 * 101 * @since 4.0.0 102 */ 103 public function render($initialize = true, $renderStackedData = true) 104 { 105 $js = ''; 106 $doc = Factory::getApplication()->getDocument(); 107 108 if ($initialize) { 109 $js = $this->getJsInitializationCode(); 110 } 111 112 if ($renderStackedData && $this->debugBar->hasStackedData()) { 113 foreach ($this->debugBar->getStackedData() as $id => $data) { 114 $js .= $this->getAddDatasetCode($id, $data, '(stacked)'); 115 } 116 } 117 118 $suffix = !$initialize ? '(ajax)' : null; 119 $js .= $this->getAddDatasetCode($this->debugBar->getCurrentRequestId(), $this->debugBar->getData(), $suffix); 120 121 $nonce = ''; 122 123 if ($doc->cspNonce) { 124 $nonce = ' nonce="' . $doc->cspNonce . '"'; 125 } 126 127 if ($this->useRequireJs) { 128 return "<script type=\"module\"$nonce>\nrequire(['debugbar'], function(PhpDebugBar){ $js });\n</script>\n"; 129 } else { 130 return "<script type=\"module\"$nonce>\n$js\n</script>\n"; 131 } 132 } 133 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |