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
|
<?php
namespace Wcms;
use Exception;
use InvalidArgumentException;
use LogicException;
class Controllermedia extends Controller
{
/**
* @var Modelmedia
*/
protected $mediamanager;
public function __construct($render)
{
parent::__construct($render);
$this->mediamanager = new Modelmedia();
}
/**
* @throws Exception
*/
public function desktop()
{
if ($this->user->iseditor()) {
try {
dircheck(Model::FONT_DIR);
dircheck(Model::THUMBNAIL_DIR);
dircheck(Model::FAVICON_DIR);
dircheck(Model::CSS_DIR);
} catch (\InvalidArgumentException $exception) {
throw new LogicException($exception->getMessage());
}
$mediaopt = new Mediaopt($_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);
$vars['maxuploadsize'] = readablesize(file_upload_max_size()) . 'o';
if (isset($_GET['display'])) {
$this->session->addtosession('mediadisplay', $_GET['display']);
}
$vars['display'] = $this->session->mediadisplay;
$vars['medialist'] = $medialist;
$vars['dirlist'] = $dirlist;
$vars['pathlist'] = $pathlist;
$vars['mediaopt'] = $mediaopt;
$this->showtemplate('media', $vars);
} 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);
}
$this->routedirect('home');
}
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') . $_POST['route']);
}
public function rename()
{
if (
$this->user->issupereditor()
&& isset($_POST['oldid'])
&& isset($_POST['newid'])
&& isset($_POST['oldextension'])
&& isset($_POST['newextension'])
&& isset($_POST['path'])
) {
$newid = idclean($_POST['newid']);
$newextension = idclean($_POST['newextension']);
if (!empty($newid) && !empty($newextension)) {
$oldname = $_POST['path'] . $_POST['oldid'] . '.' . $_POST['oldextension'];
$newname = $_POST['path'] . $newid . '.' . $newextension;
try {
$this->mediamanager->rename($oldname, $newname);
} catch (InvalidArgumentException $e) {
Model::sendflashmessage($e->getMessage(), 'error');
}
} else {
Model::sendflashmessage('Invalid name or extension', 'warning');
}
}
$this->redirect($this->generate('media') . $_POST['route']);
}
}
|