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 = '';
|
|
|
|
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;
|
|
|
|
|
2009-12-28 01:48:20 +01:00
|
|
|
if ( null === $this->registered[$handle]->ver )
|
|
|
|
$ver = '';
|
|
|
|
else
|
|
|
|
$ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version;
|
|
|
|
|
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 ) {
|
|
|
|
if ( $this->in_default_dir($this->registered[$handle]->src) && !isset($this->registered[$handle]->extra['conditional']) && !isset($this->registered[$handle]->extra['alt']) ) {
|
2009-01-26 13:59:10 +01:00
|
|
|
$this->concat .= "$handle,";
|
|
|
|
$this->concat_version .= "$handle$ver";
|
2009-01-14 15:18:51 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-21 07:56:04 +02:00
|
|
|
if ( isset($this->registered[$handle]->args) )
|
2009-05-05 21:43:53 +02:00
|
|
|
$media = esc_attr( $this->registered[$handle]->args );
|
2008-05-21 07:56:04 +02:00
|
|
|
else
|
|
|
|
$media = 'all';
|
|
|
|
|
2008-05-22 01:24:23 +02:00
|
|
|
$href = $this->_css_href( $this->registered[$handle]->src, $ver, $handle );
|
2008-12-27 13:18:38 +01:00
|
|
|
$rel = isset($this->registered[$handle]->extra['alt']) && $this->registered[$handle]->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
|
2009-05-05 21:43:53 +02:00
|
|
|
$title = isset($this->registered[$handle]->extra['title']) ? "title='" . esc_attr( $this->registered[$handle]->extra['title'] ) . "'" : '';
|
2008-05-22 01:24:23 +02:00
|
|
|
|
2009-01-14 15:18:51 +01:00
|
|
|
$end_cond = $tag = '';
|
2008-05-22 01:24:23 +02:00
|
|
|
if ( isset($this->registered[$handle]->extra['conditional']) && $this->registered[$handle]->extra['conditional'] ) {
|
2009-01-14 15:18:51 +01:00
|
|
|
$tag .= "<!--[if {$this->registered[$handle]->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 );
|
2008-05-22 01:24:23 +02:00
|
|
|
if ( 'rtl' === $this->text_direction && isset($this->registered[$handle]->extra['rtl']) && $this->registered[$handle]->extra['rtl'] ) {
|
|
|
|
if ( is_bool( $this->registered[$handle]->extra['rtl'] ) )
|
2009-05-06 19:47:58 +02:00
|
|
|
$rtl_href = str_replace( '.css', '-rtl.css', $this->_css_href( $this->registered[$handle]->src , $ver, "$handle-rtl" ));
|
2008-05-22 01:24:23 +02:00
|
|
|
else
|
|
|
|
$rtl_href = $this->_css_href( $this->registered[$handle]->extra['rtl'], $ver, "$handle-rtl" );
|
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;
|
|
|
|
|
|
|
|
if ( $this->do_concat )
|
|
|
|
$this->print_html .= $tag;
|
|
|
|
else
|
|
|
|
echo $tag;
|
2008-05-21 07:56:04 +02:00
|
|
|
|
|
|
|
// Could do something with $this->registered[$handle]->extra here to print out extra CSS rules
|
|
|
|
// echo "<style type='text/css'>\n";
|
|
|
|
// echo "/* <![CDATA[ */\n";
|
|
|
|
// echo "/* ]]> */\n";
|
|
|
|
// echo "</style>\n";
|
|
|
|
|
|
|
|
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 ) {
|
2009-01-14 15:18:51 +01:00
|
|
|
if ( !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;
|
|
|
|
}
|
|
|
|
|
2008-05-21 07:56:04 +02:00
|
|
|
}
|