aboutsummaryrefslogtreecommitdiff
path: root/app/class/controllermedia.php
blob: 4421f657793872c87324634d7f0fcb35f0b668cd (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
<?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("Error : Cant create /media folder");
            }
            if (!$this->mediamanager->favicondircheck()) {
                throw new Exception("Error : Cant create /media/favicon folder");
            }


            $dir = rtrim($_GET['path'] ?? Model::MEDIA_DIR, DIRECTORY_SEPARATOR);

            $medialist = $this->mediamanager->getlistermedia($dir . DIRECTORY_SEPARATOR);
            $faviconlist = $this->mediamanager->getlistermedia(Model::FAVICON_DIR);

            $dirlist = $this->mediamanager->listdir(Model::MEDIA_DIR);

            $this->showtemplate('media', ['medialist' => $medialist, 'faviconlist' => $faviconlist, 'dirlist' => $dirlist, 'dir' => $dir]);
        } 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->upload($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 = $_POST['foldername'] ?? 'new folder';
            $this->mediamanager->adddir($dir, $name);
        }
        $this->redirect($this->router->generate('media') . '?path=' . $dir . DIRECTORY_SEPARATOR . $name);

    }


}


?>