]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Minify/extlib/minify/min/lib/Minify/Controller/Page.php
Added minify plugin
[quix0rs-gnu-social.git] / plugins / Minify / extlib / minify / min / lib / Minify / Controller / Page.php
1 <?php
2 /**
3  * Class Minify_Controller_Page  
4  * @package Minify
5  */
6
7 require_once 'Minify/Controller/Base.php';
8
9 /**
10  * Controller class for serving a single HTML page
11  * 
12  * @link http://code.google.com/p/minify/source/browse/trunk/web/examples/1/index.php#59
13  * @package Minify
14  * @author Stephen Clay <steve@mrclay.org>
15  */
16 class Minify_Controller_Page extends Minify_Controller_Base {
17     
18     /**
19      * Set up source of HTML content
20      * 
21      * @param array $options controller and Minify options
22      * @return array Minify options
23      * 
24      * Controller options:
25      * 
26      * 'content': (required) HTML markup
27      * 
28      * 'id': (required) id of page (string for use in server-side caching)
29      * 
30      * 'lastModifiedTime': timestamp of when this content changed. This
31      * is recommended to allow both server and client-side caching.
32      * 
33      * 'minifyAll': should all CSS and Javascript blocks be individually 
34      * minified? (default false) 
35      *
36      * @todo Add 'file' option to read HTML file.
37      */
38     public function setupSources($options) {
39         if (isset($options['file'])) {
40             $sourceSpec = array(
41                 'filepath' => $options['file']
42             );
43         } else {
44             // strip controller options
45             $sourceSpec = array(
46                 'content' => $options['content']
47                 ,'id' => $options['id']
48             );
49             unset($options['content'], $options['id']);
50         }
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             $this->_loadCssJsMinifiers = true;
58             unset($options['minifyAll']);
59         }
60         $this->sources[] = new Minify_Source($sourceSpec);
61         
62         $options['contentType'] = Minify::TYPE_HTML;
63         return $options;
64     }
65     
66     protected $_loadCssJsMinifiers = false;
67     
68     /**
69      * @see Minify_Controller_Base::loadMinifier()
70      */
71     public function loadMinifier($minifierCallback)
72     {
73         if ($this->_loadCssJsMinifiers) {
74             // Minify will not call for these so we must manually load
75             // them when Minify/HTML.php is called for.
76             require_once 'Minify/CSS.php';
77             require_once 'JSMin.php';
78         }
79         parent::loadMinifier($minifierCallback); // load Minify/HTML.php
80     }
81 }
82