Skip to content
Snippets Groups Projects
Commit 90254eea authored by Thomas Lake's avatar Thomas Lake :wrench:
Browse files

Display random poems in the motd if there are no current news entries

parent ca6ca7ef
No related branches found
No related tags found
No related merge requests found
......@@ -24,11 +24,19 @@ function linkcounter($uri) {
return $links_count;
}
$poemmode = 0;
$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");
}
if (count($news)<1) {
$news = $DB->GetAll("SELECT * FROM poems ORDER BY RANDOM() LIMIT 1");
$poemmode = 1;
}
$motd = "----------------------------- MESSAGE OF THE DAY ------------------------------\n\n";
for ($i=count($news)-1;$i>-1;$i--) {
......@@ -56,10 +64,19 @@ if (isset($uris)) {
unset($uris[$urinum]);
}
$motd .= " ".$footer;
}
$motd .= str_pad($nitem['author'], 78, " ", STR_PAD_LEFT)."\n\n";
}
$motd .= str_pad($nitem['author'], 78, " ", STR_PAD_LEFT)."\n";
if ($poemmode == 1 && $nitem['submitter'] != '') {
$motd .= str_pad("Submitted by ".$nitem['submitter'], 78, " ", STR_PAD_LEFT)."\n";
}
$motd .= "\n";
}
$motd .= "---------------------------- [ http://sucs.org/ ] -----------------------------\n";
file_put_contents($motd_file, $motd);
if (date("z",time()-filemtime($motd_file)) < 1 && $poemmode == 1) {
// print "MOTD too recent to replace with a poem!\n";
} else {
file_put_contents($motd_file, $motd);
}
?>
<?PHP
require("/var/www/sucssite/htdocs/settings.php");
require("/usr/share/php/adodb/adodb.inc.php");
$dbname = 'sucssite';
$dbuser = 'apache';
$DB = NewADOConnection('postgres8');
$DB->Connect('dbname='.$dbname.',dbuser='$dbuser);
$DB->SetFetchMode(ADODB_FETCH_ASSOC);
include("./motd.php");
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