svg_gradient.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Theme based generator for SVG gradient.
  4. *
  5. * @package PhpMyAdmin-theme
  6. */
  7. header('Content-Type: image/svg+xml');
  8. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 3600) . ' GMT');
  9. /**
  10. * Gets single color from GET parameters validating it.
  11. *
  12. * @param string $get_name Name of parameter in request
  13. * @param string $default Default value
  14. *
  15. * @return string Color name or code.
  16. */
  17. function PMA_gradientGetColor($get_name, $default)
  18. {
  19. // get color from GET args, only alphanumeric characters
  20. $opts = array('options' => array('regexp' => '/^[a-z0-9]+$/i'));
  21. $color = filter_input(INPUT_GET, $get_name, FILTER_VALIDATE_REGEXP, $opts);
  22. if (preg_match('/^[a-f0-9]{6}$/', $color)) {
  23. return '#' . $color;
  24. }
  25. return $color ? $color : $default;
  26. }
  27. $from = PMA_gradientGetColor('from', 'white');
  28. $to = PMA_gradientGetColor('to', 'blank');
  29. echo '<?xml version="1.0" ?>';
  30. ?>
  31. <svg
  32. xmlns="http://www.w3.org/2000/svg"
  33. preserveAspectRatio="none"
  34. version="1.0" width="100%" height="100%">
  35. <defs>
  36. <linearGradient id="linear-gradient" x1="0%" y1="0%" x2="0%" y2="100%">
  37. <stop
  38. offset="0%"
  39. stop-color="<?php echo $from; ?>"
  40. stop-opacity="1"
  41. />
  42. <stop
  43. offset="100%"
  44. stop-color="<?php echo $to; ?>"
  45. stop-opacity="1"
  46. />
  47. </linearGradient>
  48. </defs>
  49. <rect width="100%" height="100%" style="fill:url(#linear-gradient);" />
  50. </svg>