sprites.css.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * This file generates the CSS code for the sprites of a theme
  5. *
  6. * @package PhpMyAdmin-theme
  7. */
  8. // unplanned execution path
  9. if (! defined('PMA_MINIMUM_COMMON')) {
  10. exit();
  11. }
  12. $bg = $_SESSION['PMA_Theme']->getImgPath() . 'sprites.png';
  13. /* Check if there is a valid data file for sprites */
  14. if (is_readable($_SESSION['PMA_Theme']->getPath() . '/sprites.lib.php')) {
  15. ?>
  16. /* Icon sprites */
  17. .icon {
  18. margin: 0 .3em;
  19. padding: 0 !important;
  20. width: 16px;
  21. height: 16px;
  22. background-image: url('<?php echo $bg; ?>') !important;
  23. background-repeat: no-repeat !important;
  24. background-position: top left !important;
  25. }
  26. <?php
  27. include_once $_SESSION['PMA_Theme']->getPath() . '/sprites.lib.php';
  28. $sprites = array();
  29. if (function_exists('PMA_sprites')) {
  30. $sprites = PMA_sprites();
  31. }
  32. $template = ".ic_%s { background-position: 0 -%upx !important;%s%s }\n";
  33. foreach ($sprites as $name => $data) {
  34. // generate the CSS code for each icon
  35. $width = '';
  36. $height = '';
  37. // if either the height or width of an icon is 16px,
  38. // then it's pointless to set this as a parameter,
  39. //since it will be inherited from the "icon" class
  40. if ($data['width'] != 16) {
  41. $width = " width: " . $data['width'] . "px;";
  42. }
  43. if ($data['height'] != 16) {
  44. $height = " height: " . $data['height'] . "px;";
  45. }
  46. printf(
  47. $template,
  48. $name,
  49. ($data['position'] * 16),
  50. $width,
  51. $height
  52. );
  53. }
  54. // Here we map some of the classes that we
  55. // defined above to other CSS selectors.
  56. // The indexes of the array correspond to
  57. // already defined classes and the values
  58. // are the selectors that we want to map to.
  59. $elements = array(
  60. 's_sortable' => 'img.sortableIcon',
  61. 's_asc' => 'th.headerSortUp img.sortableIcon',
  62. 's_desc' => 'th.headerSortDown img.sortableIcon'
  63. );
  64. $template = "%s { background-position: 0 -%upx; "
  65. . "height: %upx; width: %upx; }\n";
  66. foreach ($elements as $key => $value) {
  67. if (isset($sprites[$key])) { // If the CSS class has been defined
  68. printf(
  69. $template,
  70. $value,
  71. ($sprites[$key]['position'] * 16),
  72. $sprites[$key]['height'],
  73. $sprites[$key]['width']
  74. );
  75. }
  76. }
  77. }
  78. ?>