File manager - Edit - /home/opticamezl/www/newok/Document.tar
Back
OpensearchDocument.php 0000644 00000014166 15172704423 0011060 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; use Joomla\CMS\Document\Opensearch\OpensearchImage; use Joomla\CMS\Document\Opensearch\OpensearchUrl; use Joomla\CMS\Factory; use Joomla\CMS\Router\Route; use Joomla\CMS\Uri\Uri; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * Opensearch class, provides an easy interface to display an Opensearch document * * @link http://www.opensearch.org/ * @since 1.7.0 */ class OpensearchDocument extends Document { /** * ShortName element * * required * * @var string * @since 1.7.0 */ private $_shortName = ''; /** * Images collection * * optional * * @var object[] * @since 1.7.0 */ private $_images = []; /** * The url collection * * @var array * @since 1.7.0 */ private $_urls = []; /** * Class constructor * * @param array $options Associative array of options * * @since 1.7.0 */ public function __construct($options = []) { parent::__construct($options); // Set document type $this->_type = 'opensearch'; // Set mime type $this->_mime = 'application/opensearchdescription+xml'; // Add the URL for self updating $update = new OpensearchUrl(); $update->type = 'application/opensearchdescription+xml'; $update->rel = 'self'; $update->template = Route::_(Uri::getInstance()); $this->addUrl($update); // Add the favicon as the default image // Try to find a favicon by checking the template and root folder $app = Factory::getApplication(); $dirs = [JPATH_THEMES . '/' . $app->getTemplate(), JPATH_BASE]; foreach ($dirs as $dir) { if (is_file($dir . '/favicon.ico')) { $path = str_replace(JPATH_BASE, '', $dir); $path = str_replace('\\', '/', $path); $favicon = new OpensearchImage(); if ($path == '') { $favicon->data = Uri::base() . 'favicon.ico'; } else { if ($path[0] == '/') { $path = substr($path, 1); } $favicon->data = Uri::base() . $path . '/favicon.ico'; } $favicon->height = '16'; $favicon->width = '16'; $favicon->type = 'image/vnd.microsoft.icon'; $this->addImage($favicon); break; } } } /** * Render the document * * @param boolean $cache If true, cache the output * @param array $params Associative array of attributes * * @return string The rendered data * * @since 1.7.0 */ public function render($cache = false, $params = []) { $xml = new \DOMDocument('1.0', 'utf-8'); if (\defined('JDEBUG') && JDEBUG) { $xml->formatOutput = true; } // The Opensearch Namespace $osns = 'http://a9.com/-/spec/opensearch/1.1/'; // Create the root element $elOs = $xml->createElementNS($osns, 'OpenSearchDescription'); $elShortName = $xml->createElementNS($osns, 'ShortName'); $elShortName->appendChild($xml->createTextNode(htmlspecialchars($this->_shortName))); $elOs->appendChild($elShortName); $elDescription = $xml->createElementNS($osns, 'Description'); $elDescription->appendChild($xml->createTextNode(htmlspecialchars($this->description))); $elOs->appendChild($elDescription); // Always set the accepted input encoding to UTF-8 $elInputEncoding = $xml->createElementNS($osns, 'InputEncoding'); $elInputEncoding->appendChild($xml->createTextNode('UTF-8')); $elOs->appendChild($elInputEncoding); foreach ($this->_images as $image) { $elImage = $xml->createElementNS($osns, 'Image'); $elImage->setAttribute('type', $image->type); $elImage->setAttribute('width', $image->width); $elImage->setAttribute('height', $image->height); $elImage->appendChild($xml->createTextNode(htmlspecialchars($image->data))); $elOs->appendChild($elImage); } foreach ($this->_urls as $url) { $elUrl = $xml->createElementNS($osns, 'Url'); $elUrl->setAttribute('type', $url->type); // Results is the default value so we don't need to add it if ($url->rel !== 'results') { $elUrl->setAttribute('rel', $url->rel); } $elUrl->setAttribute('template', $url->template); $elOs->appendChild($elUrl); } $xml->appendChild($elOs); parent::render($cache, $params); return $xml->saveXML(); } /** * Sets the short name * * @param string $name The name. * * @return OpensearchDocument instance of $this to allow chaining * * @since 1.7.0 */ public function setShortName($name) { $this->_shortName = $name; return $this; } /** * Adds a URL to the Opensearch description. * * @param OpensearchUrl $url The url to add to the description. * * @return OpensearchDocument instance of $this to allow chaining * * @since 1.7.0 */ public function addUrl(OpensearchUrl $url) { $this->_urls[] = $url; return $this; } /** * Adds an image to the Opensearch description. * * @param OpensearchImage $image The image to add to the description. * * @return OpensearchDocument instance of $this to allow chaining * * @since 1.7.0 */ public function addImage(OpensearchImage $image) { $this->_images[] = $image; return $this; } } Factory.php 0000644 00000006435 15172704423 0006701 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; use Joomla\CMS\Cache\CacheControllerFactoryAwareInterface; use Joomla\CMS\Cache\CacheControllerFactoryAwareTrait; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Default factory for creating Document objects * * @since 4.0.0 */ class Factory implements FactoryInterface { use CacheControllerFactoryAwareTrait; /** * Creates a new Document object for the requested format. * * @param string $type The document type to instantiate * @param array $attributes Array of attributes * * @return Document * * @since 4.0.0 */ public function createDocument(string $type = 'html', array $attributes = []): Document { $type = preg_replace('/[^A-Z0-9_\.-]/i', '', $type); $ntype = null; $class = __NAMESPACE__ . '\\' . ucfirst($type) . 'Document'; if (!class_exists($class)) { $class = 'JDocument' . ucfirst($type); } if (!class_exists($class)) { $ntype = $type; $class = RawDocument::class; } // Inject this factory into the document unless one was provided if (!isset($attributes['factory'])) { $attributes['factory'] = $this; } /** @var Document $instance */ $instance = new $class($attributes); if (!\is_null($ntype)) { // Set the type to the Document type originally requested $instance->setType($ntype); } if ($instance instanceof CacheControllerFactoryAwareInterface) { $instance->setCacheControllerFactory($this->getCacheControllerFactory()); } return $instance; } /** * Creates a new renderer object. * * @param Document $document The Document instance to attach to the renderer * @param string $type The renderer type to instantiate * @param string $docType The document type the renderer is part of * * @return RendererInterface * * @since 4.0.0 */ public function createRenderer(Document $document, string $type, string $docType = ''): RendererInterface { $docType = $docType ? ucfirst($docType) : ucfirst($document->getType()); // Determine the path and class $class = __NAMESPACE__ . '\\Renderer\\' . $docType . '\\' . ucfirst($type) . 'Renderer'; if (!class_exists($class)) { $class = 'JDocumentRenderer' . $docType . ucfirst($type); } if (!class_exists($class)) { // "Legacy" class name structure $class = '\\JDocumentRenderer' . $type; if (!class_exists($class)) { throw new \RuntimeException(sprintf('Unable to load renderer class %s', $type), 500); } } $instance = new $class($document); if ($instance instanceof CacheControllerFactoryAwareInterface) { $instance->setCacheControllerFactory($this->getCacheControllerFactory()); } return $instance; } } ImageDocument.php 0000644 00000003364 15172704423 0010011 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; use Joomla\CMS\Factory; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * ImageDocument class, provides an easy interface to output image data * * @since 3.0.0 */ class ImageDocument extends Document { /** * Class constructor * * @param array $options Associative array of options * * @since 3.0.0 */ public function __construct($options = []) { parent::__construct($options); // Set mime type $this->_mime = 'image/png'; // Set document type $this->_type = 'image'; } /** * Render the document. * * @param boolean $cache If true, cache the output * @param array $params Associative array of attributes * * @return string The rendered data * * @since 3.0.0 */ public function render($cache = false, $params = []) { // Get the image type $type = Factory::getApplication()->getInput()->get('type', 'png'); switch ($type) { case 'jpg': case 'jpeg': $this->_mime = 'image/jpeg'; break; case 'gif': $this->_mime = 'image/gif'; break; case 'png': default: $this->_mime = 'image/png'; break; } $this->_charset = null; parent::render($cache, $params); return $this->getBuffer(); } } Document.php 0000644 00000072323 15172704424 0007050 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; use Joomla\Application\AbstractWebApplication; use Joomla\CMS\Date\Date; use Joomla\CMS\Factory as CmsFactory; use Joomla\CMS\WebAsset\WebAssetManager; use Symfony\Component\WebLink\HttpHeaderSerializer; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * Document class, provides an easy interface to parse and display a document * * @since 1.7.0 */ class Document { /** * Document title * * @var string * @since 1.7.0 */ public $title = ''; /** * Document description * * @var string * @since 1.7.0 */ public $description = ''; /** * Document full URL * * @var string * @since 1.7.0 */ public $link = ''; /** * Document base URL * * @var string * @since 1.7.0 */ public $base = ''; /** * Contains the document language setting * * @var string * @since 1.7.0 */ public $language = 'en-gb'; /** * Contains the document direction setting * * @var string * @since 1.7.0 */ public $direction = 'ltr'; /** * Document generator * * @var string * @since 1.7.0 */ public $_generator = 'Joomla! - Open Source Content Management'; /** * Document modified date * * @var string|Date * @since 1.7.0 */ public $_mdate = ''; /** * Tab string * * @var string * @since 1.7.0 */ public $_tab = "\11"; /** * Contains the line end string * * @var string * @since 1.7.0 */ public $_lineEnd = "\12"; /** * Contains the character encoding string * * @var string * @since 1.7.0 */ public $_charset = 'utf-8'; /** * Document mime type * * @var string * @since 1.7.0 */ public $_mime = ''; /** * Document namespace * * @var string * @since 1.7.0 */ public $_namespace = ''; /** * Document profile * * @var string * @since 1.7.0 */ public $_profile = ''; /** * Array of linked scripts * * @var array * @since 1.7.0 * * @deprecated 4.3 will be removed in 6.0 * Use WebAssetManager */ public $_scripts = []; /** * Array of scripts placed in the header * * @var array * @since 1.7.0 * * @deprecated 4.3 will be removed in 6.0 * Use WebAssetManager */ public $_script = []; /** * Array of scripts options * * @var array */ protected $scriptOptions = []; /** * Array of linked style sheets * * @var array * @since 1.7.0 * * @deprecated 4.3 will be removed in 6.0 * Use WebAssetManager */ public $_styleSheets = []; /** * Array of included style declarations * * @var array * @since 1.7.0 * * @deprecated 4.3 will be removed in 6.0 * Use WebAssetManager */ public $_style = []; /** * Array of meta tags * * @var array * @since 1.7.0 */ public $_metaTags = []; /** * The rendering engine * * @var object * @since 1.7.0 */ public $_engine = null; /** * The document type * * @var string * @since 1.7.0 */ public $_type = null; /** * Array of buffered output * * @var mixed (depends on the renderer) * @since 1.7.0 */ public static $_buffer = null; /** * Document instances container. * * @var array * @since 1.7.3 */ protected static $instances = []; /** * Media version added to assets * * @var string * @since 3.2 */ protected $mediaVersion = null; /** * Factory for creating JDocument API objects * * @var FactoryInterface * @since 4.0.0 */ protected $factory; /** * Preload manager * * @var PreloadManagerInterface * @since 4.0.0 */ protected $preloadManager = null; /** * The supported preload types * * @var array * @since 4.0.0 */ protected $preloadTypes = ['preload', 'dns-prefetch', 'preconnect', 'prefetch', 'prerender']; /** * Web Asset instance * * @var WebAssetManager * @since 4.0.0 */ protected $webAssetManager = null; /** * Class constructor. * * @param array $options Associative array of options * * @since 1.7.0 */ public function __construct($options = []) { if (\array_key_exists('lineend', $options)) { $this->setLineEnd($options['lineend']); } if (\array_key_exists('charset', $options)) { $this->setCharset($options['charset']); } if (\array_key_exists('language', $options)) { $this->setLanguage($options['language']); } if (\array_key_exists('direction', $options)) { $this->setDirection($options['direction']); } if (\array_key_exists('tab', $options)) { $this->setTab($options['tab']); } if (\array_key_exists('link', $options)) { $this->setLink($options['link']); } if (\array_key_exists('base', $options)) { $this->setBase($options['base']); } if (\array_key_exists('mediaversion', $options)) { $this->setMediaVersion($options['mediaversion']); } if (\array_key_exists('factory', $options)) { $this->setFactory($options['factory']); } else { $this->setFactory(new Factory()); } if (\array_key_exists('preloadManager', $options)) { $this->setPreloadManager($options['preloadManager']); } else { $this->setPreloadManager(new PreloadManager()); } if (\array_key_exists('webAssetManager', $options)) { $this->setWebAssetManager($options['webAssetManager']); } else { $webAssetManager = new WebAssetManager(\Joomla\CMS\Factory::getContainer()->get('webassetregistry')); $this->setWebAssetManager($webAssetManager); } } /** * Returns the global Document object, only creating it * if it doesn't already exist. * * @param string $type The document type to instantiate * @param array $attributes Array of attributes * * @return static The document object. * * @since 1.7.0 * * @deprecated 4.3 will be removed in 6.0 * Use the \Joomla\CMS\Document\FactoryInterface instead * Example: Factory::getApplication()->getDocument(); */ public static function getInstance($type = 'html', $attributes = []) { $signature = serialize([$type, $attributes]); if (empty(self::$instances[$signature])) { self::$instances[$signature] = CmsFactory::getContainer()->get(FactoryInterface::class)->createDocument($type, $attributes); } return self::$instances[$signature]; } /** * Set the factory instance * * @param FactoryInterface $factory The factory instance * * @return Document * * @since 4.0.0 */ public function setFactory(FactoryInterface $factory): self { $this->factory = $factory; return $this; } /** * Set the document type * * @param string $type Type document is to set to * * @return Document instance of $this to allow chaining * * @since 1.7.0 */ public function setType($type) { $this->_type = $type; return $this; } /** * Returns the document type * * @return string * * @since 1.7.0 */ public function getType() { return $this->_type; } /** * Get the contents of the document buffer * * @return mixed * * @since 1.7.0 */ public function getBuffer() { return self::$_buffer; } /** * Set the contents of the document buffer * * @param string $content The content to be set in the buffer. * @param array $options Array of optional elements. * * @return Document instance of $this to allow chaining * * @since 1.7.0 */ public function setBuffer($content, $options = []) { self::$_buffer = $content; return $this; } /** * Gets a meta tag. * * @param string $name Name of the meta HTML tag * @param string $attribute Attribute to use in the meta HTML tag * * @return string * * @since 1.7.0 */ public function getMetaData($name, $attribute = 'name') { // B/C old http_equiv parameter. if (!\is_string($attribute)) { $attribute = $attribute == true ? 'http-equiv' : 'name'; } if ($name === 'generator') { $result = $this->getGenerator(); } elseif ($name === 'description') { $result = $this->getDescription(); } else { $result = isset($this->_metaTags[$attribute]) && isset($this->_metaTags[$attribute][$name]) ? $this->_metaTags[$attribute][$name] : ''; } return $result; } /** * Sets or alters a meta tag. * * @param string $name Name of the meta HTML tag * @param mixed $content Value of the meta HTML tag as array or string * @param string $attribute Attribute to use in the meta HTML tag * * @return Document instance of $this to allow chaining * * @since 1.7.0 */ public function setMetaData($name, $content, $attribute = 'name') { // Pop the element off the end of array if target function expects a string or this http_equiv parameter. if (\is_array($content) && (\in_array($name, ['generator', 'description']) || !\is_string($attribute))) { $content = array_pop($content); } // B/C old http_equiv parameter. if (!\is_string($attribute)) { $attribute = $attribute == true ? 'http-equiv' : 'name'; } if ($name === 'generator') { $this->setGenerator($content); } elseif ($name === 'description') { $this->setDescription($content); } else { $this->_metaTags[$attribute][$name] = $content; } return $this; } /** * Adds a linked script to the page * * @param string $url URL to the linked script. * @param array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9', 'preload' => array('preload')) * @param array $attribs Array of attributes. Example: array('id' => 'scriptid', 'async' => 'async', 'data-test' => 1) * * @return Document instance of $this to allow chaining * * @since 1.7.0 * * @deprecated 4.3 will be removed in 6.0 * Use WebAssetManager * Example: $wa->registerAndUseScript(...); */ public function addScript($url, $options = [], $attribs = []) { // Default value for type. if (!isset($attribs['type']) && !isset($attribs['mime'])) { $attribs['type'] = 'text/javascript'; } $this->_scripts[$url] = isset($this->_scripts[$url]) ? array_replace($this->_scripts[$url], $attribs) : $attribs; $this->_scripts[$url]['options'] = isset($this->_scripts[$url]['options']) ? array_replace($this->_scripts[$url]['options'], $options) : $options; return $this; } /** * Adds a script to the page * * @param string $content Script * @param string $type Scripting mime (defaults to 'text/javascript') * * @return Document instance of $this to allow chaining * * @since 1.7.0 * * @deprecated 4.3 will be removed in 6.0 * Use WebAssetManager * Example: $wa->addInlineScript(...); */ public function addScriptDeclaration($content, $type = 'text/javascript') { $type = strtolower($type); if (empty($this->_script[$type])) { $this->_script[$type] = []; } $this->_script[$type][md5($content)] = $content; return $this; } /** * Add option for script * * @param string $key Name in Storage * @param mixed $options Scrip options as array or string * @param bool $merge Whether merge with existing (true) or replace (false) * * @return Document instance of $this to allow chaining * * @since 3.5 */ public function addScriptOptions($key, $options, $merge = true) { if (empty($this->scriptOptions[$key])) { $this->scriptOptions[$key] = []; } if ($merge && \is_array($options)) { $this->scriptOptions[$key] = array_replace_recursive($this->scriptOptions[$key], $options); } else { $this->scriptOptions[$key] = $options; } return $this; } /** * Get script(s) options * * @param string $key Name in Storage * * @return array Options for given $key, or all script options * * @since 3.5 */ public function getScriptOptions($key = null) { if ($key) { return (empty($this->scriptOptions[$key])) ? [] : $this->scriptOptions[$key]; } else { return $this->scriptOptions; } } /** * Adds a linked stylesheet to the page * * @param string $url URL to the linked style sheet * @param array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9', 'preload' => array('preload')) * @param array $attribs Array of attributes. Example: array('id' => 'stylesheet', 'data-test' => 1) * * @return Document instance of $this to allow chaining * * @since 1.7.0 * * @deprecated 4.3 will be removed in 6.0 * Use WebAssetManager * Example: $wa->registerAndUseStyle(...); */ public function addStyleSheet($url, $options = [], $attribs = []) { // Default value for type. if (!isset($attribs['type']) && !isset($attribs['mime'])) { $attribs['type'] = 'text/css'; } $this->_styleSheets[$url] = isset($this->_styleSheets[$url]) ? array_replace($this->_styleSheets[$url], $attribs) : $attribs; if (isset($this->_styleSheets[$url]['options'])) { $this->_styleSheets[$url]['options'] = array_replace($this->_styleSheets[$url]['options'], $options); } else { $this->_styleSheets[$url]['options'] = $options; } return $this; } /** * Adds a stylesheet declaration to the page * * @param string $content Style declarations * @param string $type Type of stylesheet (defaults to 'text/css') * * @return Document instance of $this to allow chaining * * @since 1.7.0 * * @deprecated 4.3 will be removed in 6.0 * Use WebAssetManager * Example: $wa->addInlineStyle(...); */ public function addStyleDeclaration($content, $type = 'text/css') { if ($content === null) { return $this; } $type = strtolower($type); if (empty($this->_style[$type])) { $this->_style[$type] = []; } $this->_style[$type][md5($content)] = $content; return $this; } /** * Sets the document charset * * @param string $type Charset encoding string * * @return Document instance of $this to allow chaining * * @since 1.7.0 */ public function setCharset($type = 'utf-8') { $this->_charset = $type; return $this; } /** * Returns the document charset encoding. * * @return string * * @since 1.7.0 */ public function getCharset() { return $this->_charset; } /** * Sets the global document language declaration. Default is English (en-gb). * * @param string $lang The language to be set * * @return Document instance of $this to allow chaining * * @since 1.7.0 */ public function setLanguage($lang = 'en-gb') { $this->language = strtolower($lang); return $this; } /** * Returns the document language. * * @return string * * @since 1.7.0 */ public function getLanguage() { return $this->language; } /** * Sets the global document direction declaration. Default is left-to-right (ltr). * * @param string $dir The language direction to be set * * @return Document instance of $this to allow chaining * * @since 1.7.0 */ public function setDirection($dir = 'ltr') { $this->direction = strtolower($dir); return $this; } /** * Returns the document direction declaration. * * @return string * * @since 1.7.0 */ public function getDirection() { return $this->direction; } /** * Sets the title of the document * * @param string $title The title to be set * * @return Document instance of $this to allow chaining * * @since 1.7.0 */ public function setTitle($title) { $this->title = $title; return $this; } /** * Return the title of the document. * * @return string * * @since 1.7.0 */ public function getTitle() { return $this->title; } /** * Set the assets version * * @param string $mediaVersion Media version to use * * @return Document instance of $this to allow chaining * * @since 3.2 */ public function setMediaVersion($mediaVersion) { $this->mediaVersion = strtolower($mediaVersion); return $this; } /** * Return the media version * * @return string * * @since 3.2 */ public function getMediaVersion() { return $this->mediaVersion; } /** * Set the preload manager * * @param PreloadManagerInterface $preloadManager The preload manager service * * @return Document instance of $this to allow chaining * * @since 4.0.0 */ public function setPreloadManager(PreloadManagerInterface $preloadManager): self { $this->preloadManager = $preloadManager; return $this; } /** * Return the preload manager * * @return PreloadManagerInterface * * @since 4.0.0 */ public function getPreloadManager(): PreloadManagerInterface { return $this->preloadManager; } /** * Set WebAsset manager * * @param WebAssetManager $webAsset The WebAsset instance * * @return Document * * @since 4.0.0 */ public function setWebAssetManager(WebAssetManager $webAsset): self { $this->webAssetManager = $webAsset; return $this; } /** * Return WebAsset manager * * @return WebAssetManager * * @since 4.0.0 */ public function getWebAssetManager(): WebAssetManager { return $this->webAssetManager; } /** * Sets the base URI of the document * * @param string $base The base URI to be set * * @return Document instance of $this to allow chaining * * @since 1.7.0 */ public function setBase($base) { $this->base = $base; return $this; } /** * Return the base URI of the document. * * @return string * * @since 1.7.0 */ public function getBase() { return $this->base; } /** * Sets the description of the document * * @param string $description The description to set * * @return Document instance of $this to allow chaining * * @since 1.7.0 */ public function setDescription($description) { $this->description = $description; return $this; } /** * Return the description of the document. * * @return string * * @since 1.7.0 */ public function getDescription() { return $this->description; } /** * Sets the document link * * @param string $url A url * * @return Document instance of $this to allow chaining * * @since 1.7.0 */ public function setLink($url) { $this->link = $url; return $this; } /** * Returns the document base url * * @return string * * @since 1.7.0 */ public function getLink() { return $this->link; } /** * Sets the document generator * * @param string $generator The generator to be set * * @return Document instance of $this to allow chaining * * @since 1.7.0 */ public function setGenerator($generator) { $this->_generator = $generator; return $this; } /** * Returns the document generator * * @return string * * @since 1.7.0 */ public function getGenerator() { return $this->_generator; } /** * Sets the document modified date * * @param string|Date $date The date to be set * * @return Document instance of $this to allow chaining * * @since 1.7.0 * @throws \InvalidArgumentException */ public function setModifiedDate($date) { if (!\is_string($date) && !($date instanceof Date)) { throw new \InvalidArgumentException( sprintf( 'The $date parameter of %1$s must be a string or a %2$s instance, a %3$s was given.', __METHOD__ . '()', 'Joomla\\CMS\\Date\\Date', \gettype($date) === 'object' ? (\get_class($date) . ' instance') : \gettype($date) ) ); } $this->_mdate = $date; return $this; } /** * Returns the document modified date * * @return string|Date * * @since 1.7.0 */ public function getModifiedDate() { return $this->_mdate; } /** * Sets the document MIME encoding that is sent to the browser. * * This usually will be text/html because most browsers cannot yet * accept the proper mime settings for XHTML: application/xhtml+xml * and to a lesser extent application/xml and text/xml. See the W3C note * ({@link https://www.w3.org/TR/xhtml-media-types/ * https://www.w3.org/TR/xhtml-media-types/}) for more details. * * @param string $type The document type to be sent * @param boolean $sync Should the type be synced with HTML? * * @return Document instance of $this to allow chaining * * @since 1.7.0 * * @link https://www.w3.org/TR/xhtml-media-types/ */ public function setMimeEncoding($type = 'text/html', $sync = true) { $this->_mime = strtolower($type); // Syncing with metadata if ($sync) { $this->setMetaData('content-type', $type . '; charset=' . $this->_charset, true); } return $this; } /** * Return the document MIME encoding that is sent to the browser. * * @return string * * @since 1.7.0 */ public function getMimeEncoding() { return $this->_mime; } /** * Sets the line end style to Windows, Mac, Unix or a custom string. * * @param string $style "win", "mac", "unix" or custom string. * * @return Document instance of $this to allow chaining * * @since 1.7.0 */ public function setLineEnd($style) { switch ($style) { case 'win': $this->_lineEnd = "\15\12"; break; case 'unix': $this->_lineEnd = "\12"; break; case 'mac': $this->_lineEnd = "\15"; break; default: $this->_lineEnd = $style; } return $this; } /** * Returns the lineEnd * * @return string * * @since 1.7.0 */ public function _getLineEnd() { return $this->_lineEnd; } /** * Sets the string used to indent HTML * * @param string $string String used to indent ("\11", "\t", ' ', etc.). * * @return Document instance of $this to allow chaining * * @since 1.7.0 */ public function setTab($string) { $this->_tab = $string; return $this; } /** * Returns a string containing the unit for indenting HTML * * @return string * * @since 1.7.0 */ public function _getTab() { return $this->_tab; } /** * Load a renderer * * @param string $type The renderer type * * @return RendererInterface * * @since 1.7.0 * @throws \RuntimeException */ public function loadRenderer($type) { return $this->factory->createRenderer($this, $type); } /** * Parses the document and prepares the buffers * * @param array $params The array of parameters * * @return Document instance of $this to allow chaining * * @since 1.7.0 */ public function parse($params = []) { return $this; } /** * Outputs the document * * @param boolean $cache If true, cache the output * @param array $params Associative array of attributes * * @return string The rendered data * * @since 1.7.0 */ public function render($cache = false, $params = []) { $app = CmsFactory::getApplication(); if ($mdate = $this->getModifiedDate()) { if (!($mdate instanceof Date)) { $mdate = new Date($mdate); } $app->modifiedDate = $mdate; } $app->mimeType = $this->_mime; $app->charSet = $this->_charset; // Handle preloading for configured assets in web applications if ($app instanceof AbstractWebApplication) { $this->preloadAssets(); } return ''; } /** * Generate the Link header for assets configured for preloading * * @return void * * @since 4.0.0 */ protected function preloadAssets() { // Process stylesheets first foreach ($this->_styleSheets as $link => $properties) { if (empty($properties['options']['preload'])) { continue; } foreach ($properties['options']['preload'] as $preloadMethod) { // Make sure the preload method is supported, special case for `dns-prefetch` to convert it to the right method name if ($preloadMethod === 'dns-prefetch') { $this->getPreloadManager()->dnsPrefetch($link); } elseif (\in_array($preloadMethod, $this->preloadTypes)) { $this->getPreloadManager()->$preloadMethod($link); } else { throw new \InvalidArgumentException(sprintf('The "%s" method is not supported for preloading.', $preloadMethod), 500); } } } // Now process scripts foreach ($this->_scripts as $link => $properties) { if (empty($properties['options']['preload'])) { continue; } foreach ($properties['options']['preload'] as $preloadMethod) { // Make sure the preload method is supported, special case for `dns-prefetch` to convert it to the right method name if ($preloadMethod === 'dns-prefetch') { $this->getPreloadManager()->dnsPrefetch($link); } elseif (\in_array($preloadMethod, $this->preloadTypes)) { $this->getPreloadManager()->$preloadMethod($link); } else { throw new \InvalidArgumentException(sprintf('The "%s" method is not supported for preloading.', $preloadMethod), 500); } } } // Check if the manager's provider has links, if so add the Link header if ($links = $this->getPreloadManager()->getLinkProvider()->getLinks()) { CmsFactory::getApplication()->setHeader('Link', (new HttpHeaderSerializer())->serialize($links)); } } } PartialDocument.php 0000604 00000056742 15172704424 0010370 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; defined('JPATH_PLATFORM') or die; use Joomla\CMS\Cache\Cache; use Joomla\CMS\Helper\ModuleHelper; use Joomla\CMS\Log\Log; use Joomla\CMS\Uri\Uri; use Joomla\Registry\Registry; use Joomla\CMS\Factory; jimport('joomla.utilities.utility'); /** * HtmlDocument class, provides an easy interface to parse and display a HTML document * * @since 11.1 */ class PartialDocument extends Document { /** * Array of Header `<link>` tags * * @var array * @since 11.1 */ public $_links = array(); /** * Array of custom tags * * @var array * @since 11.1 */ public $_custom = array(); /** * Name of the template * * @var string * @since 11.1 */ public $template = null; /** * Base url * * @var string * @since 11.1 */ public $baseurl = null; /** * Array of template parameters * * @var array * @since 11.1 */ public $params = null; /** * File name * * @var array * @since 11.1 */ public $_file = null; /** * String holding parsed template * * @var string * @since 11.1 */ protected $_template = ''; /** * Array of parsed template JDoc tags * * @var array * @since 11.1 */ protected $_template_tags = array(); /** * Integer with caching setting * * @var integer * @since 11.1 */ protected $_caching = null; /** * Set to true when the document should be output as HTML5 * * @var boolean * @since 12.1 * * @note 4.0 Will be replaced by $html5 and the default value will be true. */ private $_html5 = null; /** * Class constructor * * @param array $options Associative array of options * * @since 11.1 */ public function __construct($options = array()) { parent::__construct($options); // Set document type $this->_type = 'partial'; // Set default mime type and document metadata (meta data syncs with mime type by default) $this->setMimeEncoding('text/html'); } /** * Get the HTML document head data * * @return array The document head data in array form * * @since 11.1 */ public function getHeadData() { $data = array(); $data['title'] = $this->title; $data['description'] = $this->description; $data['link'] = $this->link; $data['metaTags'] = $this->_metaTags; $data['links'] = $this->_links; $data['styleSheets'] = $this->_styleSheets; $data['style'] = $this->_style; $data['scripts'] = $this->_scripts; $data['script'] = $this->_script; $data['custom'] = $this->_custom; $data['scriptText'] = \JText::script(); return $data; } /** * Reset the HTML document head data * * @param mixed $types type or types of the heads elements to reset * * @return PartialDocument instance of $this to allow chaining * * @since 3.7.0 */ public function resetHeadData($types = null) { if (is_null($types)) { $this->title = ''; $this->description = ''; $this->link = ''; $this->_metaTags = array(); $this->_links = array(); $this->_styleSheets = array(); $this->_style = array(); $this->_scripts = array(); $this->_script = array(); $this->_custom = array(); } if (is_array($types)) { foreach ($types as $type) { $this->resetHeadDatum($type); } } if (is_string($types)) { $this->resetHeadDatum($types); } return $this; } /** * Reset a part the HTML document head data * * @param string $type type of the heads elements to reset * * @return void * * @since 3.7.0 */ private function resetHeadDatum($type) { switch ($type) { case 'title': case 'description': case 'link': $this->{$type} = ''; break; case 'metaTags': case 'links': case 'styleSheets': case 'style': case 'scripts': case 'script': case 'custom': $realType = '_' . $type; $this->{$realType} = array(); break; } } /** * Set the HTML document head data * * @param array $data The document head data in array form * * @return HtmlDocument|null instance of $this to allow chaining or null for empty input data * * @since 11.1 */ public function setHeadData($data) { if (empty($data) || !is_array($data)) { return; } $this->title = (isset($data['title']) && !empty($data['title'])) ? $data['title'] : $this->title; $this->description = (isset($data['description']) && !empty($data['description'])) ? $data['description'] : $this->description; $this->link = (isset($data['link']) && !empty($data['link'])) ? $data['link'] : $this->link; $this->_metaTags = (isset($data['metaTags']) && !empty($data['metaTags'])) ? $data['metaTags'] : $this->_metaTags; $this->_links = (isset($data['links']) && !empty($data['links'])) ? $data['links'] : $this->_links; $this->_styleSheets = (isset($data['styleSheets']) && !empty($data['styleSheets'])) ? $data['styleSheets'] : $this->_styleSheets; $this->_style = (isset($data['style']) && !empty($data['style'])) ? $data['style'] : $this->_style; $this->_scripts = (isset($data['scripts']) && !empty($data['scripts'])) ? $data['scripts'] : $this->_scripts; $this->_script = (isset($data['script']) && !empty($data['script'])) ? $data['script'] : $this->_script; $this->_custom = (isset($data['custom']) && !empty($data['custom'])) ? $data['custom'] : $this->_custom; if (isset($data['scriptText']) && !empty($data['scriptText'])) { foreach ($data['scriptText'] as $key => $string) { \JText::script($key, $string); } } return $this; } /** * Merge the HTML document head data * * @param array $data The document head data in array form * * @return PartialDocument|null instance of $this to allow chaining or null for empty input data * * @since 11.1 */ public function mergeHeadData($data) { if (empty($data) || !is_array($data)) { return; } $this->title = (isset($data['title']) && !empty($data['title']) && !stristr($this->title, $data['title'])) ? $this->title . $data['title'] : $this->title; $this->description = (isset($data['description']) && !empty($data['description']) && !stristr($this->description, $data['description'])) ? $this->description . $data['description'] : $this->description; $this->link = (isset($data['link'])) ? $data['link'] : $this->link; if (isset($data['metaTags'])) { foreach ($data['metaTags'] as $type1 => $data1) { $booldog = $type1 == 'http-equiv' ? true : false; foreach ($data1 as $name2 => $data2) { $this->setMetaData($name2, $data2, $booldog); } } } $this->_links = (isset($data['links']) && !empty($data['links']) && is_array($data['links'])) ? array_unique(array_merge($this->_links, $data['links']), SORT_REGULAR) : $this->_links; $this->_styleSheets = (isset($data['styleSheets']) && !empty($data['styleSheets']) && is_array($data['styleSheets'])) ? array_merge($this->_styleSheets, $data['styleSheets']) : $this->_styleSheets; if (isset($data['style'])) { foreach ($data['style'] as $type => $stdata) { if (!isset($this->_style[strtolower($type)]) || !stristr($this->_style[strtolower($type)], $stdata)) { $this->addStyleDeclaration($stdata, $type); } } } $this->_scripts = (isset($data['scripts']) && !empty($data['scripts']) && is_array($data['scripts'])) ? array_merge($this->_scripts, $data['scripts']) : $this->_scripts; if (isset($data['script'])) { foreach ($data['script'] as $type => $sdata) { if (!isset($this->_script[strtolower($type)]) || !stristr($this->_script[strtolower($type)], $sdata)) { $this->addScriptDeclaration($sdata, $type); } } } $this->_custom = (isset($data['custom']) && !empty($data['custom']) && is_array($data['custom'])) ? array_unique(array_merge($this->_custom, $data['custom'])) : $this->_custom; return $this; } /** * Adds `<link>` tags to the head of the document * * $relType defaults to 'rel' as it is the most common relation type used. * ('rev' refers to reverse relation, 'rel' indicates normal, forward relation.) * Typical tag: `<link href="index.php" rel="Start">` * * @param string $href The link that is being related. * @param string $relation Relation of link. * @param string $relType Relation type attribute. Either rel or rev (default: 'rel'). * @param array $attribs Associative array of remaining attributes. * * @return PartialDocument instance of $this to allow chaining * * @since 11.1 */ public function addHeadLink($href, $relation, $relType = 'rel', $attribs = array()) { $this->_links[$href]['relation'] = $relation; $this->_links[$href]['relType'] = $relType; $this->_links[$href]['attribs'] = $attribs; return $this; } /** * Adds a shortcut icon (favicon) * * This adds a link to the icon shown in the favorites list or on * the left of the url in the address bar. Some browsers display * it on the tab, as well. * * @param string $href The link that is being related. * @param string $type File type * @param string $relation Relation of link * * @return PartialDocument instance of $this to allow chaining * * @since 11.1 */ public function addFavicon($href, $type = 'image/vnd.microsoft.icon', $relation = 'shortcut icon') { $href = str_replace('\\', '/', $href); $this->addHeadLink($href, $relation, 'rel', array('type' => $type)); return $this; } /** * Adds a custom HTML string to the head block * * @param string $html The HTML to add to the head * * @return PartialDocument instance of $this to allow chaining * * @since 11.1 */ public function addCustomTag($html) { $this->_custom[] = trim($html); return $this; } /** * Returns whether the document is set up to be output as HTML5 * * @return boolean true when HTML5 is used * * @since 12.1 */ public function isHtml5() { return $this->_html5; } /** * Sets whether the document should be output as HTML5 * * @param bool $state True when HTML5 should be output * * @return void * * @since 12.1 */ public function setHtml5($state) { if (is_bool($state)) { $this->_html5 = $state; } } /** * Get the contents of a document include * * @param string $type The type of renderer * @param string $name The name of the element to render * @param array $attribs Associative array of remaining attributes. * * @return mixed|string The output of the renderer * * @since 11.1 */ public function getBuffer($type = null, $name = null, $attribs = array()) { // If no type is specified, return the whole buffer if ($type === null) { return parent::$_buffer; } $title = (isset($attribs['title'])) ? $attribs['title'] : null; if (isset(parent::$_buffer[$type][$name][$title])) { return parent::$_buffer[$type][$name][$title]; } $renderer = $this->loadRenderer($type); if ($this->_caching == true && $type == 'modules') { $cache = \JFactory::getCache('com_modules', ''); $hash = md5(serialize(array($name, $attribs, null, $renderer))); $cbuffer = $cache->get('cbuffer_' . $type); if (isset($cbuffer[$hash])) { return Cache::getWorkarounds($cbuffer[$hash], array('mergehead' => 1)); } else { $options = array(); $options['nopathway'] = 1; $options['nomodules'] = 1; $options['modulemode'] = 1; $this->setBuffer($renderer->render($name, $attribs, null), $type, $name); $data = parent::$_buffer[$type][$name][$title]; $tmpdata = Cache::setWorkarounds($data, $options); $cbuffer[$hash] = $tmpdata; $cache->store($cbuffer, 'cbuffer_' . $type); } } else { $this->setBuffer($renderer->render($name, $attribs, null), $type, $name, $title); } return parent::$_buffer[$type][$name][$title]; } /** * Set the contents a document includes * * @param string $content The content to be set in the buffer. * @param array $options Array of optional elements. * * @return PartialDocument instance of $this to allow chaining * * @since 11.1 */ public function setBuffer($content, $options = array()) { // The following code is just for backward compatibility. if (func_num_args() > 1 && !is_array($options)) { $args = func_get_args(); $options = array(); $options['type'] = $args[1]; $options['name'] = (isset($args[2])) ? $args[2] : null; $options['title'] = (isset($args[3])) ? $args[3] : null; } parent::$_buffer[$options['type']][$options['name']][$options['title']] = $content; return $this; } /** * Parses the template and populates the buffer * * @param array $params Parameters for fetching the template * * @return PartialDocument instance of $this to allow chaining * * @since 11.1 */ public function parse($params = array()) { return $this->_fetchTemplate($params)->_parseTemplate(); } /** * Outputs the template to the browser. * * @param boolean $caching If true, cache the output * @param array $params Associative array of attributes * * @return string The rendered data * * @since 11.1 */ public function render($caching = false, $params = array()) { $this->_caching = $caching; if (empty($this->_template)) { $this->parse($params); } $data = $this->_renderTemplate(); parent::render(); return $data; } /** * Count the modules based on the given condition * * @param string $condition The condition to use * * @return integer Number of modules found * * @since 11.1 */ public function countModules($condition) { $operators = '(\+|\-|\*|\/|==|\!=|\<\>|\<|\>|\<=|\>=|and|or|xor)'; $words = preg_split('# ' . $operators . ' #', $condition, null, PREG_SPLIT_DELIM_CAPTURE); if (count($words) === 1) { $name = strtolower($words[0]); $result = ((isset(parent::$_buffer['modules'][$name])) && (parent::$_buffer['modules'][$name] === false)) ? 0 : count(ModuleHelper::getModules($name)); return $result; } Log::add('Using an expression in PartialDocument::countModules() is deprecated.', Log::WARNING, 'deprecated'); for ($i = 0, $n = count($words); $i < $n; $i += 2) { // Odd parts (modules) $name = strtolower($words[$i]); $words[$i] = ((isset(parent::$_buffer['modules'][$name])) && (parent::$_buffer['modules'][$name] === false)) ? 0 : count(ModuleHelper::getModules($name)); } $str = 'return ' . implode(' ', $words) . ';'; return eval($str); } /** * Count the number of child menu items of the current active menu item * * @return integer Number of child menu items * * @since 11.1 */ public function countMenuChildren() { static $children; if (!isset($children)) { $db = \JFactory::getDbo(); $app = \JFactory::getApplication(); $menu = $app->getMenu(); $active = $menu->getActive(); $children = 0; if ($active) { $query = $db->getQuery(true) ->select('COUNT(*)') ->from('#__menu') ->where('parent_id = ' . $active->id) ->where('published = 1'); $db->setQuery($query); $children = $db->loadResult(); } } return $children; } /** * Load a template file * * @param string $directory The name of the template * @param string $filename The actual filename * * @return string The contents of the template * * @since 11.1 */ protected function _loadTemplate($directory, $filename) { $contents = ''; // Check to see if we have a valid template file if (file_exists($directory . '/' . $filename)) { // Store the file path $this->_file = $directory . '/' . $filename; // Get the file content ob_start(); require $directory . '/' . $filename; $contents = ob_get_contents(); ob_end_clean(); } // Try to find a favicon by checking the template and root folder $icon = '/favicon.ico'; foreach (array($directory, JPATH_BASE) as $dir) { if (file_exists($dir . $icon)) { $path = str_replace(JPATH_BASE, '', $dir); $path = str_replace('\\', '/', $path); $this->addFavicon(Uri::base(true) . $path . $icon); break; } } return $contents; } /** * Fetch the template, and initialise the params * * @param array $params Parameters to determine the template * * @return PartialDocument instance of $this to allow chaining * * @since 11.1 */ protected function _fetchTemplate($params = array()) { // Check $directory = isset($params['directory']) ? $params['directory'] : 'templates'; $filter = \JFilterInput::getInstance(); $template = $filter->clean($params['template'], 'cmd'); $file = $filter->clean($params['file'], 'cmd'); if (!file_exists($directory . '/' . $template . '/' . $file)) { $template = 'system'; } if (!file_exists($directory . '/' . $template . '/' . $file)) { $file = 'index.php'; } // Load the language file for the template $lang = \JFactory::getLanguage(); // 1.5 or core then 1.6 $lang->load('tpl_' . $template, JPATH_BASE, null, false, true) || $lang->load('tpl_' . $template, $directory . '/' . $template, null, false, true); // Assign the variables $this->template = $template; $this->baseurl = Uri::base(true); $this->params = isset($params['params']) ? $params['params'] : new Registry; // Load $this->_template = $this->_loadTemplate($directory . '/' . $template, $file); return $this; } /** * Parse a document template * * @return PartialDocument instance of $this to allow chaining * * @since 11.1 */ protected function _parseTemplate() { $matches = array(); if (preg_match_all('#<jdoc:include\ type="([^"]+)"(.*)\/>#iU', $this->_template, $matches)) { $template_tags_first = array(); $template_tags_last = array(); // Step through the jdocs in reverse order. for ($i = count($matches[0]) - 1; $i >= 0; $i--) { $type = $matches[1][$i]; $attribs = empty($matches[2][$i]) ? array() : \JUtility::parseAttributes($matches[2][$i]); $name = isset($attribs['name']) ? $attribs['name'] : null; // Separate buffers to be executed first and last if ($type == 'module' || $type == 'modules') { $template_tags_first[$matches[0][$i]] = array('type' => $type, 'name' => $name, 'attribs' => $attribs); } else { $template_tags_last[$matches[0][$i]] = array('type' => $type, 'name' => $name, 'attribs' => $attribs); } } // Reverse the last array so the jdocs are in forward order. $template_tags_last = array_reverse($template_tags_last); $this->_template_tags = $template_tags_first + $template_tags_last; } return $this; } /** * Render pre-parsed template * * @return string rendered template * * @since 11.1 */ protected function _renderTemplate() { $replace = array(); $with = array(); foreach ($this->_template_tags as $jdoc => $args) { $replace[] = $jdoc; $with[] = $this->getBuffer($args['type'], $args['name'], $args['attribs']); } return str_replace($replace, $with, $this->_template); } } Opensearch/OpensearchUrl.php 0000644 00000001664 15172704424 0012133 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Opensearch; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * Data object representing an OpenSearch URL * * @since 1.7.0 */ class OpensearchUrl { /** * Type item element * * required * * @var string * @since 1.7.0 */ public $type = 'text/html'; /** * Rel item element * * required * * @var string * @since 1.7.0 */ public $rel = 'results'; /** * Template item element. Has to contain the {searchTerms} parameter to work. * * required * * @var string * @since 1.7.0 */ public $template; } Opensearch/OpensearchImage.php 0000644 00000002035 15172704424 0012404 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Opensearch; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * Data object representing an OpenSearch image * * @since 1.7.0 */ class OpensearchImage { /** * The images MIME type * * required * * @var string * @since 1.7.0 */ public $type = ''; /** * URL of the image or the image as base64 encoded value * * required * * @var string * @since 1.7.0 */ public $data = ''; /** * The image's width * * required * * @var string * @since 1.7.0 */ public $width; /** * The image's height * * required * * @var string * @since 1.7.0 */ public $height; } PdfDocument.php 0000604 00000015321 15172704424 0007471 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; defined('JPATH_PLATFORM') or die; //require_once JPATH_SITE . '/components/com_fabrik/helpers/pdf.php'; use Fabrik\Helpers\Pdf; jimport('joomla.utilities.utility'); /** * PdfDocument class, provides an easy interface to parse and display a PDF document * * @since 11.1 */ class PdfDocument extends HtmlDocument { /** * Array of Header `<link>` tags * * @var array * @since 11.1 */ public $_links = array(); /** * Array of custom tags * * @var array * @since 11.1 */ public $_custom = array(); /** * Name of the template * * @var string * @since 11.1 */ public $template = null; /** * Base url * * @var string * @since 11.1 */ public $baseurl = null; /** * Array of template parameters * * @var array * @since 11.1 */ public $params = null; /** * File name * * @var array * @since 11.1 */ public $_file = null; /** * String holding parsed template * * @var string * @since 11.1 */ protected $_template = ''; /** * Array of parsed template JDoc tags * * @var array * @since 11.1 */ protected $_template_tags = array(); /** * Integer with caching setting * * @var integer * @since 11.1 */ protected $_caching = null; /** * Set to true when the document should be output as HTML5 * * @var boolean * @since 12.1 * * @note 4.0 Will be replaced by $html5 and the default value will be true. */ private $_html5 = null; /** * Fabrik config * * @var null */ protected $config = null; /** * Orientation * * @var string */ private $orientation = 'P'; /** * Paper size * * @var string */ private $size = 'A4'; /** * Class constructor * * @param array $options Associative array of options * * @since 11.1 */ public function __construct($options = array()) { parent::__construct($options); $this->config = \JComponentHelper::getParams('com_fabrik'); if ($this->config->get('pdf_debug', false)) { $this->setMimeEncoding('text/html'); $this->_type = 'pdf'; } else { // Set mime type $this->_mime = 'application/pdf'; // Set document type $this->_type = 'pdf'; } $this->iniPdf(); } /** * Init selected PDF */ protected function iniPdf() { if ($this->config->get('fabrik_pdf_lib', 'dompdf') === 'dompdf') { if (!$this->iniDomPdf()) { throw new RuntimeException(FText::_('COM_FABRIK_NOTICE_DOMPDF_NOT_FOUND')); } } } /** * Set up DomPDF engine * * @return bool */ protected function iniDomPdf() { $this->engine = Pdf::iniDomPdf(true); return $this->engine; } /** * Set the paper size and orientation * Note if too small for content then the pdf renderer will bomb out in an infinite loop * Legal seems to be more lenient than a4 for example * If doing landscape set large paper size * * @param string $size Paper size E.g A4,legal * @param string $orientation Paper orientation landscape|portrait * * @since 3.0.7 * * @return void */ public function setPaper($size = 'A4', $orientation = 'landscape') { if ($this->config->get('fabrik_pdf_lib', 'dompdf') === 'dompdf') { $size = strtoupper($size); $this->engine->set_paper($size, $orientation); } else { $this->size = ucfirst($size); switch ($orientation) { case 'landscape': $this->orientation = 'L'; $this->size .= '-' . $this->orientation; break; case 'portrait': default: $this->orientation = 'P'; break; } } } /** * Sets the document name * * @param string $name Document name * * @return void */ public function setName($name = 'joomla') { $this->name = $name; } /** * Returns the document name * * @return string */ public function getName() { return $this->name; } /** * Render the document. * * @param boolean $cache If true, cache the output * @param array $params Associative array of attributes * * @return string */ public function render($cache = false, $params = array()) { // mb_encoding foo when content-type had been set to text/html; uft-8; $this->_metaTags['http-equiv'] = array(); $this->_metaTags['http-equiv']['content-type'] = 'text/html'; // Testing using futural font. // $this->addStyleDeclaration('body: { font-family: futural !important; }'); $data = parent::render(); Pdf::fullPaths($data); /** * I think we need this to handle some HTML entities when rendering otherlanguages (like Polish), * but haven't tested it much */ $data = mb_convert_encoding($data,'HTML-ENTITIES','UTF-8'); $config = \JComponentHelper::getParams('com_fabrik'); if ($this->config->get('fabrik_pdf_lib', 'dompdf') === 'dompdf') { $this->engine->load_html($data); if ($config->get('pdf_debug', false)) { return $this->engine->output_html(); } else { $this->engine->render(); $this->engine->stream($this->getName() . '.pdf'); } } else { if ($config->get('pdf_debug', false)) { return $data; } else { try { $mpdf = new \Mpdf\Mpdf( [ 'tempDir' => \JFactory::getConfig()->get('tmp_path', JPATH_ROOT . '/tmp'), 'mode' => 'utf-8', 'format' => $this->size, 'orientation' => $this->orientation ] ); //$mpdf->shrink_tables_to_fit = 1; $mpdf->use_kwt = true; $mpdf->WriteHTML($data); $mpdf->Output($this->getName() . '.pdf', \Mpdf\Output\Destination::INLINE); } catch (\Mpdf\MpdfException $e) { // mmmphh echo 'Error creating PDF: ' . ($e->getMessage()); } } } return ''; } /** * Get the contents of a document include * * @param string $type The type of renderer * @param string $name The name of the element to render * @param array $attribs Associative array of remaining attributes. * * @return The output of the renderer */ public function getBuffer($type = null, $name = null, $attribs = array()) { if ($type == 'head' || $type == 'component') { return parent::getBuffer($type, $name, $attribs); } else { return ''; } } } JsonapiDocument.php 0000644 00000010056 15172704424 0010367 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; use Joomla\CMS\Factory; use Tobscure\JsonApi\Document; use Tobscure\JsonApi\ElementInterface; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * JsonapiDocument class, provides an easy interface to parse output in JSON-API format. * * @link http://www.jsonapi.org/ * @since 4.0.0 */ class JsonapiDocument extends JsonDocument implements \JsonSerializable { /** * The JsonApi Document object. * * @var Document * @since 4.0.0 */ protected $document; /** * Class constructor. * * @param array $options Associative array of options * * @since 4.0.0 */ public function __construct($options = []) { parent::__construct($options); // Set mime type to JSON-API $this->_mime = 'application/vnd.api+json'; $this->_type = 'jsonapi'; if (\array_key_exists('api_document', $options) && $options['api_document'] instanceof Document) { $this->document = $options['api_document']; } else { $this->document = new Document(); } } /** * Set the data object. * * @param ElementInterface $element Element interface. * * @return $this * * @since 4.0.0 */ public function setData(ElementInterface $element) { $this->document->setData($element); return $this; } /** * Set the errors array. * * @param array $errors Error array. * * @return $this * * @since 4.0.0 */ public function setErrors($errors) { $this->document->setErrors($errors); return $this; } /** * Set the JSON-API array. * * @param array $jsonapi JSON-API array. * * @return $this * * @since 4.0.0 */ public function setJsonapi($jsonapi) { $this->document->setJsonapi($jsonapi); return $this; } /** * Map everything to arrays. * * @return array * * @since 4.0.0 */ public function toArray() { return $this->document->toArray(); } /** * Map to string. * * @return string * * @since 4.0.0 */ public function __toString() { return json_encode($this->toArray()); } /** * Outputs the document. * * @param boolean $cache If true, cache the output. * @param array $params Associative array of attributes. * * @return string The rendered data. * * @since 4.0.0 */ public function render($cache = false, $params = []) { $app = Factory::getApplication(); if ($mdate = $this->getModifiedDate()) { $app->modifiedDate = $mdate; } $app->mimeType = $this->_mime; $app->charSet = $this->_charset; return json_encode($this->document); } /** * Serialize for JSON usage. * * @return array * * @since 4.0.0 */ #[\ReturnTypeWillChange] public function jsonSerialize() { return $this->toArray(); } /** * Add a link to the output. * * @param string $key The name of the link * @param string $value The link * * @return $this * * @since 4.0.0 */ public function addLink($key, $value) { $this->document->addLink($key, $value); return $this; } /** * Add a link to the output. * * @param string $key The name of the metadata key * @param string $value The value * * @return $this * * @since 4.0.0 */ public function addMeta($key, $value) { $this->document->addMeta($key, $value); return $this; } } RendererInterface.php 0000644 00000001545 15172704424 0010657 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Interface for a document renderer * * @since 4.0.0 */ interface RendererInterface { /** * Renders a script and returns the results as a string * * @param string $name The name of the element to render * @param array $params Array of values * @param string $content Override the output of the renderer * * @return string The output of the script * * @since 4.0.0 */ public function render($name, $params = null, $content = null); } Feed/FeedItem.php 0000644 00000005007 15172704424 0007612 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Feed; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * Data object representing a feed item * * @since 1.7.0 */ class FeedItem { /** * Title item element * * required * * @var string * @since 1.7.0 */ public $title; /** * Link item element * * required * * @var string * @since 1.7.0 */ public $link; /** * Description item element * * required * * @var string * @since 1.7.0 */ public $description; /** * Author item element * * optional * * @var string * @since 1.7.0 */ public $author; /** * Author email element * * optional * * @var string * @since 1.7.0 */ public $authorEmail; /** * Category element * * optional * * @var array or string * @since 1.7.0 */ public $category; /** * Comments element * * optional * * @var string * @since 1.7.0 */ public $comments; /** * Enclosure element * * @var FeedEnclosure * @since 1.7.0 */ public $enclosure = null; /** * Guid element * * optional * * @var string * @since 1.7.0 */ public $guid; /** * Published date * * optional * * May be in one of the following formats: * * RFC 822: * "Mon, 20 Jan 03 18:05:41 +0400" * "20 Jan 03 18:05:41 +0000" * * ISO 8601: * "2003-01-20T18:05:41+04:00" * * Unix: * 1043082341 * * @var string * @since 1.7.0 */ public $date; /** * Source element * * optional * * @var string * @since 1.7.0 */ public $source; /** * Set the FeedEnclosure for this item * * @param FeedEnclosure $enclosure The FeedEnclosure to add to the feed. * * @return FeedItem instance of $this to allow chaining * * @since 1.7.0 */ public function setEnclosure(FeedEnclosure $enclosure) { $this->enclosure = $enclosure; return $this; } } Feed/FeedImage.php 0000644 00000002413 15172704424 0007734 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Feed; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * Data object representing a feed image * * @since 1.7.0 */ class FeedImage { /** * Title image attribute * * required * * @var string * @since 1.7.0 */ public $title = ''; /** * URL image attribute * * required * * @var string * @since 1.7.0 */ public $url = ''; /** * Link image attribute * * required * * @var string * @since 1.7.0 */ public $link = ''; /** * Width image attribute * * optional * * @var string * @since 1.7.0 */ public $width; /** * Title feed attribute * * optional * * @var string * @since 1.7.0 */ public $height; /** * Title feed attribute * * optional * * @var string * @since 1.7.0 */ public $description; } Feed/FeedEnclosure.php 0000644 00000001570 15172704424 0010654 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Feed; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * Data object representing a feed enclosure * * @since 1.7.0 */ class FeedEnclosure { /** * URL enclosure element * * required * * @var string * @since 1.7.0 */ public $url = ''; /** * Length enclosure element * * required * * @var string * @since 1.7.0 */ public $length = ''; /** * Type enclosure element * * required * * @var string * @since 1.7.0 */ public $type = ''; } FeedDocument.php 0000644 00000011726 15172704424 0007634 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; use Joomla\CMS\Document\Feed\FeedImage; use Joomla\CMS\Document\Feed\FeedItem; use Joomla\CMS\Factory as CmsFactory; use Joomla\CMS\Language\Text; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * FeedDocument class, provides an easy interface to parse and display any feed document * * @since 1.7.0 */ class FeedDocument extends Document { /** * Syndication URL feed element * * optional * * @var string * @since 1.7.0 */ public $syndicationURL = ''; /** * Image feed element * * optional * * @var FeedImage * @since 1.7.0 */ public $image = null; /** * Copyright feed element * * optional * * @var string * @since 1.7.0 */ public $copyright = ''; /** * Published date feed element * * optional * * @var string * @since 1.7.0 */ public $pubDate = ''; /** * Lastbuild date feed element * * @var \Joomla\CMS\Date\Date * @since 1.7.0 */ public $lastBuildDate; /** * Editor feed element * * optional * * @var string * @since 1.7.0 */ public $editor = ''; /** * Docs feed element * * @var string * @since 1.7.0 */ public $docs = ''; /** * Editor email feed element * * optional * * @var string * @since 1.7.0 */ public $editorEmail = ''; /** * Webmaster email feed element * * optional * * @var string * @since 1.7.0 */ public $webmaster = ''; /** * Category feed element * * optional * * @var string * @since 1.7.0 */ public $category = ''; /** * TTL feed attribute * * optional * * @var string * @since 1.7.0 */ public $ttl = ''; /** * Rating feed element * * optional * * @var string * @since 1.7.0 */ public $rating = ''; /** * Skiphours feed element * * optional * * @var string * @since 1.7.0 */ public $skipHours = ''; /** * Skipdays feed element * * optional * * @var string * @since 1.7.0 */ public $skipDays = ''; /** * The feed items collection * * @var FeedItem[] * @since 1.7.0 */ public $items = []; /** * Class constructor * * @param array $options Associative array of options * * @since 1.7.0 */ public function __construct($options = []) { parent::__construct($options); // Set document type $this->_type = 'feed'; // Gets and sets timezone offset from site configuration $this->lastBuildDate = CmsFactory::getDate(); $this->lastBuildDate->setTimezone(new \DateTimeZone(CmsFactory::getApplication()->get('offset', 'UTC'))); } /** * Render the document * * @param boolean $cache If true, cache the output * @param array $params Associative array of attributes * * @return string The rendered data * * @since 1.7.0 * @throws \Exception * @todo Make this cacheable */ public function render($cache = false, $params = []) { // Get the feed type $type = CmsFactory::getApplication()->getInput()->get('type', 'rss'); // Instantiate feed renderer and set the mime encoding $renderer = $this->loadRenderer($type ?: 'rss'); if (!($renderer instanceof DocumentRenderer)) { throw new \Exception(Text::_('JGLOBAL_RESOURCE_NOT_FOUND'), 404); } $this->setMimeEncoding($renderer->getContentType()); // Output // Generate prolog $data = "<?xml version=\"1.0\" encoding=\"" . $this->_charset . "\"?>\n"; $data .= "<!-- generator=\"" . $this->getGenerator() . "\" -->\n"; // Generate stylesheet links foreach ($this->_styleSheets as $src => $attr) { $data .= "<?xml-stylesheet href=\"$src\" type=\"" . $attr['type'] . "\"?>\n"; } // Render the feed $data .= $renderer->render(); parent::render($cache, $params); return $data; } /** * Adds a FeedItem to the feed. * * @param FeedItem $item The feeditem to add to the feed. * * @return FeedDocument instance of $this to allow chaining * * @since 1.7.0 */ public function addItem(FeedItem $item) { $item->source = $this->link; $this->items[] = $item; return $this; } } DocumentAwareInterface.php 0000644 00000001305 15172704424 0011641 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Interface to be implemented by classes depending on a document. * * @since 4.4.0 */ interface DocumentAwareInterface { /** * Set the document to use. * * @param Document $document The document to use. * * @return void * * @since 4.4.0 */ public function setDocument(Document $document): void; } DocumentAwareTrait.php 0000644 00000002341 15172704424 0011025 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Defines the trait for a document aware class. * * @since 4.4.0 */ trait DocumentAwareTrait { /** * Document * * @var Document * @since 4.4.0 */ private $document; /** * Get the Document. * * @return Document * * @since 4.4.0 * @throws \UnexpectedValueException May be thrown if the document has not been set. */ protected function getDocument(): Document { if ($this->document) { return $this->document; } throw new \UnexpectedValueException('Document not set in ' . __CLASS__); } /** * Set the document to use. * * @param Document $document The document to use * * @return void * * @since 4.4.0 */ public function setDocument(Document $document): void { $this->document = $document; } } RawDocument.php 0000644 00000002361 15172704424 0007515 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * RawDocument class, provides an easy interface to parse and display raw output * * @since 1.7.0 */ class RawDocument extends Document { /** * Class constructor * * @param array $options Associative array of options * * @since 1.7.0 */ public function __construct($options = []) { parent::__construct($options); // Set mime type $this->_mime = 'text/html'; // Set document type $this->_type = 'raw'; } /** * Render the document. * * @param boolean $cache If true, cache the output * @param array $params Associative array of attributes * * @return string The rendered data * * @since 1.7.0 */ public function render($cache = false, $params = []) { parent::render($cache, $params); return $this->getBuffer(); } } PreloadManager.php 0000644 00000011007 15172704424 0010143 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; use Fig\Link\GenericLinkProvider; use Fig\Link\Link; use Psr\Link\EvolvableLinkProviderInterface; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Joomla! Preload Manager * * @since 4.0.0 */ class PreloadManager implements PreloadManagerInterface { /** * The link provider * * @var EvolvableLinkProviderInterface * @since 4.0.0 */ protected $linkProvider; /** * PreloadManager constructor * * @param EvolvableLinkProviderInterface $linkProvider The link provider * * @since 4.0.0 */ public function __construct(EvolvableLinkProviderInterface $linkProvider = null) { $this->linkProvider = $linkProvider ?: new GenericLinkProvider(); } /** * Get the link provider * * @return EvolvableLinkProviderInterface * * @since 4.0.0 */ public function getLinkProvider(): EvolvableLinkProviderInterface { return $this->linkProvider; } /** * Set the link provider * * @param EvolvableLinkProviderInterface $linkProvider The link provider * * @return $this * * @since 4.0.0 */ public function setLinkProvider(EvolvableLinkProviderInterface $linkProvider) { $this->linkProvider = $linkProvider; return $this; } /** * Preloads a resource. * * @param string $uri A public path * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('crossorigin' => 'use-credentials')") * * @return void * * @since 4.0.0 */ public function preload(string $uri, array $attributes = []) { $this->link($uri, 'preload', $attributes); } /** * Resolves a resource origin as early as possible. * * @param string $uri A public path * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('pr' => 0.5)") * * @return void * * @since 4.0.0 */ public function dnsPrefetch(string $uri, array $attributes = []) { $this->link($uri, 'dns-prefetch', $attributes); } /** * Initiates an early connection to a resource (DNS resolution, TCP handshake, TLS negotiation). * * @param string $uri A public path * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('pr' => 0.5)") * * @return void * * @since 4.0.0 */ public function preconnect(string $uri, array $attributes = []) { $this->link($uri, 'preconnect', $attributes); } /** * Indicates to the client that it should prefetch this resource. * * @param string $uri A public path * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('pr' => 0.5)") * * @return void * * @since 4.0.0 */ public function prefetch(string $uri, array $attributes = []) { $this->link($uri, 'prefetch', $attributes); } /** * Indicates to the client that it should prerender this resource. * * @param string $uri A public path * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('pr' => 0.5)") * * @return void * * @since 4.0.0 */ public function prerender(string $uri, array $attributes = []) { $this->link($uri, 'prerender', $attributes); } /** * Adds a "Link" HTTP header. * * @param string $uri The relation URI * @param string $rel The relation type (e.g. "preload", "prefetch", "prerender" or "dns-prefetch") * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('pr' => 0.5)") * * @return void * * @since 4.0.0 */ private function link(string $uri, string $rel, array $attributes = []) { $link = new Link($rel, $uri); foreach ($attributes as $key => $value) { $link = $link->withAttribute($key, $value); } $this->setLinkProvider($this->getLinkProvider()->withLink($link)); } } DocumentRenderer.php 0000644 00000003276 15172704424 0010540 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; use Joomla\CMS\Uri\Uri; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * Abstract class for a renderer * * @since 1.7.0 */ abstract class DocumentRenderer implements RendererInterface { /** * Reference to the Document object that instantiated the renderer * * @var Document * @since 1.7.0 */ protected $_doc = null; /** * Renderer mime type * * @var string * @since 1.7.0 */ protected $_mime = 'text/html'; /** * Class constructor * * @param Document $doc A reference to the Document object that instantiated the renderer * * @since 1.7.0 */ public function __construct(Document $doc) { $this->_doc = $doc; } /** * Return the content type of the renderer * * @return string The contentType * * @since 1.7.0 */ public function getContentType() { return $this->_mime; } /** * Convert links in a text from relative to absolute * * @param string $text The text processed * * @return string Text with converted links * * @since 1.7.0 */ protected function _relToAbs($text) { $base = Uri::base(); $text = preg_replace("/(href|src)=\"(?!http|ftp|https|mailto|data|\/\/)([^\"]*)\"/", "$1=\"$base\$2\"", $text); return $text; } } XmlDocument.php 0000644 00000005634 15172704424 0007532 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; use Joomla\CMS\Factory as CmsFactory; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * XmlDocument class, provides an easy interface to parse and display XML output * * @since 1.7.0 */ class XmlDocument extends Document { /** * Document name * * @var string * @since 3.0.0 */ protected $name = 'joomla'; /** * Flag indicating the document should be downloaded (Content-Disposition = attachment) versus displayed inline * * @var boolean * @since 3.9.0 */ protected $isDownload = false; /** * Class constructor * * @param array $options Associative array of options * * @since 1.7.0 */ public function __construct($options = []) { parent::__construct($options); // Set mime type $this->_mime = 'application/xml'; // Set document type $this->_type = 'xml'; } /** * Render the document. * * @param boolean $cache If true, cache the output * @param array $params Associative array of attributes * * @return string The rendered data * * @since 1.7.0 */ public function render($cache = false, $params = []) { parent::render($cache, $params); $disposition = $this->isDownload ? 'attachment' : 'inline'; CmsFactory::getApplication()->setHeader('Content-disposition', $disposition . '; filename="' . $this->getName() . '.xml"', true); return $this->getBuffer(); } /** * Returns the document name * * @return string * * @since 1.7.0 */ public function getName() { return $this->name; } /** * Sets the document name * * @param string $name Document name * * @return XmlDocument instance of $this to allow chaining * * @since 1.7.0 */ public function setName($name = 'joomla') { $this->name = $name; return $this; } /** * Check if this document is intended for download * * @return string * * @since 3.9.0 */ public function isDownload() { return $this->isDownload; } /** * Sets the document's download state * * @param boolean $download If true, this document will be downloaded; if false, this document will be displayed inline * * @return XmlDocument instance of $this to allow chaining * * @since 3.9.0 */ public function setDownload($download = false) { $this->isDownload = $download; return $this; } } ErrorDocument.php 0000644 00000007363 15172704424 0010064 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; use Joomla\CMS\Factory as CmsFactory; use Joomla\CMS\Layout\LayoutHelper; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * ErrorDocument class, provides an easy interface to parse and display an HTML based error page * * @since 1.7.0 */ class ErrorDocument extends HtmlDocument { /** * Flag if debug mode has been enabled * * @var boolean * @since 1.7.0 */ public $debug = false; /** * Error Object * * @var \Throwable * @since 1.7.0 */ public $error; /** * Error Object * * @var \Throwable * @since 1.7.0 */ protected $_error; /** * Class constructor * * @param array $options Associative array of attributes * * @since 1.7.0 */ public function __construct($options = []) { parent::__construct($options); // Set document type $this->_type = 'error'; } /** * Set error object * * @param \Throwable $error Error object to set * * @return boolean True on success * * @since 1.7.0 */ public function setError($error) { if ($error instanceof \Throwable) { $this->_error = & $error; return true; } return false; } /** * Load a renderer * * @param string $type The renderer type * * @return RendererInterface * * @since 4.0.0 * @throws \RuntimeException */ public function loadRenderer($type) { // Need to force everything to go to the HTML renderers or we duplicate all the things return $this->factory->createRenderer($this, $type, 'html'); } /** * Render the document * * @param boolean $cache If true, cache the output * @param array $params Associative array of attributes * * @return string The rendered data * * @since 1.7.0 */ public function render($cache = false, $params = []) { // If no error object is set return null if (!isset($this->_error)) { return; } // Set the status header $status = $this->_error->getCode(); if ($status < 400 || $status > 599) { $status = 500; } $errorReporting = CmsFactory::getApplication()->get('error_reporting'); if ($errorReporting === "development" || $errorReporting === "maximum") { $status .= ' ' . str_replace("\n", ' ', $this->_error->getMessage()); } CmsFactory::getApplication()->setHeader('status', $status); // Set variables $this->debug = $params['debug'] ?? false; $this->error = $this->_error; $params['file'] = 'error.php'; return parent::render($cache, $params); } /** * Render the backtrace * * @return string The contents of the backtrace * * @since 1.7.0 */ public function renderBacktrace() { // If no error object is set return null if (!isset($this->_error)) { return; } // The back trace $backtrace = $this->_error->getTrace(); // Add the position of the actual file array_unshift($backtrace, ['file' => $this->_error->getFile(), 'line' => $this->_error->getLine(), 'function' => '']); return LayoutHelper::render('joomla.error.backtrace', ['backtrace' => $backtrace]); } } PreloadManagerInterface.php 0000644 00000005524 15172704424 0011773 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; use Psr\Link\EvolvableLinkProviderInterface; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Joomla! Preload Manager Interface * * @since 4.0.0 */ interface PreloadManagerInterface { /** * Get the link provider * * @return EvolvableLinkProviderInterface * * @since 4.0.0 */ public function getLinkProvider(): EvolvableLinkProviderInterface; /** * Set the link provider * * @param EvolvableLinkProviderInterface $linkProvider The link provider * * @return $this * * @since 4.0.0 */ public function setLinkProvider(EvolvableLinkProviderInterface $linkProvider); /** * Preloads a resource. * * @param string $uri A public path * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('crossorigin' => 'use-credentials')") * * @return void * * @since 4.0.0 */ public function preload(string $uri, array $attributes = []); /** * Resolves a resource origin as early as possible. * * @param string $uri A public path * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('pr' => 0.5)") * * @return void * * @since 4.0.0 */ public function dnsPrefetch(string $uri, array $attributes = []); /** * Initiates an early connection to a resource (DNS resolution, TCP handshake, TLS negotiation). * * @param string $uri A public path * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('pr' => 0.5)") * * @return void * * @since 4.0.0 */ public function preconnect(string $uri, array $attributes = []); /** * Indicates to the client that it should prefetch this resource. * * @param string $uri A public path * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('pr' => 0.5)") * * @return void * * @since 4.0.0 */ public function prefetch(string $uri, array $attributes = []); /** * Indicates to the client that it should prerender this resource. * * @param string $uri A public path * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('pr' => 0.5)") * * @return void * * @since 4.0.0 */ public function prerender(string $uri, array $attributes = []); } FactoryInterface.php 0000644 00000002445 15172704424 0010520 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Interface defining a factory which can create Document objects * * @since 4.0.0 */ interface FactoryInterface { /** * Creates a new Document object for the requested format. * * @param string $type The document type to instantiate * @param array $attributes Array of attributes * * @return Document * * @since 4.0.0 */ public function createDocument(string $type = 'html', array $attributes = []): Document; /** * Creates a new renderer object. * * @param Document $document The Document instance to attach to the renderer * @param string $type The renderer type to instantiate * @param string $docType The document type the renderer is part of * * @return RendererInterface * * @since 4.0.0 */ public function createRenderer(Document $document, string $type, string $docType = ''): RendererInterface; } Renderer/Pdf/ComponentRenderer.php 0000604 00000001662 15172704424 0013174 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Html; defined('JPATH_PLATFORM') or die; use Joomla\CMS\Document\DocumentRenderer; /** * HTML document renderer for the component output * * @since 3.5 */ class ComponentRenderer extends DocumentRenderer { /** * Renders a component script and returns the results as a string * * @param string $component The name of the component to render * @param array $params Associative array of values * @param string $content Content script * * @return string The output of the script * * @since 3.5 */ public function render($component = null, $params = array(), $content = null) { return $content; } } Renderer/Pdf/ModulesRenderer.php 0000604 00000003676 15172704424 0012651 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Html; defined('JPATH_PLATFORM') or die; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\Helper\ModuleHelper; use Joomla\CMS\Layout\LayoutHelper; /** * HTML document renderer for a module position * * @since 3.5 */ class ModulesRenderer extends DocumentRenderer { /** * Renders multiple modules script and returns the results as a string * * @param string $position The position of the modules to render * @param array $params Associative array of values * @param string $content Module content * * @return string The output of the script * * @since 3.5 */ public function render($position, $params = array(), $content = null) { $renderer = $this->_doc->loadRenderer('module'); $buffer = ''; $app = \JFactory::getApplication(); $user = \JFactory::getUser(); $frontediting = ($app->isClient('site') && $app->get('frontediting', 1) && !$user->guest); $menusEditing = ($app->get('frontediting', 1) == 2) && $user->authorise('core.edit', 'com_menus'); foreach (ModuleHelper::getModules($position) as $mod) { $moduleHtml = $renderer->render($mod, $params, $content); if ($frontediting && trim($moduleHtml) != '' && $user->authorise('module.edit.frontend', 'com_modules.module.' . $mod->id)) { $displayData = array('moduleHtml' => &$moduleHtml, 'module' => $mod, 'position' => $position, 'menusediting' => $menusEditing); LayoutHelper::render('joomla.edit.frontediting_modules', $displayData); } $buffer .= $moduleHtml; } \JEventDispatcher::getInstance()->trigger('onAfterRenderModules', array(&$buffer, &$params)); return $buffer; } } Renderer/Pdf/ModuleRenderer.php 0000604 00000005421 15172704424 0012454 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Html; defined('JPATH_PLATFORM') or die; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\Helper\ModuleHelper; use Joomla\CMS\Log\Log; use Joomla\CMS\Layout\LayoutHelper; use Joomla\Registry\Registry; /** * HTML document renderer for a single module * * @since 3.5 */ class ModuleRenderer extends DocumentRenderer { /** * Renders a module script and returns the results as a string * * @param string $module The name of the module to render * @param array $attribs Associative array of values * @param string $content If present, module information from the buffer will be used * * @return string The output of the script * * @since 3.5 */ public function render($module, $attribs = array(), $content = null) { if (!is_object($module)) { $title = isset($attribs['title']) ? $attribs['title'] : null; $module = ModuleHelper::getModule($module, $title); if (!is_object($module)) { if (is_null($content)) { return ''; } /** * If module isn't found in the database but data has been pushed in the buffer * we want to render it */ $tmp = $module; $module = new \stdClass; $module->params = null; $module->module = $tmp; $module->id = 0; $module->user = 0; } } // Set the module content if (!is_null($content)) { $module->content = $content; } // Get module parameters $params = new Registry($module->params); // Use parameters from template if (isset($attribs['params'])) { $template_params = new Registry(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8')); $params->merge($template_params); $module = clone $module; $module->params = (string) $params; } // Default for compatibility purposes. Set cachemode parameter or use JModuleHelper::moduleCache from within the module instead $cachemode = $params->get('cachemode', 'oldstatic'); if ($params->get('cache', 0) == 1 && \JFactory::getConfig()->get('caching') >= 1 && $cachemode != 'id' && $cachemode != 'safeuri') { // Default to itemid creating method and workarounds on $cacheparams = new \stdClass; $cacheparams->cachemode = $cachemode; $cacheparams->class = 'JModuleHelper'; $cacheparams->method = 'renderModule'; $cacheparams->methodparams = array($module, $attribs); return ModuleHelper::ModuleCache($module, $params, $cacheparams); } return ModuleHelper::renderModule($module, $attribs); } } Renderer/Pdf/MessageRenderer.php 0000604 00000004247 15172704424 0012620 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Html; defined('JPATH_PLATFORM') or die; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\Log\Log; use Joomla\CMS\Layout\LayoutHelper; /** * HTML document renderer for the system message queue * * @since 3.5 */ class MessageRenderer extends DocumentRenderer { /** * Renders the error stack and returns the results as a string * * @param string $name Not used. * @param array $params Associative array of values * @param string $content Not used. * * @return string The output of the script * * @since 3.5 */ public function render($name, $params = array(), $content = null) { $msgList = $this->getData(); $displayData = array( 'msgList' => $msgList, 'name' => $name, 'params' => $params, 'content' => $content, ); $app = \JFactory::getApplication(); $chromePath = JPATH_THEMES . '/' . $app->getTemplate() . '/html/message.php'; if (file_exists($chromePath)) { include_once $chromePath; } if (function_exists('renderMessage')) { Log::add('renderMessage() is deprecated. Override system message rendering with layouts instead.', Log::WARNING, 'deprecated'); return renderMessage($msgList); } return LayoutHelper::render('joomla.system.message', $displayData); } /** * Get and prepare system message data for output * * @return array An array contains system message * * @since 3.5 */ private function getData() { // Initialise variables. $lists = array(); // Get the message queue $messages = \JFactory::getApplication()->getMessageQueue(); // Build the sorted message list if (is_array($messages) && !empty($messages)) { foreach ($messages as $msg) { if (isset($msg['type']) && isset($msg['message'])) { $lists[$msg['type']][] = $msg['message']; } } } return $lists; } } Renderer/Pdf/HeadRenderer.php 0000604 00000025671 15172704424 0012101 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Html; defined('JPATH_PLATFORM') or die; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\Helper\TagsHelper; use Joomla\CMS\Uri\Uri; use Joomla\Utilities\ArrayHelper; /** * HTML document renderer for the document `<head>` element * * @since 3.5 */ class HeadRenderer extends DocumentRenderer { /** * Renders the document head 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 3.5 */ public function render($head, $params = array(), $content = null) { return $this->fetchHead($this->_doc); } /** * Generates the head HTML and return the results as a string * * @param JDocumentHtml $document The document for which the head will be created * * @return string The head hTML * * @since 3.5 * @deprecated 4.0 Method code will be moved into the render method */ public function fetchHead($document) { // Convert the tagids to titles if (isset($document->_metaTags['name']['tags'])) { $tagsHelper = new TagsHelper; $document->_metaTags['name']['tags'] = implode(', ', $tagsHelper->getTagNames($document->_metaTags['name']['tags'])); } if ($document->getScriptOptions()) { \JHtml::_('behavior.core'); } // Trigger the onBeforeCompileHead event $app = \JFactory::getApplication(); $app->triggerEvent('onBeforeCompileHead'); // Get line endings $lnEnd = $document->_getLineEnd(); $tab = $document->_getTab(); $tagEnd = ' />'; $buffer = ''; $mediaVersion = $document->getMediaVersion(); // Generate charset when using HTML5 (should happen first) if ($document->isHtml5()) { $buffer .= $tab . '<meta charset="' . $document->getCharset() . '" />' . $lnEnd; } // Generate base tag (need to happen early) $base = $document->getBase(); if (!empty($base)) { $buffer .= $tab . '<base href="' . $base . '" />' . $lnEnd; } // Generate META tags (needs to happen as early as possible in the head) foreach ($document->_metaTags as $type => $tag) { foreach ($tag as $name => $content) { if ($type == 'http-equiv' && !($document->isHtml5() && $name == 'content-type')) { $buffer .= $tab . '<meta http-equiv="' . $name . '" content="' . htmlspecialchars($content, ENT_COMPAT, 'UTF-8') . '" />' . $lnEnd; } elseif ($type != 'http-equiv' && !empty($content)) { if (is_array($content)) { foreach ($content as $value) { $buffer .= $tab . '<meta ' . $type . '="' . $name . '" content="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '" />' . $lnEnd; } } else { $buffer .= $tab . '<meta ' . $type . '="' . $name . '" content="' . htmlspecialchars($content, ENT_COMPAT, 'UTF-8') . '" />' . $lnEnd; } } } } // Don't add empty descriptions $documentDescription = $document->getDescription(); if ($documentDescription) { $buffer .= $tab . '<meta name="description" content="' . htmlspecialchars($documentDescription, ENT_COMPAT, 'UTF-8') . '" />' . $lnEnd; } // Don't add empty generators $generator = $document->getGenerator(); if ($generator) { $buffer .= $tab . '<meta name="generator" content="' . htmlspecialchars($generator, ENT_COMPAT, 'UTF-8') . '" />' . $lnEnd; } $buffer .= $tab . '<title>' . htmlspecialchars($document->getTitle(), ENT_COMPAT, 'UTF-8') . '</title>' . $lnEnd; // Generate link declarations foreach ($document->_links as $link => $linkAtrr) { $buffer .= $tab . '<link href="' . $link . '" ' . $linkAtrr['relType'] . '="' . $linkAtrr['relation'] . '"'; if (is_array($linkAtrr['attribs'])) { if ($temp = ArrayHelper::toString($linkAtrr['attribs'])) { $buffer .= ' ' . $temp; } } $buffer .= ' />' . $lnEnd; } $defaultCssMimes = array('text/css'); // Generate stylesheet links foreach ($document->_styleSheets as $src => $attribs) { // Check if stylesheet uses IE conditional statements. $conditional = isset($attribs['options']) && isset($attribs['options']['conditional']) ? $attribs['options']['conditional'] : null; // Check if script uses media version. if (isset($attribs['options']['version']) && $attribs['options']['version'] && strpos($src, '?') === false && ($mediaVersion || $attribs['options']['version'] !== 'auto')) { $src .= '?' . ($attribs['options']['version'] === 'auto' ? $mediaVersion : $attribs['options']['version']); } $buffer .= $tab; // This is for IE conditional statements support. if (!is_null($conditional)) { $buffer .= '<!--[if ' . $conditional . ']>'; } $buffer .= '<link href="' . $src . '" rel="stylesheet"'; // Add script tag attributes. foreach ($attribs as $attrib => $value) { // Don't add the 'options' attribute. This attribute is for internal use (version, conditional, etc). if ($attrib === 'options') { continue; } // Don't add type attribute if document is HTML5 and it's a default mime type. 'mime' is for B/C. if (in_array($attrib, array('type', 'mime')) && $document->isHtml5() && in_array($value, $defaultCssMimes)) { continue; } // Don't add type attribute if document is HTML5 and it's a default mime type. 'mime' is for B/C. if ($attrib === 'mime') { $attrib = 'type'; } // Add attribute to script tag output. $buffer .= ' ' . htmlspecialchars($attrib, ENT_COMPAT, 'UTF-8'); // Json encode value if it's an array. $value = !is_scalar($value) ? json_encode($value) : $value; $buffer .= '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; } $buffer .= $tagEnd; // This is for IE conditional statements support. if (!is_null($conditional)) { $buffer .= '<![endif]-->'; } $buffer .= $lnEnd; } // Generate stylesheet declarations foreach ($document->_style as $type => $content) { $buffer .= $tab . '<style'; if (!is_null($type) && (!$document->isHtml5() || !in_array($type, $defaultCssMimes))) { $buffer .= ' type="' . $type . '"'; } $buffer .= '>' . $lnEnd; // This is for full XHTML support. if ($document->_mime != 'text/html') { $buffer .= $tab . $tab . '/*<![CDATA[*/' . $lnEnd; } $buffer .= $content . $lnEnd; // See above note if ($document->_mime != 'text/html') { $buffer .= $tab . $tab . '/*]]>*/' . $lnEnd; } $buffer .= $tab . '</style>' . $lnEnd; } // Generate scripts options $scriptOptions = $document->getScriptOptions(); if (!empty($scriptOptions)) { $buffer .= $tab . '<script type="application/json" class="joomla-script-options new">'; $prettyPrint = (JDEBUG && defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : false); $jsonOptions = json_encode($scriptOptions, $prettyPrint); $jsonOptions = $jsonOptions ? $jsonOptions : '{}'; $buffer .= $jsonOptions; $buffer .= '</script>' . $lnEnd; } $defaultJsMimes = array('text/javascript', 'application/javascript', 'text/x-javascript', 'application/x-javascript'); $html5NoValueAttributes = array('defer', 'async'); // Generate script file links foreach ($document->_scripts as $src => $attribs) { // Check if script uses IE conditional statements. $conditional = isset($attribs['options']) && isset($attribs['options']['conditional']) ? $attribs['options']['conditional'] : null; // Check if script uses media version. if (isset($attribs['options']['version']) && $attribs['options']['version'] && strpos($src, '?') === false && ($mediaVersion || $attribs['options']['version'] !== 'auto')) { $src .= '?' . ($attribs['options']['version'] === 'auto' ? $mediaVersion : $attribs['options']['version']); } $buffer .= $tab; // This is for IE conditional statements support. if (!is_null($conditional)) { $buffer .= '<!--[if ' . $conditional . ']>'; } $buffer .= '<script src="' . $src . '"'; // Add script tag attributes. foreach ($attribs as $attrib => $value) { // Don't add the 'options' attribute. This attribute is for internal use (version, conditional, etc). if ($attrib === 'options') { continue; } // Don't add type attribute if document is HTML5 and it's a default mime type. 'mime' is for B/C. if (in_array($attrib, array('type', 'mime')) && $document->isHtml5() && in_array($value, $defaultJsMimes)) { continue; } // B/C: If defer and async is false or empty don't render the attribute. if (in_array($attrib, array('defer', 'async')) && !$value) { continue; } // Don't add type attribute if document is HTML5 and it's a default mime type. 'mime' is for B/C. if ($attrib === 'mime') { $attrib = 'type'; } // B/C defer and async can be set to yes when using the old method. elseif (in_array($attrib, array('defer', 'async')) && $value === true) { $value = $attrib; } // Add attribute to script tag output. $buffer .= ' ' . htmlspecialchars($attrib, ENT_COMPAT, 'UTF-8'); if (!($document->isHtml5() && in_array($attrib, $html5NoValueAttributes))) { // Json encode value if it's an array. $value = !is_scalar($value) ? json_encode($value) : $value; $buffer .= '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; } } $buffer .= '></script>'; // This is for IE conditional statements support. if (!is_null($conditional)) { $buffer .= '<![endif]-->'; } $buffer .= $lnEnd; } // Generate script declarations foreach ($document->_script as $type => $content) { $buffer .= $tab . '<script'; if (!is_null($type) && (!$document->isHtml5() || !in_array($type, $defaultJsMimes))) { $buffer .= ' type="' . $type . '"'; } $buffer .= '>' . $lnEnd; // This is for full XHTML support. if ($document->_mime != 'text/html') { $buffer .= $tab . $tab . '//<![CDATA[' . $lnEnd; } $buffer .= $content . $lnEnd; // See above note if ($document->_mime != 'text/html') { $buffer .= $tab . $tab . '//]]>' . $lnEnd; } $buffer .= $tab . '</script>' . $lnEnd; } // Output the custom tags - array_unique makes sure that we don't output the same tags twice foreach (array_unique($document->_custom) as $custom) { $buffer .= $tab . $custom . $lnEnd; } return ltrim($buffer, $tab); } } Renderer/Feed/RssRenderer.php 0000644 00000022765 15172704424 0012146 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Feed; use Joomla\CMS\Date\Date; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; use Joomla\CMS\Uri\Uri; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * RssRenderer is a feed that implements RSS 2.0 Specification * * @link http://www.rssboard.org/rss-specification * @since 3.5 * * @property-read \Joomla\CMS\Document\FeedDocument $_doc Reference to the Document object that instantiated the renderer */ class RssRenderer extends DocumentRenderer { /** * Renderer mime type * * @var string * @since 3.5 */ protected $_mime = 'application/rss+xml'; /** * Render the feed. * * @param string $name The name of the element to render * @param array $params Array of values * @param string $content Override the output of the renderer * * @return string The output of the script * * @see DocumentRenderer::render() * @since 3.5 */ public function render($name = '', $params = null, $content = null) { $app = Factory::getApplication(); $tz = new \DateTimeZone($app->get('offset')); $data = $this->_doc; // If the last build date from the document isn't a Date object, create one if (!($data->lastBuildDate instanceof Date)) { // Gets and sets timezone offset from site configuration $data->lastBuildDate = Factory::getDate(); $data->lastBuildDate->setTimezone(new \DateTimeZone($app->get('offset'))); } $url = Uri::getInstance()->toString(['scheme', 'user', 'pass', 'host', 'port']); $syndicationURL = Route::_('&format=feed&type=rss'); $title = $data->getTitle(); if ($app->get('sitename_pagetitles', 0) == 1) { $title = Text::sprintf('JPAGETITLE', $app->get('sitename'), $data->getTitle()); } elseif ($app->get('sitename_pagetitles', 0) == 2) { $title = Text::sprintf('JPAGETITLE', $data->getTitle(), $app->get('sitename')); } $feed_title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8'); $datalink = $data->getLink(); if (preg_match('/[\x80-\xFF]/', $datalink)) { $datalink = implode('/', array_map('rawurlencode', explode('/', $datalink))); } $feed = "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n"; $feed .= " <channel>\n"; $feed .= " <title>" . $feed_title . "</title>\n"; $feed .= " <description><![CDATA[" . $data->getDescription() . "]]></description>\n"; $feed .= " <link>" . str_replace(' ', '%20', $url . $datalink) . "</link>\n"; $feed .= " <lastBuildDate>" . htmlspecialchars($data->lastBuildDate->toRFC822(true), ENT_COMPAT, 'UTF-8') . "</lastBuildDate>\n"; $feed .= " <generator>" . $data->getGenerator() . "</generator>\n"; $feed .= " <atom:link rel=\"self\" type=\"application/rss+xml\" href=\"" . str_replace(' ', '%20', $url . $syndicationURL) . "\"/>\n"; if ($data->image != null) { $feed .= " <image>\n"; $feed .= " <url>" . $data->image->url . "</url>\n"; $feed .= " <title>" . htmlspecialchars($data->image->title, ENT_COMPAT, 'UTF-8') . "</title>\n"; $feed .= " <link>" . str_replace(' ', '%20', $data->image->link) . "</link>\n"; if ($data->image->width != '') { $feed .= " <width>" . $data->image->width . "</width>\n"; } if ($data->image->height != '') { $feed .= " <height>" . $data->image->height . "</height>\n"; } if ($data->image->description != '') { $feed .= " <description><![CDATA[" . $data->image->description . "]]></description>\n"; } $feed .= " </image>\n"; } if ($data->getLanguage() !== '') { $feed .= " <language>" . $data->getLanguage() . "</language>\n"; } if ($data->copyright != '') { $feed .= " <copyright>" . htmlspecialchars($data->copyright, ENT_COMPAT, 'UTF-8') . "</copyright>\n"; } if ($data->editorEmail != '') { $feed .= " <managingEditor>" . htmlspecialchars($data->editorEmail, ENT_COMPAT, 'UTF-8') . ' (' . htmlspecialchars($data->editor, ENT_COMPAT, 'UTF-8') . ")</managingEditor>\n"; } if ($data->webmaster != '') { $feed .= " <webMaster>" . htmlspecialchars($data->webmaster, ENT_COMPAT, 'UTF-8') . "</webMaster>\n"; } if ($data->pubDate != '') { $pubDate = Factory::getDate($data->pubDate); $pubDate->setTimezone($tz); $feed .= " <pubDate>" . htmlspecialchars($pubDate->toRFC822(true), ENT_COMPAT, 'UTF-8') . "</pubDate>\n"; } if (!empty($data->category)) { if (\is_array($data->category)) { foreach ($data->category as $cat) { $feed .= " <category>" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "</category>\n"; } } else { $feed .= " <category>" . htmlspecialchars($data->category, ENT_COMPAT, 'UTF-8') . "</category>\n"; } } if ($data->docs != '') { $feed .= " <docs>" . htmlspecialchars($data->docs, ENT_COMPAT, 'UTF-8') . "</docs>\n"; } if ($data->ttl != '') { $feed .= " <ttl>" . htmlspecialchars($data->ttl, ENT_COMPAT, 'UTF-8') . "</ttl>\n"; } if ($data->rating != '') { $feed .= " <rating>" . htmlspecialchars($data->rating, ENT_COMPAT, 'UTF-8') . "</rating>\n"; } if ($data->skipHours != '') { $feed .= " <skipHours>" . htmlspecialchars($data->skipHours, ENT_COMPAT, 'UTF-8') . "</skipHours>\n"; } if ($data->skipDays != '') { $feed .= " <skipDays>" . htmlspecialchars($data->skipDays, ENT_COMPAT, 'UTF-8') . "</skipDays>\n"; } for ($i = 0, $count = \count($data->items); $i < $count; $i++) { $itemlink = $data->items[$i]->link; if (preg_match('/[\x80-\xFF]/', $itemlink)) { $itemlink = implode('/', array_map('rawurlencode', explode('/', $itemlink))); } if ((strpos($itemlink, 'http://') === false) && (strpos($itemlink, 'https://') === false)) { $itemlink = str_replace(' ', '%20', $url . $itemlink); } $feed .= " <item>\n"; $feed .= " <title>" . htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT, 'UTF-8') . "</title>\n"; $feed .= " <link>" . str_replace(' ', '%20', $itemlink) . "</link>\n"; if (empty($data->items[$i]->guid)) { $feed .= " <guid isPermaLink=\"true\">" . str_replace(' ', '%20', $itemlink) . "</guid>\n"; } else { $feed .= " <guid isPermaLink=\"false\">" . htmlspecialchars($data->items[$i]->guid, ENT_COMPAT, 'UTF-8') . "</guid>\n"; } $feed .= " <description><![CDATA[" . $this->_relToAbs($data->items[$i]->description) . "]]></description>\n"; if ($data->items[$i]->authorEmail != '') { $feed .= ' <author>' . htmlspecialchars($data->items[$i]->authorEmail . ' (' . $data->items[$i]->author . ')', ENT_COMPAT, 'UTF-8') . "</author>\n"; } /* * @todo: On hold * if ($data->items[$i]->source!='') * { * $data.= " <source>" . htmlspecialchars($data->items[$i]->source, ENT_COMPAT, 'UTF-8') . "</source>\n"; * } */ if (empty($data->items[$i]->category) === false) { if (\is_array($data->items[$i]->category)) { foreach ($data->items[$i]->category as $cat) { $feed .= " <category>" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "</category>\n"; } } else { $feed .= " <category>" . htmlspecialchars($data->items[$i]->category, ENT_COMPAT, 'UTF-8') . "</category>\n"; } } if ($data->items[$i]->comments != '') { $feed .= " <comments>" . htmlspecialchars($data->items[$i]->comments, ENT_COMPAT, 'UTF-8') . "</comments>\n"; } if ($data->items[$i]->date != '') { $itemDate = Factory::getDate($data->items[$i]->date); $itemDate->setTimezone($tz); $feed .= " <pubDate>" . htmlspecialchars($itemDate->toRFC822(true), ENT_COMPAT, 'UTF-8') . "</pubDate>\n"; } if ($data->items[$i]->enclosure != null) { $feed .= " <enclosure url=\""; $feed .= $data->items[$i]->enclosure->url; $feed .= "\" length=\""; $feed .= $data->items[$i]->enclosure->length; $feed .= "\" type=\""; $feed .= $data->items[$i]->enclosure->type; $feed .= "\"/>\n"; } $feed .= " </item>\n"; } $feed .= " </channel>\n"; $feed .= "</rss>\n"; return $feed; } } Renderer/Feed/AtomRenderer.php 0000644 00000017006 15172704424 0012267 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Feed; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; use Joomla\CMS\Uri\Uri; use Joomla\CMS\Version; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * AtomRenderer is a feed that implements the atom specification * * Please note that just by using this class you won't automatically * produce valid atom files. For example, you have to specify either an editor * for the feed or an author for every single feed item. * * @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php * @since 3.5 * * @property-read \Joomla\CMS\Document\FeedDocument $_doc Reference to the Document object that instantiated the renderer */ class AtomRenderer extends DocumentRenderer { /** * Document mime type * * @var string * @since 3.5 */ protected $_mime = 'application/atom+xml'; /** * Render the feed. * * @param string $name The name of the element to render * @param array $params Array of values * @param string $content Override the output of the renderer * * @return string The output of the script * * @see DocumentRenderer::render() * @since 3.5 */ public function render($name = '', $params = null, $content = null) { $app = Factory::getApplication(); // Gets and sets timezone offset from site configuration $tz = new \DateTimeZone($app->get('offset')); $now = Factory::getDate(); $now->setTimezone($tz); $data = $this->_doc; $url = Uri::getInstance()->toString(['scheme', 'user', 'pass', 'host', 'port']); $syndicationURL = Route::_('&format=feed&type=atom'); $title = $data->getTitle(); if ($app->get('sitename_pagetitles', 0) == 1) { $title = Text::sprintf('JPAGETITLE', $app->get('sitename'), $data->getTitle()); } elseif ($app->get('sitename_pagetitles', 0) == 2) { $title = Text::sprintf('JPAGETITLE', $data->getTitle(), $app->get('sitename')); } $feed_title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8'); $feed = "<feed xmlns=\"http://www.w3.org/2005/Atom\""; if ($data->getLanguage() != '') { $feed .= " xml:lang=\"" . $data->getLanguage() . "\""; } $feed .= ">\n"; $feed .= " <title type=\"text\">" . $feed_title . "</title>\n"; $feed .= " <subtitle type=\"text\">" . htmlspecialchars($data->getDescription() ?? '', ENT_COMPAT, 'UTF-8') . "</subtitle>\n"; if (!empty($data->category)) { if (\is_array($data->category)) { foreach ($data->category as $cat) { $feed .= " <category term=\"" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "\" />\n"; } } else { $feed .= " <category term=\"" . htmlspecialchars($data->category, ENT_COMPAT, 'UTF-8') . "\" />\n"; } } $feed .= " <link rel=\"alternate\" type=\"text/html\" href=\"" . $url . "\"/>\n"; $feed .= " <id>" . str_replace(' ', '%20', $data->getBase()) . "</id>\n"; $feed .= " <updated>" . htmlspecialchars($now->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</updated>\n"; if ($data->editor != '') { $feed .= " <author>\n"; $feed .= " <name>" . $data->editor . "</name>\n"; if ($data->editorEmail != '') { $feed .= " <email>" . htmlspecialchars($data->editorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n"; } $feed .= " </author>\n"; } $versionHtmlEscaped = ''; if ($app->get('MetaVersion', 0)) { $minorVersion = Version::MAJOR_VERSION . '.' . Version::MINOR_VERSION; $versionHtmlEscaped = ' version="' . htmlspecialchars($minorVersion, ENT_COMPAT, 'UTF-8') . '"'; } $feed .= " <generator uri=\"https://www.joomla.org\"" . $versionHtmlEscaped . ">" . $data->getGenerator() . "</generator>\n"; $feed .= " <link rel=\"self\" type=\"application/atom+xml\" href=\"" . str_replace(' ', '%20', $url . $syndicationURL) . "\"/>\n"; for ($i = 0, $count = \count($data->items); $i < $count; $i++) { $itemlink = $data->items[$i]->link; if (preg_match('/[\x80-\xFF]/', $itemlink)) { $itemlink = implode('/', array_map('rawurlencode', explode('/', $itemlink))); } $feed .= " <entry>\n"; $feed .= " <title>" . htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT, 'UTF-8') . "</title>\n"; $feed .= " <link rel=\"alternate\" type=\"text/html\" href=\"" . $url . $itemlink . "\"/>\n"; if ($data->items[$i]->date == '') { $data->items[$i]->date = $now->toUnix(); } $itemDate = Factory::getDate($data->items[$i]->date); $itemDate->setTimezone($tz); $feed .= " <published>" . htmlspecialchars($itemDate->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</published>\n"; $feed .= " <updated>" . htmlspecialchars($itemDate->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</updated>\n"; if (empty($data->items[$i]->guid)) { $itemGuid = str_replace(' ', '%20', $url . $itemlink); } else { $itemGuid = htmlspecialchars($data->items[$i]->guid, ENT_COMPAT, 'UTF-8'); } $feed .= " <id>" . $itemGuid . "</id>\n"; if ($data->items[$i]->author != '') { $feed .= " <author>\n"; $feed .= " <name>" . htmlspecialchars($data->items[$i]->author, ENT_COMPAT, 'UTF-8') . "</name>\n"; if (!empty($data->items[$i]->authorEmail)) { $feed .= " <email>" . htmlspecialchars($data->items[$i]->authorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n"; } $feed .= " </author>\n"; } if (!empty($data->items[$i]->description)) { $feed .= " <summary type=\"html\">" . htmlspecialchars($this->_relToAbs($data->items[$i]->description), ENT_COMPAT, 'UTF-8') . "</summary>\n"; $feed .= " <content type=\"html\">" . htmlspecialchars($this->_relToAbs($data->items[$i]->description), ENT_COMPAT, 'UTF-8') . "</content>\n"; } if (!empty($data->items[$i]->category)) { if (\is_array($data->items[$i]->category)) { foreach ($data->items[$i]->category as $cat) { $feed .= " <category term=\"" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "\" />\n"; } } else { $feed .= " <category term=\"" . htmlspecialchars($data->items[$i]->category, ENT_COMPAT, 'UTF-8') . "\" />\n"; } } if ($data->items[$i]->enclosure != null) { $feed .= " <link rel=\"enclosure\" href=\"" . $data->items[$i]->enclosure->url . "\" type=\"" . $data->items[$i]->enclosure->type . "\" length=\"" . $data->items[$i]->enclosure->length . "\"/>\n"; } $feed .= " </entry>\n"; } $feed .= "</feed>\n"; return $feed; } } Renderer/Partial/ModulesRenderer.php 0000604 00000003701 15172704424 0013521 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Partial; defined('JPATH_PLATFORM') or die; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\Helper\ModuleHelper; use Joomla\CMS\Layout\LayoutHelper; /** * HTML document renderer for a module position * * @since 3.5 */ class ModulesRenderer extends DocumentRenderer { /** * Renders multiple modules script and returns the results as a string * * @param string $position The position of the modules to render * @param array $params Associative array of values * @param string $content Module content * * @return string The output of the script * * @since 3.5 */ public function render($position, $params = array(), $content = null) { $renderer = $this->_doc->loadRenderer('module'); $buffer = ''; $app = \JFactory::getApplication(); $user = \JFactory::getUser(); $frontediting = ($app->isClient('site') && $app->get('frontediting', 1) && !$user->guest); $menusEditing = ($app->get('frontediting', 1) == 2) && $user->authorise('core.edit', 'com_menus'); foreach (ModuleHelper::getModules($position) as $mod) { $moduleHtml = $renderer->render($mod, $params, $content); if ($frontediting && trim($moduleHtml) != '' && $user->authorise('module.edit.frontend', 'com_modules.module.' . $mod->id)) { $displayData = array('moduleHtml' => &$moduleHtml, 'module' => $mod, 'position' => $position, 'menusediting' => $menusEditing); LayoutHelper::render('joomla.edit.frontediting_modules', $displayData); } $buffer .= $moduleHtml; } \JEventDispatcher::getInstance()->trigger('onAfterRenderModules', array(&$buffer, &$params)); return $buffer; } } Renderer/Partial/MessageRenderer.php 0000604 00000004252 15172704424 0013477 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Partial; defined('JPATH_PLATFORM') or die; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\Log\Log; use Joomla\CMS\Layout\LayoutHelper; /** * HTML document renderer for the system message queue * * @since 3.5 */ class MessageRenderer extends DocumentRenderer { /** * Renders the error stack and returns the results as a string * * @param string $name Not used. * @param array $params Associative array of values * @param string $content Not used. * * @return string The output of the script * * @since 3.5 */ public function render($name, $params = array(), $content = null) { $msgList = $this->getData(); $displayData = array( 'msgList' => $msgList, 'name' => $name, 'params' => $params, 'content' => $content, ); $app = \JFactory::getApplication(); $chromePath = JPATH_THEMES . '/' . $app->getTemplate() . '/html/message.php'; if (file_exists($chromePath)) { include_once $chromePath; } if (function_exists('renderMessage')) { Log::add('renderMessage() is deprecated. Override system message rendering with layouts instead.', Log::WARNING, 'deprecated'); return renderMessage($msgList); } return LayoutHelper::render('joomla.system.message', $displayData); } /** * Get and prepare system message data for output * * @return array An array contains system message * * @since 3.5 */ private function getData() { // Initialise variables. $lists = array(); // Get the message queue $messages = \JFactory::getApplication()->getMessageQueue(); // Build the sorted message list if (is_array($messages) && !empty($messages)) { foreach ($messages as $msg) { if (isset($msg['type']) && isset($msg['message'])) { $lists[$msg['type']][] = $msg['message']; } } } return $lists; } } Renderer/Partial/HeadRenderer.php 0000604 00000031031 15172704424 0012747 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Partial; defined('JPATH_PLATFORM') or die; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\Helper\TagsHelper; use Joomla\CMS\Uri\Uri; use Joomla\Utilities\ArrayHelper; use Joomla\CMS\Factory; /** * HTML document renderer for the document `<head>` element * * @since 3.5 */ class HeadRenderer extends DocumentRenderer { public $excludeJsFiles = array( '/jquery.js', '/bootstrap.js' ); public $keeperJsFiles = array( '/components/com_fabrik/js/' ); /** * Renders the document head 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 3.5 */ public function render($head, $params = array(), $content = null) { return $this->fetchHead($this->_doc); } /** * Generates the head HTML and return the results as a string * * @param JDocumentHtml $document The document for which the head will be created * * @return string The head hTML * * @since 3.5 * @deprecated 4.0 Method code will be moved into the render method */ public function fetchHead($document) { // Convert the tagids to titles if (isset($document->_metaTags['name']['tags'])) { $tagsHelper = new TagsHelper; $document->_metaTags['name']['tags'] = implode(', ', $tagsHelper->getTagNames($document->_metaTags['name']['tags'])); } if ($document->getScriptOptions()) { \JHtml::_('behavior.core'); } // Trigger the onBeforeCompileHead event $app = \JFactory::getApplication(); $app->triggerEvent('onBeforeCompileHead'); // Get line endings $lnEnd = $document->_getLineEnd(); $tab = $document->_getTab(); $tagEnd = ' />'; $buffer = ''; $mediaVersion = $document->getMediaVersion(); // Generate charset when using HTML5 (should happen first) if ($document->isHtml5()) { $buffer .= $tab . '<meta charset="' . $document->getCharset() . '" />' . $lnEnd; } // Generate base tag (need to happen early) $base = $document->getBase(); if (!empty($base)) { $buffer .= $tab . '<base href="' . $base . '" />' . $lnEnd; } // Generate META tags (needs to happen as early as possible in the head) foreach ($document->_metaTags as $type => $tag) { foreach ($tag as $name => $content) { if ($type == 'http-equiv' && !($document->isHtml5() && $name == 'content-type')) { $buffer .= $tab . '<meta http-equiv="' . $name . '" content="' . htmlspecialchars($content, ENT_COMPAT, 'UTF-8') . '" />' . $lnEnd; } elseif ($type != 'http-equiv' && !empty($content)) { if (is_array($content)) { foreach ($content as $value) { $buffer .= $tab . '<meta ' . $type . '="' . $name . '" content="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '" />' . $lnEnd; } } else { $buffer .= $tab . '<meta ' . $type . '="' . $name . '" content="' . htmlspecialchars($content, ENT_COMPAT, 'UTF-8') . '" />' . $lnEnd; } } } } // Don't add empty descriptions $documentDescription = $document->getDescription(); if ($documentDescription) { $buffer .= $tab . '<meta name="description" content="' . htmlspecialchars($documentDescription, ENT_COMPAT, 'UTF-8') . '" />' . $lnEnd; } // Don't add empty generators $generator = $document->getGenerator(); if ($generator) { $buffer .= $tab . '<meta name="generator" content="' . htmlspecialchars($generator, ENT_COMPAT, 'UTF-8') . '" />' . $lnEnd; } $buffer .= $tab . '<title>' . htmlspecialchars($document->getTitle(), ENT_COMPAT, 'UTF-8') . '</title>' . $lnEnd; // Generate link declarations foreach ($document->_links as $link => $linkAtrr) { $buffer .= $tab . '<link href="' . $link . '" ' . $linkAtrr['relType'] . '="' . $linkAtrr['relation'] . '"'; if (is_array($linkAtrr['attribs'])) { if ($temp = ArrayHelper::toString($linkAtrr['attribs'])) { $buffer .= ' ' . $temp; } } $buffer .= ' />' . $lnEnd; } $defaultCssMimes = array('text/css'); // Generate stylesheet links foreach ($document->_styleSheets as $src => $attribs) { // Check if stylesheet uses IE conditional statements. $conditional = isset($attribs['options']) && isset($attribs['options']['conditional']) ? $attribs['options']['conditional'] : null; // Check if script uses media version. if (isset($attribs['options']['version']) && $attribs['options']['version'] && strpos($src, '?') === false && ($mediaVersion || $attribs['options']['version'] !== 'auto')) { $src .= '?' . ($attribs['options']['version'] === 'auto' ? $mediaVersion : $attribs['options']['version']); } $buffer .= $tab; // This is for IE conditional statements support. if (!is_null($conditional)) { $buffer .= '<!--[if ' . $conditional . ']>'; } $buffer .= '<link href="' . $src . '" rel="stylesheet"'; // Add script tag attributes. foreach ($attribs as $attrib => $value) { // Don't add the 'options' attribute. This attribute is for internal use (version, conditional, etc). if ($attrib === 'options') { continue; } // Don't add type attribute if document is HTML5 and it's a default mime type. 'mime' is for B/C. if (in_array($attrib, array('type', 'mime')) && $document->isHtml5() && in_array($value, $defaultCssMimes)) { continue; } // Don't add type attribute if document is HTML5 and it's a default mime type. 'mime' is for B/C. if ($attrib === 'mime') { $attrib = 'type'; } // Add attribute to script tag output. $buffer .= ' ' . htmlspecialchars($attrib, ENT_COMPAT, 'UTF-8'); // Json encode value if it's an array. $value = !is_scalar($value) ? json_encode($value) : $value; $buffer .= '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; } $buffer .= $tagEnd; // This is for IE conditional statements support. if (!is_null($conditional)) { $buffer .= '<![endif]-->'; } $buffer .= $lnEnd; } // Generate stylesheet declarations foreach ($document->_style as $type => $content) { $buffer .= $tab . '<style'; if (!is_null($type) && (!$document->isHtml5() || !in_array($type, $defaultCssMimes))) { $buffer .= ' type="' . $type . '"'; } $buffer .= '>' . $lnEnd; // This is for full XHTML support. if ($document->_mime != 'text/html') { $buffer .= $tab . $tab . '/*<![CDATA[*/' . $lnEnd; } $buffer .= $content . $lnEnd; // See above note if ($document->_mime != 'text/html') { $buffer .= $tab . $tab . '/*]]>*/' . $lnEnd; } $buffer .= $tab . '</style>' . $lnEnd; } // Generate scripts options $scriptOptions = $document->getScriptOptions(); if (!empty($scriptOptions)) { $buffer .= $tab . '<script type="application/json" class="joomla-script-options new">'; $prettyPrint = (JDEBUG && defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : false); $jsonOptions = json_encode($scriptOptions, $prettyPrint); $jsonOptions = $jsonOptions ? $jsonOptions : '{}'; $buffer .= $jsonOptions; $buffer .= '</script>' . $lnEnd; } $defaultJsMimes = array('text/javascript', 'application/javascript', 'text/x-javascript', 'application/x-javascript'); $html5NoValueAttributes = array('defer', 'async'); $excludeJsFiles = $this->getHeadCache(); // Generate script file links foreach ($document->_scripts as $src => $attribs) { foreach ($excludeJsFiles as $exclude) { foreach ($this->keeperJsFiles as $keeper) { if (strstr($exclude, $keeper)) { continue 2; } } if (strstr($src, $exclude)) { continue 2; } } // Check if script uses IE conditional statements. $conditional = isset($attribs['options']) && isset($attribs['options']['conditional']) ? $attribs['options']['conditional'] : null; // Check if script uses media version. if (isset($attribs['options']['version']) && $attribs['options']['version'] && strpos($src, '?') === false && ($mediaVersion || $attribs['options']['version'] !== 'auto')) { $src .= '?' . ($attribs['options']['version'] === 'auto' ? $mediaVersion : $attribs['options']['version']); } $buffer .= $tab; // This is for IE conditional statements support. if (!is_null($conditional)) { $buffer .= '<!--[if ' . $conditional . ']>'; } $buffer .= '<script src="' . $src . '"'; // Add script tag attributes. foreach ($attribs as $attrib => $value) { // Don't add the 'options' attribute. This attribute is for internal use (version, conditional, etc). if ($attrib === 'options') { continue; } // Don't add type attribute if document is HTML5 and it's a default mime type. 'mime' is for B/C. if (in_array($attrib, array('type', 'mime')) && $document->isHtml5() && in_array($value, $defaultJsMimes)) { continue; } // B/C: If defer and async is false or empty don't render the attribute. if (in_array($attrib, array('defer', 'async')) && !$value) { continue; } // Don't add type attribute if document is HTML5 and it's a default mime type. 'mime' is for B/C. if ($attrib === 'mime') { $attrib = 'type'; } // B/C defer and async can be set to yes when using the old method. elseif (in_array($attrib, array('defer', 'async')) && $value === true) { $value = $attrib; } // Add attribute to script tag output. $buffer .= ' ' . htmlspecialchars($attrib, ENT_COMPAT, 'UTF-8'); if (!($document->isHtml5() && in_array($attrib, $html5NoValueAttributes))) { // Json encode value if it's an array. $value = !is_scalar($value) ? json_encode($value) : $value; $buffer .= '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; } } $buffer .= '></script>'; // This is for IE conditional statements support. if (!is_null($conditional)) { $buffer .= '<![endif]-->'; } $buffer .= $lnEnd; } // Generate script declarations foreach ($document->_script as $type => $content) { $buffer .= $tab . '<script'; if (!is_null($type) && (!$document->isHtml5() || !in_array($type, $defaultJsMimes))) { $buffer .= ' type="' . $type . '"'; } $buffer .= '>' . $lnEnd; // This is for full XHTML support. if ($document->_mime != 'text/html') { $buffer .= $tab . $tab . '//<![CDATA[' . $lnEnd; } $buffer .= $content . $lnEnd; // See above note if ($document->_mime != 'text/html') { $buffer .= $tab . $tab . '//]]>' . $lnEnd; } $buffer .= $tab . '</script>' . $lnEnd; } // Output the custom tags - array_unique makes sure that we don't output the same tags twice foreach (array_unique($document->_custom) as $custom) { $buffer .= $tab . $custom . $lnEnd; } return ltrim($buffer, $tab); } private function getHeadCache() { $session = \JFactory::getSession(); $doc = \JFactory::getDocument(); $app = \JFactory::getApplication(); $uri = parse_url($app->input->server->get('HTTP_REFERER', '', 'string')); $key = $uri['path']; $qs = ArrayHelper::getValue($uri, 'query', ''); if (!empty($qs)) { $key .= '?' . $qs; } $key = md5($key); $scripts = $this->excludeJsFiles; if (!empty($key)) { $key = 'fabrik.js.head.cache.' . $key; $cachedScripts = $session->get($key, ''); if (!empty($cachedScripts)) { $scripts = json_decode($cachedScripts); $scripts = ArrayHelper::fromObject($scripts); $scripts = array_keys($scripts); } } return $scripts; } } Renderer/Partial/ComponentRenderer.php 0000604 00000001665 15172704424 0014062 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Partial; defined('JPATH_PLATFORM') or die; use Joomla\CMS\Document\DocumentRenderer; /** * HTML document renderer for the component output * * @since 3.5 */ class ComponentRenderer extends DocumentRenderer { /** * Renders a component script and returns the results as a string * * @param string $component The name of the component to render * @param array $params Associative array of values * @param string $content Content script * * @return string The output of the script * * @since 3.5 */ public function render($component = null, $params = array(), $content = null) { return $content; } } Renderer/Partial/ModuleRenderer.php 0000604 00000005424 15172704424 0013342 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Partial; defined('JPATH_PLATFORM') or die; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\Helper\ModuleHelper; use Joomla\CMS\Log\Log; use Joomla\CMS\Layout\LayoutHelper; use Joomla\Registry\Registry; /** * HTML document renderer for a single module * * @since 3.5 */ class ModuleRenderer extends DocumentRenderer { /** * Renders a module script and returns the results as a string * * @param string $module The name of the module to render * @param array $attribs Associative array of values * @param string $content If present, module information from the buffer will be used * * @return string The output of the script * * @since 3.5 */ public function render($module, $attribs = array(), $content = null) { if (!is_object($module)) { $title = isset($attribs['title']) ? $attribs['title'] : null; $module = ModuleHelper::getModule($module, $title); if (!is_object($module)) { if (is_null($content)) { return ''; } /** * If module isn't found in the database but data has been pushed in the buffer * we want to render it */ $tmp = $module; $module = new \stdClass; $module->params = null; $module->module = $tmp; $module->id = 0; $module->user = 0; } } // Set the module content if (!is_null($content)) { $module->content = $content; } // Get module parameters $params = new Registry($module->params); // Use parameters from template if (isset($attribs['params'])) { $template_params = new Registry(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8')); $params->merge($template_params); $module = clone $module; $module->params = (string) $params; } // Default for compatibility purposes. Set cachemode parameter or use JModuleHelper::moduleCache from within the module instead $cachemode = $params->get('cachemode', 'oldstatic'); if ($params->get('cache', 0) == 1 && \JFactory::getConfig()->get('caching') >= 1 && $cachemode != 'id' && $cachemode != 'safeuri') { // Default to itemid creating method and workarounds on $cacheparams = new \stdClass; $cacheparams->cachemode = $cachemode; $cacheparams->class = 'JModuleHelper'; $cacheparams->method = 'renderModule'; $cacheparams->methodparams = array($module, $attribs); return ModuleHelper::ModuleCache($module, $params, $cacheparams); } return ModuleHelper::renderModule($module, $attribs); } } Renderer/Html/ModulesRenderer.php 0000644 00000004117 15172704424 0013037 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Html; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\Factory; use Joomla\CMS\Helper\ModuleHelper; use Joomla\CMS\Layout\LayoutHelper; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * HTML document renderer for a module position * * @since 3.5 */ class ModulesRenderer extends DocumentRenderer { /** * Renders multiple modules script and returns the results as a string * * @param string $position The position of the modules to render * @param array $params Associative array of values * @param string $content Module content * * @return string The output of the script * * @since 3.5 */ public function render($position, $params = [], $content = null) { $renderer = $this->_doc->loadRenderer('module'); $buffer = ''; $app = Factory::getApplication(); $user = Factory::getUser(); $frontediting = ($app->isClient('site') && $app->get('frontediting', 1) && !$user->guest); $menusEditing = ($app->get('frontediting', 1) == 2) && $user->authorise('core.edit', 'com_menus'); foreach (ModuleHelper::getModules($position) as $mod) { $moduleHtml = $renderer->render($mod, $params, $content); if ($frontediting && trim($moduleHtml) != '' && $user->authorise('module.edit.frontend', 'com_modules.module.' . $mod->id)) { $displayData = ['moduleHtml' => &$moduleHtml, 'module' => $mod, 'position' => $position, 'menusediting' => $menusEditing]; LayoutHelper::render('joomla.edit.frontediting_modules', $displayData); } $buffer .= $moduleHtml; } $app->triggerEvent('onAfterRenderModules', [&$buffer, &$params]); return $buffer; } } Renderer/Html/MessageRenderer.php 0000644 00000004704 15172704424 0013015 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Html; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\Factory; use Joomla\CMS\Layout\LayoutHelper; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * HTML document renderer for the system message queue * * @since 3.5 */ class MessageRenderer extends DocumentRenderer { /** * Renders the error stack and returns the results as a string * * @param string $name Not used. * @param array $params Associative array of values * @param string $content Not used. * * @return string The output of the script * * @since 3.5 */ public function render($name, $params = [], $content = null) { $msgList = $this->getData(); $displayData = [ 'msgList' => $msgList, 'name' => $name, 'params' => $params, 'content' => $content, ]; $app = Factory::getApplication(); $chromePath = JPATH_THEMES . '/' . $app->getTemplate() . '/html/message.php'; if (is_file($chromePath)) { include_once $chromePath; } if (\function_exists('renderMessage')) { @trigger_error( 'renderMessage() is deprecated. Override system message rendering with layouts instead.', E_USER_DEPRECATED ); return renderMessage($msgList); } return LayoutHelper::render('joomla.system.message', $displayData); } /** * Get and prepare system message data for output * * @return array An array contains system message * * @since 3.5 */ private function getData() { // Initialise variables. $lists = []; // Get the message queue $messages = Factory::getApplication()->getMessageQueue(); // Build the sorted message list if (\is_array($messages) && !empty($messages)) { foreach ($messages as $msg) { if (isset($msg['type']) && isset($msg['message'])) { $lists[$msg['type']][] = $msg['message']; } } } return $lists; } } Renderer/Html/ScriptsRenderer.php 0000644 00000025144 15172704424 0013061 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Html; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\WebAsset\WebAssetItemInterface; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * JDocument head renderer * * @since 4.0.0 */ class ScriptsRenderer extends DocumentRenderer { /** * List of already rendered src * * @var array * * @since 4.0.0 */ private $renderedSrc = []; /** * Renders the document script tags 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 = [], $content = null) { // Get line endings $lnEnd = $this->_doc->_getLineEnd(); $tab = $this->_doc->_getTab(); $buffer = ''; $wam = $this->_doc->getWebAssetManager(); $assets = $wam->getAssets('script', true); // Get a list of inline assets and their relation with regular assets $inlineAssets = $wam->filterOutInlineAssets($assets); $inlineRelation = $wam->getInlineRelation($inlineAssets); // Merge with existing scripts, for rendering $assets = array_merge(array_values($assets), $this->_doc->_scripts); // Generate script file links foreach ($assets as $key => $item) { // Check whether we have an Asset instance, or old array with attributes $asset = $item instanceof WebAssetItemInterface ? $item : null; // Add src attribute for non Asset item if (!$asset) { $item['src'] = $key; } // Check for inline content "before" if ($asset && !empty($inlineRelation[$asset->getName()]['before'])) { foreach ($inlineRelation[$asset->getName()]['before'] as $itemBefore) { $buffer .= $this->renderInlineElement($itemBefore); // Remove this item from inline queue unset($inlineAssets[$itemBefore->getName()]); } } $buffer .= $this->renderElement($item); // Check for inline content "after" if ($asset && !empty($inlineRelation[$asset->getName()]['after'])) { foreach ($inlineRelation[$asset->getName()]['after'] as $itemBefore) { $buffer .= $this->renderInlineElement($itemBefore); // Remove this item from inline queue unset($inlineAssets[$itemBefore->getName()]); } } } // Generate script declarations for assets foreach ($inlineAssets as $item) { $buffer .= $this->renderInlineElement($item); } // Generate script declarations for old scripts foreach ($this->_doc->_script as $type => $contents) { // Test for B.C. in case someone still store script declarations as single string if (\is_string($contents)) { $contents = [$contents]; } foreach ($contents as $content) { $buffer .= $this->renderInlineElement( [ 'type' => $type, 'content' => $content, ] ); } } // Output the custom tags - array_unique makes sure that we don't output the same tags twice foreach (array_unique($this->_doc->_custom) as $custom) { $buffer .= $tab . $custom . $lnEnd; } return ltrim($buffer, $tab); } /** * Renders the element * * @param WebAssetItemInterface|array $item The element * * @return string The resulting string * * @since 4.0.0 */ private function renderElement($item): string { $buffer = ''; $asset = $item instanceof WebAssetItemInterface ? $item : null; $src = $asset ? $asset->getUri() : ($item['src'] ?? ''); // Make sure we have a src, and it not already rendered if (!$src || !empty($this->renderedSrc[$src]) || ($asset && $asset->getOption('webcomponent'))) { return ''; } $lnEnd = $this->_doc->_getLineEnd(); $tab = $this->_doc->_getTab(); $mediaVersion = $this->_doc->getMediaVersion(); // Get the attributes and other options if ($asset) { $attribs = $asset->getAttributes(); $version = $asset->getVersion(); $conditional = $asset->getOption('conditional'); // Add an asset info for debugging if (JDEBUG) { $attribs['data-asset-name'] = $asset->getName(); if ($asset->getDependencies()) { $attribs['data-asset-dependencies'] = implode(',', $asset->getDependencies()); } if ($asset->getOption('deprecated')) { @trigger_error( sprintf('Web Asset script [%s] is deprecated. %s', $asset->getName(), $asset->getOption('deprecatedMsg', '')), E_USER_DEPRECATED ); } } } else { $attribs = $item; $version = isset($attribs['options']['version']) ? $attribs['options']['version'] : ''; $conditional = !empty($attribs['options']['conditional']) ? $attribs['options']['conditional'] : null; } // Add "nonce" attribute if exist if ($this->_doc->cspNonce && !is_null($this->_doc->cspNonce)) { $attribs['nonce'] = $this->_doc->cspNonce; } // To prevent double rendering $this->renderedSrc[$src] = true; // Check if script uses media version. if ($version && strpos($src, '?') === false && ($mediaVersion || $version !== 'auto')) { $src .= '?' . ($version === 'auto' ? $mediaVersion : $version); } $buffer .= $tab; // This is for IE conditional statements support. if (!\is_null($conditional)) { $buffer .= '<!--[if ' . $conditional . ']>'; } // Render the element with attributes $buffer .= '<script src="' . htmlspecialchars($src) . '"'; $buffer .= $this->renderAttributes($attribs); $buffer .= '></script>'; // This is for IE conditional statements support. if (!\is_null($conditional)) { $buffer .= '<![endif]-->'; } $buffer .= $lnEnd; return $buffer; } /** * Renders the inline element * * @param WebAssetItemInterface|array $item The element * * @return string The resulting string * * @since 4.0.0 */ private function renderInlineElement($item): string { $buffer = ''; $lnEnd = $this->_doc->_getLineEnd(); $tab = $this->_doc->_getTab(); if ($item instanceof WebAssetItemInterface) { $attribs = $item->getAttributes(); $content = $item->getOption('content'); } else { $attribs = $item; $content = $item['content'] ?? ''; unset($attribs['content']); } // Do not produce empty elements if (!$content) { return ''; } // Add "nonce" attribute if exist if ($this->_doc->cspNonce && !is_null($this->_doc->cspNonce)) { $attribs['nonce'] = $this->_doc->cspNonce; } $buffer .= $tab . '<script'; $buffer .= $this->renderAttributes($attribs); $buffer .= '>'; // This is for full XHTML support. if ($this->_doc->_mime !== 'text/html') { $buffer .= $tab . $tab . '//<![CDATA[' . $lnEnd; } $buffer .= $content; // See above note if ($this->_doc->_mime !== 'text/html') { $buffer .= $tab . $tab . '//]]>' . $lnEnd; } $buffer .= '</script>' . $lnEnd; return $buffer; } /** * Renders the element attributes * * @param array $attributes The element attributes * * @return string The attributes string * * @since 4.0.0 */ private function renderAttributes(array $attributes): string { $buffer = ''; $defaultJsMimes = ['text/javascript', 'application/javascript', 'text/x-javascript', 'application/x-javascript']; $html5NoValueAttributes = ['defer', 'async', 'nomodule']; foreach ($attributes as $attrib => $value) { // Don't add the 'options' attribute. This attribute is for internal use (version, conditional, etc). if ($attrib === 'options' || $attrib === 'src') { continue; } // Don't add type attribute if document is HTML5 and it's a default mime type. 'mime' is for B/C. if (\in_array($attrib, ['type', 'mime']) && $this->_doc->isHtml5() && \in_array($value, $defaultJsMimes)) { continue; } // B/C: If defer and async is false or empty don't render the attribute. Also skip if value is bool:false. if (\in_array($attrib, ['defer', 'async']) && !$value || $value === false) { continue; } // NoValue attribute, if it have bool:true $isNoValueAttrib = $value === true || \in_array($attrib, $html5NoValueAttributes); // Don't add type attribute if document is HTML5 and it's a default mime type. 'mime' is for B/C. if ($attrib === 'mime') { $attrib = 'type'; } elseif ($isNoValueAttrib) { // NoValue attribute in non HTML5 should contain a value, set it equal to attribute name. $value = $attrib; } // Add attribute to script tag output. $buffer .= ' ' . htmlspecialchars($attrib, ENT_COMPAT, 'UTF-8'); if (!($this->_doc->isHtml5() && $isNoValueAttrib)) { // Json encode value if it's an array. $value = !is_scalar($value) ? json_encode($value) : $value; $buffer .= '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; } } return $buffer; } } Renderer/Html/ComponentRenderer.php 0000644 00000001774 15172704424 0013377 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Html; use Joomla\CMS\Document\DocumentRenderer; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * HTML document renderer for the component output * * @since 3.5 */ class ComponentRenderer extends DocumentRenderer { /** * Renders a component script and returns the results as a string * * @param string $component The name of the component to render * @param array $params Associative array of values * @param string $content Content script * * @return string The output of the script * * @since 3.5 */ public function render($component = null, $params = [], $content = null) { return $content; } } Renderer/Html/StylesRenderer.php 0000644 00000024337 15172704424 0012720 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Html; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\WebAsset\WebAssetItemInterface; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * JDocument styles renderer * * @since 4.0.0 */ class StylesRenderer extends DocumentRenderer { /** * List of already rendered src * * @var array * * @since 4.0.0 */ private $renderedSrc = []; /** * Renders the document stylesheets and style tags 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 = [], $content = null) { $tab = $this->_doc->_getTab(); $buffer = ''; $wam = $this->_doc->getWebAssetManager(); $assets = $wam->getAssets('style', true); // Get a list of inline assets and their relation with regular assets $inlineAssets = $wam->filterOutInlineAssets($assets); $inlineRelation = $wam->getInlineRelation($inlineAssets); // Merge with existing styleSheets, for rendering $assets = array_merge(array_values($assets), $this->_doc->_styleSheets); // Generate stylesheet links foreach ($assets as $key => $item) { $asset = $item instanceof WebAssetItemInterface ? $item : null; // Add href attribute for non Asset item if (!$asset) { $item['href'] = $key; } // Check for inline content "before" if ($asset && !empty($inlineRelation[$asset->getName()]['before'])) { foreach ($inlineRelation[$asset->getName()]['before'] as $itemBefore) { $buffer .= $this->renderInlineElement($itemBefore); // Remove this item from inline queue unset($inlineAssets[$itemBefore->getName()]); } } $buffer .= $this->renderElement($item); // Check for inline content "after" if ($asset && !empty($inlineRelation[$asset->getName()]['after'])) { foreach ($inlineRelation[$asset->getName()]['after'] as $itemBefore) { $buffer .= $this->renderInlineElement($itemBefore); // Remove this item from inline queue unset($inlineAssets[$itemBefore->getName()]); } } } // Generate script declarations for assets foreach ($inlineAssets as $item) { $buffer .= $this->renderInlineElement($item); } // Generate stylesheet declarations foreach ($this->_doc->_style as $type => $contents) { // Test for B.C. in case someone still store stylesheet declarations as single string if (\is_string($contents)) { $contents = [$contents]; } foreach ($contents as $content) { $buffer .= $this->renderInlineElement( [ 'type' => $type, 'content' => $content, ] ); } } return ltrim($buffer, $tab); } /** * Renders the element * * @param WebAssetItemInterface|array $item The element * * @return string The resulting string * * @since 4.0.0 */ private function renderElement($item): string { $buffer = ''; $asset = $item instanceof WebAssetItemInterface ? $item : null; $src = $asset ? $asset->getUri() : ($item['href'] ?? ''); // Make sure we have a src, and it not already rendered if (!$src || !empty($this->renderedSrc[$src])) { return ''; } $lnEnd = $this->_doc->_getLineEnd(); $tab = $this->_doc->_getTab(); $mediaVersion = $this->_doc->getMediaVersion(); // Get the attributes and other options if ($asset) { $attribs = $asset->getAttributes(); $version = $asset->getVersion(); $conditional = $asset->getOption('conditional'); // Add an asset info for debugging if (JDEBUG) { $attribs['data-asset-name'] = $asset->getName(); if ($asset->getDependencies()) { $attribs['data-asset-dependencies'] = implode(',', $asset->getDependencies()); } if ($asset->getOption('deprecated')) { @trigger_error( sprintf('Web Asset style [%s] is deprecated. %s', $asset->getName(), $asset->getOption('deprecatedMsg', '')), E_USER_DEPRECATED ); } } } else { $attribs = $item; $version = isset($attribs['options']['version']) ? $attribs['options']['version'] : ''; $conditional = !empty($attribs['options']['conditional']) ? $attribs['options']['conditional'] : null; } // Add "nonce" attribute if exist if ($this->_doc->cspNonce && !is_null($this->_doc->cspNonce)) { $attribs['nonce'] = $this->_doc->cspNonce; } // To prevent double rendering $this->renderedSrc[$src] = true; // Check if script uses media version. if ($version && strpos($src, '?') === false && ($mediaVersion || $version !== 'auto')) { $src .= '?' . ($version === 'auto' ? $mediaVersion : $version); } $buffer .= $tab; // This is for IE conditional statements support. if (!\is_null($conditional)) { $buffer .= '<!--[if ' . $conditional . ']>'; } $relation = isset($attribs['rel']) ? $attribs['rel'] : 'stylesheet'; if (isset($attribs['rel'])) { unset($attribs['rel']); } // Render the element with attributes $buffer .= '<link href="' . htmlspecialchars($src) . '" rel="' . $relation . '"'; $buffer .= $this->renderAttributes($attribs); $buffer .= ' />'; if ($relation === 'lazy-stylesheet') { $buffer .= '<noscript><link href="' . htmlspecialchars($src) . '" rel="stylesheet" /></noscript>'; } // This is for IE conditional statements support. if (!\is_null($conditional)) { $buffer .= '<![endif]-->'; } $buffer .= $lnEnd; return $buffer; } /** * Renders the inline element * * @param WebAssetItemInterface|array $item The element * * @return string The resulting string * * @since 4.0.0 */ private function renderInlineElement($item): string { $buffer = ''; $lnEnd = $this->_doc->_getLineEnd(); $tab = $this->_doc->_getTab(); if ($item instanceof WebAssetItemInterface) { $attribs = $item->getAttributes(); $content = $item->getOption('content'); } else { $attribs = $item; $content = $item['content'] ?? ''; unset($attribs['content']); } // Do not produce empty elements if (!$content) { return ''; } // Add "nonce" attribute if exist if ($this->_doc->cspNonce && !is_null($this->_doc->cspNonce)) { $attribs['nonce'] = $this->_doc->cspNonce; } $buffer .= $tab . '<style'; $buffer .= $this->renderAttributes($attribs); $buffer .= '>'; // This is for full XHTML support. if ($this->_doc->_mime !== 'text/html') { $buffer .= $tab . $tab . '/*<![CDATA[*/' . $lnEnd; } $buffer .= $content; // See above note if ($this->_doc->_mime !== 'text/html') { $buffer .= $tab . $tab . '/*]]>*/' . $lnEnd; } $buffer .= '</style>' . $lnEnd; return $buffer; } /** * Renders the element attributes * * @param array $attributes The element attributes * * @return string The attributes string * * @since 4.0.0 */ private function renderAttributes(array $attributes): string { $buffer = ''; $defaultCssMimes = ['text/css']; foreach ($attributes as $attrib => $value) { // Don't add the 'options' attribute. This attribute is for internal use (version, conditional, etc). if ($attrib === 'options' || $attrib === 'href') { continue; } // Don't add type attribute if document is HTML5 and it's a default mime type. 'mime' is for B/C. if (\in_array($attrib, ['type', 'mime']) && $this->_doc->isHtml5() && \in_array($value, $defaultCssMimes)) { continue; } // Skip the attribute if value is bool:false. if ($value === false) { continue; } // NoValue attribute, if it have bool:true $isNoValueAttrib = $value === true; // Don't add type attribute if document is HTML5 and it's a default mime type. 'mime' is for B/C. if ($attrib === 'mime') { $attrib = 'type'; } elseif ($isNoValueAttrib) { // NoValue attribute in non HTML5 should contain a value, set it equal to attribute name. $value = $attrib; } // Add attribute to script tag output. $buffer .= ' ' . htmlspecialchars($attrib, ENT_COMPAT, 'UTF-8'); if (!($this->_doc->isHtml5() && $isNoValueAttrib)) { // Json encode value if it's an array. $value = !is_scalar($value) ? json_encode($value) : $value; $buffer .= '="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"'; } } return $buffer; } } Renderer/Html/HeadRenderer.php 0000644 00000002363 15172704424 0012271 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Html; use Joomla\CMS\Document\DocumentRenderer; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * HTML document renderer for the document `<head>` element * * @since 3.5 */ class HeadRenderer extends DocumentRenderer { /** * Renders the document head 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 3.5 */ public function render($head, $params = [], $content = null) { $buffer = ''; $buffer .= $this->_doc->loadRenderer('metas')->render($head, $params, $content); $buffer .= $this->_doc->loadRenderer('styles')->render($head, $params, $content); $buffer .= $this->_doc->loadRenderer('scripts')->render($head, $params, $content); return $buffer; } } Renderer/Html/MetasRenderer.php 0000644 00000015354 15172704424 0012505 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ 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 = [], $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 . '<meta charset="' . $this->_doc->getCharset() . '">' . $lnEnd; } // Generate base tag (need to happen early) $base = $this->_doc->getBase(); if (!empty($base)) { $buffer .= $tab . '<base href="' . $base . '">' . $lnEnd; } $noFavicon = true; $searchFor = 'image/vnd.microsoft.icon'; array_map(function ($value) use (&$noFavicon, $searchFor) { if (isset($value['attribs']['type']) && $value['attribs']['type'] === $searchFor) { $noFavicon = false; } }, array_values((array)$this->_doc->_links)); if ($noFavicon) { $client = $app->isClient('administrator') === true ? 'administrator/' : 'site/'; $template = $app->getTemplate(true); // Try to find a favicon by checking the template and root folder $icon = '/favicon.ico'; $foldersToCheck = [ JPATH_BASE, JPATH_ROOT . '/media/templates/' . $client . $template->template, JPATH_BASE . '/templates/' . $template->template, ]; foreach ($foldersToCheck as $base => $dir) { if ( $template->parent !== '' && $base === 1 && !is_file(JPATH_ROOT . '/media/templates/' . $client . $template->template . $icon) ) { $dir = JPATH_ROOT . '/media/templates/' . $client . $template->parent; } if (is_file($dir . $icon)) { $urlBase = in_array($base, [0, 2]) ? Uri::base(true) : Uri::root(true); $base = in_array($base, [0, 2]) ? JPATH_BASE : JPATH_ROOT; $path = str_replace($base, '', $dir); $path = str_replace('\\', '/', $path); $this->_doc->addFavicon($urlBase . $path . $icon); break; } } } // Generate META tags (needs to happen as early as possible in the head) foreach ($this->_doc->_metaTags as $type => $tag) { foreach ($tag as $name => $contents) { if ($type === 'http-equiv' && !($this->_doc->isHtml5() && $name === 'content-type')) { $buffer .= $tab . '<meta http-equiv="' . $name . '" content="' . htmlspecialchars($contents, ENT_COMPAT, 'UTF-8') . '">' . $lnEnd; } elseif ($type !== 'http-equiv' && !empty($contents)) { $buffer .= $tab . '<meta ' . $type . '="' . $name . '" content="' . htmlspecialchars($contents, ENT_COMPAT, 'UTF-8') . '">' . $lnEnd; } } } // Don't add empty descriptions $documentDescription = $this->_doc->getDescription(); if ($documentDescription) { $buffer .= $tab . '<meta name="description" content="' . htmlspecialchars($documentDescription, ENT_COMPAT, 'UTF-8') . '">' . $lnEnd; } // Don't add empty generators $generator = $this->_doc->getGenerator(); if ($generator) { $buffer .= $tab . '<meta name="generator" content="' . htmlspecialchars($generator, ENT_COMPAT, 'UTF-8') . '">' . $lnEnd; } $buffer .= $tab . '<title>' . htmlspecialchars($this->_doc->getTitle(), ENT_COMPAT, 'UTF-8') . '</title>' . $lnEnd; // Generate link declarations foreach ($this->_doc->_links as $link => $linkAtrr) { $buffer .= $tab . '<link href="' . $link . '" ' . $linkAtrr['relType'] . '="' . $linkAtrr['relation'] . '"'; if (\is_array($linkAtrr['attribs'])) { if ($temp = ArrayHelper::toString($linkAtrr['attribs'])) { $buffer .= ' ' . $temp; } } $buffer .= '>' . $lnEnd; } return ltrim($buffer, $tab); } } Renderer/Html/ModuleRenderer.php 0000644 00000006631 15172704424 0012657 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document\Renderer\Html; use Joomla\CMS\Document\DocumentRenderer; use Joomla\CMS\Factory; use Joomla\CMS\Helper\ModuleHelper; use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * HTML document renderer for a single module * * @since 3.5 */ class ModuleRenderer extends DocumentRenderer { /** * Renders a module script and returns the results as a string * * @param string $module The name of the module to render * @param array $attribs Associative array of values * @param string $content If present, module information from the buffer will be used * * @return string The output of the script * * @since 3.5 */ public function render($module, $attribs = [], $content = null) { if (!\is_object($module)) { $title = $attribs['title'] ?? null; $module = ModuleHelper::getModule($module, $title); if (!\is_object($module)) { if (\is_null($content)) { return ''; } /** * If module isn't found in the database but data has been pushed in the buffer * we want to render it */ $tmp = $module; $module = new \stdClass(); $module->params = null; $module->module = $tmp; $module->id = 0; $module->user = 0; } } // Set the module content if (!\is_null($content)) { $module->content = $content; } // Get module parameters $params = new Registry($module->params); // Use parameters from template if (isset($attribs['params'])) { $template_params = new Registry(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8')); $params->merge($template_params); $module = clone $module; $module->params = (string) $params; } // Set cachemode parameter or use JModuleHelper::moduleCache from within the module instead $cachemode = $params->get('cachemode', 'static'); if ($params->get('cache', 0) == 1 && Factory::getApplication()->get('caching') >= 1 && $cachemode !== 'id' && $cachemode !== 'safeuri') { // Default to itemid creating method and workarounds on $cacheparams = new \stdClass(); $cacheparams->cachemode = $cachemode; $cacheparams->class = ModuleHelper::class; $cacheparams->method = 'renderModule'; $cacheparams->methodparams = [$module, $attribs]; $cacheparams->cachesuffix = $attribs['contentOnly'] ?? false; // It need to be done here because the cache controller does not keep reference to the module object $module->content = ModuleHelper::moduleCache($module, $params, $cacheparams); $module->contentRendered = true; return $module->content; } return ModuleHelper::renderModule($module, $attribs); } } HtmlDocument.php 0000644 00000062022 15172704424 0007670 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; use Joomla\CMS\Cache\Cache; use Joomla\CMS\Cache\CacheControllerFactoryAwareInterface; use Joomla\CMS\Cache\CacheControllerFactoryAwareTrait; use Joomla\CMS\Factory as CmsFactory; use Joomla\CMS\Filter\InputFilter; use Joomla\CMS\Helper\ModuleHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Uri\Uri; use Joomla\CMS\Utility\Utility; use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * HtmlDocument class, provides an easy interface to parse and display a HTML document * * @since 1.7.0 */ class HtmlDocument extends Document implements CacheControllerFactoryAwareInterface { use CacheControllerFactoryAwareTrait; /** * Array of Header `<link>` tags * * @var array * @since 1.7.0 */ public $_links = []; /** * Array of custom tags * * @var array * @since 1.7.0 */ public $_custom = []; /** * Name of the template * * @var string * @since 1.7.0 */ public $template = null; /** * Base url * * @var string * @since 1.7.0 */ public $baseurl = null; /** * Array of template parameters * * @var array * @since 1.7.0 */ public $params = null; /** * File name * * @var array * @since 1.7.0 */ public $_file = null; /** * Script nonce (string if set, null otherwise) * * @var string|null * @since 4.0.0 */ public $cspNonce = null; /** * String holding parsed template * * @var string * @since 1.7.0 */ protected $_template = ''; /** * Array of parsed template JDoc tags * * @var array * @since 1.7.0 */ protected $_template_tags = []; /** * Integer with caching setting * * @var integer * @since 1.7.0 */ protected $_caching = null; /** * Set to true when the document should be output as HTML5 * * @var boolean * @since 4.0.0 */ private $html5 = true; /** * Class constructor * * @param array $options Associative array of options * * @since 1.7.0 */ public function __construct($options = []) { parent::__construct($options); // Set document type $this->_type = 'html'; // Set default mime type and document metadata (metadata syncs with mime type by default) $this->setMimeEncoding('text/html'); } /** * Get the HTML document head data * * @return array The document head data in array form * * @since 1.7.0 */ public function getHeadData() { $data = []; $data['title'] = $this->title; $data['description'] = $this->description; $data['link'] = $this->link; $data['metaTags'] = $this->_metaTags; $data['links'] = $this->_links; $data['styleSheets'] = $this->_styleSheets; $data['style'] = $this->_style; $data['scripts'] = $this->_scripts; $data['script'] = $this->_script; $data['custom'] = $this->_custom; /** * @deprecated 4.0 will be removed in 6.0 * This property is for backwards compatibility. Pass text through script options in the future */ $data['scriptText'] = Text::getScriptStrings(); $data['scriptOptions'] = $this->scriptOptions; // Get Asset manager state $wa = $this->getWebAssetManager(); $waState = $wa->getManagerState(); // Get asset objects and filter only manually added/enabled assets, // Dependencies will be picked up from registry files $waState['assets'] = []; foreach ($waState['activeAssets'] as $assetType => $assetNames) { foreach ($assetNames as $assetName => $assetState) { $waState['assets'][$assetType][] = $wa->getAsset($assetType, $assetName); } } // We have loaded asset objects, now can remove unused stuff unset($waState['activeAssets']); $data['assetManager'] = $waState; return $data; } /** * Reset the HTML document head data * * @param mixed $types type or types of the heads elements to reset * * @return HtmlDocument instance of $this to allow chaining * * @since 3.7.0 */ public function resetHeadData($types = null) { if (\is_null($types)) { $this->title = ''; $this->description = ''; $this->link = ''; $this->_metaTags = []; $this->_links = []; $this->_styleSheets = []; $this->_style = []; $this->_scripts = []; $this->_script = []; $this->_custom = []; $this->scriptOptions = []; } if (\is_array($types)) { foreach ($types as $type) { $this->resetHeadDatum($type); } } if (\is_string($types)) { $this->resetHeadDatum($types); } return $this; } /** * Reset a part the HTML document head data * * @param string $type type of the heads elements to reset * * @return void * * @since 3.7.0 */ private function resetHeadDatum($type) { switch ($type) { case 'title': case 'description': case 'link': $this->{$type} = ''; break; case 'metaTags': case 'links': case 'styleSheets': case 'style': case 'scripts': case 'script': case 'custom': $realType = '_' . $type; $this->{$realType} = []; break; case 'scriptOptions': $this->{$type} = []; break; } } /** * Set the HTML document head data * * @param array $data The document head data in array form * * @return HtmlDocument|null instance of $this to allow chaining or null for empty input data * * @since 1.7.0 */ public function setHeadData($data) { if (empty($data) || !\is_array($data)) { return null; } $this->title = $data['title'] ?? $this->title; $this->description = $data['description'] ?? $this->description; $this->link = $data['link'] ?? $this->link; $this->_metaTags = $data['metaTags'] ?? $this->_metaTags; $this->_links = $data['links'] ?? $this->_links; $this->_styleSheets = $data['styleSheets'] ?? $this->_styleSheets; $this->_style = $data['style'] ?? $this->_style; $this->_scripts = $data['scripts'] ?? $this->_scripts; $this->_script = $data['script'] ?? $this->_script; $this->_custom = $data['custom'] ?? $this->_custom; $this->scriptOptions = (isset($data['scriptOptions']) && !empty($data['scriptOptions'])) ? $data['scriptOptions'] : $this->scriptOptions; // Restore asset manager state $wa = $this->getWebAssetManager(); if (!empty($data['assetManager']['registryFiles'])) { $waRegistry = $wa->getRegistry(); foreach ($data['assetManager']['registryFiles'] as $registryFile) { $waRegistry->addRegistryFile($registryFile); } } if (!empty($data['assetManager']['assets'])) { foreach ($data['assetManager']['assets'] as $assetType => $assets) { foreach ($assets as $asset) { $wa->registerAsset($assetType, $asset)->useAsset($assetType, $asset->getName()); } } } return $this; } /** * Merge the HTML document head data * * @param array $data The document head data in array form * * @return HtmlDocument instance of $this to allow chaining * * @since 1.7.0 */ public function mergeHeadData($data) { if (empty($data) || !\is_array($data)) { return $this; } $this->title = (isset($data['title']) && !empty($data['title']) && !stristr($this->title, $data['title'])) ? $this->title . $data['title'] : $this->title; $this->description = (isset($data['description']) && !empty($data['description']) && !stristr($this->description, $data['description'])) ? $this->description . $data['description'] : $this->description; $this->link = $data['link'] ?? $this->link; if (isset($data['metaTags'])) { foreach ($data['metaTags'] as $type1 => $data1) { $booldog = $type1 === 'http-equiv'; foreach ($data1 as $name2 => $data2) { $this->setMetaData($name2, $data2, $booldog); } } } $this->_links = (isset($data['links']) && !empty($data['links']) && \is_array($data['links'])) ? array_unique(array_merge($this->_links, $data['links']), SORT_REGULAR) : $this->_links; $this->_styleSheets = (isset($data['styleSheets']) && !empty($data['styleSheets']) && \is_array($data['styleSheets'])) ? array_merge($this->_styleSheets, $data['styleSheets']) : $this->_styleSheets; if (isset($data['style'])) { foreach ($data['style'] as $type => $styles) { foreach ($styles as $hash => $style) { if (!isset($this->_style[strtolower($type)][$hash])) { $this->addStyleDeclaration($style, $type); } } } } $this->_scripts = (isset($data['scripts']) && !empty($data['scripts']) && \is_array($data['scripts'])) ? array_merge($this->_scripts, $data['scripts']) : $this->_scripts; if (isset($data['script'])) { foreach ($data['script'] as $type => $scripts) { foreach ($scripts as $hash => $script) { if (!isset($this->_script[strtolower($type)][$hash])) { $this->addScriptDeclaration($script, $type); } } } } $this->_custom = (isset($data['custom']) && !empty($data['custom']) && \is_array($data['custom'])) ? array_unique(array_merge($this->_custom, $data['custom'])) : $this->_custom; if (!empty($data['scriptOptions'])) { foreach ($data['scriptOptions'] as $key => $scriptOptions) { $this->addScriptOptions($key, $scriptOptions, true); } } // Restore asset manager state $wa = $this->getWebAssetManager(); if (!empty($data['assetManager']['registryFiles'])) { $waRegistry = $wa->getRegistry(); foreach ($data['assetManager']['registryFiles'] as $registryFile) { $waRegistry->addRegistryFile($registryFile); } } if (!empty($data['assetManager']['assets'])) { foreach ($data['assetManager']['assets'] as $assetType => $assets) { foreach ($assets as $asset) { $wa->registerAsset($assetType, $asset)->useAsset($assetType, $asset->getName()); } } } return $this; } /** * Adds `<link>` tags to the head of the document * * $relType defaults to 'rel' as it is the most common relation type used. * ('rev' refers to reverse relation, 'rel' indicates normal, forward relation.) * Typical tag: `<link href="index.php" rel="Start">` * * @param string $href The link that is being related. * @param string $relation Relation of link. * @param string $relType Relation type attribute. Either rel or rev (default: 'rel'). * @param array $attribs Associative array of remaining attributes. * * @return HtmlDocument instance of $this to allow chaining * * @since 1.7.0 */ public function addHeadLink($href, $relation, $relType = 'rel', $attribs = []) { $this->_links[$href]['relation'] = $relation; $this->_links[$href]['relType'] = $relType; $this->_links[$href]['attribs'] = $attribs; return $this; } /** * Adds a shortcut icon (favicon) * * This adds a link to the icon shown in the favorites list or on * the left of the url in the address bar. Some browsers display * it on the tab, as well. * * @param string $href The link that is being related. * @param string $type File type * @param string $relation Relation of link * * @return HtmlDocument instance of $this to allow chaining * * @since 1.7.0 */ public function addFavicon($href, $type = 'image/vnd.microsoft.icon', $relation = 'icon') { $href = str_replace('\\', '/', $href); $this->addHeadLink($href, $relation, 'rel', ['type' => $type]); return $this; } /** * Adds a custom HTML string to the head block * * @param string $html The HTML to add to the head * * @return HtmlDocument instance of $this to allow chaining * * @since 1.7.0 */ public function addCustomTag($html) { $this->_custom[] = trim($html); return $this; } /** * Returns whether the document is set up to be output as HTML5 * * @return boolean true when HTML5 is used * * @since 3.0.0 */ public function isHtml5() { return $this->html5; } /** * Sets whether the document should be output as HTML5 * * @param bool $state True when HTML5 should be output * * @return void * * @since 3.0.0 */ public function setHtml5($state) { if (\is_bool($state)) { $this->html5 = $state; } } /** * Get the contents of a document include * * @param string $type The type of renderer * @param string $name The name of the element to render * @param array $attribs Associative array of remaining attributes. * * @return mixed|string The output of the renderer * * @since 1.7.0 */ public function getBuffer($type = null, $name = null, $attribs = []) { // If no type is specified, return the whole buffer if ($type === null) { return parent::$_buffer; } $title = $attribs['title'] ?? null; if (isset(parent::$_buffer[$type][$name][$title])) { return parent::$_buffer[$type][$name][$title]; } $renderer = $this->loadRenderer($type); if ($this->_caching == true && $type === 'modules' && $name !== 'debug') { /** @var \Joomla\CMS\Document\Renderer\Html\ModulesRenderer $renderer */ /** @var \Joomla\CMS\Cache\Controller\OutputController $cache */ $cache = $this->getCacheControllerFactory()->createCacheController('output', ['defaultgroup' => 'com_modules']); $itemId = (int) CmsFactory::getApplication()->getInput()->get('Itemid', 0, 'int'); $hash = md5( serialize( [ $name, $attribs, \get_class($renderer), $itemId, ] ) ); $cbuffer = $cache->get('cbuffer_' . $type) ?: []; if (isset($cbuffer[$hash])) { return Cache::getWorkarounds($cbuffer[$hash], ['mergehead' => 1]); } $options = []; $options['nopathway'] = 1; $options['nomodules'] = 1; $options['modulemode'] = 1; $this->setBuffer($renderer->render($name, $attribs, null), $type, $name); $data = parent::$_buffer[$type][$name][$title]; $tmpdata = Cache::setWorkarounds($data, $options); $cbuffer[$hash] = $tmpdata; $cache->store($cbuffer, 'cbuffer_' . $type); } else { $this->setBuffer($renderer->render($name, $attribs, null), $type, $name, $title); } return parent::$_buffer[$type][$name][$title]; } /** * Set the contents a document includes * * @param string $content The content to be set in the buffer. * @param array $options Array of optional elements. * * @return HtmlDocument instance of $this to allow chaining * * @since 1.7.0 */ public function setBuffer($content, $options = []) { // The following code is just for backward compatibility. if (\func_num_args() > 1 && !\is_array($options)) { $args = \func_get_args(); $options = []; $options['type'] = $args[1]; $options['name'] = $args[2] ?? null; $options['title'] = $args[3] ?? null; } $type = $options['type'] ?? ''; $name = $options['name'] ?? ''; $title = $options['title'] ?? ''; parent::$_buffer[$type][$name][$title] = $content; return $this; } /** * Parses the template and populates the buffer * * @param array $params Parameters for fetching the template * * @return HtmlDocument instance of $this to allow chaining * * @since 1.7.0 */ public function parse($params = []) { return $this->_fetchTemplate($params)->_parseTemplate(); } /** * Outputs the template to the browser. * * @param boolean $caching If true, cache the output * @param array $params Associative array of attributes * * @return string The rendered data * * @since 1.7.0 */ public function render($caching = false, $params = []) { $this->_caching = $caching; if (empty($this->_template)) { $this->parse($params); } if (\array_key_exists('csp_nonce', $params) && $params['csp_nonce'] !== null) { $this->cspNonce = $params['csp_nonce']; } $data = $this->_renderTemplate(); parent::render($caching, $params); return $data; } /** * Count the modules in the given position * * @param string $positionName The position to use * @param boolean $withContentOnly Count only a modules which actually has a content * * @return integer Number of modules found * * @since 1.7.0 */ public function countModules(string $positionName, bool $withContentOnly = false) { if ((isset(parent::$_buffer['modules'][$positionName])) && (parent::$_buffer['modules'][$positionName] === false)) { return 0; } $modules = ModuleHelper::getModules($positionName); if (!$withContentOnly) { return \count($modules); } // Now we need to count only modules which actually have a content $result = 0; $renderer = $this->loadRenderer('module'); foreach ($modules as $module) { if (empty($module->contentRendered)) { $renderer->render($module, ['contentOnly' => true]); } if (trim($module->content) !== '') { $result++; } } return $result; } /** * Count the number of child menu items of the current active menu item * * @return integer Number of child menu items * * @since 1.7.0 * * @deprecated 4.4 will be removed in 6.0 * Load the active menu item directly and count the children with the php count function * `$children = count($app->getMenu()->getActive()->getChildren())` beware getActive could be `null` */ public function countMenuChildren() { $active = CmsFactory::getApplication()->getMenu()->getActive(); return $active ? count($active->getChildren()) : 0; } /** * Load a template file * * @param string $directory The name of the template * @param string $filename The actual filename * * @return string The contents of the template * * @since 1.7.0 */ protected function _loadTemplate($directory, $filename) { $contents = ''; // Check to see if we have a valid template file if (is_file($directory . '/' . $filename)) { // Store the file path $this->_file = $directory . '/' . $filename; // Get the file content ob_start(); require $directory . '/' . $filename; $contents = ob_get_contents(); ob_end_clean(); } return $contents; } /** * Fetch the template, and initialise the params * * @param array $params Parameters to determine the template * * @return HtmlDocument instance of $this to allow chaining * * @since 1.7.0 */ protected function _fetchTemplate($params = []) { // Check $directory = $params['directory'] ?? 'templates'; $filter = InputFilter::getInstance(); $template = $filter->clean($params['template'], 'cmd'); $file = $filter->clean($params['file'], 'cmd'); $inherits = $params['templateInherits'] ?? ''; $baseDir = $directory . '/' . $template; if (!is_file($directory . '/' . $template . '/' . $file)) { if ($inherits !== '' && is_file($directory . '/' . $inherits . '/' . $file)) { $baseDir = $directory . '/' . $inherits; } else { $baseDir = $directory . '/system'; $template = 'system'; if ($file !== 'index.php' && !is_file($baseDir . '/' . $file)) { $file = 'index.php'; } } } // Load the language file for the template $lang = CmsFactory::getLanguage(); // 1.5 or core then 1.6 $lang->load('tpl_' . $template, JPATH_BASE) || ($inherits !== '' && $lang->load('tpl_' . $inherits, JPATH_BASE)) || $lang->load('tpl_' . $template, $directory . '/' . $template) || ($inherits !== '' && $lang->load('tpl_' . $inherits, $directory . '/' . $inherits)); // Assign the variables $this->baseurl = Uri::base(true); $this->params = $params['params'] ?? new Registry(); $this->template = $template; // Load $this->_template = $this->_loadTemplate($baseDir, $file); return $this; } /** * Parse a document template * * @return HtmlDocument instance of $this to allow chaining * * @since 1.7.0 */ protected function _parseTemplate() { $matches = []; if (preg_match_all('#<jdoc:include\ type="([^"]+)"(.*)\/>#iU', $this->_template, $matches)) { $messages = []; $template_tags_first = []; $template_tags_last = []; // Step through the jdocs in reverse order. for ($i = \count($matches[0]) - 1; $i >= 0; $i--) { $type = $matches[1][$i]; $attribs = empty($matches[2][$i]) ? [] : Utility::parseAttributes($matches[2][$i]); $name = $attribs['name'] ?? null; // Separate buffers to be executed first and last if ($type === 'module' || $type === 'modules') { $template_tags_first[$matches[0][$i]] = ['type' => $type, 'name' => $name, 'attribs' => $attribs]; } elseif ($type === 'message') { $messages = [$matches[0][$i] => ['type' => $type, 'name' => $name, 'attribs' => $attribs]]; } else { $template_tags_last[$matches[0][$i]] = ['type' => $type, 'name' => $name, 'attribs' => $attribs]; } } $this->_template_tags = $template_tags_first + $messages + array_reverse($template_tags_last); } return $this; } /** * Render pre-parsed template * * @return string rendered template * * @since 1.7.0 */ protected function _renderTemplate() { $replace = []; $with = []; foreach ($this->_template_tags as $jdoc => $args) { $replace[] = $jdoc; $with[] = $this->getBuffer($args['type'], $args['name'], $args['attribs']); } return str_replace($replace, $with, $this->_template); } } JsonDocument.php 0000644 00000005143 15172704424 0007676 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Document; use Joomla\CMS\Factory as CmsFactory; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * JsonDocument class, provides an easy interface to parse and display JSON output * * @link http://www.json.org/ * @since 1.7.0 */ class JsonDocument extends Document { /** * Document name * * @var string * @since 1.7.0 */ protected $_name = 'joomla'; /** * Class constructor * * @param array $options Associative array of options * * @since 1.7.0 */ public function __construct($options = []) { parent::__construct($options); // Set mime type if ( isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') === false && strpos($_SERVER['HTTP_ACCEPT'], 'text/html') !== false ) { // Internet Explorer < 10 $this->_mime = 'text/plain'; } else { $this->_mime = 'application/json'; } // Set document type $this->_type = 'json'; } /** * Render the document. * * @param boolean $cache If true, cache the output * @param array $params Associative array of attributes * * @return string The rendered data * * @since 1.7.0 */ public function render($cache = false, $params = []) { /** @var \Joomla\CMS\Application\CMSApplication $app */ $app = CmsFactory::getApplication(); $app->allowCache($cache); if ($this->_mime === 'application/json') { // Browser other than Internet Explorer < 10 $app->setHeader('Content-Disposition', 'attachment; filename="' . $this->getName() . '.json"', true); } parent::render($cache, $params); return $this->getBuffer(); } /** * Returns the document name * * @return string * * @since 1.7.0 */ public function getName() { return $this->_name; } /** * Sets the document name * * @param string $name Document name * * @return JsonDocument instance of $this to allow chaining * * @since 1.7.0 */ public function setName($name = 'joomla') { $this->_name = $name; return $this; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0 |
proxy
|
phpinfo
|
Settings