source: main/trunk/greenstone2/runtime-src/src/recpt/extlinkaction.cpp@ 22044

Last change on this file since 22044 was 17410, checked in by ak19, 16 years ago

External links no longer takes one to an intermediate page informing the user that they've just clicked on an external link

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