source: main/trunk/greenstone2/runtime-src/src/recpt/pagedbrowserclass.cpp@ 31687

Last change on this file since 31687 was 28913, checked in by ak19, 10 years ago

6th commit for security of cgiargs. Looked over all occurrences of setmacro in *action.cpp files

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
RevLine 
[668]1/**********************************************************************
2 *
3 * pagedbrowserclass.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
[7379]26#include "gsdl_modules_cfg.h"
27#ifdef GSDL_USE_PAGED_BROWSER
28
[668]29#include "pagedbrowserclass.h"
30#include <assert.h>
[15418]31#include "recptprototools.h"
[668]32#include "OIDtools.h"
[1559]33#include "gsdltools.h"
[28913]34#include "securitytools.h"
[668]35
36pagedbrowserclass::pagedbrowserclass () {
37}
38
39pagedbrowserclass::~pagedbrowserclass () {
40}
41
42// returns the name that specifies the browserclass type
43text_t pagedbrowserclass::get_browser_name () {
44 return "Paged";
45}
46
[7379]47browserclass* pagedbrowserclass::clone()
48{
49 return new pagedbrowserclass();
50}
[668]51
52void pagedbrowserclass::load_metadata_defaults (text_tset &metadata) {
53 metadata.insert ("Title");
54}
55
[912]56// if the "gp" (go to page) argument is set we need to set
[668]57// the "d" argument to the corresponding page
[937]58// also want to set "d" argument to first child if we're at
59// an 'Invisible' top level
[668]60void pagedbrowserclass::processOID (cgiargsclass &args, recptproto *collectproto,
[912]61 ostream &logout) {
[668]62
63 text_t &arg_d = args["d"];
64 text_t &arg_gp = args["gp"];
[912]65 text_tset metadata;
66 bool getParents = false;
67 FilterResponse_t response;
68
[10988]69 if (!arg_d.empty() && !arg_gp.empty()) {
[19047]70 text_t immediate_parent = get_parent (arg_d);
71
72 metadata.insert("Title");
73 get_children (immediate_parent, args["c"], args["l"], metadata,
74 getParents, collectproto, response, logout);
[668]75 ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
76 ResultDocInfo_tarray::iterator docend = response.docInfo.end();
77 while (dochere != docend) {
78 if ((*dochere).metadata["Title"].values[0] == arg_gp) {
[912]79 arg_d = (*dochere).OID;
[10988]80 return;
[668]81 }
[9620]82 ++dochere;
[668]83 }
[10988]84 }
[912]85
[10988]86 // The "gp" argument was either empty or invalid, so display the first child if given a document OID
87 if (!arg_d.empty() && is_top(arg_d)) { // if top level doc, check if not invisible
[912]88 metadata.insert("thistype");
[7432]89 if (get_info(arg_d, args["c"], args["l"], metadata, getParents, collectproto, response, logout)) {
[912]90 text_t type = response.docInfo[0].metadata["thistype"].values[0];
91 if (type=="Invisible") { // display first child
[937]92 arg_d = arg_d + ".fc";
[912]93 }
94 }
[668]95 }
96}
97
98int pagedbrowserclass::output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
[753]99 const text_t &/*collection*/, int /*colnumber*/,
100 format_t * /*formatlistptr*/, bool /*use_table*/,
101 text_tset &/*metadata*/, bool &/*getParents*/,
[727]102 recptproto * /*collectproto*/, displayclass &disp,
[753]103 outconvertclass &outconvert, ostream &textout,
104 ostream &/*logout*/) {
[668]105
106 // this browser class only handles document levels
107 if (args["d"].empty()) return 0;
108
109 if (section.OID != args["d"]) {
[28912]110 text_t httpprevarrow = "_httpdocument_&cl=" + encodeForURL(args["cl"]) + "&d=" + dm_safe(section.OID);
[1282]111 text_t parentarrow = "<a href=\"" + httpprevarrow + "\">_iconprev_</a>\n";
112 disp.setmacro ("httpprevarrow", "document", httpprevarrow);
[668]113 disp.setmacro ("parentarrow", "document", parentarrow);
114 return 0;
115 }
116
117 // must be at top level to get to here!
[1048]118 textout << outconvert << disp << "<b>" << section.metadata["Title"].values[0]
119 << "_document:textintro_</b>\n";
[668]120
121 return 0;
122}
123
124int pagedbrowserclass::output_section_group (FilterResponse_t &sections, cgiargsclass &args,
[753]125 const text_t &/*collection*/, int /*colnumber*/,
126 format_t * /*formatlistptr*/, bool /*use_table*/,
127 text_tset &/*metadata*/, bool &/*getParents*/,
[727]128 recptproto * /*collectproto*/, displayclass &disp,
[753]129 outconvertclass &outconvert, ostream &textout,
130 ostream &/*logout*/) {
[668]131
132 text_t &arg_d = args["d"];
133
134 // this browser class only handles document levels
135 if (arg_d.empty()) return 0;
136
137 text_t previousOID, previoustitle, nextOID, nexttitle;
[7618]138 text_t prevarrow, nextarrow, httpprevarrow, httpnextarrow;
[668]139 bool found = false;
140
141 // this should be our list of pages
142
143 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
144 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
145
146 while (thissection != endsection) {
147 if (arg_d == (*thissection).OID) {
148 found = true;
[753]149 textout << outconvert << disp
[943]150 << "<table><tr valign=top><td colspan=3><center><b>_page_"
[668]151 << (*thissection).metadata["Title"].values[0] << "</b>\n";
152 if (thissection != sections.docInfo.begin()) {
153 previousOID = (*(thissection-1)).OID;
154 previoustitle = (*(thissection-1)).metadata["Title"].values[0];
[1282]155 } else {
[7618]156 prevarrow = "_document:parentarrow_";
[1282]157 }
[668]158
[912]159 if ((thissection+1) != endsection) {
[668]160 nextOID = (*(thissection+1)).OID;
161 nexttitle = (*(thissection+1)).metadata["Title"].values[0];
162 }
163 break;
164 }
[9620]165 ++thissection;
[668]166 }
167
[928]168 if (!found) {
169 textout << outconvert << disp
170 << "<table><tr valign=top> <td colspan=3><center>\n";
171 }
[668]172 int numpages = sections.docInfo.size();
173 textout << outconvert << disp
174 << ("_document:textnumpages_(" + text_t(numpages) + ")</center></td></tr>\n");
175
[7618]176 disp.setmacro ("numpages", "document", numpages);
177
[1282]178 if (!found) {
[28912]179 httpnextarrow = "_httpdocument_&cl=" + encodeForURL(args["cl"]) + "&d=" + sections.docInfo[0].OID;
[1282]180 nextarrow = "<a href=\"" + httpnextarrow + "\">" +
181 sections.docInfo[0].metadata["Title"].values[0] + "_iconnext_</a>\n";
182
183 } else {
184 if (!previousOID.empty()) {
[28912]185 httpprevarrow = "_httpdocument_&cl=" + encodeForURL(args["cl"]) + "&d=" + dm_safe(previousOID);
[7618]186 prevarrow = "<a href=\"" + httpprevarrow + "\">_iconprev_" + previoustitle + "</a>\n";
[1282]187 }
188 if (!nextOID.empty()) {
[28912]189 httpnextarrow = "_httpdocument_&cl=" + encodeForURL(args["cl"]) + "&d=" + dm_safe(nextOID);
[1282]190 nextarrow = "<a href=\"" + httpnextarrow + "\">" + nexttitle + "_iconnext_</a>\n";
191 }
[668]192 }
193
[1282]194 if (!httpprevarrow.empty()) disp.setmacro ("httpprevarrow", "document", httpprevarrow);
195 if (!httpnextarrow.empty()) disp.setmacro ("httpnextarrow", "document", httpnextarrow);
196
[7618]197 if (!prevarrow.empty()) disp.setmacro ("prevarrow", "document", prevarrow);
198 if (!nextarrow.empty()) disp.setmacro ("nextarrow", "document", nextarrow);
199
[19047]200 if (!previoustitle.empty()) disp.setmacro ("prevtitle", "document", previoustitle);
201 if (!nexttitle.empty()) disp.setmacro ("nexttitle", "document", nexttitle);
[7618]202
[19047]203
[668]204 textout << outconvert << disp << "<tr valign=middle>\n"
[7618]205 << "<td align=right>" << prevarrow << "</td>\n"
[668]206 << "<td align=center valign=top>_document:gotoform_</td>"
207 << "<td align=left>" << nextarrow << "</td>\n"
208 << "</tr></table>\n";
209
210 return 0;
211}
[7379]212
213#endif //GSDL_USE_PAGED_BROWSER
Note: See TracBrowser for help on using the repository browser.