Hyper Cache - Version 1.0.3

Version Description

Download this release

Release Info

Developer satollo
Plugin Icon wp plugin Hyper Cache
Version 1.0.3
Comparing to
See all releases

Version 1.0.3

Files changed (4) hide show
  1. advanced-cache.php +75 -0
  2. options.php +109 -0
  3. plugin.php +101 -0
  4. readme.txt +39 -0
advanced-cache.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ @include(dirname(__FILE__) . '/hyper-cache-config.php');
3
+
4
+ // From the config file
5
+ if (!$hyper_cache_enabled) return;
6
+
7
+ // Do not cache post request (comments, plugins and so on)
8
+ if ($_SERVER["REQUEST_METHOD"] == 'POST') return;
9
+
10
+ // Do not use or cache pages when a wordpress user is logged on
11
+ foreach ($_COOKIE as $n=>$v)
12
+ {
13
+ if (substr($n, 0, 13) == 'wordpressuser') return;
14
+ }
15
+
16
+ $hyper_uri = $_SERVER['REQUEST_URI'];
17
+
18
+ // Do not cache WP pages, even if those calls typically don't go throught this script
19
+ if (strpos($hyper_uri, '?') !== false) return;
20
+ if (strpos($hyper_uri, '/wp-admin/') !== false) return;
21
+ if (strpos($hyper_uri, '/wp-includes/') !== false) return;
22
+ if (strpos($hyper_uri, '/wp-content/') !== false) return;
23
+
24
+ // Special blocks: the download manager plugin
25
+ if (strpos($hyper_uri, '/download/') !== false) return;
26
+
27
+ // Remove the anchor
28
+ $x = strpos($hyper_uri, '#');
29
+ if ($x !== false) $hyper_uri = substr($hyper_uri, 0, $x);
30
+
31
+
32
+
33
+ $hyper_cache_name = md5($hyper_uri);
34
+ $hyper_file = ABSPATH . 'wp-content/hyper-cache/' . $hyper_cache_name . '.dat';
35
+
36
+ if (file_exists($hyper_file))
37
+ {
38
+ $hyper_data = unserialize(file_get_contents($hyper_file));
39
+ if ($hyper_cache_timeout == null) $hyper_cache_timeout = 60;
40
+ if ($hyper_data != null && ($hyper_data['time'] > time()-($hyper_cache_timeout*60)) && $hyper_data['html'] != '')
41
+ {
42
+ header('Content-Type: text/html;charset=UTF-8');
43
+ echo $hyper_data['html'];
44
+ //echo '<!-- -->';
45
+ flush();
46
+ die();
47
+ }
48
+ }
49
+
50
+ //var_dump($_COOKIE);
51
+ // Now we start the caching, but we remove the cookie which stores the comment for data
52
+ foreach ($_COOKIE as $n=>$v)
53
+ {
54
+ if (substr($n, 0, 14) == 'comment_author') unset($_COOKIE[$n]);
55
+ }
56
+ ob_start('hyper_cache_callback');
57
+
58
+
59
+ function hyper_cache_callback($buffer) {
60
+ global $hyper_file;
61
+ //$name = md5($_SERVER['REQUEST_URI']);
62
+
63
+ $data['uri'] = $_SERVER['REQUEST_URI'];
64
+ $data['referer'] = $_SERVER['HTTP_REFERER'];
65
+ $data['time'] = time();
66
+ $data['html'] = $buffer;
67
+
68
+ $file = fopen($hyper_file, 'w');
69
+ fwrite($file, serialize($data));
70
+ fclose($file);
71
+
72
+ return $buffer;
73
+ }
74
+
75
+ ?>
options.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if (function_exists('load_plugin_textdomain')) {
3
+ load_plugin_textdomain('hyper-cache', 'wp-content/plugins/hyper-cache');
4
+ }
5
+
6
+ function hyper_request($name, $default=null) {
7
+ if (!isset($_REQUEST[$name])) return $default;
8
+ if (get_magic_quotes_gpc()) return hyper_stripslashes($_REQUEST[$name]);
9
+ else return $_REQUEST[$name];
10
+ }
11
+
12
+ function hyper_stripslashes($value) {
13
+ $value = is_array($value) ? array_map('hyper_stripslashes', $value) : stripslashes($value);
14
+ return $value;
15
+ }
16
+
17
+ function hyper_field_checkbox($name, $label='', $tips='', $attrs='') {
18
+ global $options;
19
+ echo '<tr><td class="label">';
20
+ echo '<label for="options[' . $name . ']">' . $label . '</label></td>';
21
+ echo '<td><input type="checkbox" ' . $attrs . ' name="options[' . $name . ']" value="1" ' .
22
+ ($options[$name]!= null?'checked':'') . '/>';
23
+ echo ' ' . $tips;
24
+ echo '</td></tr>';
25
+ }
26
+
27
+ function hyper_field_text($name, $label='', $tips='', $attrs='') {
28
+ global $options;
29
+ if (strpos($attrs, 'size') === false) $attrs .= 'size="30"';
30
+ echo '<tr><td class="label">';
31
+ echo '<label for="options[' . $name . ']">' . $label . '</label></td>';
32
+ echo '<td><input type="text" ' . $attrs . ' name="options[' . $name . ']" value="' .
33
+ htmlspecialchars($options[$name]) . '"/>';
34
+ echo ' ' . $tips;
35
+ echo '</td></tr>';
36
+ }
37
+
38
+ function hyper_field_textarea($name, $label='', $tips='', $attrs='') {
39
+ global $options;
40
+
41
+ if (strpos($attrs, 'cols') === false) $attrs .= 'cols="70"';
42
+ if (strpos($attrs, 'rows') === false) $attrs .= 'rows="5"';
43
+
44
+ echo '<tr><td class="label">';
45
+ echo '<label for="options[' . $name . ']">' . $label . '</label></td>';
46
+ echo '<td><textarea wrap="off" ' . $attrs . ' name="options[' . $name . ']">' .
47
+ htmlspecialchars($options[$name]) . '</textarea>';
48
+ echo '<br /> ' . $tips;
49
+ echo '</td></tr>';
50
+ }
51
+
52
+ if (isset($_POST['save'])) {
53
+ $options = hyper_request('options');
54
+ update_option('hyper', $options);
55
+
56
+ // Write the configuration file
57
+
58
+ if (!file_exists(ABSPATH . '/wp-content/hyper-cache'))
59
+ {
60
+ mkdir(ABSPATH . '/wp-content/hyper-cache', 0766);
61
+ }
62
+
63
+ if (!$options['timeout'] || !is_numeric($options['timeout'])) $options['timeout'] = 60;
64
+ $buffer = "<?php\n";
65
+ $buffer .= '$hyper_cache_enabled = ' . ($options['cache']?'true':'false') . ";\n";
66
+ $buffer .= '$hyper_cache_timeout = ' . $options['timeout'] . ";\n";
67
+ $buffer .= '?>';
68
+ $file = fopen(ABSPATH . 'wp-content/hyper-cache-config.php', 'w');
69
+ fwrite($file, $buffer);
70
+ fclose($file);
71
+
72
+ // Write the advanced-cache.php (so we grant it's the correct version)
73
+ $buffer = file_get_contents(dirname(__FILE__) . '/advanced-cache.php');
74
+ $file = fopen(ABSPATH . 'wp-content/advanced-cache.php', 'w');
75
+ fwrite($file, $buffer);
76
+ fclose($file);
77
+ }
78
+ else
79
+ {
80
+ $options = get_option('hyper');
81
+ if (!$options['timeout']) $options['timeout'] = 60;
82
+ }
83
+ ?>
84
+ <style type="text/css">
85
+ td.label{width: 150px;vertical-align: top;font-weight: bold;text-align: right;}
86
+ td textarea {font-family: monospace;font-size: 11px;}
87
+ </style>
88
+ <div class="wrap">
89
+ <form method="post">
90
+ <h2><?php _e('Hyper Cache', 'hyper-cache'); ?></h2>
91
+ <?php
92
+ if (!defined('WP_CACHE')) {
93
+ $pre = __("<pre>define('WP_CACHE', true);</pre>", 'hyper-cache');
94
+ echo '<p>';
95
+ printf(__('The WordPress caching system is not enabled. Please add the line: %s in your wp-config.php file. Thank you.', 'hyper-cache'), $pre);
96
+ echo '</p>';
97
+ }
98
+ ?>
99
+
100
+ <h3><?php _e('Configuration', 'hyper-cache'); ?></h3>
101
+ <table>
102
+ <?php hyper_field_checkbox('cache', __('Cache active?', 'hyper-cache')); ?>
103
+ <?php hyper_field_text('timeout', __('Single page cached expire after', 'hyper-cache'), __('(minutes!)', 'hyper-cache')); ?>
104
+ </table>
105
+
106
+ <p>
107
+ <input class="button" type="submit" name="save" value="<?php _e('Save', 'hyper-cache'); ?>"></p>
108
+ </form>
109
+ </div>
plugin.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Hyper Cache
4
+ Plugin URI: http://www.satollo.com/english/wordpress/hyper-cache
5
+ Description: Hyper Cache is an extremely aggressive cache for WordPress.
6
+ Version: 1.0.3
7
+ Author: Satollo
8
+ Author URI: http://www.satollo.com
9
+ Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
10
+ */
11
+
12
+ /* Copyright 2008 Satollo (email : satollo@gmail.com)
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 2 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
+ */
28
+
29
+ $hyper_options = get_option('hyper');
30
+
31
+ /*
32
+ add_action('activate_hyper-cache/plugin.php', 'hyper_activate');
33
+ function hyper_activate() {
34
+ }
35
+ */
36
+
37
+ add_action('deactivate_hyper-cache/plugin.php', 'hyper_deactivate');
38
+ function hyper_deactivate() {
39
+ unlink(ABSPATH . 'wp-content/advanced-cache.php');
40
+ unlink(ABSPATH . 'wp-content/hyper-cache-config.php');
41
+
42
+ $path = ABSPATH . 'wp-content/' . time();
43
+ rename(ABSPATH . 'wp-content/hyper-cache', $path);
44
+
45
+ if ($handle = opendir($path))
46
+ {
47
+ while ($file = readdir($handle))
48
+ {
49
+ if ($file != '.' && $file != '..')
50
+ {
51
+ unlink($path . '/' . $file);
52
+ }
53
+ }
54
+ closedir($handle);
55
+ rmdir($path);
56
+ }
57
+ }
58
+
59
+ add_action('admin_head', 'hyper_admin_head');
60
+ function hyper_admin_head() {
61
+ add_options_page('Hyper Cache', 'Hyper Cache', 'manage_options', 'hyper-cache/options.php');
62
+ }
63
+
64
+ function hyper_cache_invalidate()
65
+ {
66
+ $path = ABSPATH . 'wp-content/' . time();
67
+ rename(ABSPATH . 'wp-content/hyper-cache', $path);
68
+ mkdir(ABSPATH . 'wp-content/hyper-cache', 0766);
69
+
70
+ if ($handle = opendir($path))
71
+ {
72
+ while ($file = readdir($handle))
73
+ {
74
+ if ($file != '.' && $file != '..')
75
+ {
76
+ unlink($path . '/' . $file);
77
+ }
78
+ }
79
+ closedir($handle);
80
+ rmdir($path);
81
+ }
82
+ }
83
+
84
+ if ($hyper_options['cache'])
85
+ {
86
+ add_action('publish_post', 'hyper_cache_invalidate', 0);
87
+ add_action('edit_post', 'hyper_cache_invalidate', 0);
88
+ add_action('delete_post', 'hyper_cache_invalidate', 0);
89
+ add_action('publish_phone', 'hyper_cache_invalidate', 0);
90
+ // Coment ID is received
91
+ add_action('trackback_post', 'hyper_cache_invalidate', 0);
92
+ add_action('pingback_post', 'hyper_cache_invalidate', 0);
93
+ add_action('comment_post', 'hyper_cache_invalidate', 0);
94
+ add_action('edit_comment', 'hyper_cache_invalidate', 0);
95
+ add_action('wp_set_comment_status', 'hyper_cache_invalidate', 0);
96
+ // No post_id is available
97
+ add_action('delete_comment', 'hyper_cache_invalidate', 0);
98
+ add_action('switch_theme', 'hyper_cache_invalidate', 0);
99
+ }
100
+
101
+ ?>
readme.txt ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Hyper Cache ===
2
+ Tags: cache,chaching
3
+ Requires at least: 2.1
4
+ Tested up to: 2.5
5
+ Stable tag: 1.0.3
6
+ Donate link: http://www.satollo.com/english/donate
7
+ Contributors: satollo,momo360modena
8
+
9
+ Hyper Cache is an extremely aggressive cache for WordPress.
10
+
11
+ == Description ==
12
+
13
+ Hyper Cache is an experimental really aggressive cache for WordPress. I wrote it because my hosting provider is very low in resources, particulary on the mysql side.
14
+
15
+ The cache tries to reduce the database queries to zero.
16
+
17
+ To install, please read carefully the instructions on:
18
+
19
+ http://www.satollo.com/english/wordpress/hyper-cache
20
+
21
+ For any problem or question write me: satollo@gmail.com or leave a comment
22
+ in my blog.
23
+
24
+ Thank you to Amaury Balmer for the internationalization and other
25
+ modifications.
26
+
27
+ == Installation ==
28
+
29
+ 1. Put the plugin folder into [wordpress_dir]/wp-content/plugins/
30
+ 2. Go into the WordPress admin interface and activate the plugin
31
+ 3. Optional: go to the options page and configure the plugin
32
+
33
+ == Frequently Asked Questions ==
34
+
35
+ No questions have been asked.
36
+
37
+ == Screenshots ==
38
+
39
+ No screenshots are available.