Version Description
- Reworked handling for cases where multiple js files are combined into one on Google's servers. In the past this has been mostly a non-issue because the dependencies took care of it, but due to changes in the latest jQuery UI this stopped working as expected.
Download this release
Release Info
Developer | jczorkmid |
Plugin | Use Google Libraries |
Version | 1.2 |
Comparing to | |
See all releases |
Code changes from version 1.1.2 to 1.2
- README.txt +13 -5
- use-google-libraries.php +290 -295
README.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: jczorkmid
|
|
3 |
Donate link: http://jasonpenney.net/donate
|
4 |
Tags: javascript, performance, CDN, Google, jQuery, Prototype, MooTools, Dojo, Google AJAX Libraries API, YSlow, Page Speed
|
5 |
Requires at least: 2.9.1
|
6 |
-
Tested up to: 3.
|
7 |
-
Stable tag: 1.
|
8 |
|
9 |
Allows your site to use common javascript libraries from Google's AJAX
|
10 |
Libraries CDN, rather than from WordPress's own copies.
|
@@ -71,6 +71,7 @@ Please see the section on **Incompatible Plugins** and
|
|
71 |
|
72 |
== Incompatible Plugins ==
|
73 |
|
|
|
74 |
== Incompatible Themes ==
|
75 |
|
76 |
= K2 =
|
@@ -80,6 +81,13 @@ using K2.
|
|
80 |
|
81 |
== Changelog ==
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
= 1.1.2 =
|
84 |
|
85 |
+ Updated jQuery UI to work with WordPress 3.1rc1
|
@@ -149,8 +157,8 @@ from [Peter Wilson](http://peterwilson.cc/).
|
|
149 |
|
150 |
== Upgrade Notice ==
|
151 |
|
152 |
-
= 1.
|
153 |
-
|
154 |
|
155 |
== A Request ==
|
156 |
|
@@ -193,4 +201,4 @@ which has very similar goals to this plugin.
|
|
193 |
== Future Plans ==
|
194 |
|
195 |
+ add ability to enable/disable loading from Google for specific libraries
|
196 |
-
|
3 |
Donate link: http://jasonpenney.net/donate
|
4 |
Tags: javascript, performance, CDN, Google, jQuery, Prototype, MooTools, Dojo, Google AJAX Libraries API, YSlow, Page Speed
|
5 |
Requires at least: 2.9.1
|
6 |
+
Tested up to: 3.3
|
7 |
+
Stable tag: 1.2
|
8 |
|
9 |
Allows your site to use common javascript libraries from Google's AJAX
|
10 |
Libraries CDN, rather than from WordPress's own copies.
|
71 |
|
72 |
== Incompatible Plugins ==
|
73 |
|
74 |
+
|
75 |
== Incompatible Themes ==
|
76 |
|
77 |
= K2 =
|
81 |
|
82 |
== Changelog ==
|
83 |
|
84 |
+
= 1.2 =
|
85 |
+
|
86 |
+
+ Reworked handling for cases where multiple js files are combined
|
87 |
+
into one on Google's servers. In the past this has been mostly a
|
88 |
+
non-issue because the dependencies took care of it, but due to changes
|
89 |
+
in the latest jQuery UI this stopped working as expected.
|
90 |
+
|
91 |
= 1.1.2 =
|
92 |
|
93 |
+ Updated jQuery UI to work with WordPress 3.1rc1
|
157 |
|
158 |
== Upgrade Notice ==
|
159 |
|
160 |
+
= 1.2 =
|
161 |
+
Dependency support improved. Needed for WordPress 3.3.
|
162 |
|
163 |
== A Request ==
|
164 |
|
201 |
== Future Plans ==
|
202 |
|
203 |
+ add ability to enable/disable loading from Google for specific libraries
|
204 |
+
|
use-google-libraries.php
CHANGED
@@ -2,11 +2,11 @@
|
|
2 |
/*
|
3 |
Plugin Name: Use Google Libraries
|
4 |
Plugin URI: http://jasonpenney.net/wordpress-plugins/use-google-libraries/
|
5 |
-
Description:Allows your site to use common javascript libraries from Google's AJAX Libraries CDN, rather than from Wordpress's own copies.
|
6 |
-
Version: 1.
|
7 |
Author: Jason Penney
|
8 |
Author URI: http://jasonpenney.net/
|
9 |
-
*/
|
10 |
|
11 |
/* Copyright 2008 Jason Penney (email : jpenney@jczorkmid.net )
|
12 |
|
@@ -26,300 +26,295 @@
|
|
26 |
|
27 |
*/
|
28 |
|
29 |
-
if (!class_exists('JCP_UseGoogleLibraries')) {
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
}
|
260 |
-
}
|
261 |
-
|
262 |
-
foreach ($newscripts as $script) {
|
263 |
-
$olddata = $this->WP_Dependency_get_data($scripts, $script->handle);
|
264 |
-
$scripts->remove( $script->handle );
|
265 |
-
// re-register with original ver
|
266 |
-
$scripts->add($script->handle, $script->src, $script->deps, $script->ver);
|
267 |
-
if ($olddata)
|
268 |
-
foreach ($olddata as $data_name => $data) {
|
269 |
-
$scripts->add_data($script->handle,$data_name,$data);
|
270 |
-
}
|
271 |
-
}
|
272 |
-
|
273 |
-
}
|
274 |
-
|
275 |
-
|
276 |
-
function WP_Dependency_get_data( $dep_obj, $handle, $data_name = false) {
|
277 |
-
|
278 |
-
if ( !method_exists($dep_obj,'add_data') )
|
279 |
-
return false;
|
280 |
-
|
281 |
-
if ( !isset($dep_obj->registered[$handle]) )
|
282 |
-
return false;
|
283 |
-
|
284 |
-
if (!$data_name)
|
285 |
-
return $dep_obj->registered[$handle]->extra;
|
286 |
-
|
287 |
-
return $dep_obj->registered[$handle]->extra[$data_name];
|
288 |
-
}
|
289 |
-
|
290 |
-
|
291 |
-
/**
|
292 |
-
* Remove 'ver' from query string for scripts loaded from Google's
|
293 |
-
* CDN
|
294 |
-
*
|
295 |
-
* @param string $src src attribute of script tag
|
296 |
-
* @return string Updated src attribute
|
297 |
-
*/
|
298 |
-
function remove_ver_query ($src) {
|
299 |
-
if ($this->noconflict_next) {
|
300 |
-
$this->noconflict_next = FALSE;
|
301 |
-
echo "<script type='text/javascript'>try{jQuery.noConflict();}catch(e){};</script>\n";
|
302 |
-
}
|
303 |
-
if ( preg_match( '/ajax\.googleapis\.com\//', $src ) ) {
|
304 |
-
$src = remove_query_arg('ver',$src);
|
305 |
-
if (strpos($src,$this->google_scripts['jquery'][1] . ".js")) {
|
306 |
-
$this->noconflict_next = TRUE;
|
307 |
-
}
|
308 |
-
}
|
309 |
-
return $src;
|
310 |
-
}
|
311 |
-
|
312 |
-
static function remove_ver_query_filter ($src) {
|
313 |
-
$ugl = self::get_instance();
|
314 |
-
return $ugl->remove_ver_query($src);
|
315 |
-
}
|
316 |
-
}
|
317 |
}
|
318 |
|
319 |
//instantiate the class
|
320 |
-
if (class_exists('JCP_UseGoogleLibraries')){
|
321 |
-
|
322 |
}
|
323 |
-
|
324 |
-
|
325 |
-
|
2 |
/*
|
3 |
Plugin Name: Use Google Libraries
|
4 |
Plugin URI: http://jasonpenney.net/wordpress-plugins/use-google-libraries/
|
5 |
+
Description:Allows your site to use common javascript libraries from Google's AJAX Libraries CDN, rather than from Wordpress's own copies.
|
6 |
+
Version: 1.2
|
7 |
Author: Jason Penney
|
8 |
Author URI: http://jasonpenney.net/
|
9 |
+
*/
|
10 |
|
11 |
/* Copyright 2008 Jason Penney (email : jpenney@jczorkmid.net )
|
12 |
|
26 |
|
27 |
*/
|
28 |
|
29 |
+
if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
30 |
+
|
31 |
+
if ( ! defined( 'WP_CONTENT_URL' ) )
|
32 |
+
define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
|
33 |
+
if ( ! defined( 'WP_CONTENT_DIR' ) )
|
34 |
+
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
|
35 |
+
if ( ! defined( 'WP_PLUGIN_URL' ) )
|
36 |
+
define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
|
37 |
+
if ( ! defined( 'WP_PLUGIN_DIR' ) )
|
38 |
+
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
|
39 |
+
|
40 |
+
class JCP_UseGoogleLibraries {
|
41 |
+
|
42 |
+
private static $instance;
|
43 |
+
|
44 |
+
public static function get_instance() {
|
45 |
+
if ( !isset( self::$instance ) ) {
|
46 |
+
self::$instance = new JCP_UseGoogleLibraries();
|
47 |
+
}
|
48 |
+
return self::$instance;
|
49 |
+
}
|
50 |
+
|
51 |
+
protected $google_scripts;
|
52 |
+
protected $noconflict_url;
|
53 |
+
protected $noconflict_next;
|
54 |
+
protected $is_ssl;
|
55 |
+
protected static $script_before_init_notice =
|
56 |
+
'<strong>Use Google Libraries</strong>: Another plugin has registered or enqued a script before the "init" action. Attempting to work around it.';
|
57 |
+
|
58 |
+
/**
|
59 |
+
* PHP 4 Compatible Constructor
|
60 |
+
*/
|
61 |
+
function JCP_UseGoogleLibraries() {$this->__construct();}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* PHP 5 Constructor
|
65 |
+
*/
|
66 |
+
function __construct() {
|
67 |
+
$this->google_scripts =
|
68 |
+
array(
|
69 |
+
// any extra scripts listed here not provided by WordPress
|
70 |
+
// or another plugin will not be registered. This liste
|
71 |
+
// is just used to chancge where things load from.
|
72 |
+
|
73 |
+
// 'script-handle' => ( 'google-lib-path', 'google-file-name', 'google-combined-into')
|
74 |
+
/* jQuery */
|
75 |
+
'jquery' => array( 'jquery', 'jquery.min', '' ),
|
76 |
+
|
77 |
+
/* jQuery UI */
|
78 |
+
'jquery-ui-core' => array( 'jqueryui', 'jquery-ui.min', '' ),
|
79 |
+
'jquery-ui-accordion' => array( '', '', 'jquery-ui-core' ),
|
80 |
+
'jquery-ui-autocomplete' => array( '', '', 'jquery-ui-core' ), /* jQueri UI 1.8 */
|
81 |
+
'jquery-ui-button' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
82 |
+
'jquery-ui-datepicker' => array( '', '', 'jquery-ui-core' ),
|
83 |
+
'jquery-ui-dialog' => array( '', '', 'jquery-ui-core' ),
|
84 |
+
'jquery-ui-draggable' => array( '', '', 'jquery-ui-core' ),
|
85 |
+
'jquery-ui-droppable' => array( '', '', 'jquery-ui-core' ),
|
86 |
+
'jquery-ui-menu' => array( '', '', 'jquery-ui-core' ),
|
87 |
+
'jquery-ui-mouse' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
88 |
+
'jquery-ui-position' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
89 |
+
'jquery-ui-progressbar' => array( '', '', 'jquery-ui-core' ),
|
90 |
+
'jquery-ui-resizable' => array( '', '', 'jquery-ui-core' ),
|
91 |
+
'jquery-ui-selectable' => array( '', '', 'jquery-ui-core' ),
|
92 |
+
'jquery-ui-slider' => array( '', '', 'jquery-ui-core' ),
|
93 |
+
'jquery-ui-sortable' => array( '', '', 'jquery-ui-core' ),
|
94 |
+
'jquery-ui-tabs' => array( '', '', 'jquery-ui-core' ),
|
95 |
+
'jquery-ui-widget' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
96 |
+
|
97 |
+
/* jQuery Effects */
|
98 |
+
'jquery-effects-core' => array( '', '', 'jquery-ui-core' ),
|
99 |
+
'jquery-effects-blind' => array( '', '', 'jquery-ui-core' ),
|
100 |
+
'jquery-effects-bounce' => array( '', '', 'jquery-ui-core' ),
|
101 |
+
'jquery-effects-clip' => array( '', '', 'jquery-ui-core' ),
|
102 |
+
'jquery-effects-drop' => array( '', '', 'jquery-ui-core' ),
|
103 |
+
'jquery-effects-explode' => array( '', '', 'jquery-ui-core' ),
|
104 |
+
'jquery-effects-fade' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
|
105 |
+
'jquery-effects-fold' => array( '', '', 'jquery-ui-core' ),
|
106 |
+
'jquery-effects-highlight' => array( '', '', 'jquery-ui-core' ),
|
107 |
+
'jquery-effects-pulsate' => array( '', '', 'jquery-ui-core' ),
|
108 |
+
'jquery-effects-scale' => array( '', '', 'jquery-ui-core' ),
|
109 |
+
'jquery-effects-shake' => array( '', '', 'jquery-ui-core' ),
|
110 |
+
'jquery-effects-slide' => array( '', '', 'jquery-ui-core' ),
|
111 |
+
'jquery-effects-transfer' => array( '', '', 'jquery-ui-core' ),
|
112 |
+
|
113 |
+
/* prototype */
|
114 |
+
'prototype' => array( 'prototype', 'prototype', '' ),
|
115 |
+
|
116 |
+
/* scriptaculous */
|
117 |
+
'scriptaculous-root' => array( 'scriptaculous', 'scriptaculous', '' ),
|
118 |
+
'scriptaculous-builder' => array( '', '', 'scriptaculous-root' ),
|
119 |
+
'scriptaculous-effects' => array( '', '', 'scriptaculous-root' ),
|
120 |
+
'scriptaculous-dragdrop' => array( '', '', 'scriptaculous-root' ),
|
121 |
+
'scriptaculous-controls' => array( '', '', 'scriptaculous-root' ),
|
122 |
+
'scriptaculous-slider' => array( '', '', 'scriptaculous-root' ),
|
123 |
+
'scriptaculous-sound' => array( '', '', 'scriptaculous-root' ),
|
124 |
+
|
125 |
+
/* moo tools */
|
126 |
+
'mootools' => array( 'mootools', 'mootools-yui-compressed', '' ),
|
127 |
+
|
128 |
+
/* Dojo */
|
129 |
+
'dojo' => array( 'dojo', 'dojo.xd', '' ),
|
130 |
+
|
131 |
+
/* swfobject */
|
132 |
+
'swfobject' => array( 'swfobject', 'swfobject', '' ),
|
133 |
+
|
134 |
+
/* YUI */
|
135 |
+
'yui' => array( 'yui', 'build/yuiloader/yuiloader-min', '' ),
|
136 |
+
|
137 |
+
/* Ext Core */
|
138 |
+
'ext-core' => array( 'ext-core', 'ext-core', '' )
|
139 |
+
|
140 |
+
);
|
141 |
+
$this->noconflict_url = WP_PLUGIN_URL . '/use-google-libraries/js/jQnc.js';
|
142 |
+
|
143 |
+
$this->noconflict_next = FALSE;
|
144 |
+
// test for SSL
|
145 |
+
// thanks to suggestions from Peter Wilson (http://peterwilson.cc/)
|
146 |
+
// and Richard Hearne
|
147 |
+
$is_ssl = false;
|
148 |
+
if ( ( function_exists( 'getenv' ) and
|
149 |
+
( ( getenv( 'HTTPS' ) != '' and getenv( 'HTTPS' ) != 'off' )
|
150 |
+
or
|
151 |
+
( getenv( 'SERVER_PORT' ) == '433' ) ) )
|
152 |
+
or
|
153 |
+
( isset( $_SERVER ) and
|
154 |
+
( ( isset( $_SERVER['HTTPS'] ) and $_SERVER['https'] !='' and $_SERVER['HTTPS'] != 'off' )
|
155 |
+
or
|
156 |
+
( isset( $_SERVER['SERVER_PORT'] ) and $_SERVER['SERVER_PORT'] == '443' ) ) ) ) {
|
157 |
+
$is_ssl = true;
|
158 |
+
}
|
159 |
+
$this->is_ssl = $is_ssl;
|
160 |
+
}
|
161 |
+
|
162 |
+
static function configure_plugin() {
|
163 |
+
add_action( 'wp_default_scripts',
|
164 |
+
array( 'JCP_UseGoogleLibraries',
|
165 |
+
'replace_default_scripts_action' ),
|
166 |
+
1000 );
|
167 |
+
add_filter( 'script_loader_src',
|
168 |
+
array( "JCP_UseGoogleLibraries", "remove_ver_query_filter" ),
|
169 |
+
1000 );
|
170 |
+
add_filter( 'init', array( "JCP_UseGoogleLibraries", "setup_filter" ) );
|
171 |
+
|
172 |
+
// There's a chance some plugin has called wp_enqueue_script outside
|
173 |
+
// of any hooks, which means that this plugin's 'wp_default_scripts'
|
174 |
+
// hook will never get a chance to fire. This tries to work around
|
175 |
+
// that.
|
176 |
+
global $wp_scripts;
|
177 |
+
if ( is_a( $wp_scripts, 'WP_Scripts' ) ) {
|
178 |
+
if ( WP_DEBUG !== false ) {
|
179 |
+
error_log( self::$script_before_init_notice );
|
180 |
+
}
|
181 |
+
|
182 |
+
$ugl = self::get_instance();
|
183 |
+
$ugl->replace_default_scripts( $wp_scripts );
|
184 |
+
}
|
185 |
+
}
|
186 |
+
|
187 |
+
|
188 |
+
static function script_before_init_admin_notice() {
|
189 |
+
echo '<div class="error fade"><p>' . self::$script_before_init_notice . '</p></div>';
|
190 |
+
}
|
191 |
+
|
192 |
+
static function setup_filter() {
|
193 |
+
$ugl = self::get_instance();
|
194 |
+
$ugl->setup();
|
195 |
+
}
|
196 |
+
|
197 |
+
/**
|
198 |
+
* Disables script concatination, which breaks when dependencies are not
|
199 |
+
* all loaded locally.
|
200 |
+
*/
|
201 |
+
function setup() {
|
202 |
+
global $concatenate_scripts;
|
203 |
+
$concatenate_scripts = false;
|
204 |
+
|
205 |
+
}
|
206 |
+
|
207 |
+
|
208 |
+
static function replace_default_scripts_action( &$scripts ) {
|
209 |
+
$ugl = self::get_instance();
|
210 |
+
$ugl->replace_default_scripts( $scripts );
|
211 |
+
}
|
212 |
+
|
213 |
+
/**
|
214 |
+
* Replace as many of the wordpress default script registrations as possible
|
215 |
+
* with ones from google
|
216 |
+
*
|
217 |
+
* @param object $scripts WP_Scripts object.
|
218 |
+
*/
|
219 |
+
function replace_default_scripts( &$scripts ) {
|
220 |
+
$newscripts = array();
|
221 |
+
foreach ( $this->google_scripts as $name => $values ) {
|
222 |
+
if ( $script = $scripts->query( $name ) ) {
|
223 |
+
$lib = $values[0];
|
224 |
+
$js = $values[1];
|
225 |
+
$combined = $values[2];
|
226 |
+
|
227 |
+
// default to requested ver
|
228 |
+
$ver = $script->ver;
|
229 |
+
|
230 |
+
// TODO: replace with more flexible option
|
231 |
+
// quick and dirty work around for scriptaculous 1.8.0
|
232 |
+
if ( $name == 'scriptaculous-root' && $ver == '1.8.0' ) {
|
233 |
+
$ver = '1.8';
|
234 |
+
}
|
235 |
+
|
236 |
+
if ( ( $combined !== '' ) && ( ! in_array( $combined, $script->deps ) ) ) {
|
237 |
+
// if this script has been combined into another script
|
238 |
+
// ensure this handle depends on the combined handle
|
239 |
+
$script->deps[] = $combined;
|
240 |
+
}
|
241 |
+
|
242 |
+
// if $lib is empty, then this script does not need to be
|
243 |
+
// exlicitly loaded when using googleapis.com, but we need to keep
|
244 |
+
// it around for dependencies
|
245 |
+
if ( $lib != '' ) {
|
246 |
+
// build new URL
|
247 |
+
$script->src = "http://ajax.googleapis.com/ajax/libs/$lib/$ver/$js.js";
|
248 |
+
|
249 |
+
if ( $this->is_ssl ) {
|
250 |
+
//use ssl
|
251 |
+
$script->src = preg_replace( '/^http:/', 'https:', $script->src );
|
252 |
+
}
|
253 |
+
} else {
|
254 |
+
$script->src = "";
|
255 |
+
}
|
256 |
+
$newscripts[] = $script;
|
257 |
+
}
|
258 |
+
}
|
259 |
+
|
260 |
+
foreach ( $newscripts as $script ) {
|
261 |
+
$olddata = $this->WP_Dependency_get_data( $scripts, $script->handle );
|
262 |
+
$scripts->remove( $script->handle );
|
263 |
+
// re-register with original ver
|
264 |
+
$scripts->add( $script->handle, $script->src, $script->deps, $script->ver );
|
265 |
+
if ( $olddata )
|
266 |
+
foreach ( $olddata as $data_name => $data ) {
|
267 |
+
$scripts->add_data( $script->handle, $data_name, $data );
|
268 |
+
}
|
269 |
+
}
|
270 |
+
|
271 |
+
}
|
272 |
+
|
273 |
+
|
274 |
+
function WP_Dependency_get_data( $dep_obj, $handle, $data_name = false ) {
|
275 |
+
|
276 |
+
if ( !method_exists( $dep_obj, 'add_data' ) )
|
277 |
+
return false;
|
278 |
+
|
279 |
+
if ( !isset( $dep_obj->registered[$handle] ) )
|
280 |
+
return false;
|
281 |
+
|
282 |
+
if ( !$data_name )
|
283 |
+
return $dep_obj->registered[$handle]->extra;
|
284 |
+
|
285 |
+
return $dep_obj->registered[$handle]->extra[$data_name];
|
286 |
+
}
|
287 |
+
|
288 |
+
|
289 |
+
/**
|
290 |
+
* Remove 'ver' from query string for scripts loaded from Google's
|
291 |
+
* CDN
|
292 |
+
*
|
293 |
+
* @param string $src src attribute of script tag
|
294 |
+
* @return string Updated src attribute
|
295 |
+
*/
|
296 |
+
function remove_ver_query( $src ) {
|
297 |
+
if ( $this->noconflict_next ) {
|
298 |
+
$this->noconflict_next = FALSE;
|
299 |
+
echo "<script type='text/javascript'>try{jQuery.noConflict();}catch(e){};</script>\n";
|
300 |
+
}
|
301 |
+
if ( preg_match( '/ajax\.googleapis\.com\//', $src ) ) {
|
302 |
+
$src = remove_query_arg( 'ver', $src );
|
303 |
+
if ( strpos( $src, $this->google_scripts['jquery'][1] . ".js" ) ) {
|
304 |
+
$this->noconflict_next = TRUE;
|
305 |
+
}
|
306 |
+
}
|
307 |
+
return $src;
|
308 |
+
}
|
309 |
+
|
310 |
+
static function remove_ver_query_filter( $src ) {
|
311 |
+
$ugl = self::get_instance();
|
312 |
+
return $ugl->remove_ver_query( $src );
|
313 |
+
}
|
314 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
}
|
316 |
|
317 |
//instantiate the class
|
318 |
+
if ( class_exists( 'JCP_UseGoogleLibraries' ) ) {
|
319 |
+
JCP_UseGoogleLibraries::configure_plugin();
|
320 |
}
|
|
|
|
|
|