xref: /web-master/fetch/user-notes-rss.php (revision 81b302aa)
1<?php
2
3require_once __DIR__ . '/../include/functions.inc';
4
5db_connect();
6
7if (isset($_GET['limit']) && is_numeric($_GET['limit']) && $_GET['limit'] <= 1000) {
8  $limit = $_GET['limit'];
9} else {
10  $limit = 100;
11}
12
13$query = new Query('SELECT DISTINCT id,sect,user,note,UNIX_TIMESTAMP(ts) AS ts FROM note');
14if (isset($_GET['id']) && is_numeric($_GET['id'])) {
15  $query->add(" WHERE id = ?", [$_GET['id']]);
16} elseif (isset($_GET['section'])) {
17  $query->add(" WHERE sect LIKE ");
18  $sect = explode(',', $_GET['section']);
19  for ($i=0; $i<count($sect) - 1; $i++) {
20    $query->add('? OR sect LIKE ', [strtr($sect[$i],'*','%')]);
21  }
22  $query->add('?', [strtr($sect[count($sect) - 1],'*','%')]);
23}
24$query->add(" ORDER BY sect,ts DESC");
25$query->add(" LIMIT ?", [$limit]);
26
27$res = db_query($query);
28
29$notes = [];
30while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
31  $notes[$row['id']] = $row;
32}
33
34header('Content-type: text/xml');
35?>
36<?php echo "<?";?>xml version="1.0" encoding="ISO-8859-1"?>
37<rdf:RDF
38  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
39  xmlns="http://purl.org/rss/1.0/"
40  xmlns:dc="http://purl.org/dc/elements/1.1/"
41>
42  <channel rdf:about="http://php.net/">
43  <title>PHP Manual User Notes</title>
44  <link>https://master.php.net/manage/user-notes.php</link>
45  <description/>
46  <items>
47    <?php if ($notes) { ?>
48    <rdf:Seq>
49      <rdf:li rdf:resource="https://master.php.net/note/edit/<?php
50      echo implode('"/> <rdf:li rdf:resource="https://master.php.net/note/edit/',
51        array_keys($notes));?>"/>
52    </rdf:Seq>
53    <?php } ?>
54  </items>
55  </channel>
56  <image rdf:about="http://php.net/images/php.gif">
57    <title>PHP Manual User Notes</title>
58    <url>http://php.net/images/php.gif</url>
59    <link>https://master.php.net/manage/user-notes.php</link>
60  </image>
61<?php
62foreach ($notes as $note) {
63  ?>
64  <item>
65    <title><?php echo htmlspecialchars(substr($note['note'], 0, 40));
66      echo strlen($note['note']) < 40 ? '...' : ''; ?></title>
67    <link>https://master.php.net/note/edit/<?php echo $note['id']; ?></link>
68    <description>
69      <![CDATA[
70      <?php echo htmlspecialchars($note['note']); ?>
71      ]]>
72    </description>
73    <dc:date><?php echo date('Y-m-d', $note['ts']);?></dc:date>
74    <dc:time><?php echo date('H:i:s', $note['ts']);?></dc:time>
75    <dc:creator><?php echo htmlspecialchars(preg_replace('/.@./','*@*',$note['user'])); ?></dc:creator>
76    <dc:subject><?php echo htmlspecialchars($note['sect']); ?></dc:subject>
77  </item>
78  <?php
79}
80?>
81</rdf:RDF>
82