website/lib/news.php

249 lines
6.6 KiB
PHP
Raw Normal View History

2000-07-08 04:06:04 +00:00
<?
/*
news.php
SQL-based news reading library
Copyright (C) 2000,2001 Jeff Teunissen <deek@quakeforge.net>
Copyright (C) 2000 Daniel David Olson <theoddone33@users.sourceforge.net>
2000-07-08 04:06:04 +00:00
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
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 DEFAULT '' NOT NULL
);
*/
2000-07-08 04:06:04 +00:00
function newsItem ($date, $user, $text)
{
echo
' <DL>' .
' <DT><FONT SIZE="-1">' . "<EM>Posted on </EM>$date<EM> by </EM><STRONG>$user</STRONG></FONT></DT>" .
" <DD><P>$text</P></DD>" .
' </DL>' ;
2000-07-08 04:06:04 +00:00
}
function newsEntry ($array)
{
need ("date");
return
' <DL>' .
' <DT><FONT size="-1"><EM>Posted on </EM>' . dateFromSQLDateTime ($array[n_date]) . '<EM> by </EM><STRONG>' . $array[n_user] . '</STRONG></FONT></DT>' .
' <DD>' . StripSlashes ($array[n_news]) . '</DD>' .
' </DL>';
2000-07-08 04:06:04 +00:00
}
function monthForm ($month, $year)
2000-07-08 04:06:04 +00:00
{
need ('feature');
// suppress warnings
@featureOpen ('Date Search');
2000-07-08 04:06:04 +00:00
?>
<FORM name="bymonth" method="get" action="<?=thisURL?>">
<P align="center">
2000-07-08 04:06:04 +00:00
<SELECT name="month">
<?
for ( $i = 1 ; $i < 13 ; $i++ ) {
printf ("<OPTION%s>%02d</OPTION>", $i == $month ? " selected" : "", $i);
2000-07-08 04:06:04 +00:00
}
?>
</SELECT><STRONG> / </STRONG><SELECT name="year">
<?
if ($year == "")
2002-02-14 07:38:45 +00:00
$year = date ('Y');
for ($i = 1999; $i <= date ('Y'); $i++ ) {
printf ("<OPTION%s>%04d</OPTION>", $i == $year ? " selected" : "", $i);
}
?>
2000-07-08 04:06:04 +00:00
</SELECT>
<BR>
<BR>
2001-02-12 17:25:01 +00:00
<INPUT type="submit" value="Search">
</P>
</FORM><?
featureClose ();
2000-07-08 04:06:04 +00:00
}
function keywordForm ($string)
2000-07-08 04:06:04 +00:00
{
need ('feature');
// suppress warnings
@featureOpen ('Keyword Search');
2000-07-08 04:06:04 +00:00
?>
<FORM name="bystring" method="get" action="<?=thisURL?>">
<P align="center">
<?
printf ('<INPUT name="string" type="text" size="16" value="%s">', $string);
?>
<BR>
<BR>
2000-07-08 04:06:04 +00:00
<INPUT TYPE="submit" VALUE="Search">
</P>
</FORM><?
featureClose ();
2000-07-08 04:06:04 +00:00
}
function fetchNewsEntry ($number)
{
need('date');
$conn = @mysql_pconnect (sqlHost, sqlUser, sqlPass);
if ($conn) {
$query = 'SELECT n_date, n_user, n_news FROM news_main' .
" ORDER BY n_date DESC LIMIT $number";
$result = @mysql_db_query (sqlDB, $query, $conn);
if ($result) {
$numRows = @mysql_num_rows ($result);
if ($numRows) {
for ($i = 0 ; $i < $numRows ; $i++) {
list ($n_date, $n_user, $n_news) = mysql_fetch_row ($result);
}
} else {
return 0;
2000-07-08 04:06:04 +00:00
}
} else {
return 0;
}
mysql_close ($conn);
2000-07-08 04:06:04 +00:00
} else {
return 0;
}
// return (list (dateFromSQLDateTime ($n_date), $n_user, StripSlashes($n_news)));
2000-07-08 18:43:38 +00:00
return 0;
2000-07-08 04:06:04 +00:00
}
function latestNews ($max)
2000-07-08 04:06:04 +00:00
{
2001-05-06 02:38:07 +00:00
if (sqlAvail) {
2002-02-22 05:31:39 +00:00
$conn = mysql_pconnect (sqlHost, sqlUser, sqlPass);
if ($conn) {
$query = 'SELECT n_date, n_user, n_news FROM news_main' .
' ORDER BY n_date DESC';
2002-02-22 05:29:05 +00:00
$result = mysql_db_query (sqlDB, $query, $conn);
if ($result) {
2002-02-22 05:31:39 +00:00
$numRows = mysql_num_rows ($result);
if ($numRows) {
for ($i = 0 ; $i < $numRows && $i < $max; $i++) {
$news[$i] = mysql_fetch_array ($result);
echo newsEntry ($news[$i]);
}
} else {
2002-02-18 07:44:50 +00:00
newsItem (date ('d M Y'), 'Web Server', '<P>No current news!');
2000-07-08 04:06:04 +00:00
}
} else {
2002-02-18 07:44:50 +00:00
newsItem (date ('d M Y'), 'Web Server', '<P>No news in database!');
2000-07-08 04:06:04 +00:00
}
mysql_close ($conn);
2000-07-08 04:06:04 +00:00
} else {
2002-01-23 03:40:21 +00:00
include 'newscache.php';
return 1;
2000-07-08 04:06:04 +00:00
}
return 0;
2000-07-08 04:06:04 +00:00
} else {
2002-02-18 07:44:50 +00:00
newsItem (date ('d M Y'), 'Web Server', '<P>No SQL server available!');
return 0;
2000-07-08 04:06:04 +00:00
}
}
function monthlyNews ($month, $year)
{
if (($year < 1999) || ($year > date ('Y'))) { // Sanity checking
$year = date ('Y');
2000-07-08 04:06:04 +00:00
}
2001-05-06 03:03:58 +00:00
if (($month < 1) || ($month > 12)) {
$month = date ('m');
2000-07-08 04:06:04 +00:00
}
2001-05-06 03:03:58 +00:00
$date1 = sprintf ("%04d-%02d", $year, $month);
$date2 = sprintf ("%04d-%02d", $year, $month+1);
2000-07-08 04:06:04 +00:00
2001-05-06 02:38:07 +00:00
if (sqlAvail) {
2002-02-22 05:29:05 +00:00
$conn = mysql_pconnect (sqlHost, sqlUser, sqlPass);
if ($conn) {
$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';
$result = @mysql_db_query (sqlDB, $query, $conn);
if ($result) {
$numRows = @mysql_num_rows ($result);
if ($numRows) {
for ($i = 0 ; $i < $numRows ; $i++) {
$news[$i] = mysql_fetch_array ($result);
echo newsEntry ($news[$i]);
}
} else {
2002-02-18 07:44:50 +00:00
newsItem (date ('d M Y'), 'Web Server', '<P>No news for this month!');
2000-07-08 04:06:04 +00:00
}
} else {
2002-02-18 07:44:50 +00:00
newsItem (date ('d M Y'), 'Web Server', '<P>No news in database!');
2000-07-08 04:06:04 +00:00
}
mysql_close ($conn);
2000-07-08 04:06:04 +00:00
} else {
2002-02-18 07:44:50 +00:00
newsItem (date ('d M Y'), 'Web Server', '<STRONG>SQL error!</STRONG> Please contact the <A href="mailto:deek@quakeforge.net">Webmaster</A>.');
2000-07-08 04:06:04 +00:00
}
} else {
2002-02-18 07:44:50 +00:00
newsItem (date ('d M Y'), 'Web Server', '<P>No SQL server available');
2000-07-08 04:06:04 +00:00
}
}
function searchNews ($string)
{
2001-05-06 02:38:07 +00:00
if (sqlAvail) {
$search = AddSlashes ("%$string%");
2002-02-22 05:30:36 +00:00
$conn = mysql_pconnect (sqlHost, sqlUser, sqlPass);
if ($conn) {
$query = 'SELECT n_date, n_user, n_news FROM news_main' .
" WHERE n_news LIKE '$search'" .
' ORDER BY n_date DESC';
2002-02-22 05:30:36 +00:00
$result = mysql_db_query (sqlDB, $query, $conn);
if ($result) {
2002-02-22 05:30:36 +00:00
$numRows = mysql_num_rows ($result);
if ($numRows) {
for ($i = 0 ; $i < $numRows ; $i++) {
$news[$i] = mysql_fetch_array ($result);
echo newsEntry ($news[$i]);
}
} else {
2002-02-18 07:44:50 +00:00
newsItem (date ('d M Y'), 'Web Server', "No news found matching '$string'");
2000-07-08 04:06:04 +00:00
}
} else {
2002-02-18 07:44:50 +00:00
newsItem (date ('d M Y'), 'Web Server', "No news found matching '$string'");
2000-07-08 04:06:04 +00:00
}
mysql_close ($conn);
} else {
2002-02-18 07:44:50 +00:00
newsItem (date ('d M Y'), 'Web Server', '<STRONG>SQL error!</STRONG> Please contact the <A href="mailto:deek@quakeforge.net">Webmaster</A>.');
2000-07-08 04:06:04 +00:00
}
} else {
2002-02-18 07:44:50 +00:00
newsItem (date ('d M Y'), 'Web Server', '<P>No SQL server available');
2000-07-08 04:06:04 +00:00
}
}
?>