|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @link https://github.com/rkit/filemanager-yii2 |
|
5
|
|
|
* @copyright Copyright (c) 2015 Igor Romanov |
|
6
|
|
|
* @license [MIT](http://opensource.org/licenses/MIT) |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace rkit\filemanager; |
|
10
|
|
|
|
|
11
|
|
|
use Yii; |
|
12
|
|
|
use yii\base\Component; |
|
13
|
|
|
use yii\base\InvalidParamException; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Component of FileManager |
|
17
|
|
|
* |
|
18
|
|
|
* @author Igor Romanov <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
class FileManager extends Component |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var string Directory to upload files protected, not accessible from the web |
|
24
|
|
|
*/ |
|
25
|
|
|
public $uploadDirProtected = '@runtime'; |
|
26
|
|
|
/** |
|
27
|
|
|
* @var string Directory to upload files, accessible from the web |
|
28
|
|
|
*/ |
|
29
|
|
|
public $uploadDirUnprotected = '@app/web'; |
|
30
|
|
|
/** |
|
31
|
|
|
* @var string Public path to files |
|
32
|
|
|
*/ |
|
33
|
|
|
public $publicPath = 'uploads'; |
|
34
|
|
|
/** |
|
35
|
|
|
* @var array Type of owner in format: title:string => type:int |
|
36
|
|
|
*/ |
|
37
|
|
|
public $ownerTypes = []; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @internal |
|
41
|
|
|
*/ |
|
42
|
1 |
|
public function init() |
|
43
|
|
|
{ |
|
44
|
1 |
|
parent::init(); |
|
45
|
|
|
|
|
46
|
1 |
|
$this->registerTranslations(); |
|
47
|
1 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get owner type |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $ownerType The type of the owner |
|
53
|
|
|
* @return void |
|
54
|
|
|
* @throws InvalidParamException |
|
55
|
|
|
*/ |
|
56
|
34 |
|
public function getOwnerType($ownerType) |
|
57
|
|
|
{ |
|
58
|
34 |
|
if (!isset($this->ownerTypes[$ownerType])) { |
|
59
|
1 |
|
throw new InvalidParamException('This type `' . $ownerType . '` is not found'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
33 |
|
return $this->ownerTypes[$ownerType]; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Registers translator |
|
67
|
|
|
* @internal |
|
68
|
|
|
* |
|
69
|
|
|
* @return void |
|
70
|
|
|
*/ |
|
71
|
44 |
|
public function registerTranslations() |
|
72
|
|
|
{ |
|
73
|
44 |
|
if (!isset(\Yii::$app->i18n->translations['filemanager-yii2'])) { |
|
74
|
1 |
|
\Yii::$app->i18n->translations['filemanager-yii2'] = [ |
|
75
|
1 |
|
'class' => 'yii\i18n\PhpMessageSource', |
|
76
|
1 |
|
'basePath' => '@vendor/rkit/filemanager-yii2/src/messages', |
|
77
|
1 |
|
'sourceLanguage' => 'en', |
|
78
|
|
|
]; |
|
79
|
1 |
|
} |
|
80
|
44 |
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|