Completed
Pull Request — master (#254)
by
unknown
01:50
created

autoptimizeConfig::get_ao_imgopt_default_options()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
3
4
class autoptimizeConfig
5
{
6
    private $config          = null;
7
    static private $instance = null;
8
9
    private $settings_screen_do_remote_http = true;
10
11
    /**
12
     * Singleton.
13
     */
14
    private function __construct()
15
    {
16
        if ( is_admin() ) {
17
            // Add the admin page and settings.
18
			if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) {
19
				add_action( 'network_admin_menu', array( $this, 'addmenu' ) );
20
			}
21
22
			add_action( 'admin_menu', array( $this, 'addmenu' ) );
23
            add_action( 'admin_init', array( $this, 'registersettings' ) );
24
25
            // Set meta info.
26
            if ( function_exists( 'plugin_row_meta' ) ) {
27
                // 2.8 and higher.
28
                add_filter( 'plugin_row_meta', array( $this, 'setmeta' ), 10, 2 );
29
            } elseif ( function_exists( 'post_class' ) ) {
30
                // 2.7 and lower.
31
                $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
32
                add_filter( 'plugin_action_links_' . $plugin, array( $this, 'setmeta' ) );
33
            }
34
35
            // Clean cache?
36
            if ( autoptimizeOption::get_option( 'autoptimize_cache_clean' ) ) {
37
                autoptimizeCache::clearall();
38
                autoptimizeOption::update_option( 'autoptimize_cache_clean', 0 );
39
            }
40
41
            $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
42
        }
43
44
        // Adds the Autoptimize Toolbar to the Admin bar.
45
        // (we load outside the is_admin check so it's also displayed on the frontend toolbar).
46
        $toolbar = new autoptimizeToolbar();
0 ignored issues
show
Unused Code introduced by
$toolbar is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
    }
48
49
    /**
50
     * @return autoptimizeConfig
51
     */
52
    static public function instance()
53
    {
54
        // Only one instance.
55
        if ( null === self::$instance ) {
56
            self::$instance = new autoptimizeConfig();
57
        }
58
59
        return self::$instance;
60
    }
61
62
	public function show_message() {
63
		?>
64
			<h1>Autoptimize enabled in network</h1>
65
			<p>If you want to enable per site configutation for Autoptimize, please contact your network administrator.</p>
66
		<?php
67
	}
68
69
    public function show()
70
    {
71
        $conf = self::instance();
72
?>
73
<style>
74
/* title and button */
75
#ao_title_and_button:after {content:''; display:block; clear:both;}
76
#ao_adv_button{float:right;}
77
#ao_hide_adv:before, #ao_show_adv:before {
78
    display: inline-block;
79
    float: left;
80
    height: 20px;
81
    width: 35px;
82
    background: none;
83
    color: #b4b9be;
84
    font: normal 20px/26px dashicons;
85
    letter-spacing: -4px;
86
    text-align: left;
87
    speak: none;
88
    -webkit-font-smoothing: antialiased;
89
    -moz-osx-font-smoothing: grayscale;
90
}
91
#ao_hide_adv:before {
92
    content: "\f108 \f142";
93
}
94
#ao_show_adv:before {
95
    content: "\f108 \f140";
96
}
97
98
/* animate "show adv" button */
99
#ao_show_adv { animation: watchmenow 3s linear 5s 10; }
100
#ao_show_adv:hover { animation: none; }
101
@keyframes watchmenow {
102
  0% { box-shadow: unset; }
103
  100% { box-shadow: 0px 0px 20px yellow; }
104
}
105
106
/* form */
107
.itemDetail {
108
    background: #fff;
109
    border: 1px solid #ccc;
110
    padding: 15px;
111
    margin: 15px 10px 10px 0;
112
}
113
.itemTitle {
114
    margin-top: 0;
115
}
116
117
input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:normal;}
118
#autoptimize_main .cb_label {display: block; padding-left: 25px; text-indent: -25px;}
119
120
/* rss block */
121
#futtta_feed ul{list-style:outside;}
122
#futtta_feed {font-size:medium; margin:0px 20px;}
123
124
/* banner + unslider */
125
.autoptimize_banner {
126
    margin: 0 38px;
127
    padding-bottom: 5px;
128
}
129
.autoptimize_banner ul li {
130
    font-size:medium;
131
    text-align:center;
132
}
133
.unslider {
134
    position:relative;
135
}
136
.unslider-arrow {
137
    display: block;
138
    left: unset;
139
    margin-top: -35px;
140
    margin-left: 7px;
141
    margin-right: 7px;
142
    border-radius: 32px;
143
    background: rgba(0, 0, 0, 0.10) no-repeat 50% 50%;
144
    color: rgba(255, 255, 255, 0.8);
145
    font: normal 20px/1 dashicons;
146
    speak: none;
147
    padding: 3px 2px 3px 4px;
148
    -webkit-font-smoothing: antialiased;
149
    -moz-osx-font-smoothing: grayscale;
150
}
151
.unslider-arrow:hover {
152
    background-color: rgba(0, 0, 0, 0.20);
153
    color: #FFF;
154
}
155
.unslider-arrow.prev {
156
    padding: 3px 4px 3px 2px;
157
}
158
.unslider-arrow.next {
159
    right: 0px;
160
}
161
.unslider-arrow.prev::before {
162
    content: "\f341";
163
}
164
.unslider-arrow.next::before {
165
    content: "\f345";
166
}
167
168
/* responsive stuff: hide admin-feed on smaller screens */
169
@media (min-width: 961px) {
170
    #autoptimize_main {float:left;width:69%;}
171
    #autoptimize_admin_feed{float:right;width:30%;display:block !important;}
172
    }
