Use Google Libraries - Version 1.6.1

Version Description

  • same as 1.6 (due to SVN issue with 1.6)
Download this release

Release Info

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

Code changes from version 1.6 to 1.6.1

.gitattributes ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ # Standards for multi-platform colaboration
2
+
3
+ # Set default behaviour, in case users don't have core.autocrlf set.
4
+ * text=auto
.gitignore ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # folders and files to be ignored by git
2
+
3
+ #################
4
+ ## Eclipse
5
+ #################
6
+
7
+ *.pydevproject
8
+ .project
9
+ .metadata
10
+ tmp/
11
+ *.tmp
12
+ *.bak
13
+ *.swp
14
+ *~.nib
15
+ local.properties
16
+ .classpath
17
+ .settings/
18
+ .loadpath
19
+
20
+ # External tool builders
21
+ .externalToolBuilders/
22
+
23
+ # Locally stored "Eclipse launch configurations"
24
+ *.launch
25
+
26
+ # CDT-specific
27
+ .cproject
28
+
29
+ # PDT-specific
30
+ .buildpath
31
+
32
+ ############
33
+ ## Windows
34
+ ############
35
+
36
+ # Windows image file caches
37
+ Thumbs.db
38
+
39
+ # Folder config file
40
+ Desktop.ini
41
+
42
+ #################
43
+ ## Misc
44
+ #################
45
+
46
+ # Netbeans project meta data
47
+ nbproject/
48
+
49
+ # SVN
50
+ .svn
51
+
52
+ # phptidy
53
+ .phptidy-cache
54
+ *.phptidybak
55
+ *.phptidybak~
.scrutinizer.yml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ filter:
2
+ excluded_paths:
3
+ - 'tests/*'
4
+ - 'bin/*'
5
+
6
+ tools:
7
+ php_code_sniffer:
8
+ config:
9
+ standard: WordPress
10
+
11
+ php_cpd: true
12
+
13
+ php_mess_detector:
14
+ config:
15
+ code_size_rules: { cyclomatic_complexity: true }
16
+ unused_code_rules: { unused_local_variable: true, unused_private_method: true, unused_formal_parameter: true }
17
+
18
+ php_pdepend: true
19
+
20
+ php_analyzer: true
21
+
22
+ sensiolabs_security_checker: true
23
+
24
+ external_code_coverage:
25
+ timeout: 1200
.travis.yml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ language: php
2
+
3
+ php:
4
+ - 5.3
5
+ - 5.4
6
+ - 5.5
7
+
8
+ env:
9
+ - WP_VERSION=latest WP_MULTISITE=0
10
+ - WP_VERSION=latest WP_MULTISITE=1
11
+ - WP_VERSION=4.0 WP_MULTISITE=0
12
+ - WP_VERSION=4.0 WP_MULTISITE=1
13
+
14
+ before_script:
15
+ - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
16
+ - mkdir -p build/logs
17
+
18
+ script:
19
+ - phpunit
20
+
21
+ after_script:
22
+ - wget https://scrutinizer-ci.com/ocular.phar
23
+ - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
24
+
README.md ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Google Libraries
2
+ __Allows your site to use common javascript libraries from Google's AJAX Libraries CDN, rather than from WordPress's own copies.__
3
+
4
+ ## For More Information ##
5
+ See the [README.txt][1.0] file, or one of the links below:
6
+
7
+ - [Homepage][1.1]
8
+ - [WordPress.org Plugin Page][1.2]
9
+ - [GitHub-Repository][1.3]
10
+ - Support
11
+ - [Issue Tracker][1.4.1]
12
+ - [Forum][1.4.2]
13
+ - Releases
14
+ - __[1.5.2][1.5]__ [![Build Status](https://travis-ci.org/jpenney/use-google-libraries.png?branch=master)](https://travis-ci.org/jpenney/use-google-libraries)
15
+ - __[dev][1.6]__ [![Build Status](https://travis-ci.org/jpenney/use-google-libraries.png?branch=develop)](https://travis-ci.org/jpenney/use-google-libraries)
16
+
17
+
18
+ [1.0]: ./README.txt
19
+ [1.1]: http://jasonpenney.net/wordpress-plugins/use-google-libraries/
20
+ [1.2]: http://wordpress.org/plugins/use-google-libraries/
21
+ [1.3]: https://github.com/jpenney/use-google-libraries
22
+ [1.4.1]: https://github.com/jpenney/use-google-libraries/issues
23
+ [1.4.2]: http://wordpress.org/support/plugin/use-google-libraries
24
+ [1.5]: http://downloads.wordpress.org/plugin/use-google-libraries.1.5.2.zip
25
+ [1.6]: https://github.com/jpenney/use-google-libraries/archive/develop.zip
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, YSlow, Page Speed
5
- Requires at least: 2.9.1
6
- Tested up to: 3.6b3
7
- Stable tag: 1.5.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.
@@ -37,6 +37,13 @@ you](http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jque
37
  * [script.aculo.us](http://script.aculo.us/)
38
  * [swfobject](http://code.google.com/p/swfobject/)
39
 
 
 
 
 
 
 
 
40
  == Installation ==
41
 
42
  # Upload the `use-google-libraries` folder to the `/wp-content/plugins/` folder.
@@ -92,6 +99,23 @@ point.
92
 
93
  == Incompatible Plugins ==
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
  == Incompatible Themes ==
97
 
@@ -102,6 +126,15 @@ using K2.
102
 
103
  == Changelog ==
104
 
 
 
 
 
 
 
 
 
 
105
  = 1.5.2 =
106
 
107
  + using protocol-relative URLS with WordPress >= 3.5
@@ -204,8 +237,8 @@ from [Peter Wilson](http://peterwilson.cc/).
204
 
205
  == Upgrade Notice ==
206
 
207
- = 1.5.2 =
208
- Better SSL support. Required for WordPress 3.6!
209
 
210
  == A Request ==
211
 
@@ -247,5 +280,6 @@ which has very similar goals to this plugin.
247
 
248
  == Future Plans ==
249
 
250
- + add ability to enable/disable loading from Google for specific libraries
 
251
 
2
  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: 3.4
6
+ Tested up to: 4.0
7
+ Stable tag: 1.6.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.
37
  * [script.aculo.us](http://script.aculo.us/)
38
  * [swfobject](http://code.google.com/p/swfobject/)
39
 
40
+ = Links =
41
+
42
+ * [Use Google Libraries Home](http://jasonpenney.net/wordpress-plugins/use-google-libraries/)
43
+ * [Issue Tracker](http://github.com/jpenney/use-google-libraries/issues)
44
+ * [GitHub Repository](http://github.com/jpenney/use-google-libraries)
45
+ * [Support Forum](http://wordpress.org/support/plugin/use-google-libraries)
46
+
47
  == Installation ==
48
 
49
  # Upload the `use-google-libraries` folder to the `/wp-content/plugins/` folder.
99
 
100
  == Incompatible Plugins ==
101
 
102
+ = Better WordPress Minify =
103
+
104
+ Better WordPress Minify version 1.2.2 does not yet support
105
+ protocol-relative URLs, but [the next release is supposed to correct
106
+ this](http://wordpress.org/support/topic/conflict-with-use-google-libraries-152).
107
+
108
+ = Gravity Forms =
109
+
110
+ I've had reports of Gravity Forms breaking UGL, but I don't have
111
+ access to Gravity Forms, so I'm not sure what's going on. If you need
112
+ Gravity Forms you might need to disable UGL, or it might be fine, I'm
113
+ not really sure.
114
+
115
+ = WP-Minify =
116
+
117
+ WP-Minify doesn't yet support protocol-relative URLs. Add
118
+ '//ajax.googleapis.com/' as a JS and CSS exclusion.
119
 
120
  == Incompatible Themes ==
121
 
126
 
127
  == Changelog ==
128
 
129
+ = 1.6.1 =
130
+
131
+ + same as 1.6 (due to SVN issue with 1.6)
132
+
133
+ = 1.6 =
134
+
135
+ + Drop support for PHP4, and WordPress < 3.4
136
+ + clean up PHP 5.x strict issues
137
+
138
  = 1.5.2 =
139
 
140
  + using protocol-relative URLS with WordPress >= 3.5
237
 
238
  == Upgrade Notice ==
239
 
240
+ = 1.6.1 =
241
+ Fixes numerous issues. Recommended upgrade.
242
 
243
  == A Request ==
244
 
280
 
281
  == Future Plans ==
282
 
283
+ + add ability to disable protocol relative URLs
284
+ + add ability to disable on frontend and/or admin
285
 
bin/install-wp-tests.sh ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+
3
+ if [ $# -lt 3 ]; then
4
+ echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
5
+ exit 1
6
+ fi
7
+
8
+ DB_NAME=$1
9
+ DB_USER=$2
10
+ DB_PASS=$3
11
+ DB_HOST=${4-localhost}
12
+ WP_VERSION=${5-latest}
13
+
14
+ WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
15
+ WP_CORE_DIR=/tmp/wordpress/
16
+
17
+ set -ex
18
+
19
+ install_wp() {
20
+ mkdir -p $WP_CORE_DIR
21
+
22
+ if [ $WP_VERSION == 'latest' ]; then
23
+ local ARCHIVE_NAME='latest'
24
+ else
25
+ local ARCHIVE_NAME="wordpress-$WP_VERSION"
26
+ fi
27
+
28
+ wget -nv -O /tmp/wordpress.tar.gz http://wordpress.org/${ARCHIVE_NAME}.tar.gz
29
+ tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
30
+
31
+ wget -nv -O $WP_CORE_DIR/wp-content/db.php https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
32
+ }
33
+
34
+ install_test_suite() {
35
+ # portable in-place argument for both GNU sed and Mac OSX sed
36
+ if [[ $(uname -s) == 'Darwin' ]]; then
37
+ local ioption='-i .bak'
38
+ else
39
+ local ioption='-i'
40
+ fi
41
+
42
+ # set up testing suite
43
+ mkdir -p $WP_TESTS_DIR
44
+ cd $WP_TESTS_DIR
45
+ svn co --quiet http://develop.svn.wordpress.org/trunk/tests/phpunit/includes/
46
+
47
+ wget -nv -O wp-tests-config.php http://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php
48
+ sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" wp-tests-config.php
49
+ sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" wp-tests-config.php
50
+ sed $ioption "s/yourusernamehere/$DB_USER/" wp-tests-config.php
51
+ sed $ioption "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php
52
+ sed $ioption "s|localhost|${DB_HOST}|" wp-tests-config.php
53
+ }
54
+
55
+ install_db() {
56
+ # parse DB_HOST for port or socket references
57
+ local PARTS=(${DB_HOST//\:/ })
58
+ local DB_HOSTNAME=${PARTS[0]};
59
+ local DB_SOCK_OR_PORT=${PARTS[1]};
60
+ local EXTRA=""
61
+
62
+ if ! [ -z $DB_HOSTNAME ] ; then
63
+ if [[ "$DB_SOCK_OR_PORT" =~ ^[0-9]+$ ]] ; then
64
+ EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
65
+ elif ! [ -z $DB_SOCK_OR_PORT ] ; then
66
+ EXTRA=" --socket=$DB_SOCK_OR_PORT"
67
+ elif ! [ -z $DB_HOSTNAME ] ; then
68
+ EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
69
+ fi
70
+ fi
71
+
72
+ # create database
73
+ mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
74
+ }
75
+
76
+ install_wp
77
+ install_test_suite
78
+ install_db
phpunit.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <phpunit
2
+ bootstrap="tests/bootstrap.php"
3
+ strict="true"
4
+ backupGlobals="false"
5
+ colors="true"
6
+ convertErrorsToExceptions="true"
7
+ convertNoticesToExceptions="true"
8
+ convertWarningsToExceptions="true"
9
+ >
10
+
11
+ <testsuites>
12
+ <testsuite>
13
+ <directory prefix="test_" suffix=".php">./tests/</directory>
14
+ </testsuite>
15
+ </testsuites>
16
+
17
+ <logging>
18
+ <log type="coverage-clover" target="build/logs/clover.xml"/>
19
+ </logging>
20
+ </phpunit>
tests/bootstrap.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $_tests_dir = getenv( 'WP_TESTS_DIR' );
4
+ if ( ! $_tests_dir ) $_tests_dir = '/tmp/wordpress-tests-lib';
5
+
6
+ require_once $_tests_dir . '/includes/functions.php';
7
+
8
+ function _manually_load_plugin() {
9
+ require dirname( __FILE__ ) . '/../use-google-libraries.php';
10
+ }
11
+ tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
12
+
13
+ require $_tests_dir . '/includes/bootstrap.php';
14
+
15
+ require_once dirname( __FILE__ ) . '/includes/classes.php';
tests/includes/classes.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( class_exists( 'JCP_UseGoogleLibraries' ) ) {
4
+ class JCP_UseGoogleLibraries_Test extends JCP_UseGoogleLibraries {
5
+ public static function get_instance() {
6
+ if ( ! isset( self::$instance ) || ! is_a( self::$instance, 'JCP_UseGoogleLibraries_Test' ) ) {
7
+ self::$instance = new JCP_UseGoogleLibraries_Test();
8
+ }
9
+ return self::$instance;
10
+ }
11
+
12
+ public function get_protocol_relative_supported() {
13
+ return $this->protocol_relative_supported;
14
+ }
15
+
16
+ public function get_google_scripts() {
17
+ return $this->google_scripts;
18
+ }
19
+
20
+ public function get_version() {
21
+ return self::$version;
22
+ }
23
+
24
+ public function get_plugin_file() {
25
+ return self::$plugin_file;
26
+ }
27
+
28
+ public function get_jquery_tag() {
29
+ return $this->jquery_tag;
30
+ }
31
+
32
+ public function newscripts_fix_jquery_core( &$scripts ) {
33
+ parent::newscripts_fix_jquery_core( $scripts );
34
+ }
35
+
36
+ public function newscripts_build_url( $name, $lib, $ver, $js, $orig_url ) {
37
+ return parent::newscripts_build_url(
38
+ $name, $lib, $ver, $js, $orig_url
39
+ );
40
+ }
41
+
42
+ public function get_noconflict_next( ) {
43
+ return $this->noconflict_next;
44
+ }
45
+
46
+ public function get_noconflict_inject() {
47
+ return self::$noconflict_inject;
48
+ }
49
+
50
+ public function set_noconflict_next( $value ) {
51
+ $this->noconflict_next = $value;
52
+ }
53
+ }
54
+ }
55
+
56
+ class UGL_UnitTestCase extends WP_UnitTestCase {
57
+
58
+ function setUp() {
59
+ parent::setUp();
60
+ $this->ugl = null;
61
+ if ( class_exists( 'JCP_UseGoogleLibraries' ) ) {
62
+ $this->ugl = JCP_UseGoogleLibraries_Test::get_instance();
63
+ } else {
64
+ $this->markTestSkipped( 'Use Google Libraries not loaded' );
65
+ }
66
+ }
67
+
68
+ }
69
+
70
+ class UGL_ScriptTestCase extends UGL_UnitTestCase {
71
+
72
+ function setUp() {
73
+ parent::setUp();
74
+ $scripts = new WP_Scripts();
75
+ wp_default_scripts( $scripts );
76
+ $this->scripts = $scripts;
77
+ }
78
+ }
tests/test_ugl_basic.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * @medium
6
+ *
7
+ */
8
+ class UGL_BasicTests extends UGL_UnitTestCase {
9
+
10
+ function test_ugl() {
11
+ $this->assertInstanceOf( 'JCP_UseGoogleLibraries', $this->ugl );
12
+ $props = array(
13
+ 'google_scripts', 'noconflict_next',
14
+ 'protocol_relative_supported', 'jquery_tag',
15
+ );
16
+
17
+ foreach ( $props as $prop ) {
18
+ $this->assertObjectHasAttribute( $prop, $this->ugl );
19
+ }
20
+ }
21
+
22
+ function test_ugl_version() {
23
+ $plugin_data = get_plugin_data( $this->ugl->get_plugin_file() );
24
+
25
+ $this->assertEquals(
26
+ $this->ugl->get_version(),
27
+ $plugin_data['Version'],
28
+ 'class version should match header version' );
29
+ }
30
+
31
+ function test_ugl_remove_ver_query() {
32
+ $dummy_src = '//ajax.googleapis.com/dummy.js';
33
+ $dummy_script = add_query_arg( 'ver', '1.2.3', $dummy_src );
34
+ $this->assertNotEquals( $dummy_src, $dummy_script );
35
+ $this->assertEquals(
36
+ $dummy_src, $this->ugl->remove_ver_query( $dummy_script ),
37
+ 'ver should be removed from url if from google libs'
38
+ );
39
+ }
40
+
41
+ function test_ugl_remove_ver_query_negative() {
42
+ $dummy_src = 'dummy.js';
43
+ $dummy_script = add_query_arg( 'ver', '1.2.3', $dummy_src );
44
+ $this->assertNotEquals( $dummy_src, $dummy_script );
45
+ $this->assertEquals(
46
+ $dummy_script, $this->ugl->remove_ver_query( $dummy_script ),
47
+ 'ver should not be removed unless url is from google libs'
48
+ );
49
+ }
50
+
51
+ function test_concatenate_scripts_disabled() {
52
+ global $concatenate_scripts;
53
+ $this->assertFalse( $concatenate_scripts );
54
+ }
55
+
56
+ }
tests/test_ugl_scripts.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @medium
5
+ *
6
+ */
7
+ class UGL_ScriptTests extends UGL_ScriptTestCase {
8
+
9
+ function test_protocol_relative_url() {
10
+ $jquery_tag = $this->ugl->get_jquery_tag();
11
+ $jquery = $this->scripts->query( $jquery_tag );
12
+ $prefix = '//';
13
+ if ( ! $this->ugl->get_protocol_relative_supported() ) {
14
+ if ( is_ssl() ) {
15
+ $prefix = 'https://';
16
+ } else {
17
+ $prefix = 'http://';
18
+ }
19
+ }
20
+ $this->assertStringStartsWith( $prefix, $jquery->src );
21
+ }
22
+
23
+ function test_scripts_replaced() {
24
+ $scripts = $this->ugl->get_google_scripts();
25
+ foreach ( array_keys( $scripts ) as $handle ) {
26
+ if ( $script = $this->scripts->query( $handle ) ) {
27
+ if ( $script->src && strpos( $script->ver, '-' ) === false ) {
28
+ $this->assertContains(
29
+ '//ajax.googleapis.com/ajax/libs',
30
+ $script->src, $handle + ' should be loading from google'
31
+ );
32
+ }
33
+ }
34
+ }
35
+ }
36
+
37
+ function test_nonstandard_ver_not_replaced() {
38
+ $scripts = $this->ugl->get_google_scripts();
39
+ foreach ( array_keys( $scripts ) as $handle ) {
40
+ if ( $script = $this->scripts->query( $handle ) ) {
41
+ if ( $script->src && strpos( $script->ver, '-' ) !== false ) {
42
+ $this->assertNotContains(
43
+ '//ajax.googleapis.com/ajax/libs',
44
+ $script->src, $handle + ' should not be loading from google'
45
+ );
46
+ }
47
+ }
48
+ }
49
+ }
50
+
51
+ function test_scriptaculous_1_8_0() {
52
+ $scriptaculous = $this->scripts->query( 'scriptaculous-root' );
53
+ if ( !$scriptaculous || $scriptaculous->ver !== '1.8.0' ||
54
+ strpos( $scriptaculous->src, '//ajax.googleapis.com/ajax/libs' ) === false ) {
55
+ $this->markTestSkipped( 'does not apply, not replacing scriptaculous version 1.8.0' );
56
+ }
57
+ $this->assertContains( '1.8', $scriptaculous->src );
58
+ $this->assertNotContains( '1.8.0', $scriptaculous->src );
59
+ }
60
+
61
+
62
+ function test_noconfict_next_set() {
63
+ $jquery = $this->scripts->query( $this->ugl->get_jquery_tag() );
64
+ $src = $jquery->src;
65
+ if ( strpos( $src, '//ajax.googleapis.com/ajax/libs' ) === false ) {
66
+ $this->markTestSkipped( 'jQuery not replaced, noconflict_next unused' );
67
+ }
68
+
69
+ $this->ugl->set_noconflict_next( false );
70
+
71
+ $this->ugl->remove_ver_query( $src );
72
+
73
+ $this->assertTrue(
74
+ $this->ugl->get_noconflict_next(),
75
+ 'noconflict_next should be set after remove_ver_query is run for jquery'
76
+ );
77
+ }
78
+
79
+ function test_noconflict_injected() {
80
+
81
+ $this->ugl->set_noconflict_next( true );
82
+ $this->expectOutputString( $this->ugl->get_noconflict_inject() );
83
+ $this->ugl->remove_ver_query( 'http://example.com/' );
84
+
85
+ $this->assertFalse(
86
+ $this->ugl->get_noconflict_next(),
87
+ 'noconflict_next should be cleared after remove_ver_query runs'
88
+ );
89
+ }
90
+ }
tests/test_wordpress_plugin_tests.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Tests to test that that testing framework is testing tests. Meta, huh?
4
+ *
5
+ * @package wordpress-plugins-tests
6
+ */
7
+ class WP_Test_WordPress_Plugin_Tests extends WP_UnitTestCase {
8
+
9
+ /**
10
+ * Run a simple test to ensure that the tests are running
11
+ */
12
+ function test_tests() {
13
+
14
+ $this->assertTrue( true );
15
+
16
+ }
17
+
18
+ /**
19
+ * Verify that WordPress is installed and is the version that we requested
20
+ */
21
+ function test_wp_version() {
22
+
23
+ if ( ! getenv( 'TRAVIS_PHP_VERSION' ) ) {
24
+ $this->markTestSkipped( 'Not running on Travis CI' );
25
+ }
26
+
27
+ //grab the requested version
28
+ $requested_version = getenv( 'WP_VERSION' );
29
+
30
+ if ( $requested_version == 'latest' ) {
31
+ $this->markTestSkipped( "Can't verify version on 'latest'" );
32
+ }
33
+
34
+ //trunk is always "master" in github terms, but WordPress has a specific way of describing it
35
+ //grab the exact version number to verify that we're on trunk
36
+ if ( $requested_version == 'master' ) {
37
+ // check that we have the https wrapper
38
+ if ( ! in_array( 'https', stream_get_wrappers() ) )
39
+ $this->markTestSkipped( 'https wrapper unavailable' );
40
+
41
+ $file = file_get_contents( 'https://raw.github.com/WordPress/WordPress/master/wp-includes/version.php' );
42
+ preg_match( '#\$wp_version = \'([^\']+)\';#', $file, $matches );
43
+ $requested_version = $matches[1];
44
+ }
45
+
46
+ $this->assertEquals( get_bloginfo( 'version' ), $requested_version );
47
+
48
+ }
49
+
50
+ }
use-google-libraries.php CHANGED
@@ -3,9 +3,11 @@
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.5.2
7
  Author: Jason Penney
8
  Author URI: http://jasonpenney.net/
 
 
9
  */
10
 
11
  /* Copyright 2008-2013 Jason Penney (email : jpenney@jczorkmid.net )
@@ -26,47 +28,50 @@
26
 
27
  */
28
 
29
- if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
30
 
31
  class JCP_UseGoogleLibraries {
32
 
33
- private static $instance;
34
- private static $version = '1.5.2';
 
 
 
35
  public static function get_instance() {
36
- if ( !isset( self::$instance ) ) {
37
- self::$instance = new JCP_UseGoogleLibraries();
38
  }
39
  return self::$instance;
40
  }
41
-
42
  /**
43
  * Registry of script replacement rules
44
- *
45
  * Entries are formatted as follows:
46
  * <code>
47
- * 'script-handle' => array(
48
- * 'google-lib-path',
49
- * 'google-file-name',
50
  * 'google-combined-into')
51
  * </code>
52
  *
53
- * - 'script-handle' -- the handle used by WordPress script
54
  * registration
55
  * - 'google-lib-path' -- path to location on Google CDN( empty
56
  * string if script has been combined).
57
  * - 'google-file-name' -- file name (minus .js) on Google CDN (empty
58
  * string if script has been combined).
59
- * - 'google-combined-into' -- If not empty string, then the given
60
  * handle has been combined into a file loaded by this handle.
61
- *
62
  * @var array
63
  */
64
  protected $google_scripts;
65
-
66
  /**
67
  * Used internally to ensure jQuery.noconflict is executed as close to
68
  * how core WordPress would.
69
- *
70
  * @var bool
71
  */
72
  protected $noconflict_next;
@@ -79,143 +84,165 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
79
  * @since 5.2
80
  */
81
  protected $jquery_tag;
82
-
83
  /**
84
- * True if using a version of WordPress that allows
85
- * `wp_register_script` to take protocol-relative URLs, otherwise False
86
- *
 
87
  * @since 1.5.2
88
- *
89
  * @var bool
90
  */
91
  protected $protocol_relative_supported;
92
-
93
  /**
94
  * transient name used when caching
95
- *
96
  * @var string
97
  */
98
  protected static $cache_id = 'JCP_UseGoogleLibraries_cache';
99
-
100
  /**
101
  * transient expiration
102
- *
103
  * @var int
104
  */
105
  protected static $cache_len = 90000; // 25 hours
106
-
107
  /**
108
- * Message displayed and logged when a WP_Scripts has been created before it's time
109
- *
110
- * @var unknown_type
 
111
  */
112
  protected static $script_before_init_notice =
113
  'Another plugin has registered or enqued a script before the "init" action. Attempting to work around it.';
114
-
115
  /**
116
- * PHP 4 Compatible Constructor
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  */
118
- function JCP_UseGoogleLibraries() {$this->__construct();}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
  /**
121
  * PHP 5 Constructor
122
  */
123
  function __construct() {
124
- $this->jquery_tag = 'jquery';
125
- $this->google_scripts =
126
- array(
127
- // any extra scripts listed here not provided by WordPress
128
- // or another plugin will not be registered. This list
129
- // is just used to chancge where things load from.
130
-
131
- // 'script-handle' => ( 'google-lib-path', 'google-file-name', 'google-combined-into')
132
- /* jQuery */
133
- 'jquery' => array( 'jquery', 'jquery.min', '' ),
134
-
135
- /* jQuery UI */
136
- 'jquery-ui-core' => array( 'jqueryui', 'jquery-ui.min', '' ),
137
- 'jquery-ui-accordion' => array( '', '', 'jquery-ui-core' ),
138
- 'jquery-ui-autocomplete' => array( '', '', 'jquery-ui-core' ), /* jQueri UI 1.8 */
139
- 'jquery-ui-button' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
140
- 'jquery-ui-datepicker' => array( '', '', 'jquery-ui-core' ),
141
- 'jquery-ui-dialog' => array( '', '', 'jquery-ui-core' ),
142
- 'jquery-ui-draggable' => array( '', '', 'jquery-ui-core' ),
143
- 'jquery-ui-droppable' => array( '', '', 'jquery-ui-core' ),
144
- 'jquery-ui-menu' => array( '', '', 'jquery-ui-core' ),
145
- 'jquery-ui-mouse' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
146
- 'jquery-ui-position' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
147
- 'jquery-ui-progressbar' => array( '', '', 'jquery-ui-core' ),
148
- 'jquery-ui-resizable' => array( '', '', 'jquery-ui-core' ),
149
- 'jquery-ui-selectable' => array( '', '', 'jquery-ui-core' ),
150
- 'jquery-ui-slider' => array( '', '', 'jquery-ui-core' ),
151
- 'jquery-ui-sortable' => array( '', '', 'jquery-ui-core' ),
152
- 'jquery-ui-tabs' => array( '', '', 'jquery-ui-core' ),
153
- 'jquery-ui-widget' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
154
-
155
- /* jQuery Effects */
156
- 'jquery-effects-core' => array( '', '', 'jquery-ui-core' ),
157
- 'jquery-effects-blind' => array( '', '', 'jquery-ui-core' ),
158
- 'jquery-effects-bounce' => array( '', '', 'jquery-ui-core' ),
159
- 'jquery-effects-clip' => array( '', '', 'jquery-ui-core' ),
160
- 'jquery-effects-drop' => array( '', '', 'jquery-ui-core' ),
161
- 'jquery-effects-explode' => array( '', '', 'jquery-ui-core' ),
162
- 'jquery-effects-fade' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
163
- 'jquery-effects-fold' => array( '', '', 'jquery-ui-core' ),
164
- 'jquery-effects-highlight' => array( '', '', 'jquery-ui-core' ),
165
- 'jquery-effects-pulsate' => array( '', '', 'jquery-ui-core' ),
166
- 'jquery-effects-scale' => array( '', '', 'jquery-ui-core' ),
167
- 'jquery-effects-shake' => array( '', '', 'jquery-ui-core' ),
168
- 'jquery-effects-slide' => array( '', '', 'jquery-ui-core' ),
169
- 'jquery-effects-transfer' => array( '', '', 'jquery-ui-core' ),
170
-
171
- /* prototype */
172
- 'prototype' => array( 'prototype', 'prototype', '' ),
173
-
174
- /* scriptaculous */
175
- 'scriptaculous-root' => array( 'scriptaculous', 'scriptaculous', '' ),
176
- 'scriptaculous-builder' => array( '', '', 'scriptaculous-root' ),
177
- 'scriptaculous-effects' => array( '', '', 'scriptaculous-root' ),
178
- 'scriptaculous-dragdrop' => array( '', '', 'scriptaculous-root' ),
179
- 'scriptaculous-controls' => array( '', '', 'scriptaculous-root' ),
180
- 'scriptaculous-slider' => array( '', '', 'scriptaculous-root' ),
181
- 'scriptaculous-sound' => array( '', '', 'scriptaculous-root' ),
182
-
183
- /* moo tools */
184
- 'mootools' => array( 'mootools', 'mootools-yui-compressed', '' ),
185
-
186
- /* Dojo */
187
- 'dojo' => array( 'dojo', 'dojo.xd', '' ),
188
-
189
- /* swfobject */
190
- 'swfobject' => array( 'swfobject', 'swfobject', '' ),
191
-
192
- /* YUI */
193
- 'yui' => array( 'yui', 'build/yuiloader/yuiloader-min', '' ),
194
-
195
- /* Ext Core */
196
- 'ext-core' => array( 'ext-core', 'ext-core', '' )
197
 
198
- );
199
- $this->noconflict_next = FALSE;
200
- // protocol-relative URLS accepted by `wp_register_scripts`
201
  // starting with version 3.5
202
- $this->protocol_relative_supported = version_compare( get_bloginfo( 'version' ), '3.5', '>=' );
 
 
203
  }
204
 
205
  static function configure_plugin() {
206
- add_action( 'wp_default_scripts',
207
- array( 'JCP_UseGoogleLibraries',
208
- 'replace_default_scripts_action' ),
209
- 1000 );
210
- add_filter( 'script_loader_src',
211
- array( "JCP_UseGoogleLibraries", "remove_ver_query_filter" ),
212
- 1000 );
213
- add_filter( 'init', array( "JCP_UseGoogleLibraries", "setup_filter" ) );
214
-
215
- // There's a chance some plugin has called wp_enqueue_script outside
216
- // of any hooks, which means that this plugin's 'wp_default_scripts'
217
- // hook will never get a chance to fire. This tries to work around
218
- // that.
 
 
 
 
 
 
 
 
 
219
  global $wp_scripts;
220
  if ( is_a( $wp_scripts, 'WP_Scripts' ) ) {
221
  self::debug( self::$script_before_init_notice );
@@ -225,11 +252,14 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
225
  }
226
 
227
  /**
228
- * Get markup to show error message in admin when $WP_Script created befor it's time
229
- * @returns string markup for notice display
 
 
230
  */
231
  static function script_before_init_admin_notice() {
232
- echo '<div class="error fade"><p>Use Google Libraries: ' . self::$script_before_init_notice . '</p></div>';
 
233
  }
234
 
235
  static function setup_filter() {
@@ -247,9 +277,9 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
247
  static function debug( $message ) {
248
  if ( WP_DEBUG !== false ) {
249
  if ( is_array( $message ) || is_object( $message ) ) {
250
- $message = print_r( $message, true );
251
  }
252
- error_log( "Use Google Libraries: " . $message );
253
  }
254
  }
255
 
@@ -263,12 +293,55 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
263
 
264
  }
265
 
266
-
267
  static function replace_default_scripts_action( &$scripts ) {
268
  $ugl = self::get_instance();
269
  $ugl->replace_default_scripts( $scripts );
270
  }
271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  /**
273
  * Collects replacement script registration data.
274
  *
@@ -286,15 +359,9 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
286
  function build_newscripts( &$scripts ) {
287
  $newscripts = array();
288
  $combine_ok = array();
289
-
290
- // jquery may really be loaded under jquery-core
291
- // if so, we'll adjust google_scripts here
292
- if ( $scripts->query( 'jquery-core' ) && array_key_exists( 'jquery', $this->google_scripts ) ) {
293
- $this->google_scripts['jquery-core'] = $this->google_scripts['jquery'];
294
- unset($this->google_scripts['jquery']);
295
- $this->jquery_tag = 'jquery-core';
296
- }
297
-
298
  foreach ( $this->google_scripts as $name => $values ) {
299
  if ( $script = $scripts->query( $name ) ) {
300
  $lib = $values[0];
@@ -326,23 +393,10 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
326
  }
327
  }
328
 
329
- // if $lib is empty, then this script does not need to be
330
- // exlicitly loaded when using googleapis.com, but we need to keep
331
- // it around for dependencies
332
- if ( $lib != '' ) {
333
- // build new URL
334
- $url = "//ajax.googleapis.com/ajax/libs/$lib/$ver/$js.js";
335
- if ( wp_remote_retrieve_response_code( wp_remote_head( "http:$url" ) ) !== 200 ) {
336
- self::debug( "Google servers do not seem to be hosting requested version of $name (version $ver). Using version provided by WordPress." );
337
- continue;
338
- }
339
- if ( ! $this->protocol_relative_supported ) {
340
- $url = "http:$url";
341
- }
342
- $script->src = $url;
343
- } else {
344
- $script->src = "";
345
- }
346
  $newscripts[] = $script;
347
  $combine_ok[] = $name;
348
  }
@@ -403,7 +457,7 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
403
  function replace_default_scripts( &$scripts ) {
404
  $newscripts = $this->get_newscripts( $scripts );
405
  foreach ( $newscripts as $script ) {
406
- $olddata = $this->WP_Dependency_get_data( $scripts, $script->handle );
407
  $scripts->remove( $script->handle );
408
  // re-register with original ver
409
  $scripts->add( $script->handle, $script->src, $script->deps, $script->ver );
@@ -416,20 +470,24 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
416
  }
417
 
418
 
419
- function WP_Dependency_get_data( $dep_obj, $handle, $data_name = false ) {
420
 
421
- if ( !method_exists( $dep_obj, 'add_data' ) )
422
  return false;
 
423
 
424
- if ( !isset( $dep_obj->registered[$handle] ) )
425
  return false;
 
426
 
427
- if ( !$data_name )
428
- return $dep_obj->registered[$handle]->extra;
 
 
 
 
 
429
 
430
- if ( !method_exists( $dep_obj, 'get_data' ) )
431
- return $dep_obj->registered[$handle]->extra[$data_name];
432
-
433
  return $dep_obj->get_data( $handle, $data_name );
434
  }
435
 
@@ -443,20 +501,20 @@ if ( !class_exists( 'JCP_UseGoogleLibraries' ) ) {
443
  */
444
  function remove_ver_query( $src ) {
445
  if ( $this->noconflict_next ) {
446
- $this->noconflict_next = FALSE;
447
- echo "<script type='text/javascript'>try{jQuery.noConflict();}catch(e){};</script>\n";
448
  }
449
  if ( preg_match( '/ajax\.googleapis\.com\//', $src ) ) {
450
  $src = remove_query_arg( 'ver', $src );
451
- if ( strpos( $src, $this->google_scripts[$this->jquery_tag][1] . ".js" ) ) {
452
- $this->noconflict_next = TRUE;
453
  }
454
  }
455
  return $src;
456
  }
457
 
458
  static function remove_ver_query_filter( $src ) {
459
- $ugl = self::get_instance();
460
  return $ugl->remove_ver_query( $src );
461
  }
462
  }
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.6.1
7
  Author: Jason Penney
8
  Author URI: http://jasonpenney.net/
9
+ Text Domain: use-google-libraries
10
+ Domain Path: /languages
11
  */
12
 
13
  /* Copyright 2008-2013 Jason Penney (email : jpenney@jczorkmid.net )
28
 
29
  */
30
 
31
+ if ( ! class_exists( 'JCP_UseGoogleLibraries' ) ) {
32
 
33
  class JCP_UseGoogleLibraries {
34
 
35
+ protected static $instance;
36
+ protected static $plugin_file = __FILE__;
37
+ protected static $version = '1.6.1';
38
+ protected static $noconflict_inject = "<script type='text/javascript'>try{jQuery.noConflict();}catch(e){};</script>\n";
39
+
40
  public static function get_instance() {
41
+ if ( ! isset( self::$instance ) ) {
42
+ self::$instance = new JCP_UseGoogleLibraries();
43
  }
44
  return self::$instance;
45
  }
46
+
47
  /**
48
  * Registry of script replacement rules
49
+ *
50
  * Entries are formatted as follows:
51
  * <code>
52
+ * 'script-handle' => array(
53
+ * 'google-lib-path',
54
+ * 'google-file-name',
55
  * 'google-combined-into')
56
  * </code>
57
  *
58
+ * - 'script-handle' -- the handle used by WordPress script
59
  * registration
60
  * - 'google-lib-path' -- path to location on Google CDN( empty
61
  * string if script has been combined).
62
  * - 'google-file-name' -- file name (minus .js) on Google CDN (empty
63
  * string if script has been combined).
64
+ * - 'google-combined-into' -- If not empty string, then the given
65
  * handle has been combined into a file loaded by this handle.
66
+ *
67
  * @var array
68
  */
69
  protected $google_scripts;
70
+
71
  /**
72
  * Used internally to ensure jQuery.noconflict is executed as close to
73
  * how core WordPress would.
74
+ *
75
  * @var bool
76
  */
77
  protected $noconflict_next;
84
  * @since 5.2
85
  */
86
  protected $jquery_tag;
87
+
88
  /**
89
+ * True if using a version of WordPress that allows
90
+ * `wp_register_script` to take protocol-relative URLs,
91
+ * otherwise False
92
+ *
93
  * @since 1.5.2
94
+ *
95
  * @var bool
96
  */
97
  protected $protocol_relative_supported;
98
+
99
  /**
100
  * transient name used when caching
101
+ *
102
  * @var string
103
  */
104
  protected static $cache_id = 'JCP_UseGoogleLibraries_cache';
105
+
106
  /**
107
  * transient expiration
108
+ *
109
  * @var int
110
  */
111
  protected static $cache_len = 90000; // 25 hours
112
+
113
  /**
114
+ * Message displayed and logged when a WP_Scripts has been created
115
+ * before it's time
116
+ *
117
+ * @var str
118
  */
119
  protected static $script_before_init_notice =
120
  'Another plugin has registered or enqued a script before the "init" action. Attempting to work around it.';
121
+
122
  /**
123
+ * Registry of scripts available from Google Libraries. Any extra
124
+ * scripts listed here not provided by WordPress or another plugin
125
+ * will not be registered. This list is just used to chancge where
126
+ * things load from.
127
+ *
128
+ * Entries are in the format:
129
+ * <code>
130
+ * 'script-handle' => array(
131
+ * 'google-lib-path',
132
+ * 'google-file-name',
133
+ * 'google-combined-into'
134
+ * )
135
+ * </code>
136
+ *
137
+ * @var array
138
  */
139
+ protected static $default_google_scripts = array(
140
+ /* jQuery */
141
+ 'jquery' => array( 'jquery', 'jquery.min', '' ),
142
+
143
+ /* jQuery UI */
144
+ 'jquery-ui-core' => array( 'jqueryui', 'jquery-ui.min', '' ),
145
+ 'jquery-ui-accordion' => array( '', '', 'jquery-ui-core' ),
146
+ 'jquery-ui-autocomplete' => array( '', '', 'jquery-ui-core' ), /* jQueri UI 1.8 */
147
+ 'jquery-ui-button' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
148
+ 'jquery-ui-datepicker' => array( '', '', 'jquery-ui-core' ),
149
+ 'jquery-ui-dialog' => array( '', '', 'jquery-ui-core' ),
150
+ 'jquery-ui-draggable' => array( '', '', 'jquery-ui-core' ),
151
+ 'jquery-ui-droppable' => array( '', '', 'jquery-ui-core' ),
152
+ 'jquery-ui-menu' => array( '', '', 'jquery-ui-core' ),
153
+ 'jquery-ui-mouse' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
154
+ 'jquery-ui-position' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
155
+ 'jquery-ui-progressbar' => array( '', '', 'jquery-ui-core' ),
156
+ 'jquery-ui-resizable' => array( '', '', 'jquery-ui-core' ),
157
+ 'jquery-ui-selectable' => array( '', '', 'jquery-ui-core' ),
158
+ 'jquery-ui-slider' => array( '', '', 'jquery-ui-core' ),
159
+ 'jquery-ui-sortable' => array( '', '', 'jquery-ui-core' ),
160
+ 'jquery-ui-tabs' => array( '', '', 'jquery-ui-core' ),
161
+ 'jquery-ui-widget' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
162
+
163
+ /* jQuery Effects */
164
+ 'jquery-effects-core' => array( '', '', 'jquery-ui-core' ),
165
+ 'jquery-effects-blind' => array( '', '', 'jquery-ui-core' ),
166
+ 'jquery-effects-bounce' => array( '', '', 'jquery-ui-core' ),
167
+ 'jquery-effects-clip' => array( '', '', 'jquery-ui-core' ),
168
+ 'jquery-effects-drop' => array( '', '', 'jquery-ui-core' ),
169
+ 'jquery-effects-explode' => array( '', '', 'jquery-ui-core' ),
170
+ 'jquery-effects-fade' => array( '', '', 'jquery-ui-core' ), /* jQuery UI 1.8 */
171
+ 'jquery-effects-fold' => array( '', '', 'jquery-ui-core' ),
172
+ 'jquery-effects-highlight' => array( '', '', 'jquery-ui-core' ),
173
+ 'jquery-effects-pulsate' => array( '', '', 'jquery-ui-core' ),
174
+ 'jquery-effects-scale' => array( '', '', 'jquery-ui-core' ),
175
+ 'jquery-effects-shake' => array( '', '', 'jquery-ui-core' ),
176
+ 'jquery-effects-slide' => array( '', '', 'jquery-ui-core' ),
177
+ 'jquery-effects-transfer' => array( '', '', 'jquery-ui-core' ),
178
+
179
+ /* prototype */
180
+ 'prototype' => array( 'prototype', 'prototype', '' ),
181
+
182
+ /* scriptaculous */
183
+ 'scriptaculous-root' => array( 'scriptaculous', 'scriptaculous', '' ),
184
+ 'scriptaculous-builder' => array( '', '', 'scriptaculous-root' ),
185
+ 'scriptaculous-effects' => array( '', '', 'scriptaculous-root' ),
186
+ 'scriptaculous-dragdrop' => array( '', '', 'scriptaculous-root' ),
187
+ 'scriptaculous-controls' => array( '', '', 'scriptaculous-root' ),
188
+ 'scriptaculous-slider' => array( '', '', 'scriptaculous-root' ),
189
+ 'scriptaculous-sound' => array( '', '', 'scriptaculous-root' ),
190
+
191
+ /* moo tools */
192
+ 'mootools' => array( 'mootools', 'mootools-yui-compressed', '' ),
193
+
194
+ /* Dojo */
195
+ 'dojo' => array( 'dojo', 'dojo.xd', '' ),
196
+
197
+ /* swfobject */
198
+ 'swfobject' => array( 'swfobject', 'swfobject', '' ),
199
+
200
+ /* YUI */
201
+ 'yui' => array( 'yui', 'build/yuiloader/yuiloader-min', '' ),
202
+
203
+ /* Ext Core */
204
+ 'ext-core' => array( 'ext-core', 'ext-core', '' )
205
+
206
+ );
207
 
208
  /**
209
  * PHP 5 Constructor
210
  */
211
  function __construct() {
212
+ $this->jquery_tag = 'jquery';
213
+ $this->google_scripts = self::$default_google_scripts;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
 
215
+ $this->noconflict_next = false;
216
+ // protocol-relative URLS accepted by `wp_register_scripts`
 
217
  // starting with version 3.5
218
+ $this->protocol_relative_supported = version_compare(
219
+ get_bloginfo( 'version' ), '3.5', '>='
220
+ );
221
  }
222
 
223
  static function configure_plugin() {
224
+ add_action(
225
+ 'wp_default_scripts',
226
+ array(
227
+ 'JCP_UseGoogleLibraries',
228
+ 'replace_default_scripts_action',
229
+ ),
230
+ 1000
231
+ );
232
+ add_filter(
233
+ 'script_loader_src',
234
+ array( 'JCP_UseGoogleLibraries', 'remove_ver_query_filter' ),
235
+ 1000
236
+ );
237
+ add_filter(
238
+ 'init',
239
+ array( 'JCP_UseGoogleLibraries', 'setup_filter' )
240
+ );
241
+
242
+ // There's a chance some plugin has called wp_enqueue_script
243
+ // outside of any hooks, which means that this plugin's
244
+ // 'wp_default_scripts' hook will never get a chance to fire.
245
+ // This tries to work around that.
246
  global $wp_scripts;
247
  if ( is_a( $wp_scripts, 'WP_Scripts' ) ) {
248
  self::debug( self::$script_before_init_notice );
252
  }
253
 
254
  /**
255
+ * Get markup to show error message in admin when $WP_Script
256
+ * created before it's time
257
+ *
258
+ * @returns string markup for notice display
259
  */
260
  static function script_before_init_admin_notice() {
261
+ echo '<div class="error fade"><p>Use Google Libraries: ' .
262
+ self::$script_before_init_notice . '</p></div>';
263
  }
264
 
265
  static function setup_filter() {
277
  static function debug( $message ) {
278
  if ( WP_DEBUG !== false ) {
279
  if ( is_array( $message ) || is_object( $message ) ) {
280
+ $message = var_export( $message, true );
281
  }
282
+ error_log( 'Use Google Libraries: ' . $message );
283
  }
284
  }
285
 
293
 
294
  }
295
 
 
296
  static function replace_default_scripts_action( &$scripts ) {
297
  $ugl = self::get_instance();
298
  $ugl->replace_default_scripts( $scripts );
299
  }
300
 
301
+ /**
302
+ * Sometimes WordPress registes `jquery.js` as `'jquery-core'`, while
303
+ * '`jquery`' is some other script with a dependency on
304
+ * `'jquery-core'`. If '`jquery-core`' in present in `$scripts`
305
+ * this is assumed to be the case and update the registration for
306
+ * '`jquery-core`' instead.
307
+ *
308
+ * @since 1.6
309
+ *
310
+ * @param object $scripts
311
+ */
312
+ protected function newscripts_fix_jquery_core( &$scripts ) {
313
+ // jquery may really be loaded under jquery-core
314
+ // if so, we'll adjust google_scripts here
315
+ if ( $scripts->query( 'jquery-core' ) && array_key_exists( 'jquery', $this->google_scripts ) ) {
316
+ $this->google_scripts['jquery-core'] = $this->google_scripts['jquery'];
317
+ unset( $this->google_scripts['jquery'] );
318
+ $this->jquery_tag = 'jquery-core';
319
+ }
320
+ }
321
+
322
+ protected function newscripts_build_url( $name, $lib, $ver, $js, $orig_url ) {
323
+
324
+ // if $lib is empty, then this script does not need to be
325
+ // exlicitly loaded when using googleapis.com, but we need to keep
326
+ // it around for dependencies
327
+ if ( $lib != '' ) {
328
+ // build new URL
329
+ $url = "//ajax.googleapis.com/ajax/libs/$lib/$ver/$js.js";
330
+ $proto_url = "http:$url";
331
+ $head = wp_remote_head( $proto_url );
332
+ if ( wp_remote_retrieve_response_code( $head ) !== 200 ) {
333
+ self::debug( "Google servers do not seem to be hosting requested version of $name (version $ver). Using version provided by WordPress." );
334
+ return $orig_url;
335
+ }
336
+ if ( ! $this->protocol_relative_supported ) {
337
+ return $proto_url;
338
+ }
339
+ return $url;
340
+ } else {
341
+ return '';
342
+ }
343
+ }
344
+
345
  /**
346
  * Collects replacement script registration data.
347
  *
359
  function build_newscripts( &$scripts ) {
360
  $newscripts = array();
361
  $combine_ok = array();
362
+
363
+ $this->newscripts_fix_jquery_core( $scripts );
364
+
 
 
 
 
 
 
365
  foreach ( $this->google_scripts as $name => $values ) {
366
  if ( $script = $scripts->query( $name ) ) {
367
  $lib = $values[0];
393
  }
394
  }
395
 
396
+ $script->src = $this->newscripts_build_url(
397
+ $name, $lib, $ver, $js, $script->src
398
+ );
399
+
 
 
 
 
 
 
 
 
 
 
 
 
 
400
  $newscripts[] = $script;
401
  $combine_ok[] = $name;
402
  }
457
  function replace_default_scripts( &$scripts ) {
458
  $newscripts = $this->get_newscripts( $scripts );
459
  foreach ( $newscripts as $script ) {
460
+ $olddata = $this->wp_dependency_get_data( $scripts, $script->handle );
461
  $scripts->remove( $script->handle );
462
  // re-register with original ver
463
  $scripts->add( $script->handle, $script->src, $script->deps, $script->ver );
470
  }
471
 
472
 
473
+ function wp_dependency_get_data( $dep_obj, $handle, $data_name = false ) {
474
 
475
+ if ( ! method_exists( $dep_obj, 'add_data' ) ) {
476
  return false;
477
+ }
478
 
479
+ if ( ! isset( $dep_obj->registered[ $handle ] ) ) {
480
  return false;
481
+ }
482
 
483
+ if ( ! $data_name ) {
484
+ return $dep_obj->registered[ $handle ]->extra;
485
+ }
486
+
487
+ if ( ! method_exists( $dep_obj, 'get_data' ) ) {
488
+ return $dep_obj->registered[ $handle ]->extra[ $data_name ];
489
+ }
490
 
 
 
 
491
  return $dep_obj->get_data( $handle, $data_name );
492
  }
493
 
501
  */
502
  function remove_ver_query( $src ) {
503
  if ( $this->noconflict_next ) {
504
+ $this->noconflict_next = false;
505
+ echo self::$noconflict_inject; // xss ok
506
  }
507
  if ( preg_match( '/ajax\.googleapis\.com\//', $src ) ) {
508
  $src = remove_query_arg( 'ver', $src );
509
+ if ( strpos( $src, $this->google_scripts[ $this->jquery_tag ][1] . '.js' ) ) {
510
+ $this->noconflict_next = true;
511
  }
512
  }
513
  return $src;
514
  }
515
 
516
  static function remove_ver_query_filter( $src ) {
517
+ $ugl = self::get_instance();
518
  return $ugl->remove_ver_query( $src );
519
  }
520
  }