summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/class/ajax.class.php2
-rw-r--r--lib/class/ampache_rss.class.php2
-rw-r--r--lib/class/playlist_object.abstract.php2
-rw-r--r--lib/class/ui.class.php59
-rw-r--r--lib/javascript/search-data.php2
-rw-r--r--lib/ui.lib.php73
6 files changed, 64 insertions, 76 deletions
diff --git a/lib/class/ajax.class.php b/lib/class/ajax.class.php
index de217330..04098861 100644
--- a/lib/class/ajax.class.php
+++ b/lib/class/ajax.class.php
@@ -123,7 +123,7 @@ class Ajax {
$class = ' class="' . $class . '"';
}
- $string = get_user_icon($icon,$alt);
+ $string = UI::get_icon($icon,$alt);
// Generate an <a> so that it's more compliant with older
// browsers (ie :hover actions) and also to unify linkbuttons
diff --git a/lib/class/ampache_rss.class.php b/lib/class/ampache_rss.class.php
index 3b567937..3056e9cf 100644
--- a/lib/class/ampache_rss.class.php
+++ b/lib/class/ampache_rss.class.php
@@ -113,7 +113,7 @@ class Ampache_RSS {
// Default to now playing
$type = self::validate_type($type);
- $string = '<a href="' . Config::get('web_path') . '/rss.php?type=' . $type . '">' . get_user_icon('feed', T_('RSS Feed')) . '</a>';
+ $string = '<a href="' . Config::get('web_path') . '/rss.php?type=' . $type . '">' . UI::get_icon('feed', T_('RSS Feed')) . '</a>';
return $string;
diff --git a/lib/class/playlist_object.abstract.php b/lib/class/playlist_object.abstract.php
index 48eefb0d..d232d6d7 100644
--- a/lib/class/playlist_object.abstract.php
+++ b/lib/class/playlist_object.abstract.php
@@ -40,7 +40,7 @@ abstract class playlist_object extends database_object {
public function format() {
$this->f_name = UI::truncate($this->name,Config::get('ellipse_threshold_title'));
- $this->f_type = ($this->type == 'private') ? get_user_icon('lock', T_('Private')) : '';
+ $this->f_type = ($this->type == 'private') ? UI::get_icon('lock', T_('Private')) : '';
$client = new User($this->user);
diff --git a/lib/class/ui.class.php b/lib/class/ui.class.php
index c3d69198..f37c5a36 100644
--- a/lib/class/ui.class.php
+++ b/lib/class/ui.class.php
@@ -27,6 +27,7 @@ class UI {
private static $_classes;
private static $_ticker;
+ private static $_icon_cache;
public function __construct($data) {
return false;
@@ -104,6 +105,64 @@ class UI {
}
/**
+ * get_icon
+ *
+ * Returns an <img> tag for the specified icon
+ */
+ public static function get_icon($name, $title = null, $id = null) {
+ if (is_array($name)) {
+ $hover_name = $name[1];
+ $name = $name[0];
+ }
+
+ $title = $title ?: T_(ucfirst($name));
+
+ $icon_url = self::_find_icon($name);
+ if ($hover_name) {
+ $hover_url = self::_find_icon($hover_text);
+ }
+
+ $tag = '<img src="' . $icon_url . '" ';
+
+ if ($id) {
+ $tag .= 'id="' . $id . '" ';
+ }
+
+ $tag .= 'alt="' . $title . '" ';
+ $tag .= 'title="' . $title . '" ';
+
+ if ($hover_name) {
+ $tag .= 'onmouseover="this.src=\'' . $hover_url . '\'; return true;"';
+ $tag .= 'onmouseout="this.src=\'' . $icon_url . '\'; return true;" ';
+ }
+
+ $tag .= '/>';
+ return $tag;
+ }
+
+ /**
+ * _find_icon
+ *
+ * Does the finding icon thing
+ */
+ private static function _find_icon($name) {
+ if ($url = self::$_icon_cache[$name]) {
+ return $url;
+ }
+
+ $filename = 'icon_' . $name . '.png';
+ $path = Config::get('theme_path') . '/images/icons/';
+ if (!file_exists(Config::get('prefix') . $path . $filename)) {
+ $path = '/images/';
+ }
+ $url = Config::get('web_path') . $path . $filename;
+ self::$_icon_cache[$name] = $url;
+
+ return $url;
+ }
+
+
+ /**
* show_header
*
* For now this just shows the header template
diff --git a/lib/javascript/search-data.php b/lib/javascript/search-data.php
index 83c3be29..dd3e302e 100644
--- a/lib/javascript/search-data.php
+++ b/lib/javascript/search-data.php
@@ -48,5 +48,5 @@ echo 'var types = $H(\'';
echo arrayToJSON($search->types) . "'.evalJSON());\n";
echo 'var basetypes = $H(\'';
echo arrayToJSON($search->basetypes) . "'.evalJSON());\n";
-echo 'removeIcon = \'<a href="javascript: void(0)">' . get_user_icon('disable', T_('Remove')) . '</a>\';';
+echo 'removeIcon = \'<a href="javascript: void(0)">' . UI::get_icon('disable', T_('Remove')) . '</a>\';';
?>
diff --git a/lib/ui.lib.php b/lib/ui.lib.php
index 7755a939..a72c4c70 100644
--- a/lib/ui.lib.php
+++ b/lib/ui.lib.php
@@ -342,78 +342,7 @@ function show_playlist_select($name,$selected='',$style='') {
} // show_playlist_select
-/**
- * get_user_icon
- * this function takes a name and a returns either a text representation
- * or an <img /> tag
- */
-function get_user_icon($name,$title='',$id='') {
-
- /* Because we do a lot of calls cache the URLs */
- static $url_cache = array();
-
- // If our name is an array
- if (is_array($name)) {
- $hover_name = $name['1'];
- $name = $name['0'];
- }
-
- if (!$title) { $title = T_(ucfirst($name)); }
-
- if ($id) {
- $id = ' id="' . $id . '" ';
- }
-
- if (isset($url_cache[$name])) {
- $img_url = $url_cache[$name];
- $cache_url = true;
- }
-
- if (empty($hover_name)) {
- $cache_hover = true;
- $hov_txt = '';
- }
- elseif (isset($url_cache[$hover_name])) {
- $hover_url = $url_cache[$hover_name];
- $cache_hover = true;
- }
-
- if (!isset($cache_url) OR !isset($cache_hover)) {
-
- $icon_name = 'icon_' . $name . '.png';
-
- /* Build the image url */
- if (file_exists(Config::get('prefix') . Config::get('theme_path') . '/images/icons/' . $icon_name)) {
- $img_url = Config::get('web_path') . Config::get('theme_path') . '/images/icons/' . $icon_name;
- }
- else {
- $img_url = Config::get('web_path') . '/images/' . $icon_name;
- }
-
- $url_cache[$name] = $img_url;
-
- /* If Hover, then build its url */
- if (!empty($hover_name)) {
- $hover_icon = 'icon_' . $hover_name . '.png';
- if (file_exists(Config::get('prefix') . Config::get('theme_path') . '/images/icons/' . $icon_name)) {
- $hov_url = Config::get('web_path') . Config::get('theme_path') . '/images/icons/' . $hover_icon;
- }
- else {
- $hov_url = Config::get('web_path') . '/images/' . $hover_icon;
- }
-
- $hov_txt = " onmouseover=\"this.src='$hov_url'; return true;\" onmouseout=\"this.src='$img_url'; return true;\" ";
- $url_cache[$hover_name] = $hov_txt;
- } // end hover
-
- } // end if not cached
-
- $string = '<img src="' . $img_url . '"' . $id . 'alt="' . $title . '" title="' . $title . '"' . $hov_txt . '/>';
-
- return $string;
-
-} // get_user_icon
-
+// FIXME: This should probably go in XML_Data
/**
* xml_from_array
* This takes a one dimensional array and creates a XML document from it. For