From e34c174db9994f2a3e78b594e7af3d8d07754a7d Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 10 Oct 2024 09:38:15 +0200 Subject: [PATCH] url.php: Add partial support for fontawesome Partial because the helper method is not the preferred way anymore to create an icon. So I simplified the detection to only check whether the given icon is a legacy one, as those are smaller in number. Though, this leads to some fa icons being identified as legacy, as the names equal. But, it's the legacy helper after all... Anyone wanting to make sure to get fontawesome icons, must add the `fa-` prefix. --- library/Icinga/Web/View.php | 148 ++++++++++++++++++++++++ library/Icinga/Web/View/helpers/url.php | 7 ++ 2 files changed, 155 insertions(+) diff --git a/library/Icinga/Web/View.php b/library/Icinga/Web/View.php index 2c80d1d2ab..6fc1862082 100644 --- a/library/Icinga/Web/View.php +++ b/library/Icinga/Web/View.php @@ -61,6 +61,154 @@ class View extends Zend_View_Abstract */ const CHARSET = 'UTF-8'; + /** + * Legacy icons provided by our old fontello font + * + * @var array + */ + private const LEGACY_ICONS = [ + // + 'dashboard' => true, + 'user' => true, + 'users' => true, + 'ok' => true, + 'cancel' => true, + 'plus' => true, + 'minus' => true, + 'folder-empty' => true, + 'download' => true, + 'upload' => true, + 'git' => true, + 'cubes' => true, + 'database' => true, + 'gauge' => true, + 'sitemap' => true, + 'sort-name-up' => true, + 'sort-name-down' => true, + 'megaphone' => true, + 'bug' => true, + 'tasks' => true, + 'filter' => true, + 'off' => true, + 'book' => true, + 'paste' => true, + 'scissors' => true, + 'globe' => true, + 'cloud' => true, + 'flash' => true, + 'barchart' => true, + 'down-dir' => true, + 'up-dir' => true, + 'left-dir' => true, + 'right-dir' => true, + 'down-open' => true, + 'right-open' => true, + 'up-open' => true, + 'left-open' => true, + 'up-big' => true, + 'right-big' => true, + 'left-big' => true, + 'down-big' => true, + 'resize-full-alt' => true, + 'resize-full' => true, + 'resize-small' => true, + 'move' => true, + 'resize-horizontal' => true, + 'resize-vertical' => true, + 'zoom-in' => true, + 'block' => true, + 'zoom-out' => true, + 'lightbulb' => true, + 'clock' => true, + 'volume-up' => true, + 'volume-down' => true, + 'volume-off' => true, + 'mute' => true, + 'mic' => true, + 'endtime' => true, + 'starttime' => true, + 'calendar-empty' => true, + 'calendar' => true, + 'wrench' => true, + 'sliders' => true, + 'services' => true, + 'service' => true, + 'phone' => true, + 'file-pdf' => true, + 'file-word' => true, + 'file-excel' => true, + 'doc-text' => true, + 'trash' => true, + 'comment-empty' => true, + 'comment' => true, + 'chat' => true, + 'chat-empty' => true, + 'bell' => true, + 'bell-alt' => true, + 'attention-alt' => true, + 'print' => true, + 'edit' => true, + 'forward' => true, + 'reply' => true, + 'reply-all' => true, + 'eye' => true, + 'tag' => true, + 'tags' => true, + 'lock-open-alt' => true, + 'lock-open' => true, + 'lock' => true, + 'home' => true, + 'info' => true, + 'help' => true, + 'search' => true, + 'flapping' => true, + 'rewind' => true, + 'chart-line' => true, + 'bell-off' => true, + 'bell-off-empty' => true, + 'plug' => true, + 'eye-off' => true, + 'arrows-cw' => true, + 'cw' => true, + 'host' => true, + 'thumbs-up' => true, + 'thumbs-down' => true, + 'spinner' => true, + 'attach' => true, + 'keyboard' => true, + 'menu' => true, + 'wifi' => true, + 'moon' => true, + 'chart-pie' => true, + 'chart-area' => true, + 'chart-bar' => true, + 'beaker' => true, + 'magic' => true, + 'spin6' => true, + 'down-small' => true, + 'left-small' => true, + 'right-small' => true, + 'up-small' => true, + 'pin' => true, + 'angle-double-left' => true, + 'angle-double-right' => true, + 'circle' => true, + 'info-circled' => true, + 'twitter' => true, + 'facebook-squared' => true, + 'gplus-squared' => true, + 'attention-circled' => true, + 'check' => true, + 'reschedule' => true, + 'warning-empty' => true, + 'th-list' => true, + 'th-thumb-empty' => true, + 'github-circled' => true, + 'history' => true, + 'binoculars' => true + // + ]; + /** * Registered helper functions */ diff --git a/library/Icinga/Web/View/helpers/url.php b/library/Icinga/Web/View/helpers/url.php index 277c23775d..05c13a3d4b 100644 --- a/library/Icinga/Web/View/helpers/url.php +++ b/library/Icinga/Web/View/helpers/url.php @@ -5,6 +5,7 @@ use Icinga\Web\Url; use Icinga\Exception\ProgrammingError; +use ipl\Web\Widget\Icon; $view = $this; @@ -108,6 +109,12 @@ function ($title, $url, $params = null, $properties = null, $escape = true) use $properties['aria-hidden'] = 'true'; } + if (! isset($view::LEGACY_ICONS[$img]) || substr($img, 0, 3) === 'fa-') { + // This may not be reached, as some legacy icons have equal names as fontawesome ones. + // Though, this is a legacy helper, so in that case one gets legacy icons... + return new Icon($img, $properties); + } + if (isset($properties['class'])) { $properties['class'] .= ' icon-' . $img; } else {