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

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

bug in generating "how to find information" text for about pages

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