Head Cleaner - Version 1.3.7

Version Description

Download this release

Release Info

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

Code changes from version 1.3.6 to 1.3.7

Files changed (3) hide show
  1. head-cleaner.php +111 -45
  2. readme.txt +5 -2
  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.3.6
5
  Plugin URI: http://wppluginsj.sourceforge.jp/head-cleaner/
6
  Description: Cleaning tags from your WordPress header and footer.
7
  Author: wokamoto
@@ -60,6 +60,7 @@ define('HC_CACHE_DIR', 'cache/head-cleaner');
60
  if (!defined('ABSPATH') && strstr($_SERVER['PHP_SELF'], '/head-cleaner.php')) {
61
  define('HC_EXPIRED_JS_CSS', 2592000); // 60 * 60 * 24 * 30 [sec.]
62
 
 
63
  if (isset($_GET['f']) && isset($_GET['t'])) {
64
  $cache_dir = realpath(dirname(__FILE__) . '/../../' . HC_CACHE_DIR) . '/';
65
  $filename_hash = trim(stripslashes($_GET['f']));
@@ -80,21 +81,45 @@ if (!defined('ABSPATH') && strstr($_SERVER['PHP_SELF'], '/head-cleaner.php')) {
80
  header('Content-Encoding: gzip');
81
 
82
  readfile($filename);
83
- exit();
84
  } else {
85
- header('HTTP/1.1 404 Not Found');
86
- echo "404 : Not Found";
87
- die();
88
  }
89
  } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  header("HTTP/1.0 403 Forbidden");
91
- echo "403 : Forbidden";
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  die();
93
  }
94
- } else {
95
- header("HTTP/1.0 403 Forbidden");
96
- echo "403 : Forbidden";
97
- die();
98
  }
99
  }
100
 
@@ -107,9 +132,9 @@ if (!class_exists('wokController') || !class_exists('wokScriptManager'))
107
  //**************************************************************************************
108
  // Head Cleaner
109
  //**************************************************************************************
