/ASTRA_Demo_Server/udrive/home/admin/www/phpMyAdmin/libraries/Theme.class.php

https://github.com/shafiqissani/ASTRA-College-Website · PHP · 301 lines · 151 code · 43 blank · 107 comment · 16 complexity · 8207a14726c10581bc4cc7ac42e0dfe0 MD5 · raw file

  1. <?php
  2. /* $Id: Theme.class.php 9902 2007-02-01 13:25:54Z cybot_tm $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4. class PMA_Theme {
  5. /**
  6. * @var string version
  7. */
  8. var $version = '0.0.0.0';
  9. /**
  10. * @var string name
  11. */
  12. var $name = '';
  13. /**
  14. * @var string id
  15. */
  16. var $id = '';
  17. /**
  18. * @var string
  19. */
  20. var $path = '';
  21. /**
  22. * @var string
  23. */
  24. var $img_path = '';
  25. /**
  26. * @var array valid css types
  27. */
  28. var $types = array('left', 'right', 'print');
  29. /**
  30. * @var integer last modification time for info file
  31. */
  32. var $mtime_info = 0;
  33. function loadInfo()
  34. {
  35. if (! file_exists($this->getPath() . '/info.inc.php')) {
  36. return false;
  37. }
  38. if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
  39. return true;
  40. }
  41. @include $this->getPath() . '/info.inc.php';
  42. // did it set correctly?
  43. if (! isset($theme_name)) {
  44. return false;
  45. }
  46. $this->mtime_info = filemtime($this->getPath() . '/info.inc.php');
  47. if (isset($theme_full_version)) {
  48. $this->setVersion($theme_full_version);
  49. } elseif (isset($theme_generation, $theme_version)) {
  50. $this->setVersion($theme_generation . '.' . $theme_version);
  51. }
  52. $this->setName($theme_name);
  53. return true;
  54. }
  55. /**
  56. * returns theme object loaded from given folder
  57. * or false if theme is invalid
  58. *
  59. * @static
  60. * @param string path to theme
  61. * @return object PMA_Theme
  62. */
  63. function load($folder)
  64. {
  65. $theme = new PMA_Theme();
  66. $theme->setPath($folder);
  67. if (! $theme->loadInfo()) {
  68. return false;
  69. }
  70. $theme->checkImgPath();
  71. return $theme;
  72. }
  73. function checkImgPath()
  74. {
  75. if (is_dir($this->getPath() . '/img/')) {
  76. $this->setImgPath($this->getPath() . '/img/');
  77. return true;
  78. } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
  79. $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
  80. return true;
  81. } else {
  82. $GLOBALS['PMA_errors'][] =
  83. sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName());
  84. trigger_error(
  85. sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
  86. E_USER_WARNING);
  87. return false;
  88. }
  89. }
  90. /**
  91. * returns path to theme
  92. * @uses $this->$path as return value
  93. * @return string $path path to theme
  94. */
  95. function getPath()
  96. {
  97. return $this->path;
  98. }
  99. /**
  100. * returns layout file
  101. *
  102. * @return string layout file
  103. */
  104. function getLayoutFile()
  105. {
  106. return $this->getPath() . '/layout.inc.php';
  107. }
  108. /**
  109. * set path to theme
  110. * @uses $this->$path to set it
  111. * @param string $path path to theme
  112. */
  113. function setPath($path)
  114. {
  115. $this->path = trim($path);
  116. }
  117. /**
  118. * sets version
  119. * @uses $this->version
  120. * @param string new version
  121. */
  122. function setVersion($version)
  123. {
  124. $this->version = trim($version);
  125. }
  126. /**
  127. * returns version
  128. * @uses $this->version
  129. * @return string version
  130. */
  131. function getVersion()
  132. {
  133. return $this->version;
  134. }
  135. /**
  136. * checks theme version agaisnt $version
  137. * returns true if theme version is equal or higher to $version
  138. *
  139. * @uses version_compare()
  140. * @uses $this->getVersion()
  141. * @param string $version version to compare to
  142. * @return boolean
  143. */
  144. function checkVersion($version)
  145. {
  146. return version_compare($this->getVersion(), $version, 'lt');
  147. }
  148. /**
  149. * sets name
  150. * @param string $name new name
  151. */
  152. function setName($name)
  153. {
  154. $this->name = trim($name);
  155. }
  156. /**
  157. * returns name
  158. * @return string name
  159. */
  160. function getName()
  161. {
  162. return $this->name;
  163. }
  164. /**
  165. * sets id
  166. * @param string $id new id
  167. */
  168. function setId($id)
  169. {
  170. $this->id = trim($id);
  171. }
  172. /**
  173. * returns id
  174. * @return string id
  175. */
  176. function getId()
  177. {
  178. return $this->id;
  179. }
  180. function setImgPath($path)
  181. {
  182. $this->img_path = $path;
  183. }
  184. function getImgPath()
  185. {
  186. return $this->img_path;
  187. }
  188. /**
  189. * load css (send to stdout, normaly the browser)
  190. *
  191. * @uses $this->getPath()
  192. * @uses $this->types
  193. * @uses PMA_SQP_buildCssData()
  194. * @uses file_exists()
  195. * @uses in_array()
  196. * @param string $type left, right or print
  197. */
  198. function loadCss(&$type)
  199. {
  200. if (empty($type) || ! in_array($type, $this->types)) {
  201. $type = 'left';
  202. }
  203. if ($type == 'right') {
  204. echo PMA_SQP_buildCssData();
  205. }
  206. $_css_file = $this->getPath()
  207. . '/css/theme_' . $type . '.css.php';
  208. if (! file_exists($_css_file)) {
  209. return false;
  210. }
  211. if ($GLOBALS['text_dir'] === 'ltr') {
  212. $right = 'right';
  213. $left = 'left';
  214. } else {
  215. $right = 'left';
  216. $left = 'right';
  217. }
  218. include $_css_file;
  219. return true;
  220. }
  221. /**
  222. * prints out the preview for this theme
  223. *
  224. * @uses $this->getName()
  225. * @uses $this->getVersion()
  226. * @uses $this->getId()
  227. * @uses $this->getPath()
  228. * @uses $GLOBALS['strThemeNoPreviewAvailable']
  229. * @uses $GLOBALS['strTakeIt']
  230. * @uses PMA_generate_common_url()
  231. * @uses addslashes()
  232. * @uses file_exists()
  233. * @uses htmlspecialchars()
  234. */
  235. function printPreview()
  236. {
  237. echo '<div class="theme_preview">';
  238. echo '<h2>' . htmlspecialchars($this->getName())
  239. .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
  240. .'<p>'
  241. .'<a target="_top" href="index.php'
  242. .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
  243. .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
  244. .' return false;">';
  245. if (@file_exists($this->getPath() . '/screen.png')) {
  246. // if screen exists then output
  247. echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
  248. .' alt="' . htmlspecialchars($this->getName()) . '"'
  249. .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
  250. } else {
  251. echo $GLOBALS['strThemeNoPreviewAvailable'];
  252. }
  253. echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'
  254. .'</p>'
  255. .'</div>';
  256. }
  257. }
  258. ?>