mirror of
https://git.code.sf.net/p/quake/website
synced 2024-11-13 08:27:41 +00:00
146 lines
No EOL
4.2 KiB
PHP
146 lines
No EOL
4.2 KiB
PHP
<?
|
|
/*
|
|
news.php
|
|
|
|
SQL-based news reading
|
|
|
|
Copyright (C) 2000-2007 Jeff Teunissen <deek@quakeforge.net>
|
|
Copyright (C) 2000 Daniel David Olson <theoddone33@users.sourceforge.net>
|
|
|
|
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');
|
|
need ('sql');
|
|
// 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)
|
|
{
|
|
return "<DL>\n"
|
|
.' <DT><FONT SIZE="-1">'
|
|
. "<EM>Posted on </EM>$date<EM> by </EM><STRONG>$user</STRONG>"
|
|
. "</FONT></DT>\n"
|
|
." <DD>$text</DD>\n"
|
|
."</DL>\n";
|
|
}
|
|
|
|
|
|
function formatNewsArray ($a)
|
|
{
|
|
need ("date");
|
|
|
|
return formatNews (dateFromSQLDateTime ($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)
|
|
{
|
|
$query = 'SELECT n_date, n_user, n_news FROM news_main'
|
|
." ORDER BY n_date DESC LIMIT $max";
|
|
|
|
return sqlReadQuery ($query);
|
|
}
|
|
|
|
|
|
function printLatestNews ($max)
|
|
{
|
|
$filler = date ('d M Y');
|
|
$entries = latestNews ($max);
|
|
|
|
if ($entries === true) { // success, but no data
|
|
printNews ($filler, 'Web Server', 'Nobody has posted news yet, so I got nothing to say right now.');
|
|
} 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 monthlyNews ($month, $year)
|
|
{
|
|
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)
|
|
{
|
|
$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]);
|
|
}
|
|
}
|
|
?>
|