[26744] | 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 |
|
---|
| 6 | use strict;
|
---|
| 7 |
|
---|
| 8 | # Set this to 1 to work around IIS 6 craziness
|
---|
| 9 | my $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
|
---|
| 14 | if ($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)
|
---|
| 22 | eval("require \"gsdlCGI.pm\"");
|
---|
| 23 | if ($@)
|
---|
| 24 | {
|
---|
| 25 | print STDOUT "Content-type:text/plain\n\n";
|
---|
| 26 | print STDOUT "ERROR: $@\n";
|
---|
| 27 | exit 0;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | sub 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 | \$(function(){
|
---|
| 63 | \$('#progress').progressbar();
|
---|
| 64 |
|
---|
| 65 | \$('#go').button().click(function(){
|
---|
| 66 | var collect = document.getElementById("collect").value;
|
---|
| 67 |
|
---|
| 68 | if(collect.match(/^\\s*\$/)){
|
---|
| 69 | alert("No collection specified");
|
---|
| 70 | return false;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | var cl = document.getElementById("cl").value;
|
---|
| 74 | if(cl.match(/^\\s*\$/)){
|
---|
| 75 | alert("No classifier specified");
|
---|
| 76 | return false;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | if(cl.match(/^\\d+\$/)){
|
---|
| 80 | cl = "CL" + cl;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | var gs2 = $isGSDL2;
|
---|
| 84 |
|
---|
| 85 | var url;
|
---|
| 86 |
|
---|
| 87 | if(gs2){
|
---|
| 88 | url = "library.cgi";
|
---|
| 89 | url += "?c=" + collect + "&a=d&cl=" + cl;
|
---|
| 90 | }else{
|
---|
| 91 | url = "library";
|
---|
| 92 | url += "?c=" + collect + "&a=b&rt=s&s=ClassifierBrowse&cl=" + cl;
|
---|
| 93 | url += "&excerptid=gs_content";
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | docOIDs = [];
|
---|
| 97 | var outstandingURLs = [];
|
---|
| 98 | var visitedURLs = {};
|
---|
| 99 |
|
---|
| 100 | outstandingURLs.push(url);
|
---|
| 101 | visitedURLs[url] = 1;
|
---|
| 102 |
|
---|
| 103 | while(outstandingURLs.length>0){
|
---|
| 104 | var clHtml = urlGetSync(url);
|
---|
| 105 |
|
---|
| 106 | var aElems;
|
---|
| 107 | var workingTrav = document.getElementById("workingTraverse");
|
---|
| 108 | workingTrav.innerHTML = clHtml;
|
---|
| 109 | aElems = workingTrav.getElementsByTagName("a");
|
---|
| 110 |
|
---|
| 111 | //console.log(aElems.length);
|
---|
| 112 |
|
---|
| 113 | var actionRE = new RegExp("(\\\\/)(?:document|browse)(\\\\/)");
|
---|
| 114 | var clRE = new RegExp("(\\\\/)browse\\\\/" + cl + "(\\\\/\\\\d+)+(\$)");
|
---|
| 115 | var docRE = new RegExp("(?:\\\\/)document\\\\/(.*?)(?:\$)");
|
---|
| 116 |
|
---|
| 117 | for(var i = 0; i < aElems.length; i++){
|
---|
| 118 | var aElem = aElems[i];
|
---|
| 119 |
|
---|
| 120 | var href = aElem.href;
|
---|
| 121 |
|
---|
| 122 | if(href && href.match(actionRE)){
|
---|
| 123 | if(href.match(clRE)){
|
---|
| 124 | if(!visitedURLs[href]){
|
---|
| 125 | outstandingURLs.push(href);
|
---|
| 126 | visitedURLs[href] = 1;
|
---|
| 127 |
|
---|
| 128 | }
|
---|
| 129 | }else if(href.match(docRE)){
|
---|
| 130 | if(!visitedURLs[href]){
|
---|
| 131 | var docMatch = docRE.exec(href);
|
---|
| 132 | var docOID = docMatch[1];
|
---|
| 133 |
|
---|
| 134 | console.log("found a new doc line: " + docOID);
|
---|
| 135 | visitedURLs[href] = 1;
|
---|
| 136 | docOIDs.push(docOID);
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | numDocOIDs = docOIDs.length;
|
---|
| 144 | });
|
---|
| 145 |
|
---|
| 146 | return false;
|
---|
| 147 | });
|
---|
| 148 |
|
---|
| 149 | function pageLoaded(){
|
---|
| 150 |
|
---|
| 151 | \$(function(){
|
---|
| 152 | \$('#progressbar').progressbar({ value: 0 });
|
---|
| 153 | });
|
---|
| 154 | }
|
---|
| 155 | </script>
|
---|
| 156 |
|
---|
| 157 | <div id="progressbar" width="100%" style="display: none; margin: 10px; height: 10px;"></div>
|
---|
| 158 |
|
---|
| 159 | <!-- set display to "none" for this div-->
|
---|
| 160 | <div id="workingTraverse" style="display: none"></div>
|
---|
| 161 |
|
---|
| 162 | <hr style="margin: 10px;">
|
---|
| 163 |
|
---|
| 164 | <iframe width="100%" id="iframe" style="display: none;" onload="pageLoaded()"></iframe>
|
---|
| 165 | </body>
|
---|
| 166 | </html>
|
---|
| 167 | EOT
|
---|
| 168 |
|
---|
| 169 | print "Content-type:text/html\n\n";
|
---|
| 170 | print $html_form;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | sub main
|
---|
| 174 | {
|
---|
| 175 | my $gsdl_cgi = new gsdlCGI();
|
---|
| 176 |
|
---|
| 177 | # Load the Greenstone modules that we need to use
|
---|
| 178 | $gsdl_cgi->setup_gsdl();
|
---|
| 179 |
|
---|
| 180 | my $gsdlhome = $ENV{'GSDLHOME'};
|
---|
| 181 | $gsdl_cgi->checked_chdir($gsdlhome);
|
---|
| 182 |
|
---|
| 183 | require cgiactions::HtmlToExpediteeAction;
|
---|
| 184 |
|
---|
| 185 | $gsdl_cgi->parse_cgi_args();
|
---|
| 186 |
|
---|
| 187 | # We don't want the gsdlCGI module to return errors and warnings in XML
|
---|
| 188 | $gsdl_cgi->{'xml'} = 0;
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | #my $action = new HtmlToExpediteeAction($gsdl_cgi,$iis6_mode);
|
---|
| 192 |
|
---|
| 193 | #$action->do_action();
|
---|
| 194 |
|
---|
| 195 | my $collect = $gsdl_cgi->clean_param("collect");
|
---|
| 196 | my $cl = $gsdl_cgi->clean_param("cl");
|
---|
| 197 |
|
---|
| 198 | #Establish collect_dir using defining 'site' along the way if GS3
|
---|
| 199 | my $site = undef;
|
---|
| 200 | my $isGSDL2 = undef;
|
---|
| 201 |
|
---|
| 202 | if($gsdl_cgi->greenstone_version() == 2){
|
---|
| 203 | $isGSDL2 = 1;
|
---|
| 204 | }else{
|
---|
| 205 | $isGSDL2 = 0;
|
---|
| 206 |
|
---|
| 207 | #GS3 makes use of 'site'
|
---|
| 208 | $site = $gsdl_cgi->clean_param("site");
|
---|
| 209 |
|
---|
| 210 | if(!defined $site){
|
---|
| 211 | $gsdl_cgi->generate_error("No site specified.");
|
---|
| 212 | }
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | generate_html_form($isGSDL2,$site,$collect,$cl);
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | &main(); |
---|