1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\Modules\DropboxFilestorage; |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | class Module extends \Aurora\System\Module\AbstractModule |
22: | { |
23: | protected static $sStorageType = 'dropbox'; |
24: | protected static $iStorageOrder = 100; |
25: | protected $oClient = null; |
26: | protected $aRequireModules = array( |
27: | 'OAuthIntegratorWebclient', |
28: | 'DropboxAuthWebclient' |
29: | ); |
30: | |
31: | |
32: | |
33: | |
34: | public static function getInstance() |
35: | { |
36: | return parent::getInstance(); |
37: | } |
38: | |
39: | |
40: | |
41: | |
42: | public static function Decorator() |
43: | { |
44: | return parent::Decorator(); |
45: | } |
46: | |
47: | |
48: | |
49: | |
50: | public function getModuleSettings() |
51: | { |
52: | return $this->oModuleSettings; |
53: | } |
54: | |
55: | protected function issetScope($sScope) |
56: | { |
57: | return in_array($sScope, explode(' ', $this->oModuleSettings->Scopes)); |
58: | } |
59: | |
60: | |
61: | |
62: | |
63: | |
64: | |
65: | |
66: | public function init() |
67: | { |
68: | $this->subscribeEvent('Files::GetStorages::after', array($this, 'onAfterGetStorages')); |
69: | $this->subscribeEvent('Files::GetFile', array($this, 'onGetFile')); |
70: | $this->subscribeEvent('Files::GetItems', array($this, 'onGetItems')); |
71: | $this->subscribeEvent('Files::CreateFolder::after', array($this, 'onAfterCreateFolder')); |
72: | $this->subscribeEvent('Files::CreateFile', array($this, 'onCreateFile')); |
73: | $this->subscribeEvent('Files::Delete::after', array($this, 'onAfterDelete')); |
74: | $this->subscribeEvent('Files::Rename::after', array($this, 'onAfterRename')); |
75: | $this->subscribeEvent('Files::Move::after', array($this, 'onAfterMove')); |
76: | $this->subscribeEvent('Files::Copy::after', array($this, 'onAfterCopy')); |
77: | $this->subscribeEvent('Files::GetFileInfo::after', array($this, 'onAfterGetFileInfo')); |
78: | $this->subscribeEvent('Files::PopulateFileItem::after', array($this, 'onAfterPopulateFileItem')); |
79: | |
80: | $this->subscribeEvent('Dropbox::GetSettings', array($this, 'onGetSettings')); |
81: | $this->subscribeEvent('Dropbox::UpdateSettings::after', array($this, 'onAfterUpdateSettings')); |
82: | |
83: | $this->subscribeEvent('Files::GetItems::before', array($this, 'onCheckUrlFile')); |
84: | $this->subscribeEvent('Files::UploadFile::before', array($this, 'onCheckUrlFile')); |
85: | $this->subscribeEvent('Files::CreateFolder::before', array($this, 'onCheckUrlFile')); |
86: | $this->subscribeEvent('Files::CheckQuota::after', array($this, 'onAfterCheckQuota')); |
87: | } |
88: | |
89: | |
90: | |
91: | |
92: | |
93: | |
94: | protected function getClient() |
95: | { |
96: | $oDropboxModule = \Aurora\Modules\Dropbox\Module::getInstance(); |
97: | if ($oDropboxModule) { |
98: | if (!$oDropboxModule->oModuleSettings->EnableModule || !$this->issetScope('storage')) { |
99: | return false; |
100: | } |
101: | } else { |
102: | return false; |
103: | } |
104: | |
105: | if ($this->oClient === null) { |
106: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
107: | |
108: | $oOAuthIntegratorWebclientModule = \Aurora\Modules\OAuthIntegratorWebclient\Module::Decorator(); |
109: | $oOAuthAccount = $oOAuthIntegratorWebclientModule->GetAccount(self::$sStorageType); |
110: | |
111: | $oTokenData = \json_decode($oOAuthAccount->AccessToken); |
112: | if ($oTokenData && $oOAuthAccount) { |
113: | $accessToken = $oTokenData->access_token; |
114: | $iCreated = (int) $oTokenData->created; |
115: | $iExpiresIn = (int) $oTokenData->expires_in; |
116: | $now = new \DateTime(); |
117: | $now->setTimezone(new \DateTimeZone('GMT')); |
118: | |
119: | if ($now->getTimestamp() > ($iCreated + $iExpiresIn) && isset($oOAuthAccount->RefreshToken)) { |
120: | $oConnector = new \Aurora\Modules\DropboxAuthWebclient\Classes\Connector($this); |
121: | $aResult = $oConnector->RefreshAccessToken( |
122: | $oDropboxModule->oModuleSettings->Id, |
123: | $oDropboxModule->oModuleSettings->Secret, |
124: | $oOAuthAccount->RefreshToken |
125: | ); |
126: | if (isset($aResult['access_token'])) { |
127: | $oTokenData->access_token = $aResult['access_token']; |
128: | $oTokenData->created = $now->getTimestamp(); |
129: | $oTokenData->expires_in = $aResult['expires_in']; |
130: | |
131: | $oOAuthAccount->AccessToken = \json_encode($oTokenData); |
132: | $oOAuthAccount->save(); |
133: | |
134: | $accessToken = $oTokenData->access_token; |
135: | } |
136: | } |
137: | |
138: | $oDropboxApp = new \Kunnu\Dropbox\DropboxApp( |
139: | $oDropboxModule->oModuleSettings->Id, |
140: | $oDropboxModule->oModuleSettings->Secret, |
141: | $accessToken |
142: | ); |
143: | $this->oClient = new \Kunnu\Dropbox\Dropbox($oDropboxApp); |
144: | } |
145: | } |
146: | |
147: | return $this->oClient; |
148: | } |
149: | |
150: | |
151: | |
152: | |
153: | |
154: | |
155: | |
156: | |
157: | public function onAfterGetStorages($aArgs, &$mResult) |
158: | { |
159: | if ($this->CheckDropboxAccess()) { |
160: | $mResult[] = [ |
161: | 'Type' => self::$sStorageType, |
162: | 'IsExternal' => true, |
163: | 'DisplayName' => 'Dropbox', |
164: | 'Order' => self::$iStorageOrder, |
165: | 'IsDroppable' => true |
166: | ]; |
167: | } |
168: | } |
169: | |
170: | |
171: | |
172: | |
173: | |
174: | |
175: | |
176: | protected function getDirName($sPath) |
177: | { |
178: | $sPath = dirname($sPath); |
179: | return str_replace(DIRECTORY_SEPARATOR, '/', $sPath); |
180: | } |
181: | |
182: | |
183: | |
184: | |
185: | |
186: | |
187: | |
188: | protected function getBaseName($sPath) |
189: | { |
190: | $aPath = explode('/', $sPath); |
191: | return end($aPath); |
192: | } |
193: | |
194: | |
195: | |
196: | |
197: | |
198: | |
199: | protected function getItemHash($oItem) |
200: | { |
201: | return \Aurora\System\Api::EncodeKeyValues(array( |
202: | 'UserId' => \Aurora\System\Api::getAuthenticatedUserId(), |
203: | 'Type' => $oItem->TypeStr, |
204: | 'Path' => '', |
205: | 'Name' => $oItem->FullPath, |
206: | 'FileName' => $oItem->Name |
207: | )); |
208: | } |
209: | |
210: | protected function hasThumb($sName) |
211: | { |
212: | return in_array( |
213: | pathinfo($sName, PATHINFO_EXTENSION), |
214: | ['jpg', 'jpeg', 'png', 'tiff', 'tif', 'gif', 'bmp'] |
215: | ); |
216: | } |
217: | |
218: | |
219: | |
220: | |
221: | |
222: | |
223: | |
224: | protected function populateFileInfo($aData) |
225: | { |
226: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
227: | |
228: | $mResult = false; |
229: | if ($aData) { |
230: | $sPath = ltrim($this->getDirName($aData->getPathDisplay()), '/'); |
231: | |
232: | $mResult = new \Aurora\Modules\Files\Classes\FileItem(); |
233: | $mResult->IsExternal = true; |
234: | $mResult->TypeStr = self::$sStorageType; |
235: | $mResult->IsFolder = ($aData instanceof \Kunnu\Dropbox\Models\FolderMetadata); |
236: | $mResult->Id = $aData->getName(); |
237: | $mResult->Name = $mResult->Id; |
238: | $mResult->Path = !empty($sPath) ? '/' . $sPath : $sPath; |
239: | $mResult->Size = !$mResult->IsFolder ? $aData->getSize() : 0; |
240: | |
241: | if (!$mResult->IsFolder) { |
242: | $mResult->LastModified = date("U", strtotime($aData->getServerModified())); |
243: | } |
244: | |
245: | $mResult->FullPath = $mResult->Name !== '' ? $mResult->Path . '/' . $mResult->Name : $mResult->Path ; |
246: | $mResult->ContentType = \Aurora\System\Utils::MimeContentType($mResult->Name); |
247: | |
248: | $mResult->Thumb = $this->hasThumb($mResult->Name); |
249: | |
250: | if ($mResult->IsFolder) { |
251: | $mResult->AddAction([ |
252: | 'list' => [] |
253: | ]); |
254: | } else { |
255: | $mResult->AddAction([ |
256: | 'view' => [ |
257: | 'url' => '?download-file/' . $this->getItemHash($mResult) . '/view' |
258: | ] |
259: | ]); |
260: | $mResult->AddAction([ |
261: | 'download' => [ |
262: | 'url' => '?download-file/' . $this->getItemHash($mResult) |
263: | ] |
264: | ]); |
265: | } |
266: | } |
267: | return $mResult; |
268: | } |
269: | |
270: | |
271: | |
272: | |
273: | |
274: | |
275: | |
276: | |
277: | |
278: | |
279: | public function onGetFile($aArgs, &$mResult) |
280: | { |
281: | if ($aArgs['Type'] === self::$sStorageType) { |
282: | $oClient = $this->getClient(); |
283: | if ($oClient) { |
284: | $sFullPath = $aArgs['Path'] . '/' . ltrim($aArgs['Name'], '/'); |
285: | |
286: | if (isset($aArgs['IsThumb']) && (bool)$aArgs['IsThumb'] === true) { |
287: | $oThumbnail = $oClient->getThumbnail($sFullPath, 'medium', 'png'); |
288: | if ($oThumbnail) { |
289: | $mResult = \fopen('php://memory', 'r+'); |
290: | \fwrite($mResult, $oThumbnail->getContents()); |
291: | \rewind($mResult); |
292: | } |
293: | } else { |
294: | $mDownloadResult = $oClient->download($sFullPath); |
295: | if ($mDownloadResult) { |
296: | $mResult = \fopen('php://memory', 'r+'); |
297: | \fwrite($mResult, $mDownloadResult->getContents()); |
298: | \rewind($mResult); |
299: | } |
300: | } |
301: | } |
302: | |
303: | return true; |
304: | } |
305: | } |
306: | |
307: | |
308: | |
309: | |
310: | |
311: | |
312: | |
313: | |
314: | |
315: | |
316: | public function onGetItems($aArgs, &$mResult) |
317: | { |
318: | if ($aArgs['Type'] === self::$sStorageType) { |
319: | $mResult = array(); |
320: | $oClient = $this->getClient(); |
321: | if ($oClient) { |
322: | $aItems = array(); |
323: | $Path = '/' . ltrim($aArgs['Path'], '/'); |
324: | if (empty($aArgs['Pattern'])) { |
325: | $oListFolderContents = $oClient->listFolder($Path); |
326: | $oItems = $oListFolderContents->getItems(); |
327: | $aItems = $oItems->all(); |
328: | } else { |
329: | $oListFolderContents = $oClient->search($Path, $aArgs['Pattern']); |
330: | $oItems = $oListFolderContents->getItems(); |
331: | $aItems = $oItems->all(); |
332: | } |
333: | |
334: | foreach ($aItems as $oChild) { |
335: | if ($oChild instanceof \Kunnu\Dropbox\Models\SearchResult) { |
336: | $oChild = $oChild->getMetadata(); |
337: | } |
338: | $oItem = $this->populateFileInfo($oChild); |
339: | if ($oItem) { |
340: | $mResult[] = $oItem; |
341: | } |
342: | } |
343: | } |
344: | |
345: | return true; |
346: | } |
347: | } |
348: | |
349: | |
350: | |
351: | |
352: | |
353: | |
354: | |
355: | |
356: | |
357: | |
358: | public function onAfterCreateFolder($aArgs, &$mResult) |
359: | { |
360: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
361: | |
362: | if ($aArgs['Type'] === self::$sStorageType) { |
363: | $oClient = $this->getClient(); |
364: | if ($oClient) { |
365: | $mResult = false; |
366: | $sPath = $aArgs['Path']; |
367: | |
368: | if ($oClient->createFolder($sPath . '/' . $aArgs['FolderName']) !== null) { |
369: | $mResult = true; |
370: | } |
371: | } |
372: | return true; |
373: | } |
374: | } |
375: | |
376: | |
377: | |
378: | |
379: | |
380: | |
381: | |
382: | |
383: | |
384: | |
385: | public function onCreateFile($aArgs, &$mResult) |
386: | { |
387: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
388: | |
389: | if ($aArgs['Type'] === self::$sStorageType) { |
390: | $oClient = $this->getClient(); |
391: | if ($oClient) { |
392: | $mResult = false; |
393: | |
394: | $Path = $aArgs['Path'] . '/' . $aArgs['Name']; |
395: | $rData = $aArgs['Data']; |
396: | if (!is_resource($aArgs['Data'])) { |
397: | $rData = fopen('php://memory', 'r+'); |
398: | fwrite($rData, $aArgs['Data']); |
399: | rewind($rData); |
400: | } |
401: | $oDropboxFile = \Kunnu\Dropbox\DropboxFile::createByStream($aArgs['Name'], $rData); |
402: | if ($oClient->upload($oDropboxFile, $Path)) { |
403: | $mResult = true; |
404: | } |
405: | |
406: | return true; |
407: | } |
408: | } |
409: | } |
410: | |
411: | |
412: | |
413: | |
414: | |
415: | |
416: | |
417: | |
418: | |
419: | |
420: | public function onAfterDelete($aArgs, &$mResult) |
421: | { |
422: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
423: | |
424: | if ($aArgs['Type'] === self::$sStorageType) { |
425: | $oClient = $this->getClient(); |
426: | if ($oClient) { |
427: | $mResult = false; |
428: | |
429: | foreach ($aArgs['Items'] as $aItem) { |
430: | $oClient->delete($aItem['Path'] . '/' . $aItem['Name']); |
431: | $mResult = true; |
432: | } |
433: | } |
434: | return true; |
435: | } |
436: | } |
437: | |
438: | |
439: | |
440: | |
441: | |
442: | |
443: | |
444: | |
445: | |
446: | |
447: | public function onAfterRename($aArgs, &$mResult) |
448: | { |
449: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
450: | |
451: | if ($aArgs['Type'] === self::$sStorageType) { |
452: | $oClient = $this->getClient(); |
453: | if ($oClient) { |
454: | $mResult = false; |
455: | |
456: | $sPath = $aArgs['Path']; |
457: | if ($oClient->move($sPath . '/' . $aArgs['Name'], $sPath . '/' . $aArgs['NewName'])) { |
458: | $mResult = true; |
459: | } |
460: | } |
461: | } |
462: | } |
463: | |
464: | |
465: | |
466: | |
467: | |
468: | |
469: | |
470: | |
471: | |
472: | |
473: | public function onAfterMove($aArgs, &$mResult) |
474: | { |
475: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
476: | |
477: | if ($aArgs['FromType'] === self::$sStorageType) { |
478: | $oClient = $this->getClient(); |
479: | if ($oClient) { |
480: | $mResult = false; |
481: | |
482: | if ($aArgs['ToType'] === $aArgs['FromType']) { |
483: | foreach ($aArgs['Files'] as $aFile) { |
484: | $oClient->move($aArgs['FromPath'] . '/' . $aFile['Name'], $aArgs['ToPath'] . '/' . $aFile['Name']); |
485: | } |
486: | $mResult = true; |
487: | } |
488: | } |
489: | return true; |
490: | } |
491: | } |
492: | |
493: | |
494: | |
495: | |
496: | |
497: | |
498: | |
499: | |
500: | |
501: | |
502: | public function onAfterCopy($aArgs, &$mResult) |
503: | { |
504: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
505: | |
506: | if ($aArgs['FromType'] === self::$sStorageType) { |
507: | $oClient = $this->getClient(); |
508: | if ($oClient) { |
509: | $mResult = false; |
510: | |
511: | if ($aArgs['ToType'] === $aArgs['FromType']) { |
512: | foreach ($aArgs['Files'] as $aFile) { |
513: | $oClient->copy($aArgs['FromPath'] . '/' . $aFile['Name'], $aArgs['ToPath'] . '/' . $aFile['Name']); |
514: | } |
515: | $mResult = true; |
516: | } |
517: | } |
518: | return true; |
519: | } |
520: | } |
521: | |
522: | protected function _getFileInfo($sPath, $sName) |
523: | { |
524: | $mResult = false; |
525: | $oClient = $this->GetClient(); |
526: | if ($oClient) { |
527: | $mResult = $oClient->getMetadata($sPath . '/' . $sName); |
528: | } |
529: | |
530: | return $mResult; |
531: | } |
532: | |
533: | |
534: | |
535: | |
536: | |
537: | |
538: | |
539: | |
540: | |
541: | |
542: | public function onAfterGetFileInfo($aArgs, &$mResult) |
543: | { |
544: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
545: | |
546: | if (self::$sStorageType === $aArgs['Type']) { |
547: | $mFileInfo = $this->_getFileInfo($aArgs['Path'], $aArgs['Id']); |
548: | if ($mFileInfo) { |
549: | $mResult = $this->PopulateFileInfo($mFileInfo); |
550: | } |
551: | return true; |
552: | } |
553: | } |
554: | |
555: | |
556: | |
557: | |
558: | |
559: | |
560: | |
561: | |
562: | |
563: | public function onAfterPopulateFileItem($aArgs, &$oItem) |
564: | { |
565: | if ($oItem->IsLink) { |
566: | if (false !== strpos($oItem->LinkUrl, 'dl.dropboxusercontent.com') || |
567: | false !== strpos($oItem->LinkUrl, 'dropbox.com')) { |
568: | $aMetadata = $this->getMetadataLink($oItem->LinkUrl); |
569: | if (isset($aMetadata['path_lower']) && $aMetadata['.tag'] == 'folder') { |
570: | $oItem->UnshiftAction(array( |
571: | 'list' => array() |
572: | )); |
573: | |
574: | $oItem->Thumb = true; |
575: | $oItem->ThumbnailUrl = \MailSo\Base\Http::SingletonInstance()->GetFullUrl() . 'modules/' . self::GetName() . '/images/dropbox.png'; |
576: | } |
577: | $oItem->LinkType = 'dropbox'; |
578: | return true; |
579: | } |
580: | } |
581: | |
582: | return false; |
583: | } |
584: | |
585: | protected function getMetadataLink($sLink) |
586: | { |
587: | if (!$this->CheckDropboxAccess()) { |
588: | return null; |
589: | } |
590: | $oClient = $this->getClient(); |
591: | $response = $oClient->postToAPI( |
592: | '/sharing/get_shared_link_metadata', |
593: | array( |
594: | 'url' => $sLink |
595: | ) |
596: | ); |
597: | |
598: | if ($response->getHttpStatusCode() === 404) { |
599: | return null; |
600: | } |
601: | if ($response->getHttpStatusCode() !== 200) { |
602: | return null; |
603: | } |
604: | |
605: | $metadata = $response->getDecodedBody(); |
606: | if (array_key_exists("is_deleted", $metadata) && $metadata["is_deleted"]) { |
607: | return null; |
608: | } |
609: | return $metadata; |
610: | } |
611: | |
612: | public function onCheckUrlFile(&$aArgs, &$mResult) |
613: | { |
614: | if ($this->CheckDropboxAccess() && (\pathinfo($aArgs['Path'], PATHINFO_EXTENSION) === 'url' || strpos($aArgs['Path'], '.url/'))) { |
615: | list($sUrl, $sPath) = explode('.url', $aArgs['Path']); |
616: | $sUrl .= '.url'; |
617: | $aArgs['Path'] = $sUrl; |
618: | $this->prepareArgs($aArgs); |
619: | if ($sPath && $aArgs['Type'] === self::$sStorageType) { |
620: | $aArgs['Path'] .= $sPath; |
621: | } elseif ($aArgs['Type'] !== self::$sStorageType) { |
622: | $aArgs['Path'] = $sUrl . $sPath; |
623: | } |
624: | } |
625: | } |
626: | |
627: | protected function prepareArgs(&$aData) |
628: | { |
629: | $aPathInfo = pathinfo($aData['Path']); |
630: | $sExtension = isset($aPathInfo['extension']) ? $aPathInfo['extension'] : ''; |
631: | if ($sExtension === 'url') { |
632: | $aArgs = array( |
633: | 'UserId' => $aData['UserId'], |
634: | 'Type' => $aData['Type'], |
635: | 'Path' => $aPathInfo['dirname'], |
636: | 'Name' => $aPathInfo['basename'], |
637: | 'Id' => $aPathInfo['basename'], |
638: | 'IsThumb' => false |
639: | ); |
640: | $mResult = false; |
641: | \Aurora\System\Api::GetModuleManager()->broadcastEvent( |
642: | 'Files', |
643: | 'GetFile', |
644: | $aArgs, |
645: | $mResult |
646: | ); |
647: | if (is_resource($mResult)) { |
648: | $aUrlFileInfo = \Aurora\System\Utils::parseIniString(stream_get_contents($mResult)); |
649: | if ($aUrlFileInfo && isset($aUrlFileInfo['URL'])) { |
650: | if (false !== strpos($aUrlFileInfo['URL'], 'dl.dropboxusercontent.com') || |
651: | false !== strpos($aUrlFileInfo['URL'], 'dropbox.com')) { |
652: | $aData['Type'] = 'dropbox'; |
653: | $aMetadata = $this->getMetadataLink($aUrlFileInfo['URL']); |
654: | if (isset($aMetadata['path_lower'])) { |
655: | $aData['Path'] = $aMetadata['path_lower']; |
656: | } |
657: | } |
658: | } |
659: | } |
660: | } |
661: | } |
662: | |
663: | |
664: | |
665: | |
666: | |
667: | |
668: | |
669: | |
670: | |
671: | public function onGetSettings($aArgs, &$mResult) |
672: | { |
673: | $oUser = \Aurora\System\Api::getAuthenticatedUser(); |
674: | |
675: | if ($oUser) { |
676: | $aScope = array( |
677: | 'Name' => 'storage', |
678: | 'Description' => $this->i18N('SCOPE_FILESTORAGE'), |
679: | 'Value' => false |
680: | ); |
681: | if ($oUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin) { |
682: | $aScope['Value'] = $this->issetScope('storage'); |
683: | $mResult['Scopes'][] = $aScope; |
684: | } |
685: | if ($oUser->isNormalOrTenant()) { |
686: | if ($aArgs['OAuthAccount'] instanceof \Aurora\Modules\OAuthIntegratorWebclient\Models\OauthAccount) { |
687: | $aScope['Value'] = $aArgs['OAuthAccount']->issetScope('storage'); |
688: | } |
689: | if ($this->issetScope('storage')) { |
690: | $mResult['Scopes'][] = $aScope; |
691: | } |
692: | } |
693: | } |
694: | } |
695: | |
696: | public function onAfterUpdateSettings($aArgs, &$mResult) |
697: | { |
698: | $sScope = ''; |
699: | if (isset($aArgs['Scopes']) && is_array($aArgs['Scopes'])) { |
700: | foreach ($aArgs['Scopes'] as $aScope) { |
701: | if ($aScope['Name'] === 'storage') { |
702: | if ($aScope['Value']) { |
703: | $sScope = 'storage'; |
704: | break; |
705: | } |
706: | } |
707: | } |
708: | } |
709: | $this->setConfig('Scopes', $sScope); |
710: | $this->saveModuleConfig(); |
711: | } |
712: | |
713: | |
714: | |
715: | |
716: | |
717: | |
718: | |
719: | protected function checkStorageType($Type) |
720: | { |
721: | return $Type === static::$sStorageType; |
722: | } |
723: | |
724: | |
725: | |
726: | |
727: | |
728: | |
729: | public function onAfterCheckQuota($aArgs, &$mResult) |
730: | { |
731: | $Type = $aArgs['Type']; |
732: | if ($this->checkStorageType($Type)) { |
733: | $mResult = true; |
734: | return true; |
735: | } |
736: | } |
737: | |
738: | protected function CheckDropboxAccess() |
739: | { |
740: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
741: | $bEnableDropboxModule = false; |
742: | |
743: | if (class_exists('Aurora\Modules\Dropbox\Module')) { |
744: | $oDropboxModule = \Aurora\Modules\Dropbox\Module::getInstance(); |
745: | $bEnableDropboxModule = $oDropboxModule->oModuleSettings->EnableModule; |
746: | } |
747: | |
748: | $oOAuthIntegratorWebclientModule = \Aurora\Modules\OAuthIntegratorWebclient\Module::Decorator(); |
749: | $oOAuthAccount = $oOAuthIntegratorWebclientModule->GetAccount(self::$sStorageType); |
750: | |
751: | return ($oOAuthAccount instanceof \Aurora\Modules\OAuthIntegratorWebclient\Models\OauthAccount |
752: | && $oOAuthAccount->Type === self::$sStorageType |
753: | && $bEnableDropboxModule |
754: | && $this->issetScope('storage') |
755: | && $oOAuthAccount->issetScope('storage')); |
756: | } |
757: | } |
758: | |