web/wp-includes/class.wp-styles.php
changeset 136 bde1974c263b
child 194 32102edaa81b
equal deleted inserted replaced
135:53cff4b4a802 136:bde1974c263b
       
     1 <?php
       
     2 /**
       
     3  * BackPress Styles enqueue.
       
     4  *
       
     5  * These classes were refactored from the WordPress WP_Scripts and WordPress
       
     6  * script enqueue API.
       
     7  *
       
     8  * @package BackPress
       
     9  * @since r74
       
    10  */
       
    11 
       
    12 /**
       
    13  * BackPress Styles enqueue class.
       
    14  *
       
    15  * @package BackPress
       
    16  * @uses WP_Dependencies
       
    17  * @since r74
       
    18  */
       
    19 class WP_Styles extends WP_Dependencies {
       
    20 	var $base_url;
       
    21 	var $content_url;
       
    22 	var $default_version;
       
    23 	var $text_direction = 'ltr';
       
    24 	var $concat = '';
       
    25 	var $concat_version = '';
       
    26 	var $do_concat = false;
       
    27 	var $print_html = '';
       
    28 	var $default_dirs;
       
    29 
       
    30 	function __construct() {
       
    31 		do_action_ref_array( 'wp_default_styles', array(&$this) );
       
    32 	}
       
    33 
       
    34 	function do_item( $handle ) {
       
    35 		if ( !parent::do_item($handle) )
       
    36 			return false;
       
    37 
       
    38 		$ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version;
       
    39 		if ( isset($this->args[$handle]) )
       
    40 			$ver .= '&amp;' . $this->args[$handle];
       
    41 
       
    42 		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']) ) {
       
    44 				$this->concat .= "$handle,";
       
    45 				$this->concat_version .= "$handle$ver";
       
    46 				return true;
       
    47 			}
       
    48 		}
       
    49 
       
    50 		if ( isset($this->registered[$handle]->args) )
       
    51 			$media = esc_attr( $this->registered[$handle]->args );
       
    52 		else
       
    53 			$media = 'all';
       
    54 
       
    55 		$href = $this->_css_href( $this->registered[$handle]->src, $ver, $handle );
       
    56 		$rel = isset($this->registered[$handle]->extra['alt']) && $this->registered[$handle]->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
       
    57 		$title = isset($this->registered[$handle]->extra['title']) ? "title='" . esc_attr( $this->registered[$handle]->extra['title'] ) . "'" : '';
       
    58 
       
    59 		$end_cond = $tag = '';
       
    60 		if ( isset($this->registered[$handle]->extra['conditional']) && $this->registered[$handle]->extra['conditional'] ) {
       
    61 			$tag .= "<!--[if {$this->registered[$handle]->extra['conditional']}]>\n";
       
    62 			$end_cond = "<![endif]-->\n";
       
    63 		}
       
    64 
       
    65 		$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'] ) {
       
    67 			if ( is_bool( $this->registered[$handle]->extra['rtl'] ) )
       
    68 				$rtl_href = str_replace( '.css', '-rtl.css', $this->_css_href( $this->registered[$handle]->src , $ver, "$handle-rtl" ));
       
    69 			else
       
    70 				$rtl_href = $this->_css_href( $this->registered[$handle]->extra['rtl'], $ver, "$handle-rtl" );
       
    71 
       
    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 );
       
    73 		}
       
    74 
       
    75 		$tag .= $end_cond;
       
    76 
       
    77 		if ( $this->do_concat )
       
    78 			$this->print_html .= $tag;
       
    79 		else
       
    80 			echo $tag;
       
    81 
       
    82 		// Could do something with $this->registered[$handle]->extra here to print out extra CSS rules
       
    83 //		echo "<style type='text/css'>\n";
       
    84 //		echo "/* <![CDATA[ */\n";
       
    85 //		echo "/* ]]> */\n";
       
    86 //		echo "</style>\n";
       
    87 
       
    88 		return true;
       
    89 	}
       
    90 
       
    91 	function all_deps( $handles, $recursion = false, $group = false ) {
       
    92 		$r = parent::all_deps( $handles, $recursion );
       
    93 		if ( !$recursion )
       
    94 			$this->to_do = apply_filters( 'print_styles_array', $this->to_do );
       
    95 		return $r;
       
    96 	}
       
    97 
       
    98 	function _css_href( $src, $ver, $handle ) {
       
    99 		if ( !preg_match('|^https?://|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {
       
   100 			$src = $this->base_url . $src;
       
   101 		}
       
   102 
       
   103 		$src = add_query_arg('ver', $ver, $src);
       
   104 		$src = apply_filters( 'style_loader_src', $src, $handle );
       
   105 		return esc_url( $src );
       
   106 	}
       
   107 
       
   108 	function in_default_dir($src) {
       
   109 		if ( ! $this->default_dirs )
       
   110 			return true;
       
   111 
       
   112 		foreach ( (array) $this->default_dirs as $test ) {
       
   113 			if ( 0 === strpos($src, $test) )
       
   114 				return true;
       
   115 		}
       
   116 		return false;
       
   117 	}
       
   118 
       
   119 }