source: gs3-extensions/html-to-expeditee/trunk/src/src/cgi-bin/generate-collection-space.pl.in@ 26748

Last change on this file since 26748 was 26748, checked in by davidb, 11 years ago

Basic functionality of generating a collection space frameset is now complete.

File size: 8.1 KB
Line 
1#!/cygdrive/c/strawberry/perl/bin/perl -w
2
3# Need to specify the full path of Perl above, e.g. for Windows something like
4#!C:\\Perl32\\bin\\perl -w
5
6use strict;
7
8# Set this to 1 to work around IIS 6 craziness
9my $iis6_mode = 0;
10
11
12# IIS 6: for some reason, IIS runs this script with the working directory set to the Greenstone
13# directory rather than the cgi-bin directory, causing lots of stuff to fail
14if ($iis6_mode)
15{
16 # Change into cgi-bin directory
17 chdir("cgi-bin");
18}
19
20
21# We use require and an eval here (instead of "use") to catch any errors loading the module (for IIS)
22eval("require \"gsdlCGI.pm\"");
23if ($@)
24{
25 print STDOUT "Content-type:text/plain\n\n";
26 print STDOUT "ERROR: $@\n";
27 exit 0;
28}
29
30sub generate_html_form
31{
32 # First create an overlay frame containing CL links.
33
34 # Then create frames with document links and images.
35
36 my ($isGSDL2,$site,$collect,$cl) = @_;
37
38 my $html_form = <<EOT;
39<html>
40 <head>
41 <title>Generate Collection Space for $collect</title>
42 <base href=".."/>
43
44 <link type="text/css" href="ext/html-to-expeditee/jquery/css/le-frog/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
45 <script type="text/javascript" src="ext/html-to-expeditee/jquery/js/jquery-1.6.2.min.js"></script>
46 <script type="text/javascript" src="ext/html-to-expeditee/jquery/js/jquery-ui-1.8.16.custom.min.js"></script>
47 <script type="text/javascript" src="ext/html-to-expeditee/js/gsajax-min.js"></script>
48 <script type="text/javascript" src="ext/html-to-expeditee/js/html-to-expeditee.js"></script>
49
50 </head>
51 <body>
52 <form class="ui-widget">
53
54 <p style="font-size: 16px; width: 550px; text-align: justify;">Generate a Collection Space to make it easier to view documents in GlamED/Expeditee. Before running this script you must have already converted the Greenstone collection to an Expeditee frameset. If you have <b>NOT</b> done this, click <a href="html-to-expeditee.pl?site=$site&collect=$collect&cl=CL1" target="_blank">here</a></p>
55
56 Generate a Collection Space for <input type="text" class="ui-corner-all" style="padding: 4px;" name="collect" value="$collect" id="collect"/> using the classifier <input type="text" class="ui-corner-all" style="padding: 4px;" name="cl" value="$cl" id="cl"/>
57
58 <input value="$site" name="site" id="site" type="hidden"> <input value="Go" id="go" class="ui-button ui-widget ui-state-default ui-corner-all" type="submit">
59 </form>
60
61 <script type="text/javascript">
62 var clPages = [];
63 var numClPages;
64
65 \$(function(){
66 \$('#progress').progressbar();
67
68 \$('#go').button().click(function(){
69 var collect = document.getElementById("collect").value;
70
71 if(collect.match(/^\\s*\$/)){
72 alert("No collection specified");
73 return false;
74 }
75
76 var cl = document.getElementById("cl").value;
77 if(cl.match(/^\\s*\$/)){
78 alert("No classifier specified");
79 return false;
80 }
81
82 if(cl.match(/^\\d+\$/)){
83 cl = "CL" + cl;
84 }
85
86 var gs2 = $isGSDL2;
87
88 var url;
89 if(gs2){
90 url = "library.cgi";
91 url += "?c=" + collect + "&a=d&cl=" + cl;
92 }else{
93 url = "library";
94 url += "?c=" + collect + "&a=b&rt=s&s=ClassifierBrowse&cl=" + cl;
95 url += "&excerptid=gs_content";
96 }
97
98 /* processing animation */
99
100 clPages = [];
101 var outstandingURLs = [];
102 var visitedURLs = {};
103
104 outstandingURLs.push(url);
105 visitedURLs[url] = 1;
106
107 while(outstandingURLs.length>0){
108
109 url = outstandingURLs.shift();
110
111 var clHtml = urlGetSync(url);
112
113 var aElems;
114 var workingTrav = document.getElementById("workingTraverse");
115 workingTrav.innerHTML = clHtml;
116 aElems = workingTrav.getElementsByTagName("a");
117
118 var actionRE = new RegExp("(\\\\/)(?:document|browse)(\\\\/)");
119 var clRE = new RegExp("(\\\\/)browse\\\\/" + cl + "(\\\\/\\\\d+)+(\$)");
120 var docRE = new RegExp("(?:\\\\/)document\\\\/(.*?)(?:\$)");
121
122 for(var i = 0; i < aElems.length; i++){
123 var aElem = aElems[i];
124 var href = aElem.href;
125
126 if(href && href.match(actionRE)){
127 if(href.match(clRE)){
128 if(!visitedURLs[href]){
129 var clPage = href;
130 console.log("Found a new cl link: " + clPage);
131 visitedURLs[clPage] = 1;
132 clPages.push(clPage);
133 }
134 }
135 }
136 }
137 }
138
139 numClPages = clPages.length;
140
141 var iframe = document.getElementById("iframe");
142
143 var url = clPages.shift();
144
145 iframe.src = url;
146
147 var progressbar = document.getElementById("progressbar");
148 progressbar.style.dispay = "block";
149
150
151 return false; });
152 });
153
154 function pageLoaded(){
155
156 var iframe = document.getElementById("iframe");
157
158 if(iframe.src){
159 if(iframe.style.display != "block"){
160 iframe.height = "90%";
161 iframe.style.display = "block";
162 }
163
164 var iframeDoc;
165
166 if(iframe.contentDocument){
167 /* FF */
168 iframeDoc = iframe.contentDocument;
169 }else if(iframe.contentWindow){
170 /* IE */
171 iframeDoc = iframe.contentWindow.document;
172 }
173
174 var frameNum = (numClPages - clPages.length);
175 var progressPercent = frameNum/numClPages * 100;
176
177 \$(function(){
178 \$('#progressbar').progressbar({ value: 0 });
179 });
180
181 var gsContent = iframeDoc.getElementById("gs_content");
182
183 //Need to change htmlToExpeditee code to account for links
184 var expFrameTree = htmlToExpeditee(gsContent);
185 var expFrame = JSON.stringify(expFrameTree);
186
187 var collect = document.getElementById("collect").value;
188 var site = document.getElementById("site").value;
189
190 var url = "cgi-bin/generate-collection-space.pl";
191 var params = "c=" + collect;
192
193 if(site.match(/\\w/)){
194 params += "&site=" + site;
195 }
196
197 params += "&a=generate-frame&fn=" + frameNum;
198 params += "&json=" + escape(expFrame);
199
200 var clHtml = urlPostSync(url,params);
201
202 if(!clHtml.match(/html-to-expeditee saved frame/)){
203 alert("Error processing url: " + url);s
204 }
205
206 if(clPages.length > 0){
207 var clPage = clPages.shift();
208
209 var cl = document.getElementById("cl").value;
210
211 var gs2 = $isGSDL2;
212
213 iframe.src = clPage;
214 console.log("iframe url: " + iframe.src + " ****");
215 }else{
216
217 var progressbar = document.getElementById("progressbar");
218 progressbar.style.display = "none";
219
220 iframe.style.display = "none";
221 delete iframe.src;
222 }
223
224
225 }
226
227
228 }
229 </script>
230
231 <div id="progressbar" width="100%" style="display: none; margin: 10px; height: 10px;"></div>
232
233 <div id="workingTraverse" style="display: none"></div>
234
235 <hr style="margin: 10px;">
236
237 <iframe width="100%" id="iframe" style="display: none;" onload="pageLoaded()"></iframe>
238</body>
239</html>
240EOT
241
242 print "Content-type:text/html\n\n";
243 print $html_form;
244}
245
246sub main
247{
248 my $gsdl_cgi = new gsdlCGI();
249
250 # Load the Greenstone modules that we need to use
251 $gsdl_cgi->setup_gsdl();
252
253 my $gsdlhome = $ENV{'GSDLHOME'};
254 $gsdl_cgi->checked_chdir($gsdlhome);
255
256 require cgiactions::CollectionSpaceAction;
257
258 $gsdl_cgi->parse_cgi_args();
259
260 # We don't want the gsdlCGI module to return errors and warnings in XML
261 $gsdl_cgi->{'xml'} = 0;
262
263 my $fn = $gsdl_cgi->clean_param("fn");
264
265 if(defined $fn){
266 #Generate a frame.
267 my $action = new CollectionSpaceAction($gsdl_cgi,$iis6_mode);
268 $action->do_action();
269 }else{
270 my $collect = $gsdl_cgi->clean_param("collect");
271 my $cl = $gsdl_cgi->clean_param("cl");
272
273 #Establish collect_dir using defining 'site' along the way if GS3
274 my $site = undef;
275 my $isGSDL2 = undef;
276
277 if($gsdl_cgi->greenstone_version() == 2){
278 $isGSDL2 = 1;
279 }else{
280 $isGSDL2 = 0;
281
282 #GS3 makes use of 'site'
283 $site = $gsdl_cgi->clean_param("site");
284
285 if(!defined $site){
286 $gsdl_cgi->generate_error("No site specified.");
287 }
288 }
289
290 generate_html_form($isGSDL2,$site,$collect,$cl);
291 }
292}
293
294&main();
Note: See TracBrowser for help on using the repository browser.