diff --git a/build/build-modules-js/settings.json b/build/build-modules-js/settings.json index fff256698be76..5e604d79dac09 100644 --- a/build/build-modules-js/settings.json +++ b/build/build-modules-js/settings.json @@ -249,7 +249,8 @@ }, "filesExtra": { "scss": "scss", - "webfonts": "webfonts" + "webfonts": "webfonts", + "svgs": "images" }, "provideAssets": [ { diff --git a/libraries/src/Document/HtmlDocument.php b/libraries/src/Document/HtmlDocument.php index f33f7004752a4..06de3f2b9fb37 100644 --- a/libraries/src/Document/HtmlDocument.php +++ b/libraries/src/Document/HtmlDocument.php @@ -14,6 +14,7 @@ use Joomla\CMS\Factory as CmsFactory; use Joomla\CMS\Filter\InputFilter; use Joomla\CMS\Helper\ModuleHelper; +use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Log\Log; use Joomla\CMS\Uri\Uri; @@ -116,6 +117,14 @@ class HtmlDocument extends Document */ private $html5 = true; + /** + * Array of icons + * + * @var array + * @since 4.0.0 + */ + private $icons = array(); + /** * Class constructor * @@ -132,6 +141,11 @@ public function __construct($options = array()) // Set default mime type and document metadata (metadata syncs with mime type by default) $this->setMimeEncoding('text/html'); + + if (array_key_exists('icons', $options)) + { + $this->setIcons($options['icons']); + } } /** @@ -154,6 +168,7 @@ public function getHeadData() $data['scripts'] = $this->_scripts; $data['script'] = $this->_script; $data['custom'] = $this->_custom; + $data['icons'] = $this->icons; // @deprecated 5.0 This property is for backwards compatibility. Pass text through script options in the future $data['scriptText'] = Text::getScriptStrings(); @@ -163,6 +178,73 @@ public function getHeadData() return $data; } + /** + * Returns the icon names + * + * @return array + * + * @since 4.0.0 + */ + public function getIcons() + { + return $this->icons; + } + + /** + * Setter for all icons + * + * @param array $icons + * @return string + * + * @since 4.0.0 + */ + public function setIcons($icons = []) + { + $this->icons = $icons; + } + + /** + * Setter for an icon + * + * @param array $icon + * @return string + * + * @since 4.0.0 + */ + public function setIcon($icon = []) + { + if (empty($icon['icon'])) + { + return ''; + } + + $attribs = ''; + $provider = $icon['provider'] ? $icon['provider'] : 'fontawesome-free'; + $group = $icon['group'] ? $icon['group'] : 'solid'; + $classes = $icon['classes'] ? $icon['classes'] : ''; + + // Setup options object + if (!in_array($provider . '.' . $group . '.' . $icon['icon'], $this->getIcons())) + { + $this->icons[$provider . '.' . $group . '.' . $icon['icon']] = [ + 'provider' => $provider, + 'group' => $group, + 'icon' => $icon['icon'], + 'text' => $icon['text'] ? $icon['text'] : '' + ]; + } + + if (isset($icon['attributes']) && count($icon['attributes'])) + { + foreach ($icon['attributes'] as $key => $val) + { + $attribs .= $key . '="' . $val . '" '; + } + } + + return ''; + } + /** * Reset the HTML document head data * @@ -186,6 +268,7 @@ public function resetHeadData($types = null) $this->_scripts = array(); $this->_script = array(); $this->_custom = array(); + $this->icons = array(); $this->scriptOptions = array(); } @@ -235,6 +318,10 @@ private function resetHeadDatum($type) $this->{$realType} = array(); break; + case 'icons': + $this->icons = array(); + break; + case 'scriptOptions': $this->{$type} = array(); break; @@ -267,6 +354,7 @@ public function setHeadData($data) $this->_scripts = $data['scripts'] ?? $this->_scripts; $this->_script = $data['script'] ?? $this->_script; $this->_custom = $data['custom'] ?? $this->_custom; + $this->icons = $data['icons'] ?? $this->icons; $this->scriptOptions = (isset($data['scriptOptions']) && !empty($data['scriptOptions'])) ? $data['scriptOptions'] : $this->scriptOptions; return $this; diff --git a/libraries/src/Document/Renderer/Html/IconsRenderer.php b/libraries/src/Document/Renderer/Html/IconsRenderer.php new file mode 100644 index 0000000000000..21c258ad66c71 --- /dev/null +++ b/libraries/src/Document/Renderer/Html/IconsRenderer.php @@ -0,0 +1,69 @@ +_doc->getIcons() as $key => $icon) + { + $file = HTMLHelper::image('vendor/' . $icon['provider'] . '/' . $icon['group'] . '/' . $icon['icon'] . '.svg', '', null, true, 1); + + if ($file) + { + $content = @file_get_contents(JPATH_ROOT . substr($file, strpos($file, '/media'))); + $content = str_replace( + '_doc->setIcons([]); + + return '
' . implode('', $files) . '
'; + } + + return ''; + } +} diff --git a/modules/mod_login/tmpl/default.php b/modules/mod_login/tmpl/default.php index c164e99ec6565..ca620175ea76b 100644 --- a/modules/mod_login/tmpl/default.php +++ b/modules/mod_login/tmpl/default.php @@ -10,6 +10,7 @@ defined('_JEXEC') or die; use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Plugin\PluginHelper; @@ -21,6 +22,19 @@ Text::script('JSHOWPASSWORD'); Text::script('JHIDEPASSWORD'); + +Factory::getDocument()->addStyleDeclaration( +<<