Plugins para comprimir js/css/html
git-svn-id: https://192.168.0.254/svn/Proyectos.ASong2U_Web/trunk@68 cd1a4ea2-8c7f-e448-aada-19d1fee9e1d6
This commit is contained in:
parent
c5640e56a8
commit
9318212000
40
wp-content/plugins/html-compress/html-compress.php
Normal file
40
wp-content/plugins/html-compress/html-compress.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: html-compress
|
||||
Plugin URI: http://code.google.com/p/html-compress/
|
||||
Description: Reduce html, css and js size by removing unnecessary white space from an HTML document.
|
||||
Version: 0.0
|
||||
Author: karrikas
|
||||
Author URI: http://karrikas.com/
|
||||
Author Email: karrikas@karrikas.com
|
||||
License: GPL3
|
||||
*/
|
||||
|
||||
/*
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
include_once 'lib/html-compress/Compress.class.php';
|
||||
|
||||
function wp_finish($html)
|
||||
{
|
||||
return Compress::Compress($html);
|
||||
}
|
||||
|
||||
|
||||
function wp_start()
|
||||
{
|
||||
ob_start('wp_finish');
|
||||
}
|
||||
|
||||
add_action('get_header', 'wp_start');
|
||||
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
include_once 'htmlCompress.class.php';
|
||||
include_once 'jsCompress.class.php';
|
||||
include_once 'cssCompress.class.php';
|
||||
/**
|
||||
* Web orri bat ahalik eta gehien murrizten du
|
||||
* funtzionamendua mantenduz.
|
||||
*
|
||||
* @author karrikas
|
||||
*/
|
||||
class compress
|
||||
{
|
||||
/**
|
||||
* JS kodeak gordetzeko array statikoa.
|
||||
* @var array
|
||||
*/
|
||||
static $jsCodes = array();
|
||||
|
||||
/**
|
||||
* Css kodeak gordetzeko arrya.
|
||||
* @var array (html: html code, js: js code, css: css code)
|
||||
*/
|
||||
static $cssCodes = array();
|
||||
|
||||
/**
|
||||
* Honek Compress metodoa konstrukturea izatea ekiditen du.
|
||||
*/
|
||||
public function __construct(){}
|
||||
|
||||
|
||||
static public function Compress( $html )
|
||||
{
|
||||
self::emptyVars();
|
||||
|
||||
// html zatitu
|
||||
$html = self::splitCode( $html );
|
||||
|
||||
// html txikitu
|
||||
$html = htmlCompress::Compress($html);
|
||||
|
||||
// js txikitu
|
||||
foreach(self::$jsCodes as $key => $jsCode)
|
||||
{
|
||||
self::$jsCodes[$key] = jsCompress::Compress( $jsCode );
|
||||
}
|
||||
|
||||
// css txikitu
|
||||
foreach(self::$cssCodes as $key => $cssCode)
|
||||
{
|
||||
self::$cssCodes[$key] = cssCompress::Compress( $cssCode );
|
||||
}
|
||||
|
||||
// kodea batu
|
||||
$html = self::mergeCode( $html );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Batu js eta css guztiak htmlarekin.
|
||||
* @param string $html
|
||||
* @return string $html
|
||||
*/
|
||||
static public function mergeCode( $html )
|
||||
{
|
||||
// merge js
|
||||
foreach(self::$jsCodes as $key => $jsCode)
|
||||
{
|
||||
$html = str_replace("__JAVASCRIPTCOMPRESS[$key]__", $jsCode, $html);
|
||||
}
|
||||
|
||||
// merge js
|
||||
foreach(self::$cssCodes as $key => $cssCode)
|
||||
{
|
||||
$html = str_replace("__CSSCOMPRESS[$key]__", $cssCode, $html);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* html, css, js banatzen ditu gero procesatzeko.
|
||||
*
|
||||
* @param string $html
|
||||
* @return array
|
||||
*/
|
||||
static public function splitCode( $html )
|
||||
{
|
||||
// aurrekoak ustu
|
||||
self::emptyVars();
|
||||
|
||||
// javascript kodeak atera.
|
||||
$html = preg_replace_callback('/(<script[^>]*>)(.*?)(\<\/script>)/si','self::addJsCode', $html);
|
||||
|
||||
// Css kodeak atera.
|
||||
$html = preg_replace_callback('/(<style[^>]*>)(.*?)(<\/style>)/si','self::addCssCode', $html);
|
||||
|
||||
// return split result
|
||||
return $html;
|
||||
}
|
||||
|
||||
static private function addJsCode( $js )
|
||||
{
|
||||
$count = count(self::$jsCodes);
|
||||
self::$jsCodes[] = $js[2];
|
||||
|
||||
return "{$js[1]}__JAVASCRIPTCOMPRESS[$count]__{$js[3]}";
|
||||
}
|
||||
|
||||
static private function addCssCode( $css )
|
||||
{
|
||||
$count = count(self::$cssCodes);
|
||||
self::$cssCodes[] = $css[2];
|
||||
|
||||
return "{$css[1]}__CSSCOMPRESS[$count]__{$css[3]}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Hasierako bariableak ustu.
|
||||
*/
|
||||
static private function emptyVars()
|
||||
{
|
||||
self::$cssCodes = array();
|
||||
self::$jsCodes = array();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @Pacage karrikaslib
|
||||
* @Subpacage compress
|
||||
*/
|
||||
class baseCompress
|
||||
{
|
||||
static public function delSpace( $html )
|
||||
{
|
||||
// hasiera eta amaiera garbitu.
|
||||
$html = trim($html);
|
||||
// utsune bikoitzak kendu.
|
||||
$html = preg_replace('/[ ]+/', ' ', $html);
|
||||
// Etiketen aurreko eta ondorengo utsuneak kendu.
|
||||
$html = preg_replace('/>[ ]+/', '> ', $html);
|
||||
$html = preg_replace('/[ ]+</', ' <', $html);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
static public function delTab( $html )
|
||||
{
|
||||
// tabulazioak kendu.
|
||||
$html = preg_replace('/[\t]+/', ' ', $html);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
static public function delNL( $html )
|
||||
{
|
||||
// saltoak kendu.
|
||||
$html = preg_replace('/[\n\r]+/', ' ', $html);
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
include_once 'baseCompress.class.php';
|
||||
/**
|
||||
* @Pacage karrikaslib
|
||||
* @Subpacage compress
|
||||
*/
|
||||
/**
|
||||
* Htmlan ahal den modu guztietan murriztu zentzua galdu gabe.
|
||||
*/
|
||||
class cssCompress extends baseCompress
|
||||
{
|
||||
static public function compress( $css )
|
||||
{
|
||||
$css = self::delComments( $css );
|
||||
$css = parent::delTab( $css );
|
||||
$css = parent::delNL( $css );
|
||||
$css = self::delSpace( $css );
|
||||
|
||||
return $css;
|
||||
}
|
||||
|
||||
static public function delSpace( $css )
|
||||
{
|
||||
$css = parent::delSpace( $css );
|
||||
|
||||
// ;
|
||||
$css = preg_replace('/[ \t\n\r]*;[ \t\n\r]*/',';',$css);
|
||||
|
||||
// :
|
||||
$css = preg_replace('/[ \t\n\r]*:[ \t\n\r]*/',':',$css);
|
||||
|
||||
// ,
|
||||
$css = preg_replace('/[ \t\n\r]*,[ \t\n\r]*/',',',$css);
|
||||
|
||||
// (
|
||||
$css = preg_replace('/[ \t\n\r]*\([ \t\n\r]*/','(',$css);
|
||||
|
||||
// )
|
||||
$css = preg_replace('/[ \t\n\r]*\)[ \t\n\r]*/',')',$css);
|
||||
|
||||
// {
|
||||
$css = preg_replace('/[ \t\n\r]*\{[ \t\n\r]*/','{',$css);
|
||||
|
||||
// }
|
||||
$css = preg_replace('/[ \t\n\r]*\}[ \t\n\r]*/','}',$css);
|
||||
|
||||
return $css;
|
||||
}
|
||||
|
||||
static public function delComments( $css )
|
||||
{
|
||||
// /* */
|
||||
$css = preg_replace('/\/\*.*\*\//ms','',$css);
|
||||
|
||||
return $css;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
include_once 'baseCompress.class.php';
|
||||
/**
|
||||
* @Pacage karrikaslib
|
||||
* @Subpacage compress
|
||||
*/
|
||||
/**
|
||||
* Htmlan ahal den modu guztietan murriztu zentzua galdu gabe.
|
||||
*/
|
||||
class htmlCompress extends baseCompress
|
||||
{
|
||||
static public function compress( $html )
|
||||
{
|
||||
$html = self::delComment( $html );
|
||||
$html = self::delTab( $html );
|
||||
$html = self::delNL( $html );
|
||||
$html = self::delSpace( $html );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
static public function delComment( $html )
|
||||
{
|
||||
// iruzkinak kendu.
|
||||
$html = preg_replace('/<!(?<comment>--).*?-->/si', '', $html);
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
include_once 'baseCompress.class.php';
|
||||
/**
|
||||
* Javascript codea ahalik eta murriztuen egitea funtzionatzeari utzi gabe.
|
||||
*
|
||||
* @Pacage html-compress
|
||||
* @author karrikas
|
||||
*/
|
||||
class jsCompress extends baseCompress
|
||||
{
|
||||
static $jsStrings = array();
|
||||
|
||||
static public function compress( $js )
|
||||
{
|
||||
$js = self::outStrings($js);
|
||||
$js = self::delComments($js);
|
||||
$js = self::delSpace($js);
|
||||
$js = parent::delTab( $js );
|
||||
$js = parent::delNL( $js );
|
||||
$js = self::inStrings($js);
|
||||
|
||||
return $js;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kateak array batean gorde.
|
||||
*/
|
||||
static public function outStrings( $js )
|
||||
{
|
||||
// ustu aurreko baloreak
|
||||
self::$jsStrings = array();
|
||||
|
||||
// kateak gorde
|
||||
$js = preg_replace_callback('/"[^"]*"|\'[^\']*\'/','self::addString', $js);
|
||||
|
||||
return $js;
|
||||
}
|
||||
|
||||
static private function addString( $string )
|
||||
{
|
||||
$count = count(self::$jsStrings);
|
||||
self::$jsStrings[] = $string[0];
|
||||
|
||||
return "__STRINGCOMPRESS[$count]__";
|
||||
}
|
||||
|
||||
/**
|
||||
* Lehenago kendutako kateak berrezari
|
||||
*/
|
||||
static public function inStrings( $js )
|
||||
{
|
||||
foreach(self::$jsStrings as $key => $string)
|
||||
{
|
||||
$js = str_replace("__STRINGCOMPRESS[$key]__", $string, $js);
|
||||
}
|
||||
|
||||
return $js;
|
||||
}
|
||||
|
||||
static public function delSpace( $js )
|
||||
{
|
||||
// oinarria aprobetsatu
|
||||
$js = parent::delSpace( $js );
|
||||
|
||||
// spaces on = ; : , ( ) { } +
|
||||
$js = preg_replace('/[ \t\n\r]*(=|;|:|,|\(|\)|\{|\}|\+)[ \t\n\r]*/',"$1",$js);
|
||||
|
||||
return $js;
|
||||
}
|
||||
|
||||
static public function delComments( $js )
|
||||
{
|
||||
// /* */
|
||||
$js = preg_replace('/\/\*.*?\*\//ms','',$js);
|
||||
|
||||
// //
|
||||
$js = preg_replace('/\/\/.*/','',$js);
|
||||
|
||||
return $js;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
include dirname(__FILE__) . '/../../html-compress/Compress.class.php';
|
||||
|
||||
class CompressTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
function testSplitCode()
|
||||
{
|
||||
// js bat
|
||||
$html = '<html><script>javascript</script>html</html>';
|
||||
$result = Compress::splitCode($html);
|
||||
$this->assertEquals($result,'<html><script>__JAVASCRIPTCOMPRESS[0]__</script>html</html>');
|
||||
$this->assertEquals(Compress::$jsCodes[0],'javascript');
|
||||
|
||||
// css bat
|
||||
$html = '<html><style>css</style>html</html>';
|
||||
$result = Compress::splitCode($html);
|
||||
$this->assertEquals($result,'<html><style>__CSSCOMPRESS[0]__</style>html</html>');
|
||||
$this->assertEquals(Compress::$cssCodes[0],'css');
|
||||
|
||||
// js eta css bat
|
||||
$html = '<html><script>javascript</script><style>css</style>html</html>';
|
||||
$result = Compress::splitCode($html);
|
||||
$this->assertEquals($result,'<html><script>__JAVASCRIPTCOMPRESS[0]__</script><style>__CSSCOMPRESS[0]__</style>html</html>');
|
||||
$this->assertEquals(Compress::$cssCodes[0],'css');
|
||||
$this->assertEquals(Compress::$jsCodes[0],'javascript');
|
||||
|
||||
// 2 js
|
||||
$html = '<html><script>javascript</script><script>javascript_2</script>html</html>';
|
||||
$result = Compress::splitCode($html);
|
||||
$this->assertEquals($result,'<html><script>__JAVASCRIPTCOMPRESS[0]__</script><script>__JAVASCRIPTCOMPRESS[1]__</script>html</html>');
|
||||
$this->assertEquals(Compress::$jsCodes[0],'javascript');
|
||||
$this->assertEquals(Compress::$jsCodes[1],'javascript_2');
|
||||
|
||||
// 2 css
|
||||
$html = '<html><style>css</style><style>css_2</style>html</html>';
|
||||
$result = Compress::splitCode($html);
|
||||
$this->assertEquals($result,'<html><style>__CSSCOMPRESS[0]__</style><style>__CSSCOMPRESS[1]__</style>html</html>');
|
||||
$this->assertEquals(Compress::$cssCodes[0],'css');
|
||||
$this->assertEquals(Compress::$cssCodes[1],'css_2');
|
||||
|
||||
// js aukerekin
|
||||
$html = '<html><script type="text/javascript">javascript</script>html</html>';
|
||||
$result = Compress::splitCode($html);
|
||||
$this->assertEquals($result,'<html><script type="text/javascript">__JAVASCRIPTCOMPRESS[0]__</script>html</html>');
|
||||
$this->assertEquals(Compress::$jsCodes[0],'javascript');
|
||||
|
||||
// css aukerekin
|
||||
$html = '<html><style type="text/css">css</style>html</html>';
|
||||
$result = Compress::splitCode($html);
|
||||
$this->assertEquals($result,'<html><style type="text/css">__CSSCOMPRESS[0]__</style>html</html>');
|
||||
$this->assertEquals(Compress::$cssCodes[0],'css');
|
||||
}
|
||||
|
||||
function testMergeCode()
|
||||
{
|
||||
// batu js bat
|
||||
compress::$jsCodes = array();
|
||||
compress::$jsCodes[] = 'Code A';
|
||||
$html_sta = '<html><script>__JAVASCRIPTCOMPRESS[0]__</script>html</html>';
|
||||
$html_end = '<html><script>Code A</script>html</html>';
|
||||
$result = Compress::mergeCode($html_sta);
|
||||
$this->assertEquals($result,$html_end);
|
||||
|
||||
// batu 2 js bat
|
||||
compress::$jsCodes = array();
|
||||
compress::$jsCodes[] = 'Code A';
|
||||
compress::$jsCodes[] = 'Code B';
|
||||
$html_sta = '<html><script>__JAVASCRIPTCOMPRESS[0]__</script><script>__JAVASCRIPTCOMPRESS[1]__</script>html</html>';
|
||||
$html_end = '<html><script>Code A</script><script>Code B</script>html</html>';
|
||||
$result = Compress::mergeCode($html_sta);
|
||||
$this->assertEquals($result,$html_end);
|
||||
|
||||
// batu css bat
|
||||
compress::$cssCodes = array();
|
||||
compress::$cssCodes[] = 'Code A';
|
||||
$html_sta = '<html><style>__CSSCOMPRESS[0]__</style>html</html>';
|
||||
$html_end = '<html><style>Code A</style>html</html>';
|
||||
$result = Compress::mergeCode($html_sta);
|
||||
$this->assertEquals($result,$html_end);
|
||||
|
||||
// batu 2 css bat
|
||||
compress::$cssCodes = array();
|
||||
compress::$cssCodes[] = 'Code A';
|
||||
compress::$cssCodes[] = 'Code B';
|
||||
$html_sta = '<html><style>__CSSCOMPRESS[0]__</style><style>__CSSCOMPRESS[1]__</style>html</html>';
|
||||
$html_end = '<html><style>Code A</style><style>Code B</style>html</html>';
|
||||
$result = Compress::mergeCode($html_sta);
|
||||
$this->assertEquals($result,$html_end);
|
||||
}
|
||||
|
||||
function testCompress()
|
||||
{
|
||||
$html_sta = ' <html><script> a = 2 ; b = 3; c = a + b ; </script></html> ';
|
||||
$html_end = '<html><script>a=2;b=3;c=a+b;</script></html>';
|
||||
$result = compress::Compress($html_sta);
|
||||
$this->assertEquals($result,$html_end);
|
||||
|
||||
$html_sta = ' <html><style> body { border: 1px solid red; float: left } </style></html> ';
|
||||
$html_end = '<html><style>body{border:1px solid red;float:left}</style></html>';
|
||||
$result = compress::Compress($html_sta);
|
||||
$this->assertEquals($result,$html_end);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
include dirname(__FILE__) . '/../../html-compress/baseCompress.class.php';
|
||||
|
||||
class baseCompressTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Utsuneak ezabatu.
|
||||
*/
|
||||
public function testDelSpace()
|
||||
{
|
||||
$html = ' ';
|
||||
$esperotakoa = '';
|
||||
$emaitza = baseCompress::delSpace($html);
|
||||
$this->assertEquals($emaitza,$esperotakoa);
|
||||
|
||||
$html = ' a b c d e ';
|
||||
$esperotakoa = 'a b c d e';
|
||||
$emaitza = baseCompress::delSpace($html);
|
||||
$this->assertEquals($emaitza,$esperotakoa);
|
||||
|
||||
$html = ' a b c d e ';
|
||||
$esperotakoa = 'a b c d e';
|
||||
$emaitza = baseCompress::delSpace($html);
|
||||
$this->assertEquals($emaitza,$esperotakoa);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tabulazioak ezabatu.
|
||||
*/
|
||||
public function testDelTab()
|
||||
{
|
||||
$html = ' ';
|
||||
$esperotakoa = ' ';
|
||||
$emaitza = baseCompress::delTab($html);
|
||||
$this->assertEquals($emaitza,$esperotakoa);
|
||||
|
||||
$html = ' <div> testu bat </div> ';
|
||||
$esperotakoa = ' <div> testu bat </div> ';
|
||||
$emaitza = baseCompress::delTab($html);
|
||||
$this->assertEquals($emaitza,$esperotakoa);
|
||||
|
||||
$html = ' <div> testu bat </div> ';
|
||||
$esperotakoa = ' <div> testu bat </div> ';
|
||||
$emaitza = baseCompress::delTab($html);
|
||||
$this->assertEquals($emaitza,$esperotakoa);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saltoak ezabatu.
|
||||
*/
|
||||
public function testDelNL()
|
||||
{
|
||||
$html = <<<HTML
|
||||
|
||||
|
||||
|
||||
HTML;
|
||||
$esperotakoa = ' ';
|
||||
$emaitza = baseCompress::delNL($html);
|
||||
$this->assertEquals($emaitza,$esperotakoa);
|
||||
|
||||
$html = <<<HTML
|
||||
a
|
||||
b
|
||||
c
|
||||
d
|
||||
e
|
||||
HTML;
|
||||
$esperotakoa = 'a b c d e';
|
||||
$emaitza = baseCompress::delNL($html);
|
||||
$this->assertEquals($emaitza,$esperotakoa);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
include dirname(__FILE__) . '/../../html-compress/cssCompress.class.php';
|
||||
|
||||
class cssCompressTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
|
||||
public function testDelComments()
|
||||
{
|
||||
$css_sta = '/* comment */';
|
||||
$css_end = '';
|
||||
$css_pro = cssCompress::delComments($css_sta);
|
||||
$this->assertEquals($css_pro,$css_end);
|
||||
}
|
||||
|
||||
public function testDelSpace()
|
||||
{
|
||||
$css_sta = ' ; ';
|
||||
$css_end = ';';
|
||||
$css_pro = cssCompress::delSpace($css_sta);
|
||||
$this->assertEquals($css_pro,$css_end);
|
||||
|
||||
$css_sta = ' ( ';
|
||||
$css_end = '(';
|
||||
$css_pro = cssCompress::delSpace($css_sta);
|
||||
$this->assertEquals($css_pro,$css_end);
|
||||
}
|
||||
|
||||
public function testCompress()
|
||||
{
|
||||
$css_sta = <<<CSS
|
||||
#eskuin .zabala { /* Erabili eskero #erdi ez erabili */
|
||||
width: 560px;
|
||||
background: red;
|
||||
}
|
||||
CSS;
|
||||
$css_end = '#eskuin .zabala{width:560px;background:red;}';
|
||||
$css_pro = cssCompress::Compress($css_sta);
|
||||
$this->assertEquals($css_pro,$css_end);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
include dirname(__FILE__) . '/../../html-compress/htmlCompress.class.php';
|
||||
|
||||
class htmlCompressTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Html iruzkinak ezabatu.
|
||||
*/
|
||||
public function testDelComment()
|
||||
{
|
||||
$html = '<!-- testu bat edo -->';
|
||||
$esperotakoa = '';
|
||||
$emaitza = htmlCompress::delComment($html);
|
||||
$this->assertEquals($emaitza,$esperotakoa);
|
||||
|
||||
$html = '<!-- a --> b <!-- c --> d <!-- e -->';
|
||||
$esperotakoa = ' b d ';
|
||||
$emaitza = htmlCompress::delComment($html);
|
||||
$this->assertEquals($emaitza,$esperotakoa);
|
||||
|
||||
$html = <<<HTML
|
||||
<!--
|
||||
a
|
||||
-->
|
||||
HTML;
|
||||
$esperotakoa = '';
|
||||
$emaitza = htmlCompress::delComment($html);
|
||||
$this->assertEquals($emaitza,$esperotakoa);
|
||||
}
|
||||
|
||||
/**
|
||||
* Html ahalik eta txikituen utzi.
|
||||
*/
|
||||
public function testCompress()
|
||||
{
|
||||
$html = '<html></html>';
|
||||
$emaitza = htmlCompress::compress($html);
|
||||
$this->assertEquals($emaitza,$html);
|
||||
|
||||
$html = <<<HTML
|
||||
<h1>This is a heading</h1>
|
||||
|
||||
<h2>This is a heading</h2>
|
||||
|
||||
<h3>This is a heading</h3>
|
||||
HTML;
|
||||
$esperotakoa = '<h1>This is a heading</h1> <h2>This is a heading</h2> <h3>This is a heading</h3>';
|
||||
$emaitza = htmlCompress::compress($html);
|
||||
$this->assertEquals($emaitza,$esperotakoa);
|
||||
|
||||
$html = '<span>|</span> <span><a href="#">text</a></span> <span>|</span>';
|
||||
$esperotakoa = '<span>|</span> <span><a href="#">text</a></span> <span>|</span>';
|
||||
$emaitza = htmlCompress::compress($html);
|
||||
$this->assertEquals($emaitza,$esperotakoa);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,246 @@
|
||||
<?php
|
||||
include dirname(__FILE__) . '/../../html-compress/jsCompress.class.php';
|
||||
|
||||
class jsCompressTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testOutStrings()
|
||||
{
|
||||
// ketak ez dira aldatu behar
|
||||
$js_sta = ' a = " string "';
|
||||
$js_end = ' a = __STRINGCOMPRESS[0]__';
|
||||
$js_pro = jsCompress::outStrings($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$arrExpected = array('" string "');
|
||||
$this->assertEquals(jsCompress::$jsStrings,$arrExpected);
|
||||
|
||||
$js_sta = ' a = " string " b = " string2 "';
|
||||
$js_end = ' a = __STRINGCOMPRESS[0]__ b = __STRINGCOMPRESS[1]__';
|
||||
$js_pro = jsCompress::outStrings($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$arrExpected = array('" string "','" string2 "');
|
||||
$this->assertEquals(jsCompress::$jsStrings,$arrExpected);
|
||||
|
||||
$js_sta = ' a = \' string \'';
|
||||
$js_end = ' a = __STRINGCOMPRESS[0]__';
|
||||
$js_pro = jsCompress::outStrings($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$arrExpected = array('\' string \'');
|
||||
$this->assertEquals(jsCompress::$jsStrings,$arrExpected);
|
||||
|
||||
$js_sta = ' a = \' string \' b = \' string2 \'';
|
||||
$js_end = ' a = __STRINGCOMPRESS[0]__ b = __STRINGCOMPRESS[1]__';
|
||||
$js_pro = jsCompress::outStrings($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$arrExpected = array('\' string \'','\' string2 \'');
|
||||
$this->assertEquals(jsCompress::$jsStrings,$arrExpected);
|
||||
|
||||
$js_sta = ' a = " string " b = \' string2 \'';
|
||||
$js_end = ' a = __STRINGCOMPRESS[0]__ b = __STRINGCOMPRESS[1]__';
|
||||
$js_pro = jsCompress::outStrings($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$arrExpected = array('" string "','\' string2 \'');
|
||||
$this->assertEquals(jsCompress::$jsStrings,$arrExpected);
|
||||
|
||||
# issue 1
|
||||
$js_sta = ' a = ""';
|
||||
$js_end = ' a = __STRINGCOMPRESS[0]__';
|
||||
$js_pro = jsCompress::outStrings($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
# issue 1
|
||||
$js_sta = ' a = \'\'';
|
||||
$js_end = ' a = __STRINGCOMPRESS[0]__';
|
||||
$js_pro = jsCompress::outStrings($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
}
|
||||
|
||||
public function testInStrings()
|
||||
{
|
||||
// testuak berrezarri
|
||||
$js_sta = ' a = " string " b = \' string2 \'';
|
||||
$js = jsCompress::outStrings($js_sta);
|
||||
$js_end = jsCompress::inStrings($js);
|
||||
$this->assertEquals($js_sta,$js_end);
|
||||
}
|
||||
|
||||
public function testDelSpace()
|
||||
{
|
||||
// utsune bat baino gehiago
|
||||
$js_sta = ' ';
|
||||
$js_end = '';
|
||||
$js_pro = jsCompress::delSpace($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
// = en atze eta aurrean ez da behar utsunerik
|
||||
$js_sta = 'a =b';
|
||||
$js_end = 'a=b';
|
||||
$js_pro = jsCompress::delSpace($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = 'a= b';
|
||||
$js_end = 'a=b';
|
||||
$js_pro = jsCompress::delSpace($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = 'a = b + c';
|
||||
$js_end = 'a=b+c';
|
||||
$js_pro = jsCompress::delSpace($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = 'a = b; c = d;';
|
||||
$js_end = 'a=b;c=d;';
|
||||
$js_pro = jsCompress::delSpace($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = 'a = b ;c = d;';
|
||||
$js_end = 'a=b;c=d;';
|
||||
$js_pro = jsCompress::delSpace($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = 'array( a, b, c, d);';
|
||||
$js_end = 'array(a,b,c,d);';
|
||||
$js_pro = jsCompress::delSpace($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = 'if (elem) { action }';
|
||||
$js_end = 'if(elem){action}';
|
||||
$js_pro = jsCompress::delSpace($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
}
|
||||
|
||||
public function testDelComments()
|
||||
{
|
||||
$js_sta = '/* comment */';
|
||||
$js_end = '';
|
||||
$js_pro = jsCompress::delComments($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = ' string /* comment */';
|
||||
$js_end = ' string ';
|
||||
$js_pro = jsCompress::delComments($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = '/* comment */ string ';
|
||||
$js_end = ' string ';
|
||||
$js_pro = jsCompress::delComments($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = <<<JS
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
JS;
|
||||
$js_end = <<<JS
|
||||
JS;
|
||||
$js_pro = jsCompress::delComments($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = '// comment';
|
||||
$js_end = '';
|
||||
$js_pro = jsCompress::delComments($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = ' string // comment';
|
||||
$js_end = ' string ';
|
||||
$js_pro = jsCompress::delComments($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = <<<JS
|
||||
string
|
||||
// comment
|
||||
JS;
|
||||
$js_end = <<<JS
|
||||
string
|
||||
|
||||
JS;
|
||||
$js_pro = jsCompress::delComments($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = <<<JS
|
||||
// comment
|
||||
string
|
||||
JS;
|
||||
$js_end = <<<JS
|
||||
|
||||
string
|
||||
JS;
|
||||
$js_pro = jsCompress::delComments($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = <<<JS
|
||||
// comment
|
||||
string
|
||||
// comment
|
||||
string
|
||||
// comment
|
||||
JS;
|
||||
$js_end = <<<JS
|
||||
|
||||
string
|
||||
|
||||
string
|
||||
|
||||
JS;
|
||||
$js_pro = jsCompress::delComments($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
$js_sta = <<<JS
|
||||
/* c1 */
|
||||
string
|
||||
/* c2 */
|
||||
string
|
||||
|
||||
JS;
|
||||
$js_end = <<<JS
|
||||
|
||||
string
|
||||
|
||||
string
|
||||
|
||||
JS;
|
||||
|
||||
$js_pro = jsCompress::delComments($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
}
|
||||
|
||||
public function testCompress()
|
||||
{
|
||||
$js_sta = <<<JS
|
||||
var a = " my firts string"
|
||||
var b = 'other string ';
|
||||
res = a + b
|
||||
JS;
|
||||
$js_end = 'var a=" my firts string" var b=\'other string \';res=a+b';
|
||||
$js_pro = jsCompress::compress($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
// Issue 1: https://code.google.com/p/html-compress/issues/detail?id=1
|
||||
$js_sta = <<<JS
|
||||
var analyticsFileTypes = [''];
|
||||
var analyticsEventTracking = 'enabled';
|
||||
JS;
|
||||
$js_end = 'var analyticsFileTypes=[\'\'];var analyticsEventTracking=\'enabled\';';
|
||||
$js_pro = jsCompress::compress($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
// Issue 2: https://code.google.com/p/html-compress/issues/detail?id=2
|
||||
$js_sta = <<<JS
|
||||
/* <![CDATA[ */
|
||||
var emailL10n = {
|
||||
ajax_url: "http://zuzeu/wp-content/plugins/wp-email/wp-email.php",
|
||||
max_allowed: "5"
|
||||
};
|
||||
/* ]]> */
|
||||
JS;
|
||||
$js_end = 'var emailL10n={ajax_url:"http://zuzeu/wp-content/plugins/wp-email/wp-email.php",max_allowed:"5"};';
|
||||
$js_pro = jsCompress::compress($js_sta);
|
||||
$this->assertEquals($js_pro,$js_end);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
Launch testSuite
|
||||
$ phpunit testSuite.class.php
|
||||
|
||||
Launch one test
|
||||
$ phpunit baseCompressTest.class.php
|
||||
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
include_once 'baseCompressTest.php';
|
||||
include_once 'htmlCompressTest.php';
|
||||
include_once 'cssCompressTest.php';
|
||||
include_once 'jsCompressTest.php';
|
||||
include_once 'CompressTest.php';
|
||||
|
||||
class testSuite
|
||||
{
|
||||
public static function suite()
|
||||
{
|
||||
$suite = new PHPUnit_Framework_TestSuite();
|
||||
|
||||
$suite->addTestSuite('baseCompressTest');
|
||||
$suite->addTestSuite('htmlCompressTest');
|
||||
$suite->addTestSuite('cssCompressTest');
|
||||
$suite->addTestSuite('jsCompressTest');
|
||||
$suite->addTestSuite('CompressTest');
|
||||
|
||||
return $suite;
|
||||
}
|
||||
}
|
||||
31
wp-content/plugins/html-compress/readme.txt
Normal file
31
wp-content/plugins/html-compress/readme.txt
Normal file
@ -0,0 +1,31 @@
|
||||
=== Plugin Name ===
|
||||
Contributors: kakrrikas
|
||||
Tags: html, compress, minify, css, javascript
|
||||
Requires at least: 3.0
|
||||
Tested up to: 3.0
|
||||
Stable tag: 0.1
|
||||
|
||||
Reduce html, css and javascript size on web pages processing the code.
|
||||
|
||||
== Description ==
|
||||
|
||||
Clear html of web page. Reduce space, tab,... on all source content, including in line css and javascript.
|
||||
|
||||
== Installation ==
|
||||
|
||||
Use the automatic plugin installer of your WordPress admin, or do it manually:
|
||||
|
||||
1. Upload the html-compress directory to the /wp-content/plugins/ directory
|
||||
2. Activate the plugin through the 'Plugins' menu in WordPress
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. html compress source
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 0.1 =
|
||||
* Debug, spaces between tags
|
||||
|
||||
= 0.0 =
|
||||
* First release
|
||||
BIN
wp-content/plugins/html-compress/screenshot-1.png
Normal file
BIN
wp-content/plugins/html-compress/screenshot-1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 41 KiB |
284
wp-content/plugins/wp-minify/common.php
Normal file
284
wp-content/plugins/wp-minify/common.php
Normal file
@ -0,0 +1,284 @@
|
||||
<?php
|
||||
class WPMinifyCommon {
|
||||
|
||||
var $p = null;
|
||||
|
||||
function WPMinifyCommon($plugin) {
|
||||
$this->p = $plugin;
|
||||
}
|
||||
|
||||
// admin methods
|
||||
|
||||
function a_check_version() {
|
||||
// check WP version
|
||||
global $wp_version;
|
||||
if (!empty($wp_version) && is_admin() &&
|
||||
version_compare($wp_version, $this->p->required_wp_version, "<")
|
||||
) {
|
||||
add_action('admin_notices', array($this, 'a_notify_version'));
|
||||
}
|
||||
|
||||
// check plugin version
|
||||
$options = get_option($this->p->name);
|
||||
if ($options && array_key_exists('version', $options) && is_admin() &&
|
||||
version_compare($options['version'], $this->p->version, "<")
|
||||
) {
|
||||
if (method_exists($this->p, 'a_upgrade_options')) {
|
||||
// run plugin's upgrade options function if it exists
|
||||
$this->p->a_upgrade_options();
|
||||
} elseif (method_exists($this->p->a, 'upgrade_options')) {
|
||||
// another flavor
|
||||
$this->p->a->upgrade_options();
|
||||
} else {
|
||||
// else run generic upgrade options function
|
||||
$this->a_upgrade_options();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function a_check_dir_writable($dir, $notify_cb) {
|
||||
if (is_writable($dir)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
// error and return false
|
||||
add_action('admin_notices', $notify_cb);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function a_check_orphan_options($notify_cb) {
|
||||
$options = get_option($this->p->name);
|
||||
if (!$options) {
|
||||
$this->a_upgrade_options();
|
||||
}
|
||||
else {
|
||||
$default_options = $this->p->a_default_options();
|
||||
foreach( $default_options as $key => $value ) {
|
||||
if ( !array_key_exists($key, $options) ) {
|
||||
add_action('admin_notices', $notify_cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function a_notify($message, $error=false) {
|
||||
if ( !$error ) {
|
||||
echo '<div class="updated fade"><p>'.$message.'</p></div>';
|
||||
}
|
||||
else {
|
||||
echo '<div class="error"><p>'.$message.'</p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
function a_notify_version() {
|
||||
global $wp_version;
|
||||
$this->a_notify(
|
||||
sprintf(__('You are using WordPress version %s.', $this->p->name), $wp_version).' '.
|
||||
sprintf(__('%s recommends that you use WordPress %s or newer.', $this->p->name),
|
||||
$this->p->name_proper,
|
||||
$this->p->required_wp_version).' '.
|
||||
sprintf(__('%sPlease update!%s', $this->p->name),
|
||||
'<a href="http://codex.wordpress.org/Upgrading_WordPress">', '</a>'),
|
||||
true);
|
||||
}
|
||||
|
||||
function a_notify_updated() {
|
||||
$this->a_notify(
|
||||
sprintf(__('%s options has been updated.', $this->p->name),
|
||||
$this->p->name_proper));
|
||||
}
|
||||
|
||||
function a_notify_upgrade() {
|
||||
$this->a_notify(
|
||||
sprintf(__('%s options has been upgraded.', $this->p->name),
|
||||
$this->p->name_proper));
|
||||
}
|
||||
|
||||
function a_notify_reset() {
|
||||
$this->a_notify(
|
||||
sprintf(__('%s options has been reset.', $this->p->name),
|
||||
$this->p->name_proper));
|
||||
}
|
||||
|
||||
function a_notify_cache_cleared() {
|
||||
$this->a_notify(
|
||||
sprintf(__('%s cache has been cleared.', $this->p->name),
|
||||
$this->p->name_proper));
|
||||
}
|
||||
|
||||
function a_notify_imported() {
|
||||
$this->a_notify(
|
||||
sprintf(__('%s options imported.', $this->p->name),
|
||||
$this->p->name_proper));
|
||||
}
|
||||
|
||||
function a_notify_import_failed() {
|
||||
$this->a_notify(
|
||||
sprintf(__('%s options import failed!', $this->p->name),
|
||||
$this->p->name_proper), true);
|
||||
}
|
||||
|
||||
function a_notify_import_failed_missing() {
|
||||
$this->a_notify(
|
||||
sprintf(__('Did not receive any file to be imported. %s options import failed!', $this->p->name),
|
||||
$this->p->name_proper), true);
|
||||
}
|
||||
|
||||
function a_notify_import_failed_syntax() {
|
||||
$this->a_notify(
|
||||
sprintf(__('Found syntax errors in file being imported. %s options import failed!', $this->p->name),
|
||||
$this->p->name_proper), true);
|
||||
}
|
||||
|
||||
function a_upgrade_options() {
|
||||
$options = get_option($this->p->name);
|
||||
if ( !$options ) {
|
||||
add_option($this->p->name, $this->p->a_default_options());
|
||||
}
|
||||
else {
|
||||
$default_options = $this->p->a_default_options();
|
||||
|
||||
// upgrade regular options
|
||||
foreach($default_options as $option_name => $option_value) {
|
||||
if(!isset($options[$option_name])) {
|
||||
$options[$option_name] = $option_value;
|
||||
}
|
||||
}
|
||||
$options['version'] = $this->p->version;
|
||||
// get rid of deprecated options if any
|
||||
foreach($default_options['deprecated'] as $option_name) {
|
||||
if(isset($options[$option_name])) {
|
||||
unset($options[$option_name]);
|
||||
}
|
||||
}
|
||||
update_option($this->p->name, $options);
|
||||
}
|
||||
add_action('admin_notices', array($this, 'a_notify_upgrade'));
|
||||
}
|
||||
|
||||
function a_reset_options() {
|
||||
$options = get_option($this->p->name);
|
||||
if ( !$options ) {
|
||||
add_option($this->p->name, $this->p->a_default_options());
|
||||
}
|
||||
else {
|
||||
update_option($this->p->name, $this->p->a_default_options());
|
||||
}
|
||||
}
|
||||
|
||||
function valid_syntax($code) {
|
||||
return @eval('return true;'.$code);
|
||||
}
|
||||
|
||||
function a_import_options($file_var) {
|
||||
if (isset($_FILES[$file_var]) && !empty($_FILES[$file_var]['name'])) {
|
||||
$imported_options = join('', file($_FILES[$file_var]['tmp_name']));
|
||||
$code = '$imported_options = '.$imported_options.';';
|
||||
if ($this->valid_syntax($code)) {
|
||||
if (eval($code) === null) {
|
||||
update_option($this->p->name, $imported_options);
|
||||
add_action('admin_notices', array($this, 'a_notify_imported'));
|
||||
} else {
|
||||
add_action('admin_notices', array($this, 'a_notify_import_failed'));
|
||||
}
|
||||
} else {
|
||||
add_action('admin_notices', array($this, 'a_notify_import_failed_syntax'));
|
||||
}
|
||||
} else {
|
||||
add_action('admin_notices', array($this, 'a_notify_import_failed_missing'));
|
||||
}
|
||||
}
|
||||
|
||||
function a_export_options($file_name) {
|
||||
$content = var_export($this->p->o, true);
|
||||
header('Cache-Control: public');
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-disposition: attachment; filename='.$file_name.'.txt');
|
||||
header('Content-Type: text/plain');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Content-Length: '. mb_strlen($content, 'latin1'));
|
||||
echo $content;
|
||||
exit();
|
||||
}
|
||||
|
||||
function a_register_scripts() {
|
||||
}
|
||||
|
||||
function a_enqueue_scripts() {
|
||||
}
|
||||
|
||||
function a_register_styles() {
|
||||
if (file_exists($this->get_plugin_dir().'css/style-admin.css')) {
|
||||
wp_register_style($this->p->name.'_style_admin',
|
||||
$this->get_plugin_url().'css/style-admin.css');
|
||||
}
|
||||
}
|
||||
|
||||
function a_enqueue_styles() {
|
||||
wp_enqueue_style($this->p->name.'_style_admin');
|
||||
}
|
||||
|
||||
function a_clear_cache() {
|
||||
$cache_location = $this->get_plugin_dir().'/cache/';
|
||||
|
||||
if(!$dh = @opendir($cache_location))
|
||||
{
|
||||
return;
|
||||
}
|
||||
while (false !== ($obj = readdir($dh)))
|
||||
{
|
||||
if($obj == '.' || $obj == '..')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@unlink(trailingslashit($cache_location) . $obj);
|
||||
}
|
||||
closedir($dh);
|
||||
|
||||
$this->a_clear_super_cache();
|
||||
}
|
||||
|
||||
function a_clear_super_cache() {
|
||||
if ( function_exists('prune_super_cache') ) {
|
||||
prune_super_cache(WP_CONTENT_DIR.'/cache/', true );
|
||||
}
|
||||
}
|
||||
|
||||
// other methods
|
||||
|
||||
// Localization support
|
||||
function load_text_domain() {
|
||||
// get current language
|
||||
$locale = get_locale();
|
||||
|
||||
if(!empty($locale)) {
|
||||
// locate translation file
|
||||
$mofile = $this->get_plugin_dir().'lang/'.str_replace('_', '-', $this->p->name).'-'.$locale.'.mo';
|
||||
// load translation
|
||||
if(@file_exists($mofile) && is_readable($mofile)) load_textdomain($this->p->name, $mofile);
|
||||
}
|
||||
}
|
||||
|
||||
function get_plugin_dir() {
|
||||
$path = trailingslashit(trailingslashit(WP_PLUGIN_DIR).plugin_basename(dirname(__FILE__)));
|
||||
$path = preg_replace('/(\/plugins\/[^\/]+?\/).+\//', '\1', $path);
|
||||
return $path;
|
||||
}
|
||||
|
||||
function get_plugin_url() {
|
||||
$url = trailingslashit(trailingslashit(WP_PLUGIN_URL).plugin_basename(dirname(__FILE__)));
|
||||
$url = preg_replace('/(\/plugins\/[^\/]+?\/).+\//', '\1', $url);
|
||||
return $url;
|
||||
}
|
||||
|
||||
function get_current_page_url() {
|
||||
$isHTTPS = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on");
|
||||
$port = (isset($_SERVER["SERVER_PORT"]) && ((!$isHTTPS && $_SERVER["SERVER_PORT"] != "80") || ($isHTTPS && $_SERVER["SERVER_PORT"] != "443")));
|
||||
$port = ($port) ? ':'.$_SERVER["SERVER_PORT"] : '';
|
||||
$url = ($isHTTPS ? 'https://' : 'http://').$_SERVER["SERVER_NAME"].$port.$_SERVER["REQUEST_URI"];
|
||||
return $url;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
12
wp-content/plugins/wp-minify/css/style-admin.css
Normal file
12
wp-content/plugins/wp-minify/css/style-admin.css
Normal file
@ -0,0 +1,12 @@
|
||||
.omni_admin_content {
|
||||
width:1055px;
|
||||
}
|
||||
|
||||
.omni_admin_main {
|
||||
background-color:#f6f6f6;
|
||||
border:1px solid #ccc;
|
||||
float:left;
|
||||
margin:10px;
|
||||
padding:10px;
|
||||
width:760px;
|
||||
}
|
||||
104
wp-content/plugins/wp-minify/http_build_url.php
Normal file
104
wp-content/plugins/wp-minify/http_build_url.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
if (!function_exists('http_build_url'))
|
||||
{
|
||||
define('HTTP_URL_REPLACE', 1); // Replace every part of the first URL when there's one of the second URL
|
||||
define('HTTP_URL_JOIN_PATH', 2); // Join relative paths
|
||||
define('HTTP_URL_JOIN_QUERY', 4); // Join query strings
|
||||
define('HTTP_URL_STRIP_USER', 8); // Strip any user authentication information
|
||||
define('HTTP_URL_STRIP_PASS', 16); // Strip any password authentication information
|
||||
define('HTTP_URL_STRIP_AUTH', 32); // Strip any authentication information
|
||||
define('HTTP_URL_STRIP_PORT', 64); // Strip explicit port numbers
|
||||
define('HTTP_URL_STRIP_PATH', 128); // Strip complete path
|
||||
define('HTTP_URL_STRIP_QUERY', 256); // Strip query string
|
||||
define('HTTP_URL_STRIP_FRAGMENT', 512); // Strip any fragments (#identifier)
|
||||
define('HTTP_URL_STRIP_ALL', 1024); // Strip anything but scheme and host
|
||||
|
||||
// Build an URL
|
||||
// The parts of the second URL will be merged into the first according to the flags argument.
|
||||
//
|
||||
// @param mixed (Part(s) of) an URL in form of a string or associative array like parse_url() returns
|
||||
// @param mixed Same as the first argument
|
||||
// @param int A bitmask of binary or'ed HTTP_URL constants (Optional)HTTP_URL_REPLACE is the default
|
||||
// @param array If set, it will be filled with the parts of the composed url like parse_url() would return
|
||||
function http_build_url($url, $parts=array(), $flags=HTTP_URL_REPLACE, &$new_url=false)
|
||||
{
|
||||
$keys = array('user','pass','port','path','query','fragment');
|
||||
|
||||
// HTTP_URL_STRIP_ALL becomes all the HTTP_URL_STRIP_Xs
|
||||
if ($flags & HTTP_URL_STRIP_ALL)
|
||||
{
|
||||
$flags |= HTTP_URL_STRIP_USER;
|
||||
$flags |= HTTP_URL_STRIP_PASS;
|
||||
$flags |= HTTP_URL_STRIP_PORT;
|
||||
$flags |= HTTP_URL_STRIP_PATH;
|
||||
$flags |= HTTP_URL_STRIP_QUERY;
|
||||
$flags |= HTTP_URL_STRIP_FRAGMENT;
|
||||
}
|
||||
// HTTP_URL_STRIP_AUTH becomes HTTP_URL_STRIP_USER and HTTP_URL_STRIP_PASS
|
||||
else if ($flags & HTTP_URL_STRIP_AUTH)
|
||||
{
|
||||
$flags |= HTTP_URL_STRIP_USER;
|
||||
$flags |= HTTP_URL_STRIP_PASS;
|
||||
}
|
||||
|
||||
// Parse the original URL
|
||||
$parse_url = parse_url($url);
|
||||
|
||||
// Scheme and Host are always replaced
|
||||
if (isset($parts['scheme']))
|
||||
$parse_url['scheme'] = $parts['scheme'];
|
||||
if (isset($parts['host']))
|
||||
$parse_url['host'] = $parts['host'];
|
||||
|
||||
// (If applicable) Replace the original URL with it's new parts
|
||||
if ($flags & HTTP_URL_REPLACE)
|
||||
{
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if (isset($parts[$key]))
|
||||
$parse_url[$key] = $parts[$key];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Join the original URL path with the new path
|
||||
if (isset($parts['path']) && ($flags & HTTP_URL_JOIN_PATH))
|
||||
{
|
||||
if (isset($parse_url['path']))
|
||||
$parse_url['path'] = rtrim(str_replace(basename($parse_url['path']), '', $parse_url['path']), '/') . '/' . ltrim($parts['path'], '/');
|
||||
else
|
||||
$parse_url['path'] = $parts['path'];
|
||||
}
|
||||
|
||||
// Join the original query string with the new query string
|
||||
if (isset($parts['query']) && ($flags & HTTP_URL_JOIN_QUERY))
|
||||
{
|
||||
if (isset($parse_url['query']))
|
||||
$parse_url['query'] .= '&' . $parts['query'];
|
||||
else
|
||||
$parse_url['query'] = $parts['query'];
|
||||
}
|
||||
}
|
||||
|
||||
// Strips all the applicable sections of the URL
|
||||
// Note: Scheme and Host are never stripped
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if ($flags & (int)constant('HTTP_URL_STRIP_' . strtoupper($key)))
|
||||
unset($parse_url[$key]);
|
||||
}
|
||||
|
||||
|
||||
$new_url = $parse_url;
|
||||
|
||||
return
|
||||
((isset($parse_url['scheme'])) ? $parse_url['scheme'] . '://' : '')
|
||||
.((isset($parse_url['user'])) ? $parse_url['user'] . ((isset($parse_url['pass'])) ? ':' . $parse_url['pass'] : '') .'@' : '')
|
||||
.((isset($parse_url['host'])) ? $parse_url['host'] : '')
|
||||
.((isset($parse_url['port'])) ? ':' . $parse_url['port'] : '')
|
||||
.((isset($parse_url['path'])) ? $parse_url['path'] : '')
|
||||
.((isset($parse_url['query'])) ? '?' . $parse_url['query'] : '')
|
||||
.((isset($parse_url['fragment'])) ? '#' . $parse_url['fragment'] : '')
|
||||
;
|
||||
}
|
||||
}
|
||||
175
wp-content/plugins/wp-minify/js/easySlider1.5.js
Normal file
175
wp-content/plugins/wp-minify/js/easySlider1.5.js
Normal file
@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Easy Slider 1.5 - jQuery plugin
|
||||
* written by Alen Grakalic
|
||||
* http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
|
||||
*
|
||||
* Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
|
||||
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
||||
* and GPL (GPL-LICENSE.txt) licenses.
|
||||
*
|
||||
* Built for jQuery library
|
||||
* http://jquery.com
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* markup example for $("#slider").easySlider();
|
||||
*
|
||||
* <div id="slider">
|
||||
* <ul>
|
||||
* <li><img src="images/01.jpg" alt="" /></li>
|
||||
* <li><img src="images/02.jpg" alt="" /></li>
|
||||
* <li><img src="images/03.jpg" alt="" /></li>
|
||||
* <li><img src="images/04.jpg" alt="" /></li>
|
||||
* <li><img src="images/05.jpg" alt="" /></li>
|
||||
* </ul>
|
||||
* </div>
|
||||
*
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
|
||||
$.fn.easySlider = function(options){
|
||||
|
||||
// default configuration properties
|
||||
var defaults = {
|
||||
prevId: 'prevBtn',
|
||||
prevText: 'Previous',
|
||||
nextId: 'nextBtn',
|
||||
nextText: 'Next',
|
||||
controlsShow: true,
|
||||
controlsBefore: '',
|
||||
controlsAfter: '',
|
||||
controlsFade: true,
|
||||
firstId: 'firstBtn',
|
||||
firstText: 'First',
|
||||
firstShow: false,
|
||||
lastId: 'lastBtn',
|
||||
lastText: 'Last',
|
||||
lastShow: false,
|
||||
vertical: false,
|
||||
speed: 800,
|
||||
auto: false,
|
||||
pause: 2000,
|
||||
continuous: false
|
||||
};
|
||||
|
||||
var options = $.extend(defaults, options);
|
||||
|
||||
this.each(function() {
|
||||
var obj = $(this);
|
||||
var s = $("li", obj).length;
|
||||
var w = $("li", obj).width();
|
||||
var h = $("li", obj).height();
|
||||
obj.width(w);
|
||||
obj.height(h);
|
||||
obj.css("overflow","hidden");
|
||||
var ts = s-1;
|
||||
var t = 0;
|
||||
$("ul", obj).css('width',s*w);
|
||||
if(!options.vertical) $("li", obj).css('float','left');
|
||||
|
||||
if(options.controlsShow){
|
||||
var html = options.controlsBefore;
|
||||
if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
|
||||
html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
|
||||
html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
|
||||
if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';
|
||||
html += options.controlsAfter;
|
||||
$(obj).after(html);
|
||||
};
|
||||
|
||||
$("a","#"+options.nextId).click(function(){
|
||||
animate("next",true);
|
||||
});
|
||||
$("a","#"+options.prevId).click(function(){
|
||||
animate("prev",true);
|
||||
});
|
||||
$("a","#"+options.firstId).click(function(){
|
||||
animate("first",true);
|
||||
});
|
||||
$("a","#"+options.lastId).click(function(){
|
||||
animate("last",true);
|
||||
});
|
||||
|
||||
function animate(dir,clicked){
|
||||
var ot = t;
|
||||
switch(dir){
|
||||
case "next":
|
||||
t = (ot>=ts) ? (options.continuous ? 0 : ts) : t+1;
|
||||
break;
|
||||
case "prev":
|
||||
t = (t<=0) ? (options.continuous ? ts : 0) : t-1;
|
||||
break;
|
||||
case "first":
|
||||
t = 0;
|
||||
break;
|
||||
case "last":
|
||||
t = ts;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
||||
var diff = Math.abs(ot-t);
|
||||
var speed = diff*options.speed;
|
||||
if(!options.vertical) {
|
||||
p = (t*w*-1);
|
||||
$("ul",obj).animate(
|
||||
{ marginLeft: p },
|
||||
speed
|
||||
);
|
||||
} else {
|
||||
p = (t*h*-1);
|
||||
$("ul",obj).animate(
|
||||
{ marginTop: p },
|
||||
speed
|
||||
);
|
||||
};
|
||||
|
||||
if(!options.continuous && options.controlsFade){
|
||||
if(t==ts){
|
||||
$("a","#"+options.nextId).hide();
|
||||
$("a","#"+options.lastId).hide();
|
||||
} else {
|
||||
$("a","#"+options.nextId).show();
|
||||
$("a","#"+options.lastId).show();
|
||||
};
|
||||
if(t==0){
|
||||
$("a","#"+options.prevId).hide();
|
||||
$("a","#"+options.firstId).hide();
|
||||
} else {
|
||||
$("a","#"+options.prevId).show();
|
||||
$("a","#"+options.firstId).show();
|
||||
};
|
||||
};
|
||||
|
||||
if(clicked) clearTimeout(timeout);
|
||||
if(options.auto && dir=="next" && !clicked){;
|
||||
timeout = setTimeout(function(){
|
||||
animate("next",false);
|
||||
},diff*options.speed+options.pause);
|
||||
};
|
||||
|
||||
};
|
||||
// init
|
||||
var timeout;
|
||||
if(options.auto){;
|
||||
timeout = setTimeout(function(){
|
||||
animate("next",false);
|
||||
},options.pause);
|
||||
};
|
||||
|
||||
if(!options.continuous && options.controlsFade){
|
||||
$("a","#"+options.prevId).hide();
|
||||
$("a","#"+options.firstId).hide();
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
|
||||
|
||||
|
||||
BIN
wp-content/plugins/wp-minify/lang/wp-minify-it_IT.mo
Normal file
BIN
wp-content/plugins/wp-minify/lang/wp-minify-it_IT.mo
Normal file
Binary file not shown.
273
wp-content/plugins/wp-minify/lang/wp-minify-it_IT.po
Normal file
273
wp-content/plugins/wp-minify/lang/wp-minify-it_IT.po
Normal file
@ -0,0 +1,273 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: WP Minify in italiano\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2011-05-09 22:34+0100\n"
|
||||
"PO-Revision-Date: \n"
|
||||
"Last-Translator: Gianni Diurno (aka gidibao) <gidibao[at]gmail[dot]com>\n"
|
||||
"Language-Team: Gianni Diurno | gidibao.net\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Poedit-Basepath: ../\n"
|
||||
"X-Poedit-KeywordsList: __;_e\n"
|
||||
"X-Poedit-Language: Italian\n"
|
||||
"X-Poedit-Country: ITALY\n"
|
||||
"X-Poedit-SourceCharset: utf-8\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
|
||||
#: common.php:77
|
||||
#, php-format
|
||||
msgid "You are using WordPress version %s."
|
||||
msgstr "Stai utilizzando la versione %s di WordPress."
|
||||
|
||||
#: common.php:78
|
||||
#, php-format
|
||||
msgid "%s recommends that you use WordPress %s or newer."
|
||||
msgstr "%s si raccomanda l'utilizzo di WordPress %s o superiore."
|
||||
|
||||
#: common.php:81
|
||||
#, php-format
|
||||
msgid "%sPlease update!%s"
|
||||
msgstr "%sAggiorna!%s"
|
||||
|
||||
#: common.php:88
|
||||
#, php-format
|
||||
msgid "%s options has been updated."
|
||||
msgstr "%s le opzioni sono state aggiornate."
|
||||
|
||||
#: common.php:94
|
||||
#, php-format
|
||||
msgid "%s options has been upgraded."
|
||||
msgstr "%s le opzioni sono state aggiornate alla superiore."
|
||||
|
||||
#: common.php:100
|
||||
#, php-format
|
||||
msgid "%s options has been reset."
|
||||
msgstr "%s le opzioni sono state ripristinate."
|
||||
|
||||
#: common.php:106
|
||||
#, php-format
|
||||
msgid "%s cache has been cleared."
|
||||
msgstr "%s la cache é stata svuotata."
|
||||
|
||||
#: common.php:112
|
||||
#, php-format
|
||||
msgid "%s options imported."
|
||||
msgstr "%s le opzioni sono state importate."
|
||||
|
||||
#: common.php:118
|
||||
#, php-format
|
||||
msgid "%s options import failed!"
|
||||
msgstr "%s la importazione delle opzioni é fallita!"
|
||||
|
||||
#: common.php:124
|
||||
#, php-format
|
||||
msgid "Did not receive any file to be imported. %s options import failed!"
|
||||
msgstr "Non é stato ricevuto alcun file che possa essere importato. %s l'importazione delle opzioni é fallita!"
|
||||
|
||||
#: common.php:130
|
||||
#, php-format
|
||||
msgid "Found syntax errors in file being imported. %s options import failed!"
|
||||
msgstr "E' stato riscontrato un errore di sintassi nel file di importazione. %s l'importazione delle opzioni non é avvenuta!"
|
||||
|
||||
#: options-generic.php:3
|
||||
msgid "All of options will return to default settings. Are you sure you want to reset all settings?"
|
||||
msgstr "Tutte le opzioni ritorneranno alla impostazioni predefinite. Sei certo di volere procedere?"
|
||||
|
||||
#: options-generic.php:18
|
||||
#: options-generic.php:71
|
||||
msgid "Show Advanced Options"
|
||||
msgstr "Mostra opzioni avanzate"
|
||||
|
||||
#: options-generic.php:35
|
||||
#: options-generic.php:66
|
||||
msgid "Hide Advanced Options"
|
||||
msgstr "Nascondi opzioni avanzate"
|
||||
|
||||
#: options-generic.php:88
|
||||
msgid "Support this plugin!"
|
||||
msgstr "Sostieni questo plugin!"
|
||||
|
||||
#: options-generic.php:89
|
||||
msgid "Display \"Page optimized by WP Minify\" link in the footer"
|
||||
msgstr "Mostra nel footer il link \"Ottimizzazione pagina via WP Minify\""
|
||||
|
||||
#: options-generic.php:90
|
||||
msgid "Do not display \"Page optimized by WP Minify\" link."
|
||||
msgstr "Non mostrare il link \"Ottimizzazione pagina via WP Minify\"."
|
||||
|
||||
#: options-generic.php:91
|
||||
msgid "I will donate and/or write about this plugin"
|
||||
msgstr "Ho scritto e/o donato per questo plugin"
|
||||
|
||||
#: options-generic.php:100
|
||||
#: wp-minify.php:370
|
||||
msgid "General Configuration"
|
||||
msgstr "Configurazione generale"
|
||||
|
||||
#: options-generic.php:101
|
||||
msgid "Enable JavaScript Minification"
|
||||
msgstr "Attiva minimizzazione per i JavaScript"
|
||||
|
||||
#: options-generic.php:102
|
||||
msgid "Enable CSS Minification"
|
||||
msgstr "Attiva minimizzazione CSS"
|
||||
|
||||
#: options-generic.php:103
|
||||
msgid "Enable HTML Minification"
|
||||
msgstr "Attiva minimizzazione HTML"
|
||||
|
||||
#: options-generic.php:111
|
||||
msgid "Debugging"
|
||||
msgstr "Debugging"
|
||||
|
||||
#: options-generic.php:112
|
||||
msgid "Combine files but do not minify"
|
||||
msgstr "Unire i file senza minimizzarli"
|
||||
|
||||
#: options-generic.php:113
|
||||
msgid "Show minify errors through FirePHP"
|
||||
msgstr "Mostra errori minimizzazione via FirePHP"
|
||||
|
||||
#: options-generic.php:122
|
||||
msgid "Local Files Minification"
|
||||
msgstr "Minimizzazione file locali"
|
||||
|
||||
#: options-generic.php:123
|
||||
msgid "JavaScript files to exclude from minify (line delimited)."
|
||||
msgstr "File JavaScript da escludere dalla minimizzazione (uno per riga)."
|
||||
|
||||
#: options-generic.php:124
|
||||
msgid "CSS files to exclude from minify (line delimited)."
|
||||
msgstr "File CSS da escludere dalla minimizzazione (uno per riga)."
|
||||
|
||||
#: options-generic.php:125
|
||||
msgid "URIs on which WP-Minify parsing will be disabled (line delimited)"
|
||||
msgstr "URI da escludere dal parsing di WP-Minify (uno per riga)"
|
||||
|
||||
#: options-generic.php:134
|
||||
msgid "Non-Local Files Minification"
|
||||
msgstr "Minimizzazione file non locali"
|
||||
|
||||
#: options-generic.php:135
|
||||
msgid "Enable minification on external files"
|
||||
msgstr "Attiva minimizzazione per i file esterni"
|
||||
|
||||
#: options-generic.php:136
|
||||
msgid "Not recommended unless you want to exclude a bunch of external .js/.css files"
|
||||
msgstr "Non consigliabile a patto che tu non voglia escludere un gruppo di file .js/.css esterni"
|
||||
|
||||
#: options-generic.php:137
|
||||
msgid "External JavaScript files to include into minify."
|
||||
msgstr "File JavaScript esterni da includere alla minimizzazione."
|
||||
|
||||
#: options-generic.php:138
|
||||
#: options-generic.php:141
|
||||
msgid "Only useful if \"Minification on external files\" is unchecked"
|
||||
msgstr "Utile solo se \"Minimizzazione file esterni\" non attiva"
|
||||
|
||||
#: options-generic.php:139
|
||||
#: options-generic.php:142
|
||||
#: options-generic.php:166
|
||||
msgid "more info"
|
||||
msgstr "ulteriori informazioni"
|
||||
|
||||
#: options-generic.php:140
|
||||
msgid "External CSS files to include into minify."
|
||||
msgstr "File CSS esterni da includere alla minimizzazione."
|
||||
|
||||
#: options-generic.php:150
|
||||
msgid "Caching"
|
||||
msgstr "Cache"
|
||||
|
||||
#: options-generic.php:151
|
||||
msgid "Cache expires after every"
|
||||
msgstr "La cache scade ogni "
|
||||
|
||||
#: options-generic.php:152
|
||||
msgid "seconds"
|
||||
msgstr " secondi"
|
||||
|
||||
#: options-generic.php:153
|
||||
msgid "Manually Clear Cache"
|
||||
msgstr "Svuota manualmente la cache"
|
||||
|
||||
#: options-generic.php:161
|
||||
msgid "Tweaking/Tuning"
|
||||
msgstr "Tweaking/Tuning"
|
||||
|
||||
#: options-generic.php:162
|
||||
msgid "Use \"pretty\" URL\""
|
||||
msgstr "Usa \"pretty\" URL\""
|
||||
|
||||
#: options-generic.php:163
|
||||
msgid "i.e. use \"wp-minify/cache/1234abcd.js\" instead of \"wp-minify/min/?f=file1.js,file2.js,...,fileN.js\""
|
||||
msgstr "ad esempio usa \"wp-minify/cache/1234abcd.js\" al posto di \"wp-minify/min/?f=file1.js,file2.js,...,fileN.js\""
|
||||
|
||||
#: options-generic.php:164
|
||||
msgid "Place Minified JavaScript in footer"
|
||||
msgstr "Posiziona il Minified JavaScript nel footer"
|
||||
|
||||
#: options-generic.php:165
|
||||
msgid "Not recommended"
|
||||
msgstr "Non consigliato"
|
||||
|
||||
#: options-generic.php:172
|
||||
msgid "Force all JavaScript/CSS calls to be HTTPS on HTTPS pages"
|
||||
msgstr "Imponi a tutte le chiamate JavaScript/CSS di essere HTTPS per le pagine HTTPS"
|
||||
|
||||
#: options-generic.php:179
|
||||
msgid "Automatically set your Minify base per siteurl setting (recommended)"
|
||||
msgstr "Imposta in automatico Minify a url del sito (consigliato)"
|
||||
|
||||
#: options-generic.php:180
|
||||
msgid "Extra arguments to pass to minify engine. This value will get append to calls to URL \"wp-minify/min/?f=file1.js,file2.js,...,fileN.js\"."
|
||||
msgstr "Argomenti extra da veicolare nel motore di minimizzazione. Questo valore verrà aggiunto alle chiamate all'URL \"wp-minify/min/?f=file1.js,file2.js,...,fileN.js\"."
|
||||
|
||||
#: options-generic.php:181
|
||||
msgid "e.g. You can specify this value to be b=somepath to specify the base path for all files passed into Minify."
|
||||
msgstr "ad es: specifica il valore b=somepath per definire il percorso di base per tutti i file veicolati in Minify."
|
||||
|
||||
#: options-generic.php:192
|
||||
msgid "Update Options"
|
||||
msgstr "Aggiorna le opzioni"
|
||||
|
||||
#: options-generic.php:193
|
||||
msgid "Reset ALL Options"
|
||||
msgstr "Ripristina TUTTE le opzioni"
|
||||
|
||||
#: wp-minify.php:331
|
||||
msgid "Cache directory is not writable. Please grant your server write permissions to the directory"
|
||||
msgstr "La cartella Cache non é scrivibile. Apporta le modifiche ai permessi chmod del file"
|
||||
|
||||
#: wp-minify.php:339
|
||||
msgid "Minify Engine config.php is not writable. Please grant your server write permissions to file"
|
||||
msgstr "Il Minify Engine config.php non é scrivibile. Apporta le modifiche ai permessi chmod del file"
|
||||
|
||||
#: wp-minify.php:346
|
||||
msgid "Some option settings are missing (possibly from plugin upgrade)."
|
||||
msgstr "Mancano alcune opzioni di impostazione (causa aggiornamento plugin)."
|
||||
|
||||
#: wp-minify.php:350
|
||||
msgid "Minify Engine config.php was configured automatically."
|
||||
msgstr "Il Minify Engine config.php é stato configurato automaticamente."
|
||||
|
||||
#: wp-minify.php:369
|
||||
msgid "WP Minify Options"
|
||||
msgstr "Opzioni WP Minify"
|
||||
|
||||
#: wp-minify.php:371
|
||||
msgid "Documentation"
|
||||
msgstr "Documentazione"
|
||||
|
||||
#: wp-minify.php:418
|
||||
msgid "Error: Could not fetch and cache URL"
|
||||
msgstr "Errore: impossibile elaborazione e cache URL"
|
||||
|
||||
#: wp-minify.php:419
|
||||
msgid "You might need to exclude this file in WP Minify options."
|
||||
msgstr "Potrebbe essere necessario escludere questo file nelle opzioni WP Minify."
|
||||
|
||||
#~ msgid "Debug mode"
|
||||
#~ msgstr "Modalità debug"
|
||||
BIN
wp-content/plugins/wp-minify/lang/wp-minify-uk.mo
Normal file
BIN
wp-content/plugins/wp-minify/lang/wp-minify-uk.mo
Normal file
Binary file not shown.
286
wp-content/plugins/wp-minify/lang/wp-minify-uk.po
Normal file
286
wp-content/plugins/wp-minify/lang/wp-minify-uk.po
Normal file
@ -0,0 +1,286 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: WP-minify\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2011-04-24 22:14-0800\n"
|
||||
"PO-Revision-Date: \n"
|
||||
"Last-Translator: Jurko Chervony <info@skinik.name>\n"
|
||||
"Language-Team: UA Wordpress <skinik@wordpress.co.ua>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Poedit-Language: Ukrainian\n"
|
||||
"X-Poedit-Country: UKRAINE\n"
|
||||
"X-Poedit-SourceCharset: utf-8\n"
|
||||
|
||||
#: common.php:77
|
||||
#, php-format
|
||||
msgid "You are using WordPress version %s."
|
||||
msgstr "Ви використовуєте WordPress версії %s."
|
||||
|
||||
#: common.php:78
|
||||
#, php-format
|
||||
msgid "%s recommends that you use WordPress %s or newer."
|
||||
msgstr "%s рекомендує використовувати WordPress %s або більш пізньої версії."
|
||||
|
||||
#: common.php:81
|
||||
#, php-format
|
||||
msgid "%sPlease update!%s"
|
||||
msgstr "%sБудь ласка, оновіть!%s"
|
||||
|
||||
#: common.php:88
|
||||
#, php-format
|
||||
msgid "%s options has been updated."
|
||||
msgstr "Опції %s оновлено"
|
||||
|
||||
#: common.php:94
|
||||
#, php-format
|
||||
msgid "%s options has been upgraded."
|
||||
msgstr "Опції %s оновлено."
|
||||
|
||||
#: common.php:100
|
||||
#, php-format
|
||||
msgid "%s options has been reset."
|
||||
msgstr "Опції %s скинуто."
|
||||
|
||||
#: common.php:106
|
||||
#, php-format
|
||||
msgid "%s cache has been cleared."
|
||||
msgstr "Кеш %s очищено."
|
||||
|
||||
#: common.php:112
|
||||
#, php-format
|
||||
msgid "%s options imported."
|
||||
msgstr "Опції %s імпортовано."
|
||||
|
||||
#: common.php:118
|
||||
#, php-format
|
||||
msgid "%s options import failed!"
|
||||
msgstr "Імпортування опції %s невдале!"
|
||||
|
||||
#: common.php:124
|
||||
#, php-format
|
||||
msgid "Did not receive any file to be imported. %s options import failed!"
|
||||
msgstr "Неможливо отримати доступ до файлу. %s опції імпортувати не вдалося!"
|
||||
|
||||
#: common.php:130
|
||||
#, php-format
|
||||
msgid "Found syntax errors in file being imported. %s options import failed!"
|
||||
msgstr "Знайдено синтаксичні помилки у файлі імпорту. %s параметри імпортувати не вдалося!"
|
||||
|
||||
#: options-generic.php:3
|
||||
msgid "All of options will return to default settings. Are you sure you want to reset all settings?"
|
||||
msgstr "Усі налаштування буде видалено. Ви справді хочете повернутися до стандартних налаштувань?"
|
||||
|
||||
#: options-generic.php:18
|
||||
#: options-generic.php:71
|
||||
msgid "Show Advanced Options"
|
||||
msgstr "Показати розширені опції"
|
||||
|
||||
#: options-generic.php:35
|
||||
#: options-generic.php:66
|
||||
msgid "Hide Advanced Options"
|
||||
msgstr "Сховати розширені опції"
|
||||
|
||||
#: options-generic.php:88
|
||||
msgid "Support this plugin!"
|
||||
msgstr "Підтримайте цей плаґін!"
|
||||
|
||||
#: options-generic.php:89
|
||||
msgid "Display \"Page optimized by WP Minify\" link in the footer"
|
||||
msgstr "Показувати в підвалі «Page optimized by WP Minify»"
|
||||
|
||||
#: options-generic.php:90
|
||||
msgid "Do not display \"Page optimized by WP Minify\" link."
|
||||
msgstr "Не показувати «Page optimized by WP Minify»"
|
||||
|
||||
#: options-generic.php:91
|
||||
msgid "I will donate and/or write about this plugin"
|
||||
msgstr "Я хочу зробити благодійний внесок чи написати про плаґін"
|
||||
|
||||
#: options-generic.php:100
|
||||
#: wp-minify.php:370
|
||||
msgid "General Configuration"
|
||||
msgstr "Загальні опції"
|
||||
|
||||
#: options-generic.php:101
|
||||
msgid "Enable JavaScript Minification"
|
||||
msgstr "Включити мінімізацію JavaScript"
|
||||
|
||||
#: options-generic.php:102
|
||||
msgid "Enable CSS Minification"
|
||||
msgstr "Включити мінімізацію CSS"
|
||||
|
||||
#: options-generic.php:103
|
||||
msgid "Enable HTML Minification"
|
||||
msgstr "Включити мінімізацію HTML"
|
||||
|
||||
#: options-generic.php:112
|
||||
msgid "Debugging"
|
||||
msgstr "Режим відлагодження"
|
||||
|
||||
#: options-generic.php:113
|
||||
msgid "Don't use \"pretty\" URL\""
|
||||
msgstr "Не використовувати «гарні» URL"
|
||||
|
||||
#: options-generic.php:114
|
||||
msgid "Combine files but do not minify"
|
||||
msgstr "Об’єднати файли, але не мінімізувати"
|
||||
|
||||
#: options-generic.php:115
|
||||
msgid "Show minify errors through FirePHP"
|
||||
msgstr "Показувати помилки мінімізації у FirePHP"
|
||||
|
||||
#: options-generic.php:124
|
||||
msgid "Local Files Minification"
|
||||
msgstr "Мінімізація локальних файлів"
|
||||
|
||||
#: options-generic.php:125
|
||||
msgid "JavaScript files to exclude from minify (line delimited)."
|
||||
msgstr "Файли Javascript для виключення (у кожному рядку по файлу)."
|
||||
|
||||
#: options-generic.php:126
|
||||
msgid "CSS files to exclude from minify (line delimited)."
|
||||
msgstr "CSS файли для виключення (у кожному рядку по файлу)."
|
||||
|
||||
#: options-generic.php:127
|
||||
msgid "URIs on which WP-Minify parsing will be disabled (line delimited)"
|
||||
msgstr "Адреси URI, на яких WP-Minify буде відключено (у кожному рядку по файлу)"
|
||||
|
||||
#: options-generic.php:136
|
||||
msgid "Non-Local Files Minification"
|
||||
msgstr "Мінімізація НЕ локальних файлів"
|
||||
|
||||
#: options-generic.php:137
|
||||
msgid "Enable minification on external files"
|
||||
msgstr "Включити мінімізацію сторонніх файлів"
|
||||
|
||||
#: options-generic.php:138
|
||||
msgid "Not recommended unless you want to exclude a bunch of external .js/.css files"
|
||||
msgstr "Не рекомендується, якщо ви хочете виключити купу зовнішніх .js /.css файлів"
|
||||
|
||||
#: options-generic.php:139
|
||||
msgid "External JavaScript files to include into minify."
|
||||
msgstr "Сторонні файли JavaScript для включення в мінімізацію."
|
||||
|
||||
#: options-generic.php:140
|
||||
#: options-generic.php:143
|
||||
msgid "Only useful if \"Minification on external files\" is unchecked"
|
||||
msgstr "Має сенс тільки тоді, коли «Включити мінімізацію сторонніх файлів» НЕ увімкнено"
|
||||
|
||||
#: options-generic.php:141
|
||||
#: options-generic.php:144
|
||||
#: options-generic.php:164
|
||||
msgid "more info"
|
||||
msgstr "більше інформації"
|
||||
|
||||
#: options-generic.php:142
|
||||
msgid "External CSS files to include into minify."
|
||||
msgstr "Зовнішні CSS-файли, які будуть включені в мінімізацію."
|
||||
|
||||
#: options-generic.php:151
|
||||
msgid "Caching"
|
||||
msgstr "Кешування"
|
||||
|
||||
#: options-generic.php:152
|
||||
msgid "Cache expires after every"
|
||||
msgstr "Видаляти кеш кожні"
|
||||
|
||||
#: options-generic.php:153
|
||||
msgid "seconds"
|
||||
msgstr "секунд"
|
||||
|
||||
#: options-generic.php:154
|
||||
msgid "Manually Clear Cache"
|
||||
msgstr "Очистити кеш вручну"
|
||||
|
||||
#: options-generic.php:161
|
||||
msgid "Tweaking/Tuning"
|
||||
msgstr "Тонка настройка/Тюнінґ"
|
||||
|
||||
#: options-generic.php:162
|
||||
msgid "Place Minified JavaScript in footer"
|
||||
msgstr "Розмістити мінімізовані файли JavaScript у підвалі"
|
||||
|
||||
#: options-generic.php:163
|
||||
msgid "Not recommended"
|
||||
msgstr "Не рекомендовано"
|
||||
|
||||
#: options-generic.php:170
|
||||
msgid "Force all JavaScript/CSS calls to be HTTPS on HTTPS pages"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:177
|
||||
msgid "Automatically set your Minify base per siteurl setting (recommended)"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:178
|
||||
msgid "Extra arguments to pass to minify engine. This value will get append to calls to URL \"wp-minify/min/?f=file1.js,file2.js,...,fileN.js\"."
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:179
|
||||
msgid "e.g. You can specify this value to be b=somepath to specify the base path for all files passed into Minify."
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:190
|
||||
msgid "Update Options"
|
||||
msgstr "Оновити опції"
|
||||
|
||||
#: options-generic.php:191
|
||||
msgid "Reset ALL Options"
|
||||
msgstr "Скинути ВСІ опції"
|
||||
|
||||
#: wp-minify.php:331
|
||||
msgid "Cache directory is not writable. Please grant your server write permissions to the directory"
|
||||
msgstr "Директорія кешу не має прав на запис. Поставте права на запис."
|
||||
|
||||
#: wp-minify.php:339
|
||||
msgid "Minify Engine config.php is not writable. Please grant your server write permissions to file"
|
||||
msgstr "Файл налаштувань config.php не має прав на запис. Будь ласка, надайте права на запис"
|
||||
|
||||
#: wp-minify.php:346
|
||||
msgid "Some option settings are missing (possibly from plugin upgrade)."
|
||||
msgstr "Деякі параметри налаштування відсутні (можливо, через оновлення плаґіну)."
|
||||
|
||||
#: wp-minify.php:350
|
||||
msgid "Minify Engine config.php was configured automatically."
|
||||
msgstr "Файл config.php налаштовано автоматично."
|
||||
|
||||
#: wp-minify.php:369
|
||||
msgid "WP Minify Options"
|
||||
msgstr "Опції WP Minify"
|
||||
|
||||
#: wp-minify.php:371
|
||||
msgid "Documentation"
|
||||
msgstr "Документація"
|
||||
|
||||
#: wp-minify.php:418
|
||||
msgid "Error: Could not fetch and cache URL"
|
||||
msgstr "Помилка: не вдалося отримати і закешувати URL"
|
||||
|
||||
#: wp-minify.php:419
|
||||
msgid "You might need to exclude this file in WP Minify options."
|
||||
msgstr "Вам може знадобитися виключити цей файл в опціях WP Minify."
|
||||
|
||||
#~ msgid "Debug mode"
|
||||
#~ msgstr "Режим розробника"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "WordPress path from web root (e.g. Use \"blog/wordpress\" if your blog is "
|
||||
#~ "installed under \"http://example.com/blog/wordpress\". Leave empty if "
|
||||
#~ "your blog is installed in the web root.)"
|
||||
#~ msgstr ""
|
||||
#~ "Шлях до теки WordPress (наприклад, використайте \"blog/wordpress\", якщо "
|
||||
#~ "Ваш сайт розміщено за адресою \"http://example.com/blog/wordpress\". "
|
||||
#~ "Нічого не вказуйте, якщо сайт розміщено у кореневій теці.)"
|
||||
|
||||
#~ msgid "Additional Javascript files to minify (line delimited)"
|
||||
#~ msgstr ""
|
||||
#~ "Додаткові файли Javascript для мінімізації (у кожному рядку по файлу)"
|
||||
|
||||
#~ msgid "Additional CSS files to minify (line delimited)"
|
||||
#~ msgstr "Додаткові файли CSS для мінімізації (у кожному рядку по файлу)"
|
||||
|
||||
#~ msgid "Reactivate"
|
||||
#~ msgstr "Повторно активувати"
|
||||
264
wp-content/plugins/wp-minify/lang/wp-minify.pot
Normal file
264
wp-content/plugins/wp-minify/lang/wp-minify.pot
Normal file
@ -0,0 +1,264 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: wp_minify\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2011-04-24 22:14-0800\n"
|
||||
"PO-Revision-Date: \n"
|
||||
"Last-Translator: Thaya Kareeson <thaya.kareeson@gmail.com>\n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Poedit-Basepath: ../\n"
|
||||
"X-Poedit-KeywordsList: __;_e\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
|
||||
#: common.php:77
|
||||
#, php-format
|
||||
msgid "You are using WordPress version %s."
|
||||
msgstr ""
|
||||
|
||||
#: common.php:78
|
||||
#, php-format
|
||||
msgid "%s recommends that you use WordPress %s or newer."
|
||||
msgstr ""
|
||||
|
||||
#: common.php:81
|
||||
#, php-format
|
||||
msgid "%sPlease update!%s"
|
||||
msgstr ""
|
||||
|
||||
#: common.php:88
|
||||
#, php-format
|
||||
msgid "%s options has been updated."
|
||||
msgstr ""
|
||||
|
||||
#: common.php:94
|
||||
#, php-format
|
||||
msgid "%s options has been upgraded."
|
||||
msgstr ""
|
||||
|
||||
#: common.php:100
|
||||
#, php-format
|
||||
msgid "%s options has been reset."
|
||||
msgstr ""
|
||||
|
||||
#: common.php:106
|
||||
#, php-format
|
||||
msgid "%s cache has been cleared."
|
||||
msgstr ""
|
||||
|
||||
#: common.php:112
|
||||
#, php-format
|
||||
msgid "%s options imported."
|
||||
msgstr ""
|
||||
|
||||
#: common.php:118
|
||||
#, php-format
|
||||
msgid "%s options import failed!"
|
||||
msgstr ""
|
||||
|
||||
#: common.php:124
|
||||
#, php-format
|
||||
msgid "Did not receive any file to be imported. %s options import failed!"
|
||||
msgstr ""
|
||||
|
||||
#: common.php:130
|
||||
#, php-format
|
||||
msgid "Found syntax errors in file being imported. %s options import failed!"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:3
|
||||
msgid "All of options will return to default settings. Are you sure you want to reset all settings?"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:18
|
||||
#: options-generic.php:71
|
||||
msgid "Show Advanced Options"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:35
|
||||
#: options-generic.php:66
|
||||
msgid "Hide Advanced Options"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:88
|
||||
msgid "Support this plugin!"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:89
|
||||
msgid "Display \"Page optimized by WP Minify\" link in the footer"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:90
|
||||
msgid "Do not display \"Page optimized by WP Minify\" link."
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:91
|
||||
msgid "I will donate and/or write about this plugin"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:100
|
||||
#: wp-minify.php:370
|
||||
msgid "General Configuration"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:101
|
||||
msgid "Enable JavaScript Minification"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:102
|
||||
msgid "Enable CSS Minification"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:103
|
||||
msgid "Enable HTML Minification"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:112
|
||||
msgid "Debugging"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:113
|
||||
msgid "Don't use \"pretty\" URL\""
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:114
|
||||
msgid "Combine files but do not minify"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:115
|
||||
msgid "Show minify errors through FirePHP"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:124
|
||||
msgid "Local Files Minification"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:125
|
||||
msgid "JavaScript files to exclude from minify (line delimited)."
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:126
|
||||
msgid "CSS files to exclude from minify (line delimited)."
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:127
|
||||
msgid "URIs on which WP-Minify parsing will be disabled (line delimited)"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:136
|
||||
msgid "Non-Local Files Minification"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:137
|
||||
msgid "Enable minification on external files"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:138
|
||||
msgid "Not recommended unless you want to exclude a bunch of external .js/.css files"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:139
|
||||
msgid "External JavaScript files to include into minify."
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:140
|
||||
#: options-generic.php:143
|
||||
msgid "Only useful if \"Minification on external files\" is unchecked"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:141
|
||||
#: options-generic.php:144
|
||||
#: options-generic.php:164
|
||||
msgid "more info"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:142
|
||||
msgid "External CSS files to include into minify."
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:151
|
||||
msgid "Caching"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:152
|
||||
msgid "Cache expires after every"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:153
|
||||
msgid "seconds"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:154
|
||||
msgid "Manually Clear Cache"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:161
|
||||
msgid "Tweaking/Tuning"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:162
|
||||
msgid "Place Minified JavaScript in footer"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:163
|
||||
msgid "Not recommended"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:170
|
||||
msgid "Force all JavaScript/CSS calls to be HTTPS on HTTPS pages"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:177
|
||||
msgid "Automatically set your Minify base per siteurl setting (recommended)"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:178
|
||||
msgid "Extra arguments to pass to minify engine. This value will get append to calls to URL \"wp-minify/min/?f=file1.js,file2.js,...,fileN.js\"."
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:179
|
||||
msgid "e.g. You can specify this value to be b=somepath to specify the base path for all files passed into Minify."
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:190
|
||||
msgid "Update Options"
|
||||
msgstr ""
|
||||
|
||||
#: options-generic.php:191
|
||||
msgid "Reset ALL Options"
|
||||
msgstr ""
|
||||
|
||||
#: wp-minify.php:331
|
||||
msgid "Cache directory is not writable. Please grant your server write permissions to the directory"
|
||||
msgstr ""
|
||||
|
||||
#: wp-minify.php:339
|
||||
msgid "Minify Engine config.php is not writable. Please grant your server write permissions to file"
|
||||
msgstr ""
|
||||
|
||||
#: wp-minify.php:346
|
||||
msgid "Some option settings are missing (possibly from plugin upgrade)."
|
||||
msgstr ""
|
||||
|
||||
#: wp-minify.php:350
|
||||
msgid "Minify Engine config.php was configured automatically."
|
||||
msgstr ""
|
||||
|
||||
#: wp-minify.php:369
|
||||
msgid "WP Minify Options"
|
||||
msgstr ""
|
||||
|
||||
#: wp-minify.php:371
|
||||
msgid "Documentation"
|
||||
msgstr ""
|
||||
|
||||
#: wp-minify.php:418
|
||||
msgid "Error: Could not fetch and cache URL"
|
||||
msgstr ""
|
||||
|
||||
#: wp-minify.php:419
|
||||
msgid "You might need to exclude this file in WP Minify options."
|
||||
msgstr ""
|
||||
|
||||
4
wp-content/plugins/wp-minify/min/.htaccess
Normal file
4
wp-content/plugins/wp-minify/min/.htaccess
Normal file
@ -0,0 +1,4 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine on
|
||||
RewriteRule ^([a-z]=.*) index.php?$1 [L,NE]
|
||||
</IfModule>
|
||||
132
wp-content/plugins/wp-minify/min/README.txt
Normal file
132
wp-content/plugins/wp-minify/min/README.txt
Normal file
@ -0,0 +1,132 @@
|
||||
The files in this directory represent the default Minify setup designed to ease
|
||||
integration with your site. This app will combine and minify your Javascript or
|
||||
CSS files and serve them with HTTP compression and cache headers.
|
||||
|
||||
|
||||
RECOMMENDED
|
||||
|
||||
It's recommended to edit config.php to set $min_cachePath to a writeable
|
||||
(by PHP) directory on your system. This will improve performance.
|
||||
|
||||
|
||||
GETTING STARTED
|
||||
|
||||
The quickest way to get started is to use the Minify URI Builder application
|
||||
on your website: http://example.com/min/builder/
|
||||
|
||||
|
||||
MINIFYING A SINGLE FILE
|
||||
|
||||
Let's say you want to serve this file:
|
||||
http://example.com/wp-content/themes/default/default.css
|
||||
|
||||
Here's the "Minify URL" for this file:
|
||||
http://example.com/min/?f=wp-content/themes/default/default.css
|
||||
|
||||
In other words, the "f" argument is set to the file path from root without the
|
||||
initial "/". As CSS files may contain relative URIs, Minify will automatically
|
||||
"fix" these by rewriting them as root relative.
|
||||
|
||||
|
||||
COMBINING MULTIPLE FILES IN ONE DOWNLOAD
|
||||
|
||||
Separate the paths given to "f" with commas.
|
||||
|
||||
Let's say you have CSS files at these URLs:
|
||||
http://example.com/scripts/jquery-1.2.6.js
|
||||
http://example.com/scripts/site.js
|
||||
|
||||
You can combine these files through Minify by requesting this URL:
|
||||
http://example.com/min/?f=scripts/jquery-1.2.6.js,scripts/site.js
|
||||
|
||||
|
||||
SIMPLIFYING URLS WITH A BASE PATH
|
||||
|
||||
If you're combining files that share the same ancestor directory, you can use
|
||||
the "b" argument to set the base directory for the "f" argument. Do not include
|
||||
the leading or trailing "/" characters.
|
||||
|
||||
E.g., the following URLs will serve the exact same content:
|
||||
http://example.com/min/?f=scripts/jquery-1.2.6.js,scripts/site.js,scripts/home.js
|
||||
http://example.com/min/?b=scripts&f=jquery-1.2.6.js,site.js,home.js
|
||||
|
||||
|
||||
MINIFY URLS IN HTML
|
||||
|
||||
In (X)HTML files, don't forget to replace any "&" characters with "&".
|
||||
|
||||
|
||||
SPECIFYING ALLOWED DIRECTORIES
|
||||
|
||||
By default, Minify will serve any *.css/*.js files within the DOCUMENT_ROOT. If
|
||||
you'd prefer to limit Minify's access to certain directories, set the
|
||||
$min_serveOptions['minApp']['allowDirs'] array in config.php. E.g. to limit
|
||||
to the /js and /themes/default directories, use:
|
||||
|
||||
$min_serveOptions['minApp']['allowDirs'] = array('//js', '//themes/default');
|
||||
|
||||
|
||||
GROUPS: FASTER PERFORMANCE AND BETTER URLS
|
||||
|
||||
For the best performance, edit groupsConfig.php to pre-specify groups of files
|
||||
to be combined under preset keys. E.g., here's an example configuration in
|
||||
groupsConfig.php:
|
||||
|
||||
return array(
|
||||
'js' => array('//js/Class.js', '//js/email.js')
|
||||
);
|
||||
|
||||
This pre-selects the following files to be combined under the key "js":
|
||||
http://example.com/js/Class.js
|
||||
http://example.com/js/email.js
|
||||
|
||||
You can now serve these files with this simple URL:
|
||||
http://example.com/min/?g=js
|
||||
|
||||
|
||||
GROUPS: SPECIFYING FILES OUTSIDE THE DOC_ROOT
|
||||
|
||||
In the groupsConfig.php array, the "//" in the file paths is a shortcut for
|
||||
the DOCUMENT_ROOT, but you can also specify paths from the root of the filesystem
|
||||
or relative to the DOC_ROOT:
|
||||
|
||||
return array(
|
||||
'js' => array(
|
||||
'//js/file.js' // file within DOC_ROOT
|
||||
,'//../file.js' // file in parent directory of DOC_ROOT
|
||||
,'C:/Users/Steve/file.js' // file anywhere on filesystem
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
FAR-FUTURE EXPIRES HEADERS
|
||||
|
||||
Minify can send far-future (one year) Expires headers. To enable this you must
|
||||
add a number to the querystring (e.g. /min/?g=js&1234 or /min/f=file.js&1234)
|
||||
and alter it whenever a source file is changed. If you have a build process you
|
||||
can use a build/source control revision number.
|
||||
|
||||
If you serve files as a group, you can use the utility function Minify_groupUri()
|
||||
to get a "versioned" Minify URI for use in your HTML. E.g.:
|
||||
|
||||
<?php
|
||||
// add /min/lib to your include_path first!
|
||||
require $_SERVER['DOCUMENT_ROOT'] . '/min/utils.php';
|
||||
|
||||
$jsUri = Minify_groupUri('js');
|
||||
echo "<script type='text/javascript' src='{$jsUri}'></script>";
|
||||
|
||||
|
||||
DEBUG MODE
|
||||
|
||||
In debug mode, instead of compressing files, Minify sends combined files with
|
||||
comments prepended to each line to show the line number in the original source
|
||||
file. To enable this, set $min_allowDebugFlag to true in config.php and append
|
||||
"&debug=1" to your URIs. E.g. /min/?f=script1.js,script2.js&debug=1
|
||||
|
||||
Known issue: files with comment-like strings/regexps can cause problems in this mode.
|
||||
|
||||
|
||||
QUESTIONS?
|
||||
|
||||
http://groups.google.com/group/minify
|
||||
242
wp-content/plugins/wp-minify/min/builder/_index.js
Normal file
242
wp-content/plugins/wp-minify/min/builder/_index.js
Normal file
@ -0,0 +1,242 @@
|
||||
var MUB = {
|
||||
_uid : 0
|
||||
,_minRoot : '/min/?'
|
||||
,checkRewrite : function () {
|
||||
var testUri = location.pathname.replace(/\/[^\/]*$/, '/rewriteTest.js').substr(1);
|
||||
function fail() {
|
||||
$('#minRewriteFailed')[0].className = 'topNote';
|
||||
};
|
||||
$.ajax({
|
||||
url : '../f=' + testUri + '&' + (new Date()).getTime()
|
||||
,success : function (data) {
|
||||
if (data === '1') {
|
||||
MUB._minRoot = '/min/';
|
||||
$('span.minRoot').html('/min/');
|
||||
} else
|
||||
fail();
|
||||
}
|
||||
,error : fail
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get markup for new source LI element
|
||||
*/
|
||||
,newLi : function () {
|
||||
return '<li id="li' + MUB._uid + '">http://' + location.host + '/<input type=text size=20>'
|
||||
+ ' <button title="Remove">x</button> <button title="Include Earlier">↑</button>'
|
||||
+ ' <button title="Include Later">↓</button> <span></span></li>';
|
||||
}
|
||||
/**
|
||||
* Add new empty source LI and attach handlers to buttons
|
||||
*/
|
||||
,addLi : function () {
|
||||
$('#sources').append(MUB.newLi());
|
||||
var li = $('#li' + MUB._uid)[0];
|
||||
$('button[title=Remove]', li).click(function () {
|
||||
$('#results').hide();
|
||||
var hadValue = !!$('input', li)[0].value;
|
||||
$(li).remove();
|
||||
});
|
||||
$('button[title$=Earlier]', li).click(function () {
|
||||
$(li).prev('li').find('input').each(function () {
|
||||
$('#results').hide();
|
||||
// this = previous li input
|
||||
var tmp = this.value;
|
||||
this.value = $('input', li).val();
|
||||
$('input', li).val(tmp);
|
||||
MUB.updateAllTestLinks();
|
||||
});
|
||||
});
|
||||
$('button[title$=Later]', li).click(function () {
|
||||
$(li).next('li').find('input').each(function () {
|
||||
$('#results').hide();
|
||||
// this = next li input
|
||||
var tmp = this.value;
|
||||
this.value = $('input', li).val();
|
||||
$('input', li).val(tmp);
|
||||
MUB.updateAllTestLinks();
|
||||
});
|
||||
});
|
||||
++MUB._uid;
|
||||
}
|
||||
/**
|
||||
* In the context of a source LI element, this will analyze the URI in
|
||||
* the INPUT and check the URL on the site.
|
||||
*/
|
||||
,liUpdateTestLink : function () { // call in context of li element
|
||||
if (! $('input', this)[0].value)
|
||||
return;
|
||||
var li = this;
|
||||
$('span', this).html('');
|
||||
var url = 'http://' + location.host + '/'
|
||||
+ $('input', this)[0].value.replace(/^\//, '');
|
||||
$.ajax({
|
||||
url : url
|
||||
,complete : function (xhr, stat) {
|
||||
if ('success' == stat)
|
||||
$('span', li).html('✓');
|
||||
else {
|
||||
$('span', li).html('<button><b>404! </b> recheck</button>')
|
||||
.find('button').click(function () {
|
||||
MUB.liUpdateTestLink.call(li);
|
||||
});
|
||||
}
|
||||
}
|
||||
,dataType : 'text'
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Check all source URLs
|
||||
*/
|
||||
,updateAllTestLinks : function () {
|
||||
$('#sources li').each(MUB.liUpdateTestLink);
|
||||
}
|
||||
/**
|
||||
* In a given array of strings, find the character they all have at
|
||||
* a particular index
|
||||
* @param Array arr array of strings
|
||||
* @param Number pos index to check
|
||||
* @return mixed a common char or '' if any do not match
|
||||
*/
|
||||
,getCommonCharAtPos : function (arr, pos) {
|
||||
var i
|
||||
,l = arr.length
|
||||
,c = arr[0].charAt(pos);
|
||||
if (c === '' || l === 1)
|
||||
return c;
|
||||
for (i = 1; i < l; ++i)
|
||||
if (arr[i].charAt(pos) !== c)
|
||||
return '';
|
||||
return c;
|
||||
}
|
||||
/**
|
||||
* Get the shortest URI to minify the set of source files
|
||||
* @param Array sources URIs
|
||||
*/
|
||||
,getBestUri : function (sources) {
|
||||
var pos = 0
|
||||
,base = ''
|
||||
,c;
|
||||
while (true) {
|
||||
c = MUB.getCommonCharAtPos(sources, pos);
|
||||
if (c === '')
|
||||
break;
|
||||
else
|
||||
base += c;
|
||||
++pos;
|
||||
}
|
||||
base = base.replace(/[^\/]+$/, '');
|
||||
var uri = MUB._minRoot + 'f=' + sources.join(',');
|
||||
if (base.charAt(base.length - 1) === '/') {
|
||||
// we have a base dir!
|
||||
var basedSources = sources
|
||||
,i
|
||||
,l = sources.length;
|
||||
for (i = 0; i < l; ++i) {
|
||||
basedSources[i] = sources[i].substr(base.length);
|
||||
}
|
||||
base = base.substr(0, base.length - 1);
|
||||
var bUri = MUB._minRoot + 'b=' + base + '&f=' + basedSources.join(',');
|
||||
//window.console && console.log([uri, bUri]);
|
||||
uri = uri.length < bUri.length
|
||||
? uri
|
||||
: bUri;
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
/**
|
||||
* Create the Minify URI for the sources
|
||||
*/
|
||||
,update : function () {
|
||||
MUB.updateAllTestLinks();
|
||||
var sources = []
|
||||
,ext = false
|
||||
,fail = false;
|
||||
$('#sources input').each(function () {
|
||||
var m, val;
|
||||
if (! fail && this.value && (m = this.value.match(/\.(css|js)$/))) {
|
||||
var thisExt = m[1];
|
||||
if (ext === false)
|
||||
ext = thisExt;
|
||||
else if (thisExt !== ext) {
|
||||
fail = true;
|
||||
return alert('extensions must match!');
|
||||
}
|
||||
this.value = this.value.replace(/^\//, '');
|
||||
if (-1 != $.inArray(this.value, sources)) {
|
||||
fail = true;
|
||||
return alert('duplicate file!');
|
||||
}
|
||||
sources.push(this.value);
|
||||
}
|
||||
});
|
||||
if (fail || ! sources.length)
|
||||
return;
|
||||
$('#groupConfig').val(" 'keyName' => array('//" + sources.join("', '//") + "'),");
|
||||
var uri = MUB.getBestUri(sources)
|
||||
,uriH = uri.replace(/</, '<').replace(/>/, '>').replace(/&/, '&');
|
||||
$('#uriA').html(uriH)[0].href = uri;
|
||||
$('#uriHtml').val(
|
||||
ext === 'js'
|
||||
? '<script type="text/javascript" src="' + uriH + '"></script>'
|
||||
: '<link type="text/css" rel="stylesheet" href="' + uriH + '" />'
|
||||
);
|
||||
$('#results').show();
|
||||
}
|
||||
/**
|
||||
* Handler for the "Add file +" button
|
||||
*/
|
||||
,addButtonClick : function () {
|
||||
$('#results').hide();
|
||||
MUB.addLi();
|
||||
MUB.updateAllTestLinks();
|
||||
$('#update').show().click(MUB.update);
|
||||
$('#sources li:last input')[0].focus();
|
||||
}
|
||||
/**
|
||||
* Runs on DOMready
|
||||
*/
|
||||
,init : function () {
|
||||
$('#app').show();
|
||||
$('#sources').html('');
|
||||
$('#add button').click(MUB.addButtonClick);
|
||||
// make easier to copy text out of
|
||||
$('#uriHtml, #groupConfig').click(function () {
|
||||
this.select();
|
||||
}).focus(function () {
|
||||
this.select();
|
||||
});
|
||||
$('a.ext').attr({target:'_blank'});
|
||||
if (location.hash) {
|
||||
// make links out of URIs from bookmarklet
|
||||
$('#getBm').hide();
|
||||
$('#bmUris').html('<p><strong>Found by bookmarklet:</strong> /<a href=#>'
|
||||
+ location.hash.substr(1).split(',').join('</a> | /<a href=#>')
|
||||
+ '</a></p>'
|
||||
);
|
||||
$('#bmUris a').click(function () {
|
||||
MUB.addButtonClick();
|
||||
$('#sources li:last input').val(this.innerHTML)
|
||||
MUB.liUpdateTestLink.call($('#sources li:last')[0]);
|
||||
$('#results').hide();
|
||||
return false;
|
||||
}).attr({title:'Add file +'});
|
||||
} else {
|
||||
// copy bookmarklet code into href
|
||||
var bmUri = location.pathname.replace(/\/[^\/]*$/, '/bm.js').substr(1);
|
||||
$.ajax({
|
||||
url : '../?f=' + bmUri
|
||||
,success : function (code) {
|
||||
$('#bm')[0].href = code
|
||||
.replace('%BUILDER_URL%', location.href)
|
||||
.replace(/\n/g, ' ');
|
||||
}
|
||||
,dataType : 'text'
|
||||
});
|
||||
$.browser.msie && $('#getBm p:last').append(' Sorry, not supported in MSIE!');
|
||||
MUB.addButtonClick();
|
||||
}
|
||||
MUB.checkRewrite();
|
||||
}
|
||||
};
|
||||
window.onload = MUB.init;
|
||||
36
wp-content/plugins/wp-minify/min/builder/bm.js
Normal file
36
wp-content/plugins/wp-minify/min/builder/bm.js
Normal file
@ -0,0 +1,36 @@
|
||||
javascript:(function() {
|
||||
var d = document
|
||||
,uris = []
|
||||
,i = 0
|
||||
,o
|
||||
,home = (location + '').split('/').splice(0, 3).join('/') + '/';
|
||||
function add(uri) {
|
||||
return (0 === uri.indexOf(home))
|
||||
&& (!/[\?&]/.test(uri))
|
||||
&& uris.push(escape(uri.substr(home.length)));
|
||||
};
|
||||
function sheet(ss) {
|
||||
// we must check the domain with add() before accessing ss.cssRules
|
||||
// otherwise a security exception will be thrown
|
||||
if (ss.href && add(ss.href) && ss.cssRules) {
|
||||
var i = 0, r;
|
||||
while (r = ss.cssRules[i++])
|
||||
r.styleSheet && sheet(r.styleSheet);
|
||||
}
|
||||
};
|
||||
while (o = d.getElementsByTagName('script')[i++])
|
||||
o.src && !(o.type && /vbs/i.test(o.type)) && add(o.src);
|
||||
i = 0;
|
||||
while (o = d.styleSheets[i++])
|
||||
/* http://www.w3.org/TR/DOM-Level-2-Style/stylesheets.html#StyleSheets-DocumentStyle-styleSheets
|
||||
document.styleSheet is a list property where [0] accesses the 1st element and
|
||||
[outOfRange] returns null. In IE, styleSheets is a function, and also throws an
|
||||
exception when you check the out of bounds index. (sigh) */
|
||||
sheet(o);
|
||||
if (uris.length)
|
||||
window.open('%BUILDER_URL%#' + uris.join(','));
|
||||
else
|
||||
alert('No js/css files found with URLs within "'
|
||||
+ home.split('/')[2]
|
||||
+ '".\n(This tool is limited to URLs with the same domain.)');
|
||||
})();
|
||||
182
wp-content/plugins/wp-minify/min/builder/index.php
Normal file
182
wp-content/plugins/wp-minify/min/builder/index.php
Normal file
@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
if (phpversion() < 5) {
|
||||
exit('Minify requires PHP5 or greater.');
|
||||
}
|
||||
|
||||
// check for auto-encoding
|
||||
$encodeOutput = (function_exists('gzdeflate')
|
||||
&& !ini_get('zlib.output_compression'));
|
||||
|
||||
require dirname(__FILE__) . '/../config.php';
|
||||
|
||||
if (! $min_enableBuilder) {
|
||||
header('Location: /');
|
||||
exit();
|
||||
}
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<head>
|
||||
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
|
||||
<title>Minify URI Builder</title>
|
||||
<style type="text/css">
|
||||
body {margin:1em 60px;}
|
||||
h1, h2, h3 {margin-left:-25px; position:relative;}
|
||||
h1 {margin-top:0;}
|
||||
#sources {margin:0; padding:0;}
|
||||
#sources li {margin:0 0 0 40px}
|
||||
#sources li input {margin-left:2px}
|
||||
#add {margin:5px 0 1em 40px}
|
||||
.hide {display:none}
|
||||
#uriTable {border-collapse:collapse;}
|
||||
#uriTable td, #uriTable th {padding-top:10px;}
|
||||
#uriTable th {padding-right:10px;}
|
||||
#groupConfig {font-family:monospace;}
|
||||
b {color:#c00}
|
||||
.topNote {background: #ff9; display:inline-block; padding:.5em .6em; margin:0 0 1em;}
|
||||
.topWarning {background:#c00; color:#fff; padding:.5em .6em; margin:0 0 1em;}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<?php if (! isset($min_cachePath)): ?>
|
||||
<p class=topNote><strong>Note:</strong> Please set <code>$min_cachePath</code>
|
||||
in /min/config.php to improve performance.</p>
|
||||
<?php endIf; ?>
|
||||
|
||||
<p id=minRewriteFailed class="hide"><strong>Note:</strong> Your webserver does not seem to
|
||||
support mod_rewrite (used in /min/.htaccess). Your Minify URIs will contain "?", which
|
||||
<a href="http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/"
|
||||
>may reduce the benefit of proxy cache servers</a>.</p>
|
||||
|
||||
<h1>Minify URI Builder</h1>
|
||||
|
||||
<noscript><p class="topNote">Javascript and a browser supported by jQuery 1.2.6 is required
|
||||
for this application.</p></noscript>
|
||||
|
||||
<div id=app class=hide>
|
||||
|
||||
<p>Create a list of Javascript or CSS files (or 1 is fine) you'd like to combine
|
||||
and click [Update].</p>
|
||||
|
||||
<ol id=sources><li></li></ol>
|
||||
<div id=add><button>Add file +</button></div>
|
||||
|
||||
<div id=bmUris></div>
|
||||
|
||||
<p><button id=update class=hide>Update</button></p>
|
||||
|
||||
<div id=results class=hide>
|
||||
|
||||
<h2>Minify URI</h2>
|
||||
<p>Place this URI in your HTML to serve the files above combined, minified, compressed and
|
||||
with cache headers.</p>
|
||||
<table id=uriTable>
|
||||
<tr><th>URI</th><td><a id=uriA class=ext>/min</a> <small>(opens in new window)</small></td></tr>
|
||||
<tr><th>HTML</th><td><input id=uriHtml type=text size=100 readonly></td></tr>
|
||||
</table>
|
||||
|
||||
<h2>How to serve these files as a group</h2>
|
||||
<p>For the best performance you can serve these files as a pre-defined group with a URI
|
||||
like: <code><span class=minRoot>/min/?</span>g=keyName</code></p>
|
||||
<p>To do this, add a line like this to /min/groupsConfig.php:</p>
|
||||
|
||||
<pre><code>return array(
|
||||
<span style="color:#666">... your existing groups here ...</span>
|
||||
<input id=groupConfig size=100 type=text readonly>
|
||||
);</code></pre>
|
||||
|
||||
<p><em>Make sure to replace <code>keyName</code> with a unique key for this group.</em></p>
|
||||
</div>
|
||||
|
||||
<div id=getBm>
|
||||
<h3>Find URIs on a Page</h3>
|
||||
<p>You can use the bookmarklet below to fetch all CSS & Javascript URIs from a page
|
||||
on your site. When you active it, this page will open in a new window with a list of
|
||||
available URIs to add.</p>
|
||||
|
||||
<p><a id=bm>Create Minify URIs</a> <small>(right-click, add to bookmarks)</small></p>
|
||||
</div>
|
||||
|
||||
<h3>Combining CSS files that contain <code>@import</code></h3>
|
||||
<p>If your CSS files contain <code>@import</code> declarations, Minify will not
|
||||
remove them. Therefore, you will want to remove those that point to files already
|
||||
in your list, and move any others to the top of the first file in your list
|
||||
(imports below any styles will be ignored by browsers as invalid).</p>
|
||||
<p>If you desire, you can use Minify URIs in imports and they will not be touched
|
||||
by Minify. E.g. <code>@import "<span class=minRoot>/min/?</span>g=css2";</code></p>
|
||||
|
||||
</div><!-- #app -->
|
||||
|
||||
<hr>
|
||||
<p>Need help? Search or post to the <a class=ext
|
||||
href="http://groups.google.com/group/minify">Minify discussion list</a>.</p>
|
||||
<p><small>This app is minified :) <a class=ext
|
||||
href="http://code.google.com/p/minify/source/browse/trunk/min/builder/index.php">view
|
||||
source</a></small></p>
|
||||
|
||||
<script type="text/javascript"
|
||||
src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
// detection of double output encoding
|
||||
var msg = '<\p class=topWarning><\strong>Warning:<\/strong> ';
|
||||
var url = 'ocCheck.php?' + (new Date()).getTime();
|
||||
$.get(url, function (ocStatus) {
|
||||
$.get(url + '&hello=1', function (ocHello) {
|
||||
if (ocHello != 'World!') {
|
||||
msg += 'It appears output is being automatically compressed, interfering '
|
||||
+ ' with Minify\'s own compression. ';
|
||||
if (ocStatus == '1')
|
||||
msg += 'The option "zlib.output_compression" is enabled in your PHP configuration. '
|
||||
+ 'Minify set this to "0", but it had no effect. This option must be disabled '
|
||||
+ 'in php.ini or .htaccess.';
|
||||
else
|
||||
msg += 'The option "zlib.output_compression" is disabled in your PHP configuration '
|
||||
+ 'so this behavior is likely due to a server option.';
|
||||
$(document.body).prepend(msg + '<\/p>');
|
||||
} else
|
||||
if (ocStatus == '1')
|
||||
$(document.body).prepend('<\p class=topNote><\strong>Note:</\strong> The option '
|
||||
+ '"zlib.output_compression" is enabled in your PHP configuration, but has been '
|
||||
+ 'successfully disabled via ini_set(). If you experience mangled output you '
|
||||
+ 'may want to consider disabling this option in your PHP configuration.<\/p>'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
// workaround required to test when /min isn't child of web root
|
||||
var src = location.pathname.replace(/\/[^\/]*$/, '/_index.js').substr(1);
|
||||
document.write('<\script type="text/javascript" src="../?f=' + src + '"><\/script>');
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
$serveOpts = array(
|
||||
'content' => ob_get_contents()
|
||||
,'id' => __FILE__
|
||||
,'lastModifiedTime' => max(
|
||||
// regenerate cache if either of these change
|
||||
filemtime(__FILE__)
|
||||
,filemtime(dirname(__FILE__) . '/../config.php')
|
||||
)
|
||||
,'minifyAll' => true
|
||||
,'encodeOutput' => $encodeOutput
|
||||
);
|
||||
ob_end_clean();
|
||||
|
||||
set_include_path(dirname(__FILE__) . '/../lib' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
require 'Minify.php';
|
||||
|
||||
if (0 === stripos(PHP_OS, 'win')) {
|
||||
Minify::setDocRoot(); // we may be on IIS
|
||||
}
|
||||
Minify::setCache(isset($min_cachePath) ? $min_cachePath : null);
|
||||
Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
|
||||
|
||||
Minify::serve('Page', $serveOpts);
|
||||
36
wp-content/plugins/wp-minify/min/builder/ocCheck.php
Normal file
36
wp-content/plugins/wp-minify/min/builder/ocCheck.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* AJAX checks for zlib.output_compression
|
||||
*
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
$_oc = ini_get('zlib.output_compression');
|
||||
|
||||
// allow access only if builder is enabled
|
||||
require dirname(__FILE__) . '/../config.php';
|
||||
if (! $min_enableBuilder) {
|
||||
header('Location: /');
|
||||
exit();
|
||||
}
|
||||
|
||||
if (isset($_GET['hello'])) {
|
||||
// echo 'World!'
|
||||
|
||||
// try to prevent double encoding (may not have an effect)
|
||||
ini_set('zlib.output_compression', '0');
|
||||
|
||||
require $min_libPath . '/HTTP/Encoder.php';
|
||||
HTTP_Encoder::$encodeToIe6 = true; // just in case
|
||||
$he = new HTTP_Encoder(array(
|
||||
'content' => 'World!'
|
||||
,'method' => 'deflate'
|
||||
));
|
||||
$he->encode();
|
||||
$he->sendAll();
|
||||
|
||||
} else {
|
||||
// echo status "0" or "1"
|
||||
header('Content-Type: text/plain');
|
||||
echo (int)$_oc;
|
||||
}
|
||||
1
wp-content/plugins/wp-minify/min/builder/rewriteTest.js
Normal file
1
wp-content/plugins/wp-minify/min/builder/rewriteTest.js
Normal file
@ -0,0 +1 @@
|
||||
1
|
||||
165
wp-content/plugins/wp-minify/min/config.php
Normal file
165
wp-content/plugins/wp-minify/min/config.php
Normal file
@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* Configuration for default Minify application
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* In 'debug' mode, Minify can combine files with no minification and
|
||||
* add comments to indicate line #s of the original files.
|
||||
*
|
||||
* To allow debugging, set this option to true and add "&debug=1" to
|
||||
* a URI. E.g. /min/?f=script1.js,script2.js&debug=1
|
||||
*/
|
||||
$min_allowDebugFlag = false;
|
||||
//###WPM-DEBUG-FLAG-BEFORE###
|
||||
$min_allowDebugFlag = false;
|
||||
//###WPM-DEBUG-FLAG-AFTER###
|
||||
|
||||
|
||||
/**
|
||||
* Set to true to log messages to FirePHP (Firefox Firebug addon).
|
||||
* Set to false for no error logging (Minify may be slightly faster).
|
||||
* @link http://www.firephp.org/
|
||||
*
|
||||
* If you want to use a custom error logger, set this to your logger
|
||||
* instance. Your object should have a method log(string $message).
|
||||
*
|
||||
* @todo cache system does not have error logging yet.
|
||||
*/
|
||||
$min_errorLogger = false;
|
||||
//###WPM-ERROR-LOGGER-BEFORE###
|
||||
$min_errorLogger = false;
|
||||
//###WPM-ERROR-LOGGER-AFTER###
|
||||
|
||||
|
||||
/**
|
||||
* Allow use of the Minify URI Builder app. If you no longer need
|
||||
* this, set to false.
|
||||
**/
|
||||
$min_enableBuilder = false;
|
||||
|
||||
|
||||
/**
|
||||
* For best performance, specify your temp directory here. Otherwise Minify
|
||||
* will have to load extra code to guess. Some examples below:
|
||||
*/
|
||||
//$min_cachePath = 'c:\\WINDOWS\\Temp';
|
||||
//$min_cachePath = '/tmp';
|
||||
//$min_cachePath = preg_replace('/^\\d+;/', '', session_save_path());
|
||||
//###WPM-CACHE-PATH-BEFORE###
|
||||
$min_cachePath = 'D:\Trabajo\Asong2u\WP\InstantWP_4.2\iwpserver\htdocs\wordpress/wp-content/plugins/wp-minify/cache/';
|
||||
//###WPM-CACHE-PATH-AFTER###
|
||||
|
||||
/**
|
||||
* Leave an empty string to use PHP's $_SERVER['DOCUMENT_ROOT'].
|
||||
*
|
||||
* On some servers, this value may be misconfigured or missing. If so, set this
|
||||
* to your full document root path with no trailing slash.
|
||||
* E.g. '/home/accountname/public_html' or 'c:\\xampp\\htdocs'
|
||||
*
|
||||
* If /min/ is directly inside your document root, just uncomment the
|
||||
* second line. The third line might work on some Apache servers.
|
||||
*/
|
||||
$min_documentRoot = '';
|
||||
//$min_documentRoot = substr(__FILE__, 0, strlen(__FILE__) - 15);
|
||||
//$min_documentRoot = $_SERVER['SUBDOMAIN_DOCUMENT_ROOT'];
|
||||
|
||||
|
||||
/**
|
||||
* Cache file locking. Set to false if filesystem is NFS. On at least one
|
||||
* NFS system flock-ing attempts stalled PHP for 30 seconds!
|
||||
*/
|
||||
$min_cacheFileLocking = true;
|
||||
|
||||
|
||||
/**
|
||||
* Combining multiple CSS files can place @import declarations after rules, which
|
||||
* is invalid. Minify will attempt to detect when this happens and place a
|
||||
* warning comment at the top of the CSS output. To resolve this you can either
|
||||
* move the @imports within your CSS files, or enable this option, which will
|
||||
* move all @imports to the top of the output. Note that moving @imports could
|
||||
* affect CSS values (which is why this option is disabled by default).
|
||||
*/
|
||||
$min_serveOptions['bubbleCssImports'] = false;
|
||||
|
||||
|
||||
/**
|
||||
* Maximum age of browser cache in seconds. After this period, the browser
|
||||
* will send another conditional GET. Use a longer period for lower traffic
|
||||
* but you may want to shorten this before making changes if it's crucial
|
||||
* those changes are seen immediately.
|
||||
*
|
||||
* Note: Despite this setting, if you include a number at the end of the
|
||||
* querystring, maxAge will be set to one year. E.g. /min/f=hello.css&123456
|
||||
*/
|
||||
$min_serveOptions['maxAge'] = 1800;
|
||||
//###WPM-CACHE-AGE-BEFORE###
|
||||
$min_serveOptions['maxAge'] = 2592000;
|
||||
//###WPM-CACHE-AGE-AFTER###
|
||||
|
||||
/**
|
||||
* If you'd like to restrict the "f" option to files within/below
|
||||
* particular directories below DOCUMENT_ROOT, set this here.
|
||||
* You will still need to include the directory in the
|
||||
* f or b GET parameters.
|
||||
*
|
||||
* // = shortcut for DOCUMENT_ROOT
|
||||
*/
|
||||
//$min_serveOptions['minApp']['allowDirs'] = array('//js', '//css');
|
||||
|
||||
/**
|
||||
* Set to true to disable the "f" GET parameter for specifying files.
|
||||
* Only the "g" parameter will be considered.
|
||||
*/
|
||||
$min_serveOptions['minApp']['groupsOnly'] = false;
|
||||
|
||||
/**
|
||||
* Maximum # of files that can be specified in the "f" GET parameter
|
||||
*/
|
||||
$min_serveOptions['minApp']['maxFiles'] = 50;
|
||||
|
||||
|
||||
/**
|
||||
* If you minify CSS files stored in symlink-ed directories, the URI rewriting
|
||||
* algorithm can fail. To prevent this, provide an array of link paths to
|
||||
* target paths, where the link paths are within the document root.
|
||||
*
|
||||
* Because paths need to be normalized for this to work, use "//" to substitute
|
||||
* the doc root in the link paths (the array keys). E.g.:
|
||||
* <code>
|
||||
* array('//symlink' => '/real/target/path') // unix
|
||||
* array('//static' => 'D:\\staticStorage') // Windows
|
||||
* </code>
|
||||
*/
|
||||
$min_symlinks = array();
|
||||
|
||||
|
||||
/**
|
||||
* If you upload files from Windows to a non-Windows server, Windows may report
|
||||
* incorrect mtimes for the files. This may cause Minify to keep serving stale
|
||||
* cache files when source file changes are made too frequently (e.g. more than
|
||||
* once an hour).
|
||||
*
|
||||
* Immediately after modifying and uploading a file, use the touch command to
|
||||
* update the mtime on the server. If the mtime jumps ahead by a number of hours,
|
||||
* set this variable to that number. If the mtime moves back, this should not be
|
||||
* needed.
|
||||
*
|
||||
* In the Windows SFTP client WinSCP, there's an option that may fix this
|
||||
* issue without changing the variable below. Under login > environment,
|
||||
* select the option "Adjust remote timestamp with DST".
|
||||
* @link http://winscp.net/eng/docs/ui_login_environment#daylight_saving_time
|
||||
*/
|
||||
$min_uploaderHoursBehind = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Path to Minify's lib folder. If you happen to move it, change
|
||||
* this accordingly.
|
||||
*/
|
||||
$min_libPath = dirname(__FILE__) . '/lib';
|
||||
|
||||
|
||||
// try to disable output_compression (may not ha
|
||||
34
wp-content/plugins/wp-minify/min/groupsConfig.php
Normal file
34
wp-content/plugins/wp-minify/min/groupsConfig.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Groups configuration for default Minify implementation
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* You may wish to use the Minify URI Builder app to suggest
|
||||
* changes. http://yourdomain/min/builder/
|
||||
**/
|
||||
|
||||
return array(
|
||||
// 'js' => array('//js/file1.js', '//js/file2.js'),
|
||||
// 'css' => array('//css/file1.css', '//css/file2.css'),
|
||||
|
||||
// custom source example
|
||||
/*'js2' => array(
|
||||
dirname(__FILE__) . '/../min_unit_tests/_test_files/js/before.js',
|
||||
// do NOT process this file
|
||||
new Minify_Source(array(
|
||||
'filepath' => dirname(__FILE__) . '/../min_unit_tests/_test_files/js/before.js',
|
||||
'minifier' => create_function('$a', 'return $a;')
|
||||
))
|
||||
),//*/
|
||||
|
||||
/*'js3' => array(
|
||||
dirname(__FILE__) . '/../min_unit_tests/_test_files/js/before.js',
|
||||
// do NOT process this file
|
||||
new Minify_Source(array(
|
||||
'filepath' => dirname(__FILE__) . '/../min_unit_tests/_test_files/js/before.js',
|
||||
'minifier' => array('Minify_Packer', 'minify')
|
||||
))
|
||||
),//*/
|
||||
);
|
||||
66
wp-content/plugins/wp-minify/min/index.php
Normal file
66
wp-content/plugins/wp-minify/min/index.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Front controller for default Minify implementation
|
||||
*
|
||||
* DO NOT EDIT! Configure this utility via config.php and groupsConfig.php
|
||||
*
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
define('MINIFY_MIN_DIR', dirname(__FILE__));
|
||||
|
||||
// load config
|
||||
require MINIFY_MIN_DIR . '/config.php';
|
||||
|
||||
// setup include path
|
||||
set_include_path($min_libPath . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
require 'Minify.php';
|
||||
|
||||
Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
|
||||
Minify::setCache(
|
||||
isset($min_cachePath) ? $min_cachePath : ''
|
||||
,$min_cacheFileLocking
|
||||
);
|
||||
|
||||
if ($min_documentRoot) {
|
||||
$_SERVER['DOCUMENT_ROOT'] = $min_documentRoot;
|
||||
} elseif (0 === stripos(PHP_OS, 'win')) {
|
||||
Minify::setDocRoot(); // IIS may need help
|
||||
}
|
||||
|
||||
$min_serveOptions['minifierOptions']['text/css']['symlinks'] = $min_symlinks;
|
||||
|
||||
if ($min_allowDebugFlag && isset($_GET['debug'])) {
|
||||
$min_serveOptions['debug'] = true;
|
||||
}
|
||||
|
||||
if ($min_errorLogger) {
|
||||
require_once 'Minify/Logger.php';
|
||||
if (true === $min_errorLogger) {
|
||||
require_once 'FirePHP.php';
|
||||
Minify_Logger::setLogger(FirePHP::getInstance(true));
|
||||
} else {
|
||||
Minify_Logger::setLogger($min_errorLogger);
|
||||
}
|
||||
}
|
||||
|
||||
// check for URI versioning
|
||||
if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) {
|
||||
$min_serveOptions['maxAge'] = 31536000;
|
||||
}
|
||||
if (isset($_GET['g'])) {
|
||||
// well need groups config
|
||||
$min_serveOptions['minApp']['groups'] = (require MINIFY_MIN_DIR . '/groupsConfig.php');
|
||||
}
|
||||
if (isset($_GET['f']) || isset($_GET['g'])) {
|
||||
// serve!
|
||||
Minify::serve('MinApp', $min_serveOptions);
|
||||
|
||||
} elseif ($min_enableBuilder) {
|
||||
header('Location: builder/');
|
||||
exit();
|
||||
} else {
|
||||
header("Location: /");
|
||||
exit();
|
||||
}
|
||||
1370
wp-content/plugins/wp-minify/min/lib/FirePHP.php
Normal file
1370
wp-content/plugins/wp-minify/min/lib/FirePHP.php
Normal file
File diff suppressed because it is too large
Load Diff
348
wp-content/plugins/wp-minify/min/lib/HTTP/ConditionalGet.php
Normal file
348
wp-content/plugins/wp-minify/min/lib/HTTP/ConditionalGet.php
Normal file
@ -0,0 +1,348 @@
|
||||
<?php
|
||||
/**
|
||||
* Class HTTP_ConditionalGet
|
||||
* @package Minify
|
||||
* @subpackage HTTP
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implement conditional GET via a timestamp or hash of content
|
||||
*
|
||||
* E.g. Content from DB with update time:
|
||||
* <code>
|
||||
* list($updateTime, $content) = getDbUpdateAndContent();
|
||||
* $cg = new HTTP_ConditionalGet(array(
|
||||
* 'lastModifiedTime' => $updateTime
|
||||
* ,'isPublic' => true
|
||||
* ));
|
||||
* $cg->sendHeaders();
|
||||
* if ($cg->cacheIsValid) {
|
||||
* exit();
|
||||
* }
|
||||
* echo $content;
|
||||
* </code>
|
||||
*
|
||||
* E.g. Shortcut for the above
|
||||
* <code>
|
||||
* HTTP_ConditionalGet::check($updateTime, true); // exits if client has cache
|
||||
* echo $content;
|
||||
* </code>
|
||||
*
|
||||
* E.g. Content from DB with no update time:
|
||||
* <code>
|
||||
* $content = getContentFromDB();
|
||||
* $cg = new HTTP_ConditionalGet(array(
|
||||
* 'contentHash' => md5($content)
|
||||
* ));
|
||||
* $cg->sendHeaders();
|
||||
* if ($cg->cacheIsValid) {
|
||||
* exit();
|
||||
* }
|
||||
* echo $content;
|
||||
* </code>
|
||||
*
|
||||
* E.g. Static content with some static includes:
|
||||
* <code>
|
||||
* // before content
|
||||
* $cg = new HTTP_ConditionalGet(array(
|
||||
* 'lastUpdateTime' => max(
|
||||
* filemtime(__FILE__)
|
||||
* ,filemtime('/path/to/header.inc')
|
||||
* ,filemtime('/path/to/footer.inc')
|
||||
* )
|
||||
* ));
|
||||
* $cg->sendHeaders();
|
||||
* if ($cg->cacheIsValid) {
|
||||
* exit();
|
||||
* }
|
||||
* </code>
|
||||
* @package Minify
|
||||
* @subpackage HTTP
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class HTTP_ConditionalGet {
|
||||
|
||||
/**
|
||||
* Does the client have a valid copy of the requested resource?
|
||||
*
|
||||
* You'll want to check this after instantiating the object. If true, do
|
||||
* not send content, just call sendHeaders() if you haven't already.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $cacheIsValid = null;
|
||||
|
||||
/**
|
||||
* @param array $spec options
|
||||
*
|
||||
* 'isPublic': (bool) if true, the Cache-Control header will contain
|
||||
* "public", allowing proxies to cache the content. Otherwise "private" will
|
||||
* be sent, allowing only browser caching. (default false)
|
||||
*
|
||||
* 'lastModifiedTime': (int) if given, both ETag AND Last-Modified headers
|
||||
* will be sent with content. This is recommended.
|
||||
*
|
||||
* 'encoding': (string) if set, the header "Vary: Accept-Encoding" will
|
||||
* always be sent and a truncated version of the encoding will be appended
|
||||
* to the ETag. E.g. "pub123456;gz". This will also trigger a more lenient
|
||||
* checking of the client's If-None-Match header, as the encoding portion of
|
||||
* the ETag will be stripped before comparison.
|
||||
*
|
||||
* 'contentHash': (string) if given, only the ETag header can be sent with
|
||||
* content (only HTTP1.1 clients can conditionally GET). The given string
|
||||
* should be short with no quote characters and always change when the
|
||||
* resource changes (recommend md5()). This is not needed/used if
|
||||
* lastModifiedTime is given.
|
||||
*
|
||||
* 'eTag': (string) if given, this will be used as the ETag header rather
|
||||
* than values based on lastModifiedTime or contentHash. Also the encoding
|
||||
* string will not be appended to the given value as described above.
|
||||
*
|
||||
* 'invalidate': (bool) if true, the client cache will be considered invalid
|
||||
* without testing. Effectively this disables conditional GET.
|
||||
* (default false)
|
||||
*
|
||||
* 'maxAge': (int) if given, this will set the Cache-Control max-age in
|
||||
* seconds, and also set the Expires header to the equivalent GMT date.
|
||||
* After the max-age period has passed, the browser will again send a
|
||||
* conditional GET to revalidate its cache.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function __construct($spec)
|
||||
{
|
||||
$scope = (isset($spec['isPublic']) && $spec['isPublic'])
|
||||
? 'public'
|
||||
: 'private';
|
||||
$maxAge = 0;
|
||||
// backwards compatibility (can be removed later)
|
||||
if (isset($spec['setExpires'])
|
||||
&& is_numeric($spec['setExpires'])
|
||||
&& ! isset($spec['maxAge'])) {
|
||||
$spec['maxAge'] = $spec['setExpires'] - $_SERVER['REQUEST_TIME'];
|
||||
}
|
||||
if (isset($spec['maxAge'])) {
|
||||
$maxAge = $spec['maxAge'];
|
||||
$this->_headers['Expires'] = self::gmtDate(
|
||||
$_SERVER['REQUEST_TIME'] + $spec['maxAge']
|
||||
);
|
||||
}
|
||||
$etagAppend = '';
|
||||
if (isset($spec['encoding'])) {
|
||||
$this->_stripEtag = true;
|
||||
$this->_headers['Vary'] = 'Accept-Encoding';
|
||||
if ('' !== $spec['encoding']) {
|
||||
if (0 === strpos($spec['encoding'], 'x-')) {
|
||||
$spec['encoding'] = substr($spec['encoding'], 2);
|
||||
}
|
||||
$etagAppend = ';' . substr($spec['encoding'], 0, 2);
|
||||
}
|
||||
}
|
||||
if (isset($spec['lastModifiedTime'])) {
|
||||
$this->_setLastModified($spec['lastModifiedTime']);
|
||||
if (isset($spec['eTag'])) { // Use it
|
||||
$this->_setEtag($spec['eTag'], $scope);
|
||||
} else { // base both headers on time
|
||||
$this->_setEtag($spec['lastModifiedTime'] . $etagAppend, $scope);
|
||||
}
|
||||
} elseif (isset($spec['eTag'])) { // Use it
|
||||
$this->_setEtag($spec['eTag'], $scope);
|
||||
} elseif (isset($spec['contentHash'])) { // Use the hash as the ETag
|
||||
$this->_setEtag($spec['contentHash'] . $etagAppend, $scope);
|
||||
}
|
||||
$this->_headers['Cache-Control'] = "max-age={$maxAge}, {$scope}";
|
||||
// invalidate cache if disabled, otherwise check
|
||||
$this->cacheIsValid = (isset($spec['invalidate']) && $spec['invalidate'])
|
||||
? false
|
||||
: $this->_isCacheValid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get array of output headers to be sent
|
||||
*
|
||||
* In the case of 304 responses, this array will only contain the response
|
||||
* code header: array('_responseCode' => 'HTTP/1.0 304 Not Modified')
|
||||
*
|
||||
* Otherwise something like:
|
||||
* <code>
|
||||
* array(
|
||||
* 'Cache-Control' => 'max-age=0, public'
|
||||
* ,'ETag' => '"foobar"'
|
||||
* )
|
||||
* </code>
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->_headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Content-Length header in bytes
|
||||
*
|
||||
* With most PHP configs, as long as you don't flush() output, this method
|
||||
* is not needed and PHP will buffer all output and set Content-Length for
|
||||
* you. Otherwise you'll want to call this to let the client know up front.
|
||||
*
|
||||
* @param int $bytes
|
||||
*
|
||||
* @return int copy of input $bytes
|
||||
*/
|
||||
public function setContentLength($bytes)
|
||||
{
|
||||
return $this->_headers['Content-Length'] = $bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send headers
|
||||
*
|
||||
* @see getHeaders()
|
||||
*
|
||||
* Note this doesn't "clear" the headers. Calling sendHeaders() will
|
||||
* call header() again (but probably have not effect) and getHeaders() will
|
||||
* still return the headers.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function sendHeaders()
|
||||
{
|
||||
$headers = $this->_headers;
|
||||
if (array_key_exists('_responseCode', $headers)) {
|
||||
header($headers['_responseCode']);
|
||||
unset($headers['_responseCode']);
|
||||
}
|
||||
foreach ($headers as $name => $val) {
|
||||
header($name . ': ' . $val);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit if the client's cache is valid for this resource
|
||||
*
|
||||
* This is a convenience method for common use of the class
|
||||
*
|
||||
* @param int $lastModifiedTime if given, both ETag AND Last-Modified headers
|
||||
* will be sent with content. This is recommended.
|
||||
*
|
||||
* @param bool $isPublic (default false) if true, the Cache-Control header
|
||||
* will contain "public", allowing proxies to cache the content. Otherwise
|
||||
* "private" will be sent, allowing only browser caching.
|
||||
*
|
||||
* @param array $options (default empty) additional options for constructor
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public static function check($lastModifiedTime = null, $isPublic = false, $options = array())
|
||||
{
|
||||
if (null !== $lastModifiedTime) {
|
||||
$options['lastModifiedTime'] = (int)$lastModifiedTime;
|
||||
}
|
||||
$options['isPublic'] = (bool)$isPublic;
|
||||
$cg = new HTTP_ConditionalGet($options);
|
||||
$cg->sendHeaders();
|
||||
if ($cg->cacheIsValid) {
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a GMT formatted date for use in HTTP headers
|
||||
*
|
||||
* <code>
|
||||
* header('Expires: ' . HTTP_ConditionalGet::gmtdate($time));
|
||||
* </code>
|
||||
*
|
||||
* @param int $time unix timestamp
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function gmtDate($time)
|
||||
{
|
||||
return gmdate('D, d M Y H:i:s \G\M\T', $time);
|
||||
}
|
||||
|
||||
protected $_headers = array();
|
||||
protected $_lmTime = null;
|
||||
protected $_etag = null;
|
||||
protected $_stripEtag = false;
|
||||
|
||||
protected function _setEtag($hash, $scope)
|
||||
{
|
||||
$this->_etag = '"' . substr($scope, 0, 3) . $hash . '"';
|
||||
$this->_headers['ETag'] = $this->_etag;
|
||||
}
|
||||
|
||||
protected function _setLastModified($time)
|
||||
{
|
||||
$this->_lmTime = (int)$time;
|
||||
$this->_headers['Last-Modified'] = self::gmtDate($time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine validity of client cache and queue 304 header if valid
|
||||
*/
|
||||
protected function _isCacheValid()
|
||||
{
|
||||
if (null === $this->_etag) {
|
||||
// lmTime is copied to ETag, so this condition implies that the
|
||||
// server sent neither ETag nor Last-Modified, so the client can't
|
||||
// possibly has a valid cache.
|
||||
return false;
|
||||
}
|
||||
$isValid = ($this->resourceMatchedEtag() || $this->resourceNotModified());
|
||||
if ($isValid) {
|
||||
$this->_headers['_responseCode'] = 'HTTP/1.0 304 Not Modified';
|
||||
}
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
protected function resourceMatchedEtag()
|
||||
{
|
||||
if (!isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
|
||||
return false;
|
||||
}
|
||||
$clientEtagList = get_magic_quotes_gpc()
|
||||
? stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])
|
||||
: $_SERVER['HTTP_IF_NONE_MATCH'];
|
||||
$clientEtags = explode(',', $clientEtagList);
|
||||
|
||||
$compareTo = $this->normalizeEtag($this->_etag);
|
||||
foreach ($clientEtags as $clientEtag) {
|
||||
if ($this->normalizeEtag($clientEtag) === $compareTo) {
|
||||
// respond with the client's matched ETag, even if it's not what
|
||||
// we would've sent by default
|
||||
$this->_headers['ETag'] = trim($clientEtag);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function normalizeEtag($etag) {
|
||||
$etag = trim($etag);
|
||||
return $this->_stripEtag
|
||||
? preg_replace('/;\\w\\w"$/', '"', $etag)
|
||||
: $etag;
|
||||
}
|
||||
|
||||
protected function resourceNotModified()
|
||||
{
|
||||
if (!isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
|
||||
return false;
|
||||
}
|
||||
$ifModifiedSince = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
|
||||
if (false !== ($semicolon = strrpos($ifModifiedSince, ';'))) {
|
||||
// IE has tacked on extra data to this header, strip it
|
||||
$ifModifiedSince = substr($ifModifiedSince, 0, $semicolon);
|
||||
}
|
||||
if ($ifModifiedSince == self::gmtDate($this->_lmTime)) {
|
||||
// Apache 2.2's behavior. If there was no ETag match, send the
|
||||
// non-encoded version of the ETag value.
|
||||
$this->_headers['ETag'] = $this->normalizeEtag($this->_etag);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
326
wp-content/plugins/wp-minify/min/lib/HTTP/Encoder.php
Normal file
326
wp-content/plugins/wp-minify/min/lib/HTTP/Encoder.php
Normal file
@ -0,0 +1,326 @@
|
||||
<?php
|
||||
/**
|
||||
* Class HTTP_Encoder
|
||||
* @package Minify
|
||||
* @subpackage HTTP
|
||||
*/
|
||||
|
||||
/**
|
||||
* Encode and send gzipped/deflated content
|
||||
*
|
||||
* The "Vary: Accept-Encoding" header is sent. If the client allows encoding,
|
||||
* Content-Encoding and Content-Length are added.
|
||||
*
|
||||
* <code>
|
||||
* // Send a CSS file, compressed if possible
|
||||
* $he = new HTTP_Encoder(array(
|
||||
* 'content' => file_get_contents($cssFile)
|
||||
* ,'type' => 'text/css'
|
||||
* ));
|
||||
* $he->encode();
|
||||
* $he->sendAll();
|
||||
* </code>
|
||||
*
|
||||
* <code>
|
||||
* // Shortcut to encoding output
|
||||
* header('Content-Type: text/css'); // needed if not HTML
|
||||
* HTTP_Encoder::output($css);
|
||||
* </code>
|
||||
*
|
||||
* <code>
|
||||
* // Just sniff for the accepted encoding
|
||||
* $encoding = HTTP_Encoder::getAcceptedEncoding();
|
||||
* </code>
|
||||
*
|
||||
* For more control over headers, use getHeaders() and getData() and send your
|
||||
* own output.
|
||||
*
|
||||
* Note: If you don't need header mgmt, use PHP's native gzencode, gzdeflate,
|
||||
* and gzcompress functions for gzip, deflate, and compress-encoding
|
||||
* respectively.
|
||||
*
|
||||
* @package Minify
|
||||
* @subpackage HTTP
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class HTTP_Encoder {
|
||||
|
||||
/**
|
||||
* Should the encoder allow HTTP encoding to IE6?
|
||||
*
|
||||
* If you have many IE6 users and the bandwidth savings is worth troubling
|
||||
* some of them, set this to true.
|
||||
*
|
||||
* By default, encoding is only offered to IE7+. When this is true,
|
||||
* getAcceptedEncoding() will return an encoding for IE6 if its user agent
|
||||
* string contains "SV1". This has been documented in many places as "safe",
|
||||
* but there seem to be remaining, intermittent encoding bugs in patched
|
||||
* IE6 on the wild web.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static $encodeToIe6 = false;
|
||||
|
||||
|
||||
/**
|
||||
* Default compression level for zlib operations
|
||||
*
|
||||
* This level is used if encode() is not given a $compressionLevel
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public static $compressionLevel = 6;
|
||||
|
||||
|
||||
/**
|
||||
* Get an HTTP Encoder object
|
||||
*
|
||||
* @param array $spec options
|
||||
*
|
||||
* 'content': (string required) content to be encoded
|
||||
*
|
||||
* 'type': (string) if set, the Content-Type header will have this value.
|
||||
*
|
||||
* 'method: (string) only set this if you are forcing a particular encoding
|
||||
* method. If not set, the best method will be chosen by getAcceptedEncoding()
|
||||
* The available methods are 'gzip', 'deflate', 'compress', and '' (no
|
||||
* encoding)
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function __construct($spec)
|
||||
{
|
||||
$this->_content = $spec['content'];
|
||||
$this->_headers['Content-Length'] = (string)strlen($this->_content);
|
||||
if (isset($spec['type'])) {
|
||||
$this->_headers['Content-Type'] = $spec['type'];
|
||||
}
|
||||
if (isset($spec['method'])
|
||||
&& in_array($spec['method'], array('gzip', 'deflate', 'compress', '')))
|
||||
{
|
||||
$this->_encodeMethod = array($spec['method'], $spec['method']);
|
||||
} else {
|
||||
$this->_encodeMethod = self::getAcceptedEncoding();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content in current form
|
||||
*
|
||||
* Call after encode() for encoded content.
|
||||
*
|
||||
* return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get array of output headers to be sent
|
||||
*
|
||||
* E.g.
|
||||
* <code>
|
||||
* array(
|
||||
* 'Content-Length' => '615'
|
||||
* ,'Content-Encoding' => 'x-gzip'
|
||||
* ,'Vary' => 'Accept-Encoding'
|
||||
* )
|
||||
* </code>
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->_headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send output headers
|
||||
*
|
||||
* You must call this before headers are sent and it probably cannot be
|
||||
* used in conjunction with zlib output buffering / mod_gzip. Errors are
|
||||
* not handled purposefully.
|
||||
*
|
||||
* @see getHeaders()
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function sendHeaders()
|
||||
{
|
||||
foreach ($this->_headers as $name => $val) {
|
||||
header($name . ': ' . $val);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send output headers and content
|
||||
*
|
||||
* A shortcut for sendHeaders() and echo getContent()
|
||||
*
|
||||
* You must call this before headers are sent and it probably cannot be
|
||||
* used in conjunction with zlib output buffering / mod_gzip. Errors are
|
||||
* not handled purposefully.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function sendAll()
|
||||
{
|
||||
$this->sendHeaders();
|
||||
echo $this->_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the client's best encoding method from the HTTP Accept-Encoding
|
||||
* header.
|
||||
*
|
||||
* If no Accept-Encoding header is set, or the browser is IE before v6 SP2,
|
||||
* this will return ('', ''), the "identity" encoding.
|
||||
*
|
||||
* A syntax-aware scan is done of the Accept-Encoding, so the method must
|
||||
* be non 0. The methods are favored in order of gzip, deflate, then
|
||||
* compress. Deflate is always smallest and generally faster, but is
|
||||
* rarely sent by servers, so client support could be buggier.
|
||||
*
|
||||
* @param bool $allowCompress allow the older compress encoding
|
||||
*
|
||||
* @param bool $allowDeflate allow the more recent deflate encoding
|
||||
*
|
||||
* @return array two values, 1st is the actual encoding method, 2nd is the
|
||||
* alias of that method to use in the Content-Encoding header (some browsers
|
||||
* call gzip "x-gzip" etc.)
|
||||
*/
|
||||
public static function getAcceptedEncoding($allowCompress = true, $allowDeflate = true)
|
||||
{
|
||||
// @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
|
||||
|
||||
if (! isset($_SERVER['HTTP_ACCEPT_ENCODING'])
|
||||
|| self::_isBuggyIe())
|
||||
{
|
||||
return array('', '');
|
||||
}
|
||||
$ae = $_SERVER['HTTP_ACCEPT_ENCODING'];
|
||||
// gzip checks (quick)
|
||||
if (0 === strpos($ae, 'gzip,') // most browsers
|
||||
|| 0 === strpos($ae, 'deflate, gzip,') // opera
|
||||
) {
|
||||
return array('gzip', 'gzip');
|
||||
}
|
||||
// gzip checks (slow)
|
||||
if (preg_match(
|
||||
'@(?:^|,)\\s*((?:x-)?gzip)\\s*(?:$|,|;\\s*q=(?:0\\.|1))@'
|
||||
,$ae
|
||||
,$m)) {
|
||||
return array('gzip', $m[1]);
|
||||
}
|
||||
if ($allowDeflate) {
|
||||
// deflate checks
|
||||
$aeRev = strrev($ae);
|
||||
if (0 === strpos($aeRev, 'etalfed ,') // ie, webkit
|
||||
|| 0 === strpos($aeRev, 'etalfed,') // gecko
|
||||
|| 0 === strpos($ae, 'deflate,') // opera
|
||||
// slow parsing
|
||||
|| preg_match(
|
||||
'@(?:^|,)\\s*deflate\\s*(?:$|,|;\\s*q=(?:0\\.|1))@', $ae)) {
|
||||
return array('deflate', 'deflate');
|
||||
}
|
||||
}
|
||||
if ($allowCompress && preg_match(
|
||||
'@(?:^|,)\\s*((?:x-)?compress)\\s*(?:$|,|;\\s*q=(?:0\\.|1))@'
|
||||
,$ae
|
||||
,$m)) {
|
||||
return array('compress', $m[1]);
|
||||
}
|
||||
return array('', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode (compress) the content
|
||||
*
|
||||
* If the encode method is '' (none) or compression level is 0, or the 'zlib'
|
||||
* extension isn't loaded, we return false.
|
||||
*
|
||||
* Then the appropriate gz_* function is called to compress the content. If
|
||||
* this fails, false is returned.
|
||||
*
|
||||
* The header "Vary: Accept-Encoding" is added. If encoding is successful,
|
||||
* the Content-Length header is updated, and Content-Encoding is also added.
|
||||
*
|
||||
* @param int $compressionLevel given to zlib functions. If not given, the
|
||||
* class default will be used.
|
||||
*
|
||||
* @return bool success true if the content was actually compressed
|
||||
*/
|
||||
public function encode($compressionLevel = null)
|
||||
{
|
||||
$this->_headers['Vary'] = 'Accept-Encoding';
|
||||
if (null === $compressionLevel) {
|
||||
$compressionLevel = self::$compressionLevel;
|
||||
}
|
||||
if ('' === $this->_encodeMethod[0]
|
||||
|| ($compressionLevel == 0)
|
||||
|| !extension_loaded('zlib'))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ($this->_encodeMethod[0] === 'deflate') {
|
||||
$encoded = gzdeflate($this->_content, $compressionLevel);
|
||||
} elseif ($this->_encodeMethod[0] === 'gzip') {
|
||||
$encoded = gzencode($this->_content, $compressionLevel);
|
||||
} else {
|
||||
$encoded = gzcompress($this->_content, $compressionLevel);
|
||||
}
|
||||
if (false === $encoded) {
|
||||
return false;
|
||||
}
|
||||
$this->_headers['Content-Length'] = strlen($encoded);
|
||||
$this->_headers['Content-Encoding'] = $this->_encodeMethod[1];
|
||||
$this->_content = $encoded;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode and send appropriate headers and content
|
||||
*
|
||||
* This is a convenience method for common use of the class
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
* @param int $compressionLevel given to zlib functions. If not given, the
|
||||
* class default will be used.
|
||||
*
|
||||
* @return bool success true if the content was actually compressed
|
||||
*/
|
||||
public static function output($content, $compressionLevel = null)
|
||||
{
|
||||
if (null === $compressionLevel) {
|
||||
$compressionLevel = self::$compressionLevel;
|
||||
}
|
||||
$he = new HTTP_Encoder(array('content' => $content));
|
||||
$ret = $he->encode($compressionLevel);
|
||||
$he->sendAll();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected $_content = '';
|
||||
protected $_headers = array();
|
||||
protected $_encodeMethod = array('', '');
|
||||
|
||||
/**
|
||||
* Is the browser an IE version earlier than 6 SP2?
|
||||
*/
|
||||
protected static function _isBuggyIe()
|
||||
{
|
||||
$ua = $_SERVER['HTTP_USER_AGENT'];
|
||||
// quick escape for non-IEs
|
||||
if (0 !== strpos($ua, 'Mozilla/4.0 (compatible; MSIE ')
|
||||
|| false !== strpos($ua, 'Opera')) {
|
||||
return false;
|
||||
}
|
||||
// no regex = faaast
|
||||
$version = (float)substr($ua, 30);
|
||||
return self::$encodeToIe6
|
||||
? ($version < 6 || ($version == 6 && false === strpos($ua, 'SV1')))
|
||||
: ($version < 7);
|
||||
}
|
||||
}
|
||||
314
wp-content/plugins/wp-minify/min/lib/JSMin.php
Normal file
314
wp-content/plugins/wp-minify/min/lib/JSMin.php
Normal file
@ -0,0 +1,314 @@
|
||||
<?php
|
||||
/**
|
||||
* jsmin.php - PHP implementation of Douglas Crockford's JSMin.
|
||||
*
|
||||
* This is a direct port of jsmin.c to PHP with a few PHP performance tweaks and
|
||||
* modifications to preserve some comments (see below). Also, rather than using
|
||||
* stdin/stdout, JSMin::minify() accepts a string as input and returns another
|
||||
* string as output.
|
||||
*
|
||||
* Comments containing IE conditional compilation are preserved, as are multi-line
|
||||
* comments that begin with "/*!" (for documentation purposes). In the latter case
|
||||
* newlines are inserted around the comment to enhance readability.
|
||||
*
|
||||
* PHP 5 or higher is required.
|
||||
*
|
||||
* Permission is hereby granted to use this version of the library under the
|
||||
* same terms as jsmin.c, which has the following license:
|
||||
*
|
||||
* --
|
||||
* Copyright (c) 2002 Douglas Crockford (www.crockford.com)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* The Software shall be used for Good, not Evil.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* --
|
||||
*
|
||||
* @package JSMin
|
||||
* @author Ryan Grove <ryan@wonko.com> (PHP port)
|
||||
* @author Steve Clay <steve@mrclay.org> (modifications + cleanup)
|
||||
* @author Andrea Giammarchi <http://www.3site.eu> (spaceBeforeRegExp)
|
||||
* @copyright 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c)
|
||||
* @copyright 2008 Ryan Grove <ryan@wonko.com> (PHP port)
|
||||
* @license http://opensource.org/licenses/mit-license.php MIT License
|
||||
* @link http://code.google.com/p/jsmin-php/
|
||||
*/
|
||||
|
||||
class JSMin {
|
||||
const ORD_LF = 10;
|
||||
const ORD_SPACE = 32;
|
||||
const ACTION_KEEP_A = 1;
|
||||
const ACTION_DELETE_A = 2;
|
||||
const ACTION_DELETE_A_B = 3;
|
||||
|
||||
protected $a = "\n";
|
||||
protected $b = '';
|
||||
protected $input = '';
|
||||
protected $inputIndex = 0;
|
||||
protected $inputLength = 0;
|
||||
protected $lookAhead = null;
|
||||
protected $output = '';
|
||||
|
||||
/**
|
||||
* Minify Javascript
|
||||
*
|
||||
* @param string $js Javascript to be minified
|
||||
* @return string
|
||||
*/
|
||||
public static function minify($js)
|
||||
{
|
||||
$jsmin = new JSMin($js);
|
||||
return $jsmin->min();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup process
|
||||
*/
|
||||
public function __construct($input)
|
||||
{
|
||||
$this->input = str_replace("\r\n", "\n", $input);
|
||||
$this->inputLength = strlen($this->input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform minification, return result
|
||||
*/
|
||||
public function min()
|
||||
{
|
||||
if ($this->output !== '') { // min already run
|
||||
return $this->output;
|
||||
}
|
||||
$this->action(self::ACTION_DELETE_A_B);
|
||||
|
||||
while ($this->a !== null) {
|
||||
// determine next command
|
||||
$command = self::ACTION_KEEP_A; // default
|
||||
if ($this->a === ' ') {
|
||||
if (! $this->isAlphaNum($this->b)) {
|
||||
$command = self::ACTION_DELETE_A;
|
||||
}
|
||||
} elseif ($this->a === "\n") {
|
||||
if ($this->b === ' ') {
|
||||
$command = self::ACTION_DELETE_A_B;
|
||||
} elseif (false === strpos('{[(+-', $this->b)
|
||||
&& ! $this->isAlphaNum($this->b)) {
|
||||
$command = self::ACTION_DELETE_A;
|
||||
}
|
||||
} elseif (! $this->isAlphaNum($this->a)) {
|
||||
if ($this->b === ' '
|
||||
|| ($this->b === "\n"
|
||||
&& (false === strpos('}])+-"\'', $this->a)))) {
|
||||
$command = self::ACTION_DELETE_A_B;
|
||||
}
|
||||
}
|
||||
$this->action($command);
|
||||
}
|
||||
$this->output = trim($this->output);
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
* ACTION_KEEP_A = Output A. Copy B to A. Get the next B.
|
||||
* ACTION_DELETE_A = Copy B to A. Get the next B.
|
||||
* ACTION_DELETE_A_B = Get the next B.
|
||||
*/
|
||||
protected function action($command)
|
||||
{
|
||||
switch ($command) {
|
||||
case self::ACTION_KEEP_A:
|
||||
$this->output .= $this->a;
|
||||
// fallthrough
|
||||
case self::ACTION_DELETE_A:
|
||||
$this->a = $this->b;
|
||||
if ($this->a === "'" || $this->a === '"') { // string literal
|
||||
$str = $this->a; // in case needed for exception
|
||||
while (true) {
|
||||
$this->output .= $this->a;
|
||||
$this->a = $this->get();
|
||||
if ($this->a === $this->b) { // end quote
|
||||
break;
|
||||
}
|
||||
if (ord($this->a) <= self::ORD_LF) {
|
||||
throw new JSMin_UnterminatedStringException(
|
||||
'Unterminated String: ' . var_export($str, true));
|
||||
}
|
||||
$str .= $this->a;
|
||||
if ($this->a === '\\') {
|
||||
$this->output .= $this->a;
|
||||
$this->a = $this->get();
|
||||
$str .= $this->a;
|
||||
}
|
||||
}
|
||||
}
|
||||
// fallthrough
|
||||
case self::ACTION_DELETE_A_B:
|
||||
$this->b = $this->next();
|
||||
if ($this->b === '/' && $this->isRegexpLiteral()) { // RegExp literal
|
||||
$this->output .= $this->a . $this->b;
|
||||
$pattern = '/'; // in case needed for exception
|
||||
while (true) {
|
||||
$this->a = $this->get();
|
||||
$pattern .= $this->a;
|
||||
if ($this->a === '/') { // end pattern
|
||||
break; // while (true)
|
||||
} elseif ($this->a === '\\') {
|
||||
$this->output .= $this->a;
|
||||
$this->a = $this->get();
|
||||
$pattern .= $this->a;
|
||||
} elseif (ord($this->a) <= self::ORD_LF) {
|
||||
throw new JSMin_UnterminatedRegExpException(
|
||||
'Unterminated RegExp: '. var_export($pattern, true));
|
||||
}
|
||||
$this->output .= $this->a;
|
||||
}
|
||||
$this->b = $this->next();
|
||||
}
|
||||
// end case ACTION_DELETE_A_B
|
||||
}
|
||||
}
|
||||
|
||||
protected function isRegexpLiteral()
|
||||
{
|
||||
if (false !== strpos("\n{;(,=:[!&|?", $this->a)) { // we aren't dividing
|
||||
return true;
|
||||
}
|
||||
if (' ' === $this->a) {
|
||||
$length = strlen($this->output);
|
||||
if ($length < 2) { // weird edge case
|
||||
return true;
|
||||
}
|
||||
// you can't divide a keyword
|
||||
if (preg_match('/(?:case|else|in|return|typeof)$/', $this->output, $m)) {
|
||||
if ($this->output === $m[0]) { // odd but could happen
|
||||
return true;
|
||||
}
|
||||
// make sure it's a keyword, not end of an identifier
|
||||
$charBeforeKeyword = substr($this->output, $length - strlen($m[0]) - 1, 1);
|
||||
if (! $this->isAlphaNum($charBeforeKeyword)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next char. Convert ctrl char to space.
|
||||
*/
|
||||
protected function get()
|
||||
{
|
||||
$c = $this->lookAhead;
|
||||
$this->lookAhead = null;
|
||||
if ($c === null) {
|
||||
if ($this->inputIndex < $this->inputLength) {
|
||||
$c = $this->input[$this->inputIndex];
|
||||
$this->inputIndex += 1;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($c === "\r" || $c === "\n") {
|
||||
return "\n";
|
||||
}
|
||||
if (ord($c) < self::ORD_SPACE) { // control char
|
||||
return ' ';
|
||||
}
|
||||
return $c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next char. If is ctrl character, translate to a space or newline.
|
||||
*/
|
||||
protected function peek()
|
||||
{
|
||||
$this->lookAhead = $this->get();
|
||||
return $this->lookAhead;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is $c a letter, digit, underscore, dollar sign, escape, or non-ASCII?
|
||||
*/
|
||||
protected function isAlphaNum($c)
|
||||
{
|
||||
return (preg_match('/^[0-9a-zA-Z_\\$\\\\]$/', $c) || ord($c) > 126);
|
||||
}
|
||||
|
||||
protected function singleLineComment()
|
||||
{
|
||||
$comment = '';
|
||||
while (true) {
|
||||
$get = $this->get();
|
||||
$comment .= $get;
|
||||
if (ord($get) <= self::ORD_LF) { // EOL reached
|
||||
// if IE conditional comment
|
||||
if (preg_match('/^\\/@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
||||
return "/{$comment}";
|
||||
}
|
||||
return $get;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function multipleLineComment()
|
||||
{
|
||||
$this->get();
|
||||
$comment = '';
|
||||
while (true) {
|
||||
$get = $this->get();
|
||||
if ($get === '*') {
|
||||
if ($this->peek() === '/') { // end of comment reached
|
||||
$this->get();
|
||||
// if comment preserved by YUI Compressor
|
||||
if (0 === strpos($comment, '!')) {
|
||||
return "\n/*" . substr($comment, 1) . "*/\n";
|
||||
}
|
||||
// if IE conditional comment
|
||||
if (preg_match('/^@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
||||
return "/*{$comment}*/";
|
||||
}
|
||||
return ' ';
|
||||
}
|
||||
} elseif ($get === null) {
|
||||
throw new JSMin_UnterminatedCommentException('Unterminated Comment: ' . var_export('/*' . $comment, true));
|
||||
}
|
||||
$comment .= $get;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next character, skipping over comments.
|
||||
* Some comments may be preserved.
|
||||
*/
|
||||
protected function next()
|
||||
{
|
||||
$get = $this->get();
|
||||
if ($get !== '/') {
|
||||
return $get;
|
||||
}
|
||||
switch ($this->peek()) {
|
||||
case '/': return $this->singleLineComment();
|
||||
case '*': return $this->multipleLineComment();
|
||||
default: return $get;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class JSMin_UnterminatedStringException extends Exception {}
|
||||
class JSMin_UnterminatedCommentException extends Exception {}
|
||||
class JSMin_UnterminatedRegExpException extends Exception {}
|
||||
1872
wp-content/plugins/wp-minify/min/lib/JSMinPlus.php
Normal file
1872
wp-content/plugins/wp-minify/min/lib/JSMinPlus.php
Normal file
File diff suppressed because it is too large
Load Diff
532
wp-content/plugins/wp-minify/min/lib/Minify.php
Normal file
532
wp-content/plugins/wp-minify/min/lib/Minify.php
Normal file
@ -0,0 +1,532 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Minify_Source
|
||||
*/
|
||||
require_once 'Minify/Source.php';
|
||||
|
||||
/**
|
||||
* Minify - Combines, minifies, and caches JavaScript and CSS files on demand.
|
||||
*
|
||||
* See README for usage instructions (for now).
|
||||
*
|
||||
* This library was inspired by {@link mailto:flashkot@mail.ru jscsscomp by Maxim Martynyuk}
|
||||
* and by the article {@link http://www.hunlock.com/blogs/Supercharged_Javascript "Supercharged JavaScript" by Patrick Hunlock}.
|
||||
*
|
||||
* Requires PHP 5.1.0.
|
||||
* Tested on PHP 5.1.6.
|
||||
*
|
||||
* @package Minify
|
||||
* @author Ryan Grove <ryan@wonko.com>
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
* @copyright 2008 Ryan Grove, Stephen Clay. All rights reserved.
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @link http://code.google.com/p/minify/
|
||||
*/
|
||||
class Minify {
|
||||
|
||||
const VERSION = '2.1.3';
|
||||
const TYPE_CSS = 'text/css';
|
||||
const TYPE_HTML = 'text/html';
|
||||
// there is some debate over the ideal JS Content-Type, but this is the
|
||||
// Apache default and what Yahoo! uses..
|
||||
const TYPE_JS = 'application/x-javascript';
|
||||
|
||||
/**
|
||||
* How many hours behind are the file modification times of uploaded files?
|
||||
*
|
||||
* If you upload files from Windows to a non-Windows server, Windows may report
|
||||
* incorrect mtimes for the files. Immediately after modifying and uploading a
|
||||
* file, use the touch command to update the mtime on the server. If the mtime
|
||||
* jumps ahead by a number of hours, set this variable to that number. If the mtime
|
||||
* moves back, this should not be needed.
|
||||
*
|
||||
* @var int $uploaderHoursBehind
|
||||
*/
|
||||
public static $uploaderHoursBehind = 0;
|
||||
|
||||
/**
|
||||
* If this string is not empty AND the serve() option 'bubbleCssImports' is
|
||||
* NOT set, then serve() will check CSS files for @import declarations that
|
||||
* appear too late in the combined stylesheet. If found, serve() will prepend
|
||||
* the output with this warning.
|
||||
*
|
||||
* @var string $importWarning
|
||||
*/
|
||||
public static $importWarning = "/* See http://code.google.com/p/minify/wiki/CommonProblems#@imports_can_appear_in_invalid_locations_in_combined_CSS_files */\n";
|
||||
|
||||
/**
|
||||
* Specify a cache object (with identical interface as Minify_Cache_File) or
|
||||
* a path to use with Minify_Cache_File.
|
||||
*
|
||||
* If not called, Minify will not use a cache and, for each 200 response, will
|
||||
* need to recombine files, minify and encode the output.
|
||||
*
|
||||
* @param mixed $cache object with identical interface as Minify_Cache_File or
|
||||
* a directory path, or null to disable caching. (default = '')
|
||||
*
|
||||
* @param bool $fileLocking (default = true) This only applies if the first
|
||||
* parameter is a string.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public static function setCache($cache = '', $fileLocking = true)
|
||||
{
|
||||
if (is_string($cache)) {
|
||||
require_once 'Minify/Cache/File.php';
|
||||
self::$_cache = new Minify_Cache_File($cache, $fileLocking);
|
||||
} else {
|
||||
self::$_cache = $cache;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serve a request for a minified file.
|
||||
*
|
||||
* Here are the available options and defaults in the base controller:
|
||||
*
|
||||
* 'isPublic' : send "public" instead of "private" in Cache-Control
|
||||
* headers, allowing shared caches to cache the output. (default true)
|
||||
*
|
||||
* 'quiet' : set to true to have serve() return an array rather than sending
|
||||
* any headers/output (default false)
|
||||
*
|
||||
* 'encodeOutput' : set to false to disable content encoding, and not send
|
||||
* the Vary header (default true)
|
||||
*
|
||||
* 'encodeMethod' : generally you should let this be determined by
|
||||
* HTTP_Encoder (leave null), but you can force a particular encoding
|
||||
* to be returned, by setting this to 'gzip' or '' (no encoding)
|
||||
*
|
||||
* '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')
|
||||
*
|
||||
* '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
|
||||
* Expires header. Unlike the old 'setExpires' setting, this setting will NOT
|
||||
* prevent conditional GETs. Note this has nothing to do with server-side caching.
|
||||
*
|
||||
* 'rewriteCssUris' : If true, serve() will automatically set the 'currentDir'
|
||||
* minifier option to enable URI rewriting in CSS files (default true)
|
||||
*
|
||||
* 'bubbleCssImports' : If true, all @import declarations in combined CSS
|
||||
* files will be move to the top. Note this may alter effective CSS values
|
||||
* due to a change in order. (default false)
|
||||
*
|
||||
* 'debug' : set to true to minify all sources with the 'Lines' controller, which
|
||||
* eases the debugging of combined files. This also prevents 304 responses.
|
||||
* @see Minify_Lines::minify()
|
||||
*
|
||||
* 'minifiers' : to override Minify's default choice of minifier function for
|
||||
* a particular content-type, specify your callback under the key of the
|
||||
* content-type:
|
||||
* <code>
|
||||
* // call customCssMinifier($css) for all CSS minification
|
||||
* $options['minifiers'][Minify::TYPE_CSS] = 'customCssMinifier';
|
||||
*
|
||||
* // don't minify Javascript at all
|
||||
* $options['minifiers'][Minify::TYPE_JS] = '';
|
||||
* </code>
|
||||
*
|
||||
* 'minifierOptions' : to send options to the minifier function, specify your options
|
||||
* under the key of the content-type. E.g. To send the CSS minifier an option:
|
||||
* <code>
|
||||
* // give CSS minifier array('optionName' => 'optionValue') as 2nd argument
|
||||
* $options['minifierOptions'][Minify::TYPE_CSS]['optionName'] = 'optionValue';
|
||||
* </code>
|
||||
*
|
||||
* 'contentType' : (optional) this is only needed if your file extension is not
|
||||
* js/css/html. The given content-type will be sent regardless of source file
|
||||
* extension, so this should not be used in a Groups config with other
|
||||
* Javascript/CSS files.
|
||||
*
|
||||
* Any controller options are documented in that controller's setupSources() method.
|
||||
*
|
||||
* @param mixed instance of subclass of Minify_Controller_Base or string name of
|
||||
* controller. E.g. 'Files'
|
||||
*
|
||||
* @param array $options controller/serve options
|
||||
*
|
||||
* @return mixed null, or, if the 'quiet' option is set to true, an array
|
||||
* with keys "success" (bool), "statusCode" (int), "content" (string), and
|
||||
* "headers" (array).
|
||||
*/
|
||||
public static function serve($controller, $options = array())
|
||||
{
|
||||
if (is_string($controller)) {
|
||||
// make $controller into object
|
||||
$class = 'Minify_Controller_' . $controller;
|
||||
if (! class_exists($class, false)) {
|
||||
require_once "Minify/Controller/"
|
||||
. str_replace('_', '/', $controller) . ".php";
|
||||
}
|
||||
$controller = new $class();
|
||||
}
|
||||
|
||||
// set up controller sources and mix remaining options with
|
||||
// controller defaults
|
||||
$options = $controller->setupSources($options);
|
||||
$options = $controller->analyzeSources($options);
|
||||
self::$_options = $controller->mixInDefaultOptions($options);
|
||||
|
||||
// check request validity
|
||||
if (! $controller->sources) {
|
||||
// invalid request!
|
||||
if (! self::$_options['quiet']) {
|
||||
header(self::$_options['badRequestHeader']);
|
||||
echo self::$_options['badRequestHeader'];
|
||||
return;
|
||||
} else {
|
||||
list(,$statusCode) = explode(' ', self::$_options['badRequestHeader']);
|
||||
return array(
|
||||
'success' => false
|
||||
,'statusCode' => (int)$statusCode
|
||||
,'content' => ''
|
||||
,'headers' => array()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
self::$_controller = $controller;
|
||||
|
||||
if (self::$_options['debug']) {
|
||||
self::_setupDebug($controller->sources);
|
||||
self::$_options['maxAge'] = 0;
|
||||
}
|
||||
|
||||
// determine encoding
|
||||
if (self::$_options['encodeOutput']) {
|
||||
if (self::$_options['encodeMethod'] !== null) {
|
||||
// controller specifically requested this
|
||||
$contentEncoding = self::$_options['encodeMethod'];
|
||||
} else {
|
||||
// sniff request header
|
||||
require_once 'HTTP/Encoder.php';
|
||||
// depending on what the client accepts, $contentEncoding may be
|
||||
// 'x-gzip' while our internal encodeMethod is 'gzip'. Calling
|
||||
// getAcceptedEncoding(false, false) leaves out compress and deflate as options.
|
||||
list(self::$_options['encodeMethod'], $contentEncoding) = HTTP_Encoder::getAcceptedEncoding(false, false);
|
||||
}
|
||||
} else {
|
||||
self::$_options['encodeMethod'] = ''; // identity (no encoding)
|
||||
}
|
||||
|
||||
// check client cache
|
||||
require_once 'HTTP/ConditionalGet.php';
|
||||
$cgOptions = array(
|
||||
'lastModifiedTime' => self::$_options['lastModifiedTime']
|
||||
,'isPublic' => self::$_options['isPublic']
|
||||
,'encoding' => self::$_options['encodeMethod']
|
||||
);
|
||||
if (self::$_options['maxAge'] > 0) {
|
||||
$cgOptions['maxAge'] = self::$_options['maxAge'];
|
||||
}
|
||||
$cg = new HTTP_ConditionalGet($cgOptions);
|
||||
if ($cg->cacheIsValid) {
|
||||
// client's cache is valid
|
||||
if (! self::$_options['quiet']) {
|
||||
$cg->sendHeaders();
|
||||
return;
|
||||
} else {
|
||||
return array(
|
||||
'success' => true
|
||||
,'statusCode' => 304
|
||||
,'content' => ''
|
||||
,'headers' => $cg->getHeaders()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// client will need output
|
||||
$headers = $cg->getHeaders();
|
||||
unset($cg);
|
||||
}
|
||||
|
||||
if (self::$_options['contentType'] === self::TYPE_CSS
|
||||
&& self::$_options['rewriteCssUris']) {
|
||||
reset($controller->sources);
|
||||
while (list($key, $source) = each($controller->sources)) {
|
||||
if ($source->filepath
|
||||
&& !isset($source->minifyOptions['currentDir'])
|
||||
&& !isset($source->minifyOptions['prependRelativePath'])
|
||||
) {
|
||||
$source->minifyOptions['currentDir'] = dirname($source->filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check server cache
|
||||
if (null !== self::$_cache) {
|
||||
// using cache
|
||||
// the goal is to use only the cache methods to sniff the length and
|
||||
// output the content, as they do not require ever loading the file into
|
||||
// memory.
|
||||
$cacheId = 'minify_' . self::_getCacheId();
|
||||
$fullCacheId = (self::$_options['encodeMethod'])
|
||||
? $cacheId . '.gz'
|
||||
: $cacheId;
|
||||
// check cache for valid entry
|
||||
$cacheIsReady = self::$_cache->isValid($fullCacheId, self::$_options['lastModifiedTime']);
|
||||
if ($cacheIsReady) {
|
||||
$cacheContentLength = self::$_cache->getSize($fullCacheId);
|
||||
} else {
|
||||
// generate & cache content
|
||||
$content = self::_combineMinify();
|
||||
self::$_cache->store($cacheId, $content);
|
||||
if (function_exists('gzencode')) {
|
||||
self::$_cache->store($cacheId . '.gz', gzencode($content, self::$_options['encodeLevel']));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// no cache
|
||||
$cacheIsReady = false;
|
||||
$content = self::_combineMinify();
|
||||
}
|
||||
if (! $cacheIsReady && self::$_options['encodeMethod']) {
|
||||
// still need to encode
|
||||
$content = gzencode($content, self::$_options['encodeLevel']);
|
||||
}
|
||||
|
||||
// add headers
|
||||
$headers['Content-Length'] = $cacheIsReady
|
||||
? $cacheContentLength
|
||||
: strlen($content);
|
||||
$headers['Content-Type'] = self::$_options['contentTypeCharset']
|
||||
? self::$_options['contentType'] . '; charset=' . self::$_options['contentTypeCharset']
|
||||
: self::$_options['contentType'];
|
||||
if (self::$_options['encodeMethod'] !== '') {
|
||||
$headers['Content-Encoding'] = $contentEncoding;
|
||||
}
|
||||
if (self::$_options['encodeOutput']) {
|
||||
$headers['Vary'] = 'Accept-Encoding';
|
||||
}
|
||||
|
||||
if (! self::$_options['quiet']) {
|
||||
// output headers & content
|
||||
foreach ($headers as $name => $val) {
|
||||
header($name . ': ' . $val);
|
||||
}
|
||||
if ($cacheIsReady) {
|
||||
self::$_cache->display($fullCacheId);
|
||||
} else {
|
||||
echo $content;
|
||||
}
|
||||
} else {
|
||||
return array(
|
||||
'success' => true
|
||||
,'statusCode' => 200
|
||||
,'content' => $cacheIsReady
|
||||
? self::$_cache->fetch($fullCacheId)
|
||||
: $content
|
||||
,'headers' => $headers
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return combined minified content for a set of sources
|
||||
*
|
||||
* No internal caching will be used and the content will not be HTTP encoded.
|
||||
*
|
||||
* @param array $sources array of filepaths and/or Minify_Source objects
|
||||
*
|
||||
* @param array $options (optional) array of options for serve. By default
|
||||
* these are already set: quiet = true, encodeMethod = '', lastModifiedTime = 0.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function combine($sources, $options = array())
|
||||
{
|
||||
$cache = self::$_cache;
|
||||
self::$_cache = null;
|
||||
$options = array_merge(array(
|
||||
'files' => (array)$sources
|
||||
,'quiet' => true
|
||||
,'encodeMethod' => ''
|
||||
,'lastModifiedTime' => 0
|
||||
), $options);
|
||||
$out = self::serve('Files', $options);
|
||||
self::$_cache = $cache;
|
||||
return $out['content'];
|
||||
}
|
||||
|
||||
/**
|
||||
* On IIS, create $_SERVER['DOCUMENT_ROOT']
|
||||
*
|
||||
* @param bool $unsetPathInfo (default false) if true, $_SERVER['PATH_INFO']
|
||||
* will be unset (it is inconsistent with Apache's setting)
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public static function setDocRoot($unsetPathInfo = false)
|
||||
{
|
||||
if (isset($_SERVER['SERVER_SOFTWARE'])
|
||||
&& 0 === strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/')
|
||||
) {
|
||||
$_SERVER['DOCUMENT_ROOT'] = rtrim(substr(
|
||||
$_SERVER['PATH_TRANSLATED']
|
||||
,0
|
||||
,strlen($_SERVER['PATH_TRANSLATED']) - strlen($_SERVER['SCRIPT_NAME'])
|
||||
), '\\');
|
||||
if ($unsetPathInfo) {
|
||||
unset($_SERVER['PATH_INFO']);
|
||||
}
|
||||
require_once 'Minify/Logger.php';
|
||||
Minify_Logger::log("setDocRoot() set DOCUMENT_ROOT to \"{$_SERVER['DOCUMENT_ROOT']}\"");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @var mixed Minify_Cache_* object or null (i.e. no server cache is used)
|
||||
*/
|
||||
private static $_cache = null;
|
||||
|
||||
/**
|
||||
* @var Minify_Controller active controller for current request
|
||||
*/
|
||||
protected static $_controller = null;
|
||||
|
||||
/**
|
||||
* @var array options for current request
|
||||
*/
|
||||
protected static $_options = null;
|
||||
|
||||
/**
|
||||
* Set up sources to use Minify_Lines
|
||||
*
|
||||
* @param array $sources Minify_Source instances
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected static function _setupDebug($sources)
|
||||
{
|
||||
foreach ($sources as $source) {
|
||||
$source->minifier = array('Minify_Lines', 'minify');
|
||||
$id = $source->getId();
|
||||
$source->minifyOptions = array(
|
||||
'id' => (is_file($id) ? basename($id) : $id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines sources and minifies the result.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function _combineMinify()
|
||||
{
|
||||
$type = self::$_options['contentType']; // ease readability
|
||||
|
||||
// when combining scripts, make sure all statements separated and
|
||||
// trailing single line comment is terminated
|
||||
$implodeSeparator = ($type === self::TYPE_JS)
|
||||
? "\n;"
|
||||
: '';
|
||||
// allow the user to pass a particular array of options to each
|
||||
// minifier (designated by type). source objects may still override
|
||||
// these
|
||||
$defaultOptions = isset(self::$_options['minifierOptions'][$type])
|
||||
? self::$_options['minifierOptions'][$type]
|
||||
: array();
|
||||
// if minifier not set, default is no minification. source objects
|
||||
// may still override this
|
||||
$defaultMinifier = isset(self::$_options['minifiers'][$type])
|
||||
? self::$_options['minifiers'][$type]
|
||||
: false;
|
||||
|
||||
if (Minify_Source::haveNoMinifyPrefs(self::$_controller->sources)) {
|
||||
// all source have same options/minifier, better performance
|
||||
// to combine, then minify once
|
||||
foreach (self::$_controller->sources as $source) {
|
||||
$pieces[] = $source->getContent();
|
||||
}
|
||||
$content = implode($implodeSeparator, $pieces);
|
||||
if ($defaultMinifier) {
|
||||
self::$_controller->loadMinifier($defaultMinifier);
|
||||
$content = call_user_func($defaultMinifier, $content, $defaultOptions);
|
||||
}
|
||||
} else {
|
||||
// minify each source with its own options and minifier, then combine
|
||||
foreach (self::$_controller->sources as $source) {
|
||||
// allow the source to override our minifier and options
|
||||
$minifier = (null !== $source->minifier)
|
||||
? $source->minifier
|
||||
: $defaultMinifier;
|
||||
$options = (null !== $source->minifyOptions)
|
||||
? array_merge($defaultOptions, $source->minifyOptions)
|
||||
: $defaultOptions;
|
||||
if ($minifier) {
|
||||
self::$_controller->loadMinifier($minifier);
|
||||
// get source content and minify it
|
||||
$pieces[] = call_user_func($minifier, $source->getContent(), $options);
|
||||
} else {
|
||||
$pieces[] = $source->getContent();
|
||||
}
|
||||
}
|
||||
$content = implode($implodeSeparator, $pieces);
|
||||
}
|
||||
|
||||
if ($type === self::TYPE_CSS && false !== strpos($content, '@import')) {
|
||||
$content = self::_handleCssImports($content);
|
||||
}
|
||||
|
||||
// do any post-processing (esp. for editing build URIs)
|
||||
if (self::$_options['postprocessorRequire']) {
|
||||
require_once self::$_options['postprocessorRequire'];
|
||||
}
|
||||
if (self::$_options['postprocessor']) {
|
||||
$content = call_user_func(self::$_options['postprocessor'], $content, $type);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a unique cache id for for this request.
|
||||
*
|
||||
* Any settings that could affect output are taken into consideration
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function _getCacheId()
|
||||
{
|
||||
return md5(serialize(array(
|
||||
Minify_Source::getDigest(self::$_controller->sources)
|
||||
,self::$_options['minifiers']
|
||||
,self::$_options['minifierOptions']
|
||||
,self::$_options['postprocessor']
|
||||
,self::$_options['bubbleCssImports']
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Bubble CSS @imports to the top or prepend a warning if an
|
||||
* @import is detected not at the top.
|
||||
*/
|
||||
protected static function _handleCssImports($css)
|
||||
{
|
||||
if (self::$_options['bubbleCssImports']) {
|
||||
// bubble CSS imports
|
||||
preg_match_all('/@import.*?;/', $css, $imports);
|
||||
$css = implode('', $imports[0]) . preg_replace('/@import.*?;/', '', $css);
|
||||
} else if ('' !== self::$importWarning) {
|
||||
// remove comments so we don't mistake { in a comment as a block
|
||||
$noCommentCss = preg_replace('@/\\*[\\s\\S]*?\\*/@', '', $css);
|
||||
$lastImportPos = strrpos($noCommentCss, '@import');
|
||||
$firstBlockPos = strpos($noCommentCss, '{');
|
||||
if (false !== $lastImportPos
|
||||
&& false !== $firstBlockPos
|
||||
&& $firstBlockPos < $lastImportPos
|
||||
) {
|
||||
// { appears before @import : prepend warning
|
||||
$css = self::$importWarning . $css;
|
||||
}
|
||||
}
|
||||
return $css;
|
||||
}
|
||||
}
|
||||
103
wp-content/plugins/wp-minify/min/lib/Minify/Build.php
Normal file
103
wp-content/plugins/wp-minify/min/lib/Minify/Build.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Build
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once 'Minify/Source.php';
|
||||
|
||||
/**
|
||||
* Maintain a single last modification time for a group of Minify sources to
|
||||
* allow use of far off Expires headers in Minify.
|
||||
*
|
||||
* <code>
|
||||
* // in config file
|
||||
* $groupSources = array(
|
||||
* 'js' => array('file1.js', 'file2.js')
|
||||
* ,'css' => array('file1.css', 'file2.css', 'file3.css')
|
||||
* )
|
||||
*
|
||||
* // during HTML generation
|
||||
* $jsBuild = new Minify_Build($groupSources['js']);
|
||||
* $cssBuild = new Minify_Build($groupSources['css']);
|
||||
*
|
||||
* $script = "<script type='text/javascript' src='"
|
||||
* . $jsBuild->uri('/min.php/js') . "'></script>";
|
||||
* $link = "<link rel='stylesheet' type='text/css' href='"
|
||||
* . $cssBuild->uri('/min.php/css') . "'>";
|
||||
*
|
||||
* // in min.php
|
||||
* Minify::serve('Groups', array(
|
||||
* 'groups' => $groupSources
|
||||
* ,'setExpires' => (time() + 86400 * 365)
|
||||
* ));
|
||||
* </code>
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_Build {
|
||||
|
||||
/**
|
||||
* Last modification time of all files in the build
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $lastModified = 0;
|
||||
|
||||
/**
|
||||
* String to use as ampersand in uri(). Set this to '&' if
|
||||
* you are not HTML-escaping URIs.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $ampersand = '&';
|
||||
|
||||
/**
|
||||
* Get a time-stamped URI
|
||||
*
|
||||
* <code>
|
||||
* echo $b->uri('/site.js');
|
||||
* // outputs "/site.js?1678242"
|
||||
*
|
||||
* echo $b->uri('/scriptaculous.js?load=effects');
|
||||
* // outputs "/scriptaculous.js?load=effects&1678242"
|
||||
* </code>
|
||||
*
|
||||
* @param string $uri
|
||||
* @param boolean $forceAmpersand (default = false) Force the use of ampersand to
|
||||
* append the timestamp to the URI.
|
||||
* @return string
|
||||
*/
|
||||
public function uri($uri, $forceAmpersand = false) {
|
||||
$sep = ($forceAmpersand || strpos($uri, '?') !== false)
|
||||
? self::$ampersand
|
||||
: '?';
|
||||
return "{$uri}{$sep}{$this->lastModified}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a build object
|
||||
*
|
||||
* @param array $sources array of Minify_Source objects and/or file paths
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function __construct($sources)
|
||||
{
|
||||
$max = 0;
|
||||
foreach ((array)$sources as $source) {
|
||||
if ($source instanceof Minify_Source) {
|
||||
$max = max($max, $source->lastModified);
|
||||
} elseif (is_string($source)) {
|
||||
if (0 === strpos($source, '//')) {
|
||||
$source = $_SERVER['DOCUMENT_ROOT'] . substr($source, 1);
|
||||
}
|
||||
if (is_file($source)) {
|
||||
$max = max($max, filemtime($source));
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->lastModified = $max;
|
||||
}
|
||||
}
|
||||
83
wp-content/plugins/wp-minify/min/lib/Minify/CSS.php
Normal file
83
wp-content/plugins/wp-minify/min/lib/Minify/CSS.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_CSS
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Minify CSS
|
||||
*
|
||||
* This class uses Minify_CSS_Compressor and Minify_CSS_UriRewriter to
|
||||
* minify CSS and rewrite relative URIs.
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
* @author http://code.google.com/u/1stvamp/ (Issue 64 patch)
|
||||
*/
|
||||
class Minify_CSS {
|
||||
|
||||
/**
|
||||
* Minify a CSS string
|
||||
*
|
||||
* @param string $css
|
||||
*
|
||||
* @param array $options available options:
|
||||
*
|
||||
* 'preserveComments': (default true) multi-line comments that begin
|
||||
* with "/*!" will be preserved with newlines before and after to
|
||||
* enhance readability.
|
||||
*
|
||||
* 'prependRelativePath': (default null) if given, this string will be
|
||||
* prepended to all relative URIs in import/url declarations
|
||||
*
|
||||
* 'currentDir': (default null) if given, this is assumed to be the
|
||||
* directory of the current CSS file. Using this, minify will rewrite
|
||||
* all relative URIs in import/url declarations to correctly point to
|
||||
* the desired files. For this to work, the files *must* exist and be
|
||||
* visible by the PHP process.
|
||||
*
|
||||
* 'symlinks': (default = array()) If the CSS file is stored in
|
||||
* a symlink-ed directory, provide an array of link paths to
|
||||
* target paths, where the link paths are within the document root. Because
|
||||
* paths need to be normalized for this to work, use "//" to substitute
|
||||
* the doc root in the link paths (the array keys). E.g.:
|
||||
* <code>
|
||||
* array('//symlink' => '/real/target/path') // unix
|
||||
* array('//static' => 'D:\\staticStorage') // Windows
|
||||
* </code>
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function minify($css, $options = array())
|
||||
{
|
||||
require_once 'Minify/CSS/Compressor.php';
|
||||
if (isset($options['preserveComments'])
|
||||
&& !$options['preserveComments']) {
|
||||
$css = Minify_CSS_Compressor::process($css, $options);
|
||||
} else {
|
||||
require_once 'Minify/CommentPreserver.php';
|
||||
$css = Minify_CommentPreserver::process(
|
||||
$css
|
||||
,array('Minify_CSS_Compressor', 'process')
|
||||
,array($options)
|
||||
);
|
||||
}
|
||||
if (! isset($options['currentDir']) && ! isset($options['prependRelativePath'])) {
|
||||
return $css;
|
||||
}
|
||||
require_once 'Minify/CSS/UriRewriter.php';
|
||||
if (isset($options['currentDir'])) {
|
||||
return Minify_CSS_UriRewriter::rewrite(
|
||||
$css
|
||||
,$options['currentDir']
|
||||
,isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT']
|
||||
,isset($options['symlinks']) ? $options['symlinks'] : array()
|
||||
);
|
||||
} else {
|
||||
return Minify_CSS_UriRewriter::prepend(
|
||||
$css
|
||||
,$options['prependRelativePath']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
250
wp-content/plugins/wp-minify/min/lib/Minify/CSS/Compressor.php
Normal file
250
wp-content/plugins/wp-minify/min/lib/Minify/CSS/Compressor.php
Normal file
@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_CSS_Compressor
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Compress CSS
|
||||
*
|
||||
* This is a heavy regex-based removal of whitespace, unnecessary
|
||||
* comments and tokens, and some CSS value minimization, where practical.
|
||||
* Many steps have been taken to avoid breaking comment-based hacks,
|
||||
* including the ie5/mac filter (and its inversion), but expect tricky
|
||||
* hacks involving comment tokens in 'content' value strings to break
|
||||
* minimization badly. A test suite is available.
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
* @author http://code.google.com/u/1stvamp/ (Issue 64 patch)
|
||||
*/
|
||||
class Minify_CSS_Compressor {
|
||||
|
||||
/**
|
||||
* Minify a CSS string
|
||||
*
|
||||
* @param string $css
|
||||
*
|
||||
* @param array $options (currently ignored)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function process($css, $options = array())
|
||||
{
|
||||
$obj = new Minify_CSS_Compressor($options);
|
||||
return $obj->_process($css);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var array options
|
||||
*/
|
||||
protected $_options = null;
|
||||
|
||||
/**
|
||||
* @var bool Are we "in" a hack?
|
||||
*
|
||||
* I.e. are some browsers targetted until the next comment?
|
||||
*/
|
||||
protected $_inHack = false;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options (currently ignored)
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private function __construct($options) {
|
||||
$this->_options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Minify a CSS string
|
||||
*
|
||||
* @param string $css
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _process($css)
|
||||
{
|
||||
$css = str_replace("\r\n", "\n", $css);
|
||||
|
||||
// preserve empty comment after '>'
|
||||
// http://www.webdevout.net/css-hacks#in_css-selectors
|
||||
$css = preg_replace('@>/\\*\\s*\\*/@', '>/*keep*/', $css);
|
||||
|
||||
// preserve empty comment between property and value
|
||||
// http://css-discuss.incutio.com/?page=BoxModelHack
|
||||
$css = preg_replace('@/\\*\\s*\\*/\\s*:@', '/*keep*/:', $css);
|
||||
$css = preg_replace('@:\\s*/\\*\\s*\\*/@', ':/*keep*/', $css);
|
||||
|
||||
// apply callback to all valid comments (and strip out surrounding ws
|
||||
$css = preg_replace_callback('@\\s*/\\*([\\s\\S]*?)\\*/\\s*@'
|
||||
,array($this, '_commentCB'), $css);
|
||||
|
||||
// remove ws around { } and last semicolon in declaration block
|
||||
$css = preg_replace('/\\s*{\\s*/', '{', $css);
|
||||
$css = preg_replace('/;?\\s*}\\s*/', '}', $css);
|
||||
|
||||
// remove ws surrounding semicolons
|
||||
$css = preg_replace('/\\s*;\\s*/', ';', $css);
|
||||
|
||||
// remove ws around urls
|
||||
$css = preg_replace('/
|
||||
url\\( # url(
|
||||
\\s*
|
||||
([^\\)]+?) # 1 = the URL (really just a bunch of non right parenthesis)
|
||||
\\s*
|
||||
\\) # )
|
||||
/x', 'url($1)', $css);
|
||||
|
||||
// remove ws between rules and colons
|
||||
$css = preg_replace('/
|
||||
\\s*
|
||||
([{;]) # 1 = beginning of block or rule separator
|
||||
\\s*
|
||||
([\\*_]?[\\w\\-]+) # 2 = property (and maybe IE filter)
|
||||
\\s*
|
||||
:
|
||||
\\s*
|
||||
(\\b|[#\'"]) # 3 = first character of a value
|
||||
/x', '$1$2:$3', $css);
|
||||
|
||||
// remove ws in selectors
|
||||
$css = preg_replace_callback('/
|
||||
(?: # non-capture
|
||||
\\s*
|
||||
[^~>+,\\s]+ # selector part
|
||||
\\s*
|
||||
[,>+~] # combinators
|
||||
)+
|
||||
\\s*
|
||||
[^~>+,\\s]+ # selector part
|
||||
{ # open declaration block
|
||||
/x'
|
||||
,array($this, '_selectorsCB'), $css);
|
||||
|
||||
// minimize hex colors
|
||||
$css = preg_replace('/([^=])#([a-f\\d])\\2([a-f\\d])\\3([a-f\\d])\\4([\\s;\\}])/i'
|
||||
, '$1#$2$3$4$5', $css);
|
||||
|
||||
// remove spaces between font families
|
||||
$css = preg_replace_callback('/font-family:([^;}]+)([;}])/'
|
||||
,array($this, '_fontFamilyCB'), $css);
|
||||
|
||||
$css = preg_replace('/@import\\s+url/', '@import url', $css);
|
||||
|
||||
// replace any ws involving newlines with a single newline
|
||||
$css = preg_replace('/[ \\t]*\\n+\\s*/', "\n", $css);
|
||||
|
||||
// separate common descendent selectors w/ newlines (to limit line lengths)
|
||||
$css = preg_replace('/([\\w#\\.\\*]+)\\s+([\\w#\\.\\*]+){/', "$1\n$2{", $css);
|
||||
|
||||
// Use newline after 1st numeric value (to limit line lengths).
|
||||
$css = preg_replace('/
|
||||
((?:padding|margin|border|outline):\\d+(?:px|em)?) # 1 = prop : 1st numeric value
|
||||
\\s+
|
||||
/x'
|
||||
,"$1\n", $css);
|
||||
|
||||
// prevent triggering IE6 bug: http://www.crankygeek.com/ie6pebug/
|
||||
$css = preg_replace('/:first-l(etter|ine)\\{/', ':first-l$1 {', $css);
|
||||
|
||||
return trim($css);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace what looks like a set of selectors
|
||||
*
|
||||
* @param array $m regex matches
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _selectorsCB($m)
|
||||
{
|
||||
// remove ws around the combinators
|
||||
return preg_replace('/\\s*([,>+~])\\s*/', '$1', $m[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a comment and return a replacement
|
||||
*
|
||||
* @param array $m regex matches
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _commentCB($m)
|
||||
{
|
||||
$hasSurroundingWs = (trim($m[0]) !== $m[1]);
|
||||
$m = $m[1];
|
||||
// $m is the comment content w/o the surrounding tokens,
|
||||
// but the return value will replace the entire comment.
|
||||
if ($m === 'keep') {
|
||||
return '/**/';
|
||||
}
|
||||
if ($m === '" "') {
|
||||
// component of http://tantek.com/CSS/Examples/midpass.html
|
||||
return '/*" "*/';
|
||||
}
|
||||
if (preg_match('@";\\}\\s*\\}/\\*\\s+@', $m)) {
|
||||
// component of http://tantek.com/CSS/Examples/midpass.html
|
||||
return '/*";}}/* */';
|
||||
}
|
||||
if ($this->_inHack) {
|
||||
// inversion: feeding only to one browser
|
||||
if (preg_match('@
|
||||
^/ # comment started like /*/
|
||||
\\s*
|
||||
(\\S[\\s\\S]+?) # has at least some non-ws content
|
||||
\\s*
|
||||
/\\* # ends like /*/ or /**/
|
||||
@x', $m, $n)) {
|
||||
// end hack mode after this comment, but preserve the hack and comment content
|
||||
$this->_inHack = false;
|
||||
return "/*/{$n[1]}/**/";
|
||||
}
|
||||
}
|
||||
if (substr($m, -1) === '\\') { // comment ends like \*/
|
||||
// begin hack mode and preserve hack
|
||||
$this->_inHack = true;
|
||||
return '/*\\*/';
|
||||
}
|
||||
if ($m !== '' && $m[0] === '/') { // comment looks like /*/ foo */
|
||||
// begin hack mode and preserve hack
|
||||
$this->_inHack = true;
|
||||
return '/*/*/';
|
||||
}
|
||||
if ($this->_inHack) {
|
||||
// a regular comment ends hack mode but should be preserved
|
||||
$this->_inHack = false;
|
||||
return '/**/';
|
||||
}
|
||||
// Issue 107: if there's any surrounding whitespace, it may be important, so
|
||||
// replace the comment with a single space
|
||||
return $hasSurroundingWs // remove all other comments
|
||||
? ' '
|
||||
: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a font-family listing and return a replacement
|
||||
*
|
||||
* @param array $m regex matches
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _fontFamilyCB($m)
|
||||
{
|
||||
$m[1] = preg_replace('/
|
||||
\\s*
|
||||
(
|
||||
"[^"]+" # 1 = family in double qutoes
|
||||
|\'[^\']+\' # or 1 = family in single quotes
|
||||
|[\\w\\-]+ # or 1 = unquoted family
|
||||
)
|
||||
\\s*
|
||||
/x', '$1', $m[1]);
|
||||
return 'font-family:' . $m[1] . $m[2];
|
||||
}
|
||||
}
|
||||
270
wp-content/plugins/wp-minify/min/lib/Minify/CSS/UriRewriter.php
Normal file
270
wp-content/plugins/wp-minify/min/lib/Minify/CSS/UriRewriter.php
Normal file
@ -0,0 +1,270 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_CSS_UriRewriter
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Rewrite file-relative URIs as root-relative in CSS files
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_CSS_UriRewriter {
|
||||
|
||||
/**
|
||||
* Defines which class to call as part of callbacks, change this
|
||||
* if you extend Minify_CSS_UriRewriter
|
||||
* @var string
|
||||
*/
|
||||
protected static $className = 'Minify_CSS_UriRewriter';
|
||||
|
||||
/**
|
||||
* rewrite() and rewriteRelative() append debugging information here
|
||||
* @var string
|
||||
*/
|
||||
public static $debugText = '';
|
||||
|
||||
/**
|
||||
* Rewrite file relative URIs as root relative in CSS files
|
||||
*
|
||||
* @param string $css
|
||||
*
|
||||
* @param string $currentDir The directory of the current CSS file.
|
||||
*
|
||||
* @param string $docRoot The document root of the web site in which
|
||||
* the CSS file resides (default = $_SERVER['DOCUMENT_ROOT']).
|
||||
*
|
||||
* @param array $symlinks (default = array()) If the CSS file is stored in
|
||||
* a symlink-ed directory, provide an array of link paths to
|
||||
* target paths, where the link paths are within the document root. Because
|
||||
* paths need to be normalized for this to work, use "//" to substitute
|
||||
* the doc root in the link paths (the array keys). E.g.:
|
||||
* <code>
|
||||
* array('//symlink' => '/real/target/path') // unix
|
||||
* array('//static' => 'D:\\staticStorage') // Windows
|
||||
* </code>
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function rewrite($css, $currentDir, $docRoot = null, $symlinks = array())
|
||||
{
|
||||
self::$_docRoot = self::_realpath(
|
||||
$docRoot ? $docRoot : $_SERVER['DOCUMENT_ROOT']
|
||||
);
|
||||
self::$_currentDir = self::_realpath($currentDir);
|
||||
self::$_symlinks = array();
|
||||
|
||||
// normalize symlinks
|
||||
foreach ($symlinks as $link => $target) {
|
||||
$link = ($link === '//')
|
||||
? self::$_docRoot
|
||||
: str_replace('//', self::$_docRoot . '/', $link);
|
||||
$link = strtr($link, '/', DIRECTORY_SEPARATOR);
|
||||
self::$_symlinks[$link] = self::_realpath($target);
|
||||
}
|
||||
|
||||
self::$debugText .= "docRoot : " . self::$_docRoot . "\n"
|
||||
. "currentDir : " . self::$_currentDir . "\n";
|
||||
if (self::$_symlinks) {
|
||||
self::$debugText .= "symlinks : " . var_export(self::$_symlinks, 1) . "\n";
|
||||
}
|
||||
self::$debugText .= "\n";
|
||||
|
||||
$css = self::_trimUrls($css);
|
||||
|
||||
// rewrite
|
||||
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
$css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
|
||||
return $css;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend a path to relative URIs in CSS files
|
||||
*
|
||||
* @param string $css
|
||||
*
|
||||
* @param string $path The path to prepend.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function prepend($css, $path)
|
||||
{
|
||||
self::$_prependPath = $path;
|
||||
|
||||
$css = self::_trimUrls($css);
|
||||
|
||||
// append
|
||||
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
$css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
|
||||
self::$_prependPath = null;
|
||||
return $css;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @var string directory of this stylesheet
|
||||
*/
|
||||
private static $_currentDir = '';
|
||||
|
||||
/**
|
||||
* @var string DOC_ROOT
|
||||
*/
|
||||
private static $_docRoot = '';
|
||||
|
||||
/**
|
||||
* @var array directory replacements to map symlink targets back to their
|
||||
* source (within the document root) E.g. '/var/www/symlink' => '/var/realpath'
|
||||
*/
|
||||
private static $_symlinks = array();
|
||||
|
||||
/**
|
||||
* @var string path to prepend
|
||||
*/
|
||||
private static $_prependPath = null;
|
||||
|
||||
private static function _trimUrls($css)
|
||||
{
|
||||
return preg_replace('/
|
||||
url\\( # url(
|
||||
\\s*
|
||||
([^\\)]+?) # 1 = URI (assuming does not contain ")")
|
||||
\\s*
|
||||
\\) # )
|
||||
/x', 'url($1)', $css);
|
||||
}
|
||||
|
||||
private static function _processUriCB($m)
|
||||
{
|
||||
// $m matched either '/@import\\s+([\'"])(.*?)[\'"]/' or '/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
|
||||
$isImport = ($m[0][0] === '@');
|
||||
// determine URI and the quote character (if any)
|
||||
if ($isImport) {
|
||||
$quoteChar = $m[1];
|
||||
$uri = $m[2];
|
||||
} else {
|
||||
// $m[1] is either quoted or not
|
||||
$quoteChar = ($m[1][0] === "'" || $m[1][0] === '"')
|
||||
? $m[1][0]
|
||||
: '';
|
||||
$uri = ($quoteChar === '')
|
||||
? $m[1]
|
||||
: substr($m[1], 1, strlen($m[1]) - 2);
|
||||
}
|
||||
// analyze URI
|
||||
if ('/' !== $uri[0] // root-relative
|
||||
&& false === strpos($uri, '//') // protocol (non-data)
|
||||
&& 0 !== strpos($uri, 'data:') // data protocol
|
||||
) {
|
||||
// URI is file-relative: rewrite depending on options
|
||||
$uri = (self::$_prependPath !== null)
|
||||
? (self::$_prependPath . $uri)
|
||||
: self::rewriteRelative($uri, self::$_currentDir, self::$_docRoot, self::$_symlinks);
|
||||
}
|
||||
return $isImport
|
||||
? "@import {$quoteChar}{$uri}{$quoteChar}"
|
||||
: "url({$quoteChar}{$uri}{$quoteChar})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewrite a file relative URI as root relative
|
||||
*
|
||||
* <code>
|
||||
* Minify_CSS_UriRewriter::rewriteRelative(
|
||||
* '../img/hello.gif'
|
||||
* , '/home/user/www/css' // path of CSS file
|
||||
* , '/home/user/www' // doc root
|
||||
* );
|
||||
* // returns '/img/hello.gif'
|
||||
*
|
||||
* // example where static files are stored in a symlinked directory
|
||||
* Minify_CSS_UriRewriter::rewriteRelative(
|
||||
* 'hello.gif'
|
||||
* , '/var/staticFiles/theme'
|
||||
* , '/home/user/www'
|
||||
* , array('/home/user/www/static' => '/var/staticFiles')
|
||||
* );
|
||||
* // returns '/static/theme/hello.gif'
|
||||
* </code>
|
||||
*
|
||||
* @param string $uri file relative URI
|
||||
*
|
||||
* @param string $realCurrentDir realpath of the current file's directory.
|
||||
*
|
||||
* @param string $realDocRoot realpath of the site document root.
|
||||
*
|
||||
* @param array $symlinks (default = array()) If the file is stored in
|
||||
* a symlink-ed directory, provide an array of link paths to
|
||||
* real target paths, where the link paths "appear" to be within the document
|
||||
* root. E.g.:
|
||||
* <code>
|
||||
* array('/home/foo/www/not/real/path' => '/real/target/path') // unix
|
||||
* array('C:\\htdocs\\not\\real' => 'D:\\real\\target\\path') // Windows
|
||||
* </code>
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function rewriteRelative($uri, $realCurrentDir, $realDocRoot, $symlinks = array())
|
||||
{
|
||||
// prepend path with current dir separator (OS-independent)
|
||||
$path = strtr($realCurrentDir, '/', DIRECTORY_SEPARATOR)
|
||||
. DIRECTORY_SEPARATOR . strtr($uri, '/', DIRECTORY_SEPARATOR);
|
||||
|
||||
self::$debugText .= "file-relative URI : {$uri}\n"
|
||||
. "path prepended : {$path}\n";
|
||||
|
||||
// "unresolve" a symlink back to doc root
|
||||
foreach ($symlinks as $link => $target) {
|
||||
if (0 === strpos($path, $target)) {
|
||||
// replace $target with $link
|
||||
$path = $link . substr($path, strlen($target));
|
||||
|
||||
self::$debugText .= "symlink unresolved : {$path}\n";
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
// strip doc root
|
||||
$path = substr($path, strlen($realDocRoot));
|
||||
|
||||
self::$debugText .= "docroot stripped : {$path}\n";
|
||||
|
||||
// fix to root-relative URI
|
||||
|
||||
$uri = strtr($path, '/\\', '//');
|
||||
|
||||
// remove /./ and /../ where possible
|
||||
$uri = str_replace('/./', '/', $uri);
|
||||
// inspired by patch from Oleg Cherniy
|
||||
do {
|
||||
$uri = preg_replace('@/[^/]+/\\.\\./@', '/', $uri, 1, $changed);
|
||||
} while ($changed);
|
||||
|
||||
self::$debugText .= "traversals removed : {$uri}\n\n";
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get realpath with any trailing slash removed. If realpath() fails,
|
||||
* just remove the trailing slash.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return mixed path with no trailing slash
|
||||
*/
|
||||
protected static function _realpath($path)
|
||||
{
|
||||
$realPath = realpath($path);
|
||||
if ($realPath !== false) {
|
||||
$path = $realPath;
|
||||
}
|
||||
return rtrim($path, '/\\');
|
||||
}
|
||||
}
|
||||
130
wp-content/plugins/wp-minify/min/lib/Minify/Cache/APC.php
Normal file
130
wp-content/plugins/wp-minify/min/lib/Minify/Cache/APC.php
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Cache_APC
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* APC-based cache class for Minify
|
||||
*
|
||||
* <code>
|
||||
* Minify::setCache(new Minify_Cache_APC());
|
||||
* </code>
|
||||
*
|
||||
* @package Minify
|
||||
* @author Chris Edwards
|
||||
**/
|
||||
class Minify_Cache_APC {
|
||||
|
||||
/**
|
||||
* Create a Minify_Cache_APC object, to be passed to
|
||||
* Minify::setCache().
|
||||
*
|
||||
*
|
||||
* @param int $expire seconds until expiration (default = 0
|
||||
* meaning the item will not get an expiration date)
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function __construct($expire = 0)
|
||||
{
|
||||
$this->_exp = $expire;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data to cache.
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @param string $data
|
||||
*
|
||||
* @return bool success
|
||||
*/
|
||||
public function store($id, $data)
|
||||
{
|
||||
return apc_store($id, "{$_SERVER['REQUEST_TIME']}|{$data}", $this->_exp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of a cache entry
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @return int size in bytes
|
||||
*/
|
||||
public function getSize($id)
|
||||
{
|
||||
return $this->_fetch($id)
|
||||
? strlen($this->_data)
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a valid cache entry exist?
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @param int $srcMtime mtime of the original source file(s)
|
||||
*
|
||||
* @return bool exists
|
||||
*/
|
||||
public function isValid($id, $srcMtime)
|
||||
{
|
||||
return ($this->_fetch($id) && ($this->_lm >= $srcMtime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the cached content to output
|
||||
*
|
||||
* @param string $id cache id
|
||||
*/
|
||||
public function display($id)
|
||||
{
|
||||
echo $this->_fetch($id)
|
||||
? $this->_data
|
||||
: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the cached content
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function fetch($id)
|
||||
{
|
||||
return $this->_fetch($id)
|
||||
? $this->_data
|
||||
: '';
|
||||
}
|
||||
|
||||
private $_exp = null;
|
||||
|
||||
// cache of most recently fetched id
|
||||
private $_lm = null;
|
||||
private $_data = null;
|
||||
private $_id = null;
|
||||
|
||||
/**
|
||||
* Fetch data and timestamp from apc, store in instance
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return bool success
|
||||
*/
|
||||
private function _fetch($id)
|
||||
{
|
||||
if ($this->_id === $id) {
|
||||
return true;
|
||||
}
|
||||
$ret = apc_fetch($id);
|
||||
if (false === $ret) {
|
||||
$this->_id = null;
|
||||
return false;
|
||||
}
|
||||
list($this->_lm, $this->_data) = explode('|', $ret, 2);
|
||||
$this->_id = $id;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
125
wp-content/plugins/wp-minify/min/lib/Minify/Cache/File.php
Normal file
125
wp-content/plugins/wp-minify/min/lib/Minify/Cache/File.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Cache_File
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
class Minify_Cache_File {
|
||||
|
||||
public function __construct($path = '', $fileLocking = false)
|
||||
{
|
||||
if (! $path) {
|
||||
require_once 'Solar/Dir.php';
|
||||
$path = rtrim(Solar_Dir::tmp(), DIRECTORY_SEPARATOR);
|
||||
}
|
||||
$this->_locking = $fileLocking;
|
||||
$this->_path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data to cache.
|
||||
*
|
||||
* @param string $id cache id (e.g. a filename)
|
||||
*
|
||||
* @param string $data
|
||||
*
|
||||
* @return bool success
|
||||
*/
|
||||
public function store($id, $data)
|
||||
{
|
||||
$flag = $this->_locking
|
||||
? LOCK_EX
|
||||
: null;
|
||||
if (is_file($this->_path . '/' . $id)) {
|
||||
@unlink($this->_path . '/' . $id);
|
||||
}
|
||||
if (! @file_put_contents($this->_path . '/' . $id, $data, $flag)) {
|
||||
return false;
|
||||
}
|
||||
// write control
|
||||
if ($data !== $this->fetch($id)) {
|
||||
@unlink($file);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of a cache entry
|
||||
*
|
||||
* @param string $id cache id (e.g. a filename)
|
||||
*
|
||||
* @return int size in bytes
|
||||
*/
|
||||
public function getSize($id)
|
||||
{
|
||||
return filesize($this->_path . '/' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a valid cache entry exist?
|
||||
*
|
||||
* @param string $id cache id (e.g. a filename)
|
||||
*
|
||||
* @param int $srcMtime mtime of the original source file(s)
|
||||
*
|
||||
* @return bool exists
|
||||
*/
|
||||
public function isValid($id, $srcMtime)
|
||||
{
|
||||
$file = $this->_path . '/' . $id;
|
||||
return (is_file($file) && (filemtime($file) >= $srcMtime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the cached content to output
|
||||
*
|
||||
* @param string $id cache id (e.g. a filename)
|
||||
*/
|
||||
public function display($id)
|
||||
{
|
||||
if ($this->_locking) {
|
||||
$fp = fopen($this->_path . '/' . $id, 'rb');
|
||||
flock($fp, LOCK_SH);
|
||||
fpassthru($fp);
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
} else {
|
||||
readfile($this->_path . '/' . $id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the cached content
|
||||
*
|
||||
* @param string $id cache id (e.g. a filename)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function fetch($id)
|
||||
{
|
||||
if ($this->_locking) {
|
||||
$fp = fopen($this->_path . '/' . $id, 'rb');
|
||||
flock($fp, LOCK_SH);
|
||||
$ret = stream_get_contents($fp);
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
return $ret;
|
||||
} else {
|
||||
return file_get_contents($this->_path . '/' . $id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the cache path used
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->_path;
|
||||
}
|
||||
|
||||
private $_path = null;
|
||||
private $_locking = null;
|
||||
}
|
||||
137
wp-content/plugins/wp-minify/min/lib/Minify/Cache/Memcache.php
Normal file
137
wp-content/plugins/wp-minify/min/lib/Minify/Cache/Memcache.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Cache_Memcache
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Memcache-based cache class for Minify
|
||||
*
|
||||
* <code>
|
||||
* // fall back to disk caching if memcache can't connect
|
||||
* $memcache = new Memcache;
|
||||
* if ($memcache->connect('localhost', 11211)) {
|
||||
* Minify::setCache(new Minify_Cache_Memcache($memcache));
|
||||
* } else {
|
||||
* Minify::setCache();
|
||||
* }
|
||||
* </code>
|
||||
**/
|
||||
class Minify_Cache_Memcache {
|
||||
|
||||
/**
|
||||
* Create a Minify_Cache_Memcache object, to be passed to
|
||||
* Minify::setCache().
|
||||
*
|
||||
* @param Memcache $memcache already-connected instance
|
||||
*
|
||||
* @param int $expire seconds until expiration (default = 0
|
||||
* meaning the item will not get an expiration date)
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function __construct($memcache, $expire = 0)
|
||||
{
|
||||
$this->_mc = $memcache;
|
||||
$this->_exp = $expire;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data to cache.
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @param string $data
|
||||
*
|
||||
* @return bool success
|
||||
*/
|
||||
public function store($id, $data)
|
||||
{
|
||||
return $this->_mc->set($id, "{$_SERVER['REQUEST_TIME']}|{$data}", 0, $this->_exp);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the size of a cache entry
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @return int size in bytes
|
||||
*/
|
||||
public function getSize($id)
|
||||
{
|
||||
return $this->_fetch($id)
|
||||
? strlen($this->_data)
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a valid cache entry exist?
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @param int $srcMtime mtime of the original source file(s)
|
||||
*
|
||||
* @return bool exists
|
||||
*/
|
||||
public function isValid($id, $srcMtime)
|
||||
{
|
||||
return ($this->_fetch($id) && ($this->_lm >= $srcMtime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the cached content to output
|
||||
*
|
||||
* @param string $id cache id
|
||||
*/
|
||||
public function display($id)
|
||||
{
|
||||
echo $this->_fetch($id)
|
||||
? $this->_data
|
||||
: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the cached content
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function fetch($id)
|
||||
{
|
||||
return $this->_fetch($id)
|
||||
? $this->_data
|
||||
: '';
|
||||
}
|
||||
|
||||
private $_mc = null;
|
||||
private $_exp = null;
|
||||
|
||||
// cache of most recently fetched id
|
||||
private $_lm = null;
|
||||
private $_data = null;
|
||||
private $_id = null;
|
||||
|
||||
/**
|
||||
* Fetch data and timestamp from memcache, store in instance
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return bool success
|
||||
*/
|
||||
private function _fetch($id)
|
||||
{
|
||||
if ($this->_id === $id) {
|
||||
return true;
|
||||
}
|
||||
$ret = $this->_mc->get($id);
|
||||
if (false === $ret) {
|
||||
$this->_id = null;
|
||||
return false;
|
||||
}
|
||||
list($this->_lm, $this->_data) = explode('|', $ret, 2);
|
||||
$this->_id = $id;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_CommentPreserver
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Process a string in pieces preserving C-style comments that begin with "/*!"
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_CommentPreserver {
|
||||
|
||||
/**
|
||||
* String to be prepended to each preserved comment
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $prepend = "\n";
|
||||
|
||||
/**
|
||||
* String to be appended to each preserved comment
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $append = "\n";
|
||||
|
||||
/**
|
||||
* Process a string outside of C-style comments that begin with "/*!"
|
||||
*
|
||||
* On each non-empty string outside these comments, the given processor
|
||||
* function will be called. The first "!" will be removed from the
|
||||
* preserved comments, and the comments will be surrounded by
|
||||
* Minify_CommentPreserver::$preprend and Minify_CommentPreserver::$append.
|
||||
*
|
||||
* @param string $content
|
||||
* @param callback $processor function
|
||||
* @param array $args array of extra arguments to pass to the processor
|
||||
* function (default = array())
|
||||
* @return string
|
||||
*/
|
||||
public static function process($content, $processor, $args = array())
|
||||
{
|
||||
$ret = '';
|
||||
while (true) {
|
||||
list($beforeComment, $comment, $afterComment) = self::_nextComment($content);
|
||||
if ('' !== $beforeComment) {
|
||||
$callArgs = $args;
|
||||
array_unshift($callArgs, $beforeComment);
|
||||
$ret .= call_user_func_array($processor, $callArgs);
|
||||
}
|
||||
if (false === $comment) {
|
||||
break;
|
||||
}
|
||||
$ret .= $comment;
|
||||
$content = $afterComment;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract comments that YUI Compressor preserves.
|
||||
*
|
||||
* @param string $in input
|
||||
*
|
||||
* @return array 3 elements are returned. If a YUI comment is found, the
|
||||
* 2nd element is the comment and the 1st and 2nd are the surrounding
|
||||
* strings. If no comment is found, the entire string is returned as the
|
||||
* 1st element and the other two are false.
|
||||
*/
|
||||
private static function _nextComment($in)
|
||||
{
|
||||
if (
|
||||
false === ($start = strpos($in, '/*!'))
|
||||
|| false === ($end = strpos($in, '*/', $start + 3))
|
||||
) {
|
||||
return array($in, false, false);
|
||||
}
|
||||
$ret = array(
|
||||
substr($in, 0, $start)
|
||||
,self::$prepend . '/*' . substr($in, $start + 3, $end - $start - 1) . self::$append
|
||||
);
|
||||
$endChars = (strlen($in) - $end - 2);
|
||||
$ret[] = (0 === $endChars)
|
||||
? ''
|
||||
: substr($in, -$endChars);
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
202
wp-content/plugins/wp-minify/min/lib/Minify/Controller/Base.php
Normal file
202
wp-content/plugins/wp-minify/min/lib/Minify/Controller/Base.php
Normal file
@ -0,0 +1,202 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Controller_Base
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for Minify controller
|
||||
*
|
||||
* The controller class validates a request and uses it to create sources
|
||||
* for minification and set options like contentType. It's also responsible
|
||||
* for loading minifier code upon request.
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
abstract class Minify_Controller_Base {
|
||||
|
||||
/**
|
||||
* Setup controller sources and set an needed options for Minify::source
|
||||
*
|
||||
* You must override this method in your subclass controller to set
|
||||
* $this->sources. If the request is NOT valid, make sure $this->sources
|
||||
* is left an empty array. Then strip any controller-specific options from
|
||||
* $options and return it. To serve files, $this->sources must be an array of
|
||||
* Minify_Source objects.
|
||||
*
|
||||
* @param array $options controller and Minify options
|
||||
*
|
||||
* return array $options Minify::serve options
|
||||
*/
|
||||
abstract public function setupSources($options);
|
||||
|
||||
/**
|
||||
* Get default Minify options for this controller.
|
||||
*
|
||||
* Override in subclass to change defaults
|
||||
*
|
||||
* @return array options for Minify
|
||||
*/
|
||||
public function getDefaultMinifyOptions() {
|
||||
return array(
|
||||
'isPublic' => true
|
||||
,'encodeOutput' => function_exists('gzdeflate')
|
||||
,'encodeMethod' => null // determine later
|
||||
,'encodeLevel' => 9
|
||||
,'minifierOptions' => array() // no minifier options
|
||||
,'contentTypeCharset' => 'utf-8'
|
||||
,'maxAge' => 1800 // 30 minutes
|
||||
,'rewriteCssUris' => true
|
||||
,'bubbleCssImports' => false
|
||||
,'quiet' => false // serve() will send headers and output
|
||||
,'debug' => false
|
||||
|
||||
// if you override this, the response code MUST be directly after
|
||||
// the first space.
|
||||
,'badRequestHeader' => 'HTTP/1.0 400 Bad Request'
|
||||
|
||||
// callback function to see/modify content of all sources
|
||||
,'postprocessor' => null
|
||||
// file to require to load preprocessor
|
||||
,'postprocessorRequire' => null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default minifiers for this controller.
|
||||
*
|
||||
* Override in subclass to change defaults
|
||||
*
|
||||
* @return array minifier callbacks for common types
|
||||
*/
|
||||
public function getDefaultMinifers() {
|
||||
$ret[Minify::TYPE_JS] = array('JSMin', 'minify');
|
||||
$ret[Minify::TYPE_CSS] = array('Minify_CSS', 'minify');
|
||||
$ret[Minify::TYPE_HTML] = array('Minify_HTML', 'minify');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load any code necessary to execute the given minifier callback.
|
||||
*
|
||||
* The controller is responsible for loading minification code on demand
|
||||
* via this method. This built-in function will only load classes for
|
||||
* static method callbacks where the class isn't already defined. It uses
|
||||
* the PEAR convention, so, given array('Jimmy_Minifier', 'minCss'), this
|
||||
* function will include 'Jimmy/Minifier.php'.
|
||||
*
|
||||
* If you need code loaded on demand and this doesn't suit you, you'll need
|
||||
* to override this function in your subclass.
|
||||
* @see Minify_Controller_Page::loadMinifier()
|
||||
*
|
||||
* @param callback $minifierCallback callback of minifier function
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function loadMinifier($minifierCallback)
|
||||
{
|
||||
if (is_array($minifierCallback)
|
||||
&& is_string($minifierCallback[0])
|
||||
&& !class_exists($minifierCallback[0], false)) {
|
||||
|
||||
require str_replace('_', '/', $minifierCallback[0]) . '.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a user-given file within an allowable directory, existing,
|
||||
* and having an extension js/css/html/txt ?
|
||||
*
|
||||
* This is a convenience function for controllers that have to accept
|
||||
* user-given paths
|
||||
*
|
||||
* @param string $file full file path (already processed by realpath())
|
||||
*
|
||||
* @param array $safeDirs directories where files are safe to serve. Files can also
|
||||
* be in subdirectories of these directories.
|
||||
*
|
||||
* @return bool file is safe
|
||||
*/
|
||||
public static function _fileIsSafe($file, $safeDirs)
|
||||
{
|
||||
$pathOk = false;
|
||||
foreach ((array)$safeDirs as $safeDir) {
|
||||
if (strpos($file, $safeDir) === 0) {
|
||||
$pathOk = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$base = basename($file);
|
||||
if (! $pathOk || ! is_file($file) || $base[0] === '.') {
|
||||
return false;
|
||||
}
|
||||
list($revExt) = explode('.', strrev($base));
|
||||
return in_array(strrev($revExt), array('js', 'css', 'html', 'txt'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @var array instances of Minify_Source, which provide content and
|
||||
* any individual minification needs.
|
||||
*
|
||||
* @see Minify_Source
|
||||
*/
|
||||
public $sources = array();
|
||||
|
||||
/**
|
||||
* Mix in default controller options with user-given options
|
||||
*
|
||||
* @param array $options user options
|
||||
*
|
||||
* @return array mixed options
|
||||
*/
|
||||
public final function mixInDefaultOptions($options)
|
||||
{
|
||||
$ret = array_merge(
|
||||
$this->getDefaultMinifyOptions(), $options
|
||||
);
|
||||
if (! isset($options['minifiers'])) {
|
||||
$options['minifiers'] = array();
|
||||
}
|
||||
$ret['minifiers'] = array_merge(
|
||||
$this->getDefaultMinifers(), $options['minifiers']
|
||||
);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze sources (if there are any) and set $options 'contentType'
|
||||
* and 'lastModifiedTime' if they already aren't.
|
||||
*
|
||||
* @param array $options options for Minify
|
||||
*
|
||||
* @return array options for Minify
|
||||
*/
|
||||
public final function analyzeSources($options = array())
|
||||
{
|
||||
if ($this->sources) {
|
||||
if (! isset($options['contentType'])) {
|
||||
$options['contentType'] = Minify_Source::getContentType($this->sources);
|
||||
}
|
||||
// last modified is needed for caching, even if setExpires is set
|
||||
if (! isset($options['lastModifiedTime'])) {
|
||||
$max = 0;
|
||||
foreach ($this->sources as $source) {
|
||||
$max = max($source->lastModified, $max);
|
||||
}
|
||||
$options['lastModifiedTime'] = $max;
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send message to the Minify logger
|
||||
* @param string $msg
|
||||
* @return null
|
||||
*/
|
||||
protected function log($msg) {
|
||||
require_once 'Minify/Logger.php';
|
||||
Minify_Logger::log($msg);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Controller_Files
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once 'Minify/Controller/Base.php';
|
||||
|
||||
/**
|
||||
* Controller class for minifying a set of files
|
||||
*
|
||||
* E.g. the following would serve the minified Javascript for a site
|
||||
* <code>
|
||||
* Minify::serve('Files', array(
|
||||
* 'files' => array(
|
||||
* '//js/jquery.js'
|
||||
* ,'//js/plugins.js'
|
||||
* ,'/home/username/file.js'
|
||||
* )
|
||||
* ));
|
||||
* </code>
|
||||
*
|
||||
* As a shortcut, the controller will replace "//" at the beginning
|
||||
* of a filename with $_SERVER['DOCUMENT_ROOT'] . '/'.
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_Controller_Files extends Minify_Controller_Base {
|
||||
|
||||
/**
|
||||
* Set up file sources
|
||||
*
|
||||
* @param array $options controller and Minify options
|
||||
* @return array Minify options
|
||||
*
|
||||
* Controller options:
|
||||
*
|
||||
* 'files': (required) array of complete file paths, or a single path
|
||||
*/
|
||||
public function setupSources($options) {
|
||||
// strip controller options
|
||||
|
||||
$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();
|
||||
foreach ($files as $file) {
|
||||
if ($file instanceof Minify_Source) {
|
||||
$sources[] = $file;
|
||||
continue;
|
||||
}
|
||||
if (0 === strpos($file, '//')) {
|
||||
$file = $_SERVER['DOCUMENT_ROOT'] . substr($file, 1);
|
||||
}
|
||||
$realPath = realpath($file);
|
||||
if (is_file($realPath)) {
|
||||
$sources[] = new Minify_Source(array(
|
||||
'filepath' => $realPath
|
||||
));
|
||||
} else {
|
||||
$this->log("The path \"{$file}\" could not be found (or was not a file)");
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
if ($sources) {
|
||||
$this->sources = $sources;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Controller_Groups
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once 'Minify/Controller/Base.php';
|
||||
|
||||
/**
|
||||
* Controller class for serving predetermined groups of minimized sets, selected
|
||||
* by PATH_INFO
|
||||
*
|
||||
* <code>
|
||||
* Minify::serve('Groups', array(
|
||||
* 'groups' => array(
|
||||
* 'css' => array('//css/type.css', '//css/layout.css')
|
||||
* ,'js' => array('//js/jquery.js', '//js/site.js')
|
||||
* )
|
||||
* ));
|
||||
* </code>
|
||||
*
|
||||
* If the above code were placed in /serve.php, it would enable the URLs
|
||||
* /serve.php/js and /serve.php/css
|
||||
*
|
||||
* As a shortcut, the controller will replace "//" at the beginning
|
||||
* of a filename with $_SERVER['DOCUMENT_ROOT'] . '/'.
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_Controller_Groups extends Minify_Controller_Base {
|
||||
|
||||
/**
|
||||
* Set up groups of files as sources
|
||||
*
|
||||
* @param array $options controller and Minify options
|
||||
* @return array Minify options
|
||||
*
|
||||
* Controller options:
|
||||
*
|
||||
* 'groups': (required) array mapping PATH_INFO strings to arrays
|
||||
* of complete file paths. @see Minify_Controller_Groups
|
||||
*/
|
||||
public function setupSources($options) {
|
||||
// strip controller options
|
||||
$groups = $options['groups'];
|
||||
unset($options['groups']);
|
||||
|
||||
// mod_fcgid places PATH_INFO in ORIG_PATH_INFO
|
||||
$pi = isset($_SERVER['ORIG_PATH_INFO'])
|
||||
? substr($_SERVER['ORIG_PATH_INFO'], 1)
|
||||
: (isset($_SERVER['PATH_INFO'])
|
||||
? substr($_SERVER['PATH_INFO'], 1)
|
||||
: false
|
||||
);
|
||||
if (false === $pi || ! isset($groups[$pi])) {
|
||||
// no PATH_INFO or not a valid group
|
||||
$this->log("Missing PATH_INFO or no group set for \"$pi\"");
|
||||
return $options;
|
||||
}
|
||||
$sources = array();
|
||||
|
||||
$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;
|
||||
}
|
||||
if (0 === strpos($file, '//')) {
|
||||
$file = $_SERVER['DOCUMENT_ROOT'] . substr($file, 1);
|
||||
}
|
||||
$realPath = realpath($file);
|
||||
if (is_file($realPath)) {
|
||||
$sources[] = new Minify_Source(array(
|
||||
'filepath' => $realPath
|
||||
));
|
||||
} else {
|
||||
$this->log("The path \"{$file}\" could not be found (or was not a file)");
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
if ($sources) {
|
||||
$this->sources = $sources;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Controller_MinApp
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once 'Minify/Controller/Base.php';
|
||||
|
||||
/**
|
||||
* Controller class for requests to /min/index.php
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_Controller_MinApp extends Minify_Controller_Base {
|
||||
|
||||
/**
|
||||
* Set up groups of files as sources
|
||||
*
|
||||
* @param array $options controller and Minify options
|
||||
* @return array Minify options
|
||||
*
|
||||
*/
|
||||
public function setupSources($options) {
|
||||
// filter controller options
|
||||
$cOptions = array_merge(
|
||||
array(
|
||||
'allowDirs' => '//'
|
||||
,'groupsOnly' => false
|
||||
,'groups' => array()
|
||||
,'maxFiles' => 10
|
||||
)
|
||||
,(isset($options['minApp']) ? $options['minApp'] : array())
|
||||
);
|
||||
unset($options['minApp']);
|
||||
$sources = array();
|
||||
if (isset($_GET['g'])) {
|
||||
// try groups
|
||||
if (! isset($cOptions['groups'][$_GET['g']])) {
|
||||
$this->log("A group configuration for \"{$_GET['g']}\" was not set");
|
||||
return $options;
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
if (0 === strpos($file, '//')) {
|
||||
$file = $_SERVER['DOCUMENT_ROOT'] . substr($file, 1);
|
||||
}
|
||||
$file = realpath($file);
|
||||
if (is_file($file)) {
|
||||
$sources[] = new Minify_Source(array(
|
||||
'filepath' => $file
|
||||
));
|
||||
} else {
|
||||
$this->log("The path \"{$file}\" could not be found (or was not a file)");
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
} elseif (! $cOptions['groupsOnly'] && isset($_GET['f'])) {
|
||||
// try user files
|
||||
// The following restrictions are to limit the URLs that minify will
|
||||
// respond to. Ideally there should be only one way to reference a file.
|
||||
if (// verify at least one file, files are single comma separated,
|
||||
// and are all same extension
|
||||
! preg_match('/^[^,]+\\.(css|js)(?:,[^,]+\\.\\1)*$/', $_GET['f'])
|
||||
// no "//"
|
||||
|| strpos($_GET['f'], '//') !== false
|
||||
// no "\"
|
||||
|| strpos($_GET['f'], '\\') !== false
|
||||
// no "./"
|
||||
|| preg_match('/(?:^|[^\\.])\\.\\//', $_GET['f'])
|
||||
) {
|
||||
$this->log("GET param 'f' invalid (see MinApp.php line 63)");
|
||||
return $options;
|
||||
}
|
||||
$files = explode(',', $_GET['f']);
|
||||
if (count($files) > $cOptions['maxFiles'] || $files != array_unique($files)) {
|
||||
$this->log("Too many or duplicate files specified");
|
||||
return $options;
|
||||
}
|
||||
if (isset($_GET['b'])) {
|
||||
// check for validity
|
||||
if (preg_match('@^[^/]+(?:/[^/]+)*$@', $_GET['b'])
|
||||
&& false === strpos($_GET['b'], '..')
|
||||
&& $_GET['b'] !== '.') {
|
||||
// valid base
|
||||
$base = "/{$_GET['b']}/";
|
||||
} else {
|
||||
$this->log("GET param 'b' invalid (see MinApp.php line 84)");
|
||||
return $options;
|
||||
}
|
||||
} else {
|
||||
$base = '/';
|
||||
}
|
||||
$allowDirs = array();
|
||||
foreach ((array)$cOptions['allowDirs'] as $allowDir) {
|
||||
$allowDirs[] = realpath(str_replace('//', $_SERVER['DOCUMENT_ROOT'] . '/', $allowDir));
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
$path = $_SERVER['DOCUMENT_ROOT'] . $base . $file;
|
||||
$file = realpath($path);
|
||||
if (false === $file) {
|
||||
$this->log("Path \"{$path}\" failed realpath()");
|
||||
return $options;
|
||||
} elseif (! parent::_fileIsSafe($file, $allowDirs)) {
|
||||
$this->log("Path \"{$path}\" failed Minify_Controller_Base::_fileIsSafe()");
|
||||
return $options;
|
||||
} else {
|
||||
$sources[] = new Minify_Source(array(
|
||||
'filepath' => $file
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($sources) {
|
||||
$this->sources = $sources;
|
||||
} else {
|
||||
$this->log("No sources to serve");
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
<?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']
|
||||
);
|
||||
} else {
|
||||
// strip controller options
|
||||
$sourceSpec = array(
|
||||
'content' => $options['content']
|
||||
,'id' => $options['id']
|
||||
);
|
||||
unset($options['content'], $options['id']);
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Controller_Version1
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once 'Minify/Controller/Base.php';
|
||||
|
||||
/**
|
||||
* Controller class for emulating version 1 of minify.php
|
||||
*
|
||||
* <code>
|
||||
* Minify::serve('Version1');
|
||||
* </code>
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_Controller_Version1 extends Minify_Controller_Base {
|
||||
|
||||
/**
|
||||
* Set up groups of files as sources
|
||||
*
|
||||
* @param array $options controller and Minify options
|
||||
* @return array Minify options
|
||||
*
|
||||
*/
|
||||
public function setupSources($options) {
|
||||
self::_setupDefines();
|
||||
if (MINIFY_USE_CACHE) {
|
||||
$cacheDir = defined('MINIFY_CACHE_DIR')
|
||||
? MINIFY_CACHE_DIR
|
||||
: '';
|
||||
Minify::setCache($cacheDir);
|
||||
}
|
||||
$options['badRequestHeader'] = 'HTTP/1.0 404 Not Found';
|
||||
$options['contentTypeCharset'] = MINIFY_ENCODING;
|
||||
|
||||
// The following restrictions are to limit the URLs that minify will
|
||||
// respond to. Ideally there should be only one way to reference a file.
|
||||
if (! isset($_GET['files'])
|
||||
// verify at least one file, files are single comma separated,
|
||||
// and are all same extension
|
||||
|| ! preg_match('/^[^,]+\\.(css|js)(,[^,]+\\.\\1)*$/', $_GET['files'], $m)
|
||||
// no "//" (makes URL rewriting easier)
|
||||
|| strpos($_GET['files'], '//') !== false
|
||||
// no "\"
|
||||
|| strpos($_GET['files'], '\\') !== false
|
||||
// no "./"
|
||||
|| preg_match('/(?:^|[^\\.])\\.\\//', $_GET['files'])
|
||||
) {
|
||||
return $options;
|
||||
}
|
||||
$extension = $m[1];
|
||||
|
||||
$files = explode(',', $_GET['files']);
|
||||
if (count($files) > MINIFY_MAX_FILES) {
|
||||
return $options;
|
||||
}
|
||||
|
||||
// strings for prepending to relative/absolute paths
|
||||
$prependRelPaths = dirname($_SERVER['SCRIPT_FILENAME'])
|
||||
. DIRECTORY_SEPARATOR;
|
||||
$prependAbsPaths = $_SERVER['DOCUMENT_ROOT'];
|
||||
|
||||
$sources = array();
|
||||
$goodFiles = array();
|
||||
$hasBadSource = false;
|
||||
|
||||
$allowDirs = isset($options['allowDirs'])
|
||||
? $options['allowDirs']
|
||||
: MINIFY_BASE_DIR;
|
||||
|
||||
foreach ($files as $file) {
|
||||
// prepend appropriate string for abs/rel paths
|
||||
$file = ($file[0] === '/' ? $prependAbsPaths : $prependRelPaths) . $file;
|
||||
// make sure a real file!
|
||||
$file = realpath($file);
|
||||
// don't allow unsafe or duplicate files
|
||||
if (parent::_fileIsSafe($file, $allowDirs)
|
||||
&& !in_array($file, $goodFiles))
|
||||
{
|
||||
$goodFiles[] = $file;
|
||||
$srcOptions = array(
|
||||
'filepath' => $file
|
||||
);
|
||||
$this->sources[] = new Minify_Source($srcOptions);
|
||||
} else {
|
||||
$hasBadSource = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($hasBadSource) {
|
||||
$this->sources = array();
|
||||
}
|
||||
if (! MINIFY_REWRITE_CSS_URLS) {
|
||||
$options['rewriteCssUris'] = false;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
private static function _setupDefines()
|
||||
{
|
||||
$defaults = array(
|
||||
'MINIFY_BASE_DIR' => realpath($_SERVER['DOCUMENT_ROOT'])
|
||||
,'MINIFY_ENCODING' => 'utf-8'
|
||||
,'MINIFY_MAX_FILES' => 16
|
||||
,'MINIFY_REWRITE_CSS_URLS' => true
|
||||
,'MINIFY_USE_CACHE' => true
|
||||
);
|
||||
foreach ($defaults as $const => $val) {
|
||||
if (! defined($const)) {
|
||||
define($const, $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
245
wp-content/plugins/wp-minify/min/lib/Minify/HTML.php
Normal file
245
wp-content/plugins/wp-minify/min/lib/Minify/HTML.php
Normal file
@ -0,0 +1,245 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_HTML
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Compress HTML
|
||||
*
|
||||
* This is a heavy regex-based removal of whitespace, unnecessary comments and
|
||||
* tokens. IE conditional comments are preserved. There are also options to have
|
||||
* STYLE and SCRIPT blocks compressed by callback functions.
|
||||
*
|
||||
* A test suite is available.
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_HTML {
|
||||
|
||||
/**
|
||||
* "Minify" an HTML page
|
||||
*
|
||||
* @param string $html
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* 'cssMinifier' : (optional) callback function to process content of STYLE
|
||||
* elements.
|
||||
*
|
||||
* 'jsMinifier' : (optional) callback function to process content of SCRIPT
|
||||
* elements. Note: the type attribute is ignored.
|
||||
*
|
||||
* 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
|
||||
* unset, minify will sniff for an XHTML doctype.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function minify($html, $options = array()) {
|
||||
$min = new Minify_HTML($html, $options);
|
||||
return $min->process();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a minifier object
|
||||
*
|
||||
* @param string $html
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* 'cssMinifier' : (optional) callback function to process content of STYLE
|
||||
* elements.
|
||||
*
|
||||
* 'jsMinifier' : (optional) callback function to process content of SCRIPT
|
||||
* elements. Note: the type attribute is ignored.
|
||||
*
|
||||
* 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
|
||||
* unset, minify will sniff for an XHTML doctype.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function __construct($html, $options = array())
|
||||
{
|
||||
$this->_html = str_replace("\r\n", "\n", trim($html));
|
||||
if (isset($options['xhtml'])) {
|
||||
$this->_isXhtml = (bool)$options['xhtml'];
|
||||
}
|
||||
if (isset($options['cssMinifier'])) {
|
||||
$this->_cssMinifier = $options['cssMinifier'];
|
||||
}
|
||||
if (isset($options['jsMinifier'])) {
|
||||
$this->_jsMinifier = $options['jsMinifier'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Minify the markeup given in the constructor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
if ($this->_isXhtml === null) {
|
||||
$this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
|
||||
}
|
||||
|
||||
$this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
|
||||
$this->_placeholders = array();
|
||||
|
||||
// replace SCRIPTs (and minify) with placeholders
|
||||
$this->_html = preg_replace_callback(
|
||||
'/(\\s*)(<script\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/i'
|
||||
,array($this, '_removeScriptCB')
|
||||
,$this->_html);
|
||||
|
||||
// replace STYLEs (and minify) with placeholders
|
||||
$this->_html = preg_replace_callback(
|
||||
'/\\s*(<style\\b[^>]*?>)([\\s\\S]*?)<\\/style>\\s*/i'
|
||||
,array($this, '_removeStyleCB')
|
||||
,$this->_html);
|
||||
|
||||
// remove HTML comments (not containing IE conditional comments).
|
||||
$this->_html = preg_replace_callback(
|
||||
'/<!--([\\s\\S]*?)-->/'
|
||||
,array($this, '_commentCB')
|
||||
,$this->_html);
|
||||
|
||||
// replace PREs with placeholders
|
||||
$this->_html = preg_replace_callback('/\\s*(<pre\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i'
|
||||
,array($this, '_removePreCB')
|
||||
,$this->_html);
|
||||
|
||||
// replace TEXTAREAs with placeholders
|
||||
$this->_html = preg_replace_callback(
|
||||
'/\\s*(<textarea\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i'
|
||||
,array($this, '_removeTextareaCB')
|
||||
,$this->_html);
|
||||
|
||||
// trim each line.
|
||||
// @todo take into account attribute values that span multiple lines.
|
||||
$this->_html = preg_replace('/^\\s+|\\s+$/m', '', $this->_html);
|
||||
|
||||
// remove ws around block/undisplayed elements
|
||||
$this->_html = preg_replace('/\\s+(<\\/?(?:area|base(?:font)?|blockquote|body'
|
||||
.'|caption|center|cite|col(?:group)?|dd|dir|div|dl|dt|fieldset|form'
|
||||
.'|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta'
|
||||
.'|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h||r|foot|itle)'
|
||||
.'|ul)\\b[^>]*>)/i', '$1', $this->_html);
|
||||
|
||||
// remove ws outside of all elements
|
||||
$this->_html = preg_replace_callback(
|
||||
'/>([^<]+)</'
|
||||
,array($this, '_outsideTagCB')
|
||||
,$this->_html);
|
||||
|
||||
// use newlines before 1st attribute in open tags (to limit line lengths)
|
||||
$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html);
|
||||
|
||||
// fill placeholders
|
||||
$this->_html = str_replace(
|
||||
array_keys($this->_placeholders)
|
||||
,array_values($this->_placeholders)
|
||||
,$this->_html
|
||||
);
|
||||
return $this->_html;
|
||||
}
|
||||
|
||||
protected function _commentCB($m)
|
||||
{
|
||||
return (0 === strpos($m[1], '[') || false !== strpos($m[1], '<!['))
|
||||
? $m[0]
|
||||
: '';
|
||||
}
|
||||
|
||||
protected function _reservePlace($content)
|
||||
{
|
||||
$placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%';
|
||||
$this->_placeholders[$placeholder] = $content;
|
||||
return $placeholder;
|
||||
}
|
||||
|
||||
protected $_isXhtml = null;
|
||||
protected $_replacementHash = null;
|
||||
protected $_placeholders = array();
|
||||
protected $_cssMinifier = null;
|
||||
protected $_jsMinifier = null;
|
||||
|
||||
protected function _outsideTagCB($m)
|
||||
{
|
||||
return '>' . preg_replace('/^\\s+|\\s+$/', ' ', $m[1]) . '<';
|
||||
}
|
||||
|
||||
protected function _removePreCB($m)
|
||||
{
|
||||
return $this->_reservePlace($m[1]);
|
||||
}
|
||||
|
||||
protected function _removeTextareaCB($m)
|
||||
{
|
||||
return $this->_reservePlace($m[1]);
|
||||
}
|
||||
|
||||
protected function _removeStyleCB($m)
|
||||
{
|
||||
$openStyle = $m[1];
|
||||
$css = $m[2];
|
||||
// remove HTML comments
|
||||
$css = preg_replace('/(?:^\\s*<!--|-->\\s*$)/', '', $css);
|
||||
|
||||
// remove CDATA section markers
|
||||
$css = $this->_removeCdata($css);
|
||||
|
||||
// minify
|
||||
$minifier = $this->_cssMinifier
|
||||
? $this->_cssMinifier
|
||||
: 'trim';
|
||||
$css = call_user_func($minifier, $css);
|
||||
|
||||
return $this->_reservePlace($this->_needsCdata($css)
|
||||
? "{$openStyle}/*<![CDATA[*/{$css}/*]]>*/</style>"
|
||||
: "{$openStyle}{$css}</style>"
|
||||
);
|
||||
}
|
||||
|
||||
protected function _removeScriptCB($m)
|
||||
{
|
||||
$openScript = $m[2];
|
||||
$js = $m[3];
|
||||
|
||||
// whitespace surrounding? preserve at least one space
|
||||
$ws1 = ($m[1] === '') ? '' : ' ';
|
||||
$ws2 = ($m[4] === '') ? '' : ' ';
|
||||
|
||||
// remove HTML comments (and ending "//" if present)
|
||||
$js = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $js);
|
||||
|
||||
// remove CDATA section markers
|
||||
$js = $this->_removeCdata($js);
|
||||
|
||||
// minify
|
||||
$minifier = $this->_jsMinifier
|
||||
? $this->_jsMinifier
|
||||
: 'trim';
|
||||
$js = call_user_func($minifier, $js);
|
||||
|
||||
return $this->_reservePlace($this->_needsCdata($js)
|
||||
? "{$ws1}{$openScript}/*<![CDATA[*/{$js}/*]]>*/</script>{$ws2}"
|
||||
: "{$ws1}{$openScript}{$js}</script>{$ws2}"
|
||||
);
|
||||
}
|
||||
|
||||
protected function _removeCdata($str)
|
||||
{
|
||||
return (false !== strpos($str, '<![CDATA['))
|
||||
? str_replace(array('<![CDATA[', ']]>'), '', $str)
|
||||
: $str;
|
||||
}
|
||||
|
||||
protected function _needsCdata($str)
|
||||
{
|
||||
return ($this->_isXhtml && preg_match('/(?:[<&]|\\-\\-|\\]\\]>)/', $str));
|
||||
}
|
||||
}
|
||||
157
wp-content/plugins/wp-minify/min/lib/Minify/ImportProcessor.php
Normal file
157
wp-content/plugins/wp-minify/min/lib/Minify/ImportProcessor.php
Normal file
@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_ImportProcessor
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Linearize a CSS/JS file by including content specified by CSS import
|
||||
* declarations. In CSS files, relative URIs are fixed.
|
||||
*
|
||||
* @imports will be processed regardless of where they appear in the source
|
||||
* files; i.e. @imports commented out or in string content will still be
|
||||
* processed!
|
||||
*
|
||||
* This has a unit test but should be considered "experimental".
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_ImportProcessor {
|
||||
|
||||
public static $filesIncluded = array();
|
||||
|
||||
public static function process($file)
|
||||
{
|
||||
self::$filesIncluded = array();
|
||||
self::$_isCss = (strtolower(substr($file, -4)) === '.css');
|
||||
$obj = new Minify_ImportProcessor(dirname($file));
|
||||
return $obj->_getContent($file);
|
||||
}
|
||||
|
||||
// allows callback funcs to know the current directory
|
||||
private $_currentDir = null;
|
||||
|
||||
// allows _importCB to write the fetched content back to the obj
|
||||
private $_importedContent = '';
|
||||
|
||||
private static $_isCss = null;
|
||||
|
||||
private function __construct($currentDir)
|
||||
{
|
||||
$this->_currentDir = $currentDir;
|
||||
}
|
||||
|
||||
private function _getContent($file)
|
||||
{
|
||||
$file = realpath($file);
|
||||
if (! $file
|
||||
|| in_array($file, self::$filesIncluded)
|
||||
|| false === ($content = @file_get_contents($file))
|
||||
) {
|
||||
// file missing, already included, or failed read
|
||||
return '';
|
||||
}
|
||||
self::$filesIncluded[] = realpath($file);
|
||||
$this->_currentDir = dirname($file);
|
||||
|
||||
// remove UTF-8 BOM if present
|
||||
if (pack("CCC",0xef,0xbb,0xbf) === substr($content, 0, 3)) {
|
||||
$content = substr($content, 3);
|
||||
}
|
||||
// ensure uniform EOLs
|
||||
$content = str_replace("\r\n", "\n", $content);
|
||||
|
||||
// process @imports
|
||||
$content = preg_replace_callback(
|
||||
'/
|
||||
@import\\s+
|
||||
(?:url\\(\\s*)? # maybe url(
|
||||
[\'"]? # maybe quote
|
||||
(.*?) # 1 = URI
|
||||
[\'"]? # maybe end quote
|
||||
(?:\\s*\\))? # maybe )
|
||||
([a-zA-Z,\\s]*)? # 2 = media list
|
||||
; # end token
|
||||
/x'
|
||||
,array($this, '_importCB')
|
||||
,$content
|
||||
);
|
||||
|
||||
if (self::$_isCss) {
|
||||
// rewrite remaining relative URIs
|
||||
$content = preg_replace_callback(
|
||||
'/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
|
||||
,array($this, '_urlCB')
|
||||
,$content
|
||||
);
|
||||
}
|
||||
|
||||
return $this->_importedContent . $content;
|
||||
}
|
||||
|
||||
private function _importCB($m)
|
||||
{
|
||||
$url = $m[1];
|
||||
$mediaList = preg_replace('/\\s+/', '', $m[2]);
|
||||
|
||||
if (strpos($url, '://') > 0) {
|
||||
// protocol, leave in place for CSS, comment for JS
|
||||
return self::$_isCss
|
||||
? $m[0]
|
||||
: "/* Minify_ImportProcessor will not include remote content */";
|
||||
}
|
||||
if ('/' === $url[0]) {
|
||||
// protocol-relative or root path
|
||||
$url = ltrim($url, '/');
|
||||
$file = realpath($_SERVER['DOCUMENT_ROOT']) . DIRECTORY_SEPARATOR
|
||||
. strtr($url, '/', DIRECTORY_SEPARATOR);
|
||||
} else {
|
||||
// relative to current path
|
||||
$file = $this->_currentDir . DIRECTORY_SEPARATOR
|
||||
. strtr($url, '/', DIRECTORY_SEPARATOR);
|
||||
}
|
||||
$obj = new Minify_ImportProcessor(dirname($file));
|
||||
$content = $obj->_getContent($file);
|
||||
if ('' === $content) {
|
||||
// failed. leave in place for CSS, comment for JS
|
||||
return self::$_isCss
|
||||
? $m[0]
|
||||
: "/* Minify_ImportProcessor could not fetch '{$file}' */";;
|
||||
}
|
||||
return (!self::$_isCss || preg_match('@(?:^$|\\ball\\b)@', $mediaList))
|
||||
? $content
|
||||
: "@media {$mediaList} {\n{$content}\n}\n";
|
||||
}
|
||||
|
||||
private function _urlCB($m)
|
||||
{
|
||||
// $m[1] is either quoted or not
|
||||
$quote = ($m[1][0] === "'" || $m[1][0] === '"')
|
||||
? $m[1][0]
|
||||
: '';
|
||||
$url = ($quote === '')
|
||||
? $m[1]
|
||||
: substr($m[1], 1, strlen($m[1]) - 2);
|
||||
if ('/' !== $url[0]) {
|
||||
if (strpos($url, '//') > 0) {
|
||||
// probably starts with protocol, do not alter
|
||||
} else {
|
||||
// prepend path with current dir separator (OS-independent)
|
||||
$path = $this->_currentDir
|
||||
. DIRECTORY_SEPARATOR . strtr($url, '/', DIRECTORY_SEPARATOR);
|
||||
// strip doc root
|
||||
$path = substr($path, strlen(realpath($_SERVER['DOCUMENT_ROOT'])));
|
||||
// fix to absolute URL
|
||||
$url = strtr($path, '/\\', '//');
|
||||
// remove /./ and /../ where possible
|
||||
$url = str_replace('/./', '/', $url);
|
||||
// inspired by patch from Oleg Cherniy
|
||||
do {
|
||||
$url = preg_replace('@/[^/]+/\\.\\./@', '/', $url, 1, $changed);
|
||||
} while ($changed);
|
||||
}
|
||||
}
|
||||
return "url({$quote}{$url}{$quote})";
|
||||
}
|
||||
}
|
||||
131
wp-content/plugins/wp-minify/min/lib/Minify/Lines.php
Normal file
131
wp-content/plugins/wp-minify/min/lib/Minify/Lines.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Lines
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add line numbers in C-style comments for easier debugging of combined content
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
* @author Adam Pedersen (Issue 55 fix)
|
||||
*/
|
||||
class Minify_Lines {
|
||||
|
||||
/**
|
||||
* Add line numbers in C-style comments
|
||||
*
|
||||
* This uses a very basic parser easily fooled by comment tokens inside
|
||||
* strings or regexes, but, otherwise, generally clean code will not be
|
||||
* mangled. URI rewriting can also be performed.
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
* @param array $options available options:
|
||||
*
|
||||
* 'id': (optional) string to identify file. E.g. file name/path
|
||||
*
|
||||
* 'currentDir': (default null) if given, this is assumed to be the
|
||||
* directory of the current CSS file. Using this, minify will rewrite
|
||||
* all relative URIs in import/url declarations to correctly point to
|
||||
* the desired files, and prepend a comment with debugging information about
|
||||
* this process.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function minify($content, $options = array())
|
||||
{
|
||||
$id = (isset($options['id']) && $options['id'])
|
||||
? $options['id']
|
||||
: '';
|
||||
$content = str_replace("\r\n", "\n", $content);
|
||||
$lines = explode("\n", $content);
|
||||
$numLines = count($lines);
|
||||
// determine left padding
|
||||
$padTo = strlen($numLines);
|
||||
$inComment = false;
|
||||
$i = 0;
|
||||
$newLines = array();
|
||||
while (null !== ($line = array_shift($lines))) {
|
||||
if (('' !== $id) && (0 == $i % 50)) {
|
||||
array_push($newLines, '', "/* {$id} */", '');
|
||||
}
|
||||
++$i;
|
||||
$newLines[] = self::_addNote($line, $i, $inComment, $padTo);
|
||||
$inComment = self::_eolInComment($line, $inComment);
|
||||
}
|
||||
$content = implode("\n", $newLines) . "\n";
|
||||
|
||||
// check for desired URI rewriting
|
||||
if (isset($options['currentDir'])) {
|
||||
require_once 'Minify/CSS/UriRewriter.php';
|
||||
Minify_CSS_UriRewriter::$debugText = '';
|
||||
$content = Minify_CSS_UriRewriter::rewrite(
|
||||
$content
|
||||
,$options['currentDir']
|
||||
,isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT']
|
||||
,isset($options['symlinks']) ? $options['symlinks'] : array()
|
||||
);
|
||||
$content = "/* Minify_CSS_UriRewriter::\$debugText\n\n"
|
||||
. Minify_CSS_UriRewriter::$debugText . "*/\n"
|
||||
. $content;
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the parser within a C-style comment at the end of this line?
|
||||
*
|
||||
* @param string $line current line of code
|
||||
*
|
||||
* @param bool $inComment was the parser in a comment at the
|
||||
* beginning of the line?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function _eolInComment($line, $inComment)
|
||||
{
|
||||
while (strlen($line)) {
|
||||
$search = $inComment
|
||||
? '*/'
|
||||
: '/*';
|
||||
$pos = strpos($line, $search);
|
||||
if (false === $pos) {
|
||||
return $inComment;
|
||||
} else {
|
||||
if ($pos == 0
|
||||
|| ($inComment
|
||||
? substr($line, $pos, 3)
|
||||
: substr($line, $pos-1, 3)) != '*/*')
|
||||
{
|
||||
$inComment = ! $inComment;
|
||||
}
|
||||
$line = substr($line, $pos + 2);
|
||||
}
|
||||
}
|
||||
return $inComment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend a comment (or note) to the given line
|
||||
*
|
||||
* @param string $line current line of code
|
||||
*
|
||||
* @param string $note content of note/comment
|
||||
*
|
||||
* @param bool $inComment was the parser in a comment at the
|
||||
* beginning of the line?
|
||||
*
|
||||
* @param int $padTo minimum width of comment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function _addNote($line, $note, $inComment, $padTo)
|
||||
{
|
||||
return $inComment
|
||||
? '/* ' . str_pad($note, $padTo, ' ', STR_PAD_RIGHT) . ' *| ' . $line
|
||||
: '/* ' . str_pad($note, $padTo, ' ', STR_PAD_RIGHT) . ' */ ' . $line;
|
||||
}
|
||||
}
|
||||
45
wp-content/plugins/wp-minify/min/lib/Minify/Logger.php
Normal file
45
wp-content/plugins/wp-minify/min/lib/Minify/Logger.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Logger
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Message logging class
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_Logger {
|
||||
|
||||
/**
|
||||
* Set logger object.
|
||||
*
|
||||
* The object should have a method "log" that accepts a value as 1st argument and
|
||||
* an optional string label as the 2nd.
|
||||
*
|
||||
* @param mixed $obj or a "falsey" value to disable
|
||||
* @return null
|
||||
*/
|
||||
public static function setLogger($obj = null) {
|
||||
self::$_logger = $obj
|
||||
? $obj
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass a message to the logger (if set)
|
||||
*
|
||||
* @param string $msg message to log
|
||||
* @return null
|
||||
*/
|
||||
public static function log($msg, $label = 'Minify') {
|
||||
if (! self::$_logger) return;
|
||||
self::$_logger->log($msg, $label);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var mixed logger object (like FirePHP) or null (i.e. no logger available)
|
||||
*/
|
||||
private static $_logger = null;
|
||||
}
|
||||
37
wp-content/plugins/wp-minify/min/lib/Minify/Packer.php
Normal file
37
wp-content/plugins/wp-minify/min/lib/Minify/Packer.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Packer
|
||||
*
|
||||
* To use this class you must first download the PHP port of Packer
|
||||
* and place the file "class.JavaScriptPacker.php" in /lib (or your
|
||||
* include_path).
|
||||
* @link http://joliclic.free.fr/php/javascript-packer/en/
|
||||
*
|
||||
* Be aware that, as long as HTTP encoding is used, scripts minified with JSMin
|
||||
* will provide better client-side performance, as they need not be unpacked in
|
||||
* client-side code.
|
||||
*
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
if (false === (@include 'class.JavaScriptPacker.php')) {
|
||||
trigger_error(
|
||||
'The script "class.JavaScriptPacker.php" is required. Please see: http:'
|
||||
.'//code.google.com/p/minify/source/browse/trunk/min/lib/Minify/Packer.php'
|
||||
,E_USER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Minify Javascript using Dean Edward's Packer
|
||||
*
|
||||
* @package Minify
|
||||
*/
|
||||
class Minify_Packer {
|
||||
public static function minify($code, $options = array())
|
||||
{
|
||||
// @todo: set encoding options based on $options :)
|
||||
$packer = new JavascriptPacker($code, 'Normal', true, false);
|
||||
return trim($packer->pack());
|
||||
}
|
||||
}
|
||||
187
wp-content/plugins/wp-minify/min/lib/Minify/Source.php
Normal file
187
wp-content/plugins/wp-minify/min/lib/Minify/Source.php
Normal file
@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Source
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* A content source to be minified by Minify.
|
||||
*
|
||||
* This allows per-source minification options and the mixing of files with
|
||||
* content from other sources.
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_Source {
|
||||
|
||||
/**
|
||||
* @var int time of last modification
|
||||
*/
|
||||
public $lastModified = null;
|
||||
|
||||
/**
|
||||
* @var callback minifier function specifically for this source.
|
||||
*/
|
||||
public $minifier = null;
|
||||
|
||||
/**
|
||||
* @var array minification options specific to this source.
|
||||
*/
|
||||
public $minifyOptions = null;
|
||||
|
||||
/**
|
||||
* @var string full path of file
|
||||
*/
|
||||
public $filepath = null;
|
||||
|
||||
/**
|
||||
* @var string HTTP Content Type (Minify requires one of the constants Minify::TYPE_*)
|
||||
*/
|
||||
public $contentType = null;
|
||||
|
||||
/**
|
||||
* Create a Minify_Source
|
||||
*
|
||||
* In the $spec array(), you can either provide a 'filepath' to an existing
|
||||
* file (existence will not be checked!) or give 'id' (unique string for
|
||||
* the content), 'content' (the string content) and 'lastModified'
|
||||
* (unixtime of last update).
|
||||
*
|
||||
* As a shortcut, the controller will replace "//" at the beginning
|
||||
* of a filepath with $_SERVER['DOCUMENT_ROOT'] . '/'.
|
||||
*
|
||||
* @param array $spec options
|
||||
*/
|
||||
public function __construct($spec)
|
||||
{
|
||||
if (isset($spec['filepath'])) {
|
||||
if (0 === strpos($spec['filepath'], '//')) {
|
||||
$spec['filepath'] = $_SERVER['DOCUMENT_ROOT'] . substr($spec['filepath'], 1);
|
||||
}
|
||||
$segments = explode('.', $spec['filepath']);
|
||||
$ext = strtolower(array_pop($segments));
|
||||
switch ($ext) {
|
||||
case 'js' : $this->contentType = 'application/x-javascript';
|
||||
break;
|
||||
case 'css' : $this->contentType = 'text/css';
|
||||
break;
|
||||
case 'htm' : // fallthrough
|
||||
case 'html' : $this->contentType = 'text/html';
|
||||
break;
|
||||
}
|
||||
$this->filepath = $spec['filepath'];
|
||||
$this->_id = $spec['filepath'];
|
||||
$this->lastModified = filemtime($spec['filepath'])
|
||||
// offset for Windows uploaders with out of sync clocks
|
||||
+ round(Minify::$uploaderHoursBehind * 3600);
|
||||
} elseif (isset($spec['id'])) {
|
||||
$this->_id = 'id::' . $spec['id'];
|
||||
if (isset($spec['content'])) {
|
||||
$this->_content = $spec['content'];
|
||||
} else {
|
||||
$this->_getContentFunc = $spec['getContentFunc'];
|
||||
}
|
||||
$this->lastModified = isset($spec['lastModified'])
|
||||
? $spec['lastModified']
|
||||
: time();
|
||||
}
|
||||
if (isset($spec['contentType'])) {
|
||||
$this->contentType = $spec['contentType'];
|
||||
}
|
||||
if (isset($spec['minifier'])) {
|
||||
$this->minifier = $spec['minifier'];
|
||||
}
|
||||
if (isset($spec['minifyOptions'])) {
|
||||
$this->minifyOptions = $spec['minifyOptions'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
$content = (null !== $this->filepath)
|
||||
? file_get_contents($this->filepath)
|
||||
: ((null !== $this->_content)
|
||||
? $this->_content
|
||||
: call_user_func($this->_getContentFunc, $this->_id)
|
||||
);
|
||||
// remove UTF-8 BOM if present
|
||||
return (pack("CCC",0xef,0xbb,0xbf) === substr($content, 0, 3))
|
||||
? substr($content, 3)
|
||||
: $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies a single minification call can handle all sources
|
||||
*
|
||||
* @param array $sources Minify_Source instances
|
||||
*
|
||||
* @return bool true iff there no sources with specific minifier preferences.
|
||||
*/
|
||||
public static function haveNoMinifyPrefs($sources)
|
||||
{
|
||||
foreach ($sources as $source) {
|
||||
if (null !== $source->minifier
|
||||
|| null !== $source->minifyOptions) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unique string for a set of sources
|
||||
*
|
||||
* @param array $sources Minify_Source instances
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getDigest($sources)
|
||||
{
|
||||
foreach ($sources as $source) {
|
||||
$info[] = array(
|
||||
$source->_id, $source->minifier, $source->minifyOptions
|
||||
);
|
||||
}
|
||||
return md5(serialize($info));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content type from a group of sources
|
||||
*
|
||||
* This is called if the user doesn't pass in a 'contentType' options
|
||||
*
|
||||
* @param array $sources Minify_Source instances
|
||||
*
|
||||
* @return string content type. e.g. 'text/css'
|
||||
*/
|
||||
public static function getContentType($sources)
|
||||
{
|
||||
foreach ($sources as $source) {
|
||||
if ($source->contentType !== null) {
|
||||
return $source->contentType;
|
||||
}
|
||||
}
|
||||
return 'text/plain';
|
||||
}
|
||||
|
||||
protected $_content = null;
|
||||
protected $_getContentFunc = null;
|
||||
protected $_id = null;
|
||||
}
|
||||
|
||||
139
wp-content/plugins/wp-minify/min/lib/Minify/YUICompressor.php
Normal file
139
wp-content/plugins/wp-minify/min/lib/Minify/YUICompressor.php
Normal file
@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_YUICompressor
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Compress Javascript/CSS using the YUI Compressor
|
||||
*
|
||||
* You must set $jarFile and $tempDir before calling the minify functions.
|
||||
* Also, depending on your shell's environment, you may need to specify
|
||||
* the full path to java in $javaExecutable or use putenv() to setup the
|
||||
* Java environment.
|
||||
*
|
||||
* <code>
|
||||
* Minify_YUICompressor::$jarFile = '/path/to/yuicompressor-2.3.5.jar';
|
||||
* Minify_YUICompressor::$tempDir = '/tmp';
|
||||
* $code = Minify_YUICompressor::minifyJs(
|
||||
* $code
|
||||
* ,array('nomunge' => true, 'line-break' => 1000)
|
||||
* );
|
||||
* </code>
|
||||
*
|
||||
* @todo unit tests, $options docs
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_YUICompressor {
|
||||
|
||||
/**
|
||||
* Filepath of the YUI Compressor jar file. This must be set before
|
||||
* calling minifyJs() or minifyCss().
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $jarFile = null;
|
||||
|
||||
/**
|
||||
* Writable temp directory. This must be set before calling minifyJs()
|
||||
* or minifyCss().
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $tempDir = null;
|
||||
|
||||
/**
|
||||
* Filepath of "java" executable (may be needed if not in shell's PATH)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $javaExecutable = 'java';
|
||||
|
||||
/**
|
||||
* Minify a Javascript string
|
||||
*
|
||||
* @param string $js
|
||||
*
|
||||
* @param array $options (verbose is ignored)
|
||||
*
|
||||
* @see http://www.julienlecomte.net/yuicompressor/README
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function minifyJs($js, $options = array())
|
||||
{
|
||||
return self::_minify('js', $js, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Minify a CSS string
|
||||
*
|
||||
* @param string $css
|
||||
*
|
||||
* @param array $options (verbose is ignored)
|
||||
*
|
||||
* @see http://www.julienlecomte.net/yuicompressor/README
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function minifyCss($css, $options = array())
|
||||
{
|
||||
return self::_minify('css', $css, $options);
|
||||
}
|
||||
|
||||
private static function _minify($type, $content, $options)
|
||||
{
|
||||
self::_prepare();
|
||||
if (! ($tmpFile = tempnam(self::$tempDir, 'yuic_'))) {
|
||||
throw new Exception('Minify_YUICompressor : could not create temp file.');
|
||||
}
|
||||
file_put_contents($tmpFile, $content);
|
||||
exec(self::_getCmd($options, $type, $tmpFile), $output);
|
||||
unlink($tmpFile);
|
||||
return implode("\n", $output);
|
||||
}
|
||||
|
||||
private static function _getCmd($userOptions, $type, $tmpFile)
|
||||
{
|
||||
$o = array_merge(
|
||||
array(
|
||||
'charset' => ''
|
||||
,'line-break' => 5000
|
||||
,'type' => $type
|
||||
,'nomunge' => false
|
||||
,'preserve-semi' => false
|
||||
,'disable-optimizations' => false
|
||||
)
|
||||
,$userOptions
|
||||
);
|
||||
$cmd = self::$javaExecutable . ' -jar ' . escapeshellarg(self::$jarFile)
|
||||
. " --type {$type}"
|
||||
. (preg_match('/^[a-zA-Z\\-]+$/', $o['charset'])
|
||||
? " --charset {$o['charset']}"
|
||||
: '')
|
||||
. (is_numeric($o['line-break']) && $o['line-break'] >= 0
|
||||
? ' --line-break ' . (int)$o['line-break']
|
||||
: '');
|
||||
if ($type === 'js') {
|
||||
foreach (array('nomunge', 'preserve-semi', 'disable-optimizations') as $opt) {
|
||||
$cmd .= $o[$opt]
|
||||
? " --{$opt}"
|
||||
: '';
|
||||
}
|
||||
}
|
||||
return $cmd . ' ' . escapeshellarg($tmpFile);
|
||||
}
|
||||
|
||||
private static function _prepare()
|
||||
{
|
||||
if (! is_file(self::$jarFile)
|
||||
|| ! is_dir(self::$tempDir)
|
||||
|| ! is_writable(self::$tempDir)
|
||||
) {
|
||||
throw new Exception('Minify_YUICompressor : $jarFile and $tempDir must be set.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
199
wp-content/plugins/wp-minify/min/lib/Solar/Dir.php
Normal file
199
wp-content/plugins/wp-minify/min/lib/Solar/Dir.php
Normal file
@ -0,0 +1,199 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* Utility class for static directory methods.
|
||||
*
|
||||
* @category Solar
|
||||
*
|
||||
* @package Solar
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@solarphp.com>
|
||||
*
|
||||
* @license http://opensource.org/licenses/bsd-license.php BSD
|
||||
*
|
||||
* @version $Id: Dir.php 2926 2007-11-09 16:25:44Z pmjones $
|
||||
*
|
||||
*/
|
||||
class Solar_Dir {
|
||||
|
||||
/**
|
||||
*
|
||||
* The OS-specific temporary directory location.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
protected static $_tmp;
|
||||
|
||||
/**
|
||||
*
|
||||
* Hack for [[php::is_dir() | ]] that checks the include_path.
|
||||
*
|
||||
* Use this to see if a directory exists anywhere in the include_path.
|
||||
*
|
||||
* {{code: php
|
||||
* $dir = Solar_Dir::exists('path/to/dir')
|
||||
* if ($dir) {
|
||||
* $files = scandir($dir);
|
||||
* } else {
|
||||
* echo "Not found in the include-path.";
|
||||
* }
|
||||
* }}
|
||||
*
|
||||
* @param string $dir Check for this directory in the include_path.
|
||||
*
|
||||
* @return mixed If the directory exists in the include_path, returns the
|
||||
* absolute path; if not, returns boolean false.
|
||||
*
|
||||
*/
|
||||
public static function exists($dir)
|
||||
{
|
||||
// no file requested?
|
||||
$dir = trim($dir);
|
||||
if (! $dir) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// using an absolute path for the file?
|
||||
// dual check for Unix '/' and Windows '\',
|
||||
// or Windows drive letter and a ':'.
|
||||
$abs = ($dir[0] == '/' || $dir[0] == '\\' || $dir[1] == ':');
|
||||
if ($abs && is_dir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
|
||||
// using a relative path on the file
|
||||
$path = explode(PATH_SEPARATOR, ini_get('include_path'));
|
||||
foreach ($path as $base) {
|
||||
// strip Unix '/' and Windows '\'
|
||||
$target = rtrim($base, '\\/') . DIRECTORY_SEPARATOR . $dir;
|
||||
if (is_dir($target)) {
|
||||
return $target;
|
||||
}
|
||||
}
|
||||
|
||||
// never found it
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* "Fixes" a directory string for the operating system.
|
||||
*
|
||||
* Use slashes anywhere you need a directory separator. Then run the
|
||||
* string through fixdir() and the slashes will be converted to the
|
||||
* proper separator (for example '\' on Windows).
|
||||
*
|
||||
* Always adds a final trailing separator.
|
||||
*
|
||||
* @param string $dir The directory string to 'fix'.
|
||||
*
|
||||
* @return string The "fixed" directory string.
|
||||
*
|
||||
*/
|
||||
public static function fix($dir)
|
||||
{
|
||||
$dir = str_replace('/', DIRECTORY_SEPARATOR, $dir);
|
||||
return rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Convenience method for dirname() and higher-level directories.
|
||||
*
|
||||
* @param string $file Get the dirname() of this file.
|
||||
*
|
||||
* @param int $up Move up in the directory structure this many
|
||||
* times, default 0.
|
||||
*
|
||||
* @return string The dirname() of the file.
|
||||
*
|
||||
*/
|
||||
public static function name($file, $up = 0)
|
||||
{
|
||||
$dir = dirname($file);
|
||||
while ($up --) {
|
||||
$dir = dirname($dir);
|
||||
}
|
||||
return $dir;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns the OS-specific directory for temporary files.
|
||||
*
|
||||
* @param string $sub Add this subdirectory to the returned temporary
|
||||
* directory name.
|
||||
*
|
||||
* @return string The temporary directory path.
|
||||
*
|
||||
*/
|
||||
public static function tmp($sub = '')
|
||||
{
|
||||
// find the tmp dir if needed
|
||||
if (! Solar_Dir::$_tmp) {
|
||||
|
||||
// use the system if we can
|
||||
if (function_exists('sys_get_temp_dir')) {
|
||||
$tmp = sys_get_temp_dir();
|
||||
} else {
|
||||
$tmp = Solar_Dir::_tmp();
|
||||
}
|
||||
|
||||
// remove trailing separator and save
|
||||
Solar_Dir::$_tmp = rtrim($tmp, DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
// do we have a subdirectory request?
|
||||
$sub = trim($sub);
|
||||
if ($sub) {
|
||||
// remove leading and trailing separators, and force exactly
|
||||
// one trailing separator
|
||||
$sub = trim($sub, DIRECTORY_SEPARATOR)
|
||||
. DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
return Solar_Dir::$_tmp . DIRECTORY_SEPARATOR . $sub;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns the OS-specific temporary directory location.
|
||||
*
|
||||
* @return string The temp directory path.
|
||||
*
|
||||
*/
|
||||
protected static function _tmp()
|
||||
{
|
||||
// non-Windows system?
|
||||
if (strtolower(substr(PHP_OS, 0, 3)) != 'win') {
|
||||
$tmp = empty($_ENV['TMPDIR']) ? getenv('TMPDIR') : $_ENV['TMPDIR'];
|
||||
if ($tmp) {
|
||||
return $tmp;
|
||||
} else {
|
||||
return '/tmp';
|
||||
}
|
||||
}
|
||||
|
||||
// Windows 'TEMP'
|
||||
$tmp = empty($_ENV['TEMP']) ? getenv('TEMP') : $_ENV['TEMP'];
|
||||
if ($tmp) {
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// Windows 'TMP'
|
||||
$tmp = empty($_ENV['TMP']) ? getenv('TMP') : $_ENV['TMP'];
|
||||
if ($tmp) {
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// Windows 'windir'
|
||||
$tmp = empty($_ENV['windir']) ? getenv('windir') : $_ENV['windir'];
|
||||
if ($tmp) {
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// final fallback for Windows
|
||||
return getenv('SystemRoot') . '\\temp';
|
||||
}
|
||||
}
|
||||
90
wp-content/plugins/wp-minify/min/utils.php
Normal file
90
wp-content/plugins/wp-minify/min/utils.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Utility functions for generating group URIs in HTML files
|
||||
*
|
||||
* Before including this file, /min/lib must be in your include_path.
|
||||
*
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once 'Minify/Build.php';
|
||||
|
||||
|
||||
/**
|
||||
* Get a timestamped URI to a minified resource using the default Minify install
|
||||
*
|
||||
* <code>
|
||||
* <link rel="stylesheet" type="text/css" href="<?php echo Minify_groupUri('css'); ?>" />
|
||||
* <script type="text/javascript" src="<?php echo Minify_groupUri('js'); ?>"></script>
|
||||
* </code>
|
||||
*
|
||||
* If you do not want ampersands as HTML entities, set Minify_Build::$ampersand = "&"
|
||||
* before using this function.
|
||||
*
|
||||
* @param string $group a key from groupsConfig.php
|
||||
* @param boolean $forceAmpersand (default false) Set to true if the RewriteRule
|
||||
* directives in .htaccess are functional. This will remove the "?" from URIs, making them
|
||||
* more cacheable by proxies.
|
||||
* @return string
|
||||
*/
|
||||
function Minify_groupUri($group, $forceAmpersand = false)
|
||||
{
|
||||
$path = $forceAmpersand
|
||||
? "/g={$group}"
|
||||
: "/?g={$group}";
|
||||
return _Minify_getBuild($group)->uri(
|
||||
'/' . basename(dirname(__FILE__)) . $path
|
||||
,$forceAmpersand
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the last modification time of the source js/css files used by Minify to
|
||||
* build the page.
|
||||
*
|
||||
* If you're caching the output of Minify_groupUri(), you'll want to rebuild
|
||||
* the cache if it's older than this timestamp.
|
||||
*
|
||||
* <code>
|
||||
* // simplistic HTML cache system
|
||||
* $file = '/path/to/cache/file';
|
||||
* if (! file_exists($file) || filemtime($file) < Minify_groupsMtime(array('js', 'css'))) {
|
||||
* // (re)build cache
|
||||
* $page = buildPage(); // this calls Minify_groupUri() for js and css
|
||||
* file_put_contents($file, $page);
|
||||
* echo $page;
|
||||
* exit();
|
||||
* }
|
||||
* readfile($file);
|
||||
* </code>
|
||||
*
|
||||
* @param array $groups an array of keys from groupsConfig.php
|
||||
* @return int Unix timestamp of the latest modification
|
||||
*/
|
||||
function Minify_groupsMtime($groups)
|
||||
{
|
||||
$max = 0;
|
||||
foreach ((array)$groups as $group) {
|
||||
$max = max($max, _Minify_getBuild($group)->lastModified);
|
||||
}
|
||||
return $max;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $group a key from groupsConfig.php
|
||||
* @return Minify_Build
|
||||
* @private
|
||||
*/
|
||||
function _Minify_getBuild($group)
|
||||
{
|
||||
static $builds = array();
|
||||
static $gc = false;
|
||||
if (false === $gc) {
|
||||
$gc = (require dirname(__FILE__) . '/groupsConfig.php');
|
||||
}
|
||||
if (! isset($builds[$group])) {
|
||||
$builds[$group] = new Minify_Build($gc[$group]);
|
||||
}
|
||||
return $builds[$group];
|
||||
}
|
||||
197
wp-content/plugins/wp-minify/options-generic.php
Normal file
197
wp-content/plugins/wp-minify/options-generic.php
Normal file
@ -0,0 +1,197 @@
|
||||
<script type="text/javascript">
|
||||
function confirm_reset() {
|
||||
var answer = confirm("<?php _e('All of options will return to default settings. Are you sure you want to reset all settings?'); ?>");
|
||||
if(answer)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
jQuery(document).ready(function($){
|
||||
$("#wpm_options_toggle_advanced").click(function(e){
|
||||
e.preventDefault();
|
||||
state = $(this).attr("state");
|
||||
if(state == "visible"){
|
||||
$(".wpm_advanced").slideUp();
|
||||
$("#wpm_options_reset").fadeOut();
|
||||
$(this).attr("state", "hidden");
|
||||
$(this).attr("value", "<?php echo __('Show Advanced Options', $this->name); ?>" + " " + String.fromCharCode(187));
|
||||
$.ajax({
|
||||
type : "POST",
|
||||
url : "admin-ajax.php",
|
||||
data : { action : "wpm", _ajax_nonce: "<?php echo wp_create_nonce($this->name); ?>", wpm_action : "hide_advanced" },
|
||||
success : function(resp){
|
||||
// do nothing visually
|
||||
},
|
||||
error : function(resp){
|
||||
alert("Error:" + resp);
|
||||
}
|
||||
});
|
||||
}
|
||||
else{
|
||||
$(".wpm_advanced").slideDown();
|
||||
$("#wpm_options_reset").fadeIn();
|
||||
$(this).attr("state", "visible");
|
||||
$(this).attr("value", "<?php echo __('Hide Advanced Options', $this->name); ?>" + " " + String.fromCharCode(187));
|
||||
$.ajax({
|
||||
type : "POST",
|
||||
url : "admin-ajax.php",
|
||||
data : { action : "wpm", _ajax_nonce: "<?php echo wp_create_nonce($this->name); ?>", wpm_action : "show_advanced" },
|
||||
success : function(resp){
|
||||
// do nothing visually
|
||||
},
|
||||
error : function(resp){
|
||||
alert("Error:" + resp);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
$('#cache_external_checkbox').click(function(e) {
|
||||
state = $(this).attr("state");
|
||||
if (state == "on") {
|
||||
$(".wpm_include").slideDown();
|
||||
$(this).attr("state", "off");
|
||||
} else {
|
||||
$(".wpm_include").slideUp();
|
||||
$(this).attr("state", "on");
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<form method="post"><fieldset>
|
||||
<?php
|
||||
// take care of advanced options
|
||||
if ($wpm_options['show_advanced']) {
|
||||
$advanced_style = '';
|
||||
$advanced_toggle_text = __('Hide Advanced Options', $this->name);
|
||||
$advanced_toggle_state = 'visible';
|
||||
}
|
||||
else {
|
||||
$advanced_style = 'style="display:none"';
|
||||
$advanced_toggle_text = __('Show Advanced Options', $this->name);
|
||||
$advanced_toggle_state = 'hidden';
|
||||
}
|
||||
|
||||
if ($wpm_options['cache_external']) {
|
||||
$include_style = 'style="display:none"';
|
||||
$include_toggle_state = 'on';
|
||||
} else {
|
||||
$include_style = '';
|
||||
$include_toggle_state = 'off';
|
||||
}
|
||||
|
||||
printf('
|
||||
<h2>%s</h2>
|
||||
<p><label>%s <input name="wpm_options_update[show_link]" value="on" type="radio" '.checked(true, $wpm_options['show_link'], false).'/></label></p>
|
||||
<p><label>%s (<a href="http://omninoggin.com/donate">%s</a>) <input name="wpm_options_update[show_link]" value="off" type="radio" '.checked(false, $wpm_options['show_link'], false).'/></label></p>
|
||||
',
|
||||
__('Support this plugin!', $this->name),
|
||||
__('Display "Page optimized by WP Minify" link in the footer', $this->name),
|
||||
__('Do not display "Page optimized by WP Minify" link.', $this->name),
|
||||
__('Donations are appreciated!', $this->name)
|
||||
);
|
||||
|
||||
printf('
|
||||
<h2>%s</h2>
|
||||
<p><label>%s <input name="wpm_options_update[enable_js]" type="checkbox" '.checked(true, $wpm_options['enable_js'], false).'/></label></p>
|
||||
<p><label>%s <input name="wpm_options_update[enable_css]" type="checkbox" '.checked(true, $wpm_options['enable_css'], false).'/></label></p>
|
||||
<p><label>%s <input name="wpm_options_update[enable_html]" type="checkbox" '.checked(true, $wpm_options['enable_html'], false).'/></label></p>
|
||||
',
|
||||
__('General Configuration', $this->name),
|
||||
__('Enable JavaScript Minification', $this->name),
|
||||
__('Enable CSS Minification', $this->name),
|
||||
__('Enable HTML Minification', $this->name)
|
||||
);
|
||||
|
||||
printf('
|
||||
<h2 class="wpm_advanced" '.$advanced_style.'>%s</h2>
|
||||
<p class="wpm_advanced" '.$advanced_style.'><label>%s <input name="wpm_options_update[debug_nominify]" type="checkbox" '.checked(true, $wpm_options['debug_nominify'], false).'/></label></p>
|
||||
<p class="wpm_advanced" '.$advanced_style.'><label><a href="http://omninoggin.com/wordpress-posts/troubleshooting-wp-minify-with-firephp/">%s</a> <input name="wpm_options_update[debug_firephp]" type="checkbox" '.checked(true, $wpm_options['debug_firephp'], false).'/></label></p>
|
||||
',
|
||||
__('Debugging', $this->name),
|
||||
__('Combine files but do not minify', $this->name),
|
||||
__('Show minify errors through FirePHP', $this->name)
|
||||
);
|
||||
|
||||
printf('
|
||||
<h2 class="wpm_advanced" '.$advanced_style.'>%s</h2>
|
||||
<p><label>%s<br/><textarea name="wpm_options_update[js_exclude]" style="width:600px" rows="5">'.attribute_escape(implode(chr(10), $wpm_options['js_exclude'])).'</textarea></label></p>
|
||||
<p><label>%s<br/><textarea name="wpm_options_update[css_exclude]" style="width:600px" rows="5">'.attribute_escape(implode(chr(10), $wpm_options['css_exclude'])).'</textarea></label></p>
|
||||
<p class="wpm_advanced" '.$advanced_style.'><label>%s<br/><textarea name="wpm_options_update[uri_exclude]" style="width:600px" rows="5">'.attribute_escape(implode(chr(10), $wpm_options['uri_exclude'])).'</textarea></label></p>
|
||||
',
|
||||
__('Local Files Minification', $this->name),
|
||||
__('JavaScript files to exclude from minify (line delimited).', $this->name),
|
||||
__('CSS files to exclude from minify (line delimited).', $this->name),
|
||||
__('URIs on which WP-Minify parsing will be disabled (line delimited)', $this->name)
|
||||
);
|
||||
|
||||
printf('
|
||||
<h2 class="wpm_advanced" '.$advanced_style.'>%s</h2>
|
||||
<p class="wpm_advanced" '.$advanced_style.'><label>%s <input name="wpm_options_update[cache_external]" id="cache_external_checkbox" state="'.$include_toggle_state.'" type="checkbox" '.checked(true, $wpm_options['cache_external'], false).'/> (%s)</label></p>
|
||||
<p class="wpm_advanced wpm_include" '.$advanced_style.' '.$include_style.'><label>%s (%s, <a href="http://omninoggin.com/wordpress-posts/tutorial-wp-minify-options/#include_external_files">%s</a>)<br/><textarea name="wpm_options_update[js_include]" style="width:600px" rows="5">'.attribute_escape(implode(chr(10), $wpm_options['js_include'])).'</textarea></label></p>
|
||||
<p class="wpm_advanced wpm_include" '.$advanced_style.' '.$include_style.'><label>%s (%s, <a href="http://omninoggin.com/wordpress-posts/tutorial-wp-minify-options/#include_external_files">%s</a>)<br/><textarea name="wpm_options_update[css_include]" style="width:600px" rows="5">'.attribute_escape(implode(chr(10), $wpm_options['css_include'])).'</textarea></label></p>
|
||||
',
|
||||
__('Non-Local Files Minification', $this->name),
|
||||
__('Enable minification on external files', $this->name),
|
||||
__('Not recommended unless you want to exclude a bunch of external .js/.css files', $this->name),
|
||||
__('External JavaScript files to include into minify.', $this->name),
|
||||
__('Only useful if "Minification on external files" is unchecked', $this->name),
|
||||
__('more info', $this->name),
|
||||
__('External CSS files to include into minify.', $this->name),
|
||||
__('Only useful if "Minification on external files" is unchecked', $this->name),
|
||||
__('more info', $this->name)
|
||||
);
|
||||
|
||||
printf('
|
||||
<h2 class="wpm_advanced" '.$advanced_style.'>%s</h2>
|
||||
<p class="wpm_advanced" '.$advanced_style.'><label>%s<input name="wpm_options_
|
||||
update[cache_interval]" type="text" size="4" value="'.attribute_escape($wpm_options['cache_interval']).'"/>%s <span class="submit"><input type="submit" name="wpm_options_clear_cache_submit" value="%s"/></span></p></label>
|
||||
',
|
||||
__('Caching', $this->name),
|
||||
__('Cache expires after every', $this->name),
|
||||
__('seconds', $this->name),
|
||||
__('Manually Clear Cache', $this->name)
|
||||
);
|
||||
|
||||
printf('
|
||||
<h2 class="wpm_advanced" '.$advanced_style.'>%s</h2>
|
||||
<p class="wpm_advanced" '.$advanced_style.'><label>%s <input name="wpm_options_update[pretty_url]" type="checkbox" '.checked(true, $wpm_options['pretty_url'], false).'/> (%s)</label></p>
|
||||
<p class="wpm_advanced" '.$advanced_style.'><label>%s <input name="wpm_options_update[js_in_footer]" type="checkbox" '.checked(true, $wpm_options['js_in_footer'], false).'/> (%s, <a href="http://omninoggin.com/wordpress-posts/tutorial-wp-minify-options/#manual_placement">%s</a>)</label></p>
|
||||
',
|
||||
__('Tweaking/Tuning', $this->name),
|
||||
__('Use "pretty" URL"', $this->name),
|
||||
__('i.e. use "wp-minify/cache/1234abcd.js" instead of "wp-minify/min/?f=file1.js,file2.js,...,fileN.js"', $this->name),
|
||||
__('Place Minified JavaScript in footer', $this->name),
|
||||
__('Not recommended', $this->name),
|
||||
__('more info', $this->name)
|
||||
);
|
||||
|
||||
printf('
|
||||
<p class="wpm_advanced" '.$advanced_style.'><label>%s <input name="wpm_options_update[force_https]" type="checkbox" '.checked(true, $wpm_options['force_https'], false).'/></label></p>
|
||||
',
|
||||
__('Force all JavaScript/CSS calls to be HTTPS on HTTPS pages', $this->name)
|
||||
);
|
||||
|
||||
printf('
|
||||
<p class="wpm_advanced" '.$advanced_style.'><label>%s <input name="wpm_options_update[auto_base]" type="checkbox" '.checked(true, $wpm_options['auto_base'], false).'/></label></p>
|
||||
<p class="wpm_advanced" '.$advanced_style.'><label>%s<br/><input name="wpm_options_update[extra_minify_options]" type="text" size="100" value="'.attribute_escape($wpm_options['extra_minify_options']).'"/><br/><em>%s</em></label></p>
|
||||
',
|
||||
__('Automatically set your Minify base per siteurl setting (recommended)', $this->name),
|
||||
__('Extra arguments to pass to minify engine. This value will get append to calls to URL "wp-minify/min/?f=file1.js,file2.js,...,fileN.js".', $this->name),
|
||||
__('e.g. You can specify this value to be b=somepath to specify the base path for all files passed into Minify.', $this->name)
|
||||
);
|
||||
|
||||
if ( function_exists( 'wp_nonce_field' ) && wp_nonce_field( $this->name ) ) {
|
||||
printf('
|
||||
<p class="submit">
|
||||
<input type="submit" name="wpm_options_update_submit" value="%s »" />
|
||||
<input type="submit" name="wpm_options_reset_submit" id="wpm_options_reset" value="%s »" onclick="return confirm_reset()" '.$advanced_style.'/>
|
||||
<input type="button" id="wpm_options_toggle_advanced" state="'.$advanced_toggle_state.'" value="'.$advanced_toggle_text.' »"/>
|
||||
</p>
|
||||
',
|
||||
__('Update Options', $this->name),
|
||||
__('Reset ALL Options', $this->name)
|
||||
);
|
||||
}
|
||||
?>
|
||||
</fieldset></form>
|
||||
1
wp-content/plugins/wp-minify/options-sidebar.php
Normal file
1
wp-content/plugins/wp-minify/options-sidebar.php
Normal file
@ -0,0 +1 @@
|
||||
<iframe src="http://omninoggin.com/res/sidebar.php?name=<?php echo $this->name_dashed ?>" border=0 width=250 height=950></iframe>
|
||||
256
wp-content/plugins/wp-minify/readme.txt
Normal file
256
wp-content/plugins/wp-minify/readme.txt
Normal file
@ -0,0 +1,256 @@
|
||||
=== WP Minify ===
|
||||
Tags: minify, js, css, html, javascript, cascading style sheets, optimize, performance, speed, http request, phpspeedy
|
||||
Contributors: madeinthayaland
|
||||
Donate link: http://omninoggin.com/donate/
|
||||
Requires at least: 2.7
|
||||
Tested up to: 3.3.2
|
||||
Stable Tag: 1.2.0
|
||||
|
||||
This plugin uses the Minify engine to combine and compress JS and CSS files
|
||||
to improve page load time.
|
||||
|
||||
== Description ==
|
||||
This plugin integrates the [Minify engine](http://code.google.com/p/minify/)
|
||||
into your WordPress blog. Once enabled, this plugin will combine and compress
|
||||
JS and CSS files to improve page load time.
|
||||
|
||||
= How Does it Work? =
|
||||
|
||||
WP Minify grabs JS/CSS files in your generated WordPress page and passes that
|
||||
list to the Minify engine. The Minify engine then returns a consolidated,
|
||||
minified, and compressed script or style for WP Minify to reference in the
|
||||
WordPress header.
|
||||
|
||||
= Features =
|
||||
|
||||
* Easily integrate Minify into your WordPress blog.
|
||||
* Minifies JavaScript, CSS, and HTML.
|
||||
* Debug tools to help you debug your issues.
|
||||
* Ability to include extra JS and CSS files for Minifying.
|
||||
* Ability to exclude certain JS and CSS files for Minifying.
|
||||
* Minified JS and CSS files can be placed wherever you want.
|
||||
* Support for to minifying external files via caching.
|
||||
* Ability to pass extra arguments to Minify engine.
|
||||
* Expire headers for minified JS and CSS files.
|
||||
* Detection and elimination of duplicate sources.
|
||||
* Plugin hooks!
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.2.0 =
|
||||
* Tested with 3.3.2
|
||||
* No longer showing attribution link by default.
|
||||
* Changed donation phrasing.
|
||||
|
||||
= 1.1.8 =
|
||||
* Removed unnecessary error_log line.
|
||||
|
||||
= 1.1.7 =
|
||||
* Set User Agent as "WP-Minify" when curling things.
|
||||
* Cleaned up some old code.
|
||||
* Added last modified time to pretty URLs.
|
||||
* Updating it_IT translation (thanks Gianni Diiurno!).
|
||||
* Added uk translation (thanks Jurko Chervony!).
|
||||
|
||||
= 1.1.6 =
|
||||
* Extra precautions when printing last modified time variable (?m= vs. &m=)
|
||||
|
||||
= 1.1.5 =
|
||||
* Fixed documentation.
|
||||
|
||||
= 1.1.4 =
|
||||
* Made pretty URL off by default since it doesn't work for everybody.
|
||||
|
||||
= 1.1.3 =
|
||||
* Added it_IT translation (thanks Gianni Diurno!)
|
||||
|
||||
= 1.1.2 =
|
||||
* Re-did options page and documentation to make things a bit more clear.
|
||||
|
||||
= 1.1.1 =
|
||||
* Fixed incomplete /min/config.php file.
|
||||
|
||||
= 1.1 =
|
||||
* Fixed "Class 'WPMinifyCommon' not found" errors that some are seeing.
|
||||
* Added pretty URL for minified files so now you can stick it on a CDN.
|
||||
* Organized options page.
|
||||
|
||||
= 1.0.4 =
|
||||
* Fixed conflict with W3 Total Cache.
|
||||
|
||||
= 1.0.3 =
|
||||
* Fixed "Invalid argument supplied for foreach()" error that some are having.
|
||||
|
||||
= 1.0.2 =
|
||||
* Adding options for excluding certain URIs from WP Minify parsing.
|
||||
|
||||
= 1.0.1 =
|
||||
* Reverting bbpress fix since it causs Minify to not even run.
|
||||
|
||||
= 1.0.0 =
|
||||
* Added option to minify HTML.
|
||||
* Added ability to NOT minify when "wp-minify-off=1" is in URL.
|
||||
* Added option to report errors through FirePHP.
|
||||
* Added "wp_minify_js_url" filter
|
||||
* Added "wp_minify_css_url" filter
|
||||
* Added "wp_minify_content" filter
|
||||
* Enhanced "JavaScript files to include" feature.
|
||||
* Enhanced "CSS files to include" feature.
|
||||
* Fixed persistent SSL issue (Thanks belg4mit!)
|
||||
* Fixed bbpress issue (Thanks foobar!)
|
||||
|
||||
= 0.9.3 =
|
||||
* Fixed removing trailing slash in base path.
|
||||
|
||||
= 0.9.2 =
|
||||
* Fixed "delimiter" error.
|
||||
* Fixed admin sidebar.
|
||||
|
||||
= 0.9.1 =
|
||||
* Automatically set far future expiration headers in Minify config (30 days).
|
||||
* Automatically detect subdirectory from siteurl for passing as base path
|
||||
for Minify engine.
|
||||
|
||||
= 0.9.0 =
|
||||
* Added SSL option to force http -> https on secured pages.
|
||||
* Updated common.php and some other maintenance.
|
||||
|
||||
= 0.8.1 =
|
||||
* Fixed WPMU subdirectory bug.
|
||||
|
||||
= 0.8.0 =
|
||||
* Added ability to de-dupe sources
|
||||
* Added ability to manually specify location of minified JS and CSS files.
|
||||
* Fixed XHTML compliance bugs
|
||||
* Cleaned empty lines in HTML output
|
||||
|
||||
= 0.7.4 =
|
||||
* Fixed detecting if script is local or not.
|
||||
|
||||
= 0.7.3 =
|
||||
* Fixed corner case on expire headers implementation.
|
||||
|
||||
= 0.7.2 =
|
||||
* Add expire headers to combined JS and CSS files (Thanks Jan Seidl!).
|
||||
|
||||
= 0.7.1 =
|
||||
* Fixed extra arguments for Minify engine.
|
||||
|
||||
= 0.7.0 =
|
||||
* Added advanced options:
|
||||
- Minification on external files
|
||||
- Place JavaScript in footer
|
||||
- Extra arguments for Minify engine
|
||||
* Removed wp_path option (Thanks Jan Seidl!)
|
||||
* Fixed Output Buffer conflicts with other plugins that use output buffering
|
||||
such as All-in-One SEO and Anarchy Media Player.
|
||||
|
||||
= 0.6.5 =
|
||||
* Fixed URL building (bug introduced by last release).
|
||||
* Brought back WordPress path settings as some people with .htaccess issues
|
||||
may still need this.
|
||||
|
||||
= 0.6.4 =
|
||||
* Fixed CSS regex to catch "media=''" case. (Thanks forum user bobmarkl33!)
|
||||
* Modified minified JavaScript injection to the end of <head> (Thanks forum
|
||||
user bobmarl33!)
|
||||
* Fixed WP Minify working with blogs installed in subdirectory of webroot.
|
||||
(Thanks forum user Luke!)
|
||||
* Removed WordPress path settings as this is no longer needed per Luke's fix.
|
||||
|
||||
= 0.6.3 =
|
||||
* Fixed JavaScript minification failure for large number of files.
|
||||
|
||||
= 0.6.2 =
|
||||
* Fixed admin array_keys() bug
|
||||
* Updated .pot file.
|
||||
|
||||
= 0.6.1 =
|
||||
* Added .pot file.
|
||||
|
||||
= 0.6 =
|
||||
* Upgraded to Minify engine 2.1.3.
|
||||
* Added automatic Minify engine cache configuration.
|
||||
* Fixed HTML5 <header> conflict.
|
||||
* Fixed bug from blog installed in subdirectory.
|
||||
* Fixed localization.
|
||||
|
||||
= 0.5 =
|
||||
* Added option to disable JS or CSS minification.
|
||||
* Fixed a few bugs.
|
||||
* Admin facelift
|
||||
|
||||
= 0.4.1 =
|
||||
* Fixed non-replaced </link> tag for valid XHTML usage.
|
||||
|
||||
= 0.4 =
|
||||
* Automatically exclude CSS conditionals.
|
||||
* Automatically exclude CSS media != all, or screen.
|
||||
* Automatically exclude https URLs.
|
||||
* Added sanity checking for buffer start & stop.
|
||||
* Moved buffer start to init with priority 99999.
|
||||
* Fixed "strpos()" warnings when settings have empty lines.
|
||||
|
||||
= 0.3.1 =
|
||||
* Fixed "URL file-access disabled" errors.
|
||||
* Fixed "implode()" warnings.
|
||||
|
||||
= 0.3 =
|
||||
* WP 2.8 Compatibility
|
||||
|
||||
= 0.2.1 =
|
||||
* Fixed another CSS exclusion bug (src_match -> href_match).
|
||||
* Fixed JS WP Minify bug passing double forward slashes when not needed.
|
||||
* Added media="screen" for minified CSS reference.
|
||||
|
||||
= 0.2 =
|
||||
* Changed the way CSS and JS files are picked up. No more wp_enqueue_*
|
||||
requirements!
|
||||
* Fixed exclusion bug where specified files are not excluded from
|
||||
minification.
|
||||
* Removed OMNINOGGIN dashboard widget.
|
||||
|
||||
= 0.1.1 =
|
||||
* Fixed array_slice() warning in the admin dashboard.
|
||||
* Fixed version check to not break page when $wp_version is empty.
|
||||
|
||||
= 0.1 =
|
||||
* Initial release
|
||||
|
||||
= Credits =
|
||||
This plugin utilizes the [Minify engine](http://code.google.com/p/minify/)
|
||||
coded by [Steve Clay](http://mrclay.org/) and [Ryan Grove](http://wonko.com)
|
||||
to perform all JS & CSS Minifying.
|
||||
|
||||
== Installation ==
|
||||
|
||||
1. Upload the plugin to your plugins folder: 'wp-content/plugins/'
|
||||
2. Make sure 'wp-content/plugins/wp-minify/cache' is writeable by the
|
||||
web server. (try 'chmod 777 wp-content/plugins/wp-minify/cache')
|
||||
3. Activate the 'WP Minify' plugin from the Plugins admin panel.
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= Where is the documentation? =
|
||||
If you are having problems with this plugin, please first take a look at the
|
||||
various links under the "Documentation" section of the
|
||||
[plugin page](http://omninoggin.com/wordpress-plugins/wp-minify-wordpress-plugin/).
|
||||
|
||||
= I still can't get it to work after reading the documentation! =
|
||||
Please take a look at documentation available on the
|
||||
[plugin page](http://omninoggin.com/wordpress-plugins/wp-minify-wordpress-plugin/).
|
||||
to see if any of them can help you. If not, feel free to post your issues
|
||||
on the appropriate [plugin support forum](http://omninoggin.com/forum).
|
||||
I will try my best to help you resolve any issues that you are having.
|
||||
|
||||
== License ==
|
||||
All contents under the wp-minify/min/ directory is licensed under
|
||||
[New BSD License](http://www.opensource.org/licenses/bsd-license.php) (which is
|
||||
[GPL](http://www.gnu.org/copyleft/gpl.html) compatible). All other
|
||||
contents within this package is licensed under GPLv3.
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. Options
|
||||
2. Before WP Minify (11 JS requests @ 111KB)
|
||||
3. After WP Minify (1 JS request @ 30KB)
|
||||
BIN
wp-content/plugins/wp-minify/screenshot-1.png
Normal file
BIN
wp-content/plugins/wp-minify/screenshot-1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
BIN
wp-content/plugins/wp-minify/screenshot-2.png
Normal file
BIN
wp-content/plugins/wp-minify/screenshot-2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
BIN
wp-content/plugins/wp-minify/screenshot-3.png
Normal file
BIN
wp-content/plugins/wp-minify/screenshot-3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.1 KiB |
932
wp-content/plugins/wp-minify/wp-minify.php
Normal file
932
wp-content/plugins/wp-minify/wp-minify.php
Normal file
@ -0,0 +1,932 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: WP Minify
|
||||
Plugin URI: http://omninoggin.com/wordpress-plugins/wp-minify-wordpress-plugin/
|
||||
Description: This plugin uses the Minify engine to combine and compress JS and CSS files to improve page load time.
|
||||
Version: 1.2.0
|
||||
Author: Thaya Kareeson
|
||||
Author URI: http://omninoggin.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2009-2011 Thaya Kareeson (email : thaya.kareeson@gmail.com)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
class WPMinify {
|
||||
|
||||
var $author_homepage = 'http://omninoggin.com/';
|
||||
var $homepage = 'http://omninoggin.com/wordpress-plugins/wp-minify-wordpress-plugin/';
|
||||
var $name = 'wp_minify';
|
||||
var $name_dashed = 'wp-minify';
|
||||
var $name_proper = 'WP Minify';
|
||||
var $required_wp_version = '2.7';
|
||||
var $version = '1.2.0';
|
||||
|
||||
var $c = null;
|
||||
var $debug = false;
|
||||
var $cache_location = 'wp-content/plugins/wp-minify/cache/';
|
||||
var $url_len_limit = 2000;
|
||||
var $minify_limit = 50;
|
||||
var $buffer_started = false;
|
||||
var $default_exclude = array();
|
||||
|
||||
function WPMinify() {
|
||||
// initialize common functions
|
||||
$this->c = new WPMinifyCommon($this);
|
||||
|
||||
// load translation
|
||||
$this->c->load_text_domain();
|
||||
|
||||
// register admin scripts
|
||||
add_action('admin_init', array($this->c, 'a_register_scripts'));
|
||||
add_action('admin_init', array($this->c, 'a_register_styles'));
|
||||
|
||||
// check wp version
|
||||
add_action('admin_head', array($this->c, 'a_check_version'));
|
||||
|
||||
// load admin menu
|
||||
add_action('admin_menu', array($this, 'a_menu'));
|
||||
|
||||
// register ajax handler
|
||||
add_action('wp_ajax_wpm', array($this, 'a_ajax_handler'));
|
||||
|
||||
// No need to minify admin stuff
|
||||
if (!is_admin() && !is_feed() && !defined('XMLRPC_REQUEST')) {
|
||||
// Don't minify if if user passes wp-minify-off=1 in GET parameter
|
||||
if (!(isset($_GET['wp-minify-off']) && $_GET['wp-minify-off'])) {
|
||||
add_action('init', array($this, 'pre_content'), 99999);
|
||||
add_action('wp_footer', array($this, 'post_content'));
|
||||
}
|
||||
// advertise hook
|
||||
add_action('wp_footer', array($this, 'advertise'));
|
||||
}
|
||||
}
|
||||
|
||||
// admin functions
|
||||
|
||||
function a_default_options() {
|
||||
return array(
|
||||
'cache_external' => false,
|
||||
'cache_interval' => 900,
|
||||
'css_exclude' => array(),
|
||||
'css_include' => array(),
|
||||
'debug_nominify' => false,
|
||||
'debug_firephp' => false,
|
||||
'enable_css' => true,
|
||||
'enable_js' => true,
|
||||
'enable_html' => true,
|
||||
'auto_base' => true,
|
||||
'extra_minify_options' => '',
|
||||
'js_exclude' => array(),
|
||||
'js_include' => array(),
|
||||
'js_in_footer' => false,
|
||||
'force_https' => false,
|
||||
'pretty_url' => false,
|
||||
'show_link' => false,
|
||||
'show_advanced' => false,
|
||||
'uri_exclude' => array(),
|
||||
'version' => $this->version,
|
||||
'deprecated' => array(
|
||||
'wp_path', 'debug', 'debug_noprettyurl'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function a_update_options() {
|
||||
// new options
|
||||
$wpm_new_options = stripslashes_deep($_POST['wpm_options_update']);
|
||||
|
||||
// current options
|
||||
$wpm_current_options = get_option($this->name);
|
||||
|
||||
// convert "on" to true and "off" to false for checkbox fields
|
||||
// and set defaults for fields that are left blank
|
||||
if (isset($wpm_new_options['show_link']) && $wpm_new_options['show_link'] == "on")
|
||||
$wpm_new_options['show_link'] = true;
|
||||
else
|
||||
$wpm_new_options['show_link'] = false;
|
||||
|
||||
if (isset($wpm_new_options['enable_js']))
|
||||
$wpm_new_options['enable_js'] = true;
|
||||
else
|
||||
$wpm_new_options['enable_js'] = false;
|
||||
|
||||
if (isset($wpm_new_options['enable_css']))
|
||||
$wpm_new_options['enable_css'] = true;
|
||||
else
|
||||
$wpm_new_options['enable_css'] = false;
|
||||
|
||||
if (isset($wpm_new_options['enable_html']))
|
||||
$wpm_new_options['enable_html'] = true;
|
||||
else
|
||||
$wpm_new_options['enable_html'] = false;
|
||||
|
||||
if (isset($wpm_new_options['auto_base']))
|
||||
$wpm_new_options['auto_base'] = true;
|
||||
else
|
||||
$wpm_new_options['auto_base'] = false;
|
||||
|
||||
if (isset($wpm_new_options['cache_external']))
|
||||
$wpm_new_options['cache_external'] = true;
|
||||
else
|
||||
$wpm_new_options['cache_external'] = false;
|
||||
|
||||
if (isset($wpm_new_options['js_in_footer']))
|
||||
$wpm_new_options['js_in_footer'] = true;
|
||||
else
|
||||
$wpm_new_options['js_in_footer'] = false;
|
||||
|
||||
if (isset($wpm_new_options['pretty_url']))
|
||||
$wpm_new_options['pretty_url'] = true;
|
||||
else
|
||||
$wpm_new_options['pretty_url'] = false;
|
||||
|
||||
if (isset($wpm_new_options['debug_nominify']))
|
||||
$wpm_new_options['debug_nominify'] = true;
|
||||
else
|
||||
$wpm_new_options['debug_nominify'] = false;
|
||||
|
||||
if (isset($wpm_new_options['debug_firephp']))
|
||||
$wpm_new_options['debug_firephp'] = true;
|
||||
else
|
||||
$wpm_new_options['debug_firephp'] = false;
|
||||
|
||||
$this->a_set_minify_config($wpm_new_options['debug_nominify'], $wpm_new_options['debug_firephp']);
|
||||
|
||||
if ( isset($wpm_new_options['force_https']) )
|
||||
$wpm_new_options['force_https'] = true;
|
||||
else
|
||||
$wpm_new_options['force_https'] = false;
|
||||
|
||||
if (strlen(trim($wpm_new_options['js_include'])) > 0)
|
||||
$wpm_new_options['js_include'] = $this->array_trim(split(chr(10), str_replace(chr(13), '', $wpm_new_options['js_include'])));
|
||||
else
|
||||
$wpm_new_options['js_include'] = array();
|
||||
|
||||
if (strlen(trim($wpm_new_options['js_exclude'])) > 0)
|
||||
$wpm_new_options['js_exclude'] = $this->array_trim(split(chr(10), str_replace(chr(13), '', $wpm_new_options['js_exclude'])));
|
||||
else
|
||||
$wpm_new_options['js_exclude'] = array();
|
||||
|
||||
if (strlen(trim($wpm_new_options['css_include'])) > 0)
|
||||
$wpm_new_options['css_include'] = $this->array_trim(split(chr(10), str_replace(chr(13), '', $wpm_new_options['css_include'])));
|
||||
else
|
||||
$wpm_new_options['css_include'] = array();
|
||||
|
||||
if (strlen(trim($wpm_new_options['css_exclude'])) > 0)
|
||||
$wpm_new_options['css_exclude'] = $this->array_trim(split(chr(10), str_replace(chr(13), '', $wpm_new_options['css_exclude'])));
|
||||
else
|
||||
$wpm_new_options['css_exclude'] = array();
|
||||
|
||||
if ( strlen(trim($wpm_new_options['uri_exclude'])) > 0 )
|
||||
$wpm_new_options['uri_exclude'] = $this->array_trim(split(chr(10), str_replace(chr(13), '', $wpm_new_options['uri_exclude'])));
|
||||
else
|
||||
$wpm_new_options['uri_exclude'] = array();
|
||||
|
||||
// Update options
|
||||
foreach ($wpm_new_options as $key => $value) {
|
||||
$wpm_current_options[$key] = $value;
|
||||
}
|
||||
|
||||
update_option($this->name, $wpm_current_options);
|
||||
}
|
||||
|
||||
function a_set_advanced_options($val) {
|
||||
$wpm_options = get_option($this->name);
|
||||
$wpm_options['show_advanced'] = $val;
|
||||
update_option($this->name, $wpm_options);
|
||||
}
|
||||
|
||||
function a_ajax_handler() {
|
||||
check_ajax_referer($this->name);
|
||||
if (isset($_POST['wpm_action'])) {
|
||||
if (strtolower($_POST['wpm_action']) == 'show_advanced') {
|
||||
$this->a_set_advanced_options(true);
|
||||
}
|
||||
elseif (strtolower($_POST['wpm_action']) == 'hide_advanced') {
|
||||
$this->a_set_advanced_options(false);
|
||||
}
|
||||
else {
|
||||
echo 'Invalid wpm_action.';
|
||||
}
|
||||
}
|
||||
exit();
|
||||
}
|
||||
|
||||
function a_request_handler() {
|
||||
if (isset($_POST['wpm_options_update_submit'])) {
|
||||
check_admin_referer($this->name);
|
||||
$this->a_update_options();
|
||||
add_action('admin_notices', array($this->c, 'a_notify_updated'));
|
||||
}
|
||||
elseif (isset($_POST['wpm_options_clear_cache_submit'])) {
|
||||
// if user wants to regenerate nonce
|
||||
check_admin_referer($this->name);
|
||||
$this->c->a_clear_cache();
|
||||
add_action('admin_notices', array($this->c, 'a_notify_cache_cleared'));
|
||||
}
|
||||
elseif (isset($_POST['wpm_options_upgrade_submit'])) {
|
||||
// if user wants to upgrade options (for new options on version upgrades)
|
||||
check_admin_referer($this->name);
|
||||
$this->c->a_upgrade_options();
|
||||
add_action('admin_notices', array($this->c, 'a_notify_upgraded'));
|
||||
}
|
||||
elseif (isset($_POST['wpm_options_reset_submit'])) {
|
||||
// if user wants to reset all options
|
||||
check_admin_referer($this->name);
|
||||
$this->c->a_reset_options();
|
||||
add_action('admin_notices', array($this->c, 'a_notify_reset'));
|
||||
}
|
||||
|
||||
// only check these on plugin settings page
|
||||
$this->c->a_check_dir_writable($this->c->get_plugin_dir().'cache/', array($this, 'a_notify_cache_not_writable'));
|
||||
$this->c->a_check_orphan_options(array($this, 'a_notify_orphan_options'));
|
||||
if ($this->c->a_check_dir_writable($this->c->get_plugin_dir().'min/config.php', array($this, 'a_notify_config_not_writable'))) {
|
||||
$this->a_check_minify_config();
|
||||
}
|
||||
}
|
||||
|
||||
function a_check_minify_config() {
|
||||
$fname = $this->c->get_plugin_dir().'min/config.php';
|
||||
$fhandle = fopen($fname,'r');
|
||||
$content = fread($fhandle,filesize($fname));
|
||||
|
||||
$config_modified = false;
|
||||
|
||||
preg_match('/\/\/###WPM-CACHE-PATH-BEFORE###(.*)\/\/###WPM-CACHE-PATH-AFTER###/s', $content, $matches);
|
||||
$cache_path_code = $matches[1];
|
||||
if (!preg_match('/\$min_cachePath.*?/', $cache_path_code)) {
|
||||
$content = preg_replace(
|
||||
'/\/\/###WPM-CACHE-PATH-BEFORE###(.*)\/\/###WPM-CACHE-PATH-AFTER###/s',
|
||||
"//###WPM-CACHE-PATH-BEFORE###\n".'$min_cachePath = \''.$this->c->get_plugin_dir()."cache/';\n//###WPM-CACHE-PATH-AFTER###",
|
||||
$content);
|
||||
$config_modified = true;
|
||||
}
|
||||
|
||||
preg_match('/\/\/###WPM-CACHE-AGE-BEFORE###(.*)\/\/###WPM-CACHE-AGE-AFTER###/s', $content, $matches);
|
||||
$cache_age_code = $matches[1];
|
||||
if (!preg_match('/\$min_serveOptions\[\'maxAge\'].*?/', $cache_age_code)) {
|
||||
$content = preg_replace(
|
||||
'/\/\/###WPM-CACHE-AGE-BEFORE###(.*)\/\/###WPM-CACHE-AGE-AFTER###/s',
|
||||
"//###WPM-CACHE-AGE-BEFORE###\n".'$min_serveOptions[\'maxAge\'] = 2592000;'."\n//###WPM-CACHE-AGE-AFTER###",
|
||||
$content);
|
||||
$config_modified = true;
|
||||
}
|
||||
|
||||
if ($config_modified) {
|
||||
$this->a_notify_modified_minify_config();
|
||||
}
|
||||
|
||||
$fhandle = fopen($fname,"w");
|
||||
fwrite($fhandle,$content);
|
||||
fclose($fhandle);
|
||||
}
|
||||
|
||||
function a_set_minify_config($nominify = false, $firephp = false) {
|
||||
if ($nominify) {
|
||||
$nominify = 'true';
|
||||
} else {
|
||||
$nominify = 'false';
|
||||
}
|
||||
if ($firephp) {
|
||||
$firephp = 'true';
|
||||
} else {
|
||||
$firephp = 'false';
|
||||
}
|
||||
$fname = $this->c->get_plugin_dir().'min/config.php';
|
||||
$fhandle = fopen($fname,'r');
|
||||
$content = fread($fhandle,filesize($fname));
|
||||
|
||||
$content = preg_replace(
|
||||
'/\/\/###WPM-DEBUG-FLAG-BEFORE###(.*)\/\/###WPM-DEBUG-FLAG-AFTER###/s',
|
||||
"//###WPM-DEBUG-FLAG-BEFORE###\n".'$min_allowDebugFlag = '.$nominify.";\n//###WPM-DEBUG-FLAG-AFTER###",
|
||||
$content);
|
||||
|
||||
$content = preg_replace(
|
||||
'/\/\/###WPM-ERROR-LOGGER-BEFORE###(.*)\/\/###WPM-ERROR-LOGGER-AFTER###/s',
|
||||
"//###WPM-ERROR-LOGGER-BEFORE###\n".'$min_errorLogger = '.$firephp.";\n//###WPM-ERROR-LOGGER-AFTER###",
|
||||
$content);
|
||||
|
||||
$fhandle = fopen($fname,"w");
|
||||
fwrite($fhandle,$content);
|
||||
fclose($fhandle);
|
||||
}
|
||||
|
||||
function a_notify_cache_not_writable() {
|
||||
$this->c->a_notify(
|
||||
sprintf('%s: %s',
|
||||
__('Cache directory is not writable. Please grant your server write permissions to the directory', $this->name),
|
||||
$this->c->get_plugin_dir().'cache/'),
|
||||
true);
|
||||
}
|
||||
|
||||
function a_notify_config_not_writable() {
|
||||
$this->c->a_notify(
|
||||
sprintf('%s: %s',
|
||||
__('Minify Engine config.php is not writable. Please grant your server write permissions to file', $this->name),
|
||||
$this->c->get_plugin_dir().'min/config.php'));
|
||||
}
|
||||
|
||||
function a_notify_orphan_options() {
|
||||
$this->c->a_notify(
|
||||
sprintf('%s',
|
||||
__('Some option settings are missing (possibly from plugin upgrade).', $this->name)));
|
||||
}
|
||||
|
||||
function a_notify_modified_minify_config() {
|
||||
$this->c->a_notify(__('Minify Engine config.php was configured automatically.', $this->name));
|
||||
}
|
||||
|
||||
function a_menu() {
|
||||
$options_page = add_options_page($this->name_proper, $this->name_proper, 'manage_options', 'wp-minify', array($this, 'a_page'));
|
||||
add_action('admin_head-'.$options_page, array($this, 'a_request_handler'));
|
||||
add_action('admin_print_scripts-'.$options_page, array($this->c, 'a_enqueue_scripts'));
|
||||
add_action('admin_print_styles-'.$options_page, array($this->c, 'a_enqueue_styles'));
|
||||
}
|
||||
|
||||
function a_page() {
|
||||
$wpm_options = get_option($this->name);
|
||||
printf('
|
||||
<div class="wrap omni_admin_content">
|
||||
<h2>%s</h2>
|
||||
<div>
|
||||
<a href="'.preg_replace('/&wpm-page=[^&]*/', '', $_SERVER['REQUEST_URI']).'">%s</a> |
|
||||
<a href="'.$this->homepage.'">%s</a>
|
||||
</div>',
|
||||
__('WP Minify Options', $this->name),
|
||||
__('General Configuration', $this->name),
|
||||
__('Documentation', $this->name)
|
||||
);
|
||||
printf('<div class="omni_admin_main">');
|
||||
if (isset($_GET['wpm-page'])) {
|
||||
if ($_GET['wpm-page'] || !$_GET['wpm-page']) {
|
||||
require_once('options-generic.php');
|
||||
}
|
||||
}
|
||||
else {
|
||||
require_once('options-generic.php');
|
||||
}
|
||||
printf('</div>'); // omni_admin_main
|
||||
require_once('options-sidebar.php');
|
||||
printf('</div>'); // wrap
|
||||
|
||||
} // admin_page()
|
||||
|
||||
// other functions
|
||||
|
||||
function fetch_and_cache($url, $cache_file) {
|
||||
$ch = curl_init();
|
||||
$timeout = 5; // set to zero for no timeout
|
||||
curl_setopt ($ch, CURLOPT_URL, $url);
|
||||
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||||
curl_setopt ($ch, CURLOPT_USERAGENT, 'WP-Minify');
|
||||
$content = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
if ($content) {
|
||||
if (is_array($content)) {
|
||||
$content = implode($content);
|
||||
}
|
||||
|
||||
// save cache file
|
||||
$fh = fopen($cache_file, 'w');
|
||||
if ($fh) {
|
||||
fwrite($fh, $content);
|
||||
fclose($fh);
|
||||
}
|
||||
else {
|
||||
// cannot open for write. no error b/c something else is probably writing to the file.
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
else {
|
||||
printf(
|
||||
'%s: '.$url.'. %s<br/>',
|
||||
__('Error: Could not fetch and cache URL'),
|
||||
__('You might need to exclude this file in WP Minify options.')
|
||||
);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function refetch_cache_if_expired($url, $cache_file) {
|
||||
$wpm_options = get_option($this->name);
|
||||
$cache_file_mtime = filemtime($cache_file);
|
||||
if ((time() - $cache_file_mtime) > $wpm_options['cache_interval']) {
|
||||
$this->fetch_and_cache($url, $cache_file);
|
||||
}
|
||||
}
|
||||
|
||||
function tiny_filename($str) {
|
||||
$f = __FILE__;
|
||||
// no fancy shortening for Windows
|
||||
return ('/' === $f[0]) ? strtr(base64_encode(md5($str, true)), '+/=', '-_(') : md5($str);
|
||||
}
|
||||
|
||||
function array_trim($arr, $charlist=null) {
|
||||
foreach ($arr as $key => $value) {
|
||||
if (is_array($value)) $result[$key] = array_trim($value, $charlist);
|
||||
else $result[$key] = trim($value, $charlist);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function check_and_split_url($url, $latest_modified = 0) {
|
||||
$url_chunk = explode('?f=', $url);
|
||||
$base_url = array_shift($url_chunk);
|
||||
$files = explode(',', array_shift($url_chunk));
|
||||
$num_files = sizeof($files);
|
||||
|
||||
if ($this->url_needs_splitting($url, $files)) {
|
||||
$first_half = $this->check_and_split_url($base_url . '?f=' . implode(',', array_slice($files, 0, $num_files/2)), $latest_modified);
|
||||
$second_half = $this->check_and_split_url($base_url . '?f=' . implode(',', array_slice($files, $num_files/2)), $latest_modified);
|
||||
return $first_half + $second_half;
|
||||
}
|
||||
else {
|
||||
$wpm_options = get_option($this->name);
|
||||
|
||||
// append &debug if we need to
|
||||
if ($wpm_options['debug_nominify']) {
|
||||
$debug_string = '&debug=true';
|
||||
} else {
|
||||
$debug_string = '';
|
||||
}
|
||||
|
||||
// append base directory if needed
|
||||
$base = $this->get_base();
|
||||
if ($base != '') {
|
||||
$base_string = '&b='.$base;
|
||||
} else {
|
||||
$base_string = '';
|
||||
}
|
||||
|
||||
// get rid of any base directory specification in extra options
|
||||
$extra_minify_options = preg_replace('/(&|&|\b)b=[^&]*/', '', trim($wpm_options['extra_minify_options']));
|
||||
if (trim($extra_minify_options) != '') {
|
||||
$extra_string = '&'.$extra_minify_options;
|
||||
} else {
|
||||
$extra_string = '';
|
||||
}
|
||||
|
||||
// append last modified time
|
||||
$latest_modified_string = '&m='.$latest_modified;
|
||||
|
||||
return array($base_url . '?f=' . implode(',', $files) . $debug_string . $base_string . $extra_string . $latest_modified_string);
|
||||
}
|
||||
}
|
||||
|
||||
function fetch_content($url, $type = '') {
|
||||
$cache_file = $this->c->get_plugin_dir().'cache/'.md5($url).$type;
|
||||
$content = '';
|
||||
if (file_exists($cache_file)) {
|
||||
// check cache expiration
|
||||
$this->refetch_cache_if_expired($url, $cache_file);
|
||||
|
||||
$fh = fopen($cache_file, 'r');
|
||||
if ($fh && filesize($cache_file) > 0) {
|
||||
$content = fread($fh, filesize($cache_file));
|
||||
fclose($fh);
|
||||
}
|
||||
else {
|
||||
// cannot open cache file so fetch it
|
||||
$content = $this->fetch_and_cache($url, $cache_file);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// no cache file. fetch from internet and save to local cache
|
||||
$content = $this->fetch_and_cache($url, $cache_file);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
function local_version($url) {
|
||||
$site_url = trailingslashit(get_option('siteurl'));
|
||||
$url = str_replace($site_url, '', $url); // relative paths only for local urls
|
||||
$url = preg_replace('/^\//', '', $url); // strip front / if any
|
||||
$url = preg_replace('/\?.*/i', '', $url); // throws away parameters, if any
|
||||
return $url;
|
||||
}
|
||||
|
||||
function is_external($url, $localize=true) {
|
||||
if ($localize) {
|
||||
$url = $this->local_version($url);
|
||||
}
|
||||
|
||||
if (substr($url, 0, 4) != 'http'
|
||||
&& (substr($url, -3, 3) == '.js' || substr($url, -4, 4) == '.css')) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function get_js_location($src) {
|
||||
if ($this->debug)
|
||||
echo 'Script URL:'.$src."<br/>\n";
|
||||
|
||||
$script_path = $this->local_version($src);
|
||||
if ($this->is_external($script_path, false)) {
|
||||
// fetch scripts if necessary
|
||||
$this->fetch_content($src, '.js');
|
||||
$location = $this->cache_location . md5($src) . '.js';
|
||||
if ($this->debug)
|
||||
echo 'External script detected, cached as:'. md5($src) . "<br/>\n";
|
||||
} else {
|
||||
// if script is local to server
|
||||
$location = $script_path;
|
||||
if ($this->debug)
|
||||
echo 'Local script detected:'.$script_path."<br/>\n";
|
||||
}
|
||||
|
||||
return $location;
|
||||
}
|
||||
|
||||
function get_css_location($src) {
|
||||
if ($this->debug)
|
||||
echo 'Style URL:'.$src."<br/>\n";
|
||||
|
||||
$css_path = $this->local_version($src);
|
||||
if ($this->is_external($css_path, false)) {
|
||||
// fetch scripts if necessary
|
||||
$this->fetch_content($src, '.css');
|
||||
$location = $this->cache_location . md5($src) . '.css';
|
||||
if ($this->debug)
|
||||
echo 'External css detected, cached as:'. md5($src) . "<br/>\n";
|
||||
} else {
|
||||
$location = $css_path;
|
||||
// if css is local to server
|
||||
if ($this->debug)
|
||||
echo 'Local css detected:'.$css_path."<br/>\n";
|
||||
}
|
||||
|
||||
return $location;
|
||||
}
|
||||
|
||||
function url_needs_splitting($url, $locations) {
|
||||
if ($url > $this->url_len_limit || count($locations) > $this->minify_limit) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function build_minify_urls($locations, $type) {
|
||||
$wpm_options = get_option($this->name);
|
||||
$minify_url = $this->c->get_plugin_url().'min/?f=';
|
||||
if ($wpm_options['force_https'] && $_SERVER["HTTPS"] == "on") {
|
||||
$minify_url = preg_replace('/^http:\/\//', 'https://', $minify_url);
|
||||
}
|
||||
$minify_url .= implode(',', $locations);
|
||||
$latest_modified = $this->get_latest_modified_time($locations);
|
||||
$minify_urls = $this->check_and_split_url($minify_url, $latest_modified);
|
||||
|
||||
if ($wpm_options['pretty_url']) {
|
||||
return $this->get_cached_minify_urls($minify_urls, $type);
|
||||
} else {
|
||||
return $minify_urls;
|
||||
}
|
||||
}
|
||||
|
||||
function get_cached_minify_urls($urls, $type) {
|
||||
$wpm_options = get_option($this->name);
|
||||
$cached_urls = array();
|
||||
foreach ($urls as $url) {
|
||||
$cache_file = $this->c->get_plugin_dir().'cache/'.md5($url).$type;
|
||||
if (file_exists($cache_file)) {
|
||||
// check cache expiration
|
||||
$this->refetch_cache_if_expired($url, $cache_file);
|
||||
|
||||
$fh = fopen($cache_file, 'r');
|
||||
if ($fh && filesize($cache_file) > 0) {
|
||||
$content = fread($fh, filesize($cache_file));
|
||||
fclose($fh);
|
||||
} else {
|
||||
// cannot open cache file so fetch it
|
||||
$this->fetch_and_cache($url, $cache_file);
|
||||
}
|
||||
} else {
|
||||
// no cache file. fetch it
|
||||
$this->fetch_and_cache($url, $cache_file);
|
||||
}
|
||||
$cache_url = $this->c->get_plugin_url().'cache/'.md5($url).$type.'?m='.filemtime($cache_file);
|
||||
$cached_urls[] = $cache_url;
|
||||
}
|
||||
return $cached_urls;
|
||||
}
|
||||
|
||||
function get_base_from_minify_args() {
|
||||
$wpm_options = get_option($this->name);
|
||||
if (!empty($wpm_options['extra_minify_options'])) {
|
||||
if (preg_match('/\bb=([^&]*?)(&|$)/', trim($wpm_options['extra_minify_options']), $matches)) {
|
||||
return rtrim(trim($matches[1]), '\\/');
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function get_base_from_siteurl() {
|
||||
$site_url = trailingslashit(get_option('siteurl'));
|
||||
return rtrim(preg_replace('/^https?:\/\/.*?\//', '', $site_url), '\\/');
|
||||
}
|
||||
|
||||
function get_base() {
|
||||
$base_from_min_args = $this->get_base_from_minify_args();
|
||||
if ($base_from_min_args != '') {
|
||||
return $base_from_min_args;
|
||||
}
|
||||
|
||||
$wpm_options = get_option($this->name);
|
||||
if ($wpm_options['auto_base']) {
|
||||
return $this->get_base_from_siteurl();
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function get_latest_modified_time($locations = array()) {
|
||||
$latest_modified = 0;
|
||||
if (!empty($locations)) {
|
||||
$base_path = trailingslashit($_SERVER['DOCUMENT_ROOT']);
|
||||
$base_path .= trailingslashit($this->get_base());
|
||||
|
||||
foreach ($locations as $location) {
|
||||
$path = $base_path.$location;
|
||||
$mtime = filemtime($path);
|
||||
if ($latest_modified < $mtime) {
|
||||
$latest_modified = $mtime;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $latest_modified;
|
||||
}
|
||||
|
||||
function extract_css($content) {
|
||||
$wpm_options = get_option($this->name);
|
||||
$css_locations = array();
|
||||
|
||||
preg_match_all('/<link([^>]*?)>/i', $content, $link_tags_match);
|
||||
|
||||
foreach ($link_tags_match[0] as $link_tag) {
|
||||
if (strpos(strtolower($link_tag), 'stylesheet')) {
|
||||
// check CSS media type
|
||||
if (!strpos(strtolower($link_tag), 'media=')
|
||||
|| preg_match('/media=["\'](?:["\']|[^"\']*?(all|screen)[^"\']*?["\'])/', $link_tag)
|
||||
) {
|
||||
preg_match('/href=[\'"]([^\'"]+)/', $link_tag, $href_match);
|
||||
if ($href_match[1]) {
|
||||
// include it if it is in the include list
|
||||
$include = false;
|
||||
$inclusions = $wpm_options['css_include'];
|
||||
foreach ($inclusions as $include_pat) {
|
||||
$include_pat = trim($include_pat);
|
||||
if (strlen($include_pat) > 0 && strpos($src_match[1], $include_pat) !== false) {
|
||||
$include = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$include) {
|
||||
// support external files?
|
||||
if (!$wpm_options['cache_external'] && $this->is_external($href_match[1])) {
|
||||
continue; // skip if we don't cache externals and this file is external
|
||||
}
|
||||
|
||||
// do not include anything in excluded list
|
||||
$skip = false;
|
||||
$exclusions = array_merge($this->default_exclude, $wpm_options['css_exclude']);
|
||||
foreach ($exclusions as $exclude_pat) {
|
||||
$exclude_pat = trim($exclude_pat);
|
||||
if (strlen($exclude_pat) > 0 && strpos($href_match[1], $exclude_pat) !== false) {
|
||||
$skip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($skip) continue;
|
||||
}
|
||||
|
||||
$content = str_replace($link_tag . '</link>', '', $content);
|
||||
$content = str_replace($link_tag, '', $content);
|
||||
$css_locations[] = $this->get_css_location($href_match[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$css_locations = array_unique($css_locations);
|
||||
|
||||
return array($content, $css_locations);
|
||||
}
|
||||
|
||||
function inject_css($content, $css_locations) {
|
||||
if (count($css_locations) > 0) {
|
||||
$wpm_options = get_option($this->name);
|
||||
// build minify URLS
|
||||
$css_tags = '';
|
||||
$minify_urls = $this->build_minify_urls($css_locations, '.css');
|
||||
|
||||
foreach ($minify_urls as $minify_url) {
|
||||
$minify_url = apply_filters('wp_minify_css_url', $minify_url); // Allow plugins to modify final minify URL
|
||||
$css_tags .= "<link rel='stylesheet' href='$minify_url' type='text/css' media='screen' />";
|
||||
}
|
||||
|
||||
$matches = preg_match('/<!-- WP-Minify CSS -->/', $content);
|
||||
|
||||
if ($matches) {
|
||||
$content = preg_replace('/<!-- WP-Minify CSS -->/', "$css_tags", $content, 1); // limit 1 replacement
|
||||
} else {
|
||||
// HTML5 has <header> tags so account for those in regex
|
||||
$content = preg_replace('/<head(>|\s[^>]*?>)/', "\\0\n$css_tags", $content, 1); // limit 1 replacement
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
function extract_conditionals($content) {
|
||||
preg_match_all('/<!--\[if[^\]]*?\]>.*?<!\[endif\]-->/is', $content, $conditionals_match);
|
||||
$content = preg_replace('/<!--\[if[^\]]*?\]>.*?<!\[endif\]-->/is', '###WPM-CSS-CONDITIONAL###', $content);
|
||||
|
||||
$conditionals = array();
|
||||
foreach ($conditionals_match[0] as $conditional) {
|
||||
$conditionals[] = $conditional;
|
||||
}
|
||||
|
||||
return array($content, $conditionals);
|
||||
}
|
||||
|
||||
function inject_conditionals($content, $conditionals) {
|
||||
while (count($conditionals) > 0 && strpos($content, '###WPM-CSS-CONDITIONAL###')) {
|
||||
$conditional = array_shift($conditionals);
|
||||
$content = preg_replace('/###WPM-CSS-CONDITIONAL###/', $conditional, $content, 1);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
function extract_js($content) {
|
||||
$wpm_options = get_option($this->name);
|
||||
$js_locations = array();
|
||||
|
||||
preg_match_all('/<script([^>]*?)><\/script>/i', $content, $script_tags_match);
|
||||
|
||||
foreach ($script_tags_match[0] as $script_tag) {
|
||||
if (strpos(strtolower($script_tag), 'text/javascript') !== false) {
|
||||
preg_match('/src=[\'"]([^\'"]+)/', $script_tag, $src_match);
|
||||
if ($src_match[1]) {
|
||||
// include it if it is in the include list
|
||||
$include = false;
|
||||
$inclusions = $wpm_options['js_include'];
|
||||
foreach ($inclusions as $include_pat) {
|
||||
$include_pat = trim($include_pat);
|
||||
if (strlen($include_pat) > 0 && strpos($src_match[1], $include_pat) !== false) {
|
||||
$include = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$include) {
|
||||
// support external files?
|
||||
if (!$wpm_options['cache_external'] && $this->is_external($src_match[1])) {
|
||||
continue; // skip if we don't cache externals and this file is external
|
||||
}
|
||||
|
||||
// do not include anything in excluded list
|
||||
$skip = false;
|
||||
$exclusions = array_merge($this->default_exclude, $wpm_options['js_exclude']);
|
||||
foreach ($exclusions as $exclude_pat) {
|
||||
$exclude_pat = trim($exclude_pat);
|
||||
if (strlen($exclude_pat) > 0 && strpos($src_match[1], $exclude_pat) !== false) {
|
||||
$skip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($skip) continue;
|
||||
}
|
||||
|
||||
$content = str_replace($script_tag, '', $content);
|
||||
$js_locations[] = $this->get_js_location($src_match[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$js_locations = array_unique($js_locations);
|
||||
|
||||
return array($content, $js_locations);
|
||||
}
|
||||
|
||||
function inject_js($content, $js_locations) {
|
||||
if (count($js_locations) > 0) {
|
||||
// build minify URLS
|
||||
$js_tags = '';
|
||||
$minify_urls = $this->build_minify_urls($js_locations, '.js');
|
||||
|
||||
foreach ($minify_urls as $minify_url) {
|
||||
$minify_url = apply_filters('wp_minify_js_url', $minify_url); // Allow plugins to modify final minify URL
|
||||
$js_tags .= "<script type='text/javascript' src='$minify_url'></script>";
|
||||
}
|
||||
|
||||
$matches = preg_match('/<!-- WP-Minify JS -->/', $content);
|
||||
|
||||
if ($matches) {
|
||||
$content = preg_replace('/<!-- WP-Minify JS -->/', "$js_tags", $content, 1); // limit 1 replacement
|
||||
} else {
|
||||
$wpm_options = get_option($this->name);
|
||||
if ($wpm_options['js_in_footer']) {
|
||||
$content = preg_replace('/<\/body>/', "$js_tags\n</body>", $content, 1); // limit 1 replacement
|
||||
} else {
|
||||
// HTML5 has <header> tags so account for those in regex
|
||||
$content = preg_replace('/<head(>|\s[^>]*?>)/', "\\0\n$js_tags", $content, 1); // limit 1 replacement
|
||||
}
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
function pre_content() {
|
||||
$wpm_options = get_option($this->name);
|
||||
if ($wpm_options['uri_exclude'] && count($wpm_options['uri_exclude'])) {
|
||||
foreach ($wpm_options['uri_exclude'] as $exclude_pat) {
|
||||
$exclude_pat = trim($exclude_pat);
|
||||
if (strlen($exclude_pat) > 0 && strpos($_SERVER['REQUEST_URI'], $exclude_pat) !== false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ob_start(array($this, 'modify_buffer'));
|
||||
|
||||
// variable for sanity checking
|
||||
$this->buffer_started = true;
|
||||
}
|
||||
|
||||
function modify_buffer($buffer) {
|
||||
$wpm_options = get_option($this->name);
|
||||
|
||||
// if we do not want to force http to https then we need to exclude https
|
||||
if (!($wpm_options['force_https'] && $_SERVER["HTTPS"] == "on")) {
|
||||
$this->default_exclude[] = 'https://';
|
||||
}
|
||||
|
||||
// minify JS
|
||||
if ($wpm_options['enable_js']) {
|
||||
list($buffer, $js_locations) = $this->extract_js($buffer);
|
||||
$buffer= $this->inject_js($buffer, $js_locations);
|
||||
}
|
||||
|
||||
// minify CSS (make sure to exclude CSS conditionals)
|
||||
if ($wpm_options['enable_css']) {
|
||||
list($buffer, $conditionals) = $this->extract_conditionals($buffer);
|
||||
list($buffer, $css_locations) = $this->extract_css($buffer);
|
||||
$buffer = $this->inject_css($buffer, $css_locations);
|
||||
$buffer = $this->inject_conditionals($buffer, $conditionals);
|
||||
}
|
||||
|
||||
// get rid of empty lines
|
||||
$buffer = preg_replace('/\s*(\r?\n)(\r?\n)*/', '$1', $buffer);
|
||||
|
||||
// minify HTML
|
||||
if ($wpm_options['enable_html']) {
|
||||
if (!class_exists('Minify_HTML')) {
|
||||
require_once('min/lib/Minify/HTML.php');
|
||||
}
|
||||
$buffer = Minify_HTML::minify($buffer);
|
||||
}
|
||||
|
||||
$buffer = apply_filters('wp_minify_content', $buffer); // allow plugins to modify buffer
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
function post_content() {
|
||||
// sanity checking
|
||||
if ($this->buffer_started) {
|
||||
ob_end_flush();
|
||||
}
|
||||
}
|
||||
|
||||
function advertise() {
|
||||
$wpm_options = get_option($this->name);
|
||||
if ($wpm_options['show_link']) {
|
||||
printf("<p align='center'><small>Page optimized by <a href='$this->homepage' title='$this->name_proper WordPress Plugin' style='text-decoration:none;'>$this->name_proper</a> <a href='$this->author_homepage' title='WordPress Plugin' style='text-decoration:none;'>WordPress Plugin</a></small></p>");
|
||||
}
|
||||
}
|
||||
|
||||
} // class WPMinify
|
||||
|
||||
require_once('common.php');
|
||||
require_once('http_build_url.php');
|
||||
$wp_minify = new WPMinify();
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user