Head Cleaner - Version 1.3.14

Version Description

Download this release

Release Info

Developer wokamoto
Plugin Icon wp plugin Head Cleaner
Version 1.3.14
Comparing to
See all releases

Code changes from version 1.3.13 to 1.3.14

head-cleaner.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: Head Cleaner
4
- Version: 1.3.13
5
  Plugin URI: http://wppluginsj.sourceforge.jp/head-cleaner/
6
  Description: Cleaning tags from your WordPress header and footer.
7
  Author: wokamoto
@@ -65,83 +65,8 @@ if (!defined('HC_RAW_SHORTCODE'))
65
 
66
  //**************************************************************************************
67
  if (!defined('ABSPATH') && strstr($_SERVER['PHP_SELF'], '/head-cleaner.php')) {
68
- define('HC_EXPIRED_JS_CSS', 2592000); // 60 * 60 * 24 * 30 [sec.]
69
-
70
- $error = false;
71
- if (isset($_GET['f']) && isset($_GET['t'])) {
72
- $cache_dir = realpath(dirname(__FILE__) . '/../../' . HC_CACHE_DIR) . '/';
73
- $filename_hash = trim(stripslashes($_GET['f']));
74
- $type = trim(stripslashes($_GET['t']));
75
-
76
- if (strlen($filename_hash) == 32 && ($type == 'js' || $type == 'css')) {
77
- $is_gzip = (strpos(strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') !== FALSE);
78
- $ob_gzip = false;
79
-
80
- $filename = "{$cache_dir}{$type}/{$filename_hash}.{$type}";
81
- if ($is_gzip && file_exists($filename.'.gz'))
82
- $filename .= '.gz';
83
- else
84
- $ob_gzip = $is_gzip;
85
-
86
- if (file_exists($filename)) {
87
- $offset = (!defined('HC_EXPIRED_JS_CSS') ? HC_EXPIRED_JS_CSS : 60 * 60 * 24 * 30);
88
- $content_type = 'text/' . ($type == 'js' ? 'javascript' : $type);
89
-
90
- header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($filename)).' GMT');
91
- header('Expires: '.gmdate('D, d M Y H:i:s', time() + $offset).' GMT');
92
- header("Content-type: $content_type");
93
-
94
- if ($is_gzip)
95
- header('Content-Encoding: gzip');
96
-
97
- if ($ob_gzip)
98
- ob_start("ob_gzhandler");
99
-
100
- readfile($filename);
101
-
102
- if ($ob_gzip)
103
- ob_end_flush();
104
-
105
- $error = false;
106
- } else {
107
- $error = 404;
108
- }
109
- } else {
110
- $error = 403;
111
- }
112
- } else {
113
- $error = 403;
114
- }
115
-
116
- if ( $error === FALSE ) {
117
- exit();
118
- } else {
119
- if(!function_exists('get_option')) {
120
- $path = (defined('ABSPATH') ? ABSPATH : dirname(dirname(dirname(dirname(__FILE__)))) . '/');
121
- require_once(file_exists($path.'wp-load.php') ? $path.'wp-load.php' : $path.'wp-config.php');
122
- }
123
-
124
- $err_msg = "Unknown Error";
125
- switch ($error) {
126
- case 403:
127
- header("HTTP/1.0 403 Forbidden");
128
- $err_msg = "403 : Forbidden";
129
- break;
130
- case 404:
131
- header('HTTP/1.1 404 Not Found');
132
- $err_msg = "404 : Not Found";
133
- break;
134
- default:
135
- break;
136
- }
137
-
138
- if (function_exists('wp_die')) {
139
- wp_die($err_msg);
140
- } else {
141
- echo $err_msg;
142
- die();
143
- }
144
- }
145
  }
146
 
147
  //**************************************************************************************
@@ -155,7 +80,7 @@ if (!class_exists('wokController') || !class_exists('wokScriptManager'))
155
  //**************************************************************************************
