Skip to content
Commits on Source (2)
......@@ -3,16 +3,21 @@ $motd_file = "/etc/motd";
function decode_entities($text, $quote_style = ENT_COMPAT)
{
if (function_exists('html_entity_decode')) {
$text = html_entity_decode($text, $quote_style, 'ISO-8859-1'); // NOTE: UTF-8 does not work!
} else {
$trans_tbl = get_html_translation_table(HTML_ENTITIES, $quote_style);
$trans_tbl = array_flip($trans_tbl);
$text = strtr($text, $trans_tbl);
}
$text = preg_replace('~&ndash\;~i', '-', $text);
$text = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $text);
$text = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $text);
$text = html_entity_decode($text, $quote_style, 'ISO-8859-1'); // NOTE: UTF-8 does not work!
$text = preg_replace_callback('~&#x([0-9a-f]+);~i',
function ($matches) {
foreach ($matches as $match) {
return chr(hexdec($match));
}
},
$text);
$text = preg_replace_callback('~&#([0-9]+);~',
function ($matches) {
foreach ($matches as $match) {
return chr($match);
}
},
$text);
return $text;
}
......@@ -52,7 +57,12 @@ for ($i = count($news) - 1; $i > -1; $i--) {
$body = str_replace("…", "...", $body);
$body = str_replace("'", "'", $body);
// remove hyperlinks, collect to display later
$body = preg_replace(":<a href=['\"](.+?)['\"].*?>(.*?)</a>:e", "'\\2['.linkcounter('\\1').']'", $body);
$body = preg_replace_callback(":<a href=['\"](.+?)['\"].*?>(.*?)</a>:",
function ($matches) {
$i = linkcounter($matches[1]);
return $matches[0]."[".$i."]";
},
$body);
$body = strip_tags($body);
$body = decode_entities($body);
$body = wordwrap($body, 75, "\n ", 1);
......@@ -76,9 +86,11 @@ for ($i = count($news) - 1; $i > -1; $i--) {
}
$motd .= "---------------------------- [ http://sucs.org/ ] -----------------------------\n";
//print($motd);
//if (time()-filemtime($motd_file) < 86000 && $poemmode == 1) { //86000 to allow a little slack depending on when cron runs
// print "MOTD too recent to replace with a poem!\n";
//} else {
file_put_contents($motd_file, $motd);
//}
?>
?>
\ No newline at end of file