# # This file is part of Gnuheter. # See the file README for copyright notice. # # 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 the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # 02111-1307 USA. # function gethighest($table, $id) { $result = mysql_query("SELECT MAX($id) FROM $table"); if(!$result) { echo mysql_errno(). ": ".mysql_error(); exit(); } list($high) = mysql_fetch_row($result); return $high; } # list the latest articles function index() { $article = gethighest("stories", "sid"); $comment = gethighest("comments", "tid"); $poll = gethighest("poll_desc", "pollID"); $pollcomment = gethighest("pollcomments", "tid"); $diary = gethighest("diary", "did"); echo "Högsta artikelnummer: $article\n" . "Högsta kommentar-tid: $comment\n" . "Högsta omröstning: $poll\n" . "Högsta röstkommentar: $pollcomment\n" . "Högsta dagboksinlägg: $diary\n" . "\n"; } # show article(s) function showarticle($endsid, $count, $index) { global $nuke_url; if (@$count < 1) $count=1; if ($count > 50) { echo "$count stycken artiklar? Nejdu!\n"; exit; } if (@$endsid > 0) $endsql = "WHERE sid <= \"$endsid\""; $sql = "SELECT sid,title,time,topic,aid,informant,hometext,notes,bodytext" . " FROM stories $endsql ORDER BY sid DESC LIMIT $count"; $result = mysql_query($sql); if (!$result) { echo mysql_errno(). ": ".mysql_error(); exit(); } while ($resarray = mysql_fetch_row($result)) { list($sid, $title, $time, $topic, $aid, $informant, $hometext, $notes, $bodytext) = $resarray; $result2 = mysql_query("SELECT topictext FROM topics " . "WHERE topicid='$topic'"); list($topictext) = mysql_fetch_row($result2); echo "<> <> <>\n" . "$title\n" . "\n" . " Tid: " . formatTimestamp($time) . "\n" . " Avdelning: $topictext\n" . " Författare: $aid\n" . " URL: $nuke_url"."article.php?sid=$sid\n"; if ("$aid" != "$informant") echo " Insänt av: $informant\n"; echo "\n" . "$hometext\n" . "\n" . "$notes\n" . "\n" . "$bodytext\n"; } } # show comment function showcomment($tid) { global $nuke_url; # Not strictly necessary, but it feels better. if (@$tid < 1) { echo "\"$tid\" är inte en giltig tid."; exit; } $sql = "SELECT pid,sid,date,name,email,url,subject,comment" . " FROM comments WHERE tid='$tid'"; $result = mysql_query($sql); if (!$result) { echo mysql_errno(). ": ".mysql_error(); exit(); } $resarray = mysql_fetch_row($result); if (!$resarray) { echo "Kommentar $tid finns inte."; exit; } list($pid, $sid, $date, $name, $email, $url, $subject, $comment) = $resarray; $sql = "SELECT title FROM stories WHERE sid=$sid"; $result = mysql_query($sql); if (!$result) { echo mysql_errno(). ": ".mysql_error(); exit(); } $resarray = mysql_fetch_row($result); if (!$resarray) { echo "Very strange. Article $sid does not exist.\n"; exit; } list($title) = $resarray; echo "<> <> <> <> <>\n" . "$title\n" . "\n" . " Tid: " . formatTimestamp($date) . "\n" . " Författare: $name"; if ($email) echo " ($email)"; echo "\n" . " Kommentera: $nuke_url"."comments.php?op=Reply&pid=$tid&sid=$sid\n" . " Ärende: $subject\n" . "\n" . "$comment\n"; } # Show poll function showpoll($pollID) { global $nuke_url; # Not strictly necessary, but it feels better. if (@$pollID < 1) { echo "\"$pollID\" är inte en giltig pollID."; exit; } $sql = "SELECT pollTitle FROM poll_desc WHERE pollID='$pollID'"; $result = mysql_query($sql); if (!$result) { echo mysql_errno(). ": ".mysql_error(); exit(); } $resarray = mysql_fetch_row($result); if (!$resarray) { echo "Undersökning $pollID finns inte."; exit; } list($pollTitle) = $resarray; echo "<>\n" . "Undersökning: $pollTitle\n" . "\n" . " Avdelning: Undersökning\n" . " Röstningsbås: http://www.gnuheter.com/pollBooth.php?pollID=$pollID\n" . " Resultat: http://www.gnuheter.org/pollBooth.php?op=results&pollID=$pollID\n" . "\n" . " $pollTitle\n" . "\n"; $sql = "SELECT optionText FROM poll_data WHERE pollID=$pollID"; $result = mysql_query($sql); if (!$result) { echo mysql_errno(). ": ".mysql_error(); exit(); } while ($resarray = mysql_fetch_row($result)) { list($optionText) = $resarray; if ($optionText) echo " * $optionText\n"; } echo "\n"; } # show pollcomment function showpollcomment($tid) { global $nuke_url; if (@$tid < 1) { echo "\"$tid\" är inte en giltig tid."; exit; } $sql = "SELECT pid,pollID,date,name,email,url,subject,comment" . " FROM pollcomments WHERE tid='$tid'"; $result = mysql_query($sql); if (!$result) { echo mysql_errno(). ": ".mysql_error(); exit(); } $resarray = mysql_fetch_row($result); if (!$resarray) { echo "Undersökningskommentar $tid finns inte."; exit; } list($pid, $pollID, $date, $name, $email, $url, $subject, $comment) = $resarray; $sql = "SELECT pollTitle FROM poll_desc WHERE pollID=$pollID"; $result = mysql_query($sql); if (!$result) { echo mysql_errno(). ": ".mysql_error(); exit(); } $resarray = mysql_fetch_row($result); if (!$resarray) { echo "Mycket konstigt. Undersökning $pollID finns inte.\n"; exit; } list($pollTitle) = $resarray; echo "<> <> <> <> <>\n" . "Undersökning: $pollTitle\n" . "\n" . " Tid: " . formatTimestamp($date) . "\n" . " Författare: $name"; if ($email) echo " ($email)"; echo "\n" . " Kommentera: $nuke_url"."pollcomments.php?op=Reply&pid=$tid&pollID=$pollID\n" . " Ärende: $subject\n" . "\n" . "$comment\n"; } # Show diary function showdiary($did) { global $nuke_url; if (@$did < 1) { echo "\"$did\" är inte en giltig did."; exit; } $sql = "SELECT aid,title,time,bodytext FROM diary WHERE did='$did'"; $result = mysql_query($sql); if (!$result) { echo mysql_errno(). ": ".mysql_error(); exit(); } $resarray = mysql_fetch_row($result); if (!$resarray) { echo "Dagboksinlägg $did finns inte."; exit; } list($aid, $title, $time, $bodytext) = $resarray; echo "<> <> <>\n" . "Dagbok: ($aid) $title\n" . "\n" . " Tid: " . formatTimestamp($time) . "\n" . " Författare: $aid\n" . " Ärende: $title\n" . "\n" . "$bodytext\n"; } # Show help function help() { global $nuke_url; $url = "$nuke_url"."jcexport.php?op="; echo "Användning:\n" . $url."help Den här hjälptexten.\n" . $url."index Visa högsta kommentar/artikelnummer.\n" . $url."diary&did=DID Visa daboksinlägg nummer DID.\n" . $url."pollcomment&tid=TID Visa undersökningskommentar nummer TID\n" . $url."poll&pollID=ID Visa undersökning nummer ID\n" . $url."comment&tid=TID Visa kommentar nummer TID\n" . $url."article[&sid=SID][&count=COUNT]\n" . " Visa COUNT kommentarer där SID är den med högst nummer.\n" . " SID defaultar till den sista kommentaren.\n" . " COUNT defaultar till 1.\n" . "\n" . " Lägg till &index=yes för att se index först.\n"; } include('mainfile.php'); dbconnect(); header("Content-Type: text/plain"); if ("$index" == "yes") index(); switch ($op) { case "article": showarticle($sid, $count, $index); break; case "comment": showcomment($tid); break; case "poll": showpoll($pollID); break; case "pollcomment": showpollcomment($tid); break; case "diary": showdiary($did); break; case "index": index(); break; case "help": default: help(); } include('counter.php'); ?>