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

Last change on this file since 1270 was 1270, checked in by sjboddie, 24 years ago

Receptionist now caches collection information to avoid making multiple
get_collectinfo calls to collection server

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 18.8 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 1270 2000-07-05 21:49:36Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.33 2000/07/05 21:49:33 sjboddie
31 Receptionist now caches collection information to avoid making multiple
32 get_collectinfo calls to collection server
33
34 Revision 1.32 2000/06/27 23:02:40 sjboddie
35 Tidied up the way collections are displayed on 'standard' homepage.
36 Removed all the nzdl.org specific stuff.
37
38 Revision 1.31 2000/06/23 03:48:08 sjboddie
39 Added Arabic language and encoding options to the preferences page. This
40 is a much more complex task than it should be (you even have to recompile!)
41 but it's not really worth fixing until the new config file format is
42 finalised.
43
44 Revision 1.30 2000/06/14 22:33:42 sjboddie
45 Added French and Spanish language selection options to the preferences
46 page. I really don't like how this is currently implemented (i.e. you
47 have to recompile the library to do something so simple), it might have
48 to wait until the new configuration file stuff is done before it's fixed
49 though.
50
51 Revision 1.29 2000/03/19 21:16:46 nzdl
52 added german language interface
53
54 Revision 1.28 2000/02/24 01:19:01 sjboddie
55 fixed up messy hack for meldex
56
57 Revision 1.27 2000/02/15 22:53:51 kjm18
58 search history stuff added.
59
60 Revision 1.26 2000/02/03 01:49:35 sjboddie
61 fixed up some of the preferences stuff
62
63 Revision 1.25 2000/01/26 20:11:04 sjboddie
64 added some collection specific help text
65
66 Revision 1.24 2000/01/25 22:31:09 sjboddie
67 more hacky changes to get preferences to be a bit smarter
68
69 Revision 1.23 2000/01/24 22:59:57 sjboddie
70 changes to set macros differently for preferences page depending
71 on type of collection - pageaction is getting kind of hacky - should
72 tidy it up some day
73
74 Revision 1.22 1999/11/25 23:01:09 sjboddie
75 now need to be able to handle it if no collection is selected
76
77 Revision 1.21 1999/11/03 22:50:13 sjboddie
78 now defaults to home page
79
80 Revision 1.20 1999/11/01 21:58:02 sjboddie
81 changes to arguments of many functions, now pass list of protocols
82 instead of just that for this collection
83
84 Revision 1.19 1999/10/19 21:59:09 sjboddie
85 bug in generating "how to find information" text for about pages
86
87 Revision 1.18 1999/10/19 03:23:44 davidb
88 Collection building support through web pages
89 and internal and external link handling for collection documents
90
91 Revision 1.17 1999/10/14 23:04:44 sjboddie
92 some hacks to make nzdl home page look right
93
94 Revision 1.16 1999/10/10 08:14:09 sjboddie
95 - metadata now returns mp rather than array
96 - redesigned browsing support (although it's not finished so
97 won't currently work ;-)
98
99 Revision 1.15 1999/09/17 04:46:05 sjboddie
100 fixed a couple of problems with 'unknown' classifier
101
102 Revision 1.14 1999/09/07 23:08:09 rjmcnab
103 Removed some compiler warnings
104
105 Revision 1.13 1999/09/07 04:56:57 sjboddie
106 added GPL notice
107
108 Revision 1.12 1999/09/02 00:26:43 rjmcnab
109 made the p cgi argument always saved in the compressed arguments
110
111 Revision 1.11 1999/08/25 04:48:43 sjboddie
112 changes to the home and about pages
113
114 Revision 1.10 1999/08/11 23:29:43 sjboddie
115 added support for html classifier (i.e. the hp argument)
116
117 Revision 1.9 1999/08/03 03:29:47 sjboddie
118 added ability to set receptionist from collect.cfg
119
120 Revision 1.8 1999/07/30 02:24:44 sjboddie
121 added collectinfo argument to some functions
122
123 Revision 1.7 1999/06/24 05:12:24 sjboddie
124 lots of small changes
125
126 Revision 1.6 1999/06/10 00:39:16 sjboddie
127 navigation bar is no longer written out for every page (it should
128 be included in the _content_ macro of pages wanting to display it).
129
130 Revision 1.5 1999/06/08 04:29:35 sjboddie
131 added argsinfo to the call to check_cgiargs to make it easy to set
132 args to their default if they're found to be screwed up
133
134 Revision 1.4 1999/02/28 20:00:14 rjmcnab
135
136
137 Fixed a few things.
138
139 Revision 1.3 1999/02/25 21:58:58 rjmcnab
140
141 Merged sources.
142
143 Revision 1.2 1999/02/21 22:33:54 rjmcnab
144
145 Lots of stuff :-)
146
147 Revision 1.1 1999/02/12 02:40:17 sjboddie
148
149 Added page action
150
151 */
152
153#include "OIDtools.h"
154#include "pageaction.h"
155#include "receptionist.h"
156#include <time.h>
157
158pageaction::pageaction () {
159
160 recpt = NULL;
161
162 // this action uses cgi variables "a", "p", and "hp"
163 cgiarginfo arg_ainfo;
164 arg_ainfo.shortname = "a";
165 arg_ainfo.longname = "action";
166 arg_ainfo.multiplechar = true;
167 arg_ainfo.defaultstatus = cgiarginfo::weak;
168 arg_ainfo.argdefault = "p";
169 arg_ainfo.savedarginfo = cgiarginfo::must;
170 argsinfo.addarginfo (NULL, arg_ainfo);
171
172 arg_ainfo.shortname = "p";
173 arg_ainfo.longname = "page";
174 arg_ainfo.multiplechar = true;
175 arg_ainfo.defaultstatus = cgiarginfo::weak;
176 arg_ainfo.argdefault = "home";
177 arg_ainfo.savedarginfo = cgiarginfo::must;
178 argsinfo.addarginfo (NULL, arg_ainfo);
179
180 arg_ainfo.shortname = "hp";
181 arg_ainfo.longname = "html page";
182 arg_ainfo.multiplechar = true;
183 arg_ainfo.defaultstatus = cgiarginfo::weak;
184 arg_ainfo.argdefault = "";
185 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
186 argsinfo.addarginfo (NULL, arg_ainfo);
187}
188
189pageaction::~pageaction () {
190}
191
192bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
193 ostream &/*logout*/) {
194 // don't want to check anything yet.
195 return true;
196}
197
198void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
199 response_t &response,text_t &response_data,
200 ostream &/*logout*/) {
201 response = content;
202 response_data = "text/html";
203}
204
205void pageaction::set_homeextra_macro (displayclass &disp, recptprotolistclass *protos,
206 ostream &logout) {
207
208 text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
209
210 recptprotolistclass::iterator rprotolist_here = protos->begin();
211 recptprotolistclass::iterator rprotolist_end = protos->end();
212 while (rprotolist_here != rprotolist_end) {
213 if ((*rprotolist_here).p != NULL) {
214
215 text_tarray collist;
216 comerror_t err;
217 (*rprotolist_here).p->get_collection_list (collist, err, logout);
218 if (err == noError) {
219 text_tarray::iterator collist_here = collist.begin();
220 text_tarray::iterator collist_end = collist.end();
221
222 int count = 0;
223 bool first = true;
224 while (collist_here != collist_end) {
225
226 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
227
228 if (cinfo != NULL) {
229 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
230
231 FilterResponse_t response;
232 text_tset metadata;
233 metadata.insert ("collectionname");
234 metadata.insert ("iconcollection");
235 metadata.insert ("iconcollectionsmall");
236 text_t collectionname = *collist_here;
237 text_t alt = collectionname;
238 if (get_info ("collection", *collist_here, metadata, false,
239 (*rprotolist_here).p, response, logout)) {
240 if (!response.docInfo[0].metadata["collectionname"].values[0].empty())
241 alt = response.docInfo[0].metadata["collectionname"].values[0];
242
243 if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty())
244 collectionname = "<img width=150 border=1 src=\""
245 + response.docInfo[0].metadata["iconcollectionsmall"].values[0]
246 + "\" alt=\"" + alt + "\">";
247 else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty())
248 collectionname = "<img width=150 border=1 src=\""
249 + response.docInfo[0].metadata["iconcollection"].values[0]
250 + "\" alt=\"" + alt + "\">";
251 else collectionname = alt;
252 }
253
254 if ((count%3 == 0) && (!first))
255 homeextra += "</tr><tr valign=top>\n";
256
257 text_t link = "<a href=\"_gwcgi_?a=p&p=about&c=" + *collist_here + "\">";
258 if (*collist_here == "chinese")
259 link = "<a href=\"_gwcgi_?a=p&p=about&l=zh&nw=u&c=" + *collist_here + "\">";
260 if (*collist_here == "arabic")
261 link = "<a href=\"_gwcgi_?a=p&p=about&l=ar&nw=u&c=" + *collist_here + "\">";
262
263 if (!cinfo->receptionist.empty())
264 link = "<a href=\"" + cinfo->receptionist + "\">";
265
266 homeextra += "<td>" + link + collectionname + "</a></td>\n";
267
268 count ++;
269 first = false;
270 }
271 }
272
273 collist_here ++;
274 }
275 for (; count%3 != 0; count ++) homeextra += "<td></td>\n";
276 homeextra += "</tr></table></center>\n";
277 disp.setmacro ("homeextra", "home", homeextra);
278 }
279 }
280 rprotolist_here ++;
281 }
282}
283
284void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
285 recptprotolistclass *protos, ostream &logout) {
286
287 // define_internal_macros sets the following macros:
288
289 // _numdocs_ the number of documents in the collection
290
291 // _builddate_ the date last built
292
293
294 // if page is "home"
295 // _homeextra_ this is the list of available collections and collection info
296 // to be displayed on the home page
297
298
299 // if page is "preferences"
300 // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
301
302 // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
303
304 // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
305
306 // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
307
308 // _encodingoption_ will be overridden to "" if chinese language interface isn't specified
309
310 // if page is "about"
311 // _textsubcollections_ the text on which subcollections make up the collection (if
312 // cross-collection searching is being used
313
314 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
315
316 // _numbrowseoptions_ the number of browsing options
317
318
319 // if page is "help"
320 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
321
322 // _numbrowseoptions_ the number of browsing options
323
324 // _topicreadingdocs_ this section of the help text differs depending on what type of
325 // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
326 // _texthelpreadingdocs_
327
328
329 if (recpt == NULL) {
330 logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
331 << " information about any receptionists. The method set_receptionist was\n"
332 << " probably not called from the module which instantiated this action.\n";
333 return;
334 }
335
336 text_t &arg_p = args["p"];
337 text_t &arg_c = args["c"];
338 ColInfoResponse_t *cinfo = NULL;
339
340 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
341 if (collectproto != NULL) {
342 cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
343
344 disp.setmacro ("numdocs", "Global", cinfo->numDocs);
345 unsigned long current_time = time(NULL);
346 unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
347 disp.setmacro ("builddate", "Global", builddate);
348 }
349
350 if (arg_p == "home") set_homeextra_macro (disp, protos, logout);
351
352 else if (arg_p == "preferences") {
353
354 // _collectionoption_
355
356 if (args["ccs"] == "1" && collectproto != NULL && (cinfo->ccsCols.size() > 1)) {
357 text_t collectionoption = "_textcollectionoption_";
358 text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
359 text_tarray::const_iterator col_end = cinfo->ccsCols.end();
360 int count = 0;
361 while (col_here != col_end) {
362 text_t colname;
363 if (*col_here == arg_c) {
364 colname = cinfo->collectionmeta["collectionname"];
365 } else {
366 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
367 if (this_cinfo == NULL) {col_here ++; continue;}
368 colname = this_cinfo->collectionmeta["collectionname"];
369 }
370
371 count ++;
372 collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
373 *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
374 colname + "<br>\n";
375 col_here ++;
376 }
377
378 if (count > 1)
379 disp.setmacro ("collectionoption", "preferences", collectionoption);
380 }
381
382 // _htmloptions_
383
384 text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
385 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
386 disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
387
388
389 // _PreferenceDocsFromWeb_
390
391 it = cinfo->format.find ("PreferenceDocsFromWeb");
392 if ((it == cinfo->format.end()) || ((*it).second == "true"))
393 disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
394 }
395
396 // _languageoption_
397 // this is kind of a hack (another one!!). note that there're potential
398 // problems here as no checking is done anywhere to make sure language
399 // is set to a valid value. this does allow us to set which languages
400 // should go in the preference selection box (from collect.cfg) however
401 // and that's sufficient for current requirements
402
403 // currently supported languages (_languageoption_ will default to all
404 // these languages unless PreferenceLanguages is set
405 text_tarray languages;
406 languages.push_back ("en");
407 languages.push_back ("fr");
408 languages.push_back ("de");
409 languages.push_back ("es");
410 languages.push_back ("mi");
411 languages.push_back ("zh");
412 languages.push_back ("ar");
413 text_tarray::const_iterator this_lang = languages.begin();
414 text_tarray::const_iterator end_lang = languages.end();
415
416 text_t languageoption = "_textlanguage_\n<select name=\"l\" onChange=\"updatel();\">\n";
417 it = cinfo->format.find ("PreferenceLanguages");
418 if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
419 text_tset pref_langs;
420 splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
421 if (pref_langs.size() > 1) {
422 while (this_lang != end_lang) {
423 if (pref_langs.find(*this_lang) != pref_langs.end())
424 languageoption += "_" + *this_lang + "languageoption_\n";
425 this_lang ++;
426 }
427 languageoption += "</select>\n";
428 disp.setmacro ("languageoption", "preferences", languageoption);
429 }
430
431 // _encodingoption_
432
433 if (pref_langs.find("zh") == pref_langs.end())
434 disp.setmacro ("encodingoption", "preferences", "");
435
436 } else {
437 while (this_lang != end_lang) {
438 languageoption += "_" + *this_lang + "languageoption_\n";
439 this_lang ++;
440 }
441 languageoption += "</select>\n";
442 disp.setmacro ("languageoption", "preferences", languageoption);
443 }
444
445 } else if (arg_p == "about" || arg_p == "help") {
446 if (collectproto == NULL) return;
447
448 // _textbrowseoptions_ and _numbrowseoptions_
449
450 FilterResponse_t response;
451 text_tset metadata;
452 metadata.insert ("Title");
453 bool getParents = false;
454 get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
455
456 disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
457
458 ResultDocInfo_tarray::iterator here = response.docInfo.begin();
459 ResultDocInfo_tarray::iterator end = response.docInfo.end();
460
461 // we're assuming that we've always got a search button
462 text_t shorttext = "<ul><li>_textSearchshort_\n";
463 text_t longtext = "_textSearchlong_";
464
465 while (here != end) {
466 text_t title = (*here).metadata["Title"].values[0];
467
468 text_t stext, ltext;
469 disp.expandstring ("help", "_text" + title + "short_", stext);
470 if (stext == ("_text" + title + "short_")) {
471 shorttext += "<li>_help:textdefaultshorttext_";
472 longtext += "_help:textdefaultlongtext_";
473 } else {
474 shorttext += "<li>" + stext;
475 longtext += "_help:text" + title + "long_";
476 }
477
478 here ++;
479 }
480 shorttext += "</ul>\n";
481 if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
482 else disp.setmacro ("textbrowseoptions", "help", longtext);
483
484 if (arg_p == "help") {
485
486 // _topicreadingdocs_ _textreadingdocs_ _texthelpreadingdocs_
487
488 // if HTML collection there's no how to read document text
489 text_tmap::const_iterator it = cinfo->format.find ("HelpNoDocs");
490 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
491 disp.setmacro ("topicreadingdocs", "help", "");
492 disp.setmacro ("texthelpreadingdocs", "help", "");
493 }
494 it = cinfo->format.find ("HelpBibDocs");
495 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
496 disp.setmacro ("texthelpreadingdocs", "help", "_bibtexthelpreadingdocs_");
497 disp.setmacro ("textreadingdocs", "help", "_bibtextreadingdocs_");
498 }
499 it = cinfo->format.find ("HelpBookDocs");
500 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
501 disp.setmacro ("texthelpreadingdocs", "help", "_booktexthelpreadingdocs_");
502 disp.setmacro ("textreadingdocs", "help", "_booktextreadingdocs_");
503 }
504
505 }
506 if (arg_p == "about") {
507
508 // _textsubcollections_
509 if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
510 text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
511 text_tarray::const_iterator here = cinfo->ccsCols.begin();
512 text_tarray::const_iterator end = cinfo->ccsCols.end();
513 bool first = true;
514 int count = 0;
515 while (here != end) {
516 if (*here == arg_c) {
517 if (!first) textsubcollections += "<br>";
518 textsubcollections += "\n" + cinfo->collectionmeta["collectionname"] + "\n";
519 } else {
520 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
521 if (this_cinfo == NULL) {here ++; continue;}
522 if (!first) textsubcollections += "<br>";
523 textsubcollections += "\n" + this_cinfo->collectionmeta["collectionname"] + "\n";
524 }
525 count ++;
526 first = false;
527 here ++;
528 }
529 textsubcollections += "_textsubcols2_";
530 if (count > 1)
531 disp.setmacro ("textsubcollections", "about", textsubcollections);
532 }
533 }
534 }
535}
536
537bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
538 browsermapclass * /*browsers*/, displayclass &disp,
539 outconvertclass &outconvert, ostream &textout,
540 ostream &/*logout*/) {
541
542 text_t &arg_p = args["p"];
543
544 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
545 << ("_" + arg_p + ":content_\n")
546 << ("_" + arg_p + ":footer_\n");
547
548 return true;
549}
550
551
552
553
554
Note: See TracBrowser for help on using the repository browser.