2008-05-21 07:56:04 +02:00
|
|
|
<?php
|
2008-09-27 12:06:18 +02: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 07:56:04 +02:00
|
|
|
|
2008-09-27 12:06:18 +02:00
|
|
|
/**
|
|
|
|
* BackPress Styles enqueue class.
|
|
|
|
*
|
|
|
|
* @package BackPress
|
|
|
|
* @uses WP_Dependencies
|
|
|
|
* @since r74
|
|
|
|
*/
|
2008-05-21 07:56:04 +02:00
|
|
|
class WP_Styles extends WP_Dependencies {
|
|
|
|
var $base_url;
|
2009-01-14 15:18:51 +01:00
|
|
|
var $content_url;
|
2008-05-21 07:56:04 +02:00
|
|
|
var $default_version;
|
2008-05-22 01:24:23 +02:00
|
|
|
var $text_direction = 'ltr';
|
2009-01-14 15:18:51 +01:00
|
|
|
var $concat = '';
|
|
|
|
var $concat_version = '';
|
|
|
|
var $do_concat = false;
|
|
|
|
var $print_html = '';
|
2011-07-25 02:36:06 +02:00
|
|
|
var $print_code = '';
|
2009-01-14 15:18:51 +01:00
|
|
|
var $default_dirs;
|
2008-05-21 07:56:04 +02: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-25 02:36:06 +02:00
|
|
|
$obj = $this->registered[$handle];
|
|
|
|
if ( null === $obj->ver )
|
2009-12-28 01:48:20 +01:00
|
|
|
$ver = '';
|
|
|
|
else
|
2011-07-25 02:36:06 +02:00
|
|
|
$ver = $obj->ver ? $obj->ver : $this->default_version;
|
2009-12-28 01:48:20 +01:00
|
|
|
|
2008-05-21 07:56:04 +02:00
|
|
|
if ( isset($this->args[$handle]) )
|
2009-12-28 01:56:41 +01:00
|
|
|
$ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle];
|
2008-05-21 07:56:04 +02:00
|
|
|
|
2009-01-14 15:18:51 +01:00
|
|
|
if ( $this->do_concat ) {
|
2011-07-28 20:24:00 +02:00
|
|
|
if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) {
|
2009-01-26 13:59:10 +01:00
|
|
|
$this->concat .= "$handle,";
|
|
|
|
$this->concat_version .= "$handle$ver";
|
2011-07-25 02:36:06 +02:00
|
|
|
|
2011-07-28 20:24:00 +02:00
|
|
|
$this->print_code .= $this->get_data( $handle, 'after' );
|
2011-07-25 02:36:06 +02:00
|
|
|
|
2009-01-14 15:18:51 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-25 02:36:06 +02:00
|
|
|
if ( isset($obj->args) )
|
|
|
|
$media = esc_attr( $obj->args );
|
2008-05-21 07:56:04 +02:00
|
|
|
else
|
|
|
|
$media = 'all';
|
|
|
|
|
2011-07-25 02:36:06 +02: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-22 01:24:23 +02:00
|
|
|
|
2009-01-14 15:18:51 +01:00
|
|
|
$end_cond = $tag = '';
|
2011-07-25 02:36:06 +02:00
|
|
|
if ( isset($obj->extra['conditional']) && $obj->extra['conditional'] ) {
|
|
|
|
$tag .= "<!--[if {$obj->extra['conditional']}]>\n";
|
2008-05-22 01:24:23 +02:00
|
|
|
$end_cond = "<![endif]-->\n";
|
2008-05-21 07:56:04 +02:00
|
|
|
}
|
|
|
|
|
2009-04-09 00:49:39 +02: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-25 02:36:06 +02: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-24 00:46:07 +01:00
|
|
|
} else {
|
2011-07-25 02:36:06 +02:00
|
|
|
$rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" );
|
2010-02-24 00:46:07 +01:00
|
|
|
}
|
2008-05-21 07:56:04 +02:00
|
|
|
|
2009-04-09 00:49:39 +02: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-22 01:24:23 +02:00
|
|
|
}
|
|
|
|
|
2009-01-14 15:18:51 +01:00
|
|
|
$tag .= $end_cond;
|
|
|
|
|
2011-07-25 02:36:06 +02:00
|
|
|
if ( $this->do_concat ) {
|
2009-01-14 15:18:51 +01:00
|
|
|
$this->print_html .= $tag;
|
2011-07-25 02:36:06 +02:00
|
|
|
$this->print_html .= $this->print_inline_style( $handle, false );
|
|
|
|
} else {
|
2009-01-14 15:18:51 +01:00
|
|
|
echo $tag;
|
2011-07-25 02:36:06 +02:00
|
|
|
$this->print_inline_style( $handle );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-28 20:24:00 +02:00
|
|
|
function add_inline_style( $handle, $code ) {
|
|
|
|
if ( !$code )
|
2011-07-25 02:36:06 +02:00
|
|
|
return false;
|
|
|
|
|
2011-07-28 20:24:00 +02:00
|
|
|
$after = $this->get_data( $handle, 'after' );
|
|
|
|
if ( !$after )
|
|
|
|
$after = array();
|
2011-07-25 02:36:06 +02:00
|
|
|
|
2011-07-28 20:24:00 +02:00
|
|
|
$after[] = $code;
|
|
|
|
|
|
|
|
return $this->add_data( $handle, 'after', $after );
|
2011-07-25 02:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function print_inline_style( $handle, $echo = true ) {
|
2011-07-28 20:24:00 +02:00
|
|
|
$output = $this->get_data( $handle, 'after' );
|
|
|
|
|
|
|
|
if ( empty( $output ) )
|
2011-07-25 02:36:06 +02:00
|
|
|
return false;
|
|
|
|
|
2011-07-28 20:24:00 +02:00
|
|
|
$output = implode( "\n", $output );
|
2011-07-25 02:36:06 +02:00
|
|
|
|
|
|
|
if ( !$echo )
|
|
|
|
return $output;
|
2008-05-21 07:56:04 +02:00
|
|
|
|
2011-07-25 02:36:06 +02:00
|
|
|
echo "<style type='text/css'>\n";
|
|
|
|
echo "$output\n";
|
|
|
|
echo "</style>\n";
|
2008-05-21 07:56:04 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-01-26 13:59:10 +01:00
|
|
|
function all_deps( $handles, $recursion = false, $group = false ) {
|
2008-05-21 07:56:04 +02:00
|
|
|
$r = parent::all_deps( $handles, $recursion );
|
|
|
|
if ( !$recursion )
|
|
|
|
$this->to_do = apply_filters( 'print_styles_array', $this->to_do );
|
|
|
|
return $r;
|
|
|
|
}
|
2008-05-22 01:24:23 +02:00
|
|
|
|
|
|
|
function _css_href( $src, $ver, $handle ) {
|
2012-06-28 22:18:38 +02:00
|
|
|
if ( !is_bool($src) && !preg_match('|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {
|
2008-05-22 01:24:23 +02:00
|
|
|
$src = $this->base_url . $src;
|
|
|
|
}
|
|
|
|
|
2009-12-28 01:48:20 +01:00
|
|
|
if ( !empty($ver) )
|
|
|
|
$src = add_query_arg('ver', $ver, $src);
|
2008-05-22 01:24:23 +02:00
|
|
|
$src = apply_filters( 'style_loader_src', $src, $handle );
|
2009-05-18 18:00:33 +02:00
|
|
|
return esc_url( $src );
|
2008-05-22 01:24:23 +02:00
|
|
|
}
|
|
|
|
|
2009-01-14 15:18:51 +01: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 20:24:00 +02:00
|
|
|
|
2011-07-21 18:32:01 +02: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 15:18:51 +01:00
|
|
|
|
2011-07-21 18:32:01 +02:00
|
|
|
function reset() {
|
|
|
|
$this->do_concat = false;
|
|
|
|
$this->concat = '';
|
|
|
|
$this->concat_version = '';
|
|
|
|
$this->print_html = '';
|
|
|
|
}
|
2008-05-21 07:56:04 +02:00
|
|
|
}
|