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

Last change on this file since 722 was 722, checked in by davidb, 25 years ago

Collection building support through web pages
and internal and external link handling for collection documents

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