Translated using Weblate (Slovenian)
[phpmyadmin.git] / js / get_image.js.php
blob7a76a6d1dbadcdddd5d02fb82192d2550e405c7d
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 $buffer = PMA\libraries\OutputBuffering::getInstance();
21 $buffer->start();
22 register_shutdown_function(
23 function () {
24 echo PMA\libraries\OutputBuffering::getInstance()->getContents();
28 // Get the data for the sprites, if it's available
29 if (is_readable($_SESSION['PMA_Theme']->getPath() . '/sprites.lib.php')) {
30 include $_SESSION['PMA_Theme']->getPath() . '/sprites.lib.php';
32 $sprites = array();
33 if (function_exists('PMA_sprites')) {
34 $sprites = PMA_sprites();
36 // We only need the keys from the array of sprites data,
37 // since they contain the (partial) class names
38 $keys = array();
39 foreach ($sprites as $key => $value) {
40 $keys[] = "'$key'";
44 /**
45 * Returns an HTML IMG tag for a particular image from a theme,
46 * which may be an actual file or an icon from a sprite
48 * @param string image The name of the file to get
49 * @param string alternate Used to set 'alt' and 'title' attributes of the image
50 * @param object attributes An associative array of other attributes
52 * @return Object The requested image, this object has two methods:
53 * .toString() - Returns the IMG tag for the requested image
54 * .attr(name) - Returns a particular attribute of the IMG
55 * tag given it's name
56 * .attr(name, value) - Sets a particular attribute of the IMG
57 * tag to the given value
58 * And one property:
59 * .isSprite - Whether the image is a sprite or not
61 function PMA_getImage(image, alternate, attributes) {
62 var in_array = function (needle, haystack) {
63 for (var i in haystack) {
64 if (haystack[i] == needle) {
65 return true;
68 return false;
70 var sprites = [
71 <?php echo implode($keys, ",\n ") , "\n"; ?>
73 // custom image object, it will eventually be returned by this functions
74 var retval = {
75 data: {
76 // this is private
77 alt: '',
78 title: '',
79 src: (typeof PMA_TEST_THEME == 'undefined' ? '' : '../')
80 + 'themes/dot.gif'
82 isSprite: true,
83 attr: function (name, value) {
84 if (value == undefined) {
85 if (this.data[name] == undefined) {
86 return '';
87 } else {
88 return this.data[name];
90 } else {
91 this.data[name] = value;
94 toString: function () {
95 var retval = '<' + 'img';
96 for (var i in this.data) {
97 retval += ' ' + i + '="' + this.data[i] + '"';
99 retval += ' /' + '>';
100 return retval;
103 // initialise missing parameters
104 if (attributes == undefined) {
105 attributes = {};
107 if (alternate == undefined) {
108 alternate = '';
110 // set alt
111 if (attributes.alt != undefined) {
112 retval.attr('alt', attributes.alt);
113 } else {
114 retval.attr('alt', alternate);
116 // set title
117 if (attributes.title != undefined) {
118 retval.attr('title', attributes.title);
119 } else {
120 retval.attr('title', alternate);
122 // set src
123 var klass = image.replace('.gif', '').replace('.png', '');
124 if (in_array(klass, sprites)) {
125 // it's an icon from a sprite
126 retval.attr('class', 'icon ic_' + klass);
127 } else {
128 // it's an image file
129 retval.isSprite = false;
130 retval.attr(
131 'src',
132 "<?php echo $_SESSION['PMA_Theme']->getImgPath(); ?>" + image
135 // set all other attrubutes
136 for (var i in attributes) {
137 if (i == 'src') {
138 // do not allow to override the 'src' attribute
139 continue;
142 if (i == 'class') {
143 retval.attr(i, retval.attr('class') + ' ' + attributes[i]);
144 } else {
145 retval.attr(i, attributes[i]);
149 return retval;