-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-feedburner.php
203 lines (171 loc) · 7.57 KB
/
wp-feedburner.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
/*
Plugin Name: FeedBurner
Plugin URI: https://github.com/turadg/wp-feedburner
Description: Detects all ways to access your original WordPress feeds and redirects them to your FeedBurner feed so you can track every possible subscriber. Originally authored by <a href="http://www.orderedlist.com/">Steve Smith</a>. Categories added by <a href="http://interfacelab.com/feedburner-wp-plugin-fix/">InterfaceLab</a>.
Author: Turadg Aleahmad
Author URI: http://turadg.aleahmad.net/
Version: 2.4.0 beta 1
*/
$category_count=10;
$data = array(
'feedburner_url' => '',
'feedburner_comments_url' => ''
);
$ol_flash = '';
function ol_is_authorized() {
global $user_level;
if (function_exists("current_user_can")) {
return current_user_can('activate_plugins');
} else {
return $user_level > 5;
}
}
add_option('feedburner_settings',$data,'FeedBurner Feed Replacement Options');
$feedburner_settings = get_option('feedburner_settings');
function fb_is_hash_valid($form_hash) {
$ret = false;
$saved_hash = fb_retrieve_hash();
if ($form_hash === $saved_hash) {
$ret = true;
}
return $ret;
}
function fb_generate_hash() {
return md5(uniqid(rand(), TRUE));
}
function fb_store_hash($generated_hash) {
return update_option('feedsmith_token',$generated_hash,'FeedSmith Security Hash');
}
function fb_retrieve_hash() {
$ret = get_option('feedsmith_token');
return $ret;
}
function ol_add_feedburner_options_page() {
if (function_exists('add_options_page')) {
add_options_page('FeedBurner', 'FeedBurner', 8, basename(__FILE__), 'ol_feedburner_options_subpanel');
}
}
function ol_feedburner_options_subpanel() {
global $ol_flash, $feedburner_settings, $_POST, $wp_rewrite, $category_count;
$cats=get_categories();
if (!ol_is_authorized()) {
echo '<div class="wrap"><p>Sorry, you are not allowed to access this page.</p></div>';
return;
}
$updates_cats=array();
foreach($cats as $cat)
{
$field='feedburner_category_'.$cat->slug;
if (isset($_POST[$field]))
$updated_cats[$field]=$_POST[$field];
}
// Easiest test to see if we have been submitted to
if(isset($_POST['feedburner_url']) || isset($_POST['feedburner_comments_url']) || (count($updated_cats)>0)) {
// Now we check the hash, to make sure we are not getting CSRF
if (fb_is_hash_valid($_POST['token'])) {
// update the category feeds
if (count($updated_cats)>0)
foreach($updated_cats as $key=>$val)
{
$feedburner_settings[$key] = $val;
update_option('feedburner_settings',$feedburner_settings);
$ol_flash = "Your settings have been saved.";
}
if (isset($_POST['feedburner_url'])) {
$feedburner_settings['feedburner_url'] = $_POST['feedburner_url'];
update_option('feedburner_settings',$feedburner_settings);
$ol_flash = "Your settings have been saved.";
}
if (isset($_POST['feedburner_comments_url'])) {
$feedburner_settings['feedburner_comments_url'] = $_POST['feedburner_comments_url'];
update_option('feedburner_settings',$feedburner_settings);
$ol_flash = "Your settings have been saved.";
}
} else {
// Invalid form hash, possible CSRF attempt
$ol_flash = "Security hash missing.";
} // endif fb_is_hash_valid
} // endif isset(feedburner_url)
if ($ol_flash != '') echo '<div id="message" class="updated fade"><p>' . $ol_flash . '</p></div>';
$temp_hash = fb_generate_hash();
fb_store_hash($temp_hash);
?>
<div class="wrap">
<h2>Set Up Your FeedBurner Feed</h2>
<p>This plugin makes it easy to redirect 100% of traffic for your feeds to a FeedBurner feed you have created. FeedBurner can then track all of your feed subscriber traffic and usage and apply a variety of features you choose to improve and enhance your original WordPress feed.</p>
<form action="" method="post">
<input type="hidden" name="redirect" value="true" />
<input type="hidden" name="token" value="<?=fb_retrieve_hash()?>" />
<ol>
<li>To get started, <a href="http://feedburner.google.com/fb/a/myfeeds" target="_blank">create a FeedBurner feed</a> for <tt><?=get_bloginfo('name')?></tt>. This feed will handle all traffic for your posts.</li>
<li>Once you have created your FeedBurner feed, enter its address into the field below (http://feeds.feedburner.com/yourfeed):<br/>
<input type="text" name="feedburner_url" value="<?=htmlentities($feedburner_settings['feedburner_url'])?>" size="45" />
</li>
<?
foreach($cats as $cat)
echo "<li><strong>$cat->name</strong> Feed:<br/><input type=\"text\" name=\"feedburner_category_$cat->slug\" value=\"" . htmlentities($feedburner_settings['feedburner_category_'.$cat->slug]) . "\" size=\"45\" /></li>";
echo '<li>Optional: If you also want to handle your WordPress comments feed using FeedBurner, <a href="https://www.feedburner.com/fb/a/addfeed?sourceUrl=' . get_bloginfo('url') . '/wp-commentsrss2.php" target="_blank">create a FeedBurner comments feed</a> and then enter its address below:<br/><input type="text" name="feedburner_comments_url" value="' . htmlentities($feedburner_settings['feedburner_comments_url']) . '" size="45" />
</ol>
<p><input type="submit" value="Save" /></p></form>';
echo '</div>';
}
function ol_feed_redirect() {
global $wp, $feedburner_settings, $feed, $withcomments;
if (is_feed() && $feed != 'comments-rss2' && !is_single() && $wp->query_vars['category_name'] == '' && ($withcomments != 1) && trim($feedburner_settings['feedburner_url']) != '') {
if (function_exists('status_header')) status_header( 302 );
header("Location:" . trim($feedburner_settings['feedburner_url']));
header("HTTP/1.1 302 Temporary Redirect");
exit();
}
else if (is_feed() && $feed != 'comments-rss2' && !is_single() && $wp->query_vars['category_name'] != '' && ($withcomments != 1) && trim($feedburner_settings['feedburner_category_'.$wp->query_vars['category_name']]) != '') {
if (function_exists('status_header')) status_header( 302 );
header("Location:" . trim($feedburner_settings['feedburner_category_'.$wp->query_vars['category_name']]));
header("HTTP/1.1 302 Temporary Redirect");
exit();
}
elseif (is_feed() && ($feed == 'comments-rss2' || $withcomments == 1) && trim($feedburner_settings['feedburner_comments_url']) != '') {
if (function_exists('status_header')) status_header( 302 );
header("Location:" . trim($feedburner_settings['feedburner_comments_url']));
header("HTTP/1.1 302 Temporary Redirect");
exit();
}
}
function ol_check_url() {
global $feedburner_settings;
switch (basename($_SERVER['PHP_SELF'])) {
case 'wp-rss.php':
case 'wp-rss2.php':
case 'wp-atom.php':
case 'wp-rdf.php':
if (trim($feedburner_settings['feedburner_url']) != '') {
if (function_exists('status_header')) status_header( 302 );
header("Location:" . trim($feedburner_settings['feedburner_url']));
header("HTTP/1.1 302 Temporary Redirect");
exit();
}
break;
case 'wp-commentsrss2.php':
if (trim($feedburner_settings['feedburner_comments_url']) != '') {
if (function_exists('status_header')) status_header( 302 );
header("Location:" . trim($feedburner_settings['feedburner_comments_url']));
header("HTTP/1.1 302 Temporary Redirect");
exit();
}
break;
}
}
if (!preg_match("/feedburner|feedvalidator/i", $_SERVER['HTTP_USER_AGENT'])) {
add_action('template_redirect', 'ol_feed_redirect');
add_action('init','ol_check_url');
}
add_action('admin_menu', 'ol_add_feedburner_options_page');
/* Subscription Widget */
/* Add our function to the widgets_init hook. */
add_action( 'widgets_init', 'feedburner_loadwidgets' );
/* Function that registers our widget. */
function feedburner_loadwidgets() {
require_once('widgets/feedburner_subscribe_widget.php');
register_widget( 'FeedBurner_Subscribe_Widget' );
}
?>