You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

min.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Easy Min
  4. *
  5. * Simple minification for better website performance
  6. *
  7. * @author Timothy J. Warren
  8. * @copyright Copyright (c) 2012-2016
  9. * @link https://git.timshomepage.net/aviat4ion/Easy-Min
  10. * @license http://philsturgeon.co.uk/code/dbad-license
  11. */
  12. // --------------------------------------------------------------------------
  13. namespace Aviat\EasyMin;
  14. //Creative rewriting of /g/groupname to ?g=groupname
  15. $pi = $_SERVER['PATH_INFO'];
  16. $pia = explode('/', $pi);
  17. $pia_len = count($pia);
  18. $i = 1;
  19. while($i < $pia_len)
  20. {
  21. $j = $i+1;
  22. $j = (isset($pia[$j])) ? $j : $i;
  23. $_GET[$pia[$i]] = $pia[$j];
  24. $i = $j + 1;
  25. };
  26. class FileNotChangedException extends \Exception {}
  27. class BaseMin {
  28. /**
  29. * Get value of the if-modified-since header
  30. *
  31. * @return int - timestamp to compare for cache control
  32. */
  33. protected function get_if_modified()
  34. {
  35. return (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER))
  36. ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])
  37. : time();
  38. }
  39. /**
  40. * Get value of etag to compare to hash of output
  41. *
  42. * @return string - the etag to compare
  43. */
  44. protected function get_if_none_match()
  45. {
  46. return (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER))
  47. ? $_SERVER['HTTP_IF_NONE_MATCH']
  48. : '';
  49. }
  50. /**
  51. * Determine whether or not to send debug version
  52. *
  53. * @return boolean
  54. */
  55. protected function is_not_debug()
  56. {
  57. return ! $this->is_debug_call();
  58. }
  59. /**
  60. * Determine whether or not to send debug version
  61. *
  62. * @return boolean
  63. */
  64. protected function is_debug_call()
  65. {
  66. return array_key_exists('debug', $_GET);
  67. }
  68. /**
  69. * Send actual output to browser
  70. *
  71. * @param string $content - the body of the response
  72. * @param string $mime_type - the content type
  73. * @param int $last_modified - the last modified date
  74. * @return void
  75. */
  76. protected function send_final_output($content, $mime_type, $last_modified)
  77. {
  78. //This GZIPs the CSS for transmission to the user
  79. //making file size smaller and transfer rate quicker
  80. ob_start("ob_gzhandler");
  81. $expires = $last_modified + 691200;
  82. $last_modified_date = gmdate('D, d M Y H:i:s', $last_modified);
  83. $expires_date = gmdate('D, d M Y H:i:s', $expires);
  84. header("Content-Type: {$mime_type}; charset=utf8");
  85. header("Cache-control: public, max-age=691200, must-revalidate");
  86. header("Last-Modified: {$last_modified_date} GMT");
  87. header("Expires: {$expires_date} GMT");
  88. echo $content;
  89. ob_end_flush();
  90. }
  91. /**
  92. * Send a 304 Not Modified header
  93. *
  94. * @return void
  95. */
  96. public static function send304()
  97. {
  98. header("status: 304 Not Modified", true, 304);
  99. }
  100. }