From 39388c3f927ceb1ff508b4c759c1199b96acb2b0 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 12 Jun 2013 22:36:33 +0200 Subject: [PATCH] request-feed-update.php --- README.rst | 37 +++++++++++++++++++++++++ data/tables.sql | 12 ++++++++ www/request-feed-update.php | 55 +++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 www/request-feed-update.php diff --git a/README.rst b/README.rst index 9fff7c4..47954d0 100644 --- a/README.rst +++ b/README.rst @@ -2,3 +2,40 @@ stapibas ******** The standalone Pingback server, written in PHP. + + + +================= +Pingback receiver +================= +stapibas receives pingbacks for your website and puts them into a database. + + +Setup +===== +Let your website send out the following HTTP header:: + + X-Pingback: http://stapibas.example.org/xmlrpc.php + +That's all. + + +=============== +Pingback sender +=============== +stapibas is able to send pingbacks out to other websites at behalf of +your website. + +It does this by watching your website's Atom feed. +Whenever it changes, it fetches the articles that are new or got updated and +sends out pingbacks to the remote websites. + + +Setup +===== +Insert your feed URL in the ``feeds`` database table. + +Whenever you update your website, tell stapibas about it via a +HTTP POST request:: + + $ curl -d url=http://example.org/feed/ http://stapibas.example.org/request-feed-update.php diff --git a/data/tables.sql b/data/tables.sql index a8bdda4..b9b2d98 100644 --- a/data/tables.sql +++ b/data/tables.sql @@ -9,3 +9,15 @@ CREATE TABLE IF NOT EXISTS `pingbacks` ( PRIMARY KEY (`p_id`), UNIQUE KEY `p_id` (`p_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +CREATE TABLE IF NOT EXISTS `feeds` ( + `f_id` int(11) NOT NULL AUTO_INCREMENT, + `f_url` varchar(2048) NOT NULL, + `f_updated` datetime NOT NULL, + `f_needs_update` tinyint(4) NOT NULL, + PRIMARY KEY (`f_id`), + UNIQUE KEY `f_id` (`f_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + diff --git a/www/request-feed-update.php b/www/request-feed-update.php new file mode 100644 index 0000000..d82de07 --- /dev/null +++ b/www/request-feed-update.php @@ -0,0 +1,55 @@ +query( + 'SELECT f_id, f_needs_update FROM feeds WHERE f_url = ' . $db->quote($url) +); +$row = $res->fetch(PDO::FETCH_OBJ); +if ($row === false) { + header('HTTP/1.0 404 Not Found'); + echo "Feed URL could not be found in database\n"; + exit(1); +} +if ($row->f_needs_update == 1) { + header('HTTP/1.0 200 OK'); + echo "Already in the queue\n"; + exit(0); +} + +$db->exec( + 'UPDATE feeds SET f_needs_update = 1' + . ' WHERE f_id = ' . $db->quote($row->f_id) +); + +header('HTTP/1.0 202 Accepted'); +echo "Feed has been put into the queue\n"; +exit(0); +?> -- 2.30.2