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