source: main/tags/2.50-cdrom/gsdl/src/recpt/vlistbrowserclass.cpp

Last change on this file was 5124, checked in by kjdon, 21 years ago

made some small changes to allow the user to specify that documents should be detached by default - the links in the search list and classifier lists lead to new windows being opened for the documents. there is a new arg xx, which is 0 by default, but if its 1, it means that docs should be detached. affected classes are documentaction - this is where I defined the arg, just because the x arg is there, and the browser classes where the links to the documents are created. I have only changed vlist, hlist and datelist browser classes - I didn't think the others needed changing. to use this, you need to set the arg to 1 in main.cfg (for all collections), or add it to the receptionist thingy in a colls collect.cfg file

  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1/**********************************************************************
2 *
3 * vlistbrowserclass.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 "vlistbrowserclass.h"
27#include <assert.h>
28#include "OIDtools.h"
29#include "browsetools.h"
30
31vlistbrowserclass::vlistbrowserclass () {
32}
33
34vlistbrowserclass::~vlistbrowserclass () {
35}
36
37// returns the name that specifies the browserclass type
38text_t vlistbrowserclass::get_browser_name () {
39 return "VList";
40}
41
42void vlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
43 metadata.insert ("haschildren");
44 metadata.insert ("doctype");
45}
46
47text_t vlistbrowserclass::get_default_formatstring () {
48 return "<td valign=top>[link][icon][/link]</td>"
49 "<td valign=top>[srclink][srcicon][/srclink]</td>"
50 "<td valign=top>[highlight]{Or}{[Title],Untitled}[/highlight]"
51 "{If}{[Source],<br><i>([Source])</i>}</td>";
52}
53
54int vlistbrowserclass::output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
55 const text_t &collection, int colnumber,
56 format_t *formatlistptr, bool use_table,
57 text_tset &/*metadata*/, bool &/*getParents*/,
58 recptproto * collectproto, displayclass &disp,
59 outconvertclass &outconvert, ostream &textout,
60 ostream& logout) {
61
62 text_t link, icon;
63
64 text_t collink = collection;
65 if (!collink.empty()) collink = "&c=" + collink;
66
67 get_link_icon (section, args, collink, link, icon);
68 bool highlight = false;
69 if (!args["d"].empty()) {
70 if (args["d"] == section.OID) highlight = true;
71 } else
72 if (args["cl"] == section.OID) highlight = true;
73
74
75 if (use_table || colnumber > 0) {
76 textout << outconvert << "<table><tr valign=top>";
77 // get tab size
78 text_t tab; int itab;
79 disp.expandstring ("Global", "_tabwidth_", tab);
80 itab = tab.getint();
81 if (colnumber > 0) textout << outconvert << disp
82 << "<td><img src=\"_httpimg_/space.gif\" width="
83 << (itab*colnumber) << "></td>";
84 }
85
86 text_tmap options;
87 options["link"] = link;
88 options["icon"] = icon;
89 if (highlight) options["highlight"] = "1";
90 else options["highlight"] = "0";
91 options["DocImage"] = get_cover_image();
92 textout << outconvert << disp
93 << get_formatted_string (collection, collectproto,
94 section, disp, formatlistptr,
95 options, logout);
96
97 if (use_table || colnumber > 0) textout << outconvert << "</tr></table>\n";
98
99 return 1;
100}
101
102int vlistbrowserclass::output_section_group (FilterResponse_t &sections, cgiargsclass &args,
103 const text_t &collection, int colnumber,
104 format_t *formatlistptr, bool use_table,
105 text_tset &/*metadata*/, bool &/*getParents*/,
106 recptproto * collectproto, displayclass &disp,
107 outconvertclass &outconvert, ostream &textout,
108 ostream& logout) {
109
110 text_t link, icon;
111 text_t &arg_d = args["d"];
112 text_t &arg_cl = args["cl"];
113
114 text_t collink = collection;
115 if (!collink.empty()) collink = "&c=" + collink;
116
117 if (colnumber > 0) {
118 textout << outconvert << "<table><tr valign=top>";
119 // get tab size
120 text_t tab; int itab;
121 disp.expandstring ("Global", "_tabwidth_", tab);
122 itab = tab.getint();
123 if (colnumber > 0) textout << outconvert << disp
124 << "<td><img src=\"_httpimg_/space.gif\" width="
125 << (itab*colnumber) << "></td>";
126 textout << outconvert << "<td>";
127 }
128 if (use_table) textout << outconvert << "<table>\n";
129
130 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
131 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
132
133 // ** here lies Alan's hack to get 4 results per table row
134 int item = 0, perline;; // set perline to 1 normally
135 text_t fstring;
136
137 text_tmap options;
138 options["link"] = link;
139 options["icon"] = icon;
140 options["highlight"] = "0";
141 options["DocImage"] = get_cover_image();
142
143 if ( thissection != endsection ) { // only if there are results (else corrupts display)
144 fstring = get_formatted_string (collection, collectproto, *thissection,
145 disp, formatlistptr, options, logout);
146 // if format string
147 // has <td><t (e.g. <td><table>) then
148 // we assume it is an image and put it in 4 columns
149 if (fstring[5] == 't')
150 perline = 4;
151 else
152 perline = 1;
153 }
154
155 while (thissection != endsection) {
156 item++;
157 get_link_icon (*thissection, args, collink, link, icon);
158 bool highlight = false;
159 if (!arg_d.empty()) {
160 if (arg_d == (*thissection).OID) highlight = true;
161 } else
162 if (arg_cl == (*thissection).OID) highlight = true;
163
164 if ((item == 1 && use_table) || colnumber > 0 )
165 textout << outconvert << "<tr valign=top>\n";
166
167 options["link"] = link;
168 options["icon"] = icon;
169 if (highlight) options["highlight"] = "1";
170 else options["highlight"] = "0";
171 options["DocImage"] = get_cover_image();
172
173 textout << outconvert << disp
174 << " " << get_formatted_string (collection, collectproto, *thissection, disp,
175 formatlistptr, options, logout);
176
177 if ((item >= perline && use_table) || colnumber > 0) {
178 textout << outconvert << "\n</tr>";
179 item = 0;
180 }
181 textout << outconvert << "\n";
182 thissection ++;
183 }
184
185 if (use_table) textout << outconvert << "</table>\n";
186 if (colnumber > 0) textout << outconvert << "</td></tr></table>\n";
187
188 return 1;
189}
190
191
192// get_link_icon attempts to work out what type of icon should be displayed for
193// the given section and what it should link to.
194// [modification to allow default document detach settings -- kjdon]
195void vlistbrowserclass::get_link_icon (ResultDocInfo_t &section, cgiargsclass &args,
196 const text_t &collink, text_t &link, text_t &icon) {
197
198 link = "<a href=\"_httpdocument_" + collink;
199 text_t link_end = "\">";
200 text_t detach_link_end = "&x=1\" target=\\_blank>"; // to detach the link, and x=1 signifies it is a detached page
201 icon = "_document:icontext_";
202
203 text_t doctype;
204 int haschildren = 0;
205
206 if (section.metadata.count("haschildren")>0)
207 haschildren = section.metadata["haschildren"].values[0].getint();
208 if (section.metadata.count("doctype")>0)
209 doctype = section.metadata["doctype"].values[0];
210
211 text_t &arg_d = args["d"];
212 text_t &arg_cl = args["cl"];
213
214 if (args["a"] == "q") {
215 // query results list
216 link += "&cl=search&d=" + section.OID;
217
218 if (args["xx"] == "1") {
219 link += detach_link_end;
220 } else {
221 link += link_end;
222 }
223 if ((is_top (section.OID)) && (haschildren == 1)) icon = "_document:iconclosedbook_";
224 else if (haschildren == 1) icon = "_document:iconclosedfolder_";
225
226 } else if (!arg_d.empty()) {
227 // we are in a document - none of the links should be detach links
228 if (is_top(section.OID)) {
229 // we link back to the originating page eg search page or classifier page
230 icon = "_document:iconopenbook_";
231 if (arg_cl == "search") {
232 link = "<a href=\"_httpquery_\">";
233 }
234 else link += "&cl=" + arg_cl + "\">";
235
236 } else if (haschildren == 1) {
237 if ((args["gc"] == "1") ||
238 (is_child_of (section.OID, arg_d)) ||
239 (section.OID == arg_d)) {
240 icon = "_document:iconopenfolder_";
241 link += "&cl=" + arg_cl + "&d=" + section.OID + ".pr\">";
242 } else {
243 icon = "_document:iconclosedfolder_";
244 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
245 }
246 } else {
247 if (args["gt"] == "0") {
248 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
249 } else {
250 link += "&cl=" + arg_cl + "&d=" + section.OID + "#" + section.OID + "\">";
251 }
252 }
253
254 } else {
255 // classification level - links to docs may be detaching
256 if (haschildren == 1) {
257 if (doctype == "classify") {
258 if ((args["gc"] == "1") ||
259 (is_child_of (section.OID, arg_cl)) ||
260 (section.OID == arg_cl)) {
261 icon = "_document:iconopenbookshelf_";
262 link += "&cl=" + section.OID + ".pr\">";
263 } else {
264 icon = "_document:iconclosedbookshelf_";
265 link += "&cl=" + section.OID + "\">";
266 }
267 } else {
268
269 icon = "_document:iconclosedbook_";
270 link += "&cl=" + arg_cl + "&d=" + section.OID;
271 if (args["xx"] == "1") {
272 link += detach_link_end;
273 } else {
274 link += link_end;
275 }
276
277 }
278 } else {
279 if (doctype == "classify") link = "";
280 else {
281 link += "&cl=" + arg_cl + "&d=" + section.OID;
282 if (args["xx"] == "1") {
283 link += detach_link_end;
284 } else {
285 link += link_end;
286 }
287 }
288 }
289 }
290
291}
Note: See TracBrowser for help on using the repository browser.