fix xml problems
[push-tester.git] / www / add-article.php
index 6e9a03850491ff129354adbb8e3cb9d5911f98f2..3b46ef5e8a3f560cc58de1b95a228368f40becba 100644 (file)
@@ -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();
 ?>