-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedactorModule.php
More file actions
72 lines (63 loc) · 1.9 KB
/
RedactorModule.php
File metadata and controls
72 lines (63 loc) · 1.9 KB
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
72
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace vsdesk\redactor;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\FileHelper;
use yii\helpers\Url;
/**
* @author asivanow <ivanov@vsdesk.ru>
* @since 1.0
*/
class RedactorModule extends \yii\base\Module
{
public $controllerNamespace = 'vsdesk\redactor\controllers';
public $defaultRoute = 'upload';
public $uploadDir = '@webroot/uploads';
public $uploadUrl = '@web/uploads';
public $imageUploadRoute = ['/redactor/upload/image'];
public $fileUploadRoute = ['/redactor/upload/file'];
public $imageManagerJsonRoute = ['/redactor/upload/image-json'];
public $fileManagerJsonRoute = ['/redactor/upload/file-json'];
public $imageAllowExtensions = ['jpg', 'png', 'gif', 'bmp', 'svg'];
public $fileAllowExtensions = null;
public $widgetOptions=[];
public $widgetClientOptions=[];
public function getOwnerPath()
{
return Yii::$app->user->isGuest ? 'guest' : Yii::$app->user->id;
}
/**
* @return string
* @throws InvalidConfigException
* @throws \yii\base\Exception
*/
public function getSaveDir()
{
$path = Yii::getAlias($this->uploadDir);
if (FileHelper::createDirectory($path . DIRECTORY_SEPARATOR . $this->getOwnerPath(), 0777)) {
return $path . DIRECTORY_SEPARATOR . $this->getOwnerPath();
}
}
/**
* @param $fileName
* @return string
* @throws InvalidConfigException
*/
public function getFilePath($fileName)
{
return $this->getSaveDir() . DIRECTORY_SEPARATOR . $fileName;
}
/**
* @param $fileName
* @return string
*/
public function getUrl($fileName)
{
return Url::to($this->uploadUrl . '/' . $this->getOwnerPath() . '/' . $fileName);
}
}