Completed
Push — master ( 5ca5eb...afb5d4 )
by Lukas
16:52
created
core/Command/Maintenance/Install.php 1 patch
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -40,152 +40,152 @@
 block discarded – undo
40 40
 
41 41
 class Install extends Command {
42 42
 
43
-	/**
44
-	 * @var SystemConfig
45
-	 */
46
-	private $config;
47
-
48
-	public function __construct(SystemConfig $config) {
49
-		parent::__construct();
50
-		$this->config = $config;
51
-	}
52
-
53
-	protected function configure() {
54
-		$this
55
-			->setName('maintenance:install')
56
-			->setDescription('install Nextcloud')
57
-			->addOption('database', null, InputOption::VALUE_REQUIRED, 'Supported database type', 'sqlite')
58
-			->addOption('database-name', null, InputOption::VALUE_REQUIRED, 'Name of the database')
59
-			->addOption('database-host', null, InputOption::VALUE_REQUIRED, 'Hostname of the database', 'localhost')
60
-			->addOption('database-port', null, InputOption::VALUE_REQUIRED, 'Port the database is listening on')
61
-			->addOption('database-user', null, InputOption::VALUE_REQUIRED, 'User name to connect to the database')
62
-			->addOption('database-pass', null, InputOption::VALUE_OPTIONAL, 'Password of the database user', null)
63
-			->addOption('database-table-prefix', null, InputOption::VALUE_OPTIONAL, 'Prefix for all tables (default: oc_)', null)
64
-			->addOption('admin-user', null, InputOption::VALUE_REQUIRED, 'User name of the admin account', 'admin')
65
-			->addOption('admin-pass', null, InputOption::VALUE_REQUIRED, 'Password of the admin account')
66
-			->addOption('data-dir', null, InputOption::VALUE_REQUIRED, 'Path to data directory', \OC::$SERVERROOT."/data");
67
-	}
68
-
69
-	protected function execute(InputInterface $input, OutputInterface $output) {
70
-
71
-		// validate the environment
72
-		$server = \OC::$server;
73
-		$setupHelper = new Setup($this->config, $server->getIniWrapper(),
74
-			$server->getL10N('lib'), $server->query(Defaults::class), $server->getLogger(),
75
-			$server->getSecureRandom());
76
-		$sysInfo = $setupHelper->getSystemInfo(true);
77
-		$errors = $sysInfo['errors'];
78
-		if (count($errors) > 0) {
79
-			$this->printErrors($output, $errors);
80
-
81
-			// ignore the OS X setup warning
82
-			if(count($errors) !== 1 ||
83
-				(string)($errors[0]['error']) !== 'Mac OS X is not supported and Nextcloud will not work properly on this platform. Use it at your own risk! ') {
84
-				return 1;
85
-			}
86
-		}
87
-
88
-		// validate user input
89
-		$options = $this->validateInput($input, $output, array_keys($sysInfo['databases']));
90
-
91
-		// perform installation
92
-		$errors = $setupHelper->install($options);
93
-		if (count($errors) > 0) {
94
-			$this->printErrors($output, $errors);
95
-			return 1;
96
-		}
97
-		$output->writeln("Nextcloud was successfully installed");
98
-		return 0;
99
-	}
100
-
101
-	/**
102
-	 * @param InputInterface $input
103
-	 * @param OutputInterface $output
104
-	 * @param string[] $supportedDatabases
105
-	 * @return array
106
-	 */
107
-	protected function validateInput(InputInterface $input, OutputInterface $output, $supportedDatabases) {
108
-		$db = strtolower($input->getOption('database'));
109
-
110
-		if (!in_array($db, $supportedDatabases)) {
111
-			throw new InvalidArgumentException("Database <$db> is not supported.");
112
-		}
113
-
114
-		$dbUser = $input->getOption('database-user');
115
-		$dbPass = $input->getOption('database-pass');
116
-		$dbName = $input->getOption('database-name');
117
-		$dbPort = $input->getOption('database-port');
118
-		if ($db === 'oci') {
119
-			// an empty hostname needs to be read from the raw parameters
120
-			$dbHost = $input->getParameterOption('--database-host', '');
121
-		} else {
122
-			$dbHost = $input->getOption('database-host');
123
-		}
124
-		$dbTablePrefix = 'oc_';
125
-		if ($input->hasParameterOption('--database-table-prefix')) {
126
-			$dbTablePrefix = (string) $input->getOption('database-table-prefix');
127
-			$dbTablePrefix = trim($dbTablePrefix);
128
-		}
129
-		if ($input->hasParameterOption('--database-pass')) {
130
-			$dbPass = (string) $input->getOption('database-pass');
131
-		}
132
-		$adminLogin = $input->getOption('admin-user');
133
-		$adminPassword = $input->getOption('admin-pass');
134
-		$dataDir = $input->getOption('data-dir');
135
-
136
-		if ($db !== 'sqlite') {
137
-			if (is_null($dbUser)) {
138
-				throw new InvalidArgumentException("Database user not provided.");
139
-			}
140
-			if (is_null($dbName)) {
141
-				throw new InvalidArgumentException("Database name not provided.");
142
-			}
143
-			if (is_null($dbPass)) {
144
-				/** @var QuestionHelper $helper */
145
-				$helper = $this->getHelper('question');
146
-				$question = new Question('What is the password to access the database with user <'.$dbUser.'>?');
147
-				$question->setHidden(true);
148
-				$question->setHiddenFallback(false);
149
-				$dbPass = $helper->ask($input, $output, $question);
150
-			}
151
-		}
152
-
153
-		if (is_null($adminPassword)) {
154
-			/** @var QuestionHelper $helper */
155
-			$helper = $this->getHelper('question');
156
-			$question = new Question('What is the password you like to use for the admin account <'.$adminLogin.'>?');
157
-			$question->setHidden(true);
158
-			$question->setHiddenFallback(false);
159
-			$adminPassword = $helper->ask($input, $output, $question);
160
-		}
161
-
162
-		$options = [
163
-			'dbtype' => $db,
164
-			'dbuser' => $dbUser,
165
-			'dbpass' => $dbPass,
166
-			'dbname' => $dbName,
167
-			'dbhost' => $dbHost,
168
-			'dbport' => $dbPort,
169
-			'dbtableprefix' => $dbTablePrefix,
170
-			'adminlogin' => $adminLogin,
171
-			'adminpass' => $adminPassword,
172
-			'directory' => $dataDir
173
-		];
174
-		return $options;
175
-	}
176
-
177
-	/**
178
-	 * @param OutputInterface $output
179
-	 * @param $errors
180
-	 */
181
-	protected function printErrors(OutputInterface $output, $errors) {
182
-		foreach ($errors as $error) {
183
-			if (is_array($error)) {
184
-				$output->writeln('<error>' . (string)$error['error'] . '</error>');
185
-				$output->writeln('<info> -> ' . (string)$error['hint'] . '</info>');
186
-			} else {
187
-				$output->writeln('<error>' . (string)$error . '</error>');
188
-			}
189
-		}
190
-	}
43
+    /**
44
+     * @var SystemConfig
45
+     */
46
+    private $config;
47
+
48
+    public function __construct(SystemConfig $config) {
49
+        parent::__construct();
50
+        $this->config = $config;
51
+    }
52
+
53
+    protected function configure() {
54
+        $this
55
+            ->setName('maintenance:install')
56
+            ->setDescription('install Nextcloud')
57
+            ->addOption('database', null, InputOption::VALUE_REQUIRED, 'Supported database type', 'sqlite')
58
+            ->addOption('database-name', null, InputOption::VALUE_REQUIRED, 'Name of the database')
59
+            ->addOption('database-host', null, InputOption::VALUE_REQUIRED, 'Hostname of the database', 'localhost')
60
+            ->addOption('database-port', null, InputOption::VALUE_REQUIRED, 'Port the database is listening on')
61
+            ->addOption('database-user', null, InputOption::VALUE_REQUIRED, 'User name to connect to the database')
62
+            ->addOption('database-pass', null, InputOption::VALUE_OPTIONAL, 'Password of the database user', null)
63
+            ->addOption('database-table-prefix', null, InputOption::VALUE_OPTIONAL, 'Prefix for all tables (default: oc_)', null)
64
+            ->addOption('admin-user', null, InputOption::VALUE_REQUIRED, 'User name of the admin account', 'admin')
65
+            ->addOption('admin-pass', null, InputOption::VALUE_REQUIRED, 'Password of the admin account')
66
+            ->addOption('data-dir', null, InputOption::VALUE_REQUIRED, 'Path to data directory', \OC::$SERVERROOT."/data");
67
+    }
68
+
69
+    protected function execute(InputInterface $input, OutputInterface $output) {
70
+
71
+        // validate the environment
72
+        $server = \OC::$server;
73
+        $setupHelper = new Setup($this->config, $server->getIniWrapper(),
74
+            $server->getL10N('lib'), $server->query(Defaults::class), $server->getLogger(),
75
+            $server->getSecureRandom());
76
+        $sysInfo = $setupHelper->getSystemInfo(true);
77
+        $errors = $sysInfo['errors'];
78
+        if (count($errors) > 0) {
79
+            $this->printErrors($output, $errors);
80
+
81
+            // ignore the OS X setup warning
82
+            if(count($errors) !== 1 ||
83
+                (string)($errors[0]['error']) !== 'Mac OS X is not supported and Nextcloud will not work properly on this platform. Use it at your own risk! ') {
84
+                return 1;
85
+            }
86
+        }
87
+
88
+        // validate user input
89
+        $options = $this->validateInput($input, $output, array_keys($sysInfo['databases']));
90
+
91
+        // perform installation
92
+        $errors = $setupHelper->install($options);
93
+        if (count($errors) > 0) {
94
+            $this->printErrors($output, $errors);
95
+            return 1;
96
+        }
97
+        $output->writeln("Nextcloud was successfully installed");
98
+        return 0;
99
+    }
100
+
101
+    /**
102
+     * @param InputInterface $input
103
+     * @param OutputInterface $output
104
+     * @param string[] $supportedDatabases
105
+     * @return array
106
+     */
107
+    protected function validateInput(InputInterface $input, OutputInterface $output, $supportedDatabases) {
108
+        $db = strtolower($input->getOption('database'));
109
+
110
+        if (!in_array($db, $supportedDatabases)) {
111
+            throw new InvalidArgumentException("Database <$db> is not supported.");
112
+        }
113
+
114
+        $dbUser = $input->getOption('database-user');
115
+        $dbPass = $input->getOption('database-pass');
116
+        $dbName = $input->getOption('database-name');
117
+        $dbPort = $input->getOption('database-port');
118
+        if ($db === 'oci') {
119
+            // an empty hostname needs to be read from the raw parameters
120
+            $dbHost = $input->getParameterOption('--database-host', '');
121
+        } else {
122
+            $dbHost = $input->getOption('database-host');
123
+        }
124
+        $dbTablePrefix = 'oc_';
125
+        if ($input->hasParameterOption('--database-table-prefix')) {
126
+            $dbTablePrefix = (string) $input->getOption('database-table-prefix');
127
+            $dbTablePrefix = trim($dbTablePrefix);
128
+        }
129
+        if ($input->hasParameterOption('--database-pass')) {
130
+            $dbPass = (string) $input->getOption('database-pass');
131
+        }
132
+        $adminLogin = $input->getOption('admin-user');
133
+        $adminPassword = $input->getOption('admin-pass');
134
+        $dataDir = $input->getOption('data-dir');
135
+
136
+        if ($db !== 'sqlite') {
137
+            if (is_null($dbUser)) {
138
+                throw new InvalidArgumentException("Database user not provided.");
139
+            }
140
+            if (is_null($dbName)) {
141
+                throw new InvalidArgumentException("Database name not provided.");
142
+            }
143
+            if (is_null($dbPass)) {
144
+                /** @var QuestionHelper $helper */
145
+                $helper = $this->getHelper('question');
146
+                $question = new Question('What is the password to access the database with user <'.$dbUser.'>?');
147
+                $question->setHidden(true);
148
+                $question->setHiddenFallback(false);
149
+                $dbPass = $helper->ask($input, $output, $question);
150
+            }
151
+        }
152
+
153
+        if (is_null($adminPassword)) {
154
+            /** @var QuestionHelper $helper */
155
+            $helper = $this->getHelper('question');
156
+            $question = new Question('What is the password you like to use for the admin account <'.$adminLogin.'>?');
157
+            $question->setHidden(true);
158
+            $question->setHiddenFallback(false);
159
+            $adminPassword = $helper->ask($input, $output, $question);
160
+        }
161
+
162
+        $options = [
163
+            'dbtype' => $db,
164
+            'dbuser' => $dbUser,
165
+            'dbpass' => $dbPass,
166
+            'dbname' => $dbName,
167
+            'dbhost' => $dbHost,
168
+            'dbport' => $dbPort,
169
+            'dbtableprefix' => $dbTablePrefix,
170
+            'adminlogin' => $adminLogin,
171
+            'adminpass' => $adminPassword,
172
+            'directory' => $dataDir
173
+        ];
174
+        return $options;
175
+    }
176
+
177
+    /**
178
+     * @param OutputInterface $output
179
+     * @param $errors
180
+     */
181
+    protected function printErrors(OutputInterface $output, $errors) {
182
+        foreach ($errors as $error) {
183
+            if (is_array($error)) {
184
+                $output->writeln('<error>' . (string)$error['error'] . '</error>');
185
+                $output->writeln('<info> -> ' . (string)$error['hint'] . '</info>');
186
+            } else {
187
+                $output->writeln('<error>' . (string)$error . '</error>');
188
+            }
189
+        }
190
+    }
191 191
 }
Please login to merge, or discard this patch.
settings/Application.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -49,84 +49,84 @@
 block discarded – undo
49 49
 class Application extends App {
50 50
 
51 51
 
52
-	/**
53
-	 * @param array $urlParams
54
-	 */
55
-	public function __construct(array $urlParams=[]){
56
-		parent::__construct('settings', $urlParams);
52
+    /**
53
+     * @param array $urlParams
54
+     */
55
+    public function __construct(array $urlParams=[]){
56
+        parent::__construct('settings', $urlParams);
57 57
 
58
-		$container = $this->getContainer();
58
+        $container = $this->getContainer();
59 59
 
60
-		// Register Middleware
61
-		$container->registerAlias('SubadminMiddleware', SubadminMiddleware::class);
62
-		$container->registerMiddleWare('SubadminMiddleware');
60
+        // Register Middleware
61
+        $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class);
62
+        $container->registerMiddleWare('SubadminMiddleware');
63 63
 
64
-		/**
65
-		 * Core class wrappers
66
-		 */
67
-		/** FIXME: Remove once OC_User is non-static and mockable */
68
-		$container->registerService('isAdmin', function() {
69
-			return \OC_User::isAdminUser(\OC_User::getUser());
70
-		});
71
-		/** FIXME: Remove once OC_SubAdmin is non-static and mockable */
72
-		$container->registerService('isSubAdmin', function(IContainer $c) {
73
-			$userObject = \OC::$server->getUserSession()->getUser();
74
-			$isSubAdmin = false;
75
-			if($userObject !== null) {
76
-				$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
77
-			}
78
-			return $isSubAdmin;
79
-		});
80
-		$container->registerService('userCertificateManager', function(IContainer $c) {
81
-			return $c->query('ServerContainer')->getCertificateManager();
82
-		}, false);
83
-		$container->registerService('systemCertificateManager', function (IContainer $c) {
84
-			return $c->query('ServerContainer')->getCertificateManager(null);
85
-		}, false);
86
-		$container->registerService(IProvider::class, function (IContainer $c) {
87
-			return $c->query('ServerContainer')->query(IProvider::class);
88
-		});
89
-		$container->registerService(IManager::class, function (IContainer $c) {
90
-			return $c->query('ServerContainer')->getSettingsManager();
91
-		});
64
+        /**
65
+         * Core class wrappers
66
+         */
67
+        /** FIXME: Remove once OC_User is non-static and mockable */
68
+        $container->registerService('isAdmin', function() {
69
+            return \OC_User::isAdminUser(\OC_User::getUser());
70
+        });
71
+        /** FIXME: Remove once OC_SubAdmin is non-static and mockable */
72
+        $container->registerService('isSubAdmin', function(IContainer $c) {
73
+            $userObject = \OC::$server->getUserSession()->getUser();
74
+            $isSubAdmin = false;
75
+            if($userObject !== null) {
76
+                $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
77
+            }
78
+            return $isSubAdmin;
79
+        });
80
+        $container->registerService('userCertificateManager', function(IContainer $c) {
81
+            return $c->query('ServerContainer')->getCertificateManager();
82
+        }, false);
83
+        $container->registerService('systemCertificateManager', function (IContainer $c) {
84
+            return $c->query('ServerContainer')->getCertificateManager(null);
85
+        }, false);
86
+        $container->registerService(IProvider::class, function (IContainer $c) {
87
+            return $c->query('ServerContainer')->query(IProvider::class);
88
+        });
89
+        $container->registerService(IManager::class, function (IContainer $c) {
90
+            return $c->query('ServerContainer')->getSettingsManager();
91
+        });
92 92
 
93
-		$container->registerService(NewUserMailHelper::class, function (IContainer $c) {
94
-			/** @var Server $server */
95
-			$server = $c->query('ServerContainer');
96
-			/** @var Defaults $defaults */
97
-			$defaults = $server->query(Defaults::class);
93
+        $container->registerService(NewUserMailHelper::class, function (IContainer $c) {
94
+            /** @var Server $server */
95
+            $server = $c->query('ServerContainer');
96
+            /** @var Defaults $defaults */
97
+            $defaults = $server->query(Defaults::class);
98 98
 
99
-			return new NewUserMailHelper(
100
-				$defaults,
101
-				$server->getURLGenerator(),
102
-				$server->getL10N('settings'),
103
-				$server->getMailer(),
104
-				$server->getSecureRandom(),
105
-				new TimeFactory(),
106
-				$server->getConfig(),
107
-				$server->getCrypto(),
108
-				Util::getDefaultEmailAddress('no-reply')
109
-			);
110
-		});
111
-		$container->registerService(AppFetcher::class, function (IContainer $c) {
112
-			/** @var Server $server */
113
-			$server = $c->query('ServerContainer');
114
-			return new AppFetcher(
115
-				$server->getAppDataDir('appstore'),
116
-				$server->getHTTPClientService(),
117
-				$server->query(TimeFactory::class),
118
-				$server->getConfig()
119
-			);
120
-		});
121
-		$container->registerService(CategoryFetcher::class, function (IContainer $c) {
122
-			/** @var Server $server */
123
-			$server = $c->query('ServerContainer');
124
-			return new CategoryFetcher(
125
-				$server->getAppDataDir('appstore'),
126
-				$server->getHTTPClientService(),
127
-				$server->query(TimeFactory::class),
128
-				$server->getConfig()
129
-			);
130
-		});
131
-	}
99
+            return new NewUserMailHelper(
100
+                $defaults,
101
+                $server->getURLGenerator(),
102
+                $server->getL10N('settings'),
103
+                $server->getMailer(),
104
+                $server->getSecureRandom(),
105
+                new TimeFactory(),
106
+                $server->getConfig(),
107
+                $server->getCrypto(),
108
+                Util::getDefaultEmailAddress('no-reply')
109
+            );
110
+        });
111
+        $container->registerService(AppFetcher::class, function (IContainer $c) {
112
+            /** @var Server $server */
113
+            $server = $c->query('ServerContainer');
114
+            return new AppFetcher(
115
+                $server->getAppDataDir('appstore'),
116
+                $server->getHTTPClientService(),
117
+                $server->query(TimeFactory::class),
118
+                $server->getConfig()
119
+            );
120
+        });
121
+        $container->registerService(CategoryFetcher::class, function (IContainer $c) {
122
+            /** @var Server $server */
123
+            $server = $c->query('ServerContainer');
124
+            return new CategoryFetcher(
125
+                $server->getAppDataDir('appstore'),
126
+                $server->getHTTPClientService(),
127
+                $server->query(TimeFactory::class),
128
+                $server->getConfig()
129
+            );
130
+        });
131
+    }
132 132
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	/**
53 53
 	 * @param array $urlParams
54 54
 	 */
