pquery.css.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * pQuery plugin for composing sets of CSS stylesheets.
  4. * The plugin has built-in cache control and uses the CssParser class.
  5. *
  6. * @package pQuery
  7. */
  8. __p::require_plugins('cache');
  9. __p::load_utils('CssParser');
  10. /**
  11. * pQuery extension class for the 'css' plugin.
  12. */
  13. class pQueryCss extends pQueryCache {
  14. static $accepts = array('array' => 'add_extensions', 'string' => 'make_array');
  15. var $minify_config = array(
  16. 'replace_shorthands' => true,
  17. 'sort_rules' => true,
  18. 'minify' => true,
  19. 'compress_measurements' => true,
  20. 'compress_colors' => true
  21. );
  22. /**
  23. * Make a single file into an array.
  24. *
  25. * @param string $file The file to put in an array.
  26. */
  27. function make_array($file) {
  28. return $this->add_extensions(array($file));
  29. }
  30. /**
  31. *
  32. *
  33. * @param array $files
  34. */
  35. function add_extensions($files) {
  36. foreach( $files as $i => $file )
  37. if( !preg_match('/\.css$/', $file) )
  38. $files[$i] = $file.'.css';
  39. return $this->get_modification_dates($files);
  40. }
  41. /**
  42. *
  43. *
  44. * @param array $override
  45. */
  46. function set_config($override) {
  47. $this->minify_config = array_merge($this->minify_config, $override);
  48. return $this;
  49. }
  50. /**
  51. *
  52. */
  53. function minify() {
  54. $this->content = CssParser::minify($this->content, $this->minify_config);
  55. return $this;
  56. }
  57. /**
  58. *
  59. */
  60. function set_headers() {
  61. header('Content-Type: text/css');
  62. return $this;
  63. }
  64. }
  65. /**
  66. * Shortcut constructor for {@link pQueryCss}.
  67. *
  68. * @param array|string $stylesheets
  69. * @returns pQueryCss A new stylesheet cache instance.
  70. */
  71. function _css($stylesheets) {
  72. return pQuery::create('css', $stylesheets);
  73. }
  74. /*
  75. * Add plugin to pQuery
  76. */
  77. __p::extend('pQueryCss', 'css');
  78. ?>