root/blosxom_plugins/trunk/rast

Revision 12, 2.7 kB (checked in by miya, 3 years ago)

import blosxom plugins

  • Property svn:executable set to
Line 
1 # Blosxom Plugin: rast
2 # Author: Gosuke Miyashita <miya@mizzy.org>
3 # Version: 2005-05-03
4 # Blosxom Home/Docs/Licensing: http://www.blosxom.com/
5
6 package rast;
7
8 use strict;
9 use vars qw($query $summary);
10 use CGI qw(param url);
11 use Rast;
12 use HTML::TagFilter;
13
14 ## --- configurable variables ---
15 my $rast_db_dir = "$blosxom::plugin_state_dir/rastdb";
16 my $rast_encoding = "euc_jp";
17
18 sub start {
19     return 1;
20 }
21
22 sub filter {
23     my($pkg, $files) = @_;
24
25     ## create rast database
26     ## Usage: blosxom.cgi rast_create_db=1 [recache=all]
27     if (!$ENV{GATEWAY_INTERFACE} and param('rast_create_db')){
28         Rast->create(
29                      "$rast_db_dir",
30                      {
31                          encoding => $rast_encoding,
32                          preserve_text => 1,
33                          properties => [
34                                         ['filename', RAST_TYPE_STRING, RAST_PROPERTY_FLAG_SEARCH|RAST_PROPERTY_FLAG_UNIQUE],
35                                         ['last_modified', RAST_TYPE_DATE, RAST_PROPERTY_FLAG_SEARCH],
36                                         ],
37                          }
38                      );
39        
40     }
41
42     ## reindex database
43     if (!$ENV{GATEWAY_INTERFACE} and param('rast_reindex_db')){
44         my $db = Rast->open("$rast_db_dir", RAST_RDWR, {sync_threshold_chars => 1000000});
45         foreach my $file (keys %$files){
46             my $time = $files->{$file};
47             my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime($time);
48             my $date = sprintf("%04d-%02d-%02dT%02d:%02d:%02d", $year + 1900, $month + 1, $mday, $hour, $min, $sec);
49             my $options = [$file, $date];
50            
51             open(IN, $file) or die $!;
52             my @lines = <IN>;
53             my $lines;
54             my $tf = HTML::TagFilter->new( allow => {} );
55             foreach my $line (@lines){
56                 if($line !~ /^meta-/){
57                     $lines .= $tf->filter($line);
58                 }
59             }
60
61             $db->register($lines, $options);
62         }
63        
64         $db->close;
65        
66     }
67
68     ## search rast database
69     if(param('rast_search_query')){
70         $query = param('rast_search_query');
71
72         my $db = Rast->open("$rast_db_dir", RAST_RDWR, {sync_threshold_chars => 1000000});
73        
74         my $result = $db->search(
75                                  $query,
76                                  {
77                                      need_summary => 1,
78                                      properties => ['filename', 'last_modified'],
79                                  }
80                                  );
81        
82         my $hit_files;
83         while(my $row = $result->fetch){
84             $hit_files->{$row->{properties}->[0]} = $files->{$row->{properties}->[0]};
85             my @query = split(/\s/, $query);
86             map { $row->{summary} =~ s!$_!<strong class="search">$_</strong>!gi; } @query;
87             $summary->{$row->{properties}->[0]} = $row->{summary};
88         }
89        
90         if($result->hit_count){
91             %$files = %$hit_files;
92         } else {
93             %$files = {};
94         }
95
96         $db->close;
97     }
98
99 }
100
101 sub story {
102     my($pkg, $path, $fn, $story_ref, $title_ref, $body_ref) = @_;
103    
104     if(param('rast_search_query')){
105         $$body_ref = '<p class="entryBody">' . $summary->{"$blosxom::datadir$path/$fn.$blosxom::file_extension"} .
106             " ... <a href='$path/$fn.html'>[ÁŽÉôÆÉ€à]</a></p>";   
107     }
108 }
109
110 1;
Note: See TracBrowser for help on using the browser.