sprites.css.php 2.5 KB

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