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.
This commit is contained in:
Johannes Meyer 2024-10-10 09:38:15 +02:00
parent 526de93c89
commit e34c174db9
2 changed files with 155 additions and 0 deletions

View File

@ -61,6 +61,154 @@ class View extends Zend_View_Abstract
*/
const CHARSET = 'UTF-8';
/**
* Legacy icons provided by our old fontello font
*
* @var array<string, bool>
*/
private const LEGACY_ICONS = [
//<editor-fold desc="Icon names">
'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
//</editor-fold>
];
/**
* Registered helper functions
*/

View File

@ -5,6 +5,7 @@ namespace Icinga\Web\View;
use Icinga\Web\Url;
use Icinga\Exception\ProgrammingError;
use ipl\Web\Widget\Icon;
$view = $this;
@ -108,6 +109,12 @@ $this->addHelperFunction('icon', function ($img, $title = null, array $propertie
$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 {