blob: c6e5d6c9653865ef77afc065bf8744cc03ec248d (
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
117
118
119
120
121
|
<?php
namespace Wcms;
use Exception;
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);
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') . '?path=/' . $_POST['path']);
}
}
|