bixbite 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.markdown +49 -0
- data/VERSION +1 -0
- data/bin/bixbite +73 -0
- data/lib/bixbite.rb +13 -0
- data/lib/bixbite/command.rb +14 -0
- data/lib/bixbite/create.rb +76 -0
- data/template/Rakefile +25 -0
- data/template/assets/bixbite/Rakefile.rb +297 -0
- data/template/assets/naturaldocs/NaturalDocs/Config/Languages.txt +286 -0
- data/template/assets/naturaldocs/NaturalDocs/Config/Topics.txt +382 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/customizinglanguages.html +52 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/customizingtopics.html +74 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/documenting.html +58 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/documenting/reference.html +146 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/documenting/walkthrough.html +180 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/example/Default.css +528 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/example/NaturalDocs.js +204 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/examples.css +90 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/header/background.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/header/leftside.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/header/logo.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/header/overbody.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/header/overbodybg.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/header/overleftmargin.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/header/overmenu.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/header/overmenubg.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/header/rightside.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/logo.gif +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/menu/about.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/menu/background.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/menu/bottomleft.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/menu/bottomright.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/menu/community.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/menu/customizing.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/images/menu/using.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/index.html +9 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/javascript/BrowserStyles.js +77 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/javascript/PNGHandling.js +72 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/keywords.html +38 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/languages.html +32 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/menu.html +79 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/output.html +84 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/running.html +40 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/styles.css +290 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/styles.html +52 -0
- data/template/assets/naturaldocs/NaturalDocs/Help/troubleshooting.html +18 -0
- data/template/assets/naturaldocs/NaturalDocs/Info/CSSGuide.txt +947 -0
- data/template/assets/naturaldocs/NaturalDocs/Info/File Parsing.txt +83 -0
- data/template/assets/naturaldocs/NaturalDocs/Info/HTMLTestCases.pm +269 -0
- data/template/assets/naturaldocs/NaturalDocs/Info/Languages.txt +107 -0
- data/template/assets/naturaldocs/NaturalDocs/Info/NDMarkup.txt +91 -0
- data/template/assets/naturaldocs/NaturalDocs/Info/Symbol Management.txt +59 -0
- data/template/assets/naturaldocs/NaturalDocs/Info/images/Logo.png +0 -0
- data/template/assets/naturaldocs/NaturalDocs/JavaScript/NaturalDocs.js +836 -0
- data/template/assets/naturaldocs/NaturalDocs/License-GPL.txt +341 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/BinaryFile.pm +294 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Builder.pm +280 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Builder/Base.pm +348 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Builder/FramedHTML.pm +345 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Builder/HTML.pm +398 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Builder/HTMLBase.pm +3693 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ClassHierarchy.pm +860 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ClassHierarchy/Class.pm +412 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ClassHierarchy/File.pm +157 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ConfigFile.pm +497 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Constants.pm +165 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/DefineMembers.pm +100 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Error.pm +305 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/File.pm +540 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ImageReferenceTable.pm +383 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ImageReferenceTable/Reference.pm +44 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ImageReferenceTable/String.pm +110 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages.pm +1475 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/ActionScript.pm +1473 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Ada.pm +38 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Advanced.pm +828 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Advanced/Scope.pm +95 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Advanced/ScopeChange.pm +70 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Base.pm +832 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/CSharp.pm +1484 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/PLSQL.pm +319 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Pascal.pm +143 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Perl.pm +1370 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Prototype.pm +92 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Prototype/Parameter.pm +87 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Simple.pm +503 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Languages/Tcl.pm +219 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Menu.pm +3406 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Menu/Entry.pm +201 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/NDMarkup.pm +76 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Parser.pm +1331 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Parser/JavaDoc.pm +464 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Parser/Native.pm +1060 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Parser/ParsedTopic.pm +253 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Project.pm +1402 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Project/ImageFile.pm +160 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Project/SourceFile.pm +113 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/ReferenceString.pm +334 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Settings.pm +1418 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Settings/BuildTarget.pm +66 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SourceDB.pm +678 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SourceDB/Extension.pm +84 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SourceDB/File.pm +129 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SourceDB/Item.pm +201 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SourceDB/ItemDefinition.pm +45 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SourceDB/WatchedFileDefinitions.pm +159 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/StatusMessage.pm +102 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolString.pm +212 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolTable.pm +1984 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolTable/File.pm +186 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolTable/IndexElement.pm +522 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolTable/Reference.pm +273 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolTable/ReferenceTarget.pm +97 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolTable/Symbol.pm +428 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/SymbolTable/SymbolDefinition.pm +96 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Topics.pm +1319 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Topics/Type.pm +151 -0
- data/template/assets/naturaldocs/NaturalDocs/Modules/NaturalDocs/Version.pm +384 -0
- data/template/assets/naturaldocs/NaturalDocs/NaturalDocs +400 -0
- data/template/assets/naturaldocs/NaturalDocs/NaturalDocs.bat +17 -0
- data/template/assets/naturaldocs/NaturalDocs/Styles/Default.css +767 -0
- data/template/assets/naturaldocs/NaturalDocs/Styles/Roman.css +765 -0
- data/template/assets/naturaldocs/NaturalDocs/Styles/Small.css +763 -0
- data/template/assets/utilities/pngout +0 -0
- data/template/deploy/public_html/.htaccess +0 -0
- data/template/documentation/js/.htaccess +0 -0
- data/template/src/html/.htaccess +76 -0
- data/template/src/html/css/cmn/global.css +96 -0
- data/template/src/html/css/cmn/ie.css +15 -0
- data/template/src/html/css/cmn/ie6.css +15 -0
- data/template/src/html/images/cmn/.htaccess +0 -0
- data/template/src/html/images/tmp/.htaccess +0 -0
- data/template/src/html/includes/debug.inc +5 -0
- data/template/src/html/includes/footer.inc +52 -0
- data/template/src/html/includes/header.inc +61 -0
- data/template/src/html/includes/html.inc +3 -0
- data/template/src/html/includes/namespace.inc +19 -0
- data/template/src/html/includes/page.inc +151 -0
- data/template/src/html/index.html +35 -0
- data/template/src/html/js/cmn/bootstrap.js +74 -0
- data/template/src/html/js/cmn/global.js +142 -0
- data/template/src/html/js/cmn/lib/LAB.js +348 -0
- data/template/src/html/min/.htaccess +4 -0
- data/template/src/html/min/MinifyCLI.php +19 -0
- data/template/src/html/min/README.txt +132 -0
- data/template/src/html/min/builder/_index.js +242 -0
- data/template/src/html/min/builder/bm.js +36 -0
- data/template/src/html/min/builder/index.php +182 -0
- data/template/src/html/min/builder/ocCheck.php +36 -0
- data/template/src/html/min/builder/rewriteTest.js +1 -0
- data/template/src/html/min/config.php +187 -0
- data/template/src/html/min/groupsConfig.php +34 -0
- data/template/src/html/min/index.php +66 -0
- data/template/src/html/min/lib/FirePHP.php +1370 -0
- data/template/src/html/min/lib/HTTP/ConditionalGet.php +348 -0
- data/template/src/html/min/lib/HTTP/Encoder.php +326 -0
- data/template/src/html/min/lib/JSMin.php +314 -0
- data/template/src/html/min/lib/JSMinPlus.php +1872 -0
- data/template/src/html/min/lib/Minify.php +532 -0
- data/template/src/html/min/lib/Minify/Build.php +103 -0
- data/template/src/html/min/lib/Minify/CSS.php +83 -0
- data/template/src/html/min/lib/Minify/CSS/Compressor.php +250 -0
- data/template/src/html/min/lib/Minify/CSS/UriRewriter.php +270 -0
- data/template/src/html/min/lib/Minify/Cache/APC.php +130 -0
- data/template/src/html/min/lib/Minify/Cache/File.php +125 -0
- data/template/src/html/min/lib/Minify/Cache/Memcache.php +137 -0
- data/template/src/html/min/lib/Minify/ClosureCompiler.php +85 -0
- data/template/src/html/min/lib/Minify/CommentPreserver.php +90 -0
- data/template/src/html/min/lib/Minify/Controller/Base.php +202 -0
- data/template/src/html/min/lib/Minify/Controller/Files.php +78 -0
- data/template/src/html/min/lib/Minify/Controller/Groups.php +94 -0
- data/template/src/html/min/lib/Minify/Controller/MinApp.php +132 -0
- data/template/src/html/min/lib/Minify/Controller/Page.php +82 -0
- data/template/src/html/min/lib/Minify/Controller/Version1.php +118 -0
- data/template/src/html/min/lib/Minify/HTML.php +245 -0
- data/template/src/html/min/lib/Minify/ImportProcessor.php +157 -0
- data/template/src/html/min/lib/Minify/Lines.php +131 -0
- data/template/src/html/min/lib/Minify/Logger.php +45 -0
- data/template/src/html/min/lib/Minify/Packer.php +37 -0
- data/template/src/html/min/lib/Minify/Source.php +187 -0
- data/template/src/html/min/lib/Minify/YUICompressor.php +139 -0
- data/template/src/html/min/lib/Solar/Dir.php +199 -0
- data/template/src/html/min/lib/closure-compiler.jar +0 -0
- data/template/src/html/min/lib/yuicompressor-2.4.2.jar +0 -0
- data/template/src/html/min/utils.php +90 -0
- data/template/src/templates/css/template.css +7 -0
- data/template/src/templates/js/template.js +72 -0
- data/template/src/templates/template.html +18 -0
- data/template/src/yaml/config.yml +46 -0
- data/template/src/yaml/deploy.yml +35 -0
- data/test/bixbite_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +278 -0
@@ -0,0 +1,132 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* Class Minify_Controller_MinApp
|
4
|
+
* @package Minify
|
5
|
+
*/
|
6
|
+
|
7
|
+
require_once 'Minify/Controller/Base.php';
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Controller class for requests to /min/index.php
|
11
|
+
*
|
12
|
+
* @package Minify
|
13
|
+
* @author Stephen Clay <steve@mrclay.org>
|
14
|
+
*/
|
15
|
+
class Minify_Controller_MinApp extends Minify_Controller_Base {
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Set up groups of files as sources
|
19
|
+
*
|
20
|
+
* @param array $options controller and Minify options
|
21
|
+
* @return array Minify options
|
22
|
+
*
|
23
|
+
*/
|
24
|
+
public function setupSources($options) {
|
25
|
+
// filter controller options
|
26
|
+
$cOptions = array_merge(
|
27
|
+
array(
|
28
|
+
'allowDirs' => '//'
|
29
|
+
,'groupsOnly' => false
|
30
|
+
,'groups' => array()
|
31
|
+
,'maxFiles' => 10
|
32
|
+
)
|
33
|
+
,(isset($options['minApp']) ? $options['minApp'] : array())
|
34
|
+
);
|
35
|
+
unset($options['minApp']);
|
36
|
+
$sources = array();
|
37
|
+
if (isset($_GET['g'])) {
|
38
|
+
// try groups
|
39
|
+
if (! isset($cOptions['groups'][$_GET['g']])) {
|
40
|
+
$this->log("A group configuration for \"{$_GET['g']}\" was not set");
|
41
|
+
return $options;
|
42
|
+
}
|
43
|
+
|
44
|
+
$files = $cOptions['groups'][$_GET['g']];
|
45
|
+
// if $files is a single object, casting will break it
|
46
|
+
if (is_object($files)) {
|
47
|
+
$files = array($files);
|
48
|
+
} elseif (! is_array($files)) {
|
49
|
+
$files = (array)$files;
|
50
|
+
}
|
51
|
+
foreach ($files as $file) {
|
52
|
+
if ($file instanceof Minify_Source) {
|
53
|
+
$sources[] = $file;
|
54
|
+
continue;
|
55
|
+
}
|
56
|
+
if (0 === strpos($file, '//')) {
|
57
|
+
$file = $_SERVER['DOCUMENT_ROOT'] . substr($file, 1);
|
58
|
+
}
|
59
|
+
$file = realpath($file);
|
60
|
+
if (is_file($file)) {
|
61
|
+
$sources[] = new Minify_Source(array(
|
62
|
+
'filepath' => $file
|
63
|
+
));
|
64
|
+
} else {
|
65
|
+
$this->log("The path \"{$file}\" could not be found (or was not a file)");
|
66
|
+
return $options;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
} elseif (! $cOptions['groupsOnly'] && isset($_GET['f'])) {
|
70
|
+
// try user files
|
71
|
+
// The following restrictions are to limit the URLs that minify will
|
72
|
+
// respond to. Ideally there should be only one way to reference a file.
|
73
|
+
if (// verify at least one file, files are single comma separated,
|
74
|
+
// and are all same extension
|
75
|
+
! preg_match('/^[^,]+\\.(css|js)(?:,[^,]+\\.\\1)*$/', $_GET['f'])
|
76
|
+
// no "//"
|
77
|
+
|| strpos($_GET['f'], '//') !== false
|
78
|
+
// no "\"
|
79
|
+
|| strpos($_GET['f'], '\\') !== false
|
80
|
+
// no "./"
|
81
|
+
|| preg_match('/(?:^|[^\\.])\\.\\//', $_GET['f'])
|
82
|
+
) {
|
83
|
+
$this->log("GET param 'f' invalid (see MinApp.php line 63)");
|
84
|
+
return $options;
|
85
|
+
}
|
86
|
+
$files = explode(',', $_GET['f']);
|
87
|
+
if (count($files) > $cOptions['maxFiles'] || $files != array_unique($files)) {
|
88
|
+
$this->log("Too many or duplicate files specified");
|
89
|
+
return $options;
|
90
|
+
}
|
91
|
+
if (isset($_GET['b'])) {
|
92
|
+
// check for validity
|
93
|
+
if (preg_match('@^[^/]+(?:/[^/]+)*$@', $_GET['b'])
|
94
|
+
&& false === strpos($_GET['b'], '..')
|
95
|
+
&& $_GET['b'] !== '.') {
|
96
|
+
// valid base
|
97
|
+
$base = "/{$_GET['b']}/";
|
98
|
+
} else {
|
99
|
+
$this->log("GET param 'b' invalid (see MinApp.php line 84)");
|
100
|
+
return $options;
|
101
|
+
}
|
102
|
+
} else {
|
103
|
+
$base = '/';
|
104
|
+
}
|
105
|
+
$allowDirs = array();
|
106
|
+
foreach ((array)$cOptions['allowDirs'] as $allowDir) {
|
107
|
+
$allowDirs[] = realpath(str_replace('//', $_SERVER['DOCUMENT_ROOT'] . '/', $allowDir));
|
108
|
+
}
|
109
|
+
foreach ($files as $file) {
|
110
|
+
$path = $_SERVER['DOCUMENT_ROOT'] . $base . $file;
|
111
|
+
$file = realpath($path);
|
112
|
+
if (false === $file) {
|
113
|
+
$this->log("Path \"{$path}\" failed realpath()");
|
114
|
+
return $options;
|
115
|
+
} elseif (! parent::_fileIsSafe($file, $allowDirs)) {
|
116
|
+
$this->log("Path \"{$path}\" failed Minify_Controller_Base::_fileIsSafe()");
|
117
|
+
return $options;
|
118
|
+
} else {
|
119
|
+
$sources[] = new Minify_Source(array(
|
120
|
+
'filepath' => $file
|
121
|
+
));
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
if ($sources) {
|
126
|
+
$this->sources = $sources;
|
127
|
+
} else {
|
128
|
+
$this->log("No sources to serve");
|
129
|
+
}
|
130
|
+
return $options;
|
131
|
+
}
|
132
|
+
}
|
@@ -0,0 +1,82 @@
|
|
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
|
+
|
@@ -0,0 +1,118 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* Class Minify_Controller_Version1
|
4
|
+
* @package Minify
|
5
|
+
*/
|
6
|
+
|
7
|
+
require_once 'Minify/Controller/Base.php';
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Controller class for emulating version 1 of minify.php
|
11
|
+
*
|
12
|
+
* <code>
|
13
|
+
* Minify::serve('Version1');
|
14
|
+
* </code>
|
15
|
+
*
|
16
|
+
* @package Minify
|
17
|
+
* @author Stephen Clay <steve@mrclay.org>
|
18
|
+
*/
|
19
|
+
class Minify_Controller_Version1 extends Minify_Controller_Base {
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Set up groups of files as sources
|
23
|
+
*
|
24
|
+
* @param array $options controller and Minify options
|
25
|
+
* @return array Minify options
|
26
|
+
*
|
27
|
+
*/
|
28
|
+
public function setupSources($options) {
|
29
|
+
self::_setupDefines();
|
30
|
+
if (MINIFY_USE_CACHE) {
|
31
|
+
$cacheDir = defined('MINIFY_CACHE_DIR')
|
32
|
+
? MINIFY_CACHE_DIR
|
33
|
+
: '';
|
34
|
+
Minify::setCache($cacheDir);
|
35
|
+
}
|
36
|
+
$options['badRequestHeader'] = 'HTTP/1.0 404 Not Found';
|
37
|
+
$options['contentTypeCharset'] = MINIFY_ENCODING;
|
38
|
+
|
39
|
+
// The following restrictions are to limit the URLs that minify will
|
40
|
+
// respond to. Ideally there should be only one way to reference a file.
|
41
|
+
if (! isset($_GET['files'])
|
42
|
+
// verify at least one file, files are single comma separated,
|
43
|
+
// and are all same extension
|
44
|
+
|| ! preg_match('/^[^,]+\\.(css|js)(,[^,]+\\.\\1)*$/', $_GET['files'], $m)
|
45
|
+
// no "//" (makes URL rewriting easier)
|
46
|
+
|| strpos($_GET['files'], '//') !== false
|
47
|
+
// no "\"
|
48
|
+
|| strpos($_GET['files'], '\\') !== false
|
49
|
+
// no "./"
|
50
|
+
|| preg_match('/(?:^|[^\\.])\\.\\//', $_GET['files'])
|
51
|
+
) {
|
52
|
+
return $options;
|
53
|
+
}
|
54
|
+
$extension = $m[1];
|
55
|
+
|
56
|
+
$files = explode(',', $_GET['files']);
|
57
|
+
if (count($files) > MINIFY_MAX_FILES) {
|
58
|
+
return $options;
|
59
|
+
}
|
60
|
+
|
61
|
+
// strings for prepending to relative/absolute paths
|
62
|
+
$prependRelPaths = dirname($_SERVER['SCRIPT_FILENAME'])
|
63
|
+
. DIRECTORY_SEPARATOR;
|
64
|
+
$prependAbsPaths = $_SERVER['DOCUMENT_ROOT'];
|
65
|
+
|
66
|
+
$sources = array();
|
67
|
+
$goodFiles = array();
|
68
|
+
$hasBadSource = false;
|
69
|
+
|
70
|
+
$allowDirs = isset($options['allowDirs'])
|
71
|
+
? $options['allowDirs']
|
72
|
+
: MINIFY_BASE_DIR;
|
73
|
+
|
74
|
+
foreach ($files as $file) {
|
75
|
+
// prepend appropriate string for abs/rel paths
|
76
|
+
$file = ($file[0] === '/' ? $prependAbsPaths : $prependRelPaths) . $file;
|
77
|
+
// make sure a real file!
|
78
|
+
$file = realpath($file);
|
79
|
+
// don't allow unsafe or duplicate files
|
80
|
+
if (parent::_fileIsSafe($file, $allowDirs)
|
81
|
+
&& !in_array($file, $goodFiles))
|
82
|
+
{
|
83
|
+
$goodFiles[] = $file;
|
84
|
+
$srcOptions = array(
|
85
|
+
'filepath' => $file
|
86
|
+
);
|
87
|
+
$this->sources[] = new Minify_Source($srcOptions);
|
88
|
+
} else {
|
89
|
+
$hasBadSource = true;
|
90
|
+
break;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
if ($hasBadSource) {
|
94
|
+
$this->sources = array();
|
95
|
+
}
|
96
|
+
if (! MINIFY_REWRITE_CSS_URLS) {
|
97
|
+
$options['rewriteCssUris'] = false;
|
98
|
+
}
|
99
|
+
return $options;
|
100
|
+
}
|
101
|
+
|
102
|
+
private static function _setupDefines()
|
103
|
+
{
|
104
|
+
$defaults = array(
|
105
|
+
'MINIFY_BASE_DIR' => realpath($_SERVER['DOCUMENT_ROOT'])
|
106
|
+
,'MINIFY_ENCODING' => 'utf-8'
|
107
|
+
,'MINIFY_MAX_FILES' => 16
|
108
|
+
,'MINIFY_REWRITE_CSS_URLS' => true
|
109
|
+
,'MINIFY_USE_CACHE' => true
|
110
|
+
);
|
111
|
+
foreach ($defaults as $const => $val) {
|
112
|
+
if (! defined($const)) {
|
113
|
+
define($const, $val);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
@@ -0,0 +1,245 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* Class Minify_HTML
|
4
|
+
* @package Minify
|
5
|
+
*/
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Compress HTML
|
9
|
+
*
|
10
|
+
* This is a heavy regex-based removal of whitespace, unnecessary comments and
|
11
|
+
* tokens. IE conditional comments are preserved. There are also options to have
|
12
|
+
* STYLE and SCRIPT blocks compressed by callback functions.
|
13
|
+
*
|
14
|
+
* A test suite is available.
|
15
|
+
*
|
16
|
+
* @package Minify
|
17
|
+
* @author Stephen Clay <steve@mrclay.org>
|
18
|
+
*/
|
19
|
+
class Minify_HTML {
|
20
|
+
|
21
|
+
/**
|
22
|
+
* "Minify" an HTML page
|
23
|
+
*
|
24
|
+
* @param string $html
|
25
|
+
*
|
26
|
+
* @param array $options
|
27
|
+
*
|
28
|
+
* 'cssMinifier' : (optional) callback function to process content of STYLE
|
29
|
+
* elements.
|
30
|
+
*
|
31
|
+
* 'jsMinifier' : (optional) callback function to process content of SCRIPT
|
32
|
+
* elements. Note: the type attribute is ignored.
|
33
|
+
*
|
34
|
+
* 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
|
35
|
+
* unset, minify will sniff for an XHTML doctype.
|
36
|
+
*
|
37
|
+
* @return string
|
38
|
+
*/
|
39
|
+
public static function minify($html, $options = array()) {
|
40
|
+
$min = new Minify_HTML($html, $options);
|
41
|
+
return $min->process();
|
42
|
+
}
|
43
|
+
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Create a minifier object
|
47
|
+
*
|
48
|
+
* @param string $html
|
49
|
+
*
|
50
|
+
* @param array $options
|
51
|
+
*
|
52
|
+
* 'cssMinifier' : (optional) callback function to process content of STYLE
|
53
|
+
* elements.
|
54
|
+
*
|
55
|
+
* 'jsMinifier' : (optional) callback function to process content of SCRIPT
|
56
|
+
* elements. Note: the type attribute is ignored.
|
57
|
+
*
|
58
|
+
* 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
|
59
|
+
* unset, minify will sniff for an XHTML doctype.
|
60
|
+
*
|
61
|
+
* @return null
|
62
|
+
*/
|
63
|
+
public function __construct($html, $options = array())
|
64
|
+
{
|
65
|
+
$this->_html = str_replace("\r\n", "\n", trim($html));
|
66
|
+
if (isset($options['xhtml'])) {
|
67
|
+
$this->_isXhtml = (bool)$options['xhtml'];
|
68
|
+
}
|
69
|
+
if (isset($options['cssMinifier'])) {
|
70
|
+
$this->_cssMinifier = $options['cssMinifier'];
|
71
|
+
}
|
72
|
+
if (isset($options['jsMinifier'])) {
|
73
|
+
$this->_jsMinifier = $options['jsMinifier'];
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Minify the markeup given in the constructor
|
80
|
+
*
|
81
|
+
* @return string
|
82
|
+
*/
|
83
|
+
public function process()
|
84
|
+
{
|
85
|
+
if ($this->_isXhtml === null) {
|
86
|
+
$this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
|
87
|
+
}
|
88
|
+
|
89
|
+
$this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
|
90
|
+
$this->_placeholders = array();
|
91
|
+
|
92
|
+
// replace SCRIPTs (and minify) with placeholders
|
93
|
+
$this->_html = preg_replace_callback(
|
94
|
+
'/(\\s*)(<script\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/i'
|
95
|
+
,array($this, '_removeScriptCB')
|
96
|
+
,$this->_html);
|
97
|
+
|
98
|
+
// replace STYLEs (and minify) with placeholders
|
99
|
+
$this->_html = preg_replace_callback(
|
100
|
+
'/\\s*(<style\\b[^>]*?>)([\\s\\S]*?)<\\/style>\\s*/i'
|
101
|
+
,array($this, '_removeStyleCB')
|
102
|
+
,$this->_html);
|
103
|
+
|
104
|
+
// remove HTML comments (not containing IE conditional comments).
|
105
|
+
$this->_html = preg_replace_callback(
|
106
|
+
'/<!--([\\s\\S]*?)-->/'
|
107
|
+
,array($this, '_commentCB')
|
108
|
+
,$this->_html);
|
109
|
+
|
110
|
+
// replace PREs with placeholders
|
111
|
+
$this->_html = preg_replace_callback('/\\s*(<pre\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i'
|
112
|
+
,array($this, '_removePreCB')
|
113
|
+
,$this->_html);
|
114
|
+
|
115
|
+
// replace TEXTAREAs with placeholders
|
116
|
+
$this->_html = preg_replace_callback(
|
117
|
+
'/\\s*(<textarea\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i'
|
118
|
+
,array($this, '_removeTextareaCB')
|
119
|
+
,$this->_html);
|
120
|
+
|
121
|
+
// trim each line.
|
122
|
+
// @todo take into account attribute values that span multiple lines.
|
123
|
+
$this->_html = preg_replace('/^\\s+|\\s+$/m', '', $this->_html);
|
124
|
+
|
125
|
+
// remove ws around block/undisplayed elements
|
126
|
+
$this->_html = preg_replace('/\\s+(<\\/?(?:area|base(?:font)?|blockquote|body'
|
127
|
+
.'|caption|center|cite|col(?:group)?|dd|dir|div|dl|dt|fieldset|form'
|
128
|
+
.'|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta'
|
129
|
+
.'|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h||r|foot|itle)'
|
130
|
+
.'|ul)\\b[^>]*>)/i', '$1', $this->_html);
|
131
|
+
|
132
|
+
// remove ws outside of all elements
|
133
|
+
$this->_html = preg_replace_callback(
|
134
|
+
'/>([^<]+)</'
|
135
|
+
,array($this, '_outsideTagCB')
|
136
|
+
,$this->_html);
|
137
|
+
|
138
|
+
// use newlines before 1st attribute in open tags (to limit line lengths)
|
139
|
+
$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html);
|
140
|
+
|
141
|
+
// fill placeholders
|
142
|
+
$this->_html = str_replace(
|
143
|
+
array_keys($this->_placeholders)
|
144
|
+
,array_values($this->_placeholders)
|
145
|
+
,$this->_html
|
146
|
+
);
|
147
|
+
return $this->_html;
|
148
|
+
}
|
149
|
+
|
150
|
+
protected function _commentCB($m)
|
151
|
+
{
|
152
|
+
return (0 === strpos($m[1], '[') || false !== strpos($m[1], '<!['))
|
153
|
+
? $m[0]
|
154
|
+
: '';
|
155
|
+
}
|
156
|
+
|
157
|
+
protected function _reservePlace($content)
|
158
|
+
{
|
159
|
+
$placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%';
|
160
|
+
$this->_placeholders[$placeholder] = $content;
|
161
|
+
return $placeholder;
|
162
|
+
}
|
163
|
+
|
164
|
+
protected $_isXhtml = null;
|
165
|
+
protected $_replacementHash = null;
|
166
|
+
protected $_placeholders = array();
|
167
|
+
protected $_cssMinifier = null;
|
168
|
+
protected $_jsMinifier = null;
|
169
|
+
|
170
|
+
protected function _outsideTagCB($m)
|
171
|
+
{
|
172
|
+
return '>' . preg_replace('/^\\s+|\\s+$/', ' ', $m[1]) . '<';
|
173
|
+
}
|
174
|
+
|
175
|
+
protected function _removePreCB($m)
|
176
|
+
{
|
177
|
+
return $this->_reservePlace($m[1]);
|
178
|
+
}
|
179
|
+
|
180
|
+
protected function _removeTextareaCB($m)
|
181
|
+
{
|
182
|
+
return $this->_reservePlace($m[1]);
|
183
|
+
}
|
184
|
+
|
185
|
+
protected function _removeStyleCB($m)
|
186
|
+
{
|
187
|
+
$openStyle = $m[1];
|
188
|
+
$css = $m[2];
|
189
|
+
// remove HTML comments
|
190
|
+
$css = preg_replace('/(?:^\\s*<!--|-->\\s*$)/', '', $css);
|
191
|
+
|
192
|
+
// remove CDATA section markers
|
193
|
+
$css = $this->_removeCdata($css);
|
194
|
+
|
195
|
+
// minify
|
196
|
+
$minifier = $this->_cssMinifier
|
197
|
+
? $this->_cssMinifier
|
198
|
+
: 'trim';
|
199
|
+
$css = call_user_func($minifier, $css);
|
200
|
+
|
201
|
+
return $this->_reservePlace($this->_needsCdata($css)
|
202
|
+
? "{$openStyle}/*<![CDATA[*/{$css}/*]]>*/</style>"
|
203
|
+
: "{$openStyle}{$css}</style>"
|
204
|
+
);
|
205
|
+
}
|
206
|
+
|
207
|
+
protected function _removeScriptCB($m)
|
208
|
+
{
|
209
|
+
$openScript = $m[2];
|
210
|
+
$js = $m[3];
|
211
|
+
|
212
|
+
// whitespace surrounding? preserve at least one space
|
213
|
+
$ws1 = ($m[1] === '') ? '' : ' ';
|
214
|
+
$ws2 = ($m[4] === '') ? '' : ' ';
|
215
|
+
|
216
|
+
// remove HTML comments (and ending "//" if present)
|
217
|
+
$js = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $js);
|
218
|
+
|
219
|
+
// remove CDATA section markers
|
220
|
+
$js = $this->_removeCdata($js);
|
221
|
+
|
222
|
+
// minify
|
223
|
+
$minifier = $this->_jsMinifier
|
224
|
+
? $this->_jsMinifier
|
225
|
+
: 'trim';
|
226
|
+
$js = call_user_func($minifier, $js);
|
227
|
+
|
228
|
+
return $this->_reservePlace($this->_needsCdata($js)
|
229
|
+
? "{$ws1}{$openScript}/*<![CDATA[*/{$js}/*]]>*/</script>{$ws2}"
|
230
|
+
: "{$ws1}{$openScript}{$js}</script>{$ws2}"
|
231
|
+
);
|
232
|
+
}
|
233
|
+
|
234
|
+
protected function _removeCdata($str)
|
235
|
+
{
|
236
|
+
return (false !== strpos($str, '<![CDATA['))
|
237
|
+
? str_replace(array('<![CDATA[', ']]>'), '', $str)
|
238
|
+
: $str;
|
239
|
+
}
|
240
|
+
|
241
|
+
protected function _needsCdata($str)
|
242
|
+
{
|
243
|
+
return ($this->_isXhtml && preg_match('/(?:[<&]|\\-\\-|\\]\\]>)/', $str));
|
244
|
+
}
|
245
|
+
}
|