110
- class HeadCleanerController extends wokController {
111
  public $plugin_name = 'head-cleaner';
112
- public $plugin_ver = '1.3.6';
113
 
114
  // Deafault Options
115
  private $options_default = array(
@@ -169,7 +194,7 @@ class HeadCleanerController extends wokController {
169
  );
170
 
171
  private $default_head_filters = array(
172
- 'HeadCleanerController::.*' ,
173
  'noindex' ,
174
  'lambda_[\d]+' ,
175
  'rsd_link' ,
@@ -186,7 +211,7 @@ class HeadCleanerController extends wokController {
186
  /**********************************************************
187
  * Constructor
188
  ***********************************************************/
189
- public function HeadCleanerController() {
190
  $this->__construct();
191
  }
192
  public function __construct() {
@@ -513,7 +538,7 @@ class HeadCleanerController extends wokController {
513
  if (count($dom->find("link[rel='canonical']")) <= 0 && $this->options['canonical_tag'])
514
  $link_tag .= '<link rel="canonical" href="' . htmlspecialchars($url, ENT_QUOTES) . '" />'."\n";
515
 
516
- $css_tag = ''; $inner_css = ''; $css_src = array();
517
  $elements = $dom->find("link[rel='stylesheet']");
518
  foreach ((array) $elements as $element) {
519
  $tag = trim($element->outertext);
@@ -521,7 +546,7 @@ class HeadCleanerController extends wokController {
521
  if (strpos($element->href, $this->wp_url) === FALSE) {
522
  $css_tag .= trim($tag) . "\n";
523
  } elseif ( isset($element->id) && !empty($element->id) ) {
524
- $css_tag .= trim($tag) . "\n";
525
  } else {
526
  $media = trim( isset($element->media) ? $element->media : $this->options['default_media'] );
527
  $media = ( empty($media) || is_null($media) || $media === FALSE ? $this->options['default_media'] : $media );
@@ -561,7 +586,7 @@ class HeadCleanerController extends wokController {
561
  $css_tag = trim($css_tag) . "\n";
562
  foreach ($css_src as $key => $val) {
563
  $inner_css = $this->_combined_css($val, trim(isset($wk_inline_css[$key]) ? $wk_inline_css[$key] : '' ), $key);
564
- $css_tag .= trim($inner_css) . "\n";
565
  if (isset($wk_inline_css[$key])) $wk_inline_css[$key] = '';
566
  }
567
  foreach ($wk_inline_css as $key => $val) {
@@ -572,7 +597,7 @@ class HeadCleanerController extends wokController {
572
  }
573
  }
574
  } else {
575
- $css_tag = trim(trim($css_tag) . "\n" . trim($inner_css)) . "\n";
576
  foreach ($wk_inline_css as $key => $val) {
577
  $val = trim($val);
578
  if (!empty($val)) {
@@ -582,7 +607,7 @@ class HeadCleanerController extends wokController {
582
  }
583
  }
584
  } else {
585
- $css_tag = trim(trim($css_tag) . "\n" . trim($inner_css)) . "\n";
586
  foreach ($wk_inline_css as $key => $val) {
587
  $val = trim($val);
588
  if (!empty($val)) {
@@ -897,10 +922,31 @@ class HeadCleanerController extends wokController {
897
  $content = trim(isset($tags[$type][$name]) && isset($tags[$type][$name]['content'])
898
  ? $tags[$type][$name]['content']
899
  : '');
900
- $content = trim($content
901
- . (!empty($content) ? ', ' : '')
902
- . (isset($element->content) ? $element->content : '')
 
 
 
 
 
 
 
 
 
 
903
  );
 
 
 
 
 
 
 
 
 
 
 
904
 
905
  $tags[$type][$name] = array(
906
  'name' => $name
@@ -919,15 +965,27 @@ class HeadCleanerController extends wokController {
919
  }
920
  unset($element); unset($elements);
921
 
922
- foreach ((array) $tags as $tag_types) {
923
- foreach ((array) $tag_types as $tag) {
924
- $html .= "<$type";
925
- foreach((array) $tag as $key => $val) {
926
- $html .= " $key=\"$val\"";
 
 
 
 
 
 
 
 
 
 
 
 
927
  }
928
- $html .= " />\n";
 
929
  }
930
- unset($tag);
931
  }
932
  unset($tags); unset($tag_types);
933
 
@@ -942,11 +1000,15 @@ class HeadCleanerController extends wokController {
942
  private function _abs_url($path, $base_path = ''){
943
  if (preg_match('/^https?:\/\//i', $base_path))
944
  $base_path = str_replace($this->wp_url, ABSPATH, $base_path);
 
945
  $absolute_path = realpath($base_path . '/' . $path);
946
- if(!$absolute_path)
947
- $absolute_path = $base_path . '/' . $path;
948
 
949
  $url = str_replace(ABSPATH, $this->wp_url, $absolute_path);
 
 
 
950
  return $url;
951
  }
952
 
@@ -972,15 +1034,15 @@ class HeadCleanerController extends wokController {
972
  // Read file
973
  //**************************************************************************************
974
  private function _file_read($filename) {
 
975
  if (preg_match('/^https?:\/\//i', $filename)) {
976
  $content = file_get_contents($filename);
977
  } else {
978
- if (file_exists($filename)) {
 
979
  $handle = @fopen($filename, 'r');
980
  $content = trim(@fread($handle, filesize($filename)));
981
  @fclose($handle);
982
- } else {
983
- $content = false;
984
  }
985
  }
986
 
@@ -1006,8 +1068,9 @@ class HeadCleanerController extends wokController {
1006
  // : '}finally{};');
1007
  break;
1008
  }
1009
- $text .= "/***** ".str_replace(ABSPATH, $this->wp_url,$filename)." *****/\n"
1010
- . $content . "\n\n";
 
1011
  }
1012
  unset($filename);
1013
  $text = trim($text);
@@ -1374,13 +1437,15 @@ class HeadCleanerController extends wokController {
1374
  // Optimise CSS
1375
  //**************************************************************************************
1376
  private function _css_import($css) {
1377
- if (preg_match_all('/@import[ \t]*url[ \t]*\([\'"]?([^\)]*)[\'"]?\);?/i', $css, $matches, PREG_SET_ORDER)) {
1378
  $search = array(); $replace = array();
1379
  foreach ((array) $matches as $match) {
1380
  $filename = str_replace($this->wp_url, ABSPATH, trim($match[1]));
1381
- $content = $this->_file_read($filename);
1382
  $content = $this->_css_url_edit($content, $filename);
1383
- if (preg_match('/@import[ \t]*url[ \t]*\[\'"]?[^\)]*[\'"]?\;?/i', $content))
 
 
1384
  $content = $this->_css_import($content);
1385
  $search[] = $match[0];
1386
  $replace[] = $content;
@@ -1389,15 +1454,14 @@ class HeadCleanerController extends wokController {
1389
  unset($match); unset($search); unset($replace);
1390
  }
1391
  unset($matches);
 
1392
  return $css;
1393
  }
1394
 
1395
- private function _css_optimise($buffer) {
1396
  $css = trim($buffer . "\n");
1397
 
1398
  if ($this->options['css_optimise']) {
1399
- $css = $this->_css_import($css);
1400
-
1401
  $csstidy = new csstidy();
1402
  $csstidy->set_cfg('optimise_shorthands', $this->options['csstidy_option']['optimise_shorthands']);
1403
  $csstidy->set_cfg('compress_colors', $this->options['csstidy_option']['compress_colors']);
@@ -1408,6 +1472,8 @@ class HeadCleanerController extends wokController {
1408
  $css = $csstidy->print->plain();
1409
  unset($csstidy);
1410
  }
 
 
1411
  $css = trim($css);
1412
 
1413
  return $css . (!empty($css) ? "\n" : '');
@@ -2070,7 +2136,7 @@ class HeadCleanerController extends wokController {
2070
  ? $this->filters[$tag]
2071
  : array());
2072
  foreach ($active_filters as $function_name => $priority) {
2073
- if (strpos($function_name, 'HeadCleanerController') === FALSE && strpos($function_name, 'noindex') === FALSE)
2074
  $ret_val .= " ($priority) : $function_name\n";
2075
  }
2076
  $ret_val .= "**************************************************\n\n";
@@ -2093,7 +2159,7 @@ class HeadCleanerController extends wokController {
2093
 
2094
  global $head_cleaner;
2095
 
2096
- $head_cleaner = new HeadCleanerController();
2097
 
2098
  if (is_admin()) {
2099
  add_action('admin_menu', array(&$head_cleaner, 'admin_menu'));
@@ -2109,4 +2175,4 @@ if (is_admin()) {
2109
  add_action('wp_footer', array(&$head_cleaner, 'filters_save'), 11);
2110
 
2111
  }
2112
- ?>
1
  <?php
2
  /*
3
  Plugin Name: Head Cleaner
4
+ Version: 1.3.7
5
  Plugin URI: http://wppluginsj.sourceforge.jp/head-cleaner/
6
  Description: Cleaning tags from your WordPress header and footer.
7
  Author: wokamoto
60
  if (!defined('ABSPATH') && strstr($_SERVER['PHP_SELF'], '/head-cleaner.php')) {
61
  define('HC_EXPIRED_JS_CSS', 2592000); // 60 * 60 * 24 * 30 [sec.]
62
 
63
+ $error = false;
64
  if (isset($_GET['f']) && isset($_GET['t'])) {
65
  $cache_dir = realpath(dirname(__FILE__) . '/../../' . HC_CACHE_DIR) . '/';
66
  $filename_hash = trim(stripslashes($_GET['f']));
81
  header('Content-Encoding: gzip');
82
 
83
  readfile($filename);
84
+ $error = false;
85
  } else {
86
+ $error = 404;
 
 
87
  }
88
  } else {
89
+ $error = 403;
90
+ }
91
+ } else {
92
+ $error = 403;
93
+ }
94
+
95
+ if ( $error === FALSE ) {
96
+ exit();
97
+ } else {
98
+ if(!function_exists('get_option')) {
99
+ $path = (defined('ABSPATH') ? ABSPATH : dirname(dirname(dirname(dirname(__FILE__)))) . '/');
100
+ require_once(file_exists($path.'wp-load.php') ? $path.'wp-load.php' : $path.'wp-config.php');
101
+ }
102
+
103
+ $err_msg = "Unknown Error";
104
+ switch ($error) {
105
+ case 403:
106
  header("HTTP/1.0 403 Forbidden");
107
+ $err_msg = "403 : Forbidden";
108
+ break;
109
+ case 404:
110
+ header('HTTP/1.1 404 Not Found');
111
+ $err_msg = "404 : Not Found";
112
+ break;
113
+ default:
114
+ break;
115
+ }
116
+
117
+ if (function_exists('wp_die')) {
118
+ wp_die($err_msg);
119
+ } else {
120
+ echo $err_msg;
121
  die();
122
  }
 
 
 
 
123
  }
124
  }
125
 
132
  //**************************************************************************************
133
  // Head Cleaner
134
  //**************************************************************************************
135
+ class HeadCleaner extends wokController {
136
  public $plugin_name = 'head-cleaner';
137
+ public $plugin_ver = '1.3.7';
138
 
139
  // Deafault Options
140
  private $options_default = array(
194
  );
195
 
196
  private $default_head_filters = array(
197
+ 'HeadCleaner::.*' ,
198
  'noindex' ,
199
  'lambda_[\d]+' ,
200
  'rsd_link' ,
211
  /**********************************************************
212
  * Constructor
213
  ***********************************************************/
214
+ public function HeadCleaner() {
215
  $this->__construct();
216
  }
217
  public function __construct() {
538
  if (count($dom->find("link[rel='canonical']")) <= 0 && $this->options['canonical_tag'])
539
  $link_tag .= '<link rel="canonical" href="' . htmlspecialchars($url, ENT_QUOTES) . '" />'."\n";
540
 
541
+ $css_tag = ''; $css_tag_with_id = ''; $inner_css = ''; $css_src = array();
542
  $elements = $dom->find("link[rel='stylesheet']");
543
  foreach ((array) $elements as $element) {
544
  $tag = trim($element->outertext);
546
  if (strpos($element->href, $this->wp_url) === FALSE) {
547
  $css_tag .= trim($tag) . "\n";
548
  } elseif ( isset($element->id) && !empty($element->id) ) {
549
+ $css_tag_with_id .= trim($tag) . "\n";
550
  } else {
551
  $media = trim( isset($element->media) ? $element->media : $this->options['default_media'] );
552
  $media = ( empty($media) || is_null($media) || $media === FALSE ? $this->options['default_media'] : $media );
586
  $css_tag = trim($css_tag) . "\n";
587
  foreach ($css_src as $key => $val) {
588
  $inner_css = $this->_combined_css($val, trim(isset($wk_inline_css[$key]) ? $wk_inline_css[$key] : '' ), $key);
589
+ $css_tag .= trim($inner_css) . "\n" . trim($css_tag_with_id) . "\n";
590
  if (isset($wk_inline_css[$key])) $wk_inline_css[$key] = '';
591
  }
592
  foreach ($wk_inline_css as $key => $val) {
597
  }
598
  }
599
  } else {
600
+ $css_tag = trim($css_tag) . "\n" . trim($inner_css) . "\n" . trim($css_tag_with_id) . "\n";
601
  foreach ($wk_inline_css as $key => $val) {
602
  $val = trim($val);
603
  if (!empty($val)) {
607
  }
608
  }
609
  } else {
610
+ $css_tag = trim($css_tag) . "\n" . trim($inner_css) . "\n" . trim($css_tag_with_id) . "\n";
611
  foreach ($wk_inline_css as $key => $val) {
612
  $val = trim($val);
613
  if (!empty($val)) {
922
  $content = trim(isset($tags[$type][$name]) && isset($tags[$type][$name]['content'])
923
  ? $tags[$type][$name]['content']
924
  : '');
925
+ // $content = trim($content
926
+ // . (!empty($content) ? ', ' : '')
927
+ // . (isset($element->content) ? $element->content : '')
928
+ // );
929
+ $contents = ( !empty($content) ? explode( ',', $content ) : array() );
930
+ if ( isset($element->content) )
931
+ $contents = array_merge( $contents, explode(',', $element->content) );
932
+ $content = implode( ',', $contents );
933
+ unset( $contents );
934
+
935
+ $tags[$type][$name] = array(
936
+ 'name' => $name
937
+ ,'content' => $content
938
  );
939
+ } else {
940
+ $html .= $tag . "\n";
941
+ }
942
+ break;
943
+ case 'link':
944
+ if (isset($element->rel)) {
945
+ $name = strtolower($element->rel);
946
+ $content = (isset($tags[$type][$name]) && isset($tags[$type][$name]['content'])
947
+ ? $tags[$type][$name]['content']
948
+ : '');
949
+ $content .= $tag . "\n";
950
 
951
  $tags[$type][$name] = array(
952
  'name' => $name
965
  }
966
  unset($element); unset($elements);
967
 
968
+ foreach ((array) $tags as $tag_type => $contents) {
969
+ switch($tag_type) {
970
+ case 'meta':
971
+ ksort( $contents );
972
+ foreach ((array) $contents as $tag) {
973
+ $html .= "<$type";
974
+ foreach((array) $tag as $key => $val) {
975
+ $html .= " $key=\"$val\"";
976
+ }
977
+ $html .= " />\n";
978
+ }
979
+ unset($tag);
980
+ break;
981
+ case 'link':
982
+ default:
983
+ foreach ((array) $contents as $tag) {
984
+ $html .= $tag['content'];
985
  }
986
+ unset($tag);
987
+ break;
988
  }
 
989
  }
990
  unset($tags); unset($tag_types);
991
 
1000
  private function _abs_url($path, $base_path = ''){
1001
  if (preg_match('/^https?:\/\//i', $base_path))
1002
  $base_path = str_replace($this->wp_url, ABSPATH, $base_path);
1003
+
1004
  $absolute_path = realpath($base_path . '/' . $path);
1005
+ if ( $absolute_path === FALSE )
1006
+ $absolute_path = $base_path . '/' . $path;
1007
 
1008
  $url = str_replace(ABSPATH, $this->wp_url, $absolute_path);
1009
+ $url = str_replace('/./', '/', $url);
1010
+ $url = preg_replace('/(\/[^\/]*\/)\.\.(\/[^\/]*\/)/', '$2', $url);
1011
+
1012
  return $url;
1013
  }
1014
 
1034
  // Read file
1035
  //**************************************************************************************
1036
  private function _file_read($filename) {
1037
+ $content = false;
1038
  if (preg_match('/^https?:\/\//i', $filename)) {
1039
  $content = file_get_contents($filename);
1040
  } else {
1041
+ $filename = realpath($filename);
1042
+ if ($filename !== FALSE && file_exists($filename)) {
1043
  $handle = @fopen($filename, 'r');
1044
  $content = trim(@fread($handle, filesize($filename)));
1045
  @fclose($handle);
 
 
1046
  }
1047
  }
1048
 
1068
  // : '}finally{};');
1069
  break;
1070
  }
1071
+ // $text .= "/***** ".str_replace(ABSPATH, $this->wp_url,$filename)." *****/\n"
1072
+ // . $content . "\n\n";
1073
+ $text .= $content . "\n\n";
1074
  }
1075
  unset($filename);
1076
  $text = trim($text);
1437
  // Optimise CSS
1438
  //**************************************************************************************
1439
  private function _css_import($css) {
1440
+ if (preg_match_all('/@import[ \t]*url[ \t]*\([\'"]?([^\)\'"]*)[\'"]?\);?/i', $css, $matches, PREG_SET_ORDER)) {
1441
  $search = array(); $replace = array();
1442
  foreach ((array) $matches as $match) {
1443
  $filename = str_replace($this->wp_url, ABSPATH, trim($match[1]));
1444
+ $content = $this->_file_read(file_exists($filename) ? $filename : $match[1]);
1445
  $content = $this->_css_url_edit($content, $filename);
1446
+ if ($this->options['css_optimise'])
1447
+ $content = $this->_css_optimise($content, false);
1448
+ if (preg_match('/@import[ \t]*url[ \t]*\([\'"]?[^\)\'"]*[\'"]?\);?/i', $content))
1449
  $content = $this->_css_import($content);
1450
  $search[] = $match[0];
1451
  $replace[] = $content;
1454
  unset($match); unset($search); unset($replace);
1455
  }
1456
  unset($matches);
1457
+
1458
  return $css;
1459
  }
1460
 
1461
+ private function _css_optimise($buffer, $merge = true) {
1462
  $css = trim($buffer . "\n");
1463
 
1464
  if ($this->options['css_optimise']) {
 
 
1465
  $csstidy = new csstidy();
1466
  $csstidy->set_cfg('optimise_shorthands', $this->options['csstidy_option']['optimise_shorthands']);
1467
  $csstidy->set_cfg('compress_colors', $this->options['csstidy_option']['compress_colors']);
1472
  $css = $csstidy->print->plain();
1473
  unset($csstidy);
1474
  }
1475
+ if ( $merge )
1476
+ $css = str_replace("\n\n", "\n", $this->_css_import($css));
1477
  $css = trim($css);
1478
 
1479
  return $css . (!empty($css) ? "\n" : '');
2136
  ? $this->filters[$tag]
2137
  : array());
2138
  foreach ($active_filters as $function_name => $priority) {
2139
+ if (strpos($function_name, 'HeadCleaner') === FALSE && strpos($function_name, 'noindex') === FALSE)
2140
  $ret_val .= " ($priority) : $function_name\n";
2141
  }
2142
  $ret_val .= "**************************************************\n\n";
2159
 
2160
  global $head_cleaner;
2161
 
2162
+ $head_cleaner = new HeadCleaner();
2163
 
2164
  if (is_admin()) {
2165
  add_action('admin_menu', array(&$head_cleaner, 'admin_menu'));
2175
  add_action('wp_footer', array(&$head_cleaner, 'filters_save'), 11);
2176
 
2177
  }
2178
+ ?>
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: 2.9.2
7
- Stable tag: 1.3.6
8
 
9
  Cleaning tags from your WordPress header and footer.
10
 
@@ -88,6 +88,9 @@ Head Cleaner Ver.1.1.5 includes 'php_browscap.ini' .
88
 
89
  == Changelog ==
90
 
 
 
 
91
  **1.3.6 - February 15, 2010**
92
  Minor bug fixes.
93
 
@@ -108,7 +111,7 @@ In the inline CSS "@import", &lt;link rel=&quot;stylesheet&quot;&gt; was modifie
108
  Minor bug fixes.
109
 
110
  **1.3.0 - July 5, 2009**
111
- Google AJAX Libraries support
112
 
113
  **1.2.0 - April 5, 2009**
114
  Add an item to the Options page set.
4
  Tags: head, header, footer, javascript, css, optimization, minified, performance
5
  Requires at least: 2.5
6
  Tested up to: 2.9.2
7
+ Stable tag: 1.3.7
8
 
9
  Cleaning tags from your WordPress header and footer.
10
 
88
 
89
  == Changelog ==
90
 
91
+ **1.3.7 - April 15, 2010**
92
+ Fixed a bug, css @import interpreting the instructions.
93
+
94
  **1.3.6 - February 15, 2010**
95
  Minor bug fixes.
96
 
111
  Minor bug fixes.
112
 
113
  **1.3.0 - July 5, 2009**
114
+ Google AJAX Libraries support.
115
 
116
  **1.2.0 - April 5, 2009**
117
  Add an item to the Options page set.
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: 2.9.2
7
- Stable tag: 1.3.6
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: 2.9.2
7
+ Stable tag: 1.3.7
8
 
9
  Head �� footer �����|�����܂��B
10