Fix for the Open in New Window in Patient/Client->Patients search gui, take 2.
[openemr.git] / phpmyadmin / libraries / Theme.class.php
blob2e204f198b4e554ee29b8aafe99e9af8153578d3
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold PMA_Theme class
6 * @version $Id$
7 */
9 /**
10 * handles theme
12 * @todo add the possibility to make a theme depends on another theme and by default on original
13 * @todo make all components optional - taking missing components from 'parent' theme
14 * @todo make css optionally replacing 'parent' css or extending it (by appending at the end)
15 * @todo add an optional global css file - which will be used for both frames
18 class PMA_Theme {
19 /**
20 * @var string theme version
21 * @access protected
23 var $version = '0.0.0.0';
25 /**
26 * @var string theme name
27 * @access protected
29 var $name = '';
31 /**
32 * @var string theme id
33 * @access protected
35 var $id = '';
37 /**
38 * @var string theme path
39 * @access protected
41 var $path = '';
43 /**
44 * @var string image path
45 * @access protected
47 var $img_path = '';
49 /**
50 * @var array valid css types
51 * @access protected
53 var $types = array('left', 'right', 'print');
55 /**
56 * @var integer last modification time for info file
57 * @access protected
59 var $mtime_info = 0;
61 /**
62 * needed because sometimes, the mtime for different themes
63 * is identical
64 * @var integer filesize for info file
65 * @access protected
67 var $filesize_info = 0;
69 /**
70 * @access public
71 * @uses PMA_Theme::getPath()
72 * @uses PMA_Theme::$mtime_info
73 * @uses PMA_Theme::setVersion()
74 * @uses PMA_Theme::setName()
75 * @uses filemtime()
76 * @uses filesize()
77 * @uses file_exists()
78 * @return boolean whether loading them info was successful or not
80 function loadInfo()
82 if (! file_exists($this->getPath() . '/info.inc.php')) {
83 return false;
86 if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
87 return true;
90 @include $this->getPath() . '/info.inc.php';
92 // did it set correctly?
93 if (! isset($theme_name)) {
94 return false;
97 $this->mtime_info = filemtime($this->getPath() . '/info.inc.php');
98 $this->filesize_info = filesize($this->getPath() . '/info.inc.php');
100 if (isset($theme_full_version)) {
101 $this->setVersion($theme_full_version);
102 } elseif (isset($theme_generation, $theme_version)) {
103 $this->setVersion($theme_generation . '.' . $theme_version);
105 $this->setName($theme_name);
107 return true;
111 * returns theme object loaded from given folder
112 * or false if theme is invalid
114 * @static
115 * @access public
116 * @uses PMA_Theme
117 * @uses PMA_Theme::setPath()
118 * @uses PMA_Theme::loadInfo()
119 * @uses PMA_Theme::checkImgPath()
120 * @param string $folder path to theme
121 * @return object PMA_Theme
123 function load($folder)
125 $theme = new PMA_Theme();
127 $theme->setPath($folder);
129 if (! $theme->loadInfo()) {
130 return false;
133 $theme->checkImgPath();
135 return $theme;
139 * checks image path for existance - if not found use img from original theme
141 * @access public
142 * @uses PMA_Theme::getPath()
143 * @uses PMA_Theme::setImgPath()
144 * @uses PMA_Theme::getName()
145 * @uses $GLOBALS['cfg']['ThemePath']
146 * @uses $GLOBALS['PMA_errors']
147 * @uses $GLOBALS['strThemeNoValidImgPath']
148 * @uses is_dir()
149 * @uses sprintf()
151 function checkImgPath()
153 if (is_dir($this->getPath() . '/img/')) {
154 $this->setImgPath($this->getPath() . '/img/');
155 return true;
156 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
157 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
158 return true;
159 } else {
160 $GLOBALS['PMA_errors'][] =
161 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName());
163 trigger_error(
164 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
165 E_USER_WARNING);
167 return false;
172 * returns path to theme
174 * @access public
175 * @uses PMA_Theme::$path as return value
176 * @return string $path path to theme
178 function getPath()
180 return $this->path;
184 * returns layout file
186 * @access public
187 * @uses PMA_Theme::getPath()
188 * @return string layout file
190 function getLayoutFile()
192 return $this->getPath() . '/layout.inc.php';
196 * set path to theme
198 * @access public
199 * @uses PMA_Theme::$path to set it
200 * @param string $path path to theme
202 function setPath($path)
204 $this->path = trim($path);
208 * sets version
210 * @access public
211 * @uses PMA_Theme::$version
212 * @param string new version
214 function setVersion($version)
216 $this->version = trim($version);
220 * returns version
222 * @access public
223 * @uses PMA_Theme::$version
224 * @return string version
226 function getVersion()
228 return $this->version;
232 * checks theme version agaisnt $version
233 * returns true if theme version is equal or higher to $version
235 * @access public
236 * @uses version_compare()
237 * @uses PMA_Theme::getVersion()
238 * @param string $version version to compare to
239 * @return boolean
241 function checkVersion($version)
243 return version_compare($this->getVersion(), $version, 'lt');
247 * sets name
249 * @access public
250 * @uses PMA_Theme::$name to set it
251 * @uses trim()
252 * @param string $name new name
254 function setName($name)
256 $this->name = trim($name);
260 * returns name
262 * @access public
263 * @uses PMA_Theme::$name as return value
264 * @return string name
266 function getName()
268 return $this->name;
272 * sets id
274 * @access public
275 * @uses PMA_Theme::$id to set it
276 * @param string $id new id
278 function setId($id)
280 $this->id = trim($id);
284 * returns id
286 * @access public
287 * @uses PMA_Theme::$id as return value
288 * @return string id
290 function getId()
292 return $this->id;
296 * @access public
297 * @uses PMA_Theme::$img_path to set it
298 * @param string path to images for this theme
300 function setImgPath($path)
302 $this->img_path = $path;
306 * @access public
307 * @uses PMA_Theme::$img_path as retunr value
308 * @return string image path for this theme
310 function getImgPath()
312 return $this->img_path;
316 * load css (send to stdout, normaly the browser)
318 * @access public
319 * @uses PMA_Theme::getPath()
320 * @uses PMA_Theme::$types
321 * @uses PMA_SQP_buildCssData()
322 * @uses file_exists()
323 * @uses in_array()
324 * @param string $type left, right or print
326 function loadCss(&$type)
328 if (empty($type) || ! in_array($type, $this->types)) {
329 $type = 'left';
332 if ($type == 'right') {
333 echo PMA_SQP_buildCssData();
336 $_css_file = $this->getPath()
337 . '/css/theme_' . $type . '.css.php';
339 if (! file_exists($_css_file)) {
340 return false;
343 if ($GLOBALS['text_dir'] === 'ltr') {
344 $right = 'right';
345 $left = 'left';
346 } else {
347 $right = 'left';
348 $left = 'right';
351 include $_css_file;
352 return true;
356 * prints out the preview for this theme
358 * @access public
359 * @uses PMA_Theme::getName()
360 * @uses PMA_Theme::getVersion()
361 * @uses PMA_Theme::getId()
362 * @uses PMA_Theme::getPath()
363 * @uses $GLOBALS['strThemeNoPreviewAvailable']
364 * @uses $GLOBALS['strTakeIt']
365 * @uses PMA_generate_common_url()
366 * @uses addslashes()
367 * @uses file_exists()
368 * @uses htmlspecialchars()
370 function printPreview()
372 echo '<div class="theme_preview">';
373 echo '<h2>' . htmlspecialchars($this->getName())
374 .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
375 .'<p>'
376 .'<a target="_top" href="index.php'
377 .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
378 .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
379 .' return false;">';
380 if (@file_exists($this->getPath() . '/screen.png')) {
381 // if screen exists then output
383 echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
384 .' alt="' . htmlspecialchars($this->getName()) . '"'
385 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
386 } else {
387 echo $GLOBALS['strThemeNoPreviewAvailable'];
390 echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'
391 .'</p>'
392 .'</div>';