add author, url and photo
[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 $params = array(
35     'hub.mode' => 'publish',
36     'hub.url'  => $self,
37 );
38 $enc = array();
39 foreach ($params as $key => $val) {
40     $enc[] = urlencode($key) . '=' . urlencode($val);
41 }
42 $postMsg = implode('&', $enc);
43
44 $ctx = stream_context_create(
45     array(
46         'http' => array(
47             'method' => 'POST',
48             'header' => array(
49                 'Content-type: application/x-www-form-urlencoded',
50             ),
51             'content' => $postMsg,
52             'ignore_errors' => true,
53         )
54     )
55 );
56
57 $res = file_get_contents($hub, false, $ctx);
58 list($http, $code, $rest) = explode(' ', $http_response_header[0]);
59 if (intval($code / 100) === 2) {
60     echo "notified hub\n";
61     exit();
62 }
63
64 echo "Error notifying hub: HTTP status was not 2xx; got $code\n";
65 echo $res . "\n";
66 ?>