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

Last change on this file since 2370 was 2370, checked in by sjboddie, 23 years ago

The collector will now add a "This collection contains n documents"
sentence to the about text of each collection it builds.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 20.5 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 *********************************************************************/
25
26#include "OIDtools.h"
27#include "pageaction.h"
28#include "receptionist.h"
29#include <time.h>
30
31pageaction::pageaction () {
32
33 status_disabled = true;
34 collector_disabled = true;
35 recpt = NULL;
36
37 // this action uses cgi variables "a", "p", and "hp"
38 cgiarginfo arg_ainfo;
39 arg_ainfo.shortname = "a";
40 arg_ainfo.longname = "action";
41 arg_ainfo.multiplechar = true;
42 arg_ainfo.defaultstatus = cgiarginfo::weak;
43 arg_ainfo.argdefault = "p";
44 arg_ainfo.savedarginfo = cgiarginfo::must;
45 argsinfo.addarginfo (NULL, arg_ainfo);
46
47 arg_ainfo.shortname = "p";
48 arg_ainfo.longname = "page";
49 arg_ainfo.multiplechar = true;
50 arg_ainfo.defaultstatus = cgiarginfo::weak;
51 arg_ainfo.argdefault = "home";
52 arg_ainfo.savedarginfo = cgiarginfo::must;
53 argsinfo.addarginfo (NULL, arg_ainfo);
54
55 arg_ainfo.shortname = "hp";
56 arg_ainfo.longname = "html page";
57 arg_ainfo.multiplechar = true;
58 arg_ainfo.defaultstatus = cgiarginfo::weak;
59 arg_ainfo.argdefault = "";
60 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
61 argsinfo.addarginfo (NULL, arg_ainfo);
62}
63
64pageaction::~pageaction () {
65}
66
67bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
68 ostream &/*logout*/) {
69 // don't want to check anything yet.
70 return true;
71}
72
73void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
74 response_t &response,text_t &response_data,
75 ostream &/*logout*/) {
76 response = content;
77 response_data = "text/html";
78}
79
80void pageaction::set_homeextra_macro (displayclass &disp, recptprotolistclass *protos,
81 ostream &logout) {
82 text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
83 bool found_valid_col = false;
84
85 recptprotolistclass::iterator rprotolist_here = protos->begin();
86 recptprotolistclass::iterator rprotolist_end = protos->end();
87 while (rprotolist_here != rprotolist_end) {
88 if ((*rprotolist_here).p != NULL) {
89
90 text_tarray collist;
91 comerror_t err;
92 (*rprotolist_here).p->get_collection_list (collist, err, logout);
93 if (err == noError) {
94 text_tarray::iterator collist_here = collist.begin();
95 text_tarray::iterator collist_end = collist.end();
96
97 int count = 0;
98 bool first = true;
99 while (collist_here != collist_end) {
100 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
101
102 if (cinfo != NULL) {
103 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
104
105 text_t coll_type = "&ct=";
106 if (cinfo->buildType == "mgpp") {
107 coll_type += "1";
108 }
109 else {
110 coll_type += "0";
111 }
112 found_valid_col = true;
113 FilterResponse_t response;
114 text_tset metadata;
115 metadata.insert ("collectionname");
116 metadata.insert ("iconcollection");
117 metadata.insert ("iconcollectionsmall");
118 text_t collectionname = *collist_here;
119 text_t alt = collectionname;
120
121 if (get_info ("collection", *collist_here, metadata, false,
122 (*rprotolist_here).p, response, logout)) {
123 if (!response.docInfo[0].metadata["collectionname"].values[0].empty())
124 alt = response.docInfo[0].metadata["collectionname"].values[0];
125
126 text_t iconurl;
127 iconurl.clear();
128
129 if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty()) {
130 iconurl = response.docInfo[0].metadata["iconcollectionsmall"].values[0];
131 } else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty()) {
132 iconurl = response.docInfo[0].metadata["iconcollection"].values[0];
133 }
134
135 if (!iconurl.empty())
136 {
137 // check to see URL is local to colserver
138 text_t::iterator iconurl_head = iconurl.begin();
139 text_t iconhead = substr(iconurl_head,iconurl_head+16);
140 if (iconhead=="_httpcollection_")
141 {
142 // local and using _httpcollection_
143 text_t icontail = substr(iconurl_head+16,iconurl.end());
144 iconurl = "http://" + cinfo->httpdomain
145 + cinfo->httpprefix + "/collect/"
146 + *collist_here + "/" + icontail;
147 }
148 else if (iconurl[0]=='/')
149 {
150 // local but with full path
151 iconurl = "http://" + cinfo->httpdomain + iconurl;
152 }
153
154 collectionname
155 = "<img width=150 border=1 src=\"" + iconurl + "\" alt=\"" + alt + "\">";
156 }
157 else
158 {
159 collectionname = alt;
160 }
161
162 }
163 if ((count%3 == 0) && (!first))
164 homeextra += "</tr><tr valign=top>\n";
165
166 comerror_t err;
167 text_t optsite = "";
168 text_t site_name = (*rprotolist_here).p->get_site_name (err);
169 if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
170
171 text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + coll_type+"\">";
172
173 if (!cinfo->receptionist.empty())
174 link = "<a href=\"" + cinfo->receptionist + "\">";
175
176 homeextra += "<td>" + link + collectionname + "</a></td>\n";
177
178 count ++;
179 first = false;
180 }
181 }
182 collist_here ++;
183 }
184
185 for (; count%3 != 0; count ++) homeextra += "<td></td>\n";
186 }
187 }
188 homeextra += "</td></tr>\n<tr>\n";
189 rprotolist_here ++;
190 }
191
192 if (!found_valid_col) {
193 homeextra += "<td>No valid (i.e. built and public) collections are available</td>\n";
194 }
195 homeextra += "</tr></table></center>\n";
196 disp.setmacro ("homeextra", "home", homeextra);
197}
198
199void pageaction::set_collectionlist_macro (displayclass &disp, recptprotolistclass *protos,
200 ostream &logout) {
201
202 text_t collectionlist;
203 int count = 0;
204
205 recptprotolistclass::iterator rprotolist_here = protos->begin();
206 recptprotolistclass::iterator rprotolist_end = protos->end();
207 while (rprotolist_here != rprotolist_end) {
208 if ((*rprotolist_here).p != NULL) {
209
210 text_tarray collist;
211 comerror_t err;
212 (*rprotolist_here).p->get_collection_list (collist, err, logout);
213 if (err == noError) {
214 text_tarray::iterator collist_here = collist.begin();
215 text_tarray::iterator collist_end = collist.end();
216
217 while (collist_here != collist_end) {
218 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
219
220 if (cinfo != NULL) {
221 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
222
223 count ++;
224
225 text_t coll_type = "&ct=";
226 if (cinfo->buildType == "mgpp") {
227 coll_type += "1";
228 }
229 else {
230 coll_type += "0";
231 }
232 FilterResponse_t response;
233 text_tset metadata;
234 metadata.insert ("collectionname");
235 text_t collectionname = *collist_here;
236
237 if (get_info ("collection", *collist_here, metadata, false,
238 (*rprotolist_here).p, response, logout)) {
239 if (!response.docInfo[0].metadata["collectionname"].values[0].empty()) {
240 collectionname = response.docInfo[0].metadata["collectionname"].values[0];
241 }
242 }
243
244 comerror_t err;
245 text_t optsite = "";
246 text_t site_name = (*rprotolist_here).p->get_site_name (err);
247 if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
248
249 text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + coll_type+"\">";
250
251 if (!cinfo->receptionist.empty())
252 link = "<a href=\"" + cinfo->receptionist + "\">";
253
254 collectionlist += "<li>" + link + collectionname + "</a>\n";
255 }
256 }
257 collist_here ++;
258 }
259 }
260 }
261 rprotolist_here ++;
262 }
263
264 if (count == 1) {
265 collectionlist = "<p>This Greenstone installation contains 1 collection\n<ul>" +
266 collectionlist + "</ul>\n";
267 } else if (count > 1) {
268 collectionlist = "<p>This Greenstone installation contains " + text_t(count) +
269 " collections\n<ul>" + collectionlist + "</ul>\n";
270 }
271
272 disp.setmacro ("collectionlist", "homehelp", collectionlist);
273}
274
275void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
276 recptprotolistclass *protos, ostream &logout) {
277
278 // define_internal_macros sets the following macros:
279
280 // _numdocs_ the number of documents in the collection
281
282 // _builddate_ the date last built
283
284 // if page is "home"
285 // _homeextra_ this is the list of available collections and collection info
286 // to be displayed on the home page
287
288
289 // if page is "preferences"
290 // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
291
292 // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
293
294 // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
295
296 // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
297
298 // _encodingoption_ encodings to select from
299
300 // if page is "about"
301 // _textsubcollections_ the text on which subcollections make up the collection (if
302 // cross-collection searching is being used
303
304 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
305
306 // _numbrowseoptions_ the number of browsing options
307
308
309 // if page is "help"
310 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
311
312 // _numbrowseoptions_ the number of browsing options
313
314 // _topicreadingdocs_ this section of the help text differs depending on what type of
315 // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
316 // _texthelpreadingdocs_
317
318 // _textgocollector_ set to "" if collector is disabled in main.cfg
319 // _textgoadmin_ set to "" if status is disabled in main.cfg
320
321
322 // if page is "homehelp"
323 // _collectionlist_ list of available collections to be displayed on the homehelp page
324
325 if (recpt == NULL) {
326 logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
327 << " information about any receptionists. The method set_receptionist was\n"
328 << " probably not called from the module which instantiated this action.\n";
329 return;
330 }
331
332 text_t &arg_p = args["p"];
333 text_t &arg_c = args["c"];
334 ColInfoResponse_t *cinfo = NULL;
335
336 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
337 if (collectproto != NULL) {
338 cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
339
340 disp.setmacro ("numdocs", "Global", cinfo->numDocs);
341 unsigned long current_time = time(NULL);
342 unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
343 disp.setmacro ("builddate", "Global", builddate);
344
345 text_t numbytes;
346 if ((cinfo->numBytes/(1024*1024)) > 1) {
347 numbytes = (text_t)(cinfo->numBytes/(1024*1024)) + " Mb";
348 } else if ((cinfo->numBytes/1024) > 1) {
349 numbytes = (text_t)(cinfo->numBytes/1024) + " kb";
350 } else {
351 numbytes = (text_t)cinfo->numBytes + " bytes";
352 }
353 disp.setmacro("numbytes", "Global", numbytes);
354 }
355
356 if (arg_p == "home") {
357 set_homeextra_macro (disp, protos, logout);
358 if (status_disabled) disp.setmacro ("textgoadmin", "home", "");
359 if (collector_disabled) disp.setmacro ("textgocollector", "home", "");
360 }
361
362 else if (arg_p == "preferences") {
363 if (collectproto == NULL) {return;}
364 // _collectionoption_
365
366 if (args["ccs"] == "1" && collectproto != NULL && (cinfo->ccsCols.size() > 1)) {
367 text_t collectionoption = "_textcollectionoption_";
368 text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
369 text_tarray::const_iterator col_end = cinfo->ccsCols.end();
370 int count = 0;
371 while (col_here != col_end) {
372 text_t colname;
373 if (*col_here == arg_c) {
374 colname = cinfo->collectionmeta["collectionname"];
375 } else {
376 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
377 if (this_cinfo == NULL) {col_here ++; continue;}
378 colname = this_cinfo->collectionmeta["collectionname"];
379 }
380
381 count ++;
382 collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
383 *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
384 colname + "<br>\n";
385 col_here ++;
386 }
387
388 if (count > 1)
389 disp.setmacro ("collectionoption", "preferences", collectionoption);
390 }
391
392 // _htmloptions_
393
394 text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
395 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
396 disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
397
398
399 // _PreferenceDocsFromWeb_
400
401 it = cinfo->format.find ("PreferenceDocsFromWeb");
402 if ((it == cinfo->format.end()) || ((*it).second == "true"))
403 disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
404 }
405
406 // _languageoption_
407 // Create the "interface language" selection box for the preferences page.
408 // You can use something like "format PreferenceLanguages en|fr|zn" from within
409 // a collect.cfg file to use only a subset of the available languages for
410 // any given collection. This facility is kind of ugly though and should be
411 // replaced by something better when the configuration files are tidied up (as
412 // should all the other "format Preference..." options).
413
414 text_t &arg_l = args["l"];
415 const recptconf &configinfo = recpt->get_configinfo();
416 // put languages in another map to sort them by longname
417 text_tmap languages;
418 languageinfo_tmap::const_iterator thislang = configinfo.languages.begin();
419 languageinfo_tmap::const_iterator endlang = configinfo.languages.end();
420 while (thislang != endlang) {
421 languages[(*thislang).second.longname] = (*thislang).first;
422 thislang++;
423 }
424 text_tmap::iterator tlang = languages.begin();
425 text_tmap::iterator elang = languages.end();
426
427 text_t languageoption;
428 it = cinfo->format.find ("PreferenceLanguages");
429 if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
430 text_tset pref_langs;
431 splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
432 if (pref_langs.size() > 1) {
433 while (tlang != elang) {
434 if (pref_langs.find((*tlang).second) != pref_langs.end()) {
435 languageoption += "<option value=\"" + (*tlang).second + "\"";
436 if ((*tlang).second == arg_l) languageoption += " selected";
437 languageoption += ">" + (*tlang).first + "\n";
438 }
439 tlang ++;
440 }
441 }
442
443 } else {
444 while (tlang != elang) {
445 languageoption += "<option value=\"" + (*tlang).second + "\"";
446 if ((*tlang).second == arg_l) languageoption += " selected";
447 languageoption += ">" + (*tlang).first + "\n";
448 tlang ++;
449 }
450 }
451 if (!languageoption.empty()) {
452 languageoption = "<select name=\"l\" onChange=\"updatel();\">\n" + languageoption;
453 languageoption += "</select>\n";
454 disp.setmacro ("languageoption", "preferences", languageoption);
455 }
456
457 // _encodingoption_
458 // create the "encoding" selection box for the preferences page
459 if (configinfo.encodings.size() > 1) {
460 text_t &arg_w = args["w"];
461 text_t encodingoption;
462 text_tmap::const_iterator thisenc = configinfo.encodings.begin();
463 text_tmap::const_iterator endenc = configinfo.encodings.end();
464 while (thisenc != endenc) {
465 encodingoption += "<option value=\"" + (*thisenc).second + "\"";
466 if ((*thisenc).second == arg_w) encodingoption += " selected";
467 encodingoption += ">" + (*thisenc).first + "\n";
468 thisenc ++;
469 }
470
471 encodingoption = "<select name=\"w\" onChange=\"updatew();\">\n" + encodingoption;
472 encodingoption += "</select>\n";
473 disp.setmacro ("encodingoption", "preferences", encodingoption);
474 }
475
476 } else if (arg_p == "about" || arg_p == "help") {
477 if (collectproto == NULL) return;
478
479 // _textbrowseoptions_ and _numbrowseoptions_
480
481 FilterResponse_t response;
482 text_tset metadata;
483 metadata.insert ("Title");
484 bool getParents = false;
485 get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
486
487 disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
488
489 ResultDocInfo_tarray::iterator here = response.docInfo.begin();
490 ResultDocInfo_tarray::iterator end = response.docInfo.end();
491
492 // we're assuming that we've always got a search button
493 text_t shorttext = "<ul><li>_textSearchshort_\n";
494 text_t longtext = "_textSearchlong_";
495
496 while (here != end) {
497 text_t title = (*here).metadata["Title"].values[0];
498
499 text_t stext, ltext;
500 disp.expandstring ("help", "_text" + title + "short_", stext);
501 if (stext == ("_text" + title + "short_")) {
502 shorttext += "<li>_help:textdefaultshorttext_";
503 longtext += "_help:textdefaultlongtext_";
504 } else {
505 shorttext += "<li>_help:text" + title + "short_";
506 longtext += "_help:text" + title + "long_";
507 }
508
509 here ++;
510 }
511 shorttext += "</ul>\n";
512 if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
513 else disp.setmacro ("textbrowseoptions", "help", longtext);
514
515 if (arg_p == "help") {
516
517 // _topicreadingdocs_ _textreadingdocs_ _texthelpreadingdocs_
518
519 // if HTML collection there's no how to read document text
520 text_tmap::const_iterator it = cinfo->format.find ("HelpNoDocs");
521 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
522 disp.setmacro ("topicreadingdocs", "help", "");
523 disp.setmacro ("texthelpreadingdocs", "help", "");
524 }
525 it = cinfo->format.find ("HelpBibDocs");
526 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
527 disp.setmacro ("texthelpreadingdocs", "help", "_bibtexthelpreadingdocs_");
528 disp.setmacro ("textreadingdocs", "help", "_bibtextreadingdocs_");
529 }
530 it = cinfo->format.find ("HelpBookDocs");
531 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
532 disp.setmacro ("texthelpreadingdocs", "help", "_booktexthelpreadingdocs_");
533 disp.setmacro ("textreadingdocs", "help", "_booktextreadingdocs_");
534 }
535
536 }
537 if (arg_p == "about") {
538
539 // _textsubcollections_
540 if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
541 text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
542 text_tarray::const_iterator here = cinfo->ccsCols.begin();
543 text_tarray::const_iterator end = cinfo->ccsCols.end();
544 bool first = true;
545 int count = 0;
546 while (here != end) {
547 if (*here == arg_c) {
548 if (!first) textsubcollections += "<br>";
549 textsubcollections += "\n" + cinfo->collectionmeta["collectionname"] + "\n";
550 } else {
551 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
552 if (this_cinfo == NULL) {here ++; continue;}
553 if (!first) textsubcollections += "<br>";
554 textsubcollections += "\n" + this_cinfo->collectionmeta["collectionname"] + "\n";
555 }
556 count ++;
557 first = false;
558 here ++;
559 }
560 textsubcollections += "_textsubcols2_";
561 if (count > 1)
562 disp.setmacro ("textsubcollections", "about", textsubcollections);
563 }
564 }
565
566 } else if (arg_p == "homehelp") {
567
568 set_collectionlist_macro (disp, protos, logout);
569
570 }
571}
572
573bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
574 browsermapclass * /*browsers*/, displayclass &disp,
575 outconvertclass &outconvert, ostream &textout,
576 ostream &/*logout*/) {
577
578 text_t &arg_p = args["p"];
579
580 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
581 << ("_" + arg_p + ":content_\n")
582 << ("_" + arg_p + ":footer_\n");
583
584 return true;
585}
586
587void pageaction::configure (const text_t &key, const text_tarray &cfgline) {
588 if ((key == "status") && (cfgline.size() == 1) &&
589 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
590 status_disabled = false;
591 } else if ((key == "collector") && (cfgline.size() == 1) &&
592 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
593 collector_disabled = false;
594 } else {
595 // call the parent class to deal with the things which
596 // are not dealt with here
597 action::configure (key, cfgline);
598 }
599}
Note: See TracBrowser for help on using the repository browser.