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