home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 April / APC443.iso / features / grpware / coldfus / coldfusi.exe / data1.cab / Examples / publish / admin / createpage.cfm < prev    next >
Encoding:
Text File  |  1998-10-08  |  4.9 KB  |  143 lines

  1. <!--- This publishing systems' "templates" (not Cold Fusion templates)
  2.     are just like regular Cold Fusion templates except that they have
  3.     a block of "metadata" (for lack of a better word) in the first few
  4.     lines of the file. The template files are all named <Template name>.template
  5.     so that the file default.template would be a template named "default".
  6.     
  7.     An example of a template is this:
  8.     
  9.     ---BEGIN PUBLISHING DATA---
  10.     LOCATIONS=1
  11.     DESCRIPTION=This is a completely bare template which should be modified before use.
  12.     ---END PUBLISHING DATA---
  13.     
  14.     <CFINCLUDE TEMPLATE="_header.cfm">
  15.     
  16.     <CF_ShowContent>
  17.     
  18.     <CFINCLUDE TEMPLATE="_footer.cfm">
  19. --->
  20.  
  21. <!--- These are just aliases; ValidAttributes lists the
  22.     template attributes that are allowed --->
  23. <CFSET ValidAttributes = "Name,Locations,Description">
  24. <CFSET NewLine = Chr(10)>
  25.  
  26. <!--- Get the template files' info and put it in the query Templates --->
  27. <CFDIRECTORY ACTION="LIST"
  28.              DIRECTORY="#ExpandPath('templates')#"
  29.              NAME="Templates"
  30.              FILTER="*.template"
  31.              SORT="DateLastModified">
  32.  
  33. <!--- Initialize the query TemplateInfo... this will hold the
  34.     final data; each template will have a record, each column
  35.     will be an attribute --->
  36. <CFSET TemplateInfo = QueryNew(ValidAttributes)>
  37.  
  38. <!--- Now go into each file and retrieve the attributes --->
  39. <CFLOOP QUERY="Templates">
  40.  
  41.     <CFFILE ACTION="READ" FILE="#ExpandPath('templates\' & Name)#" VARIABLE="FileData">
  42.  
  43.     <!--- Adding a row to the TemplateInfo query, and putting in the name --->
  44.     <CFSET Temp = QueryAddRow(TemplateInfo)>
  45.     <CFSET Temp = QuerySetCell(TemplateInfo, "Name", Left(Name, Len(Name) - Len(".template")))>
  46.  
  47.     <!--- Grab the whole chunk of attribute-value pairs, call it MetaData --->
  48.     <CFSET MetaDataStart = FindNoCase("---BEGIN PUBLISHING DATA---", FileData) + Len("---BEGIN PUBLISHING DATA---")>
  49.     <CFSET MetaDataEnd = FindNoCase("---END PUBLISHING DATA---", FileData)>
  50.     <CFSET MetaData = Trim(Mid(FileData, MetaDataStart, MetaDataEnd - MetaDataStart))>
  51.  
  52.     <!--- Now loop over each line of MetaData --->
  53.     <CFLOOP CONDITION="Trim(MetaData) NEQ ''">
  54.  
  55.         <!--- Grab just one line of info from MetaData.  If this
  56.             happens to be the last line in MetaData, just grab
  57.             all that's left. --->
  58.         <CFSET EOL = Find(Newline, MetaData)>
  59.         <CFIF EOL NEQ 0>
  60.             <CFSET CurrentLine = Trim(Left(MetaData, EOL))>
  61.         <CFELSE>
  62.             <CFSET CurrentLine = Trim(MetaData)>
  63.         </CFIF>
  64.         
  65.         <!--- If there's a "=" character in the current line, continue processing --->
  66.         <CFIF Find("=", CurrentLine) NEQ 0 AND Left(CurrentLine, 1) NEQ ":">
  67.  
  68.             <!--- Split the current line at the "="; everything to the left
  69.                 is the attribute name, everything to the right is the value --->
  70.             <CFSET MidPoint = Find("=", CurrentLine)>
  71.             <CFSET Attribute = Left(CurrentLine, MidPoint - 1)>
  72.             <CFSET Value = Right(CurrentLine, Len(CurrentLine) - MidPoint)>
  73.             
  74.             <!--- If the parameter is valid, save the value in the TemplateInfo query --->
  75.             <CFIF ListFindNoCase(ValidAttributes, Attribute) NEQ 0>
  76.                 <CFSET Temp = QuerySetCell(TemplateInfo, Attribute, Value)>
  77.             </CFIF>
  78.  
  79.         </CFIF>
  80.  
  81.         <CFIF Len(Trim(MetaData)) NEQ Len(CurrentLine)>
  82.             <CFSET MetaData = Trim(Right(MetaData, Len(MetaData) - Len(CurrentLine)))>
  83.         <CFELSE>
  84.             <CFSET MetaData = "">
  85.         </CFIF>
  86.  
  87.     </CFLOOP>
  88.  
  89. </CFLOOP>
  90.  
  91. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
  92.  
  93. <HTML>
  94. <HEAD>
  95.     <TITLE>Create Page</TITLE>
  96. <STYLE TYPE="text/css">
  97. <!-- A {text-decoration: none} -->
  98. </STYLE>
  99. </HEAD>
  100.  
  101. <BODY BGCOLOR="#660000" TEXT="#FFFFFF" LINK="#FFFF00" VLINK="#FFFF00">
  102.  
  103. <TABLE ALIGN="RIGHT" CELLPADDING="0" CELLSPACING="0">
  104. <TR>
  105.     <TD ALIGN="RIGHT">
  106.     <FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">
  107.         <A HREF="index.cfm">Administrator Home</A>
  108.     </FONT>
  109.     </TD>
  110. </TR>
  111. </TABLE>
  112.  
  113. <P><IMG SRC="images/createpage.gif" WIDTH=96 HEIGHT=23 BORDER=0 ALT="Create Page"></P>
  114.  
  115. <FORM ACTION="createpage2.cfm" METHOD="POST">
  116.  
  117. <TABLE BORDER="1" CELLPADDING="5" CELLSPACING="2">
  118. <TR>
  119.     <TD></TD>
  120.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><B>Name</B></FONT></TD>
  121.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><B>Locations</B></FONT></TD>
  122.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><B>Description</B></FONT></TD>
  123.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><B>Sample Image</B></FONT></TD>
  124. </TR>
  125. <CFOUTPUT QUERY="TemplateInfo">
  126. <TR>
  127.     <TD><INPUT TYPE="RADIO" NAME="Template" VALUE="#Name#"></TD>
  128.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">#Name#</FONT></TD>
  129.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">#Locations#</FONT></TD>
  130.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">#Description#</FONT></TD>
  131.     <CFIF FileExists(ExpandPath("templates/" & Name & ".gif"))>
  132.         <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><A HREF="templates/#name#.gif" TARGET="_blank">Sample Image</A></FONT></TD>
  133.     </CFIF>
  134. </TR>
  135. </CFOUTPUT>
  136. </TABLE>
  137.  
  138. <P><INPUT TYPE="SUBMIT" VALUE="Continue"></P>
  139.  
  140. </FORM>
  141.  
  142. </BODY>
  143. </HTML>