Page.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. }