@@ -75,18 +75,18 @@ |
||
75 | 75 | $wp_admin_bar->add_node( array( |
76 | 76 | 'id' => 'autoptimize-cache-info', |
77 | 77 | 'title' => '<p>' . __( "Cache Info", 'autoptimize' ) . '</p>' . |
78 | - '<div class="autoptimize-radial-bar" percentage="' . $percentage . '">' . |
|
79 | - '<div class="circle">'. |
|
80 | - '<div class="mask full"><div class="fill bg-' . $color . '"></div></div>'. |
|
81 | - '<div class="mask half"><div class="fill bg-' . $color . '"></div></div>'. |
|
82 | - '<div class="shadow"></div>'. |
|
83 | - '</div>'. |
|
84 | - '<div class="inset"><div class="percentage"><div class="numbers ' . $color . '">' . $percentage . '%</div></div></div>'. |
|
85 | - '</div>' . |
|
86 | - '<table>' . |
|
87 | - '<tr><td>' . __( "Size", 'autoptimize' ) . ':</td><td class="size ' . $color . '">' . $size . '</td></tr>' . |
|
88 | - '<tr><td>' . __( "Files", 'autoptimize' ) . ':</td><td class="files white">' . $files . '</td></tr>' . |
|
89 | - '</table>', |
|
78 | + '<div class="autoptimize-radial-bar" percentage="' . $percentage . '">' . |
|
79 | + '<div class="circle">'. |
|
80 | + '<div class="mask full"><div class="fill bg-' . $color . '"></div></div>'. |
|
81 | + '<div class="mask half"><div class="fill bg-' . $color . '"></div></div>'. |
|
82 | + '<div class="shadow"></div>'. |
|
83 | + '</div>'. |
|
84 | + '<div class="inset"><div class="percentage"><div class="numbers ' . $color . '">' . $percentage . '%</div></div></div>'. |
|
85 | + '</div>' . |
|
86 | + '<table>' . |
|
87 | + '<tr><td>' . __( "Size", 'autoptimize' ) . ':</td><td class="size ' . $color . '">' . $size . '</td></tr>' . |
|
88 | + '<tr><td>' . __( "Files", 'autoptimize' ) . ':</td><td class="files white">' . $files . '</td></tr>' . |
|
89 | + '</table>', |
|
90 | 90 | 'parent' => 'autoptimize' |
91 | 91 | )); |
92 | 92 |
@@ -1,35 +1,35 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if (!defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | class autoptimizeToolbar |
4 | 4 | { |
5 | 5 | public function __construct() |
6 | 6 | { |
7 | 7 | // If Cache is not available we don't add the Autoptimize Toolbar |
8 | - if( ! autoptimizeCache::cacheavail() ) { |
|
8 | + if (!autoptimizeCache::cacheavail()) { |
|
9 | 9 | return; |
10 | 10 | } |
11 | 11 | // Load admin toolbar feature once WordPress, all plugins, and the theme are fully loaded and instantiated. |
12 | - add_action( 'wp_loaded', array( $this, 'load_toolbar' ) ); |
|
12 | + add_action('wp_loaded', array($this, 'load_toolbar')); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | public function load_toolbar() |
16 | 16 | { |
17 | 17 | // Check permissions and that toolbar is not hidden via filter |
18 | - if ( current_user_can( 'manage_options' ) && apply_filters( 'autoptimize_filter_toolbar_show', true ) ) { |
|
18 | + if (current_user_can('manage_options') && apply_filters('autoptimize_filter_toolbar_show', true)) { |
|
19 | 19 | // Create a handler for the AJAX toolbar requests |
20 | - add_action( 'wp_ajax_autoptimize_delete_cache', array( $this, 'delete_cache' ) ); |
|
20 | + add_action('wp_ajax_autoptimize_delete_cache', array($this, 'delete_cache')); |
|
21 | 21 | |
22 | 22 | // Load custom styles, scripts and menu only when needed |
23 | - if ( is_admin_bar_showing() ) { |
|
24 | - if ( is_admin() ) { |
|
23 | + if (is_admin_bar_showing()) { |
|
24 | + if (is_admin()) { |
|
25 | 25 | // in the case of back-end |
26 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
26 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); |
|
27 | 27 | } else { |
28 | 28 | // in the case of front-end |
29 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
29 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts')); |
|
30 | 30 | } |
31 | 31 | // Add the Autoptimize Toolbar to the Admin bar |
32 | - add_action( 'admin_bar_menu', array( $this, 'add_toolbar' ), 100 ); |
|
32 | + add_action('admin_bar_menu', array($this, 'add_toolbar'), 100); |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $stats = autoptimizeCache::stats(); |
43 | 43 | |
44 | 44 | // Set the Max Size recommended for cache files |
45 | - $max_size = apply_filters( 'autoptimize_filter_cachecheck_maxsize', 512 * 1024 * 1024 ); |
|
45 | + $max_size = apply_filters('autoptimize_filter_cachecheck_maxsize', 512*1024*1024); |
|
46 | 46 | |
47 | 47 | // Retrieve the current Total Files in cache |
48 | 48 | $files = $stats[0]; |
@@ -52,83 +52,83 @@ discard block |
||
52 | 52 | $size = $this->format_filesize($bytes); |
53 | 53 | |
54 | 54 | // We calculated the percentage of cache used |
55 | - $percentage = ceil( $bytes / $max_size * 100 ); |
|
56 | - if ( $percentage > 100 ) { |
|
55 | + $percentage = ceil($bytes/$max_size*100); |
|
56 | + if ($percentage > 100) { |
|
57 | 57 | $percentage = 100; |
58 | 58 | } |
59 | 59 | // We define the type of color indicator for the current state of cache size. |
60 | 60 | // "green" if the size is less than 80% of the total recommended |
61 | 61 | // "orange" if over 80% |
62 | 62 | // "red" if over 100% |
63 | - $color = ( $percentage == 100 ) ? 'red' : ( ( $percentage > 80 ) ? 'orange' : 'green' ); |
|
63 | + $color = ($percentage == 100) ? 'red' : (($percentage > 80) ? 'orange' : 'green'); |
|
64 | 64 | |
65 | 65 | // Create or add new items into the Admin Toolbar. |
66 | 66 | // Main Autoptimize node |
67 | - $wp_admin_bar->add_node( array( |
|
67 | + $wp_admin_bar->add_node(array( |
|
68 | 68 | 'id' => 'autoptimize', |
69 | - 'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( "Autoptimize", 'autoptimize' ) . '</span>', |
|
70 | - 'href' => admin_url( 'options-general.php?page=autoptimize' ), |
|
71 | - 'meta' => array( 'class' => 'bullet-' . $color ) |
|
69 | + 'title' => '<span class="ab-icon"></span><span class="ab-label">'.__("Autoptimize", 'autoptimize').'</span>', |
|
70 | + 'href' => admin_url('options-general.php?page=autoptimize'), |
|
71 | + 'meta' => array('class' => 'bullet-'.$color) |
|
72 | 72 | )); |
73 | 73 | |
74 | 74 | // Cache Info node |
75 | - $wp_admin_bar->add_node( array( |
|
75 | + $wp_admin_bar->add_node(array( |
|
76 | 76 | 'id' => 'autoptimize-cache-info', |
77 | - 'title' => '<p>' . __( "Cache Info", 'autoptimize' ) . '</p>' . |
|
78 | - '<div class="autoptimize-radial-bar" percentage="' . $percentage . '">' . |
|
77 | + 'title' => '<p>'.__("Cache Info", 'autoptimize').'</p>'. |
|
78 | + '<div class="autoptimize-radial-bar" percentage="'.$percentage.'">'. |
|
79 | 79 | '<div class="circle">'. |
80 | - '<div class="mask full"><div class="fill bg-' . $color . '"></div></div>'. |
|
81 | - '<div class="mask half"><div class="fill bg-' . $color . '"></div></div>'. |
|
80 | + '<div class="mask full"><div class="fill bg-'.$color.'"></div></div>'. |
|
81 | + '<div class="mask half"><div class="fill bg-'.$color.'"></div></div>'. |
|
82 | 82 | '<div class="shadow"></div>'. |
83 | 83 | '</div>'. |
84 | - '<div class="inset"><div class="percentage"><div class="numbers ' . $color . '">' . $percentage . '%</div></div></div>'. |
|
85 | - '</div>' . |
|
86 | - '<table>' . |
|
87 | - '<tr><td>' . __( "Size", 'autoptimize' ) . ':</td><td class="size ' . $color . '">' . $size . '</td></tr>' . |
|
88 | - '<tr><td>' . __( "Files", 'autoptimize' ) . ':</td><td class="files white">' . $files . '</td></tr>' . |
|
84 | + '<div class="inset"><div class="percentage"><div class="numbers '.$color.'">'.$percentage.'%</div></div></div>'. |
|
85 | + '</div>'. |
|
86 | + '<table>'. |
|
87 | + '<tr><td>'.__("Size", 'autoptimize').':</td><td class="size '.$color.'">'.$size.'</td></tr>'. |
|
88 | + '<tr><td>'.__("Files", 'autoptimize').':</td><td class="files white">'.$files.'</td></tr>'. |
|
89 | 89 | '</table>', |
90 | 90 | 'parent' => 'autoptimize' |
91 | 91 | )); |
92 | 92 | |
93 | 93 | // Delete Cache node |
94 | - $wp_admin_bar->add_node( array( |
|
94 | + $wp_admin_bar->add_node(array( |
|
95 | 95 | 'id' => 'autoptimize-delete-cache', |
96 | - 'title' => __( "Delete Cache", 'autoptimize' ), |
|
96 | + 'title' => __("Delete Cache", 'autoptimize'), |
|
97 | 97 | 'parent' => 'autoptimize' |
98 | 98 | )); |
99 | 99 | } |
100 | 100 | |
101 | 101 | public function delete_cache() |
102 | 102 | { |
103 | - check_ajax_referer( 'ao_delcache_nonce', 'nonce' ); |
|
103 | + check_ajax_referer('ao_delcache_nonce', 'nonce'); |
|
104 | 104 | $result = false; |
105 | - if ( current_user_can( 'manage_options' ) ) |
|
105 | + if (current_user_can('manage_options')) |
|
106 | 106 | { |
107 | 107 | // We call the function for cleaning the Autoptimize cache |
108 | 108 | $result = autoptimizeCache::clearall(); |
109 | 109 | } |
110 | - wp_send_json( $result ); |
|
110 | + wp_send_json($result); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | public function enqueue_scripts() |
114 | 114 | { |
115 | 115 | // Autoptimize Toolbar Styles |
116 | - wp_enqueue_style( 'autoptimize-toolbar', plugins_url( '/static/toolbar.css', __FILE__ ), array(), time(), 'all' ); |
|
116 | + wp_enqueue_style('autoptimize-toolbar', plugins_url('/static/toolbar.css', __FILE__), array(), time(), 'all'); |
|
117 | 117 | // Autoptimize Toolbar Javascript |
118 | - wp_enqueue_script( 'autoptimize-toolbar', plugins_url( '/static/toolbar.js', __FILE__ ), array( 'jquery' ), time(), true ); |
|
118 | + wp_enqueue_script('autoptimize-toolbar', plugins_url('/static/toolbar.js', __FILE__), array('jquery'), time(), true); |
|
119 | 119 | // Localizes a registered script with data for a JavaScript variable. (We need this for the AJAX work properly in the front-end mode) |
120 | - wp_localize_script( 'autoptimize-toolbar', 'autoptimize_ajax_object', array( |
|
121 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
122 | - 'error_msg' => sprintf( __( 'Your Autoptimize cache might not have been purged successfully, please check on the <a href=%s>Autoptimize settings page</a>.', 'autoptimize' ), admin_url( 'options-general.php?page=autoptimize' ) . ' style="white-space:nowrap;"' ), |
|
123 | - 'dismiss_msg' => __( 'Dismiss this notice.' ), |
|
124 | - 'nonce' => wp_create_nonce( 'ao_delcache_nonce' ) |
|
125 | - ) ); |
|
120 | + wp_localize_script('autoptimize-toolbar', 'autoptimize_ajax_object', array( |
|
121 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
122 | + 'error_msg' => sprintf(__('Your Autoptimize cache might not have been purged successfully, please check on the <a href=%s>Autoptimize settings page</a>.', 'autoptimize'), admin_url('options-general.php?page=autoptimize').' style="white-space:nowrap;"'), |
|
123 | + 'dismiss_msg' => __('Dismiss this notice.'), |
|
124 | + 'nonce' => wp_create_nonce('ao_delcache_nonce') |
|
125 | + )); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | public function format_filesize($bytes, $decimals = 2) |
129 | 129 | { |
130 | - $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ); |
|
131 | - for ($i = 0; ($bytes / 1024) > 0.9; $i++, $bytes /= 1024) {} |
|
132 | - return sprintf( "%1.{$decimals}f %s", round( $bytes, $decimals ), $units[$i] ); |
|
130 | + $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
|
131 | + for ($i = 0; ($bytes/1024) > 0.9; $i++, $bytes /= 1024) {} |
|
132 | + return sprintf("%1.{$decimals}f %s", round($bytes, $decimals), $units[$i]); |
|
133 | 133 | } |
134 | 134 | } |
@@ -1,5 +1,8 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | class autoptimizeToolbar |
4 | 7 | { |
5 | 8 | public function __construct() |
@@ -139,6 +139,10 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | // hide everything between noptimize-comment tags |
142 | + |
|
143 | + /** |
|
144 | + * @param string $noptimize_in |
|
145 | + */ |
|
142 | 146 | protected function hide_noptimize($noptimize_in) { |
143 | 147 | if ( preg_match( '/<!--\s?noptimize\s?-->/', $noptimize_in ) ) { |
144 | 148 | $noptimize_out = preg_replace_callback( |
@@ -267,6 +271,9 @@ discard block |
||
267 | 271 | return $url; |
268 | 272 | } |
269 | 273 | |
274 | + /** |
|
275 | + * @param string $payload |
|
276 | + */ |
|
270 | 277 | protected function inject_in_html($payload,$replaceTag) { |
271 | 278 | if (strpos($this->content,$replaceTag[0])!== false) { |
272 | 279 | if ($replaceTag[1]==="after") { |
@@ -286,6 +293,9 @@ discard block |
||
286 | 293 | } |
287 | 294 | } |
288 | 295 | |
296 | + /** |
|
297 | + * @param string $tag |
|
298 | + */ |
|
289 | 299 | protected function isremovable($tag, $removables) { |
290 | 300 | foreach ($removables as $match) { |
291 | 301 | if (strpos($tag,$match)!==false) { |
@@ -296,6 +306,10 @@ discard block |
||
296 | 306 | } |
297 | 307 | |
298 | 308 | // inject already minified code in optimized JS/CSS |
309 | + |
|
310 | + /** |
|
311 | + * @return string |
|
312 | + */ |
|
299 | 313 | protected function inject_minified($in) { |
300 | 314 | if ( strpos( $in, '%%INJECTLATER%%' ) !== false ) { |
301 | 315 | $out = preg_replace_callback( |
@@ -340,6 +354,9 @@ discard block |
||
340 | 354 | return $out; |
341 | 355 | } |
342 | 356 | |
357 | + /** |
|
358 | + * @param string $pathIn |
|
359 | + */ |
|
343 | 360 | protected function minify_single($pathIn) { |
344 | 361 | // determine JS or CSS and set var (also mimetype), return false if neither |
345 | 362 | if ( $this->str_ends_in($pathIn,".js") === true ) { |
@@ -403,6 +420,9 @@ discard block |
||
403 | 420 | return $_CachedMinifiedUrl; |
404 | 421 | } |
405 | 422 | |
423 | + /** |
|
424 | + * @param string $needle |
|
425 | + */ |
|
406 | 426 | protected function str_ends_in($haystack,$needle) { |
407 | 427 | $needleLength = strlen($needle); |
408 | 428 | $haystackLength = strlen($haystack); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if (!defined('ABSPATH')) exit; // Exit if accessed directly |
|
3 | 3 | |
4 | 4 | abstract class autoptimizeBase { |
5 | 5 | protected $content = ''; |
@@ -23,37 +23,37 @@ discard block |
||
23 | 23 | |
24 | 24 | //Converts an URL to a full path |
25 | 25 | protected function getpath($url) { |
26 | - $url=apply_filters( 'autoptimize_filter_cssjs_alter_url', $url); |
|
26 | + $url = apply_filters('autoptimize_filter_cssjs_alter_url', $url); |
|
27 | 27 | |
28 | - if (strpos($url,'%')!==false) { |
|
29 | - $url=urldecode($url); |
|
28 | + if (strpos($url, '%') !== false) { |
|
29 | + $url = urldecode($url); |
|
30 | 30 | } |
31 | 31 | |
32 | - $siteHost=parse_url(AUTOPTIMIZE_WP_SITE_URL,PHP_URL_HOST); |
|
33 | - $contentHost=parse_url(AUTOPTIMIZE_WP_ROOT_URL,PHP_URL_HOST); |
|
32 | + $siteHost = parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST); |
|
33 | + $contentHost = parse_url(AUTOPTIMIZE_WP_ROOT_URL, PHP_URL_HOST); |
|
34 | 34 | |
35 | 35 | // normalize |
36 | - if (strpos($url,'//')===0) { |
|
36 | + if (strpos($url, '//') === 0) { |
|
37 | 37 | if (is_ssl()) { |
38 | 38 | $url = "https:".$url; |
39 | 39 | } else { |
40 | 40 | $url = "http:".$url; |
41 | 41 | } |
42 | - } else if ((strpos($url,'//')===false) && (strpos($url,$siteHost)===false)) { |
|
42 | + } else if ((strpos($url, '//') === false) && (strpos($url, $siteHost) === false)) { |
|
43 | 43 | if (AUTOPTIMIZE_WP_SITE_URL === $siteHost) { |
44 | 44 | $url = AUTOPTIMIZE_WP_SITE_URL.$url; |
45 | 45 | } else { |
46 | - $subdir_levels=substr_count(preg_replace("/https?:\/\//","",AUTOPTIMIZE_WP_SITE_URL),"/"); |
|
47 | - $url = AUTOPTIMIZE_WP_SITE_URL.str_repeat("/..",$subdir_levels).$url; |
|
46 | + $subdir_levels = substr_count(preg_replace("/https?:\/\//", "", AUTOPTIMIZE_WP_SITE_URL), "/"); |
|
47 | + $url = AUTOPTIMIZE_WP_SITE_URL.str_repeat("/..", $subdir_levels).$url; |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | if ($siteHost !== $contentHost) { |
52 | - $url=str_replace(AUTOPTIMIZE_WP_CONTENT_URL,AUTOPTIMIZE_WP_SITE_URL.AUTOPTIMIZE_WP_CONTENT_NAME,$url); |
|
52 | + $url = str_replace(AUTOPTIMIZE_WP_CONTENT_URL, AUTOPTIMIZE_WP_SITE_URL.AUTOPTIMIZE_WP_CONTENT_NAME, $url); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | // first check; hostname wp site should be hostname of url |
56 | - $thisHost=@parse_url($url,PHP_URL_HOST); |
|
56 | + $thisHost = @parse_url($url, PHP_URL_HOST); |
|
57 | 57 | if ($thisHost !== $siteHost) { |
58 | 58 | /* |
59 | 59 | * first try to get all domains from WPML (if available) |
@@ -65,18 +65,18 @@ discard block |
||
65 | 65 | |
66 | 66 | $multidomainsWPML = apply_filters('wpml_setting', array(), 'language_domains'); |
67 | 67 | if (!empty($multidomainsWPML)) { |
68 | - $multidomains = array_map(array($this,"ao_getDomain"),$multidomainsWPML); |
|
68 | + $multidomains = array_map(array($this, "ao_getDomain"), $multidomainsWPML); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | if (!empty($this->cdn_url)) { |
72 | - $multidomains[]=parse_url($this->cdn_url,PHP_URL_HOST); |
|
72 | + $multidomains[] = parse_url($this->cdn_url, PHP_URL_HOST); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | $multidomains = apply_filters('autoptimize_filter_cssjs_multidomain', $multidomains); |
76 | 76 | |
77 | 77 | if (!empty($multidomains)) { |
78 | - if (in_array($thisHost,$multidomains)) { |
|
79 | - $url=str_replace($thisHost, parse_url(AUTOPTIMIZE_WP_SITE_URL,PHP_URL_HOST), $url); |
|
78 | + if (in_array($thisHost, $multidomains)) { |
|
79 | + $url = str_replace($thisHost, parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST), $url); |
|
80 | 80 | } else { |
81 | 81 | return false; |
82 | 82 | } |
@@ -86,22 +86,22 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | // try to remove "wp root url" from url while not minding http<>https |
89 | - $tmp_ao_root = preg_replace('/https?:/','',AUTOPTIMIZE_WP_ROOT_URL); |
|
89 | + $tmp_ao_root = preg_replace('/https?:/', '', AUTOPTIMIZE_WP_ROOT_URL); |
|
90 | 90 | if ($siteHost !== $contentHost) { |
91 | 91 | // as we replaced the content-domain with the site-domain, we should match against that |
92 | - $tmp_ao_root = preg_replace('/https?:/','',AUTOPTIMIZE_WP_SITE_URL); |
|
92 | + $tmp_ao_root = preg_replace('/https?:/', '', AUTOPTIMIZE_WP_SITE_URL); |
|
93 | 93 | } |
94 | - $tmp_url = preg_replace('/https?:/','',$url); |
|
95 | - $path = str_replace($tmp_ao_root,'',$tmp_url); |
|
94 | + $tmp_url = preg_replace('/https?:/', '', $url); |
|
95 | + $path = str_replace($tmp_ao_root, '', $tmp_url); |
|
96 | 96 | |
97 | 97 | // if path starts with :// or //, this is not a URL in the WP context and we have to assume we can't aggregate |
98 | - if (preg_match('#^:?//#',$path)) { |
|
98 | + if (preg_match('#^:?//#', $path)) { |
|
99 | 99 | /** External script/css (adsense, etc) */ |
100 | 100 | return false; |
101 | 101 | } |
102 | 102 | |
103 | 103 | // prepend with WP_ROOT_DIR to have full path to file |
104 | - $path = str_replace('//','/',WP_ROOT_DIR.$path); |
|
104 | + $path = str_replace('//', '/', WP_ROOT_DIR.$path); |
|
105 | 105 | |
106 | 106 | // final check: does file exist and is it readable |
107 | 107 | if (file_exists($path) && is_file($path) && is_readable($path)) { |
@@ -114,25 +114,25 @@ discard block |
||
114 | 114 | // needed for WPML-filter |
115 | 115 | protected function ao_getDomain($in) { |
116 | 116 | // make sure the url starts with something vaguely resembling a protocol |
117 | - if ((strpos($in,"http")!==0) && (strpos($in,"//")!==0)) { |
|
118 | - $in="http://".$in; |
|
117 | + if ((strpos($in, "http") !== 0) && (strpos($in, "//") !== 0)) { |
|
118 | + $in = "http://".$in; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | // do the actual parse_url |
122 | - $out = parse_url($in,PHP_URL_HOST); |
|
122 | + $out = parse_url($in, PHP_URL_HOST); |
|
123 | 123 | |
124 | 124 | // fallback if parse_url does not understand the url is in fact a url |
125 | - if (empty($out)) $out=$in; |
|
125 | + if (empty($out)) $out = $in; |
|
126 | 126 | |
127 | 127 | return $out; |
128 | 128 | } |
129 | 129 | |
130 | 130 | |
131 | 131 | // logger |
132 | - protected function ao_logger($logmsg,$appendHTML=true) { |
|
132 | + protected function ao_logger($logmsg, $appendHTML = true) { |
|
133 | 133 | if ($appendHTML) { |
134 | - $logmsg="<!--noptimize--><!-- ".$logmsg." --><!--/noptimize-->"; |
|
135 | - $this->content.=$logmsg; |
|
134 | + $logmsg = "<!--noptimize--><!-- ".$logmsg." --><!--/noptimize-->"; |
|
135 | + $this->content .= $logmsg; |
|
136 | 136 | } else { |
137 | 137 | error_log("Autoptimize: ".$logmsg); |
138 | 138 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | // hide everything between noptimize-comment tags |
142 | 142 | protected function hide_noptimize($noptimize_in) { |
143 | - if ( preg_match( '/<!--\s?noptimize\s?-->/', $noptimize_in ) ) { |
|
143 | + if (preg_match('/<!--\s?noptimize\s?-->/', $noptimize_in)) { |
|
144 | 144 | $noptimize_out = preg_replace_callback( |
145 | 145 | '#<!--\s?noptimize\s?-->.*?<!--\s?/\s?noptimize\s?-->#is', |
146 | 146 | create_function( |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | // unhide noptimize-tags |
159 | 159 | protected function restore_noptimize($noptimize_in) { |
160 | - if ( strpos( $noptimize_in, '%%NOPTIMIZE%%' ) !== false ) { |
|
160 | + if (strpos($noptimize_in, '%%NOPTIMIZE%%') !== false) { |
|
161 | 161 | $noptimize_out = preg_replace_callback( |
162 | 162 | '#%%NOPTIMIZE%%(.*?)%%NOPTIMIZE%%#is', |
163 | 163 | create_function( |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | } |
174 | 174 | |
175 | 175 | protected function hide_iehacks($iehacks_in) { |
176 | - if ( strpos( $iehacks_in, '<!--[if' ) !== false ) { |
|
176 | + if (strpos($iehacks_in, '<!--[if') !== false) { |
|
177 | 177 | $iehacks_out = preg_replace_callback( |
178 | 178 | '#<!--\[if.*?\[endif\]-->#is', |
179 | 179 | create_function( |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | protected function restore_iehacks($iehacks_in) { |
192 | - if ( strpos( $iehacks_in, '%%IEHACK%%' ) !== false ) { |
|
192 | + if (strpos($iehacks_in, '%%IEHACK%%') !== false) { |
|
193 | 193 | $iehacks_out = preg_replace_callback( |
194 | 194 | '#%%IEHACK%%(.*?)%%IEHACK%%#is', |
195 | 195 | create_function( |
@@ -199,13 +199,13 @@ discard block |
||
199 | 199 | $iehacks_in |
200 | 200 | ); |
201 | 201 | } else { |
202 | - $iehacks_out=$iehacks_in; |
|
202 | + $iehacks_out = $iehacks_in; |
|
203 | 203 | } |
204 | 204 | return $iehacks_out; |
205 | 205 | } |
206 | 206 | |
207 | 207 | protected function hide_comments($comments_in) { |
208 | - if ( strpos( $comments_in, '<!--' ) !== false ) { |
|
208 | + if (strpos($comments_in, '<!--') !== false) { |
|
209 | 209 | $comments_out = preg_replace_callback( |
210 | 210 | '#<!--.*?-->#is', |
211 | 211 | create_function( |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | } |
222 | 222 | |
223 | 223 | protected function restore_comments($comments_in) { |
224 | - if ( strpos( $comments_in, '%%COMMENTS%%' ) !== false ) { |
|
224 | + if (strpos($comments_in, '%%COMMENTS%%') !== false) { |
|
225 | 225 | $comments_out = preg_replace_callback( |
226 | 226 | '#%%COMMENTS%%(.*?)%%COMMENTS%%#is', |
227 | 227 | create_function( |
@@ -231,31 +231,31 @@ discard block |
||
231 | 231 | $comments_in |
232 | 232 | ); |
233 | 233 | } else { |
234 | - $comments_out=$comments_in; |
|
234 | + $comments_out = $comments_in; |
|
235 | 235 | } |
236 | 236 | return $comments_out; |
237 | 237 | } |
238 | 238 | |
239 | - protected function url_replace_cdn( $url ) { |
|
239 | + protected function url_replace_cdn($url) { |
|
240 | 240 | // API filter to change base CDN URL |
241 | - $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $this->cdn_url ); |
|
241 | + $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $this->cdn_url); |
|
242 | 242 | |
243 | - if ( !empty($cdn_url) ) { |
|
243 | + if (!empty($cdn_url)) { |
|
244 | 244 | // prepend domain-less absolute URL's |
245 | - if ( ( substr( $url, 0, 1 ) === '/' ) && ( substr( $url, 1, 1 ) !== '/' ) ) { |
|
246 | - $url = rtrim( $cdn_url, '/' ) . $url; |
|
245 | + if ((substr($url, 0, 1) === '/') && (substr($url, 1, 1) !== '/')) { |
|
246 | + $url = rtrim($cdn_url, '/').$url; |
|
247 | 247 | } else { |
248 | 248 | // get wordpress base URL |
249 | - $WPSiteBreakdown = parse_url( AUTOPTIMIZE_WP_SITE_URL ); |
|
250 | - $WPBaseUrl = $WPSiteBreakdown['scheme'] . '://' . $WPSiteBreakdown['host']; |
|
251 | - if ( ! empty( $WPSiteBreakdown['port'] ) ) { |
|
252 | - $WPBaseUrl .= ":" . $WPSiteBreakdown['port']; |
|
249 | + $WPSiteBreakdown = parse_url(AUTOPTIMIZE_WP_SITE_URL); |
|
250 | + $WPBaseUrl = $WPSiteBreakdown['scheme'].'://'.$WPSiteBreakdown['host']; |
|
251 | + if (!empty($WPSiteBreakdown['port'])) { |
|
252 | + $WPBaseUrl .= ":".$WPSiteBreakdown['port']; |
|
253 | 253 | } |
254 | 254 | // replace full url's with scheme |
255 | - $tmp_url = str_replace( $WPBaseUrl, rtrim( $cdn_url, '/' ), $url ); |
|
256 | - if ( $tmp_url === $url ) { |
|
255 | + $tmp_url = str_replace($WPBaseUrl, rtrim($cdn_url, '/'), $url); |
|
256 | + if ($tmp_url === $url) { |
|
257 | 257 | // last attempt; replace scheme-less URL's |
258 | - $url = str_replace( preg_replace( '/https?:/', '', $WPBaseUrl ), rtrim( $cdn_url, '/' ), $url ); |
|
258 | + $url = str_replace(preg_replace('/https?:/', '', $WPBaseUrl), rtrim($cdn_url, '/'), $url); |
|
259 | 259 | } else { |
260 | 260 | $url = $tmp_url; |
261 | 261 | } |
@@ -263,32 +263,32 @@ discard block |
||
263 | 263 | } |
264 | 264 | |
265 | 265 | // allow API filter to alter URL after CDN replacement |
266 | - $url = apply_filters( 'autoptimize_filter_base_replace_cdn', $url ); |
|
266 | + $url = apply_filters('autoptimize_filter_base_replace_cdn', $url); |
|
267 | 267 | return $url; |
268 | 268 | } |
269 | 269 | |
270 | - protected function inject_in_html($payload,$replaceTag) { |
|
271 | - if (strpos($this->content,$replaceTag[0])!== false) { |
|
272 | - if ($replaceTag[1]==="after") { |
|
273 | - $replaceBlock=$replaceTag[0].$payload; |
|
274 | - } else if ($replaceTag[1]==="replace"){ |
|
275 | - $replaceBlock=$payload; |
|
270 | + protected function inject_in_html($payload, $replaceTag) { |
|
271 | + if (strpos($this->content, $replaceTag[0]) !== false) { |
|
272 | + if ($replaceTag[1] === "after") { |
|
273 | + $replaceBlock = $replaceTag[0].$payload; |
|
274 | + } else if ($replaceTag[1] === "replace") { |
|
275 | + $replaceBlock = $payload; |
|
276 | 276 | } else { |
277 | - $replaceBlock=$payload.$replaceTag[0]; |
|
277 | + $replaceBlock = $payload.$replaceTag[0]; |
|
278 | 278 | } |
279 | - $this->content = substr_replace($this->content,$replaceBlock,strpos($this->content,$replaceTag[0]),strlen($replaceTag[0])); |
|
279 | + $this->content = substr_replace($this->content, $replaceBlock, strpos($this->content, $replaceTag[0]), strlen($replaceTag[0])); |
|
280 | 280 | } else { |
281 | 281 | $this->content .= $payload; |
282 | 282 | if (!$this->tagWarning) { |
283 | - $this->content .= "<!--noptimize--><!-- Autoptimize found a problem with the HTML in your Theme, tag \"".str_replace(array("<",">"),"",$replaceTag[0])."\" missing --><!--/noptimize-->"; |
|
284 | - $this->tagWarning=true; |
|
283 | + $this->content .= "<!--noptimize--><!-- Autoptimize found a problem with the HTML in your Theme, tag \"".str_replace(array("<", ">"), "", $replaceTag[0])."\" missing --><!--/noptimize-->"; |
|
284 | + $this->tagWarning = true; |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | } |
288 | 288 | |
289 | 289 | protected function isremovable($tag, $removables) { |
290 | 290 | foreach ($removables as $match) { |
291 | - if (strpos($tag,$match)!==false) { |
|
291 | + if (strpos($tag, $match) !== false) { |
|
292 | 292 | return true; |
293 | 293 | } |
294 | 294 | } |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | |
298 | 298 | // inject already minified code in optimized JS/CSS |
299 | 299 | protected function inject_minified($in) { |
300 | - if ( strpos( $in, '%%INJECTLATER%%' ) !== false ) { |
|
300 | + if (strpos($in, '%%INJECTLATER%%') !== false) { |
|
301 | 301 | $out = preg_replace_callback( |
302 | 302 | '#%%INJECTLATER%%(.*?)%%INJECTLATER%%#is', |
303 | 303 | create_function( |
@@ -342,47 +342,47 @@ discard block |
||
342 | 342 | |
343 | 343 | protected function minify_single($pathIn) { |
344 | 344 | // determine JS or CSS and set var (also mimetype), return false if neither |
345 | - if ( $this->str_ends_in($pathIn,".js") === true ) { |
|
346 | - $codeType="js"; |
|
347 | - $codeMime="text/javascript"; |
|
348 | - } else if ( $this->str_ends_in($pathIn,".css") === true ) { |
|
349 | - $codeType="css"; |
|
350 | - $codeMime="text/css"; |
|
345 | + if ($this->str_ends_in($pathIn, ".js") === true) { |
|
346 | + $codeType = "js"; |
|
347 | + $codeMime = "text/javascript"; |
|
348 | + } else if ($this->str_ends_in($pathIn, ".css") === true) { |
|
349 | + $codeType = "css"; |
|
350 | + $codeMime = "text/css"; |
|
351 | 351 | } else { |
352 | 352 | return false; |
353 | 353 | } |
354 | 354 | |
355 | 355 | // if min.js or min.css return false |
356 | - if (( $this->str_ends_in($pathIn,"-min.".$codeType) === true ) || ( $this->str_ends_in($pathIn,".min.".$codeType) === true ) || ( $this->str_ends_in($pathIn,"js/jquery/jquery.js") === true ) ) { |
|
356 | + if (($this->str_ends_in($pathIn, "-min.".$codeType) === true) || ($this->str_ends_in($pathIn, ".min.".$codeType) === true) || ($this->str_ends_in($pathIn, "js/jquery/jquery.js") === true)) { |
|
357 | 357 | return false; |
358 | 358 | } |
359 | 359 | |
360 | 360 | // read file, return false if empty |
361 | 361 | $_toMinify = file_get_contents($pathIn); |
362 | - if ( empty($_toMinify) ) return false; |
|
362 | + if (empty($_toMinify)) return false; |
|
363 | 363 | |
364 | 364 | // check cache |
365 | 365 | $_md5hash = "single_".md5($_toMinify); |
366 | - $_cache = new autoptimizeCache($_md5hash,$codeType); |
|
367 | - if ($_cache->check() ) { |
|
366 | + $_cache = new autoptimizeCache($_md5hash, $codeType); |
|
367 | + if ($_cache->check()) { |
|
368 | 368 | $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
369 | 369 | } else { |
370 | 370 | // if not in cache first minify |
371 | 371 | $_Minified = $_toMinify; |
372 | 372 | if ($codeType === "js") { |
373 | - if (class_exists('JSMin') && apply_filters( 'autoptimize_js_do_minify' , true)) { |
|
374 | - if (@is_callable(array("JSMin","minify"))) { |
|
373 | + if (class_exists('JSMin') && apply_filters('autoptimize_js_do_minify', true)) { |
|
374 | + if (@is_callable(array("JSMin", "minify"))) { |
|
375 | 375 | $tmp_code = trim(JSMin::minify($_toMinify)); |
376 | 376 | } |
377 | 377 | } |
378 | 378 | } else if ($codeType === "css") { |
379 | 379 | if (class_exists('Minify_CSS_Compressor')) { |
380 | 380 | $tmp_code = trim(Minify_CSS_Compressor::process($_toMinify)); |
381 | - } else if(class_exists('CSSmin')) { |
|
381 | + } else if (class_exists('CSSmin')) { |
|
382 | 382 | $cssmin = new CSSmin(); |
383 | - if (method_exists($cssmin,"run")) { |
|
383 | + if (method_exists($cssmin, "run")) { |
|
384 | 384 | $tmp_code = trim($cssmin->run($_toMinify)); |
385 | - } elseif (@is_callable(array($cssmin,"minify"))) { |
|
385 | + } elseif (@is_callable(array($cssmin, "minify"))) { |
|
386 | 386 | $tmp_code = trim(CssMin::minify($_toMinify)); |
387 | 387 | } |
388 | 388 | } |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | unset($tmp_code); |
393 | 393 | } |
394 | 394 | // and then cache |
395 | - $_cache->cache($_Minified,$codeMime); |
|
395 | + $_cache->cache($_Minified, $codeMime); |
|
396 | 396 | $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
397 | 397 | } |
398 | 398 | unset($_cache); |
@@ -403,10 +403,10 @@ discard block |
||
403 | 403 | return $_CachedMinifiedUrl; |
404 | 404 | } |
405 | 405 | |
406 | - protected function str_ends_in($haystack,$needle) { |
|
406 | + protected function str_ends_in($haystack, $needle) { |
|
407 | 407 | $needleLength = strlen($needle); |
408 | 408 | $haystackLength = strlen($haystack); |
409 | - $lastPos=strrpos($haystack,$needle); |
|
409 | + $lastPos = strrpos($haystack, $needle); |
|
410 | 410 | if ($lastPos === $haystackLength - $needleLength) { |
411 | 411 | return true; |
412 | 412 | } else { |
@@ -1,5 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly |
|
3 | 6 | |
4 | 7 | abstract class autoptimizeBase { |
5 | 8 | protected $content = ''; |
@@ -122,7 +125,9 @@ discard block |
||
122 | 125 | $out = parse_url($in,PHP_URL_HOST); |
123 | 126 | |
124 | 127 | // fallback if parse_url does not understand the url is in fact a url |
125 | - if (empty($out)) $out=$in; |
|
128 | + if (empty($out)) { |
|
129 | + $out=$in; |
|
130 | + } |
|
126 | 131 | |
127 | 132 | return $out; |
128 | 133 | } |
@@ -359,7 +364,9 @@ discard block |
||
359 | 364 | |
360 | 365 | // read file, return false if empty |
361 | 366 | $_toMinify = file_get_contents($pathIn); |
362 | - if ( empty($_toMinify) ) return false; |
|
367 | + if ( empty($_toMinify) ) { |
|
368 | + return false; |
|
369 | + } |
|
363 | 370 | |
364 | 371 | // check cache |
365 | 372 | $_md5hash = "single_".md5($_toMinify); |
@@ -341,43 +341,43 @@ discard block |
||
341 | 341 | } |
342 | 342 | |
343 | 343 | protected function minify_single($pathIn) { |
344 | - // determine JS or CSS and set var (also mimetype), return false if neither |
|
345 | - if ( $this->str_ends_in($pathIn,".js") === true ) { |
|
346 | - $codeType="js"; |
|
347 | - $codeMime="text/javascript"; |
|
348 | - } else if ( $this->str_ends_in($pathIn,".css") === true ) { |
|
349 | - $codeType="css"; |
|
350 | - $codeMime="text/css"; |
|
351 | - } else { |
|
352 | - return false; |
|
353 | - } |
|
344 | + // determine JS or CSS and set var (also mimetype), return false if neither |
|
345 | + if ( $this->str_ends_in($pathIn,".js") === true ) { |
|
346 | + $codeType="js"; |
|
347 | + $codeMime="text/javascript"; |
|
348 | + } else if ( $this->str_ends_in($pathIn,".css") === true ) { |
|
349 | + $codeType="css"; |
|
350 | + $codeMime="text/css"; |
|
351 | + } else { |
|
352 | + return false; |
|
353 | + } |
|
354 | 354 | |
355 | - // if min.js or min.css return false |
|
356 | - if (( $this->str_ends_in($pathIn,"-min.".$codeType) === true ) || ( $this->str_ends_in($pathIn,".min.".$codeType) === true ) || ( $this->str_ends_in($pathIn,"js/jquery/jquery.js") === true ) ) { |
|
357 | - return false; |
|
358 | - } |
|
355 | + // if min.js or min.css return false |
|
356 | + if (( $this->str_ends_in($pathIn,"-min.".$codeType) === true ) || ( $this->str_ends_in($pathIn,".min.".$codeType) === true ) || ( $this->str_ends_in($pathIn,"js/jquery/jquery.js") === true ) ) { |
|
357 | + return false; |
|
358 | + } |
|
359 | 359 | |
360 | - // read file, return false if empty |
|
361 | - $_toMinify = file_get_contents($pathIn); |
|
362 | - if ( empty($_toMinify) ) return false; |
|
360 | + // read file, return false if empty |
|
361 | + $_toMinify = file_get_contents($pathIn); |
|
362 | + if ( empty($_toMinify) ) return false; |
|
363 | 363 | |
364 | - // check cache |
|
365 | - $_md5hash = "single_".md5($_toMinify); |
|
366 | - $_cache = new autoptimizeCache($_md5hash,$codeType); |
|
367 | - if ($_cache->check() ) { |
|
368 | - $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
|
369 | - } else { |
|
370 | - // if not in cache first minify |
|
371 | - $_Minified = $_toMinify; |
|
372 | - if ($codeType === "js") { |
|
373 | - if (class_exists('JSMin') && apply_filters( 'autoptimize_js_do_minify' , true)) { |
|
374 | - if (@is_callable(array("JSMin","minify"))) { |
|
375 | - $tmp_code = trim(JSMin::minify($_toMinify)); |
|
376 | - } |
|
377 | - } |
|
378 | - } else if ($codeType === "css") { |
|
364 | + // check cache |
|
365 | + $_md5hash = "single_".md5($_toMinify); |
|
366 | + $_cache = new autoptimizeCache($_md5hash,$codeType); |
|
367 | + if ($_cache->check() ) { |
|
368 | + $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
|
369 | + } else { |
|
370 | + // if not in cache first minify |
|
371 | + $_Minified = $_toMinify; |
|
372 | + if ($codeType === "js") { |
|
373 | + if (class_exists('JSMin') && apply_filters( 'autoptimize_js_do_minify' , true)) { |
|
374 | + if (@is_callable(array("JSMin","minify"))) { |
|
375 | + $tmp_code = trim(JSMin::minify($_toMinify)); |
|
376 | + } |
|
377 | + } |
|
378 | + } else if ($codeType === "css") { |
|
379 | 379 | if (class_exists('Minify_CSS_Compressor')) { |
380 | - $tmp_code = trim(Minify_CSS_Compressor::process($_toMinify)); |
|
380 | + $tmp_code = trim(Minify_CSS_Compressor::process($_toMinify)); |
|
381 | 381 | } else if(class_exists('CSSmin')) { |
382 | 382 | $cssmin = new CSSmin(); |
383 | 383 | if (method_exists($cssmin,"run")) { |
@@ -386,31 +386,31 @@ discard block |
||
386 | 386 | $tmp_code = trim(CssMin::minify($_toMinify)); |
387 | 387 | } |
388 | 388 | } |
389 | - } |
|
390 | - if (!empty($tmp_code)) { |
|
391 | - $_Minified = $tmp_code; |
|
392 | - unset($tmp_code); |
|
393 | - } |
|
394 | - // and then cache |
|
395 | - $_cache->cache($_Minified,$codeMime); |
|
396 | - $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
|
397 | - } |
|
398 | - unset($_cache); |
|
389 | + } |
|
390 | + if (!empty($tmp_code)) { |
|
391 | + $_Minified = $tmp_code; |
|
392 | + unset($tmp_code); |
|
393 | + } |
|
394 | + // and then cache |
|
395 | + $_cache->cache($_Minified,$codeMime); |
|
396 | + $_CachedMinifiedUrl = AUTOPTIMIZE_CACHE_URL.$_cache->getname(); |
|
397 | + } |
|
398 | + unset($_cache); |
|
399 | 399 | |
400 | - // if CDN, then CDN |
|
401 | - $_CachedMinifiedUrl = $this->url_replace_cdn($_CachedMinifiedUrl); |
|
400 | + // if CDN, then CDN |
|
401 | + $_CachedMinifiedUrl = $this->url_replace_cdn($_CachedMinifiedUrl); |
|
402 | 402 | |
403 | - return $_CachedMinifiedUrl; |
|
404 | - } |
|
403 | + return $_CachedMinifiedUrl; |
|
404 | + } |
|
405 | 405 | |
406 | - protected function str_ends_in($haystack,$needle) { |
|
407 | - $needleLength = strlen($needle); |
|
408 | - $haystackLength = strlen($haystack); |
|
409 | - $lastPos=strrpos($haystack,$needle); |
|
410 | - if ($lastPos === $haystackLength - $needleLength) { |
|
411 | - return true; |
|
412 | - } else { |
|
413 | - return false; |
|
414 | - } |
|
415 | - } |
|
406 | + protected function str_ends_in($haystack,$needle) { |
|
407 | + $needleLength = strlen($needle); |
|
408 | + $haystackLength = strlen($haystack); |
|
409 | + $lastPos=strrpos($haystack,$needle); |
|
410 | + if ($lastPos === $haystackLength - $needleLength) { |
|
411 | + return true; |
|
412 | + } else { |
|
413 | + return false; |
|
414 | + } |
|
415 | + } |
|
416 | 416 | } |