FeedWordPress - Version 0.98

Version Description

Download this release

Release Info

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

Code changes from version 0.97 to 0.98

ChangeLog.text CHANGED
@@ -1,6 +1,29 @@
1
  FeedWordPress Change Log
2
  ========================
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  Changes from 0.96 to 0.97
5
  -------------------------
6
 
1
  FeedWordPress Change Log
2
  ========================
3
 
4
+ Changes from 0.97 to 0.98
5
+ --------------------------
6
+
7
+ * WORDPRESS 2.0 COMPATIBILITY: This is a narrowly-targeted release to
8
+ solve a major outstanding problem. FeedWordPress is now compatible with
9
+ both WordPress 1.5 and WordPress 2.0. Incompatibilities that caused
10
+ fatal SQL errors, and a more subtle bug with off-kilter counts of posts
11
+ under a given category, have been resolved. FeedWordPress tests for
12
+ database schema using the global $wp_db_version variable (if null, then
13
+ we presume that we're dealing with WordPress 1.5).
14
+
15
+ NOTE: I have **not** fully tested FeedWordPress with WordPress 2.0.
16
+ Further testing may reveal more bugs. However, you should now be able
17
+ to get at least basic FeedWordPress functionality up and running.
18
+
19
+ * AUTHOR MATCHING: FeedWordPress tests several fields to see if it can
20
+ identify the author of the post as a user already in the WordPress user
21
+ database. In previous versions, it tested the user login, the nickname,
22
+ and tested for "aliases" listed in the Profile (see documentation). FWP
23
+ now also matches authors on the basis of e-mail address (*if* an e-mail
24
+ address is present). This is particularly helpful for formats such as
25
+ RSS 2.0, in which authors are primarily identified by e-mail addresses.
26
+
27
  Changes from 0.96 to 0.97
28
  -------------------------
29
 
README.text CHANGED
@@ -2,41 +2,42 @@ FeedWordPress
2
  =============
3
 
4
  * Author: [Charles Johnson](http://radgeek.com/contact)
5
- * Version: 0.97
6
  * Project URI: <http://projects.radgeek.com/feedwordpress>
7
  * License: GPL 2. See License below for copyright jots and tittles.
8
 
9
  Introduction
10
  ------------
11
- FeedWordPress is an Atom/RSS aggregator for WordPress 1.5. It syndicates content
12
- from newsfeeds that you choose into your WordPress blog; if you syndicate
13
- several newsfeeds then you can use WordPress's posts database and templating
14
- engine as the back-end of an aggregation ("planet") website. I originally
15
- developed it because I needed a more flexible replacement for [Planet][] to
16
- use at [Feminist Blogs][].
17
 
18
  [Planet]: http://www.planetplanet.org/ "Planet Planet"
19
  [Feminist Blogs]: http://www.feministblogs.org/
20
 
21
  FeedWordPress is designed with flexibility, ease of use, and ease of
22
- configuration in mind. You'll need a working installation of [WordPress
23
- 1.5][] and FTP or SFTP access to your web host. The ability to create cron
24
- jobs on your web host would be very helpful but it's not absolutely
25
- necessary. You *don't* need to tweak any plain-text configuration files and
26
- you *don't* need shell access to your web host to make it work. (Although, I
27
- should point out, web hosts that *don't* offer shell access are *bad web
28
- hosts*.)
29
 
30
- [WordPress 1.5]: http://wordpress.org/development/2005/02/strayhorn/
 
31
 
32
  Installation
33
  ------------
34
  ### Requirements ###
35
 
36
- To use version 0.97 of FeedWordPress, you will need:
37
 
38
- 1. an installed configured copy of WordPress 1.5.x. (It *won't work* with
39
- WP 1.2 or WP 1.6 development builds.)
40
 
41
  2. FTP or SFTP access to your web host
42
 
@@ -50,7 +51,7 @@ And you'll probably also want to have either:
50
 
51
  #### Upgrades ####
52
 
53
- To *upgrade* an existing installation of FeedWordPress to version 0.97:
54
 
55
  1. Download the FeedWordPress archive in zip or gzipped tar format and
56
  extract the files on your computer. Replace your existing FeedWordPress
