-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_info_main.cgi
executable file
·242 lines (208 loc) · 5.97 KB
/
module_info_main.cgi
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/usr/bin/perl
# Copyright (C) 2004-2019
# Emmanuel Saracco <emmanuel@esaracco.fr>
#
# GNU GENERAL PUBLIC LICENSE
require './translator-lib.pl';
my ($_success, $_error, $_info) = ('', '', '');
my $app = $in{'app'};
my $old_app = $in{'old_app'};
my $path = &trans_get_path ('', '') . "/$app";
my $finfo = (&trans_is_theme ($app)) ? 'theme' : 'module';
# init_msg ()
#
# Set success or error message.
#
sub init_msg ()
{
# Creation of the new translation was ok
if ($in{'o'} eq 'new_trans')
{
$_success = sprintf ($text{'MSG_NEW_TRANSLATION'}, $in{'t'});
}
# Translation already exists
elsif ($in{'o'} eq 'new_trans_exist')
{
$_error = sprintf ($text{'MSG_NEW_TRANSLATION_EXIST'}, $in{'t'}, $app);
}
# Added new items from ref translation to translation
elsif ($in{'o'} eq 'add_new')
{
$_success = sprintf ($text{'MSG_ADDED_ITEMS'}, $in{'t'});
}
# Updated translation
elsif ($in{'o'} eq 'update_trans')
{
$_success = sprintf ($text{'MSG_UPDATED_TRANSLATION'}, $in{'t'});
}
}
sub trans_display_description_table ( $ $ $ \@ )
{
my ($type, $title, $ref_line, $h) = @_;
my %hash = %$h;
print qq(<p><table class="trans keys-values" width="100%">);
print qq(<tr><td>$title</td><td class="to-translate">$ref_line</td></tr>);
print qq(</table>);
print qq(<p><table class="trans header keys-values" width="100%">);
print qq(<tr><td>$text{'LANGUAGE'}</td><td>$text{'DESCRIPTION'}</td></tr>);
foreach my $key (sort keys %hash)
{
next if (!&trans_is_language ($key));
my $value_print = &html_escape ($hash{$key});
print qq(
<tr>
<td>$key</td>
<td><input type="text" value="$value_print" name="${type}_$key" size="100%"></td></tr>);
}
print qq(</table></p>);
}
sub read_file_descs ( $ $ $ $ $ )
{
my ($f, $ref_line_short, $ref_line_long, $hash_short, $hash_long) = @_;
open (H, '<', $f);
while (my $line = <H>)
{
next if ($line !~ /^(desc|longdesc)/);
my ($name, $value) = split (/=/, $line);
my $value_print = &html_escape ($value);
if ($name eq 'desc')
{
$$ref_line_short = &html_escape ($value);
}
elsif ($name eq 'longdesc')
{
$$ref_line_long = &html_escape ($value);
}
elsif ($name =~ /^desc_(.*)$/)
{
$hash_short->{$1} = &trans_ent2char_buffer ($value);
}
elsif ($name =~ /^longdesc_(.*)$/)
{
$hash_long->{$1} = &trans_ent2char_buffer ($value);
}
}
close (H);
}
##### POST action #####
#
# Update module.info/theme descriptions
if (defined ($in{'update'}))
{
my %hash_main = ();
my %hash_extra = ();
unlink ("$config_directory/$finfo.infos.cache");
&read_file ("$path/$finfo.info", \%hash_main);
foreach my $key (keys %in)
{
next if ($key !~ /desc_(.*)/);
my $lang = $1;
if (&trans_lang_must_be_encoded ($lang))
{
$in{$key} = &trans_char2ent_buffer ($in{$key});
}
else
{
$in{$key} = &trans_ent2char_buffer ($in{$key});
}
if (exists ($hash_main{$key}))
{
$hash_main{$key} = $in{$key};
}
else
{
$hash_extra{$lang}{$key} = $in{$key};
}
}
# write main module.info file
&write_file ("$path/$finfo.info", \%hash_main);
# write extra module.info file per language if needed
while (my ($k, $v) = each (%hash_extra))
{
&write_file ("$path/$finfo.info.$k", $v);
}
$_success = $text{'MSG_MODULE_INFO_UPDATE'};
}
#
########################
&trans_header ($text{'MODULE_INFO_TITLE'}, $app);
&trans_get_menu_icons_panel ('module_info_main', $app);
print qq(<br/>$text{'MODULE_INFO_DESCRIPTION'});
print qq(<p>);
print qq(<form action="module_info_main.cgi" method="post">);
print qq(<input type="hidden" name="old_app" value="$app">);
print qq(<input type="hidden" name="radio_select" value="">);
&trans_modules_list_get_options ([$app], '');
if (my $msg = &trans_monitor_panel ($app, $in{'monitor'}))
{
$_success = $msg;
}
# Set success or error msg
&init_msg ();
# if a module have been chosen
if ($app ne '')
{
my $updated = 0;
my %hash_short = ();
my %hash_long = ();
my $ref_line_short = '';
my $ref_line_long = '';
# read in main module.info/theme.info
&read_file_descs (
"$path/$finfo.info",
\$ref_line_short, \$ref_line_long,
\%hash_short, \%hash_long);
# read dedicated module.info file per language if some
if ($finfo eq 'module')
{
opendir (DH, "$path/");
foreach my $item (readdir (DH))
{
if ($item =~ /^$finfo.info\./)
{
&read_file_descs (
"$path/$item",
undef, undef,
\%hash_short, \%hash_long);
}
}
closedir (DH);
}
# Check for missed languages (sometimes there is more languages in lang/
# than in module.info/theme.info)
opendir (DH, "$path/lang/");
foreach my $item (readdir (DH))
{
if ($item ne $ref_lang && &trans_is_language ($item))
{
$hash_short{$item} = '' if (!exists ($hash_short{$item}));
$hash_long{$item} = '' if (!exists ($hash_long{$item}));
}
}
closedir (DH);
# Tabs management
my @tabs = (['short', $text{'MODULE_INFO_TAB_SHORT_TITLE'}]);
if ($ref_line_long)
{
push (@tabs, (['long', $text{'MODULE_INFO_TAB_LONG_TITLE'}]));
}
print ui_tabs_start(\@tabs, 'admin', 'short');
print ui_tabs_start_tab('infos', 'short');
&trans_display_description_table (
'desc', $text{'MODULE_CONFIG_SHORT_DESCRIPTION3'},
$ref_line_short, \%hash_short);
print ui_tabs_end_tab('infos', 'short');
if ($ref_line_long)
{
print ui_tabs_start_tab('infos', 'long');
&trans_display_description_table (
'longdesc', $text{'MODULE_CONFIG_LONG_DESCRIPTION3'},
$ref_line_long, \%hash_long);
print ui_tabs_end_tab('infos', 'long');
}
print ui_tabs_end();
print qq(<div><button type="submit" name="update" class="btn btn-success ui_form_end_submit"><i class="fa fa-fw fa-check-circle-o"></i> <span>$text{'MODULE_CONFIG_UPDATE_BUTTON'}</span></button></div>);
}
print qq(</form>);
print qq(</p>);
&trans_footer ('', $text{'MODULE_INDEX'}, $_success, $_error, $_info);