1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package sitemaker |
5
|
|
|
* @copyright (c) 2017 Daniel A. (blitze) |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace blitze\sitemaker\services\filemanager; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @package sitemaker |
14
|
|
|
*/ |
15
|
|
|
class setup |
16
|
|
|
{ |
17
|
|
|
/** @var \phpbb\auth\auth */ |
18
|
|
|
protected $auth; |
19
|
|
|
|
20
|
|
|
/** @var \phpbb\config\config */ |
21
|
|
|
protected $config; |
22
|
|
|
|
23
|
|
|
/** @var \phpbb\filesystem\filesystem */ |
24
|
|
|
protected $filesystem; |
25
|
|
|
|
26
|
|
|
/** @var \phpbb\user */ |
27
|
|
|
protected $user; |
28
|
|
|
|
29
|
|
|
/** @var string */ |
30
|
|
|
protected $config_path; |
31
|
|
|
|
32
|
|
|
/** @var string */ |
33
|
|
|
protected $phpbb_root_path; |
34
|
|
|
|
35
|
|
|
/** @var string */ |
36
|
|
|
protected $user_dir = false; |
37
|
|
|
|
38
|
|
|
/** @var string */ |
39
|
|
|
protected $thumbs_dir = 'images/sitemaker_uploads/thumbs/'; |
40
|
|
|
|
41
|
|
|
/** @var string */ |
42
|
|
|
protected $upload_dir = 'images/sitemaker_uploads/source/'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Constructor |
46
|
|
|
* |
47
|
|
|
* @param \phpbb\auth\auth $auth Auth object |
48
|
|
|
* @param \phpbb\config\config $config Config object |
49
|
|
|
* @param \phpbb\filesystem\filesystem $filesystem File system |
50
|
|
|
* @param \phpbb\user $user User object |
51
|
|
|
* @param string $config_path path to filemanager config file |
52
|
|
|
* @param string $phpbb_root_path phpBB root path |
53
|
|
|
*/ |
54
|
17 |
|
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\filesystem\filesystem $filesystem, \phpbb\user $user, $config_path, $phpbb_root_path) |
55
|
|
|
{ |
56
|
17 |
|
$this->auth = $auth; |
57
|
17 |
|
$this->config = $config; |
58
|
17 |
|
$this->filesystem = $filesystem; |
59
|
17 |
|
$this->user = $user; |
60
|
17 |
|
$this->config_path = $config_path; |
61
|
17 |
|
$this->phpbb_root_path = $phpbb_root_path; |
62
|
17 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return bool |
66
|
|
|
*/ |
67
|
4 |
|
public function is_enabled() |
68
|
|
|
{ |
69
|
4 |
|
return is_dir($this->config_path) && $this->config['sm_filemanager'] && $this->auth->acl_get('u_sm_filemanager'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
4 |
|
public function get_access_key() |
76
|
|
|
{ |
77
|
4 |
|
return sha1($this->user->data['user_form_salt'] . 'filemanager'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public function get_upload_dir() |
84
|
|
|
{ |
85
|
|
|
return $this->upload_dir; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function get_thumbs_dir() |
92
|
|
|
{ |
93
|
|
|
return $this->thumbs_dir; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
4 |
|
public function get_upload_destination() |
100
|
|
|
{ |
101
|
4 |
|
return $this->upload_dir . $this->get_user_dir(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
4 |
|
public function get_user_dir() |
108
|
|
|
{ |
109
|
4 |
|
if ($this->user_dir === false) |
110
|
4 |
|
{ |
111
|
4 |
|
$this->set_user_dir(); |
112
|
4 |
|
} |
113
|
|
|
|
114
|
4 |
|
return $this->user_dir; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
4 |
|
protected function set_user_dir() |
121
|
|
|
{ |
122
|
|
|
// if user does not have root access, they must have a directory |
123
|
4 |
|
$this->user_dir = (!$this->auth->acl_get('a_sm_filemanager')) ? 'users/' . $this->user->data['username'] . '/' : ''; |
124
|
|
|
|
125
|
4 |
|
$destination = $this->phpbb_root_path . $this->upload_dir . $this->user_dir; |
126
|
|
|
|
127
|
4 |
|
if (!is_dir($destination)) |
128
|
4 |
|
{ |
129
|
1 |
|
$this->filesystem->mkdir($destination, 0755); |
130
|
1 |
|
} |
131
|
4 |
|
} |
132
|
|
|
} |
133
|
|
|
|