Completed
Push — master ( f1d861...5b581f )
by frank
01:49
created
classes/autoptimizeCacheChecker.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * Checks if cachesize is > 0.5GB (size is filterable), if so, an option is set which controls showing an admin notice.
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if (!defined('ABSPATH')) {
10 10
     exit;
11 11
 }
12 12
 
@@ -25,51 +25,51 @@  discard block
 block discarded – undo
25 25
 
26 26
     public function add_hooks()
27 27
     {
28
-        if ( is_admin() ) {
29
-            add_action( 'plugins_loaded', array( $this, 'setup' ) );
28
+        if (is_admin()) {
29
+            add_action('plugins_loaded', array($this, 'setup'));
30 30
         }
31
-        add_action( self::SCHEDULE_HOOK, array( $this, 'cronjob' ) );
32
-        add_action( 'admin_notices', array( $this, 'show_admin_notice' ) );
31
+        add_action(self::SCHEDULE_HOOK, array($this, 'cronjob'));
32
+        add_action('admin_notices', array($this, 'show_admin_notice'));
33 33
     }
34 34
 
35 35
     public function setup()
36 36
     {
37
-        $do_cache_check = (bool) apply_filters( 'autoptimize_filter_cachecheck_do', true );
38
-        $schedule       = wp_get_schedule( self::SCHEDULE_HOOK );
39
-        $frequency      = apply_filters( 'autoptimize_filter_cachecheck_frequency', 'twicedaily' );
40
-        if ( ! in_array( $frequency, array( 'hourly', 'twicedaily', 'daily', 'weekly', 'monthly' ) ) ) {
37
+        $do_cache_check = (bool) apply_filters('autoptimize_filter_cachecheck_do', true);
38
+        $schedule       = wp_get_schedule(self::SCHEDULE_HOOK);
39
+        $frequency      = apply_filters('autoptimize_filter_cachecheck_frequency', 'twicedaily');
40
+        if (!in_array($frequency, array('hourly', 'twicedaily', 'daily', 'weekly', 'monthly'))) {
41 41
             $frequency = 'twicedaily';
42 42
         }
43
-        if ( $do_cache_check && ( ! $schedule || $schedule !== $frequency ) ) {
44
-            if ( $schedule ) {
45
-                wp_clear_scheduled_hook( self::SCHEDULE_HOOK );
43
+        if ($do_cache_check && (!$schedule || $schedule !== $frequency)) {
44
+            if ($schedule) {
45
+                wp_clear_scheduled_hook(self::SCHEDULE_HOOK);
46 46
             }
47
-            wp_schedule_event( time(), $frequency, self::SCHEDULE_HOOK );
48
-        } elseif ( $schedule && ! $do_cache_check ) {
49
-            wp_clear_scheduled_hook( self::SCHEDULE_HOOK );
47
+            wp_schedule_event(time(), $frequency, self::SCHEDULE_HOOK);
48
+        } elseif ($schedule && !$do_cache_check) {
49
+            wp_clear_scheduled_hook(self::SCHEDULE_HOOK);
50 50
         }
51 51
     }
52 52
 
53 53
     public function cronjob()
54 54
     {
55 55
         // Check cachesize and act accordingly.
56
-        $max_size       = (int) apply_filters( 'autoptimize_filter_cachecheck_maxsize', 536870912 );
57
-        $do_cache_check = (bool) apply_filters( 'autoptimize_filter_cachecheck_do', true );
56
+        $max_size       = (int) apply_filters('autoptimize_filter_cachecheck_maxsize', 536870912);
57
+        $do_cache_check = (bool) apply_filters('autoptimize_filter_cachecheck_do', true);
58 58
         $stat_array     = autoptimizeCache::stats();
59
-        $cache_size     = round( $stat_array[1] );
60
-        if ( ( $cache_size > $max_size ) && ( $do_cache_check ) ) {
61
-            autoptimizeOptionWrapper::update_option( 'autoptimize_cachesize_notice', true );
62
-            if ( apply_filters( 'autoptimize_filter_cachecheck_sendmail', true ) ) {
63
-                $home_url  = esc_url( home_url() );
64
-                $ao_mailto = apply_filters( 'autoptimize_filter_cachecheck_mailto', autoptimizeOptionWrapper::get_option( 'admin_email', '' ) );
65
-
66
-                $ao_mailsubject = __( 'Autoptimize cache size warning', 'autoptimize' ) . ' (' . $home_url . ')';
67
-                $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' ) . ' (site: ' . $home_url . ')';
68
-
69
-                if ( ! empty( $ao_mailto ) ) {
70
-                    $ao_mailresult = wp_mail( $ao_mailto, $ao_mailsubject, $ao_mailbody );
71
-                    if ( ! $ao_mailresult ) {
72
-                        error_log( 'Autoptimize could not send cache size warning mail.' );
59
+        $cache_size     = round($stat_array[1]);
60
+        if (($cache_size > $max_size) && ($do_cache_check)) {
61
+            autoptimizeOptionWrapper::update_option('autoptimize_cachesize_notice', true);
62
+            if (apply_filters('autoptimize_filter_cachecheck_sendmail', true)) {
63
+                $home_url  = esc_url(home_url());
64
+                $ao_mailto = apply_filters('autoptimize_filter_cachecheck_mailto', autoptimizeOptionWrapper::get_option('admin_email', ''));
65
+
66
+                $ao_mailsubject = __('Autoptimize cache size warning', 'autoptimize').' ('.$home_url.')';
67
+                $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').' (site: '.$home_url.')';
68
+
69
+                if (!empty($ao_mailto)) {
70
+                    $ao_mailresult = wp_mail($ao_mailto, $ao_mailsubject, $ao_mailbody);
71
+                    if (!$ao_mailresult) {
72
+                        error_log('Autoptimize could not send cache size warning mail.');
73 73
                     }
74 74
                 }
75 75
             }
@@ -87,16 +87,16 @@  discard block
 block discarded – undo
87 87
 
88 88
     public function show_admin_notice()
89 89
     {
90
-        if ( (bool) autoptimizeOptionWrapper::get_option( 'autoptimize_cachesize_notice', false ) && current_user_can( 'manage_options' ) ) {
90
+        if ((bool) autoptimizeOptionWrapper::get_option('autoptimize_cachesize_notice', false) && current_user_can('manage_options')) {
91 91
             echo '<div class="notice notice-warning"><p>';
92
-            _e( '<strong>Autoptimize\'s cache size is getting big</strong>, consider purging the cache. Have a look at <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank" rel="noopener noreferrer">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize' );
92
+            _e('<strong>Autoptimize\'s cache size is getting big</strong>, consider purging the cache. Have a look at <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank" rel="noopener noreferrer">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize');
93 93
             echo '</p></div>';
94
-            autoptimizeOptionWrapper::update_option( 'autoptimize_cachesize_notice', false );
94
+            autoptimizeOptionWrapper::update_option('autoptimize_cachesize_notice', false);
95 95
         }
96 96
 
97 97
         // Notice for image proxy usage.
98 98
         $_imgopt_notice = autoptimizeImages::instance()->get_imgopt_status_notice_wrapper();
99
-        if ( current_user_can( 'manage_options' ) && is_array( $_imgopt_notice ) && array_key_exists( 'status', $_imgopt_notice ) && in_array( $_imgopt_notice['status'], array( 1, -1, -2, -3 ) ) ) {
99
+        if (current_user_can('manage_options') && is_array($_imgopt_notice) && array_key_exists('status', $_imgopt_notice) && in_array($_imgopt_notice['status'], array(1, -1, -2, -3))) {
100 100
             $_dismissible = 'ao-img-opt-notice-';
101 101
             $_hide_notice = '7';
102 102
 
@@ -104,10 +104,10 @@  discard block
 block discarded – undo
104 104
                 $_hide_notice = '1';
105 105
             }
106 106
 
107
-            $_imgopt_notice_dismissible = apply_filters( 'autoptimize_filter_imgopt_notice_dismissable', $_dismissible . $_hide_notice );
107
+            $_imgopt_notice_dismissible = apply_filters('autoptimize_filter_imgopt_notice_dismissable', $_dismissible.$_hide_notice);
108 108
 
109
-            if ( $_imgopt_notice && PAnD::is_admin_notice_active( $_imgopt_notice_dismissible ) ) {
110
-                echo '<div class="notice notice-warning is-dismissible" data-dismissible="' . $_imgopt_notice_dismissible . '"><p><strong>' . __( 'Autoptimize', 'autoptimize' ) . '</strong>: ' . $_imgopt_notice['notice'] . '</p></div>';
109
+            if ($_imgopt_notice && PAnD::is_admin_notice_active($_imgopt_notice_dismissible)) {
110
+                echo '<div class="notice notice-warning is-dismissible" data-dismissible="'.$_imgopt_notice_dismissible.'"><p><strong>'.__('Autoptimize', 'autoptimize').'</strong>: '.$_imgopt_notice['notice'].'</p></div>';
111 111
             }
112 112
         }
113 113
     }
Please login to merge, or discard this patch.
classes/autoptimizePartners.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * addons and/or affiliate services.
5 5
  */
6 6
 
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
     exit;
9 9
 }
10 10
 
@@ -17,68 +17,68 @@  discard block
 block discarded – undo
17 17
 
18 18
     public function run()
19 19
     {
20
-        if ( $this->enabled() ) {
21
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_partner_tabs' ), 10, 1 );
20
+        if ($this->enabled()) {
21
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_partner_tabs'), 10, 1);
22 22
         }
23
-        if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
24
-            add_action( 'network_admin_menu', array( $this, 'add_admin_menu' ) );
23
+        if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
24
+            add_action('network_admin_menu', array($this, 'add_admin_menu'));
25 25
         } else {
26
-            add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
26
+            add_action('admin_menu', array($this, 'add_admin_menu'));
27 27
         }
28 28
     }
29 29
 
30 30
     protected function enabled()
31 31
     {
32
-        return apply_filters( 'autoptimize_filter_show_partner_tabs', true );
32
+        return apply_filters('autoptimize_filter_show_partner_tabs', true);
33 33
     }
34 34
 
35
-    public function add_partner_tabs( $in )
35
+    public function add_partner_tabs($in)
36 36
     {
37
-        $in = array_merge( $in, array(
38
-            'ao_partners' => __( 'Optimize More!', 'autoptimize' ),
39
-        ) );
37
+        $in = array_merge($in, array(
38
+            'ao_partners' => __('Optimize More!', 'autoptimize'),
39
+        ));
40 40
 
41 41
         return $in;
42 42
     }
43 43
 
44 44
     public function add_admin_menu()
45 45
     {
46
-        if ( $this->enabled() ) {
47
-            add_submenu_page( null, 'AO partner', 'AO partner', 'manage_options', 'ao_partners', array( $this, 'ao_partners_page' ) );
46
+        if ($this->enabled()) {
47
+            add_submenu_page(null, 'AO partner', 'AO partner', 'manage_options', 'ao_partners', array($this, 'ao_partners_page'));
48 48
         }
49 49
     }
50 50
 
51 51
     protected function get_ao_partner_feed_markup()
52 52
     {
53
-        $no_feed_text = __( 'Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for Autoptimize power-ups!', 'autoptimize' );
53
+        $no_feed_text = __('Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for Autoptimize power-ups!', 'autoptimize');
54 54
         $output       = '';
55
-        if ( apply_filters( 'autoptimize_settingsscreen_remotehttp', true ) ) {
56
-            $rss      = fetch_feed( 'http://feeds.feedburner.com/OptimizingMattersDownloads' );
55
+        if (apply_filters('autoptimize_settingsscreen_remotehttp', true)) {
56
+            $rss      = fetch_feed('http://feeds.feedburner.com/OptimizingMattersDownloads');
57 57
             $maxitems = 0;
58 58
 
59
-            if ( ! is_wp_error( $rss ) ) {
60
-                $maxitems  = $rss->get_item_quantity( 20 );
61
-                $rss_items = $rss->get_items( 0, $maxitems );
59
+            if (!is_wp_error($rss)) {
60
+                $maxitems  = $rss->get_item_quantity(20);
61
+                $rss_items = $rss->get_items(0, $maxitems);
62 62
             }
63 63
 
64
-            if ( 0 == $maxitems ) {
64
+            if (0 == $maxitems) {
65 65
                 $output .= $no_feed_text;
66 66
             } else {
67 67
                 $output .= '<ul>';
68
-                foreach ( $rss_items as $item ) {
69
-                    $item_url  = esc_url( $item->get_permalink() );
68
+                foreach ($rss_items as $item) {
69
+                    $item_url  = esc_url($item->get_permalink());
70 70
                     $enclosure = $item->get_enclosure();
71 71
 
72 72
                     $output .= '<li class="itemDetail">';
73
-                    $output .= '<h3 class="itemTitle"><a href="' . $item_url . '" target="_blank">' . esc_html( $item->get_title() ) . '</a></h3>';
73
+                    $output .= '<h3 class="itemTitle"><a href="'.$item_url.'" target="_blank">'.esc_html($item->get_title()).'</a></h3>';
74 74
 
75
-                    if ( $enclosure && ( false !== strpos( $enclosure->get_type(), 'image' ) ) ) {
76
-                        $img_url = esc_url( $enclosure->get_link() );
77
-                        $output .= '<div class="itemImage"><a href="' . $item_url . '" target="_blank"><img src="' . $img_url . '"></a></div>';
75
+                    if ($enclosure && (false !== strpos($enclosure->get_type(), 'image'))) {
76
+                        $img_url = esc_url($enclosure->get_link());
77
+                        $output .= '<div class="itemImage"><a href="'.$item_url.'" target="_blank"><img src="'.$img_url.'"></a></div>';
78 78
                     }
79 79
 
80
-                    $output .= '<div class="itemDescription">' . wp_kses_post( $item->get_description() ) . '</div>';
81
-                    $output .= '<div class="itemButtonRow"><div class="itemButton button-secondary"><a href="' . $item_url . '" target="_blank">' . __( 'More info', 'autoptimize' ) . '</a></div></div>';
80
+                    $output .= '<div class="itemDescription">'.wp_kses_post($item->get_description()).'</div>';
81
+                    $output .= '<div class="itemButtonRow"><div class="itemButton button-secondary"><a href="'.$item_url.'" target="_blank">'.__('More info', 'autoptimize').'</a></div></div>';
82 82
                     $output .= '</li>';
83 83
                 }
84 84
                 $output .= '</ul>';
@@ -136,11 +136,11 @@  discard block
 block discarded – undo
136 136
         color: #23282d;
137 137
     }
138 138
     </style>
139
-    <script>document.title = "Autoptimize: <?php _e( 'Optimize More!', 'autoptimize' ); ?> " + document.title;</script>
139
+    <script>document.title = "Autoptimize: <?php _e('Optimize More!', 'autoptimize'); ?> " + document.title;</script>
140 140
     <div class="wrap">
141
-        <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
141
+        <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
142 142
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
143
-        <?php echo '<h2>' . __( "These Autoptimize power-ups and related services will improve your site's performance even more!", 'autoptimize' ) . '</h2>'; ?>
143
+        <?php echo '<h2>'.__("These Autoptimize power-ups and related services will improve your site's performance even more!", 'autoptimize').'</h2>'; ?>
144 144
         <div>
145 145
             <?php echo $this->get_ao_partner_feed_markup(); ?>
146 146
         </div>
Please login to merge, or discard this patch.
config/autoptimize_404_handler.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -20,19 +20,19 @@
 block discarded – undo
20 20
  * to files that don't exist in AO's cache.
21 21
  */
22 22
 
23
-$original_request = strtok( $_SERVER['REQUEST_URI'], '?' );
24
-$fallback_target  = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request );
23
+$original_request = strtok($_SERVER['REQUEST_URI'], '?');
24
+$fallback_target  = preg_replace('/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request);
25 25
 $ao_cache_dir     = '<!--ao-cache-dir-->';
26
-$js_or_css        = pathinfo( $original_request, PATHINFO_EXTENSION );
27
-$fallback_path    = $ao_cache_dir . $js_or_css . '/autoptimize_fallback.' . $js_or_css;
26
+$js_or_css        = pathinfo($original_request, PATHINFO_EXTENSION);
27
+$fallback_path    = $ao_cache_dir.$js_or_css.'/autoptimize_fallback.'.$js_or_css;
28 28
 
29
-if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) {
29
+if ($original_request !== $fallback_target && file_exists($fallback_path)) {
30 30
     // error_log( 'Autoptimize file ' . $original_request . ' not found, using fallback instead.' );
31
-    header( 'HTTP/1.1 301 Moved Permanently' );
32
-    header( 'Location: ' . $fallback_target );
31
+    header('HTTP/1.1 301 Moved Permanently');
32
+    header('Location: '.$fallback_target);
33 33
 } else {
34 34
     // error_log( 'Autoptimize file ' . $original_request . ' not found, sending 410 gone response.' );
35
-    header( 'HTTP/1.1 410 Gone' );
35
+    header('HTTP/1.1 410 Gone');
36 36
 }
37 37
 
38 38
 exit();
Please login to merge, or discard this patch.
classes/autoptimizeOptionWrapper.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Autoptimize options handler.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
      * Ensure that is_plugin_active_for_network function is declared.
22 22
      */
23 23
     public static function maybe_include_plugin_functions() {
24
-        if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
25
-            include_once ABSPATH . 'wp-admin/includes/plugin.php';
24
+        if (!function_exists('is_plugin_active_for_network')) {
25
+            include_once ABSPATH.'wp-admin/includes/plugin.php';
26 26
         }
27 27
     }
28 28
 
@@ -33,19 +33,19 @@  discard block
 block discarded – undo
33 33
      * @param mixed  $default Optional. Default value to return if the option does not exist.
34 34
      * @return mixed Value set for the option.
35 35
      */
36
-    public static function get_option( $option, $default = false ) {
36
+    public static function get_option($option, $default = false) {
37 37
         // This is always a network setting, it is on by default to ensure settings are available at site level unless explicitly turned off.
38
-        if ( 'autoptimize_enable_site_config' === $option ) {
39
-            return get_network_option( get_main_network_id(), $option, 'on' );
38
+        if ('autoptimize_enable_site_config' === $option) {
39
+            return get_network_option(get_main_network_id(), $option, 'on');
40 40
         }
41 41
 
42 42
         // If the plugin is network activated and our per site setting is not on, use the network configuration.
43
-        $configuration_per_site = get_network_option( get_main_network_id(), 'autoptimize_enable_site_config', 'on' );
44
-        if ( self::is_ao_active_for_network() && ( 'on' !== $configuration_per_site || is_network_admin() ) ) {
45
-            return get_network_option( get_main_network_id(), $option, $default );
43
+        $configuration_per_site = get_network_option(get_main_network_id(), 'autoptimize_enable_site_config', 'on');
44
+        if (self::is_ao_active_for_network() && ('on' !== $configuration_per_site || is_network_admin())) {
45
+            return get_network_option(get_main_network_id(), $option, $default);
46 46
         }
47 47
 
48
-        return get_option( $option, $default );
48
+        return get_option($option, $default);
49 49
     }
50 50
 
51 51
     /**
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
      *                              the default value is 'yes'. Default null.
60 60
      * @return bool False if value was not updated and true if value was updated.
61 61
      */
62
-    public static function update_option( $option, $value, $autoload = null ) {
63
-        if ( self::is_ao_active_for_network() && is_network_admin() ) {
64
-            return update_network_option( get_main_network_id(), $option, $value );
65
-        } elseif ( 'autoptimize_enable_site_config' !== $option ) {
66
-            return update_option( $option, $value, $autoload );
62
+    public static function update_option($option, $value, $autoload = null) {
63
+        if (self::is_ao_active_for_network() && is_network_admin()) {
64
+            return update_network_option(get_main_network_id(), $option, $value);
65
+        } elseif ('autoptimize_enable_site_config' !== $option) {
66
+            return update_option($option, $value, $autoload);
67 67
         }
68 68
     }
69 69
 
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
      * in that case, take care of multisite case.
73 73
      */
74 74
     public static function check_multisite_on_saving_options() {
75
-        if ( self::is_ao_active_for_network() ) {
76
-            add_filter( 'pre_update_option', 'autoptimizeOptionWrapper::update_autoptimize_option_on_network', 10, 3 );
75
+        if (self::is_ao_active_for_network()) {
76
+            add_filter('pre_update_option', 'autoptimizeOptionWrapper::update_autoptimize_option_on_network', 10, 3);
77 77
         }
78 78
     }
79 79
 
@@ -84,16 +84,16 @@  discard block
 block discarded – undo
84 84
      * @param string $option    Option name.
85 85
      * @param string $old_value Old value.
86 86
      */
87
-    public static function update_autoptimize_option_on_network( $value, $option, $old_value ) {
88
-        if ( strpos( $option, 'autoptimize_' ) === 0 && self::is_options_from_network_admin() ) {
89
-            if ( self::is_ao_active_for_network() ) {
90
-                update_network_option( get_main_network_id(), $option, $value );
87
+    public static function update_autoptimize_option_on_network($value, $option, $old_value) {
88
+        if (strpos($option, 'autoptimize_') === 0 && self::is_options_from_network_admin()) {
89
+            if (self::is_ao_active_for_network()) {
90
+                update_network_option(get_main_network_id(), $option, $value);
91 91
                 // Return old value, to stop update_option logic.
92 92
                 return $old_value;
93 93
             }
94
-            if ( apply_filters( 'autoptimize_filter_optionwrapper_wp_cache_delete', false ) ) {
94
+            if (apply_filters('autoptimize_filter_optionwrapper_wp_cache_delete', false)) {
95 95
                 // in some (rare) cases options seem to get stuck in WP's Object cache, this should clear it there.
96
-                wp_cache_delete( $option );
96
+                wp_cache_delete($option);
97 97
             }
98 98
         }
99 99
         return $value;
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
     public static function is_options_from_network_admin() {
108 108
         static $_really_is_network_admin = null;
109 109
 
110
-        if ( null === $_really_is_network_admin ) {
111
-            if ( array_key_exists( '_wp_http_referer', $_POST ) && strpos( network_admin_url( 'settings.php' ), strtok( $_POST['_wp_http_referer'], '?' ) ) !== false ) {
110
+        if (null === $_really_is_network_admin) {
111
+            if (array_key_exists('_wp_http_referer', $_POST) && strpos(network_admin_url('settings.php'), strtok($_POST['_wp_http_referer'], '?')) !== false) {
112 112
                 $_really_is_network_admin = true;
113 113
             } else {
114 114
                 $_really_is_network_admin = false;
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
      */
124 124
     public static function is_ao_active_for_network() {
125 125
         static $_is_ao_active_for_network = null;
126
-        if ( null === $_is_ao_active_for_network || defined( 'TEST_MULTISITE_FORCE_AO_ON_NETWORK' ) ) {
126
+        if (null === $_is_ao_active_for_network || defined('TEST_MULTISITE_FORCE_AO_ON_NETWORK')) {
127 127
             self::maybe_include_plugin_functions();
128
-            if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) || is_plugin_active_for_network( 'autoptimize-beta/autoptimize.php' ) || defined( 'TEST_MULTISITE_FORCE_AO_ON_NETWORK' ) ) {
128
+            if (is_plugin_active_for_network('autoptimize/autoptimize.php') || is_plugin_active_for_network('autoptimize-beta/autoptimize.php') || defined('TEST_MULTISITE_FORCE_AO_ON_NETWORK')) {
129 129
                 $_is_ao_active_for_network = true;
130 130
             } else {
131 131
                 $_is_ao_active_for_network = false;
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSCore.php 2 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -335,6 +335,9 @@  discard block
 block discarded – undo
335 335
         }
336 336
     }
337 337
 
338
+    /**
339
+     * @param boolean $render
340
+     */
338 341
     public static function ao_ccss_key_status( $render ) {
339 342
         // Provide key status
340 343
         // Get key and key status.
@@ -539,6 +542,9 @@  discard block
 block discarded – undo
539 542
         return true;
540 543
     }
541 544
 
545
+    /**
546
+     * @param integer $lvl
547
+     */
542 548
     public static function ao_ccss_log( $msg, $lvl ) {
543 549
         // Commom logging facility
544 550
         // Attach debug option.
Please login to merge, or discard this patch.
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * gets called by AO core, checks the rules and if a matching rule is found returns the associated CCSS.
5 5
  */
6 6
 
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
     exit;
9 9
 }
10 10
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
     {
14 14
         // fetch all options at once and populate them individually explicitely as globals.
15 15
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
16
-        foreach ( $all_options as $_option => $_value ) {
16
+        foreach ($all_options as $_option => $_value) {
17 17
             global ${$_option};
18 18
             ${$_option} = $_value;
19 19
         }
@@ -27,23 +27,23 @@  discard block
 block discarded – undo
27 27
         global $ao_ccss_key;
28 28
 
29 29
         // add all filters to do CCSS if key present.
30
-        if ( $ao_css_defer && isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) ) {
30
+        if ($ao_css_defer && isset($ao_ccss_key) && !empty($ao_ccss_key)) {
31 31
             // Set AO behavior: disable minification to avoid double minifying and caching.
32
-            add_filter( 'autoptimize_filter_css_critcss_minify', '__return_false' );
33
-            add_filter( 'autoptimize_filter_css_defer_inline', array( $this, 'ao_ccss_frontend' ), 10, 1 );
32
+            add_filter('autoptimize_filter_css_critcss_minify', '__return_false');
33
+            add_filter('autoptimize_filter_css_defer_inline', array($this, 'ao_ccss_frontend'), 10, 1);
34 34
 
35 35
             // Add the action to enqueue jobs for CriticalCSS cron.
36
-            add_action( 'autoptimize_action_css_hash', array( 'autoptimizeCriticalCSSEnqueue', 'ao_ccss_enqueue' ), 10, 1 );
36
+            add_action('autoptimize_action_css_hash', array('autoptimizeCriticalCSSEnqueue', 'ao_ccss_enqueue'), 10, 1);
37 37
 
38 38
             // conditionally add the filter to defer jquery and others.
39
-            if ( $ao_ccss_deferjquery ) {
40
-                add_filter( 'autoptimize_html_after_minify', array( $this, 'ao_ccss_defer_jquery' ), 11, 1 );
39
+            if ($ao_ccss_deferjquery) {
40
+                add_filter('autoptimize_html_after_minify', array($this, 'ao_ccss_defer_jquery'), 11, 1);
41 41
             }
42 42
 
43 43
             // Order paths by length, as longest ones have greater priority in the rules.
44
-            if ( ! empty( $ao_ccss_rules['paths'] ) ) {
45
-                $keys = array_map( 'strlen', array_keys( $ao_ccss_rules['paths'] ) );
46
-                array_multisort( $keys, SORT_DESC, $ao_ccss_rules['paths'] );
44
+            if (!empty($ao_ccss_rules['paths'])) {
45
+                $keys = array_map('strlen', array_keys($ao_ccss_rules['paths']));
46
+                array_multisort($keys, SORT_DESC, $ao_ccss_rules['paths']);
47 47
             }
48 48
 
49 49
             // Add an array with default WordPress's conditional tags
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
             $ao_ccss_types = $this->get_ao_ccss_core_types();
53 53
 
54 54
             // Extend conditional tags on plugin initalization.
55
-            add_action( apply_filters( 'autoptimize_filter_ccss_extend_types_hook', 'init' ), array( $this, 'ao_ccss_extend_types' ) );
55
+            add_action(apply_filters('autoptimize_filter_ccss_extend_types_hook', 'init'), array($this, 'ao_ccss_extend_types'));
56 56
         }
57 57
     }
58 58
 
59
-    public function ao_ccss_frontend( $inlined ) {
59
+    public function ao_ccss_frontend($inlined) {
60 60
         // Apply CriticalCSS to frontend pages
61 61
         // Attach types and settings arrays.
62 62
         global $ao_ccss_types;
@@ -68,20 +68,20 @@  discard block
 block discarded – undo
68 68
         $no_ccss = '';
69 69
 
70 70
         // Only if keystatus is OK and option to add CCSS for logged on users is on or user is not logged in.
71
-        if ( ( $ao_ccss_keyst && 2 == $ao_ccss_keyst ) && ( $ao_ccss_loggedin || ! is_user_logged_in() ) ) {
71
+        if (($ao_ccss_keyst && 2 == $ao_ccss_keyst) && ($ao_ccss_loggedin || !is_user_logged_in())) {
72 72
             // Check for a valid CriticalCSS based on path to return its contents.
73
-            $req_path = strtok( $_SERVER['REQUEST_URI'], '?' );
74
-            if ( ! empty( $ao_ccss_rules['paths'] ) ) {
75
-                foreach ( $ao_ccss_rules['paths'] as $path => $rule ) {
73
+            $req_path = strtok($_SERVER['REQUEST_URI'], '?');
74
+            if (!empty($ao_ccss_rules['paths'])) {
75
+                foreach ($ao_ccss_rules['paths'] as $path => $rule) {
76 76
                     // explicit match OR partial match if MANUAL rule.
77
-                    if ( $req_path == $path || urldecode( $req_path ) == $path || ( false == $rule['hash'] && false != $rule['file'] && strpos( $req_path, str_replace( site_url(), '', $path ) ) !== false ) ) {
78
-                        if ( file_exists( AO_CCSS_DIR . $rule['file'] ) ) {
79
-                            $_ccss_contents = file_get_contents( AO_CCSS_DIR . $rule['file'] );
80
-                            if ( 'none' != $_ccss_contents ) {
81
-                                if ( $ao_ccss_debug ) {
82
-                                    $_ccss_contents = '/* PATH: ' . $path . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
77
+                    if ($req_path == $path || urldecode($req_path) == $path || (false == $rule['hash'] && false != $rule['file'] && strpos($req_path, str_replace(site_url(), '', $path)) !== false)) {
78
+                        if (file_exists(AO_CCSS_DIR.$rule['file'])) {
79
+                            $_ccss_contents = file_get_contents(AO_CCSS_DIR.$rule['file']);
80
+                            if ('none' != $_ccss_contents) {
81
+                                if ($ao_ccss_debug) {
82
+                                    $_ccss_contents = '/* PATH: '.$path.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
83 83
                                 }
84
-                                return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
84
+                                return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
85 85
                             } else {
86 86
                                 $no_ccss = 'none';
87 87
                             }
@@ -91,55 +91,55 @@  discard block
 block discarded – undo
91 91
             }
92 92
 
93 93
             // Check for a valid CriticalCSS based on conditional tags to return its contents.
94
-            if ( ! empty( $ao_ccss_rules['types'] ) && 'none' !== $no_ccss ) {
94
+            if (!empty($ao_ccss_rules['types']) && 'none' !== $no_ccss) {
95 95
                 // order types-rules by the order of the original $ao_ccss_types array so as not to depend on the order in which rules were added.
96
-                $ao_ccss_rules['types'] = array_replace( array_intersect_key( array_flip( $ao_ccss_types ), $ao_ccss_rules['types'] ), $ao_ccss_rules['types'] );
96
+                $ao_ccss_rules['types'] = array_replace(array_intersect_key(array_flip($ao_ccss_types), $ao_ccss_rules['types']), $ao_ccss_rules['types']);
97 97
                 $is_front_page          = is_front_page();
98 98
 
99
-                foreach ( $ao_ccss_rules['types'] as $type => $rule ) {
100
-                    if ( in_array( $type, $ao_ccss_types ) && file_exists( AO_CCSS_DIR . $rule['file'] ) ) {
101
-                        $_ccss_contents = file_get_contents( AO_CCSS_DIR . $rule['file'] );
102
-                        if ( $is_front_page && 'is_front_page' == $type ) {
103
-                            if ( 'none' != $_ccss_contents ) {
104
-                                if ( $ao_ccss_debug ) {
105
-                                    $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
99
+                foreach ($ao_ccss_rules['types'] as $type => $rule) {
100
+                    if (in_array($type, $ao_ccss_types) && file_exists(AO_CCSS_DIR.$rule['file'])) {
101
+                        $_ccss_contents = file_get_contents(AO_CCSS_DIR.$rule['file']);
102
+                        if ($is_front_page && 'is_front_page' == $type) {
103
+                            if ('none' != $_ccss_contents) {
104
+                                if ($ao_ccss_debug) {
105
+                                    $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
106 106
                                 }
107
-                                return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
107
+                                return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
108 108
                             } else {
109 109
                                 $no_ccss = 'none';
110 110
                             }
111
-                        } elseif ( strpos( $type, 'custom_post_' ) === 0 && ! $is_front_page ) {
112
-                            if ( get_post_type( get_the_ID() ) === substr( $type, 12 ) ) {
113
-                                if ( 'none' != $_ccss_contents ) {
114
-                                    if ( $ao_ccss_debug ) {
115
-                                        $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
111
+                        } elseif (strpos($type, 'custom_post_') === 0 && !$is_front_page) {
112
+                            if (get_post_type(get_the_ID()) === substr($type, 12)) {
113
+                                if ('none' != $_ccss_contents) {
114
+                                    if ($ao_ccss_debug) {
115
+                                        $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
116 116
                                     }
117
-                                    return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
117
+                                    return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
118 118
                                 } else {
119 119
                                     $no_ccss = 'none';
120 120
                                 }
121 121
                             }
122
-                        } elseif ( 0 === strpos( $type, 'template_' ) && ! $is_front_page ) {
123
-                            if ( is_page_template( substr( $type, 9 ) ) ) {
124
-                                if ( 'none' != $_ccss_contents ) {
125
-                                    if ( $ao_ccss_debug ) {
126
-                                        $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
122
+                        } elseif (0 === strpos($type, 'template_') && !$is_front_page) {
123
+                            if (is_page_template(substr($type, 9))) {
124
+                                if ('none' != $_ccss_contents) {
125
+                                    if ($ao_ccss_debug) {
126
+                                        $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
127 127
                                     }
128
-                                    return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
128
+                                    return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
129 129
                                 } else {
130 130
                                     $no_ccss = 'none';
131 131
                                 }
132 132
                             }
133
-                        } elseif ( ! $is_front_page ) {
133
+                        } elseif (!$is_front_page) {
134 134
                             // all "normal" conditional tags, core + woo + buddypress + edd + bbpress
135 135
                             // but we have to remove the prefix for the non-core ones for them to function.
136
-                            $type = str_replace( array( 'woo_', 'bp_', 'bbp_', 'edd_' ), '', $type );
137
-                            if ( function_exists( $type ) && call_user_func( $type ) ) {
138
-                                if ( 'none' != $_ccss_contents ) {
139
-                                    if ( $ao_ccss_debug ) {
140
-                                        $_ccss_contents = '/* TYPES: ' . $type . ' hash: ' . $rule['hash'] . ' file: ' . $rule['file'] . ' */ ' . $_ccss_contents;
136
+                            $type = str_replace(array('woo_', 'bp_', 'bbp_', 'edd_'), '', $type);
137
+                            if (function_exists($type) && call_user_func($type)) {
138
+                                if ('none' != $_ccss_contents) {
139
+                                    if ($ao_ccss_debug) {
140
+                                        $_ccss_contents = '/* TYPES: '.$type.' hash: '.$rule['hash'].' file: '.$rule['file'].' */ '.$_ccss_contents;
141 141
                                     }
142
-                                    return apply_filters( 'autoptimize_filter_ccss_core_ccss', $_ccss_contents . $ao_ccss_additional );
142
+                                    return apply_filters('autoptimize_filter_ccss_core_ccss', $_ccss_contents.$ao_ccss_additional);
143 143
                                 } else {
144 144
                                     $no_ccss = 'none';
145 145
                                 }
@@ -152,26 +152,26 @@  discard block
 block discarded – undo
152 152
 
153 153
         // Finally, inline the default CriticalCSS if any or else the entire CSS for the page
154 154
         // This also applies to logged in users if the option to add CCSS for logged in users has been disabled.
155
-        if ( ! empty( $inlined ) && 'none' !== $no_ccss ) {
156
-            return apply_filters( 'autoptimize_filter_ccss_core_ccss', $inlined . $ao_ccss_additional );
155
+        if (!empty($inlined) && 'none' !== $no_ccss) {
156
+            return apply_filters('autoptimize_filter_ccss_core_ccss', $inlined.$ao_ccss_additional);
157 157
         } else {
158
-            add_filter( 'autoptimize_filter_css_inline', '__return_true' );
158
+            add_filter('autoptimize_filter_css_inline', '__return_true');
159 159
             return;
160 160
         }
161 161
     }
162 162
 
163
-    public function ao_ccss_defer_jquery( $in ) {
163
+    public function ao_ccss_defer_jquery($in) {
164 164
         // try to defer all JS (main goal being jquery.js as AO by default does not aggregate that).
165
-        if ( ( ! is_user_logged_in() || $ao_ccss_loggedin ) && preg_match_all( '#<script.*>(.*)</script>#Usmi', $in, $matches, PREG_SET_ORDER ) ) {
166
-            foreach ( $matches as $match ) {
167
-                if ( ( ! preg_match( '/<script.* type\s?=.*>/', $match[0] ) || preg_match( '/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $match[0] ) ) && '' !== $match[1] && ( false !== strpos( $match[1], 'jQuery' ) || false !== strpos( $match[1], '$' ) ) ) {
165
+        if ((!is_user_logged_in() || $ao_ccss_loggedin) && preg_match_all('#<script.*>(.*)</script>#Usmi', $in, $matches, PREG_SET_ORDER)) {
166
+            foreach ($matches as $match) {
167
+                if ((!preg_match('/<script.* type\s?=.*>/', $match[0]) || preg_match('/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $match[0])) && '' !== $match[1] && (false !== strpos($match[1], 'jQuery') || false !== strpos($match[1], '$'))) {
168 168
                     // inline js that requires jquery, wrap deferring JS around it to defer it.
169
-                    $new_match = 'var aoDeferInlineJQuery=function(){' . $match[1] . '}; if (document.readyState === "loading") {document.addEventListener("DOMContentLoaded", aoDeferInlineJQuery);} else {aoDeferInlineJQuery();}';
170
-                    $in        = str_replace( $match[1], $new_match, $in );
171
-                } elseif ( '' === $match[1] && false !== strpos( $match[0], 'src=' ) && false === strpos( $match[0], 'defer' ) ) {
169
+                    $new_match = 'var aoDeferInlineJQuery=function(){'.$match[1].'}; if (document.readyState === "loading") {document.addEventListener("DOMContentLoaded", aoDeferInlineJQuery);} else {aoDeferInlineJQuery();}';
170
+                    $in        = str_replace($match[1], $new_match, $in);
171
+                } elseif ('' === $match[1] && false !== strpos($match[0], 'src=') && false === strpos($match[0], 'defer')) {
172 172
                     // linked non-aggregated JS, defer it.
173
-                    $new_match = str_replace( '<script ', '<script defer ', $match[0] );
174
-                    $in        = str_replace( $match[0], $new_match, $in );
173
+                    $new_match = str_replace('<script ', '<script defer ', $match[0]);
174
+                    $in        = str_replace($match[0], $new_match, $in);
175 175
                 }
176 176
             }
177 177
         }
@@ -184,9 +184,9 @@  discard block
 block discarded – undo
184 184
         global $ao_ccss_types;
185 185
 
186 186
         // in some cases $ao_ccss_types is empty and/or not an array, this should work around that problem.
187
-        if ( empty( $ao_ccss_types ) || ! is_array( $ao_ccss_types ) ) {
187
+        if (empty($ao_ccss_types) || !is_array($ao_ccss_types)) {
188 188
             $ao_ccss_types = get_ao_ccss_core_types();
189
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Empty types array in extend, refetching array with core conditionals.', 3 );
189
+            autoptimizeCriticalCSSCore::ao_ccss_log('Empty types array in extend, refetching array with core conditionals.', 3);
190 190
         }
191 191
 
192 192
         // Custom Post Types.
@@ -198,18 +198,18 @@  discard block
 block discarded – undo
198 198
             'names',
199 199
             'and'
200 200
         );
201
-        foreach ( $cpts as $cpt ) {
202
-            array_unshift( $ao_ccss_types, 'custom_post_' . $cpt );
201
+        foreach ($cpts as $cpt) {
202
+            array_unshift($ao_ccss_types, 'custom_post_'.$cpt);
203 203
         }
204 204
 
205 205
         // Templates.
206 206
         $templates = wp_get_theme()->get_page_templates();
207
-        foreach ( $templates as $tplfile => $tplname ) {
208
-            array_unshift( $ao_ccss_types, 'template_' . $tplfile );
207
+        foreach ($templates as $tplfile => $tplname) {
208
+            array_unshift($ao_ccss_types, 'template_'.$tplfile);
209 209
         }
210 210
 
211 211
         // bbPress tags.
212
-        if ( function_exists( 'is_bbpress' ) ) {
212
+        if (function_exists('is_bbpress')) {
213 213
             $ao_ccss_types = array_merge(
214 214
                 array(
215 215
                     'bbp_is_bbpress',
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         }
242 242
 
243 243
         // BuddyPress tags.
244
-        if ( function_exists( 'is_buddypress' ) ) {
244
+        if (function_exists('is_buddypress')) {
245 245
             $ao_ccss_types = array_merge(
246 246
                 array(
247 247
                     'bp_is_activation_page',
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
         }
284 284
 
285 285
         // Easy Digital Downloads (EDD) tags.
286
-        if ( function_exists( 'edd_is_checkout' ) ) {
286
+        if (function_exists('edd_is_checkout')) {
287 287
             $ao_ccss_types = array_merge(
288 288
                 array(
289 289
                     'edd_is_checkout',
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
         }
296 296
 
297 297
         // WooCommerce tags.
298
-        if ( class_exists( 'WooCommerce' ) ) {
298
+        if (class_exists('WooCommerce')) {
299 299
             $ao_ccss_types = array_merge(
300 300
                 array(
301 301
                     'woo_is_account_page',
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 
315 315
     public function get_ao_ccss_core_types() {
316 316
         global $ao_ccss_types;
317
-        if ( empty( $ao_ccss_types ) || ! is_array( $ao_ccss_types ) ) {
317
+        if (empty($ao_ccss_types) || !is_array($ao_ccss_types)) {
318 318
             return array(
319 319
                 'is_404',
320 320
                 'is_archive',
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
         }
336 336
     }
337 337
 
338
-    public static function ao_ccss_key_status( $render ) {
338
+    public static function ao_ccss_key_status($render) {
339 339
         // Provide key status
340 340
         // Get key and key status.
341 341
         global $ao_ccss_key;
@@ -348,55 +348,55 @@  discard block
 block discarded – undo
348 348
         $key_return = array();
349 349
         $status     = false;
350 350
 
351
-        if ( $key && 2 == $key_status ) {
351
+        if ($key && 2 == $key_status) {
352 352
             // Key exists and its status is valid.
353 353
             // Set valid key status.
354 354
             $status     = 'valid';
355
-            $status_msg = __( 'Valid' );
355
+            $status_msg = __('Valid');
356 356
             $color      = '#46b450'; // Green.
357 357
             $message    = null;
358
-        } elseif ( $key && 1 == $key_status ) {
358
+        } elseif ($key && 1 == $key_status) {
359 359
             // Key exists but its validation has failed.
360 360
             // Set invalid key status.
361 361
             $status     = 'invalid';
362
-            $status_msg = __( 'Invalid' );
362
+            $status_msg = __('Invalid');
363 363
             $color      = '#dc3232'; // Red.
364
-            $message    = __( 'Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize' );
365
-        } elseif ( $key && ! $key_status ) {
364
+            $message    = __('Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize');
365
+        } elseif ($key && !$key_status) {
366 366
             // Key exists but it has no valid status yet
367 367
             // Perform key validation.
368
-            $key_check = $self->ao_ccss_key_validation( $key );
368
+            $key_check = $self->ao_ccss_key_validation($key);
369 369
 
370 370
             // Key is valid, set valid status.
371
-            if ( $key_check ) {
371
+            if ($key_check) {
372 372
                 $status     = 'valid';
373
-                $status_msg = __( 'Valid' );
373
+                $status_msg = __('Valid');
374 374
                 $color      = '#46b450'; // Green.
375 375
                 $message    = null;
376 376
             } else {
377 377
                 // Key is invalid, set invalid status.
378 378
                 $status     = 'invalid';
379
-                $status_msg = __( 'Invalid' );
379
+                $status_msg = __('Invalid');
380 380
                 $color      = '#dc3232'; // Red.
381
-                if ( get_option( 'autoptimize_ccss_keyst' ) == 1 ) {
382
-                    $message = __( 'Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize' );
381
+                if (get_option('autoptimize_ccss_keyst') == 1) {
382
+                    $message = __('Your API key is invalid. Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> key.', 'autoptimize');
383 383
                 } else {
384
-                    $message = __( 'Something went wrong when checking your API key, make sure you server can communicate with https://criticalcss.com and/ or try again later.', 'autoptimize' );
384
+                    $message = __('Something went wrong when checking your API key, make sure you server can communicate with https://criticalcss.com and/ or try again later.', 'autoptimize');
385 385
                 }
386 386
             }
387 387
         } else {
388 388
             // No key nor status
389 389
             // Set no key status.
390 390
             $status     = 'nokey';
391
-            $status_msg = __( 'None' );
391
+            $status_msg = __('None');
392 392
             $color      = '#ffb900'; // Yellow.
393
-            $message    = __( 'Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key to start.', 'autoptimize' );
393
+            $message    = __('Please enter a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key to start.', 'autoptimize');
394 394
         }
395 395
 
396 396
         // Fill returned values.
397 397
         $key_return['status'] = $status;
398 398
         // Provide rendering information if required.
399
-        if ( $render ) {
399
+        if ($render) {
400 400
             $key_return['stmsg'] = $status_msg;
401 401
             $key_return['color'] = $color;
402 402
             $key_return['msg']   = $message;
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
         return $key_return;
407 407
     }
408 408
 
409
-    public function ao_ccss_key_validation( $key ) {
409
+    public function ao_ccss_key_validation($key) {
410 410
         global $ao_ccss_noptimize;
411 411
 
412 412
         // POST a dummy job to criticalcss.com to check for key validation
@@ -414,26 +414,26 @@  discard block
 block discarded – undo
414 414
         $src_url = get_home_url();
415 415
 
416 416
         // Avoid AO optimizations if required by config or avoid lazyload if lazyload is active in AO.
417
-        if ( ! empty( $ao_ccss_noptimize ) ) {
417
+        if (!empty($ao_ccss_noptimize)) {
418 418
             $src_url .= '?ao_noptirocket=1';
419
-        } elseif ( class_exists( 'autoptimizeImages', false ) && autoptimizeImages::should_lazyload_wrapper() ) {
419
+        } elseif (class_exists('autoptimizeImages', false) && autoptimizeImages::should_lazyload_wrapper()) {
420 420
             $src_url .= '?ao_nolazy=1';
421 421
         }
422 422
 
423
-        $src_url = apply_filters( 'autoptimize_filter_ccss_cron_srcurl', $src_url );
423
+        $src_url = apply_filters('autoptimize_filter_ccss_cron_srcurl', $src_url);
424 424
 
425 425
         // Prepare the request.
426
-        $url  = esc_url_raw( AO_CCSS_API . 'generate' );
426
+        $url  = esc_url_raw(AO_CCSS_API.'generate');
427 427
         $args = array(
428 428
             'headers' => array(
429
-                'User-Agent'    => 'Autoptimize v' . AO_CCSS_VER,
429
+                'User-Agent'    => 'Autoptimize v'.AO_CCSS_VER,
430 430
                 'Content-type'  => 'application/json; charset=utf-8',
431
-                'Authorization' => 'JWT ' . $key,
431
+                'Authorization' => 'JWT '.$key,
432 432
                 'Connection'    => 'close',
433 433
             ),
434 434
             // Body must be JSON.
435 435
             'body'    => json_encode(
436
-                apply_filters( 'autoptimize_ccss_cron_api_generate_body',
436
+                apply_filters('autoptimize_ccss_cron_api_generate_body',
437 437
                     array(
438 438
                         'url'    => $src_url,
439 439
                         'aff'    => 1,
@@ -444,23 +444,23 @@  discard block
 block discarded – undo
444 444
         );
445 445
 
446 446
         // Dispatch the request and store its response code.
447
-        $req  = wp_safe_remote_post( $url, $args );
448
-        $code = wp_remote_retrieve_response_code( $req );
449
-        $body = json_decode( wp_remote_retrieve_body( $req ), true );
447
+        $req  = wp_safe_remote_post($url, $args);
448
+        $code = wp_remote_retrieve_response_code($req);
449
+        $body = json_decode(wp_remote_retrieve_body($req), true);
450 450
 
451
-        if ( 200 == $code ) {
451
+        if (200 == $code) {
452 452
             // Response is OK.
453 453
             // Set key status as valid and log key check.
454
-            update_option( 'autoptimize_ccss_keyst', 2 );
455
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is valid, updating key status', 3 );
454
+            update_option('autoptimize_ccss_keyst', 2);
455
+            autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is valid, updating key status', 3);
456 456
 
457 457
             // extract job-id from $body and put it in the queue as a P job
458 458
             // but only if no jobs and no rules!
459 459
             global $ao_ccss_queue;
460 460
             global $ao_ccss_rules;
461 461
 
462
-            if ( 0 == count( $ao_ccss_queue ) && 0 == count( $ao_ccss_rules['types'] ) && 0 == count( $ao_ccss_rules['paths'] ) ) {
463
-                if ( 'JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] ) {
462
+            if (0 == count($ao_ccss_queue) && 0 == count($ao_ccss_rules['types']) && 0 == count($ao_ccss_rules['paths'])) {
463
+                if ('JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status']) {
464 464
                     $jprops['ljid']     = 'firstrun';
465 465
                     $jprops['rtarget']  = 'types|is_front_page';
466 466
                     $jprops['ptype']    = 'is_front_page';
@@ -471,30 +471,30 @@  discard block
 block discarded – undo
471 471
                     $jprops['jqstat']   = $body['job']['status'];
472 472
                     $jprops['jrstat']   = null;
473 473
                     $jprops['jvstat']   = null;
474
-                    $jprops['jctime']   = microtime( true );
474
+                    $jprops['jctime']   = microtime(true);
475 475
                     $jprops['jftime']   = null;
476 476
                     $ao_ccss_queue['/'] = $jprops;
477
-                    $ao_ccss_queue_raw  = json_encode( $ao_ccss_queue );
478
-                    update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
479
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Created P job for is_front_page based on API key check response.', 3 );
477
+                    $ao_ccss_queue_raw  = json_encode($ao_ccss_queue);
478
+                    update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
479
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Created P job for is_front_page based on API key check response.', 3);
480 480
                 }
481 481
             }
482 482
             return true;
483
-        } elseif ( 401 == $code ) {
483
+        } elseif (401 == $code) {
484 484
             // Response is unauthorized
485 485
             // Set key status as invalid and log key check.
486
-            update_option( 'autoptimize_ccss_keyst', 1 );
487
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 );
486
+            update_option('autoptimize_ccss_keyst', 1);
487
+            autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3);
488 488
             return false;
489 489
         } else {
490 490
             // Response unkown
491 491
             // Log key check attempt.
492
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: could not check API key status, this is a service error, body follows if any...', 2 );
493
-            if ( ! empty( $body ) ) {
494
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
492
+            autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: could not check API key status, this is a service error, body follows if any...', 2);
493
+            if (!empty($body)) {
494
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
495 495
             }
496
-            if ( is_wp_error( $req ) ) {
497
-                autoptimizeCriticalCSSCore::ao_ccss_log( $req->get_error_message(), 2 );
496
+            if (is_wp_error($req)) {
497
+                autoptimizeCriticalCSSCore::ao_ccss_log($req->get_error_message(), 2);
498 498
             }
499 499
             return false;
500 500
         }
@@ -509,14 +509,14 @@  discard block
 block discarded – undo
509 509
         $viewport = array();
510 510
 
511 511
         // Viewport Width.
512
-        if ( ! empty( $ao_ccss_viewport['w'] ) ) {
512
+        if (!empty($ao_ccss_viewport['w'])) {
513 513
             $viewport['w'] = $ao_ccss_viewport['w'];
514 514
         } else {
515 515
             $viewport['w'] = '';
516 516
         }
517 517
 
518 518
         // Viewport Height.
519
-        if ( ! empty( $ao_ccss_viewport['h'] ) ) {
519
+        if (!empty($ao_ccss_viewport['h'])) {
520 520
             $viewport['h'] = $ao_ccss_viewport['h'];
521 521
         } else {
522 522
             $viewport['h'] = '';
@@ -525,23 +525,23 @@  discard block
 block discarded – undo
525 525
         return $viewport;
526 526
     }
527 527
 
528
-    public static function ao_ccss_check_contents( $ccss ) {
528
+    public static function ao_ccss_check_contents($ccss) {
529 529
         // Perform basic exploit avoidance and CSS validation.
530
-        if ( ! empty( $ccss ) ) {
530
+        if (!empty($ccss)) {
531 531
             // Try to avoid code injection.
532
-            $blacklist = array( '#!/', 'function(', '<script', '<?php' );
533
-            foreach ( $blacklist as $blacklisted ) {
534
-                if ( strpos( $ccss, $blacklisted ) !== false ) {
535
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received contained blacklisted content.', 2 );
532
+            $blacklist = array('#!/', 'function(', '<script', '<?php');
533
+            foreach ($blacklist as $blacklisted) {
534
+                if (strpos($ccss, $blacklisted) !== false) {
535
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received contained blacklisted content.', 2);
536 536
                     return false;
537 537
                 }
538 538
             }
539 539
 
540 540
             // Check for most basics CSS structures.
541
-            $pinklist = array( '{', '}', ':' );
542
-            foreach ( $pinklist as $needed ) {
543
-                if ( false === strpos( $ccss, $needed ) && 'none' !== $ccss ) {
544
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received did not seem to contain real CSS.', 2 );
541
+            $pinklist = array('{', '}', ':');
542
+            foreach ($pinklist as $needed) {
543
+                if (false === strpos($ccss, $needed) && 'none' !== $ccss) {
544
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received did not seem to contain real CSS.', 2);
545 545
                     return false;
546 546
                 }
547 547
             }
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
         return true;
552 552
     }
553 553
 
554
-    public static function ao_ccss_log( $msg, $lvl ) {
554
+    public static function ao_ccss_log($msg, $lvl) {
555 555
         // Commom logging facility
556 556
         // Attach debug option.
557 557
         global $ao_ccss_debug;
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
         // 3: DD (for debug)
563 563
         // Default: UU (for unkown).
564 564
         $level = false;
565
-        switch ( $lvl ) {
565
+        switch ($lvl) {
566 566
             case 1:
567 567
                 $level = 'II';
568 568
                 break;
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
                 break;
572 572
             case 3:
573 573
                 // Output debug messages only if debug mode is enabled.
574
-                if ( $ao_ccss_debug ) {
574
+                if ($ao_ccss_debug) {
575 575
                     $level = 'DD';
576 576
                 }
577 577
                 break;
@@ -580,13 +580,13 @@  discard block
 block discarded – undo
580 580
         }
581 581
 
582 582
         // Prepare and write a log message if there's a valid level.
583
-        if ( $level ) {
583
+        if ($level) {
584 584
 
585 585
             // Prepare message.
586
-            $message = date( 'c' ) . ' - [' . $level . '] ' . htmlentities( $msg ) . '<br>';
586
+            $message = date('c').' - ['.$level.'] '.htmlentities($msg).'<br>';
587 587
 
588 588
             // Write message to log file.
589
-            error_log( $message, 3, AO_CCSS_LOG );
589
+            error_log($message, 3, AO_CCSS_LOG);
590 590
         }
591 591
     }
592 592
 }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSCron.php 2 patches
Doc Comments   +9 added lines patch added patch discarded remove patch
@@ -423,6 +423,9 @@  discard block
 block discarded – undo
423 423
         }
424 424
     }
425 425
 
426
+    /**
427
+     * @param boolean|string $debug
428
+     */
426 429
     public function ao_ccss_api_generate( $path, $debug, $dcode ) {
427 430
         // POST jobs to criticalcss.com and return responses
428 431
         // Get key and key status.
@@ -559,6 +562,9 @@  discard block
 block discarded – undo
559 562
         }
560 563
     }
561 564
 
565
+    /**
566
+     * @param boolean $debug
567
+     */
562 568
     public function ao_ccss_api_results( $jobid, $debug, $dcode ) {
563 569
         // GET jobs from criticalcss.com and return responses
564 570
         // Get key.
@@ -625,6 +631,9 @@  discard block
 block discarded – undo
625 631
         }
626 632
     }
627 633
 
634
+    /**
635
+     * @param boolean $review
636
+     */
628 637
     public function ao_ccss_save_file( $ccss, $target, $review ) {
629 638
         // Save critical CSS into the filesystem and return its filename
630 639
         // Prepare review mark.
Please login to merge, or discard this patch.
Spacing   +254 added lines, -254 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * processes the queue, submitting jobs to criticalcss.com and retrieving generated CSS from criticalcss.com and saving rules.
5 5
  */
6 6
 
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
     exit;
9 9
 }
10 10
 
@@ -13,23 +13,23 @@  discard block
 block discarded – undo
13 13
     {
14 14
         // fetch all options at once and populate them individually explicitely as globals.
15 15
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
16
-        foreach ( $all_options as $_option => $_value ) {
16
+        foreach ($all_options as $_option => $_value) {
17 17
             global ${$_option};
18 18
             ${$_option} = $_value;
19 19
         }
20 20
 
21 21
         // Add queue control to a registered event.
22
-        add_action( 'ao_ccss_queue', array( $this, 'ao_ccss_queue_control' ) );
22
+        add_action('ao_ccss_queue', array($this, 'ao_ccss_queue_control'));
23 23
         // Add cleaning job to a registered event.
24
-        add_action( 'ao_ccss_maintenance', array( $this, 'ao_ccss_cleaning' ) );
24
+        add_action('ao_ccss_maintenance', array($this, 'ao_ccss_cleaning'));
25 25
     }
26 26
 
27 27
     public function ao_ccss_queue_control() {
28 28
         // The queue execution backend.
29 29
         global $ao_ccss_key;
30
-        if ( ! isset( $ao_ccss_key ) || empty( $ao_ccss_key ) ) {
30
+        if (!isset($ao_ccss_key) || empty($ao_ccss_key)) {
31 31
             // no key set, not processing the queue!
32
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'No key set, so not processing queue.', 3 );
32
+            autoptimizeCriticalCSSCore::ao_ccss_log('No key set, so not processing queue.', 3);
33 33
             return;
34 34
         }
35 35
 
@@ -50,35 +50,35 @@  discard block
 block discarded – undo
50 50
          *    When properly set, queue will always finish a job with the declared settings above regardless of the real API responses.
51 51
          */
52 52
         $queue_debug = false;
53
-        if ( file_exists( AO_CCSS_DEBUG ) ) {
54
-            $qdobj_raw = file_get_contents( AO_CCSS_DEBUG );
55
-            $qdobj     = json_decode( $qdobj_raw, true );
56
-            if ( $qdobj ) {
57
-                if ( 1 === $qdobj['enable'] ) {
53
+        if (file_exists(AO_CCSS_DEBUG)) {
54
+            $qdobj_raw = file_get_contents(AO_CCSS_DEBUG);
55
+            $qdobj     = json_decode($qdobj_raw, true);
56
+            if ($qdobj) {
57
+                if (1 === $qdobj['enable']) {
58 58
                     $queue_debug = true;
59
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue operating in debug mode with the following settings: <' . $qdobj_raw . '>', 3 );
59
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Queue operating in debug mode with the following settings: <'.$qdobj_raw.'>', 3);
60 60
                 }
61 61
             }
62 62
         }
63 63
 
64 64
         // Set some default values for $qdobj to avoid function call warnings.
65
-        if ( ! $queue_debug ) {
65
+        if (!$queue_debug) {
66 66
             $qdobj['htcode'] = false;
67 67
         }
68 68
 
69 69
         // Check if queue is already running.
70 70
         $queue_lock = false;
71
-        if ( file_exists( AO_CCSS_LOCK ) ) {
71
+        if (file_exists(AO_CCSS_LOCK)) {
72 72
             $queue_lock = true;
73 73
         }
74 74
 
75 75
         // Proceed with the queue if it's not already running.
76
-        if ( ! $queue_lock ) {
76
+        if (!$queue_lock) {
77 77
 
78 78
             // Log queue start and create the lock file.
79
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control started', 3 );
80
-            if ( touch( AO_CCSS_LOCK ) ) {
81
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control locked', 3 );
79
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue control started', 3);
80
+            if (touch(AO_CCSS_LOCK)) {
81
+                autoptimizeCriticalCSSCore::ao_ccss_log('Queue control locked', 3);
82 82
             }
83 83
 
84 84
             // Attach required variables.
@@ -88,218 +88,218 @@  discard block
 block discarded – undo
88 88
             // Initialize job counters.
89 89
             $jc = 1;
90 90
             $jr = 1;
91
-            $jt = count( $ao_ccss_queue );
91
+            $jt = count($ao_ccss_queue);
92 92
 
93 93
             // Sort queue by ascending job status (e.g. ERROR, JOB_ONGOING, JOB_QUEUED, NEW...).
94
-            array_multisort( array_column( $ao_ccss_queue, 'jqstat' ), $ao_ccss_queue ); // @codingStandardsIgnoreLine
94
+            array_multisort(array_column($ao_ccss_queue, 'jqstat'), $ao_ccss_queue); // @codingStandardsIgnoreLine
95 95
 
96 96
             // Iterates over the entire queue.
97
-            foreach ( $ao_ccss_queue as $path => $jprops ) {
97
+            foreach ($ao_ccss_queue as $path => $jprops) {
98 98
                 // Prepare flags and target rule.
99 99
                 $update      = false;
100 100
                 $deljob      = false;
101 101
                 $rule_update = false;
102 102
                 $oldccssfile = false;
103
-                $trule       = explode( '|', $jprops['rtarget'] );
103
+                $trule       = explode('|', $jprops['rtarget']);
104 104
 
105 105
                 // Log job count.
106
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Processing job ' . $jc . ' of ' . $jt . ' with id <' . $jprops['ljid'] . '> and status <' . $jprops['jqstat'] . '>', 3 );
106
+                autoptimizeCriticalCSSCore::ao_ccss_log('Processing job '.$jc.' of '.$jt.' with id <'.$jprops['ljid'].'> and status <'.$jprops['jqstat'].'>', 3);
107 107
 
108 108
                 // Process NEW jobs.
109
-                if ( 'NEW' == $jprops['jqstat'] ) {
109
+                if ('NEW' == $jprops['jqstat']) {
110 110
 
111 111
                     // Log the new job.
112
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Found NEW job with local ID <' . $jprops['ljid'] . '>, starting its queue processing', 3 );
112
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Found NEW job with local ID <'.$jprops['ljid'].'>, starting its queue processing', 3);
113 113
 
114 114
                     // Compare job and rule hashes (if any).
115
-                    $hash = $this->ao_ccss_diff_hashes( $jprops['ljid'], $jprops['hash'], $jprops['hashes'], $jprops['rtarget'] );
115
+                    $hash = $this->ao_ccss_diff_hashes($jprops['ljid'], $jprops['hash'], $jprops['hashes'], $jprops['rtarget']);
116 116
 
117 117
                     // If job hash is new or different of a previous one.
118
-                    if ( $hash ) {
118
+                    if ($hash) {
119 119
                         // Set job hash.
120 120
                         $jprops['hash'] = $hash;
121 121
 
122 122
                         // If this is not the first job, wait 10 seconds before process next job due criticalcss.com API limits.
123
-                        if ( $jr > 1 ) {
124
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Waiting ' . AO_CCSS_SLEEP . ' seconds due to criticalcss.com API limits', 3 );
125
-                            sleep( AO_CCSS_SLEEP );
123
+                        if ($jr > 1) {
124
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Waiting '.AO_CCSS_SLEEP.' seconds due to criticalcss.com API limits', 3);
125
+                            sleep(AO_CCSS_SLEEP);
126 126
                         }
127 127
 
128 128
                         // Dispatch the job generate request and increment request count.
129
-                        $apireq = $this->ao_ccss_api_generate( $path, $queue_debug, $qdobj['htcode'] );
129
+                        $apireq = $this->ao_ccss_api_generate($path, $queue_debug, $qdobj['htcode']);
130 130
                         $jr++;
131 131
 
132 132
                         // NOTE: All the following conditions maps to the ones in admin_settings_queue.js.php.
133
-                        if ( 'JOB_QUEUED' == $apireq['job']['status'] || 'JOB_ONGOING' == $apireq['job']['status'] ) {
133
+                        if ('JOB_QUEUED' == $apireq['job']['status'] || 'JOB_ONGOING' == $apireq['job']['status']) {
134 134
                             // SUCCESS: request has a valid result.
135 135
                             // Update job properties.
136 136
                             $jprops['jid']    = $apireq['job']['id'];
137 137
                             $jprops['jqstat'] = $apireq['job']['status'];
138
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> generate request successful, remote id <' . $jprops['jid'] . '>, status now is <' . $jprops['jqstat'] . '>', 3 );
139
-                        } elseif ( 'STATUS_JOB_BAD' == $apireq['job']['status'] ) {
138
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> generate request successful, remote id <'.$jprops['jid'].'>, status now is <'.$jprops['jqstat'].'>', 3);
139
+                        } elseif ('STATUS_JOB_BAD' == $apireq['job']['status']) {
140 140
                             // ERROR: concurrent requests
141 141
                             // Update job properties.
142 142
                             $jprops['jid']    = $apireq['job']['id'];
143 143
                             $jprops['jqstat'] = $apireq['job']['status'];
144 144
                             $jprops['jrstat'] = $apireq['error'];
145 145
                             $jprops['jvstat'] = 'NONE';
146
-                            $jprops['jftime'] = microtime( true );
147
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Concurrent requests when processing job id <' . $jprops['ljid'] . '>, job status is now <' . $jprops['jqstat'] . '>', 3 );
148
-                        } elseif ( 'INVALID_JWT_TOKEN' == $apireq['errorCode'] ) {
146
+                            $jprops['jftime'] = microtime(true);
147
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Concurrent requests when processing job id <'.$jprops['ljid'].'>, job status is now <'.$jprops['jqstat'].'>', 3);
148
+                        } elseif ('INVALID_JWT_TOKEN' == $apireq['errorCode']) {
149 149
                             // ERROR: key validation
150 150
                             // Update job properties.
151 151
                             $jprops['jqstat'] = $apireq['errorCode'];
152 152
                             $jprops['jrstat'] = $apireq['error'];
153 153
                             $jprops['jvstat'] = 'NONE';
154
-                            $jprops['jftime'] = microtime( true );
155
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'API key validation error when processing job id <' . $jprops['ljid'] . '>, job status is now <' . $jprops['jqstat'] . '>', 3 );
156
-                        } elseif ( empty( $apireq ) ) {
154
+                            $jprops['jftime'] = microtime(true);
155
+                            autoptimizeCriticalCSSCore::ao_ccss_log('API key validation error when processing job id <'.$jprops['ljid'].'>, job status is now <'.$jprops['jqstat'].'>', 3);
156
+                        } elseif (empty($apireq)) {
157 157
                             // ERROR: no response
158 158
                             // Update job properties.
159 159
                             $jprops['jqstat'] = 'NO_RESPONSE';
160 160
                             $jprops['jrstat'] = 'NONE';
161 161
                             $jprops['jvstat'] = 'NONE';
162
-                            $jprops['jftime'] = microtime( true );
163
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> request has no response, status now is <' . $jprops['jqstat'] . '>', 3 );
162
+                            $jprops['jftime'] = microtime(true);
163
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> request has no response, status now is <'.$jprops['jqstat'].'>', 3);
164 164
                         } else {
165 165
                             // UNKNOWN: unhandled generate exception
166 166
                             // Update job properties.
167 167
                             $jprops['jqstat'] = 'JOB_UNKNOWN';
168 168
                             $jprops['jrstat'] = 'NONE';
169 169
                             $jprops['jvstat'] = 'NONE';
170
-                            $jprops['jftime'] = microtime( true );
171
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> generate request has an UNKNOWN condition, status now is <' . $jprops['jqstat'] . '>, check log messages above for more information', 2 );
172
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 );
170
+                            $jprops['jftime'] = microtime(true);
171
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> generate request has an UNKNOWN condition, status now is <'.$jprops['jqstat'].'>, check log messages above for more information', 2);
172
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3);
173 173
                         }
174 174
                     } else {
175 175
                         // SUCCESS: Job hash is equal to a previous one, so it's done
176 176
                         // Update job status and finish time.
177 177
                         $jprops['jqstat'] = 'JOB_DONE';
178
-                        $jprops['jftime'] = microtime( true );
179
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> requires no further processing, status now is <' . $jprops['jqstat'] . '>', 3 );
178
+                        $jprops['jftime'] = microtime(true);
179
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> requires no further processing, status now is <'.$jprops['jqstat'].'>', 3);
180 180
                     }
181 181
 
182 182
                     // Set queue update flag.
183 183
                     $update = true;
184 184
 
185
-                } elseif ( 'JOB_QUEUED' == $jprops['jqstat'] || 'JOB_ONGOING' == $jprops['jqstat'] ) {
185
+                } elseif ('JOB_QUEUED' == $jprops['jqstat'] || 'JOB_ONGOING' == $jprops['jqstat']) {
186 186
                     // Process QUEUED and ONGOING jobs
187 187
                     // Log the pending job.
188
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Found PENDING job with local ID <' . $jprops['ljid'] . '>, continuing its queue processing', 3 );
188
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Found PENDING job with local ID <'.$jprops['ljid'].'>, continuing its queue processing', 3);
189 189
 
190 190
                     // If this is not the first job, wait before process next job due criticalcss.com API limits.
191
-                    if ( $jr > 1 ) {
192
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Waiting ' . AO_CCSS_SLEEP . ' seconds due to criticalcss.com API limits', 3 );
193
-                        sleep( AO_CCSS_SLEEP );
191
+                    if ($jr > 1) {
192
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Waiting '.AO_CCSS_SLEEP.' seconds due to criticalcss.com API limits', 3);
193
+                        sleep(AO_CCSS_SLEEP);
194 194
                     }
195 195
 
196 196
                     // Dispatch the job result request and increment request count.
197
-                    $apireq = $this->ao_ccss_api_results( $jprops['jid'], $queue_debug, $qdobj['htcode'] );
197
+                    $apireq = $this->ao_ccss_api_results($jprops['jid'], $queue_debug, $qdobj['htcode']);
198 198
                     $jr++;
199 199
 
200 200
                     // NOTE: All the following condigitons maps to the ones in admin_settings_queue.js.php
201 201
                     // Replace API response values if queue debugging is enabled and some value is set.
202
-                    if ( $queue_debug ) {
203
-                        if ( $qdobj['status'] ) {
202
+                    if ($queue_debug) {
203
+                        if ($qdobj['status']) {
204 204
                             $apireq['status'] = $qdobj['status'];
205 205
                         }
206
-                        if ( $qdobj['resultStatus'] ) {
206
+                        if ($qdobj['resultStatus']) {
207 207
                             $apireq['resultStatus'] = $qdobj['resultStatus'];
208 208
                         }
209
-                        if ( $qdobj['validationStatus'] ) {
209
+                        if ($qdobj['validationStatus']) {
210 210
                             $apireq['validationStatus'] = $qdobj['validationStatus'];
211 211
                         }
212 212
                     }
213 213
 
214
-                    if ( 'JOB_QUEUED' == $apireq['status'] || 'JOB_ONGOING' == $apireq['status'] ) {
214
+                    if ('JOB_QUEUED' == $apireq['status'] || 'JOB_ONGOING' == $apireq['status']) {
215 215
                         // SUCCESS: request has a valid result
216 216
                         // Process a PENDING job
217 217
                         // Update job properties.
218 218
                         $jprops['jqstat'] = $apireq['status'];
219
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . '> unchanged', 3 );
220
-                    } elseif ( 'JOB_DONE' == $apireq['status'] ) {
219
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].'> unchanged', 3);
220
+                    } elseif ('JOB_DONE' == $apireq['status']) {
221 221
                         // Process a DONE job
222 222
                         // New resultStatus from ccss.com "HTML_404", consider as "GOOD" for now.
223
-                        if ( 'HTML_404' == $apireq['resultStatus'] ) {
223
+                        if ('HTML_404' == $apireq['resultStatus']) {
224 224
                             $apireq['resultStatus'] = 'GOOD';
225 225
                         }
226 226
 
227
-                        if ( 'GOOD' == $apireq['resultStatus'] && 'GOOD' == $apireq['validationStatus'] ) {
227
+                        if ('GOOD' == $apireq['resultStatus'] && 'GOOD' == $apireq['validationStatus']) {
228 228
                             // SUCCESS: GOOD job with GOOD validation
229 229
                             // Update job properties.
230
-                            $jprops['file']   = $this->ao_ccss_save_file( $apireq['css'], $trule, false );
230
+                            $jprops['file']   = $this->ao_ccss_save_file($apireq['css'], $trule, false);
231 231
                             $jprops['jqstat'] = $apireq['status'];
232 232
                             $jprops['jrstat'] = $apireq['resultStatus'];
233 233
                             $jprops['jvstat'] = $apireq['validationStatus'];
234
-                            $jprops['jftime'] = microtime( true );
234
+                            $jprops['jftime'] = microtime(true);
235 235
                             $rule_update      = true;
236
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . '>, file saved <' . $jprops['file'] . '>', 3 );
237
-                        } elseif ( 'GOOD' == $apireq['resultStatus'] && ( 'WARN' == $apireq['validationStatus'] || 'BAD' == $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' == $apireq['validationStatus'] ) ) {
236
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].'>, file saved <'.$jprops['file'].'>', 3);
237
+                        } elseif ('GOOD' == $apireq['resultStatus'] && ('WARN' == $apireq['validationStatus'] || 'BAD' == $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' == $apireq['validationStatus'])) {
238 238
                             // SUCCESS: GOOD job with WARN or BAD validation
239 239
                             // Update job properties.
240
-                            $jprops['file']   = $this->ao_ccss_save_file( $apireq['css'], $trule, true );
240
+                            $jprops['file']   = $this->ao_ccss_save_file($apireq['css'], $trule, true);
241 241
                             $jprops['jqstat'] = $apireq['status'];
242 242
                             $jprops['jrstat'] = $apireq['resultStatus'];
243 243
                             $jprops['jvstat'] = $apireq['validationStatus'];
244
-                            $jprops['jftime'] = microtime( true );
244
+                            $jprops['jftime'] = microtime(true);
245 245
                             $rule_update      = true;
246
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful, remote id <' . $jprops['jid'] . '>, status <' . $jprops['jqstat'] . ', file saved <' . $jprops['file'] . '> but requires REVIEW', 3 );
247
-                        } elseif ( 'GOOD' != $apireq['resultStatus'] && ( 'GOOD' != $apireq['validationStatus'] || 'WARN' != $apireq['validationStatus'] || 'BAD' != $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' != $apireq['validationStatus'] ) ) {
246
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful, remote id <'.$jprops['jid'].'>, status <'.$jprops['jqstat'].', file saved <'.$jprops['file'].'> but requires REVIEW', 3);
247
+                        } elseif ('GOOD' != $apireq['resultStatus'] && ('GOOD' != $apireq['validationStatus'] || 'WARN' != $apireq['validationStatus'] || 'BAD' != $apireq['validationStatus'] || 'SCREENSHOT_WARN_BLANK' != $apireq['validationStatus'])) {
248 248
                             // ERROR: no GOOD, WARN or BAD results
249 249
                             // Update job properties.
250 250
                             $jprops['jqstat'] = $apireq['status'];
251 251
                             $jprops['jrstat'] = $apireq['resultStatus'];
252 252
                             $jprops['jvstat'] = $apireq['validationStatus'];
253
-                            $jprops['jftime'] = microtime( true );
254
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 );
253
+                            $jprops['jftime'] = microtime(true);
254
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3);
255 255
                             $apireq['css'] = '/* critical css removed for DEBUG logging purposes */';
256
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 );
256
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3);
257 257
                         } else {
258 258
                             // UNKNOWN: unhandled JOB_DONE exception
259 259
                             // Update job properties.
260 260
                             $jprops['jqstat'] = 'JOB_UNKNOWN';
261 261
                             $jprops['jrstat'] = $apireq['resultStatus'];
262 262
                             $jprops['jvstat'] = $apireq['validationStatus'];
263
-                            $jprops['jftime'] = microtime( true );
264
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job is UNKNOWN, status now is <' . $jprops['jqstat'] . '>', 2 );
263
+                            $jprops['jftime'] = microtime(true);
264
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job is UNKNOWN, status now is <'.$jprops['jqstat'].'>', 2);
265 265
                             $apireq['css'] = '/* critical css removed for DEBUG logging purposes */';
266
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job response was: ' . json_encode( $apireq ), 3 );
266
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Job response was: '.json_encode($apireq), 3);
267 267
                         }
268
-                    } elseif ( 'JOB_FAILED' == $apireq['job']['status'] || 'STATUS_JOB_BAD' == $apireq['job']['status'] ) {
268
+                    } elseif ('JOB_FAILED' == $apireq['job']['status'] || 'STATUS_JOB_BAD' == $apireq['job']['status']) {
269 269
                         // ERROR: failed job
270 270
                         // Update job properties.
271 271
                         $jprops['jqstat'] = $apireq['job']['status'];
272
-                        if ( $apireq['error'] ) {
272
+                        if ($apireq['error']) {
273 273
                             $jprops['jrstat'] = $apireq['job']['error'];
274 274
                         } else {
275 275
                         }
276 276
                         $jprops['jvstat'] = 'NONE';
277
-                        $jprops['jftime'] = microtime( true );
278
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 );
279
-                    } elseif ( 'This css no longer exists. Please re-generate it.' == $apireq['error'] ) {
277
+                        $jprops['jftime'] = microtime(true);
278
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3);
279
+                    } elseif ('This css no longer exists. Please re-generate it.' == $apireq['error']) {
280 280
                         // ERROR: CSS doesn't exist
281 281
                         // Update job properties.
282 282
                         $jprops['jqstat'] = 'NO_CSS';
283 283
                         $jprops['jrstat'] = $apireq['error'];
284 284
                         $jprops['jvstat'] = 'NONE';
285
-                        $jprops['jftime'] = microtime( true );
286
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request successful but job FAILED, status now is <' . $jprops['jqstat'] . '>', 3 );
287
-                    } elseif ( empty( $apireq ) ) {
285
+                        $jprops['jftime'] = microtime(true);
286
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request successful but job FAILED, status now is <'.$jprops['jqstat'].'>', 3);
287
+                    } elseif (empty($apireq)) {
288 288
                         // ERROR: no response
289 289
                         // Update job properties.
290 290
                         $jprops['jqstat'] = 'NO_RESPONSE';
291 291
                         $jprops['jrstat'] = 'NONE';
292 292
                         $jprops['jvstat'] = 'NONE';
293
-                        $jprops['jftime'] = microtime( true );
294
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> request has no response, status now is <' . $jprops['jqstat'] . '>', 3 );
293
+                        $jprops['jftime'] = microtime(true);
294
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> request has no response, status now is <'.$jprops['jqstat'].'>', 3);
295 295
                     } else {
296 296
                         // UNKNOWN: unhandled results exception
297 297
                         // Update job properties.
298 298
                         $jprops['jqstat'] = 'JOB_UNKNOWN';
299 299
                         $jprops['jrstat'] = 'NONE';
300 300
                         $jprops['jvstat'] = 'NONE';
301
-                        $jprops['jftime'] = microtime( true );
302
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> result request has an UNKNOWN condition, status now is <' . $jprops['jqstat'] . '>, check log messages above for more information', 2 );
301
+                        $jprops['jftime'] = microtime(true);
302
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> result request has an UNKNOWN condition, status now is <'.$jprops['jqstat'].'>, check log messages above for more information', 2);
303 303
                     }
304 304
 
305 305
                     // Set queue update flag.
@@ -307,40 +307,40 @@  discard block
 block discarded – undo
307 307
                 }
308 308
 
309 309
                 // Mark DONE jobs for removal.
310
-                if ( 'JOB_DONE' == $jprops['jqstat'] ) {
310
+                if ('JOB_DONE' == $jprops['jqstat']) {
311 311
                     $update = true;
312 312
                     $deljob = true;
313 313
                 }
314 314
 
315 315
                 // Persist updated queue object.
316
-                if ( $update ) {
317
-                    if ( ! $deljob ) {
316
+                if ($update) {
317
+                    if (!$deljob) {
318 318
                         // Update properties of a NEW or PENDING job...
319
-                        $ao_ccss_queue[ $path ] = $jprops;
319
+                        $ao_ccss_queue[$path] = $jprops;
320 320
                     } else {
321 321
                         // ...or remove the DONE job.
322
-                        unset( $ao_ccss_queue[ $path ] );
323
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> is DONE and was removed from the queue', 3 );
322
+                        unset($ao_ccss_queue[$path]);
323
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> is DONE and was removed from the queue', 3);
324 324
                     }
325 325
 
326 326
                     // Update queue object.
327
-                    $ao_ccss_queue_raw = json_encode( $ao_ccss_queue );
328
-                    update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
329
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue updated by job id <' . $jprops['ljid'] . '>', 3 );
327
+                    $ao_ccss_queue_raw = json_encode($ao_ccss_queue);
328
+                    update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
329
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Queue updated by job id <'.$jprops['ljid'].'>', 3);
330 330
 
331 331
                     // Update target rule.
332
-                    if ( $rule_update ) {
333
-                        $this->ao_ccss_rule_update( $jprops['ljid'], $jprops['rtarget'], $jprops['file'], $jprops['hash'] );
334
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $jprops['ljid'] . '> updated the target rule <' . $jprops['rtarget'] . '>', 3 );
332
+                    if ($rule_update) {
333
+                        $this->ao_ccss_rule_update($jprops['ljid'], $jprops['rtarget'], $jprops['file'], $jprops['hash']);
334
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$jprops['ljid'].'> updated the target rule <'.$jprops['rtarget'].'>', 3);
335 335
                     }
336 336
                 } else {
337 337
                     // Or log no queue action.
338
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Nothing to do on this job', 3 );
338
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Nothing to do on this job', 3);
339 339
                 }
340 340
 
341 341
                 // Break the loop if request limit is set and was reached.
342
-                if ( $ao_ccss_rlimit && $ao_ccss_rlimit == $jr ) {
343
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'The limit of ' . $ao_ccss_rlimit . ' request(s) to criticalcss.com was reached, queue control must finish now', 3 );
342
+                if ($ao_ccss_rlimit && $ao_ccss_rlimit == $jr) {
343
+                    autoptimizeCriticalCSSCore::ao_ccss_log('The limit of '.$ao_ccss_rlimit.' request(s) to criticalcss.com was reached, queue control must finish now', 3);
344 344
                     break;
345 345
                 }
346 346
 
@@ -349,46 +349,46 @@  discard block
 block discarded – undo
349 349
             }
350 350
 
351 351
             // Remove the lock file and log the queue end.
352
-            if ( file_exists( AO_CCSS_LOCK ) ) {
353
-                unlink( AO_CCSS_LOCK );
354
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control unlocked', 3 );
352
+            if (file_exists(AO_CCSS_LOCK)) {
353
+                unlink(AO_CCSS_LOCK);
354
+                autoptimizeCriticalCSSCore::ao_ccss_log('Queue control unlocked', 3);
355 355
             }
356
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue control finished', 3 );
356
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue control finished', 3);
357 357
 
358 358
             // Log that queue is locked.
359 359
         } else {
360
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue is already running, skipping the attempt to run it again', 3 );
360
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue is already running, skipping the attempt to run it again', 3);
361 361
         }
362 362
     }
363 363
 
364
-    public function ao_ccss_diff_hashes( $ljid, $hash, $hashes, $rule ) {
364
+    public function ao_ccss_diff_hashes($ljid, $hash, $hashes, $rule) {
365 365
         // Compare job hashes
366 366
         // STEP 1: update job hashes.
367
-        if ( 1 == count( $hashes ) ) {
367
+        if (1 == count($hashes)) {
368 368
             // Job with a single hash
369 369
             // Set job hash.
370 370
             $hash = $hashes[0];
371
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> updated with SINGLE hash <' . $hash . '>', 3 );
371
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> updated with SINGLE hash <'.$hash.'>', 3);
372 372
         } else {
373 373
             // Job with multiple hashes
374 374
             // Loop through hashes to concatenate them.
375 375
             $nhash = '';
376
-            foreach ( $hashes as $shash ) {
376
+            foreach ($hashes as $shash) {
377 377
                 $nhash .= $shash;
378 378
             }
379 379
 
380 380
             // Set job hash.
381
-            $hash = md5( $nhash );
382
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> updated with a COMPOSITE hash <' . $hash . '>', 3 );
381
+            $hash = md5($nhash);
382
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> updated with a COMPOSITE hash <'.$hash.'>', 3);
383 383
         }
384 384
 
385 385
         // STEP 2: compare job to existing jobs to prevent double submission for same type+hash.
386 386
         global $ao_ccss_queue;
387 387
 
388
-        foreach ( $ao_ccss_queue as $queue_item ) {
389
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Comparing <' . $rule . $hash . '> with <' . $queue_item['rtarget'] . $queue_item['hash'] . '>', 3 );
390
-            if ( $queue_item['hash'] == $hash && $queue_item['rtarget'] == $rule && in_array( $queue_item['jqstat'], array( 'JOB_QUEUED', 'JOB_ONGOING', 'JOB_DONE' ) ) ) {
391
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> matches the already pending job <' . $queue_item['ljid'] . '>', 3 );
388
+        foreach ($ao_ccss_queue as $queue_item) {
389
+            autoptimizeCriticalCSSCore::ao_ccss_log('Comparing <'.$rule.$hash.'> with <'.$queue_item['rtarget'].$queue_item['hash'].'>', 3);
390
+            if ($queue_item['hash'] == $hash && $queue_item['rtarget'] == $rule && in_array($queue_item['jqstat'], array('JOB_QUEUED', 'JOB_ONGOING', 'JOB_DONE'))) {
391
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> matches the already pending job <'.$queue_item['ljid'].'>', 3);
392 392
                 return false;
393 393
             }
394 394
         }
@@ -398,32 +398,32 @@  discard block
 block discarded – undo
398 398
         global $ao_ccss_rules;
399 399
 
400 400
         // Prepare rule variables.
401
-        $trule = explode( '|', $rule );
402
-        $srule = $ao_ccss_rules[ $trule[0] ][ $trule[1] ];
401
+        $trule = explode('|', $rule);
402
+        $srule = $ao_ccss_rules[$trule[0]][$trule[1]];
403 403
 
404 404
         // Check if a MANUAL rule exist and return false.
405
-        if ( ! empty( $srule ) && ( 0 == $srule['hash'] && 0 != $srule['file'] ) ) {
406
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> matches the MANUAL rule <' . $trule[0] . '|' . $trule[1] . '>', 3 );
405
+        if (!empty($srule) && (0 == $srule['hash'] && 0 != $srule['file'])) {
406
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> matches the MANUAL rule <'.$trule[0].'|'.$trule[1].'>', 3);
407 407
             return false;
408
-        } elseif ( ! empty( $srule ) ) {
408
+        } elseif (!empty($srule)) {
409 409
             // Check if an AUTO rule exist.
410
-            if ( $hash === $srule['hash'] && is_file( AO_CCSS_DIR . $srule['file'] ) && 0 != filesize( AO_CCSS_DIR . $srule['file'] ) ) {
410
+            if ($hash === $srule['hash'] && is_file(AO_CCSS_DIR.$srule['file']) && 0 != filesize(AO_CCSS_DIR.$srule['file'])) {
411 411
                 // Check if job hash matches rule, if the CCSS file exists said file is not empty and return FALSE is so.
412
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> with hash <' . $hash . '> MATCH the one in rule <' . $trule[0] . '|' . $trule[1] . '>', 3 );
412
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> with hash <'.$hash.'> MATCH the one in rule <'.$trule[0].'|'.$trule[1].'>', 3);
413 413
                 return false;
414 414
             } else {
415 415
                 // Or return the new hash if they differ.
416
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> with hash <' . $hash . '> DOES NOT MATCH the one in rule <' . $trule[0] . '|' . $trule[1] . '> or rule\'s CCSS file was invalid.', 3 );
416
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> with hash <'.$hash.'> DOES NOT MATCH the one in rule <'.$trule[0].'|'.$trule[1].'> or rule\'s CCSS file was invalid.', 3);
417 417
                 return $hash;
418 418
             }
419 419
         } else {
420 420
             // Or just return the hash if no rule exist yet.
421
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Job id <' . $ljid . '> with hash <' . $hash . '> has no rule yet', 3 );
421
+            autoptimizeCriticalCSSCore::ao_ccss_log('Job id <'.$ljid.'> with hash <'.$hash.'> has no rule yet', 3);
422 422
             return $hash;
423 423
         }
424 424
     }
425 425
 
426
-    public function ao_ccss_api_generate( $path, $debug, $dcode ) {
426
+    public function ao_ccss_api_generate($path, $debug, $dcode) {
427 427
         // POST jobs to criticalcss.com and return responses
428 428
         // Get key and key status.
429 429
         global $ao_ccss_key;
@@ -435,35 +435,35 @@  discard block
 block discarded – undo
435 435
         global $ao_ccss_noptimize;
436 436
 
437 437
         $site_host = get_site_url();
438
-        $site_path = parse_url( $site_host, PHP_URL_PATH );
438
+        $site_path = parse_url($site_host, PHP_URL_PATH);
439 439
 
440
-        if ( ! empty( $site_path ) ) {
441
-            $site_host = str_replace( $site_path, '', $site_host );
440
+        if (!empty($site_path)) {
441
+            $site_host = str_replace($site_path, '', $site_host);
442 442
         }
443 443
 
444 444
         // Logic to bind to one domain to avoid site clones of sites would
445 445
         // automatically begin spawning requests to criticalcss.com which has
446 446
         // a per domain cost.
447 447
         global $ao_ccss_domain;
448
-        if ( empty( $ao_ccss_domain ) ) {
448
+        if (empty($ao_ccss_domain)) {
449 449
             // first request being done, update option to allow future requests are only allowed if from same domain.
450
-            update_option( 'autoptimize_ccss_domain', str_rot13( $site_host ) );
451
-        } elseif ( trim( $ao_ccss_domain, '\'"' ) !== 'none' && parse_url( $site_host, PHP_URL_HOST ) !== parse_url( $ao_ccss_domain, PHP_URL_HOST ) && apply_filters( 'autoptimize_filter_ccss_bind_domain', true ) ) {
450
+            update_option('autoptimize_ccss_domain', str_rot13($site_host));
451
+        } elseif (trim($ao_ccss_domain, '\'"') !== 'none' && parse_url($site_host, PHP_URL_HOST) !== parse_url($ao_ccss_domain, PHP_URL_HOST) && apply_filters('autoptimize_filter_ccss_bind_domain', true)) {
452 452
             // not the same domain, log as error and return without posting to criticalcss.com.
453
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Request for domain ' . $site_host . ' does not match bound domain ' . $ao_ccss_domain . ' so not proceeding.', 2 );
453
+            autoptimizeCriticalCSSCore::ao_ccss_log('Request for domain '.$site_host.' does not match bound domain '.$ao_ccss_domain.' so not proceeding.', 2);
454 454
             return false;
455 455
         }
456 456
 
457
-        $src_url = $site_host . $path;
457
+        $src_url = $site_host.$path;
458 458
 
459 459
         // Avoid AO optimizations if required by config or avoid lazyload if lazyload is active in AO.
460
-        if ( ! empty( $ao_ccss_noptimize ) ) {
460
+        if (!empty($ao_ccss_noptimize)) {
461 461
             $src_url .= '?ao_noptirocket=1';
462
-        } elseif ( class_exists( 'autoptimizeImages', false ) && autoptimizeImages::should_lazyload_wrapper() ) {
462
+        } elseif (class_exists('autoptimizeImages', false) && autoptimizeImages::should_lazyload_wrapper()) {
463 463
             $src_url .= '?ao_nolazy=1';
464 464
         }
465 465
 
466
-        $src_url = apply_filters( 'autoptimize_filter_ccss_cron_srcurl', $src_url );
466
+        $src_url = apply_filters('autoptimize_filter_ccss_cron_srcurl', $src_url);
467 467
 
468 468
         // Initialize request body.
469 469
         $body           = array();
@@ -473,88 +473,88 @@  discard block
 block discarded – undo
473 473
 
474 474
         // Prepare and add viewport size to the body if available.
475 475
         $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport();
476
-        if ( ! empty( $viewport['w'] ) && ! empty( $viewport['h'] ) ) {
476
+        if (!empty($viewport['w']) && !empty($viewport['h'])) {
477 477
             $body['width']  = $viewport['w'];
478 478
             $body['height'] = $viewport['h'];
479 479
         }
480 480
 
481 481
         // Prepare and add forceInclude to the body if available.
482 482
         global $ao_ccss_finclude;
483
-        $finclude = $this->ao_ccss_finclude( $ao_ccss_finclude );
484
-        if ( ! empty( $finclude ) ) {
483
+        $finclude = $this->ao_ccss_finclude($ao_ccss_finclude);
484
+        if (!empty($finclude)) {
485 485
             $body['forceInclude'] = $finclude;
486 486
         }
487 487
 
488 488
         // Add filter to allow the body array to be altered (e.g. to add customPageHeaders).
489
-        $body = apply_filters( 'autoptimize_ccss_cron_api_generate_body', $body );
489
+        $body = apply_filters('autoptimize_ccss_cron_api_generate_body', $body);
490 490
 
491 491
         // Body must be json and log it.
492
-        $body = json_encode( $body );
493
-        autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request body is ' . $body, 3 );
492
+        $body = json_encode($body);
493
+        autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request body is '.$body, 3);
494 494
 
495 495
         // Prepare the request.
496
-        $url  = esc_url_raw( AO_CCSS_API . 'generate?aover=' . AO_CCSS_VER );
496
+        $url  = esc_url_raw(AO_CCSS_API.'generate?aover='.AO_CCSS_VER);
497 497
         $args = array(
498 498
             'headers' => array(
499
-                'User-Agent'    => 'Autoptimize v' . AO_CCSS_VER,
499
+                'User-Agent'    => 'Autoptimize v'.AO_CCSS_VER,
500 500
                 'Content-type'  => 'application/json; charset=utf-8',
501
-                'Authorization' => 'JWT ' . $key,
501
+                'Authorization' => 'JWT '.$key,
502 502
                 'Connection'    => 'close',
503 503
             ),
504 504
             'body'    => $body,
505 505
         );
506 506
 
507 507
         // Dispatch the request and store its response code.
508
-        $req  = wp_safe_remote_post( $url, $args );
509
-        $code = wp_remote_retrieve_response_code( $req );
510
-        $body = json_decode( wp_remote_retrieve_body( $req ), true );
508
+        $req  = wp_safe_remote_post($url, $args);
509
+        $code = wp_remote_retrieve_response_code($req);
510
+        $body = json_decode(wp_remote_retrieve_body($req), true);
511 511
 
512
-        if ( $debug && $dcode ) {
512
+        if ($debug && $dcode) {
513 513
             // If queue debug is active, change response code.
514 514
             $code = $dcode;
515 515
         }
516 516
 
517
-        if ( 200 == $code ) {
517
+        if (200 == $code) {
518 518
             // Response code is OK.
519 519
             // Workaround criticalcss.com non-RESTful reponses.
520
-            if ( 'JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] || 'STATUS_JOB_BAD' == $body['job']['status'] ) {
520
+            if ('JOB_QUEUED' == $body['job']['status'] || 'JOB_ONGOING' == $body['job']['status'] || 'STATUS_JOB_BAD' == $body['job']['status']) {
521 521
                 // Log successful and return encoded request body.
522
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> replied successfully', 3 );
522
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> replied successfully', 3);
523 523
 
524 524
                 // This code also means the key is valid, so cache key status for 24h if not already cached.
525
-                if ( ( ! $key_status || 2 != $key_status ) && $key ) {
526
-                    update_option( 'autoptimize_ccss_keyst', 2 );
527
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is valid, updating key status', 3 );
525
+                if ((!$key_status || 2 != $key_status) && $key) {
526
+                    update_option('autoptimize_ccss_keyst', 2);
527
+                    autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is valid, updating key status', 3);
528 528
                 }
529 529
 
530 530
                 // Return the request body.
531 531
                 return $body;
532 532
             } else {
533 533
                 // Log successful requests with invalid reponses.
534
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> replied with code <' . $code . '> and an UNKNOWN error condition, body follows...', 2 );
535
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
534
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> replied with code <'.$code.'> and an UNKNOWN error condition, body follows...', 2);
535
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
536 536
                 return $body;
537 537
             }
538 538
         } else {
539 539
             // Response code is anything else.
540 540
             // Log failed request with a valid response code and return body.
541
-            if ( $code ) {
542
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> replied with error code <' . $code . '>, body follows...', 2 );
543
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
541
+            if ($code) {
542
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> replied with error code <'.$code.'>, body follows...', 2);
543
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
544 544
 
545
-                if ( 401 == $code ) {
545
+                if (401 == $code) {
546 546
                     // If request is unauthorized, also clear key status.
547
-                    update_option( 'autoptimize_ccss_keyst', 1 );
548
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 );
547
+                    update_option('autoptimize_ccss_keyst', 1);
548
+                    autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3);
549 549
                 }
550 550
 
551 551
                 // Return the request body.
552 552
                 return $body;
553 553
             } else {
554 554
                 // Log failed request with no response and return false.
555
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request for path <' . $src_url . '> has no response, this could be a service timeout', 2 );
556
-                if ( is_wp_error( $req ) ) {
557
-                    autoptimizeCriticalCSSCore::ao_ccss_log( $req->get_error_message(), 2 );
555
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: POST generate request for path <'.$src_url.'> has no response, this could be a service timeout', 2);
556
+                if (is_wp_error($req)) {
557
+                    autoptimizeCriticalCSSCore::ao_ccss_log($req->get_error_message(), 2);
558 558
                 }
559 559
 
560 560
                 return false;
@@ -562,76 +562,76 @@  discard block
 block discarded – undo
562 562
         }
563 563
     }
564 564
 
565
-    public function ao_ccss_api_results( $jobid, $debug, $dcode ) {
565
+    public function ao_ccss_api_results($jobid, $debug, $dcode) {
566 566
         // GET jobs from criticalcss.com and return responses
567 567
         // Get key.
568 568
         global $ao_ccss_key;
569 569
         $key = $ao_ccss_key;
570 570
 
571 571
         // Prepare the request.
572
-        $url  = AO_CCSS_API . 'results?resultId=' . $jobid;
572
+        $url  = AO_CCSS_API.'results?resultId='.$jobid;
573 573
         $args = array(
574 574
             'headers' => array(
575
-                'User-Agent'    => 'Autoptimize CriticalCSS Power-Up v' . AO_CCSS_VER,
576
-                'Authorization' => 'JWT ' . $key,
575
+                'User-Agent'    => 'Autoptimize CriticalCSS Power-Up v'.AO_CCSS_VER,
576
+                'Authorization' => 'JWT '.$key,
577 577
                 'Connection'    => 'close',
578 578
             ),
579 579
         );
580 580
 
581 581
         // Dispatch the request and store its response code.
582
-        $req  = wp_safe_remote_get( $url, $args );
583
-        $code = wp_remote_retrieve_response_code( $req );
584
-        $body = json_decode( wp_remote_retrieve_body( $req ), true );
582
+        $req  = wp_safe_remote_get($url, $args);
583
+        $code = wp_remote_retrieve_response_code($req);
584
+        $body = json_decode(wp_remote_retrieve_body($req), true);
585 585
 
586
-        if ( $debug && $dcode ) {
586
+        if ($debug && $dcode) {
587 587
             // If queue debug is active, change response code.
588 588
             $code = $dcode;
589 589
         }
590 590
 
591
-        if ( 200 == $code ) {
591
+        if (200 == $code) {
592 592
             // Response code is OK.
593
-            if ( is_array( $body ) && ( array_key_exists( 'status', $body ) || array_key_exists( 'job', $body ) ) && ( 'JOB_QUEUED' == $body['status'] || 'JOB_ONGOING' == $body['status'] || 'JOB_DONE' == $body['status'] || 'JOB_FAILED' == $body['status'] || 'JOB_UNKNOWN' == $body['status'] || 'STATUS_JOB_BAD' == $body['job']['status'] ) ) {
593
+            if (is_array($body) && (array_key_exists('status', $body) || array_key_exists('job', $body)) && ('JOB_QUEUED' == $body['status'] || 'JOB_ONGOING' == $body['status'] || 'JOB_DONE' == $body['status'] || 'JOB_FAILED' == $body['status'] || 'JOB_UNKNOWN' == $body['status'] || 'STATUS_JOB_BAD' == $body['job']['status'])) {
594 594
                 // Workaround criticalcss.com non-RESTful reponses
595 595
                 // Log successful and return encoded request body.
596
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied successfully', 3 );
596
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied successfully', 3);
597 597
                 return $body;
598
-            } elseif ( is_array( $body ) && ( array_key_exists( 'error', $body ) && 'This css no longer exists. Please re-generate it.' == $body['error'] ) ) {
598
+            } elseif (is_array($body) && (array_key_exists('error', $body) && 'This css no longer exists. Please re-generate it.' == $body['error'])) {
599 599
                 // Handle no CSS reply
600 600
                 // Log no CSS error and return encoded request body.
601
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied successfully but the CSS for it does not exist anymore', 3 );
601
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied successfully but the CSS for it does not exist anymore', 3);
602 602
                 return $body;
603 603
             } else {
604 604
                 // Log failed request and return false.
605
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied with code <' . $code . '> and an UNKNOWN error condition, body follows...', 2 );
606
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
605
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied with code <'.$code.'> and an UNKNOWN error condition, body follows...', 2);
606
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
607 607
                 return false;
608 608
             }
609 609
         } else {
610 610
             // Response code is anything else
611 611
             // Log failed request with a valid response code and return body.
612
-            if ( $code ) {
613
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> replied with error code <' . $code . '>, body follows...', 2 );
614
-                autoptimizeCriticalCSSCore::ao_ccss_log( print_r( $body, true ), 2 );
615
-                if ( 401 == $code ) {
612
+            if ($code) {
613
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> replied with error code <'.$code.'>, body follows...', 2);
614
+                autoptimizeCriticalCSSCore::ao_ccss_log(print_r($body, true), 2);
615
+                if (401 == $code) {
616 616
                     // If request is unauthorized, also clear key status.
617
-                    update_option( 'autoptimize_ccss_keyst', 1 );
618
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: API key is invalid, updating key status', 3 );
617
+                    update_option('autoptimize_ccss_keyst', 1);
618
+                    autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: API key is invalid, updating key status', 3);
619 619
                 }
620 620
 
621 621
                 // Return the request body.
622 622
                 return $body;
623 623
             } else {
624 624
                 // Log failed request with no response and return false.
625
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: GET results request for remote job id <' . $jobid . '> has no response, this could be a service timeout', 2 );
625
+                autoptimizeCriticalCSSCore::ao_ccss_log('criticalcss.com: GET results request for remote job id <'.$jobid.'> has no response, this could be a service timeout', 2);
626 626
                 return false;
627 627
             }
628 628
         }
629 629
     }
630 630
 
631
-    public function ao_ccss_save_file( $ccss, $target, $review ) {
631
+    public function ao_ccss_save_file($ccss, $target, $review) {
632 632
         // Save critical CSS into the filesystem and return its filename
633 633
         // Prepare review mark.
634
-        if ( $review ) {
634
+        if ($review) {
635 635
             $rmark = '_R';
636 636
         } else {
637 637
             $rmark = '';
@@ -641,21 +641,21 @@  discard block
 block discarded – undo
641 641
         $filename = false;
642 642
         $content  = $ccss;
643 643
 
644
-        if ( autoptimizeCriticalCSSCore::ao_ccss_check_contents( $content ) ) {
644
+        if (autoptimizeCriticalCSSCore::ao_ccss_check_contents($content)) {
645 645
             // Sanitize content, set filename and try to save file.
646
-            $file     = AO_CCSS_DIR . 'ccss_' . md5( $ccss . $target[1] ) . $rmark . '.css';
647
-            $status   = file_put_contents( $file, $content, LOCK_EX );
648
-            $filename = pathinfo( $file, PATHINFO_BASENAME );
649
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS file for the rule <' . $target[0] . '|' . $target[1] . '> was saved as <' . $filename . '>, size in bytes is <' . $status . '>', 3 );
646
+            $file     = AO_CCSS_DIR.'ccss_'.md5($ccss.$target[1]).$rmark.'.css';
647
+            $status   = file_put_contents($file, $content, LOCK_EX);
648
+            $filename = pathinfo($file, PATHINFO_BASENAME);
649
+            autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS file for the rule <'.$target[0].'|'.$target[1].'> was saved as <'.$filename.'>, size in bytes is <'.$status.'>', 3);
650 650
 
651
-            if ( ! $status ) {
651
+            if (!$status) {
652 652
                 // If file has not been saved, reset filename.
653
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS file <' . $filename . '> could not be not saved', 2 );
653
+                autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS file <'.$filename.'> could not be not saved', 2);
654 654
                 $filename = false;
655 655
                 return $filename;
656 656
             }
657 657
         } else {
658
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Critical CSS received did not pass content check', 2 );
658
+            autoptimizeCriticalCSSCore::ao_ccss_log('Critical CSS received did not pass content check', 2);
659 659
             return $filename;
660 660
         }
661 661
 
@@ -665,15 +665,15 @@  discard block
 block discarded – undo
665 665
         global $ao_ccss_rules;
666 666
 
667 667
         // Prepare rule variables.
668
-        $srule   = $ao_ccss_rules[ $target[0] ][ $target[1] ];
668
+        $srule   = $ao_ccss_rules[$target[0]][$target[1]];
669 669
         $oldfile = $srule['file'];
670 670
 
671
-        if ( $oldfile && $oldfile !== $filename ) {
672
-            $delfile = AO_CCSS_DIR . $oldfile;
673
-            if ( file_exists( $delfile ) ) {
674
-                $unlinkst = unlink( $delfile );
675
-                if ( $unlinkst ) {
676
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'A previous critical CSS file <' . $oldfile . '> was removed for the rule <' . $target[0] . '|' . $target[1] . '>', 3 );
671
+        if ($oldfile && $oldfile !== $filename) {
672
+            $delfile = AO_CCSS_DIR.$oldfile;
673
+            if (file_exists($delfile)) {
674
+                $unlinkst = unlink($delfile);
675
+                if ($unlinkst) {
676
+                    autoptimizeCriticalCSSCore::ao_ccss_log('A previous critical CSS file <'.$oldfile.'> was removed for the rule <'.$target[0].'|'.$target[1].'>', 3);
677 677
                 }
678 678
             }
679 679
         }
@@ -682,29 +682,29 @@  discard block
 block discarded – undo
682 682
         return $filename;
683 683
     }
684 684
 
685
-    public function ao_ccss_rule_update( $ljid, $srule, $file, $hash ) {
685
+    public function ao_ccss_rule_update($ljid, $srule, $file, $hash) {
686 686
         // Update or create a rule
687 687
         // Attach required arrays.
688 688
         global $ao_ccss_rules;
689 689
 
690 690
         // Prepare rule variables.
691
-        $trule  = explode( '|', $srule );
692
-        $rule   = $ao_ccss_rules[ $trule[0] ][ $trule[1] ];
691
+        $trule  = explode('|', $srule);
692
+        $rule   = $ao_ccss_rules[$trule[0]][$trule[1]];
693 693
         $action = false;
694 694
         $rtype  = '';
695 695
 
696
-        if ( 0 === $rule['hash'] && 0 !== $rule['file'] ) {
696
+        if (0 === $rule['hash'] && 0 !== $rule['file']) {
697 697
             // manual rule, don't ever overwrite.
698 698
             $action = 'NOT UPDATED';
699 699
             $rtype  = 'MANUAL';
700
-        } elseif ( 0 === $rule['hash'] && 0 === $rule['file'] ) {
700
+        } elseif (0 === $rule['hash'] && 0 === $rule['file']) {
701 701
             // If this is an user created AUTO rule with no hash and file yet, update its hash and filename
702 702
             // Set rule hash, file and action flag.
703 703
             $rule['hash'] = $hash;
704 704
             $rule['file'] = $file;
705 705
             $action       = 'UPDATED';
706 706
             $rtype        = 'AUTO';
707
-        } elseif ( 0 !== $rule['hash'] && ctype_alnum( $rule['hash'] ) ) {
707
+        } elseif (0 !== $rule['hash'] && ctype_alnum($rule['hash'])) {
708 708
             // If this is an genuine AUTO rule, update its hash and filename
709 709
             // Set rule hash, file and action flag.
710 710
             $rule['hash'] = $hash;
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
         } else {
715 715
             // If rule doesn't exist, create an AUTO rule
716 716
             // AUTO rules were only for types, but will now also work for paths.
717
-            if ( 'types' == $trule[0] || 'paths' == $trule[0] ) {
717
+            if ('types' == $trule[0] || 'paths' == $trule[0]) {
718 718
                 // Set rule hash and file and action flag.
719 719
                 $rule['hash'] = $hash;
720 720
                 $rule['file'] = $file;
@@ -722,47 +722,47 @@  discard block
 block discarded – undo
722 722
                 $rtype        = 'AUTO';
723 723
             } else {
724 724
                 // Log that no rule was created.
725
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Exception, no AUTO rule created', 3 );
725
+                autoptimizeCriticalCSSCore::ao_ccss_log('Exception, no AUTO rule created', 3);
726 726
             }
727 727
         }
728 728
 
729
-        if ( $action ) {
729
+        if ($action) {
730 730
             // If a rule creation/update is required, persist updated rules object.
731
-            $ao_ccss_rules[ $trule[0] ][ $trule[1] ] = $rule;
732
-            $ao_ccss_rules_raw                       = json_encode( $ao_ccss_rules );
733
-            update_option( 'autoptimize_ccss_rules', $ao_ccss_rules_raw );
734
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Target rule <' . $srule . '> of type <' . $rtype . '> was ' . $action . ' for job id <' . $ljid . '>', 3 );
731
+            $ao_ccss_rules[$trule[0]][$trule[1]] = $rule;
732
+            $ao_ccss_rules_raw                       = json_encode($ao_ccss_rules);
733
+            update_option('autoptimize_ccss_rules', $ao_ccss_rules_raw);
734
+            autoptimizeCriticalCSSCore::ao_ccss_log('Target rule <'.$srule.'> of type <'.$rtype.'> was '.$action.' for job id <'.$ljid.'>', 3);
735 735
         } else {
736
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'No rule action required', 3 );
736
+            autoptimizeCriticalCSSCore::ao_ccss_log('No rule action required', 3);
737 737
         }
738 738
     }
739 739
 
740
-    function ao_ccss_finclude( $finclude_raw ) {
740
+    function ao_ccss_finclude($finclude_raw) {
741 741
         // Prepare forceInclude object.
742
-        if ( ! empty( $finclude_raw ) ) {
742
+        if (!empty($finclude_raw)) {
743 743
             // If there are any content
744 744
             // Convert raw string into arra and initialize the returning object.
745
-            $fincludes = explode( ',', $finclude_raw );
745
+            $fincludes = explode(',', $finclude_raw);
746 746
             $finclude  = array();
747 747
 
748 748
             // Interacts over every rule.
749 749
             $i = 0;
750
-            foreach ( $fincludes as $include ) {
750
+            foreach ($fincludes as $include) {
751 751
                 // Trim leading and trailing whitespaces.
752
-                $include = trim( $include );
752
+                $include = trim($include);
753 753
 
754
-                if ( substr( $include, 0, 2 ) === '//' ) {
754
+                if (substr($include, 0, 2) === '//') {
755 755
                     // Regex rule
756 756
                     // Format value as required.
757
-                    $include = str_replace( '//', '/', $include );
758
-                    $include = $include . '/i';
757
+                    $include = str_replace('//', '/', $include);
758
+                    $include = $include.'/i';
759 759
 
760 760
                     // Store regex object.
761
-                    $finclude[ $i ]['type']  = 'RegExp';
762
-                    $finclude[ $i ]['value'] = $include;
761
+                    $finclude[$i]['type']  = 'RegExp';
762
+                    $finclude[$i]['value'] = $include;
763 763
                 } else {
764 764
                     // Simple value rule.
765
-                    $finclude[ $i ]['value'] = $include;
765
+                    $finclude[$i]['value'] = $include;
766 766
                 }
767 767
 
768 768
                 $i++;
@@ -779,54 +779,54 @@  discard block
 block discarded – undo
779 779
     public function ao_ccss_cleaning() {
780 780
         // Perform plugin maintenance
781 781
         // Truncate log file >= 1MB .
782
-        if ( file_exists( AO_CCSS_LOG ) ) {
783
-            if ( filesize( AO_CCSS_LOG ) >= 1048576 ) {
784
-                $logfile = fopen( AO_CCSS_LOG, 'w' );
785
-                fclose( $logfile );
782
+        if (file_exists(AO_CCSS_LOG)) {
783
+            if (filesize(AO_CCSS_LOG) >= 1048576) {
784
+                $logfile = fopen(AO_CCSS_LOG, 'w');
785
+                fclose($logfile);
786 786
             }
787 787
         }
788 788
 
789 789
         // Remove lock file.
790
-        if ( file_exists( AO_CCSS_LOCK ) ) {
791
-            unlink( AO_CCSS_LOCK );
790
+        if (file_exists(AO_CCSS_LOCK)) {
791
+            unlink(AO_CCSS_LOCK);
792 792
         }
793 793
 
794 794
         // Make sure queue processing is scheduled, recreate if not.
795
-        if ( ! wp_next_scheduled( 'ao_ccss_queue' ) ) {
796
-            wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' );
795
+        if (!wp_next_scheduled('ao_ccss_queue')) {
796
+            wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue');
797 797
         }
798 798
 
799 799
         // Queue cleaning.
800 800
         global $ao_ccss_queue;
801 801
         $queue_purge_threshold = 100;
802
-        $queue_purge_age       = 24 * 60 * 60;
803
-        $queue_length          = count( $ao_ccss_queue );
804
-        $timestamp_yesterday   = microtime( true ) - $queue_purge_age;
802
+        $queue_purge_age       = 24*60*60;
803
+        $queue_length          = count($ao_ccss_queue);
804
+        $timestamp_yesterday   = microtime(true) - $queue_purge_age;
805 805
         $remove_old_new        = false;
806 806
         $queue_altered         = false;
807 807
 
808
-        if ( $queue_length > $queue_purge_threshold ) {
808
+        if ($queue_length > $queue_purge_threshold) {
809 809
             $remove_old_new = true;
810 810
         }
811 811
 
812
-        foreach ( $ao_ccss_queue as $path => $job ) {
813
-            if ( ( $remove_old_new && 'NEW' == $job['jqstat'] && $job['jctime'] < $timestamp_yesterday ) || in_array( $job['jqstat'], array( 'JOB_FAILED', 'STATUS_JOB_BAD', 'NO_CSS', 'NO_RESPONSE' ) ) ) {
814
-                unset( $ao_ccss_queue[ $path ] );
812
+        foreach ($ao_ccss_queue as $path => $job) {
813
+            if (($remove_old_new && 'NEW' == $job['jqstat'] && $job['jctime'] < $timestamp_yesterday) || in_array($job['jqstat'], array('JOB_FAILED', 'STATUS_JOB_BAD', 'NO_CSS', 'NO_RESPONSE'))) {
814
+                unset($ao_ccss_queue[$path]);
815 815
                 $queue_altered = true;
816 816
             }
817 817
         }
818 818
 
819 819
         // save queue to options!
820
-        if ( $queue_altered ) {
821
-            $ao_ccss_queue_raw = json_encode( $ao_ccss_queue );
822
-            update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
823
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Queue cleaning done.', 3 );
820
+        if ($queue_altered) {
821
+            $ao_ccss_queue_raw = json_encode($ao_ccss_queue);
822
+            update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
823
+            autoptimizeCriticalCSSCore::ao_ccss_log('Queue cleaning done.', 3);
824 824
         }
825 825
 
826 826
         // re-check key if invalid.
827 827
         global $ao_ccss_keyst;
828
-        if ( 1 == $ao_ccss_keyst ) {
829
-            $this->ao_ccss_api_generate( '', '', '' );
828
+        if (1 == $ao_ccss_keyst) {
829
+            $this->ao_ccss_api_generate('', '', '');
830 830
         }
831 831
     }
832 832
 }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSEnqueue.php 2 patches
Doc Comments   +5 added lines patch added patch discarded remove patch
@@ -221,6 +221,11 @@
 block discarded – undo
221 221
         return $page_type;
222 222
     }
223 223
 
224
+    /**
225
+     * @param string $path
226
+     * @param false|string $target
227
+     * @param boolean $create
228
+     */
224 229
     public function ao_ccss_define_job( $path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create ) {
225 230
         // Define a job entry to be created or updated
226 231
         // Define commom job properties.
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS job enqueue logic.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -12,27 +12,27 @@  discard block
 block discarded – undo
12 12
     {
13 13
         // fetch all options at once and populate them individually explicitely as globals.
14 14
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
15
-        foreach ( $all_options as $_option => $_value ) {
15
+        foreach ($all_options as $_option => $_value) {
16 16
             global ${$_option};
17 17
             ${$_option} = $_value;
18 18
         }
19 19
     }
20 20
 
21
-    public static function ao_ccss_enqueue( $hash ) {
21
+    public static function ao_ccss_enqueue($hash) {
22 22
         $self = new self();
23 23
         // Get key status.
24
-        $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( false );
24
+        $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(false);
25 25
 
26 26
         // Queue is available to anyone...
27 27
         $enqueue = true;
28 28
 
29 29
         // ... which are not the ones below.
30
-        if ( is_user_logged_in() || is_feed() || is_404() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || $self->ao_ccss_ua() || 'nokey' == $key['status'] || 'invalid' == $key['status'] ) {
30
+        if (is_user_logged_in() || is_feed() || is_404() || (defined('DOING_AJAX') && DOING_AJAX) || $self->ao_ccss_ua() || 'nokey' == $key['status'] || 'invalid' == $key['status']) {
31 31
             $enqueue = false;
32
-            autoptimizeCriticalCSSCore::ao_ccss_log( "Job queuing is not available for WordPress's logged in users, feeds, error pages, ajax calls, to criticalcss.com itself or when a valid API key is not found", 3 );
32
+            autoptimizeCriticalCSSCore::ao_ccss_log("Job queuing is not available for WordPress's logged in users, feeds, error pages, ajax calls, to criticalcss.com itself or when a valid API key is not found", 3);
33 33
         }
34 34
 
35
-        if ( $enqueue ) {
35
+        if ($enqueue) {
36 36
             // Continue if queue is available
37 37
             // Attach required arrays/ vars.
38 38
             global $ao_ccss_rules;
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
             global $ao_ccss_forcepath;
42 42
 
43 43
             // Get request path and page type, and initialize the queue update flag.
44
-            $req_path        = strtok( $_SERVER['REQUEST_URI'], '?' );
44
+            $req_path        = strtok($_SERVER['REQUEST_URI'], '?');
45 45
             $req_type        = $self->ao_ccss_get_type();
46 46
             $job_qualify     = false;
47 47
             $target_rule     = false;
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
             $queue_update    = false;
50 50
 
51 51
             // Match for paths in rules.
52
-            foreach ( $ao_ccss_rules['paths'] as $path => $props ) {
52
+            foreach ($ao_ccss_rules['paths'] as $path => $props) {
53 53
 
54 54
                 // Prepare rule target and log.
55
-                $target_rule = 'paths|' . $path;
56
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Qualifying path <' . $req_path . '> for job submission by rule <' . $target_rule . '>', 3 );
55
+                $target_rule = 'paths|'.$path;
56
+                autoptimizeCriticalCSSCore::ao_ccss_log('Qualifying path <'.$req_path.'> for job submission by rule <'.$target_rule.'>', 3);
57 57
 
58 58
                 // Path match
59 59
                 // -> exact match needed for AUTO rules
60 60
                 // -> partial match OK for MANUAL rules (which have empty hash and a file with CCSS).
61
-                if ( $path === $req_path || ( false == $props['hash'] && false != $props['file'] && preg_match( '|' . $path . '|', $req_path ) ) ) {
61
+                if ($path === $req_path || (false == $props['hash'] && false != $props['file'] && preg_match('|'.$path.'|', $req_path))) {
62 62
 
63 63
                     // There's a path match in the rule, so job QUALIFIES with a path rule match.
64 64
                     $job_qualify     = true;
65 65
                     $rule_properties = $props;
66
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Path <' . $req_path . '> QUALIFIED for job submission by rule <' . $target_rule . '>', 3 );
66
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Path <'.$req_path.'> QUALIFIED for job submission by rule <'.$target_rule.'>', 3);
67 67
 
68 68
                     // Stop processing other path rules.
69 69
                     break;
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
             }
72 72
 
73 73
             // Match for types in rules if no path rule matches and if we're not enforcing paths.
74
-            if ( ! $job_qualify && ( ! $ao_ccss_forcepath || ! in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) || ! apply_filters( 'autoptimize_filter_ccss_coreenqueue_ignorealltypes', false ) ) ) {
75
-                foreach ( $ao_ccss_rules['types'] as $type => $props ) {
74
+            if (!$job_qualify && (!$ao_ccss_forcepath || !in_array($req_type, apply_filters('autoptimize_filter_ccss_coreenqueue_forcepathfortype', array('is_page'))) || !apply_filters('autoptimize_filter_ccss_coreenqueue_ignorealltypes', false))) {
75
+                foreach ($ao_ccss_rules['types'] as $type => $props) {
76 76
 
77 77
                     // Prepare rule target and log.
78
-                    $target_rule = 'types|' . $type;
79
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'Qualifying page type <' . $req_type . '> on path <' . $req_path . '> for job submission by rule <' . $target_rule . '>', 3 );
78
+                    $target_rule = 'types|'.$type;
79
+                    autoptimizeCriticalCSSCore::ao_ccss_log('Qualifying page type <'.$req_type.'> on path <'.$req_path.'> for job submission by rule <'.$target_rule.'>', 3);
80 80
 
81
-                    if ( $req_type == $type ) {
81
+                    if ($req_type == $type) {
82 82
                         // Type match.
83 83
                         // There's a type match in the rule, so job QUALIFIES with a type rule match.
84 84
                         $job_qualify     = true;
85 85
                         $rule_properties = $props;
86
-                        autoptimizeCriticalCSSCore::ao_ccss_log( 'Page type <' . $req_type . '> on path <' . $req_path . '> QUALIFIED for job submission by rule <' . $target_rule . '>', 3 );
86
+                        autoptimizeCriticalCSSCore::ao_ccss_log('Page type <'.$req_type.'> on path <'.$req_path.'> QUALIFIED for job submission by rule <'.$target_rule.'>', 3);
87 87
 
88 88
                         // Stop processing other type rules.
89 89
                         break;
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
                 }
92 92
             }
93 93
 
94
-            if ( $job_qualify && false == $rule_properties['hash'] && false != $rule_properties['file'] ) {
94
+            if ($job_qualify && false == $rule_properties['hash'] && false != $rule_properties['file']) {
95 95
                 // If job qualifies but rule hash is false and file isn't false  (MANUAL rule), job does not qualify despite what previous evaluations says.
96 96
                 $job_qualify = false;
97
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission DISQUALIFIED by MANUAL rule <' . $target_rule . '> with hash <' . $rule_properties['hash'] . '> and file <' . $rule_properties['file'] . '>', 3 );
98
-            } elseif ( ! $job_qualify && empty( $rule_properties ) ) {
97
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission DISQUALIFIED by MANUAL rule <'.$target_rule.'> with hash <'.$rule_properties['hash'].'> and file <'.$rule_properties['file'].'>', 3);
98
+            } elseif (!$job_qualify && empty($rule_properties)) {
99 99
                 // But if job does not qualify and rule properties are set, job qualifies as there is no matching rule for it yet
100 100
                 // Fill-in the new target rule.
101 101
                 $job_qualify = true;
@@ -103,28 +103,28 @@  discard block
 block discarded – undo
103 103
                 // Should we switch to path-base AUTO-rules? Conditions:
104 104
                 // 1. forcepath option has to be enabled (off by default)
105 105
                 // 2. request type should be (by default, but filterable) one of is_page (removed for now: woo_is_product or woo_is_product_category).
106
-                if ( ( $ao_ccss_forcepath && in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) ) || apply_filters( 'autoptimize_filter_ccss_coreenqueue_ignorealltypes', false ) ) {
107
-                    if ( '/' !== $req_path ) {
108
-                        $target_rule = 'paths|' . $req_path;
106
+                if (($ao_ccss_forcepath && in_array($req_type, apply_filters('autoptimize_filter_ccss_coreenqueue_forcepathfortype', array('is_page')))) || apply_filters('autoptimize_filter_ccss_coreenqueue_ignorealltypes', false)) {
107
+                    if ('/' !== $req_path) {
108
+                        $target_rule = 'paths|'.$req_path;
109 109
                     } else {
110 110
                         // Exception; we don't want a path-based rule for "/" as that messes things up, hard-switch this to a type-based is_front_page rule.
111
-                        $target_rule = 'types|' . 'is_front_page';
111
+                        $target_rule = 'types|'.'is_front_page';
112 112
                     }
113 113
                 } else {
114
-                    $target_rule = 'types|' . $req_type;
114
+                    $target_rule = 'types|'.$req_type;
115 115
                 }
116
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission QUALIFIED by MISSING rule for page type <' . $req_type . '> on path <' . $req_path . '>, new rule target is <' . $target_rule . '>', 3 );
116
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission QUALIFIED by MISSING rule for page type <'.$req_type.'> on path <'.$req_path.'>, new rule target is <'.$target_rule.'>', 3);
117 117
             } else {
118 118
                 // Or just log a job qualified by a matching rule.
119
-                autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission QUALIFIED by AUTO rule <' . $target_rule . '> with hash <' . $rule_properties['hash'] . '> and file <' . $rule_properties['file'] . '>', 3 );
119
+                autoptimizeCriticalCSSCore::ao_ccss_log('Job submission QUALIFIED by AUTO rule <'.$target_rule.'> with hash <'.$rule_properties['hash'].'> and file <'.$rule_properties['file'].'>', 3);
120 120
             }
121 121
 
122 122
             // Submit job.
123
-            if ( $job_qualify ) {
124
-                if ( ! array_key_exists( $req_path, $ao_ccss_queue ) ) {
123
+            if ($job_qualify) {
124
+                if (!array_key_exists($req_path, $ao_ccss_queue)) {
125 125
                     // This is a NEW job
126 126
                     // Merge job into the queue.
127
-                    $ao_ccss_queue[ $req_path ] = $self->ao_ccss_define_job(
127
+                    $ao_ccss_queue[$req_path] = $self->ao_ccss_define_job(
128 128
                         $req_path,
129 129
                         $target_rule,
130 130
                         $req_type,
@@ -140,30 +140,30 @@  discard block
 block discarded – undo
140 140
                 } else {
141 141
                     // This is an existing job
142 142
                     // The job is still NEW, most likely this is extra CSS file for the same page that needs a hash.
143
-                    if ( 'NEW' == $ao_ccss_queue[ $req_path ]['jqstat'] ) {
143
+                    if ('NEW' == $ao_ccss_queue[$req_path]['jqstat']) {
144 144
                         // Add hash if it's not already in the job.
145
-                        if ( ! in_array( $hash, $ao_ccss_queue[ $req_path ]['hashes'] ) ) {
145
+                        if (!in_array($hash, $ao_ccss_queue[$req_path]['hashes'])) {
146 146
                             // Push new hash to its array and update flag.
147
-                            $queue_update = array_push( $ao_ccss_queue[ $req_path ]['hashes'], $hash );
147
+                            $queue_update = array_push($ao_ccss_queue[$req_path]['hashes'], $hash);
148 148
 
149 149
                             // Log job update.
150
-                            autoptimizeCriticalCSSCore::ao_ccss_log( 'Hashes UPDATED on local job id <' . $ao_ccss_queue[ $req_path ]['ljid'] . '>, job status NEW, target rule <' . $ao_ccss_queue[ $req_path ]['rtarget'] . '>, hash added: ' . $hash, 3 );
150
+                            autoptimizeCriticalCSSCore::ao_ccss_log('Hashes UPDATED on local job id <'.$ao_ccss_queue[$req_path]['ljid'].'>, job status NEW, target rule <'.$ao_ccss_queue[$req_path]['rtarget'].'>, hash added: '.$hash, 3);
151 151
 
152 152
                             // Return from here as the hash array is already updated.
153 153
                             return true;
154 154
                         }
155
-                    } elseif ( 'NEW' != $ao_ccss_queue[ $req_path ]['jqstat'] && 'JOB_QUEUED' != $ao_ccss_queue[ $req_path ]['jqstat'] && 'JOB_ONGOING' != $ao_ccss_queue[ $req_path ]['jqstat'] ) {
155
+                    } elseif ('NEW' != $ao_ccss_queue[$req_path]['jqstat'] && 'JOB_QUEUED' != $ao_ccss_queue[$req_path]['jqstat'] && 'JOB_ONGOING' != $ao_ccss_queue[$req_path]['jqstat']) {
156 156
                         // Allow requeuing jobs that are not NEW, JOB_QUEUED or JOB_ONGOING
157 157
                         // Merge new job keeping some previous job values.
158
-                        $ao_ccss_queue[ $req_path ] = $self->ao_ccss_define_job(
158
+                        $ao_ccss_queue[$req_path] = $self->ao_ccss_define_job(
159 159
                             $req_path,
160 160
                             $target_rule,
161 161
                             $req_type,
162 162
                             $hash,
163
-                            $ao_ccss_queue[ $req_path ]['file'],
164
-                            $ao_ccss_queue[ $req_path ]['jid'],
165
-                            $ao_ccss_queue[ $req_path ]['jrstat'],
166
-                            $ao_ccss_queue[ $req_path ]['jvstat'],
163
+                            $ao_ccss_queue[$req_path]['file'],
164
+                            $ao_ccss_queue[$req_path]['jid'],
165
+                            $ao_ccss_queue[$req_path]['jrstat'],
166
+                            $ao_ccss_queue[$req_path]['jvstat'],
167 167
                             false
168 168
                         );
169 169
                         // Set update flag.
@@ -171,14 +171,14 @@  discard block
 block discarded – undo
171 171
                     }
172 172
                 }
173 173
 
174
-                if ( $queue_update ) {
174
+                if ($queue_update) {
175 175
                     // Persist the job to the queue and return.
176
-                    $ao_ccss_queue_raw = json_encode( $ao_ccss_queue );
177
-                    update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false );
176
+                    $ao_ccss_queue_raw = json_encode($ao_ccss_queue);
177
+                    update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false);
178 178
                     return true;
179 179
                 } else {
180 180
                     // Or just return false if no job was added.
181
-                    autoptimizeCriticalCSSCore::ao_ccss_log( 'A job for path <' . $req_path . '> already exist with NEW or PENDING status, skipping job creation', 3 );
181
+                    autoptimizeCriticalCSSCore::ao_ccss_log('A job for path <'.$req_path.'> already exist with NEW or PENDING status, skipping job creation', 3);
182 182
                     return false;
183 183
                 }
184 184
             }
@@ -194,25 +194,25 @@  discard block
 block discarded – undo
194 194
         $page_type = false;
195 195
 
196 196
         // Iterates over the array to match a type.
197
-        foreach ( $ao_ccss_types as $type ) {
198
-            if ( is_404() ) {
197
+        foreach ($ao_ccss_types as $type) {
198
+            if (is_404()) {
199 199
                 $page_type = 'is_404';
200 200
                 break;
201
-            } elseif ( strpos( $type, 'custom_post_' ) !== false ) {
201
+            } elseif (strpos($type, 'custom_post_') !== false) {
202 202
                 // Match custom post types.
203
-                if ( get_post_type( get_the_ID() ) === substr( $type, 12 ) ) {
203
+                if (get_post_type(get_the_ID()) === substr($type, 12)) {
204 204
                     $page_type = $type;
205 205
                     break;
206 206
                 }
207
-            } elseif ( strpos( $type, 'template_' ) !== false ) {
207
+            } elseif (strpos($type, 'template_') !== false) {
208 208
                 // If templates; don't break, templates become manual-only rules.
209 209
             } else {
210 210
                 // Match all other existing types
211 211
                 // but remove prefix to be able to check if the function exists & returns true.
212
-                $_type = str_replace( array( 'woo_', 'bp_', 'bbp_', 'edd_' ), '', $type );
213
-                if ( function_exists( $_type ) && call_user_func( $_type ) ) {
212
+                $_type = str_replace(array('woo_', 'bp_', 'bbp_', 'edd_'), '', $type);
213
+                if (function_exists($_type) && call_user_func($_type)) {
214 214
                     // Make sure we only return is_front_page (and is_home) for one page, not for the "paged frontpage" (/page/2 ..).
215
-                    if ( ( 'is_front_page' !== $_type && 'is_home' !== $_type ) || ! is_paged() ) {
215
+                    if (('is_front_page' !== $_type && 'is_home' !== $_type) || !is_paged()) {
216 216
                         $page_type = $type;
217 217
                         break;
218 218
                     }
@@ -224,44 +224,44 @@  discard block
 block discarded – undo
224 224
         return $page_type;
225 225
     }
226 226
 
227
-    public function ao_ccss_define_job( $path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create ) {
227
+    public function ao_ccss_define_job($path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create) {
228 228
         // Define a job entry to be created or updated
229 229
         // Define commom job properties.
230 230
         $path            = array();
231 231
         $path['ljid']    = $this->ao_ccss_job_id();
232 232
         $path['rtarget'] = $target;
233 233
         $path['ptype']   = $type;
234
-        $path['hashes']  = array( $hash );
234
+        $path['hashes']  = array($hash);
235 235
         $path['hash']    = $hash;
236 236
         $path['file']    = $file;
237 237
         $path['jid']     = $jid;
238 238
         $path['jqstat']  = 'NEW';
239 239
         $path['jrstat']  = $jrstat;
240 240
         $path['jvstat']  = $jvstat;
241
-        $path['jctime']  = microtime( true );
241
+        $path['jctime']  = microtime(true);
242 242
         $path['jftime']  = null;
243 243
 
244 244
         // Set operation requested.
245
-        if ( $create ) {
245
+        if ($create) {
246 246
             $operation = 'CREATED';
247 247
         } else {
248 248
             $operation = 'UPDATED';
249 249
         }
250 250
 
251 251
         // Log job creation.
252
-        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job ' . $operation . ' with local job id <' . $path['ljid'] . '> for target rule <' . $target . '>', 3 );
252
+        autoptimizeCriticalCSSCore::ao_ccss_log('Job '.$operation.' with local job id <'.$path['ljid'].'> for target rule <'.$target.'>', 3);
253 253
 
254 254
         return $path;
255 255
     }
256 256
 
257
-    public function ao_ccss_job_id( $length = 6 ) {
257
+    public function ao_ccss_job_id($length = 6) {
258 258
         // Generate random strings for the local job ID
259 259
         // Based on https://stackoverflow.com/a/4356295 .
260 260
         $characters        = '0123456789abcdefghijklmnopqrstuvwxyz';
261
-        $characters_length = strlen( $characters );
261
+        $characters_length = strlen($characters);
262 262
         $random_string     = 'j-';
263
-        for ( $i = 0; $i < $length; $i++ ) {
264
-            $random_string .= $characters[ rand( 0, $characters_length - 1 ) ];
263
+        for ($i = 0; $i < $length; $i++) {
264
+            $random_string .= $characters[rand(0, $characters_length - 1)];
265 265
         }
266 266
         return $random_string;
267 267
     }
@@ -269,17 +269,17 @@  discard block
 block discarded – undo
269 269
     public function ao_ccss_ua() {
270 270
         // Check for criticalcss.com user agent.
271 271
         $agent = '';
272
-        if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
272
+        if (isset($_SERVER['HTTP_USER_AGENT'])) {
273 273
             $agent = $_SERVER['HTTP_USER_AGENT'];
274 274
         }
275 275
 
276 276
         // Check for UA and return TRUE when criticalcss.com is the detected UA, false when not.
277
-        $rtn = strpos( $agent, AO_CCSS_URL );
278
-        if ( 0 === $rtn ) {
277
+        $rtn = strpos($agent, AO_CCSS_URL);
278
+        if (0 === $rtn) {
279 279
             $rtn = true;
280 280
         } else {
281 281
             $rtn = false;
282 282
         }
283
-        return ( $rtn );
283
+        return ($rtn);
284 284
     }
285 285
 }
Please login to merge, or discard this patch.
classes/autoptimizeScripts.php 2 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -676,6 +676,9 @@  discard block
 block discarded – undo
676 676
         return true;
677 677
     }
678 678
 
679
+    /**
680
+     * @param string $tag
681
+     */
679 682
     private function movetolast( $tag )
680 683
     {
681 684
         if ( empty( $tag ) ) {
@@ -733,7 +736,7 @@  discard block
 block discarded – undo
733 736
      * @param string $filepath Filepath.
734 737
      * @param bool   $cache_miss Optional. Force a cache miss. Default false.
735 738
      *
736
-     * @return bool|string Url pointing to the minified js file or false.
739
+     * @return false|string Url pointing to the minified js file or false.
737 740
      */
738 741
     public function minify_single( $filepath, $cache_miss = false )
739 742
     {
Please login to merge, or discard this patch.
Spacing   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Class for JS optimization.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -198,127 +198,127 @@  discard block
 block discarded – undo
198 198
      *
199 199
      * @param array $options all options.
200 200
      */
201
-    public function read( $options )
201
+    public function read($options)
202 202
     {
203
-        $noptimize_js = apply_filters( 'autoptimize_filter_js_noptimize', false, $this->content );
204
-        if ( $noptimize_js ) {
203
+        $noptimize_js = apply_filters('autoptimize_filter_js_noptimize', false, $this->content);
204
+        if ($noptimize_js) {
205 205
             return false;
206 206
         }
207 207
 
208 208
         // only optimize known good JS?
209
-        $whitelist_js = apply_filters( 'autoptimize_filter_js_whitelist', '', $this->content );
210
-        if ( ! empty( $whitelist_js ) ) {
211
-            $this->whitelist = array_filter( array_map( 'trim', explode( ',', $whitelist_js ) ) );
209
+        $whitelist_js = apply_filters('autoptimize_filter_js_whitelist', '', $this->content);
210
+        if (!empty($whitelist_js)) {
211
+            $this->whitelist = array_filter(array_map('trim', explode(',', $whitelist_js)));
212 212
         }
213 213
 
214 214
         // is there JS we should simply remove?
215
-        $removable_js = apply_filters( 'autoptimize_filter_js_removables', '', $this->content );
216
-        if ( ! empty( $removable_js ) ) {
217
-            $this->jsremovables = array_filter( array_map( 'trim', explode( ',', $removable_js ) ) );
215
+        $removable_js = apply_filters('autoptimize_filter_js_removables', '', $this->content);
216
+        if (!empty($removable_js)) {
217
+            $this->jsremovables = array_filter(array_map('trim', explode(',', $removable_js)));
218 218
         }
219 219
 
220 220
         // only header?
221
-        if ( apply_filters( 'autoptimize_filter_js_justhead', $options['justhead'] ) ) {
222
-            $content             = explode( '</head>', $this->content, 2 );
223
-            $this->content       = $content[0] . '</head>';
221
+        if (apply_filters('autoptimize_filter_js_justhead', $options['justhead'])) {
222
+            $content             = explode('</head>', $this->content, 2);
223
+            $this->content       = $content[0].'</head>';
224 224
             $this->restofcontent = $content[1];
225 225
         }
226 226
 
227 227
         // Determine whether we're doing JS-files aggregation or not.
228
-        if ( ! $options['aggregate'] ) {
228
+        if (!$options['aggregate']) {
229 229
             $this->aggregate = false;
230 230
         }
231 231
         // Returning true for "dontaggregate" turns off aggregation.
232
-        if ( $this->aggregate && apply_filters( 'autoptimize_filter_js_dontaggregate', false ) ) {
232
+        if ($this->aggregate && apply_filters('autoptimize_filter_js_dontaggregate', false)) {
233 233
             $this->aggregate = false;
234 234
         }
235 235
 
236 236
         // include inline?
237
-        if ( apply_filters( 'autoptimize_js_include_inline', $options['include_inline'] ) ) {
237
+        if (apply_filters('autoptimize_js_include_inline', $options['include_inline'])) {
238 238
             $this->include_inline = true;
239 239
         }
240 240
 
241 241
         // filter to "late inject minified JS", default to true for now (it is faster).
242
-        $this->inject_min_late = apply_filters( 'autoptimize_filter_js_inject_min_late', true );
242
+        $this->inject_min_late = apply_filters('autoptimize_filter_js_inject_min_late', true);
243 243
 
244 244
         // filters to override hardcoded do(nt)move(last) array contents (array in, array out!).
245
-        $this->dontmove   = apply_filters( 'autoptimize_filter_js_dontmove', $this->dontmove );
246
-        $this->domovelast = apply_filters( 'autoptimize_filter_js_movelast', $this->domovelast );
247
-        $this->domove     = apply_filters( 'autoptimize_filter_js_domove', $this->domove );
245
+        $this->dontmove   = apply_filters('autoptimize_filter_js_dontmove', $this->dontmove);
246
+        $this->domovelast = apply_filters('autoptimize_filter_js_movelast', $this->domovelast);
247
+        $this->domove     = apply_filters('autoptimize_filter_js_domove', $this->domove);
248 248
 
249 249
         // Determine whether excluded files should be minified if not yet so.
250
-        if ( ! $options['minify_excluded'] && $options['aggregate'] ) {
250
+        if (!$options['minify_excluded'] && $options['aggregate']) {
251 251
             $this->minify_excluded = false;
252 252
         }
253
-        $this->minify_excluded = apply_filters( 'autoptimize_filter_js_minify_excluded', $this->minify_excluded, '' );
253
+        $this->minify_excluded = apply_filters('autoptimize_filter_js_minify_excluded', $this->minify_excluded, '');
254 254
 
255 255
         // get extra exclusions settings or filter.
256 256
         $exclude_js = $options['js_exclude'];
257
-        $exclude_js = apply_filters( 'autoptimize_filter_js_exclude', $exclude_js, $this->content );
258
-
259
-        if ( '' !== $exclude_js ) {
260
-            if ( is_array( $exclude_js ) ) {
261
-                $remove_keys = array_keys( $exclude_js, 'remove' );
262
-                if ( false !== $remove_keys ) {
263
-                    foreach ( $remove_keys as $remove_key ) {
264
-                        unset( $exclude_js[ $remove_key ] );
257
+        $exclude_js = apply_filters('autoptimize_filter_js_exclude', $exclude_js, $this->content);
258
+
259
+        if ('' !== $exclude_js) {
260
+            if (is_array($exclude_js)) {
261
+                $remove_keys = array_keys($exclude_js, 'remove');
262
+                if (false !== $remove_keys) {
263
+                    foreach ($remove_keys as $remove_key) {
264
+                        unset($exclude_js[$remove_key]);
265 265
                         $this->jsremovables[] = $remove_key;
266 266
                     }
267 267
                 }
268
-                $excl_js_arr = array_keys( $exclude_js );
268
+                $excl_js_arr = array_keys($exclude_js);
269 269
             } else {
270
-                $excl_js_arr = array_filter( array_map( 'trim', explode( ',', $exclude_js ) ) );
270
+                $excl_js_arr = array_filter(array_map('trim', explode(',', $exclude_js)));
271 271
             }
272
-            $this->dontmove = array_merge( $excl_js_arr, $this->dontmove );
272
+            $this->dontmove = array_merge($excl_js_arr, $this->dontmove);
273 273
         }
274 274
 
275 275
         // Should we add try-catch?
276
-        if ( $options['trycatch'] ) {
276
+        if ($options['trycatch']) {
277 277
             $this->trycatch = true;
278 278
         }
279 279
 
280 280
         // force js in head?
281
-        if ( $options['forcehead'] ) {
281
+        if ($options['forcehead']) {
282 282
             $this->forcehead = true;
283 283
         } else {
284 284
             $this->forcehead = false;
285 285
         }
286 286
 
287
-        $this->forcehead = apply_filters( 'autoptimize_filter_js_forcehead', $this->forcehead );
287
+        $this->forcehead = apply_filters('autoptimize_filter_js_forcehead', $this->forcehead);
288 288
 
289 289
         // get cdn url.
290 290
         $this->cdn_url = $options['cdn_url'];
291 291
 
292 292
         // noptimize me.
293
-        $this->content = $this->hide_noptimize( $this->content );
293
+        $this->content = $this->hide_noptimize($this->content);
294 294
 
295 295
         // Save IE hacks.
296
-        $this->content = $this->hide_iehacks( $this->content );
296
+        $this->content = $this->hide_iehacks($this->content);
297 297
 
298 298
         // comments.
299
-        $this->content = $this->hide_comments( $this->content );
299
+        $this->content = $this->hide_comments($this->content);
300 300
 
301 301
         // Get script files.
302
-        if ( preg_match_all( '#<script.*</script>#Usmi', $this->content, $matches ) ) {
303
-            foreach ( $matches[0] as $tag ) {
302
+        if (preg_match_all('#<script.*</script>#Usmi', $this->content, $matches)) {
303
+            foreach ($matches[0] as $tag) {
304 304
                 // only consider script aggregation for types whitelisted in should_aggregate-function.
305
-                $should_aggregate = $this->should_aggregate( $tag );
306
-                if ( ! $should_aggregate ) {
305
+                $should_aggregate = $this->should_aggregate($tag);
306
+                if (!$should_aggregate) {
307 307
                     $tag = '';
308 308
                     continue;
309 309
                 }
310 310
 
311
-                if ( preg_match( '#<script[^>]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source ) ) {
311
+                if (preg_match('#<script[^>]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source)) {
312 312
                     // non-inline script.
313
-                    if ( $this->isremovable( $tag, $this->jsremovables ) ) {
314
-                        $this->content = str_replace( $tag, '', $this->content );
313
+                    if ($this->isremovable($tag, $this->jsremovables)) {
314
+                        $this->content = str_replace($tag, '', $this->content);
315 315
                         continue;
316 316
                     }
317 317
 
318 318
                     $orig_tag = null;
319
-                    $url      = current( explode( '?', $source[2], 2 ) );
320
-                    $path     = $this->getpath( $url );
321
-                    if ( false !== $path && preg_match( '#\.js$#', $path ) && $this->ismergeable( $tag ) ) {
319
+                    $url      = current(explode('?', $source[2], 2));
320
+                    $path     = $this->getpath($url);
321
+                    if (false !== $path && preg_match('#\.js$#', $path) && $this->ismergeable($tag)) {
322 322
                         // ok to optimize, add to array.
323 323
                         $this->scripts[] = $path;
324 324
                     } else {
@@ -326,11 +326,11 @@  discard block
 block discarded – undo
326 326
                         $new_tag  = $tag;
327 327
 
328 328
                         // non-mergeable script (excluded or dynamic or external).
329
-                        if ( is_array( $exclude_js ) ) {
329
+                        if (is_array($exclude_js)) {
330 330
                             // should we add flags?
331
-                            foreach ( $exclude_js as $excl_tag => $excl_flags ) {
332
-                                if ( false !== strpos( $orig_tag, $excl_tag ) && in_array( $excl_flags, array( 'async', 'defer' ) ) ) {
333
-                                    $new_tag = str_replace( '<script ', '<script ' . $excl_flags . ' ', $new_tag );
331
+                            foreach ($exclude_js as $excl_tag => $excl_flags) {
332
+                                if (false !== strpos($orig_tag, $excl_tag) && in_array($excl_flags, array('async', 'defer'))) {
333
+                                    $new_tag = str_replace('<script ', '<script '.$excl_flags.' ', $new_tag);
334 334
                                 }
335 335
                             }
336 336
                         }
@@ -338,14 +338,14 @@  discard block
 block discarded – undo
338 338
                         // Should we minify the non-aggregated script?
339 339
                         // -> if aggregate is on and exclude minify is on
340 340
                         // -> if aggregate is off and the file is not in dontmove.
341
-                        if ( $path && $this->minify_excluded ) {
342
-                            $consider_minified_array = apply_filters( 'autoptimize_filter_js_consider_minified', false );
343
-                            if ( ( false === $this->aggregate && str_replace( $this->dontmove, '', $path ) === $path ) || ( true === $this->aggregate && ( false === $consider_minified_array || str_replace( $consider_minified_array, '', $path ) === $path ) ) ) {
344
-                                $minified_url = $this->minify_single( $path );
345
-                                if ( ! empty( $minified_url ) ) {
341
+                        if ($path && $this->minify_excluded) {
342
+                            $consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified', false);
343
+                            if ((false === $this->aggregate && str_replace($this->dontmove, '', $path) === $path) || (true === $this->aggregate && (false === $consider_minified_array || str_replace($consider_minified_array, '', $path) === $path))) {
344
+                                $minified_url = $this->minify_single($path);
345
+                                if (!empty($minified_url)) {
346 346
                                     // Replace original URL with minified URL from cache.
347
-                                    $new_tag = str_replace( $url, $minified_url, $new_tag );
348
-                                } elseif ( apply_filters( 'autoptimize_filter_ccsjs_remove_empty_minified_url', false ) ) {
347
+                                    $new_tag = str_replace($url, $minified_url, $new_tag);
348
+                                } elseif (apply_filters('autoptimize_filter_ccsjs_remove_empty_minified_url', false)) {
349 349
                                     // Remove the original script tag, because cache content is empty but only if filter
350 350
                                     // is trued because $minified_url is also false if original JS is minified already.
351 351
                                     $new_tag = '';
@@ -353,17 +353,17 @@  discard block
 block discarded – undo
353 353
                             }
354 354
                         }
355 355
 
356
-                        if ( $this->ismovable( $new_tag ) ) {
356
+                        if ($this->ismovable($new_tag)) {
357 357
                             // can be moved, flags and all.
358
-                            if ( $this->movetolast( $new_tag ) ) {
358
+                            if ($this->movetolast($new_tag)) {
359 359
                                 $this->move['last'][] = $new_tag;
360 360
                             } else {
361 361
                                 $this->move['first'][] = $new_tag;
362 362
                             }
363 363
                         } else {
364 364
                             // cannot be moved, so if flag was added re-inject altered tag immediately.
365
-                            if ( ( '' !== $new_tag && $orig_tag !== $new_tag ) || ( '' === $new_tag && apply_filters( 'autoptimize_filter_js_remove_empty_files', false ) ) ) {
366
-                                $this->content = str_replace( $orig_tag, $new_tag, $this->content );
365
+                            if (('' !== $new_tag && $orig_tag !== $new_tag) || ('' === $new_tag && apply_filters('autoptimize_filter_js_remove_empty_files', false))) {
366
+                                $this->content = str_replace($orig_tag, $new_tag, $this->content);
367 367
                                 $orig_tag      = '';
368 368
                             }
369 369
                             // and forget about the $tag (not to be touched any more).
@@ -372,23 +372,23 @@  discard block
 block discarded – undo
372 372
                     }
373 373
                 } else {
374 374
                     // Inline script.
375
-                    if ( $this->isremovable( $tag, $this->jsremovables ) ) {
376
-                        $this->content = str_replace( $tag, '', $this->content );
375
+                    if ($this->isremovable($tag, $this->jsremovables)) {
376
+                        $this->content = str_replace($tag, '', $this->content);
377 377
                         continue;
378 378
                     }
379 379
 
380 380
                     // unhide comments, as javascript may be wrapped in comment-tags for old times' sake.
381
-                    $tag = $this->restore_comments( $tag );
382
-                    if ( $this->ismergeable( $tag ) && $this->include_inline ) {
383
-                        preg_match( '#<script.*>(.*)</script>#Usmi', $tag, $code );
384
-                        $code            = preg_replace( '#.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*#sm', '$1', $code[1] );
385
-                        $code            = preg_replace( '/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $code );
386
-                        $this->scripts[] = 'INLINE;' . $code;
381
+                    $tag = $this->restore_comments($tag);
382
+                    if ($this->ismergeable($tag) && $this->include_inline) {
383
+                        preg_match('#<script.*>(.*)</script>#Usmi', $tag, $code);
384
+                        $code            = preg_replace('#.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*#sm', '$1', $code[1]);
385
+                        $code            = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $code);
386
+                        $this->scripts[] = 'INLINE;'.$code;
387 387
                     } else {
388 388
                         // Can we move this?
389
-                        $autoptimize_js_moveable = apply_filters( 'autoptimize_js_moveable', '', $tag );
390
-                        if ( $this->ismovable( $tag ) || '' !== $autoptimize_js_moveable ) {
391
-                            if ( $this->movetolast( $tag ) || 'last' === $autoptimize_js_moveable ) {
389
+                        $autoptimize_js_moveable = apply_filters('autoptimize_js_moveable', '', $tag);
390
+                        if ($this->ismovable($tag) || '' !== $autoptimize_js_moveable) {
391
+                            if ($this->movetolast($tag) || 'last' === $autoptimize_js_moveable) {
392 392
                                 $this->move['last'][] = $tag;
393 393
                             } else {
394 394
                                 $this->move['first'][] = $tag;
@@ -399,11 +399,11 @@  discard block
 block discarded – undo
399 399
                         }
400 400
                     }
401 401
                     // Re-hide comments to be able to do the removal based on tag from $this->content.
402
-                    $tag = $this->hide_comments( $tag );
402
+                    $tag = $this->hide_comments($tag);
403 403
                 }
404 404
 
405 405
                 // Remove the original script tag.
406
-                $this->content = str_replace( $tag, '', $this->content );
406
+                $this->content = str_replace($tag, '', $this->content);
407 407
             }
408 408
 
409 409
             return true;
@@ -428,30 +428,30 @@  discard block
 block discarded – undo
428 428
      * @param string $tag Script node & child(ren).
429 429
      * @return bool
430 430
      */
431
-    public function should_aggregate( $tag )
431
+    public function should_aggregate($tag)
432 432
     {
433
-        if ( empty( $tag ) ) {
433
+        if (empty($tag)) {
434 434
             return false;
435 435
         }
436 436
 
437 437
         // We're only interested in the type attribute of the <script> tag itself, not any possible
438 438
         // inline code that might just contain the 'type=' string...
439 439
         $tag_parts = array();
440
-        preg_match( '#<(script[^>]*)>#i', $tag, $tag_parts );
440
+        preg_match('#<(script[^>]*)>#i', $tag, $tag_parts);
441 441
         $tag_without_contents = null;
442
-        if ( ! empty( $tag_parts[1] ) ) {
442
+        if (!empty($tag_parts[1])) {
443 443
             $tag_without_contents = $tag_parts[1];
444 444
         }
445 445
 
446
-        $has_type = ( strpos( $tag_without_contents, 'type' ) !== false );
446
+        $has_type = (strpos($tag_without_contents, 'type') !== false);
447 447
 
448 448
         $type_valid = false;
449
-        if ( $has_type ) {
450
-            $type_valid = (bool) preg_match( '/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $tag_without_contents );
449
+        if ($has_type) {
450
+            $type_valid = (bool) preg_match('/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $tag_without_contents);
451 451
         }
452 452
 
453 453
         $should_aggregate = false;
454
-        if ( ! $has_type || $type_valid ) {
454
+        if (!$has_type || $type_valid) {
455 455
             $should_aggregate = true;
456 456
         }
457 457
 
@@ -463,75 +463,75 @@  discard block
 block discarded – undo
463 463
      */
464 464
     public function minify()
465 465
     {
466
-        foreach ( $this->scripts as $script ) {
467
-            if ( empty( $script ) ) {
466
+        foreach ($this->scripts as $script) {
467
+            if (empty($script)) {
468 468
                 continue;
469 469
             }
470 470
 
471 471
             // TODO/FIXME: some duplicate code here, can be reduced/simplified.
472
-            if ( preg_match( '#^INLINE;#', $script ) ) {
472
+            if (preg_match('#^INLINE;#', $script)) {
473 473
                 // Inline script.
474
-                $script = preg_replace( '#^INLINE;#', '', $script );
475
-                $script = rtrim( $script, ";\n\t\r" ) . ';';
474
+                $script = preg_replace('#^INLINE;#', '', $script);
475
+                $script = rtrim($script, ";\n\t\r").';';
476 476
                 // Add try-catch?
477
-                if ( $this->trycatch ) {
478
-                    $script = 'try{' . $script . '}catch(e){}';
477
+                if ($this->trycatch) {
478
+                    $script = 'try{'.$script.'}catch(e){}';
479 479
                 }
480
-                $tmpscript = apply_filters( 'autoptimize_js_individual_script', $script, '' );
481
-                if ( has_filter( 'autoptimize_js_individual_script' ) && ! empty( $tmpscript ) ) {
480
+                $tmpscript = apply_filters('autoptimize_js_individual_script', $script, '');
481
+                if (has_filter('autoptimize_js_individual_script') && !empty($tmpscript)) {
482 482
                     $script                = $tmpscript;
483 483
                     $this->alreadyminified = true;
484 484
                 }
485
-                $this->jscode .= "\n" . $script;
485
+                $this->jscode .= "\n".$script;
486 486
             } else {
487 487
                 // External script.
488
-                if ( false !== $script && file_exists( $script ) && is_readable( $script ) ) {
489
-                    $scriptsrc = file_get_contents( $script );
490
-                    $scriptsrc = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $scriptsrc );
491
-                    $scriptsrc = rtrim( $scriptsrc, ";\n\t\r" ) . ';';
488
+                if (false !== $script && file_exists($script) && is_readable($script)) {
489
+                    $scriptsrc = file_get_contents($script);
490
+                    $scriptsrc = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $scriptsrc);
491
+                    $scriptsrc = rtrim($scriptsrc, ";\n\t\r").';';
492 492
                     // Add try-catch?
493
-                    if ( $this->trycatch ) {
494
-                        $scriptsrc = 'try{' . $scriptsrc . '}catch(e){}';
493
+                    if ($this->trycatch) {
494
+                        $scriptsrc = 'try{'.$scriptsrc.'}catch(e){}';
495 495
                     }
496
-                    $tmpscriptsrc = apply_filters( 'autoptimize_js_individual_script', $scriptsrc, $script );
497
-                    if ( has_filter( 'autoptimize_js_individual_script' ) && ! empty( $tmpscriptsrc ) ) {
496
+                    $tmpscriptsrc = apply_filters('autoptimize_js_individual_script', $scriptsrc, $script);
497
+                    if (has_filter('autoptimize_js_individual_script') && !empty($tmpscriptsrc)) {
498 498
                         $scriptsrc             = $tmpscriptsrc;
499 499
                         $this->alreadyminified = true;
500
-                    } elseif ( $this->can_inject_late( $script ) ) {
501
-                        $scriptsrc = self::build_injectlater_marker( $script, md5( $scriptsrc ) );
500
+                    } elseif ($this->can_inject_late($script)) {
501
+                        $scriptsrc = self::build_injectlater_marker($script, md5($scriptsrc));
502 502
                     }
503
-                    $this->jscode .= "\n" . $scriptsrc;
503
+                    $this->jscode .= "\n".$scriptsrc;
504 504
                 }
505 505
             }
506 506
         }
507 507
 
508 508
         // Check for already-minified code.
509
-        $this->md5hash = md5( $this->jscode );
510
-        $ccheck        = new autoptimizeCache( $this->md5hash, 'js' );
511
-        if ( $ccheck->check() ) {
509
+        $this->md5hash = md5($this->jscode);
510
+        $ccheck        = new autoptimizeCache($this->md5hash, 'js');
511
+        if ($ccheck->check()) {
512 512
             $this->jscode = $ccheck->retrieve();
513 513
             return true;
514 514
         }
515
-        unset( $ccheck );
515
+        unset($ccheck);
516 516
 
517 517
         // $this->jscode has all the uncompressed code now.
518
-        if ( true !== $this->alreadyminified ) {
519
-            if ( apply_filters( 'autoptimize_js_do_minify', true ) ) {
520
-                $tmp_jscode = trim( JSMin::minify( $this->jscode ) );
521
-                if ( ! empty( $tmp_jscode ) ) {
518
+        if (true !== $this->alreadyminified) {
519
+            if (apply_filters('autoptimize_js_do_minify', true)) {
520
+                $tmp_jscode = trim(JSMin::minify($this->jscode));
521
+                if (!empty($tmp_jscode)) {
522 522
                     $this->jscode = $tmp_jscode;
523
-                    unset( $tmp_jscode );
523
+                    unset($tmp_jscode);
524 524
                 }
525
-                $this->jscode = $this->inject_minified( $this->jscode );
526
-                $this->jscode = apply_filters( 'autoptimize_js_after_minify', $this->jscode );
525
+                $this->jscode = $this->inject_minified($this->jscode);
526
+                $this->jscode = apply_filters('autoptimize_js_after_minify', $this->jscode);
527 527
                 return true;
528 528
             } else {
529
-                $this->jscode = $this->inject_minified( $this->jscode );
529
+                $this->jscode = $this->inject_minified($this->jscode);
530 530
                 return false;
531 531
             }
532 532
         }
533 533
 
534
-        $this->jscode = apply_filters( 'autoptimize_js_after_minify', $this->jscode );
534
+        $this->jscode = apply_filters('autoptimize_js_after_minify', $this->jscode);
535 535
         return true;
536 536
     }
537 537
 
@@ -540,13 +540,13 @@  discard block
 block discarded – undo
540 540
      */
541 541
     public function cache()
542 542
     {
543
-        $cache = new autoptimizeCache( $this->md5hash, 'js' );
544
-        if ( ! $cache->check() ) {
543
+        $cache = new autoptimizeCache($this->md5hash, 'js');
544
+        if (!$cache->check()) {
545 545
             // Cache our code.
546
-            $cache->cache( $this->jscode, 'text/javascript' );
546
+            $cache->cache($this->jscode, 'text/javascript');
547 547
         }
548
-        $this->url = AUTOPTIMIZE_CACHE_URL . $cache->getname();
549
-        $this->url = $this->url_replace_cdn( $this->url );
548
+        $this->url = AUTOPTIMIZE_CACHE_URL.$cache->getname();
549
+        $this->url = $this->url_replace_cdn($this->url);
550 550
     }
551 551
 
552 552
     /**
@@ -555,47 +555,47 @@  discard block
 block discarded – undo
555 555
     public function getcontent()
556 556
     {
557 557
         // Restore the full content.
558
-        if ( ! empty( $this->restofcontent ) ) {
558
+        if (!empty($this->restofcontent)) {
559 559
             $this->content      .= $this->restofcontent;
560 560
             $this->restofcontent = '';
561 561
         }
562 562
 
563 563
         // Add the scripts taking forcehead/ deferred (default) into account.
564
-        if ( $this->forcehead ) {
565
-            $replace_tag = array( '</head>', 'before' );
564
+        if ($this->forcehead) {
565
+            $replace_tag = array('</head>', 'before');
566 566
             $defer       = '';
567 567
         } else {
568
-            $replace_tag = array( '</body>', 'before' );
568
+            $replace_tag = array('</body>', 'before');
569 569
             $defer       = 'defer ';
570 570
         }
571 571
 
572
-        $defer   = apply_filters( 'autoptimize_filter_js_defer', $defer );
572
+        $defer   = apply_filters('autoptimize_filter_js_defer', $defer);
573 573
         $type_js = '';
574
-        if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
574
+        if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
575 575
             $type_js = 'type="text/javascript" ';
576 576
         }
577 577
 
578
-        $bodyreplacementpayload = '<script ' . $type_js . $defer . 'src="' . $this->url . '"></script>';
579
-        $bodyreplacementpayload = apply_filters( 'autoptimize_filter_js_bodyreplacementpayload', $bodyreplacementpayload );
578
+        $bodyreplacementpayload = '<script '.$type_js.$defer.'src="'.$this->url.'"></script>';
579
+        $bodyreplacementpayload = apply_filters('autoptimize_filter_js_bodyreplacementpayload', $bodyreplacementpayload);
580 580
 
581
-        $bodyreplacement  = implode( '', $this->move['first'] );
581
+        $bodyreplacement  = implode('', $this->move['first']);
582 582
         $bodyreplacement .= $bodyreplacementpayload;
583
-        $bodyreplacement .= implode( '', $this->move['last'] );
583
+        $bodyreplacement .= implode('', $this->move['last']);
584 584
 
585
-        $replace_tag = apply_filters( 'autoptimize_filter_js_replacetag', $replace_tag );
585
+        $replace_tag = apply_filters('autoptimize_filter_js_replacetag', $replace_tag);
586 586
 
587
-        if ( strlen( $this->jscode ) > 0 ) {
588
-            $this->inject_in_html( $bodyreplacement, $replace_tag );
587
+        if (strlen($this->jscode) > 0) {
588
+            $this->inject_in_html($bodyreplacement, $replace_tag);
589 589
         }
590 590
 
591 591
         // Restore comments.
592
-        $this->content = $this->restore_comments( $this->content );
592
+        $this->content = $this->restore_comments($this->content);
593 593
 
594 594
         // Restore IE hacks.
595
-        $this->content = $this->restore_iehacks( $this->content );
595
+        $this->content = $this->restore_iehacks($this->content);
596 596
 
597 597
         // Restore noptimize.
598
-        $this->content = $this->restore_noptimize( $this->content );
598
+        $this->content = $this->restore_noptimize($this->content);
599 599
 
600 600
         // Return the modified HTML.
601 601
         return $this->content;
@@ -606,34 +606,34 @@  discard block
 block discarded – undo
606 606
      *
607 607
      * @param string $tag JS tag.
608 608
      */
609
-    private function ismergeable( $tag )
609
+    private function ismergeable($tag)
610 610
     {
611
-        if ( empty( $tag ) || ! $this->aggregate ) {
611
+        if (empty($tag) || !$this->aggregate) {
612 612
             return false;
613 613
         }
614 614
 
615
-        if ( ! empty( $this->whitelist ) ) {
616
-            foreach ( $this->whitelist as $match ) {
617
-                if ( false !== strpos( $tag, $match ) ) {
615
+        if (!empty($this->whitelist)) {
616
+            foreach ($this->whitelist as $match) {
617
+                if (false !== strpos($tag, $match)) {
618 618
                     return true;
619 619
                 }
620 620
             }
621 621
             // No match with whitelist.
622 622
             return false;
623 623
         } else {
624
-            foreach ( $this->domove as $match ) {
625
-                if ( false !== strpos( $tag, $match ) ) {
624
+            foreach ($this->domove as $match) {
625
+                if (false !== strpos($tag, $match)) {
626 626
                     // Matched something.
627 627
                     return false;
628 628
                 }
629 629
             }
630 630
 
631
-            if ( $this->movetolast( $tag ) ) {
631
+            if ($this->movetolast($tag)) {
632 632
                 return false;
633 633
             }
634 634
 
635
-            foreach ( $this->dontmove as $match ) {
636
-                if ( false !== strpos( $tag, $match ) ) {
635
+            foreach ($this->dontmove as $match) {
636
+                if (false !== strpos($tag, $match)) {
637 637
                     // Matched something.
638 638
                     return false;
639 639
                 }
@@ -649,25 +649,25 @@  discard block
 block discarded – undo
649 649
      *
650 650
      * @param string $tag tag to check for blacklist (exclusions).
651 651
      */
652
-    private function ismovable( $tag )
652
+    private function ismovable($tag)
653 653
     {
654
-        if ( empty( $tag ) || true !== $this->include_inline || apply_filters( 'autoptimize_filter_js_unmovable', true ) ) {
654
+        if (empty($tag) || true !== $this->include_inline || apply_filters('autoptimize_filter_js_unmovable', true)) {
655 655
             return false;
656 656
         }
657 657
 
658
-        foreach ( $this->domove as $match ) {
659
-            if ( false !== strpos( $tag, $match ) ) {
658
+        foreach ($this->domove as $match) {
659
+            if (false !== strpos($tag, $match)) {
660 660
                 // Matched something.
661 661
                 return true;
662 662
             }
663 663
         }
664 664
 
665
-        if ( $this->movetolast( $tag ) ) {
665
+        if ($this->movetolast($tag)) {
666 666
             return true;
667 667
         }
668 668
 
669
-        foreach ( $this->dontmove as $match ) {
670
-            if ( false !== strpos( $tag, $match ) ) {
669
+        foreach ($this->dontmove as $match) {
670
+            if (false !== strpos($tag, $match)) {
671 671
                 // Matched something.
672 672
                 return false;
673 673
             }
@@ -677,14 +677,14 @@  discard block
 block discarded – undo
677 677
         return true;
678 678
     }
679 679
 
680
-    private function movetolast( $tag )
680
+    private function movetolast($tag)
681 681
     {
682
-        if ( empty( $tag ) ) {
682
+        if (empty($tag)) {
683 683
             return false;
684 684
         }
685 685
 
686
-        foreach ( $this->domovelast as $match ) {
687
-            if ( false !== strpos( $tag, $match ) ) {
686
+        foreach ($this->domovelast as $match) {
687
+            if (false !== strpos($tag, $match)) {
688 688
                 // Matched, return true.
689 689
                 return true;
690 690
             }
@@ -704,12 +704,12 @@  discard block
 block discarded – undo
704 704
      * @param string $js_path Path to JS file.
705 705
      * @return bool
706 706
      */
707
-    private function can_inject_late( $js_path ) {
708
-        $consider_minified_array = apply_filters( 'autoptimize_filter_js_consider_minified', false );
709
-        if ( true !== $this->inject_min_late ) {
707
+    private function can_inject_late($js_path) {
708
+        $consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified', false);
709
+        if (true !== $this->inject_min_late) {
710 710
             // late-inject turned off.
711 711
             return false;
712
-        } elseif ( ( false === strpos( $js_path, 'min.js' ) ) && ( false === strpos( $js_path, 'wp-includes/js/jquery/jquery.js' ) ) && ( str_replace( $consider_minified_array, '', $js_path ) === $js_path ) ) {
712
+        } elseif ((false === strpos($js_path, 'min.js')) && (false === strpos($js_path, 'wp-includes/js/jquery/jquery.js')) && (str_replace($consider_minified_array, '', $js_path) === $js_path)) {
713 713
             // file not minified based on filename & filter.
714 714
             return false;
715 715
         } else {
@@ -736,32 +736,32 @@  discard block
 block discarded – undo
736 736
      *
737 737
      * @return bool|string Url pointing to the minified js file or false.
738 738
      */
739
-    public function minify_single( $filepath, $cache_miss = false )
739
+    public function minify_single($filepath, $cache_miss = false)
740 740
     {
741
-        $contents = $this->prepare_minify_single( $filepath );
741
+        $contents = $this->prepare_minify_single($filepath);
742 742
 
743
-        if ( empty( $contents ) ) {
743
+        if (empty($contents)) {
744 744
             return false;
745 745
         }
746 746
 
747 747
         // Check cache.
748
-        $hash  = 'single_' . md5( $contents );
749
-        $cache = new autoptimizeCache( $hash, 'js' );
748
+        $hash  = 'single_'.md5($contents);
749
+        $cache = new autoptimizeCache($hash, 'js');
750 750
 
751 751
         // If not in cache already, minify...
752
-        if ( ! $cache->check() || $cache_miss ) {
753
-            $contents = trim( JSMin::minify( $contents ) );
752
+        if (!$cache->check() || $cache_miss) {
753
+            $contents = trim(JSMin::minify($contents));
754 754
 
755 755
             // Check if minified cache content is empty.
756
-            if ( empty( $contents ) ) {
756
+            if (empty($contents)) {
757 757
                 return false;
758 758
             }
759 759
 
760 760
             // Store in cache.
761
-            $cache->cache( $contents, 'text/javascript' );
761
+            $cache->cache($contents, 'text/javascript');
762 762
         }
763 763
 
764
-        $url = $this->build_minify_single_url( $cache );
764
+        $url = $this->build_minify_single_url($cache);
765 765
 
766 766
         return $url;
767 767
     }
Please login to merge, or discard this patch.
classes/autoptimizeStyles.php 2 patches
Doc Comments   +22 added lines, -2 removed lines patch added patch discarded remove patch
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
      * be inlined into a data: URI. Defaults to 4096, passed through
440 440
      * `autoptimize_filter_css_datauri_maxsize` filter.
441 441
      *
442
-     * @return mixed
442
+     * @return integer|null
443 443
      */
444 444
     private function get_datauri_maxsize()
445 445
     {
@@ -460,6 +460,9 @@  discard block
 block discarded – undo
460 460
         return $max_size;
461 461
     }
462 462
 
463
+    /**
464
+     * @param false|string $url
465
+     */
463 466
     private function check_datauri_exclude_list( $url )
464 467
     {
465 468
         static $exclude_list = null;
@@ -485,6 +488,9 @@  discard block
 block discarded – undo
485 488
         return $matched;
486 489
     }
487 490
 
491
+    /**
492
+     * @param false|string $path
493
+     */
488 494
     private function build_or_get_datauri_image( $path )
489 495
     {
490 496
         /**
@@ -914,6 +920,11 @@  discard block
 block discarded – undo
914 920
         return true;
915 921
     }
916 922
 
923
+    /**
924
+     * @param string $code
925
+     *
926
+     * @return string
927
+     */
917 928
     public function run_minifier_on( $code )
918 929
     {
919 930
         if ( ! $this->alreadyminified ) {
@@ -1135,6 +1146,9 @@  discard block
 block discarded – undo
1135 1146
         return $code;
1136 1147
     }
1137 1148
 
1149
+    /**
1150
+     * @param string $tag
1151
+     */
1138 1152
     private function ismovable( $tag )
1139 1153
     {
1140 1154
         if ( ! $this->aggregate ) {
@@ -1164,6 +1178,9 @@  discard block
 block discarded – undo
1164 1178
         }
1165 1179
     }
1166 1180
 
1181
+    /**
1182
+     * @param string $css
1183
+     */
1167 1184
     private function can_inject_late( $css_path, $css )
1168 1185
     {
1169 1186
         $consider_minified_array = apply_filters( 'autoptimize_filter_css_consider_minified', false, $css_path );
@@ -1195,7 +1212,7 @@  discard block
 block discarded – undo
1195 1212
      * @param string $filepath Filepath.
1196 1213
      * @param bool   $cache_miss Optional. Force a cache miss. Default false.
1197 1214
      *
1198
-     * @return bool|string Url pointing to the minified css file or false.
1215
+     * @return false|string Url pointing to the minified css file or false.
1199 1216
      */
1200 1217
     public function minify_single( $filepath, $cache_miss = false )
1201 1218
     {
@@ -1256,6 +1273,9 @@  discard block
 block discarded – undo
1256 1273
         $this->options = $options;
1257 1274
     }
1258 1275
 
1276
+    /**
1277
+     * @param string $name
1278
+     */
1259 1279
     public function setOption( $name, $value )
1260 1280
     {
1261 1281
         $this->options[ $name ] = $value;
Please login to merge, or discard this patch.
Spacing   +335 added lines, -335 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Class for CSS optimization.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -161,53 +161,53 @@  discard block
 block discarded – undo
161 161
      *
162 162
      * @param array $options all options.
163 163
      */
164
-    public function read( $options )
164
+    public function read($options)
165 165
     {
166
-        $noptimize_css = apply_filters( 'autoptimize_filter_css_noptimize', false, $this->content );
167
-        if ( $noptimize_css ) {
166
+        $noptimize_css = apply_filters('autoptimize_filter_css_noptimize', false, $this->content);
167
+        if ($noptimize_css) {
168 168
             return false;
169 169
         }
170 170
 
171
-        $whitelist_css = apply_filters( 'autoptimize_filter_css_whitelist', '', $this->content );
172
-        if ( ! empty( $whitelist_css ) ) {
173
-            $this->whitelist = array_filter( array_map( 'trim', explode( ',', $whitelist_css ) ) );
171
+        $whitelist_css = apply_filters('autoptimize_filter_css_whitelist', '', $this->content);
172
+        if (!empty($whitelist_css)) {
173
+            $this->whitelist = array_filter(array_map('trim', explode(',', $whitelist_css)));
174 174
         }
175 175
 
176
-        $removable_css = apply_filters( 'autoptimize_filter_css_removables', '' );
177
-        if ( ! empty( $removable_css ) ) {
178
-            $this->cssremovables = array_filter( array_map( 'trim', explode( ',', $removable_css ) ) );
176
+        $removable_css = apply_filters('autoptimize_filter_css_removables', '');
177
+        if (!empty($removable_css)) {
178
+            $this->cssremovables = array_filter(array_map('trim', explode(',', $removable_css)));
179 179
         }
180 180
 
181
-        $this->cssinlinesize = apply_filters( 'autoptimize_filter_css_inlinesize', 256 );
181
+        $this->cssinlinesize = apply_filters('autoptimize_filter_css_inlinesize', 256);
182 182
 
183 183
         // filter to "late inject minified CSS", default to true for now (it is faster).
184
-        $this->inject_min_late = apply_filters( 'autoptimize_filter_css_inject_min_late', true );
184
+        $this->inject_min_late = apply_filters('autoptimize_filter_css_inject_min_late', true);
185 185
 
186 186
         // Remove everything that's not the header.
187
-        if ( apply_filters( 'autoptimize_filter_css_justhead', $options['justhead'] ) ) {
188
-            $content             = explode( '</head>', $this->content, 2 );
189
-            $this->content       = $content[0] . '</head>';
187
+        if (apply_filters('autoptimize_filter_css_justhead', $options['justhead'])) {
188
+            $content             = explode('</head>', $this->content, 2);
189
+            $this->content       = $content[0].'</head>';
190 190
             $this->restofcontent = $content[1];
191 191
         }
192 192
 
193 193
         // Determine whether we're doing CSS-files aggregation or not.
194
-        if ( isset( $options['aggregate'] ) && ! $options['aggregate'] ) {
194
+        if (isset($options['aggregate']) && !$options['aggregate']) {
195 195
             $this->aggregate = false;
196 196
         }
197 197
         // Returning true for "dontaggregate" turns off aggregation.
198
-        if ( $this->aggregate && apply_filters( 'autoptimize_filter_css_dontaggregate', false ) ) {
198
+        if ($this->aggregate && apply_filters('autoptimize_filter_css_dontaggregate', false)) {
199 199
             $this->aggregate = false;
200 200
         }
201 201
 
202 202
         // include inline?
203
-        if ( apply_filters( 'autoptimize_css_include_inline', $options['include_inline'] ) ) {
203
+        if (apply_filters('autoptimize_css_include_inline', $options['include_inline'])) {
204 204
             $this->include_inline = true;
205 205
         }
206 206
 
207 207
         // List of CSS strings which are excluded from autoptimization.
208
-        $exclude_css = apply_filters( 'autoptimize_filter_css_exclude', $options['css_exclude'], $this->content );
209
-        if ( '' !== $exclude_css ) {
210
-            $this->dontmove = array_filter( array_map( 'trim', explode( ',', $exclude_css ) ) );
208
+        $exclude_css = apply_filters('autoptimize_filter_css_exclude', $options['css_exclude'], $this->content);
209
+        if ('' !== $exclude_css) {
210
+            $this->dontmove = array_filter(array_map('trim', explode(',', $exclude_css)));
211 211
         } else {
212 212
             $this->dontmove = array();
213 213
         }
@@ -218,16 +218,16 @@  discard block
 block discarded – undo
218 218
         // Should we defer css?
219 219
         // value: true / false.
220 220
         $this->defer = $options['defer'];
221
-        $this->defer = apply_filters( 'autoptimize_filter_css_defer', $this->defer, $this->content );
221
+        $this->defer = apply_filters('autoptimize_filter_css_defer', $this->defer, $this->content);
222 222
 
223 223
         // Should we inline while deferring?
224 224
         // value: inlined CSS.
225
-        $this->defer_inline = apply_filters( 'autoptimize_filter_css_defer_inline', $options['defer_inline'], $this->content );
225
+        $this->defer_inline = apply_filters('autoptimize_filter_css_defer_inline', $options['defer_inline'], $this->content);
226 226
 
227 227
         // Should we inline?
228 228
         // value: true / false.
229 229
         $this->inline = $options['inline'];
230
-        $this->inline = apply_filters( 'autoptimize_filter_css_inline', $this->inline, $this->content );
230
+        $this->inline = apply_filters('autoptimize_filter_css_inline', $this->inline, $this->content);
231 231
 
232 232
         // Store cdn url.
233 233
         $this->cdn_url = $options['cdn_url'];
@@ -236,16 +236,16 @@  discard block
 block discarded – undo
236 236
         $this->datauris = $options['datauris'];
237 237
 
238 238
         // Determine whether excluded files should be minified if not yet so.
239
-        if ( ! $options['minify_excluded'] && $options['aggregate'] ) {
239
+        if (!$options['minify_excluded'] && $options['aggregate']) {
240 240
             $this->minify_excluded = false;
241 241
         }
242
-        $this->minify_excluded = apply_filters( 'autoptimize_filter_css_minify_excluded', $this->minify_excluded, '' );
242
+        $this->minify_excluded = apply_filters('autoptimize_filter_css_minify_excluded', $this->minify_excluded, '');
243 243
 
244 244
         // should we force all media-attributes to all?
245
-        $this->media_force_all = apply_filters( 'autoptimize_filter_css_tagmedia_forceall', false );
245
+        $this->media_force_all = apply_filters('autoptimize_filter_css_tagmedia_forceall', false);
246 246
 
247 247
         // noptimize me.
248
-        $this->content = $this->hide_noptimize( $this->content );
248
+        $this->content = $this->hide_noptimize($this->content);
249 249
 
250 250
         // Exclude (no)script, as those may contain CSS which should be left as is.
251 251
         $this->content = $this->replace_contents_with_marker_if_exists(
@@ -256,25 +256,25 @@  discard block
 block discarded – undo
256 256
         );
257 257
 
258 258
         // Save IE hacks.
259
-        $this->content = $this->hide_iehacks( $this->content );
259
+        $this->content = $this->hide_iehacks($this->content);
260 260
 
261 261
         // Hide HTML comments.
262
-        $this->content = $this->hide_comments( $this->content );
262
+        $this->content = $this->hide_comments($this->content);
263 263
 
264 264
         // Get <style> and <link>.
265
-        if ( preg_match_all( '#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches ) ) {
265
+        if (preg_match_all('#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches)) {
266 266
 
267
-            foreach ( $matches[0] as $tag ) {
268
-                if ( $this->isremovable( $tag, $this->cssremovables ) ) {
269
-                    $this->content = str_replace( $tag, '', $this->content );
270
-                } elseif ( $this->ismovable( $tag ) ) {
267
+            foreach ($matches[0] as $tag) {
268
+                if ($this->isremovable($tag, $this->cssremovables)) {
269
+                    $this->content = str_replace($tag, '', $this->content);
270
+                } elseif ($this->ismovable($tag)) {
271 271
                     // Get the media.
272
-                    if ( false !== strpos( $tag, 'media=' ) ) {
273
-                        preg_match( '#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias );
274
-                        $medias = explode( ',', $medias[1] );
272
+                    if (false !== strpos($tag, 'media=')) {
273
+                        preg_match('#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias);
274
+                        $medias = explode(',', $medias[1]);
275 275
                         $media  = array();
276
-                        foreach ( $medias as $elem ) {
277
-                            if ( empty( $elem ) ) {
276
+                        foreach ($medias as $elem) {
277
+                            if (empty($elem)) {
278 278
                                 $elem = 'all';
279 279
                             }
280 280
 
@@ -282,68 +282,68 @@  discard block
 block discarded – undo
282 282
                         }
283 283
                     } else {
284 284
                         // No media specified - applies to all.
285
-                        $media = array( 'all' );
285
+                        $media = array('all');
286 286
                     }
287 287
 
288 288
                     // forcing media attribute to all to merge all in one file.
289
-                    if ( $this->media_force_all ) {
290
-                        $media = array( 'all' );
289
+                    if ($this->media_force_all) {
290
+                        $media = array('all');
291 291
                     }
292 292
 
293
-                    $media = apply_filters( 'autoptimize_filter_css_tagmedia', $media, $tag );
293
+                    $media = apply_filters('autoptimize_filter_css_tagmedia', $media, $tag);
294 294
 
295
-                    if ( preg_match( '#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source ) ) {
295
+                    if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) {
296 296
                         // <link>.
297
-                        $url  = current( explode( '?', $source[2], 2 ) );
298
-                        $path = $this->getpath( $url );
297
+                        $url  = current(explode('?', $source[2], 2));
298
+                        $path = $this->getpath($url);
299 299
 
300
-                        if ( false !== $path && preg_match( '#\.css$#', $path ) ) {
300
+                        if (false !== $path && preg_match('#\.css$#', $path)) {
301 301
                             // Good link.
302
-                            $this->css[] = array( $media, $path );
302
+                            $this->css[] = array($media, $path);
303 303
                         } else {
304 304
                             // Link is dynamic (.php etc).
305
-                            $new_tag = $this->optionally_defer_excluded( $tag, 'none' );
306
-                            if ( '' !== $new_tag && $new_tag !== $tag ) {
307
-                                $this->content = str_replace( $tag, $new_tag, $this->content );
305
+                            $new_tag = $this->optionally_defer_excluded($tag, 'none');
306
+                            if ('' !== $new_tag && $new_tag !== $tag) {
307
+                                $this->content = str_replace($tag, $new_tag, $this->content);
308 308
                             }
309 309
                             $tag = '';
310 310
                         }
311 311
                     } else {
312 312
                         // Inline css in style tags can be wrapped in comment tags, so restore comments.
313
-                        $tag = $this->restore_comments( $tag );
314
-                        preg_match( '#<style.*>(.*)</style>#Usmi', $tag, $code );
313
+                        $tag = $this->restore_comments($tag);
314
+                        preg_match('#<style.*>(.*)</style>#Usmi', $tag, $code);
315 315
 
316 316
                         // And re-hide them to be able to to the removal based on tag.
317
-                        $tag = $this->hide_comments( $tag );
317
+                        $tag = $this->hide_comments($tag);
318 318
 
319
-                        if ( $this->include_inline ) {
320
-                            $code        = preg_replace( '#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1] );
321
-                            $this->css[] = array( $media, 'INLINE;' . $code );
319
+                        if ($this->include_inline) {
320
+                            $code        = preg_replace('#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1]);
321
+                            $this->css[] = array($media, 'INLINE;'.$code);
322 322
                         } else {
323 323
                             $tag = '';
324 324
                         }
325 325
                     }
326 326
 
327 327
                     // Remove the original style tag.
328
-                    $this->content = str_replace( $tag, '', $this->content );
328
+                    $this->content = str_replace($tag, '', $this->content);
329 329
                 } else {
330
-                    if ( preg_match( '#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source ) ) {
331
-                        $exploded_url = explode( '?', $source[2], 2 );
330
+                    if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) {
331
+                        $exploded_url = explode('?', $source[2], 2);
332 332
                         $url          = $exploded_url[0];
333
-                        $path         = $this->getpath( $url );
333
+                        $path         = $this->getpath($url);
334 334
                         $new_tag      = $tag;
335 335
 
336 336
                         // Excluded CSS, minify that file:
337 337
                         // -> if aggregate is on and exclude minify is on
338 338
                         // -> if aggregate is off and the file is not in dontmove.
339
-                        if ( $path && $this->minify_excluded ) {
340
-                            $consider_minified_array = apply_filters( 'autoptimize_filter_css_consider_minified', false );
341
-                            if ( ( false === $this->aggregate && str_replace( $this->dontmove, '', $path ) === $path ) || ( true === $this->aggregate && ( false === $consider_minified_array || str_replace( $consider_minified_array, '', $path ) === $path ) ) ) {
342
-                                $minified_url = $this->minify_single( $path );
343
-                                if ( ! empty( $minified_url ) ) {
339
+                        if ($path && $this->minify_excluded) {
340
+                            $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false);
341
+                            if ((false === $this->aggregate && str_replace($this->dontmove, '', $path) === $path) || (true === $this->aggregate && (false === $consider_minified_array || str_replace($consider_minified_array, '', $path) === $path))) {
342
+                                $minified_url = $this->minify_single($path);
343
+                                if (!empty($minified_url)) {
344 344
                                     // Replace orig URL with cached minified URL.
345
-                                    $new_tag = str_replace( $url, $minified_url, $tag );
346
-                                } elseif ( apply_filters( 'autoptimize_filter_ccsjs_remove_empty_minified_url', false ) ) {
345
+                                    $new_tag = str_replace($url, $minified_url, $tag);
346
+                                } elseif (apply_filters('autoptimize_filter_ccsjs_remove_empty_minified_url', false)) {
347 347
                                     // Remove the original style tag, because cache content is empty but only if
348 348
                                     // filter is true-ed because $minified_url is also false if file is minified already.
349 349
                                     $new_tag = '';
@@ -351,14 +351,14 @@  discard block
 block discarded – undo
351 351
                             }
352 352
                         }
353 353
 
354
-                        if ( '' !== $new_tag ) {
354
+                        if ('' !== $new_tag) {
355 355
                             // Optionally defer (preload) non-aggregated CSS.
356
-                            $new_tag = $this->optionally_defer_excluded( $new_tag, $url );
356
+                            $new_tag = $this->optionally_defer_excluded($new_tag, $url);
357 357
                         }
358 358
 
359 359
                         // And replace!
360
-                        if ( ( '' !== $new_tag && $new_tag !== $tag ) || ( '' === $new_tag && apply_filters( 'autoptimize_filter_css_remove_empty_files', false ) ) ) {
361
-                            $this->content = str_replace( $tag, $new_tag, $this->content );
360
+                        if (('' !== $new_tag && $new_tag !== $tag) || ('' === $new_tag && apply_filters('autoptimize_filter_css_remove_empty_files', false))) {
361
+                            $this->content = str_replace($tag, $new_tag, $this->content);
362 362
                         }
363 363
                     }
364 364
                 }
@@ -379,10 +379,10 @@  discard block
 block discarded – undo
379 379
      *
380 380
      * @return string $new_tag
381 381
      */
382
-    private function optionally_defer_excluded( $tag, $url = '' )
382
+    private function optionally_defer_excluded($tag, $url = '')
383 383
     {
384 384
         // Defer single CSS if "inline & defer" is ON and there is inline CSS.
385
-        if ( ! empty( $tag ) && false === strpos( $tag, ' onload=' ) && $this->defer && ! empty( $this->defer_inline ) && apply_filters( 'autoptimize_filter_css_defer_excluded', true, $tag ) ) {
385
+        if (!empty($tag) && false === strpos($tag, ' onload=') && $this->defer && !empty($this->defer_inline) && apply_filters('autoptimize_filter_css_defer_excluded', true, $tag)) {
386 386
             // Get/ set (via filter) the JS to be triggers onload of the preloaded CSS.
387 387
             $_preload_onload = apply_filters(
388 388
                 'autoptimize_filter_css_preload_onload',
@@ -391,12 +391,12 @@  discard block
 block discarded – undo
391 391
             );
392 392
 
393 393
             // Adapt original <link> element for CSS to be preloaded and add <noscript>-version for fallback.
394
-            $new_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>' . str_replace(
394
+            $new_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>'.str_replace(
395 395
                 array(
396 396
                     "rel='stylesheet'",
397 397
                     'rel="stylesheet"',
398 398
                 ),
399
-                "rel='preload' as='style' onload=\"" . $_preload_onload . '"',
399
+                "rel='preload' as='style' onload=\"".$_preload_onload.'"',
400 400
                 $tag
401 401
             );
402 402
 
@@ -414,22 +414,22 @@  discard block
 block discarded – undo
414 414
      * @param string $path image path.
415 415
      * @return boolean
416 416
      */
417
-    private function is_datauri_candidate( $path )
417
+    private function is_datauri_candidate($path)
418 418
     {
419 419
         // Call only once since it's called from a loop.
420 420
         static $max_size = null;
421
-        if ( null === $max_size ) {
421
+        if (null === $max_size) {
422 422
             $max_size = $this->get_datauri_maxsize();
423 423
         }
424 424
 
425
-        if ( $path && preg_match( '#\.(jpe?g|png|gif|webp|bmp)$#i', $path ) &&
426
-            file_exists( $path ) && is_readable( $path ) && filesize( $path ) <= $max_size ) {
425
+        if ($path && preg_match('#\.(jpe?g|png|gif|webp|bmp)$#i', $path) &&
426
+            file_exists($path) && is_readable($path) && filesize($path) <= $max_size) {
427 427
 
428 428
             // Seems we have a candidate.
429 429
             $is_candidate = true;
430 430
         } else {
431 431
             // Filter allows overriding default decision (which checks for local file existence).
432
-            $is_candidate = apply_filters( 'autoptimize_filter_css_is_datauri_candidate', false, $path );
432
+            $is_candidate = apply_filters('autoptimize_filter_css_is_datauri_candidate', false, $path);
433 433
         }
434 434
 
435 435
         return $is_candidate;
@@ -454,29 +454,29 @@  discard block
 block discarded – undo
454 454
          * of thing you're probably better of building assets completely
455 455
          * outside of WordPress anyway.
456 456
          */
457
-        if ( null === $max_size ) {
458
-            $max_size = (int) apply_filters( 'autoptimize_filter_css_datauri_maxsize', 4096 );
457
+        if (null === $max_size) {
458
+            $max_size = (int) apply_filters('autoptimize_filter_css_datauri_maxsize', 4096);
459 459
         }
460 460
 
461 461
         return $max_size;
462 462
     }
463 463
 
464
-    private function check_datauri_exclude_list( $url )
464
+    private function check_datauri_exclude_list($url)
465 465
     {
466 466
         static $exclude_list = null;
467 467
         $no_datauris         = array();
468 468
 
469 469
         // Again, skip doing certain stuff repeatedly when loop-called.
470
-        if ( null === $exclude_list ) {
471
-            $exclude_list = apply_filters( 'autoptimize_filter_css_datauri_exclude', '' );
472
-            $no_datauris  = array_filter( array_map( 'trim', explode( ',', $exclude_list ) ) );
470
+        if (null === $exclude_list) {
471
+            $exclude_list = apply_filters('autoptimize_filter_css_datauri_exclude', '');
472
+            $no_datauris  = array_filter(array_map('trim', explode(',', $exclude_list)));
473 473
         }
474 474
 
475 475
         $matched = false;
476 476
 
477
-        if ( ! empty( $exclude_list ) ) {
478
-            foreach ( $no_datauris as $no_datauri ) {
479
-                if ( false !== strpos( $url, $no_datauri ) ) {
477
+        if (!empty($exclude_list)) {
478
+            foreach ($no_datauris as $no_datauri) {
479
+                if (false !== strpos($url, $no_datauri)) {
480 480
                     $matched = true;
481 481
                     break;
482 482
                 }
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
         return $matched;
487 487
     }
488 488
 
489
-    private function build_or_get_datauri_image( $path )
489
+    private function build_or_get_datauri_image($path)
490 490
     {
491 491
         /**
492 492
          * TODO/FIXME: document the required return array format, or better yet,
@@ -495,27 +495,27 @@  discard block
 block discarded – undo
495 495
          */
496 496
 
497 497
         // Allows short-circuiting datauri generation for an image.
498
-        $result = apply_filters( 'autoptimize_filter_css_datauri_image', array(), $path );
499
-        if ( ! empty( $result ) ) {
500
-            if ( is_array( $result ) && isset( $result['full'] ) && isset( $result['base64data'] ) ) {
498
+        $result = apply_filters('autoptimize_filter_css_datauri_image', array(), $path);
499
+        if (!empty($result)) {
500
+            if (is_array($result) && isset($result['full']) && isset($result['base64data'])) {
501 501
                 return $result;
502 502
             }
503 503
         }
504 504
 
505
-        $hash  = md5( $path );
506
-        $check = new autoptimizeCache( $hash, 'img' );
507
-        if ( $check->check() ) {
505
+        $hash  = md5($path);
506
+        $check = new autoptimizeCache($hash, 'img');
507
+        if ($check->check()) {
508 508
             // we have the base64 image in cache.
509 509
             $head_and_data = $check->retrieve();
510
-            $_base64data   = explode( ';base64,', $head_and_data );
510
+            $_base64data   = explode(';base64,', $head_and_data);
511 511
             $base64data    = $_base64data[1];
512
-            unset( $_base64data );
512
+            unset($_base64data);
513 513
         } else {
514 514
             // It's an image and we don't have it in cache, get the type by extension.
515
-            $exploded_path = explode( '.', $path );
516
-            $type          = end( $exploded_path );
515
+            $exploded_path = explode('.', $path);
516
+            $type          = end($exploded_path);
517 517
 
518
-            switch ( $type ) {
518
+            switch ($type) {
519 519
                 case 'jpg':
520 520
                 case 'jpeg':
521 521
                     $dataurihead = 'data:image/jpeg;base64,';
@@ -537,13 +537,13 @@  discard block
 block discarded – undo
537 537
             }
538 538
 
539 539
             // Encode the data.
540
-            $base64data    = base64_encode( file_get_contents( $path ) );
541
-            $head_and_data = $dataurihead . $base64data;
540
+            $base64data    = base64_encode(file_get_contents($path));
541
+            $head_and_data = $dataurihead.$base64data;
542 542
 
543 543
             // Save in cache.
544
-            $check->cache( $head_and_data, 'text/plain' );
544
+            $check->cache($head_and_data, 'text/plain');
545 545
         }
546
-        unset( $check );
546
+        unset($check);
547 547
 
548 548
         return array(
549 549
             'full'       => $head_and_data,
@@ -560,13 +560,13 @@  discard block
 block discarded – undo
560 560
      *
561 561
      * @return string
562 562
      */
563
-    protected static function replace_longest_matches_first( $string, $replacements = array() )
563
+    protected static function replace_longest_matches_first($string, $replacements = array())
564 564
     {
565
-        if ( ! empty( $replacements ) ) {
565
+        if (!empty($replacements)) {
566 566
             // Sort the replacements array by key length in desc order (so that the longest strings are replaced first).
567
-            $keys = array_map( 'strlen', array_keys( $replacements ) );
568
-            array_multisort( $keys, SORT_DESC, $replacements );
569
-            $string = str_replace( array_keys( $replacements ), array_values( $replacements ), $string );
567
+            $keys = array_map('strlen', array_keys($replacements));
568
+            array_multisort($keys, SORT_DESC, $replacements);
569
+            $string = str_replace(array_keys($replacements), array_values($replacements), $string);
570 570
         }
571 571
 
572 572
         return $string;
@@ -582,15 +582,15 @@  discard block
 block discarded – undo
582 582
      *
583 583
      * @return string
584 584
      */
585
-    public function replace_urls( $code = '' )
585
+    public function replace_urls($code = '')
586 586
     {
587 587
         $replacements = array();
588 588
 
589
-        preg_match_all( self::ASSETS_REGEX, $code, $url_src_matches );
590
-        if ( is_array( $url_src_matches ) && ! empty( $url_src_matches ) ) {
591
-            foreach ( $url_src_matches[1] as $count => $original_url ) {
589
+        preg_match_all(self::ASSETS_REGEX, $code, $url_src_matches);
590
+        if (is_array($url_src_matches) && !empty($url_src_matches)) {
591
+            foreach ($url_src_matches[1] as $count => $original_url) {
592 592
                 // Removes quotes and other cruft.
593
-                $url = trim( $original_url, " \t\n\r\0\x0B\"'" );
593
+                $url = trim($original_url, " \t\n\r\0\x0B\"'");
594 594
 
595 595
                 /**
596 596
                  * TODO/FIXME: Add a way for other code / callable to be called here
@@ -608,17 +608,17 @@  discard block
 block discarded – undo
608 608
                  */
609 609
 
610 610
                 // Do CDN replacement if needed.
611
-                if ( ! empty( $this->cdn_url ) ) {
612
-                    $replacement_url = $this->url_replace_cdn( $url );
611
+                if (!empty($this->cdn_url)) {
612
+                    $replacement_url = $this->url_replace_cdn($url);
613 613
                     // Prepare replacements array.
614
-                    $replacements[ $url_src_matches[1][ $count ] ] = str_replace(
615
-                        $original_url, $replacement_url, $url_src_matches[1][ $count ]
614
+                    $replacements[$url_src_matches[1][$count]] = str_replace(
615
+                        $original_url, $replacement_url, $url_src_matches[1][$count]
616 616
                     );
617 617
                 }
618 618
             }
619 619
         }
620 620
 
621
-        $code = self::replace_longest_matches_first( $code, $replacements );
621
+        $code = self::replace_longest_matches_first($code, $replacements);
622 622
 
623 623
         return $code;
624 624
     }
@@ -631,26 +631,26 @@  discard block
 block discarded – undo
631 631
      * @param string $code HTML being processed to hide fonts.
632 632
      * @return string
633 633
      */
634
-    public function hide_fontface_and_maybe_cdn( $code )
634
+    public function hide_fontface_and_maybe_cdn($code)
635 635
     {
636 636
         // Proceed only if @font-face declarations exist within $code.
637
-        preg_match_all( self::FONT_FACE_REGEX, $code, $fontfaces );
638
-        if ( isset( $fontfaces[0] ) ) {
637
+        preg_match_all(self::FONT_FACE_REGEX, $code, $fontfaces);
638
+        if (isset($fontfaces[0])) {
639 639
             // Check if we need to cdn fonts or not.
640
-            $do_font_cdn = apply_filters( 'autoptimize_filter_css_fonts_cdn', false );
640
+            $do_font_cdn = apply_filters('autoptimize_filter_css_fonts_cdn', false);
641 641
 
642
-            foreach ( $fontfaces[0] as $full_match ) {
642
+            foreach ($fontfaces[0] as $full_match) {
643 643
                 // Keep original match so we can search/replace it.
644 644
                 $match_search = $full_match;
645 645
 
646 646
                 // Do font cdn if needed.
647
-                if ( $do_font_cdn ) {
648
-                    $full_match = $this->replace_urls( $full_match );
647
+                if ($do_font_cdn) {
648
+                    $full_match = $this->replace_urls($full_match);
649 649
                 }
650 650
 
651 651
                 // Replace declaration with its base64 encoded string.
652
-                $replacement = self::build_marker( 'FONTFACE', $full_match );
653
-                $code        = str_replace( $match_search, $replacement, $code );
652
+                $replacement = self::build_marker('FONTFACE', $full_match);
653
+                $code        = str_replace($match_search, $replacement, $code);
654 654
             }
655 655
         }
656 656
 
@@ -664,9 +664,9 @@  discard block
 block discarded – undo
664 664
      * @param string $code HTML being processed to unhide fonts.
665 665
      * @return string
666 666
      */
667
-    public function restore_fontface( $code )
667
+    public function restore_fontface($code)
668 668
     {
669
-        return $this->restore_marked_content( 'FONTFACE', $code );
669
+        return $this->restore_marked_content('FONTFACE', $code);
670 670
     }
671 671
 
672 672
     /**
@@ -675,10 +675,10 @@  discard block
 block discarded – undo
675 675
      * @param string $code HTML being processed rewrite assets.
676 676
      * @return string
677 677
      */
678
-    public function rewrite_assets( $code )
678
+    public function rewrite_assets($code)
679 679
     {
680 680
         // Handle @font-face rules by hiding and processing them separately.
681
-        $code = $this->hide_fontface_and_maybe_cdn( $code );
681
+        $code = $this->hide_fontface_and_maybe_cdn($code);
682 682
 
683 683
         /**
684 684
          * TODO/FIXME:
@@ -695,35 +695,35 @@  discard block
 block discarded – undo
695 695
         $imgreplace      = array();
696 696
 
697 697
         // Matches and captures anything specified within the literal `url()` and excludes those containing data: URIs.
698
-        preg_match_all( self::ASSETS_REGEX, $code, $url_src_matches );
699
-        if ( is_array( $url_src_matches ) && ! empty( $url_src_matches ) ) {
700
-            foreach ( $url_src_matches[1] as $count => $original_url ) {
698
+        preg_match_all(self::ASSETS_REGEX, $code, $url_src_matches);
699
+        if (is_array($url_src_matches) && !empty($url_src_matches)) {
700
+            foreach ($url_src_matches[1] as $count => $original_url) {
701 701
                 // Removes quotes and other cruft.
702
-                $url = trim( $original_url, " \t\n\r\0\x0B\"'" );
702
+                $url = trim($original_url, " \t\n\r\0\x0B\"'");
703 703
 
704 704
                 // If datauri inlining is turned on, do it.
705 705
                 $inlined = false;
706
-                if ( $this->datauris ) {
706
+                if ($this->datauris) {
707 707
                     $iurl = $url;
708
-                    if ( false !== strpos( $iurl, '?' ) ) {
709
-                        $iurl = strtok( $iurl, '?' );
708
+                    if (false !== strpos($iurl, '?')) {
709
+                        $iurl = strtok($iurl, '?');
710 710
                     }
711 711
 
712
-                    $ipath = $this->getpath( $iurl );
712
+                    $ipath = $this->getpath($iurl);
713 713
 
714
-                    $excluded = $this->check_datauri_exclude_list( $ipath );
715
-                    if ( ! $excluded ) {
716
-                        $is_datauri_candidate = $this->is_datauri_candidate( $ipath );
717
-                        if ( $is_datauri_candidate ) {
718
-                            $datauri    = $this->build_or_get_datauri_image( $ipath );
714
+                    $excluded = $this->check_datauri_exclude_list($ipath);
715
+                    if (!$excluded) {
716
+                        $is_datauri_candidate = $this->is_datauri_candidate($ipath);
717
+                        if ($is_datauri_candidate) {
718
+                            $datauri    = $this->build_or_get_datauri_image($ipath);
719 719
                             $base64data = $datauri['base64data'];
720 720
                             // Add it to the list for replacement.
721
-                            $imgreplace[ $url_src_matches[1][ $count ] ] = str_replace(
721
+                            $imgreplace[$url_src_matches[1][$count]] = str_replace(
722 722
                                 $original_url,
723 723
                                 $datauri['full'],
724
-                                $url_src_matches[1][ $count ]
724
+                                $url_src_matches[1][$count]
725 725
                             );
726
-                            $inlined                                     = true;
726
+                            $inlined = true;
727 727
                         }
728 728
                     }
729 729
                 }
@@ -734,20 +734,20 @@  discard block
 block discarded – undo
734 734
                  * inlining isn't turned on, or if a resource is skipped from
735 735
                  * being inlined for whatever reason above.
736 736
                  */
737
-                if ( ! $inlined && ( ! empty( $this->cdn_url ) || has_filter( 'autoptimize_filter_base_replace_cdn' ) ) ) {
737
+                if (!$inlined && (!empty($this->cdn_url) || has_filter('autoptimize_filter_base_replace_cdn'))) {
738 738
                     // Just do the "simple" CDN replacement.
739
-                    $replacement_url                             = $this->url_replace_cdn( $url );
740
-                    $imgreplace[ $url_src_matches[1][ $count ] ] = str_replace(
741
-                        $original_url, $replacement_url, $url_src_matches[1][ $count ]
739
+                    $replacement_url                             = $this->url_replace_cdn($url);
740
+                    $imgreplace[$url_src_matches[1][$count]] = str_replace(
741
+                        $original_url, $replacement_url, $url_src_matches[1][$count]
742 742
                     );
743 743
                 }
744 744
             }
745 745
         }
746 746
 
747
-        $code = self::replace_longest_matches_first( $code, $imgreplace );
747
+        $code = self::replace_longest_matches_first($code, $imgreplace);
748 748
 
749 749
         // Replace back font-face markers with actual font-face declarations.
750
-        $code = $this->restore_fontface( $code );
750
+        $code = $this->restore_fontface($code);
751 751
 
752 752
         return $code;
753 753
     }
@@ -757,29 +757,29 @@  discard block
 block discarded – undo
757 757
      */
758 758
     public function minify()
759 759
     {
760
-        foreach ( $this->css as $group ) {
761
-            list( $media, $css ) = $group;
762
-            if ( preg_match( '#^INLINE;#', $css ) ) {
760
+        foreach ($this->css as $group) {
761
+            list($media, $css) = $group;
762
+            if (preg_match('#^INLINE;#', $css)) {
763 763
                 // <style>.
764
-                $css      = preg_replace( '#^INLINE;#', '', $css );
765
-                $css      = self::fixurls( ABSPATH . 'index.php', $css ); // ABSPATH already contains a trailing slash.
766
-                $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, '' );
767
-                if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) {
764
+                $css      = preg_replace('#^INLINE;#', '', $css);
765
+                $css      = self::fixurls(ABSPATH.'index.php', $css); // ABSPATH already contains a trailing slash.
766
+                $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, '');
767
+                if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) {
768 768
                     $css                   = $tmpstyle;
769 769
                     $this->alreadyminified = true;
770 770
                 }
771 771
             } else {
772 772
                 // <link>
773
-                if ( false !== $css && file_exists( $css ) && is_readable( $css ) ) {
773
+                if (false !== $css && file_exists($css) && is_readable($css)) {
774 774
                     $css_path = $css;
775
-                    $css      = self::fixurls( $css_path, file_get_contents( $css_path ) );
776
-                    $css      = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $css );
777
-                    $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, $css_path );
778
-                    if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) {
775
+                    $css      = self::fixurls($css_path, file_get_contents($css_path));
776
+                    $css      = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $css);
777
+                    $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, $css_path);
778
+                    if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) {
779 779
                         $css                   = $tmpstyle;
780 780
                         $this->alreadyminified = true;
781
-                    } elseif ( $this->can_inject_late( $css_path, $css ) ) {
782
-                        $css = self::build_injectlater_marker( $css_path, md5( $css ) );
781
+                    } elseif ($this->can_inject_late($css_path, $css)) {
782
+                        $css = self::build_injectlater_marker($css_path, md5($css));
783 783
                     }
784 784
                 } else {
785 785
                     // Couldn't read CSS. Maybe getpath isn't working?
@@ -787,12 +787,12 @@  discard block
 block discarded – undo
787 787
                 }
788 788
             }
789 789
 
790
-            foreach ( $media as $elem ) {
791
-                if ( ! empty( $css ) ) {
792
-                    if ( ! isset( $this->csscode[ $elem ] ) ) {
793
-                        $this->csscode[ $elem ] = '';
790
+            foreach ($media as $elem) {
791
+                if (!empty($css)) {
792
+                    if (!isset($this->csscode[$elem])) {
793
+                        $this->csscode[$elem] = '';
794 794
                     }
795
-                    $this->csscode[ $elem ] .= "\n/*FILESTART*/" . $css;
795
+                    $this->csscode[$elem] .= "\n/*FILESTART*/".$css;
796 796
                 }
797 797
             }
798 798
         }
@@ -800,133 +800,133 @@  discard block
 block discarded – undo
800 800
         // Check for duplicate code.
801 801
         $md5list = array();
802 802
         $tmpcss  = $this->csscode;
803
-        foreach ( $tmpcss as $media => $code ) {
804
-            $md5sum    = md5( $code );
803
+        foreach ($tmpcss as $media => $code) {
804
+            $md5sum    = md5($code);
805 805
             $medianame = $media;
806
-            foreach ( $md5list as $med => $sum ) {
806
+            foreach ($md5list as $med => $sum) {
807 807
                 // If same code.
808
-                if ( $sum === $md5sum ) {
808
+                if ($sum === $md5sum) {
809 809
                     // Add the merged code.
810
-                    $medianame                   = $med . ', ' . $media;
811
-                    $this->csscode[ $medianame ] = $code;
812
-                    $md5list[ $medianame ]       = $md5list[ $med ];
813
-                    unset( $this->csscode[ $med ], $this->csscode[ $media ], $md5list[ $med ] );
810
+                    $medianame                   = $med.', '.$media;
811
+                    $this->csscode[$medianame] = $code;
812
+                    $md5list[$medianame]       = $md5list[$med];
813
+                    unset($this->csscode[$med], $this->csscode[$media], $md5list[$med]);
814 814
                 }
815 815
             }
816
-            $md5list[ $medianame ] = $md5sum;
816
+            $md5list[$medianame] = $md5sum;
817 817
         }
818
-        unset( $tmpcss );
818
+        unset($tmpcss);
819 819
 
820 820
         // Manage @imports, while is for recursive import management.
821
-        foreach ( $this->csscode as &$thiscss ) {
821
+        foreach ($this->csscode as &$thiscss) {
822 822
             // Flag to trigger import reconstitution and var to hold external imports.
823 823
             $fiximports       = false;
824 824
             $external_imports = '';
825 825
 
826 826
             // remove comments to avoid importing commented-out imports.
827
-            $thiscss_nocomments = preg_replace( '#/\*.*\*/#Us', '', $thiscss );
828
-            while ( preg_match_all( '#@import +(?:url)?(?:(?:\((["\']?)(?:[^"\')]+)\1\)|(["\'])(?:[^"\']+)\2)(?:[^,;"\']+(?:,[^,;"\']+)*)?)(?:;)#mi', $thiscss_nocomments, $matches ) ) {
829
-                foreach ( $matches[0] as $import ) {
830
-                    if ( $this->isremovable( $import, $this->cssremovables ) ) {
831
-                        $thiscss   = str_replace( $import, '', $thiscss );
827
+            $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss);
828
+            while (preg_match_all('#@import +(?:url)?(?:(?:\((["\']?)(?:[^"\')]+)\1\)|(["\'])(?:[^"\']+)\2)(?:[^,;"\']+(?:,[^,;"\']+)*)?)(?:;)#mi', $thiscss_nocomments, $matches)) {
829
+                foreach ($matches[0] as $import) {
830
+                    if ($this->isremovable($import, $this->cssremovables)) {
831
+                        $thiscss   = str_replace($import, '', $thiscss);
832 832
                         $import_ok = true;
833 833
                     } else {
834
-                        $url       = trim( preg_replace( '#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim( $import ) ), " \t\n\r\0\x0B\"'" );
835
-                        $path      = $this->getpath( $url );
834
+                        $url       = trim(preg_replace('#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim($import)), " \t\n\r\0\x0B\"'");
835
+                        $path      = $this->getpath($url);
836 836
                         $import_ok = false;
837
-                        if ( file_exists( $path ) && is_readable( $path ) ) {
838
-                            $code     = addcslashes( self::fixurls( $path, file_get_contents( $path ) ), '\\' );
839
-                            $code     = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $code );
840
-                            $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $code, '' );
841
-                            if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) {
837
+                        if (file_exists($path) && is_readable($path)) {
838
+                            $code     = addcslashes(self::fixurls($path, file_get_contents($path)), '\\');
839
+                            $code     = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $code);
840
+                            $tmpstyle = apply_filters('autoptimize_css_individual_style', $code, '');
841
+                            if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) {
842 842
                                 $code                  = $tmpstyle;
843 843
                                 $this->alreadyminified = true;
844
-                            } elseif ( $this->can_inject_late( $path, $code ) ) {
845
-                                $code = self::build_injectlater_marker( $path, md5( $code ) );
844
+                            } elseif ($this->can_inject_late($path, $code)) {
845
+                                $code = self::build_injectlater_marker($path, md5($code));
846 846
                             }
847 847
 
848
-                            if ( ! empty( $code ) ) {
849
-                                $tmp_thiscss = preg_replace( '#(/\*FILESTART\*/.*)' . preg_quote( $import, '#' ) . '#Us', '/*FILESTART2*/' . $code . '$1', $thiscss );
850
-                                if ( ! empty( $tmp_thiscss ) ) {
848
+                            if (!empty($code)) {
849
+                                $tmp_thiscss = preg_replace('#(/\*FILESTART\*/.*)'.preg_quote($import, '#').'#Us', '/*FILESTART2*/'.$code.'$1', $thiscss);
850
+                                if (!empty($tmp_thiscss)) {
851 851
                                     $thiscss   = $tmp_thiscss;
852 852
                                     $import_ok = true;
853
-                                    unset( $tmp_thiscss );
853
+                                    unset($tmp_thiscss);
854 854
                                 }
855 855
                             }
856
-                            unset( $code );
856
+                            unset($code);
857 857
                         }
858 858
                     }
859
-                    if ( ! $import_ok ) {
859
+                    if (!$import_ok) {
860 860
                         // External imports and general fall-back.
861 861
                         $external_imports .= $import;
862 862
 
863
-                        $thiscss    = str_replace( $import, '', $thiscss );
863
+                        $thiscss    = str_replace($import, '', $thiscss);
864 864
                         $fiximports = true;
865 865
                     }
866 866
                 }
867
-                $thiscss = preg_replace( '#/\*FILESTART\*/#', '', $thiscss );
868
-                $thiscss = preg_replace( '#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss );
867
+                $thiscss = preg_replace('#/\*FILESTART\*/#', '', $thiscss);
868
+                $thiscss = preg_replace('#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss);
869 869
 
870 870
                 // and update $thiscss_nocomments before going into next iteration in while loop.
871
-                $thiscss_nocomments = preg_replace( '#/\*.*\*/#Us', '', $thiscss );
871
+                $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss);
872 872
             }
873
-            unset( $thiscss_nocomments );
873
+            unset($thiscss_nocomments);
874 874
 
875 875
             // Add external imports to top of aggregated CSS.
876
-            if ( $fiximports ) {
877
-                $thiscss = $external_imports . $thiscss;
876
+            if ($fiximports) {
877
+                $thiscss = $external_imports.$thiscss;
878 878
             }
879 879
         }
880
-        unset( $thiscss );
880
+        unset($thiscss);
881 881
 
882 882
         // $this->csscode has all the uncompressed code now.
883
-        foreach ( $this->csscode as &$code ) {
883
+        foreach ($this->csscode as &$code) {
884 884
             // Check for already-minified code.
885
-            $hash = md5( $code );
886
-            do_action( 'autoptimize_action_css_hash', $hash );
887
-            $ccheck = new autoptimizeCache( $hash, 'css' );
888
-            if ( $ccheck->check() ) {
885
+            $hash = md5($code);
886
+            do_action('autoptimize_action_css_hash', $hash);
887
+            $ccheck = new autoptimizeCache($hash, 'css');
888
+            if ($ccheck->check()) {
889 889
                 $code                          = $ccheck->retrieve();
890
-                $this->hashmap[ md5( $code ) ] = $hash;
890
+                $this->hashmap[md5($code)] = $hash;
891 891
                 continue;
892 892
             }
893
-            unset( $ccheck );
893
+            unset($ccheck);
894 894
 
895 895
             // Rewrite and/or inline referenced assets.
896
-            $code = $this->rewrite_assets( $code );
896
+            $code = $this->rewrite_assets($code);
897 897
 
898 898
             // Minify.
899
-            $code = $this->run_minifier_on( $code );
899
+            $code = $this->run_minifier_on($code);
900 900
 
901 901
             // Bring back INJECTLATER stuff.
902
-            $code = $this->inject_minified( $code );
902
+            $code = $this->inject_minified($code);
903 903
 
904 904
             // Filter results.
905
-            $tmp_code = apply_filters( 'autoptimize_css_after_minify', $code );
906
-            if ( ! empty( $tmp_code ) ) {
905
+            $tmp_code = apply_filters('autoptimize_css_after_minify', $code);
906
+            if (!empty($tmp_code)) {
907 907
                 $code = $tmp_code;
908
-                unset( $tmp_code );
908
+                unset($tmp_code);
909 909
             }
910 910
 
911
-            $this->hashmap[ md5( $code ) ] = $hash;
911
+            $this->hashmap[md5($code)] = $hash;
912 912
         }
913 913
 
914
-        unset( $code );
914
+        unset($code);
915 915
         return true;
916 916
     }
917 917
 
918
-    public function run_minifier_on( $code )
918
+    public function run_minifier_on($code)
919 919
     {
920
-        if ( ! $this->alreadyminified ) {
921
-            $do_minify = apply_filters( 'autoptimize_css_do_minify', true );
920
+        if (!$this->alreadyminified) {
921
+            $do_minify = apply_filters('autoptimize_css_do_minify', true);
922 922
 
923
-            if ( $do_minify ) {
923
+            if ($do_minify) {
924 924
                 $cssmin   = new autoptimizeCSSmin();
925
-                $tmp_code = trim( $cssmin->run( $code ) );
925
+                $tmp_code = trim($cssmin->run($code));
926 926
 
927
-                if ( ! empty( $tmp_code ) ) {
927
+                if (!empty($tmp_code)) {
928 928
                     $code = $tmp_code;
929
-                    unset( $tmp_code );
929
+                    unset($tmp_code);
930 930
                 }
931 931
             }
932 932
         }
@@ -940,18 +940,18 @@  discard block
 block discarded – undo
940 940
     public function cache()
941 941
     {
942 942
         // CSS cache.
943
-        foreach ( $this->csscode as $media => $code ) {
944
-            if ( empty( $code ) ) {
943
+        foreach ($this->csscode as $media => $code) {
944
+            if (empty($code)) {
945 945
                 continue;
946 946
             }
947 947
 
948
-            $md5   = $this->hashmap[ md5( $code ) ];
949
-            $cache = new autoptimizeCache( $md5, 'css' );
950
-            if ( ! $cache->check() ) {
948
+            $md5   = $this->hashmap[md5($code)];
949
+            $cache = new autoptimizeCache($md5, 'css');
950
+            if (!$cache->check()) {
951 951
                 // Cache our code.
952
-                $cache->cache( $code, 'text/css' );
952
+                $cache->cache($code, 'text/css');
953 953
             }
954
-            $this->url[ $media ] = AUTOPTIMIZE_CACHE_URL . $cache->getname();
954
+            $this->url[$media] = AUTOPTIMIZE_CACHE_URL.$cache->getname();
955 955
         }
956 956
     }
957 957
 
@@ -961,99 +961,99 @@  discard block
 block discarded – undo
961 961
     public function getcontent()
962 962
     {
963 963
         // Restore the full content (only applies when "autoptimize_filter_css_justhead" filter is true).
964
-        if ( ! empty( $this->restofcontent ) ) {
964
+        if (!empty($this->restofcontent)) {
965 965
             $this->content      .= $this->restofcontent;
966 966
             $this->restofcontent = '';
967 967
         }
968 968
 
969 969
         // type is not added by default.
970 970
         $type_css = '';
971
-        if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
971
+        if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
972 972
             $type_css = 'type="text/css" ';
973 973
         }
974 974
 
975 975
         // Inject the new stylesheets.
976
-        $replace_tag = array( '<title', 'before' );
977
-        $replace_tag = apply_filters( 'autoptimize_filter_css_replacetag', $replace_tag, $this->content );
976
+        $replace_tag = array('<title', 'before');
977
+        $replace_tag = apply_filters('autoptimize_filter_css_replacetag', $replace_tag, $this->content);
978 978
 
979
-        if ( $this->inline ) {
980
-            foreach ( $this->csscode as $media => $code ) {
981
-                $this->inject_in_html( '<style ' . $type_css . 'media="' . $media . '">' . $code . '</style>', $replace_tag );
979
+        if ($this->inline) {
980
+            foreach ($this->csscode as $media => $code) {
981
+                $this->inject_in_html('<style '.$type_css.'media="'.$media.'">'.$code.'</style>', $replace_tag);
982 982
             }
983 983
         } else {
984
-            if ( $this->defer ) {
984
+            if ($this->defer) {
985 985
                 $preload_css_block  = '';
986 986
                 $inlined_ccss_block = '';
987 987
                 $noscript_css_block = '<noscript id="aonoscrcss">';
988 988
 
989 989
                 $defer_inline_code = $this->defer_inline;
990
-                if ( ! empty( $defer_inline_code ) ) {
991
-                    if ( apply_filters( 'autoptimize_filter_css_critcss_minify', true ) ) {
992
-                        $icss_hash  = md5( $defer_inline_code );
993
-                        $icss_cache = new autoptimizeCache( $icss_hash, 'css' );
994
-                        if ( $icss_cache->check() ) {
990
+                if (!empty($defer_inline_code)) {
991
+                    if (apply_filters('autoptimize_filter_css_critcss_minify', true)) {
992
+                        $icss_hash  = md5($defer_inline_code);
993
+                        $icss_cache = new autoptimizeCache($icss_hash, 'css');
994
+                        if ($icss_cache->check()) {
995 995
                             // we have the optimized inline CSS in cache.
996 996
                             $defer_inline_code = $icss_cache->retrieve();
997 997
                         } else {
998 998
                             $cssmin   = new autoptimizeCSSmin();
999
-                            $tmp_code = trim( $cssmin->run( $defer_inline_code ) );
999
+                            $tmp_code = trim($cssmin->run($defer_inline_code));
1000 1000
 
1001
-                            if ( ! empty( $tmp_code ) ) {
1001
+                            if (!empty($tmp_code)) {
1002 1002
                                 $defer_inline_code = $tmp_code;
1003
-                                $icss_cache->cache( $defer_inline_code, 'text/css' );
1004
-                                unset( $tmp_code );
1003
+                                $icss_cache->cache($defer_inline_code, 'text/css');
1004
+                                unset($tmp_code);
1005 1005
                             }
1006 1006
                         }
1007 1007
                     }
1008 1008
                     // inlined critical css set here, but injected when full CSS is injected
1009 1009
                     // to avoid CSS containing SVG with <title tag receiving the full CSS link.
1010
-                    $inlined_ccss_block = '<style ' . $type_css . 'id="aoatfcss" media="all">' . $defer_inline_code . '</style>';
1010
+                    $inlined_ccss_block = '<style '.$type_css.'id="aoatfcss" media="all">'.$defer_inline_code.'</style>';
1011 1011
                 }
1012 1012
             }
1013 1013
 
1014
-            foreach ( $this->url as $media => $url ) {
1015
-                $url = $this->url_replace_cdn( $url );
1014
+            foreach ($this->url as $media => $url) {
1015
+                $url = $this->url_replace_cdn($url);
1016 1016
 
1017 1017
                 // Add the stylesheet either deferred (import at bottom) or normal links in head.
1018
-                if ( $this->defer ) {
1018
+                if ($this->defer) {
1019 1019
                     $preload_onload = autoptimizeConfig::get_ao_css_preload_onload();
1020 1020
 
1021
-                    $preload_css_block  .= '<link rel="preload" as="style" media="' . $media . '" href="' . $url . '" onload="' . $preload_onload . '" />';
1022
-                    $noscript_css_block .= '<link ' . $type_css . 'media="' . $media . '" href="' . $url . '" rel="stylesheet" />';
1021
+                    $preload_css_block  .= '<link rel="preload" as="style" media="'.$media.'" href="'.$url.'" onload="'.$preload_onload.'" />';
1022
+                    $noscript_css_block .= '<link '.$type_css.'media="'.$media.'" href="'.$url.'" rel="stylesheet" />';
1023 1023
                 } else {
1024
-                    if ( strlen( $this->csscode[ $media ] ) > $this->cssinlinesize ) {
1025
-                        $this->inject_in_html( '<link ' . $type_css . 'media="' . $media . '" href="' . $url . '" rel="stylesheet" />', $replace_tag );
1026
-                    } elseif ( strlen( $this->csscode[ $media ] ) > 0 ) {
1027
-                        $this->inject_in_html( '<style ' . $type_css . 'media="' . $media . '">' . $this->csscode[ $media ] . '</style>', $replace_tag );
1024
+                    if (strlen($this->csscode[$media]) > $this->cssinlinesize) {
1025
+                        $this->inject_in_html('<link '.$type_css.'media="'.$media.'" href="'.$url.'" rel="stylesheet" />', $replace_tag);
1026
+                    } elseif (strlen($this->csscode[$media]) > 0) {
1027
+                        $this->inject_in_html('<style '.$type_css.'media="'.$media.'">'.$this->csscode[$media].'</style>', $replace_tag);
1028 1028
                     }
1029 1029
                 }
1030 1030
             }
1031 1031
 
1032
-            if ( $this->defer ) {
1032
+            if ($this->defer) {
1033 1033
                 $preload_polyfill    = autoptimizeConfig::get_ao_css_preload_polyfill();
1034 1034
                 $noscript_css_block .= '</noscript>';
1035 1035
                 // Inject inline critical CSS, the preloaded full CSS and the noscript-CSS.
1036
-                $this->inject_in_html( $inlined_ccss_block . $preload_css_block . $noscript_css_block, $replace_tag );
1036
+                $this->inject_in_html($inlined_ccss_block.$preload_css_block.$noscript_css_block, $replace_tag);
1037 1037
 
1038 1038
                 // Adds preload polyfill at end of body tag.
1039 1039
                 $this->inject_in_html(
1040
-                    apply_filters( 'autoptimize_css_preload_polyfill', $preload_polyfill ),
1041
-                    apply_filters( 'autoptimize_css_preload_polyfill_injectat', array( '</body>', 'before' ) )
1040
+                    apply_filters('autoptimize_css_preload_polyfill', $preload_polyfill),
1041
+                    apply_filters('autoptimize_css_preload_polyfill_injectat', array('</body>', 'before'))
1042 1042
                 );
1043 1043
             }
1044 1044
         }
1045 1045
 
1046 1046
         // restore comments.
1047
-        $this->content = $this->restore_comments( $this->content );
1047
+        $this->content = $this->restore_comments($this->content);
1048 1048
 
1049 1049
         // restore IE hacks.
1050
-        $this->content = $this->restore_iehacks( $this->content );
1050
+        $this->content = $this->restore_iehacks($this->content);
1051 1051
 
1052 1052
         // restore (no)script.
1053
-        $this->content = $this->restore_marked_content( 'SCRIPT', $this->content );
1053
+        $this->content = $this->restore_marked_content('SCRIPT', $this->content);
1054 1054
 
1055 1055
         // Restore noptimize.
1056
-        $this->content = $this->restore_noptimize( $this->content );
1056
+        $this->content = $this->restore_noptimize($this->content);
1057 1057
 
1058 1058
         // Return the modified stylesheet.
1059 1059
         return $this->content;
@@ -1065,44 +1065,44 @@  discard block
 block discarded – undo
1065 1065
      * @param string $file filename of optimized CSS-file.
1066 1066
      * @param string $code CSS-code in which to fix URL's.
1067 1067
      */
1068
-    static function fixurls( $file, $code )
1068
+    static function fixurls($file, $code)
1069 1069
     {
1070 1070
         // Switch all imports to the url() syntax.
1071
-        $code = preg_replace( '#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code );
1071
+        $code = preg_replace('#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code);
1072 1072
 
1073
-        if ( preg_match_all( self::ASSETS_REGEX, $code, $matches ) ) {
1074
-            $file = str_replace( WP_ROOT_DIR, '/', $file );
1073
+        if (preg_match_all(self::ASSETS_REGEX, $code, $matches)) {
1074
+            $file = str_replace(WP_ROOT_DIR, '/', $file);
1075 1075
             /**
1076 1076
              * Rollback as per https://github.com/futtta/autoptimize/issues/94
1077 1077
              * $file = str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', $file );
1078 1078
              */
1079
-            $dir = dirname( $file ); // Like /themes/expound/css.
1079
+            $dir = dirname($file); // Like /themes/expound/css.
1080 1080
 
1081 1081
             /**
1082 1082
              * $dir should not contain backslashes, since it's used to replace
1083 1083
              * urls, but it can contain them when running on Windows because
1084 1084
              * fixurls() is sometimes called with `ABSPATH . 'index.php'`
1085 1085
              */
1086
-            $dir = str_replace( '\\', '/', $dir );
1087
-            unset( $file ); // not used below at all.
1086
+            $dir = str_replace('\\', '/', $dir);
1087
+            unset($file); // not used below at all.
1088 1088
 
1089 1089
             $replace = array();
1090
-            foreach ( $matches[1] as $k => $url ) {
1090
+            foreach ($matches[1] as $k => $url) {
1091 1091
                 // Remove quotes.
1092
-                $url      = trim( $url, " \t\n\r\0\x0B\"'" );
1093
-                $no_q_url = trim( $url, "\"'" );
1094
-                if ( $url !== $no_q_url ) {
1092
+                $url      = trim($url, " \t\n\r\0\x0B\"'");
1093
+                $no_q_url = trim($url, "\"'");
1094
+                if ($url !== $no_q_url) {
1095 1095
                     $removed_quotes = true;
1096 1096
                 } else {
1097 1097
                     $removed_quotes = false;
1098 1098
                 }
1099 1099
 
1100
-                if ( '' === $no_q_url ) {
1100
+                if ('' === $no_q_url) {
1101 1101
                     continue;
1102 1102
                 }
1103 1103
 
1104 1104
                 $url = $no_q_url;
1105
-                if ( '/' === $url[0] || preg_match( '#^(https?://|ftp://|data:)#i', $url ) ) {
1105
+                if ('/' === $url[0] || preg_match('#^(https?://|ftp://|data:)#i', $url)) {
1106 1106
                     // URL is protocol-relative, host-relative or something we don't touch.
1107 1107
                     continue;
1108 1108
                 } else { // Relative URL.
@@ -1111,49 +1111,49 @@  discard block
 block discarded – undo
1111 1111
                      * rollback as per https://github.com/futtta/autoptimize/issues/94
1112 1112
                      * $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_CONTENT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) );
1113 1113
                      */
1114
-                    $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_ROOT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) );
1115
-                    $newurl = apply_filters( 'autoptimize_filter_css_fixurl_newurl', $newurl );
1114
+                    $newurl = preg_replace('/https?:/', '', str_replace(' ', '%20', AUTOPTIMIZE_WP_ROOT_URL.str_replace('//', '/', $dir.'/'.$url)));
1115
+                    $newurl = apply_filters('autoptimize_filter_css_fixurl_newurl', $newurl);
1116 1116
 
1117 1117
                     /**
1118 1118
                      * Hash the url + whatever was behind potentially for replacement
1119 1119
                      * We must do this, or different css classes referencing the same bg image (but
1120 1120
                      * different parts of it, say, in sprites and such) loose their stuff...
1121 1121
                      */
1122
-                    $hash = md5( $url . $matches[2][ $k ] );
1123
-                    $code = str_replace( $matches[0][ $k ], $hash, $code );
1122
+                    $hash = md5($url.$matches[2][$k]);
1123
+                    $code = str_replace($matches[0][$k], $hash, $code);
1124 1124
 
1125
-                    if ( $removed_quotes ) {
1126
-                        $replace[ $hash ] = "url('" . $newurl . "')" . $matches[2][ $k ];
1125
+                    if ($removed_quotes) {
1126
+                        $replace[$hash] = "url('".$newurl."')".$matches[2][$k];
1127 1127
                     } else {
1128
-                        $replace[ $hash ] = 'url(' . $newurl . ')' . $matches[2][ $k ];
1128
+                        $replace[$hash] = 'url('.$newurl.')'.$matches[2][$k];
1129 1129
                     }
1130 1130
                 }
1131 1131
             }
1132 1132
 
1133
-            $code = self::replace_longest_matches_first( $code, $replace );
1133
+            $code = self::replace_longest_matches_first($code, $replace);
1134 1134
         }
1135 1135
 
1136 1136
         return $code;
1137 1137
     }
1138 1138
 
1139
-    private function ismovable( $tag )
1139
+    private function ismovable($tag)
1140 1140
     {
1141
-        if ( ! $this->aggregate ) {
1141
+        if (!$this->aggregate) {
1142 1142
             return false;
1143 1143
         }
1144 1144
 
1145
-        if ( ! empty( $this->whitelist ) ) {
1146
-            foreach ( $this->whitelist as $match ) {
1147
-                if ( false !== strpos( $tag, $match ) ) {
1145
+        if (!empty($this->whitelist)) {
1146
+            foreach ($this->whitelist as $match) {
1147
+                if (false !== strpos($tag, $match)) {
1148 1148
                     return true;
1149 1149
                 }
1150 1150
             }
1151 1151
             // no match with whitelist.
1152 1152
             return false;
1153 1153
         } else {
1154
-            if ( is_array( $this->dontmove ) && ! empty( $this->dontmove ) ) {
1155
-                foreach ( $this->dontmove as $match ) {
1156
-                    if ( false !== strpos( $tag, $match ) ) {
1154
+            if (is_array($this->dontmove) && !empty($this->dontmove)) {
1155
+                foreach ($this->dontmove as $match) {
1156
+                    if (false !== strpos($tag, $match)) {
1157 1157
                         // Matched something.
1158 1158
                         return false;
1159 1159
                     }
@@ -1165,22 +1165,22 @@  discard block
 block discarded – undo
1165 1165
         }
1166 1166
     }
1167 1167
 
1168
-    private function can_inject_late( $css_path, $css )
1168
+    private function can_inject_late($css_path, $css)
1169 1169
     {
1170
-        $consider_minified_array = apply_filters( 'autoptimize_filter_css_consider_minified', false, $css_path );
1171
-        if ( true !== $this->inject_min_late ) {
1170
+        $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false, $css_path);
1171
+        if (true !== $this->inject_min_late) {
1172 1172
             // late-inject turned off.
1173 1173
             return false;
1174
-        } elseif ( ( false === strpos( $css_path, 'min.css' ) ) && ( str_replace( $consider_minified_array, '', $css_path ) === $css_path ) ) {
1174
+        } elseif ((false === strpos($css_path, 'min.css')) && (str_replace($consider_minified_array, '', $css_path) === $css_path)) {
1175 1175
             // file not minified based on filename & filter.
1176 1176
             return false;
1177
-        } elseif ( false !== strpos( $css, '@import' ) ) {
1177
+        } elseif (false !== strpos($css, '@import')) {
1178 1178
             // can't late-inject files with imports as those need to be aggregated.
1179 1179
             return false;
1180
-        } elseif ( ( false !== strpos( $css, '@font-face' ) ) && ( apply_filters( 'autoptimize_filter_css_fonts_cdn', false ) === true ) && ( ! empty( $this->cdn_url ) ) ) {
1180
+        } elseif ((false !== strpos($css, '@font-face')) && (apply_filters('autoptimize_filter_css_fonts_cdn', false) === true) && (!empty($this->cdn_url))) {
1181 1181
             // don't late-inject CSS with font-src's if fonts are set to be CDN'ed.
1182 1182
             return false;
1183
-        } elseif ( ( ( true == $this->datauris ) || ( ! empty( $this->cdn_url ) ) ) && preg_match( '#background[^;}]*url\(#Ui', $css ) ) {
1183
+        } elseif (((true == $this->datauris) || (!empty($this->cdn_url))) && preg_match('#background[^;}]*url\(#Ui', $css)) {
1184 1184
             // don't late-inject CSS with images if CDN is set OR if image inlining is on.
1185 1185
             return false;
1186 1186
         } else {
@@ -1198,41 +1198,41 @@  discard block
 block discarded – undo
1198 1198
      *
1199 1199
      * @return bool|string Url pointing to the minified css file or false.
1200 1200
      */
1201
-    public function minify_single( $filepath, $cache_miss = false )
1201
+    public function minify_single($filepath, $cache_miss = false)
1202 1202
     {
1203
-        $contents = $this->prepare_minify_single( $filepath );
1203
+        $contents = $this->prepare_minify_single($filepath);
1204 1204
 
1205
-        if ( empty( $contents ) ) {
1205
+        if (empty($contents)) {
1206 1206
             return false;
1207 1207
         }
1208 1208
 
1209 1209
         // Check cache.
1210
-        $hash  = 'single_' . md5( $contents );
1211
-        $cache = new autoptimizeCache( $hash, 'css' );
1212
-        do_action( 'autoptimize_action_css_hash', $hash );
1210
+        $hash  = 'single_'.md5($contents);
1211
+        $cache = new autoptimizeCache($hash, 'css');
1212
+        do_action('autoptimize_action_css_hash', $hash);
1213 1213
 
1214 1214
         // If not in cache already, minify...
1215
-        if ( ! $cache->check() || $cache_miss ) {
1215
+        if (!$cache->check() || $cache_miss) {
1216 1216
             // Fixurls...
1217
-            $contents = self::fixurls( $filepath, $contents );
1217
+            $contents = self::fixurls($filepath, $contents);
1218 1218
             // CDN-replace any referenced assets if needed...
1219
-            $contents = $this->hide_fontface_and_maybe_cdn( $contents );
1220
-            $contents = $this->replace_urls( $contents );
1221
-            $contents = $this->restore_fontface( $contents );
1219
+            $contents = $this->hide_fontface_and_maybe_cdn($contents);
1220
+            $contents = $this->replace_urls($contents);
1221
+            $contents = $this->restore_fontface($contents);
1222 1222
             // Now minify...
1223 1223
             $cssmin   = new autoptimizeCSSmin();
1224
-            $contents = trim( $cssmin->run( $contents ) );
1224
+            $contents = trim($cssmin->run($contents));
1225 1225
 
1226 1226
             // Check if minified cache content is empty.
1227
-            if ( empty( $contents ) ) {
1227
+            if (empty($contents)) {
1228 1228
                 return false;
1229 1229
             }
1230 1230
 
1231 1231
             // Store in cache.
1232
-            $cache->cache( $contents, 'text/css' );
1232
+            $cache->cache($contents, 'text/css');
1233 1233
         }
1234 1234
 
1235
-        $url = $this->build_minify_single_url( $cache );
1235
+        $url = $this->build_minify_single_url($cache);
1236 1236
 
1237 1237
         return $url;
1238 1238
     }
@@ -1252,19 +1252,19 @@  discard block
 block discarded – undo
1252 1252
         return $this->options;
1253 1253
     }
1254 1254
 
1255
-    public function replaceOptions( $options )
1255
+    public function replaceOptions($options)
1256 1256
     {
1257 1257
         $this->options = $options;
1258 1258
     }
1259 1259
 
1260
-    public function setOption( $name, $value )
1260
+    public function setOption($name, $value)
1261 1261
     {
1262
-        $this->options[ $name ] = $value;
1262
+        $this->options[$name] = $value;
1263 1263
         $this->$name            = $value;
1264 1264
     }
1265 1265
 
1266
-    public function getOption( $name )
1266
+    public function getOption($name)
1267 1267
     {
1268
-        return $this->options[ $name ];
1268
+        return $this->options[$name];
1269 1269
     }
1270 1270
 }
Please login to merge, or discard this patch.