/********************************************************************** * * 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 "fileutil.h" #include "gsdltools.h" #include pageaction::pageaction () { status_disabled = true; collector_disabled = true; translator_disabled = true; 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); arg_ainfo.shortname = "bp"; arg_ainfo.longname = "set preferences button"; arg_ainfo.multiplechar = true; arg_ainfo.defaultstatus = cgiarginfo::weak; arg_ainfo.argdefault = ""; arg_ainfo.savedarginfo = cgiarginfo::mustnot; argsinfo.addarginfo (NULL, arg_ainfo); // the "u" argument will disable the search facility, remove links to the // home and preferences pages, and disable the DocumentButton buttons // (for use when generating static html versions of collections) arg_ainfo.shortname = "u"; arg_ainfo.longname = "static page"; arg_ainfo.multiplechar = false; arg_ainfo.defaultstatus = cgiarginfo::weak; arg_ainfo.argdefault = "0"; arg_ainfo.savedarginfo = cgiarginfo::mustnot; argsinfo.addarginfo (NULL, arg_ainfo); } pageaction::~pageaction () { } bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &args, recptprotolistclass * /*protos*/, ostream &/*logout*/) { if (args["p"] == "preferences" && !args["bp"].empty()) { if (args["hd"] != "0") args["hd"] = args["hdn"]; } 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, cgiargsclass &args, 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)) { text_t coll_type = "&ct="; if (cinfo->buildType == "mgpp") { coll_type += "1"; } else { coll_type += "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]; text_t iconurl; iconurl.clear(); if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty()) { iconurl = response.docInfo[0].metadata["iconcollectionsmall"].values[0]; } else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty()) { iconurl = response.docInfo[0].metadata["iconcollection"].values[0]; } if (!iconurl.empty()) { // check to see URL is local to colserver text_t::iterator iconurl_head = iconurl.begin(); text_t iconhead = substr(iconurl_head,iconurl_head+16); if (iconhead=="_httpcollection_") { // local and using _httpcollection_ text_t icontail = substr(iconurl_head+16,iconurl.end()); iconurl = "http://" + cinfo->httpdomain + cinfo->httpprefix + "/collect/" + *collist_here + "/" + icontail; } else if (iconurl[0]=='/') { // local but with full path iconurl = "http://" + cinfo->httpdomain + iconurl; } collectionname = "\"""; } else { collectionname = alt; } } if ((count%3 == 0) && (!first)) homeextra += "\n"; comerror_t err; text_t optsite = ""; text_t site_name = (*rprotolist_here).p->get_site_name (err); if (!site_name.empty()) { optsite = "site="+site_name+"&"; } text_t link = ""; if (!cinfo->receptionist.empty()) link = "receptionist + "\">"; homeextra += "\n"; count ++; first = false; } } collist_here ++; } for (; count%3 != 0; count ++) homeextra += "\n"; } } homeextra += "\n\n"; rprotolist_here ++; } if (!found_valid_col) { homeextra += "\n"; } homeextra += "
" + link + collectionname + "
No valid (i.e. built and public) collections are available
\n"; disp.setmacro ("homeextra", "home", homeextra); } void pageaction::set_collectionlist_macro (displayclass &disp, recptprotolistclass *protos, ostream &logout) { text_t collectionlist; int count = 0; 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(); 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)) { count ++; text_t coll_type = "&ct="; if (cinfo->buildType == "mgpp") { coll_type += "1"; } else { coll_type += "0"; } FilterResponse_t response; text_tset metadata; metadata.insert ("collectionname"); text_t collectionname = *collist_here; if (get_info ("collection", *collist_here, metadata, false, (*rprotolist_here).p, response, logout)) { if (!response.docInfo[0].metadata["collectionname"].values[0].empty()) { collectionname = response.docInfo[0].metadata["collectionname"].values[0]; } } comerror_t err; text_t optsite = ""; text_t site_name = (*rprotolist_here).p->get_site_name (err); if (!site_name.empty()) { optsite = "site="+site_name+"&"; } text_t link = ""; if (!cinfo->receptionist.empty()) link = "receptionist + "\">"; collectionlist += "
  • " + link + collectionname + "\n"; } } collist_here ++; } } } rprotolist_here ++; } if (count == 1) { collectionlist = "

    _text1coll_\n

    \n"; } else if (count > 1) { collectionlist = "

    _textmorecolls_(" + text_t(count) + ")\n

    \n"; } disp.setmacro ("collectionlist", "homehelp", collectionlist); } void pageaction::set_documentation_macro (displayclass &disp) { text_t documentation; text_t docsdir = filename_cat(gsdlhome, "docs"); if (file_exists(filename_cat(docsdir, "User.pdf"))) { documentation += "_iconpdf_" "_textuserguide_"; } if (file_exists(filename_cat(docsdir, "Install.pdf"))) { documentation += "_iconpdf_" "_textinstallerguide_"; } if (file_exists(filename_cat(docsdir, "Develop.pdf"))) { documentation += "_iconpdf_" "_textdeveloperguide_"; } if (file_exists(filename_cat(docsdir, "Paper.pdf"))) { documentation += "_iconpdf_" "_textpaperguide_"; } if (!documentation.empty()) { disp.setmacro("documentation", "docs", "

    \n\n" + documentation + "\n
    \n"); } } void pageaction::set_macro_to_file_contents (displayclass &disp, const text_t ¯oname, const text_t &packagename, const text_t &filename) { text_t filecontent; char *filenamec = filename.getcstr(); ifstream file_in (filenamec); delete filenamec; if (file_in) { char c; file_in.get(c); while (!file_in.eof ()) { if (c == '\n') filecontent += "
    "; filecontent.push_back(c); file_in.get(c); } file_in.close(); } disp.setmacro (macroname, packagename, dm_safe(filecontent)); } void pageaction::set_language_encoding_macros(displayclass &disp, cgiargsclass &args, recptprotolistclass *protos, ColInfoResponse_t *cinfo, ostream &logout) { // _languageoption_ // Create the "interface language" selection box for the preferences // pages. You can use something like "format PreferenceLanguages // en|fr|zn" from within a collect.cfg file to use only a subset of // the available languages for any given collection (for // collection-specific preferences pages). This facility is kind of // ugly though and should be replaced by something better when the // configuration files are tidied up (as should all the other // "format Preference..." options). text_t &arg_l = args["l"]; const recptconf &configinfo = recpt->get_configinfo(); // put languages in another map to sort them by longname text_tmap languages; languageinfo_tmap::const_iterator thislang = configinfo.languages.begin(); languageinfo_tmap::const_iterator endlang = configinfo.languages.end(); while (thislang != endlang) { languages[(*thislang).second.longname] = (*thislang).first; thislang++; } text_tmap::iterator tlang = languages.begin(); text_tmap::iterator elang = languages.end(); text_t languageoption; bool collection_specific = false; if (cinfo != NULL) { text_tmap::const_iterator it = cinfo->format.find ("PreferenceLanguages"); if ((it != cinfo->format.end()) && (!(*it).second.empty())) { collection_specific = true; text_tset pref_langs; splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs); if (pref_langs.size() > 1) { while (tlang != elang) { if (pref_langs.find((*tlang).second) != pref_langs.end()) { languageoption += "

    \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); } } } else if (arg_p == "homehelp") { set_collectionlist_macro (disp, protos, logout); } else if (arg_p == "docs") { set_documentation_macro (disp); } else if (arg_p == "bsummary" && !arg_c.empty()) { set_macro_to_file_contents (disp, "importlog", "bsummary", filename_cat(gsdlhome, "collect", arg_c, "etc", "import.log")); set_macro_to_file_contents (disp, "faillog", "bsummary", filename_cat(gsdlhome, "collect", arg_c, "etc", "fail.log")); } } 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; } void pageaction::configure (const text_t &key, const text_tarray &cfgline) { if ((key == "status") && (cfgline.size() == 1) && (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) { status_disabled = false; } else if ((key == "collector") && (cfgline.size() == 1) && (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) { collector_disabled = false; } else if ((key == "translator") && (cfgline.size() == 1) && (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) { translator_disabled = false; } else { // call the parent class to deal with the things which // are not dealt with here action::configure (key, cfgline); } }