PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/manage/phpmyadminlite/libraries/Theme.class.php

https://gitlab.com/albert925/lading-ach
PHP | 392 lines | 151 code | 42 blank | 199 comment | 16 complexity | fe3b2fc55513c3c56c1cbdd0d4a7aa1c MD5 | raw file
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * hold PMA_Theme class
  5. *
  6. * @version $Id$
  7. * @package phpMyAdmin
  8. */
  9. /**
  10. * handles theme
  11. *
  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
  16. *
  17. * @package phpMyAdmin
  18. */
  19. class PMA_Theme {
  20. /**
  21. * @var string theme version
  22. * @access protected
  23. */
  24. var $version = '0.0.0.0';
  25. /**
  26. * @var string theme name
  27. * @access protected
  28. */
  29. var $name = '';
  30. /**
  31. * @var string theme id
  32. * @access protected
  33. */
  34. var $id = '';
  35. /**
  36. * @var string theme path
  37. * @access protected
  38. */
  39. var $path = '';
  40. /**
  41. * @var string image path
  42. * @access protected
  43. */
  44. var $img_path = '';
  45. /**
  46. * @var array valid css types
  47. * @access protected
  48. */
  49. var $types = array('left', 'right', 'print');
  50. /**
  51. * @var integer last modification time for info file
  52. * @access protected
  53. */
  54. var $mtime_info = 0;
  55. /**
  56. * needed because sometimes, the mtime for different themes
  57. * is identical
  58. * @var integer filesize for info file
  59. * @access protected
  60. */
  61. var $filesize_info = 0;
  62. /**
  63. * @access public
  64. * @uses PMA_Theme::getPath()
  65. * @uses PMA_Theme::$mtime_info
  66. * @uses PMA_Theme::setVersion()
  67. * @uses PMA_Theme::setName()
  68. * @uses filemtime()
  69. * @uses filesize()
  70. * @uses file_exists()
  71. * @return boolean whether loading them info was successful or not
  72. */
  73. function loadInfo()
  74. {
  75. if (! file_exists($this->getPath() . '/info.inc.php')) {
  76. return false;
  77. }
  78. if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
  79. return true;
  80. }
  81. @include $this->getPath() . '/info.inc.php';
  82. // was it set correctly?
  83. if (! isset($theme_name)) {
  84. return false;
  85. }
  86. $this->mtime_info = filemtime($this->getPath() . '/info.inc.php');
  87. $this->filesize_info = filesize($this->getPath() . '/info.inc.php');
  88. if (isset($theme_full_version)) {
  89. $this->setVersion($theme_full_version);
  90. } elseif (isset($theme_generation, $theme_version)) {
  91. $this->setVersion($theme_generation . '.' . $theme_version);
  92. }
  93. $this->setName($theme_name);
  94. return true;
  95. }
  96. /**
  97. * returns theme object loaded from given folder
  98. * or false if theme is invalid
  99. *
  100. * @static
  101. * @access public
  102. * @uses PMA_Theme
  103. * @uses PMA_Theme::setPath()
  104. * @uses PMA_Theme::loadInfo()
  105. * @uses PMA_Theme::checkImgPath()
  106. * @param string $folder path to theme
  107. * @return object PMA_Theme
  108. */
  109. static public function load($folder)
  110. {
  111. $theme = new PMA_Theme();
  112. $theme->setPath($folder);
  113. if (! $theme->loadInfo()) {
  114. return false;
  115. }
  116. $theme->checkImgPath();
  117. return $theme;
  118. }
  119. /**
  120. * checks image path for existance - if not found use img from original theme
  121. *
  122. * @access public
  123. * @uses PMA_Theme::getPath()
  124. * @uses PMA_Theme::setImgPath()
  125. * @uses PMA_Theme::getName()
  126. * @uses $GLOBALS['cfg']['ThemePath']
  127. * @uses $GLOBALS['strThemeNoValidImgPath']
  128. * @uses is_dir()
  129. * @uses sprintf()
  130. */
  131. function checkImgPath()
  132. {
  133. if (is_dir($this->getPath() . '/img/')) {
  134. $this->setImgPath($this->getPath() . '/img/');
  135. return true;
  136. } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
  137. $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
  138. return true;
  139. } else {
  140. trigger_error(
  141. sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
  142. E_USER_ERROR);
  143. return false;
  144. }
  145. }
  146. /**
  147. * returns path to theme
  148. *
  149. * @access public
  150. * @uses PMA_Theme::$path as return value
  151. * @return string $path path to theme
  152. */
  153. function getPath()
  154. {
  155. return $this->path;
  156. }
  157. /**
  158. * returns layout file
  159. *
  160. * @access public
  161. * @uses PMA_Theme::getPath()
  162. * @return string layout file
  163. */
  164. function getLayoutFile()
  165. {
  166. return $this->getPath() . '/layout.inc.php';
  167. }
  168. /**
  169. * set path to theme
  170. *
  171. * @access public
  172. * @uses PMA_Theme::$path to set it
  173. * @param string $path path to theme
  174. */
  175. function setPath($path)
  176. {
  177. $this->path = trim($path);
  178. }
  179. /**
  180. * sets version
  181. *
  182. * @access public
  183. * @uses PMA_Theme::$version
  184. * @param string new version
  185. */
  186. function setVersion($version)
  187. {
  188. $this->version = trim($version);
  189. }
  190. /**
  191. * returns version
  192. *
  193. * @access public
  194. * @uses PMA_Theme::$version
  195. * @return string version
  196. */
  197. function getVersion()
  198. {
  199. return $this->version;
  200. }
  201. /**
  202. * checks theme version agaisnt $version
  203. * returns true if theme version is equal or higher to $version
  204. *
  205. * @access public
  206. * @uses version_compare()
  207. * @uses PMA_Theme::getVersion()
  208. * @param string $version version to compare to
  209. * @return boolean
  210. */
  211. function checkVersion($version)
  212. {
  213. return version_compare($this->getVersion(), $version, 'lt');
  214. }
  215. /**
  216. * sets name
  217. *
  218. * @access public
  219. * @uses PMA_Theme::$name to set it
  220. * @uses trim()
  221. * @param string $name new name
  222. */
  223. function setName($name)
  224. {
  225. $this->name = trim($name);
  226. }
  227. /**
  228. * returns name
  229. *
  230. * @access public
  231. * @uses PMA_Theme::$name as return value
  232. * @return string name
  233. */
  234. function getName()
  235. {
  236. return $this->name;
  237. }
  238. /**
  239. * sets id
  240. *
  241. * @access public
  242. * @uses PMA_Theme::$id to set it
  243. * @param string $id new id
  244. */
  245. function setId($id)
  246. {
  247. $this->id = trim($id);
  248. }
  249. /**
  250. * returns id
  251. *
  252. * @access public
  253. * @uses PMA_Theme::$id as return value
  254. * @return string id
  255. */
  256. function getId()
  257. {
  258. return $this->id;
  259. }
  260. /**
  261. * @access public
  262. * @uses PMA_Theme::$img_path to set it
  263. * @param string path to images for this theme
  264. */
  265. function setImgPath($path)
  266. {
  267. $this->img_path = $path;
  268. }
  269. /**
  270. * @access public
  271. * @uses PMA_Theme::$img_path as retunr value
  272. * @return string image path for this theme
  273. */
  274. function getImgPath()
  275. {
  276. return $this->img_path;
  277. }
  278. /**
  279. * load css (send to stdout, normally the browser)
  280. *
  281. * @access public
  282. * @uses PMA_Theme::getPath()
  283. * @uses PMA_Theme::$types
  284. * @uses PMA_SQP_buildCssData()
  285. * @uses file_exists()
  286. * @uses in_array()
  287. * @param string $type left, right or print
  288. */
  289. function loadCss(&$type)
  290. {
  291. if (empty($type) || ! in_array($type, $this->types)) {
  292. $type = 'left';
  293. }
  294. if ($type == 'right') {
  295. echo PMA_SQP_buildCssData();
  296. }
  297. $_css_file = $this->getPath()
  298. . '/css/theme_' . $type . '.css.php';
  299. if (! file_exists($_css_file)) {
  300. return false;
  301. }
  302. if ($GLOBALS['text_dir'] === 'ltr') {
  303. $right = 'right';
  304. $left = 'left';
  305. } else {
  306. $right = 'left';
  307. $left = 'right';
  308. }
  309. include $_css_file;
  310. return true;
  311. }
  312. /**
  313. * prints out the preview for this theme
  314. *
  315. * @access public
  316. * @uses PMA_Theme::getName()
  317. * @uses PMA_Theme::getVersion()
  318. * @uses PMA_Theme::getId()
  319. * @uses PMA_Theme::getPath()
  320. * @uses $GLOBALS['strThemeNoPreviewAvailable']
  321. * @uses $GLOBALS['strTakeIt']
  322. * @uses PMA_generate_common_url()
  323. * @uses addslashes()
  324. * @uses file_exists()
  325. * @uses htmlspecialchars()
  326. */
  327. function printPreview()
  328. {
  329. echo '<div class="theme_preview">';
  330. echo '<h2>' . htmlspecialchars($this->getName())
  331. .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
  332. .'<p>'
  333. .'<a target="_top" href="index.php'
  334. .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
  335. .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
  336. .' return false;">';
  337. if (@file_exists($this->getPath() . '/screen.png')) {
  338. // if screen exists then output
  339. echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
  340. .' alt="' . htmlspecialchars($this->getName()) . '"'
  341. .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
  342. } else {
  343. echo $GLOBALS['strThemeNoPreviewAvailable'];
  344. }
  345. echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'
  346. .'</p>'
  347. .'</div>';
  348. }
  349. }
  350. ?>