Version Description
- berarbeitung der GUI
- Source Code-Modularisierung
- Cache-Gre auf dem Dashboard
- Festplatte als Ablageort fr Cache
- Produktseite online: http://cachify.de
- Cache-Neuaufbau bei Kommentarstatusnderungen
- APC-Anforderungen: APC 3.0.0, empfohlen 3.1.4
- Optional: Kein Cache fr kommentierende Nutzer
- Schnellbersicht der Optionen als Inline-Hilfe
- Mindestanforderungen: WordPress 3.1 & PHP 5.1.2
Download this release
Release Info
Developer | sergej.mueller |
Plugin | Cachify |
Version | 2.0 |
Comparing to | |
See all releases |
Version 2.0
- apc/proxy.php +18 -0
- cachify.php +73 -0
- css/style.css +1 -0
- css/style.dev.css +93 -0
- img/icon.png +0 -0
- img/icon16.png +0 -0
- img/icon32.png +0 -0
- inc/cachify.class.php +1354 -0
- inc/cachify_apc.class.php +159 -0
- inc/cachify_db.class.php +236 -0
- inc/cachify_hdd.class.php +348 -0
- readme.txt +123 -0
- screenshot-1.png +0 -0
apc/proxy.php
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (
|
3 |
+
extension_loaded('apc')
|
4 |
+
&& ( !empty($_SERVER['PHP_SELF']) && strpos($_SERVER['PHP_SELF'], '/wp-admin/') === false )
|
5 |
+
&& ( !empty($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false )
|
6 |
+
&& ( $cache = apc_fetch(md5($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) . '.cachify') )
|
7 |
+
) {
|
8 |
+
ini_set('zlib.output_compression', 'Off');
|
9 |
+
|
10 |
+
header('Vary: Accept-Encoding');
|
11 |
+
header('X-Powered-By: Cachify');
|
12 |
+
header('Content-Encoding: gzip');
|
13 |
+
header('Content-Length: '.strlen($cache));
|
14 |
+
header('Content-Type: text/html; charset=utf-8');
|
15 |
+
|
16 |
+
echo $cache;
|
17 |
+
exit;
|
18 |
+
}
|
cachify.php
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Cachify
|
4 |
+
Description: Smarter Cache für WordPress. Reduziert die Ladezeit der Blogseiten, indem Inhalte in statischer Form abgelegt und ausgeliefert werden.
|
5 |
+
Author: Sergej Müller
|
6 |
+
Author URI: http://wpseo.de
|
7 |
+
Plugin URI: http://cachify.de
|
8 |
+
Version: 2.0
|
9 |
+
*/
|
10 |
+
|
11 |
+
|
12 |
+
/* Sicherheitsabfrage */
|
13 |
+
if ( !class_exists('WP') ) {
|
14 |
+
die();
|
15 |
+
}
|
16 |
+
|
17 |
+
|
18 |
+
/* Filter */
|
19 |
+
if ( ! ( (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) or (defined('DOING_CRON') && DOING_CRON) ) ) {
|
20 |
+
/* PHP-Check */
|
21 |
+
if ( ! function_exists('spl_autoload_register') ) {
|
22 |
+
wp_die('Cachify benötigt mindestens PHP 5.1.2');
|
23 |
+
}
|
24 |
+
|
25 |
+
/* Konstanten */
|
26 |
+
define('CACHIFY_FILE', __FILE__);
|
27 |
+
define('CACHIFY_BASE', plugin_basename(__FILE__));
|
28 |
+
define('CACHIFY_CACHE_DIR', WP_CONTENT_DIR . '/cache/cachify');
|
29 |
+
|
30 |
+
/* Autoload */
|
31 |
+
spl_autoload_register('cachify_autoload');
|
32 |
+
|
33 |
+
/* Init */
|
34 |
+
add_action(
|
35 |
+
'plugins_loaded',
|
36 |
+
array(
|
37 |
+
'Cachify',
|
38 |
+
'init'
|
39 |
+
)
|
40 |
+
);
|
41 |
+
|
42 |
+
/* Install */
|
43 |
+
register_activation_hook(
|
44 |
+
__FILE__,
|
45 |
+
array(
|
46 |
+
'Cachify',
|
47 |
+
'install'
|
48 |
+
)
|
49 |
+
);
|
50 |
+
|
51 |
+
/* Uninstall */
|
52 |
+
register_uninstall_hook(
|
53 |
+
__FILE__,
|
54 |
+
array(
|
55 |
+
'Cachify',
|
56 |
+
'uninstall'
|
57 |
+
)
|
58 |
+
);
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
/* Autoload */
|
63 |
+
function cachify_autoload($class) {
|
64 |
+
if ( in_array($class, array('Cachify', 'Cachify_APC', 'Cachify_DB', 'Cachify_HDD')) ) {
|
65 |
+
require_once(
|
66 |
+
sprintf(
|
67 |
+
'%s/inc/%s.class.php',
|
68 |
+
dirname(__FILE__),
|
69 |
+
strtolower($class)
|
70 |
+
)
|
71 |
+
);
|
72 |
+
}
|
73 |
+
}
|
css/style.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
#icon-cachify{background:url('../img/icon32.png') no-repeat;}#cachify_sidebar_icon{width:11px;height:9px;border:0;display:inline-block;background:url(../img/icon.png) no-repeat;}#wp-admin-bar-cachify .ab-icon{position:relative;float:left;width:16px;height:16px;margin-top:6px;background:url(../img/icon16.png) no-repeat 0 -1px;}#cachify_main .table{width:460px;height:1%;margin:20px 0 0;padding:0 0 5px;overflow:hidden;border:1px solid #dfdfdf;}#cachify_main .form-table{margin:0;}#cachify_main .form-table th{width:230px;vertical-align:middle;}#cachify_main .form-table th small{color:#8f8f8f;display:block;text-shadow:none;}#cachify_main .form-table caption{width:100%;color:#8f8f8f;margin:0 0 5px;background:whiteSmoke;line-height:20px;text-shadow:1px 1px #FFF;}#cachify_main .rounded{border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;}#cachify_main input,#cachify_main select{width:172px;}#cachify_main input.small{width:50px;}#cachify_main .submit{width:460px;height:1%;overflow:hidden;}#cachify_main .help{float:right;color:#bebebe;font-size:11px;text-align:right;line-height:11px;}
|
css/style.dev.css
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* @group Icon */
|
2 |
+
|
3 |
+
#icon-cachify {
|
4 |
+
background: url('../img/icon32.png') no-repeat;
|
5 |
+
}
|
6 |
+
|
7 |
+
/* @end group */
|
8 |
+
|
9 |
+
|
10 |
+
/* @group Sidebar */
|
11 |
+
|
12 |
+
#cachify_sidebar_icon {
|
13 |
+
width: 11px;
|
14 |
+
height: 9px;
|
15 |
+
border: 0;
|
16 |
+
display: inline-block;
|
17 |
+
background: url(../img/icon.png) no-repeat;
|
18 |
+
}
|
19 |
+
|
20 |
+
/* @end group */
|
21 |
+
|
22 |
+
|
23 |
+
/* @group Adminbar */
|
24 |
+
|
25 |
+
#wp-admin-bar-cachify .ab-icon {
|
26 |
+
position: relative;
|
27 |
+
float: left;
|
28 |
+
width: 16px;
|
29 |
+
height: 16px;
|
30 |
+
margin-top: 6px;
|
31 |
+
background: url(../img/icon16.png) no-repeat 0 -1px;
|
32 |
+
}
|
33 |
+
|
34 |
+
/* @end group */
|
35 |
+
|
36 |
+
|
37 |
+
/* @group GUI */
|
38 |
+
|
39 |
+
#cachify_main .table {
|
40 |
+
width: 460px;
|
41 |
+
height: 1%;
|
42 |
+
margin: 20px 0 0;
|
43 |
+
padding: 0 0 5px;
|
44 |
+
overflow: hidden;
|
45 |
+
border: 1px solid #DFDFDF;
|
46 |
+
}
|
47 |
+
#cachify_main .form-table {
|
48 |
+
margin: 0;
|
49 |
+
}
|
50 |
+
#cachify_main .form-table th {
|
51 |
+
width: 230px;
|
52 |
+
vertical-align: middle;
|
53 |
+
}
|
54 |
+
#cachify_main .form-table th small {
|
55 |
+
color: #8F8F8F;
|
56 |
+
display: block;
|
57 |
+
text-shadow: none;
|
58 |
+
}
|
59 |
+
#cachify_main .form-table caption {
|
60 |
+
width: 100%;
|
61 |
+
color: #8F8F8F;
|
62 |
+
margin: 0 0 5px;
|
63 |
+
background: whiteSmoke;
|
64 |
+
line-height: 20px;
|
65 |
+
text-shadow: 1px 1px #FFF;
|
66 |
+
}
|
67 |
+
#cachify_main .rounded {
|
68 |
+
border-radius: 3px;
|
69 |
+
-moz-border-radius: 3px;
|
70 |
+
-webkit-border-radius: 3px;
|
71 |
+
}
|
72 |
+
|
73 |
+
#cachify_main input,
|
74 |
+
#cachify_main select {
|
75 |
+
width: 172px;
|
76 |
+
}
|
77 |
+
#cachify_main input.small {
|
78 |
+
width: 50px;
|
79 |
+
}
|
80 |
+
#cachify_main .submit {
|
81 |
+
width: 460px;
|
82 |
+
height: 1%;
|
83 |
+
overflow: hidden;
|
84 |
+
}
|
85 |
+
#cachify_main .help {
|
86 |
+
float: right;
|
87 |
+
color: #bebebe;
|
88 |
+
font-size: 11px;
|
89 |
+
text-align: right;
|
90 |
+
line-height: 11px;
|
91 |
+
}
|
92 |
+
|
93 |
+
/* @end group */
|
img/icon.png
ADDED
Binary file
|
img/icon16.png
ADDED
Binary file
|
img/icon32.png
ADDED
Binary file
|
inc/cachify.class.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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Cachify
|
6 |
+
*/
|
7 |
+
|
8 |
+
final class Cachify {
|
9 |
+
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Plugin-Optionen
|
13 |
+
*
|
14 |
+
* @since 2.0
|
15 |
+
* @var array
|
16 |
+
*/
|
17 |
+
|
18 |
+
private static $options;
|
19 |
+
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Cache-Methode
|
23 |
+
*
|
24 |
+
* @since 2.0
|
25 |
+
* @var object
|
26 |
+
*/
|
27 |
+
|
28 |
+
private static $method;
|
29 |
+
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Initialisierung des Plugins
|
33 |
+
*
|
34 |
+
* @since 1.0
|
35 |
+
* @change 2.0
|
36 |
+
*/
|
37 |
+
|
38 |
+
public static function init()
|
39 |
+
{
|
40 |
+
/* Variablen */
|
41 |
+
self::_set_vars();
|
42 |
+
|
43 |
+
/* Publish post */
|
44 |
+
add_action(
|
45 |
+
'publish_post',
|
46 |
+
array(
|
47 |
+
__CLASS__,
|
48 |
+
'publish_post'
|
49 |
+
)
|
50 |
+
);
|
51 |
+
|
52 |
+
/* Publish page */
|
53 |
+
add_action(
|
54 |
+
'publish_page',
|
55 |
+
array(
|
56 |
+
__CLASS__,
|
57 |
+
'publish_page'
|
58 |
+
)
|
59 |
+
);
|
60 |
+
|
61 |
+
/* Backend */
|
62 |
+
if ( is_admin() ) {
|
63 |
+
add_action(
|
64 |
+
'wpmu_new_blog',
|
65 |
+
array(
|
66 |
+
__CLASS__,
|
67 |
+
'install_later'
|
68 |
+
)
|
69 |
+
);
|
70 |
+
add_action(
|
71 |
+
'delete_blog',
|
72 |
+
array(
|
73 |
+
__CLASS__,
|
74 |
+
'uninstall_later'
|
75 |
+
)
|
76 |
+
);
|
77 |
+
|
78 |
+
add_action(
|
79 |
+
'admin_init',
|
80 |
+
array(
|
81 |
+
__CLASS__,
|
82 |
+
'register_settings'
|
83 |
+
)
|
84 |
+
);
|
85 |
+
add_action(
|
86 |
+
'admin_init',
|
87 |
+
array(
|
88 |
+
__CLASS__,
|
89 |
+
'receive_flush'
|
90 |
+
)
|
91 |
+
);
|
92 |
+
add_action(
|
93 |
+
'admin_menu',
|
94 |
+
array(
|
95 |
+
__CLASS__,
|
96 |
+
'add_page'
|
97 |
+
)
|
98 |
+
);
|
99 |
+
add_action(
|
100 |
+
'admin_print_styles',
|
101 |
+
array(
|
102 |
+
__CLASS__,
|
103 |
+
'add_css'
|
104 |
+
)
|
105 |
+
);
|
106 |
+
|
107 |
+
add_action(
|
108 |
+
'transition_comment_status',
|
109 |
+
array(
|
110 |
+
__CLASS__,
|
111 |
+
'touch_comment'
|
112 |
+
),
|
113 |
+
10,
|
114 |
+
3
|
115 |
+
);
|
116 |
+
add_action(
|
117 |
+
'edit_comment',
|
118 |
+
array(
|
119 |
+
__CLASS__,
|
120 |
+
'edit_comment'
|
121 |
+
)
|
122 |
+
);
|
123 |
+
add_action(
|
124 |
+
'admin_bar_menu',
|
125 |
+
array(
|
126 |
+
__CLASS__,
|
127 |
+
'add_menu'
|
128 |
+
),
|
129 |
+
90
|
130 |
+
);
|
131 |
+
add_action(
|
132 |
+
'right_now_table_end',
|
133 |
+
array(
|
134 |
+
__CLASS__,
|
135 |
+
'add_count'
|
136 |
+
)
|
137 |
+
);
|
138 |
+
|
139 |
+
add_filter(
|
140 |
+
'plugin_row_meta',
|
141 |
+
array(
|
142 |
+
__CLASS__,
|
143 |
+
'row_meta'
|
144 |
+
),
|
145 |
+
10,
|
146 |
+
2
|
147 |
+
);
|
148 |
+
add_filter(
|
149 |
+
'plugin_action_links_' .CACHIFY_BASE,
|
150 |
+
array(
|
151 |
+
__CLASS__,
|
152 |
+
'action_links'
|
153 |
+
)
|
154 |
+
);
|
155 |
+
|
156 |
+
/* Frontend */
|
157 |
+
} else {
|
158 |
+
add_action(
|
159 |
+
'preprocess_comment',
|
160 |
+
array(
|
161 |
+
__CLASS__,
|
162 |
+
'add_comment'
|
163 |
+
),
|
164 |
+
1
|
165 |
+
);
|
166 |
+
add_action(
|
167 |
+
'template_redirect',
|
168 |
+
array(
|
169 |
+
__CLASS__,
|
170 |
+
'manage_cache'
|
171 |
+
),
|
172 |
+
0
|
173 |
+
);
|
174 |
+
}
|
175 |
+
}
|
176 |
+
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Plugin-Installation für MU-Blogs
|
180 |
+
*
|
181 |
+
* @since 1.0
|
182 |
+
* @change 1.0
|
183 |
+
*/
|
184 |
+
|
185 |
+
public static function install()
|
186 |
+
{
|
187 |
+
/* Multisite & Network */
|
188 |
+
if ( is_multisite() && !empty($_GET['networkwide']) ) {
|
189 |
+
/* Blog-IDs */
|
190 |
+
$ids = self::_get_blog_ids();
|
191 |
+
|
192 |
+
/* Loopen */
|
193 |
+
foreach ($ids as $id) {
|
194 |
+
switch_to_blog( (int)$id );
|
195 |
+
self::_install_backend();
|
196 |
+
}
|
197 |
+
|
198 |
+
/* Wechsel zurück */
|
199 |
+
restore_current_blog();
|
200 |
+
|
201 |
+
} else {
|
202 |
+
self::_install_backend();
|
203 |
+
}
|
204 |
+
}
|
205 |
+
|
206 |
+
|
207 |
+
/**
|
208 |
+
* Plugin-Installation bei neuen MU-Blogs
|
209 |
+
*
|
210 |
+
* @since 1.0
|
211 |
+
* @change 1.0
|
212 |
+
*/
|
213 |
+
|
214 |
+
public static function install_later($id) {
|
215 |
+
/* Kein Netzwerk-Plugin */
|
216 |
+
if ( !is_plugin_active_for_network(CACHIFY_BASE) ) {
|
217 |
+
return;
|
218 |
+
}
|
219 |
+
|
220 |
+
/* Wechsel */
|
221 |
+
switch_to_blog( (int)$id );
|
222 |
+
|
223 |
+
/* Installieren */
|
224 |
+
self::_install_backend();
|
225 |
+
|
226 |
+
/* Wechsel zurück */
|
227 |
+
restore_current_blog();
|
228 |
+
}
|
229 |
+
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Eigentliche Installation der Optionen
|
233 |
+
*
|
234 |
+
* @since 1.0
|
235 |
+
* @change 2.0
|
236 |
+
*/
|
237 |
+
|
238 |
+
private static function _install_backend()
|
239 |
+
{
|
240 |
+
add_option(
|
241 |
+
'cachify',
|
242 |
+
array()
|
243 |
+
);
|
244 |
+
|
245 |
+
/* Flush */
|
246 |
+
self::flush_cache();
|
247 |
+
}
|
248 |
+
|
249 |
+
|
250 |
+
/**
|
251 |
+
* Deinstallation des Plugins pro MU-Blog
|
252 |
+
*
|
253 |
+
* @since 1.0
|
254 |
+
* @change 1.0
|
255 |
+
*/
|
256 |
+
|
257 |
+
public static function uninstall()
|
258 |
+
{
|
259 |
+
/* Global */
|
260 |
+
global $wpdb;
|
261 |
+
|
262 |
+
/* Multisite & Network */
|
263 |
+
if ( is_multisite() && !empty($_GET['networkwide']) ) {
|
264 |
+
/* Alter Blog */
|
265 |
+
$old = $wpdb->blogid;
|
266 |
+
|
267 |
+
/* Blog-IDs */
|
268 |
+
$ids = self::_get_blog_ids();
|
269 |
+
|
270 |
+
/* Loopen */
|
271 |
+
foreach ($ids as $id) {
|
272 |
+
switch_to_blog($id);
|
273 |
+
self::_uninstall_backend();
|
274 |
+
}
|
275 |
+
|
276 |
+
/* Wechsel zurück */
|
277 |
+
switch_to_blog($old);
|
278 |
+
} else {
|
279 |
+
self::_uninstall_backend();
|
280 |
+
}
|
281 |
+
}
|
282 |
+
|
283 |
+
|
284 |
+
/**
|
285 |
+
* Deinstallation des Plugins bei MU & Network
|
286 |
+
*
|
287 |
+
* @since 1.0
|
288 |
+
* @change 1.0
|
289 |
+
*/
|
290 |
+
|
291 |
+
public static function uninstall_later($id)
|
292 |
+
{
|
293 |
+
/* Kein Netzwerk-Plugin */
|
294 |
+
if ( !is_plugin_active_for_network(CACHIFY_BASE) ) {
|
295 |
+
return;
|
296 |
+
}
|
297 |
+
|
298 |
+
/* Wechsel */
|
299 |
+
switch_to_blog( (int)$id );
|
300 |
+
|
301 |
+
/* Installieren */
|
302 |
+
self::_uninstall_backend();
|
303 |
+
|
304 |
+
/* Wechsel zurück */
|
305 |
+
restore_current_blog();
|
306 |
+
}
|
307 |
+
|
308 |
+
|
309 |
+
/**
|
310 |
+
* Eigentliche Deinstallation des Plugins
|
311 |
+
*
|
312 |
+
* @since 1.0
|
313 |
+
* @change 1.0
|
314 |
+
*/
|
315 |
+
|
316 |
+
private static function _uninstall_backend()
|
317 |
+
{
|
318 |
+
/* Option */
|
319 |
+
delete_option('cachify');
|
320 |
+
|
321 |
+
/* Cache leeren */
|
322 |
+
self::flush_cache();
|
323 |
+
}
|
324 |
+
|
325 |
+
|
326 |
+
/**
|
327 |
+
* Rückgabe der IDs installierter Blogs
|
328 |
+
*
|
329 |
+
* @since 1.0
|
330 |
+
* @change 1.0
|
331 |
+
*
|
332 |
+
* @return array Blog-IDs
|
333 |
+
*/
|
334 |
+
|
335 |
+
private static function _get_blog_ids()
|
336 |
+
{
|
337 |
+
/* Global */
|
338 |
+
global $wpdb;
|
339 |
+
|
340 |
+
return $wpdb->get_col(
|
341 |
+
$wpdb->prepare("SELECT blog_id FROM `$wpdb->blogs`")
|
342 |
+
);
|
343 |
+
}
|
344 |
+
|
345 |
+
|
346 |
+
/**
|
347 |
+
* Eigenschaften des Objekts
|
348 |
+
*
|
349 |
+
* @since 2.0
|
350 |
+
* @change 2.0
|
351 |
+
*/
|
352 |
+
|
353 |
+
private static function _set_vars()
|
354 |
+
{
|
355 |
+
/* Optionen */
|
356 |
+
self::$options = self::_get_options();
|
357 |
+
|
358 |
+
/* Methode */
|
359 |
+
if ( self::$options['use_apc'] === 1 && extension_loaded('apc') ) {
|
360 |
+
self::$method = new Cachify_APC;
|
361 |
+
} else if ( self::$options['use_apc'] === 2 ) {
|
362 |
+
self::$method = new Cachify_HDD;
|
363 |
+
} else {
|
364 |
+
self::$method = new Cachify_DB;
|
365 |
+
}
|
366 |
+
}
|
367 |
+
|
368 |
+
|
369 |
+
/**
|
370 |
+
* Rückgabe der Optionen
|
371 |
+
*
|
372 |
+
* @since 2.0
|
373 |
+
* @change 2.0
|
374 |
+
*
|
375 |
+
* @return array $diff Array mit Werten
|
376 |
+
*/
|
377 |
+
|
378 |
+
private static function _get_options()
|
379 |
+
{
|
380 |
+
return wp_parse_args(
|
381 |
+
get_option('cachify'),
|
382 |
+
array(
|
383 |
+
'only_guests' => 1,
|
384 |
+
'compress_html' => 0,
|
385 |
+
'cache_expires' => 12,
|
386 |
+
'without_ids' => '',
|
387 |
+
'without_agents' => '',
|
388 |
+
'use_apc' => 0
|
389 |
+
)
|
390 |
+
);
|
391 |
+
}
|
392 |
+
|
393 |
+
|
394 |
+
/**
|
395 |
+
* Hinzufügen der Action-Links
|
396 |
+
*
|
397 |
+
* @since 1.0
|
398 |
+
* @change 1.0
|
399 |
+
*
|
400 |
+
* @param array $data Bereits existente Links
|
401 |
+
* @return array $data Erweitertes Array mit Links
|
402 |
+
*/
|
403 |
+
|
404 |
+
public static function action_links($data)
|
405 |
+
{
|
406 |
+
/* Rechte? */
|
407 |
+
if ( !current_user_can('manage_options') ) {
|
408 |
+
return $data;
|
409 |
+
}
|
410 |
+
|
411 |
+
return array_merge(
|
412 |
+
$data,
|
413 |
+
array(
|
414 |
+
sprintf(
|
415 |
+
'<a href="%s">%s</a>',
|
416 |
+
add_query_arg(
|
417 |
+
array(
|
418 |
+
'page' => 'cachify'
|
419 |
+
),
|
420 |
+
admin_url('options-general.php')
|
421 |
+
),
|
422 |
+
__('Settings')
|
423 |
+
)
|
424 |
+
)
|
425 |
+
);
|
426 |
+
}
|
427 |
+
|
428 |
+
|
429 |
+
/**
|
430 |
+
* Meta-Links des Plugins
|
431 |
+
*
|
432 |
+
* @since 0.5
|
433 |
+
* @change 1.3
|
434 |
+
*
|
435 |
+
* @param array $data Bereits vorhandene Links
|
436 |
+
* @param string $page Aktuelle Seite
|
437 |
+
* @return array $data Modifizierte Links
|
438 |
+
*/
|
439 |
+
|
440 |
+
public static function row_meta($data, $page)
|
441 |
+
{
|
442 |
+
/* Rechte */
|
443 |
+
if ( $page != CACHIFY_BASE ) {
|
444 |
+
return $data;
|
445 |
+
}
|
446 |
+
|
447 |
+
return array_merge(
|
448 |
+
$data,
|
449 |
+
array(
|
450 |
+
'<a href="http://flattr.com/profile/sergej.mueller" target="_blank">Plugin flattern</a>',
|
451 |
+
'<a href="https://plus.google.com/110569673423509816572" target="_blank">Auf Google+ folgen</a>'
|
452 |
+
)
|
453 |
+
);
|
454 |
+
}
|
455 |
+
|
456 |
+
|
457 |
+
/**
|
458 |
+
* Hinzufügen eines Admin-Bar-Menüs
|
459 |
+
*
|
460 |
+
* @since 1.2
|
461 |
+
* @change 1.2.1
|
462 |
+
*
|
463 |
+
* @param object Objekt mit Menü-Eigenschaften
|
464 |
+
*/
|
465 |
+
|
466 |
+
public static function add_menu($wp_admin_bar)
|
467 |
+
{
|
468 |
+
/* Aussteigen */
|
469 |
+
if ( !is_admin_bar_showing() or !is_super_admin() ) {
|
470 |
+
return;
|
471 |
+
}
|
472 |
+
|
473 |
+
/* Hinzufügen */
|
474 |
+
$wp_admin_bar->add_menu(
|
475 |
+
array(
|
476 |
+
'id' => 'cachify',
|
477 |
+
'title' => '<span class="ab-icon" title="Cache leeren"></span>',
|
478 |
+
'href' => add_query_arg('_cachify', 'flush'),
|
479 |
+
'parent' => 'top-secondary'
|
480 |
+
)
|
481 |
+
);
|
482 |
+
}
|
483 |
+
|
484 |
+
|
485 |
+
/**
|
486 |
+
* Anzeige des Spam-Counters auf dem Dashboard
|
487 |
+
*
|
488 |
+
* @since 2.0
|
489 |
+
* @change 2.0
|
490 |
+
*/
|
491 |
+
|
492 |
+
public static function add_count()
|
493 |
+
{
|
494 |
+
/* Größe */
|
495 |
+
if ( !$size = get_transient('cachify_cache_size') ) {
|
496 |
+
/* Auslesen */
|
497 |
+
$size = (int) call_user_func(
|
498 |
+
array(
|
499 |
+
self::$method,
|
500 |
+
'get_stats'
|
501 |
+
)
|
502 |
+
);
|
503 |
+
|
504 |
+
/* Speichern */
|
505 |
+
set_transient(
|
506 |
+
'cachify_cache_size',
|
507 |
+
$size,
|
508 |
+
60 * 15
|
509 |
+
);
|
510 |
+
}
|
511 |
+
|
512 |
+
/* Ausgabe */
|
513 |
+
echo sprintf(
|
514 |
+
'<tr>
|
515 |
+
<td class="b b-spam" style="font-size:18px">%s</td>
|
516 |
+
<td class="last t">Cache</td>
|
517 |
+
</tr>',
|
518 |
+
( $size ? size_format($size) : 0 )
|
519 |
+
);
|
520 |
+
}
|
521 |
+
|
522 |
+
|
523 |
+
/**
|
524 |
+
* Verarbeitung der Plugin-Meta-Aktionen
|
525 |
+
*
|
526 |
+
* @since 0.5
|
527 |
+
* @change 1.2
|
528 |
+
*
|
529 |
+
* @param array $data Metadaten der Plugins
|
530 |
+
*/
|
531 |
+
|
532 |
+
public static function receive_flush($data)
|
533 |
+
{
|
534 |
+
/* Leer? */
|
535 |
+
if ( empty($_GET['_cachify']) or $_GET['_cachify'] !== 'flush' ) {
|
536 |
+
return;
|
537 |
+
}
|
538 |
+
|
539 |
+
/* Global */
|
540 |
+
global $wpdb;
|
541 |
+
|
542 |
+
/* Multisite & Network */
|
543 |
+
if ( is_multisite() && is_plugin_active_for_network(CACHIFY_BASE) ) {
|
544 |
+
/* Alter Blog */
|
545 |
+
$old = $wpdb->blogid;
|
546 |
+
|
547 |
+
/* Blog-IDs */
|
548 |
+
$ids = self::_get_blog_ids();
|
549 |
+
|
550 |
+
/* Loopen */
|
551 |
+
foreach ($ids as $id) {
|
552 |
+
switch_to_blog($id);
|
553 |
+
self::flush_cache();
|
554 |
+
}
|
555 |
+
|
556 |
+
/* Wechsel zurück */
|
557 |
+
switch_to_blog($old);
|
558 |
+
|
559 |
+
/* Notiz */
|
560 |
+
add_action(
|
561 |
+
'network_admin_notices',
|
562 |
+
array(
|
563 |
+
__CLASS__,
|
564 |
+
'flush_notice'
|
565 |
+
)
|
566 |
+
);
|
567 |
+
} else {
|
568 |
+
/* Leeren */
|
569 |
+
self::flush_cache();
|
570 |
+
|
571 |
+
/* Notiz */
|
572 |
+
add_action(
|
573 |
+
'admin_notices',
|
574 |
+
array(
|
575 |
+
__CLASS__,
|
576 |
+
'flush_notice'
|
577 |
+
)
|
578 |
+
);
|
579 |
+
}
|
580 |
+
}
|
581 |
+
|
582 |
+
|
583 |
+
/**
|
584 |
+
* Hinweis nach erfolgreichem Cache-Leeren
|
585 |
+
*
|
586 |
+
* @since 1.2
|
587 |
+
* @change 1.2
|
588 |
+
*/
|
589 |
+
|
590 |
+
public static function flush_notice()
|
591 |
+
{
|
592 |
+
/* Kein Admin */
|
593 |
+
if ( !is_super_admin() ) {
|
594 |
+
return false;
|
595 |
+
}
|
596 |
+
|
597 |
+
echo '<div id="message" class="updated"><p><strong>Cachify-Cache geleert.</strong></p></div>';
|
598 |
+
}
|
599 |
+
|
600 |
+
|
601 |
+
/**
|
602 |
+
* Löschung des Cache beim Kommentar-Editieren
|
603 |
+
*
|
604 |
+
* @since 0.1
|
605 |
+
* @change 0.4
|
606 |
+
*
|
607 |
+
* @param integer $id ID des Kommentars
|
608 |
+
*/
|
609 |
+
|
610 |
+
public static function edit_comment($id)
|
611 |
+
{
|
612 |
+
self::_delete_cache(
|
613 |
+
get_permalink(
|
614 |
+
get_comment($id)->comment_post_ID
|
615 |
+
)
|
616 |
+
);
|
617 |
+
}
|
618 |
+
|
619 |
+
|
620 |
+
/**
|
621 |
+
* Löschung des Cache beim neuen Kommentar
|
622 |
+
*
|
623 |
+
* @since 0.1
|
624 |
+
* @change 0.1
|
625 |
+
*
|
626 |
+
* @param array $comment Array mit Eigenschaften
|
627 |
+
* @return array $comment Array mit Eigenschaften
|
628 |
+
*/
|
629 |
+
|
630 |
+
public static function add_comment($comment)
|
631 |
+
{
|
632 |
+
self::_delete_cache(
|
633 |
+
get_permalink($comment['comment_post_ID'])
|
634 |
+
);
|
635 |
+
|
636 |
+
return $comment;
|
637 |
+
}
|
638 |
+
|
639 |
+
|
640 |
+
/**
|
641 |
+
* Löschung des Cache beim Editieren der Kommentare
|
642 |
+
*
|
643 |
+
* @since 0.1
|
644 |
+
* @change 0.4
|
645 |
+
*
|
646 |
+
* @param string $new_status Neuer Status
|
647 |
+
* @param string $old_status Alter Status
|
648 |
+
* @param object $comment Array mit Eigenschaften
|
649 |
+
*/
|
650 |
+
|
651 |
+
public static function touch_comment($new_status, $old_status, $comment)
|
652 |
+
{
|
653 |
+
if ( $new_status != $old_status ) {
|
654 |
+
self::_delete_cache(
|
655 |
+
get_permalink($comment->comment_post_ID)
|
656 |
+
);
|
657 |
+
}
|
658 |
+
}
|
659 |
+
|
660 |
+
|
661 |
+
/**
|
662 |
+
* Leerung des Cache bei neuen Beiträgen
|
663 |
+
*
|
664 |
+
* @since 0.1
|
665 |
+
* @change 0.9.1
|
666 |
+
*
|
667 |
+
* @param intval $id ID des Beitrags
|
668 |
+
*/
|
669 |
+
|
670 |
+
public static function publish_post($id)
|
671 |
+
{
|
672 |
+
/* Post */
|
673 |
+
$post = get_post($id);
|
674 |
+
|
675 |
+
/* Löschen */
|
676 |
+
if ( in_array( $post->post_status, array('publish', 'future') ) ) {
|
677 |
+
self::flush_cache();
|
678 |
+
}
|
679 |
+
}
|
680 |
+
|
681 |
+
|
682 |
+
/**
|
683 |
+
* Leerung des Cache bei neuen Beiträgen
|
684 |
+
*
|
685 |
+
* @since 1.0
|
686 |
+
* @change 1.0
|
687 |
+
*
|
688 |
+
* @param intval $id ID des Beitrags
|
689 |
+
*/
|
690 |
+
|
691 |
+
public static function publish_page($id)
|
692 |
+
{
|
693 |
+
/* Page */
|
694 |
+
$page = get_page($id);
|
695 |
+
|
696 |
+
/* Löschen */
|
697 |
+
if ( $page->post_status == 'publish' ) {
|
698 |
+
self::flush_cache();
|
699 |
+
}
|
700 |
+
}
|
701 |
+
|
702 |
+
|
703 |
+
/**
|
704 |
+
* Rückgabe der Cache-Gültigkeit
|
705 |
+
*
|
706 |
+
* @since 2.0
|
707 |
+
* @change 2.0
|
708 |
+
*
|
709 |
+
* @return intval Gültigkeit in Sekunden
|
710 |
+
*/
|
711 |
+
|
712 |
+
private static function _cache_expires()
|
713 |
+
{
|
714 |
+
return 60 * 60 * self::$options['cache_expires'];
|
715 |
+
}
|
716 |
+
|
717 |
+
|
718 |
+
/**
|
719 |
+
* Rückgabe des Cache-Hash-Wertes
|
720 |
+
*
|
721 |
+
* @since 0.1
|
722 |
+
* @change 2.0
|
723 |
+
*
|
724 |
+
* @param string $url URL für den Hash-Wert [optional]
|
725 |
+
* @return string Cachify-Hash-Wert
|
726 |
+
*/
|
727 |
+
|
728 |
+
private static function _cache_hash($url = '')
|
729 |
+
{
|
730 |
+
return md5(
|
731 |
+
empty($url) ? ( $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) : ( parse_url($url, PHP_URL_HOST) . parse_url($url, PHP_URL_PATH) )
|
732 |
+
) . '.cachify';
|
733 |
+
}
|
734 |
+
|
735 |
+
|
736 |
+
/**
|
737 |
+
* Splittung nach Komma
|
738 |
+
*
|
739 |
+
* @since 0.9.1
|
740 |
+
* @change 1.0
|
741 |
+
*
|
742 |
+
* @param string $input Zu splittende Zeichenkette
|
743 |
+
* @return array Konvertierter Array
|
744 |
+
*/
|
745 |
+
|
746 |
+
private static function _preg_split($input)
|
747 |
+
{
|
748 |
+
return (array)preg_split('/,/', $input, -1, PREG_SPLIT_NO_EMPTY);
|
749 |
+
}
|
750 |
+
|
751 |
+
|
752 |
+
/**
|
753 |
+
* Prüfung der WordPress-Version
|
754 |
+
*
|
755 |
+
* @since 2.0
|
756 |
+
* @change 2.0
|
757 |
+
*
|
758 |
+
* @param integer $version Gesuchte WP-Version
|
759 |
+
* @return boolean TRUE, wenn mindestens gesuchte
|
760 |
+
*/
|
761 |
+
|
762 |
+
private static function _is_wp($version) {
|
763 |
+
return version_compare(
|
764 |
+
$GLOBALS['wp_version'],
|
765 |
+
$version. 'alpha',
|
766 |
+
'>='
|
767 |
+
);
|
768 |
+
}
|
769 |
+
|
770 |
+
|
771 |
+
/**
|
772 |
+
* Prüfung auf Index
|
773 |
+
*
|
774 |
+
* @since 0.6
|
775 |
+
* @change 1.0
|
776 |
+
*
|
777 |
+
* @return boolean TRUE bei Index
|
778 |
+
*/
|
779 |
+
|
780 |
+
private static function _is_index()
|
781 |
+
{
|
782 |
+
return basename($_SERVER['SCRIPT_NAME']) != 'index.php';
|
783 |
+
}
|
784 |
+
|
785 |
+
|
786 |
+
/**
|
787 |
+
* Prüfung auf Mobile Devices
|
788 |
+
*
|
789 |
+
* @since 0.9.1
|
790 |
+
* @change 1.0
|
791 |
+
*
|
792 |
+
* @return boolean TRUE bei Mobile
|
793 |
+
*/
|
794 |
+
|
795 |
+
private static function _is_mobile()
|
796 |
+
{
|
797 |
+
return ( strpos(TEMPLATEPATH, 'wptouch') or strpos(TEMPLATEPATH, 'carrington') );
|
798 |
+
}
|
799 |
+
|
800 |
+
|
801 |
+
/**
|
802 |
+
* Prüfung auf eingeloggte und kommentierte Nutzer
|
803 |
+
*
|
804 |
+
* @since 2.0
|
805 |
+
* @change 2.0
|
806 |
+
*
|
807 |
+
* @return boolean $diff TRUE bei "vermerkten" Nutzern
|
808 |
+
*/
|
809 |
+
|
810 |
+
private static function _is_logged_in()
|
811 |
+
{
|
812 |
+
/* Eingeloggt */
|
813 |
+
if ( is_user_logged_in() ) {
|
814 |
+
return true;
|
815 |
+
}
|
816 |
+
|
817 |
+
/* Cookie? */
|
818 |
+
if ( empty($_COOKIE) ) {
|
819 |
+
return false;
|
820 |
+
}
|
821 |
+
|
822 |
+
/* Loopen */
|
823 |
+
foreach ( $_COOKIE as $k => $v) {
|
824 |
+
if ( preg_match('/^(wp-postpass|wordpress|comment_author)_/', $k) ) {
|
825 |
+
return true;
|
826 |
+
}
|
827 |
+
}
|
828 |
+
}
|
829 |
+
|
830 |
+
|
831 |
+
/**
|
832 |
+
* Definition der Ausnahmen für den Cache
|
833 |
+
*
|
834 |
+
* @since 0.2
|
835 |
+
* @change 2.0
|
836 |
+
*
|
837 |
+
* @return boolean TRUE bei Ausnahmen
|
838 |
+
*/
|
839 |
+
|
840 |
+
private static function _skip_cache()
|
841 |
+
{
|
842 |
+
/* Optionen */
|
843 |
+
$options = self::$options;
|
844 |
+
|
845 |
+
/* Filter */
|
846 |
+
if ( !empty($_POST) or self::_is_index() or is_search() or is_404() or is_feed() or is_trackback() or is_robots() or is_preview() or post_password_required() ) {
|
847 |
+
return true;
|
848 |
+
}
|
849 |
+
|
850 |
+
/* Logged in */
|
851 |
+
if ( $options['only_guests'] && self::_is_logged_in() ) {
|
852 |
+
return true;
|
853 |
+
}
|
854 |
+
|
855 |
+
/* WP Touch */
|
856 |
+
if ( self::_is_mobile() ) {
|
857 |
+
return true;
|
858 |
+
}
|
859 |
+
|
860 |
+
/* Post IDs */
|
861 |
+
if ( $options['without_ids'] && is_singular() ) {
|
862 |
+
if ( in_array( $GLOBALS['wp_query']->get_queried_object_id(), self::_preg_split($options['without_ids']) ) ) {
|
863 |
+
return true;
|
864 |
+
}
|
865 |
+
}
|
866 |
+
|
867 |
+
/* User Agents */
|
868 |
+
if ( $options['without_agents'] && isset($_SERVER['HTTP_USER_AGENT']) ) {
|
869 |
+
if ( array_filter( self::_preg_split($options['without_agents']), create_function('$a', 'return strpos($_SERVER["HTTP_USER_AGENT"], $a);') ) ) {
|
870 |
+
return true;
|
871 |
+
}
|
872 |
+
}
|
873 |
+
|
874 |
+
return false;
|
875 |
+
}
|
876 |
+
|
877 |
+
|
878 |
+
/**
|
879 |
+
* Komprimierung des HTML-Codes
|
880 |
+
*
|
881 |
+
* @since 0.9.2
|
882 |
+
* @change 1.2.1
|
883 |
+
*
|
884 |
+
* @param string $data Zu komprimierende Datensatz
|
885 |
+
* @return string $data Komprimierter Datensatz
|
886 |
+
*/
|
887 |
+
|
888 |
+
private static function _minify_cache($data) {
|
889 |
+
/* Komprimieren? */
|
890 |
+
if ( !self::$options['compress_html'] ) {
|
891 |
+
return($data);
|
892 |
+
}
|
893 |
+
|
894 |
+
/* Verkleinern */
|
895 |
+
$cleaned = preg_replace(
|
896 |
+
array(
|
897 |
+
'/<!--[^\[><](.*?)-->/s',
|
898 |
+
'#(?ix)(?>[^\S ]\s*|\s{2,})(?=(?:(?:[^<]++|<(?!/?(?:textarea|pre)\b))*+)(?:<(?>textarea|pre)\b|\z))#'
|
899 |
+
),
|
900 |
+
array(
|
901 |
+
'',
|
902 |
+
' '
|
903 |
+
),
|
904 |
+
(string) $data
|
905 |
+
);
|
906 |
+
|
907 |
+
/* Fehlerhaft? */
|
908 |
+
if ( strlen($cleaned) <= 1 ) {
|
909 |
+
return($data);
|
910 |
+
}
|
911 |
+
|
912 |
+
return $cleaned;
|
913 |
+
}
|
914 |
+
|
915 |
+
|
916 |
+
/**
|
917 |
+
* Löschung des Cache für eine URL
|
918 |
+
*
|
919 |
+
* @since 0.1
|
920 |
+
* @change 2.0
|
921 |
+
*
|
922 |
+
* @param string $url URL für den Hash-Wert
|
923 |
+
*/
|
924 |
+
|
925 |
+
private static function _delete_cache($url)
|
926 |
+
{
|
927 |
+
call_user_func(
|
928 |
+
array(
|
929 |
+
self::$method,
|
930 |
+
'delete_item'
|
931 |
+
),
|
932 |
+
self::_cache_hash($url),
|
933 |
+
$url
|
934 |
+
);
|
935 |
+
}
|
936 |
+
|
937 |
+
|
938 |
+
/**
|
939 |
+
* Zurücksetzen des kompletten Cache
|
940 |
+
*
|
941 |
+
* @since 0.1
|
942 |
+
* @change 2.0
|
943 |
+
*/
|
944 |
+
|
945 |
+
public static function flush_cache()
|
946 |
+
{
|
947 |
+
/* DB */
|
948 |
+
Cachify_DB::clear_cache();
|
949 |
+
|
950 |
+
/* APC */
|
951 |
+
Cachify_APC::clear_cache();
|
952 |
+
|
953 |
+
/* HD */
|
954 |
+
Cachify_HDD::clear_cache();
|
955 |
+
|
956 |
+
/* Transient */
|
957 |
+
delete_transient('cachify_cache_size');
|
958 |
+
}
|
959 |
+
|
960 |
+
|
961 |
+
/**
|
962 |
+
* Zuweisung des Cache
|
963 |
+
*
|
964 |
+
* @since 0.1
|
965 |
+
* @change 2.0
|
966 |
+
*
|
967 |
+
* @param string $data Inhalt der Seite
|
968 |
+
* @return string $data Inhalt der Seite
|
969 |
+
*/
|
970 |
+
|
971 |
+
public static function set_cache($data)
|
972 |
+
{
|
973 |
+
/* Leer? */
|
974 |
+
if ( empty($data) ) {
|
975 |
+
return '';
|
976 |
+
}
|
977 |
+
|
978 |
+
/* Speicherung */
|
979 |
+
call_user_func(
|
980 |
+
array(
|
981 |
+
self::$method,
|
982 |
+
'store_item'
|
983 |
+
),
|
984 |
+
self::_cache_hash(),
|
985 |
+
self::_minify_cache($data),
|
986 |
+
self::_cache_expires()
|
987 |
+
);
|
988 |
+
|
989 |
+
return $data;
|
990 |
+
}
|
991 |
+
|
992 |
+
|
993 |
+
/**
|
994 |
+
* Verwaltung des Cache
|
995 |
+
*
|
996 |
+
* @since 0.1
|
997 |
+
* @change 2.0
|
998 |
+
*/
|
999 |
+
|
1000 |
+
public static function manage_cache()
|
1001 |
+
{
|
1002 |
+
/* Kein Caching? */
|
1003 |
+
if ( self::_skip_cache() ) {
|
1004 |
+
return;
|
1005 |
+
}
|
1006 |
+
|
1007 |
+
/* Daten im Cache */
|
1008 |
+
$cache = call_user_func(
|
1009 |
+
array(
|
1010 |
+
self::$method,
|
1011 |
+
'get_item'
|
1012 |
+
),
|
1013 |
+
self::_cache_hash()
|
1014 |
+
);
|
1015 |
+
|
1016 |
+
/* Kein Cache? */
|
1017 |
+
if ( empty($cache) ) {
|
1018 |
+
ob_start('Cachify::set_cache');
|
1019 |
+
return;
|
1020 |
+
}
|
1021 |
+
|
1022 |
+
/* Cache verarbeiten */
|
1023 |
+
call_user_func(
|
1024 |
+
array(
|
1025 |
+
self::$method,
|
1026 |
+
'print_cache'
|
1027 |
+
),
|
1028 |
+
$cache
|
1029 |
+
);
|
1030 |
+
}
|
1031 |
+
|
1032 |
+
|
1033 |
+
/**
|
1034 |
+
* Einbindung von CSS
|
1035 |
+
*
|
1036 |
+
* @since 1.0
|
1037 |
+
* @change 2.0
|
1038 |
+
*/
|
1039 |
+
|
1040 |
+
public static function add_css()
|
1041 |
+
{
|
1042 |
+
/* Infos auslesen */
|
1043 |
+
$data = get_plugin_data(CACHIFY_FILE);
|
1044 |
+
|
1045 |
+
/* CSS registrieren */
|
1046 |
+
wp_register_style(
|
1047 |
+
'cachify_css',
|
1048 |
+
plugins_url('css/style.css', CACHIFY_FILE),
|
1049 |
+
array(),
|
1050 |
+
$data['Version']
|
1051 |
+
);
|
1052 |
+
|
1053 |
+
/* CSS einbinden */
|
1054 |
+
wp_enqueue_style('cachify_css');
|
1055 |
+
}
|
1056 |
+
|
1057 |
+
|
1058 |
+
/**
|
1059 |
+
* Einfügen der Optionsseite
|
1060 |
+
*
|
1061 |
+
* @since 1.0
|
1062 |
+
* @change 2.0
|
1063 |
+
*/
|
1064 |
+
|
1065 |
+
public static function add_page()
|
1066 |
+
{
|
1067 |
+
$page = add_options_page(
|
1068 |
+
'Cachify',
|
1069 |
+
'<span id="cachify_sidebar_icon"></span>Cachify',
|
1070 |
+
'manage_options',
|
1071 |
+
'cachify',
|
1072 |
+
array(
|
1073 |
+
__CLASS__,
|
1074 |
+
'options_page'
|
1075 |
+
)
|
1076 |
+
);
|
1077 |
+
|
1078 |
+
/* Hilfe */
|
1079 |
+
add_action(
|
1080 |
+
'load-' .$page,
|
1081 |
+
array(
|
1082 |
+
__CLASS__,
|
1083 |
+
'add_help'
|
1084 |
+
)
|
1085 |
+
);
|
1086 |
+
}
|
1087 |
+
|
1088 |
+
|
1089 |
+
/**
|
1090 |
+
* Hilfe-Tab oben rechts
|
1091 |
+
*
|
1092 |
+
* @since 2.0
|
1093 |
+
* @change 2.0
|
1094 |
+
*/
|
1095 |
+
|
1096 |
+
public static function add_help()
|
1097 |
+
{
|
1098 |
+
/* WP zu alt? */
|
1099 |
+
if ( !self::_is_wp('3.3') ) {
|
1100 |
+
return;
|
1101 |
+
}
|
1102 |
+
|
1103 |
+
/* Screen */
|
1104 |
+
$screen = get_current_screen();
|
1105 |
+
|
1106 |
+
/* Tabs */
|
1107 |
+
$screen->add_help_tab(
|
1108 |
+
array(
|
1109 |
+
'id' => 'cachify_settings',
|
1110 |
+
'title' => 'Einstellungen',
|
1111 |
+
'content' => '<p>Bereitgestellte Einstellungen in Schnellübersicht:</p>'.
|
1112 |
+
'<ul>'.
|
1113 |
+
'<li><em>Aufbewahrungsort für Cache</em><br />'.
|
1114 |
+
'Je nach Verfügbarkeit stehen 3 Methoden der Cache-Speicherung zur Nutzung bereit: <em>Datenbank</em>, <em>APC</em>, <em>Festplatte</em>. Die Standard-Einstellung ist <em>Datenbank</em> - Cache-Inhalte werden dabei in der WordPress-Datenbank abgelegt und dort verwaltet. <em>APC</em> (Alternative PHP Cache) kann bei installiertem APC-PHP-Modul ausgewählt und verwendet werden. <em>Festplatte</em> als Methode ist erst bei eingeschalteten WordPress-Permalinks nutzbar. Bei der Auswahl <em>Festplatte</em> und <em>APC</em> sind Anpassungen in der Datei <em>.htaccess</em> / <em>nginx.conf</em> notwendig.</li>'.
|
1115 |
+
|
1116 |
+
'<li><em>Cache-Gültigkeit in Stunden</em><br />'.
|
1117 |
+
'Gültigkeitsdauer der Aufbewahrung von Cache-Inhalten. Keine Verwendung bei <em>Festplatte</em> als Caching-Methode. <em>0</em> = <em>unbegrenzt</em></li>'.
|
1118 |
+
|
1119 |
+
'<li><em>Komprimierung der Ausgabe</em><br />'.
|
1120 |
+
'Durch die Entfernung von HTML-Kommentaren und Umbrüchen im Quelltext der Blogseiten kann die Ausgabegröße reduziert und die Übertragung beschleunigt werden. In Fehlerfällen ist die Option zu deaktivieren.</li>'.
|
1121 |
+
'</ul>'
|
1122 |
+
)
|
1123 |
+
);
|
1124 |
+
$screen->add_help_tab(
|
1125 |
+
array(
|
1126 |
+
'id' => 'cachify_filter',
|
1127 |
+
'title' => 'Filter',
|
1128 |
+
'content' => '<p>Filter grenzen die Cache-Anwendung wie folgt ein:</p>'.
|
1129 |
+
'<ul>'.
|
1130 |
+
'<li><em>Ausnahme für (Post/Pages) IDs</em><br />'.
|
1131 |
+
'IDs bestimmter Artikel oder/und Seiten, die vom Caching ausgeschlossen werden sollen. Kommaseparierte Liste.</li>'.
|
1132 |
+
|
1133 |
+
'<li><em>Ausnahme für User Agents</em><br />'.
|
1134 |
+
'User Agents gewünschter Browser bzw. Apps, die eine zwischengespeicherte Version der Webseite nie angezeigt bekommen sollen. Gilt nicht bei <em>APC</em> und <em>Festplatte</em> als Caching-Methoden.</li>'.
|
1135 |
+
|
1136 |
+
'<li><em>Kein Cache für eingeloggte bzw. kommentierende Nutzer</em><br />'.
|
1137 |
+
'Bei aktiver Option bekommen ausschließlich nicht angemeldete bzw. nicht kommentierende Blog-Nutzer die Cache-Variante einer Webseite angezeigt. Gilt nicht bei <em>APC</em>. Online-Dokumentation beachten.</li>'.
|
1138 |
+
'</ul>'
|
1139 |
+
)
|
1140 |
+
);
|
1141 |
+
$screen->add_help_tab(
|
1142 |
+
array(
|
1143 |
+
'id' => 'cachify_dashboard',
|
1144 |
+
'title' => 'Dashboard',
|
1145 |
+
'content' => '<p>Auf dem Admin-Dashboard bildet Cachify die aktuelle Cache-Größe ab. Der Wert aktualisiert sich alle 15 Minuten.</p>'
|
1146 |
+
)
|
1147 |
+
);
|
1148 |
+
$screen->add_help_tab(
|
1149 |
+
array(
|
1150 |
+
'id' => 'cachify_manual',
|
1151 |
+
'title' => 'Dokumentation',
|
1152 |
+
'content' => '<p>Ausführliche Dokumentation für das Cachify-Plugin online verfügbar:</p>'.
|
1153 |
+
'<p><a href="http://playground.ebiene.de/cachify-wordpress-cache/" target="_blank">http://playground.ebiene.de/cachify-wordpress-cache/</a></p>'
|
1154 |
+
)
|
1155 |
+
);
|
1156 |
+
|
1157 |
+
/* Sidebar */
|
1158 |
+
$screen->set_help_sidebar(
|
1159 |
+
'<p><strong>Mehr zum Autor</strong></p>'.
|
1160 |
+
'<p><a href="https://plus.google.com/110569673423509816572/" target="_blank">Google+</a></p>'.
|
1161 |
+
'<p><a href="http://ebiene.de" target="_blank">Portfolio</a></p>'.
|
1162 |
+
'<p><a href="http://flattr.com/profile/sergej.mueller" target="_blank">Flattr</a></p>'
|
1163 |
+
);
|
1164 |
+
}
|
1165 |
+
|
1166 |
+
|
1167 |
+
/**
|
1168 |
+
* Verfügbare Cache-Methoden
|
1169 |
+
*
|
1170 |
+
* @since 2.0
|
1171 |
+
* @change 2.0
|
1172 |
+
*
|
1173 |
+
* @param array $available Array mit verfügbaren Arten
|
1174 |
+
*/
|
1175 |
+
|
1176 |
+
private static function _method_select()
|
1177 |
+
{
|
1178 |
+
/* Verfügbar */
|
1179 |
+
$available = array(
|
1180 |
+
0 => 'Datenbank',
|
1181 |
+
1 => 'APC',
|
1182 |
+
2 => 'Festplatte'
|
1183 |
+
);
|
1184 |
+
|
1185 |
+
/* Kein APC */
|
1186 |
+
if ( !extension_loaded('apc') ) {
|
1187 |
+
unset($available[1]);
|
1188 |
+
}
|
1189 |
+
|
1190 |
+
/* Keine Permalinks */
|
1191 |
+
if ( !get_option('permalink_structure') ) {
|
1192 |
+
unset($available[2]);
|
1193 |
+
}
|
1194 |
+
|
1195 |
+
return $available;
|
1196 |
+
}
|
1197 |
+
|
1198 |
+
|
1199 |
+
/**
|
1200 |
+
* Registrierung der Settings
|
1201 |
+
*
|
1202 |
+
* @since 1.0
|
1203 |
+
* @change 1.0
|
1204 |
+
*/
|
1205 |
+
|
1206 |
+
public static function register_settings()
|
1207 |
+
{
|
1208 |
+
register_setting(
|
1209 |
+
'cachify',
|
1210 |
+
'cachify',
|
1211 |
+
array(
|
1212 |
+
__CLASS__,
|
1213 |
+
'validate_options'
|
1214 |
+
)
|
1215 |
+
);
|
1216 |
+
}
|
1217 |
+
|
1218 |
+
|
1219 |
+
/**
|
1220 |
+
* Valisierung der Optionsseite
|
1221 |
+
*
|
1222 |
+
* @since 1.0
|
1223 |
+
* @change 2.0
|
1224 |
+
*
|
1225 |
+
* @param array $data Array mit Formularwerten
|
1226 |
+
* @return array Array mit geprüften Werten
|
1227 |
+
*/
|
1228 |
+
|
1229 |
+
public static function validate_options($data)
|
1230 |
+
{
|
1231 |
+
/* Cache leeren */
|
1232 |
+
self::flush_cache();
|
1233 |
+
|
1234 |
+
/* Hinweis */
|
1235 |
+
if ( self::$options['use_apc'] != $data['use_apc'] && $data['use_apc'] >= 1 ) {
|
1236 |
+
add_settings_error(
|
1237 |
+
'cachify_method_tip',
|
1238 |
+
'cachify_method_tip',
|
1239 |
+
'Die Server-Konfigurationsdatei (z.B. .htaccess) muss jetzt erweitert werden [<a href="http://playground.ebiene.de/cachify-wordpress-cache/" target="_blank">?</a>]',
|
1240 |
+
'error'
|
1241 |
+
);
|
1242 |
+
}
|
1243 |
+
|
1244 |
+
/* Rückgabe */
|
1245 |
+
return array(
|
1246 |
+
'only_guests' => (int)(!empty($data['only_guests'])),
|
1247 |
+
'compress_html' => (int)(!empty($data['compress_html'])),
|
1248 |
+
'cache_expires' => (int)(@$data['cache_expires']),
|
1249 |
+
'without_ids' => (string)sanitize_text_field(@$data['without_ids']),
|
1250 |
+
'without_agents' => (string)sanitize_text_field(@$data['without_agents']),
|
1251 |
+
'use_apc' => (int)$data['use_apc']
|
1252 |
+
);
|
1253 |
+
}
|
1254 |
+
|
1255 |
+
|
1256 |
+
/**
|
1257 |
+
* Darstellung der Optionsseite
|
1258 |
+
*
|
1259 |
+
* @since 1.0
|
1260 |
+
* @change 2.0
|
1261 |
+
*/
|
1262 |
+
|
1263 |
+
public static function options_page()
|
1264 |
+
{ ?>
|
1265 |
+
<div class="wrap" id="cachify_main">
|
1266 |
+
<?php screen_icon('cachify') ?>
|
1267 |
+
|
1268 |
+
<h2>
|
1269 |
+
Cachify
|
1270 |
+
</h2>
|
1271 |
+
|
1272 |
+
<form method="post" action="options.php">
|
1273 |
+
<?php settings_fields('cachify') ?>
|
1274 |
+
|
1275 |
+
<?php $options = self::_get_options() ?>
|
1276 |
+
|
1277 |
+
<div class="table rounded">
|
1278 |
+
<table class="form-table">
|
1279 |
+
<caption class="rounded">Einstellungen</caption>
|
1280 |
+
|
1281 |
+
<tr>
|
1282 |
+
<th>
|
1283 |
+
Aufbewahrungsort für Cache
|
1284 |
+
</th>
|
1285 |
+
<td>
|
1286 |
+
<select name="cachify[use_apc]">
|
1287 |
+
<?php foreach( self::_method_select() as $k => $v ) { ?>
|
1288 |
+
<option value="<?php echo esc_attr($k) ?>" <?php selected($options['use_apc'], $k); ?>><?php echo esc_html($v) ?></option>
|
1289 |
+
<?php } ?>
|
1290 |
+
</select>
|
1291 |
+
</td>
|
1292 |
+
</tr>
|
1293 |
+
|
1294 |
+
<tr>
|
1295 |
+
<th>
|
1296 |
+
Cache-Gültigkeit in Stunden
|
1297 |
+
</th>
|
1298 |
+
<td>
|
1299 |
+
<input type="text" name="cachify[cache_expires]" value="<?php echo $options['cache_expires'] ?>" class="small" />
|
1300 |
+
</td>
|
1301 |
+
</tr>
|
1302 |
+
|
1303 |
+
<tr>
|
1304 |
+
<th>
|
1305 |
+
Komprimierung der Ausgabe
|
1306 |
+
</th>
|
1307 |
+
<td>
|
1308 |
+
<input type="checkbox" name="cachify[compress_html]" value="1" <?php checked('1', $options['compress_html']); ?> />
|
1309 |
+
</td>
|
1310 |
+
</tr>
|
1311 |
+
</table>
|
1312 |
+
</div>
|
1313 |
+
|
1314 |
+
<div class="table rounded">
|
1315 |
+
<table class="form-table">
|
1316 |
+
<caption class="rounded">Filter</caption>
|
1317 |
+
|
1318 |
+
<tr>
|
1319 |
+
<th>
|
1320 |
+
Ausnahme für (Post/Pages) IDs
|
1321 |
+
</th>
|
1322 |
+
<td>
|
1323 |
+
<input type="text" name="cachify[without_ids]" value="<?php echo $options['without_ids'] ?>" />
|
1324 |
+
</td>
|
1325 |
+
</tr>
|
1326 |
+
|
1327 |
+
<tr>
|
1328 |
+
<th>
|
1329 |
+
Ausnahme für User Agents
|
1330 |
+
</th>
|
1331 |
+
<td>
|
1332 |
+
<input type="text" name="cachify[without_agents]" value="<?php echo $options['without_agents'] ?>" />
|
1333 |
+
</td>
|
1334 |
+
</tr>
|
1335 |
+
|
1336 |
+
<tr>
|
1337 |
+
<th>
|
1338 |
+
Kein Cache für eingeloggte<br />bzw. kommentierende Nutzer
|
1339 |
+
</th>
|
1340 |
+
<td>
|
1341 |
+
<input type="checkbox" name="cachify[only_guests]" value="1" <?php checked('1', $options['only_guests']); ?> />
|
1342 |
+
</td>
|
1343 |
+
</tr>
|
1344 |
+
</table>
|
1345 |
+
</div>
|
1346 |
+
|
1347 |
+
<p class="submit">
|
1348 |
+
<span class="help">Beachte die Hilfe<br />oben rechts</span>
|
1349 |
+
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
|
1350 |
+
</p>
|
1351 |
+
</form>
|
1352 |
+
</div><?php
|
1353 |
+
}
|
1354 |
+
}
|
inc/cachify_apc.class.php
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
/* Secure check */
|
5 |
+
if ( !class_exists('Cachify') ) {
|
6 |
+
die();
|
7 |
+
}
|
8 |
+
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Cachify_APC
|
12 |
+
*/
|
13 |
+
|
14 |
+
final class Cachify_APC {
|
15 |
+
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Speicherung im Cache
|
19 |
+
*
|
20 |
+
* @since 2.0
|
21 |
+
* @change 2.0
|
22 |
+
*
|
23 |
+
* @param string $hash Hash des Eintrags
|
24 |
+
* @param string $data Inhalt des Eintrags
|
25 |
+
* @param integer $lifetime Lebensdauer des Eintrags
|
26 |
+
*/
|
27 |
+
|
28 |
+
public static function store_item($hash, $data, $lifetime)
|
29 |
+
{
|
30 |
+
/* Leer? */
|
31 |
+
if ( empty($hash) or empty($data) ) {
|
32 |
+
wp_die('APC add item: Empty input.');
|
33 |
+
}
|
34 |
+
|
35 |
+
/* Store */
|
36 |
+
apc_store(
|
37 |
+
$hash,
|
38 |
+
gzencode( $data . self::_cache_signatur(), 9),
|
39 |
+
$lifetime
|
40 |
+
);
|
41 |
+
}
|
42 |
+
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Lesen aus dem Cache
|
46 |
+
*
|
47 |
+
* @since 2.0
|
48 |
+
* @change 2.0
|
49 |
+
*
|
50 |
+
* @param string $hash Hash des Eintrags
|
51 |
+
* @return mixed $diff Wert des Eintrags
|
52 |
+
*/
|
53 |
+
|
54 |
+
public static function get_item($hash)
|
55 |
+
{
|
56 |
+
/* Leer? */
|
57 |
+
if ( empty($hash) ) {
|
58 |
+
wp_die('APC get item: Empty input.');
|
59 |
+
}
|
60 |
+
|
61 |
+
return ( function_exists('apc_exists') ? apc_exists($hash) : apc_fetch($hash) );
|
62 |
+
}
|
63 |
+
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Entfernung aus dem Cache
|
67 |
+
*
|
68 |
+
* @since 2.0
|
69 |
+
* @change 2.0
|
70 |
+
*
|
71 |
+
* @param string $hash Hash des Eintrags
|
72 |
+
* @param string $url URL des Eintrags [optional]
|
73 |
+
*/
|
74 |
+
|
75 |
+
public static function delete_item($hash, $url = '')
|
76 |
+
{
|
77 |
+
/* Leer? */
|
78 |
+
if ( empty($hash) ) {
|
79 |
+
wp_die('APC delete item: Empty input.');
|
80 |
+
}
|
81 |
+
|
82 |
+
/* Löschen */
|
83 |
+
apc_delete($hash);
|
84 |
+
}
|
85 |
+
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Leerung des Cache
|
89 |
+
*
|
90 |
+
* @since 2.0
|
91 |
+
* @change 2.0
|
92 |
+
*/
|
93 |
+
|
94 |
+
public static function clear_cache()
|
95 |
+
{
|
96 |
+
if ( extension_loaded('apc') ) {
|
97 |
+
apc_clear_cache('user');
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Ausgabe des Cache
|
104 |
+
*
|
105 |
+
* @since 2.0
|
106 |
+
* @change 2.0
|
107 |
+
*/
|
108 |
+
|
109 |
+
public static function print_cache()
|
110 |
+
{
|
111 |
+
return;
|
112 |
+
}
|
113 |
+
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Ermittlung der Cache-Größe
|
117 |
+
*
|
118 |
+
* @since 2.0
|
119 |
+
* @change 2.0
|
120 |
+
*
|
121 |
+
* @return mixed $diff Cache-Größe
|
122 |
+
*/
|
123 |
+
|
124 |
+
public static function get_stats()
|
125 |
+
{
|
126 |
+
/* Infos */
|
127 |
+
$data = apc_cache_info('user');
|
128 |
+
|
129 |
+
/* Leer */
|
130 |
+
if ( empty($data['mem_size']) ) {
|
131 |
+
return NULL;
|
132 |
+
}
|
133 |
+
|
134 |
+
return $data['mem_size'];
|
135 |
+
}
|
136 |
+
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Generierung der Signatur
|
140 |
+
*
|
141 |
+
* @since 2.0
|
142 |
+
* @change 2.0
|
143 |
+
*
|
144 |
+
* @return string $diff Signatur als String
|
145 |
+
*/
|
146 |
+
|
147 |
+
private static function _cache_signatur()
|
148 |
+
{
|
149 |
+
return sprintf(
|
150 |
+
"\n\n<!-- %s\n%s @ %s -->",
|
151 |
+
'Cachify | http://bit.ly/cachify',
|
152 |
+
'APC Cache',
|
153 |
+
date_i18n(
|
154 |
+
'd.m.Y H:i:s',
|
155 |
+
current_time('timestamp')
|
156 |
+
)
|
157 |
+
);
|
158 |
+
}
|
159 |
+
}
|
inc/cachify_db.class.php
ADDED
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
/* Secure check */
|
5 |
+
if ( !class_exists('Cachify') ) {
|
6 |
+
die();
|
7 |
+
}
|
8 |
+
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Cachify_DB
|
12 |
+
*/
|
13 |
+
|
14 |
+
final class Cachify_DB {
|
15 |
+
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Speicherung im Cache
|
19 |
+
*
|
20 |
+
* @since 2.0
|
21 |
+
* @change 2.0
|
22 |
+
*
|
23 |
+
* @param string $hash Hash des Eintrags
|
24 |
+
* @param string $data Inhalt des Eintrags
|
25 |
+
* @param integer $lifetime Lebensdauer des Eintrags
|
26 |
+
*/
|
27 |
+
|
28 |
+
public static function store_item($hash, $data, $lifetime)
|
29 |
+
{
|
30 |
+
/* Leer? */
|
31 |
+
if ( empty($hash) or empty($data) ) {
|
32 |
+
wp_die('DB add item: Empty input.');
|
33 |
+
}
|
34 |
+
|
35 |
+
/* Store */
|
36 |
+
set_transient(
|
37 |
+
$hash,
|
38 |
+
array(
|
39 |
+
'data' => $data,
|
40 |
+
'meta' => array(
|
41 |
+
'queries' => self::_page_queries(),
|
42 |
+
'timer' => self::_page_timer(),
|
43 |
+
'memory' => self::_page_memory(),
|
44 |
+
'time' => current_time('timestamp')
|
45 |
+
)
|
46 |
+
),
|
47 |
+
$lifetime
|
48 |
+
);
|
49 |
+
}
|
50 |
+
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Lesen aus dem Cache
|
54 |
+
*
|
55 |
+
* @since 2.0
|
56 |
+
* @change 2.0
|
57 |
+
*
|
58 |
+
* @param string $hash Hash des Eintrags
|
59 |
+
* @return mixed $diff Wert des Eintrags
|
60 |
+
*/
|
61 |
+
|
62 |
+
public static function get_item($hash)
|
63 |
+
{
|
64 |
+
/* Leer? */
|
65 |
+
if ( empty($hash) ) {
|
66 |
+
wp_die('DB get item: Empty input.');
|
67 |
+
}
|
68 |
+
|
69 |
+
return get_transient($hash);
|
70 |
+
}
|
71 |
+
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Entfernung aus dem Cache
|
75 |
+
*
|
76 |
+
* @since 2.0
|
77 |
+
* @change 2.0
|
78 |
+
*
|
79 |
+
* @param string $hash Hash des Eintrags
|
80 |
+
* @param string $url URL des Eintrags [optional]
|
81 |
+
*/
|
82 |
+
|
83 |
+
public static function delete_item($hash, $url = '')
|
84 |
+
{
|
85 |
+
/* Leer? */
|
86 |
+
if ( empty($hash) ) {
|
87 |
+
wp_die('DB delete item: Empty input.');
|
88 |
+
}
|
89 |
+
|
90 |
+
/* Löschen */
|
91 |
+
delete_transient($hash);
|
92 |
+
}
|
93 |
+
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Leerung des Cache
|
97 |
+
*
|
98 |
+
* @since 2.0
|
99 |
+
* @change 2.0
|
100 |
+
*/
|
101 |
+
|
102 |
+
public static function clear_cache()
|
103 |
+
{
|
104 |
+
/* Init */
|
105 |
+
global $wpdb;
|
106 |
+
|
107 |
+
/* Löschen */
|
108 |
+
$wpdb->query("DELETE FROM `" .$wpdb->options. "` WHERE `option_name` LIKE ('_transient%.cachify')");
|
109 |
+
|
110 |
+
/* Optimieren */
|
111 |
+
$wpdb->query("OPTIMIZE TABLE `" .$wpdb->options. "`");
|
112 |
+
}
|
113 |
+
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Ausgabe des Cache
|
117 |
+
*
|
118 |
+
* @since 2.0
|
119 |
+
* @change 2.0
|
120 |
+
*/
|
121 |
+
|
122 |
+
public static function print_cache(array $cache)
|
123 |
+
{
|
124 |
+
/* Content */
|
125 |
+
echo $cache['data'];
|
126 |
+
|
127 |
+
/* Signatur */
|
128 |
+
if ( isset($cache['meta']) ) {
|
129 |
+
echo self::_cache_signatur($cache['meta']);
|
130 |
+
}
|
131 |
+
|
132 |
+
/* Raus */
|
133 |
+
exit;
|
134 |
+
}
|
135 |
+
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Ermittlung der Cache-Größe
|
139 |
+
*
|
140 |
+
* @since 2.0
|
141 |
+
* @change 2.0
|
142 |
+
*
|
143 |
+
* @return integer $diff Spaltengröße
|
144 |
+
*/
|
145 |
+
|
146 |
+
public static function get_stats()
|
147 |
+
{
|
148 |
+
/* Init */
|
149 |
+
global $wpdb;
|
150 |
+
|
151 |
+
/* Auslesen */
|
152 |
+
return $wpdb->get_var(
|
153 |
+
"SELECT SUM( CHAR_LENGTH(option_value) ) FROM `" .$wpdb->options. "` WHERE `option_name` LIKE ('_transient%.cachify')"
|
154 |
+
);
|
155 |
+
}
|
156 |
+
|
157 |
+
|
158 |
+
/**
|
159 |
+
* Generierung der Signatur
|
160 |
+
*
|
161 |
+
* @since 2.0
|
162 |
+
* @change 2.0
|
163 |
+
*
|
164 |
+
* @param array $meta Inhalt der Metadaten
|
165 |
+
* @return string $diff Signatur als String
|
166 |
+
*/
|
167 |
+
|
168 |
+
private static function _cache_signatur(array $meta)
|
169 |
+
{
|
170 |
+
return sprintf(
|
171 |
+
"\n\n<!--\n%s\n%s\n%s\n%s\n-->",
|
172 |
+
'Cachify | http://bit.ly/cachify',
|
173 |
+
sprintf(
|
174 |
+
'Ohne Plugin: %d DB-Anfragen, %s Sekunden, %s',
|
175 |
+
$meta['queries'],
|
176 |
+
$meta['timer'],
|
177 |
+
$meta['memory']
|
178 |
+
),
|
179 |
+
sprintf(
|
180 |
+
'Mit Plugin: %d DB-Anfragen, %s Sekunden, %s',
|
181 |
+
self::_page_queries(),
|
182 |
+
self::_page_timer(),
|
183 |
+
self::_page_memory()
|
184 |
+
),
|
185 |
+
sprintf(
|
186 |
+
'Generiert: %s zuvor',
|
187 |
+
human_time_diff($meta['time'], current_time('timestamp'))
|
188 |
+
)
|
189 |
+
);
|
190 |
+
}
|
191 |
+
|
192 |
+
|
193 |
+
/**
|
194 |
+
* Rückgabe der Query-Anzahl
|
195 |
+
*
|
196 |
+
* @since 0.1
|
197 |
+
* @change 2.0
|
198 |
+
*
|
199 |
+
* @return intval $diff Query-Anzahl
|
200 |
+
*/
|
201 |
+
|
202 |
+
private static function _page_queries()
|
203 |
+
{
|
204 |
+
return $GLOBALS['wpdb']->num_queries;
|
205 |
+
}
|
206 |
+
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Rückgabe der Ausführungszeit
|
210 |
+
*
|
211 |
+
* @since 0.1
|
212 |
+
* @change 2.0
|
213 |
+
*
|
214 |
+
* @return intval $diff Anzahl der Sekunden
|
215 |
+
*/
|
216 |
+
|
217 |
+
private static function _page_timer()
|
218 |
+
{
|
219 |
+
return timer_stop(0, 2);
|
220 |
+
}
|
221 |
+
|
222 |
+
|
223 |
+
/**
|
224 |
+
* Rückgabe des Speicherverbrauchs
|
225 |
+
*
|
226 |
+
* @since 0.7
|
227 |
+
* @change 2.0
|
228 |
+
*
|
229 |
+
* @return string $diff Konvertierter Größenwert
|
230 |
+
*/
|
231 |
+
|
232 |
+
private static function _page_memory()
|
233 |
+
{
|
234 |
+
return ( function_exists('memory_get_usage') ? size_format(memory_get_usage(), 2) : 0 );
|
235 |
+
}
|
236 |
+
}
|
inc/cachify_hdd.class.php
ADDED
@@ -0,0 +1,348 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
/* Secure check */
|
5 |
+
if ( !class_exists('Cachify') ) {
|
6 |
+
die();
|
7 |
+
}
|
8 |
+
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Cachify_HDD
|
12 |
+
*/
|
13 |
+
|
14 |
+
final class Cachify_HDD {
|
15 |
+
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Speicherung im Cache
|
19 |
+
*
|
20 |
+
* @since 2.0
|
21 |
+
* @change 2.0
|
22 |
+
*
|
23 |
+
* @param string $hash Hash des Eintrags [optional]
|
24 |
+
* @param string $data Inhalt des Eintrags
|
25 |
+
* @param integer $lifetime Lebensdauer des Eintrags [optional]
|
26 |
+
*/
|
27 |
+
|
28 |
+
public static function store_item($hash, $data, $lifetime)
|
29 |
+
{
|
30 |
+
/* Leer? */
|
31 |
+
if ( empty($data) ) {
|
32 |
+
wp_die('HDD add item: Empty input.');
|
33 |
+
}
|
34 |
+
|
35 |
+
/* Speichern */
|
36 |
+
self::_create_files(
|
37 |
+
$data . self::_cache_signatur()
|
38 |
+
);
|
39 |
+
}
|
40 |
+
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Lesen aus dem Cache
|
44 |
+
*
|
45 |
+
* @since 2.0
|
46 |
+
* @change 2.0
|
47 |
+
*
|
48 |
+
* @return boolean $diff TRUE wenn Cache vorhanden
|
49 |
+
*/
|
50 |
+
|
51 |
+
public static function get_item()
|
52 |
+
{
|
53 |
+
return is_readable( self::_file_html() );
|
54 |
+
}
|
55 |
+
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Entfernen aus dem Cache
|
59 |
+
*
|
60 |
+
* @since 2.0
|
61 |
+
* @change 2.0
|
62 |
+
*
|
63 |
+
* @param string $hash Hash des Eintrags [optional]
|
64 |
+
* @param string $url URL des Eintrags
|
65 |
+
*/
|
66 |
+
|
67 |
+
public static function delete_item($hash = '', $url)
|
68 |
+
{
|
69 |
+
/* Leer? */
|
70 |
+
if ( empty($url) ) {
|
71 |
+
wp_die('HDD delete item: Empty input.');
|
72 |
+
}
|
73 |
+
|
74 |
+
/* Löschen */
|
75 |
+
self::_clear_dir(
|
76 |
+
self::_file_path($url)
|
77 |
+
);
|
78 |
+
}
|
79 |
+
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Leerung des Cache
|
83 |
+
*
|
84 |
+
* @since 2.0
|
85 |
+
* @change 2.0
|
86 |
+
*/
|
87 |
+
|
88 |
+
public static function clear_cache()
|
89 |
+
{
|
90 |
+
self::_clear_dir(
|
91 |
+
CACHIFY_CACHE_DIR
|
92 |
+
);
|
93 |
+
}
|
94 |
+
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Ausgabe des Cache
|
98 |
+
*
|
99 |
+
* @since 2.0
|
100 |
+
* @change 2.0
|
101 |
+
*/
|
102 |
+
|
103 |
+
public static function print_cache()
|
104 |
+
{
|
105 |
+
return;
|
106 |
+
}
|
107 |
+
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Ermittlung der Cache-Größe
|
111 |
+
*
|
112 |
+
* @since 2.0
|
113 |
+
* @change 2.0
|
114 |
+
*
|
115 |
+
* @return integer $diff Ordnergröße
|
116 |
+
*/
|
117 |
+
|
118 |
+
public static function get_stats()
|
119 |
+
{
|
120 |
+
return self::_dir_size( CACHIFY_CACHE_DIR );
|
121 |
+
}
|
122 |
+
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Generierung der Signatur
|
126 |
+
*
|
127 |
+
* @since 2.0
|
128 |
+
* @change 2.0
|
129 |
+
*
|
130 |
+
* @return string $diff Signatur als String
|
131 |
+
*/
|
132 |
+
|
133 |
+
private static function _cache_signatur()
|
134 |
+
{
|
135 |
+
return sprintf(
|
136 |
+
"\n\n<!-- %s\n%s @ %s -->",
|
137 |
+
'Cachify | http://bit.ly/cachify',
|
138 |
+
'HDD Cache',
|
139 |
+
date_i18n(
|
140 |
+
'd.m.Y H:i:s',
|
141 |
+
current_time('timestamp')
|
142 |
+
)
|
143 |
+
);
|
144 |
+
}
|
145 |
+
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Initialisierung des Cache-Speichervorgangs
|
149 |
+
*
|
150 |
+
* @since 2.0
|
151 |
+
* @change 2.0
|
152 |
+
*
|
153 |
+
* @param string $data Cache-Inhalt
|
154 |
+
*/
|
155 |
+
|
156 |
+
private static function _create_files($data)
|
157 |
+
{
|
158 |
+
/* Ordner anlegen */
|
159 |
+
if ( !wp_mkdir_p( self::_file_path() ) ) {
|
160 |
+
wp_die('Unable to create directory.');
|
161 |
+
}
|
162 |
+
|
163 |
+
/* Dateien schreiben */
|
164 |
+
self::_create_file( self::_file_html(), $data );
|
165 |
+
self::_create_file( self::_file_gzip(), gzencode($data, 9) );
|
166 |
+
}
|
167 |
+
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Anlegen der Cache-Datei
|
171 |
+
*
|
172 |
+
* @since 2.0
|
173 |
+
* @change 2.0
|
174 |
+
*
|
175 |
+
* @param string $file Pfad der Cache-Datei
|
176 |
+
* @param string $data Cache-Inhalt
|
177 |
+
*/
|
178 |
+
|
179 |
+
private static function _create_file($file, $data)
|
180 |
+
{
|
181 |
+
/* Beschreibbar? */
|
182 |
+
if ( !$handle = @fopen($file, 'wb') ) {
|
183 |
+
wp_die('Could not write file.');
|
184 |
+
}
|
185 |
+
|
186 |
+
/* Schreiben */
|
187 |
+
@fwrite($handle, $data);
|
188 |
+
fclose($handle);
|
189 |
+
clearstatcache();
|
190 |
+
|
191 |
+
/* Permissions */
|
192 |
+
$stat = @stat( dirname($file) );
|
193 |
+
$perms = $stat['mode'] & 0007777;
|
194 |
+
$perms = $perms & 0000666;
|
195 |
+
@chmod($file, $perms);
|
196 |
+
clearstatcache();
|
197 |
+
}
|
198 |
+
|
199 |
+
|
200 |
+
/**
|
201 |
+
* Rekrusive Leerung eines Ordners
|
202 |
+
*
|
203 |
+
* @since 2.0
|
204 |
+
* @change 2.0
|
205 |
+
*
|
206 |
+
* @param string $dir Ordnerpfad
|
207 |
+
*/
|
208 |
+
|
209 |
+
private static function _clear_dir($dir) {
|
210 |
+
/* Ordner? */
|
211 |
+
if ( !is_dir($dir) ) {
|
212 |
+
return;
|
213 |
+
}
|
214 |
+
|
215 |
+
/* Einlesen */
|
216 |
+
$objects = array_diff(
|
217 |
+
scandir($dir),
|
218 |
+
array('..', '.')
|
219 |
+
);
|
220 |
+
|
221 |
+
/* Leer? */
|
222 |
+
if ( empty($objects) ) {
|
223 |
+
return;
|
224 |
+
}
|
225 |
+
|
226 |
+
/* Loopen */
|
227 |
+
foreach ( $objects as $object ) {
|
228 |
+
/* Um Pfad erweitern */
|
229 |
+
$object = $dir. DIRECTORY_SEPARATOR .$object;
|
230 |
+
|
231 |
+
/* Ordner/Datei */
|
232 |
+
if ( is_dir($object) ) {
|
233 |
+
self::_clear_dir($object);
|
234 |
+
} else {
|
235 |
+
unlink($object);
|
236 |
+
}
|
237 |
+
}
|
238 |
+
|
239 |
+
/* Killen */
|
240 |
+
@rmdir($dir);
|
241 |
+
|
242 |
+
/* Aufräumen */
|
243 |
+
clearstatcache();
|
244 |
+
}
|
245 |
+
|
246 |
+
|
247 |
+
/**
|
248 |
+
* Ermittlugn der Ordnergröße
|
249 |
+
*
|
250 |
+
* @since 2.0
|
251 |
+
* @change 2.0
|
252 |
+
*
|
253 |
+
* @param string $dir Ordnerpfad
|
254 |
+
* @return mixed $size Ordnergröße
|
255 |
+
*/
|
256 |
+
|
257 |
+
public static function _dir_size($dir = '.')
|
258 |
+
{
|
259 |
+
/* Ordner? */
|
260 |
+
if ( !is_dir($dir) ) {
|
261 |
+
return;
|
262 |
+
}
|
263 |
+
|
264 |
+
/* Einlesen */
|
265 |
+
$objects = array_diff(
|
266 |
+
scandir($dir),
|
267 |
+
array('..', '.')
|
268 |
+
);
|
269 |
+
|
270 |
+
/* Leer? */
|
271 |
+
if ( empty($objects) ) {
|
272 |
+
return;
|
273 |
+
}
|
274 |
+
|
275 |
+
/* Init */
|
276 |
+
$size = 0;
|
277 |
+
|
278 |
+
/* Loopen */
|
279 |
+
foreach ( $objects as $object ) {
|
280 |
+
/* Um Pfad erweitern */
|
281 |
+
$object = $dir. DIRECTORY_SEPARATOR .$object;
|
282 |
+
|
283 |
+
/* Ordner/Datei */
|
284 |
+
if ( is_dir($object) ) {
|
285 |
+
$size += self::_dir_size($object);
|
286 |
+
} else {
|
287 |
+
$size += filesize($object);
|
288 |
+
}
|
289 |
+
}
|
290 |
+
|
291 |
+
return $size;
|
292 |
+
}
|
293 |
+
|
294 |
+
|
295 |
+
/**
|
296 |
+
* Pfad der Cache-Datei
|
297 |
+
*
|
298 |
+
* @since 2.0
|
299 |
+
* @change 2.0
|
300 |
+
*
|
301 |
+
* @param string $path Request-URI oder Permalink [optional]
|
302 |
+
* @return string $diff Pfad zur Cache-Datei
|
303 |
+
*/
|
304 |
+
|
305 |
+
private static function _file_path($path = NULL)
|
306 |
+
{
|
307 |
+
return sprintf(
|
308 |
+
'%s%s%s%s',
|
309 |
+
CACHIFY_CACHE_DIR,
|
310 |
+
DIRECTORY_SEPARATOR,
|
311 |
+
$_SERVER['HTTP_HOST'],
|
312 |
+
parse_url(
|
313 |
+
( $path ? $path : $_SERVER['REQUEST_URI'] ),
|
314 |
+
PHP_URL_PATH
|
315 |
+
)
|
316 |
+
);
|
317 |
+
}
|
318 |
+
|
319 |
+
|
320 |
+
/**
|
321 |
+
* Pfad der HTML-Datei
|
322 |
+
*
|
323 |
+
* @since 2.0
|
324 |
+
* @change 2.0
|
325 |
+
*
|
326 |
+
* @return string $diff Pfad zur HTML-Datei
|
327 |
+
*/
|
328 |
+
|
329 |
+
private static function _file_html()
|
330 |
+
{
|
331 |
+
return self::_file_path(). 'index.html';
|
332 |
+
}
|
333 |
+
|
334 |
+
|
335 |
+
/**
|
336 |
+
* Pfad der GZIP-Datei
|
337 |
+
*
|
338 |
+
* @since 2.0
|
339 |
+
* @change 2.0
|
340 |
+
*
|
341 |
+
* @return string $diff Pfad zur GZIP-Datei
|
342 |
+
*/
|
343 |
+
|
344 |
+
private static function _file_gzip()
|
345 |
+
{
|
346 |
+
return self::_file_path(). 'index.html.gz';
|
347 |
+
}
|
348 |
+
}
|
readme.txt
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Cachify ===
|
2 |
+
Contributors: sergej.mueller
|
3 |
+
Tags: apc, cache, caching, performance
|
4 |
+
Donate link: http://flattr.com/profile/sergej.mueller
|
5 |
+
Requires at least: 3.1
|
6 |
+
Tested up to: 3.4
|
7 |
+
Stable tag: trunk
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
Turbo für WordPress. Smarte, aber effiziente Cache-Lösung für WordPress. Mit der Konzentration aufs Wesentliche.
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
== Description ==
|
16 |
+
|
17 |
+
= Unkompliziert und ausbaufähig =
|
18 |
+
*Cachify* optimiert Ladezeit der Blogseiten, indem Seiteninhalte in statischer Form wahlweise in der Datenbank, auf der Festplatte des Webservers oder im APC (Alternative PHP Cache) abgelegt und beim Seitenaufruf ohne Umwege ausgegeben werden. Die Anzahl der DB-Anfragen und PHP-Anweisungen reduziert sich je nach Methode um Faktor 10.
|
19 |
+
|
20 |
+
= Stärken =
|
21 |
+
* Speicherungsmethoden: DB, HDD und APC
|
22 |
+
* "Cache leeren" in der Admin Bar
|
23 |
+
* Inline- und Online-Handbuch
|
24 |
+
* Optionale Komprimierung der HTML-Ausgabe
|
25 |
+
* Ausnahmelisten für Beiträge und User Agents
|
26 |
+
* Manueller und automatischer Cache-Reset
|
27 |
+
* Ausgabe der "davor, danach" Informationen im Quelltext
|
28 |
+
* Verständliche Oberfläche zum Sofortstart
|
29 |
+
* Automatisches Management des Cache-Bestandes
|
30 |
+
* Cache-Belegung auf dem Dashboard
|
31 |
+
|
32 |
+
= Information =
|
33 |
+
* [Offizielle Homepage](http://cachify.de "Cachify WordPress Cache")
|
34 |
+
* [Online-Dokumentation](http://playground.ebiene.de/cachify-wordpress-cache/ "Cachify Online-Doku")
|
35 |
+
|
36 |
+
= Autor =
|
37 |
+
* [Google+](https://plus.google.com/110569673423509816572 "Google+")
|
38 |
+
* [Portfolio](http://ebiene.de "Portfolio")
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
== Changelog ==
|
43 |
+
|
44 |
+
= 2.0 =
|
45 |
+
* Überarbeitung der GUI
|
46 |
+
* Source Code-Modularisierung
|
47 |
+
* Cache-Größe auf dem Dashboard
|
48 |
+
* Festplatte als Ablageort für Cache
|
49 |
+
* Produktseite online: http://cachify.de
|
50 |
+
* Cache-Neuaufbau bei Kommentarstatusänderungen
|
51 |
+
* APC-Anforderungen: APC 3.0.0, empfohlen 3.1.4
|
52 |
+
* Optional: Kein Cache für kommentierende Nutzer
|
53 |
+
* Schnellübersicht der Optionen als Inline-Hilfe
|
54 |
+
* Mindestanforderungen: WordPress 3.1 & PHP 5.1.2
|
55 |
+
|
56 |
+
= 1.5.1 =
|
57 |
+
* `zlib.output_compression = Off` für Apache Webserver
|
58 |
+
|
59 |
+
= 1.5 =
|
60 |
+
* Überarbeitung des Regexp für HTML-Minify
|
61 |
+
* Reduzierung des Toolbar-Buttons auf das Icon
|
62 |
+
* Formatierung und Kommentierung des Quelltextes
|
63 |
+
|
64 |
+
= 1.4 =
|
65 |
+
* Xmas Edition
|
66 |
+
|
67 |
+
= 1.3 =
|
68 |
+
* Unterstützung für APC (Alternative PHP Cache)
|
69 |
+
* Umpositionierung des Admin Bar Buttons
|
70 |
+
|
71 |
+
= 1.2.1 =
|
72 |
+
* Icon für die "Cache leeren" Schaltfläche in der Admin Bar
|
73 |
+
|
74 |
+
= 1.2 =
|
75 |
+
* Schaltfläche "Cache leeren" in der Adminbar (ab WordPress 3.1)
|
76 |
+
* `flush_cache` auf public gesetzt, um von [wpSEO](http://wpseo.de "WordPress SEO Plugin") ansprechen zu können
|
77 |
+
* Ausführliche Tests unter WordPress 3.3
|
78 |
+
|
79 |
+
= 1.1 =
|
80 |
+
* Interne Prüfung auf fehlerhafte Cache-Generierung
|
81 |
+
* Anpassungen an der Code-Struktur
|
82 |
+
* Entfernung der Inline-Hilfe
|
83 |
+
* Verknüpfung der Online-Hilfe mit Optionen
|
84 |
+
|
85 |
+
= 1.0 =
|
86 |
+
* Leerung des Cache beim Aktualisieren von statischen Seiten
|
87 |
+
* Seite mit Plugin-Einstellungen
|
88 |
+
* Inline-Dokumentation in der Optionsseite
|
89 |
+
* Ausschluss von Passwort-geschützten Seiten
|
90 |
+
* WordPress 3.2 Support
|
91 |
+
* Unterstützung der WordPress Multisite Blogs
|
92 |
+
* Umstellung auf den template_redirect-Hook (Plugin-Kompatibilität)
|
93 |
+
* Interne Code-Bereinigung
|
94 |
+
|
95 |
+
= 0.9.2 =
|
96 |
+
* HTML-Kompression
|
97 |
+
* Flattr-Link
|
98 |
+
|
99 |
+
= 0.9.1 =
|
100 |
+
* Cache-Reset bei geplanten Beiträgen
|
101 |
+
* Unterstützung für das Carrington-Mobile Theme
|
102 |
+
|
103 |
+
= 0.9 =
|
104 |
+
* Workaround für Redirects
|
105 |
+
|
106 |
+
= 0.8 =
|
107 |
+
* Blacklist für PostIDs
|
108 |
+
* Blacklist für UserAgents
|
109 |
+
* Ausnahme für WP Touch
|
110 |
+
* Ausgabe des Zeitpunktes der Generierung
|
111 |
+
* Umbenennung der Konstanten
|
112 |
+
|
113 |
+
= 0.7 =
|
114 |
+
* Ausgabe des Speicherverbrauchs
|
115 |
+
|
116 |
+
= 0.6 =
|
117 |
+
* Live auf wordpress.org
|
118 |
+
|
119 |
+
|
120 |
+
|
121 |
+
== Screenshots ==
|
122 |
+
|
123 |
+
1. Cachify Optionen
|
screenshot-1.png
ADDED
Binary file
|