PluginProbe
FeedWordPress / 2008.1105
FeedWordPress v2008.1105
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 | feedwordpress.php +298 -112 2008.10302008.1105 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: 2008.1030
6 +Version: 2008.1105
7 7 Author: Charles Johnson
8 8 Author URI: http://radgeek.com/
9 9 License: GPL
10 -Last modified: 2008-10-30 4:14pm PDT
10 +Last modified: 2008-11-05 4:35pm PST
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,9 +26,9 @@
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
30 -define ('FEEDWORDPRESS_VERSION', '2008.1030');
30 +define ('FEEDWORDPRESS_VERSION', '2008.1105');
31 31 define ('FEEDWORDPRESS_AUTHOR_CONTACT', 'http://radgeek.com/contact');
32 32 define ('DEFAULT_SYNDICATION_CATEGORY', 'Contributors');
33 33
34 34 define ('FEEDWORDPRESS_DEBUG', false);
@@ -39,8 +39,9 @@
39 39 define ('FEEDVALIDATOR_URI', 'http://feedvalidator.org/check.cgi');
40 40
41 41 define ('FEEDWORDPRESS_FRESHNESS_INTERVAL', 10*60); // Every ten minutes
42 42
43 +define ('FWP_SCHEMA_HAS_USERMETA', 2966);
43 44 define ('FWP_SCHEMA_20', 3308); // Database schema # for WP 2.0
44 45 define ('FWP_SCHEMA_21', 4772); // Database schema # for WP 2.1
45 46 define ('FWP_SCHEMA_23', 5495); // Database schema # for WP 2.3
46 47 define ('FWP_SCHEMA_25', 7558); // Database schema # for WP 2.5
@@ -248,17 +249,80 @@
248 249 ################################################################################
249 250
250 251 function is_syndicated () { return (strlen(get_syndication_feed_id()) > 0); }
251 252
252 -function the_syndication_source_link () { echo get_syndication_source_link(); }
253 -function get_syndication_source_link () { list($n) = get_post_custom_values('syndication_source_uri'); return $n; }
253 +function get_syndication_source_link ($original = NULL) {
254 + if (is_null($original)) : $original = FeedWordPress::use_aggregator_source_data();
255 + endif;
254 256
255 -function get_syndication_source () { list($n) = get_post_custom_values('syndication_source'); return $n; }
256 -function the_syndication_source () { echo get_syndication_source(); }
257 + if ($original) : $vals = get_post_custom_values('syndication_source_uri_original');
258 + else : $vals = array();
259 + endif;
260 +
261 + if (count($vals) == 0) : $vals = get_post_custom_values('syndication_source_uri');
262 + endif;
263 +
264 + if (count($vals) > 0) : $ret = $vals[0]; else : $ret = NULL; endif;
257 265
258 -function get_syndication_feed () { list($u) = get_post_custom_values('syndication_feed'); return $u; }
259 -function the_syndication_feed () { echo get_syndication_feed (); }
266 + return $ret;
267 +} /* function get_syndication_source_link() */
260 268
269 +function the_syndication_source_link ($original = NULL) { echo get_syndication_source_link($original); }
270 +
271 +function get_syndication_source ($original = NULL) {
272 + if (is_null($original)) : $original = FeedWordPress::use_aggregator_source_data();
273 + endif;
274 +
275 + if ($original) : $vals = get_post_custom_values('syndication_source_original');
276 + else : $vals = array();
277 + endif;
278 +
279 + if (count($vals) == 0) : $vals = get_post_custom_values('syndication_source');
280 + endif;
281 +
282 + if (count($vals) > 0) : $ret = $vals[0]; else : $ret = NULL; endif;
283 +
284 + return $ret;
285 +} /* function get_syndication_source() */
286 +
287 +function the_syndication_source ($original = NULL) { echo get_syndication_source($original); }
288 +
289 +function get_syndication_feed ($original = NULL) {
290 + if (is_null($original)) : $original = FeedWordPress::use_aggregator_source_data();
291 + endif;
292 +
293 + if ($original) : $vals = get_post_custom_values('syndication_feed_original');
294 + else : $vals = array();
295 + endif;
296 +
297 + if (count($vals) == 0) : $vals = get_post_custom_values('syndication_feed');
298 + endif;
299 +
300 + if (count($vals) > 0) : $ret = $vals[0]; else : $ret = NULL; endif;
301 +
302 + return $ret;
303 +} /* function get_syndication_feed() */
304 +
305 +function the_syndication_feed ($original = NULL) { echo get_syndication_feed ($original); }
306 +
307 +function get_syndication_feed_guid ($original = NULL) {
308 + if (is_null($original)) : $original = FeedWordPress::use_aggregator_source_data();
309 + endif;
310 +
311 + if ($original) : $vals = get_post_custom_values('syndication_source_id_original');
312 + else : $vals = array();
313 + endif;
314 +
315 + if (count($vals) == 0) : $vals = array(get_feed_meta('feed/id'));
316 + endif;
317 +
318 + if (count($vals) > 0) : $ret = $vals[0]; else : $ret = NULL; endif;
319 +
320 + return $ret;
321 +} /* function get_syndication_feed_guid () */
322 +
323 +function the_syndication_feed_guid ($original = NULL) { echo get_syndication_feed_guid($original); }
324 +
261 325 function get_syndication_feed_id () { list($u) = get_post_custom_values('syndication_feed_id'); return $u; }
262 326 function the_syndication_feed_id () { echo get_syndication_feed_id(); }
263 327
264 328 $feedwordpress_linkcache = array (); // only load links from database once
@@ -323,9 +387,9 @@
323 387 <title><?php the_syndication_source(); ?></title>
324 388 <link rel="alternate" type="text/html" href="<?php the_syndication_source_link(); ?>" />
325 389 <link rel="self" href="<?php the_syndication_feed(); ?>" />
326 390 <?php
327 - $id = get_feed_meta('feed/id');
391 + $id = get_syndication_feed_guid();
328 392 if (strlen($id) > 0) :
329 393 ?>
330 394 <id><?php print $id; ?></id>
331 395 <?php
@@ -358,8 +422,9 @@
358 422 global $fwp_capability;
359 423 global $fwp_path;
360 424
361 425 add_menu_page('Syndicated Sites', 'Syndication', $fwp_capability['manage_links'], $fwp_path.'/syndication.php');
426 + add_submenu_page($fwp_path.'/syndication.php', 'Syndicated Authors', 'Authors', $fwp_capability['manage_options'], $fwp_path.'/authors.php');
362 427 add_submenu_page($fwp_path.'/syndication.php', 'Syndication Options', 'Options', $fwp_capability['manage_options'], $fwp_path.'/syndication-options.php');
363 428 add_options_page('Syndication Options', 'Syndication', $fwp_capability['manage_options'], $fwp_path.'/syndication-options.php');
364 429 } // function fwp_add_pages () */
365 430
@@ -517,9 +582,9 @@
517 582 #
518 583 # * Updates to existing posts since the last poll are mirrored in the
519 584 # WordPress store.
520 585 #
521 - function update ($uri = null) {
586 + function update ($uri = null, $crash_ts = null) {
522 587 global $wpdb;
523 588
524 589 if (FeedWordPress::needs_upgrade()) : // Will make duplicate posts if we don't hold off
525 590 return NULL;
@@ -532,11 +597,28 @@
532 597 endif;
533 598
534 599 do_action('feedwordpress_update', $uri);
535 600
601 + if (is_null($crash_ts)) :
602 + $crash_dt = (int) get_option('feedwordpress_update_time_limit');
603 + if ($crash_dt > 0) :
604 + $crash_ts = time() + $crash_dt;
605 + else :
606 + $crash_ts = NULL;
607 + endif;
608 + endif;
609 +
610 + // Randomize order for load balancing purposes
611 + $feed_set = $this->feeds;
612 + shuffle($feed_set);
613 +
536 614 // Loop through and check for new posts
537 615 $delta = NULL;
538 - foreach ($this->feeds as $feed) :
616 + foreach ($feed_set as $feed) :
617 + if (!is_null($crash_ts) and (time() > $crash_ts)) : // Check whether we've exceeded the time limit
618 + break;
619 + endif;
620 +
539 621 $pinged_that = (is_null($uri) or in_array($uri, array($feed->uri(), $feed->homepage())));
540 622
541 623 if (!is_null($uri)) : // A site-specific ping always updates
542 624 $timely = true;
@@ -549,9 +631,12 @@
549 631 endif;
550 632
551 633 if ($pinged_that and $timely) :
552 634 do_action('feedwordpress_check_feed', $feed->settings);
553 - $added = $feed->poll();
635 + $start_ts = time();
636 + $added = $feed->poll($crash_ts);
637 + do_action('feedwordpress_check_feed_complete', $feed->settings, $added, time() - $start_ts);
638 +
554 639 if (isset($added['new'])) : $delta['new'] += $added['new']; endif;
555 640 if (isset($added['updated'])) : $delta['updated'] += $added['updated']; endif;
556 641 endif;
557 642 endforeach;
@@ -646,8 +731,33 @@
646 731
647 732 return $ret;
648 733 } // function FeedWordPress::on_unfamiliar()
649 734
735 + function null_email_set () {
736 + $base = get_option('feedwordpress_null_email_set');
737 +
738 + if ($base===false) :
739 + $ret = array('noreply@blogger.com'); // default
740 + else :
741 + $ret = array_map('strtolower',
742 + array_map('trim', explode("\n", $base)));
743 + endif;
744 + $ret = apply_filters('syndicated_item_author_null_email_set', $ret);
745 + return $ret;
746 +
747 + } /* FeedWordPress::null_email_set () */
748 +
749 + function is_null_email ($email) {
750 + $ret = in_array(strtolower(trim($email)), FeedWordPress::null_email_set());
751 + $ret = apply_filters('syndicated_item_author_is_null_email', $ret, $email);
752 + return $ret;
753 + } /* FeedWordPress::is_null_email () */
754 +
755 + function use_aggregator_source_data () {
756 + $ret = get_option('feedwordpress_use_aggregator_source_data');
757 + return apply_filters('syndicated_post_use_aggregator_source_data', ($ret=='yes'));
758 + }
759 +
650 760 function syndicated_links () {
651 761 $contributors = FeedWordPress::link_category_id();
652 762 if (function_exists('get_bookmarks')) :
653 763 $links = get_bookmarks(array("category" => $contributors));
@@ -805,8 +915,16 @@
805 915 endswitch;
806 916 echo "<p>Upgrade complete. FeedWordPress is now ready to use again.</p>";
807 917 } /* FeedWordPress::upgrade_database() */
808 918
919 + function create_guid_index () {
920 + global $wpdb;
921 +
922 + $wpdb->query("
923 + CREATE INDEX {$wpdb->posts}_guid_idx ON {$wpdb->posts}(guid)
924 + ");
925 + } /* FeedWordPress::create_guid_index () */
926 +
809 927 # Utility functions for handling text settings
810 928 function negative ($f, $setting) {
811 929 $nego = array ('n', 'no', 'f', 'false');
812 930 return (isset($f[$setting]) and in_array(strtolower($f[$setting]), $nego));
@@ -953,12 +1071,26 @@
953 1071 // In case you want to point back to the blog this was syndicated from
954 1072 if (isset($this->feed->channel['title'])) :
955 1073 $this->post['meta']['syndication_source'] = apply_filters('syndicated_item_source_title', $this->feed->channel['title'], $this);
956 1074 endif;
1075 +
957 1076 if (isset($this->feed->channel['link'])) :
958 1077 $this->post['meta']['syndication_source_uri'] = apply_filters('syndicated_item_source_link', $this->feed->channel['link'], $this);
959 1078 endif;
960 1079
1080 + // Make use of atom:source data, if present in an aggregated feed
1081 + if (isset($this->item['source_title'])) :
1082 + $this->post['meta']['syndication_source_original'] = $this->item['source_title'];
1083 + endif;
1084 +
1085 + if (isset($this->item['source_link'])) :
1086 + $this->post['meta']['syndication_source_uri_original'] = $this->item['source_link'];
1087 + endif;
1088 +
1089 + if (isset($this->item['source_id'])) :
1090 + $this->post['meta']['syndication_source_id_original'] = $this->item['source_id'];
1091 + endif;
1092 +
961 1093 // Store information on human-readable and machine-readable comment URIs
962 1094 if (isset($this->item['comments'])) :
963 1095 $this->post['meta']['rss:comments'] = apply_filters('syndicated_item_comments', $this->item['comments']);
964 1096 endif;
@@ -969,8 +1101,12 @@
969 1101 // Store information to identify the feed that this came from
970 1102 $this->post['meta']['syndication_feed'] = $this->feedmeta['link/uri'];
971 1103 $this->post['meta']['syndication_feed_id'] = $this->feedmeta['link/id'];
972 1104
1105 + if (isset($this->item['source_link_self'])) :
1106 + $this->post['meta']['syndication_feed_original'] = $this->item['source_link_self'];
1107 + endif;
1108 +
973 1109 // In case you want to know the external permalink...
974 1110 $this->post['meta']['syndication_permalink'] = apply_filters('syndicated_item_link', $this->item['link']);
975 1111
976 1112 // Store a hash of the post content for checking whether something needs to be updated
@@ -1449,9 +1585,9 @@
1449 1585
1450 1586 // SyndicatedPost::author_id (): get the ID for an author name from
1451 1587 // the feed. Create the author if necessary.
1452 1588 function author_id ($unfamiliar_author = 'create') {
1453 - global $wpdb, $wp_db_version; // test for WordPress 2.0 database schema
1589 + global $wpdb;
1454 1590
1455 1591 $a = $this->author();
1456 1592 $author = $a['name'];
1457 1593 $email = $a['email'];
@@ -1456,8 +1592,15 @@
1456 1592 $author = $a['name'];
1457 1593 $email = $a['email'];
1458 1594 $url = $a['uri'];
1459 1595
1596 + $match_author_by_email = !('yes' == get_option("feedwordpress_do_not_match_author_by_email"));
1597 + if ($match_author_by_email and !FeedWordPress::is_null_email($email)) :
1598 + $test_email = $email;
1599 + else :
1600 + $test_email = NULL;
1601 + endif;
1602 +
1460 1603 // Never can be too careful...
1461 1604 $login = sanitize_user($author, /*strict=*/ true);
1462 1605 $login = apply_filters('pre_user_login', $login);
1463 1606
@@ -1466,8 +1609,9 @@
1466 1609
1467 1610 $reg_author = $wpdb->escape(preg_quote($author));
1468 1611 $author = $wpdb->escape($author);
1469 1612 $email = $wpdb->escape($email);
1613 + $test_email = $wpdb->escape($test_email);
1470 1614 $url = $wpdb->escape($url);
1471 1615
1472 1616 // Check for an existing author rule....
1473 1617 if (isset($this->link->settings['map authors']['name'][strtolower(trim($author))])) :
@@ -1486,34 +1630,10 @@
1486 1630
1487 1631 else :
1488 1632 // Check the database for an existing author record that might fit
1489 1633
1490 - #-- WordPress 1.5.x
1491 - if (!isset($wp_db_version)) :
1492 - $id = $wpdb->get_var(
1493 - "SELECT ID from $wpdb->users
1494 - WHERE
1495 - TRIM(LCASE(user_login)) = TRIM(LCASE('$login')) OR
1496 - (
1497 - LENGTH(TRIM(LCASE(user_email))) > 0
1498 - AND TRIM(LCASE(user_email)) = TRIM(LCASE('$email'))
1499 - ) OR
1500 - TRIM(LCASE(user_firstname)) = TRIM(LCASE('$author')) OR
1501 - TRIM(LCASE(user_nickname)) = TRIM(LCASE('$author')) OR
1502 - TRIM(LCASE(user_nicename)) = TRIM(LCASE('$nice_author')) OR
1503 - TRIM(LCASE(user_description)) = TRIM(LCASE('$author')) OR
1504 - (
1505 - LOWER(user_description)
1506 - RLIKE CONCAT(
1507 - '(^|\\n)a\\.?k\\.?a\\.?( |\\t)*:?( |\\t)*',
1508 - LCASE('$reg_author'),
1509 - '( |\\t|\\r)*(\\n|\$)'
1510 - )
1511 - )
1512 - ");
1513 -
1514 1634 #-- WordPress 2.0+
1515 - elseif ($wp_db_version >= 2966) :
1635 + if (fwp_test_wp_version(FWP_SCHEMA_HAS_USERMETA)) :
1516 1636
1517 1637 // First try the user core data table.
1518 1638 $id = $wpdb->get_var(
1519 1639 "SELECT ID FROM $wpdb->users
@@ -1520,9 +1640,9 @@
1520 1640 WHERE
1521 1641 TRIM(LCASE(user_login)) = TRIM(LCASE('$login'))
1522 1642 OR (
1523 1643 LENGTH(TRIM(LCASE(user_email))) > 0
1524 - AND TRIM(LCASE(user_email)) = TRIM(LCASE('$email'))
1644 + AND TRIM(LCASE(user_email)) = TRIM(LCASE('$test_email'))
1525 1645 )
1526 1646 OR TRIM(LCASE(user_nicename)) = TRIM(LCASE('$nice_author'))
1527 1647 ");
1528 1648
@@ -1542,8 +1662,33 @@
1542 1662 )
1543 1663 )
1544 1664 ");
1545 1665 endif;
1666 +
1667 + #-- WordPress 1.5.x
1668 + else :
1669 + $id = $wpdb->get_var(
1670 + "SELECT ID from $wpdb->users
1671 + WHERE
1672 + TRIM(LCASE(user_login)) = TRIM(LCASE('$login')) OR
1673 + (
1674 + LENGTH(TRIM(LCASE(user_email))) > 0
1675 + AND TRIM(LCASE(user_email)) = TRIM(LCASE('$test_email'))
1676 + ) OR
1677 + TRIM(LCASE(user_firstname)) = TRIM(LCASE('$author')) OR
1678 + TRIM(LCASE(user_nickname)) = TRIM(LCASE('$author')) OR
1679 + TRIM(LCASE(user_nicename)) = TRIM(LCASE('$nice_author')) OR
1680 + TRIM(LCASE(user_description)) = TRIM(LCASE('$author')) OR
1681 + (
1682 + LOWER(user_description)
1683 + RLIKE CONCAT(
1684 + '(^|\\n)a\\.?k\\.?a\\.?( |\\t)*:?( |\\t)*',
1685 + LCASE('$reg_author'),
1686 + '( |\\t|\\r)*(\\n|\$)'
1687 + )
1688 + )
1689 + ");
1690 +
1546 1691 endif;
1547 1692
1548 1693 // ... if you don't find one, then do what you need to do
1549 1694 if (is_null($id)) :
@@ -1999,13 +2144,13 @@
1999 2144 endforeach;
2000 2145 $this->settings['map authors'] = $ma;
2001 2146 endif;
2002 2147 endif;
2003 - } // SyndicatedLink::SyndicatedLink ()
2148 + } /* SyndicatedLink::SyndicatedLink () */
2004 2149
2005 2150 function found () {
2006 2151 return is_object($this->link);
2007 - }
2152 + } /* SyndicatedLink::found () */
2008 2153
2009 2154 function stale () {
2010 2155 $stale = true;
2011 2156 if (isset($this->settings['update/hold']) and ($this->settings['update/hold']=='ping')) :
@@ -2019,16 +2164,25 @@
2019 2164 +((int) $this->settings['update/ttl'] * 60);
2020 2165 $stale = (time() >= $after);
2021 2166 endif;
2022 2167 return $stale;
2023 - }
2168 + } /* SyndicatedLink::stale () */
2024 2169
2025 - function poll () {
2170 + function poll ($crash_ts = NULL) {
2026 2171 global $wpdb;
2027 2172
2028 2173 $this->magpie = fetch_rss($this->link->link_rss);
2029 2174 $new_count = NULL;
2030 2175
2176 + $resume = FeedWordPress::affirmative($this->settings, 'update/unfinished');
2177 + if ($resume) :
2178 + // pick up where we left off
2179 + $processed = array_map('trim', explode("\n", $this->settings['update/processed']));
2180 + else :
2181 + // begin at the beginning
2182 + $processed = array();
2183 + endif;
2184 +
2031 2185 if (is_object($this->magpie)) :
2032 2186 $new_count = array('new' => 0, 'updated' => 0);
2033 2187
2034 2188 # -- Update Link metadata live from feed
@@ -2064,44 +2218,17 @@
2064 2218 else :
2065 2219 $this->settings['update/ttl'] = rand(30, 120); // spread over time interval for staggered updates
2066 2220 $this->settings['update/timed'] = 'automatically';
2067 2221 endif;
2068 -
2222 +
2069 2223 if (!isset($this->settings['update/hold']) or $this->settings['update/hold']!='ping') :
2070 2224 $this->settings['update/hold'] = 'scheduled';
2071 2225 endif;
2072 -
2073 - // Copy back without a few things that we don't want to save in the notes
2074 - $to_notes = $this->settings;
2075 2226
2076 - if (is_array($to_notes['cats'])) :
2077 - $to_notes['cats'] = implode(FEEDWORDPRESS_CAT_SEPARATOR, $to_notes['cats']);
2078 - endif;
2079 - if (is_array($to_notes['tags'])) :
2080 - $to_notes['tags'] = implode(FEEDWORDPRESS_CAT_SEPARATOR, $to_notes['tags']);
2081 - endif;
2227 + $this->settings['update/unfinished'] = 'yes';
2082 2228
2083 - if (isset($to_notes['map authors'])) :
2084 - $ma = array();
2085 - foreach ($to_notes['map authors'] as $rule_type => $author_rules) :
2086 - foreach ($author_rules as $author_name => $author_action) :
2087 - $ma[] = $rule_type."\n".$author_name."\n".$author_action;
2088 - endforeach;
2089 - endforeach;
2090 - $to_notes['map authors'] = implode("\n\n", $ma);
2091 - endif;
2229 + $update[] = "link_notes = '".$wpdb->escape($this->settings_to_notes())."'";
2092 2230
2093 - unset($to_notes['link/id']); unset($to_notes['link/uri']);
2094 - unset($to_notes['link/name']);
2095 - unset($to_notes['hardcode categories']); // Deprecated
2096 - unset($to_notes['unfamiliar categories']); // Deprecated
2097 -
2098 - $notes = '';
2099 - foreach ($to_notes as $key => $value) :
2100 - $notes .= $key . ": ". addcslashes($value, "\0..\37".'\\') . "\n";
2101 - endforeach;
2102 - $update[] = "link_notes = '".$wpdb->escape($notes)."'";
2103 -
2104 2231 $update_set = implode(',', $update);
2105 2232
2106 2233 // Update the properties of the link from the feed information
2107 2234 $result = $wpdb->query("
@@ -2110,14 +2237,24 @@
2110 2237 WHERE link_id='$this->id'
2111 2238 ");
2112 2239
2113 2240 # -- Add new posts from feed and update any updated posts
2241 + $crashed = false;
2242 +
2114 2243 if (is_array($this->magpie->items)) :
2115 2244 foreach ($this->magpie->items as $item) :
2116 2245 $post =& new SyndicatedPost($item, $this);
2117 - if (!$post->filtered()) :
2118 - $new = $post->store();
2119 - if ( $new !== false ) $new_count[$new]++;
2246 + if (!$resume or !in_array(trim($post->guid()), $processed)) :
2247 + $processed[] = $post->guid();
2248 + if (!$post->filtered()) :
2249 + $new = $post->store();
2250 + if ( $new !== false ) $new_count[$new]++;
2251 + endif;
2252 +
2253 + if (!is_null($crash_ts) and (time() > $crash_ts)) :
2254 + $crashed = true;
2255 + break;
2256 + endif;
2120 2257 endif;
2121 2258 endforeach;
2122 2259 endif;
2123 2260
@@ -2123,53 +2260,102 @@
2123 2260
2124 2261 // Copy back any changes to feed settings made in the course of updating (e.g. new author rules)
2125 2262 $to_notes = $this->settings;
2126 2263
2127 - if (is_array($to_notes['cats'])) :
2128 - $to_notes['cats'] = implode(FEEDWORDPRESS_CAT_SEPARATOR, $to_notes['cats']);
2264 + $this->settings['update/processed'] = $processed;
2265 + if (!$crashed) :
2266 + $this->settings['update/unfinished'] = 'no';
2129 2267 endif;
2130 - if (is_array($to_notes['tags'])) :
2131 - $to_notes['tags'] = implode(FEEDWORDPRESS_CAT_SEPARATOR, $to_notes['tags']);
2132 - endif;
2133 2268
2134 - if (isset($to_notes['map authors'])) :
2135 - $ma = array();
2136 - foreach ($to_notes['map authors'] as $rule_type => $author_rules) :
2137 - foreach ($author_rules as $author_name => $author_action) :
2138 - $ma[] = $rule_type."\n".$author_name."\n".$author_action;
2139 - endforeach;
2140 - endforeach;
2141 - $to_notes['map authors'] = implode("\n\n", $ma);
2142 - endif;
2143 -
2144 - unset($to_notes['link/id']); unset($to_notes['link/uri']);
2145 - unset($to_notes['link/name']);
2146 - unset($to_notes['hardcode categories']); // Deprecated
2147 - unset($to_notes['unfamiliar categories']); // Deprecated
2148 -
2149 - $notes = '';
2150 - foreach ($to_notes as $key => $value) :
2151 - $notes .= $key . ": ". addcslashes($value, "\0..\37".'\\') . "\n";
2152 - endforeach;
2153 -
2154 - $update_set = "link_notes = '".$wpdb->escape($notes)."'";
2269 + $update_set = "link_notes = '".$wpdb->escape($this->settings_to_notes())."'";
2155 2270
2156 2271 // Update the properties of the link from the feed information
2157 2272 $result = $wpdb->query("
2158 - UPDATE $wpdb->links
2159 - SET $update_set
2160 - WHERE link_id='$this->id'
2273 + UPDATE $wpdb->links
2274 + SET $update_set
2275 + WHERE link_id='$this->id'
2161 2276 ");
2162 2277 endif;
2278 +
2163 2279 return $new_count;
2164 2280 } /* SyndicatedLink::poll() */
2165 -
2281 +
2282 + function map_name_to_new_user ($name, $newuser_name) {
2283 + global $wpdb;
2284 +
2285 + if (strlen($newuser_name) > 0) :
2286 + $userdata = array();
2287 + $userdata['ID'] = NULL;
2288 +
2289 + $userdata['user_login'] = sanitize_user($newuser_name);
2290 + $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
2291 +
2292 + $userdata['user_nicename'] = sanitize_title($newuser_name);
2293 + $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
2294 +
2295 + $userdata['display_name'] = $wpdb->escape($newuser_name);
2296 +
2297 + $newuser_id = wp_insert_user($userdata);
2298 + if (is_numeric($newuser_id)) :
2299 + if (is_null($name)) : // Unfamiliar author
2300 + $this->settings['unfamiliar author'] = $newuser_id;
2301 + else :
2302 + $this->settings['map authors']['name'][$name] = $newuser_id;
2303 + endif;
2304 + else :
2305 + // TODO: Add some error detection and reporting
2306 + endif;
2307 + else :
2308 + // TODO: Add some error reporting
2309 + endif;
2310 + } /* SyndicatedLink::map_name_to_new_user () */
2311 +
2312 + function settings_to_notes () {
2313 + $to_notes = $this->settings;
2314 +
2315 + unset($to_notes['link/id']); // Magic setting; don't save
2316 + unset($to_notes['link/uri']); // Magic setting; don't save
2317 + unset($to_notes['link/name']); // Magic setting; don't save
2318 + unset($to_notes['hardcode categories']); // Deprecated
2319 + unset($to_notes['unfamiliar categories']); // Deprecated
2320 +
2321 + // Collapse array settings
2322 + if (isset($to_notes['update/processed']) and (is_array($to_notes['update/processed']))) :
2323 + $to_notes['update/processed'] = implode("\n", $to_notes['update/processed']);
2324 + endif;
2325 +
2326 + if (is_array($to_notes['cats'])) :
2327 + $to_notes['cats'] = implode(FEEDWORDPRESS_CAT_SEPARATOR, $to_notes['cats']);
2328 + endif;
2329 + if (is_array($to_notes['tags'])) :
2330 + $to_notes['tags'] = implode(FEEDWORDPRESS_CAT_SEPARATOR, $to_notes['tags']);
2331 + endif;
2332 +
2333 + // Collapse the author mapping rule structure back into a flat string
2334 + if (isset($to_notes['map authors'])) :
2335 + $ma = array();
2336 + foreach ($to_notes['map authors'] as $rule_type => $author_rules) :
2337 + foreach ($author_rules as $author_name => $author_action) :
2338 + $ma[] = $rule_type."\n".$author_name."\n".$author_action;
2339 + endforeach;
2340 + endforeach;
2341 + $to_notes['map authors'] = implode("\n\n", $ma);
2342 + endif;
2343 +
2344 + $notes = '';
2345 + foreach ($to_notes as $key => $value) :
2346 + $notes .= $key . ": ". addcslashes($value, "\0..\37".'\\') . "\n";
2347 + endforeach;
2348 + return $notes;
2349 + } /* SyndicatedLink::settings_to_notes () */
2350 +
2166 2351 function uri () {
2167 2352 return (is_object($this->link) ? $this->link->link_rss : NULL);
2168 - }
2353 + } /* SyndicatedLink::uri () */
2354 +
2169 2355 function homepage () {
2170 2356 return (isset($this->settings['feed/link']) ? $this->settings['feed/link'] : NULL);
2171 - }
2357 + } /* SyndicatedLink::homepage () */
2172 2358
2173 2359 function ttl () {
2174 2360 if (is_object($this->magpie)) :
2175 2361 $channel = $this->magpie->channel;
@@ -2236,9 +2422,9 @@
2236 2422 endif;
2237 2423 endforeach;
2238 2424 endif;
2239 2425 return $ret;
2240 - } // function SyndicatedLink::flatten_array ()
2426 + } /* SyndicatedLink::flatten_array () */
2241 2427
2242 2428 function hardcode ($what) {
2243 2429 $default = get_option("feedwordpress_hardcode_$what");
2244 2430 if ( $default === 'yes' ) :
@@ -2252,9 +2438,9 @@
2252 2438 // setting is explicitly "yes"
2253 2439 $ret = FeedWordPress::affirmative($this->settings, "hardcode $what");
2254 2440 endif;
2255 2441 return $ret;
2256 - } // function SyndicatedLink::hardcode ()
2442 + } /* SyndicatedLink::hardcode () */
2257 2443
2258 2444 function syndicated_status ($what, $default) {
2259 2445 global $wpdb;
2260 2446
@@ -2264,9 +2450,9 @@
2264 2450 elseif (!$ret) :
2265 2451 $ret = $default;
2266 2452 endif;
2267 2453 return $wpdb->escape(trim(strtolower($ret)));
2268 - } // function SyndicatedLink:syndicated_status ()
2454 + } /* SyndicatedLink:syndicated_status () */
2269 2455 } // class SyndicatedLink
2270 2456
2271 2457 ################################################################################
2272 2458 ## XML-RPC HOOKS: accept XML-RPC update pings from Contributors ################