-
Notifications
You must be signed in to change notification settings - Fork 1
/
MwfPlgNaviTSV.pm
66 lines (58 loc) · 2.27 KB
/
MwfPlgNaviTSV.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
#------------------------------------------------------------------------------
# mwForum - Web-based discussion forum
# Copyright (c) 1999-2008 Markus Wichitill
#
# MwfPlgNaviTSV.pm - Table Seperated Values Generation
# Copyright (c) 2010 Tobias Jaeggi
#
# 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 MwfPlgNaviTSV;
use strict;
use warnings;
our $VERSION = "2.22.1";
use Net::FTP;
sub create {
my %params = @_;
my $m = $params{m};
my $cfg = $m->{cfg};
my @words = @{$params{words}};
my $ftp = $params{ftp};
my @lcs = @{$params{languages}};
# Clean up
`rm -f $cfg->{EE}{tmpDir}/*.tsv`;
# Open file handles to avoid iterating X times through @words
my %files = ();
for my $lc (@lcs) {
my $adding = $lc eq 'eng' ? '' : "_$lc";
open($files{$lc}, '>::utf8', "$cfg->{EE}{tmpDir}/$cfg->{EE}{addonBasename}$adding.tsv") or $m->error("Could not open file for $lc! ($! for $cfg->{EE}{tmpDir}/$cfg->{EE}{addonBasename}$adding.tsv)");
$files{$lc} or $m->error("could not open file $lc");
}
# Iterate through @words
for my $word (@words) {
# For each language...
for my $lc (@lcs) {
$files{$lc} && defined $files{$lc} or $m->error("filehandle for $lc closed!");
next if !$word->{$lc};
my $type = $word->{"type$lc"} ? $word->{"type$lc"} : $word->{type};
print {$files{$lc}} $word->{nav}, "\t", $word->{$lc}, "\t", $type, "\n";
}
}
for my $lc (@lcs) {
close $files{$lc};
# FTP
my $adding = $lc eq 'eng' ? '' : "_$lc";
$ftp->delete("$cfg->{EE}{addonBasename}$adding.tsv");
$ftp->put("$cfg->{EE}{tmpDir}/$cfg->{EE}{addonBasename}$adding.tsv", "$cfg->{EE}{addonBasename}$adding.tsv") or $m->error("could not ftp: $!");
}
}
#-----------------------------------------------------------------------------
1;