#!/usr/local/bin/perl # ###################################################################### ### ### ### CGIリンク集管理システム T-Bookmark Ver.1.10 ### [1/4] 表示、検索 (tbookmark.cgi) ### (c) 1996-2000 Takahiro Nishida ### http://www.mytools.net/ ### ### ###################################################################### # ### 変数設定部 (詳細は上記ページをご覧下さい) ###################### ### 以下は配色の設定 ### $col_anm = "#FF0000"; # No.xx 〜 No.xx $col_num = "#000000"; # No. $col_ttl = "#006600"; # タイトル $col_gnr = "#000099"; # 分野 $col_day = "#9999FF"; # 日付 $col_url = "#888888"; # URL $col_key = "#9933CC"; # キーワード $col_pid = "#FF6600"; # ID ### (以下は表示に関するカスタマイズ) # 表示単位(1ページに〜件ずつ) $show_scale = 20; # 「登録順」を選んだとき何ページ分表示するか $default_pages = 3; # 検索記録を取るか(1→とる、0→とらない) $user_trace = 0; # 「全表示」が選択された場合の表示限度数(0→無制限) $show_max = 0; # 更新日から何日以内なら「New」「Up」を付けるか $new_date = 7; # "NEW" の画像 $image_new = ""; # "UP" の画像 $image_up = ""; ### 変数設定部 (ここまで)########################################### require './tblib.pl'; &main; sub main{ &init_variables; &check_input; &open_datafile; &process_data; &show_html; } ########## 変数の初期化 sub init_variables{ $basedir = $tblib'basedir; $datafile = "$basedir/tbdata.txt"; $genrefile = "$basedir/tbgenre.txt"; $tpfile = "$basedir/tb_main.html"; $ulogfile = "$basedir/userlog.txt"; } ########## 入力のチェック sub check_input{ &tblib'parseform; $s = $tblib'F{'s'}; # 検索文字列 $m = $tblib'F{'m'}; # 検索モード $g = $tblib'F{'g'}; # 分野コード $p = $tblib'F{'p'}; # ページ $sdec = &tblib'decode($s); ### スイッチ ($m =~ /i/) && ($sw_sid = 1); # ID表示 ($m =~ /k/) && ($sw_kwd = 1); # キーワード表示 ($m =~ /a/) && ($sw_all = 1); # 一気表示 } ########## データファイルのオープン sub open_datafile{ &tblib'openfile($datafile, *datas); &tblib'openfile($tpfile, *tps); &tblib'openfile($genrefile, *genres); &tblib'set_genre(*genres); } ########## データの加工 sub process_data{ local($us, $uw); # ユーザの行動記録用 if($s){ $us = "S"; $uw = $sdec; $stype = "文字列検索 [$sdec]"; &search_by_word($sdec); $g = ""; } elsif($g){ $stype = "分野検索 [$tblib'G{$g}]"; ($tblib'G{$g}) && &search_by_genre($g); $s = ""; } else{ $stype = "新着順"; $showno = ($sw_all) ? ($show_max || @datas) : $show_scale * $default_pages; &search_by_date($showno); } $hitno = @hits; # ヒット件数 ### 全表示の場合の表示単位セット ($sw_all) && ($show_scale = $show_max || $hitno); ### ユーザ行動の保存(トレースオン、検索、ページでない場合) ($user_trace) && ($us) && (!$p) && &record_action($us, $uw, $hitno); ### データを表示範囲でカット ($hitno) && (&cut_data); $resultmsg .= "◆ $stype:$hitno件 ◆"; } ############### 検索関数:ここから ############### ##### 単語検索 sub search_by_word{ local($word) = @_; # 検索文字の処理 $efind = $word; $efind =~ s/ / /g; $efind =~ s/(\W)/\\$1/g; @efinds = split(/\\\s+/, $efind); if($efinds[0] eq "\\-"){ shift(@efinds); $sw_or = 1; } local($match, $tmp, $url, $title, $com, $keywords); ### 検索 foreach(@datas){ ($tmp, $tmp, $tmp, $url, $title, $com, $keywords, $name, $email) = split("\t"); $str = "$url\t$title\t$com\t$keywords"; $match = 0; # マッチング foreach $pattern(@efinds){ if($str =~ /$pattern/i){ $match++; } } ### and検索の場合、マッチ数が文字数に一致しなければダメ (!$sw_or) && ($match < @efinds) && ($match = 0); ($match !=0) && unshift(@hits, $_); } } ########## 分野検索 sub search_by_genre{ local($gcode) = @_; local($id, $gbuf); foreach (@datas){ ($id, $gbuf) = split("\t"); ($gbuf =~ /:$gcode:/) && unshift(@hits, $_); } } ########## 日付順検索 sub search_by_date{ local($amount) = @_; ### 末尾が最新なのでひっくり返すだけ @hits = reverse(@datas); ($amount) && (@hits = splice(@hits, 0, $amount)); } ############### 検索関数:ここまで ############### ########## ユーザ行動の記録 sub record_action{ local($type, $word, $hitno) = @_; local($udate, $logline,); $udate = &tblib'get_time(0, 2); $logline[0] = "$udate\tTYPE:$type($word)\tHITS:$hitno\tHOST:$ENV{'REMOTE_HOST'}\t\n"; &tblib'updatefile($ulogfile, *logline, 1); } ########## データを表示単位で切り抜く sub cut_data{ $p = int($p); $allpage = int(($hitno-1) / $show_scale) + 1; ($p > 0) && ($p <= $allpage) || ($p = 1); # 表示範囲の特定 $t = $p * $show_scale; $f = $t - $show_scale + 1; ($t < $hitno) ? ($next = $p + 1) : ($t = $hitno); ($f > 1) && ($prev = $p - 1); # 前後を切り取る unshift(@hits, "dmy"); @hits = splice(@hits, $f, $show_scale); # 前後へのリンク $pagelink = "【No.$f 〜 No.$t】 / "; $linkcgi = "tbookmark.cgi?s=$s&g=$g&m=$m"; ($prev) && ($pagelink .= "前の$show_scale件 / "); for(1 .. $allpage){ $pagelink .= ($_ == $p) ? "$_ " : "$_ "; } ($next) && ($pagelink .= "/ 次の$show_scale件"); $pagelink .= ""; } ########## 表示 sub show_html{ local($urllist, $genrebar); $urllist = ($hitno) ? &html_urllist : &html_nohit; $genrebar = &html_genrebar; $C{'keys'} = $sdec; ### 表示用ハッシュ if($m){ $C{'normal'} = " [通常に戻す]"; $C{'m'} = $m; ($sw_sid) && ($C{'mode'} .= "[ID]"); ($sw_kwd) && ($C{'mode'} .= "[キーワード]"); ($sw_all) && ($C{'mode'} .= "[一気]"); } $C{'allno'} = @datas; # 総登録件数 ($s || $m || $g) || ($tptype = "firstmsg"); print "Content-type: text/html\n\n"; $tpfrag = 1; foreach (@tps){ (/^