/
mobile.pl
executable file
·138 lines (108 loc) · 3.28 KB
/
mobile.pl
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
#!/usr/bin/perl
#
# Kareha mobile reader - v20071108 by Squeeks
#
# Configuration option:
use constant SHOWN_LINES => 4; # Truncates individual posts in a thread
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use lib '.';
BEGIN { require 'config.pl'; }
BEGIN { require 'config_defaults.pl'; }
BEGIN { require 'wakautils.pl'; }
BEGIN { require 'kareha.pl'; }
use constant MOBILE_HEAD_INCLUDE => q{
<?xml version="1.0" encoding="<const CHARSET>"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=<const CHARSET>" />
<title><const TITLE></title><style type="text/css">h1, h2, .replythread, .reply{margin-bottom:0;display:inline;}</style>
</head>
<body>
};
use constant FRONT_TEMPLATE => compile_template(MOBILE_HEAD_INCLUDE.q{
<p><b><const TITLE></b></p>
<hr />
<loop $threads>
<var $num>: <a href="<var $self>/<var $thread>/l10"><var $title or "Thread $thread"> (<var $postcount>)<if $closed or $permasage> <small>(<if $closed>closed</if><if !$closed and $permasage>permasaged</if>)</small></if></a><br>
</loop>
<br>
<a href="<var $self>/list"><const S_TOP></a>
<hr />
</body></html>
});
use constant LIST_TEMPLATE => compile_template(MOBILE_HEAD_INCLUDE.q{
<p><b><const TITLE></b></p>
<a href="<var $self>"><const S_RETURN></a>
<hr />
<loop $threads>
<var $num>: <a href="<var $self>/<var $thread>"><var $title or "Thread $thread"> (<var $postcount>)<if $closed or $permasage> <small>(<if $closed>closed</if><if !$closed and $permasage>permasaged</if>)</small></if></a><br>
</loop>
</body></html>
});
use constant THREAD_TEMPLATE => compile_template(MOBILE_HEAD_INCLUDE.q{
<loop $shownthreads>
<a href="<var $self>"><const S_RETURN></a> - <a href="<var $self>/<var $thread>/"><const S_ENTIRE></a> - <a href="<var $self>/<var $thread>/l10"><const S_LAST10></a><br>
<hr />
<h1><var $title or "Thread $thread"> (<var $postcount>)</h1><br>
<loop $posts>
<var $abbreviation>
<if $abbreviated>
<var sprintf(S_MO_TRUNC,"$self/$thread/$num","$num")>
</if>
</loop>
</loop>
</body></html>
});
eval "use constant S_MO_TRUNC => '<a href=\"%s\">Ganzen Beitrag anzeigen...</a>'" unless(defined &S_MO_TRUNC);
eval "use constant S_LAST10 => 'Die letzten 10 BeitrŠge anzeigen...'" unless(defined &S_LAST10);
my @threads=get_threads(1);
my @shownthreads;
my $showlist;
my ($threadnum,$ranges,$list,$info,$page)=$ENV{PATH_INFO}=~
m!/(?:([0-9]+)(?:/(.*)|)|(list)|(info)|p([0-9]+))!i;
if($threadnum)
{
if ($ranges =~/^\d/) { show_threads( filter_post_ranges($threadnum,$ranges,50) ); }
else {show_threads( filter_post_ranges($threadnum,$ranges,SHOWN_LINES) ); }
}
elsif($list)
{
show_list();
}
else
{
show_front();
}
sub show_threads(@)
{
my @shownthreads=@_;
print_http_header();
print THREAD_TEMPLATE->(
threads=>\@threads,
shownthreads=>\@shownthreads,
currpage=>$page,
);
}
sub show_front()
{
print_http_header();
my @thread_list;
for(1..THREADS_DISPLAYED)
{
last unless @threads;
push(@thread_list,shift(@threads));
}
print FRONT_TEMPLATE->( threads=>\@thread_list );
}
sub show_list()
{
print_http_header();
print LIST_TEMPLATE->( threads=>\@threads );
}
sub print_http_header()
{
print "Content-Type: ".get_xhtml_content_type(CHARSET,0)."\n\n";
}