pquery.css.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. function minify() {
  45. $this->content = CssParser::minify($this->content, $this->minify_config);
  46. return $this;
  47. }
  48. /**
  49. *
  50. */
  51. function set_headers() {
  52. header('Content-Type: text/css');
  53. return $this;
  54. }
  55. }
  56. /**
  57. * Shortcut constructor for {@link pQueryCss}.
  58. *
  59. * @param array|string $stylesheets
  60. * @returns pQueryCss A new stylesheet cache instance.
  61. */
  62. function _css($stylesheets) {
  63. return pQuery::create('css', $stylesheets);
  64. }
  65. /*
  66. * Add plugin to pQuery
  67. */
  68. __p::extend('pQueryCss', 'css');
  69. ?>