Changeset 6133
- Timestamp:
- 09/19/2007 12:51:21 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/script-loader.php
r5939 r6133 3 3 var $scripts = array(); 4 4 var $queue = array(); 5 var $to_print = array(); 5 6 var $printed = array(); 6 7 var $args = array(); … … 155 156 */ 156 157 function print_scripts( $handles = false ) { 158 global $wp_db_version; 159 157 160 // Print the queue if nothing is passed. If a string is passed, print that script. If an array is passed, print those scripts. 158 161 $handles = false === $handles ? $this->queue : (array) $handles; 159 $handles = $this->all_deps( $handles ); 160 $this->_print_scripts( $handles ); 161 return $this->printed; 162 } 163 164 /** 165 * Internally used helper function for printing script tags 166 * 167 * @param array handles Hierarchical array of scripts to be printed 168 * @see WP_Scripts::all_deps() 169 */ 170 function _print_scripts( $handles ) { 171 global $wp_db_version; 172 173 foreach( array_keys($handles) as $handle ) { 174 if ( !$handles[$handle] ) 175 return; 176 elseif ( is_array($handles[$handle]) ) 177 $this->_print_scripts( $handles[$handle] ); 162 $this->all_deps( $handles ); 163 164 $to_print = apply_filters( 'print_scripts_array', array_keys($this->to_print) ); 165 166 foreach( $to_print as $handle ) { 178 167 if ( !in_array($handle, $this->printed) && isset($this->scripts[$handle]) ) { 179 168 if ( $this->scripts[$handle]->src ) { // Else it defines a group. … … 196 185 } 197 186 } 187 188 $this->to_print = array(); 189 return $this->printed; 198 190 } 199 191 … … 220 212 * Determines dependencies of scripts 221 213 * 222 * Recursively builds hierarchical array of script dependencies. Does NOT catch infinite loops.214 * Recursively builds array of scripts to print taking dependencies into account. Does NOT catch infinite loops. 223 215 * 224 216 * @param mixed handles Accepts (string) script name or (array of strings) script names 225 217 * @param bool recursion Used internally when function calls itself 226 * @return array Hierarchical array of dependencies227 218 */ 228 219 function all_deps( $handles, $recursion = false ) { 229 if ( ! 230 return array();231 $return = array(); 220 if ( !$handles = (array) $handles ) 221 return false; 222 232 223 foreach ( $handles as $handle ) { 233 224 $handle = explode('?', $handle); … … 235 226 $this->args[$handle[0]] = $handle[1]; 236 227 $handle = $handle[0]; 237 if ( is_null($return[$handle]) ) // Prime the return array with $handles 238 $return[$handle] = true; 239 if ( $this->scripts[$handle]->deps ) { 240 if ( false !== $return[$handle] && array_diff($this->scripts[$handle]->deps, array_keys($this->scripts)) ) 241 $return[$handle] = false; // Script required deps which don't exist 228 229 if ( isset($this->to_print[$handle]) ) // Already grobbed it and its deps 230 continue; 231 232 $keep_going = true; 233 if ( !isset($this->scripts[$handle]) ) 234 $keep_going = false; // Script doesn't exist 235 elseif ( $this->scripts[$handle]->deps && array_diff($this->scripts[$handle]->deps, array_keys($this->scripts)) ) 236 $keep_going = false; // Script requires deps which don't exist (not a necessary check. efficiency?) 237 elseif ( $this->scripts[$handle]->deps && !$this->all_deps( $this->scripts[$handle]->deps, true ) ) 238 $keep_going = false; // Script requires deps which don't exist 239 240 if ( !$keep_going ) { // Either script or its deps don't exist. 241 if ( $recursion ) 242 return false; // Abort this branch. 242 243 else 243 $return[$handle] = $this->all_deps( $this->scripts[$handle]->deps, true ); // Build the hierarchy244 } 245 if ( $recursion && false === $return[$handle] ) 246 return false; // Cut the branch244 continue; // We're at the top level. Move on to the next one. 245 } 246 247 $this->to_print[$handle] = true; 247 248 } 248 return $return; 249 250 return true; 249 251 } 250 252
Note: See TracChangeset
for help on using the changeset viewer.