mirror of
https://github.com/mrclay/minify.git
synced 2025-08-12 17:14:24 +02:00
minifyTextarea.php : set charset, + HTML rendering option
Fixed source array casting in controllers Files, Groups, MinApp Changed default from "UTF-8" to "utf-8"
This commit is contained in:
@@ -105,7 +105,7 @@ class Minify {
|
||||
* 'encodeLevel' : level of encoding compression (0 to 9, default 9)
|
||||
*
|
||||
* 'contentTypeCharset' : appended to the Content-Type header sent. Set to a falsey
|
||||
* value to remove. (default 'UTF-8')
|
||||
* value to remove. (default 'utf-8')
|
||||
*
|
||||
* 'maxAge' : set this to the number of seconds the client should use its cache
|
||||
* before revalidating with the server. This sets Cache-Control: max-age and the
|
||||
|
@@ -45,7 +45,7 @@ abstract class Minify_Controller_Base {
|
||||
,'encodeMethod' => null // determine later
|
||||
,'encodeLevel' => 9
|
||||
,'minifierOptions' => array() // no minifier options
|
||||
,'contentTypeCharset' => 'UTF-8'
|
||||
,'contentTypeCharset' => 'utf-8'
|
||||
,'maxAge' => 1800 // 30 minutes
|
||||
,'rewriteCssUris' => true
|
||||
,'bubbleCssImports' => false
|
||||
|
@@ -40,7 +40,14 @@ class Minify_Controller_Files extends Minify_Controller_Base {
|
||||
*/
|
||||
public function setupSources($options) {
|
||||
// strip controller options
|
||||
$files = (array)$options['files'];
|
||||
|
||||
$files = $options['files'];
|
||||
// if $files is a single object, casting will break it
|
||||
if (is_object($files)) {
|
||||
$files = array($files);
|
||||
} elseif (! is_array($files)) {
|
||||
$files = (array)$files;
|
||||
}
|
||||
unset($options['files']);
|
||||
|
||||
$sources = array();
|
||||
|
@@ -59,7 +59,15 @@ class Minify_Controller_Groups extends Minify_Controller_Base {
|
||||
return $options;
|
||||
}
|
||||
$sources = array();
|
||||
foreach ((array)$groups[$pi] as $file) {
|
||||
|
||||
$files = $groups[$pi];
|
||||
// if $files is a single object, casting will break it
|
||||
if (is_object($files)) {
|
||||
$files = array($files);
|
||||
} elseif (! is_array($files)) {
|
||||
$files = (array)$files;
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
if ($file instanceof Minify_Source) {
|
||||
$sources[] = $file;
|
||||
continue;
|
||||
|
@@ -40,7 +40,15 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
|
||||
$this->log("A group configuration for \"{$_GET['g']}\" was not set");
|
||||
return $options;
|
||||
}
|
||||
foreach ((array)$cOptions['groups'][$_GET['g']] as $file) {
|
||||
|
||||
$files = $cOptions['groups'][$_GET['g']];
|
||||
// if $files is a single object, casting will break it
|
||||
if (is_object($files)) {
|
||||
$files = array($files);
|
||||
} elseif (! is_array($files)) {
|
||||
$files = (array)$files;
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
if ($file instanceof Minify_Source) {
|
||||
$sources[] = $file;
|
||||
continue;
|
||||
|
@@ -59,9 +59,6 @@ class Minify_Controller_Page extends Minify_Controller_Base {
|
||||
}
|
||||
$this->sources[] = new Minify_Source($sourceSpec);
|
||||
|
||||
// may not be needed
|
||||
//$options['minifier'] = array('Minify_HTML', 'minify');
|
||||
|
||||
$options['contentType'] = Minify::TYPE_HTML;
|
||||
return $options;
|
||||
}
|
||||
|
@@ -1,17 +1,52 @@
|
||||
<?php
|
||||
|
||||
$classes = array('Minify_HTML', 'Minify_CSS', 'JSMin', 'JSMinPlus');
|
||||
header('Content-Type: text/html;charset=UTF-8');
|
||||
function getPost($key) {
|
||||
return get_magic_quotes_gpc()
|
||||
? stripslashes($_POST[$key])
|
||||
: $_POST[$key];
|
||||
}
|
||||
|
||||
if (isset($_POST['textIn']) && in_array($_POST['method'], $classes)) {
|
||||
if (isset($_POST['textIn'])) {
|
||||
require '../config.php';
|
||||
$textIn = str_replace("\r\n", "\n", getPost('textIn'));
|
||||
}
|
||||
|
||||
if (isset($_POST['method']) && $_POST['method'] === 'Minify and serve') {
|
||||
require 'Minify.php';
|
||||
|
||||
$textIn = get_magic_quotes_gpc()
|
||||
? stripslashes($_POST['textIn'])
|
||||
: $_POST['textIn'];
|
||||
|
||||
$textIn = str_replace("\r\n", "\n", $textIn);
|
||||
$base = trim(getPost('base'));
|
||||
if ($base) {
|
||||
$textIn = preg_replace(
|
||||
'@(<head\\b[^>]*>)@i'
|
||||
,'$1<base href="' . htmlentities($base) . '" />'
|
||||
,$textIn
|
||||
);
|
||||
}
|
||||
|
||||
$sourceSpec['content'] = $textIn;
|
||||
$sourceSpec['id'] = 'foo';
|
||||
if (isset($_POST['minJs'])) {
|
||||
$sourceSpec['minifyOptions']['jsMinifier'] = array('JSMin', 'minify');
|
||||
require 'JSMin.php';
|
||||
}
|
||||
if (isset($_POST['minCss'])) {
|
||||
$sourceSpec['minifyOptions']['cssMinifier'] = array('Minify_CSS', 'minify');
|
||||
require 'Minify/CSS.php';
|
||||
}
|
||||
$source = new Minify_Source($sourceSpec);
|
||||
require_once 'Minify/Logger.php';
|
||||
require_once 'FirePHP.php';
|
||||
Minify_Logger::setLogger(FirePHP::getInstance(true));
|
||||
Minify::serve('Files', array(
|
||||
'files' => $source
|
||||
,'contentType' => Minify::TYPE_HTML
|
||||
));
|
||||
exit();
|
||||
}
|
||||
|
||||
$classes = array('Minify_HTML', 'Minify_CSS', 'JSMin', 'JSMinPlus');
|
||||
|
||||
if (isset($_POST['method']) && in_array($_POST['method'], $classes)) {
|
||||
// easier to just require them all
|
||||
require 'Minify/HTML.php';
|
||||
require 'Minify/CSS.php';
|
||||
@@ -31,6 +66,10 @@ if (isset($_POST['textIn']) && in_array($_POST['method'], $classes)) {
|
||||
$inOutBytes[1] = strlen($textOut);
|
||||
}
|
||||
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
?>
|
||||
<!DOCTYPE html><head><title>minifyTextarea</title></head>
|
||||
<?php
|
||||
if (isset($inOutBytes)) {
|
||||
echo "
|
||||
<table>
|
||||
@@ -39,17 +78,21 @@ if (isset($inOutBytes)) {
|
||||
</table>
|
||||
";
|
||||
}
|
||||
|
||||
?>
|
||||
<form action="" method="post">
|
||||
<p><label>Content<br /><textarea name="textIn" cols="80" rows="35" style="width:99%"><?php
|
||||
<form action="?2" method="post">
|
||||
<p><label>Content<br><textarea name="textIn" cols="80" rows="35" style="width:99%"><?php
|
||||
if (isset($textOut)) {
|
||||
echo htmlspecialchars($textOut);
|
||||
}
|
||||
?></textarea></label></p>
|
||||
<p>Minify with:
|
||||
<?php foreach ($classes as $minClass): ?>
|
||||
<input type="submit" name="method" value="<?php echo $minClass; ?>" />
|
||||
<input type="submit" name="method" value="<?php echo $minClass; ?>">
|
||||
<?php endForEach; ?>
|
||||
</p>
|
||||
<p>...or <input type="submit" name="method" value="Minify and serve"> this HTML to the browser. Also minify:
|
||||
<label>CSS <input type="checkbox" name="minCss" checked></label> :
|
||||
<label>JS <input type="checkbox" name="minJs" checked></label>.
|
||||
<label>Insert BASE element w/ href: <input type="text" name="base" size="20"></label>
|
||||
</p>
|
||||
</form>
|
||||
|
@@ -72,7 +72,7 @@ function test_Minify()
|
||||
'ETag' => "\"pub{$lastModified}\"",
|
||||
'Cache-Control' => 'max-age=86400, public, must-revalidate',
|
||||
'Content-Length' => strlen($content),
|
||||
'Content-Type' => 'application/x-javascript; charset=UTF-8',
|
||||
'Content-Type' => 'application/x-javascript; charset=utf-8',
|
||||
)
|
||||
);
|
||||
$output = Minify::serve('Files', array(
|
||||
@@ -170,7 +170,7 @@ function test_Minify()
|
||||
|
||||
// Test minifying CSS and responding with Etag/Last-Modified
|
||||
|
||||
Minify::setCache();
|
||||
Minify::setCache(null);
|
||||
|
||||
// don't allow conditional headers
|
||||
unset($_SERVER['HTTP_IF_NONE_MATCH'], $_SERVER['HTTP_IF_MODIFIED_SINCE']);
|
||||
@@ -187,7 +187,7 @@ function test_Minify()
|
||||
'ETag' => "\"pub{$lastModified}\"",
|
||||
'Cache-Control' => 'max-age=0, public, must-revalidate',
|
||||
'Content-Length' => strlen($expectedContent),
|
||||
'Content-Type' => 'text/css; charset=UTF-8',
|
||||
'Content-Type' => 'text/css; charset=utf-8',
|
||||
)
|
||||
);
|
||||
$output = Minify::serve('Files', array(
|
||||
|
Reference in New Issue
Block a user