blob: 4200253c24d24dca0cb73e0770ed653b8a365e4f (
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
|
<?php
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->basedircheck()) {
throw new Exception("Media error : Cant create /media folder");
}
if (!$this->mediamanager->favicondircheck()) {
throw new Exception("Media error : Cant create /media/favicon folder");
}
if (!$this->mediamanager->thumbnaildircheck()) {
throw new Exception("Media error : Cant create /media/thumbnail folder");
}
$dir = rtrim($_GET['path'] ?? Model::MEDIA_DIR, DIRECTORY_SEPARATOR);
$sortby = isset($_GET['sortby']) ? $_GET['sortby'] : 'id';
$order = isset($_GET['order']) ? $_GET['order'] : '1';
$opt = ['dir' => $dir, 'sortby' => $sortby, 'order' => $order];
if(is_dir($dir)) {
$medialist = $this->mediamanager->getlistermedia($dir . DIRECTORY_SEPARATOR);
$faviconlist = $this->mediamanager->getlistermedia(Model::FAVICON_DIR);
$dirlist = $this->mediamanager->listdir(Model::MEDIA_DIR);
$this->mediamanager->medialistsort($medialist, $sortby, $order);
$this->showtemplate('media', ['medialist' => $medialist, 'faviconlist' => $faviconlist, 'dirlist' => $dirlist, 'dir' => $dir, 'opt' => $opt]);
} 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 folder()
{
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);
}
}
?>
|