cvs: pear /Forum/lib/classes ForumList.php /Forum/lib/classes/db NNTPStandard.php /Net_NNTP NNTP.php
| From: | Morgan Christiansson | Date: | Tue, 30 Oct 2001 22:17:31 +0000 |
| Subject: | cvs: pear /Forum/lib/classes ForumList.php /Forum/lib/classes/db NNTPStandard.php /Net_NNTP NNTP.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-1210@lists.php.net to get a copy of this message | ||
mog Tue Oct 30 17:17:31 2001 EDT
Modified files:
/pear/Forum/lib/classes ForumList.php
/pear/Forum/lib/classes/db NNTPStandard.php
/pear/Net_NNTP NNTP.php
Log:
Some indentation fixes and NNTP additions both in Net_NNTP and Forum.
Index: pear/Forum/lib/classes/ForumList.php diff -u pear/Forum/lib/classes/ForumList.php:1.2 pear/Forum/lib/classes/ForumList.php:1.3 --- pear/Forum/lib/classes/ForumList.php:1.2 Sat Oct 27 08:12:29 2001 +++ pear/Forum/lib/classes/ForumList.php Tue Oct 30 17:17:31 2001 @@ -137,7 +137,7 @@ $ARR["URL"]=forum_get_url(FORUM_READ, $this->forum_id, $row["thread_id"],$row["message_id"]); // Image view - $ARR["IMAGE"] = ""; + $ARR["IMAGE"] = array(); $LEVEL=sizeof($this->level); foreach($this->level as $val) { $LEVEL-=1; @@ -189,6 +189,7 @@ //debug code, handy to have around //$TPL["SUBJECT"] .= /*<br>timestamp: $ARR[TIMESTAMP]*/ "<br>message: $ARR[MESSAGE_ID] parent: $ARR[PARENT_ID] replies_left: ".@$this->rows[$row["parent_id"]]["replies_left"]."<br>".implode(",",$this->level); + if(!isset($row["parent_id"])) my_var_dump($row); if(isset($this->rows[$row["parent_id"]]["replies_left"])) { $this->rows[$row["parent_id"]]["replies_left"] -= 1; } Index: pear/Forum/lib/classes/db/NNTPStandard.php diff -u pear/Forum/lib/classes/db/NNTPStandard.php:1.2 pear/Forum/lib/classes/db/NNTPStandard.php:1.3 --- pear/Forum/lib/classes/db/NNTPStandard.php:1.2 Mon Oct 29 16:23:19 2001 +++ pear/Forum/lib/classes/db/NNTPStandard.php Tue Oct 30 17:17:31 2001 @@ -13,18 +13,12 @@ var $db=FALSE; function connect() { - /* - $this->db = new ForumNNTP("news1.telia.com"); - if(PEAR::isError($this->db)) { - return $this->db; + if(!is_object($this->db)) { + require_once("Net_NNTP/NNTP.php"); + $this->db = new Net_NNTP; + $this->db->connect("news.php.net"); + $this->db->_debug = 1; } - */ - if(!is_object($this->db)) { - require_once("Net_NNTP/NNTP.php"); - $this->db = new Net_NNTP; - $this->db->connect("news.php.net"); - $this->db->_debug = 1; - } } /** @@ -147,36 +141,44 @@ } function process_headers($rows) { + foreach($rows as $msgid => $row) { + + $row["user_id"] = NULL; + $row["replies_left"] = 0; + $row["replies"] = array(); + + $row["message_id"] = $row["Message-ID"]; + $row["subject"] = $row["Subject"]; + $row["author"] = $row["From"]; + $row["timestamp"] = strtotime($row["Date"]); + $row["thread_id"] = $row["Message-ID"]; + $row["parent_id"] = $row["References"]; + if(empty($row["References"])) { + $row["parent_id"] = 0; + $row["References"] = 0; + } + $rows[$msgid] = $row; + } + $rows[0] = array( "replies_left" => 0, "message_id" => 0, "parent_id" => 0, ); - foreach($rows as $msgid => $roww) { - $row =& $rows[$msgid]; + foreach($rows as $row) { - if(isset($row["message_id"]) && $row["message_id"] == 0) { continue; } - - $rows[$row["Message-ID"]]["user_id"] = NULL; - $rows[$row["Message-ID"]]["message_id"] = $row["Message-ID"]; - $rows[$row["Message-ID"]]["subject"] = $row["Subject"]; - $rows[$row["Message-ID"]]["author"] = $row["From"]; - $rows[$row["Message-ID"]]["timestamp"] = strtotime($row["Date"]); - $rows[$row["Message-ID"]]["thread_id"] = $row["Message-ID"]; - if(empty($row["References"])) { - $rows[$row["Message-ID"]]["parent_id"] = 0; - $rows[$row["Message-ID"]]["References"] = 0; + if(isset($row["message_id"]) && $row["message_id"] === 0) { + trigger_error("Skipped root message",E_USER_NOTICE); + continue; } - - + if(!isset($rows[$row["References"]])) { trigger_error("Orphan message (id: ".$row["Message-ID"]."), parent (id: $row[parent_id]) does not exist", E_USER_WARNING); } $rows[$row["References"]]["replies"][] = $row["Message-ID"]; $rows[$row["References"]]["replies_left"] += 1; - unset($row); + $rows[$row["Message-ID"]] = $row; } - my_var_dump($rows); return($rows); } @@ -247,31 +249,17 @@ */ function get_forums($parent_id="") { $this->connect(); - $groups=array(); - foreach($this->db->get_groups(NNTP_ALL) as $group) { - $groups[$group["group"]] = array( - "forum_id" => $group["group"], - "name" => $group["group"], - "count" => $group["last"] - $group["first"], - "description" => $group["desc"], - "last_post" => $group["last"] - ); - } - return $groups; - - /* - return array( - "telia.internet.news.test" => array( - "forum_id" => $group[3], - "name" => $group[3], - // used to kill warnings - "count" => $group[0], - "description" => "", - "last_post" => $group[2], - ) - ); - */ - trigger_error("TODO",E_USER_ERROR); + $groups=array(); + foreach($this->db->get_groups(NNTP_ALL) as $group) { + $groups[$group["group"]] = array( + "forum_id" => $group["group"], + "name" => $group["group"], + "count" => $group["last"] - $group["first"], + "description" => $group["desc"], + "last_post" => $group["last"] + ); + } + return $groups; } /** @@ -370,8 +358,6 @@ "WHERE forum_id='$forum_id'"; return($this->query($SQL)); } - -} // end class - +} ?> Index: pear/Net_NNTP/NNTP.php diff -u pear/Net_NNTP/NNTP.php:1.5 pear/Net_NNTP/NNTP.php:1.6 --- pear/Net_NNTP/NNTP.php:1.5 Mon Oct 29 16:46:05 2001 +++ pear/Net_NNTP/NNTP.php Tue Oct 30 17:17:31 2001 @@ -18,10 +18,13 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: NNTP.php,v 1.5 2001/10/29 21:46:05 mog Exp $ +// $Id: NNTP.php,v 1.6 2001/10/30 22:17:31 mog Exp $ require_once 'PEAR.php'; +define("NNTP_ALL"0,); +define("NNTP_NAMES",1); +define("NNTP_LIST",2); /** * The NNTP:: class fetches UseNet news articles acording to the standard * based on RFC 1036. @@ -345,16 +348,16 @@ * @author Morgan Christiansson <mog@linux.nu> */ function get_data() { - $body = array(); - while(!feof($this->fp)) { - $line = trim(fgets($this->fp, 256)); - if ($line == '.') { - break; - } else { - $body[] = $line; - } - } - return $body; + $body = array(); + while(!feof($this->fp)) { + $line = trim(fgets($this->fp, 256)); + if ($line == '.') { + break; + } else { + $body[] = $line; + } + } + return $body; } /** @@ -412,26 +415,26 @@ } function get_overview($first,$last) { - $format = $this->get_overview_fmt(); + $format = $this->get_overview_fmt(); - $this->command("XOVER $first-$last"); - foreach($this->get_data() as $line) { - $i=0; - foreach(explode("\t",$line) as $line) { - $message[$format[$i++]] = $line; - } - $messages[$message["number"]] = $message; - } + $this->command("XOVER $first-$last"); + foreach($this->get_data() as $line) { + $i=0; + foreach(explode("\t",$line) as $line) { + $message[$format[$i++]] = $line; + } + $messages[$message["Message-ID"]] = $message; + } - $this->command("XROVER $first-$last"); - foreach($this->get_data() as $line) { - $i=0; - foreach(explode("\t",$line) as $line) { - $message[$format[$i++]] = $line; - } - $messages[$message["number"]] = $message; - } - return $messages; + $this->command("XROVER $first-$last"); + foreach($this->get_data() as $line) { + $i=0; + foreach(explode("\t",$line) as $line) { + $message[$format[$i++]] = $line; + } + $messages[$message["Message-ID"]] = $message; + } + return $messages; } /**
Index: pear/Forum/lib/classes/ForumList.php diff -u pear/Forum/lib/classes/ForumList.php:1.2 pear/Forum/lib/classes/ForumList.php:1.3 --- pear/Forum/lib/classes/ForumList.php:1.2 Sat Oct 27 08:12:29 2001 +++ pear/Forum/lib/classes/ForumList.php Tue Oct 30 17:17:31 2001 @@ -137,7 +137,7 @@ $ARR["URL"]=forum_get_url(FORUM_READ, $this->forum_id, $row["thread_id"],$row["message_id"]); // Image view - $ARR["IMAGE"] = ""; + $ARR["IMAGE"] = array(); $LEVEL=sizeof($this->level); foreach($this->level as $val) { $LEVEL-=1; @@ -189,6 +189,7 @@ //debug code, handy to have around //$TPL["SUBJECT"] .= /*<br>timestamp: $ARR[TIMESTAMP]*/ "<br>message: $ARR[MESSAGE_ID] parent: $ARR[PARENT_ID] replies_left: ".@$this->rows[$row["parent_id"]]["replies_left"]."<br>".implode(",",$this->level); + if(!isset($row["parent_id"])) my_var_dump($row); if(isset($this->rows[$row["parent_id"]]["replies_left"])) { $this->rows[$row["parent_id"]]["replies_left"] -= 1; } Index: pear/Forum/lib/classes/db/NNTPStandard.php diff -u pear/Forum/lib/classes/db/NNTPStandard.php:1.2 pear/Forum/lib/classes/db/NNTPStandard.php:1.3 --- pear/Forum/lib/classes/db/NNTPStandard.php:1.2 Mon Oct 29 16:23:19 2001 +++ pear/Forum/lib/classes/db/NNTPStandard.php Tue Oct 30 17:17:31 2001 @@ -13,18 +13,12 @@ var $db=FALSE; function connect() { - /* - $this->db = new ForumNNTP("news1.telia.com"); - if(PEAR::isError($this->db)) { - return $this->db; + if(!is_object($this->db)) { + require_once("Net_NNTP/NNTP.php"); + $this->db = new Net_NNTP; + $this->db->connect("news.php.net"); + $this->db->_debug = 1; } - */ - if(!is_object($this->db)) { - require_once("Net_NNTP/NNTP.php"); - $this->db = new Net_NNTP; - $this->db->connect("news.php.net"); - $this->db->_debug = 1; - } } /** @@ -147,36 +141,44 @@ } function process_headers($rows) { + foreach($rows as $msgid => $row) { + + $row["user_id"] = NULL; + $row["replies_left"] = 0; + $row["replies"] = array(); + + $row["message_id"] = $row["Message-ID"]; + $row["subject"] = $row["Subject"]; + $row["author"] = $row["From"]; + $row["timestamp"] = strtotime($row["Date"]); + $row["thread_id"] = $row["Message-ID"]; + $row["parent_id"] = $row["References"]; + if(empty($row["References"])) { + $row["parent_id"] = 0; + $row["References"] = 0; + } + $rows[$msgid] = $row; + } + $rows[0] = array( "replies_left" => 0, "message_id" => 0, "parent_id" => 0, ); - foreach($rows as $msgid => $roww) { - $row =& $rows[$msgid]; + foreach($rows as $row) { - if(isset($row["message_id"]) && $row["message_id"] == 0) { continue; } - - $rows[$row["Message-ID"]]["user_id"] = NULL; - $rows[$row["Message-ID"]]["message_id"] = $row["Message-ID"]; - $rows[$row["Message-ID"]]["subject"] = $row["Subject"]; - $rows[$row["Message-ID"]]["author"] = $row["From"]; - $rows[$row["Message-ID"]]["timestamp"] = strtotime($row["Date"]); - $rows[$row["Message-ID"]]["thread_id"] = $row["Message-ID"]; - if(empty($row["References"])) { - $rows[$row["Message-ID"]]["parent_id"] = 0; - $rows[$row["Message-ID"]]["References"] = 0; + if(isset($row["message_id"]) && $row["message_id"] === 0) { + trigger_error("Skipped root message",E_USER_NOTICE); + continue; } - - + if(!isset($rows[$row["References"]])) { trigger_error("Orphan message (id: ".$row["Message-ID"]."), parent (id: $row[parent_id]) does not exist", E_USER_WARNING); } $rows[$row["References"]]["replies"][] = $row["Message-ID"]; $rows[$row["References"]]["replies_left"] += 1; - unset($row); + $rows[$row["Message-ID"]] = $row; } - my_var_dump($rows); return($rows); } @@ -247,31 +249,17 @@ */ function get_forums($parent_id="") { $this->connect(); - $groups=array(); - foreach($this->db->get_groups(NNTP_ALL) as $group) { - $groups[$group["group"]] = array( - "forum_id" => $group["group"], - "name" => $group["group"], - "count" => $group["last"] - $group["first"], - "description" => $group["desc"], - "last_post" => $group["last"] - ); - } - return $groups; - - /* - return array( - "telia.internet.news.test" => array( - "forum_id" => $group[3], - "name" => $group[3], - // used to kill warnings - "count" => $group[0], - "description" => "", - "last_post" => $group[2], - ) - ); - */ - trigger_error("TODO",E_USER_ERROR); + $groups=array(); + foreach($this->db->get_groups(NNTP_ALL) as $group) { + $groups[$group["group"]] = array( + "forum_id" => $group["group"], + "name" => $group["group"], + "count" => $group["last"] - $group["first"], + "description" => $group["desc"], + "last_post" => $group["last"] + ); + } + return $groups; } /** @@ -370,8 +358,6 @@ "WHERE forum_id='$forum_id'"; return($this->query($SQL)); } - -} // end class - +} ?> Index: pear/Net_NNTP/NNTP.php diff -u pear/Net_NNTP/NNTP.php:1.5 pear/Net_NNTP/NNTP.php:1.6 --- pear/Net_NNTP/NNTP.php:1.5 Mon Oct 29 16:46:05 2001 +++ pear/Net_NNTP/NNTP.php Tue Oct 30 17:17:31 2001 @@ -18,10 +18,13 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: NNTP.php,v 1.5 2001/10/29 21:46:05 mog Exp $ +// $Id: NNTP.php,v 1.6 2001/10/30 22:17:31 mog Exp $ require_once 'PEAR.php'; +define("NNTP_ALL"0,); +define("NNTP_NAMES",1); +define("NNTP_LIST",2); /** * The NNTP:: class fetches UseNet news articles acording to the standard * based on RFC 1036. @@ -345,16 +348,16 @@ * @author Morgan Christiansson <mog@linux.nu> */ function get_data() { - $body = array(); - while(!feof($this->fp)) { - $line = trim(fgets($this->fp, 256)); - if ($line == '.') { - break; - } else { - $body[] = $line; - } - } - return $body; + $body = array(); + while(!feof($this->fp)) { + $line = trim(fgets($this->fp, 256)); + if ($line == '.') { + break; + } else { + $body[] = $line; + } + } + return $body; } /** @@ -412,26 +415,26 @@ } function get_overview($first,$last) { - $format = $this->get_overview_fmt(); + $format = $this->get_overview_fmt(); - $this->command("XOVER $first-$last"); - foreach($this->get_data() as $line) { - $i=0; - foreach(explode("\t",$line) as $line) { - $message[$format[$i++]] = $line; - } - $messages[$message["number"]] = $message; - } + $this->command("XOVER $first-$last"); + foreach($this->get_data() as $line) { + $i=0; + foreach(explode("\t",$line) as $line) { + $message[$format[$i++]] = $line; + } + $messages[$message["Message-ID"]] = $message; + } - $this->command("XROVER $first-$last"); - foreach($this->get_data() as $line) { - $i=0; - foreach(explode("\t",$line) as $line) { - $message[$format[$i++]] = $line; - } - $messages[$message["number"]] = $message; - } - return $messages; + $this->command("XROVER $first-$last"); + foreach($this->get_data() as $line) { + $i=0; + foreach(explode("\t",$line) as $line) { + $message[$format[$i++]] = $line; + } + $messages[$message["Message-ID"]] = $message; + } + return $messages; } /**