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