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

Last change on this file since 24411 was 22984, checked in by ak19, 14 years ago
  1. Undoing commit of 22934 where decode_commas was called on stem and fold comma separated list: previously separated due to url-encoding of commas. Now that the problem has been fixed at the source, the decode_commas hack is no longer necessary. 2. Commas in stem and fold are no longer url-encoded because the multiple_value field of the continuously-reused struct arg_ainfo is always set back to the default false after ever being set to true. So it no longer subtly stays at true to affect Greenstone functioning in unforeseen ways (such as suddenly and unnecessarily URL-encoding commas where this is not wanted).
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 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.multiplevalue = false;
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;
51 arg_ainfo.multiplevalue = false;
52 arg_ainfo.defaultstatus = cgiarginfo::weak;
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
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;
61 arg_ainfo.multiplevalue = false;
62 arg_ainfo.defaultstatus = cgiarginfo::none;
63 arg_ainfo.argdefault = g_EmptyText;
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;
70 arg_ainfo.multiplevalue = false;
71 arg_ainfo.defaultstatus = cgiarginfo::none;
72 arg_ainfo.argdefault = g_EmptyText;
73 arg_ainfo.savedarginfo = cgiarginfo::can;
74 argsinfo.addarginfo (NULL, arg_ainfo);
75
76 arg_ainfo.shortname = "rl";
77 arg_ainfo.longname = "is relative link";
78 arg_ainfo.multiplechar = false;
79 arg_ainfo.multiplevalue = false;
80 arg_ainfo.defaultstatus = cgiarginfo::none;
81 arg_ainfo.argdefault = "0";
82 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
83 argsinfo.addarginfo (NULL, arg_ainfo);
84
85}
86
87extlinkaction::~extlinkaction () {
88}
89
90
91void extlinkaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
92 response_t &response, text_t &response_data,
93 ostream &logout) {
94
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") {
105 response = location;
106 response_data = link;
107 return;
108 }
109 }
110
111 response = content;
112 response_data = "text/html";
113}
114
115void extlinkaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
116 recptprotolistclass * /*protos*/,
117 ostream &/*logout*/) {
118
119 // define_internal_macros sets the following macros:
120
121 // _nexturl_ link to external page
122 // _prevdoc_ link to previous document
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
126 disp.setmacro("nexturl", "extlink", args["href"]);
127 disp.setmacro("prevdoc", "extlink", args["d"]);
128}
129
130
131// if link is found returns true and url in link, otherwise returns
132// false
133bool 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
140 text_t httpdoc = "_gwcgi_?e=_compressedoptions_&a=d";
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
149 if (get_info (arg_href, thiscollection, args["l"], metadata, false, collectproto, response, logout)) {
150 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
151 link = httpdoc+"&d=" + response.docInfo[0].metadata["section"].values[0];
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
168 if (*col_here == thiscollection) {++col_here; continue;}
169
170 recptproto *collectproto = protos->getrecptproto (*col_here, logout);
171 if (collectproto == NULL) {++col_here; continue;}
172
173 if (get_info (arg_href, *col_here, args["l"], metadata, false, collectproto, response, logout)) {
174 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
175 link = httpdoc+"&c=" + *col_here + "&d=" +
176 response.docInfo[0].metadata["section"].values[0];
177 return true;
178 }
179 }
180 ++col_here;
181 }
182 }
183 return false;
184
185 } else {
186 // link is external
187 link = arg_href;
188 return false;
189 }
190}
191
192
193bool extlinkaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
194 browsermapclass * /*browsers*/, displayclass &disp,
195 outconvertclass &outconvert, ostream &textout,
196 ostream &logout) {
197
198 if (args["href"].empty()) {
199 // oops, this shouldn't happen
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
223 if (*col_here == args["c"]) {++col_here; continue;}
224
225 recptproto *collectproto = protos->getrecptproto (*col_here, logout);
226 if (get_info (args["href"], *col_here, args["l"], metadata, false, collectproto, response, logout)) {
227 if (!response.docInfo[0].metadata["section"].values[0].empty()) {
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;
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 }
239 }
240 ++col_here;
241 }
242 }
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 }
254
255 return true;
256}
257
258#endif //GSDL_USE_EXTLINK_ACTION
Note: See TracBrowser for help on using the repository browser.