source: trunk/gsdl/src/recpt/pageaction.cpp@ 761

Last change on this file since 761 was 761, checked in by sjboddie, 25 years ago

changes to arguments of many functions, now pass list of protocols
instead of just that for this collection

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 10.6 KB
Line 
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 761 1999-11-01 21:58:02Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.20 1999/11/01 21:58:02 sjboddie
31 changes to arguments of many functions, now pass list of protocols
32 instead of just that for this collection
33
34 Revision 1.19 1999/10/19 21:59:09 sjboddie
35 bug in generating "how to find information" text for about pages
36
37 Revision 1.18 1999/10/19 03:23:44 davidb
38 Collection building support through web pages
39 and internal and external link handling for collection documents
40
41 Revision 1.17 1999/10/14 23:04:44 sjboddie
42 some hacks to make nzdl home page look right
43
44 Revision 1.16 1999/10/10 08:14:09 sjboddie
45 - metadata now returns mp rather than array
46 - redesigned browsing support (although it's not finished so
47 won't currently work ;-)
48
49 Revision 1.15 1999/09/17 04:46:05 sjboddie
50 fixed a couple of problems with 'unknown' classifier
51
52 Revision 1.14 1999/09/07 23:08:09 rjmcnab
53 Removed some compiler warnings
54
55 Revision 1.13 1999/09/07 04:56:57 sjboddie
56 added GPL notice
57
58 Revision 1.12 1999/09/02 00:26:43 rjmcnab
59 made the p cgi argument always saved in the compressed arguments
60
61 Revision 1.11 1999/08/25 04:48:43 sjboddie
62 changes to the home and about pages
63
64 Revision 1.10 1999/08/11 23:29:43 sjboddie
65 added support for html classifier (i.e. the hp argument)
66
67 Revision 1.9 1999/08/03 03:29:47 sjboddie
68 added ability to set receptionist from collect.cfg
69
70 Revision 1.8 1999/07/30 02:24:44 sjboddie
71 added collectinfo argument to some functions
72
73 Revision 1.7 1999/06/24 05:12:24 sjboddie
74 lots of small changes
75
76 Revision 1.6 1999/06/10 00:39:16 sjboddie
77 navigation bar is no longer written out for every page (it should
78 be included in the _content_ macro of pages wanting to display it).
79
80 Revision 1.5 1999/06/08 04:29:35 sjboddie
81 added argsinfo to the call to check_cgiargs to make it easy to set
82 args to their default if they're found to be screwed up
83
84 Revision 1.4 1999/02/28 20:00:14 rjmcnab
85
86
87 Fixed a few things.
88
89 Revision 1.3 1999/02/25 21:58:58 rjmcnab
90
91 Merged sources.
92
93 Revision 1.2 1999/02/21 22:33:54 rjmcnab
94
95 Lots of stuff :-)
96
97 Revision 1.1 1999/02/12 02:40:17 sjboddie
98
99 Added page action
100
101 */
102
103#include "OIDtools.h"
104#include "pageaction.h"
105#include "receptionist.h"
106#include <time.h>
107
108pageaction::pageaction () {
109
110 recpt = NULL;
111
112 // this action uses cgi variables "a", "p", and "hp"
113 cgiarginfo arg_ainfo;
114 arg_ainfo.shortname = "a";
115 arg_ainfo.longname = "action";
116 arg_ainfo.multiplechar = true;
117 arg_ainfo.defaultstatus = cgiarginfo::weak;
118 arg_ainfo.argdefault = "p";
119 arg_ainfo.savedarginfo = cgiarginfo::must;
120 argsinfo.addarginfo (NULL, arg_ainfo);
121
122 arg_ainfo.shortname = "p";
123 arg_ainfo.longname = "page";
124 arg_ainfo.multiplechar = true;
125 arg_ainfo.defaultstatus = cgiarginfo::weak;
126 arg_ainfo.argdefault = "about";
127 arg_ainfo.savedarginfo = cgiarginfo::must;
128 argsinfo.addarginfo (NULL, arg_ainfo);
129
130 arg_ainfo.shortname = "hp";
131 arg_ainfo.longname = "html page";
132 arg_ainfo.multiplechar = true;
133 arg_ainfo.defaultstatus = cgiarginfo::weak;
134 arg_ainfo.argdefault = "";
135 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
136 argsinfo.addarginfo (NULL, arg_ainfo);
137}
138
139pageaction::~pageaction () {
140}
141
142bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
143 ostream &/*logout*/) {
144 // don't want to check anything yet.
145 return true;
146}
147
148void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
149 response_t &response,text_t &response_data,
150 ostream &/*logout*/) {
151 response = content;
152 response_data = "text/html";
153}
154
155void pageaction::set_homeextra_macro (displayclass &disp, recptprotolistclass *protos,
156 ostream &logout) {
157
158 text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
159
160 recptprotolistclass::iterator rprotolist_here = protos->begin();
161 recptprotolistclass::iterator rprotolist_end = protos->end();
162 while (rprotolist_here != rprotolist_end) {
163 if ((*rprotolist_here).p != NULL) {
164
165 text_tarray collist;
166 comerror_t err;
167 (*rprotolist_here).p->get_collection_list (collist, err, logout);
168 if (err == noError) {
169 text_tarray::iterator collist_here = collist.begin();
170 text_tarray::iterator collist_end = collist.end();
171
172 int row1 = 6;
173 int row2 = 4;
174 int count = 1;
175 while (collist_here != collist_end) {
176
177 if (*collist_here == "niupepa")
178 homeextra += "<p><a href=\"_httpmusiclibrary_\">_iconmusiclibrary_</a>\n";
179
180 ColInfoResponse_t cinfo;
181 (*rprotolist_here).p->get_collectinfo (*collist_here, cinfo, err, logout);
182
183 if (err == noError) {
184 if (cinfo.isPublic && (cinfo.buildDate > 0)) {
185
186 FilterResponse_t response;
187 text_tset metadata;
188 metadata.insert ("collectionname");
189 metadata.insert ("iconcollection");
190 metadata.insert ("iconcollectionsmall");
191 text_t collectionname = *collist_here;
192 text_t alt = collectionname;
193 if (get_info ("collection", *collist_here, metadata, false,
194 (*rprotolist_here).p, response, logout)) {
195 if (!response.docInfo[0].metadata["collectionname"].values[0].empty())
196 alt = response.docInfo[0].metadata["collectionname"].values[0];
197
198 if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty())
199 collectionname = "<img width=150 border=1 src=\""
200 + response.docInfo[0].metadata["iconcollectionsmall"].values[0]
201 + "\" alt=\"" + alt + "\">";
202 else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty())
203 collectionname = "<img width=150 border=1 src=\""
204 + response.docInfo[0].metadata["iconcollection"].values[0]
205 + "\" alt=\"" + alt + "\">";
206 else collectionname = alt;
207 }
208
209 if ((count == 1) || (count == (row1+1)) || (count == ((row1+row2)+1)))
210 homeextra += "<td align=center>";
211 else homeextra += "<p>";
212 text_t link = "<a href=\"_gwcgi_?a=p&p=about&c=" + *collist_here + "\">";
213 if (*collist_here == "chinese")
214 link = "<a href=\"_gwcgi_?a=p&p=about&l=zh&nw=u&c=" + *collist_here + "\">";
215
216 if (!cinfo.receptionist.empty())
217 link = "<a href=\"" + cinfo.receptionist + "?a=p&p=about&c="
218 + *collist_here + "\">";
219
220 homeextra += link + collectionname + "</a>\n";
221
222 if ((count == row1) || (count == (row1+row2)))
223 homeextra += "</td>";
224
225 count ++;
226 }
227 }
228
229 collist_here ++;
230 }
231 homeextra += "</tr></table></center>\n";
232 disp.setmacro ("homeextra", "home", homeextra);
233 }
234 }
235 rprotolist_here ++;
236 }
237}
238
239void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
240 recptprotolistclass *protos, ostream &logout) {
241
242 // define_internal_macros sets the following macros:
243
244 // if page is "home"
245 // _homeextra_ this is the list of available collections and collection info
246 // to be displayed on the home page
247
248
249 // if page is "about"
250 // _numdocs_ the number of documents in the collection
251
252 // _builddate_ the date last built
253
254 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
255
256 // _numbrowseoptions_ the number of browsing options
257
258
259 // if page is "help"
260 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
261
262 // _numbrowseoptions_ the number of browsing options
263
264
265 text_t &arg_p = args["p"];
266
267 if (arg_p == "home") set_homeextra_macro (disp, protos, logout);
268
269 else if (arg_p == "about" || arg_p == "help") {
270 // get pointer to collection server
271 recptproto* collectproto = protos->getrecptproto (args["c"], logout);
272 if (collectproto == NULL) return;
273
274 if (arg_p == "about") {
275 comerror_t err;
276 ColInfoResponse_t cinfo;
277 collectproto->get_collectinfo (args["c"], cinfo, err, logout);
278
279 disp.setmacro ("numdocs", "about", cinfo.numDocs);
280 unsigned long current_time = time(NULL);
281 unsigned long builddate = (current_time - cinfo.buildDate) / 86400;
282 disp.setmacro ("builddate", "about", builddate);
283 }
284
285 // _textbrowseoptions_ and _numbrowseoptions_
286
287 FilterResponse_t response;
288 text_tset metadata;
289 metadata.insert ("Title");
290 bool getParents = false;
291 get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
292
293 disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
294
295 ResultDocInfo_tarray::iterator here = response.docInfo.begin();
296 ResultDocInfo_tarray::iterator end = response.docInfo.end();
297
298 // we're assuming that we've always got a search button
299 text_t shorttext = "<ul><li>_textSearchshort_\n";
300 text_t longtext = "_textSearchlong_";
301
302 while (here != end) {
303 text_t title = (*here).metadata["Title"].values[0];
304
305 text_t stext, ltext;
306 disp.expandstring ("help", "_text" + title + "short_", stext);
307 if (stext == ("_text" + title + "short_")) {
308 shorttext += "<li>_help:textdefaultshorttext_";
309 longtext += "_help:textdefaultlongtext_";
310 } else {
311 shorttext += "<li>" + stext;
312 longtext += "_help:text" + title + "long_";
313 }
314
315 here ++;
316 }
317 shorttext += "</ul>\n";
318 disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
319 }
320}
321
322bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
323 browsermapclass * /*browsers*/, displayclass &disp,
324 outconvertclass &outconvert, ostream &textout,
325 ostream &/*logout*/) {
326
327 text_t &arg_p = args["p"];
328
329 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
330 << ("_" + arg_p + ":content_\n")
331 << ("_" + arg_p + ":footer_\n");
332
333 return true;
334}
Note: See TracBrowser for help on using the repository browser.