blob: 8423d1857d6807c008c83055ff2a7553a7e602f8 (
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
|
<?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->router->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->router->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->router->generate('media') . '?path=/' . $_POST['dir']);
exit;
}
}
$this->redirect($this->router->generate('media'));
}
public function edit()
{
if($this->user->issupereditor() && isset($_POST['action']) && isset($_POST['id'])) {
if($_POST['action'] == 'delete') {
$this->mediamanager->multifiledelete($_POST['id']);
} elseif ($_POST['action'] == 'move' && isset($_POST['dir'])) {
$this->mediamanager->multimovefile($_POST['id'], $_POST['dir']);
}
}
$this->redirect($this->router->generate('media') . '?path=' . $_POST['path']);
}
}
?>
|