Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 669 lines (572 sloc) 30.279 kB
3f632c8 Initial commit.
Pål-Kristian Hamre authored
1 <?php
2 /*
3 Plugin Name: WordPress Varnish
52cb1b8 Changed urls.
Pål-Kristian Hamre authored
4 Plugin URI: http://github.com/pkhamre/wp-varnish
fa187c1 @cd34 update for release
cd34 authored
5 Version: 0.8
52cb1b8 Changed urls.
Pål-Kristian Hamre authored
6 Author: <a href="http://github.com/pkhamre/">Pål-Kristian Hamre</a>
3f632c8 Initial commit.
Pål-Kristian Hamre authored
7 Description: A plugin for purging Varnish cache when content is published or edited.
8
9 Copyright 2010 Pål-Kristian Hamre (email : post_at_pkhamre_dot_com)
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
63f56d3 Added administration interface.
Pål-Kristian Hamre authored
26 class WPVarnish {
9e7712d Added functionality to actually make the administration interface work.
Pål-Kristian Hamre authored
27 public $wpv_addr_optname;
28 public $wpv_port_optname;
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
29 public $wpv_secret_optname;
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
30 public $wpv_timeout_optname;
31 public $wpv_update_pagenavi_optname;
32 public $wpv_update_commentnavi_optname;
9e7712d Added functionality to actually make the administration interface work.
Pål-Kristian Hamre authored
33
cdeb6c6 Added missing parantheses.
Pål-Kristian Hamre authored
34 function WPVarnish() {
8cd8b3c Need to pass the post id to the WPVarnishPurge function when add_acti…
Pål-Kristian Hamre authored
35 global $post;
9e7712d Added functionality to actually make the administration interface work.
Pål-Kristian Hamre authored
36
37 $this->wpv_addr_optname = "wpvarnish_addr";
38 $this->wpv_port_optname = "wpvarnish_port";
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
39 $this->wpv_secret_optname = "wpvarnish_secret";
a3d5068 @wfelipe timeout configuration
wfelipe authored
40 $this->wpv_timeout_optname = "wpvarnish_timeout";
7c50bff @linickx Add manual URL purge to Admin Dashboard
linickx authored
41 $this->wpvarnish_purge_url_optname = "wpvarnish_purge_url";
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
42 $this->wpv_update_pagenavi_optname = "wpvarnish_update_pagenavi";
43 $this->wpv_update_commentnavi_optname = "wpvarnish_update_commentnavi";
ec3b596 @wfelipe using admin port instead of PURGE method
wfelipe authored
44 $this->wpv_use_adminport_optname = "wpvarnish_use_adminport";
61cfa90 @linickx Enable Varnish version 3 bans
linickx authored
45 $this->wpv_vversion_optname = "wpvarnish_vversion";
11410ea support for multiple varnish servers
Wilson Felipe authored
46 $wpv_addr_optval = array ("127.0.0.1");
a3d5068 @wfelipe timeout configuration
wfelipe authored
47 $wpv_port_optval = array (80);
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
48 $wpv_secret_optval = array ("");
a3d5068 @wfelipe timeout configuration
wfelipe authored
49 $wpv_timeout_optval = 5;
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
50 $wpv_update_pagenavi_optval = 0;
51 $wpv_update_commentnavi_optval = 0;
ec3b596 @wfelipe using admin port instead of PURGE method
wfelipe authored
52 $wpv_use_adminport_optval = 0;
61cfa90 @linickx Enable Varnish version 3 bans
linickx authored
53 $wpv_vversion_optval = 2;
9e7712d Added functionality to actually make the administration interface work.
Pål-Kristian Hamre authored
54
55 if ( (get_option($this->wpv_addr_optname) == FALSE) ) {
56 add_option($this->wpv_addr_optname, $wpv_addr_optval, '', 'yes');
57 }
58
59 if ( (get_option($this->wpv_port_optname) == FALSE) ) {
60 add_option($this->wpv_port_optname, $wpv_port_optval, '', 'yes');
61 }
62
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
63 if ( (get_option($this->wpv_secret_optname) == FALSE) ) {
64 add_option($this->wpv_secret_optname, $wpv_secret_optval, '', 'yes');
65 }
66
a3d5068 @wfelipe timeout configuration
wfelipe authored
67 if ( (get_option($this->wpv_timeout_optname) == FALSE) ) {
68 add_option($this->wpv_timeout_optname, $wpv_timeout_optval, '', 'yes');
69 }
70
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
71 if ( (get_option($this->wpv_update_pagenavi_optname) == FALSE) ) {
72 add_option($this->wpv_update_pagenavi_optname, $wpv_update_pagenavi_optval, '', 'yes');
73 }
74
75 if ( (get_option($this->wpv_update_commentnavi_optname) == FALSE) ) {
76 add_option($this->wpv_update_commentnavi_optname, $wpv_update_commentnavi_optval, '', 'yes');
77 }
78
ec3b596 @wfelipe using admin port instead of PURGE method
wfelipe authored
79 if ( (get_option($this->wpv_use_adminport_optname) == FALSE) ) {
80 add_option($this->wpv_use_adminport_optname, $wpv_use_adminport_optval, '', 'yes');
81 }
82
61cfa90 @linickx Enable Varnish version 3 bans
linickx authored
83 if ( (get_option($this->wpv_vversion_optname) == FALSE) ) {
84 add_option($this->wpv_vversion_optname, $wpv_vversion_optval, '', 'yes');
85 }
86
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
87 // Localization init
96874ea @Flynsarmy Fix 'Call-time pass-by-reference' errors on activation
Flynsarmy authored
88 add_action('init', array($this, 'WPVarnishLocalization'));
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
89
90 // Add Administration Interface
96874ea @Flynsarmy Fix 'Call-time pass-by-reference' errors on activation
Flynsarmy authored
91 add_action('admin_menu', array($this, 'WPVarnishAdminMenu'));
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
92
8720801 @someguy9 Added Purge Button in Admin Bar
someguy9 authored
93 // Add Purge Links to Admin Bar
3a6e0a4 Reverted last change.
Pål-Kristian Hamre authored
94 add_action('admin_bar_menu', array($this, 'WPVarnishAdminBarLinks'), 100);
8720801 @someguy9 Added Purge Button in Admin Bar
someguy9 authored
95
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
96 // When posts/pages are published, edited or deleted
ab857a4 @gnotaras Complete rewrite of the part that generates the URL to be purged.
gnotaras authored
97 // 'edit_post' is not used as it is also executed when a comment is changed,
98 // causing the plugin to purge several URLs (WPVarnishPurgeCommonObjects)
99 // that do not need purging.
100
101 // When a post or custom post type is published, or if it is edited and its status is "published".
102 add_action('publish_post', array($this, 'WPVarnishPurgePost'), 99);
103 add_action('publish_post', array($this, 'WPVarnishPurgeCommonObjects'), 99);
104 // When a page is published, or if it is edited and its status is "published".
105 add_action('publish_page', array($this, 'WPVarnishPurgePost'), 99);
106 add_action('publish_page', array($this, 'WPVarnishPurgeCommonObjects'), 99);
107 // When an attachment is updated.
108 add_action('edit_attachment', array($this, 'WPVarnishPurgePost'), 99);
109 add_action('edit_attachment', array($this, 'WPVarnishPurgeCommonObjects'), 99);
110 // Runs just after a post is added via email.
111 add_action('publish_phone', array($this, 'WPVarnishPurgePost'), 99);
112 add_action('publish_phone', array($this, 'WPVarnishPurgeCommonObjects'), 99);
113 // Runs when a post is published via XMLRPC request, or if it is edited via XMLRPC and its status is "published".
114 add_action('xmlrpc_publish_post', array($this, 'WPVarnishPurgePost'), 99);
115 add_action('xmlrpc_publish_post', array($this, 'WPVarnishPurgeCommonObjects'), 99);
116 // Runs when a future post or page is published.
117 add_action('publish_future_post', array($this, 'WPVarnishPurgePost'), 99);
118 add_action('publish_future_post', array($this, 'WPVarnishPurgeCommonObjects'), 99);
119 // When post status is changed
1361a29 Fixed error 'Missing argument 2/3 for WPVarnish::WPVarnishPurgeCommon…
= authored
120 add_action('transition_post_status', array($this, 'WPVarnishPurgePostStatus'), 99, 3);
121 add_action('transition_post_status', array($this, 'WPVarnishPurgeCommonObjectsStatus'), 99, 3);
ab857a4 @gnotaras Complete rewrite of the part that generates the URL to be purged.
gnotaras authored
122 // When posts, pages, attachments are deleted
123 add_action('deleted_post', array($this, 'WPVarnishPurgePost'), 99);
124 add_action('deleted_post', array($this, 'WPVarnishPurgeCommonObjects'), 99);
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
125
126 // When comments are made, edited or deleted
ab857a4 @gnotaras Complete rewrite of the part that generates the URL to be purged.
gnotaras authored
127 // See: http://codex.wordpress.org/Plugin_API/Action_Reference#Comment.2C_Ping.2C_and_Trackback_Actions
96874ea @Flynsarmy Fix 'Call-time pass-by-reference' errors on activation
Flynsarmy authored
128 add_action('comment_post', array($this, 'WPVarnishPurgePostComments'),99);
129 add_action('edit_comment', array($this, 'WPVarnishPurgePostComments'),99);
130 add_action('deleted_comment', array($this, 'WPVarnishPurgePostComments'),99);
ab857a4 @gnotaras Complete rewrite of the part that generates the URL to be purged.
gnotaras authored
131 add_action('trashed_comment', array($this, 'WPVarnishPurgePostComments'),99);
132 add_action('pingback_post', array($this, 'WPVarnishPurgePostComments'),99);
133 add_action('trackback_post', array($this, 'WPVarnishPurgePostComments'),99);
134 add_action('wp_set_comment_status', array($this, 'WPVarnishPurgePostCommentsStatus'),99);
d0a6fb9 @cd34 purge actions
cd34 authored
135
136 // When Theme is changed, Thanks dupuis
137 add_action('switch_theme',array($this, 'WPVarnishPurgeAll'), 99);
138
e997a59 @cd34 added plugins_loaded hook to fix ticket #12
cd34 authored
139 // When a new plugin is loaded
aac0315 @cd34 fix for issue #41 and #42
cd34 authored
140 // this was added due to Issue #12, but, doesn't do what was intended
141 // commenting this out gets rid of the incessant purging.
142 //add_action('plugins_loaded',array($this, 'WPVarnishPurgeAll'), 99);
764b541 Added function for purging common content like the frontpage and feeds.
Pål-Kristian Hamre authored
143 }
144
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
145 function WPVarnishLocalization() {
3150f7c @wfelipe fix plugin directory name in code
wfelipe authored
146 load_plugin_textdomain('wp-varnish', false, dirname(plugin_basename( __FILE__ ) ) . '/lang/');
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
147 }
148
ab857a4 @gnotaras Complete rewrite of the part that generates the URL to be purged.
gnotaras authored
149 // WPVarnishPurgeAll - Using a regex, clear all blog cache. Use carefully.
150 function WPVarnishPurgeAll() {
151 $this->WPVarnishPurgeObject('/.*');
152 }
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
153
ab857a4 @gnotaras Complete rewrite of the part that generates the URL to be purged.
gnotaras authored
154 // WPVarnishPurgeURL - Using a URL, clear the cache
155 function WPVarnishPurgeURL($wpv_purl) {
156 $wpv_purl = preg_replace( '#^https?://[^/]+#i', '', $wpv_purl );
157 $this->WPVarnishPurgeObject($wpv_purl);
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
158 }
63f56d3 Added administration interface.
Pål-Kristian Hamre authored
159
ab857a4 @gnotaras Complete rewrite of the part that generates the URL to be purged.
gnotaras authored
160 //wrapper on WPVarnishPurgeCommonObjects for transition_post_status
161 function WPVarnishPurgeCommonObjectsStatus($old, $new, $post) {
162 if ( $old != $new ) {
163 if ( $old == 'publish' || $new == 'publish' ) {
164 $this->WPVarnishPurgeCommonObjects($post->ID);
165 }
166 }
167 }
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
168
ab857a4 @gnotaras Complete rewrite of the part that generates the URL to be purged.
gnotaras authored
169 // Purge related objects
170 function WPVarnishPurgeCommonObjects($post_id) {
171
172 $post = get_post($post_id);
173 // We need a post object in order to generate the archive URLs which are
174 // related to the post. We perform a few checks to make sure we have a
175 // post object.
176 if ( ! is_object($post) || ! isset($post->post_type) || ! in_array( get_post_type($post), array('post') ) ) {
177 // Do nothing for pages, attachments.
178 return;
179 }
180
181 // NOTE: Policy for archive purging
182 // By default, only the first page of the archives is purged. If
183 // 'wpv_update_pagenavi_optname' is checked, then all the pages of each
184 // archive are purged.
185 if ( get_option($this->wpv_update_pagenavi_optname) == 1 ) {
186 // Purge all pages of the archive.
187 $archive_pattern = '(?:page/[\d]+/)?$';
188 } else {
189 // Only first page of the archive is purged.
190 $archive_pattern = '$';
191 }
192
193 // Front page (latest posts OR static front page)
194 $this->WPVarnishPurgeObject( '/' . $archive_pattern );
195
196 // Static Posts page (Added only if a static page used as the 'posts page')
197 if ( get_option('show_on_front', 'posts') == 'page' && intval(get_option('page_for_posts', 0)) > 0 ) {
198 $posts_page_url = preg_replace( '#^https?://[^/]+#i', '', get_permalink(intval(get_option('page_for_posts'))) );
199 $this->WPVarnishPurgeObject( $posts_page_url . $archive_pattern );
200 }
201
202 // Feeds
203 $this->WPVarnishPurgeObject( '/feed/(?:(atom|rdf)/)?$' );
204
205 // Category, Tag, Author and Date Archives
206
207 // We get the URLs of the category and tag archives, only for
208 // those categories and tags which have been attached to the post.
209
210 // Category Archive
211 $category_slugs = array();
212 foreach( get_the_category($post->ID) as $cat ) {
213 $category_slugs[] = $cat->slug;
214 }
215 if ( ! empty($category_slugs) ) {
216 if ( count($category_slugs) > 1 ) {
217 $cat_slug_pattern = '(' . implode('|', $category_slugs) . ')';
218 } else {
219 $cat_slug_pattern = implode('', $category_slugs);
220 }
221 $this->WPVarnishPurgeObject( '/' . get_option('category_base', 'category') . '/' . $cat_slug_pattern . '/' . $archive_pattern );
222 }
223
224 // Tag Archive
225 $tag_slugs = array();
226 foreach( get_the_tags($post->ID) as $tag ) {
227 $tag_slugs[] = $tag->slug;
228 }
229 if ( ! empty($tag_slugs) ) {
230 if ( count($tag_slugs) > 1 ) {
231 $tag_slug_pattern = '(' . implode('|', $tag_slugs) . ')';
232 } else {
233 $tag_slug_pattern = implode('', $tag_slugs);
234 }
235 $this->WPVarnishPurgeObject( '/' . get_option('tag_base', 'tag') . '/' . $tag_slug_pattern . '/' . $archive_pattern );
236 }
237
238 // Author Archive
239 $author_archive_url = preg_replace('#^https?://[^/]+#i', '', get_author_posts_url($post->post_author) );
240 $this->WPVarnishPurgeObject( $author_archive_url . $archive_pattern );
241
242 // Date based archives
243 $archive_year = mysql2date('Y', $post->post_date);
244 $archive_month = mysql2date('m', $post->post_date);
245 $archive_day = mysql2date('d', $post->post_date);
246 // Yearly Archive
247 $archive_year_url = preg_replace('#^https?://[^/]+#i', '', get_year_link( $archive_year ) );
248 $this->WPVarnishPurgeObject( $archive_year_url . $archive_pattern );
249 // Monthly Archive
250 $archive_month_url = preg_replace('#^https?://[^/]+#i', '', get_month_link( $archive_year, $archive_month ) );
251 $this->WPVarnishPurgeObject( $archive_month_url . $archive_pattern );
252 // Daily Archive
253 $archive_day_url = preg_replace('#^https?://[^/]+#i', '', get_day_link( $archive_year, $archive_month, $archive_day ) );
254 $this->WPVarnishPurgeObject( $archive_day_url . $archive_pattern );
255 }
7c50bff @linickx Add manual URL purge to Admin Dashboard
linickx authored
256
ab857a4 @gnotaras Complete rewrite of the part that generates the URL to be purged.
gnotaras authored
257 //wrapper on WPVarnishPurgePost for transition_post_status
258 function WPVarnishPurgePostStatus($old, $new, $post) {
259 if ( $old != $new ) {
260 if ( $old == 'publish' || $new == 'publish' ) {
261 $this->WPVarnishPurgePost($post->ID);
262 }
263 }
264 }
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
265
ab857a4 @gnotaras Complete rewrite of the part that generates the URL to be purged.
gnotaras authored
266 // WPVarnishPurgePost - Purges a post object
267 function WPVarnishPurgePost($post_id, $purge_comments=false) {
268
269 $post = get_post($post_id);
270 // We need a post object, so we perform a few checks.
271 if ( ! is_object($post) || ! isset($post->post_type) || ! in_array( get_post_type($post), array('post', 'page', 'attachment') ) ) {
272 return;
273 }
274
275 //$wpv_url = get_permalink($post->ID);
276 // Here we do not use ``get_permalink()`` to get the post object's permalink,
277 // because this function generates a permalink only for published posts.
278 // So, for example, there is a problem when a post transitions from
279 // status 'publish' to status 'draft', because ``get_permalink`` would
280 // return a URL of the form, ``?p=123``, which does not exist in the cache.
281 // For this reason, the following workaround is used:
282 // http://wordpress.stackexchange.com/a/42988/14743
283 // It creates a clone of the post object and pretends it's published and
284 // then it generates the permalink for it.
285 if (in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) {
286 $my_post = clone $post;
287 $my_post->post_status = 'published';
288 $my_post->post_name = sanitize_title($my_post->post_name ? $my_post->post_name : $my_post->post_title, $my_post->ID);
289 $wpv_url = get_permalink($my_post);
290 } else {
291 $wpv_url = get_permalink($post->ID);
292 }
293
294 $wpv_url = preg_replace( '#^https?://[^/]+#i', '', $wpv_url );
295
296 // Purge post comments feed and comment pages, if requested, before
297 // adding multipage support.
298 if ( $purge_comments === true ) {
299 // Post comments feed
300 $this->WPVarnishPurgeObject( $wpv_url . 'feed/(?:(atom|rdf)/)?$' );
301 // For paged comments
302 if ( intval(get_option('page_comments', 0)) == 1 ) {
303 if ( get_option($this->wpv_update_commentnavi_optname) == 1 ) {
304 $this->WPVarnishPurgeObject( $wpv_url . 'comment-page-[\d]+/(?:#comments)?$' );
305 }
306 }
307 }
308
309 // Add support for multipage content for posts and pages
310 if ( in_array( get_post_type($post), array('post', 'page') ) ) {
311 $wpv_url .= '([\d]+/)?$';
312 }
313 // Purge object permalink
314 $this->WPVarnishPurgeObject($wpv_url);
315
316 // For attachments, also purge the parent post, if it is published.
317 if ( get_post_type($post) == 'attachment' ) {
318 if ( $post->post_parent > 0 ) {
319 $parent_post = get_post( $post->post_parent );
320 if ( $parent_post->post_status == 'publish' ) {
321 // If the parent post is published, then purge its permalink
322 $wpv_url = preg_replace( '#^https?://[^/]+#i', '', get_permalink($parent_post->ID) );
323 $this->WPVarnishPurgeObject( $wpv_url );
324 }
325 }
326 }
327 }
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
328
ab857a4 @gnotaras Complete rewrite of the part that generates the URL to be purged.
gnotaras authored
329 // wrapper on WPVarnishPurgePostComments for comment status changes
330 function WPVarnishPurgePostCommentsStatus($comment_id, $new_comment_status) {
331 $this->WPVarnishPurgePostComments($comment_id);
332 }
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
333
ab857a4 @gnotaras Complete rewrite of the part that generates the URL to be purged.
gnotaras authored
334 // WPVarnishPurgePostComments - Purge all comments pages from a post
335 function WPVarnishPurgePostComments($comment_id) {
336 $comment = get_comment($comment_id);
337 $post = get_post( $comment->comment_post_ID );
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
338
ab857a4 @gnotaras Complete rewrite of the part that generates the URL to be purged.
gnotaras authored
339 // Comments feed
340 $this->WPVarnishPurgeObject( '/comments/feed/(?:(atom|rdf)/)?$' );
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
341
ab857a4 @gnotaras Complete rewrite of the part that generates the URL to be purged.
gnotaras authored
342 // Purge post page, post comments feed and post comments pages
343 $this->WPVarnishPurgePost($post, $purge_comments=true);
344
345 // Popup comments
346 // See:
347 // - http://codex.wordpress.org/Function_Reference/comments_popup_link
348 // - http://codex.wordpress.org/Template_Tags/comments_popup_script
349 $this->WPVarnishPurgeObject( '/.*comments_popup=' . $post->ID . '.*' );
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
350
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
351 }
352
8720801 @someguy9 Added Purge Button in Admin Bar
someguy9 authored
353 function WPVarnishPostID() {
354 global $posts, $comment_post_ID, $post_ID;
355
356 if ($post_ID) {
357 return $post_ID;
358 } elseif ($comment_post_ID) {
359 return $comment_post_ID;
360 } elseif (is_single() || is_page() && count($posts)) {
361 return $posts[0]->ID;
362 } elseif (isset($_REQUEST['p'])) {
363 return (integer) $_REQUEST['p'];
364 }
365
366 return 0;
367 }
368
63f56d3 Added administration interface.
Pål-Kristian Hamre authored
369 function WPVarnishAdminMenu() {
0ec0e09 @vilhelmk add define to disable the admin menu
vilhelmk authored
370 if (!defined('VARNISH_HIDE_ADMINMENU')) {
652be7e @lrkwz Fix #72 replaced role 1 with 'publish_posts' cabìpability
lrkwz authored
371 add_options_page(__('WP-Varnish Configuration','wp-varnish'), 'WP-Varnish', 'publish_posts', 'WPVarnish', array($this, 'WPVarnishAdmin'));
0ec0e09 @vilhelmk add define to disable the admin menu
vilhelmk authored
372 }
63f56d3 Added administration interface.
Pål-Kristian Hamre authored
373 }
374
8720801 @someguy9 Added Purge Button in Admin Bar
someguy9 authored
375 function WPVarnishAdminBarLinks($admin_bar){
376 $admin_bar->add_menu( array(
377 'id' => 'wp-varnish',
378 'title' => __('Varnish','wp-varnish'),
379 'href' => admin_url('admin.php?page=WPVarnish')
380 ));
381 $admin_bar->add_menu( array(
382 'id' => 'clear-all-cache',
383 'parent' => 'wp-varnish',
384 'title' => 'Purge All Cache',
385 'href' => wp_nonce_url(admin_url('admin.php?page=WPVarnish&amp;wpvarnish_clear_blog_cache&amp;noheader=true'), 'wp-varnish')
386 ));
387 $admin_bar->add_menu( array(
388 'id' => 'clear-single-cache',
389 'parent' => 'wp-varnish',
390 'title' => 'Purge This Page',
391 'href' => wp_nonce_url(admin_url('admin.php?page=WPVarnish&amp;wpvarnish_clear_post&amp;noheader=true&amp;post_id=' . $this->WPVarnishPostID() ), 'wp-varnish')
392 ));
393 }
394
395
396
5aff235 Added todo.txt and written a bit more documentation.
Pål-Kristian Hamre authored
397 // WpVarnishAdmin - Draw the administration interface.
63f56d3 Added administration interface.
Pål-Kristian Hamre authored
398 function WPVarnishAdmin() {
8720801 @someguy9 Added Purge Button in Admin Bar
someguy9 authored
399 if ($_SERVER["REQUEST_METHOD"] == "GET") {
55fad5e @gnotaras Check for the 'manage_options' capability instead of the 'administrat…
gnotaras authored
400 if (current_user_can('manage_options')) {
8720801 @someguy9 Added Purge Button in Admin Bar
someguy9 authored
401
402 $nonce = $_REQUEST['_wpnonce'];
403
404 if (isset($_GET['wpvarnish_clear_blog_cache']) && wp_verify_nonce( $nonce, 'wp-varnish' )) {
405 $this->WPVarnishPurgeAll();
406 header('Location: '.admin_url('admin.php?page=WPVarnish'));
407 }
408
409 if (isset($_GET['wpvarnish_clear_post']) && wp_verify_nonce( $nonce, 'wp-varnish' )) {
410 $this->WPVarnishPurgePost($_GET['post_id']);
411 header('Location: '.admin_url('admin.php?page=WPVarnish'));
412 }
413 }
414 }elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
55fad5e @gnotaras Check for the 'manage_options' capability instead of the 'administrat…
gnotaras authored
415 if (current_user_can('manage_options')) {
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
416 if (isset($_POST['wpvarnish_admin'])) {
44f309c @cd34 Clean data rather than reject to fix ticket #31. Should do validation…
cd34 authored
417 cleanSubmittedData('wpvarnish_port', '/[^0-9]/');
418 cleanSubmittedData('wpvarnish_addr', '/[^0-9.]/');
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
419 if (!empty($_POST["$this->wpv_addr_optname"])) {
420 $wpv_addr_optval = $_POST["$this->wpv_addr_optname"];
421 update_option($this->wpv_addr_optname, $wpv_addr_optval);
422 }
423
424 if (!empty($_POST["$this->wpv_port_optname"])) {
425 $wpv_port_optval = $_POST["$this->wpv_port_optname"];
426 update_option($this->wpv_port_optname, $wpv_port_optval);
427 }
428
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
429 if (!empty($_POST["$this->wpv_secret_optname"])) {
430 $wpv_secret_optval = $_POST["$this->wpv_secret_optname"];
431 update_option($this->wpv_secret_optname, $wpv_secret_optval);
432 }
433
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
434 if (!empty($_POST["$this->wpv_timeout_optname"])) {
435 $wpv_timeout_optval = $_POST["$this->wpv_timeout_optname"];
436 update_option($this->wpv_timeout_optname, $wpv_timeout_optval);
437 }
438
439 if (!empty($_POST["$this->wpv_update_pagenavi_optname"])) {
440 update_option($this->wpv_update_pagenavi_optname, 1);
441 } else {
442 update_option($this->wpv_update_pagenavi_optname, 0);
443 }
444
445 if (!empty($_POST["$this->wpv_update_commentnavi_optname"])) {
446 update_option($this->wpv_update_commentnavi_optname, 1);
447 } else {
448 update_option($this->wpv_update_commentnavi_optname, 0);
449 }
ec3b596 @wfelipe using admin port instead of PURGE method
wfelipe authored
450
451 if (!empty($_POST["$this->wpv_use_adminport_optname"])) {
452 update_option($this->wpv_use_adminport_optname, 1);
453 } else {
454 update_option($this->wpv_use_adminport_optname, 0);
455 }
61cfa90 @linickx Enable Varnish version 3 bans
linickx authored
456
457 if (!empty($_POST["$this->wpv_vversion_optname"])) {
458 $wpv_vversion_optval = $_POST["$this->wpv_vversion_optname"];
459 update_option($this->wpv_vversion_optname, $wpv_vversion_optval);
460 }
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
461 }
462
7c50bff @linickx Add manual URL purge to Admin Dashboard
linickx authored
463 if (isset($_POST['wpvarnish_purge_url_submit'])) {
464 $this->WPVarnishPurgeURL($_POST["$this->wpvarnish_purge_url_optname"]);
465 }
466
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
467 if (isset($_POST['wpvarnish_clear_blog_cache']))
468 $this->WPVarnishPurgeAll();
9e7712d Added functionality to actually make the administration interface work.
Pål-Kristian Hamre authored
469
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
470 ?><div class="updated"><p><?php echo __('Settings Saved!','wp-varnish' ); ?></p></div><?php
471 } else {
472 ?><div class="updated"><p><?php echo __('You do not have the privileges.','wp-varnish' ); ?></p></div><?php
473 }
9e7712d Added functionality to actually make the administration interface work.
Pål-Kristian Hamre authored
474 }
475
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
476 $wpv_timeout_optval = get_option($this->wpv_timeout_optname);
477 $wpv_update_pagenavi_optval = get_option($this->wpv_update_pagenavi_optname);
478 $wpv_update_commentnavi_optval = get_option($this->wpv_update_commentnavi_optname);
ec3b596 @wfelipe using admin port instead of PURGE method
wfelipe authored
479 $wpv_use_adminport_optval = get_option($this->wpv_use_adminport_optname);
61cfa90 @linickx Enable Varnish version 3 bans
linickx authored
480 $wpv_vversion_optval = get_option($this->wpv_vversion_optname);
9e7712d Added functionality to actually make the administration interface work.
Pål-Kristian Hamre authored
481 ?>
482 <div class="wrap">
3150f7c @wfelipe fix plugin directory name in code
wfelipe authored
483 <script type="text/javascript" src="<?php echo plugins_url('wp-varnish.js', __FILE__ ); ?>"></script>
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
484 <h2><?php echo __("WordPress Varnish Administration",'wp-varnish'); ?></h2>
485 <h3><?php echo __("IP address and port configuration",'wp-varnish'); ?></h3>
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
486 <form method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
ddff59a Purge category pages as part of purging common objects.
Pål-Kristian Hamre authored
487 <?php
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
488 // Can't be edited - already defined in wp-config.php
489 global $varnish_servers;
214a660 Display global varnish version on settings page with other globals
= authored
490 global $varnish_version;
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
491 if (is_array($varnish_servers)) {
492 echo "<p>" . __("These values can't be edited since there's a global configuration located in <em>wp-config.php</em>. If you want to change these settings, please update the file or contact the administrator.",'wp-varnish') . "</p>\n";
493 // Also, if defined, show the varnish servers configured (VARNISH_SHOWCFG)
494 if (defined('VARNISH_SHOWCFG')) {
495 echo "<h3>" . __("Current configuration:",'wp-varnish') . "</h3>\n";
496 echo "<ul>";
214a660 Display global varnish version on settings page with other globals
= authored
497 if ( isset($varnish_version) && $varnish_version )
498 echo "<li>" . __("Version: ",'wp-varnish') . $varnish_version . "</li>";
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
499 foreach ($varnish_servers as $server) {
b03c1d8 @cd34 add @ to suppress Undefined Offset notice
cd34 authored
500 @list ($host, $port, $secret) = explode(':', $server);
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
501 echo "<li>" . __("Server: ",'wp-varnish') . $host . "<br/>" . __("Port: ",'wp-varnish') . $port . "</li>";
502 }
503 echo "</ul>";
504 }
505 } else {
506 // If not defined in wp-config.php, use individual configuration.
507 ?>
a3d5068 @wfelipe timeout configuration
wfelipe authored
508 <!-- <table class="form-table" id="form-table" width=""> -->
11410ea support for multiple varnish servers
Wilson Felipe authored
509 <table class="form-table" id="form-table">
9e7712d Added functionality to actually make the administration interface work.
Pål-Kristian Hamre authored
510 <tr valign="top">
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
511 <th scope="row"><?php echo __("Varnish Administration IP Address",'wp-varnish'); ?></th>
512 <th scope="row"><?php echo __("Varnish Administration Port",'wp-varnish'); ?></th>
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
513 <th scope="row"><?php echo __("Varnish Secret",'wp-varnish'); ?></th>
9e7712d Added functionality to actually make the administration interface work.
Pål-Kristian Hamre authored
514 </tr>
21cc3a4 multiple varnish servers working on interface
Wilson Felipe authored
515 <script>
11410ea support for multiple varnish servers
Wilson Felipe authored
516 <?php
517 $addrs = get_option($this->wpv_addr_optname);
518 $ports = get_option($this->wpv_port_optname);
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
519 $secrets = get_option($this->wpv_secret_optname);
3742342 @cd34 remove debug line to avoid strict warning
cd34 authored
520 //echo "rowCount = $i\n";
11410ea support for multiple varnish servers
Wilson Felipe authored
521 for ($i = 0; $i < count ($addrs); $i++) {
ddbeead some comments and code clean up
Wilson Felipe authored
522 // let's center the row creation in one spot, in javascript
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
523 echo "addRow('form-table', $i, '$addrs[$i]', $ports[$i], '$secrets[$i]');\n";
21cc3a4 multiple varnish servers working on interface
Wilson Felipe authored
524 } ?>
525 </script>
1ec4725 @eitchugo little layout modifications and l10n
eitchugo authored
526 </table>
527
528 <br/>
529
530 <table>
a3d5068 @wfelipe timeout configuration
wfelipe authored
531 <tr>
1ec4725 @eitchugo little layout modifications and l10n
eitchugo authored
532 <td colspan="3"><input type="button" class="" name="wpvarnish_admin" value="+" onclick="addRow ('form-table', rowCount)" /> <?php echo __("Add one more server",'wp-varnish'); ?></td>
a3d5068 @wfelipe timeout configuration
wfelipe authored
533 </tr>
9e7712d Added functionality to actually make the administration interface work.
Pål-Kristian Hamre authored
534 </table>
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
535 <?php
536 }
537 ?>
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
538 <p><?php echo __("Timeout",'wp-varnish'); ?>: <input class="small-text" type="text" name="wpvarnish_timeout" value="<?php echo $wpv_timeout_optval; ?>" /> <?php echo __("seconds",'wp-varnish'); ?></p>
539
ec3b596 @wfelipe using admin port instead of PURGE method
wfelipe authored
540 <p><input type="checkbox" name="wpvarnish_use_adminport" value="1" <?php if ($wpv_use_adminport_optval == 1) echo 'checked '?>/> <?php echo __("Use admin port instead of PURGE method.",'wp-varnish'); ?></p>
541
2b62cfc @eitchugo little fix on l10n messages
eitchugo authored
542 <p><input type="checkbox" name="wpvarnish_update_pagenavi" value="1" <?php if ($wpv_update_pagenavi_optval == 1) echo 'checked '?>/> <?php echo __("Also purge all page navigation (experimental, use carefully, it will include a bit more load on varnish servers.)",'wp-varnish'); ?></p>
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
543
2b62cfc @eitchugo little fix on l10n messages
eitchugo authored
544 <p><input type="checkbox" name="wpvarnish_update_commentnavi" value="1" <?php if ($wpv_update_commentnavi_optval == 1) echo 'checked '?>/> <?php echo __("Also purge all comment navigation (experimental, use carefully, it will include a bit more load on varnish servers.)",'wp-varnish'); ?></p>
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
545
f16227f Made Varnish version string translatable.
Timo Leiniö authored
546 <p><?php echo __('Varnish Version', 'wp-varnish'); ?>: <select name="wpvarnish_vversion"><option value="2" <?php if ($wpv_vversion_optval == 2) echo 'selected '?>/> 2 </option><option value="3" <?php if ($wpv_vversion_optval == 3) echo 'selected '?>/> 3 </option></select></p>
61cfa90 @linickx Enable Varnish version 3 bans
linickx authored
547
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
548 <p class="submit"><input type="submit" class="button-primary" name="wpvarnish_admin" value="<?php echo __("Save Changes",'wp-varnish'); ?>" /></p>
ddff59a Purge category pages as part of purging common objects.
Pål-Kristian Hamre authored
549
96874ea @Flynsarmy Fix 'Call-time pass-by-reference' errors on activation
Flynsarmy authored
550 <p>
be86d18 @pothi Add a delimiter at the end of ban regex; add a trailing slash after s…
pothi authored
551 <?php echo __('Purge a URL', 'wp-varnish'); ?>:<input class="text" type="text" name="wpvarnish_purge_url" value="<?php echo get_bloginfo('url'), '/'; ?>" />
7c50bff @linickx Add manual URL purge to Admin Dashboard
linickx authored
552 <input type="submit" class="button-primary" name="wpvarnish_purge_url_submit" value="<?php echo __("Purge",'wp-varnish'); ?>" />
553 </p>
554
2b62cfc @eitchugo little fix on l10n messages
eitchugo authored
555 <p class="submit"><input type="submit" class="button-primary" name="wpvarnish_clear_blog_cache" value="<?php echo __("Purge All Blog Cache",'wp-varnish'); ?>" /> <?php echo __("Use only if necessary, and carefully as this will include a bit more load on varnish servers.",'wp-varnish'); ?></p>
752a0b4 @eitchugo Code cleanup, support for cleaning all blog cache and purging comment…
eitchugo authored
556 </form>
9e7712d Added functionality to actually make the administration interface work.
Pål-Kristian Hamre authored
557 </div>
63f56d3 Added administration interface.
Pål-Kristian Hamre authored
558 <?php
559 }
560
5aff235 Added todo.txt and written a bit more documentation.
Pål-Kristian Hamre authored
561 // WPVarnishPurgeObject - Takes a location as an argument and purges this object
562 // from the varnish cache.
563 function WPVarnishPurgeObject($wpv_url) {
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
564 global $varnish_servers;
565
d78a499 Applied patch that adds a hook in the function WPVarnishPurgeObject.
Pål-Kristian Hamre authored
566 // added this hook to enable other plugins do something when cache is purged
567 do_action( 'WPVarnishPurgeObject', $wpv_url );
568
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
569 if (is_array($varnish_servers)) {
570 foreach ($varnish_servers as $server) {
3f0f222 ability to add secret to server list
Kit Westneat authored
571 list ($host, $port, $secret) = explode(':', $server);
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
572 $wpv_purgeaddr[] = $host;
573 $wpv_purgeport[] = $port;
3f0f222 ability to add secret to server list
Kit Westneat authored
574 $wpv_secret[] = $secret;
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
575 }
576 } else {
577 $wpv_purgeaddr = get_option($this->wpv_addr_optname);
578 $wpv_purgeport = get_option($this->wpv_port_optname);
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
579 $wpv_secret = get_option($this->wpv_secret_optname);
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
580 }
581
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
582 $wpv_timeout = get_option($this->wpv_timeout_optname);
ec3b596 @wfelipe using admin port instead of PURGE method
wfelipe authored
583 $wpv_use_adminport = get_option($this->wpv_use_adminport_optname);
4a0e19a Added global varnish_version setting
= authored
584 global $varnish_version;
585 if ( isset($varnish_version) && in_array($varnish_version, array(2,3)) )
586 $wpv_vversion_optval = $varnish_version;
587 else
588 $wpv_vversion_optval = get_option($this->wpv_vversion_optname);
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
589
16e00fd @cd34 take care of issue #33 (tested locally
cd34 authored
590 // check for domain mapping plugin by donncha
591 if (function_exists('domain_mapping_siteurl')) {
592 $wpv_wpurl = domain_mapping_siteurl('NA');
593 } else {
594 $wpv_wpurl = get_bloginfo('url');
595 }
dc5a392 @wfelipe replace get_bloginfo by get_option and allow https
wfelipe authored
596 $wpv_replace_wpurl = '/^https?:\/\/([^\/]+)(.*)/i';
9b747bc @eitchugo Support for WPMU, fix for multiple domains and blogs on subdirectories.
eitchugo authored
597 $wpv_host = preg_replace($wpv_replace_wpurl, "$1", $wpv_wpurl);
598 $wpv_blogaddr = preg_replace($wpv_replace_wpurl, "$2", $wpv_wpurl);
599 $wpv_url = $wpv_blogaddr . $wpv_url;
43e808d @wfelipe finished support for multiple varnish servers
wfelipe authored
600
6210a77 @kitwestneat add a member variable to allow for custom flush functions
kitwestneat authored
601 // allow custom purge functions and stop if they return false
602 if (function_exists($this->wpv_custom_purge_obj_f)) {
603 $f = $this->wpv_custom_purge_obj_f;
604 if (!$f($wpv_url, $wpv_host))
605 return;
606 }
607
43e808d @wfelipe finished support for multiple varnish servers
wfelipe authored
608 for ($i = 0; $i < count ($wpv_purgeaddr); $i++) {
b39b8b9 @eitchugo New options for purging page and comment navigation and fix for conne…
eitchugo authored
609 $varnish_sock = fsockopen($wpv_purgeaddr[$i], $wpv_purgeport[$i], $errno, $errstr, $wpv_timeout);
43e808d @wfelipe finished support for multiple varnish servers
wfelipe authored
610 if (!$varnish_sock) {
5d94865 @nicolas-grekas Try all varnish servers even when one fails
nicolas-grekas authored
611 error_log("wp-varnish error: $errstr ($errno) on server $wpv_purgeaddr[$i]:$wpv_purgeport[$i]");
612 continue;
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
613 }
614
615 if($wpv_use_adminport) {
616 $buf = fread($varnish_sock, 1024);
96874ea @Flynsarmy Fix 'Call-time pass-by-reference' errors on activation
Flynsarmy authored
617 if(preg_match('/(\w+)\s+Authentication required./', $buf, $matches)) {
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
618 # get the secret
61cfa90 @linickx Enable Varnish version 3 bans
linickx authored
619 $secret = $wpv_secret[$i];
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
620 fwrite($varnish_sock, "auth " . $this->WPAuth($matches[1], $secret) . "\n");
621 $buf = fread($varnish_sock, 1024);
622 if(!preg_match('/^200/', $buf)) {
5d94865 @nicolas-grekas Try all varnish servers even when one fails
nicolas-grekas authored
623 error_log("wp-varnish error: authentication failed using admin port on server $wpv_purgeaddr[$i]:$wpv_purgeport[$i]");
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
624 fclose($varnish_sock);
5d94865 @nicolas-grekas Try all varnish servers even when one fails
nicolas-grekas authored
625 continue;
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
626 }
ec3b596 @wfelipe using admin port instead of PURGE method
wfelipe authored
627 }
61cfa90 @linickx Enable Varnish version 3 bans
linickx authored
628 if ($wpv_vversion_optval == 3) {
be86d18 @pothi Add a delimiter at the end of ban regex; add a trailing slash after s…
pothi authored
629 $out = "ban req.url ~ ^$wpv_url$ && req.http.host == $wpv_host\n";
61cfa90 @linickx Enable Varnish version 3 bans
linickx authored
630 } else {
631 $out = "purge req.url ~ ^$wpv_url && req.http.host == $wpv_host\n";
632 }
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
633 } else {
3b7a7cb @cd34 modifications to fix issue #39 with ban versus purge
cd34 authored
634 $out = "BAN $wpv_url HTTP/1.0\r\n";
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
635 $out .= "Host: $wpv_host\r\n";
0b894f0 @cd34 WordPress-Varnish UserAgent as per ticket #23
cd34 authored
636 $out .= "User-Agent: WordPress-Varnish plugin\r\n";
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
637 $out .= "Connection: Close\r\n\r\n";
43e808d @wfelipe finished support for multiple varnish servers
wfelipe authored
638 }
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
639 fwrite($varnish_sock, $out);
640 fclose($varnish_sock);
3f632c8 Initial commit.
Pål-Kristian Hamre authored
641 }
642 }
a0c6370 @wfelipe now supporting secrets in admin port
wfelipe authored
643
644 function WPAuth($challenge, $secret) {
645 $ctx = hash_init('sha256');
646 hash_update($ctx, $challenge);
647 hash_update($ctx, "\n");
648 hash_update($ctx, $secret . "\n");
649 hash_update($ctx, $challenge);
650 hash_update($ctx, "\n");
651 $sha256 = hash_final($ctx);
652
653 return $sha256;
654 }
34e8947 Added lost curly bracket.
Pål-Kristian Hamre authored
655 }
63f56d3 Added administration interface.
Pål-Kristian Hamre authored
656
0642580 @xbudex Fix assigning return value by reference is deprecated warning
xbudex authored
657 $wpvarnish = new WPVarnish();
63f56d3 Added administration interface.
Pål-Kristian Hamre authored
658
44f309c @cd34 Clean data rather than reject to fix ticket #31. Should do validation…
cd34 authored
659 // Helper functions
660 function cleanSubmittedData($varname, $regexp) {
661 // FIXME: should do this in the admin console js, not here
662 // normally I hate cleaning data and would rather validate before submit
663 // but, this fixes the problem in the cleanest method for now
664 foreach ($_POST[$varname] as $key=>$value) {
665 $_POST[$varname][$key] = preg_replace($regexp,'',$value);
666 }
667 }
3f632c8 Initial commit.
Pål-Kristian Hamre authored
668 ?>
Something went wrong with that request. Please try again.