diff --git a/wp-admin/admin-header.php b/wp-admin/admin-header.php index 8e5b731faf..599be92fe1 100644 --- a/wp-admin/admin-header.php +++ b/wp-admin/admin-header.php @@ -45,21 +45,24 @@ addLoadEvent = function(func) {if (typeof jQuery != "undefined") jQuery(document diff --git a/wp-includes/class.wp-dependencies.php b/wp-includes/class.wp-dependencies.php new file mode 100644 index 0000000000..1f7bb8db20 --- /dev/null +++ b/wp-includes/class.wp-dependencies.php @@ -0,0 +1,193 @@ +queue : (array) $handles; + $this->all_deps( $handles ); + + foreach( $this->to_do as $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 ); + } + $this->done[] = $handle; + } + } + + $this->to_do = array(); + return $this->done; + } + + function do_item( $handle ) { + return isset($this->registered[$handle]); + } + + /** + * Determines dependencies + * + * Recursively builds array of items to process taking dependencies into account. Does NOT catch infinite loops. + * + + * @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 ) { + 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]; + + if ( isset($this->to_do[$handle]) ) // Already grobbed it and its deps + continue; + + $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 ) ) + $keep_going = false; // Script requires deps which don't exist + + if ( !$keep_going ) { // Either script or its deps don't exist. + if ( $recursion ) + return false; // Abort this branch. + else + continue; // We're at the top level. Move on to the next one. + } + + $this->to_do[$handle] = true; + } + + if ( !$recursion ) // at the end + $this->to_do = array_keys( $this->to_do ); + return true; + } + + /** + * Adds item + * + * Adds the item only if no item of that name already exists + * + * @param string handle Script name + * @param string src Script url + * @param array deps (optional) Array of script names on which this script depends + * @param string ver (optional) Script version (used for cache busting) + * @return array Hierarchical array of dependencies + */ + function add( $handle, $src, $deps = array(), $ver = false, $args = null ) { + if ( isset($this->registered[$handle]) ) + return false; + $this->registered[$handle] = new _WP_Dependency( $handle, $src, $deps, $ver, $args ); + return true; + } + + /** + * Adds extra data + * + * Adds data only if script has already been added + * + * @param string handle Script name + * @param string data_name Name of object in which to store extra data + * @param array data Array of extra data + * @return bool success + */ + function add_data( $handle, $data_name, $data ) { + if ( !isset($this->registered[$handle]) ) + return false; + return $this->registered[$handle]->add_data( $data_name, $data ); + } + + function remove( $handles ) { + foreach ( (array) $handles as $handle ) + unset($this->registered[$handle]); + } + + function enqueue( $handles ) { + foreach ( (array) $handles as $handle ) { + $handle = explode('?', $handle); + if ( !in_array($handle[0], $this->queue) && isset($this->registered[$handle[0]]) ) { + $this->queue[] = $handle[0]; + if ( isset($handle[1]) ) + $this->args[$handle[0]] = $handle[1]; + } + } + } + + function dequeue( $handles ) { + foreach ( (array) $handles as $handle ) + unset( $this->queue[$handle] ); + } + + function query( $handle, $list = 'registered' ) { // registered, queue, done, to_do + switch ( $list ) : + case 'registered': + case 'scripts': // back compat + if ( isset($this->registered[$handle]) ) + return $this->registered[$handle]; + break; + case 'to_print': // back compat + case 'printed': // back compat + if ( 'to_print' == $list ) + $list = 'to_do'; + else + $list = 'printed'; + default: + if ( in_array($handle, $this->$list) ) + return true; + break; + endswitch; + return false; + } + +} + +class _WP_Dependency { + var $handle; + var $src; + var $deps = array(); + var $ver = false; + var $args = null; + + var $extra = array(); + + function _WP_Dependency() { + @list($this->handle, $this->src, $this->deps, $this->ver, $this->args) = func_get_args(); + if ( !is_array($this->deps) ) + $this->deps = array(); + if ( !$this->ver ) + $this->ver = false; + } + + function add_data( $name, $data ) { + if ( !is_scalar($name) ) + return false; + $this->extra[$name] = $data; + return true; + } +} diff --git a/wp-includes/class.wp-scripts.php b/wp-includes/class.wp-scripts.php new file mode 100644 index 0000000000..8d45f51511 --- /dev/null +++ b/wp-includes/class.wp-scripts.php @@ -0,0 +1,89 @@ +do_items( $handles ); + } + + function print_scripts_l10n( $handle ) { + 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 "\n"; + + return true; + } + + function do_item( $handle ) { + if ( !parent::do_item($handle) ) + return false; + + $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; + if ( isset($this->args[$handle]) ) + $ver .= '&' . $this->args[$handle]; + + $src = $this->registered[$handle]->src; + if ( !preg_match('|^https?://|', $src) ) { + $src = $this->base_url . $src; + } + + $src = add_query_arg('ver', $ver, $src); + $src = clean_url(apply_filters( 'script_loader_src', $src )); + + $this->print_scripts_l10n( $handle ); + + echo "\n"; + + return true; + } + + /** + * Localizes a script + * + * Localizes only if script has already been added + * + * @param string handle Script name + * @param string object_name Name of JS object to hold l10n info + * @param array l10n Array of JS var name => localized string + * @return bool Successful localization + */ + function localize( $handle, $object_name, $l10n ) { + if ( !$object_name || !$l10n ) + return false; + return $this->add_data( $handle, 'l10n', array( $object_name, $l10n ) ); + } + + 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; + } +} diff --git a/wp-includes/class.wp-styles.php b/wp-includes/class.wp-styles.php new file mode 100644 index 0000000000..45dc091103 --- /dev/null +++ b/wp-includes/class.wp-styles.php @@ -0,0 +1,49 @@ +registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; + if ( isset($this->args[$handle]) ) + $ver .= '&' . $this->args[$handle]; + + if ( isset($this->registered[$handle]->args) ) + $media = attribute_escape( $this->registered[$handle]->args ); + else + $media = 'all'; + + $src = $this->registered[$handle]->src; + if ( !preg_match('|^https?://|', $src) ) { + $src = $this->base_url . $src; + } + + $src = add_query_arg('ver', $ver, $src); + $src = clean_url(apply_filters( 'style_loader_src', $src )); + + echo "\n"; + + // Could do something with $this->registered[$handle]->extra here to print out extra CSS rules +// echo "\n"; + + return true; + } + + function all_deps( $handles, $recursion = false ) { + $r = parent::all_deps( $handles, $recursion ); + if ( !$recursion ) + $this->to_do = apply_filters( 'print_styles_array', $this->to_do ); + return $r; + } +} diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index d858b20d4e..fb6d6ed1eb 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -175,6 +175,7 @@ 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('init', 'smilies_init', 5); add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 ); add_action( 'shutdown', 'wp_ob_end_flush_all', 1); diff --git a/wp-includes/functions.wp-scripts.php b/wp-includes/functions.wp-scripts.php new file mode 100644 index 0000000000..87995a4b9a --- /dev/null +++ b/wp-includes/functions.wp-scripts.php @@ -0,0 +1,77 @@ +do_items( $handles ); +} + +function wp_register_script( $handle, $src, $deps = array(), $ver = false ) { + global $wp_scripts; + if ( !is_a($wp_scripts, 'WP_Scripts') ) + $wp_scripts = new WP_Scripts(); + + $wp_scripts->add( $handle, $src, $deps, $ver ); +} + +/** + * Localizes a script + * + * Localizes only if script has already been added + * + * @see WP_Script::localize() + */ +function wp_localize_script( $handle, $object_name, $l10n ) { + global $wp_scripts; + if ( !is_a($wp_scripts, 'WP_Scripts') ) + return false; + + return $wp_scripts->localize( $handle, $object_name, $l10n ); +} + +function wp_deregister_script( $handle ) { + global $wp_scripts; + if ( !is_a($wp_scripts, 'WP_Scripts') ) + $wp_scripts = new WP_Scripts(); + + $wp_scripts->remove( $handle ); +} + +/** + * Equeues script + * + * Registers the script if src provided (does NOT overwrite) and enqueues. + * + * @see WP_Script::add(), WP_Script::enqueue() +*/ +function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false ) { + global $wp_scripts; + if ( !is_a($wp_scripts, 'WP_Scripts') ) + $wp_scripts = new WP_Scripts(); + + if ( $src ) { + $_handle = explode('?', $handle); + $wp_scripts->add( $_handle[0], $src, $deps, $ver ); + } + $wp_scripts->enqueue( $handle ); +} diff --git a/wp-includes/functions.wp-styles.php b/wp-includes/functions.wp-styles.php new file mode 100644 index 0000000000..bf3dc939a1 --- /dev/null +++ b/wp-includes/functions.wp-styles.php @@ -0,0 +1,45 @@ +do_items( $handles ); +} + +function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = false ) { + global $wp_styles; + if ( !is_a($wp_styles, 'WP_Styles') ) + $wp_styles = new WP_Styles(); + + $wp_styles->add( $handle, $src, $deps, $ver, $media ); +} + +function wp_deregister_style( $handle ) { + global $wp_styles; + if ( !is_a($wp_styles, 'WP_Styles') ) + $wp_styles = new WP_Styles(); + + $wp_styles->remove( $handle ); +} + +function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = false ) { + global $wp_styles; + if ( !is_a($wp_styles, 'WP_Styles') ) + $wp_styles = new WP_Styles(); + + if ( $src ) { + $_handle = explode('?', $handle); + $wp_styles->add( $_handle[0], $src, $deps, $ver, $media ); + } + $wp_styles->enqueue( $handle ); +} diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 49d3338c27..4102828cac 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -1,489 +1,212 @@ default_scripts(); - } +require( ABSPATH . WPINC . '/class.wp-dependencies.php' ); +require( ABSPATH . WPINC . '/class.wp-scripts.php' ); +require( ABSPATH . WPINC . '/functions.wp-scripts.php' ); +require( ABSPATH . WPINC . '/class.wp-styles.php' ); +require( ABSPATH . WPINC . '/functions.wp-styles.php' ); - function default_scripts() { - $this->add( 'common', '/wp-admin/js/common.js', array('jquery'), '20080318' ); - $this->add( 'sack', '/wp-includes/js/tw-sack.js', false, '1.6.1' ); +function wp_default_scripts( $scripts ) { + $scripts->base_url = get_option( 'siteurl' ); + $scripts->default_version = get_bloginfo( 'version' ); - $this->add( 'quicktags', '/wp-includes/js/quicktags.js', false, '3958' ); - $this->localize( 'quicktags', 'quicktagsL10n', array( - 'quickLinks' => __('(Quick Links)'), - 'wordLookup' => __('Enter a word to look up:'), - 'dictionaryLookup' => attribute_escape(__('Dictionary lookup')), - 'lookup' => attribute_escape(__('lookup')), - 'closeAllOpenTags' => attribute_escape(__('Close all open tags')), - 'closeTags' => attribute_escape(__('close tags')), - 'enterURL' => __('Enter the URL'), - 'enterImageURL' => __('Enter the URL of the image'), - 'enterImageDescription' => __('Enter a description of the image') + $scripts->add( 'common', '/wp-admin/js/common.js', array('jquery'), '20080318' ); + $scripts->add( 'sack', '/wp-includes/js/tw-sack.js', false, '1.6.1' ); + + $scripts->add( 'quicktags', '/wp-includes/js/quicktags.js', false, '3958' ); + $scripts->localize( 'quicktags', 'quicktagsL10n', array( + 'quickLinks' => __('(Quick Links)'), + 'wordLookup' => __('Enter a word to look up:'), + 'dictionaryLookup' => attribute_escape(__('Dictionary lookup')), + 'lookup' => attribute_escape(__('lookup')), + 'closeAllOpenTags' => attribute_escape(__('Close all open tags')), + 'closeTags' => attribute_escape(__('close tags')), + 'enterURL' => __('Enter the URL'), + 'enterImageURL' => __('Enter the URL of the image'), + 'enterImageDescription' => __('Enter a description of the image') + ) ); + + $scripts->add( 'colorpicker', '/wp-includes/js/colorpicker.js', array('prototype'), '3517' ); + + // Let a plugin replace the visual editor + $visual_editor = apply_filters('visual_editor', array('tiny_mce')); + $scripts->add( 'editor', false, $visual_editor, '20080321' ); + + $scripts->add( 'editor_functions', '/wp-admin/js/editor.js', false, '20080325' ); + + // Modify this version when tinyMCE plugins are changed. + $mce_version = apply_filters('tiny_mce_version', '20080423'); + $scripts->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('editor_functions'), $mce_version ); + + $scripts->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6'); + + $scripts->add( 'wp-ajax-response', '/wp-includes/js/wp-ajax-response.js', array('jquery'), '20080316' ); + $scripts->localize( 'wp-ajax-response', 'wpAjax', array( + 'noPerm' => __('You do not have permission to do that.'), + 'broken' => __('An unidentified error has occurred.') + ) ); + + $scripts->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080508' ); + + $scripts->add( 'wp-ajax', '/wp-includes/js/wp-ajax.js', array('prototype'), '20070306'); + $scripts->localize( 'wp-ajax', 'WPAjaxL10n', array( + 'defaultUrl' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', + 'permText' => __("You do not have permission to do that."), + 'strangeText' => __("Something strange happened. Try refreshing the page."), + 'whoaText' => __("Slow down, I'm still sending your data!") + ) ); + + $scripts->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20080411' ); + $scripts->localize( 'wp-lists', 'wpListL10n', array( + 'url' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php' + ) ); + + $scripts->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/scriptaculous.js', array('prototype'), '1.8.0'); + $scripts->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.8.0'); + $scripts->add( 'scriptaculous-dragdrop', '/wp-includes/js/scriptaculous/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.8.0'); + $scripts->add( 'scriptaculous-effects', '/wp-includes/js/scriptaculous/effects.js', array('scriptaculous-root'), '1.8.0'); + $scripts->add( 'scriptaculous-slider', '/wp-includes/js/scriptaculous/slider.js', array('scriptaculous-effects'), '1.8.0'); + $scripts->add( 'scriptaculous-sound', '/wp-includes/js/scriptaculous/sound.js', array( 'scriptaculous-root' ), '1.8.0' ); + $scripts->add( 'scriptaculous-controls', '/wp-includes/js/scriptaculous/controls.js', array('scriptaculous-root'), '1.8.0'); + $scripts->add( 'scriptaculous', '', array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls'), '1.8.0'); + + $scripts->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'), '20070118'); + + $scripts->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.2.3'); + $scripts->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '2.02'); + $scripts->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.js', array('jquery'), '2.0-4561'); + $scripts->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2' ); + $scripts->add( 'dimensions', '/wp-includes/js/jquery/jquery.dimensions.min.js', array('jquery'), '1.1.2'); + $scripts->add( 'suggest', '/wp-includes/js/jquery/suggest.js', array('dimensions'), '1.1'); + $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20'); + $scripts->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array('jquery'), '3.1-20080430'); + $scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.0.2-20080430'); + $scripts->add( 'swfupload-degrade', '/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', array('swfupload'), '2.0.2'); + $scripts->localize( 'swfupload-degrade', 'uploadDegradeOptions', array( + 'is_lighttpd_before_150' => is_lighttpd_before_150(), + ) ); + $scripts->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2.0.2'); + $scripts->add( 'swfupload-handlers', '/wp-includes/js/swfupload/handlers.js', array('swfupload'), '2.0.2-20080407'); + // these error messages came from the sample swfupload js, they might need changing. + $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', array( + 'queue_limit_exceeded' => __('You have attempted to queue too many files.'), + 'file_exceeds_size_limit' => sprintf(__('This file is too big. Your php.ini upload_max_filesize is %s.'), @ini_get('upload_max_filesize')), + 'zero_byte_file' => __('This file is empty. Please try another.'), + 'invalid_filetype' => __('This file type is not allowed. Please try another.'), + 'default_error' => __('An error occurred in the upload. Please try again later.'), + 'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'), + 'upload_limit_exceeded' => __('You may only upload 1 file.'), + 'http_error' => __('HTTP error.'), + 'upload_failed' => __('Upload failed.'), + 'io_error' => __('IO error.'), + 'security_error' => __('Security error.'), + 'file_cancelled' => __('File cancelled.'), + 'upload_stopped' => __('Upload stopped.'), + 'dismiss' => __('Dismiss'), + 'crunching' => __('Crunching…'), + 'deleted' => __('Deleted'), + ) ); + + $scripts->add( 'jquery-ui-core', '/wp-includes/js/jquery/ui.core.js', array('jquery'), '1.5b4' ); + $scripts->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery-ui-core'), '1.5b4' ); + + if ( is_admin() ) { + $scripts->add( 'ajaxcat', '/wp-admin/js/cat.js', array( 'wp-lists' ), '20071101' ); + $scripts->localize( 'ajaxcat', 'catL10n', array( + 'add' => attribute_escape(__('Add')), + 'how' => __('Separate multiple categories with commas.') ) ); - - $this->add( 'colorpicker', '/wp-includes/js/colorpicker.js', array('prototype'), '3517' ); - - // Let a plugin replace the visual editor - $visual_editor = apply_filters('visual_editor', array('tiny_mce')); - $this->add( 'editor', false, $visual_editor, '20080321' ); - - $this->add( 'editor_functions', '/wp-admin/js/editor.js', false, '20080325' ); - - // Modify this version when tinyMCE plugins are changed. - $mce_version = apply_filters('tiny_mce_version', '20080423'); - $this->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('editor_functions'), $mce_version ); - - $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6'); - - $this->add( 'wp-ajax-response', '/wp-includes/js/wp-ajax-response.js', array('jquery'), '20080316' ); - $this->localize( 'wp-ajax-response', 'wpAjax', array( - 'noPerm' => __('You do not have permission to do that.'), - 'broken' => __('An unidentified error has occurred.') + $scripts->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' ); + $scripts->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists'), '20071031' ); + $scripts->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' ); + $scripts->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20070405' ); + $scripts->localize( 'password-strength-meter', 'pwsL10n', array( + 'short' => __('Too short'), + 'bad' => __('Bad'), + 'good' => __('Good'), + 'strong' => __('Strong') ) ); - - $this->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20080508' ); - - $this->add( 'wp-ajax', '/wp-includes/js/wp-ajax.js', array('prototype'), '20070306'); - $this->localize( 'wp-ajax', 'WPAjaxL10n', array( - 'defaultUrl' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', - 'permText' => __("You do not have permission to do that."), - 'strangeText' => __("Something strange happened. Try refreshing the page."), - 'whoaText' => __("Slow down, I'm still sending your data!") + $scripts->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists'), '20080311' ); + $scripts->localize( 'admin-comments', 'adminCommentsL10n', array( + 'pending' => __('%i% pending') // must look like: "# blah blah" ) ); - - $this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20080411' ); - $this->localize( 'wp-lists', 'wpListL10n', array( - 'url' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php' + $scripts->add( 'admin-users', '/wp-admin/js/users.js', array('wp-lists'), '20070823' ); + $scripts->add( 'admin-forms', '/wp-admin/js/forms.js', false, '20080401'); + $scripts->add( 'xfn', '/wp-admin/js/xfn.js', false, '3517' ); + $scripts->add( 'upload', '/wp-admin/js/upload.js', array('jquery'), '20070518' ); + $scripts->add( 'postbox', '/wp-admin/js/postbox.js', array('jquery'), '20080128' ); + $scripts->localize( 'postbox', 'postboxL10n', array( + 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', ) ); - - $this->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/scriptaculous.js', array('prototype'), '1.8.0'); - $this->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.8.0'); - $this->add( 'scriptaculous-dragdrop', '/wp-includes/js/scriptaculous/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.8.0'); - $this->add( 'scriptaculous-effects', '/wp-includes/js/scriptaculous/effects.js', array('scriptaculous-root'), '1.8.0'); - $this->add( 'scriptaculous-slider', '/wp-includes/js/scriptaculous/slider.js', array('scriptaculous-effects'), '1.8.0'); - $this->add( 'scriptaculous-sound', '/wp-includes/js/scriptaculous/sound.js', array( 'scriptaculous-root' ), '1.8.0' ); - $this->add( 'scriptaculous-controls', '/wp-includes/js/scriptaculous/controls.js', array('scriptaculous-root'), '1.8.0'); - $this->add( 'scriptaculous', '', array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls'), '1.8.0'); - - $this->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'), '20070118'); - - $this->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.2.3'); - $this->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '2.02'); - $this->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.js', array('jquery'), '2.0-4561'); - $this->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2' ); - $this->add( 'dimensions', '/wp-includes/js/jquery/jquery.dimensions.min.js', array('jquery'), '1.1.2'); - $this->add( 'suggest', '/wp-includes/js/jquery/suggest.js', array('dimensions'), '1.1'); - $this->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20'); - $this->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array('jquery'), '3.1-20080430'); - $this->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.0.2-20080430'); - $this->add( 'swfupload-degrade', '/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', array('swfupload'), '2.0.2'); - $this->localize( 'swfupload-degrade', 'uploadDegradeOptions', array( - 'is_lighttpd_before_150' => is_lighttpd_before_150(), + $scripts->add( 'slug', '/wp-admin/js/slug.js', array('jquery'), '20080208' ); + $scripts->localize( 'slug', 'slugL10n', array( + 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', + 'save' => __('Save'), + 'cancel' => __('Cancel'), ) ); - $this->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2.0.2'); - $this->add( 'swfupload-handlers', '/wp-includes/js/swfupload/handlers.js', array('swfupload'), '2.0.2-20080407'); - // these error messages came from the sample swfupload js, they might need changing. - $this->localize( 'swfupload-handlers', 'swfuploadL10n', array( - 'queue_limit_exceeded' => __('You have attempted to queue too many files.'), - 'file_exceeds_size_limit' => sprintf(__('This file is too big. Your php.ini upload_max_filesize is %s.'), @ini_get('upload_max_filesize')), - 'zero_byte_file' => __('This file is empty. Please try another.'), - 'invalid_filetype' => __('This file type is not allowed. Please try another.'), - 'default_error' => __('An error occurred in the upload. Please try again later.'), - 'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'), - 'upload_limit_exceeded' => __('You may only upload 1 file.'), - 'http_error' => __('HTTP error.'), - 'upload_failed' => __('Upload failed.'), - 'io_error' => __('IO error.'), - 'security_error' => __('Security error.'), - 'file_cancelled' => __('File cancelled.'), - 'upload_stopped' => __('Upload stopped.'), - 'dismiss' => __('Dismiss'), - 'crunching' => __('Crunching…'), - 'deleted' => __('Deleted'), + $scripts->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080519' ); + $scripts->localize( 'post', 'postL10n', array( + 'tagsUsed' => __('Tags used on this post:'), + 'add' => attribute_escape(__('Add')), + 'addTag' => attribute_escape(__('Add new tag')), + 'separate' => __('Separate tags with commas'), + 'cancel' => __('Cancel'), + 'edit' => __('Edit'), ) ); + $scripts->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox'), '20080318' ); + $scripts->localize( 'page', 'postL10n', array( + 'cancel' => __('Cancel'), + 'edit' => __('Edit'), + ) ); + $scripts->add( 'link', '/wp-admin/js/link.js', array('jquery-ui-tabs', 'wp-lists', 'postbox'), '20080131' ); + $scripts->add( 'comment', '/wp-admin/js/comment.js', array('postbox'), '20080219' ); + $scripts->localize( 'comment', 'commentL10n', array( + 'cancel' => __('Cancel'), + 'edit' => __('Edit'), + ) ); + $scripts->add( 'media-upload', '/wp-admin/js/media-upload.js', false, '20080430' ); + $scripts->localize( 'upload', 'uploadL10n', array( + 'browseTitle' => attribute_escape(__('Browse your files')), + 'back' => __('« Back'), + 'directTitle' => attribute_escape(__('Direct link to file')), + 'edit' => __('Edit'), + 'thumb' => __('Thumbnail'), + 'full' => __('Full size'), + 'icon' => __('Icon'), + 'title' => __('Title'), + 'show' => __('Show:'), + 'link' => __('Link to:'), + 'file' => __('File'), + 'page' => __('Page'), + 'none' => __('None'), + 'editorText' => attribute_escape(__('Send to editor »')), + 'insert' => __('Insert'), + 'urlText' => __('URL'), + 'desc' => __('Description'), + 'deleteText' => attribute_escape(__('Delete File')), + 'saveText' => attribute_escape(__('Save »')), + 'confirmText' => __("Are you sure you want to delete the file '%title%'?\nClick ok to delete or cancel to go back.") + ) ); + $scripts->add( 'admin-widgets', '/wp-admin/js/widgets.js', array( 'interface' ), '20080503' ); + $scripts->localize( 'admin-widgets', 'widgetsL10n', array( + 'add' => __('Add'), + 'edit' => __('Edit'), + 'cancel' => __('Cancel'), + )); - $this->add( 'jquery-ui-core', '/wp-includes/js/jquery/ui.core.js', array('jquery'), '1.5b4' ); - $this->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery-ui-core'), '1.5b4' ); - - if ( is_admin() ) { - $this->add( 'ajaxcat', '/wp-admin/js/cat.js', array( 'wp-lists' ), '20071101' ); - $this->localize( 'ajaxcat', 'catL10n', array( - 'add' => attribute_escape(__('Add')), - 'how' => __('Separate multiple categories with commas.') - ) ); - $this->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' ); - $this->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists'), '20071031' ); - $this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' ); - $this->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20070405' ); - $this->localize( 'password-strength-meter', 'pwsL10n', array( - 'short' => __('Too short'), - 'bad' => __('Bad'), - 'good' => __('Good'), - 'strong' => __('Strong') - ) ); - $this->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists'), '20080311' ); - $this->localize( 'admin-comments', 'adminCommentsL10n', array( - 'pending' => __('%i% pending') // must look like: "# blah blah" - ) ); - $this->add( 'admin-users', '/wp-admin/js/users.js', array('wp-lists'), '20070823' ); - $this->add( 'admin-forms', '/wp-admin/js/forms.js', false, '20080401'); - $this->add( 'xfn', '/wp-admin/js/xfn.js', false, '3517' ); - $this->add( 'upload', '/wp-admin/js/upload.js', array('jquery'), '20070518' ); - $this->add( 'postbox', '/wp-admin/js/postbox.js', array('jquery'), '20080128' ); - $this->localize( 'postbox', 'postboxL10n', array( - 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', - ) ); - $this->add( 'slug', '/wp-admin/js/slug.js', array('jquery'), '20080208' ); - $this->localize( 'slug', 'slugL10n', array( - 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', - 'save' => __('Save'), - 'cancel' => __('Cancel'), - ) ); - $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080519' ); - $this->localize( 'post', 'postL10n', array( - 'tagsUsed' => __('Tags used on this post:'), - 'add' => attribute_escape(__('Add')), - 'addTag' => attribute_escape(__('Add new tag')), - 'separate' => __('Separate tags with commas'), - 'cancel' => __('Cancel'), - 'edit' => __('Edit'), - ) ); - $this->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox'), '20080318' ); - $this->localize( 'page', 'postL10n', array( - 'cancel' => __('Cancel'), - 'edit' => __('Edit'), - ) ); - $this->add( 'link', '/wp-admin/js/link.js', array('jquery-ui-tabs', 'wp-lists', 'postbox'), '20080131' ); - $this->add( 'comment', '/wp-admin/js/comment.js', array('postbox'), '20080219' ); - $this->localize( 'comment', 'commentL10n', array( - 'cancel' => __('Cancel'), - 'edit' => __('Edit'), - ) ); - $this->add( 'media-upload', '/wp-admin/js/media-upload.js', false, '20080430' ); - $this->localize( 'upload', 'uploadL10n', array( - 'browseTitle' => attribute_escape(__('Browse your files')), - 'back' => __('« Back'), - 'directTitle' => attribute_escape(__('Direct link to file')), - 'edit' => __('Edit'), - 'thumb' => __('Thumbnail'), - 'full' => __('Full size'), - 'icon' => __('Icon'), - 'title' => __('Title'), - 'show' => __('Show:'), - 'link' => __('Link to:'), - 'file' => __('File'), - 'page' => __('Page'), - 'none' => __('None'), - 'editorText' => attribute_escape(__('Send to editor »')), - 'insert' => __('Insert'), - 'urlText' => __('URL'), - 'desc' => __('Description'), - 'deleteText' => attribute_escape(__('Delete File')), - 'saveText' => attribute_escape(__('Save »')), - 'confirmText' => __("Are you sure you want to delete the file '%title%'?\nClick ok to delete or cancel to go back.") - ) ); - $this->add( 'admin-widgets', '/wp-admin/js/widgets.js', array( 'interface' ), '20080503' ); - $this->localize( 'admin-widgets', 'widgetsL10n', array( - 'add' => __('Add'), - 'edit' => __('Edit'), - 'cancel' => __('Cancel'), - )); - - $this->add( 'word-count', '/wp-admin/js/word-count.js', array( 'jquery' ), '20080423' ); - $this->localize( 'word-count', 'wordCountL10n', array( - 'count' => __('Word count: %d') - )); - - $this->add( 'wp-gears', '/wp-admin/js/wp-gears.js', false, '20080511' ); - $this->localize( 'wp-gears', 'wpGearsL10n', array( - 'updateCompleted' => __('Update completed.'), - 'error' => __('Error:') - )); - - $this->add( 'theme-preview', '/wp-admin/js/theme-preview.js', array( 'thickbox', 'dimensions' ), '20080515' ); - } + $scripts->add( 'word-count', '/wp-admin/js/word-count.js', array( 'jquery' ), '20080423' ); + $scripts->localize( 'word-count', 'wordCountL10n', array( + 'count' => __('Word count: %d') + )); + + $scripts->add( 'wp-gears', '/wp-admin/js/wp-gears.js', false, '20080511' ); + $scripts->localize( 'wp-gears', 'wpGearsL10n', array( + 'updateCompleted' => __('Update completed.'), + 'error' => __('Error:') + )); + + $scripts->add( 'theme-preview', '/wp-admin/js/theme-preview.js', array( 'thickbox', 'dimensions' ), '20080515' ); } - - /** - * Prints script tags - * - * 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. - * @return array Scripts that have been printed - */ - function print_scripts( $handles = false ) { - global $wp_db_version; - - // 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 ); - - $to_print = apply_filters( 'print_scripts_array', array_keys($this->to_print) ); - - foreach( $to_print as $handle ) { - if ( !in_array($handle, $this->printed) && isset($this->scripts[$handle]) ) { - if ( $this->scripts[$handle]->src ) { // Else it defines a group. - $ver = $this->scripts[$handle]->ver ? $this->scripts[$handle]->ver : $wp_db_version; - if ( isset($this->args[$handle]) ) - $ver .= '&' . $this->args[$handle]; - $src = 0 === strpos($this->scripts[$handle]->src, 'http://') ? $this->scripts[$handle]->src : get_option( 'siteurl' ) . $this->scripts[$handle]->src; - $src = $this->scripts[$handle]->src; - - if (!preg_match('|^https?://|', $src)) { - $src = get_option('siteurl') . $src; - } - - $src = add_query_arg('ver', $ver, $src); - $src = clean_url(apply_filters( 'script_loader_src', $src )); - $this->print_scripts_l10n( $handle ); - echo "\n"; - } - $this->printed[] = $handle; - } - } - - $this->to_print = array(); - return $this->printed; - } - - function print_scripts_l10n( $handle ) { - if ( empty($this->scripts[$handle]->l10n_object) || empty($this->scripts[$handle]->l10n) || !is_array($this->scripts[$handle]->l10n) ) - return; - - $object_name = $this->scripts[$handle]->l10n_object; - - echo "\n"; - } - - /** - * Determines dependencies of scripts - * - * Recursively builds array of scripts to print taking dependencies into account. Does NOT catch infinite loops. - * - * @param mixed handles Accepts (string) script name or (array of strings) script names - * @param bool recursion Used internally when function calls itself - */ - function all_deps( $handles, $recursion = 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]; - - if ( isset($this->to_print[$handle]) ) // Already grobbed it and its deps - continue; - - $keep_going = true; - if ( !isset($this->scripts[$handle]) ) - $keep_going = false; // Script doesn't exist - elseif ( $this->scripts[$handle]->deps && array_diff($this->scripts[$handle]->deps, array_keys($this->scripts)) ) - $keep_going = false; // Script requires deps which don't exist (not a necessary check. efficiency?) - elseif ( $this->scripts[$handle]->deps && !$this->all_deps( $this->scripts[$handle]->deps, true ) ) - $keep_going = false; // Script requires deps which don't exist - - if ( !$keep_going ) { // Either script or its deps don't exist. - if ( $recursion ) - return false; // Abort this branch. - else - continue; // We're at the top level. Move on to the next one. - } - - $this->to_print[$handle] = true; - } - - return true; - } - - /** - * Adds script - * - * Adds the script only if no script of that name already exists - * - * @param string handle Script name - * @param string src Script url - * @param array deps (optional) Array of script names on which this script depends - * @param string ver (optional) Script version (used for cache busting) - * @return array Hierarchical array of dependencies - */ - function add( $handle, $src, $deps = array(), $ver = false ) { - if ( isset($this->scripts[$handle]) ) - return false; - $this->scripts[$handle] = new _WP_Script( $handle, $src, $deps, $ver ); - return true; - } - - /** - * Localizes a script - * - * Localizes only if script has already been added - * - * @param string handle Script name - * @param string object_name Name of JS object to hold l10n info - * @param array l10n Array of JS var name => localized string - * @return bool Successful localization - */ - function localize( $handle, $object_name, $l10n ) { - if ( !isset($this->scripts[$handle]) ) - return false; - return $this->scripts[$handle]->localize( $object_name, $l10n ); - } - - function remove( $handles ) { - foreach ( (array) $handles as $handle ) - unset($this->scripts[$handle]); - } - - function enqueue( $handles ) { - foreach ( (array) $handles as $handle ) { - $handle = explode('?', $handle); - if ( !in_array($handle[0], $this->queue) && isset($this->scripts[$handle[0]]) ) { - $this->queue[] = $handle[0]; - if ( isset($handle[1]) ) - $this->args[$handle[0]] = $handle[1]; - } - } - } - - function dequeue( $handles ) { - foreach ( (array) $handles as $handle ) - unset( $this->queue[$handle] ); - } - - function query( $handle, $list = 'scripts' ) { // scripts, queue, or printed - switch ( $list ) : - case 'scripts': - if ( isset($this->scripts[$handle]) ) - return $this->scripts[$handle]; - break; - default: - if ( in_array($handle, $this->$list) ) - return true; - break; - endswitch; - return false; - } - -} - -class _WP_Script { - var $handle; - var $src; - var $deps = array(); - var $ver = false; - var $l10n_object = ''; - var $l10n = array(); - - function _WP_Script() { - @list($this->handle, $this->src, $this->deps, $this->ver) = func_get_args(); - if ( !is_array($this->deps) ) - $this->deps = array(); - if ( !$this->ver ) - $this->ver = false; - } - - function localize( $object_name, $l10n ) { - if ( !$object_name || !is_array($l10n) ) - return false; - $this->l10n_object = $object_name; - $this->l10n = $l10n; - return true; - } -} - -/** - * Prints script tags in document head - * - * Called by admin-header.php and by wp_head hook. Since it is called by wp_head on every page load, - * the function does not instantiate the WP_Scripts object unless script names are explicitly passed. - * Does make use of already instantiated $wp_scripts if present. - * Use provided wp_print_scripts hook to register/enqueue new scripts. - * - * @see WP_Scripts::print_scripts() - */ -function wp_print_scripts( $handles = false ) { - do_action( 'wp_print_scripts' ); - if ( '' === $handles ) // for wp_head - $handles = false; - - global $wp_scripts; - if ( !is_a($wp_scripts, 'WP_Scripts') ) { - if ( !$handles ) - return array(); // No need to instantiate if nothing's there. - else - $wp_scripts = new WP_Scripts(); - } - - return $wp_scripts->print_scripts( $handles ); -} - -function wp_register_script( $handle, $src, $deps = array(), $ver = false ) { - global $wp_scripts; - if ( !is_a($wp_scripts, 'WP_Scripts') ) - $wp_scripts = new WP_Scripts(); - - $wp_scripts->add( $handle, $src, $deps, $ver ); -} - -/** - * Localizes a script - * - * Localizes only if script has already been added - * - * @see WP_Script::localize() - */ -function wp_localize_script( $handle, $object_name, $l10n ) { - global $wp_scripts; - if ( !is_a($wp_scripts, 'WP_Scripts') ) - return false; - - return $wp_scripts->localize( $handle, $object_name, $l10n ); -} - -function wp_deregister_script( $handle ) { - global $wp_scripts; - if ( !is_a($wp_scripts, 'WP_Scripts') ) - $wp_scripts = new WP_Scripts(); - - $wp_scripts->remove( $handle ); -} - -/** - * Equeues script - * - * Registers the script if src provided (does NOT overwrite) and enqueues. - * - * @see WP_Script::add(), WP_Script::enqueue() -*/ -function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false ) { - global $wp_scripts; - if ( !is_a($wp_scripts, 'WP_Scripts') ) - $wp_scripts = new WP_Scripts(); - - if ( $src ) { - $_handle = explode('?', $handle); - $wp_scripts->add( $_handle[0], $src, $deps, $ver ); - } - $wp_scripts->enqueue( $handle ); } function wp_prototype_before_jquery( $js_array ) { @@ -515,7 +238,6 @@ function wp_just_in_time_script_localization() { ) ); } +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' ); - -?>