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

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

some hacks to make nzdl home page look right

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