/********************************************************************** * * pageaction.cpp -- * Copyright (C) 1999 The New Zealand Digital Library Project * * A component of the Greenstone digital library software * from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: pageaction.cpp 649 1999-10-10 08:14:12Z sjboddie $ * *********************************************************************/ /* $Log$ Revision 1.16 1999/10/10 08:14:09 sjboddie - metadata now returns mp rather than array - redesigned browsing support (although it's not finished so won't currently work ;-) Revision 1.15 1999/09/17 04:46:05 sjboddie fixed a couple of problems with 'unknown' classifier Revision 1.14 1999/09/07 23:08:09 rjmcnab Removed some compiler warnings Revision 1.13 1999/09/07 04:56:57 sjboddie added GPL notice Revision 1.12 1999/09/02 00:26:43 rjmcnab made the p cgi argument always saved in the compressed arguments Revision 1.11 1999/08/25 04:48:43 sjboddie changes to the home and about pages Revision 1.10 1999/08/11 23:29:43 sjboddie added support for html classifier (i.e. the hp argument) Revision 1.9 1999/08/03 03:29:47 sjboddie added ability to set receptionist from collect.cfg Revision 1.8 1999/07/30 02:24:44 sjboddie added collectinfo argument to some functions Revision 1.7 1999/06/24 05:12:24 sjboddie lots of small changes Revision 1.6 1999/06/10 00:39:16 sjboddie navigation bar is no longer written out for every page (it should be included in the _content_ macro of pages wanting to display it). Revision 1.5 1999/06/08 04:29:35 sjboddie added argsinfo to the call to check_cgiargs to make it easy to set args to their default if they're found to be screwed up Revision 1.4 1999/02/28 20:00:14 rjmcnab Fixed a few things. Revision 1.3 1999/02/25 21:58:58 rjmcnab Merged sources. Revision 1.2 1999/02/21 22:33:54 rjmcnab Lots of stuff :-) Revision 1.1 1999/02/12 02:40:17 sjboddie Added page action */ #include "OIDtools.h" #include "pageaction.h" #include "receptionist.h" #include pageaction::pageaction () { recpt = NULL; // this action uses cgi variables "a", "p", and "hp" cgiarginfo arg_ainfo; arg_ainfo.shortname = "a"; arg_ainfo.longname = "action"; arg_ainfo.multiplechar = true; arg_ainfo.defaultstatus = cgiarginfo::weak; arg_ainfo.argdefault = "p"; arg_ainfo.savedarginfo = cgiarginfo::must; argsinfo.addarginfo (NULL, arg_ainfo); arg_ainfo.shortname = "p"; arg_ainfo.longname = "page"; arg_ainfo.multiplechar = true; arg_ainfo.defaultstatus = cgiarginfo::weak; arg_ainfo.argdefault = "about"; arg_ainfo.savedarginfo = cgiarginfo::must; argsinfo.addarginfo (NULL, arg_ainfo); arg_ainfo.shortname = "hp"; arg_ainfo.longname = "html page"; arg_ainfo.multiplechar = true; arg_ainfo.defaultstatus = cgiarginfo::weak; arg_ainfo.argdefault = ""; arg_ainfo.savedarginfo = cgiarginfo::mustnot; argsinfo.addarginfo (NULL, arg_ainfo); } pageaction::~pageaction () { } bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/, ostream &/*logout*/) { // don't want to check anything yet. return true; } void pageaction::get_cgihead_info (cgiargsclass &/*args*/, response_t &response, text_t &response_data, ostream &/*logout*/) { response = content; response_data = "text/html"; } void pageaction::define_internal_macros (const ColInfoResponse_t &collectinfo, displayclass &disp, cgiargsclass &args, recptproto *collectproto, ostream &logout) { // define_internal_macros sets the following macros: // if page is "home" // _homeextra_ this is the list of available collections and collection info // to be displayed on the home page // if page is "about" // _numdocs_ the number of documents in the collection // _builddate_ the date last built // _textbrowseoptions_ the 'how to find information' text in the about and help pages // _numbrowseoptions_ the number of browsing options // if page is "help" // _textbrowseoptions_ the 'how to find information' text in the about and help pages // _numbrowseoptions_ the number of browsing options text_t &arg_p = args["p"]; if (arg_p == "home") { // make sure we know about a receptionist if (recpt == NULL) { logout << "The page action does not contain information\n" << "about any receptionists. The method set_receptionist\n" << "was probably not called from the module which instantiated\n" << "this page action.\n"; return; } text_t homeextra = "
\n"; recptprotolistclass *rprotolist = recpt->get_recptprotolist_ptr (); if (rprotolist == NULL) return; recptprotolistclass::iterator rprotolist_here = rprotolist->begin(); recptprotolistclass::iterator rprotolist_end = rprotolist->end(); while (rprotolist_here != rprotolist_end) { if ((*rprotolist_here).p != NULL) { text_tarray collist; comerror_t err; (*rprotolist_here).p->get_collection_list (collist, err, logout); if (err == noError) { text_tarray::iterator collist_here = collist.begin(); text_tarray::iterator collist_end = collist.end(); int row1 = 6; int row2 = 4; int count = 1; while (collist_here != collist_end) { ColInfoResponse_t cinfo; (*rprotolist_here).p->get_collectinfo (*collist_here, cinfo, err, logout); if (err == noError) { if (cinfo.isPublic) { FilterResponse_t response; text_tset metadata; metadata.insert ("collectionname"); metadata.insert ("iconcollection"); metadata.insert ("iconcollectionsmall"); text_t collectionname = *collist_here; text_t alt = collectionname; if (get_info ("collection", *collist_here, metadata, false, (*rprotolist_here).p, response, logout)) { if (!response.docInfo[0].metadata["collectionname"].values[0].empty()) alt = response.docInfo[0].metadata["collectionname"].values[0]; if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty()) collectionname = "\"""; else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty()) collectionname = "\"""; else collectionname = alt; } if ((count == 1) || (count == (row1+1)) || (count == ((row1+row2)+1))) homeextra += ""; count ++; } } collist_here ++; } homeextra += "
"; else homeextra += "

"; text_t link = ""; if (*collist_here == "chinese") link = ""; if (!cinfo.receptionist.empty()) link = ""; homeextra += link + collectionname + "\n"; if ((count == row1) || (count == (row1+row2))) homeextra += "

\n"; disp.setmacro ("homeextra", "home", homeextra); } } rprotolist_here ++; } } else if (arg_p == "about") { disp.setmacro ("numdocs", "about", collectinfo.numDocs); unsigned long current_time = time(NULL); unsigned long builddate = (current_time - collectinfo.buildDate) / 86400; disp.setmacro ("builddate", "about", builddate); } if (arg_p == "about" || arg_p == "help") { // _textbrowseoptions_ and _numbrowseoptions_ FilterResponse_t response; text_tset metadata; metadata.insert ("Title"); bool getParents = false; get_children ("", args["c"], metadata, getParents, collectproto, response, logout); disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1); ResultDocInfo_tarray::iterator here = response.docInfo.begin(); ResultDocInfo_tarray::iterator end = response.docInfo.end(); // we're assuming that we've always got a search button text_t shorttext = "\n"; disp.setmacro ("textbrowseoptions", "help", shorttext + longtext); } } bool pageaction::do_action (cgiargsclass &args, const ColInfoResponse_t &/*collectinfo*/, recptproto * /*collectproto*/, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) { text_t &arg_p = args["p"]; textout << outconvert << disp << ("_" + arg_p + ":header_\n") << ("_" + arg_p + ":content_\n") << ("_" + arg_p + ":footer_\n"); return true; }