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

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

changes to the home and about pages

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/**********************************************************************
2 *
3 * pageaction.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: pageaction.cpp 471 1999-08-25 04:48:43Z sjboddie $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.11 1999/08/25 04:48:43 sjboddie
15 changes to the home and about pages
16
17 Revision 1.10 1999/08/11 23:29:43 sjboddie
18 added support for html classifier (i.e. the hp argument)
19
20 Revision 1.9 1999/08/03 03:29:47 sjboddie
21 added ability to set receptionist from collect.cfg
22
23 Revision 1.8 1999/07/30 02:24:44 sjboddie
24 added collectinfo argument to some functions
25
26 Revision 1.7 1999/06/24 05:12:24 sjboddie
27 lots of small changes
28
29 Revision 1.6 1999/06/10 00:39:16 sjboddie
30 navigation bar is no longer written out for every page (it should
31 be included in the _content_ macro of pages wanting to display it).
32
33 Revision 1.5 1999/06/08 04:29:35 sjboddie
34 added argsinfo to the call to check_cgiargs to make it easy to set
35 args to their default if they're found to be screwed up
36
37 Revision 1.4 1999/02/28 20:00:14 rjmcnab
38
39
40 Fixed a few things.
41
42 Revision 1.3 1999/02/25 21:58:58 rjmcnab
43
44 Merged sources.
45
46 Revision 1.2 1999/02/21 22:33:54 rjmcnab
47
48 Lots of stuff :-)
49
50 Revision 1.1 1999/02/12 02:40:17 sjboddie
51
52 Added page action
53
54 */
55
56#include "OIDtools.h"
57#include "pageaction.h"
58#include "receptionist.h"
59#include <time.h>
60
61pageaction::pageaction () {
62
63 recpt = NULL;
64
65 // this action uses cgi variables "a", "p", and "hp"
66 cgiarginfo arg_ainfo;
67 arg_ainfo.shortname = "a";
68 arg_ainfo.longname = "action";
69 arg_ainfo.multiplechar = true;
70 arg_ainfo.defaultstatus = cgiarginfo::weak;
71 arg_ainfo.argdefault = "p";
72 arg_ainfo.savedarginfo = cgiarginfo::must;
73 argsinfo.addarginfo (NULL, arg_ainfo);
74
75 arg_ainfo.shortname = "p";
76 arg_ainfo.longname = "page";
77 arg_ainfo.multiplechar = true;
78 arg_ainfo.defaultstatus = cgiarginfo::weak;
79 arg_ainfo.argdefault = "about";
80 arg_ainfo.savedarginfo = cgiarginfo::can;
81 argsinfo.addarginfo (NULL, arg_ainfo);
82
83 arg_ainfo.shortname = "hp";
84 arg_ainfo.longname = "html page";
85 arg_ainfo.multiplechar = true;
86 arg_ainfo.defaultstatus = cgiarginfo::weak;
87 arg_ainfo.argdefault = "";
88 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
89 argsinfo.addarginfo (NULL, arg_ainfo);
90}
91
92pageaction::~pageaction () {
93}
94
95bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
96 ostream &/*logout*/) {
97 // don't want to check anything yet.
98 return true;
99}
100
101void pageaction::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
102 text_t &response_data, ostream &/*logout*/) {
103 response = content;
104 response_data = "text/html";
105}
106
107
108// define all the macros which might be used by other actions
109// to produce pages.
110void pageaction::define_external_macros (const ColInfoResponse_t &/*collectinfo*/, displayclass &/*disp*/,
111 cgiargsclass &/*args*/, recptproto */*collectproto*/,
112 ostream &/*logout*/) {
113}
114
115
116void pageaction::define_internal_macros (const ColInfoResponse_t &collectinfo, displayclass &disp,
117 cgiargsclass &args, recptproto *collectproto,
118 ostream &logout) {
119
120 // define_internal_macros sets the following macros:
121
122 // if page is "home"
123 // _homeextra_ this is the list of available collections and collection info
124 // to be displayed on the home page
125
126
127 // if page is "about"
128 // _numdocs_ the number of documents in the collection
129
130 // _builddate_ the date last built
131
132 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
133
134 // _numbrowseoptions_ the number of browsing options
135
136
137 // if page is "help"
138 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
139
140 // _numbrowseoptions_ the number of browsing options
141
142
143 text_t &arg_p = args["p"];
144
145 if (arg_p == "home") {
146 // make sure we know about a receptionist
147 if (recpt == NULL) {
148 logout << "The page action does not contain information\n"
149 << "about any receptionists. The method set_receptionist\n"
150 << "was probably not called from the module which instantiated\n"
151 << "this page action.\n";
152 return;
153 }
154
155 unsigned long current_time = time(NULL);
156 text_t homeextra;
157
158 recptprotolistclass *rprotolist = recpt->get_recptprotolist_ptr ();
159 if (rprotolist == NULL) return;
160
161 recptprotolistclass::iterator rprotolist_here = rprotolist->begin();
162 recptprotolistclass::iterator rprotolist_end = rprotolist->end();
163 while (rprotolist_here != rprotolist_end) {
164 if ((*rprotolist_here).p != NULL) {
165 text_tarray collist;
166 comerror_t err;
167 (*rprotolist_here).p->get_collection_list (collist, err, logout);
168 if (err == noError) {
169 text_tarray::iterator collist_here = collist.begin();
170 text_tarray::iterator collist_end = collist.end();
171
172 homeextra += "<dl>\n";
173
174 FilterResponse_t response;
175 text_tarray metadata;
176 metadata.push_back ("collectionname");
177
178 while (collist_here != collist_end) {
179 text_t collectionname = *collist_here;
180 if (get_info ("collection", *collist_here, metadata, false, (*rprotolist_here).p, response, logout))
181 collectionname = response.docInfo[0].metadata[0].values[0];
182
183 ColInfoResponse_t cinfo;
184 (*rprotolist_here).p->get_collectinfo (*collist_here, cinfo, err, logout);
185 if (err == noError) {
186 text_t link = "<a href=\"_gwcgi_?a=p&p=about&c=" + *collist_here + "\">";
187 if (!cinfo.receptionist.empty())
188 link = "<a href=\"" + cinfo.receptionist + "?a=p&p=about&c=" + *collist_here + "\">";
189
190 homeextra += "<dt>" + link + collectionname + "</a></dt>\n";
191 homeextra += "<dd>";
192 if (cinfo.numDocs != 0) homeextra += text_t(cinfo.numDocs) + "_documents_";
193 if (cinfo.numWords != 0) homeextra += text_t(cinfo.numWords) + "_words_";
194 unsigned long last_update = (current_time - cinfo.buildDate) / 86400;
195 homeextra += "_lastupdate_ " + text_t(last_update) + " _ago_</dd>\n";
196 }
197 collist_here ++;
198 }
199 homeextra += "</dl>\n";
200 disp.setmacro ("homeextra", "home", homeextra);
201 }
202 }
203 rprotolist_here ++;
204 }
205 } else if (arg_p == "about") {
206 disp.setmacro ("numdocs", "about", collectinfo.numDocs);
207 unsigned long current_time = time(NULL);
208 unsigned long builddate = (current_time - collectinfo.buildDate) / 86400;
209 disp.setmacro ("builddate", "about", builddate);
210 }
211
212 if (arg_p == "about" || arg_p == "help") {
213
214 // _textbrowseoptions_ and _numbrowseoptions_
215
216 FilterResponse_t response;
217 text_tarray metadata;
218 metadata.push_back ("Title");
219 bool getParents = false;
220 get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
221
222 disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
223
224 ResultDocInfo_tarray::const_iterator here = response.docInfo.begin();
225 ResultDocInfo_tarray::const_iterator end = response.docInfo.end();
226
227 // we're assuming that we've always got a search button
228 text_t shorttext = "<ul><li>_textSearchshort_\n";
229 text_t longtext = "_textSearchlong_";
230
231 while (here != end) {
232 const text_t &title = (*here).metadata[0].values[0];
233 shorttext += "<li>_text" + title + "short_\n";
234 longtext += "_text" + title + "long_";
235 here ++;
236 }
237 shorttext += "</ul>\n";
238 disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
239 }
240}
241
242bool pageaction::do_action (cgiargsclass &args, const ColInfoResponse_t &/*collectinfo*/,
243 recptproto */*collectproto*/, displayclass &disp,
244 outconvertclass &outconvert, ostream &textout,
245 ostream &/*logout*/) {
246
247 text_t &arg_p = args["p"];
248
249 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
250 << ("_" + arg_p + ":content_\n")
251 << ("_" + arg_p + ":footer_\n");
252
253 return true;
254}
Note: See TracBrowser for help on using the repository browser.