WP_Scripts

Core class used to register scripts.

Defined (1)

The class is defined in the following location(s).

/bp-forums/bbpress/bb-includes/backpress/class.wp-scripts.php  
  1. class WP_Scripts extends WP_Dependencies { 
  2. var $base_url; // Full URL with trailing slash 
  3. var $content_url; 
  4. var $default_version; 
  5. var $in_footer = array(); 
  6. var $concat = ''; 
  7. var $concat_version = ''; 
  8. var $do_concat = false; 
  9. var $print_html = ''; 
  10. var $print_code = ''; 
  11. var $ext_handles = ''; 
  12. var $ext_version = ''; 
  13. var $default_dirs; 
  14.  
  15. function __construct() { 
  16. do_action_ref_array( 'wp_default_scripts', array(&$this) ); 
  17.  
  18. /** 
  19. * Prints scripts 
  20. * Prints the scripts passed to it or the print queue. Also prints all necessary dependencies. 
  21. * @param mixed handles (optional) Scripts to be printed. (void) prints queue, (string) prints that script, (array of strings) prints those scripts. 
  22. * @param int group (optional) If scripts were queued in groups prints this group number. 
  23. * @return array Scripts that have been printed 
  24. */ 
  25. function print_scripts( $handles = false, $group = false ) { 
  26. return $this->do_items( $handles, $group ); 
  27.  
  28. function print_scripts_l10n( $handle, $echo = true ) { 
  29. if ( empty($this->registered[$handle]->extra['l10n']) || empty($this->registered[$handle]->extra['l10n'][0]) || !is_array($this->registered[$handle]->extra['l10n'][1]) ) 
  30. return false; 
  31.  
  32. $object_name = $this->registered[$handle]->extra['l10n'][0]; 
  33.  
  34. $data = "var $object_name = {\n"; 
  35. $eol = ''; 
  36. foreach ( $this->registered[$handle]->extra['l10n'][1] as $var => $val ) { 
  37. if ( 'l10n_print_after' == $var ) { 
  38. $after = $val; 
  39. continue; 
  40. $data .= "$eol\t$var: \"" . esc_js( $val ) . '"'; 
  41. $eol = ", \n"; 
  42. $data .= "\n};\n"; 
  43. $data .= isset($after) ? "$after\n" : ''; 
  44.  
  45. if ( $echo ) { 
  46. echo "<script type='text/javascript'>\n"; 
  47. echo "/* <![CDATA[ */\n"; 
  48. echo $data; 
  49. echo "/* ]]> */\n"; 
  50. echo "</script>\n"; 
  51. return true; 
  52. } else { 
  53. return $data; 
  54.  
  55. function do_item( $handle, $group = false ) { 
  56. if ( !parent::do_item($handle) ) 
  57. return false; 
  58.  
  59. if ( 0 === $group && $this->groups[$handle] > 0 ) { 
  60. $this->in_footer[] = $handle; 
  61. return false; 
  62.  
  63. if ( false === $group && in_array($handle, $this->in_footer, true) ) 
  64. $this->in_footer = array_diff( $this->in_footer, (array) $handle ); 
  65.  
  66. if ( null === $this->registered[$handle]->ver ) 
  67. $ver = ''; 
  68. else 
  69. $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; 
  70.  
  71. if ( isset($this->args[$handle]) ) 
  72. $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; 
  73.  
  74. $src = $this->registered[$handle]->src; 
  75.  
  76. if ( $this->do_concat ) { 
  77. $srce = apply_filters( 'script_loader_src', $src, $handle ); 
  78. if ( $this->in_default_dir($srce) ) { 
  79. $this->print_code .= $this->print_scripts_l10n( $handle, false ); 
  80. $this->concat .= "$handle, "; 
  81. $this->concat_version .= "$handle$ver"; 
  82. return true; 
  83. } else { 
  84. $this->ext_handles .= "$handle, "; 
  85. $this->ext_version .= "$handle$ver"; 
  86.  
  87. $this->print_scripts_l10n( $handle ); 
  88. if ( !preg_match('|^https?://|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) { 
  89. $src = $this->base_url . $src; 
  90.  
  91. if ( !empty($ver) ) 
  92. $src = add_query_arg('ver', $ver, $src); 
  93. $src = esc_url(apply_filters( 'script_loader_src', $src, $handle )); 
  94.  
  95. if ( $this->do_concat ) 
  96. $this->print_html .= "<script type='text/javascript' src='$src'></script>\n"; 
  97. else 
  98. echo "<script type='text/javascript' src='$src'></script>\n"; 
  99.  
  100. return true; 
  101.  
  102. /** 
  103. * Localizes a script 
  104. * Localizes only if script has already been added 
  105. * @param string handle Script name 
  106. * @param string object_name Name of JS object to hold l10n info 
  107. * @param array l10n Array of JS var name => localized string 
  108. * @return bool Successful localization 
  109. */ 
  110. function localize( $handle, $object_name, $l10n ) { 
  111. if ( !$object_name || !$l10n ) 
  112. return false; 
  113. return $this->add_data( $handle, 'l10n', array( $object_name, $l10n ) ); 
  114.  
  115. function set_group( $handle, $recursion, $group = false ) { 
  116. $grp = isset($this->registered[$handle]->extra['group']) ? (int) $this->registered[$handle]->extra['group'] : 0; 
  117. if ( false !== $group && $grp > $group ) 
  118. $grp = $group; 
  119.  
  120. return parent::set_group( $handle, $recursion, $grp ); 
  121.  
  122. function all_deps( $handles, $recursion = false, $group = false ) { 
  123. $r = parent::all_deps( $handles, $recursion ); 
  124. if ( !$recursion ) 
  125. $this->to_do = apply_filters( 'print_scripts_array', $this->to_do ); 
  126. return $r; 
  127.  
  128. function do_head_items() { 
  129. $this->do_items(false, 0); 
  130. return $this->done; 
  131.  
  132. function do_footer_items() { 
  133. if ( !empty($this->in_footer) ) { 
  134. foreach( $this->in_footer as $key => $handle ) { 
  135. if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) { 
  136. $this->do_item($handle); 
  137. $this->done[] = $handle; 
  138. unset( $this->in_footer[$key] ); 
  139. return $this->done; 
  140.  
  141. function in_default_dir($src) { 
  142. if ( ! $this->default_dirs ) 
  143. return true; 
  144.  
  145. foreach ( (array) $this->default_dirs as $test ) { 
  146. if ( 0 === strpos($src, $test) ) 
  147. return true; 
  148. return false; 
  149.  
  150. function reset() { 
  151. $this->do_concat = false; 
  152. $this->print_code = ''; 
  153. $this->concat = ''; 
  154. $this->concat_version = ''; 
  155. $this->print_html = ''; 
  156. $this->ext_version = ''; 
  157. $this->ext_handles = '';