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.

80 lines
2.2 KiB

<?php
$today = floor(date('U') / 24 / 60 / 60) * 24 * 60 * 60;
srand($today);
function motd($wordsPath) {
$out = [];
$words = explode("\n", file_get_contents($wordsPath));
$count = rand(1, 10);
for($i = 0; $i < $count; $i++) {
$word = $words[array_rand($words)];
if(rand(0, 4) == 0) { // 1 in 5 chance
$puctuation = [",", ".", ":", ";", "...", "!", "?"];
$word .= $puctuation[array_rand($puctuation)];
}
$out[] = $word;
}
return implode(" ", $out);
}
// Return source code
if(isset($_GET['source'])) {
header("Content-Type: text/plain");
die(file_get_contents(basename($_SERVER['PHP_SELF'])));
}
// Plaintext
if(isset($_GET['raw'])) {
header("Content-Type: text/plain");
die(motd("../words.txt"));
}
$motd = motd("../words.txt");
if(isset($_GET['rss'])) {
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>MOTD | ピケ.コム</title>
<link>http://xn--rck9c.xn--tckwe/motd.php</link>
<atom:link href="http://bbs.xn--rck9c.xn--tckwe/rss.php" rel="self" type="application/rss+xml" />
<description>A random message each day</description>
<lastBuildDate><?php echo date('r', $today); ?></lastBuildDate>
<language>en-US</language>
<item>
<title><?php echo $motd; ?></title>
<link>http://xn--rck9c.xn--tckwe/motd.php</link>
<description><?php echo $motd; ?></description>
<author>Pk11</author>
<pubDate><?php echo $post['pubDate']; ?></pubDate>
<guid isPermaLink="false"><?php echo $today; ?></guid>
</item>
</channel>
</rss>
<?php } else { ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo htmlspecialchars($motd); ?></title>
<meta name="description" content="<?php echo $motd; ?>">
<link rel="alternate" type="application/rss+xml" title="RSS feed" href="?rss" />
</head>
<body>
<h1 title="<?php echo date("Y-m-d (T)"); ?>"><?php echo htmlspecialchars($motd); ?></h1>
<p>
[<a href="//xn--rck9c.xn--tckwe/">back</a>]
[<a href="?raw">raw</a>]
[<a href="?rss">rss</a>]
[<a href="?source">source</a>]
</p>
</body>
</html>
<?php } ?>