Drizzle dbi - PMA_DBI_get_host_info - work around a segfault
[phpmyadmin.git] / libraries / Theme.class.php
blob7b01fa8a12e41f00f4ff2d5486c0a9ab637b3d68
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold PMA_Theme class
6 * @package phpMyAdmin
7 */
9 /**
10 * handles theme
12 * @todo add the possibility to make a theme depend on another theme and by default on original
13 * @todo make all components optional - get 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
17 * @package phpMyAdmin
19 class PMA_Theme {
20 /**
21 * @var string theme version
22 * @access protected
24 var $version = '0.0.0.0';
26 /**
27 * @var string theme name
28 * @access protected
30 var $name = '';
32 /**
33 * @var string theme id
34 * @access protected
36 var $id = '';
38 /**
39 * @var string theme path
40 * @access protected
42 var $path = '';
44 /**
45 * @var string image path
46 * @access protected
48 var $img_path = '';
50 /**
51 * @var array valid css types
52 * @access protected
54 var $types = array('left', 'right', 'print');
56 /**
57 * @var integer last modification time for info file
58 * @access protected
60 var $mtime_info = 0;
62 /**
63 * needed because sometimes, the mtime for different themes
64 * is identical
65 * @var integer filesize for info file
66 * @access protected
68 var $filesize_info = 0;
70 /**
71 * @access public
72 * @return boolean whether loading them info was successful or not
74 function loadInfo()
76 if (! file_exists($this->getPath() . '/info.inc.php')) {
77 return false;
80 if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
81 return true;
84 @include $this->getPath() . '/info.inc.php';
86 // was it set correctly?
87 if (! isset($theme_name)) {
88 return false;
91 $this->mtime_info = filemtime($this->getPath() . '/info.inc.php');
92 $this->filesize_info = filesize($this->getPath() . '/info.inc.php');
94 if (isset($theme_full_version)) {
95 $this->setVersion($theme_full_version);
96 } elseif (isset($theme_generation, $theme_version)) {
97 $this->setVersion($theme_generation . '.' . $theme_version);
99 $this->setName($theme_name);
101 return true;
105 * returns theme object loaded from given folder
106 * or false if theme is invalid
108 * @static
109 * @access public
110 * @param string $folder path to theme
111 * @return object PMA_Theme
113 static public function load($folder)
115 $theme = new PMA_Theme();
117 $theme->setPath($folder);
119 if (! $theme->loadInfo()) {
120 return false;
123 $theme->checkImgPath();
125 return $theme;
129 * checks image path for existance - if not found use img from original theme
131 * @access public
133 function checkImgPath()
135 if (is_dir($this->getPath() . '/img/')) {
136 $this->setImgPath($this->getPath() . '/img/');
137 return true;
138 } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
139 $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
140 return true;
141 } else {
142 trigger_error(
143 sprintf(__('No valid image path for theme %s found!'), $this->getName()),
144 E_USER_ERROR);
145 return false;
150 * returns path to theme
152 * @access public
153 * @return string $path path to theme
155 function getPath()
157 return $this->path;
161 * returns layout file
163 * @access public
164 * @return string layout file
166 function getLayoutFile()
168 return $this->getPath() . '/layout.inc.php';
172 * set path to theme
174 * @access public
175 * @param string $path path to theme
177 function setPath($path)
179 $this->path = trim($path);
183 * sets version
185 * @access public
186 * @param string new version
188 function setVersion($version)
190 $this->version = trim($version);
194 * returns version
196 * @access public
197 * @return string version
199 function getVersion()
201 return $this->version;
205 * checks theme version agaisnt $version
206 * returns true if theme version is equal or higher to $version
208 * @access public
209 * @param string $version version to compare to
210 * @return boolean
212 function checkVersion($version)
214 return version_compare($this->getVersion(), $version, 'lt');
218 * sets name
220 * @access public
221 * @param string $name new name
223 function setName($name)
225 $this->name = trim($name);
229 * returns name
231 * @access public
232 * @return string name
234 function getName()
236 return $this->name;
240 * sets id
242 * @access public
243 * @param string $id new id
245 function setId($id)
247 $this->id = trim($id);
251 * returns id
253 * @access public
254 * @return string id
256 function getId()
258 return $this->id;
262 * @access public
263 * @param string path to images for this theme
265 function setImgPath($path)
267 $this->img_path = $path;
271 * @access public
272 * @return string image path for this theme
274 function getImgPath()
276 return $this->img_path;
280 * load css (send to stdout, normally the browser)
282 * @access public
283 * @param string $type left, right or print
285 function loadCss(&$type)
287 if (empty($type) || ! in_array($type, $this->types)) {
288 $type = 'left';
291 if ($type == 'right') {
292 echo PMA_SQP_buildCssData();
295 $_css_file = $this->getPath()
296 . '/css/theme_' . $type . '.css.php';
298 if (! file_exists($_css_file)) {
299 return false;
302 if ($GLOBALS['text_dir'] === 'ltr') {
303 $right = 'right';
304 $left = 'left';
305 } else {
306 $right = 'left';
307 $left = 'right';
310 include $_css_file;
311 return true;
315 * prints out the preview for this theme
317 * @access public
319 function printPreview()
321 echo '<div class="theme_preview">';
322 echo '<h2>' . htmlspecialchars($this->getName())
323 .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
324 .'<p>'
325 .'<a target="_top" href="index.php'
326 .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
327 .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
328 .' return false;">';
329 if (@file_exists($this->getPath() . '/screen.png')) {
330 // if screen exists then output
332 echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
333 .' alt="' . htmlspecialchars($this->getName()) . '"'
334 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
335 } else {
336 echo __('No preview available.');
339 echo '[ <strong>' . __('take it') . '</strong> ]</a>'
340 .'</p>'
341 .'</div>';