| 1 | ############################################################################## | ||
| 2 | # The Faq-O-Matic is Copyright 1997 by Jon Howell, all rights reserved. # | ||
| 3 | # # | ||
| 4 | # This program is free software; you can redistribute it and/or # | ||
| 5 | # modify it under the terms of the GNU General Public License # | ||
| 6 | # as published by the Free Software Foundation; either version 2 # | ||
| 7 | # of the License, or (at your option) any later version. # | ||
| 8 | # # | ||
| 9 | # This program is distributed in the hope that it will be useful, # | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
| 12 | # GNU General Public License for more details. # | ||
| 13 | # # | ||
| 14 | # You should have received a copy of the GNU General Public License # | ||
| 15 | # along with this program; if not, write to the Free Software # | ||
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.# | ||
| 17 | # # | ||
| 18 | # Jon Howell can be contacted at: # | ||
| 19 | # 6211 Sudikoff Lab, Dartmouth College # | ||
| 20 | # Hanover, NH 03755-3510 # | ||
| 21 | # jonh@cs.dartmouth.edu # | ||
| 22 | # # | ||
| 23 | # An electronic copy of the GPL is available at: # | ||
| 24 | # http://www.gnu.org/copyleft/gpl.html # | ||
| 25 | # # | ||
| 26 | ############################################################################## | ||
| 27 | |||
| 28 | use strict; | ||
| 29 | |||
| 30 | package FAQ::OMatic::faq; | ||
| 31 | |||
| 32 | use CGI; | ||
| 33 | use FAQ::OMatic::Item; | ||
| 34 | use FAQ::OMatic; | ||
| 35 | use FAQ::OMatic::I18N; | ||
| 36 | |||
| 37 | sub main { | ||
| 38 | my $cgi = FAQ::OMatic::dispatch::cgi(); | ||
| 39 | |||
| 40 | my $params = FAQ::OMatic::getParams($cgi); | ||
| 41 | # supply some default parameters where necessary | ||
| 42 | $params->{'file'} = 1 if (not $params->{'file'}); | ||
| 43 | |||
| 44 | # strip out null params from params array | ||
| 45 | if ($params->{'_fromAppearance'}) { | ||
| 46 | my $key; | ||
| 47 | foreach $key (keys %{$params}) { | ||
| 48 | delete $params->{$key} if ($params->{$key} eq ''); | ||
| 49 | } | ||
| 50 | delete $params->{'_fromAppearance'}; | ||
| 51 | } | ||
| 52 | |||
| 53 | my $cacheUrl = FAQ::OMatic::getCacheUrl($params); | ||
| 54 | if ($cacheUrl) { | ||
| 55 | # Hey! We could just send this guy to the cached site! | ||
| 56 | FAQ::OMatic::redirect($cgi, $cacheUrl); | ||
| 57 | # (implicit exit) | ||
| 58 | } | ||
| 59 | |||
| 60 | my $render = FAQ::OMatic::getParam($params, 'render'); | ||
| 61 | my $html = ''; | ||
| 62 | if ($render eq 'text') { | ||
| 63 | $html .= FAQ::OMatic::header($cgi, '-type'=>'text/plain'); | ||
| 64 | } else { | ||
| 65 | $html .= FAQ::OMatic::header($cgi, '-type'=>'text/html'); | ||
| 66 | } | ||
| 67 | |||
| 68 | if (FAQ::OMatic::getParam($params, 'editCmds') ne 'hide') { | ||
| 69 | FAQ::OMatic::mirrorsCantEdit($cgi, $params); | ||
| 70 | } | ||
| 71 | |||
| 72 | my $item = new FAQ::OMatic::Item($params->{'file'}); | ||
| 73 | if ($item->isBroken()) { | ||
| 74 | FAQ::OMatic::gripe('error', gettexta("The file (%0) doesn't exist.", $params->{'file'})); | ||
| 75 | } | ||
| 76 | |||
| 77 | if ($params->{'debug'}) { | ||
| 78 | $html .= $item->display(); | ||
| 79 | } | ||
| 80 | |||
| 81 | $html .= $item->getWholePage($params); | ||
| 82 | |||
| 83 | # TODO: worry about this when we turn the help system back on | ||
| 84 | # TODO- (perhaps just stuff it into getWholePage().) | ||
| 85 | # if (not $params->{'file'} =~ m/^help/) { | ||
| 86 | # $html .= FAQ::OMatic::pageFooter($params, 'all'); | ||
| 87 | # } | ||
| 88 | |||
| 89 | print $html; | ||
| 90 | } | ||
| 91 | |||
| 92 | 1; |