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

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

now defaults to home page

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