diff -Nur NewsPortal-orig/killfile.php NewsPortal-new/killfile.php --- NewsPortal-orig/killfile.php 1970-01-01 01:00:00.000000000 +0100 +++ NewsPortal-new/killfile.php 2004-12-12 23:19:31.000000000 +0100 @@ -0,0 +1,62 @@ + + // see end of newsportal.php for a short comment on killfile functionality. + + // register parameters + $author = ""; + if (isset($_REQUEST["author"]))$author=urldecode($_REQUEST["author"]); + $remove = ""; + if (isset($_REQUEST["remove"])) $remove=urldecode($_REQUEST["remove"]); + $return = ""; + if (isset($_REQUEST["return"])) $return=urldecode($_REQUEST["return"]); + + include "config.inc.php"; + include "auth.inc"; + include "$file_newsportal"; + parse_killfile_cookies(); + + if ($author != "") + { + add_author_to_killfile($author); + set_killfile_cookies(); + } + else if ($remove != "") + { + remove_author_from_killfile($remove); + set_killfile_cookies(); + } + + include "head.inc"; +?> + +

+ +"; + + $killauthors = get_authors_in_killfile(); + for ($i=0; $i "; + echo htmlspecialchars($killauthors[$i]); + echo ' (remove)'; + } + echo ""; + } + + if ($return != "") + { + echo "

"; + echo 'Return to article/thread view (make sure to shift-reload the view to take changes into account)'; + } + + include "tail.inc"; +?> diff -Nur NewsPortal-orig/lang/deutsch.lang NewsPortal-new/lang/deutsch.lang --- NewsPortal-orig/lang/deutsch.lang 2004-04-03 02:34:30.000000000 +0200 +++ NewsPortal-new/lang/deutsch.lang 2004-12-13 09:22:10.000000000 +0100 @@ -58,5 +58,6 @@ $text_error["auth_error"]="Authentifikation beim Newsserver fehlgeschlagen."; $text_error["spool_error"]="Fehler in Spooldatei. Bitte neuladen."; +$text_kill["add_author_to_killfile"]="Zu Killfile hinzufügen"; ?> diff -Nur NewsPortal-orig/lang/english.lang NewsPortal-new/lang/english.lang --- NewsPortal-orig/lang/english.lang 2004-04-03 02:34:30.000000000 +0200 +++ NewsPortal-new/lang/english.lang 2004-12-12 21:10:56.000000000 +0100 @@ -58,4 +58,6 @@ $text_error["auth_error"]="Authentifikation at the Newsserver failed."; $text_error["spool_error"]="Error in spoolfile. Please reload."; +$text_kill["add_author_to_killfile"]="Add to killfile"; + ?> diff -Nur NewsPortal-orig/newsportal.php NewsPortal-new/newsportal.php --- NewsPortal-orig/newsportal.php 2004-04-03 02:39:00.000000000 +0200 +++ NewsPortal-new/newsportal.php 2004-12-13 23:21:38.000000000 +0100 @@ -1550,6 +1550,9 @@ $lineclass="np_thread_line".(($article_count%2)+1); // read the first article $c=$headers[$liste[$i]]; + + if (author_is_in_killfile($c->from)) continue; + $article_count++; // Render the graphical tree switch ($thread_treestyle) { @@ -1833,7 +1836,7 @@ // exists a cached html-output? $filename=$spooldir."/".$group."-".$article_first."-". $article_last.".html"; - if (!file_exists($filename)) { + if (!(file_exists($filename) && is_killfile_empty())) { // no, we need to create a new html-output $output=""; reset($headers); @@ -1849,10 +1852,14 @@ $output.=showThread($headers,$liste,1,"",$group,$article_first, $article_last,$article_count); } - // cache the html-output - $file=fopen($filename,"w"); - fputs($file,$output); - fclose($file); + if (is_killfile_empty()) + { + // cache the html-output + // only if kill file is empty. + $file=fopen($filename,"w"); + fputs($file,$output); + fclose($file); + } } else { // yes, a cached output exists, load it! $file=fopen($filename,"r"); @@ -1876,6 +1883,7 @@ function show_header($head,$group) { global $article_show,$text_header,$file_article,$attachment_show; global $file_attachment,$anonym_address; + global $text_kill; echo '

'; if ($article_show["Subject"]) echo $text_header["subject"].htmlspecialchars($head->subject)."
"; if ($article_show["From"]) { @@ -1895,6 +1903,11 @@ echo ''; if ($head->name != "") echo ' ('.htmlspecialchars($head->name).')'; } + // fred + + echo ' -- ('; + echo $text_kill["add_author_to_killfile"]; + echo ')'; + // fred - echo "
"; } if ($article_show["Newsgroups"]) @@ -2281,4 +2294,142 @@ return $message; } -?> \ No newline at end of file +/* -------------- + * Killfile extensions, 2004-12-12, Frederik Ramm + * + * Very crude killfile mechanism that allows users to store "From" header + * values in a killfile cookie and filters them from thread listings. + * A primitive means of editing the list is available with killfile.php. + * Caveat emptor! Authors on the kill list currently cut off everything + * that would come below in the same thread. + * + * Cookie functionality is encapsulated in these routines to make it + * easy to change the mechanism later. + * + * The whole killfile stuff still has to be internationalized properly. + * + * A few words about the "user experience": + * Following the "From:" header in an article listing, a hyperlink is + * displayed that adds this author to the kill file. + * Additionally, every thread view has a hyperlink at the top for + * branching to the kill file view (unless the user does not have a + * kill file defined). + */ + +/* + * parses the kill cookie and reads its contents into a global variable. + * has to be called by all scripts that need killfile functionality. + */ +function parse_killfile_cookies() { + global $killfile; + global $HTTP_COOKIE_VARS; + if (isset($HTTP_COOKIE_VARS["npkill"])) { + $zip = base64_decode($HTTP_COOKIE_VARS["npkill"]); + $version = substr($zip,0,1); + + // the following makes a version distinction based on the + // first character of the cookie. the idea is that later + // versions of this software with increased killfile + // capabilites will have the need to encapsulate more + // information in that cookie, requiring a different + // and incompatible structure. old-style cookies still + // stored on the user machine would then either be lost + // or, worse, trigger a php error. the version code will + // enable us to make an informed decision on how to + // process (or disregard) the cookie. + + if ($version == "a") { + // "version a" cookie + parse_killfile_cookies_version_a(substr($zip, 1)); + } + else + { + // unknown version + $killfile=array(); + } + } + else + { + $killfile=array(); + } + sort($killfile); +} + +/* + * helper for parse_killfile_cookies. decodes a "version a" cookie. + * a "version a" cookie consists of a leading "Z", followed by a + * gz-deflated version of a serialized array. + */ +function parse_killfile_cookies_version_a($cookieval) { + global $killfile; + // remove leading "Z" marker and version code + $ser = gzinflate(substr($cookieval, 1)); + $killfile = unserialize($ser); +} + +/* + * adds someone to the internal kill file list. + */ +function add_author_to_killfile($author) { + global $killfile; + if (!author_is_in_killfile($author)) { + $killfile[] = $author; + sort($killfile); + } +} + +/* + * produces a cookie from the internal kill file list. must be + * called before output is started. + * The internal array is serialized, zipped, and base-64 encoded. + * TODO: zip only if size is actually reduced. + * this implementation writes a "version a" cookie. + */ +function set_killfile_cookies() { + global $killfile; + $ser = serialize($killfile); + $zip = "Z".gzdeflate($ser); // add "Z" marker for later use + $b64 = base64_encode("a".$zip); // add "a" marker for "version a" + setcookie("npkill", $b64); +} + +/* + * returns an array with all the authors in the kill file. + */ +function get_authors_in_killfile() { + global $killfile; + return $killfile; +} + +/* + * checks whether a certian author is in the kill file. + */ +function author_is_in_killfile($author) { + global $killfile; + return is_array($killfile) && in_array($author, $killfile); +} + +/* + * removes an author from the internal kill file by copying only + * the not-removed entries. + */ +function remove_author_from_killfile($author) { + global $killfile; + $newkillfile = array(); + for ($src = 0; $src diff -Nur NewsPortal-orig/thread.php NewsPortal-new/thread.php --- NewsPortal-orig/thread.php 2004-04-03 02:34:30.000000000 +0200 +++ NewsPortal-new/thread.php 2004-12-12 23:06:09.000000000 +0100 @@ -18,14 +18,21 @@

'; if (!$readonly) echo '['.$text_thread["button_write"]."] "; -echo '['.$text_thread["button_grouplist"].']'; +echo '['.$text_thread["button_grouplist"].'] '; +if (!is_killfile_empty()) +{ + $return = urlencode($_SERVER["REQUEST_URI"]); + echo '[You have set up a kill file. Click here to edit it.]'; +} echo '

'; -include("$file_newsportal"); + $ns=nntp_open($server,$port); flush(); if ($ns != false) {