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 |
|
---|
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;
|
---|
59 | arg_ainfo.argdefault = g_EmptyText;
|
---|
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 = g_EmptyText;
|
---|
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 |
|
---|
81 | extlinkaction::~extlinkaction () {
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | void 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 |
|
---|
109 | void 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
|
---|
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 |
|
---|
134 | text_t httpdoc = "_gwcgi_?e=_compressedoptions_&a=d";
|
---|
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 |
|
---|
143 | if (get_info (arg_href, thiscollection, args["l"], metadata, false, collectproto, response, logout)) {
|
---|
144 | if (!response.docInfo[0].metadata["section"].values[0].empty()) {
|
---|
145 | link = httpdoc+"&d=" + response.docInfo[0].metadata["section"].values[0];
|
---|
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
|
---|
162 | if (*col_here == thiscollection) {++col_here; continue;}
|
---|
163 |
|
---|
164 | recptproto *collectproto = protos->getrecptproto (*col_here, logout);
|
---|
165 | if (collectproto == NULL) {++col_here; continue;}
|
---|
166 |
|
---|
167 | if (get_info (arg_href, *col_here, args["l"], metadata, false, collectproto, response, logout)) {
|
---|
168 | if (!response.docInfo[0].metadata["section"].values[0].empty()) {
|
---|
169 | link = httpdoc+"&c=" + *col_here + "&d=" +
|
---|
170 | response.docInfo[0].metadata["section"].values[0];
|
---|
171 | return true;
|
---|
172 | }
|
---|
173 | }
|
---|
174 | ++col_here;
|
---|
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,
|
---|
188 | browsermapclass * /*browsers*/, displayclass &disp,
|
---|
189 | outconvertclass &outconvert, ostream &textout,
|
---|
190 | ostream &logout) {
|
---|
191 |
|
---|
192 | if (args["href"].empty()) {
|
---|
193 | // oops, this shouldn't happen
|
---|
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
|
---|
217 | if (*col_here == args["c"]) {++col_here; continue;}
|
---|
218 |
|
---|
219 | recptproto *collectproto = protos->getrecptproto (*col_here, logout);
|
---|
220 | if (get_info (args["href"], *col_here, args["l"], metadata, false, collectproto, response, logout)) {
|
---|
221 | if (!response.docInfo[0].metadata["section"].values[0].empty()) {
|
---|
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;
|
---|
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 | }
|
---|
233 | }
|
---|
234 | ++col_here;
|
---|
235 | }
|
---|
236 | }
|
---|
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 | }
|
---|
248 |
|
---|
249 | return true;
|
---|
250 | }
|
---|
251 |
|
---|
252 | #endif //GSDL_USE_EXTLINK_ACTION
|
---|