Add support for /+tags/foo.
authorSteinar H. Gunderson <sesse@debian.org>
Wed, 25 Jul 2007 18:39:17 +0000 (20:39 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Wed, 25 Jul 2007 18:39:17 +0000 (20:39 +0200)
perl/Sesse/pr0n/Index.pm
perl/Sesse/pr0n/Templates.pm
perl/Sesse/pr0n/pr0n.pm
templates/bilder.knatten.com/tag-title [new file with mode: 0644]
templates/default/tag-title [new file with mode: 0644]
templates/images.tg05.gathering.org/tag-title [new file with mode: 0644]
templates/itk-bilder.samfundet.no/tag-title [new file with mode: 0644]
templates/skoyen.bilder.knatten.com/tag-title [new file with mode: 0644]
templates/skoyen.bildereks.knatten.com/tag-title [new file with mode: 0644]

index 72fd824943d93ca9b460ba0a2cb756463b6fe4da..b5e0d113a277902caf3f3360d2989ed8aac9108c 100644 (file)
@@ -11,13 +11,20 @@ sub handler {
        my $apr = Apache2::Request->new($r);
        my $dbh = Sesse::pr0n::Common::get_dbh();
 
-       my ($event, $abspath, $datesort);
+       my ($event, $abspath, $datesort, $tag);
        if ($r->uri =~ /^\/\+all\/?/) {
                $event = '+all';
                $abspath = 1;
+               $tag = undef; 
 
                # augh, this needs 8.3, so we'll have to fiddle around a bit instead
                # $datesort = 'DESC NULLS LAST';
+               $datesort = 'DESC';
+       } elsif ($r->uri =~ /^\/\+tags\/([a-zA-Z0-9-]+)\/?$/) {
+               $tag = $1;
+               $event = "+tags/$tag";
+               $abspath = 1;
+               
                $datesort = 'DESC';
        } else {
                # Find the event
@@ -25,12 +32,13 @@ sub handler {
                        or error($r, "Could not extract event");
                $event = $1;
                $abspath = 0;
+               $tag = undef;
                $datesort = 'ASC';
        }
 
        # Fix common error: pr0n.sesse.net/event -> pr0n.sesse.net/event/
        if ($r->uri !~ /\/$/) {
-               $r->headers_out->{'location'} = "/$event/";
+               $r->headers_out->{'location'} = $r->uri . "/";
                return Apache2::Const::REDIRECT;
        }
 
@@ -60,7 +68,10 @@ sub handler {
        );
        
        my $where;
-       if ($event eq '+all') {
+       if (defined($tag)) {
+               my $tq = $dbh->quote($tag);
+               $where = " AND id IN ( SELECT image FROM tags WHERE tag=$tq )";
+       } elsif ($event eq '+all') {
                $where = '';
        } else {
                $where = ' AND event=' . $dbh->quote($event);
@@ -135,7 +146,7 @@ sub handler {
 
        my ($date, $name);
 
-       if ($event eq '+all') {
+       if ($event eq '+all' || defined($tag)) {
                $ref = $dbh->selectrow_hashref("SELECT EXTRACT(EPOCH FROM MAX(last_update)) AS last_update FROM events WHERE vhost=?",
                        undef, $r->get_server_name)
                        or error($r, "Could not list events", 404, "File not found");
@@ -172,7 +183,13 @@ sub handler {
        # Print the page itself
        if ($settings{'fullscreen'}) {
                $r->content_type("text/html; charset=utf-8");
-               Sesse::pr0n::Templates::print_template($r, "fullscreen-header", { title => "$name [$event]" });
+
+               if (defined($tag)) {
+                       my $title = Sesse::pr0n::Templates::process_template($r, "tag-title", { tag => $tag });
+                       Sesse::pr0n::Templates::print_template($r, "fullscreen-header", { title => $title });
+               } else {
+                       Sesse::pr0n::Templates::print_template($r, "fullscreen-header", { title => "$name [$event]" });
+               }
 
                my @files = ();
                while (my $ref = $q->fetchrow_hashref()) {
@@ -202,7 +219,12 @@ sub handler {
                        infobox => $infobox
                });
        } else {
-               Sesse::pr0n::Common::header($r, "$name [$event]");
+               if (defined($tag)) {
+                       my $title = Sesse::pr0n::Templates::process_template($r, "tag-title", { tag => $tag });
+                       Sesse::pr0n::Common::header($r, $title);
+               } else {
+                       Sesse::pr0n::Common::header($r, "$name [$event]");
+               }
                if (defined($date)) {
                        Sesse::pr0n::Templates::print_template($r, "date", { date => $date });
                }
index 8ff1e0353457360b2cc69dd3356610f23a8d4d79..3e65a9a9217767f9bb7592a4e6f917023c3aacea 100644 (file)
@@ -71,7 +71,7 @@ sub fetch_template {
        return $newcache->{'contents'};
 }
 
-sub print_template {
+sub process_template {
        my ($r, $template, $args) = @_;
        my $text = fetch_template($r, $template);
 
@@ -81,7 +81,12 @@ sub print_template {
                $text =~ s/$key/$value/g;
        }
 
-       $r->print($text);
+       return $text;
+}
+
+sub print_template {
+       my ($r, $template, $args) = @_;
+       $r->print(process_template($r, $template, $args));
 }
 
 1;
index c2d9dbc93ddefb1dc155b9f2ad76bd023c39cd57..b730aca3db18e621ccb7268d5f934d4dc4d604fe 100644 (file)
@@ -17,7 +17,7 @@ sub handler {
        my $r = shift;
 
        my $uri = $r->uri;
-       if ($uri eq '/' || $uri eq '/+tags' || $uri eq '/+tags/') {
+       if ($uri eq '/' || $uri =~ /^\/\+tags\/?$/) {
                return Sesse::pr0n::Listing::handler($r);
        } elsif ($uri eq '/robots.txt' ||
                 $uri eq '/pr0n.css' ||
@@ -67,8 +67,9 @@ sub handler {
                return Sesse::pr0n::Registry::handler($r);
        } elsif ($uri =~ m#^/wizard$#) {
                return Sesse::pr0n::Wizard::handler($r);
-       } elsif ($uri =~ m#^/[a-zA-Z0-9-]+/?$# ||
-                $uri =~ m#^/\+all/?$#) {
+       } elsif ($uri =~ /^\/[a-zA-Z0-9-]+\/?$/ ||
+                $uri =~ /^\/\+all\/?$/ ||
+                $uri =~ /^\/\+tags\/[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._-]+$#) {
                return Sesse::pr0n::Image::handler($r);
diff --git a/templates/bilder.knatten.com/tag-title b/templates/bilder.knatten.com/tag-title
new file mode 100644 (file)
index 0000000..80a6792
--- /dev/null
@@ -0,0 +1 @@
+Alle bilder som er tagget '%TAG%'
diff --git a/templates/default/tag-title b/templates/default/tag-title
new file mode 100644 (file)
index 0000000..d6ec5dd
--- /dev/null
@@ -0,0 +1 @@
+All images tagged '%TAG%'
diff --git a/templates/images.tg05.gathering.org/tag-title b/templates/images.tg05.gathering.org/tag-title
new file mode 100644 (file)
index 0000000..d6ec5dd
--- /dev/null
@@ -0,0 +1 @@
+All images tagged '%TAG%'
diff --git a/templates/itk-bilder.samfundet.no/tag-title b/templates/itk-bilder.samfundet.no/tag-title
new file mode 100644 (file)
index 0000000..80a6792
--- /dev/null
@@ -0,0 +1 @@
+Alle bilder som er tagget '%TAG%'
diff --git a/templates/skoyen.bilder.knatten.com/tag-title b/templates/skoyen.bilder.knatten.com/tag-title
new file mode 100644 (file)
index 0000000..80a6792
--- /dev/null
@@ -0,0 +1 @@
+Alle bilder som er tagget '%TAG%'
diff --git a/templates/skoyen.bildereks.knatten.com/tag-title b/templates/skoyen.bildereks.knatten.com/tag-title
new file mode 100644 (file)
index 0000000..80a6792
--- /dev/null
@@ -0,0 +1 @@
+Alle bilder som er tagget '%TAG%'