--- /dev/null
+data/config.php
+www/articles/*.htm
--- /dev/null
+*******************
+PubSubHubbub tester
+*******************
+
+Simulates a blog with an h-feed.
+Sends notifications to the hub when a new article has been created.
--- /dev/null
+<?php
+$hub = 'http://phubb.bogo/hub.php';
+$self = 'http://push-tester.bogo/';
+?>
--- /dev/null
+<?php
+header('Content-type: text/plain');
+require_once __DIR__ . '/../data/config.php';
+
+$time = time();
+$timestr = date('Y-m-d', $time) . 'T' . date('H:i:s', $time);
+$file = __DIR__ . '/articles/' . $timestr . '.htm';
+$title = $timestr;
+$content = `/usr/games/fortune`;
+
+file_put_contents(
+ $file,
+ <<<HTM
+<html>
+ <head>
+ <title>$title</title>
+ </head>
+ <body class="h-entry">
+ <h1>$title</h1>
+ <div class="e-content">$content</div>
+ </body>
+</html>
+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";
+?>
--- /dev/null
+<?php
+require_once __DIR__ . '/../data/config.php';
+header('Link: <' . $hub . '>; 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);
+?>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>PubSubHubbub tester</title>
+ </head>
+ <body class="h-feed">
+ <p>
+ <a href="add-article.php">create new article</a>
+ </p>
+ <h1>Articles</h1>
+ <?php foreach ($articles as $article) { ?>
+ <article class="h-entry">
+ <h2><?php echo htmlspecialchars($article->title); ?></h2>
+ <div class="e-content">
+ <?php echo $article->content; ?>
+ </div>
+ <p>
+ <a href="<?php echo $article->file; ?>" class="u-url">permalink</a>
+ <time class="dt-published"><?php echo date('c', $article->time); ?></time>
+ </p>
+ </article>
+ <?php } ?>
+ </body>
+</html>