public static function getImage($image, $alternate = '', $attributes = array())
{
static $sprites;
// cached list of available sprites (if any)
if (defined('TESTSUITE')) {
// prevent caching in testsuite
unset($sprites);
}
$is_sprite = false;
$alternate = htmlspecialchars($alternate);
// If it's the first time this function is called
if (!isset($sprites)) {
$sprites = array();
// Try to load the list of sprites
if (isset($_SESSION['PMA_Theme'])) {
$sprites = $_SESSION['PMA_Theme']->getSpriteData();
}
}
// Check if we have the requested image as a sprite
// and set $url accordingly
$class = str_replace(array('.gif', '.png'), '', $image);
if (array_key_exists($class, $sprites)) {
$is_sprite = true;
$url = (defined('PMA_TEST_THEME') ? '../' : '') . 'themes/dot.gif';
} elseif (isset($GLOBALS['pmaThemeImage'])) {
$url = $GLOBALS['pmaThemeImage'] . $image;
} else {
$url = './themes/pmahomme/' . $image;
}
// set class attribute
if ($is_sprite) {
if (isset($attributes['class'])) {
$attributes['class'] = "icon ic_{$class} " . $attributes['class'];
} else {
$attributes['class'] = "icon ic_{$class}";
}
}
// set all other attributes
$attr_str = '';
foreach ($attributes as $key => $value) {
if (!in_array($key, array('alt', 'title'))) {
$attr_str .= " {$key}=\"{$value}\"";
}
}
// override the alt attribute
if (isset($attributes['alt'])) {
$alt = $attributes['alt'];
} else {
$alt = $alternate;
}
// override the title attribute
if (isset($attributes['title'])) {
$title = $attributes['title'];
} else {
$title = $alternate;
}
// generate the IMG tag
$template = '<img src="%s" title="%s" alt="%s"%s />';
$retval = sprintf($template, $url, $title, $alt, $attr_str);
return $retval;
}