source: trunk/gsdl/src/recpt/extlinkaction.cpp@ 7371

Last change on this file since 7371 was 7371, checked in by mdewsnip, 20 years ago

(Human Info) Allow some actions to be easily switched off.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
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
26#include "gsdl_modules_cfg.h"
27#ifdef GSDL_USE_EXTLINK_ACTION
28
29#include <string.h>
30#include "extlinkaction.h"
31#include "OIDtools.h"
32#include "cgiutils.h"
33
34extlinkaction::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;
59 arg_ainfo.argdefault = "";
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;
67 arg_ainfo.argdefault = "";
68 arg_ainfo.savedarginfo = cgiarginfo::can;
69 argsinfo.addarginfo (NULL, arg_ainfo);
70
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
79}
80
81extlinkaction::~extlinkaction () {
82}
83
84
85void extlinkaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
86 response_t &response, text_t &response_data,
87 ostream &logout) {
88
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") {
99 response = location;
100 response_data = link;
101 return;
102 }
103 }
104
105 response = content;
106 response_data = "text/html";
107}
108
109void extlinkaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
110 recptprotolistclass * /*protos*/,
111 ostream &/*logout*/) {
112
113 // define_internal_macros sets the following macros:
114
115 // _nexturl_ link to external page
116 // _prevdoc_ link to previous document
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
120 disp.setmacro("nexturl", "extlink", args["href"]);
121 disp.setmacro("prevdoc", "extlink", args["d"]);
122}
123
124
125// if link is found returns true and url in link, otherwise returns
126// false
127bool 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
134 if (args["rl"] == "1") {
135
136 FilterResponse_t response;
137 text_tset metadata;
138 metadata.insert ("section");
139
140 recptproto *collectproto = protos->getrecptproto (thiscollection, logout);
141
142 if (get_info (arg_href, thiscollection, metadata, false, collectproto, response, logout)) {
143 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
144 link = "_httpdoc_&d=" + response.docInfo[0].metadata["section"].values[0];
145 return true;
146 }
147 }
148
149 // need to see if link exists in any other collection
150 // if cross-collection searching/browsing is turned on
151 if (args["ccs"] == "1" && !args["cc"].empty()) {
152 text_tarray collections;
153 splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
154
155 text_tarray::const_iterator col_here = collections.begin();
156 text_tarray::const_iterator col_end = collections.end();
157
158 while (col_here != col_end) {
159
160 // don't need to check current collection again
161 if (*col_here == thiscollection) {col_here ++; continue;}
162
163 recptproto *collectproto = protos->getrecptproto (*col_here, logout);
164 if (collectproto == NULL) {col_here ++; continue;}
165
166 if (get_info (arg_href, *col_here, metadata, false, collectproto, response, logout)) {
167 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
168 link = "_httpdoc_&c=" + *col_here + "&d=" +
169 response.docInfo[0].metadata["section"].values[0];
170 return true;
171 }
172 }
173 col_here ++;
174 }
175 }
176 return false;
177
178 } else {
179 // link is external
180 link = arg_href;
181 return false;
182 }
183}
184
185
186bool extlinkaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
187 browsermapclass * /*browsers*/, displayclass &disp,
188 outconvertclass &outconvert, ostream &textout,
189 ostream &logout) {
190
191 if (args["href"].empty()) {
192 // oops, this shouldn't happen
193 textout << outconvert << disp << ("_extlink:header_\n")
194 << ("_extlink:notfoundcontent_\n")
195 << ("_extlink:footer_\n");
196 return true;
197 }
198
199 if (args["rl"] == "1") {
200 // need to see if link exists in any other collection
201 // if cross-collection searching/browsing is turned on
202 if (args["ccs"] == "1" && !args["cc"].empty()) {
203
204 FilterResponse_t response;
205 text_tset metadata;
206 metadata.insert ("section");
207 text_tarray collections;
208 splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
209
210 text_tarray::const_iterator col_here = collections.begin();
211 text_tarray::const_iterator col_end = collections.end();
212
213 while (col_here != col_end) {
214
215 // don't need to check current collection
216 if (*col_here == args["c"]) {col_here ++; continue;}
217
218 recptproto *collectproto = protos->getrecptproto (*col_here, logout);
219
220 if (get_info (args["href"], *col_here, metadata, false, collectproto, response, logout)) {
221 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
222 text_t collectionname = *col_here;
223 metadata.erase (metadata.begin(), metadata.end());
224 metadata.insert ("collectionname");
225 FilterResponse_t nresponse;
226 if (get_info ("collection", *col_here, metadata, false, collectproto, nresponse, logout)) {
227 if (!nresponse.docInfo[0].metadata["collectionname"].values[0].empty())
228 collectionname = nresponse.docInfo[0].metadata["collectionname"].values[0];
229 }
230 textout << outconvert << disp << ("_extlink:header_\n")
231 << ("_extlink:foundintcontent_(" + *col_here + ", " + collectionname +
232 ", " + response.docInfo[0].metadata["section"].values[0] + "\n")
233 << ("_extlink:footer_\n");
234 return true;
235 }
236 }
237 col_here ++;
238 }
239 }
240 textout << outconvert << disp << ("_extlink:header_\n")
241 << ("_extlink:notfoundcontent_\n")
242 << ("_extlink:footer_\n");
243
244
245 } else {
246 // link is external
247 textout << outconvert << disp << ("_extlink:header_\n")
248 << ("_extlink:foundcontent_\n")
249 << ("_extlink:footer_\n");
250 }
251
252 return true;
253}
254
255#endif //GSDL_USE_EXTLINK_ACTION
Note: See TracBrowser for help on using the repository browser.