1. <?php /* You really don't want to touch this file if you don't know what you're doing. */ ?>
  2.  
  3. <?php
  4.  
  5. class WP_LESS_Styles extends WP_Dependencies {
  6. var $base_url;
  7. var $content_url;
  8. var $default_version;
  9. var $text_direction = 'ltr';
  10. var $concat = '';
  11. var $concat_version = '';
  12. var $do_concat = false;
  13. var $print_html = '';
  14. var $default_dirs;
  15.  
  16. function __construct() {
  17. do_action_ref_array( 'wp_default_less_styles', array(&$this) );
  18. }
  19.  
  20. function do_item( $handle ) {
  21. if ( !parent::do_item($handle) )
  22. return false;
  23.  
  24. if ( null === $this->registered[$handle]->ver )
  25. $ver = '';
  26. else
  27. $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version;
  28.  
  29. if ( isset($this->args[$handle]) )
  30. $ver = $ver ? $ver . '&amp;' . $this->args[$handle] : $this->args[$handle];
  31.  
  32. if ( $this->do_concat ) {
  33. if ( $this->in_default_dir($this->registered[$handle]->src) && !isset($this->registered[$handle]->extra['conditional']) && !isset($this->registered[$handle]->extra['alt']) ) {
  34. $this->concat .= "$handle,";
  35. $this->concat_version .= "$handle$ver";
  36. return true;
  37. }
  38. }
  39.  
  40. if ( isset($this->registered[$handle]->args) )
  41. $media = esc_attr( $this->registered[$handle]->args );
  42. else
  43. $media = 'all';
  44.  
  45. $href = $this->_css_href( $this->registered[$handle]->src, $ver, $handle );
  46. $rel = isset($this->registered[$handle]->extra['alt']) && $this->registered[$handle]->extra['alt'] ? 'alternate stylesheet' : 'stylesheet/less';
  47. $title = isset($this->registered[$handle]->extra['title']) ? "title='" . esc_attr( $this->registered[$handle]->extra['title'] ) . "'" : '';
  48.  
  49. $end_cond = $tag = '';
  50. if ( isset($this->registered[$handle]->extra['conditional']) && $this->registered[$handle]->extra['conditional'] ) {
  51. $tag .= "<!--[if {$this->registered[$handle]->extra['conditional']}]>\n";
  52. $end_cond = "<![endif]-->\n";
  53. }
  54.  
  55. $tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' href='$href' media='screen' />\n", $handle );
  56. if ( 'rtl' === $this->text_direction && isset($this->registered[$handle]->extra['rtl']) && $this->registered[$handle]->extra['rtl'] ) {
  57. if ( is_bool( $this->registered[$handle]->extra['rtl'] ) ) {
  58. $suffix = isset( $this->registered[$handle]->extra['suffix'] ) ? $this->registered[$handle]->extra['suffix'] : '';
  59. $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $this->registered[$handle]->src , $ver, "$handle-rtl" ));
  60. } else {
  61. $rtl_href = $this->_css_href( $this->registered[$handle]->extra['rtl'], $ver, "$handle-rtl" );
  62. }
  63.  
  64. $tag .= apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-rtl-css' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle );
  65. }
  66.  
  67. $tag .= $end_cond;
  68.  
  69. if ( $this->do_concat )
  70. $this->print_html .= $tag;
  71. else
  72. echo $tag;
  73.  
  74. return true;
  75. }
  76.  
  77. function all_deps( $handles, $recursion = false, $group = false ) {
  78. $r = parent::all_deps( $handles, $recursion );
  79. if ( !$recursion )
  80. $this->to_do = apply_filters( 'print_less_styles_array', $this->to_do );
  81. return $r;
  82. }
  83.  
  84. function _css_href( $src, $ver, $handle ) {
  85. if ( !is_bool($src) && !preg_match('|^https?://|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {
  86. $src = $this->base_url . $src;
  87. }
  88.  
  89. if ( !empty($ver) )
  90. $src = add_query_arg('ver', $ver, $src);
  91. $src = apply_filters( 'style_loader_src', $src, $handle );
  92. return esc_url( $src );
  93. }
  94.  
  95. function in_default_dir($src) {
  96. if ( ! $this->default_dirs )
  97. return true;
  98.  
  99. foreach ( (array) $this->default_dirs as $test ) {
  100. if ( 0 === strpos($src, $test) )
  101. return true;
  102. }
  103. return false;
  104. }
  105. }
  106.