Example #1
0
 public function delete_cache()
 {
     check_ajax_referer('ao_delcache_nonce', 'nonce');
     if (current_user_can('manage_options')) {
         // We call the function for cleaning the Autoptimize cache
         autoptimizeCache::clearall();
     }
     wp_die();
     // NOTE: Remember that any return values of this function must be in JSON format
 }
function autoptimize_cachechecker_notice()
{
    if ((bool) get_option("autoptimize_cachesize_notice", false)) {
        $statArr = autoptimizeCache::stats();
        $cacheSize = round($statArr[1] / 1024);
        echo '<div class="update-nag">';
        _e('Autoptimize\'s cache size is getting big, consider purging the cache.<br /><br />Have a look at <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize');
        echo '</div>';
        update_option("autoptimize_cachesize_notice", false);
    }
}
function ao_cachechecker_cronjob()
{
    $maxSize = (int) apply_filters("autoptimize_filter_cachecheck_maxsize", 512000);
    $doCacheCheck = (bool) apply_filters("autoptimize_filter_cachecheck_do", true);
    $statArr = autoptimizeCache::stats();
    $cacheSize = round($statArr[1] / 1024);
    if ($cacheSize > $maxSize && $doCacheCheck) {
        update_option("autoptimize_cachesize_notice", true);
        if (apply_filters('autoptimize_filter_cachecheck_sendmail', true)) {
            $ao_mailto = apply_filters('autoptimize_filter_cachecheck_mailto', get_option('admin_email', ''));
            $ao_mailsubject = __('Autoptimize cache size warning', 'autoptimize');
            $ao_mailbody = __('Autoptimize\'s cache size is getting big, consider purging the cache. Have a look at https://wordpress.org/plugins/autoptimize/faq/ to see how you can keep the cache size under control.', 'autoptimize');
            if (!empty($ao_mailto)) {
                $ao_mailresult = wp_mail($ao_mailto, $ao_mailsubject, $ao_mailbody);
                if (!$ao_mailresult) {
                    error_log("Autoptimize could not send cache size warning mail.");
                }
            }
        }
    }
}
Example #4
0
function autoptimize_uninstall()
{
    autoptimizeCache::clearall();
    $delete_options = array("autoptimize_cache_clean", "autoptimize_cache_nogzip", "autoptimize_css", "autoptimize_css_datauris", "autoptimize_css_justhead", "autoptimize_css_defer", "autoptimize_css_defer_inline", "autoptimize_css_inline", "autoptimize_css_exclude", "autoptimize_html", "autoptimize_html_keepcomments", "autoptimize_js", "autoptimize_js_exclude", "autoptimize_js_forcehead", "autoptimize_js_justhead", "autoptimize_js_trycatch", "autoptimize_version", "autoptimize_show_adv", "autoptimize_cdn_url", "autoptimize_cachesize_notice", "autoptimize_css_include_inline", "autoptimize_js_include_inline", "autoptimize_css_nogooglefont");
    if (!is_multisite()) {
        foreach ($delete_options as $del_opt) {
            delete_option($del_opt);
        }
    } else {
        global $wpdb;
        $blog_ids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}");
        $original_blog_id = get_current_blog_id();
        foreach ($blog_ids as $blog_id) {
            switch_to_blog($blog_id);
            foreach ($delete_options as $del_opt) {
                delete_option($del_opt);
            }
        }
        switch_to_blog($original_blog_id);
    }
    if (wp_get_schedule('ao_cachechecker')) {
        wp_clear_scheduled_hook('ao_cachechecker');
    }
}
 public function cache()
 {
     $cache = new autoptimizeCache($this->md5hash, 'js');
     if (!$cache->check()) {
         //Cache our code
         $cache->cache($this->jscode, 'text/javascript');
     }
     $this->url = AUTOPTIMIZE_CACHE_URL . $cache->getname();
     $this->url = $this->url_replace_cdn($this->url);
 }
 static function stats()
 {
     //Cache not available :(
     if (!autoptimizeCache::cacheavail()) {
         return 0;
     }
     //Count cached info
     $count = 0;
     $scan = scandir(AUTOPTIMIZE_CACHE_DIR);
     foreach ($scan as $file) {
         if (!in_array($file, array('.', '..')) && strpos($file, 'autoptimize') !== false) {
             if (is_file(AUTOPTIMIZE_CACHE_DIR . $file)) {
                 if (AUTOPTIMIZE_CACHE_NOGZIP && (strpos($file, '.js') !== false || strpos($file, '.css') !== false)) {
                     $count++;
                 } elseif (!AUTOPTIMIZE_CACHE_NOGZIP && strpos($file, '.none') !== false) {
                     $count++;
                 }
                 /*else{
                 			//Tricky one... it was a dir or a gzip/deflate file
                 		}*/
             }
         }
     }
     //Tell the number of instances
     return $count;
 }
    public function show()
    {
        ?>
<style>input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:100;} #futtta_feed ul{list-style:outside;} #futtta_feed {font-size:medium; margin:0px 20px;}</style>

<div class="wrap">

<h1><?php 
        _e('Autoptimize Settings', 'autoptimize');
        ?>
</h1>

<div style="float:left;width:70%;">
<?php 
        if (get_option('autoptimize_show_adv', '0') == '1') {
            ?>
	<a href="javascript:void(0);" id="ao_show_adv" class="button" style="display:none;"><?php 
            _e("Show advanced settings", "autoptimize");
            ?>
</a>
	<a href="javascript:void(0);" id="ao_hide_adv" class="button"><?php 
            _e("Hide advanced settings", "autoptimize");
            ?>
</a>
	<style>.ao_adv {display:table-row};</style>
	<?php 
        } else {
            ?>
	<a href="javascript:void(0);" id="ao_show_adv" class="button"><?php 
            _e("Show advanced settings", "autoptimize");
            ?>
</a>
	<a href="javascript:void(0);" id="ao_hide_adv" class="button" style="display:none;"><?php 
            _e("Hide advanced settings", "autoptimize");
            ?>
</a>
	<?php 
        }
        ?>

<form method="post" action="options.php">
<?php 
        settings_fields('autoptimize');
        ?>

<h2><?php 
        _e('HTML Options', 'autoptimize');
        ?>
</h2>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize HTML Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php 
        echo get_option('autoptimize_html') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr class="html_sub" valign="top">
