PluginProbe
FeedWordPress / 0.98
FeedWordPress v0.98
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/update-feeds.php +147 -49 0.950.98 View file →
@@ -4,9 +4,9 @@
4 4 # Project: FeedWordPress
5 5 # URI: <http://projects.radgeek.com/feedwordpress>
6 6 # Author: Charles Johnson <technophilia@radgeek.com>
7 7 # License: GPL
8 -# Version: 2005.04.09
8 +# Version: 2005.11.06
9 9 #
10 10 # USAGE
11 11 # -----
12 12 # update-feeds.php is a useful script for instructing the FeedWordPress plugin
@@ -17,48 +17,120 @@
17 17 # 1. Install FeedWordPress and activate the FeedWordPress plugin. (See
18 18 # <http://projects.radgeek.com/feedwordpress/install> if you need a guide
19 19 # for the perplexed.)
20 20 #
21 -# 2. Set up a cron job to run update-feeds.php locally:
21 +# 2. If you want to manually update one or more of your feeds, you can do
22 +# so by pointing your web browser to the URI
23 +# <http://xyz.com/wp-content/update-feeds.php>, where `http://xyz.com/` is
24 +# replaced by the URI to your installation of WordPress. Log in as any
25 +# user in your WordPress database and use the form to update.
22 26 #
23 -# cd <your-wordpress>/wp-content ; php update-feeds.php
27 +# 3. To keep content up-to-date automatically, set up a cron job to run
28 +# update-feeds.php locally:
24 29 #
25 -# or to send an HTTP GET request to the appropriate URI:
30 +# cd /path/to/wordpress/wp-content ; php update-feeds.php
26 31 #
27 -# curl http://xyz.com/wp-content/update-feeds.php?shibboleth=foo
32 +# where `/path/to/wordpress` is replaced by the filesystem path to your
33 +# installation of WordPress; or, if you don't have, or don't want to use,
34 +# command-line PHP, you can send an HTTP POST request to the appropriate
35 +# URI:
28 36 #
37 +# curl --user user:pass http://xyz.com/wp-content/update-feeds.php -d update=quiet
38 +#
39 +# `user` and `pass` should be replaced by the username and password of
40 +# a user in your WordPress database (you can create a dummy user for
41 +# updates if you want; that's what I do). `http://xyz.com/` should be
42 +# replaced by the URI to your installation of WordPress.
43 +#
44 +# Don't be afraid to run this cron job frequently. FeedWordPress staggers
45 +# updates over time rather than checking all of the feeds every time the
46 +# cron job runs, so even if the cron job runs every 10 minutes, each feed
47 +# will, on average only be polled for updates once an hour or so (or less
48 +# frequently if the feed author requests less frequent updates using
49 +# the RSS <ttl> element or the syndication module elements).
50 +#
29 51 # 4. If you want to update *one* of the feeds rather than *all* of them, then
30 52 # pass the URI and title as command-line arguments:
31 53 #
32 -# $ php update-feeds.php http://www.radgeek.com "Geekery Today"
54 +# $ php update-feeds.php http://radgeek.com
33 55 #
34 -# or in the GET query:
56 +# or in the POST request:
35 57 #
36 -# $ curl http://www.xyz.com/wp-content/update-feeds.php?uri=http://www.radgeek.com\&title=Geekery+Today\&shibboleth=yourshibboleth
58 +# $ curl --user login:password http://xyz.com/wp-content/update-feeds.php -d uri=http://www.radgeek.com\&update=quiet
37 59 #
60 +// Help us to pick out errors, if any.
61 +ini_set('error_reporting', E_ALL & ~E_NOTICE);
62 +ini_set('display_errors', true);
63 +define('MAGPIE_DEBUG', true);
38 64
39 -require_once ('../wp-config.php');
40 -require_once (ABSPATH . WPINC . '/class-IXR.php');
65 +// Are we running from a web request or from the command line?
66 +if (!isset($_SERVER['REQUEST_URI'])) :
67 + $update_feeds_display = 'text/plain';
68 + $update_feeds_invoke = 'cmd';
69 +elseif (isset($_POST['update'])) :
70 + if ($_POST['update'] == 'quiet') :
71 + $update_feeds_display = 'text/plain';
72 + $update_feeds_invoke = 'post';
73 + $update_feeds_verbose = false;
74 + elseif ($_POST['update'] == 'verbose') :
75 + $update_feeds_display = 'text/plain';
76 + $update_feeds_invoke = 'post';
77 + $update_feeds_verbose = true;
78 + else :
79 + $update_feeds_display = 'text/html';
80 + $update_feeds_invoke = 'post';
81 + endif;
82 +else :
83 + $update_feeds_display = 'text/html';
84 + $update_feeds_invoke = 'get';
85 +endif;
41 86
87 +require_once ('../wp-blog-header.php');
88 +
89 +function update_feeds_mention ($feed) {
90 + global $update_feeds_display;
91 +
92 + if ($update_feeds_display=='text/html') :
93 + echo "<li>Updating <cite>".$feed['link/name']."</cite> from &lt;<a href=\""
94 + .$feed['link/uri']."\">".$feed['link/uri']."</a>&gt; ...</li>\n";
95 + else :
96 + echo "* Updating ".$feed['link/name']." from <".$feed['link/uri']."> ...\n";
97 + endif;
98 + flush();
99 +}
100 +
42 101 # -- Don't change these unless you know what you're doing...
43 -define ('RPC_URI', NULL); // Change this setting to ping a URI of your own devising
44 102 define ('RPC_MAGIC', 'tag:radgeek.com/projects/feedwordpress/'); // update all
45 103
46 -if (is_null(RPC_URI)):
47 - $rpc_uri = get_settings('siteurl');
48 - if (substr($rpc_uri,-1)!='/') $rpc_uri .= '/';
49 - $rpc_uri .= 'xmlrpc.php';
50 -else:
51 - $rpc_uri = RPC_URI;
52 -endif;
104 +// Query secret word from database
105 +$rpc_secret = get_settings('feedwordpress_rpc_secret');
53 106
54 -# -- Are we running from an HTTP GET or from the command line?
55 -if (isset($_SERVER['REQUEST_URI'])) {
56 - $rpc_secret = (isset($_REQUEST['shibboleth'])?$_REQUEST['shibboleth']:'');
107 +header("Content-Type: {$update_feeds_display}; charset=utf-8");
108 +
109 +# -- Are we running from an HTTP GET, HTTP POST, or from the command line?
110 +if ($update_feeds_invoke != 'cmd') : // We're acessing this from HTTP GET or HTTP POST
111 + // Authenticate the user, if possible ...
112 + if (isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW'])) : // try HTTP authentication
113 + $login = $_SERVER['PHP_AUTH_USER']; $pass = $_SERVER['PHP_AUTH_PW'];
114 + elseif (isset($_POST['log']) and isset($_POST['pwd'])) : // try POST data
115 + $login = $_REQUEST['log']; $pass = $_REQUEST['pwd'];
116 + endif;
117 +
118 + if (empty($login) or empty($pass) or !wp_login($login, $pass)) :
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;
126 +
127 + // Henceforward, we can proceed on the assumption that we have an authenticated user
57 128 $uri = (isset($_REQUEST['uri']) ? $_REQUEST['uri'] : RPC_MAGIC.$rpc_secret);
58 - $blog = (isset($_REQUEST['title']) ? $_REQUEST['title'] : 'Refresh');
59 129
60 - echo <<< EOHTML
130 + if ($update_feeds_display=='text/html') :
131 + echo <<<EOHTML
132 +<?xml version="1.0" encoding="utf-8"?>
61 133 <html>
62 134 <head>
63 135 <title>update-feeds :: FeedWordPress</title>
64 136 </head>
@@ -63,45 +135,71 @@
63 135 <title>update-feeds :: FeedWordPress</title>
64 136 </head>
65 137
66 138 <body>
67 -<h1>update-feeds: instruct FeedWordPress to look for new syndicated content</h1>
139 +<h1>update-feeds: make FeedWordPress check for new syndicated content</h1>
68 140
69 -<p>Sending ping to &lt;$rpc_uri&gt;...</p>
141 +EOHTML;
142 + endif;
143 +else :
144 + // update-feeds has been invoked from the command line; no further
145 + // authentication is necessary. (If PAM hasn't already done the
146 + // necessary screening for you, you have bigger problems than their
147 + // access to FeedWordPress...)
148 + $uri = (isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : RPC_MAGIC.$rpc_secret);
149 +endif;
70 150
71 -<p>
72 -EOHTML;
73 -} else {
74 - // Query secret word from database
75 - $rpc_secret = get_settings('feedwordpress_rpc_secret');
151 +$feedwordpress =& new FeedWordPress;
76 152
77 - $uri = (isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : RPC_MAGIC.$rpc_secret);
78 - $blog = (isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : 'Refresh');
79 -}
153 +if ($update_feeds_display=='text/html' or $update_feeds_verbose) :
154 + add_action('feedwordpress_check_feed', 'update_feeds_mention');
155 +endif;
80 156
81 -$client =& new IXR_Client($rpc_uri);
82 -$ret = $client->query('weblogUpdates.ping', $blog, $uri);
157 +if ($update_feeds_display=='text/html') : // HTTP GET or HTTP POST: add some web niceties
83 158
84 -if (!$ret):
85 - if (!isset($_SERVER['REQUEST_URI'])) echo "[".date('Y-m-d H:i:s')."][update-feeds] ";
86 - echo "The XML-RPC ping failed (local): ".wp_specialchars($client->getErrorMessage())."\n";
87 -else:
88 - $response = $client->getResponse();
89 - if ($response['flerror']):
90 - if (!isset($_SERVER['REQUEST_URI'])) echo "[".date('Y-m-d H:i:s')."][update-feeds] ";
91 - echo "The XML-RPC ping failed (remote): ".wp_specialchars($response['message'])."\n";
92 - elseif (isset($_SERVER['REQUEST_URI'])):
93 - if (!isset($_SERVER['REQUEST_URI'])) echo "[".date('Y-m-d H:i:s')."][update-feeds] ";
94 - echo "The XML-RPC ping succeeded: ".wp_specialchars($response['message'])."\n";
159 + echo "<form action=\"\" method=\"POST\">\n";
160 + echo "<select name=\"uri\">\n";
161 + echo "<option value=\"".RPC_MAGIC.$rpc_secret."\">All feeds</option>\n";
162 + foreach ($feedwordpress->feeds as $feed) :
163 + echo "<option value=\"{$feed['link/uri']}\"";
164 + if ($feed['link/uri']==$_REQUEST['uri']) : echo ' selected="selected"'; endif;
165 + echo ">{$feed['link/name']}</option>\n";
166 + endforeach;
167 + echo "</select> ";
168 + echo "<input type=\"submit\" name=\"update\" value=\"Update\" />\n";
169 + echo "</form>\n";
170 +endif;
171 +
172 +if ($update_feeds_invoke != 'get') : // Only do things with side-effects for HTTP POST or command line
173 + if ($update_feeds_display == 'text/html') : echo "<ul>\n"; endif;
174 + $delta = @$feedwordpress->update($uri);
175 + if ($update_feeds_display == 'text/html') : echo "</ul>\n"; endif;
176 +
177 + if (is_null($delta)) :
178 + if ($update_feeds_invoke == 'cmd') :
179 + $stderr = fopen('php://stderr', 'w');
180 + fputs($stderr, "update-feeds (".date('Y-m-d H:i:s')."): ERROR: I don't syndicate <$uri>\n");
181 + elseif ($update_feeds_display == 'text/plain') :
182 + echo "update-feeds (".date('Y-m-d H:i:s')."): ERROR: I don't syndicate <$uri>\n";
183 + else :
184 + echo "<p><strong>Error:</strong> I don't syndicate <a href=\"$uri\">$uri</a></p>\n";
185 + endif;
186 + elseif ($update_feeds_display=='text/html' or $update_feeds_verbose) :
187 + $mesg = array();
188 + if (isset($delta['new'])) : $mesg[] = ' '.$delta['new'].' new posts were syndicated'; endif;
189 + if (isset($delta['updated'])) : $mesg[] = ' '.$delta['updated'].' existing posts were updated'; endif;
190 + if ($update_feeds_display=='text/html') : echo "<p>"; endif;
191 + echo "Update complete.".implode(' and', $mesg);
192 + if ($update_feeds_display=='text/html') : echo "</p>"; endif;
193 + echo "\n"; flush();
95 194 endif;
96 195 endif;
97 196
98 -if (isset($_SERVER['REQUEST_URI'])) {
197 +if ($update_feeds_display=='text/html') : // HTTP GET or HTTP POST: close off web niceties
99 198 echo <<<EOHTML
100 -</p>
101 199
102 200 <p><a href="../wp-admin">&larr; Return to WordPress Dashboard</a></p>
103 201 </body>
104 202 </html>
105 203 EOHTML;
106 -}
204 +endif;
107 205 ?>