2008-05-21 01:56:04 -04:00
|
|
|
<?php
|
2008-09-27 06:06:18 -04:00
|
|
|
/**
|
|
|
|
* BackPress Styles enqueue.
|
|
|
|
*
|
|
|
|
* These classes were refactored from the WordPress WP_Scripts and WordPress
|
|
|
|
* script enqueue API.
|
|
|
|
*
|
|
|
|
* @package BackPress
|
|
|
|
* @since r74
|
|
|
|
*/
|
2008-05-21 01:56:04 -04:00
|
|
|
|
2008-09-27 06:06:18 -04:00
|
|
|
/**
|
|
|
|
* BackPress Styles enqueue class.
|
|
|
|
*
|
|
|
|
* @package BackPress
|
|
|
|
* @uses WP_Dependencies
|
|
|
|
* @since r74
|
|
|
|
*/
|
2008-05-21 01:56:04 -04:00
|
|
|
class WP_Styles extends WP_Dependencies {
|
|
|
|
var $base_url;
|
2009-01-14 09:18:51 -05:00
|
|
|
var $content_url;
|
2008-05-21 01:56:04 -04:00
|
|
|
var $default_version;
|
2008-05-21 19:24:23 -04:00
|
|
|
var $text_direction = 'ltr';
|
2009-01-14 09:18:51 -05:00
|
|
|
var $concat = '';
|
|
|
|
var $concat_version = '';
|
|
|
|
var $do_concat = false;
|
|
|
|
var $print_html = '';
|
2011-07-24 20:36:06 -04:00
|
|
|
var $print_code = '';
|
2009-01-14 09:18:51 -05:00
|
|
|
var $default_dirs;
|
2008-05-21 01:56:04 -04:00
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
do_action_ref_array( 'wp_default_styles', array(&$this) );
|
|
|
|
}
|
|
|
|
|
|
|
|
function do_item( $handle ) {
|
|
|
|
if ( !parent::do_item($handle) )
|
|
|
|
return false;
|
|
|
|
|
2011-07-24 20:36:06 -04:00
|
|
|
$obj = $this->registered[$handle];
|
|
|
|
if ( null === $obj->ver )
|
2009-12-27 19:48:20 -05:00
|
|
|
$ver = '';
|
|
|
|
else
|
2011-07-24 20:36:06 -04:00
|
|
|
$ver = $obj->ver ? $obj->ver : $this->default_version;
|
2009-12-27 19:48:20 -05:00
|
|
|
|
2008-05-21 01:56:04 -04:00
|
|
|
if ( isset($this->args[$handle]) )
|
2009-12-27 19:56:41 -05:00
|
|
|
$ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle];
|
2008-05-21 01:56:04 -04:00
|
|
|
|
2009-01-14 09:18:51 -05:00
|
|
|
if ( $this->do_concat ) {
|
2011-07-28 14:24:00 -04:00
|
|
|
if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) {
|
2009-01-26 07:59:10 -05:00
|
|
|
$this->concat .= "$handle,";
|
|
|
|
$this->concat_version .= "$handle$ver";
|
2011-07-24 20:36:06 -04:00
|
|
|
|
2011-07-28 14:24:00 -04:00
|
|
|
$this->print_code .= $this->get_data( $handle, 'after' );
|
2011-07-24 20:36:06 -04:00
|
|
|
|
2009-01-14 09:18:51 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-24 20:36:06 -04:00
|
|
|
if ( isset($obj->args) )
|
|
|
|
$media = esc_attr( $obj->args );
|
2008-05-21 01:56:04 -04:00
|
|
|
else
|
|
|
|
$media = 'all';
|
|
|
|
|
2011-07-24 20:36:06 -04:00
|
|
|
$href = $this->_css_href( $obj->src, $ver, $handle );
|
|
|
|
$rel = isset($obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
|
|
|
|
$title = isset($obj->extra['title']) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : '';
|
2008-05-21 19:24:23 -04:00
|
|
|
|
2009-01-14 09:18:51 -05:00
|
|
|
$end_cond = $tag = '';
|
2011-07-24 20:36:06 -04:00
|
|
|
if ( isset($obj->extra['conditional']) && $obj->extra['conditional'] ) {
|
|
|
|
$tag .= "<!--[if {$obj->extra['conditional']}]>\n";
|
2008-05-21 19:24:23 -04:00
|
|
|
$end_cond = "<![endif]-->\n";
|
2008-05-21 01:56:04 -04:00
|
|
|
}
|
|
|
|
|
2009-04-08 18:49:39 -04:00
|
|
|
$tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle );
|
2011-07-24 20:36:06 -04:00
|
|
|
if ( 'rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl'] ) {
|
|
|
|
if ( is_bool( $obj->extra['rtl'] ) ) {
|
|
|
|
$suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : '';
|
|
|
|
$rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src , $ver, "$handle-rtl" ));
|
2010-02-23 18:46:07 -05:00
|
|
|
} else {
|
2011-07-24 20:36:06 -04:00
|
|
|
$rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" );
|
2010-02-23 18:46:07 -05:00
|
|
|
}
|
2008-05-21 01:56:04 -04:00
|
|
|
|
2009-04-08 18:49:39 -04:00
|
|
|
$tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-rtl-css' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle );
|
2008-05-21 19:24:23 -04:00
|
|
|
}
|
|
|
|
|
2009-01-14 09:18:51 -05:00
|
|
|
$tag .= $end_cond;
|
|
|
|
|
2011-07-24 20:36:06 -04:00
|
|
|
if ( $this->do_concat ) {
|
2009-01-14 09:18:51 -05:00
|
|
|
$this->print_html .= $tag;
|
2011-07-24 20:36:06 -04:00
|
|
|
$this->print_html .= $this->print_inline_style( $handle, false );
|
|
|
|
} else {
|
2009-01-14 09:18:51 -05:00
|
|
|
echo $tag;
|
2011-07-24 20:36:06 -04:00
|
|
|
$this->print_inline_style( $handle );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-28 14:24:00 -04:00
|
|
|
function add_inline_style( $handle, $code ) {
|
|
|
|
if ( !$code )
|
2011-07-24 20:36:06 -04:00
|
|
|
return false;
|
|
|
|
|
2011-07-28 14:24:00 -04:00
|
|
|
$after = $this->get_data( $handle, 'after' );
|
|
|
|
if ( !$after )
|
|
|
|
$after = array();
|
2011-07-24 20:36:06 -04:00
|
|
|
|
2011-07-28 14:24:00 -04:00
|
|
|
$after[] = $code;
|
|
|
|
|
|
|
|
return $this->add_data( $handle, 'after', $after );
|
2011-07-24 20:36:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function print_inline_style( $handle, $echo = true ) {
|
2011-07-28 14:24:00 -04:00
|
|
|
$output = $this->get_data( $handle, 'after' );
|
|
|
|
|
|
|
|
if ( empty( $output ) )
|
2011-07-24 20:36:06 -04:00
|
|
|
return false;
|
|
|
|
|
2011-07-28 14:24:00 -04:00
|
|
|
$output = implode( "\n", $output );
|
2011-07-24 20:36:06 -04:00
|
|
|
|
|
|
|
if ( !$echo )
|
|
|
|
return $output;
|
2008-05-21 01:56:04 -04:00
|
|
|
|
2011-07-24 20:36:06 -04:00
|
|
|
echo "<style type='text/css'>\n";
|
|
|
|
echo "$output\n";
|
|
|
|
echo "</style>\n";
|
2008-05-21 01:56:04 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-01-26 07:59:10 -05:00
|
|
|
function all_deps( $handles, $recursion = false, $group = false ) {
|
2008-05-21 01:56:04 -04:00
|
|
|
$r = parent::all_deps( $handles, $recursion );
|
|
|
|
if ( !$recursion )
|
|
|
|
$this->to_do = apply_filters( 'print_styles_array', $this->to_do );
|
|
|
|
return $r;
|
|
|
|
}
|
2008-05-21 19:24:23 -04:00
|
|
|
|
|
|
|
function _css_href( $src, $ver, $handle ) {
|
2010-02-18 05:30:28 -05:00
|
|
|
if ( !is_bool($src) && !preg_match('|^https?://|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {
|
2008-05-21 19:24:23 -04:00
|
|
|
$src = $this->base_url . $src;
|
|
|
|
}
|
|
|
|
|
2009-12-27 19:48:20 -05:00
|
|
|
if ( !empty($ver) )
|
|
|
|
$src = add_query_arg('ver', $ver, $src);
|
2008-05-21 19:24:23 -04:00
|
|
|
$src = apply_filters( 'style_loader_src', $src, $handle );
|
2009-05-18 12:00:33 -04:00
|
|
|
return esc_url( $src );
|
2008-05-21 19:24:23 -04:00
|
|
|
}
|
|
|
|
|
2009-01-14 09:18:51 -05:00
|
|
|
function in_default_dir($src) {
|
|
|
|
if ( ! $this->default_dirs )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
foreach ( (array) $this->default_dirs as $test ) {
|
|
|
|
if ( 0 === strpos($src, $test) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-28 14:24:00 -04:00
|
|
|
|
2011-07-21 12:32:01 -04:00
|
|
|
function do_footer_items() { // HTML 5 allows styles in the body, grab late enqueued items and output them in the footer.
|
|
|
|
$this->do_items(false, 1);
|
|
|
|
return $this->done;
|
|
|
|
}
|
2009-01-14 09:18:51 -05:00
|
|
|
|
2011-07-21 12:32:01 -04:00
|
|
|
function reset() {
|
|
|
|
$this->do_concat = false;
|
|
|
|
$this->concat = '';
|
|
|
|
$this->concat_version = '';
|
|
|
|
$this->print_html = '';
|
|
|
|
}
|
2008-05-21 01:56:04 -04:00
|
|
|
}
|
2011-07-21 12:32:01 -04:00
|
|
|
|