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 {
|
2014-05-19 08:17:14 +02:00
|
|
|
public $base_url;
|
|
|
|
public $content_url;
|
|
|
|
public $default_version;
|
|
|
|
public $text_direction = 'ltr';
|
|
|
|
public $concat = '';
|
|
|
|
public $concat_version = '';
|
|
|
|
public $do_concat = false;
|
|
|
|
public $print_html = '';
|
|
|
|
public $print_code = '';
|
|
|
|
public $default_dirs;
|
|
|
|
|
|
|
|
public function __construct() {
|
2014-03-28 22:24:14 +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) );
|
|
|
|
}
|
|
|
|
|
2014-12-01 02:34:24 +01:00
|
|
|
/**
|
|
|
|
* @param string $handle
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-05-19 08:17:14 +02:00
|
|
|
public function do_item( $handle ) {
|
2008-05-21 07:56:04 +02:00
|
|
|
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:12:15 +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:24:14 +01:00
|
|
|
/**
|
|
|
|
* Filter the HTML link tag of an enqueued style.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
2015-06-21 21:35:26 +02:00
|
|
|
* @since 4.3.0 Introduced the `$href` parameter.
|
2014-03-28 22:24:14 +01:00
|
|
|
*
|
2015-07-13 23:03:24 +02:00
|
|
|
* @param string $html The link tag for the enqueued style.
|
2014-03-28 22:24:14 +01:00
|
|
|
* @param string $handle The style's registered handle.
|
2015-06-21 21:35:26 +02:00
|
|
|
* @param string $href The stylesheet's source URL.
|
2014-03-28 22:24:14 +01:00
|
|
|
*/
|
2015-06-21 21:35:26 +02:00
|
|
|
$tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle, $href );
|
2011-07-25 02:36:06 +02:00
|
|
|
if ( 'rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl'] ) {
|
2013-11-12 22:19:15 +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-04-25 08:29:14 +02:00
|
|
|
/** This filter is documented in wp-includes/class.wp-styles.php */
|
2015-06-21 21:35:26 +02: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, $rtl_href );
|
2013-11-12 22:19:15 +01:00
|
|
|
|
|
|
|
if ( $obj->extra['rtl'] === 'replace' ) {
|
|
|
|
$tag = $rtl_tag;
|
|
|
|
} else {
|
|
|
|
$tag .= $rtl_tag;
|
|
|
|
}
|
2008-05-22 01:24:23 +02:00
|
|
|
}
|
|
|
|
|
2015-01-03 05:10:21 +01:00
|
|
|
$conditional_pre = $conditional_post = '';
|
|
|
|
if ( isset( $obj->extra['conditional'] ) && $obj->extra['conditional'] ) {
|
|
|
|
$conditional_pre = "<!--[if {$obj->extra['conditional']}]>\n";
|
|
|
|
$conditional_post = "<![endif]-->\n";
|
2013-11-12 22:19:15 +01:00
|
|
|
}
|
2009-01-14 15:18:51 +01:00
|
|
|
|
2011-07-25 02:36:06 +02:00
|
|
|
if ( $this->do_concat ) {
|
2015-01-03 05:10:21 +01:00
|
|
|
$this->print_html .= $conditional_pre;
|
2009-01-14 15:18:51 +01:00
|
|
|
$this->print_html .= $tag;
|
2015-01-03 05:10:21 +01:00
|
|
|
if ( $inline_style = $this->print_inline_style( $handle, false ) ) {
|
2014-10-18 21:04:20 +02:00
|
|
|
$this->print_html .= sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );
|
2015-01-03 05:10:21 +01:00
|
|
|
}
|
|
|
|
$this->print_html .= $conditional_post;
|
2011-07-25 02:36:06 +02:00
|
|
|
} else {
|
2015-01-03 05:10:21 +01:00
|
|
|
echo $conditional_pre;
|
2009-01-14 15:18:51 +01:00
|
|
|
echo $tag;
|
2013-10-15 16:35:09 +02:00
|
|
|
$this->print_inline_style( $handle );
|
2015-01-03 05:10:21 +01:00
|
|
|
echo $conditional_post;
|
2011-07-25 02:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-01 02:34:24 +01:00
|
|
|
/**
|
|
|
|
* @param string $handle
|
|
|
|
* @param string $code
|
|
|
|
*/
|
2014-05-19 08:17:14 +02:00
|
|
|
public function add_inline_style( $handle, $code ) {
|
2014-10-18 19:58:19 +02:00
|
|
|
if ( ! $code ) {
|
2011-07-25 02:36:06 +02:00
|
|
|
return false;
|
2014-10-18 19:58:19 +02:00
|
|
|
}
|
2011-07-25 02:36:06 +02:00
|
|
|
|
2011-07-28 20:24:00 +02:00
|
|
|
$after = $this->get_data( $handle, 'after' );
|
2014-10-18 19:58:19 +02:00
|
|
|
if ( ! $after ) {
|
2011-07-28 20:24:00 +02:00
|
|
|
$after = array();
|
2014-10-18 19:58:19 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2014-12-01 02:34:24 +01:00
|
|
|
/**
|
|
|
|
* @param string $handle
|
|
|
|
* @param bool $echo
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-05-19 08:17:14 +02:00
|
|
|
public function print_inline_style( $handle, $echo = true ) {
|
2011-07-28 20:24:00 +02:00
|
|
|
$output = $this->get_data( $handle, 'after' );
|
|
|
|
|
2014-10-18 19:58:19 +02:00
|
|
|
if ( empty( $output ) ) {
|
2011-07-25 02:36:06 +02:00
|
|
|
return false;
|
2014-10-18 19:58:19 +02:00
|
|
|
}
|
2011-07-25 02:36:06 +02:00
|
|
|
|
2011-07-28 20:24:00 +02:00
|
|
|
$output = implode( "\n", $output );
|
2011-07-25 02:36:06 +02:00
|
|
|
|
2014-10-18 19:58:19 +02:00
|
|
|
if ( ! $echo ) {
|
2011-07-25 02:36:06 +02:00
|
|
|
return $output;
|
2014-10-18 19:58:19 +02:00
|
|
|
}
|
2008-05-21 07:56:04 +02:00
|
|
|
|
2014-10-18 21:04:20 +02:00
|
|
|
printf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $output );
|
2008-05-21 07:56:04 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-01 02:34:24 +01:00
|
|
|
/**
|
|
|
|
* @param mixed $handles
|
|
|
|
* @param bool $recursion
|
|
|
|
* @param mixed $group
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-05-19 08:17:14 +02:00
|
|
|
public 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:24:14 +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:24:14 +01:00
|
|
|
}
|
2008-05-21 07:56:04 +02:00
|
|
|
return $r;
|
|
|
|
}
|
2008-05-22 01:24:23 +02:00
|
|
|
|
2014-12-01 02:34:24 +01:00
|
|
|
/**
|
|
|
|
* @param string $src
|
|
|
|
* @param string $ver
|
|
|
|
* @param string $handle
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-05-19 08:17:14 +02:00
|
|
|
public 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:24:14 +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
|
|
|
}
|
|
|
|
|
2014-12-01 02:34:24 +01:00
|
|
|
/**
|
|
|
|
* @param string $src
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-05-19 08:17:14 +02:00
|
|
|
public function in_default_dir($src) {
|
2009-01-14 15:18:51 +01:00
|
|
|
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
|
|
|
|
2015-05-24 07:05:26 +02:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2014-05-19 08:17:14 +02:00
|
|
|
public function do_footer_items() { // HTML 5 allows styles in the body, grab late enqueued items and output them in the footer.
|
2011-07-21 18:32:01 +02:00
|
|
|
$this->do_items(false, 1);
|
|
|
|
return $this->done;
|
|
|
|
}
|
2009-01-14 15:18:51 +01:00
|
|
|
|
2015-05-29 23:37:24 +02:00
|
|
|
/**
|
|
|
|
* @access public
|
|
|
|
*/
|
2014-05-19 08:17:14 +02:00
|
|
|
public function reset() {
|
2011-07-21 18:32:01 +02:00
|
|
|
$this->do_concat = false;
|
|
|
|
$this->concat = '';
|
|
|
|
$this->concat_version = '';
|
|
|
|
$this->print_html = '';
|
|
|
|
}
|
2008-05-21 07:56:04 +02:00
|
|
|
}
|