#TopicPathプラグイン Ver 1.01 (2007/08/11) #Copyright(C) 2002-2007 Knight, All rights reserved. package webliberty::Plugin::TopicPath; use strict; use base qw(webliberty::Basis); use webliberty::Encoder; ### コンストラクタ sub new { my $class = shift; my $self = { init => shift, config => shift, query => shift, plugin => undef }; bless $self, $class; require $self->{init}->{plugin_dir} . 'TopicPath/init.cgi'; $self->{plugin} = &webliberty::Plugin::TopicPath::init::get_init; return $self; } ### メイン処理 sub run { my $self = shift; my $result; if (!$self->{query}->{plugin}) { my $info_path; if ($self->{init}->{script_file} =~ /([^\/\\]*)$/) { $info_path = "$self->{config}->{site_url}$1"; } if (($self->{query}->{no} or $self->{query}->{id}) and (!$self->{query}->{mode} or $self->{query}->{mode} eq 'comment' or $self->{query}->{mode} eq 'trackback')) { #個別表示ページ opendir(DIR, $self->{init}->{data_diary_dir}) or $self->error("Read Error : $self->{init}->{data_diary_dir}"); my @dir = sort { $b <=> $a } readdir(DIR); closedir(DIR); my($show_subj, $show_field, $flag); foreach my $entry (@dir) { if ($flag) { last; } if ($entry !~ /^\d\d\d\d\d\d\.$self->{init}->{data_ext}$/) { next; } open(FH, "$self->{init}->{data_diary_dir}$entry") or $self->error("Read Error : $self->{init}->{data_diary_dir}$entry"); while () { chomp; my($no, $id, $stat, $break, $comt, $tb, $field, $date, $name, $subj, $text, $color, $icon, $file, $host) = split(/\t/); if (!$stat) { next; } if (($self->{query}->{no} and $self->{query}->{no} == $no) or ($self->{query}->{id} and $self->{query}->{id} eq $id)) { $show_subj = $subj; $show_field = $field; $flag = 1; last; } } close(FH); } if ($show_field) { if ($show_field =~ /^(.+)<>(.+)$/) { $result = "$self->{plugin}->{top_string}$self->{plugin}->{delimiter_string}new($1)->url_encode . "\">$1$self->{plugin}->{delimiter_string}new("$1<>$2")->url_encode . "\">$2$self->{plugin}->{delimiter_string}$show_subj"; } else { $result = "$self->{plugin}->{top_string}$self->{plugin}->{delimiter_string}new($show_field)->url_encode . "\">$show_field$self->{plugin}->{delimiter_string}$show_subj"; } } else { $result = "$self->{plugin}->{top_string}$self->{plugin}->{delimiter_string}未分類$self->{plugin}->{delimiter_string}$show_subj"; } } elsif (!$self->{query}->{mode} and $self->{query}->{field}) { #分類一覧ページ my $show_field = $self->{query}->{field}; if ($show_field and $show_field =~ /^\d+$/) { my $i; open(FH, $self->{init}->{data_field}) or $self->error("Read Error : $self->{init}->{data_field}"); while () { chomp; if ($show_field == ++$i) { $show_field = $_; } } close(FH); } if ($show_field) { if ($show_field =~ /^(.+)<>(.+)$/) { $result = "$self->{plugin}->{top_string}$self->{plugin}->{delimiter_string}new($1)->url_encode . "\">$1$self->{plugin}->{delimiter_string}$2"; } else { $result = "$self->{plugin}->{top_string}$self->{plugin}->{delimiter_string}$show_field"; } } else { $result = "$self->{plugin}->{top_string}$self->{plugin}->{delimiter_string}未分類"; } } elsif ($self->{query}->{date}) { #日付別表示ページ my $date; if ($self->{query}->{date} =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) { $date = "$1年$2月$3日"; } elsif ($self->{query}->{date} =~ /^(\d\d\d\d)(\d\d)$/) { $date = "$1年$2月"; } elsif ($self->{query}->{date} =~ /^(\d\d\d\d)$/) { $date = "$1年"; } $result = "$self->{plugin}->{top_string}$self->{plugin}->{delimiter_string}$date"; } elsif ($self->{query}->{user}) { #投稿者別表示ページ my $show_name; open(FH, $self->{init}->{data_profile}) or $self->error("Read Error : $self->{init}->{data_profile}"); while () { chomp; my($user, $name, $text) = split(/\t/); if ($self->{query}->{user} eq $user) { $show_name = $name; last; } } close(FH); if (!$show_name) { $show_name = $self->{query}->{user}; } $result = "$self->{plugin}->{top_string}$self->{plugin}->{delimiter_string}$show_nameの記事"; } else { if (!$self->{plugin}->{top_mode}) { return; } $result = $self->{plugin}->{top_string}; } $result = "$self->{plugin}->{markup_begin}$result$self->{plugin}->{markup_end}"; } return $result; } 1;