From: Christian Weiske Date: Fri, 13 Mar 2020 20:32:52 +0000 (+0100) Subject: fix xml problems X-Git-Url: https://git.cweiske.de/push-tester.git/commitdiff_plain/HEAD?hp=26fb4103618d21ce3884e89239cba6ccb82743ed fix xml problems --- diff --git a/README.rst b/README.rst index 143ea49..47d5a34 100644 --- a/README.rst +++ b/README.rst @@ -1,6 +1,6 @@ -******************* -PubSubHubbub tester -******************* +************* +WebSub tester +************* -Simulates a blog with an h-feed. -Sends notifications to the hub when a new article has been created. +Simulates a blog with an atom and an h-feed. +Sends a publish notification to the hub when a new article has been created. diff --git a/www/add-article.php b/www/add-article.php index 6e9a038..3b46ef5 100644 --- a/www/add-article.php +++ b/www/add-article.php @@ -6,7 +6,7 @@ $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`; +$content = htmlspecialchars(`/usr/games/fortune`); file_put_contents( $file, @@ -31,37 +31,41 @@ 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); +$arUrls = array($self, $self . 'feed.php'); +foreach ($arUrls as $url) { + $params = array( + 'hub.mode' => 'publish', + 'hub.url' => $url, + ); + $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, + $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"; - header('Location: /'); - exit(); + $res = file_get_contents($hub, false, $ctx); + list($http, $code, $rest) = explode(' ', $http_response_header[0]); + if (intval($code / 100) !== 2) { + echo "Error notifying hub: HTTP status was not 2xx; got $code\n"; + echo $res . "\n"; + echo 'URL: ' . $url . "\n"; + } else { + //echo "notified hub: $url\n"; + } } - -echo "Error notifying hub: HTTP status was not 2xx; got $code\n"; -echo $res . "\n"; +header('Location: /'); +exit(); ?> diff --git a/www/feed.php b/www/feed.php new file mode 100644 index 0000000..e3e1ac0 --- /dev/null +++ b/www/feed.php @@ -0,0 +1,41 @@ +; rel="hub"'); +header('Link: <' . $self . 'feed.php>; rel="self"', false); + +$articles = loadArticles(); +reset($articles); +$lastUpdate = key($articles); +?> + + + WebSub tester + + Someone + someone@example.org + + + + + + feed.php + + + + + file; ?> + <?php echo htmlspecialchars($article->title); ?> + time); ?> + time); ?> + content, 0, 100); ?>… + +
+ content; ?> +
+
+ +
+ +
diff --git a/www/functions.php b/www/functions.php new file mode 100644 index 0000000..962012e --- /dev/null +++ b/www/functions.php @@ -0,0 +1,22 @@ + 'articles/' . basename($file), + 'title' => basename($file, '.htm'), + 'content' => (string) $xml->body->div, + 'time' => $timestamp, + ); + } + krsort($articles); + $articles = array_slice($articles, 0, 10); + //FIXME: delete old ones + return $articles; +} +?> diff --git a/www/index.php b/www/index.php index 0a205f8..9be78bc 100644 --- a/www/index.php +++ b/www/index.php @@ -1,30 +1,25 @@ ; 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); +$articles = loadArticles(); ?> - PubSubHubbub tester + WebSub tester +

create new article + | atom feed +

+

+ This is a tool to test your WebSub + subscriber. + With one click, a new post gets published and the hub gets notified.

Articles