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

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

Made a start on tidying up the main.cfg configuration file and adding a
few more options to it. Some of the options I've added to the file but
have yet to implement.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 16.0 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
83 text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
84 bool found_valid_col = false;
85
86 recptprotolistclass::iterator rprotolist_here = protos->begin();
87 recptprotolistclass::iterator rprotolist_end = protos->end();
88 while (rprotolist_here != rprotolist_end) {
89 if ((*rprotolist_here).p != NULL) {
90
91 text_tarray collist;
92 comerror_t err;
93 (*rprotolist_here).p->get_collection_list (collist, err, logout);
94 if (err == noError) {
95 text_tarray::iterator collist_here = collist.begin();
96 text_tarray::iterator collist_end = collist.end();
97
98 int count = 0;
99 bool first = true;
100 while (collist_here != collist_end) {
101 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
102
103 if (cinfo != NULL) {
104 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
105
106 found_valid_col = true;
107 FilterResponse_t response;
108 text_tset metadata;
109 metadata.insert ("collectionname");
110 metadata.insert ("iconcollection");
111 metadata.insert ("iconcollectionsmall");
112 text_t collectionname = *collist_here;
113 text_t alt = collectionname;
114 if (get_info ("collection", *collist_here, metadata, false,
115 (*rprotolist_here).p, response, logout)) {
116 if (!response.docInfo[0].metadata["collectionname"].values[0].empty())
117 alt = response.docInfo[0].metadata["collectionname"].values[0];
118
119 if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty())
120 collectionname = "<img width=150 border=1 src=\""
121 + response.docInfo[0].metadata["iconcollectionsmall"].values[0]
122 + "\" alt=\"" + alt + "\">";
123 else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty())
124 collectionname = "<img width=150 border=1 src=\""
125 + response.docInfo[0].metadata["iconcollection"].values[0]
126 + "\" alt=\"" + alt + "\">";
127 else collectionname = alt;
128 }
129 if ((count%3 == 0) && (!first))
130 homeextra += "</tr><tr valign=top>\n";
131
132 text_t link = "<a href=\"_gwcgi_?a=p&p=about&c=" + *collist_here + "\">";
133 if (*collist_here == "chinese")
134 link = "<a href=\"_gwcgi_?a=p&p=about&l=zh&nw=u&c=" + *collist_here + "\">";
135 if (*collist_here == "arabic")
136 link = "<a href=\"_gwcgi_?a=p&p=about&l=ar&nw=u&c=" + *collist_here + "\">";
137
138 if (!cinfo->receptionist.empty())
139 link = "<a href=\"" + cinfo->receptionist + "\">";
140
141 homeextra += "<td>" + link + collectionname + "</a></td>\n";
142
143 count ++;
144 first = false;
145 }
146 }
147 collist_here ++;
148 }
149
150 // disp.setmacro ("homeextra", "home", homeextra);
151 for (; count%3 != 0; count ++) homeextra += "<td></td>\n";
152 }
153 }
154 homeextra += "</td></tr>\n<tr>\n";
155 rprotolist_here ++;
156 }
157
158 if (!found_valid_col) {
159 homeextra += "<td>No valid (i.e. built and public) collections are available</td>\n";
160 }
161 homeextra += "</tr></table></center>\n";
162 disp.setmacro ("homeextra", "home", homeextra);
163}
164
165void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
166 recptprotolistclass *protos, ostream &logout) {
167
168 // define_internal_macros sets the following macros:
169
170 // _numdocs_ the number of documents in the collection
171
172 // _builddate_ the date last built
173
174
175 // if page is "home"
176 // _homeextra_ this is the list of available collections and collection info
177 // to be displayed on the home page
178
179
180 // if page is "preferences"
181 // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
182
183 // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
184
185 // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
186
187 // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
188
189 // _encodingoption_ will be overridden to "" if chinese language interface isn't specified
190
191 // if page is "about"
192 // _textsubcollections_ the text on which subcollections make up the collection (if
193 // cross-collection searching is being used
194
195 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
196
197 // _numbrowseoptions_ the number of browsing options
198
199
200 // if page is "help"
201 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
202
203 // _numbrowseoptions_ the number of browsing options
204
205 // _topicreadingdocs_ this section of the help text differs depending on what type of
206 // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
207 // _texthelpreadingdocs_
208
209 // _textgocollector_ set to "" if collector is disabled in main.cfg
210 // _textgoadmin_ set to "" if status is disabled in main.cfg
211
212
213 if (recpt == NULL) {
214 logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
215 << " information about any receptionists. The method set_receptionist was\n"
216 << " probably not called from the module which instantiated this action.\n";
217 return;
218 }
219
220 text_t &arg_p = args["p"];
221 text_t &arg_c = args["c"];
222 ColInfoResponse_t *cinfo = NULL;
223
224 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
225 if (collectproto != NULL) {
226 cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
227
228 disp.setmacro ("numdocs", "Global", cinfo->numDocs);
229 unsigned long current_time = time(NULL);
230 unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
231 disp.setmacro ("builddate", "Global", builddate);
232 }
233
234 if (arg_p == "home") {
235 set_homeextra_macro (disp, protos, logout);
236 if (status_disabled) disp.setmacro ("textgoadmin", "home", "");
237 if (collector_disabled) disp.setmacro ("textgocollector", "home", "");
238 }
239
240 else if (arg_p == "preferences") {
241
242 // _collectionoption_
243
244 if (args["ccs"] == "1" && collectproto != NULL && (cinfo->ccsCols.size() > 1)) {
245 text_t collectionoption = "_textcollectionoption_";
246 text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
247 text_tarray::const_iterator col_end = cinfo->ccsCols.end();
248 int count = 0;
249 while (col_here != col_end) {
250 text_t colname;
251 if (*col_here == arg_c) {
252 colname = cinfo->collectionmeta["collectionname"];
253 } else {
254 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
255 if (this_cinfo == NULL) {col_here ++; continue;}
256 colname = this_cinfo->collectionmeta["collectionname"];
257 }
258
259 count ++;
260 collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
261 *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
262 colname + "<br>\n";
263 col_here ++;
264 }
265
266 if (count > 1)
267 disp.setmacro ("collectionoption", "preferences", collectionoption);
268 }
269
270 // _htmloptions_
271
272 text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
273 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
274 disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
275
276
277 // _PreferenceDocsFromWeb_
278
279 it = cinfo->format.find ("PreferenceDocsFromWeb");
280 if ((it == cinfo->format.end()) || ((*it).second == "true"))
281 disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
282 }
283
284 // _languageoption_
285 // this is kind of a hack (another one!!). note that there're potential
286 // problems here as no checking is done anywhere to make sure language
287 // is set to a valid value. this does allow us to set which languages
288 // should go in the preference selection box (from collect.cfg) however
289 // and that's sufficient for current requirements
290
291 // currently supported languages (_languageoption_ will default to all
292 // these languages unless PreferenceLanguages is set
293 text_tarray languages;
294 languages.push_back ("en");
295 languages.push_back ("fr");
296 languages.push_back ("de");
297 languages.push_back ("es");
298 languages.push_back ("mi");
299 languages.push_back ("zh");
300 languages.push_back ("ar");
301 languages.push_back ("pt");
302 languages.push_back ("nl");
303 text_tarray::const_iterator this_lang = languages.begin();
304 text_tarray::const_iterator end_lang = languages.end();
305
306 text_t languageoption = "_textlanguage_\n<select name=\"l\" onChange=\"updatel();\">\n";
307 it = cinfo->format.find ("PreferenceLanguages");
308 if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
309 text_tset pref_langs;
310 splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
311 if (pref_langs.size() > 1) {
312 while (this_lang != end_lang) {
313 if (pref_langs.find(*this_lang) != pref_langs.end())
314 languageoption += "_" + *this_lang + "languageoption_\n";
315 this_lang ++;
316 }
317 languageoption += "</select>\n";
318 disp.setmacro ("languageoption", "preferences", languageoption);
319 }
320
321 // _encodingoption_
322
323 if (pref_langs.find("zh") == pref_langs.end())
324 disp.setmacro ("encodingoption", "preferences", "");
325
326 } else {
327 while (this_lang != end_lang) {
328 languageoption += "_" + *this_lang + "languageoption_\n";
329 this_lang ++;
330 }
331 languageoption += "</select>\n";
332 disp.setmacro ("languageoption", "preferences", languageoption);
333 }
334
335 } else if (arg_p == "about" || arg_p == "help") {
336 if (collectproto == NULL) return;
337
338 // _textbrowseoptions_ and _numbrowseoptions_
339
340 FilterResponse_t response;
341 text_tset metadata;
342 metadata.insert ("Title");
343 bool getParents = false;
344 get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
345
346 disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
347
348 ResultDocInfo_tarray::iterator here = response.docInfo.begin();
349 ResultDocInfo_tarray::iterator end = response.docInfo.end();
350
351 // we're assuming that we've always got a search button
352 text_t shorttext = "<ul><li>_textSearchshort_\n";
353 text_t longtext = "_textSearchlong_";
354
355 while (here != end) {
356 text_t title = (*here).metadata["Title"].values[0];
357
358 text_t stext, ltext;
359 disp.expandstring ("help", "_text" + title + "short_", stext);
360 if (stext == ("_text" + title + "short_")) {
361 shorttext += "<li>_help:textdefaultshorttext_";
362 longtext += "_help:textdefaultlongtext_";
363 } else {
364 shorttext += "<li>_help:text" + title + "short_";
365 longtext += "_help:text" + title + "long_";
366 }
367
368 here ++;
369 }
370 shorttext += "</ul>\n";
371 if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
372 else disp.setmacro ("textbrowseoptions", "help", longtext);
373
374 if (arg_p == "help") {
375
376 // _topicreadingdocs_ _textreadingdocs_ _texthelpreadingdocs_
377
378 // if HTML collection there's no how to read document text
379 text_tmap::const_iterator it = cinfo->format.find ("HelpNoDocs");
380 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
381 disp.setmacro ("topicreadingdocs", "help", "");
382 disp.setmacro ("texthelpreadingdocs", "help", "");
383 }
384 it = cinfo->format.find ("HelpBibDocs");
385 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
386 disp.setmacro ("texthelpreadingdocs", "help", "_bibtexthelpreadingdocs_");
387 disp.setmacro ("textreadingdocs", "help", "_bibtextreadingdocs_");
388 }
389 it = cinfo->format.find ("HelpBookDocs");
390 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
391 disp.setmacro ("texthelpreadingdocs", "help", "_booktexthelpreadingdocs_");
392 disp.setmacro ("textreadingdocs", "help", "_booktextreadingdocs_");
393 }
394
395 }
396 if (arg_p == "about") {
397
398 // _textsubcollections_
399 if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
400 text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
401 text_tarray::const_iterator here = cinfo->ccsCols.begin();
402 text_tarray::const_iterator end = cinfo->ccsCols.end();
403 bool first = true;
404 int count = 0;
405 while (here != end) {
406 if (*here == arg_c) {
407 if (!first) textsubcollections += "<br>";
408 textsubcollections += "\n" + cinfo->collectionmeta["collectionname"] + "\n";
409 } else {
410 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
411 if (this_cinfo == NULL) {here ++; continue;}
412 if (!first) textsubcollections += "<br>";
413 textsubcollections += "\n" + this_cinfo->collectionmeta["collectionname"] + "\n";
414 }
415 count ++;
416 first = false;
417 here ++;
418 }
419 textsubcollections += "_textsubcols2_";
420 if (count > 1)
421 disp.setmacro ("textsubcollections", "about", textsubcollections);
422 }
423 }
424 }
425}
426
427bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
428 browsermapclass * /*browsers*/, displayclass &disp,
429 outconvertclass &outconvert, ostream &textout,
430 ostream &/*logout*/) {
431
432 text_t &arg_p = args["p"];
433
434 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
435 << ("_" + arg_p + ":content_\n")
436 << ("_" + arg_p + ":footer_\n");
437
438 return true;
439}
440
441void pageaction::configure (const text_t &key, const text_tarray &cfgline) {
442 if ((key == "status") && (cfgline.size() == 1) &&
443 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
444 status_disabled = false;
445 } else if ((key == "collector") && (cfgline.size() == 1) &&
446 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
447 collector_disabled = false;
448 } else {
449 // call the parent class to deal with the things which
450 // are not dealt with here
451 action::configure (key, cfgline);
452 }
453}
Note: See TracBrowser for help on using the repository browser.