Completed
Push — development ( f93eb8...ffa1a0 )
by Thomas
20s
created

htdocs/translate.php (92 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/***************************************************************************
3
 * for license information see LICENSE.md
4
 ***************************************************************************/
5
6
require __DIR__ . '/lib2/web.inc.php';
7
require_once __DIR__ . '/lib2/translate.class.php';
8
require_once __DIR__ . '/lib2/translationHandler.class.php';
9
10
/* config section
11
 */
12
global $msDirlist;
13
$msDirlist = [];
14
$msDirlist[] = '.';
15
$msDirlist[] = './config2';
16
$msDirlist[] = './lang/de';
17
$msDirlist[] = './lang/de/ocstyle';
18
$msDirlist[] = './lang/de/ocstyle/lib';
19
$msDirlist[] = './lib';
20
$msDirlist[] = './lib2';
21
$msDirlist[] = './lib2/logic';
22
$msDirlist[] = './lib2/search';
23
$msDirlist[] = './templates2/mail';
24
$msDirlist[] = './templates2/ocstyle';
25
$msDirlist[] = './util/notification';
26
$msDirlist[] = './util/watchlist';
27
$msDirlist[] = './util2/cron';
28
$msDirlist[] = './util2/cron/modules';
29
30
// recursively add directory trees to $msDirlist
31
addClassesDirectoriesToDirlist('src/Oc/Libse');
32
33
$transIdCols = [
34
    ['table' => 'attribute_categories', 'text' => 'name', 'trans_id' => 'trans_id'],
35
    ['table' => 'attribute_groups', 'text' => 'name', 'trans_id' => 'trans_id'],
36
    ['table' => 'cache_attrib', 'text' => 'name', 'trans_id' => 'trans_id'],
37
    ['table' => 'cache_attrib', 'text' => 'html_desc', 'trans_id' => 'html_desc_trans_id'],
38
    ['table' => 'cache_report_reasons', 'text' => 'name', 'trans_id' => 'trans_id'],
39
    ['table' => 'cache_report_status', 'text' => 'name', 'trans_id' => 'trans_id'],
40
    ['table' => 'cache_size', 'text' => 'name', 'trans_id' => 'trans_id'],
41
    ['table' => 'cache_status', 'text' => 'name', 'trans_id' => 'trans_id'],
42
    ['table' => 'cache_type', 'text' => 'name', 'trans_id' => 'trans_id'],
43
    ['table' => 'cache_type', 'text' => 'short2', 'trans_id' => 'short2_trans_id'],
44
    ['table' => 'coordinates_type', 'text' => 'name', 'trans_id' => 'trans_id'],
45
    ['table' => 'countries', 'text' => 'name', 'trans_id' => 'trans_id'],
46
    ['table' => 'languages', 'text' => 'name', 'trans_id' => 'trans_id'],
47
    ['table' => 'log_types', 'text' => 'name', 'trans_id' => 'trans_id'],
48
    ['table' => 'profile_options', 'text' => 'name', 'trans_id' => 'trans_id'],
49
    ['table' => 'statpics', 'text' => 'description', 'trans_id' => 'trans_id'],
50
    ['table' => 'sys_menu', 'text' => 'menustring', 'trans_id' => 'menustring_trans_id'],
51
    ['table' => 'sys_menu', 'text' => 'title', 'trans_id' => 'title_trans_id'],
52
    ['table' => 'towns', 'text' => 'name', 'trans_id' => 'trans_id'],
53
];
54
55
$tpl->name = 'translate';
56
$tpl->menuitem = MNU_ADMIN_TRANSLATE;
57
58
$login->verify();
59
$access = new translateAccess();
60
61
if (!$access->hasAccess()) {
62
    if ($login->admin & ADMIN_USER) {
63
        $tpl->redirect('adminreports.php');
64
    } else {
65
        $tpl->error(ERROR_NO_ACCESS);
66
    }
67
}
68
69
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
70
71
// zu übersetzende Sprache anzeigen
72
$translang = isset($_REQUEST['translang']) ? strtoupper($_REQUEST['translang']) : strtoupper(
73
    $opt['template']['locale']
74
);
75
if (!isset($opt['locale'][$translang])) {
76
    $action = 'selectlang';
77
}
78
79
// prüfen, ob die aktuelle data.sql eingespielt wurde
80
if (calcDataSqlChecksum(true) != getSysConfig('datasql_checksum', '')) {
0 ignored issues
show
Deprecated Code introduced by
The function getSysConfig() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
81
    $tpl->assign('datasqlfailed', true);
82
} else {
83
    $tpl->assign('datasqlfailed', false);
84
}
85
86
switch ($action) {
87
    case 'selectlang':
88
        break;
89
90
    case 'verify':
91
        verify();
92
        break;
93
94
    case 'resetids':
95
        resetIds();
96
        break;
97
98
    case 'clearcache':
99
        clearCache();
100
        break;
101
102
    case 'export':
103
        export();
104
        break;
105
106
    case 'xmlexport':
107
        xmlexport();
108
        break;
109
110
    case 'xmlimport':
111
        break;
112
113
    case 'xmlimport2':
114
        xmlimport2();
115
        break;
116
117
    case 'xmlimport3':
118
        xmlimport3();
119
        break;
120
121
    case 'textexportnew':
122
        textexport($translang, false);
123
        break;
124
125
    case 'textexportall':
126
        textexport($translang, true);
127
        break;
128
129
    case 'textimport':
130
        break;
131
132
    case 'textimport2':
133
        textimport($translang);
134
        break;
135
136
    case 'edit':
137
        if (!$access->mayTranslate($translang)) {
138
            $tpl->error(ERROR_NO_ACCESS);
139
        }
140
        edit();
141
        break;
142
143
    case 'copy_en':
144
        copy_english_texts();
145
        break;
146
147
    case 'listfaults':
148
        $trans = sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
149
            'SELECT `sys_trans`.`id`,
150
                    `sys_trans`.`text`
151
             FROM `sys_trans`
152
             LEFT JOIN `sys_trans_ref`
153
                ON `sys_trans`.`id`=`sys_trans_ref`.`trans_id`
154
             WHERE ISNULL(`sys_trans_ref`.`trans_id`)
155
             ORDER BY `sys_trans`.`id` DESC'
156
        );
157
        $tpl->assign_rs('trans', $trans);
158
        sql_free_result($trans);
0 ignored issues
show
Deprecated Code introduced by
The function sql_free_result() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
159
        break;
160
161
    case 'listall':
162
        $trans = sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
163
            "SELECT `sys_trans`.`id`,
164
                    `sys_trans`.`text`,
165
                    `sys_trans_text`.`text` AS `trans`
166
             FROM `sys_trans`
167
             LEFT JOIN `sys_trans_text`
168
               ON `sys_trans`.`id`=`sys_trans_text`.`trans_id`
169
               AND `sys_trans_text`.`lang`='&1'
170
             ORDER BY `sys_trans`.`id` DESC",
171
            $translang
172
        );