55
-	public function __construct(array $urlParams=[]){
55
+	public function __construct(array $urlParams = []) {
56 56
 		parent::__construct('settings', $urlParams);
57 57
 
58 58
 		$container = $this->getContainer();
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 		$container->registerService('isSubAdmin', function(IContainer $c) {
73 73
 			$userObject = \OC::$server->getUserSession()->getUser();
74 74
 			$isSubAdmin = false;
75
-			if($userObject !== null) {
75
+			if ($userObject !== null) {
76 76
 				$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
77 77
 			}
78 78
 			return $isSubAdmin;
@@ -80,17 +80,17 @@  discard block
 block discarded – undo
80 80
 		$container->registerService('userCertificateManager', function(IContainer $c) {
81 81
 			return $c->query('ServerContainer')->getCertificateManager();
82 82
 		}, false);
83
-		$container->registerService('systemCertificateManager', function (IContainer $c) {
83
+		$container->registerService('systemCertificateManager', function(IContainer $c) {
84 84
 			return $c->query('ServerContainer')->getCertificateManager(null);
85 85
 		}, false);
86
-		$container->registerService(IProvider::class, function (IContainer $c) {
86
+		$container->registerService(IProvider::class, function(IContainer $c) {
87 87
 			return $c->query('ServerContainer')->query(IProvider::class);
88 88
 		});
89
-		$container->registerService(IManager::class, function (IContainer $c) {
89
+		$container->registerService(IManager::class, function(IContainer $c) {
90 90
 			return $c->query('ServerContainer')->getSettingsManager();
91 91
 		});
92 92
 
93
-		$container->registerService(NewUserMailHelper::class, function (IContainer $c) {
93
+		$container->registerService(NewUserMailHelper::class, function(IContainer $c) {
94 94
 			/** @var Server $server */
95 95
 			$server = $c->query('ServerContainer');
96 96
 			/** @var Defaults $defaults */
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 				Util::getDefaultEmailAddress('no-reply')
109 109
 			);
110 110
 		});
111
-		$container->registerService(AppFetcher::class, function (IContainer $c) {
111
+		$container->registerService(AppFetcher::class, function(IContainer $c) {
112 112
 			/** @var Server $server */
113 113
 			$server = $c->query('ServerContainer');
114 114
 			return new AppFetcher(
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 				$server->getConfig()
119 119
 			);
120 120
 		});
121
-		$container->registerService(CategoryFetcher::class, function (IContainer $c) {
121
+		$container->registerService(CategoryFetcher::class, function(IContainer $c) {
122 122
 			/** @var Server $server */
123 123
 			$server = $c->query('ServerContainer');
124 124
 			return new CategoryFetcher(
Please login to merge, or discard this patch.
apps/provisioning_api/lib/AppInfo/Application.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -11,35 +11,35 @@
 block discarded – undo
11 11
 use OCP\Util;
12 12
 
13 13
 class Application extends App {
14
-	public function __construct(array $urlParams = array()) {
15
-		parent::__construct('provisioning_api', $urlParams);
14
+    public function __construct(array $urlParams = array()) {
15
+        parent::__construct('provisioning_api', $urlParams);
16 16
 
17
-		$container = $this->getContainer();
18
-		$server = $container->getServer();
17
+        $container = $this->getContainer();
18
+        $server = $container->getServer();
19 19
 
20
-		$container->registerService(NewUserMailHelper::class, function(SimpleContainer $c) use ($server) {
21
-			return new NewUserMailHelper(
22
-				$server->query(Defaults::class),
23
-				$server->getURLGenerator(),
24
-				$server->getL10N('settings'),
25
-				$server->getMailer(),
26
-				$server->getSecureRandom(),
27
-				new TimeFactory(),
28
-				$server->getConfig(),
29
-				$server->getCrypto(),
30
-				Util::getDefaultEmailAddress('no-reply')
31
-			);
32
-		});
33
-		$container->registerService('ProvisioningApiMiddleware', function(SimpleContainer $c) use ($server) {
34
-			$user = $server->getUserManager()->get($c['UserId']);
35
-			$isAdmin = $user !== null ? $server->getGroupManager()->isAdmin($user->getUID()) : false;
36
-			$isSubAdmin = $user !== null ? $server->getGroupManager()->getSubAdmin()->isSubAdmin($user) : false;
37
-			return new ProvisioningApiMiddleware(
38
-				$c['ControllerMethodReflector'],
39
-				$isAdmin,
40
-				$isSubAdmin
41
-			);
42
-		});
43
-		$container->registerMiddleWare('ProvisioningApiMiddleware');
44
-	}
20
+        $container->registerService(NewUserMailHelper::class, function(SimpleContainer $c) use ($server) {
21
+            return new NewUserMailHelper(
22
+                $server->query(Defaults::class),
23
+                $server->getURLGenerator(),
24
+                $server->getL10N('settings'),
25
+                $server->getMailer(),
26
+                $server->getSecureRandom(),
27
+                new TimeFactory(),
28
+                $server->getConfig(),
29
+                $server->getCrypto(),
30
+                Util::getDefaultEmailAddress('no-reply')
31
+            );
32
+        });
33
+        $container->registerService('ProvisioningApiMiddleware', function(SimpleContainer $c) use ($server) {
34
+            $user = $server->getUserManager()->get($c['UserId']);
35
+            $isAdmin = $user !== null ? $server->getGroupManager()->isAdmin($user->getUID()) : false;
36
+            $isSubAdmin = $user !== null ? $server->getGroupManager()->getSubAdmin()->isSubAdmin($user) : false;
37
+            return new ProvisioningApiMiddleware(
38
+                $c['ControllerMethodReflector'],
39
+                $isAdmin,
40
+                $isSubAdmin
41
+            );
42
+        });
43
+        $container->registerMiddleWare('ProvisioningApiMiddleware');
44
+    }
45 45
 }
Please login to merge, or discard this patch.
apps/federatedfilesharing/settings-personal.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -39,17 +39,17 @@
 block discarded – undo
39 39
 }
40 40
 
41 41
 $cloudID = \OC::$server->getUserSession()->getUser()->getCloudId();
42
-$url = 'https://nextcloud.com/federation#' . $cloudID;
42
+$url = 'https://nextcloud.com/federation#'.$cloudID;
43 43
 $logoPath = \OC::$server->getURLGenerator()->imagePath('core', 'logo-icon.svg');
44 44
 /** @var \OCP\Defaults $theme */
45 45
 $theme = \OC::$server->query(\OCP\Defaults::class);
46 46
 $color = $theme->getColorPrimary();
47 47
 $textColor = "#ffffff";
48
-if(\OC::$server->getAppManager()->isEnabledForUser("theming")) {
48
+if (\OC::$server->getAppManager()->isEnabledForUser("theming")) {
49 49
 	$logoPath = $theme->getLogo();
50 50
 	try {
51 51
 		$util = \OC::$server->query("\OCA\Theming\Util");
52
-		if($util->invertTextColor($color)) {
52
+		if ($util->invertTextColor($color)) {
53 53
 			$textColor = "#000000";
54 54
 		}
55 55
 	} catch (OCP\AppFramework\QueryException $e) {
Please login to merge, or discard this patch.
apps/files_sharing/lib/AppInfo/Application.php 2 patches
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -41,131 +41,131 @@
 block discarded – undo
41 41
 use OCP\IServerContainer;
42 42
 
43 43
 class Application extends App {
44
-	public function __construct(array $urlParams = array()) {
45
-		parent::__construct('files_sharing', $urlParams);
44
+    public function __construct(array $urlParams = array()) {
45
+        parent::__construct('files_sharing', $urlParams);
46 46
 
47
-		$container = $this->getContainer();
48
-		/** @var IServerContainer $server */
49
-		$server = $container->getServer();
47
+        $container = $this->getContainer();
48
+        /** @var IServerContainer $server */
49
+        $server = $container->getServer();
50 50
 
51
-		/**
52
-		 * Controllers
53
-		 */
54
-		$container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
55
-			$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
56
-			return new ShareController(
57
-				$c->query('AppName'),
58
-				$c->query('Request'),
59
-				$server->getConfig(),
60
-				$server->getURLGenerator(),
61
-				$server->getUserManager(),
62
-				$server->getLogger(),
63
-				$server->getActivityManager(),
64
-				$server->getShareManager(),
65
-				$server->getSession(),
66
-				$server->getPreviewManager(),
67
-				$server->getRootFolder(),
68
-				$federatedSharingApp->getFederatedShareProvider(),
69
-				$server->getEventDispatcher(),
70
-				$server->getL10N($c->query('AppName')),
71
-				$server->query(Defaults::class)
72
-			);
73
-		});
74
-		$container->registerService('ExternalSharesController', function (SimpleContainer $c) {
75
-			return new ExternalSharesController(
76
-				$c->query('AppName'),
77
-				$c->query('Request'),
78
-				$c->query('ExternalManager'),
79
-				$c->query('HttpClientService')
80
-			);
81
-		});
51
+        /**
52
+         * Controllers
53
+         */
54
+        $container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
55
+            $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
56
+            return new ShareController(
57
+                $c->query('AppName'),
58
+                $c->query('Request'),
59
+                $server->getConfig(),
60
+                $server->getURLGenerator(),
61
+                $server->getUserManager(),
62
+                $server->getLogger(),
63
+                $server->getActivityManager(),
64
+                $server->getShareManager(),
65
+                $server->getSession(),
66
+                $server->getPreviewManager(),
67
+                $server->getRootFolder(),
68
+                $federatedSharingApp->getFederatedShareProvider(),
69
+                $server->getEventDispatcher(),
70
+                $server->getL10N($c->query('AppName')),
71
+                $server->query(Defaults::class)
72
+            );
73
+        });
74
+        $container->registerService('ExternalSharesController', function (SimpleContainer $c) {
75
+            return new ExternalSharesController(
76
+                $c->query('AppName'),
77
+                $c->query('Request'),
78
+                $c->query('ExternalManager'),
79
+                $c->query('HttpClientService')
80
+            );
81
+        });
82 82
 
83
-		/**
84
-		 * Core class wrappers
85
-		 */
86
-		$container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) {
87
-			return $server->getHTTPClientService();
88
-		});
89
-		$container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) {
90
-			return $server->getCloudIdManager();
91
-		});
92
-		$container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
93
-			$user = $server->getUserSession()->getUser();
94
-			$uid = $user ? $user->getUID() : null;
95
-			$discoveryManager = new DiscoveryManager(
96
-				\OC::$server->getMemCacheFactory(),
97
-				\OC::$server->getHTTPClientService()
98
-			);
99
-			return new \OCA\Files_Sharing\External\Manager(
100
-				$server->getDatabaseConnection(),
101
-				\OC\Files\Filesystem::getMountManager(),
102
-				\OC\Files\Filesystem::getLoader(),
103
-				$server->getHTTPClientService(),
104
-				$server->getNotificationManager(),
105
-				$discoveryManager,
106
-				$uid
107
-			);
108
-		});
109
-		$container->registerAlias('OCA\Files_Sharing\External\Manager', 'ExternalManager');
83
+        /**
84
+         * Core class wrappers
85
+         */
86
+        $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) {
87
+            return $server->getHTTPClientService();
88
+        });
89
+        $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) {
90
+            return $server->getCloudIdManager();
91
+        });
92
+        $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
93
+            $user = $server->getUserSession()->getUser();
94
+            $uid = $user ? $user->getUID() : null;
95
+            $discoveryManager = new DiscoveryManager(
96
+                \OC::$server->getMemCacheFactory(),
97
+                \OC::$server->getHTTPClientService()
98
+            );
99
+            return new \OCA\Files_Sharing\External\Manager(
100
+                $server->getDatabaseConnection(),
101
+                \OC\Files\Filesystem::getMountManager(),
102
+                \OC\Files\Filesystem::getLoader(),
103
+                $server->getHTTPClientService(),
104
+                $server->getNotificationManager(),
105
+                $discoveryManager,
106
+                $uid
107
+            );
108
+        });
109
+        $container->registerAlias('OCA\Files_Sharing\External\Manager', 'ExternalManager');
110 110
 
111
-		/**
112
-		 * Middleware
113
-		 */
114
-		$container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) {
115
-			return new SharingCheckMiddleware(
116
-				$c->query('AppName'),
117
-				$server->getConfig(),
118
-				$server->getAppManager(),
119
-				$c['ControllerMethodReflector'],
120
-				$server->getShareManager(),
121
-				$server->getRequest()
122
-			);
123
-		});
111
+        /**
112
+         * Middleware
113
+         */
114
+        $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) {
115
+            return new SharingCheckMiddleware(
116
+                $c->query('AppName'),
117
+                $server->getConfig(),
118
+                $server->getAppManager(),
119
+                $c['ControllerMethodReflector'],
120
+                $server->getShareManager(),
121
+                $server->getRequest()
122
+            );
123
+        });
124 124
 
125
-		$container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) {
126
-			return new OCSShareAPIMiddleware(
127
-				$server->getShareManager(),
128
-				$server->getL10N($c->query('AppName'))
129
-			);
130
-		});
125
+        $container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) {
126
+            return new OCSShareAPIMiddleware(
127
+                $server->getShareManager(),
128
+                $server->getL10N($c->query('AppName'))
129
+            );
130
+        });
131 131
 
132
-		// Execute middlewares
133
-		$container->registerMiddleWare('SharingCheckMiddleware');
134
-		$container->registerMiddleWare('OCSShareAPIMiddleware');
132
+        // Execute middlewares
133
+        $container->registerMiddleWare('SharingCheckMiddleware');
134
+        $container->registerMiddleWare('OCSShareAPIMiddleware');
135 135
 
136
-		$container->registerService('MountProvider', function (IContainer $c) {
137
-			/** @var \OCP\IServerContainer $server */
138
-			$server = $c->query('ServerContainer');
139
-			return new MountProvider(
140
-				$server->getConfig(),
141
-				$server->getShareManager(),
142
-				$server->getLogger()
143
-			);
144
-		});
136
+        $container->registerService('MountProvider', function (IContainer $c) {
137
+            /** @var \OCP\IServerContainer $server */
138
+            $server = $c->query('ServerContainer');
139
+            return new MountProvider(
140
+                $server->getConfig(),
141
+                $server->getShareManager(),
142
+                $server->getLogger()
143
+            );
144
+        });
145 145
 
146
-		$container->registerService('ExternalMountProvider', function (IContainer $c) {
147
-			/** @var \OCP\IServerContainer $server */
148
-			$server = $c->query('ServerContainer');
149
-			return new \OCA\Files_Sharing\External\MountProvider(
150
-				$server->getDatabaseConnection(),
151
-				function() use ($c) {
152
-					return $c->query('ExternalManager');
153
-				},
154
-				$server->getCloudIdManager()
155
-			);
156
-		});
146
+        $container->registerService('ExternalMountProvider', function (IContainer $c) {
147
+            /** @var \OCP\IServerContainer $server */
148
+            $server = $c->query('ServerContainer');
149
+            return new \OCA\Files_Sharing\External\MountProvider(
150
+                $server->getDatabaseConnection(),
151
+                function() use ($c) {
152
+                    return $c->query('ExternalManager');
153
+                },
154
+                $server->getCloudIdManager()
155
+            );
156
+        });
157 157
 
158
-		/*
158
+        /*
159 159
 		 * Register capabilities
160 160
 		 */
161
-		$container->registerCapability('OCA\Files_Sharing\Capabilities');
162
-	}
161
+        $container->registerCapability('OCA\Files_Sharing\Capabilities');
162
+    }
163 163
 
164
-	public function registerMountProviders() {
165
-		/** @var \OCP\IServerContainer $server */
166
-		$server = $this->getContainer()->query('ServerContainer');
167
-		$mountProviderCollection = $server->getMountProviderCollection();
168
-		$mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider'));
169
-		$mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider'));
170
-	}
164
+    public function registerMountProviders() {
165
+        /** @var \OCP\IServerContainer $server */
166
+        $server = $this->getContainer()->query('ServerContainer');
167
+        $mountProviderCollection = $server->getMountProviderCollection();
168
+        $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider'));
169
+        $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider'));
170
+    }
171 171
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		/**
52 52
 		 * Controllers
53 53
 		 */