173
@media (max-width: 960px) {
174
    #autoptimize_main {width:100%;}
175
    #autoptimize_admin_feed {width:0%;display:none !important;}
176
}
177
@media (max-width: 782px) {
178
    #ao_hide_adv span, #ao_show_adv span {display: none;}
179
    #ao_hide_adv,#ao_show_adv {height: 34px;padding: 4px 12px 8px 8px;}
180
    #ao_hide_adv:before,#ao_show_adv:before {font-size: 25px;}
181
    #autoptimize_main input[type="checkbox"] {margin-left: 10px;}
182
    #autoptimize_main .cb_label {display: block; padding-left: 45px; text-indent: -45px;}
183
}
184
</style>
185
186
<div class="wrap">
187
188
<?php if ( version_compare( PHP_VERSION, '5.3.0' ) < 0 ) { ?>
189
<div class="notice-error notice"><?php echo '<p>' . sprintf( __( '<strong>You are using a very old version of PHP</strong> (5.2.x or older) which has <a href=%s>serious security and performance issues</a>. Support for PHP 5.5 and below will be removed in one of the next AO released, please ask your hoster to provide you with an upgrade path to 7.x.', 'autoptimize' ), '"http://blog.futtta.be/2016/03/15/why-would-you-still-be-on-php-5-2/" target="_blank"' ) . '</p>'; ?></div>
190
<?php } ?>
191
192
<?php if ( defined( 'AUTOPTIMIZE_LEGACY_MINIFIERS' ) ) { ?>
193
    <div class="notice-error notice"><p>
194
        <?php _e( "You are using the (no longer supported) AUTOPTIMIZE_LEGACY_MINIFIERS constant. Ensure your site is working properly and remove the constant, it doesn't do anything any more.", 'autoptimize' ); ?>
195
    </p></div>
196
<?php } ?>
197
198
<div id="autoptimize_main">
199
    <div id="ao_title_and_button">
200
        <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?>
201
        <span id="ao_adv_button">
202
        <?php if ( autoptimizeOption::get_option( 'autoptimize_show_adv', '1' ) == '1' ) { ?>
203
            <a href="javascript:void(0);" id="ao_show_adv" class="button" style="display:none;"><span><?php _e("Show advanced settings","autoptimize") ?></span></a>
204
            <a href="javascript:void(0);" id="ao_hide_adv" class="button"><span><?php _e("Hide advanced settings","autoptimize") ?></span></a>
205
            <style>tr.ao_adv{display:table-row;} li.ao_adv{display:list-item;}</style>
206
            <?php $hiddenClass = ''; ?>
207
        <?php } else { ?>
208
            <a href="javascript:void(0);" id="ao_show_adv" class="button"><span><?php _e("Show advanced settings","autoptimize") ?></span></a>
209
            <a href="javascript:void(0);" id="ao_hide_adv" class="button" style="display:none;"><span><?php _e("Hide advanced settings","autoptimize") ?></span></a>
210
            <?php $hiddenClass = 'hidden '; ?>
211
        <?php } ?>
212
        </span>
213
        </h1>
214
    </div>
215
216
    <?php echo $this->ao_admin_tabs(); ?>
