Split the script queue in head and footer part, concatenate and compress the default js and css, first run, see #8628

git-svn-id: http://svn.automattic.com/wordpress/trunk@10357 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-01-14 14:18:51 +00:00
parent cc2b577fbe
commit fc7d871678
10 changed files with 726 additions and 58 deletions

View File

@ -63,6 +63,18 @@ case 'ajax-tag-search' :
echo join( $results, "\n" );
die;
break;
case 'wp-compression-test' :
if ( !current_user_can( 'manage_options' ) )
die('-1');
if ( isset($_GET['tested']) ) {
if ( 1 == $_GET['tested'] )
update_option('can_compress_scripts', 1);
elseif ( 0 == $_GET['tested'] )
update_option('can_compress_scripts', 0);
}
die('0');
break;
default :
do_action( 'wp_ajax_' . $_GET['action'] );
die('0');

View File

@ -22,7 +22,14 @@ echo '<span id="footer-thankyou">' . __('Thank you for creating with <a href="ht
<p id="footer-upgrade" class="alignright"><?php echo $upgrade; ?></p>
<div class="clear"></div>
</div>
<?php do_action('admin_footer', ''); ?>
<?php
do_action('admin_footer', '');
do_action('admin_print_footer_scripts');
if ( false === get_option('can_compress_scripts') )
compression_test();
?>
<script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
</body>
</html>
</html>

View File

@ -3387,4 +3387,37 @@ function screen_icon($name = '') {
<?php
}
/**
* Test support for compressed JavaScript and CSS
*
* Outputs JavaScript that tests if compression from PHP works as expected
* and sets an option with the result. Has no effect when the current user
* is not an administrator. To run the test again the option 'can_compress_scripts'
* has to be deleted.
*
* @since 2.8.0
*/
function compression_test() {
?>
<script type="text/javascript" src="load-scripts.php?test=1"></script>
<script type="text/javascript">
/* <![CDATA[ */
(function() {
var x, test = typeof wpCompressionTest == 'undefined' ? 0 : 1;
if ( window.XMLHttpRequest ) {
x = new XMLHttpRequest();
} else {
try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
}
if (x) {
x.open('GET', 'admin-ajax.php?action=wp-compression-test&tested='+test+'&'+(new Date()).getTime(), true);
x.send('');
}
})();
/* ]]> */
</script>
<?php
}
?>

160
wp-admin/load-scripts.php Normal file
View File

@ -0,0 +1,160 @@
<?php
/** Set ABSPATH for execution */
define( 'ABSPATH', dirname(dirname(__FILE__)) );
define( 'WPINC', '/wp-includes' );
/**
* @ignore
*/
function __() {}
/**
* @ignore
*/
function _c() {}
/**
* @ignore
*/
function add_filter() {}
/**
* @ignore
*/
function attribute_escape() {}
/**
* @ignore
*/
function apply_filters() {}
/**
* @ignore
*/
function get_option() {}
/**
* @ignore
*/
function is_lighttpd_before_150() {}
/**
* @ignore
*/
function add_action() {}
/**
* @ignore
*/
function do_action_ref_array() {}
/**
* @ignore
*/
function get_bloginfo() {}
/**
* @ignore
*/
function is_admin() {return true;}
/**
* @ignore
*/
function site_url() {}
/**
* @ignore
*/
function admin_url() {}
/**
* @ignore
*/
function wp_guess_url() {}
function get_file($path) {
if ( function_exists('realpath') )
$path = realpath($path);
if ( ! $path || ! @is_file($path) )
return '';
return @file_get_contents($path);
}
if ( isset($_GET['test']) && 1 == $_GET['test'] ) {
if ( ini_get('zlib.output_compression') )
exit('');
$out = 'var wpCompressionTest = 1;';
$compressed = false;
if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'deflate') && function_exists('gzdeflate') ) {
header('Content-Encoding: deflate');
$out = gzdeflate( $out, 3 );
$compressed = true;
} elseif ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && function_exists('gzencode') ) {
header('Content-Encoding: gzip');
$out = gzencode( $out, 3 );
$compressed = true;
}
if ( ! $compressed )
exit('');
header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
header( 'Pragma: no-cache' );
header( 'Content-Type: application/x-javascript; charset=UTF-8' );
echo $out;
exit;
}
$load = preg_replace( '/[^a-z0-9,_-]*/i', '', $_GET['load'] );
$load = explode(',', $load);
if ( empty($load) )
exit;
require(ABSPATH . '/wp-includes/script-loader.php');
require(ABSPATH . '/wp-includes/version.php');
// Discard any buffers
while ( @ob_end_clean() );
$compress = ( isset($_GET['c']) && 1 == $_GET['c'] );
$expires_offset = 31536000;
$out = '';
$wp_scripts = new WP_Scripts();
wp_default_scripts($wp_scripts);
foreach( $load as $handle ) {
if ( !array_key_exists($handle, $wp_scripts->registered) )
continue;
$path = ABSPATH . $wp_scripts->registered[$handle]->src;
$out .= get_file($path) . "\n";
}
header('Content-Type: application/x-javascript; charset=UTF-8');
header('Vary: Accept-Encoding'); // Handle proxies
header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
header("Cache-Control: public, max-age=$expires_offset");
if ( $compress && ! ini_get('zlib.output_compression') ) {
if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'deflate') && function_exists('gzdeflate') ) {
header('Content-Encoding: deflate');
$out = gzdeflate( $out, 3 );
} elseif ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && function_exists('gzencode') ) {
header('Content-Encoding: gzip');
$out = gzencode( $out, 3 );
}
}
echo $out;
exit;

