Version Description
- Schaltflche "Cache leeren" in der Adminbar (ab WordPress 3.1)
-
flush_cache
auf public gesetzt, um von wpSEO ansprechen zu knnen - Ausfhrliche Tests unter WordPress 3.3
Download this release
Release Info
Developer | sergej.mueller |
Plugin | Cachify |
Version | 1.2 |
Comparing to | |
See all releases |
Version 1.2
- cachify.original.php +1207 -0
- cachify.php +642 -0
- css/style.css +1 -0
- css/style.original.css +22 -0
- img/icon.png +0 -0
- img/icon32.png +0 -0
- readme.txt +94 -0
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
cachify.original.php
ADDED
@@ -0,0 +1,1207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
);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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
if ( !class_exists('WP') ) {
|
13 |
+
header('Status: 403 Forbidden');
|
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 |
+
add_action(
|
613 |
+
'plugins_loaded',
|
614 |
+
array(
|
615 |
+
'Cachify',
|
616 |
+
'init'
|
617 |
+
),
|
618 |
+
99
|
619 |
+
);
|
620 |
+
register_activation_hook(
|
621 |
+
__FILE__,
|
622 |
+
array(
|
623 |
+
'Cachify',
|
624 |
+
'install'
|
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 |
+
}
|
css/style.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
#icon-cachify{background:url(../img/icon32.png) no-repeat;}.wp-submenu a img[alt="Cachify"]{width:11px;height:9px;border:0;}table.form-table.cachify th{width:220px;line-height:26px;}table.form-table.cachify th span{font-size:11px;white-space:nowrap;}table.form-table.cachify th span a{padding:0 1px;text-decoration:none;}
|
css/style.original.css
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
Binary file
|
img/icon32.png
ADDED
Binary file
|
readme.txt
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Cachify ===
|
2 |
+
Contributors: sergej.mueller
|
3 |
+
Tags: performance,caching,cache
|
4 |
+
Requires at least: 3.0
|
5 |
+
Tested up to: 3.3
|
6 |
+
Stable tag: trunk
|
7 |
+
|
8 |
+
Simple und effiziente Cache-Lösung für WordPress.
|
9 |
+
|
10 |
+
|
11 |
+
== Description ==
|
12 |
+
= Unkompliziert und ausbaufähig =
|
13 |
+
Cachify optimiert die Ladezeit der Blogseiten, indem Seiteninhalte in statischer Form in der Datenbank abgelegt und beim Seitenaufruf direkt ausgegeben werden. Dabei wird die Anzahl der DB-Anfragen und PHP-Anweisungen reduziert.
|
14 |
+
|
15 |
+
= Einige Stärken =
|
16 |
+
* NEU: Adminbar-Schaltfläche "Cache leeren"
|
17 |
+
* Einfache Installation: Aktivieren, fertig
|
18 |
+
* Übersichtliche Optionsseite mit verknüpfter Online-Hilfe
|
19 |
+
* Optionale Komprimierung der HTML-Ausgabe
|
20 |
+
* Ausnahmelisten für PostIDs und User Agents
|
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 |
+
= Wichtige Information =
|
27 |
+
Vor der Inbetriebnahme des Plugins ist die [Dokumentation](http://playground.ebiene.de/2652/cachify-wordpress-cache/ "Cachify WordPress Cache") durchzulesen, um eine inkorrekte Funktionsweise und negative Auswirkungen des Cache-Tools zu vermeiden!
|
28 |
+
|
29 |
+
= Weiterführende Links =
|
30 |
+
* [Blog](http://playground.ebiene.de "Playground Blog")
|
31 |
+
* [Flattr](http://flattr.com/profile/sergej.mueller "Flattr")
|
32 |
+
* [Google+](https://plus.google.com/110569673423509816572 "Google+")
|
33 |
+
* [Portfolio](http://ebiene.de "Portfolio")
|
34 |
+
* [Andere Plugins](http://wpcoder.de "Andere Plugins")
|
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
|
42 |
+
* Ausführliche Tests unter WordPress 3.3
|
43 |
+
|
44 |
+
= 1.1 =
|
45 |
+
* Interne Prüfung auf fehlerhafte Cache-Generierung
|
46 |
+
* Anpassungen an der Code-Struktur
|
47 |
+
* Entfernung der Inline-Hilfe
|
48 |
+
* Verknüpfung der Online-Hilfe mit Optionen
|
49 |
+
|
50 |
+
= 1.0 =
|
51 |
+
* Leerung des Cache beim Aktualisieren von statischen Seiten
|
52 |
+
* Seite mit Plugin-Einstellungen
|
53 |
+
* Inline-Dokumentation in der Optionsseite
|
54 |
+
* Ausschluss von Passwort-geschützten Seiten
|
55 |
+
* WordPress 3.2 Support
|
56 |
+
* Unterstützung der WordPress Multisite Blogs
|
57 |
+
* Umstellung auf den template_redirect-Hook (Plugin-Kompatibilität)
|
58 |
+
* Interne Code-Bereinigung
|
59 |
+
|
60 |
+
= 0.9.2 =
|
61 |
+
* HTML-Kompression
|
62 |
+
* Flattr-Link
|
63 |
+
|
64 |
+
= 0.9.1 =
|
65 |
+
* Cache-Reset bei geplanten Beiträgen
|
66 |
+
* Unterstützung für das Carrington-Mobile Theme
|
67 |
+
|
68 |
+
= 0.9 =
|
69 |
+
* Workaround für Redirects
|
70 |
+
|
71 |
+
= 0.8 =
|
72 |
+
* Blacklist für PostIDs
|
73 |
+
* Blacklist für UserAgents
|
74 |
+
* Ausnahme für WP Touch
|
75 |
+
* Ausgabe des Zeitpunktes der Generierung
|
76 |
+
* Umbenennung der Konstanten
|
77 |
+
|
78 |
+
= 0.7 =
|
79 |
+
* Ausgabe des Speicherverbrauchs
|
80 |
+
|
81 |
+
= 0.6 =
|
82 |
+
* Live auf wordpress.org
|
83 |
+
|
84 |
+
|
85 |
+
== Screenshots ==
|
86 |
+
|
87 |
+
1. Cachify Optionsseite
|
88 |
+
2. Cachify Cache leeren
|
89 |
+
|
90 |
+
|
91 |
+
== Installation ==
|
92 |
+
1. *Cachify* installieren
|
93 |
+
1. [Dokumentation](http://playground.ebiene.de/2652/cachify-wordpress-cache/ "Cachify WordPress Cache") beachten
|
94 |
+
1. Einstellungen vornehmen
|
screenshot-1.png
ADDED
Binary file
|
screenshot-2.png
ADDED
Binary file
|