-
Notifications
You must be signed in to change notification settings - Fork 1
/
MwfPlgNaviRSS.pm
104 lines (90 loc) · 3.95 KB
/
MwfPlgNaviRSS.pm
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
#------------------------------------------------------------------------------
# mwForum - Web-based discussion forum
# Copyright (c) 1999-2008 Markus Wichitill
#
# MwfPlgNaviRSS.pm - RSS Generation
# Copyright (c) 2010 Tobias Jaeggi, modified for RSS 2010 by Murray Colpman
#
# 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.
#------------------------------------------------------------------------------
package MwfPlgNaviRSS;
use strict;
use warnings;
our $VERSION = "2.22.1";
use Net::FTP;
use Time::Format;
sub create {
my %params = @_;
my $m = $params{m};
my $cfg = $m->{cfg};
my @words = @{$params{words}};
my @sorted = sort {$b->{editTime} <=> $a->{editTime}} @words;
my $ftp = $params{ftp};
my $languages = $params{advLanguages};
my @rssmessages = qw(1 10 25 50);
# Clean up
`rm -f $cfg->{EE}{tmpDir}/*.rss`;
# Open file handles to avoid iterating X times through @words
my %files = ();
for my $number (@rssmessages){
open($files{$number}, '>::utf8', "$cfg->{EE}{tmpDir}/NaviUpdates_${number}.rss") or $m->error("Could not open file! ($! for $cfg->{EE}{tmpDir}/NaviUpdates_${number}.rss)");
$files{$number} or $m->error("could not open file");
require POSIX;
my $oldLocale = POSIX::setlocale(POSIX::LC_TIME(), 'C');
my $buildDate = $m->formatTime($m->{now}, 0, "%a, %d %b %Y %H:%M:%S GMT");
my $pubDate = $m->formatTime($sorted[0]->{editTime}, "%a, %d %b %Y %H:%M:%S GMT");
print {$files{$number}} <<EORSS;
<?xml version='1.0' encoding='utf-8'?>
<rss version='2.0'>\n",
<channel>
<title>Na'vi dictionary updates</title>
<link>http://forum.learnnavi.org/intermediate/my-dictionary/</link>
<description>List of Na'vi words recently modified.</description>
<language>en-gb</language>
<pubDate>$pubDate</pubDate>
<lastBuildDate>$buildDate</lastBuildDate>
<docs>http://www.rssboard.org/rss-specification</docs>
<generator>RSS generator for Eana Eltu 1.0</generator>
<copyright>Eana Eltu RSS data by Tobias Jaeggi (Tuiq, tuiq\@clonk2c.ch), Richard Littauer (Taronyu, richard\@learnnavi.org) and others is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License ( http://creativecommons.org/licenses/by-nc-sa/3.0/ ). The full license text is available at http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode .</copyright>
EORSS
}
# Iterate through @words
my $done = 0;
for my $word (@sorted) {
for my $number (@rssmessages){
if($done < $number){
print {$files{$number}}
"<item>\n",
"<title><![CDATA[$word->{nav}]]></title>\n",
"<pubDate>", $m->formatTime($word->{editTime}, 0, "%a, %d %b %Y %H:%M:%S GMT"), "</pubDate>\n",
"<description><![CDATA[Na'vi: $word->{nav}<br />IPA: $word->{ipa}<br />Part of speech: $word->{type}<br />";
# And now for each language...
for my $lc (grep { $languages->{$_}{active} } keys %$languages) {
next if !$word->{$lc};
print {$files{$number}} "$languages->{$lc}{nat}: $word->{$lc}<br />\n";
}
# We show mercy to poor editors.
print {$files{$number}} "]]></description></item>\n";
}
}
$done++;
}
POSIX::setlocale(POSIX::LC_TIME(), $oldLocale);
for my $number (@rssmessages) {
print {$files{$number}} "</channel>\n</rss>\n";
close $files{$number};
# FTP
$ftp->delete("NaviUpdates_$number.rss");
$ftp->put("$cfg->{EE}{tmpDir}/NaviUpdates_$number.rss", "NaviUpdates_$number.rss") or $m->error("could not ftp: $!");
}
}
#-----------------------------------------------------------------------------
1;