Commit 9a5e1fad authored by lindonb's avatar lindonb

[FIX] icons: add ability to size icons, including legacy icons for at least...

[FIX] icons: add ability to size icons, including legacy icons for at least double size (32 by 32) and triple size (48 by 48) when available (see admin_fgal in legacy file for example - used at admin_files.tpl). Also add ability to add class to icon span.
parent dc6d927d
......@@ -15,7 +15,13 @@ if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
* smarty_function_icon: Display a Tiki icon, using theme icons if they exists
*
* params will be used as params for the HTML tag (e.g. border, class, ...), except special params starting with '_' :
* - _id: short name (i.e. 'page_edit') or relative file path (i.e. 'img/icons/page_edit.png'). [required]
* - _id: [deprecated] short name (i.e. 'page_edit') or relative file path (i.e. 'img/icons/page_edit.png').
* Will not work with iconsets.
* - name: name of icon from themes/base_files/iconsets file, which allows for choosing different iconsets.
* Use instead of _id.
* - class set custom class (otherwise default classes are applied). When using icon sets, this class will apply to
* anchor element
* - iclass set custom class for the icon itself (not the link)
* - _type: type of URL to use (e.g. 'absolute_uri', 'absolute_path'). Defaults to a relative URL.
* - _tag: type of HTML tag to use (e.g. 'img', 'input_image'). Defaults to 'img' tag.
* - _notag: if set to 'y', will only return the URL (which also handles theme icons).
......@@ -87,7 +93,7 @@ function smarty_function_icon($params, $smarty)
if (!empty($params['name']) && empty($params['_tag']) && !empty($iconset)) {
$name = $params['name'];
$html = $iconset->getHtml($name);
$html = $iconset->getHtml($name, $params);
$menu_text = (isset($params['_menu_text']) && $params['_menu_text'] == 'y');
if (!empty($params['href']) || !empty($params['title']) || $menu_text) {
/* Generate a link for the icon if href or title (for tips) parameter is set.
......
......@@ -166,7 +166,7 @@ class Iconset
return $this->append;
}
public function getHtml($name) {
public function getHtml($name, array $params = []) {
global $prefs;
......@@ -176,14 +176,23 @@ class Iconset
$prepend = isset($icon['prepend']) ? $icon['prepend'] : $this->prepend;
$append = isset($icon['append']) ? $icon['append'] : $this->append;
$icon_class = '';
$size = isset($params['size']) && $params['size'] < 10 ? $params['size'] : 1;
$custom_class = isset($params['iclass']) ? $params['iclass'] : '';
if ($tag == 'img') { //manage legacy image icons (eg: png, gif, etc)
$src = TikiLib::lib('theme')->get_theme_path($prefs['theme'], $prefs['theme_option'], $icon['id'] . $append, 'icons/');
//some ability to use larger legacy icons based on size setting
// 1 = 16px x 16px; 2 = 32px x 32px; 3 = 48px x 48px
if ($size > 1 && isset($icon['size']) && $icon['size'] != $size && !empty($icon['sizes'][$size])) {
$id = $icon['sizes'][$size];
} else {
$id = $icon['id'];
}
$src = TikiLib::lib('theme')->get_theme_path($prefs['theme'], $prefs['theme_option'], $id . $append, 'icons/');
if (empty($src)) {
$src = $prepend . $icon['id'] . $append;
$src = $prepend . $id . $append;
}
$alt = $name; //use icon name as alternate text
$html = "<span class=\"icon icon-$name $icon_class\"><img src=\"$src\" alt=\"$alt\"></span>";
$html = "<span class=\"icon icon-$name $icon_class $custom_class\"><img src=\"$src\" alt=\"$alt\"></span>";
} else {
if (isset($icon['id'])) { //use class defined for the icon if set
$icon_class = $prepend . $icon['id'] . $append;
......@@ -191,7 +200,8 @@ class Iconset
TikiLib::lib('errorreport')->report(tr('Iconset: Class not defined for icon %0', $name));
}
$html = "<$tag class=\"icon icon-$name $icon_class\"></$tag>";
$style = $size > 1 ? 'style="font-size:' . $size . '00%"' : '';
$html = "<$tag class=\"icon icon-$name $icon_class $custom_class\" $style></$tag>";
}
return $html;
......
......@@ -9,6 +9,15 @@ if (strpos($_SERVER['SCRIPT_NAME'], basename(__FILE__)) !== false) {
header('location: index.php');
exit;
}
/*
* Note on sizing:
* Some ability to use larger legacy icons based on size parameter in smarty icon function
* Indicate size of main id using size => X
* Add paths to additional sizes (usually just size 3) by using sizes => array(3 => iconname)
* Regular size is 16px by 16px, so size 2 is 32px by 32px and size 3 is 48px by 48px
* See admin_fgal below for an example
*/
function iconset_legacy()
{
......@@ -63,6 +72,10 @@ function iconset_legacy()
),
'admin_fgal' => array(
'id' => 'large/file-manager',
'size' => 2,
'sizes' => array(
3 => 'large/fileopen48x48'
)
),
'admin_forums' => array(
'id' => 'large/stock_index',
......@@ -160,6 +173,10 @@ function iconset_legacy()
),
'admin_wiki' => array(
'id' => 'large/wikipages',
'size' => 2,
'sizes' => array(
3 => 'large/wikipages48x48'
)
),
'admin_workspace' => array(
'id' => 'large/areas',
......@@ -466,6 +483,10 @@ function iconset_legacy()
'wizard' => array(
'id' => 'wizard16x16',
),
'wizard_admin' => array(
'id' => 'large/wizard48x48',
'size' => 3
),
),
);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment