Changeset 87

Show
Ignore:
Timestamp:
04/02/06 12:59:38 (2 years ago)
Author:
miya
Message:

add function displaying related tags to tagging plugin

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • blosxom_plugins/trunk/tagging

    r42 r87  
    11# Blosxom Plugin: tagging 
    22# Author: Gosuke Miyashita <miya@mizzy.org> 
    3 # Version: 2006-01-05 
     3# Version: 2006-04-02 
    44# Blosxom Home/Docs/Licensing: http://www.blosxom.com/ 
    55 
     
    88use strict; 
    99use CGI qw(param url); 
    10 use vars qw($list $current_tag $find_tag $tags_in_this $tags_in_this_array); 
     10use vars qw($list $current_tag $find_tag $tags_in_this $tags_in_this_array $related_tags); 
    1111use Storable qw(store retrieve); 
    1212use Jcode; 
     
    5858            } 
    5959        } 
    60          
     60 
    6161        foreach my $tag (sort keys %tags){ 
    6262            my $encoded_tag = $tag; 
     
    6464            $list .= "<li><a href='$url?tag=$encoded_tag'>$tag</a> ($tags{$tag})</li>\n"; 
    6565        } 
    66          
    67     } else { 
     66    } 
     67    else { 
    6868        foreach my $tag (sort keys %$tags_list){ 
    6969            if(($find_tag and $tag =~ /^$find_tag/i) or !$find_tag){ 
     
    132132 
    133133 
    134     ## find entries that have tags  
     134    ## find entries that have tags 
    135135    if(param('tag')){ 
    136136        my @tags = split(/,/, param('tag')); 
    137137        my ($files_have_tags, $cnt); 
    138          
     138 
    139139        foreach my $tag (@tags){ 
    140140            if(!$files_have_tags and !$cnt){ 
    141141                %$files_have_tags = map { $_ => $files->{$_} } @{$tags_to_files->{$tag}}; 
    142             } else { 
     142            } 
     143            else { 
    143144                my $files_have_tags_tmp; 
    144145                foreach my $file (keys %$files_have_tags){ 
     
    156157 
    157158        %$files = %$files_have_tags; 
     159 
     160        my %related_tags; 
     161        for my $file (keys %$files){ 
     162            for my $tag (@{$files_to_tags->{$file}}){ 
     163                if(param('tag') !~ /$tag/){ 
     164                    $related_tags{$tag}++; 
     165                } 
     166            } 
     167        } 
     168 
     169        $related_tags = '<ul>'; 
     170        for my $tag (sort keys %related_tags){ 
     171            my $encoded_tag = $tag; 
     172            my $current_tag = param('tag'); 
     173            $encoded_tag =~ s/(\W)/sprintf("%%%02X", ord($1))/ego; 
     174            $related_tags .= "<li><a href='$blosxom::url/?tag=$current_tag,$encoded_tag'>$tag</a> ($related_tags{$tag})</li>\n"; 
     175        } 
     176        $related_tags .= '</ul>'; 
    158177    } 
    159178 
     
    169188    foreach (sort @tags) { 
    170189        my $encoded_tag = $_; 
    171         $encoded_tag =~ s/(\W)/sprintf("%%%02X", ord($1))/ego;              
     190        $encoded_tag =~ s/(\W)/sprintf("%%%02X", ord($1))/ego; 
    172191        $tags_in_this .= "<a href='$blosxom::url/?tag=$encoded_tag'>$_</a> "; 
    173192    }