217
218
<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
219
<?php settings_fields( 'autoptimize' ); ?>
220
221
<ul>
222
223
<?php
224
// Only show enable site configuration in network site option.
225
$blog_id = get_current_blog_id();
226
if( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) && 1 === $blog_id ) { 
227
?>
228
	<li class="itemDetail">
229
	<h2 class="itemTitle"><?php _e('Multisite Options','autoptimize'); ?></h2>
230
	<table class="form-table">
231
	<tr valign="top">
232
	<th scope="row"><?php _e('Enable site configuration?','autoptimize'); ?></th>
233
	<td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOption::get_option('autoptimize_enable_site_config')?'checked="checked" ':''; ?>/>
234
	<?php _e('Enable Autoptimize configuration per site.','autoptimize'); ?></label></td>
235
	</tr>
236
	</table>
237
	</li>
238
<?php } ?>
239
240
<li class="itemDetail">
241
<h2 class="itemTitle"><?php _e('JavaScript Options','autoptimize'); ?></h2>
242
<table class="form-table">
243
<tr valign="top">
244
<th scope="row"><?php _e('Optimize JavaScript Code?','autoptimize'); ?></th>
245
<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOption::get_option('autoptimize_js')?'checked="checked" ':''; ?>/></td>
246
</tr>
247
<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv">
248
<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
249
<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get( 'autoptimize_js_aggregate' ) ? 'checked="checked" ':''; ?>/>
250
<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
251
</tr>
252
<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv js_aggregate">
253
<th scope="row"><?php _e('Also aggregate inline JS?','autoptimize'); ?></th>
254
<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOption::get_option('autoptimize_js_include_inline')?'checked="checked" ':''; ?>/>
255
<?php _e('Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.','autoptimize'); ?></label></td>
256
</tr>
257
<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv js_aggregate">
258
<th scope="row"><?php _e('Force JavaScript in &lt;head&gt;?','autoptimize'); ?></th>
259
<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOption::get_option('autoptimize_js_forcehead')?'checked="checked" ':''; ?>/>
260
<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.','autoptimize'); ?></label></td>
261
</tr>
262 View Code Duplication
<?php if (autoptimizeOption::get_option('autoptimize_js_justhead')) { ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
263
<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv js_aggregate">
264
<th scope="row"><?php _e('Look for scripts only in &lt;head&gt;?','autoptimize'); echo ' <i>'. __('(deprecated)','autoptimize') . '</i>'; ?></th>
265
<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOption::get_option('autoptimize_js_justhead')?'checked="checked" ':''; ?>/>
266
<?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>
267
</tr>
268
<?php } ?>
269
<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv">
270
<th scope="row"><?php _e('Exclude scripts from Autoptimize:','autoptimize'); ?></th>
271
<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo autoptimizeOption::get_option('autoptimize_js_exclude',"wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js"); ?>"/><br />
272
<?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 by Autoptimize.','autoptimize'); ?></label></td>
273
</tr>
274
<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv js_aggregate">
275
<th scope="row"><?php _e('Add try-catch wrapping?','autoptimize'); ?></th>
276
<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOption::get_option('autoptimize_js_trycatch')?'checked="checked" ':''; ?>/>
277
<?php _e('If your scripts break because of a JS-error, you might want to try this.','autoptimize'); ?></label></td>
278
</tr>
279
</table>
280
</li>
281
282
<li class="itemDetail">
283
<h2 class="itemTitle"><?php _e('CSS Options','autoptimize'); ?></h2>
284
<table class="form-table">
285
<tr valign="top">
286
<th scope="row"><?php _e('Optimize CSS Code?','autoptimize'); ?></th>
287
<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOption::get_option('autoptimize_css')?'checked="checked" ':''; ?>/></td>
288
</tr>
289
<tr class="<?php echo $hiddenClass;?>css_sub ao_adv" valign="top">
290
<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
291
<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get( 'autoptimize_css_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
292
<?php _e('Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
293
</tr>
294
<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv css_aggregate">
295
<th scope="row"><?php _e('Also aggregate inline CSS?','autoptimize'); ?></th>
296
<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOption::get_option('autoptimize_css_include_inline','1')?'checked="checked" ':''; ?>/>
297
<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.','autoptimize'); ?></label></td>
298
</tr>
299
<tr class="<?php echo $hiddenClass;?>css_sub ao_adv css_aggregate" valign="top">
300
<th scope="row"><?php _e('Generate data: URIs for images?','autoptimize'); ?></th>
301
<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOption::get_option('autoptimize_css_datauris')?'checked="checked" ':''; ?>/>
302
<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.','autoptimize'); ?></label></td>
303
</tr>
304 View Code Duplication
<?php if (autoptimizeOption::get_option('autoptimize_css_justhead')) { ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
305
<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv css_aggregate">
306
<th scope="row"><?php _e('Look for styles only in &lt;head&gt;?','autoptimize'); echo ' <i>'. __('(deprecated)','autoptimize') . '</i>'; ?></th>
307
<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOption::get_option('autoptimize_css_justhead')?'checked="checked" ':''; ?>/>
308
<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.','autoptimize'); ?></label></td>
309
</tr>
310
<?php } ?>
311
<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv">
312
<th scope="row"><?php _e('Inline and Defer CSS?','autoptimize'); ?></th>
313
<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOption::get_option('autoptimize_css_defer')?'checked="checked" ':''; ?>/>
314
<?php
315
_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> for more info.', 'autoptimize' );
316 View Code Duplication
if ( function_exists( 'is_plugin_active' ) && ! is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
317
    echo ' ';
318
    $critcss_install_url = network_admin_url() . 'plugin-install.php?s=autoptimize+criticalcss&tab=search&type=term';
319
    echo sprintf( __( 'This can be fully automated for different types of pages with the %s.', 'autoptimize' ), '<a href="'.$critcss_install_url.'">Autoptimize CriticalCSS Power-Up</a>' );
320
}
321
?>
322
</label></td>
323
</tr>
324
<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv" id="autoptimize_css_defer_inline">
325
<th scope="row"></th>
326
<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 autoptimizeOption::get_option('autoptimize_css_defer_inline'); ?></textarea></label></td>
327
</tr>
328
<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv css_sub css_aggregate">
329
<th scope="row"><?php _e('Inline all CSS?','autoptimize'); ?></th>
330
<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOption::get_option('autoptimize_css_inline')?'checked="checked" ':''; ?>/>
331
<?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>
332
</tr>
333
<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv css_sub">
334
<th scope="row"><?php _e('Exclude CSS from Autoptimize:','autoptimize'); ?></th>
335
<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo autoptimizeOption::get_option('autoptimize_css_exclude','wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css'); ?>"/><br />
336
<?php _e('A comma-separated list of CSS you want to exclude from being optimized.','autoptimize'); ?></label></td>
337
</tr>
338
</table>
339
</li>
340
341
<li class="itemDetail">
342
<h2 class="itemTitle"><?php _e('HTML Options','autoptimize'); ?></h2>
343
<table class="form-table">
344
<tr valign="top">
345
<th scope="row"><?php _e('Optimize HTML Code?','autoptimize'); ?></th>
346
<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOption::get_option('autoptimize_html')?'checked="checked" ':''; ?>/></td>
347
</tr>
348
<tr class="<?php echo $hiddenClass;?>html_sub ao_adv" valign="top">
349
<th scope="row"><?php _e('Keep HTML comments?','autoptimize'); ?></th>
350
<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOption::get_option('autoptimize_html_keepcomments')?'checked="checked" ':''; ?>/>
351
<?php _e('Enable this if you want HTML comments to remain in the page.','autoptimize'); ?></label></td>
352
</tr>
353
</table>
354
</li>
355
356
<li class="itemDetail">
357
<h2 class="itemTitle"><?php _e('CDN Options','autoptimize'); ?></h2>
358
<table class="form-table">
359
<tr valign="top">
360
<th scope="row"><?php _e('CDN Base URL','autoptimize'); ?></th>
361
<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(autoptimizeOption::get_option('autoptimize_cdn_url',''),array("http","https")); ?>" /><br />
362
<?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>). This is not needed for Cloudflare.','autoptimize'); ?></label></td>
363
</tr>
364
</table>
365
</li>
366
367
<li class="<?php echo $hiddenClass;?>itemDetail ao_adv">
368
<h2 class="itemTitle"><?php _e('Cache Info','autoptimize'); ?></h2>
369
<table class="form-table" >
370
<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
371
<th scope="row"><?php _e('Cache folder','autoptimize'); ?></th>
372
<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td>
373
</tr>
374
<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
375
<th scope="row"><?php _e('Can we write?','autoptimize'); ?></th>
376
<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes','autoptimize') : __('No','autoptimize')); ?></td>
377
</tr>
378
<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
379
<th scope="row"><?php _e('Cached styles and scripts','autoptimize'); ?></th>
380
<td><?php
381
    $AOstatArr = autoptimizeCache::stats();
382
    if ( ! empty( $AOstatArr ) && is_array( $AOstatArr ) ) {
383
        $AOcacheSize = size_format( $AOstatArr[1], 2 );
384
        $details = '';
0 ignored issues
show
Unused Code introduced by
$details is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
385
        if ( $AOcacheSize > 0 ) {
386
            $details = ', ~' . $AOcacheSize . ' total';
0 ignored issues
show
Unused Code introduced by
$details is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
387
        }
388
        printf( __( '%1$s files, totalling %2$s Kbytes (calculated at %3$s)', 'autoptimize' ), $AOstatArr[0], $AOcacheSize, date( 'H:i e', $AOstatArr[2] ) );
389
    }
390
?></td>
391
</tr>
392
</table>
393
</li>
394
395
<li class="<?php echo $hiddenClass;?>itemDetail ao_adv">
396
<h2 class="itemTitle"><?php _e('Misc Options','autoptimize'); ?></h2>
397
<table class="form-table">
398
    <tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
399
    <th scope="row"><?php _e('Save aggregated script/css as static files?','autoptimize'); ?></th>
400
    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOption::get_option('autoptimize_cache_nogzip','1')?'checked="checked" ':''; ?>/>
401
    <?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>
402
    </tr>
403
    <?php
404
    $_min_excl_class = 'ao_adv';
405
    if ( !$conf->get( 'autoptimize_css_aggregate' ) && !$conf->get( 'autoptimize_js_aggregate' ) ) {
406
        $_min_excl_class = ' hidden';
407
    }
408
    ?>
409
    <tr valign="top" id="min_excl_row" class="<?php echo $hiddenClass.$_min_excl_class; ?>">
410
        <th scope="row"><?php _e('Minify excluded CSS and JS files?','autoptimize'); ?></th>
411
        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOption::get_option('autoptimize_minify_excluded','1')?'checked="checked" ':''; ?>/>
412
        <?php _e('When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.','autoptimize'); ?></label></td>
413
    </tr>
414
    <tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
415
    <th scope="row"><?php _e('Also optimize for logged in users?','autoptimize'); ?></th>
416
    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOption::get_option('autoptimize_optimize_logged','1')?'checked="checked" ':''; ?>/>
417
    <?php _e('By default Autoptimize is also active for logged on users, uncheck not to optimize when logged in e.g. to use a pagebuilder.','autoptimize'); ?></label></td>
418
    </tr>
419
    <?php
420
    if ( function_exists("is_checkout") || function_exists("is_cart") || function_exists("edd_is_checkout") || function_exists("wpsc_is_cart") || function_exists("wpsc_is_checkout") ) {
421
    ?>
422
    <tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
423
        <th scope="row"><?php _e('Also optimize shop cart/ checkout?','autoptimize'); ?></th>
424
        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOption::get_option('autoptimize_optimize_checkout','1')?'checked="checked" ':''; ?>/>
425
            <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.','autoptimize'); ?></label>
426
        </td>
427
    </tr>
428
    <?php } ?>
429
</table>
430
</li>
431
432
</ul>
433
434
<input type="hidden" id="autoptimize_show_adv" name="autoptimize_show_adv" value="<?php echo autoptimizeOption::get_option('autoptimize_show_adv','1'); ?>">
435
436
<p class="submit">
437
<input type="submit" class="button-secondary" value="<?php _e('Save Changes','autoptimize') ?>" />
438
<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache','autoptimize') ?>" />
439
</p>
440
441
</form>
442
</div>
443
<div id="autoptimize_admin_feed" class="hidden">
444
    <div class="autoptimize_banner hidden">
445
      <ul>
446
    <?php
447
    if ( $this->settings_screen_do_remote_http ) {
448
        $AO_banner = get_transient( 'autoptimize_banner' );
449
        if ( empty( $AO_banner ) ) {
450
            $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION );
451
            if ( ! is_wp_error( $banner_resp ) ) {
452
                if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) {
453
                    $AO_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
454
                    set_transient('autoptimize_banner', $AO_banner, DAY_IN_SECONDS);
455
                }
456
            }
457
        }
