Extending your HTML on a Macintosh using macro languages

Abstract

This article describes and illustrates the use of three Macintosh tools that can be used to extend HTML for the purposes of creating dynamic and client-specific HTML documents. These three tools are a server application (Intercon's InterServer Publisher) and two common gateway interface scripts (Tim Endres's HTPL and Maxum Development's NetCloak).

Introduction

HTML was originally designed as a subset of SGML (Standard Generalized Markup Language). As such, HTML's primary purpose is to logically describe the content of documents. As Web browsers have matured, and as the use of the Internet for commercial marketing purposes has increased, more and more effort has been put into HTML's ability to stylize documents. This has caused many idiosyncrasies and discrepancies in the way various WWW browsers interpret HTML. For example, we have all experienced the disappointment of creating a truly beautiful document for one browser but have it appear absolutely ugly on another. Another problem with HTML documents is their rather dynamic nature---unlike SGML documents, HTML documents are much more likely to change over time as they get updated and maintained.

To overcome some of these problems, and if your server platform is a Macintosh, you can incorporate three various systems of extensions (meta- or macro-languages) into your HTML. These macro-languages provide the means for dynamically inserting and modifing dates, times, file information, graphics, random numbers, and other document elements. One of these macro languages even allows you to call the operating system through AppleScripts.

The best feature of all these macro-languages is they are all interpreted on the server side of the client/server equation. In other words, all of these macro-languages are evaluated by a server application or through CGI scripts. Consequently, the use of these macro-languages work independently of any WWW browser application.

These three macro-language system extensions take the form of one server application and two CGI scripts. The server application is Intercon's InterServer Publisher. One of the CGI scripts is called NetCloak. The other is called HTPL. The balance of this article describes the pros and cons of each implementation.

InterServer Publisher

InterCon's InterServer Publisher is the only applications described here in the form of a server application. This means all of the extensions to your HTML are handled by the server and not a CGI or ACTION interpreter. All of InterServer's extension to HTML are directly related to the files your server is serving; InterServer does not support WWW client sort of if-then statements the way NetCloak and HTPL do. Intercon calls its implementation InterXTML.

One of the easiest InterXTML commands to understand is <IX-FILE-NAME>. By adding this "extended" HTML command to your documents InterServer will output the file name of the current document. There are numerous other commands supported by InterServer relating to file information. These commands provide information on such things as size, version, comment (from the Get Info box), and kind.

Another simple command is the random command allowing a document to be chosen at random from a specififed folder. For example, the following HTML code will display the name of a random GIF file from the current folder:


    Random file: <IX-RANDOM-URL PATH="*.gif">
 
		

This command can then be inserted ("nested") in other commands or HTML. Consequently, the following HTML will display a random GIF file from the current folder:


    Random GIF: <img src="<IX-RANDOM-URL PATH="*.gif">">
 
		

Some commands can take numerous arguments. The IX-FILE-DATE command is a good example. This command displays a date and its various arguments include modification or creation date as well as various formats for the date like long, short, whether the time is displayed and if so in what format. It can become quite precise. For example, this command can be used in the footer of pages to list the last time your HTML was updated:


    This file was last updated on <IX-FILE-DATE TYPE=MODIFICATION FORMAT=ABBREV>
 
		

Incorporating hit counters is also easy with InterServer. To add a counter to your pages all you have to do is insert the counter command as in:


    This page was accessed <IX-FILE-COUNTER> times.
 
		

You can modify the counter and update the counter as well by giving the counter command one of a few arguments specifiying start date or reset. InterServer's real strength is dynamically listing the contents of folders. These features are especially useful when you have one or more folders with constantly changing contents and you do not what to be forever writing HTML code to reflect the changes. To implement this feature you create a file named "index" in the directory to be dynamically listed. This file is divided into three sections: prologue, body, epilogue. The prologue is the place where things like the name and/or URL of the directory is inserted with InterXTML commands. The body is where the actual listing takes place. The epilogue is where you might insert an InterXTML command listing the modification date of the directory. Below is an examle of one of these index files and it creates a list of downloadable files from a directory:


    <IX-FILELISTING-PROLOGUE>
    <HTML>
    <TITLE><IX-DIRECTORY-NAME></TITLE>
    <H1><IX-DIRECTORY-NAME></H1>
    This is simple index file containing InterXTML commands<p>
    <UL>
    </IX-FILELISTING-PROLOGUE>

    <IX-FILELISTING-BODY>
    <LI><A HREF="<IX-FILE-URL>"><IX-FILE-NAME></A>
    </IX-FILELISTING-BODY>

    <IX-FILELISTING-EPILOGUE>
    </UL>
    Folder last modified on <IX-DIRECTORY-DATE TYPE=MODIFICATION FORMAT=LONG><P>
    </HTML>
    </IX-FILELISTING-EPILOGUE>
 
		

What is really nice about this feature is the ways you can extend the directory listing; each of the files listed using these commands can be enhanced with information about the files. For example, by using the <IX-FILE-ICON TYPE=FILE SIZE=32> command you can insert each file's large icon into the listing. Similarly, by using <IX-FILEINFO-COMMENT> you can insert into the listing any comments found from the each file's Get Info box. In many ways these sorts of features can turn a rudimentary FTP server into a more robust, and information-rich FTP server using the HTTP protocol.

NetCloak

NetCloak is the oldest of the system extensions described here. It dates "way back" to the early days of MacHTTP. It also comes in two flavors: NetCloak Personal and NetCloak. NetCloak Personal is essentially NetCloak version 1.0 and sold as shareware. NetCloak version 2.0 is designed to work with WebSTAR. Specifically, NetCloak can be configured as a WebSTAR ACTION. NetCloak is sold as a commercial product.

Since NetCloak is essentially a CGI script, and since it can be configured to run as a WebSTAR ACTION, then there is no need to call NetCloak with command arguments like the other CGI implementation (HTPL). In other words, links to HTML documents containing NetCloak commands look like any other links to HTML documents. Alternatively, you can name the documents containing NetCloak extensions with the suffix "nclk," as in "default.nclk." In either case, this makes for much cleaner HTML markup when compared to HTPL.

All NetCloak commands, like InterServer Publisher commands, look like extended HTML codes; all NetCloak commands are case-insensitive and surrounded by the less than (<) and greater than (>) symbols.

There are basically twelve NetCloak commands. These commands evaluate things such as client domain and type, dates and times, user names and passwords, access counts, and random numbers. Each of these sets of commands generally have three variations: hide, show, and insert.

By inserting the hide and show commands in your HTML, you can turn off and on various parts of your HTML:


    Hello, World!<p>
    <hide>
    Nobody will see this text.
    <show>
    It is nice to meet you.
 
		

Using the show_domain command, you can easily show some of your HTML document to particular end-users with ranges of IP addresses. The following databases and services are available:


    <ul>
    <show_domain 152.1>
    <li>Computer Index
    <li>MEDLINE
    <show>
    <li>Electronic Card Catalog
    <li>Government Documents
    </ul>
 
		

Like most of the NetCloak commands, you can use the insert_domain command in your HTML to echo the IP address of the end-user's host as in:


    Your IP address is <insert_domain>.
 
		

A unique feature of NetCloak is its referer command. This command lets you modify your HTML based on the URL pointing to your document. For example, suppose an entry in Yahoo contains a pointer to your pages. You can insert into our HTML the following code and allow Yahoo users to see parts of it:


    <show_referer yahoo>
    Ha! I know you just visited Yahoo.
    <show>
    Welcome to my pages.
 
		

A thing to keep in mind when implementing NetCloak commands is the way it analyzes its arguments. In the example above, if the string "yahoo" is contained in the referring URL, then the command will prove successful. At the same time, this command will still be successful even if the filename from the referring URL contains "yahoo." In other words, you must specify enough of an argument to specify uniqueness, but you do not have to be exhaustive in your specification.

The referrer command proves even more useful when you incorporate its insert variation into a hypertext link and provide the means for an end-user to easily return to the page whence they came:


    <a href="<insert_referer>">Return</a> to the page pointing to this document.
 
		

NetCloak makes it a trivial task to insert counters into your HTML documents. All you have to do is insert code like:


    You are visitor number <insert_count visitor>.
 
		

NetCloak will then keep track of a variable named visitor and increment it each time a page is accessed. Other variations of the counter command allow you to show HTML when the counter's value is greater than or less than a range of values. Thus, you can only show a segment of HTML when the counter's value is greater than 100 or less than 50. Hiding or showing HTML based on the date is easily implemented with NetCloak. If the current date or time falls within a particular range, then you can either hide or show your HTML. Like other commands, you can simply display the date and time as is:


    The date and time is <insert_date>, <insert_time>.
 
		

Other variations include the ability to count down from a particular date or time and the show or hide some HTML accordingly.

Random numbers seem to be a big part of NetCloak's philosophy. NetCloak provides facilities for simply displaying random numbers, showing and hiding HTML based on random numbers, and showing and hiding HTML based on percentages. Using these features you can certainly create dynamic pages!

Like HTPL, you can create variables that are then displayed in your HTML. Unfortunately, the only way to create these variables is through an HTML+ form. By creating a form, like any other form, and specifying the action of the form as a NetCloak document, NetCloak will interpret the contents of the form and create variables. For example, the following HTML+ form will create a variable called favoriteSeason:


    <form method=post action="formTest.html">
    What is your favorite season?<br>
    <select name="favoriteSeason">
    <option>Winter
    <option selected>Spring
    <option>Summer
    <option>Autum
    </option><p>
    <input type=submit value="OK">
    </form> 
 
		

You could then use the variable in some of your HTML:


    You said your favorite season is <insert_variable favoriteSeason>.
 
		

Finally, NetCloak provides a feature it calls macros. Macros are strings of text defined in one location and then made available throughout your NetCloaked documents. To use a macro you edit the macros file (NetCloak.macros) by surrounding your text in the macros command. For example, the following macro may be used as the footer of a document:


    <begin_macro footer>
    <HR>
    This document was created by me, Eric Morgan.
    <end_macro>
 
		

You can then use this macro in your HTML by including the following sort of command in your HTML:


    <html>
    <head><title>Hello, World!</title></head>
    <body>
    <h1>Hello, World!</h1>
    <macro footer>
    </body>
    </html>
 
		

Consequently, NetCloak will insert the contents of footer into the HTML.

HTPL

HTPL, an acronym for "HyperText Pre-processing Language," is the most full featured, least expensive, and only cross-platform system described here. At the same time, this system may be the most difficult to incorporate into your HTML since it resembles a miniature programing language. It is complete with if-then statements, foreach loops, variable definitions, include files, and operating system calls.

HTPL was written to eliminate its author's need to maintain multiple HTML pages appropriately suited for multiple WWW browsers. Accept for a few minor points, HTPL accomplishes that goal.

HTPL is a CGI script. The script itself requires a configuration file. The most important purpose of the configuration file is to define aliases for folder names because each call to HTPL must be accompanied by two arguments: the folder of the document to be served and the file name to be served. Consequently, in order for HTPL to interpret your extended HTML, you must create links look much like the following:


    /htpl.acgi?htpl+default.html
 
		

These links look much like old-style NetCloak links before the implementation of WebSTAR ACTIONS. This also means it is very difficult to use an HTPL page as your server's default page.

HTPL comes with more than 27 individual commands including if-then statements, file I/O, foreach and for loops, and a C-like sprint statment. Additionally, it automatically creates almost 40 special variables and allows you to program your HTML based on these variables' values. The special variables get some of their definitions from client applications (user agent, query string, remote IP address, user name, user password, etc.). Other variables get defined by the server (file name, HTML level, server software, etc.). Still others are defined by HTPL itself (number of arguments in a query, date, time, HTML script name, etc.)

If you aren't satisfied with what is available by default, then you can define your own variables. For example, to define a variable called emailAddress, you may incorporate the following HTPL into your HTML:


    #define emailAddress = eric_morgan@ncsu.edu
 
		

Note that all HTPL commands are proceeded by a hash mark (#).

To use this definition you simply preceed the defined variable with dollar ($) sign as in:


    My email address is $emailAddress.
 
		

You can extend this concept my incorporating the variable into links:


    <a href="mailto:$emailAddress">Email me</a>.
 
		

In both of these cases, if the text after the dollar sign has not been defined, then HTPL does not interpret the variable and outputs the dollar sign as well as the text.

Using the AGENT special variable and HTPL's if-then agent syntax, you can serve HTML depending on the end-user's WWW browser. The following example outputs one set of text for end-users using the LYNX browser and another set for everybody else:


    #ifagent lynx
    Welcome Lynx user!
    #else
    Welcome graphical browser user!
    #endif
 
		

There are similar specialized if-then constructs for logical expressions and variable definitions.

Another unique feature of HTPL is its file I/O capabilities. Using the logmsg command you can append or overwrite to a text file. For example, the following code defines a file name (logfile) and the contents of a variable (message) with the date and host IP address of the client application. It then opens logfile and appends message:


    #define logfile = "Hard disk:www:htpl:test:logfile.txt"
    #define message = $DATE_AND_TIME $REMOTE_HOST
    #logmsg $logfile a $message
 
		

The same file can then be read using the catfile command, as in:


    #catfile $logfile
 
		

By adding two hidden field in an HTML+ form, HTPL can parse the contents of that form. For example, the following HTPL code allows the end-user to insert any text into a field, submit the form, and have the contents of the text field appear as a new header in the HTML:


    #ifndef dynamicHeader
    #define theHeader = Forms
    #else
    #define theHeader = $dynamicHeader
    #endif

    <h2>$theHeader</h2>
    <FORM ACTION="/htpl.acgi?htpl+default.html"
    <METHOD=POST>
    <INPUT TYPE="text" NAME="dynamicHeader" VALUE="This is a dynamic header" SIZE=40 MAX=40>
    <INPUT TYPE="hidden" NAME="HTPLDIR" VALUE="test">
    <INPUT TYPE="hidden" NAME="HTPLFILE" VALUE="default.html">
    <INPUT TYPE="submit" VALUE="Relaod page">
    </FORM>
 
		

To supplement the value of HTPL, you can indirectly call the operating system through AppleScripts. This is done by enclosing a valid AppleScript command in back ticks (`). For example, the following command runs an AppleScript script named randomNumber:


    #define randomNumber = `run script alias "Hard disk:www:applescripts:randomNumber"`
 
		

The AppleScript itself is only three lines long:


    set randomNumber to random number from 0 to 100
    set output to "The random number is " & randomNumber & "."
    return output
 
		

Consequently, each time a page is loaded containing this HTPL code, HTPL:

  1. Calls the randomNumber script
  2. Generates a random number
  3. Inserts the number into a string
  4. Returns the string
  5. Assigns the string to a variable
  6. Allows you to incorporate the variable into your HTML

The features described here are some of HTPL's more robust constructs. While HTPL may be more difficult to implement, it can perform all the functions of the NetCloak and InterServer Publisher. Furthermore, HTPL works under the Unix operating system as well and has been specially designed to work with the Apache server. If HTPL was able to be called as a WebSTAR ACTION and eliminating the convoluted linking proceedure, then it might be a more perfect solution to dynamic HTML documents on the Macintosh.


Creator: Eric Lease Morgan <eric_morgan@infomotions.com>
Source: This article was originally published in the now defunct Websmith magazine sometime around March, 1996.
Date created: 1996-03-03
Date updated: 2005-05-08
Subject(s): articles; HTML (Hypertext Markup Language);
URL: http://infomotions.com/musings/extending-html/