Translated using Weblate (Italian)
[phpmyadmin.git] / js / get_image.js.php
blobc541bdd496a5f1f7d42f1f9f3ade6ecf792a5db8
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Provides the functionality for retreiving images
5 * which may be actual images or an icon from a sprite
7 * @package PhpMyAdmin
8 */
9 chdir('..');
11 // Send correct type:
12 header('Content-Type: text/javascript; charset=UTF-8');
13 header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 3600) . ' GMT');
15 // Avoid loading the full common.inc.php because this would add many
16 // non-js-compatible stuff like DOCTYPE
17 define('PMA_MINIMUM_COMMON', true);
18 require_once './libraries/common.inc.php';
20 // Get the data for the sprites, if it's available
21 if (is_readable($_SESSION['PMA_Theme']->getPath() . '/sprites.lib.php')) {
22 include $_SESSION['PMA_Theme']->getPath() . '/sprites.lib.php';
24 $sprites = array();
25 if (function_exists('PMA_sprites')) {
26 $sprites = PMA_sprites();
28 // We only need the keys from the array of sprites data,
29 // since they contain the (partial) class names
30 $keys = array();
31 foreach ($sprites as $key => $value) {
32 $keys[] = "'$key'";
36 /**
37 * Returns an HTML IMG tag for a particular image from a theme,
38 * which may be an actual file or an icon from a sprite
40 * @param string image The name of the file to get
41 * @param string alternate Used to set 'alt' and 'title' attributes of the image
42 * @param object attributes An associative array of other attributes
44 * @return Object The requested image, this object has two methods:
45 * .toString() - Returns the IMG tag for the requested image
46 * .attr(name) - Returns a particular attribute of the IMG
47 * tag given it's name
48 * .attr(name, value) - Sets a particular attribute of the IMG
49 * tag to the given value
50 * And one property:
51 * .isSprite - Whether the image is a sprite or not
53 function PMA_getImage(image, alternate, attributes) {
54 var in_array = function (needle, haystack) {
55 for (var i in haystack) {
56 if (haystack[i] == needle) {
57 return true;
60 return false;
62 var sprites = [
63 <?php echo implode($keys, ",\n ") . "\n"; ?>
65 // custom image object, it will eventually be returned by this functions
66 var retval = {
67 data: {
68 // this is private
69 alt: '',
70 title: '',
71 src: (typeof PMA_TEST_THEME == 'undefined' ? '' : '../')
72 + 'themes/dot.gif'
74 isSprite: true,
75 attr: function (name, value) {
76 if (value == undefined) {
77 if (this.data[name] == undefined) {
78 return '';
79 } else {
80 return this.data[name];
82 } else {
83 this.data[name] = value;
86 toString: function () {
87 var retval = '<' + 'img';
88 for (var i in this.data) {
89 retval += ' ' + i + '="' + this.data[i] + '"';
91 retval += ' /' + '>';
92 return retval;
95 // initialise missing parameters
96 if (attributes == undefined) {
97 attributes = {};
99 if (alternate == undefined) {
100 alternate = '';
102 // set alt
103 if (attributes.alt != undefined) {
104 retval.attr('alt', attributes.alt);
105 } else {
106 retval.attr('alt', alternate);
108 // set title
109 if (attributes.title != undefined) {
110 retval.attr('title', attributes.title);
111 } else {
112 retval.attr('title', alternate);
114 // set src
115 var klass = image.replace('.gif', '').replace('.png', '');
116 if (in_array(klass, sprites)) {
117 // it's an icon from a sprite
118 retval.attr('class', 'icon ic_' + klass);
119 } else {
120 // it's an image file
121 retval.isSprite = false;
122 retval.attr(
123 'src',
124 "<?php echo $_SESSION['PMA_Theme']->getImgPath(); ?>" + image
127 // set all other attrubutes
128 for (var i in attributes) {
129 if (i == 'src') {
130 // do not allow to override the 'src' attribute
131 continue;
132 } else if (i == 'class') {
133 retval.attr(i, retval.attr('class') + ' ' + attributes[i]);
134 } else {
135 retval.attr(i, attributes[i]);
139 return retval;