458
        echo $AO_banner;
459
    }
460
    ?>
461
        <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.","autoptimize"); ?></li>
462
        <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>
463
    </ul>
464
    </div>
465
    <div style="margin-left:10px;margin-top:-5px;">
466
        <h2>
467
            <?php _e("futtta about","autoptimize") ?>
468
            <select id="feed_dropdown" >
469
                <option value="1"><?php _e("Autoptimize","autoptimize") ?></option>
470
                <option value="2"><?php _e("WordPress","autoptimize") ?></option>
471
                <option value="3"><?php _e("Web Technology","autoptimize") ?></option>
472
            </select>
473
        </h2>
474
        <div id="futtta_feed">
475
            <div id="autoptimizefeed">
476
                <?php $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_autoptimize"); ?>
477
            </div>
478
            <div id="wordpressfeed">
479
                <?php $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_wordpress"); ?>
480
            </div>
481
            <div id="webtechfeed">
482
                <?php $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_webtech"); ?>
483
            </div>
484
        </div>
485
    </div>
486
    <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!","autoptimize"); ?>"></a></div>
487
</div>
488
489
<script type="text/javascript">
490
    var feed = new Array;
491
    feed[1]="autoptimizefeed";
492
    feed[2]="wordpressfeed";
493
    feed[3]="webtechfeed";
