From 8617983e0daf05890374cb82c2df4f0274513240 Mon Sep 17 00:00:00 2001 From: Graham Cole <chckens@sucs.org> Date: Mon, 20 Oct 2008 23:19:50 +0000 Subject: [PATCH] attempt to strip out hyperlinks and add to post footer. Also change motd file location back to a safe default ;-) --- components/motd.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/components/motd.php b/components/motd.php index f9f1e2e..33d938e 100644 --- a/components/motd.php +++ b/components/motd.php @@ -1,5 +1,5 @@ <?php -$motd_file = "/etc/motd"; +$motd_file = "/tmp/motd.txt"; function decode_entities($text, $quote_style = ENT_COMPAT) { if (function_exists('html_entity_decode')) { @@ -15,6 +15,14 @@ function decode_entities($text, $quote_style = ENT_COMPAT) { return $text; } +//function to count and collect hyperlinks +$links_count = 0; +function linkcounter($uri) { + global $links_count, $uris; + $uris[++$links_count] = $uri; + return $links_count; +} + $news = $DB->GetAll("SELECT * FROM news WHERE sticky=true AND expiry > now() ORDER BY date DESC"); if (count($news)<3) { $news = $DB->GetAll("(SELECT * FROM news WHERE sticky=false AND expiry > now() ORDER by date DESC LIMIT ".(3-count($news)).") UNION SELECT * FROM news WHERE sticky=true AND expiry > now() ORDER BY date DESC"); @@ -31,7 +39,17 @@ $body = str_replace("<br />", "\n ", $body); $body = str_replace("<li>", " * ", $body); $body = str_replace("</li>", "\n ", $body); $body = str_replace(" ", " ", $body); +// remove hyperlinks, collect to display later +$body = preg_replace(":<a href=['\"](.+?)['\"]>(.*?)</a>:e", "'\\2['.linkcounter('\\1').']'", $body); $body = strip_tags($body); +if (isset($uris)) { + $body .= "----\n"; + foreach ($uris as $urinum => $uri) { + $body .= " [$urinum]: $uri\n"; + //remove uri from list so it won't show up on the next post + unset($uris[$urinum]); + } +} $body = decode_entities($body); $body = wordwrap($body, 75, "\n ", 1); $body = rtrim($body); -- GitLab