1 | <?php |
||
27 | class File { |
||
28 | protected $fileId; |
||
29 | protected $owner; |
||
30 | protected $sharing; |
||
31 | protected $token; |
||
32 | protected $passwordProtected = false; |
||
33 | protected $ownerView; |
||
34 | protected $ownerViewFiles; |
||
35 | protected $path; |
||
36 | protected $pathFiles; |
||
37 | |||
38 | public function __construct($fileId, $shareOps = null, $token = ''){ |
||
39 | if (!$fileId){ |
||
40 | throw new \Exception('No valid file has been passed'); |
||
41 | } |
||
42 | |||
43 | $this->fileId = $fileId; |
||
44 | $this->sharing = $shareOps; |
||
45 | $this->token = $token; |
||
46 | |||
47 | if ($this->isPublicShare()) { |
||
48 | if (isset($this->sharing['uid_owner'])){ |
||
49 | $this->owner = $this->sharing['uid_owner']; |
||
50 | if (!\OC::$server->getUserManager()->userExists($this->sharing['uid_owner'])) { |
||
51 | throw new \Exception('Share owner' . $this->sharing['uid_owner'] . ' does not exist '); |
||
52 | } |
||
53 | |||
54 | \OC_Util::tearDownFS(); |
||
55 | \OC_Util::setupFS($this->sharing['uid_owner']); |
||
56 | } else { |
||
57 | throw new \Exception($this->fileId . ' is a broken share'); |
||
58 | } |
||
59 | } else { |
||
60 | $this->owner = \OC::$server->getUserSession()->getUser()->getUID(); |
||
61 | } |
||
62 | $this->initViews(); |
||
63 | } |
||
64 | |||
65 | |||
66 | public static function getByShareToken($token){ |
||
67 | $linkItem = \OCP\Share::getShareByToken($token, false); |
||
68 | if (is_array($linkItem) && isset($linkItem['uid_owner'])) { |
||
69 | // seems to be a valid share |
||
70 | $rootLinkItem = \OCP\Share::resolveReShare($linkItem); |
||
71 | } else { |
||
72 | throw new \Exception('This file was probably unshared'); |
||
73 | } |
||
74 | |||
75 | $file = new File($rootLinkItem['file_source'], $rootLinkItem, $token); |
||
76 | |||
77 | if (isset($linkItem['share_with']) && !empty($linkItem['share_with'])){ |
||
78 | $file->setPasswordProtected(true); |
||
79 | } |
||
80 | |||
81 | return $file; |
||
82 | } |
||
83 | |||
84 | public function getToken(){ |
||
85 | return $this->token; |
||
86 | } |
||
87 | |||
88 | public function getFileId(){ |
||
89 | return $this->fileId; |
||
90 | } |
||
91 | |||
92 | public function setToken($token){ |
||
93 | $this->token = $token; |
||
94 | } |
||
95 | |||
96 | public function isPublicShare(){ |
||
97 | return !empty($this->token); |
||
98 | } |
||
99 | |||
100 | public function isPasswordProtected(){ |
||
101 | return $this->passwordProtected; |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @param string $password |
||
106 | * @return boolean |
||
107 | */ |
||
108 | public function checkPassword($password){ |
||
143 | |||
144 | /** |
||
145 | * @param boolean $value |
||
146 | */ |
||
147 | public function setPasswordProtected($value){ |
||
150 | |||
151 | public function getOwner(){ |
||
152 | return $this->owner; |
||
153 | } |
||
154 | |||
155 | public function getOwnerView($relativeToFiles = false){ |
||
156 | return $relativeToFiles ? $this->ownerViewFiles : $this->ownerView; |
||
158 | |||
159 | public function getPath($relativeToFiles = false){ |
||
162 | |||
163 | public function getPermissions(){ |
||
167 | |||
168 | protected function initViews(){ |
||
184 | |||
185 | protected function getPassword(){ |
||
188 | } |
||
189 |