1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* balloon |
7
|
|
|
* |
8
|
|
|
* @copyright Copryright (c) 2012-2019 gyselroth GmbH (https://gyselroth.com) |
9
|
|
|
* @license GPL-3.0 https://opensource.org/licenses/GPL-3.0 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Balloon\App\Wopi\Session; |
13
|
|
|
|
14
|
|
|
use Balloon\Filesystem\Node\AbstractNode; |
15
|
|
|
use Balloon\Filesystem\Node\File; |
16
|
|
|
use Balloon\Server\User; |
17
|
|
|
|
18
|
|
|
class Session implements SessionInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Session. |
22
|
|
|
* |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
protected $session = []; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* File. |
29
|
|
|
* |
30
|
|
|
* @var File |
31
|
|
|
*/ |
32
|
|
|
protected $file; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* User. |
36
|
|
|
* |
37
|
|
|
* @var User |
38
|
|
|
*/ |
39
|
|
|
protected $user; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Session. |
43
|
|
|
*/ |
44
|
|
|
public function __construct(File $file, User $user, array $session) |
45
|
|
|
{ |
46
|
|
|
$this->file = $file; |
47
|
|
|
$this->user = $user; |
48
|
|
|
$this->session = $session; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function getUser(): User |
55
|
|
|
{ |
56
|
|
|
return $this->user; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function getFile(): File |
63
|
|
|
{ |
64
|
|
|
return $this->file; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function getAccessTokenTTl(): int |
71
|
|
|
{ |
72
|
|
|
return $this->session['ttl']->toDateTime()->format('U') * 1000; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function getAccessToken(): string |
79
|
|
|
{ |
80
|
|
|
return $this->session['token']; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get wopi url. |
85
|
|
|
*/ |
86
|
|
|
public function getWopiUrl(): string |
87
|
|
|
{ |
88
|
|
|
return $this->session['client'].'/api/v2/office/wopi/files/'.$this->file->getId().'?access_token='.$this->getAccessToken().'&access_token_ttl='.$this->getAccessTokenTTl(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function getAttributes(): array |
95
|
|
|
{ |
96
|
|
|
$attrs = $this->file->getAttributes(['name', 'version']); |
|
|
|
|
97
|
|
|
$attributes = [ |
98
|
|
|
'AllowExternalMarketplace' => false, |
99
|
|
|
'BaseFileName' => $this->file->getName(), |
|
|
|
|
100
|
|
|
'DisablePrint' => false, |
101
|
|
|
'DisableTranslation' => false, |
102
|
|
|
//'DownloadUrl' => null, |
103
|
|
|
//'FileSharingUrl' => null, |
104
|
|
|
//'FileUrl' => null, |
105
|
|
|
'FileVersionPostMessage' => true, |
106
|
|
|
// 'FileSharingPostMessage' => null, |
107
|
|
|
'PostMessageOrigin' => $this->session['client'], |
108
|
|
|
'OwnerId' => (string) $this->file->getOwner(), |
109
|
|
|
'ReadOnly' => $this->file->isReadonly(), |
110
|
|
|
'RestrictedWebViewOnly' => false, |
111
|
|
|
//'SHA256' => null, |
112
|
|
|
//'SignoutUrl' => null, |
113
|
|
|
'Size' => $this->file->getSize(), |
114
|
|
|
'SupportsCobalt' => false, |
115
|
|
|
'SupportsFolders' => true, |
116
|
|
|
'SupportsLocks' => true, |
117
|
|
|
'SupportsGetLock' => true, |
118
|
|
|
'SupportsExtendedLockLength' => true, |
119
|
|
|
'SupportsUserInfo' => false, |
120
|
|
|
'SupportsDeleteFile' => true, |
121
|
|
|
'SupportsUpdate' => true, |
122
|
|
|
'SupportsRename' => true, |
123
|
|
|
'FileNameMaxLength' => AbstractNode::MAX_NAME_LENGTH, |
124
|
|
|
'UserCanAttend' => false, |
125
|
|
|
'UserCanNotWriteRelative' => false, |
126
|
|
|
'UserCanPresent' => false, |
127
|
|
|
'UserCanRename' => true, |
128
|
|
|
'UserCanWrite' => $this->file->mayWrite(), |
129
|
|
|
'UserFriendlyName' => $this->user->getUsername(), |
130
|
|
|
'UserId' => (string) $this->user->getId(), |
131
|
|
|
'Version' => (string) $this->file->getVersion(), |
132
|
|
|
]; |
133
|
|
|
|
134
|
|
|
return $attributes; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.