23 var $text_direction = 'ltr'; |
23 var $text_direction = 'ltr'; |
24 var $concat = ''; |
24 var $concat = ''; |
25 var $concat_version = ''; |
25 var $concat_version = ''; |
26 var $do_concat = false; |
26 var $do_concat = false; |
27 var $print_html = ''; |
27 var $print_html = ''; |
|
28 var $print_code = ''; |
28 var $default_dirs; |
29 var $default_dirs; |
29 |
30 |
30 function __construct() { |
31 function __construct() { |
31 do_action_ref_array( 'wp_default_styles', array(&$this) ); |
32 do_action_ref_array( 'wp_default_styles', array(&$this) ); |
32 } |
33 } |
33 |
34 |
34 function do_item( $handle ) { |
35 function do_item( $handle ) { |
35 if ( !parent::do_item($handle) ) |
36 if ( !parent::do_item($handle) ) |
36 return false; |
37 return false; |
37 |
38 |
38 $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; |
39 $obj = $this->registered[$handle]; |
|
40 if ( null === $obj->ver ) |
|
41 $ver = ''; |
|
42 else |
|
43 $ver = $obj->ver ? $obj->ver : $this->default_version; |
|
44 |
39 if ( isset($this->args[$handle]) ) |
45 if ( isset($this->args[$handle]) ) |
40 $ver .= '&' . $this->args[$handle]; |
46 $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; |
41 |
47 |
42 if ( $this->do_concat ) { |
48 if ( $this->do_concat ) { |
43 if ( $this->in_default_dir($this->registered[$handle]->src) && !isset($this->registered[$handle]->extra['conditional']) && !isset($this->registered[$handle]->extra['alt']) ) { |
49 if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) { |
44 $this->concat .= "$handle,"; |
50 $this->concat .= "$handle,"; |
45 $this->concat_version .= "$handle$ver"; |
51 $this->concat_version .= "$handle$ver"; |
|
52 |
|
53 $this->print_code .= $this->get_data( $handle, 'after' ); |
|
54 |
46 return true; |
55 return true; |
47 } |
56 } |
48 } |
57 } |
49 |
58 |
50 if ( isset($this->registered[$handle]->args) ) |
59 if ( isset($obj->args) ) |
51 $media = esc_attr( $this->registered[$handle]->args ); |
60 $media = esc_attr( $obj->args ); |
52 else |
61 else |
53 $media = 'all'; |
62 $media = 'all'; |
54 |
63 |
55 $href = $this->_css_href( $this->registered[$handle]->src, $ver, $handle ); |
64 $href = $this->_css_href( $obj->src, $ver, $handle ); |
56 $rel = isset($this->registered[$handle]->extra['alt']) && $this->registered[$handle]->extra['alt'] ? 'alternate stylesheet' : 'stylesheet'; |
65 $rel = isset($obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet'; |
57 $title = isset($this->registered[$handle]->extra['title']) ? "title='" . esc_attr( $this->registered[$handle]->extra['title'] ) . "'" : ''; |
66 $title = isset($obj->extra['title']) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : ''; |
58 |
67 |
59 $end_cond = $tag = ''; |
68 $end_cond = $tag = ''; |
60 if ( isset($this->registered[$handle]->extra['conditional']) && $this->registered[$handle]->extra['conditional'] ) { |
69 if ( isset($obj->extra['conditional']) && $obj->extra['conditional'] ) { |
61 $tag .= "<!--[if {$this->registered[$handle]->extra['conditional']}]>\n"; |
70 $tag .= "<!--[if {$obj->extra['conditional']}]>\n"; |
62 $end_cond = "<![endif]-->\n"; |
71 $end_cond = "<![endif]-->\n"; |
63 } |
72 } |
64 |
73 |
65 $tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle ); |
74 $tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle ); |
66 if ( 'rtl' === $this->text_direction && isset($this->registered[$handle]->extra['rtl']) && $this->registered[$handle]->extra['rtl'] ) { |
75 if ( 'rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl'] ) { |
67 if ( is_bool( $this->registered[$handle]->extra['rtl'] ) ) |
76 if ( is_bool( $obj->extra['rtl'] ) ) { |
68 $rtl_href = str_replace( '.css', '-rtl.css', $this->_css_href( $this->registered[$handle]->src , $ver, "$handle-rtl" )); |
77 $suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : ''; |
69 else |
78 $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src , $ver, "$handle-rtl" )); |
70 $rtl_href = $this->_css_href( $this->registered[$handle]->extra['rtl'], $ver, "$handle-rtl" ); |
79 } else { |
|
80 $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" ); |
|
81 } |
71 |
82 |
72 $tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-rtl-css' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle ); |
83 $tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-rtl-css' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle ); |
73 } |
84 } |
74 |
85 |
75 $tag .= $end_cond; |
86 $tag .= $end_cond; |
76 |
87 |
77 if ( $this->do_concat ) |
88 if ( $this->do_concat ) { |
78 $this->print_html .= $tag; |
89 $this->print_html .= $tag; |
79 else |
90 $this->print_html .= $this->print_inline_style( $handle, false ); |
|
91 } else { |
80 echo $tag; |
92 echo $tag; |
|
93 $this->print_inline_style( $handle ); |
|
94 } |
81 |
95 |
82 // Could do something with $this->registered[$handle]->extra here to print out extra CSS rules |
96 return true; |
83 // echo "<style type='text/css'>\n"; |
97 } |
84 // echo "/* <![CDATA[ */\n"; |
98 |
85 // echo "/* ]]> */\n"; |
99 function add_inline_style( $handle, $code ) { |
86 // echo "</style>\n"; |
100 if ( !$code ) |
|
101 return false; |
|
102 |
|
103 $after = $this->get_data( $handle, 'after' ); |
|
104 if ( !$after ) |
|
105 $after = array(); |
|
106 |
|
107 $after[] = $code; |
|
108 |
|
109 return $this->add_data( $handle, 'after', $after ); |
|
110 } |
|
111 |
|
112 function print_inline_style( $handle, $echo = true ) { |
|
113 $output = $this->get_data( $handle, 'after' ); |
|
114 |
|
115 if ( empty( $output ) ) |
|
116 return false; |
|
117 |
|
118 $output = implode( "\n", $output ); |
|
119 |
|
120 if ( !$echo ) |
|
121 return $output; |
|
122 |
|
123 echo "<style type='text/css'>\n"; |
|
124 echo "$output\n"; |
|
125 echo "</style>\n"; |
87 |
126 |
88 return true; |
127 return true; |
89 } |
128 } |
90 |
129 |
91 function all_deps( $handles, $recursion = false, $group = false ) { |
130 function all_deps( $handles, $recursion = false, $group = false ) { |
94 $this->to_do = apply_filters( 'print_styles_array', $this->to_do ); |
133 $this->to_do = apply_filters( 'print_styles_array', $this->to_do ); |
95 return $r; |
134 return $r; |
96 } |
135 } |
97 |
136 |
98 function _css_href( $src, $ver, $handle ) { |
137 function _css_href( $src, $ver, $handle ) { |
99 if ( !preg_match('|^https?://|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) { |
138 if ( !is_bool($src) && !preg_match('|^https?://|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) { |
100 $src = $this->base_url . $src; |
139 $src = $this->base_url . $src; |
101 } |
140 } |
102 |
141 |
103 $src = add_query_arg('ver', $ver, $src); |
142 if ( !empty($ver) ) |
|
143 $src = add_query_arg('ver', $ver, $src); |
104 $src = apply_filters( 'style_loader_src', $src, $handle ); |
144 $src = apply_filters( 'style_loader_src', $src, $handle ); |
105 return esc_url( $src ); |
145 return esc_url( $src ); |
106 } |
146 } |
107 |
147 |
108 function in_default_dir($src) { |
148 function in_default_dir($src) { |