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() {
|
2014-03-28 22:23:44 +01:00
|
|
|
/**
|
|
|
|
* Fires when the WP_Styles instance is initialized.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*
|
|
|
|
* @param WP_Styles &$this WP_Styles instance, passed by reference.
|
|
|
|
*/
|
2008-05-21 07:56:04 +02:00
|
|
|
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
|
|
|
|
2013-04-22 21:22:09 +02:00
|
|
|
$this->print_code .= $this->print_inline_style( $handle, false );
|
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 );
|
2014-03-12 17:11:38 +01:00
|
|
|
if ( empty( $href ) ) {
|
|
|
|
// Turns out there is nothing to print.
|
|
|
|
return true;
|
|
|
|
}
|
2011-07-25 02:36:06 +02:00
|
|
|
$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
|
|
|
|
2014-03-28 22:23:44 +01:00
|
|
|
/**
|
|
|
|
* Filter the HTML link tag of an enqueued style.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*
|
|
|
|
* @param string The link tag for the enqueued style.
|
|
|
|
* @param string $handle The style's registered handle.
|
|
|
|
*/
|
2013-11-12 22:18:45 +01: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'] ) {
|
2013-11-12 22:18:45 +01:00
|
|
|
if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) {
|
2011-07-25 02:36:06 +02:00
|
|
|
$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
|
|
|
|
2014-03-28 22:23:44 +01:00
|
|
|
/**
|
|
|
|
* Filter the right-to-left (RTL) HTML link tag of an enqueued style.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*
|
|
|
|
* @param string $rtl_style The right to left link tag for the enqueued style.
|
|
|
|
* @param string $handle The style's registered handle.
|
|
|
|
*/
|
2013-11-12 22:18:45 +01:00
|
|
|
$rtl_tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-rtl-css' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle );
|
|
|
|
|
|
|
|
if ( $obj->extra['rtl'] === 'replace' ) {
|
|
|
|
$tag = $rtl_tag;
|
|
|
|
} else {
|
|
|
|
$tag .= $rtl_tag;
|
|
|
|
}
|
2008-05-22 01:24:23 +02:00
|
|
|
}
|
|
|
|
|
2013-11-12 22:18:45 +01:00
|
|
|
if ( isset($obj->extra['conditional']) && $obj->extra['conditional'] ) {
|
|
|
|
$tag = "<!--[if {$obj->extra['conditional']}]>\n" . $tag . "<![endif]-->\n";
|
|
|
|
}
|
2009-01-14 15:18:51 +01:00
|
|
|
|
2011-07-25 02:36:06 +02:00
|
|
|
if ( $this->do_concat ) {
|
2009-01-14 15:18:51 +01:00
|
|
|
$this->print_html .= $tag;
|
2013-10-15 16:34:33 +02:00
|
|
|
if ( $inline_style = $this->print_inline_style( $handle, false ) )
|
|
|
|
$this->print_html .= sprintf( "<style type='text/css'>\n%s\n</style>\n", $inline_style );
|
2011-07-25 02:36:06 +02:00
|
|
|
} else {
|
2009-01-14 15:18:51 +01:00
|
|
|
echo $tag;
|
2013-10-15 16:34:33 +02:00
|
|
|
$this->print_inline_style( $handle );
|
2011-07-25 02:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
2014-03-28 22:23:44 +01:00
|
|
|
if ( !$recursion ) {
|
|
|
|
/**
|
|
|
|
* Filter the array of enqueued styles before processing for output.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*
|
|
|
|
* @param array $to_do The list of enqueued styles about to be processed.
|
|
|
|
*/
|
2008-05-21 07:56:04 +02:00
|
|
|
$this->to_do = apply_filters( 'print_styles_array', $this->to_do );
|
2014-03-28 22:23:44 +01:00
|
|
|
}
|
2008-05-21 07:56:04 +02:00
|
|
|
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);
|
2014-03-28 22:23:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter an enqueued style's fully-qualified URL.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*
|
|
|
|
* @param string $src The source URL of the enqueued style.
|
|
|
|
* @param string $handle The style's registered handle.
|
|
|
|
*/
|
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
|
|
|
}
|