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 {
|
2014-05-19 02:17:14 -04: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 17:24:14 -04: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 01:56:04 -04:00
|
|
|
do_action_ref_array( 'wp_default_styles', array(&$this) );
|
|
|
|
}
|
|
|
|
|
2014-11-30 20:34:24 -05:00
|
|
|
/**
|
|
|
|
* @param string $handle
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-05-19 02:17:14 -04:00
|
|
|
public function do_item( $handle ) {
|
2008-05-21 01:56:04 -04:00
|
|
|
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
|
|
|
|
2013-04-22 15:22:09 -04:00
|
|
|
$this->print_code .= $this->print_inline_style( $handle, false );
|
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';
|
|
|
|
|
2016-02-17 12:11:26 -05:00
|
|
|
// A single item may alias a set of items, by having dependencies, but no source.
|
|
|
|
if ( ! $obj->src ) {
|
|
|
|
if ( $inline_style = $this->print_inline_style( $handle, false ) ) {
|
|
|
|
$inline_style = sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style );
|
|
|
|
if ( $this->do_concat ) {
|
|
|
|
$this->print_html .= $inline_style;
|
|
|
|
} else {
|
|
|
|
echo $inline_style;
|
|
|
|
}
|
|
|
|
}
|
2014-03-12 12:12:15 -04:00
|
|
|
return true;
|
|
|
|
}
|
2016-02-17 12:11:26 -05:00
|
|
|
|
|
|
|
$href = $this->_css_href( $obj->src, $ver, $handle );
|
2016-02-19 15:34:26 -05:00
|
|
|
if ( ! $href ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-24 20:36:06 -04: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-21 19:24:23 -04:00
|
|
|
|
2014-03-28 17:24:14 -04:00
|
|
|
/**
|
|
|
|
* Filter the HTML link tag of an enqueued style.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
2015-06-21 15:35:26 -04:00
|
|
|
* @since 4.3.0 Introduced the `$href` parameter.
|
2014-03-28 17:24:14 -04:00
|
|
|
*
|
2015-07-13 17:03:24 -04:00
|
|
|
* @param string $html The link tag for the enqueued style.
|
2014-03-28 17:24:14 -04:00
|
|
|
* @param string $handle The style's registered handle.
|
2015-06-21 15:35:26 -04:00
|
|
|
* @param string $href The stylesheet's source URL.
|
2014-03-28 17:24:14 -04:00
|
|
|
*/
|
2015-06-21 15:35:26 -04: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-24 20:36:06 -04:00
|
|
|
if ( 'rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl'] ) {
|
2013-11-12 16:19:15 -05:00
|
|
|
if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) {
|
2011-07-24 20:36:06 -04: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-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
|
|
|
|
2014-04-25 02:29:14 -04:00
|
|
|
/** This filter is documented in wp-includes/class.wp-styles.php */
|
2015-06-21 15:35:26 -04: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 16:19:15 -05:00
|
|
|
|
|
|
|
if ( $obj->extra['rtl'] === 'replace' ) {
|
|
|
|
$tag = $rtl_tag;
|
|
|
|
} else {
|
|
|
|
$tag .= $rtl_tag;
|
|
|
|
}
|
2008-05-21 19:24:23 -04:00
|
|
|
}
|
|
|
|
|
2015-01-02 23:10:21 -05: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 16:19:15 -05:00
|
|
|
}
|
2009-01-14 09:18:51 -05:00
|
|
|
|
2011-07-24 20:36:06 -04:00
|
|
|
if ( $this->do_concat ) {
|
2015-01-02 23:10:21 -05:00
|
|
|
$this->print_html .= $conditional_pre;
|
2009-01-14 09:18:51 -05:00
|
|
|
$this->print_html .= $tag;
|
2015-01-02 23:10:21 -05:00
|
|
|
if ( $inline_style = $this->print_inline_style( $handle, false ) ) {
|
2014-10-18 15:04:20 -04: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-02 23:10:21 -05:00
|
|
|
}
|
|
|
|
$this->print_html .= $conditional_post;
|
2011-07-24 20:36:06 -04:00
|
|
|
} else {
|
2015-01-02 23:10:21 -05:00
|
|
|
echo $conditional_pre;
|
2009-01-14 09:18:51 -05:00
|
|
|
echo $tag;
|
2013-10-15 10:35:09 -04:00
|
|
|
$this->print_inline_style( $handle );
|
2015-01-02 23:10:21 -05:00
|
|
|
echo $conditional_post;
|
2011-07-24 20:36:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-30 20:34:24 -05:00
|
|
|
/**
|
|
|
|
* @param string $handle
|
|
|
|
* @param string $code
|
|
|
|
*/
|
2014-05-19 02:17:14 -04:00
|
|
|
public function add_inline_style( $handle, $code ) {
|
2014-10-18 13:58:19 -04:00
|
|
|
if ( ! $code ) {
|
2011-07-24 20:36:06 -04:00
|
|
|
return false;
|
2014-10-18 13:58:19 -04:00
|
|
|
}
|
2011-07-24 20:36:06 -04:00
|
|
|
|
2011-07-28 14:24:00 -04:00
|
|
|
$after = $this->get_data( $handle, 'after' );
|
2014-10-18 13:58:19 -04:00
|
|
|
if ( ! $after ) {
|
2011-07-28 14:24:00 -04:00
|
|
|
$after = array();
|
2014-10-18 13:58:19 -04:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2014-11-30 20:34:24 -05:00
|
|
|
/**
|
|
|
|
* @param string $handle
|
|
|
|
* @param bool $echo
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-05-19 02:17:14 -04:00
|
|
|
public function print_inline_style( $handle, $echo = true ) {
|
2011-07-28 14:24:00 -04:00
|
|
|
$output = $this->get_data( $handle, 'after' );
|
|
|
|
|
2014-10-18 13:58:19 -04:00
|
|
|
if ( empty( $output ) ) {
|
2011-07-24 20:36:06 -04:00
|
|
|
return false;
|
2014-10-18 13:58:19 -04:00
|
|
|
}
|
2011-07-24 20:36:06 -04:00
|
|
|
|
2011-07-28 14:24:00 -04:00
|
|
|
$output = implode( "\n", $output );
|
2011-07-24 20:36:06 -04:00
|
|
|
|
2014-10-18 13:58:19 -04:00
|
|
|
if ( ! $echo ) {
|
2011-07-24 20:36:06 -04:00
|
|
|
return $output;
|
2014-10-18 13:58:19 -04:00
|
|
|
}
|
2008-05-21 01:56:04 -04:00
|
|
|
|
2014-10-18 15:04:20 -04:00
|
|
|
printf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $output );
|
2008-05-21 01:56:04 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-30 20:34:24 -05:00
|
|
|
/**
|
|
|
|
* @param mixed $handles
|
|
|
|
* @param bool $recursion
|
|
|
|
* @param mixed $group
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-05-19 02:17:14 -04:00
|
|
|
public function all_deps( $handles, $recursion = false, $group = false ) {
|
2008-05-21 01:56:04 -04:00
|
|
|
$r = parent::all_deps( $handles, $recursion );
|
2014-03-28 17:24:14 -04: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 01:56:04 -04:00
|
|
|
$this->to_do = apply_filters( 'print_styles_array', $this->to_do );
|
2014-03-28 17:24:14 -04:00
|
|
|
}
|
2008-05-21 01:56:04 -04:00
|
|
|
return $r;
|
|
|
|
}
|
2008-05-21 19:24:23 -04:00
|
|
|
|
2014-11-30 20:34:24 -05:00
|
|
|
/**
|
|
|
|
* @param string $src
|
|
|
|
* @param string $ver
|
|
|
|
* @param string $handle
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-05-19 02:17:14 -04:00
|
|
|
public function _css_href( $src, $ver, $handle ) {
|
2012-06-28 16:18:38 -04: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);
|
2014-03-28 17:24:14 -04: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-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
|
|
|
}
|
|
|
|
|
2014-11-30 20:34:24 -05:00
|
|
|
/**
|
|
|
|
* @param string $src
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-05-19 02:17:14 -04:00
|
|
|
public function in_default_dir($src) {
|
2009-01-14 09:18:51 -05: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 14:24:00 -04:00
|
|
|
|
2015-05-24 01:05:26 -04:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2014-05-19 02:17:14 -04: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 12:32:01 -04:00
|
|
|
$this->do_items(false, 1);
|
|
|
|
return $this->done;
|
|
|
|
}
|
2009-01-14 09:18:51 -05:00
|
|
|
|
2015-05-29 17:37:24 -04:00
|
|
|
/**
|
|
|
|
* @access public
|
|
|
|
*/
|
2014-05-19 02:17:14 -04:00
|
|
|
public function reset() {
|
2011-07-21 12:32:01 -04:00
|
|
|
$this->do_concat = false;
|
|
|
|
$this->concat = '';
|
|
|
|
$this->concat_version = '';
|
|
|
|
$this->print_html = '';
|
|
|
|
}
|
2008-05-21 01:56:04 -04:00
|
|
|
}
|