494
    cookiename="autoptimize_feed";
495
496
    jQuery(document).ready(function() {
497
        check_ini_state();
498
499
        jQuery('#autoptimize_admin_feed').fadeTo("slow",1).show();
500
        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();
501
502
        jQuery( "#feed_dropdown" ).change(function() {
503
            jQuery("#futtta_feed").fadeTo(0,0);
504
            jQuery("#futtta_feed").fadeTo("slow",1);
505
        });
506
507
        jQuery( "#ao_show_adv" ).click(function() {
508
            jQuery( "#ao_show_adv" ).hide();
509
            jQuery( "#ao_hide_adv" ).show();
510
            jQuery( ".ao_adv" ).removeClass("hidden");
511
            jQuery( ".ao_adv" ).show("slow");
512
            if (jQuery("#autoptimize_css").attr('checked')) {
513
                jQuery(".css_sub:visible").fadeTo("fast",1);
514
                if (!jQuery("#autoptimize_css_defer").attr('checked')) {
515
                    jQuery("#autoptimize_css_defer_inline").hide();
516
                }
517
            }
518
            if (jQuery("#autoptimize_js").attr('checked')) {
519
                jQuery(".js_sub:visible").fadeTo("fast",1);
520
            }
521
            check_ini_state();
522
            jQuery( "input#autoptimize_show_adv" ).val("1");
523
        });
524
525
        jQuery( "#ao_hide_adv" ).click(function() {
526
            jQuery( "#ao_hide_adv" ).hide();
527
            jQuery( "#ao_show_adv" ).show();
528
            jQuery( ".ao_adv" ).hide("slow");
529
            jQuery( ".ao_adv" ).addClass("hidden");
530
            if (!jQuery("#autoptimize_css").attr('checked')) {
531
                jQuery(".css_sub:visible").fadeTo("fast",.33);
532
            }
533
            if (!jQuery("#autoptimize_js").attr('checked')) {
534
                jQuery(".js_sub:visible").fadeTo("fast",.33);
535
            }
536
            check_ini_state();
537
            jQuery( "input#autoptimize_show_adv" ).val("0");
538
        });
539
540
        jQuery( "#autoptimize_html" ).change(function() {
541
            if (this.checked) {
542
                jQuery(".html_sub:visible").fadeTo("fast",1);
543
            } else {
544
                jQuery(".html_sub:visible").fadeTo("fast",.33);
545
            }
546
        });
547
548
        jQuery( "#autoptimize_js" ).change(function() {
549
            if (this.checked) {
550
                jQuery(".js_sub:visible").fadeTo("fast",1);
551
            } else {
552
                jQuery(".js_sub:visible").fadeTo("fast",.33);
553
            }
554
        });
555
556
        jQuery( "#autoptimize_js_aggregate" ).change(function() {
557
            if (this.checked && jQuery("#autoptimize_js").attr('checked')) {
558
                jQuery(".js_aggregate:visible").fadeTo("fast",1);
559
                jQuery( "#min_excl_row" ).show();
560
            } else {
561
                jQuery(".js_aggregate:visible").fadeTo("fast",.33);
562
                if ( jQuery( "#autoptimize_css_aggregate" ).prop('checked') == false ) {
563
                    jQuery( "#min_excl_row" ).hide();
564
                }
565
            }
566
        });
567
568
        jQuery( "#autoptimize_css" ).change(function() {
569
            if (this.checked) {
570
                jQuery(".css_sub:visible").fadeTo("fast",1);
571
            } else {
572
                jQuery(".css_sub:visible").fadeTo("fast",.33);
573
            }
574
        });
575
576
        jQuery( "#autoptimize_css_aggregate" ).change(function() {
577
            if (this.checked && jQuery("#autoptimize_css").attr('checked')) {
578
                jQuery(".css_aggregate:visible").fadeTo("fast",1);
579
                jQuery( "#min_excl_row" ).show();
580
            } else {
581
                jQuery(".css_aggregate:visible").fadeTo("fast",.33);
582
                if ( jQuery( "#autoptimize_js_aggregate" ).prop('checked') == false ) {
583
                    jQuery( "#min_excl_row" ).hide();
584
                }
585
            }
586
        });
587
588
        jQuery( "#autoptimize_css_inline" ).change(function() {
589
            if (this.checked) {
590
                jQuery("#autoptimize_css_defer").prop("checked",false);
591
                jQuery("#autoptimize_css_defer_inline").hide("slow");
592
            }
593
        });
594
595
        jQuery( "#autoptimize_css_defer" ).change(function() {
596
            if (this.checked) {
597
                jQuery("#autoptimize_css_inline").prop("checked",false);
598
                jQuery("#autoptimize_css_defer_inline").show("slow");
599
            } else {
600
                jQuery("#autoptimize_css_defer_inline").hide("slow");
601
            }
602
        });
603
604
        jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) });