156
  class HeadCleaner extends wokController {
157
  public $plugin_name = 'head-cleaner';
158
- public $plugin_ver = '1.3.13';
159
 
160
  // Deafault Options
161
  private $options_default = array(
@@ -204,6 +129,9 @@ class HeadCleaner extends wokController {
204
  private $foot_js_src;
205
 
206
  private $mtime_start;
 
 
 
207
 
208
  private $filters;
209
  private $head_js;
@@ -241,7 +169,7 @@ class HeadCleaner extends wokController {
241
 
242
  $this->wp_url = trailingslashit($this->_get_site_url());
243
  $this->root_url = preg_replace('/^(https?:\/\/[^\/]*\/).*$/i', '$1', $this->wp_url);
244
- $this->self_url = str_replace(ABSPATH, $this->wp_url, __FILE__);
245
  $this->lang = (defined('WPLANG') ? WPLANG : 'ja');
246
  $this->charset = get_option('blog_charset');
247
  $this->_get_filters('wp_head');
@@ -271,6 +199,7 @@ class HeadCleaner extends wokController {
271
  // Require PHP Libraries
272
  $this->_require_libraries();
273
 
 
274
  add_action('get_header', array(&$this, 'head_start'));
275
  add_action('wp_footer', array(&$this, 'filters_save'), 11);
276
 
@@ -278,11 +207,11 @@ class HeadCleaner extends wokController {
278
  if (HC_RAW_SHORTCODE) {
279
  remove_filter('the_content', 'wpautop');
280
  remove_filter('the_content', 'wptexturize');
281
- add_filter('the_content', array(&$head_cleaner, 'raw_formatter'), 99);
282
 
283
  remove_filter('the_excerpt', 'wpautop');
284
  remove_filter('the_excerpt', 'wptexturize');
285
- add_filter('the_excerpt', array(&$head_cleaner, 'raw_formatter'), 99);
286
  }
287
  }
288
  }
@@ -321,6 +250,7 @@ class HeadCleaner extends wokController {
321
  $wk_options['head_js'] = $head_js;
322
  $wk_options['analyze_expired'] = time() + HC_ANALYZE_EXPIRED;
323
  }
 
324
  return $wk_options;
325
  }
326
 
@@ -468,8 +398,7 @@ class HeadCleaner extends wokController {
468
  if ( $this->options['filters'] != $this->filters || $this->options['head_js'] != $this->head_js ) {
469
  $this->options['filters'] = $this->filters;
470
  $this->options['head_js'] = $this->head_js;
471
- if (time() > $this->options['analyze_expired'])
472
- $this->options['analyze_expired'] = time() + HC_ANALYZE_EXPIRED;
473
  $this->updateOptions();
474
  }
475
  }
@@ -479,78 +408,107 @@ class HeadCleaner extends wokController {
479
  // head cleaner
480
  //**************************************************************************************
481
  public function head_cleaner($buffer) {
 
482
  if (!function_exists('str_get_html'))
483
- return trim($buffer) . "\n";
484
 
485
- $buffer = $this->ob_handler($buffer);
 
 
 
486
 
 
487
  $url = $this->_get_permalink();
488
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
489
  if (preg_match('/<!DOCTYPE [^>]* XHTML [^>]*>/i', $buffer)) {
490
  // xhtml
491
- $doctype = 'xhtml';
492
- $xml_head = "<?xml version=\"1.0\" encoding=\"{$this->charset}\"?>\n";
493
- $html_tag = "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"{$this->lang}\" lang=\"{$this->lang}\">\n";
494
- $head_tag = '<head profile="http://gmpg.org/xfn/11">'."\n";
 
495
  } else {
496
  // html
497
- $doctype = 'html';
498
- $xml_head = '';
499
- $html_tag = "<html dir=\"ltr\" lang=\"{$this->lang}\">\n";
500
- $head_tag = '<head>'."\n";
501
  }
502
- $head_txt = trim($buffer);
503
 
504
- $ret_val = '';
505
- $meta_tag = ''; $title_tag = ''; $base_tag = '';
506
- $link_tag = ''; $object_tag = ''; $other_tag = '';
507
- $css_tag = ''; $inline_css = '';
508
- $script_tag = ''; $inline_js = '';
 
 
 
 
 
 
 
509
 
510
  // for IE conditional tag
511
  list($head_txt, $IE_conditional_tags, $ie6) = $this->_parse_IE_conditional_tags($head_txt);
512
 
513
  // Get Simple DOM Object
514
  if (preg_match('/^(.*)(<html[^>]*>[^<]*)(<head[^>]*>[^<]*)(.*)$/ism', $head_txt, $matches)) {
515
- $ret_val = trim($matches[1]) . "\n";
516
- $html_tag = trim($matches[2]) . "\n";
517
- $head_tag = trim($matches[3]) . "\n";
518
- $head_txt = trim($matches[4]) . "\n";
519
  }
520
  unset($matches);
521
- $html_txt = $xml_head . $html_tag . $head_tag
522
- . $head_txt
523
- . '</head><body></body></html>';
524
 
525
- $dom = str_get_html($html_txt);
 
 
 
526
  if ($dom === false)
527
- return (trim($buffer)."\n");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
528
 
529
- // Parse Start!
530
- if ( $doctype === 'xhtml' ) {
531
- // xhtml
532
- $xmlns = (defined('HC_XMLNS') ? HC_XMLNS : 'http://www.w3.org/1999/xhtml');
533
- $xml_lang = $this->lang;
534
- $lang = $this->lang;
535
  if (preg_match_all('/ +([^ ]*)=[\'"]([^\'"]*)[\'"]/', $html_tag, $matches, PREG_SET_ORDER)) {
536
  foreach ((array) $matches as $match) {
537
  switch ($match[1]){
538
  case 'xmlns': $xmlns = $match[2]; break;
539
  case 'xml:lang': $xml_lang = $match[2]; break;
540
  case 'lang': $lang = $match[2]; break;
541
- }
542
- }
543
- unset($match);
544
- }
545
- unset($matches);
546
- $html_tag = "<html xmlns=\"{$xmlns}\" xml:lang=\"{$xml_lang}\" lang=\"{$lang}\">\n";
547
- } else {
548
- // html
549
- $dir = 'ltr';
550
- $lang = $this->lang;
551
- if (preg_match_all('/ +([^ ]*)=[\'"]([^\'"]*)[\'"]/', $html_tag, $matches, PREG_SET_ORDER)) {
552
- foreach ((array) $matches as $match) {
553
- switch ($match[1]){
554
  case 'dir': $dir = $match[2]; break;
555
  case 'lang': $lang = $match[2]; break;
556
  }
@@ -558,35 +516,40 @@ class HeadCleaner extends wokController {
558
  unset($match);
559
  }
560
  unset($matches);
561
- $html_tag = "<html dir=\"{$dir}\" lang=\"{$lang}\">\n";
 
 
 
562
  }
563
 
564
- $meta_tag = $this->_dom_to_html($dom->find("meta"));
565
- $title_tag = $this->_dom_to_html($dom->find("title"), 1);
566
- $base_tag = $this->_dom_to_html($dom->find("base"), 1);
567
- $link_tag = $this->_dom_to_html($dom->find("link[rel!='stylesheet']"));
568
  if (count($dom->find("link[rel='canonical']")) <= 0 && $this->options['canonical_tag'])
569
- $link_tag .= '<link rel="canonical" href="' . htmlspecialchars($url, ENT_QUOTES) . '" />'."\n";
570
- $object_tag = $this->_dom_to_html($dom->find("object"));
571
- list($css_tag, $css_tag_with_id, $inner_css, $css_src, $inline_css) = $this->_parse_stylesheet_tag($dom->find("link[rel='stylesheet']"),$dom->find("style"));
572
- list($script_tag, $inner_js, $inline_js, $foot_js) = $this->_parse_script_tag($dom->find("script"));
 
573
 
574
- $dom->clear(); unset($dom);
 
575
 
576
  // for IE conditional tag
577
  if (!$this->options['ie_conditional'] && count($IE_conditional_tags) > 0) {
578
  $IE_conditional_tag_pattern = '/(<\!-+[ \t]*\[if[ \t]+.*IE.*[ \t]*?\][ \t]*>)[ \t\r\n]*(.*?)[ \t\r\n]*(<\![ \t]*\[endif\][ \t]*-+>)/ims';
579
  foreach ((array) $IE_conditional_tags as $IE_conditional_tag) {
580
  if (isset($IE_conditional_tag[0])) {
581
- $IE_tag = trim(preg_replace($IE_conditional_tag_pattern, "$1$2$3", $IE_conditional_tag[0]));
582
  if ( strpos(strtolower($IE_tag), '<link') !== false )
583
- $css_tag = trim($css_tag) . "\n" . $IE_tag . "\n";
584
  elseif ( strpos(strtolower($IE_tag), '<style') !== false )
585
- $inline_css = trim($inline_css) . "\n" . $IE_tag . "\n";
586
  elseif ( strpos(strtolower($IE_tag), '<script') !== false )
587
- $inline_js = trim($inline_js) . "\n" . $IE_tag . "\n";
588
  elseif ( !empty($IE_tag) )
589
- $object_tag = trim($object_tag) . "\n" . $IE_tag . "\n";
590
  }
591
  }
592
  }
@@ -594,54 +557,51 @@ class HeadCleaner extends wokController {
594
 
595
  // Build!
596
  $ret_val .=
597
- $html_tag
598
- . $head_tag
599
- . $meta_tag
600
- . $title_tag
601
- . $base_tag
602
- . $link_tag
603
- . $css_tag
604
- . $inline_css
605
- . (!$this->options['js_move_foot'] ? $script_tag : '')
606
- . (!$this->options['js_move_foot'] ? $inline_js : '')
607
- . $object_tag
608
- ;
609
- //$ret_val = str_replace('\'', '"', $ret_val);
610
- $ret_val = preg_replace(
611
- array( "/[\s]+([^\=]+)\='([^']*)'/i", '/[\n\r]+/i', '/(<\/[^>]+>)[ \t]*(<[^>]+)/i' ) ,
612
- array( ' $1="$2"', "\n", "$1\n$2" ),
613
- $ret_val
614
- );
615
-
616
- if ($this->options['js_move_foot'] || !empty($foot_js))
617
- $this->foot_js_src = trim(
618
- $foot_js
619
- . ($this->options['js_move_foot'] ? $script_tag : '')
620
- . ($this->options['js_move_foot'] ? $inline_js : '')
621
- );
622
- if (!empty($this->foot_js_src)) {
623
- $this->foot_js_src .= "\n";
624
  add_action('wp_footer', array(&$this, 'footer'), 9);
625
- }
626
 
627
- if ($this->options['dynamic']) {
628
- $ret_val = preg_replace(
629
- '/' . preg_quote($this->cache_url, '/') . '(js|css)\/([^\.]*)\.(js|css)/i' ,
630
- $this->self_url . "?f=$2&amp;t=$3" ,
631
- $ret_val
632
- );
633
- }
634
 
 
635
  $ret_val = ($ie6 || !$this->options['xml_declaration']
636
  ? preg_replace('/^<\?xml[^>]*>/i', '', $ret_val)
637
- : (strpos($ret_val, '<?xml') === false ? $xml_head : '') . $ret_val
638
  );
639
- // $ret_val = str_replace($this->root_url, '/', $ret_val);
640
- $ret_val = trim($ret_val) . "\n";
641
 
 
642
  if ($this->options['debug_mode'])
643
  $ret_val .= $this->_get_debug_info($buffer);
644
 
 
 
 
 
 
 
 
645
  return $ret_val;
646
  }
647
 
@@ -650,11 +610,10 @@ class HeadCleaner extends wokController {
650
  //**************************************************************************************
651
  private function _parse_IE_conditional_tags($head_txt){
652
  // Check USER AGENT
653
- $ua = trim(strtolower($_SERVER['HTTP_USER_AGENT']));
654
- $ie = (strpos($ua, 'msie') !== false)
655
- && (! preg_match('/(gecko|applewebkit|opera|sleipnir|chrome)/i', $ua));
656
  $ie_ver = ($ie ? preg_replace('/^.*msie +([\d+\.]+);.*$/i', '$1', $ua) : false);
657
- $ie6 = ($ie ? version_compare($ie_ver, '7.0', '<') : false);
658
 
659
  $IE_conditional_tags = array();
660
  if ($this->options['ie_conditional']) {
@@ -686,8 +645,8 @@ class HeadCleaner extends wokController {
686
  $replace_patterns[] = sprintf($IE_conditional_tag_pattern, '(gte?[ \t]*)', ' [567]\.?0?'); // > 5 - 7, >= 5 - 7
687
  $replace_patterns[] = sprintf($IE_conditional_tag_pattern, '(gte?[ \t]*)', ' 5\.5'); // > 5.5, >= 5.5
688
  } elseif (version_compare($ie_ver, '10.0', '<')) { // IE 9
689
- $replace_patterns[] = sprintf($IE_conditional_tag_pattern, '([lg]te[ \t]*|[ \t]*)', ' 9\.?0?'); // >= 8, <= 8, = 8
690
- $replace_patterns[] = sprintf($IE_conditional_tag_pattern, '(gte?[ \t]*)', ' [5678]\.?0?'); // > 5 - 7, >= 5 - 7
691
  $replace_patterns[] = sprintf($IE_conditional_tag_pattern, '(gte?[ \t]*)', ' 5\.5'); // > 5.5, >= 5.5
692
  }
693
 
@@ -710,6 +669,7 @@ class HeadCleaner extends wokController {
710
  private function _parse_stylesheet_tag($elements_linktag, $elements_styletag){
711
  $css_tag = '';
712
  $css_tag_with_id = '';
 
713
  $inner_css = '';
714
  $css_src = array();
715
  $wk_inline_css = array();
@@ -720,13 +680,19 @@ class HeadCleaner extends wokController {
720
  $tag = trim($element->outertext);
721
  if (strpos($css_tag, $tag) === FALSE) {
722
  if (strpos($element->href, $this->wp_url) === FALSE) {
723
- $css_tag .= trim($tag) . "\n";
724
  } elseif ( isset($element->id) && !empty($element->id) ) {
725
- $css_tag_with_id .= trim($tag) . "\n";
 
 
726
  } else {
727
- $media = trim( isset($element->media) ? $element->media : $this->options['default_media'] );
728
- $media = ( empty($media) || is_null($media) || $media === FALSE ? $this->options['default_media'] : $media );
729
- $inner_css .= trim($tag) . "\n";
 
 
 
 
730
  $css_src[$media][] = $element->href;
731
  }
732
  }
@@ -742,7 +708,7 @@ class HeadCleaner extends wokController {
742
  foreach ($wk_matches as $val) {
743
  $wk_text = trim(str_replace( $val[0], '', $wk_text));
744
  $href = trim($val[1]);
745
- $tag = "<link rel=\"stylesheet\" href=\"{$href}\" type=\"text/css\" media=\"{$media}\" />";
746
  if (strpos( $href, $this->wp_url) === FALSE) {
747
  $css_tag .= $tag . "\n";
748
  } else {
@@ -754,56 +720,64 @@ class HeadCleaner extends wokController {
754
  unset($wk_matches);
755
  if ( !empty($wk_text) ) {
756
  if ( !isset($wk_inline_css[$media]) )
757
- $wk_inline_css[$media] = trim($wk_text) . "\n";
758
  else
759
- $wk_inline_css[$media] .= trim($wk_text) . "\n";
760
  }
761
  }
762
  if ($this->options['cache_enabled']) {
763
  if ($this->options['combined_css']) {
764
- $css_tag = trim($css_tag) . "\n";
765
  foreach ($css_src as $key => $val) {
766
  $inner_css = $this->_combined_css($val, trim(isset($wk_inline_css[$key]) ? $wk_inline_css[$key] : '' ), $key);
767
- $css_tag .= trim($inner_css) . "\n" . trim($css_tag_with_id) . "\n";
768
- if (isset($wk_inline_css[$key])) $wk_inline_css[$key] = '';
 
 
 
 
769
  }
770
  foreach ($wk_inline_css as $key => $val) {
771
  $val = trim($val);
772
  if (!empty($val)) {
773
  $inner_css = $this->_combined_css(array(), $val, $key);
774
- $css_tag .= trim($inner_css) . "\n";
775
  }
776
  }
 
777
  } else {
778
- $css_tag = trim($css_tag) . "\n" . trim($inner_css) . "\n" . trim($css_tag_with_id) . "\n";
 
 
 
 
779
  foreach ($wk_inline_css as $key => $val) {
780
  $val = trim($val);
781
  if (!empty($val)) {
782
  $inner_css = $this->_combined_inline_css(trim($val), $key);
783
- $inline_css .= trim($inner_css) . "\n";
784
  }
785
  }
786
  }
787
  } else {
788
- $css_tag = trim($css_tag) . "\n" . trim($inner_css) . "\n" . trim($css_tag_with_id) . "\n";
 
 
 
 
789
  foreach ($wk_inline_css as $key => $val) {
790
  $val = trim($val);
791
- if (!empty($val)) {
792
- $inline_css .=
793
- '<style type="text/css"' . (!empty($media) ? " media=\"{$media}\"" : '') . ">/*<![CDATA[ */\n" .
794
- $val .
795
- "\n/* ]]>*/</style>\n";
796
- }
797
  }
798
  }
799
  unset($wk_inline_css);
800
  unset($element);
801
 
802
- $css_tag = trim($css_tag) . (!empty($css_tag) ? "\n" : '');
803
- $inner_css = trim($inner_css) . (!empty($inner_css) ? "\n" : '');
804
- $inline_css = trim($inline_css) . (!empty($inline_css) ? "\n" : '');
805
 
806
- return array($css_tag, $css_tag_with_id, $inner_css, $css_src, $inline_css);
807
  }
808
 
809
  //**************************************************************************************
@@ -846,11 +820,11 @@ class HeadCleaner extends wokController {
846
  $version = '1';
847
  $js_libs[$product][$version] = $src;
848
  } elseif ($this->head_js[$src] === FALSE) {
849
- $foot_js .= trim($element->outertext) . "\n";
850
  } elseif (strpos($src, $this->wp_url) === FALSE) {
851
- $script_tag .= trim($element->outertext) . "\n";
852
  } else {
853
- $inner_js .= trim($element->outertext) . "\n";
854
  $js_src[] = $element->src;
855
  }
856
  }
@@ -865,34 +839,33 @@ class HeadCleaner extends wokController {
865
  if (count($js_libs_src) > 0)
866
  $js_src = array_merge($js_libs_src, $js_src);
867
 
868
- $script_tag = trim($script_tag) . "\n" . $wk_outer_js;
869
  $inner_js = $wk_inner_js . $inner_js;
870
 
871
  unset($js_libs_src);
872
  unset($js_libs);
873
  }
874
 
875
- $inline_js = trim($inline_js);
876
  if ($this->options['cache_enabled']) {
877
  if ($this->options['combined_js']) {
878
- $inner_js = $this->_combined_javascript($js_src, trim($inline_js));
879
- $script_tag = trim(trim($script_tag) . "\n" . $inner_js) . "\n";
880
- $inline_js = '';
881
  } else {
882
- $script_tag = trim(trim($script_tag) . "\n" . $inner_js) . "\n";
883
- $inline_js = $this->_combined_inline_javascript(trim($inline_js));
884
  }
885
  } else {
886
- $script_tag = trim(trim($script_tag) . "\n" . $inner_js) . "\n";
887
- $inline_js = (!empty($inline_js) ? "<script type=\"text/javascript\">//<![CDATA[\n{$inline_js}\n//]]></script>\n" : '');
888
  }
889
 
890
- $script_tag = trim($script_tag) . (!empty($script_tag) ? "\n" : '');
891
- $inner_js = trim($inner_js) . (!empty($inner_js) ? "\n" : '');
892
- $inline_js = trim($inline_js) . (!empty($inline_js) ? "\n" : '');
893
- $foot_js = trim($foot_js) . (!empty($foot_js) ? "\n" : '');
894
 
895
- return array($script_tag, $inner_js, $inline_js, $foot_js);
896
  }
897
 
898
  //**************************************************************************************
@@ -906,27 +879,34 @@ class HeadCleaner extends wokController {
906
  // footer cleaner
907
  //**************************************************************************************
908
  public function footer_cleaner($buffer) {
 
909
  if (!function_exists('str_get_html'))
910
- return trim($buffer) . "\n";
911
 
912
- $buffer = $this->ob_handler($buffer);
 
 
 
913
 
914
  $ret_val = '';
915
- $script_tag = ''; $inline_js = '';
 
916
  $other_tag = '';
917
 
918
- $html_txt = '<html><head></head><body>'
919
- . '<div id="footer">' . trim($buffer) . '</div>'
920
- . '</body></html>';
921
-
922
  // Get Simple DOM Object
923
- $dom = str_get_html($html_txt);
 
 
 
 
924
  if ($dom === false)
925
- return (trim($buffer)."\n");
926
 
927
- $inner_js = ''; $js_src = array();
928
- $elements = $dom->find("div#footer *");
929
- foreach ((array) $elements as $element) {
 
 
930
  switch ($element->tag) {
931
  case 'script':
932
  if (!isset($element->src)) {
@@ -935,65 +915,68 @@ class HeadCleaner extends wokController {
935
  $src = $element->src;
936
  if (array_search( $src, (array) $this->options['remove_js']) === FALSE) {
937
  if (strpos($src, $this->wp_url) === FALSE) {
938
- $script_tag .= trim($element->outertext) . "\n";
939
  } else {
940
- $inner_js .= trim($element->outertext) . "\n";
941
  $js_src[] = preg_replace('/\.gz$/i', '', $src);
942
  }
943
  }
944
  }
945
  break;
946
  default:
947
- $tag = trim($element->outertext);
948
  if (strpos($other_tag, $tag) === FALSE && ! preg_match('/^<\!\-+/', $tag))
949
- $other_tag .= $tag . "\n";
950
  break;
951
  }
952
  }
953
- unset($element); unset($elements);
 
954
 
955
- $inline_js = trim($inline_js);
 
 
 
 
956
  if ($this->options['cache_enabled']) {
957
  if ($this->options['combined_js']) {
958
- $inner_js = $this->_combined_javascript($js_src, trim($inline_js));
959
- $script_tag = trim(trim($script_tag) . "\n" . $inner_js) . "\n";
960
- $inline_js = '';
961
  } else {
962
- $script_tag = trim(trim($script_tag) . "\n" . $inner_js) . "\n";
963
- $inline_js = $this->_combined_inline_javascript(trim($inline_js));
964
  }
965
  } else {
966
- $script_tag = trim(trim($script_tag) . "\n" . $inner_js) . "\n";
967
- $inline_js = (!empty($inline_js) ? "<script type=\"text/javascript\">//<![CDATA[\n{$inline_js}\n//]]></script>\n" : '');
968
  }
969
 
970
- $dom->clear(); unset($dom);
971
-
972
  $ret_val .=
973
- $other_tag
974
- . $script_tag
975
- . $inline_js
976
- ;
977
-
978
- if ($this->options['dynamic']) {
979
- $ret_val = preg_replace(
980
- '/' . preg_quote($this->cache_url, '/') . '(js|css)\/([^\.]*)\.(js|css)/i' ,
981
- $this->self_url . "?f=$2&amp;t=$3" ,
982
- $ret_val
983
- );
984
- }
985
 
986
- // $ret_val = str_replace($this->root_url, '/', $ret_val);
987
- $ret_val = preg_replace(
988
- array( "/[\s]+([^\=]+)\='([^']*)'/i", '/[\n\r]+/i', '/(<\/[^>]+>)[ \t]*(<[^>]+)/i' ) ,
989
- array( ' $1="$2"', "\n", "$1\n$2" ),
990
- $ret_val
991
- );
992
- $ret_val = trim($ret_val) . "\n";
993
 
 
994
  if ($this->options['debug_mode'])
995
  $ret_val .= $this->_get_debug_info($buffer);
996
 
 
 
 
 
 
 
 
 
997
  return $ret_val;
998
  }
999
 
@@ -1015,7 +998,8 @@ class HeadCleaner extends wokController {
1015
  return is_user_logged_in();
1016
  } else {
1017
  global $user;
1018
- if (!isset($user)) $user = wp_get_current_user();
 
1019
  return (!empty($user->ID));
1020
  }
1021
  }
@@ -1045,8 +1029,11 @@ class HeadCleaner extends wokController {
1045
  //**************************************************************************************
1046
  private function _get_permalink() {
1047
  $url = get_bloginfo('url');
1048
- if (! preg_match('|^(https?://[^/]*)|', $url, $host))
1049
- $host[1] = (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') ? 'http://' : 'https://' . $_SERVER['SERVER_NAME'];
 
 
 
1050
  $url = preg_replace( '/\?[^s].*$/i', '', $host[1] . $_SERVER['REQUEST_URI']);
1051
  unset($host);
1052
  return ($url);
@@ -1055,62 +1042,73 @@ class HeadCleaner extends wokController {
1055
  //**************************************************************************************
1056
  // DOM Element -> html tag
1057
  //**************************************************************************************
1058
- private function _dom_to_html($elements, $limit = false) {
1059
- $html = ''; $count = 0;
 
1060
  $type = '';
1061
  $tags = array();
1062
  foreach ((array) $elements as $element) {
1063
  $tag = trim($element->outertext);
1064
  $type = strtolower($element->tag);
1065
- if (strpos($html, $tag) === FALSE) {
1066
- switch($type) {
1067
- case 'meta':
1068
- if (isset($element->name)) {
1069
- $name = strtolower($element->name);
1070
-
1071
- $content = trim(isset($tags[$type][$name]) && isset($tags[$type][$name]['content'])
1072
- ? $tags[$type][$name]['content']
1073
- : '');
1074
- // $content = trim($content
1075
- // . (!empty($content) ? ', ' : '')
1076
- // . (isset($element->content) ? $element->content : '')
1077
- // );
1078
- $contents = ( !empty($content) ? explode( ',', $content ) : array() );
1079
- if ( isset($element->content) )
1080
- $contents = array_merge( $contents, explode(',', $element->content) );
1081
- $content = implode( ',', $contents );
1082
- unset( $contents );
1083
-
1084
- $tags[$type][$name] = array(
1085
- 'name' => $name
1086
- ,'content' => $content
1087
- );
1088
- } else {
1089
- $html .= $tag . "\n";
1090
- }
1091
- break;
1092
- case 'link':
1093
- if (isset($element->rel)) {
1094
- $name = strtolower($element->rel);
1095
- $content = (isset($tags[$type][$name]) && isset($tags[$type][$name]['content'])
1096
- ? $tags[$type][$name]['content']
1097
- : '');
1098
- $content .= $tag . "\n";
1099
-
1100
- $tags[$type][$name] = array(
1101
- 'name' => $name
1102
- ,'content' => $content
1103
- );
1104
- } else {
 
 
 
 
 
 
 
 
 
 
 
1105
  $html .= $tag . "\n";
 
1106
  }
1107
- break;
1108
- default:
1109
- $html .= $tag . "\n";
1110
- break;
1111
  }
 
 
 
1112
  }
1113
- if ($limit !== false && $count++ >= $limit) break;
1114
  }
1115
  unset($element); unset($elements);
1116
 
@@ -1127,6 +1125,7 @@ class HeadCleaner extends wokController {
1127
  }
1128
  unset($tag);
1129
  break;
 
1130
  case 'link':
1131
  default:
1132
  foreach ((array) $contents as $tag) {
@@ -1136,11 +1135,12 @@ class HeadCleaner extends wokController {
1136
  break;
1137
  }
1138
  }
1139
- unset($tags); unset($tag_types);
 
1140
 
1141
- $html = trim($html);
1142
 
1143
- return $html . (!empty($html) ? "\n" : '');
1144
  }
1145
 
1146
  //**************************************************************************************
@@ -1164,7 +1164,8 @@ class HeadCleaner extends wokController {
1164
  private function _css_url_edit($content, $filename) {
1165
  if (preg_match_all('/url[ \t]*\([\'"]?([^\)]*)[\'"]?\)/i', $content, $matches, PREG_SET_ORDER)) {
1166
  $base_path = dirname($filename);
1167
- $search = array(); $replace = array();
 
1168
  foreach ((array) $matches as $match) {
1169
  if (! preg_match('/^https?:\/\//i', trim($match[1]))) {
1170
  $abs_url = $this->_abs_url(trim($match[1]), $base_path);
@@ -1173,7 +1174,9 @@ class HeadCleaner extends wokController {
1173
  }
1174
  }
1175
  $content = str_replace($search, $replace, $content);
1176
- unset($match); unset($search); unset($replace);
 
 
1177
  }
1178
  unset ($matches);
1179
  return $content;
@@ -1192,6 +1195,7 @@ class HeadCleaner extends wokController {
1192
  }
1193
  if ($content === false)
1194
  $content = @file_get_contents($filename);
 
1195
  } else {
1196
  $filename = realpath($filename);
1197
  if ($filename !== FALSE && file_exists($filename)) {
@@ -1201,6 +1205,7 @@ class HeadCleaner extends wokController {
1201
  }
1202
  }
1203
 
 
1204
  return $content;
1205
  }
1206
 
@@ -1215,6 +1220,7 @@ class HeadCleaner extends wokController {
1215
  case 'css':
1216
  $content = $this->_css_url_edit($content, $filename);
1217
  break;
 
1218
  case 'js':
1219
  // $content = 'try{'
1220
  // . trim($content . (substr($content, -1) !== ';' ? ';' : '')) . "\n"
@@ -1223,12 +1229,12 @@ class HeadCleaner extends wokController {
1223
  // : '}finally{};');
1224
  break;
1225
  }
1226
- // $text .= "/***** ".str_replace(ABSPATH, $this->wp_url,$filename)." *****/\n"
1227
- // . $content . "\n\n";
1228
  $text .= $content . "\n\n";
1229
  }
1230
  unset($filename);
1231
- $text = trim($text);
1232
 
1233
  return $text . (!empty($text) ? "\n" : '');
1234
  }
@@ -1238,14 +1244,16 @@ class HeadCleaner extends wokController {
1238
  //**************************************************************************************
1239
  private function _file_write($filename, $content = '', $gzip = true) {
1240
  if (!empty($content)) {
 
 
1241
  $handle = @fopen($filename, 'w');
1242
  @fwrite($handle, $content);
1243
  @fclose($handle);
1244
 
1245
  return ($gzip
1246
  ? $this->_file_gzip($filename, $content)
1247
- : file_exists($filename)
1248
- );
1249
  } else {
1250
  return false;
1251
  }
@@ -1273,6 +1281,7 @@ class HeadCleaner extends wokController {
1273
  }
1274
 
1275
  return (file_exists($filename . '.gz'));
 
1276
  } else {
1277
  return false;
1278
  }
@@ -1296,7 +1305,7 @@ class HeadCleaner extends wokController {
1296
  if (version_compare($ver, '1.6.0.3', '<='))
1297
  $src = $this->plugin_url . 'includes/js/prototype-1.6.0.3.min.js';
1298
 
1299
- $wk_outer_js .= "<script type=\"text/javascript\" src=\"$src\"></script>\n";
1300
  }
1301
  }
1302
 
@@ -1305,16 +1314,16 @@ class HeadCleaner extends wokController {
1305
  if (!$prototype) {
1306
  $prototype = true;
1307
  $src = $this->plugin_url . 'includes/js/prototype-1.6.0.3.min.js';
1308
- $wk_outer_js .= "<script type=\"text/javascript\" src=\"$src\"></script>\n";
1309
  }
1310
  $scriptaculous = array(
1311
- 'scriptaculous/scriptaculous'
1312
- , 'scriptaculous/controls'
1313
- , 'scriptaculous/dragdrop'
1314
- , 'scriptaculous/effects'
1315
- , 'scriptaculous/slider'
1316
- , 'scriptaculous/sound'
1317
- , 'scriptaculous/unittest'
1318
  );
1319
  foreach ($scriptaculous as $product) {
1320
  if (isset($js_libs[$product])) {
@@ -1322,8 +1331,7 @@ class HeadCleaner extends wokController {
1322
  if (!empty($src)) {
1323
  if (version_compare($ver, '1.8.2', '<='))
1324
  $src = $this->plugin_url . 'includes/js/' . $product . '.min.js';
1325
-
1326
- $wk_outer_js .= "<script type=\"text/javascript\" src=\"$src\"></script>\n";
1327
  }
1328
  }
1329
  }
@@ -1340,20 +1348,20 @@ class HeadCleaner extends wokController {
1340
  $src = $this->plugin_url . 'includes/js/jquery-1.4.2.min.js';
1341
 
1342
  if ($prototype || $mootools || strpos($src, $this->wp_url) === FALSE) {
1343
- $wk_outer_js .= "<script type=\"text/javascript\" src=\"$src\"></script>\n";
1344
  } else {
1345
  $js_libs_src[] = $src;
1346
- $wk_inner_js .= "<script type=\"text/javascript\" src=\"$src\"></script>\n";
1347
  }
1348
 
1349
  // jQuery noConflict
1350
  if ($prototype || $mootools) {
1351
  $src = $this->plugin_url . 'includes/js/jquery.noconflict.js';
1352
  if (strpos($src, $this->wp_url) === FALSE) {
1353
- $wk_outer_js .= "<script type=\"text/javascript\" src=\"$src\"></script>\n";
1354
  } else {
1355
  $js_libs_src[] = $src;
1356
- $wk_inner_js .= "<script type=\"text/javascript\" src=\"$src\"></script>\n";
1357
  }
1358
  }
1359
  }
@@ -1365,12 +1373,11 @@ class HeadCleaner extends wokController {
1365
  if (!empty($src)) {
1366
  if (version_compare($ver, '1.2.1', '<='))
1367
  $src = $this->plugin_url . 'includes/js/mootools-1.2.1-core-yc.js';
1368
-
1369
  if ($prototype || $jquery || strpos($src, $this->wp_url) === FALSE) {
1370
- $wk_outer_js .= "<script type=\"text/javascript\" src=\"$src\"></script>\n";
1371
  } else {
1372
  $js_libs_src[] = $src;
1373
- $wk_inner_js .= "<script type=\"text/javascript\" src=\"$src\"></script>\n";
1374
  }
1375
  }
1376
  }
@@ -1395,7 +1402,7 @@ class HeadCleaner extends wokController {
1395
  $longfilename .= $filename . filemtime($src);
1396
  $files[] = $filename;
1397
  } else {
1398
- $html .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$style}\" media=\"{$media}\" />\n";
1399
  }
1400
  }
1401
 
@@ -1405,20 +1412,18 @@ class HeadCleaner extends wokController {
1405
  if (! file_exists($filename) ) {
1406
  if (count($files) > 0 && !empty($longfilename))
1407
  $css = $this->_files_read($files, 'css') . "\n\n" . $css;
1408
-
1409
- // Optimise CSS
1410
- $css = $this->_css_optimise($css);
1411
-
1412
  if (!empty($css))
1413
  $this->_file_write($filename, $css, $this->options['gzip_on'] || HC_MAKE_GZ_FILE );
1414
  }
1415
 
1416
- $fileurl = ($this->options['dynamic']
1417
- ? $this->self_url . '?f=' . $md5_filename . '&amp;t=css'
1418
- : $this->cache_url . $longfilename
1419
- );
 
1420
  if (file_exists($filename))
1421
- $html .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$fileurl}\" media=\"{$media}\" />\n";
1422
 
1423
  return $html;
1424
  }
@@ -1444,12 +1449,13 @@ class HeadCleaner extends wokController {
1444
  if (!file_exists($filename) && !empty($css))
1445
  $this->_file_write($filename, $css, $this->options['gzip_on'] || HC_MAKE_GZ_FILE);
1446
 
1447
- $fileurl = ($this->options['dynamic']
1448
- ? $this->self_url . '?f=' . $md5_filename . '&amp;t=css'
1449
- : $this->cache_url . $longfilename
1450
- );
 
1451
  if (file_exists($filename))
1452
- $html .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$fileurl}\" media=\"{$media}\" />\n";
1453
 
1454
  return $html;
1455
  }
@@ -1468,7 +1474,7 @@ class HeadCleaner extends wokController {
1468
  $longfilename .= $filename . filemtime($src);
1469
  $files[] = $filename;
1470
  } else {
1471
- $html .= "<script type=\"text/javascript\" src=\"{$javascript}\"></script>\n";
1472
  }
1473
  }
1474
 
@@ -1478,21 +1484,15 @@ class HeadCleaner extends wokController {
1478
  if (! file_exists($filename) ) {
1479
  if (count($files) > 0 && !empty($longfilename))
1480
  $script = $this->_files_read($files, 'js') . "\n\n" . $script;
1481
-
1482
- // Minified JavaScript
1483
- $script = $this->_js_minify($script);
1484
-
1485
  if (!empty($script))
1486
  $this->_file_write($filename, $script, $this->options['gzip_on'] || HC_MAKE_GZ_FILE);
1487
  }
1488
 
1489
  $fileurl = $this->cache_url . $longfilename;
1490
- // $fileurl = ($this->options['dynamic']
1491
- // ? $this->self_url . '?f=' . $md5_filename . '&amp;t=js'
1492
- // : $this->cache_url . $longfilename
1493
- // );
1494
  if (file_exists($filename))
1495
- $html .= "<script type=\"text/javascript\" src=\"{$fileurl}\"></script>\n";
1496
 
1497
  return $html;
1498
  }
@@ -1516,12 +1516,9 @@ class HeadCleaner extends wokController {
1516
  $this->_file_write($filename, $script, $this->options['gzip_on'] || HC_MAKE_GZ_FILE);
1517
 
1518
  $fileurl = $this->cache_url . $longfilename;
1519
- // $fileurl = ($this->options['dynamic']
1520
- // ? $this->self_url . '?f=' . $md5_filename . '&amp;t=js'
1521
- // : $this->cache_url . $longfilename
1522
- // );
1523
  if (file_exists($filename))
1524
- $html .= "<script type=\"text/javascript\" src=\"{$fileurl}\"></script>\n";
1525
 
1526
  return $html;
1527
  }
@@ -1558,7 +1555,7 @@ class HeadCleaner extends wokController {
1558
  break;
1559
  }
1560
 
1561
- return ($text . "\n\n");
1562
  }
1563
 
1564
  //**************************************************************************************
@@ -1579,7 +1576,7 @@ class HeadCleaner extends wokController {
1579
  // Minified JavaScript
1580
  //**************************************************************************************
1581
  private function _js_minify($buffer) {
1582
- $js = trim($buffer . "\n");
1583
  if ($this->options['js_minify']) {
1584
  if ( class_exists('JSMin') ) {
1585
  $js = JSMin::minify($js);
@@ -1618,7 +1615,7 @@ class HeadCleaner extends wokController {
1618
  }
1619
 
1620
  private function _css_optimise($buffer, $merge = true) {
1621
- $css = trim($buffer . "\n");
1622
 
1623
  if ($this->options['css_optimise']) {
1624
  if ( class_exists('Minify_CSS') ) {
@@ -1646,7 +1643,8 @@ class HeadCleaner extends wokController {
1646
  // Create cache dir
1647
  //**************************************************************************************
1648
  private function _create_cache_dir($cache_dir = '') {
1649
- if (empty($cache_dir)) $cache_dir = HC_CACHE_DIR;
 
1650
  $cache_dir = $this->_wp_content_dir('/' . trailingslashit($cache_dir) );
1651
 
1652
  $mode = 0777;
@@ -1772,6 +1770,12 @@ class HeadCleaner extends wokController {
1772
  //**************************************************************************************
1773
  // Show Option Page
1774
  //**************************************************************************************
 
 
 
 
 
 
1775
  public function option_page() {
1776
  if ($this->_chk_filters_update()) {
1777
  $this->options['filters'] = $this->filters;
@@ -1783,7 +1787,7 @@ class HeadCleaner extends wokController {
1783
  check_admin_referer("update_options", "_wpnonce_update_options");
1784
 
1785
  // Update options
1786
- $this->_options_update($_POST);
1787
  $this->note .= "<strong>".__('Done!', $this->textdomain_name)."</strong>";
1788
 
1789
  } elseif(isset($_POST['remove_cache'])) {
@@ -1820,16 +1824,16 @@ class HeadCleaner extends wokController {
1820
 
1821
  $out .= "<tr>";
1822
  $out .= "<td>";
1823
- $out .= "<input type=\"checkbox\" name=\"cache_enabled\" id=\"cache_enabled\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['cache_enabled'] === true ? " checked=\"true\"" : "")." />";
1824
  $out .= __('CSS and JavaScript are cached on the server.', $this->textdomain_name);
1825
  $out .= "</td>";
1826
  $out .= "<td>";
1827
- $out .= "<input type=\"checkbox\" name=\"js_move_foot\" id=\"js_move_foot\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['js_move_foot'] === true ? " checked=\"true\"" : "")." />";
1828
  $out .= __('Put JavaScripts at the Bottom.', $this->textdomain_name);
1829
  $out .= "</td>";
1830
  $out .= "<td>";
1831
  if ($this->options['cache_enabled']) {
1832
- $out .= "<input type=\"checkbox\" name=\"dynamic\" id=\"dynamic\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['dynamic'] === true ? " checked=\"true\"" : "")." />";
1833
  $out .= __('CSS and JS are dynamically generated.', $this->textdomain_name);
1834
  }
1835
  $out .= "</td>";
@@ -1838,11 +1842,11 @@ class HeadCleaner extends wokController {
1838
  if ($this->options['cache_enabled']) {
1839
  $out .= "<tr>";
1840
  $out .= "<td>";
1841
- $out .= "<input type=\"checkbox\" name=\"combined_css\" id=\"combined_css\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['combined_css'] === true ? " checked=\"true\"" : "")." />";
1842
  $out .= __('Two or more CSS is combined.', $this->textdomain_name);
1843
  $out .= "</td>";
1844
  $out .= "<td>";
1845
- $out .= "<input type=\"checkbox\" name=\"css_optimise\" id=\"css_optimise\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['css_optimise'] === true ? " checked=\"true\"" : "")." />";
1846
  $out .= __('CSS is optimized.', $this->textdomain_name);
1847
  $out .= "</td>";
1848
  $out .= "<td>";
@@ -1854,30 +1858,30 @@ class HeadCleaner extends wokController {
1854
 
1855
  $out .= "<tr>";
1856
  $out .= "<td>";
1857
- $out .= "<input type=\"checkbox\" name=\"combined_js\" id=\"combined_js\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['combined_js'] === true ? " checked=\"true\"" : "")." />";
1858
  $out .= __('Two or more JavaScript is combined.', $this->textdomain_name);
1859
  $out .= "</td>";
1860
  $out .= "<td>";
1861
- $out .= "<input type=\"checkbox\" name=\"js_minify\" id=\"js_minify\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['js_minify'] === true ? " checked=\"true\"" : "")." />";
1862
  $out .= __('JavaScript is minified.', $this->textdomain_name);
1863
  $out .= "</td>";
1864
  $out .= "<td>";
1865
- $out .= "<input type=\"checkbox\" name=\"foot_js\" id=\"foot_js\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['foot_js'] === true ? " checked=\"true\"" : "")." />";
1866
  $out .= __('Bottom JavaScript is combined, too.', $this->textdomain_name);
1867
  $out .= "</td>";
1868
  $out .= "</tr>\n";
1869
  }
1870
  $out .= "<tr>";
1871
  // $out .= "<td>";
1872
- // $out .= "<input type=\"checkbox\" name=\"gzip_on\" id=\"gzip_on\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['gzip_on'] === true ? " checked=\"true\"" : "")." />";
1873
  // $out .= __('gzip compress to CSS and JS.', $this->textdomain_name);
1874
  // $out .= "</td>";
1875
  $out .= "<td>";
1876
- $out .= "<input type=\"checkbox\" name=\"use_ajax_libs\" id=\"use_ajax_libs\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['use_ajax_libs'] === true ? " checked=\"true\"" : "")." />";
1877
  $out .= __('Use Google Ajax Libraries.', $this->textdomain_name);
1878
  $out .= "</td>";
1879
  $out .= "<td>";
1880
- $out .= "<input type=\"checkbox\" name=\"ie_conditional\" id=\"ie_conditional\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['ie_conditional'] === true ? " checked=\"true\"" : "")." />";
1881
  $out .= __('Remove IE Conditional Tag.', $this->textdomain_name);
1882
  $out .= "</td>";
1883
  $out .= "<td>";
@@ -1886,11 +1890,11 @@ class HeadCleaner extends wokController {
1886
 
1887
  $out .= "<tr>";
1888
  $out .= "<td>";
1889
- $out .= "<input type=\"checkbox\" name=\"xml_declaration\" id=\"xml_declaration\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['xml_declaration'] === true ? " checked=\"true\"" : "")." />";
1890
  $out .= __('Add XML Declaration.', $this->textdomain_name);
1891
  $out .= "</td>";
1892
  $out .= "<td>";
1893
- $out .= "<input type=\"checkbox\" name=\"canonical_tag\" id=\"canonical_tag\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['canonical_tag'] === true ? " checked=\"true\"" : "")." />";
1894
  $out .= __('Add canonical tag.', $this->textdomain_name);
1895
  $out .= "</td>";
1896
  $out .= "<td>";
@@ -1899,22 +1903,22 @@ class HeadCleaner extends wokController {
1899
 
1900
  $out .= "<tr>";
1901
  $out .= "<td>";
1902
- $out .= "<input type=\"checkbox\" name=\"rm_generator\" id=\"rm_generator\" value=\"on\" style=\"margin-right:0.5em;\"".(isset($this->options['priority']['wp_head']['wp_generator']) && $this->options['priority']['wp_head']['wp_generator'] <= 0 ? " checked=\"true\"" : "")." />";
1903
  $out .= __('Remove generator tag.', $this->textdomain_name);
1904
  $out .= "</td>";
1905
  $out .= "<td>";
1906
- $out .= "<input type=\"checkbox\" name=\"rm_rsd_link\" id=\"rm_rsd_link\" value=\"on\" style=\"margin-right:0.5em;\"".(isset($this->options['priority']['wp_head']['rsd_link']) && $this->options['priority']['wp_head']['rsd_link'] <= 0 ? " checked=\"true\"" : "")." />";
1907
  $out .= __('Remove RSD link tag.', $this->textdomain_name);
1908
  $out .= "</td>";
1909
  $out .= "<td>";
1910
- $out .= "<input type=\"checkbox\" name=\"rm_manifest\" id=\"rm_manifest\" value=\"on\" style=\"margin-right:0.5em;\"".(isset($this->options['priority']['wp_head']['wlwmanifest_link']) && $this->options['priority']['wp_head']['wlwmanifest_link'] <= 0 ? " checked=\"true\"" : "")." />";
1911
  $out .= __('Remove wlwmanifest link tag.', $this->textdomain_name);
1912
  $out .= "</td>";
1913
  $out .= "</tr>\n";
1914
 
1915
  $out .= "<tr>";
1916
  $out .= "<td>";
1917
- $out .= "<input type=\"checkbox\" name=\"debug_mode\" id=\"debug_mode\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['debug_mode'] === true ? " checked=\"true\"" : "")." />";
1918
  $out .= __('Debug mode', $this->textdomain_name);
1919
  $out .= "</td>";
1920
  $out .= "<td>";
@@ -1946,13 +1950,13 @@ class HeadCleaner extends wokController {
1946
  $out .= '</select>';
1947
  $out .= "<br />\n";
1948
 
1949
- $out .= "<input type=\"checkbox\" name=\"compress_colors\" id=\"compress_colors\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['csstidy_option']['compress_colors'] === true ? " checked=\"true\"" : "")." />";
1950
  $out .= __('Compress colors', $this->textdomain_name);
1951
  $out .= '&nbsp;&nbsp;&nbsp;&nbsp;';
1952
- $out .= "<input type=\"checkbox\" name=\"compress_font_weight\" id=\"compress_font_weight\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['csstidy_option']['compress_font_weight'] === true ? " checked=\"true\"" : "")." />";
1953
  $out .= __('Compress font-weight', $this->textdomain_name);
1954
  $out .= '&nbsp;&nbsp;&nbsp;&nbsp;';
1955
- $out .= "<input type=\"checkbox\" name=\"remove_bslash\" id=\"remove_bslash\" value=\"on\" style=\"margin-right:0.5em;\"".($this->options['csstidy_option']['remove_bslash'] === true ? " checked=\"true\"" : "")." />";
1956
  $out .= __('Remove unnecessary backslashes', $this->textdomain_name);
1957
  $out .= "<br />\n";
1958
 
@@ -2088,41 +2092,44 @@ class HeadCleaner extends wokController {
2088
  //**************************************************************************************
2089
  // options update
2090
  //**************************************************************************************
 
 
 
2091
  private function _options_update($recv_param) {
2092
- // strip slashes array
2093
- $head_js = $this->stripArray(isset($recv_param['head_js']) ? $recv_param['head_js'] : array());
2094
- $remove_js = $this->stripArray(isset($recv_param['remove_js']) ? $recv_param['remove_js'] : array());
2095
- $head_filters = $this->stripArray(isset($recv_param['head_filters']) ? $recv_param['head_filters'] : array());
2096
- $head_remove = $this->stripArray(isset($recv_param['head_remove']) ? $recv_param['head_remove'] : array());
2097
- $foot_filters = $this->stripArray(isset($recv_param['foot_filters']) ? $recv_param['foot_filters'] : array());
2098
- $foot_remove = $this->stripArray(isset($recv_param['foot_remove']) ? $recv_param['foot_remove'] : array());
2099
- $recv_param = $this->stripArray($recv_param);
2100
 
2101
  // get options
2102
- $this->options['xml_declaration'] = (isset($recv_param['xml_declaration']) && $recv_param['xml_declaration'] == 'on' ? true : false);
2103
- $this->options['ie_conditional']= (isset($recv_param['ie_conditional']) && $recv_param['ie_conditional'] == 'on' ? true : false);
2104
- $this->options['canonical_tag'] = (isset($recv_param['canonical_tag']) && $recv_param['canonical_tag'] == 'on' ? true : false);
2105
- $this->options['foot_js'] = (isset($recv_param['foot_js']) && $recv_param['foot_js'] == 'on' ? true : false);
2106
- $this->options['dynamic'] = (isset($recv_param['dynamic']) && $recv_param['dynamic'] == 'on' ? true : false);
2107
- $this->options['js_move_foot'] = (isset($recv_param['js_move_foot']) && $recv_param['js_move_foot'] == 'on' ? true : false);
2108
- $this->options['cache_enabled'] = (isset($recv_param['cache_enabled']) && $recv_param['cache_enabled'] == 'on' ? true : false);
2109
- $this->options['combined_css'] = (isset($recv_param['combined_css']) && $recv_param['combined_css'] == 'on' ? true : false);
2110
- $this->options['combined_js'] = (isset($recv_param['combined_js']) && $recv_param['combined_js'] == 'on' ? true : false);
2111
- $this->options['js_minify'] = (isset($recv_param['js_minify']) && $recv_param['js_minify'] == 'on' ? true : false);
2112
- $this->options['css_optimise'] = (isset($recv_param['css_optimise']) && $recv_param['css_optimise'] == 'on' ? true : false);
2113
- $this->options['default_media'] = trim($recv_param['default_media']);
2114
- $this->options['gzip_on'] = (isset($recv_param['gzip_on']) && $recv_param['gzip_on'] == 'on' ? true : false);
2115
- $this->options['use_ajax_libs'] = (isset($recv_param['use_ajax_libs']) && $recv_param['use_ajax_libs'] == 'on' ? true : false);
2116
- $this->options['debug_mode'] = (isset($recv_param['debug_mode']) && $recv_param['debug_mode'] == 'on' ? true : false);
2117
- $this->options['csstidy_option']['template'] = (int) $recv_param['template'];
2118
- $this->options['csstidy_option']['optimise_shorthands'] = (int) $recv_param['optimise_shorthands'];
2119
- $this->options['csstidy_option']['compress_colors'] = (isset($recv_param['compress_colors']) && $recv_param['compress_colors'] == 'on' ? true : false);
2120
- $this->options['csstidy_option']['compress_font_weight'] = (isset($recv_param['compress_font_weight']) && $recv_param['compress_font_weight'] == 'on' ? true : false);
2121
- $this->options['csstidy_option']['remove_bslash'] = (isset($recv_param['remove_bslash']) && $recv_param['remove_bslash'] == 'on' ? true : false);
2122
-
2123
- $rm_generator = (isset($recv_param['rm_generator']) && $recv_param['rm_generator'] == 'on' ? true : false);
2124
- $rm_rsd_link = (isset($recv_param['rm_rsd_link']) && $recv_param['rm_rsd_link'] == 'on' ? true : false);
2125
- $rm_manifest = (isset($recv_param['rm_manifest']) && $recv_param['rm_manifest'] == 'on' ? true : false);
 
 
2126
 
2127
  $this->options['remove_js'] = array();
2128
  foreach ((array) $this->options['head_js'] as $javascript => $value) {
@@ -2170,6 +2177,8 @@ class HeadCleaner extends wokController {
2170
  $cache_dir = $this->_create_cache_dir();
2171
  if ( $cache_dir !== FALSE )
2172
  $this->_create_htaccess($cache_dir);
 
 
2173
  }
2174
 
2175
  //**************************************************************************************
@@ -2179,16 +2188,18 @@ class HeadCleaner extends wokController {
2179
  $this->deleteOptions();
2180
  $this->_remove_cache_file();
2181
  $this->options = $this->_init_options();
 
 
2182
  }
2183
 
2184
  //**************************************************************************************
2185
  // Get function name
2186
  //**************************************************************************************
2187
  private function _get_function_name($function) {
2188
- return (is_array($function)
 
2189
  ? (get_class($function[0]) !== FALSE ? get_class($function[0]) : $function[0]) . '::' . $function[1]
2190
- : $function
2191
- );
2192
  }
2193
 
2194
  //**************************************************************************************
@@ -2226,17 +2237,20 @@ class HeadCleaner extends wokController {
2226
  if ( isset($this->options['filters'][$tag]) ) {
2227
  foreach ( $filters as $function_name => $priority) {
2228
  $retval = ( !isset($this->options['filters'][$tag][$function_name]) );
2229
- if ($retval) break;
 
2230
  }
2231
  } else {
2232
- $retval = true; break;
 
2233
  }
2234
  }
2235
  unset ($filters);
2236
 
2237
  foreach ( $this->head_js as $key => $val ) {
2238
  if ( !isset($this->options['head_js'][$key]) ) {
2239
- $retval = true; break;
 
2240
  }
2241
  }
2242
 
@@ -2254,10 +2268,10 @@ class HeadCleaner extends wokController {
2254
 
2255
  $active_filters = (isset($wp_filter[$tag])
2256
  ? $wp_filter[$tag]
2257
- : array());
2258
  $custom_priority = (isset($this->options['priority'][$tag])
2259
  ? $this->options['priority'][$tag]
2260
- : array());
2261
  foreach ($this->no_conflict as $function_name) {
2262
  $custom_priority[$function_name] = HC_PRIORITY + 1;
2263
  }
@@ -2302,7 +2316,7 @@ class HeadCleaner extends wokController {
2302
  else
2303
  $url = ( !function_exists('get_blog_option') ? get_option( 'siteurl' ) : get_blog_option( $blog_id, 'siteurl' ));
2304
 
2305
- $url = str_replace( 'http://', "{$scheme}://", $url );
2306
 
2307
  if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
2308
  $url .= '/' . ltrim( $path, '/' );
@@ -2314,20 +2328,18 @@ class HeadCleaner extends wokController {
2314
  // raw shortcode
2315
  //**************************************************************************************
2316
  public function raw_formatter($content) {
2317
- $new_content = '';
2318
- $pattern_full = '{(\[raw\].*?\[/raw\])}is';
2319
- $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
2320
- $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
2321
-
2322
- foreach ($pieces as $piece) {
2323
- if (preg_match($pattern_contents, $piece, $matches)) {
2324
- $new_content .= $matches[1];
2325
- } else {
2326
- $new_content .= wptexturize(wpautop($piece));
2327
- }
2328
- }
2329
-
2330
- return $new_content;
2331
  }
2332
 
2333
  //**************************************************************************************
@@ -2344,13 +2356,11 @@ class HeadCleaner extends wokController {
2344
  }
2345
 
2346
  private function _get_debug_info($buffer, $tag = '') {
2347
- $ret_val = "<!--\n";
2348
-
2349
- $ret_val .= "***** Processing time ****************************\n"
2350
- . $this->_microtime_diff($this->mtime_start) . " seconds\n"
2351
- . "**************************************************\n\n";
2352
  $this->mtime_start = microtime();
2353
 
 
 
2354
  $ret_val .= "***** Original ***********************************\n"
2355
  . str_replace(array('<', '>'), array('<', '>'), $buffer) . "\n"
2356
  . "**************************************************\n\n";
@@ -2381,8 +2391,71 @@ class HeadCleaner extends wokController {
2381
 
2382
  return $ret_val;
2383
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2384
  }
2385
 
 
 
 
2386
  global $head_cleaner;
2387
 
2388
  $head_cleaner = new HeadCleaner();
@@ -2391,4 +2464,4 @@ if (function_exists('register_activation_hook'))
2391
  register_activation_hook(__FILE__, array(&$head_cleaner, 'activation'));
2392
  if (function_exists('register_deactivation_hook'))
2393
  register_deactivation_hook(__FILE__, array(&$head_cleaner, 'deactivation'));
2394
- ?>
1
  <?php
2
  /*
3
  Plugin Name: Head Cleaner
4
+ Version: 1.3.14
5
  Plugin URI: http://wppluginsj.sourceforge.jp/head-cleaner/
6
  Description: Cleaning tags from your WordPress header and footer.
7
  Author: wokamoto
65
 
66
  //**************************************************************************************
67
  if (!defined('ABSPATH') && strstr($_SERVER['PHP_SELF'], '/head-cleaner.php')) {
68
+ include('js_css.php');
69
+ exit();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  }
71
 
72
  //**************************************************************************************
80
  //**************************************************************************************
81
  class HeadCleaner extends wokController {
82
  public $plugin_name = 'head-cleaner';
83
+ public $plugin_ver = '1.3.14';
84
 
85
  // Deafault Options
86
  private $options_default = array(
129
  private $foot_js_src;
130
 
131
  private $mtime_start;
132
+ private $process_time = 0;
133
+ private $org_len = 0;
134
+ private $ret_len = 0;
135
 
136
  private $filters;
137
  private $head_js;
169
 
170
  $this->wp_url = trailingslashit($this->_get_site_url());
171
  $this->root_url = preg_replace('/^(https?:\/\/[^\/]*\/).*$/i', '$1', $this->wp_url);
172
+ $this->self_url = $this->wp_plugin_url( basename(dirname(__FILE__)) ) . basename(__FILE__);
173
  $this->lang = (defined('WPLANG') ? WPLANG : 'ja');
174
  $this->charset = get_option('blog_charset');
175
  $this->_get_filters('wp_head');
199
  // Require PHP Libraries
200
  $this->_require_libraries();
201
 
202
+ // add action
203
  add_action('get_header', array(&$this, 'head_start'));
204
  add_action('wp_footer', array(&$this, 'filters_save'), 11);
205
 
207
  if (HC_RAW_SHORTCODE) {
208
  remove_filter('the_content', 'wpautop');
209
  remove_filter('the_content', 'wptexturize');
210
+ add_filter('the_content', array(&$this, 'raw_formatter'), 99);
211
 
212
  remove_filter('the_excerpt', 'wpautop');
213
  remove_filter('the_excerpt', 'wptexturize');
214
+ add_filter('the_excerpt', array(&$this, 'raw_formatter'), 99);
215
  }
216
  }
217
  }
250
  $wk_options['head_js'] = $head_js;
251
  $wk_options['analyze_expired'] = time() + HC_ANALYZE_EXPIRED;
252
  }
253
+
254
  return $wk_options;
255
  }
256
 
398
  if ( $this->options['filters'] != $this->filters || $this->options['head_js'] != $this->head_js ) {
399
  $this->options['filters'] = $this->filters;
400
  $this->options['head_js'] = $this->head_js;
401
+ $this->options['analyze_expired'] = time() + HC_ANALYZE_EXPIRED;
 
402
  $this->updateOptions();
403
  }
404
  }
408
  // head cleaner
409
  //**************************************************************************************
410
  public function head_cleaner($buffer) {
411
+ $buffer = $this->_tag_trim($this->ob_handler($buffer));
412
  if (!function_exists('str_get_html'))
413
+ return $buffer;
414
 
415
+ // $transient_key = $this->option_name.'_'.md5($buffer);
416
+ // $ret_val = get_transient($transient_key);
417
+ // if ( $ret_val !== false )
418
+ // return $ret_val;
419
 
420
+ $head_txt = $buffer;
421
  $url = $this->_get_permalink();
422
 
423
+ $doctype = 'html';
424
+ $xml_head = $html_tag = $head_tag = '';
425
+ if (preg_match_all('/<(\?xml|html|head) ([^>]*)>/ism', $buffer, $matches, PREG_SET_ORDER)) {
426
+ foreach ((array) $matches as $match) {
427
+ $tag = $this->_tag_trim(preg_replace("/[ \t\r\n]+/ism", ' ', "<{$match[1]} {$match[2]}>"));
428
+ switch ($match[1]){
429
+ case '?xml':
430
+ $doctype = 'xhtml';
431
+ $xml_head = $tag;
432
+ break;
433
+ case 'html':
434
+ $html_tag = $tag;
435
+ break;
436
+ case 'head':
437
+ $head_tag = $tag;
438
+ break;
439
+ }
440
+ }
441
+ unset($match);
442
+ }
443
+
444
  if (preg_match('/<!DOCTYPE [^>]* XHTML [^>]*>/i', $buffer)) {
445
  // xhtml
446
+ $doctype = 'xhtml';
447
+ $xml_head = empty($xml_head) ? $this->_tag_trim('<?xml version="1.0" encoding="'.$this->charset.'"?>') : $xml_head;
448
+ $html_tag = empty($html_tag) ? $this->_tag_trim('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$this->lang.'" lang="'.$this->lang.'">') : $html_tag;
449
+ $head_tag = empty($head_tag) ? $this->_tag_trim('<head profile="http://gmpg.org/xfn/11">') : $head_tag;
450
+
451
  } else {
452
  // html
453
+ $doctype = 'html';
454
+ $xml_head = '';
455
+ $html_tag = empty($html_tag) ? $this->_tag_trim('<html dir="ltr" lang="'.$this->lang.'">') : $html_tag;
456
+ $head_tag = empty($head_tag) ? $this->_tag_trim('<head>') : $head_tag;
457
  }
458
+ unset($matches);
459
 
460
+ $ret_val = '';
461
+ $meta_tag = '';
462
+ $title_tag = '';
463
+ $base_tag = '';
464
+ $link_tag = '';
465
+ $object_tag = '';
466
+ $other_tag = '';
467
+ $css_tag = '';
468
+ $inline_css = '';
469
+ $script_tag = '';
470
+ $inline_js = '';
471
+ $noscript_tag = '';
472
 
473
  // for IE conditional tag
474
  list($head_txt, $IE_conditional_tags, $ie6) = $this->_parse_IE_conditional_tags($head_txt);
475
 
476
  // Get Simple DOM Object
477
  if (preg_match('/^(.*)(<html[^>]*>[^<]*)(<head[^>]*>[^<]*)(.*)$/ism', $head_txt, $matches)) {
478
+ $ret_val = $this->_tag_trim($matches[1]);
479
+ $html_tag = $this->_tag_trim($matches[2]);
480
+ $head_tag = $this->_tag_trim($matches[3]);
481
+ $head_txt = $this->_tag_trim($matches[4]);
482
  }
483
  unset($matches);
 
 
 
484
 
485
+ $dom = str_get_html(
486
+ $xml_head . $html_tag . $head_tag . $head_txt .
487
+ '</head><body></body></html>'
488
+ );
489
  if ($dom === false)
490
+ return ($this->_tag_trim($buffer));
491
+
492
+ // ***** Parse Start! *****
493
+
494
+ // for html tag
495
+ if ( empty($html_tag) ) {
496
+ if ( $doctype === 'xhtml' ) {
497
+ // xhtml
498
+ $xmlns = (defined('HC_XMLNS') ? HC_XMLNS : 'http://www.w3.org/1999/xhtml');
499
+ $xml_lang = $this->lang;
500
+ } else {
501
+ // html
502
+ $dir = 'ltr';
503
+ }
504
+ $lang = $this->lang;
505
 
 
 
 
 
 
 
506
  if (preg_match_all('/ +([^ ]*)=[\'"]([^\'"]*)[\'"]/', $html_tag, $matches, PREG_SET_ORDER)) {
507
  foreach ((array) $matches as $match) {
508
  switch ($match[1]){
509
  case 'xmlns': $xmlns = $match[2]; break;
510
  case 'xml:lang': $xml_lang = $match[2]; break;
511
  case 'lang': $lang = $match[2]; break;
 
 
 
 
 
 
 
 
 
 
 
 
 
512
  case 'dir': $dir = $match[2]; break;
513
  case 'lang': $lang = $match[2]; break;
514
  }
516
  unset($match);
517
  }
518
  unset($matches);
519
+
520
+ $html_tag = $this->_tag_trim( $doctype === 'xhtml'
521
+ ? '<html xmlns="'.$xmlns.'" xml:lang="'.$xml_lang.'" lang="'.$lang.'">'
522
+ : '<html dir="'.$dir.'" lang="'.$lang.'">' );
523
  }
524
 
525
+ $meta_tag = $this->_dom_to_html($dom->find("meta"));
526
+ $title_tag = $this->_dom_to_html($dom->find("title"), 1);
527
+ $base_tag = $this->_dom_to_html($dom->find("base"), 1);
528
+ $link_tag = $this->_dom_to_html($dom->find("link[rel!='stylesheet']"), false, '/alternate stylesheet/i');
529
  if (count($dom->find("link[rel='canonical']")) <= 0 && $this->options['canonical_tag'])
530
+ $link_tag .= $this->_tag_trim('<link rel="canonical" href="' . htmlspecialchars($url, ENT_QUOTES) . '" />');
531
+ list($css_tag, $inline_css) = $this->_parse_stylesheet_tag($dom->find("link[rel*='stylesheet']"), $dom->find("style"));
532
+ list($script_tag, $inline_js, $foot_js) = $this->_parse_script_tag($dom->find("script"));
533
+ $noscript_tag = $this->_dom_to_html($dom->find("noscript"));
534
+ $object_tag = $this->_dom_to_html($dom->find("object"));
535
 
536
+ $dom->clear();
537
+ unset($dom);
538
 
539
  // for IE conditional tag
540
  if (!$this->options['ie_conditional'] && count($IE_conditional_tags) > 0) {
541
  $IE_conditional_tag_pattern = '/(<\!-+[ \t]*\[if[ \t]+.*IE.*[ \t]*?\][ \t]*>)[ \t\r\n]*(.*?)[ \t\r\n]*(<\![ \t]*\[endif\][ \t]*-+>)/ims';
542
  foreach ((array) $IE_conditional_tags as $IE_conditional_tag) {
543
  if (isset($IE_conditional_tag[0])) {
544
+ $IE_tag = $this->_tag_trim(preg_replace($IE_conditional_tag_pattern, "$1$2$3", $IE_conditional_tag[0]));
545
  if ( strpos(strtolower($IE_tag), '<link') !== false )
546
+ $css_tag .= $IE_tag;
547
  elseif ( strpos(strtolower($IE_tag), '<style') !== false )
548
+ $inline_css .= $IE_tag;
549
  elseif ( strpos(strtolower($IE_tag), '<script') !== false )
550
+ $inline_js .= $IE_tag;
551
  elseif ( !empty($IE_tag) )
552
+ $object_tag .= $IE_tag;
553
  }
554
  }
555
  }
557
 
558
  // Build!
559
  $ret_val .=
560
+ $this->_tag_trim($html_tag) .
561
+ $this->_tag_trim($head_tag) .
562
+ $this->_tag_trim($meta_tag) .
563
+ $this->_tag_trim($title_tag) .
564
+ $this->_tag_trim($base_tag) .
565
+ $this->_tag_trim($link_tag) .
566
+ $this->_tag_trim($css_tag) .
567
+ $this->_tag_trim($inline_css) .
568
+ $this->_tag_trim(!$this->options['js_move_foot'] ? $script_tag : '') .
569
+ $this->_tag_trim(!$this->options['js_move_foot'] ? $inline_js : '') .
570
+ $this->_tag_trim($noscript_tag) .
571
+ $this->_tag_trim($object_tag) ;
572
+
573
+ // JavaScript move footer space
574
+ if ($this->options['js_move_foot'] || !empty($foot_js)) {
575
+ $this->foot_js_src = $foot_js;
576
+ if ( $this->options['js_move_foot'] )
577
+ $this->foot_js_src .= $script_tag . $inline_js;
578
+ $this->foot_js_src = $this->_tag_trim($this->foot_js_src);
579
+ }
580
+ if (!empty($this->foot_js_src))
 
 
 
 
 
 
581
  add_action('wp_footer', array(&$this, 'footer'), 9);
 
582
 
583
+ // dynamic css, js
584
+ if ($this->options['dynamic'])
585
+ $ret_val = $this->_dynamic_js_css($ret_val);
 
 
 
 
586
 
587
+ // set xml declaration
588
  $ret_val = ($ie6 || !$this->options['xml_declaration']
589
  ? preg_replace('/^<\?xml[^>]*>/i', '', $ret_val)
590
+ : $this->_tag_trim(strpos($ret_val, '<?xml') === false ? $xml_head : '') . $ret_val
591
  );
592
+ $ret_val = $this->_tag_normalize($ret_val);
 
593
 
594
+ // add debug information
595
  if ($this->options['debug_mode'])
596
  $ret_val .= $this->_get_debug_info($buffer);
597
 
598
+ $this->org_len = strlen(bin2hex($buffer));
599
+ $this->ret_len = strlen(bin2hex($ret_val));
600
+ $this->process_time = $this->_microtime_diff($this->mtime_start);
601
+ // $ret_val .= "<!-- {$this->process_time} seconds. {$this->ret_len} / {$this->org_len} (" . (int) (($this->org_len - $this->ret_len) / $this->org_len * 10000) / 100 . "% saving) -->\n";
602
+
603
+ // set_transient($transient_key, $ret_val, $this->options['analyze_expired']);
604
+
605
  return $ret_val;
606
  }
607
 
610
  //**************************************************************************************
611
  private function _parse_IE_conditional_tags($head_txt){
612
  // Check USER AGENT
613
+ $ua = trim(strtolower($_SERVER['HTTP_USER_AGENT']));
614
+ $ie = (strpos($ua, 'msie') !== false && !preg_match('/(gecko|applewebkit|opera|sleipnir|chrome)/i', $ua));
 
615
  $ie_ver = ($ie ? preg_replace('/^.*msie +([\d+\.]+);.*$/i', '$1', $ua) : false);
616
+ $ie6 = ($ie ? version_compare($ie_ver, '7.0', '<') : false);
617
 
618
  $IE_conditional_tags = array();
619
  if ($this->options['ie_conditional']) {
645
  $replace_patterns[] = sprintf($IE_conditional_tag_pattern, '(gte?[ \t]*)', ' [567]\.?0?'); // > 5 - 7, >= 5 - 7
646
  $replace_patterns[] = sprintf($IE_conditional_tag_pattern, '(gte?[ \t]*)', ' 5\.5'); // > 5.5, >= 5.5
647
  } elseif (version_compare($ie_ver, '10.0', '<')) { // IE 9
648
+ $replace_patterns[] = sprintf($IE_conditional_tag_pattern, '([lg]te[ \t]*|[ \t]*)', ' 9\.?0?'); // >= 9, <= 9, = 9
649
+ $replace_patterns[] = sprintf($IE_conditional_tag_pattern, '(gte?[ \t]*)', ' [5678]\.?0?'); // > 5 - 8, >= 5 - 8
650
  $replace_patterns[] = sprintf($IE_conditional_tag_pattern, '(gte?[ \t]*)', ' 5\.5'); // > 5.5, >= 5.5
651
  }
652
 
669
  private function _parse_stylesheet_tag($elements_linktag, $elements_styletag){
670
  $css_tag = '';
671
  $css_tag_with_id = '';
672
+ $css_tag_with_title = '';
673
  $inner_css = '';
674
  $css_src = array();
675
  $wk_inline_css = array();
680
  $tag = trim($element->outertext);
681
  if (strpos($css_tag, $tag) === FALSE) {
682
  if (strpos($element->href, $this->wp_url) === FALSE) {
683
+ $css_tag .= $this->_tag_trim($tag);
684
  } elseif ( isset($element->id) && !empty($element->id) ) {
685
+ $css_tag_with_id .= $this->_tag_trim($tag);
686
+ } elseif ( (isset($element->title) && !empty($element->title)) || strtolower($element->rel) == 'alternate stylesheet' ) {
687
+ $css_tag_with_title .= $this->_tag_trim($tag);
688
  } else {
689
+ $media = trim( isset($element->media)
690
+ ? $element->media
691
+ : $this->options['default_media'] );
692
+ $media = ( empty($media) || is_null($media) || $media === FALSE
693
+ ? $this->options['default_media']
694
+ : $media );
695
+ $inner_css .= $this->_tag_trim($tag);
696
  $css_src[$media][] = $element->href;
697
  }
698
  }
708
  foreach ($wk_matches as $val) {
709
  $wk_text = trim(str_replace( $val[0], '', $wk_text));
710
  $href = trim($val[1]);
711
+ $tag = $this->_css_tag($href, $media);
712
  if (strpos( $href, $this->wp_url) === FALSE) {
713
  $css_tag .= $tag . "\n";
714
  } else {
720
  unset($wk_matches);
721
  if ( !empty($wk_text) ) {
722
  if ( !isset($wk_inline_css[$media]) )
723
+ $wk_inline_css[$media] = $this->_tag_trim($wk_text);
724
  else
725
+ $wk_inline_css[$media] .= $this->_tag_trim($wk_text);
726
  }
727
  }
728
  if ($this->options['cache_enabled']) {
729
  if ($this->options['combined_css']) {
730
+ $css_tag = $this->_tag_trim($css_tag);
731
  foreach ($css_src as $key => $val) {
732
  $inner_css = $this->_combined_css($val, trim(isset($wk_inline_css[$key]) ? $wk_inline_css[$key] : '' ), $key);
733
+ $css_tag .=
734
+ $this->_tag_trim($inner_css) .
735
+ $this->_tag_trim($css_tag_with_id) .
736
+ $this->_tag_trim($css_tag_with_title);
737
+ if (isset($wk_inline_css[$key]))
738
+ $wk_inline_css[$key] = '';
739
  }
740
  foreach ($wk_inline_css as $key => $val) {
741
  $val = trim($val);
742
  if (!empty($val)) {
743
  $inner_css = $this->_combined_css(array(), $val, $key);
744
+ $css_tag .= $this->_tag_trim($inner_css);
745
  }
746
  }
747
+
748
  } else {
749
+ $css_tag =
750
+ $this->_tag_trim($css_tag) .
751
+ $this->_tag_trim($inner_css) .
752
+ $this->_tag_trim($css_tag_with_id) .
753
+ $this->_tag_trim($css_tag_with_title);
754
  foreach ($wk_inline_css as $key => $val) {
755
  $val = trim($val);
756
  if (!empty($val)) {
757
  $inner_css = $this->_combined_inline_css(trim($val), $key);
758
+ $inline_css .= $this->_tag_trim($inner_css);
759
  }
760
  }
761
  }
762
  } else {
763
+ $css_tag =
764
+ $this->_tag_trim($css_tag) .
765
+ $this->_tag_trim($inner_css) .
766
+ $this->_tag_trim($css_tag_with_id) .
767
+ $this->_tag_trim($css_tag_with_title);
768
  foreach ($wk_inline_css as $key => $val) {
769
  $val = trim($val);
770
+ if (!empty($val))
771
+ $inline_css .= $this->_css_tag($val, $media, true);
 
 
 
 
772
  }
773
  }
774
  unset($wk_inline_css);
775
  unset($element);
776
 
777
+ $css_tag = $this->_tag_trim($css_tag);
778
+ $inline_css = $this->_tag_trim($inline_css);
 
779
 
780
+ return array($css_tag, $inline_css);
781
  }
782
 
783
  //**************************************************************************************
820
  $version = '1';
821
  $js_libs[$product][$version] = $src;
822
  } elseif ($this->head_js[$src] === FALSE) {
823
+ $foot_js .= $this->_tag_trim($element->outertext);
824
  } elseif (strpos($src, $this->wp_url) === FALSE) {
825
+ $script_tag .= $this->_tag_trim($element->outertext);
826
  } else {
827
+ $inner_js .= $this->_tag_trim($element->outertext);
828
  $js_src[] = $element->src;
829
  }
830
  }
839
  if (count($js_libs_src) > 0)
840
  $js_src = array_merge($js_libs_src, $js_src);
841
 
842
+ $script_tag = $this->_tag_trim($script_tag) . $wk_outer_js;
843
  $inner_js = $wk_inner_js . $inner_js;
844
 
845
  unset($js_libs_src);
846
  unset($js_libs);
847
  }
848
 
849
+ $inline_js = $this->_tag_trim($inline_js);
850
  if ($this->options['cache_enabled']) {
851
  if ($this->options['combined_js']) {
852
+ $inner_js = $this->_combined_javascript($js_src, trim($inline_js));
853
+ $script_tag = $this->_tag_trim($this->_tag_trim($script_tag) . $inner_js);
854
+ $inline_js = '';
855
  } else {
856
+ $script_tag = $this->_tag_trim($this->_tag_trim($script_tag) . $inner_js);
857
+ $inline_js = $this->_combined_inline_javascript(trim($inline_js));
858
  }
859
  } else {
860
+ $script_tag = $this->_tag_trim($this->_tag_trim($script_tag) . $inner_js);
861
+ $inline_js = $this->_script_tag($inline_js, true);
862
  }
863
 
864
+ $script_tag = $this->_tag_trim($script_tag);
865
+ $inline_js = $this->_tag_trim($inline_js);
866
+ $foot_js = $this->_tag_trim($foot_js);
 
867
 
868
+ return array($script_tag, $inline_js, $foot_js);
869
  }
870
 
871
  //**************************************************************************************
879
  // footer cleaner
880
  //**************************************************************************************
881
  public function footer_cleaner($buffer) {
882
+ $buffer = $this->_tag_trim($this->ob_handler($buffer));
883
  if (!function_exists('str_get_html'))
884
+ return $buffer;
885
 
886
+ // $transient_key = $this->option_name.'_'.md5($buffer);
887
+ // $ret_val = get_transient($transient_key);
888
+ // if ( $ret_val !== false )
889
+ // return $ret_val;
890
 
891
  $ret_val = '';
892
+ $script_tag = '';
893
+ $inline_js = '';
894
  $other_tag = '';
895
 
 
 
 
 
896
  // Get Simple DOM Object
897
+ $dom = str_get_html(
898
+ '<html><head></head><body>' .
899
+ '<div id="footer">' . $buffer . '</div>' .
900
+ '</body></html>'
901
+ );
902
  if ($dom === false)
903
+ return $buffer;
904
 
905
+ // parse
906
+ $inner_js = '';
907
+ $js_src = array();
908
+ $elements = (array) $dom->find("div#footer *");
909
+ foreach ($elements as $element) {
910
  switch ($element->tag) {
911
  case 'script':
912
  if (!isset($element->src)) {
915
  $src = $element->src;
916
  if (array_search( $src, (array) $this->options['remove_js']) === FALSE) {
917
  if (strpos($src, $this->wp_url) === FALSE) {
918
+ $script_tag .= $this->_tag_trim($element->outertext);
919
  } else {
920
+ $inner_js .= $this->_tag_trim($element->outertext);
921
  $js_src[] = preg_replace('/\.gz$/i', '', $src);
922
  }
923
  }
924
  }
925
  break;
926
  default:
927
+ $tag = $this->_tag_trim($element->outertext);
928
  if (strpos($other_tag, $tag) === FALSE && ! preg_match('/^<\!\-+/', $tag))
929
+ $other_tag .= $tag;
930
  break;
931
  }
932
  }
933
+ unset($element);
934
+ unset($elements);
935
 
936
+ $dom->clear();
937
+ unset($dom);
938
+
939
+ $script_tag = $this->_tag_trim($script_tag);
940
+ $inline_js = trim($inline_js);
941
  if ($this->options['cache_enabled']) {
942
  if ($this->options['combined_js']) {
943
+ $inner_js = $this->_combined_javascript($js_src, $inline_js);
944
+ $script_tag .= $inner_js;
945
+ $inline_js = '';
946
  } else {
947
+ $script_tag .= $inner_js;
948
+ $inline_js = $this->_combined_inline_javascript($inline_js);
949
  }
950
  } else {
951
+ $script_tag .= $inner_js;
952
+ $inline_js = $this->_script_tag($inline_js, true);
953
  }
954
 
955
+ // build!
 
956
  $ret_val .=
957
+ $this->_tag_trim($other_tag) .
958
+ $this->_tag_trim($script_tag) .
959
+ $this->_tag_trim($inline_js) ;
 
 
 
 
 
 
 
 
 
960
 
961
+ // dynamic css, js
962
+ if ($this->options['dynamic'])
963
+ $ret_val = $this->_dynamic_js_css($ret_val);
964
+
965
+ // tag normalize
966
+ $ret_val = $this->_tag_normalize($ret_val);
 
967
 
968
+ // add debug information
969
  if ($this->options['debug_mode'])
970
  $ret_val .= $this->_get_debug_info($buffer);
971
 
972
+ $this->org_len += strlen(bin2hex($buffer));
973
+ $this->ret_len += strlen(bin2hex($ret_val));
974
+ $this->process_time += $this->_microtime_diff($this->mtime_start);
975
+
976
+ // $ret_val .= $this->_process_time();
977
+
978
+ // set_transient($transient_key, $ret_val, $this->options['analyze_expired']);
979
+
980
  return $ret_val;
981
  }
982
 
998
  return is_user_logged_in();
999
  } else {
1000
  global $user;
1001
+ if (!isset($user))
1002
+ $user = wp_get_current_user();
1003
  return (!empty($user->ID));
1004
  }
1005
  }
1029
  //**************************************************************************************
1030
  private function _get_permalink() {
1031
  $url = get_bloginfo('url');
1032
+ if (! preg_match('|^(https?://[^/]*)|', $url, $host)) {
1033
+ $host[1] = (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off')
1034
+ ? 'http://'
1035
+ : 'https://' . $_SERVER['SERVER_NAME'];
1036
+ }
1037
  $url = preg_replace( '/\?[^s].*$/i', '', $host[1] . $_SERVER['REQUEST_URI']);
1038
  unset($host);
1039
  return ($url);
1042
  //**************************************************************************************
1043
  // DOM Element -> html tag
1044
  //**************************************************************************************
1045
+ private function _dom_to_html($elements, $limit = false, $exclusion = '') {
1046
+ $html = '';
1047
+ $count = 0;
1048
  $type = '';
1049
  $tags = array();
1050
  foreach ((array) $elements as $element) {
1051
  $tag = trim($element->outertext);
1052
  $type = strtolower($element->tag);
1053
+ if (!($exclusion !== '' && preg_match($exclusion, $tag))) {
1054
+ if (strpos($html, $tag) === FALSE) {
1055
+ switch($type) {
1056
+ case 'meta':
1057
+ if (isset($element->name)) {
1058
+ $name = strtolower($element->name);
1059
+ $content = trim(
1060
+ isset($tags[$type][$name]) && isset($tags[$type][$name]['content'])
1061
+ ? $tags[$type][$name]['content']
1062
+ : '');
1063
+ $contents = (
1064
+ !empty($content)
1065
+ ? explode( ',', $content )
1066
+ : array() );
1067
+ if ( isset($element->content) ) {
1068
+ foreach((array) explode(',', $element->content) as $content ) {
1069
+ if (array_search($content, $contents) === FALSE) {
1070
+ $contents[] = $content;
1071
+ }
1072
+ }
1073
+ }
1074
+ $content = implode( ',', $contents );
1075
+ unset( $contents );
1076
+
1077
+ $tags[$type][$name] = array(
1078
+ 'name' => $name ,
1079
+ 'content' => $content ,
1080
+ );
1081
+ } else {
1082
+ $html .= $tag . "\n";
1083
+ }
1084
+ break;
1085
+
1086
+ case 'link':
1087
+ if (isset($element->rel)) {
1088
+ $name = strtolower($element->rel);
1089
+ $content = (isset($tags[$type][$name]) && isset($tags[$type][$name]['content'])
1090
+ ? $tags[$type][$name]['content']
1091
+ : '');
1092
+ $content .= $tag . "\n";
1093
+
1094
+ $tags[$type][$name] = array(
1095
+ 'name' => $name ,
1096
+ 'content' => $content ,
1097
+ );
1098
+ } else {
1099
+ $html .= $tag . "\n";
1100
+ }
1101
+ break;
1102
+
1103
+ default:
1104
  $html .= $tag . "\n";
1105
+ break;
1106
  }
 
 
 
 
1107
  }
1108
+
1109
+ if ($limit !== false && $count++ >= $limit)
1110
+ break;
1111
  }
 
1112
  }
1113
  unset($element); unset($elements);
1114
 
1125
  }
1126
  unset($tag);
1127
  break;
1128
+
1129
  case 'link':
1130
  default:
1131
  foreach ((array) $contents as $tag) {
1135
  break;
1136
  }
1137
  }
1138
+ unset($tags);
1139
+ unset($tag_types);
1140
 
1141
+ $html = $this->_tag_trim($html);
1142
 
1143
+ return $html;
1144
  }
1145
 
1146
  //**************************************************************************************
1164
  private function _css_url_edit($content, $filename) {
1165
  if (preg_match_all('/url[ \t]*\([\'"]?([^\)]*)[\'"]?\)/i', $content, $matches, PREG_SET_ORDER)) {
1166
  $base_path = dirname($filename);
1167
+ $search = array();
1168
+ $replace = array();
1169
  foreach ((array) $matches as $match) {
1170
  if (! preg_match('/^https?:\/\//i', trim($match[1]))) {
1171
  $abs_url = $this->_abs_url(trim($match[1]), $base_path);
1174
  }
1175
  }
1176
  $content = str_replace($search, $replace, $content);
1177
+ unset($match);
1178
+ unset($search);
1179
+ unset($replace);
1180
  }
1181
  unset ($matches);
1182
  return $content;
1195
  }
1196
  if ($content === false)
1197
  $content = @file_get_contents($filename);
1198
+
1199
  } else {
1200
  $filename = realpath($filename);
1201
  if ($filename !== FALSE && file_exists($filename)) {
1205
  }
1206
  }
1207
 
1208
+ $this->org_len += strlen(bin2hex($content));
1209
  return $content;
1210
  }
1211
 
1220
  case 'css':
1221
  $content = $this->_css_url_edit($content, $filename);
1222
  break;
1223
+
1224
  case 'js':
1225
  // $content = 'try{'
1226
  // . trim($content . (substr($content, -1) !== ';' ? ';' : '')) . "\n"
1229
  // : '}finally{};');
1230
  break;
1231
  }
1232
+
1233
+ // $text .= "/***** ".str_replace(ABSPATH, $this->wp_url,$filename)." *****/\n" . $content . "\n\n";
1234
  $text .= $content . "\n\n";
1235
  }
1236
  unset($filename);
1237
+ $text = $this->_tag_trim($text);
1238
 
1239
  return $text . (!empty($text) ? "\n" : '');
1240
  }
1244
  //**************************************************************************************
1245
  private function _file_write($filename, $content = '', $gzip = true) {
1246
  if (!empty($content)) {
1247
+ $this->ret_len += strlen(bin2hex($content));
1248
+
1249
  $handle = @fopen($filename, 'w');
1250
  @fwrite($handle, $content);
1251
  @fclose($handle);
1252
 
1253
  return ($gzip
1254
  ? $this->_file_gzip($filename, $content)
1255
+ : file_exists($filename) );
1256
+
1257
  } else {
1258
  return false;
1259
  }
1281
  }
1282
 
1283
  return (file_exists($filename . '.gz'));
1284
+
1285
  } else {
1286
  return false;
1287
  }
1305
  if (version_compare($ver, '1.6.0.3', '<='))
1306
  $src = $this->plugin_url . 'includes/js/prototype-1.6.0.3.min.js';
1307
 
1308
+ $wk_outer_js .= $this->_script_tag($src);
1309
  }
1310
  }
1311
 
1314
  if (!$prototype) {
1315
  $prototype = true;
1316
  $src = $this->plugin_url . 'includes/js/prototype-1.6.0.3.min.js';
1317
+ $wk_outer_js .= $this->_script_tag($src);
1318
  }
1319
  $scriptaculous = array(
1320
+ 'scriptaculous/scriptaculous' ,
1321
+ 'scriptaculous/controls' ,
1322
+ 'scriptaculous/dragdrop' ,
1323
+ 'scriptaculous/effects' ,
1324
+ 'scriptaculous/slider' ,
1325
+ 'scriptaculous/sound' ,
1326
+ 'scriptaculous/unittest' ,
1327
  );
1328
  foreach ($scriptaculous as $product) {
1329
  if (isset($js_libs[$product])) {
1331
  if (!empty($src)) {
1332
  if (version_compare($ver, '1.8.2', '<='))
1333
  $src = $this->plugin_url . 'includes/js/' . $product . '.min.js';
1334
+ $wk_outer_js .= $this->_script_tag($src);
 
1335
  }
1336
  }
1337
  }
1348
  $src = $this->plugin_url . 'includes/js/jquery-1.4.2.min.js';
1349
 
1350
  if ($prototype || $mootools || strpos($src, $this->wp_url) === FALSE) {
1351
+ $wk_outer_js .= $this->_script_tag($src);
1352
  } else {
1353
  $js_libs_src[] = $src;
1354
+ $wk_inner_js .= $this->_script_tag($src);
1355
  }
1356
 
1357
  // jQuery noConflict
1358
  if ($prototype || $mootools) {
1359
  $src = $this->plugin_url . 'includes/js/jquery.noconflict.js';
1360
  if (strpos($src, $this->wp_url) === FALSE) {
1361
+ $wk_outer_js .= $this->_script_tag($src);
1362
  } else {
1363
  $js_libs_src[] = $src;
1364
+ $wk_inner_js .= $this->_script_tag($src);
1365
  }
1366
  }
1367
  }
1373
  if (!empty($src)) {
1374
  if (version_compare($ver, '1.2.1', '<='))
1375
  $src = $this->plugin_url . 'includes/js/mootools-1.2.1-core-yc.js';
 
1376
  if ($prototype || $jquery || strpos($src, $this->wp_url) === FALSE) {
1377
+ $wk_outer_js .= $this->_script_tag($src);
1378
  } else {
1379
  $js_libs_src[] = $src;
1380
+ $wk_inner_js .= $this->_script_tag($src);
1381
  }
1382
  }
1383
  }
1402
  $longfilename .= $filename . filemtime($src);
1403
  $files[] = $filename;
1404
  } else {
1405
+ $html .= $this->_css_tag($style, $media);
1406
  }
1407
  }
1408
 
1412
  if (! file_exists($filename) ) {
1413
  if (count($files) > 0 && !empty($longfilename))
1414
  $css = $this->_files_read($files, 'css') . "\n\n" . $css;
1415
+ $css = $this->_css_optimise($css); // Optimise CSS
 
 
 
1416
  if (!empty($css))
1417
  $this->_file_write($filename, $css, $this->options['gzip_on'] || HC_MAKE_GZ_FILE );
1418
  }
1419
 
1420
+ $fileurl = $this->cache_url . $longfilename;
1421
+ // $fileurl = $this->options['dynamic']
1422
+ // ? $this->self_url . '?f=' . $md5_filename . '&amp;t=css'
1423
+ // : $this->cache_url . $longfilename ;
1424
+
1425
  if (file_exists($filename))
1426
+ $html .= $this->_css_tag($fileurl, $media);
1427
 
1428
  return $html;
1429
  }
1449
  if (!file_exists($filename) && !empty($css))
1450
  $this->_file_write($filename, $css, $this->options['gzip_on'] || HC_MAKE_GZ_FILE);
1451
 
1452
+ $fileurl = $this->cache_url . $longfilename;
1453
+ // $fileurl = $this->options['dynamic']
1454
+ // ? $this->self_url . '?f=' . $md5_filename . '&amp;t=css'
1455
+ // : $this->cache_url . $longfilename ;
1456
+
1457
  if (file_exists($filename))
1458
+ $html .= $this->_css_tag($fileurl, $media);
1459
 
1460
  return $html;
1461
  }
1474
  $longfilename .= $filename . filemtime($src);
1475
  $files[] = $filename;
1476
  } else {
1477
+ $html .= $this->_script_tag($javascript);
1478
  }
1479
  }
1480
 
1484
  if (! file_exists($filename) ) {
1485
  if (count($files) > 0 && !empty($longfilename))
1486
  $script = $this->_files_read($files, 'js') . "\n\n" . $script;
1487
+ $script = $this->_js_minify($script); // Minified JavaScript
 
 
 
1488
  if (!empty($script))
1489
  $this->_file_write($filename, $script, $this->options['gzip_on'] || HC_MAKE_GZ_FILE);
1490
  }
1491
 
1492
  $fileurl = $this->cache_url . $longfilename;
1493
+
 
 
 
1494
  if (file_exists($filename))
1495
+ $html .= $this->_script_tag($fileurl);
1496
 
1497
  return $html;
1498
  }
1516
  $this->_file_write($filename, $script, $this->options['gzip_on'] || HC_MAKE_GZ_FILE);
1517
 
1518
  $fileurl = $this->cache_url . $longfilename;
1519
+
 
 
 
1520
  if (file_exists($filename))
1521
+ $html .= $this->_script_tag($fileurl);
1522
 
1523
  return $html;
1524
  }
1555
  break;
1556
  }
1557
 
1558
+ return ($this->_tag_trim($text) . "\n");
1559
  }
1560
 
1561
  //**************************************************************************************
1576
  // Minified JavaScript
1577
  //**************************************************************************************
1578
  private function _js_minify($buffer) {
1579
+ $js = $this->_tag_trim($buffer);
1580
  if ($this->options['js_minify']) {
1581
  if ( class_exists('JSMin') ) {
1582
  $js = JSMin::minify($js);
1615
  }
1616
 
1617
  private function _css_optimise($buffer, $merge = true) {
1618
+ $css = $this->_tag_trim($buffer);
1619
 
1620
  if ($this->options['css_optimise']) {
1621
  if ( class_exists('Minify_CSS') ) {
1643
  // Create cache dir
1644
  //**************************************************************************************
1645
  private function _create_cache_dir($cache_dir = '') {
1646
+ if (empty($cache_dir))
1647
+ $cache_dir = HC_CACHE_DIR;
1648
  $cache_dir = $this->_wp_content_dir('/' . trailingslashit($cache_dir) );
1649
 
1650
  $mode = 0777;
1770
  //**************************************************************************************
1771
  // Show Option Page
1772
  //**************************************************************************************
1773
+ private function _checkbox($id, $flag = '') {
1774
+ if ( $flag === '' )
1775
+ $flag = $this->options[$id];
1776
+ return '<input type="checkbox" name="'.$id.'" id="'.$id.'" value="on" style="margin-right:0.5em;" '.($flag === true ? 'checked="true" ' : '').'/>';
1777
+ }
1778
+
1779
  public function option_page() {
1780
  if ($this->_chk_filters_update()) {
1781
  $this->options['filters'] = $this->filters;
1787
  check_admin_referer("update_options", "_wpnonce_update_options");
1788
 
1789
  // Update options
1790
+ $this->_options_update($this->stripArray($_POST));
1791
  $this->note .= "<strong>".__('Done!', $this->textdomain_name)."</strong>";
1792
 
1793
  } elseif(isset($_POST['remove_cache'])) {
1824
 
1825
  $out .= "<tr>";
1826
  $out .= "<td>";
1827
+ $out .= $this->_checkbox('cache_enabled');
1828
  $out .= __('CSS and JavaScript are cached on the server.', $this->textdomain_name);
1829
  $out .= "</td>";
1830
  $out .= "<td>";
1831
+ $out .= $this->_checkbox('js_move_foot');
1832
  $out .= __('Put JavaScripts at the Bottom.', $this->textdomain_name);
1833
  $out .= "</td>";
1834
  $out .= "<td>";
1835
  if ($this->options['cache_enabled']) {
1836
+ $out .= $this->_checkbox('dynamic');
1837
  $out .= __('CSS and JS are dynamically generated.', $this->textdomain_name);
1838
  }
1839
  $out .= "</td>";
1842
  if ($this->options['cache_enabled']) {
1843
  $out .= "<tr>";
1844
  $out .= "<td>";
1845
+ $out .= $this->_checkbox('combined_css');
1846
  $out .= __('Two or more CSS is combined.', $this->textdomain_name);
1847
  $out .= "</td>";
1848
  $out .= "<td>";
1849
+ $out .= $this->_checkbox('css_optimise');
1850
  $out .= __('CSS is optimized.', $this->textdomain_name);
1851
  $out .= "</td>";
1852
  $out .= "<td>";
1858
 
1859
  $out .= "<tr>";
1860
  $out .= "<td>";
1861
+ $out .= $this->_checkbox('combined_js');
1862
  $out .= __('Two or more JavaScript is combined.', $this->textdomain_name);
1863
  $out .= "</td>";
1864
  $out .= "<td>";
1865
+ $out .= $this->_checkbox('js_minify');
1866
  $out .= __('JavaScript is minified.', $this->textdomain_name);
1867
  $out .= "</td>";
1868
  $out .= "<td>";
1869
+ $out .= $this->_checkbox('foot_js');
1870
  $out .= __('Bottom JavaScript is combined, too.', $this->textdomain_name);
1871
  $out .= "</td>";
1872
  $out .= "</tr>\n";
1873
  }
1874
  $out .= "<tr>";
1875
  // $out .= "<td>";
1876
+ // $out .= $this->_checkbox('gzip_on');
1877
  // $out .= __('gzip compress to CSS and JS.', $this->textdomain_name);
1878
  // $out .= "</td>";
1879
  $out .= "<td>";
1880
+ $out .= $this->_checkbox('use_ajax_libs');
1881
  $out .= __('Use Google Ajax Libraries.', $this->textdomain_name);
1882
  $out .= "</td>";
1883
  $out .= "<td>";
1884
+ $out .= $this->_checkbox('ie_conditional');
1885
  $out .= __('Remove IE Conditional Tag.', $this->textdomain_name);
1886
  $out .= "</td>";
1887
  $out .= "<td>";
1890
 
1891
  $out .= "<tr>";
1892
  $out .= "<td>";
1893
+ $out .= $this->_checkbox('xml_declaration');
1894
  $out .= __('Add XML Declaration.', $this->textdomain_name);
1895
  $out .= "</td>";
1896
  $out .= "<td>";
1897
+ $out .= $this->_checkbox('canonical_tag');
1898
  $out .= __('Add canonical tag.', $this->textdomain_name);
1899
  $out .= "</td>";
1900
  $out .= "<td>";
1903
 
1904
  $out .= "<tr>";
1905
  $out .= "<td>";
1906
+ $out .= $this->_checkbox('rm_generator', isset($this->options['priority']['wp_head']['wp_generator']) && $this->options['priority']['wp_head']['wp_generator'] <= 0);
1907
  $out .= __('Remove generator tag.', $this->textdomain_name);
1908
  $out .= "</td>";
1909
  $out .= "<td>";
1910
+ $out .= $this->_checkbox('rm_rsd_link', isset($this->options['priority']['wp_head']['rsd_link']) && $this->options['priority']['wp_head']['rsd_link'] <= 0);
1911
  $out .= __('Remove RSD link tag.', $this->textdomain_name);
1912
  $out .= "</td>";
1913
  $out .= "<td>";
1914
+ $out .= $this->_checkbox('rm_manifest', isset($this->options['priority']['wp_head']['wlwmanifest_link']) && $this->options['priority']['wp_head']['wlwmanifest_link'] <= 0);
1915
  $out .= __('Remove wlwmanifest link tag.', $this->textdomain_name);
1916
  $out .= "</td>";
1917
  $out .= "</tr>\n";
1918
 
1919
  $out .= "<tr>";
1920
  $out .= "<td>";
1921
+ $out .= $this->_checkbox('debug_mode');
1922
  $out .= __('Debug mode', $this->textdomain_name);
1923
  $out .= "</td>";
1924
  $out .= "<td>";
1950
  $out .= '</select>';
1951
  $out .= "<br />\n";
1952
 
1953
+ $out .= $this->_checkbox('compress_colors', $this->options['csstidy_option']['compress_colors'] === true);
1954
  $out .= __('Compress colors', $this->textdomain_name);
1955
  $out .= '&nbsp;&nbsp;&nbsp;&nbsp;';
1956
+ $out .= $this->_checkbox('compress_font_weight', $this->options['csstidy_option']['compress_font_weight'] === true);
1957
  $out .= __('Compress font-weight', $this->textdomain_name);
1958
  $out .= '&nbsp;&nbsp;&nbsp;&nbsp;';
1959
+ $out .= $this->_checkbox('remove_bslash', $this->options['csstidy_option']['remove_bslash'] === true);
1960
  $out .= __('Remove unnecessary backslashes', $this->textdomain_name);
1961
  $out .= "<br />\n";
1962
 
2092
  //**************************************************************************************
2093
  // options update
2094
  //**************************************************************************************
2095
+ private function _checkbox_val( $check_array, $check_key, $check_val = 'on' ) {
2096
+ return (isset($check_array[$check_key]) && $check_array[$check_key] === $check_val);
2097
+ }
2098
  private function _options_update($recv_param) {
2099
+ $head_js = (array) $recv_param['head_js'];
2100
+ $remove_js = (array) $recv_param['remove_js'];
2101
+ $head_filters = (array) $recv_param['head_filters'];
2102
+ $head_remove = (array) $recv_param['head_remove'];
2103
+ $foot_filters = (array) $recv_param['foot_filters'];
2104
+ $foot_remove = (array) $recv_param['foot_remove'];
 
 
2105
 
2106
  // get options
2107
+ $this->options['xml_declaration'] = $this->_checkbox_val($recv_param, 'xml_declaration');
2108
+ $this->options['ie_conditional'] = $this->_checkbox_val($recv_param, 'ie_conditional');
2109
+ $this->options['canonical_tag'] = $this->_checkbox_val($recv_param, 'canonical_tag');
2110
+ $this->options['foot_js'] = $this->_checkbox_val($recv_param, 'foot_js');
2111
+ $this->options['dynamic'] = $this->_checkbox_val($recv_param, 'dynamic');
2112
+ $this->options['js_move_foot'] = $this->_checkbox_val($recv_param, 'js_move_foot');
2113
+ $this->options['cache_enabled'] = $this->_checkbox_val($recv_param, 'cache_enabled');
2114
+ $this->options['combined_css'] = $this->_checkbox_val($recv_param, 'combined_css');
2115
+ $this->options['combined_js'] = $this->_checkbox_val($recv_param, 'combined_js');
2116
+ $this->options['js_minify'] = $this->_checkbox_val($recv_param, 'js_minify');
2117
+ $this->options['css_optimise'] = $this->_checkbox_val($recv_param, 'css_optimise');
2118
+ $this->options['default_media'] = trim($recv_param['default_media']);
2119
+ $this->options['gzip_on'] = $this->_checkbox_val($recv_param, 'gzip_on');
2120
+ $this->options['use_ajax_libs'] = $this->_checkbox_val($recv_param, 'use_ajax_libs');
2121
+ $this->options['debug_mode'] = $this->_checkbox_val($recv_param, 'debug_mode');
2122
+ $this->options['csstidy_option'] = array(
2123
+ 'template' => (int) $recv_param['template'] ,
2124
+ 'optimise_shorthands' => (int) $recv_param['optimise_shorthands'] ,
2125
+ 'compress_colors' => $this->_checkbox_val($recv_param, 'compress_colors') ,
2126
+ 'compress_font_weight' => $this->_checkbox_val($recv_param, 'compress_font_weight') ,
2127
+ 'remove_bslash' => $this->_checkbox_val($recv_param, 'remove_bslash') ,
2128
+ );
2129
+
2130
+ $rm_generator = $this->_checkbox_val($recv_param, 'rm_generator');
2131
+ $rm_rsd_link = $this->_checkbox_val($recv_param, 'rm_rsd_link');
2132
+ $rm_manifest = $this->_checkbox_val($recv_param, 'rm_manifest');
2133
 
2134
  $this->options['remove_js'] = array();
2135
  foreach ((array) $this->options['head_js'] as $javascript => $value) {
2177
  $cache_dir = $this->_create_cache_dir();
2178
  if ( $cache_dir !== FALSE )
2179
  $this->_create_htaccess($cache_dir);
2180
+
2181
+ return $this->options;
2182
  }
2183
 
2184
  //**************************************************************************************
2188
  $this->deleteOptions();
2189
  $this->_remove_cache_file();
2190
  $this->options = $this->_init_options();
2191
+
2192
+ return $this->options;
2193
  }
2194
 
2195
  //**************************************************************************************
2196
  // Get function name
2197
  //**************************************************************************************
2198
  private function _get_function_name($function) {
2199
+ // return (is_set($function[0]) && is_set($function[1])
2200
+ return (is_object($function[0])
2201
  ? (get_class($function[0]) !== FALSE ? get_class($function[0]) : $function[0]) . '::' . $function[1]
2202
+ : $function );
 
2203
  }
2204
 
2205
  //**************************************************************************************
2237
  if ( isset($this->options['filters'][$tag]) ) {
2238
  foreach ( $filters as $function_name => $priority) {
2239
  $retval = ( !isset($this->options['filters'][$tag][$function_name]) );
2240
+ if ($retval)
2241
+ break;
2242
  }
2243
  } else {
2244
+ $retval = true;
2245
+ break;
2246
  }
2247
  }
2248
  unset ($filters);
2249
 
2250
  foreach ( $this->head_js as $key => $val ) {
2251
  if ( !isset($this->options['head_js'][$key]) ) {
2252
+ $retval = true;
2253
+ break;
2254
  }
2255
  }
2256
 
2268
 
2269
  $active_filters = (isset($wp_filter[$tag])
2270
  ? $wp_filter[$tag]
2271
+ : array() );
2272
  $custom_priority = (isset($this->options['priority'][$tag])
2273
  ? $this->options['priority'][$tag]
2274
+ : array() );
2275
  foreach ($this->no_conflict as $function_name) {
2276
  $custom_priority[$function_name] = HC_PRIORITY + 1;
2277
  }
2316
  else
2317
  $url = ( !function_exists('get_blog_option') ? get_option( 'siteurl' ) : get_blog_option( $blog_id, 'siteurl' ));
2318
 
2319
+ $url = str_replace( 'http://', $scheme.'://', $url );
2320
 
2321
  if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
2322
  $url .= '/' . ltrim( $path, '/' );
2328
  // raw shortcode
2329
  //**************************************************************************************
2330
  public function raw_formatter($content) {
2331
+ $new_content = '';
2332
+ $pattern_full = '{(\[raw\].*?\[/raw\])}is';
2333
+ $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
2334
+ $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
2335
+
2336
+ foreach ($pieces as $piece) {
2337
+ $new_content .= preg_match($pattern_contents, $piece, $matches)
2338
+ ? $matches[1]
2339
+ : wptexturize(wpautop($piece)) ;
2340
+ }
2341
+
2342
+ return $new_content;
 
 
2343
  }
2344
 
2345
  //**************************************************************************************
2356
  }
2357
 
2358
  private function _get_debug_info($buffer, $tag = '') {
2359
+ $ret_val = $this->_process_time();
 
 
 
 
2360
  $this->mtime_start = microtime();
2361
 
2362
+ $ret_val .= "<!--\n";
2363
+
2364
  $ret_val .= "***** Original ***********************************\n"
2365
  . str_replace(array('<', '>'), array('<', '>'), $buffer) . "\n"
2366
  . "**************************************************\n\n";
2391
 
2392
  return $ret_val;
2393
  }
2394
+
2395
+ private function _process_time() {
2396
+ return sprintf(
2397
+ "<!-- %s sec. %d / %d (%s saving) -- %s -->\n" ,
2398
+ round($this->process_time, 4) ,
2399
+ $this->ret_len ,
2400
+ $this->org_len ,
2401
+ round(($this->org_len - $this->ret_len) / $this->org_len * 100, 2) . '%' ,
2402
+ "{$this->plugin_name} ({$this->plugin_ver})"
2403
+ );
2404
+ }
2405
+
2406
+ //**************************************************************************************
2407
+ // utility
2408
+ //**************************************************************************************
2409
+ private function _dynamic_js_css($content) {
2410
+ return preg_replace(
2411
+ '/' . preg_quote($this->cache_url, '/') . '(js|css)\/([^\.]*)\.(js|css)/i' ,
2412
+ $this->wp_plugin_url(basename(dirname(__FILE__))) . "js_css.php?f=$2&amp;t=$3" ,
2413
+ $content
2414
+ );
2415
+ }
2416
+
2417
+ private function _tag_normalize($content) {
2418
+ // $content = str_replace($this->root_url, '/', $content);
2419
+ $content = preg_replace(
2420
+ array( "/[\s]+([^<>\=]+)\=['\"]([^'\"]*)['\"]/i", '/[\n\r]+/i', '/(<\/[^>]+>)[ \t]*(<[^>]+)/i' ) ,
2421
+ array( ' $1="$2"', "\n", "$1\n$2" ),
2422
+ $content
2423
+ );
2424
+ $content = $this->_tag_trim($content);
2425
+ return $content;
2426
+ }
2427
+
2428
+ private function _tag_trim($content) {
2429
+ $content = trim($content);
2430
+ return ( !empty($content) ? $content . "\n" : '' );
2431
+ }
2432
+
2433
+ private function _css_tag($src, $media = '', $inline_css = false) {
2434
+ $css_tag = '';
2435
+ if (!empty($src)) {
2436
+ if (empty($media))
2437
+ $media = $this->options['default_media'];
2438
+ $css_tag = $inline_css
2439
+ ? sprintf('<style type="text/css" media="%s">/*<![CDATA[ */%s/* ]]>*/</style>', $media, "\n".$src."\n")
2440
+ : sprintf('<link rel="stylesheet" type="text/css" href="%s" media="%s" />', $src, $media) ;
2441
+ }
2442
+ return $this->_tag_trim($css_tag);
2443
+ }
2444
+
2445
+ private function _script_tag($src, $inline_js = false) {
2446
+ $script_tag = '';
2447
+ if (!empty($src)) {
2448
+ $script_tag = $inline_js
2449
+ ? sprintf('<script type="text/javascript">//<![CDATA[%s//]]></script>', "\n".$src."\n")
2450
+ : sprintf('<script type="text/javascript" src="%s"></script>', $src) ;
2451
+ }
2452
+ return $this->_tag_trim($script_tag);
2453
+ }
2454
  }
2455
 
2456
+ //**************************************************************************************
2457
+ // Go! Go! Go!
2458
+ //**************************************************************************************
2459
  global $head_cleaner;
2460
 
2461
  $head_cleaner = new HeadCleaner();
2464
  register_activation_hook(__FILE__, array(&$head_cleaner, 'activation'));
2465
  if (function_exists('register_deactivation_hook'))
2466
  register_deactivation_hook(__FILE__, array(&$head_cleaner, 'deactivation'));
2467
+ ?>
includes/common-controller.php CHANGED
@@ -28,6 +28,7 @@ class wokController {
28
  var $note, $error;
29
  var $charset;
30
  var $wp25, $wp26, $wp27, $wp28, $wp29, $wp30;
 
31
 
32
  var $jquery_js = 'includes/js/jquery-1.4.2.min.js';
33
  var $jquery_ver = '1.4.2';
@@ -69,6 +70,12 @@ class wokController {
69
 
70
  if (!isset($wok_script_manager) && class_exists('wokScriptManager'))
71
  $wok_script_manager = new wokScriptManager();
 
 
 
 
 
 
72
  }
73
 
74
  function setPluginDir($file) {
@@ -220,11 +227,15 @@ class wokController {
220
  }
221
 
222
  // Output Javascript
 
 
 
223
  function writeScript($out = '', $place = 'head') {
224
  global $wok_script_manager;
225
  if ($out == '' || !isset($wok_script_manager))
226
  return;
227
- add_filter($place.'_script/manageScripts', create_function('$js', 'return $js . "'.addcslashes($out,'"').'";'));
 
228
  }
229
 
230
  // Regist jQuery
@@ -356,15 +367,15 @@ class wokScriptManager {
356
  }
357
 
358
  function adminHeadPrintScript() {
359
- $this->printScript(apply_filters('admin_head_script/manageScripts', ''));
360
  }
361
 
362
  function headPrintScript() {
363
- $this->printScript(apply_filters('head_script/manageScripts', ''));
364
  }
365
 
366
  function footerPrintScript() {
367
- $this->printScript(apply_filters('footer_script/manageScripts', ''));
368
  }
369
  }
370
  endif;
28
  var $note, $error;
29
  var $charset;
30
  var $wp25, $wp26, $wp27, $wp28, $wp29, $wp30;
31
+ var $inline_js;
32
 
33
  var $jquery_js = 'includes/js/jquery-1.4.2.min.js';
34
  var $jquery_ver = '1.4.2';
70
 
71
  if (!isset($wok_script_manager) && class_exists('wokScriptManager'))
72
  $wok_script_manager = new wokScriptManager();
73
+
74
+ $this->inline_js = array(
75
+ 'admin_head' => '',
76
+ 'head' => '',
77
+ 'footer' => '',
78
+ );
79
  }
80
 
81
  function setPluginDir($file) {
227
  }
228
 
229
  // Output Javascript
230
+ function scriptConcat($js, $place) {
231
+ return $js . $this->inline_js[$place];
232
+ }
233
  function writeScript($out = '', $place = 'head') {
234
  global $wok_script_manager;
235
  if ($out == '' || !isset($wok_script_manager))
236
  return;
237
+ $this->inline_js[$place] .= $out;
238
+ add_filter($place.'_script/manageScripts', array(&$this, "scriptConcat"), 10, 2);
239
  }
240
 
241
  // Regist jQuery
367
  }
368
 
369
  function adminHeadPrintScript() {
370
+ $this->printScript(apply_filters('admin_head_script/manageScripts', '', 'admin_head'));
371
  }
372
 
373
  function headPrintScript() {
374
+ $this->printScript(apply_filters('head_script/manageScripts', '', 'head'));
375
  }
376
 
377
  function footerPrintScript() {
378
+ $this->printScript(apply_filters('footer_script/manageScripts', '', 'footer'));
379
  }
380
  }
381
  endif;
js_css.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if (!defined('HC_CACHE_DIR'))
3
+ define('HC_CACHE_DIR', 'cache/head-cleaner');
4
+ if (!defined('HC_EXPIRED_JS_CSS'))
5
+ define('HC_EXPIRED_JS_CSS', 2592000); // 60 * 60 * 24 * 30 [sec.]
6
+
7
+ $error = false;
8
+ if (isset($_GET['f']) && isset($_GET['t'])) {
9
+ $cache_dir = realpath(dirname(__FILE__) . '/../../' . HC_CACHE_DIR) . '/';
10
+ $filename_hash = trim(stripslashes($_GET['f']));
11
+ $type = trim(stripslashes($_GET['t']));
12
+
13
+ if (strlen($filename_hash) == 32 && ($type == 'js' || $type == 'css')) {
14
+ $is_gzip = (strpos(strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') !== FALSE);
15
+ $ob_gzip = false;
16
+
17
+ $filename = "{$cache_dir}{$type}/{$filename_hash}.{$type}";
18
+ if ($is_gzip && file_exists($filename.'.gz'))
19
+ $filename .= '.gz';
20
+ else
21
+ $ob_gzip = $is_gzip;
22
+
23
+ if (file_exists($filename)) {
24
+ $offset = (!defined('HC_EXPIRED_JS_CSS') ? HC_EXPIRED_JS_CSS : 60 * 60 * 24 * 30);
25
+ $content_type = 'text/' . ($type == 'js' ? 'javascript' : $type);
26
+
27
+ header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($filename)).' GMT');
28
+ header('Expires: '.gmdate('D, d M Y H:i:s', time() + $offset).' GMT');
29
+ header("Content-type: $content_type");
30
+
31
+ if ($is_gzip)
32
+ header('Content-Encoding: gzip');
33
+
34
+ if ($ob_gzip)
35
+ ob_start("ob_gzhandler");
36
+
37
+ readfile($filename);
38
+
39
+ if ($ob_gzip)
40
+ ob_end_flush();
41
+
42
+ $error = false;
43
+ } else {
44
+ $error = 404;
45
+ }
46
+ } else {
47
+ $error = 403;
48
+ }
49
+ } else {
50
+ $error = 403;
51
+ }
52
+
53
+ if ( $error !== FALSE ) {
54
+ if(!function_exists('get_option')) {
55
+ $path = (defined('ABSPATH') ? ABSPATH : dirname(dirname(dirname(dirname(__FILE__)))) . '/');
56
+ require_once(file_exists($path.'wp-load.php') ? $path.'wp-load.php' : $path.'wp-config.php');
57
+ }
58
+
59
+ $err_msg = "Unknown Error";
60
+ switch ($error) {
61
+ case 403:
62
+ header("HTTP/1.0 403 Forbidden");
63
+ $err_msg = "403 : Forbidden";
64
+ break;
65
+ case 404:
66
+ header('HTTP/1.1 404 Not Found');
67
+ $err_msg = "404 : Not Found";
68
+ break;
69
+ default:
70
+ break;
71
+ }
72
+
73
+ if (function_exists('wp_die')) {
74
+ wp_die($err_msg);
75
+ } else {
76
+ echo $err_msg;
77
+ die();
78
+ }
79
+ }
languages/head-cleaner-tr_TR.mo ADDED
Binary file
languages/head-cleaner-tr_TR.po ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Head Cleaner\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2009-08-26 15:40+0900\n"
6
+ "PO-Revision-Date: \n"
7
+ "Last-Translator: Hakan Demiray <hakan@dmry.net>\n"
8
+ "Language-Team: \n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=utf-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
13
+ "X-Poedit-SourceCharset: utf-8\n"
14
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
15
+ "X-Textdomain-Support: yes\n"
16
+ "X-Poedit-SearchPath-0: .\n"
17
+
18
+ # description
19
+ #@ head-cleaner
20
+ msgid "Cleaning tags from your WordPress header and footer."
21
+ msgstr "Wordpress üst ve alt alanındaki etiketleri temizler"
22
+
23
+ #@ head-cleaner
24
+ #: ../head-cleaner.php:1420
25
+ msgid "Head Cleaner"
26
+ msgstr "Head Cleaner"
27
+
28
+ #@ head-cleaner
29
+ #: ../head-cleaner.php:1429
30
+ #: ../includes/common-controller.php:175
31
+ msgid "Settings"
32
+ msgstr "Ayarlar"
33
+
34
+ #@ head-cleaner
35
+ #: ../head-cleaner.php:1526
36
+ #: ../head-cleaner.php:1536
37
+ #: ../head-cleaner.php:1546
38
+ msgid "Done!"
39
+ msgstr "Tamamlandı!"
40
+
41
+ #@ head-cleaner
42
+ #: ../head-cleaner.php:1558
43
+ msgid "Head Cleaner Options"
44
+ msgstr "Head Cleaner Seçenekleri"
45
+
46
+ #@ head-cleaner
47
+ #: ../head-cleaner.php:1566
48
+ msgid "CSS and JavaScript are cached on the server."
49
+ msgstr "CSS ve JavaScript dosyalarını sunucu üzerinde önbellekle."
50
+
51
+ #@ head-cleaner
52
+ #: ../head-cleaner.php:1570
53
+ msgid "Put JavaScripts at the Bottom."
54
+ msgstr "JavaScript dosyalarını temanın altına ekle."
55
+
56
+ #@ head-cleaner
57
+ #: ../head-cleaner.php:1574
58
+ msgid "CSS and JS are dynamically generated."
59
+ msgstr "CSS ve JS dinamik olarak oluşturulsun."
60
+
61
+ #@ head-cleaner
62
+ #: ../head-cleaner.php:1582
63
+ msgid "Two or more CSS is combined."
64
+ msgstr "İki veya üstü CSS dosyası birleştirilsin."
65
+
66
+ #@ head-cleaner
67
+ #: ../head-cleaner.php:1586
68
+ msgid "CSS is optimized."
69
+ msgstr "CSS optimize edilsin."
70
+
71
+ #@ head-cleaner
72
+ #: ../head-cleaner.php:1589
73
+ msgid "Default media attribute applied to CSS."
74
+ msgstr "Varsayılan medya türü CSS ile uygulansın."
75
+
76
+ #@ head-cleaner
77
+ #: ../head-cleaner.php:1598
78
+ msgid "Two or more JavaScript is combined."
79
+ msgstr "İki veya üstü JavaScript dosyası birleştirilsin."
80
+
81
+ #@ head-cleaner
82
+ #: ../head-cleaner.php:1602
83
+ msgid "JavaScript is minified."
84
+ msgstr "JavaScript küçültülsün."
85
+
86
+ #@ head-cleaner
87
+ #: ../head-cleaner.php:1606
88
+ msgid "Bottom JavaScript is combined, too."
89
+ msgstr "Temanın altındaki JavaScript dosyaları birleştirilsin."
90
+
91
+ #@ head-cleaner
92
+ #: ../head-cleaner.php:1613
93
+ msgid "gzip compress to CSS and JS."
94
+ msgstr "CSS ve JS için Gzip sıkıştırma uygulansın."
95
+
96
+ #@ head-cleaner
97
+ #: ../head-cleaner.php:1617
98
+ msgid "Use Google Ajax Libraries."
99
+ msgstr "Google Ajax Kütüphaneleri Kullanılsın."
100
+
101
+ #@ head-cleaner
102
+ #: ../head-cleaner.php:1626
103
+ msgid "Add XML Declaration."
104
+ msgstr "XML bildirimleri eklensin."
105
+
106
+ #@ head-cleaner
107
+ #: ../head-cleaner.php:1630
108
+ msgid "Add canonical tag."
109
+ msgstr "canonical etiketi eklensin."
110
+
111
+ #@ head-cleaner
112
+ #: ../head-cleaner.php:1634
113
+ msgid "Remove IE Conditional Tag."
114
+ msgstr "IE Conditional etiketi kaldırılsın."
115
+
116
+ #@ head-cleaner
117
+ #: ../head-cleaner.php:1641
118
+ msgid "Remove generator tag."
119
+ msgstr "Üretici etiketi kaldırılsın."
120
+
121
+ #@ head-cleaner
122
+ #: ../head-cleaner.php:1645
123
+ msgid "Remove RSD link tag."
124
+ msgstr "RSD bağlantısı etiketi kaldırılsın."
125
+
126
+ #@ head-cleaner
127
+ #: ../head-cleaner.php:1649
128
+ msgid "Remove wlwmanifest link tag."
129
+ msgstr "wlwmanifest bağlantısı etiketi kaldırılsın."
130
+
131
+ #@ head-cleaner
132
+ #: ../head-cleaner.php:1656
133
+ msgid "Debug mode"
134
+ msgstr "Hata ayıklama modu."
135
+
136
+ #@ head-cleaner
137
+ #: ../head-cleaner.php:1669
138
+ msgid "The CSS optimization settings"
139
+ msgstr "CSS optimizasyon seçenekleri"
140
+
141
+ #@ head-cleaner
142
+ #: ../head-cleaner.php:1671
143
+ msgid "Compression (code layout):"
144
+ msgstr "Sıkıştırma (tema kodları):"
145
+
146
+ #@ head-cleaner
147
+ #: ../head-cleaner.php:1673
148
+ msgid "Highest (no readability, smallest size)"
149
+ msgstr "Çok yüksek (okunaklı değil, çok küçük boyutlu)"
150
+
151
+ #@ head-cleaner
152
+ #: ../head-cleaner.php:1674
153
+ msgid "High (moderate readability, smaller size)"
154
+ msgstr "Yüksek (okunabilir, küçük boyut)"
155
+
156
+ #@ head-cleaner
157
+ #: ../head-cleaner.php:1675
158
+ msgid "Standard (balance between readability and size)"
159
+ msgstr "Standart (orta okunabilir düzeyde ve boyutta)"
160
+
161
+ #@ head-cleaner
162
+ #: ../head-cleaner.php:1676
163
+ msgid "Low (higher readability)"
164
+ msgstr "Az (yüksek okunabilirlik)"
165
+
166
+ #@ head-cleaner
167
+ #: ../head-cleaner.php:1679
168
+ msgid "Optimise shorthands"
169
+ msgstr "Optimize kısaltmaları"
170
+
171
+ #@ head-cleaner
172
+ #: ../head-cleaner.php:1681
173
+ msgid "All optimisations"
174
+ msgstr "Tüm optimizasyonlar"
175
+
176
+ #@ head-cleaner
177
+ #: ../head-cleaner.php:1682
178
+ msgid "Safe optimisations"
179
+ msgstr "Güvenli optimizasyonlar"
180
+
181
+ #@ head-cleaner
182
+ #: ../head-cleaner.php:1683
183
+ msgid "Don't optimise"
184
+ msgstr "Optimize etme"
185
+
186
+ #@ head-cleaner
187
+ #: ../head-cleaner.php:1688
188
+ msgid "Compress colors"
189
+ msgstr "Renkleri sıkıştır"
190
+
191
+ #@ head-cleaner
192
+ #: ../head-cleaner.php:1691
193
+ msgid "Compress font-weight"
194
+ msgstr "font-weight sıkıştır"
195
+
196
+ #@ head-cleaner
197
+ #: ../head-cleaner.php:1694
198
+ msgid "Remove unnecessary backslashes"
199
+ msgstr "Gereksiz taksim işaretlerini kaldır"
200
+
201
+ #@ head-cleaner
202
+ #: ../head-cleaner.php:1702
203
+ msgid "Active Filters"
204
+ msgstr "Etkin Filtreler"
205
+
206
+ #@ head-cleaner
207
+ #: ../head-cleaner.php:1705
208
+ #: ../head-cleaner.php:1742
209
+ msgid "Don't process!"
210
+ msgstr "İşleme Koyma!"
211
+
212
+ #@ head-cleaner
213
+ #: ../head-cleaner.php:1706
214
+ #: ../head-cleaner.php:1743
215
+ msgid "Remove"
216
+ msgstr "Kaldır"
217
+
218
+ #@ head-cleaner
219
+ #: ../head-cleaner.php:1707
220
+ msgid "Head filters"
221
+ msgstr "Üst Alan Filtreleri"
222
+
223
+ #@ head-cleaner
224
+ #: ../head-cleaner.php:1709
225
+ #: ../head-cleaner.php:1746
226
+ msgid "Priority"
227
+ msgstr "Öncelik"
228
+
229
+ #@ head-cleaner
230
+ #: ../head-cleaner.php:1744
231
+ msgid "Bottom filters"
232
+ msgstr "Alt Alan Filtreleri"
233
+
234
+ #@ head-cleaner
235
+ #: ../head-cleaner.php:1781
236
+ msgid "Active JavaScripts"
237
+ msgstr "Etkin JavaScript Dosyaları"
238
+
239
+ #@ head-cleaner
240
+ #: ../head-cleaner.php:1784
241
+ msgid "Move to footer"
242
+ msgstr "Alt alana taşı"
243
+
244
+ #@ head-cleaner
245
+ #: ../head-cleaner.php:1785
246
+ msgid "JavaScripts"
247
+ msgstr "JavaScript'ler"
248
+
249
+ #@ head-cleaner
250
+ #: ../head-cleaner.php:1796
251
+ msgid "Update Options"
252
+ msgstr "Seçenekleri Güncelle"
253
+
254
+ #@ head-cleaner
255
+ #: ../head-cleaner.php:1801
256
+ msgid "Remove all cache files"
257
+ msgstr "Tüm önbellek dosyalarını kaldır"
258
+
259
+ #@ head-cleaner
260
+ #: ../head-cleaner.php:1804
261
+ msgid "All cache files are removed."
262
+ msgstr "Tüm önbellek dosyaları kaldırıldı."
263
+
264
+ #@ head-cleaner
265
+ #: ../head-cleaner.php:1805
266
+ msgid "Remove All Cache Files"
267
+ msgstr "Tüm Önbellek Dosyalarını Kaldır"
268
+
269
+ #@ head-cleaner
270
+ #: ../head-cleaner.php:1810
271
+ msgid "Uninstall"
272
+ msgstr "Kaldır"
273
+
274
+ #@ head-cleaner
275
+ #: ../head-cleaner.php:1813
276
+ msgid "All the settings of &quot;Head Cleaner&quot; are deleted."
277
+ msgstr "&quot;Head Cleaner&quot; eklentisinin tüm ayarları kaldırılacak."
278
+
279
+ #@ head-cleaner
280
+ #: ../head-cleaner.php:1814
281
+ msgid "Delete Options"
282
+ msgstr "Seçenekleri Sil"
283
+
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=9S8AJ
4
  Tags: head, header, footer, javascript, css, optimization, minified, performance
5
  Requires at least: 2.5
6
  Tested up to: 3.0.1
7
- Stable tag: 1.3.13
8
 
9
  Cleaning tags from your WordPress header and footer.
10
 
@@ -44,6 +44,7 @@ To speed up the loading of JavaScript and CSS.
44
  * Japanese (ja) - [OKAMOTO Wataru](http://dogmap.jp/ "dogmap.jp") (plugin author)
45
  * Spanish (es) - [Franz Hartmann](http://tolingo.com/ "tolingo.com - Franz Hartmann")
46
  * Russian (ru) - [ilyuha](http://antsar.info/ "ilyuha")
 
47
 
48
  If you have translated into your language, please let me know.
49
 
4
  Tags: head, header, footer, javascript, css, optimization, minified, performance
5
  Requires at least: 2.5
6
  Tested up to: 3.0.1
7
+ Stable tag: 1.3.14
8
 
9
  Cleaning tags from your WordPress header and footer.
10
 
44
  * Japanese (ja) - [OKAMOTO Wataru](http://dogmap.jp/ "dogmap.jp") (plugin author)
45
  * Spanish (es) - [Franz Hartmann](http://tolingo.com/ "tolingo.com - Franz Hartmann")
46
  * Russian (ru) - [ilyuha](http://antsar.info/ "ilyuha")
47
+ * Turkish (tr_TR) - [Hakan Demiray](http://www.dmry.net/ "Günlük Haftalık Aylık")
48
 
49
  If you have translated into your language, please let me know.
50
 
readme_ja.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=9S8AJ
4
  Tags: head optimization, javascript, css, optimization, minified, performance
5
  Requires at least: 2.5
6
  Tested up to: 3.0.1
7
- Stable tag: 1.3.13
8
 
9
  Head �� footer �����|�����܂��B
10
 
4
  Tags: head optimization, javascript, css, optimization, minified, performance
5
  Requires at least: 2.5
6
  Tested up to: 3.0.1
7
+ Stable tag: 1.3.14
8
 
9
  Head �� footer �����|�����܂��B
10