@@ -58,13 +59,14 @@ To *upgrade* an existing installation of FeedWordPress to version 0.97:
58
  use the optional MagpieRSS upgrade, or don't use it yet but do want to
59
  syndicate Atom 1.0 feeds.
60
 
61
- 2. **Immediately** log in to the WordPress Dashboard, and go to Options -->
62
- Syndicated. Follow the directions to launch the database upgrade
63
- procedure. The new version of FeedWordPress incorporates some
64
- long-needed improvements, but old meta-data needs to be updated to
65
- prevent duplicate posts and other possible maladies. If you're upgrading
66
- an existing installation, updates and FeedWordPress template functions
67
- *will not work* until you've done the upgrade.
 
68
 
69
  3. Take a coffee break while the upgrade runs. It should, hopefully, finish
70
  within a few minutes even on relatively large databases.
@@ -201,9 +203,9 @@ You can pull that off in one of two ways, or by a mixture of both:
201
 
202
  Basic Concepts
203
  --------------
204
- FeedWordPress is written as a plugin for [WordPress 1.5][]. It is designed to
205
- store all the data it needs within the WordPress database and to make that data
206
- easy to manage from within the WordPress Dashboard.
207
 
208
  ### Contributors / Newsfeeds ###
209
 
@@ -371,8 +373,8 @@ Most newsfeeds include information about the author of the items on them.
371
  the title of the feed from which the item was taken.) This information is used
372
  to determine the WordPress user that the post will be attributed to. Given the
373
  name of the author, FeedWordPress looks for authors in the WordPress database
374
- with the same name as either (1) their login, (2) their first name, (3) their
375
- nickname, (4) their full name, or (5) one of the "aliases" listed in the
376
  user's profile.
377
 
378
  __Aliases:__ If there is an author who posts under more than one name (for
2
  =============
3
 
4
  * Author: [Charles Johnson](http://radgeek.com/contact)
5
+ * Version: 0.98
6
  * Project URI: <http://projects.radgeek.com/feedwordpress>
7
  * License: GPL 2. See License below for copyright jots and tittles.
8
 
9
  Introduction
10
  ------------
11
+ FeedWordPress is an Atom/RSS aggregator for the WordPress weblog software. It
12
+ syndicates content from newsfeeds that you choose into your WordPress webblog;
13
+ if you syndicate several newsfeeds then you can use WordPress's posts database
14
+ and templating engine as the back-end of an aggregation ("planet") website. I
15
+ originally developed it because I needed a more flexible replacement for
16
+ [Planet][] to use at [Feminist Blogs][].
17
 
18
  [Planet]: http://www.planetplanet.org/ "Planet Planet"
19
  [Feminist Blogs]: http://www.feministblogs.org/
20
 
21
  FeedWordPress is designed with flexibility, ease of use, and ease of
22
+ configuration in mind. You'll need a working installation of WordPress (version
23
+ [2.0][] or [1.5][]), and also FTP or SFTP access to your web host. The ability
24
+ to create cron jobs on your web host would be very helpful but it's not
25
+ absolutely necessary. You *don't* need to tweak any plain-text configuration
26
+ files and you *don't* need shell access to your web host to make it work.
27
+ (Although, I should point out, web hosts that *don't* offer shell access are
28
+ *bad web hosts*.)
29
 
30
+ [2.0]: http://wordpress.org/development/2005/12/wp2/
31
+ [1.5]: http://wordpress.org/development/2005/02/strayhorn/
32
 
33
  Installation
34
  ------------
35
  ### Requirements ###
36
 
37
+ To use version 0.98 of FeedWordPress, you will need:
38
 
39
+ 1. an installed configured copy of WordPress 2.0.x or 1.5.x. (FeedWordPress
40
+ *will not work* with WP 1.2 or WP MU development builds.)
41
 
42
  2. FTP or SFTP access to your web host
43
 
51
 
52
  #### Upgrades ####
53
 
54
+ To *upgrade* an existing installation of FeedWordPress to version 0.98:
55
 
56
  1. Download the FeedWordPress archive in zip or gzipped tar format and
57
  extract the files on your computer. Replace your existing FeedWordPress
59
  use the optional MagpieRSS upgrade, or don't use it yet but do want to
60
  syndicate Atom 1.0 feeds.
61
 
62
+ 2. If you are upgrading from version 0.96 or earlier, **immediately** log
63
+ in to the WordPress Dashboard, and go to Options --> Syndicated. Follow
64
+ the directions to launch the database upgrade procedure. The new
65
+ versions of FeedWordPress incorporate some long-needed improvements, but
66
+ old meta-data needs to be updated to prevent duplicate posts and other
67
+ possible maladies. If you're upgrading an existing installation, updates
68
+ and FeedWordPress template functions *will not work* until you've done
69
+ the upgrade.
70
 
71
  3. Take a coffee break while the upgrade runs. It should, hopefully, finish
72
  within a few minutes even on relatively large databases.
203
 
204
  Basic Concepts
205
  --------------
206
+ FeedWordPress is written as a plugin for the WordPress weblog software. It is
207
+ designed to store all the data it needs within the WordPress database and to
208
+ make that data easy to manage from within the WordPress Dashboard.
209
 
210
  ### Contributors / Newsfeeds ###
211
 
373
  the title of the feed from which the item was taken.) This information is used
