-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathRedactorModule.php
75 lines (66 loc) · 2.04 KB
/
RedactorModule.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
69
70
71
72
73
74
75
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\redactor;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\FileHelper;
use yii\helpers\Url;
/**
* @author Nghia Nguyen <[email protected]>
* @since 2.0
*/
class RedactorModule extends \yii\base\Module
{
public $controllerNamespace = 'yii\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) . DIRECTORY_SEPARATOR . $this->getOwnerPath();
if(!file_exists($path)){
if (!FileHelper::createDirectory($path, 0775,$recursive = true )) {
throw new InvalidConfigException('$uploadDir does not exist and default path creation failed');
}
}
return $path;
}
/**
* @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);
}
}