173
        $tpl->assign_rs('trans', $trans);
174
        sql_free_result($trans);
0 ignored issues
show
Deprecated Code introduced by
The function sql_free_result() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
175
        break;
176
177
    case 'remove':
178
        if (!$access->mayTranslate($translang)) {
179
            $tpl->error(ERROR_NO_ACCESS);
180
        }
181
        remove();
182
        break;
183
184
    case 'scan':
185
        scan();
186
        break;
187
188
    case 'scanstart':
189
        scanStart();
190
        break;
191
192
    case 'scanfile':
193
        $filename = isset($_REQUEST['filename']) ? $_REQUEST['filename'] : '';
194
        scanFile($filename);
195
        exit;
196
197
    case 'quicknone':
198
        $cookie->un_set('translate_mode');
199
        break;
200
201
    case 'quicknew':
202
        $cookie->set('translate_mode', 'new');
203
        break;
204
205
    case 'quickall':
206
        $cookie->set('translate_mode', 'all');
207
        break;
208
209
    default:
210
        $action = 'listnew';
211
        $trans = sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
212
            "SELECT DISTINCT `sys_trans`.`id`,
213
                             `sys_trans`.`text`
214
             FROM `sys_trans`
215
             LEFT JOIN `sys_trans_text`
216
               ON `sys_trans`.`id`=`sys_trans_text`.`trans_id`
217
               AND `sys_trans_text`.`lang`='&1'
218
             LEFT JOIN `sys_trans_ref`
219
               ON `sys_trans`.`id`=`sys_trans_ref`.`trans_id`
220
             WHERE ISNULL(`sys_trans_text`.`trans_id`)
221
               OR `sys_trans_text`.`text`=''
222
             ORDER BY `sys_trans`.`id` DESC",
223
            $translang
224
        );
225
        $tpl->assign_rs('trans', $trans);
226
        sql_free_result($trans);
0 ignored issues
show
Deprecated Code introduced by
The function sql_free_result() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
227
}
228
229
$languages = [];
230
foreach ($opt['locale'] as $k => $v) {
231
    if ($access->mayTranslate($k)) {
232
        $languages[] = $k;
233
    }
234
}
235
$tpl->assign('languages', $languages);
236
237
$tpl->assign('translang', $translang);
238
$tpl->assign('action', $action);
239
$tpl->display();
240
241
/* $truncatLastInsert = true   for downloaded file
242
 * $truncatLastInsert = false  to sign self generated file (in function export)
243
 */
244
/**
245
 * @param boolean $truncateLastInsert
246
 * @return string
247
 */
