[REBOL] [ANN] Messages 0.9.4
From: ryan::christiansen::intellisol::com at: 20-Apr-2001 14:30
Following is Messages 0.9.4 which includes many improvements, etc., as
follows:
-Code reduction: replaced redundant code in several places with functions.
-Added support for forums. Messages can now be used to display/administer
news headlines or it can be used as an engine for a discussion forum.
Known issues:
-Bo's encrypt.r, which is used to create %logins.bin, runs into a memory
error when decrypting more than a half dozen login usernames/passwords.
You may view Messages "in action" at rebolrepublic.org.
View message system "news" style...
http://www.rebolrepublic.org/cgi-bin/messages.cgi?actionType=display&messageType=news&messageID=none
View message system "forum" style...
http://www.rebolrepublic.org/cgi-bin/messages.cgi?actionType=forum&messageType=news&messageID=none
NOTE: the stylesheet for messages is based on the messageType variable.
PLANS FOR FUTURE RELEASES: Support for classifieds (essentially a forum
system without comments); support for HTML tags in message content; replace
encrypt.r functions with RSA-encrypted login system based on Tom's rsa.r
As always, input is appreciated.
-Ryan
#!rebol -cs
REBOL [
Title: "Messages"
Date: 20-Apr-2001
Version: 0.9.4
File: %messages.cgi
Home: http://www.rebolrepublic.org
Author: "Ryan C. Christiansen"
Email: [norsepower--qwest--net]
Rights: "Copyright (C) Ryan C. Christiansen 1999-2001"
Purpose: {
Create, display, edit, and delete messages using a standard XML
storage format and CSS2-reference <DIV> tags for display. The script is
dependent on the use of .css stylesheets for separate messageTypes.
}
Comment: {
This file %messages.cgi is a single engine for creating,
displaying, editing, and deleting messages. For displaying, editing, and
deleting messages, %messages.cgi must receive the following variables as
CGI input: actionType, messageType, and messageID. For creating messages,
%messages.cgi must receive a REBOL e-mail object! as input or the following
variables as CGI input: actionType, messageType, subject, author, and
content. During message creation, %messages.cgi creates the following
variables: date and messageID.
}
History: [
0.0.9 [4-Jan-2001 "Created %std_msg_func_lib.r based on previous
work." "Ryan"]
0.1.1 [5-Jan-2001 "Added 'display-markup object! functions and
changed file name to %standard-message-function-library.r" "Ryan"]
0.1.2 [8-Jan-2001 "Fixed 'read-message-directory to output file
names including path to directory defined by messageType." "Ryan"]
0.2.1 [9-Jan-2001 "Corrected target 'word in 'write-xml-message.
Added 'create-message object! functions. Corrected 'display-markup to
output string! datatype instead of block! datatype. Negated use of
'message-request-data target variable in 'read-directory-messages. Added
'get-messages-for-display object! functions." "Ryan"]
0.2.3 [10-Jan-2001 "Added 'display-messages function, the
top-level function for displaying messages. Pared down usage in 'Example
portion of header to include only top-most functions. Removed /html-output
function from 'get-messages-for-display object! and removed /html function
from 'display-markup object!" "Ryan"]
0.2.4 [11-Jan-2001 "Changed the order of values (switched 'author'
and 'subject') for the XML grammar in all functions. Changed the 'either
switch in 'display-messages from 'none to the string! datatype 'none'."
Ryan
]
0.2.5 [8-Feb-2001 "Removed incorrect class/id combinations from CSS
font designations. Changed 'display-markup and 'display-messages to markup
content using only CSS class designations instead of class/id
combinations." "Ryan"]
0.2.7 [18-Feb-2001 "Added routine to 'display-messages function
which will display all messages in a directory minus the content value. The
index option is called by sending 'index' as the 'messageID value to
'display-messages." "Ryan"]
0.3.7 [28-Mar-2001 "Changed name of script to %messages.cgi.
Changed e-mail address in header. Updated Comment and Example field in
header. Changed 'display-markup to markup messages using <div> tags instead
of <font> tags. Changed 'display-markup from a function to an object which
includes 'for-reading object including 'with-reference (display messageID
and messageType) and 'without-reference functions, and also 'for-editing
object with 'with-reference function to display a message or messages for
editing, including <FORM> and <INPUT> tags. Added 'edit-message function
for editing messages. Added 'edited-from-cgi function to 'decode-to-object
object! Added 'delete-message function. Added 'message-action-cgi
uber-function." "Ryan"]
0.5.0 [29-Mar-2001 "Added return display for delete, create, and
edit switches in 'message-action-cgi. Changed 'append to 'insert in
'read-directory-messages function, which will make newest messages display
first. Changed radio button value for edit/delete choice from 'choice' to
'actionType'. Fixed the way 'for-editing object functions display form
values and form targets. Added form for creating new messages to
'for-editing object functions. Added 'create-form' action type to switch in
'message-action-cgi function. Added 'display-create-form function to
display message creation form. Added Bohdan Lechnowsky's %encrypt.r
functions. Created 'encrypt-logins function for creating %.bin files
containing usernames and passwords. Added 'display-login-form function to
display login form. Added 'sessionID check to all administration functions
including delete, edit, display-admin, create, and create-form. Added
'sessionID variables to form output in all admin forms. Added sort/reverse
statement in 'read-dir
ectory-messages function in an attempt to make the newest messages display
first. Added if error? try statement to program section script which will
default to displaying messages in the absence of cgi input data." "Ryan"]
0.5.1 [30-Mar-2001 "Changed sort/reverse statement in
'read-directory-messages function so that it sorts the 'message-directory
block instead of the 'message-block block." "Ryan"]
0.5.6 [4-Apr-2001 "Removed HTML headers from 'display-create-form
and 'display-login-form. Removed 'without-reference function in
'display-messages/for-reading object!, making 'display-messages/for-reading
a function replacing the 'with-reference function. Made
'display-messages/for-editing a function replacing the 'with-reference
function within the 'display-messages/for-editing object! All messages will
display references. Changed 'display-admin' switch to 'edit-form' in
'message-action-cgi function. Added parse statement to display 'messageID
and 'messageType in 'display-messages/for-editing function." "Ryan"]
0.6.0 [5-Apr-2001 "Added 'display-comments' switch to
'message-action-cgi, including 'reverse-input function which will make the
messageID the messageType for comment viewing and posting. Added post/view
comments link to 'display-messages/for-editing function. Added error
correction to stylesheet loading, making it load %comments.css on error
(expecting an error when the messageType is messageID after the
'reverse-input operation. Added 'display-comment-form function." "Ryan"]
0.6.6 [6-Apr-2001 "Added 'post-comment-input object to 'comment'
switch, including 'parent-messageID value in 'comment' switch and
'display-comment-form function, allowing a comment's parent to be displayed
after commenting, eliminating an error. Made 'display-messages/for-reading
function an object! containing functions 'for-commenting and
'no-commenting. Updated 'message-action-cgi switch statements for the
change. Added 'parent-message-input object and 'post-comment-reverse-input
object to 'comment' switch for displaying original message and proper
comment input form after comment creation. Added <DIV> tag to post/view
comments link. Added post/view comments links to
'display-messages/for-editing function. Added 'display-comments-edit'
switch to 'message-action-cgi function." "Ryan"]
0.7.4 [11-Apr-2001 "Added 'message-block return statement to
'read-directory-messages function and moved 'sort/reverse statement to sort
'message-block instead of 'message-directory. Added error-checking to
'display' switch in 'message-action-cgi. Added 'make decimal! statement to
'login' switch in 'message-action-cgi. Created 'check-sessionID function to
replace redundant code in 'message-action-cgi. Added 'sessionID-timeout
value in configuration section. Changed 'Edit' and 'Delete' and 'Create
New!' options in 'display-messages/for-editing function to be more
descriptive. Added 'search-messages function. Added 'search' switch to
'message-action-cgi. Added search form to all 'display-messages object!
output." "Ryan"]
0.7.5 [12-Apr-2001 "Moved 'message-block return statement in
'search-messages function. Removed 'search' switch debugging in
'message-action-cgi." "Ryan"]
0.8.1 [18-Apr-2001 "Changed 'insert to 'append in
'read-directory-messages function. Added 'display-search-form function to
replace redundant code in 'display-messages object! Added
'display-create-button function to replace redundant code in
'display-messages/for-editing function. Added 'display-edit-message-button
function to replace redundant code in 'display-messages/for-editing
function. Added 'display-delete-message-button function to replace
redundant code in 'display-messages/for-editing function. Added
'display-comments-link function to replace redundant code in
'display-messages object!" "Ryan"]
0.8.2 [19-Apr-2001 "Added 'display-comments-edit-link function to
replace redundant code in 'display-messages/for-editing function." "Ryan"]
0.9.4 [20-Apr-2001 "Added 'return-div-text function to replace
redundant code in 'display-messages object! Added 'return-messageID
function to replace redundant code in 'display-messages object! Added
'return-messageType function to replace redundant code in 'display-messages
object! Added 'display-messages/forum-style function for using
%messages.cgi to run a forum. Added 'display-create-button-forum function
for creating new messages in 'display-messages/forum-style function. Added
'create-form-forum' switch to 'message-action-cgi function. Added
'display-create-form-forum function for displaying a message creation form
in a forum environment. Added 'create-forum' switch to 'message-action-cgi
function for creating new messages in a forum environment. Added
'display-comments-forum-link function for using the commenting system
within a forum environment. Added 'display-comments-forum' switch to
'message-action-cgi function for using the commenting system within a forum
environment. Added 'display-com
ments-form-forum function for displaying a commenting system form within a
forum environment. Added 'comment-forum' switch to 'message-action-cgi for
creating comments within a forum environment. Added
'display-search-form-forum function to allow searches within a forum
environment. Added 'search-forum' switch to 'message-action-cgi function to
return forum-style message display after a search." "Ryan"]
]
Example: {
Decode CGI input and create, display, edit, or delete message(s).
This is the script's uber-function for CGI.
message-action-cgi
To decode CGI input from the web server:
cgi-input: retrieve-user-data
Using decoded CGI data, write XML standard message file to
directory determined by messageType.
create-message/from-cgi cgi-input
Using an e-mail message or newsgroup message in the form of a
REBOL e-mail object!, write XML standard message file to 'email' directory.
create-message/from-email email-message
Convert decoded CGI data into the standard message object!,
overwriting a previously created message.
edit-message cgi-input
Delete a previously created message.
delete-message cgi-input
Using decoded CGI data containing messageID and messageType
variables, either display a single message (messageID specified), a
directory of messages (messageID = "none"), or an index of messages
(messageID = "index") to the browser, including displaying the messageID
and messageType to the reader.
display-messages/for-reading/with-reference cgi-input
Using decoded CGI data containing messageID and messageType
variables, either display a single message (messageID specified), a
directory of messages (messageID = "none"), or an index of messages
(messageID = "index") to the browser, not displaying the messageID nor the
messageType to the reader.
display-messages/for-reading/without-reference cgi-input
Using decoded CGI data containing messageID and messageType
variables, either display a single message (messageID specified), a
directory of messages (messageID = "none"), or an index of messages
(messageID = "index") to the browser, including displaying the messageID
and messageType to the reader, in an HTML form for editing.
display-messages/for-editing/with-reference cgi-input
}
]
;########################################
;# CONFIGURATION #
;########################################
sessionID-timeout: make decimal! 1000
;########################################
;# FUNCTIONS #
;########################################
translate-message: make object! [
xml-tags: [
["subject" "/subject"]
["author" "/author"]
["date" "/date"]
["content" "/content"]
["messageID" "/messageID"]
["messageType" "/messageType"]
]
markup-data: func [
"Converts a standard message object! into a string containing the
XML-format standard message."
data [object!] "The standard message object!"
][
data-object: make data []
object-data: next first data-object
output: copy ""
for x 1 (length? xml-tags) 1 [
item: reform [rejoin ["data-object" "/" (first object-data)]]
made-tag: rejoin ["" (build-tag [(xml-tags/1/1)]) (do item)
(build-tag [(xml-tags/1/2)])]
xml-tags: next xml-tags
object-data: next object-data
append output made-tag
]
xml-tags: head xml-tags
output
]
read-markup: func [
"Converts a file containing the XML-format standard message into a
standard message object!"
xml-file [file!] "File containing the XML-format standard message."
][
message-data: load/markup xml-file
xml-data: make object! [
subject: message-data/<subject>
author: message-data/<author>
date: message-data/<date>
content: message-data/<content>
messageID: message-data/<messageID>
messageType: message-data/<messageType>
]
xml-data
]
]
decode-to-object: make object! [
from-cgi: func [
"Converts decoded CGI data into the standard message object!"
cgi-data [object!] "Decoded CGI data."
][
make object! [
subject: cgi-data/subject
author: cgi-data/author
date: now
content: cgi-data/content
messageID: time-in-digits now
messageType: cgi-data/messageType
]
]
edited-from-cgi: func [
"Converts decoded CGI data into the standard message object!"
cgi-data [object!] "Decoded CGI data."
][
make object! [
subject: cgi-data/subject
author: cgi-data/author
date: cgi-data/date
content: cgi-data/content
messageID: cgi-data/messageID
messageType: cgi-data/messageType
]
]
from-email: func [
"Converts the standard REBOL e-mail object! into the standard
message object!"
email-data [object!] "Standard REBOL e-mail object!"
][
make object! [
subject: email-data/subject
author: email-data/from
date: email-data/date
content: email-data/content
messageID: time-in-digits now