pquery.css.php 1.4 KB

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