From 94ca2d0308ea8faa4c0573b8d3ba46c19c7c5c9f Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 26 Mar 2015 17:41:50 +0100 Subject: [PATCH] push tester --- .gitignore | 2 ++ README.rst | 6 +++++ data/config.php.dist | 4 +++ www/add-article.php | 60 ++++++++++++++++++++++++++++++++++++++++++++ www/articles/.keep | 0 www/index.php | 43 +++++++++++++++++++++++++++++++ 6 files changed, 115 insertions(+) create mode 100644 .gitignore create mode 100644 README.rst create mode 100644 data/config.php.dist create mode 100644 www/add-article.php create mode 100644 www/articles/.keep create mode 100644 www/index.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e989522 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +data/config.php +www/articles/*.htm diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..143ea49 --- /dev/null +++ b/README.rst @@ -0,0 +1,6 @@ +******************* +PubSubHubbub tester +******************* + +Simulates a blog with an h-feed. +Sends notifications to the hub when a new article has been created. diff --git a/data/config.php.dist b/data/config.php.dist new file mode 100644 index 0000000..97a2101 --- /dev/null +++ b/data/config.php.dist @@ -0,0 +1,4 @@ + diff --git a/www/add-article.php b/www/add-article.php new file mode 100644 index 0000000..25db71e --- /dev/null +++ b/www/add-article.php @@ -0,0 +1,60 @@ + + + $title + + +

$title

+
$content
+ + +HTM +); +echo "saved as " . $file . "\n"; + +//hub-notification +$params = array( + 'hub.mode' => 'publish', + 'hub.url' => $self, +); +$enc = array(); +foreach ($params as $key => $val) { + $enc[] = urlencode($key) . '=' . urlencode($val); +} +$postMsg = implode('&', $enc); + +$ctx = stream_context_create( + array( + 'http' => array( + 'method' => 'POST', + 'header' => array( + 'Content-type: application/x-www-form-urlencoded', + ), + 'content' => $postMsg, + 'ignore_errors' => true, + ) + ) +); + +$res = file_get_contents($hub, false, $ctx); +list($http, $code, $rest) = explode(' ', $http_response_header[0]); +if (intval($code / 100) === 2) { + echo "notified hub\n"; + exit(); +} + +echo "Error notifying hub: HTTP status was not 2xx; got $code\n"; +echo $res . "\n"; +?> diff --git a/www/articles/.keep b/www/articles/.keep new file mode 100644 index 0000000..e69de29 diff --git a/www/index.php b/www/index.php new file mode 100644 index 0000000..b4d0b2f --- /dev/null +++ b/www/index.php @@ -0,0 +1,43 @@ +; rel="hub"'); +header('Link: <' . $self . '>; rel="self"', false); + +$files = glob(__DIR__ . '/articles/*.htm'); +$articles = array(); +foreach ($files as $file) { + $content = file_get_contents($file); + $xml = simplexml_load_string($content); + $timestamp = strtotime(basename($file, '.htm')); + $articles[$timestamp] = (object) array( + 'file' => 'articles/' . basename($file), + 'title' => basename($file, '.htm'), + 'content' => (string) $xml->body->div, + 'time' => $timestamp, + ); +} +krsort($articles); +?> + + + PubSubHubbub tester + + +

+ create new article +

+

Articles

+ +
+

title); ?>

+
+ content; ?> +
+

+ permalink + +

+
+ + + -- 2.30.2