* Added ctdlelements.php ... this is to be used for functions which fetch
authorArt Cancro <ajc@citadel.org>
Tue, 18 Nov 2003 04:58:34 +0000 (04:58 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 18 Nov 2003 04:58:34 +0000 (04:58 +0000)
  Citadel protocol data and convert it to insertable HTML.
* Implemented a first cut of a "read message" function.

ctdlphp/ChangeLog
ctdlphp/ctdlelements.php [new file with mode: 0644]
ctdlphp/ctdlheader.php
ctdlphp/ctdlprotocol.php
ctdlphp/readmsgs.php

index aa5d436fb9bdc350fcba33da97f4d540eac9d83e..9ed300cad15b965020ed458c376e9c330e0ca98c 100644 (file)
@@ -1,4 +1,9 @@
  $Log$
+ Revision 1.18  2003/11/18 04:58:34  ajc
+ * Added ctdlelements.php ... this is to be used for functions which fetch
+   Citadel protocol data and convert it to insertable HTML.
+ * Implemented a first cut of a "read message" function.
+
  Revision 1.17  2003/11/14 17:15:19  ajc
  * Identify our message format preference (HTML followed by plain text)
    to the server upon connection, so MSG4 commands run properly.
@@ -73,4 +78,3 @@
 
  Revision 1.1  2003/10/31 03:47:13  ajc
  * Initial CVS import
-
diff --git a/ctdlphp/ctdlelements.php b/ctdlphp/ctdlelements.php
new file mode 100644 (file)
index 0000000..efee340
--- /dev/null
@@ -0,0 +1,42 @@
+<?PHP
+
+// $Id$
+// 
+// Translates Citadel protocol data to insertable HTML snippets.  You can
+// use these directly, or you can bypass them completely.
+//
+// Copyright (c) 2003 by Art Cancro <ajc@uncensored.citadel.org>
+// This program is released under the terms of the GNU General Public License.
+
+
+//
+// Fetch and display a message.
+//
+function display_message($msgnum) {
+
+       echo '<TABLE border=0 width=100% bgcolor="#DDDDDD"><TR><TD>' ;
+       // Fetch the message from the server
+       list($ok, $response, $fields) = ctdl_fetch_message($msgnum);
+
+       // Bail out gracefully if the message isn't there.
+       if (!$ok) {
+               echo "Error: " . htmlspecialchars($response) . "<BR>" ;
+               echo '</TD></TR></TABLE>' ;
+               return;
+       }
+
+       // Begin header
+       echo "<B><I>" .
+               strftime("%b %d %Y %I:%M%p ", $fields["time"]) .
+               " from " . htmlspecialchars($fields["from"]) .
+               "</I></B><BR>\n" ;
+
+       // Do message text
+       echo $fields["text"] . "<BR>";
+
+       echo '</TD></TR></TABLE><BR>' ;
+}
+
+
+
+?>
index c5b8f5e6421fce1a0db4770f753c35d5c4c04002..635df8be43d228432e157c36c2926d94a3ae368e 100644 (file)
@@ -16,6 +16,7 @@
 //
 include "ctdlsession.php";
 include "ctdlprotocol.php";
+include "ctdlelements.php";
 
 function bbs_page_header() {
 
index b3ebe337998a89de63eaf8adea68cbcfa45d40bc..7770364112ffe252bf9ff5c583a8be43e992a79e 100644 (file)
@@ -335,4 +335,76 @@ function ctdl_msgs($mode, $count) {
 }
 
 
+// Load a message from the server.
+function ctdl_fetch_message($msgnum) {
+       global $clientsocket;
+
+       serv_puts("MSG4 " . $msgnum);
+       $response = serv_gets();
+
+       if (substr($response, 0, 1) != "1") {
+               return array(FALSE, substr($response, 4), NULL);
+       }
+
+       $fields = array();
+       while (strcmp($buf = serv_gets(), "000")) {
+               if (substr($buf, 0, 4) == "text") {
+                       // We're in the text body.  New loop here.
+                       $fields["text"] = ctdl_msg4_from_server();
+                       return array(TRUE, substr($response, 4), $fields);
+               }
+               else {
+                       $fields[substr($buf, 0, 4)] = substr($buf, 5);
+               }
+       }
+
+       // Message terminated prematurely (no text body)
+       return array(FALSE, substr($response, 4), $fields);
+}
+
+// Support function for ctdl_fetch_message().  This handles the text body
+// portion of the message, converting various formats to HTML as
+// appropriate.
+function ctdl_msg4_from_server() {
+
+       $txt = "";
+       $msgformat = "text/plain";
+       $in_body = FALSE;
+
+       $previous_line = "";
+       while (strcmp($buf = serv_gets(), "000")) {
+               if ($in_body == FALSE) {
+                       if (strlen($buf) == 0) {
+                               $in_body = TRUE;
+                       }
+                       else {
+                               if (!strncasecmp($buf, "content-type: ", 14)) {
+                                       $msgformat = substr($buf, 14);
+                               }
+                       }
+               }
+               else {
+                       if (!strcasecmp($msgformat, "text/html")) {
+                               $txt .= $buf;
+                       }
+                       else if (!strcasecmp($msgformat, "text/plain")) {
+                               $txt .= "<TT>" . htmlspecialchars($buf) . "</TT><BR>\n" ;
+                       }
+                       else if (!strcasecmp($msgformat, "text/x-citadel-variformat")) {
+                               if (substr($previous_line, 0, 1) == " ") {
+                                       $txt .= "<BR>\n" ;
+                               }
+                               $txt .= htmlspecialchars($buf);
+                       }
+                       else {
+                               $txt .= htmlspecialchars($buf);
+                       }
+                       $previous_line = $buf;
+               }
+       }
+
+       return($txt);
+}
+
+
 ?>
index 2c81dd41a3be20ae5baf6eb1992654da7ddf04ae..1ea74c5ed1cb48bf6e2903b75ca1bc29c6646560 100644 (file)
@@ -9,7 +9,7 @@
        echo "response: " . htmlspecialchars($response) . "<BR>\n" ;
 
         if ($num_msgs > 0) foreach ($msgs as $msgnum) {
-               echo $msgnum . ", " ;
+               display_message($msgnum);
        }
 
 ?>