Add the client code for the WinXP wizard.
authorSteinar H. Gunderson <sesse@debian.org>
Tue, 2 Jan 2007 22:15:14 +0000 (23:15 +0100)
committerSteinar H. Gunderson <sesse@debian.org>
Tue, 2 Jan 2007 22:15:14 +0000 (23:15 +0100)
files/pr0n.ico [new file with mode: 0644]
files/wizard.css [new file with mode: 0644]
files/wizard.js [new file with mode: 0644]
perl/Sesse/pr0n/Registry.pm [new file with mode: 0644]
perl/Sesse/pr0n/Wizard.pm [new file with mode: 0644]
perl/Sesse/pr0n/pr0n.pm
templates/bilder.knatten.com/wizard-description [new file with mode: 0644]
templates/default/wizard-description [new file with mode: 0644]
templates/default/wizard-footer [new file with mode: 0644]
templates/default/wizard-header [new file with mode: 0644]

diff --git a/files/pr0n.ico b/files/pr0n.ico
new file mode 100644 (file)
index 0000000..e45b578
Binary files /dev/null and b/files/pr0n.ico differ
diff --git a/files/wizard.css b/files/wizard.css
new file mode 100644 (file)
index 0000000..a97205f
--- /dev/null
@@ -0,0 +1,24 @@
+table {
+       border-collapse: collapse;
+}
+body {
+       font: message-box;
+       padding: 0px;
+       color: buttontext;
+       background-color: buttonface;
+}
+input, select {
+       font: message-box;
+}
+tr, td {
+       font: message-box;
+       margin: 0px;
+       padding: 0px;
+}
+p.question, tr.alternative {
+       margin-top: 15px;
+       margin-bottom: 5px;
+}
+p.warning {
+       color: red;
+}
diff --git a/files/wizard.js b/files/wizard.js
new file mode 100644 (file)
index 0000000..000e49c
--- /dev/null
@@ -0,0 +1,163 @@
+function OnBack()
+{
+       window.external.FinalBack();
+}
+
+function OnNext()
+{
+       var xml = window.external.Property("TransferManifest");
+       var files = xml.selectNodes("transfermanifest/filelist/file");
+       var form = document.getElementById('form1');
+
+       for (i = 0; i < files.length; i++) {
+               var postTag = xml.createNode(1, "post", "");
+               postTag.setAttribute("href", "http://pr0n-internal.sesse.net/webdav/upload/");
+               postTag.setAttribute("name", "image");
+
+               // event
+               if (form.existing.checked) {
+                       var dataTag = xml.createNode(1, "formdata", "");
+                       dataTag.setAttribute("name", "event");
+                       dataTag.text = "test"; //form.existingevent.value; FIXME
+                       postTag.appendChild(dataTag);
+               } else {
+                       var dataTag = xml.createNode(1, "formdata", "");
+                       dataTag.setAttribute("name", "neweventid");
+                       dataTag.text = form.neweventid.value;
+                       postTag.appendChild(dataTag);
+                       
+                       dataTag = xml.createNode(1, "formdata", "");
+                       dataTag.setAttribute("name", "neweventdate");
+                       dataTag.text = form.neweventdate.value;
+                       postTag.appendChild(dataTag);
+                       
+                       dataTag = xml.createNode(1, "formdata", "");
+                       dataTag.setAttribute("name", "neweventdesc");
+                       dataTag.text = form.neweventdesc.value;
+                       postTag.appendChild(dataTag);
+               }
+
+               // who took this
+               if (form.others.checked) {
+                       var dataTag = xml.createNode(1, "formdata", "");
+                       dataTag.setAttribute("name", "takenby");
+                       dataTag.text = form.other.value;
+                       postTag.appendChild(dataTag);
+               }
+               
+               // original file size (to avoid the evil resizing)
+               dataTag = xml.createNode(1, "formdata", "");
+               dataTag.setAttribute("name", "size");
+               dataTag.text = files.item(i).getAttribute("size");
+               postTag.appendChild(dataTag);
+       
+               files.item(i).appendChild(postTag);
+       }
+
+       var uploadTag = xml.createNode(1, "uploadinfo", "");
+       var htmluiTag = xml.createNode(1, "htmlui", "");
+       htmluiTag.text = "http://pr0n.sesse.net/test/";
+       uploadTag.appendChild(htmluiTag);
+       
+       /*var target = xml.createNode(1, "target", "");
+       target.setAttribute("href", "https://pr0n-internal.sesse.net/webdav/upload/test/");
+       uploadTag.appendChild(target); */
+
+       xml.documentElement.appendChild(uploadTag);
+       window.external.FinalNext();
+}
+
+function OnCancel()
+{
+       alert('OnCancel');
+}
+
+function somethingchanged()
+{
+       var valid = true;
+       var form = document.getElementById('form1');
+       var disable_existingevent, disable_newevent;
+
+       if (form.existing.checked) {
+               disable_existingevent = false;
+               disable_newevent = true;
+
+               if (form.existingevent.value == '') {
+                       valid = false;
+               }
+       } else {
+               disable_existingevent = true;
+               disable_newevent = false;
+
+               // this matches 1:1 the checks done on the server
+               var id = form.neweventid.value;
+               var date = form.neweventdate.value;
+               var desc = form.neweventdesc.value;
+               
+               if (id.match(/^\s*$/) || !id.match(/^([a-zA-Z0-9-]+)$/)) {
+                       valid = false;
+               }
+               if (date.match(/^\s*$/) || date.match(/[<>&]/) || date.length > 100) {
+                       valid = false;
+               }
+               if (desc.match(/^\s*$/) || desc.match(/[<>&]/) || desc.length > 100) {
+                       valid = false;
+               }
+       }
+
+       // enable/disable the "existing event" form
+       form.existingevent.disabled = disable_existingevent;
+       
+       var extexts = getElementsByClass(document, 'existingeventtext', '*');
+       for (i = 0; i < extexts.length; ++i) {
+               extexts[i].style.color = disable_existingevent ? 'gray' : '';
+       }
+
+       // enable/disable the "new event" form
+       form.neweventid.disabled = disable_newevent;
+       form.neweventdate.disabled = disable_newevent;
+       form.neweventdesc.disabled = disable_newevent;
+
+       var netexts = getElementsByClass(document, 'neweventtext', '*');
+       for (i = 0; i < netexts.length; ++i) {
+               netexts[i].style.color = disable_newevent ? 'gray' : '';
+       }
+
+       // and finally, the "who" form
+       var disable_who;
+       if (form.me.checked) {
+               disable_who = true;
+       } else {
+               disable_who = false;
+       
+               var who = form.other.value;
+               if (who.match(/^\s*$/) || who.match(/[<>&]/) || who.length > 100) {
+                       valid = false;
+               }
+       }
+
+       form.other.disabled = disable_who;
+
+       var whotexts = getElementsByClass(document, 'whotext', '*');
+       for (i = 0; i < whotexts.length; ++i) {
+               whotexts[i].style.color = disable_who ? 'gray' : '';
+       }
+
+
+       window.external.SetWizardButtons(true, valid, false);
+}
+
+function getElementsByClass(node,searchClass,tag) {
+       var classElements = new Array();
+       var els = node.getElementsByTagName(tag);
+       var elsLen = els.length;
+       for (i = 0, j = 0; i < elsLen; i++) {
+               if (els[i].className == searchClass) {
+                       classElements[j] = els[i];
+                       j++;
+               }
+       }
+       return classElements;
+}
+
+somethingchanged();
diff --git a/perl/Sesse/pr0n/Registry.pm b/perl/Sesse/pr0n/Registry.pm
new file mode 100644 (file)
index 0000000..14b5b14
--- /dev/null
@@ -0,0 +1,31 @@
+# Not related to Apache2::Registry; generates a .reg file for Windows XP to import.
+
+package Sesse::pr0n::Registry;
+use strict;
+use warnings;
+
+use Sesse::pr0n::Common qw(error dberror);
+use Apache2::Request;
+
+sub handler {
+       my $r = shift;
+       my $dbh = Sesse::pr0n::Common::get_dbh();
+       my $vhost = $r->get_server_name;
+       chomp (my $desc = Sesse::pr0n::Templates::fetch_template($r, 'wizard-description'));
+
+       $r->content_type("application/octet-stream");
+       $r->headers_out->add('Content-disposition' => 'attachment; filename="' . $vhost . '.reg"');
+
+       $r->print("Windows Registry Editor Version 5.00\r\n\r\n");
+       $r->print("[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Currentversion\\Explorer\\PublishingWizard\\PublishingWizard\\Providers\\$vhost]\r\n");
+       $r->print("\"Icon\"=\"http://$vhost/pr0n.ico\"\r\n");
+       $r->print("\"DisplayName\"=\"$vhost\"\r\n");
+       $r->print("\"Description\"=\"$desc\"\r\n");
+       $r->print("\"HREF\"=\"http://$vhost/wizard\"\r\n");
+
+       return Apache2::Const::OK;
+}
+       
+1;
+
+
diff --git a/perl/Sesse/pr0n/Wizard.pm b/perl/Sesse/pr0n/Wizard.pm
new file mode 100644 (file)
index 0000000..929b7db
--- /dev/null
@@ -0,0 +1,45 @@
+package Sesse::pr0n::Wizard;
+use strict;
+use warnings;
+
+use Sesse::pr0n::Common qw(error dberror);
+use Apache2::Request;
+
+sub handler {
+       my $r = shift;
+       my $apr = Apache2::Request->new($r);
+       my $dbh = Sesse::pr0n::Common::get_dbh();
+
+        # Internal? (Ugly?)
+       if ($r->get_server_name =~ /internal/ || $r->get_server_name =~ /skoyen\.bilder\.knatten\.com/) {
+               my $user = Sesse::pr0n::Common::check_access($r);
+               if (!defined($user)) {
+                       return Apache2::Const::OK;
+               }
+       }
+
+       # Find events
+       my $q = $dbh->prepare('SELECT id,date,name FROM events e JOIN last_picture_cache c ON e.id=c.event WHERE vhost=? ORDER BY last_picture DESC')
+               or dberror($r, "Couldn't list events");
+       $q->execute($r->get_server_name)
+               or dberror($r, "Couldn't get events");
+
+       $r->content_type('text/html; charset=utf-8');
+       $r->print(Sesse::pr0n::Templates::fetch_template($r, 'wizard-header'));
+       
+       while (my $ref = $q->fetchrow_hashref()) {
+               my $id = $ref->{'id'};
+               my $date = $ref->{'date'};
+               my $name = $ref->{'name'};
+               
+               $r->print("              <option value=\"$id\">$name</option>\n");
+       }
+
+       $r->print(Sesse::pr0n::Templates::fetch_template($r, 'wizard-footer'));
+
+       return Apache2::Const::OK;
+}
+       
+1;
+
+
index 0175c95547b8d3afa082371363bae076ef3ff263..55e64de907e983be97ef2e4edb49e3be5cd07053 100644 (file)
@@ -6,6 +6,8 @@ use Sesse::pr0n::Rotate;
 use Sesse::pr0n::Select;
 use Sesse::pr0n::WebDAV;
 use Sesse::pr0n::NewEvent;
