Copyright (C) 2000 Daniel David Olson This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to: Free Software Foundation, Inc. 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA. */ have ('news'); // SQL definition for news table $createQuery="CREATE TABLE news_main (" ." n_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT," ." n_user TINYTEXT NOT NULL," ." n_date TIMESTAMP NOT NULL DEFAULT NOW()," ." n_news TEXT NOT NULL" .")"; function formatNews ($date, $user, $text) { need ('date'); $date = dateFromSQLDateTime ($date); return "
\n" .'
' . "Posted on $date by $user" . "
\n" ."
$text
\n" ."
\n"; } function formatNewsRSS ($date, $user, $text) { need ('date'); $rfcDate = RFCDateFromSQLDateTime ($date); $humanDate = dateFromSQLDateTime ($date); return "QF News for $humanDate (posted by $user)\n" ."http://www.quakeforge.net/\n" // ."http://www.quakeforge.net/news.php?item=$humanDate" ."$rfcDate" // ."$user" ."" ."\n"; } function formatNewsArray ($a) { return formatNews ($a['n_date'], $a['n_user'], stripSlashes($a['n_news'])); } function formatNewsArrayRSS ($a) { return formatNewsRSS ($a['n_date'], $a['n_user'], stripSlashes($a['n_news'])); } function printNews ($date, $user, $text) { echo formatNews ($date, $user, $text); } function printNewsArray ($a) { echo formatNewsArray ($a); } function latestNews ($max=5) { need ('sql'); $query = 'SELECT n_date, n_user, n_news FROM news_main' ." ORDER BY n_date DESC LIMIT $max"; return sqlReadQuery ($query); } function printLatestNews ($max=5) { $filler = date ('d-M-Y H:i:s'); $entries = latestNews ($max); global $newsFormat; if ($newsFormat && strtolower($newsFormat) == 'rss') { $fmt = 'formatNewsRSS'; } else { $fmt = 'formatNews'; } if ($entries === true) { // success, but no data echo $fmt($filler, 'Web Server', 'Nobody has posted news yet, so I got nothing to say right now.'); } elseif ($entries === false) { // bad query echo $fmt($filler, 'Web Server', 'Got an error while finding news. Bug a project administrator, eh?'); } elseif ($entries === null) { // boom echo $fmt($filler, 'Web Server', 'Couldn\'t connect to the project news server...Sorry.'); } else { for ($i = 0; $i < count ($entries); $i++) { echo $fmt($entries[$i]['n_date'], $entries[$i]['n_user'], stripSlashes($entries[$i]['n_news'])); } } } function monthlyNews ($month, $year) { need ('sql'); if (($year < 1999) || ($year > date ('Y'))) { // Sanity checking $year = date ('Y'); } if (($month < 1) || ($month > 12)) { $month = date ('m'); } $filler = date ('d M Y'); $date1 = sprintf ("%04d-%02d", $year, $month); $date2 = sprintf ("%04d-%02d", $year, $month+1); $query = 'SELECT n_date, n_user, n_news FROM news_main' ." WHERE n_date BETWEEN '$date1-01 00:00:00'" ." AND '$date2-01 00:00:00'" .' ORDER BY n_date DESC'; $entries = sqlReadQuery ($query); if ($entries === true) { // success, but no data printNews ($filler, 'Web Server', 'Nobody posted news in the month you asked for.'); } elseif ($entries === false) { // bad query printNews ($filler, 'Web Server', 'Got an error while finding news. Bug a project administrator, eh?'); } elseif ($entries === null) { // boom printNews ($filler, 'Web Server', 'Couldn\'t connect to the project news server...Sorry.'); } else for ($i = 0; $i < count ($entries); $i++) { printNewsArray ($entries[$i]); } } function searchNews ($string) { need ('sql'); $filler = date ('d M Y'); $search = addSlashes ("%$string%"); $query = 'SELECT n_date, n_user, n_news FROM news_main' ." WHERE n_news LIKE '$search'" .' ORDER BY n_date DESC'; $entries = sqlReadQuery ($query); if ($entries === true) { // success, but no data printNews ($filler, 'Web Server', "No news found matching '$string'"); } elseif ($entries === false) { // bad query printNews ($filler, 'Web Server', 'Got an error while finding news. Bug a project administrator, eh?'); } elseif ($entries === null) { // boom printNews ($filler, 'Web Server', 'Couldn\'t connect to the project news server...Sorry.'); } else for ($i = 0; $i < count ($entries); $i++) { printNewsArray ($entries[$i]); } } ?>