605
        feedid=jQuery.cookie(cookiename);
606
        if(typeof(feedid) !== "string") feedid=1;
607
        show_feed(feedid);
608
    })
609
610
    // validate cdn_url.
611
    var cdn_url=document.getElementById("cdn_url");
612
    cdn_url_baseCSS=cdn_url.style.cssText;
613
    if ("validity" in cdn_url) {
614
        jQuery("#cdn_url").focusout(function (event) {
615
        if (cdn_url.validity.valid) {
616
            cdn_url.style.cssText=cdn_url_baseCSS;
617
        } else {
618
            cdn_url.style.cssText=cdn_url_baseCSS+"border:1px solid #f00;color:#f00;box-shadow: 0 0 2px #f00;";
619
        }});
620
    }
621
622
    function check_ini_state() {
623
        if (!jQuery("#autoptimize_css_defer").attr('checked')) {
624
            jQuery("#autoptimize_css_defer_inline").hide();
625
        }
626
        if (!jQuery("#autoptimize_html").attr('checked')) {
627
            jQuery(".html_sub:visible").fadeTo('fast',.33);
628
        }
629
        if (!jQuery("#autoptimize_css").attr('checked')) {
630
            jQuery(".css_sub:visible").fadeTo('fast',.33);
631
        }
632
        if (!jQuery("#autoptimize_css_aggregate").attr('checked')) {
633
            jQuery(".css_aggregate:visible").fadeTo('fast',.33);
634
        }
635
        if (!jQuery("#autoptimize_js").attr('checked')) {
636
            jQuery(".js_sub:visible").fadeTo('fast',.33);
637
        }
638
        if (!jQuery("#autoptimize_js_aggregate").attr('checked')) {
639
            jQuery(".js_aggregate:visible").fadeTo('fast',.33);
640
        }
641
    }
642
643
    function show_feed(id) {
644
        jQuery('#futtta_feed').children().hide();
645
        jQuery('#'+feed[id]).show();
646
        jQuery("#feed_dropdown").val(id);
647
        jQuery.cookie(cookiename,id,{ expires: 365 });
648
    }
649
</script>
650
</div>
651
652
<?php
653
    }
654
655
    public function addmenu()
656
    {
657
		if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) ) {
658
			$hook = add_submenu_page( 'settings.php',  __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show' ) );
0 ignored issues
show
Unused Code introduced by
$hook is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
659
		}
660
		if ( ! is_multisite() || 'on' === autoptimizeOption::get_option('autoptimize_enable_site_config') ) {
661
			$hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show' ) );
662
		} else {
663
			$hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_message' ) );
664
		}
665
666
        add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
667
        add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
668
    }
669
670
    public function autoptimize_admin_scripts()
671
    {
672
        wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true );
673
        wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
674
    }
675
676
    public function autoptimize_admin_styles()
677
    {
678
        wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) );
679
        wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) );
680
    }
