PluginProbe
FeedWordPress / 0.91
FeedWordPress v0.91
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
← All changes | wp-content/plugins/feedwordpress.php +324 -1671 0.970.91 View file →
@@ -2,13 +2,13 @@
2 2 /*
3 3 Plugin Name: FeedWordPress
4 4 Plugin URI: http://projects.radgeek.com/feedwordpress
5 5 Description: simple and flexible Atom/RSS syndication for WordPress
6 -Version: 0.97
6 +Version: 0.91
7 7 Author: Charles Johnson
8 -Author URI: http://radgeek.com/
8 +Author URI: http://www.radgeek.com/
9 9 License: GPL
10 -Last modified: 2005-09-28 4:40pm EDT
10 +Last modified: 2005-04-09 2:00pm EDT
11 11 */
12 12
13 13 # This uses code derived from:
14 14 # - wp-rss-aggregate.php by Kellan Elliot-McCrea <kellan@protest.net>
@@ -26,16 +26,11 @@
26 26 # <http://www.zyx.com/blog/xmlrpc.php>), or see `update-feeds.php`
27 27
28 28 # -- Don't change these unless you know what you're doing...
29 29 define ('RPC_MAGIC', 'tag:radgeek.com/projects/feedwordpress/');
30 -define ('FEEDWORDPRESS_VERSION', '0.97');
30 +define ('FEEDWORDPRESS_VERSION', '0.91');
31 31 define ('DEFAULT_SYNDICATION_CATEGORY', 'Contributors');
32 32
33 -define ('FEEDWORDPRESS_CAT_SEPARATOR_PATTERN', '/[:\n]/');
34 -define ('FEEDWORDPRESS_CAT_SEPARATOR', "\n");
35 -
36 -define ('FEEDVALIDATOR_URI', 'http://feedvalidator.org/check.cgi');
37 -
38 33 // Note that the rss-functions.php that comes prepackaged with WordPress is
39 34 // old & busted. For the new hotness, drop a copy of rss-functions.php from
40 35 // this archive into wp-includes/rss-functions.php
41 36 require_once (ABSPATH . WPINC . '/rss-functions.php');
@@ -42,116 +37,85 @@
42 37
43 38 // Is this being loaded from within WordPress 1.5 or later?
44 39 if (isset($wp_version) and $wp_version >= 1.5):
45 40
46 - $fwp_db_version = get_settings('feedwordpress_version');
47 - $feedwordpress_needs_upgrade = false; // innocent until proven guilty
48 - if (!$fwp_db_version or $fwp_db_version < FEEDWORDPRESS_VERSION) :
49 - // check to see whether this is a fresh install or an upgrade
50 - $syn = $wpdb->get_col("
51 - SELECT post_id
52 - FROM $wpdb->postmeta
53 - WHERE meta_key = 'syndication_feed'
54 - ");
55 - if (count($syn) > 0) : // contains at least one syndicated post
56 - $feedwordpress_needs_upgrade = true;
57 - else : // fresh install; brand it as ours
58 - update_option('feedwordpress_version', FEEDWORDPRESS_VERSION);
59 - if (!get_settings('feedwordpress_rpc_secret')) :
60 - update_option('feedwordpress_rpc_secret', substr(md5(uniqid(microtime())), 0, 6));
61 - endif;
62 - endif;
63 - endif;
41 + # Syndicated items should not be folded, crumpled, mutilated, or
42 + # spindled by WordPress formatting filters. But we don't want to
43 + # interfere with filters for any locally-authored posts.
44 + #
45 + # What WordPress should really have is a way for upstream filters to
46 + # stop downstream filters from running at all. Since it doesn't, and
47 + # since a downstream filter can't access the original copy of the text
48 + # that is being filtered, what we will do here is (1) save a copy of the
49 + # original text upstream, before any other filters run, and then (2)
50 + # retrieve that copy downstream, after all the other filters run, if
51 + # this is a syndicated post
52 + #
53 + add_filter('the_content', 'feedwordpress_preserve_syndicated_content', -10000);
54 + add_filter('the_content', 'feedwordpress_restore_syndicated_content', 10000);
64 55
65 - if (!$feedwordpress_needs_upgrade) : // only work if the conditions are safe!
56 + # Filter in original permalinks if the user wants that
57 + add_filter('post_link', 'syndication_permalink', 1);
66 58
67 - # Syndicated items are generally received in output-ready (X)HTML and
68 - # should not be folded, crumpled, mutilated, or spindled by WordPress
69 - # formatting filters. But we don't want to interfere with filters for
70 - # any locally-authored posts, either.
71 - #
72 - # What WordPress should really have is a way for upstream filters to
73 - # stop downstream filters from running at all. Since it doesn't, and
74 - # since a downstream filter can't access the original copy of the text
75 - # that is being filtered, what we will do here is (1) save a copy of the
76 - # original text upstream, before any other filters run, and then (2)
77 - # retrieve that copy downstream, after all the other filters run, *if*
78 - # this is a syndicated post
59 + # Admin menu
60 + add_action('admin_menu', 'fwp_add_pages');
79 61
80 - add_filter('the_content', 'feedwordpress_preserve_syndicated_content', -10000);
81 - add_filter('the_content', 'feedwordpress_restore_syndicated_content', 10000);
62 + # Inbound XML-RPC update methods
63 + add_filter('xmlrpc_methods', 'feedwordpress_xmlrpc_hook');
64 +
65 + # Outbound XML-RPC reform
66 + remove_action('publish_post', 'generic_ping');
67 + add_action('publish_post', 'fwp_catch_ping');
68 +
69 + $update_logging = get_settings('feedwordpress_update_logging');
70 +
71 + # -- Logging status updates to error_log, if you want it
72 + if ($update_logging == 'yes') :
73 + add_action('post_syndicated_item', 'log_feedwordpress_post', 100);
74 + add_action('update_syndicated_item', 'log_feedwordpress_update_post', 100);
75 + add_action('feedwordpress_update', 'log_feedwordpress_update_feeds', 100);
76 + add_action('feedwordpress_check_feed', 'log_feedwordpress_check_feed', 100);
77 + add_action('feedwordpress_update_complete', 'log_feedwordpress_update_complete', 100);
82 78
83 - # Filter in original permalinks if the user wants that
84 - add_filter('post_link', 'syndication_permalink', 1);
79 + function log_feedwordpress_post ($id) {
80 + $post = wp_get_single_post($id);
81 + error_log("[".date('Y-m-d H:i:s')."][feedwordpress] posted "
82 + ."'{$post->post_title}' ({$post->post_date})");
83 + }
85 84
86 - # Admin menu
87 - add_action('admin_menu', 'fwp_add_pages');
85 + function log_feedwordpress_update_post ($id) {
86 + $post = wp_get_single_post($id);
87 + error_log("[".date('Y-m-d H:i:s')."][feedwordpress] updated "
88 + ."'{$post->post_title}' ({$post->post_date})"
89 + ." (as of {$post->post_modified})");
90 + }
91 +
92 + function log_feedwordpress_update_feeds ($uri) {
93 + error_log("[".date('Y-m-d H:i:s')."][feedwordpress] update('$uri')");
94 + }
95 +
96 + function log_feedwordpress_check_feed ($feed) {
97 + $uri = $feed['uri']; $name = $feed['name'];
98 + error_log("[".date('Y-m-d H:i:s')."][feedwordpress] Examining $name <$uri>");
99 + }
88 100
89 - # Inbound XML-RPC update methods
90 - add_filter('xmlrpc_methods', 'feedwordpress_xmlrpc_hook');
101 + function log_feedwordpress_update_complete ($delta) {
102 + $mesg = array();
103 + if (isset($delta['new'])) $mesg[] = 'added '.$delta['new'].' new posts';
104 + if (isset($delta['updated'])) $mesg[] = 'updated '.$delta['updated'].' existing posts';
105 + if (empty($mesg)) $mesg[] = 'nothing changed';
91 106
92 - # Outbound XML-RPC ping reform
93 - remove_action('publish_post', 'generic_ping');
94 - add_action('publish_post', 'fwp_catch_ping');
95 -
96 - # Hook in logging functions only if the logging option is ON
97 - $update_logging = get_settings('feedwordpress_update_logging');
98 - if ($update_logging == 'yes') :
99 - add_action('post_syndicated_item', 'log_feedwordpress_post', 100);
100 - add_action('update_syndicated_item', 'log_feedwordpress_update_post', 100);
101 - add_action('feedwordpress_update', 'log_feedwordpress_update_feeds', 100);
102 - add_action('feedwordpress_check_feed', 'log_feedwordpress_check_feed', 100);
103 - add_action('feedwordpress_update_complete', 'log_feedwordpress_update_complete', 100);
104 - endif;
105 - else :
106 - # Hook in the menus, which will just point to the upgrade interface
107 - add_action('admin_menu', 'fwp_add_pages');
108 - endif; // if (!$feedwordpress_needs_upgrade)
107 + error_log("[".date('Y-m-d H:i:s')."][feedwordpress] "
108 + .(is_null($delta) ? "I don't syndicate <$uri>"
109 + : implode(' and ', $mesg)));
110 + }
111 + endif;
112 +
109 113 endif;
110 114
111 -################################################################################
112 -## LOGGING FUNCTIONS: log status updates to error_log if you want it ###########
113 -################################################################################
115 +# -- Template functions for syndication sites
116 +function is_syndicated () { return (strlen(get_syndication_feed()) > 0); }
114 117
115 -function log_feedwordpress_post ($id) {
116 - $post = wp_get_single_post($id);
117 - error_log("[".date('Y-m-d H:i:s')."][feedwordpress] posted "
118 - ."'{$post->post_title}' ({$post->post_date})");
119 -}
120 -
121 -function log_feedwordpress_update_post ($id) {
122 - $post = wp_get_single_post($id);
123 - error_log("[".date('Y-m-d H:i:s')."][feedwordpress] updated "
124 - ."'{$post->post_title}' ({$post->post_date})"
125 - ." (as of {$post->post_modified})");
126 -}
127 -
128 -function log_feedwordpress_update_feeds ($uri) {
129 - error_log("[".date('Y-m-d H:i:s')."][feedwordpress] update('$uri')");
130 -}
131 -
132 -function log_feedwordpress_check_feed ($feed) {
133 - $uri = $feed['link/uri']; $name = $feed['link/name'];
134 - error_log("[".date('Y-m-d H:i:s')."][feedwordpress] Examining $name <$uri>");
135 -}
136 -
137 -function log_feedwordpress_update_complete ($delta) {
138 - $mesg = array();
139 - if (isset($delta['new'])) $mesg[] = 'added '.$delta['new'].' new posts';
140 - if (isset($delta['updated'])) $mesg[] = 'updated '.$delta['updated'].' existing posts';
141 - if (empty($mesg)) $mesg[] = 'nothing changed';
142 -
143 - error_log("[".date('Y-m-d H:i:s')."][feedwordpress] "
144 - .(is_null($delta) ? "Error: I don't syndicate that URI"
145 - : implode(' and ', $mesg)));
146 -}
147 -
148 -################################################################################
149 -## TEMPLATE API: functions to make your templates syndication-aware ############
150 -################################################################################
151 -
152 -function is_syndicated () { return (strlen(get_syndication_feed_id()) > 0); }
153 -
154 118 function the_syndication_source_link () { echo get_syndication_source_link(); }
155 119 function get_syndication_source_link () { list($n) = get_post_custom_values('syndication_source_uri'); return $n; }
156 120
157 121 function get_syndication_source () { list($n) = get_post_custom_values('syndication_source'); return $n; }
@@ -159,30 +123,24 @@
159 123
160 124 function get_syndication_feed () { list($u) = get_post_custom_values('syndication_feed'); return $u; }
161 125 function the_syndication_feed () { echo get_syndication_feed (); }
162 126
163 -function get_syndication_feed_id () { list($u) = get_post_custom_values('syndication_feed_id'); return $u; }
164 -function the_syndication_feed_id () { echo get_syndication_feed_id(); }
165 -
166 -$feedwordpress_linkcache = array (); // only load links from database once
167 -
168 127 function get_feed_meta ($key) {
169 - global $wpdb, $feedwordpress_linkcache;
170 - $feed_id = get_syndication_feed_id();
171 -
128 + global $wpdb;
129 + $feed = get_syndication_feed();
130 +
172 131 $ret = NULL;
173 - if (strlen($feed_id) > 0):
174 - if (isset($feedwordpress_linkcache[$feed_id])) :
175 - $result = $feedwordpress_linkcache[$feed_id];
176 - else :
177 - $result = $wpdb->get_row("
178 - SELECT * FROM $wpdb->links
179 - WHERE (link_id = '".$wpdb->escape($feed_id)."')"
180 - );
181 - $feedwordpress_linkcache[$feed_id] = $result;
182 - endif;
183 -
184 - $meta = FeedWordPress::notes_to_settings($result->link_notes);
132 + if (strlen($feed) > 0):
133 + $result = $wpdb->get_var("
134 + SELECT link_notes FROM $wpdb->links
135 + WHERE link_rss = '".$wpdb->escape($feed)."'"
136 + );
137 +
138 + $notes = explode("\n", $result);
139 + foreach ($notes as $note):
140 + list($k, $v) = explode(': ', $note, 2);
141 + $meta[$k] = trim($v);
142 + endforeach;
185 143 $ret = $meta[$key];
186 144 endif; /* if */
187 145 return $ret;
188 146 }
@@ -193,12 +151,9 @@
193 151 function the_syndication_permalink () {
194 152 echo get_syndication_permalink();
195 153 }
196 154
197 -################################################################################
198 -## FILTERS: syndication-aware handling of post data for templates and feeds ####
199 -################################################################################
200 -
155 +# -- Filters for templates and feeds
201 156 $feedwordpress_the_syndicated_content = NULL;
202 157
203 158 function feedwordpress_preserve_syndicated_content ($text) {
204 159 global $feedwordpress_the_syndicated_content;
@@ -229,76 +184,19 @@
229 184 return $permalink;
230 185 endif;
231 186 } // function syndication_permalink ()
232 187
233 -################################################################################
234 -## UPGRADE INTERFACE: Have users upgrade DB from older versions of FWP #########
235 -################################################################################
236 -
237 -function fwp_upgrade_page () {
238 - if (isset($_POST['action']) and $_POST['action']=='Upgrade') :
239 - $ver = get_settings('feedwordpress_version');
240 - if (get_settings('feedwordpress_version') != FEEDWORDPRESS_VERSION) :
241 - echo "<div class=\"wrap\">\n";
242 - echo "<h2>Upgrading FeedWordPress...</h2>";
243 -
244 - $feedwordpress =& new FeedWordPress;
245 - $feedwordpress->upgrade_database();
246 - echo "<p><strong>Done!</strong> Upgraded database to version ".FEEDWORDPRESS_VERSION.".</p>\n";
247 - echo "<form action=\"\" method=\"get\">\n";
248 - echo "<div class=\"submit\"><input type=\"hidden\" name=\"page\" value=\"".basename(__FILE__)."\" />";
249 - echo "<input type=\"submit\" value=\"Continue &raquo;\" /></form></div>\n";
250 - echo "</div>\n";
251 - return;
252 - else :
253 - echo "<div class=\"updated\"><p>Already at version ".FEEDWORDPRESS_VERSION."!</p></div>";
254 - endif;
255 - endif;
256 -?>
257 -<div class="wrap">
258 -<h2>Upgrade FeedWordPress</h2>
259 -
260 -<p>It appears that you have installed FeedWordPress
261 -<?=FEEDWORDPRESS_VERSION?> as an upgrade to an existing installation of
262 -FeedWordPress. That's no problem, but you will need to take a minute out first
263 -to upgrade your database: some necessarily changes in how the software keeps
264 -track of posts and feeds will cause problems such as duplicate posts and broken
265 -templates if we were to continue without the upgrade.</p>
266 -
267 -<p>Note that most of FeedWordPress's functionality is temporarily disabled
268 -until we have successfully completed the upgrade. Everything should begin
269 -working as normal again once the upgrade is complete. There's extraordinarily
270 -little chance of any damage as the result of the upgrade, but if you're paranoid
271 -like me you may want to back up your database before you proceed.</p>
272 -
273 -<p>This may take several minutes for a large installation.</p>
274 -
275 -<form action="" method="post">
276 -<div class="submit"><input type="submit" name="action" value="Upgrade" /></div>
277 -</form>
278 -</div>
279 -<?php
280 -} // function fwp_upgrade_page ()
281 -
282 -################################################################################
283 -## ADMIN MENU ADD-ONS: implement Dashboard management pages ####################
284 -################################################################################
285 -
188 +# -- Admin menu add-ons
286 189 function fwp_add_pages () {
287 190 add_submenu_page('link-manager.php', 'Syndicated Sites', 'Syndicated', 5, basename(__FILE__), 'fwp_syndication_manage_page');
288 - add_options_page('Syndication Options', 'Syndication', 6, basename(__FILE__), 'fwp_syndication_options_page');
191 + add_options_page('Syndication', 'Syndication', 6, basename(__FILE__), 'fwp_syndication_options_page');
289 192 } // function fwp_add_pages () */
290 193
291 194 function fwp_syndication_options_page () {
292 195 global $wpdb, $user_level;
293 196
294 - if ($GLOBALS['feedwordpress_needs_upgrade']) :
295 - fwp_upgrade_page();
296 - return;
297 - endif;
298 -
299 197 $caption = 'Save Changes';
300 - if (isset($_POST['action']) and $_POST['action']==$caption):
198 + if (isset($_REQUEST['action']) and $_REQUEST['action']=$caption):
301 199 check_admin_referer();
302 200
303 201 if ($user_level < 6):
304 202 die (__("Cheatin' uh ?"));
@@ -306,58 +204,8 @@
306 204 update_option('feedwordpress_rpc_secret', $_REQUEST['rpc_secret']);
307 205 update_option('feedwordpress_cat_id', $_REQUEST['syndication_category']);
308 206 update_option('feedwordpress_munge_permalink', $_REQUEST['munge_permalink']);
309 207 update_option('feedwordpress_update_logging', $_REQUEST['update_logging']);
310 - update_option('feedwordpress_unfamiliar_author', $_REQUEST['unfamiliar_author']);
311 - update_option('feedwordpress_unfamiliar_category', $_REQUEST['unfamiliar_category']);
312 - update_option('feedwordpress_syndicated_post_status', $_REQUEST['post_status']);
313 -
314 - // Categories
315 - $cats = array();
316 - if (isset($_POST['post_category'])) :
317 - $cat_set = "(".implode(",", $_POST['post_category']).")";
318 - $cats = $wpdb->get_col(
319 - "SELECT cat_name
320 - FROM $wpdb->categories
321 - WHERE cat_ID IN {$cat_set}
322 - ");
323 - endif;
324 -
325 - if (!empty($cats)) :
326 - update_option('feedwordpress_syndication_cats', implode("\n", $cats));
327 - else :
328 - delete_option('feedwordpress_syndication_cats');
329 - endif;
330 -
331 - if (isset($_REQUEST['comment_status']) and ($_REQUEST['comment_status'] == 'open')) :
332 - update_option('feedwordpress_syndicated_comment_status', 'open');
333 - else :
334 - update_option('feedwordpress_syndicated_comment_status', 'closed');
335 - endif;
336 -
337 - if (isset($_REQUEST['ping_status']) and ($_REQUEST['ping_status'] == 'open')) :
338 - update_option('feedwordpress_syndicated_ping_status', 'open');
339 - else :
340 - update_option('feedwordpress_syndicated_ping_status', 'closed');
341 - endif;
342 -
343 - if (isset($_REQUEST['hardcode_name']) and ($_REQUEST['hardcode_name'] == 'no')) :
344 - update_option('feedwordpress_hardcode_name', 'no');
345 - else :
346 - update_option('feedwordpress_hardcode_name', 'yes');
347 - endif;
348 -
349 - if (isset($_REQUEST['hardcode_description']) and ($_REQUEST['hardcode_description'] == 'no')) :
350 - update_option('feedwordpress_hardcode_description', 'no');
351 - else :
352 - update_option('feedwordpress_hardcode_description', 'yes');
353 - endif;
354 -
355 - if (isset($_REQUEST['hardcode_url']) and ($_REQUEST['hardcode_url'] == 'no')) :
356 - update_option('feedwordpress_hardcode_url', 'no');
357 - else :
358 - update_option('feedwordpress_hardcode_url', 'yes');
359 - endif;
360 208 ?>
361 209 <div class="updated">
362 210 <p><?php _e('Options saved.')?></p>
363 211 </div>
@@ -368,50 +216,31 @@
368 216 $cat_id = FeedWordPress::link_category_id();
369 217 $rpc_secret = FeedWordPress::rpc_secret();
370 218 $munge_permalink = get_settings('feedwordpress_munge_permalink');
371 219 $update_logging = get_settings('feedwordpress_update_logging');
372 -
373 - $hardcode_name = get_settings('feedwordpress_hardcode_name');
374 - $hardcode_description = get_settings('feedwordpress_hardcode_description');
375 - $hardcode_url = get_settings('feedwordpress_hardcode_url');
376 -
377 - $post_status = FeedWordPress::syndicated_status('post', array(), 'publish');
378 - $comment_status = FeedWordPress::syndicated_status('comment', array(), 'closed');
379 - $ping_status = FeedWordPress::syndicated_status('ping', array(), 'closed');
380 -
381 - $unfamiliar_author = array ('create' => '','default' => '','filter' => '');
382 - $ua = FeedWordPress::on_unfamiliar('author');
383 - if (is_string($ua) and array_key_exists($ua, $unfamiliar_author)) :
384 - $unfamiliar_author[$ua] = ' checked="checked"';
385 - endif;
386 - $unfamiliar_category = array ('create'=>'','default'=>'','filter'=>'');
387 - $uc = FeedWordPress::on_unfamiliar('category');
388 - if (is_string($uc) and array_key_exists($uc, $unfamiliar_category)) :
389 - $unfamiliar_category[$uc] = ' checked="checked"';
390 - endif;
391 220 $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY cat_id");
392 -
393 - $cats = get_settings('feedwordpress_syndication_cats');
394 - $dogs = get_nested_categories(-1, 0);
395 - $cats = array_map('strtolower',
396 - array_map('trim',
397 - preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, $cats)
398 - ));
399 -
400 - foreach ($dogs as $tag => $dog) :
401 - if (in_array(strtolower(trim($dog['cat_name'])), $cats)) :
402 - $dogs[$tag]['checked'] = true;
403 - endif;
404 - endforeach;
405 -
406 221 ?>
407 222 <div class="wrap">
408 223 <h2>Syndication Options</h2>
409 224 <form action="" method="post">
410 225 <fieldset class="options">
411 -<legend>Syndicated Feeds</legend>
226 +<legend>Template Options</legend>
412 227 <table class="editform" width="100%" cellspacing="2" cellpadding="5">
413 228 <tr>
229 +<th width="33%" scope="row">Permalinks for syndicated posts point to:</th>
230 +<td width="67%"><select name="munge_permalink" size="1">
231 +<option value="yes"<?=($munge_permalink=='yes')?' selected="selected"':''?>>source website</option>
232 +<option value="no"<?=($munge_permalink=='no')?' selected="selected"':''?>>this website</option>
233 +</select></td>
234 +</tr>
235 +</table>
236 +<div class="submit"><input type="submit" name="action" value="<?=$caption?>" /></div>
237 +</fieldset>
238 +
239 +<fieldset class="options">
240 +<legend>Syndication Options</legend>
241 +<table class="editform" width="100%" cellspacing="2" cellpadding="5">
242 +<tr>
414 243 <th width="33%" scope="row">Syndicate links in category:</th>
415 244 <td width="67%"><?php
416 245 echo "\n<select name=\"syndication_category\" size=\"1\">";
417 246 foreach ($results as $row) {
@@ -425,67 +254,9 @@
425 254 }
426 255 echo "\n</select>\n";
427 256 ?></td>
428 257 </tr>
429 -
430 -<tr><th width="33%" scope="row" style="vertical-align:top">Update live from feed:</th>
431 -<td width="67%"><ul style="margin:0;list-style:none">
432 -<li><input type="checkbox" name="hardcode_name" value="no"<?=(($hardcode_name=='yes')?'':' checked="checked"')?>/> Contributor name (feed title)</li>
433 -<li><input type="checkbox" name="hardcode_description" value="no"<?=(($hardcode_description=='yes')?'':' checked="checked"')?>/> Contributor description (feed tagline)</li>
434 -<li><input type="checkbox" name="hardcode_url" value="no"<?=(($hardcode_url=='yes')?'':' checked="checked"')?>/> Homepage (feed link)</li>
435 -</ul></td></tr>
436 258 </table>
437 -</fieldset>
438 -
439 -<fieldset class="options">
440 -<legend>Syndicated Posts</legend>
441 -
442 -<fieldset id="categorydiv" style="width: 20%; margin-right: 2em">
443 -<legend>Categories</legend>
444 -<p style="font-size:smaller;font-style:bold;margin:0">Place <em>all syndicated
445 -posts</em> under...</p>
446 -<div style="height: 20em"><?php write_nested_categories($dogs); ?></div>
447 -</fieldset>
448 -
449 -<table class="editform" width="75%" cellspacing="2" cellpadding="5">
450 -<tr style="vertical-align: top"><th width="33%" scope="row">Publication:</th>
451 -<td width="67%"><ul style="margin: 0; padding: 0; list-style:none">
452 -<li><label><input type="radio" name="post_status" value="publish"<?=($post_status=='publish')?' checked="checked"':''?> /> Publish syndicated posts immediately</label></li>
453 -<li><label><input type="radio" name="post_status" value="draft"<?=($post_status=='draft')?' checked="checked"':''?> /> Hold syndicated posts as drafts</label></li>
454 -<li><label><input type="radio" name="post_status" value="private"<?=($post_status=='private')?' checked="checked"':''?> /> Hold syndicated posts as private posts</label></li>
455 -</ul></td></tr>
456 -
457 -<tr style="vertical-align: top"><th width="33%" scope="row">Comments:</th>
458 -<td width="67%"><ul style="margin: 0; padding: 0; list-style:none">
459 -<li><label><input type="radio" name="comment_status" value="open"<?=($comment_status=='open')?' checked="checked"':''?> /> Allow comments on syndicated posts</label></li>
460 -<li><label><input type="radio" name="comment_status" value="closed"<?=($comment_status!='open')?' checked="checked"':''?> /> Don't allow comments on syndicated posts</label></li>
461 -</ul></td></tr>
462 -
463 -<tr style="vertical-align: top"><th width="33%" scope="row">Trackback and Pingback:</th>
464 -<td width="67%"><ul style="margin:0; padding: 0; list-style:none">
465 -<li><label><input type="radio" name="ping_status" value="open"<?=($ping_status=='open')?' checked="checked"':''?> /> Accept pings on syndicated posts</label></li>
466 -<li><label><input type="radio" name="ping_status" value="closed"<?=($ping_status!='open')?' checked="checked"':''?> /> Don't accept pings on syndicated posts</label></li>
467 -</ul></td></tr>
468 -
469 -<tr style="vertical-align: top"><th width="33%" scope="row" style="vertical-align:top">Unfamiliar authors:</th>
470 -<td width="67%"><ul style="margin: 0; padding: 0; list-style:none">
471 -<li><label><input type="radio" name="unfamiliar_author" value="create"<?=$unfamiliar_author['create']?>/> create a new author account</label></li>
472 -<li><label><input type="radio" name="unfamiliar_author" value="default"<?=$unfamiliar_author['default']?> /> attribute the post to the default author</label></li>
473 -<li><label><input type="radio" name="unfamiliar_author" value="filter"<?=$unfamiliar_author['filter']?> /> don't syndicate the post</label></li>
474 -</ul></td></tr>
475 -<tr style="vertical-align: top"><th width="33%" scope="row" style="vertical-align:top">Unfamiliar categories:</th>
476 -<td width="67%"><ul style="margin: 0; padding:0; list-style:none">
477 -<li><label><input type="radio" name="unfamiliar_category" value="create"<?=$unfamiliar_category['create']?>/> create any categories the post is in</label></li>
478 -<li><label><input type="radio" name="unfamiliar_category" value="default"<?=$unfamiliar_category['default']?>/> don't create new categories</li>
479 -<li><label><input type="radio" name="unfamiliar_category" value="filter"<?=$unfamiliar_category['filter']?>/> don't create new categories and don't syndicate posts unless they match at least one familiar category</label></li>
480 -</ul></td></tr>
481 -
482 -<tr style="vertical-align: top"><th width="33%" scope="row">Permalinks point to:</th>
483 -<td width="67%"><select name="munge_permalink" size="1">
484 -<option value="yes"<?=($munge_permalink=='yes')?' selected="selected"':''?>>original website</option>
485 -<option value="no"<?=($munge_permalink=='no')?' selected="selected"':''?>>this website</option>
486 -</select></td></tr>
487 -</table>
488 259 <div class="submit"><input type="submit" name="action" value="<?=$caption?>" /></div>
489 260 </fieldset>
490 261
491 262 <fieldset class="options">
@@ -512,21 +283,15 @@
512 283 }
513 284
514 285 function fwp_syndication_manage_page () {
515 286 global $user_level, $wpdb;
516 -
517 - if ($GLOBALS['feedwordpress_needs_upgrade']) :
518 - fwp_upgrade_page();
519 - return;
520 - endif;
521 -
522 287 ?>
523 288 <?php $cont = true;
524 289 if (isset($_REQUEST['action'])):
525 - if ($_REQUEST['action'] == 'feedfinder') : $cont = fwp_feedfinder_page();
526 - elseif ($_REQUEST['action'] == 'switchfeed') : $cont = fwp_switchfeed_page();
527 - elseif ($_REQUEST['action'] == 'linkedit') : $cont = fwp_linkedit_page();
528 - elseif ($_REQUEST['action'] == 'Unsubscribe from Checked' or $_REQUEST['action'] == 'Unsubscribe') : $cont = fwp_multidelete_page();
290 + //die("ACTION: '".$_REQUEST['action']."'");
291 + if ($_REQUEST['action'] == 'feedfinder'): $cont = fwp_feedfinder_page();
292 + elseif ($_REQUEST['action'] == 'switchfeed'): $cont = fwp_switchfeed_page();
293 + elseif ($_REQUEST['action'] == 'Delete Checked'): $cont = fwp_multidelete_page();
529 294 endif;
530 295 endif;
531 296
532 297 if ($cont):
@@ -554,9 +319,9 @@
554 319
555 320 <table width="100%" cellpadding="3" cellspacing="3">
556 321 <tr>
557 322 <th width="20%"><?php _e('Name'); ?></th>
558 -<th width="40%"><?php _e('Feed'); ?></th>
323 +<th width="50%"><?php _e('Feed'); ?></th>
559 324 <th colspan="4"><?php _e('Action'); ?></th>
560 325 </tr>
561 326
562 327 <?php foreach ($links as $link):
@@ -562,46 +327,33 @@
562 327 <?php foreach ($links as $link):
563 328 $alt_row = !$alt_row; ?>
564 329 <tr<?=($alt_row?' class="alternate"':'')?>>
565 330 <td><a href="<?=wp_specialchars($link->link_url)?>"><?=wp_specialchars($link->link_name)?></a></td>
566 -<?php
567 - if (strlen($link->link_rss) > 0):
568 - $caption='Switch Feed';
569 - $uri_bits = parse_url($link->link_rss);
570 - $uri_bits['host'] = preg_replace('/^www\./i', '', $uri_bits['host']);
571 - $display_uri =
572 - (isset($uri_bits['user'])?$uri_bits['user'].'@':'')
573 - .(isset($uri_bits['host'])?$uri_bits['host']:'')
574 - .(isset($uri_bits['port'])?':'.$uri_bits['port']:'')
575 - .(isset($uri_bits['path'])?$uri_bits['path']:'')
576 - .(isset($uri_bits['query'])?'?'.$uri_bits['query']:'');
577 - if (strlen($display_uri) > 32) : $display_uri = substr($display_uri, 0, 32).'&#8230;'; endif;
331 +<?php if (strlen($link->link_rss) > 0): $caption='Switch Feed'; ?>
332 +<td style="font-size:smaller;text-align:center">
333 +<strong><a href="<?=$link->link_rss?>"><?=wp_specialchars($link->link_rss)?></a></strong>
334 +<em>check validity</em> <a style="vertical-align:middle"
335 +title="Check feed &lt;<?=wp_specialchars($link->link_rss)?>&gt; for validity"
336 +href="http://feedvalidator.org/check.cgi?url=<?=urlencode($link->link_rss)?>"><img
337 +src="../wp-images/smilies/icon_arrow.gif" alt="&rarr;" /></a></td>
338 +<?php else: $caption='Find Feed'; ?>
339 +<td style="background-color:#FFFFD0"><p><strong>no
340 +feed assigned</strong></p></td>
341 +<? endif; ?>
342 +<?php if (($link->user_level <= $user_level)): ?>
343 + <td><a href="link-manager.php?page=<?=basename(__FILE__)?>&amp;link_id=<?=$link->link_id?>&amp;action=feedfinder" class="edit"><?=$caption?></a></div></td>
344 + <td><a href="link-manager.php?link_id=<?=$link->link_id?>&amp;action=linkedit" class="edit"><?php _e('Edit')?></a></td>
345 + <td><a href="link-manager.php?link_id=<?=$link->link_id?>&amp;action=Delete" onclick="return confirm('You are about to delete this link.\\n \'Cancel\' to stop, \'OK\' to delete.');" class="delete"><?php _e('Delete'); ?></a></td>
346 + <td><input type="checkbox" name="linkcheck[]" value="<?=$link->link_id?>" /></td>
347 +<?php else:
348 + echo "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>\n";
349 + endif;
350 + echo "\n\t</tr>";
578 351 ?>
579 - <td>
580 - <strong><a href="<?=$link->link_rss?>"><?=wp_specialchars($display_uri)?></a></strong></td>
352 + </tr>
581 353 <?php
582 - else:
583 - $caption='Find Feed';
584 -?>
585 - <td style="background-color:#FFFFD0"><p><strong>no
586 - feed assigned</strong></p></td>
587 -<?php
588 - endif;
589 -
590 - if (($link->user_level <= $user_level)):
591 -?>
592 - <td><a href="link-manager.php?page=<?=basename(__FILE__)?>&amp;link_id=<?=$link->link_id?>&amp;action=linkedit" class="edit"><?php _e('Edit')?></a></td>
593 - <td><a href="link-manager.php?page=<?=basename(__FILE__)?>&amp;link_id=<?=$link->link_id?>&amp;action=feedfinder" class="edit"><?=$caption?></a></td>
594 - <td><a href="link-manager.php?page=<?=basename(__FILE__)?>&amp;link_id=<?=$link->link_id?>&amp;action=Unsubscribe" class="delete"><?php _e('Unsubscribe'); ?></a></td>
595 - <td><input type="checkbox" name="link_ids[]" value="<?=$link->link_id?>" /></td>
596 -<?php
597 - else:
598 - echo "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>\n";
599 - endif;
600 - echo "\n\t</tr>";
601 354 endforeach;
602 - else:
603 -?>
355 + else: ?>
604 356
605 357 <p>There are no websites currently listed for syndication.</p>
606 358
607 359 <?php endif; ?>
@@ -610,9 +362,9 @@
610 362
611 363 <div class="wrap">
612 364 <h2>Manage Multiple Links</h2>
613 365 <div class="submit">
614 - <input type="submit" class="delete" name="action" value="Unsubscribe from Checked" />
366 + <input type="submit" class="delete" name="action" value="Delete Checked" />
615 367 </div>
616 368 </div>
617 369 </form>
618 370 <?php
@@ -736,9 +488,9 @@
736 488 ");
737 489
738 490 if ($result): ?>
739 491 <div class="updated"><p><a href="<?=$_REQUEST['feed_link']?>"><?=wp_specialchars($_REQUEST['feed_title'])?></a>
740 -has been added as a contributing site, using the newsfeed at &lt;<a href="<?=$_REQUEST['feed']?>"><?=wp_specialchars($_REQUEST['feed'])?></a>&gt;.</p></div>
492 +has been added as a contributing site, using the newfeed at &lt;<a href="<?=$_REQUEST['feed']?>"><?=wp_specialchars($_REQUEST['feed'])?></a>&gt;.</p></div>
741 493 <?php else: ?>
742 494 <div class="updated"><p>There was a problem adding the newsfeed. [SQL: <?=wp_specialchars(mysql_error())?>]</p></div>
743 495 <?php endif;
744 496 elseif (isset($_REQUEST['link_id'])):
@@ -765,618 +517,32 @@
765 517 endif;
766 518 return true; // Continue
767 519 }
768 520
769 -function fwp_linkedit_page () {
770 - global $wpdb, $user_level;
771 -
772 - check_admin_referer(); // Make sure we arrived here from the Dashboard
773 -
774 - $special_settings = array ( /* Regular expression syntax is OK here */
775 - 'cats',
776 - 'hardcode name',
777 - 'hardcode url',
778 - 'hardcode description',
779 - 'hardcode categories', /* Deprecated */
780 - 'post status',
781 - 'comment status',
782 - 'ping status',
783 - 'unfamiliar author',
784 - 'unfamliar categories',
785 - 'update/.*',
786 - 'feed/.*',
787 - 'link/.*',
788 - );
789 -
790 - if ($user_level < 5) :
791 - die (__("Cheatin' uh ?"));
792 - elseif (isset($_REQUEST['feedfinder'])) :
793 - return fwp_feedfinder_page(); // re-route to Feed Finder page
794 - else :
795 - $link_id = (int) $_REQUEST['link_id'];
796 - $row = $wpdb->get_row("
797 - SELECT * FROM $wpdb->links WHERE link_id = $link_id
798 - ");
799 -
800 - if ($row) :
801 - if (isset($_POST['save'])) :
802 - $alter = array ();
803 -
804 - $meta = FeedWordPress::notes_to_settings($row->link_notes);
805 - if (isset($meta['cats'])):
806 - $meta['cats'] = preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, $meta['cats']);
807 - endif;
808 -
809 - // custom feed settings first
810 - foreach ($_POST['notes'] as $mn) :
811 - $mn['key0'] = trim($mn['key0']);
812 - $mn['key1'] = trim($mn['key1']);
813 - if (preg_match("\007^(("
814 - .implode(')|(',$special_settings)
815 - ."))$\007i",
816 - $mn['key1'])) :
817 - $mn['key1'] = 'user/'.$mn['key1'];
818 - endif;
819 -
820 - if (strlen($mn['key0']) > 0) :
821 - unset($meta[$mn['key0']]); // out with the old
822 - endif;
823 -
824 - if (($mn['action']=='update') and (strlen($mn['key1']) > 0)) :
825 - $meta[$mn['key1']] = $mn['value']; // in with the new
826 - endif;
827 - endforeach;
828 -
829 - // now stuff through the web form
830 - // hardcoded feed info
831 - if (isset($_POST['hardcode_name'])) :
832 - $meta['hardcode name'] = $_POST['hardcode_name'];
833 - if (FeedWordPress::affirmative($meta, 'hardcode name')) :
834 - $alter[] = "link_name = '".$wpdb->escape($_POST['name'])."'";
835 - endif;
836 - endif;
837 - if (isset($_POST['hardcode_description'])) :
838 - $meta['hardcode description'] = $_POST['hardcode_description'];
839 - if (FeedWordPress::affirmative($meta, 'hardcode description')) :
840 - $alter[] = "link_description = '".$wpdb->escape($_POST['description'])."'";
841 - endif;
842 - endif;
843 - if (isset($_POST['hardcode_url'])) :
844 - $meta['hardcode url'] = $_POST['hardcode_url'];
845 - if (FeedWordPress::affirmative($meta, 'hardcode url')) :
846 - $alter[] = "link_url = '".$wpdb->escape($_POST['linkurl'])."'";
847 - endif;
848 - endif;
849 -
850 - // Update scheduling
851 - if (isset($_POST['update_schedule'])) :
852 - $meta['update/hold'] = $_POST['update_schedule'];
853 - endif;
854 -
855 - // Categories
856 - if (isset($_POST['post_category'])) :
857 - $cat_set = "(".implode(",", $_POST['post_category']).")";
858 - $meta['cats'] = $wpdb->get_col(
859 - "SELECT cat_name
860 - FROM $wpdb->categories
861 - WHERE cat_ID IN {$cat_set}
862 - ");
863 - if (count($meta['cats']) == 0) :
864 - unset($meta['cats']);
865 - endif;
866 - else :
867 - unset($meta['cats']);
868 - endif;
869 -
870 - // Post status, comment status, ping status
871 - foreach (array('post', 'comment', 'ping') as $what) :
872 - $sfield = "feed_{$what}_status";
873 - if (isset($_POST[$sfield])) :
874 - if ($_POST[$sfield]=='site-default') :
875 - unset($meta["{$what} status"]);
876 - else :
877 - $meta["{$what} status"] = $_POST[$sfield];
878 - endif;
879 - endif;
880 - endforeach;
881 -
882 - // Unfamiliar author, unfamiliar categories
883 - foreach (array("author", "category") as $what) :
884 - $sfield = "unfamiliar_{$what}";
885 - if (isset($_POST[$sfield])) :
886 - if ($_POST[$sfield]=='site-default') :
887 - unset($meta["unfamiliar {$what}"]);
888 - else :
889 - $meta["unfamiliar {$what}"] = $_POST[$sfield];
890 - endif;
891 - endif;
892 - endforeach;
893 -
894 - if (is_array($meta['cats'])) :
895 - $meta['cats'] = implode(FEEDWORDPRESS_CAT_SEPARATOR, $meta['cats']);
896 - endif;
897 -
898 - $notes = '';
899 - foreach ($meta as $key => $value) :
900 - $notes .= $key . ": ". addcslashes($value, "\0..\37") . "\n";
901 - endforeach;
902 - $alter[] = "link_notes = '".$wpdb->escape($notes)."'";
903 -
904 - $alter_set = implode(", ", $alter);
905 -
906 - // issue update query
907 - $result = $wpdb->query("
908 - UPDATE $wpdb->links
909 - SET $alter_set
910 - WHERE link_id='$link_id'
911 - ");
912 - $updated_link = true;
913 -
914 - // reload link information from DB
915 - $row = $wpdb->get_row("
916 - SELECT * FROM $wpdb->links WHERE link_id = $link_id
917 - ");
918 - else :
919 - $updated_link = false;
920 - endif;
921 -
922 - $link_url = wp_specialchars($row->link_url, 1);
923 - $link_name = wp_specialchars($row->link_name, 1);
924 - $link_image = $row->link_image;
925 - $link_target = $row->link_target;
926 - $link_category = $row->link_category;
927 - $link_description = wp_specialchars($row->link_description);
928 - $link_visible = $row->link_visible;
929 - $link_rating = $row->link_rating;
930 - $link_rel = $row->link_rel;
931 - $link_notes = wp_specialchars($row->link_notes);
932 - $link_rss_uri = wp_specialchars($row->link_rss);
933 -
934 - $meta = FeedWordPress::notes_to_settings($row->link_notes);
935 -
936 - $status['post'] = array('publish' => '', 'private' => '', 'draft' => '', 'site-default' => '');
937 - $status['comment'] = array('open' => '', 'closed' => '', 'site-default' => '');
938 - $status['ping'] = array('open' => '', 'closed' => '', 'site-default' => '');
939 -
940 - foreach (array('post', 'comment', 'ping') as $what) :
941 - if (isset($meta["{$what} status"])) :
942 - $status[$what][$meta["{$what} status"]] = ' checked="checked"';
943 - else :
944 - $status[$what]['site-default'] = ' checked="checked"';
945 - endif;
946 - endforeach;
947 -
948 - $unfamiliar['author'] = array ('create' => '','default' => '','filter' => '');
949 - $unfamiliar['category'] = array ('create'=>'','default'=>'','filter'=>'');
950 -
951 - foreach (array('author', 'category') as $what) :
952 - if (is_string($meta["unfamiliar {$what}"]) and
953 - array_key_exists($meta["unfamiliar {$what}"], $unfamiliar[$what])) :
954 - $key = $meta["unfamiliar {$what}"];
955 - else:
956 - $key = 'site-default';
957 - endif;
958 - $unfamiliar[$what][$key] = ' checked="checked"';
959 - endforeach;
960 -
961 - $dogs = get_nested_categories(-1, 0);
962 - $cats = array_map('strtolower',
963 - array_map('trim',
964 - preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, $meta['cats'])
965 - ));
966 -
967 - foreach ($dogs as $tag => $dog) :
968 - if (in_array(strtolower(trim($dog['cat_name'])), $cats)) :
969 - $dogs[$tag]['checked'] = true;
970 - endif;
971 - endforeach;
972 - else :
973 - die( __('Link not found.') );
974 - endif;
975 -
976 - ?>
977 -<script type="text/javascript">
978 - function flip_hardcode (item) {
979 - ed=document.getElementById('basics-'+item+'-edit');
980 - view=document.getElementById('basics-'+item+'-view');
981 -
982 - o = document.getElementById('basics-hardcode-'+item);
983 - if (o.value=='yes') { ed.style.display='inline'; view.style.display='none'; }
984 - else { ed.style.display='none'; view.style.display='inline'; }
985 - }
986 -</script>
987 -
988 -<?php if ($updated_link) : ?>
989 -<div class="updated"><p>Syndicated feed settings updated.</p></div>
990 -<?php endif; ?>
991 -
992 -<form action="link-manager.php?page=<?=basename(__FILE__)?>" method="post">
993 -<div class="wrap">
994 -<input type="hidden" name="link_id" value="<?=$link_id?>" />
995 -<input type="hidden" name="action" value="linkedit" />
996 -<input type="hidden" name="save" value="link" />
997 -
998 -<h2>Edit a syndicated feed:</h2>
999 -<fieldset><legend>Basics</legend>
1000 -<table class="editform" width="100%" cellspacing="2" cellpadding="5">
1001 -<tr>
1002 -<th scope="row" width="20%"><?php _e('Feed URI:') ?></th>
1003 -<td width="60%"><a href="<?=wp_specialchars($link_rss_uri)?>"><?=$link_rss_uri?></a>
1004 -<a href="<?=FEEDVALIDATOR_URI?>?url=<?=urlencode($link_rss_uri)?>"
1005 -title="Check feed &lt;<?=wp_specialchars($link_rss_uri)?>&gt; for validity"><img src="../wp-images/smilies/icon_arrow.gif" alt="&rarr;" /></a>
1006 -</td>
1007 -<td width="20%"><input type="submit" name="feedfinder" value="switch &rarr;" style="font-size:smaller" /></td>
1008 -</tr>
1009 -<tr>
1010 -<th scope="row" width="20%"><?php _e('Link Name:') ?></th>
1011 -<td width="60%"><input type="text" id="basics-name-edit" name="name"
1012 -value="<?php echo $link_name; ?>" style="width: 95%" />
1013 -<span id="basics-name-view"><strong><?=$link_name?></strong></span>
1014 -</td>
1015 -<td>
1016 -<select id="basics-hardcode-name" onchange="flip_hardcode('name')" name="hardcode_name">
1017 -<option value="no" <?=FeedWordPress::hardcode('name', $meta)?'':'selected="selected"'?>>update automatically</option>
1018 -<option value="yes" <?=FeedWordPress::hardcode('name', $meta)?'selected="selected"':''?>>edit manually</option>
1019 -</select>
1020 -</td>
1021 -</tr>
1022 -<tr>
1023 -<th scope="row" width="20%"><?php _e('Short description:') ?></th>
1024 -<td width="60%">
1025 -<input id="basics-description-edit" type="text" name="description" value="<?php echo $link_description; ?>" style="width: 95%" />
1026 -<span id="basics-description-view"><strong><?=$link_description?></strong></span>
1027 -</td>
1028 -<td>
1029 -<select id="basics-hardcode-description" onchange="flip_hardcode('description')"
1030 -name="hardcode_description">
1031 -<option value="no" <?=FeedWordPress::hardcode('description', $meta)?'':'selected="selected"'?>>update automatically</option>
1032 -<option value="yes" <?=FeedWordPress::hardcode('description', $meta)?'selected="selected"':''?>>edit manually</option>
1033 -</select></td>
1034 -</tr>
1035 -<tr>
1036 -<th width="20%" scope="row"><?php _e('Homepage:') ?></th>
1037 -<td width="60%">
1038 -<input id="basics-url-edit" type="text" name="linkurl" value="<?php echo $link_url; ?>" style="width: 95%;" />
1039 -<a id="basics-url-view" href="<?=$link_url?>"><?=$link_url?></a></td>
1040 -<td>
1041 -<select id="basics-hardcode-url" onchange="flip_hardcode('url')" name="hardcode_url">
1042 -<option value="no"<?=FeedWordPress::hardcode('url', $meta)?'':' selected="selected"'?>>update live from feed</option>
1043 -<option value="yes"<?=FeedWordPress::hardcode('url', $meta)?' selected="selected"':''?>>edit manually</option>
1044 -</select></td></tr>
1045 -
1046 -<tr>
1047 -<th width="20%"><?php _e('Last update') ?>:</th>
1048 -<td colspan="2"><?php
1049 - if (isset($meta['update/last'])) :
1050 - echo strftime('%x %X', $meta['update/last'])." ";
1051 - else :
1052 - echo " none yet";
1053 - endif;
1054 -?></td></tr>
1055 -<tr><th width="20%">Next update:</th>
1056 -<td colspan="2"><?php
1057 - $holdem = (isset($meta['update/hold']) ? $meta['update/hold'] : 'scheduled');
1058 -?>
1059 -<select name="update_schedule">
1060 -<option value="scheduled"<?=($holdem=='scheduled')?' selected="selected"':''?>>update on schedule <?php
1061 - echo " (";
1062 - if (isset($meta['update/ttl']) and is_numeric($meta['update/ttl'])) :
1063 - if (isset($meta['update/timed']) and $meta['update/timed']=='automatically') :
1064 - echo 'next: ';
1065 - $next = $meta['update/last'] + ((int) $meta['update/ttl'] * 60);
1066 - if (strftime('%x', time()) != strftime('%x', $next)) :
1067 - echo strftime('%x', $next)." ";
1068 - endif;
1069 - echo strftime('%X', $meta['update/last']+((int) $meta['update/ttl']*60));
1070 - else :
1071 - echo "every ".$meta['update/ttl']." minute".(($meta['update/ttl']!=1)?"s":"");
1072 - endif;
1073 - else:
1074 - echo "next scheduled update";
1075 - endif;
1076 - echo ")";
1077 -?></option>
1078 -<option value="next"<?=($holdem=='next')?' selected="selected"':''?>>update ASAP</option>
1079 -<option value="ping"<?=($holdem=='ping')?' selected="selected"':''?>>update only when pinged</option>
1080 -</select></tr>
1081 -</table>
1082 -</fieldset>
1083 -
1084 -<script type="text/javascript">
1085 -flip_hardcode('name');
1086 -flip_hardcode('description');
1087 -flip_hardcode('url');
1088 -</script>
1089 -
1090 -<p class="submit">
1091 -<input type="submit" name="submit" value="<?php _e('Save Changes &raquo;') ?>" />
1092 -</p>
1093 -
1094 -<fieldset>
1095 -<legend>Syndicated Posts</legend>
1096 -
1097 -<fieldset id="categorydiv" style="width: 20%; margin-right: 2em">
1098 -<legend>Categories</legend>
1099 -<p style="font-size:smaller;font-style:bold;margin:0">Place all syndicated posts from this feed
1100 -under...</p>
1101 -<div style="height: 16em"><?php write_nested_categories($dogs); ?></div>
1102 -</fieldset>
1103 -
1104 -<table class="editform" width="80%" cellspacing="2" cellpadding="5">
1105 -<tr><th width="20%" scope="row" style="vertical-align:top">Publication:</th>
1106 -<td width="80%" style="vertical-align:top"><ul style="margin:0; list-style:none">
1107 -<li><label><input type="radio" name="feed_post_status" value="site-default"
1108 -<?=$status['post']['site-default']?> /> Use site-wide setting from <a href="options-general.php?page=<?=basename(__FILE__)?>">Syndication Options</a>
1109 -(currently: <strong><?=FeedWordPress::syndicated_status('post', array(), 'publish')?></strong>)</label></li>
1110 -<li><label><input type="radio" name="feed_post_status" value="publish"
1111 -<?=$status['post']['publish']?> /> Publish posts from this feed immediately</label></li>
1112 -<li><label><input type="radio" name="feed_post_status" value="private"
1113 -<?=$status['post']['private']?> /> Hold posts from this feed as private posts</label></li>
1114 -<li><label><input type="radio" name="feed_post_status" value="draft"
1115 -<?=$status['post']['draft']?> /> Hold posts from this feed as drafts</label></li>
1116 -</ul></td>
1117 -</tr>
1118 -
1119 -<tr><th width="20%" scope="row" style="vertical-align:top">Comments:</th>
1120 -<td width="80%"><ul style="margin:0; list-style:none">
1121 -<li><label><input type="radio" name="feed_comment_status" value="site-default"
1122 -<?=$status['comment']['site-default']?> /> Use site-wide setting from <a href="options-general.php?page=<?=basename(__FILE__)?>">Syndication Options</a>
1123 -(currently: <strong><?=FeedWordPress::syndicated_status('comment', array(), 'closed')?>)</strong></label></li>
1124 -<li><label><input type="radio" name="feed_comment_status" value="open"
1125 -<?=$status['comment']['open']?> /> Allow comments on syndicated posts from this feed</label></li>
1126 -<li><label><input type="radio" name="feed_comment_status" value="closed"
1127 -<?=$status['comment']['closed']?> /> Don't allow comments on syndicated posts from this feed</label></li>
1128 -</ul></td>
1129 -</tr>
1130 -
1131 -<tr><th width="20%" scope="row" style="vertical-align:top">Trackback and Pingback:</th>
1132 -<td width="80%"><ul style="margin:0; list-style:none">
1133 -<li><label><input type="radio" name="feed_ping_status" value="site-default"
1134 -<?=$status['ping']['site-default']?> /> Use site-wide setting from <a href="options-general.php?page=<?=basename(__FILE__)?>">Syndication Options</a>
1135 -(currently: <strong><?=FeedWordPress::syndicated_status('ping', array(), 'closed')?>)</strong></label></li>
1136 -<li><label><input type="radio" name="feed_ping_status" value="open"
1137 -<?=$status['ping']['open']?> /> Accept pings on syndicated posts from this feed</label></li>
1138 -<li><label><input type="radio" name="feed_ping_status" value="closed"
1139 -<?=$status['ping']['closed']?> /> Don't accept pings on syndicated posts from this feed</label></li>
1140 -</ul></td>
1141 -</tr>
1142 -</table>
1143 -</fieldset>
1144 -
1145 -<p class="submit">
1146 -<input type="submit" name="submit" value="<?php _e('Save Changes &raquo;') ?>" />
1147 -</p>
1148 -
1149 -<fieldset>
1150 -<legend>Advanced Feed Options</legend>
1151 -<table class="editform" width="100%" cellspacing="2" cellpadding="5">
1152 -<tr>
1153 -<th width="20%" scope="row" style="vertical-align:top">Unfamiliar authors:</th>
1154 -<td width="80%"><ul style="margin: 0; list-style:none">
1155 -<li><label><input type="radio" name="unfamiliar_author" value="site-default"<?=$unfamiliar['author']['site-default']?> /> use site-wide setting from <a href="options-general.php?page=<?=basename(__FILE__)?>">Syndication Options</a>
1156 -(currently <strong><?=FeedWordPress::on_unfamiliar('author');?></strong>)</label></li>
1157 -<li><label><input type="radio" name="unfamiliar_author" value="create"<?=$unfamiliar['author']['create']?>/> create a new author account</label></li>
1158 -<li><label><input type="radio" name="unfamiliar_author" value="default"<?=$unfamiliar['author']['default']?> /> attribute the post to the default author</label></li>
1159 -<li><label><input type="radio" name="unfamiliar_author" value="filter"<?=$unfamiliar['author']['filter']?> /> don't syndicate the post</label></li>
1160 -</ul></td>
1161 -</tr>
1162 -
1163 -<tr>
1164 -<th width="20%" scope="row" style="vertical-align:top">Unfamiliar categories:</th>
1165 -<td width="80%"><ul style="margin: 0; list-style:none">
1166 -<li><label><input type="radio" name="unfamiliar_category" value="site-default"<?=$unfamiliar['category']['site-default']?> /> use site-wide setting from <a href="options-general.php?page=<?=basename(__FILE__)?>">Syndication Options</a>
1167 -(currently <strong><?=FeedWordPress::on_unfamiliar('category');?></strong>)</label></li>
1168 -<li><label><input type="radio" name="unfamiliar_category" value="create"<?=$unfamiliar['category']['create']?> /> create any categories the post is in</label></li>
1169 -<li><label><input type="radio" name="unfamiliar_category" value="default"<?=$unfamiliar['category']['default']?> /> don't create new categories</label></li>
1170 -<li><label><input type="radio" name="unfamiliar_category" value="filter"<?=$unfamiliar['category']['filter']?> /> don't create new categories and don't syndicate posts unless they match at least one familiar category</label></li>
1171 -</ul></td>
1172 -</tr></table>
1173 -</fieldset>
1174 -
1175 -<p class="submit">
1176 -<input type="submit" name="submit" value="<?php _e('Save Changes &raquo;') ?>" />
1177 -</p>
1178 -
1179 -<fieldset id="postcustom">
1180 -<legend>Custom Settings (for use in templates)</legend>
1181 -<div id="postcustomstuff">
1182 -<table id="meta-list" cellpadding="3">
1183 - <tr>
1184 - <th>Key</th>
1185 - <th>Value</th>
1186 - <th>Action</th>
1187 - </tr>
1188 -
1189 -<?php
1190 - $i = 0;
1191 - foreach ($meta as $key => $value) :
1192 - if (!preg_match("\007^((".implode(')|(', $special_settings)."))$\007i", $key)) :
1193 -?>
1194 - <tr style="vertical-align:top">
1195 - <th width="30%" scope="row"><input type="hidden" name="notes[<?=$i?>][key0]" value="<?=wp_specialchars($key)?>" />
1196 - <input id="notes-<?=$i?>-key" name="notes[<?=$i?>][key1]" value="<?=wp_specialchars($key)?>" /></th>
1197 - <td width="60%"><textarea rows="2" cols="40" id="notes-<?=$i?>-value" name="notes[<?=$i?>][value]"><?=wp_specialchars($value)?></textarea></td>
1198 - <td width="10%"><select name="notes[<?=$i?>][action]">
1199 - <option value="update">save changes</option>
1200 - <option value="delete">delete this setting</option>
1201 - </select></td>
1202 - </tr>
1203 -<?php
1204 - $i++;
1205 - endif;
1206 - endforeach;
1207 -?>
1208 - <tr>
1209 - <th scope="row"><input type="text" size="10" name="notes[<?=$i?>][key1]" value="" /></th>
1210 - <td><textarea name="notes[<?=$i?>][value]" rows="2" cols="40"></textarea></td>
1211 - <td><em>add new setting...</em><input type="hidden" name="notes[<?=$i?>][action]" value="update" /></td>
1212 - </tr>
1213 -</table>
1214 -</fieldset>
1215 -
1216 -<p class="submit">
1217 -<input type="submit" name="submit" value="<?php _e('Save Changes &raquo;') ?>" />
1218 -</p>
1219 -
1220 -</div>
1221 - <?php
1222 - endif;
1223 - return false; // Don't continue
1224 -}
1225 -
1226 521 function fwp_multidelete_page () {
1227 522 global $wpdb, $user_level;
1228 -
1229 - check_admin_referer(); // Make sure the referers are kosher
1230 -
1231 - $link_ids = (isset($_REQUEST['link_ids']) ? $_REQUEST['link_ids'] : array());
1232 - if (isset($_REQUEST['link_id'])) : array_push($link_ids, $_REQUEST['link_id']); endif;
1233 -
523 + check_admin_referer();
1234 524 if ($user_level < 5):
1235 525 die (__("Cheatin' uh ?"));
1236 - elseif (isset($_POST['confirm']) and $_POST['confirm']=='Delete'):
1237 - foreach ($_POST['link_action'] as $link_id => $what) :
1238 - $do_it[$what][] = $link_id;
1239 - endforeach;
526 + else:
527 + // Update link_rss
528 + $result = $wpdb->query("
529 + DELETE FROM $wpdb->links
530 + WHERE link_id IN (".implode(',',$_REQUEST['linkcheck']).")
531 + ");
1240 532
1241 - $alter = array();
1242 - if (count($do_it['hide']) > 0) :
1243 - $hidem = "(".implode(', ', $do_it['hide']).")";
1244 - $alter[] = "
1245 - UPDATE $wpdb->links
1246 - SET link_visible = 'N'
1247 - WHERE link_id IN {$hidem}
1248 - ";
533 + if ($result):
534 + $mesg = "Sites deleted from syndication list.";
535 + else:
536 + $mesg = "There was a problem deleting the sites from the syndication list. [SQL: ".mysql_error()."]";
1249 537 endif;
1250 -
1251 - if (count($do_it['nuke']) > 0) :
1252 - $nukem = "(".implode(', ', $do_it['nuke']).")";
1253 -
1254 - // Make a list of the items syndicated from this feed...
1255 - $post_ids = $wpdb->get_col("
1256 - SELECT post_id FROM $wpdb->postmeta
1257 - WHERE meta_key = 'syndication_feed_id'
1258 - AND meta_value IN {$nukem}
1259 - ");
1260 -
1261 - // ... and kill them all
1262 - if (count($post_ids) > 0) :
1263 - foreach ($post_ids as $post_id) :
1264 - wp_delete_post($post_id);
1265 - endforeach;
1266 - endif;
1267 -
1268 - $alter[] = "
1269 - DELETE FROM $wpdb->links
1270 - WHERE link_id IN {$nukem}
1271 - ";
1272 - endif;
1273 -
1274 - if (count($do_it['delete']) > 0) :
1275 - $deletem = "(".implode(', ', $do_it['delete']).")";
1276 -
1277 - // Make the items syndicated from this feed appear to be locally-authored
1278 - $alter[] = "
1279 - DELETE FROM $wpdb->postmeta
1280 - WHERE meta_key = 'syndication_feed_id'
1281 - AND meta_value IN {$deletem}
1282 - ";
1283 -
1284 - // ... and delete the links themselves.
1285 - $alter[] = "
1286 - DELETE FROM $wpdb->links
1287 - WHERE link_id IN {$deletem}
1288 - ";
1289 - endif;
1290 -
1291 - $errs = array(); $success = array ();
1292 - foreach ($alter as $sql) :
1293 - $result = $wpdb->query($sql);
1294 - if (!$result):
1295 - $errs[] = mysql_error();
1296 - endif;
1297 - endforeach;
1298 -
1299 - if (count($alter) > 0) :
1300 - echo "<div class=\"updated\">\n";
1301 - if (count($errs) > 0) :
1302 - echo "There were some problems processing your ";
1303 - echo "unsubscribe request. [SQL: ".implode('; ', $errs)."]";
1304 - else :
1305 - echo "Your unsubscribe request(s) have been processed.";
1306 - endif;
1307 - echo "</div>\n";
1308 - endif;
1309 -
1310 - return true; // Continue on to Syndicated Sites listing
1311 - else :
1312 - $targets = $wpdb->get_results("
1313 - SELECT * FROM $wpdb->links
1314 - WHERE link_id IN (".implode(",",$link_ids).")
1315 - ");
1316 -?>
1317 -<form action="link-manager.php?page=<?=basename(__FILE__)?>" method="post">
1318 -<div class="wrap">
1319 -<input type="hidden" name="action" value="Unsubscribe" />
1320 -<input type="hidden" name="confirm" value="Delete" />
1321 -
1322 -<h2>Unsubscribe from Syndicated Links:</h2>
1323 -<?php foreach ($targets as $link) :
1324 - $link_url = wp_specialchars($link->link_url, 1);
1325 - $link_name = wp_specialchars($link->link_name, 1);
1326 - $link_description = wp_specialchars($link->link_description);
1327 - $link_rss = wp_specialchars($link->link_rss);
1328 - $meta = FeedWordPress::notes_to_settings($link->link_notes);
1329 -?>
1330 -<fieldset>
1331 -<legend><?=$link_name?></legend>
1332 -<table class="editform" width="100%" cellspacing="2" cellpadding="5">
1333 -<tr><th scope="row" width="20%"><?php _e('Feed URI:') ?></th>
1334 -<td width="80%"><a href="<?=$link_rss?>"><?=$link_rss?></a></td></tr>
1335 -<tr><th scope="row" width="20%"><?php _e('Short description:') ?></th>
1336 -<td width="80%"><?=$link_description?></span></td></tr>
1337 -<tr><th width="20%" scope="row"><?php _e('Homepage:') ?></th>
1338 -<td width="80%"><a href="<?=$link_url?>"><?=$link_url?></a></td></tr>
1339 -<tr style="vertical-align:top"><th width="20%" scope="row">Subscription <?php _e('Options') ?>:</th>
1340 -<td width="80%"><ul style="margin:0; padding: 0; list-style: none">
1341 -<li><input type="radio" id="hide-<?=$link->link_id?>"
1342 -name="link_action[<?=$link->link_id?>]" value="hide" />
1343 -<label for="hide-<?=$link->link_id?>">Turn off the subscription for this
1344 -syndicated link<br/><span style="font-size:smaller">(Keep the feed information
1345 -and all the posts from this feed in the database, but don't syndicate any
1346 -new posts from the feed.)</span></label></li>
1347 -<li><input type="radio" id="nuke-<?=$link->link_id?>"
1348 -name="link_action[<?=$link->link_id?>]" value="nuke" />
1349 -<label for="nuke-<?=$link->link_id?>">Delete this syndicated link and all the
1350 -posts that were syndicated from it</label></li>
1351 -<li><input type="radio" id="delete-<?=$link->link_id?>"
1352 -name="link_action[<?=$link->link_id?>]" value="delete" />
1353 -<label for="delete-<?=$link->link_id?>">Delete this syndicated link, but
1354 -<em>keep</em> posts that were syndicated from it (as if they were authored
1355 -locally).</label></li>
1356 -<li><input type="radio" id="nothing-<?=$link->link_id?>"
1357 -name="link_action[<?=$link->link_id?>]" value="nothing" />
1358 -<label for="nothing-<?=$link->link_id?>">Keep this feed as it is. I changed
1359 -my mind.</label></li>
1360 -</ul>
1361 -</table>
1362 -</fieldset>
1363 -<?php endforeach; ?>
1364 -
1365 -<div class="submit">
1366 -<input class="delete" type="submit" name="submit" value="<?php _e('Unsubscribe from selected feeds &raquo;') ?>" />
1367 -</div>
1368 -</div>
1369 -<?php
1370 - return false; // Don't continue on to Syndicated Sites listing
538 + echo "<div class=\"updated\">$mesg</div>\n";
1371 539 endif;
540 + return true;
1372 541 }
1373 542
1374 -################################################################################
1375 -## fwp_hold_pings() and fwp_release_pings(): Outbound XML-RPC ping reform ####
1376 -## ... 'coz it's rude to send 500 pings the first time your aggregator runs ####
1377 -################################################################################
1378 -
543 +# -- Outbound XML-RPC ping reform
544 +# 'coz it's rude to send 500 pings the first time your aggregator runs
1379 545 $fwp_held_ping = NULL; // NULL: not holding pings yet
1380 546
1381 547 function fwp_hold_pings () {
1382 548 global $fwp_held_ping;
@@ -1401,13 +567,10 @@
1401 567 generic_ping($fwp_held_ping);
1402 568 endif;
1403 569 }
1404 570
1405 -################################################################################
1406 -## class FeedWordPress #########################################################
1407 -################################################################################
1408 -
1409 -// class FeedWordPress: handles feed updates and plugs in to the XML-RPC interface
571 +// class FeedWordPress: handle the updating of the feeds and plug in to the
572 +// XML-RPC interface
1410 573 class FeedWordPress {
1411 574 var $strip_attrs = array (
1412 575 array('[a-z]+', 'style'),
1413 576 array('[a-z]+', 'target'),
@@ -1455,18 +618,15 @@
1455 618 # * link_notes: user-configurable options, with keys and values
1456 619 # like so:
1457 620 #
1458 621 # key: value
1459 - # cats: computers\nweb
622 + # cats: computers:web
1460 623 # feed/key: value
1461 624 #
1462 625 # Keys that start with "feed/" are gleaned from the data supplied
1463 626 # by the feed itself, and will be overwritten with each update.
1464 627 #
1465 - # Values have linebreak characters escaped with C-style
1466 - # backslashes (so, for example, a newline becomes "\n").
1467 - #
1468 - # The value of `cats` is used as a newline-separated list of
628 + # The value of `cats` is used as a colon-separated (:) list of
1469 629 # default categories for any post coming from a particular feed.
1470 630 # (In the example above, any posts from this feed will be placed
1471 631 # in the "computers" and "web" categories--*in addition to* any
1472 632 # categories that may already be applied to the posts.)
@@ -1478,26 +638,31 @@
1478 638 $result = get_linkobjects(FeedWordPress::link_category_id());
1479 639
1480 640 $feeds = array ();
1481 641 if ($result): foreach ($result as $link):
642 + $sec = array ();
643 +
1482 644 if (strlen($link->link_rss) > 0):
1483 - $sec = FeedWordPress::notes_to_settings($link->link_notes);
1484 - $sec['link/uri'] = $link->link_rss;
1485 - $sec['link/name'] = $link->link_name;
1486 - $sec['link/id'] = $link->link_id;
645 + $notes = explode("\n", $link->link_notes);
646 + foreach ($notes as $note):
647 + list($key, $value) = explode(": ", $note, 2);
648 +
649 + if (strlen($key) > 0) :
650 + $sec[$key] = str_replace (
651 + '%newline%',
652 + "\n",
653 + trim($value) // trim() off the whitespace. Thanks to Ray Lischner for pointing this out.
654 + );
655 + endif;
656 + endforeach;
1487 657
1488 - // `hardcode categories` is deprecated in favor
1489 - // of `unfamiliar categories`
1490 - if (
1491 - FeedWordPress::affirmative($sec, 'hardcode categories')
1492 - and !isset($sec['unfamiliar categories'])
1493 - ) :
1494 - $sec['unfamiliar categories'] = 'default';
1495 - endif;
658 + $sec['uri'] = $link->link_rss;
659 + $sec['name'] = $link->link_name;
1496 660
1497 661 if (isset($sec['cats'])):
1498 - $sec['cats'] = preg_split(FEEDWORDPRESS_CAT_SEPARATOR_PATTERN, $sec['cats']);
662 + $sec['cats'] = explode(':',$sec['cats']);
1499 663 endif;
664 + $sec['link_id'] = $link->link_id;
1500 665
1501 666 $feeds[] = $sec;
1502 667 endif;
1503 668 endforeach; endif;
@@ -1502,152 +667,42 @@
1502 667 endif;
1503 668 endforeach; endif;
1504 669
1505 670 $this->feeds = $feeds;
1506 - } // FeedWordPress::FeedWordPress ()
671 + } // function acquire_feeds ()
1507 672
1508 - # function notes_to_settings (): Convert WordPress Link Notes to array
1509 - # of feed-level settings
1510 - #
1511 - # Arguments:
1512 - # ----------
1513 - # * $link_notes (string): the text from the Link Notes section of a link
1514 - #
1515 - # Returns:
1516 - # --------
1517 - # An associative array of settings stored in the Link Notes field. (For
1518 - # the `unfamiliar authors` setting, for example, simply look up the
1519 - # value of $meta['unfamiliar authors'], if $meta contains the value
1520 - # returned by `notes_to_settings()`.
1521 - #
1522 - # Values in FeedWordPress feed settings are escaped using C-style
1523 - # slashes. The escaped characters will already have been processed and
1524 - # converted in the returned array.
1525 - function notes_to_settings ($link_notes) {
1526 - $notes = explode("\n", $link_notes);
1527 -
1528 - $sec = array ();
1529 - foreach ($notes as $note):
1530 - list($key, $value) = explode(": ", $note, 2);
1531 -
1532 - if (strlen($key) > 0) :
1533 - // Unescape and trim() off the whitespace.
1534 - // Thanks to Ray Lischner for pointing out the
1535 - // need to trim off whitespace.
1536 - $sec[$key] = stripcslashes (trim($value));
1537 - endif;
1538 - endforeach;
1539 - return $sec;
1540 - } // FeedWordPress::notes_to_settings ()
1541 -
1542 - # function update (): polls for updates on one or more Contributor feeds
1543 - #
1544 - # Arguments:
1545 - # ----------
1546 - # * $uri (string): either the URI of the feed to poll, the URI of the
1547 - # website (human-readable link) whose feed you want to poll, or a
1548 - # "magic" tag: URI composed of the URI in the constant `RPC_MAGIC`
1549 - # and a "secret word" set in the FeedWordPress Options.
1550 - #
1551 - # If the "magic" URI is used, then FeedWordPress will poll any
1552 - # feeds that are ready for polling. It will not poll feeds that are
1553 - # marked as "Invisible" Links (signifying that the subscription has
1554 - # been de-activated), or feeds that are not yet stale according to
1555 - # their TTL setting (which is either set in the feed, or else
1556 - # set randomly within a window of 30 minutes - 2 hours).
1557 - #
1558 - # Returns:
1559 - # --------
1560 - # * Normally returns an associative array, with 'new' => the number
1561 - # of new posts added during the update, and 'updated' => the number
1562 - # of old posts that were updated during the update. If both numbers
1563 - # are zero, there was no change since the last poll on that URI.
1564 - #
1565 - # * Returns NULL if URI it was passed was not a URI that this
1566 - # installation of FeedWordPress syndicates (the most common cause
1567 - # of this error is attempts to poll all feeds, lacking, or using
1568 - # an incorrect, "secret word."
1569 - #
1570 - # Effects:
1571 - # --------
1572 - # * One or more feeds are polled for updates
1573 - #
1574 - # * If the feed Link does not have a hardcoded name set, its Link
1575 - # Name is synchronized with the feed's title element
1576 - #
1577 - # * If the feed Link does not have a hardcoded URI set, its Link URI
1578 - # is synchronized with the feed's human-readable link element
1579 - #
1580 - # * If the feed Link does not have a hardcoded description set, its
1581 - # Link Description is synchronized with the feed's description,
1582 - # tagline, or subtitle element.
1583 - #
1584 - # * The time of polling is recorded in the feed's settings, and the
1585 - # TTL (time until the feed is next available for polling) is set
1586 - # either from the feed (if it is supplied in the ttl or syndication
1587 - # module elements) or else from a randomly-generated time window
1588 - # (between 30 minutes and 2 hours).
1589 - #
1590 - # * New posts from the polled feed are added to the WordPress store.
1591 - #
1592 - # * Updates to existing posts since the last poll are mirrored in the
1593 - # WordPress store.
1594 - #
1595 673 function update ($uri) {
1596 674 global $wpdb;
1597 -
1598 - $uri = trim($uri);
1599 -
1600 - if ($GLOBALS['feedwordpress_needs_upgrade']) : // Will make duplicate posts if we don't hold off
1601 - return NULL;
1602 - endif;
1603 -
675 +
1604 676 do_action('feedwordpress_update', $uri);
1605 677
1606 678 // Secret voodoo tag: URI for updating *everything*.
1607 679 $secret = RPC_MAGIC.FeedWordPress::rpc_secret();
1608 680
1609 - fwp_hold_pings(); // Only send out one ping for the whole to-do
681 + fwp_hold_pings();
1610 682
1611 683 // Loop through and check for new posts
1612 684 $delta = NULL;
1613 - foreach ($this->feeds as $feed) :
1614 - $pinged_that = in_array($uri, array($secret, $feed['link/uri'], $feed['feed/link']));
1615 -
1616 - if ($uri != $secret) : // A site-specific ping always updates
1617 - $timely = true;
1618 - elseif (isset($feed['update/hold']) and ($feed['update/hold']=='ping')) :
1619 - $timely = false;
1620 - elseif (isset($feed['update/hold']) and ($feed['update/hold']=='next')) :
1621 - $timely = true;
1622 - elseif (!isset($feed['update/ttl']) or !isset($feed['update/last'])) :
1623 - $timely = true;
1624 - else :
1625 - $after = ((int) $feed['update/last'])
1626 - +((int) $feed['update/ttl'] * 60);
1627 - $timely = (time() >= $after);
1628 - endif;
1629 -
1630 - if ($pinged_that and is_null($delta)) : // If at least one feed was hit for updating...
1631 - $delta = array('new' => 0, 'updated' => 0); // ... don't return error condition
1632 - endif;
1633 -
1634 - if ($pinged_that and $timely) :
685 + foreach ($this->feeds as $feed) {
686 + if (($uri === $secret)
687 + or ($uri === $feed['uri'])
688 + or ($uri === $feed['feed/link'])) {
689 + if (is_null($delta)) $delta = array('new' => 0, 'updated' => 0);
1635 690 do_action('feedwordpress_check_feed', array($feed));
1636 691 $added = $this->feed2wp($wpdb, $feed);
1637 - if (isset($added['new'])) : $delta['new'] += $added['new']; endif;
1638 - if (isset($added['updated'])) : $delta['updated'] += $added['updated']; endif;
1639 - endif;
1640 - endforeach;
1641 -
692 + if (isset($added['new'])) $delta['new'] += $added['new'];
693 + if (isset($added['updated'])) $delta['updated'] += $added['updated'];
694 + } /* if */
695 + } /* foreach */
696 +
1642 697 do_action('feedwordpress_update_complete', array($delta));
1643 - fwp_release_pings(); // Now that we're done, send the one ping
698 + fwp_release_pings();
1644 699
1645 700 return $delta;
1646 701 }
1647 702
1648 703 function feed2wp ($wpdb, $f) {
1649 - $feed = fetch_rss($f['link/uri']);
704 + $feed = fetch_rss($f['uri']);
1650 705 $new_count = array('new' => 0, 'updated' => 0);
1651 706
1652 707 $this->update_feed($wpdb, $feed->channel, $f);
1653 708
@@ -1652,9 +707,9 @@
1652 707 $this->update_feed($wpdb, $feed->channel, $f);
1653 708
1654 709 if (is_array($feed->items)) :
1655 710 foreach ($feed->items as $item) :
1656 - $post = $this->item_to_post($wpdb, $item, $feed, $f);
711 + $post = $this->item_to_post($wpdb, $item, $feed->channel, $f);
1657 712 if (!is_null($post)) :
1658 713 $new = $this->add_post($wpdb, $post);
1659 714 if ( $new !== false ) $new_count[$new]++;
1660 715 endif;
@@ -1673,16 +728,16 @@
1673 728 // returned array for FeedWordPress::flatten_array($a) will contain a key
1674 729 // $a['feed/b/c/d'] with value 'e'.
1675 730 function flatten_array ($arr, $prefix = 'feed/', $separator = '/') {
1676 731 $ret = array ();
1677 - if (is_array($arr)) :
1678 - foreach ($arr as $key => $value) :
1679 - if (is_scalar($value)) :
732 + if (is_array($arr)):
733 + foreach ($arr as $key => $value) {
734 + if (is_scalar($value)) {
1680 735 $ret[$prefix.$key] = $value;
1681 - else :
736 + } else {
1682 737 $ret = array_merge($ret, $this->flatten_array($value, $prefix.$key.$separator, $separator));
1683 - endif;
1684 - endforeach;
738 + } /* if */
739 + } /* foreach */
1685 740 endif;
1686 741 return $ret;
1687 742 } // function FeedWordPress::flatten_array ()
1688 743
@@ -1689,103 +744,30 @@
1689 744 function resolve_relative_uri ($matches) {
1690 745 return $matches[1].Relative_URI::resolve($matches[2], $this->_base).$matches[3];
1691 746 } // function FeedWordPress::resolve_relative_uri ()
1692 747
1693 - function hardcode ($what, $f) {
1694 - $default = get_settings("feedwordpress_hardcode_$what");
1695 - if ( $default === 'yes' ) :
1696 - // If the default is to hardcode, then we want the
1697 - // negation of negative(): TRUE by default and FALSE if
1698 - // the setting is explicitly "no"
1699 - $ret = !FeedWordPress::negative($f, "hardcode $what");
1700 - else :
1701 - // If the default is NOT to hardcode, then we want
1702 - // affirmative(): FALSE by default and TRUE if the
1703 - // setting is explicitly "yes"
1704 - $ret = FeedWordPress::affirmative($f, "hardcode $what");
1705 - endif;
1706 - return $ret;
1707 - }
1708 -
1709 - function syndicated_status ($what, $f, $default) {
1710 - global $wpdb;
1711 -
1712 - $ret = get_settings("feedwordpress_syndicated_{$what}_status");
1713 - if ( isset($f["$what status"]) ) :
1714 - $ret = $f["$what status"];
1715 - elseif (!$ret) :
1716 - $ret = $default;
1717 - endif;
1718 - return $wpdb->escape(trim(strtolower($ret)));
1719 - }
1720 -
1721 - function negative ($f, $setting) {
1722 - $nego = array ('n', 'no', 'f', 'false');
1723 - return (isset($f[$setting]) and in_array(strtolower($f[$setting]), $nego));
1724 - }
1725 -
1726 - function affirmative ($f, $setting) {
748 + function setting_on ($f, $setting) {
1727 749 $affirmo = array ('y', 'yes', 't', 'true', 1);
1728 750 return (isset($f[$setting]) and in_array(strtolower($f[$setting]), $affirmo));
1729 751 }
1730 752
1731 - function feed_ttl ($channel) {
1732 - if (isset($channel['ttl'])) :
1733 - // "ttl stands for time to live. It's a number of
1734 - // minutes that indicates how long a channel can be
1735 - // cached before refreshing from the source."
1736 - // <http://blogs.law.harvard.edu/tech/rss#ltttlgtSubelementOfLtchannelgt>
1737 - $ret = $channel['ttl'];
1738 - elseif (isset($channel['sy']['updatefrequency']) or isset($channel['sy']['updateperiod'])) :
1739 - $period_minutes = array (
1740 - 'hourly' => 60, /* minutes in an hour */
1741 - 'daily' => 1440, /* minutes in a day */
1742 - 'weekly' => 10080, /* minutes in a week */
1743 - 'monthly' => 43200, /* minutes in a month */
1744 - 'yearly' => 525600, /* minutes in a year */
1745 - );
1746 -
1747 - // "sy:updatePeriod: Describes the period over which the
1748 - // channel format is updated. Acceptable values are:
1749 - // hourly, daily, weekly, monthly, yearly. If omitted,
1750 - // daily is assumed." <http://web.resource.org/rss/1.0/modules/syndication/>
1751 - if (isset($channel['sy']['updateperiod'])) : $period = $channel['sy']['updateperiod'];
1752 - else : $period = 'daily';
1753 - endif;
1754 -
1755 - // "sy:updateFrequency: Used to describe the frequency
1756 - // of updates in relation to the update period. A
1757 - // positive integer indicates how many times in that
1758 - // period the channel is updated. ... If omitted a value
1759 - // of 1 is assumed." <http://web.resource.org/rss/1.0/modules/syndication/>
1760 - if (isset($channel['sy']['updatefrequency'])) : $freq = (int) $channel['sy']['updatefrequency'];
1761 - else : $freq = 1;
1762 - endif;
1763 -
1764 - $ret = (int) ($period_minutes[$period] / $freq);
1765 - else :
1766 - $ret = NULL;
1767 - endif;
1768 - return $ret;
1769 - }
1770 -
1771 753 function update_feed ($wpdb, $channel, $f) {
1772 - $link_id = $f['link/id'];
754 + $link_id = $f['link_id'];
1773 755
1774 - if (!isset($channel['id'])) :
1775 - $channel['id'] = $f['link/uri'];
1776 - endif;
756 + if (!isset($channel['id'])) {
757 + $channel['id'] = $f['uri'];
758 + }
1777 759
1778 760 $update = array();
1779 - if (!FeedWordPress::hardcode('url', $f) and isset($channel['link'])) :
761 + if (isset($channel['link'])) :
1780 762 $update[] = "link_url = '".$wpdb->escape($channel['link'])."'";
1781 763 endif;
1782 764
1783 - if (!FeedWordPress::hardcode('name', $f) and isset($channel['title'])) :
765 + if (!FeedWordPress::setting_on($f, 'hardcode name') and isset($channel['title'])) :
1784 766 $update[] = "link_name = '".$wpdb->escape($channel['title'])."'";
1785 767 endif;
1786 768
1787 - if (!FeedWordPress::hardcode('description', $f)) :
769 + if (!FeedWordPress::setting_on($f, 'hardcode description')) :
1788 770 if (isset($channel['tagline'])) :
1789 771 $update[] = "link_description = '".$wpdb->escape($channel['tagline'])."'";
1790 772 elseif (isset($channel['description'])) :
1791 773 $update[] = "link_description = '".$wpdb->escape($channel['description'])."'";
@@ -1792,41 +774,25 @@
1792 774 endif;
1793 775 endif;
1794 776
1795 777 if (is_array($f['cats'])) :
1796 - $f['cats'] = implode(FEEDWORDPRESS_CAT_SEPARATOR, $f['cats']);
778 + $f['cats'] = implode(':',$f['cats']);
1797 779 endif;
1798 780
1799 781 $f = array_merge($f, $this->flatten_array($channel));
1800 -
1801 - $f['update/last'] = time();
1802 - $ttl = $this->feed_ttl($channel);
1803 - if (!is_null($ttl)) :
1804 - $f['update/ttl'] = $ttl;
1805 - $f['update/timed'] = 'feed';
1806 - else :
1807 - $f['update/ttl'] = rand(30, 120); // spread over time interval for staggered updates
1808 - $f['update/timed'] = 'automatically';
1809 - endif;
1810 782
1811 - if (!isset($f['update/hold']) or $f['update/hold']!='ping') :
1812 - $f['update/hold'] = 'scheduled';
1813 - endif;
1814 -
1815 783 # -- A few things we don't want to save in the notes
1816 - unset($f['link/id']); unset($f['link/uri']);
1817 - unset($f['link/name']);
1818 - unset($f['hardcode categories']); // Deprecated
784 + unset($f['link_id']); unset($f['uri']); unset($f['name']);
1819 785
1820 786 $notes = '';
1821 787 foreach ($f as $key => $value) :
1822 - $notes .= $key . ": ". addcslashes($value, "\0..\37") . "\n";
788 + $notes .= $key . ": ". str_replace("\n", "%newline%", $value) . "\n";
1823 789 endforeach;
1824 790 $update[] = "link_notes = '".$wpdb->escape($notes)."'";
1825 791
1826 792 $update_set = implode(',', $update);
1827 793
1828 - // Update the properties of the link from the feed information
794 + // if we've already have this feed, update
1829 795 $result = $wpdb->query("
1830 796 UPDATE $wpdb->links
1831 797 SET $update_set
1832 798 WHERE link_id='$link_id'
@@ -1831,59 +797,9 @@
1831 797 SET $update_set
1832 798 WHERE link_id='$link_id'
1833 799 ");
1834 800 } // function FeedWordPress::update_feed ()
1835 -
1836 - function date_created ($item) {
1837 - if (isset($item['dc']['created'])) :
1838 - $epoch = @parse_w3cdtf($item['dc']['created']);
1839 - elseif (isset($item['dcterms']['created'])) :
1840 - $epoch = @parse_w3cdtf($item['dcterms']['created']);
1841 - elseif (isset($item['created'])): // Atom 0.3
1842 - $epoch = @parse_w3cdtf($item['created']);
1843 - endif;
1844 - return $epoch;
1845 - }
1846 -
1847 - function guid ($item, $feed) {
1848 - if (isset($item['id'])): // Atom 0.3 / 1.0
1849 - $guid = $item['id'];
1850 - elseif (isset($item['atom']['id'])) : // Namespaced Atom
1851 - $guid = $item['atom']['id'];
1852 - elseif (isset($item['guid'])) : // RSS 2.0
1853 - $guid = $item['guid'];
1854 - elseif (isset($item['dc']['identifier'])) : // yeah, right
1855 - $guid = $item['dc']['identifier'];
1856 - else :
1857 - // The feed does not seem to have provided us with a
1858 - // unique identifier, so we'll have to cobble together
1859 - // a tag: URI that might work for us. The base of the
1860 - // URI will be the host name of the feed source ...
1861 - $bits = parse_url($feed['link/uri']);
1862 - $guid = 'tag:'.$bits['host'];
1863 -
1864 - // If we have a date of creation, then we can use that
1865 - // to uniquely identify the item. (On the other hand, if
1866 - // the feed producer was consicentious enough to
1867 - // generate dates of creation, she probably also was
1868 - // conscientious enough to generate unique identifiers.)
1869 - if (!is_null(FeedWordPress::date_created($item))) :
1870 - $guid .= '://post.'.date('YmdHis', FeedWordPress::date_created($item));
1871 -
1872 - // Otherwise, use both the URI of the item, *and* the
1873 - // item's title. We have to use both because titles are
1874 - // often not unique, and sometimes links aren't unique
1875 - // either (e.g. Bitch (S)HITLIST, Mozilla Dot Org news,
1876 - // some podcasts). But it's rare to have *both* the same
1877 - // title *and* the same link for two different items. So
1878 - // this is about the best we can do.
1879 - else :
1880 - $guid .= '://'.md5($item['link'].'/'.$item['title']);
1881 - endif;
1882 - endif;
1883 - return $guid;
1884 - }
1885 -
801 +
1886 802 // item_to_post(): convert information from a single item from an
1887 803 // Atom/RSS feed to a post for WordPress's database.
1888 804 //
1889 805 // item_to_post() invokes the syndicated_item filter on each item it
@@ -1896,11 +812,10 @@
1896 812 // we handle lookup/creation of numeric author and category IDs in
1897 813 // add_post()). If you want plugins that have side effects on the posts
1898 814 // database, you should probably hook into the action
1899 815 // post_syndicated_item
1900 - function item_to_post($wpdb, $item, $rss, $f) {
1901 - $channel = $rss->channel;
1902 -
816 + //
817 + function item_to_post($wpdb, $item, $channel, $f) {
1903 818 $post = array();
1904 819
1905 820 // This is ugly as all hell. I'd like to use apply_filters()'s
1906 821 // alleged support for a variable argument count, but this seems
@@ -1910,9 +825,8 @@
1910 825 //
1911 826 // Cf.: <http://mosquito.wordpress.org/view.php?id=901>
1912 827 global $fwp_channel, $fwp_feedmeta;
1913 828 $fwp_channel = $channel; $fwp_feedmeta = $f;
1914 -
1915 829 $item = apply_filters('syndicated_item', $item);
1916 830
1917 831 // Filters can halt further processing by returning NULL
1918 832 if (is_null($item)) :
@@ -1920,48 +834,24 @@
1920 834 else :
1921 835 $post['post_title'] = $wpdb->escape($item['title']);
1922 836
1923 837 $post['named']['author'] = array ();
1924 -
1925 - if (isset($item['author_name'])):
1926 - $post['named']['author']['name'] = $item['author_name'];
838 + if (isset($item['dc']['creator'])):
839 + $post['named']['author']['name'] = $item['dc']['creator'];
1927 840 elseif (isset($item['dc']['creator'])):
1928 - $post['named']['author']['name'] = $item['dc']['creator'];
1929 - elseif (isset($item['dc']['contributor'])):
1930 841 $post['named']['author']['name'] = $item['dc']['contributor'];
1931 - elseif (isset($channel['dc']['creator'])) :
1932 - $post['named']['author']['name'] = $channel['dc']['creator'];
1933 - elseif (isset($channel['dc']['contributor'])) :
1934 - $post['named']['author']['name'] = $channel['dc']['contributor'];
1935 - elseif (isset($channel['author_name'])) :
1936 - $post['named']['author']['name'] = $channel['author_name'];
1937 - elseif ($rss->is_rss() and isset($item['author'])) :
1938 - // The author element in RSS is allegedly an
1939 - // e-mail address, but lots of people don't use
1940 - // it that way. So let's make of it what we can.
1941 - $post['named']['author'] = parse_email_with_realname($item['author']);
1942 -
1943 - if (!isset($post['named']['author']['name'])) :
1944 - if (isset($post['named']['author']['email'])) :
1945 - $post['named']['author']['name'] = $post['named']['author']['email'];
1946 - else :
1947 - $post['named']['author']['name'] = $channel['title'];
1948 - endif;
1949 - endif;
1950 - else :
842 + elseif (isset($item['author_name'])):
843 + $post['named']['author']['name'] = $item['author_name'];
844 + else:
1951 845 $post['named']['author']['name'] = $channel['title'];
1952 846 endif;
1953 847
1954 848 if (isset($item['author_email'])):
1955 849 $post['named']['author']['email'] = $item['author_email'];
1956 - elseif (isset($channel['author_email'])) :
1957 - $post['named']['author']['email'] = $channel['author_email'];
1958 850 endif;
1959 851
1960 852 if (isset($item['author_url'])):
1961 853 $post['named']['author']['uri'] = $item['author_url'];
1962 - elseif (isset($channel['author_url'])) :
1963 - $post['named']['author']['uri'] = $item['author_url'];
1964 854 else:
1965 855 $post['named']['author']['uri'] = $channel['link'];
1966 856 endif;
1967 857
@@ -1971,13 +861,9 @@
1971 861 // FeedWordPress::add_post()
1972 862
1973 863 # Identify content and sanitize it.
1974 864 # ---------------------------------
1975 - if (isset($item['xhtml']['body'])) :
1976 - $content = $item['xhtml']['body'];
1977 - elseif (isset($item['xhtml']['div'])) :
1978 - $content = $item['xhtml']['div'];
1979 - elseif (isset($item['content']['encoded']) and $item['content']['encoded']):
865 + if (isset($item['content']['encoded']) and $item['content']['encoded']):
1980 866 $content = $item['content']['encoded'];
1981 867 else:
1982 868 $content = $item['description'];
1983 869 endif;
@@ -1988,9 +874,9 @@
1988 874 # any way to get that information out of MagpieRSS if it's
1989 875 # in the feed, and if it's in the content itself we'd have
1990 876 # to do yet more XML parsing to do things right. For now
1991 877 # this will have to do.
1992 -
878 +
1993 879 $this->_base = $item['link']; // Reset the base for resolving relative URIs
1994 880 foreach ($this->uri_attrs as $pair):
1995 881 list($tag,$attr) = $pair;
1996 882 $content = preg_replace_callback (
@@ -2030,9 +916,9 @@
2030 916 # This is unneeded if wp_insert_post can be used.
2031 917 # --- cut here ---
2032 918 $post['post_name'] = sanitize_title($post['post_title']);
2033 919 # --- cut here ---
2034 -
920 +
2035 921 # RSS is a fucking mess. Figure out whether we have a date in
2036 922 # dc:date, <issued>, <pubDate>, etc., and get it into Unix epoch
2037 923 # format for reformatting. If you can't find anything, use the
2038 924 # current time.
@@ -2037,34 +923,21 @@
2037 923 # format for reformatting. If you can't find anything, use the
2038 924 # current time.
2039 925 if (isset($item['dc']['date'])):
2040 926 $post['epoch']['issued'] = parse_w3cdtf($item['dc']['date']);
2041 - elseif (isset($item['dcterms']['issued'])) :
2042 - $post['epoch']['issued'] = parse_w3cdtf($item['dcterms']['issued']);
2043 - elseif (isset($item['published'])) : // Atom 1.0
2044 - $post['epoch']['issued'] = parse_w3cdtf($item['published']);
2045 - elseif (isset($item['issued'])): // Atom 0.3
927 + elseif (isset($item['issued'])):
2046 928 $post['epoch']['issued'] = parse_w3cdtf($item['issued']);
2047 - elseif (isset($item['pubdate'])): // RSS 2.0
929 + elseif (isset($item['pubdate'])):
2048 930 $post['epoch']['issued'] = strtotime($item['pubdate']);
2049 931 else:
2050 932 $post['epoch']['issued'] = time();
2051 933 endif;
2052 934
2053 - # And again, for the created date
2054 - $post['epoch']['created'] = FeedWordPress::date_created($item);
2055 -
2056 935 # As far as I know, only atom currently has a reliable way to
2057 936 # specify when something was *modified* last
2058 - if (isset($item['dc']['modified'])) : // Not really correct
2059 - $post['epoch']['modified'] = @parse_w3cdtf($item['dc']['modified']);
2060 - elseif (isset($item['dcterms']['modified'])) : // Dublin Core extensions
2061 - $post['epoch']['modified'] = @parse_w3cdtf($item['dcterms']['modified']);
2062 - elseif (isset($item['modified'])): // Atom 0.3
2063 - $post['epoch']['modified'] = @parse_w3cdtf($item['modified']);
2064 - elseif (isset($item['updated'])): // Atom 1.0
2065 - $post['epoch']['modified'] = @parse_w3cdtf($item['updated']);
2066 - else : // Fall back to issued / dc:date
937 + if (isset($item['modified'])):
938 + $post['epoch']['modified'] = parse_w3cdtf($item['modified']);
939 + else:
2067 940 $post['epoch']['modified'] = $post['epoch']['issued'];
2068 941 endif;
2069 942
2070 943 $post['post_date'] = date('Y-m-d H:i:s', $post['epoch']['issued']);
@@ -2070,67 +943,43 @@
2070 943 $post['post_date'] = date('Y-m-d H:i:s', $post['epoch']['issued']);
2071 944 $post['post_modified'] = date('Y-m-d H:i:s', $post['epoch']['modified']);
2072 945 $post['post_date_gmt'] = gmdate('Y-m-d H:i:s', $post['epoch']['issued']);
2073 946 $post['post_modified_gmt'] = gmdate('Y-m-d H:i:s', $post['epoch']['modified']);
2074 -
2075 - # Use feed-level preferences or the global default.
2076 - $post['post_status'] = FeedWordPress::syndicated_status('post', $f, 'publish');
2077 - $post['comment_status'] = FeedWordPress::syndicated_status('comment', $f, 'closed');
2078 - $post['ping_status'] = FeedWordPress::syndicated_status('ping', $f, 'closed');
2079 -
947 +
948 + # Use feed-level preferences or a sensible default.
949 + $post['post_status'] = (isset($f['post status']) ? $wpdb->escape(trim(strtolower($f['post status']))) : 'publish');
950 + $post['comment_status'] = (isset($f['comment status']) ? $wpdb->escape(trim(strtolower($f['comment status']))) : 'closed');
951 + $post['ping_status'] = (isset($f['ping status']) ? $wpdb->escape(trim(strtolower($f['ping status']))) : 'closed');
952 +
2080 953 // Unique ID (hopefully a unique tag: URI); failing that, the permalink
2081 - $post['guid'] = $wpdb->escape(FeedWordPress::guid($item, $f));
2082 -
2083 - // RSS 2.0 / Atom 1.0 enclosure support
2084 - if ( isset($item['enclosure#']) ) :
2085 - for ($i = 1; $i <= $item['enclosure#']; $i++) :
2086 - $eid = (($i > 1) ? "#{$id}" : "");
2087 - $post['meta']['enclosure'][] =
2088 - $item["enclosure{$eid}@url"]."\n".
2089 - $item["enclosure{$eid}@length"]."\n".
2090 - $item["enclosure{$eid}@type"];
2091 - endfor;
954 + if (isset($item['id'])):
955 + $post['guid'] = $wpdb->escape($item['id']);
956 + else:
957 + $post['guid'] = $wpdb->escape($item['link']);
2092 958 endif;
2093 -
2094 - // In case you want to point back to the blog this was syndicated from
2095 - if (isset($channel['title'])) $post['meta']['syndication_source'] = $channel['title'];
2096 - if (isset($channel['link'])) $post['meta']['syndication_source_uri'] = $channel['link'];
2097 -
2098 - // Store information on human-readable and machine-readable comment URIs
2099 - if (isset($item['comments'])) : $post['meta']['rss:comments'] = $item['comments']; endif;
2100 - if (isset($item['wfw']['commentrss'])) : $post['meta']['wfw:commentRSS'] = $item['wfw']['commentrss']; endif;
2101 -
2102 - // Store information to identify the feed that this came from
2103 - $post['meta']['syndication_feed'] = $f['link/uri'];
2104 - $post['meta']['syndication_feed_id'] = $f['link/id'];
2105 -
959 +
960 + if (isset($channel['title'])) $post['syndication_source'] = $channel['title'];
961 + if (isset($channel['link'])) $post['syndication_source_uri'] = $channel['link'];
962 + $post['syndication_feed'] = $f['uri'];
963 +
2106 964 // In case you want to know the external permalink...
2107 - $post['meta']['syndication_permalink'] = $item['link'];
965 + $post['syndication_permalink'] = $item['link'];
2108 966
2109 - // Feed-by-feed options for author and category creation
2110 - $post['named']['unfamiliar']['author'] = $f['unfamiliar author'];
2111 - $post['named']['unfamiliar']['category'] = $f['unfamiliar categories'];
2112 -
2113 967 // Categories: start with default categories
2114 - $fc = get_settings("feedwordpress_syndication_cats");
2115 - if ($fc) : $post['named']['preset/category'] = explode("\n", $fc);
2116 - else : $post['named']['preset/category'] = array();
2117 - endif;
2118 - $post['named']['preset/category'] = array_merge($post['named']['preset/category'], $f['cats']);
968 + $post['named']['category'] = $f['cats'];
2119 969
2120 970 // Now add categories from the post, if we have 'em
2121 - $post['named']['category'] = array();
2122 - if ( isset($item['category#']) ) :
2123 - for ($i = 1; $i <= $item['category#']; $i++) :
2124 - $cat_idx = (($i > 1) ? "#{$i}" : "");
2125 - $cat = $item["category{$cat_idx}"];
2126 -
2127 - if ( strpos($f['link/uri'], 'del.icio.us') !== false ):
971 + if (
972 + !FeedWordPress::setting_on($f, 'hardcode categories')
973 + and is_array($item['categories'])
974 + ):
975 + foreach ($item['categories'] as $cat):
976 + if ( strpos($f['uri'], 'del.icio.us') !== false ):
2128 977 $post['named']['category'] = array_merge($post['named']['category'], explode(' ', $cat));
2129 978 else:
2130 979 $post['named']['category'][] = $cat;
2131 980 endif;
2132 - endfor;
981 + endforeach;
2133 982 endif;
2134 983 endif;
2135 984 return $post;
2136 985 } // function FeedWordPress::item_to_post ()
@@ -2141,13 +990,13 @@
2141 990 SELECT id, guid, UNIX_TIMESTAMP(post_modified) AS modified
2142 991 FROM $wpdb->posts WHERE guid='$guid'
2143 992 ");
2144 993
2145 - if (!$result) :
994 + if (!$result):
2146 995 $freshness = 2; // New content
2147 - elseif ($post['epoch']['modified'] > $result->modified) :
996 + elseif ($post['epoch']['modified'] > $result->modified):
2148 997 $freshness = 1; // Updated content
2149 - else :
998 + else:
2150 999 $freshness = 0;
2151 1000 endif;
2152 1001
2153 1002 if ($freshness > 0) :
@@ -2155,44 +1004,23 @@
2155 1004 $post['post_author'] = $this->author_to_id (
2156 1005 $wpdb,
2157 1006 $post['named']['author']['name'],
2158 1007 $post['named']['author']['email'],
2159 - $post['named']['author']['uri'],
2160 - FeedWordPress::on_unfamiliar('author', $post['named']['unfamiliar']['author'])
1008 + $post['named']['author']['uri']
2161 1009 );
2162 -
2163 - if (is_null($post['post_author'])) :
2164 - $freshness = 0;
2165 - else :
2166 - # -- Look up, or create, numeric ID for categories
2167 - $post['post_category'] = $this->lookup_categories (
2168 - $wpdb,
2169 - $post['named']['category'],
2170 - FeedWordPress::on_unfamiliar('category', $post['named']['unfamiliar']['category'])
2171 - );
2172 -
2173 - if (is_null($post['post_category'])) : // filter mode on, no matching categories; drop the post
2174 - $freshness = 0;
2175 - else : // filter mode off or at least one match; now add on the feed and global presets
2176 - $post['post_category'] = array_merge (
2177 - $post['post_category'],
2178 - $this->lookup_categories (
2179 - $wpdb,
2180 - $post['named']['preset/category'],
2181 - 'default'
2182 - )
2183 - );
2184 - endif;
2185 - endif;
2186 1010
1011 + # -- Look up, or create, numeric ID for categories
1012 + $post['post_category'] = $this->lookup_categories (
1013 + $wpdb,
1014 + $post['named']['category']
1015 + );
1016 +
2187 1017 unset($post['named']);
2188 1018 endif;
2189 1019
2190 - if ($freshness > 0) :
2191 - $post = apply_filters('syndicated_post', $post);
2192 - if (is_null($post)) $freshness = 0;
2193 - endif;
2194 -
1020 + $post = apply_filters('syndicated_post', $post);
1021 + if (is_null($post)) $freshness = 0;
1022 +
2195 1023 if ($freshness == 2) :
2196 1024 // The item has not yet been added. So let's add it.
2197 1025
2198 1026 # The right way to do this would be to use:
@@ -2271,13 +1099,13 @@
2271 1099 // able to use).
2272 1100 do_action('edit_post', $postId);
2273 1101
2274 1102 $this->add_rss_meta($wpdb, $postId, $post);
2275 -
1103 +
2276 1104 do_action('update_syndicated_item', $postId);
2277 1105
2278 1106 $ret = 'updated';
2279 - else :
1107 + else:
2280 1108 $ret = false;
2281 1109 endif;
2282 1110
2283 1111 return $ret;
@@ -2308,185 +1136,119 @@
2308 1136 endforeach;
2309 1137 } // function FeedWordPress::add_to_category ()
2310 1138 # --- cut here ---
2311 1139
2312 - // FeedWordPress::add_rss_meta: adds interesting meta-data to each entry
2313 - // using the space for custom keys. The set of keys and values to add is
2314 - // specified by the keys and values of $post['meta']. This is used to
2315 - // store anything that the WordPress user might want to access from a
2316 - // template concerning the post's original source that isn't provided
2317 - // for by standard WP meta-data (i.e., any interesting data about the
2318 - // syndicated post other than author, title, timestamp, categories, and
2319 - // guid). It's also used to hook into WordPress's support for
2320 - // enclosures.
1140 + // FeedWordPress::add_rss_meta: adds feed meta-data to user-defined keys
1141 + // for each entry. Interesting feed meta-data is tagged in the $post
1142 + // array using the prefix 'syndication_'. This should be used for
1143 + // anything that the WordPress user might want to access about a post's
1144 + // original source that isn't provided for by standard WP meta-data
1145 + // (i.e., beyond author, title, timestamp, and categories)
2321 1146 function add_rss_meta ($wpdb, $postId, $post) {
2322 - if ( is_array($post) and isset($post['meta']) and is_array($post['meta']) ) :
2323 - foreach ( $post['meta'] as $key => $values ) :
1147 + foreach ($post as $key => $value):
1148 + if (strpos($key, "syndication_") === 0):
1149 + $value = $wpdb->escape($value);
2324 1150
2325 - $key = $wpdb->escape($key);
2326 -
2327 - // If this is an update, clear out the old
2328 - // values to avoid duplication.
2329 1151 $result = $wpdb->query("
2330 1152 DELETE FROM $wpdb->postmeta
2331 1153 WHERE post_id='$postId' AND meta_key='$key'
2332 1154 ");
2333 1155
2334 - // Allow for either a single value or an array
2335 - if (!is_array($values)) $values = array($values);
2336 - foreach ( $values as $value ) :
2337 - $value = $wpdb->escape($value);
2338 - $result = $wpdb->query("
2339 - INSERT INTO $wpdb->postmeta
2340 - SET
2341 - post_id='$postId',
2342 - meta_key='$key',
2343 - meta_value='$value'
2344 - ");
2345 - endforeach;
2346 - endforeach;
2347 - endif;
1156 + $result = $wpdb->query("
1157 + INSERT INTO $wpdb->postmeta
1158 + SET
1159 + post_id='$postId',
1160 + meta_key='$key',
1161 + meta_value='$value'
1162 + ");
1163 + endif;
1164 + endforeach;
2348 1165 } /* FeedWordPress::add_rss_meta () */
2349 1166
2350 1167 // FeedWordPress::author_to_id (): get the ID for an author name from
2351 1168 // the feed. Create the author if necessary.
2352 - function author_to_id ($wpdb, $author, $email, $url, $unfamiliar_author = 'create') {
1169 + function author_to_id ($wpdb, $author, $email, $url) {
2353 1170 // Never can be too careful...
2354 1171 $nice_author = sanitize_title($author);
2355 - $reg_author = $wpdb->escape(preg_quote($author));
2356 1172 $author = $wpdb->escape($author);
2357 1173 $email = $wpdb->escape($email);
2358 1174 $url = $wpdb->escape($url);
2359 -
1175 +
2360 1176 $id = $wpdb->get_var(
2361 - "SELECT ID from $wpdb->users
2362 - WHERE
2363 - TRIM(LCASE(user_login)) = TRIM(LCASE('$author')) OR
2364 - TRIM(LCASE(user_firstname)) = TRIM(LCASE('$author')) OR
2365 - TRIM(LCASE(user_nickname)) = TRIM(LCASE('$author')) OR
2366 - TRIM(LCASE(user_nicename)) = TRIM(LCASE('$nice_author')) OR
2367 - TRIM(LCASE(user_description)) = TRIM(LCASE('$author')) OR
2368 - (
2369 - LOWER(user_description)
2370 - RLIKE CONCAT(
2371 - '(^|\\n)a.k.a.( |\\t)*:?( |\\t)*',
2372 - LCASE('$reg_author'),
2373 - '( |\\t|\\r)*(\\n|\$)'
2374 - )
2375 - )
2376 - ");
2377 -
2378 - if (is_null($id)) :
2379 - if ($unfamiliar_author === 'create') :
2380 - $wpdb->query (
2381 - "INSERT INTO $wpdb->users
2382 - SET
2383 - ID='0',
2384 - user_login='$author',
2385 - user_firstname='$author',
2386 - user_nickname='$author',
2387 - user_nicename='$nice_author',
2388 - user_description='$author',
2389 - user_email='$email',
2390 - user_url='$url'");
2391 - $id = $wpdb->insert_id;
2392 - elseif ($unfamiliar_author === 'default') :
2393 - $id = 1;
2394 - endif;
1177 + "SELECT ID from $wpdb->users
1178 + WHERE
1179 + user_login = '$author' OR
1180 + user_firstname = '$author' OR
1181 + user_nickname = '$author' OR
1182 + user_description = '$author' OR
1183 + user_nicename = '$nice_author'");
1184 +
1185 + if (is_null($id)):
1186 + $wpdb->query (
1187 + "INSERT INTO $wpdb->users
1188 + SET
1189 + ID='0',
1190 + user_login='$author',
1191 + user_firstname='$author',
1192 + user_nickname='$author',
1193 + user_nicename='$nice_author',
1194 + user_description='$author',
1195 + user_email='$email',
1196 + user_url='$url'");
1197 + $id = $wpdb->insert_id;
2395 1198 endif;
2396 1199 return $id;
2397 1200 } // function FeedWordPress::author_to_id ()
2398 -
1201 +
2399 1202 // look up (and create) category ids from a list of categories
2400 - function lookup_categories ($wpdb, $cats, $unfamiliar_category = 'create') {
2401 - // Normalize whitespace because (1) trailing whitespace can
2402 - // cause PHP and MySQL not to see eye to eye on VARCHAR
2403 - // comparisons for some versions of MySQL (cf.
2404 - // <http://dev.mysql.com/doc/mysql/en/char.html>), and (2)
2405 - // because I doubt most people want to make a semantic
2406 - // distinction between 'Computers' and 'Computers '
2407 - $cats = array_map('trim', $cats);
2408 -
1203 + function lookup_categories ($wpdb, $cats) {
2409 1204 $cat_ids = array ();
2410 -
2411 1205 if ( count($cats) > 0 ) :
2412 1206 # i'd kill for a decent map function in PHP
2413 1207 # but that would require functions to be first class object,
2414 1208 # or at least coderef support
2415 - $cat_str = array ();
2416 - $cat_aka = array ();
1209 + $cat_strs = array();
1210 + $cat_aka = array();
2417 1211 foreach ( $cats as $c ) :
2418 - $resc = $wpdb->escape(preg_quote($c));
2419 - $esc = $wpdb->escape($c);
2420 - $cat_str[] = "'$esc'";
2421 -
2422 - $cat_aka[] = "(LOWER(category_description)
2423 - RLIKE CONCAT('(^|\n)a.k.a.( |\t)*:?( |\t)*', LOWER('{$resc}'), '( |\t|\r)*(\n|\$)'))";
1212 + $esc = $wpdb->escape(trim($c));
1213 + $cat_strs[] = "'$esc'";
1214 + $cat_aka[] = "(LOWER(category_description) RLIKE '(^|\n)a.k.a.( |\t)*:?( |\t)*".strtolower($esc)."( |\t|\r)*(\n|\$)')";
2424 1215 endforeach;
2425 1216
2426 - $match_cat_name = 'cat_name IN ('.join(',', $cat_str).')';
2427 - $match_cat_alias = join(' OR ', $cat_aka);
1217 + $cat_sql = join(',', $cat_strs);
1218 + $cat_akas = join(' OR ', $cat_aka);
2428 1219
2429 - $results = $wpdb->get_results(
2430 - "SELECT
2431 - cat_ID,
2432 - cat_name,
2433 - category_description
2434 - FROM $wpdb->categories
2435 - WHERE ($match_cat_name) OR ($match_cat_alias)"
2436 - );
1220 + $sql = "SELECT cat_ID,cat_name,category_description from $wpdb->categories
1221 + WHERE cat_name IN ($cat_sql)
1222 + OR ($cat_akas)";
1223 + $results = $wpdb->get_results($sql);
2437 1224
2438 - $cat_ids = array();
2439 - $found = array();
1225 + $cat_ids = array();
1226 + $cat_found = array();
2440 1227
2441 1228 if (!is_null($results)):
2442 1229 foreach ( $results as $row ) :
2443 - // Add existing ID to list of numerical
2444 - // IDs to eventually place post in
2445 1230 $cat_ids[] = $row->cat_ID;
1231 + $cat_found[] = strtolower($row->cat_name); // Normalize to avoid case problems
2446 1232
2447 - // Add name to list of categories not to
2448 - // create afresh. Normalizing case with
2449 - // strtolower() avoids mismatches in
2450 - // VARCHAR comparison between PHP (which
2451 - // has case-sensitive comparisons) and
2452 - // MySQL (which has case-insensitive
2453 - // comparisons for the field types used
2454 - // by WordPress)
2455 - $found[] = strtolower(trim($row->cat_name));
2456 -
2457 - // Add name of any aliases to list of
2458 - // categories not to create afresh.
2459 1233 if (preg_match_all('/^a.k.a. \s* :? \s* (.*\S) \s*$/mx',
2460 1234 $row->category_description, $aka,
2461 1235 PREG_PATTERN_ORDER)) :
2462 - $found = array_merge (
2463 - $found,
2464 - array_map('strtolower',
2465 - array_map('trim',
2466 - $aka[1]
2467 - ))
2468 - );
1236 + $cat_found = array_merge($cat_found,
1237 + array_map('strtolower', $aka[1]));
2469 1238 endif;
2470 1239 endforeach;
2471 1240 endif;
2472 1241
2473 1242 foreach ($cats as $new_cat) :
2474 - if (($unfamiliar_category==='create') and !in_array(strtolower($new_cat), $found)) :
1243 + $sql = "INSERT INTO $wpdb->categories (cat_name, category_nicename)
1244 + VALUES ('%s', '%s')";
1245 + if (!in_array(strtolower($new_cat), $cat_found)):
2475 1246 $nice_cat = sanitize_title($new_cat);
2476 - $wpdb->query(sprintf("
2477 - INSERT INTO $wpdb->categories
2478 - SET
2479 - cat_name='%s',
2480 - category_nicename='%s'
2481 - ", $wpdb->escape($new_cat), $nice_cat));
1247 + $wpdb->query(sprintf($sql, $wpdb->escape($new_cat), $nice_cat));
2482 1248 $cat_ids[] = $wpdb->insert_id;
2483 1249 endif;
2484 1250 endforeach;
2485 -
2486 - if ((count($cat_ids) == 0) and ($unfamiliar_category === 'filter')) :
2487 - $cat_ids = NULL; // Drop the post
2488 - endif;
2489 1251 endif;
2490 1252 return $cat_ids;
2491 1253 } // function FeedWordPress::lookup_categories ()
2492 1254
@@ -2492,23 +1254,9 @@
2492 1254
2493 1255 function rpc_secret () {
2494 1256 return get_settings('feedwordpress_rpc_secret');
2495 1257 } // function FeedWordPress::rpc_secret ()
2496 -
2497 - function on_unfamiliar ($what = 'author', $override = NULL) {
2498 - $set = array('create', 'default', 'filter');
2499 -
2500 - $ret = strtolower($override);
2501 - if (!in_array($ret, $set)) :
2502 - $ret = get_settings('feedwordpress_unfamiliar_'.$what);
2503 - if (!in_array($ret, $set)) :
2504 - $ret = 'create';
2505 - endif;
2506 - endif;
2507 -
2508 - return $ret;
2509 - } // function FeedWordPress::on_unfamiliar()
2510 -
1258 +
2511 1259 function link_category_id () {
2512 1260 global $wpdb;
2513 1261
2514 1262 $cat_id = get_settings('feedwordpress_cat_id');
@@ -2555,75 +1303,11 @@
2555 1303 WHERE cat_id='$cat_id'
2556 1304 ");
2557 1305 return $cat_name;
2558 1306 }
2559 -
2560 - function upgrade_database ($from = NULL) {
2561 - global $wpdb;
2562 -
2563 - if (is_null($from) or $from <= 0.96) : $from = 0.96; endif;
2564 -
2565 - switch ($from) :
2566 - case 0.96: // account for changes to syndication custom values and guid
2567 - echo "<p>Upgrading database from {$from} to 0.97...</p>\n";
2568 -
2569 - $cat_id = FeedWordPress::link_category_id();
2570 -
2571 - // Avoid duplicates
2572 - $wpdb->query("DELETE FROM `{$wpdb->postmeta}` WHERE meta_key = 'syndication_feed_id'");
2573 -
2574 - // Look up all the link IDs
2575 - $wpdb->query("
2576 - CREATE TEMPORARY TABLE tmp_custom_values
2577 - SELECT
2578 - NULL AS meta_id,
2579 - post_id,
2580 - 'syndication_feed_id' AS meta_key,
2581 - link_id AS meta_value
2582 - FROM `{$wpdb->postmeta}`, `{$wpdb->links}`
2583 - WHERE
2584 - meta_key='syndication_feed'
2585 - AND meta_value=link_rss
2586 - AND link_category = {$cat_id}
2587 - ");
2588 -
2589 - // Now attach them to their posts
2590 - $wpdb->query("INSERT INTO `{$wpdb->postmeta}` SELECT * FROM tmp_custom_values");
2591 -
2592 - // And clean up after ourselves.
2593 - $wpdb->query("DROP TABLE tmp_custom_values");
2594 -
2595 - // Now fix the guids to avoid duplicate posts
2596 - echo "<ul>";
2597 - foreach ($this->feeds as $feed) :
2598 - echo "<li>Fixing post meta-data for <cite>".$feed['link/name']."</cite> &#8230; "; flush();
2599 - $rss = @fetch_rss($feed['link/uri']);
2600 - if (is_array($rss->items)) :
2601 - foreach ($rss->items as $item) :
2602 - $guid = $wpdb->escape(FeedWordPress::guid($item, $feed)); // new GUID algorithm
2603 - $link = $wpdb->escape($item['link']);
2604 -
2605 - $wpdb->query("
2606 - UPDATE `{$wpdb->posts}` SET guid='{$guid}' WHERE guid='{$link}'
2607 - ");
2608 - endforeach;
2609 - endif;
2610 - echo "<strong>complete.</strong></li>\n";
2611 - endforeach;
2612 - echo "</ul>\n";
2613 -
2614 - // Mark the upgrade as successful.
2615 - update_option('feedwordpress_version', FEEDWORDPRESS_VERSION);
2616 - endswitch;
2617 - echo "<p>Upgrade complete. FeedWordPress is now ready to use again.</p>";
2618 - } /* FeedWordPress::upgrade_database() */
2619 -
2620 1307 } // class FeedWordPress
2621 1308
2622 -################################################################################
2623 -## XML-RPC HOOKS: accept XML-RPC update pings from Contributors ################
2624 -################################################################################
2625 -
1309 +# -- Inbound XML-RPC plugin interface
2626 1310 function feedwordpress_xmlrpc_hook ($args = array ()) {
2627 1311 $args['weblogUpdates.ping'] = 'feedwordpress_pong';
2628 1312 return $args;
2629 1313 }
@@ -2641,12 +1325,8 @@
2641 1325 return array('flerror' => false, 'message' => "Thanks for the ping.".implode(' and', $mesg));
2642 1326 endif;
2643 1327 }
2644 1328
2645 -################################################################################
2646 -## class FeedFinder: find likely feeds using autodetection and/or guesswork ####
2647 -################################################################################
2648 -
2649 1329 class FeedFinder {
2650 1330 var $uri = NULL;
2651 1331 var $_cache_uri = NULL;
2652 1332
@@ -2975,32 +1655,5 @@
2975 1655 // remove any character outside the hex range: 21 - 7E (see www.asciitable.com)
2976 1656 return preg_replace('/[^\x21-\x7e]/', '', $encoded);
2977 1657 }
2978 1658 }
2979 -
2980 -// take your best guess at the realname and e-mail, given a string
2981 -define('FWP_REGEX_EMAIL_ADDY', '([^@"(<\s]+@[^"@(<\s]+\.[^"@(<\s]+)');
2982 -define('FWP_REGEX_EMAIL_NAME', '("([^"]*)"|([^"<(]+\S))');
2983 -define('FWP_REGEX_EMAIL_POSTFIX_NAME', "/^\s*".FWP_REGEX_EMAIL_ADDY."\s+\(".FWP_REGEX_EMAIL_NAME."\)\s*$/");
2984 -define('FWP_REGEX_EMAIL_PREFIX_NAME', "/^\s*".FWP_REGEX_EMAIL_NAME."\s*<".FWP_REGEX_EMAIL_ADDY.">\s*$/");
2985 -define('FWP_REGEX_EMAIL_JUST_ADDY', "/^\s*".FWP_REGEX_EMAIL_ADDY."\s*$/");
2986 -define('FWP_REGEX_EMAIL_JUST_NAME', "/^\s*".FWP_REGEX_EMAIL_NAME."\s*$/");
2987 -
2988 -function parse_email_with_realname ($email) {
2989 - if (preg_match(FWP_REGEX_EMAIL_POSTFIX_NAME, $email, $matches)) :
2990 - ($ret['name'] = $matches[3]) or ($ret['name'] = $matches[2]);
2991 - $ret['email'] = $matches[1];
2992 - elseif (preg_match(FWP_REGEX_EMAIL_PREFIX_NAME, $email, $matches)) :
2993 - ($ret['name'] = $matches[2]) or ($ret['name'] = $matches[3]);
2994 - $ret['email'] = $matches[4];
2995 - elseif (preg_match(FWP_REGEX_EMAIL_JUST_ADDY, $email, $matches)) :
2996 - $ret['name'] = NULL; $ret['email'] = $matches[1];
2997 - elseif (preg_match(FWP_REGEX_EMAIL_JUST_NAME, $email, $matches)) :
2998 - $ret['email'] = NULL;
2999 - ($ret['name'] = $matches[2]) or ($ret['name'] = $matches[3]);
3000 - else :
3001 - $ret['name'] = NULL; $ret['email'] = NULL;
3002 - endif;
3003 - return $ret;
3004 -}
3005 -
3006 1659 ?>