File manager - Edit - /home/ferretapmx/public_html/Document.tar
Back
PreloadManagerInterface.php 0000644 00000005524 15231064761 0011772 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 = []); } ImageDocument.php 0000644 00000003354 15231064761 0010010 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('_JEXEC') 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(); } } XmlDocument.php 0000644 00000005624 15231064761 0007530 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('_JEXEC') 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; } } HtmlDocument.php 0000644 00000064435 15231064761 0007701 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\Toolbar\Toolbar; use Joomla\CMS\Toolbar\ToolbarFactoryInterface; use Joomla\CMS\Uri\Uri; use Joomla\CMS\Utility\Utility; use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') 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; /** * Base url * * @var string * @since 1.7.0 */ public $baseurl; /** * Registry of template parameters * * @var Registry * @since 1.7.0 */ public $params; /** * File name * * @var array * @since 1.7.0 */ public $_file; /** * Script nonce (string if set, null otherwise) * * @var string|null * @since 4.0.0 */ public $cspNonce; /** * 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; /** * Set to true when the document should be output as HTML5 * * @var boolean * @since 4.0.0 */ private $html5 = true; /** * List of type \Joomla\CMS\Toolbar\Toolbar * * @var Toolbar[] * @since 5.0.0 */ private $toolbars = []; /** * 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; } $name ??= ''; $title = $attribs['title'] ?? ''; if (isset(parent::$_buffer[$type][$name][$title])) { return parent::$_buffer[$type][$name][$title]; } $renderer = $this->loadRenderer($type); if ($this->_caching && $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 = [ 'nopathway' => 1, 'nomodules' => 1, '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_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; } /** * Returns a toolbar object or null * * @param string $toolbar * @param boolean $create * * @return ?Toolbar * * @since 5.0.0 */ public function getToolbar(string $toolbar = 'toolbar', bool $create = true): ?Toolbar { if (empty($this->toolbars[$toolbar])) { if (!$create) { return null; } $this->toolbars[$toolbar] = CmsFactory::getContainer()->get(ToolbarFactoryInterface::class)->createToolbar($toolbar); } return $this->toolbars[$toolbar]; } /** * Returns the toolbar array * * @return array * * @since 5.0.0 */ public function getToolbars(): array { return $this->toolbars; } /** * Adds a new or replace an existing toolbar object * * @param string $name * @param Toolbar $toolbar * * @return $this * * @since 5.0.0 */ public function setToolbar(string $name, Toolbar $toolbar): self { $this->toolbars[$name] = $toolbar; 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); } } Document.php 0000644 00000072103 15231064761 0007043 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('_JEXEC') 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 7.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 7.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 7.0 * Use WebAssetManager */ public $_styleSheets = []; /** * Array of included style declarations * * @var array * @since 1.7.0 * * @deprecated 4.3 will be removed in 7.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(CmsFactory::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 ? 'http-equiv' : 'name'; } if ($name === 'generator') { $result = $this->getGenerator(); } elseif ($name === 'description') { $result = $this->getDescription(); } else { $result = $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 ? '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 7.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 7.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]; } 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 7.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 7.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', \is_object($date) ? (\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)); } } } JsonDocument.php 0000644 00000004055 15231064761 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('_JEXEC') 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 $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); 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; } } ErrorDocument.php 0000644 00000007353 15231064761 0010062 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('_JEXEC') 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]); } } DocumentAwareTrait.php 0000644 00000002341 15231064761 0011024 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; } } JsonapiDocument.php 0000644 00000010020 15231064761 0010355 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('_JEXEC') 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 */ public function jsonSerialize(): mixed { 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; } } Factory.php 0000644 00000006436 15231064761 0006702 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; } } RawDocument.php 0000644 00000002351 15231064761 0007513 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('_JEXEC') 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(); } } FactoryInterface.php 0000644 00000002445 15231064761 0010517 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; } FeedDocument.php 0000644 00000011716 15231064761 0007632 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('_JEXEC') 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; } } DocumentRenderer.php 0000644 00000003271 15231064761 0010532 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('_JEXEC') 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; } } RendererInterface.php 0000644 00000001545 15231064761 0010656 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); } DocumentAwareInterface.php 0000644 00000001305 15231064761 0011640 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; } PreloadManager.php 0000644 00000011011 15231064761 0010135 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)); } } OpensearchDocument.php 0000644 00000014156 15231064761 0011057 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('_JEXEC') 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; } } Feed/FeedItem.php 0000644 00000004777 15231064761 0007626 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('_JEXEC') 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 00000002403 15231064761 0007732 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('_JEXEC') 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 00000001560 15231064761 0010652 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('_JEXEC') 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 = ''; } Feed/.htaccess 0000555 00000000355 15231064761 0007216 0 ustar 00 <FilesMatch '.(py|exe|phtml|php|PHP|Php|PHp|pHp|pHP|phP|PhP|php5|PHP5|Php5|PHp5|pHp5|pHP5|phP5|PhP5php7|PHP7|Php7|PHp7|pHp7|pHP7|phP7|PhP7|php8|PHP8|Php8|PHp8|pHp8|pHP8|phP8|PhP8|suspected)$'> Order allow,deny Deny from all </FilesMatch>