Completed
Push — master ( aa3e09...85e896 )
by Mikołaj
04:06
created

EditorModel::saveFile()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 2
nop 2
dl 0
loc 10
rs 9.2
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 = THEMES_ROOT.'/front/'.FRONT_THEME.'/';
10
11
    public function getFilesListByPath($path)
12
    {
13
        return array_diff(
14
            scandir($this->root.$path),
15
            array('.', '..')
16
        );
17
    }
18
19
    public function getFileInfo($path)
20
    {
21
        $file = $this->root.$path;
22
23
        if (!file_exists($file)) {
24
            $file = $this->root.'templates/_head.html.php';
25
        }
26
27
        return [
28
            'name' => str_replace($this->root, '', $file),
29
            'content' => file_get_contents($file),
30
            'last-modified' => date("Y-m-d H:i:s", filemtime($file)),
31
            'size' => filesize($file),
32
            'perms' => decoct(fileperms($file) & 0777),
33
        ];
34
    }
35
36
    public function saveFile($path, $data)
37
    {
38
        $file = $this->root.$path;
39
40
        if (!file_exists($file) || !is_file($file) || !is_writable($file)) {
41
            return false;
42
        }
43
44
        return file_put_contents($file, $data, LOCK_EX);
45
    }
46
}
47