Beispiel #1
0
/**
 * Returns an HTML IMG tag for a particular image from a theme,
 * which may be an actual file or an icon from a sprite
 *
 * @param string $image      The name of the file to get
 * @param string $alternate  Used to set 'alt' and 'title' attributes of the image
 * @param array  $attributes An associative array of other attributes
 *
 * @return string an html IMG tag
 */
function PMA_getImage($image, $alternate = '', $attributes = array())
{
    static $sprites;
    // cached list of available sprites (if any)
    $url = '';
    $is_sprite = false;
    $alternate = htmlspecialchars($alternate);
    // If it's the first time this function is called
    if (!isset($sprites)) {
        // Try to load the list of sprites
        if (is_readable($_SESSION['PMA_Theme']->getPath() . '/sprites.lib.php')) {
            include_once $_SESSION['PMA_Theme']->getPath() . '/sprites.lib.php';
            $sprites = PMA_sprites();
        } else {
            // No sprites are available for this theme
            $sprites = array();
        }
    }
    // 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 = 'themes/dot.gif';
    } else {
        $url = $GLOBALS['pmaThemeImage'] . $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;
}
// non-js-compatible stuff like DOCTYPE
define('PMA_MINIMUM_COMMON', true);
require_once './libraries/common.inc.php';
require_once './libraries/OutputBuffering.class.php';
$buffer = PMA_OutputBuffering::getInstance();
$buffer->start();
register_shutdown_function(function () {
    echo PMA_OutputBuffering::getInstance()->getContents();
});
// Get the data for the sprites, if it's available
if (is_readable($_SESSION['PMA_Theme']->getPath() . '/sprites.lib.php')) {
    include $_SESSION['PMA_Theme']->getPath() . '/sprites.lib.php';
}
$sprites = array();
if (function_exists('PMA_sprites')) {
    $sprites = PMA_sprites();
}
// We only need the keys from the array of sprites data,
// since they contain the (partial) class names
$keys = array();
foreach ($sprites as $key => $value) {
    $keys[] = "'{$key}'";
}
?>
/**
 * Returns an HTML IMG tag for a particular image from a theme,
 * which may be an actual file or an icon from a sprite
 *
 * @param string image      The name of the file to get
 * @param string alternate  Used to set 'alt' and 'title' attributes of the image
 * @param object attributes An associative array of other attributes
Beispiel #3
0
 /**
  * Loads sprites data
  *
  * @return array with sprites
  */
 public function getSpriteData()
 {
     $sprites = array();
     $filename = $this->getPath() . '/sprites.lib.php';
     if (is_readable($filename)) {
         // This defines sprites array
         include $filename;
         // Backwards compatibility for themes from 4.6 and older
         if (function_exists('PMA_sprites')) {
             $sprites = PMA_sprites();
         }
     }
     return $sprites;
 }