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