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