248
function calcDataSqlChecksum($truncateLastInsert)
249
{
250
    global $opt;
251
252
    if (!file_exists(__DIR__ . '/../sql/static-data/data.sql')) {
253
        return '';
254
    }
255
256
    $content = file_get_contents(__DIR__ . '/../sql/static-data/data.sql');
257
258
    // at the end is an INSERT of the current checksum
259
    // to calculate this checksum, we have to trim the end before that statement and the linefeed before
260
    // windows lineFeeds will be converted to linux lineFeeds
261
    $content = str_replace("\r\n", "\n", $content);
262
263
    if ($truncateLastInsert == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
264
        $pos = strrpos($content, 'INSERT');
265
        $content = substr($content, 0, $pos);
266
    }
267
268
    while (substr($content, - 1) == "\n") {
269
        $content = substr($content, 0, - 1);
270
    }
271
272
    return md5($content);
273
}
274
275
function remove()
0 ignored issues
show
remove uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
276
{
277
    global $tpl, $translang;
278
279
    $id = isset($_REQUEST['id']) ? $_REQUEST['id'] + 0 : 0;
280
281
    sql("DELETE FROM `sys_trans` WHERE `id`='&1'", $id);
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
282
    sql("DELETE FROM `sys_trans_text` WHERE `trans_id`='&1'", $id);
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
283
    sql("DELETE FROM `sys_trans_ref` WHERE `trans_id`='&1'", $id);
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
284
285
    $tpl->redirect('translate.php?translang=' . $translang);
286
}
287
288
function edit()
0 ignored issues
show
edit uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
289
{
290
    global $tpl, $translang;
291
292
    $id = isset($_REQUEST['id']) ? $_REQUEST['id'] + 0 : 0;
293
294
    if (isset($_REQUEST['usetrans'])) {
295
        $usetransid = $_REQUEST['usetrans'] + 0;
296
297
        $rs = sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
298
            "SELECT `lang`,
299
                    `text`
300
             FROM `sys_trans_text`
301
             WHERE `trans_id`='&1'",
302
            $usetransid
303
        );
304
        while ($r = sql_fetch_assoc($rs)) {
0 ignored issues
show
Deprecated Code introduced by
The function sql_fetch_assoc() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
305
            sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
306
                "INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`)
307
                 VALUES ('&1', '&2', '&3')
308
                 ON DUPLICATE KEY UPDATE `text`='&3'",
309
                $id,
310
                $r['lang'],
311
                $r['text']
312
            );
313
        }
314
        sql_free_result($rs);
0 ignored issues
show
Deprecated Code introduced by
The function sql_free_result() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
315
        $tpl->redirect('translate.php?translang=' . $translang . '&action=edit&id=' . $id);
316
    } else {
317
        if (isset($_REQUEST['submit'])) {
318
            $transText = isset($_REQUEST['transText']) ? $_REQUEST['transText'] : '';
319
            sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
320
                "INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`)
321
                 VALUES ('&1', '&2', '&3')
322
                 ON DUPLICATE KEY UPDATE `text`='&3'",
323
                $id,
324
                $translang,
325
                $transText
326
            );
327
        }
328
    }
329
330
    $rs = sql("SELECT `id`, `text` FROM `sys_trans` WHERE `id`='&1'", $id);
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
331
    if (!$r = sql_fetch_assoc($rs)) {
0 ignored issues
show
Deprecated Code introduced by
The function sql_fetch_assoc() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
332
        $tpl->error('Trans id not exists');
333
    }
334
    sql_fetch_array($rs);
0 ignored issues
show
Deprecated Code introduced by
The function sql_fetch_array() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
335
336
    $tpl->assign('id', $r['id']);
337
    $tpl->assign('text', $r['text']);
338
339
    $rs = sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
340
        "SELECT `resource_name`, `line`
341
         FROM `sys_trans_ref`
342
         WHERE `trans_id`='&1'
343
         ORDER BY resource_name, line ASC",
344
        $id
345
    );
346
    $tpl->assign_rs('transRef', $rs);
347
    sql_free_result($rs);
0 ignored issues
show
Deprecated Code introduced by
The function sql_free_result() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
348
349
    // built sql string to search for texts with little difference (levensthein() would be better, but not available in MYSQL)
350
    $sWhereSql =
351
        "SOUNDEX('" . sql_escape($r['text']) . "')=SOUNDEX(`sys_trans`.`text`)
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
352
         OR SOUNDEX('" . sql_escape($r['text']) . "')=SOUNDEX(`sys_trans_text`.`text`)";
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
353
354
    $trans = sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
355
        "SELECT DISTINCT `sys_trans`.`id`, `sys_trans`.`text`
356
         FROM `sys_trans`
