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