PluginProbe
Autoptimize / 1.2
Autoptimize v1.2
2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 All 107 releases
← All changes | autoptimize.php +133 -84 2.7.61.2 View file →
@@ -1,97 +1,146 @@
1 1 <?php
2 -/**
3 - * Plugin Name: Autoptimize
4 - * Plugin URI: https://autoptimize.com/
5 - * Description: Makes your site faster by optimizing CSS, JS, Images, Google fonts and more.
6 - * Version: 2.7.6
7 - * Author: Frank Goossens (futtta)
8 - * Author URI: https://autoptimize.com/
9 - * Text Domain: autoptimize
10 - * License: GPLv2
11 - * Released under the GNU General Public License (GPL)
12 - * https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
13 - */
2 +/*
3 +Plugin Name: Autoptimize
4 +Plugin URI: http://www.turleando.com.ar/autoptimize/
5 +Description: Optimizes your website, concatenating the CSS and JavaScript code, and compressing it.
6 +Version: 1.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 +*/
14 12
15 -/**
16 - * Autoptimize main plugin file.
17 - */
13 +//Load config and cache class
14 +include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeConfig.php');
15 +include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeCache.php');
18 16
17 +//Plugin constants
18 +define('AUTOPTIMIZE_CACHE_DIR',WP_CONTENT_DIR.'/cache/autoptimize/');
19 +define('AUTOPTIMIZE_CACHE_URL',WP_CONTENT_URL.'/cache/autoptimize/');
20 +define('AUTOPTIMIZE_CACHE_DELAY',true);
19 21
20 -if ( ! defined( 'ABSPATH' ) ) {
21 - exit;
22 -}
22 +//Initialize the cache at least once
23 +$conf = autoptimizeConfig::instance();
23 24
24 -define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.7.6' );
25 +//Do we gzip when caching?
26 +define('AUTOPTIMIZE_CACHE_NOGZIP',(bool) $conf->get('autoptimize_cache_nogzip'));
25 27
26 -// plugin_dir_path() returns the trailing slash!
27 -define( 'AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
28 -define( 'AUTOPTIMIZE_PLUGIN_FILE', __FILE__ );
28 +//Load translations
29 +$plugin_dir = basename(dirname(__FILE__));
30 +load_plugin_textdomain('autoptimize','wp-content/plugins/'.$plugin_dir.'/localization',$plugin_dir.'/localization');
29 31
30 -// Bail early if attempting to run on non-supported php versions.
31 -if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
32 - function autoptimize_incompatible_admin_notice() {
33 - echo '<div class="error"><p>' . __( 'Autoptimize requires PHP 5.6 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize' ) . '</p></div>';
34 - if ( isset( $_GET['activate'] ) ) {
35 - unset( $_GET['activate'] );
36 - }
37 - }
38 - function autoptimize_deactivate_self() {
39 - deactivate_plugins( plugin_basename( AUTOPTIMIZE_PLUGIN_FILE ) );
40 - }
41 - add_action( 'admin_notices', 'autoptimize_incompatible_admin_notice' );
42 - add_action( 'admin_init', 'autoptimize_deactivate_self' );
43 - return;
32 +//Set up the buffering
33 +function autoptimize_start_buffering()
34 +{
35 + //Config element
36 + $conf = autoptimizeConfig::instance();
37 +
38 + //Load our base class
39 + include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeBase.php');
40 +
41 + //Load extra classes and set some vars
42 + if($conf->get('autoptimize_html'))
43 + {
44 + include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeHTML.php');
45 + @include(WP_PLUGIN_DIR.'/autoptimize/classes/minify-html.php');
46 + }
47 +
48 + if($conf->get('autoptimize_js'))
49 + {
50 + include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeScripts.php');
51 + @include(WP_PLUGIN_DIR.'/autoptimize/classes/jsmin-1.1.1.php');
52 + define('CONCATENATE_SCRIPTS',false);
53 + define('COMPRESS_SCRIPTS',false);
54 + }
55 +
56 + if($conf->get('autoptimize_css'))
57 + {
58 + include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeStyles.php');
59 + @include(WP_PLUGIN_DIR.'/autoptimize/classes/minify-css-compressor.php');
60 + define('COMPRESS_CSS',false);
61 + }
62 +
63 + if($conf->get('autoptimize_js_yui') || $conf->get('autoptimize_css_yui'))
64 + {
65 + include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeYUI.php');
66 + }
67 +
68 + if($conf->get('autoptimize_cdn_js') || $conf->get('autoptimize_cdn_css'))
69 + {
70 + include(WP_PLUGIN_DIR.'/autoptimize/classes/autoptimizeCDN.php');
71 + }
72 +
73 + //Now, start the real thing!
74 + ob_start('autoptimize_end_buffering');
44 75 }
45 76
46 -function autoptimize_autoload( $class_name ) {
47 - if ( in_array( $class_name, array( 'Minify_HTML', 'JSMin' ) ) ) {
48 - $file = strtolower( $class_name );
49 - $file = str_replace( '_', '-', $file );
50 - $path = dirname( __FILE__ ) . '/classes/external/php/';
51 - $filepath = $path . $file . '.php';
52 - } elseif ( false !== strpos( $class_name, 'Autoptimize\\tubalmartin\\CssMin' ) ) {
53 - $file = str_replace( 'Autoptimize\\tubalmartin\\CssMin\\', '', $class_name );
54 - $path = dirname( __FILE__ ) . '/classes/external/php/yui-php-cssmin-bundled/';
55 - $filepath = $path . $file . '.php';
56 - } elseif ( 'autoptimize' === substr( $class_name, 0, 11 ) ) {
57 - // One of our "old" classes.
58 - $file = $class_name;
59 - $path = dirname( __FILE__ ) . '/classes/';
60 - $filepath = $path . $file . '.php';
61 - } elseif ( 'PAnD' === $class_name ) {
62 - $file = 'persist-admin-notices-dismissal';
63 - $path = dirname( __FILE__ ) . '/classes/external/php/persist-admin-notices-dismissal/';
64 - $filepath = $path . $file . '.php';
65 - }
66 -
67 - // If we didn't match one of our rules, bail!
68 - if ( ! isset( $filepath ) ) {
69 - return;
70 - }
71 -
72 - require $filepath;
77 +//Action on end -
78 +function autoptimize_end_buffering($content)
79 +{
80 + //Config element
81 + $conf = autoptimizeConfig::instance();
82 +
83 + //Choose the classes
84 + $classes = array();
85 + if($conf->get('autoptimize_js'))
86 + $classes[] = 'autoptimizeScripts';
87 + if($conf->get('autoptimize_css'))
88 + $classes[] = 'autoptimizeStyles';
89 + if($conf->get('autoptimize_cdn_js') || $conf->get('autoptimize_cdn_css'))
90 + $classes[] = 'autoptimizeCDN';
91 + if($conf->get('autoptimize_html'))
92 + $classes[] = 'autoptimizeHTML';
93 +
94 + //Set some options
95 + $classoptions = array(
96 + 'autoptimizeScripts' => array(
97 + 'justhead' => $conf->get('autoptimize_js_justhead'),
98 + 'trycatch' => $conf->get('autoptimize_js_trycatch'),
99 + 'yui' => $conf->get('autoptimize_js_yui'),
100 + ),
101 + 'autoptimizeStyles' => array(
102 + 'justhead' => $conf->get('autoptimize_css_justhead'),
103 + 'datauris' => $conf->get('autoptimize_css_datauris'),
104 + 'yui' => $conf->get('autoptimize_css_yui'),
105 + ),
106 + 'autoptimizeCDN' => array(
107 + 'js' => $conf->get('autoptimize_cdn_js'),
108 + 'jsurl' => $conf->get('autoptimize_cdn_js_url'),
109 + 'css' => $conf->get('autoptimize_cdn_css'),
110 + 'cssurl' => $conf->get('autoptimize_cdn_css_url'),
111 + 'img' => $conf->get('autoptimize_cdn_img'),
112 + 'imgurl' => $conf->get('autoptimize_cdn_img_url')
113 + ),
114 + 'autoptimizeHTML' => array(
115 + 'keepcomments' => $conf->get('autoptimize_html_keepcomments')
116 + )
117 + );
118 +
119 +
120 + //Run the classes
121 + foreach($classes as $name)
122 + {
123 + $instance = new $name($content);
124 + if($instance->read($classoptions[$name]))
125 + {
126 + $instance->minify();
127 + $instance->cache();
128 + $content = $instance->getcontent();
129 + }
130 + unset($instance);
131 + }
132 + return $content;
73 133 }
74 134
75 -spl_autoload_register( 'autoptimize_autoload' );
76 -
77 -// Load WP CLI command(s) on demand.
78 -if ( defined( 'WP_CLI' ) && WP_CLI ) {
79 - require AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php';
135 +if(autoptimizeCache::cacheavail())
136 +{
137 + $conf = autoptimizeConfig::instance();
138 + if($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') || $conf->get('autoptimize_cdn_js') || $conf->get('autoptimize_cdn_css'))
139 + {
140 + //Hook to wordpress
141 + add_action('template_redirect','autoptimize_start_buffering',2);
142 + }
80 143 }
81 144
82 -/**
83 - * Retrieve the instance of the main plugin class.
84 - *
85 - * @return autoptimizeMain
86 - */
87 -function autoptimize() {
88 - static $plugin = null;
89 -
90 - if ( null === $plugin ) {
91 - $plugin = new autoptimizeMain( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE );
92 - }
93 -
94 - return $plugin;
95 -}
96 -
97 -autoptimize()->run();
145 +//Do not pollute other plugins
146 +unset($conf);