357
         INNER JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id`
358
         WHERE `sys_trans`.`id`!='&1' AND (" . $sWhereSql . ")",
359
        $id
360
    );
361
    $tpl->assign_rs('trans', $trans);
362
    sql_free_result($trans);
0 ignored issues
show
Deprecated Code introduced by
The function sql_free_result() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
363
364
    $tpl->assign(
365
        'transText',
366
        sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
367
            "SELECT `text`
368
             FROM `sys_trans_text`
369
             WHERE `trans_id`='&1' AND `lang`='&2'",
370
            '',
371
            $id,
372
            $translang
373
        )
374
    );
375
}
376
377
function clearCache()
378
{
379
    global $tpl, $translang, $translationHandler;
380
381
    unlinkFiles('var/cache2', 'php');
382
383
    unlinkFiles('var/cache2/smarty/cache', 'tpl');
384
    unlinkFiles('var/cache2/smarty/compiled', 'inc');
385
    unlinkFiles('var/cache2/smarty/compiled', 'php');
386
387
    $translationHandler->createMessageFiles();
388
389
    $tpl->redirect('translate.php?translang=' . $translang);
390
}
391
392
/**
393
 * @param string $relbasedir
394
 * @param string $ext
395
 */
396
function unlinkFiles($relbasedir, $ext)
397
{
398
    global $opt;
399
400
    if (substr($relbasedir, - 1, 1) != '/') {
401
        $relbasedir .= '/';
402
    }
403
404
    if ($opt['rootpath'] . $relbasedir) {
405
        if ($dh = opendir($opt['rootpath'] . $relbasedir)) {
406
            while (($file = readdir($dh)) !== false) {
407
                if ($file != '.' && $file != '..' && is_file($opt['rootpath'] . $relbasedir . $file)) {
408 View Code Duplication
                    if (substr($file, - (strlen($ext) + 1), strlen($ext) + 1) == '.' . $ext) {
409
                        unlink($opt['rootpath'] . $relbasedir . $file);
410
                    }
411
                }
412
            }
413
        }
414
        closedir($dh);
415
    }
416
}
417
418
/**
419
 *
420
 */
421
function resetIds()
422
{
423
    global $translang, $tpl;
424
425
    if (sql_connect_maintenance() == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Deprecated Code introduced by
The function sql_connect_maintenance() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
426
        $tpl->error(ERROR_DB_NO_ROOT);
427
    }
428
429
    // clean up dead refs
430
    sql_temp_table('transDeadIds');
0 ignored issues
show
Deprecated Code introduced by
The function sql_temp_table() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
431
    sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
432
        "CREATE TEMPORARY TABLE &transDeadIds (`trans_id` INT(11) PRIMARY KEY)
433
         SELECT DISTINCT `sys_trans_ref`.`trans_id`
434
         FROM `sys_trans_ref`
435
         LEFT JOIN `sys_trans` ON `sys_trans_ref`.`trans_id`=`sys_trans`.`id`
436
         WHERE ISNULL(`sys_trans`.`id`)"
437
    );
438
    sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
439
        "DELETE `sys_trans_ref`
440
         FROM `sys_trans_ref`, &transDeadIds
441
         WHERE `sys_trans_ref`.`trans_id`=&transDeadIds.`trans_id`"
442
    );
443
    sql_drop_temp_table('transDeadIds');
0 ignored issues
show
Deprecated Code introduced by
The function sql_drop_temp_table() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
444
445
    sql_temp_table('transDeadIds');
0 ignored issues
show
Deprecated Code introduced by
The function sql_temp_table() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
446
    sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
447
        "CREATE TEMPORARY TABLE &transDeadIds (`trans_id` INT(11) PRIMARY KEY)
448
         SELECT DISTINCT `sys_trans_text`.`trans_id`
449
         FROM `sys_trans_text`
450
         LEFT JOIN `sys_trans` ON `sys_trans_text`.`trans_id`=`sys_trans`.`id`
451
         WHERE ISNULL(`sys_trans`.`id`)"
452
    );
453
    sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
454
        "DELETE `sys_trans_text`
455
         FROM `sys_trans_text`, &transDeadIds
456
         WHERE `sys_trans_text`.`trans_id`=&transDeadIds.`trans_id`"
457
    );
458
    sql_drop_temp_table('transDeadIds');
0 ignored issues
show
Deprecated Code introduced by
The function sql_drop_temp_table() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
459
460
    if (sql_value('SELECT COUNT(*) FROM `sys_trans` WHERE `id`=1', 0) == 0) {
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
461
        useId(1);
462
    }
463
464
    $lastId = sql_value('SELECT MAX(`id`) FROM `sys_trans`', 0);
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
465
466
    while ($id = sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
467
        "SELECT `s1`.`id`+1
468
         FROM `sys_trans` AS `s1`
469
         LEFT JOIN `sys_trans` AS `s2` ON `s1`.`id`+1=`s2`.`id`
470
         WHERE ISNULL(`s2`.`id`) AND `s1`.`id`<'&1'
471
         ORDER BY `s1`.`id` LIMIT 1",
472
        0,
473
        $lastId
474
    )) {
475
        if ($lastId + 1 == $id) {
476
            break;
477
        }
478
        setId($lastId, $id);
479
        $lastId = sql_value('SELECT MAX(`id`) FROM `sys_trans`', 0);
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
480
    }
481
482
    // need alter privileges
483
    $lastId = sql_value('SELECT MAX(`id`) FROM `sys_trans`', 0);
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
484
    sql("ALTER TABLE `sys_trans` AUTO_INCREMENT = &1", $lastId + 1);
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
485
486
    $tpl->redirect('translate.php?translang=' . $translang);
487
}
488
489
/**
490
 * @param integer $freeId
491
 */
492
function useId($freeId)
493
{
494
    $lastId = sql_value('SELECT MAX(`id`) FROM `sys_trans`', 0);
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
495
    if ($lastId + 1 == $freeId) {
496
        return;
497
    }
498
    setId($lastId, $freeId);
499
}
500
501
/**
502
 * @param integer $oldId
503
 * @param $newId
504
 */
505
function setId($oldId, $newId)
506
{
507
    global $transIdCols;
508
509
    sql("UPDATE `sys_trans` SET `id`='&1' WHERE `id`='&2'", $newId, $oldId);
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
510
    sql("UPDATE `sys_trans_ref` SET `trans_id`='&1' WHERE `trans_id`='&2'", $newId, $oldId);
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
511
    sql("UPDATE `sys_trans_text` SET `trans_id`='&1' WHERE `trans_id`='&2'", $newId, $oldId);
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
512
513
    foreach ($transIdCols as $col) {
514
        sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
515
            'UPDATE `' . $col['table'] . '`
516
             SET `' . $col['trans_id'] . "`='&1'
517
             WHERE `" . $col['trans_id'] . "`='&2'",
518
            $newId,
519
            $oldId
520
        );
521
    }
