[723] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * extlinkaction.cpp --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
| 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.
|
---|
| 9 | *
|
---|
| 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 | *
|
---|
| 24 | *********************************************************************/
|
---|
| 25 |
|
---|
[7371] | 26 | #include "gsdl_modules_cfg.h"
|
---|
| 27 | #ifdef GSDL_USE_EXTLINK_ACTION
|
---|
[723] | 28 |
|
---|
| 29 | #include <string.h>
|
---|
| 30 | #include "extlinkaction.h"
|
---|
[15418] | 31 | #include "recptprototools.h"
|
---|
[827] | 32 | #include "cgiutils.h"
|
---|
[723] | 33 |
|
---|
| 34 | extlinkaction::extlinkaction () {
|
---|
| 35 |
|
---|
| 36 | // this action uses cgi variables "a", "d", and "href"
|
---|
| 37 |
|
---|
| 38 | cgiarginfo arg_ainfo;
|
---|
| 39 | arg_ainfo.shortname = "a";
|
---|
| 40 | arg_ainfo.longname = "action";
|
---|
| 41 | arg_ainfo.multiplechar = true;
|
---|
[22984] | 42 | arg_ainfo.multiplevalue = false;
|
---|
[723] | 43 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 44 | arg_ainfo.argdefault = "extlink";
|
---|
| 45 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 46 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 47 |
|
---|
| 48 | arg_ainfo.shortname = "el";
|
---|
| 49 | arg_ainfo.longname = "external link preference";
|
---|
| 50 | arg_ainfo.multiplechar = true;
|
---|
[22984] | 51 | arg_ainfo.multiplevalue = false;
|
---|
[723] | 52 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[17410] | 53 | arg_ainfo.argdefault = "direct"; // changed from "prompt" - will now directly load external links instead of
|
---|
| 54 | // going through an intermediate page indicating that the link is external
|
---|
[723] | 55 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 56 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 57 |
|
---|
| 58 | arg_ainfo.shortname = "d";
|
---|
| 59 | arg_ainfo.longname = "document OID";
|
---|
| 60 | arg_ainfo.multiplechar = true;
|
---|
[22984] | 61 | arg_ainfo.multiplevalue = false;
|
---|
[723] | 62 | arg_ainfo.defaultstatus = cgiarginfo::none;
|
---|
[7408] | 63 | arg_ainfo.argdefault = g_EmptyText;
|
---|
[723] | 64 | arg_ainfo.savedarginfo = cgiarginfo::can;
|
---|
| 65 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 66 |
|
---|
| 67 | arg_ainfo.shortname = "href";
|
---|
| 68 | arg_ainfo.longname = "URL of external link";
|
---|
| 69 | arg_ainfo.multiplechar = true;
|
---|
[22984] | 70 | arg_ainfo.multiplevalue = false;
|
---|
[723] | 71 | arg_ainfo.defaultstatus = cgiarginfo::none;
|
---|
[7408] | 72 | arg_ainfo.argdefault = g_EmptyText;
|
---|
[723] | 73 | arg_ainfo.savedarginfo = cgiarginfo::can;
|
---|
| 74 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 75 |
|
---|
[756] | 76 | arg_ainfo.shortname = "rl";
|
---|
| 77 | arg_ainfo.longname = "is relative link";
|
---|
| 78 | arg_ainfo.multiplechar = false;
|
---|
[22984] | 79 | arg_ainfo.multiplevalue = false;
|
---|
[756] | 80 | arg_ainfo.defaultstatus = cgiarginfo::none;
|
---|
| 81 | arg_ainfo.argdefault = "0";
|
---|
| 82 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 83 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 84 |
|
---|
[723] | 85 | }
|
---|
| 86 |
|
---|
| 87 | extlinkaction::~extlinkaction () {
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 |
|
---|
[869] | 91 | void extlinkaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
|
---|
| 92 | response_t &response, text_t &response_data,
|
---|
| 93 | ostream &logout) {
|
---|
[723] | 94 |
|
---|
[869] | 95 | text_t link;
|
---|
| 96 | if (get_link (args, protos, link, logout)) {
|
---|
| 97 | response = location;
|
---|
| 98 | response_data = link;
|
---|
| 99 | return;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | // external link
|
---|
| 103 | if (!link.empty()) {
|
---|
| 104 | if (args["el"] == "direct") {
|
---|
[723] | 105 | response = location;
|
---|
[869] | 106 | response_data = link;
|
---|
| 107 | return;
|
---|
[723] | 108 | }
|
---|
[869] | 109 | }
|
---|
| 110 |
|
---|
| 111 | response = content;
|
---|
| 112 | response_data = "text/html";
|
---|
[723] | 113 | }
|
---|
| 114 |
|
---|
[756] | 115 | void extlinkaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
|
---|
| 116 | recptprotolistclass * /*protos*/,
|
---|
| 117 | ostream &/*logout*/) {
|
---|
[723] | 118 |
|
---|
| 119 | // define_internal_macros sets the following macros:
|
---|
| 120 |
|
---|
| 121 | // _nexturl_ link to external page
|
---|
| 122 | // _prevdoc_ link to previous document
|
---|
[1443] | 123 | // disp.setmacro("nexturl", "extlink", cgi_safe(args["href"]));
|
---|
| 124 | // problem in whist, above line changed. Perhaps decode_cgi_arg ??
|
---|
| 125 | // see also HTML plugin
|
---|
[869] | 126 | disp.setmacro("nexturl", "extlink", args["href"]);
|
---|
[723] | 127 | disp.setmacro("prevdoc", "extlink", args["d"]);
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 |
|
---|
[869] | 131 | // if link is found returns true and url in link, otherwise returns
|
---|
| 132 | // false
|
---|
| 133 | bool extlinkaction::get_link (cgiargsclass &args, recptprotolistclass *protos,
|
---|
| 134 | text_t &link, ostream &logout) {
|
---|
| 135 |
|
---|
| 136 | text_t &arg_href = args["href"];
|
---|
| 137 | text_t &thiscollection = args["c"];
|
---|
| 138 | if (arg_href.empty()) return false;
|
---|
| 139 |
|
---|
[11306] | 140 | text_t httpdoc = "_gwcgi_?e=_compressedoptions_&a=d";
|
---|
[869] | 141 | if (args["rl"] == "1") {
|
---|
| 142 |
|
---|
| 143 | FilterResponse_t response;
|
---|
| 144 | text_tset metadata;
|
---|
| 145 | metadata.insert ("section");
|
---|
| 146 |
|
---|
| 147 | recptproto *collectproto = protos->getrecptproto (thiscollection, logout);
|
---|
| 148 |
|
---|
[7408] | 149 | if (get_info (arg_href, thiscollection, args["l"], metadata, false, collectproto, response, logout)) {
|
---|
[869] | 150 | if (!response.docInfo[0].metadata["section"].values[0].empty()) {
|
---|
[11306] | 151 | link = httpdoc+"&d=" + response.docInfo[0].metadata["section"].values[0];
|
---|
[869] | 152 | return true;
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | // need to see if link exists in any other collection
|
---|
| 157 | // if cross-collection searching/browsing is turned on
|
---|
| 158 | if (args["ccs"] == "1" && !args["cc"].empty()) {
|
---|
| 159 | text_tarray collections;
|
---|
| 160 | splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
|
---|
| 161 |
|
---|
| 162 | text_tarray::const_iterator col_here = collections.begin();
|
---|
| 163 | text_tarray::const_iterator col_end = collections.end();
|
---|
| 164 |
|
---|
| 165 | while (col_here != col_end) {
|
---|
| 166 |
|
---|
| 167 | // don't need to check current collection again
|
---|
[9620] | 168 | if (*col_here == thiscollection) {++col_here; continue;}
|
---|
[869] | 169 |
|
---|
| 170 | recptproto *collectproto = protos->getrecptproto (*col_here, logout);
|
---|
[9620] | 171 | if (collectproto == NULL) {++col_here; continue;}
|
---|
[869] | 172 |
|
---|
[7408] | 173 | if (get_info (arg_href, *col_here, args["l"], metadata, false, collectproto, response, logout)) {
|
---|
[869] | 174 | if (!response.docInfo[0].metadata["section"].values[0].empty()) {
|
---|
[11306] | 175 | link = httpdoc+"&c=" + *col_here + "&d=" +
|
---|
[869] | 176 | response.docInfo[0].metadata["section"].values[0];
|
---|
| 177 | return true;
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
[9620] | 180 | ++col_here;
|
---|
[869] | 181 | }
|
---|
| 182 | }
|
---|
| 183 | return false;
|
---|
| 184 |
|
---|
| 185 | } else {
|
---|
| 186 | // link is external
|
---|
| 187 | link = arg_href;
|
---|
| 188 | return false;
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 |
|
---|
| 193 | bool extlinkaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
|
---|
[756] | 194 | browsermapclass * /*browsers*/, displayclass &disp,
|
---|
| 195 | outconvertclass &outconvert, ostream &textout,
|
---|
[869] | 196 | ostream &logout) {
|
---|
[11306] | 197 |
|
---|
[869] | 198 | if (args["href"].empty()) {
|
---|
[11306] | 199 | // oops, this shouldn't happen
|
---|
[869] | 200 | textout << outconvert << disp << ("_extlink:header_\n")
|
---|
| 201 | << ("_extlink:notfoundcontent_\n")
|
---|
| 202 | << ("_extlink:footer_\n");
|
---|
| 203 | return true;
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | if (args["rl"] == "1") {
|
---|
| 207 | // need to see if link exists in any other collection
|
---|
| 208 | // if cross-collection searching/browsing is turned on
|
---|
| 209 | if (args["ccs"] == "1" && !args["cc"].empty()) {
|
---|
| 210 |
|
---|
| 211 | FilterResponse_t response;
|
---|
| 212 | text_tset metadata;
|
---|
| 213 | metadata.insert ("section");
|
---|
| 214 | text_tarray collections;
|
---|
| 215 | splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
|
---|
| 216 |
|
---|
| 217 | text_tarray::const_iterator col_here = collections.begin();
|
---|
| 218 | text_tarray::const_iterator col_end = collections.end();
|
---|
| 219 |
|
---|
| 220 | while (col_here != col_end) {
|
---|
| 221 |
|
---|
| 222 | // don't need to check current collection
|
---|
[9620] | 223 | if (*col_here == args["c"]) {++col_here; continue;}
|
---|
[869] | 224 |
|
---|
| 225 | recptproto *collectproto = protos->getrecptproto (*col_here, logout);
|
---|
[7408] | 226 | if (get_info (args["href"], *col_here, args["l"], metadata, false, collectproto, response, logout)) {
|
---|
[869] | 227 | if (!response.docInfo[0].metadata["section"].values[0].empty()) {
|
---|
[9931] | 228 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
|
---|
| 229 | text_t collectionname = cinfo->get_collectionmeta("collectionname", args["l"]); //
|
---|
| 230 | if (collectionname.empty()) {
|
---|
| 231 | collectionname = *col_here;
|
---|
[869] | 232 | }
|
---|
| 233 | textout << outconvert << disp << ("_extlink:header_\n")
|
---|
| 234 | << ("_extlink:foundintcontent_(" + *col_here + ", " + collectionname +
|
---|
| 235 | ", " + response.docInfo[0].metadata["section"].values[0] + "\n")
|
---|
| 236 | << ("_extlink:footer_\n");
|
---|
| 237 | return true;
|
---|
| 238 | }
|
---|
[723] | 239 | }
|
---|
[9620] | 240 | ++col_here;
|
---|
[869] | 241 | }
|
---|
[723] | 242 | }
|
---|
[869] | 243 | textout << outconvert << disp << ("_extlink:header_\n")
|
---|
| 244 | << ("_extlink:notfoundcontent_\n")
|
---|
| 245 | << ("_extlink:footer_\n");
|
---|
| 246 |
|
---|
| 247 |
|
---|
| 248 | } else {
|
---|
| 249 | // link is external
|
---|
| 250 | textout << outconvert << disp << ("_extlink:header_\n")
|
---|
| 251 | << ("_extlink:foundcontent_\n")
|
---|
| 252 | << ("_extlink:footer_\n");
|
---|
| 253 | }
|
---|
[723] | 254 |
|
---|
| 255 | return true;
|
---|
| 256 | }
|
---|
[7371] | 257 |
|
---|
| 258 | #endif //GSDL_USE_EXTLINK_ACTION
|
---|