+use Sesse::pr0n::Registry;
+use Sesse::pr0n::Wizard;
 
 package Sesse::pr0n::pr0n;
 use strict;    
@@ -27,6 +29,9 @@ sub handler {
                 $uri eq '/previous.png' ||
                 $uri eq '/next.png' ||
                 $uri eq '/close.png' ||
+                $uri eq '/wizard.js' ||
+                $uri eq '/wizard.css' ||
+                $uri eq '/pr0n.ico' ||
                 $uri =~ m#^/usage/([a-zA-Z0-9_.]+)$#) {
                $uri =~ s#^/##;
                my $fname = Sesse::pr0n::Common::get_base($r) . 'files/' . $uri;
@@ -58,6 +63,10 @@ sub handler {
                return Sesse::pr0n::Select::handler($r);
        } elsif ($uri =~ m#^/newevent$#) {
                return Sesse::pr0n::NewEvent::handler($r);
+       } elsif ($uri =~ m#^/registry$#) {
+               return Sesse::pr0n::Registry::handler($r);
+       } elsif ($uri =~ m#^/wizard$#) {
+               return Sesse::pr0n::Wizard::handler($r);
        } elsif ($uri =~ m#^/[a-zA-Z0-9-]+/?$#) {
                return Sesse::pr0n::Index::handler($r);
        } elsif ($uri =~ m#^/[a-zA-Z0-9-]+/(\d+x\d+/|original/)?(nobox/)?[a-zA-Z0-9._-]+$#) {
diff --git a/templates/bilder.knatten.com/wizard-description b/templates/bilder.knatten.com/wizard-description
new file mode 100644 (file)
index 0000000..b9e4980
--- /dev/null
@@ -0,0 +1 @@
+Bilder fra SVURR-arrangementer
diff --git a/templates/default/wizard-description b/templates/default/wizard-description
new file mode 100644 (file)
index 0000000..19244c0
--- /dev/null
@@ -0,0 +1 @@
+Personal image gallery
diff --git a/templates/default/wizard-footer b/templates/default/wizard-footer
new file mode 100644 (file)
index 0000000..7cb875e
--- /dev/null
@@ -0,0 +1,54 @@
+            </select>
+          </td>
+        </tr>
+        <tr class="alternative">
+          <td><input type="radio" name="event" value="new" id="new" onfocus="somethingchanged();" onclick="somethingchanged();" onchange="somethingchanged();" onkeyup="somethingchanged();" /></td>
+          <td><label for="new">A new event</label></td>
+          <td></td>
+        </tr>
+        <tr>
+          <td></td>
+          <td class="neweventtext">ID:</td>
+          <td class="neweventtext"><input type="text" name="neweventid" value="" size="25" onchange="somethingchanged();" onkeyup="somethingchanged();" /> &nbsp;&nbsp;(e.g. "revy03"; a-zA-Z0-9 and - only, no spaces)</td>
+        </td>
+        <tr>
+          <td></td>
+          <td class="neweventtext">Date:</td>
+          <td class="neweventtext"><input type="text" name="neweventdate" value="" size="25" onchange="somethingchanged();" onkeyup="somethingchanged();" /> &nbsp;&nbsp;(e.g. "27.-31. desember 2003")</td>
+        </td>
+        <tr>
+          <td></td>
+          <td class="neweventtext">Description:</td>
+          <td class="neweventtext"><input type="text" name="neweventdesc" value="" size="25" onchange="somethingchanged();" onkeyup="somethingchanged();" /> &nbsp;&nbsp;(e.g. "NyttÃ¥rsrevyen 2003")</td>
+        </td>
+      </table>
+      
+      <p class="question"><b>Who took these images?</b></p>
+      
+      <table>
+        <tr class="alternative">
+          <td><input type="radio" name="whotook" value="me" id="me" checked="checked" onfocus="somethingchanged();" onclick="somethingchanged();" onchange="somethingchanged();" onkeyup="somethingchanged();" /></td>
+          <td><label for="me">Myself</label></td>
+          <td></td>
+        </tr>
+        <tr class="alternative">
+          <td><input type="radio" name="whotook" value="others" id="others" onfocus="somethingchanged();" onclick="somethingchanged();" onchange="somethingchanged();" onkeyup="somethingchanged();" /></td>
+          <td><label for="others">Someone else</label></td>
+          <td></td>
+        <tr>
+        <tr>
+          <td></td>
+          <td class="whotext">Who:</td>
+          <td><input type="text" name="other" value="" size="20" onchange="somethingchanged();" onkeyup="somethingchanged();" /></td>
+        </tr>
+      </table>
+      
+      <p class="warning"><b>After pressing Next, be sure to turn OFF image
+        resizing; otherwise, you will get an error.</b></p>
+    </form>
+      
+    <script type="text/javascript" src="/wizard.js"></script>
+    <script>window.external.SetHeaderText('Upload photos to pr0n.sesse.net', 'Non-EXIF metadata');</script>
+  </body>
+</html>
+
diff --git a/templates/default/wizard-header b/templates/default/wizard-header
new file mode 100644 (file)
index 0000000..a50cc30
--- /dev/null
@@ -0,0 +1,22 @@
+<html>
+  <head>
+    <title>XP Publish Wizard</title>
+    <link rel="stylesheet" type="text/css" href="/wizard.css" />
+  </head>
+  <body onContextMenu="event.returnValue=false;">
+    <form id="form1">
+      <p class="question"><b>What event do you want to upload to?</b></p>
+      <table>
+        <tr>
+          <td><input type="radio" name="event" value="existing" id="existing" checked="checked" onfocus="somethingchanged();" onclick="somethingchanged()" onchange="somethingchanged();" onkeyup="somethingchanged();" /></td>
+          <td>
+            <label for="existing">An existing event</label>
+          </td>
+          <td></td>
+        </tr>
+        <tr class="alternative">
+          <td></td>
+          <td class="existingeventtext">Select one:</td>
+          <td>
+            <select name="event" id="existingevent" onchange="somethingchanged();" onclick="somethingchanged();" onkeyup="somethingchanged();">
+              <option value=""></option>