news caching stuff

This commit is contained in:
Dan Olson 2000-06-22 00:30:50 +00:00
parent eb60c7044b
commit 231eb79fc2

View file

@ -1,205 +1,234 @@
<? <?
function newsItem ($date, $user, $text) function newsItem ($date, $user, $text)
{ {
if ($user == "Theoddone33") $user = "theoddone33"; if ($user == "Theoddone33") $user = "theoddone33";
echo '<TR>' . echo '<TR>' .
' <TD>' . ' <TD>' .
' <DL>' . ' <DL>' .
" <DT><FONT SIZE=\"-1\">Posted on $date by $user</FONT></DT>" . " <DT><FONT SIZE=\"-1\">Posted on $date by $user</FONT></DT>" .
" <DD><P>$text</DD>" . " <DD><P>$text</DD>" .
' </DL>' . ' </DL>' .
' </TD>' . ' </TD>' .
'</TR>'; '</TR>';
} }
function monthForm () function monthForm ()
{ {
?><FORM name="bymonth" method="get" action="/old_news.php"><? ?><FORM name="bymonth" method="get" action="/old_news.php"><?
tableBoxHeader ('black', tableHeadColor); tableBoxHeader ('black', tableHeadColor);
tableTitle ("Search by Month", 1, tableHeadColor); tableTitle ("Search by Month", 1, tableHeadColor);
?><TD align="center"><? ?><TD align="center"><?
tableHeader("100%", featureBgColor); tableHeader("100%", featureBgColor);
?> ?>
<TR vAlign="center"> <TR vAlign="center">
<TD align="center"> <TD align="center">
<STRONG>Month:</STRONG> <STRONG>Month:</STRONG>
</TD> </TD>
<TD align="center"> <TD align="center">
<SELECT name="month"> <SELECT name="month">
<? <?
for ( $i = 1 ; $i < 13 ; $i++ ) { for ( $i = 1 ; $i < 13 ; $i++ ) {
printf("<OPTION>%02d</OPTION>", $i); printf("<OPTION>%02d</OPTION>", $i);
} }
?> ?>
</SELECT> </SELECT>
</TD> </TD>
<TD align="center"> <TD align="center">
<STRONG>Year:</STRONG> <STRONG>Year:</STRONG>
</TD> </TD>
<TD align="center"> <TD align="center">
<SELECT name="year"> <SELECT name="year">
<OPTION SELECTED>2000</OPTION> <OPTION SELECTED>2000</OPTION>
</SELECT> </SELECT>
</TD> </TD>
</TR> </TR>
<TR vAlign="center"> <TR vAlign="center">
<TD align="center" colSpan="4"> <TD align="center" colSpan="4">
<INPUT TYPE="submit" VALUE="Search"> <INPUT TYPE="submit" VALUE="Search">
</TD> </TD>
</TR> </TR>
<? <?
tableFooter (); tableFooter ();
tableBoxFooter (); tableBoxFooter ();
?> ?>
</FORM> </FORM>
<? <?
} }
function keywordForm () function keywordForm ()
{ {
?><FORM name="bystring" method="get" action="/old_news.php"><? ?><FORM name="bystring" method="get" action="/old_news.php"><?
tableBoxHeader ('black', tableHeadColor); tableBoxHeader ('black', tableHeadColor);
tableTitle ("Search by String", 1, tableHeadColor); tableTitle ("Search by String", 1, tableHeadColor);
?><TD align="center"><? ?><TD align="center"><?
tableHeader("100%", featureBgColor); tableHeader("100%", featureBgColor);
?> ?>
<TR vAlign="center"> <TR vAlign="center">
<TD align="center"> <TD align="center">
<STRONG>String:</STRONG> <STRONG>String:</STRONG>
</TD> </TD>
<TD align="center"> <TD align="center">
<INPUT name="string" type="text" size="25"> <INPUT name="string" type="text" size="25">
</TD> </TD>
</TR> </TR>
<TR vAlign="center"> <TR vAlign="center">
<TD align="center" colSpan="2"> <TD align="center" colSpan="2">
<INPUT TYPE="submit" VALUE="Search"> <INPUT TYPE="submit" VALUE="Search">
</TD> </TD>
</TR> </TR>
<? <?
tableFooter (); tableFooter ();
tableBoxFooter (); tableBoxFooter ();
?> ?>
</FORM> </FORM>
<? <?
} }
function listMonths () function listMonths ()
{ {
$startyear = 2000; $startyear = 2000;
$today = getdate (); $today = getdate ();
while ($startyear <= $today['year']) { while ($startyear <= $today['year']) {
for ($month = $today['mon']+1 ; $month > 1 ; $month--) { for ($month = $today['mon']+1 ; $month > 1 ; $month--) {
echo '<P><A href="old_news.php?month=' . echo '<P><A href="old_news.php?month=' .
date ("m", mktime (0,0,0,$month,0,0,0)) . date ("m", mktime (0,0,0,$month,0,0,0)) .
'&year=' . date ("Y", mktime (0,0,0,0,0,$today['year']+1,0)) . '">' . '&year=' . date ("Y", mktime (0,0,0,0,0,$today['year']+1,0)) . '">' .
date ("F, Y", mktime (0,0,0,$month,0,$today['year'],0)) . date ("F, Y", mktime (0,0,0,$month,0,$today['year'],0)) .
'</A>'; '</A>';
} }
$today['year']--; $today['year']--;
} }
} }
function latestNews ($length) function latestNews ($length)
{ {
need('date'); need('date');
$conn = @mysql_pconnect (sqlHost, sqlUser, sqlPass); $conn = @mysql_pconnect (sqlHost, sqlUser, sqlPass);
if ($conn) { if ($conn) {
$query = 'SELECT n_date, n_user, n_news FROM news_main' . $query = 'SELECT n_date, n_user, n_news FROM news_main' .
" WHERE n_date > DATE_SUB(NOW(), INTERVAL $length)" . " WHERE n_date > DATE_SUB(NOW(), INTERVAL $length)" .
' ORDER BY n_date DESC'; ' ORDER BY n_date DESC';
$result = @mysql_db_query (sqlDB, $query, $conn); $result = @mysql_db_query (sqlDB, $query, $conn);
if ($result) { if ($result) {
$numRows = @mysql_num_rows ($result); $numRows = @mysql_num_rows ($result);
if ($numRows) { if ($numRows) {
for ($i = 0 ; $i < $numRows ; $i++) { for ($i = 0 ; $i < $numRows ; $i++) {
list ($n_date, $n_user, $n_news) = mysql_fetch_row ($result); list ($n_date, $n_user, $n_news) = mysql_fetch_row ($result);
newsItem (dateFromSQLDateTime ($n_date), $n_user, StripSlashes($n_news)); newsItem (dateFromSQLDateTime ($n_date), $n_user, StripSlashes($n_news));
} }
} else { } else {
newsItem ('now', 'Web Server', '<P>No current news!'); newsItem ('now', 'Web Server', '<P>No current news!');
} }
} else { } else {
newsItem ('now', 'Web Server', '<P>No news in database!'); newsItem ('now', 'Web Server', '<P>No news in database!');
} }
mysql_close ($conn); mysql_close ($conn);
} else { } else {
newsItem ('Now', 'Web Server', '<P>Error: Could not connect to SQL server to fetch news. Please notify the server administrator.'); include ('cache.php');
} // newsItem ('Now', 'Web Server', '<P>Error: Could not connect to SQL server to fetch news. Please notify the server administrator.');
} }
}
function monthlyNews ($month, $year)
{ function fetchNewsEntry ($number)
need('date'); {
need('date');
// Do sanity checking on dates
if (((!is_int($year)) || $year < 2000)) { $conn = @mysql_pconnect (sqlHost, sqlUser, sqlPass);
$year = date('Y',time()); if ($conn) {
} $query = 'SELECT n_date, n_user, n_news FROM news_main' .
" ORDER BY n_date DESC LIMIT $number";
if ($month < 1 || $month > 12) { $result = @mysql_db_query (sqlDB, $query, $conn);
$month = date('m',time()); if ($result) {
} $numRows = @mysql_num_rows ($result);
$date = "$year-$month"; if ($numRows) {
for ($i = 0 ; $i < $numRows ; $i++) {
$conn = @mysql_pconnect (sqlHost, sqlUser, sqlPass); list ($n_date, $n_user, $n_news) = mysql_fetch_row ($result);
if ($conn) { }
$query = 'SELECT n_date, n_user, n_news FROM news_main' . } else {
" WHERE n_date BETWEEN '$date-00 00:00:00'" . return 0;
" AND '$date-31 23:59:59'" . }
' ORDER BY n_date DESC'; } else {
$result = @mysql_db_query (sqlDB, $query, $conn); return 0;
if ($result) { }
$numRows = @mysql_num_rows ($result); mysql_close ($conn);
if ($numRows) { } else {
for ($i = 0 ; $i < $numRows ; $i++) { return 0;
list ($n_date, $n_user, $n_news) = mysql_fetch_row ($result); }
newsItem (dateFromSQLDateTime ($n_date), $n_user, StripSlashes($n_news)); return array (dateFromSQLDateTime ($n_date), $n_user, StripSlashes($n_news));
} }
} else {
newsItem ('now', 'Web Server', '<P>No news for this month!'); function monthlyNews ($month, $year)
} {
} else { need('date');
newsItem ('now', 'Web Server', '<P>No news in database!');
} // Do sanity checking on dates
mysql_close ($conn); if (((!is_int($year)) || $year < 2000)) {
} else { $year = date('Y',time());
newsItem ('Now', 'Web Server', '<P>Error: Could not connect to SQL server to fetch news. Please notify the server administrator.'); }
}
} if ($month < 1 || $month > 12) {
$month = date('m',time());
function searchNews ( $string ) }
{ $date = "$year-$month";
need ('date');
$conn = @mysql_pconnect (sqlHost, sqlUser, sqlPass);
$search = AddSlashes ("%$string%"); if ($conn) {
$conn = @mysql_pconnect (sqlHost, sqlUser, sqlPass); $query = 'SELECT n_date, n_user, n_news FROM news_main' .
if ($conn) { " WHERE n_date BETWEEN '$date-00 00:00:00'" .
$query = 'SELECT n_date, n_user, n_news FROM news_main' . " AND '$date-31 23:59:59'" .
" WHERE n_news LIKE '$search'" . ' ORDER BY n_date DESC';
' ORDER BY n_date DESC'; $result = @mysql_db_query (sqlDB, $query, $conn);
$result = @mysql_db_query (sqlDB, $query, $conn); if ($result) {
if ($result) { $numRows = @mysql_num_rows ($result);
$numRows = @mysql_num_rows ($result); if ($numRows) {
if ($numRows) { for ($i = 0 ; $i < $numRows ; $i++) {
tableBoxHeader( 'black', tableHeadColor ); list ($n_date, $n_user, $n_news) = mysql_fetch_row ($result);
tableTitle( "Search Results", 1, tableHeadColor ); newsItem (dateFromSQLDateTime ($n_date), $n_user, StripSlashes($n_news));
for ($i = 0 ; $i < $numRows ; $i++) { }
list ($n_date, $n_user, $n_news) = mysql_fetch_row ($result); } else {
newsItem (dateFromSQLDateTime ($n_date), $n_user, StripSlashes($n_news)); newsItem ('now', 'Web Server', '<P>No news for this month!');
} }
tableBoxFooter(); } else {
} else { newsItem ('now', 'Web Server', '<P>No news in database!');
newsItem ('now', 'Web Server', "No news found matching '$string'"); }
} mysql_close ($conn);
} else { } else {
newsItem ('now', 'Web Server', "No news found matching '$string'"); newsItem ('Now', 'Web Server', '<P>Error: Could not connect to SQL server to fetch news. Please notify the server administrator.');
} }
mysql_close ($conn); }
} else {
newsItem ('now', 'Web Server', '<STRONG>SQL error!</STRONG> Please contact the <A href="mailto:deek@quakeforge.net">Webmaster</A>.'); function searchNews ( $string )
} {
} need ('date');
?>
$search = AddSlashes ("%$string%");
$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';
$result = @mysql_db_query (sqlDB, $query, $conn);
if ($result) {
$numRows = @mysql_num_rows ($result);
if ($numRows) {
tableBoxHeader( 'black', tableHeadColor );
tableTitle( "Search Results", 1, tableHeadColor );
for ($i = 0 ; $i < $numRows ; $i++) {
list ($n_date, $n_user, $n_news) = mysql_fetch_row ($result);
newsItem (dateFromSQLDateTime ($n_date), $n_user, StripSlashes($n_news));
}
tableBoxFooter();
} else {
newsItem ('now', 'Web Server', "No news found matching '$string'");
}
} else {
newsItem ('now', 'Web Server', "No news found matching '$string'");
}
mysql_close ($conn);
} else {
newsItem ('now', 'Web Server', '<STRONG>SQL error!</STRONG> Please contact the <A href="mailto:deek@quakeforge.net">Webmaster</A>.');
}
}
?>