change debian/ubuntu package version from 4.3.0 to 4.2.1
[openemr.git] / phpmyadmin / js / get_image.js.php
blob8dfce6b8fbb044b980323dc608e9d5a3fb4903ae
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 require_once './libraries/OutputBuffering.class.php';
21 $buffer = PMA_OutputBuffering::getInstance();
22 $buffer->start();
23 register_shutdown_function(
24 function () {
25 echo PMA_OutputBuffering::getInstance()->getContents();
29 // Get the data for the sprites, if it's available
30 if (is_readable($_SESSION['PMA_Theme']->getPath() . '/sprites.lib.php')) {
31 include $_SESSION['PMA_Theme']->getPath() . '/sprites.lib.php';
33 $sprites = array();
34 if (function_exists('PMA_sprites')) {
35 $sprites = PMA_sprites();
37 // We only need the keys from the array of sprites data,
38 // since they contain the (partial) class names
39 $keys = array();
40 foreach ($sprites as $key => $value) {
41 $keys[] = "'$key'";
45 /**
46 * Returns an HTML IMG tag for a particular image from a theme,
47 * which may be an actual file or an icon from a sprite
49 * @param string image The name of the file to get
50 * @param string alternate Used to set 'alt' and 'title' attributes of the image
51 * @param object attributes An associative array of other attributes
53 * @return Object The requested image, this object has two methods:
54 * .toString() - Returns the IMG tag for the requested image
55 * .attr(name) - Returns a particular attribute of the IMG
56 * tag given it's name
57 * .attr(name, value) - Sets a particular attribute of the IMG
58 * tag to the given value
59 * And one property:
60 * .isSprite - Whether the image is a sprite or not
62 function PMA_getImage(image, alternate, attributes) {
63 var in_array = function (needle, haystack) {
64 for (var i in haystack) {
65 if (haystack[i] == needle) {
66 return true;
69 return false;
71 var sprites = [
72 <?php echo implode($keys, ",\n ") . "\n"; ?>
74 // custom image object, it will eventually be returned by this functions
75 var retval = {
76 data: {
77 // this is private
78 alt: '',
79 title: '',
80 src: (typeof PMA_TEST_THEME == 'undefined' ? '' : '../')
81 + 'themes/dot.gif'
83 isSprite: true,
84 attr: function (name, value) {
85 if (value == undefined) {
86 if (this.data[name] == undefined) {
87 return '';
88 } else {
89 return this.data[name];
91 } else {
92 this.data[name] = value;
95 toString: function () {
96 var retval = '<' + 'img';
97 for (var i in this.data) {
98 retval += ' ' + i + '="' + this.data[i] + '"';
100 retval += ' /' + '>';
101 return retval;
104 // initialise missing parameters
105 if (attributes == undefined) {
106 attributes = {};
108 if (alternate == undefined) {
109 alternate = '';
111 // set alt
112 if (attributes.alt != undefined) {
113 retval.attr('alt', attributes.alt);
114 } else {
115 retval.attr('alt', alternate);
117 // set title
118 if (attributes.title != undefined) {
119 retval.attr('title', attributes.title);
120 } else {
121 retval.attr('title', alternate);
123 // set src
124 var klass = image.replace('.gif', '').replace('.png', '');
125 if (in_array(klass, sprites)) {
126 // it's an icon from a sprite
127 retval.attr('class', 'icon ic_' + klass);
128 } else {
129 // it's an image file
130 retval.isSprite = false;
131 retval.attr(
132 'src',
133 "<?php echo $_SESSION['PMA_Theme']->getImgPath(); ?>" + image
136 // set all other attrubutes
137 for (var i in attributes) {
138 if (i == 'src') {
139 // do not allow to override the 'src' attribute
140 continue;
143 if (i == 'class') {
144 retval.attr(i, retval.attr('class') + ' ' + attributes[i]);
145 } else {
146 retval.attr(i, attributes[i]);
150 return retval;