1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: web-utils-aserve.lisp
6 ;;;; Purpose: Web utilities based on aserve functions
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Apr 2000
10 ;;;; $Id: web-utils-aserve.lisp,v 1.4 2002/10/10 16:23:48 kevin Exp $
12 ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg
14 ;;;; KMRCL users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
21 (declaim (optimize (speed 3) (safety 1) (compilation-speed 0) (debug 3)))
24 ;;; AllegroServe interaction functions
26 (defun cgi-var (var req)
27 "Look CGI variable in AllegroServe association list"
28 (cdr (assoc var (net.aserve:request-query req) :test #'equal)))
31 (princ s *html-stream*))
34 (format *html-stream* "~a~%" s))
39 (defmacro with-tag (tag &rest body)
40 "Outputs to http tag and executes body"
43 (princ-http (format nil "<~a>" ,tag))
45 (princ-http (format nil "</~a>" ,tag))))
47 (defmacro with-tag-attribute (tag attribute &rest body)
48 "Outputs to http tag + attribute and executes body"
51 (princ-http (format nil "<~a ~a>" ,tag ,attribute))
53 (princ-http (format nil "</~a>" ,tag))))
55 (defun princ-http-with-color (text color)
56 (with-tag-attribute "font" (format nil "color=\"~a\"" color)
59 (defun princ-http-with-size (text size)
60 (with-tag-attribute "font" (format nil "size=\"~a\"" size)
63 (defmacro with-link ((href xml linktype) &rest body)
64 (declare (ignore linktype))
65 ; (format *html-stream* "Return to <cui2 xml:href=\"qstr\">Home</cui2>")
66 ; (format *html-stream* "Return to <go xml:link=\"simple\" show=\"replace\" href=\"qstr/\">Home</go>")
69 (princ-http "<elem xlink:type=\"simple\" xlink:href=\"")
73 (princ-http "</elem>"))
75 (princ-http "<a href=\"")
79 (princ-http "</a>"))))
81 (defun home-link (&key (xml nil) (vars nil))
82 (princ-http "<font size=\"-1\">Return to ")
83 (with-link ((make-url "index.html" :vars vars) xml "homelink")
84 (princ-http "Browser Home"))
85 (princ-http "</font><p></p>"))
87 (defun head (title-str)
88 (net.html.generator:html
90 "<LINK rel=\"stylesheet\" href=\"http://www.med-info.com/main.css\" type=\"text/css\">"
91 (:title (:princ-safe title-str)))))
97 (defmacro with-xml-page (title &rest body)
100 (net.html.generator:html
101 (princ-http (std-xml-header))
102 (princ-http "<pagedata xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:html=\"http://www.w3.org/TR/REC-html40\">"))
103 (with-tag "pagetitle" (princ-http ,title))
105 (princ-http "</pagedata>")))
107 (defmacro with-trans-page (title &rest body)
110 (print-http "<?xml version=\"1.0\" standalone=\"yes\"?>")
111 (print-http "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"")
112 (print-http " \"http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
114 (print-http "<html xmlns=\"http://www.w3.org/1999/xhtml\">")
116 (print-http "<body bgcolor=\"#FFFFFF\">")
119 (print-http "</body>")))
120 (print-http "</html>")))
125 (defun encode-query (query)
126 "Escape [] from net.aserve's query-to-form-urlencoded"
127 (substitute-string-for-char
128 (substitute-string-for-char
129 (substitute-string-for-char
130 (substitute #\+ #\space query)