PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/class.wp-styles.php

https://bitbucket.org/aqge/deptandashboard
PHP | 171 lines | 121 code | 34 blank | 16 comment | 30 complexity | 9729e8e48b82deab1c5a7f4744b2c5b8 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * BackPress Styles enqueue.
  4. *
  5. * These classes were refactored from the WordPress WP_Scripts and WordPress
  6. * script enqueue API.
  7. *
  8. * @package BackPress
  9. * @since r74
  10. */
  11. /**
  12. * BackPress Styles enqueue class.
  13. *
  14. * @package BackPress
  15. * @uses WP_Dependencies
  16. * @since r74
  17. */
  18. class WP_Styles extends WP_Dependencies {
  19. var $base_url;
  20. var $content_url;
  21. var $default_version;
  22. var $text_direction = 'ltr';
  23. var $concat = '';
  24. var $concat_version = '';
  25. var $do_concat = false;
  26. var $print_html = '';
  27. var $print_code = '';
  28. var $default_dirs;
  29. function __construct() {
  30. do_action_ref_array( 'wp_default_styles', array(&$this) );
  31. }
  32. function do_item( $handle ) {
  33. if ( !parent::do_item($handle) )
  34. return false;
  35. $obj = $this->registered[$handle];
  36. if ( null === $obj->ver )
  37. $ver = '';
  38. else
  39. $ver = $obj->ver ? $obj->ver : $this->default_version;
  40. if ( isset($this->args[$handle]) )
  41. $ver = $ver ? $ver . '&amp;' . $this->args[$handle] : $this->args[$handle];
  42. if ( $this->do_concat ) {
  43. if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) {
  44. $this->concat .= "$handle,";
  45. $this->concat_version .= "$handle$ver";
  46. $this->print_code .= $this->get_data( $handle, 'after' );
  47. return true;
  48. }
  49. }
  50. if ( isset($obj->args) )
  51. $media = esc_attr( $obj->args );
  52. else
  53. $media = 'all';
  54. $href = $this->_css_href( $obj->src, $ver, $handle );
  55. $rel = isset($obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
  56. $title = isset($obj->extra['title']) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : '';
  57. $end_cond = $tag = '';
  58. if ( isset($obj->extra['conditional']) && $obj->extra['conditional'] ) {
  59. $tag .= "<!--[if {$obj->extra['conditional']}]>\n";
  60. $end_cond = "<![endif]-->\n";
  61. }
  62. $tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle );
  63. if ( 'rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl'] ) {
  64. if ( is_bool( $obj->extra['rtl'] ) ) {
  65. $suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : '';
  66. $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src , $ver, "$handle-rtl" ));
  67. } else {
  68. $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" );
  69. }
  70. $tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-rtl-css' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle );
  71. }
  72. $tag .= $end_cond;
  73. if ( $this->do_concat ) {
  74. $this->print_html .= $tag;
  75. $this->print_html .= $this->print_inline_style( $handle, false );
  76. } else {
  77. echo $tag;
  78. $this->print_inline_style( $handle );
  79. }
  80. return true;
  81. }
  82. function add_inline_style( $handle, $code ) {
  83. if ( !$code )
  84. return false;
  85. $after = $this->get_data( $handle, 'after' );
  86. if ( !$after )
  87. $after = array();
  88. $after[] = $code;
  89. return $this->add_data( $handle, 'after', $after );
  90. }
  91. function print_inline_style( $handle, $echo = true ) {
  92. $output = $this->get_data( $handle, 'after' );
  93. if ( empty( $output ) )
  94. return false;
  95. $output = implode( "\n", $output );
  96. if ( !$echo )
  97. return $output;
  98. echo "<style type='text/css'>\n";
  99. echo "$output\n";
  100. echo "</style>\n";
  101. return true;
  102. }
  103. function all_deps( $handles, $recursion = false, $group = false ) {
  104. $r = parent::all_deps( $handles, $recursion );
  105. if ( !$recursion )
  106. $this->to_do = apply_filters( 'print_styles_array', $this->to_do );
  107. return $r;
  108. }
  109. function _css_href( $src, $ver, $handle ) {
  110. if ( !is_bool($src) && !preg_match('|^https?://|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {
  111. $src = $this->base_url . $src;
  112. }
  113. if ( !empty($ver) )
  114. $src = add_query_arg('ver', $ver, $src);
  115. $src = apply_filters( 'style_loader_src', $src, $handle );
  116. return esc_url( $src );
  117. }
  118. function in_default_dir($src) {
  119. if ( ! $this->default_dirs )
  120. return true;
  121. foreach ( (array) $this->default_dirs as $test ) {
  122. if ( 0 === strpos($src, $test) )
  123. return true;
  124. }
  125. return false;
  126. }
  127. function do_footer_items() { // HTML 5 allows styles in the body, grab late enqueued items and output them in the footer.
  128. $this->do_items(false, 1);
  129. return $this->done;
  130. }
  131. function reset() {
  132. $this->do_concat = false;
  133. $this->concat = '';
  134. $this->concat_version = '';
  135. $this->print_html = '';
  136. }
  137. }