Version Description
- Interne Prfung auf fehlerhafte Cache-Generierung
- Anpassungen an der Code-Struktur
- Entfernung der Inline-Hilfe
- Verknpfung der Online-Hilfe mit Optionen
Download this release
Release Info
Developer | sergej.mueller |
Plugin | Cachify |
Version | 1.1 |
Comparing to | |
See all releases |
Version 1.1
- cachify.original.php +1138 -0
- cachify.php +602 -0
- css/style.css +1 -0
- css/style.original.css +22 -0
- img/icon.png +0 -0
- img/icon32.png +0 -0
- readme.txt +86 -0
- screenshot-1.png +0 -0
cachify.original.php
ADDED
@@ -0,0 +1,1138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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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://www.wpSEO.de
|
7 |
+
Plugin URI: http://playground.ebiene.de/2652/cachify-wordpress-cache/
|
8 |
+
Version: 1.1
|
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.1
|
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 |
+
'pre_current_active_plugins',
|
70 |
+
array(
|
71 |
+
__CLASS__,
|
72 |
+
'receive_flush'
|
73 |
+
)
|
74 |
+
);
|
75 |
+
|
76 |
+
add_action(
|
77 |
+
'wpmu_new_blog',
|
78 |
+
array(
|
79 |
+
__CLASS__,
|
80 |
+
'install_later'
|
81 |
+
)
|
82 |
+
);
|
83 |
+
add_action(
|
84 |
+
'delete_blog',
|
85 |
+
array(
|
86 |
+
__CLASS__,
|
87 |
+
'uninstall_later'
|
88 |
+
)
|
89 |
+
);
|
90 |
+
|
91 |
+
add_action(
|
92 |
+
'admin_init',
|
93 |
+
array(
|
94 |
+
__CLASS__,
|
95 |
+
'register_settings'
|
96 |
+
)
|
97 |
+
);
|
98 |
+
add_action(
|
99 |
+
'admin_menu',
|
100 |
+
array(
|
101 |
+
__CLASS__,
|
102 |
+
'add_page'
|
103 |
+
)
|
104 |
+
);
|
105 |
+
add_action(
|
106 |
+
'admin_print_styles',
|
107 |
+
array(
|
108 |
+
__CLASS__,
|
109 |
+
'add_css'
|
110 |
+
)
|
111 |
+
);
|
112 |
+
|
113 |
+
add_action(
|
114 |
+
'transition_comment_status',
|
115 |
+
array(
|
116 |
+
__CLASS__,
|
117 |
+
'touch_comment'
|
118 |
+
),
|
119 |
+
10,
|
120 |
+
3
|
121 |
+
);
|
122 |
+
add_action(
|
123 |
+
'edit_comment',
|
124 |
+
array(
|
125 |
+
__CLASS__,
|
126 |
+
'edit_comment'
|
127 |
+
)
|
128 |
+
);
|
129 |
+
|
130 |
+
add_filter(
|
131 |
+
'plugin_row_meta',
|
132 |
+
array(
|
133 |
+
__CLASS__,
|
134 |
+
'row_meta'
|
135 |
+
),
|
136 |
+
10,
|
137 |
+
2
|
138 |
+
);
|
139 |
+
add_filter(
|
140 |
+
'plugin_action_links_' .self::$base,
|
141 |
+
array(
|
142 |
+
__CLASS__,
|
143 |
+
'action_links'
|
144 |
+
)
|
145 |
+
);
|
146 |
+
|
147 |
+
/* Frontend */
|
148 |
+
} else {
|
149 |
+
add_action(
|
150 |
+
'preprocess_comment',
|
151 |
+
array(
|
152 |
+
__CLASS__,
|
153 |
+
'add_comment'
|
154 |
+
),
|
155 |
+
1
|
156 |
+
);
|
157 |
+
|
158 |
+
add_action(
|
159 |
+
'template_redirect',
|
160 |
+
array(
|
161 |
+
__CLASS__,
|
162 |
+
'manage_cache'
|
163 |
+
),
|
164 |
+
99
|
165 |
+
);
|
166 |
+
}
|
167 |
+
}
|
168 |
+
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Installation des Plugins auch für MU-Blogs
|
172 |
+
*
|
173 |
+
* @since 1.0
|
174 |
+
* @change 1.0
|
175 |
+
*/
|
176 |
+
|
177 |
+
public static function install()
|
178 |
+
{
|
179 |
+
/* Global */
|
180 |
+
global $wpdb;
|
181 |
+
|
182 |
+
/* Multisite & Network */
|
183 |
+
if ( is_multisite() && !empty($_GET['networkwide']) ) {
|
184 |
+
/* Blog-IDs */
|
185 |
+
$ids = self::_get_blog_ids();
|
186 |
+
|
187 |
+
/* Loopen */
|
188 |
+
foreach ($ids as $id) {
|
189 |
+
switch_to_blog( (int)$id );
|
190 |
+
self::_install_backend();
|
191 |
+
}
|
192 |
+
|
193 |
+
/* Wechsel zurück */
|
194 |
+
restore_current_blog();
|
195 |
+
|
196 |
+
} else {
|
197 |
+
self::_install_backend();
|
198 |
+
}
|
199 |
+
}
|
200 |
+
|
201 |
+
|
202 |
+
/**
|
203 |
+
* Installation des Plugins bei einem neuen MU-Blog
|
204 |
+
*
|
205 |
+
* @since 1.0
|
206 |
+
* @change 1.0
|
207 |
+
*/
|
208 |
+
|
209 |
+
public static function install_later($id) {
|
210 |
+
/* Kein Netzwerk-Plugin */
|
211 |
+
if ( !is_plugin_active_for_network(self::$base) ) {
|
212 |
+
return;
|
213 |
+
}
|
214 |
+
|
215 |
+
/* Wechsel */
|
216 |
+
switch_to_blog( (int)$id );
|
217 |
+
|
218 |
+
/* Installieren */
|
219 |
+
self::_install_backend();
|
220 |
+
|
221 |
+
/* Wechsel zurück */
|
222 |
+
restore_current_blog();
|
223 |
+
}
|
224 |
+
|
225 |
+
|
226 |
+
/**
|
227 |
+
* Eigentliche Installation der Option und der Tabelle
|
228 |
+
*
|
229 |
+
* @since 1.0
|
230 |
+
* @change 1.0
|
231 |
+
*/
|
232 |
+
|
233 |
+
private static function _install_backend()
|
234 |
+
{
|
235 |
+
add_option(
|
236 |
+
'cachify',
|
237 |
+
array(
|
238 |
+
'only_guests' => 1,
|
239 |
+
'compress_html' => 0,
|
240 |
+
'cache_expires' => 12,
|
241 |
+
'without_ids' => '',
|
242 |
+
'without_agents' => ''
|
243 |
+
),
|
244 |
+
'',
|
245 |
+
'no'
|
246 |
+
);
|
247 |
+
|
248 |
+
/* Flush */
|
249 |
+
self::_flush_cache();
|
250 |
+
}
|
251 |
+
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Uninstallation des Plugins pro MU-Blog
|
255 |
+
*
|
256 |
+
* @since 1.0
|
257 |
+
* @change 1.0
|
258 |
+
*/
|
259 |
+
|
260 |
+
public static function uninstall()
|
261 |
+
{
|
262 |
+
/* Global */
|
263 |
+
global $wpdb;
|
264 |
+
|
265 |
+
/* Multisite & Network */
|
266 |
+
if ( is_multisite() && !empty($_GET['networkwide']) ) {
|
267 |
+
/* Alter Blog */
|
268 |
+
$old = $wpdb->blogid;
|
269 |
+
|
270 |
+
/* Blog-IDs */
|
271 |
+
$ids = self::_get_blog_ids();
|
272 |
+
|
273 |
+
/* Loopen */
|
274 |
+
foreach ($ids as $id) {
|
275 |
+
switch_to_blog($id);
|
276 |
+
self::_uninstall_backend();
|
277 |
+
}
|
278 |
+
|
279 |
+
/* Wechsel zurück */
|
280 |
+
switch_to_blog($old);
|
281 |
+
} else {
|
282 |
+
self::_uninstall_backend();
|
283 |
+
}
|
284 |
+
}
|
285 |
+
|
286 |
+
|
287 |
+
/**
|
288 |
+
* Uninstallation des Plugins bei MU & Network-Plugin
|
289 |
+
*
|
290 |
+
* @since 1.0
|
291 |
+
* @change 1.0
|
292 |
+
*/
|
293 |
+
|
294 |
+
public static function uninstall_later($id) {
|
295 |
+
/* Global */
|
296 |
+
global $wpdb;
|
297 |
+
|
298 |
+
/* Kein Netzwerk-Plugin */
|
299 |
+
if ( !is_plugin_active_for_network(self::$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 |
+
* Update des Plugins
|
333 |
+
*
|
334 |
+
* @since 1.0
|
335 |
+
* @change 1.0
|
336 |
+
*/
|
337 |
+
|
338 |
+
public static function update()
|
339 |
+
{
|
340 |
+
/* Updaten */
|
341 |
+
self::_update_backend();
|
342 |
+
}
|
343 |
+
|
344 |
+
|
345 |
+
/**
|
346 |
+
* Eigentlicher Update des Plugins
|
347 |
+
*
|
348 |
+
* @since 1.0
|
349 |
+
* @change 1.0
|
350 |
+
*/
|
351 |
+
|
352 |
+
private static function _update_backend()
|
353 |
+
{
|
354 |
+
/* Cache leeren */
|
355 |
+
self::_flush_cache();
|
356 |
+
}
|
357 |
+
|
358 |
+
|
359 |
+
/**
|
360 |
+
* Rückgabe der IDs installierter Blogs
|
361 |
+
*
|
362 |
+
* @since 1.0
|
363 |
+
* @change 1.0
|
364 |
+
*
|
365 |
+
* @return array Blog-IDs
|
366 |
+
*/
|
367 |
+
|
368 |
+
private static function _get_blog_ids()
|
369 |
+
{
|
370 |
+
/* Global */
|
371 |
+
global $wpdb;
|
372 |
+
|
373 |
+
return $wpdb->get_col(
|
374 |
+
$wpdb->prepare("SELECT blog_id FROM `$wpdb->blogs`")
|
375 |
+
);
|
376 |
+
}
|
377 |
+
|
378 |
+
|
379 |
+
/**
|
380 |
+
* Hinzufügen der Action-Links (Einstellungen links)
|
381 |
+
*
|
382 |
+
* @since 1.0
|
383 |
+
* @change 1.0
|
384 |
+
*/
|
385 |
+
|
386 |
+
public static function action_links($data)
|
387 |
+
{
|
388 |
+
/* Rechte? */
|
389 |
+
if ( !current_user_can('manage_options') ) {
|
390 |
+
return $data;
|
391 |
+
}
|
392 |
+
|
393 |
+
return array_merge(
|
394 |
+
$data,
|
395 |
+
array(
|
396 |
+
sprintf(
|
397 |
+
'<a href="%s">%s</a>',
|
398 |
+
add_query_arg(
|
399 |
+
array(
|
400 |
+
'page' => 'cachify'
|
401 |
+
),
|
402 |
+
admin_url('options-general.php')
|
403 |
+
),
|
404 |
+
__('Settings')
|
405 |
+
)
|
406 |
+
)
|
407 |
+
);
|
408 |
+
}
|
409 |
+
|
410 |
+
|
411 |
+
/**
|
412 |
+
* Meta-Links zum Plugin
|
413 |
+
*
|
414 |
+
* @since 0.5
|
415 |
+
* @change 1.1
|
416 |
+
*
|
417 |
+
* @param array $data Bereits vorhandene Links
|
418 |
+
* @param string $page Aktuelle Seite
|
419 |
+
* @return array $data Modifizierte Links
|
420 |
+
*/
|
421 |
+
|
422 |
+
public static function row_meta($data, $page)
|
423 |
+
{
|
424 |
+
if ( $page == self::$base && current_user_can('manage_options') ) {
|
425 |
+
$data = array_merge(
|
426 |
+
$data,
|
427 |
+
array(
|
428 |
+
'<a href="http://flattr.com/thing/114377/Cachify-Handliches-Cache-Plugin-fur-WordPress" target="_blank">Plugin flattern</a>',
|
429 |
+
'<a href="https://plus.google.com/110569673423509816572" target="_blank">Auf Google+ folgen</a>',
|
430 |
+
sprintf(
|
431 |
+
'<a href="%s">Cache leeren</a>',
|
432 |
+
add_query_arg('_cachify', 'flush', 'plugins.php')
|
433 |
+
)
|
434 |
+
)
|
435 |
+
);
|
436 |
+
}
|
437 |
+
|
438 |
+
return $data;
|
439 |
+
}
|
440 |
+
|
441 |
+
|
442 |
+
/**
|
443 |
+
* Verarbeitung der Plugin-Meta-Aktionen
|
444 |
+
*
|
445 |
+
* @since 0.5
|
446 |
+
* @change 1.1
|
447 |
+
*
|
448 |
+
* @param array $data Metadaten der Plugins
|
449 |
+
*/
|
450 |
+
|
451 |
+
public static function receive_flush($data)
|
452 |
+
{
|
453 |
+
/* Leer? */
|
454 |
+
if ( empty($_GET['_cachify']) or $_GET['_cachify'] !== 'flush' ) {
|
455 |
+
return;
|
456 |
+
}
|
457 |
+
|
458 |
+
/* Global */
|
459 |
+
global $wpdb;
|
460 |
+
|
461 |
+
/* Multisite & Network */
|
462 |
+
if ( is_multisite() && is_plugin_active_for_network(self::$base) ) {
|
463 |
+
/* Alter Blog */
|
464 |
+
$old = $wpdb->blogid;
|
465 |
+
|
466 |
+
/* Blog-IDs */
|
467 |
+
$ids = self::_get_blog_ids();
|
468 |
+
|
469 |
+
/* Loopen */
|
470 |
+
foreach ($ids as $id) {
|
471 |
+
switch_to_blog($id);
|
472 |
+
self::_flush_cache();
|
473 |
+
}
|
474 |
+
|
475 |
+
/* Wechsel zurück */
|
476 |
+
switch_to_blog($old);
|
477 |
+
} else {
|
478 |
+
self::_flush_cache();
|
479 |
+
}
|
480 |
+
}
|
481 |
+
|
482 |
+
|
483 |
+
/**
|
484 |
+
* Löschung des Cache bei neuem Kommentar
|
485 |
+
*
|
486 |
+
* @since 0.1
|
487 |
+
* @change 0.4
|
488 |
+
*
|
489 |
+
* @param integer $id ID des Kommentars
|
490 |
+
*/
|
491 |
+
|
492 |
+
public static function edit_comment($id)
|
493 |
+
{
|
494 |
+
self::_delete_cache(
|
495 |
+
get_permalink(
|
496 |
+
get_comment($id)->comment_post_ID
|
497 |
+
)
|
498 |
+
);
|
499 |
+
}
|
500 |
+
|
501 |
+
|
502 |
+
/**
|
503 |
+
* Löschung des Cache bei neuem Kommentar
|
504 |
+
*
|
505 |
+
* @since 0.1
|
506 |
+
* @change 0.1
|
507 |
+
*
|
508 |
+
* @param array $comment Array mit Eigenschaften
|
509 |
+
* @return array $comment Array mit Eigenschaften
|
510 |
+
*/
|
511 |
+
|
512 |
+
public static function add_comment($comment)
|
513 |
+
{
|
514 |
+
self::_delete_cache(
|
515 |
+
get_permalink($comment['comment_post_ID'])
|
516 |
+
);
|
517 |
+
|
518 |
+
return $comment;
|
519 |
+
}
|
520 |
+
|
521 |
+
|
522 |
+
/**
|
523 |
+
* Löschung des Cache beim Kommentar-Editieren
|
524 |
+
*
|
525 |
+
* @since 0.1
|
526 |
+
* @change 0.4
|
527 |
+
*
|
528 |
+
* @param string $new_status Neuer Status
|
529 |
+
* @param string $old_status Alter Status
|
530 |
+
* @param object $comment Array mit Eigenschaften
|
531 |
+
*/
|
532 |
+
|
533 |
+
public static function touch_comment($new_status, $old_status, $comment)
|
534 |
+
{
|
535 |
+
if ( $new_status != $old_status ) {
|
536 |
+
self::_delete_cache(
|
537 |
+
get_permalink($comment->comment_post_ID)
|
538 |
+
);
|
539 |
+
}
|
540 |
+
}
|
541 |
+
|
542 |
+
|
543 |
+
/**
|
544 |
+
* Leerung des kompletten Cache
|
545 |
+
*
|
546 |
+
* @since 0.1
|
547 |
+
* @change 0.9.1
|
548 |
+
*
|
549 |
+
* @param intval $id ID des Beitrags
|
550 |
+
*/
|
551 |
+
|
552 |
+
public static function publish_post($id)
|
553 |
+
{
|
554 |
+
/* Post */
|
555 |
+
$post = get_post($id);
|
556 |
+
|
557 |
+
/* Löschen */
|
558 |
+
if ( in_array( $post->post_status, array('publish', 'future') ) ) {
|
559 |
+
self::_flush_cache();
|
560 |
+
}
|
561 |
+
}
|
562 |
+
|
563 |
+
|
564 |
+
/**
|
565 |
+
* Leerung des kompletten Cache
|
566 |
+
*
|
567 |
+
* @since 1.0
|
568 |
+
* @change 1.0
|
569 |
+
*
|
570 |
+
* @param intval $id ID des Beitrags
|
571 |
+
*/
|
572 |
+
|
573 |
+
public static function publish_page($id)
|
574 |
+
{
|
575 |
+
/* Page */
|
576 |
+
$page = get_page($id);
|
577 |
+
|
578 |
+
/* Löschen */
|
579 |
+
if ( $page->post_status == 'publish' ) {
|
580 |
+
self::_flush_cache();
|
581 |
+
}
|
582 |
+
}
|
583 |
+
|
584 |
+
|
585 |
+
/**
|
586 |
+
* Rückgabe des Cache-Hash-Wertes
|
587 |
+
*
|
588 |
+
* @since 0.1
|
589 |
+
* @change 1.0
|
590 |
+
*
|
591 |
+
* @param string $url URL für den Hash-Wert [optional]
|
592 |
+
* @return string Cachify-Hash-Wert
|
593 |
+
*/
|
594 |
+
|
595 |
+
private static function _cache_hash($url = '')
|
596 |
+
{
|
597 |
+
/* Leer? */
|
598 |
+
if ( empty($url) ) {
|
599 |
+
$url = esc_url_raw(
|
600 |
+
sprintf(
|
601 |
+
'%s://%s%s',
|
602 |
+
(is_ssl() ? 'https' : 'http'),
|
603 |
+
$_SERVER['HTTP_HOST'],
|
604 |
+
$_SERVER['REQUEST_URI']
|
605 |
+
)
|
606 |
+
);
|
607 |
+
}
|
608 |
+
|
609 |
+
return 'cachify_' .md5($url);
|
610 |
+
}
|
611 |
+
|
612 |
+
|
613 |
+
/**
|
614 |
+
* Rückgabe der Query-Anzahl
|
615 |
+
*
|
616 |
+
* @since 0.1
|
617 |
+
* @change 1.0
|
618 |
+
*
|
619 |
+
* @return intval Query-Anzahl
|
620 |
+
*/
|
621 |
+
|
622 |
+
private static function _page_queries()
|
623 |
+
{
|
624 |
+
return $GLOBALS['wpdb']->num_queries;
|
625 |
+
}
|
626 |
+
|
627 |
+
|
628 |
+
/**
|
629 |
+
* Rückgabe der Ausführungszeit
|
630 |
+
*
|
631 |
+
* @since 0.1
|
632 |
+
* @change 1.0
|
633 |
+
*
|
634 |
+
* @return intval Anzahl der Sekunden
|
635 |
+
*/
|
636 |
+
|
637 |
+
private static function _page_timer()
|
638 |
+
{
|
639 |
+
return timer_stop(0, 2);
|
640 |
+
}
|
641 |
+
|
642 |
+
|
643 |
+
/**
|
644 |
+
* Rückgabe des Speicherverbrauchs
|
645 |
+
*
|
646 |
+
* @since 0.7
|
647 |
+
* @change 1.0
|
648 |
+
*
|
649 |
+
* @return string Konvertierter Größenwert
|
650 |
+
*/
|
651 |
+
|
652 |
+
private static function _memory_usage()
|
653 |
+
{
|
654 |
+
return ( function_exists('memory_get_usage') ? size_format(memory_get_usage(), 2) : 0 );
|
655 |
+
}
|
656 |
+
|
657 |
+
|
658 |
+
/**
|
659 |
+
* Splittung nach Komma
|
660 |
+
*
|
661 |
+
* @since 0.9.1
|
662 |
+
* @change 1.0
|
663 |
+
*
|
664 |
+
* @param string $input Zu splittende Zeichenkette
|
665 |
+
* @return array Konvertierter Array
|
666 |
+
*/
|
667 |
+
|
668 |
+
private static function _preg_split($input)
|
669 |
+
{
|
670 |
+
return (array)preg_split('/,/', $input, -1, PREG_SPLIT_NO_EMPTY);
|
671 |
+
}
|
672 |
+
|
673 |
+
|
674 |
+
/**
|
675 |
+
* Prüfung auf Index
|
676 |
+
*
|
677 |
+
* @since 0.6
|
678 |
+
* @change 1.0
|
679 |
+
*
|
680 |
+
* @return boolean TRUE bei Index
|
681 |
+
*/
|
682 |
+
|
683 |
+
private static function _is_index()
|
684 |
+
{
|
685 |
+
return basename($_SERVER['SCRIPT_NAME']) != 'index.php';
|
686 |
+
}
|
687 |
+
|
688 |
+
|
689 |
+
/**
|
690 |
+
* Prüfung auf Mobile Devices
|
691 |
+
*
|
692 |
+
* @since 0.9.1
|
693 |
+
* @change 1.0
|
694 |
+
*
|
695 |
+
* @return boolean TRUE bei Mobile
|
696 |
+
*/
|
697 |
+
|
698 |
+
private static function _is_mobile()
|
699 |
+
{
|
700 |
+
return ( strpos(TEMPLATEPATH, 'wptouch') or strpos(TEMPLATEPATH, 'carrington') );
|
701 |
+
}
|
702 |
+
|
703 |
+
|
704 |
+
/**
|
705 |
+
* Definition der Ausnahmen für den Cache
|
706 |
+
*
|
707 |
+
* @since 0.2
|
708 |
+
* @change 1.0
|
709 |
+
*
|
710 |
+
* @param string $type Typ der Abfrage [optional]
|
711 |
+
* @return boolean TRUE bei Ausnahmen
|
712 |
+
*/
|
713 |
+
|
714 |
+
private static function _skip_cache()
|
715 |
+
{
|
716 |
+
/* Optionen */
|
717 |
+
$options = get_option('cachify');
|
718 |
+
|
719 |
+
/* Filter */
|
720 |
+
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() ) ) {
|
721 |
+
return true;
|
722 |
+
}
|
723 |
+
|
724 |
+
/* WP Touch */
|
725 |
+
if ( self::_is_mobile() ) {
|
726 |
+
return true;
|
727 |
+
}
|
728 |
+
|
729 |
+
/* Post IDs */
|
730 |
+
if ( $options['without_ids'] && is_singular() ) {
|
731 |
+
if ( in_array( $GLOBALS['wp_query']->get_queried_object_id(), self::_preg_split($options['without_ids']) ) ) {
|
732 |
+
return true;
|
733 |
+
}
|
734 |
+
}
|
735 |
+
|
736 |
+
/* User Agents */
|
737 |
+
if ( $options['without_agents'] && isset($_SERVER['HTTP_USER_AGENT']) ) {
|
738 |
+
if ( array_filter( self::_preg_split($options['without_agents']), create_function('$a', 'return strpos($_SERVER["HTTP_USER_AGENT"], $a);') ) ) {
|
739 |
+
return true;
|
740 |
+
}
|
741 |
+
}
|
742 |
+
|
743 |
+
return false;
|
744 |
+
}
|
745 |
+
|
746 |
+
|
747 |
+
/**
|
748 |
+
* Komprimiert den HTML-Code
|
749 |
+
*
|
750 |
+
* @since 0.9.2
|
751 |
+
* @change 1.0
|
752 |
+
*
|
753 |
+
* @param string $data Zu komprimierende Datensatz
|
754 |
+
* @return string $data Komprimierter Datensatz
|
755 |
+
*/
|
756 |
+
|
757 |
+
private static function _sanitize_cache($data) {
|
758 |
+
/* Optionen */
|
759 |
+
$options = get_option('cachify');
|
760 |
+
|
761 |
+
/* Komprimieren? */
|
762 |
+
if ( !$options['compress_html'] ) {
|
763 |
+
return($data);
|
764 |
+
}
|
765 |
+
|
766 |
+
/* Verkleinern */
|
767 |
+
$cleaned = preg_replace(
|
768 |
+
array(
|
769 |
+
'/\<!--.+?--\>/s',
|
770 |
+
'/\>(\s)+(\S)/s',
|
771 |
+
'/\>[^\S ]+/s',
|
772 |
+
'/[^\S ]+\</s',
|
773 |
+
'/\>(\s)+/s',
|
774 |
+
'/(\s)+\</s',
|
775 |
+
'/\>\s+\</s'
|
776 |
+
),
|
777 |
+
array(
|
778 |
+
'',
|
779 |
+
'>\\1\\2',
|
780 |
+
'>',
|
781 |
+
'<',
|
782 |
+
'>\\1',
|
783 |
+
'\\1<',
|
784 |
+
'><'
|
785 |
+
),
|
786 |
+
(string)$data
|
787 |
+
);
|
788 |
+
|
789 |
+
/* Fehlerhaft? */
|
790 |
+
if ( strlen($cleaned) <= 1 ) {
|
791 |
+
return($data);
|
792 |
+
}
|
793 |
+
|
794 |
+
return($cleaned);
|
795 |
+
}
|
796 |
+
|
797 |
+
|
798 |
+
/**
|
799 |
+
* Löschung des Cache für eine URL
|
800 |
+
*
|
801 |
+
* @since 0.1
|
802 |
+
* @change 1.0
|
803 |
+
*
|
804 |
+
* @param string $url URL für den Hash-Wert
|
805 |
+
*/
|
806 |
+
|
807 |
+
private static function _delete_cache($url)
|
808 |
+
{
|
809 |
+
delete_transient(
|
810 |
+
self::_cache_hash($url)
|
811 |
+
);
|
812 |
+
}
|
813 |
+
|
814 |
+
|
815 |
+
/**
|
816 |
+
* Zurücksetzen des kompletten Cache
|
817 |
+
*
|
818 |
+
* @since 0.1
|
819 |
+
* @change 1.0
|
820 |
+
*/
|
821 |
+
|
822 |
+
private static function _flush_cache()
|
823 |
+
{
|
824 |
+
$GLOBALS['wpdb']->query("DELETE FROM `" .$GLOBALS['wpdb']->options. "` WHERE `option_name` LIKE ('_transient%_cachify_%')");
|
825 |
+
$GLOBALS['wpdb']->query("OPTIMIZE TABLE `" .$GLOBALS['wpdb']->options. "`");
|
826 |
+
}
|
827 |
+
|
828 |
+
|
829 |
+
/**
|
830 |
+
* Zuweisung des Cache
|
831 |
+
*
|
832 |
+
* @since 0.1
|
833 |
+
* @change 1.0
|
834 |
+
*
|
835 |
+
* @param string $data Inhalt der Seite
|
836 |
+
* @return string $data Inhalt der Seite
|
837 |
+
*/
|
838 |
+
|
839 |
+
public static function set_cache($data)
|
840 |
+
{
|
841 |
+
/* Optionen */
|
842 |
+
$options = get_option('cachify');
|
843 |
+
|
844 |
+
/* Speichern */
|
845 |
+
if ( !empty($data) ) {
|
846 |
+
set_transient(
|
847 |
+
self::_cache_hash(),
|
848 |
+
array(
|
849 |
+
'data' => self::_sanitize_cache($data),
|
850 |
+
'queries' => self::_page_queries(),
|
851 |
+
'timer' => self::_page_timer(),
|
852 |
+
'memory' => self::_memory_usage(),
|
853 |
+
'time' => current_time('timestamp')
|
854 |
+
),
|
855 |
+
60 * 60 * (int)$options['cache_expires']
|
856 |
+
);
|
857 |
+
}
|
858 |
+
|
859 |
+
return $data;
|
860 |
+
}
|
861 |
+
|
862 |
+
|
863 |
+
/**
|
864 |
+
* Verwaltung des Cache
|
865 |
+
*
|
866 |
+
* @since 0.1
|
867 |
+
* @change 0.9
|
868 |
+
*/
|
869 |
+
|
870 |
+
public static function manage_cache()
|
871 |
+
{
|
872 |
+
/* Kein Cache? */
|
873 |
+
if ( self::_skip_cache() ) {
|
874 |
+
return;
|
875 |
+
}
|
876 |
+
|
877 |
+
/* Im Cache? */
|
878 |
+
if ( $cache = get_transient(self::_cache_hash()) ) {
|
879 |
+
if ( !empty($cache['data']) ) {
|
880 |
+
/* Content */
|
881 |
+
echo $cache['data'];
|
882 |
+
|
883 |
+
/* Signatur */
|
884 |
+
echo sprintf(
|
885 |
+
"\n\n<!--\n%s\n%s\n%s\n%s\n-->",
|
886 |
+
'Cachify für WordPress | http://bit.ly/cachify',
|
887 |
+
sprintf(
|
888 |
+
'Ohne Cachify: %d DB-Anfragen, %s Sekunden, %s',
|
889 |
+
$cache['queries'],
|
890 |
+
$cache['timer'],
|
891 |
+
$cache['memory']
|
892 |
+
),
|
893 |
+
sprintf(
|
894 |
+
'Mit Cachify: %d DB-Anfragen, %s Sekunden, %s',
|
895 |
+
self::_page_queries(),
|
896 |
+
self::_page_timer(),
|
897 |
+
self::_memory_usage()
|
898 |
+
),
|
899 |
+
sprintf(
|
900 |
+
'Generiert: %s zuvor',
|
901 |
+
human_time_diff($cache['time'], current_time('timestamp'))
|
902 |
+
)
|
903 |
+
);
|
904 |
+
|
905 |
+
exit;
|
906 |
+
}
|
907 |
+
}
|
908 |
+
|
909 |
+
/* Cachen */
|
910 |
+
ob_start('Cachify::set_cache');
|
911 |
+
}
|
912 |
+
|
913 |
+
|
914 |
+
/**
|
915 |
+
* Einbindung von CSS
|
916 |
+
*
|
917 |
+
* @since 1.0
|
918 |
+
* @change 1.1
|
919 |
+
*/
|
920 |
+
|
921 |
+
function add_css()
|
922 |
+
{
|
923 |
+
/* Infos auslesen */
|
924 |
+
$data = get_plugin_data(__FILE__);
|
925 |
+
|
926 |
+
/* CSS registrieren */
|
927 |
+
wp_register_style(
|
928 |
+
'cachify_css',
|
929 |
+
plugins_url('css/style.css', __FILE__),
|
930 |
+
array(),
|
931 |
+
$data['Version']
|
932 |
+
);
|
933 |
+
|
934 |
+
/* CSS einbinden */
|
935 |
+
wp_enqueue_style('cachify_css');
|
936 |
+
}
|
937 |
+
|
938 |
+
|
939 |
+
/**
|
940 |
+
* Einfüger der Optionsseite
|
941 |
+
*
|
942 |
+
* @since 1.0
|
943 |
+
* @change 1.0
|
944 |
+
*/
|
945 |
+
|
946 |
+
function add_page()
|
947 |
+
{
|
948 |
+
add_options_page(
|
949 |
+
'Cachify',
|
950 |
+
'<img src="' .plugins_url('cachify/img/icon.png'). '" alt="Cachify" />Cachify',
|
951 |
+
'manage_options',
|
952 |
+
'cachify',
|
953 |
+
array(
|
954 |
+
__CLASS__,
|
955 |
+
'options_page'
|
956 |
+
)
|
957 |
+
);
|
958 |
+
}
|
959 |
+
|
960 |
+
|
961 |
+
/**
|
962 |
+
* Anzeige des Hilfe-Links
|
963 |
+
*
|
964 |
+
* @since 1.1
|
965 |
+
* @change 1.1
|
966 |
+
*
|
967 |
+
* @param string $anchor Anker in der Hilfe
|
968 |
+
*/
|
969 |
+
|
970 |
+
function help_link($anchor) {
|
971 |
+
echo sprintf(
|
972 |
+
'<span>[<a href="http://playground.ebiene.de/2652/cachify-wordpress-cache/#%s" target="_blank">?</a>]</span>',
|
973 |
+
$anchor
|
974 |
+
);
|
975 |
+
}
|
976 |
+
|
977 |
+
|
978 |
+
/**
|
979 |
+
* Registrierung der Settings
|
980 |
+
*
|
981 |
+
* @since 1.0
|
982 |
+
* @change 1.0
|
983 |
+
*/
|
984 |
+
|
985 |
+
function register_settings()
|
986 |
+
{
|
987 |
+
register_setting(
|
988 |
+
'cachify',
|
989 |
+
'cachify',
|
990 |
+
array(
|
991 |
+
__CLASS__,
|
992 |
+
'validate_options'
|
993 |
+
)
|
994 |
+
);
|
995 |
+
}
|
996 |
+
|
997 |
+
|
998 |
+
/**
|
999 |
+
* Valisierung der Optionsseite
|
1000 |
+
*
|
1001 |
+
* @since 1.0
|
1002 |
+
* @change 1.0
|
1003 |
+
*
|
1004 |
+
* @param array $data Array mit Formularwerten
|
1005 |
+
* @return array Array mit geprüften Werten
|
1006 |
+
*/
|
1007 |
+
|
1008 |
+
public static function validate_options($data)
|
1009 |
+
{
|
1010 |
+
/* Cache leeren */
|
1011 |
+
self::_flush_cache();
|
1012 |
+
|
1013 |
+
return array(
|
1014 |
+
'only_guests' => (int)(!empty($data['only_guests'])),
|
1015 |
+
'compress_html' => (int)(!empty($data['compress_html'])),
|
1016 |
+
'cache_expires' => (int)(@$data['cache_expires']),
|
1017 |
+
'without_ids' => (string)sanitize_text_field(@$data['without_ids']),
|
1018 |
+
'without_agents' => (string)sanitize_text_field(@$data['without_agents'])
|
1019 |
+
);
|
1020 |
+
}
|
1021 |
+
|
1022 |
+
|
1023 |
+
/**
|
1024 |
+
* Darstellung der Optionsseite
|
1025 |
+
*
|
1026 |
+
* @since 1.0
|
1027 |
+
* @change 1.0
|
1028 |
+
*/
|
1029 |
+
|
1030 |
+
public static function options_page()
|
1031 |
+
{ ?>
|
1032 |
+
<div class="wrap">
|
1033 |
+
<?php screen_icon('cachify') ?>
|
1034 |
+
|
1035 |
+
<h2>
|
1036 |
+
Cachify
|
1037 |
+
</h2>
|
1038 |
+
|
1039 |
+
<form method="post" action="options.php">
|
1040 |
+
<?php settings_fields('cachify') ?>
|
1041 |
+
|
1042 |
+
<?php $options = get_option('cachify') ?>
|
1043 |
+
|
1044 |
+
<table class="form-table cachify">
|
1045 |
+
<tr>
|
1046 |
+
<th>
|
1047 |
+
Cache-Gültigkeit in Stunden <?php self::help_link('cache_expires') ?>
|
1048 |
+
</th>
|
1049 |
+
<td>
|
1050 |
+
<input type="text" name="cachify[cache_expires]" value="<?php echo $options['cache_expires'] ?>" />
|
1051 |
+
</td>
|
1052 |
+
</tr>
|
1053 |
+
|
1054 |
+
<tr>
|
1055 |
+
<th>
|
1056 |
+
Ausnahme für (Post/Pages) IDs <?php self::help_link('without_ids') ?>
|
1057 |
+
</th>
|
1058 |
+
<td>
|
1059 |
+
<input type="text" name="cachify[without_ids]" value="<?php echo $options['without_ids'] ?>" />
|
1060 |
+
</td>
|
1061 |
+
</tr>
|
1062 |
+
|
1063 |
+
<tr>
|
1064 |
+
<th>
|
1065 |
+
Ausnahme für User Agents <?php self::help_link('without_agents') ?>
|
1066 |
+
</th>
|
1067 |
+
<td>
|
1068 |
+
<input type="text" name="cachify[without_agents]" value="<?php echo $options['without_agents'] ?>" />
|
1069 |
+
</td>
|
1070 |
+
</tr>
|
1071 |
+
|
1072 |
+
<tr>
|
1073 |
+
<th>
|
1074 |
+
Komprimierung der Ausgabe <?php self::help_link('compress_html') ?>
|
1075 |
+
</th>
|
1076 |
+
<td>
|
1077 |
+
<input type="checkbox" name="cachify[compress_html]" value="1" <?php checked('1', $options['compress_html']); ?> />
|
1078 |
+
</td>
|
1079 |
+
</tr>
|
1080 |
+
|
1081 |
+
<tr>
|
1082 |
+
<th>
|
1083 |
+
Nur für nicht eingeloggte Nutzer <?php self::help_link('only_guests') ?>
|
1084 |
+
</th>
|
1085 |
+
<td>
|
1086 |
+
<input type="checkbox" name="cachify[only_guests]" value="1" <?php checked('1', $options['only_guests']); ?> />
|
1087 |
+
</td>
|
1088 |
+
</tr>
|
1089 |
+
</table>
|
1090 |
+
|
1091 |
+
<p class="submit">
|
1092 |
+
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
|
1093 |
+
</p>
|
1094 |
+
</form>
|
1095 |
+
</div><?php
|
1096 |
+
}
|
1097 |
+
}
|
1098 |
+
|
1099 |
+
|
1100 |
+
/* Fire */
|
1101 |
+
add_action(
|
1102 |
+
'plugins_loaded',
|
1103 |
+
array(
|
1104 |
+
'Cachify',
|
1105 |
+
'init'
|
1106 |
+
),
|
1107 |
+
99
|
1108 |
+
);
|
1109 |
+
|
1110 |
+
|
1111 |
+
/* Install */
|
1112 |
+
register_activation_hook(
|
1113 |
+
__FILE__,
|
1114 |
+
array(
|
1115 |
+
'Cachify',
|
1116 |
+
'install'
|
1117 |
+
)
|
1118 |
+
);
|
1119 |
+
|
1120 |
+
/* Uninstall */
|
1121 |
+
register_uninstall_hook(
|
1122 |
+
__FILE__,
|
1123 |
+
array(
|
1124 |
+
'Cachify',
|
1125 |
+
'uninstall'
|
1126 |
+
)
|
1127 |
+
);
|
1128 |
+
|
1129 |
+
/* Updaten */
|
1130 |
+
if ( function_exists('register_update_hook') ) {
|
1131 |
+
register_update_hook(
|
1132 |
+
__FILE__,
|
1133 |
+
array(
|
1134 |
+
'Cachify',
|
1135 |
+
'update'
|
1136 |
+
)
|
1137 |
+
);
|
1138 |
+
}
|
cachify.php
ADDED
@@ -0,0 +1,602 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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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://www.wpSEO.de
|
7 |
+
Plugin URI: http://playground.ebiene.de/2652/cachify-wordpress-cache/
|
8 |
+
Version: 1.1
|
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 |
+
private static $menu;
|
20 |
+
public static function init()
|
21 |
+
{
|
22 |
+
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
|
23 |
+
return;
|
24 |
+
}
|
25 |
+
self::$base = plugin_basename(__FILE__);
|
26 |
+
add_action(
|
27 |
+
'publish_post',
|
28 |
+
array(
|
29 |
+
__CLASS__,
|
30 |
+
'publish_post'
|
31 |
+
)
|
32 |
+
);
|
33 |
+
add_action(
|
34 |
+
'publish_page',
|
35 |
+
array(
|
36 |
+
__CLASS__,
|
37 |
+
'publish_page'
|
38 |
+
)
|
39 |
+
);
|
40 |
+
if ( is_admin() ) {
|
41 |
+
add_action(
|
42 |
+
'pre_current_active_plugins',
|
43 |
+
array(
|
44 |
+
__CLASS__,
|
45 |
+
'receive_flush'
|
46 |
+
)
|
47 |
+
);
|
48 |
+
add_action(
|
49 |
+
'wpmu_new_blog',
|
50 |
+
array(
|
51 |
+
__CLASS__,
|
52 |
+
'install_later'
|
53 |
+
)
|
54 |
+
);
|
55 |
+
add_action(
|
56 |
+
'delete_blog',
|
57 |
+
array(
|
58 |
+
__CLASS__,
|
59 |
+
'uninstall_later'
|
60 |
+
)
|
61 |
+
);
|
62 |
+
add_action(
|
63 |
+
'admin_init',
|
64 |
+
array(
|
65 |
+
__CLASS__,
|
66 |
+
'register_settings'
|
67 |
+
)
|
68 |
+
);
|
69 |
+
add_action(
|
70 |
+
'admin_menu',
|
71 |
+
array(
|
72 |
+
__CLASS__,
|
73 |
+
'add_page'
|
74 |
+
)
|
75 |
+
);
|
76 |
+
add_action(
|
77 |
+
'admin_print_styles',
|
78 |
+
array(
|
79 |
+
__CLASS__,
|
80 |
+
'add_css'
|
81 |
+
)
|
82 |
+
);
|
83 |
+
add_action(
|
84 |
+
'transition_comment_status',
|
85 |
+
array(
|
86 |
+
__CLASS__,
|
87 |
+
'touch_comment'
|
88 |
+
),
|
89 |
+
10,
|
90 |
+
3
|
91 |
+
);
|
92 |
+
add_action(
|
93 |
+
'edit_comment',
|
94 |
+
array(
|
95 |
+
__CLASS__,
|
96 |
+
'edit_comment'
|
97 |
+
)
|
98 |
+
);
|
99 |
+
add_filter(
|
100 |
+
'plugin_row_meta',
|
101 |
+
array(
|
102 |
+
__CLASS__,
|
103 |
+
'row_meta'
|
104 |
+
),
|
105 |
+
10,
|
106 |
+
2
|
107 |
+
);
|
108 |
+
add_filter(
|
109 |
+
'plugin_action_links_' .self::$base,
|
110 |
+
array(
|
111 |
+
__CLASS__,
|
112 |
+
'action_links'
|
113 |
+
)
|
114 |
+
);
|
115 |
+
} else {
|
116 |
+
add_action(
|
117 |
+
'preprocess_comment',
|
118 |
+
array(
|
119 |
+
__CLASS__,
|
120 |
+
'add_comment'
|
121 |
+
),
|
122 |
+
1
|
123 |
+
);
|
124 |
+
add_action(
|
125 |
+
'template_redirect',
|
126 |
+
array(
|
127 |
+
__CLASS__,
|
128 |
+
'manage_cache'
|
129 |
+
),
|
130 |
+
99
|
131 |
+
);
|
132 |
+
}
|
133 |
+
}
|
134 |
+
public static function install()
|
135 |
+
{
|
136 |
+
global $wpdb;
|
137 |
+
if ( is_multisite() && !empty($_GET['networkwide']) ) {
|
138 |
+
$ids = self::_get_blog_ids();
|
139 |
+
foreach ($ids as $id) {
|
140 |
+
switch_to_blog( (int)$id );
|
141 |
+
self::_install_backend();
|
142 |
+
}
|
143 |
+
restore_current_blog();
|
144 |
+
} else {
|
145 |
+
self::_install_backend();
|
146 |
+
}
|
147 |
+
}
|
148 |
+
public static function install_later($id) {
|
149 |
+
if ( !is_plugin_active_for_network(self::$base) ) {
|
150 |
+
return;
|
151 |
+
}
|
152 |
+
switch_to_blog( (int)$id );
|
153 |
+
self::_install_backend();
|
154 |
+
restore_current_blog();
|
155 |
+
}
|
156 |
+
private static function _install_backend()
|
157 |
+
{
|
158 |
+
add_option(
|
159 |
+
'cachify',
|
160 |
+
array(
|
161 |
+
'only_guests'=> 1,
|
162 |
+
'compress_html'=> 0,
|
163 |
+
'cache_expires'=> 12,
|
164 |
+
'without_ids'=> '',
|
165 |
+
'without_agents' => ''
|
166 |
+
),
|
167 |
+
'',
|
168 |
+
'no'
|
169 |
+
);
|
170 |
+
self::_flush_cache();
|
171 |
+
}
|
172 |
+
public static function uninstall()
|
173 |
+
{
|
174 |
+
global $wpdb;
|
175 |
+
if ( is_multisite() && !empty($_GET['networkwide']) ) {
|
176 |
+
$old = $wpdb->blogid;
|
177 |
+
$ids = self::_get_blog_ids();
|
178 |
+
foreach ($ids as $id) {
|
179 |
+
switch_to_blog($id);
|
180 |
+
self::_uninstall_backend();
|
181 |
+
}
|
182 |
+
switch_to_blog($old);
|
183 |
+
} else {
|
184 |
+
self::_uninstall_backend();
|
185 |
+
}
|
186 |
+
}
|
187 |
+
public static function uninstall_later($id) {
|
188 |
+
global $wpdb;
|
189 |
+
if ( !is_plugin_active_for_network(self::$base) ) {
|
190 |
+
return;
|
191 |
+
}
|
192 |
+
switch_to_blog( (int)$id );
|
193 |
+
self::_uninstall_backend();
|
194 |
+
restore_current_blog();
|
195 |
+
}
|
196 |
+
private static function _uninstall_backend()
|
197 |
+
{
|
198 |
+
delete_option('cachify');
|
199 |
+
self::_flush_cache();
|
200 |
+
}
|
201 |
+
public static function update()
|
202 |
+
{
|
203 |
+
self::_update_backend();
|
204 |
+
}
|
205 |
+
private static function _update_backend()
|
206 |
+
{
|
207 |
+
self::_flush_cache();
|
208 |
+
}
|
209 |
+
private static function _get_blog_ids()
|
210 |
+
{
|
211 |
+
global $wpdb;
|
212 |
+
return $wpdb->get_col(
|
213 |
+
$wpdb->prepare("SELECT blog_id FROM `$wpdb->blogs`")
|
214 |
+
);
|
215 |
+
}
|
216 |
+
public static function action_links($data)
|
217 |
+
{
|
218 |
+
if ( !current_user_can('manage_options') ) {
|
219 |
+
return $data;
|
220 |
+
}
|
221 |
+
return array_merge(
|
222 |
+
$data,
|
223 |
+
array(
|
224 |
+
sprintf(
|
225 |
+
'<a href="%s">%s</a>',
|
226 |
+
add_query_arg(
|
227 |
+
array(
|
228 |
+
'page' => 'cachify'
|
229 |
+
),
|
230 |
+
admin_url('options-general.php')
|
231 |
+
),
|
232 |
+
__('Settings')
|
233 |
+
)
|
234 |
+
)
|
235 |
+
);
|
236 |
+
}
|
237 |
+
public static function row_meta($data, $page)
|
238 |
+
{
|
239 |
+
if ( $page == self::$base && current_user_can('manage_options') ) {
|
240 |
+
$data = array_merge(
|
241 |
+
$data,
|
242 |
+
array(
|
243 |
+
'<a href="http://flattr.com/thing/114377/Cachify-Handliches-Cache-Plugin-fur-WordPress" target="_blank">Plugin flattern</a>',
|
244 |
+
'<a href="https://plus.google.com/110569673423509816572" target="_blank">Auf Google+ folgen</a>',
|
245 |
+
sprintf(
|
246 |
+
'<a href="%s">Cache leeren</a>',
|
247 |
+
add_query_arg('_cachify', 'flush', 'plugins.php')
|
248 |
+
)
|
249 |
+
)
|
250 |
+
);
|
251 |
+
}
|
252 |
+
return $data;
|
253 |
+
}
|
254 |
+
public static function receive_flush($data)
|
255 |
+
{
|
256 |
+
if ( empty($_GET['_cachify']) or $_GET['_cachify'] !== 'flush' ) {
|
257 |
+
return;
|
258 |
+
}
|
259 |
+
global $wpdb;
|
260 |
+
if ( is_multisite() && is_plugin_active_for_network(self::$base) ) {
|
261 |
+
$old = $wpdb->blogid;
|
262 |
+
$ids = self::_get_blog_ids();
|
263 |
+
foreach ($ids as $id) {
|
264 |
+
switch_to_blog($id);
|
265 |
+
self::_flush_cache();
|
266 |
+
}
|
267 |
+
switch_to_blog($old);
|
268 |
+
} else {
|
269 |
+
self::_flush_cache();
|
270 |
+
}
|
271 |
+
}
|
272 |
+
public static function edit_comment($id)
|
273 |
+
{
|
274 |
+
self::_delete_cache(
|
275 |
+
get_permalink(
|
276 |
+
get_comment($id)->comment_post_ID
|
277 |
+
)
|
278 |
+
);
|
279 |
+
}
|
280 |
+
public static function add_comment($comment)
|
281 |
+
{
|
282 |
+
self::_delete_cache(
|
283 |
+
get_permalink($comment['comment_post_ID'])
|
284 |
+
);
|
285 |
+
return $comment;
|
286 |
+
}
|
287 |
+
public static function touch_comment($new_status, $old_status, $comment)
|
288 |
+
{
|
289 |
+
if ( $new_status != $old_status ) {
|
290 |
+
self::_delete_cache(
|
291 |
+
get_permalink($comment->comment_post_ID)
|
292 |
+
);
|
293 |
+
}
|
294 |
+
}
|
295 |
+
public static function publish_post($id)
|
296 |
+
{
|
297 |
+
$post = get_post($id);
|
298 |
+
if ( in_array( $post->post_status, array('publish', 'future') ) ) {
|
299 |
+
self::_flush_cache();
|
300 |
+
}
|
301 |
+
}
|
302 |
+
public static function publish_page($id)
|
303 |
+
{
|
304 |
+
$page = get_page($id);
|
305 |
+
if ( $page->post_status == 'publish' ) {
|
306 |
+
self::_flush_cache();
|
307 |
+
}
|
308 |
+
}
|
309 |
+
private static function _cache_hash($url = '')
|
310 |
+
{
|
311 |
+
if ( empty($url) ) {
|
312 |
+
$url = esc_url_raw(
|
313 |
+
sprintf(
|
314 |
+
'%s://%s%s',
|
315 |
+
(is_ssl() ? 'https' : 'http'),
|
316 |
+
$_SERVER['HTTP_HOST'],
|
317 |
+
$_SERVER['REQUEST_URI']
|
318 |
+
)
|
319 |
+
);
|
320 |
+
}
|
321 |
+
return 'cachify_' .md5($url);
|
322 |
+
}
|
323 |
+
private static function _page_queries()
|
324 |
+
{
|
325 |
+
return $GLOBALS['wpdb']->num_queries;
|
326 |
+
}
|
327 |
+
private static function _page_timer()
|
328 |
+
{
|
329 |
+
return timer_stop(0, 2);
|
330 |
+
}
|
331 |
+
private static function _memory_usage()
|
332 |
+
{
|
333 |
+
return ( function_exists('memory_get_usage') ? size_format(memory_get_usage(), 2) : 0 );
|
334 |
+
}
|
335 |
+
private static function _preg_split($input)
|
336 |
+
{
|
337 |
+
return (array)preg_split('/,/', $input, -1, PREG_SPLIT_NO_EMPTY);
|
338 |
+
}
|
339 |
+
private static function _is_index()
|
340 |
+
{
|
341 |
+
return basename($_SERVER['SCRIPT_NAME']) != 'index.php';
|
342 |
+
}
|
343 |
+
private static function _is_mobile()
|
344 |
+
{
|
345 |
+
return ( strpos(TEMPLATEPATH, 'wptouch') or strpos(TEMPLATEPATH, 'carrington') );
|
346 |
+
}
|
347 |
+
private static function _skip_cache()
|
348 |
+
{
|
349 |
+
$options = get_option('cachify');
|
350 |
+
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() ) ) {
|
351 |
+
return true;
|
352 |
+
}
|
353 |
+
if ( self::_is_mobile() ) {
|
354 |
+
return true;
|
355 |
+
}
|
356 |
+
if ( $options['without_ids'] && is_singular() ) {
|
357 |
+
if ( in_array( $GLOBALS['wp_query']->get_queried_object_id(), self::_preg_split($options['without_ids']) ) ) {
|
358 |
+
return true;
|
359 |
+
}
|
360 |
+
}
|
361 |
+
if ( $options['without_agents'] && isset($_SERVER['HTTP_USER_AGENT']) ) {
|
362 |
+
if ( array_filter( self::_preg_split($options['without_agents']), create_function('$a', 'return strpos($_SERVER["HTTP_USER_AGENT"], $a);') ) ) {
|
363 |
+
return true;
|
364 |
+
}
|
365 |
+
}
|
366 |
+
return false;
|
367 |
+
}
|
368 |
+
private static function _sanitize_cache($data) {
|
369 |
+
$options = get_option('cachify');
|
370 |
+
if ( !$options['compress_html'] ) {
|
371 |
+
return($data);
|
372 |
+
}
|
373 |
+
$cleaned = preg_replace(
|
374 |
+
array(
|
375 |
+
'/\<!--.+?--\>/s',
|
376 |
+
'/\>(\s)+(\S)/s',
|
377 |
+
'/\>[^\S ]+/s',
|
378 |
+
'/[^\S ]+\</s',
|
379 |
+
'/\>(\s)+/s',
|
380 |
+
'/(\s)+\</s',
|
381 |
+
'/\>\s+\</s'
|
382 |
+
),
|
383 |
+
array(
|
384 |
+
'',
|
385 |
+
'>\\1\\2',
|
386 |
+
'>',
|
387 |
+
'<',
|
388 |
+
'>\\1',
|
389 |
+
'\\1<',
|
390 |
+
'><'
|
391 |
+
),
|
392 |
+
(string)$data
|
393 |
+
);
|
394 |
+
if ( strlen($cleaned) <= 1 ) {
|
395 |
+
return($data);
|
396 |
+
}
|
397 |
+
return($cleaned);
|
398 |
+
}
|
399 |
+
private static function _delete_cache($url)
|
400 |
+
{
|
401 |
+
delete_transient(
|
402 |
+
self::_cache_hash($url)
|
403 |
+
);
|
404 |
+
}
|
405 |
+
private static function _flush_cache()
|
406 |
+
{
|
407 |
+
$GLOBALS['wpdb']->query("DELETE FROM `" .$GLOBALS['wpdb']->options. "` WHERE `option_name` LIKE ('_transient%_cachify_%')");
|
408 |
+
$GLOBALS['wpdb']->query("OPTIMIZE TABLE `" .$GLOBALS['wpdb']->options. "`");
|
409 |
+
}
|
410 |
+
public static function set_cache($data)
|
411 |
+
{
|
412 |
+
$options = get_option('cachify');
|
413 |
+
if ( !empty($data) ) {
|
414 |
+
set_transient(
|
415 |
+
self::_cache_hash(),
|
416 |
+
array(
|
417 |
+
'data'=> self::_sanitize_cache($data),
|
418 |
+
'queries'=> self::_page_queries(),
|
419 |
+
'timer'=> self::_page_timer(),
|
420 |
+
'memory'=> self::_memory_usage(),
|
421 |
+
'time'=> current_time('timestamp')
|
422 |
+
),
|
423 |
+
60 * 60 * (int)$options['cache_expires']
|
424 |
+
);
|
425 |
+
}
|
426 |
+
return $data;
|
427 |
+
}
|
428 |
+
public static function manage_cache()
|
429 |
+
{
|
430 |
+
if ( self::_skip_cache() ) {
|
431 |
+
return;
|
432 |
+
}
|
433 |
+
if ( $cache = get_transient(self::_cache_hash()) ) {
|
434 |
+
if ( !empty($cache['data']) ) {
|
435 |
+
echo $cache['data'];
|
436 |
+
echo sprintf(
|
437 |
+
"\n\n<!--\n%s\n%s\n%s\n%s\n-->",
|
438 |
+
'Cachify für WordPress | http://bit.ly/cachify',
|
439 |
+
sprintf(
|
440 |
+
'Ohne Cachify: %d DB-Anfragen, %s Sekunden, %s',
|
441 |
+
$cache['queries'],
|
442 |
+
$cache['timer'],
|
443 |
+
$cache['memory']
|
444 |
+
),
|
445 |
+
sprintf(
|
446 |
+
'Mit Cachify: %d DB-Anfragen, %s Sekunden, %s',
|
447 |
+
self::_page_queries(),
|
448 |
+
self::_page_timer(),
|
449 |
+
self::_memory_usage()
|
450 |
+
),
|
451 |
+
sprintf(
|
452 |
+
'Generiert: %s zuvor',
|
453 |
+
human_time_diff($cache['time'], current_time('timestamp'))
|
454 |
+
)
|
455 |
+
);
|
456 |
+
exit;
|
457 |
+
}
|
458 |
+
}
|
459 |
+
ob_start('Cachify::set_cache');
|
460 |
+
}
|
461 |
+
function add_css()
|
462 |
+
{
|
463 |
+
$data = get_plugin_data(__FILE__);
|
464 |
+
wp_register_style(
|
465 |
+
'cachify_css',
|
466 |
+
plugins_url('css/style.css', __FILE__),
|
467 |
+
array(),
|
468 |
+
$data['Version']
|
469 |
+
);
|
470 |
+
wp_enqueue_style('cachify_css');
|
471 |
+
}
|
472 |
+
function add_page()
|
473 |
+
{
|
474 |
+
self::$menu = add_options_page(
|
475 |
+
'Cachify',
|
476 |
+
'<img src="' .plugins_url('cachify/img/icon.png'). '" alt="Cachify" />Cachify',
|
477 |
+
'manage_options',
|
478 |
+
'cachify',
|
479 |
+
array(
|
480 |
+
__CLASS__,
|
481 |
+
'options_page'
|
482 |
+
)
|
483 |
+
);
|
484 |
+
}
|
485 |
+
function help_link($anchor) {
|
486 |
+
echo sprintf(
|
487 |
+
'<span>[<a href="http://playground.ebiene.de/2652/cachify-wordpress-cache/#%s" target="_blank">?</a>]</span>',
|
488 |
+
$anchor
|
489 |
+
);
|
490 |
+
}
|
491 |
+
function register_settings()
|
492 |
+
{
|
493 |
+
register_setting(
|
494 |
+
'cachify',
|
495 |
+
'cachify',
|
496 |
+
array(
|
497 |
+
__CLASS__,
|
498 |
+
'validate_options'
|
499 |
+
)
|
500 |
+
);
|
501 |
+
}
|
502 |
+
public static function validate_options($data)
|
503 |
+
{
|
504 |
+
self::_flush_cache();
|
505 |
+
return array(
|
506 |
+
'only_guests'=> (int)(!empty($data['only_guests'])),
|
507 |
+
'compress_html'=> (int)(!empty($data['compress_html'])),
|
508 |
+
'cache_expires'=> (int)(@$data['cache_expires']),
|
509 |
+
'without_ids'=> (string)sanitize_text_field(@$data['without_ids']),
|
510 |
+
'without_agents' => (string)sanitize_text_field(@$data['without_agents'])
|
511 |
+
);
|
512 |
+
}
|
513 |
+
public static function options_page()
|
514 |
+
{ ?>
|
515 |
+
<div class="wrap">
|
516 |
+
<?php screen_icon('cachify') ?>
|
517 |
+
<h2>
|
518 |
+
Cachify
|
519 |
+
</h2>
|
520 |
+
<form method="post" action="options.php">
|
521 |
+
<?php settings_fields('cachify') ?>
|
522 |
+
<?php $options = get_option('cachify') ?>
|
523 |
+
<table class="form-table cachify">
|
524 |
+
<tr>
|
525 |
+
<th>
|
526 |
+
Cache-Gültigkeit in Stunden <?php self::help_link('cache_expires') ?>
|
527 |
+
</th>
|
528 |
+
<td>
|
529 |
+
<input type="text" name="cachify[cache_expires]" value="<?php echo $options['cache_expires'] ?>" />
|
530 |
+
</td>
|
531 |
+
</tr>
|
532 |
+
<tr>
|
533 |
+
<th>
|
534 |
+
Ausnahme für (Post/Pages) IDs <?php self::help_link('without_ids') ?>
|
535 |
+
</th>
|
536 |
+
<td>
|
537 |
+
<input type="text" name="cachify[without_ids]" value="<?php echo $options['without_ids'] ?>" />
|
538 |
+
</td>
|
539 |
+
</tr>
|
540 |
+
<tr>
|
541 |
+
<th>
|
542 |
+
Ausnahme für User Agents <?php self::help_link('without_agents') ?>
|
543 |
+
</th>
|
544 |
+
<td>
|
545 |
+
<input type="text" name="cachify[without_agents]" value="<?php echo $options['without_agents'] ?>" />
|
546 |
+
</td>
|
547 |
+
</tr>
|
548 |
+
<tr>
|
549 |
+
<th>
|
550 |
+
Komprimierung der Ausgabe <?php self::help_link('compress_html') ?>
|
551 |
+
</th>
|
552 |
+
<td>
|
553 |
+
<input type="checkbox" name="cachify[compress_html]" value="1" <?php checked('1', $options['compress_html']); ?> />
|
554 |
+
</td>
|
555 |
+
</tr>
|
556 |
+
<tr>
|
557 |
+
<th>
|
558 |
+
Nur für nicht eingeloggte Nutzer <?php self::help_link('only_guests') ?>
|
559 |
+
</th>
|
560 |
+
<td>
|
561 |
+
<input type="checkbox" name="cachify[only_guests]" value="1" <?php checked('1', $options['only_guests']); ?> />
|
562 |
+
</td>
|
563 |
+
</tr>
|
564 |
+
</table>
|
565 |
+
<p class="submit">
|
566 |
+
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
|
567 |
+
</p>
|
568 |
+
</form>
|
569 |
+
</div><?php
|
570 |
+
}
|
571 |
+
}
|
572 |
+
add_action(
|
573 |
+
'plugins_loaded',
|
574 |
+
array(
|
575 |
+
'Cachify',
|
576 |
+
'init'
|
577 |
+
),
|
578 |
+
99
|
579 |
+
);
|
580 |
+
register_activation_hook(
|
581 |
+
__FILE__,
|
582 |
+
array(
|
583 |
+
'Cachify',
|
584 |
+
'install'
|
585 |
+
)
|
586 |
+
);
|
587 |
+
register_uninstall_hook(
|
588 |
+
__FILE__,
|
589 |
+
array(
|
590 |
+
'Cachify',
|
591 |
+
'uninstall'
|
592 |
+
)
|
593 |
+
);
|
594 |
+
if ( function_exists('register_update_hook') ) {
|
595 |
+
register_update_hook(
|
596 |
+
__FILE__,
|
597 |
+
array(
|
598 |
+
'Cachify',
|
599 |
+
'update'
|
600 |
+
)
|
601 |
+
);
|
602 |
+
}
|
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,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
* Einfache Installation: Aktivieren, fertig
|
17 |
+
* Übersichtliche Optionsseite mit integrierter Hilfe
|
18 |
+
* Optionale Komprimierung der HTML-Ausgabe
|
19 |
+
* Blacklists für PostIDs und User Agents
|
20 |
+
* Bis zu 80 % weniger DB-Anfragen
|
21 |
+
* Bis zu 60 % schnellere Ausführungszeiten
|
22 |
+
* Manueller und automatischer Cache-Reset
|
23 |
+
* Ausgabe der "davor, danach" Informationen im Quelltext
|
24 |
+
|
25 |
+
= Wichtige Information =
|
26 |
+
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!
|
27 |
+
|
28 |
+
= Weiterführende Links =
|
29 |
+
* [Blog](http://playground.ebiene.de "Playground Blog")
|
30 |
+
* [Flattr](http://flattr.com/profile/sergej.mueller "Flattr")
|
31 |
+
* [Google+](https://plus.google.com/110569673423509816572 "Google+")
|
32 |
+
* [Portfolio](http://ebiene.de "Portfolio")
|
33 |
+
* [Andere Plugins](http://wpcoder.de "Andere Plugins")
|
34 |
+
|
35 |
+
|
36 |
+
== Changelog ==
|
37 |
+
= 1.1 =
|
38 |
+
* Interne Prüfung auf fehlerhafte Cache-Generierung
|
39 |
+
* Anpassungen an der Code-Struktur
|
40 |
+
* Entfernung der Inline-Hilfe
|
41 |
+
* Verknüpfung der Online-Hilfe mit Optionen
|
42 |
+
|
43 |
+
= 1.0 =
|
44 |
+
* Leerung des Cache beim Aktualisieren von statischen Seiten
|
45 |
+
* Seite mit Plugin-Einstellungen
|
46 |
+
* Inline-Dokumentation in der Optionsseite
|
47 |
+
* Ausschluss von Passwort-geschützten Seiten
|
48 |
+
* WordPress 3.2 Support
|
49 |
+
* Unterstützung der WordPress Multisite Blogs
|
50 |
+
* Umstellung auf den template_redirect-Hook (Plugin-Kompatibilität)
|
51 |
+
* Interne Code-Bereinigung
|
52 |
+
|
53 |
+
= 0.9.2 =
|
54 |
+
* HTML-Kompression
|
55 |
+
* Flattr-Link
|
56 |
+
|
57 |
+
= 0.9.1 =
|
58 |
+
* Cache-Reset bei geplanten Beiträgen
|
59 |
+
* Unterstützung für das Carrington-Mobile Theme
|
60 |
+
|
61 |
+
= 0.9 =
|
62 |
+
* Workaround für Redirects
|
63 |
+
|
64 |
+
= 0.8 =
|
65 |
+
* Blacklist für PostIDs
|
66 |
+
* Blacklist für UserAgents
|
67 |
+
* Ausnahme für WP Touch
|
68 |
+
* Ausgabe des Zeitpunktes der Generierung
|
69 |
+
* Umbenennung der Konstanten
|
70 |
+
|
71 |
+
= 0.7 =
|
72 |
+
* Ausgabe des Speicherverbrauchs
|
73 |
+
|
74 |
+
= 0.6 =
|
75 |
+
* Live auf wordpress.org
|
76 |
+
|
77 |
+
|
78 |
+
== Screenshots ==
|
79 |
+
|
80 |
+
1. Cachify Optionsseite
|
81 |
+
|
82 |
+
|
83 |
+
== Installation ==
|
84 |
+
1. *Cachify* installieren
|
85 |
+
1. [Dokumentation](http://playground.ebiene.de/2652/cachify-wordpress-cache/ "Cachify WordPress Cache") beachten
|
86 |
+
1. Einstellungen vornehmen
|
screenshot-1.png
ADDED
Binary file
|