Page.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Class Minify_Controller_Page
  4. * @package Minify
  5. */
  6. /**
  7. * Controller class for serving a single HTML page
  8. *
  9. * @link http://code.google.com/p/minify/source/browse/trunk/web/examples/1/index.php#59
  10. * @package Minify
  11. * @author Stephen Clay <steve@mrclay.org>
  12. */
  13. class Minify_Controller_Page extends Minify_Controller_Base {
  14. /**
  15. * Set up source of HTML content
  16. *
  17. * @param array $options controller and Minify options
  18. * @return array Minify options
  19. *
  20. * Controller options:
  21. *
  22. * 'content': (required) HTML markup
  23. *
  24. * 'id': (required) id of page (string for use in server-side caching)
  25. *
  26. * 'lastModifiedTime': timestamp of when this content changed. This
  27. * is recommended to allow both server and client-side caching.
  28. *
  29. * 'minifyAll': should all CSS and Javascript blocks be individually
  30. * minified? (default false)
  31. *
  32. * @todo Add 'file' option to read HTML file.
  33. */
  34. public function setupSources($options) {
  35. if (isset($options['file'])) {
  36. $sourceSpec = array(
  37. 'filepath' => $options['file']
  38. );
  39. $f = $options['file'];
  40. } else {
  41. // strip controller options
  42. $sourceSpec = array(
  43. 'content' => $options['content']
  44. ,'id' => $options['id']
  45. );
  46. $f = $options['id'];
  47. unset($options['content'], $options['id']);
  48. }
  49. // something like "builder,index.php" or "directory,file.html"
  50. $this->selectionId = strtr(substr($f, 1 + strlen(dirname(dirname($f)))), '/\\', ',,');
  51. if (isset($options['minifyAll'])) {
  52. // this will be the 2nd argument passed to Minify_HTML::minify()
  53. $sourceSpec['minifyOptions'] = array(
  54. 'cssMinifier' => array('Minify_CSS', 'minify')
  55. ,'jsMinifier' => array('JSMin', 'minify')
  56. );
  57. unset($options['minifyAll']);
  58. }
  59. $this->sources[] = new Minify_Source($sourceSpec);
  60. $options['contentType'] = Minify::TYPE_HTML;
  61. return $options;
  62. }
  63. }