[24918] | 1 | #!@FULL_PERL_EXE@ -w
|
---|
[24916] | 2 |
|
---|
| 3 | # Need to specify the full path of Perl above, e.g. for Windows something like
|
---|
| 4 | #!C:\\Perl32\\bin\\perl -w
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | use strict;
|
---|
| 8 |
|
---|
| 9 | # Set this to 1 to work around IIS 6 craziness
|
---|
| 10 | my $iis6_mode = 0;
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | # IIS 6: for some reason, IIS runs this script with the working directory set to the Greenstone
|
---|
| 14 | # directory rather than the cgi-bin directory, causing lots of stuff to fail
|
---|
| 15 | if ($iis6_mode)
|
---|
| 16 | {
|
---|
| 17 | # Change into cgi-bin directory
|
---|
| 18 | chdir("cgi-bin");
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | # We use require and an eval here (instead of "use") to catch any errors loading the module (for IIS)
|
---|
| 23 | eval("require \"gsdlCGI.pm\"");
|
---|
| 24 | if ($@)
|
---|
| 25 | {
|
---|
| 26 | print STDOUT "Content-type:text/plain\n\n";
|
---|
| 27 | print STDOUT "ERROR: $@\n";
|
---|
| 28 | exit 0;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 |
|
---|
[24926] | 32 | sub generate_html_form
|
---|
[24916] | 33 | {
|
---|
[24926] | 34 | my ($isGSDL2,$site,$collect,$cl) = @_;
|
---|
[24916] | 35 |
|
---|
[24926] | 36 | my $html_form = <<EOT;
|
---|
[24916] | 37 | <html>
|
---|
| 38 | <head>
|
---|
| 39 | <title>HTML to Expeditee Frames</title>
|
---|
| 40 |
|
---|
[24922] | 41 | <base href=".." />
|
---|
| 42 |
|
---|
| 43 | <link type="text/css" href="ext/html-to-expeditee/jquery/css/le-frog/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
|
---|
| 44 | <script type="text/javascript" src="ext/html-to-expeditee/jquery/js/jquery-1.6.2.min.js"></script>
|
---|
| 45 | <script type="text/javascript" src="ext/html-to-expeditee/jquery/js/jquery-ui-1.8.16.custom.min.js"></script>
|
---|
| 46 | <script type="text/javascript" src="ext/html-to-expeditee/js/gsajax-min.js"></script>
|
---|
| 47 | <script type="text/javascript" src="ext/html-to-expeditee/js/html-to-expeditee.js"></script>
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 |
|
---|
[24916] | 51 | </head>
|
---|
| 52 | <body>
|
---|
[24922] | 53 | <form class="ui-widget">
|
---|
| 54 | Convert the collection
|
---|
| 55 | <input type="text"
|
---|
| 56 | class="ui-corner-all" style="padding: 4px;"
|
---|
| 57 | name="collect" value="$collect" id="collect" />
|
---|
| 58 | to Expeditee frames by traversing the classifier
|
---|
| 59 | <input type="text"
|
---|
| 60 | class="ui-corner-all" style="padding: 4px;"
|
---|
| 61 | name="cl" value="$cl" id="cl" />
|
---|
[24916] | 62 |
|
---|
[24922] | 63 | <input value="$site" id="site" type="hidden">
|
---|
| 64 | <input value="Go" id="go"
|
---|
| 65 | class="ui-button ui-widget ui-state-default ui-corner-all"
|
---|
| 66 | type="submit">
|
---|
[24916] | 67 |
|
---|
| 68 | </form>
|
---|
| 69 | <script type="text/javascript">
|
---|
| 70 | var docOIDs = [];
|
---|
| 71 | var numDocOIDs;
|
---|
| 72 |
|
---|
| 73 | \$(function() {
|
---|
| 74 | \$('#progress').progressbar();
|
---|
| 75 |
|
---|
| 76 | \$('#go').button().click(function() {
|
---|
| 77 | var collect = document.getElementById("collect").value;
|
---|
| 78 | if (collect.match(/^\\s*\$/)) {
|
---|
| 79 | alert("No collection specified");
|
---|
| 80 | return false;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | var cl = document.getElementById("cl").value;
|
---|
| 84 | if (cl.match(/^\\s*\$/)) {
|
---|
| 85 | alert("No classifier specified");
|
---|
| 86 | return false;
|
---|
| 87 | }
|
---|
| 88 | if (cl.match(/^\\d+\$/)) {
|
---|
[24920] | 89 | cl = "CL" + cl;
|
---|
[24916] | 90 | }
|
---|
| 91 |
|
---|
[24920] | 92 | var gs2=$isGSDL2;
|
---|
| 93 |
|
---|
| 94 | var url;
|
---|
| 95 | if (gs2) {
|
---|
| 96 | url = "library.cgi";
|
---|
| 97 | url += "?c="+collect +"&a=d&cl=" + cl;
|
---|
| 98 | }
|
---|
| 99 | else {
|
---|
[24922] | 100 | url = "dev";
|
---|
[24920] | 101 | url += "?c="+collect +"&a=b&rt=s&s=ClassifierBrowse&cl=" + cl;
|
---|
[24922] | 102 | url += "&excerptid=gs_content";
|
---|
[24920] | 103 | }
|
---|
| 104 |
|
---|
| 105 |
|
---|
[24916] | 106 | /* processing animation */
|
---|
| 107 |
|
---|
| 108 | docOIDs = [];
|
---|
| 109 | var outstandingURLs = [];
|
---|
| 110 | outstandingURLs.push(url);
|
---|
[24920] | 111 |
|
---|
[24916] | 112 | while (outstandingURLs.length>0) {
|
---|
| 113 | url = outstandingURLs.shift();
|
---|
| 114 |
|
---|
| 115 | var clHtml = urlGetSync(url);
|
---|
[24920] | 116 |
|
---|
[24916] | 117 | var aElems;
|
---|
[24922] | 118 | var workingTrav = document.getElementById("workingTraverse");
|
---|
| 119 | workingTrav.innerHTML = clHtml;
|
---|
| 120 | aElems = workingTrav.getElementsByTagName("a");
|
---|
[24916] | 121 |
|
---|
| 122 |
|
---|
| 123 | /* any links with a=d ... cl=??? => outstandingURLS */
|
---|
| 124 | /* any links with a=d ... d=??? => docOIDS */
|
---|
| 125 |
|
---|
[24920] | 126 | var actionRE = new RegExp("(\\\\?|&)a=(?:d|b)(&|\$)");
|
---|
[24916] | 127 | var clRE = new RegExp("(\\\\?|&)cl=" + cl + "\\\\.");
|
---|
[24920] | 128 | var docRE = new RegExp("(?:\\\\?|&)d=(.*?)(?:&|\$)");
|
---|
[24916] | 129 |
|
---|
| 130 | for (var i=0; i<aElems.length; i++) {
|
---|
| 131 | var aElem = aElems[i];
|
---|
| 132 | var href=aElem.href;
|
---|
| 133 | if (href && href.match(actionRE)) {
|
---|
| 134 | if (href.match(clRE)) {
|
---|
| 135 | outstandingURLs.push(href);
|
---|
| 136 | }
|
---|
| 137 | else if (href.match(docRE)) {
|
---|
[24920] | 138 |
|
---|
[24916] | 139 | var docMatch = docRE.exec(href);
|
---|
| 140 | var docOID = docMatch[1];
|
---|
[24920] | 141 |
|
---|
[24916] | 142 | docOIDs.push(docOID);
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | numDocOIDs = docOIDs.length;
|
---|
| 149 |
|
---|
| 150 | var iframe = document.getElementById("iframe");
|
---|
| 151 |
|
---|
| 152 | var docOID = docOIDs.shift();
|
---|
| 153 | console.log("doc oid = " + docOID);
|
---|
| 154 |
|
---|
[24920] | 155 | var url;
|
---|
| 156 | if (gs2) {
|
---|
| 157 | url = "library.cgi";
|
---|
| 158 | url += "?c="+collect +"&a=d&d=" + docOID;
|
---|
[24934] | 159 | }
|
---|
| 160 | else {
|
---|
[24922] | 161 | url = "dev";
|
---|
[24920] | 162 | url += "?c="+collect +"&a=d&d=" + docOID;
|
---|
[24922] | 163 | url += "&ed=1&dt=hierarchy";
|
---|
[24934] | 164 | // url += "&excerptid=gs_content";
|
---|
| 165 | }
|
---|
[24916] | 166 |
|
---|
[24934] | 167 | /* load iframe with document drawn from Greenstone collection */
|
---|
[24916] | 168 | iframe.src = url;
|
---|
| 169 |
|
---|
| 170 | var progressbar = document.getElementById("progressbar");
|
---|
| 171 | progressbar.style.display = "block";
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 | return false; });
|
---|
| 175 | });
|
---|
| 176 |
|
---|
| 177 | function pageLoaded()
|
---|
| 178 | {
|
---|
| 179 | var iframe = document.getElementById("iframe");
|
---|
| 180 |
|
---|
| 181 | if (iframe.src) {
|
---|
| 182 | if (iframe.style.display != "block") {
|
---|
| 183 | iframe.height = "90%";
|
---|
| 184 | iframe.style.display = "block";
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | var iframeDoc;
|
---|
| 188 | if ( iframe.contentDocument )
|
---|
| 189 | { /* FF */
|
---|
| 190 | iframeDoc = iframe.contentDocument;
|
---|
| 191 | }
|
---|
| 192 | else if ( iframe.contentWindow )
|
---|
| 193 | { /* IE */
|
---|
| 194 | iframeDoc = iframe.contentWindow.document;
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | var frameID = (numDocOIDs - docOIDs.length);
|
---|
| 198 | var progressPercent = frameID/numDocOIDs * 100;
|
---|
| 199 |
|
---|
| 200 | \$(function() {
|
---|
| 201 | \$('#progressbar').progressbar({ value: progressPercent })
|
---|
| 202 | });
|
---|
| 203 |
|
---|
[24934] | 204 | var gsContent = iframeDoc.getElementById("gs_content");
|
---|
| 205 |
|
---|
| 206 | /*
|
---|
| 207 | var gsContentPos = getElementPosition(gsContent);
|
---|
| 208 | var pxl = gsContentPos.xl;
|
---|
| 209 | var pxr = gsContentPos.xr;
|
---|
| 210 | */
|
---|
| 211 |
|
---|
| 212 | var expFrameTree = htmlToExpeditee(gsContent);
|
---|
| 213 |
|
---|
[24924] | 214 | var expFrame = JSON.stringify(expFrameTree);
|
---|
[24916] | 215 | //alert(expFrame);
|
---|
| 216 |
|
---|
| 217 | var collect = document.getElementById("collect").value;
|
---|
[24920] | 218 | var site = document.getElementById("site").value;
|
---|
[24916] | 219 |
|
---|
[24922] | 220 | var url = "cgi-bin/html-to-expeditee.pl";
|
---|
[24920] | 221 | var params = "c=" + collect;
|
---|
| 222 | if (site.match(/\\w/)) {
|
---|
| 223 | params += "&site=" + site;
|
---|
| 224 | }
|
---|
[24924] | 225 | params += "&a=generate-frame&fn=" + frameID;
|
---|
[24916] | 226 | params += "&json=" + escape(expFrame);
|
---|
| 227 |
|
---|
| 228 | var clHtml = urlPostSync(url,params);
|
---|
| 229 |
|
---|
| 230 | if (!clHtml.match(/html-to-expeditee saved frame/)) {
|
---|
| 231 | alert("Error processing url: " + url);
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | if (docOIDs.length>0) {
|
---|
| 235 | var docOID = docOIDs.shift();
|
---|
| 236 |
|
---|
| 237 | // console.log("doc oid = " + docOID);
|
---|
| 238 |
|
---|
[24924] | 239 | // is the following line used ????
|
---|
[24916] | 240 | var cl = document.getElementById("cl").value;
|
---|
| 241 |
|
---|
[24920] | 242 | var gs2 = $isGSDL2;
|
---|
| 243 | var url;
|
---|
| 244 |
|
---|
| 245 | if (gs2) {
|
---|
| 246 | url = "library.cgi";
|
---|
| 247 | url += "?c="+collect +"&a=d&d=" + docOID;
|
---|
| 248 | }
|
---|
| 249 | else {
|
---|
[24922] | 250 | url = "dev";
|
---|
[24920] | 251 | url += "?c="+collect +"&a=d&d=" + docOID;
|
---|
[24922] | 252 | url += "&ed=1&dt=hierarchy";
|
---|
[24934] | 253 | // url += "&excerptid=gs_content";
|
---|
[24920] | 254 | }
|
---|
| 255 |
|
---|
[24916] | 256 | iframe.src = url;
|
---|
| 257 | }
|
---|
| 258 | else {
|
---|
| 259 | var progressbar = document.getElementById("progressbar");
|
---|
| 260 | progressbar.style.display = "none";
|
---|
| 261 |
|
---|
| 262 | iframe.style.display = "none";
|
---|
| 263 | delete iframe.src;
|
---|
| 264 | }
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | </script>
|
---|
| 270 |
|
---|
| 271 | <div id="progressbar" width="100%"
|
---|
| 272 | style="display: none; margin: 10px; height: 10px;"></div>
|
---|
| 273 | <div id="workingTraverse" style="display: none"></div>
|
---|
| 274 |
|
---|
| 275 | <hr style="margin: 10px;">
|
---|
| 276 |
|
---|
| 277 | <iframe width="100%" id="iframe" style="display: none;"
|
---|
| 278 | onload="pageLoaded()"></iframe>
|
---|
| 279 |
|
---|
| 280 | </body>
|
---|
| 281 | </html>
|
---|
| 282 | EOT
|
---|
| 283 |
|
---|
[24926] | 284 | print "Content-type:text/html\n\n";
|
---|
| 285 | print $html_form;
|
---|
| 286 | }
|
---|
[24916] | 287 |
|
---|
[24926] | 288 | sub main
|
---|
| 289 | {
|
---|
[24916] | 290 |
|
---|
[24934] | 291 | # $ENV{'QUERY_STRING'} = "a=...";set-import-metadata&c=espresso-music&d=HASH012d6f72cde5dc48162f4a1d.1&metaname=annotation&metapos=0&metavalue=adfadfad";
|
---|
[24926] | 292 | # $ENV{'REQUEST_METHOD'} = "GET";
|
---|
| 293 |
|
---|
| 294 | my $gsdl_cgi = new gsdlCGI();
|
---|
| 295 |
|
---|
| 296 | # Load the Greenstone modules that we need to use
|
---|
| 297 | $gsdl_cgi->setup_gsdl();
|
---|
| 298 |
|
---|
| 299 | my $gsdlhome = $ENV{'GSDLHOME'};
|
---|
| 300 | $gsdl_cgi->checked_chdir($gsdlhome);
|
---|
| 301 |
|
---|
| 302 | require cgiactions::HtmlToExpediteeAction;
|
---|
| 303 |
|
---|
| 304 | # Useful debug statement for seeing what packages have been included
|
---|
| 305 | #### printf("%-45s%-s\n",$_,$INC{$_}) foreach (sort keys %INC);
|
---|
| 306 |
|
---|
| 307 | $gsdl_cgi->parse_cgi_args();
|
---|
| 308 |
|
---|
| 309 | # We don't want the gsdlCGI module to return errors and warnings in XML
|
---|
| 310 | $gsdl_cgi->{'xml'} = 0;
|
---|
| 311 |
|
---|
| 312 | my $fn = $gsdl_cgi->clean_param("fn"); # frame number
|
---|
| 313 |
|
---|
| 314 | if (defined $fn) {
|
---|
| 315 |
|
---|
| 316 | my $action = new HtmlToExpediteeAction($gsdl_cgi,$iis6_mode);
|
---|
| 317 |
|
---|
| 318 | $action->do_action();
|
---|
[24916] | 319 | }
|
---|
[24926] | 320 | else {
|
---|
| 321 | # generate form, pre-filled out with any useful values such
|
---|
| 322 | # as the collection and classifier value
|
---|
| 323 |
|
---|
| 324 | my $collect = $gsdl_cgi->clean_param("c");
|
---|
| 325 | my $cl = $gsdl_cgi->clean_param("cl");
|
---|
| 326 |
|
---|
| 327 | # Establish collect_dir using defining 'site' along the way if GS3
|
---|
| 328 |
|
---|
| 329 | my $site = undef;
|
---|
| 330 | my $isGSDL2 = undef;
|
---|
| 331 |
|
---|
| 332 | if ($gsdl_cgi->greenstone_version() == 2) {
|
---|
| 333 | $isGSDL2 = 1;
|
---|
| 334 | }
|
---|
| 335 | else {
|
---|
| 336 | $isGSDL2 = 0;
|
---|
| 337 |
|
---|
| 338 | # GS3 (and possible future versions) make use of 'site'
|
---|
| 339 | $site = $gsdl_cgi->clean_param("site");
|
---|
| 340 | if (!defined $site) {
|
---|
| 341 | $gsdl_cgi->generate_error("No site specified.");
|
---|
| 342 | }
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | generate_html_form($isGSDL2,$site,$collect,$cl);
|
---|
| 346 | }
|
---|
[24916] | 347 | }
|
---|
| 348 |
|
---|
| 349 |
|
---|
| 350 |
|
---|
| 351 | &main();
|
---|