From 927f37abfcffc21810e9d1ecd46cdd4a20048ee9 Mon Sep 17 00:00:00 2001 From: Jeff Teunissen Date: Sat, 17 Jun 2000 11:29:29 +0000 Subject: [PATCH] News stuff: all the SQL-accessing news stuff is now in news_funcs.php -- I'm considering moving this into lib/news.php, once I get permission from Dan Olson to GPL his contributions to that file. --- index.php | 4 +- news.php | 18 +++- news_funcs.php | 228 ++++++++++++++++++++++++++++++++++++++++++------ news_search.php | 33 ------- old_news.php | 67 ++++++-------- 5 files changed, 243 insertions(+), 107 deletions(-) delete mode 100644 news_search.php diff --git a/index.php b/index.php index ef6c7d0..5d13525 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,6 @@ @@ -10,7 +10,7 @@ tableBoxHeader( 'black', tableHeadColor ); tableTitle( 'Latest News', 1, tableHeadColor ); require("news_funcs.php"); - include("cur_news.php"); + latestNews('1 month'); tableBoxFooter(); ?> diff --git a/news.php b/news.php index 5706562..ce70a0e 100644 --- a/news.php +++ b/news.php @@ -3,11 +3,21 @@ $focused = "none"; // Dock icon name to gets a border require("parts/preamble.php"); // Load most of document ?> - - - + + + + + + + +
+ +
+ +
diff --git a/news_funcs.php b/news_funcs.php index 2115214..2387289 100644 --- a/news_funcs.php +++ b/news_funcs.php @@ -1,28 +1,200 @@ -
Posted on ' . $date . ' by ' . $user . '
' . - '

' . $text . '

' . - '
'; - } - - function listMonths ( ) - { - $startyear = 2000; - $today = getdate (); - while ($startyear <= $today['year']) - { - for ($month = $today['mon']+1 ; $month > 1 ; $month--) - { - echo '

' . - date ("F, Y", mktime (0,0,0,$month,0,$today['year'],0)) . - ''; - } - $today['year']--; - } - } -?> +

Posted on ' . $date . ' by ' . $user . '
' . + '

' . $text . '

' . + '
'; + } + + function monthForm () + { + ?>
+ + + Month: + + + + + + Year: + + + + + + + + + + + +
+
+ + + String: + + + + + + + + + + + +
+ 1 ; $month--) { + echo '

' . + date ("F, Y", mktime (0,0,0,$month,0,$today['year'],0)) . + ''; + } + $today['year']--; + } + } + + function latestNews ( $length ) + { + need('date sql'); + + $conn = @mysql_pconnect (sqlHost, sqlUser, sqlPass); + if ($conn) { + $query = 'SELECT n_date, n_user, n_news FROM news_main' . + " WHERE n_date > DATE_SUB(NOW(), INTERVAL $length)" . + ' 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++) { + list ($n_date, $n_user, $n_news) = mysql_fetch_row ($result); + newsItem (dateFromSQLDateTime ($n_date), $n_user, StripSlashes($n_news)); + } + } else { + newsItem ('now', 'Web Server', '

No current news!'); + } + } else { + newsItem ('now', 'Web Server', '

No news in database!'); + } + mysql_close ($conn); + } else { + newsItem ('Now', 'Web Server', '

Error: Could not connect to SQL server to fetch news. Please notify the server administrator.'); + } + } + + function monthlyNews ( $month, $year ) + { + need('date sql'); + + // Do sanity checking on dates + if (((!is_int($year)) || $year < 2000)) { + $year = date('Y',time()); + } + + if ($month < 1 || $month > 12) { + $month = date('m',time()); + } + $date = "$year-$month"; + + $conn = @mysql_pconnect (sqlHost, sqlUser, sqlPass); + if ($conn) { + $query = 'SELECT n_date, n_user, n_news FROM news_main' . + " WHERE n_date BETWEEN '$date-00 00:00:00'" . + " AND '$date-31 23:59:59'" . + ' 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++) { + list ($n_date, $n_user, $n_news) = mysql_fetch_row ($result); + newsItem (dateFromSQLDateTime ($n_date), $n_user, StripSlashes($n_news)); + } + } else { + newsItem ('now', 'Web Server', '

No news for this month!'); + } + } else { + newsItem ('now', 'Web Server', '

No news in database!'); + } + mysql_close ($conn); + } else { + newsItem ('Now', 'Web Server', '

Error: Could not connect to SQL server to fetch news. Please notify the server administrator.'); + } + } + + function searchNews ( $string ) + { + need ('date sql'); + + $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', 'SQL error! Please contact the Webmaster.'); + } + } +?> diff --git a/news_search.php b/news_search.php deleted file mode 100644 index f8579f3..0000000 --- a/news_search.php +++ /dev/null @@ -1,33 +0,0 @@ -'. - ' '; - 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(); - echo ''; - } else { - echo '

No news found matching "' . $string . '"'; - } - } else { - echo '

No news found matching "' . $string . '"\n'; - } - mysql_close ($conn); - } else { - echo '

SQL error, please contact the webmaster.'; - } -?> \ No newline at end of file diff --git a/old_news.php b/old_news.php index 8e854f3..cc518dd 100644 --- a/old_news.php +++ b/old_news.php @@ -1,42 +1,29 @@ 12) $mon = date('m',time()); - $pageName = 'News: '. date("F, Y", mktime(0,0,0,$mon+1,0,$yr,0)); - $focused = "none"; - require("parts/preamble.php"); // Load most of document - - need ('date sql'); - require ("news_funcs.php"); -echo '
'; - tableBoxHeader( 'black', tableHeadColor ); - tableTitle( $pageName, 1, tableHeadColor ); - - $mydate = $yr . '-' . $mon; - $conn = @mysql_pconnect (sqlHost, sqlUser, sqlPass); - if ($conn) { - $query = 'SELECT n_date, n_user, n_news FROM news_main WHERE '. - 'n_date BETWEEN \'' . $mydate . '-00 00:00:00\' AND '. - '\'' . $mydate . '-31 23:59:59\'' . - ' 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++) { - list ($n_date, $n_user, $n_news) = mysql_fetch_row ($result); - newsItem (dateFromSQLDateTime ($n_date), $n_user, StripSlashes($n_news)); - } - } else { - newsItem ('now', 'Web Server', '

No news for this month!'); - } - } else { - newsItem ('now', 'Web Server', '

No news in database!'); - } - mysql_close ($conn); - } else { - newsItem ('Now', 'Web Server', '

Error: Could not connect to SQL server to fetch news. Please notify the server administrator.'); - } - tableBoxFooter(); - echo '

'; - require("parts/postamble.php"); + $pageName = 'News Archives'; + $focused = "home"; // Dock icon name to get a border + require("parts/preamble.php"); // Load most of document +?> + + + + + +
+ +