Use Google Libraries - Version 1.0.9

Version Description

Download this release

Release Info

Developer jczorkmid
Plugin Icon wp plugin Use Google Libraries
Version 1.0.9
Comparing to
See all releases

Code changes from version 1.0.7.1 to 1.0.9

Files changed (2) hide show
  1. README.txt +9 -3
  2. use-google-libraries.php +98 -54
README.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: jczorkmid
3
  Donate link: http://jasonpenney.net/donate
4
  Tags: javascript, performance, CDN, Google, jQuery, Prototype, MooTools, Dojo, Google AJAX Libraries API
5
- Requires at least: 2.6
6
- Tested up to: 2.9
7
- Stable tag: 1.0.7.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.
@@ -35,6 +35,7 @@ you](http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jque
35
  * [MooTools](http://mootools.net/)
36
  * [Prototype](http://www.prototypejs.org/)
37
  * [script.aculo.us](http://script.aculo.us/)
 
38
 
39
  == Installation ==
40
 
@@ -52,6 +53,11 @@ disappearing.
52
 
53
  == Changelog ==
54
 
 
 
 
 
 
55
  = 1.0.7.1 =
56
 
57
  + fix previous fix (whoops!)
2
  Contributors: jczorkmid
3
  Donate link: http://jasonpenney.net/donate
4
  Tags: javascript, performance, CDN, Google, jQuery, Prototype, MooTools, Dojo, Google AJAX Libraries API
5
+ Requires at least: 2.9.1
6
+ Tested up to: 2.9.1
7
+ Stable tag: 1.0.9
8
 
9
  Allows your site to use common javascript libraries from Google's AJAX
10
  Libraries CDN, rather than from Wordpress's own copies.
35
  * [MooTools](http://mootools.net/)
36
  * [Prototype](http://www.prototypejs.org/)
37
  * [script.aculo.us](http://script.aculo.us/)
38
+ * [swfobject](http://code.google.com/p/swfobject/)
39
 
40
  == Installation ==
41
 
53
 
54
  == Changelog ==
55
 
56
+ = 1.0.8 =
57
+
58
+ + more https detection
59
+ + inline jQuery.noConflict()
60
+
61
  = 1.0.7.1 =
62
 
63
  + fix previous fix (whoops!)
use-google-libraries.php CHANGED
@@ -3,7 +3,7 @@
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.0.7.1
7
  Author: Jason Penney
8
  Author URI: http://jasonpenney.net/
9
  */
@@ -28,7 +28,6 @@
28
 
29
  if (!class_exists('JCP_UseGoogleLibraries')) {
30
 
31
- $google_scripts;
32
 
33
  if ( ! defined( 'WP_CONTENT_URL' ) )
34
  define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
@@ -39,8 +38,21 @@ if (!class_exists('JCP_UseGoogleLibraries')) {
39
  if ( ! defined( 'WP_PLUGIN_DIR' ) )
40
  define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
41
 
42
-
43
  class JCP_UseGoogleLibraries {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  /**
45
  * PHP 4 Compatible Constructor
46
  */
@@ -50,34 +62,67 @@ if (!class_exists('JCP_UseGoogleLibraries')) {
50
  * PHP 5 Constructor
51
  */
52
  function __construct(){
53
- $this->google_scripts = array(
54
- 'jquery' => array( 'jquery','jquery.min'),
55
- 'jquery-ui-core' => array('jqueryui','jquery-ui.min'),
56
- 'jquery-ui-tabs' => array('',''),
57
- 'jquery-ui-sortable' => array('',''),
58
- 'jquery-ui-draggable' => array('',''),
59
- 'jquery-ui-resizable' => array('',''),
60
- 'jquery-ui-dialog' => array('',''),
61
- 'prototype' => array('prototype','prototype'),
62
- 'scriptaculous-root' => array('scriptaculous', 'scriptaculous'),
63
- 'scriptaculous-builder' => array('',''),
64
- 'scriptaculous-effects' => array('',''),
65
- 'scriptaculous-dragdrop' => array('',''),
66
- 'scriptaculous-controls' => array('',''),
67
- 'scriptaculous-slider' => array('',''),
68
- 'scriptaculous-sound' => array('',''),
69
- 'mootools' => array('mootools','mootools-yui-compressed'),
70
- 'dojo' => array('dojo','dojo.xd'),
71
- 'swfobject' => array('swfobject','swfobject'),
72
- 'yui' => array('yui','build/yuiloader/yuiloader-min'),
73
- 'ext-core' => array('ext-core','ext-core')
74
- );
75
- add_action( 'wp_default_scripts', array(&$this,"replace_default_scripts"),1000);
76
- add_filter( 'print_scripts_array',array(&$this,"jquery_noconflict"),1000);
77
- add_filter( 'script_loader_src', array(&$this,"remove_ver_query"),1000);
78
- add_filter( 'init', array(&$this,"setup"));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  }
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  /**
82
  * Disables script concatination, which breaks when dependencies are not
83
  * all loaded locally
@@ -87,6 +132,12 @@ if (!class_exists('JCP_UseGoogleLibraries')) {
87
  $concatenate_scripts = false;
88
  }
89
 
 
 
 
 
 
 
90
  /**
91
  * Replace as many of the wordpress default script registrations as possible
92
  * with ones from google
@@ -115,9 +166,8 @@ if (!class_exists('JCP_UseGoogleLibraries')) {
115
  if ($lib != '') {
116
  // build new URL
117
  $script->src = "http://ajax.googleapis.com/ajax/libs/$lib/$ver/$js.js";
118
- // test for SSL
119
- // thanks to suggestion from Peter Wilson (http://peterwilson.cc/)
120
- if ((isset($_SERVER['HTTPS'])) AND ($_SERVER['HTTPS'] != ”) AND ($_SERVER['HTTPS'] != ‘off’)) {
121
  //use ssl
122
  $script->src = preg_replace('/^http:/', 'https:', $script->src);
123
  }
@@ -138,28 +188,10 @@ if (!class_exists('JCP_UseGoogleLibraries')) {
138
  $scripts->add_data($script->handle,$data_name,$data);
139
  }
140
  }
141
- $scripts->add( 'jquery-noconflict', WP_PLUGIN_URL . '/use-google-libraries/js/jQnc.js', array('jquery-core'));
142
- $jqueryGroup = $this->WP_Dependency_get_data($scripts,'jquery','group');
143
- if ($jqueryGroup) {
144
- $scripts->add_data('jquery-noconflict','group',$jqueryGroup);;
145
- }
146
- }
147
 
148
-
149
- /**
150
- * Ensure jQuery is loaded in noConflict mode
151
- *
152
- * @param array $js_array JavaScript scripts array
153
- * @return array Updated scripts array, if needed
154
- */
155
- function jquery_noconflict( $js_array ) {
156
- if ( false === $jquery = array_search( 'jquery', $js_array ) ) {
157
- return $js_array;
158
- }
159
- array_splice( $js_array, $jquery, 1, array('jquery','jquery-noconflict'));
160
- return $js_array;
161
  }
162
 
 
163
  function WP_Dependency_get_data( $dep_obj, $handle, $data_name = false) {
164
 
165
  if ( !method_exists($dep_obj,'add_data') )
@@ -174,6 +206,7 @@ if (!class_exists('JCP_UseGoogleLibraries')) {
174
  return $dep_obj->registered[$handle]->extra[$data_name];
175
  }
176
 
 
177
  /**
178
  * Remove 'ver' from query string for scripts loaded from Google's
179
  * CDN
@@ -182,16 +215,27 @@ if (!class_exists('JCP_UseGoogleLibraries')) {
182
  * @return string Updated src attribute
183
  */
184
  function remove_ver_query ($src) {
 
 
 
 
185
  if ( preg_match( '/ajax\.googleapis\.com\//', $src ) ) {
186
  $src = remove_query_arg('ver',$src);
187
- }
 
 
 
188
  return $src;
189
  }
190
 
 
 
 
 
191
  }
192
  }
193
 
194
  //instantiate the class
195
- if (class_exists('JCP_UseGoogleLibraries')) {
196
- $JCP_UseGoogleLibraries = new JCP_UseGoogleLibraries();
197
  }
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.0.9
7
  Author: Jason Penney
8
  Author URI: http://jasonpenney.net/
9
  */
28
 
29
  if (!class_exists('JCP_UseGoogleLibraries')) {
30
 
 
31
 
32
  if ( ! defined( 'WP_CONTENT_URL' ) )
33
  define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
38
  if ( ! defined( 'WP_PLUGIN_DIR' ) )
39
  define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
40
 
 
41
  class JCP_UseGoogleLibraries {
42
+
43
+ private static $instance;
44
+
45
+ public static function get_instance() {
46
+ if (!isset(self::$instance)) {
47
+ self::$instance = new JCP_UseGoogleLibraries();
48
+ }
49
+ return self::$instance;
50
+ }
51
+
52
+ protected $google_scripts;
53
+ protected $noconflict_url;
54
+ protected $noconflict_next;
55
+ protected $is_ssl;
56
  /**
57
  * PHP 4 Compatible Constructor
58
  */
62
  * PHP 5 Constructor
63
  */
64
  function __construct(){
65
+ $this->google_scripts =
66
+ array(
67
+ 'jquery' => array( 'jquery','jquery.min'),
68
+ 'jquery-ui-core' => array('jqueryui','jquery-ui.min'),
69
+ 'jquery-ui-tabs' => array('',''),
70
+ 'jquery-ui-sortable' => array('',''),
71
+ 'jquery-ui-draggable' => array('',''),
72
+ 'jquery-ui-resizable' => array('',''),
73
+ 'jquery-ui-dialog' => array('',''),
74
+ 'prototype' => array('prototype','prototype'),
75
+ 'scriptaculous-root' => array('scriptaculous', 'scriptaculous'),
76
+ 'scriptaculous-builder' => array('',''),
77
+ 'scriptaculous-effects' => array('',''),
78
+ 'scriptaculous-dragdrop' => array('',''),
79
+ 'scriptaculous-controls' => array('',''),
80
+ 'scriptaculous-slider' => array('',''),
81
+ 'scriptaculous-sound' => array('',''),
82
+ 'mootools' => array('mootools','mootools-yui-compressed'),
83
+ 'dojo' => array('dojo','dojo.xd'),
84
+ 'swfobject' => array('swfobject','swfobject'),
85
+ 'yui' => array('yui','build/yuiloader/yuiloader-min'),
86
+ 'ext-core' => array('ext-core','ext-core')
87
+ );
88
+ $this->noconflict_url = WP_PLUGIN_URL . '/use-google-libraries/js/jQnc.js';
89
+
90
+ $this->noconflict_next = FALSE;
91
+ // test for SSL
92
+ // thanks to suggestions from Peter Wilson (http://peterwilson.cc/)
93
+ // and Richard Hearne
94
+ $is_ssl = false;
95
+ if ((function_exists('getenv') AND
96
+ ((getenv('HTTPS') != '' AND getenv('HTTPS') != 'off')
97
+ OR
98
+ (getenv('SERVER_PORT') == '433')))
99
+ OR
100
+ (isset($_SERVER) AND
101
+ ((isset($_SERVER['HTTPS']) AND $_SERVER['https'] !='' AND $_SERVER['HTTPS'] != 'off')
102
+ OR
103
+ (isset($_SERVER['SERVER_PORT']) AND $_SERVER['SERVER_PORT'] == '443')))) {
104
+ $is_ssl = true;
105
+ }
106
+ $this->is_ssl = $is_ssl;
107
  }
108
 
109
+ static function configure_plugin() {
110
+ add_action( 'wp_default_scripts',
111
+ 'JCP_UseGoogleLibraries::replace_default_scripts_action',
112
+ 1000);
113
+ add_filter( 'script_loader_src',
114
+ "JCP_UseGoogleLibraries::remove_ver_query_filter",1000);
115
+ add_filter( 'init',"JCP_UseGoogleLibraries::setup_filter");
116
+
117
+ }
118
+
119
+
120
+ static function setup_filter() {
121
+ $ugl = self::get_instance();
122
+ $ugl->setup();
123
+ }
124
+
125
+
126
  /**
127
  * Disables script concatination, which breaks when dependencies are not
128
  * all loaded locally
132
  $concatenate_scripts = false;
133
  }
134
 
135
+
136
+ static function replace_default_scripts_action( &$scripts ) {
137
+ $ugl = self::get_instance();
138
+ $ugl->replace_default_scripts( $scripts );
139
+ }
140
+
141
  /**
142
  * Replace as many of the wordpress default script registrations as possible
143
  * with ones from google
166
  if ($lib != '') {
167
  // build new URL
168
  $script->src = "http://ajax.googleapis.com/ajax/libs/$lib/$ver/$js.js";
169
+
170
+ if ($this->is_ssl) {
 
171
  //use ssl
172
  $script->src = preg_replace('/^http:/', 'https:', $script->src);
173
  }
188
  $scripts->add_data($script->handle,$data_name,$data);
189
  }
190
  }
 
 
 
 
 
 
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  }
193
 
194
+
195
  function WP_Dependency_get_data( $dep_obj, $handle, $data_name = false) {
196
 
197
  if ( !method_exists($dep_obj,'add_data') )
206
  return $dep_obj->registered[$handle]->extra[$data_name];
207
  }
208
 
209
+
210
  /**
211
  * Remove 'ver' from query string for scripts loaded from Google's
212
  * CDN
215
  * @return string Updated src attribute
216
  */
217
  function remove_ver_query ($src) {
218
+ if ($this->noconflict_next) {
219
+ $this->noconflict_next = FALSE;
220
+ echo "<script type='text/javascript'>try{jQuery.noConflict();}catch(e){};</script>\n";
221
+ }
222
  if ( preg_match( '/ajax\.googleapis\.com\//', $src ) ) {
223
  $src = remove_query_arg('ver',$src);
224
+ if (strpos($src,$this->google_scripts['jquery'][1] . ".js")) {
225
+ $this->noconflict_next = TRUE;
226
+ }
227
+ }
228
  return $src;
229
  }
230
 
231
+ static function remove_ver_query_filter ($src) {
232
+ $ugl = self::get_instance();
233
+ return $ugl->remove_ver_query($src);
234
+ }
235
  }
236
  }
237
 
238
  //instantiate the class
239
+ if (class_exists('JCP_UseGoogleLibraries')){
240
+ JCP_UseGoogleLibraries::configure_plugin();
241
  }