* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\CMS\Document\Renderer\Html;
use Joomla\CMS\Document\DocumentRenderer;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\WebAsset\WebAssetAttachBehaviorInterface;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('JPATH_PLATFORM') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* JDocument metas renderer
*
* @since 4.0.0
*/
class MetasRenderer extends DocumentRenderer
{
/**
* Renders the document metas and returns the results as a string
*
* @param string $head (unused)
* @param array $params Associative array of values
* @param string $content The script
*
* @return string The output of the script
*
* @since 4.0.0
*/
public function render($head, $params = array(), $content = null)
{
// Convert the tagids to titles
if (isset($this->_doc->_metaTags['name']['tags'])) {
$tagsHelper = new TagsHelper();
$this->_doc->_metaTags['name']['tags'] = implode(', ', $tagsHelper->getTagNames($this->_doc->_metaTags['name']['tags']));
}
/** @var \Joomla\CMS\Application\CMSApplication $app */
$app = Factory::getApplication();
$wa = $this->_doc->getWebAssetManager();
// Check for AttachBehavior and web components
foreach ($wa->getAssets('script', true) as $asset) {
if ($asset instanceof WebAssetAttachBehaviorInterface) {
$asset->onAttachCallback($this->_doc);
}
}
// Trigger the onBeforeCompileHead event
$app->triggerEvent('onBeforeCompileHead');
// Add Script Options as inline asset
$scriptOptions = $this->_doc->getScriptOptions();
if ($scriptOptions) {
$prettyPrint = (JDEBUG && \defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : false);
$jsonOptions = json_encode($scriptOptions, $prettyPrint);
$jsonOptions = $jsonOptions ?: '{}';
$wa->addInlineScript(
$jsonOptions,
['name' => 'joomla.script.options', 'position' => 'before'],
['type' => 'application/json', 'class' => 'joomla-script-options new'],
['core']
);
}
// Lock the AssetManager
$wa->lock();
// Get line endings
$lnEnd = $this->_doc->_getLineEnd();
$tab = $this->_doc->_getTab();
$buffer = '';
// Generate charset when using HTML5 (should happen first)
if ($this->_doc->isHtml5()) {
$buffer .= $tab . '' . $lnEnd;
}
// Generate base tag (need to happen early)
$base = $this->_doc->getBase();
if (!empty($base)) {
$buffer .= $tab . '