Skip to content
Snippets Groups Projects
Commit 8617983e authored by Graham Cole's avatar Graham Cole
Browse files

attempt to strip out hyperlinks and add to post footer. Also change motd file...

attempt to strip out hyperlinks and add to post footer. Also change motd file location back to a safe default ;-)
parent bb77adb3
No related branches found
No related tags found
No related merge requests found
<?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("&nbsp;", " ", $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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment