-
Notifications
You must be signed in to change notification settings - Fork 1
/
ss_selector
219 lines (181 loc) · 5.7 KB
/
ss_selector
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# Blosxom Plugin: ss_selector
# Author(s): mustan <[email protected]>
# Version: 2005-04-17
package ss_selector;
use strict;
use vars qw($header $debugMes $form);
my (@styleTitle, @stylePath, @styleMedia);
my $styleNum = 0;
my ($form_label, $form_button, $form_accesskey,
$no_styleTitle,
$cookie_path,
$use_xhtml, $xhtml_endTag);
my (%COOKIES, %FORM);
# --- Configurable variables -----
$form_label = 'Select Style'; # Character string displayed in label of form
$form_accesskey = 'S'; # Key to activate selection box
$form_button = 'submit'; # Character string displayed in submit button
$no_styleTitle = 'No-Style'; # Character string when style is not applied
$cookie_path = '/'; # Preservation path of Cookie
$use_xhtml = 0; # 0: XHTML Mode is not Applied 1: XHTML Mode is Applied
#&add_style('Style Title', 'Style URL', 'Media Type');
# ex)&add_style('WhiteBack', 'http://mustan.sakura.ne.jp/style/whiteback.css', 'screen,tv');
#---------------------------------
&add_style($no_styleTitle, "", "");
if($use_xhtml == 1){
$xhtml_endTag = ' /';
}
&readForm();
&get_cookies();
sub start{
my $count;
my $ss;
my $f_findFirstStyle = 0;
if($FORM{'ss'}){
for($count=0;$count<$styleNum;$count++){
if($FORM{'ss'} eq $styleTitle[$count]){
if($FORM{'ss'} ne $no_styleTitle){
$header =
<<OUTPUT;
<link rel="stylesheet" type="text/css" href="$stylePath[$count]" title="$styleTitle[$count]" media="$styleMedia[$count]"$xhtml_endTag>
OUTPUT
}
$f_findFirstStyle = 1;
&set_cookie("ss", "$FORM{'ss'}", 30, $cookie_path);
last;
}
}
}
elsif($COOKIES{'ss'}){
for($count=0;$count<$styleNum;$count++){
if($COOKIES{'ss'} eq $styleTitle[$count]){
if($COOKIES{'ss'} ne $no_styleTitle){
$header =
<<OUTPUT;
<link rel="stylesheet" type="text/css" href="$stylePath[$count]" title="$styleTitle[$count]" media="$styleMedia[$count]"$xhtml_endTag>
OUTPUT
}
$f_findFirstStyle = 1;
&set_cookie("ss", "$styleTitle[$count]", 30, $cookie_path);
last;
}
}
}
for($count=0;$count<$styleNum;$count++){
if($f_findFirstStyle == 0){
$header =
<<OUTPUT;
<link rel="stylesheet" type="text/css" href="$stylePath[$count]" title="$styleTitle[$count]" media="$styleMedia[$count]"$xhtml_endTag>
OUTPUT
$f_findFirstStyle = 1;
&set_cookie("ss", "$styleTitle[$count]", 30, $cookie_path);
}
elsif(($styleTitle[$count] ne $COOKIES{'ss'}) && ($stylePath[$count]) && ($f_findFirstStyle == 1)){
$header .=
<<OUTPUT
<link rel="alternate stylesheet" type="text/css" href="$stylePath[$count]" title="$styleTitle[$count]" media="$styleMedia[$count]"$xhtml_endTag>
OUTPUT
}
}
$header =~ s/\n$//;
1;
}
sub filter{
my $options;
my $count;
$form =
<<OUT;
<form id="ss_selectorForm" method="get" action="$blosxom::url$ENV{'PATH_INFO'}">
<p id="ss_selectorForm_paragraph">
::label::
<input type="submit" value="$form_button"$xhtml_endTag>
</p>
</form>
OUT
if($form_label){
$form =~ s/::label::/<label for=\"ss_selector_selectbox\" accesskey=\"::form_accesskey::\">\n$form_label ::form_accesskey:: \n::label::\n<\/label>/;
if($form_accesskey){
$form =~ s/::form_accesskey::/$form_accesskey/;
$form =~ s/ ::form_accesskey:: /<sup>\($form_accesskey\)<\/sup>/;
}
}
for($count=0;$count<$styleNum;$count++){
if($styleTitle[$count] eq $COOKIES{'ss'}){
$options .= "<option value=\"$styleTitle[$count]\" label=\"$styleTitle[$count]\" selected>$styleTitle[$count]<\/option>\n";
}
elsif($styleTitle[$count]){
$options .= "<option value=\"$styleTitle[$count]\" label=\"$styleTitle[$count]\">$styleTitle[$count]<\/option>\n";
}
}
$form =~ s/::label::/<select name=\"ss\" id=\"ss_selector_selectbox\">\n$options<\/select>/;
return 1;
}
sub add_style {
$styleTitle[$styleNum] = $_[0];
$stylePath[$styleNum] = $_[1];
if(!$_[2]){
$styleMedia[$styleNum] = 'all';
}
else{
$styleMedia[$styleNum] = $_[2];
}
$styleNum = $styleNum + 1;
return 1;
}
sub get_cookies{
my ($work, $name, $value);
for $work (split(/; */, $ENV{'HTTP_COOKIE'})) {
($name, $value) = split(/=/, $work);
$value =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack("C", hex($1))/eg;
$COOKIES{$name} = $value;
}
return 1;
}
sub set_cookie{
my($str, $limit, $value, $path);
if(!$cookie_path){
$path = '/';
}
$COOKIES{$_[0]} = $_[1];
$value = $_[1];
$value =~ s/(\W)/sprintf("%%%02X", unpack("C", $1))/eg;
$limit = gmtime(time + (86400 * $_[2]));
$limit =~ s/^(...) (...) (..) (........) (....).*/$1, $3-$2-$5 $4 GMT\;/;
if ($_[3] ne '') {
$path = " path=$_[3];";
}
else {
$path = '';
}
if ($_[4] == 0) {
print "Set-Cookie: $_[0]=$value; expires=$limit$path\n";
}
elsif($_[4] == 2){
print "Set-Cookie: expires=$limit$path\n";
}
# else {
# print "<meta http-equiv=\"Set-Cookie\" content=\"$_[0]=$value; expires=$limit$path\">\n";
# }
}
sub readForm{
my ($query_string, $work, @work, $name, $value);
if ($ENV{'REQUEST_METHOD'} eq "POST") {
# read(STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
$query_string = '';
}
else {
$query_string = $ENV{'QUERY_STRING'};
}
@work = split(/&/, $query_string);
foreach $work (@work) {
($name, $value) = split(/=/, $work);
$value =~ tr/+/ /;
$value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg;
# &jcode'convert(*value, "euc");
$FORM{$name} = $value;
}
}
1;
__END__
=head1 NAME
Blosxom Plug-in: ss_selector