Completed
Push — master ( 18f460...9e5c66 )
by Mikołaj
02:35
created

EditorModel::getFilesListByPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Rudolf\Modules\Appearance\One\Admin;
4
5
use Rudolf\Framework\Model\AdminModel;
6
7
class EditorModel extends AdminModel
8
{
9
    private $root;
10
11
    public function __construct()
12
    {
13
        parent::__construct();
14
15
        $this->root = THEMES_ROOT.'/front/'.FRONT_THEME.'/';
16
    }
17
18
    public function getFilesListByPath($path)
19
    {
20
        return array_diff(
21
            scandir($this->root.$path),
22
            array('.', '..')
23
        );
24
    }
25
26
    public function getFileInfo($path)
27
    {
28
        $file = $this->root.$path;
29
30
        if (!file_exists($file)) {
31
            $file = $this->root.'templates/_head.html.php';
32
        }
33
34
        return [
35
            'name' => str_replace($this->root, '', $file),
36
            'content' => file_get_contents($file),
37
            'last-modified' => date("Y-m-d H:i:s", filemtime($file)),
38
            'size' => filesize($file),
39
            'perms' => decoct(fileperms($file) & 0777),
40
        ];
41
    }
42
43
    public function saveFile($path, $data)
44
    {
45
        $file = $this->root.$path;
46
47
        if (!file_exists($file) || !is_file($file) || !is_writable($file)) {
48
            return false;
49
        }
50
51
        return file_put_contents($file, $data, LOCK_EX);
52
    }
53
}
54