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