File: clkeitai.cgi

package info (click to toggle)
chalow 1.0-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 444 kB
  • sloc: perl: 1,534; makefile: 53
file content (148 lines) | stat: -rwxr-xr-x 3,740 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env perl
# $Id: clkeitai.cgi,v 1.4 2004/06/04 13:08:30 yto Exp $
# clkeitai.cgi - chalow ˤ HTML 줿ڡ򥱡Ǹ

# ƥɽ - 󥫡ʤɤϤʤƥɽؤΥѡ
# ƥɽ - 󥫡

use strict;

use Jcode;

use CGI;
my $q = new CGI;

# äɽǤХ
# ֤3k ȻפΤ;͵򸫤Τ褤ȡ
my $page_size_max = 2500;	


print "Content-type: text/html; charset=Shift_JIS\n\n";
print qq(<html><head><title>CHALOW Keitai</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"></head>);

if (defined $q->param('date')) {
    my $date = $q->param('date');
    if ($date =~ /^\d{4}-\d\d-\d\d$/) {
	# ƥसʤƥȥꤷƤȤн
	print "<body>Candidates: \n";
	for (my $i = 1; $i < 10; $i++) {
	    print qq(<a href="clkeitai.cgi?date=$date-$i">$date-$i</a>, );
	}
	print "...</body></html>\n";
	exit;
    }
    output_an_item($date);
} else {

    my $from = $q->param('from') || 1;
    output_simple_list($from);
}

### ƥɽ
sub output_an_item {
    my ($ymdi) = @_;
    my ($ymd, $ym) = ($ymdi =~ /^((\d{4}-\d\d)-\d\d)/);

    my $fn;
    if (-e "$ymd.html") {
	$fn = "$ymd.html";
    } elsif (-e "$ym.html") {
	$fn = "$ym.html";
    } else {
	print "<body>No Entry $ymdi</body></html>\n";
    }
	 
    open(F, "< $fn") or die "Can't open $fn : $!\n";
    binmode(F);
    my $all = join('', <F>);
    close(F);

    my $outstr = "no match";
    while ($all =~ m|start:$ymdi -->(.*?)<!-- end:$ymdi|smg) {
	my $new = $1;
	$new =~ s|<!--.+?-->||gsm;

	$new =~ s|<div class="itemauthor">.*?</div>||gsm; # Ҽ̾
	$new =~ s|</?p>||gsm;
	$new =~ s|</?pre.*?>||gsm;
	$new =~ s|</?div.*?>||gsm;
	$new =~ s|</?span.*?>||gsm;
	$new =~ s|<a name="$ymdi".+?>(.+?)</a>|$1|g; # إåΤ
	$new =~ s|\[<a href="cat.+?">(.+?)</a>\]|[$1]|g; # ƥΤ

	# img ν
	$new =~ s|(<a.+>)(<img.+>)(</a>)|$1&lt;>$3 $2 |gsm;
	$new =~ s|<img\s*src="(.+?\.([^\.]+?))"\s*alt="(.+?)".*?>|
	    qq(<a href="$1">[$3($2)]</a>)|exg;

	# inside ref
	$new =~ s|<a\shref="[\d\-]+.html\#([\d\-]+)">|
	    qq(<a href="clkeitai.cgi?date=$1">)|gxe;

	$new =~ s!^(<.+?>|)\t!$1!gsm; # ƬΥ֤ν

	$outstr = $new;
	last;
    }

    if (length($outstr) > $page_size_max) {
	$outstr = substr($outstr, 0, $page_size_max);
	$outstr =~ s|<[^>]*$||;
	$outstr =~ s|([\x00-\x7f]([\x80-\xff]{2})*)[\x80-\xff]$|$1|;
	$outstr .= "\n\n[ĹΤǰʹ߾άޤ]\n";
    }

    $outstr = jcode($outstr)->sjis;
    print "<body>$ymdi<p>$outstr</p></body></html>\n";
}

### ƥɽ
# anchor ȤʤʸƥɽؤΥ󥯤ꡣ
sub output_simple_list {
    my ($from) = @_;
    my $outstr = "";
    my $len = 0;
    my $last = 0;
    my $fn = "cl.itemlist";
    open(F, "< $fn") or die "Can't open $fn : $!\n";
    binmode(F);
    while (<F>) {
#	print "$from $.\n";
	if ($from <= $.) {
	    my ($d, $c) = (/^(.+?)\t(.+)$/);

	    $d =~ s|^.*?\[(\d{4}-\d\d-\d\d-\d+)\].*?$|
		qq(<a href="clkeitai.cgi?date=$1">$1</a>)|ex;
	    #$d =~ s/<.+?>//g;

	    $c =~ s/<.+?>//g;

	    my $URLCHARS = "[-_.!~*'a-zA-Z0-9;/?:@&=+,%\#\$]";
	    my $URLDELIM = "\\\\\\n[\\t ]+";
	    $c =~ s{(s?https?|ftp)://($URLCHARS+)}{$1://...}gm;
	    
	    my $new = "$d<br>$c<hr>\n";

	    if (length($new) > $page_size_max) { # a item > max
		$new =~ s/<br>.*$/<br>(礭ʤΤɽ)<hr>\n/;
	    }

	    if ($len + length($new) > $page_size_max) {
		$last = $.;
		last;
	    }
	    $len += length($new);
	    $outstr .= $new;
	}
    }
    close(F);
    $outstr = jcode($outstr)->sjis;
    print << "HTML"
<body>
$outstr
<a href="clkeitai.cgi?from=$last">&lt;&lt;</a>
</body></html>
HTML
    ;
}