FeedWordPress - Version 2009.0612

Version Description

Download this release

Release Info

Developer radgeek
Plugin Icon wp plugin FeedWordPress
Version 2009.0612
Comparing to
See all releases

Code changes from version 2008.1214 to 2009.0612

ChangeLog.text CHANGED
@@ -1,6 +1,147 @@
1
  FeedWordPress Change Log
2
  ========================
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  Changes from 2008.1105 to 2008.1214
5
  -----------------------------------
6
 
@@ -466,7 +607,7 @@ between version 0.98 of WordPress and the recently released WordPress 2.1.
466
  in parse_w3cdtf(), some installations of PHP encountered problems with
467
  FeedWordPress's attempt to date posts, which would cause some new posts
468
  on Atom feeds to be dated as if they had apppeared in 1969 or 1970
469
- (thus, effectively, never appearing on front apge at all). This bug in
470
  the date handling should now be fixed.
471
 
472
  * PHP <?=...?> SHORT FORM ELIMINATED: some installations of PHP do not
@@ -550,7 +691,7 @@ Changes from 0.96 to 0.97
550
  (comparing results from PHP only to other results from PHP, and results
551
  from MySQL only to other results from MySQL).
552
 
553
- * BUG FIX: Items dated Decembr 31, 1969 should appear less often. The
554
  function for parsing W3C date-time format dates that ships with
555
  MagpieRSS can only correctly parse fully-specified dates with a
556
  fully-specified time, but valid W3C date-time format dates may omit the
@@ -577,7 +718,7 @@ Changes from 0.96 to 0.97
577
  require an HTTP POST to take effect. I think I got pretty much
578
  everything; if there's anything that I missed, let me know.
579
 
