Head Cleaner - Version 1.4.2.1

Version Description

Download this release

Release Info

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

Code changes from version 1.4.2 to 1.4.2.1

Files changed (3) hide show
  1. head-cleaner.php +67 -28
  2. readme.txt +4 -1
  3. readme_ja.txt +1 -1
head-cleaner.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: Head Cleaner
4
- Version: 1.4.2
5
  Plugin URI: http://wppluginsj.sourceforge.jp/head-cleaner/
6
  Description: Cleaning tags from your WordPress header and footer.
7
  Author: wokamoto
@@ -72,7 +72,7 @@ class HeadCleaner extends wokController {
72
  const ANALYZE_EXPIRED = 604800; // 60 * 60 * 24 * 7 [sec.]
73
  const XMLNS = 'http://www.w3.org/1999/xhtml';
74
  const XMLNS_OG = 'http://ogp.me/ns#';
75
- // const XMLNS_FB = 'http://www.facebook.com/2008/fbml';
76
  const IMG_BASE64_MAX_SIZE = 4096;
77
 
78
  // Deafault Options
@@ -467,7 +467,6 @@ class HeadCleaner extends wokController {
467
 
468
  $ret_val = '';
469
  $doctype_tag = '';
470
- $html_tag = '';
471
  $head_tag = '';
472
  $meta_tag = '';
473
  $title_tag = '';
@@ -495,33 +494,68 @@ class HeadCleaner extends wokController {
495
 
496
  // for IE conditional tag
497
  list($IE_conditional_tags, $head_txt, $ie6) = $this->_parse_IE_conditional_tags($buffer);
498
-
499
  $IE_conditional_tag_pattern = '/(<\!-+[ \t]*\[if[ \t]*[\(]?[ \t]*(IE|[gl]te?[ \t]+IE)[^\]]+\][ \t]*>)[ \t\r\n]*(.*?)[ \t\r\n]*(<\![ \t]*\[endif\][ \t]*-+>)/ims';
500
  if (!$this->options['ie_conditional'] && count($IE_conditional_tags) > 0) {
 
501
  foreach ((array) $IE_conditional_tags as $IE_conditional_tag) {
502
  if (isset($IE_conditional_tag[0])) {
503
  $IE_tag = $this->_tag_trim(preg_replace($IE_conditional_tag_pattern, "$1$3$4", $IE_conditional_tag[0]));
504
  if ( strpos(strtolower($IE_tag), '<html') !== false ) {
505
- $html_tag .= $IE_tag;
506
  }
507
  }
508
  }
509
  unset($IE_conditional_tag);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
510
  }
511
 
512
  // Get <html> tag and <head> tag
513
  if ($doctype == 'xhtml') {
514
  // xhtml
515
- $xml_head = empty($xml_head) ? $this->_tag_trim('<?xml version="1.0" encoding="'.$this->charset.'"?>') : $xml_head;
516
- $doctype_tag = empty($doctype_tag) ? $this->_tag_trim('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">') : $doctype_tag;
517
- $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;
518
- $head_tag = empty($head_tag) ? $this->_tag_trim('<head profile="http://gmpg.org/xfn/11">') : $head_tag;
 
 
 
 
 
 
 
 
519
  } else {
520
  // html
521
  $xml_head = '';
522
- $doctype_tag = empty($doctype_tag) ? $this->_tag_trim('<!DOCTYPE html>') : $doctype_tag;
523
- $html_tag = empty($html_tag) ? $this->_tag_trim('<html dir="ltr" lang="'.$this->lang.'">') : $html_tag;
524
- $head_tag = empty($head_tag) ? $this->_tag_trim('<head>') : $head_tag;
 
 
 
 
 
 
525
  }
526
 
527
  if ($this->options['add_ogp_tag']) {
@@ -540,8 +574,6 @@ class HeadCleaner extends wokController {
540
  }
541
 
542
  // ***** Parse Start! *****
543
-
544
- $html_tag = $this->_html_tag_normalize($html_tag, $doctype);
545
  $meta_tag = $this->_dom_to_html($dom->find("meta"));
546
  $title_tag = $this->_dom_to_html($dom->find("title"), 1);
547
  $base_tag = $this->_dom_to_html($dom->find("base"), 1);
@@ -2800,8 +2832,9 @@ E__O__T;
2800
  $xml_lang = $this->lang;
2801
  $dir = 'ltr';
2802
  $lang = $this->lang;
2803
- $xmlns_og = self::XMLNS_OG;
2804
- // $xmlns_fb = self::XMLNS_FB;
 
2805
 
2806
  if (preg_match_all('/ +([^ ]*)=[\'"]([^\'"]*)[\'"]/', $html_tag, $matches, PREG_SET_ORDER)) {
2807
  foreach ((array) $matches as $match) {
@@ -2818,15 +2851,15 @@ E__O__T;
2818
  case 'dir':
2819
  $dir = $match[2];
2820
  break;
2821
- case 'lang':
2822
- $lang = $match[2];
2823
  break;
2824
  case 'xmlns:og':
2825
  $xmlns_og = $match[2];
2826
  break;
2827
- // case 'xmlns:fb':
2828
- // $xmlns_fb = $match[2];
2829
- // break;
2830
  }
2831
  }
2832
  unset($match);
@@ -2834,17 +2867,23 @@ E__O__T;
2834
  unset($matches);
2835
 
2836
  if ( empty($html_tag) ) {
2837
- $html_tag = $this->_tag_trim( $doctype === 'xhtml'
2838
- ? '<html xmlns="'.$xmlns.'" xml:lang="'.$xml_lang.'" lang="'.$lang.'">'
2839
- : '<html dir="'.$dir.'" lang="'.$lang.'">' );
 
 
 
 
 
 
2840
  }
2841
 
2842
  if ($this->options['add_ogp_tag']) {
2843
- if (!preg_match('/xmlns:og=[\'"][^\'"]+[\'"]"/i', $html_tag)) {
2844
- $html_tag = preg_replace('/(<html[^>]*)>/i', '$1 xmlns:og="'.$xmlns_og.'">', $html_tag);
2845
  }
2846
- // if (!preg_match('/xmlns:fb=[\'"][^\'"]+[\'"]"/i', $html_tag)) {
2847
- // $html_tag = preg_replace('/(<html[^>]*)>/i', '$1 xmlns:fb="'.$xmlns_fb.'">', $html_tag);
2848
  // }
2849
  }
2850
 
1
  <?php
2
  /*
3
  Plugin Name: Head Cleaner
4
+ Version: 1.4.2.1
5
  Plugin URI: http://wppluginsj.sourceforge.jp/head-cleaner/
6
  Description: Cleaning tags from your WordPress header and footer.
7
  Author: wokamoto
72
  const ANALYZE_EXPIRED = 604800; // 60 * 60 * 24 * 7 [sec.]
73
  const XMLNS = 'http://www.w3.org/1999/xhtml';
74
  const XMLNS_OG = 'http://ogp.me/ns#';
75
+ const XMLNS_FB = 'http://www.facebook.com/2008/fbml';
76
  const IMG_BASE64_MAX_SIZE = 4096;
77
 
78
  // Deafault Options
467
 
468
  $ret_val = '';
469
  $doctype_tag = '';
 
470
  $head_tag = '';
471
  $meta_tag = '';
472
  $title_tag = '';
494
 
495
  // for IE conditional tag
496
  list($IE_conditional_tags, $head_txt, $ie6) = $this->_parse_IE_conditional_tags($buffer);
 
497
  $IE_conditional_tag_pattern = '/(<\!-+[ \t]*\[if[ \t]*[\(]?[ \t]*(IE|[gl]te?[ \t]+IE)[^\]]+\][ \t]*>)[ \t\r\n]*(.*?)[ \t\r\n]*(<\![ \t]*\[endif\][ \t]*-+>)/ims';
498
  if (!$this->options['ie_conditional'] && count($IE_conditional_tags) > 0) {
499
+ $html_tag = '';
500
  foreach ((array) $IE_conditional_tags as $IE_conditional_tag) {
501
  if (isset($IE_conditional_tag[0])) {
502
  $IE_tag = $this->_tag_trim(preg_replace($IE_conditional_tag_pattern, "$1$3$4", $IE_conditional_tag[0]));
503
  if ( strpos(strtolower($IE_tag), '<html') !== false ) {
504
+ $html_tag .= $IE_tag;
505
  }
506
  }
507
  }
508
  unset($IE_conditional_tag);
509
+
510
+ // Get <html> tag
511
+ if (!empty($html_tag)) {
512
+ $replace = array();
513
+ $pattern = '/<html[^>]*>/ims';
514
+ if (preg_match_all($pattern, $html_tag, $matches)) {
515
+ foreach ($matches[0] as $match) {
516
+ $replace[] = trim($this->_html_tag_normalize($match));
517
+ }
518
+ }
519
+ if (count($replace) > 0 && preg_match_all($pattern, $html_tag, $matches)) {
520
+ $html_tag = str_replace($matches[0], $replace, $html_tag);
521
+ }
522
+ unset($replace);
523
+ unset($matches);
524
+ }
525
+
526
+ if (empty($html_tag) && preg_match('/(<html[^>]*>)(.*)$/ism', $buffer, $matches)) {
527
+ $html_tag = $this->_html_tag_normalize($this->_tag_trim($matches[1]), $doctype);
528
+ }
529
+ unset($matches);
530
  }
531
 
532
  // Get <html> tag and <head> tag
533
  if ($doctype == 'xhtml') {
534
  // xhtml
535
+ if (empty($xml_head)) {
536
+ $xml_head = $this->_tag_trim('<?xml version="1.0" encoding="'.$this->charset.'"?>');
537
+ }
538
+ if (empty($doctype_tag)) {
539
+ $doctype_tag = $this->_tag_trim('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
540
+ }
541
+ if (empty($html_tag)) {
542
+ $html_tag = $this->_html_tag_normalize($this->_tag_trim('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$this->lang.'" lang="'.$this->lang.'">'), $doctype);
543
+ }
544
+ if (empty($head_tag)) {
545
+ $head_tag = $this->_tag_trim('<head profile="http://gmpg.org/xfn/11">');
546
+ }
547
  } else {
548
  // html
549
  $xml_head = '';
550
+ if (empty($doctype_tag)) {
551
+ $doctype_tag = $this->_tag_trim('<!DOCTYPE html>');
552
+ }
553
+ if (empty($html_tag)) {
554
+ $html_tag = $this->_html_tag_normalize($this->_tag_trim('<html dir="ltr" lang="'.$this->lang.'">'), $doctype);
555
+ }
556
+ if (empty($head_tag)) {
557
+ $this->_tag_trim('<head>');
558
+ }
559
  }
560
 
561
  if ($this->options['add_ogp_tag']) {
574
  }
575
 
576
  // ***** Parse Start! *****
 
 
577
  $meta_tag = $this->_dom_to_html($dom->find("meta"));
578
  $title_tag = $this->_dom_to_html($dom->find("title"), 1);
579
  $base_tag = $this->_dom_to_html($dom->find("base"), 1);
2832
  $xml_lang = $this->lang;
2833
  $dir = 'ltr';
2834
  $lang = $this->lang;
2835
+ $class = '';
2836
+ $xmlns_og = '';
2837
+ $xmlns_fb = '';
2838
 
2839
  if (preg_match_all('/ +([^ ]*)=[\'"]([^\'"]*)[\'"]/', $html_tag, $matches, PREG_SET_ORDER)) {
2840
  foreach ((array) $matches as $match) {
2851
  case 'dir':
2852
  $dir = $match[2];
2853
  break;
2854
+ case 'class':
2855
+ $class = $match[2];
2856
  break;
2857
  case 'xmlns:og':
2858
  $xmlns_og = $match[2];
2859
  break;
2860
+ case 'xmlns:fb':
2861
+ $xmlns_fb = $match[2];
2862
+ break;
2863
  }
2864
  }
2865
  unset($match);
2867
  unset($matches);
2868
 
2869
  if ( empty($html_tag) ) {
2870
+ $html_tag = $this->_tag_trim(
2871
+ '<html ' .
2872
+ ($doctype === 'xhtml'
2873
+ ? "xmlns=\"{$xmlns}\" xml:lang=\"{$xml_lang}\" lang=\"{$lang}\""
2874
+ : "dir=\"{$dir}\" lang=\"{$lang}\"") .
2875
+ (!empty($class) ? " class=\"{$class}\"" : '') .
2876
+ (!empty($xmlns_og) ? " xmlns:og=\"{$xmlns_og}\"" : '') .
2877
+ (!empty($xmlns_fb) ? " xmlns:fb=\"{$xmlns_fb}\"" : '') .
2878
+ '>');
2879
  }
2880
 
2881
  if ($this->options['add_ogp_tag']) {
2882
+ if (!preg_match('/xmlns:og="[^"]+"/i', $html_tag)) {
2883
+ $html_tag = preg_replace('/(<html[^>]*)>/i', '$1 xmlns:og="'.(!empty($xmlns_og) ? $xmlns_og : self::XMLNS_OG).'">', $html_tag);
2884
  }
2885
+ // if (!preg_match('/xmlns:fb="[^"]+"/i', $html_tag)) {
2886
+ // $html_tag = preg_replace('/(<html[^>]*)>/i', '$1 xmlns:fb="'.(!empty($xmlns_fb) ? $xmlns_fb : self::XMLNS_FB).'">', $html_tag);
2887
  // }
2888
  }
2889
 
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, facebook, OGP
5
  Requires at least: 2.5
6
  Tested up to: 3.1
7
- Stable tag: 1.4.2
8
 
9
  Cleaning tags from your WordPress header and footer.
10
 
@@ -91,6 +91,9 @@ Head Cleaner Ver.1.1.5 includes 'php_browscap.ini' .
91
 
92
  == Changelog ==
93
 
 
 
 
94
  **1.4.2 - April 20, 2011**
95
  Add an item to the Options page set.
96
  (Added the option to "Add Last-Modified tag" and "Paranoia mode")
4
  Tags: head, header, footer, javascript, css, optimization, minified, performance, facebook, OGP
5
  Requires at least: 2.5
6
  Tested up to: 3.1
7
+ Stable tag: 1.4.2.1
8
 
9
  Cleaning tags from your WordPress header and footer.
10
 
91
 
92
  == Changelog ==
93
 
94
+ **1.4.2.1 - April 20, 2011**
95
+ Fixed a bug, html tag issue.
96
+
97
  **1.4.2 - April 20, 2011**
98
  Add an item to the Options page set.
99
  (Added the option to "Add Last-Modified tag" and "Paranoia mode")
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.1
7
- Stable tag: 1.4.2
8
 
9
  Head と footer をお掃除します。
10
 
4
  Tags: head optimization, javascript, css, optimization, minified, performance
5
  Requires at least: 2.5
6
  Tested up to: 3.1
7
+ Stable tag: 1.4.2.1
8
 
9
  Head と footer をお掃除します。
10