summaryrefslogtreecommitdiff
path: root/inc/lib/minify/Minify/Controller/Page.php
diff options
context:
space:
mode:
authorMichael Save <savetheinternet@tinyboard.org>2012-04-09 20:52:26 +1000
committerMichael Save <savetheinternet@tinyboard.org>2012-04-09 20:52:26 +1000
commit874b8cbf002e9d8bf0ff39671e1501165016320a (patch)
tree1428acec23fef6c607e10fd355d88af31c2029ed /inc/lib/minify/Minify/Controller/Page.php
parent69c9a9dd452299e0e8f7335966a1d0b4036df583 (diff)
inc/contrib -> inc/lib
Diffstat (limited to 'inc/lib/minify/Minify/Controller/Page.php')
-rwxr-xr-xinc/lib/minify/Minify/Controller/Page.php87
1 files changed, 87 insertions, 0 deletions
diff --git a/inc/lib/minify/Minify/Controller/Page.php b/inc/lib/minify/Minify/Controller/Page.php
new file mode 100755
index 00000000..de471e12
--- /dev/null
+++ b/inc/lib/minify/Minify/Controller/Page.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * Class Minify_Controller_Page
+ * @package Minify
+ */
+
+require_once 'Minify/Controller/Base.php';
+
+/**
+ * Controller class for serving a single HTML page
+ *
+ * @link http://code.google.com/p/minify/source/browse/trunk/web/examples/1/index.php#59
+ * @package Minify
+ * @author Stephen Clay <steve@mrclay.org>
+ */
+class Minify_Controller_Page extends Minify_Controller_Base {
+
+ /**
+ * Set up source of HTML content
+ *
+ * @param array $options controller and Minify options
+ * @return array Minify options
+ *
+ * Controller options:
+ *
+ * 'content': (required) HTML markup
+ *
+ * 'id': (required) id of page (string for use in server-side caching)
+ *
+ * 'lastModifiedTime': timestamp of when this content changed. This
+ * is recommended to allow both server and client-side caching.
+ *
+ * 'minifyAll': should all CSS and Javascript blocks be individually
+ * minified? (default false)
+ *
+ * @todo Add 'file' option to read HTML file.
+ */
+ public function setupSources($options) {
+ if (isset($options['file'])) {
+ $sourceSpec = array(
+ 'filepath' => $options['file']
+ );
+ $f = $options['file'];
+ } else {
+ // strip controller options
+ $sourceSpec = array(
+ 'content' => $options['content']
+ ,'id' => $options['id']
+ );
+ $f = $options['id'];
+ unset($options['content'], $options['id']);
+ }
+ // something like "builder,index.php" or "directory,file.html"
+ $this->selectionId = strtr(substr($f, 1 + strlen(dirname(dirname($f)))), '/\\', ',,');
+
+ if (isset($options['minifyAll'])) {
+ // this will be the 2nd argument passed to Minify_HTML::minify()
+ $sourceSpec['minifyOptions'] = array(
+ 'cssMinifier' => array('Minify_CSS', 'minify')
+ ,'jsMinifier' => array('JSMin', 'minify')
+ );
+ $this->_loadCssJsMinifiers = true;
+ unset($options['minifyAll']);
+ }
+ $this->sources[] = new Minify_Source($sourceSpec);
+
+ $options['contentType'] = Minify::TYPE_HTML;
+ return $options;
+ }
+
+ protected $_loadCssJsMinifiers = false;
+
+ /**
+ * @see Minify_Controller_Base::loadMinifier()
+ */
+ public function loadMinifier($minifierCallback)
+ {
+ if ($this->_loadCssJsMinifiers) {
+ // Minify will not call for these so we must manually load
+ // them when Minify/HTML.php is called for.
+ require_once 'Minify/CSS.php';
+ require_once 'JSMin.php';
+ }
+ parent::loadMinifier($minifierCallback); // load Minify/HTML.php
+ }
+}
+