141
wp-admin/load-styles.php Normal file
View File

@ -0,0 +1,141 @@
<?php
/** Set ABSPATH for execution */
define( 'ABSPATH', dirname(dirname(__FILE__)) );
define( 'WPINC', '/wp-includes' );
/**
* @ignore
*/
function __() {}
/**
* @ignore
*/
function _c() {}
/**
* @ignore
*/
function add_filter() {}
/**
* @ignore
*/
function attribute_escape() {}
/**
* @ignore
*/
function apply_filters() {}
/**
* @ignore
*/
function get_option() {}
/**
* @ignore
*/
function is_lighttpd_before_150() {}
/**
* @ignore
*/
function add_action() {}
/**
* @ignore
*/
function do_action_ref_array() {}
/**
* @ignore
*/
function get_bloginfo() {}
/**
* @ignore
*/
function is_admin() {return true;}
/**
* @ignore
*/
function site_url() {}
/**
* @ignore
*/
function admin_url() {}
/**
* @ignore
*/
function wp_guess_url() {}
function get_file($path) {
if ( function_exists('realpath') )
$path = realpath($path);
if ( ! $path || ! @is_file($path) )
return '';
return @file_get_contents($path);
}
require(ABSPATH . '/wp-includes/script-loader.php');
require(ABSPATH . '/wp-includes/version.php');
// Discard any buffers
while ( @ob_end_clean() );
$load = preg_replace( '/[^a-z0-9,_-]*/i', '', $_GET['load'] );
$load = explode(',', $load);
if ( empty($load) )
exit;
$compress = ( isset($_GET['c']) && 1 == $_GET['c'] );
$rtl = ( isset($_GET['rtl']) && 1 == $_GET['rtl'] );
$expires_offset = 31536000;
$out = '';
$wp_styles = new WP_Styles();
wp_default_styles($wp_styles);
foreach( $load as $handle ) {
if ( !array_key_exists($handle, $wp_styles->registered) )
continue;
$style = $wp_styles->registered[$handle];
$path = ABSPATH . $style->src;
$content = get_file($path) . "\n";
if ( $rtl && isset($style->extra['rtl']) && $style->extra['rtl'] ) {
$rtl_path = is_bool($style->extra['rtl']) ? str_replace( '.css', '-rtl.css', $path ) : ABSPATH . $style->extra['rtl'];
$content .= get_file($rtl_path) . "\n";
}
$out .= str_replace( '../images/', 'images/', $content );
}
header('Content-Type: text/css');
header('Vary: Accept-Encoding'); // Handle proxies
header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
header("Cache-Control: public, max-age=$expires_offset");
if ( $compress && ! ini_get('zlib.output_compression') ) {
if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'deflate') && function_exists('gzdeflate') ) {
header('Content-Encoding: deflate');
$out = gzdeflate( $out, 3 );
} elseif ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && function_exists('gzencode') ) {
header('Content-Encoding: gzip');
$out = gzencode( $out, 3 );
}
}
echo $out;
exit;

View File

