diff --git a/lib/AppConfig.php b/lib/AppConfig.php index c983c7c87..6a84dd0c0 100644 --- a/lib/AppConfig.php +++ b/lib/AppConfig.php @@ -15,7 +15,6 @@ use OCA\Richdocuments\AppInfo\Application; use \OCP\IConfig; class AppConfig { - public const FEDERATION_USE_TRUSTED_DOMAINS = 'federation_use_trusted_domains'; public const SYSTEM_GS_TRUSTED_HOSTS = 'gs.trustedHosts'; @@ -30,13 +29,13 @@ class AppConfig { 'token_ttl' => 36000, // 10 hours ]; - const WATERMARK_APP_NAMESPACE = 'files'; + public const WATERMARK_APP_NAMESPACE = 'files'; - const APP_SETTING_TYPES = [ - 'watermark_allGroupsList' => 'array', - 'watermark_allTagsList' => 'array', - 'watermark_linkTagsList' => 'array' - ]; + public const APP_SETTING_TYPES = [ + 'watermark_allGroupsList' => 'array', + 'watermark_allTagsList' => 'array', + 'watermark_linkTagsList' => 'array' + ]; /** @var IConfig */ private $config; @@ -59,7 +58,7 @@ class AppConfig { */ public function getAppValue($key) { $defaultValue = null; - if (array_key_exists($key, $this->defaults)){ + if (array_key_exists($key, $this->defaults)) { $defaultValue = $this->defaults[$key]; } return $this->config->getAppValue($this->getAppNamespace($key), $key, $defaultValue); @@ -124,5 +123,4 @@ class AppConfig { public function isTrustedDomainAllowedForFederation(): bool { return $this->config->getAppValue(Application::APPNAME, self::FEDERATION_USE_TRUSTED_DOMAINS, 'no') === 'yes'; } - - } +} diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index d71a21c9a..e75905be7 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -25,9 +25,7 @@ namespace OCA\Richdocuments\AppInfo; use OC\EventDispatcher\SymfonyAdapter; -use OC\Files\Type\Detection; use OC\Security\CSP\ContentSecurityPolicy; -use OCA\Files_Sharing\Listener\LoadAdditionalListener; use OCA\Richdocuments\AppConfig; use OCA\Richdocuments\Capabilities; use OCA\Richdocuments\Middleware\WOPIMiddleware; @@ -57,7 +55,6 @@ use OCP\IL10N; use OCP\IPreview; class Application extends App implements IBootstrap { - public const APPNAME = 'richdocuments'; public function __construct(array $urlParams = array()) { @@ -75,15 +72,15 @@ class Application extends App implements IBootstrap { public function boot(IBootContext $context): void { $currentUser = \OC::$server->getUserSession()->getUser(); - if($currentUser !== null) { + if ($currentUser !== null) { /** @var PermissionManager $permissionManager */ $permissionManager = \OC::$server->query(PermissionManager::class); - if(!$permissionManager->isEnabledForUser($currentUser)) { + if (!$permissionManager->isEnabledForUser($currentUser)) { return; } } - $context->injectFn(function(ITemplateManager $templateManager, IL10N $l10n, IConfig $config, CapabilitiesService $capabilitiesService) { + $context->injectFn(function (ITemplateManager $templateManager, IL10N $l10n, IConfig $config, CapabilitiesService $capabilitiesService) { if (empty($capabilitiesService->getCapabilities())) { return; } @@ -98,7 +95,7 @@ class Application extends App implements IBootstrap { $odtType->addMimetype('application/vnd.oasis.opendocument.text-template'); } $odtType->setIconClass('icon-filetype-document'); - $odtType->setRatio(21/29.7); + $odtType->setRatio(21 / 29.7); return $odtType; }); $templateManager->registerTemplateFileCreator(function () use ($l10n, $ooxml) { @@ -111,7 +108,7 @@ class Application extends App implements IBootstrap { $odsType->addMimetype('application/vnd.oasis.opendocument.spreadsheet-template'); } $odsType->setIconClass('icon-filetype-spreadsheet'); - $odsType->setRatio(16/9); + $odsType->setRatio(16 / 9); return $odsType; }); $templateManager->registerTemplateFileCreator(function () use ($l10n, $ooxml) { @@ -124,7 +121,7 @@ class Application extends App implements IBootstrap { $odpType->addMimetype('application/vnd.oasis.opendocument.presentation-template'); } $odpType->setIconClass('icon-filetype-presentation'); - $odpType->setRatio(16/9); + $odpType->setRatio(16 / 9); return $odpType; }); @@ -174,23 +171,23 @@ class Application extends App implements IBootstrap { /** @var IPreview $previewManager */ $previewManager = $container->query(IPreview::class); - $previewManager->registerProvider('/application\/vnd.ms-excel/', function() use ($container) { + $previewManager->registerProvider('/application\/vnd.ms-excel/', function () use ($container) { return $container->query(MSExcel::class); }); - $previewManager->registerProvider('/application\/msword/', function() use ($container) { + $previewManager->registerProvider('/application\/msword/', function () use ($container) { return $container->query(MSWord::class); }); - $previewManager->registerProvider('/application\/vnd.openxmlformats-officedocument.*/', function() use ($container) { + $previewManager->registerProvider('/application\/vnd.openxmlformats-officedocument.*/', function () use ($container) { return $container->query(OOXML::class); }); - $previewManager->registerProvider('/application\/vnd.oasis.opendocument.*/', function() use ($container) { + $previewManager->registerProvider('/application\/vnd.oasis.opendocument.*/', function () use ($container) { return $container->query(OpenDocument::class); }); - $previewManager->registerProvider('/application\/pdf/', function() use ($container) { + $previewManager->registerProvider('/application\/pdf/', function () use ($container) { return $container->query(Pdf::class); }); } @@ -261,8 +258,9 @@ class Application extends App implements IBootstrap { // Supported only on Linux OS, and x86_64 & ARM64 platforms $supportedArchs = array('x86_64', 'aarch64'); $osFamily = PHP_VERSION_ID >= 70200 ? PHP_OS_FAMILY : PHP_OS; - if ($osFamily !== 'Linux' || !in_array(php_uname('m'), $supportedArchs)) + if ($osFamily !== 'Linux' || !in_array(php_uname('m'), $supportedArchs)) { return; + } $CODEAppID = (php_uname('m') === 'x86_64') ? 'richdocumentscode' : 'richdocumentscode_arm64'; @@ -307,8 +305,8 @@ class Application extends App implements IBootstrap { private function domainOnly($url) { $parsed_url = parse_url($url); $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; - $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; - $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; + $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; + $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; return "$scheme$host$port"; } } diff --git a/lib/Backgroundjobs/Cleanup.php b/lib/Backgroundjobs/Cleanup.php index 5d3efdb35..4bdeb68ae 100644 --- a/lib/Backgroundjobs/Cleanup.php +++ b/lib/Backgroundjobs/Cleanup.php @@ -39,7 +39,7 @@ class Cleanup extends TimedJob { $this->db = $db; $this->wopiMapper = $wopiMapper; - $this->setInterval(60*60); + $this->setInterval(60 * 60); } protected function run($argument) { @@ -51,11 +51,9 @@ class Cleanup extends TimedJob { // Expired WOPI access tokens $this->cleanUpWopiTokens(); - } - private function cleanUpWopiTokens() - { + private function cleanUpWopiTokens() { $tokenIds = $this->wopiMapper->getExpiredTokenIds(1000); $query = $this->db->getQueryBuilder(); $query->delete('richdocuments_wopi') diff --git a/lib/Backgroundjobs/ObtainCapabilities.php b/lib/Backgroundjobs/ObtainCapabilities.php index 4aee00344..287a91aaa 100644 --- a/lib/Backgroundjobs/ObtainCapabilities.php +++ b/lib/Backgroundjobs/ObtainCapabilities.php @@ -34,7 +34,7 @@ class ObtainCapabilities extends TimedJob { public function __construct(CapabilitiesService $capabilitiesService) { $this->capabilitiesService = $capabilitiesService; - $this->setInterval(60*60); + $this->setInterval(60 * 60); } protected function run($argument) { diff --git a/lib/Capabilities.php b/lib/Capabilities.php index 0e58d48ff..96e16af74 100644 --- a/lib/Capabilities.php +++ b/lib/Capabilities.php @@ -28,8 +28,7 @@ use OCP\Capabilities\ICapability; use OCP\IL10N; class Capabilities implements ICapability { - - const MIMETYPES = [ + public const MIMETYPES = [ 'application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.spreadsheet', 'application/vnd.oasis.opendocument.graphics', @@ -68,7 +67,7 @@ class Capabilities implements ICapability { 'text/csv' ]; - const MIMETYPES_OPTIONAL = [ + public const MIMETYPES_OPTIONAL = [ 'image/svg+xml', 'application/pdf', 'text/plain', diff --git a/lib/Command/ActivateConfig.php b/lib/Command/ActivateConfig.php index 9c3edfa83..665966641 100644 --- a/lib/Command/ActivateConfig.php +++ b/lib/Command/ActivateConfig.php @@ -26,11 +26,9 @@ namespace OCA\RichDocuments\Command; use OCA\Richdocuments\AppConfig; use OCA\Richdocuments\Service\CapabilitiesService; -use OCA\Richdocuments\TemplateManager; use OCA\Richdocuments\WOPI\DiscoveryManager; use OCA\Richdocuments\WOPI\Parser; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -85,5 +83,4 @@ class ActivateConfig extends Command { return 1; } } - } diff --git a/lib/Command/UpdateEmptyTemplates.php b/lib/Command/UpdateEmptyTemplates.php index e83cda2d0..848f45d0b 100644 --- a/lib/Command/UpdateEmptyTemplates.php +++ b/lib/Command/UpdateEmptyTemplates.php @@ -26,7 +26,6 @@ namespace OCA\RichDocuments\Command; use OCA\Richdocuments\TemplateManager; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -58,5 +57,4 @@ class UpdateEmptyTemplates extends Command { return 1; } } - } diff --git a/lib/Controller/DirectViewController.php b/lib/Controller/DirectViewController.php index 4013890c0..a36ac2877 100644 --- a/lib/Controller/DirectViewController.php +++ b/lib/Controller/DirectViewController.php @@ -140,11 +140,10 @@ class DirectViewController extends Controller { } $relativePath = '/new.odt'; - } else { try { $item = $folder->getById($direct->getFileid())[0]; - if(!($item instanceof Node)) { + if (!($item instanceof Node)) { throw new \Exception(); } @@ -190,7 +189,6 @@ class DirectViewController extends Controller { $this->logger->logException($e); return $this->renderErrorPage('Failed to open the requested file.'); } - } public function showPublicShare(Direct $direct) { @@ -245,12 +243,11 @@ class DirectViewController extends Controller { return $response; } } catch (\Exception $e) { - $this->logger->logException($e, ['app'=>'richdocuments']); + $this->logger->logException($e, ['app' => 'richdocuments']); return $this->renderErrorPage('Failed to open the requested file.'); } return new TemplateResponse('core', '403', [], 'guest'); - } private function renderErrorPage($message) { diff --git a/lib/Controller/DocumentAPIController.php b/lib/Controller/DocumentAPIController.php index dc1554467..eeeda4957 100644 --- a/lib/Controller/DocumentAPIController.php +++ b/lib/Controller/DocumentAPIController.php @@ -40,7 +40,6 @@ use Psr\Log\LoggerInterface; use Throwable; class DocumentAPIController extends \OCP\AppFramework\OCSController { - private $rootFolder; private $shareManager; private $templateManager; diff --git a/lib/Controller/DocumentController.php b/lib/Controller/DocumentController.php index 9d3a48d73..c12df1058 100644 --- a/lib/Controller/DocumentController.php +++ b/lib/Controller/DocumentController.php @@ -27,7 +27,6 @@ use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use \OCP\IRequest; use \OCP\IConfig; -use \OCP\IL10N; use \OCP\ILogger; use \OCP\AppFramework\Http\ContentSecurityPolicy; use \OCP\AppFramework\Http\FeaturePolicy; @@ -105,7 +104,7 @@ class DocumentController extends Controller { public function extAppGetData($fileId) { $secretToken = $this->request->getParam('secret_token'); $apps = array_filter(explode(',', $this->appConfig->getAppValue('external_apps'))); - foreach($apps as $app) { + foreach ($apps as $app) { if ($app !== '' && $secretToken === $app) { $appName = explode(':', $app); $this->logger->debug('External app "{extApp}" authenticated; issuing access token for fileId {fileId}', [ @@ -116,7 +115,7 @@ class DocumentController extends Controller { try { $folder = $this->rootFolder->getUserFolder($this->uid); $item = $folder->getById($fileId)[0]; - if(!($item instanceof Node)) { + if (!($item instanceof Node)) { throw new \Exception(); } list($urlSrc, $token) = $this->tokenManager->getToken($item->getId()); @@ -126,7 +125,7 @@ class DocumentController extends Controller { 'token' => $token ]; } catch (\Exception $e) { - $this->logger->logException($e, ['app'=>'richdocuments']); + $this->logger->logException($e, ['app' => 'richdocuments']); } } } @@ -145,8 +144,8 @@ class DocumentController extends Controller { private function domainOnly($url) { $parsed_url = parse_url($url); $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; - $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; - $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; + $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; + $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; return "$scheme$host$port"; } @@ -184,7 +183,7 @@ class DocumentController extends Controller { $item = $folder->getById($fileId)[0]; } - if(!($item instanceof File)) { + if (!($item instanceof File)) { throw new \Exception(); } @@ -221,8 +220,7 @@ class DocumentController extends Controller { ]; $encryptionManager = \OC::$server->getEncryptionManager(); - if ($encryptionManager->isEnabled()) - { + if ($encryptionManager->isEnabled()) { // Update the current file to be accessible with system public shared key $owner = $item->getOwner()->getUID(); $absPath = '/' . $owner . '/' . $item->getInternalPath(); @@ -236,7 +234,7 @@ class DocumentController extends Controller { $this->setupPolicy($response); return $response; } catch (\Exception $e) { - $this->logger->logException($e, ['app'=>'richdocuments']); + $this->logger->logException($e, ['app' => 'richdocuments']); return $this->renderErrorPage('Failed to open the requested file.'); } } @@ -309,7 +307,7 @@ class DocumentController extends Controller { try { $share = $this->shareManager->getShareByToken($shareToken); // not authenticated ? - if($share->getPassword()){ + if ($share->getPassword()) { if (!$this->session->exists('public_link_authenticated') || $this->session->get('public_link_authenticated') !== (string)$share->getId() ) { @@ -322,7 +320,7 @@ class DocumentController extends Controller { } $node = $share->getNode(); - if($node instanceof Folder) { + if ($node instanceof Folder) { $item = $node->getById($fileId)[0]; } else { $item = $node; @@ -355,7 +353,7 @@ class DocumentController extends Controller { return $response; } } catch (\Exception $e) { - $this->logger->logException($e, ['app'=>'richdocuments']); + $this->logger->logException($e, ['app' => 'richdocuments']); return $this->renderErrorPage('Failed to open the requested file.'); } @@ -402,7 +400,7 @@ class DocumentController extends Controller { $this->logger->warning('Failed to connect to remote collabora instance for ' . $fileId); } } catch (\Exception $e) { - $this->logger->logException($e, ['app'=>'richdocuments']); + $this->logger->logException($e, ['app' => 'richdocuments']); return $this->renderErrorPage('Failed to open the requested file.'); } @@ -425,7 +423,7 @@ class DocumentController extends Controller { try { $share = $this->shareManager->getShareByToken($shareToken); // not authenticated ? - if($share->getPassword()){ + if ($share->getPassword()) { if (!$this->session->exists('public_link_authenticated') || $this->session->get('public_link_authenticated') !== (string)$share->getId() ) { @@ -486,7 +484,7 @@ class DocumentController extends Controller { } catch (ShareNotFound $e) { return new TemplateResponse('core', '404', [], 'guest'); } catch (\Exception $e) { - $this->logger->logException($e, ['app'=>'richdocuments']); + $this->logger->logException($e, ['app' => 'richdocuments']); return $this->renderErrorPage('Failed to open the requested file.'); } diff --git a/lib/Controller/FederationController.php b/lib/Controller/FederationController.php index 17651a309..3fa597fcb 100644 --- a/lib/Controller/FederationController.php +++ b/lib/Controller/FederationController.php @@ -25,7 +25,6 @@ namespace OCA\Richdocuments\Controller; use OCA\Richdocuments\Exceptions\ExpiredTokenException; use OCA\Richdocuments\Exceptions\UnknownTokenException; use OCP\AppFramework\Db\DoesNotExistException; -use OCP\AppFramework\Db\TokenExpiredException; use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\AppFramework\OCSController; use OCA\Richdocuments\Db\WopiMapper; @@ -63,7 +62,7 @@ class FederationController extends OCSController { IURLGenerator $urlGenerator ) { parent::__construct($appName, $request); - $this->config = $config; + $this->config = $config; $this->logger = $logger; $this->wopiMapper = $wopiMapper; $this->userManager = $userManager; @@ -110,7 +109,7 @@ class FederationController extends OCSController { $initiatorWopi->setGuestDisplayname($initiatorUser['displayName']); } else { $user = $this->userManager->get($initiatorWopi->getEditorUid()); - if($user !== null) { + if ($user !== null) { $initiatorWopi->setGuestDisplayname($user->getDisplayName()); } } @@ -142,7 +141,7 @@ class FederationController extends OCSController { try { $wopi = $this->wopiMapper->getWopiForToken($token); $user = $this->userManager->get($wopi->getEditorUid()); - if($user !== null) { + if ($user !== null) { $wopi->setGuestDisplayname($user->getDisplayName()); } $this->logger->debug('COOL-Federation-Initiator-User: Token ' . $token . ' returned'); @@ -159,5 +158,4 @@ class FederationController extends OCSController { throw new OCSNotFoundException(); } } - } diff --git a/lib/Controller/OCSController.php b/lib/Controller/OCSController.php index e6f04c244..77de110ad 100644 --- a/lib/Controller/OCSController.php +++ b/lib/Controller/OCSController.php @@ -31,7 +31,6 @@ use OCA\Richdocuments\Exceptions\UnknownTokenException; use OCA\Richdocuments\Service\FederationService; use OCA\Richdocuments\TemplateManager; use OCA\Richdocuments\TokenManager; -use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSBadRequestException; @@ -90,11 +89,11 @@ class OCSController extends \OCP\AppFramework\OCSController { ) { parent::__construct($appName, $request); - $this->rootFolder = $rootFolder; - $this->userId = $userId; + $this->rootFolder = $rootFolder; + $this->userId = $userId; $this->directMapper = $directMapper; $this->urlGenerator = $urlGenerator; - $this->manager = $manager; + $this->manager = $manager; $this->tokenManager = $tokenManager; $this->shareManager = $shareManager; $this->federationService = $federationService; @@ -113,7 +112,7 @@ class OCSController extends \OCP\AppFramework\OCSController { public function createDirect($fileId) { try { $userFolder = $this->rootFolder->getUserFolder($this->userId); - $nodes = $userFolder->getById($fileId); + $nodes = $userFolder->getById($fileId); if ($nodes === []) { throw new OCSNotFoundException(); @@ -345,16 +344,16 @@ class OCSController extends \OCP\AppFramework\OCSController { private function mb_pathinfo($filepath) { $result = []; preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', ltrim('/' . $filepath), $matches); - if($matches[1]) { + if ($matches[1]) { $result['dirname'] = $matches[1]; } - if($matches[2]) { + if ($matches[2]) { $result['basename'] = $matches[2]; } - if($matches[5]) { + if ($matches[5]) { $result['extension'] = $matches[5]; } - if($matches[3]) { + if ($matches[3]) { $result['filename'] = $matches[3]; } return $result; diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 9d9a789d0..8cb09d90c 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -11,7 +11,6 @@ namespace OCA\Richdocuments\Controller; -use Exception; use OCA\Richdocuments\Service\CapabilitiesService; use OCA\Richdocuments\Service\DemoService; use OCA\Richdocuments\Service\FontService; @@ -35,7 +34,7 @@ use OCP\IConfig; use OCP\PreConditionNotMetException; use OCP\Util; -class SettingsController extends Controller{ +class SettingsController extends Controller { // TODO adapt overview generation if we add more font mimetypes public const FONT_MIME_TYPES = [ 'font/ttf', @@ -148,20 +147,20 @@ class SettingsController extends Controller{ * @return JSONResponse */ public function setSettings($wopi_url, - $wopi_allowlist, - $disable_certificate_verification, - $edit_groups, - $use_groups, - $doc_format, - $external_apps, - $canonical_webroot) { + $wopi_allowlist, + $disable_certificate_verification, + $edit_groups, + $use_groups, + $doc_format, + $external_apps, + $canonical_webroot) { $message = $this->l10n->t('Saved'); - if ($wopi_url !== null){ + if ($wopi_url !== null) { $this->appConfig->setAppValue('wopi_url', $wopi_url); } - if ($wopi_allowlist !== null){ + if ($wopi_allowlist !== null) { $this->appConfig->setAppValue('wopi_allowlist', $wopi_allowlist); } @@ -172,11 +171,11 @@ class SettingsController extends Controller{ ); } - if ($edit_groups !== null){ + if ($edit_groups !== null) { $this->appConfig->setAppValue('edit_groups', $edit_groups); } - if ($use_groups !== null){ + if ($use_groups !== null) { $this->appConfig->setAppValue('use_groups', $use_groups); } @@ -201,12 +200,12 @@ class SettingsController extends Controller{ if ($public_wopi_url !== null) { $this->appConfig->setAppValue('public_wopi_url', $public_wopi_url); $colon = strpos($public_wopi_url, ':', 0); - if ($this->request->getServerProtocol() !== substr($public_wopi_url, 0, $colon)){ + if ($this->request->getServerProtocol() !== substr($public_wopi_url, 0, $colon)) { $message = $this->l10n->t('Saved with error: Collabora Online should use the same protocol as the server installation.'); } } } - } catch (\Exception $e){ + } catch (\Exception $e) { if ($wopi_url !== null) { return new JSONResponse([ 'status' => 'error', @@ -289,7 +288,7 @@ class SettingsController extends Controller{ $message = $this->l10n->t('Saved'); $status = 'success'; - if ($templateFolder !== null){ + if ($templateFolder !== null) { try { $this->config->setUserValue($this->userId, 'richdocuments', 'templateFolder', $templateFolder); } catch (PreConditionNotMetException $e) { @@ -304,7 +303,6 @@ class SettingsController extends Controller{ ]; return new JSONResponse($response); - } /** @@ -381,7 +379,7 @@ class SettingsController extends Controller{ } catch (NotFoundException $e) { return new DataDisplayResponse('', Http::STATUS_NOT_FOUND); } -} + } /** * @NoAdminRequired diff --git a/lib/Controller/TemplatesController.php b/lib/Controller/TemplatesController.php index e59a0396e..e8eabc7eb 100644 --- a/lib/Controller/TemplatesController.php +++ b/lib/Controller/TemplatesController.php @@ -1,4 +1,5 @@ @@ -70,7 +71,7 @@ class TemplatesController extends Controller { $this->appName = $appName; $this->request = $request; - $this->l10n = $l10n; + $this->l10n = $l10n; $this->manager = $manager; $this->preview = $preview; } @@ -96,7 +97,6 @@ class TemplatesController extends Controller { $a = false, $forceIcon = true, $mode = 'fill') { - if ($fileId === '' || $x === 0 || $y === 0) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } @@ -200,7 +200,6 @@ class TemplatesController extends Controller { bool $a = false, bool $forceIcon = true, string $mode = IPreview::MODE_FILL): Http\Response { - if (!($node instanceof Node) || (!$forceIcon && !$this->preview->isAvailable($node))) { return new DataResponse([], Http::STATUS_NOT_FOUND); } @@ -209,7 +208,7 @@ class TemplatesController extends Controller { } try { - $f = $this->preview->getPreview($node, $x, $y, !$a, $mode); + $f = $this->preview->getPreview($node, $x, $y, !$a, $mode); $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); $response->cacheFor(3600 * 24); diff --git a/lib/Controller/WopiController.php b/lib/Controller/WopiController.php index c01a6df26..b06a9d1d3 100644 --- a/lib/Controller/WopiController.php +++ b/lib/Controller/WopiController.php @@ -98,9 +98,9 @@ class WopiController extends Controller { private ILockManager $lockManager; // Signifies LOOL that document has been changed externally in this storage - const LOOL_STATUS_DOC_CHANGED = 1010; + public const LOOL_STATUS_DOC_CHANGED = 1010; - const WOPI_AVATAR_SIZE = 32; + public const WOPI_AVATAR_SIZE = 32; /** * @param string $appName @@ -172,7 +172,6 @@ class WopiController extends Controller { */ public function checkFileInfo($fileId, $access_token) { try { - list($fileId, , $version) = Helper::parseFileId($fileId); $wopi = $this->wopiMapper->getWopiForToken($access_token); @@ -182,7 +181,7 @@ class WopiController extends Controller { } else { $file = $this->getFileForWopiToken($wopi); } - if(!($file instanceof File)) { + if (!($file instanceof File)) { throw new NotFoundException('No valid file found for ' . $fileId); } } catch (NotFoundException $e) { @@ -257,10 +256,10 @@ class WopiController extends Controller { } $user = $this->userManager->get($wopi->getEditorUid()); - if($user !== null) { + if ($user !== null) { $response['UserExtraInfo']['avatar'] = $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $wopi->getEditorUid(), 'size' => self::WOPI_AVATAR_SIZE]); if ($this->groupManager->isAdmin($wopi->getEditorUid())) { - $response['UserExtraInfo']['is_admin'] = true; + $response['UserExtraInfo']['is_admin'] = true; } } else { $response['UserExtraInfo']['avatar'] = $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => urlencode($wopi->getGuestDisplayname()), 'size' => self::WOPI_AVATAR_SIZE]); @@ -428,8 +427,7 @@ class WopiController extends Controller { } else { $response = new StreamResponse($info->fopen('rb')); } - } - else { + } else { if ($file->getSize() === 0) { $response = new Http\Response(); } else { @@ -461,7 +459,7 @@ class WopiController extends Controller { */ public function putFile($fileId, $access_token) { - list($fileId, ,) = Helper::parseFileId($fileId); + list($fileId, , ) = Helper::parseFileId($fileId); $isPutRelative = ($this->request->getHeader('X-WOPI-Override') === 'PUT_RELATIVE'); try { @@ -505,11 +503,9 @@ class WopiController extends Controller { if ($suggested[0] === '.') { $path = dirname($file->getPath()) . '/New File' . $suggested; - } - else if ($suggested[0] !== '/') { + } elseif ($suggested[0] !== '/') { $path = dirname($file->getPath()) . '/' . $suggested; - } - else { + } else { $path = $userFolder->getPath() . $suggested; } @@ -546,7 +542,7 @@ class WopiController extends Controller { $content = fopen('php://input', 'rb'); try { - $this->wrappedFilesystemOperation($wopi, function () use ($file, $content){ + $this->wrappedFilesystemOperation($wopi, function () use ($file, $content) { return $file->putContent($content); }); } catch (LockedException $e) { @@ -595,7 +591,7 @@ class WopiController extends Controller { try { $wopiOverride = $this->request->getHeader('X-WOPI-Override'); $wopiLock = $this->request->getHeader('X-WOPI-Lock'); - list($fileId, ,) = Helper::parseFileId($fileId); + list($fileId, , ) = Helper::parseFileId($fileId); $wopi = $this->wopiMapper->getWopiForToken($access_token); } catch (UnknownTokenException $e) { $this->logger->debug($e->getMessage(), ['app' => 'richdocuments']); @@ -643,7 +639,7 @@ class WopiController extends Controller { if ($wopi->isTemplateToken()) { $this->templateManager->setUserId($wopi->getOwnerUid()); $file = $userFolder->getById($wopi->getTemplateDestination())[0]; - } else if ($isRenameFile) { + } elseif ($isRenameFile) { // the new file needs to be installed in the current user dir $userFolder = $this->rootFolder->getUserFolder($wopi->getEditorUid()); $file = $userFolder->getById($fileId)[0]; @@ -654,11 +650,9 @@ class WopiController extends Controller { if (strpos($suggested, '.') === 0) { $path = dirname($file->getPath()) . '/New File' . $suggested; - } - else if (strpos($suggested, '/') !== 0) { + } elseif (strpos($suggested, '/') !== 0) { $path = dirname($file->getPath()) . '/' . $suggested; - } - else { + } else { $path = $userFolder->getPath() . $suggested; } @@ -689,7 +683,7 @@ class WopiController extends Controller { if ($suggested[0] === '.') { $path = dirname($file->getPath()) . '/New File' . $suggested; - } else if ($suggested[0] !== '/') { + } elseif ($suggested[0] !== '/') { $path = dirname($file->getPath()) . '/' . $suggested; } else { $path = $userFolder->getPath() . $suggested; @@ -718,7 +712,7 @@ class WopiController extends Controller { $this->userScopeService->setFilesystemScope($wopi->getEditorUid()); try { - $this->wrappedFilesystemOperation($wopi, function () use ($file, $content){ + $this->wrappedFilesystemOperation($wopi, function () use ($file, $content) { return $file->putContent($content); }); } catch (LockedException $e) { diff --git a/lib/Db/AssetMapper.php b/lib/Db/AssetMapper.php index 39f74bce2..9d03a7c06 100644 --- a/lib/Db/AssetMapper.php +++ b/lib/Db/AssetMapper.php @@ -31,7 +31,7 @@ use OCP\Security\ISecureRandom; class AssetMapper extends Mapper { /** @var int Limetime of a token is 10 minutes */ - const tokenLifeTime = 600; + public const tokenLifeTime = 600; /** @var ISecureRandom */ private $random; diff --git a/lib/Db/DirectMapper.php b/lib/Db/DirectMapper.php index f98b2a400..256adfc63 100644 --- a/lib/Db/DirectMapper.php +++ b/lib/Db/DirectMapper.php @@ -28,12 +28,11 @@ use OCP\AppFramework\Db\Mapper; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IDBConnection; use OCP\Security\ISecureRandom; -use PhpParser\Node\Scalar\MagicConst\Dir; class DirectMapper extends Mapper { /** @var int Limetime of a token is 10 minutes */ - const tokenLifeTime = 600; + public const tokenLifeTime = 600; /** @var ISecureRandom */ protected $random; diff --git a/lib/Db/Wopi.php b/lib/Db/Wopi.php index 312506032..ff1d7a95b 100644 --- a/lib/Db/Wopi.php +++ b/lib/Db/Wopi.php @@ -66,27 +66,27 @@ class Wopi extends Entity implements \JsonSerializable { /** * WOPI token to open a file as a user on the current instance */ - const TOKEN_TYPE_USER = 0; + public const TOKEN_TYPE_USER = 0; /** * WOPI token to open a file as a guest on the current instance */ - const TOKEN_TYPE_GUEST = 1; + public const TOKEN_TYPE_GUEST = 1; /** * WOPI token to open a file as a user from a federated instance */ - const TOKEN_TYPE_REMOTE_USER = 2; + public const TOKEN_TYPE_REMOTE_USER = 2; /** * WOPI token to open a file as a guest from a federated instance */ - const TOKEN_TYPE_REMOTE_GUEST = 3; + public const TOKEN_TYPE_REMOTE_GUEST = 3; /* * Temporary token that is used to share the initiator details to the source instance */ - const TOKEN_TYPE_INITIATOR = 4; + public const TOKEN_TYPE_INITIATOR = 4; /** @var string */ protected $ownerUid; diff --git a/lib/Db/WopiMapper.php b/lib/Db/WopiMapper.php index 272ef7af4..4d874f4e9 100644 --- a/lib/Db/WopiMapper.php +++ b/lib/Db/WopiMapper.php @@ -139,7 +139,6 @@ class WopiMapper extends Mapper { * @throws ExpiredTokenException */ public function getWopiForToken($token) { - $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from('richdocuments_wopi') @@ -161,7 +160,7 @@ class WopiMapper extends Mapper { /** @var Wopi $wopi */ $wopi = Wopi::fromRow($row); - if ($wopi->getExpiry() < $this->timeFactory->getTime()){ + if ($wopi->getExpiry() < $this->timeFactory->getTime()) { throw new ExpiredTokenException('Provided token is expired.'); } diff --git a/lib/Events/BeforeFederationRedirectEvent.php b/lib/Events/BeforeFederationRedirectEvent.php index 40bb8b021..9119f04a5 100644 --- a/lib/Events/BeforeFederationRedirectEvent.php +++ b/lib/Events/BeforeFederationRedirectEvent.php @@ -2,45 +2,43 @@ namespace OCA\Richdocuments\Events; - use OCP\Files\Node; use Symfony\Component\EventDispatcher\Event; class BeforeFederationRedirectEvent extends Event { - /** @var Node */ - private $node; - /** @var string */ - private $relativePath; - /** @var string|null */ - private $redirectUrl = null; - /** @var string */ - private $remote; + /** @var Node */ + private $node; + /** @var string */ + private $relativePath; + /** @var string|null */ + private $redirectUrl = null; + /** @var string */ + private $remote; - public function __construct($node, $relativePath, $remote) { - $this->node = $node; - $this->relativePath = $relativePath; - $this->remote = $remote; - } + public function __construct($node, $relativePath, $remote) { + $this->node = $node; + $this->relativePath = $relativePath; + $this->remote = $remote; + } - public function getRelativePath() { - return $this->relativePath; - } + public function getRelativePath() { + return $this->relativePath; + } - public function getNode() { - return $this->node; - } + public function getNode() { + return $this->node; + } - public function getRemote() { - return $this->remote; - } + public function getRemote() { + return $this->remote; + } - public function setRedirectUrl($redirectUrl) { - $this->redirectUrl = $redirectUrl; - } + public function setRedirectUrl($redirectUrl) { + $this->redirectUrl = $redirectUrl; + } - public function getRedirectUrl() { - return $this->redirectUrl; - } - -} \ No newline at end of file + public function getRedirectUrl() { + return $this->redirectUrl; + } +} diff --git a/lib/Exceptions/ExpiredTokenException.php b/lib/Exceptions/ExpiredTokenException.php index afd909f21..d5963059a 100644 --- a/lib/Exceptions/ExpiredTokenException.php +++ b/lib/Exceptions/ExpiredTokenException.php @@ -22,4 +22,5 @@ */ namespace OCA\Richdocuments\Exceptions; -class ExpiredTokenException extends \Exception {} +class ExpiredTokenException extends \Exception { +} diff --git a/lib/Exceptions/UnknownTokenException.php b/lib/Exceptions/UnknownTokenException.php index c3c802173..2813d7815 100644 --- a/lib/Exceptions/UnknownTokenException.php +++ b/lib/Exceptions/UnknownTokenException.php @@ -22,4 +22,5 @@ */ namespace OCA\Richdocuments\Exceptions; -class UnknownTokenException extends \Exception {} +class UnknownTokenException extends \Exception { +} diff --git a/lib/Helper.php b/lib/Helper.php index 6b96d3a7d..a7a7a22e8 100644 --- a/lib/Helper.php +++ b/lib/Helper.php @@ -36,10 +36,10 @@ class Helper { $fileId = $arr[0]; $instanceId = ''; $version = '0'; - } else if (count($arr) === 2) { + } elseif (count($arr) === 2) { list($fileId, $instanceId) = $arr; $version = '0'; - } else if (count($arr) === 3) { + } elseif (count($arr) === 3) { list($fileId, $instanceId, $version) = $arr; } else { throw new \Exception('$fileId has not the expected format'); @@ -61,12 +61,12 @@ class Helper { * WOPI helper function to convert to ISO 8601 round-trip format. * @param integer $time Must be seconds since unix epoch */ - public static function toISO8601($time) - { + public static function toISO8601($time) { // TODO: Be more precise and don't ignore milli, micro seconds ? $datetime = DateTime::createFromFormat('U', $time, new DateTimeZone('UTC')); - if ($datetime) + if ($datetime) { return $datetime->format('Y-m-d\TH:i:s.u\Z'); + } return false; } @@ -88,5 +88,4 @@ class Helper { } return $_COOKIE['guestUser']; } - } diff --git a/lib/Listener/FileCreatedFromTemplateListener.php b/lib/Listener/FileCreatedFromTemplateListener.php index 661d376f8..524c8884b 100644 --- a/lib/Listener/FileCreatedFromTemplateListener.php +++ b/lib/Listener/FileCreatedFromTemplateListener.php @@ -26,7 +26,6 @@ declare(strict_types=1); namespace OCA\Richdocuments\Listener; - use OCA\Richdocuments\TemplateManager; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; diff --git a/lib/Middleware/WOPIMiddleware.php b/lib/Middleware/WOPIMiddleware.php index 9f6420e9c..74f240d4d 100644 --- a/lib/Middleware/WOPIMiddleware.php +++ b/lib/Middleware/WOPIMiddleware.php @@ -67,14 +67,14 @@ class WOPIMiddleware extends Middleware { public function isWOPIAllowed(): bool { $allowedRanges = $this->config->getAppValue(Application::APPNAME, 'wopi_allowlist'); - if($allowedRanges === '') { + if ($allowedRanges === '') { return true; } $allowedRanges = explode(',', $allowedRanges); $userIp = $this->request->getRemoteAddress(); - foreach($allowedRanges as $range) { - if($this->matchCidr($userIp, $range)) { + foreach ($allowedRanges as $range) { + if ($this->matchCidr($userIp, $range)) { return true; } } @@ -125,7 +125,7 @@ class WOPIMiddleware extends Middleware { $binMask = str_pad($binMask, 32, '0'); $binMask = pack("H*", $binMask); - if ( ($ip & $binMask) === $subnet ) { + if (($ip & $binMask) === $subnet) { return true; } } diff --git a/lib/Migration/Version2060Date20200302131958.php b/lib/Migration/Version2060Date20200302131958.php index 29f90bbda..2d2fe10a5 100644 --- a/lib/Migration/Version2060Date20200302131958.php +++ b/lib/Migration/Version2060Date20200302131958.php @@ -185,5 +185,4 @@ class Version2060Date20200302131958 extends SimpleMigrationStep { } return $schema; } - } diff --git a/lib/Migration/Version2060Date20200302132145.php b/lib/Migration/Version2060Date20200302132145.php index 6663eb633..e570901cf 100644 --- a/lib/Migration/Version2060Date20200302132145.php +++ b/lib/Migration/Version2060Date20200302132145.php @@ -9,8 +9,7 @@ use OCP\DB\ISchemaWrapper; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; -class Version2060Date20200302132145 extends SimpleMigrationStep -{ +class Version2060Date20200302132145 extends SimpleMigrationStep { /** * @param IOutput $output @@ -18,8 +17,7 @@ class Version2060Date20200302132145 extends SimpleMigrationStep * @param array $options * @return null|ISchemaWrapper */ - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) - { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); @@ -33,5 +31,4 @@ class Version2060Date20200302132145 extends SimpleMigrationStep return $schema; } - } diff --git a/lib/Migration/Version30704Date20200626072306.php b/lib/Migration/Version30704Date20200626072306.php index 5219cf9f8..d4b39da8e 100644 --- a/lib/Migration/Version30704Date20200626072306.php +++ b/lib/Migration/Version30704Date20200626072306.php @@ -66,7 +66,6 @@ class Version30704Date20200626072306 extends SimpleMigrationStep { 'notnull' => false, 'default' => '', ]); - } if (!$table->hasColumn('remote_server_token')) { $table->addColumn('remote_server_token', 'string', [ diff --git a/lib/Migration/Version30709Date20201111104147.php b/lib/Migration/Version30709Date20201111104147.php index 201783c69..e8a5151b2 100644 --- a/lib/Migration/Version30709Date20201111104147.php +++ b/lib/Migration/Version30709Date20201111104147.php @@ -10,7 +10,6 @@ use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; class Version30709Date20201111104147 extends SimpleMigrationStep { - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version30717Date20210310164901.php b/lib/Migration/Version30717Date20210310164901.php index 8f4347f12..55d7526ab 100644 --- a/lib/Migration/Version30717Date20210310164901.php +++ b/lib/Migration/Version30717Date20210310164901.php @@ -10,7 +10,6 @@ use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; class Version30717Date20210310164901 extends SimpleMigrationStep { - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); @@ -51,5 +50,4 @@ class Version30717Date20210310164901 extends SimpleMigrationStep { return $schema; } - } diff --git a/lib/PermissionManager.php b/lib/PermissionManager.php index cf1638ef9..501a671f9 100644 --- a/lib/PermissionManager.php +++ b/lib/PermissionManager.php @@ -49,14 +49,14 @@ class PermissionManager { public function isEnabledForUser(IUser $user) { $enabledForGroups = $this->config->getAppValue(Application::APPNAME, 'use_groups', ''); - if($enabledForGroups === '') { + if ($enabledForGroups === '') { return true; } $groups = $this->splitGroups($enabledForGroups); $uid = $user->getUID(); - foreach($groups as $group) { - if($this->groupManager->isInGroup($uid, $group)) { + foreach ($groups as $group) { + if ($this->groupManager->isInGroup($uid, $group)) { return true; } } diff --git a/lib/Preview/Office.php b/lib/Preview/Office.php index f3f8af01f..43edcae30 100644 --- a/lib/Preview/Office.php +++ b/lib/Preview/Office.php @@ -21,8 +21,6 @@ */ namespace OCA\Richdocuments\Preview; -use GuzzleHttp\Psr7\LimitStream; -use function GuzzleHttp\Psr7\stream_for; use OC\Preview\Provider; use OCA\Richdocuments\Capabilities; use OCP\Http\Client\IClientService; @@ -107,7 +105,5 @@ abstract class Office extends Provider { return $image; } return false; - } - } diff --git a/lib/Service/CapabilitiesService.php b/lib/Service/CapabilitiesService.php index 51adc4245..71c169e12 100644 --- a/lib/Service/CapabilitiesService.php +++ b/lib/Service/CapabilitiesService.php @@ -66,7 +66,7 @@ class CapabilitiesService { $isCODEInstalled = $this->appManager->isEnabledForUser($CODEAppID); $isCODEEnabled = strpos($this->config->getAppValue('richdocuments', 'wopi_url'), 'proxy.php?req=') !== false; $shouldRecheckCODECapabilities = $isCODEInstalled && $isCODEEnabled && ($this->capabilities === null || count($this->capabilities) === 0); - if($this->capabilities === null || $shouldRecheckCODECapabilities) { + if ($this->capabilities === null || $shouldRecheckCODECapabilities) { $this->refetch(); } @@ -131,16 +131,15 @@ class CapabilitiesService { if (!is_array($capabilities)) { $capabilities = []; } - - } catch (\Exception $e) { $capabilities = []; } $this->capabilities = $capabilities; $ttl = 3600; - if (count($capabilities) === 0) + if (count($capabilities) === 0) { $ttl = 60; + } $this->cache->set('capabilities', $capabilities, $ttl); } diff --git a/lib/Service/DemoService.php b/lib/Service/DemoService.php index f0e0bf7f8..d2d61724d 100644 --- a/lib/Service/DemoService.php +++ b/lib/Service/DemoService.php @@ -58,5 +58,4 @@ class DemoService { $this->cache->set('richdocuments-demo', json_encode($servers)); return $servers; } - } diff --git a/lib/Service/FederationService.php b/lib/Service/FederationService.php index ac541f54f..403df2c11 100644 --- a/lib/Service/FederationService.php +++ b/lib/Service/FederationService.php @@ -23,7 +23,6 @@ namespace OCA\Richdocuments\Service; - use OCA\Federation\TrustedServers; use OCA\Files_Sharing\External\Storage as SharingExternalStorage; use OCA\Richdocuments\AppConfig; @@ -70,8 +69,9 @@ class FederationService { $this->request = $request; $this->urlGenerator = $urlGenerator; try { - $this->trustedServers = \OC::$server->query( \OCA\Federation\TrustedServers::class); - } catch (QueryException $e) {} + $this->trustedServers = \OC::$server->query(\OCA\Federation\TrustedServers::class); + } catch (QueryException $e) { + } } /** @@ -128,8 +128,8 @@ class FederationService { break; } $regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function ($v) { - return preg_quote($v, '/'); - }, explode('*', $trusted))) . '$/i'; + return preg_quote($v, '/'); + }, explode('*', $trusted))) . '$/i'; if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) { return true; } diff --git a/lib/Service/FontService.php b/lib/Service/FontService.php index eeaa6c68e..9a4d8d864 100644 --- a/lib/Service/FontService.php +++ b/lib/Service/FontService.php @@ -23,7 +23,6 @@ namespace OCA\Richdocuments\Service; - use OCA\Richdocuments\AppInfo\Application; use OCP\Files\IAppData; use OCP\Files\NotFoundException; diff --git a/lib/Service/UserScopeService.php b/lib/Service/UserScopeService.php index ba2c19e26..b85899326 100644 --- a/lib/Service/UserScopeService.php +++ b/lib/Service/UserScopeService.php @@ -23,12 +23,10 @@ namespace OCA\Richdocuments\Service; - use OCP\IUserManager; use OCP\IUserSession; class UserScopeService { - public function __construct(IUserSession $userSession, IUserManager $userManager) { $this->userSession = $userSession; $this->userManager = $userManager; diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index bbff9d9e2..fa89f953b 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -66,7 +66,7 @@ class Admin implements ISettings { FontService $fontService, InitialStateService $initialStateService ) { - $this->config = $config; + $this->config = $config; $this->appConfig = $appConfig; $this->manager = $manager; $this->capabilitiesService = $capabilitiesService; @@ -82,15 +82,15 @@ class Admin implements ISettings { 'admin', [ 'settings' => [ - 'wopi_url' => $this->config->getAppValue('richdocuments', 'wopi_url'), - 'wopi_allowlist' => $this->config->getAppValue('richdocuments', 'wopi_allowlist'), - 'edit_groups' => $this->config->getAppValue('richdocuments', 'edit_groups'), - 'use_groups' => $this->config->getAppValue('richdocuments', 'use_groups'), - 'doc_format' => $this->config->getAppValue('richdocuments', 'doc_format'), - 'external_apps' => $this->config->getAppValue('richdocuments', 'external_apps'), - 'canonical_webroot' => $this->config->getAppValue('richdocuments', 'canonical_webroot'), + 'wopi_url' => $this->config->getAppValue('richdocuments', 'wopi_url'), + 'wopi_allowlist' => $this->config->getAppValue('richdocuments', 'wopi_allowlist'), + 'edit_groups' => $this->config->getAppValue('richdocuments', 'edit_groups'), + 'use_groups' => $this->config->getAppValue('richdocuments', 'use_groups'), + 'doc_format' => $this->config->getAppValue('richdocuments', 'doc_format'), + 'external_apps' => $this->config->getAppValue('richdocuments', 'external_apps'), + 'canonical_webroot' => $this->config->getAppValue('richdocuments', 'canonical_webroot'), 'disable_certificate_verification' => $this->config->getAppValue('richdocuments', 'disable_certificate_verification', '') === 'yes', - 'templates' => $this->manager->getSystemFormatted(), + 'templates' => $this->manager->getSystemFormatted(), 'templatesAvailable' => $this->capabilitiesService->hasTemplateSaveAs() || $this->capabilitiesService->hasTemplateSource(), 'settings' => $this->appConfig->getAppSettings(), 'demo_servers' => $this->demoService->fetchDemoServers(), @@ -111,5 +111,4 @@ class Admin implements ISettings { public function getPriority() { return 0; } - } diff --git a/lib/Template/CollaboraTemplateProvider.php b/lib/Template/CollaboraTemplateProvider.php index e7abad9dc..8e0ee08d7 100644 --- a/lib/Template/CollaboraTemplateProvider.php +++ b/lib/Template/CollaboraTemplateProvider.php @@ -26,14 +26,12 @@ declare(strict_types=1); namespace OCA\Richdocuments\Template; - use OCA\Richdocuments\TemplateManager; use OCP\Files\File; use OCP\Files\NotFoundException; use OCP\Files\Template\ICustomTemplateProvider; use OCP\Files\Template\ITemplateManager; use OCP\Files\Template\Template; -use OCP\Files\Template\TemplateFileCreator; use OCP\IURLGenerator; class CollaboraTemplateProvider implements ICustomTemplateProvider { @@ -70,7 +68,7 @@ class CollaboraTemplateProvider implements ICustomTemplateProvider { $collaboraTemplates = $this->isSameUserTemplateFolder() ? $this->templateManager->getSystem($type) : $this->templateManager->getAll($type); - return array_map(function(File $file) { + return array_map(function (File $file) { $template = new Template(CollaboraTemplateProvider::class, (string)$file->getId(), $file); $template->setCustomPreviewUrl($this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.getPreview', ['fileId' => $file->getId()])); return $template; diff --git a/lib/TemplateManager.php b/lib/TemplateManager.php index 798b5164e..e11be635e 100644 --- a/lib/TemplateManager.php +++ b/lib/TemplateManager.php @@ -1,5 +1,6 @@ * @@ -66,43 +67,43 @@ class TemplateManager { private $logger; /** Accepted templates mime types */ - const MIMES_DOCUMENTS = [ + public const MIMES_DOCUMENTS = [ 'application/vnd.oasis.opendocument.text-template', 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', 'application/msword' ]; - const MIMES_SHEETS = [ + public const MIMES_SHEETS = [ 'application/vnd.oasis.opendocument.spreadsheet-template', 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', 'application/vnd.ms-excel' ]; - const MIMES_PRESENTATIONS = [ + public const MIMES_PRESENTATIONS = [ 'application/vnd.oasis.opendocument.presentation-template', 'application/vnd.openxmlformats-officedocument.presentationml.template', 'application/vnd.ms-powerpoint' ]; - const MIMES_DRAWINGS = [ + public const MIMES_DRAWINGS = [ 'application/vnd.oasis.opendocument.graphics-template', ]; /** @var array Template mime types match */ - static public $tplTypes = [ - 'document' => self::MIMES_DOCUMENTS, - 'spreadsheet' => self::MIMES_SHEETS, + public static $tplTypes = [ + 'document' => self::MIMES_DOCUMENTS, + 'spreadsheet' => self::MIMES_SHEETS, 'presentation' => self::MIMES_PRESENTATIONS, - 'drawing' => self::MIMES_DRAWINGS, + 'drawing' => self::MIMES_DRAWINGS, ]; - const TYPE_EXTENTION = [ - 'document' => 'odt', - 'spreadsheet' => 'ods', + public const TYPE_EXTENTION = [ + 'document' => 'odt', + 'spreadsheet' => 'ods', 'presentation' => 'odp', - 'drawing' => 'odg', + 'drawing' => 'odg', ]; - const TYPE_EXTENSION_OOXML = [ - 'document' => 'docx', - 'spreadsheet' => 'xlsx', + public const TYPE_EXTENSION_OOXML = [ + 'document' => 'docx', + 'spreadsheet' => 'xlsx', 'presentation' => 'pptx', ]; @@ -272,11 +273,11 @@ class TemplateManager { $empty = $this->getEmpty($type); $system = $this->getSystem($type); - $emptyFormatted = array_map(function(File $file) { + $emptyFormatted = array_map(function (File $file) { return $this->formatEmpty($file); }, $empty); - $systemFormatted = array_map(function(File $file) { + $systemFormatted = array_map(function (File $file) { return $this->formatNodeReturn($file); }, $system); @@ -290,11 +291,11 @@ class TemplateManager { */ public function getUser($type = null) { try { - $templateDir = $this->getUserTemplateDir(); + $templateDir = $this->getUserTemplateDir(); $templateFiles = $templateDir->getDirectoryListing(); return $this->filterTemplates($templateFiles, $type); - } catch(NotFoundException $e) { + } catch (NotFoundException $e) { return []; } } @@ -305,7 +306,7 @@ class TemplateManager { public function getUserFormatted($type) { $templates = $this->getUser($type); - return array_map(function(File $file) { + return array_map(function (File $file) { return $this->formatNodeReturn($file); }, $templates); } @@ -317,7 +318,7 @@ class TemplateManager { */ public function getAll($type = 'document') { $system = $this->getSystem(); - $user = $this->getUser(); + $user = $this->getUser(); if (!array_key_exists($type, self::$tplTypes)) { return []; @@ -339,7 +340,7 @@ class TemplateManager { } $system = $this->getSystemFormatted($type); - $user = $this->getUserFormatted($type); + $user = $this->getUserFormatted($type); return array_merge($system, $user); } @@ -458,11 +459,11 @@ class TemplateManager { $ooxml = $this->config->getAppValue(Application::APPNAME, 'doc_format', '') === 'ooxml'; $documentType = $this->flipTypes()[$template->getMimeType()]; return [ - 'id' => $template->getId(), - 'name' => $template->getName(), - 'preview' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.getPreview', ['fileId' => $template->getId()]), - 'type' => $this->flipTypes()[$template->getMimeType()], - 'delete' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.delete', ['fileId' => $template->getId()]), + 'id' => $template->getId(), + 'name' => $template->getName(), + 'preview' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.getPreview', ['fileId' => $template->getId()]), + 'type' => $this->flipTypes()[$template->getMimeType()], + 'delete' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.delete', ['fileId' => $template->getId()]), 'extension' => ($ooxml && isset(self::TYPE_EXTENSION_OOXML[$documentType])) ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType], ]; } @@ -487,9 +488,9 @@ class TemplateManager { $ooxml = $this->config->getAppValue(Application::APPNAME, 'doc_format', '') === 'ooxml'; $documentType = $this->flipTypes()[$template->getMimeType()]; return [ - 'id' => $template->getId(), - 'name' => $this->l->t('Empty'), - 'type' => $this->flipTypes()[$template->getMimeType()], + 'id' => $template->getId(), + 'name' => $this->l->t('Empty'), + 'type' => $this->flipTypes()[$template->getMimeType()], 'extension' => ($ooxml && isset(self::TYPE_EXTENSION_OOXML[$documentType])) ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType], ]; } diff --git a/lib/TokenManager.php b/lib/TokenManager.php index e513f17c5..95a81081a 100644 --- a/lib/TokenManager.php +++ b/lib/TokenManager.php @@ -21,18 +21,14 @@ namespace OCA\Richdocuments; -use InvalidArgumentException; use OC\Files\Filesystem; use OCA\Richdocuments\Db\Direct; use OCA\Richdocuments\Db\WopiMapper; use OCA\Richdocuments\Db\Wopi; use OCA\Richdocuments\Service\CapabilitiesService; use OCA\Richdocuments\WOPI\Parser; -use OCP\AppFramework\Db\DoesNotExistException; -use OCP\AppFramework\Http\DataResponse; use OCP\Constants; use OCP\Files\File; -use OCP\Files\ForbiddenException; use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\IGroupManager; @@ -41,7 +37,6 @@ use OCP\IUserManager; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager; use OCP\IL10N; -use OCP\Share\IShare; use OCP\Util; class TokenManager { @@ -122,7 +117,7 @@ class TokenManager { $updatable = (bool)($share->getPermissions() & \OCP\Constants::PERMISSION_UPDATE); $hideDownload = $share->getHideDownload(); $owneruid = $share->getShareOwner(); - } else if ($this->userId !== null) { + } elseif ($this->userId !== null) { try { $editoruid = $this->userId; $rootFolder = $this->rootFolder->getUserFolder($editoruid); @@ -176,7 +171,6 @@ class TokenManager { } } } - } /** @var File $file */ $file = $rootFolder->getById($fileId)[0]; @@ -263,7 +257,7 @@ class TokenManager { $editorUser = $this->userManager->get($editoruid); if ($updatable && count($editGroups) > 0 && $editorUser) { $updatable = false; - foreach($editGroups as $editGroup) { + foreach ($editGroups as $editGroup) { $editorGroup = $this->groupManager->get($editGroup); if ($editorGroup !== null && $editorGroup->inGroup($editorUser)) { $updatable = true; @@ -335,5 +329,4 @@ class TokenManager { $wopi->setGuestDisplayname($this->prepareGuestName($guestName)); $this->wopiMapper->update($wopi); } - } diff --git a/lib/WOPI/DiscoveryManager.php b/lib/WOPI/DiscoveryManager.php index bcc103d84..6b53d213e 100644 --- a/lib/WOPI/DiscoveryManager.php +++ b/lib/WOPI/DiscoveryManager.php @@ -77,8 +77,9 @@ class DiscoveryManager { $options['verify'] = false; } - if ($this->isProxyStarting($wopiDiscovery)) + if ($this->isProxyStarting($wopiDiscovery)) { $options['timeout'] = 180; + } try { return $client->get($wopiDiscovery, $options); @@ -98,10 +99,11 @@ class DiscoveryManager { private function isProxyStarting($url) { $usesProxy = false; $proxyPos = strrpos($url, 'proxy.php'); - if ($proxyPos === false) + if ($proxyPos === false) { $usesProxy = false; - else + } else { $usesProxy = true; + } if ($usesProxy === true) { $statusUrl = substr($url, 0, $proxyPos); diff --git a/lib/WOPI/Parser.php b/lib/WOPI/Parser.php index ed0fb67dc..2a99252ff 100644 --- a/lib/WOPI/Parser.php +++ b/lib/WOPI/Parser.php @@ -57,7 +57,5 @@ class Parser { } throw new \Exception('Could not find urlsrc in WOPI'); - } - -} \ No newline at end of file +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9533ead2e..2837726af 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -6,7 +6,7 @@ if (!defined('PHPUNIT_RUN')) { require_once __DIR__.'/../../../lib/base.php'; -if(!class_exists('\PHPUnit\Framework\TestCase')) { +if (!class_exists('\PHPUnit\Framework\TestCase')) { require_once('PHPUnit/Autoload.php'); } \OC_App::loadApp('richdocuments'); diff --git a/tests/features/bootstrap/DirectContext.php b/tests/features/bootstrap/DirectContext.php index 4662d35d8..8be661fda 100644 --- a/tests/features/bootstrap/DirectContext.php +++ b/tests/features/bootstrap/DirectContext.php @@ -212,5 +212,4 @@ class DirectContext implements Context { } $this->serverContext->sendOCSRequest('POST', 'apps/richdocuments/api/v1/share', $data, $options); } - } diff --git a/tests/features/bootstrap/FederationContext.php b/tests/features/bootstrap/FederationContext.php index ae9ae6c33..2184058e2 100644 --- a/tests/features/bootstrap/FederationContext.php +++ b/tests/features/bootstrap/FederationContext.php @@ -74,5 +74,4 @@ class FederationContext implements Context { $table ); } - } diff --git a/tests/features/bootstrap/RichDocumentsContext.php b/tests/features/bootstrap/RichDocumentsContext.php index 20cf8bf46..12bafbfff 100644 --- a/tests/features/bootstrap/RichDocumentsContext.php +++ b/tests/features/bootstrap/RichDocumentsContext.php @@ -1,4 +1,5 @@ serverContext->usingWebAsUser($user); $davClient = $this->filesContext->getSabreClient($user); $path = $this->filesContext->makeSabrePath($user, $file); @@ -78,24 +77,21 @@ class RichDocumentsContext implements Context /** * @Then a guest opens the share link */ - public function aGuestOpensTheShareLink() - { + public function aGuestOpensTheShareLink() { $this->aGuestOpensTheShareLinkAs(); } /** * @Then a guest opens the share link as :guestName */ - public function aGuestOpensTheShareLinkAs($guestName = null) - { + public function aGuestOpensTheShareLinkAs($guestName = null) { $this->openTheShareLink(null, $guestName); } /** * @Then the user opens the share link */ - public function aUserOpensTheShareLink() - { + public function aUserOpensTheShareLink() { $this->openTheShareLink($this->serverContext->getAuth()[0], null); } diff --git a/tests/features/bootstrap/WopiContext.php b/tests/features/bootstrap/WopiContext.php index f2ce2d1d2..9f83a40fd 100644 --- a/tests/features/bootstrap/WopiContext.php +++ b/tests/features/bootstrap/WopiContext.php @@ -48,8 +48,7 @@ class WopiContext implements Context { private $wopiToken; private $checkFileInfoResult; - public function __construct() - { + public function __construct() { $this->downloadedFile = tempnam(sys_get_temp_dir(), 'downloadedFile'); } @@ -91,8 +90,7 @@ class WopiContext implements Context { /** * @Then /^Collabora saved the file with the content of "([^"]*)"$/ */ - public function collaboraPuts($source) - { + public function collaboraPuts($source) { $file = Utils::streamFor(fopen($source, 'r')); $client = new Client(); $options = [ @@ -133,8 +131,7 @@ class WopiContext implements Context { /** * @Then /^checkFileInfo "([^"]*)" is "([^"]*)"$/ */ - public function checkfileinfoIs($key, $value) - { + public function checkfileinfoIs($key, $value) { \PHPUnit\Framework\Assert::assertEquals($value, $this->checkFileInfoResult[$key]); } @@ -142,32 +139,28 @@ class WopiContext implements Context { /** * @Then /^checkFileInfo "([^"]*)" matches "([^"]*)"$/ */ - public function checkfileinfoMatches($key, $regex) - { + public function checkfileinfoMatches($key, $regex) { \PHPUnit\Framework\Assert::assertRegExp($regex, $this->checkFileInfoResult[$key]); } /** * @Then /^checkFileInfo "([^"]*)" is true$/ */ - public function checkfileinfoIsTrue($key) - { + public function checkfileinfoIsTrue($key) { \PHPUnit\Framework\Assert::assertTrue($this->checkFileInfoResult[$key]); } /** * @Then /^checkFileInfo "([^"]*)" is false$/ */ - public function checkfileinfoIsFalse($key) - { + public function checkfileinfoIsFalse($key) { \PHPUnit\Framework\Assert::assertFalse($this->checkFileInfoResult[$key]); } /** * @Then /^checkFileInfo "([^"]*)" is not set/ */ - public function checkfileinfoIsNotSet($key) - { + public function checkfileinfoIsNotSet($key) { \PHPUnit\Framework\Assert::assertArrayNotHasKey($key, $this->checkFileInfoResult); } @@ -255,8 +248,8 @@ class WopiContext implements Context { if (count($this->fileIds) <= 1) { throw new \Exception('Less than two file ids available for comparison'); } - $current = $this->fileIds[count($this->fileIds)-1]; - $previous = $this->fileIds[count($this->fileIds)-2]; + $current = $this->fileIds[count($this->fileIds) - 1]; + $previous = $this->fileIds[count($this->fileIds) - 2]; Assert::assertEquals($current, $previous); } @@ -267,8 +260,8 @@ class WopiContext implements Context { if (count($this->fileIds) <= 1) { throw new \Exception('Less than two file ids available for comparison'); } - $current = $this->fileIds[count($this->fileIds)-1]; - $previous = $this->fileIds[count($this->fileIds)-2]; + $current = $this->fileIds[count($this->fileIds) - 1]; + $previous = $this->fileIds[count($this->fileIds) - 2]; Assert::assertNotEquals($current, $previous); } @@ -293,5 +286,4 @@ class WopiContext implements Context { $this->response = $e->getResponse(); } } - }