View | Details | Raw Unified | Return to bug 124055
Collapse All | Expand All

(-)multimedia.pl (-200 / +236 lines)
Lines 2-8 Link Here
2
2
3
#
3
#
4
# $Id$
4
# $Id$
5
# $FreeBSD: www/en/multimedia/multimedia.pl,v 1.1 2007/05/15 21:30:41 keramida Exp $
5
# $FreeBSD$
6
#
6
#
7
7
8
use strict;
8
use strict;
Lines 10-157 Link Here
10
use Data::Dumper;
10
use Data::Dumper;
11
use POSIX;
11
use POSIX;
12
12
13
my @months=(
13
my @months = (
14
    "","January","February","March",
14
    "", "January", "February", "March",
15
    "April","May","June","July",
15
    "April", "May", "June", "July",
16
    "August","September","October",
16
    "August", "September", "October",
17
    "November","December"
17
    "November", "December"
18
);
18
);
19
19
20
my @createdfiles=();
20
my @createdfiles = ();
21
21
22
my @tree=();
22
my @tree = ();
23
my @values=();
23
my @values = ();
24
my $treeindex=-1;
24
my $treeindex = -1;
25
25
26
my @items;
26
my @items;
27
my $ci=-1;
27
my $ci = -1;
28
my %sources;
28
my %sources;
29
my $sid="";
29
my $sid = "";
30
my %tags;
30
my %tags;
31
31
32
sub addtags {
32
sub addtags {
33
    my $tags=shift;
33
    my $tags = shift;
34
34
35
    if ($tags) {
35
    if ($tags) {
36
	my @w=split(/,/,$tags);
36
	my @w = split(/,/, $tags);
37
	foreach my $w (@w) {
37
	foreach my $w (@w) {
38
	    $tags{$w}=0 if (!defined $tags{$w});
38
	    $tags{$w} = 0 if (!defined $tags{$w});
39
	    $tags{$w}++;
39
	    $tags{$w}++;
40
	}
40
	}
41
	return;
41
	return;
42
    }
42
    }
43
43
44
    my $array=shift;
44
    my $array = shift;
45
    my @array=@{$array};
45
    my @array = @{$array};
46
    foreach my $w (@array) {
46
    foreach my $w (@array) {
47
	$tags{$w}=0 if (!defined $tags{$w});
47
	$tags{$w} = 0 if (!defined $tags{$w});
48
	$tags{$w}++;
48
	$tags{$w}++;
49
    }
49
    }
50
}
50
}
51
51
52
sub xml_start {
52
sub xml_start {
53
    my $expat=shift;
53
    my $expat = shift;
54
    my $element=shift;
54
    my $element = shift;
55
55
56
    $tree[++$treeindex]=$element;
56
    $tree[++$treeindex] = $element;
57
    while (defined (my $attribute=shift)) {
57
    while (defined (my $attribute = shift)) {
58
	$values[$treeindex]{$attribute}=shift;
58
	$values[$treeindex]{$attribute} = shift;
59
    }
59
    }
60
60
61
    if ($element eq "item"
61
    if ($element eq "item"
62
     && $treeindex==2) {
62
     && $treeindex == 2) {
63
	$ci++;
63
	$ci++;
64
	$items[$ci]=();
64
	$items[$ci] = ();
65
	$items[$ci]{source}=$values[$treeindex]{source};
65
	$items[$ci]{source} = $values[$treeindex]{source};
66
	$items[$ci]{added}=$values[$treeindex]{added};
66
	$items[$ci]{added} = $values[$treeindex]{added};
67
	$items[$ci]{ci}=$ci;
67
	$items[$ci]{ci} = $ci;
68
	$items[$ci]{fc}=-1;
68
	$items[$ci]{fc} = -1;
69
    }
69
    }
70
70
71
    if ($element eq "source"
71
    if ($element eq "source"
72
     && $treeindex==2) {
72
     && $treeindex == 2) {
73
	$sid=$values[$treeindex]{id};
73
	$sid = $values[$treeindex]{id};
74
	$sources{$values[$treeindex]{id}}=();
74
	$sources{$values[$treeindex]{id}} = ();
75
    }
76
77
    if ($element eq "url"
78
     && $treeindex == 5) {
79
	$items[$ci]{fc}++;
75
    }
80
    }
76
}
81
}
77
82
78
sub xml_end {
83
sub xml_end {
79
    my $expat=shift;
84
    my $expat = shift;
80
    my $element=shift;
85
    my $element = shift;
81
86
82
    $values[$treeindex]=();
87
    $values[$treeindex] = ();
83
    $treeindex--;
88
    $treeindex--;
84
}
89
}
85
90
86
sub xml_char {
91
sub xml_char {
87
    my $expat=shift;
92
    my $expat = shift;
88
    my $value=shift;
93
    my $value = shift;
89
94
90
    if ($tree[0] eq "multimedia") {
95
    if ($tree[0] eq "multimedia") {
91
	return if ($treeindex==0);
96
	return if ($treeindex == 0);
92
97
93
	if ($tree[1] eq "items") {
98
	if ($tree[1] eq "items") {
94
	    return if ($treeindex==1);
99
	    return if ($treeindex == 1);
95
100
96
	    if ($tree[2] eq "item") {
101
	    if ($tree[2] eq "item") {
97
		return if ($treeindex==2);
102
		return if ($treeindex == 2);
98
103
99
		if ($tree[3] eq "title") {
104
		if ($tree[3] eq "title") {
100
		    $items[$ci]{title}=$value;
105
		    $items[$ci]{title} = "" if (!defined $items[$ci]{title});
106
		    $items[$ci]{title} .= $value;
101
		    return;
107
		    return;
102
		}
108
		}
103
		if ($tree[3] eq "desc") {
109
		if ($tree[3] eq "desc") {
104
		    $items[$ci]{desc}="" if (!defined $items[$ci]{desc});
110
		    $items[$ci]{desc} = "" if (!defined $items[$ci]{desc});
105
		    $items[$ci]{desc}.=$value;
111
		    $items[$ci]{desc} .= $value;
106
		    return;
112
		    return;
107
		}
113
		}
108
		if ($tree[3] eq "overview") {
114
		if ($tree[3] eq "overview") {
109
		    $items[$ci]{overview}=$value;
115
		    $items[$ci]{overview} = "" if (!defined $items[$ci]{desc});
116
		    $items[$ci]{overview} .= $value;
110
		    return;
117
		    return;
111
		}
118
		}
112
		if ($tree[3] eq "link") {
119
		if ($tree[3] eq "link") {
113
		    $items[$ci]{link}=$value;
120
		    $items[$ci]{link} = "" if (!defined $items[$ci]{link});
121
		    $items[$ci]{link} .= $value;
114
		    return;
122
		    return;
115
		}
123
		}
116
		if ($tree[3] eq "tags") {
124
		if ($tree[3] eq "tags") {
117
		    @{$items[$ci]{tags}}=split(/,/,$value);
125
		    @{$items[$ci]{tags}} = split(/,/, $value);
118
		    addtags($value);
126
		    addtags($value);
119
		    return;
127
		    return;
120
		}
128
		}
121
129
122
		if ($tree[3] eq "files") {
130
		if ($tree[3] eq "files") {
123
		    return if ($treeindex==3);
131
		    return if ($treeindex == 3);
124
132
125
		    if ($tree[4] eq "prefix") {
133
		    if ($tree[4] eq "prefix") {
126
			$items[$ci]{prefix}="" if (!defined $items[$ci]{prefix});
134
			$items[$ci]{prefix} = "" if (!defined $items[$ci]{prefix});
127
			$items[$ci]{prefix}.=$value;
135
			$items[$ci]{prefix} .= $value;
128
			return;
136
			return;
129
		    }
137
		    }
130
138
131
		    if ($tree[4] eq "file") {
139
		    if ($tree[4] eq "file") {
132
			return if ($treeindex==4);
140
			return if ($treeindex == 4);
133
141
134
			if ($tree[5] eq "url") {
142
			if ($tree[5] eq "url") {
135
			    $items[$ci]{fc}++;
143
			    # Note that $items[$ci]{fc} gets incremented in xml_start
136
			    $items[$ci]{files}{$items[$ci]{fc}}{url}=$value;
144
			    $items[$ci]{files}{$items[$ci]{fc}}{url} = ""
145
				if (!defined $items[$ci]{files}{$items[$ci]{fc}}{url});
146
			    $items[$ci]{files}{$items[$ci]{fc}}{url} .= $value;
137
			    return;
147
			    return;
138
			}
148
			}
139
			if ($tree[5] eq "size") {
149
			if ($tree[5] eq "size") {
140
			    $items[$ci]{files}{$items[$ci]{fc}}{size}=$value;
150
			    $items[$ci]{files}{$items[$ci]{fc}}{size} = ""
151
				if (!defined $items[$ci]{files}{$items[$ci]{fc}}{size});
152
			    $items[$ci]{files}{$items[$ci]{fc}}{size} .= $value;
141
			    return;
153
			    return;
142
			}
154
			}
143
			if ($tree[5] eq "length") {
155
			if ($tree[5] eq "length") {
144
			    $items[$ci]{files}{$items[$ci]{fc}}{length}=$value;
156
			    $items[$ci]{files}{$items[$ci]{fc}}{length} = ""
157
				if (!defined $items[$ci]{files}{$items[$ci]{fc}}{length});
158
			    $items[$ci]{files}{$items[$ci]{fc}}{length} .= $value;
145
			    return;
159
			    return;
146
			}
160
			}
147
			if ($tree[5] eq "desc") {
161
			if ($tree[5] eq "desc") {
148
			    $items[$ci]{files}{$items[$ci]{fc}}{desc}=$value;
162
			    $items[$ci]{files}{$items[$ci]{fc}}{desc} = ""
163
				if (!defined $items[$ci]{files}{$items[$ci]{fc}}{desc});
164
			    $items[$ci]{files}{$items[$ci]{fc}}{desc} .= $value;
149
			    return;
165
			    return;
150
			}
166
			}
151
			if ($tree[5] eq "tags") {
167
			if ($tree[5] eq "tags") {
152
			    @{$items[$ci]{files}{$items[$ci]{fc}}{tags}}=split(/,/,$value);
168
			    @{$items[$ci]{files}{$items[$ci]{fc}}{tags}} = split(/,/, $value);
153
			    addtags($value);
169
			    addtags($value);
154
			    addtags("",$items[$ci]{tags});
170
			    addtags("", $items[$ci]{tags});
155
			    return;
171
			    return;
156
			}
172
			}
157
			goto error;
173
			goto error;
Lines 164-180 Link Here
164
	}
180
	}
165
181
166
	if ($tree[1] eq "sources") {
182
	if ($tree[1] eq "sources") {
167
	    return if ($treeindex==1);
183
	    return if ($treeindex == 1);
168
184
169
	    if ($tree[2] eq "source") {
185
	    if ($tree[2] eq "source") {
170
		return if ($treeindex==2);
186
		return if ($treeindex == 2);
171
187
172
		if ($tree[3] eq "name") {
188
		if ($tree[3] eq "name") {
173
		    $sources{$sid}{name}=$value;
189
		    $sources{$sid}{name} = $value;
174
		    return;
190
		    return;
175
		}
191
		}
176
		if ($tree[3] eq "url") {
192
		if ($tree[3] eq "url") {
177
		    $sources{$sid}{url}=$value;
193
		    $sources{$sid}{url} = $value;
178
		    return;
194
		    return;
179
		}
195
		}
180
		goto error;
196
		goto error;
Lines 188-194 Link Here
188
    print "Unknown item at depth $treeindex: $tree[$treeindex]\n";
204
    print "Unknown item at depth $treeindex: $tree[$treeindex]\n";
189
}
205
}
190
206
191
my $p=new XML::Parser(
207
my $p = new XML::Parser(
192
    Handlers => {
208
    Handlers => {
193
	Start	=> \&xml_start,
209
	Start	=> \&xml_start,
194
	End	=> \&xml_end,
210
	End	=> \&xml_end,
Lines 197-260 Link Here
197
);
213
);
198
$p->parsefile("multimedia-input.xml");
214
$p->parsefile("multimedia-input.xml");
199
215
200
my @site_order=();
216
my @site_order = ();
201
{
217
{
202
    sub site_sort {
218
    sub site_sort {
203
	my %a=%{$a};
219
	my %a = %{$a};
204
	my %b=%{$b};
220
	my %b = %{$b};
205
	return $a{source} cmp $b{source}
221
	return $a{source} cmp $b{source}
206
	    if ($a{source} ne $b{source});
222
	    if ($a{source} ne $b{source});
207
	return $a{title} cmp $b{title};
223
	return $a{title} cmp $b{title};
208
    }
224
    }
209
    @site_order=sort site_sort @items;
225
    @site_order = sort site_sort @items;
210
}
226
}
211
227
212
my @date_order=();
228
my @date_order = ();
213
{
229
{
214
    my %dates=();
230
    my %dates = ();
215
    foreach my $item (@items) {
231
    foreach my $item (@items) {
216
	my %item=%{$item};
232
	my %item = %{$item};
217
	$dates{$item{ci}}=$item{added};
233
	$dates{$item{ci}} = $item{added};
218
    }
234
    }
219
    my @dates=keys(%dates);
235
    my @dates = keys(%dates);
220
    @date_order=sort { $dates{$b} cmp $dates{$a} } @dates;
236
    @date_order = sort { $dates{$b} cmp $dates{$a} } @dates;
221
}
237
}
222
238
223
#
239
#
224
# HTML overview output
240
# HTML overview output
225
#
241
#
226
sub print_htmlitem {
242
sub print_htmlitem {
227
    my $item=shift;
243
    my $item = shift;
228
    my %item=%{$item};
244
    my %item = %{$item};
229
    my $source=shift;
245
    my $source = shift;
230
    my %source=%{$source};
246
    my %source = %{$source};
231
247
232
    print FOUT "<li><p>";
248
    print FOUT "<li><p>";
233
    if (defined $item{overview}) {
249
    if (defined $item{overview}) {
234
	print FOUT "<a href=\"$item{overview}\">$item{title}</a>\n";
250
	print FOUT "<a href=\"$item{overview}\">$item{title}</a>\n";
235
    } else {
251
    } else {
236
	my %media=%{$item{files}{0}};
252
	my %media = %{$item{files}{0}};
237
	print FOUT "<a href=\"$media{url}\">$item{title}</a>\n";
253
	print FOUT "<a href=\"$media{url}\">$item{title}</a>\n";
238
	if (defined $media{size} || defined $media{length}) {
254
	if (defined $media{size} || defined $media{length}) {
239
	    my $s="";
255
	    my $s = "";
240
	    print FOUT "(";
256
	    print FOUT "(";
241
	    if (defined $media{size}) {
257
	    if (defined $media{size}) {
242
		print FOUT "$media{size}";
258
		print FOUT "$media{size}";
243
		$s=", ";
259
		$s = ", ";
244
	    }
260
	    }
245
	    if (defined $media{length}) {
261
	    if (defined $media{length}) {
246
		print FOUT "$s$media{length}";
262
		print FOUT "$s$media{length}";
247
		$s=", ";
263
		$s = ", ";
248
	    }
264
	    }
249
	    print FOUT ")";
265
	    print FOUT ")";
250
	}
266
	}
251
    }
267
    }
252
    print FOUT "<br>Source: <a href=\"",$source{url},"\">",$source{name},"</a><br>\n";
268
    print FOUT "<br>Source: <a href=\"", $source{url}, "\">",
253
    print FOUT "Tags: ",join(", ",@{$item{tags}}),"<br>\n";
269
	$source{name}, "</a><br>\n";
270
    print FOUT "Added: ",
271
	    substr($item{added}, 6, 2), " ",
272
	    $months[substr($item{added}, 4, 2)], " ",
273
	    substr($item{added}, 0, 4), "<br>\n";
274
275
    print FOUT "Tags: ";
276
    {
277
	my $first = 1;
278
	foreach my $t (@{$item{tags}}) {
279
	    print FOUT ", " if (!$first);
280
#	    join(", ", @{$item{$t}}), "<br>\n";
281
	    my $th = $t;
282
	    $th =~ s/ /_/g;
283
	    print FOUT "<a href=\"multimedia-tag-$th.html\">$t</a>";
284
	    $first = 0;
285
	}
286
    }
287
    print FOUT "<br>\n";
288
254
    if (defined $item{overview} && defined $item{files}) {
289
    if (defined $item{overview} && defined $item{files}) {
255
	my $c=0;
290
	my $c = 0;
256
	foreach my $m (keys(%{$item{files}})) {
291
	foreach my $m (keys(%{$item{files}})) {
257
	    my %file=%{$item{files}{$m}};
292
	    my %file = %{$item{files}{$m}};
258
	    print FOUT ", " if ($c++);
293
	    print FOUT ", " if ($c++);
259
	    if (defined $item{prefix}) {
294
	    if (defined $item{prefix}) {
260
		print FOUT "<a href=\"$item{prefix}/$file{url}\">$file{desc}</a>";
295
		print FOUT "<a href=\"$item{prefix}/$file{url}\">$file{desc}</a>";
Lines 262-276 Link Here
262
		print FOUT "<a href=\"$file{url}\">$file{desc}</a>";
297
		print FOUT "<a href=\"$file{url}\">$file{desc}</a>";
263
	    }
298
	    }
264
	    if (defined $file{size} || defined $file{length}) {
299
	    if (defined $file{size} || defined $file{length}) {
265
		my $s="";
300
		my $s = "";
266
		print FOUT " (";
301
		print FOUT " (";
267
		if (defined $file{size}) {
302
		if (defined $file{size}) {
268
		    print FOUT "$file{size}";
303
		    print FOUT "$file{size}";
269
		    $s=", ";
304
		    $s = ", ";
270
		}
305
		}
271
		if (defined $file{length}) {
306
		if (defined $file{length}) {
272
		    print FOUT "$s$file{length}";
307
		    print FOUT "$s$file{length}";
273
		    $s=", ";
308
		    $s = ", ";
274
		}
309
		}
275
		print FOUT ")";
310
		print FOUT ")";
276
	    }
311
	    }
Lines 280-314 Link Here
280
    print FOUT "$item{desc}\n";
315
    print FOUT "$item{desc}\n";
281
}
316
}
282
{
317
{
283
    $createdfiles[$#createdfiles+1]="multimedia.html";
318
    $createdfiles[$#createdfiles+1] = "multimedia.html";
284
    open(FOUT,">multimedia.html");
319
    open(FOUT, ">multimedia.html");
285
    open(FIN,"multimedia.html.pre");
320
    open(FIN, "multimedia.html.pre");
286
    my @lines=<FIN>;
321
    my @lines = <FIN>;
287
    close(FIN);
322
    close(FIN);
288
    print FOUT @lines;
323
    print FOUT @lines;
289
    open(FIN,"multimedia.html.intro");
324
    open(FIN, "multimedia.html.intro");
290
    @lines=<FIN>;
325
    @lines = <FIN>;
291
    close(FIN);
326
    close(FIN);
292
    print FOUT @lines;
327
    print FOUT @lines;
293
    print FOUT "<h2 id=\"latest\">Newest resources</h2>\n";
328
    print FOUT "<h2 id=\"latest\">Newest resources</h2>\n";
294
329
295
    my $month="";
330
    my $month = "";
296
331
297
    foreach my $order (@date_order) {
332
    foreach my $order (@date_order) {
298
	my %item=%{$items[$order]};
333
	my %item = %{$items[$order]};
299
	my %source=%{$sources{$item{source}}};
334
	my %source = %{$sources{$item{source}}};
300
	if (substr($item{added},0,6) ne $month) {
335
	if (substr($item{added}, 0, 6) ne $month) {
301
	    print FOUT "</ul><h2>",$months[substr($item{added},4,2)+0]," ",substr($item{added},0,4),"</h2><ul>";
336
	    print FOUT "</ul><h2>", $months[substr($item{added}, 4, 2)+0], " ", substr($item{added}, 0, 4), "</h2><ul>";
302
	    $month=substr($item{added},0,6);
337
	    $month = substr($item{added}, 0, 6);
303
	}
338
	}
304
339
305
	print_htmlitem(\%item,\%source);
340
	print_htmlitem(\%item, \%source);
306
    }
341
    }
307
342
308
    print FOUT "</ul>\n";
343
    print FOUT "</ul>\n";
309
344
310
    open(FIN,"multimedia.html.post");
345
    open(FIN, "multimedia.html.post");
311
    @lines=<FIN>;
346
    @lines = <FIN>;
312
    close(FIN);
347
    close(FIN);
313
    print FOUT @lines;
348
    print FOUT @lines;
314
349
Lines 319-353 Link Here
319
# HTML cloud output
354
# HTML cloud output
320
#
355
#
321
{
356
{
322
    $createdfiles[$#createdfiles+1]="multimedia-tags.html";
357
    $createdfiles[$#createdfiles+1] = "multimedia-tags.html";
323
    open(FOUT,">multimedia-tags.html");
358
    open(FOUT, ">multimedia-tags.html");
324
    open(FIN,"multimedia.html.pre");
359
    open(FIN, "multimedia.html.pre");
325
    my @lines=<FIN>;
360
    my @lines = <FIN>;
326
    close(FIN);
361
    close(FIN);
327
    print FOUT @lines;
362
    print FOUT @lines;
328
    open(FIN,"multimedia.html.intro");
363
    open(FIN, "multimedia.html.intro");
329
    @lines=<FIN>;
364
    @lines = <FIN>;
330
    close(FIN);
365
    close(FIN);
331
    print FOUT @lines;
366
    print FOUT @lines;
332
    print FOUT "<h2 id=\"latest\">Tags</h2>\n";
367
    print FOUT "<h2 id=\"latest\">Tags</h2>\n";
333
368
334
    my $month="";
369
    my $month = "";
335
370
336
    sub size {
371
    sub size {
337
	return $b cmp $a if ($tags{$b}==$tags{$a});
372
	return $b cmp $a if ($tags{$b} == $tags{$a});
338
	return $tags{$b} <=> $tags{$a};
373
	return $tags{$b} <=> $tags{$a};
339
    }
374
    }
340
    my $size=20;
375
    my $size = 20;
341
    my $c=0;
376
    my $c = 0;
342
    foreach my $tag (sort size(keys(%tags))) {
377
    foreach my $tag (sort size(keys(%tags))) {
343
	my $ftag=$tag;
378
	my $ftag = $tag;
344
	$ftag=~s/ /_/g;
379
	$ftag =~ s/ /_/g;
345
	print FOUT "<font style=\"font-size:${size}pt\"><a href=\"multimedia-tag-$ftag.html\">$tag</a></font>\n";
380
	print FOUT "<font style=\"font-size:${size}pt\"><a href=\"multimedia-tag-$ftag.html\">$tag</a></font>\n";
346
	$size-- if ($c++%10==0 && $size>2);
381
	$size-- if ($c++%10 == 0 && $size > 2);
347
    }
382
    }
348
383
349
    open(FIN,"multimedia.html.post");
384
    open(FIN, "multimedia.html.post");
350
    @lines=<FIN>;
385
    @lines = <FIN>;
351
    close(FIN);
386
    close(FIN);
352
    print FOUT @lines;
387
    print FOUT @lines;
353
388
Lines 359-412 Link Here
359
#
394
#
360
{
395
{
361
    foreach my $tag (keys(%tags)) {
396
    foreach my $tag (keys(%tags)) {
362
	my $ftag=$tag;
397
	my $ftag = $tag;
363
	$ftag=~s/ /_/g;
398
	$ftag =~ s/ /_/g;
364
	$createdfiles[$#createdfiles+1]="multimedia-tag-$ftag.html";
399
	$createdfiles[$#createdfiles+1] = "multimedia-tag-$ftag.html";
365
	open(FOUT,">multimedia-tag-$ftag.html");
400
	open(FOUT, ">multimedia-tag-$ftag.html");
366
401
367
	open(FIN,"multimedia.html.pre");
402
	open(FIN, "multimedia.html.pre");
368
	my @lines=<FIN>;
403
	my @lines = <FIN>;
369
	close(FIN);
404
	close(FIN);
370
	print FOUT @lines;
405
	print FOUT @lines;
371
	open(FIN,"multimedia.html.intro");
406
	open(FIN, "multimedia.html.intro");
372
	@lines=<FIN>;
407
	@lines = <FIN>;
373
	close(FIN);
408
	close(FIN);
374
	print FOUT @lines;
409
	print FOUT @lines;
375
	print FOUT "<h2 id=\"latest\">Tag: $tag</h2>\n";
410
	print FOUT "<h2 id=\"latest\">Tag: $tag</h2>\n";
376
	print FOUT "<ul>\n";
411
	print FOUT "<ul>\n";
377
412
378
	foreach my $item (@items) {
413
	foreach my $item (@items) {
379
	    my %item=%{$item};
414
	    my %item = %{$item};
380
	    my %source=%{$sources{$item{source}}};
415
	    my %source = %{$sources{$item{source}}};
381
416
382
	    my $found=0;
417
	    my $found = 0;
383
418
384
	    foreach my $itag (@{$item{tags}}) {
419
	    foreach my $itag (@{$item{tags}}) {
385
		if ($itag eq $tag) {
420
		if ($itag eq $tag) {
386
		    $found=1;
421
		    $found = 1;
387
		    last;
422
		    last;
388
		}
423
		}
389
	    }
424
	    }
390
425
391
	    if (!$found) {
426
	    if (!$found) {
392
		foreach my $file (keys(%{$item{files}})) {
427
		foreach my $file (keys(%{$item{files}})) {
393
		    my %file=%{$item{files}{$file}};
428
		    my %file = %{$item{files}{$file}};
394
		    foreach my $itag (@{$file{tags}}) {
429
		    foreach my $itag (@{$file{tags}}) {
395
			if ($itag eq $tag) {
430
			if ($itag eq $tag) {
396
			    $found=1;
431
			    $found = 1;
397
			    last;
432
			    last;
398
			}
433
			}
399
		    }
434
		    }
400
		}
435
		}
401
	    }
436
	    }
402
437
403
	    print_htmlitem(\%item,\%source) if ($found);
438
	    print_htmlitem(\%item, \%source) if ($found);
404
439
405
	}
440
	}
406
441
407
	print FOUT "</ul>\n";
442
	print FOUT "</ul>\n";
408
	open(FIN,"multimedia.html.post");
443
	open(FIN, "multimedia.html.post");
409
	@lines=<FIN>;
444
	@lines = <FIN>;
410
	close(FIN);
445
	close(FIN);
411
	print FOUT @lines;
446
	print FOUT @lines;
412
	close(FOUT);
447
	close(FOUT);
Lines 417-447 Link Here
417
# HTML all-sources output
452
# HTML all-sources output
418
#
453
#
419
{
454
{
420
    $createdfiles[$#createdfiles+1]="multimedia-sources.html";
455
    $createdfiles[$#createdfiles+1] = "multimedia-sources.html";
421
    open(FOUT,">multimedia-sources.html");
456
    open(FOUT, ">multimedia-sources.html");
422
    open(FIN,"multimedia.html.pre");
457
    open(FIN, "multimedia.html.pre");
423
    my @lines=<FIN>;
458
    my @lines = <FIN>;
424
    close(FIN);
459
    close(FIN);
425
    print FOUT @lines;
460
    print FOUT @lines;
426
    open(FIN,"multimedia.html.intro");
461
    open(FIN, "multimedia.html.intro");
427
    @lines=<FIN>;
462
    @lines = <FIN>;
428
    close(FIN);
463
    close(FIN);
429
    print FOUT @lines;
464
    print FOUT @lines;
430
    print FOUT "<h2 id=\"latest\">Sources</h2>\n";
465
    print FOUT "<h2 id=\"latest\">Sources</h2>\n";
431
    print FOUT "<ul>\n";
466
    print FOUT "<ul>\n";
432
467
433
    my $lastsource="";
468
    my $lastsource = "";
434
    foreach my $item (@site_order) {
469
    foreach my $item (@site_order) {
435
	my %item=%{$item};
470
	my %item = %{$item};
436
	next if ($lastsource eq $item{source});
471
	next if ($lastsource eq $item{source});
437
	$lastsource=$item{source};
472
	$lastsource = $item{source};
438
473
439
	print FOUT "<li><a href=\"multimedia-source-$lastsource.html\">",$sources{$item{source}}{name},"</a>\n";
474
	print FOUT "<li><a href=\"multimedia-source-$lastsource.html\">", $sources{$item{source}}{name}, "</a>\n";
440
    }
475
    }
441
476
442
    print FOUT "</ul>\n";
477
    print FOUT "</ul>\n";
443
    open(FIN,"multimedia.html.post");
478
    open(FIN, "multimedia.html.post");
444
    @lines=<FIN>;
479
    @lines = <FIN>;
445
    close(FIN);
480
    close(FIN);
446
    print FOUT @lines;
481
    print FOUT @lines;
447
    close(FOUT);
482
    close(FOUT);
Lines 451-490 Link Here
451
# HTML per-source output
486
# HTML per-source output
452
#
487
#
453
{
488
{
454
    my $lastsource="";
489
    my $lastsource = "";
455
    foreach my $item (@site_order) {
490
    foreach my $item (@site_order) {
456
	my %item=%{$item};
491
	my %item = %{$item};
457
	my %source=%{$sources{$item{source}}};
492
	my %source = %{$sources{$item{source}}};
458
	if ($lastsource ne $item{source}) {
493
	if ($lastsource ne $item{source}) {
459
494
460
	    if ($lastsource) {
495
	    if ($lastsource) {
461
		print FOUT "</ul>\n";
496
		print FOUT "</ul>\n";
462
		open(FIN,"multimedia.html.post");
497
		open(FIN, "multimedia.html.post");
463
		my @lines=<FIN>;
498
		my @lines = <FIN>;
464
		close(FIN);
499
		close(FIN);
465
		print FOUT @lines;
500
		print FOUT @lines;
466
		close(FOUT);
501
		close(FOUT);
467
	    }
502
	    }
468
	    $createdfiles[$#createdfiles+1]="multimedia-source-$item{source}.html";
503
	    $createdfiles[$#createdfiles+1] = "multimedia-source-$item{source}.html";
469
	    open(FOUT,">multimedia-source-$item{source}.html");
504
	    open(FOUT, ">multimedia-source-$item{source}.html");
470
	    open(FIN,"multimedia.html.pre");
505
	    open(FIN, "multimedia.html.pre");
471
	    my @lines=<FIN>;
506
	    my @lines = <FIN>;
472
	    close(FIN);
507
	    close(FIN);
473
	    print FOUT @lines;
508
	    print FOUT @lines;
474
	    open(FIN,"multimedia.html.intro");
509
	    open(FIN, "multimedia.html.intro");
475
	    @lines=<FIN>;
510
	    @lines = <FIN>;
476
	    close(FIN);
511
	    close(FIN);
477
	    print FOUT @lines;
512
	    print FOUT @lines;
478
	    $lastsource=$item{source};
513
	    $lastsource = $item{source};
479
	    print FOUT "<h2 id=\"latest\">$source{name}</h2>\n";
514
	    print FOUT "<h2 id=\"latest\">$source{name}</h2>\n";
480
	    print FOUT "<ul>\n";
515
	    print FOUT "<ul>\n";
481
	}
516
	}
482
	print_htmlitem(\%item,\%source);
517
	print_htmlitem(\%item, \%source);
483
518
484
    }
519
    }
485
    print FOUT "</ul>\n";
520
    print FOUT "</ul>\n";
486
    open(FIN,"multimedia.html.post");
521
    open(FIN, "multimedia.html.post");
487
    my @lines=<FIN>;
522
    my @lines = <FIN>;
488
    close(FIN);
523
    close(FIN);
489
    print FOUT @lines;
524
    print FOUT @lines;
490
    close(FOUT);
525
    close(FOUT);
Lines 496-547 Link Here
496
{
531
{
497
532
498
    sub htmlentities {
533
    sub htmlentities {
499
	my $s=shift;
534
	my $s = shift;
500
	$s=~s/&/&amp;/g;
535
	$s =~ s/&/&amp;/g;
501
	$s=~s/</&lt;/g;
536
	$s =~ s/</&lt;/g;
502
	$s=~s/>/&gt;/g;
537
	$s =~ s/>/&gt;/g;
503
	return $s;;
538
	return $s;;
504
    }
539
    }
505
    sub printxml_multiple {
540
    sub printxml_multiple {
506
	my $item=shift;
541
	my $item = shift;
507
	my %item=%{$item};
542
	my %item = %{$item};
508
	my $source=shift;
543
	my $source = shift;
509
	my %source=%{$source};
544
	my %source = %{$source};
510
	
545
	
511
	return if ($item{fc}<0);
546
	return if ($item{fc}<0);
512
547
513
	for (my $i=0;$i<=$item{fc};$i++) {
548
	for (my $i = 0; $i <= $item{fc}; $i++) {
514
	    my %f=%{$item{files}{$i}};
549
	    my %f = %{$item{files}{$i}};
515
550
516
	    my %tempitem=%item;
551
	    my %tempitem = %item;
517
	    $tempitem{title}.=" - $f{desc}";
552
	    $tempitem{title} .= " - $f{desc}";
518
	    $f{url}="$item{prefix}/$f{url}"
553
	    $f{url} = "$item{prefix}/$f{url}"
519
		if (defined $item{prefix});
554
		if (defined $item{prefix});
520
	    printxml_single(\%tempitem,\%source,\%f);
555
	    printxml_single(\%tempitem, \%source, \%f);
521
	}
556
	}
522
    }
557
    }
523
558
524
    sub printxml_single {
559
    sub printxml_single {
525
	my $item=shift;
560
	my $item = shift;
526
	my %item=%{$item};
561
	my %item = %{$item};
527
	my $source=shift;
562
	my $source = shift;
528
	my %source=%{$source};
563
	my %source = %{$source};
529
	my $file=shift;
564
	my $file = shift;
530
	my %file=%{$file};
565
	my %file = %{$file};
531
566
532
	my $date=POSIX::strftime("%a, %d %b %Y %H:%M:%S %Z",
567
	my $date = POSIX::strftime("%a, %d %b %Y %H:%M:%S %Z",
533
	    0,0,0,substr($item{added},6,2),substr($item{added},4,2)-1,substr($item{added},0,4)-1900);
568
	    0, 0, 0, substr($item{added}, 6, 2),
534
569
	    substr($item{added}, 4, 2)-1, substr($item{added}, 0, 4)-1900);
535
	my $tags=join(", ",@{$item{tags}});
570
536
	for my $tag (@{$file{tags}}) {
571
	my $tags = join(", ", @{$item{tags}});
537
	    $tags.=", $tag";
572
	foreach my $tag (@{$file{tags}}) {
573
	    $tags .= ", $tag";
538
	}
574
	}
539
575
540
	print FOUT "<item>\n";
576
	print FOUT "<item>\n";
541
	print FOUT "<title>",htmlentities("$source{name} - $item{title}"),"</title>\n";
577
	print FOUT "<title>", htmlentities("$source{name} - $item{title}"), "</title>\n";
542
	print FOUT "<guid>",htmlentities($file{url}),"</guid>\n";
578
	print FOUT "<guid>", htmlentities($file{url}), "</guid>\n";
543
	print FOUT "<pubDate>$date</pubDate>\n";
579
	print FOUT "<pubDate>$date</pubDate>\n";
544
	print FOUT "<enclosure url=\"",htmlentities($file{url}),"\" length=\"1\" type=\"application/octet-stream\" />\n";
580
	print FOUT "<enclosure url=\"", htmlentities($file{url}), "\" length=\"1\" type=\"application/octet-stream\" />\n";
545
	print FOUT "<description>";
581
	print FOUT "<description>";
546
	print FOUT htmlentities("$item{title}<br>From: $source{name}<br>");
582
	print FOUT htmlentities("$item{title}<br>From: $source{name}<br>");
547
	print FOUT htmlentities("Tags: $tags<br>\n");
583
	print FOUT htmlentities("Tags: $tags<br>\n");
Lines 550-560 Link Here
550
	print FOUT "</item>\n";
586
	print FOUT "</item>\n";
551
    }
587
    }
552
588
553
    $createdfiles[$#createdfiles+1]="multimedia.xml";
589
    $createdfiles[$#createdfiles+1] = "multimedia.xml";
554
    open(FOUT,">multimedia.xml");
590
    open(FOUT, ">multimedia.xml");
555
591
556
    my @s=stat("multimedia-input.xml");
592
    my @s = stat("multimedia-input.xml");
557
    my $date=POSIX::strftime("%a, %d %b %Y %H:%M:%S %Z",localtime($s[9]));
593
    my $date = POSIX::strftime("%a, %d %b %Y %H:%M:%S %Z", localtime($s[9]));
558
594
559
    print FOUT <<EOF;
595
    print FOUT <<EOF;
560
<rss version="2.0">
596
<rss version="2.0">
Lines 566-578 Link Here
566
EOF
602
EOF
567
603
568
    foreach my $order (@date_order) {
604
    foreach my $order (@date_order) {
569
	my %item=%{$items[$order]};
605
	my %item = %{$items[$order]};
570
	my %source=%{$sources{$item{source}}};
606
	my %source = %{$sources{$item{source}}};
571
607
572
	if (defined $item{overview}) {
608
	if (defined $item{overview}) {
573
	    printxml_multiple(\%item,\%source);
609
	    printxml_multiple(\%item, \%source);
574
	} else {
610
	} else {
575
	    printxml_single(\%item,\%source,$item{files}{0});
611
	    printxml_single(\%item, \%source, $item{files}{0});
576
	}
612
	}
577
    }
613
    }
578
614
Lines 588-594 Link Here
588
# Created files
624
# Created files
589
#
625
#
590
{
626
{
591
    open(FOUT,">multimedia.created");
627
    open(FOUT, ">multimedia.created");
592
    foreach my $f (@createdfiles) {
628
    foreach my $f (@createdfiles) {
593
	print FOUT "$f\n";
629
	print FOUT "$f\n";
594
    }
630
    }

Return to bug 124055