580
- Further reading: [Sam Ruby 2005-05-06: This Stuff Matters] (http://www.intertwingly.net/blog/2005/05/06/This-Stuff-Matters)
581
 
582
  * BUG FIX: Categories applied by `cats` setting should no longer prevent
583
  category-based filtering from working. In FeedWordPress, you can (1)
1
  FeedWordPress Change Log
2
  ========================
3
 
4
+ Changes from 2008.1214 to 2009.0612
5
+ -----------------------------------
6
+ * WORDPRESS 2.8 COMPATIBILITY: FeedWordPress 2009.0612 has been tested for
7
+ compatibility with the recent version 2.8 release of WordPress.
8
+
9
+ * INTERFACE RESTRUCTURING: In order to avoid settings posts from becoming
10
+ too crowded, and to modularize and better organize the user interface,
11
+ new "Posts" and "Categories & Tags" subpages have been created under the
12
+ "Syndication" menu. "Posts" controls settings for individal syndicated
13
+ posts (such as publication status, comment and ping status, whether or
14
+ not to use the original location of the post as the permalink, whether
15
+ or not to expose posts to formatting filters, and so on). "Categories &
16
+ Tags" controls settings for assigning new syndicated posts to categories
17
+ and tags, such as categories or tags to apply to all syndicated posts,
18
+ and how to handle categories that do not yet exist in the WordPress
19
+ database. These subpages, like the Authors subpage, handle settings for
20
+ the global default level and for individual syndicated feeds.
21
+
22
+ Corresponding to these new subpages, the old Syndication Settings and
23
+ Feed Settings subpages have been cleaned up and simplified, and now only
24
+ link to the appropriate subpages for options that can be set in the
25
+ Posts, Authors, or Categories & Tags subpages.
26
+
27
+ * FEATURE: ADD CUSTOM SETTINGS TO EACH SYNDICATED POST: FeedWordPress has
28
+ long had an interface for creating custom settings for each syndicated
29
+ *feed* which could be retrieved in templates using the `get_feed_meta()`
30
+ template function. But it had no feature for adding custom fields to
31
+ each individual syndicated *post*. In response to requests from users, I
32
+ have added the ability to apply custom fields to each individual
33
+ syndicated post, using the new Syndication --> Posts subpage. You can
34
+ set up custom fields to be applied to every syndicated post, or custom
35
+ fields to be applied to syndicated posts from a particular feed.
36
+
37
+ * FEATURE: MAGPIERSS VERSION CHECK AND UPGRADE: FeedWordPress will attempt
38
+ to determine whether or not you are using the upgraded version of
39
+ MagpieRSS that comes packaged with FeedWordPress. If not, it will throw
40
+ an error on admin pages, and, if you are a site administrator, it will
41
+ give you the option to ignore the error message, or to attempt an
42
+ automatic upgrade (using a native file copy). If the file copy fails,
43
+ FeedWordPress will offer some guidance on how to perform the upgrade
44
+ manually.
45
+
46
+ * BLANK POSTS PROBLEM NO LONGER OCCURS WITH OLD & BUSTED MAGPIERSS: Due
47
+ to the fact that I relied on a content normalization that occurs in my
48
+ upgraded version of MagpieRSS, but not in the old & busted version of
49
+ MagpieRSS that ships with WordPress, until this version, if you tried to
50
+ syndicate an Atom feed without having performed the (*strongly
51
+ recommended*) MagpieRSS upgrade, all of the posts would come up with
52
+ completely blank contents. That's not because MagpieRSS couldn't read
53
+ the data, but rather because the new Magpie version puts that data in a
54
+ location where the old version doesn't, and I was only looking in that
55
+ newer location. Now it checks for both, meaning that posts will continue
56
+ to display their contents even if you don't upgrade MagpieRSS. (But you
57
+ **really should** upgrade it, anyway.)
58
+
59
+ * BUGFIX: RELATIVE URI RESOLUTION FOR POST CONTENT RESTORED. Some time
60
+ back, I added support for resolving relative URIs against xml:base on
61
+ feeds that support it to the MagpieRSS upgrade in FeedWordPress. Then I
62
+ took out code that did the same thing from the main FeedWordPress code.
63
+ Of course, the problem is that some people, even though it is clearly
64
+ stupid or evil to do so, still include relative URIs for images or links
65
+ in posts on feed formats that do *not* adequately support xml:base
66
+ (notably, RSS 2.0 feeds). In response to a user request, I have added
67
+ this functionality back in, so that MagpieRSS will resolve any relative
68
+ URIs that it knows how to resolve using xml:base, and then FeedWordPress
69
+ will attempt to resolve any relative URIs that are left over afterwards.
70
+
71
+ * BUGFIX: INTERFACE OPTION FOR SETTING SYNDICATED POST PUBLICATION STATUS
72
+ ON A FEED-BY-FEED BASIS HAS BEEN RESTORED: Due to a version-checking
73
+ bug, users of WordPress 2.7.x lost an option from the "Edit a syndicated
74
+ feed" interface which allowed them to determine whether newly syndicated
75
+ posts should be published immediately, held as "Pending Review," saved
76
+ as drafts, or saved as private posts. (The option to change this
77
+ setting globally remained in place, but users could no longer set it on
78
+ a feed-by-feed basis.) The version-checking bug has been fixed, and the
79
+ option has been restored.
80
+
81
+ * BUGFIX: "ARE YOU SURE?" FATAL ERROR ELIMINATED AND SECURITY IMPROVED:
82
+ Under certain circumstances (for example, when users have configured
83
+ their browser or proxy not to send HTTP Referer headers, for privacy or
84
+ other reasons), many features in the FeedWordPress administrative
85
+ interface (such as adding new feeds or changing settings) would hit a
86
+ fatal error, displaying only a cryptic message reading "Are you sure?"
87
+ and a blank page following it. This problem has been eliminated by
88
+ taking advantage of WordPress's nonce functions, which allow the
89
+ security check which ran into this error to work properly even without
90
+ receiving an HTTP Referer header. (N.B.: WordPress's nonce functions
91
+ were first introduced in WordPress 2.0.3. If you're using FeedWordPress
92
+ with an older version of WordPress, there's no fix for this problem:
93
+ you'll just need to turn Referer headers back on. Sorry.)
94
+
95
+ * BUGFIX: MANUALLY-ALTERED POST STATUS, COMMENT STATUS, AND PING STATUS NO
96
+ LONGER REVERTED BY POST UPDATES: If you manually altered the post status,
97
+ comment status, or ping status of a syndicated post from what it was set
98
+ to when first syndicated -- for example, if you had a feed that was set
99
+ to bring in new posts as "Pending Review," and you then marked some of
100
+ the pending posts as "Published" and others as "Unpublished" -- then
101
+ in previous versions of FeedWordPress, these manual changes to the
102
+ status would be lost -- so that, for example, your Published or Unpublished
103
+ articles would revert to Pending Review -- if the source feed made any
104
+ upates to the item. This could make the Pending Review feature both
105
+ unreliable and also extremely frustrating to work with. The good news is
106
+ that this bug has since been fixed: if you manually update the status
107
+ of a post, it will no longer be reverted if or when the post is updated.
108
+
109
+ * BUGFIX: OCCASIONAL FATAL ERROR ON UPDATE ELIMINATED: Under certain
110
+ limited conditions (specifically, when both the title and the content of
111
+ a post to be updated are empty), an attempt to update the post would
112
+ result in a fatal error. This has been fixed.
113
+
114
+ * INTERFACE: "CONFIGURE SETTINGS" CONVENIENCE LINK ADDED TO CONFIRMATION
115
+ MESSAGE WHEN A NEW FEED IS ADDED: When you add a new subscription to
116
+ FeedWordPress, the message box that appears to confirm it now includes a
117
+ handy link to the feed's settings subpage, so that you can quickly set
118
+ up any special settings you may want to set up for the new feed, without
119
+ having to hunt through the list of all your other subscriptions to pick
120
+ out the new one.
121
+
122
+ * INTERFACE: SIMPLIFYING AND CLARIFYING AUTOMATIC UPDATES SETTINGS. I have
123
+ removed an interval setting for the cronless automatic updates which has
124
+ confused many FeedWordPress users. In past versions of FWP, when you
125
+ turned on automatic updates, you would be presented with a time interval
126
+ setting which controlled how often FeedWordPress would check for feeds
127
+ ready to be polled for updates. (That is, it DID NOT control how often
128
+ feeds *would be polled*; it controlled how often FeedWordPress would
129
+ *check* for feeds that *had become ready to poll*. The schedule on which
130
+ feeds became ready for polling was still controlled either by requests
131
+ encoded in elements within the feed itself, or else according to an
132
+ internal calculation within FeedWordPress, averaging out to about 1 hour,
133
+ if the feed did not include any scheduling request elements.) Since many
134
+ users very often (and understandably) confused the purpose of this
135
+ setting, and since the setting is for a feature that's actually very
136
+ unlikely to require any manual control by the user, I have removed the
137
+ setting; FeedWordPress now simply uses the default value of checking for
138
+ feeds to poll every 10 minutes.
139
+
140
+ * FEEDFINDER PERFORMANCE IMPROVEMENT: FeedWordPress's FeedFinder class
141
+ now uses `array_unique()` to make sure that it doesn't waste time
142
+ repeatedly iterating over and polling the same URI. Props to Camilo
143
+ (<http://projects.radgeek.com/2008/12/14/feedwordpress-20081214/#comment-20090122160414>).
144
+
145
  Changes from 2008.1105 to 2008.1214
146
  -----------------------------------
147
 
607
  in parse_w3cdtf(), some installations of PHP encountered problems with
608
  FeedWordPress's attempt to date posts, which would cause some new posts
609
  on Atom feeds to be dated as if they had apppeared in 1969 or 1970
610
+ (thus, effectively, never appearing on front page at all). This bug in
611
  the date handling should now be fixed.
612
 
613
  * PHP <?=...?> SHORT FORM ELIMINATED: some installations of PHP do not
691
  (comparing results from PHP only to other results from PHP, and results
692
  from MySQL only to other results from MySQL).
693
 
694
+ * BUG FIX: Items dated December 31, 1969 should appear less often. The
695
  function for parsing W3C date-time format dates that ships with
696
  MagpieRSS can only correctly parse fully-specified dates with a
697
  fully-specified time, but valid W3C date-time format dates may omit the
718
  require an HTTP POST to take effect. I think I got pretty much
719
  everything; if there's anything that I missed, let me know.
720
 
721
+ Further reading: [Sam Ruby 2005-05-06: This Stuff Matters](http://www.intertwingly.net/blog/2005/05/06/This-Stuff-Matters)
722
 
723
  * BUG FIX: Categories applied by `cats` setting should no longer prevent
724
  category-based filtering from working. In FeedWordPress, you can (1)
admin-ui.php CHANGED
@@ -4,24 +4,7 @@ function fwp_linkedit_single_submit ($status = NULL) {
4
  ?>
5
  <div class="submitbox" id="submitlink">
6
  <div id="previewview"></div>
7
- <div class="inside">
8
- <?php if (!is_null($status)) : ?>
9
- <p><strong>Publication</strong></p>
10
- <p>When a new post is syndicated from this feed...</p>
11
- <select name="feed_post_status">
12
- <option value="site-default" <?php echo $status['post']['site-default']; ?>> Use
13
- Syndication Options setting</option>
14
- <option value="publish" <?php echo $status['post']['publish']; ?>>Publish it immediately</option>
15
-
16
- <?php if (SyndicatedPost::use_api('post_status_pending')) : ?>
17
- <option value="pending" <?php echo $status['post']['pending']; ?>>Hold it Pending Review</option>
18
- <?php endif; ?>
19
-
20
- <option value="draft" <?php echo $status['post']['draft']; ?>>Save it as a draft</option>
21
- <option value="private" <?php echo $status['post']['private']; ?>>Keep it private</option>
22
- </select>
23
- <?php endif; ?>
24
- </div>
25
 
26
  <p class="submit">
27
  <input type="submit" name="submit" value="<?php _e('Save') ?>" />
@@ -202,3 +185,95 @@ function fwp_author_list () {
202
  return $ret;
203
  }
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ?>
5
  <div class="submitbox" id="submitlink">
6
  <div id="previewview"></div>
7
+ <div class="inside"></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  <p class="submit">
10
  <input type="submit" name="submit" value="<?php _e('Save') ?>" />
185
  return $ret;
186
  }
187
 
188
+ class FeedWordPressSettingsUI {
189
+ function instead_of_posts_box ($link_id = null) {
190
+ fwp_option_box_opener('Syndicated Posts, Comments & Pings', 'syndicatedpostsdiv', 'postbox');
191
+ if (!is_null($link_id)) :
192
+ $from_this_feed = 'from this feed';
193
+ $by_default = '';
194
+ $id_param = "&amp;link_id=".$link_id;
195
+ else :
196
+ $from_this_feed = 'from syndicated feeds';
197
+ $by_default = " by default";
198
+ $id_param = "";
199
+ endif;
200
+ ?>
201
+ <p>Use the <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/posts-page.php<?php print $id_param; ?>"><?php _e('Posts'); ?></a>
202
+ settings page to set up how new posts <?php print $from_this_feed; ?> will be published<?php $by_default; ?>, whether they will accept
203
+ comments and pings, any custom fields that should be set on each post, etc.</p>
204
+ <?php
205
+ fwp_option_box_closer();
206
+ } /* FeedWordPressSettingsUI::instead_of_posts_box () */
207
+
208
+ function instead_of_authors_box ($link_id = null) {
209
+ if (!is_null($link_id)) :
210
+ $from_this_feed = 'from this feed';
211
+ $by_default = '';
212
+ $id_param = "&amp;link_id=".$link_id;
213
+ else :
214
+ $from_this_feed = 'from syndicated feeds';
215
+ $by_default = " by default";
216
+ $id_param = "";
217
+ endif;
218
+
219
+ fwp_option_box_opener('Syndicated Authors', 'authordiv', 'postbox')
220
+ ?>
221
+ <p>Use the <a
222
+ href="admin.php?page=<?php print $GLOBALS['fwp_path']
223
+ ?>/authors-page.php<?php print $id_param; ?>"><?php _e('Authors');
224
+ ?></a> settings page to set up how new posts
225
+ <?php print $from_this_feed; ?> will be assigned to
226
+ authors.</p>
227
+ <?php
228
+ fwp_option_box_closer();
229
+ } /* FeedWordPressSettingsUI::instead_of_authors_box () */
230
+
231
+ function instead_of_categories_box ($link_id = null) {
232
+ if (!is_null($link_id)) :
233
+ $from_this_feed = 'from this feed';
234
+ $by_default = '';
235
+ $id_param = "&amp;link_id=".$link_id;
236
+ else :
237
+ $from_this_feed = 'from syndicated feeds';
238
+ $by_default = " by default";
239
+ $id_param = "";
240
+ endif;
241
+
242
+ fwp_option_box_opener(__('Categories & Tags'), 'categorydiv', 'postbox');
243
+ ?>
244
+ <p>Use the <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/categories-page.php<?php print $id_param; ?>"><?php _e('Categories & Tags'); ?></a>
245
+ settings page to set up how new posts <?php print $from_this_feed; ?> are assigned categories or tags<?php print $by_default; ?>.</p>
246
+ <?php
247
+ fwp_option_box_closer();
248
+ } /* FeedWordPressSettingsUI::instead_of_categories_box () */
249
+
250
+ } /* class FeedWordPressSettingsUI */
251
+
252
+ function fwp_insert_new_user ($newuser_name) {
253
+ global $wpdb;
254
+
255
+ $ret = null;
256
+ if (strlen($newuser_name) > 0) :
257
+ $userdata = array();
258
+ $userdata['ID'] = NULL;
259
+
260
+ $userdata['user_login'] = sanitize_user($newuser_name);
261
+ $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
262
+
263
+ $userdata['user_nicename'] = sanitize_title($newuser_name);
264
+ $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
265
+
266
+ $userdata['display_name'] = $wpdb->escape($newuser_name);
267
+
268
+ $newuser_id = wp_insert_user($userdata);
269
+ if (is_numeric($newuser_id)) :
270
+ $ret = $newuser_id;
271
+ else :
272
+ // TODO: Add some error detection and reporting
273
+ endif;
274
+ else :
275
+ // TODO: Add some error reporting
276
+ endif;
277
+ return $ret;
278
+ } /* fwp_insert_new_user () */
279
+
authors.php → authors-page.php RENAMED
@@ -4,8 +4,8 @@ require_once(dirname(__FILE__) . '/admin-ui.php');
4
  function fwp_authors_page () {
5
  global $wpdb, $wp_db_version;
6
 
7
- check_admin_referer(); // Make sure we arrived here from the Dashboard
8
-
9
  if (isset($GLOBALS['fwp_post']['save']) or isset($GLOBALS['fwp_post']['fix_mismatch'])) :
10
  $link_id = $_REQUEST['save_link_id'];
11
  elseif (isset($_REQUEST['link_id'])) :
@@ -21,12 +21,145 @@ function fwp_authors_page () {
21
  endif;
22
 
23
  $mesg = null;
24
- if (!current_user_can('manage_links')) :
25
- die (__("Cheatin' uh ?"));
26
- else :
27
- if (isset($GLOBALS['fwp_post']['fix_mismatch'])) :
28
- if ('newuser'==$GLOBALS['fwp_post']['fix_mismatch_to']) :
29
- $newuser_name = trim($GLOBALS['fwp_post']['fix_mismatch_to_newuser']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  if (strlen($newuser_name) > 0) :
31
  $userdata = array();
32
  $userdata['ID'] = NULL;
@@ -41,7 +174,7 @@ function fwp_authors_page () {
41
 
42
  $newuser_id = wp_insert_user($userdata);
43
  if (is_numeric($newuser_id)) :
44
- $fix_mismatch_to_id = $newuser_id;
45
  else :
46
  // TODO: Add some error detection and reporting
47
  endif;
@@ -49,176 +182,41 @@ function fwp_authors_page () {
49
  // TODO: Add some error reporting
50
  endif;
51
  else :
52
- $fix_mismatch_to_id = $GLOBALS['fwp_post']['fix_mismatch_to'];
53
- endif;
54
- $fix_mismatch_from_id = (int) $GLOBALS['fwp_post']['fix_mismatch_from'];
55
- if (is_numeric($fix_mismatch_from_id)) :
56
- // Make a list of all the items by this author syndicated from this feed...
57
- $post_ids = $wpdb->get_col("
58
- SELECT {$wpdb->posts}.id
59
- FROM {$wpdb->posts}, {$wpdb->postmeta}
60
- WHERE ({$wpdb->posts}.id = {$wpdb->postmeta}.post_id)
61
- AND {$wpdb->postmeta}.meta_key = 'syndication_feed_id'
62
- AND {$wpdb->postmeta}.meta_value = '{$link_id}'
63
- AND {$wpdb->posts}.post_author = '{$fix_mismatch_from_id}'
64
- ");
65
-
66
- if (count($post_ids) > 0) :
67
- // Re-assign them all to the correct author
68
- if (is_numeric($fix_mismatch_to_id)) : // re-assign to a particular user
69
- $post_set = "(".implode(",", $post_ids).")";
70
-
71
- // Getting the revisions too, if there are any
72
- if (fwp_test_wp_version(FWP_SCHEMA_26)) :
73
- $parent_in_clause = "OR {$wpdb->posts}.post_parent IN $post_set";
74
- else :
75
- $parent_in_clause = '';
76
- endif;
77
-
78
- $wpdb->query("
79
- UPDATE {$wpdb->posts}
80
- SET post_author='{$fix_mismatch_to_id}'
81
- WHERE ({$wpdb->posts}.id IN $post_set
82
- $parent_in_clause)
83
- ");
84
- $mesg = "Re-assigned ".count($post_ids)." post".((count($post_ids)==1)?'':'s').".";
85
-
86
- // ... and kill them all
87
- elseif ($fix_mismatch_to_id=='filter') :
88
- foreach ($post_ids as $post_id) :
89
- wp_delete_post($post_id);
90
- endforeach;
91
- $mesg = "Deleted ".count($post_ids)." post".((count($post_ids)==1)?'':'s').".";
92
- endif;
93
- else :
94
- $mesg = "Couldn't find any posts that matched your criteria.";
95
- endif;
96
  endif;
97
- elseif (isset($GLOBALS['fwp_post']['save'])) :
98
- if (is_object($link) and $link->found()) :
99
- $alter = array ();
100
-
101
- // Unfamiliar author rule
102
- if (isset($GLOBALS['fwp_post']["unfamiliar_author"])) :
103
- if ('site-default'==$GLOBALS['fwp_post']["unfamiliar_author"]) :
104
- unset($link->settings["unfamiliar author"]);
105
- elseif ('newuser'==$GLOBALS['fwp_post']["unfamiliar_author"]) :
106
- $newuser_name = trim($GLOBALS['fwp_post']["unfamiliar_author_newuser"]);
107
- $link->map_name_to_new_user(/*name=*/ NULL, $newuser_name);
108
- else :
109
- $link->settings["unfamiliar author"] = $GLOBALS['fwp_post']["unfamiliar_author"];
110
- endif;
111
- endif;
112
-
113
- // Handle author mapping rules
114
- if (isset($GLOBALS['fwp_post']['author_rules_name']) and isset($GLOBALS['fwp_post']['author_rules_action'])) :
115
- unset($link->settings['map authors']);
116
- foreach ($GLOBALS['fwp_post']['author_rules_name'] as $key => $name) :
117
- // Normalize for case and whitespace
118
- $name = strtolower(trim($name));
119
- $author_action = strtolower(trim($GLOBALS['fwp_post']['author_rules_action'][$key]));
120
-
121
- if (strlen($name) > 0) :
122
- if ('newuser' == $author_action) :
123
- $newuser_name = trim($GLOBALS['fwp_post']['author_rules_newuser'][$key]);
124
- $link->map_name_to_new_user($name, $newuser_name);
125
- else :
126
- $link->settings['map authors']['name'][$name] = $author_action;
127
- endif;
128
- endif;
129
- endforeach;
130
- endif;
131
-
132
- if (isset($GLOBALS['fwp_post']['add_author_rule_name']) and isset($GLOBALS['fwp_post']['add_author_rule_action'])) :
133
- $name = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_name']));
134
- $author_action = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_action']));
135
- if (strlen($name) > 0) :
136
- if ('newuser' == $author_action) :
137
- $newuser_name = trim($GLOBALS['fwp_post']['add_author_rule_newuser']);
138
- $link->map_name_to_new_user($name, $newuser_name);
139
- else :
140
- $link->settings['map authors']['name'][$name] = $author_action;
141
- endif;
142
- endif;
143
- endif;
144
-
145
- $alter[] = "link_notes = '".$wpdb->escape($link->settings_to_notes())."'";
146
-
147
- $alter_set = implode(", ", $alter);
148
-
149
- // issue update query
150
- $result = $wpdb->query("
151
- UPDATE $wpdb->links
152
- SET $alter_set
153
- WHERE link_id='$link_id'
154
- ");
155
- $updated_link = true;
156
-
157
- // reload link information from DB
158
- if (function_exists('clean_bookmark_cache')) :
159
- clean_bookmark_cache($link_id);
160
- endif;
161
- $link =& new SyndicatedLink($link_id);
162
  else :
163
- if ('newuser'==$GLOBALS['fwp_post']['unfamiliar_author']) :
164
- $newuser_name = trim($GLOBALS['fwp_post']['unfamiliar_author_newuser']);
165
- if (strlen($newuser_name) > 0) :
166
- $userdata = array();
167
- $userdata['ID'] = NULL;
168
-
169
- $userdata['user_login'] = sanitize_user($newuser_name);
170
- $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
171
-
172
- $userdata['user_nicename'] = sanitize_title($newuser_name);
173
- $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
174
-
175
- $userdata['display_name'] = $wpdb->escape($newuser_name);
176
-
177
- $newuser_id = wp_insert_user($userdata);
178
- if (is_numeric($newuser_id)) :
179
- update_option('feedwordpress_unfamiliar_author', $newuser_id);
180
- else :
181
- // TODO: Add some error detection and reporting
182
- endif;
183
- else :
184
- // TODO: Add some error reporting
185
- endif;
186
- else :
187
- update_option('feedwordpress_unfamiliar_author', $GLOBALS['fwp_post']['unfamiliar_author']);
188
- endif;
189
-
190
- if (isset($GLOBALS['fwp_post']['match_author_by_email']) and $GLOBALS['fwp_post']['match_author_by_email']=='yes') :
191
- update_option('feedwordpress_do_not_match_author_by_email', 'no');
192
- else :
193
- update_option('feedwordpress_do_not_match_author_by_email', 'yes');
194
- endif;
195
-
196
- if (isset($GLOBALS['fwp_post']['null_emails'])) :
197
- update_option('feedwordpress_null_email_set', $GLOBALS['fwp_post']['null_emails']);
198
- endif;
199
-
200
- $updated_link = true;
201
  endif;
202
- else :
203
- $updated_link = false;
 
 
 
 
204
  endif;
 
 
 
205
 
206
- $unfamiliar = array ('create' => '','default' => '','filter' => '');
207
 
208
- if (is_object($link) and $link->found()) :
209
- if (is_string($link->settings["unfamiliar author"])) :
210
- $key = $link->settings["unfamiliar author"];
211
- else:
212
- $key = 'site-default';
213
- endif;
214
- else :
215
- $key = FeedWordPress::on_unfamiliar('author');
216
  endif;
 
 
 
217
 
218
- $unfamiliar[$key] = ' selected="selected"';
219
 
220
- $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
221
- $null_emails = FeedWordPress::null_email_set();
222
  ?>
223
  <script type="text/javascript">
224
  function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) {
@@ -247,11 +245,20 @@ function fwp_authors_page () {
247
 
248
  <div class="wrap">
249
  <form style="position: relative" action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
250
- <?php if (is_numeric($link_id) and $link_id) : ?>
 
 
 
 
251
  <input type="hidden" name="save_link_id" value="<?php echo $link_id; ?>" />
252
- <?php else : ?>
 
 
253
  <input type="hidden" name="save_link_id" value="*" />
254
- <?php endif; ?>
 
 
 
255
 
256
  <?php $links = FeedWordPress::syndicated_links(); ?>
257
  <?php if (fwp_test_wp_version(FWP_SCHEMA_27)) : ?>
@@ -458,8 +465,7 @@ and instead
458
  </script>
459
  </form>
460
  </div> <!-- class="wrap" -->
461
- <?php
462
- endif;
463
  } /* function fwp_authors_page () */
464
 
465
  fwp_authors_page();
4
  function fwp_authors_page () {
5
  global $wpdb, $wp_db_version;
6
 
7
+ FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_author_settings', /*capability=*/ 'manage_links');
8
+
9
  if (isset($GLOBALS['fwp_post']['save']) or isset($GLOBALS['fwp_post']['fix_mismatch'])) :
10
  $link_id = $_REQUEST['save_link_id'];
11
  elseif (isset($_REQUEST['link_id'])) :
21
  endif;
22
 
23
  $mesg = null;
24
+
25
+ if (isset($GLOBALS['fwp_post']['fix_mismatch'])) :
26
+ if ('newuser'==$GLOBALS['fwp_post']['fix_mismatch_to']) :
27
+ $newuser_name = trim($GLOBALS['fwp_post']['fix_mismatch_to_newuser']);
28
+ if (strlen($newuser_name) > 0) :
29
+ $userdata = array();
30
+ $userdata['ID'] = NULL;
31
+
32
+ $userdata['user_login'] = sanitize_user($newuser_name);
33
+ $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
34
+
35
+ $userdata['user_nicename'] = sanitize_title($newuser_name);
36
+ $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
37
+
38
+ $userdata['display_name'] = $wpdb->escape($newuser_name);
39
+
40
+ $newuser_id = wp_insert_user($userdata);
41
+ if (is_numeric($newuser_id)) :
42
+ $fix_mismatch_to_id = $newuser_id;
43
+ else :
44
+ // TODO: Add some error detection and reporting
45
+ endif;
46
+ else :
47
+ // TODO: Add some error reporting
48
+ endif;
49
+ else :
50
+ $fix_mismatch_to_id = $GLOBALS['fwp_post']['fix_mismatch_to'];
51
+ endif;
52
+ $fix_mismatch_from_id = (int) $GLOBALS['fwp_post']['fix_mismatch_from'];
53
+ if (is_numeric($fix_mismatch_from_id)) :
54
+ // Make a list of all the items by this author syndicated from this feed...
55
+ $post_ids = $wpdb->get_col("
56
+ SELECT {$wpdb->posts}.id
57
+ FROM {$wpdb->posts}, {$wpdb->postmeta}
58
+ WHERE ({$wpdb->posts}.id = {$wpdb->postmeta}.post_id)
59
+ AND {$wpdb->postmeta}.meta_key = 'syndication_feed_id'
60
+ AND {$wpdb->postmeta}.meta_value = '{$link_id}'
61
+ AND {$wpdb->posts}.post_author = '{$fix_mismatch_from_id}'
62
+ ");
63
+
64
+ if (count($post_ids) > 0) :
65
+ // Re-assign them all to the correct author
66
+ if (is_numeric($fix_mismatch_to_id)) : // re-assign to a particular user
67
+ $post_set = "(".implode(",", $post_ids).")";
68
+
69
+ // Getting the revisions too, if there are any
70
+ if (fwp_test_wp_version(FWP_SCHEMA_26)) :
71
+ $parent_in_clause = "OR {$wpdb->posts}.post_parent IN $post_set";
72
+ else :
73
+ $parent_in_clause = '';
74
+ endif;
75
+
76
+ $wpdb->query("
77
+ UPDATE {$wpdb->posts}
78
+ SET post_author='{$fix_mismatch_to_id}'
79
+ WHERE ({$wpdb->posts}.id IN $post_set
80
+ $parent_in_clause)
81
+ ");
82
+ $mesg = "Re-assigned ".count($post_ids)." post".((count($post_ids)==1)?'':'s').".";
83
+
84
+ // ... and kill them all
85
+ elseif ($fix_mismatch_to_id=='filter') :
86
+ foreach ($post_ids as $post_id) :
87
+ wp_delete_post($post_id);
88
+ endforeach;
89
+ $mesg = "Deleted ".count($post_ids)." post".((count($post_ids)==1)?'':'s').".";
90
+ endif;
91
+ else :
92
+ $mesg = "Couldn't find any posts that matched your criteria.";
93
+ endif;
94
+ endif;
95
+ elseif (isset($GLOBALS['fwp_post']['save'])) :
96
+ if (is_object($link) and $link->found()) :
97
+ $alter = array ();
98
+
99
+ // Unfamiliar author rule
100
+ if (isset($GLOBALS['fwp_post']["unfamiliar_author"])) :
101
+ if ('site-default'==$GLOBALS['fwp_post']["unfamiliar_author"]) :
102
+ unset($link->settings["unfamiliar author"]);
103
+ elseif ('newuser'==$GLOBALS['fwp_post']["unfamiliar_author"]) :
104
+ $newuser_name = trim($GLOBALS['fwp_post']["unfamiliar_author_newuser"]);
105
+ $link->map_name_to_new_user(/*name=*/ NULL, $newuser_name);
106
+ else :
107
+ $link->settings["unfamiliar author"] = $GLOBALS['fwp_post']["unfamiliar_author"];
108
+ endif;
109
+ endif;
110
+
111
+ // Handle author mapping rules
112
+ if (isset($GLOBALS['fwp_post']['author_rules_name']) and isset($GLOBALS['fwp_post']['author_rules_action'])) :
113
+ unset($link->settings['map authors']);
114
+ foreach ($GLOBALS['fwp_post']['author_rules_name'] as $key => $name) :
115
+ // Normalize for case and whitespace
116
+ $name = strtolower(trim($name));
117
+ $author_action = strtolower(trim($GLOBALS['fwp_post']['author_rules_action'][$key]));
118
+
119
+ if (strlen($name) > 0) :
120
+ if ('newuser' == $author_action) :
121
+ $newuser_name = trim($GLOBALS['fwp_post']['author_rules_newuser'][$key]);
122
+ $link->map_name_to_new_user($name, $newuser_name);
123
+ else :
124
+ $link->settings['map authors']['name'][$name] = $author_action;
125
+ endif;
126
+ endif;
127
+ endforeach;
128
+ endif;
129
+
130
+ if (isset($GLOBALS['fwp_post']['add_author_rule_name']) and isset($GLOBALS['fwp_post']['add_author_rule_action'])) :
131
+ $name = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_name']));
132
+ $author_action = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_action']));
133
+ if (strlen($name) > 0) :
134
+ if ('newuser' == $author_action) :
135
+ $newuser_name = trim($GLOBALS['fwp_post']['add_author_rule_newuser']);
136
+ $link->map_name_to_new_user($name, $newuser_name);
137
+ else :
138
+ $link->settings['map authors']['name'][$name] = $author_action;
139
+ endif;
140
+ endif;
141
+ endif;
142
+
143
+ $alter[] = "link_notes = '".$wpdb->escape($link->settings_to_notes())."'";
144
+
145
+ $alter_set = implode(", ", $alter);
146
+
147
+ // issue update query
148
+ $result = $wpdb->query("
149
+ UPDATE $wpdb->links
150
+ SET $alter_set
151
+ WHERE link_id='$link_id'
152
+ ");
153
+ $updated_link = true;
154
+
155
+ // reload link information from DB
156
+ if (function_exists('clean_bookmark_cache')) :
157
+ clean_bookmark_cache($link_id);
158
+ endif;
159
+ $link =& new SyndicatedLink($link_id);
160
+ else :
161
+ if ('newuser'==$GLOBALS['fwp_post']['unfamiliar_author']) :
162
+ $newuser_name = trim($GLOBALS['fwp_post']['unfamiliar_author_newuser']);
163
  if (strlen($newuser_name) > 0) :
164
  $userdata = array();
165
  $userdata['ID'] = NULL;
174
 
175
  $newuser_id = wp_insert_user($userdata);
176
  if (is_numeric($newuser_id)) :
177
+ update_option('feedwordpress_unfamiliar_author', $newuser_id);
178
  else :
179
  // TODO: Add some error detection and reporting
180
  endif;
182
  // TODO: Add some error reporting
183
  endif;
184
  else :
185
+ update_option('feedwordpress_unfamiliar_author', $GLOBALS['fwp_post']['unfamiliar_author']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  endif;
187
+
188
+ if (isset($GLOBALS['fwp_post']['match_author_by_email']) and $GLOBALS['fwp_post']['match_author_by_email']=='yes') :
189
+ update_option('feedwordpress_do_not_match_author_by_email', 'no');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  else :
191
+ update_option('feedwordpress_do_not_match_author_by_email', 'yes');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  endif;
193
+
194
+ if (isset($GLOBALS['fwp_post']['null_emails'])) :
195
+ update_option('feedwordpress_null_email_set', $GLOBALS['fwp_post']['null_emails']);
196
+ endif;
197
+
198
+ $updated_link = true;
199
  endif;
200
+ else :
201
+ $updated_link = false;
202
+ endif;
203
 
204
+ $unfamiliar = array ('create' => '','default' => '','filter' => '');
205
 
206
+ if (is_object($link) and $link->found()) :
207
+ if (is_string($link->settings["unfamiliar author"])) :
208
+ $key = $link->settings["unfamiliar author"];
209
+ else:
210
+ $key = 'site-default';
 
 
 
211
  endif;
212
+ else :
213
+ $key = FeedWordPress::on_unfamiliar('author');
214
+ endif;
215
 
216
+ $unfamiliar[$key] = ' selected="selected"';
217
 
218
+ $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
219
+ $null_emails = FeedWordPress::null_email_set();
220
  ?>
221
  <script type="text/javascript">
222
  function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) {
245
 
246
  <div class="wrap">
247
  <form style="position: relative" action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
248
+ <div><?php
249
+ FeedWordPressCompatibility::stamp_nonce('feedwordpress_author_settings');
250
+
251
+ if (is_numeric($link_id) and $link_id) :
252
+ ?>
253
  <input type="hidden" name="save_link_id" value="<?php echo $link_id; ?>" />
254
+ <?php
255
+ else :
256
+ ?>
257
  <input type="hidden" name="save_link_id" value="*" />
258
+ <?php
259
+ endif;
260
+ ?>
261
+ </div>
262
 
263
  <?php $links = FeedWordPress::syndicated_links(); ?>
264
  <?php if (fwp_test_wp_version(FWP_SCHEMA_27)) : ?>
465
  </script>
466
  </form>
467
  </div> <!-- class="wrap" -->
468
+ <?php
 
469
  } /* function fwp_authors_page () */
470
 
471
  fwp_authors_page();
categories-page.php ADDED
@@ -0,0 +1,346 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once(dirname(__FILE__) . '/admin-ui.php');
3
+
4
+ function fwp_categories_page () {
5
+ global $wpdb, $wp_db_version;
6
+
7
+ FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_categories_settings', /*capability=*/ 'manage_links');
8
+
9
+ if (isset($GLOBALS['fwp_post']['save']) or isset($GLOBALS['fwp_post']['fix_mismatch'])) :
10
+ $link_id = $_REQUEST['save_link_id'];
11
+ elseif (isset($_REQUEST['link_id'])) :
12
+ $link_id = $_REQUEST['link_id'];
13
+ else :
14
+ $link_id = NULL;
15
+ endif;
16
+
17
+ if (is_numeric($link_id) and $link_id) :
18
+ $link =& new SyndicatedLink($link_id);
19
+ else :
20
+ $link = NULL;
21
+ endif;
22
+
23
+ $mesg = null;
24
+
25
+ ////////////////////////////////////////////////
26
+ // Process POST request, if any /////////////////
27
+ ////////////////////////////////////////////////
28
+ if (isset($GLOBALS['fwp_post']['save'])) :
29
+ $saveCats = array();
30
+ if (isset($GLOBALS['fwp_post']['post_category'])) :
31
+ foreach ($GLOBALS['fwp_post']['post_category'] as $cat_id) :
32
+ $saveCats[] = '{#'.$cat_id.'}';
33
+ endforeach;
34
+ endif;
35
+
36
+ if (is_object($link) and $link->found()) :
37
+ $alter = array ();
38
+
39
+ // Categories
40
+ if (!empty($saveCats)) : $link->settings['cats'] = $saveCats;
41
+ else : unset($link->settings['cats']);
42
+ endif;
43
+
44
+ // Tags
45
+ if (isset($GLOBALS['fwp_post']['tags_input'])) :
46
+ $link->settings['tags'] = array();
47
+ foreach (explode(',', $GLOBALS['fwp_post']['tags_input']) as $tag) :
48
+ $link->settings['tags'][] = trim($tag);
49
+ endforeach;
50
+ endif;
51
+
52
+ // Unfamiliar categories
53
+ if (isset($GLOBALS['fwp_post']["unfamiliar_category"])) :
54
+ if ('site-default'==$GLOBALS['fwp_post']["unfamiliar_category"]) :
55
+ unset($link->settings["unfamiliar category"]);
56
+ else :
57
+ $link->settings["unfamiliar category"] = $GLOBALS['fwp_post']["unfamiliar_category"];
58
+ endif;
59
+ endif;
60
+
61
+ // Category spitting regex
62
+ if (isset($GLOBALS['fwp_post']['cat_split'])) :
63
+ if (strlen(trim($GLOBALS['fwp_post']['cat_split'])) > 0) :
64
+ $link->settings['cat_split'] = trim($GLOBALS['fwp_post']['cat_split']);
65
+ else :
66
+ unset($link->settings['cat_split']);
67
+ endif;
68
+ endif;
69
+
70
+ $alter[] = "link_notes = '".$wpdb->escape($link->settings_to_notes())."'";
71
+
72
+ $alter_set = implode(", ", $alter);
73
+
74
+ // issue update query
75
+ $result = $wpdb->query("
76
+ UPDATE $wpdb->links
77
+ SET $alter_set
78
+ WHERE link_id='$link_id'
79
+ ");
80
+ $updated_link = true;
81
+
82
+ // reload link information from DB
83
+ if (function_exists('clean_bookmark_cache')) :
84
+ clean_bookmark_cache($link_id);
85
+ endif;
86
+ $link =& new SyndicatedLink($link_id);
87
+ else :
88
+ // Categories
89
+ if (!empty($saveCats)) :
90
+ update_option('feedwordpress_syndication_cats', implode(FEEDWORDPRESS_CAT_SEPARATOR, $saveCats));
91
+ else :
92
+ delete_option('feedwordpress_syndication_cats');
93
+ endif;
94
+
95
+ // Tags
96
+ if (isset($_REQUEST['tags_input'])) :
97
+ $tags = explode(",", $_REQUEST['tags_input']);
98
+ else :
99
+ $tags = array();
100
+ endif;
101
+
102
+ if (!empty($tags)) :
103
+ update_option('feedwordpress_syndication_tags', implode(FEEDWORDPRESS_CAT_SEPARATOR, $tags));
104
+ else :
105
+ delete_option('feedwordpress_syndication_tags');
106
+ endif;
107
+
108
+ update_option('feedwordpress_unfamiliar_category', $_REQUEST['unfamiliar_category']);
109
+
110
+ $updated_link = true;
111
+ endif;
112
+ else :
113
+ $updated_link = false;
114
+ endif;
115
+
116
+ ////////////////////////////////////////////////
117
+ // Get defaults from database //////////////////
118
+ ////////////////////////////////////////////////
119
+
120
+ $unfamiliar = array ('create'=>'','tag' => '', 'default'=>'','filter'=>'');
121
+ if (is_object($link) and $link->found()) :
122
+ $unfamiliar['site-default'] = '';
123
+ $ucKey = $link->settings["unfamiliar category"];
124
+ $ucDefault = 'site-default';
125
+
126
+ if (is_array($link->settings['cats'])) : $cats = $link->settings['cats'];
127
+ else : $cats = array();
128
+ endif;
129
+
130
+ $tags = $link->settings['tags'];
131
+ else :
132
+ $ucKey = FeedWordPress::on_unfamiliar('category');
133
+ $ucDefault = 'create';
134
+
135
+ $cats = array_map('trim',
136
+ preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_cats'))
137
+ );
138
+ $tags = array_map('trim',
139
+ preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, get_option('feedwordpress_syndication_tags'))
140
+ );
141
+ endif;
142
+
143
+ if (!is_string($ucKey) or !array_key_exists($ucKey, $unfamiliar)) :
144
+ $ucKey = $ucDefault;
145
+ endif;
146
+ $unfamiliar[$ucKey] = ' checked="checked"';
147
+
148
+ $dogs = SyndicatedPost::category_ids($cats, /*unfamiliar=*/ NULL);
149
+ ?>
150
+ <script type="text/javascript">
151
+ function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) {
152
+ if (typeof(visibleStyle)=='undefined') visibleStyle = 'block';
153
+
154
+ var rollup=document.getElementById(item);
155
+ var newuser=document.getElementById(appear);
156
+ var sitewide=document.getElementById(disappear);
157
+ if (rollup) {
158
+ if ((checkbox && rollup.checked) || (!checkbox && value==rollup.value)) {
159
+ if (newuser) newuser.style.display=visibleStyle;
160
+ if (sitewide) sitewide.style.display='none';
161
+ } else {
162
+ if (newuser) newuser.style.display='none';
163
+ if (sitewide) sitewide.style.display=visibleStyle;
164
+ }
165
+ }
166
+ }
167
+ </script>
168
+
169
+ <?php if ($updated_link) : ?>
170
+ <div class="updated"><p>Syndicated categories and tags settings updated.</p></div>
171
+ <?php elseif (!is_null($mesg)) : ?>
172
+ <div class="updated"><p><?php print wp_specialchars($mesg, 1); ?></p></div>
173
+ <?php endif; ?>
174
+
175
+ <div class="wrap">
176
+ <form style="position: relative" action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
177
+ <div><?php
178
+ FeedWordPressCompatibility::stamp_nonce('feedwordpress_categories_settings');
179
+
180
+ if (is_numeric($link_id) and $link_id) :
181
+ ?>
182
+ <input type="hidden" name="save_link_id" value="<?php echo $link_id; ?>" />
183
+ <?php
184
+ else :
185
+ ?>
186
+ <input type="hidden" name="save_link_id" value="*" />
187
+ <?php
188
+ endif;
189
+ ?>
190
+ </div>
191
+
192
+ <?php $links = FeedWordPress::syndicated_links(); ?>
193
+ <?php if (fwp_test_wp_version(FWP_SCHEMA_27)) : ?>
194
+ <div class="icon32"><img src="<?php print htmlspecialchars(WP_PLUGIN_URL.'/'.$GLOBALS['fwp_path'].'/feedwordpress.png'); ?>" alt="" /></div>
195
+ <?php endif; ?>
196
+ <h2>Categories &amp; Tags Settings<?php if (!is_null($link) and $link->found()) : ?>: <?php echo wp_specialchars($link->link->link_name, 1); ?><?php endif; ?></h2>
197
+
198
+ <style type="text/css">
199
+ table.edit-form th { width: 27%; vertical-align: top; }
200
+ table.edit-form td { width: 73%; vertical-align: top; }
201
+ table.edit-form td ul.options { margin: 0; padding: 0; list-style: none; }
202
+ </style>
203
+
204
+ <?php if (fwp_test_wp_version(FWP_SCHEMA_27)) : ?>
205
+ <style type="text/css">
206
+ #post-search {
207
+ float: right;
208
+ margin:11px 12px 0;
209
+ min-width: 130px;
210
+ position:relative;
211
+ }
212
+ .fwpfs {
213
+ color: #dddddd;
214
+ background:#797979 url(<?php bloginfo('home') ?>/wp-admin/images/fav.png) repeat-x scroll left center;
215
+ border-color:#777777 #777777 #666666 !important; -moz-border-radius-bottomleft:12px;
216
+ -moz-border-radius-bottomright:12px;
217
+ -moz-border-radius-topleft:12px;
218
+ -moz-border-radius-topright:12px;
219
+ border-style:solid;
220
+ border-width:1px;
221
+ line-height:15px;
222
+ padding:3px 30px 4px 12px;
223
+ }
224
+ .fwpfs.slide-down {
225
+ border-bottom-color: #626262;
226
+ -moz-border-radius-bottomleft:0;
227
+ -moz-border-radius-bottomright:0;
228
+ -moz-border-radius-topleft:12px;
229
+ -moz-border-radius-topright:12px;
230
+ background-image:url(<?php bloginfo('home') ?>/wp-admin/images/fav-top.png);
231
+ background-position:0 top;
232
+ background-repeat:repeat-x;
233
+ border-bottom-style:solid;
234
+ border-bottom-width:1px;
235
+ }
236
+ </style>
237
+
238
+ <script type="text/javascript">
239
+ jQuery(document).ready(function($){
240
+ $('.fwpfs').toggle(
241
+ function(){$('.fwpfs').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideDown') ) { $('.fwpfs').addClass('slide-down'); }}, 10) },
242
+ function(){$('.fwpfs').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideUp') ) { $('.fwpfs').removeClass('slide-down'); }}, 10) }
243
+ );
244
+ $('.fwpfs').bind(
245
+ 'change',
246
+ function () { this.form.submit(); }
247
+ );
248
+ $('#post-search .button').css( 'display', 'none' );
249
+ });
250
+ </script>
251
+ <?php endif; /* else : */?>
252
+ <p id="post-search">
253
+ <select name="link_id" class="fwpfs" style="max-width: 20.0em;">
254
+ <option value="*"<?php if (is_null($link) or !$link->found()) : ?> selected="selected"<?php endif; ?>>- defaults for all feeds -</option>
255
+ <?php if ($links) : foreach ($links as $ddlink) : ?>
256
+ <option value="<?php print (int) $ddlink->link_id; ?>"<?php if (!is_null($link) and ($link->link->link_id==$ddlink->link_id)) : ?> selected="selected"<?php endif; ?>><?php print wp_specialchars($ddlink->link_name, 1); ?></option>
257
+ <?php endforeach; endif; ?>
258
+ </select>
259
+ <input class="button" type="submit" name="go" value="<?php _e('Go') ?> &raquo;" />
260
+ </p>
261
+ <?php /* endif; */ ?>
262
+
263
+ <?php if (!is_null($link) and $link->found()) : ?>
264
+ <p>These settings only affect posts syndicated from
265
+ <strong><?php echo wp_specialchars($link->link->link_name, 1); ?></strong>.</p>
266
+ <?php else : ?>
267
+ <p>These settings affect posts syndicated from any feed unless they are overridden
268
+ by settings for that specific feed.</p>
269
+ <?php endif; ?>
270
+
271
+ <div id="poststuff">
272
+ <div id="post-body">
273
+ <?php
274
+ fwp_option_box_opener(__('Categories'), 'categorydiv', 'postbox');
275
+ fwp_category_box($dogs, 'all syndicated posts'.((is_object($link) and $link->found()) ? ' from this feed':''));
276
+ ?>
277
+ <table class="edit-form">
278
+ <tr>
279
+ <th scope="row">Unfamiliar categories:</th>
280
+ <td><p>When one of the categories on a syndicated post is a category that FeedWordPress has not encountered before ...</p>
281
+
282
+ <ul class="options">
283
+ <?php if (is_object($link) and ($link->found())) : ?>
284
+ <li><label><input type="radio" name="unfamiliar_category" value="site-default"<?php echo $unfamiliar['site-default']; ?> /> use the <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php print basename(__FILE__); ?>">site-wide setting</a>
285
+ (currently <strong><?php echo FeedWordPress::on_unfamiliar('category'); ?></strong>)</label></li>
286
+ <?php endif; ?>
287
+
288
+ <li><label><input type="radio" name="unfamiliar_category" value="create"<?php echo $unfamiliar['create']; ?> /> create a new category</label></li>
289
+
290
+ <?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?>
291
+ <li><label><input type="radio" name="unfamiliar_category" value="tag"<?php echo $unfamiliar['tag']; ?>/> create a new tag</label></li>
292
+ <?php endif; ?>
293
+
294
+ <li><label><input type="radio" name="unfamiliar_category" value="default"<?php echo $unfamiliar['default']; ?> /> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?> or tags<?php endif; ?></label></li>
295
+ <li><label><input type="radio" name="unfamiliar_category" value="filter"<?php echo $unfamiliar['filter']; ?> /> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?> or tags<?php endif; ?> and don't syndicate posts unless they match at least one familiar category</label></li>
296
+ </ul></td>
297
+ </tr>
298
+
299
+ <?php if (is_object($link) and $link->found()) : ?>
300
+ <tr>
301
+ <th scope="row">Multiple categories:</th>
302
+ <td>
303
+ <input type="text" size="20" id="cat_split" name="cat_split" value="<?php if (isset($link->settings['cat_split'])) : echo htmlspecialchars($link->settings['cat_split']); endif; ?>" />
304
+ <p class="setting-description">Enter a <a href="http://us.php.net/manual/en/reference.pcre.pattern.syntax.php">Perl-compatible regular expression</a> here if the feed provides multiple
305
+ categories in a single category element. The regular expression should match
306
+ the characters used to separate one category from the next. If the feed uses
307
+ spaces (like <a href="http://del.icio.us/">del.icio.us</a>), use the pattern "\s".
308
+ If the feed does not provide multiple categories in a single element, leave this
309
+ blank.</p></td>
310
+ </tr>
311
+ <?php endif; ?>
312
+ </table>
313
+ <?php
314
+ fwp_option_box_closer();
315
+ fwp_linkedit_periodic_submit();
316
+
317
+ if (isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25) :
318
+ fwp_tags_box($tags);
319
+ fwp_linkedit_periodic_submit();
320
+ endif; ?>
321
+ </div>
322
+ </div>
323
+
324
+ <p class="submit">
325
+ <input class="button-primary" type="submit" name="save" value="Save Changes" />
326
+ </p>
327
+
328
+ <script type="text/javascript">
329
+ contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser', 'inline');
330
+ <?php if (is_object($link) and $link->found()) : ?>
331
+ <?php for ($j=1; $j<=$i; $j++) : ?>
332
+ contextual_appearance('author-rules-<?php echo $j; ?>', 'author-rules-<?php echo $j; ?>-newuser', 'author-rules-<?php echo $j; ?>-default', 'newuser', 'inline');
333
+ <?php endfor; ?>
334
+ contextual_appearance('add-author-rule', 'add-author-rule-newuser', 'add-author-rule-default', 'newuser', 'inline');
335
+ contextual_appearance('fix-mismatch-to', 'fix-mismatch-to-newuser', null, 'newuser', 'inline');
336
+ <?php else : ?>
337
+ contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', 'block', /*checkbox=*/ true);
338
+ <?php endif; ?>
339
+ </script>
340
+ </form>
341
+ </div> <!-- class="wrap" -->
342
+ <?php
343
+ } /* function fwp_categories_page () */
344
+
345
+ fwp_categories_page();
346
+
compatability.php CHANGED
@@ -15,6 +15,34 @@ function fwp_test_wp_version ($floor, $ceiling = NULL) {
15
  return $good;
16
  } /* function fwp_test_wp_version () */
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  if (!function_exists('stripslashes_deep')) {
19
  function stripslashes_deep($value) {
20
  $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
@@ -45,6 +73,9 @@ if (!function_exists('current_user_can')) {
45
  case 'manage_links':
46
  $can = ($user_level >= 5);
47
  break;
 
 
 
48
  endswitch;
49
  return $can;
50
  }
@@ -83,7 +114,13 @@ if (!function_exists('wp_insert_user')) {
83
 
84
  return $id;
85
  }
86
- }
 
 
 
 
 
 
87
 
88
  function fwp_category_checklist ($post_id = 0, $descendents_and_self = 0, $selected_cats = false) {
89
  if (function_exists('wp_category_checklist')) :
@@ -163,6 +200,7 @@ like me you may want to back up your database before you proceed.</p>
163
  <p>This may take several minutes for a large installation.</p>
164
 
165
  <form action="" method="post">
 
166
  <div class="submit"><input type="submit" name="action" value="Upgrade" /></div>
167
  </form>
168
  </div>
15
  return $good;
16
  } /* function fwp_test_wp_version () */
17
 
18
+ class FeedWordPressCompatibility {
19
+ /*static*/ function validate_http_request ($action = -1, $capability = null) {
20
+ // Only worry about this if we're using a method with significant side-effects
21
+ if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') :
22
+ // Limit post by user capabilities
23
+ if (!is_null($capability) and !current_user_can($capability)) :
24
+ wp_die(__('Cheatin&#8217; uh?'));
25
+ endif;
26
+
27
+ // If check_admin_referer() checks a nonce.
28
+ if (function_exists('wp_verify_nonce')) :
29
+ check_admin_referer($action);
30
+
31
+ // No nonces means no checking nonces.
32
+ else :
33
+ check_admin_referer();
34
+ endif;
35
+ endif;
36
+ } /* FeedWordPressCompatibility::validate_http_request() */
37
+
38
+ /*static*/ function stamp_nonce ($action = -1) {
39
+ // stamp form with hidden fields for a nonce in WP 2.0.3 & later
40
+ if (function_exists('wp_nonce_field')) :
41
+ wp_nonce_field($action);
42
+ endif;
43
+ } /* FeedWordPressCompatibility::stamp_nonce() */
44
+ } /* class FeedWordPressCompatibility */
45
+
46
  if (!function_exists('stripslashes_deep')) {
47
  function stripslashes_deep($value) {
48
  $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
73
  case 'manage_links':
74
  $can = ($user_level >= 5);
75
  break;
76
+ case 'edit_files':
77
+ $can = ($user_level >= 9);
78
+ break;
79
  endswitch;
80
  return $can;
81
  }
114
 
115
  return $id;
116
  }
117
+ } /* if (!function_exists('wp_insert_user')) */
118
+
119
+ if (!function_exists('wp_die')) {
120
+ function wp_die ( $message, $title = '', $args = array() ) {
121
+ die($message);
122
+ } /* wp_die() */
123
+ } /* if */
124
 
125
  function fwp_category_checklist ($post_id = 0, $descendents_and_self = 0, $selected_cats = false) {
126
  if (function_exists('wp_category_checklist')) :
200
  <p>This may take several minutes for a large installation.</p>
201
 
202
  <form action="" method="post">
203
+ <?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_upgrade'); ?>
204
  <div class="submit"><input type="submit" name="action" value="Upgrade" /></div>
205
  </form>
206
  </div>
feedwordpress.php CHANGED
@@ -3,11 +3,10 @@
3
  Plugin Name: FeedWordPress
4
  Plugin URI: http://projects.radgeek.com/feedwordpress
5
  Description: simple and flexible Atom/RSS syndication for WordPress
6
- Version: 2008.1214
7
  Author: Charles Johnson
8
  Author URI: http://radgeek.com/
9
  License: GPL
10
- Last modified: 2008-12-14 4:29pm PST
11
  */
12
 
13
  # This uses code derived from:
@@ -29,11 +28,15 @@ Last modified: 2008-12-14 4:29pm PST
29
 
30
  # -- Don't change these unless you know what you're doing...
31
 
32
- define ('FEEDWORDPRESS_VERSION', '2008.1214');
33
  define ('FEEDWORDPRESS_AUTHOR_CONTACT', 'http://radgeek.com/contact');
34
  define ('DEFAULT_SYNDICATION_CATEGORY', 'Contributors');
35
 
36
- define ('FEEDWORDPRESS_DEBUG', false);
 
 
 
 
37
 
38
  define ('FEEDWORDPRESS_CAT_SEPARATOR_PATTERN', '/[:\n]/');
39
  define ('FEEDWORDPRESS_CAT_SEPARATOR', "\n");
@@ -89,6 +92,7 @@ if (isset($wp_db_version)) :
89
  endif;
90
 
91
  require_once(dirname(__FILE__) . '/compatability.php'); // LEGACY API: Replicate or mock up functions for legacy support purposes
 
92
 
93
  // Magic quotes are just about the stupidest thing ever.
94
  if (is_array($_POST)) :
@@ -164,7 +168,9 @@ if (!FeedWordPress::needs_upgrade()) : // only work if the conditions are safe!
164
 
165
  # Admin menu
166
  add_action('admin_menu', 'fwp_add_pages');
167
-
 
 
168
  # Inbound XML-RPC update methods
169
  add_filter('xmlrpc_methods', 'feedwordpress_xmlrpc_hook');
170
 
@@ -190,8 +196,10 @@ if (!FeedWordPress::needs_upgrade()) : // only work if the conditions are safe!
190
 
191
  # Cron-less auto-update. Hooray!
192
  add_action('init', 'feedwordpress_auto_update');
 
193
 
194
  # Default sanitizers
 
195
  add_filter('syndicated_item_content', array('SyndicatedPost', 'sanitize_content'), 0, 2);
196
 
197
  else :
@@ -199,6 +207,31 @@ else :
199
  add_action('admin_menu', 'fwp_add_pages');
200
  endif; // if (!FeedWordPress::needs_upgrade())
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  function feedwordpress_auto_update () {
203
  if (FeedWordPress::stale()) :
204
  $feedwordpress =& new FeedWordPress;
@@ -364,7 +397,11 @@ $feedwordpress_the_syndicated_content = NULL;
364
  function feedwordpress_preserve_syndicated_content ($text) {
365
  global $feedwordpress_the_syndicated_content;
366
 
367
- if ( is_syndicated() and get_option('feedwordpress_formatting_filters') != 'yes' ) :
 
 
 
 
368
  $feedwordpress_the_syndicated_content = $text;
369
  else :
370
  $feedwordpress_the_syndicated_content = NULL;
@@ -440,11 +477,128 @@ function fwp_add_pages () {
440
  endif;
441
 
442
  call_user_func_array('add_menu_page', $menu);
443
- add_submenu_page($fwp_path.'/syndication.php', 'Syndicated Authors', 'Authors', $fwp_capability['manage_options'], $fwp_path.'/authors.php');
 
 
444
  add_submenu_page($fwp_path.'/syndication.php', $longoptions, $options, $fwp_capability['manage_options'], $fwp_path.'/syndication-options.php');
445
 
446
  add_options_page($longoptions, 'Syndication', $fwp_capability['manage_options'], $fwp_path.'/syndication-options.php');
447
- } // function fwp_add_pages () */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
 
449
  ################################################################################
450
  ## fwp_hold_pings() and fwp_release_pings(): Outbound XML-RPC ping reform ####
@@ -801,10 +955,10 @@ class FeedWordPress {
801
  if (function_exists('is_term')) :
802
  $cat_id = is_term($cat, 'link_category');
803
  // WordPress 2.1 and 2.2 use a common table for both link and post categories
804
- elseif (isset($wp_db_version) and ($wp_db_version >= FWP_SCHEMA_21 and $wp_db_version < FWP_SCHEMA_23) ) :
805
  $cat_id = $wpdb->get_var("SELECT cat_id FROM {$wpdb->categories} WHERE cat_name='$cat'");
806
  // WordPress 1.5 and 2.0.x have a separate table for link categories
807
- elseif (!isset($wp_db_version) or $wp_db_version < FWP_SCHEMA_21) :
808
  $cat_id = $wpdb->get_var("SELECT cat_id FROM {$wpdb->linkcategories} WHERE cat_name='$cat'");
809
  // This should never happen.
810
  else :
@@ -942,6 +1096,13 @@ class FeedWordPress {
942
  ");
943
  } /* FeedWordPress::create_guid_index () */
944
 
 
 
 
 
 
 
 
945
  # Utility functions for handling text settings
946
  function negative ($f, $setting) {
947
  $nego = array ('n', 'no', 'f', 'false');
@@ -958,11 +1119,16 @@ class FeedWordPress {
958
  function critical_bug ($varname, $var, $line) {
959
  global $wp_version;
960
 
 
 
 
 
961
  echo '<p>There may be a bug in FeedWordPress. Please <a href="'.FEEDWORDPRESS_AUTHOR_CONTACT.'">contact the author</a> and paste the following information into your e-mail:</p>';
962
  echo "\n<plaintext>";
963
  echo "Triggered at line # ".$line."\n";
964
  echo "FeedWordPress version: ".FEEDWORDPRESS_VERSION."\n";
965
- echo "WordPress version: $wp_version\n";
 
966
  echo "PHP version: ".phpversion()."\n";
967
  echo "\n";
968
  echo $varname.": "; var_dump($var); echo "\n";
@@ -984,7 +1150,6 @@ class SyndicatedPost {
984
  var $feedmeta = null;
985
 
986
  var $post = array ();
987
- var $_base = null;
988
 
989
  var $_freshness = null;
990
  var $_wp_id = null;
@@ -1030,7 +1195,9 @@ class SyndicatedPost {
1030
 
1031
  # Identify content and sanitize it.
1032
  # ---------------------------------
1033
- if (isset($this->item['xhtml']['body'])) :
 
 
1034
  $content = $this->item['xhtml']['body'];
1035
  elseif (isset($this->item['xhtml']['div'])) :
1036
  $content = $this->item['xhtml']['div'];
@@ -1081,6 +1248,24 @@ class SyndicatedPost {
1081
  // Unique ID (hopefully a unique tag: URI); failing that, the permalink
1082
  $this->post['guid'] = apply_filters('syndicated_item_guid', $this->guid(), $this);
1083
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1084
  // RSS 2.0 / Atom 1.0 enclosure support
1085
  if ( isset($this->item['enclosure#']) ) :
1086
  for ($i = 1; $i <= $this->item['enclosure#']; $i++) :
@@ -1323,185 +1508,221 @@ class SyndicatedPost {
1323
 
1324
  function insert_new () {
1325
  global $wpdb, $wp_db_version;
1326
-
1327
- // Why the fuck doesn't wp_insert_post already do this?
1328
- foreach ($this->post as $key => $value) :
1329
- if (is_string($value)) :
1330
- $dbpost[$key] = $wpdb->escape($value);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1331
  else :
1332
- $dbpost[$key] = $value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1333
  endif;
1334
- endforeach;
1335
-
1336
- if (strlen($dbpost['post_title'].$dbpost['post_content'].$dbpost['post_excerpt']) == 0) :
1337
- // FIXME: Option for filtering out empty posts
1338
  endif;
1339
- if (strlen($dbpost['post_title'])==0) :
1340
- $dbpost['post_title'] = $this->post['meta']['syndication_source']
1341
- .' '.gmdate('Y-m-d H:i:s', $this->published() + $offset);
1342
- // FIXME: Option for what to fill a blank title with...
1343
- endif;
1344
-
1345
- if ($this->use_api('wp_insert_post')) :
1346
- $dbpost['post_pingback'] = false; // Tell WP 2.1 and 2.2 not to process for pingbacks
1347
 
1348
- // This is a ridiculous fucking kludge necessitated by WordPress 2.6 munging authorship meta-data
1349
- add_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
1350
-
1351
- // Kludge to prevent kses filters from stripping the
1352
- // content of posts when updating without a logged in
1353
- // user who has `unfiltered_html` capability.
1354
- add_filter('content_save_pre', array($this, 'avoid_kses_munge'), 11);
1355
-
1356
- $this->_wp_id = wp_insert_post($dbpost);
1357
 
1358
- // Turn off ridiculous fucking kludges #1 and #2
1359
- remove_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
1360
- remove_filter('content_save_pre', array($this, 'avoid_kses_munge'), 11);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1361
 
1362
- // This should never happen.
1363
- if (!is_numeric($this->_wp_id) or ($this->_wp_id == 0)) :
1364
- FeedWordPress::critical_bug('SyndicatedPost (_wp_id problem)', array("dbpost" => $dbpost, "this" => $this), __LINE__);
1365
- endif;
1366
 
1367
- // Unfortunately, as of WordPress 2.3, wp_insert_post()
1368
- // *still* offers no way to use a guid of your choice,
1369
- // and munges your post modified timestamp, too.
1370
- $result = $wpdb->query("
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1371
  UPDATE $wpdb->posts
1372
  SET
1373
- guid='{$dbpost['guid']}',
1374
- post_modified='{$dbpost['post_modified']}',
1375
- post_modified_gmt='{$dbpost['post_modified_gmt']}'
1376
- WHERE ID='{$this->_wp_id}'
1377
- ");
1378
- else :
1379
- # The right way to do this is the above. But, alas,
1380
- # in earlier versions of WordPress, wp_insert_post has
1381
- # too much behavior (mainly related to pings) that can't
1382
- # be overridden. In WordPress 1.5, it's enough of a
1383
- # resource hog to make PHP segfault after inserting
1384
- # 50-100 posts. This can get pretty annoying, especially
1385
- # if you are trying to update your feeds for the first
1386
- # time.
1387
-
1388
- $result = $wpdb->query("
1389
- INSERT INTO $wpdb->posts
1390
- SET
1391
- guid = '{$dbpost['guid']}',
1392
- post_author = '{$dbpost['post_author']}',
1393
- post_date = '{$dbpost['post_date']}',
1394
- post_date_gmt = '{$dbpost['post_date_gmt']}',
1395
- post_content = '{$dbpost['post_content']}',"
1396
- .(isset($dbpost['post_excerpt']) ? "post_excerpt = '{$dbpost['post_excerpt']}'," : "")."
1397
- post_title = '{$dbpost['post_title']}',
1398
- post_name = '{$dbpost['post_name']}',
1399
- post_modified = '{$dbpost['post_modified']}',
1400
- post_modified_gmt = '{$dbpost['post_modified_gmt']}',
1401
- comment_status = '{$dbpost['comment_status']}',
1402
- ping_status = '{$dbpost['ping_status']}',
1403
- post_status = '{$dbpost['post_status']}'
1404
- ");
1405
- $this->_wp_id = $wpdb->insert_id;
1406
-
1407
- // This should never happen.
1408
- if (!is_numeric($this->_wp_id) or ($this->_wp_id == 0)) :
1409
- FeedWordPress::critical_bug('SyndicatedPost (_wp_id problem)', array("dbpost" => $dbpost, "this" => $this), __LINE__);
1410
  endif;
1411
-
1412
- // WordPress 1.5.x - 2.0.x
1413
- wp_set_post_cats('1', $this->wp_id(), $this->post['post_category']);
1414
-
1415
- // Since we are not going through official channels, we need to
1416
- // manually tell WordPress that we've published a new post.
1417
- // We need to make sure to do this in order for FeedWordPress
1418
- // to play well with the staticize-reloaded plugin (something
1419
- // that a large aggregator website is going to *want* to be
1420
- // able to use).
1421
- do_action('publish_post', $this->_wp_id);
1422
  endif;
1423
- } /* SyndicatedPost::insert_new() */
1424
 
1425
- function update_existing () {
 
 
 
 
 
 
1426
  global $wpdb;
1427
 
 
 
1428
  // Why the fuck doesn't wp_insert_post already do this?
1429
- $dbpost = array();
1430
  foreach ($this->post as $key => $value) :
1431
  if (is_string($value)) :
1432
- $dbpost[$key] = $wpdb->escape($value);
1433
  else :
1434
- $dbpost[$key] = $value;
1435
  endif;
1436
  endforeach;
1437
 
1438
- if ($this->use_api('wp_insert_post')) :
1439
- $dbpost['post_pingback'] = false; // Tell WP 2.1 and 2.2 not to process for pingbacks
1440
-
1441
- // This is a ridiculous fucking kludge necessitated by WordPress 2.6 munging authorship meta-data
1442
- add_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
1443
-
1444
- // Kludge to prevent kses filters from stripping the
1445
- // content of posts when updating without a logged in
1446
- // user who has `unfiltered_html` capability.
1447
- add_filter('content_save_pre', array($this, 'avoid_kses_munge'), 11);
1448
-
1449
- $this->_wp_id = wp_insert_post($dbpost);
1450
-
1451
- // Turn off ridiculous fucking kludges #1 and #2
1452
- remove_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
1453
- remove_filter('content_save_pre', array($this, 'avoid_kses_munge'), 11);
1454
-
1455
- // This should never happen.
1456
- if (!is_numeric($this->_wp_id) or ($this->_wp_id == 0)) :
1457
- FeedWordPress::critical_bug('SyndicatedPost (_wp_id problem)', array("dbpost" => $dbpost, "this" => $this), __LINE__);
1458
- endif;
1459
 
1460
- // Unfortunately, as of WordPress 2.3, wp_insert_post()
1461
- // munges your post modified timestamp.
1462
- $result = $wpdb->query("
1463
- UPDATE $wpdb->posts
1464
- SET
1465
- post_modified='{$dbpost['post_modified']}',
1466
- post_modified_gmt='{$dbpost['post_modified_gmt']}'
1467
- WHERE ID='{$this->_wp_id}'
1468
- ");
1469
- else :
1470
 
1471
- $result = $wpdb->query("
1472
- UPDATE $wpdb->posts
1473
- SET
1474
- post_author = '{$dbpost['post_author']}',
1475
- post_content = '{$dbpost['post_content']}',"
1476
- .(isset($dbpost['post_excerpt']) ? "post_excerpt = '{$dbpost['post_excerpt']}'," : "")."
1477
- post_title = '{$dbpost['post_title']}',
1478
- post_name = '{$dbpost['post_name']}',
1479
- post_modified = '{$dbpost['post_modified']}',
1480
- post_modified_gmt = '{$dbpost['post_modified_gmt']}'
1481
- WHERE guid='{$dbpost['guid']}'
1482
- ");
1483
-
1484
- // WordPress 2.1.x and up
1485
- if (function_exists('wp_set_post_categories')) :
1486
- wp_set_post_categories($this->wp_id(), $this->post['post_category']);
1487
- // WordPress 1.5.x - 2.0.x
1488
- elseif (function_exists('wp_set_post_cats')) :
1489
- wp_set_post_cats('1', $this->wp_id(), $this->post['post_category']);
1490
- // This should never happen.
1491
- else :
1492
- FeedWordPress::critical_bug('SyndicatedPost (_wp_id problem)', array("dbpost" => $dbpost, "this" => $this), __LINE__);
1493
- endif;
1494
-
1495
- // Since we are not going through official channels, we need to
1496
- // manually tell WordPress that we've published a new post.
1497
- // We need to make sure to do this in order for FeedWordPress
1498
- // to play well with the staticize-reloaded plugin (something
1499
- // that a large aggregator website is going to *want* to be
1500
- // able to use).
1501
- do_action('edit_post', $this->post['ID']);
1502
  endif;
1503
- } /* SyndicatedPost::update_existing() */
1504
-
1505
  /**
1506
  * SyndicatedPost::fix_revision_meta() - Fixes the way WP 2.6+ fucks up
1507
  * meta-data (authorship, etc.) when storing revisions of an updated
@@ -2028,23 +2249,85 @@ class SyndicatedPost {
2028
  return $author;
2029
  } // SyndicatedPost::author()
2030
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2031
  var $strip_attrs = array (
2032
- array('[a-z]+', 'style'),
2033
- array('[a-z]+', 'target'),
 
2034
  );
 
 
 
 
 
 
2035
  function sanitize_content ($content, $obj) {
2036
- # FeedWordPress used to resolve URIs relative to the
2037
- # feed URI. It now relies on the xml:base support
2038
- # baked in to the MagpieRSS upgrade. So all we do here
2039
- # now is to sanitize problematic attributes.
2040
- #
2041
  # This kind of sucks. I intend to replace it with
2042
  # lib_filter sometime soon.
2043
  foreach ($obj->strip_attrs as $pair):
2044
  list($tag,$attr) = $pair;
2045
- $content = preg_replace (
2046
- ":(<$tag [^>]*)($attr=(\"[^\">]*\"|[^>\\s]+))([^>]*>):i",
2047
- "\\1\\4",
 
 
2048
  $content
2049
  );
2050
  endforeach;
@@ -2052,435 +2335,7 @@ class SyndicatedPost {
2052
  }
2053
  } // class SyndicatedPost
2054
 
2055
- # class SyndicatedLink: represents a syndication feed stored within the
2056
- # WordPress database
2057
- #
2058
- # To keep things compact and editable from within WordPress, we use all the
2059
- # links under a particular category in the WordPress "Blogroll" for the list of
2060
- # feeds to syndicate. "Contributors" is the category used by default; you can
2061
- # configure that under Options --> Syndication.
2062
- #
2063
- # Fields used are:
2064
- #
2065
- # * link_rss: the URI of the Atom/RSS feed to syndicate
2066
- #
2067
- # * link_notes: user-configurable options, with keys and values
2068
- # like so:
2069
- #
2070
- # key: value
2071
- # cats: computers\nweb
2072
- # feed/key: value
2073
- #
2074
- # Keys that start with "feed/" are gleaned from the data supplied
2075
- # by the feed itself, and will be overwritten with each update.
2076
- #
2077
- # Values have linebreak characters escaped with C-style
2078
- # backslashes (so, for example, a newline becomes "\n").
2079
- #
2080
- # The value of `cats` is used as a newline-separated list of
2081
- # default categories for any post coming from a particular feed.
2082
- # (In the example above, any posts from this feed will be placed
2083
- # in the "computers" and "web" categories--*in addition to* any
2084
- # categories that may already be applied to the posts.)
2085
- #
2086
- # Values of keys in link_notes are accessible from templates using
2087
- # the function `get_feed_meta($key)` if this plugin is activated.
2088
-
2089
- class SyndicatedLink {
2090
- var $id = null;
2091
- var $link = null;
2092
- var $settings = array ();
2093
- var $magpie = null;
2094
-
2095
- function SyndicatedLink ($link) {
2096
- global $wpdb;
2097
-
2098
- if (is_object($link)) :
2099
- $this->link = $link;
2100
- $this->id = $link->link_id;
2101
- else :
2102
- $this->id = $link;
2103
- if (function_exists('get_bookmark')) : // WP 2.1+
2104
- $this->link = get_bookmark($link);
2105
- else :
2106
- $this->link = $wpdb->get_row("
2107
- SELECT * FROM $wpdb->links
2108
- WHERE (link_id = '".$wpdb->escape($link)."')"
2109
- );
2110
- endif;
2111
- endif;
2112
-
2113
- if (strlen($this->link->link_rss) > 0) :
2114
- // Read off feed settings from link_notes
2115
- $notes = explode("\n", $this->link->link_notes);
2116
- foreach ($notes as $note):
2117
- list($key, $value) = explode(": ", $note, 2);
2118
-
2119
- if (strlen($key) > 0) :
2120
- // Unescape and trim() off the whitespace.
2121
- // Thanks to Ray Lischner for pointing out the
2122
- // need to trim off whitespace.
2123
- $this->settings[$key] = stripcslashes (trim($value));
2124
- endif;
2125
- endforeach;
2126
-
2127
- // "Magic" feed settings
2128
- $this->settings['link/uri'] = $this->link->link_rss;
2129
- $this->settings['link/name'] = $this->link->link_name;
2130
- $this->settings['link/id'] = $this->link->link_id;
2131
-
2132
- // `hardcode categories` and `unfamiliar categories` are deprecated in favor of `unfamiliar category`
2133
- if (
2134
- isset($this->settings['unfamiliar categories'])
2135
- and !isset($this->settings['unfamiliar category'])
2136
- ) :
2137
- $this->settings['unfamiliar category'] = $this->settings['unfamiliar categories'];
2138
- endif;
2139
- if (
2140
- FeedWordPress::affirmative($this->settings, 'hardcode categories')
2141
- and !isset($this->settings['unfamiliar category'])
2142
- ) :
2143
- $this->settings['unfamiliar category'] = 'default';
2144
- endif;
2145
-
2146
- // Set this up automagically for del.icio.us
2147
- $bits = parse_url($this->link->link_rss);
2148
- $tagspacers = array('del.icio.us', 'feeds.delicious.com');
2149
- if (!isset($this->settings['cat_split']) and in_array($bits['host'], $tagspacers)) :
2150
- $this->settings['cat_split'] = '\s'; // Whitespace separates multiple tags in del.icio.us RSS feeds
2151
- endif;
2152
-
2153
- if (isset($this->settings['cats'])):
2154
- $this->settings['cats'] = preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, $this->settings['cats']);
2155
- endif;
2156
- if (isset($this->settings['tags'])):
2157
- $this->settings['tags'] = preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, $this->settings['tags']);
2158
- endif;
2159
-
2160
- if (isset($this->settings['map authors'])) :
2161
- $author_rules = explode("\n\n", $this->settings['map authors']);
2162
- $ma = array();
2163
- foreach ($author_rules as $rule) :
2164
- list($rule_type, $author_name, $author_action) = explode("\n", $rule);
2165
-
2166
- // Normalize for case and whitespace
2167
- $rule_type = strtolower(trim($rule_type));
2168
- $author_name = strtolower(trim($author_name));
2169
- $author_action = strtolower(trim($author_action));
2170
-
2171
- $ma[$rule_type][$author_name] = $author_action;
2172
- endforeach;
2173
- $this->settings['map authors'] = $ma;
2174
- endif;
2175
- endif;
2176
- } /* SyndicatedLink::SyndicatedLink () */
2177
-
2178
- function found () {
2179
- return is_object($this->link);
2180
- } /* SyndicatedLink::found () */
2181
-
2182
- function stale () {
2183
- $stale = true;
2184
- if (isset($this->settings['update/hold']) and ($this->settings['update/hold']=='ping')) :
2185
- $stale = false; // don't update on any timed updates; pings only
2186
- elseif (isset($this->settings['update/hold']) and ($this->settings['update/hold']=='next')) :
2187
- $stale = true; // update on the next timed update
2188
- elseif (!isset($this->settings['update/ttl']) or !isset($this->settings['update/last'])) :
2189
- $stale = true; // initial update
2190
- else :
2191
- $after = ((int) $this->settings['update/last'])
2192
- +((int) $this->settings['update/ttl'] * 60);
2193
- $stale = (time() >= $after);
2194
- endif;
2195
- return $stale;
2196
- } /* SyndicatedLink::stale () */
2197
-
2198
- function poll ($crash_ts = NULL) {
2199
- global $wpdb;
2200
-
2201
- $this->magpie = fetch_rss($this->link->link_rss);
2202
- $new_count = NULL;
2203
-
2204
- $resume = FeedWordPress::affirmative($this->settings, 'update/unfinished');
2205
- if ($resume) :
2206
- // pick up where we left off
2207
- $processed = array_map('trim', explode("\n", $this->settings['update/processed']));
2208
- else :
2209
- // begin at the beginning
2210
- $processed = array();
2211
- endif;
2212
-
2213
- if (is_object($this->magpie)) :
2214
- $new_count = array('new' => 0, 'updated' => 0);
2215
-
2216
- # -- Update Link metadata live from feed
2217
- $channel = $this->magpie->channel;
2218
-
2219
- if (!isset($channel['id'])) :
2220
- $channel['id'] = $this->link->link_rss;
2221
- endif;
2222
-
2223
- $update = array();
2224
- if (!$this->hardcode('url') and isset($channel['link'])) :
2225
- $update[] = "link_url = '".$wpdb->escape($channel['link'])."'";
2226
- endif;
2227
-
2228
- if (!$this->hardcode('name') and isset($channel['title'])) :
2229
- $update[] = "link_name = '".$wpdb->escape($channel['title'])."'";
2230
- endif;
2231
-
2232
- if (!$this->hardcode('description')) :
2233
- if (isset($channel['tagline'])) :
2234
- $update[] = "link_description = '".$wpdb->escape($channel['tagline'])."'";
2235
- elseif (isset($channel['description'])) :
2236
- $update[] = "link_description = '".$wpdb->escape($channel['description'])."'";
2237
- endif;
2238
- endif;
2239
-
2240
- $this->settings = array_merge($this->settings, $this->flatten_array($channel));
2241
-
2242
- $this->settings['update/last'] = time(); $ttl = $this->ttl();
2243
- if (!is_null($ttl)) :
2244
- $this->settings['update/ttl'] = $ttl;
2245
- $this->settings['update/timed'] = 'feed';
2246
- else :
2247
- $this->settings['update/ttl'] = rand(30, 120); // spread over time interval for staggered updates
2248
- $this->settings['update/timed'] = 'automatically';
2249
- endif;
2250
-
2251
- if (!isset($this->settings['update/hold']) or $this->settings['update/hold']!='ping') :
2252
- $this->settings['update/hold'] = 'scheduled';
2253
- endif;
2254
-
2255
- $this->settings['update/unfinished'] = 'yes';
2256
-
2257
- $update[] = "link_notes = '".$wpdb->escape($this->settings_to_notes())."'";
2258
-
2259
- $update_set = implode(',', $update);
2260
-
2261
- // Update the properties of the link from the feed information
2262
- $result = $wpdb->query("
2263
- UPDATE $wpdb->links
2264
- SET $update_set
2265
- WHERE link_id='$this->id'
2266
- ");
2267
-
2268
- # -- Add new posts from feed and update any updated posts
2269
- $crashed = false;
2270
-
2271
- if (is_array($this->magpie->items)) :
2272
- foreach ($this->magpie->items as $item) :
2273
- $post =& new SyndicatedPost($item, $this);
2274
- if (!$resume or !in_array(trim($post->guid()), $processed)) :
2275
- $processed[] = $post->guid();
2276
- if (!$post->filtered()) :
2277
- $new = $post->store();
2278
- if ( $new !== false ) $new_count[$new]++;
2279
- endif;
2280
-
2281
- if (!is_null($crash_ts) and (time() > $crash_ts)) :
2282
- $crashed = true;
2283
- break;
2284
- endif;
2285
- endif;
2286
- endforeach;
2287
- endif;
2288
-
2289
- // Copy back any changes to feed settings made in the course of updating (e.g. new author rules)
2290
- $to_notes = $this->settings;
2291
-
2292
- $this->settings['update/processed'] = $processed;
2293
- if (!$crashed) :
2294
- $this->settings['update/unfinished'] = 'no';
2295
- endif;
2296
-
2297
- $update_set = "link_notes = '".$wpdb->escape($this->settings_to_notes())."'";
2298
-
2299
- // Update the properties of the link from the feed information
2300
- $result = $wpdb->query("
2301
- UPDATE $wpdb->links
2302
- SET $update_set
2303
- WHERE link_id='$this->id'
2304
- ");
2305
- endif;
2306
-
2307
- return $new_count;
2308
- } /* SyndicatedLink::poll() */
2309
-
2310
- function map_name_to_new_user ($name, $newuser_name) {
2311
- global $wpdb;
2312
-
2313
- if (strlen($newuser_name) > 0) :
2314
- $userdata = array();
2315
- $userdata['ID'] = NULL;
2316
-
2317
- $userdata['user_login'] = sanitize_user($newuser_name);
2318
- $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
2319
-
2320
- $userdata['user_nicename'] = sanitize_title($newuser_name);
2321
- $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
2322
-
2323
- $userdata['display_name'] = $wpdb->escape($newuser_name);
2324
-
2325
- $newuser_id = wp_insert_user($userdata);
2326
- if (is_numeric($newuser_id)) :
2327
- if (is_null($name)) : // Unfamiliar author
2328
- $this->settings['unfamiliar author'] = $newuser_id;
2329
- else :
2330
- $this->settings['map authors']['name'][$name] = $newuser_id;
2331
- endif;
2332
- else :
2333
- // TODO: Add some error detection and reporting
2334
- endif;
2335
- else :
2336
- // TODO: Add some error reporting
2337
- endif;
2338
- } /* SyndicatedLink::map_name_to_new_user () */
2339
-
2340
- function settings_to_notes () {
2341
- $to_notes = $this->settings;
2342
-
2343
- unset($to_notes['link/id']); // Magic setting; don't save
2344
- unset($to_notes['link/uri']); // Magic setting; don't save
2345
- unset($to_notes['link/name']); // Magic setting; don't save
2346
- unset($to_notes['hardcode categories']); // Deprecated
2347
- unset($to_notes['unfamiliar categories']); // Deprecated
2348
-
2349
- // Collapse array settings
2350
- if (isset($to_notes['update/processed']) and (is_array($to_notes['update/processed']))) :
2351
- $to_notes['update/processed'] = implode("\n", $to_notes['update/processed']);
2352
- endif;
2353
-
2354
- if (is_array($to_notes['cats'])) :
2355
- $to_notes['cats'] = implode(FEEDWORDPRESS_CAT_SEPARATOR, $to_notes['cats']);
2356
- endif;
2357
- if (is_array($to_notes['tags'])) :
2358
- $to_notes['tags'] = implode(FEEDWORDPRESS_CAT_SEPARATOR, $to_notes['tags']);
2359
- endif;
2360
-
2361
- // Collapse the author mapping rule structure back into a flat string
2362
- if (isset($to_notes['map authors'])) :
2363
- $ma = array();
2364
- foreach ($to_notes['map authors'] as $rule_type => $author_rules) :
2365
- foreach ($author_rules as $author_name => $author_action) :
2366
- $ma[] = $rule_type."\n".$author_name."\n".$author_action;
2367
- endforeach;
2368
- endforeach;
2369
- $to_notes['map authors'] = implode("\n\n", $ma);
2370
- endif;
2371
-
2372
- $notes = '';
2373
- foreach ($to_notes as $key => $value) :
2374
- $notes .= $key . ": ". addcslashes($value, "\0..\37".'\\') . "\n";
2375
- endforeach;
2376
- return $notes;
2377
- } /* SyndicatedLink::settings_to_notes () */
2378
-
2379
- function uri () {
2380
- return (is_object($this->link) ? $this->link->link_rss : NULL);
2381
- } /* SyndicatedLink::uri () */
2382
-
2383
- function homepage () {
2384
- return (isset($this->settings['feed/link']) ? $this->settings['feed/link'] : NULL);
2385
- } /* SyndicatedLink::homepage () */
2386
-
2387
- function ttl () {
2388
- if (is_object($this->magpie)) :
2389
- $channel = $this->magpie->channel;
2390
- else :
2391
- $channel = array();
2392
- endif;
2393
-
2394
- if (isset($channel['ttl'])) :
2395
- // "ttl stands for time to live. It's a number of
2396
- // minutes that indicates how long a channel can be
2397
- // cached before refreshing from the source."
2398
- // <http://blogs.law.harvard.edu/tech/rss#ltttlgtSubelementOfLtchannelgt>
2399
- $ret = $channel['ttl'];
2400
- elseif (isset($channel['sy']['updatefrequency']) or isset($channel['sy']['updateperiod'])) :
2401
- $period_minutes = array (
2402
- 'hourly' => 60, /* minutes in an hour */
2403
- 'daily' => 1440, /* minutes in a day */
2404
- 'weekly' => 10080, /* minutes in a week */
2405
- 'monthly' => 43200, /* minutes in a month */
2406
- 'yearly' => 525600, /* minutes in a year */
2407
- );
2408
-
2409
- // "sy:updatePeriod: Describes the period over which the
2410
- // channel format is updated. Acceptable values are:
2411
- // hourly, daily, weekly, monthly, yearly. If omitted,
2412
- // daily is assumed." <http://web.resource.org/rss/1.0/modules/syndication/>
2413
- if (isset($channel['sy']['updateperiod'])) : $period = $channel['sy']['updateperiod'];
2414
- else : $period = 'daily';
2415
- endif;
2416
-
2417
- // "sy:updateFrequency: Used to describe the frequency
2418
- // of updates in relation to the update period. A
2419
- // positive integer indicates how many times in that
2420
- // period the channel is updated. ... If omitted a value
2421
- // of 1 is assumed." <http://web.resource.org/rss/1.0/modules/syndication/>
2422
- if (isset($channel['sy']['updatefrequency'])) : $freq = (int) $channel['sy']['updatefrequency'];
2423
- else : $freq = 1;
2424
- endif;
2425
-
2426
- $ret = (int) ($period_minutes[$period] / $freq);
2427
- else :
2428
- $ret = NULL;
2429
- endif;
2430
- return $ret;
2431
- } /* SyndicatedLink::ttl() */
2432
-
2433
- // SyndicatedLink::flatten_array (): flatten an array. Useful for
2434
- // hierarchical and namespaced elements.
2435
- //
2436
- // Given an array which may contain array or object elements in it,
2437
- // return a "flattened" array: a one-dimensional array of scalars
2438
- // containing each of the scalar elements contained within the array
2439
- // structure. Thus, for example, if $a['b']['c']['d'] == 'e', then the
2440
- // returned array for FeedWordPress::flatten_array($a) will contain a key
2441
- // $a['feed/b/c/d'] with value 'e'.
2442
- function flatten_array ($arr, $prefix = 'feed/', $separator = '/') {
2443
- $ret = array ();
2444
- if (is_array($arr)) :
2445
- foreach ($arr as $key => $value) :
2446
- if (is_scalar($value)) :
2447
- $ret[$prefix.$key] = $value;
2448
- else :
2449
- $ret = array_merge($ret, $this->flatten_array($value, $prefix.$key.$separator, $separator));
2450
- endif;
2451
- endforeach;
2452
- endif;
2453
- return $ret;
2454
- } /* SyndicatedLink::flatten_array () */
2455
-
2456
- function hardcode ($what) {
2457
- $default = get_option("feedwordpress_hardcode_$what");
2458
- if ( $default === 'yes' ) :
2459
- // If the default is to hardcode, then we want the
2460
- // negation of negative(): TRUE by default and FALSE if
2461
- // the setting is explicitly "no"
2462
- $ret = !FeedWordPress::negative($this->settings, "hardcode $what");
2463
- else :
2464
- // If the default is NOT to hardcode, then we want
2465
- // affirmative(): FALSE by default and TRUE if the
2466
- // setting is explicitly "yes"
2467
- $ret = FeedWordPress::affirmative($this->settings, "hardcode $what");
2468
- endif;
2469
- return $ret;
2470
- } /* SyndicatedLink::hardcode () */
2471
-
2472
- function syndicated_status ($what, $default) {
2473
- global $wpdb;
2474
-
2475
- $ret = get_option("feedwordpress_syndicated_{$what}_status");
2476
- if ( isset($this->settings["$what status"]) ) :
2477
- $ret = $this->settings["$what status"];
2478
- elseif (!$ret) :
2479
- $ret = $default;
2480
- endif;
2481
- return $wpdb->escape(trim(strtolower($ret)));
2482
- } /* SyndicatedLink:syndicated_status () */
2483
- } // class SyndicatedLink
2484
 
2485
  ################################################################################
2486
  ## XML-RPC HOOKS: accept XML-RPC update pings from Contributors ################
@@ -2552,6 +2407,10 @@ class FeedFinder {
2552
  // If all that failed, look harder
2553
  if (count($href) == 0) $href = $this->_a_href_feeds(FALSE);
2554
 
 
 
 
 
2555
  // Verify feeds and resolve relative URIs
2556
  foreach ($href as $u) {
2557
  $the_uri = Relative_URI::resolve($u, $this->uri);
3
  Plugin Name: FeedWordPress
4
  Plugin URI: http://projects.radgeek.com/feedwordpress
5
  Description: simple and flexible Atom/RSS syndication for WordPress
6
+ Version: 2009.0612
7
  Author: Charles Johnson
8
  Author URI: http://radgeek.com/
9
  License: GPL
 
10
  */
11
 
12
  # This uses code derived from:
28
 
29
  # -- Don't change these unless you know what you're doing...
30
 
31
+ define ('FEEDWORDPRESS_VERSION', '2009.0612');
32
  define ('FEEDWORDPRESS_AUTHOR_CONTACT', 'http://radgeek.com/contact');
33
  define ('DEFAULT_SYNDICATION_CATEGORY', 'Contributors');
34
 
35
+ $feedwordpress_debug = get_option('feedwordpress_debug');
36
+ if (is_string($feedwordpress_debug)) :
37
+ $feedwordpress_debug = ($feedwordpress_debug == 'yes');
38
+ endif;
39
+ define ('FEEDWORDPRESS_DEBUG', $feedwordpress_debug);
40
 
41
  define ('FEEDWORDPRESS_CAT_SEPARATOR_PATTERN', '/[:\n]/');
42
  define ('FEEDWORDPRESS_CAT_SEPARATOR', "\n");
92
  endif;
93
 
94
  require_once(dirname(__FILE__) . '/compatability.php'); // LEGACY API: Replicate or mock up functions for legacy support purposes
95
+ require_once(dirname(__FILE__) . '/feedwordpresshtml.class.php');
96
 
97
  // Magic quotes are just about the stupidest thing ever.
98
  if (is_array($_POST)) :
168
 
169
  # Admin menu
170
  add_action('admin_menu', 'fwp_add_pages');
171
+ add_action('admin_notices', 'fwp_check_debug');
172
+ add_action('admin_notices', 'fwp_check_magpie');
173
+
174
  # Inbound XML-RPC update methods
175
  add_filter('xmlrpc_methods', 'feedwordpress_xmlrpc_hook');
176
 
196
 
197
  # Cron-less auto-update. Hooray!
198
  add_action('init', 'feedwordpress_auto_update');
199
+ add_action('init', 'feedwordpress_check_for_magpie_fix');
200
 
201
  # Default sanitizers
202
+ add_filter('syndicated_item_content', array('SyndicatedPost', 'resolve_relative_uris'), 0, 2);
203
  add_filter('syndicated_item_content', array('SyndicatedPost', 'sanitize_content'), 0, 2);
204
 
205
  else :
207
  add_action('admin_menu', 'fwp_add_pages');
208
  endif; // if (!FeedWordPress::needs_upgrade())
209
 
210
+ function feedwordpress_check_for_magpie_fix () {
211
+ if (isset($_POST['action']) and $_POST['action']=='fix_magpie_version') :
212
+ FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_fix_magpie', /*capability=*/ 'edit_files');
213
+
214
+ $back_to = $_SERVER['REQUEST_URI'];
215
+ if (isset($_POST['ignore'])) :
216
+ // kill error message by telling it to expect whatever we've got
217
+ update_option('feedwordpress_expected_magpie', FeedWordPress::magpie_version());
218
+ $ret = 'ignored';
219
+ elseif (isset($_POST['upgrade'])) :
220
+ $source = dirname(__FILE__)."/MagpieRSS-upgrade/rss.php";
221
+ $destination = ABSPATH . WPINC . '/rss.php';
222
+ $success = @copy($source, $destination);
223
+ $ret = (int) $success;
224
+ endif;
225
+
226
+ if (strpos($back_to, '?')===false) : $sep = '?';
227
+ else : $sep = '&';
228
+ endif;
229
+
230
+ header("Location: {$back_to}{$sep}feedwordpress_magpie_fix=".$ret);
231
+ exit;
232
+ endif;
233
+ } /* feedwordpress_check_for_magpie_fix() */
234
+
235
  function feedwordpress_auto_update () {
236
  if (FeedWordPress::stale()) :
237
  $feedwordpress =& new FeedWordPress;
397
  function feedwordpress_preserve_syndicated_content ($text) {
398
  global $feedwordpress_the_syndicated_content;
399
 
400
+ $globalExpose = (get_option('feedwordpress_formatting_filters') == 'yes');
401
+ $localExpose = get_post_custom_values('_feedwordpress_formatting_filters');
402
+ $expose = ($globalExpose or ((count($localExpose) > 0) and $localExpose[0]));
403
+
404
+ if ( is_syndicated() and !$expose ) :
405
  $feedwordpress_the_syndicated_content = $text;
406
  else :
407
  $feedwordpress_the_syndicated_content = NULL;
477
  endif;
478
 
479
  call_user_func_array('add_menu_page', $menu);
480
+ add_submenu_page($fwp_path.'/syndication.php', 'Syndicated Posts', 'Posts', $fwp_capability['manage_options'], $fwp_path.'/posts-page.php');
481
+ add_submenu_page($fwp_path.'/syndication.php', 'Syndicated Authors', 'Authors', $fwp_capability['manage_options'], $fwp_path.'/authors-page.php');
482
+ add_submenu_page($fwp_path.'/syndication.php', 'Categories & Tags', 'Categories & Tags', $fwp_capability['manage_options'], $fwp_path.'/categories-page.php');
483
  add_submenu_page($fwp_path.'/syndication.php', $longoptions, $options, $fwp_capability['manage_options'], $fwp_path.'/syndication-options.php');
484
 
485
  add_options_page($longoptions, 'Syndication', $fwp_capability['manage_options'], $fwp_path.'/syndication-options.php');
486
+ } /* function fwp_add_pages () */
487
+
488
+ function fwp_check_debug () {
489
+ // This is a horrible fucking kludge that I have to do because the
490
+ // admin notice code is triggered before the code that updates the
491
+ // setting.
492
+ if (isset($_POST['feedwordpress_debug'])) :
493
+ $feedwordpress_debug = $_POST['feedwordpress_debug'];
494
+ else :
495
+ $feedwordpress_debug = get_option('feedwordpress_debug');
496
+ endif;
497
+ if ($feedwordpress_debug==='yes') :
498
+ ?>
499
+ <div class="error">
500
+ <p><strong>FeedWordPress warning.</strong> Debugging mode is <strong>ON</strong>.
501
+ While it remains on, FeedWordPress displays many diagnostic error messages,
502
+ warnings, and notices that are ordinarily suppressed, and also turns off all
503
+ caching of feeds. Use with caution: this setting is absolutely inappropriate
504
+ for a production server.</p>
505
+ </div>
506
+ <?php
507
+ endif;
508
+ } /* function fwp_check_debug () */
509
+
510
+ define('DEFAULT_EXPECTED_MAGPIE_VERSION', '0.85');
511
+ function fwp_check_magpie () {
512
+ if (isset($_REQUEST['feedwordpress_magpie_fix'])) :
513
+ if ($_REQUEST['feedwordpress_magpie_fix']=='ignored') :
514
+ ?>
515
+ <div class="updated fade">
516
+ <p>O.K., we'll ignore the problem for now. FeedWordPress will not display any
517
+ more error messages.</p>
518
+ </div>
519
+ <?php
520
+ elseif ((bool) $_REQUEST['feedwordpress_magpie_fix']) :
521
+ ?>
522
+ <div class="updated fade">
523
+ <p>Congratulations! Your MagpieRSS has been successfully upgraded to the version
524
+ shipped with FeedWordPress.</p>
525
+ </div>
526
+ <?php
527
+ else :
528
+ $source = dirname(__FILE__)."/MagpieRSS-upgrade/rss.php";
529
+ $destination = ABSPATH . WPINC . '/rss.php';
530
+ $cmd = "cp '".htmlspecialchars(addslashes($source))."' '".htmlspecialchars(addslashes($destination))."'";
531
+ $cmd = wordwrap($cmd, /*width=*/ 75, /*break=*/ " \\\n\t");
532
+
533
+ ?>
534
+ <div class="error">
535
+ <p><strong>FeedWordPress was unable to automatically upgrade your copy of MagpieRSS.</strong></p>
536
+ <p>It's likely that you need to change the file permissions on <code><?php print htmlspecialchars($source); ?></code>
537
+ to allow FeedWordPress to overwrite it.</p>
538
+ <p><strong>To perform the upgrade manually,</strong> you can
539
+ use a SFTP or FTP client to upload a copy of <code>rss.php</code> from the
540
+ <code>MagpieRSS-upgrades/</code> directory of your FeedWordPress archive so that
541
+ it overwrites <code><?php print htmlspecialchars($destination); ?></code>. Or,
542
+ if your web host provides shell access, you can issue the following command from
543
+ a command prompt to perform the upgrade:</p>
544
+ <pre>
545
+ <samp>$</samp> <kbd><?php print $cmd; ?></kbd>
546
+ </pre>
547
+ <p><strong>If you've fixed the file permissions,</strong> you can try the
548
+ automatic upgrade again.</p>
549
+
550
+ <?php feedwordpress_upgrade_old_and_busted_buttons(); ?>
551
+ </div>
552
+ <?php
553
+ endif;
554
+ else :
555
+ $magpie_version = FeedWordPress::magpie_version();
556
+
557
+ $exp = get_option('feedwordpress_expected_magpie');
558
+ if ($exp) : $expected = array($exp, DEFAULT_EXPECTED_MAGPIE_VERSION);
559
+ else : $expected = array(DEFAULT_EXPECTED_MAGPIE_VERSION);
560
+ endif;
561
+
562
+ if (in_array($magpie_version, $expected)) :
563
+ if ($magpie_version != $exp) :
564
+ update_option('feedwordpress_expected_magpie', $magpie_version);
565
+ endif;
566
+ else :
567
+ if (current_user_can('edit_files')) :
568
+ $youAre = 'you are';
569
+ $itIsRecommendedThatYou = 'It is <strong>strongly recommended</strong> that you';
570
+ else :
571
+ $youAre = 'this site is';
572
+ $itIsRecommendedThatYou = 'You may want to contact the administrator of the site; it is <strong>strongly recommended</strong> that they';
573
+ endif;
574
+ print '<div class="error">';
575
+ ?>
576
+ <p style="font-style: italic"><strong>FeedWordPress has detected that <?php print $youAre; ?> currently using a version of
577
+ MagpieRSS other than the upgraded version that ships with FeedWordPress.</strong></p>
578
+ <p><?php print $itIsRecommendedThatYou; ?> install the upgraded
579
+ version of MagpieRSS supplied with FeedWordPress. The version of
580
+ MagpieRSS that ships with WordPress is very old and buggy, and
581
+ encounters a number of errors when trying to parse modern Atom
582
+ and RSS feeds.</p>
583
+ <?php
584
+ feedwordpress_upgrade_old_and_busted_buttons();
585
+ print '</div>';
586
+ endif;
587
+ endif;
588
+ }
589
+
590
+ function feedwordpress_upgrade_old_and_busted_buttons() {
591
+ if (current_user_can('edit_files')) :
592
+ ?>
593
+ <form action="" method="post"><div>
594
+ <?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_fix_magpie'); ?>
595
+ <input type="hidden" name="action" value="fix_magpie_version" />
596
+ <input class="button-secondary" type="submit" name="ignore" value="<?php _e('Ignore this problem'); ?>" />
597
+ <input class="button-primary" type="submit" name="upgrade" value="<?php _e('Upgrade'); ?>" />
598
+ </div></form>
599
+ <?php
600
+ endif;
601
+ }
602
 
603
  ################################################################################
604
  ## fwp_hold_pings() and fwp_release_pings(): Outbound XML-RPC ping reform ####
955
  if (function_exists('is_term')) :
956
  $cat_id = is_term($cat, 'link_category');
957
  // WordPress 2.1 and 2.2 use a common table for both link and post categories
958
+ elseif (fwp_test_wp_version(FWP_SCHEMA_21, FWP_SCHEMA_23)) :
959
  $cat_id = $wpdb->get_var("SELECT cat_id FROM {$wpdb->categories} WHERE cat_name='$cat'");
960
  // WordPress 1.5 and 2.0.x have a separate table for link categories
961
+ elseif (fwp_test_wp_version(0, FWP_SCHEMA_21)):
962
  $cat_id = $wpdb->get_var("SELECT cat_id FROM {$wpdb->linkcategories} WHERE cat_name='$cat'");
963
  // This should never happen.
964
  else :
1096
  ");
1097
  } /* FeedWordPress::create_guid_index () */
1098
 
1099
+ function magpie_version () {
1100
+ if (!defined('MAGPIE_VERSION')) : $magpie_version = $GLOBALS['wp_version'].'-default';
1101
+ else : $magpie_version = MAGPIE_VERSION;
1102
+ endif;
1103
+ return $magpie_version;
1104
+ }
1105
+
1106
  # Utility functions for handling text settings
1107
  function negative ($f, $setting) {
1108
  $nego = array ('n', 'no', 'f', 'false');
1119
  function critical_bug ($varname, $var, $line) {
1120
  global $wp_version;
1121
 
1122
+ if (defined('MAGPIE_VERSION')) : $mv = MAGPIE_VERSION;
1123
+ else : $mv = 'WordPress '.$wp_version.' default.';
1124
+ endif;
1125
+
1126
  echo '<p>There may be a bug in FeedWordPress. Please <a href="'.FEEDWORDPRESS_AUTHOR_CONTACT.'">contact the author</a> and paste the following information into your e-mail:</p>';
1127
  echo "\n<plaintext>";
1128
  echo "Triggered at line # ".$line."\n";
1129
  echo "FeedWordPress version: ".FEEDWORDPRESS_VERSION."\n";
1130
+ echo "MagpieRSS version: {$mv}\n";
1131
+ echo "WordPress version: {$wp_version}\n";
1132
  echo "PHP version: ".phpversion()."\n";
1133
  echo "\n";
1134
  echo $varname.": "; var_dump($var); echo "\n";
1150
  var $feedmeta = null;
1151
 
1152
  var $post = array ();
 
1153
 
1154
  var $_freshness = null;
1155
  var $_wp_id = null;
1195
 
1196
  # Identify content and sanitize it.
1197
  # ---------------------------------
1198
+ if (isset($this->item['atom_content'])) :
1199
+ $content = $this->item['atom_content'];
1200
+ elseif (isset($this->item['xhtml']['body'])) :
1201
  $content = $this->item['xhtml']['body'];
1202
  elseif (isset($this->item['xhtml']['div'])) :
1203
  $content = $this->item['xhtml']['div'];
1248
  // Unique ID (hopefully a unique tag: URI); failing that, the permalink
1249
  $this->post['guid'] = apply_filters('syndicated_item_guid', $this->guid(), $this);
1250
 
1251
+ // User-supplied custom settings to apply to each post. Do first so that FWP-generated custom settings will overwrite if necessary; thus preventing any munging
1252
+ $default_custom_settings = get_option('feedwordpress_custom_settings');
1253
+ if ($default_custom_settings) :
1254
+ $default_custom_settings = unserialize($default_custom_settings);
1255
+ endif;
1256
+ if (!is_array($default_custom_settings)) :
1257
+ $default_custom_settings = array();
1258
+ endif;
1259
+
1260
+ $custom_settings = $this->link->settings['postmeta'];
1261
+ if ($custom_settings) :
1262
+ $custom_settings = unserialize($custom_settings);
1263
+ endif;
1264
+ if (!is_array($custom_settings)) :
1265
+ $custom_settings = array();
1266
+ endif;
1267
+ $this->post['meta'] = array_merge($default_custom_settings, $custom_settings);
1268
+
1269
  // RSS 2.0 / Atom 1.0 enclosure support
1270
  if ( isset($this->item['enclosure#']) ) :
1271
  for ($i = 1; $i <= $this->item['enclosure#']; $i++) :
1508
 
1509
  function insert_new () {
1510
  global $wpdb, $wp_db_version;
1511
+
1512
+ $dbpost = $this->normalize_post(/*new=*/ true);
1513
+ if (!is_null($dbpost)) :
1514
+ if ($this->use_api('wp_insert_post')) :
1515
+ $dbpost['post_pingback'] = false; // Tell WP 2.1 and 2.2 not to process for pingbacks
1516
+
1517
+ // This is a ridiculous fucking kludge necessitated by WordPress 2.6 munging authorship meta-data
1518
+ add_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
1519
+
1520
+ // Kludge to prevent kses filters from stripping the
1521
+ // content of posts when updating without a logged in
1522
+ // user who has `unfiltered_html` capability.
1523
+ add_filter('content_save_pre', array($this, 'avoid_kses_munge'), 11);
1524
+
1525
+ $this->_wp_id = wp_insert_post($dbpost);
1526
+
1527
+ // Turn off ridiculous fucking kludges #1 and #2
1528
+ remove_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
1529
+ remove_filter('content_save_pre', array($this, 'avoid_kses_munge'), 11);
1530
+
1531
+ $this->validate_post_id($dbpost, array(__CLASS__, __FUNCTION__));
1532
+
1533
+ // Unfortunately, as of WordPress 2.3, wp_insert_post()
1534
+ // *still* offers no way to use a guid of your choice,
1535
+ // and munges your post modified timestamp, too.
1536
+ $result = $wpdb->query("
1537
+ UPDATE $wpdb->posts
1538
+ SET
1539
+ guid='{$dbpost['guid']}',
1540
+ post_modified='{$dbpost['post_modified']}',
1541
+ post_modified_gmt='{$dbpost['post_modified_gmt']}'
1542
+ WHERE ID='{$this->_wp_id}'
1543
+ ");
1544
  else :
1545
+ # The right way to do this is the above. But, alas,
1546
+ # in earlier versions of WordPress, wp_insert_post has
1547
+ # too much behavior (mainly related to pings) that can't
1548
+ # be overridden. In WordPress 1.5, it's enough of a
1549
+ # resource hog to make PHP segfault after inserting
1550
+ # 50-100 posts. This can get pretty annoying, especially
1551
+ # if you are trying to update your feeds for the first
1552
+ # time.
1553
+
1554
+ $result = $wpdb->query("
1555
+ INSERT INTO $wpdb->posts
1556
+ SET
1557
+ guid = '{$dbpost['guid']}',
1558
+ post_author = '{$dbpost['post_author']}',
1559
+ post_date = '{$dbpost['post_date']}',
1560
+ post_date_gmt = '{$dbpost['post_date_gmt']}',
1561
+ post_content = '{$dbpost['post_content']}',"
1562
+ .(isset($dbpost['post_excerpt']) ? "post_excerpt = '{$dbpost['post_excerpt']}'," : "")."
1563
+ post_title = '{$dbpost['post_title']}',
1564
+ post_name = '{$dbpost['post_name']}',
1565
+ post_modified = '{$dbpost['post_modified']}',
1566
+ post_modified_gmt = '{$dbpost['post_modified_gmt']}',
1567
+ comment_status = '{$dbpost['comment_status']}',
1568
+ ping_status = '{$dbpost['ping_status']}',
1569
+ post_status = '{$dbpost['post_status']}'
1570
+ ");
1571
+ $this->_wp_id = $wpdb->insert_id;
1572
+
1573
+ $this->validate_post_id($dbpost, array(__CLASS__, __FUNCTION__));
1574
+
1575
+ // WordPress 1.5.x - 2.0.x
1576
+ wp_set_post_cats('1', $this->wp_id(), $this->post['post_category']);
1577
+
1578
+ // Since we are not going through official channels, we need to
1579
+ // manually tell WordPress that we've published a new post.
1580
+ // We need to make sure to do this in order for FeedWordPress
1581
+ // to play well with the staticize-reloaded plugin (something
1582
+ // that a large aggregator website is going to *want* to be
1583
+ // able to use).
1584
+ do_action('publish_post', $this->_wp_id);
1585
  endif;
 
 
 
 
1586
  endif;
1587
+ } /* SyndicatedPost::insert_new() */
 
 
 
 
 
 
 
1588
 
1589
+ function update_existing () {
1590
+ global $wpdb;
 
 
 
 
 
 
 
1591
 
1592
+ // Why the fuck doesn't wp_insert_post already do this?
1593
+ $dbpost = $this->normalize_post(/*new=*/ false);
1594
+ if (!is_null($dbpost)) :
1595
+ if ($this->use_api('wp_insert_post')) :
1596
+ $dbpost['post_pingback'] = false; // Tell WP 2.1 and 2.2 not to process for pingbacks
1597
+
1598
+ // This is a ridiculous fucking kludge necessitated by WordPress 2.6 munging authorship meta-data
1599
+ add_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
1600
+
1601
+ // Kludge to prevent kses filters from stripping the
1602
+ // content of posts when updating without a logged in
1603
+ // user who has `unfiltered_html` capability.
1604
+ add_filter('content_save_pre', array($this, 'avoid_kses_munge'), 11);
1605
+
1606
+ // Don't munge status fields that the user may have reset manually
1607
+ if (function_exists('get_post_field')) :
1608
+ $doNotMunge = array('post_status', 'comment_status', 'ping_status');
1609
+ foreach ($doNotMunge as $field) :
1610
+ $dbpost[$field] = get_post_field($field, $this->wp_id());
1611
+ endforeach;
1612
+ endif;
1613
 
1614
+ $this->_wp_id = wp_insert_post($dbpost);
 
 
 
1615
 
1616
+ // Turn off ridiculous fucking kludges #1 and #2
1617
+ remove_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
1618
+ remove_filter('content_save_pre', array($this, 'avoid_kses_munge'), 11);
1619
+
1620
+ $this->validate_post_id($dbpost, array(__CLASS__, __FUNCTION__));
1621
+
1622
+ // Unfortunately, as of WordPress 2.3, wp_insert_post()
1623
+ // munges your post modified timestamp.
1624
+ $result = $wpdb->query("
1625
+ UPDATE $wpdb->posts
1626
+ SET
1627
+ post_modified='{$dbpost['post_modified']}',
1628
+ post_modified_gmt='{$dbpost['post_modified_gmt']}'
1629
+ WHERE ID='{$this->_wp_id}'
1630
+ ");
1631
+ else :
1632
+
1633
+ $result = $wpdb->query("
1634
  UPDATE $wpdb->posts
1635
  SET
1636
+ post_author = '{$dbpost['post_author']}',
1637
+ post_content = '{$dbpost['post_content']}',"
1638
+ .(isset($dbpost['post_excerpt']) ? "post_excerpt = '{$dbpost['post_excerpt']}'," : "")."
1639
+ post_title = '{$dbpost['post_title']}',
1640
+ post_name = '{$dbpost['post_name']}',
1641
+ post_modified = '{$dbpost['post_modified']}',
1642
+ post_modified_gmt = '{$dbpost['post_modified_gmt']}'
1643
+ WHERE guid='{$dbpost['guid']}'
1644
+ ");
1645
+
1646
+ // WordPress 2.1.x and up
1647
+ if (function_exists('wp_set_post_categories')) :
1648
+ wp_set_post_categories($this->wp_id(), $this->post['post_category']);
1649
+ // WordPress 1.5.x - 2.0.x
1650
+ elseif (function_exists('wp_set_post_cats')) :
1651
+ wp_set_post_cats('1', $this->wp_id(), $this->post['post_category']);
1652
+ // This should never happen.
1653
+ else :
1654
+ FeedWordPress::critical_bug(__CLASS__.'::'.__FUNCTION.'(): no post categorizing function', array("dbpost" => $dbpost, "this" => $this), __LINE__);
1655
+ endif;
1656
+
1657
+ // Since we are not going through official channels, we need to
1658
+ // manually tell WordPress that we've published a new post.
1659
+ // We need to make sure to do this in order for FeedWordPress
1660
+ // to play well with the staticize-reloaded plugin (something
1661
+ // that a large aggregator website is going to *want* to be
1662
+ // able to use).
1663
+ do_action('edit_post', $this->post['ID']);
 
 
 
 
 
 
 
 
 
1664
  endif;
 
 
 
 
 
 
 
 
 
 
 
1665
  endif;
1666
+ } /* SyndicatedPost::update_existing() */
1667
 
1668
+ /**
1669
+ * SyndicatedPost::normalize_post()
1670
+ *
1671
+ * @param bool $new If true, this post is to be inserted anew. If false, it is an update of an existing post.
1672
+ * @return array A normalized representation of the post ready to be inserted into the database or sent to the WordPress API functions
1673
+ */
1674
+ function normalize_post ($new = true) {
1675
  global $wpdb;
1676
 
1677
+ $out = array();
1678
+
1679
  // Why the fuck doesn't wp_insert_post already do this?
 
1680
  foreach ($this->post as $key => $value) :
1681
  if (is_string($value)) :
1682
+ $out[$key] = $wpdb->escape($value);
1683
  else :
1684
+ $out[$key] = $value;
1685
  endif;
1686
  endforeach;
1687
 
1688
+ if (strlen($out['post_title'].$out['post_content'].$out['post_excerpt']) == 0) :
1689
+ // FIXME: Option for filtering out empty posts
1690
+ endif;
1691
+ if (strlen($out['post_title'])==0) :
1692
+ $offset = (int) get_option('gmt_offset') * 60 * 60;
1693
+ $out['post_title'] =
1694
+ $this->post['meta']['syndication_source']
1695
+ .' '.gmdate('Y-m-d H:i:s', $this->published() + $offset);
1696
+ // FIXME: Option for what to fill a blank title with...
1697
+ endif;
 
 
 
 
 
 
 
 
 
 
 
1698
 
1699
+ return $out;
1700
+ }
 
 
 
 
 
 
 
 
1701
 
1702
+ /**
1703
+ * SyndicatedPost::validate_post_id()
1704
+ *
1705
+ * @param array $dbpost An array representing the post we attempted to insert or update
1706
+ * @param mixed $ns A string or array representing the namespace (class, method) whence this method was called.
1707
+ */
1708
+ function validate_post_id ($dbpost, $ns) {
1709
+ if (is_array($ns)) : $ns = implode('::', $ns);
1710
+ else : $ns = (string) $ns; endif;
1711
+
1712
+ // This should never happen.
1713
+ if (!is_numeric($this->_wp_id) or ($this->_wp_id == 0)) :
1714
+ FeedWordPress::critical_bug(
1715
+ /*name=*/ $ns.'::_wp_id',
1716
+ /*var =*/ array(
1717
+ "\$this->_wp_id" => $this->_wp_id,
1718
+ "\$dbpost" => $dbpost,
1719
+ "\$this" => $this
1720
+ ),
1721
+ /*line # =*/ __LINE__
1722
+ );
 
 
 
 
 
 
 
 
 
 
1723
  endif;
1724
+ } /* SyndicatedPost::validate_post_id() */
1725
+
1726
  /**
1727
  * SyndicatedPost::fix_revision_meta() - Fixes the way WP 2.6+ fucks up
1728
  * meta-data (authorship, etc.) when storing revisions of an updated
2249
  return $author;
2250
  } // SyndicatedPost::author()
2251
 
2252
+ var $uri_attrs = array (
2253
+ array('a', 'href'),
2254
+ array('applet', 'codebase'),
2255
+ array('area', 'href'),
2256
+ array('blockquote', 'cite'),
2257
+ array('body', 'background'),
2258
+ array('del', 'cite'),
2259
+ array('form', 'action'),
2260
+ array('frame', 'longdesc'),
2261
+ array('frame', 'src'),
2262
+ array('iframe', 'longdesc'),
2263
+ array('iframe', 'src'),
2264
+ array('head', 'profile'),
2265
+ array('img', 'longdesc'),
2266
+ array('img', 'src'),
2267
+ array('img', 'usemap'),
2268
+ array('input', 'src'),
2269
+ array('input', 'usemap'),
2270
+ array('ins', 'cite'),
2271
+ array('link', 'href'),
2272
+ array('object', 'classid'),
2273
+ array('object', 'codebase'),
2274
+ array('object', 'data'),
2275
+ array('object', 'usemap'),
2276
+ array('q', 'cite'),
2277
+ array('script', 'src')
2278
+ ); /* var SyndicatedPost::$uri_attrs */
2279
+
2280
+ var $_base = null;
2281
+
2282
+ function resolve_single_relative_uri ($refs) {
2283
+ $tag = FeedWordPressHTML::attributeMatch($refs);
2284
+ $url = Relative_URI::resolve($tag['value'], $this->_base);
2285
+ return $tag['prefix'] . $url . $tag['suffix'];
2286
+ } /* function SyndicatedPost::resolve_single_relative_uri() */
2287
+
2288
+ function resolve_relative_uris ($content, $obj) {
2289
+ # The MagpieRSS upgrade has some `xml:base` support baked in.
2290
+ # However, sometimes people do silly things, like putting
2291
+ # relative URIs out on a production RSS 2.0 feed or other feeds
2292
+ # with no good support for `xml:base`. So we'll do our best to
2293
+ # try to catch any remaining relative URIs and resolve them as
2294
+ # best we can.
2295
+ $obj->_base = $obj->item['link']; // Reset the base for resolving relative URIs
2296
+
2297
+ foreach ($obj->uri_attrs as $pair) :
2298
+ list($tag, $attr) = $pair;
2299
+ $pattern = FeedWordPressHTML::attributeRegex($tag, $attr);
2300
+ $content = preg_replace_callback (
2301
+ $pattern,
2302
+ array(&$obj, 'resolve_single_relative_uri'),
2303
+ $content
2304
+ );
2305
+ endforeach;
2306
+
2307
+ return $content;
2308
+ } /* function SyndicatedPost::resolve_relative_uris () */
2309
+
2310
  var $strip_attrs = array (
2311
+ array('[a-z]+', 'target'),
2312
+ // array('[a-z]+', 'style'),
2313
+ // array('[a-z]+', 'on[a-z]+'),
2314
  );
2315
+
2316
+ function strip_attribute_from_tag ($refs) {
2317
+ $tag = FeedWordPressHTML::attributeMatch($refs);
2318
+ return $tag['before_attribute'].$tag['after_attribute'];
2319
+ }
2320
+
2321
  function sanitize_content ($content, $obj) {
 
 
 
 
 
2322
  # This kind of sucks. I intend to replace it with
2323
  # lib_filter sometime soon.
2324
  foreach ($obj->strip_attrs as $pair):
2325
  list($tag,$attr) = $pair;
2326
+ $pattern = FeedWordPressHTML::attributeRegex($tag, $attr);
2327
+
2328
+ $content = preg_replace_callback (
2329
+ $pattern,
2330
+ array(&$obj, 'strip_attribute_from_tag'),
2331
  $content
2332
  );
2333
  endforeach;
2335
  }
2336
  } // class SyndicatedPost
2337
 
2338
+ require_once(dirname(__FILE__) . '/syndicatedlink.class.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2339
 
2340
  ################################################################################
2341
  ## XML-RPC HOOKS: accept XML-RPC update pings from Contributors ################
2407
  // If all that failed, look harder
2408
  if (count($href) == 0) $href = $this->_a_href_feeds(FALSE);
2409
 
2410
+ // Our search may turn up duplicate URIs. We only need to do any given URI once.
2411
+ // Props to Camilo <http://projects.radgeek.com/2008/12/14/feedwordpress-20081214/#comment-20090122160414>
2412
+ $href = array_unique($href);
2413
+
2414
  // Verify feeds and resolve relative URIs
2415
  foreach ($href as $u) {
2416
  $the_uri = Relative_URI::resolve($u, $this->uri);
feedwordpresshtml.class.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class FeedWordPressHTML {
3
+ function attributeRegex ($tag, $attr) {
4
+ return ":(
5
+ (<($tag)\s+[^>]*)
6
+ ($attr)=
7
+ )
8
+ (
9
+ \s*(\"|')
10
+ (((?!\\6).)*)
11
+ \\6([^>]*>)
12
+ |
13
+ \s*(((?!/>)[^\s>])*)
14
+ ([^>]*>)
15
+ )
16
+ :ix";
17
+ } /* function FeedWordPressHTML::attributeRegex () */
18
+
19
+ function attributeMatch ($matches) {
20
+ $suffix = (isset($matches[12]) ? $matches[12] : $matches[9]);
21
+ $value = (isset($matches[10]) ? $matches[10] : $matches[7]);
22
+
23
+ return array(
24
+ "tag" => $matches[3],
25
+ "attribute" => $matches[4],
26
+ "value" => $value,
27
+ "quote" => $matches[6],
28
+ "prefix" => $matches[1].$matches[6],
29
+ "suffix" => $matches[6].$suffix,
30
+ "before_attribute" => $matches[2],
31
+ "after_attribute" => $suffix,
32
+ );
33
+ } /* function FeedWordPressHTML::attributeMatch () */
34
+ } /* class FeedWordPressHTML */
35
+
magpiemocklink.class.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class MagpieMockLink extends SyndicatedLink {
3
+ var $url;
4
+
5
+ function MagpieMockLink ($rss, $url) {
6
+ $this->link = $rss;
7
+ $this->magpie = $rss;
8
+ $this->url = $url;
9
+ $this->id = -1;
10
+ $this->settings = array(
11
+ 'unfamiliar category' => 'default',
12
+
13
+ );
14
+ } /* function MagpieMockLink::MagpieMockLink () */
15
+
16
+ function poll ($crash_ts = NULL) {
17
+ // Do nothing but update copy of feed
18
+ $this->magpie = fetch_rss($this->url);
19
+ $this->link = $this->magpie;
20
+ } /* function MagpieMockLink::poll () */
21
+
22
+ function uri () {
23
+ return $this->url;
24
+ } /* function MagpieMockLink::uri() */
25
+
26
+ function homepage () {
27
+ return (is_object($this->magpie) ? $this->magpie->channel['link'] : null);
28
+ } /* function MagpieMockLink::homepage () */
29
+ } /* class MagpieMockLink */
30
+
31
+
posts-page.php ADDED
@@ -0,0 +1,443 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once(dirname(__FILE__) . '/admin-ui.php');
3
+
4
+ function fwp_posts_page () {
5
+ global $wpdb, $wp_db_version;
6
+
7
+ FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_posts_settings', /*capability=*/ 'manage_links');
8
+
9
+ if (isset($GLOBALS['fwp_post']['save']) or isset($GLOBALS['fwp_post']['fix_mismatch'])) :
10
+ $link_id = $_REQUEST['save_link_id'];
11
+ elseif (isset($_REQUEST['link_id'])) :
12
+ $link_id = $_REQUEST['link_id'];
13
+ else :
14
+ $link_id = NULL;
15
+ endif;
16
+
17
+ if (is_numeric($link_id) and $link_id) :
18
+ $link =& new SyndicatedLink($link_id);
19
+ else :
20
+ $link = NULL;
21
+ endif;
22
+
23
+ $mesg = null;
24
+
25
+ ////////////////////////////////////////////////
26
+ // Process POST request, if any /////////////////
27
+ ////////////////////////////////////////////////
28
+ if (isset($GLOBALS['fwp_post']['save'])) :
29
+ // custom post settings
30
+ foreach ($GLOBALS['fwp_post']['notes'] as $mn) :
31
+ $mn['key0'] = trim($mn['key0']);
32
+ $mn['key1'] = trim($mn['key1']);
33
+
34
+ if (strlen($mn['key0']) > 0) :
35
+ unset($custom_settings[$mn['key0']]); // out with the old
36
+ endif;
37
+
38
+ if (($mn['action']=='update') and (strlen($mn['key1']) > 0)) :
39
+ $custom_settings[$mn['key1']] = $mn['value']; // in with the new
40
+ endif;
41
+ endforeach;
42
+
43
+ if (is_object($link) and $link->found()) :
44
+ $alter = array ();
45
+
46
+ $link->settings['postmeta'] = serialize($custom_settings);
47
+
48
+ // Post status, comment status, ping status
49
+ foreach (array('post', 'comment', 'ping') as $what) :
50
+ $sfield = "feed_{$what}_status";
51
+ if (isset($GLOBALS['fwp_post'][$sfield])) :
52
+ if ($GLOBALS['fwp_post'][$sfield]=='site-default') :
53
+ unset($link->settings["{$what} status"]);
54
+ else :
55
+ $link->settings["{$what} status"] = $GLOBALS['fwp_post'][$sfield];
56
+ endif;
57
+ endif;
58
+ endforeach;
59
+
60
+ $alter[] = "link_notes = '".$wpdb->escape($link->settings_to_notes())."'";
61
+
62
+ $alter_set = implode(", ", $alter);
63
+
64
+ // issue update query
65
+ $result = $wpdb->query("
66
+ UPDATE $wpdb->links
67
+ SET $alter_set
68
+ WHERE link_id='$link_id'
69
+ ");
70
+ $updated_link = true;
71
+
72
+ // reload link information from DB
73
+ if (function_exists('clean_bookmark_cache')) :
74
+ clean_bookmark_cache($link_id);
75
+ endif;
76
+ $link =& new SyndicatedLink($link_id);
77
+ else :
78
+ // update_option ...
79
+ if (isset($GLOBALS['fwp_post']['feed_post_status'])) :
80
+ update_option('feedwordpress_syndicated_post_status', $GLOBALS['fwp_post']['feed_post_status']);
81
+ endif;
82
+
83
+ update_option('feedwordpress_custom_settings', serialize($custom_settings));
84
+
85
+ update_option('feedwordpress_munge_permalink', $_REQUEST['munge_permalink']);
86
+ update_option('feedwordpress_use_aggregator_source_data', $_REQUEST['use_aggregator_source_data']);
87
+ update_option('feedwordpress_formatting_filters', $_REQUEST['formatting_filters']);
88
+
89
+ if (isset($_REQUEST['feed_comment_status']) and ($_REQUEST['feed_comment_status'] == 'open')) :
90
+ update_option('feedwordpress_syndicated_comment_status', 'open');
91
+ else :
92
+ update_option('feedwordpress_syndicated_comment_status', 'closed');
93
+ endif;
94
+
95
+ if (isset($_REQUEST['feed_ping_status']) and ($_REQUEST['feed_ping_status'] == 'open')) :
96
+ update_option('feedwordpress_syndicated_ping_status', 'open');
97
+ else :
98
+ update_option('feedwordpress_syndicated_ping_status', 'closed');
99
+ endif;
100
+
101
+ $updated_link = true;
102
+ endif;
103
+ else :
104
+ $updated_link = false;
105
+ endif;
106
+
107
+ ////////////////////////////////////////////////
108
+ // Get defaults from database //////////////////
109
+ ////////////////////////////////////////////////
110
+
111
+ $post_status_global = get_option('feedwordpress_syndicated_post_status');
112
+ if (!$post_status_global) : $post_status_global = 'publish'; endif;
113
+
114
+ $comment_status_global = get_option('feedwordpress_syndicated_comment_status');
115
+ if (!$comment_status_global) : $comment_status_global = 'closed'; endif;
116
+
117
+ $ping_status_global = get_option('feedwordpress_syndicated_ping_status');
118
+ if (!$ping_status_global) : $ping_status_global = 'closed'; endif;
119
+
120
+ $status['post'] = array('publish' => '', 'private' => '', 'draft' => '');
121
+ if (SyndicatedPost::use_api('post_status_pending')) :
122
+ $status['post']['pending'] = '';
123
+ endif;
124
+
125
+ $status['comment'] = array('open' => '', 'closed' => '');
126
+ $status['ping'] = array('open' => '', 'closed' => '');
127
+
128
+ if (is_object($link) and $link->found()) :
129
+ $thePostsPhrase = __('posts from this feed');
130
+
131
+ foreach (array('post', 'comment', 'ping') as $what) :
132
+ $status[$what]['site-default'] = '';
133
+ if (isset($link->settings["{$what} status"])) :
134
+ $status[$what][$link->settings["{$what} status"]] = ' checked="checked"';
135
+ else :
136
+ $status[$what]['site-default'] = ' checked="checked"';
137
+ endif;
138
+ endforeach;
139
+
140
+ $custom_settings = $link->settings["postmeta"];
141
+ if ($custom_settings) :
142
+ $custom_settings = unserialize($custom_settings);
143
+ endif;
144
+
145
+ if (!is_array($custom_settings)) :
146
+ $custom_settings = array();
147
+ endif;
148
+ else :
149
+ $thePostsPhrase = __('syndicated posts');
150
+
151
+ $status['post'][$post_status_global] = ' checked="checked"';
152
+ $status['comment'][$comment_status_global] = ' checked="checked"';
153
+ $status['ping'][$ping_status_global] = ' checked="checked"';
154
+
155
+ $munge_permalink = get_option('feedwordpress_munge_permalink');
156
+ $formatting_filters = get_option('feedwordpress_formatting_filters');
157
+ $use_aggregator_source_data = get_option('feedwordpress_use_aggregator_source_data');
158
+
159
+ $custom_settings = get_option('feedwordpress_custom_settings');
160
+ if ($custom_settings) :
161
+ $custom_settings = unserialize($custom_settings);
162
+ endif;
163
+
164
+ if (!is_array($custom_settings)) :
165
+ $custom_settings = array();
166
+ endif;
167
+ endif;
168
+ ?>
169
+ <script type="text/javascript">
170
+ function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) {
171
+ if (typeof(visibleStyle)=='undefined') visibleStyle = 'block';
172
+
173
+ var rollup=document.getElementById(item);
174
+ var newuser=document.getElementById(appear);
175
+ var sitewide=document.getElementById(disappear);
176
+ if (rollup) {
177
+ if ((checkbox && rollup.checked) || (!checkbox && value==rollup.value)) {
178
+ if (newuser) newuser.style.display=visibleStyle;
179
+ if (sitewide) sitewide.style.display='none';
180
+ } else {
181
+ if (newuser) newuser.style.display='none';
182
+ if (sitewide) sitewide.style.display=visibleStyle;
183
+ }
184
+ }
185
+ }
186
+ </script>
187
+
188
+ <?php if ($updated_link) : ?>
189
+ <div class="updated"><p>Syndicated posts settings updated.</p></div>
190
+ <?php elseif (!is_null($mesg)) : ?>
191
+ <div class="updated"><p><?php print wp_specialchars($mesg, 1); ?></p></div>
192
+ <?php endif; ?>
193
+
194
+ <div class="wrap">
195
+ <form style="position: relative" action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
196
+ <div><?php
197
+ FeedWordPressCompatibility::stamp_nonce('feedwordpress_posts_settings');
198
+
199
+ if (is_numeric($link_id) and $link_id) :
200
+ ?>
201
+ <input type="hidden" name="save_link_id" value="<?php echo $link_id; ?>" />
202
+ <?php
203
+ else :
204
+ ?>
205
+ <input type="hidden" name="save_link_id" value="*" />
206
+ <?php
207
+ endif;
208
+ ?>
209
+ </div>
210
+
211
+ <?php $links = FeedWordPress::syndicated_links(); ?>
212
+ <?php if (fwp_test_wp_version(FWP_SCHEMA_27)) : ?>
213
+ <div class="icon32"><img src="<?php print htmlspecialchars(WP_PLUGIN_URL.'/'.$GLOBALS['fwp_path'].'/feedwordpress.png'); ?>" alt="" /></div>
214
+ <?php endif; ?>
215
+
216
+ <h2>Syndicated Post Settings<?php if (!is_null($link) and $link->found()) : ?>: <?php echo wp_specialchars($link->link->link_name, 1); ?><?php endif; ?></h2>
217
+
218
+ <style type="text/css">
219
+ table.edit-form th { width: 27%; vertical-align: top; }
220
+ table.edit-form td { width: 73%; vertical-align: top; }
221
+ table.edit-form td ul.options { margin: 0; padding: 0; list-style: none; }
222
+ </style>
223
+
224
+ <?php if (fwp_test_wp_version(FWP_SCHEMA_27)) : ?>
225
+ <style type="text/css">
226
+ #post-search {
227
+ float: right;
228
+ margin:11px 12px 0;
229
+ min-width: 130px;
230
+ position:relative;
231
+ }
232
+ .fwpfs {
233
+ color: #dddddd;
234
+ background:#797979 url(<?php bloginfo('home') ?>/wp-admin/images/fav.png) repeat-x scroll left center;
235
+ border-color:#777777 #777777 #666666 !important; -moz-border-radius-bottomleft:12px;
236
+ -moz-border-radius-bottomright:12px;
237
+ -moz-border-radius-topleft:12px;
238
+ -moz-border-radius-topright:12px;
239
+ border-style:solid;
240
+ border-width:1px;
241
+ line-height:15px;
242
+ padding:3px 30px 4px 12px;
243
+ }
244
+ .fwpfs.slide-down {
245
+ border-bottom-color: #626262;
246
+ -moz-border-radius-bottomleft:0;
247
+ -moz-border-radius-bottomright:0;
248
+ -moz-border-radius-topleft:12px;
249
+ -moz-border-radius-topright:12px;
250
+ background-image:url(<?php bloginfo('home') ?>/wp-admin/images/fav-top.png);
251
+ background-position:0 top;
252
+ background-repeat:repeat-x;
253
+ border-bottom-style:solid;
254
+ border-bottom-width:1px;
255
+ }
256
+ </style>
257
+
258
+ <script type="text/javascript">
259
+ jQuery(document).ready(function($){
260
+ $('.fwpfs').toggle(
261
+ function(){$('.fwpfs').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideDown') ) { $('.fwpfs').addClass('slide-down'); }}, 10) },
262
+ function(){$('.fwpfs').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('.fwpfs').hasClass('slideUp') ) { $('.fwpfs').removeClass('slide-down'); }}, 10) }
263
+ );
264
+ $('.fwpfs').bind(
265
+ 'change',
266
+ function () { this.form.submit(); }
267
+ );
268
+ $('#post-search .button').css( 'display', 'none' );
269
+ });
270
+ </script>
271
+ <?php endif; /* else : */?>
272
+ <p id="post-search">
273
+ <select name="link_id" class="fwpfs" style="max-width: 20.0em;">
274
+ <option value="*"<?php if (is_null($link) or !$link->found()) : ?> selected="selected"<?php endif; ?>>- defaults for all feeds -</option>
275
+ <?php if ($links) : foreach ($links as $ddlink) : ?>
276
+ <option value="<?php print (int) $ddlink->link_id; ?>"<?php if (!is_null($link) and ($link->link->link_id==$ddlink->link_id)) : ?> selected="selected"<?php endif; ?>><?php print wp_specialchars($ddlink->link_name, 1); ?></option>
277
+ <?php endforeach; endif; ?>
278
+ </select>
279
+ <input class="button" type="submit" name="go" value="<?php _e('Go') ?> &raquo;" />
280
+ </p>
281
+ <?php /* endif; */ ?>
282
+
283
+ <?php if (!is_null($link) and $link->found()) : ?>
284
+ <p>These settings only affect posts syndicated from
285
+ <strong><?php echo wp_specialchars($link->link->link_name, 1); ?></strong>.</p>
286
+ <?php else : ?>
287
+ <p>These settings affect posts syndicated from any feed unless they are overridden
288
+ by settings for that specific feed.</p>
289
+ <?php endif; ?>
290
+
291
+ <div id="poststuff">
292
+ <div id="post-body">
293
+ <?php fwp_option_box_opener('Publication', 'publicationdiv', 'postbox'); ?>
294
+ <table class="form-table" cellspacing="2" cellpadding="5">
295
+ <tr><th width="27%" scope="row" style="vertical-align:top">Status for new posts:</th>
296
+ <td width="73%" style="vertical-align:top"><ul style="margin:0; list-style:none">
297
+
298
+ <?php if (is_object($link) and $link->found()) : ?>
299
+ <li><label><input type="radio" name="feed_post_status" value="site-default"
300
+ <?php echo $status['post']['site-default']; ?> /> Use <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php print basename(__FILE__); ?>">site-wide setting</a>
301
+ (currently: <strong><?php echo ($post_status_global ? $post_status_global : 'publish'); ?></strong>)</label></li>
302
+ <?php endif; ?>
303
+
304
+ <li><label><input type="radio" name="feed_post_status" value="publish"
305
+ <?php echo $status['post']['publish']; ?> /> Publish <?php print $thePostsPhrase; ?> immediately</label></li>
306
+
307
+ <?php if (SyndicatedPost::use_api('post_status_pending')) : ?>
308
+ <li><label><input type="radio" name="feed_post_status" value="pending"
309
+ <?php echo $status['post']['pending']; ?>/> Hold <?php print $thePostsPhrase; ?> for review; mark as Pending</label></li>
310
+ <?php endif; ?>
311
+
312
+ <li><label><input type="radio" name="feed_post_status" value="draft"
313
+ <?php echo $status['post']['draft']; ?> /> Save <?php print $thePostsPhrase; ?> as drafts</label></li>
314
+ <li><label><input type="radio" name="feed_post_status" value="private"
315
+ <?php echo $status['post']['private']; ?> /> Save <?php print $thePostsPhrase; ?> as private posts</label></li>
316
+ </ul></td>
317
+ </tr>
318
+ </table>
319
+ <?php
320
+ fwp_option_box_closer();
321
+ ?>
322
+
323
+ <?php if (!(is_object($link) and $link->found())) : ?>
324
+ <?php fwp_option_box_opener('Formatting', 'formattingdiv', 'postbox'); ?>
325
+ <table class="form-table" cellspacing="2" cellpadding="5">
326
+ <tr><th scope="row">Formatting filters:</th>
327
+ <td><select name="formatting_filters" size="1">
328
+ <option value="no"<?php echo ($formatting_filters!='yes')?' selected="selected"':''; ?>>Protect syndicated posts from formatting filters</option>
329
+ <option value="yes"<?php echo ($formatting_filters=='yes')?' selected="selected"':''; ?>>Expose syndicated posts to formatting filters</option>
330
+ </select>
331
+ <p class="setting-description">If you have trouble getting plugins to work that are supposed to insert
332
+ elements after posts (like relevant links or a social networking
333
+ <q>Share This</q> button), try changing this option to see if it fixes your
334
+ problem.</p>
335
+ </td></tr>
336
+ </table>
337
+ <?php fwp_option_box_closer(); ?>
338
+
339
+ <?php
340
+ fwp_option_box_opener('Links', 'linksdiv', 'postbox');
341
+ ?>
342
+ <table class="form-table" cellspacing="2" cellpadding="5">
343
+ <tr><th scope="row">Permalinks:</th>
344
+ <td><select name="munge_permalink" size="1">
345
+ <option value="yes"<?php echo ($munge_permalink=='yes')?' selected="selected"':''; ?>>point to the copy on the original website</option>
346
+ <option value="no"<?php echo ($munge_permalink=='no')?' selected="selected"':''; ?>>point to the local copy on this website</option>
347
+ </select></td>
348
+ </tr>
349
+
350
+ <tr><th scope="row">Posts from aggregator feeds:</th>
351
+ <td><ul class="options">
352
+ <li><label><input type="radio" name="use_aggregator_source_data" value="no"<?php echo ($use_aggregator_source_data!="yes")?' checked="checked"':''; ?>> Give the aggregator itself as the source of posts from an aggregator feed.</label></li>
353
+ <li><label><input type="radio" name="use_aggregator_source_data" value="yes"<?php echo ($use_aggregator_source_data=="yes")?' checked="checked"':''; ?>> Give the original source of the post as the source, not the aggregator.</label></li>
354
+ </ul>
355
+ <p class="setting-description">Some feeds (for example, those produced by FeedWordPress) aggregate content from several different sources, and include information about the original source of the post.
356
+ This setting controls what FeedWordPress will give as the source of posts from
357
+ such an aggregator feed.</p>
358
+ </td></tr>
359
+ </table>
360
+ <?php
361
+ fwp_option_box_closer();
362
+ fwp_linkedit_periodic_submit();
363
+ endif;
364
+
365
+ fwp_option_box_opener(__('Comments & Pings'), 'commentstatus', 'postbox');
366
+ ?>
367
+ <table class="form-table" cellspacing="2" cellpadding="5">
368
+ <tr><th scope="row"><?php print __('Comments') ?>:</th>
369
+ <td><ul class="options">
370
+ <?php if (is_object($link) and $link->found()) : ?>
371
+ <li><label><input type="radio" name="feed_comment_status" value="site-default"
372
+ <?php echo $status['comment']['site-default']; ?> /> Use <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php print basename(__FILE__); ?>">site-wide setting</a>
373
+ (currently: <strong><?php echo $comment_status_global; ?></strong>)</label></li>
374
+ <?php endif; ?>
375
+
376
+ <li><label><input type="radio" name="feed_comment_status" value="open"<?php echo $status['comment']['open'] ?> /> Allow comments on syndicated posts</label></li>
377
+ <li><label><input type="radio" name="feed_comment_status" value="closed"<?php echo $status['comment']['closed']; ?> /> Don't allow comments on syndicated posts</label></li>
378
+ </ul></td></tr>
379
+
380
+ <tr><th scope="row"><?php print __('Pings') ?>:</th>
381
+ <td><ul class="options">
382
+ <?php if (is_object($link) and $link->found()) : ?>
383
+ <li><label><input type="radio" name="feed_ping_status" value="site-default"
384
+ <?php echo $status['ping']['site-default']; ?> /> Use <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php print basename(__FILE__); ?>">site-wide setting</a>
385
+ (currently: <strong><?php echo $ping_status_global; ?></strong>)</label></li>
386
+ <?php endif; ?>
387
+
388
+ <li><label><input type="radio" name="feed_ping_status" value="open"<?php echo $status['ping']['open']; ?> /> Accept pings on syndicated posts</label></li>
389
+ <li><label><input type="radio" name="feed_ping_status" value="closed"<?php echo $status['ping']['closed']; ?> /> Don't accept pings on syndicated posts</label></li>
390
+ </ul></td></tr>
391
+ </table>
392
+ <?php
393
+ fwp_option_box_closer();
394
+ fwp_linkedit_periodic_submit();
395
+ ?>
396
+
397
+ <?php fwp_option_box_opener('Custom Post Settings (to apply to each syndicated post)', 'postcustom', 'postbox'); ?>
398
+ <div id="postcustomstuff">
399
+ <table id="meta-list" cellpadding="3">
400
+ <tr>
401
+ <th>Key</th>
402
+ <th>Value</th>
403
+ <th>Action</th>
404
+ </tr>
405
+
406
+ <?php
407
+ $i = 0;
408
+ foreach ($custom_settings as $key => $value) :
409
+ ?>
410
+ <tr style="vertical-align:top">
411
+ <th width="30%" scope="row"><input type="hidden" name="notes[<?php echo $i; ?>][key0]" value="<?php echo wp_specialchars($key, 'both'); ?>" />
412
+ <input id="notes-<?php echo $i; ?>-key" name="notes[<?php echo $i; ?>][key1]" value="<?php echo wp_specialchars($key, 'both'); ?>" /></th>
413
+ <td width="60%"><textarea rows="2" cols="40" id="notes-<?php echo $i; ?>-value" name="notes[<?php echo $i; ?>][value]"><?php echo wp_specialchars($value, 'both'); ?></textarea></td>
414
+ <td width="10%"><select name="notes[<?php echo $i; ?>][action]">
415
+ <option value="update">save changes</option>
416
+ <option value="delete">delete this setting</option>
417
+ </select></td>
418
+ </tr>
419
+ <?php
420
+ $i++;
421
+ endforeach;
422
+ ?>
423
+ <tr>
424
+ <th scope="row"><input type="text" size="10" name="notes[<?php echo $i; ?>][key1]" value="" /></th>
425
+ <td><textarea name="notes[<?php echo $i; ?>][value]" rows="2" cols="40"></textarea></td>
426
+ <td><em>add new setting...</em><input type="hidden" name="notes[<?php echo $i; ?>][action]" value="update" /></td>
427
+ </tr>
428
+ </table>
429
+ <?php fwp_option_box_closer(); ?>
430
+
431
+ </div>
432
+ </div>
433
+
434
+ <p class="submit">
435
+ <input class="button-primary" type="submit" name="save" value="Save Changes" />
436
+ </p>
437
+ </form>
438
+ </div> <!-- class="wrap" -->
439
+ <?php
440
+ } /* function fwp_posts_page () */
441
+
442
+ fwp_posts_page();
443
+
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: Charles Johnson
3
  Donate link: http://projects.radgeek.com/feedwordpress/
4
  Tags: syndication, aggregation, feed, atom, rss
5
  Requires at least: 1.5
6
- Tested up to: 2.7
7
- Stable tag: 2008.1214
8
 
9
  FeedWordPress syndicates content from feeds you choose into your WordPress weblog.
10
 
3
  Donate link: http://projects.radgeek.com/feedwordpress/
4
  Tags: syndication, aggregation, feed, atom, rss
5
  Requires at least: 1.5
6
+ Tested up to: 2.8
7
+ Stable tag: 2009.0612
8
 
9
  FeedWordPress syndicates content from feeds you choose into your WordPress weblog.
10
 
syndicatedlink.class.php ADDED
@@ -0,0 +1,431 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ # class SyndicatedLink: represents a syndication feed stored within the
3
+ # WordPress database
4
+ #
5
+ # To keep things compact and editable from within WordPress, we use all the
6
+ # links under a particular category in the WordPress "Blogroll" for the list of
7
+ # feeds to syndicate. "Contributors" is the category used by default; you can
8
+ # configure that under Options --> Syndication.
9
+ #
10
+ # Fields used are:
11
+ #
12
+ # * link_rss: the URI of the Atom/RSS feed to syndicate
13
+ #
14
+ # * link_notes: user-configurable options, with keys and values
15
+ # like so:
16
+ #
17
+ # key: value
18
+ # cats: computers\nweb
19
+ # feed/key: value
20
+ #
21
+ # Keys that start with "feed/" are gleaned from the data supplied
22
+ # by the feed itself, and will be overwritten with each update.
23
+ #
24
+ # Values have linebreak characters escaped with C-style
25
+ # backslashes (so, for example, a newline becomes "\n").
26
+ #
27
+ # The value of `cats` is used as a newline-separated list of
28
+ # default categories for any post coming from a particular feed.
29
+ # (In the example above, any posts from this feed will be placed
30
+ # in the "computers" and "web" categories--*in addition to* any
31
+ # categories that may already be applied to the posts.)
32
+ #
33
+ # Values of keys in link_notes are accessible from templates using
34
+ # the function `get_feed_meta($key)` if this plugin is activated.
35
+
36
+ class SyndicatedLink {
37
+ var $id = null;
38
+ var $link = null;
39
+ var $settings = array ();
40
+ var $magpie = null;
41
+
42
+ function SyndicatedLink ($link) {
43
+ global $wpdb;
44
+
45
+ if (is_object($link)) :
46
+ $this->link = $link;
47
+ $this->id = $link->link_id;
48
+ else :
49
+ $this->id = $link;
50
+ if (function_exists('get_bookmark')) : // WP 2.1+
51
+ $this->link = get_bookmark($link);
52
+ else :
53
+ $this->link = $wpdb->get_row("
54
+ SELECT * FROM $wpdb->links
55
+ WHERE (link_id = '".$wpdb->escape($link)."')"
56
+ );
57
+ endif;
58
+ endif;
59
+
60
+ if (strlen($this->link->link_rss) > 0) :
61
+ // Read off feed settings from link_notes
62
+ $notes = explode("\n", $this->link->link_notes);
63
+ foreach ($notes as $note):
64
+ list($key, $value) = explode(": ", $note, 2);
65
+
66
+ if (strlen($key) > 0) :
67
+ // Unescape and trim() off the whitespace.
68
+ // Thanks to Ray Lischner for pointing out the
69
+ // need to trim off whitespace.
70
+ $this->settings[$key] = stripcslashes (trim($value));
71
+ endif;
72
+ endforeach;
73
+
74
+ // "Magic" feed settings
75
+ $this->settings['link/uri'] = $this->link->link_rss;
76
+ $this->settings['link/name'] = $this->link->link_name;
77
+ $this->settings['link/id'] = $this->link->link_id;
78
+
79
+ // `hardcode categories` and `unfamiliar categories` are deprecated in favor of `unfamiliar category`
80
+ if (
81
+ isset($this->settings['unfamiliar categories'])
82
+ and !isset($this->settings['unfamiliar category'])
83
+ ) :
84
+ $this->settings['unfamiliar category'] = $this->settings['unfamiliar categories'];
85
+ endif;
86
+ if (
87
+ FeedWordPress::affirmative($this->settings, 'hardcode categories')
88
+ and !isset($this->settings['unfamiliar category'])
89
+ ) :
90
+ $this->settings['unfamiliar category'] = 'default';
91
+ endif;
92
+
93
+ // Set this up automagically for del.icio.us
94
+ $bits = parse_url($this->link->link_rss);
95
+ $tagspacers = array('del.icio.us', 'feeds.delicious.com');
96
+ if (!isset($this->settings['cat_split']) and in_array($bits['host'], $tagspacers)) :
97
+ $this->settings['cat_split'] = '\s'; // Whitespace separates multiple tags in del.icio.us RSS feeds
98
+ endif;
99
+
100
+ if (isset($this->settings['cats'])):
101
+ $this->settings['cats'] = preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, $this->settings['cats']);
102
+ endif;
103
+ if (isset($this->settings['tags'])):
104
+ $this->settings['tags'] = preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, $this->settings['tags']);
105
+ endif;
106
+
107
+ if (isset($this->settings['map authors'])) :
108
+ $author_rules = explode("\n\n", $this->settings['map authors']);
109
+ $ma = array();
110
+ foreach ($author_rules as $rule) :
111
+ list($rule_type, $author_name, $author_action) = explode("\n", $rule);
112
+
113
+ // Normalize for case and whitespace
114
+ $rule_type = strtolower(trim($rule_type));
115
+ $author_name = strtolower(trim($author_name));
116
+ $author_action = strtolower(trim($author_action));
117
+
118
+ $ma[$rule_type][$author_name] = $author_action;
119
+ endforeach;
120
+ $this->settings['map authors'] = $ma;
121
+ endif;
122
+ endif;
123
+ } /* SyndicatedLink::SyndicatedLink () */
124
+
125
+ function found () {
126
+ return is_object($this->link);
127
+ } /* SyndicatedLink::found () */
128
+
129
+ function stale () {
130
+ $stale = true;
131
+ if (isset($this->settings['update/hold']) and ($this->settings['update/hold']=='ping')) :
132
+ $stale = false; // don't update on any timed updates; pings only
133
+ elseif (isset($this->settings['update/hold']) and ($this->settings['update/hold']=='next')) :
134
+ $stale = true; // update on the next timed update
135
+ elseif (!isset($this->settings['update/ttl']) or !isset($this->settings['update/last'])) :
136
+ $stale = true; // initial update
137
+ else :
138
+ $after = ((int) $this->settings['update/last'])
139
+ +((int) $this->settings['update/ttl'] * 60);
140
+ $stale = (time() >= $after);
141
+ endif;
142
+ return $stale;
143
+ } /* SyndicatedLink::stale () */
144
+
145
+ function poll ($crash_ts = NULL) {
146
+ global $wpdb;
147
+
148
+ $this->magpie = fetch_rss($this->link->link_rss);
149
+ $new_count = NULL;
150
+
151
+ $resume = FeedWordPress::affirmative($this->settings, 'update/unfinished');
152
+ if ($resume) :
153
+ // pick up where we left off
154
+ $processed = array_map('trim', explode("\n", $this->settings['update/processed']));
155
+ else :
156
+ // begin at the beginning
157
+ $processed = array();
158
+ endif;
159
+
160
+ if (is_object($this->magpie)) :
161
+ $new_count = array('new' => 0, 'updated' => 0);
162
+
163
+ # -- Update Link metadata live from feed
164
+ $channel = $this->magpie->channel;
165
+
166
+ if (!isset($channel['id'])) :
167
+ $channel['id'] = $this->link->link_rss;
168
+ endif;
169
+
170
+ $update = array();
171
+ if (!$this->hardcode('url') and isset($channel['link'])) :
172
+ $update[] = "link_url = '".$wpdb->escape($channel['link'])."'";
173
+ endif;
174
+
175
+ if (!$this->hardcode('name') and isset($channel['title'])) :
176
+ $update[] = "link_name = '".$wpdb->escape($channel['title'])."'";
177
+ endif;
178
+
179
+ if (!$this->hardcode('description')) :
180
+ if (isset($channel['tagline'])) :
181
+ $update[] = "link_description = '".$wpdb->escape($channel['tagline'])."'";
182
+ elseif (isset($channel['description'])) :
183
+ $update[] = "link_description = '".$wpdb->escape($channel['description'])."'";
184
+ endif;
185
+ endif;
186
+
187
+ $this->settings = array_merge($this->settings, $this->flatten_array($channel));
188
+
189
+ $this->settings['update/last'] = time(); $ttl = $this->ttl();
190
+ if (!is_null($ttl)) :
191
+ $this->settings['update/ttl'] = $ttl;
192
+ $this->settings['update/timed'] = 'feed';
193
+ else :
194
+ $this->settings['update/ttl'] = rand(30, 120); // spread over time interval for staggered updates
195
+ $this->settings['update/timed'] = 'automatically';
196
+ endif;
197
+
198
+ if (!isset($this->settings['update/hold']) or $this->settings['update/hold']!='ping') :
199
+ $this->settings['update/hold'] = 'scheduled';
200
+ endif;
201
+
202
+ $this->settings['update/unfinished'] = 'yes';
203
+
204
+ $update[] = "link_notes = '".$wpdb->escape($this->settings_to_notes())."'";
205
+
206
+ $update_set = implode(',', $update);
207
+
208
+ // Update the properties of the link from the feed information
209
+ $result = $wpdb->query("
210
+ UPDATE $wpdb->links
211
+ SET $update_set
212
+ WHERE link_id='$this->id'
213
+ ");
214
+
215
+ # -- Add new posts from feed and update any updated posts
216
+ $crashed = false;
217
+
218
+ if (is_array($this->magpie->items)) :
219
+ foreach ($this->magpie->items as $item) :
220
+ $post =& new SyndicatedPost($item, $this);
221
+ if (!$resume or !in_array(trim($post->guid()), $processed)) :
222
+ $processed[] = $post->guid();
223
+ if (!$post->filtered()) :
224
+ $new = $post->store();
225
+ if ( $new !== false ) $new_count[$new]++;
226
+ endif;
227
+
228
+ if (!is_null($crash_ts) and (time() > $crash_ts)) :
229
+ $crashed = true;
230
+ break;
231
+ endif;
232
+ endif;
233
+ endforeach;
234
+ endif;
235
+
236
+ // Copy back any changes to feed settings made in the course of updating (e.g. new author rules)
237
+ $to_notes = $this->settings;
238
+
239
+ $this->settings['update/processed'] = $processed;
240
+ if (!$crashed) :
241
+ $this->settings['update/unfinished'] = 'no';
242
+ endif;
243
+
244
+ $update_set = "link_notes = '".$wpdb->escape($this->settings_to_notes())."'";
245
+
246
+ // Update the properties of the link from the feed information
247
+ $result = $wpdb->query("
248
+ UPDATE $wpdb->links
249
+ SET $update_set
250
+ WHERE link_id='$this->id'
251
+ ");
252
+ endif;
253
+
254
+ return $new_count;
255
+ } /* SyndicatedLink::poll() */
256
+
257
+ function map_name_to_new_user ($name, $newuser_name) {
258
+ global $wpdb;
259
+
260
+ if (strlen($newuser_name) > 0) :
261
+ $userdata = array();
262
+ $userdata['ID'] = NULL;
263
+
264
+ $userdata['user_login'] = sanitize_user($newuser_name);
265
+ $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
266
+
267
+ $userdata['user_nicename'] = sanitize_title($newuser_name);
268
+ $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
269
+
270
+ $userdata['display_name'] = $wpdb->escape($newuser_name);
271
+
272
+ $newuser_id = wp_insert_user($userdata);
273
+ if (is_numeric($newuser_id)) :
274
+ if (is_null($name)) : // Unfamiliar author
275
+ $this->settings['unfamiliar author'] = $newuser_id;
276
+ else :
277
+ $this->settings['map authors']['name'][$name] = $newuser_id;
278
+ endif;
279
+ else :
280
+ // TODO: Add some error detection and reporting
281
+ endif;
282
+ else :
283
+ // TODO: Add some error reporting
284
+ endif;
285
+ } /* SyndicatedLink::map_name_to_new_user () */
286
+
287
+ function settings_to_notes () {
288
+ $to_notes = $this->settings;
289
+
290
+ unset($to_notes['link/id']); // Magic setting; don't save
291
+ unset($to_notes['link/uri']); // Magic setting; don't save
292
+ unset($to_notes['link/name']); // Magic setting; don't save
293
+ unset($to_notes['hardcode categories']); // Deprecated
294
+ unset($to_notes['unfamiliar categories']); // Deprecated
295
+
296
+ // Collapse array settings
297
+ if (isset($to_notes['update/processed']) and (is_array($to_notes['update/processed']))) :
298
+ $to_notes['update/processed'] = implode("\n", $to_notes['update/processed']);
299
+ endif;
300
+
301
+ if (is_array($to_notes['cats'])) :
302
+ $to_notes['cats'] = implode(FEEDWORDPRESS_CAT_SEPARATOR, $to_notes['cats']);
303
+ endif;
304
+ if (is_array($to_notes['tags'])) :
305
+ $to_notes['tags'] = implode(FEEDWORDPRESS_CAT_SEPARATOR, $to_notes['tags']);
306
+ endif;
307
+
308
+ // Collapse the author mapping rule structure back into a flat string
309
+ if (isset($to_notes['map authors'])) :
310
+ $ma = array();
311
+ foreach ($to_notes['map authors'] as $rule_type => $author_rules) :
312
+ foreach ($author_rules as $author_name => $author_action) :
313
+ $ma[] = $rule_type."\n".$author_name."\n".$author_action;
314
+ endforeach;
315
+ endforeach;
316
+ $to_notes['map authors'] = implode("\n\n", $ma);
317
+ endif;
318
+
319
+ $notes = '';
320
+ foreach ($to_notes as $key => $value) :
321
+ $notes .= $key . ": ". addcslashes($value, "\0..\37".'\\') . "\n";
322
+ endforeach;
323
+ return $notes;
324
+ } /* SyndicatedLink::settings_to_notes () */
325
+
326
+ function uri () {
327
+ return (is_object($this->link) ? $this->link->link_rss : NULL);
328
+ } /* SyndicatedLink::uri () */
329
+
330
+ function homepage () {
331
+ return (isset($this->settings['feed/link']) ? $this->settings['feed/link'] : NULL);
332
+ } /* SyndicatedLink::homepage () */
333
+
334
+ function ttl () {
335
+ if (is_object($this->magpie)) :
336
+ $channel = $this->magpie->channel;
337
+ else :
338
+ $channel = array();
339
+ endif;
340
+
341
+ if (isset($channel['ttl'])) :
342
+ // "ttl stands for time to live. It's a number of
343
+ // minutes that indicates how long a channel can be
344
+ // cached before refreshing from the source."
345
+ // <http://blogs.law.harvard.edu/tech/rss#ltttlgtSubelementOfLtchannelgt>
346
+ $ret = $channel['ttl'];
347
+ elseif (isset($channel['sy']['updatefrequency']) or isset($channel['sy']['updateperiod'])) :
348
+ $period_minutes = array (
349
+ 'hourly' => 60, /* minutes in an hour */
350
+ 'daily' => 1440, /* minutes in a day */
351
+ 'weekly' => 10080, /* minutes in a week */
352
+ 'monthly' => 43200, /* minutes in a month */
353
+ 'yearly' => 525600, /* minutes in a year */
354
+ );
355
+
356
+ // "sy:updatePeriod: Describes the period over which the
357
+ // channel format is updated. Acceptable values are:
358
+ // hourly, daily, weekly, monthly, yearly. If omitted,
359
+ // daily is assumed." <http://web.resource.org/rss/1.0/modules/syndication/>
360
+ if (isset($channel['sy']['updateperiod'])) : $period = $channel['sy']['updateperiod'];
361
+ else : $period = 'daily';
362
+ endif;
363
+
364
+ // "sy:updateFrequency: Used to describe the frequency
365
+ // of updates in relation to the update period. A
366
+ // positive integer indicates how many times in that
367
+ // period the channel is updated. ... If omitted a value
368
+ // of 1 is assumed." <http://web.resource.org/rss/1.0/modules/syndication/>
369
+ if (isset($channel['sy']['updatefrequency'])) : $freq = (int) $channel['sy']['updatefrequency'];
370
+ else : $freq = 1;
371
+ endif;
372
+
373
+ $ret = (int) ($period_minutes[$period] / $freq);
374
+ else :
375
+ $ret = NULL;
376
+ endif;
377
+ return $ret;
378
+ } /* SyndicatedLink::ttl() */
379
+
380
+ // SyndicatedLink::flatten_array (): flatten an array. Useful for
381
+ // hierarchical and namespaced elements.
382
+ //
383
+ // Given an array which may contain array or object elements in it,
384
+ // return a "flattened" array: a one-dimensional array of scalars
385
+ // containing each of the scalar elements contained within the array
386
+ // structure. Thus, for example, if $a['b']['c']['d'] == 'e', then the
387
+ // returned array for FeedWordPress::flatten_array($a) will contain a key
388
+ // $a['feed/b/c/d'] with value 'e'.
389
+ function flatten_array ($arr, $prefix = 'feed/', $separator = '/') {
390
+ $ret = array ();
391
+ if (is_array($arr)) :
392
+ foreach ($arr as $key => $value) :
393
+ if (is_scalar($value)) :
394
+ $ret[$prefix.$key] = $value;
395
+ else :
396
+ $ret = array_merge($ret, $this->flatten_array($value, $prefix.$key.$separator, $separator));
397
+ endif;
398
+ endforeach;
399
+ endif;
400
+ return $ret;
401
+ } /* SyndicatedLink::flatten_array () */
402
+
403
+ function hardcode ($what) {
404
+ $default = get_option("feedwordpress_hardcode_$what");
405
+ if ( $default === 'yes' ) :
406
+ // If the default is to hardcode, then we want the
407
+ // negation of negative(): TRUE by default and FALSE if
408
+ // the setting is explicitly "no"
409
+ $ret = !FeedWordPress::negative($this->settings, "hardcode $what");
410
+ else :
411
+ // If the default is NOT to hardcode, then we want
412
+ // affirmative(): FALSE by default and TRUE if the
413
+ // setting is explicitly "yes"
414
+ $ret = FeedWordPress::affirmative($this->settings, "hardcode $what");
415
+ endif;
416
+ return $ret;
417
+ } /* SyndicatedLink::hardcode () */
418
+
419
+ function syndicated_status ($what, $default) {
420
+ global $wpdb;
421
+
422
+ $ret = get_option("feedwordpress_syndicated_{$what}_status");
423
+ if ( isset($this->settings["$what status"]) ) :
424
+ $ret = $this->settings["$what status"];
425
+ elseif (!$ret) :
426
+ $ret = $default;
427
+ endif;
428
+ return $wpdb->escape(trim(strtolower($ret)));
429
+ } /* SyndicatedLink:syndicated_status () */
430
+ } // class SyndicatedLink
431
+
syndication-options.php CHANGED
@@ -9,148 +9,57 @@ function fwp_syndication_options_page () {
9
  return;
10
  endif;
11
 
 
 
 
12
  if (isset($_POST['create_index'])) :
13
- check_admin_referer();
14
- if (!current_user_can('manage_options')) :
15
- die (__("Cheatin' uh ?"));
16
- else :
17
- FeedWordPress::create_guid_index();
18
  ?>
19
  <div class="updated">
20
  <p><?php _e('Index created on database table.')?></p>
21
  </div>
22
  <?php
23
- endif;
24
  endif;
25
 
26
  if (isset($_POST['submit']) or isset($_POST['create_index'])) :
27
- check_admin_referer();
28
-
29
- if (!current_user_can('manage_options')):
30
- die (__("Cheatin' uh ?"));
31
- else:
32
- update_option('feedwordpress_cat_id', $_REQUEST['syndication_category']);
33
- update_option('feedwordpress_munge_permalink', $_REQUEST['munge_permalink']);
34
- update_option('feedwordpress_use_aggregator_source_data', $_REQUEST['use_aggregator_source_data']);
35
- update_option('feedwordpress_formatting_filters', $_REQUEST['formatting_filters']);
36
- update_option('feedwordpress_update_logging', $_REQUEST['update_logging']);
37
-
38
- if ('newuser'==$_REQUEST['unfamiliar_author']) :
39
- $newuser_name = trim($_REQUEST['unfamiliar_author_newuser']);
40
- if (strlen($newuser_name) > 0) :
41
- $userdata = array();
42
- $userdata['ID'] = NULL;
43
-
44
- $userdata['user_login'] = sanitize_user($newuser_name);
45
- $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
46
-
47
- $userdata['user_nicename'] = sanitize_title($newuser_name);
48
- $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
49
-
50
- $userdata['display_name'] = $wpdb->escape($newuser_name);
51
-
52
- $newuser_id = wp_insert_user($userdata);
53
- if (is_numeric($newuser_id)) :
54
- update_option('feedwordpress_unfamiliar_author', $newuser_id);
55
- else :
56
- // TODO: Add some error detection and reporting
57
- endif;
58
- else :
59
- // TODO: Add some error reporting
60
- endif;
61
- else :
62
- update_option('feedwordpress_unfamiliar_author', $_REQUEST['unfamiliar_author']);
63
- endif;
64
-
65
- if (isset($_REQUEST['match_author_by_email']) and $_REQUEST['match_author_by_email']=='yes') :
66
- update_option('feedwordpress_do_not_match_author_by_email', 'no');
67
- else :
68
- update_option('feedwordpress_do_not_match_author_by_email', 'yes');
69
- endif;
70
-
71
- if (isset($_REQUEST['null_emails'])) :
72
- update_option('feedwordpress_null_email_set', $_REQUEST['null_emails']);
73
- endif;
74
-
75
- update_option('feedwordpress_unfamiliar_category', $_REQUEST['unfamiliar_category']);
76
- update_option('feedwordpress_syndicated_post_status', $_REQUEST['post_status']);
77
- update_option('feedwordpress_automatic_updates', ($_POST['automatic_updates']=='yes'));
78
- update_option('feedwordpress_update_time_limit', ($_POST['update_time_limit']=='yes')?(int) $_POST['time_limit_seconds']:0);
79
- update_option('feedwordpress_freshness', ($_POST['freshness_interval']*60));
80
-
81
- // Categories
82
- $cats = array();
83
- if (isset($_POST['post_category'])) :
84
- $cats = array();
85
- foreach ($_POST['post_category'] as $cat_id) :
86
- $cats[] = '{#'.$cat_id.'}';
87
- endforeach;
88
- endif;
89
-
90
- if (!empty($cats)) :
91
- update_option('feedwordpress_syndication_cats', implode(FEEDWORDPRESS_CAT_SEPARATOR, $cats));
92
- else :
93
- delete_option('feedwordpress_syndication_cats');
94
- endif;
95
-
96
- // Tags
97
- if (isset($_REQUEST['tags_input'])) :
98
- $tags = explode(",", $_REQUEST['tags_input']);
99
- else :
100
- $tags = array();
101
- endif;
102
-
103
- if (!empty($tags)) :
104
- update_option('feedwordpress_syndication_tags', implode(FEEDWORDPRESS_CAT_SEPARATOR, $tags));
105
- else :
106
- delete_option('feedwordpress_syndication_tags');
107
- endif;
108
 
109
- if (isset($_REQUEST['comment_status']) and ($_REQUEST['comment_status'] == 'open')) :
110
- update_option('feedwordpress_syndicated_comment_status', 'open');
111
- else :
112
- update_option('feedwordpress_syndicated_comment_status', 'closed');
113
- endif;
114
 
115
- if (isset($_REQUEST['ping_status']) and ($_REQUEST['ping_status'] == 'open')) :
116
- update_option('feedwordpress_syndicated_ping_status', 'open');
117
- else :
118
- update_option('feedwordpress_syndicated_ping_status', 'closed');
119
- endif;
120
-
121
- if (isset($_REQUEST['hardcode_name']) and ($_REQUEST['hardcode_name'] == 'no')) :
122
- update_option('feedwordpress_hardcode_name', 'no');
123
- else :
124
- update_option('feedwordpress_hardcode_name', 'yes');
125
- endif;
126
-
127
- if (isset($_REQUEST['hardcode_description']) and ($_REQUEST['hardcode_description'] == 'no')) :
128
- update_option('feedwordpress_hardcode_description', 'no');
129
- else :
130
- update_option('feedwordpress_hardcode_description', 'yes');
131
- endif;
132
 
133
- if (isset($_REQUEST['hardcode_url']) and ($_REQUEST['hardcode_url'] == 'no')) :
134
- update_option('feedwordpress_hardcode_url', 'no');
135
- else :
136
- update_option('feedwordpress_hardcode_url', 'yes');
137
- endif;
138
  ?>
139
  <div class="updated">
140
  <p><?php _e('Options saved.')?></p>
141
  </div>
142
  <?php
143
- endif;
144
  endif;
145
 
146
  $cat_id = FeedWordPress::link_category_id();
147
- $munge_permalink = get_option('feedwordpress_munge_permalink');
148
- $use_aggregator_source_data = get_option('feedwordpress_use_aggregator_source_data');
149
- $formatting_filters = get_option('feedwordpress_formatting_filters');
150
  $update_logging = get_option('feedwordpress_update_logging');
 
151
 
152
  $update_time_limit = (int) get_option('feedwordpress_update_time_limit');
153
-
154
  $automatic_updates = get_option('feedwordpress_automatic_updates');
155
 
156
  $freshness_interval = get_option('feedwordpress_freshness');
@@ -162,28 +71,12 @@ function fwp_syndication_options_page () {
162
  $hardcode_name = get_option('feedwordpress_hardcode_name');
163
  $hardcode_description = get_option('feedwordpress_hardcode_description');
164
  $hardcode_url = get_option('feedwordpress_hardcode_url');
165
-
166
- $post_status = get_option("feedwordpress_syndicated_post_status"); // default="publish"
167
- $comment_status = get_option("feedwordpress_syndicated_comment_status"); // default="closed"
168
- $ping_status = get_option("feedwordpress_syndicated_ping_status"); // default="closed"
169
-
170
- $unfamiliar_author = array ('create' => '','default' => '','filter' => '');
171
- $ua = FeedWordPress::on_unfamiliar('author');
172
- if (is_string($ua) and array_key_exists($ua, $unfamiliar_author)) :
173
- $unfamiliar_author[$ua] = ' checked="checked"';
174
- endif;
175
-
176
- $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
177
- $null_emails = FeedWordPress::null_email_set();
178
-
179
- $unfamiliar_category = array ('create'=>'','default'=>'','filter'=>'', 'tag'=>'');
180
- $uc = FeedWordPress::on_unfamiliar('category');
181
- if (is_string($uc) and array_key_exists($uc, $unfamiliar_category)) :
182
- $unfamiliar_category[$uc] = ' checked="checked"';
183
- endif;
184
 
185
  if (isset($wp_db_version) and $wp_db_version >= 4772) :
186
- $results = get_categories('type=link');
 
 
 
187
 
188
  // Guarantee that the Contributors category will be in the drop-down chooser, even if it is empty.
189
  $found_link_category_id = false;
@@ -239,36 +132,40 @@ function fwp_syndication_options_page () {
239
  <h2>Syndication <?php print $options; ?></h2>
240
  <div id="poststuff">
241
  <form action="" method="post">
242
- <?php fwp_linkedit_single_submit(); ?>
 
 
 
243
  <div id="post-body">
244
  <?php fwp_option_box_opener('Syndicated Feeds', 'syndicatedfeedsdiv'); ?>
245
  <table class="editform" width="100%" cellspacing="2" cellpadding="5">
246
  <tr>
247
  <th width="33%" scope="row">Syndicated Link category:</th>
248
  <td width="67%"><?php
249
- echo "\n<select name=\"syndication_category\" size=\"1\">";
250
- foreach ($results as $row) {
251
- if (!isset($row->cat_id)) { $row->cat_id = $row->cat_ID; }
252
-
253
- echo "\n\t<option value=\"$row->cat_id\"";
254
- if ($row->cat_id == $cat_id)
255
- echo " selected='selected'";
256
- echo ">$row->cat_id: ".wp_specialchars($row->cat_name);
257
- if ('Y' == $row->auto_toggle)
258
- echo ' (auto toggle)';
259
- echo "</option>\n";
260
- }
261
- echo "\n</select>\n";
 
 
262
  ?></td>
263
  </tr>
264
 
265
  <tr style="vertical-align: top">
266
- <th width="33%" scope="row">Check for feeds ready to be polled for updates:</th>
267
- <td width="67%"><select name="automatic_updates" size="1" onchange="if (this.value=='yes') { disp = 'inline'; } else { disp = 'none'; }; el=document.getElementById('automatic-update-interval-span'); if (el) el.style.display=disp;">
268
  <option value="yes"<?php echo ($automatic_updates)?' selected="selected"':''; ?>>automatically</option>
269
  <option value="no"<?php echo (!$automatic_updates)?' selected="selected"':''; ?>>only when I request</option>
270
  </select>
271
- <span id="automatic-update-interval-span" style="display: <?php echo $automatic_updates?'inline':'none';?>"><label for="automatic-update-interval">every</label> <input id="automatic-update-interval" name="freshness_interval" value="<?php echo $freshness_interval; ?>" size="4" /> minutes.</span>
272
  </td>
273
  </tr>
274
 
@@ -296,145 +193,9 @@ function fwp_syndication_options_page () {
296
  <?php fwp_option_box_closer(); ?>
297
 
298
  <?php
299
- fwp_option_box_opener(__('Syndicated Posts'), 'syndicatedpostsdiv');
300
- ?>
301
- <table class="editform" width="75%" cellspacing="2" cellpadding="5">
302
- <tr style="vertical-align: top"><th width="44%" scope="row">Publication:</th>
303
- <td width="56%"><ul style="margin: 0; padding: 0; list-style:none">
304
- <li><label><input type="radio" name="post_status" value="publish"<?php echo (!$post_status or $post_status=='publish')?' checked="checked"':''; ?> /> Publish syndicated posts immediately</label></li>
305
- <?php if (SyndicatedPost::use_api('post_status_pending')) : ?>
306
- <li><label><input type="radio" name="post_status" value="pending"<?php echo ($post_status=='pending')?' checked="checked"':''; ?> /> Hold syndicated posts for review; mark as Pending</label></li>
307
- <?php endif; ?>
308
- <li><label><input type="radio" name="post_status" value="draft"<?php echo ($post_status=='draft')?' checked="checked"':''; ?> /> Save syndicated posts as drafts</label></li>
309
- <li><label><input type="radio" name="post_status" value="private"<?php echo ($post_status=='private')?' checked="checked"':''; ?> /> Save syndicated posts as private posts</label></li>
310
- </ul></td></tr>
311
-
312
- <tr style="vertical-align: top"><th width="44%" scope="row">Permalinks point to:</th>
313
- <td width="56%"><select name="munge_permalink" size="1">
314
- <option value="yes"<?php echo ($munge_permalink=='yes')?' selected="selected"':''; ?>>original website</option>
315
- <option value="no"<?php echo ($munge_permalink=='no')?' selected="selected"':''; ?>>this website</option>
316
- </select></td></tr>
317
-
318
- <tr style="vertical-align: top"><th width="44%" scope="row">Posts from aggregator feeds:</th>
319
- <td width="56%"><ul style="margin: 0; padding: 0; list-style: none;">
320
- <li><label><input type="radio" name="use_aggregator_source_data" value="no"<?php echo ($use_aggregator_source_data!="yes")?' checked="checked"':''; ?>> Give the aggregator itself as the source of posts from an aggregator feed.</label></li>
321
- <li><label><input type="radio" name="use_aggregator_source_data" value="yes"<?php echo ($use_aggregator_source_data=="yes")?' checked="checked"':''; ?>> Give the original source of the post as the source, not the aggregator.</label></li>
322
- </ul>
323
- <p>Some feeds (for example, those produced by FeedWordPress) aggregate content from several different sources, and include information about the original source of the post.
324
- This setting controls what FeedWordPress will give as the source of posts from
325
- such an aggregator feed.</p>
326
- </td></tr>
327
-
328
- <tr style="vertical-align:top"><th width="44%" scope="row">Formatting filters:</th>
329
- <td width="56%">
330
- <select name="formatting_filters" size="1">
331
- <option value="no"<?php echo ($formatting_filters!='yes')?' selected="selected"':''; ?>>Protect syndicated posts from formatting filters</option>
332
- <option value="yes"<?php echo ($formatting_filters=='yes')?' selected="selected"':''; ?>>Expose syndicated posts to formatting filters</option>
333
- </select>
334
- <p>If you have trouble getting plugins to work that are supposed to insert
335
- elements after posts (like relevant links or a social networking
336
- <q>Share This</q> button), try changing this option to see if it fixes your
337
- problem.</p>
338
- </td></tr>
339
- </table>
340
- <?php
341
- fwp_option_box_closer();
342
- fwp_linkedit_periodic_submit();
343
-
344
- fwp_option_box_opener(__('Categories for syndicated posts'), 'categorydiv', 'postbox');
345
- fwp_category_box($dogs, '<em>all syndicated posts</em>');
346
- ?>
347
- <table class="editform" width="75%" cellspacing="2" cellpadding="5">
348
- <tr style="vertical-align: top"><th width="27%" scope="row" style="vertical-align:top">Unfamiliar categories:</th>
349
- <td><p>When one of the categories on a syndicated post is a category that FeedWordPress has not encountered before ...</p>
350
- <ul style="margin: 0; padding:0; list-style:none">
351
- <li><label><input type="radio" name="unfamiliar_category" value="create"<?php echo $unfamiliar_category['create']; ?>/> create a new category</label></li>
352
- <?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?>
353
- <li><label><input type="radio" name="unfamiliar_category" value="tag"<?php echo $unfamiliar_category['tag']; ?>/> create a new tag</label></li>
354
- <?php endif; ?>
355
- <li><label><input type="radio" name="unfamiliar_category" value="default"<?php echo $unfamiliar_category['default']; ?>/> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?> or tags<?php endif; ?></li>
356
- <li><label><input type="radio" name="unfamiliar_category" value="filter"<?php echo $unfamiliar_category['filter']; ?>/> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?> or tags<?php endif; ?> and don't syndicate posts unless they match at least one familiar category</label></li>
357
- </ul></td></tr>
358
- </table>
359
- <?php
360
- fwp_option_box_closer();
361
- fwp_linkedit_periodic_submit();
362
-
363
- if (isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25) :
364
- fwp_tags_box($tags);
365
- fwp_linkedit_periodic_submit();
366
- endif;
367
-
368
- fwp_option_box_opener(__('Comments & Pings'), 'commentstatus', 'postbox');
369
- ?>
370
- <table class="editform" width="75%" cellspacing="2" cellpadding="5">
371
- <tr style="vertical-align: top"><th width="44%" scope="row"><?php print __('Comments') ?>:</th>
372
- <td width="56%"><ul style="margin: 0; padding: 0; list-style:none">
373
- <li><label><input type="radio" name="comment_status" value="open"<?php echo ($comment_status=='open')?' checked="checked"':''; ?> /> Allow comments on syndicated posts</label></li>
374
- <li><label><input type="radio" name="comment_status" value="closed"<?php echo ($comment_status!='open')?' checked="checked"':''; ?> /> Don't allow comments on syndicated posts</label></li>
375
- </ul></td></tr>
376
-
377
- <tr style="vertical-align: top"><th width="44%" scope="row"><?php print __('Pings') ?>:</th>
378
- <td width="56%"><ul style="margin:0; padding: 0; list-style:none">
379
- <li><label><input type="radio" name="ping_status" value="open"<?php echo ($ping_status=='open')?' checked="checked"':''; ?> /> Accept pings on syndicated posts</label></li>
380
- <li><label><input type="radio" name="ping_status" value="closed"<?php echo ($ping_status!='open')?' checked="checked"':''; ?> /> Don't accept pings on syndicated posts</label></li>
381
- </ul></td></tr>
382
- </table>
383
- <?php
384
- fwp_option_box_closer();
385
- fwp_linkedit_periodic_submit();
386
-
387
- fwp_option_box_opener('Syndicated Authors', 'authordiv', 'postbox');
388
-
389
- $unfamiliar_author = FeedWordPress::on_unfamiliar('author');
390
- $authorlist = fwp_author_list();
391
- ?>
392
- <table>
393
- <tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">For posts by authors that haven't been syndicated before:</th></tr>
394
- <tr style="vertical-align: top">
395
- <th style="text-align: left">Posts by new authors</th>
396
- <td>
397
- <select style="max-width: 16.0em;" id="unfamiliar-author" name="unfamiliar_author" onchange="contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser');">
398
- <option value="create"<?php if ('create'==$unfamiliar_author) : ?>selected="selected"<?php endif; ?>>create a new author account</option>
399
- <?php foreach ($authorlist as $author_id => $author_name) : ?>
400
- <option value="<?php echo $author_id; ?>"<?php if ($author_id==$unfamiliar_author) : ?>selected="selected"<?php endif; ?>>are assigned to <?php echo $author_name; ?></option>
401
- <?php endforeach; ?>
402
- <option value="newuser">will be assigned to a user named...</option>
403
- <option value="filter"<?php if ('filter'==$unfamiliar_author) : ?>selected="selected"<?php endif; ?>>get filtered out</option>
404
- </select>
405
- </td>
406
- <td>
407
- <div id="unfamiliar-author-newuser"><input type="text" name="unfamiliar_author_newuser" value="" /></div>
408
- </td>
409
- </tr>
410
- <tr><td></td>
411
- <td colspan="2">
412
- <p>This is a default setting. You can override it for one or more particular feeds using the Edit link in <a href="admin.php?page=<?php print $GLOBALS['fwp_path']; ?>/syndication.php">Syndicated Sites</a></p>
413
- </td>
414
- </table>
415
-
416
- <script type="text/javascript">
417
- contextual_appearance('unfamiliar-author', 'unfamiliar-author-newuser', 'unfamiliar-author-default', 'newuser');
418
- </script>
419
-
420
- <h4>Matching Authors</h4>
421
- <ul style="list-style: none; margin: 0; padding: 0;">
422
- <li><div><label><input id="match-author-by-email" type="checkbox" name="match_author_by_email" value="yes" <?php if ($match_author_by_email) : ?>checked="checked" <?php endif; ?>onchange="contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', /*checkbox=*/ true);" /> Treat syndicated authors with the same e-mail address as the same author.</label></div>
423
- <div id="unless-null-email">
424
- <p>Unless the e-mail address is one of the following anonymous e-mail addresses:</p>
425
- <textarea name="null_emails" rows="3" style="width: 100%">
426
- <?php print implode("\n", $null_emails); ?>
427
- </textarea>
428
- </div></li>
429
- </ul>
430
-
431
- <script type="text/javascript">
432
- contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes', /*checkbox=*/ true);
433
- </script>
434
-
435
- <?php
436
- fwp_option_box_closer();
437
- fwp_linkedit_periodic_submit();
438
 
439
  fwp_option_box_opener('Back End', 'backenddiv', 'postbox');
440
  ?>
@@ -446,6 +207,18 @@ contextual_appearance('match-author-by-email', 'unless-null-email', null, 'yes',
446
  <option value="no"<?php echo (($update_logging!='yes')?' selected="selected"':''); ?>>don't write to PHP logs</option>
447
  </select></td>
448
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
449
  <tr style="vertical-align: top">
450
  <th width="33%" scope="row">Guid index:</th>
451
  <td width="67%"><input class="button" type="submit" name="create_index" value="Create index on guid column in posts database table" />
9
  return;
10
  endif;
11
 
12
+ // If this is a POST, validate source and user credentials
13
+ FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_options', /*capability=*/ 'manage_options');
14
+
15
  if (isset($_POST['create_index'])) :
16
+ FeedWordPress::create_guid_index();
 
 
 
 
17
  ?>
18
  <div class="updated">
19
  <p><?php _e('Index created on database table.')?></p>
20
  </div>
21
  <?php
 
22
  endif;
23
 
24
  if (isset($_POST['submit']) or isset($_POST['create_index'])) :
25
+ update_option('feedwordpress_cat_id', $_REQUEST['syndication_category']);
26
+ update_option('feedwordpress_update_logging', $_REQUEST['update_logging']);
27
+ update_option('feedwordpress_debug', $_POST['feedwordpress_debug']);
28
+ update_option('feedwordpress_automatic_updates', ($_POST['automatic_updates']=='yes'));
29
+ update_option('feedwordpress_update_time_limit', ($_POST['update_time_limit']=='yes')?(int) $_POST['time_limit_seconds']:0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
+ $freshness_interval = (isset($_POST['freshness_interval']) ? (int) $_POST['freshness_interval'] : 10);
32
+ update_option('feedworidpress_freshness', $freshness_interval*60);
 
 
 
33
 
34
+ if (isset($_REQUEST['hardcode_name']) and ($_REQUEST['hardcode_name'] == 'no')) :
35
+ update_option('feedwordpress_hardcode_name', 'no');
36
+ else :
37
+ update_option('feedwordpress_hardcode_name', 'yes');
38
+ endif;
39
+
40
+ if (isset($_REQUEST['hardcode_description']) and ($_REQUEST['hardcode_description'] == 'no')) :
41
+ update_option('feedwordpress_hardcode_description', 'no');
42
+ else :
43
+ update_option('feedwordpress_hardcode_description', 'yes');
44
+ endif;
 
 
 
 
 
 
45
 
46
+ if (isset($_REQUEST['hardcode_url']) and ($_REQUEST['hardcode_url'] == 'no')) :
47
+ update_option('feedwordpress_hardcode_url', 'no');
48
+ else :
49
+ update_option('feedwordpress_hardcode_url', 'yes');
50
+ endif;
51
  ?>
52
  <div class="updated">
53
  <p><?php _e('Options saved.')?></p>
54
  </div>
55
  <?php
 
56
  endif;
57
 
58
  $cat_id = FeedWordPress::link_category_id();
 
 
 
59
  $update_logging = get_option('feedwordpress_update_logging');
60
+ $feedwordpress_debug = (get_option('feedwordpress_debug')=='yes');
61
 
62
  $update_time_limit = (int) get_option('feedwordpress_update_time_limit');
 
63
  $automatic_updates = get_option('feedwordpress_automatic_updates');
64
 
65
  $freshness_interval = get_option('feedwordpress_freshness');
71
  $hardcode_name = get_option('feedwordpress_hardcode_name');
72
  $hardcode_description = get_option('feedwordpress_hardcode_description');
73
  $hardcode_url = get_option('feedwordpress_hardcode_url');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  if (isset($wp_db_version) and $wp_db_version >= 4772) :
76
+ $results = get_categories(array(
77
+ "type" => 'link',
78
+ "hide_empty" => false,
79
+ ));
80
 
81
  // Guarantee that the Contributors category will be in the drop-down chooser, even if it is empty.
82
  $found_link_category_id = false;
132
  <h2>Syndication <?php print $options; ?></h2>
133
  <div id="poststuff">
134
  <form action="" method="post">
135
+ <?php
136
+ FeedWordPressCompatibility::stamp_nonce('feedwordpress_options');
137
+ fwp_linkedit_single_submit();
138
+ ?>
139
  <div id="post-body">
140
  <?php fwp_option_box_opener('Syndicated Feeds', 'syndicatedfeedsdiv'); ?>
141
  <table class="editform" width="100%" cellspacing="2" cellpadding="5">
142
  <tr>
143
  <th width="33%" scope="row">Syndicated Link category:</th>
144
  <td width="67%"><?php
145
+ echo "\n<select name=\"syndication_category\" size=\"1\">";
146
+ foreach ($results as $row) :
147
+ if (!isset($row->cat_id)) : $row->cat_id = $row->cat_ID; endif;
148
+
149
+ echo "\n\t<option value=\"$row->cat_id\"";
150
+ if ($row->cat_id == $cat_id) :
151
+ echo " selected='selected'";
152
+ endif;
153
+ echo ">$row->cat_id: ".wp_specialchars($row->cat_name);
154
+ if ('Y' == $row->auto_toggle) :
155
+ echo ' (auto toggle)';
156
+ endif;
157
+ echo "</option>\n";
158
+ endforeach;
159
+ echo "\n</select>\n";
160
  ?></td>
161
  </tr>
162
 
163
  <tr style="vertical-align: top">
164
+ <th width="33%" scope="row">Check for updates:</th>
165
+ <td width="67%"><select name="automatic_updates" size="1">
166
  <option value="yes"<?php echo ($automatic_updates)?' selected="selected"':''; ?>>automatically</option>
167
  <option value="no"<?php echo (!$automatic_updates)?' selected="selected"':''; ?>>only when I request</option>
168
  </select>
 
169
  </td>
170
  </tr>
171
 
193
  <?php fwp_option_box_closer(); ?>
194
 
195
  <?php
196
+ FeedWordPressSettingsUI::instead_of_posts_box();
197
+ FeedWordPressSettingsUI::instead_of_authors_box();
198
+ FeedWordPressSettingsUI::instead_of_categories_box();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
 
200
  fwp_option_box_opener('Back End', 'backenddiv', 'postbox');
201
  ?>
207
  <option value="no"<?php echo (($update_logging!='yes')?' selected="selected"':''); ?>>don't write to PHP logs</option>
208
  </select></td>
209
  </tr>
210
+ <tr style="vertical-align: top">
211
+ <th width="33%" scope="row">Debugging mode:</th>
212
+ <td width="67%"><select name="feedwordpress_debug" size="1">
213
+ <option value="yes"<?php echo ($feedwordpress_debug ? ' selected="selected"' : ''); ?>>on</option>
214
+ <option value="no"<?php echo ($feedwordpress_debug ? '' : ' selected="selected"'); ?>>off</option>
215
+ </select>
216
+ <p>When debugging mode is <strong>ON</strong>, FeedWordPress displays many diagnostic error messages,
217
+ warnings, and notices that are ordinarily suppressed, and turns off all caching of feeds. Use with
218
+ caution: this setting is absolutely inappropriate for a production server.</p>
219
+ </td>
220
+ </tr>
221
+
222
  <tr style="vertical-align: top">
223
  <th width="33%" scope="row">Guid index:</th>
224
  <td width="67%"><input class="button" type="submit" name="create_index" value="Create index on guid column in posts database table" />
syndication.php CHANGED
@@ -1,5 +1,6 @@
1
  <?php
2
  require_once(dirname(__FILE__) . '/admin-ui.php');
 
3
 
4
  ################################################################################
5
  ## ADMIN MENU ADD-ONS: implement Dashboard management pages ####################
@@ -167,9 +168,10 @@ if ($cont):
167
  <?php if (fwp_test_wp_version(0, FWP_SCHEMA_25)) : ?>
168
  <div class="wrap">
169
  <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
 
170
  <h2>Add a new syndicated site:</h2>
171
  <div>
172
- <label for="add-uri">Website or newsfeed:</label>
173
  <input type="text" name="lookup" id="add-uri" value="URI" size="64" />
174
  <input type="hidden" name="action" value="feedfinder" />
175
  </div>
@@ -190,6 +192,7 @@ function fwp_syndication_manage_page_update_box ($object = NULL, $box = NULL) {
190
  $updateFeedsNow = __('Update feeds now');
191
  ?>
192
  <form action="" method="POST">
 
193
  <?php if (fwp_test_wp_version(FWP_SCHEMA_25, FWP_SCHEMA_27)) : ?>
194
  <div id="rightnow">
195
  <h3 class="reallynow"><span><?php print $updateFeedsNow; ?></span>
@@ -240,6 +243,8 @@ function fwp_syndication_manage_page_links_box ($object = NULL, $box = NULL) {
240
  <?php endif; ?>
241
 
242
  <form id="syndicated-links" action="admin.php?page=<?php print $GLOBALS['fwp_path']; ?>/<?php echo basename(__FILE__); ?>" method="post">
 
 
243
  <?php $alt_row = true; ?>
244
 
245
  <?php if (fwp_test_wp_version(FWP_SCHEMA_25)) : ?>
@@ -307,10 +312,15 @@ jQuery(document).ready( function () {
307
  ?>
308
  <td>
309
  <strong><a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>&amp;link_id=<?php echo $link->link_id; ?>&amp;action=linkedit"><?php echo wp_specialchars($link->link_name, 'both'); ?></a></strong>
310
- <div class="row-actions"><a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>&amp;link_id=<?php echo $link->link_id; ?>&amp;action=linkedit"><?php _e('Edit'); ?></a>
311
- | <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>&amp;link_id=<?php echo $link->link_id; ?>&amp;action=feedfinder"><?php echo $caption; ?></a>
 
 
 
 
 
312
  | <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>&amp;link_id=<?php echo $link->link_id; ?>&amp;action=Unsubscribe"><?php _e('Unsubscribe'); ?></a>
313
- | <a href="<?php echo wp_specialchars($link->link_url, 'both'); ?>"><?php _e('View')?></a>
314
  </div>
315
  </td>
316
  <?php
@@ -424,6 +434,7 @@ function fwp_feedfinder_page () {
424
  endif;
425
  ?>
426
  <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
 
427
  <fieldset style="clear: both">
428
  <legend><?php echo $rss->feed_type; ?> <?php echo $rss->feed_version; ?> feed</legend>
429
 
@@ -439,14 +450,18 @@ function fwp_feedfinder_page () {
439
  <div>
440
  <div style="float:right; background-color:#D0D0D0; color: black; width:45%; font-size:70%; border-left: 1px dotted #A0A0A0; padding-left: 0.5em; margin-left: 1.0em">
441
  <?php if (count($rss->items) > 0): ?>
442
- <?php $item = $rss->items[0]; ?>
 
 
 
 
443
  <h3>Sample Item</h3>
444
  <ul>
445
- <li><strong>Title:</strong> <a href="<?php echo $item['link']; ?>"><?php echo $item['title']; ?></a></li>
446
- <li><strong>Date:</strong> <?php echo isset($item['date_timestamp']) ? date('d-M-y g:i:s a', $item['date_timestamp']) : 'unknown'; ?></li>
447
  </ul>
448
  <div class="entry">
449
- <?php echo (isset($item['content']['encoded'])?$item['content']['encoded']:$item['description']); ?>
450
  </div>
451
  <?php else: ?>
452
  <h3>No Items</h3>
@@ -481,6 +496,9 @@ function fwp_feedfinder_page () {
481
  </div>
482
 
483
  <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
 
 
 
484
  <div class="wrap">
485
  <h2>Use another feed</h2>
486
  <div><label>Feed:</label>
@@ -497,19 +515,20 @@ function fwp_feedfinder_page () {
497
  function fwp_switchfeed_page () {
498
  global $wpdb, $wp_db_version;
499
 
500
- check_admin_referer();
 
 
501
  if (!isset($_REQUEST['Cancel'])):
502
- if (!current_user_can('manage_links')):
503
- die (__("Cheatin' uh ?"));
504
- elseif (isset($_REQUEST['link_id']) and ($_REQUEST['link_id']==0)):
505
  $link_id = FeedWordPress::syndicate_link($_REQUEST['feed_title'], $_REQUEST['feed_link'], $_REQUEST['feed']);
506
  if ($link_id): ?>
507
- <div class="updated"><p><a href="<?php echo $_REQUEST['feed_link']; ?>"><?php echo wp_specialchars($_REQUEST['feed_title'], 'both'); ?></a>
508
- has been added as a contributing site, using the newsfeed at &lt;<a href="<?php echo $_REQUEST['feed']; ?>"><?php echo wp_specialchars($_REQUEST['feed'], 'both'); ?></a>&gt;.</p></div>
 
509
  <?php else: ?>
510
- <div class="updated"><p>There was a problem adding the newsfeed. [SQL: <?php echo wp_specialchars(mysql_error(), 'both'); ?>]</p></div>
511
  <?php endif;
512
- elseif (isset($_REQUEST['link_id'])):
513
  // Update link_rss
514
  $result = $wpdb->query("
515
  UPDATE $wpdb->links
@@ -537,7 +556,8 @@ updated to &lt;<a href="<?php echo $_REQUEST['feed']; ?>"><?php echo wp_specialc
537
  function fwp_linkedit_page () {
538
  global $wpdb, $wp_db_version;
539
 
540
- check_admin_referer(); // Make sure we arrived here from the Dashboard
 
541
 
542
  $special_settings = array ( /* Regular expression syntax is OK here */
543
  'cats',
@@ -559,9 +579,7 @@ function fwp_linkedit_page () {
559
  'link/.*',
560
  );
561
 
562
- if (!current_user_can('manage_links')) :
563
- die (__("Cheatin' uh ?"));
564
- elseif (isset($_REQUEST['feedfinder'])) :
565
  return fwp_feedfinder_page(); // re-route to Feed Finder page
566
  else :
567
  $link_id = (int) $_REQUEST['link_id'];
@@ -617,151 +635,6 @@ function fwp_linkedit_page () {
617
  $link->settings['update/hold'] = $GLOBALS['fwp_post']['update_schedule'];
618
  endif;
619
 
620
- // Categories
621
- if (isset($GLOBALS['fwp_post']['post_category'])) :
622
- $link->settings['cats'] = array();
623
- foreach ($GLOBALS['fwp_post']['post_category'] as $cat_id) :
624
- $link->settings['cats'][] = '{#'.$cat_id.'}';
625
- endforeach;
626
- else :
627
- unset($link->settings['cats']);
628
- endif;
629
-
630
- // Tags
631
- if (isset($GLOBALS['fwp_post']['tags_input'])) :
632
- $link->settings['tags'] = array();
633
- foreach (explode(',', $GLOBALS['fwp_post']['tags_input']) as $tag) :
634
- $link->settings['tags'][] = trim($tag);
635
- endforeach;
636
- endif;
637
-
638
- // Post status, comment status, ping status
639
- foreach (array('post', 'comment', 'ping') as $what) :
640
- $sfield = "feed_{$what}_status";
641
- if (isset($GLOBALS['fwp_post'][$sfield])) :
642
- if ($GLOBALS['fwp_post'][$sfield]=='site-default') :
643
- unset($link->settings["{$what} status"]);
644
- else :
645
- $link->settings["{$what} status"] = $GLOBALS['fwp_post'][$sfield];
646
- endif;
647
- endif;
648
- endforeach;
649
-
650
- // Unfamiliar author, unfamiliar categories
651
- foreach (array("author", "category") as $what) :
652
- $sfield = "unfamiliar_{$what}";
653
- if (isset($GLOBALS['fwp_post'][$sfield])) :
654
- if ('site-default'==$GLOBALS['fwp_post'][$sfield]) :
655
- unset($link->settings["unfamiliar {$what}"]);
656
- elseif ('newuser'==$GLOBALS['fwp_post'][$sfield]) :
657
- $newuser_name = trim($GLOBALS['fwp_post']["{$sfield}_newuser"]);
658
- if (strlen($newuser_name) > 0) :
659
- $userdata = array();
660
- $userdata['ID'] = NULL;
661
-
662
- $userdata['user_login'] = sanitize_user($newuser_name);
663
- $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
664
-
665
- $userdata['user_nicename'] = sanitize_title($newuser_name);
666
- $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
667
-
668
- $userdata['display_name'] = $wpdb->escape($newuser_name);
669
-
670
- $newuser_id = wp_insert_user($userdata);
671
- if (is_numeric($newuser_id)) :
672
- $link->settings["unfamiliar {$what}"] = $newuser_id;
673
- else :
674
- // TODO: Add some error detection and reporting
675
- endif;
676
- else :
677
- // TODO: Add some error reporting
678
- endif;
679
- else :
680
- $link->settings["unfamiliar {$what}"] = $GLOBALS['fwp_post'][$sfield];
681
- endif;
682
- endif;
683
- endforeach;
684
-
685
- // Handle author mapping rules
686
- if (isset($GLOBALS['fwp_post']['author_rules_name']) and isset($GLOBALS['fwp_post']['author_rules_action'])) :
687
- unset($link->settings['map authors']);
688
- foreach ($GLOBALS['fwp_post']['author_rules_name'] as $key => $name) :
689
- // Normalize for case and whitespace
690
- $name = strtolower(trim($name));
691
- $author_action = strtolower(trim($GLOBALS['fwp_post']['author_rules_action'][$key]));
692
-
693
- if (strlen($name) > 0) :
694
- if ('newuser' == $author_action) :
695
- $newuser_name = trim($GLOBALS['fwp_post']['author_rules_newuser'][$key]);
696
- if (strlen($newuser_name) > 0) :
697
- $userdata = array();
698
- $userdata['ID'] = NULL;
699
-
700
- $userdata['user_login'] = sanitize_user($newuser_name);
701
- $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
702
-
703
- $userdata['user_nicename'] = sanitize_title($newuser_name);
704
- $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
705
-
706
- $userdata['display_name'] = $wpdb->escape($newuser_name);
707
-
708
- $newuser_id = wp_insert_user($userdata);
709
- if (is_numeric($newuser_id)) :
710
- $link->settings['map authors']['name'][$name] = $newuser_id;
711
- else :
712
- // TODO: Add some error detection and reporting
713
- endif;
714
- else :
715
- // TODO: Add some error reporting
716
- endif;
717
- else :
718
- $link->settings['map authors']['name'][$name] = $author_action;
719
- endif;
720
- endif;
721
- endforeach;
722
- endif;
723
-
724
- if (isset($GLOBALS['fwp_post']['add_author_rule_name']) and isset($GLOBALS['fwp_post']['add_author_rule_action'])) :
725
- $name = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_name']));
726
- $author_action = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_action']));
727
- if (strlen($name) > 0) :
728
- if ('newuser' == $author_action) :
729
- $newuser_name = trim($GLOBALS['fwp_post']['add_author_rule_newuser']);
730
- if (strlen($newuser_name) > 0) :
731
- $userdata = array();
732
- $userdata['ID'] = NULL;
733
-
734
- $userdata['user_login'] = sanitize_user($newuser_name);
735
- $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
736
-
737
- $userdata['user_nicename'] = sanitize_title($newuser_name);
738
- $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
739
-
740
- $userdata['display_name'] = $wpdb->escape($newuser_name);
741
-
742
- $newuser_id = wp_insert_user($userdata);
743
- if (is_numeric($newuser_id)) :
744
- $link->settings['map authors']['name'][$name] = $newuser_id;
745
- else :
746
- // TODO: Add some error detection and reporting
747
- endif;
748
- else :
749
- // TODO: Add some error reporting
750
- endif;
751
- else :
752
- $link->settings['map authors']['name'][$name] = $author_action;
753
- endif;
754
- endif;
755
- endif;
756
-
757
- if (isset($GLOBALS['fwp_post']['cat_split'])) :
758
- if (strlen(trim($GLOBALS['fwp_post']['cat_split'])) > 0) :
759
- $link->settings['cat_split'] = trim($GLOBALS['fwp_post']['cat_split']);
760
- else :
761
- unset($link->settings['cat_split']);
762
- endif;
763
- endif;
764
-
765
  $alter[] = "link_notes = '".$wpdb->escape($link->settings_to_notes())."'";
766
 
767
  $alter_set = implode(", ", $alter);
@@ -788,45 +661,6 @@ function fwp_linkedit_page () {
788
  $link_name = wp_specialchars($db_link->link_name, 1);
789
  $link_description = wp_specialchars($db_link->link_description, 'both');
790
  $link_rss_uri = wp_specialchars($db_link->link_rss, 'both');
791
-
792
- $post_status_global = get_option('feedwordpress_syndicated_post_status');
793
- $comment_status_global = get_option('feedwordpress_syndicated_comment_status');
794
- $ping_status_global = get_option('feedwordpress_syndicated_ping_status');
795
-
796
- $status['post'] = array('publish' => '', 'private' => '', 'draft' => '', 'site-default' => '');
797
- if (SyndicatedPost::use_api('post_status_pending')) :
798
- $status['post']['pending'] = '';
799
- endif;
800
-
801
- $status['comment'] = array('open' => '', 'closed' => '', 'site-default' => '');
802
- $status['ping'] = array('open' => '', 'closed' => '', 'site-default' => '');
803
-
804
- foreach (array('post', 'comment', 'ping') as $what) :
805
- if (isset($link->settings["{$what} status"])) :
806
- $status[$what][$link->settings["{$what} status"]] = ' checked="checked"';
807
- else :
808
- $status[$what]['site-default'] = ' checked="checked"';
809
- endif;
810
- endforeach;
811
-
812
- $unfamiliar['author'] = array ('create' => '','default' => '','filter' => '');
813
- $unfamiliar['category'] = array ('create'=>'','tag' => '','default'=>'','filter'=>'');
814
-
815
- foreach (array('author', 'category') as $what) :
816
- if (is_string($link->settings["unfamiliar {$what}"]) and
817
- array_key_exists($link->settings["unfamiliar {$what}"], $unfamiliar[$what])) :
818
- $key = $link->settings["unfamiliar {$what}"];
819
- else:
820
- $key = 'site-default';
821
- endif;
822
- $unfamiliar[$what][$key] = ' checked="checked"';
823
- endforeach;
824
-
825
- if (is_array($link->settings['cats'])) : $cats = $link->settings['cats'];
826
- else : $cats = array();
827
- endif;
828
-
829
- $dogs = SyndicatedPost::category_ids($cats, /*unfamiliar=*/ NULL);
830
  else :
831
  die( __('Link not found.') );
832
  endif;
@@ -841,23 +675,6 @@ function fwp_linkedit_page () {
841
  if (o.value=='yes') { ed.style.display='inline'; view.style.display='none'; }
842
  else { ed.style.display='none'; view.style.display='inline'; }
843
  }
844
- function flip_newuser (item) {
845
- rollup=document.getElementById(item);
846
- newuser=document.getElementById(item+'-newuser');
847
- sitewide=document.getElementById(item+'-default');
848
- if (rollup) {
849
- if ('newuser'==rollup.value) {
850
- if (newuser) newuser.style.display='block';
851
- if (sitewide) sitewide.style.display='none';
852
- } else if ('site-default'==rollup.value) {
853
- if (newuser) newuser.style.display='none';
854
- if (sitewide) sitewide.style.display='block';
855
- } else {
856
- if (newuser) newuser.style.display='none';
857
- if (sitewide) sitewide.style.display='none';
858
- }
859
- }
860
- }
861
  </script>
862
 
863
  <?php if ($updated_link) : ?>
@@ -866,11 +683,17 @@ function fwp_linkedit_page () {
866
 
867
  <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
868
  <div class="wrap">
 
869
  <input type="hidden" name="link_id" value="<?php echo $link_id; ?>" />
870
  <input type="hidden" name="action" value="linkedit" />
871
  <input type="hidden" name="save" value="link" />
872
 
873
- <h2>Edit a syndicated feed:</h2>
 
 
 
 
 
874
  <div id="poststuff">
875
  <?php fwp_linkedit_single_submit($status); ?>
876
 
@@ -969,176 +792,17 @@ flip_hardcode('url');
969
  <?php fwp_linkedit_periodic_submit(); ?>
970
 
971
  <?php
972
- if (!(isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25)) :
973
- fwp_option_box_opener('Syndicated Posts', 'syndicatedpostsdiv', 'postbox');
974
- ?>
975
- <table class="editform" width="75%" cellspacing="2" cellpadding="5">
976
- <tr><th width="27%" scope="row" style="vertical-align:top">Publication:</th>
977
- <td width="73%" style="vertical-align:top"><ul style="margin:0; list-style:none">
978
- <li><label><input type="radio" name="feed_post_status" value="site-default"
979
- <?php echo $status['post']['site-default']; ?> /> Use site-wide setting from <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/syndication-options.php">Syndication Options</a>
980
- (currently: <strong><?php echo ($post_status_global ? $post_status_global : 'publish'); ?></strong>)</label></li>
981
- <li><label><input type="radio" name="feed_post_status" value="publish"
982
- <?php echo $status['post']['publish']; ?> /> Publish posts from this feed immediately</label></li>
983
-
984
- <?php if (SyndicatedPost::use_api('post_status_pending')) : ?>
985
- <li><label><input type="radio" name="feed_post_status" value="pending"
986
- <?php echo $status['post']['pending']; ?>/> Hold posts from this feed for review; mark as Pending</label></li>
987
- <?php endif; ?>
988
-
989
- <li><label><input type="radio" name="feed_post_status" value="draft"
990
- <?php echo $status['post']['draft']; ?> /> Save posts from this feed as drafts</label></li>
991
- <li><label><input type="radio" name="feed_post_status" value="private"
992
- <?php echo $status['post']['private']; ?> /> Save posts from this feed as private posts</label></li>
993
- </ul></td>
994
- </tr>
995
- </table>
996
- <?php
997
- fwp_option_box_closer();
998
- fwp_linkedit_periodic_submit();
999
- endif;
1000
-
1001
- fwp_option_box_opener(__('Categories'), 'categorydiv', 'postbox');
1002
- fwp_category_box($dogs, 'all syndicated posts from this feed');
1003
- ?>
1004
- <table>
1005
- <tr>
1006
- <th width="20%" scope="row" style="vertical-align:top">Unfamiliar categories:</th>
1007
- <td width="80%"><p>When one of the categories on a syndicated post is a category that FeedWordPress has not encountered before ...</p>
1008
-
1009
- <ul style="margin: 0; list-style:none">
1010
- <li><label><input type="radio" name="unfamiliar_category" value="site-default"<?php echo $unfamiliar['category']['site-default']; ?> /> use the site-wide setting from <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/syndication-options.php">Syndication Options</a>
1011
- (currently <strong><?php echo FeedWordPress::on_unfamiliar('category'); ?></strong>)</label></li>
1012
- <li><label><input type="radio" name="unfamiliar_category" value="create"<?php echo $unfamiliar['category']['create']; ?> /> create a new category</label></li>
1013
- <?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?>
1014
- <li><label><input type="radio" name="unfamiliar_category" value="tag"<?php echo $unfamiliar['category']['tag']; ?>/> create a new tag</label></li>
1015
- <?php endif; ?>
1016
- <li><label><input type="radio" name="unfamiliar_category" value="default"<?php echo $unfamiliar['category']['default']; ?> /> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?> or tags<?php endif; ?></label></li>
1017
- <li><label><input type="radio" name="unfamiliar_category" value="filter"<?php echo $unfamiliar['category']['filter']; ?> /> don't create new categories<?php if (fwp_test_wp_version(FWP_SCHEMA_23)) : ?> or tags<?php endif; ?> and don't syndicate posts unless they match at least one familiar category</label></li>
1018
- </ul></td>
1019
- </tr>
1020
-
1021
- <tr>
1022
- <th width="20%" scope="row" style="vertical-align:top">Multiple categories:</th>
1023
- <td width="80%">
1024
- <input type="text" size="20" id="cat_split" name="cat_split" value="<?php if (isset($link->settings['cat_split'])) : echo htmlspecialchars($link->settings['cat_split']); endif; ?>" /><br/>
1025
- Enter a <a href="http://us.php.net/manual/en/reference.pcre.pattern.syntax.php">Perl-compatible regular expression</a> here if the feed provides multiple
1026
- categories in a single category element. The regular expression should match
1027
- the characters used to separate one category from the next. If the feed uses
1028
- spaces (like <a href="http://del.icio.us/">del.icio.us</a>), use the pattern "\s".
1029
- If the feed does not provide multiple categories in a single element, leave this
1030
- blank.</td>
1031
- </tr>
1032
- </table>
1033
- <?php
1034
- fwp_option_box_closer();
1035
- fwp_linkedit_periodic_submit();
1036
-
1037
- if (isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25) :
1038
- fwp_tags_box($link->settings['tags']);
1039
- fwp_linkedit_periodic_submit();
1040
- endif; ?>
1041
-
1042
- <?php fwp_option_box_opener('Syndicated Authors', 'authordiv', 'postbox'); ?>
1043
- <?php $authorlist = fwp_author_list(); ?>
1044
- <table>
1045
- <tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">For posts by authors that haven't been syndicated before:</th></tr>
1046
- <tr>
1047
- <th style="text-align: left">Posts by new authors</th>
1048
- <td>
1049
- <select id="unfamiliar-author" name="unfamiliar_author" onchange="flip_newuser('unfamiliar-author');">
1050
- <option value="site-default"<?php if (!isset($link->settings['unfamiliar author'])) : ?>selected="selected"<?php endif; ?>>are handled using site-wide settings</option>
1051
- <option value="create"<?php if ('create'==$link->settings['unfamiliar author']) : ?>selected="selected"<?php endif; ?>>create a new author account</option>
1052
- <?php foreach ($authorlist as $author_id => $author_name) : ?>
1053
- <option value="<?php echo $author_id; ?>"<?php if ($author_id==$link->settings['unfamiliar author']) : ?>selected="selected"<?php endif; ?>>are assigned to <?php echo $author_name; ?></option>
1054
- <?php endforeach; ?>
1055
- <option value="newuser">will be assigned to a new user...</option>
1056
- <option value="filter"<?php if ('filter'==$link->settings['unfamiliar author']) : ?>selected="selected"<?php endif; ?>>get filtered out</option>
1057
- </select>
1058
- </td>
1059
- <td>
1060
- <div id="unfamiliar-author-default">Site-wide settings can be set in <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/syndication-options.php">Syndication Options</a></div>
1061
- <div id="unfamiliar-author-newuser">named <input type="text" name="unfamiliar_author_newuser" value="" /></div>
1062
- </td>
1063
- </tr>
1064
-
1065
- <tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">For posts by specific authors. Blank out a name to delete the rule.</th></tr>
1066
-
1067
- <?php if (isset($link->settings['map authors'])) : $i=0; foreach ($link->settings['map authors'] as $author_rules) : foreach ($author_rules as $author_name => $author_action) : $i++; ?>
1068
- <tr>
1069
- <th style="text-align: left">Posts by <input type="text" name="author_rules_name[]" value="<?php echo htmlspecialchars($author_name); ?>" /></th>
1070
- <td>
1071
- <select id="author-rules-<?php echo $i; ?>" name="author_rules_action[]" onchange="flip_newuser('author-rules-<?php echo $i; ?>');">
1072
- <?php foreach ($authorlist as $local_author_id => $local_author_name) : ?>
1073
- <option value="<?php echo $local_author_id; ?>"<?php if ($local_author_id==$author_action) : echo ' selected="selected"'; endif; ?>>are assigned to <?php echo $local_author_name; ?></option>
1074
- <?php endforeach; ?>
1075
- <option value="newuser">will be assigned to a new user...</option>
1076
- <option value="filter"<?php if ('filter'==$author_action) : echo ' selected="selected"'; endif; ?>>get filtered out</option>
1077
- </select>
1078
- </td>
1079
- <td><div id="author-rules-<?php echo $i; ?>-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></div></td>
1080
- </tr>
1081
- <?php endforeach; endforeach; endif; ?>
1082
-
1083
- <tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">Fill in to set up a new rule:</th></tr>
1084
-
1085
- <tr>
1086
- <th style="text-align: left">Posts by <input type="text" name="add_author_rule_name" /></th>
1087
- <td>
1088
- <select id="add-author-rule" name="add_author_rule_action" onchange="flip_newuser('add-author-rule');">
1089
- <?php foreach ($authorlist as $author_id => $author_name) : ?>
1090
- <option value="<?php echo $author_id; ?>">are assigned to <?php echo $author_name; ?></option>
1091
- <?php endforeach; ?>
1092
- <option value="newuser">will be assigned to a new user...</option>
1093
- <option value="filter">get filtered out</option>
1094
- </select>
1095
- </td>
1096
- <td><div id="add-author-rule-newuser">named <input type="text" name="add_author_rule_newuser" value="" /></div></td>
1097
- </tr>
1098
 
1099
- </table>
1100
- <?php fwp_option_box_closer(); ?>
1101
-
1102
- <script>
1103
- flip_newuser('unfamiliar-author');
1104
- <?php for ($j=1; $j<=$i; $j++) : ?>
1105
- flip_newuser('author-rules-<?php echo $j; ?>');
1106
- <?php endfor; ?>
1107
- flip_newuser('add-author-rule');
1108
- </script>
1109
-
1110
- <?php
1111
- fwp_linkedit_periodic_submit();
1112
- fwp_option_box_opener('Comments & Pings', 'commentstatusdiv', 'postbox');
1113
  ?>
1114
- <table class="editform" width="75%" cellspacing="2" cellpadding="5">
1115
- <tr><th width="27%" scope="row" style="vertical-align:top"><?php print __('Comments'); ?>:</th>
1116
- <td width="73%"><ul style="margin:0; list-style:none">
1117
- <li><label><input type="radio" name="feed_comment_status" value="site-default"
1118
- <?php echo $status['comment']['site-default']; ?> /> Use site-wide setting from <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/syndication-options.php">Syndication Options</a>
1119
- (currently: <strong><?php echo ($comment_status_global ? $comment_status_global : 'closed'); ?>)</strong></label></li>
1120
- <li><label><input type="radio" name="feed_comment_status" value="open"
1121
- <?php echo $status['comment']['open']; ?> /> Allow comments on syndicated posts from this feed</label></li>
1122
- <li><label><input type="radio" name="feed_comment_status" value="closed"
1123
- <?php echo $status['comment']['closed']; ?> /> Don't allow comments on syndicated posts from this feed</label></li>
1124
- </ul></td></tr>
1125
-
1126
- <tr><th width="27%" scope="row" style="vertical-align:top"><?php print __('Pings'); ?>:</th>
1127
- <td width="73%"><ul style="margin:0; list-style:none">
1128
- <li><label><input type="radio" name="feed_ping_status" value="site-default"
1129
- <?php echo $status['ping']['site-default']; ?> /> Use site-wide setting from <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/syndication-options.php">Syndication Options</a>
1130
- (currently: <strong><?php echo ($ping_status_global ? $ping_status_global : 'closed'); ?>)</strong></label></li>
1131
- <li><label><input type="radio" name="feed_ping_status" value="open"
1132
- <?php echo $status['ping']['open']; ?> /> Accept pings on syndicated posts from this feed</label></li>
1133
- <li><label><input type="radio" name="feed_ping_status" value="closed"
1134
- <?php echo $status['ping']['closed']; ?> /> Don't accept pings on syndicated posts from this feed</label></li>
1135
- </ul></td></tr>
1136
-
1137
- </table>
1138
- <?php fwp_option_box_closer(); ?>
1139
- <?php fwp_linkedit_periodic_submit(); ?>
1140
 
1141
- <?php fwp_option_box_opener('Custom Settings (for use in templates)', 'postcustom', 'postbox'); ?>
1142
  <div id="postcustomstuff">
1143
  <table id="meta-list" cellpadding="3">
1144
  <tr>
@@ -1187,14 +851,13 @@ endif; ?>
1187
  function fwp_multidelete_page () {
1188
  global $wpdb;
1189
 
1190
- check_admin_referer(); // Make sure the referers are kosher
 
1191
 
1192
  $link_ids = (isset($_REQUEST['link_ids']) ? $_REQUEST['link_ids'] : array());
1193
  if (isset($_REQUEST['link_id'])) : array_push($link_ids, $_REQUEST['link_id']); endif;
1194
 
1195
- if (!current_user_can('manage_links')):
1196
- die (__("Cheatin' uh ?"));
1197
- elseif (isset($GLOBALS['fwp_post']['confirm']) and $GLOBALS['fwp_post']['confirm']=='Delete'):
1198
  foreach ($GLOBALS['fwp_post']['link_action'] as $link_id => $what) :
1199
  $do_it[$what][] = $link_id;
1200
  endforeach;
@@ -1277,6 +940,7 @@ function fwp_multidelete_page () {
1277
  ?>
1278
  <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
1279
  <div class="wrap">
 
1280
  <input type="hidden" name="action" value="Unsubscribe" />
1281
  <input type="hidden" name="confirm" value="Delete" />
1282
 
1
  <?php
2
  require_once(dirname(__FILE__) . '/admin-ui.php');
3
+ require_once(dirname(__FILE__) . '/magpiemocklink.class.php');
4
 
5
  ################################################################################
6
  ## ADMIN MENU ADD-ONS: implement Dashboard management pages ####################
168
  <?php if (fwp_test_wp_version(0, FWP_SCHEMA_25)) : ?>
169
  <div class="wrap">
170
  <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
171
+ <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
172
  <h2>Add a new syndicated site:</h2>
173
  <div>
174
+ <label for="add-uri">Website or feed:</label>
175
  <input type="text" name="lookup" id="add-uri" value="URI" size="64" />
176
  <input type="hidden" name="action" value="feedfinder" />
177
  </div>
192
  $updateFeedsNow = __('Update feeds now');
193
  ?>
194
  <form action="" method="POST">
195
+ <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
196
  <?php if (fwp_test_wp_version(FWP_SCHEMA_25, FWP_SCHEMA_27)) : ?>
197
  <div id="rightnow">
198
  <h3 class="reallynow"><span><?php print $updateFeedsNow; ?></span>
243
  <?php endif; ?>
244
 
245
  <form id="syndicated-links" action="admin.php?page=<?php print $GLOBALS['fwp_path']; ?>/<?php echo basename(__FILE__); ?>" method="post">
246
+ <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?></div>
247
+
248
  <?php $alt_row = true; ?>
249
 
250
  <?php if (fwp_test_wp_version(FWP_SCHEMA_25)) : ?>
312
  ?>
313
  <td>
314
  <strong><a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>&amp;link_id=<?php echo $link->link_id; ?>&amp;action=linkedit"><?php echo wp_specialchars($link->link_name, 'both'); ?></a></strong>
315
+ <div class="row-actions"><div><strong>Settings &gt;</strong>
316
+ <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>&amp;link_id=<?php echo $link->link_id; ?>&amp;action=linkedit"><?php _e('Feed'); ?></a>
317
+ | <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/posts-page.php&amp;link_id=<?php echo $link->link_id; ?>"><?php _e('Posts'); ?></a>
318
+ | <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/authors-page.php&amp;link_id=<?php echo $link->link_id; ?>"><?php _e('Authors'); ?></a>
319
+ | <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/categories-page.php&amp;link_id=<?php echo $link->link_id; ?>"><?php _e('Categories &amp; Tags'); ?></a></div>
320
+ <div><strong>Actions &gt;</strong>
321
+ <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>&amp;link_id=<?php echo $link->link_id; ?>&amp;action=feedfinder"><?php echo $caption; ?></a>
322
  | <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>&amp;link_id=<?php echo $link->link_id; ?>&amp;action=Unsubscribe"><?php _e('Unsubscribe'); ?></a>
323
+ | <a href="<?php echo wp_specialchars($link->link_url, 'both'); ?>"><?php _e('View')?></a></div>
324
  </div>
325
  </td>
326
  <?php
434
  endif;
435
  ?>
436
  <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
437
+ <div><?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_switchfeed'); ?></div>
438
  <fieldset style="clear: both">
439
  <legend><?php echo $rss->feed_type; ?> <?php echo $rss->feed_version; ?> feed</legend>
440
 
450
  <div>
451
  <div style="float:right; background-color:#D0D0D0; color: black; width:45%; font-size:70%; border-left: 1px dotted #A0A0A0; padding-left: 0.5em; margin-left: 1.0em">
452
  <?php if (count($rss->items) > 0): ?>
453
+ <?php
454
+ // Prepare to display Sample Item
455
+ $link =& new MagpieMockLink($rss, $f);
456
+ $post =& new SyndicatedPost($rss->items[0], $link);
457
+ ?>
458
  <h3>Sample Item</h3>
459
  <ul>
460
+ <li><strong>Title:</strong> <a href="<?php echo $post->post['meta']['syndication_permalink']; ?>"><?php echo $post->post['post_title']; ?></a></li>
461
+ <li><strong>Date:</strong> <?php print date('d-M-y g:i:s a', $post->published()); ?></li>
462
  </ul>
463
  <div class="entry">
464
+ <?php print $post->post['post_content']; ?>
465
  </div>
466
  <?php else: ?>
467
  <h3>No Items</h3>
496
  </div>
497
 
498
  <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
499
+ <div><?php
500
+ FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds');
501
+ ?></div>
502
  <div class="wrap">
503
  <h2>Use another feed</h2>
504
  <div><label>Feed:</label>
515
  function fwp_switchfeed_page () {
516
  global $wpdb, $wp_db_version;
517
 
518
+ // If this is a POST, validate source and user credentials
519
+ FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_switchfeed', /*capability=*/ 'manage_links');
520
+
521
  if (!isset($_REQUEST['Cancel'])):
522
+ if (isset($_POST['link_id']) and ($_POST['link_id']==0)):
 
 
523
  $link_id = FeedWordPress::syndicate_link($_REQUEST['feed_title'], $_REQUEST['feed_link'], $_REQUEST['feed']);
524
  if ($link_id): ?>
525
+ <div class="updated"><p><a href="<?php echo stripslashes($_REQUEST['feed_link']); ?>"><?php echo wp_specialchars(stripslashes($_REQUEST['feed_title']), 'both'); ?></a>
526
+ has been added as a contributing site, using the feed at &lt;<a href="<?php echo stripslashes($_REQUEST['feed']); ?>"><?php echo wp_specialchars(stripslashes($_REQUEST['feed']), 'both'); ?></a>&gt;.
527
+ | <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>&amp;link_id=<?php echo $link_id; ?>&amp;action=linkedit">Configure settings</a>.</div>
528
  <?php else: ?>
529
+ <div class="updated"><p>There was a problem adding the feed. [SQL: <?php echo wp_specialchars(mysql_error(), 'both'); ?>]</p></div>
530
  <?php endif;
531
+ elseif (isset($_POST['link_id'])):
532
  // Update link_rss
533
  $result = $wpdb->query("
534
  UPDATE $wpdb->links
556
  function fwp_linkedit_page () {
557
  global $wpdb, $wp_db_version;
558
 
559
+ // If this is a POST, validate source and user credentials
560
+ FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_linkedit', /*capability=*/ 'manage_links');
561
 
562
  $special_settings = array ( /* Regular expression syntax is OK here */
563
  'cats',
579
  'link/.*',
580
  );
581
 
582
+ if (isset($_REQUEST['feedfinder'])) :
 
 
583
  return fwp_feedfinder_page(); // re-route to Feed Finder page
584
  else :
585
  $link_id = (int) $_REQUEST['link_id'];
635
  $link->settings['update/hold'] = $GLOBALS['fwp_post']['update_schedule'];
636
  endif;
637
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
638
  $alter[] = "link_notes = '".$wpdb->escape($link->settings_to_notes())."'";
639
 
640
  $alter_set = implode(", ", $alter);
661
  $link_name = wp_specialchars($db_link->link_name, 1);
662
  $link_description = wp_specialchars($db_link->link_description, 'both');
663
  $link_rss_uri = wp_specialchars($db_link->link_rss, 'both');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
664
  else :
665
  die( __('Link not found.') );
666
  endif;
675
  if (o.value=='yes') { ed.style.display='inline'; view.style.display='none'; }
676
  else { ed.style.display='none'; view.style.display='inline'; }
677
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
678
  </script>
679
 
680
  <?php if ($updated_link) : ?>
683
 
684
  <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
685
  <div class="wrap">
686
+ <?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_linkedit'); ?>
687
  <input type="hidden" name="link_id" value="<?php echo $link_id; ?>" />
688
  <input type="hidden" name="action" value="linkedit" />
689
  <input type="hidden" name="save" value="link" />
690
 
691
+ <?php if (fwp_test_wp_version(FWP_SCHEMA_27)) : ?>
692
+ <div class="icon32"><img src="<?php print htmlspecialchars(WP_PLUGIN_URL.'/'.$GLOBALS['fwp_path'].'/feedwordpress.png'); ?>" alt="" /></div>
693
+ <?php endif; ?>
694
+
695
+ <h2><?php _e('Feed settings'); ?><?php if (!is_null($link) and $link->found()) : ?>: <?php echo wp_specialchars($link->link->link_name, 1); ?><?php endif; ?></h2>
696
+
697
  <div id="poststuff">
698
  <?php fwp_linkedit_single_submit($status); ?>
699
 
792
  <?php fwp_linkedit_periodic_submit(); ?>
793
 
794
  <?php
795
+ FeedWordPressSettingsUI::instead_of_posts_box($link_id);
796
+ FeedWordPressSettingsUI::instead_of_authors_box($link_id);
797
+ FeedWordPressSettingsUI::instead_of_categories_box($link_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
798
 
799
+ fwp_option_box_opener('Custom Feed Settings (for use in templates)', 'postcustom', 'postbox');
 
 
 
 
 
 
 
 
 
 
 
 
 
800
  ?>
801
+ <p class="setting-description">These custom settings are special fields for the <strong>feed</strong> you are
802
+ syndicating, to be retrieved in templates using the <code>get_feed_meta()</code> function. They do not create
803
+ custom fields on syndicated <strong>posts</strong>. If you want to create custom fields that are applied to each
804
+ individual post from this feed, set up the settings in <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/posts-page.php&amp;link_id=<?php print $link_id; ?>">Syndicated Posts</a>.</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
805
 
 
806
  <div id="postcustomstuff">
807
  <table id="meta-list" cellpadding="3">
808
  <tr>
851
  function fwp_multidelete_page () {
852
  global $wpdb;
853
 
854
+ // If this is a POST, validate source and user credentials
855
+ FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_feeds', /*capability=*/ 'manage_links');
856
 
857
  $link_ids = (isset($_REQUEST['link_ids']) ? $_REQUEST['link_ids'] : array());
858
  if (isset($_REQUEST['link_id'])) : array_push($link_ids, $_REQUEST['link_id']); endif;
859
 
860
+ if (isset($GLOBALS['fwp_post']['confirm']) and $GLOBALS['fwp_post']['confirm']=='Delete'):
 
 
861
  foreach ($GLOBALS['fwp_post']['link_action'] as $link_id => $what) :
862
  $do_it[$what][] = $link_id;
863
  endforeach;
940
  ?>
941
  <form action="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/<?php echo basename(__FILE__); ?>" method="post">
942
  <div class="wrap">
943
+ <?php FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds'); ?>
944
  <input type="hidden" name="action" value="Unsubscribe" />
945
  <input type="hidden" name="confirm" value="Delete" />
946