-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlanguage_codechange.php
More file actions
199 lines (165 loc) · 4.5 KB
/
language_codechange.php
File metadata and controls
199 lines (165 loc) · 4.5 KB
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
<?php
/**
*
* @author carlino1994 / Carlo / www.phpbbitalia.net
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
* Create code changes for phpBB translations
*
*/
/**
* Append diff to file or echo
* File will be stored in this script directory
*/
$append = false;
/**
* Set translation ISO, phpBB versions and optional author information
*/
$iso = 'en';
$previousVersion = '3.0.9';
$latestVersion = '3.0.10';
$author_username = 'naderman';
$author_email = 'naderman@phpbb.com';
$author_realname = 'Nils Adermann';
$author_website = 'http://www.phpbb.com';
/**
* Translations root directory (with final slash)
*/
$directory = array(
'previous' => "./phpBB/{$previousVersion}/language/{$iso}/",
'latest' => "./phpBB/{$latestVersion}/language/{$iso}/"
);
$files = array(
'new' => array(),
'edit' => array()
);
header("Content-Type: text/plain; charset=UTF-8");
include('./diff_class.php');
$text = createDiff($directory['latest']);
$text = DiffHeader() . $text . DiffFooter();
if ($append)
{
$filename = "./phpbb-{$previousVersion}_to_{$latestVersion}_language_{$iso}.txt";
$fp = fopen($filename, 'wb');
if (!$fp)
{
echo "Unable to create {$filename}";
}
else
{
fwrite($fp, $text);
fclose($fp);
chmod($filename, 0666);
echo "File appended to {$filename}";
}
}
else
{
echo $text;
}
/**
* Create diff for all files in $path directory
*/
function createDiff($path)
{
global $directory, $files, $iso;
$text = '';
foreach (glob($path . "*") as $filename)
{
if (is_dir($filename))
{
$text .= createDiff($filename . '/');
}
else
{
$phpbb_filename = str_replace($directory['latest'], '', $filename);
$phpbb_file_ext = substr(strrchr($phpbb_filename, '.'), 1);
if (file_exists($directory['previous'] . $phpbb_filename) && ($phpbb_file_ext == 'php' || $phpbb_file_ext == 'htm' || $phpbb_file_ext == 'txt'))
{
$lines1 = file($directory['previous'] . $phpbb_filename);
$lines2 = file($directory['latest'] . $phpbb_filename);
$diff = new Diff($lines1, $lines2);
$fmt = new BBCodeDiffFormatter(false, 5, false);
$format = $fmt->format($diff, $lines1);
if (!empty($format))
{
$text .= $fmt->format_open("language/{$iso}/" . $phpbb_filename);
$text .= $format;
$text .= $fmt->format_close("language/{$iso}/" . $phpbb_filename);
$files['edit'][] = $phpbb_filename;
}
}
else
{
// New file
$files['new'][] = $phpbb_filename;
}
}
}
return $text;
}
/**
* Create diff file header
*/
function DiffHeader()
{
global $iso, $previousVersion, $latestVersion, $author_username, $author_email, $author_realname, $author_website, $files;
$text = '';
$text .= "############################################################## \n";
$text .= "## Title: phpBB {$previousVersion} to phpBB {$latestVersion} Language Pack Changes [{$iso}] \n";
$text .= "## Author: {$author_username} < {$author_email} >" . (!empty($author_realname) ? " ({$author_realname})" : '') . (!empty($author_website) ? " ({$author_website})" : '') . " \n";
$text .= "## Description: \n";
$text .= "## \n";
$text .= "## \n";
$text .= "## These are the phpBB {$previousVersion} to phpBB {$latestVersion} Language Pack [{$iso}] Changes summed up into a\n";
$text .= "## little Mod. These changes are only partial and do not include any code changes,\n";
$text .= "## therefore not meant for updating phpBB.\n";
$text .= "## \n";
$text .= "## \n";
$text .= "## \n";
$text .= "## \n";
if (sizeof($files['edit']))
{
$text .= "## Files To Edit: \n";
foreach($files['edit'] as $filename)
{
$text .= "## language/{$iso}/{$filename}\n";
}
$text .= "## \n";
}
if (sizeof($files['new']))
{
$text .= "## Included Files: \n";
foreach($files['new'] as $filename)
{
$text .= "## language/{$iso}/{$filename}\n";
}
$text .= "## \n";
}
$text .= "## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2 \n";
$text .= "############################################################## \n";
$text .= "\n";
if (sizeof($files['new']))
{
$text .= "#\n#-----[ COPY ]------------------------------------------\n#\n";
foreach($files['new'] as $filename)
{
$text .= "copy language/{$iso}/{$filename} to language/{$iso}/{$filename}\n";
}
$text .= "\n";
}
return $text;
}
/**
* Create diff file footer
*/
function DiffFooter()
{
$text = '';
$text .= "# \n";
$text .= "#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ \n";
$text .= "# \n";
$text .= "# EoM";
return $text;
}
?>