This repository has been archived by the owner on Oct 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
SimpleFilemanagerModule.php
68 lines (55 loc) · 1.89 KB
/
SimpleFilemanagerModule.php
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
<?php
namespace DeLuxis\Yii2SimpleFilemanager;
use yii\base\Module;
/**
* Class SimpleFilemanagerModule
* @package DeLuxis\Yii2SimpleFilemanager
* @property string $fullUploadPath
*/
class SimpleFilemanagerModule extends Module
{
public $controllerNamespace = 'DeLuxis\Yii2SimpleFilemanager\controllers';
public $uploadPath = '@webroot/upload';
public $urlPath = '@web/upload';
public $icons = [];
private $_uploadPath;
public $defaultIcons = [
'dir' => 'fa-folder-o',
'file' => 'fa-file-o',
'image/gif' => 'fa-file-image-o',
'image/tiff' => 'fa-file-image-o',
'image/png' => 'fa-file-image-o',
'image/jpeg' => 'fa-file-image-o',
'application/pdf' => 'fa-file-pdf-o',
'application/zip' => 'fa-file-archive-o',
'application/x-gzip' => 'fa-file-archive-o',
'text/plain' => 'fa-file-text-o',
];
public function init()
{
parent::init();
$this->_checkPath();
$this->icons = array_merge($this->defaultIcons, $this->icons);
if ( ! isset(\Yii::$app->i18n->translations['filemanager'])) {
\Yii::$app->i18n->translations['filemanager'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en-US',
'basePath' => $this->basePath . '/messages',
'fileMap' => ['filemanager' => 'filemanager.php'],
];
}
}
public function getFullUploadPath()
{
if ( ! isset($this->_uploadPath)) {
$this->_uploadPath = \Yii::getAlias($this->uploadPath);
}
return $this->_uploadPath;
}
private function _checkPath()
{
if ( ! is_dir($this->fullUploadPath)) {
mkdir($this->fullUploadPath, 0755, true);
}
}
}