2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Provides the functionality for retreiving images
5 * which may be actual images or an icon from a sprite
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();
22 register_shutdown_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';
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
39 foreach ($sprites as $key => $value) {
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
56 * .attr(name, value) - Sets a particular attribute of the IMG
57 * tag to the given value
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
) {
71 <?php
echo implode($keys, ",\n ") , "\n"; ?
>
73 // custom image object, it will eventually be returned by this functions
79 src
: (typeof PMA_TEST_THEME
== 'undefined' ?
'' : '../')
83 attr
: function (name
, value
) {
84 if (value
== undefined
) {
85 if (this
.data
[name
] == undefined
) {
88 return this
.data
[name
];
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
] +
'"';
103 // initialise missing parameters
104 if (attributes
== undefined
) {
107 if (alternate
== undefined
) {
111 if (attributes
.alt
!= undefined
) {
112 retval
.attr('alt', attributes
.alt
);
114 retval
.attr('alt', alternate
);
117 if (attributes
.title
!= undefined
) {
118 retval
.attr('title', attributes
.title
);
120 retval
.attr('title', alternate
);
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
);
128 // it's an image file
129 retval
.isSprite
= false;
132 "<?php echo $_SESSION['PMA_Theme']->getImgPath(); ?>" + image
135 // set all other attrubutes
136 for (var i in attributes
) {
138 // do not allow to override the 'src' attribute
143 retval
.attr(i
, retval
.attr('class') +
' ' + attributes
[i
]);
145 retval
.attr(i
, attributes
[i
]);