-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
DropDownUploadFileBlock.php
85 lines (75 loc) · 2.46 KB
/
DropDownUploadFileBlock.php
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
<?php
/**
* HTML Generator for drop down for file upload
*
* @package PhpMyAdmin
*/
declare(strict_types=1);
namespace PhpMyAdmin\Html\Forms\Fields;
use PhpMyAdmin\FileListing;
use PhpMyAdmin\Message;
use PhpMyAdmin\Plugins\ImportPlugin;
use PhpMyAdmin\Util;
/**
* * HTML Generator for drop down for file upload
*
* @package PhpMyAdmin
*/
class DropDownUploadFileBlock implements FieldGenerator
{
/**
* Prepare the form used to select a file to import from the server upload
* directory
*
* @param ImportPlugin[] $import_list array of import plugins
* @param string $uploaddir upload directory
*
* @return string
*/
public static function generate($import_list, $uploaddir): string
{
$fileListing = new FileListing();
$block_html = '';
$block_html .= '<label for="radio_local_import_file">'
. sprintf(
__('Select from the web server upload directory <b>%s</b>:'),
htmlspecialchars(Util::userDir($uploaddir))
)
. '</label>';
$extensions = '';
foreach ($import_list as $import_plugin) {
if (! empty($extensions)) {
$extensions .= '|';
}
$extensions .= $import_plugin->getProperties()
->getExtension();
}
$matcher = '@\.(' . $extensions . ')(\.('
. $fileListing->supportedDecompressions() . '))?$@';
$active = isset($GLOBALS['timeout_passed'], $GLOBALS['local_import_file']) && $GLOBALS['timeout_passed']
? $GLOBALS['local_import_file']
: '';
$files = $fileListing->getFileSelectOptions(
Util::userDir($uploaddir),
$matcher,
$active
);
if ($files === false) {
Message::error(
__('The directory you set for upload work cannot be reached.')
)
->display();
} elseif (! empty($files)) {
$block_html .= "\n"
. ' <select style="margin: 5px" size="1" '
. 'name="local_import_file" '
. 'id="select_local_import_file">' . "\n"
. ' <option value=""> </option>' . "\n"
. $files
. ' </select>' . "\n";
} elseif (empty($files)) {
$block_html .= '<i>' . __('There are no files to upload!') . '</i>';
}
return $block_html;
}
}