522
}
523
524
function export()
525
{
526
    global $opt, $tpl, $translang;
527
528
    $structure = enumSqlFiles(__DIR__ . '/../sql/tables');
529
    foreach ($structure as $sTable) {
530
        sql_export_structure_to_file(__DIR__ . '/../sql/tables/' . $sTable . '.sql', $sTable);
0 ignored issues
show
Deprecated Code introduced by
The function sql_export_structure_to_file() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
531
    }
532
533
    // static data tables
534
    $stab[] = 'attribute_categories';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$stab was never initialized. Although not strictly required by PHP, it is generally a good practice to add $stab = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
535
    $stab[] = 'attribute_groups';
536
    $stab[] = 'cache_attrib';
537
    $stab[] = 'cache_logtype';
538
    $stab[] = 'cache_report_reasons';
539
    $stab[] = 'cache_report_status';
540
    $stab[] = 'cache_size';
541
    $stab[] = 'cache_status';
542
    $stab[] = 'cache_type';
543
    $stab[] = 'coordinates_type';
544
    $stab[] = 'countries';
545
    $stab[] = 'countries_list_default';
546
    $stab[] = 'countries_options';
547
    $stab[] = 'helppages';
548
    $stab[] = 'languages';
549
    $stab[] = 'languages_list_default';
550
    $stab[] = 'logentries_types';
551
    $stab[] = 'log_types';
552
    $stab[] = 'nodes';
553
    $stab[] = 'object_types';
554
    $stab[] = 'profile_options';
555
    $stab[] = 'replication_overwritetypes';
556
    $stab[] = 'search_ignore';
557
    $stab[] = 'statpics';
558
    $stab[] = 'sys_menu';
559
    $stab[] = 'sys_trans';
560
    $stab[] = 'sys_trans_ref';
561
    $stab[] = 'sys_trans_text';
562
    $stab[] = 'towns';
563
    $stab[] = 'watches_waitingtypes';
564
565
    sql_export_tables_to_file(__DIR__ . '/../sql/static-data/data.sql', $stab);
0 ignored issues
show
Deprecated Code introduced by
The function sql_export_tables_to_file() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
566
567
    $checksum = calcDataSqlChecksum(false);
568
    $f = fopen(__DIR__ . '/../sql/static-data/data.sql', 'ab');
569
    fwrite(
570
        $f,
571
        'INSERT INTO `sysconfig` (`name`, `value`)'
572
        . " VALUES ('datasql_checksum', '" . sql_escape($checksum) . "')"
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
573
        . " ON DUPLICATE KEY UPDATE `value`='" . sql_escape($checksum) . "';\n"
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
574
    );
575
    fclose($f);
576
577
    setSysConfig('datasql_checksum', $checksum);
0 ignored issues
show
Deprecated Code introduced by
The function setSysConfig() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
578
579
    $tpl->redirect('translate.php?translang=' . $translang);
580
}
581
582
/**
583
 * @param string $dir
584
 * @return array
585
 */
586
function enumSqlFiles($dir)
587
{
588
    $retval = [];
589
    if (is_dir($dir)) {
590
        if ($dh = opendir($dir)) {
591 View Code Duplication
            while (($file = readdir($dh)) !== false) {
592
                if (substr($file, - 4) == '.sql') {
593
                    $retval[] = substr($file, 0, strlen($file) - 4);
594
                }
595
            }
596
            closedir($dh);
597
        }
598
    }
599
600
    return $retval;
601
}
602
603
function scan()
604
{
605
    global $tpl, $msDirlist;
606
607
    $files = [];
608
    foreach ($msDirlist as $dir) {
609
        $hDir = opendir($dir);
610
        if ($hDir !== false) {
611
            while (($file = readdir($hDir)) !== false) {
612
                if (is_file($dir . '/' . $file)) {
613
                    if ((substr($file, - 4) == '.tpl') || (substr($file, - 4) == '.php')) {
614
                        $files[] = $dir . '/' . $file;
615
                    }
616
                }
617
            }
618
            closedir($hDir);
619
        }
620
    }
621
622
    $tpl->assign('files', $files);
623
}
624
625
function scanStart()
626
{
627
    global $translationHandler, $transIdCols;
628
629
    $translationHandler->clearReferences();
630
631
    foreach ($transIdCols as $col) {
632
        $translationHandler->importFromTable($col['table'], $col['text'], $col['trans_id']);
633
    }
634
}
635
636
function scanFile($filename)
637
{
638
    global $msDirlist, $translationHandler;
639
640
    // check if supplied filename is within allowed path!
641
    $bFound = false;
642
    foreach ($msDirlist as $dir) {
643
        if (substr($dir, - 1) != '/') {
644
            $dir .= '/';
645
        }
646
647
        if (substr($filename, 0, strlen($dir)) == $dir) {
648
            $file = substr($filename, strlen($dir));
649
            if (strpos($file, '/') === false) {
650
                if ((substr($filename, - 4) == '.tpl') || (substr($filename, - 4) == '.php')) {
651
                    $bFound = true;
652
                    break;
653
                }
654
            }
655
        }
656
    }
657
    if ($bFound == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
658
        return;
659
    }
660
661
    if (file_exists($filename) == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
662
        return;
663
    }
664
665
    $transFileScan = new translate_filescan($filename);
666
    $transFileScan->parse();
667
668
    foreach ($transFileScan->textlist as $item) {
669
        $translationHandler->addText($item['text'], $filename, $item['line']);
670
    }
671
672
    exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The function scanFile() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
673
}
674
675
function xmlexport()
676
{
677
    global $opt;
678
679
    header('Content-type:application/octet-stream');
680
    header('Content-Disposition:attachment;filename="translation.xml"');
681
682
    $lang = [];
683
    foreach ($opt['template']['locales'] as $k => $v) {
684
        $lang[] = $k;
685
    }
686
687
    @date_default_timezone_set('GMT');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
688
    $writer = new XMLWriter();
689
    $writer->openURI('php://output');
690
    $writer->startDocument('1.0', 'UTF-8', 'yes');
691
    $writer->setIndent(2);
692
693
    $writer->startElement('translation');
694
    $writer->writeAttribute('version', '1.0');
695
    $writer->writeAttribute('timestamp', date('c'));
696
697
    $rs = sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
698
        "SELECT `id`, `text`
699
         FROM `sys_trans`
700
         ORDER BY `id` ASC"
701
    );