681
682
    public function registersettings() {
683
        register_setting( 'autoptimize', 'autoptimize_html' );
684
        register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
685
		register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
686
        register_setting( 'autoptimize', 'autoptimize_js' );
687
        register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
688
        register_setting( 'autoptimize', 'autoptimize_js_exclude' );
689
        register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
690
        register_setting( 'autoptimize', 'autoptimize_js_justhead' );
691
        register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
692
        register_setting( 'autoptimize', 'autoptimize_js_include_inline' );
693
        register_setting( 'autoptimize', 'autoptimize_css' );
694
        register_setting( 'autoptimize', 'autoptimize_css_aggregate' );
695
        register_setting( 'autoptimize', 'autoptimize_css_exclude' );
696
        register_setting( 'autoptimize', 'autoptimize_css_justhead' );
697
        register_setting( 'autoptimize', 'autoptimize_css_datauris' );
698
        register_setting( 'autoptimize', 'autoptimize_css_defer' );
699
        register_setting( 'autoptimize', 'autoptimize_css_defer_inline' );
700
        register_setting( 'autoptimize', 'autoptimize_css_inline' );
701
        register_setting( 'autoptimize', 'autoptimize_css_include_inline' );
702
        register_setting( 'autoptimize', 'autoptimize_cdn_url' );
703
        register_setting( 'autoptimize', 'autoptimize_cache_clean' );
704
        register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
705
        register_setting( 'autoptimize', 'autoptimize_show_adv' );
706
        register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
707
        register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
708
        register_setting( 'autoptimize', 'autoptimize_minify_excluded' );
709
    }
710
711
    public function setmeta($links, $file = null)
712
    {
713
        // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/.
714
        // Do it only once - saves time.
715
        static $plugin;
716
        if ( empty( $plugin ) ) {
717
            $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
718
        }
719
720
        if ( null === $file ) {
721
            // 2.7 and lower.
722
            $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) );
723
            array_unshift( $links, $settings_link );
724
        } else {
725
            // 2.8 and higher.
726
            // If it's us, add the link.
727
            if ( $file === $plugin ) {
728
                $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) );
729
                $links = array_merge( $links, $newlink );
730
            }
731
        }
732
733
        return $links;
734
    }
735
736
    /**
737
     * @return array
738
     */
739
    public static function get_defaults()
740
    {
741
        static $config = array(
742
            'autoptimize_html' => 0,
743
            'autoptimize_html_keepcomments' => 0,
744
			'autoptimize_enable_site_config' => 0,
745
            'autoptimize_js' => 0,
746
            'autoptimize_js_aggregate' => 1,
747
            'autoptimize_js_exclude' => 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js',
748
            'autoptimize_js_trycatch' => 0,
749
            'autoptimize_js_justhead' => 0,
750
            'autoptimize_js_include_inline' => 0,
751
            'autoptimize_js_forcehead' => 0,
752
            'autoptimize_css' => 0,
753
            'autoptimize_css_aggregate' => 1,
754
            'autoptimize_css_exclude' => 'admin-bar.min.css, dashicons.min.css, wp-content/cache/, wp-content/uploads/',
755
            'autoptimize_css_justhead' => 0,
756
            'autoptimize_css_include_inline' => 1,
757
            'autoptimize_css_defer' => 0,
758
            'autoptimize_css_defer_inline' => '',
759
            'autoptimize_css_inline' => 0,
760
            'autoptimize_css_datauris' => 0,
761
            'autoptimize_cdn_url' => '',
762
            'autoptimize_cache_nogzip' => 1,
763
            'autoptimize_show_adv' => 1,
764
            'autoptimize_optimize_logged' => 1,
765
            'autoptimize_optimize_checkout' => 1,
766
            'autoptimize_minify_excluded' => 1,
767
        );
768
769
        return $config;
770
    }
771
772
    /**
773
     * Returns default option values for autoptimizeExtra.
774
     *
775
     * @return array
776
     */
777
    public static function get_ao_extra_default_options()
778
    {
779
        $defaults = array(
780
            'autoptimize_extra_checkbox_field_1' => '0',
781
            'autoptimize_extra_checkbox_field_0' => '0',
782
            'autoptimize_extra_radio_field_4'    => '1',
783
            'autoptimize_extra_text_field_2'     => '',
784
            'autoptimize_extra_text_field_3'     => '',
785
        );
786
787
        return $defaults;
788
    }
789
790
    /**
791
     * Returns default option values for autoptimizeExtra.
792
     *
793
     * @return array
794
     */
795
    public static function get_ao_imgopt_default_options()
796
    {
797
        $defaults = array(
798
            'autoptimize_imgopt_checkbox_field_1' => '0', // imgopt off.
799
            'autoptimize_imgopt_select_field_2'   => '2', // quality glossy.
800
            'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
801
            'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
802
            'autoptimize_imgopt_text_field_5'     => '',  // lazy load exclusions empty.
803
        );
804
        return $defaults;
805
    }
806
807
    /**
808
     * Returns preload polyfill JS.
809
     *
810
     * @return string
811
     */
812
    public static function get_ao_css_preload_polyfill()
