[Rt-commit] r11054 - rt/branches/3.8-TESTING/html/NoAuth/iCal

ruz at bestpractical.com ruz at bestpractical.com
Wed Mar 12 18:24:35 EDT 2008


Author: ruz
Date: Wed Mar 12 18:24:35 2008
New Revision: 11054

Added:
   rt/branches/3.8-TESTING/html/NoAuth/iCal/dhandler

Log:
* add iCal dhandler we missed on commit

Added: rt/branches/3.8-TESTING/html/NoAuth/iCal/dhandler
==============================================================================
--- (empty file)
+++ rt/branches/3.8-TESTING/html/NoAuth/iCal/dhandler	Wed Mar 12 18:24:35 2008
@@ -0,0 +1,89 @@
+<%init>
+use Data::ICal;
+use Data::ICal::Entry::Event;
+use Date::ICal;
+use Encode ();
+
+my $path = $m->dhandler_arg;
+
+my $notfound = sub {
+    $r->header_out("Status" => "404 Not Found");
+    $m->clear_and_abort;
+};
+
+$notfound->() unless $path =~ m!^([^/]+)/([^/]+)/(.*)(\.(ical|ics))?!;
+
+my ($name, $auth, $search) = ($1, $2, $3);
+$name = Encode::decode_utf8( $name );
+my $user = RT::User->new( $RT::SystemUser );
+$user->Load( $name );
+$notfound->() unless $user->id;
+
+# Unescape the query
+$search =~ s/\%([0-9a-z]{2})/chr(hex($1))/gei;
+
+my $secret = $user->AuthToken;
+$notfound->() unless $auth eq substr(Digest::MD5::md5_hex($secret.$search),0,16);
+
+$search = Encode::decode_utf8( $search );
+
+my $cu = RT::CurrentUser->new;
+$cu->Load($user);
+my $tickets = RT::Tickets->new( $cu );
+$tickets->FromSQL($search);
+
+$r->header_out("Content-Type" => "text/calendar; charset=utf-8");
+
+my $feed = Data::ICal->new();
+$feed->add_properties('x-wr-calname' => ["RT due dates" => {value => "TEXT"}]);
+$feed->add_properties('x-wr-caldesc' => ["Due dates for RT tickets: $search" => {value => "TEXT"}]);
+$feed->add_properties('calscale' => ['gregorian']);
+$feed->add_properties('method'   => ['publish']);
+$feed->add_properties('prodid'   => ["-//$RT::rtname//"]);
+
+my $ic = sub {
+    my $time = shift;
+
+    if (ref $time) {
+        $time = Date::ICal->new( epoch => $time->Unix )->ical;
+    } else {
+        $time = Date::ICal->new( epoch => $time )->ical;
+    }
+    $time =~ s/T.*// if shift;
+    return $time;
+};
+
+while (my $t = $tickets->Next) {
+    next unless $t->DueObj->Unix > 0;
+
+    my $starttime = $t->StartsObj->Unix > 0 ? $t->StartsObj : $t->CreatedObj;
+
+    my $start = Data::ICal::Entry::Event->new;
+    my $end   = Data::ICal::Entry::Event->new;
+    $_->add_properties(
+        url       => $RT::WebURL . "?q=".$t->id,
+        organizer => $t->OwnerObj->Name,
+        dtstamp   => $ic->(time),
+        created   => $ic->($t->CreatedObj),
+       'last-modified' => $ic->($t->LastUpdatedObj),
+    ) for $start, $end;
+
+    $start->add_properties(
+        summary   => "Start: ".$t->Subject,
+        dtstart   => $ic->($starttime, 1),
+        dtend     => $ic->($starttime, 1),
+    );
+    $end->add_properties(
+        summary   => "Due: ".$t->Subject,
+        dtstart   => $ic->($t->DueObj, 1),
+        dtend     => $ic->($t->DueObj, 1),
+    );
+
+    $feed->add_entry($start);
+    $feed->add_entry($end);
+}
+
+$m->clear_buffer;
+$m->out($feed->as_string);
+$m->abort;
+</%init>


More information about the Rt-commit mailing list