blob: 06885b3c7021d1fa76dc32b124449ec77fe1bdfa (
plain)
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
|
<?php
namespace Wcms;
use Exception;
class Controllermedia extends Controller
{
/**
* @var Modelmedia
*/
protected $mediamanager;
public function __construct($render)
{
parent::__construct($render);
$this->mediamanager = new Modelmedia();
}
public function desktop()
{
if ($this->user->iseditor()) {
if (!$this->mediamanager->dircheck(Model::MEDIA_DIR)) {
throw new Exception("Media error : Cant create /media folder");
}
if (!$this->mediamanager->dircheck(Model::FAVICON_DIR)) {
throw new Exception("Media error : Cant create /media/favicon folder");
}
if (!$this->mediamanager->dircheck(Model::THUMBNAIL_DIR)) {
throw new Exception("Media error : Cant create /media/thumbnail folder");
}
$mediaopt = new Medialist($_GET);
if (empty($mediaopt->path())) {
$mediaopt->setpath(DIRECTORY_SEPARATOR . Model::MEDIA_DIR);
}
if (is_dir($mediaopt->dir())) {
$medialist = $this->mediamanager->medialistopt($mediaopt);
$dirlist = $this->mediamanager->listdir(Model::MEDIA_DIR);
$pathlist = [];
$this->mediamanager->listpath($dirlist, '', $pathlist);
$this->showtemplate(
'media',
[
'medialist' => $medialist,
'dirlist' => $dirlist,
'pathlist' => $pathlist,
'mediaopt' => $mediaopt
]
);
} else {
$this->routedirect('media');
}
} else {
$this->routedirect('home');
}
}
public function upload()
{
if ($this->user->iseditor()) {
$target = $_POST['dir'] ?? Model::MEDIA_DIR;
if (!empty($_FILES['file']['name'][0])) {
$this->mediamanager->multiupload('file', $target);
}
$this->redirect($this->generate('media') . '?path=/' . $target);
} else {
$this->routedirect('home');
}
}
public function folderadd()
{
if ($this->user->iseditor()) {
$dir = $_POST['dir'] ?? Model::MEDIA_DIR;
$name = idclean($_POST['foldername']) ?? 'new-folder';
$this->mediamanager->adddir($dir, $name);
}
$this->redirect($this->generate('media') . '?path=/' . $dir . DIRECTORY_SEPARATOR . $name);
}
public function folderdelete()
{
if (isset($_POST['dir'])) {
if (isset($_POST['deletefolder']) && intval($_POST['deletefolder']) && $this->user->issupereditor()) {
$this->mediamanager->deletedir($_POST['dir']);
} else {
$this->redirect($this->generate('media') . '?path=/' . $_POST['dir']);
exit;
}
}
$this->redirect($this->generate('media'));
}
public function edit()
{
if ($this->user->issupereditor() && isset($_POST['action']) && isset($_POST['id'])) {
if ($_POST['action'] == 'delete') {
if ($this->mediamanager->multifiledelete($_POST['id'])) {
Model::sendflashmessage('Files deletion successfull', 'success');
} else {
Model::sendflashmessage('Error while deleting files', 'error');
}
} elseif ($_POST['action'] == 'move' && isset($_POST['dir'])) {
$this->mediamanager->multimovefile($_POST['id'], $_POST['dir']);
}
}
$this->redirect($this->generate('media') . '?path=/' . $_POST['path']);
}
}
|