2007-08-03 16:01:20 +00:00
|
|
|
# Copyright (C) 2007 Alex Schroeder <alex@gnu.org>
|
|
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2015-03-27 03:01:01 +02:00
|
|
|
use strict;
|
2015-08-18 10:48:03 +02:00
|
|
|
use v5.10;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2014-08-21 22:23:23 +02:00
|
|
|
AddModuleDescription('enclosure.pl', 'Podcasting');
|
2007-08-03 16:01:20 +00:00
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
our (%Page, %IndexHash, @MyRules, $FreeLinkPattern);
|
|
|
|
|
our (@Enclosures);
|
2007-08-03 16:01:20 +00:00
|
|
|
|
|
|
|
|
push(@MyRules, \&EnclosureRule);
|
|
|
|
|
|
|
|
|
|
# [[enclosure:page name]]
|
|
|
|
|
# [[enclosure:page name|alt text]]
|
|
|
|
|
# [[enclosure:url|size in bytes|mime type]]
|
|
|
|
|
|
|
|
|
|
sub EnclosureRule {
|
2015-08-23 21:22:12 +03:00
|
|
|
if (m!\G\[\[enclosure:\s*$FreeLinkPattern(\|([^\]]+))?\]\]!cgi) {
|
2007-08-03 16:01:20 +00:00
|
|
|
my $id = FreeToNormal($1);
|
|
|
|
|
# Make sure we don't add duplicates; we will add non-existing
|
|
|
|
|
# enclosures as well. We test for existence only when the RSS feed
|
|
|
|
|
# is being produced.
|
|
|
|
|
my %enclosures = map { $_ => 1 } split(' ', $Page{enclosures});
|
|
|
|
|
$enclosures{$id} = 1;
|
|
|
|
|
$Page{enclosures} = join(' ', keys %enclosures);
|
|
|
|
|
return GetDownloadLink($id, undef, undef, $3);
|
|
|
|
|
}
|
2015-02-27 12:10:18 +02:00
|
|
|
return;
|
2007-08-03 16:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-12 22:50:50 +03:00
|
|
|
*OldEnclosurePrintWikiToHTML = \&PrintWikiToHTML;
|
|
|
|
|
*PrintWikiToHTML = \&NewEnclosurePrintWikiToHTML;
|
2007-08-03 16:01:20 +00:00
|
|
|
|
|
|
|
|
sub NewEnclosurePrintWikiToHTML {
|
|
|
|
|
$Page{enclosures} = '';
|
|
|
|
|
return OldEnclosurePrintWikiToHTML(@_);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-12 22:50:50 +03:00
|
|
|
*OldEnclosureRssItem = \&RssItem;
|
|
|
|
|
*RssItem = \&NewEnclosureRssItem;
|
2007-08-03 16:01:20 +00:00
|
|
|
|
|
|
|
|
sub NewEnclosureRssItem {
|
|
|
|
|
my $id = shift;
|
|
|
|
|
my $rss = OldEnclosureRssItem($id, @_);
|
|
|
|
|
require MIME::Base64;
|
2015-09-04 04:55:48 +03:00
|
|
|
my $data = ParseData(ReadFileOrDie(GetPageFile($id)));
|
|
|
|
|
my @enclosures = split(' ', $data->{enclosures});
|
2007-08-03 16:01:20 +00:00
|
|
|
my $enclosures = '';
|
|
|
|
|
foreach my $enclosure (@enclosures) {
|
|
|
|
|
# Don't add the enclosure if the page has been deleted in the mean
|
|
|
|
|
# time (or never existed in the first place).
|
|
|
|
|
next unless $IndexHash{$enclosure};
|
|
|
|
|
my $url = GetDownloadLink($enclosure, 2); # just the URL
|
|
|
|
|
my %item = ParseData(ReadFileOrDie(GetPageFile($enclosure)));
|
|
|
|
|
my ($type) = TextIsFile($item{text});
|
|
|
|
|
my ($data) = $item{text} =~ /^[^\n]*\n(.*)/s;
|
|
|
|
|
my $size = length(MIME::Base64::decode($data));
|
|
|
|
|
$enclosures .= qq{<enclosure url="$url" length="$size" type="$type" />\n};
|
|
|
|
|
}
|
|
|
|
|
$rss =~ s!</item>$!$enclosures</item>! if $enclosures;
|
|
|
|
|
return $rss;
|
|
|
|
|
}
|