54
-		$container->registerService('ShareController', function (SimpleContainer $c) use ($server) {
54
+		$container->registerService('ShareController', function(SimpleContainer $c) use ($server) {
55 55
 			$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
56 56
 			return new ShareController(
57 57
 				$c->query('AppName'),
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 				$server->query(Defaults::class)
72 72
 			);
73 73
 		});
74
-		$container->registerService('ExternalSharesController', function (SimpleContainer $c) {
74
+		$container->registerService('ExternalSharesController', function(SimpleContainer $c) {
75 75
 			return new ExternalSharesController(
76 76
 				$c->query('AppName'),
77 77
 				$c->query('Request'),
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
 		/**
84 84
 		 * Core class wrappers
85 85
 		 */
86
-		$container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) {
86
+		$container->registerService('HttpClientService', function(SimpleContainer $c) use ($server) {
87 87
 			return $server->getHTTPClientService();
88 88
 		});
89
-		$container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) {
89
+		$container->registerService(ICloudIdManager::class, function(SimpleContainer $c) use ($server) {
90 90
 			return $server->getCloudIdManager();
91 91
 		});
92
-		$container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
92
+		$container->registerService('ExternalManager', function(SimpleContainer $c) use ($server) {
93 93
 			$user = $server->getUserSession()->getUser();
94 94
 			$uid = $user ? $user->getUID() : null;
95 95
 			$discoveryManager = new DiscoveryManager(
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 		/**
112 112
 		 * Middleware
113 113
 		 */
114
-		$container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) {
114
+		$container->registerService('SharingCheckMiddleware', function(SimpleContainer $c) use ($server) {
115 115
 			return new SharingCheckMiddleware(
116 116
 				$c->query('AppName'),
117 117
 				$server->getConfig(),
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 			);
123 123
 		});
124 124
 
125
-		$container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) {
125
+		$container->registerService('OCSShareAPIMiddleware', function(SimpleContainer $c) use ($server) {
126 126
 			return new OCSShareAPIMiddleware(
127 127
 				$server->getShareManager(),
128 128
 				$server->getL10N($c->query('AppName'))
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 		$container->registerMiddleWare('SharingCheckMiddleware');
134 134
 		$container->registerMiddleWare('OCSShareAPIMiddleware');
135 135
 
136
-		$container->registerService('MountProvider', function (IContainer $c) {
136
+		$container->registerService('MountProvider', function(IContainer $c) {
137 137
 			/** @var \OCP\IServerContainer $server */
138 138
 			$server = $c->query('ServerContainer');
139 139
 			return new MountProvider(
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 			);
144 144
 		});
145 145
 
146
-		$container->registerService('ExternalMountProvider', function (IContainer $c) {
146
+		$container->registerService('ExternalMountProvider', function(IContainer $c) {
147 147
 			/** @var \OCP\IServerContainer $server */
148 148
 			$server = $c->query('ServerContainer');
149 149
 			return new \OCA\Files_Sharing\External\MountProvider(
Please login to merge, or discard this patch.
apps/theming/lib/ThemingDefaults.php 2 patches
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -32,214 +32,214 @@
 block discarded – undo
32 32
 
33 33
 class ThemingDefaults extends \OC_Defaults {
34 34
 
35
-	/** @var IConfig */
36
-	private $config;
37
-	/** @var IL10N */
38
-	private $l;
39
-	/** @var IURLGenerator */
40
-	private $urlGenerator;
41
-	/** @var IAppData */
42
-	private $appData;
43
-	/** @var ICacheFactory */
44
-	private $cacheFactory;
45
-	/** @var string */
46
-	private $name;
47
-	/** @var string */
48
-	private $url;
49
-	/** @var string */
50
-	private $slogan;
51
-	/** @var string */
52
-	private $color;
53
-
54
-	/**
55
-	 * ThemingDefaults constructor.
56
-	 *
57
-	 * @param IConfig $config
58
-	 * @param IL10N $l
59
-	 * @param IURLGenerator $urlGenerator
60
-	 * @param \OC_Defaults $defaults
61
-	 * @param IAppData $appData
62
-	 * @param ICacheFactory $cacheFactory
63
-	 */
64
-	public function __construct(IConfig $config,
65
-								IL10N $l,
66
-								IURLGenerator $urlGenerator,
67
-								\OC_Defaults $defaults,
68
-								IAppData $appData,
69
-								ICacheFactory $cacheFactory
70
-	) {
71
-		parent::__construct();
72
-		$this->config = $config;
73
-		$this->l = $l;
74
-		$this->urlGenerator = $urlGenerator;
75
-		$this->appData = $appData;
76
-		$this->cacheFactory = $cacheFactory;
77
-
78
-		$this->name = $defaults->getName();
79
-		$this->url = $defaults->getBaseUrl();
80
-		$this->slogan = $defaults->getSlogan();
81
-		$this->color = $defaults->getColorPrimary();
82
-	}
83
-
84
-	public function getName() {
85
-		return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
86
-	}
87
-
88
-	public function getHTMLName() {
89
-		return $this->config->getAppValue('theming', 'name', $this->name);
90
-	}
91
-
92
-	public function getTitle() {
93
-		return $this->getName();
94
-	}
95
-
96
-	public function getEntity() {
97
-		return $this->getName();
98
-	}
99
-
100
-	public function getBaseUrl() {
101
-		return $this->config->getAppValue('theming', 'url', $this->url);
102
-	}
103
-
104
-	public function getSlogan() {
105
-		return Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan));
106
-	}
107
-
108
-	public function getShortFooter() {
109
-		$slogan = $this->getSlogan();
110
-		$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
111
-			' rel="noreferrer">' .$this->getEntity() . '</a>'.
112
-			($slogan !== '' ? ' – ' . $slogan : '');
113
-
114
-		return $footer;
115
-	}
116
-
117
-	/**
118
-	 * Color that is used for the header as well as for mail headers
119
-	 *
120
-	 * @return string
121
-	 */
122
-	public function getColorPrimary() {
123
-		return $this->config->getAppValue('theming', 'color', $this->color);
124
-	}
125
-
126
-	/**
127
-	 * Themed logo url
128
-	 *
129
-	 * @return string
130
-	 */
131
-	public function getLogo() {
132
-		$logo = $this->config->getAppValue('theming', 'logoMime');
133
-
134
-		$logoExists = true;
135
-		try {
136
-			$this->appData->getFolder('images')->getFile('logo');
137
-		} catch (\Exception $e) {
138
-			$logoExists = false;
139
-		}
140
-
141
-		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
142
-
143
-		if(!$logo || !$logoExists) {
144
-			return $this->urlGenerator->imagePath('core','logo.svg') . '?v=' . $cacheBusterCounter;
145
-		}
146
-
147
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
148
-	}
149
-
150
-	/**
151
-	 * Themed background image url
152
-	 *
153
-	 * @return string
154
-	 */
155
-	public function getBackground() {
156
-		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime');
157
-
158
-		$backgroundExists = true;
159
-		try {
160
-			$this->appData->getFolder('images')->getFile('background');
161
-		} catch (\Exception $e) {
162
-			$backgroundExists = false;
163
-		}
164
-
165
-		if(!$backgroundLogo || !$backgroundExists) {
166
-			return $this->urlGenerator->imagePath('core','background.jpg');
167
-		}
168
-
169
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground');
170
-	}
171
-
172
-	/**
173
-	 * Check if Imagemagick is enabled and if SVG is supported
174
-	 * otherwise we can't render custom icons
175
-	 *
176
-	 * @return bool
177
-	 */
178
-	public function shouldReplaceIcons() {
179
-		$cache = $this->cacheFactory->create('theming');
180
-		if($value = $cache->get('shouldReplaceIcons')) {
181
-			return (bool)$value;
182
-		}
183
-		$value = false;
184
-		if(extension_loaded('imagick')) {
185
-			$checkImagick = new \Imagick();
186
-			if (count($checkImagick->queryFormats('SVG')) >= 1) {
187
-				$value = true;
188
-			}
189
-			$checkImagick->clear();
190
-		}
191
-		$cache->set('shouldReplaceIcons', $value);
192
-		return $value;
193
-	}
194
-
195
-	/**
196
-	 * Increases the cache buster key
197
-	 */
198
-	private function increaseCacheBuster() {
199
-		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
200
-		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
201
-	}
202
-
203
-	/**
204
-	 * Update setting in the database
205
-	 *
206
-	 * @param string $setting
207
-	 * @param string $value
208
-	 */
209
-	public function set($setting, $value) {
210
-		$this->config->setAppValue('theming', $setting, $value);
211
-		$this->increaseCacheBuster();
212
-	}
213
-
214
-	/**
215
-	 * Revert settings to the default value
216
-	 *
217
-	 * @param string $setting setting which should be reverted
218
-	 * @return string default value
219
-	 */
220
-	public function undo($setting) {
221
-		$this->config->deleteAppValue('theming', $setting);
222
-		$this->increaseCacheBuster();
223
-
224
-		switch ($setting) {
225
-			case 'name':
226
-				$returnValue = $this->getEntity();
227
-				break;
228
-			case 'url':
229
-				$returnValue = $this->getBaseUrl();
230
-				break;
231
-			case 'slogan':
232
-				$returnValue = $this->getSlogan();
233
-				break;
234
-			case 'color':
235
-				$returnValue = $this->getColorPrimary();
236
-				break;
237
-			default:
238
-				$returnValue = '';
239
-				break;
240
-		}
241
-
242
-		return $returnValue;
243
-	}
35
+    /** @var IConfig */
36
+    private $config;
37
+    /** @var IL10N */
38
+    private $l;
39
+    /** @var IURLGenerator */
40
+    private $urlGenerator;
41
+    /** @var IAppData */
42
+    private $appData;
43
+    /** @var ICacheFactory */
44
+    private $cacheFactory;
45
+    /** @var string */
46
+    private $name;
47
+    /** @var string */
48
+    private $url;
49
+    /** @var string */
50
+    private $slogan;
51
+    /** @var string */
52
+    private $color;
53
+
54
+    /**
55
+     * ThemingDefaults constructor.
56
+     *
57
+     * @param IConfig $config
58
+     * @param IL10N $l
59
+     * @param IURLGenerator $urlGenerator
60
+     * @param \OC_Defaults $defaults
61
+     * @param IAppData $appData
62
+     * @param ICacheFactory $cacheFactory
63
+     */
64
+    public function __construct(IConfig $config,
65
+                                IL10N $l,
66
+                                IURLGenerator $urlGenerator,
67
+                                \OC_Defaults $defaults,
68
+                                IAppData $appData,
69
+                                ICacheFactory $cacheFactory
70
+    ) {
71
+        parent::__construct();
72
+        $this->config = $config;
73
+        $this->l = $l;
74
+        $this->urlGenerator = $urlGenerator;
75
+        $this->appData = $appData;
76
+        $this->cacheFactory = $cacheFactory;
77
+
78
+        $this->name = $defaults->getName();
79
+        $this->url = $defaults->getBaseUrl();
80
+        $this->slogan = $defaults->getSlogan();
81
+        $this->color = $defaults->getColorPrimary();
82
+    }
83
+
84
+    public function getName() {
85
+        return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
86
+    }
87
+
88
+    public function getHTMLName() {
89
+        return $this->config->getAppValue('theming', 'name', $this->name);
90
+    }
91
+
92
+    public function getTitle() {
93
+        return $this->getName();
94
+    }
95
+
96
+    public function getEntity() {
97
+        return $this->getName();
98
+    }
99
+
100
+    public function getBaseUrl() {
101
+        return $this->config->getAppValue('theming', 'url', $this->url);
102
+    }
103
+
104
+    public function getSlogan() {
105
+        return Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan));
106
+    }
107
+
108
+    public function getShortFooter() {
109
+        $slogan = $this->getSlogan();
110
+        $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
111
+            ' rel="noreferrer">' .$this->getEntity() . '</a>'.
112
+            ($slogan !== '' ? ' – ' . $slogan : '');
113
+
114
+        return $footer;
115
+    }
116
+
117
+    /**
118
+     * Color that is used for the header as well as for mail headers
119
+     *
120
+     * @return string
121
+     */
122
+    public function getColorPrimary() {
123
+        return $this->config->getAppValue('theming', 'color', $this->color);
124
+    }
125
+
126
+    /**
127
+     * Themed logo url
128
+     *
129
+     * @return string
130
+     */
131
+    public function getLogo() {
132
+        $logo = $this->config->getAppValue('theming', 'logoMime');
133
+
134
+        $logoExists = true;
135
+        try {
136
+            $this->appData->getFolder('images')->getFile('logo');
137
+        } catch (\Exception $e) {
138
+            $logoExists = false;
139
+        }
140
+
141
+        $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
142
+
143
+        if(!$logo || !$logoExists) {
144
+            return $this->urlGenerator->imagePath('core','logo.svg') . '?v=' . $cacheBusterCounter;
145
+        }
146
+
147
+        return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
148
+    }
149
+
150
+    /**
151
+     * Themed background image url
152
+     *
153
+     * @return string
154
+     */
155
+    public function getBackground() {
156
+        $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime');
157
+
158
+        $backgroundExists = true;
159
+        try {
160
+            $this->appData->getFolder('images')->getFile('background');
161
+        } catch (\Exception $e) {
162
+            $backgroundExists = false;
163
+        }
164
+
165
+        if(!$backgroundLogo || !$backgroundExists) {
166
+            return $this->urlGenerator->imagePath('core','background.jpg');
167
+        }
168
+
169
+        return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground');
170
+    }
171
+
172
+    /**
173
+     * Check if Imagemagick is enabled and if SVG is supported
174
+     * otherwise we can't render custom icons
175
+     *
176
+     * @return bool
177
+     */
178
+    public function shouldReplaceIcons() {
179
+        $cache = $this->cacheFactory->create('theming');
180
+        if($value = $cache->get('shouldReplaceIcons')) {
181
+            return (bool)$value;
182
+        }
183
+        $value = false;
184
+        if(extension_loaded('imagick')) {
185
+            $checkImagick = new \Imagick();
186
+            if (count($checkImagick->queryFormats('SVG')) >= 1) {
187
+                $value = true;
188
+            }
189
+            $checkImagick->clear();
190
+        }
191
+        $cache->set('shouldReplaceIcons', $value);
192
+        return $value;
193
+    }
194
+
195
+    /**
196
+     * Increases the cache buster key
197
+     */
198
+    private function increaseCacheBuster() {
199
+        $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
200
+        $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
201
+    }
202
+
203
+    /**
204
+     * Update setting in the database
205
+     *
206
+     * @param string $setting
207
+     * @param string $value
208
+     */
209
+    public function set($setting, $value) {
210
+        $this->config->setAppValue('theming', $setting, $value);
211
+        $this->increaseCacheBuster();
212
+    }
213
+
214
+    /**
215
+     * Revert settings to the default value
216
+     *
217
+     * @param string $setting setting which should be reverted
218
+     * @return string default value
219
+     */
220
+    public function undo($setting) {
221
+        $this->config->deleteAppValue('theming', $setting);
222
+        $this->increaseCacheBuster();
223
+
224
+        switch ($setting) {
225
+            case 'name':
226
+                $returnValue = $this->getEntity();
227
+                break;
228
+            case 'url':
229
+                $returnValue = $this->getBaseUrl();
230
+                break;
231
+            case 'slogan':
232
+                $returnValue = $this->getSlogan();
233
+                break;
234
+            case 'color':
235
+                $returnValue = $this->getColorPrimary();
236
+                break;
237
+            default:
238
+                $returnValue = '';
239
+                break;
240
+        }
241
+
242
+        return $returnValue;
243
+    }
244 244
 
245 245
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
 
108 108
 	public function getShortFooter() {
109 109
 		$slogan = $this->getSlogan();
110
-		$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
111
-			' rel="noreferrer">' .$this->getEntity() . '</a>'.
112
-			($slogan !== '' ? ' – ' . $slogan : '');
110
+		$footer = '<a href="'.$this->getBaseUrl().'" target="_blank"'.
111
+			' rel="noreferrer">'.$this->getEntity().'</a>'.
112
+			($slogan !== '' ? ' – '.$slogan : '');
113 113
 
114 114
 		return $footer;
115 115
 	}
@@ -140,11 +140,11 @@  discard block
 block discarded – undo
140 140
 
141 141
 		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
142 142
 
143
-		if(!$logo || !$logoExists) {
144
-			return $this->urlGenerator->imagePath('core','logo.svg') . '?v=' . $cacheBusterCounter;
143
+		if (!$logo || !$logoExists) {
144
+			return $this->urlGenerator->imagePath('core', 'logo.svg').'?v='.$cacheBusterCounter;
145 145
 		}
146 146
 
147
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
147
+		return $this->urlGenerator->linkToRoute('theming.Theming.getLogo').'?v='.$cacheBusterCounter;
148 148
 	}
149 149
 
150 150
 	/**
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
 			$backgroundExists = false;
163 163
 		}
164 164
 
165
-		if(!$backgroundLogo || !$backgroundExists) {
166
-			return $this->urlGenerator->imagePath('core','background.jpg');
165
+		if (!$backgroundLogo || !$backgroundExists) {
166
+			return $this->urlGenerator->imagePath('core', 'background.jpg');
167 167
 		}
168 168
 
169 169
 		return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground');
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
 	 */
178 178
 	public function shouldReplaceIcons() {
179 179
 		$cache = $this->cacheFactory->create('theming');
180
-		if($value = $cache->get('shouldReplaceIcons')) {
181
-			return (bool)$value;
180
+		if ($value = $cache->get('shouldReplaceIcons')) {
181
+			return (bool) $value;
182 182
 		}
183 183
 		$value = false;
184
-		if(extension_loaded('imagick')) {
184
+		if (extension_loaded('imagick')) {
185 185
 			$checkImagick = new \Imagick();
186 186
 			if (count($checkImagick->queryFormats('SVG')) >= 1) {
187 187
 				$value = true;
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	 */
198 198
 	private function increaseCacheBuster() {
199 199
 		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
200
-		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
200
+		$this->config->setAppValue('theming', 'cachebuster', (int) $cacheBusterKey + 1);
201 201
 	}
202 202
 
203 203
 	/**
Please login to merge, or discard this patch.
lib/private/legacy/util.php 1 patch
Indentation   +1380 added lines, -1380 removed lines patch added patch discarded remove patch
@@ -61,1388 +61,1388 @@
 block discarded – undo
61 61
 use OCP\IUser;
62 62
 
63 63
 class OC_Util {
64
-	public static $scripts = array();
65
-	public static $styles = array();
66
-	public static $headers = array();
67
-	private static $rootMounted = false;
68
-	private static $fsSetup = false;
69
-
70
-	/** @var array Local cache of version.php */
71
-	private static $versionCache = null;
72
-
73
-	protected static function getAppManager() {
74
-		return \OC::$server->getAppManager();
75
-	}
76
-
77
-	private static function initLocalStorageRootFS() {
78
-		// mount local file backend as root
79
-		$configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data");
80
-		//first set up the local "root" storage
81
-		\OC\Files\Filesystem::initMountManager();
82
-		if (!self::$rootMounted) {
83
-			\OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/');
84
-			self::$rootMounted = true;
85
-		}
86
-	}
87
-
88
-	/**
89
-	 * mounting an object storage as the root fs will in essence remove the
90
-	 * necessity of a data folder being present.
91
-	 * TODO make home storage aware of this and use the object storage instead of local disk access
92
-	 *
93
-	 * @param array $config containing 'class' and optional 'arguments'
94
-	 */
95
-	private static function initObjectStoreRootFS($config) {
96
-		// check misconfiguration
97
-		if (empty($config['class'])) {
98
-			\OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
99
-		}
100
-		if (!isset($config['arguments'])) {
101
-			$config['arguments'] = array();
102
-		}
103
-
104
-		// instantiate object store implementation
105
-		$name = $config['class'];
106
-		if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) {
107
-			$segments = explode('\\', $name);
108
-			OC_App::loadApp(strtolower($segments[1]));
109
-		}
110
-		$config['arguments']['objectstore'] = new $config['class']($config['arguments']);
111
-		// mount with plain / root object store implementation
112
-		$config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage';
113
-
114
-		// mount object storage as root
115
-		\OC\Files\Filesystem::initMountManager();
116
-		if (!self::$rootMounted) {
117
-			\OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/');
118
-			self::$rootMounted = true;
119
-		}
120
-	}
121
-
122
-	/**
123
-	 * Can be set up
124
-	 *
125
-	 * @param string $user
126
-	 * @return boolean
127
-	 * @description configure the initial filesystem based on the configuration
128
-	 */
129
-	public static function setupFS($user = '') {
130
-		//setting up the filesystem twice can only lead to trouble
131
-		if (self::$fsSetup) {
132
-			return false;
133
-		}
134
-
135
-		\OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem');
136
-
137
-		// If we are not forced to load a specific user we load the one that is logged in
138
-		if ($user === null) {
139
-			$user = '';
140
-		} else if ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) {
141
-			$user = OC_User::getUser();
142
-		}
143
-
144
-		// load all filesystem apps before, so no setup-hook gets lost
145
-		OC_App::loadApps(array('filesystem'));
146
-
147
-		// the filesystem will finish when $user is not empty,
148
-		// mark fs setup here to avoid doing the setup from loading
149
-		// OC_Filesystem
150
-		if ($user != '') {
151
-			self::$fsSetup = true;
152
-		}
153
-
154
-		\OC\Files\Filesystem::initMountManager();
155
-
156
-		\OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false);
157
-		\OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
158
-			if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) {
159
-				/** @var \OC\Files\Storage\Common $storage */
160
-				$storage->setMountOptions($mount->getOptions());
161
-			}
162
-			return $storage;
163
-		});
164
-
165
-		\OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
166
-			if (!$mount->getOption('enable_sharing', true)) {
167
-				return new \OC\Files\Storage\Wrapper\PermissionsMask([
168
-					'storage' => $storage,
169
-					'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE
170
-				]);
171
-			}
172
-			return $storage;
173
-		});
174
-
175
-		// install storage availability wrapper, before most other wrappers
176
-		\OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, $storage) {
177
-			if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
178
-				return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]);
179
-			}
180
-			return $storage;
181
-		});
182
-
183
-		\OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
184
-			if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
185
-				return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]);
186
-			}
187
-			return $storage;
188
-		});
189
-
190
-		\OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
191
-			// set up quota for home storages, even for other users
192
-			// which can happen when using sharing
193
-
194
-			/**
195
-			 * @var \OC\Files\Storage\Storage $storage
196
-			 */
197
-			if ($storage->instanceOfStorage('\OC\Files\Storage\Home')
198
-				|| $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')
199
-			) {
200
-				/** @var \OC\Files\Storage\Home $storage */
201
-				if (is_object($storage->getUser())) {
202
-					$user = $storage->getUser()->getUID();
203
-					$quota = OC_Util::getUserQuota($user);
204
-					if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
205
-						return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files'));
206
-					}
207
-				}
208
-			}
209
-
210
-			return $storage;
211
-		});
212
-
213
-		OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user));
214
-		\OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true);
215
-
216
-		//check if we are using an object storage
217
-		$objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null);
218
-		if (isset($objectStore)) {
219
-			self::initObjectStoreRootFS($objectStore);
220
-		} else {
221
-			self::initLocalStorageRootFS();
222
-		}
223
-
224
-		if ($user != '' && !OCP\User::userExists($user)) {
225
-			\OC::$server->getEventLogger()->end('setup_fs');
226
-			return false;
227
-		}
228
-
229
-		//if we aren't logged in, there is no use to set up the filesystem
230
-		if ($user != "") {
231
-
232
-			$userDir = '/' . $user . '/files';
233
-
234
-			//jail the user into his "home" directory
235
-			\OC\Files\Filesystem::init($user, $userDir);
236
-
237
-			OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
238
-		}
239
-		\OC::$server->getEventLogger()->end('setup_fs');
240
-		return true;
241
-	}
242
-
243
-	/**
244
-	 * check if a password is required for each public link
245
-	 *
246
-	 * @return boolean
247
-	 */
248
-	public static function isPublicLinkPasswordRequired() {
249
-		$appConfig = \OC::$server->getAppConfig();
250
-		$enforcePassword = $appConfig->getValue('core', 'shareapi_enforce_links_password', 'no');
251
-		return ($enforcePassword === 'yes') ? true : false;
252
-	}
253
-
254
-	/**
255
-	 * check if sharing is disabled for the current user
256
-	 * @param IConfig $config
257
-	 * @param IGroupManager $groupManager
258
-	 * @param IUser|null $user
259
-	 * @return bool
260
-	 */
261
-	public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) {
262
-		if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
263
-			$groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', '');
264
-			$excludedGroups = json_decode($groupsList);
265
-			if (is_null($excludedGroups)) {
266
-				$excludedGroups = explode(',', $groupsList);
267
-				$newValue = json_encode($excludedGroups);
268
-				$config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue);
269
-			}
270
-			$usersGroups = $groupManager->getUserGroupIds($user);
271
-			if (!empty($usersGroups)) {
272
-				$remainingGroups = array_diff($usersGroups, $excludedGroups);
273
-				// if the user is only in groups which are disabled for sharing then
274
-				// sharing is also disabled for the user
275
-				if (empty($remainingGroups)) {
276
-					return true;
277
-				}
278
-			}
279
-		}
280
-		return false;
281
-	}
282
-
283
-	/**
284
-	 * check if share API enforces a default expire date
285
-	 *
286
-	 * @return boolean
287
-	 */
288
-	public static function isDefaultExpireDateEnforced() {
289
-		$isDefaultExpireDateEnabled = \OCP\Config::getAppValue('core', 'shareapi_default_expire_date', 'no');
290
-		$enforceDefaultExpireDate = false;
291
-		if ($isDefaultExpireDateEnabled === 'yes') {
292
-			$value = \OCP\Config::getAppValue('core', 'shareapi_enforce_expire_date', 'no');
293
-			$enforceDefaultExpireDate = ($value === 'yes') ? true : false;
294
-		}
295
-
296
-		return $enforceDefaultExpireDate;
297
-	}
298
-
299
-	/**
300
-	 * Get the quota of a user
301
-	 *
302
-	 * @param string $userId
303
-	 * @return int Quota bytes
304
-	 */
305
-	public static function getUserQuota($userId) {
306
-		$user = \OC::$server->getUserManager()->get($userId);
307
-		if (is_null($user)) {
308
-			return \OCP\Files\FileInfo::SPACE_UNLIMITED;
309
-		}
310
-		$userQuota = $user->getQuota();
311
-		if($userQuota === 'none') {
312
-			return \OCP\Files\FileInfo::SPACE_UNLIMITED;
313
-		}
314
-		return OC_Helper::computerFileSize($userQuota);
315
-	}
316
-
317
-	/**
318
-	 * copies the skeleton to the users /files
319
-	 *
320
-	 * @param String $userId
321
-	 * @param \OCP\Files\Folder $userDirectory
322
-	 * @throws \RuntimeException
323
-	 */
324
-	public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) {
325
-
326
-		$skeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton');
327
-		$instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', '');
328
-
329
-		if ($instanceId === null) {
330
-			throw new \RuntimeException('no instance id!');
331
-		}
332
-		$appdata = 'appdata_' . $instanceId;
333
-		if ($userId === $appdata) {
334
-			throw new \RuntimeException('username is reserved name: ' . $appdata);
335
-		}
336
-
337
-		if (!empty($skeletonDirectory)) {
338
-			\OCP\Util::writeLog(
339
-				'files_skeleton',
340
-				'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'),
341
-				\OCP\Util::DEBUG
342
-			);
343
-			self::copyr($skeletonDirectory, $userDirectory);
344
-			// update the file cache
345
-			$userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE);
346
-		}
347
-	}
348
-
349
-	/**
350
-	 * copies a directory recursively by using streams
351
-	 *
352
-	 * @param string $source
353
-	 * @param \OCP\Files\Folder $target
354
-	 * @return void
355
-	 */
356
-	public static function copyr($source, \OCP\Files\Folder $target) {
357
-		$logger = \OC::$server->getLogger();
358
-
359
-		// Verify if folder exists
360
-		$dir = opendir($source);
361
-		if($dir === false) {
362
-			$logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']);
363
-			return;
364
-		}
365
-
366
-		// Copy the files
367
-		while (false !== ($file = readdir($dir))) {
368
-			if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
369
-				if (is_dir($source . '/' . $file)) {
370
-					$child = $target->newFolder($file);
371
-					self::copyr($source . '/' . $file, $child);
372
-				} else {
373
-					$child = $target->newFile($file);
374
-					$sourceStream = fopen($source . '/' . $file, 'r');
375
-					if($sourceStream === false) {
376
-						$logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']);
377
-						closedir($dir);
378
-						return;
379
-					}
380
-					stream_copy_to_stream($sourceStream, $child->fopen('w'));
381
-				}
382
-			}
383
-		}
384
-		closedir($dir);
385
-	}
386
-
387
-	/**
388
-	 * @return void
389
-	 */
390
-	public static function tearDownFS() {
391
-		\OC\Files\Filesystem::tearDown();
392
-		\OC::$server->getRootFolder()->clearCache();
393
-		self::$fsSetup = false;
394
-		self::$rootMounted = false;
395
-	}
396
-
397
-	/**
398
-	 * get the current installed version of ownCloud
399
-	 *
400
-	 * @return array
401
-	 */
402
-	public static function getVersion() {
403
-		OC_Util::loadVersion();
404
-		return self::$versionCache['OC_Version'];
405
-	}
406
-
407
-	/**
408
-	 * get the current installed version string of ownCloud
409
-	 *
410
-	 * @return string
411
-	 */
412
-	public static function getVersionString() {
413
-		OC_Util::loadVersion();
414
-		return self::$versionCache['OC_VersionString'];
415
-	}
416
-
417
-	/**
418
-	 * @deprecated the value is of no use anymore
419
-	 * @return string
420
-	 */
421
-	public static function getEditionString() {
422
-		return '';
423
-	}
424
-
425
-	/**
426
-	 * @description get the update channel of the current installed of ownCloud.
427
-	 * @return string
428
-	 */
429
-	public static function getChannel() {
430
-		OC_Util::loadVersion();
431
-		return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']);
432
-	}
433
-
434
-	/**
435
-	 * @description get the build number of the current installed of ownCloud.
436
-	 * @return string
437
-	 */
438
-	public static function getBuild() {
439
-		OC_Util::loadVersion();
440
-		return self::$versionCache['OC_Build'];
441
-	}
442
-
443
-	/**
444
-	 * @description load the version.php into the session as cache
445
-	 */
446
-	private static function loadVersion() {
447
-		if (self::$versionCache !== null) {
448
-			return;
449
-		}
450
-
451
-		$timestamp = filemtime(OC::$SERVERROOT . '/version.php');
452
-		require OC::$SERVERROOT . '/version.php';
453
-		/** @var $timestamp int */
454
-		self::$versionCache['OC_Version_Timestamp'] = $timestamp;
455
-		/** @var $OC_Version string */
456
-		self::$versionCache['OC_Version'] = $OC_Version;
457
-		/** @var $OC_VersionString string */
458
-		self::$versionCache['OC_VersionString'] = $OC_VersionString;
459
-		/** @var $OC_Build string */
460
-		self::$versionCache['OC_Build'] = $OC_Build;
461
-
462
-		/** @var $OC_Channel string */
463
-		self::$versionCache['OC_Channel'] = $OC_Channel;
464
-	}
465
-
466
-	/**
467
-	 * generates a path for JS/CSS files. If no application is provided it will create the path for core.
468
-	 *
469
-	 * @param string $application application to get the files from
470
-	 * @param string $directory directory within this application (css, js, vendor, etc)
471
-	 * @param string $file the file inside of the above folder
472
-	 * @return string the path
473
-	 */
474
-	private static function generatePath($application, $directory, $file) {
475
-		if (is_null($file)) {
476
-			$file = $application;
477
-			$application = "";
478
-		}
479
-		if (!empty($application)) {
480
-			return "$application/$directory/$file";
481
-		} else {
482
-			return "$directory/$file";
483
-		}
484
-	}
485
-
486
-	/**
487
-	 * add a javascript file
488
-	 *
489
-	 * @param string $application application id
490
-	 * @param string|null $file filename
491
-	 * @param bool $prepend prepend the Script to the beginning of the list
492
-	 * @return void
493
-	 */
494
-	public static function addScript($application, $file = null, $prepend = false) {
495
-		$path = OC_Util::generatePath($application, 'js', $file);
496
-
497
-		// core js files need separate handling
498
-		if ($application !== 'core' && $file !== null) {
499
-			self::addTranslations ( $application );
500
-		}
501
-		self::addExternalResource($application, $prepend, $path, "script");
502
-	}
503
-
504
-	/**
505
-	 * add a javascript file from the vendor sub folder
506
-	 *
507
-	 * @param string $application application id
508
-	 * @param string|null $file filename
509
-	 * @param bool $prepend prepend the Script to the beginning of the list
510
-	 * @return void
511
-	 */
512
-	public static function addVendorScript($application, $file = null, $prepend = false) {
513
-		$path = OC_Util::generatePath($application, 'vendor', $file);
514
-		self::addExternalResource($application, $prepend, $path, "script");
515
-	}
516
-
517
-	/**
518
-	 * add a translation JS file
519
-	 *
520
-	 * @param string $application application id
521
-	 * @param string $languageCode language code, defaults to the current language
522
-	 * @param bool $prepend prepend the Script to the beginning of the list
523
-	 */
524
-	public static function addTranslations($application, $languageCode = null, $prepend = false) {
525
-		if (is_null($languageCode)) {
526
-			$languageCode = \OC::$server->getL10NFactory()->findLanguage($application);
527
-		}
528
-		if (!empty($application)) {
529
-			$path = "$application/l10n/$languageCode";
530
-		} else {
531
-			$path = "l10n/$languageCode";
532
-		}
533
-		self::addExternalResource($application, $prepend, $path, "script");
534
-	}
535
-
536
-	/**
537
-	 * add a css file
538
-	 *
539
-	 * @param string $application application id
540
-	 * @param string|null $file filename
541
-	 * @param bool $prepend prepend the Style to the beginning of the list
542
-	 * @return void
543
-	 */
544
-	public static function addStyle($application, $file = null, $prepend = false) {
545
-		$path = OC_Util::generatePath($application, 'css', $file);
546
-		self::addExternalResource($application, $prepend, $path, "style");
547
-	}
548
-
549
-	/**
550
-	 * add a css file from the vendor sub folder
551
-	 *
552
-	 * @param string $application application id
553
-	 * @param string|null $file filename
554
-	 * @param bool $prepend prepend the Style to the beginning of the list
555
-	 * @return void
556
-	 */
557
-	public static function addVendorStyle($application, $file = null, $prepend = false) {
558
-		$path = OC_Util::generatePath($application, 'vendor', $file);
559
-		self::addExternalResource($application, $prepend, $path, "style");
560
-	}
561
-
562
-	/**
563
-	 * add an external resource css/js file
564
-	 *
565
-	 * @param string $application application id
566
-	 * @param bool $prepend prepend the file to the beginning of the list
567
-	 * @param string $path
568
-	 * @param string $type (script or style)
569
-	 * @return void
570
-	 */
571
-	private static function addExternalResource($application, $prepend, $path, $type = "script") {
572
-
573
-		if ($type === "style") {
574
-			if (!in_array($path, self::$styles)) {
575
-				if ($prepend === true) {
576
-					array_unshift ( self::$styles, $path );
577
-				} else {
578
-					self::$styles[] = $path;
579
-				}
580
-			}
581
-		} elseif ($type === "script") {
582
-			if (!in_array($path, self::$scripts)) {
583
-				if ($prepend === true) {
584
-					array_unshift ( self::$scripts, $path );
585
-				} else {
586
-					self::$scripts [] = $path;
587
-				}
588
-			}
589
-		}
590
-	}
591
-
592
-	/**
593
-	 * Add a custom element to the header
594
-	 * If $text is null then the element will be written as empty element.
595
-	 * So use "" to get a closing tag.
596
-	 * @param string $tag tag name of the element
597
-	 * @param array $attributes array of attributes for the element
598
-	 * @param string $text the text content for the element
599
-	 */
600
-	public static function addHeader($tag, $attributes, $text=null) {
601
-		self::$headers[] = array(
602
-			'tag' => $tag,
603
-			'attributes' => $attributes,
604
-			'text' => $text
605
-		);
606
-	}
607
-
608
-	/**
609
-	 * formats a timestamp in the "right" way
610
-	 *
611
-	 * @param int $timestamp
612
-	 * @param bool $dateOnly option to omit time from the result
613
-	 * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to
614
-	 * @return string timestamp
615
-	 *
616
-	 * @deprecated Use \OC::$server->query('DateTimeFormatter') instead
617
-	 */
618
-	public static function formatDate($timestamp, $dateOnly = false, $timeZone = null) {
619
-		if ($timeZone !== null && !$timeZone instanceof \DateTimeZone) {
620
-			$timeZone = new \DateTimeZone($timeZone);
621
-		}
622
-
623
-		/** @var \OC\DateTimeFormatter $formatter */
624
-		$formatter = \OC::$server->query('DateTimeFormatter');
625
-		if ($dateOnly) {
626
-			return $formatter->formatDate($timestamp, 'long', $timeZone);
627
-		}
628
-		return $formatter->formatDateTime($timestamp, 'long', 'long', $timeZone);
629
-	}
630
-
631
-	/**
632
-	 * check if the current server configuration is suitable for ownCloud
633
-	 *
634
-	 * @param \OC\SystemConfig $config
635
-	 * @return array arrays with error messages and hints
636
-	 */
637
-	public static function checkServer(\OC\SystemConfig $config) {
638
-		$l = \OC::$server->getL10N('lib');
639
-		$errors = array();
640
-		$CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data');
641
-
642
-		if (!self::needUpgrade($config) && $config->getValue('installed', false)) {
643
-			// this check needs to be done every time
644
-			$errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY);
645
-		}
646
-
647
-		// Assume that if checkServer() succeeded before in this session, then all is fine.
648
-		if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) {
649
-			return $errors;
650
-		}
651
-
652
-		$webServerRestart = false;
653
-		$setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'),
654
-			\OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(), \OC::$server->getSecureRandom());
655
-
656
-		$urlGenerator = \OC::$server->getURLGenerator();
657
-
658
-		$availableDatabases = $setup->getSupportedDatabases();
659
-		if (empty($availableDatabases)) {
660
-			$errors[] = array(
661
-				'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'),
662
-				'hint' => '' //TODO: sane hint
663
-			);
664
-			$webServerRestart = true;
665
-		}
666
-
667
-		// Check if config folder is writable.
668
-		if(!OC_Helper::isReadOnlyConfigEnabled()) {
669
-			if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) {
670
-				$errors[] = array(
671
-					'error' => $l->t('Cannot write into "config" directory'),
672
-					'hint' => $l->t('This can usually be fixed by '
673
-						. '%sgiving the webserver write access to the config directory%s.',
674
-						array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>'))
675
-				);
676
-			}
677
-		}
678
-
679
-		// Check if there is a writable install folder.
680
-		if ($config->getValue('appstoreenabled', true)) {
681
-			if (OC_App::getInstallPath() === null
682
-				|| !is_writable(OC_App::getInstallPath())
683
-				|| !is_readable(OC_App::getInstallPath())
684
-			) {
685
-				$errors[] = array(
686
-					'error' => $l->t('Cannot write into "apps" directory'),
687
-					'hint' => $l->t('This can usually be fixed by '
688
-						. '%sgiving the webserver write access to the apps directory%s'
689
-						. ' or disabling the appstore in the config file.',
690
-						array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>'))
691
-				);
692
-			}
693
-		}
694
-		// Create root dir.
695
-		if ($config->getValue('installed', false)) {
696
-			if (!is_dir($CONFIG_DATADIRECTORY)) {
697
-				$success = @mkdir($CONFIG_DATADIRECTORY);
698
-				if ($success) {
699
-					$errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY));
700
-				} else {
701
-					$errors[] = [
702
-						'error' => $l->t('Cannot create "data" directory'),
703
-						'hint' => $l->t('This can usually be fixed by '
704
-							. '<a href="%s" target="_blank" rel="noreferrer">giving the webserver write access to the root directory</a>.',
705
-							[$urlGenerator->linkToDocs('admin-dir_permissions')])
706
-					];
707
-				}
708
-			} else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) {
709
-				//common hint for all file permissions error messages
710
-				$permissionsHint = $l->t('Permissions can usually be fixed by '
711
-					. '%sgiving the webserver write access to the root directory%s.',
712
-					['<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>']);
713
-				$errors[] = [
714
-					'error' => 'Your data directory is not writable',
715
-					'hint' => $permissionsHint
716
-				];
717
-			} else {
718
-				$errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY));
719
-			}
720
-		}
721
-
722
-		if (!OC_Util::isSetLocaleWorking()) {
723
-			$errors[] = array(
724
-				'error' => $l->t('Setting locale to %s failed',
725
-					array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/'
726
-						. 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')),
727
-				'hint' => $l->t('Please install one of these locales on your system and restart your webserver.')
728
-			);
729
-		}
730
-
731
-		// Contains the dependencies that should be checked against
732
-		// classes = class_exists
733
-		// functions = function_exists
734
-		// defined = defined
735
-		// ini = ini_get
736
-		// If the dependency is not found the missing module name is shown to the EndUser
737
-		// When adding new checks always verify that they pass on Travis as well
738
-		// for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini
739
-		$dependencies = array(
740
-			'classes' => array(
741
-				'ZipArchive' => 'zip',
742
-				'DOMDocument' => 'dom',
743
-				'XMLWriter' => 'XMLWriter',
744
-				'XMLReader' => 'XMLReader',
745
-			),
746
-			'functions' => [
747
-				'xml_parser_create' => 'libxml',
748
-				'mb_strcut' => 'mb multibyte',
749
-				'ctype_digit' => 'ctype',
750
-				'json_encode' => 'JSON',
751
-				'gd_info' => 'GD',
752
-				'gzencode' => 'zlib',
753
-				'iconv' => 'iconv',
754
-				'simplexml_load_string' => 'SimpleXML',
755
-				'hash' => 'HASH Message Digest Framework',
756
-				'curl_init' => 'cURL',
757
-				'openssl_verify' => 'OpenSSL',
758
-			],
759
-			'defined' => array(
760
-				'PDO::ATTR_DRIVER_NAME' => 'PDO'
761
-			),
762
-			'ini' => [
763
-				'default_charset' => 'UTF-8',
764
-			],
765
-		);
766
-		$missingDependencies = array();
767
-		$invalidIniSettings = [];
768
-		$moduleHint = $l->t('Please ask your server administrator to install the module.');
769
-
770
-		/**
771
-		 * FIXME: The dependency check does not work properly on HHVM on the moment
772
-		 *        and prevents installation. Once HHVM is more compatible with our
773
-		 *        approach to check for these values we should re-enable those
774
-		 *        checks.
775
-		 */
776
-		$iniWrapper = \OC::$server->getIniWrapper();
777
-		if (!self::runningOnHhvm()) {
778
-			foreach ($dependencies['classes'] as $class => $module) {
779
-				if (!class_exists($class)) {
780
-					$missingDependencies[] = $module;
781
-				}
782
-			}
783
-			foreach ($dependencies['functions'] as $function => $module) {
784
-				if (!function_exists($function)) {
785
-					$missingDependencies[] = $module;
786
-				}
787
-			}
788
-			foreach ($dependencies['defined'] as $defined => $module) {
789
-				if (!defined($defined)) {
790
-					$missingDependencies[] = $module;
791
-				}
792
-			}
793
-			foreach ($dependencies['ini'] as $setting => $expected) {
794
-				if (is_bool($expected)) {
795
-					if ($iniWrapper->getBool($setting) !== $expected) {
796
-						$invalidIniSettings[] = [$setting, $expected];
797
-					}
798
-				}
799
-				if (is_int($expected)) {
800
-					if ($iniWrapper->getNumeric($setting) !== $expected) {
801
-						$invalidIniSettings[] = [$setting, $expected];
802
-					}
803
-				}
804
-				if (is_string($expected)) {
805
-					if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) {
806
-						$invalidIniSettings[] = [$setting, $expected];
807
-					}
808
-				}
809
-			}
810
-		}
811
-
812
-		foreach($missingDependencies as $missingDependency) {
813
-			$errors[] = array(
814
-				'error' => $l->t('PHP module %s not installed.', array($missingDependency)),
815
-				'hint' => $moduleHint
816
-			);
817
-			$webServerRestart = true;
818
-		}
819
-		foreach($invalidIniSettings as $setting) {
820
-			if(is_bool($setting[1])) {
821
-				$setting[1] = ($setting[1]) ? 'on' : 'off';
822
-			}
823
-			$errors[] = [
824
-				'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]),
825
-				'hint' =>  $l->t('Adjusting this setting in php.ini will make Nextcloud run again')
826
-			];
827
-			$webServerRestart = true;
828
-		}
829
-
830
-		/**
831
-		 * The mbstring.func_overload check can only be performed if the mbstring
832
-		 * module is installed as it will return null if the checking setting is
833
-		 * not available and thus a check on the boolean value fails.
834
-		 *
835
-		 * TODO: Should probably be implemented in the above generic dependency
836
-		 *       check somehow in the long-term.
837
-		 */
838
-		if($iniWrapper->getBool('mbstring.func_overload') !== null &&
839
-			$iniWrapper->getBool('mbstring.func_overload') === true) {
840
-			$errors[] = array(
841
-				'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]),
842
-				'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini')
843
-			);
844
-		}
845
-
846
-		if(function_exists('xml_parser_create') &&
847
-			LIBXML_LOADED_VERSION < 20700 ) {
848
-			$version = LIBXML_LOADED_VERSION;
849
-			$major = floor($version/10000);
850
-			$version -= ($major * 10000);
851
-			$minor = floor($version/100);
852
-			$version -= ($minor * 100);
853
-			$patch = $version;
854
-			$errors[] = array(
855
-				'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]),
856
-				'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.')
857
-			);
858
-		}
859
-
860
-		if (!self::isAnnotationsWorking()) {
861
-			$errors[] = array(
862
-				'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'),
863
-				'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.')
864
-			);
865
-		}
866
-
867
-		if (!\OC::$CLI && $webServerRestart) {
868
-			$errors[] = array(
869
-				'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'),
870
-				'hint' => $l->t('Please ask your server administrator to restart the web server.')
871
-			);
872
-		}
873
-
874
-		$errors = array_merge($errors, self::checkDatabaseVersion());
875
-
876
-		// Cache the result of this function
877
-		\OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0);
878
-
879
-		return $errors;
880
-	}
881
-
882
-	/**
883
-	 * Check the database version
884
-	 *
885
-	 * @return array errors array
886
-	 */
887
-	public static function checkDatabaseVersion() {
888
-		$l = \OC::$server->getL10N('lib');
889
-		$errors = array();
890
-		$dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite');
891
-		if ($dbType === 'pgsql') {
892
-			// check PostgreSQL version
893
-			try {
894
-				$result = \OC_DB::executeAudited('SHOW SERVER_VERSION');
895
-				$data = $result->fetchRow();
896
-				if (isset($data['server_version'])) {
897
-					$version = $data['server_version'];
898
-					if (version_compare($version, '9.0.0', '<')) {
899
-						$errors[] = array(
900
-							'error' => $l->t('PostgreSQL >= 9 required'),
901
-							'hint' => $l->t('Please upgrade your database version')
902
-						);
903
-					}
904
-				}
905
-			} catch (\Doctrine\DBAL\DBALException $e) {
906
-				$logger = \OC::$server->getLogger();
907
-				$logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9');
908
-				$logger->logException($e);
909
-			}
910
-		}
911
-		return $errors;
912
-	}
913
-
914
-	/**
915
-	 * Check for correct file permissions of data directory
916
-	 *
917
-	 * @param string $dataDirectory
918
-	 * @return array arrays with error messages and hints
919
-	 */
920
-	public static function checkDataDirectoryPermissions($dataDirectory) {
921
-		$l = \OC::$server->getL10N('lib');
922
-		$errors = array();
923
-		$permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory'
924
-			. ' cannot be listed by other users.');
925
-		$perms = substr(decoct(@fileperms($dataDirectory)), -3);
926
-		if (substr($perms, -1) !== '0') {
927
-			chmod($dataDirectory, 0770);
928
-			clearstatcache();
929
-			$perms = substr(decoct(@fileperms($dataDirectory)), -3);
930
-			if ($perms[2] !== '0') {
931
-				$errors[] = [
932
-					'error' => $l->t('Your data directory is readable by other users'),
933
-					'hint' => $permissionsModHint
934
-				];
935
-			}
936
-		}
937
-		return $errors;
938
-	}
939
-
940
-	/**
941
-	 * Check that the data directory exists and is valid by
942
-	 * checking the existence of the ".ocdata" file.
943
-	 *
944
-	 * @param string $dataDirectory data directory path
945
-	 * @return array errors found
946
-	 */
947
-	public static function checkDataDirectoryValidity($dataDirectory) {
948
-		$l = \OC::$server->getL10N('lib');
949
-		$errors = [];
950
-		if ($dataDirectory[0] !== '/') {
951
-			$errors[] = [
952
-				'error' => $l->t('Your data directory must be an absolute path'),
953
-				'hint' => $l->t('Check the value of "datadirectory" in your configuration')
954
-			];
955
-		}
956
-		if (!file_exists($dataDirectory . '/.ocdata')) {
957
-			$errors[] = [
958
-				'error' => $l->t('Your data directory  is invalid'),
959
-				'hint' => $l->t('Please check that the data directory contains a file' .
960
-					' ".ocdata" in its root.')
961
-			];
962
-		}
963
-		return $errors;
964
-	}
965
-
966
-	/**
967
-	 * Check if the user is logged in, redirects to home if not. With
968
-	 * redirect URL parameter to the request URI.
969
-	 *
970
-	 * @return void
971
-	 */
972
-	public static function checkLoggedIn() {
973
-		// Check if we are a user
974
-		if (!\OC::$server->getUserSession()->isLoggedIn()) {
975
-			header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute(
976
-						'core.login.showLoginForm',
977
-						[
978
-							'redirect_url' => \OC::$server->getRequest()->getRequestUri(),
979
-						]
980
-					)
981
-			);
982
-			exit();
983
-		}
984
-		// Redirect to 2FA challenge selection if 2FA challenge was not solved yet
985
-		if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) {
986
-			header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge'));
987
-			exit();
988
-		}
989
-	}
990
-
991
-	/**
992
-	 * Check if the user is a admin, redirects to home if not
993
-	 *
994
-	 * @return void
995
-	 */
996
-	public static function checkAdminUser() {
997
-		OC_Util::checkLoggedIn();
998
-		if (!OC_User::isAdminUser(OC_User::getUser())) {
999
-			header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php'));
1000
-			exit();
1001
-		}
1002
-	}
1003
-
1004
-	/**
1005
-	 * Check if the user is a subadmin, redirects to home if not
1006
-	 *
1007
-	 * @return null|boolean $groups where the current user is subadmin
1008
-	 */
1009
-	public static function checkSubAdminUser() {
1010
-		OC_Util::checkLoggedIn();
1011
-		$userObject = \OC::$server->getUserSession()->getUser();
1012
-		$isSubAdmin = false;
1013
-		if($userObject !== null) {
1014
-			$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
1015
-		}
1016
-
1017
-		if (!$isSubAdmin) {
1018
-			header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php'));
1019
-			exit();
1020
-		}
1021
-		return true;
1022
-	}
1023
-
1024
-	/**
1025
-	 * Returns the URL of the default page
1026
-	 * based on the system configuration and
1027
-	 * the apps visible for the current user
1028
-	 *
1029
-	 * @return string URL
1030
-	 */
1031
-	public static function getDefaultPageUrl() {
1032
-		$urlGenerator = \OC::$server->getURLGenerator();
1033
-		// Deny the redirect if the URL contains a @
1034
-		// This prevents unvalidated redirects like ?redirect_url=:[email protected]
1035
-		if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) {
1036
-			$location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url']));
1037
-		} else {
1038
-			$defaultPage = \OC::$server->getAppConfig()->getValue('core', 'defaultpage');
1039
-			if ($defaultPage) {
1040
-				$location = $urlGenerator->getAbsoluteURL($defaultPage);
1041
-			} else {
1042
-				$appId = 'files';
1043
-				$defaultApps = explode(',', \OCP\Config::getSystemValue('defaultapp', 'files'));
1044
-				// find the first app that is enabled for the current user
1045
-				foreach ($defaultApps as $defaultApp) {
1046
-					$defaultApp = OC_App::cleanAppId(strip_tags($defaultApp));
1047
-					if (static::getAppManager()->isEnabledForUser($defaultApp)) {
1048
-						$appId = $defaultApp;
1049
-						break;
1050
-					}
1051
-				}
1052
-
1053
-				if(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') {
1054
-					$location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/');
1055
-				} else {
1056
-					$location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/');
1057
-				}
1058
-			}
1059
-		}
1060
-		return $location;
1061
-	}
1062
-
1063
-	/**
1064
-	 * Redirect to the user default page
1065
-	 *
1066
-	 * @return void
1067
-	 */
1068
-	public static function redirectToDefaultPage() {
1069
-		$location = self::getDefaultPageUrl();
1070
-		header('Location: ' . $location);
1071
-		exit();
1072
-	}
1073
-
1074
-	/**
1075
-	 * get an id unique for this instance
1076
-	 *
1077
-	 * @return string
1078
-	 */
1079
-	public static function getInstanceId() {
1080
-		$id = \OC::$server->getSystemConfig()->getValue('instanceid', null);
1081
-		if (is_null($id)) {
1082
-			// We need to guarantee at least one letter in instanceid so it can be used as the session_name
1083
-			$id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
1084
-			\OC::$server->getSystemConfig()->setValue('instanceid', $id);
1085
-		}
1086
-		return $id;
1087
-	}
1088
-
1089
-	/**
1090
-	 * Public function to sanitize HTML
1091
-	 *
1092
-	 * This function is used to sanitize HTML and should be applied on any
1093
-	 * string or array of strings before displaying it on a web page.
1094
-	 *
1095
-	 * @param string|array $value
1096
-	 * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
1097
-	 */
1098
-	public static function sanitizeHTML($value) {
1099
-		if (is_array($value)) {
1100
-			$value = array_map(function($value) {
1101
-				return self::sanitizeHTML($value);
1102
-			}, $value);
1103
-		} else {
1104
-			// Specify encoding for PHP<5.4
1105
-			$value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
1106
-		}
1107
-		return $value;
1108
-	}
1109
-
1110
-	/**
1111
-	 * Public function to encode url parameters
1112
-	 *
1113
-	 * This function is used to encode path to file before output.
1114
-	 * Encoding is done according to RFC 3986 with one exception:
1115
-	 * Character '/' is preserved as is.
1116
-	 *
1117
-	 * @param string $component part of URI to encode
1118
-	 * @return string
1119
-	 */
1120
-	public static function encodePath($component) {
1121
-		$encoded = rawurlencode($component);
1122
-		$encoded = str_replace('%2F', '/', $encoded);
1123
-		return $encoded;
1124
-	}
1125
-
1126
-
1127
-	public function createHtaccessTestFile(\OCP\IConfig $config) {
1128
-		// php dev server does not support htaccess
1129
-		if (php_sapi_name() === 'cli-server') {
1130
-			return false;
1131
-		}
1132
-
1133
-		// testdata
1134
-		$fileName = '/htaccesstest.txt';
1135
-		$testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.';
1136
-
1137
-		// creating a test file
1138
-		$testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName;
1139
-
1140
-		if (file_exists($testFile)) {// already running this test, possible recursive call
1141
-			return false;
1142
-		}
1143
-
1144
-		$fp = @fopen($testFile, 'w');
1145
-		if (!$fp) {
1146
-			throw new OC\HintException('Can\'t create test file to check for working .htaccess file.',
1147
-				'Make sure it is possible for the webserver to write to ' . $testFile);
1148
-		}
1149
-		fwrite($fp, $testContent);
1150
-		fclose($fp);
1151
-
1152
-		return $testContent;
1153
-	}
1154
-
1155
-	/**
1156
-	 * Check if the .htaccess file is working
1157
-	 * @param \OCP\IConfig $config
1158
-	 * @return bool
1159
-	 * @throws Exception
1160
-	 * @throws \OC\HintException If the test file can't get written.
1161
-	 */
1162
-	public function isHtaccessWorking(\OCP\IConfig $config) {
1163
-
1164
-		if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) {
1165
-			return true;
1166
-		}
1167
-
1168
-		$testContent = $this->createHtaccessTestFile($config);
1169
-		if ($testContent === false) {
1170
-			return false;
1171
-		}
1172
-
1173
-		$fileName = '/htaccesstest.txt';
1174
-		$testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName;
1175
-
1176
-		// accessing the file via http
1177
-		$url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName);
1178
-		try {
1179
-			$content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody();
1180
-		} catch (\Exception $e) {
1181
-			$content = false;
1182
-		}
1183
-
1184
-		// cleanup
1185
-		@unlink($testFile);
1186
-
1187
-		/*
64
+    public static $scripts = array();
65
+    public static $styles = array();
66
+    public static $headers = array();
67
+    private static $rootMounted = false;
68
+    private static $fsSetup = false;
69
+
70
+    /** @var array Local cache of version.php */
71
+    private static $versionCache = null;
72
+
73
+    protected static function getAppManager() {
74
+        return \OC::$server->getAppManager();
75
+    }
76
+
77
+    private static function initLocalStorageRootFS() {
78
+        // mount local file backend as root
79
+        $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data");
80
+        //first set up the local "root" storage
81
+        \OC\Files\Filesystem::initMountManager();
82
+        if (!self::$rootMounted) {
83
+            \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/');
84
+            self::$rootMounted = true;
85
+        }
86
+    }
87
+
88
+    /**
89
+     * mounting an object storage as the root fs will in essence remove the
90
+     * necessity of a data folder being present.
91
+     * TODO make home storage aware of this and use the object storage instead of local disk access
92
+     *
93
+     * @param array $config containing 'class' and optional 'arguments'
94
+     */
95
+    private static function initObjectStoreRootFS($config) {
96
+        // check misconfiguration
97
+        if (empty($config['class'])) {
98
+            \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
99
+        }
100
+        if (!isset($config['arguments'])) {
101
+            $config['arguments'] = array();
102
+        }
103
+
104
+        // instantiate object store implementation
105
+        $name = $config['class'];
106
+        if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) {
107
+            $segments = explode('\\', $name);
108
+            OC_App::loadApp(strtolower($segments[1]));
109
+        }
110
+        $config['arguments']['objectstore'] = new $config['class']($config['arguments']);
111
+        // mount with plain / root object store implementation
112
+        $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage';
113
+
114
+        // mount object storage as root
115
+        \OC\Files\Filesystem::initMountManager();
116
+        if (!self::$rootMounted) {
117
+            \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/');
118
+            self::$rootMounted = true;
119
+        }
120
+    }
121
+
122
+    /**
123
+     * Can be set up
124
+     *
125
+     * @param string $user
126
+     * @return boolean
127
+     * @description configure the initial filesystem based on the configuration
128
+     */
129
+    public static function setupFS($user = '') {
130
+        //setting up the filesystem twice can only lead to trouble
131
+        if (self::$fsSetup) {
132
+            return false;
133
+        }
134
+
135
+        \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem');
136
+
137
+        // If we are not forced to load a specific user we load the one that is logged in
138
+        if ($user === null) {
139
+            $user = '';
140
+        } else if ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) {
141
+            $user = OC_User::getUser();
142
+        }
143
+
144
+        // load all filesystem apps before, so no setup-hook gets lost
145
+        OC_App::loadApps(array('filesystem'));
146
+
147
+        // the filesystem will finish when $user is not empty,
148
+        // mark fs setup here to avoid doing the setup from loading
149
+        // OC_Filesystem
150
+        if ($user != '') {
151
+            self::$fsSetup = true;
152
+        }
153
+
154
+        \OC\Files\Filesystem::initMountManager();
155
+
156
+        \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false);
157
+        \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
158
+            if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) {
159
+                /** @var \OC\Files\Storage\Common $storage */
160
+                $storage->setMountOptions($mount->getOptions());
161
+            }
162
+            return $storage;
163
+        });
164
+
165
+        \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
166
+            if (!$mount->getOption('enable_sharing', true)) {
167
+                return new \OC\Files\Storage\Wrapper\PermissionsMask([
168
+                    'storage' => $storage,
169
+                    'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE
170
+                ]);
171
+            }
172
+            return $storage;
173
+        });
174
+
175
+        // install storage availability wrapper, before most other wrappers
176
+        \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, $storage) {
177
+            if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
178
+                return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]);
179
+            }
180
+            return $storage;
181
+        });
182
+
183
+        \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
184
+            if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
185
+                return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]);
186
+            }
187
+            return $storage;
188
+        });
189
+
190
+        \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
191
+            // set up quota for home storages, even for other users
192
+            // which can happen when using sharing
193
+
194
+            /**
195
+             * @var \OC\Files\Storage\Storage $storage
196
+             */
197
+            if ($storage->instanceOfStorage('\OC\Files\Storage\Home')
198
+                || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')
199
+            ) {
200
+                /** @var \OC\Files\Storage\Home $storage */
201
+                if (is_object($storage->getUser())) {
202
+                    $user = $storage->getUser()->getUID();
203
+                    $quota = OC_Util::getUserQuota($user);
204
+                    if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
205
+                        return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files'));
206
+                    }
207
+                }
208
+            }
209
+
210
+            return $storage;
211
+        });
212
+
213
+        OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user));
214
+        \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true);
215
+
216
+        //check if we are using an object storage
217
+        $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null);
218
+        if (isset($objectStore)) {
219
+            self::initObjectStoreRootFS($objectStore);
220
+        } else {
221
+            self::initLocalStorageRootFS();
222
+        }
223
+
224
+        if ($user != '' && !OCP\User::userExists($user)) {
225
+            \OC::$server->getEventLogger()->end('setup_fs');
226
+            return false;
227
+        }
228
+
229
+        //if we aren't logged in, there is no use to set up the filesystem
230
+        if ($user != "") {
231
+
232
+            $userDir = '/' . $user . '/files';
233
+
234
+            //jail the user into his "home" directory
235
+            \OC\Files\Filesystem::init($user, $userDir);
236
+
237
+            OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
238
+        }
239
+        \OC::$server->getEventLogger()->end('setup_fs');
240
+        return true;
241
+    }
242
+
243
+    /**
244
+     * check if a password is required for each public link
245
+     *
246
+     * @return boolean
247
+     */
248
+    public static function isPublicLinkPasswordRequired() {
249
+        $appConfig = \OC::$server->getAppConfig();
250
+        $enforcePassword = $appConfig->getValue('core', 'shareapi_enforce_links_password', 'no');
251
+        return ($enforcePassword === 'yes') ? true : false;
252
+    }
253
+
254
+    /**
255
+     * check if sharing is disabled for the current user
256
+     * @param IConfig $config
257
+     * @param IGroupManager $groupManager
258
+     * @param IUser|null $user
259
+     * @return bool
260
+     */
261
+    public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) {
262
+        if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
263
+            $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', '');
264
+            $excludedGroups = json_decode($groupsList);
265
+            if (is_null($excludedGroups)) {
266
+                $excludedGroups = explode(',', $groupsList);
267
+                $newValue = json_encode($excludedGroups);
268
+                $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue);
269
+            }
270
+            $usersGroups = $groupManager->getUserGroupIds($user);
271
+            if (!empty($usersGroups)) {
272
+                $remainingGroups = array_diff($usersGroups, $excludedGroups);
273
+                // if the user is only in groups which are disabled for sharing then
274
+                // sharing is also disabled for the user
275
+                if (empty($remainingGroups)) {
276
+                    return true;
277
+                }
278
+            }
279
+        }
280
+        return false;
281
+    }
282
+
283
+    /**
284
+     * check if share API enforces a default expire date
285
+     *
286
+     * @return boolean
287
+     */
288
+    public static function isDefaultExpireDateEnforced() {
289
+        $isDefaultExpireDateEnabled = \OCP\Config::getAppValue('core', 'shareapi_default_expire_date', 'no');
290
+        $enforceDefaultExpireDate = false;
291
+        if ($isDefaultExpireDateEnabled === 'yes') {
292
+            $value = \OCP\Config::getAppValue('core', 'shareapi_enforce_expire_date', 'no');
293
+            $enforceDefaultExpireDate = ($value === 'yes') ? true : false;
294
+        }
295
+
296
+        return $enforceDefaultExpireDate;
297
+    }
298
+
299
+    /**
300
+     * Get the quota of a user
301
+     *
302
+     * @param string $userId
303
+     * @return int Quota bytes
304
+     */
305
+    public static function getUserQuota($userId) {
306
+        $user = \OC::$server->getUserManager()->get($userId);
307
+        if (is_null($user)) {
308
+            return \OCP\Files\FileInfo::SPACE_UNLIMITED;
309
+        }
310
+        $userQuota = $user->getQuota();
311
+        if($userQuota === 'none') {
312
+            return \OCP\Files\FileInfo::SPACE_UNLIMITED;
313
+        }
314
+        return OC_Helper::computerFileSize($userQuota);
315
+    }
316
+
317
+    /**
318
+     * copies the skeleton to the users /files
319
+     *
320
+     * @param String $userId
321
+     * @param \OCP\Files\Folder $userDirectory
322
+     * @throws \RuntimeException
323
+     */
324
+    public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) {
325
+
326
+        $skeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton');
327
+        $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', '');
328
+
329
+        if ($instanceId === null) {
330
+            throw new \RuntimeException('no instance id!');
331
+        }
332
+        $appdata = 'appdata_' . $instanceId;
333
+        if ($userId === $appdata) {
334
+            throw new \RuntimeException('username is reserved name: ' . $appdata);
335
+        }
336
+
337
+        if (!empty($skeletonDirectory)) {
338
+            \OCP\Util::writeLog(
339
+                'files_skeleton',
340
+                'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'),
341
+                \OCP\Util::DEBUG
342
+            );
343
+            self::copyr($skeletonDirectory, $userDirectory);
344
+            // update the file cache
345
+            $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE);
346
+        }
347
+    }
348
+
349
+    /**
350
+     * copies a directory recursively by using streams
351
+     *
352
+     * @param string $source
353
+     * @param \OCP\Files\Folder $target
354
+     * @return void
355
+     */
356
+    public static function copyr($source, \OCP\Files\Folder $target) {
357
+        $logger = \OC::$server->getLogger();
358
+
359
+        // Verify if folder exists
360
+        $dir = opendir($source);
361
+        if($dir === false) {
362
+            $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']);
363
+            return;
364
+        }
365
+
366
+        // Copy the files
367
+        while (false !== ($file = readdir($dir))) {
368
+            if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
369
+                if (is_dir($source . '/' . $file)) {
370
+                    $child = $target->newFolder($file);
371
+                    self::copyr($source . '/' . $file, $child);
372
+                } else {
373
+                    $child = $target->newFile($file);
374
+                    $sourceStream = fopen($source . '/' . $file, 'r');
375
+                    if($sourceStream === false) {
376
+                        $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']);
377
+                        closedir($dir);
378
+                        return;
379
+                    }
380
+                    stream_copy_to_stream($sourceStream, $child->fopen('w'));
381
+                }
382
+            }
383
+        }
384
+        closedir($dir);
385
+    }
386
+
387
+    /**
388
+     * @return void
389
+     */
390
+    public static function tearDownFS() {
391
+        \OC\Files\Filesystem::tearDown();
392
+        \OC::$server->getRootFolder()->clearCache();
393
+        self::$fsSetup = false;
394
+        self::$rootMounted = false;
395
+    }
396
+
397
+    /**
398
+     * get the current installed version of ownCloud
399
+     *
400
+     * @return array
401
+     */
402
+    public static function getVersion() {
403
+        OC_Util::loadVersion();
404
+        return self::$versionCache['OC_Version'];
405
+    }
406
+
407
+    /**
408
+     * get the current installed version string of ownCloud
409
+     *
410
+     * @return string
411
+     */
412
+    public static function getVersionString() {
413
+        OC_Util::loadVersion();
414
+        return self::$versionCache['OC_VersionString'];
415
+    }
416
+
417
+    /**
418
+     * @deprecated the value is of no use anymore
419
+     * @return string
420
+     */
421
+    public static function getEditionString() {
422
+        return '';
423
+    }
424
+
425
+    /**
426
+     * @description get the update channel of the current installed of ownCloud.
427
+     * @return string
428
+     */
429
+    public static function getChannel() {
430
+        OC_Util::loadVersion();
431
+        return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']);
432
+    }
433
+
434
+    /**
435
+     * @description get the build number of the current installed of ownCloud.
436
+     * @return string
437
+     */
438
+    public static function getBuild() {
439
+        OC_Util::loadVersion();
440
+        return self::$versionCache['OC_Build'];
441
+    }
442
+
443
+    /**
444
+     * @description load the version.php into the session as cache
445
+     */
446
+    private static function loadVersion() {
447
+        if (self::$versionCache !== null) {
448
+            return;
449
+        }
450
+
451
+        $timestamp = filemtime(OC::$SERVERROOT . '/version.php');
452
+        require OC::$SERVERROOT . '/version.php';
453
+        /** @var $timestamp int */
454
+        self::$versionCache['OC_Version_Timestamp'] = $timestamp;
455
+        /** @var $OC_Version string */
456
+        self::$versionCache['OC_Version'] = $OC_Version;
457
+        /** @var $OC_VersionString string */
458
+        self::$versionCache['OC_VersionString'] = $OC_VersionString;
459
+        /** @var $OC_Build string */
460
+        self::$versionCache['OC_Build'] = $OC_Build;
461
+
462
+        /** @var $OC_Channel string */
463
+        self::$versionCache['OC_Channel'] = $OC_Channel;
464
+    }
465
+
466
+    /**
467
+     * generates a path for JS/CSS files. If no application is provided it will create the path for core.
468
+     *
469
+     * @param string $application application to get the files from
470
+     * @param string $directory directory within this application (css, js, vendor, etc)
471
+     * @param string $file the file inside of the above folder
472
+     * @return string the path
473
+     */
474
+    private static function generatePath($application, $directory, $file) {
475
+        if (is_null($file)) {
476
+            $file = $application;
477
+            $application = "";
478
+        }
479
+        if (!empty($application)) {
480
+            return "$application/$directory/$file";
481
+        } else {
482
+            return "$directory/$file";
483
+        }
484
+    }
485
+
486
+    /**
487
+     * add a javascript file
488
+     *
489
+     * @param string $application application id
490
+     * @param string|null $file filename
491
+     * @param bool $prepend prepend the Script to the beginning of the list
492
+     * @return void
493
+     */
494
+    public static function addScript($application, $file = null, $prepend = false) {
495
+        $path = OC_Util::generatePath($application, 'js', $file);
496
+
497
+        // core js files need separate handling
498
+        if ($application !== 'core' && $file !== null) {
499
+            self::addTranslations ( $application );
500
+        }
501
+        self::addExternalResource($application, $prepend, $path, "script");
502
+    }
503
+
504
+    /**
505
+     * add a javascript file from the vendor sub folder
506
+     *
507
+     * @param string $application application id
508
+     * @param string|null $file filename
509
+     * @param bool $prepend prepend the Script to the beginning of the list
510
+     * @return void
511
+     */
512
+    public static function addVendorScript($application, $file = null, $prepend = false) {
513
+        $path = OC_Util::generatePath($application, 'vendor', $file);
514
+        self::addExternalResource($application, $prepend, $path, "script");
515
+    }
516
+
517
+    /**
518
+     * add a translation JS file
519
+     *
520
+     * @param string $application application id
521
+     * @param string $languageCode language code, defaults to the current language
522
+     * @param bool $prepend prepend the Script to the beginning of the list
523
+     */
524
+    public static function addTranslations($application, $languageCode = null, $prepend = false) {
525
+        if (is_null($languageCode)) {
526
+            $languageCode = \OC::$server->getL10NFactory()->findLanguage($application);
527
+        }
528
+        if (!empty($application)) {
529
+            $path = "$application/l10n/$languageCode";
530
+        } else {
531
+            $path = "l10n/$languageCode";
532
+        }
533
+        self::addExternalResource($application, $prepend, $path, "script");
534
+    }
535
+
536
+    /**
537
+     * add a css file
538
+     *
539
+     * @param string $application application id
540
+     * @param string|null $file filename
541
+     * @param bool $prepend prepend the Style to the beginning of the list
542
+     * @return void
543
+     */
544
+    public static function addStyle($application, $file = null, $prepend = false) {
545
+        $path = OC_Util::generatePath($application, 'css', $file);
546
+        self::addExternalResource($application, $prepend, $path, "style");
547
+    }
548
+
549
+    /**
550
+     * add a css file from the vendor sub folder
551
+     *
552
+     * @param string $application application id
553
+     * @param string|null $file filename
554
+     * @param bool $prepend prepend the Style to the beginning of the list
555
+     * @return void
556
+     */
557
+    public static function addVendorStyle($application, $file = null, $prepend = false) {
558
+        $path = OC_Util::generatePath($application, 'vendor', $file);
559
+        self::addExternalResource($application, $prepend, $path, "style");
560
+    }
561
+
562
+    /**
563
+     * add an external resource css/js file
564
+     *
565
+     * @param string $application application id
566
+     * @param bool $prepend prepend the file to the beginning of the list
567
+     * @param string $path
568
+     * @param string $type (script or style)
569
+     * @return void
570
+     */
571
+    private static function addExternalResource($application, $prepend, $path, $type = "script") {
572
+
573
+        if ($type === "style") {
574
+            if (!in_array($path, self::$styles)) {
575
+                if ($prepend === true) {
576
+                    array_unshift ( self::$styles, $path );
577
+                } else {
578
+                    self::$styles[] = $path;
579
+                }
580
+            }
581
+        } elseif ($type === "script") {
582
+            if (!in_array($path, self::$scripts)) {
583
+                if ($prepend === true) {
584
+                    array_unshift ( self::$scripts, $path );
585
+                } else {
586
+                    self::$scripts [] = $path;
587
+                }
588
+            }
589
+        }
590
+    }
591
+
592
+    /**
593
+     * Add a custom element to the header
594
+     * If $text is null then the element will be written as empty element.
595
+     * So use "" to get a closing tag.
596
+     * @param string $tag tag name of the element
597
+     * @param array $attributes array of attributes for the element
598
+     * @param string $text the text content for the element
599
+     */
600
+    public static function addHeader($tag, $attributes, $text=null) {
601
+        self::$headers[] = array(
602
+            'tag' => $tag,
603
+            'attributes' => $attributes,
604
+            'text' => $text
605
+        );
606
+    }
607
+
608
+    /**
609
+     * formats a timestamp in the "right" way
610
+     *
611
+     * @param int $timestamp
612
+     * @param bool $dateOnly option to omit time from the result
613
+     * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to
614
+     * @return string timestamp
615
+     *
616
+     * @deprecated Use \OC::$server->query('DateTimeFormatter') instead
617
+     */
618
+    public static function formatDate($timestamp, $dateOnly = false, $timeZone = null) {
619
+        if ($timeZone !== null && !$timeZone instanceof \DateTimeZone) {
620
+            $timeZone = new \DateTimeZone($timeZone);
621
+        }
622
+
623
+        /** @var \OC\DateTimeFormatter $formatter */
624
+        $formatter = \OC::$server->query('DateTimeFormatter');
625
+        if ($dateOnly) {
626
+            return $formatter->formatDate($timestamp, 'long', $timeZone);
627
+        }
628
+        return $formatter->formatDateTime($timestamp, 'long', 'long', $timeZone);
629
+    }
630
+
631
+    /**
632
+     * check if the current server configuration is suitable for ownCloud
633
+     *
634
+     * @param \OC\SystemConfig $config
635
+     * @return array arrays with error messages and hints
636
+     */
637
+    public static function checkServer(\OC\SystemConfig $config) {
638
+        $l = \OC::$server->getL10N('lib');
639
+        $errors = array();
640
+        $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data');
641
+
642
+        if (!self::needUpgrade($config) && $config->getValue('installed', false)) {
643
+            // this check needs to be done every time
644
+            $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY);
645
+        }
646
+
647
+        // Assume that if checkServer() succeeded before in this session, then all is fine.
648
+        if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) {
649
+            return $errors;
650
+        }
651
+
652
+        $webServerRestart = false;
653
+        $setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'),
654
+            \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(), \OC::$server->getSecureRandom());
655
+
656
+        $urlGenerator = \OC::$server->getURLGenerator();
657
+
658
+        $availableDatabases = $setup->getSupportedDatabases();
659
+        if (empty($availableDatabases)) {
660
+            $errors[] = array(
661
+                'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'),
662
+                'hint' => '' //TODO: sane hint
663
+            );
664
+            $webServerRestart = true;
665
+        }
666
+
667
+        // Check if config folder is writable.
668
+        if(!OC_Helper::isReadOnlyConfigEnabled()) {
669
+            if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) {
670
+                $errors[] = array(
671
+                    'error' => $l->t('Cannot write into "config" directory'),
672
+                    'hint' => $l->t('This can usually be fixed by '
673
+                        . '%sgiving the webserver write access to the config directory%s.',
674
+                        array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>'))
675
+                );
676
+            }
677
+        }
678
+
679
+        // Check if there is a writable install folder.
680
+        if ($config->getValue('appstoreenabled', true)) {
681
+            if (OC_App::getInstallPath() === null
682
+                || !is_writable(OC_App::getInstallPath())
683
+                || !is_readable(OC_App::getInstallPath())
684
+            ) {
685
+                $errors[] = array(
686
+                    'error' => $l->t('Cannot write into "apps" directory'),
687
+                    'hint' => $l->t('This can usually be fixed by '
688
+                        . '%sgiving the webserver write access to the apps directory%s'
689
+                        . ' or disabling the appstore in the config file.',
690
+                        array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>'))
691
+                );
692
+            }
693
+        }
694
+        // Create root dir.
695
+        if ($config->getValue('installed', false)) {
696
+            if (!is_dir($CONFIG_DATADIRECTORY)) {
697
+                $success = @mkdir($CONFIG_DATADIRECTORY);
698
+                if ($success) {
699
+                    $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY));
700
+                } else {
701
+                    $errors[] = [
702
+                        'error' => $l->t('Cannot create "data" directory'),
703
+                        'hint' => $l->t('This can usually be fixed by '
704
+                            . '<a href="%s" target="_blank" rel="noreferrer">giving the webserver write access to the root directory</a>.',
705
+                            [$urlGenerator->linkToDocs('admin-dir_permissions')])
706
+                    ];
707
+                }
708
+            } else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) {
709
+                //common hint for all file permissions error messages
710
+                $permissionsHint = $l->t('Permissions can usually be fixed by '
711
+                    . '%sgiving the webserver write access to the root directory%s.',
712
+                    ['<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>']);
713
+                $errors[] = [
714
+                    'error' => 'Your data directory is not writable',
715
+                    'hint' => $permissionsHint
716
+                ];
717
+            } else {
718
+                $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY));
719
+            }
720
+        }
721
+
722
+        if (!OC_Util::isSetLocaleWorking()) {
723
+            $errors[] = array(
724
+                'error' => $l->t('Setting locale to %s failed',
725
+                    array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/'
726
+                        . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')),
727
+                'hint' => $l->t('Please install one of these locales on your system and restart your webserver.')
728
+            );
729
+        }
730
+
731
+        // Contains the dependencies that should be checked against
732
+        // classes = class_exists
733
+        // functions = function_exists
734
+        // defined = defined
735
+        // ini = ini_get
736
+        // If the dependency is not found the missing module name is shown to the EndUser
737
+        // When adding new checks always verify that they pass on Travis as well
738
+        // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini
739
+        $dependencies = array(
740
+            'classes' => array(
741
+                'ZipArchive' => 'zip',
742
+                'DOMDocument' => 'dom',
743
+                'XMLWriter' => 'XMLWriter',
744
+                'XMLReader' => 'XMLReader',
745
+            ),
746
+            'functions' => [
747
+                'xml_parser_create' => 'libxml',
748
+                'mb_strcut' => 'mb multibyte',
749
+                'ctype_digit' => 'ctype',
750
+                'json_encode' => 'JSON',
751
+                'gd_info' => 'GD',
752
+                'gzencode' => 'zlib',
753
+                'iconv' => 'iconv',
754
+                'simplexml_load_string' => 'SimpleXML',
755
+                'hash' => 'HASH Message Digest Framework',
756
+                'curl_init' => 'cURL',
757
+                'openssl_verify' => 'OpenSSL',
758
+            ],
759
+            'defined' => array(
760
+                'PDO::ATTR_DRIVER_NAME' => 'PDO'
761
+            ),
762
+            'ini' => [
763
+                'default_charset' => 'UTF-8',
764
+            ],
765
+        );
766
+        $missingDependencies = array();
767
+        $invalidIniSettings = [];
768
+        $moduleHint = $l->t('Please ask your server administrator to install the module.');
769
+
770
+        /**
771
+         * FIXME: The dependency check does not work properly on HHVM on the moment
772
+         *        and prevents installation. Once HHVM is more compatible with our
773
+         *        approach to check for these values we should re-enable those
774
+         *        checks.
775
+         */
776
+        $iniWrapper = \OC::$server->getIniWrapper();
777
+        if (!self::runningOnHhvm()) {
778
+            foreach ($dependencies['classes'] as $class => $module) {
779
+                if (!class_exists($class)) {
780
+                    $missingDependencies[] = $module;
781
+                }
782
+            }
783
+            foreach ($dependencies['functions'] as $function => $module) {
784
+                if (!function_exists($function)) {
785
+                    $missingDependencies[] = $module;
786
+                }
787
+            }
788
+            foreach ($dependencies['defined'] as $defined => $module) {
789
+                if (!defined($defined)) {
790
+                    $missingDependencies[] = $module;
791
+                }
792
+            }
793
+            foreach ($dependencies['ini'] as $setting => $expected) {
794
+                if (is_bool($expected)) {
795
+                    if ($iniWrapper->getBool($setting) !== $expected) {
796
+                        $invalidIniSettings[] = [$setting, $expected];
797
+                    }
798
+                }
799
+                if (is_int($expected)) {
800
+                    if ($iniWrapper->getNumeric($setting) !== $expected) {
801
+                        $invalidIniSettings[] = [$setting, $expected];
802
+                    }
803
+                }
804
+                if (is_string($expected)) {
805
+                    if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) {
806
+                        $invalidIniSettings[] = [$setting, $expected];
807
+                    }
808
+                }
809
+            }
810
+        }
811
+
812
+        foreach($missingDependencies as $missingDependency) {
813
+            $errors[] = array(
814
+                'error' => $l->t('PHP module %s not installed.', array($missingDependency)),
815
+                'hint' => $moduleHint
816
+            );
817
+            $webServerRestart = true;
818
+        }
819
+        foreach($invalidIniSettings as $setting) {
820
+            if(is_bool($setting[1])) {
821
+                $setting[1] = ($setting[1]) ? 'on' : 'off';
822
+            }
823
+            $errors[] = [
824
+                'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]),
825
+                'hint' =>  $l->t('Adjusting this setting in php.ini will make Nextcloud run again')
826
+            ];
827
+            $webServerRestart = true;
828
+        }
829
+
830
+        /**
831
+         * The mbstring.func_overload check can only be performed if the mbstring
832
+         * module is installed as it will return null if the checking setting is
833
+         * not available and thus a check on the boolean value fails.
834
+         *
835
+         * TODO: Should probably be implemented in the above generic dependency
836
+         *       check somehow in the long-term.
837
+         */
838
+        if($iniWrapper->getBool('mbstring.func_overload') !== null &&
839
+            $iniWrapper->getBool('mbstring.func_overload') === true) {
840
+            $errors[] = array(
841
+                'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]),
842
+                'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini')
843
+            );
844
+        }
845
+
846
+        if(function_exists('xml_parser_create') &&
847
+            LIBXML_LOADED_VERSION < 20700 ) {
848
+            $version = LIBXML_LOADED_VERSION;
849
+            $major = floor($version/10000);
850
+            $version -= ($major * 10000);
851
+            $minor = floor($version/100);
852
+            $version -= ($minor * 100);
853
+            $patch = $version;
854
+            $errors[] = array(
855
+                'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]),
856
+                'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.')
857
+            );
858
+        }
859
+
860
+        if (!self::isAnnotationsWorking()) {
861
+            $errors[] = array(
862
+                'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'),
863
+                'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.')
864
+            );
865
+        }
866
+
867
+        if (!\OC::$CLI && $webServerRestart) {
868
+            $errors[] = array(
869
+                'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'),
870
+                'hint' => $l->t('Please ask your server administrator to restart the web server.')
871
+            );
872
+        }
873
+
874
+        $errors = array_merge($errors, self::checkDatabaseVersion());
875
+
876
+        // Cache the result of this function
877
+        \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0);
878
+
879
+        return $errors;
880
+    }
881
+
882
+    /**
883
+     * Check the database version
884
+     *
885
+     * @return array errors array
886
+     */
887
+    public static function checkDatabaseVersion() {
888
+        $l = \OC::$server->getL10N('lib');
889
+        $errors = array();
890
+        $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite');
891
+        if ($dbType === 'pgsql') {
892
+            // check PostgreSQL version
893
+            try {
894
+                $result = \OC_DB::executeAudited('SHOW SERVER_VERSION');
895
+                $data = $result->fetchRow();
896
+                if (isset($data['server_version'])) {
897
+                    $version = $data['server_version'];
898
+                    if (version_compare($version, '9.0.0', '<')) {
899
+                        $errors[] = array(
900
+                            'error' => $l->t('PostgreSQL >= 9 required'),
901
+                            'hint' => $l->t('Please upgrade your database version')
902
+                        );
903
+                    }
904
+                }
905
+            } catch (\Doctrine\DBAL\DBALException $e) {
906
+                $logger = \OC::$server->getLogger();
907
+                $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9');
908
+                $logger->logException($e);
909
+            }
910
+        }
911
+        return $errors;
912
+    }
913
+
914
+    /**
915
+     * Check for correct file permissions of data directory
916
+     *
917
+     * @param string $dataDirectory
918
+     * @return array arrays with error messages and hints
919
+     */
920
+    public static function checkDataDirectoryPermissions($dataDirectory) {
921
+        $l = \OC::$server->getL10N('lib');
922
+        $errors = array();
923
+        $permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory'
924
+            . ' cannot be listed by other users.');
925
+        $perms = substr(decoct(@fileperms($dataDirectory)), -3);
926
+        if (substr($perms, -1) !== '0') {
927
+            chmod($dataDirectory, 0770);
928
+            clearstatcache();
929
+            $perms = substr(decoct(@fileperms($dataDirectory)), -3);
930
+            if ($perms[2] !== '0') {
931
+                $errors[] = [
932
+                    'error' => $l->t('Your data directory is readable by other users'),
933
+                    'hint' => $permissionsModHint
934
+                ];
935
+            }
936
+        }
937
+        return $errors;
938
+    }
939
+
940
+    /**
941
+     * Check that the data directory exists and is valid by
942
+     * checking the existence of the ".ocdata" file.
943
+     *
944
+     * @param string $dataDirectory data directory path
945
+     * @return array errors found
946
+     */
947
+    public static function checkDataDirectoryValidity($dataDirectory) {
948
+        $l = \OC::$server->getL10N('lib');
949
+        $errors = [];
950
+        if ($dataDirectory[0] !== '/') {
951
+            $errors[] = [
952
+                'error' => $l->t('Your data directory must be an absolute path'),
953
+                'hint' => $l->t('Check the value of "datadirectory" in your configuration')
954
+            ];
955
+        }
956
+        if (!file_exists($dataDirectory . '/.ocdata')) {
957
+            $errors[] = [
958
+                'error' => $l->t('Your data directory  is invalid'),
959
+                'hint' => $l->t('Please check that the data directory contains a file' .
960
+                    ' ".ocdata" in its root.')
961
+            ];
962
+        }
963
+        return $errors;
964
+    }
965
+
966
+    /**
967
+     * Check if the user is logged in, redirects to home if not. With
968
+     * redirect URL parameter to the request URI.
969
+     *
970
+     * @return void
971
+     */
972
+    public static function checkLoggedIn() {
973
+        // Check if we are a user
974
+        if (!\OC::$server->getUserSession()->isLoggedIn()) {
975
+            header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute(
976
+                        'core.login.showLoginForm',
977
+                        [
978
+                            'redirect_url' => \OC::$server->getRequest()->getRequestUri(),
979
+                        ]
980
+                    )
981
+            );
982
+            exit();
983
+        }
984
+        // Redirect to 2FA challenge selection if 2FA challenge was not solved yet
985
+        if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) {
986
+            header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge'));
987
+            exit();
988
+        }
989
+    }
990
+
991
+    /**
992
+     * Check if the user is a admin, redirects to home if not
993
+     *
994
+     * @return void
995
+     */
996
+    public static function checkAdminUser() {
997
+        OC_Util::checkLoggedIn();
998
+        if (!OC_User::isAdminUser(OC_User::getUser())) {
999
+            header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php'));
1000
+            exit();
1001
+        }
1002
+    }
1003
+
1004
+    /**
1005
+     * Check if the user is a subadmin, redirects to home if not
1006
+     *
1007
+     * @return null|boolean $groups where the current user is subadmin
1008
+     */
1009
+    public static function checkSubAdminUser() {
1010
+        OC_Util::checkLoggedIn();
1011
+        $userObject = \OC::$server->getUserSession()->getUser();
1012
+        $isSubAdmin = false;
1013
+        if($userObject !== null) {
1014
+            $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
1015
+        }
1016
+
1017
+        if (!$isSubAdmin) {
1018
+            header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php'));
1019
+            exit();
1020
+        }
1021
+        return true;
1022
+    }
1023
+
1024
+    /**
1025
+     * Returns the URL of the default page
1026
+     * based on the system configuration and
1027
+     * the apps visible for the current user
1028
+     *
1029
+     * @return string URL
1030
+     */
1031
+    public static function getDefaultPageUrl() {
1032
+        $urlGenerator = \OC::$server->getURLGenerator();
1033
+        // Deny the redirect if the URL contains a @
1034
+        // This prevents unvalidated redirects like ?redirect_url=:[email protected]
1035
+        if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) {
1036
+            $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url']));
1037
+        } else {
1038
+            $defaultPage = \OC::$server->getAppConfig()->getValue('core', 'defaultpage');
1039
+            if ($defaultPage) {
1040
+                $location = $urlGenerator->getAbsoluteURL($defaultPage);
1041
+            } else {
1042
+                $appId = 'files';
1043
+                $defaultApps = explode(',', \OCP\Config::getSystemValue('defaultapp', 'files'));
1044
+                // find the first app that is enabled for the current user
1045
+                foreach ($defaultApps as $defaultApp) {
1046
+                    $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp));
1047
+                    if (static::getAppManager()->isEnabledForUser($defaultApp)) {
1048
+                        $appId = $defaultApp;
1049
+                        break;
1050
+                    }
1051
+                }
1052
+
1053
+                if(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') {
1054
+                    $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/');
1055
+                } else {
1056
+                    $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/');
1057
+                }
1058
+            }
1059
+        }
1060
+        return $location;
1061
+    }
1062
+
1063
+    /**
1064
+     * Redirect to the user default page
1065
+     *
1066
+     * @return void
1067
+     */
1068
+    public static function redirectToDefaultPage() {
1069
+        $location = self::getDefaultPageUrl();
1070
+        header('Location: ' . $location);
1071
+        exit();
1072
+    }
1073
+
1074
+    /**
1075
+     * get an id unique for this instance
1076
+     *
1077
+     * @return string
1078
+     */
1079
+    public static function getInstanceId() {
1080
+        $id = \OC::$server->getSystemConfig()->getValue('instanceid', null);
1081
+        if (is_null($id)) {
1082
+            // We need to guarantee at least one letter in instanceid so it can be used as the session_name
1083
+            $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
1084
+            \OC::$server->getSystemConfig()->setValue('instanceid', $id);
1085
+        }
1086
+        return $id;
1087
+    }
1088
+
1089
+    /**
1090
+     * Public function to sanitize HTML
1091
+     *
1092
+     * This function is used to sanitize HTML and should be applied on any
1093
+     * string or array of strings before displaying it on a web page.
1094
+     *
1095
+     * @param string|array $value
1096
+     * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
1097
+     */
1098
+    public static function sanitizeHTML($value) {
1099
+        if (is_array($value)) {
1100
+            $value = array_map(function($value) {
1101
+                return self::sanitizeHTML($value);
1102
+            }, $value);
1103
+        } else {
1104
+            // Specify encoding for PHP<5.4
1105
+            $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
1106
+        }
1107
+        return $value;
1108
+    }
1109
+
1110
+    /**
1111
+     * Public function to encode url parameters
1112
+     *
1113
+     * This function is used to encode path to file before output.
1114
+     * Encoding is done according to RFC 3986 with one exception:
1115
+     * Character '/' is preserved as is.
1116
+     *
1117
+     * @param string $component part of URI to encode
1118
+     * @return string
1119
+     */
1120
+    public static function encodePath($component) {
1121
+        $encoded = rawurlencode($component);
1122
+        $encoded = str_replace('%2F', '/', $encoded);
1123
+        return $encoded;
1124
+    }
1125
+
1126
+
1127
+    public function createHtaccessTestFile(\OCP\IConfig $config) {
1128
+        // php dev server does not support htaccess
1129
+        if (php_sapi_name() === 'cli-server') {
1130
+            return false;
1131
+        }
1132
+
1133
+        // testdata
1134
+        $fileName = '/htaccesstest.txt';
1135
+        $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.';
1136
+
1137
+        // creating a test file
1138
+        $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName;
1139
+
1140
+        if (file_exists($testFile)) {// already running this test, possible recursive call
1141
+            return false;
1142
+        }
1143
+
1144
+        $fp = @fopen($testFile, 'w');
1145
+        if (!$fp) {
1146
+            throw new OC\HintException('Can\'t create test file to check for working .htaccess file.',
1147
+                'Make sure it is possible for the webserver to write to ' . $testFile);
1148
+        }
1149
+        fwrite($fp, $testContent);
1150
+        fclose($fp);
1151
+
1152
+        return $testContent;
1153
+    }
1154
+
1155
+    /**
1156
+     * Check if the .htaccess file is working
1157
+     * @param \OCP\IConfig $config
1158
+     * @return bool
1159
+     * @throws Exception
1160
+     * @throws \OC\HintException If the test file can't get written.
1161
+     */
1162
+    public function isHtaccessWorking(\OCP\IConfig $config) {
1163
+
1164
+        if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) {
1165
+            return true;
1166
+        }
1167
+
1168
+        $testContent = $this->createHtaccessTestFile($config);
1169
+        if ($testContent === false) {
1170
+            return false;
1171
+        }
1172
+
1173
+        $fileName = '/htaccesstest.txt';
1174
+        $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName;
1175
+
1176
+        // accessing the file via http
1177
+        $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName);
1178
+        try {
1179
+            $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody();
1180
+        } catch (\Exception $e) {
1181
+            $content = false;
1182
+        }
1183
+
1184
+        // cleanup
1185
+        @unlink($testFile);
1186
+
1187
+        /*
1188 1188
 		 * If the content is not equal to test content our .htaccess
1189 1189
 		 * is working as required
1190 1190
 		 */
