From 94912e04015f434aa68951d24a34a078771a8384 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 18 Nov 2003 04:58:34 +0000 Subject: [PATCH] * 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. --- ctdlphp/ChangeLog | 6 +++- ctdlphp/ctdlelements.php | 42 +++++++++++++++++++++++ ctdlphp/ctdlheader.php | 1 + ctdlphp/ctdlprotocol.php | 72 ++++++++++++++++++++++++++++++++++++++++ ctdlphp/readmsgs.php | 2 +- 5 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 ctdlphp/ctdlelements.php diff --git a/ctdlphp/ChangeLog b/ctdlphp/ChangeLog index aa5d436fb..9ed300cad 100644 --- a/ctdlphp/ChangeLog +++ b/ctdlphp/ChangeLog @@ -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 index 000000000..efee34000 --- /dev/null +++ b/ctdlphp/ctdlelements.php @@ -0,0 +1,42 @@ + +// This program is released under the terms of the GNU General Public License. + + +// +// Fetch and display a message. +// +function display_message($msgnum) { + + echo '
' ; + // 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) . "
" ; + echo '
' ; + return; + } + + // Begin header + echo "" . + strftime("%b %d %Y %I:%M%p ", $fields["time"]) . + " from " . htmlspecialchars($fields["from"]) . + "
\n" ; + + // Do message text + echo $fields["text"] . "
"; + + echo '
' ; +} + + + +?> diff --git a/ctdlphp/ctdlheader.php b/ctdlphp/ctdlheader.php index c5b8f5e64..635df8be4 100644 --- a/ctdlphp/ctdlheader.php +++ b/ctdlphp/ctdlheader.php @@ -16,6 +16,7 @@ // include "ctdlsession.php"; include "ctdlprotocol.php"; +include "ctdlelements.php"; function bbs_page_header() { diff --git a/ctdlphp/ctdlprotocol.php b/ctdlphp/ctdlprotocol.php index b3ebe3379..777036411 100644 --- a/ctdlphp/ctdlprotocol.php +++ b/ctdlphp/ctdlprotocol.php @@ -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 .= "" . htmlspecialchars($buf) . "
\n" ; + } + else if (!strcasecmp($msgformat, "text/x-citadel-variformat")) { + if (substr($previous_line, 0, 1) == " ") { + $txt .= "
\n" ; + } + $txt .= htmlspecialchars($buf); + } + else { + $txt .= htmlspecialchars($buf); + } + $previous_line = $buf; + } + } + + return($txt); +} + + ?> diff --git a/ctdlphp/readmsgs.php b/ctdlphp/readmsgs.php index 2c81dd41a..1ea74c5ed 100644 --- a/ctdlphp/readmsgs.php +++ b/ctdlphp/readmsgs.php @@ -9,7 +9,7 @@ echo "response: " . htmlspecialchars($response) . "
\n" ; if ($num_msgs > 0) foreach ($msgs as $msgnum) { - echo $msgnum . ", " ; + display_message($msgnum); } ?> -- 2.30.2