702
    while ($r = sql_fetch_assoc($rs)) {
0 ignored issues
show
Deprecated Code introduced by
The function sql_fetch_assoc() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
703
        $writer->startElement('text');
704
        $writer->writeAttribute('id', $r['id']);
705
706
        $writer->writeElement('code', $r['text']);
707
        $countLang = count($lang);
708
        for ($n = 0; $n < $countLang; $n++) {
709
            $writer->writeElement(
710
                $lang[$n],
711
                sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
712
                    "SELECT `text`
713
                     FROM `sys_trans_text`
714
                     WHERE `trans_id`='&1' AND `lang`='&2'",
715
                    '',
716
                    $r['id'],
717
                    $lang[$n]
718
                )
719
            );
720
        }
721
        $rsUsage = sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
722
            "SELECT `resource_name`, `line`
723
             FROM `sys_trans_ref`
724
             WHERE `trans_id`='&1'",
725
            $r['id']
726
        );
727
        while ($rUsage = sql_fetch_assoc($rsUsage)) {
0 ignored issues
show
Deprecated Code introduced by
The function sql_fetch_assoc() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
728
            $line = '';
729
            if ($rUsage['line'] != 0) {
730
                $line = ' (' . $rUsage['line'] . ')';
731
            }
732
            $writer->writeElement('usage', $rUsage['resource_name'] . $line);
733
        }
734
        sql_free_result($rsUsage);
0 ignored issues
show
Deprecated Code introduced by
The function sql_free_result() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
735
736
        $writer->endElement();
737
    }
738
    sql_free_result($rs);
0 ignored issues
show
Deprecated Code introduced by
The function sql_free_result() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
739
740
    $writer->endElement();
741
    $writer->endDocument();
742
    $writer->flush();
743
    exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The function xmlexport() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
744
}
745
746
function xmlimport2()
0 ignored issues
show
xmlimport2 uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
xmlimport2 uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
747
{
748
    global $translate, $tpl, $opt;
749
750 View Code Duplication
    if (!isset($_FILES['xmlfile']) || ($_FILES['xmlfile']['error'] != UPLOAD_ERR_OK)) {
751
        $tpl->error($translate->t('File upload failed!', '', '', 0));
752
    }
753
754
    $scanlang = [];
755
    foreach ($opt['locale'] as $k => $v) {
756
        if (isset($_REQUEST['lang' . $k]) && ($_REQUEST['lang' . $k] == '1')) {
757
            $scanlang[] = $k;
758
        }
759
    }
760
761
    $doc = new DOMDocument();
762
    if ($doc->load($_FILES['xmlfile']['tmp_name']) == false) {
763
        $tpl->error($translate->t('XML file could not be loaded!', '', '', 0));
764
    }
765
766
    $saTexts = [];
767
768
    foreach ($doc->documentElement->childNodes as $textnode) {
769
        if ($textnode->nodeType == XML_ELEMENT_NODE) {
770
            $codeElements = $textnode->getElementsByTagName('code');
771
            foreach ($scanlang as $lang) {
772
                $langElements = $textnode->getElementsByTagName($lang);
773
774
                $sCodeText = $codeElements->item(0)->nodeValue;
775
                $sLangText = $langElements->item(0)->nodeValue;
776
777
                $transId = sql_value("SELECT `id` FROM `sys_trans` WHERE `text`='&1'", 0, $sCodeText);
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
778
                if ($transId == 0) {
779
                    if ($sLangText != '') {
780
                        // text not in sys_trans => code changed while translation has been done
781
                        $saTexts[$sCodeText]['id'] = 0;
782
                        $saTexts[$sCodeText]['count'] = count($saTexts);
783
                        $saTexts[$sCodeText]['type'] = 1;
784
                        $saTexts[$sCodeText]['code'] = $sCodeText;
785
                        $saTexts[$sCodeText][$lang]['new'] = $sLangText;
786
                        $saTexts[$sCodeText][$lang]['old'] = '';
787
                    }
788
                } else {
789
                    $sOldText = sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
790
                        "SELECT `text` FROM `sys_trans_text` WHERE `trans_id`='&1' AND `lang`='&2'",
791
                        '',
792
                        $transId,
793
                        $lang
794
                    );
795
                    if (($sOldText == '') && ($sLangText != '')) {
796
                        // new translation
797
                        $saTexts[$sCodeText]['id'] = $transId;
798
                        $saTexts[$sCodeText]['count'] = count($saTexts);
799
                        $saTexts[$sCodeText]['type'] = 2;
800
                        $saTexts[$sCodeText]['code'] = $sCodeText;
801
                        $saTexts[$sCodeText][$lang]['new'] = $sLangText;
802
                        $saTexts[$sCodeText][$lang]['old'] = $sOldText;
803
                    } else {
804
                        if ($sOldText != $sLangText) {
805
                            // translation changed
806
                            $saTexts[$sCodeText]['id'] = $transId;
807
                            $saTexts[$sCodeText]['count'] = count($saTexts);
808
                            $saTexts[$sCodeText]['type'] = 3;
809
                            $saTexts[$sCodeText]['code'] = $sCodeText;
810
                            $saTexts[$sCodeText][$lang]['new'] = $sLangText;
811
                            $saTexts[$sCodeText][$lang]['old'] = $sOldText;
812
                        }
813
                    }
814
                }
815
            }
816
        }
817
    }