<th scope="row"><?php 
        _e('Keep HTML comments?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_html_keepcomments"><input type="checkbox" name="autoptimize_html_keepcomments" <?php 
        echo get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Enable this if you want HTML comments to remain in the page, needed for e.g. AdSense to function properly.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h2><?php 
        _e('JavaScript Options', 'autoptimize');
        ?>
</h2>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize JavaScript Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php 
        echo get_option('autoptimize_js') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr valign="top" class="hidden js_sub ao_adv">
<th scope="row"><?php 
        _e('Force JavaScript in &lt;head&gt;?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_forcehead"><input type="checkbox" name="autoptimize_js_forcehead" <?php 
        echo get_option('autoptimize_js_forcehead', '1') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Load JavaScript early, reducing the chance of JS-errors but making it render blocking. You can disable this if you\'re not aggregating inline JS and you want JS to be deferred.', 'autoptimize');
        ?>
</label></td>
</tr>
<?php 
        if (get_option('autoptimize_js_justhead')) {
            ?>
<tr valign="top" class="hidden js_sub ao_adv">
<th scope="row"><?php 
            _e('Look for scripts only in &lt;head&gt;?', 'autoptimize');
            _e(' <i>(deprecated)</i>', 'autoptimize');
            ?>
</th>
<td><label for="autoptimize_js_justhead"><input type="checkbox" name="autoptimize_js_justhead" <?php 
            echo get_option('autoptimize_js_justhead') ? 'checked="checked" ' : '';
            ?>
/>
<?php 
            _e('Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize');
            ?>
</label></td>
</tr>
<?php 
        }
        ?>
<tr valign="top" class="hidden js_sub ao_adv">
<th scope="row"><?php 
        _e('Also aggregate inline JS?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_include_inline"><input type="checkbox" name="autoptimize_js_include_inline" <?php 
        echo get_option('autoptimize_js_include_inline') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Check this option for Autoptimize to also aggregate JS in the HTML. If this option is not enabled, you might have to "force JavaScript in head".', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden js_sub ao_adv">
<th scope="row"><?php 
        _e('Exclude scripts from Autoptimize:', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_exclude"><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php 
        echo get_option('autoptimize_js_exclude', "s_sid,smowtion_size,sc_project,WAU_,wau_add,comment-form-quicktags,edToolbar,ch_client,seal.js");
        ?>
"/><br />
<?php 
        _e('A comma-seperated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated and minimized by Autoptimize.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden js_sub ao_adv">
<th scope="row"><?php 
        _e('Add try-catch wrapping?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_trycatch"><input type="checkbox" name="autoptimize_js_trycatch" <?php 
        echo get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('If your scripts break because of a JS-error, you might want to try this.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h2><?php 
        _e('CSS Options', 'autoptimize');
        ?>
</h2>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize CSS Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php 
        echo get_option('autoptimize_css') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr class="hidden css_sub ao_adv" valign="top">
<th scope="row"><?php 
        _e('Generate data: URIs for images?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_datauris"><input type="checkbox" name="autoptimize_css_datauris" <?php 
        echo get_option('autoptimize_css_datauris') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Enable this to include small background-images in the CSS itself instead of as seperate downloads.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr class="hidden css_sub ao_adv" valign="top">
<th scope="row"><?php 
        _e('Remove Google Fonts?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_datauris"><input type="checkbox" name="autoptimize_css_nogooglefont" <?php 
        echo get_option('autoptimize_css_nogooglefont') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Check this if you don\'t need or want Google Fonts being loaded.', 'autoptimize');
        ?>
</label></td>
</tr>
<?php 
        if (get_option('autoptimize_css_justhead')) {
            ?>
<tr valign="top" class="hidden css_sub ao_adv">
<th scope="row"><?php 
            _e('Look for styles only in &lt;head&gt;?', 'autoptimize');
            _e(' <i>(deprecated)</i>', 'autoptimize');
            ?>
</th>
<td><label for="autoptimize_css_justhead"><input type="checkbox" name="autoptimize_css_justhead" <?php 
            echo get_option('autoptimize_css_justhead') ? 'checked="checked" ' : '';
            ?>
/>
<?php 
            _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize');
            ?>
</label></td>
</tr>
<?php 
        }
        ?>
<tr valign="top" class="hidden css_sub ao_adv">
<th scope="row"><?php 
        _e('Also aggregate inline CSS?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_include_inline"><input type="checkbox" name="autoptimize_css_include_inline" <?php 
        echo get_option('autoptimize_css_include_inline') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden css_sub ao_adv">
<th scope="row"><?php 
        _e('Inline and Defer CSS?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_defer"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php 
        echo get_option('autoptimize_css_defer') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="http://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> before activating this option!', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden css_sub ao_adv" id="autoptimize_css_defer_inline">
<th scope="row"></th>
<td><label for="autoptimize_css_defer_inline"><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php 
        _e('Paste the above the fold CSS here.', 'autoptimize');
        ?>
" name="autoptimize_css_defer_inline"><?php 
        echo get_option('autoptimize_css_defer_inline');
        ?>
</textarea></label></td>
</tr>
<tr valign="top" class="hidden ao_adv css_sub">
<th scope="row"><?php 
        _e('Inline all CSS?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_inline"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php 
        echo get_option('autoptimize_css_inline') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Inlining all CSS can improve performance for sites with a low pageviews/ visitor-rate, but may slow down performance otherwise.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden ao_adv css_sub">
<th scope="row"><?php 
        _e('Exclude CSS from Autoptimize:', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_exclude"><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php 
        echo get_option('autoptimize_css_exclude', 'admin-bar.min.css, dashicons.min.css');
        ?>
"/><br />
<?php 
        _e('A comma-seperated list of CSS you want to exclude from being optimized.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h2><?php 
        _e('CDN Options', 'autoptimize');
        ?>
</h2>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('CDN Base URL', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_url"><input id="cdn_url" type="url" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php 
        $it = get_option('autoptimize_cdn_url', '');
        echo htmlentities($it);
        ?>
" /><br />
<?php 
        _e('Enter your CDN blog root directory URL if you want to enable CDN for images referenced in the CSS.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h2 class="hidden ao_adv"><?php 
        _e('Cache Info', 'autoptimize');
        ?>
</h2>
<table class="form-table" > 
<tr valign="top" class="hidden ao_adv">
<th scope="row"><?php 
        _e('Cache folder', 'autoptimize');
        ?>
</th>
<td><?php 
        echo htmlentities(AUTOPTIMIZE_CACHE_DIR);
        ?>
</td>
</tr>
<tr valign="top" class="hidden ao_adv">
<th scope="row"><?php 
        _e('Can we write?', 'autoptimize');
        ?>
</th>
<td><?php 
        echo autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize');
        ?>
</td>
</tr>
<tr valign="top" class="hidden ao_adv">
<th scope="row"><?php 
        _e('Cached styles and scripts', 'autoptimize');
        ?>
</th>
<td><?php 
        $AOstatArr = autoptimizeCache::stats();
        $AOcacheSize = round($AOstatArr[1] / 1024);
        echo $AOstatArr[0] . " files, totalling " . $AOcacheSize . " Kbytes (calculated at " . date("H:i e", $AOstatArr[2]) . ")";
        ?>
</td>
</tr>
<tr valign="top" class="hidden ao_adv">
<th scope="row"><?php 
        _e('Save aggregated script/css as static files?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_cache_nogzip"><input type="checkbox" name="autoptimize_cache_nogzip" <?php 
        echo get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>
<input type="hidden" id="autoptimize_show_adv" name="autoptimize_show_adv" value="<?php 
        echo get_option('autoptimize_show_adv', '0');
        ?>
">

<p class="submit">
<input type="submit" class="button-secondary" value="<?php 
        _e('Save Changes', 'autoptimize');
        ?>
" />
<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php 
        _e('Save Changes and Empty Cache', 'autoptimize');
        ?>
" />
</p>

</form>
</div>
<style>.autoptimize_banner ul li {font-size:medium;text-align:center;} .unslider-arrow {left:unset;}</style>
<div class="autoptimize_banner">
	<ul>
	<?php 
        $AO_banner = get_transient("autoptimize_banner");
        if (empty($AO_banner)) {
            $banner_resp = wp_remote_get("http://optimizingmatters.com/autoptimize_news.html");
            if (!is_wp_error($banner_resp)) {
                if (wp_remote_retrieve_response_code($banner_resp) == "200") {
                    $AO_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp));
                    set_transient("autoptimize_banner", $AO_banner, DAY_IN_SECONDS);
                }
            }
        }
        echo $AO_banner;
        ?>
	<li><?php 
        _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ</a> or post your question on <a href='http://wordpress.org/support/plugin/autoptimize'>the support-forum</a>.");
        ?>
</li>
	<li><?php 
        _e("Happy with Autoptimize?", "autoptimize");
        ?>
<br /><a href="<?php 
        echo network_admin_url();
        ?>
plugin-install.php?tab=search&type=author&s=futtta"><?php 
        _e("Try my other plugins!");
        ?>
</a></li>
	</ul>
</div>
<div style="float:right;width:30%" id="autoptimize_admin_feed">
        <div style="margin-left:10px;margin-top:-5px;">
                <h2>
                        <?php 
        _e("futtta about", "autoptimize");
        ?>
                        <select id="feed_dropdown" >
                                <option value="1"><?php 
        _e("Autoptimize", "autoptimize");
        ?>
</option>
                                <option value="2"><?php 
        _e("WordPress", "autoptimize");
        ?>
</option>
                                <option value="3"><?php 
        _e("Web Technology", "autoptimize");
        ?>
</option>
                        </select>
                </h2>
                <div id="futtta_feed">
       			<div id="autoptimizefeed">
				<?php 
        $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_autoptimize");
        ?>
			</div>
			<div id="wordpressfeed">
				<?php 
        $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_wordpress");
        ?>
			</div>
			<div id="webtechfeed">
				<?php 
        $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_webtech");
        ?>
			</div>
                </div>
        </div>
	<div style="float:right;margin:50px 15px;"><a href="http://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php 
        echo content_url();
        ?>
/plugins/autoptimize/classes/external/do_not_donate_smallest.png" title="<?php 
        _e("Do not donate for this plugin!");
        ?>
"></a></div>
</div>

<script type="text/javascript">
	var feed = new Array;
	feed[1]="autoptimizefeed";
	feed[2]="wordpressfeed";
	feed[3]="webtechfeed";
	cookiename="autoptimize_feed";

	jQuery(document).ready(function() {
		check_ini_state();
		
		jQuery('.autoptimize_banner').unslider({autoplay:true, delay:5000});
		
		jQuery( "#ao_show_adv" ).click(function() {
			jQuery( "#ao_show_adv" ).hide();
			jQuery( "#ao_hide_adv" ).show();
			jQuery( ".ao_adv" ).show("slow");
			if (jQuery("#autoptimize_css").attr('checked')) {
				jQuery(".css_sub:visible").fadeTo("fast",1);
				if (!jQuery("#autoptimize_css_defer").attr('checked')) {
					jQuery("#autoptimize_css_defer_inline").hide();
				}
			}
			if (jQuery("#autoptimize_js").attr('checked')) {
				jQuery(".js_sub:visible").fadeTo("fast",1);
			}
			check_ini_state()
			jQuery( "input#autoptimize_show_adv" ).val("1");
		});

		jQuery( "#ao_hide_adv" ).click(function() {
			jQuery( "#ao_hide_adv" ).hide();
			jQuery( "#ao_show_adv" ).show();
			jQuery( ".ao_adv" ).hide("slow");
                        if (!jQuery("#autoptimize_css").attr('checked')) {
                                jQuery(".css_sub:visible").fadeTo("fast",.33);
                        }
                        if (!jQuery("#autoptimize_js").attr('checked')) {
                                jQuery(".js_sub:visible").fadeTo("fast",.33);
                        }
                        check_ini_state()
			jQuery( "input#autoptimize_show_adv" ).val("0");
		});

		jQuery( "#autoptimize_html" ).change(function() {
			if (this.checked) {
				jQuery(".html_sub:visible").fadeTo("fast",1);
			} else {
				jQuery(".html_sub:visible").fadeTo("fast",.33);
			}
		});

                jQuery( "#autoptimize_js" ).change(function() {
                        if (this.checked) {
                                jQuery(".js_sub:visible").fadeTo("fast",1);
                        } else {
                                jQuery(".js_sub:visible").fadeTo("fast",.33);
                        }
                });

                jQuery( "#autoptimize_css" ).change(function() {
                        if (this.checked) {
                                jQuery(".css_sub:visible").fadeTo("fast",1);
                        } else {
                                jQuery(".css_sub:visible").fadeTo("fast",.33);
                        }
                });
		
		jQuery( "#autoptimize_css_inline" ).change(function() {
			if (this.checked) {
				jQuery("#autoptimize_css_defer").prop("checked",false);
				jQuery("#autoptimize_css_defer_inline").hide("slow");
			}
		});
		
		jQuery( "#autoptimize_css_defer" ).change(function() {
			if (this.checked) {
				jQuery("#autoptimize_css_inline").prop("checked",false);
				jQuery("#autoptimize_css_defer_inline").show("slow");
			} else {
				jQuery("#autoptimize_css_defer_inline").hide("slow");
			}
		});
		
		jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) });
		feedid=jQuery.cookie(cookiename);
		if(typeof(feedid) !== "string") feedid=1;
		show_feed(feedid);
	})

	function check_ini_state() {
		if (!jQuery("#autoptimize_css_defer").attr('checked')) {
			jQuery("#autoptimize_css_defer_inline").hide();
		}
		if (!jQuery("#autoptimize_html").attr('checked')) {
			jQuery(".html_sub:visible").fadeTo('fast',.33);
		}
                if (!jQuery("#autoptimize_css").attr('checked')) {
                        jQuery(".css_sub:visible").fadeTo('fast',.33);
                }
                if (!jQuery("#autoptimize_js").attr('checked')) {
                        jQuery(".js_sub:visible").fadeTo('fast',.33);
                }
	}

	function show_feed(id) {
		jQuery('#futtta_feed').children().hide();
		jQuery('#'+feed[id]).show();
		jQuery("#feed_dropdown").val(id);
		jQuery.cookie(cookiename,id,{ expires: 365 });
	}
</script>
</div>

<?php 
    }
Example #8
0
 public function getcontent()
 {
     // restore IE hacks
     $this->content = $this->restore_iehacks($this->content);
     // restore comments
     $this->content = $this->restore_comments($this->content);
     // restore noscript
     if (strpos($this->content, '%%NOSCRIPT%%') !== false) {
         $this->content = preg_replace_callback('#%%NOSCRIPT%%(.*?)%%NOSCRIPT%%#is', create_function('$matches', 'return stripslashes(base64_decode($matches[1]));'), $this->content);
     }
     // restore noptimize
     $this->content = $this->restore_noptimize($this->content);
     //Restore the full content
     if (!empty($this->restofcontent)) {
         $this->content .= $this->restofcontent;
         $this->restofcontent = '';
     }
     // Inject the new stylesheets
     $replaceTag = array("<title", "before");
     $replaceTag = apply_filters('autoptimize_filter_css_replacetag', $replaceTag);
     if ($this->inline == true) {
         foreach ($this->csscode as $media => $code) {
             $this->inject_in_html('<style type="text/css" media="' . $media . '">' . $code . '</style>', $replaceTag);
         }
     } else {
         if ($this->defer == true) {
             $deferredCssBlock = "<script>function lCss(url,media) {var d=document;var l=d.createElement('link');l.rel='stylesheet';l.type='text/css';l.href=url;l.media=media; d.getElementsByTagName('head')[0].appendChild(l);}function deferredCSS() {";
             $noScriptCssBlock = "<noscript>";
             $defer_inline_code = $this->defer_inline;
             $defer_inline_code = apply_filters('autoptimize_filter_css_defer_inline', $defer_inline_code);
             if (!empty($defer_inline_code)) {
                 $iCssHash = md5($defer_inline_code);
                 $iCssCache = new autoptimizeCache($iCssHash, 'css');
                 if ($iCssCache->check()) {
                     // we have the optimized inline CSS in cache
                     $defer_inline_code = $iCssCache->retrieve();
                 } else {
                     if (class_exists('Minify_CSS_Compressor')) {
                         $tmp_code = trim(Minify_CSS_Compressor::process($this->defer_inline));
                     } else {
                         if (class_exists('CSSmin')) {
                             $cssmin = new CSSmin();
                             $tmp_code = trim($cssmin->run($defer_inline_code));
                         }
                     }
                     if (!empty($tmp_code)) {
                         $defer_inline_code = $tmp_code;
                         $iCssCache->cache($defer_inline_code, "text/css");
                         unset($tmp_code);
                     }
                 }
                 $code_out = '<style type="text/css" media="all">' . $defer_inline_code . '</style>';
                 $this->inject_in_html($code_out, $replaceTag);
             }
         }
         foreach ($this->url as $media => $url) {
             $url = $this->url_replace_cdn($url);
             //Add the stylesheet either deferred (import at bottom) or normal links in head
             if ($this->defer == true) {
                 $deferredCssBlock .= "lCss('" . $url . "','" . $media . "');";
                 $noScriptCssBlock .= '<link type="text/css" media="' . $media . '" href="' . $url . '" rel="stylesheet" />';
             } else {
                 $this->inject_in_html('<link type="text/css" media="' . $media . '" href="' . $url . '" rel="stylesheet" />', $replaceTag);
             }
         }
         if ($this->defer == true) {
             $deferredCssBlock .= "}if(window.addEventListener){window.addEventListener('DOMContentLoaded',deferredCSS,false);}else{window.onload = deferredCSS;}</script>";
             $noScriptCssBlock .= "</noscript>";
             $this->inject_in_html($noScriptCssBlock, array('<title>', 'before'));
             $this->inject_in_html($deferredCssBlock, array('</body>', 'before'));
         }
     }
     //Return the modified stylesheet
     return $this->content;
 }
 /**
  * Clear cache
  */
 public function clear_pagecache()
 {
     if (class_exists('autoptimizeCache')) {
         // clean the Autoptimize cache
         autoptimizeCache::clearall();
     }
 }
    public function show()
    {
        ?>
<style>input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:100;}</style>

<div class="wrap">

<h2><?php 
        _e('Autoptimize Settings', 'autoptimize');
        ?>
</h2>

<div style="float:left;width:70%;">
<?php 
        if (get_option('autoptimize_show_adv', '0') == '1') {
            ?>
	<a href="javascript:void(0);" id="ao_show_adv" class="button" style="display:none;"><?php 
            _e("Show advanced settings", "autoptimize");
            ?>
</a>
	<a href="javascript:void(0);" id="ao_hide_adv" class="button"><?php 
            _e("Hide advanced settings", "autoptimize");
            ?>
</a>
	<style>.ao_adv {display:table-row};</style>
	<?php 
        } else {
            ?>
	<a href="javascript:void(0);" id="ao_show_adv" class="button"><?php 
            _e("Show advanced settings", "autoptimize");
            ?>
</a>
	<a href="javascript:void(0);" id="ao_hide_adv" class="button" style="display:none;"><?php 
            _e("Hide advanced settings", "autoptimize");
            ?>
</a>
	<?php 
        }
        ?>

<form method="post" action="options.php">
<?php 
        settings_fields('autoptimize');
        ?>

<h3><?php 
        _e('HTML Options', 'autoptimize');
        ?>
</h3>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize HTML Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php 
        echo get_option('autoptimize_html') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr class="html_sub" valign="top">
<th scope="row"><?php 
        _e('Keep HTML comments?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_html_keepcomments"><input type="checkbox" name="autoptimize_html_keepcomments" <?php 
        echo get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Enable this if you want HTML comments to remain in the page, needed for e.g. AdSense to function properly.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h3><?php 
        _e('JavaScript Options', 'autoptimize');
        ?>
</h3>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize JavaScript Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php 
        echo get_option('autoptimize_js') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr valign="top" class="hidden js_sub ao_adv">
<th scope="row"><?php 
        _e('Force JavaScript in &lt;head&gt;?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_forcehead"><input type="checkbox" name="autoptimize_js_forcehead" <?php 
        echo get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('For performance reasons it is better to include JavaScript at the bottom of HTML, but this sometimes breaks things. Especially useful for jQuery-based themes.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden js_sub ao_adv">
<th scope="row"><?php 
        _e('Look for scripts only in &lt;head&gt;?', 'autoptimize');
        _e(' <i>(deprecated)</i>', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_justhead"><input type="checkbox" name="autoptimize_js_justhead" <?php 
        echo get_option('autoptimize_js_justhead') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden js_sub ao_adv">
<th scope="row"><?php 
        _e('Exclude scripts from Autoptimize:', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_exclude"><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php 
        echo get_option('autoptimize_js_exclude', "s_sid,smowtion_size,sc_project,WAU_,wau_add,comment-form-quicktags,edToolbar,ch_client,seal.js");
        ?>
"/><br />
<?php 
        _e('A comma-seperated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated and minimized by Autoptimize.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden js_sub ao_adv">
<th scope="row"><?php 
        _e('Add try-catch wrapping?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_trycatch"><input type="checkbox" name="autoptimize_js_trycatch" <?php 
        echo get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('If your scripts break because of an script error, you might want to try this.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h3><?php 
        _e('CSS Options', 'autoptimize');
        ?>
</h3>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize CSS Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php 
        echo get_option('autoptimize_css') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr class="css_sub" valign="top">
<th scope="row"><?php 
        _e('Generate data: URIs for images?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_datauris"><input type="checkbox" name="autoptimize_css_datauris" <?php 
        echo get_option('autoptimize_css_datauris') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Enable this to include small background-images in the CSS itself instead of as seperate downloads.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden css_sub ao_adv">
<th scope="row"><?php 
        _e('Look for styles only in &lt;head&gt;?', 'autoptimize');
        _e(' <i>(deprecated)</i>', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_justhead"><input type="checkbox" name="autoptimize_css_justhead" <?php 
        echo get_option('autoptimize_css_justhead') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden css_sub ao_adv">
<th scope="row"><?php 
        _e('Inline and Defer CSS?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_defer"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php 
        echo get_option('autoptimize_css_defer') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="http://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> before activating this option!', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden css_sub ao_adv" id="autoptimize_css_defer_inline">
<th scope="row"></th>
<td><label for="autoptimize_css_defer_inline"><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php 
        _e('Paste the above the fold CSS here.', 'autoptimize');
        ?>
" name="autoptimize_css_defer_inline"><?php 
        echo get_option('autoptimize_css_defer_inline');
        ?>
</textarea></label></td>
</tr>
<tr valign="top" class="hidden ao_adv css_sub">
<th scope="row"><?php 
        _e('Inline all CSS?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_inline"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php 
        echo get_option('autoptimize_css_inline') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Inlining all CSS can improve performance for sites with a low pageviews/ visitor-rate, but may slow down performance otherwise.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden ao_adv css_sub">
<th scope="row"><?php 
        _e('Exclude CSS from Autoptimize:', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_exclude"><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php 
        echo get_option('autoptimize_css_exclude', 'admin-bar.min.css, dashicons.min.css');
        ?>
"/><br />
<?php 
        _e('A comma-seperated list of CSS you want to exclude from being optimized.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h3><?php 
        _e('CDN Options', 'autoptimize');
        ?>
</h3>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('CDN Base URL', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_url"><input id="cdn_url" type="url" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*\/?$" style="width:100%" value="<?php 
        $it = get_option('autoptimize_cdn_url', '');
        echo htmlentities($it);
        ?>
" /><br />
<?php 
        _e('Enter your CDN blog root directory URL if you want to enable CDN for images referenced in the CSS.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h3 class="hidden ao_adv"><?php 
        _e('Cache Info', 'autoptimize');
        ?>
</h3>
<table class="form-table" > 
<tr valign="top" class="hidden ao_adv">
<th scope="row"><?php 
        _e('Cache folder', 'autoptimize');
        ?>
</th>
<td><?php 
        echo htmlentities(AUTOPTIMIZE_CACHE_DIR);
        ?>
</td>
</tr>
<tr valign="top" class="hidden ao_adv">
<th scope="row"><?php 
        _e('Can we write?', 'autoptimize');
        ?>
</th>
<td><?php 
        echo autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize');
        ?>
</td>
</tr>
<tr valign="top" class="hidden ao_adv">
<th scope="row"><?php 
        _e('Cached styles and scripts', 'autoptimize');
        ?>
</th>
<td><?php 
        echo autoptimizeCache::stats();
        ?>
</td>
</tr>
<tr valign="top" class="hidden ao_adv">
<th scope="row"><?php 
        _e('Save aggregated script/css as static files?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_cache_nogzip"><input type="checkbox" name="autoptimize_cache_nogzip" <?php 
        echo get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>
<input type="hidden" id="autoptimize_show_adv" name="autoptimize_show_adv" value="<?php 
        echo get_option('autoptimize_show_adv', '0');
        ?>
">

<p class="submit">
<input type="submit" class="button-secondary" value="<?php 
        _e('Save Changes', 'autoptimize');
        ?>
" />
<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php 
        _e('Save Changes and Empty Cache', 'autoptimize');
        ?>
" />
</p>

</form>
</div>
<div style="float:right;width:30%" id="autoptimize_admin_feed">
	<div style="margin:0px 15px 15px 15px;font-size:larger;"><a href="<?php 
        echo network_admin_url();
        ?>
plugin-install.php?tab=search&type=author&s=futtta"><?php 
        _e("Happy with Autoptimize? Try my other plugins!");
        ?>
</a></div>
        <div style="margin-left:10px;margin-top:-5px;">
                <h3>
                        <?php 
        _e("futtta about", "autoptimize");
        ?>
                        <select id="feed_dropdown" >
                                <option value="1"><?php 
        _e("Autoptimize", "autoptimize");
        ?>
</option>
                                <option value="2"><?php 
        _e("WordPress", "autoptimize");
        ?>
</option>
                                <option value="3"><?php 
        _e("Web Technology", "autoptimize");
        ?>
</option>
                        </select>
                </h3>
                <div id="futtta_feed"></div>
        </div>
	<div style="float:right;margin:50px 15px;"><a href="http://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php 
        echo content_url();
        ?>
/plugins/autoptimize/classes/external/do_not_donate_smallest.png" title="<?php 
        _e("Do not donate for this plugin!");
        ?>
"></a></div>
</div>

<script type="text/javascript">
	var feed = new Array;
	feed[1]="http://feeds.feedburner.com/futtta_autoptimize";
	feed[2]="http://feeds.feedburner.com/futtta_wordpress";
	feed[3]="http://feeds.feedburner.com/futtta_webtech";
	cookiename="autoptimize_feed";

	jQuery(document).ready(function() {
		check_ini_state();
		jQuery( "#ao_show_adv" ).click(function() {
			jQuery( "#ao_show_adv" ).hide();
			jQuery( "#ao_hide_adv" ).show();
			jQuery( ".ao_adv" ).show("slow");
			if (jQuery("#autoptimize_css").attr('checked')) {
				jQuery(".css_sub:visible").fadeTo("fast",1);
				if (!jQuery("#autoptimize_css_defer").attr('checked')) {
					jQuery("#autoptimize_css_defer_inline").hide();
				}
			}
			if (jQuery("#autoptimize_js").attr('checked')) {
				jQuery(".js_sub:visible").fadeTo("fast",1);
			}
			check_ini_state()
			jQuery( "input#autoptimize_show_adv" ).val("1");
		});

		jQuery( "#ao_hide_adv" ).click(function() {
			jQuery( "#ao_hide_adv" ).hide();
			jQuery( "#ao_show_adv" ).show();
			jQuery( ".ao_adv" ).hide("slow");
                        if (!jQuery("#autoptimize_css").attr('checked')) {
                                jQuery(".css_sub:visible").fadeTo("fast",.33);
                        }
                        if (!jQuery("#autoptimize_js").attr('checked')) {
                                jQuery(".js_sub:visible").fadeTo("fast",.33);
                        }
                        check_ini_state()
			jQuery( "input#autoptimize_show_adv" ).val("0");
		});

		jQuery( "#autoptimize_html" ).change(function() {
			if (this.checked) {
				jQuery(".html_sub:visible").fadeTo("fast",1);
			} else {
				jQuery(".html_sub:visible").fadeTo("fast",.33);
			}
		});

                jQuery( "#autoptimize_js" ).change(function() {
                        if (this.checked) {
                                jQuery(".js_sub:visible").fadeTo("fast",1);
                        } else {
                                jQuery(".js_sub:visible").fadeTo("fast",.33);
                        }
                });

                jQuery( "#autoptimize_css" ).change(function() {
                        if (this.checked) {
                                jQuery(".css_sub:visible").fadeTo("fast",1);
                        } else {
                                jQuery(".css_sub:visible").fadeTo("fast",.33);
                        }
                });
		
		jQuery( "#autoptimize_css_inline" ).change(function() {
			if (this.checked) {
				jQuery("#autoptimize_css_defer").prop("checked",false);
				jQuery("#autoptimize_css_defer_inline").hide("slow");
			}
		});
		
		jQuery( "#autoptimize_css_defer" ).change(function() {
			if (this.checked) {
				jQuery("#autoptimize_css_inline").prop("checked",false);
				jQuery("#autoptimize_css_defer_inline").show("slow");
			} else {
				jQuery("#autoptimize_css_defer_inline").hide("slow");
			}
		});
		
		jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) });
		feedid=jQuery.cookie(cookiename);
		if(typeof(feedid) !== "string") feedid=1;
		show_feed(feedid);
	})

	function check_ini_state() {
		if (!jQuery("#autoptimize_css_defer").attr('checked')) {
			jQuery("#autoptimize_css_defer_inline").hide();
		}
		if (!jQuery("#autoptimize_html").attr('checked')) {
			jQuery(".html_sub:visible").fadeTo('fast',.33);
		}
                if (!jQuery("#autoptimize_css").attr('checked')) {
                        jQuery(".css_sub:visible").fadeTo('fast',.33);
                }
                if (!jQuery("#autoptimize_js").attr('checked')) {
                        jQuery(".js_sub:visible").fadeTo('fast',.33);
                }
	}

	function show_feed(id) {
  		jQuery('#futtta_feed').rssfeed(feed[id], {
			<?php 
        if (is_ssl()) {
            echo "ssl: true,";
        }
        ?>
    			limit: 4,
			date: true,
			header: false
  		});
		jQuery("#feed_dropdown").val(id);
		jQuery.cookie(cookiename,id,{ expires: 365 });
	}
</script>
</div>

<?php 
    }
    public function show()
    {
        ?>
<div class="wrap">
<h2><?php 
        _e('Autoptimize Settings', 'autoptimize');
        ?>
</h2>

<div style="float:left;width:70%;">
<form method="post" action="options.php">
<?php 
        settings_fields('autoptimize');
        ?>

<h3><?php 
        _e('HTML Options', 'autoptimize');
        ?>
</h3>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize HTML Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" name="autoptimize_html" <?php 
        echo get_option('autoptimize_html') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Keep HTML comments?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_html_keepcomments"><input type="checkbox" name="autoptimize_html_keepcomments" <?php 
        echo get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Disabled by default. Enable this if you want HTML comments to remain in the page.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h3><?php 
        _e('JavaScript Options', 'autoptimize');
        ?>
</h3>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize JavaScript Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" name="autoptimize_js" <?php 
        echo get_option('autoptimize_js') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Exclude scripts from autoptimize:', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_exclude"><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php 
        echo get_option('autoptimize_js_exclude', "s_sid,smowtion_size,sc_project,WAU_,wau_add,comment-form-quicktags,edToolbar,ch_client");
        ?>
"/><br />
<?php 
        _e('A comma-seperated list of scripts you want to exclude from being Autoptimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated and minimized by Autoptimize.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Look for scripts only in &lt;head&gt;?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_justhead"><input type="checkbox" name="autoptimize_js_justhead" <?php 
        echo get_option('autoptimize_js_justhead') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Disabled by default. If the cache gets big, you might want to enable this.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Force JavaScript in &lt;head&gt;?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_forcehead"><input type="checkbox" name="autoptimize_js_forcehead" <?php 
        echo get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Disabled by default. For performance reasons JavaScript is best put at the end of the HTML, but in some circumstances this breaks things. You can in that case check this option to add JavaScript to the &lt;head&gt; section.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Add try-catch wrapping?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_trycatch"><input type="checkbox" name="autoptimize_js_trycatch" <?php 
        echo get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Disabled by default. If your scripts break because of an script error, you might want to try this.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Use YUI compression?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_yui"><input type="checkbox" name="autoptimize_js_yui" <?php 
        echo get_option('autoptimize_js_yui') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('<b>Deprecated!</b> Disabled by default. Read [autoptimize]/yui/README.txt for more information.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h3><?php 
        _e('CSS Options', 'autoptimize');
        ?>
</h3>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize CSS Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" name="autoptimize_css" <?php 
        echo get_option('autoptimize_css') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Look for styles on just &lt;head&gt;?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_justhead"><input type="checkbox" name="autoptimize_css_justhead" <?php 
        echo get_option('autoptimize_css_justhead') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Disabled by default. If the cache gets big, you might want to enable this.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Generate data: URIs for images?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_datauris"><input type="checkbox" name="autoptimize_css_datauris" <?php 
        echo get_option('autoptimize_css_datauris') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Disabled by default. Enable this to include images on the CSS itself.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Use YUI compression?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_yui"><input type="checkbox" name="autoptimize_css_yui" <?php 
        echo get_option('autoptimize_css_yui') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('<b>Deprecated!</b> Disabled by default. Read [autoptimize]/yui/README.txt for more information.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h3><?php 
        _e('CDN Options', 'autoptimize');
        ?>
 (Deprecated!)</h3>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('Rewrite JavaScript URLs?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_cdn_js"><input type="checkbox" name="autoptimize_cdn_js" <?php 
        echo get_option('autoptimize_cdn_js') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Disabled by default. Do not enable this unless you know what you are doing.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('JavaScript Base URL', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_cdn_js_url"><input type="text" name="autoptimize_cdn_js_url" value="<?php 
        $it = get_option('autoptimize_cdn_js_url');
        echo htmlentities($it ? $it : site_url());
        ?>
" />
<?php 
        _e('This is the new base URL that will be used when rewriting. It should point to the blog root directory.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Rewrite CSS URLs?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_cdn_css"><input type="checkbox" name="autoptimize_cdn_css" <?php 
        echo get_option('autoptimize_cdn_css') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Disabled by default. Do not enable this unless you know what you are doing.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('CSS Base URL', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_cdn_css_url"><input type="text" name="autoptimize_cdn_css_url" value="<?php 
        $it = get_option('autoptimize_cdn_css_url');
        echo htmlentities($it ? $it : site_url());
        ?>
" />
<?php 
        _e('This is the new base URL that will be used when rewriting. It should point to the blog root directory.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Rewrite Image URLs?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_cdn_img"><input type="checkbox" name="autoptimize_cdn_img" <?php 
        echo get_option('autoptimize_cdn_img') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Disabled by default. Do not enable this unless you know what you are doing.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Image Base URL', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_cdn_img_url"><input type="text" name="autoptimize_cdn_img_url" value="<?php 
        $it = get_option('autoptimize_cdn_img_url');
        echo htmlentities($it ? $it : site_url());
        ?>
" />
<?php 
        _e('This is the new base URL that will be used when rewriting. It should point to the blog root directory.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h3><?php 
        _e('Cache Info', 'autoptimize');
        ?>
</h3>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('Cache folder', 'autoptimize');
        ?>
</th>
<td><?php 
        echo htmlentities(AUTOPTIMIZE_CACHE_DIR);
        ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Can we write?', 'autoptimize');
        ?>
</th>
<td><?php 
        echo autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize');
        ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Cached styles and scripts', 'autoptimize');
        ?>
</th>
<td><?php 
        echo autoptimizeCache::stats();
        ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        _e('Do not compress cache files', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_cache_nogzip"><input type="checkbox" name="autoptimize_cache_nogzip" <?php 
        echo get_option('autoptimize_cache_nogzip') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Disabled by default. Enable this if you want to compress the served files using your webserver.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

</table>

<p class="submit">
<input type="submit" class="button-primary" value="<?php 
        _e('Save Changes');
        ?>
" />
<input type="submit" name="autoptimize_cache_clean" value="<?php 
        _e('Save Changes and Empty Cache');
        ?>
" />
</p>

</form>
</div>
<div style="float:right;width:30%" id="autoptimize_admin_feed">
        <div style="margin-left:10px;margin-top:-5px;">
                <h3>
                        <?php 
        _e("futtta about", "autoptimize");
        ?>
                        <select id="feed_dropdown" >
                                <option value="1"><?php 
        _e("Autoptimize", "autoptimize");
        ?>
</option>
                                <option value="2"><?php 
        _e("WordPress", "autoptimize");
        ?>
</option>
                                <option value="3"><?php 
        _e("Web Technology", "autoptimize");
        ?>
</option>
                        </select>
                </h3>
                <div id="futtta_feed"></div>
        </div>
</div>

<script type="text/javascript">
	var feed = new Array;
	feed[1]="http://feeds.feedburner.com/futtta_autoptimize";
	feed[2]="http://feeds.feedburner.com/futtta_wordpress";
	feed[3]="http://feeds.feedburner.com/futtta_webtech";
	cookiename="autoptimize_feed";

        jQuery(document).ready(function() {
		jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) });

		feedid=jQuery.cookie(cookiename);
		if(typeof(feedid) !== "string") feedid=1;

		show_feed(feedid);
		})

	function show_feed(id) {
  		jQuery('#futtta_feed').rssfeed(feed[id], {
			<?php 
        if (is_ssl()) {
            echo "ssl: true,";
        }
        ?>
    			limit: 4,
			date: true,
			header: false
  		});
		jQuery("#feed_dropdown").val(id);
		jQuery.cookie(cookiename,id,{ expires: 365 });
	}
</script>

</div>
<?php 
    }
Example #12
0
    static function cacheavail()
    {
        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
            // We didn't set a cache
            return false;
        }
        foreach (array("", "js", "css") as $checkDir) {
            if (!autoptimizeCache::checkCacheDir(AUTOPTIMIZE_CACHE_DIR . $checkDir)) {
                return false;
            }
        }
        /** write index.html here to avoid prying eyes */
        $indexFile = AUTOPTIMIZE_CACHE_DIR . '/index.html';
        if (!is_file($indexFile)) {
            @file_put_contents($indexFile, '<html><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/">Autoptimize</a></body></html>');
        }
        /** write .htaccess here to overrule wp_super_cache */
        $htAccess = AUTOPTIMIZE_CACHE_DIR . '/.htaccess';
        if (!is_file($htAccess)) {
            if (is_multisite() || AUTOPTIMIZE_CACHE_NOGZIP == false) {
                @file_put_contents($htAccess, '<IfModule mod_headers.c>
        Header set Vary "Accept-Encoding"
        Header set Cache-Control "max-age=10672000, must-revalidate"
</IfModule>
<IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType text/css A30672000
        ExpiresByType text/javascript A30672000
        ExpiresByType application/javascript A30672000
</IfModule>
<IfModule mod_deflate.c>
        <FilesMatch "\\.(js|css)$">
        SetOutputFilter DEFLATE
    </FilesMatch>
</IfModule>
<IfModule mod_authz_core.c>
    <Files *.php>
        Require all granted
    </Files>
</IfModule>
<IfModule !mod_authz_core.c>
    <Files *.php>
        Order allow,deny
        Allow from all
    </Files>
</IfModule>');
            } else {
                @file_put_contents($htAccess, '<IfModule mod_headers.c>
        Header set Vary "Accept-Encoding"
        Header set Cache-Control "max-age=10672000, must-revalidate"
</IfModule>
<IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType text/css A30672000
        ExpiresByType text/javascript A30672000
        ExpiresByType application/javascript A30672000
</IfModule>
<IfModule mod_deflate.c>
        <FilesMatch "\\.(js|css)$">
        SetOutputFilter DEFLATE
    </FilesMatch>
</IfModule>
<IfModule mod_authz_core.c>
    <Files *.php>
        Require all denied
    </Files>
</IfModule>
<IfModule !mod_authz_core.c>
    <Files *.php>
        Order deny,allow
        Deny from all
    </Files>
</IfModule>');
            }
        }
        // All OK
        return true;
    }
Example #13
0
    public function show()
    {
        ?>
<style>
/* title and button */
#ao_title_and_button:after {content:''; display:block; clear:both;}
#ao_adv_button{float:right;}
#ao_hide_adv:before, #ao_show_adv:before {
    display: inline-block;
    float: left;
    height: 20px;
    width: 35px;
    background: none;
    color: #b4b9be;
    font: normal 20px/26px dashicons;
    letter-spacing: -4px;
    text-align: left;
    speak: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
#ao_hide_adv:before {
    content: "\f108 \f142";
}
#ao_show_adv:before {
    content: "\f108 \f140";
}

/* form */
.itemDetail {
    background: #fff;
    border: 1px solid #ccc;
    padding: 15px;
    margin: 15px 10px 10px 0;
}
.itemTitle {
    margin-top: 0;
}
input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:100;}
#autoptimize_main .cb_label {display: block; padding-left: 25px; text-indent: -25px;}

/* rss block */
#futtta_feed ul{list-style:outside;}
#futtta_feed {font-size:medium; margin:0px 20px;} 

/* banner + unslider */
.autoptimize_banner {
    margin: 0 38px;
    padding-bottom: 5px;
}
.autoptimize_banner ul li {
    font-size:medium;
    text-align:center;
}
.unslider {
    position:relative;
}
.unslider-arrow {
    display: block;
    left: unset;
    margin-top: -35px;
    margin-left: 7px;
    margin-right: 7px;
    border-radius: 32px;
    background: rgba(0, 0, 0, 0.10) no-repeat 50% 50%;
    color: rgba(255, 255, 255, 0.8);
    font: normal 20px/1 dashicons;
    speak: none;
    padding: 3px 2px 3px 4px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
.unslider-arrow:hover {
    background-color: rgba(0, 0, 0, 0.20);
    color: #FFF;
}
.unslider-arrow.prev {
    padding: 3px 4px 3px 2px;
}
.unslider-arrow.next {
    right: 0px;
}
.unslider-arrow.prev::before {
    content: "\f341";
}
.unslider-arrow.next::before {
    content: "\f345";
}
/* responsive stuff: hide admin-feed on smaller screens */
@media (min-width: 961px) {
    #autoptimize_main {float:left;width:69%;}
    #autoptimize_admin_feed{float:right;width:30%;display:block !important;}
    }
@media (max-width: 960px) {
    #autoptimize_main {width:100%;}
    #autoptimize_admin_feed {width:0%;display:none !important;}
}
@media (max-width: 782px) {
    #ao_hide_adv span, #ao_show_adv span {display: none;}
    #ao_hide_adv,#ao_show_adv {height: 34px;padding: 4px 12px 8px 8px;}
    #ao_hide_adv:before,#ao_show_adv:before {font-size: 25px;}
    #autoptimize_main input[type="checkbox"] {margin-left: 10px;}
    #autoptimize_main .cb_label {display: block; padding-left: 45px; text-indent: -45px;}
}
</style>

<div class="wrap">

<?php 
        if (version_compare(PHP_VERSION, '5.3.0') < 0) {
            ?>
<div class="notice-error notice"><?php 
            _e('<p><strong>You are using a very old version of PHP</strong> (5.2.x or older) which has <a href="http://blog.futtta.be/2016/03/15/why-would-you-still-be-on-php-5-2/" target="_blank">serious security and performance issues</a>. Please ask your hoster to provide you with an upgrade path to 5.6 or 7.0</p>', 'autoptimize');
            ?>
</div>
<?php 
        }
        ?>

<div id="autoptimize_main">
<div id="ao_title_and_button">
    <h1 id="ao_title"><?php 
        _e('Autoptimize Settings', 'autoptimize');
        ?>
    <span id="ao_adv_button">
    <?php 
        if (get_option('autoptimize_show_adv', '0') == '1') {
            ?>
        <a href="javascript:void(0);" id="ao_show_adv" class="button" style="display:none;"><span><?php 
            _e("Show advanced settings", "autoptimize");
            ?>
</span></a>
        <a href="javascript:void(0);" id="ao_hide_adv" class="button"><span><?php 
            _e("Hide advanced settings", "autoptimize");
            ?>
</span></a>
        <style>tr.ao_adv{display:table-row;} li.ao_adv{display:list-item;}</style>
        <?php 
            $hiddenClass = "";
        } else {
            ?>
        <a href="javascript:void(0);" id="ao_show_adv" class="button"><span><?php 
            _e("Show advanced settings", "autoptimize");
            ?>
</span></a>
        <a href="javascript:void(0);" id="ao_hide_adv" class="button" style="display:none;"><span><?php 
            _e("Hide advanced settings", "autoptimize");
            ?>
</span></a>
        <?php 
            $hiddenClass = "hidden ";
        }
        ?>
    </span>
    </h1>
</div>

<?php 
        echo $this->ao_admin_tabs();
        ?>

<form method="post" action="options.php">
<?php 
        settings_fields('autoptimize');
        ?>

<ul>

<li class="itemDetail">
<h2 class="itemTitle"><?php 
        _e('HTML Options', 'autoptimize');
        ?>
</h2>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize HTML Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php 
        echo get_option('autoptimize_html') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr class="<?php 
        echo $hiddenClass;
        ?>
html_sub ao_adv" valign="top">
<th scope="row"><?php 
        _e('Keep HTML comments?', 'autoptimize');
        ?>
</th>
<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php 
        echo get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Enable this if you want HTML comments to remain in the page.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>
</li>

<li class="itemDetail">
<h2 class="itemTitle"><?php 
        _e('JavaScript Options', 'autoptimize');
        ?>
</h2>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize JavaScript Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php 
        echo get_option('autoptimize_js') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr valign="top" class="<?php 
        echo $hiddenClass;
        ?>
js_sub ao_adv">
<th scope="row"><?php 
        _e('Force JavaScript in &lt;head&gt;?', 'autoptimize');
        ?>
</th>
<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php 
        echo get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Load JavaScript early, reducing the chance of JS-errors but making it render blocking. You can disable this if you\'re not aggregating inline JS and you want JS to be deferred.', 'autoptimize');
        ?>
</label></td>
</tr>
<?php 
        if (get_option('autoptimize_js_justhead')) {
            ?>
<tr valign="top" class="<?php 
            echo $hiddenClass;
            ?>
js_sub ao_adv">
<th scope="row"><?php 
            _e('Look for scripts only in &lt;head&gt;?', 'autoptimize');
            _e(' <i>(deprecated)</i>', 'autoptimize');
            ?>
</th>
<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php 
            echo get_option('autoptimize_js_justhead') ? 'checked="checked" ' : '';
            ?>
/>
<?php 
            _e('Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize');
            ?>
</label></td>
</tr>
<?php 
        }
        ?>
<tr valign="top" class="<?php 
        echo $hiddenClass;
        ?>
js_sub ao_adv">
<th scope="row"><?php 
        _e('Also aggregate inline JS?', 'autoptimize');
        ?>
</th>
<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php 
        echo get_option('autoptimize_js_include_inline') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Check this option for Autoptimize to also aggregate JS in the HTML. If this option is not enabled, you might have to "force JavaScript in head".', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="<?php 
        echo $hiddenClass;
        ?>
js_sub ao_adv">
<th scope="row"><?php 
        _e('Exclude scripts from Autoptimize:', 'autoptimize');
        ?>
</th>
<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php 
        echo get_option('autoptimize_js_exclude', "seal.js, js/jquery/jquery.js");
        ?>
"/><br />
<?php 
        _e('A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated and minimized by Autoptimize.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="<?php 
        echo $hiddenClass;
        ?>
js_sub ao_adv">
<th scope="row"><?php 
        _e('Add try-catch wrapping?', 'autoptimize');
        ?>
</th>
<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php 
        echo get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('If your scripts break because of a JS-error, you might want to try this.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>
</li>

<li class="itemDetail">
<h2 class="itemTitle"><?php 
        _e('CSS Options', 'autoptimize');
        ?>
</h2>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize CSS Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php 
        echo get_option('autoptimize_css') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr class="<?php 
        echo $hiddenClass;
        ?>
css_sub ao_adv" valign="top">
<th scope="row"><?php 
        _e('Generate data: URIs for images?', 'autoptimize');
        ?>
</th>
<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php 
        echo get_option('autoptimize_css_datauris') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr class="<?php 
        echo $hiddenClass;
        ?>
css_sub ao_adv" valign="top">
<th scope="row"><?php 
        _e('Remove Google Fonts?', 'autoptimize');
        ?>
</th>
<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_nogooglefont" <?php 
        echo get_option('autoptimize_css_nogooglefont') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Check this if you don\'t need or want Google Fonts being loaded.', 'autoptimize');
        ?>
</label></td>
</tr>
<?php 
        if (get_option('autoptimize_css_justhead')) {
            ?>
<tr valign="top" class="<?php 
            echo $hiddenClass;
            ?>
css_sub ao_adv">
<th scope="row"><?php 
            _e('Look for styles only in &lt;head&gt;?', 'autoptimize');
            _e(' <i>(deprecated)</i>', 'autoptimize');
            ?>
</th>
<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php 
            echo get_option('autoptimize_css_justhead') ? 'checked="checked" ' : '';
            ?>
/>
<?php 
            _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize');
            ?>
</label></td>
</tr>
<?php 
        }
        ?>
<tr valign="top" class="<?php 
        echo $hiddenClass;
        ?>
css_sub ao_adv">
<th scope="row"><?php 
        _e('Also aggregate inline CSS?', 'autoptimize');
        ?>
</th>
<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php 
        echo get_option('autoptimize_css_include_inline', '1') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="<?php 
        echo $hiddenClass;
        ?>
css_sub ao_adv">
<th scope="row"><?php 
        _e('Inline and Defer CSS?', 'autoptimize');
        ?>
</th>
<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php 
        echo get_option('autoptimize_css_defer') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="http://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> before activating this option!', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="<?php 
        echo $hiddenClass;
        ?>
css_sub ao_adv" id="autoptimize_css_defer_inline">
<th scope="row"></th>
<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php 
        _e('Paste the above the fold CSS here.', 'autoptimize');
        ?>
" name="autoptimize_css_defer_inline"><?php 
        echo get_option('autoptimize_css_defer_inline');
        ?>
</textarea></label></td>
</tr>
<tr valign="top" class="<?php 
        echo $hiddenClass;
        ?>
ao_adv css_sub">
<th scope="row"><?php 
        _e('Inline all CSS?', 'autoptimize');
        ?>
</th>
<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php 
        echo get_option('autoptimize_css_inline') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Inlining all CSS can improve performance for sites with a low pageviews/ visitor-rate, but may slow down performance otherwise.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="<?php 
        echo $hiddenClass;
        ?>
ao_adv css_sub">
<th scope="row"><?php 
        _e('Exclude CSS from Autoptimize:', 'autoptimize');
        ?>
</th>
<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php 
        echo get_option('autoptimize_css_exclude', 'admin-bar.min.css, dashicons.min.css');
        ?>
"/><br />
<?php 
        _e('A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>
</li>

<li class="itemDetail">
<h2 class="itemTitle"><?php 
        _e('CDN Options', 'autoptimize');
        ?>
</h2>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('CDN Base URL', 'autoptimize');
        ?>
</th>
<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php 
        echo esc_url(get_option('autoptimize_cdn_url', ''), array("http", "https"));
        ?>
" /><br />
<?php 
        _e('Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>).', 'autoptimize');
        ?>
</label></td>
</tr>
</table>
</li>

<li class="<?php 
        echo $hiddenClass;
        ?>
itemDetail ao_adv">
<h2 class="itemTitle"><?php 
        _e('Cache Info', 'autoptimize');
        ?>
</h2>
<table class="form-table" > 
<tr valign="top" class="<?php 
        echo $hiddenClass;
        ?>
ao_adv">
<th scope="row"><?php 
        _e('Cache folder', 'autoptimize');
        ?>
</th>
<td><?php 
        echo htmlentities(AUTOPTIMIZE_CACHE_DIR);
        ?>
</td>
</tr>
<tr valign="top" class="<?php 
        echo $hiddenClass;
        ?>
ao_adv">
<th scope="row"><?php 
        _e('Can we write?', 'autoptimize');
        ?>
</th>
<td><?php 
        echo autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize');
        ?>
</td>
</tr>
<tr valign="top" class="<?php 
        echo $hiddenClass;
        ?>
ao_adv">
<th scope="row"><?php 
        _e('Cached styles and scripts', 'autoptimize');
        ?>
</th>
<td><?php 
        $AOstatArr = autoptimizeCache::stats();
        $AOcacheSize = round($AOstatArr[1] / 1024);
        echo $AOstatArr[0] . __(' files, totalling ', 'autoptimize') . $AOcacheSize . __(' Kbytes (calculated at ', 'autoptimize') . date("H:i e", $AOstatArr[2]) . ')';
        ?>
</td>
</tr>
<tr valign="top" class="<?php 
        echo $hiddenClass;
        ?>
ao_adv">
<th scope="row"><?php 
        _e('Save aggregated script/css as static files?', 'autoptimize');
        ?>
</th>
<td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php 
        echo get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>
</li>

</ul>

<input type="hidden" id="autoptimize_show_adv" name="autoptimize_show_adv" value="<?php 
        echo get_option('autoptimize_show_adv', '0');
        ?>
">

<p class="submit">
<input type="submit" class="button-secondary" value="<?php 
        _e('Save Changes', 'autoptimize');
        ?>
" />
<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php 
        _e('Save Changes and Empty Cache', 'autoptimize');
        ?>
" />
</p>

</form>
</div>
<div id="autoptimize_admin_feed" class="hidden">
    <div class="autoptimize_banner hidden">
        <ul>
        <?php 
        if (apply_filters('autoptimize_settingsscreen_remotehttp', true)) {
            $AO_banner = get_transient("autoptimize_banner");
            if (empty($AO_banner)) {
                $banner_resp = wp_remote_get("http://misc.optimizingmatters.com/autoptimize_news.html");
                if (!is_wp_error($banner_resp)) {
                    if (wp_remote_retrieve_response_code($banner_resp) == "200") {
                        $AO_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp));
                        set_transient("autoptimize_banner", $AO_banner, DAY_IN_SECONDS);
                    }
                }
            }
            echo $AO_banner;
        }
        ?>
        <li><?php 
        _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ</a> or post your question on <a href='http://wordpress.org/support/plugin/autoptimize'>the support-forum</a>.", "autoptimize");
        ?>
</li>
        <li><?php 
        _e("Happy with Autoptimize?", "autoptimize");
        ?>
<br /><a href="<?php 
        echo network_admin_url();
        ?>
plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php 
        _e("Try my other plugins!", "autoptimize");
        ?>
</a></li>
        </ul>
    </div>
    <div style="margin-left:10px;margin-top:-5px;">
        <h2>
            <?php 
        _e("futtta about", "autoptimize");
        ?>
            <select id="feed_dropdown" >
                <option value="1"><?php 
        _e("Autoptimize", "autoptimize");
        ?>
</option>
                <option value="2"><?php 
        _e("WordPress", "autoptimize");
        ?>
</option>
                <option value="3"><?php 
        _e("Web Technology", "autoptimize");
        ?>
</option>
            </select>
        </h2>
        <div id="futtta_feed">
            <div id="autoptimizefeed">
                <?php 
        $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_autoptimize");
        ?>
            </div>
            <div id="wordpressfeed">
                <?php 
        $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_wordpress");
        ?>
            </div>
            <div id="webtechfeed">
                <?php 
        $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_webtech");
        ?>
            </div>
        </div>
    </div>
    <div style="float:right;margin:50px 15px;"><a href="http://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php 
        echo plugins_url() . '/' . plugin_basename(dirname(__FILE__)) . '/external/do_not_donate_smallest.png';
        ?>
" title="<?php 
        _e("Do not donate for this plugin!");
        ?>
"></a></div>
</div>

<script type="text/javascript">
    var feed = new Array;
    feed[1]="autoptimizefeed";
    feed[2]="wordpressfeed";
    feed[3]="webtechfeed";
    cookiename="autoptimize_feed";

    jQuery(document).ready(function() {
        check_ini_state();
        jQuery('#autoptimize_admin_feed').fadeTo("slow",1).show();        
        jQuery('.autoptimize_banner').unslider({autoplay:true, delay:3500, infinite: false, arrows:{prev:'<a class="unslider-arrow prev"></a>', next:'<a class="unslider-arrow next"></a>'}}).fadeTo("slow",1).show();

        jQuery( "#feed_dropdown" ).change(function() {
            jQuery("#futtta_feed").fadeTo(0,0);
            jQuery("#futtta_feed").fadeTo("slow",1);
        });

        jQuery( "#ao_show_adv" ).click(function() {
            jQuery( "#ao_show_adv" ).hide();
            jQuery( "#ao_hide_adv" ).show();
            jQuery( ".ao_adv" ).removeClass("hidden");
            jQuery( ".ao_adv" ).show("slow");
            if (jQuery("#autoptimize_css").attr('checked')) {
                jQuery(".css_sub:visible").fadeTo("fast",1);
                if (!jQuery("#autoptimize_css_defer").attr('checked')) {
                    jQuery("#autoptimize_css_defer_inline").hide();
                }
            }
            if (jQuery("#autoptimize_js").attr('checked')) {
                jQuery(".js_sub:visible").fadeTo("fast",1);
            }
            check_ini_state()
            jQuery( "input#autoptimize_show_adv" ).val("1");
        });

        jQuery( "#ao_hide_adv" ).click(function() {
            jQuery( "#ao_hide_adv" ).hide();
            jQuery( "#ao_show_adv" ).show();
            jQuery( ".ao_adv" ).hide("slow");
            jQuery( ".ao_adv" ).addClass("hidden");
            if (!jQuery("#autoptimize_css").attr('checked')) {
                jQuery(".css_sub:visible").fadeTo("fast",.33);
            }
            if (!jQuery("#autoptimize_js").attr('checked')) {
                jQuery(".js_sub:visible").fadeTo("fast",.33);
            }
            check_ini_state()
            jQuery( "input#autoptimize_show_adv" ).val("0");
        });

        jQuery( "#autoptimize_html" ).change(function() {
            if (this.checked) {
                jQuery(".html_sub:visible").fadeTo("fast",1);
            } else {
                jQuery(".html_sub:visible").fadeTo("fast",.33);
            }
        });

        jQuery( "#autoptimize_js" ).change(function() {
            if (this.checked) {
                jQuery(".js_sub:visible").fadeTo("fast",1);
            } else {
                jQuery(".js_sub:visible").fadeTo("fast",.33);
            }
        });

        jQuery( "#autoptimize_css" ).change(function() {
            if (this.checked) {
                jQuery(".css_sub:visible").fadeTo("fast",1);
            } else {
                jQuery(".css_sub:visible").fadeTo("fast",.33);
            }
        });

        jQuery( "#autoptimize_css_inline" ).change(function() {
            if (this.checked) {
                jQuery("#autoptimize_css_defer").prop("checked",false);
                jQuery("#autoptimize_css_defer_inline").hide("slow");
            }
        });

        jQuery( "#autoptimize_css_defer" ).change(function() {
            if (this.checked) {
                jQuery("#autoptimize_css_inline").prop("checked",false);
                jQuery("#autoptimize_css_defer_inline").show("slow");
            } else {
                jQuery("#autoptimize_css_defer_inline").hide("slow");
            }
        });

        jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) });
        feedid=jQuery.cookie(cookiename);
        if(typeof(feedid) !== "string") feedid=1;
        show_feed(feedid);
    })

    // validate cdn_url
    var cdn_url=document.getElementById("cdn_url");
    cdn_url_baseCSS=cdn_url.style.cssText;
    if ("validity" in cdn_url) {
        jQuery("#cdn_url").focusout(function (event) {
        if (cdn_url.validity.valid) {
            cdn_url.style.cssText=cdn_url_baseCSS;
        } else {
            cdn_url.style.cssText=cdn_url_baseCSS+"border:1px solid #f00;color:#f00;box-shadow: 0 0 2px #f00;";
        }});
    }

    function check_ini_state() {
        if (!jQuery("#autoptimize_css_defer").attr('checked')) {
            jQuery("#autoptimize_css_defer_inline").hide();
        }
        if (!jQuery("#autoptimize_html").attr('checked')) {
            jQuery(".html_sub:visible").fadeTo('fast',.33);
        }
        if (!jQuery("#autoptimize_css").attr('checked')) {
            jQuery(".css_sub:visible").fadeTo('fast',.33);
        }
        if (!jQuery("#autoptimize_js").attr('checked')) {
            jQuery(".js_sub:visible").fadeTo('fast',.33);
        }
    }

    function show_feed(id) {
        jQuery('#futtta_feed').children().hide();
        jQuery('#'+feed[id]).show();
        jQuery("#feed_dropdown").val(id);
        jQuery.cookie(cookiename,id,{ expires: 365 });
    }
</script>
</div>

<?php 
    }
 public function cache()
 {
     if ($this->datauris) {
         //MHTML Preparation
         $this->mhtml = "/*\r\nContent-Type: multipart/related; boundary=\"_\"\r\n\r\n" . $this->mhtml . "*/\r\n";
         $md5 = md5($this->mhtml);
         $cache = new autoptimizeCache($md5, 'txt');
         if (!$cache->check()) {
             //Cache our images for IE
             $cache->cache($this->mhtml, 'text/plain');
         }
         $mhtml = AUTOPTIMIZE_CACHE_URL . $cache->getname();
     }
     //CSS cache
     foreach ($this->csscode as $media => $code) {
         // fgo, moved from below to prevent empty md5 resulting in filenames without hash autoptimize_.php
         $md5 = $this->hashmap[md5($code)];
         if ($this->datauris) {
             //Images for ie! Get the right url
             $code = str_replace('%%MHTML%%', $mhtml, $code);
         }
         // $md5 = $this->hashmap[md5($code)];
         $cache = new autoptimizeCache($md5, 'css');
         if (!$cache->check()) {
             //Cache our code
             $cache->cache($code, 'text/css');
         }
         $this->url[$media] = AUTOPTIMIZE_CACHE_URL . $cache->getname();
     }
 }
Example #15
0
        $classes[] = 'autoptimizeStyles';
    }
    if ($conf->get('autoptimize_cdn_js') || $conf->get('autoptimize_cdn_css')) {
        $classes[] = 'autoptimizeCDN';
    }
    if ($conf->get('autoptimize_html')) {
        $classes[] = 'autoptimizeHTML';
    }
    // Set some options
    $classoptions = array('autoptimizeScripts' => array('justhead' => $conf->get('autoptimize_js_justhead'), 'forcehead' => $conf->get('autoptimize_js_forcehead'), 'trycatch' => $conf->get('autoptimize_js_trycatch'), 'yui' => $conf->get('autoptimize_js_yui'), 'exclude' => $conf->get('autoptimize_js_exclude')), 'autoptimizeStyles' => array('justhead' => $conf->get('autoptimize_css_justhead'), 'datauris' => $conf->get('autoptimize_css_datauris'), 'yui' => $conf->get('autoptimize_css_yui')), 'autoptimizeCDN' => array('js' => $conf->get('autoptimize_cdn_js'), 'jsurl' => $conf->get('autoptimize_cdn_js_url'), 'css' => $conf->get('autoptimize_cdn_css'), 'cssurl' => $conf->get('autoptimize_cdn_css_url'), 'img' => $conf->get('autoptimize_cdn_img'), 'imgurl' => $conf->get('autoptimize_cdn_img_url')), 'autoptimizeHTML' => array('keepcomments' => $conf->get('autoptimize_html_keepcomments')));
    // Run the classes
    foreach ($classes as $name) {
        $instance = new $name($content);
        if ($instance->read($classoptions[$name])) {
            $instance->minify();
            $instance->cache();
            $content = $instance->getcontent();
        }
        unset($instance);
    }
    return $content;
}
if (autoptimizeCache::cacheavail()) {
    $conf = autoptimizeConfig::instance();
    if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') || $conf->get('autoptimize_cdn_js') || $conf->get('autoptimize_cdn_css')) {
        // Hook to wordpress
        add_action('template_redirect', 'autoptimize_start_buffering', 2);
    }
}
// Do not pollute other plugins
unset($conf);
Example #16
0
    public function show()
    {
        ?>
<style>input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:100;}</style>

<div class="wrap">      


<form method="post" action="options.php" data-frm="optimize">
<?php 
        settings_fields('autoptimize');
        ?>

<h3><?php 
        _e('HTML Options', 'autoptimize');
        ?>
</h3>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize HTML Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php 
        echo get_option('autoptimize_html') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr class="html_sub" valign="top">
<th scope="row"><?php 
        _e('Keep HTML comments?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_html_keepcomments"><input type="checkbox" name="autoptimize_html_keepcomments" <?php 
        echo get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Enable this if you want HTML comments to remain in the page, needed for e.g. AdSense to function properly.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h3><?php 
        _e('JavaScript Options', 'autoptimize');
        ?>
</h3>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize JavaScript Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php 
        echo get_option('autoptimize_js') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr valign="top" class="hidden js_sub ao_adv">
<th scope="row"><?php 
        _e('Force JavaScript in &lt;head&gt;?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_forcehead"><input type="checkbox" name="autoptimize_js_forcehead" <?php 
        echo get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('For performance reasons it is better to include JavaScript at the bottom of HTML, but this sometimes breaks things. Especially useful for jQuery-based themes.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden js_sub ao_adv">
<th scope="row"><?php 
        _e('Look for scripts only in &lt;head&gt;?', 'autoptimize');
        _e(' <i>(deprecated)</i>', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_justhead"><input type="checkbox" name="autoptimize_js_justhead" <?php 
        echo get_option('autoptimize_js_justhead') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden js_sub ao_adv">
<th scope="row"><?php 
        _e('Exclude scripts from Autoptimize:', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_exclude"><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php 
        echo get_option('autoptimize_js_exclude', "s_sid,smowtion_size,sc_project,WAU_,wau_add,comment-form-quicktags,edToolbar,ch_client,seal.js");
        ?>
"/><br />
<?php 
        _e('A comma-seperated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated and minimized by Autoptimize.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden js_sub ao_adv">
<th scope="row"><?php 
        _e('Add try-catch wrapping?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_js_trycatch"><input type="checkbox" name="autoptimize_js_trycatch" <?php 
        echo get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('If your scripts break because of an script error, you might want to try this.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h3><?php 
        _e('CSS Options', 'autoptimize');
        ?>
</h3>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('Optimize CSS Code?', 'autoptimize');
        ?>
</th>
<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php 
        echo get_option('autoptimize_css') ? 'checked="checked" ' : '';
        ?>
/></td>
</tr>
<tr class="css_sub" valign="top">
<th scope="row"><?php 
        _e('Generate data: URIs for images?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_datauris"><input type="checkbox" name="autoptimize_css_datauris" <?php 
        echo get_option('autoptimize_css_datauris') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Enable this to include small background-images in the CSS itself instead of as seperate downloads.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden css_sub ao_adv">
<th scope="row"><?php 
        _e('Look for styles only in &lt;head&gt;?', 'autoptimize');
        _e(' <i>(deprecated)</i>', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_justhead"><input type="checkbox" name="autoptimize_css_justhead" <?php 
        echo get_option('autoptimize_css_justhead') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden css_sub ao_adv">
<th scope="row"><?php 
        _e('Inline and Defer CSS?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_defer"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php 
        echo get_option('autoptimize_css_defer') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="http://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> before activating this option!', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden css_sub ao_adv" id="autoptimize_css_defer_inline">
<th scope="row"></th>
<td><label for="autoptimize_css_defer_inline"><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php 
        _e('Paste the above the fold CSS here.', 'autoptimize');
        ?>
" name="autoptimize_css_defer_inline"><?php 
        echo get_option('autoptimize_css_defer_inline');
        ?>
</textarea></label></td>
</tr>
<tr valign="top" class="hidden ao_adv css_sub">
<th scope="row"><?php 
        _e('Inline all CSS?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_inline"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php 
        echo get_option('autoptimize_css_inline') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('Inlining all CSS can improve performance for sites with a low pageviews/ visitor-rate, but may slow down performance otherwise.', 'autoptimize');
        ?>
</label></td>
</tr>
<tr valign="top" class="hidden ao_adv css_sub">
<th scope="row"><?php 
        _e('Exclude CSS from Autoptimize:', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_css_exclude"><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php 
        echo get_option('autoptimize_css_exclude', 'admin-bar.min.css, dashicons.min.css');
        ?>
"/><br />
<?php 
        _e('A comma-seperated list of CSS you want to exclude from being optimized.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h3><?php 
        _e('CDN Options', 'autoptimize');
        ?>
</h3>
<table class="form-table"> 
<tr valign="top">
<th scope="row"><?php 
        _e('CDN Base URL', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_url"><input id="cdn_url" type="url" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*\/?$" style="width:100%" value="<?php 
        $it = get_option('autoptimize_cdn_url', '');
        echo htmlentities($it);
        ?>
" /><br />
<?php 
        _e('Enter your CDN blog root directory URL if you want to enable CDN for images referenced in the CSS.', 'autoptimize');
        ?>
</label></td>
</tr>
</table>

<h3 class="hidden ao_adv"><?php 
        _e('Cache Info', 'autoptimize');
        ?>
</h3>
<table class="form-table last" > 
<tr valign="top" class="hidden ao_adv">
<th scope="row"><?php 
        _e('Cache folder', 'autoptimize');
        ?>
</th>
<td><?php 
        echo htmlentities(AUTOPTIMIZE_CACHE_DIR);
        ?>
</td>
</tr>
<tr valign="top" class="hidden ao_adv">
<th scope="row"><?php 
        _e('Can we write?', 'autoptimize');
        ?>
</th>
<td><?php 
        echo autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize');
        ?>
</td>
</tr>
<tr valign="top" class="hidden ao_adv">
<th scope="row"><?php 
        _e('Cached styles and scripts', 'autoptimize');
        ?>
</th>
<td><?php 
        echo autoptimizeCache::stats();
        ?>
</td>
</tr>
<tr valign="top" class="hidden ao_adv">
<th scope="row"><?php 
        _e('Save aggregated script/css as static files?', 'autoptimize');
        ?>
</th>
<td><label for="autoptimize_cache_nogzip"><input type="checkbox" name="autoptimize_cache_nogzip" <?php 
        echo get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : '';
        ?>
/>
<?php 
        _e('By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize');
        ?>
</label></td>
</tr> 
<tr class="last">
    <th></th>
    <td>  
        <p class="submit">
        <?php 
        if (get_option('autoptimize_show_adv', '0') == '1') {
            ?>
            <a href="javascript:void(0);" id="ao_show_adv" class="button button-hero" style="display:none;"><?php 
            _e("Show advanced settings", "autoptimize");
            ?>
</a>
            <a href="javascript:void(0);" id="ao_hide_adv" class="button button-hero"><?php 
            _e("Hide advanced settings", "autoptimize");
            ?>
</a>
            <style>.ao_adv {display:table-row};</style>
            <?php 
        } else {
            ?>
            <a href="javascript:void(0);" id="ao_show_adv" class="button button-hero"><?php 
            _e("Show advanced settings", "autoptimize");
            ?>
</a>
            <a href="javascript:void(0);" id="ao_hide_adv" class="button button-hero" style="display:none;"><?php 
            _e("Hide advanced settings", "autoptimize");
            ?>
</a>
            <?php 
        }
        ?>
        <input type="submit" data-action="optimize" class="button button-hero button-primary" value="<?php 
        _e('Save Optimize Changes', 'autoptimize');
        ?>
" />
        <input type="submit" data-action="optimize" class="button button-hero button-primary right" name="autoptimize_cache_clean" value="<?php 
        _e('Save Optimize Changes and Empty Cache', 'autoptimize');
        ?>
" />
        </p>     
    </td>
</tr>
</table>
<input type="hidden" id="autoptimize_show_adv" name="autoptimize_show_adv" value="<?php 
        echo get_option('autoptimize_show_adv', '0');
        ?>
">


</form> 

<script type="text/javascript">
	
	jQuery( function( $ ) {
		check_ini_state();
		jQuery( "#ao_show_adv" ).click(function() {
			jQuery( "#ao_show_adv" ).hide();
			jQuery( "#ao_hide_adv" ).show();
			jQuery( ".ao_adv" ).show("slow");
			if (jQuery("#autoptimize_css").attr('checked')) {
				jQuery(".css_sub:visible").fadeTo("fast",1);
				if (!jQuery("#autoptimize_css_defer").attr('checked')) {
					jQuery("#autoptimize_css_defer_inline").hide();
				}
			}
			if (jQuery("#autoptimize_js").attr('checked')) {
				jQuery(".js_sub:visible").fadeTo("fast",1);
			}
			check_ini_state()
			jQuery( "input#autoptimize_show_adv" ).val("1");
		});

		jQuery( "#ao_hide_adv" ).click(function() {
			jQuery( "#ao_hide_adv" ).hide();
			jQuery( "#ao_show_adv" ).show();
			jQuery( ".ao_adv" ).hide("slow");
            if (!jQuery("#autoptimize_css").attr('checked')) {
                    jQuery(".css_sub:visible").fadeTo("fast",.33);
            }
            if (!jQuery("#autoptimize_js").attr('checked')) {
                    jQuery(".js_sub:visible").fadeTo("fast",.33);
            }
            check_ini_state()
			jQuery( "input#autoptimize_show_adv" ).val("0");
		});

		jQuery( "#autoptimize_html" ).change(function() {
			if (this.checked) {
				jQuery(".html_sub:visible").fadeTo("fast",1);
			} else {
				jQuery(".html_sub:visible").fadeTo("fast",.33);
			}
		});

        jQuery( "#autoptimize_js" ).change(function() {
                if (this.checked) {
                        jQuery(".js_sub:visible").fadeTo("fast",1);
                } else {
                        jQuery(".js_sub:visible").fadeTo("fast",.33);
                }
        });

        jQuery( "#autoptimize_css" ).change(function() {
                if (this.checked) {
                        jQuery(".css_sub:visible").fadeTo("fast",1);
                } else {
                        jQuery(".css_sub:visible").fadeTo("fast",.33);
                }
        });
		
		jQuery( "#autoptimize_css_inline" ).change(function() {
			if (this.checked) {
				jQuery("#autoptimize_css_defer").prop("checked",false);
				jQuery("#autoptimize_css_defer_inline").hide("slow");
			}
		});
		
		jQuery( "#autoptimize_css_defer" ).change(function() {
			if (this.checked) {
				jQuery("#autoptimize_css_inline").prop("checked",false);
				jQuery("#autoptimize_css_defer_inline").show("slow");
			} else {
				jQuery("#autoptimize_css_defer_inline").hide("slow");
			}
		});
        
        $( document ).delegate( '[data-frm="optimize"]', 'submit.save-optimize', function() {
            
            var frm = $( this )
                ,buttons = frm.find( '[data-action="optimize"]' ).each( function() {
                
                    $( this ).attr( 'disabled', true );
                    
                } )
            ;
                
            $.post( frm.attr( 'action' ), frm.serialize(), function() {
                
                buttons.each( function() {
                
                    $( this ).attr( 'disabled', false );
                    
                } );
                
            } );
            
           return false;
                
        } );
	});

	function check_ini_state() {
		if (!jQuery("#autoptimize_css_defer").attr('checked')) {
			jQuery("#autoptimize_css_defer_inline").hide();
		}
		if (!jQuery("#autoptimize_html").attr('checked')) {
			jQuery(".html_sub:visible").fadeTo('fast',.33);
		}
        if (!jQuery("#autoptimize_css").attr('checked')) {
                jQuery(".css_sub:visible").fadeTo('fast',.33);
        }
        if (!jQuery("#autoptimize_js").attr('checked')) {
                jQuery(".js_sub:visible").fadeTo('fast',.33);
        }
	}
</script>
</div>

<?php 
    }
                update_option('autoptimize_css_exclude', $css_exclude);
            }
            switch_to_blog($original_blog_id);
        }
        $majorUp = true;
    case "1.9":
        /* 
         * 2.0 will not aggregate inline CSS/JS by default, but we want users
         * upgrading from 1.9 to keep their inline code aggregated by default. 
         */
        if (!is_multisite()) {
            update_option('autoptimize_css_include_inline', 'on');
            update_option('autoptimize_js_include_inline', 'on');
        } else {
            global $wpdb;
            $blog_ids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}");
            $original_blog_id = get_current_blog_id();
            foreach ($blog_ids as $blog_id) {
                switch_to_blog($blog_id);
                update_option('autoptimize_css_include_inline', 'on');
                update_option('autoptimize_js_include_inline', 'on');
            }
            switch_to_blog($original_blog_id);
        }
        $majorUp = true;
}
if ($majorUp === true) {
    // clear cache and notify user to check result if major upgrade
    autoptimizeCache::clearall();
    add_action('admin_notices', 'autoptimize_update_config_notice');
}