atom feed support
[push-tester.git] / www / add-article.php
1 <?php
2 header('Content-type: text/plain');
3 require_once __DIR__ . '/../data/config.php';
4
5 $time = time();
6 $timestr = date('Y-m-d', $time) . 'T' . date('H:i:s', $time);
7 $file = __DIR__ . '/articles/' . $timestr . '.htm';
8 $title = $timestr;
9 $content = `/usr/games/fortune`;
10
11 file_put_contents(
12     $file,
13     <<<HTM
14 <html>
15  <head>
16   <title>$title</title>
17  </head>
18  <body class="h-entry">
19   <h1>$title</h1>
20   <p>
21    <span class="h-card vcard author p-author">
22     <img class="u-photo" src="../someone.png" width="16" height="16" alt=""/>
23     <a class="p-author h-card" href="../someone.htm">Someone</a>
24    </span>
25   </p>
26   <div class="e-content">$content</div>
27  </body>
28 </html>
29 HTM
30 );
31 //echo "saved as " . $file . "\n";
32
33 //hub-notification
34 $arUrls = array($self, $self . 'feed.php');
35 foreach ($arUrls as $url) {
36     $params = array(
37         'hub.mode' => 'publish',
38         'hub.url'  => $url,
39     );
40     $enc = array();
41     foreach ($params as $key => $val) {
42         $enc[] = urlencode($key) . '=' . urlencode($val);
43     }
44     $postMsg = implode('&', $enc);
45
46     $ctx = stream_context_create(
47         array(
48             'http' => array(
49                 'method' => 'POST',
50                 'header' => array(
51                     'Content-type: application/x-www-form-urlencoded',
52                 ),
53                 'content' => $postMsg,
54                 'ignore_errors' => true,
55             )
56         )
57     );
58
59     $res = file_get_contents($hub, false, $ctx);
60     list($http, $code, $rest) = explode(' ', $http_response_header[0]);
61     if (intval($code / 100) !== 2) {
62         echo "Error notifying hub: HTTP status was not 2xx; got $code\n";
63         echo $res . "\n";
64         echo 'URL: ' . $url . "\n";
65     } else {
66         //echo "notified hub: $url\n";
67     }
68 }
69 header('Location: /');
70 exit();
71 ?>