374
  to determine the WordPress user that the post will be attributed to. Given the
375
  name of the author, FeedWordPress looks for authors in the WordPress database
376
+ with the same name as either (1) their login, (2) their display name, (3) their
377
+ e-mail address (if given), or (4) one of the "aliases" listed in the
378
  user's profile.
379
 
380
  __Aliases:__ If there is an author who posts under more than one name (for
wp-content/plugins/feedwordpress.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: FeedWordPress
4
  Plugin URI: http://projects.radgeek.com/feedwordpress
5
  Description: simple and flexible Atom/RSS syndication for WordPress
6
- Version: 0.97
7
  Author: Charles Johnson
8
  Author URI: http://radgeek.com/
9
  License: GPL
@@ -27,7 +27,7 @@ Last modified: 2005-09-28 4:40pm EDT
27
 
28
  # -- Don't change these unless you know what you're doing...
29
  define ('RPC_MAGIC', 'tag:radgeek.com/projects/feedwordpress/');
30
- define ('FEEDWORDPRESS_VERSION', '0.97');
31
  define ('DEFAULT_SYNDICATION_CATEGORY', 'Contributors');
32
 
33
  define ('FEEDWORDPRESS_CAT_SEPARATOR_PATTERN', '/[:\n]/');
@@ -40,6 +40,10 @@ define ('FEEDVALIDATOR_URI', 'http://feedvalidator.org/check.cgi');
40
  // this archive into wp-includes/rss-functions.php
41
  require_once (ABSPATH . WPINC . '/rss-functions.php');
42
 
 
 
 
 
43
  // Is this being loaded from within WordPress 1.5 or later?
44
  if (isset($wp_version) and $wp_version >= 1.5):
45
 
@@ -2194,86 +2198,16 @@ class FeedWordPress {
2194
 
2195
  if ($freshness == 2) :
2196
  // The item has not yet been added. So let's add it.
2197
-
2198
- # The right way to do this would be to use:
2199
- #
2200
- # $postId = wp_insert_post($post);
2201
- # $result = $wpdb->query("
2202
- # UPDATE $wpdb->posts
2203
- # SET
2204
- # guid='$guid'
2205
- # WHERE post_id='$postId'
2206
- # ");
2207
- #
2208
- # in place of everything in the cut below. Alas,
2209
- # wp_insert_post seems to be a memory hog; using it
2210
- # to insert several posts in one session makes php
2211
- # segfault after inserting 50-100 posts. This can get
2212
- # pretty annoying, especially if you are trying to
2213
- # update your feeds for the first time.
2214
- #
2215
- # --- cut here ---
2216
- $result = $wpdb->query("
2217
- INSERT INTO $wpdb->posts
2218
- SET
2219
- guid = '$guid',
2220
- post_author = '".$post['post_author']."',
2221
- post_date = '".$post['post_date']."',
2222
- post_date_gmt = '".$post['post_date_gmt']."',
2223
- post_content = '".$post['post_content']."',"
2224
- .(isset($post['post_excerpt']) ? "post_excerpt = '".$post['post_excerpt']."'," : "")."
2225
- post_title = '".$post['post_title']."',
2226
- post_name = '".$post['post_name']."',
2227
- post_modified = '".$post['post_modified']."',
2228
- post_modified_gmt = '".$post['post_modified_gmt']."',
2229
- comment_status = '".$post['comment_status']."',
2230
- ping_status = '".$post['ping_status']."',
2231
- post_status = '".$post['post_status']."'
2232
- ");
2233
- $postId = $wpdb->insert_id;
2234
- $this->add_to_category($wpdb, $postId, $post['post_category']);
2235
-
2236
- // Since we are not going through official channels, we need to
2237
- // manually tell WordPress that we've published a new post.
2238
- // We need to make sure to do this in order for FeedWordPress
2239
- // to play well with the staticize-reloaded plugin (something
2240
- // that a large aggregator website is going to *want* to be
2241
- // able to use).
2242
- do_action('publish_post', $postId);
2243
- # --- cut here ---
2244
-
2245
  $this->add_rss_meta($wpdb, $postId, $post);
2246
-
2247
  do_action('post_syndicated_item', $postId);
2248
 
2249
  $ret = 'new';
2250
  elseif ($freshness == 1) :
2251
- $postId = $result->id; $modified = $result->modified;
2252
-
2253
- $result = $wpdb->query("
2254
- UPDATE $wpdb->posts
2255
- SET
2256
- post_author = '".$post['post_author']."',
2257
- post_content = '".$post['post_content']."',
2258
- post_title = '".$post['post_title']."',
2259
- post_name = '".$post['post_name']."',
2260
- post_modified = '".$post['post_modified']."',
2261
- post_modified_gmt = '".$post['post_modified_gmt']."'
2262
- WHERE guid='$guid'
2263
- ");
2264
- $this->add_to_category($wpdb, $postId, $post['post_category']);
2265
-
2266
- // Since we are not going through official channels, we need to
2267
- // manually tell WordPress that we've published a new post.
2268
- // We need to make sure to do this in order for FeedWordPress
2269
- // to play well with the staticize-reloaded plugin (something
2270
- // that a large aggregator website is going to *want* to be
2271
- // able to use).
2272
- do_action('edit_post', $postId);
2273
-
2274
- $this->add_rss_meta($wpdb, $postId, $post);
2275
-
2276
- do_action('update_syndicated_item', $postId);
2277
 
2278
  $ret = 'updated';
2279
  else :
@@ -2282,30 +2216,103 @@ class FeedWordPress {
2282
 
2283
  return $ret;
2284
  } // function FeedWordPress::add_post ()
2285
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2286
  # function FeedWordPress::add_to_category ()
2287
  #
2288
  # If there is a way to properly hook in to wp_insert_post, then this
2289
  # function will no longer be needed. In the meantime, here it is.
2290
  # --- cut here ---
2291
  function add_to_category($wpdb, $postId, $post_categories) {
 
 
2292
  // Default to category 1 ("Uncategorized"), if nothing else
2293
  if (!$post_categories) $post_categories[] = 1;
2294
 
2295
- // Clean the slate (in case we're updating)
2296
- $results = $wpdb->query("
2297
- DELETE FROM $wpdb->post2cat
2298
- WHERE post_id = $postId
2299
- ");
2300
-
2301
- foreach ($post_categories as $post_category):
2302
- $results = $wpdb->query("
2303
- INSERT INTO $wpdb->post2cat
2304
- SET
2305
- post_id = $postId,
2306
- category_id = $post_category
2307
- ");
2308
- endforeach;
2309
  } // function FeedWordPress::add_to_category ()
2310
  # --- cut here ---
2311
 
@@ -2350,6 +2357,8 @@ class FeedWordPress {
2350
  // FeedWordPress::author_to_id (): get the ID for an author name from
2351
  // the feed. Create the author if necessary.
2352
  function author_to_id ($wpdb, $author, $email, $url, $unfamiliar_author = 'create') {
 
 
2353
  // Never can be too careful...
2354
  $nice_author = sanitize_title($author);
2355
  $reg_author = $wpdb->escape(preg_quote($author));
@@ -2357,38 +2366,94 @@ class FeedWordPress {
2357
  $email = $wpdb->escape($email);
2358
  $url = $wpdb->escape($url);
2359
 
2360
- $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;
@@ -2564,7 +2629,7 @@ class FeedWordPress {
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
 
3
  Plugin Name: FeedWordPress
4
  Plugin URI: http://projects.radgeek.com/feedwordpress
5
  Description: simple and flexible Atom/RSS syndication for WordPress
6
+ Version: 0.98
7
  Author: Charles Johnson
8
  Author URI: http://radgeek.com/
9
  License: GPL
27
 
28
  # -- Don't change these unless you know what you're doing...
29
  define ('RPC_MAGIC', 'tag:radgeek.com/projects/feedwordpress/');
30
+ define ('FEEDWORDPRESS_VERSION', '0.98');
31
  define ('DEFAULT_SYNDICATION_CATEGORY', 'Contributors');
32
 
33
  define ('FEEDWORDPRESS_CAT_SEPARATOR_PATTERN', '/[:\n]/');
40
  // this archive into wp-includes/rss-functions.php
41
  require_once (ABSPATH . WPINC . '/rss-functions.php');
42
 
43
+ if (isset($wp_db_version) and $wp_db_version >= 2966) :
44
+ require_once (ABSPATH . WPINC . '/registration-functions.php');
45
+ endif;
46
+
47
  // Is this being loaded from within WordPress 1.5 or later?
48
  if (isset($wp_version) and $wp_version >= 1.5):
49
 
2198
 
2199
  if ($freshness == 2) :
2200
  // The item has not yet been added. So let's add it.
2201
+ $postId = $this->insert_new_post($post);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2202
  $this->add_rss_meta($wpdb, $postId, $post);
 
2203
  do_action('post_syndicated_item', $postId);
2204
 
2205
  $ret = 'new';
2206
  elseif ($freshness == 1) :
2207
+ $post['ID'] = $result->id; $modified = $result->modified;
2208
+ $this->update_existing_post($post);
2209
+ $this->add_rss_meta($wpdb, $post['ID'], $post);
2210
+ do_action('update_syndicated_item', $post['ID']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2211
 
2212
  $ret = 'updated';
2213
  else :
2216
 
2217
  return $ret;
2218
  } // function FeedWordPress::add_post ()
2219
+
2220
+ function insert_new_post ($post) {
2221
+ global $wpdb;
2222
+
2223
+ $guid = $post['guid'];
2224
+
2225
+ # The right way to do this would be to use:
2226
+ #
2227
+ # $postId = wp_insert_post($post);
2228
+ # $result = $wpdb->query("
2229
+ # UPDATE $wpdb->posts
2230
+ # SET
2231
+ # guid='$guid'
2232
+ # WHERE post_id='$postId'
2233
+ # ");
2234
+ #
2235
+ # in place of everything in the cut below. Alas,
2236
+ # wp_insert_post seems to be a memory hog; using it
2237
+ # to insert several posts in one session makes php
2238
+ # segfault after inserting 50-100 posts. This can get
2239
+ # pretty annoying, especially if you are trying to
2240
+ # update your feeds for the first time.
2241
+ #
2242
+ # --- cut here ---
2243
+ $result = $wpdb->query("
2244
+ INSERT INTO $wpdb->posts
2245
+ SET
2246
+ guid = '$guid',
2247
+ post_author = '".$post['post_author']."',
2248
+ post_date = '".$post['post_date']."',
2249
+ post_date_gmt = '".$post['post_date_gmt']."',
2250
+ post_content = '".$post['post_content']."',"
2251
+ .(isset($post['post_excerpt']) ? "post_excerpt = '".$post['post_excerpt']."'," : "")."
2252
+ post_title = '".$post['post_title']."',
2253
+ post_name = '".$post['post_name']."',
2254
+ post_modified = '".$post['post_modified']."',
2255
+ post_modified_gmt = '".$post['post_modified_gmt']."',
2256
+ comment_status = '".$post['comment_status']."',
2257
+ ping_status = '".$post['ping_status']."',
2258
+ post_status = '".$post['post_status']."'
2259
+ ");
2260
+ $postId = $wpdb->insert_id;
2261
+ $this->add_to_category($wpdb, $postId, $post['post_category']);
2262
+
2263
+ // Since we are not going through official channels, we need to
2264
+ // manually tell WordPress that we've published a new post.
2265
+ // We need to make sure to do this in order for FeedWordPress
2266
+ // to play well with the staticize-reloaded plugin (something
2267
+ // that a large aggregator website is going to *want* to be
2268
+ // able to use).
2269
+ do_action('publish_post', $postId);
2270
+ # --- cut here ---
2271
+
2272
+ return $postId;
2273
+ } /* FeedWordPress::insert_new_post() */
2274
+
2275
+ function update_existing_post ($post) {
2276
+ global $wpdb;
2277
+
2278
+ $guid = $post['guid'];
2279
+ $postId = $post['ID'];
2280
+
2281
+ $result = $wpdb->query("
2282
+ UPDATE $wpdb->posts
2283
+ SET
2284
+ post_author = '".$post['post_author']."',
2285
+ post_content = '".$post['post_content']."',
2286
+ post_title = '".$post['post_title']."',
2287
+ post_name = '".$post['post_name']."',
2288
+ post_modified = '".$post['post_modified']."',
2289
+ post_modified_gmt = '".$post['post_modified_gmt']."'
2290
+ WHERE guid='$guid'
2291
+ ");
2292
+ $this->add_to_category($wpdb, $postId, $post['post_category']);
2293
+
2294
+ // Since we are not going through official channels, we need to
2295
+ // manually tell WordPress that we've published a new post.
2296
+ // We need to make sure to do this in order for FeedWordPress
2297
+ // to play well with the staticize-reloaded plugin (something
2298
+ // that a large aggregator website is going to *want* to be
2299
+ // able to use).
2300
+ do_action('edit_post', $postId);
2301
+ } /* FeedWordPress::update_existing_post() */
2302
+
2303
  # function FeedWordPress::add_to_category ()
2304
  #
2305
  # If there is a way to properly hook in to wp_insert_post, then this
2306
  # function will no longer be needed. In the meantime, here it is.
2307
  # --- cut here ---
2308
  function add_to_category($wpdb, $postId, $post_categories) {
2309
+ global $wp_db_version; // test for WordPress 2.0 database schema
2310
+
2311
  // Default to category 1 ("Uncategorized"), if nothing else
2312
  if (!$post_categories) $post_categories[] = 1;
2313
 
2314
+ // Now pass the buck to the WordPress API...
2315
+ wp_set_post_cats('', $postId, $post_categories);
 
 
 
 
 
 
 
 
 
 
 
 
2316
  } // function FeedWordPress::add_to_category ()
2317
  # --- cut here ---
2318
 
2357
  // FeedWordPress::author_to_id (): get the ID for an author name from
2358
  // the feed. Create the author if necessary.
2359
  function author_to_id ($wpdb, $author, $email, $url, $unfamiliar_author = 'create') {
2360
+ global $wp_db_version; // test for WordPress 2.0 database schema
2361
+
2362
  // Never can be too careful...
2363
  $nice_author = sanitize_title($author);
2364
  $reg_author = $wpdb->escape(preg_quote($author));
2366
  $email = $wpdb->escape($email);
2367
  $url = $wpdb->escape($url);
2368
 
2369
+ // Look for an existing author record that fits...
2370
+ if (!isset($wp_db_version)) :
2371
+ #-- WordPress 1.5.x
2372
+ $id = $wpdb->get_var(
2373
+ "SELECT ID from $wpdb->users
2374
+ WHERE
2375
+ TRIM(LCASE(user_login)) = TRIM(LCASE('$author')) OR
2376
+ (
2377
+ LENGTH(TRIM(LCASE(user_email))) > 0
2378
+ AND TRIM(LCASE(user_email)) = TRIM(LCASE('$email'))
2379
+ ) OR
2380
+ TRIM(LCASE(user_firstname)) = TRIM(LCASE('$author')) OR
2381
+ TRIM(LCASE(user_nickname)) = TRIM(LCASE('$author')) OR
2382
+ TRIM(LCASE(user_nicename)) = TRIM(LCASE('$nice_author')) OR
2383
+ TRIM(LCASE(user_description)) = TRIM(LCASE('$author')) OR
2384
+ (
2385
+ LOWER(user_description)
2386
+ RLIKE CONCAT(
2387
+ '(^|\\n)a.k.a.( |\\t)*:?( |\\t)*',
2388
+ LCASE('$reg_author'),
2389
+ '( |\\t|\\r)*(\\n|\$)'
2390
+ )
2391
  )
2392
+ ");
2393
+ elseif ($wp_db_version >= 2966) :
2394
+ #-- WordPress 2.0+
2395
+
2396
+ # First try the user core data table.
2397
+ $id = $wpdb->get_var(
2398
+ "SELECT ID FROM $wpdb->users
2399
+ WHERE
2400
+ TRIM(LCASE(user_login)) = TRIM(LCASE('$author'))
2401
+ OR (
2402
+ LENGTH(TRIM(LCASE(user_email))) > 0
2403
+ AND TRIM(LCASE(user_email)) = TRIM(LCASE('$email'))
2404
+ )
2405
+ OR TRIM(LCASE(user_nicename)) = TRIM(LCASE('$nice_author'))
2406
+ ");
2407
 
2408
+ if (is_null($id)) : # Then look for aliases in the user meta data table
2409
+ $id = $wpdb->get_var(
2410
+ "SELECT user_id FROM $wpdb->usermeta
2411
+ WHERE
2412
+ (meta_key = 'description' AND TRIM(LCASE(meta_value)) = TRIM(LCASE('$author')))
2413
+ OR (
2414
+ meta_key = 'description'
2415
+ AND LCASE(meta_value)
2416
+ RLIKE CONCAT(
2417
+ '(^|\\n)a.k.a.( |\\t)*:?( |\\t)*',
2418
+ LCASE('$reg_author'),
2419
+ '( |\\t|\\r)*(\\n|\$)'
2420
+ )
2421
+ )
2422
+ ");
2423
+ endif;
2424
+ endif;
2425
+
2426
+ // ... if you don't find one, then do what you need to do
2427
  if (is_null($id)) :
2428
  if ($unfamiliar_author === 'create') :
2429
+ if (!isset($wp_db_version)) :
2430
+ #-- WordPress 1.5.x
2431
+ $wpdb->query (
2432
+ "INSERT INTO $wpdb->users
2433
+ SET
2434
+ ID='0',
2435
+ user_login='$author',
2436
+ user_firstname='$author',
2437
+ user_nickname='$author',
2438
+ user_nicename='$nice_author',
2439
+ user_description='$author',
2440
+ user_email='$email',
2441
+ user_url='$url'");
2442
+ $id = $wpdb->insert_id;
2443
+ elseif ($wp_db_version >= 2966) :
2444
+ #-- WordPress 2.0+
2445
+ $userdata = array();
2446
+
2447
+ #-- user table data
2448
+ $userdata['ID'] = NULL; // new user
2449
+ $userdata['user_login'] = $author;
2450
+ $userdata['user_pass'] = FeedWordPress::rpc_secret();
2451
+ $userdata['user_email'] = $email;
2452
+ $userdata['user_url'] = $url;
2453
+ $userdata['display_name'] = $author;
2454
+
2455
+ $id = wp_insert_user($userdata);
2456
+ endif;
2457
  elseif ($unfamiliar_author === 'default') :
2458
  $id = 1;
2459
  endif;
2629
 
2630
  switch ($from) :
2631
  case 0.96: // account for changes to syndication custom values and guid
2632
+ echo "<p>Upgrading database from {$from} to 0.97+...</p>\n";
2633
 
2634
  $cat_id = FeedWordPress::link_category_id();
2635
 
wp-content/update-feeds.php CHANGED
@@ -119,7 +119,7 @@ if ($update_feeds_invoke != 'cmd') : // We're acessing this from HTTP GET or HT
119
  if ($update_feeds_display=='text/html') :
120
  auth_redirect(); // try authentication cookies; if all else fails, redirect to wp-login.php
121
  else :
122
- echo "update-feeds (".date('Y-m-d H:i:s')."): ERROR: Could not log in as '$login'/pass='$pass']\n";
123
  die;
124
  endif;
125
  endif;
119
  if ($update_feeds_display=='text/html') :
120
  auth_redirect(); // try authentication cookies; if all else fails, redirect to wp-login.php
121
  else :
122
+ echo "update-feeds (".date('Y-m-d H:i:s')."): ERROR: Could not log in as '$login' (password: '$pass')\n";
123
  die;
124
  endif;
125
  endif;