home *** CD-ROM | disk | FTP | other *** search
/ Amiga Times / AmigaTimes.iso / programme / Fiasco_2.2 / Databases / Mailing List Archive / createhtml.frx < prev    next >
Encoding:
Text File  |  1998-10-06  |  13.9 KB  |  612 lines

  1. /* createhtml.frx
  2.  * Copyright © 1998 Nils Bandener
  3.  * $VER: createhtml_frx 8.9 (31.7.98)
  4.  */
  5.  
  6. /* Please specify here a name for the ARexx script:
  7.  */
  8.  
  9. scriptname = "Create HTML"
  10.  
  11. /*
  12.  * Script settings
  13.  *
  14.  * Edit the following lines to change the output
  15.  *
  16.  */
  17.  
  18. linesperpage = 30                /* Lines that should be written per page */
  19. starttemplatefile = "tpl1.html"  /* HTML file that is used as format template */
  20. endtemplatefile = "tpl2.html"    /* HTML file that is used as format template */
  21.  
  22. markercolor = "#000099"          /* Color for the markers in front of the lines */
  23. bgcolor     = "#cccccc"          /* Background color */
  24. titlebgcolor = "#aaaaaa"         /* Background color of table title */
  25. titletxcolor = "#000000"         /* Text color of table title */
  26.  
  27. mlname = "Fiasco MLArchive Example"  /* Name of mailing list */
  28.  
  29.  
  30. Options Results
  31. Parse Arg dir
  32.  
  33. /*
  34.  *  If not called from Fiasco, try to address the active
  35.  *  Fiasco project
  36.  */
  37.  
  38. if ~abbrev(address(), "FIASCO.") then
  39. do
  40.     /* Get list of all available ports */
  41.  
  42.     ports = show("Ports")
  43.  
  44.     /* Search for a port of Fiasco */
  45.  
  46.     do i = 1 to words(ports)
  47.  
  48.         if abbrev(word(ports, i), "FIASCO.") then
  49.         do
  50.             /* A port of Fiasco has been found.
  51.              * Now query Fiasco to return the port
  52.              * name of the active database.
  53.              */
  54.  
  55.             Address Value word(ports, i)
  56.  
  57.             GetAttr Project Name Active ARexx
  58.  
  59.             Address Value Result
  60.  
  61.             break
  62.         end
  63.     end
  64. end
  65.  
  66. fiasco_port = address()
  67.  
  68. Signal on Syntax
  69. Signal on Halt
  70. Signal on Break_C
  71. Signal on Failure
  72.  
  73. LockGUI
  74.  
  75. /*
  76.  *  Request the directory in which
  77.  *  the output is written.
  78.  *  It is recommended to reserve a whole
  79.  *  directory for the output.
  80.  *  The first page can be referred then
  81.  *  by <directory>/index.html
  82.  */
  83.  
  84. RequestFile 'drawersonly projectrelative savemode var dir'
  85.  
  86. if rc = 0 then
  87. do
  88.     if length(dir) ~= 0 & right(dir, 1) ~= ':' & right(dir, 1) ~= '/' then
  89.     do
  90.         dir = dir || "/"
  91.     end
  92.  
  93.     /*
  94.      *  Sort the database by date and time
  95.      */
  96.  
  97.     sort 'date time index "mlahtml.fidx"'
  98.  
  99.     if rc = 0 then
  100.     do
  101.         countrecords 'var numrecs'
  102.  
  103.         /*
  104.          *  Calculator the number of pages
  105.          */
  106.  
  107.         numpages = trunc((numrecs / linesperpage) - 0.1) + 1
  108.  
  109.         rootcnt = 0
  110.  
  111.         /*
  112.          *  Search for "root" messages
  113.          *  which are not refered by other
  114.          *  messages
  115.          */
  116.  
  117.         do i = 1 to numrecs
  118.  
  119.             newsearchinfo 'name createhtmlsi'
  120.  
  121.             getfield 'reference record ' || i || ' var mid'
  122.  
  123.             setsearchfield 'searchinfo createhtmlsi fieldid messageid pattern ' || mid
  124.  
  125.             find 'searchinfo createhtmlsi record 0'
  126.  
  127.  
  128.             if rc ~= 0 then
  129.             do
  130.                 rootcnt = rootcnt + 1       /* Number of roots */
  131.                 root.rootcnt = i            /* Stem var with roots */
  132.             end
  133.  
  134.         end
  135.  
  136.  
  137.         linecount = 0
  138.         activepage = 0
  139.         depth = 0
  140.  
  141.         /*
  142.          *  Create the first index file
  143.          */
  144.  
  145.         call newlistfile
  146.  
  147.         /*
  148.          *  Now create output for each root
  149.          *  message. All other messages are
  150.          *  handled by printmail()
  151.          */
  152.  
  153.         do i = 1 to rootcnt
  154.  
  155.             depth = 0       /* for recursion with ARexx */
  156.  
  157.             call printmail(root.i)
  158.  
  159.         end
  160.  
  161.         call closelistfile
  162.  
  163.         options failat 20
  164.  
  165.         /*
  166.          *  Activate previous active index
  167.          */
  168.  
  169.         activeindex prev
  170.     end
  171. end
  172.  
  173.  
  174. /*----------------------------------------------------*
  175.  *                                                    *
  176.  *  Clean up functions                                *
  177.  *                                                    *
  178.  *----------------------------------------------------*/
  179.  
  180.  
  181. bail_out:
  182.  
  183. Address Value fiasco_port
  184.  
  185. UnlockGUI
  186. ResetStatus
  187.  
  188. exit
  189.  
  190. syntax:
  191. failure:
  192.  
  193. if show("Ports", fiasco_port) then
  194. do
  195.     Address Value fiasco_port
  196.  
  197.     RequestChoice '"Error ' || rc || ' in line ' || sigl || ':*n' || errortext(rc) || '" "Cancel" Title "' || scriptname || '"'
  198. end
  199. else
  200. do
  201.     say "Error" rc "in line" sigl ":" errortext(rc)
  202.     say "Enter to continue"
  203.     pull dummy
  204. end
  205.  
  206. call bail_out
  207.  
  208. halt:
  209. break_c:
  210.  
  211. if show("Ports", fiasco_port) then
  212. do
  213.     Address Value fiasco_port
  214.  
  215.     RequestChoice '"Script Abort Requested" "Abort Script" Title "' || scriptname || '"'
  216. end
  217. else
  218. do
  219.     say "*** Break"
  220.     say "Enter to continue"
  221.     pull dummy
  222. end
  223.  
  224. call bail_out
  225.  
  226.  
  227. /*----------------------------------------------------*
  228.  *                                                    *
  229.  *  Create output for one mail                        *
  230.  *                                                    *
  231.  *----------------------------------------------------*/
  232.  
  233. /*
  234.  *  This function uses some tricks to do
  235.  *  recursion with ARexx.  Stem variables are used
  236.  *  as the "stack". depth, as index for these variables,
  237.  *  is the "stack pointer".
  238.  */
  239.  
  240. printmail:
  241.  
  242. parse arg num
  243.  
  244. depth = depth + 1       /* Get a new stack */
  245.  
  246. linecount = linecount + 1
  247.  
  248. /*
  249.  *  If number of lines exceeds the maximum
  250.  *  for an index page, start a new page
  251.  */
  252.  
  253. if linecount > linesperpage then
  254. do
  255.     linecount = 0
  256.  
  257.     call newlistfile
  258. end
  259.  
  260. /*
  261.  *  Read the data
  262.  */
  263.  
  264. getfield 'subject record ' || num || ' var subject'
  265. getfield 'date record ' || num || ' extformat var dateval'
  266. getfield 'realname record ' || num || ' var realname'
  267. getfield 'messagekey record ' || num || ' var messagekey'
  268. getfield 'mailbody record ' || num || ' var mailbody'
  269. getfield 'email record ' || num || ' var emailval'
  270.  
  271. /*
  272.  *  Write the mail file
  273.  */
  274.  
  275. call writemailfile
  276.  
  277. /*
  278.  *  Add a new line to the index page
  279.  */
  280.  
  281. call writeln(f, "<tr>")
  282.  
  283. leftspan = depth - 1
  284.  
  285. if leftspan > 6 then leftspan = 6
  286.  
  287. if leftspan ~= 0 then
  288. do
  289.     call writeln(f, '<td colspan=' || leftspan || '></td>')
  290. end
  291.  
  292. call writeln(f, '<td bgcolor="' || markercolor || '" width=10> </td>');
  293.  
  294. rightspan = 7 - leftspan
  295.  
  296. call writeln(f, '<td colspan=' || rightspan || '>' || '<a href="' || messagekey || '.html">' || subject || '</a></td>')
  297.  
  298. call writeln(f, '<td align=right>' || sizeval || '</td>')
  299.  
  300. call writeln(f, '<td align=right>' || dateval || '</td>')
  301.  
  302. call writeln(f, '<td>' || realname || '</td>')
  303.  
  304. call writeln(f, '</tr>')
  305.  
  306. /*
  307.  *  Search for referring mails
  308.  */
  309.  
  310. getfield 'messageid record ' || num || ' var mid.' || depth
  311.  
  312. if mid.depth ~= "" then
  313. do
  314.     siname = 'createhtmlsi.' || depth
  315.  
  316.     newsearchinfo 'name ' || siname
  317.  
  318.     setsearchfield 'searchinfo ' || siname || ' fieldid reference pattern ' || mid.depth
  319.  
  320.     find 'searchinfo ' || siname || ' stem st.' || depth
  321.  
  322.     if rc = 0 & st.depth.count ~= 0 then
  323.     do
  324.  
  325.         do j.depth = 1 to st.depth.count
  326.  
  327.             tmp = j.depth
  328.  
  329.             /*
  330.              *  Write the referring mail
  331.              */
  332.  
  333.             call printmail(st.depth.tmp)
  334.  
  335.         end
  336.     end
  337. end
  338.  
  339. depth = depth - 1
  340.  
  341. return
  342.  
  343.  
  344. /*----------------------------------------------------*
  345.  *                                                    *
  346.  *  Close an index page                               *
  347.  *                                                    *
  348.  *----------------------------------------------------*/
  349.  
  350.  
  351. closelistfile:
  352.  
  353. /*
  354.  *  Create the page navigation bar
  355.  */
  356.  
  357. call writeln(f, '</table><table border=0 width="100%" cellspacing=0 bgcolor="' || titlebgcolor || '"><tr><td><font color="' || titletxcolor || '"> Pages: ')
  358.  
  359. if activepage > 1 then
  360. do
  361.     indexnum = activepage - 1
  362.  
  363.     if indexnum = 1 then indexnum = ""
  364.  
  365.     call writeln(f, '<a href="index' || indexnum || '.html">[<<]</a> ')
  366.  
  367.     do k = 1 to activepage - 1
  368.  
  369.         indexnum = k
  370.  
  371.         if indexnum = 1 then indexnum = ""
  372.  
  373.         call writeln(f, '<a href="index' || indexnum || '.html">' || k || '</a> ')
  374.  
  375.     end
  376. end
  377.  
  378. call writeln(f, activepage || ' ')
  379.  
  380. if activepage < numpages then
  381. do
  382.     do k = activepage + 1 to numpages
  383.  
  384.         indexnum = k
  385.  
  386.         call writeln(f, '<a href="index' || indexnum || '.html">' || k || '</a> ')
  387.  
  388.     end
  389.  
  390.     indexnum = activepage + 1
  391.  
  392.     call writeln(f, '<a href="index' || indexnum || '.html">[>>]</a> ')
  393.  
  394. end
  395.  
  396. call writeln(f, '</font></td><td align=right><font color="' || titlebgcolor || '"><font color="' || titletxcolor || '">Created with the <a href="http://www.amigaworld.com/support/fiasco/">Mailing List Archive for Fiasco</a></font></td></tr></table><br>')
  397.  
  398. /*
  399.  *  Add the template file to
  400.  *  the end of the index page
  401.  */
  402.  
  403. if open(t, endtemplatefile, "r") then
  404. do
  405.     do while ~eof(t)
  406.  
  407.         tln = readln(t)
  408.  
  409.         call writeln(f, tln)
  410.  
  411.     end
  412.  
  413.     call close(t)
  414. end
  415.  
  416. call close(f)
  417.  
  418. return
  419.  
  420.  
  421. /*----------------------------------------------------*
  422.  *                                                    *
  423.  *  Create a new index page                           *
  424.  *                                                    *
  425.  *----------------------------------------------------*/
  426.  
  427. newlistfile:
  428.  
  429. /*
  430.  *  If there is still a index page open, finish it and close it
  431.  */
  432.  
  433. if activepage ~= 0 then
  434. do
  435.  
  436.     call closelistfile
  437.  
  438. end
  439.  
  440. activepage = activepage + 1
  441.  
  442. indexnum = activepage
  443.  
  444. if indexnum = "1" then indexnum = ""
  445.  
  446. if open(f, dir || "index" || indexnum || ".html", "w") then
  447. do
  448.     /*
  449.      *  Write the template to the start of the
  450.      *  index file
  451.      */
  452.  
  453.     if open(t, starttemplatefile, "r") then
  454.     do
  455.         do while ~eof(t)
  456.  
  457.             tln = readln(t)
  458.  
  459.             call writeln(f, tln)
  460.  
  461.         end
  462.  
  463.         call close(t)
  464.     end
  465.  
  466.     call writeln(f, '<!- Created with the Mailing List Archive Database for Fiasco by Nils Bandener (nilsb@amigaworld.com). More Information: http://www.amigaworld.com/support/fiasco  ->')
  467.     call writeln(f, '<table width="100%" border=0 cellspacing=0 cellpadding=2 bgcolor="' ||  titlebgcolor || '"><tr><td><font color="' || titletxcolor || '" size="+1">' || mlname || ' · Page ' || activepage || ' / ' || numpages || '</font></td><td align=right><font color="' || titletxcolor || '">Last update: ' || date() || '</font></td></tr></table>')
  468.     call writeln(f, '<table width="100%" border=0 cellspacing=0 cellpadding=2 bgcolor="' ||  bgcolor || '"><tr>')
  469.     call writeln(f, '<td bgcolor="' || titlebgcolor || '" colspan=8><font color="' || titletxcolor || '"><b>Subject</b></font></td>')
  470.     call writeln(f, '<td bgcolor="' || titlebgcolor || '"><font color="' || titletxcolor || '"><b>Size</b></font></td>')
  471.     call writeln(f, '<td bgcolor="' || titlebgcolor || '"><font color="' || titletxcolor || '"><b>Date</b></font></td>')
  472.     call writeln(f, '<td bgcolor="' || titlebgcolor || '"><font color="' || titletxcolor || '"><b>From</b></font></td></tr>')
  473. end
  474.  
  475. return
  476.  
  477.  
  478. /*----------------------------------------------------*
  479.  *                                                    *
  480.  *  Create a mail page                                *
  481.  *                                                    *
  482.  *----------------------------------------------------*/
  483.  
  484. writemailfile:
  485.  
  486. if open(m, dir || messagekey || ".html", "w") then
  487. do
  488.     /*
  489.      *  Write the template file to the beginning
  490.      */
  491.  
  492.     if open(t, starttemplatefile, "r") then
  493.     do
  494.         do while ~eof(t)
  495.  
  496.             tln = readln(t)
  497.  
  498.             call writeln(m, tln)
  499.  
  500.         end
  501.  
  502.         call close(t)
  503.     end
  504.  
  505.     /*
  506.      *  Write header
  507.      */
  508.  
  509.     call writeln(m, '<!- Created with the Mailing List Archive Database for Fiasco by Nils Bandener (nils@dinoex.sub.org). More Information: http://www.amigaworld.com/support/fiasco  ->')
  510.     call writeln(m, '<table border=0 cellspacing=0 cellpadding=2 bgcolor="' ||  bgcolor || '">')
  511.     call writeln(m, '<tr><td bgcolor="' || titlebgcolor || '"></td><td bgcolor="' || titlebgcolor || '"><font color="' || titletxcolor || '" size="+1">' || mlname || '</font></td></tr>')
  512.     call writeln(m, '<tr><td bgcolor="' || titlebgcolor || '" align=right><font color="' || titletxcolor || '" size="+1">Subject:</font></td><td><font size="+1">' || subject || '</font></td></tr>')
  513.     call writeln(m, '<tr><td bgcolor="' || titlebgcolor || '" align=right><font color="' || titletxcolor || '" size="+1">From:</font></td><td><font size="+1"><a href="mailto:' || emailval || '">'|| realname || ' <' || emailval || '></a></font></td></tr>')
  514.     call writeln(m, '<tr><td bgcolor="' || titlebgcolor || '" align=right><font color="' || titletxcolor || '" size="+1">Date:</font></td><td><font size="+1">' || dateval || '</font></td></tr>')
  515.     call writeln(m, '</table><br><pre>')
  516.  
  517.     p = 1
  518.  
  519.     /*
  520.      *  Convert newlines in the message body to <br>
  521.      */
  522.  
  523.     do forever
  524.  
  525.         p = pos("0A"x, mailbody, p)
  526.  
  527.         if p ~= 0 then
  528.         do
  529.             mailbody = substr(mailbody, 1, p - 1) || "<br>" || substr(mailbody, p + 1)
  530.  
  531.             p = p + 4
  532.         end
  533.         else break
  534.  
  535.     end
  536.  
  537.     p = 1
  538.  
  539.     do forever
  540.  
  541.         p = pos("*n", mailbody, p)
  542.  
  543.         if p ~= 0 then
  544.         do
  545.             mailbody = substr(mailbody, 1, p - 1) || "<br>" || substr(mailbody, p + 2)
  546.  
  547.             p = p + 4
  548.         end
  549.         else break
  550.  
  551.     end
  552.  
  553.     p = 1
  554.  
  555.     do forever
  556.  
  557.         p = pos('*"', mailbody, p)
  558.  
  559.         if p ~= 0 then
  560.         do
  561.             mailbody = substr(mailbody, 1, p - 1) || '"' || substr(mailbody, p + 2)
  562.  
  563.             p = p + 1
  564.         end
  565.         else break
  566.  
  567.     end
  568.  
  569.  
  570.     call writeln(m, mailbody || "<br></pre><br>")
  571.  
  572.     call writeln(m, '<table border=0 cellspacing=0 cellpadding=2 bgcolor="' ||  bgcolor || '">')
  573.     call writeln(m, '<tr><td bgcolor="' || titlebgcolor || '"><font size="+1"><a href="index' || indexnum || '.html"><<</a></font></td><td><font size="+1"><a href="index' || indexnum || '.html">Back</a></font></td></tr></table>')
  574.  
  575.     /*
  576.      *  Insert template at the end of the mail page
  577.      */
  578.  
  579.     if open(t, endtemplatefile, "r") then
  580.     do
  581.         do while ~eof(t)
  582.  
  583.             tln = readln(t)
  584.  
  585.             call writeln(m, tln)
  586.  
  587.         end
  588.  
  589.         call close(t)
  590.     end
  591.  
  592.     call close(m)
  593.  
  594.     /*
  595.      *  Get size of mail page for
  596.      *  index page
  597.      */
  598.  
  599.     address command 'list >t:chtmp "' || dir || messagekey || '.html" lformat %l'
  600.  
  601.     sizeval = "?"
  602.  
  603.     if open(m, "t:chtmp", "read") then
  604.     do
  605.         sizeval = readln(m)
  606.  
  607.         call close(m)
  608.     end
  609. end
  610.  
  611. return
  612.