3 * BackPress Styles enqueue.
5 * These classes were refactored from the WordPress WP_Scripts and WordPress
13 * BackPress Styles enqueue class.
16 * @uses WP_Dependencies
19 class WP_Styles extends WP_Dependencies {
23 var $text_direction = 'ltr';
25 var $concat_version = '';
26 var $do_concat = false;
31 function __construct() {
32 do_action_ref_array( 'wp_default_styles', array(&$this) );
35 function do_item( $handle ) {
36 if ( !parent::do_item($handle) )
39 $obj = $this->registered[$handle];
40 if ( null === $obj->ver )
43 $ver = $obj->ver ? $obj->ver : $this->default_version;
45 if ( isset($this->args[$handle]) )
46 $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle];
48 if ( $this->do_concat ) {
49 if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) {
50 $this->concat .= "$handle,";
51 $this->concat_version .= "$handle$ver";
53 $this->print_code .= $this->get_data( $handle, 'after' );
59 if ( isset($obj->args) )
60 $media = esc_attr( $obj->args );
64 $href = $this->_css_href( $obj->src, $ver, $handle );
65 $rel = isset($obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
66 $title = isset($obj->extra['title']) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : '';
68 $end_cond = $tag = '';
69 if ( isset($obj->extra['conditional']) && $obj->extra['conditional'] ) {
70 $tag .= "<!--[if {$obj->extra['conditional']}]>\n";
71 $end_cond = "<![endif]-->\n";
74 $tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle );
75 if ( 'rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl'] ) {
76 if ( is_bool( $obj->extra['rtl'] ) ) {
77 $suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : '';
78 $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src , $ver, "$handle-rtl" ));
80 $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" );
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 );
88 if ( $this->do_concat ) {
89 $this->print_html .= $tag;
90 $this->print_html .= $this->print_inline_style( $handle, false );
93 $this->print_inline_style( $handle );
99 function add_inline_style( $handle, $code ) {
103 $after = $this->get_data( $handle, 'after' );
109 return $this->add_data( $handle, 'after', $after );
112 function print_inline_style( $handle, $echo = true ) {
113 $output = $this->get_data( $handle, 'after' );
115 if ( empty( $output ) )
118 $output = implode( "\n", $output );
123 echo "<style type='text/css'>\n";
130 function all_deps( $handles, $recursion = false, $group = false ) {
131 $r = parent::all_deps( $handles, $recursion );
133 $this->to_do = apply_filters( 'print_styles_array', $this->to_do );
137 function _css_href( $src, $ver, $handle ) {
138 if ( !is_bool($src) && !preg_match('|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {
139 $src = $this->base_url . $src;
143 $src = add_query_arg('ver', $ver, $src);
144 $src = apply_filters( 'style_loader_src', $src, $handle );
145 return esc_url( $src );
148 function in_default_dir($src) {
149 if ( ! $this->default_dirs )
152 foreach ( (array) $this->default_dirs as $test ) {
153 if ( 0 === strpos($src, $test) )
159 function do_footer_items() { // HTML 5 allows styles in the body, grab late enqueued items and output them in the footer.
160 $this->do_items(false, 1);
165 $this->do_concat = false;
167 $this->concat_version = '';
168 $this->print_html = '';