| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Autoptimize |
| 4 |
Plugin URI: http://www.turleando.com.ar/ |
| 5 |
Description: Optimiza tu sitio web, uniendo el CSS y JavaScript, y comprimiéndolo. |
| 6 |
Version: 0.2 |
| 7 |
Author: Emilio López |
| 8 |
Author URI: http://www.turleando.com.ar/ |
| 9 |
Released under the GNU General Public License (GPL) |
| 10 |
http://www.gnu.org/licenses/gpl.txt |
| 11 |
*/ |
| 12 |
|
| 13 |
//Load config class |
| 14 |
@include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeConfig.php'); |
| 15 |
|
| 16 |
//Set up the buffering |
| 17 |
function autoptimize_start_buffering() |
| 18 |
{ |
| 19 |
//Pre-2.6 compatibility |
| 20 |
if(!defined('WP_PLUGIN_URL')) |
| 21 |
define('WP_PLUGIN_URL',WP_CONTENT_URL.'/plugins'); |
| 22 |
if(!defined('WP_PLUGIN_DIR')) |
| 23 |
define('WP_PLUGIN_DIR',WP_CONTENT_DIR.'/plugins'); |
| 24 |
|
| 25 |
//Config element |
| 26 |
$conf = autoptimizeConfig::instance(); |
| 27 |
|
| 28 |
//Load our always-on classes |
| 29 |
@include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeBase.php'); |
| 30 |
@include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeCache.php'); |
| 31 |
|
| 32 |
//Load extra classes and set some vars |
| 33 |
if($conf->get('autoptimize_html')) |
| 34 |
{ |
| 35 |
@include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeHTML.php'); |
| 36 |
@include(WP_PLUGIN_DIR.'/autoptimize/classes/minify-html.php'); |
| 37 |
} |
| 38 |
|
| 39 |
if($conf->get('autoptimize_js')) |
| 40 |
{ |
| 41 |
@include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeScripts.php'); |
| 42 |
@include(WP_PLUGIN_DIR.'/autoptimize/classes/jsmin-1.1.1.php'); |
| 43 |
define('CONCATENATE_SCRIPTS',false); |
| 44 |
define('COMPRESS_SCRIPTS',false); |
| 45 |
} |
| 46 |
|
| 47 |
if($conf->get('autoptimize_css')) |
| 48 |
{ |
| 49 |
@include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeStyles.php'); |
| 50 |
@include(WP_PLUGIN_DIR.'/autoptimize/classes/minify-css-compressor.php'); |
| 51 |
define('COMPRESS_CSS',false); |
| 52 |
} |
| 53 |
|
| 54 |
//Now, start the real thing! |
| 55 |
ob_start('autoptimize_end_buffering'); |
| 56 |
} |
| 57 |
|
| 58 |
//Action on end - |
| 59 |
function autoptimize_end_buffering($content) |
| 60 |
{ |
| 61 |
//Config element |
| 62 |
$conf = autoptimizeConfig::instance(); |
| 63 |
|
| 64 |
//Choose the classes |
| 65 |
$classes = array(); |
| 66 |
if($conf->get('autoptimize_js')) |
| 67 |
$classes[] = 'autoptimizeScripts'; |
| 68 |
if($conf->get('autoptimize_css')) |
| 69 |
$classes[] = 'autoptimizeStyles'; |
| 70 |
if($conf->get('autoptimize_html')) |
| 71 |
$classes[] = 'autoptimizeHTML'; |
| 72 |
|
| 73 |
//Run the classes |
| 74 |
foreach($classes as $name) |
| 75 |
{ |
| 76 |
$instance = new $name($content); |
| 77 |
if($instance->read()) |
| 78 |
{ |
| 79 |
$instance->minify(); |
| 80 |
$instance->cache(); |
| 81 |
$content = $instance->getcontent(); |
| 82 |
} |
| 83 |
unset($instance); |
| 84 |
} |
| 85 |
return $content; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
$conf = autoptimizeConfig::instance(); |
| 90 |
if($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css')) |
| 91 |
{ |
| 92 |
//Hook to wordpress |
| 93 |
add_action('template_redirect','autoptimize_start_buffering',2); |
| 94 |
} |
| 95 |
|