136
|
1 |
<?php |
|
2 |
/* |
|
3 |
Plugin Name: FD Feedburner Plugin |
|
4 |
Plugin URI: http://flagrantdisregard.com/feedburner/ |
|
5 |
Description: Redirects all feeds to a Feedburner feed |
|
6 |
Author: John Watson |
|
7 |
Author URI: http://flagrantdisregard.com/ |
|
8 |
Version: 1.41 |
|
9 |
|
|
10 |
Copyright (C) Sat Feb 18 2006 John Watson |
|
11 |
john@flagrantdisregard.com |
|
12 |
http://flagrantdisregard.com/ |
|
13 |
|
|
14 |
$Id: feedburnerplugin.php 407 2006-11-14 17:40:47Z John $ |
|
15 |
|
|
16 |
This program is free software; you can redistribute it and/or |
|
17 |
modify it under the terms of the GNU General Public License |
|
18 |
as published by the Free Software Foundation; either version 2 |
|
19 |
of the License, or any later version. |
|
20 |
|
|
21 |
This program is distributed in the hope that it will be useful, |
|
22 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
23 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
24 |
GNU General Public License for more details. |
|
25 |
' |
|
26 |
You should have received a copy of the GNU General Public License |
|
27 |
along with this program; if not, write to the Free Software |
|
28 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
29 |
*/ |
|
30 |
|
|
31 |
add_action('admin_menu', 'feedburner_config_page'); |
|
32 |
|
|
33 |
function feedburner_config_page() { |
|
34 |
global $wpdb; |
|
35 |
if ( function_exists('add_submenu_page') ) |
|
36 |
add_submenu_page('plugins.php', __('Feedburner Configuration'), __('Feedburner Configuration'), 8, __FILE__, 'feedburner_conf'); |
|
37 |
} |
|
38 |
|
|
39 |
function feedburner_fix_url($url) { |
|
40 |
$url = preg_replace('!^(http|https)://!i', '', $url); |
|
41 |
$url = preg_replace('!^/!i', '', $url); |
|
42 |
$url = 'http://'.$url; |
|
43 |
return $url; |
|
44 |
} |
|
45 |
|
|
46 |
function feedburner_conf() { |
|
47 |
$options = get_option('fd_feedburner'); |
|
48 |
|
|
49 |
if (!isset($options['feedburner_url'])) $options['feedburner_url'] = null; |
|
50 |
if (!isset($options['feedburner_comment_url'])) $options['feedburner_comment_url'] = null; |
|
51 |
if (!isset($options['feedburner_append_cats'])) $options['feedburner_append_cats'] = 0; |
|
52 |
if (!isset($options['feedburner_no_cats'])) $options['feedburner_no_cats'] = 0; |
|
53 |
if (!isset($options['feedburner_no_search'])) $options['feedburner_no_search'] = 0; |
|
54 |
|
|
55 |
$updated = false; |
|
56 |
if ( isset($_POST['submit']) ) { |
|
57 |
check_admin_referer(); |
|
58 |
|
|
59 |
if (isset($_POST['feedburner_url'])) { |
|
60 |
$feedburner_url = $_POST['feedburner_url']; |
|
61 |
if ($feedburner_url != null) $feedburner_url = feedburner_fix_url($feedburner_url); |
|
62 |
} else { |
|
63 |
$feedburner_url = null; |
|
64 |
} |
|
65 |
|
|
66 |
if (isset($_POST['feedburner_comment_url'])) { |
|
67 |
$feedburner_comment_url = $_POST['feedburner_comment_url']; |
|
68 |
if ($feedburner_comment_url != null) $feedburner_comment_url = feedburner_fix_url($feedburner_comment_url); |
|
69 |
} else { |
|
70 |
$feedburner_comment_url = null; |
|
71 |
} |
|
72 |
|
|
73 |
if (isset($_POST['feedburner_append_cats'])) { |
|
74 |
$feedburner_append_cats = $_POST['feedburner_append_cats']; |
|
75 |
} else { |
|
76 |
$feedburner_append_cats = 0; |
|
77 |
} |
|
78 |
|
|
79 |
if (isset($_POST['feedburner_no_cats'])) { |
|
80 |
$feedburner_no_cats = $_POST['feedburner_no_cats']; |
|
81 |
} else { |
|
82 |
$feedburner_no_cats = 0; |
|
83 |
} |
|
84 |
|
|
85 |
if (isset($_POST['feedburner_no_search'])) { |
|
86 |
$feedburner_no_search = $_POST['feedburner_no_search']; |
|
87 |
} else { |
|
88 |
$feedburner_no_search = 0; |
|
89 |
} |
|
90 |
|
|
91 |
$options['feedburner_url'] = $feedburner_url; |
|
92 |
$options['feedburner_comment_url'] = $feedburner_comment_url; |
|
93 |
$options['feedburner_append_cats'] = $feedburner_append_cats; |
|
94 |
$options['feedburner_no_cats'] = $feedburner_no_cats; |
|
95 |
$options['feedburner_no_search'] = $feedburner_no_search; |
|
96 |
|
|
97 |
update_option('fd_feedburner', $options); |
|
98 |
|
|
99 |
$updated = true; |
|
100 |
} |
|
101 |
?> |
|
102 |
|
|
103 |
<div class="wrap"> |
|
104 |
<?php |
|
105 |
if ($updated) { |
|
106 |
echo "<div id='message' class='updated fade'><p>"; |
|
107 |
_e('Configuration updated.'); |
|
108 |
echo "</p></div>"; |
|
109 |
} |
|
110 |
?> |
|
111 |
<h2><?php _e('Feedburner Configuration'); ?></h2> |
|
112 |
<div style="float: right; width: 350px"> |
|
113 |
<h3>How does this work?</h3> |
|
114 |
<p><?php _e('This plugin automatically redirects all of your existing feeds to Feedburner (including category and tag feeds).')?></p> |
|
115 |
<p><?php _e('First go to <a href="http://feedburner.com">Feedburner.com</a> and burn your feed. Enter the URL Feedburner created for you. You may optionally redirect your comments feed using the same procedure. To disable redirection, disable the plugin or erase the URLs.'); |
|
116 |
?></p> |
|
117 |
<p><?php _e('Once you enter URLs your feeds will be redirected automatically and you do not need to take any further action.') ?> <em><?php _e('Note that your feeds may not appear to redirect to Feedburner until you add a new post.'); ?></em> |
|
118 |
</p> |
|
119 |
</div> |
|
120 |
<form action="" method="post" id="feedburner-conf"> |
|
121 |
<h3><label for="feedburner_url"><?php _e('Redirect my feeds here:'); ?></label></h3> |
|
122 |
<p><input id="feedburner_url" name="feedburner_url" type="text" size="65" maxlength="200" value="<?php echo $options['feedburner_url']; ?>" /></p> |
|
123 |
|
|
124 |
<h3><label for="feedburner_comment_url"><?php _e('Redirect my comments feed here:'); ?></label></h3> |
|
125 |
<p><input id="feedburner_comment_url" name="feedburner_comment_url" type="text" size="65" maxlength="200" value="<?php echo $options['feedburner_comment_url']; ?>" /></p> |
|
126 |
|
|
127 |
<h3>Advanced Options</h3> |
|
128 |
<p> |
|
129 |
<input id="feedburner_no_cats" name="feedburner_no_cats" type="checkbox" value="1"<?php if ($options['feedburner_no_cats']==1) echo ' checked'; ?> /> |
|
130 |
<label for="feedburner_no_cats"><?php _e('Do not redirect category or tag feeds'); ?></label> |
|
131 |
</p> |
|
132 |
<p> |
|
133 |
<input id="feedburner_append_cats" name="feedburner_append_cats" type="checkbox" value="1"<?php if ($options['feedburner_append_cats']==1) echo ' checked'; ?> /> |
|
134 |
<label for="feedburner_append_cats"><?php _e('Append category/tag to URL for category/tag feeds'); ?> (<i>http://url<b>_category</b></i>)</label> |
|
135 |
</p> |
|
136 |
<p> |
|
137 |
<input id="feedburner_no_search" name="feedburner_no_search" type="checkbox" value="1"<?php if ($options['feedburner_no_search']==1) echo ' checked'; ?> /> |
|
138 |
<label for="feedburner_no_search"><?php _e('Do not redirect search result feeds'); ?></label> |
|
139 |
</p> |
|
140 |
|
|
141 |
<p class="submit" style="text-align: left"><input type="submit" name="submit" value="<?php _e('Save »'); ?>" /></p> |
|
142 |
</form> |
|
143 |
</div> |
|
144 |
<?php |
|
145 |
} |
|
146 |
|
|
147 |
function feedburner_redirect() { |
|
148 |
global $feed, $withcomments, $wp, $wpdb, $wp_version, $wp_db_version; |
|
149 |
|
|
150 |
// Do nothing if not a feed |
|
151 |
if (!is_feed()) return; |
|
152 |
|
|
153 |
// Do nothing if feedburner is the user-agent |
|
154 |
if (preg_match('/feedburner/i', $_SERVER['HTTP_USER_AGENT'])) return; |
|
155 |
|
|
156 |
// Do nothing if not configured |
|
157 |
$options = get_option('fd_feedburner'); |
|
158 |
if (!isset($options['feedburner_url'])) $options['feedburner_url'] = null; |
|
159 |
if (!isset($options['feedburner_comment_url'])) $options['feedburner_comment_url'] = null; |
|
160 |
if (!isset($options['feedburner_append_cats'])) $options['feedburner_append_cats'] = 0; |
|
161 |
if (!isset($options['feedburner_no_cats'])) $options['feedburner_no_cats'] = 0; |
|
162 |
if (!isset($options['feedburner_no_search'])) $options['feedburner_no_search'] = 0; |
|
163 |
$feed_url = $options['feedburner_url']; |
|
164 |
$comment_url = $options['feedburner_comment_url']; |
|
165 |
if ($feed_url == null && $comment_url == null) return; |
|
166 |
|
|
167 |
// Get category |
|
168 |
$cat = null; |
|
169 |
if ($wp->query_vars['category_name'] != null) { |
|
170 |
$cat = $wp->query_vars['category_name']; |
|
171 |
} |
|
172 |
if ($wp->query_vars['cat'] != null) { |
|
173 |
if ($wp_db_version >= 6124) { |
|
174 |
// 6124 = WP 2.3 |
|
175 |
$cat = $wpdb->get_var("SELECT slug FROM $wpdb->terms WHERE term_id = '".$wp->query_vars['cat']."' LIMIT 1"); |
|
176 |
} else { |
|
177 |
$cat = $wpdb->get_var("SELECT category_nicename FROM $wpdb->categories WHERE cat_ID = '".$wp->query_vars['cat']."' LIMIT 1"); |
|
178 |
} |
|
179 |
} |
|
180 |
if ($options['feedburner_append_cats'] == 1 && $cat) { |
|
181 |
$feed_url .= '_'.$cat; |
|
182 |
} |
|
183 |
|
|
184 |
// Get tag |
|
185 |
$tag = null; |
|
186 |
if ($wp->query_vars['tag'] != null) { |
|
187 |
$tag = $wp->query_vars['tag']; |
|
188 |
} |
|
189 |
if ($options['feedburner_append_cats'] == 1 && $tag) { |
|
190 |
$feed_url .= '_'.$tag; |
|
191 |
} |
|
192 |
|
|
193 |
// Get search terms |
|
194 |
$search = null; |
|
195 |
if ($wp->query_vars['s'] != null) { |
|
196 |
$search = $wp->query_vars['s']; |
|
197 |
} |
|
198 |
|
|
199 |
// Redirect comment feed |
|
200 |
if ($feed == 'comments-rss2' || is_single() || $withcomments) { |
|
201 |
if ($comment_url != null) { |
|
202 |
header("Location: ".$comment_url); |
|
203 |
die; |
|
204 |
} |
|
205 |
} else { |
|
206 |
// Other feeds |
|
207 |
switch($feed) { |
|
208 |
case 'feed': |
|
209 |
case 'rdf': |
|
210 |
case 'rss': |
|
211 |
case 'rss2': |
|
212 |
case 'atom': |
|
213 |
if (($cat || $tag) && $options['feedburner_no_cats'] == 1) { |
|
214 |
// If this is a category/tag feed and redirect is disabled, do nothing |
|
215 |
} else if ($search && $options['feedburner_no_search'] == 1) { |
|
216 |
// If this is a search result feed and redirect is disabled, do nothing |
|
217 |
} else { |
|
218 |
if ($feed_url != null) { |
|
219 |
// Redirect the feed |
|
220 |
header("Location: ".$feed_url); |
|
221 |
die; |
|
222 |
} |
|
223 |
} |
|
224 |
} |
|
225 |
} |
|
226 |
} |
|
227 |
|
|
228 |
/* |
|
229 |
================================================== |
|
230 |
Add action hooks |
|
231 |
================================================== |
|
232 |
*/ |
|
233 |
add_action('template_redirect', 'feedburner_redirect'); |
|
234 |
?> |