1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * pageaction.cpp --
|
---|
4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
5 | *
|
---|
6 | * A component of the Greenstone digital library software
|
---|
7 | * from the New Zealand Digital Library Project at the
|
---|
8 | * University of Waikato, New Zealand.
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | *
|
---|
24 | * $Id: pageaction.cpp 542 1999-09-07 23:08:09Z rjmcnab $
|
---|
25 | *
|
---|
26 | *********************************************************************/
|
---|
27 |
|
---|
28 | /*
|
---|
29 | $Log$
|
---|
30 | Revision 1.14 1999/09/07 23:08:09 rjmcnab
|
---|
31 | Removed some compiler warnings
|
---|
32 |
|
---|
33 | Revision 1.13 1999/09/07 04:56:57 sjboddie
|
---|
34 | added GPL notice
|
---|
35 |
|
---|
36 | Revision 1.12 1999/09/02 00:26:43 rjmcnab
|
---|
37 | made the p cgi argument always saved in the compressed arguments
|
---|
38 |
|
---|
39 | Revision 1.11 1999/08/25 04:48:43 sjboddie
|
---|
40 | changes to the home and about pages
|
---|
41 |
|
---|
42 | Revision 1.10 1999/08/11 23:29:43 sjboddie
|
---|
43 | added support for html classifier (i.e. the hp argument)
|
---|
44 |
|
---|
45 | Revision 1.9 1999/08/03 03:29:47 sjboddie
|
---|
46 | added ability to set receptionist from collect.cfg
|
---|
47 |
|
---|
48 | Revision 1.8 1999/07/30 02:24:44 sjboddie
|
---|
49 | added collectinfo argument to some functions
|
---|
50 |
|
---|
51 | Revision 1.7 1999/06/24 05:12:24 sjboddie
|
---|
52 | lots of small changes
|
---|
53 |
|
---|
54 | Revision 1.6 1999/06/10 00:39:16 sjboddie
|
---|
55 | navigation bar is no longer written out for every page (it should
|
---|
56 | be included in the _content_ macro of pages wanting to display it).
|
---|
57 |
|
---|
58 | Revision 1.5 1999/06/08 04:29:35 sjboddie
|
---|
59 | added argsinfo to the call to check_cgiargs to make it easy to set
|
---|
60 | args to their default if they're found to be screwed up
|
---|
61 |
|
---|
62 | Revision 1.4 1999/02/28 20:00:14 rjmcnab
|
---|
63 |
|
---|
64 |
|
---|
65 | Fixed a few things.
|
---|
66 |
|
---|
67 | Revision 1.3 1999/02/25 21:58:58 rjmcnab
|
---|
68 |
|
---|
69 | Merged sources.
|
---|
70 |
|
---|
71 | Revision 1.2 1999/02/21 22:33:54 rjmcnab
|
---|
72 |
|
---|
73 | Lots of stuff :-)
|
---|
74 |
|
---|
75 | Revision 1.1 1999/02/12 02:40:17 sjboddie
|
---|
76 |
|
---|
77 | Added page action
|
---|
78 |
|
---|
79 | */
|
---|
80 |
|
---|
81 | #include "OIDtools.h"
|
---|
82 | #include "pageaction.h"
|
---|
83 | #include "receptionist.h"
|
---|
84 | #include <time.h>
|
---|
85 |
|
---|
86 | pageaction::pageaction () {
|
---|
87 |
|
---|
88 | recpt = NULL;
|
---|
89 |
|
---|
90 | // this action uses cgi variables "a", "p", and "hp"
|
---|
91 | cgiarginfo arg_ainfo;
|
---|
92 | arg_ainfo.shortname = "a";
|
---|
93 | arg_ainfo.longname = "action";
|
---|
94 | arg_ainfo.multiplechar = true;
|
---|
95 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
96 | arg_ainfo.argdefault = "p";
|
---|
97 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
98 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
99 |
|
---|
100 | arg_ainfo.shortname = "p";
|
---|
101 | arg_ainfo.longname = "page";
|
---|
102 | arg_ainfo.multiplechar = true;
|
---|
103 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
104 | arg_ainfo.argdefault = "about";
|
---|
105 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
106 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
107 |
|
---|
108 | arg_ainfo.shortname = "hp";
|
---|
109 | arg_ainfo.longname = "html page";
|
---|
110 | arg_ainfo.multiplechar = true;
|
---|
111 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
112 | arg_ainfo.argdefault = "";
|
---|
113 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
114 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
115 | }
|
---|
116 |
|
---|
117 | pageaction::~pageaction () {
|
---|
118 | }
|
---|
119 |
|
---|
120 | bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
|
---|
121 | ostream &/*logout*/) {
|
---|
122 | // don't want to check anything yet.
|
---|
123 | return true;
|
---|
124 | }
|
---|
125 |
|
---|
126 | void pageaction::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
|
---|
127 | text_t &response_data, ostream &/*logout*/) {
|
---|
128 | response = content;
|
---|
129 | response_data = "text/html";
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | // define all the macros which might be used by other actions
|
---|
134 | // to produce pages.
|
---|
135 | void pageaction::define_external_macros (const ColInfoResponse_t &/*collectinfo*/, displayclass &/*disp*/,
|
---|
136 | cgiargsclass &/*args*/, recptproto * /*collectproto*/,
|
---|
137 | ostream &/*logout*/) {
|
---|
138 | }
|
---|
139 |
|
---|
140 |
|
---|
141 | void pageaction::define_internal_macros (const ColInfoResponse_t &collectinfo, displayclass &disp,
|
---|
142 | cgiargsclass &args, recptproto *collectproto,
|
---|
143 | ostream &logout) {
|
---|
144 |
|
---|
145 | // define_internal_macros sets the following macros:
|
---|
146 |
|
---|
147 | // if page is "home"
|
---|
148 | // _homeextra_ this is the list of available collections and collection info
|
---|
149 | // to be displayed on the home page
|
---|
150 |
|
---|
151 |
|
---|
152 | // if page is "about"
|
---|
153 | // _numdocs_ the number of documents in the collection
|
---|
154 |
|
---|
155 | // _builddate_ the date last built
|
---|
156 |
|
---|
157 | // _textbrowseoptions_ the 'how to find information' text in the about and help pages
|
---|
158 |
|
---|
159 | // _numbrowseoptions_ the number of browsing options
|
---|
160 |
|
---|
161 |
|
---|
162 | // if page is "help"
|
---|
163 | // _textbrowseoptions_ the 'how to find information' text in the about and help pages
|
---|
164 |
|
---|
165 | // _numbrowseoptions_ the number of browsing options
|
---|
166 |
|
---|
167 |
|
---|
168 | text_t &arg_p = args["p"];
|
---|
169 |
|
---|
170 | if (arg_p == "home") {
|
---|
171 | // make sure we know about a receptionist
|
---|
172 | if (recpt == NULL) {
|
---|
173 | logout << "The page action does not contain information\n"
|
---|
174 | << "about any receptionists. The method set_receptionist\n"
|
---|
175 | << "was probably not called from the module which instantiated\n"
|
---|
176 | << "this page action.\n";
|
---|
177 | return;
|
---|
178 | }
|
---|
179 |
|
---|
180 | unsigned long current_time = time(NULL);
|
---|
181 | text_t homeextra;
|
---|
182 |
|
---|
183 | recptprotolistclass *rprotolist = recpt->get_recptprotolist_ptr ();
|
---|
184 | if (rprotolist == NULL) return;
|
---|
185 |
|
---|
186 | recptprotolistclass::iterator rprotolist_here = rprotolist->begin();
|
---|
187 | recptprotolistclass::iterator rprotolist_end = rprotolist->end();
|
---|
188 | while (rprotolist_here != rprotolist_end) {
|
---|
189 | if ((*rprotolist_here).p != NULL) {
|
---|
190 | text_tarray collist;
|
---|
191 | comerror_t err;
|
---|
192 | (*rprotolist_here).p->get_collection_list (collist, err, logout);
|
---|
193 | if (err == noError) {
|
---|
194 | text_tarray::iterator collist_here = collist.begin();
|
---|
195 | text_tarray::iterator collist_end = collist.end();
|
---|
196 |
|
---|
197 | homeextra += "<dl>\n";
|
---|
198 |
|
---|
199 | FilterResponse_t response;
|
---|
200 | text_tarray metadata;
|
---|
201 | metadata.push_back ("collectionname");
|
---|
202 |
|
---|
203 | while (collist_here != collist_end) {
|
---|
204 | text_t collectionname = *collist_here;
|
---|
205 | if (get_info ("collection", *collist_here, metadata, false, (*rprotolist_here).p, response, logout))
|
---|
206 | collectionname = response.docInfo[0].metadata[0].values[0];
|
---|
207 |
|
---|
208 | ColInfoResponse_t cinfo;
|
---|
209 | (*rprotolist_here).p->get_collectinfo (*collist_here, cinfo, err, logout);
|
---|
210 | if (err == noError) {
|
---|
211 | text_t link = "<a href=\"_gwcgi_?a=p&p=about&c=" + *collist_here + "\">";
|
---|
212 | if (!cinfo.receptionist.empty())
|
---|
213 | link = "<a href=\"" + cinfo.receptionist + "?a=p&p=about&c=" + *collist_here + "\">";
|
---|
214 |
|
---|
215 | homeextra += "<dt>" + link + collectionname + "</a></dt>\n";
|
---|
216 | homeextra += "<dd>";
|
---|
217 | if (cinfo.numDocs != 0) homeextra += text_t(cinfo.numDocs) + "_documents_";
|
---|
218 | if (cinfo.numWords != 0) homeextra += text_t(cinfo.numWords) + "_words_";
|
---|
219 | unsigned long last_update = (current_time - cinfo.buildDate) / 86400;
|
---|
220 | homeextra += "_lastupdate_ " + text_t(last_update) + " _ago_</dd>\n";
|
---|
221 | }
|
---|
222 | collist_here ++;
|
---|
223 | }
|
---|
224 | homeextra += "</dl>\n";
|
---|
225 | disp.setmacro ("homeextra", "home", homeextra);
|
---|
226 | }
|
---|
227 | }
|
---|
228 | rprotolist_here ++;
|
---|
229 | }
|
---|
230 | } else if (arg_p == "about") {
|
---|
231 | disp.setmacro ("numdocs", "about", collectinfo.numDocs);
|
---|
232 | unsigned long current_time = time(NULL);
|
---|
233 | unsigned long builddate = (current_time - collectinfo.buildDate) / 86400;
|
---|
234 | disp.setmacro ("builddate", "about", builddate);
|
---|
235 | }
|
---|
236 |
|
---|
237 | if (arg_p == "about" || arg_p == "help") {
|
---|
238 |
|
---|
239 | // _textbrowseoptions_ and _numbrowseoptions_
|
---|
240 |
|
---|
241 | FilterResponse_t response;
|
---|
242 | text_tarray metadata;
|
---|
243 | metadata.push_back ("Title");
|
---|
244 | bool getParents = false;
|
---|
245 | get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
|
---|
246 |
|
---|
247 | disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
|
---|
248 |
|
---|
249 | ResultDocInfo_tarray::const_iterator here = response.docInfo.begin();
|
---|
250 | ResultDocInfo_tarray::const_iterator end = response.docInfo.end();
|
---|
251 |
|
---|
252 | // we're assuming that we've always got a search button
|
---|
253 | text_t shorttext = "<ul><li>_textSearchshort_\n";
|
---|
254 | text_t longtext = "_textSearchlong_";
|
---|
255 |
|
---|
256 | while (here != end) {
|
---|
257 | const text_t &title = (*here).metadata[0].values[0];
|
---|
258 | shorttext += "<li>_text" + title + "short_\n";
|
---|
259 | longtext += "_text" + title + "long_";
|
---|
260 | here ++;
|
---|
261 | }
|
---|
262 | shorttext += "</ul>\n";
|
---|
263 | disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
|
---|
264 | }
|
---|
265 | }
|
---|
266 |
|
---|
267 | bool pageaction::do_action (cgiargsclass &args, const ColInfoResponse_t &/*collectinfo*/,
|
---|
268 | recptproto * /*collectproto*/, displayclass &disp,
|
---|
269 | outconvertclass &outconvert, ostream &textout,
|
---|
270 | ostream &/*logout*/) {
|
---|
271 |
|
---|
272 | text_t &arg_p = args["p"];
|
---|
273 |
|
---|
274 | textout << outconvert << disp << ("_" + arg_p + ":header_\n")
|
---|
275 | << ("_" + arg_p + ":content_\n")
|
---|
276 | << ("_" + arg_p + ":footer_\n");
|
---|
277 |
|
---|
278 | return true;
|
---|
279 | }
|
---|