818
819
    $tpl->assign('texts', $saTexts);
820
}
821
822
function xmlimport3()
0 ignored issues
show
xmlimport3 uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
823
{
824
    global $opt, $translang, $tpl;
825
826
    $nCount = isset($_REQUEST['count']) ? $_REQUEST['count'] + 0 : 0;
827
828
    for ($nIndex = 1; $nIndex <= $nCount; $nIndex++) {
829
        if (isset($_REQUEST['useitem' . $nIndex]) && ($_REQUEST['useitem' . $nIndex] == '1')) {
830
            $sCode = base64_decode($_REQUEST['code' . $nIndex]);
831
            $transId = sql_value("SELECT `id` FROM `sys_trans` WHERE `text`='&1'", 0, $sCode);
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
832
833
            if ($transId != 0) {
834
                foreach ($opt['locale'] as $k => $v) {
835
                    if (isset($_REQUEST[$k . $nIndex . 'new'])) {
836
                        $sText = base64_decode($_REQUEST[$k . $nIndex . 'new']);
837
838
                        sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
839
                            "INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`)
840
                             VALUES ('&1', '&2', '&3')
841
                             ON DUPLICATE KEY UPDATE `text`='&3'",
842
                            $transId,
843
                            $k,
844
                            $sText
845
                        );
846
                    }
847
                }
848
            }
849
        }
850
    }
851
852
    $tpl->redirect('translate.php?translang=' . $translang);
853
}
854
855
function textexport($translang, $all)
856
{
857
    header('Content-type: text/plain');
858
    header('Content-Disposition: attachment; filename="translation.txt"');
859
860
    $rs = sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
861
        "SELECT `id`,
862
                IFNULL(`sys_trans_text`.`text`, `sys_trans`.`text`) AS `text`
863
         FROM `sys_trans`
864
         LEFT JOIN `sys_trans_text`
865
           ON `sys_trans_text`.`trans_id`=`sys_trans`.`id`
866
           AND `sys_trans_text`.`lang`='EN'
867
         ORDER BY `id` ASC"
868
    );
869
    while ($r = sql_fetch_assoc($rs)) {
0 ignored issues
show
Deprecated Code introduced by
The function sql_fetch_assoc() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
870
        $translated = sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
871
            "SELECT `text`
872
             FROM `sys_trans_text`
873
             WHERE `trans_id`='&1' AND `lang`='&2'",
874
            '',
875
            $r['id'],
876
            $translang
877
        );
878
        if (($all) || (mb_strlen($translated) == 0)) {
879
            $thisline = $r['id'] . "\r\n";
880
            $thisline .= $r['text'] . "\r\n";
881
            $thisline .= $translated . "\r\n";
882
            $thisline .= "\r\n";
883
            echo($thisline);
884
        }
885
    }
886
    sql_free_result($rs);
0 ignored issues
show
Deprecated Code introduced by
The function sql_free_result() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
887
888
    exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The function textexport() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
889
}
890
891
function textimport($lang)
0 ignored issues
show
textimport uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
892
{
893
    global $translate, $tpl, $opt;
894
895 View Code Duplication
    if (!isset($_FILES['textfile']) || ($_FILES['textfile']['error'] != UPLOAD_ERR_OK)) {
896
        $tpl->error($translate->t('File upload failed!', '', '', 0));
897
    }
898
899
    $data = file_get_contents($_FILES['textfile']['tmp_name']);
900
    $lines = explode("\n", $data);
901
902
    $saTexts = [];
903
904
    $countLines = count($lines);
905
    for ($i = 0; $i + 1 < $countLines; $i += 4) {
906
        $nId = trim($lines[$i]);
907
        $sEnText = trim($lines[$i + 1]);
908
        $sLangText = trim($lines[$i + 2]);
909
910
        if ($nId != '') {
911
            $transId = sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
912
                "SELECT `trans_id`
913
                 FROM `sys_trans_text`
914
                 WHERE `trans_id`='&1'
915
                   AND `lang`='EN'
916
                   AND BINARY `text`='&2'",
917
                0,
918
                $nId,
919
                $sEnText
920
            );
921
            if ($transId == 0) {
922
                $transId = sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
923
                    "SELECT `id`
924
                     FROM `sys_trans`
925
                     WHERE `id`='&1' AND BINARY `text`='&2'",
926
                    0,
927
                    $nId,
928
                    $sEnText
929
                );
930
            }
931
            if ($transId == 0) {
932
                if ($sLangText != '') {
933
                    // text not in sys_trans => code changed while translation has been done
934
                    $saTexts[$sEnText]['id'] = $nId;
935
                    $saTexts[$sEnText]['count'] = count($saTexts);
936
                    $saTexts[$sEnText]['type'] = 1;
937
                    $saTexts[$sEnText]['code'] = '';
938
                    $saTexts[$sEnText]['en'] = $sEnText;
939
                    $saTexts[$sEnText][$lang]['new'] = $sLangText;
940
                    $saTexts[$sEnText][$lang]['old'] = '';
941
                }
942
            } else {
943
                $sOldText = sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
944
                    "SELECT `text`
945
                     FROM `sys_trans_text`
946
                     WHERE `trans_id`='&1' AND `lang`='&2'",
947
                    '',
948
                    $transId,
949
                    $lang
950
                );
951
                $sCodeText = sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
952
                    "SELECT `text`
953
                     FROM `sys_trans`
954
                     WHERE `id`='&1'",
955
                    '',
956
                    $transId
957
                );
