/********************************************************************** * * 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 905 2000-02-03 01:49:35Z sjboddie $ * *********************************************************************/ /* $Log$ Revision 1.26 2000/02/03 01:49:35 sjboddie fixed up some of the preferences stuff Revision 1.25 2000/01/26 20:11:04 sjboddie added some collection specific help text Revision 1.24 2000/01/25 22:31:09 sjboddie more hacky changes to get preferences to be a bit smarter Revision 1.23 2000/01/24 22:59:57 sjboddie changes to set macros differently for preferences page depending on type of collection - pageaction is getting kind of hacky - should tidy it up some day Revision 1.22 1999/11/25 23:01:09 sjboddie now need to be able to handle it if no collection is selected Revision 1.21 1999/11/03 22:50:13 sjboddie now defaults to home page Revision 1.20 1999/11/01 21:58:02 sjboddie changes to arguments of many functions, now pass list of protocols instead of just that for this collection Revision 1.19 1999/10/19 21:59:09 sjboddie bug in generating "how to find information" text for about pages Revision 1.18 1999/10/19 03:23:44 davidb Collection building support through web pages and internal and external link handling for collection documents Revision 1.17 1999/10/14 23:04:44 sjboddie some hacks to make nzdl home page look right 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 = "home"; 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*/, recptprotolistclass * /*protos*/, response_t &response,text_t &response_data, ostream &/*logout*/) { response = content; response_data = "text/html"; } void pageaction::set_homeextra_macro (displayclass &disp, recptprotolistclass *protos, ostream &logout) { text_t homeextra = "
\n"; recptprotolistclass::iterator rprotolist_here = protos->begin(); recptprotolistclass::iterator rprotolist_end = protos->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 = 7; int row2 = 5; int count = 1; while (collist_here != collist_end) { if (*collist_here == "niupepa") homeextra += "

_iconmusiclibrary_\n"; ColInfoResponse_t cinfo; (*rprotolist_here).p->get_collectinfo (*collist_here, cinfo, err, logout); if (err == noError) { if (cinfo.isPublic && (cinfo.buildDate > 0)) { 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 (*collist_here == "arabic") 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 ++; } } void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args, recptprotolistclass *protos, ostream &logout) { // define_internal_macros sets the following macros: // _numdocs_ the number of documents in the collection // _builddate_ the date last built // 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 "preferences" // _collectionoption_ collections to search/browse (if cross-collection-searching is on) // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set // _languageoption_ interface languages to select from (dependant on PreferenceLanguages) // _encodingoption_ will be overridden to "" if chinese language interface isn't specified // if page is "about" // _textsubcollections_ the text on which subcollections make up the collection (if // cross-collection searching is being used // _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 // _topicreadingdocs_ this section of the help text differs depending on what type of // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.) // _texthelpreadingdocs_ text_t &arg_p = args["p"]; text_t &arg_c = args["c"]; ColInfoResponse_t cinfo; comerror_t err; recptproto* collectproto = protos->getrecptproto (arg_c, logout); if (collectproto != NULL) { collectproto->get_collectinfo (arg_c, cinfo, err, logout); disp.setmacro ("numdocs", "Global", cinfo.numDocs); unsigned long current_time = time(NULL); unsigned long builddate = (current_time - cinfo.buildDate) / 86400; disp.setmacro ("builddate", "Global", builddate); } if (arg_p == "home") set_homeextra_macro (disp, protos, logout); else if (arg_p == "preferences") { // _collectionoption_ if (args["ccs"] == "1" && collectproto != NULL && (cinfo.ccsCols.size() > 1)) { text_t collectionoption = "_textcollectionoption_"; text_tarray::const_iterator col_here = cinfo.ccsCols.begin(); text_tarray::const_iterator col_end = cinfo.ccsCols.end(); int count = 0; while (col_here != col_end) { text_t colname; if (*col_here == arg_c) { colname = cinfo.collectionmeta["collectionname"]; } else { ColInfoResponse_t this_cinfo; collectproto->get_collectinfo (*col_here, this_cinfo, err, logout); if (err != noError) {col_here ++; continue;} colname = this_cinfo.collectionmeta["collectionname"]; } count ++; collectionoption += " " + colname + "
\n"; col_here ++; } if (count > 1) disp.setmacro ("collectionoption", "preferences", collectionoption); } // _htmloptions_ text_tmap::const_iterator it = cinfo.format.find ("DocumentUseHTML"); if ((it != cinfo.format.end()) && ((*it).second == "true")) { disp.setmacro ("htmloptions", "preferences", "_htmloptionson_"); // _PreferenceDocsFromWeb_ it = cinfo.format.find ("PreferenceDocsFromWeb"); if ((it == cinfo.format.end()) || ((*it).second == "true")) disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1"); } // _languageoption_ // this is kind of a hack (another one!!). note that there're potential // problems here as no checking is done anywhere to make sure language // is set to a valid value. this does allow us to set which languages // should go in the preference selection box (from collect.cfg) however // and that's sufficient for current requirements // currently supported languages (_languageoption_ will default to all // these languages unless PreferenceLanguages is set text_tarray languages; languages.push_back ("en"); languages.push_back ("mi"); languages.push_back ("zh"); text_tarray::const_iterator this_lang = languages.begin(); text_tarray::const_iterator end_lang = languages.end(); text_t languageoption = "_textlanguage_\n\n"; disp.setmacro ("languageoption", "preferences", languageoption); } // _encodingoption_ if (pref_langs.find("zh") == pref_langs.end()) disp.setmacro ("encodingoption", "preferences", ""); } else { while (this_lang != end_lang) { languageoption += "_" + *this_lang + "languageoption_\n"; this_lang ++; } languageoption += "\n"; disp.setmacro ("languageoption", "preferences", languageoption); } } else if (arg_p == "about" || arg_p == "help") { if (collectproto == NULL) return; // _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"; if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext); else disp.setmacro ("textbrowseoptions", "help", longtext); if (arg_p == "help") { // _topicreadingdocs_ _textreadingdocs_ _texthelpreadingdocs_ // if HTML collection there's no how to read document text text_tmap::const_iterator it = cinfo.format.find ("HelpNoDocs"); if ((it != cinfo.format.end()) && ((*it).second == "true")) { disp.setmacro ("topicreadingdocs", "help", ""); disp.setmacro ("texthelpreadingdocs", "help", ""); } it = cinfo.format.find ("HelpBibDocs"); if ((it != cinfo.format.end()) && ((*it).second == "true")) { disp.setmacro ("texthelpreadingdocs", "help", "_bibtexthelpreadingdocs_"); disp.setmacro ("textreadingdocs", "help", "_bibtextreadingdocs_"); } it = cinfo.format.find ("HelpBookDocs"); if ((it != cinfo.format.end()) && ((*it).second == "true")) { disp.setmacro ("texthelpreadingdocs", "help", "_booktexthelpreadingdocs_"); disp.setmacro ("textreadingdocs", "help", "_booktextreadingdocs_"); } } if (arg_p == "about") { // _textsubcollections_ if (args["ccs"] == "1" && (cinfo.ccsCols.size() > 1)) { text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo.ccsCols.size()) + ")"; text_tarray::const_iterator here = cinfo.ccsCols.begin(); text_tarray::const_iterator end = cinfo.ccsCols.end(); bool first = true; int count = 0; while (here != end) { if (*here == arg_c) { if (!first) textsubcollections += "
"; textsubcollections += "\n" + cinfo.collectionmeta["collectionname"] + "\n"; } else { ColInfoResponse_t this_cinfo; collectproto->get_collectinfo (*here, this_cinfo, err, logout); if (err != noError) {here ++; continue;} if (!first) textsubcollections += "
"; textsubcollections += "\n" + this_cinfo.collectionmeta["collectionname"] + "\n"; } count ++; first = false; here ++; } textsubcollections += "_textsubcols2_"; if (count > 1) disp.setmacro ("textsubcollections", "about", textsubcollections); } } } } bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/, browsermapclass * /*browsers*/, 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; }