Blame view

vendor/mihaildev/yii2-elfinder/PathController.php 2.01 KB
ad2e91f7   Mihail   move multyparser ...
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  <?php
  /**
   * Date: 28.11.2014
   * Time: 14:21
   *
   * This file is part of the MihailDev project.
   *
   * (c) MihailDev project <http://github.com/mihaildev/>
   *
   * For the full copyright and license information, please view the LICENSE
   * file that was distributed with this source code.
  */
  
  namespace mihaildev\elfinder;
  use yii\helpers\ArrayHelper;
  use yii\helpers\Url;
  use Yii;
  
  /**
   * Class PathController
   *
   * @package mihaildev\elfinder
   */
  class PathController extends BaseController{
  	public $disabledCommands = ['netmount'];
  	public $root = [
  		'baseUrl' => '@web/files',
  		'basePath' => '@webroot/files',
  		'path' => ''
  	];
  	public $watermark;
  
  
  
  	private $_options;
  
  	public function getOptions()
  	{
  		if($this->_options !== null)
  			return $this->_options;
  
  		$subPath = Yii::$app->request->getQueryParam('path', '');
  
  		$this->_options['roots'] = [];
  
  		$root = $this->root;
  
  		if(is_string($root))
  			$root = ['path' => $root];
  
  		if(!isset($root['class']))
  			$root['class'] = 'mihaildev\elfinder\LocalPath';
  
  		if(!empty($subPath)){
  			if(preg_match("/\./i", $subPath)){
  				$root['path'] = rtrim($root['path'], '/');
  			}
  			else{
  				$root['path'] = rtrim($root['path'], '/');
  				$root['path'] .= '/' . trim($subPath, '/');
  			}
  		}
  
  
  		$root = Yii::createObject($root);
  
  		/** @var \mihaildev\elfinder\LocalPath $root*/
  
  		if($root->isAvailable())
  			$this->_options['roots'][] = $root->getRoot();
  
  		if(!empty($this->watermark)){
  			$this->_options['bind']['upload.presave'] = 'Plugin.Watermark.onUpLoadPreSave';
  
  			if(is_string($this->watermark)){
  				$watermark = [
  					'source' => $this->watermark
  				];
  			}else{
  				$watermark = $this->watermark;
  			}
  
  			$this->_options['plugin']['Watermark'] = $watermark;
  		}
  
  		$this->_options = ArrayHelper::merge($this->_options, $this->connectOptions);
  
  		return $this->_options;
  	}
  
  	public function getManagerOptions(){
  		$options = parent::getManagerOptions();
  		$options['url'] = Url::toRoute(['connect', 'path' => Yii::$app->request->getQueryParam('path', '')]);
  		return $options;
  	}
  }