1191
-		return $content !== $testContent;
1192
-	}
1193
-
1194
-	/**
1195
-	 * Check if the setlocal call does not work. This can happen if the right
1196
-	 * local packages are not available on the server.
1197
-	 *
1198
-	 * @return bool
1199
-	 */
1200
-	public static function isSetLocaleWorking() {
1201
-		\Patchwork\Utf8\Bootup::initLocale();
1202
-		if ('' === basename('§')) {
1203
-			return false;
1204
-		}
1205
-		return true;
1206
-	}
1207
-
1208
-	/**
1209
-	 * Check if it's possible to get the inline annotations
1210
-	 *
1211
-	 * @return bool
1212
-	 */
1213
-	public static function isAnnotationsWorking() {
1214
-		$reflection = new \ReflectionMethod(__METHOD__);
1215
-		$docs = $reflection->getDocComment();
1216
-
1217
-		return (is_string($docs) && strlen($docs) > 50);
1218
-	}
1219
-
1220
-	/**
1221
-	 * Check if the PHP module fileinfo is loaded.
1222
-	 *
1223
-	 * @return bool
1224
-	 */
1225
-	public static function fileInfoLoaded() {
1226
-		return function_exists('finfo_open');
1227
-	}
1228
-
1229
-	/**
1230
-	 * clear all levels of output buffering
1231
-	 *
1232
-	 * @return void
1233
-	 */
1234
-	public static function obEnd() {
1235
-		while (ob_get_level()) {
1236
-			ob_end_clean();
1237
-		}
1238
-	}
1239
-
1240
-	/**
1241
-	 * Checks whether the server is running on Mac OS X
1242
-	 *
1243
-	 * @return bool true if running on Mac OS X, false otherwise
1244
-	 */
1245
-	public static function runningOnMac() {
1246
-		return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN');
1247
-	}
1248
-
1249
-	/**
1250
-	 * Checks whether server is running on HHVM
1251
-	 *
1252
-	 * @return bool True if running on HHVM, false otherwise
1253
-	 */
1254
-	public static function runningOnHhvm() {
1255
-		return defined('HHVM_VERSION');
1256
-	}
1257
-
1258
-	/**
1259
-	 * Handles the case that there may not be a theme, then check if a "default"
1260
-	 * theme exists and take that one
1261
-	 *
1262
-	 * @return string the theme
1263
-	 */
1264
-	public static function getTheme() {
1265
-		$theme = \OC::$server->getSystemConfig()->getValue("theme", '');
1266
-
1267
-		if ($theme === '') {
1268
-			if (is_dir(OC::$SERVERROOT . '/themes/default')) {
1269
-				$theme = 'default';
1270
-			}
1271
-		}
1272
-
1273
-		return $theme;
1274
-	}
1275
-
1276
-	/**
1277
-	 * Clear a single file from the opcode cache
1278
-	 * This is useful for writing to the config file
1279
-	 * in case the opcode cache does not re-validate files
1280
-	 * Returns true if successful, false if unsuccessful:
1281
-	 * caller should fall back on clearing the entire cache
1282
-	 * with clearOpcodeCache() if unsuccessful
1283
-	 *
1284
-	 * @param string $path the path of the file to clear from the cache
1285
-	 * @return bool true if underlying function returns true, otherwise false
1286
-	 */
1287
-	public static function deleteFromOpcodeCache($path) {
1288
-		$ret = false;
1289
-		if ($path) {
1290
-			// APC >= 3.1.1
1291
-			if (function_exists('apc_delete_file')) {
1292
-				$ret = @apc_delete_file($path);
1293
-			}
1294
-			// Zend OpCache >= 7.0.0, PHP >= 5.5.0
1295
-			if (function_exists('opcache_invalidate')) {
1296
-				$ret = opcache_invalidate($path);
1297
-			}
1298
-		}
1299
-		return $ret;
1300
-	}
1301
-
1302
-	/**
1303
-	 * Clear the opcode cache if one exists
1304
-	 * This is necessary for writing to the config file
1305
-	 * in case the opcode cache does not re-validate files
1306
-	 *
1307
-	 * @return void
1308
-	 */
1309
-	public static function clearOpcodeCache() {
1310
-		// APC
1311
-		if (function_exists('apc_clear_cache')) {
1312
-			apc_clear_cache();
1313
-		}
1314
-		// Zend Opcache
1315
-		if (function_exists('accelerator_reset')) {
1316
-			accelerator_reset();
1317
-		}
1318
-		// XCache
1319
-		if (function_exists('xcache_clear_cache')) {
1320
-			if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) {
1321
-				\OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', \OCP\Util::WARN);
1322
-			} else {
1323
-				@xcache_clear_cache(XC_TYPE_PHP, 0);
1324
-			}
1325
-		}
1326
-		// Opcache (PHP >= 5.5)
1327
-		if (function_exists('opcache_reset')) {
1328
-			opcache_reset();
1329
-		}
1330
-	}
1331
-
1332
-	/**
1333
-	 * Normalize a unicode string
1334
-	 *
1335
-	 * @param string $value a not normalized string
1336
-	 * @return bool|string
1337
-	 */
1338
-	public static function normalizeUnicode($value) {
1339
-		if(Normalizer::isNormalized($value)) {
1340
-			return $value;
1341
-		}
1342
-
1343
-		$normalizedValue = Normalizer::normalize($value);
1344
-		if ($normalizedValue === null || $normalizedValue === false) {
1345
-			\OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']);
1346
-			return $value;
1347
-		}
1348
-
1349
-		return $normalizedValue;
1350
-	}
1351
-
1352
-	/**
1353
-	 * @param boolean|string $file
1354
-	 * @return string
1355
-	 */
1356
-	public static function basename($file) {
1357
-		$file = rtrim($file, '/');
1358
-		$t = explode('/', $file);
1359
-		return array_pop($t);
1360
-	}
1361
-
1362
-	/**
1363
-	 * A human readable string is generated based on version and build number
1364
-	 *
1365
-	 * @return string
1366
-	 */
1367
-	public static function getHumanVersion() {
1368
-		$version = OC_Util::getVersionString();
1369
-		$build = OC_Util::getBuild();
1370
-		if (!empty($build) and OC_Util::getChannel() === 'daily') {
1371
-			$version .= ' Build:' . $build;
1372
-		}
1373
-		return $version;
1374
-	}
1375
-
1376
-	/**
1377
-	 * Returns whether the given file name is valid
1378
-	 *
1379
-	 * @param string $file file name to check
1380
-	 * @return bool true if the file name is valid, false otherwise
1381
-	 * @deprecated use \OC\Files\View::verifyPath()
1382
-	 */
1383
-	public static function isValidFileName($file) {
1384
-		$trimmed = trim($file);
1385
-		if ($trimmed === '') {
1386
-			return false;
1387
-		}
1388
-		if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) {
1389
-			return false;
1390
-		}
1391
-		foreach (str_split($trimmed) as $char) {
1392
-			if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) {
1393
-				return false;
1394
-			}
1395
-		}
1396
-		return true;
1397
-	}
1398
-
1399
-	/**
1400
-	 * Check whether the instance needs to perform an upgrade,
1401
-	 * either when the core version is higher or any app requires
1402
-	 * an upgrade.
1403
-	 *
1404
-	 * @param \OC\SystemConfig $config
1405
-	 * @return bool whether the core or any app needs an upgrade
1406
-	 * @throws \OC\HintException When the upgrade from the given version is not allowed
1407
-	 */
1408
-	public static function needUpgrade(\OC\SystemConfig $config) {
1409
-		if ($config->getValue('installed', false)) {
1410
-			$installedVersion = $config->getValue('version', '0.0.0');
1411
-			$currentVersion = implode('.', \OCP\Util::getVersion());
1412
-			$versionDiff = version_compare($currentVersion, $installedVersion);
1413
-			if ($versionDiff > 0) {
1414
-				return true;
1415
-			} else if ($config->getValue('debug', false) && $versionDiff < 0) {
1416
-				// downgrade with debug
1417
-				$installedMajor = explode('.', $installedVersion);
1418
-				$installedMajor = $installedMajor[0] . '.' . $installedMajor[1];
1419
-				$currentMajor = explode('.', $currentVersion);
1420
-				$currentMajor = $currentMajor[0] . '.' . $currentMajor[1];
1421
-				if ($installedMajor === $currentMajor) {
1422
-					// Same major, allow downgrade for developers
1423
-					return true;
1424
-				} else {
1425
-					// downgrade attempt, throw exception
1426
-					throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')');
1427
-				}
1428
-			} else if ($versionDiff < 0) {
1429
-				// downgrade attempt, throw exception
1430
-				throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')');
1431
-			}
1432
-
1433
-			// also check for upgrades for apps (independently from the user)
1434
-			$apps = \OC_App::getEnabledApps(false, true);
1435
-			$shouldUpgrade = false;
1436
-			foreach ($apps as $app) {
1437
-				if (\OC_App::shouldUpgrade($app)) {
1438
-					$shouldUpgrade = true;
1439
-					break;
1440
-				}
1441
-			}
1442
-			return $shouldUpgrade;
1443
-		} else {
1444
-			return false;
1445
-		}
1446
-	}
1191
+        return $content !== $testContent;
1192
+    }
1193
+
1194
+    /**
1195
+     * Check if the setlocal call does not work. This can happen if the right
1196
+     * local packages are not available on the server.
1197
+     *
1198
+     * @return bool
1199
+     */
1200
+    public static function isSetLocaleWorking() {
1201
+        \Patchwork\Utf8\Bootup::initLocale();
1202
+        if ('' === basename('§')) {
1203
+            return false;
1204
+        }
1205
+        return true;
1206
+    }
1207
+
1208
+    /**
1209
+     * Check if it's possible to get the inline annotations
1210
+     *
1211
+     * @return bool
1212
+     */
1213
+    public static function isAnnotationsWorking() {
1214
+        $reflection = new \ReflectionMethod(__METHOD__);
1215
+        $docs = $reflection->getDocComment();
1216
+
1217
+        return (is_string($docs) && strlen($docs) > 50);
1218
+    }
1219
+
1220
+    /**
1221
+     * Check if the PHP module fileinfo is loaded.
1222
+     *
1223
+     * @return bool
1224
+     */
1225
+    public static function fileInfoLoaded() {
1226
+        return function_exists('finfo_open');
1227
+    }
1228
+
1229
+    /**
1230
+     * clear all levels of output buffering
1231
+     *
1232
+     * @return void
1233
+     */
1234
+    public static function obEnd() {
1235
+        while (ob_get_level()) {
1236
+            ob_end_clean();
1237
+        }
1238
+    }
1239
+
1240
+    /**
1241
+     * Checks whether the server is running on Mac OS X
1242
+     *
1243
+     * @return bool true if running on Mac OS X, false otherwise
1244
+     */
1245
+    public static function runningOnMac() {
1246
+        return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN');
1247
+    }
1248
+
1249
+    /**
1250
+     * Checks whether server is running on HHVM
1251
+     *
1252
+     * @return bool True if running on HHVM, false otherwise
1253
+     */
1254
+    public static function runningOnHhvm() {
1255
+        return defined('HHVM_VERSION');
1256
+    }
1257
+
1258
+    /**
1259
+     * Handles the case that there may not be a theme, then check if a "default"
1260
+     * theme exists and take that one
1261
+     *
1262
+     * @return string the theme
1263
+     */
1264
+    public static function getTheme() {
1265
+        $theme = \OC::$server->getSystemConfig()->getValue("theme", '');
1266
+
1267
+        if ($theme === '') {
1268
+            if (is_dir(OC::$SERVERROOT . '/themes/default')) {
1269
+                $theme = 'default';
1270
+            }
1271
+        }
1272
+
1273
+        return $theme;
1274
+    }
1275
+
1276
+    /**
1277
+     * Clear a single file from the opcode cache
1278
+     * This is useful for writing to the config file
1279
+     * in case the opcode cache does not re-validate files
1280
+     * Returns true if successful, false if unsuccessful:
1281
+     * caller should fall back on clearing the entire cache
1282
+     * with clearOpcodeCache() if unsuccessful
1283
+     *
1284
+     * @param string $path the path of the file to clear from the cache
1285
+     * @return bool true if underlying function returns true, otherwise false
1286
+     */
1287
+    public static function deleteFromOpcodeCache($path) {
1288
+        $ret = false;
1289
+        if ($path) {
1290
+            // APC >= 3.1.1
1291
+            if (function_exists('apc_delete_file')) {
1292
+                $ret = @apc_delete_file($path);
1293
+            }
1294
+            // Zend OpCache >= 7.0.0, PHP >= 5.5.0
1295
+            if (function_exists('opcache_invalidate')) {
1296
+                $ret = opcache_invalidate($path);
1297
+            }
1298
+        }
1299
+        return $ret;
1300
+    }
1301
+
1302
+    /**
1303
+     * Clear the opcode cache if one exists
1304
+     * This is necessary for writing to the config file
1305
+     * in case the opcode cache does not re-validate files
1306
+     *
1307
+     * @return void
1308
+     */
1309
+    public static function clearOpcodeCache() {
1310
+        // APC
1311
+        if (function_exists('apc_clear_cache')) {
1312
+            apc_clear_cache();
1313
+        }
1314
+        // Zend Opcache
1315
+        if (function_exists('accelerator_reset')) {
1316
+            accelerator_reset();
1317
+        }
1318
+        // XCache
1319
+        if (function_exists('xcache_clear_cache')) {
1320
+            if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) {
1321
+                \OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', \OCP\Util::WARN);
1322
+            } else {
1323
+                @xcache_clear_cache(XC_TYPE_PHP, 0);
1324
+            }
1325
+        }
1326
+        // Opcache (PHP >= 5.5)
1327
+        if (function_exists('opcache_reset')) {
1328
+            opcache_reset();
1329
+        }
1330
+    }
1331
+
1332
+    /**
1333
+     * Normalize a unicode string
1334
+     *
1335
+     * @param string $value a not normalized string
1336
+     * @return bool|string
1337
+     */
1338
+    public static function normalizeUnicode($value) {
1339
+        if(Normalizer::isNormalized($value)) {
1340
+            return $value;
1341
+        }
1342
+
1343
+        $normalizedValue = Normalizer::normalize($value);
1344
+        if ($normalizedValue === null || $normalizedValue === false) {
1345
+            \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']);
1346
+            return $value;
1347
+        }
1348
+
1349
+        return $normalizedValue;
1350
+    }
1351
+
1352
+    /**
1353
+     * @param boolean|string $file
1354
+     * @return string
1355
+     */
1356
+    public static function basename($file) {
1357
+        $file = rtrim($file, '/');
1358
+        $t = explode('/', $file);
1359
+        return array_pop($t);
1360
+    }
1361
+
1362
+    /**
1363
+     * A human readable string is generated based on version and build number
1364
+     *
1365
+     * @return string
1366
+     */
1367
+    public static function getHumanVersion() {
1368
+        $version = OC_Util::getVersionString();
1369
+        $build = OC_Util::getBuild();
1370
+        if (!empty($build) and OC_Util::getChannel() === 'daily') {
1371
+            $version .= ' Build:' . $build;
1372
+        }
1373
+        return $version;
1374
+    }
1375
+
1376
+    /**
1377
+     * Returns whether the given file name is valid
1378
+     *
1379
+     * @param string $file file name to check
1380
+     * @return bool true if the file name is valid, false otherwise
1381
+     * @deprecated use \OC\Files\View::verifyPath()
1382
+     */
1383
+    public static function isValidFileName($file) {
1384
+        $trimmed = trim($file);
1385
+        if ($trimmed === '') {
1386
+            return false;
1387
+        }
1388
+        if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) {
1389
+            return false;
1390
+        }
1391
+        foreach (str_split($trimmed) as $char) {
1392
+            if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) {
1393
+                return false;
1394
+            }
1395
+        }
1396
+        return true;
1397
+    }
1398
+
1399
+    /**
1400
+     * Check whether the instance needs to perform an upgrade,
1401
+     * either when the core version is higher or any app requires
1402
+     * an upgrade.
1403
+     *
1404
+     * @param \OC\SystemConfig $config
1405
+     * @return bool whether the core or any app needs an upgrade
1406
+     * @throws \OC\HintException When the upgrade from the given version is not allowed
1407
+     */
1408
+    public static function needUpgrade(\OC\SystemConfig $config) {
1409
+        if ($config->getValue('installed', false)) {
1410
+            $installedVersion = $config->getValue('version', '0.0.0');
1411
+            $currentVersion = implode('.', \OCP\Util::getVersion());
1412
+            $versionDiff = version_compare($currentVersion, $installedVersion);
1413
+            if ($versionDiff > 0) {
1414
+                return true;
1415
+            } else if ($config->getValue('debug', false) && $versionDiff < 0) {
1416
+                // downgrade with debug
1417
+                $installedMajor = explode('.', $installedVersion);
1418
+                $installedMajor = $installedMajor[0] . '.' . $installedMajor[1];
1419
+                $currentMajor = explode('.', $currentVersion);
1420
+                $currentMajor = $currentMajor[0] . '.' . $currentMajor[1];
1421
+                if ($installedMajor === $currentMajor) {
1422
+                    // Same major, allow downgrade for developers
1423
+                    return true;
1424
+                } else {
1425
+                    // downgrade attempt, throw exception
1426
+                    throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')');
1427
+                }
1428
+            } else if ($versionDiff < 0) {
1429
+                // downgrade attempt, throw exception
1430
+                throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')');
1431
+            }
1432
+
1433
+            // also check for upgrades for apps (independently from the user)
1434
+            $apps = \OC_App::getEnabledApps(false, true);
1435
+            $shouldUpgrade = false;
1436
+            foreach ($apps as $app) {
1437
+                if (\OC_App::shouldUpgrade($app)) {
1438
+                    $shouldUpgrade = true;
1439
+                    break;
1440
+                }
1441
+            }
1442
+            return $shouldUpgrade;
1443
+        } else {
1444
+            return false;
1445
+        }
1446
+    }
1447 1447
 
1448 1448
 }
Please login to merge, or discard this patch.