@ -22,6 +22,8 @@ class WP_Dependencies {
var $to_do = array();
var $done = array();
var $args = array();
var $groups = array();
var $group = 0;
function WP_Dependencies() {
$args = func_get_args();
@ -38,21 +40,26 @@ class WP_Dependencies {
* @param mixed handles (optional) items to be processed. (void) processes queue, (string) process that item, (array of strings) process those items
* @return array Items that have been processed
*/
function do_items( $handles = false ) {
function do_items( $handles = false, $group = false ) {
// Print the queue if nothing is passed. If a string is passed, print that script. If an array is passed, print those scripts.
$handles = false === $handles ? $this->queue : (array) $handles;
$this->all_deps( $handles );
foreach( $this->to_do as $handle ) {
foreach( $this->to_do as $key => $handle ) {
if ( !in_array($handle, $this->done) && isset($this->registered[$handle]) ) {
if ( $this->registered[$handle]->src ) { // Else it defines a group.
$this->do_item( $handle );
if ( ! $this->registered[$handle]->src ) { // Defines a group.
$this->done[] = $handle;
continue;
}
$this->done[] = $handle;
if ( $this->do_item( $handle, $group ) )
$this->done[] = $handle;
unset( $this->to_do[$key] );
}
}
$this->to_do = array();
return $this->done;
}
@ -69,25 +76,31 @@ class WP_Dependencies {
* @param mixed handles Accepts (string) dep name or (array of strings) dep names
* @param bool recursion Used internally when function calls itself
*/
function all_deps( $handles, $recursion = false ) {
function all_deps( $handles, $recursion = false, $group = false ) {
if ( !$handles = (array) $handles )
return false;
foreach ( $handles as $handle ) {
$handle = explode('?', $handle);
if ( isset($handle[1]) )
$this->args[$handle[0]] = $handle[1];
$handle = $handle[0];
$handle_parts = explode('?', $handle);
$handle = $handle_parts[0];
if ( isset($this->to_do[$handle]) ) // Already grobbed it and its deps
if ( in_array($handle, $this->done, true) ) // Already done
continue;
$this->set_group( $handle, $recursion, $group );
if ( in_array($handle, $this->to_do, true) ) // Already grobbed it and its deps
continue;
if ( isset($handle_parts[1]) )
$this->args[$handle] = $handle_parts[1];
$keep_going = true;
if ( !isset($this->registered[$handle]) )
$keep_going = false; // Script doesn't exist
elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) )
$keep_going = false; // Script requires deps which don't exist (not a necessary check. efficiency?)
elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true ) )
elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $group ) )
$keep_going = false; // Script requires deps which don't exist
if ( !$keep_going ) { // Either script or its deps don't exist.
@ -97,11 +110,9 @@ class WP_Dependencies {
continue; // We're at the top level. Move on to the next one.
}
$this->to_do[$handle] = true;
$this->to_do[] = $handle;
}
if ( !$recursion ) // at the end
$this->to_do = array_keys( $this->to_do );
return true;
}
@ -181,6 +192,21 @@ class WP_Dependencies {
return false;
}
function set_group( $handle, $recursion, $group ) {
$group = (int) $group;
if ( $recursion )
$group = min($this->group, $group);
else
$this->group = $group;
if ( isset($this->groups[$handle]) && $this->groups[$handle] <= $group )
return false;
$this->groups[$handle] = $group;
return true;
}
}
class _WP_Dependency {

View File

@ -18,7 +18,15 @@
*/
class WP_Scripts extends WP_Dependencies {
var $base_url; // Full URL with trailing slash
var $content_url;
var $default_version;
var $in_footer = array();
var $concat = '';
var $concat_version = '';
var $do_concat = false;
var $print_html = '';
var $print_code = '';
var $default_dirs;
function __construct() {
do_action_ref_array( 'wp_default_scripts', array(&$this) );
@ -30,57 +38,84 @@ class WP_Scripts extends WP_Dependencies {
* Prints the scripts passed to it or the print queue. Also prints all necessary dependencies.
*
* @param mixed handles (optional) Scripts to be printed. (void) prints queue, (string) prints that script, (array of strings) prints those scripts.
* @param int group (optional) If scripts were queued in groups prints this group number.
* @return array Scripts that have been printed
*/
function print_scripts( $handles = false ) {
return $this->do_items( $handles );
function print_scripts( $handles = false, $group = false ) {
return $this->do_items( $handles, $group );
}
function print_scripts_l10n( $handle ) {
function print_scripts_l10n( $handle, $echo = true ) {
if ( empty($this->registered[$handle]->extra['l10n']) || empty($this->registered[$handle]->extra['l10n'][0]) || !is_array($this->registered[$handle]->extra['l10n'][1]) )
return false;
$object_name = $this->registered[$handle]->extra['l10n'][0];
echo "<script type='text/javascript'>\n";
echo "/* <![CDATA[ */\n";
echo "\t$object_name = {\n";
$data = "var $object_name = {\n";
$eol = '';
foreach ( $this->registered[$handle]->extra['l10n'][1] as $var => $val ) {
if ( 'l10n_print_after' == $var ) {
$after = $val;
continue;
}
echo "$eol\t\t$var: \"" . js_escape( $val ) . '"';
$data .= "$eol\t$var: \"" . js_escape( $val ) . '"';
$eol = ",\n";
}
echo "\n\t}\n";
echo isset($after) ? "\t$after\n" : '';
echo "/* ]]> */\n";
echo "</script>\n";
$data .= "\n};\n";
$data .= isset($after) ? "$after\n" : '';
return true;
if ( $echo ) {
echo "<script type='text/javascript'>\n";
echo "/* <![CDATA[ */\n";
echo $data;
echo "/* ]]> */\n";
echo "</script>\n";
return true;
} else {
return $data;
}
}
function do_item( $handle ) {
function do_item( $handle, $group = false ) {
if ( !parent::do_item($handle) )
return false;
if ( 0 === $group && $this->groups[$handle] > 0 ) {
$this->in_footer[] = $handle;
return false;
}
if ( false === $group && in_array($handle, $this->in_footer, true) )
$this->in_footer = array_diff( $this->in_footer, (array) $handle );
$ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version;
if ( isset($this->args[$handle]) )
$ver .= '&amp;' . $this->args[$handle];
$src = $this->registered[$handle]->src;
if ( !preg_match('|^https?://|', $src) && !preg_match('|^' . preg_quote(WP_CONTENT_URL) . '|', $src) ) {
if ( $this->do_concat ) {
$srce = apply_filters( 'script_loader_src', $src, $handle, $echo );
if ( $this->in_default_dir($srce) ) {
$this->print_code .= $this->print_scripts_l10n( $handle, false );
$this->concat .= $handle . ',';
$this->concat_version .= $ver;
return true;
}
}
$this->print_scripts_l10n( $handle );
if ( !preg_match('|^https?://|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {
$src = $this->base_url . $src;
}
$src = add_query_arg('ver', $ver, $src);
$src = clean_url(apply_filters( 'script_loader_src', $src, $handle ));
$src = clean_url(apply_filters( 'script_loader_src', $src, $handle, $echo ));
$this->print_scripts_l10n( $handle );
echo "<script type='text/javascript' src='$src'></script>\n";
if ( $this->do_concat )
$this->print_html .= "<script type='text/javascript' src='$src'></script>\n";
else
echo "<script type='text/javascript' src='$src'></script>\n";
return true;
}
@ -101,10 +136,47 @@ class WP_Scripts extends WP_Dependencies {
return $this->add_data( $handle, 'l10n', array( $object_name, $l10n ) );
}
function set_group( $handle, $recursion, $group = false ) {
$grp = isset($this->registered[$handle]->extra['group']) ? (int) $this->registered[$handle]->extra['group'] : 0;
if ( false !== $group && $grp > $group )
$grp = $group;
parent::set_group( $handle, $recursion, $grp );
}
function all_deps( $handles, $recursion = false ) {
$r = parent::all_deps( $handles, $recursion );
if ( !$recursion )
$this->to_do = apply_filters( 'print_scripts_array', $this->to_do );
return $r;
}
function do_head_items() {
$this->do_items(false, 0);
return $this->done;
}
function do_footer_items() {
if ( !empty($this->in_footer) ) {
foreach( $this->in_footer as $key => $handle ) {
if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) {
$this->do_item($handle, false, $this->doecho);
$this->done[] = $handle;
unset( $this->in_footer[$key] );
}
}
}
return $this->done;
}
function in_default_dir($src) {
if ( ! $this->default_dirs )
return true;
foreach ( (array) $this->default_dirs as $test ) {
if ( 0 === strpos($src, $test) )
return true;
}
return false;
}
}

View File

@ -18,8 +18,14 @@
*/
class WP_Styles extends WP_Dependencies {
var $base_url;
var $content_url;
var $default_version;
var $text_direction = 'ltr';
var $concat = '';
var $concat_version = '';
var $do_concat = false;
var $print_html = '';
var $default_dirs;
function __construct() {
do_action_ref_array( 'wp_default_styles', array(&$this) );
@ -33,6 +39,14 @@ class WP_Styles extends WP_Dependencies {
if ( isset($this->args[$handle]) )
$ver .= '&amp;' . $this->args[$handle];
if ( $this->do_concat ) {
if ( $this->in_default_dir($this->registered[$handle]->src) && !isset($this->registered[$handle]->extra['conditional']) && !isset($this->registered[$handle]->extra['alt']) ) {
$this->concat .= $handle . ',';
$this->concat_version .= $ver;
return true;
}
}
if ( isset($this->registered[$handle]->args) )
$media = attribute_escape( $this->registered[$handle]->args );
else
@ -42,23 +56,28 @@ class WP_Styles extends WP_Dependencies {
$rel = isset($this->registered[$handle]->extra['alt']) && $this->registered[$handle]->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
$title = isset($this->registered[$handle]->extra['title']) ? "title='" . attribute_escape( $this->registered[$handle]->extra['title'] ) . "'" : '';
$end_cond = '';
$end_cond = $tag = '';
if ( isset($this->registered[$handle]->extra['conditional']) && $this->registered[$handle]->extra['conditional'] ) {
echo "<!--[if {$this->registered[$handle]->extra['conditional']}]>\n";
$tag .= "<!--[if {$this->registered[$handle]->extra['conditional']}]>\n";
$end_cond = "<![endif]-->\n";
}
echo apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle' $title href='$href' type='text/css' media='$media' />\n", $handle );
$tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle' $title href='$href' type='text/css' media='$media' />\n", $handle );
if ( 'rtl' === $this->text_direction && isset($this->registered[$handle]->extra['rtl']) && $this->registered[$handle]->extra['rtl'] ) {
if ( is_bool( $this->registered[$handle]->extra['rtl'] ) )
$rtl_href = str_replace( '.css', '-rtl.css', $href );
else
$rtl_href = $this->_css_href( $this->registered[$handle]->extra['rtl'], $ver, "$handle-rtl" );
echo apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle );
$tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle );
}
echo $end_cond;
$tag .= $end_cond;
if ( $this->do_concat )
$this->print_html .= $tag;
else
echo $tag;
// Could do something with $this->registered[$handle]->extra here to print out extra CSS rules
// echo "<style type='text/css'>\n";
@ -77,7 +96,7 @@ class WP_Styles extends WP_Dependencies {
}
function _css_href( $src, $ver, $handle ) {
if ( !preg_match('|^https?://|', $src) && !preg_match('|^' . preg_quote(WP_CONTENT_URL) . '|', $src) ) {
if ( !preg_match('|^https?://|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {
$src = $this->base_url . $src;
}
@ -86,4 +105,15 @@ class WP_Styles extends WP_Dependencies {
return clean_url( $src );
}
function in_default_dir($src) {
if ( ! $this->default_dirs )
return true;
foreach ( (array) $this->default_dirs as $test ) {
if ( 0 === strpos($src, $test) )
return true;
}
return false;
}
}

View File

@ -181,8 +181,9 @@ add_action('do_feed_atom', 'do_feed_atom', 10, 1);
add_action('do_pings', 'do_all_pings', 10, 1);
add_action('do_robots', 'do_robots');
add_action('sanitize_comment_cookies', 'sanitize_comment_cookies');
add_action('admin_print_scripts', 'wp_print_scripts', 20);
add_action('admin_print_styles', 'wp_print_styles', 20);
add_action('admin_print_scripts', 'wp_print_head_scripts', 20);
add_action('admin_print_footer_scripts', 'wp_print_footer_scripts', 20);
add_action('admin_print_styles', 'wp_print_admin_styles', 20);
add_action('init', 'smilies_init', 5);
add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );
add_action( 'shutdown', 'wp_ob_end_flush_all', 1);

View File

@ -35,22 +35,29 @@ require( ABSPATH . WPINC . '/functions.wp-styles.php' );
* @param object $scripts WP_Scripts object.
*/
function wp_default_scripts( &$scripts ) {
if (!$guessurl = site_url())
if ( !$guessurl = site_url() )
$guessurl = wp_guess_url();
$scripts->base_url = $guessurl;
$scripts->content_url = WP_CONTENT_URL;
$scripts->default_version = get_bloginfo( 'version' );
$scripts->default_dirs = array('/wp-admin/js/', '/wp-includes/js/');
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : '';
$scripts->add( 'utils', "/wp-admin/js/utils$suffix.js", false, '20090102' );
$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), '20090106' );
$scripts->add_data( 'common', 'group', 1 );
$scripts->localize( 'common', 'commonL10n', array(
'warnDelete' => __("You are about to delete the selected items.\n 'Cancel' to stop, 'OK' to delete."),
'l10n_print_after' => 'try{convertEntities(commonL10n);}catch(e){};'
) );
$scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", false, '1.6.1' );
$scripts->add_data( 'sack', 'group', 1 );
$scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", false, '20090102' );
$scripts->localize( 'quicktags', 'quicktagsL10n', array(
@ -79,6 +86,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6');
$scripts->add( 'wp-ajax-response', "/wp-includes/js/wp-ajax-response$suffix.js", array('jquery'), '20090102' );
$scripts->add_data( 'wp-ajax-response', 'group', 1 );
$scripts->localize( 'wp-ajax-response', 'wpAjax', array(
'noPerm' => __('You do not have permission to do that.'),
'broken' => __('An unidentified error has occurred.'),
@ -86,8 +94,10 @@ function wp_default_scripts( &$scripts ) {
) );
$scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response'), '20090106' );
$scripts->add_data( 'autosave', 'group', 1 );
$scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array('wp-ajax-response'), '20090102' );
$scripts->add_data( 'wp-lists', 'group', 1 );
$scripts->localize( 'wp-lists', 'wpListL10n', array(
'url' => admin_url('admin-ajax.php')
) );
@ -104,14 +114,48 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'), '20070118');
$scripts->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.3b2');
$scripts->add( 'jquery-ui-core', '/wp-includes/js/jquery/ui.core.js', array('jquery'), '1.5.2' );
$scripts->add_data( 'jquery-ui-core', 'group', 1 );
$scripts->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery-ui-core'), '1.5.2' );
$scripts->add_data( 'jquery-ui-tabs', 'group', 1 );
$scripts->add( 'jquery-ui-sortable', '/wp-includes/js/jquery/ui.sortable.js', array('jquery-ui-core'), '1.5.2c' );
$scripts->add_data( 'jquery-ui-sortable', 'group', 1 );
$scripts->add( 'jquery-ui-draggable', '/wp-includes/js/jquery/ui.draggable.js', array('jquery-ui-core'), '1.5.2' );
$scripts->add_data( 'jquery-ui-draggable', 'group', 1 );
$scripts->add( 'jquery-ui-resizable', '/wp-includes/js/jquery/ui.resizable.js', array('jquery-ui-core'), '1.5.2' );
$scripts->add_data( 'jquery-ui-resizable', 'group', 1 );
$scripts->add( 'jquery-ui-dialog', '/wp-includes/js/jquery/ui.dialog.js', array('jquery-ui-resizable', 'jquery-ui-draggable'), '1.5.2' );
$scripts->add_data( 'jquery-ui-dialog', 'group', 1 );
$scripts->add( 'jquery-form', "/wp-includes/js/jquery/jquery.form$suffix.js", array('jquery'), '2.02m');
$scripts->add_data( 'jquery-form', 'group', 1 );
$scripts->add( 'jquery-color', "/wp-includes/js/jquery/jquery.color$suffix.js", array('jquery'), '2.0-4561m');
$scripts->add_data( 'jquery-color', 'group', 1 );
$scripts->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2' );
$scripts->add( 'suggest', "/wp-includes/js/jquery/suggest$suffix.js", array('jquery'), '1.1bm');
$scripts->add_data( 'suggest', 'group', 1 );
$scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20m');
$scripts->add_data( 'schedule', 'group', 1 );
$scripts->add( 'jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys$suffix.js", array('jquery'), '0.0.2m' );
$scripts->add_data( 'jquery-hotkeys', 'group', 1 );
$scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array('jquery', 'jquery-hotkeys'), '20090102' );
$scripts->add_data( 'jquery-table-hotkeys', 'group', 1 );
$scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20080430m');
$scripts->add_data( 'thickbox', 'group', 1 );
if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
$scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.2.0-20081031');
@ -144,23 +188,17 @@ function wp_default_scripts( &$scripts ) {
'deleted' => __('Deleted'),
'l10n_print_after' => 'try{convertEntities(swfuploadL10n);}catch(e){};'
) );
$scripts->add( 'swfupload-degrade', '/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', array('swfupload'), '2.2.0-20081031');
$scripts->localize( 'swfupload-degrade', 'uploadDegradeOptions', array(
'is_lighttpd_before_150' => is_lighttpd_before_150(),
) );
$scripts->add( 'jquery-ui-core', '/wp-includes/js/jquery/ui.core.js', array('jquery'), '1.5.2' );
$scripts->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery-ui-core'), '1.5.2' );
$scripts->add( 'jquery-ui-sortable', '/wp-includes/js/jquery/ui.sortable.js', array('jquery-ui-core'), '1.5.2c' );
$scripts->add( 'jquery-ui-draggable', '/wp-includes/js/jquery/ui.draggable.js', array('jquery-ui-core'), '1.5.2' );
$scripts->add( 'jquery-ui-resizable', '/wp-includes/js/jquery/ui.resizable.js', array('jquery-ui-core'), '1.5.2' );
$scripts->add( 'jquery-ui-dialog', '/wp-includes/js/jquery/ui.dialog.js', array('jquery-ui-resizable', 'jquery-ui-draggable'), '1.5.2' );
$scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js", false, '20090102');
if ( is_admin() ) {
$scripts->add( 'ajaxcat', "/wp-admin/js/cat$suffix.js", array( 'wp-lists' ), '20090102' );
$scripts->add_data( 'ajaxcat', 'group', 1 );
$scripts->localize( 'ajaxcat', 'catL10n', array(
'add' => attribute_escape(__('Add')),
'how' => __('Separate multiple categories with commas.'),
@ -168,12 +206,16 @@ function wp_default_scripts( &$scripts ) {
) );
$scripts->add( 'admin-categories', "/wp-admin/js/categories$suffix.js", array('wp-lists'), '20090102' );
$scripts->add_data( 'admin-categories', 'group', 1 );
$scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array('wp-lists'), '20090102' );
$scripts->add_data( 'admin-tags', 'group', 1 );
$scripts->add( 'admin-custom-fields', "/wp-admin/js/custom-fields$suffix.js", array('wp-lists'), '20090106' );
$scripts->add_data( 'admin-custom-fields', 'group', 1 );
$scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array('jquery'), '20090102' );
$scripts->add_data( 'password-strength-meter', 'group', 1 );
$scripts->localize( 'password-strength-meter', 'pwsL10n', array(
'empty' => __('Strength indicator'),
'short' => __('Very weak'),
@ -184,6 +226,7 @@ function wp_default_scripts( &$scripts ) {
) );
$scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'jquery-ui-resizable', 'quicktags'), '20090112' );
$scripts->add_data( 'admin-comments', 'group', 1 );
$scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last'])
@ -192,11 +235,13 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'xfn', "/wp-admin/js/xfn$suffix.js", false, '3517m' );
$scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), '20090102' );
$scripts->add_data( 'postbox', 'group', 1 );
$scripts->localize( 'postbox', 'postboxL10n', array(
'requestFile' => admin_url('admin-ajax.php')
) );
$scripts->add( 'slug', "/wp-admin/js/slug$suffix.js", array('jquery'), '20090102' );
$scripts->add_data( 'slug', 'group', 1 );
$scripts->localize( 'slug', 'slugL10n', array(
'requestFile' => admin_url('admin-ajax.php'),
'save' => __('Save'),
@ -205,6 +250,7 @@ function wp_default_scripts( &$scripts ) {
) );
$scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20090102' );
$scripts->add_data( 'post', 'group', 1 );
$scripts->localize( 'post', 'postL10n', array(
'tagsUsed' => __('Tags used on this post:'),
'add' => attribute_escape(__('Add')),
@ -232,6 +278,7 @@ function wp_default_scripts( &$scripts ) {
) );
$scripts->add( 'page', "/wp-admin/js/page$suffix.js", array('jquery', 'slug', 'wp-lists', 'postbox'), '20090102' );
$scripts->add_data( 'page', 'group', 1 );
$scripts->localize( 'page', 'postL10n', array(
'cancel' => __('Cancel'),
'edit' => __('Edit'),
@ -254,8 +301,10 @@ function wp_default_scripts( &$scripts ) {
) );
$scripts->add( 'link', "/wp-admin/js/link$suffix.js", array('jquery-ui-tabs', 'wp-lists', 'postbox'), '20090102' );
$scripts->add_data( 'link', 'group', 1 );
$scripts->add( 'comment', "/wp-admin/js/comment$suffix.js", array('jquery'), '20090102' );
$scripts->add_data( 'comment', 'group', 1 );
$scripts->localize( 'comment', 'commentL10n', array(
'cancel' => __('Cancel'),
'edit' => __('Edit'),
@ -265,6 +314,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'admin-gallery', "/wp-admin/js/gallery$suffix.js", array( 'jquery-ui-sortable' ), '20090102' );
$scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox' ), '20090102' );
$scripts->add_data( 'media-upload', 'group', 1 );
$scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'interface' ), '20090106' );
$scripts->localize( 'admin-widgets', 'widgetsL10n', array(
@ -277,6 +327,7 @@ function wp_default_scripts( &$scripts ) {
));
$scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array( 'jquery' ), '20090102' );
$scripts->add_data( 'word-count', 'group', 1 );
$scripts->localize( 'word-count', 'wordCountL10n', array(
'count' => __('Word count: %d'),
'l10n_print_after' => 'try{convertEntities(wordCountL10n);}catch(e){};'
@ -290,8 +341,10 @@ function wp_default_scripts( &$scripts ) {
));
$scripts->add( 'theme-preview', "/wp-admin/js/theme-preview$suffix.js", array( 'thickbox', 'jquery' ), '20090102' );
$scripts->add_data( 'theme-preview', 'group', 1 );
$scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'jquery-form', 'suggest' ), '20090102' );
$scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery-form', 'suggest' ), '20090102' );
$scripts->add_data( 'inline-edit-post', 'group', 1 );
$scripts->localize( 'inline-edit-post', 'inlineEditL10n', array(
'error' => __('Error while saving the changes.'),
'ntdeltitle' => __('Remove From Bulk Edit'),
@ -299,23 +352,31 @@ function wp_default_scripts( &$scripts ) {
'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
) );
$scripts->add( 'inline-edit-tax', "/wp-admin/js/inline-edit-tax$suffix.js", array( 'jquery', 'jquery-form' ), '20090109' );
$scripts->add( 'inline-edit-tax', "/wp-admin/js/inline-edit-tax$suffix.js", array( 'jquery-form' ), '20090109' );
$scripts->add_data( 'inline-edit-tax', 'group', 1 );
$scripts->localize( 'inline-edit-tax', 'inlineEditL10n', array(
'error' => __('Error while saving the changes.'),
'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
) );
$scripts->add( 'plugin-install', "/wp-admin/js/plugin-install$suffix.js", array( 'thickbox', 'jquery' ), '20090102' );
$scripts->add_data( 'plugin-install', 'group', 1 );
$scripts->localize( 'plugin-install', 'plugininstallL10n', array(
'plugin_information' => __('Plugin Information:'),
'l10n_print_after' => 'try{convertEntities(plugininstallL10n);}catch(e){};'
) );
$scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array('jquery'), '1.2' );
$scripts->add_data( 'farbtastic', 'group', 1 );
$scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox' ), '20090102' );
$scripts->add_data( 'dashboard', 'group', 1 );
$scripts->add( 'hoverIntent', "/wp-includes/js/hoverIntent$suffix.js", array('jquery'), '20090102' );
$scripts->add_data( 'hoverIntent', 'group', 1 );
$scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery-ui-draggable', 'jquery-ui-resizable' ), '20090113' );
$scripts->add_data( 'media', 'group', 1 );
}
}
@ -340,9 +401,12 @@ function wp_default_styles( &$styles ) {
// then it assigns $guess_url to wp_guess_url(). Strange format, but it works.
if ( ! $guessurl = site_url() )
$guessurl = wp_guess_url();
$styles->base_url = $guessurl;
$styles->content_url = WP_CONTENT_URL;
$styles->default_version = get_bloginfo( 'version' );
$styles->text_direction = 'rtl' == get_bloginfo( 'text_direction' ) ? 'rtl' : 'ltr';
$styles->default_dirs = array('/wp-admin/');
$rtl_styles = array( 'global', 'colors', 'dashboard', 'ie', 'install', 'login', 'media', 'theme-editor', 'upload', 'widgets', 'press-this', 'plugin-install', 'farbtastic' );
@ -384,10 +448,10 @@ function wp_default_styles( &$styles ) {
* @return array Reordered array, if needed.
*/
function wp_prototype_before_jquery( $js_array ) {
if ( false === $jquery = array_search( 'jquery', $js_array ) )
if ( false === $jquery = array_search( 'jquery', $js_array, true ) )
return $js_array;
if ( false === $prototype = array_search( 'prototype', $js_array ) )
if ( false === $prototype = array_search( 'prototype', $js_array, true ) )
return $js_array;
if ( $prototype < $jquery )
@ -461,6 +525,128 @@ function wp_style_loader_src( $src, $handle ) {
return $src;
}
/**
* Print the script queue in the HTML head.
*
* Postpones the scripts that were queued for the footer.
* wp_print_footer_scripts() has to be called in the footer to print these scripts.
*
* @since unknown
* @see wp_print_scripts()
*/
function wp_print_head_scripts() {
do_action( 'wp_print_scripts' );
global $wp_scripts, $concatenate_scripts, $compress_scripts;
if ( !is_a($wp_scripts, 'WP_Scripts') )
$wp_scripts = new WP_Scripts();
if ( ! isset($concatenate_scripts) )
script_concat_settings();
$wp_scripts->do_concat = $concatenate_scripts;
$wp_scripts->do_head_items();
_pring_scripts();
$wp_scripts->do_concat = false;
return $wp_scripts->done;
}
/**
* Print the scripts that were queued for the footer.
*
* @since unknown
*/
function wp_print_footer_scripts() {
global $wp_scripts, $concatenate_scripts;
if ( !is_a($wp_scripts, 'WP_Scripts') )
return array(); // No need to run if not instantiated.
if ( ! isset($concatenate_scripts) )
script_concat_settings();
$wp_scripts->do_concat = $concatenate_scripts;
$wp_scripts->do_footer_items();
_pring_scripts();
$wp_scripts->do_concat = false;
return $wp_scripts->done;
}
function _pring_scripts() {
global $wp_scripts, $compress_scripts;
$zip = $compress_scripts ? 1 : 0;
if ( !empty($wp_scripts->concat) ) {
if ( !empty($wp_scripts->print_code) ) {
echo "<script type='text/javascript'>\n";
echo "/* <![CDATA[ */\n";
echo $wp_scripts->print_code;
echo "/* ]]> */\n";
echo "</script>\n";
$wp_scripts->print_code = '';
}
$ver = md5($wp_scripts->concat_version);
$src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}&load=" . rtrim($wp_scripts->concat, ',') . "&ver=$ver";
echo "<script type='text/javascript' src='$src'></script>\n";
$wp_scripts->concat = $wp_scripts->concat_version = '';
}
if ( !empty($wp_scripts->print_html) ) {
echo $wp_scripts->print_html;
$wp_scripts->print_html = '';
}
}
function wp_print_admin_styles() {
global $wp_styles, $concatenate_scripts, $compress_scripts;
if ( !is_a($wp_styles, 'WP_Styles') )
$wp_styles = new WP_Styles();
if ( ! isset($concatenate_scripts) )
script_concat_settings();
$wp_styles->do_concat = $concatenate_scripts;
$zip = $compress_scripts ? 1 : 0;
$wp_styles->do_items(false);
if ( !empty($wp_styles->concat) ) {
$ver = md5($wp_styles->concat_version);
$rtl = 'rtl' === $wp_styles->text_direction ? 1 : 0;
$href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&rtl={$rtl}&load=" . rtrim($wp_styles->concat, ',') . "&ver=$ver";
echo "<link rel='stylesheet' href='$href' type='text/css' media='all' />\n";
$wp_styles->concat = $wp_styles->concat_version = '';
}
if ( !empty($wp_styles->print_html) ) {
echo $wp_styles->print_html;
$wp_styles->print_html = '';
}
$wp_styles->do_concat = false;
return $wp_styles->done;
}
function script_concat_settings() {
global $concatenate_scripts, $compress_scripts;
$concatenate_scripts = defined('CONCATENATE_SCRIPTS') ? CONCATENATE_SCRIPTS : true;
if ( $concatenate_scripts && -1 == get_option('concatenate_scripts') )
$concatenate_scripts = false;
$compress_scripts = defined('COMPRESS_SCRIPTS') ? COMPRESS_SCRIPTS : true;
if ( $compress_scripts && ! get_option('can_compress_scripts') )
$compress_scripts = false;
}
add_action( 'wp_default_scripts', 'wp_default_scripts' );
add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' );
add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );