Changeset 10357 for trunk/wp-includes/class.wp-scripts.php
- Timestamp:
- 01/14/2009 02:18:51 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class.wp-scripts.php
r10135 r10357 19 19 class WP_Scripts extends WP_Dependencies { 20 20 var $base_url; // Full URL with trailing slash 21 var $content_url; 21 22 var $default_version; 23 var $in_footer = array(); 24 var $concat = ''; 25 var $concat_version = ''; 26 var $do_concat = false; 27 var $print_html = ''; 28 var $print_code = ''; 29 var $default_dirs; 22 30 23 31 function __construct() { … … 31 39 * 32 40 * @param mixed handles (optional) Scripts to be printed. (void) prints queue, (string) prints that script, (array of strings) prints those scripts. 41 * @param int group (optional) If scripts were queued in groups prints this group number. 33 42 * @return array Scripts that have been printed 34 43 */ 35 function print_scripts( $handles = false ) {36 return $this->do_items( $handles );44 function print_scripts( $handles = false, $group = false ) { 45 return $this->do_items( $handles, $group ); 37 46 } 38 47 39 function print_scripts_l10n( $handle ) {48 function print_scripts_l10n( $handle, $echo = true ) { 40 49 if ( empty($this->registered[$handle]->extra['l10n']) || empty($this->registered[$handle]->extra['l10n'][0]) || !is_array($this->registered[$handle]->extra['l10n'][1]) ) 41 50 return false; … … 43 52 $object_name = $this->registered[$handle]->extra['l10n'][0]; 44 53 45 echo "<script type='text/javascript'>\n"; 46 echo "/* <![CDATA[ */\n"; 47 echo "\t$object_name = {\n"; 54 $data = "var $object_name = {\n"; 48 55 $eol = ''; 49 56 foreach ( $this->registered[$handle]->extra['l10n'][1] as $var => $val ) { … … 52 59 continue; 53 60 } 54 echo "$eol\t\t$var: \"" . js_escape( $val ) . '"';61 $data .= "$eol\t$var: \"" . js_escape( $val ) . '"'; 55 62 $eol = ",\n"; 56 63 } 57 echo "\n\t}\n"; 58 echo isset($after) ? "\t$after\n" : ''; 59 echo "/* ]]> */\n"; 60 echo "</script>\n"; 64 $data .= "\n};\n"; 65 $data .= isset($after) ? "$after\n" : ''; 61 66 62 return true; 67 if ( $echo ) { 68 echo "<script type='text/javascript'>\n"; 69 echo "/* <![CDATA[ */\n"; 70 echo $data; 71 echo "/* ]]> */\n"; 72 echo "</script>\n"; 73 return true; 74 } else { 75 return $data; 76 } 63 77 } 64 78 65 function do_item( $handle ) {79 function do_item( $handle, $group = false ) { 66 80 if ( !parent::do_item($handle) ) 67 81 return false; 82 83 if ( 0 === $group && $this->groups[$handle] > 0 ) { 84 $this->in_footer[] = $handle; 85 return false; 86 } 87 88 if ( false === $group && in_array($handle, $this->in_footer, true) ) 89 $this->in_footer = array_diff( $this->in_footer, (array) $handle ); 68 90 69 91 $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; … … 72 94 73 95 $src = $this->registered[$handle]->src; 74 if ( !preg_match('|^https?://|', $src) && !preg_match('|^' . preg_quote(WP_CONTENT_URL) . '|', $src) ) { 96 97 if ( $this->do_concat ) { 98 $srce = apply_filters( 'script_loader_src', $src, $handle, $echo ); 99 if ( $this->in_default_dir($srce) ) { 100 $this->print_code .= $this->print_scripts_l10n( $handle, false ); 101 $this->concat .= $handle . ','; 102 $this->concat_version .= $ver; 103 return true; 104 } 105 } 106 107 $this->print_scripts_l10n( $handle ); 108 if ( !preg_match('|^https?://|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) { 75 109 $src = $this->base_url . $src; 76 110 } 77 111 78 112 $src = add_query_arg('ver', $ver, $src); 79 $src = clean_url(apply_filters( 'script_loader_src', $src, $handle ));113 $src = clean_url(apply_filters( 'script_loader_src', $src, $handle, $echo )); 80 114 81 $this->print_scripts_l10n( $handle ); 82 83 echo "<script type='text/javascript' src='$src'></script>\n"; 115 if ( $this->do_concat ) 116 $this->print_html .= "<script type='text/javascript' src='$src'></script>\n"; 117 else 118 echo "<script type='text/javascript' src='$src'></script>\n"; 84 119 85 120 return true; … … 102 137 } 103 138 139 function set_group( $handle, $recursion, $group = false ) { 140 $grp = isset($this->registered[$handle]->extra['group']) ? (int) $this->registered[$handle]->extra['group'] : 0; 141 if ( false !== $group && $grp > $group ) 142 $grp = $group; 143 144 parent::set_group( $handle, $recursion, $grp ); 145 } 146 104 147 function all_deps( $handles, $recursion = false ) { 105 148 $r = parent::all_deps( $handles, $recursion ); … … 108 151 return $r; 109 152 } 153 154 function do_head_items() { 155 $this->do_items(false, 0); 156 return $this->done; 157 } 158 159 function do_footer_items() { 160 if ( !empty($this->in_footer) ) { 161 foreach( $this->in_footer as $key => $handle ) { 162 if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) { 163 $this->do_item($handle, false, $this->doecho); 164 $this->done[] = $handle; 165 unset( $this->in_footer[$key] ); 166 } 167 } 168 } 169 return $this->done; 170 } 171 172 function in_default_dir($src) { 173 if ( ! $this->default_dirs ) 174 return true; 175 176 foreach ( (array) $this->default_dirs as $test ) { 177 if ( 0 === strpos($src, $test) ) 178 return true; 179 } 180 return false; 181 } 110 182 }
Note: See TracChangeset
for help on using the changeset viewer.