/********************************************************************** * * 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. * *********************************************************************/ #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"; bool found_valid_col = false; 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 count = 0; bool first = true; while (collist_here != collist_end) { ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout); if (cinfo != NULL) { if (cinfo->isPublic && (cinfo->buildDate > 0)) { found_valid_col = true; 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%3 == 0) && (!first)) homeextra += "\n"; text_t link = ""; if (*collist_here == "chinese") link = ""; if (*collist_here == "arabic") link = ""; if (!cinfo->receptionist.empty()) link = "receptionist + "\">"; homeextra += "\n"; count ++; first = false; } } collist_here ++; } // disp.setmacro ("homeextra", "home", homeextra); for (; count%3 != 0; count ++) homeextra += "\n"; } } homeextra += "\n\n"; rprotolist_here ++; } homeextra += "
" + link + collectionname + "
\n"; disp.setmacro ("homeextra", "home", homeextra); if (!found_valid_col) { homeextra += "No valid (i.e. built and public) collections are available\n"; } homeextra += "\n"; disp.setmacro ("homeextra", "home", homeextra); } 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_ if (recpt == NULL) { logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n" << " information about any receptionists. The method set_receptionist was\n" << " probably not called from the module which instantiated this action.\n"; return; } text_t &arg_p = args["p"]; text_t &arg_c = args["c"]; ColInfoResponse_t *cinfo = NULL; recptproto* collectproto = protos->getrecptproto (arg_c, logout); if (collectproto != NULL) { cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, 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 = recpt->get_collectinfo_ptr (collectproto, *col_here, logout); if (this_cinfo == NULL) {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 ("fr"); languages.push_back ("de"); languages.push_back ("es"); languages.push_back ("mi"); languages.push_back ("zh"); languages.push_back ("ar"); languages.push_back ("pt"); 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 = recpt->get_collectinfo_ptr (collectproto, *here, logout); if (this_cinfo == NULL) {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; }