958
                if (($sOldText == '') && ($sLangText != '')) {
959
                    // new translation
960
                    $saTexts[$sCodeText]['id'] = $transId;
961
                    $saTexts[$sCodeText]['count'] = count($saTexts);
962
                    $saTexts[$sCodeText]['type'] = 2;
963
                    $saTexts[$sCodeText]['code'] = $sCodeText;
964
                    $saTexts[$sCodeText]['en'] = $sEnText;
965
                    $saTexts[$sCodeText][$lang]['new'] = $sLangText;
966
                    $saTexts[$sCodeText][$lang]['old'] = $sOldText;
967
                } else {
968
                    if ($sOldText != $sLangText) {
969
                        // translation changed
970
                        $saTexts[$sCodeText]['id'] = $transId;
971
                        $saTexts[$sCodeText]['count'] = count($saTexts);
972
                        $saTexts[$sCodeText]['type'] = 3;
973
                        $saTexts[$sCodeText]['code'] = $sCodeText;
974
                        $saTexts[$sCodeText]['en'] = $sEnText;
975
                        $saTexts[$sCodeText][$lang]['new'] = $sLangText;
976
                        $saTexts[$sCodeText][$lang]['old'] = $sOldText;
977
                    }
978
                }
979
            }
980
        }
981
    }
982
983
    $tpl->assign('texts', $saTexts);
984
}
985
986
function copy_english_texts()
987
{
988
    sql_temp_table('transtmp');
0 ignored issues
show
Deprecated Code introduced by
The function sql_temp_table() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
989
    sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
990
        "CREATE TEMPORARY TABLE &transtmp
991
         SELECT `st`.`id` AS `trans_id`, 'EN' AS `lang`, `st`.`text`
992
         FROM `sys_trans` `st`
993
         LEFT JOIN `sys_trans_text` `stt`
994
           ON `stt`.`trans_id`=`st`.`id`
995
           AND `stt`.`lang`='EN'
996
         WHERE `stt`.`trans_id` IS NULL"
997
    );
998
    sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
999
        "INSERT INTO `sys_trans_text`
1000
         SELECT *, NULL FROM &transtmp"
1001
    );
1002
    sql_drop_temp_table('transtmp');
0 ignored issues
show
Deprecated Code introduced by
The function sql_drop_temp_table() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
1003
}
1004
1005
function addClassesDirectoriesToDirlist($basedir)
1006
{
1007
    global $msDirlist;
1008
    $msDirlist[] = $basedir;
1009
1010
    $hDir = opendir($basedir);
1011
    if (!$hDir) {
1012
        return;
1013
    }
1014
1015
    if (substr($basedir, 0, - 1) != '/') {
1016
        $basedir .= '/';
1017
    }
1018
1019
    while (($file = readdir($hDir)) !== false) {
1020
        if ($file != '.' && $file != '..' && is_dir($basedir . $file)) {
1021
            addClassesDirectoriesToDirlist($basedir . $file);
1022
        }
1023
    }
1024
    closedir($hDir);
1025
}
1026
1027
function verify()
1028
{
1029
    global $tpl, $transIdCols;
1030
1031
    $inconsistencies = [];
1032
    foreach ($transIdCols as $col) {
1033
        if (!isset($col['verify']) || $col['verify']) {
1034
            $rs = sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
1035
                'SELECT
1036
                    `' . $col['text'] . '` `text`,
1037
                    `' . $col['trans_id'] . '` `trans_id`
1038
                 FROM `' . $col['table'] . '`'
1039
            );
1040
            while ($r = sql_fetch_assoc($rs)) {
0 ignored issues
show
Deprecated Code introduced by
The function sql_fetch_assoc() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
1041
                $st = sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
1042
                    "SELECT `text`
1043
                     FROM `sys_trans`
1044
                     WHERE `id`='&1'",
1045
                    false,
1046
                    $r['trans_id']
1047
                );
1048
                $en = sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
1049
                    "SELECT `text`
1050
                     FROM `sys_trans_text`
1051
                     WHERE `trans_id`='&1' AND `lang`='EN'",
1052
                    false,
1053
                    $r['trans_id']
1054
                );
1055
                if ($en != $r['text'] || $st != $r['text']) {
1056
                    $inconsistencies[] = [
1057
                        'id' => $r['trans_id'],
1058
                        'col' => $col['table'] . '.' . $col['text'],
1059
                        'org_text' => $r['text'],
1060
                        'sys_trans' => $st,
1061
                        'en_text' => $en,
1062
                    ];
1063
                }
1064
            }
1065
        }
1066
    }
1067
    $tpl->assign('inconsistencies', $inconsistencies);
1068
}
1069