Version Description
Download this release
Release Info
Developer | radgeek |
Plugin | FeedWordPress |
Version | 0.9 |
Comparing to | |
See all releases |
Code changes from version 0.8 to 0.9
- OPTIONAL/wp-includes/rss-functions.php +5 -1
- README.text +13 -2
- wp-content/plugins/feedwordpress.php +266 -158
OPTIONAL/wp-includes/rss-functions.php
CHANGED
@@ -911,7 +911,11 @@ function init () {
|
|
911 |
}
|
912 |
|
913 |
if ( !defined('MAGPIE_OUTPUT_ENCODING') ) {
|
914 |
-
|
|
|
|
|
|
|
|
|
915 |
}
|
916 |
|
917 |
if ( !defined('MAGPIE_INPUT_ENCODING') ) {
|
911 |
}
|
912 |
|
913 |
if ( !defined('MAGPIE_OUTPUT_ENCODING') ) {
|
914 |
+
# WORDPRESS MODIFICATION: use whatever charset the blog is using
|
915 |
+
# --- cut here ---
|
916 |
+
$wp_encoding = get_settings('blog_charset');
|
917 |
+
define('MAGPIE_OUTPUT_ENCODING', ($wp_encoding?$wp_encoding:'ISO-8859-1'));
|
918 |
+
# --- cut here ---
|
919 |
}
|
920 |
|
921 |
if ( !defined('MAGPIE_INPUT_ENCODING') ) {
|
README.text
CHANGED
@@ -2,7 +2,7 @@ FeedWordPress
|
|
2 |
=============
|
3 |
|
4 |
* Author: [Charles Johnson](http://www.radgeek.com/contact)
|
5 |
-
* Version: 0.
|
6 |
* Project URI: <http://projects.radgeek.com/feedwordpress>
|
7 |
* License: GPL. See License below for copyright jots and tittles.
|
8 |
|
@@ -72,7 +72,6 @@ For detailed installation instructions, point your web browser to
|
|
72 |
|
73 |
Feed Settings
|
74 |
-------------
|
75 |
-
### Feed Settings ###
|
76 |
|
77 |
Once you have your links configured and regular feed updates scheduled, you can
|
78 |
mostly leave FeedWordPress to run on its own. If you need to add, remove, or
|
@@ -221,6 +220,18 @@ link to the location of the posts on the source website, *not* to their location
|
|
221 |
on your website. You can switch this behavior on or off at Options -->
|
222 |
Syndication in the WordPress Dashboard.
|
223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
License
|
225 |
-------
|
226 |
The FeedWordPress plugin is copyright (c) 2005 by Charles Johnson. It uses code
|
2 |
=============
|
3 |
|
4 |
* Author: [Charles Johnson](http://www.radgeek.com/contact)
|
5 |
+
* Version: 0.9
|
6 |
* Project URI: <http://projects.radgeek.com/feedwordpress>
|
7 |
* License: GPL. See License below for copyright jots and tittles.
|
8 |
|
72 |
|
73 |
Feed Settings
|
74 |
-------------
|
|
|
75 |
|
76 |
Once you have your links configured and regular feed updates scheduled, you can
|
77 |
mostly leave FeedWordPress to run on its own. If you need to add, remove, or
|
220 |
on your website. You can switch this behavior on or off at Options -->
|
221 |
Syndication in the WordPress Dashboard.
|
222 |
|
223 |
+
### Plugin API ###
|
224 |
+
|
225 |
+
FeedWordPress creates five hooks through the WordPress plugin architecture that
|
226 |
+
you can plug in to using PHP WordPress plugins, to supplement ordinary
|
227 |
+
FeedWordPress behavior, or to filter posts according to criteria that you set.
|
228 |
+
The hooks are the action ``feedwordpress_update``, the action
|
229 |
+
``feedwordpress_check_feed``, the action ``feedwordpress_update_complete``, the
|
230 |
+
filter ``syndicated_item``, the filter ``syndicated_post``, the action
|
231 |
+
``post_syndicated_item``, and the action ``update_syndicated_item``.
|
232 |
+
|
233 |
+
For more information, see <http://projects.radgeek.com/feedwordpress/use>.
|
234 |
+
|
235 |
License
|
236 |
-------
|
237 |
The FeedWordPress plugin is copyright (c) 2005 by Charles Johnson. It uses code
|
wp-content/plugins/feedwordpress.php
CHANGED
@@ -3,14 +3,14 @@
|
|
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.
|
7 |
Author: Charles Johnson
|
8 |
Author URI: http://www.radgeek.com/
|
9 |
*/
|
10 |
|
11 |
# Author: Charles Johnson <technophilia@radgeek.com>
|
12 |
# License: GPL
|
13 |
-
# Last modified: 2005-03-
|
14 |
#
|
15 |
# This uses code derived from:
|
16 |
# - wp-rss-aggregate.php by Kellan Elliot-McCrea <kellan@protest.net>
|
@@ -32,7 +32,7 @@ define ('FEEDWORDPRESS_LOG_UPDATES', true); // Make false if you hate status upd
|
|
32 |
|
33 |
# -- Don't change these unless you know what you're doing...
|
34 |
define ('RPC_MAGIC', 'tag:radgeek.com/projects/feedwordpress/');
|
35 |
-
define ('FEEDWORDPRESS_VERSION', '0.
|
36 |
define ('DEFAULT_SYNDICATION_CATEGORY', 'Contributors');
|
37 |
|
38 |
// Note that the rss-functions.php that comes prepackaged with WordPress is
|
@@ -76,6 +76,50 @@ endif;
|
|
76 |
remove_action('publish_post', 'generic_ping');
|
77 |
add_action('publish_post', 'fwp_catch_ping');
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
# -- Template functions for syndication sites
|
80 |
function is_syndicated () { return (strlen(get_syndication_feed()) > 0); }
|
81 |
|
@@ -129,7 +173,7 @@ function syndication_permalink ($permalink = '') {
|
|
129 |
# -- Admin menu add-ons
|
130 |
function fwp_add_pages () {
|
131 |
add_submenu_page('link-manager.php', 'Syndicated Sites', 'Syndicated', 5, __FILE__, 'fwp_syndication_manage_page');
|
132 |
-
add_options_page('Syndication', 'Syndication',
|
133 |
} // function fwp_add_pages () */
|
134 |
|
135 |
function fwp_syndication_options_page () {
|
@@ -139,12 +183,13 @@ function fwp_syndication_options_page () {
|
|
139 |
if (isset($_REQUEST['action']) and $_REQUEST['action']=$caption):
|
140 |
check_admin_referer();
|
141 |
|
142 |
-
if ($user_level <
|
143 |
die (__("Cheatin' uh ?"));
|
144 |
else:
|
145 |
update_option('feedwordpress_rpc_secret', $_REQUEST['rpc_secret']);
|
146 |
update_option('feedwordpress_cat_id', $_REQUEST['syndication_category']);
|
147 |
update_option('feedwordpress_munge_permalink', $_REQUEST['munge_permalink']);
|
|
|
148 |
?>
|
149 |
<div class="updated">
|
150 |
<p><?php _e('Options saved.')?></p>
|
@@ -156,6 +201,7 @@ function fwp_syndication_options_page () {
|
|
156 |
$cat_id = FeedWordPress::link_category_id();
|
157 |
$rpc_secret = FeedWordPress::rpc_secret();
|
158 |
$munge_permalink = get_settings('feedwordpress_munge_permalink');
|
|
|
159 |
$results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY cat_id");
|
160 |
?>
|
161 |
<div class="wrap">
|
@@ -205,6 +251,14 @@ function fwp_syndication_options_page () {
|
|
205 |
<th width="33%" scope="row">XML-RPC update secret word:</th>
|
206 |
<td width="67%"><input id="rpc_secret" name="rpc_secret" value="<?=$rpc_secret?>" />
|
207 |
</td>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
</table>
|
209 |
<div class="submit"><input type="submit" name="action" value="<?=$caption?>" /></div>
|
210 |
</fieldset>
|
@@ -262,7 +316,7 @@ if ($cont):
|
|
262 |
<?php if (strlen($link->link_rss) > 0): $caption='Switch Feed'; ?>
|
263 |
<td style="font-size:smaller;text-align:center">
|
264 |
<strong><a href="<?=$link->link_rss?>"><?=wp_specialchars($link->link_rss)?></a></strong>
|
265 |
-
<
|
266 |
title="Check feed <<?=wp_specialchars($link->link_rss)?>> for validity"
|
267 |
href="http://feedvalidator.org/check.cgi?url=<?=urlencode($link->link_rss)?>"><img
|
268 |
src="../wp-images/smilies/icon_arrow.gif" alt="→" /></a></td>
|
@@ -595,9 +649,9 @@ class FeedWordPress {
|
|
595 |
} // function acquire_feeds ()
|
596 |
|
597 |
function update ($uri) {
|
598 |
-
if (FEEDWORDPRESS_LOG_UPDATES) error_log("[".date('Y-m-d H:i:s')."][feedwordpress] update('$uri')");
|
599 |
-
|
600 |
global $wpdb;
|
|
|
|
|
601 |
|
602 |
// Secret voodoo tag: URI for updating *everything*.
|
603 |
$secret = RPC_MAGIC.FeedWordPress::rpc_secret();
|
@@ -611,24 +665,16 @@ class FeedWordPress {
|
|
611 |
or ($uri === $feed['url'])
|
612 |
or ($uri === $feed['feed/link'])) {
|
613 |
if (is_null($delta)) $delta = array('new' => 0, 'updated' => 0);
|
614 |
-
|
615 |
$added = $this->feed2wp($wpdb, $feed);
|
616 |
if (isset($added['new'])) $delta['new'] += $added['new'];
|
617 |
if (isset($added['updated'])) $delta['updated'] += $added['updated'];
|
618 |
} /* if */
|
619 |
} /* foreach */
|
620 |
|
|
|
621 |
fwp_release_pings();
|
622 |
-
|
623 |
-
$mesg = array();
|
624 |
-
if (isset($delta['new'])) { $mesg[] = 'added '.$delta['new'].' new posts'; }
|
625 |
-
if (isset($delta['updated'])) { $mesg[] = 'updated '.$delta['updated'].' existing posts'; }
|
626 |
-
if (empty($mesg)) { $mesg[] = 'nothing changed'; }
|
627 |
-
|
628 |
-
error_log("[".date('Y-m-d H:i:s')."][feedwordpress] "
|
629 |
-
.(is_null($delta) ? "I don't syndicate <$uri>"
|
630 |
-
: implode(' and ', $mesg)));
|
631 |
-
endif;
|
632 |
return $delta;
|
633 |
}
|
634 |
|
@@ -638,13 +684,15 @@ class FeedWordPress {
|
|
638 |
|
639 |
$this->update_feed($wpdb, $feed->channel, $f);
|
640 |
|
641 |
-
if (is_array($feed->items))
|
642 |
-
foreach ($feed->items as $item)
|
643 |
$post = $this->item_to_post($wpdb, $item, $feed->channel, $f);
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
|
|
|
|
648 |
return $new_count;
|
649 |
} // function feed2wp ()
|
650 |
|
@@ -724,134 +772,170 @@ class FeedWordPress {
|
|
724 |
");
|
725 |
} // function FeedWordPress::update_feed ()
|
726 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
727 |
function item_to_post($wpdb, $item, $channel, $f) {
|
728 |
$post = array();
|
729 |
-
$post['post_title'] = $wpdb->escape($item['title']);
|
730 |
-
|
731 |
-
$author = array ();
|
732 |
-
if (isset($item['dc']['creator'])):
|
733 |
-
$author['name'] = $item['dc']['creator'];
|
734 |
-
elseif (isset($item['dc']['creator'])):
|
735 |
-
$author['name'] = $item['dc']['contributor'];
|
736 |
-
elseif (isset($item['author_name'])):
|
737 |
-
$author['name'] = $item['author_name'];
|
738 |
-
else:
|
739 |
-
$author['name'] = $channel['title'];
|
740 |
-
endif;
|
741 |
|
742 |
-
|
743 |
-
|
744 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
745 |
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
751 |
|
752 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
753 |
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
foreach ($this->uri_attrs as $pair):
|
772 |
-
list($tag,$attr) = $pair;
|
773 |
-
$content = preg_replace_callback (
|
774 |
-
":(<$tag [^>]*$attr=\")([^\">]*)(\"[^>]*>):i",
|
775 |
-
array(&$this,'resolve_relative_uri'),
|
776 |
-
$content
|
777 |
-
);
|
778 |
-
endforeach;
|
779 |
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
$content
|
787 |
-
);
|
788 |
-
endforeach;
|
789 |
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
if (isset($item['modified'])):
|
811 |
-
$post['epoch']['modified'] = parse_w3cdtf($item['modified']);
|
812 |
-
else:
|
813 |
-
$post['epoch']['modified'] = $post['epoch']['issued'];
|
814 |
-
endif;
|
815 |
-
|
816 |
-
$post['post_date'] = date('Y-m-d H:i:s', $post['epoch']['issued']);
|
817 |
-
$post['post_modified'] = date('Y-m-d H:i:s', $post['epoch']['modified']);
|
818 |
-
$post['post_date_gmt'] = gmdate('Y-m-d H:i:s', $post['epoch']['issued']);
|
819 |
-
$post['post_modified_gmt'] = gmdate('Y-m-d H:i:s', $post['epoch']['modified']);
|
820 |
-
|
821 |
-
# Use feed-level preferences or a sensible default.
|
822 |
-
$post['post_status'] = (isset($f['post status']) ? $wpdb->escape(trim(strtolower($f['post status']))) : 'publish');
|
823 |
-
$post['comment_status'] = (isset($f['comment status']) ? $wpdb->escape(trim(strtolower($f['comment status']))) : 'closed');
|
824 |
-
$post['ping_status'] = (isset($f['ping status']) ? $wpdb->escape(trim(strtolower($f['ping status']))) : 'closed');
|
825 |
-
|
826 |
-
// Unique ID (hopefully a unique tag: URI); failing that, the permalink
|
827 |
-
if (isset($item['id'])):
|
828 |
-
$post['guid'] = $wpdb->escape($item['id']);
|
829 |
-
else:
|
830 |
-
$post['guid'] = $wpdb->escape($item['link']);
|
831 |
-
endif;
|
832 |
-
|
833 |
-
if (isset($channel['title'])) $post['syndication_source'] = $channel['title'];
|
834 |
-
if (isset($channel['link'])) $post['syndication_source_uri'] = $channel['link'];
|
835 |
-
$post['syndication_feed'] = $f['url'];
|
836 |
-
|
837 |
-
// In case you want to know the external permalink...
|
838 |
-
$post['syndication_permalink'] = $item['link'];
|
839 |
-
|
840 |
-
// Categories: start with default categories
|
841 |
-
$item_cats = $f['cats'];
|
842 |
-
|
843 |
-
// Now add categories from the post, if we have 'em
|
844 |
-
if (is_array($item['categories'])):
|
845 |
-
foreach ($item['categories'] as $cat):
|
846 |
-
if ( strpos($f['url'], 'del.icio.us') !== false ):
|
847 |
-
$item_cats = array_merge($item_cats, explode(' ', $cat));
|
848 |
-
else:
|
849 |
-
$item_cats[] = $cat;
|
850 |
-
endif;
|
851 |
-
endforeach;
|
852 |
endif;
|
853 |
-
$post['post_category'] = $this->lookup_categories($wpdb, $item_cats);
|
854 |
-
|
855 |
return $post;
|
856 |
} // function FeedWordPress::item_to_post ()
|
857 |
|
@@ -863,7 +947,37 @@ class FeedWordPress {
|
|
863 |
");
|
864 |
|
865 |
if (!$result):
|
866 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
867 |
# The right way to do this would be to use:
|
868 |
#
|
869 |
# $postId = wp_insert_post($post);
|
@@ -909,11 +1023,13 @@ class FeedWordPress {
|
|
909 |
// able to use).
|
910 |
do_action('publish_post', $postId);
|
911 |
# --- cut here ---
|
912 |
-
|
913 |
-
if (FEEDWORDPRESS_LOG_UPDATES) error_log("[".date('Y-m-d H:i:s')."][feedwordpress] posted '".$post['post_title']."' (".$post['post_date'].") from '".$post['syndication_source']."'");
|
914 |
$this->add_rss_meta($wpdb, $postId, $post);
|
|
|
|
|
|
|
915 |
$ret = 'new';
|
916 |
-
elseif ($
|
917 |
$postId = $result->id; $modified = $result->modified;
|
918 |
|
919 |
$result = $wpdb->query("
|
@@ -937,18 +1053,10 @@ class FeedWordPress {
|
|
937 |
// able to use).
|
938 |
do_action('edit_post', $postId);
|
939 |
|
940 |
-
if (FEEDWORDPRESS_LOG_UPDATES):
|
941 |
-
error_log("[".date('Y-m-d H:i:s')
|
942 |
-
."][feedwordpress] updated '"
|
943 |
-
.$post['post_title']
|
944 |
-
."' (".$post['post_date']
|
945 |
-
.") from '".$post['syndication_source']
|
946 |
-
."' (".date('Y-m-d H:i:s', $modified)
|
947 |
-
." ==> "
|
948 |
-
.date('Y-m-d H:i:s', $post['epoch']['modified'])
|
949 |
-
.')');
|
950 |
-
endif;
|
951 |
$this->add_rss_meta($wpdb, $postId, $post);
|
|
|
|
|
|
|
952 |
$ret = 'updated';
|
953 |
else:
|
954 |
$ret = false;
|
@@ -1087,7 +1195,7 @@ class FeedWordPress {
|
|
1087 |
function rpc_secret () {
|
1088 |
return get_settings('feedwordpress_rpc_secret');
|
1089 |
} // function FeedWordPress::rpc_secret ()
|
1090 |
-
|
1091 |
function link_category_id () {
|
1092 |
global $wpdb;
|
1093 |
|
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.9
|
7 |
Author: Charles Johnson
|
8 |
Author URI: http://www.radgeek.com/
|
9 |
*/
|
10 |
|
11 |
# Author: Charles Johnson <technophilia@radgeek.com>
|
12 |
# License: GPL
|
13 |
+
# Last modified: 2005-03-25
|
14 |
#
|
15 |
# This uses code derived from:
|
16 |
# - wp-rss-aggregate.php by Kellan Elliot-McCrea <kellan@protest.net>
|
32 |
|
33 |
# -- Don't change these unless you know what you're doing...
|
34 |
define ('RPC_MAGIC', 'tag:radgeek.com/projects/feedwordpress/');
|
35 |
+
define ('FEEDWORDPRESS_VERSION', '0.9');
|
36 |
define ('DEFAULT_SYNDICATION_CATEGORY', 'Contributors');
|
37 |
|
38 |
// Note that the rss-functions.php that comes prepackaged with WordPress is
|
76 |
remove_action('publish_post', 'generic_ping');
|
77 |
add_action('publish_post', 'fwp_catch_ping');
|
78 |
|
79 |
+
$update_logging = get_settings('feedwordpress_update_logging');
|
80 |
+
|
81 |
+
# -- Logging status updates to error_log, if you want it
|
82 |
+
if ($update_logging == 'yes') :
|
83 |
+
add_action('post_syndicated_item', 'log_feedwordpress_post', 100);
|
84 |
+
add_action('update_syndicated_item', 'log_feedwordpress_update_post', 100);
|
85 |
+
add_action('feedwordpress_update', 'log_feedwordpress_update_feeds', 100);
|
86 |
+
add_action('feedwordpress_check_feed', 'log_feedwordpress_check_feed', 100);
|
87 |
+
add_action('feedwordpress_update_complete', 'log_feedwordpress_update_complete', 100);
|
88 |
+
|
89 |
+
function log_feedwordpress_post ($id) {
|
90 |
+
$post = wp_get_single_post($id);
|
91 |
+
error_log("[".date('Y-m-d H:i:s')."][feedwordpress] posted "
|
92 |
+
."'{$post->post_title}' ({$post->post_date})");
|
93 |
+
}
|
94 |
+
|
95 |
+
function log_feedwordpress_update_post ($id) {
|
96 |
+
$post = wp_get_single_post($id);
|
97 |
+
error_log("[".date('Y-m-d H:i:s')."][feedwordpress] updated "
|
98 |
+
."'{$post->post_title}' ({$post->post_date})"
|
99 |
+
." (as of {$post->post_modified})");
|
100 |
+
}
|
101 |
+
|
102 |
+
function log_feedwordpress_update_feeds ($uri) {
|
103 |
+
error_log("[".date('Y-m-d H:i:s')."][feedwordpress] update('$uri')");
|
104 |
+
}
|
105 |
+
|
106 |
+
function log_feedwordpress_check_feed ($feed) {
|
107 |
+
$uri = $feed['url']; $name = $feed['name'];
|
108 |
+
error_log("[".date('Y-m-d H:i:s')."][feedwordpress] Examining $name <$uri>");
|
109 |
+
}
|
110 |
+
|
111 |
+
function log_feedwordpress_update_complete ($delta) {
|
112 |
+
$mesg = array();
|
113 |
+
if (isset($delta['new'])) $mesg[] = 'added '.$delta['new'].' new posts';
|
114 |
+
if (isset($delta['updated'])) $mesg[] = 'updated '.$delta['updated'].' existing posts';
|
115 |
+
if (empty($mesg)) $mesg[] = 'nothing changed';
|
116 |
+
|
117 |
+
error_log("[".date('Y-m-d H:i:s')."][feedwordpress] "
|
118 |
+
.(is_null($delta) ? "I don't syndicate <$uri>"
|
119 |
+
: implode(' and ', $mesg)));
|
120 |
+
}
|
121 |
+
endif;
|
122 |
+
|
123 |
# -- Template functions for syndication sites
|
124 |
function is_syndicated () { return (strlen(get_syndication_feed()) > 0); }
|
125 |
|
173 |
# -- Admin menu add-ons
|
174 |
function fwp_add_pages () {
|
175 |
add_submenu_page('link-manager.php', 'Syndicated Sites', 'Syndicated', 5, __FILE__, 'fwp_syndication_manage_page');
|
176 |
+
add_options_page('Syndication', 'Syndication', 6, __FILE__, 'fwp_syndication_options_page');
|
177 |
} // function fwp_add_pages () */
|
178 |
|
179 |
function fwp_syndication_options_page () {
|
183 |
if (isset($_REQUEST['action']) and $_REQUEST['action']=$caption):
|
184 |
check_admin_referer();
|
185 |
|
186 |
+
if ($user_level < 6):
|
187 |
die (__("Cheatin' uh ?"));
|
188 |
else:
|
189 |
update_option('feedwordpress_rpc_secret', $_REQUEST['rpc_secret']);
|
190 |
update_option('feedwordpress_cat_id', $_REQUEST['syndication_category']);
|
191 |
update_option('feedwordpress_munge_permalink', $_REQUEST['munge_permalink']);
|
192 |
+
update_option('feedwordpress_update_logging', $_REQUEST['update_logging']);
|
193 |
?>
|
194 |
<div class="updated">
|
195 |
<p><?php _e('Options saved.')?></p>
|
201 |
$cat_id = FeedWordPress::link_category_id();
|
202 |
$rpc_secret = FeedWordPress::rpc_secret();
|
203 |
$munge_permalink = get_settings('feedwordpress_munge_permalink');
|
204 |
+
$update_logging = get_settings('feedwordpress_update_logging');
|
205 |
$results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY cat_id");
|
206 |
?>
|
207 |
<div class="wrap">
|
251 |
<th width="33%" scope="row">XML-RPC update secret word:</th>
|
252 |
<td width="67%"><input id="rpc_secret" name="rpc_secret" value="<?=$rpc_secret?>" />
|
253 |
</td>
|
254 |
+
</tr>
|
255 |
+
<tr>
|
256 |
+
<th scope="row">Write update notices to PHP logs:</th>
|
257 |
+
<td><select name="update_logging" size="1">
|
258 |
+
<option value="yes"<?=(($update_logging=='yes')?' selected="selected"':'')?>>yes</option>
|
259 |
+
<option value="no"<?=(($update_logging!='yes')?' selected="selected"':'')?>>no</option>
|
260 |
+
</select></td>
|
261 |
+
</tr>
|
262 |
</table>
|
263 |
<div class="submit"><input type="submit" name="action" value="<?=$caption?>" /></div>
|
264 |
</fieldset>
|
316 |
<?php if (strlen($link->link_rss) > 0): $caption='Switch Feed'; ?>
|
317 |
<td style="font-size:smaller;text-align:center">
|
318 |
<strong><a href="<?=$link->link_rss?>"><?=wp_specialchars($link->link_rss)?></a></strong>
|
319 |
+
<em>check validity</em> <a style="vertical-align:middle"
|
320 |
title="Check feed <<?=wp_specialchars($link->link_rss)?>> for validity"
|
321 |
href="http://feedvalidator.org/check.cgi?url=<?=urlencode($link->link_rss)?>"><img
|
322 |
src="../wp-images/smilies/icon_arrow.gif" alt="→" /></a></td>
|
649 |
} // function acquire_feeds ()
|
650 |
|
651 |
function update ($uri) {
|
|
|
|
|
652 |
global $wpdb;
|
653 |
+
|
654 |
+
do_action('feedwordpress_update', $uri);
|
655 |
|
656 |
// Secret voodoo tag: URI for updating *everything*.
|
657 |
$secret = RPC_MAGIC.FeedWordPress::rpc_secret();
|
665 |
or ($uri === $feed['url'])
|
666 |
or ($uri === $feed['feed/link'])) {
|
667 |
if (is_null($delta)) $delta = array('new' => 0, 'updated' => 0);
|
668 |
+
do_action('feedwordpress_check_feed', array($feed));
|
669 |
$added = $this->feed2wp($wpdb, $feed);
|
670 |
if (isset($added['new'])) $delta['new'] += $added['new'];
|
671 |
if (isset($added['updated'])) $delta['updated'] += $added['updated'];
|
672 |
} /* if */
|
673 |
} /* foreach */
|
674 |
|
675 |
+
do_action('feedwordpress_update_complete', array($delta));
|
676 |
fwp_release_pings();
|
677 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
678 |
return $delta;
|
679 |
}
|
680 |
|
684 |
|
685 |
$this->update_feed($wpdb, $feed->channel, $f);
|
686 |
|
687 |
+
if (is_array($feed->items)) :
|
688 |
+
foreach ($feed->items as $item) :
|
689 |
$post = $this->item_to_post($wpdb, $item, $feed->channel, $f);
|
690 |
+
if (!is_null($post)) :
|
691 |
+
$new = $this->add_post($wpdb, $post);
|
692 |
+
if ( $new !== false ) $new_count[$new]++;
|
693 |
+
endif;
|
694 |
+
endforeach;
|
695 |
+
endif;
|
696 |
return $new_count;
|
697 |
} // function feed2wp ()
|
698 |
|
772 |
");
|
773 |
} // function FeedWordPress::update_feed ()
|
774 |
|
775 |
+
// item_to_post(): convert information from a single item from an
|
776 |
+
// Atom/RSS feed to a post for WordPress's database.
|
777 |
+
//
|
778 |
+
// item_to_post() invokes the syndicated_item filter on each item it
|
779 |
+
// receives. Filters should return either (a) the item unmodified,
|
780 |
+
// (b) the item modified according to the rules of the filter, or
|
781 |
+
// (c) NULL. A NULL item will not be posted into the database.
|
782 |
+
//
|
783 |
+
// N.B.: item_to_post and the syndicate_item filter really ought to have
|
784 |
+
// *no* side effects on the WordPress database (that's why, for example,
|
785 |
+
// we handle lookup/creation of numeric author and category IDs in
|
786 |
+
// add_post()). If you want plugins that have side effects on the posts
|
787 |
+
// database, you should probably hook into the action
|
788 |
+
// post_syndicated_item
|
789 |
+
//
|
790 |
function item_to_post($wpdb, $item, $channel, $f) {
|
791 |
$post = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
792 |
|
793 |
+
// This is ugly as all hell. I'd like to use apply_filters()'s
|
794 |
+
// alleged support for a variable argument count, but this seems
|
795 |
+
// to have been broken in WordPress 1.5. It'll be fixed somehow
|
796 |
+
// in WP 1.5.1, but I'm aiming at WP 1.5 compatibility across
|
797 |
+
// the board here.
|
798 |
+
//
|
799 |
+
// Cf.: <http://mosquito.wordpress.org/view.php?id=901>
|
800 |
+
global $fwp_channel, $fwp_feedmeta;
|
801 |
+
$fwp_channel = $channel; $fwp_feedmeta = $f;
|
802 |
+
$item = apply_filters('syndicated_item', $item);
|
803 |
|
804 |
+
// Filters can halt further processing by returning NULL
|
805 |
+
if (is_null($item)) :
|
806 |
+
$post = NULL;
|
807 |
+
else :
|
808 |
+
$post['post_title'] = $wpdb->escape($item['title']);
|
809 |
+
|
810 |
+
$post['named']['author'] = array ();
|
811 |
+
if (isset($item['dc']['creator'])):
|
812 |
+
$post['named']['author']['name'] = $item['dc']['creator'];
|
813 |
+
elseif (isset($item['dc']['creator'])):
|
814 |
+
$post['named']['author']['name'] = $item['dc']['contributor'];
|
815 |
+
elseif (isset($item['author_name'])):
|
816 |
+
$post['named']['author']['name'] = $item['author_name'];
|
817 |
+
else:
|
818 |
+
$post['named']['author']['name'] = $channel['title'];
|
819 |
+
endif;
|
820 |
+
|
821 |
+
if (isset($item['author_email'])):
|
822 |
+
$post['named']['author']['email'] = $item['author_email'];
|
823 |
+
endif;
|
824 |
+
|
825 |
+
if (isset($item['author_url'])):
|
826 |
+
$post['named']['author']['url'] = $item['author_url'];
|
827 |
+
else:
|
828 |
+
$post['named']['author']['url'] = $channel['link'];
|
829 |
+
endif;
|
830 |
+
|
831 |
+
// ... So far we just have an alphanumeric
|
832 |
+
// representation of the author. We will look up (or
|
833 |
+
// create) the numeric ID for the author in
|
834 |
+
// FeedWordPress::add_post()
|
835 |
+
|
836 |
+
# Identify content and sanitize it.
|
837 |
+
# ---------------------------------
|
838 |
+
if (isset($item['content']['encoded']) and $item['content']['encoded']):
|
839 |
+
$content = $item['content']['encoded'];
|
840 |
+
else:
|
841 |
+
$content = $item['description'];
|
842 |
+
endif;
|
843 |
+
|
844 |
+
# Resolve relative URIs in post content
|
845 |
+
#
|
846 |
+
# N.B.: We *might* get screwed over by xml:base. But I don't see
|
847 |
+
# any way to get that information out of MagpieRSS if it's
|
848 |
+
# in the feed, and if it's in the content itself we'd have
|
849 |
+
# to do yet more XML parsing to do things right. For now
|
850 |
+
# this will have to do.
|
851 |
|
852 |
+
$this->_base = $item['link']; // Reset the base for resolving relative URIs
|
853 |
+
foreach ($this->uri_attrs as $pair):
|
854 |
+
list($tag,$attr) = $pair;
|
855 |
+
$content = preg_replace_callback (
|
856 |
+
":(<$tag [^>]*$attr=\")([^\">]*)(\"[^>]*>):i",
|
857 |
+
array(&$this,'resolve_relative_uri'),
|
858 |
+
$content
|
859 |
+
);
|
860 |
+
endforeach;
|
861 |
+
|
862 |
+
# Sanitize problematic attributes
|
863 |
+
foreach ($this->strip_attrs as $pair):
|
864 |
+
list($tag,$attr) = $pair;
|
865 |
+
$content = preg_replace (
|
866 |
+
":(<$tag [^>]*)($attr=(\"[^\">]*\"|[^>\\s]+))([^>]*>):i",
|
867 |
+
"\\1\\4",
|
868 |
+
$content
|
869 |
+
);
|
870 |
+
endforeach;
|
871 |
+
|
872 |
+
$post['post_content'] = $wpdb->escape($content);
|
873 |
+
|
874 |
+
# This is unneeded if wp_insert_post can be used.
|
875 |
+
# --- cut here ---
|
876 |
+
$post['post_name'] = sanitize_title($post['post_title']);
|
877 |
+
# --- cut here ---
|
878 |
+
|
879 |
+
# RSS is a fucking mess. Figure out whether we have a date in
|
880 |
+
# dc:date, <issued>, <pubDate>, etc., and get it into Unix epoch
|
881 |
+
# format for reformatting. If you can't find anything, use the
|
882 |
+
# current time.
|
883 |
+
if (isset($item['dc']['date'])):
|
884 |
+
$post['epoch']['issued'] = parse_w3cdtf($item['dc']['date']);
|
885 |
+
elseif (isset($item['issued'])):
|
886 |
+
$post['epoch']['issued'] = parse_w3cdtf($item['issued']);
|
887 |
+
elseif (isset($item['pubdate'])):
|
888 |
+
$post['epoch']['issued'] = strtotime($item['pubdate']);
|
889 |
+
else:
|
890 |
+
$post['epoch']['issued'] = time();
|
891 |
+
endif;
|
892 |
|
893 |
+
# As far as I know, only atom currently has a reliable way to
|
894 |
+
# specify when something was *modified* last
|
895 |
+
if (isset($item['modified'])):
|
896 |
+
$post['epoch']['modified'] = parse_w3cdtf($item['modified']);
|
897 |
+
else:
|
898 |
+
$post['epoch']['modified'] = $post['epoch']['issued'];
|
899 |
+
endif;
|
900 |
|
901 |
+
$post['post_date'] = date('Y-m-d H:i:s', $post['epoch']['issued']);
|
902 |
+
$post['post_modified'] = date('Y-m-d H:i:s', $post['epoch']['modified']);
|
903 |
+
$post['post_date_gmt'] = gmdate('Y-m-d H:i:s', $post['epoch']['issued']);
|
904 |
+
$post['post_modified_gmt'] = gmdate('Y-m-d H:i:s', $post['epoch']['modified']);
|
905 |
+
|
906 |
+
# Use feed-level preferences or a sensible default.
|
907 |
+
$post['post_status'] = (isset($f['post status']) ? $wpdb->escape(trim(strtolower($f['post status']))) : 'publish');
|
908 |
+
$post['comment_status'] = (isset($f['comment status']) ? $wpdb->escape(trim(strtolower($f['comment status']))) : 'closed');
|
909 |
+
$post['ping_status'] = (isset($f['ping status']) ? $wpdb->escape(trim(strtolower($f['ping status']))) : 'closed');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
910 |
|
911 |
+
// Unique ID (hopefully a unique tag: URI); failing that, the permalink
|
912 |
+
if (isset($item['id'])):
|
913 |
+
$post['guid'] = $wpdb->escape($item['id']);
|
914 |
+
else:
|
915 |
+
$post['guid'] = $wpdb->escape($item['link']);
|
916 |
+
endif;
|
|
|
|
|
|
|
917 |
|
918 |
+
if (isset($channel['title'])) $post['syndication_source'] = $channel['title'];
|
919 |
+
if (isset($channel['link'])) $post['syndication_source_uri'] = $channel['link'];
|
920 |
+
$post['syndication_feed'] = $f['url'];
|
921 |
|
922 |
+
// In case you want to know the external permalink...
|
923 |
+
$post['syndication_permalink'] = $item['link'];
|
924 |
+
|
925 |
+
// Categories: start with default categories
|
926 |
+
$post['named']['category'] = $f['cats'];
|
927 |
+
|
928 |
+
// Now add categories from the post, if we have 'em
|
929 |
+
if (is_array($item['categories'])):
|
930 |
+
foreach ($item['categories'] as $cat):
|
931 |
+
if ( strpos($f['url'], 'del.icio.us') !== false ):
|
932 |
+
$post['named']['category'] = array_merge($post['named']['category'], explode(' ', $cat));
|
933 |
+
else:
|
934 |
+
$post['named']['category'][] = $cat;
|
935 |
+
endif;
|
936 |
+
endforeach;
|
937 |
+
endif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
938 |
endif;
|
|
|
|
|
939 |
return $post;
|
940 |
} // function FeedWordPress::item_to_post ()
|
941 |
|
947 |
");
|
948 |
|
949 |
if (!$result):
|
950 |
+
$freshness = 2; // New content
|
951 |
+
elseif ($post['epoch']['modified'] > $result->modified):
|
952 |
+
$freshness = 1; // Updated content
|
953 |
+
else:
|
954 |
+
$freshness = 0;
|
955 |
+
endif;
|
956 |
+
|
957 |
+
if ($freshness > 0) :
|
958 |
+
# -- Look up, or create, numeric ID for author
|
959 |
+
$post['post_author'] = $this->author_to_id (
|
960 |
+
$wpdb,
|
961 |
+
$post['named']['author']['name'],
|
962 |
+
$post['named']['author']['email'],
|
963 |
+
$post['named']['author']['url']
|
964 |
+
);
|
965 |
+
|
966 |
+
# -- Look up, or create, numeric ID for categories
|
967 |
+
$post['post_category'] = $this->lookup_categories (
|
968 |
+
$wpdb,
|
969 |
+
$post['named']['category']
|
970 |
+
);
|
971 |
+
|
972 |
+
unset($post['named']);
|
973 |
+
endif;
|
974 |
+
|
975 |
+
$post = apply_filters('syndicated_post', $post);
|
976 |
+
if (is_null($post)) $freshness = 0;
|
977 |
+
|
978 |
+
if ($freshness == 2) :
|
979 |
+
// The item has not yet been added. So let's add it.
|
980 |
+
|
981 |
# The right way to do this would be to use:
|
982 |
#
|
983 |
# $postId = wp_insert_post($post);
|
1023 |
// able to use).
|
1024 |
do_action('publish_post', $postId);
|
1025 |
# --- cut here ---
|
1026 |
+
|
|
|
1027 |
$this->add_rss_meta($wpdb, $postId, $post);
|
1028 |
+
|
1029 |
+
do_action('post_syndicated_item', $postId);
|
1030 |
+
|
1031 |
$ret = 'new';
|
1032 |
+
elseif ($freshness == 1) :
|
1033 |
$postId = $result->id; $modified = $result->modified;
|
1034 |
|
1035 |
$result = $wpdb->query("
|
1053 |
// able to use).
|
1054 |
do_action('edit_post', $postId);
|
1055 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1056 |
$this->add_rss_meta($wpdb, $postId, $post);
|
1057 |
+
|
1058 |
+
do_action('update_syndicated_item', $postId);
|
1059 |
+
|
1060 |
$ret = 'updated';
|
1061 |
else:
|
1062 |
$ret = false;
|
1195 |
function rpc_secret () {
|
1196 |
return get_settings('feedwordpress_rpc_secret');
|
1197 |
} // function FeedWordPress::rpc_secret ()
|
1198 |
+
|
1199 |
function link_category_id () {
|
1200 |
global $wpdb;
|
1201 |
|