You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.7 KiB

<?php
/* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* For more information, please refer to <http://unlicense.org/>
*/
// Return source code
if(isset($_GET['source'])) {
header("Content-Type: text/plain");
die(file_get_contents(basename($_SERVER['PHP_SELF'])));
}
// See bbs.php for a description of vars.php
require_once('vars.php');
// Regex callback, makes >>quotes into links
function quote_link($match) {
$query = "SELECT post_id FROM posts WHERE post_id=$1";
$result = pg_query_params($query, [$match[1]]) or die('Query failed: ' . pg_last_error());
$row_count = pg_num_rows($result);
pg_free_result($result);
if($row_count > 0)
return "<a href=\"#p{$match[1]}\">{$match[0]}</a>";
else
return "<del>{$match[0]}</del>";
}
$dbc = pg_connect("host=$DB_HOST dbname=$DB_NAME user=$DB_USER password=$DB_PASSWORD")
or die('Could not connect: ' . pg_last_error());
// Get posts
$posts = [];
$query = "SELECT post_id, name, trip, email, comment, img, TO_CHAR(post_time, 'Dy, DD Mon YYYY HH24:MI:SS TZHTZM') AS ts "
. "FROM posts ORDER BY posts.post_time DESC LIMIT 10";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
while($row = pg_fetch_array($result)) {
// Process quotes, links, and newlines
$comment = NULL;
if(!empty($row['comment'])) {
$comment = $row['comment'];
$comment = preg_replace('/^&gt;(?!&gt;\d).+/m', '<strong>$0</strong>', $comment);
$comment = preg_replace('/(?:https?|mailto|tel|ftp):[^\s]+/m', '<a href="$0">$0</a>', $comment);
$comment = preg_replace_callback('/&gt;&gt;\s*(\d+)/', 'quote_link', $comment);
$comment = str_replace("\n", "<br />", $comment);
}
$name = $row['name'];
if(!empty($row['trip']))
$name .= '◆' . $row['trip'];
$comment = htmlspecialchars("<p>$comment</p>");
$img = preg_replace('/\.(?:png|gif|bmp)$/', '.jpg', $row['img']);
$posts[] = [
'title' => "New post by $name",
'link' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . '/#p' . $row['post_id'],
'description' => $comment,
'author' => $name,
'pubDate' => $row['ts'],
'guid' => 'p' . $row['post_id'],
'img' => empty($row['img']) ? NULL : [
'url' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . '/' . THUMB_PATH . $img,
'length' => filesize(THUMB_PATH . $img),
'type' => mime_content_type(THUMB_PATH . $img)
]
];
}
pg_close($dbc);
header("Content-Type: application/rss+xml");
?>
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>BBS | ピケ.コム</title>
<link>http://db.universal-team.net</link>
<atom:link href="http://bbs.xn--rck9c.xn--tckwe/rss.php" rel="self" type="application/rss+xml" />
<description>dumb PHP BBS because I was bored</description>
<lastBuildDate><?php echo $posts[0]['pubDate']; ?></lastBuildDate>
<language>en-US</language>
<?php foreach($posts as $post) { ?>
<item>
<title><?php echo $post['title']; ?></title>
<link><?php echo $post['link']; ?></link>
<description><?php echo $post['description']; ?></description>
<author><?php echo $post['author']; ?></author>
<pubDate><?php echo $post['pubDate']; ?></pubDate>
<guid isPermaLink="false"><?php echo $post['guid']; ?></guid>
<?php if(!empty($post['img'])) { ?>
<enclosure url="<?php echo $post['img']['url']; ?>" length="<?php echo $post['img']['length']; ?>" type="<?php echo $post['img']['type']; ?>"></enclosure>
<?php } ?>
</item>
<?php } ?>
</channel>
</rss>