813
    {
814
        $preload_poly = apply_filters('autoptimize_css_preload_polyfill','<script data-cfasync=\'false\'>!function(t){"use strict";t.loadCSS||(t.loadCSS=function(){});var e=loadCSS.relpreload={};if(e.support=function(){var e;try{e=t.document.createElement("link").relList.supports("preload")}catch(t){e=!1}return function(){return e}}(),e.bindMediaToggle=function(t){function e(){t.media=a}var a=t.media||"all";t.addEventListener?t.addEventListener("load",e):t.attachEvent&&t.attachEvent("onload",e),setTimeout(function(){t.rel="stylesheet",t.media="only x"}),setTimeout(e,3e3)},e.poly=function(){if(!e.support())for(var a=t.document.getElementsByTagName("link"),n=0;n<a.length;n++){var o=a[n];"preload"!==o.rel||"style"!==o.getAttribute("as")||o.getAttribute("data-loadcss")||(o.setAttribute("data-loadcss",!0),e.bindMediaToggle(o))}},!e.support()){e.poly();var a=t.setInterval(e.poly,500);t.addEventListener?t.addEventListener("load",function(){e.poly(),t.clearInterval(a)}):t.attachEvent&&t.attachEvent("onload",function(){e.poly(),t.clearInterval(a)})}"undefined"!=typeof exports?exports.loadCSS=loadCSS:t.loadCSS=loadCSS}("undefined"!=typeof global?global:this);</script>');
815
        return $preload_poly;
816
    }
817
818
    /**
819
     * Returns preload JS onload handler.
820
     *
821
     * @return string
822
     */
823
    public static function get_ao_css_preload_onload()
824
    {
825
        $preload_onload = apply_filters('autoptimize_filter_css_preload_onload',"this.onload=null;this.rel='stylesheet'");
826
        return $preload_onload;
827
    }
828
829
    public function get($key)
830
    {
831
        if ( ! is_array( $this->config ) ) {
832
            // Default config.
833
            $config = self::get_defaults();
834
835
            // Override with user settings.
836
            foreach ( array_keys( $config ) as $name ) {
837
                $conf = autoptimizeOption::get_option( $name );
838
                if ( false !== $conf ) {
839
                    // It was set before!
840
                    $config[ $name ] = $conf;
841
                }
842
            }
843
844
            // Save for next call.
845
            $this->config = apply_filters( 'autoptimize_filter_get_config', $config );
846
        }
847
848
        if ( isset( $this->config[ $key ] ) ) {
849
            return $this->config[ $key ];
850
        }
851
852
        return false;
853
    }
854
855
    private function getFutttaFeeds($url) {
856
        if ( $this->settings_screen_do_remote_http ) {
857
            $rss = fetch_feed( $url );
858
            $maxitems = 0;
859
860 View Code Duplication
            if ( ! is_wp_error( $rss ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
861
                $maxitems = $rss->get_item_quantity( 7 );
862
                $rss_items = $rss->get_items( 0, $maxitems );
863
            }
864
            ?>
865
            <ul>
866
                <?php if ( $maxitems == 0 ) : ?>
867
                    <li><?php _e( 'No items', 'autoptimize' ); ?></li>
868
                <?php else : ?>
869
                    <?php foreach ( $rss_items as $item ) : ?>
0 ignored issues
show
Bug introduced by
The variable $rss_items does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
870
                        <li>
871
                            <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
872
                                title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date('j F Y | g:i a') ); ?>">
873
                                <?php echo esc_html( $item->get_title() ); ?>
874
                            </a>
875
                        </li>
876
                    <?php endforeach; ?>
877
                <?php endif; ?>
878
            </ul>
879
        <?php
880
        }
881
    }
882
883
    // based on http://wordpress.stackexchange.com/a/58826
884
    static function ao_admin_tabs()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
885
    {
886
        $tabs = apply_filters( 'autoptimize_filter_settingsscreen_tabs' ,array( 'autoptimize' => __( 'JS, CSS  &amp; HTML', 'autoptimize' ) ) );
887
        $tabContent = '';
888
        $tabs_count = count($tabs);
889
        if ( $tabs_count > 1 ) {
890
            if ( isset( $_GET['page'] ) ) {
891
                $currentId = $_GET['page'];
892
            } else {
893
                $currentId = "autoptimize";
894
            }
895
            $tabContent .= '<h2 class="nav-tab-wrapper">';
896
            foreach ($tabs as $tabId => $tabName) {
897
                if ( $currentId == $tabId ) {
898
                    $class = ' nav-tab-active';
899
                } else{
900
                    $class = '';
901
                }
902
                $tabContent .= '<a class="nav-tab' . $class . '" href="?page=' . $tabId . '">' . $tabName . '</a>';
903
            }
904
            $tabContent .= '</h2>';
905
        } else {
906
            $tabContent = '<hr/>';
907
        }
908
909
        return $tabContent;
910
    }
911
912
    /**
913
     * Returns true if in admin (and not in admin-ajax.php!)
914
     *
915
     * @return bool
916
     */
917
    public static function is_admin_and_not_ajax()
918
    {
919
        return ( is_admin() && ! self::doing_ajax() );
920
    }
921
922
    /**
923
     * Returns true if doing ajax.
924
     *
925
     * @return bool
926
     */
927
    protected static function doing_ajax()
928
    {
929
        if ( function_exists( 'wp_doing_ajax' ) ) {
930
            return wp_doing_ajax();
931
        }
932
        return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
933
    }
934
}
935