Completed
Push — master ( 186019...3eaf23 )
by Morris
14:23
created
lib/private/legacy/json.php 2 patches
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -35,163 +35,163 @@
 block discarded – undo
35 35
  * @deprecated Use a AppFramework JSONResponse instead
36 36
  */
37 37
 class OC_JSON{
38
-	static protected $send_content_type_header = false;
39
-	/**
40
-	 * set Content-Type header to jsonrequest
41
-	 * @deprecated Use a AppFramework JSONResponse instead
42
-	 */
43
-	public static function setContentTypeHeader($type='application/json') {
44
-		if (!self::$send_content_type_header) {
45
-			// We send json data
46
-			header( 'Content-Type: '.$type . '; charset=utf-8');
47
-			self::$send_content_type_header = true;
48
-		}
49
-	}
38
+    static protected $send_content_type_header = false;
39
+    /**
40
+     * set Content-Type header to jsonrequest
41
+     * @deprecated Use a AppFramework JSONResponse instead
42
+     */
43
+    public static function setContentTypeHeader($type='application/json') {
44
+        if (!self::$send_content_type_header) {
45
+            // We send json data
46
+            header( 'Content-Type: '.$type . '; charset=utf-8');
47
+            self::$send_content_type_header = true;
48
+        }
49
+    }
50 50
 
51
-	/**
52
-	 * Check if the app is enabled, send json error msg if not
53
-	 * @param string $app
54
-	 * @deprecated Use the AppFramework instead. It will automatically check if the app is enabled.
55
-	 * @suppress PhanDeprecatedFunction
56
-	 */
57
-	public static function checkAppEnabled($app) {
58
-		if( !\OC::$server->getAppManager()->isEnabledForUser($app)) {
59
-			$l = \OC::$server->getL10N('lib');
60
-			self::error(array( 'data' => array( 'message' => $l->t('Application is not enabled'), 'error' => 'application_not_enabled' )));
61
-			exit();
62
-		}
63
-	}
51
+    /**
52
+     * Check if the app is enabled, send json error msg if not
53
+     * @param string $app
54
+     * @deprecated Use the AppFramework instead. It will automatically check if the app is enabled.
55
+     * @suppress PhanDeprecatedFunction
56
+     */
57
+    public static function checkAppEnabled($app) {
58
+        if( !\OC::$server->getAppManager()->isEnabledForUser($app)) {
59
+            $l = \OC::$server->getL10N('lib');
60
+            self::error(array( 'data' => array( 'message' => $l->t('Application is not enabled'), 'error' => 'application_not_enabled' )));
61
+            exit();
62
+        }
63
+    }
64 64
 
65
-	/**
66
-	 * Check if the user is logged in, send json error msg if not
67
-	 * @deprecated Use annotation based ACLs from the AppFramework instead
68
-	 * @suppress PhanDeprecatedFunction
69
-	 */
70
-	public static function checkLoggedIn() {
71
-		$twoFactorAuthManger = \OC::$server->getTwoFactorAuthManager();
72
-		if( !\OC::$server->getUserSession()->isLoggedIn()
73
-			|| $twoFactorAuthManger->needsSecondFactor(\OC::$server->getUserSession()->getUser())) {
74
-			$l = \OC::$server->getL10N('lib');
75
-			http_response_code(\OCP\AppFramework\Http::STATUS_UNAUTHORIZED);
76
-			self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
77
-			exit();
78
-		}
79
-	}
65
+    /**
66
+     * Check if the user is logged in, send json error msg if not
67
+     * @deprecated Use annotation based ACLs from the AppFramework instead
68
+     * @suppress PhanDeprecatedFunction
69
+     */
70
+    public static function checkLoggedIn() {
71
+        $twoFactorAuthManger = \OC::$server->getTwoFactorAuthManager();
72
+        if( !\OC::$server->getUserSession()->isLoggedIn()
73
+            || $twoFactorAuthManger->needsSecondFactor(\OC::$server->getUserSession()->getUser())) {
74
+            $l = \OC::$server->getL10N('lib');
75
+            http_response_code(\OCP\AppFramework\Http::STATUS_UNAUTHORIZED);
76
+            self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
77
+            exit();
78
+        }
79
+    }
80 80
 
81
-	/**
82
-	 * Check an ajax get/post call if the request token is valid, send json error msg if not.
83
-	 * @deprecated Use annotation based CSRF checks from the AppFramework instead
84
-	 * @suppress PhanDeprecatedFunction
85
-	 */
86
-	public static function callCheck() {
87
-		if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
88
-			header('Location: '.\OC::$WEBROOT);
89
-			exit();
90
-		}
81
+    /**
82
+     * Check an ajax get/post call if the request token is valid, send json error msg if not.
83
+     * @deprecated Use annotation based CSRF checks from the AppFramework instead
84
+     * @suppress PhanDeprecatedFunction
85
+     */
86
+    public static function callCheck() {
87
+        if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
88
+            header('Location: '.\OC::$WEBROOT);
89
+            exit();
90
+        }
91 91
 
92
-		if( !(\OC::$server->getRequest()->passesCSRFCheck())) {
93
-			$l = \OC::$server->getL10N('lib');
94
-			self::error(array( 'data' => array( 'message' => $l->t('Token expired. Please reload page.'), 'error' => 'token_expired' )));
95
-			exit();
96
-		}
97
-	}
92
+        if( !(\OC::$server->getRequest()->passesCSRFCheck())) {
93
+            $l = \OC::$server->getL10N('lib');
94
+            self::error(array( 'data' => array( 'message' => $l->t('Token expired. Please reload page.'), 'error' => 'token_expired' )));
95
+            exit();
96
+        }
97
+    }
98 98
 
99
-	/**
100
-	 * Check if the user is a admin, send json error msg if not.
101
-	 * @deprecated Use annotation based ACLs from the AppFramework instead
102
-	 * @suppress PhanDeprecatedFunction
103
-	 */
104
-	public static function checkAdminUser() {
105
-		if( !OC_User::isAdminUser(OC_User::getUser())) {
106
-			$l = \OC::$server->getL10N('lib');
107
-			self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
108
-			exit();
109
-		}
110
-	}
99
+    /**
100
+     * Check if the user is a admin, send json error msg if not.
101
+     * @deprecated Use annotation based ACLs from the AppFramework instead
102
+     * @suppress PhanDeprecatedFunction
103
+     */
104
+    public static function checkAdminUser() {
105
+        if( !OC_User::isAdminUser(OC_User::getUser())) {
106
+            $l = \OC::$server->getL10N('lib');
107
+            self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
108
+            exit();
109
+        }
110
+    }
111 111
 
112
-	/**
113
-	 * Check is a given user exists - send json error msg if not
114
-	 * @param string $user
115
-	 * @deprecated Use a AppFramework JSONResponse instead
116
-	 * @suppress PhanDeprecatedFunction
117
-	 */
118
-	public static function checkUserExists($user) {
119
-		if (!OCP\User::userExists($user)) {
120
-			$l = \OC::$server->getL10N('lib');
121
-			OCP\JSON::error(array('data' => array('message' => $l->t('Unknown user'), 'error' => 'unknown_user' )));
122
-			exit;
123
-		}
124
-	}
112
+    /**
113
+     * Check is a given user exists - send json error msg if not
114
+     * @param string $user
115
+     * @deprecated Use a AppFramework JSONResponse instead
116
+     * @suppress PhanDeprecatedFunction
117
+     */
118
+    public static function checkUserExists($user) {
119
+        if (!OCP\User::userExists($user)) {
120
+            $l = \OC::$server->getL10N('lib');
121
+            OCP\JSON::error(array('data' => array('message' => $l->t('Unknown user'), 'error' => 'unknown_user' )));
122
+            exit;
123
+        }
124
+    }
125 125
 
126 126
 
127
-	/**
128
-	 * Check if the user is a subadmin, send json error msg if not
129
-	 * @deprecated Use annotation based ACLs from the AppFramework instead
130
-	 * @suppress PhanDeprecatedFunction
131
-	 */
132
-	public static function checkSubAdminUser() {
133
-		$userObject = \OC::$server->getUserSession()->getUser();
134
-		$isSubAdmin = false;
135
-		if($userObject !== null) {
136
-			$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
137
-		}
127
+    /**
128
+     * Check if the user is a subadmin, send json error msg if not
129
+     * @deprecated Use annotation based ACLs from the AppFramework instead
130
+     * @suppress PhanDeprecatedFunction
131
+     */
132
+    public static function checkSubAdminUser() {
133
+        $userObject = \OC::$server->getUserSession()->getUser();
134
+        $isSubAdmin = false;
135
+        if($userObject !== null) {
136
+            $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
137
+        }
138 138
 
139
-		if(!$isSubAdmin) {
140
-			$l = \OC::$server->getL10N('lib');
141
-			self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
142
-			exit();
143
-		}
144
-	}
139
+        if(!$isSubAdmin) {
140
+            $l = \OC::$server->getL10N('lib');
141
+            self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
142
+            exit();
143
+        }
144
+    }
145 145
 
146
-	/**
147
-	 * Send json error msg
148
-	 * @deprecated Use a AppFramework JSONResponse instead
149
-	 * @suppress PhanDeprecatedFunction
150
-	 */
151
-	public static function error($data = array()) {
152
-		$data['status'] = 'error';
153
-		self::encodedPrint($data);
154
-	}
146
+    /**
147
+     * Send json error msg
148
+     * @deprecated Use a AppFramework JSONResponse instead
149
+     * @suppress PhanDeprecatedFunction
150
+     */
151
+    public static function error($data = array()) {
152
+        $data['status'] = 'error';
153
+        self::encodedPrint($data);
154
+    }
155 155
 
156
-	/**
157
-	 * Send json success msg
158
-	 * @deprecated Use a AppFramework JSONResponse instead
159
-	 * @suppress PhanDeprecatedFunction
160
-	 */
161
-	public static function success($data = array()) {
162
-		$data['status'] = 'success';
163
-		self::encodedPrint($data);
164
-	}
156
+    /**
157
+     * Send json success msg
158
+     * @deprecated Use a AppFramework JSONResponse instead
159
+     * @suppress PhanDeprecatedFunction
160
+     */
161
+    public static function success($data = array()) {
162
+        $data['status'] = 'success';
163
+        self::encodedPrint($data);
164
+    }
165 165
 
166
-	/**
167
-	 * Convert OC_L10N_String to string, for use in json encodings
168
-	 */
169
-	protected static function to_string(&$value) {
170
-		if ($value instanceof \OC\L10N\L10NString) {
171
-			$value = (string)$value;
172
-		}
173
-	}
166
+    /**
167
+     * Convert OC_L10N_String to string, for use in json encodings
168
+     */
169
+    protected static function to_string(&$value) {
170
+        if ($value instanceof \OC\L10N\L10NString) {
171
+            $value = (string)$value;
172
+        }
173
+    }
174 174
 
175
-	/**
176
-	 * Encode and print $data in json format
177
-	 * @deprecated Use a AppFramework JSONResponse instead
178
-	 * @suppress PhanDeprecatedFunction
179
-	 */
180
-	public static function encodedPrint($data, $setContentType=true) {
181
-		if($setContentType) {
182
-			self::setContentTypeHeader();
183
-		}
184
-		echo self::encode($data);
185
-	}
175
+    /**
176
+     * Encode and print $data in json format
177
+     * @deprecated Use a AppFramework JSONResponse instead
178
+     * @suppress PhanDeprecatedFunction
179
+     */
180
+    public static function encodedPrint($data, $setContentType=true) {
181
+        if($setContentType) {
182
+            self::setContentTypeHeader();
183
+        }
184
+        echo self::encode($data);
185
+    }
186 186
 
187
-	/**
188
-	 * Encode JSON
189
-	 * @deprecated Use a AppFramework JSONResponse instead
190
-	 */
191
-	public static function encode($data) {
192
-		if (is_array($data)) {
193
-			array_walk_recursive($data, array('OC_JSON', 'to_string'));
194
-		}
195
-		return json_encode($data, JSON_HEX_TAG);
196
-	}
187
+    /**
188
+     * Encode JSON
189
+     * @deprecated Use a AppFramework JSONResponse instead
190
+     */
191
+    public static function encode($data) {
192
+        if (is_array($data)) {
193
+            array_walk_recursive($data, array('OC_JSON', 'to_string'));
194
+        }
195
+        return json_encode($data, JSON_HEX_TAG);
196
+    }
197 197
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -34,16 +34,16 @@  discard block
 block discarded – undo
34 34
  * Class OC_JSON
35 35
  * @deprecated Use a AppFramework JSONResponse instead
36 36
  */
37
-class OC_JSON{
37
+class OC_JSON {
38 38
 	static protected $send_content_type_header = false;
39 39
 	/**
40 40
 	 * set Content-Type header to jsonrequest
41 41
 	 * @deprecated Use a AppFramework JSONResponse instead
42 42
 	 */
43
-	public static function setContentTypeHeader($type='application/json') {
43
+	public static function setContentTypeHeader($type = 'application/json') {
44 44
 		if (!self::$send_content_type_header) {
45 45
 			// We send json data
46
-			header( 'Content-Type: '.$type . '; charset=utf-8');
46
+			header('Content-Type: '.$type.'; charset=utf-8');
47 47
 			self::$send_content_type_header = true;
48 48
 		}
49 49
 	}
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 	 * @suppress PhanDeprecatedFunction
56 56
 	 */
57 57
 	public static function checkAppEnabled($app) {
58
-		if( !\OC::$server->getAppManager()->isEnabledForUser($app)) {
58
+		if (!\OC::$server->getAppManager()->isEnabledForUser($app)) {
59 59
 			$l = \OC::$server->getL10N('lib');
60
-			self::error(array( 'data' => array( 'message' => $l->t('Application is not enabled'), 'error' => 'application_not_enabled' )));
60
+			self::error(array('data' => array('message' => $l->t('Application is not enabled'), 'error' => 'application_not_enabled')));
61 61
 			exit();
62 62
 		}
63 63
 	}
@@ -69,11 +69,11 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public static function checkLoggedIn() {
71 71
 		$twoFactorAuthManger = \OC::$server->getTwoFactorAuthManager();
72
-		if( !\OC::$server->getUserSession()->isLoggedIn()
72
+		if (!\OC::$server->getUserSession()->isLoggedIn()
73 73
 			|| $twoFactorAuthManger->needsSecondFactor(\OC::$server->getUserSession()->getUser())) {
74 74
 			$l = \OC::$server->getL10N('lib');
75 75
 			http_response_code(\OCP\AppFramework\Http::STATUS_UNAUTHORIZED);
76
-			self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
76
+			self::error(array('data' => array('message' => $l->t('Authentication error'), 'error' => 'authentication_error')));
77 77
 			exit();
78 78
 		}
79 79
 	}
@@ -84,14 +84,14 @@  discard block
 block discarded – undo
84 84
 	 * @suppress PhanDeprecatedFunction
85 85
 	 */
86 86
 	public static function callCheck() {
87
-		if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
87
+		if (!\OC::$server->getRequest()->passesStrictCookieCheck()) {
88 88
 			header('Location: '.\OC::$WEBROOT);
89 89
 			exit();
90 90
 		}
91 91
 
92
-		if( !(\OC::$server->getRequest()->passesCSRFCheck())) {
92
+		if (!(\OC::$server->getRequest()->passesCSRFCheck())) {
93 93
 			$l = \OC::$server->getL10N('lib');
94
-			self::error(array( 'data' => array( 'message' => $l->t('Token expired. Please reload page.'), 'error' => 'token_expired' )));
94
+			self::error(array('data' => array('message' => $l->t('Token expired. Please reload page.'), 'error' => 'token_expired')));
95 95
 			exit();
96 96
 		}
97 97
 	}
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 	 * @suppress PhanDeprecatedFunction
103 103
 	 */
104 104
 	public static function checkAdminUser() {
105
-		if( !OC_User::isAdminUser(OC_User::getUser())) {
105
+		if (!OC_User::isAdminUser(OC_User::getUser())) {
106 106
 			$l = \OC::$server->getL10N('lib');
107
-			self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
107
+			self::error(array('data' => array('message' => $l->t('Authentication error'), 'error' => 'authentication_error')));
108 108
 			exit();
109 109
 		}
110 110
 	}
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	public static function checkUserExists($user) {
119 119
 		if (!OCP\User::userExists($user)) {
120 120
 			$l = \OC::$server->getL10N('lib');
121
-			OCP\JSON::error(array('data' => array('message' => $l->t('Unknown user'), 'error' => 'unknown_user' )));
121
+			OCP\JSON::error(array('data' => array('message' => $l->t('Unknown user'), 'error' => 'unknown_user')));
122 122
 			exit;
123 123
 		}
124 124
 	}
@@ -132,13 +132,13 @@  discard block
 block discarded – undo
132 132
 	public static function checkSubAdminUser() {
133 133
 		$userObject = \OC::$server->getUserSession()->getUser();
134 134
 		$isSubAdmin = false;
135
-		if($userObject !== null) {
135
+		if ($userObject !== null) {
136 136
 			$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
137 137
 		}
138 138
 
139
-		if(!$isSubAdmin) {
139
+		if (!$isSubAdmin) {
140 140
 			$l = \OC::$server->getL10N('lib');
141
-			self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
141
+			self::error(array('data' => array('message' => $l->t('Authentication error'), 'error' => 'authentication_error')));
142 142
 			exit();
143 143
 		}
144 144
 	}
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 */
169 169
 	protected static function to_string(&$value) {
170 170
 		if ($value instanceof \OC\L10N\L10NString) {
171
-			$value = (string)$value;
171
+			$value = (string) $value;
172 172
 		}
173 173
 	}
174 174
 
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
 	 * @deprecated Use a AppFramework JSONResponse instead
178 178
 	 * @suppress PhanDeprecatedFunction
179 179
 	 */
180
-	public static function encodedPrint($data, $setContentType=true) {
181
-		if($setContentType) {
180
+	public static function encodedPrint($data, $setContentType = true) {
181
+		if ($setContentType) {
182 182
 			self::setContentTypeHeader();
183 183
 		}
184 184
 		echo self::encode($data);
Please login to merge, or discard this patch.
lib/private/legacy/app.php 2 patches
Indentation   +1204 added lines, -1204 removed lines patch added patch discarded remove patch
@@ -61,1208 +61,1208 @@
 block discarded – undo
61 61
  * upgrading and removing apps.
62 62
  */
63 63
 class OC_App {
64
-	static private $appVersion = [];
65
-	static private $adminForms = array();
66
-	static private $personalForms = array();
67
-	static private $appInfo = array();
68
-	static private $appTypes = array();
69
-	static private $loadedApps = array();
70
-	static private $altLogin = array();
71
-	static private $alreadyRegistered = [];
72
-	const officialApp = 200;
73
-
74
-	/**
75
-	 * clean the appId
76
-	 *
77
-	 * @param string|boolean $app AppId that needs to be cleaned
78
-	 * @return string
79
-	 */
80
-	public static function cleanAppId($app) {
81
-		return str_replace(array('\0', '/', '\\', '..'), '', $app);
82
-	}
83
-
84
-	/**
85
-	 * Check if an app is loaded
86
-	 *
87
-	 * @param string $app
88
-	 * @return bool
89
-	 */
90
-	public static function isAppLoaded($app) {
91
-		return in_array($app, self::$loadedApps, true);
92
-	}
93
-
94
-	/**
95
-	 * loads all apps
96
-	 *
97
-	 * @param string[] | string | null $types
98
-	 * @return bool
99
-	 *
100
-	 * This function walks through the ownCloud directory and loads all apps
101
-	 * it can find. A directory contains an app if the file /appinfo/info.xml
102
-	 * exists.
103
-	 *
104
-	 * if $types is set, only apps of those types will be loaded
105
-	 */
106
-	public static function loadApps($types = null) {
107
-		if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) {
108
-			return false;
109
-		}
110
-		// Load the enabled apps here
111
-		$apps = self::getEnabledApps();
112
-
113
-		// Add each apps' folder as allowed class path
114
-		foreach($apps as $app) {
115
-			$path = self::getAppPath($app);
116
-			if($path !== false) {
117
-				self::registerAutoloading($app, $path);
118
-			}
119
-		}
120
-
121
-		// prevent app.php from printing output
122
-		ob_start();
123
-		foreach ($apps as $app) {
124
-			if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) {
125
-				self::loadApp($app);
126
-			}
127
-		}
128
-		ob_end_clean();
129
-
130
-		return true;
131
-	}
132
-
133
-	/**
134
-	 * load a single app
135
-	 *
136
-	 * @param string $app
137
-	 */
138
-	public static function loadApp($app) {
139
-		self::$loadedApps[] = $app;
140
-		$appPath = self::getAppPath($app);
141
-		if($appPath === false) {
142
-			return;
143
-		}
144
-
145
-		// in case someone calls loadApp() directly
146
-		self::registerAutoloading($app, $appPath);
147
-
148
-		if (is_file($appPath . '/appinfo/app.php')) {
149
-			\OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app);
150
-			self::requireAppFile($app);
151
-			if (self::isType($app, array('authentication'))) {
152
-				// since authentication apps affect the "is app enabled for group" check,
153
-				// the enabled apps cache needs to be cleared to make sure that the
154
-				// next time getEnableApps() is called it will also include apps that were
155
-				// enabled for groups
156
-				self::$enabledAppsCache = array();
157
-			}
158
-			\OC::$server->getEventLogger()->end('load_app_' . $app);
159
-		}
160
-
161
-		$info = self::getAppInfo($app);
162
-		if (!empty($info['activity']['filters'])) {
163
-			foreach ($info['activity']['filters'] as $filter) {
164
-				\OC::$server->getActivityManager()->registerFilter($filter);
165
-			}
166
-		}
167
-		if (!empty($info['activity']['settings'])) {
168
-			foreach ($info['activity']['settings'] as $setting) {
169
-				\OC::$server->getActivityManager()->registerSetting($setting);
170
-			}
171
-		}
172
-		if (!empty($info['activity']['providers'])) {
173
-			foreach ($info['activity']['providers'] as $provider) {
174
-				\OC::$server->getActivityManager()->registerProvider($provider);
175
-			}
176
-		}
177
-		if (!empty($info['collaboration']['plugins'])) {
178
-			// deal with one or many plugin entries
179
-			$plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ?
180
-				[$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin'];
181
-			foreach ($plugins as $plugin) {
182
-				if($plugin['@attributes']['type'] === 'collaborator-search') {
183
-					$pluginInfo = [
184
-						'shareType' => $plugin['@attributes']['share-type'],
185
-						'class' => $plugin['@value'],
186
-					];
187
-					\OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo);
188
-				}
189
-			}
190
-		}
191
-	}
192
-
193
-	/**
194
-	 * @internal
195
-	 * @param string $app
196
-	 * @param string $path
197
-	 */
198
-	public static function registerAutoloading($app, $path) {
199
-		$key = $app . '-' . $path;
200
-		if(isset(self::$alreadyRegistered[$key])) {
201
-			return;
202
-		}
203
-
204
-		self::$alreadyRegistered[$key] = true;
205
-
206
-		// Register on PSR-4 composer autoloader
207
-		$appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
208
-		\OC::$server->registerNamespace($app, $appNamespace);
209
-
210
-		if (file_exists($path . '/composer/autoload.php')) {
211
-			require_once $path . '/composer/autoload.php';
212
-		} else {
213
-			\OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
214
-			// Register on legacy autoloader
215
-			\OC::$loader->addValidRoot($path);
216
-		}
217
-
218
-		// Register Test namespace only when testing
219
-		if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
220
-			\OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
221
-		}
222
-	}
223
-
224
-	/**
225
-	 * Load app.php from the given app
226
-	 *
227
-	 * @param string $app app name
228
-	 */
229
-	private static function requireAppFile($app) {
230
-		try {
231
-			// encapsulated here to avoid variable scope conflicts
232
-			require_once $app . '/appinfo/app.php';
233
-		} catch (Error $ex) {
234
-			\OC::$server->getLogger()->logException($ex);
235
-			$blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
236
-			if (!in_array($app, $blacklist)) {
237
-				self::disable($app);
238
-			}
239
-		}
240
-	}
241
-
242
-	/**
243
-	 * check if an app is of a specific type
244
-	 *
245
-	 * @param string $app
246
-	 * @param string|array $types
247
-	 * @return bool
248
-	 */
249
-	public static function isType($app, $types) {
250
-		if (is_string($types)) {
251
-			$types = array($types);
252
-		}
253
-		$appTypes = self::getAppTypes($app);
254
-		foreach ($types as $type) {
255
-			if (array_search($type, $appTypes) !== false) {
256
-				return true;
257
-			}
258
-		}
259
-		return false;
260
-	}
261
-
262
-	/**
263
-	 * get the types of an app
264
-	 *
265
-	 * @param string $app
266
-	 * @return array
267
-	 */
268
-	private static function getAppTypes($app) {
269
-		//load the cache
270
-		if (count(self::$appTypes) == 0) {
271
-			self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types');
272
-		}
273
-
274
-		if (isset(self::$appTypes[$app])) {
275
-			return explode(',', self::$appTypes[$app]);
276
-		} else {
277
-			return array();
278
-		}
279
-	}
280
-
281
-	/**
282
-	 * read app types from info.xml and cache them in the database
283
-	 */
284
-	public static function setAppTypes($app) {
285
-		$appData = self::getAppInfo($app);
286
-		if(!is_array($appData)) {
287
-			return;
288
-		}
289
-
290
-		if (isset($appData['types'])) {
291
-			$appTypes = implode(',', $appData['types']);
292
-		} else {
293
-			$appTypes = '';
294
-			$appData['types'] = [];
295
-		}
296
-
297
-		\OC::$server->getAppConfig()->setValue($app, 'types', $appTypes);
298
-
299
-		if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) {
300
-			$enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes');
301
-			if ($enabled !== 'yes' && $enabled !== 'no') {
302
-				\OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes');
303
-			}
304
-		}
305
-	}
306
-
307
-	/**
308
-	 * get all enabled apps
309
-	 */
310
-	protected static $enabledAppsCache = array();
311
-
312
-	/**
313
-	 * Returns apps enabled for the current user.
314
-	 *
315
-	 * @param bool $forceRefresh whether to refresh the cache
316
-	 * @param bool $all whether to return apps for all users, not only the
317
-	 * currently logged in one
318
-	 * @return string[]
319
-	 */
320
-	public static function getEnabledApps($forceRefresh = false, $all = false) {
321
-		if (!\OC::$server->getSystemConfig()->getValue('installed', false)) {
322
-			return array();
323
-		}
324
-		// in incognito mode or when logged out, $user will be false,
325
-		// which is also the case during an upgrade
326
-		$appManager = \OC::$server->getAppManager();
327
-		if ($all) {
328
-			$user = null;
329
-		} else {
330
-			$user = \OC::$server->getUserSession()->getUser();
331
-		}
332
-
333
-		if (is_null($user)) {
334
-			$apps = $appManager->getInstalledApps();
335
-		} else {
336
-			$apps = $appManager->getEnabledAppsForUser($user);
337
-		}
338
-		$apps = array_filter($apps, function ($app) {
339
-			return $app !== 'files';//we add this manually
340
-		});
341
-		sort($apps);
342
-		array_unshift($apps, 'files');
343
-		return $apps;
344
-	}
345
-
346
-	/**
347
-	 * checks whether or not an app is enabled
348
-	 *
349
-	 * @param string $app app
350
-	 * @return bool
351
-	 *
352
-	 * This function checks whether or not an app is enabled.
353
-	 */
354
-	public static function isEnabled($app) {
355
-		return \OC::$server->getAppManager()->isEnabledForUser($app);
356
-	}
357
-
358
-	/**
359
-	 * enables an app
360
-	 *
361
-	 * @param string $appId
362
-	 * @param array $groups (optional) when set, only these groups will have access to the app
363
-	 * @throws \Exception
364
-	 * @return void
365
-	 *
366
-	 * This function set an app as enabled in appconfig.
367
-	 */
368
-	public function enable($appId,
369
-						   $groups = null) {
370
-		self::$enabledAppsCache = []; // flush
371
-
372
-		// Check if app is already downloaded
373
-		$installer = new Installer(
374
-			\OC::$server->getAppFetcher(),
375
-			\OC::$server->getHTTPClientService(),
376
-			\OC::$server->getTempManager(),
377
-			\OC::$server->getLogger(),
378
-			\OC::$server->getConfig()
379
-		);
380
-		$isDownloaded = $installer->isDownloaded($appId);
381
-
382
-		if(!$isDownloaded) {
383
-			$installer->downloadApp($appId);
384
-		}
385
-
386
-		$installer->installApp($appId);
387
-
388
-		$appManager = \OC::$server->getAppManager();
389
-		if (!is_null($groups)) {
390
-			$groupManager = \OC::$server->getGroupManager();
391
-			$groupsList = [];
392
-			foreach ($groups as $group) {
393
-				$groupItem = $groupManager->get($group);
394
-				if ($groupItem instanceof \OCP\IGroup) {
395
-					$groupsList[] = $groupManager->get($group);
396
-				}
397
-			}
398
-			$appManager->enableAppForGroups($appId, $groupsList);
399
-		} else {
400
-			$appManager->enableApp($appId);
401
-		}
402
-	}
403
-
404
-	/**
405
-	 * @param string $app
406
-	 * @return bool
407
-	 */
408
-	public static function removeApp($app) {
409
-		if (\OC::$server->getAppManager()->isShipped($app)) {
410
-			return false;
411
-		}
412
-
413
-		$installer = new Installer(
414
-			\OC::$server->getAppFetcher(),
415
-			\OC::$server->getHTTPClientService(),
416
-			\OC::$server->getTempManager(),
417
-			\OC::$server->getLogger(),
418
-			\OC::$server->getConfig()
419
-		);
420
-		return $installer->removeApp($app);
421
-	}
422
-
423
-	/**
424
-	 * This function set an app as disabled in appconfig.
425
-	 *
426
-	 * @param string $app app
427
-	 * @throws Exception
428
-	 */
429
-	public static function disable($app) {
430
-		// flush
431
-		self::$enabledAppsCache = array();
432
-
433
-		// run uninstall steps
434
-		$appData = OC_App::getAppInfo($app);
435
-		if (!is_null($appData)) {
436
-			OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']);
437
-		}
438
-
439
-		// emit disable hook - needed anymore ?
440
-		\OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app));
441
-
442
-		// finally disable it
443
-		$appManager = \OC::$server->getAppManager();
444
-		$appManager->disableApp($app);
445
-	}
446
-
447
-	// This is private as well. It simply works, so don't ask for more details
448
-	private static function proceedNavigation($list) {
449
-		usort($list, function($a, $b) {
450
-			if (isset($a['order']) && isset($b['order'])) {
451
-				return ($a['order'] < $b['order']) ? -1 : 1;
452
-			} else if (isset($a['order']) || isset($b['order'])) {
453
-				return isset($a['order']) ? -1 : 1;
454
-			} else {
455
-				return ($a['name'] < $b['name']) ? -1 : 1;
456
-			}
457
-		});
458
-
459
-		$activeApp = OC::$server->getNavigationManager()->getActiveEntry();
460
-		foreach ($list as $index => &$navEntry) {
461
-			if ($navEntry['id'] == $activeApp) {
462
-				$navEntry['active'] = true;
463
-			} else {
464
-				$navEntry['active'] = false;
465
-			}
466
-		}
467
-		unset($navEntry);
468
-
469
-		return $list;
470
-	}
471
-
472
-	/**
473
-	 * Get the path where to install apps
474
-	 *
475
-	 * @return string|false
476
-	 */
477
-	public static function getInstallPath() {
478
-		if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) {
479
-			return false;
480
-		}
481
-
482
-		foreach (OC::$APPSROOTS as $dir) {
483
-			if (isset($dir['writable']) && $dir['writable'] === true) {
484
-				return $dir['path'];
485
-			}
486
-		}
487
-
488
-		\OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR);
489
-		return null;
490
-	}
491
-
492
-
493
-	/**
494
-	 * search for an app in all app-directories
495
-	 *
496
-	 * @param string $appId
497
-	 * @return false|string
498
-	 */
499
-	public static function findAppInDirectories($appId) {
500
-		$sanitizedAppId = self::cleanAppId($appId);
501
-		if($sanitizedAppId !== $appId) {
502
-			return false;
503
-		}
504
-		static $app_dir = array();
505
-
506
-		if (isset($app_dir[$appId])) {
507
-			return $app_dir[$appId];
508
-		}
509
-
510
-		$possibleApps = array();
511
-		foreach (OC::$APPSROOTS as $dir) {
512
-			if (file_exists($dir['path'] . '/' . $appId)) {
513
-				$possibleApps[] = $dir;
514
-			}
515
-		}
516
-
517
-		if (empty($possibleApps)) {
518
-			return false;
519
-		} elseif (count($possibleApps) === 1) {
520
-			$dir = array_shift($possibleApps);
521
-			$app_dir[$appId] = $dir;
522
-			return $dir;
523
-		} else {
524
-			$versionToLoad = array();
525
-			foreach ($possibleApps as $possibleApp) {
526
-				$version = self::getAppVersionByPath($possibleApp['path']);
527
-				if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) {
528
-					$versionToLoad = array(
529
-						'dir' => $possibleApp,
530
-						'version' => $version,
531
-					);
532
-				}
533
-			}
534
-			$app_dir[$appId] = $versionToLoad['dir'];
535
-			return $versionToLoad['dir'];
536
-			//TODO - write test
537
-		}
538
-	}
539
-
540
-	/**
541
-	 * Get the directory for the given app.
542
-	 * If the app is defined in multiple directories, the first one is taken. (false if not found)
543
-	 *
544
-	 * @param string $appId
545
-	 * @return string|false
546
-	 */
547
-	public static function getAppPath($appId) {
548
-		if ($appId === null || trim($appId) === '') {
549
-			return false;
550
-		}
551
-
552
-		if (($dir = self::findAppInDirectories($appId)) != false) {
553
-			return $dir['path'] . '/' . $appId;
554
-		}
555
-		return false;
556
-	}
557
-
558
-	/**
559
-	 * Get the path for the given app on the access
560
-	 * If the app is defined in multiple directories, the first one is taken. (false if not found)
561
-	 *
562
-	 * @param string $appId
563
-	 * @return string|false
564
-	 */
565
-	public static function getAppWebPath($appId) {
566
-		if (($dir = self::findAppInDirectories($appId)) != false) {
567
-			return OC::$WEBROOT . $dir['url'] . '/' . $appId;
568
-		}
569
-		return false;
570
-	}
571
-
572
-	/**
573
-	 * get the last version of the app from appinfo/info.xml
574
-	 *
575
-	 * @param string $appId
576
-	 * @param bool $useCache
577
-	 * @return string
578
-	 */
579
-	public static function getAppVersion($appId, $useCache = true) {
580
-		if($useCache && isset(self::$appVersion[$appId])) {
581
-			return self::$appVersion[$appId];
582
-		}
583
-
584
-		$file = self::getAppPath($appId);
585
-		self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0';
586
-		return self::$appVersion[$appId];
587
-	}
588
-
589
-	/**
590
-	 * get app's version based on it's path
591
-	 *
592
-	 * @param string $path
593
-	 * @return string
594
-	 */
595
-	public static function getAppVersionByPath($path) {
596
-		$infoFile = $path . '/appinfo/info.xml';
597
-		$appData = self::getAppInfo($infoFile, true);
598
-		return isset($appData['version']) ? $appData['version'] : '';
599
-	}
600
-
601
-
602
-	/**
603
-	 * Read all app metadata from the info.xml file
604
-	 *
605
-	 * @param string $appId id of the app or the path of the info.xml file
606
-	 * @param bool $path
607
-	 * @param string $lang
608
-	 * @return array|null
609
-	 * @note all data is read from info.xml, not just pre-defined fields
610
-	 */
611
-	public static function getAppInfo($appId, $path = false, $lang = null) {
612
-		if ($path) {
613
-			$file = $appId;
614
-		} else {
615
-			if ($lang === null && isset(self::$appInfo[$appId])) {
616
-				return self::$appInfo[$appId];
617
-			}
618
-			$appPath = self::getAppPath($appId);
619
-			if($appPath === false) {
620
-				return null;
621
-			}
622
-			$file = $appPath . '/appinfo/info.xml';
623
-		}
624
-
625
-		$parser = new InfoParser(\OC::$server->getMemCacheFactory()->createLocal('core.appinfo'));
626
-		$data = $parser->parse($file);
627
-
628
-		if (is_array($data)) {
629
-			$data = OC_App::parseAppInfo($data, $lang);
630
-		}
631
-		if(isset($data['ocsid'])) {
632
-			$storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid');
633
-			if($storedId !== '' && $storedId !== $data['ocsid']) {
634
-				$data['ocsid'] = $storedId;
635
-			}
636
-		}
637
-
638
-		if ($lang === null) {
639
-			self::$appInfo[$appId] = $data;
640
-		}
641
-
642
-		return $data;
643
-	}
644
-
645
-	/**
646
-	 * Returns the navigation
647
-	 *
648
-	 * @return array
649
-	 *
650
-	 * This function returns an array containing all entries added. The
651
-	 * entries are sorted by the key 'order' ascending. Additional to the keys
652
-	 * given for each app the following keys exist:
653
-	 *   - active: boolean, signals if the user is on this navigation entry
654
-	 */
655
-	public static function getNavigation() {
656
-		$entries = OC::$server->getNavigationManager()->getAll();
657
-		return self::proceedNavigation($entries);
658
-	}
659
-
660
-	/**
661
-	 * Returns the Settings Navigation
662
-	 *
663
-	 * @return string[]
664
-	 *
665
-	 * This function returns an array containing all settings pages added. The
666
-	 * entries are sorted by the key 'order' ascending.
667
-	 */
668
-	public static function getSettingsNavigation() {
669
-		$entries = OC::$server->getNavigationManager()->getAll('settings');
670
-		return self::proceedNavigation($entries);
671
-	}
672
-
673
-	/**
674
-	 * get the id of loaded app
675
-	 *
676
-	 * @return string
677
-	 */
678
-	public static function getCurrentApp() {
679
-		$request = \OC::$server->getRequest();
680
-		$script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1);
681
-		$topFolder = substr($script, 0, strpos($script, '/'));
682
-		if (empty($topFolder)) {
683
-			$path_info = $request->getPathInfo();
684
-			if ($path_info) {
685
-				$topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
686
-			}
687
-		}
688
-		if ($topFolder == 'apps') {
689
-			$length = strlen($topFolder);
690
-			return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1);
691
-		} else {
692
-			return $topFolder;
693
-		}
694
-	}
695
-
696
-	/**
697
-	 * @param string $type
698
-	 * @return array
699
-	 */
700
-	public static function getForms($type) {
701
-		$forms = array();
702
-		switch ($type) {
703
-			case 'admin':
704
-				$source = self::$adminForms;
705
-				break;
706
-			case 'personal':
707
-				$source = self::$personalForms;
708
-				break;
709
-			default:
710
-				return array();
711
-		}
712
-		foreach ($source as $form) {
713
-			$forms[] = include $form;
714
-		}
715
-		return $forms;
716
-	}
717
-
718
-	/**
719
-	 * register an admin form to be shown
720
-	 *
721
-	 * @param string $app
722
-	 * @param string $page
723
-	 */
724
-	public static function registerAdmin($app, $page) {
725
-		self::$adminForms[] = $app . '/' . $page . '.php';
726
-	}
727
-
728
-	/**
729
-	 * register a personal form to be shown
730
-	 * @param string $app
731
-	 * @param string $page
732
-	 */
733
-	public static function registerPersonal($app, $page) {
734
-		self::$personalForms[] = $app . '/' . $page . '.php';
735
-	}
736
-
737
-	/**
738
-	 * @param array $entry
739
-	 */
740
-	public static function registerLogIn(array $entry) {
741
-		self::$altLogin[] = $entry;
742
-	}
743
-
744
-	/**
745
-	 * @return array
746
-	 */
747
-	public static function getAlternativeLogIns() {
748
-		return self::$altLogin;
749
-	}
750
-
751
-	/**
752
-	 * get a list of all apps in the apps folder
753
-	 *
754
-	 * @return array an array of app names (string IDs)
755
-	 * @todo: change the name of this method to getInstalledApps, which is more accurate
756
-	 */
757
-	public static function getAllApps() {
758
-
759
-		$apps = array();
760
-
761
-		foreach (OC::$APPSROOTS as $apps_dir) {
762
-			if (!is_readable($apps_dir['path'])) {
763
-				\OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN);
764
-				continue;
765
-			}
766
-			$dh = opendir($apps_dir['path']);
767
-
768
-			if (is_resource($dh)) {
769
-				while (($file = readdir($dh)) !== false) {
770
-
771
-					if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
772
-
773
-						$apps[] = $file;
774
-					}
775
-				}
776
-			}
777
-		}
778
-
779
-		$apps = array_unique($apps);
780
-
781
-		return $apps;
782
-	}
783
-
784
-	/**
785
-	 * List all apps, this is used in apps.php
786
-	 *
787
-	 * @return array
788
-	 */
789
-	public function listAllApps() {
790
-		$installedApps = OC_App::getAllApps();
791
-
792
-		$appManager = \OC::$server->getAppManager();
793
-		//we don't want to show configuration for these
794
-		$blacklist = $appManager->getAlwaysEnabledApps();
795
-		$appList = array();
796
-		$langCode = \OC::$server->getL10N('core')->getLanguageCode();
797
-		$urlGenerator = \OC::$server->getURLGenerator();
798
-
799
-		foreach ($installedApps as $app) {
800
-			if (array_search($app, $blacklist) === false) {
801
-
802
-				$info = OC_App::getAppInfo($app, false, $langCode);
803
-				if (!is_array($info)) {
804
-					\OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR);
805
-					continue;
806
-				}
807
-
808
-				if (!isset($info['name'])) {
809
-					\OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR);
810
-					continue;
811
-				}
812
-
813
-				$enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no');
814
-				$info['groups'] = null;
815
-				if ($enabled === 'yes') {
816
-					$active = true;
817
-				} else if ($enabled === 'no') {
818
-					$active = false;
819
-				} else {
820
-					$active = true;
821
-					$info['groups'] = $enabled;
822
-				}
823
-
824
-				$info['active'] = $active;
825
-
826
-				if ($appManager->isShipped($app)) {
827
-					$info['internal'] = true;
828
-					$info['level'] = self::officialApp;
829
-					$info['removable'] = false;
830
-				} else {
831
-					$info['internal'] = false;
832
-					$info['removable'] = true;
833
-				}
834
-
835
-				$appPath = self::getAppPath($app);
836
-				if($appPath !== false) {
837
-					$appIcon = $appPath . '/img/' . $app . '.svg';
838
-					if (file_exists($appIcon)) {
839
-						$info['preview'] = $urlGenerator->imagePath($app, $app . '.svg');
840
-						$info['previewAsIcon'] = true;
841
-					} else {
842
-						$appIcon = $appPath . '/img/app.svg';
843
-						if (file_exists($appIcon)) {
844
-							$info['preview'] = $urlGenerator->imagePath($app, 'app.svg');
845
-							$info['previewAsIcon'] = true;
846
-						}
847
-					}
848
-				}
849
-				// fix documentation
850
-				if (isset($info['documentation']) && is_array($info['documentation'])) {
851
-					foreach ($info['documentation'] as $key => $url) {
852
-						// If it is not an absolute URL we assume it is a key
853
-						// i.e. admin-ldap will get converted to go.php?to=admin-ldap
854
-						if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) {
855
-							$url = $urlGenerator->linkToDocs($url);
856
-						}
857
-
858
-						$info['documentation'][$key] = $url;
859
-					}
860
-				}
861
-
862
-				$info['version'] = OC_App::getAppVersion($app);
863
-				$appList[] = $info;
864
-			}
865
-		}
866
-
867
-		return $appList;
868
-	}
869
-
870
-	/**
871
-	 * Returns the internal app ID or false
872
-	 * @param string $ocsID
873
-	 * @return string|false
874
-	 */
875
-	public static function getInternalAppIdByOcs($ocsID) {
876
-		if(is_numeric($ocsID)) {
877
-			$idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid');
878
-			if(array_search($ocsID, $idArray)) {
879
-				return array_search($ocsID, $idArray);
880
-			}
881
-		}
882
-		return false;
883
-	}
884
-
885
-	public static function shouldUpgrade($app) {
886
-		$versions = self::getAppVersions();
887
-		$currentVersion = OC_App::getAppVersion($app);
888
-		if ($currentVersion && isset($versions[$app])) {
889
-			$installedVersion = $versions[$app];
890
-			if (!version_compare($currentVersion, $installedVersion, '=')) {
891
-				return true;
892
-			}
893
-		}
894
-		return false;
895
-	}
896
-
897
-	/**
898
-	 * Adjust the number of version parts of $version1 to match
899
-	 * the number of version parts of $version2.
900
-	 *
901
-	 * @param string $version1 version to adjust
902
-	 * @param string $version2 version to take the number of parts from
903
-	 * @return string shortened $version1
904
-	 */
905
-	private static function adjustVersionParts($version1, $version2) {
906
-		$version1 = explode('.', $version1);
907
-		$version2 = explode('.', $version2);
908
-		// reduce $version1 to match the number of parts in $version2
909
-		while (count($version1) > count($version2)) {
910
-			array_pop($version1);
911
-		}
912
-		// if $version1 does not have enough parts, add some
913
-		while (count($version1) < count($version2)) {
914
-			$version1[] = '0';
915
-		}
916
-		return implode('.', $version1);
917
-	}
918
-
919
-	/**
920
-	 * Check whether the current ownCloud version matches the given
921
-	 * application's version requirements.
922
-	 *
923
-	 * The comparison is made based on the number of parts that the
924
-	 * app info version has. For example for ownCloud 6.0.3 if the
925
-	 * app info version is expecting version 6.0, the comparison is
926
-	 * made on the first two parts of the ownCloud version.
927
-	 * This means that it's possible to specify "requiremin" => 6
928
-	 * and "requiremax" => 6 and it will still match ownCloud 6.0.3.
929
-	 *
930
-	 * @param string $ocVersion ownCloud version to check against
931
-	 * @param array $appInfo app info (from xml)
932
-	 *
933
-	 * @return boolean true if compatible, otherwise false
934
-	 */
935
-	public static function isAppCompatible($ocVersion, $appInfo) {
936
-		$requireMin = '';
937
-		$requireMax = '';
938
-		if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) {
939
-			$requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version'];
940
-		} elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) {
941
-			$requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version'];
942
-		} else if (isset($appInfo['requiremin'])) {
943
-			$requireMin = $appInfo['requiremin'];
944
-		} else if (isset($appInfo['require'])) {
945
-			$requireMin = $appInfo['require'];
946
-		}
947
-
948
-		if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) {
949
-			$requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version'];
950
-		} elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) {
951
-			$requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version'];
952
-		} else if (isset($appInfo['requiremax'])) {
953
-			$requireMax = $appInfo['requiremax'];
954
-		}
955
-
956
-		if (is_array($ocVersion)) {
957
-			$ocVersion = implode('.', $ocVersion);
958
-		}
959
-
960
-		if (!empty($requireMin)
961
-			&& version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<')
962
-		) {
963
-
964
-			return false;
965
-		}
966
-
967
-		if (!empty($requireMax)
968
-			&& version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>')
969
-		) {
970
-			return false;
971
-		}
972
-
973
-		return true;
974
-	}
975
-
976
-	/**
977
-	 * get the installed version of all apps
978
-	 */
979
-	public static function getAppVersions() {
980
-		static $versions;
981
-
982
-		if(!$versions) {
983
-			$appConfig = \OC::$server->getAppConfig();
984
-			$versions = $appConfig->getValues(false, 'installed_version');
985
-		}
986
-		return $versions;
987
-	}
988
-
989
-	/**
990
-	 * @param string $app
991
-	 * @param \OCP\IConfig $config
992
-	 * @param \OCP\IL10N $l
993
-	 * @return bool
994
-	 *
995
-	 * @throws Exception if app is not compatible with this version of ownCloud
996
-	 * @throws Exception if no app-name was specified
997
-	 */
998
-	public function installApp($app,
999
-							   \OCP\IConfig $config,
1000
-							   \OCP\IL10N $l) {
1001
-		if ($app !== false) {
1002
-			// check if the app is compatible with this version of ownCloud
1003
-			$info = self::getAppInfo($app);
1004
-			if(!is_array($info)) {
1005
-				throw new \Exception(
1006
-					$l->t('App "%s" cannot be installed because appinfo file cannot be read.',
1007
-						[$info['name']]
1008
-					)
1009
-				);
1010
-			}
1011
-
1012
-			$version = \OCP\Util::getVersion();
1013
-			if (!self::isAppCompatible($version, $info)) {
1014
-				throw new \Exception(
1015
-					$l->t('App "%s" cannot be installed because it is not compatible with this version of the server.',
1016
-						array($info['name'])
1017
-					)
1018
-				);
1019
-			}
1020
-
1021
-			// check for required dependencies
1022
-			self::checkAppDependencies($config, $l, $info);
1023
-
1024
-			$config->setAppValue($app, 'enabled', 'yes');
1025
-			if (isset($appData['id'])) {
1026
-				$config->setAppValue($app, 'ocsid', $appData['id']);
1027
-			}
1028
-
1029
-			if(isset($info['settings']) && is_array($info['settings'])) {
1030
-				$appPath = self::getAppPath($app);
1031
-				self::registerAutoloading($app, $appPath);
1032
-				\OC::$server->getSettingsManager()->setupSettings($info['settings']);
1033
-			}
1034
-
1035
-			\OC_Hook::emit('OC_App', 'post_enable', array('app' => $app));
1036
-		} else {
1037
-			if(empty($appName) ) {
1038
-				throw new \Exception($l->t("No app name specified"));
1039
-			} else {
1040
-				throw new \Exception($l->t("App '%s' could not be installed!", $appName));
1041
-			}
1042
-		}
1043
-
1044
-		return $app;
1045
-	}
1046
-
1047
-	/**
1048
-	 * update the database for the app and call the update script
1049
-	 *
1050
-	 * @param string $appId
1051
-	 * @return bool
1052
-	 */
1053
-	public static function updateApp($appId) {
1054
-		$appPath = self::getAppPath($appId);
1055
-		if($appPath === false) {
1056
-			return false;
1057
-		}
1058
-		self::registerAutoloading($appId, $appPath);
1059
-
1060
-		$appData = self::getAppInfo($appId);
1061
-		self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
1062
-
1063
-		if (file_exists($appPath . '/appinfo/database.xml')) {
1064
-			OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
1065
-		} else {
1066
-			$ms = new MigrationService($appId, \OC::$server->getDatabaseConnection());
1067
-			$ms->migrate();
1068
-		}
1069
-
1070
-		self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
1071
-		self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
1072
-		unset(self::$appVersion[$appId]);
1073
-
1074
-		// run upgrade code
1075
-		if (file_exists($appPath . '/appinfo/update.php')) {
1076
-			self::loadApp($appId);
1077
-			include $appPath . '/appinfo/update.php';
1078
-		}
1079
-		self::setupBackgroundJobs($appData['background-jobs']);
1080
-		if(isset($appData['settings']) && is_array($appData['settings'])) {
1081
-			\OC::$server->getSettingsManager()->setupSettings($appData['settings']);
1082
-		}
1083
-
1084
-		//set remote/public handlers
1085
-		if (array_key_exists('ocsid', $appData)) {
1086
-			\OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
1087
-		} elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
1088
-			\OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
1089
-		}
1090
-		foreach ($appData['remote'] as $name => $path) {
1091
-			\OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
1092
-		}
1093
-		foreach ($appData['public'] as $name => $path) {
1094
-			\OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
1095
-		}
1096
-
1097
-		self::setAppTypes($appId);
1098
-
1099
-		$version = \OC_App::getAppVersion($appId);
1100
-		\OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version);
1101
-
1102
-		\OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent(
1103
-			ManagerEvent::EVENT_APP_UPDATE, $appId
1104
-		));
1105
-
1106
-		return true;
1107
-	}
1108
-
1109
-	/**
1110
-	 * @param string $appId
1111
-	 * @param string[] $steps
1112
-	 * @throws \OC\NeedsUpdateException
1113
-	 */
1114
-	public static function executeRepairSteps($appId, array $steps) {
1115
-		if (empty($steps)) {
1116
-			return;
1117
-		}
1118
-		// load the app
1119
-		self::loadApp($appId);
1120
-
1121
-		$dispatcher = OC::$server->getEventDispatcher();
1122
-
1123
-		// load the steps
1124
-		$r = new Repair([], $dispatcher);
1125
-		foreach ($steps as $step) {
1126
-			try {
1127
-				$r->addStep($step);
1128
-			} catch (Exception $ex) {
1129
-				$r->emit('\OC\Repair', 'error', [$ex->getMessage()]);
1130
-				\OC::$server->getLogger()->logException($ex);
1131
-			}
1132
-		}
1133
-		// run the steps
1134
-		$r->run();
1135
-	}
1136
-
1137
-	public static function setupBackgroundJobs(array $jobs) {
1138
-		$queue = \OC::$server->getJobList();
1139
-		foreach ($jobs as $job) {
1140
-			$queue->add($job);
1141
-		}
1142
-	}
1143
-
1144
-	/**
1145
-	 * @param string $appId
1146
-	 * @param string[] $steps
1147
-	 */
1148
-	private static function setupLiveMigrations($appId, array $steps) {
1149
-		$queue = \OC::$server->getJobList();
1150
-		foreach ($steps as $step) {
1151
-			$queue->add('OC\Migration\BackgroundRepair', [
1152
-				'app' => $appId,
1153
-				'step' => $step]);
1154
-		}
1155
-	}
1156
-
1157
-	/**
1158
-	 * @param string $appId
1159
-	 * @return \OC\Files\View|false
1160
-	 */
1161
-	public static function getStorage($appId) {
1162
-		if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check
1163
-			if (\OC::$server->getUserSession()->isLoggedIn()) {
1164
-				$view = new \OC\Files\View('/' . OC_User::getUser());
1165
-				if (!$view->file_exists($appId)) {
1166
-					$view->mkdir($appId);
1167
-				}
1168
-				return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1169
-			} else {
1170
-				\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR);
1171
-				return false;
1172
-			}
1173
-		} else {
1174
-			\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR);
1175
-			return false;
1176
-		}
1177
-	}
1178
-
1179
-	protected static function findBestL10NOption($options, $lang) {
1180
-		$fallback = $similarLangFallback = $englishFallback = false;
1181
-
1182
-		$lang = strtolower($lang);
1183
-		$similarLang = $lang;
1184
-		if (strpos($similarLang, '_')) {
1185
-			// For "de_DE" we want to find "de" and the other way around
1186
-			$similarLang = substr($lang, 0, strpos($lang, '_'));
1187
-		}
1188
-
1189
-		foreach ($options as $option) {
1190
-			if (is_array($option)) {
1191
-				if ($fallback === false) {
1192
-					$fallback = $option['@value'];
1193
-				}
1194
-
1195
-				if (!isset($option['@attributes']['lang'])) {
1196
-					continue;
1197
-				}
1198
-
1199
-				$attributeLang = strtolower($option['@attributes']['lang']);
1200
-				if ($attributeLang === $lang) {
1201
-					return $option['@value'];
1202
-				}
1203
-
1204
-				if ($attributeLang === $similarLang) {
1205
-					$similarLangFallback = $option['@value'];
1206
-				} else if (strpos($attributeLang, $similarLang . '_') === 0) {
1207
-					if ($similarLangFallback === false) {
1208
-						$similarLangFallback =  $option['@value'];
1209
-					}
1210
-				}
1211
-			} else {
1212
-				$englishFallback = $option;
1213
-			}
1214
-		}
1215
-
1216
-		if ($similarLangFallback !== false) {
1217
-			return $similarLangFallback;
1218
-		} else if ($englishFallback !== false) {
1219
-			return $englishFallback;
1220
-		}
1221
-		return (string) $fallback;
1222
-	}
1223
-
1224
-	/**
1225
-	 * parses the app data array and enhanced the 'description' value
1226
-	 *
1227
-	 * @param array $data the app data
1228
-	 * @param string $lang
1229
-	 * @return array improved app data
1230
-	 */
1231
-	public static function parseAppInfo(array $data, $lang = null) {
1232
-
1233
-		if ($lang && isset($data['name']) && is_array($data['name'])) {
1234
-			$data['name'] = self::findBestL10NOption($data['name'], $lang);
1235
-		}
1236
-		if ($lang && isset($data['summary']) && is_array($data['summary'])) {
1237
-			$data['summary'] = self::findBestL10NOption($data['summary'], $lang);
1238
-		}
1239
-		if ($lang && isset($data['description']) && is_array($data['description'])) {
1240
-			$data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1241
-		} else if (isset($data['description']) && is_string($data['description'])) {
1242
-			$data['description'] = trim($data['description']);
1243
-		} else  {
1244
-			$data['description'] = '';
1245
-		}
1246
-
1247
-		return $data;
1248
-	}
1249
-
1250
-	/**
1251
-	 * @param \OCP\IConfig $config
1252
-	 * @param \OCP\IL10N $l
1253
-	 * @param array $info
1254
-	 * @throws \Exception
1255
-	 */
1256
-	public static function checkAppDependencies($config, $l, $info) {
1257
-		$dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
1258
-		$missing = $dependencyAnalyzer->analyze($info);
1259
-		if (!empty($missing)) {
1260
-			$missingMsg = implode(PHP_EOL, $missing);
1261
-			throw new \Exception(
1262
-				$l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s',
1263
-					[$info['name'], $missingMsg]
1264
-				)
1265
-			);
1266
-		}
1267
-	}
64
+    static private $appVersion = [];
65
+    static private $adminForms = array();
66
+    static private $personalForms = array();
67
+    static private $appInfo = array();
68
+    static private $appTypes = array();
69
+    static private $loadedApps = array();
70
+    static private $altLogin = array();
71
+    static private $alreadyRegistered = [];
72
+    const officialApp = 200;
73
+
74
+    /**
75
+     * clean the appId
76
+     *
77
+     * @param string|boolean $app AppId that needs to be cleaned
78
+     * @return string
79
+     */
80
+    public static function cleanAppId($app) {
81
+        return str_replace(array('\0', '/', '\\', '..'), '', $app);
82
+    }
83
+
84
+    /**
85
+     * Check if an app is loaded
86
+     *
87
+     * @param string $app
88
+     * @return bool
89
+     */
90
+    public static function isAppLoaded($app) {
91
+        return in_array($app, self::$loadedApps, true);
92
+    }
93
+
94
+    /**
95
+     * loads all apps
96
+     *
97
+     * @param string[] | string | null $types
98
+     * @return bool
99
+     *
100
+     * This function walks through the ownCloud directory and loads all apps
101
+     * it can find. A directory contains an app if the file /appinfo/info.xml
102
+     * exists.
103
+     *
104
+     * if $types is set, only apps of those types will be loaded
105
+     */
106
+    public static function loadApps($types = null) {
107
+        if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) {
108
+            return false;
109
+        }
110
+        // Load the enabled apps here
111
+        $apps = self::getEnabledApps();
112
+
113
+        // Add each apps' folder as allowed class path
114
+        foreach($apps as $app) {
115
+            $path = self::getAppPath($app);
116
+            if($path !== false) {
117
+                self::registerAutoloading($app, $path);
118
+            }
119
+        }
120
+
121
+        // prevent app.php from printing output
122
+        ob_start();
123
+        foreach ($apps as $app) {
124
+            if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) {
125
+                self::loadApp($app);
126
+            }
127
+        }
128
+        ob_end_clean();
129
+
130
+        return true;
131
+    }
132
+
133
+    /**
134
+     * load a single app
135
+     *
136
+     * @param string $app
137
+     */
138
+    public static function loadApp($app) {
139
+        self::$loadedApps[] = $app;
140
+        $appPath = self::getAppPath($app);
141
+        if($appPath === false) {
142
+            return;
143
+        }
144
+
145
+        // in case someone calls loadApp() directly
146
+        self::registerAutoloading($app, $appPath);
147
+
148
+        if (is_file($appPath . '/appinfo/app.php')) {
149
+            \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app);
150
+            self::requireAppFile($app);
151
+            if (self::isType($app, array('authentication'))) {
152
+                // since authentication apps affect the "is app enabled for group" check,
153
+                // the enabled apps cache needs to be cleared to make sure that the
154
+                // next time getEnableApps() is called it will also include apps that were
155
+                // enabled for groups
156
+                self::$enabledAppsCache = array();
157
+            }
158
+            \OC::$server->getEventLogger()->end('load_app_' . $app);
159
+        }
160
+
161
+        $info = self::getAppInfo($app);
162
+        if (!empty($info['activity']['filters'])) {
163
+            foreach ($info['activity']['filters'] as $filter) {
164
+                \OC::$server->getActivityManager()->registerFilter($filter);
165
+            }
166
+        }
167
+        if (!empty($info['activity']['settings'])) {
168
+            foreach ($info['activity']['settings'] as $setting) {
169
+                \OC::$server->getActivityManager()->registerSetting($setting);
170
+            }
171
+        }
172
+        if (!empty($info['activity']['providers'])) {
173
+            foreach ($info['activity']['providers'] as $provider) {
174
+                \OC::$server->getActivityManager()->registerProvider($provider);
175
+            }
176
+        }
177
+        if (!empty($info['collaboration']['plugins'])) {
178
+            // deal with one or many plugin entries
179
+            $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ?
180
+                [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin'];
181
+            foreach ($plugins as $plugin) {
182
+                if($plugin['@attributes']['type'] === 'collaborator-search') {
183
+                    $pluginInfo = [
184
+                        'shareType' => $plugin['@attributes']['share-type'],
185
+                        'class' => $plugin['@value'],
186
+                    ];
187
+                    \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo);
188
+                }
189
+            }
190
+        }
191
+    }
192
+
193
+    /**
194
+     * @internal
195
+     * @param string $app
196
+     * @param string $path
197
+     */
198
+    public static function registerAutoloading($app, $path) {
199
+        $key = $app . '-' . $path;
200
+        if(isset(self::$alreadyRegistered[$key])) {
201
+            return;
202
+        }
203
+
204
+        self::$alreadyRegistered[$key] = true;
205
+
206
+        // Register on PSR-4 composer autoloader
207
+        $appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
208
+        \OC::$server->registerNamespace($app, $appNamespace);
209
+
210
+        if (file_exists($path . '/composer/autoload.php')) {
211
+            require_once $path . '/composer/autoload.php';
212
+        } else {
213
+            \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
214
+            // Register on legacy autoloader
215
+            \OC::$loader->addValidRoot($path);
216
+        }
217
+
218
+        // Register Test namespace only when testing
219
+        if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
220
+            \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
221
+        }
222
+    }
223
+
224
+    /**
225
+     * Load app.php from the given app
226
+     *
227
+     * @param string $app app name
228
+     */
229
+    private static function requireAppFile($app) {
230
+        try {
231
+            // encapsulated here to avoid variable scope conflicts
232
+            require_once $app . '/appinfo/app.php';
233
+        } catch (Error $ex) {
234
+            \OC::$server->getLogger()->logException($ex);
235
+            $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
236
+            if (!in_array($app, $blacklist)) {
237
+                self::disable($app);
238
+            }
239
+        }
240
+    }
241
+
242
+    /**
243
+     * check if an app is of a specific type
244
+     *
245
+     * @param string $app
246
+     * @param string|array $types
247
+     * @return bool
248
+     */
249
+    public static function isType($app, $types) {
250
+        if (is_string($types)) {
251
+            $types = array($types);
252
+        }
253
+        $appTypes = self::getAppTypes($app);
254
+        foreach ($types as $type) {
255
+            if (array_search($type, $appTypes) !== false) {
256
+                return true;
257
+            }
258
+        }
259
+        return false;
260
+    }
261
+
262
+    /**
263
+     * get the types of an app
264
+     *
265
+     * @param string $app
266
+     * @return array
267
+     */
268
+    private static function getAppTypes($app) {
269
+        //load the cache
270
+        if (count(self::$appTypes) == 0) {
271
+            self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types');
272
+        }
273
+
274
+        if (isset(self::$appTypes[$app])) {
275
+            return explode(',', self::$appTypes[$app]);
276
+        } else {
277
+            return array();
278
+        }
279
+    }
280
+
281
+    /**
282
+     * read app types from info.xml and cache them in the database
283
+     */
284
+    public static function setAppTypes($app) {
285
+        $appData = self::getAppInfo($app);
286
+        if(!is_array($appData)) {
287
+            return;
288
+        }
289
+
290
+        if (isset($appData['types'])) {
291
+            $appTypes = implode(',', $appData['types']);
292
+        } else {
293
+            $appTypes = '';
294
+            $appData['types'] = [];
295
+        }
296
+
297
+        \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes);
298
+
299
+        if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) {
300
+            $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes');
301
+            if ($enabled !== 'yes' && $enabled !== 'no') {
302
+                \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes');
303
+            }
304
+        }
305
+    }
306
+
307
+    /**
308
+     * get all enabled apps
309
+     */
310
+    protected static $enabledAppsCache = array();
311
+
312
+    /**
313
+     * Returns apps enabled for the current user.
314
+     *
315
+     * @param bool $forceRefresh whether to refresh the cache
316
+     * @param bool $all whether to return apps for all users, not only the
317
+     * currently logged in one
318
+     * @return string[]
319
+     */
320
+    public static function getEnabledApps($forceRefresh = false, $all = false) {
321
+        if (!\OC::$server->getSystemConfig()->getValue('installed', false)) {
322
+            return array();
323
+        }
324
+        // in incognito mode or when logged out, $user will be false,
325
+        // which is also the case during an upgrade
326
+        $appManager = \OC::$server->getAppManager();
327
+        if ($all) {
328
+            $user = null;
329
+        } else {
330
+            $user = \OC::$server->getUserSession()->getUser();
331
+        }
332
+
333
+        if (is_null($user)) {
334
+            $apps = $appManager->getInstalledApps();
335
+        } else {
336
+            $apps = $appManager->getEnabledAppsForUser($user);
337
+        }
338
+        $apps = array_filter($apps, function ($app) {
339
+            return $app !== 'files';//we add this manually
340
+        });
341
+        sort($apps);
342
+        array_unshift($apps, 'files');
343
+        return $apps;
344
+    }
345
+
346
+    /**
347
+     * checks whether or not an app is enabled
348
+     *
349
+     * @param string $app app
350
+     * @return bool
351
+     *
352
+     * This function checks whether or not an app is enabled.
353
+     */
354
+    public static function isEnabled($app) {
355
+        return \OC::$server->getAppManager()->isEnabledForUser($app);
356
+    }
357
+
358
+    /**
359
+     * enables an app
360
+     *
361
+     * @param string $appId
362
+     * @param array $groups (optional) when set, only these groups will have access to the app
363
+     * @throws \Exception
364
+     * @return void
365
+     *
366
+     * This function set an app as enabled in appconfig.
367
+     */
368
+    public function enable($appId,
369
+                            $groups = null) {
370
+        self::$enabledAppsCache = []; // flush
371
+
372
+        // Check if app is already downloaded
373
+        $installer = new Installer(
374
+            \OC::$server->getAppFetcher(),
375
+            \OC::$server->getHTTPClientService(),
376
+            \OC::$server->getTempManager(),
377
+            \OC::$server->getLogger(),
378
+            \OC::$server->getConfig()
379
+        );
380
+        $isDownloaded = $installer->isDownloaded($appId);
381
+
382
+        if(!$isDownloaded) {
383
+            $installer->downloadApp($appId);
384
+        }
385
+
386
+        $installer->installApp($appId);
387
+
388
+        $appManager = \OC::$server->getAppManager();
389
+        if (!is_null($groups)) {
390
+            $groupManager = \OC::$server->getGroupManager();
391
+            $groupsList = [];
392
+            foreach ($groups as $group) {
393
+                $groupItem = $groupManager->get($group);
394
+                if ($groupItem instanceof \OCP\IGroup) {
395
+                    $groupsList[] = $groupManager->get($group);
396
+                }
397
+            }
398
+            $appManager->enableAppForGroups($appId, $groupsList);
399
+        } else {
400
+            $appManager->enableApp($appId);
401
+        }
402
+    }
403
+
404
+    /**
405
+     * @param string $app
406
+     * @return bool
407
+     */
408
+    public static function removeApp($app) {
409
+        if (\OC::$server->getAppManager()->isShipped($app)) {
410
+            return false;
411
+        }
412
+
413
+        $installer = new Installer(
414
+            \OC::$server->getAppFetcher(),
415
+            \OC::$server->getHTTPClientService(),
416
+            \OC::$server->getTempManager(),
417
+            \OC::$server->getLogger(),
418
+            \OC::$server->getConfig()
419
+        );
420
+        return $installer->removeApp($app);
421
+    }
422
+
423
+    /**
424
+     * This function set an app as disabled in appconfig.
425
+     *
426
+     * @param string $app app
427
+     * @throws Exception
428
+     */
429
+    public static function disable($app) {
430
+        // flush
431
+        self::$enabledAppsCache = array();
432
+
433
+        // run uninstall steps
434
+        $appData = OC_App::getAppInfo($app);
435
+        if (!is_null($appData)) {
436
+            OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']);
437
+        }
438
+
439
+        // emit disable hook - needed anymore ?
440
+        \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app));
441
+
442
+        // finally disable it
443
+        $appManager = \OC::$server->getAppManager();
444
+        $appManager->disableApp($app);
445
+    }
446
+
447
+    // This is private as well. It simply works, so don't ask for more details
448
+    private static function proceedNavigation($list) {
449
+        usort($list, function($a, $b) {
450
+            if (isset($a['order']) && isset($b['order'])) {
451
+                return ($a['order'] < $b['order']) ? -1 : 1;
452
+            } else if (isset($a['order']) || isset($b['order'])) {
453
+                return isset($a['order']) ? -1 : 1;
454
+            } else {
455
+                return ($a['name'] < $b['name']) ? -1 : 1;
456
+            }
457
+        });
458
+
459
+        $activeApp = OC::$server->getNavigationManager()->getActiveEntry();
460
+        foreach ($list as $index => &$navEntry) {
461
+            if ($navEntry['id'] == $activeApp) {
462
+                $navEntry['active'] = true;
463
+            } else {
464
+                $navEntry['active'] = false;
465
+            }
466
+        }
467
+        unset($navEntry);
468
+
469
+        return $list;
470
+    }
471
+
472
+    /**
473
+     * Get the path where to install apps
474
+     *
475
+     * @return string|false
476
+     */
477
+    public static function getInstallPath() {
478
+        if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) {
479
+            return false;
480
+        }
481
+
482
+        foreach (OC::$APPSROOTS as $dir) {
483
+            if (isset($dir['writable']) && $dir['writable'] === true) {
484
+                return $dir['path'];
485
+            }
486
+        }
487
+
488
+        \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR);
489
+        return null;
490
+    }
491
+
492
+
493
+    /**
494
+     * search for an app in all app-directories
495
+     *
496
+     * @param string $appId
497
+     * @return false|string
498
+     */
499
+    public static function findAppInDirectories($appId) {
500
+        $sanitizedAppId = self::cleanAppId($appId);
501
+        if($sanitizedAppId !== $appId) {
502
+            return false;
503
+        }
504
+        static $app_dir = array();
505
+
506
+        if (isset($app_dir[$appId])) {
507
+            return $app_dir[$appId];
508
+        }
509
+
510
+        $possibleApps = array();
511
+        foreach (OC::$APPSROOTS as $dir) {
512
+            if (file_exists($dir['path'] . '/' . $appId)) {
513
+                $possibleApps[] = $dir;
514
+            }
515
+        }
516
+
517
+        if (empty($possibleApps)) {
518
+            return false;
519
+        } elseif (count($possibleApps) === 1) {
520
+            $dir = array_shift($possibleApps);
521
+            $app_dir[$appId] = $dir;
522
+            return $dir;
523
+        } else {
524
+            $versionToLoad = array();
525
+            foreach ($possibleApps as $possibleApp) {
526
+                $version = self::getAppVersionByPath($possibleApp['path']);
527
+                if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) {
528
+                    $versionToLoad = array(
529
+                        'dir' => $possibleApp,
530
+                        'version' => $version,
531
+                    );
532
+                }
533
+            }
534
+            $app_dir[$appId] = $versionToLoad['dir'];
535
+            return $versionToLoad['dir'];
536
+            //TODO - write test
537
+        }
538
+    }
539
+
540
+    /**
541
+     * Get the directory for the given app.
542
+     * If the app is defined in multiple directories, the first one is taken. (false if not found)
543
+     *
544
+     * @param string $appId
545
+     * @return string|false
546
+     */
547
+    public static function getAppPath($appId) {
548
+        if ($appId === null || trim($appId) === '') {
549
+            return false;
550
+        }
551
+
552
+        if (($dir = self::findAppInDirectories($appId)) != false) {
553
+            return $dir['path'] . '/' . $appId;
554
+        }
555
+        return false;
556
+    }
557
+
558
+    /**
559
+     * Get the path for the given app on the access
560
+     * If the app is defined in multiple directories, the first one is taken. (false if not found)
561
+     *
562
+     * @param string $appId
563
+     * @return string|false
564
+     */
565
+    public static function getAppWebPath($appId) {
566
+        if (($dir = self::findAppInDirectories($appId)) != false) {
567
+            return OC::$WEBROOT . $dir['url'] . '/' . $appId;
568
+        }
569
+        return false;
570
+    }
571
+
572
+    /**
573
+     * get the last version of the app from appinfo/info.xml
574
+     *
575
+     * @param string $appId
576
+     * @param bool $useCache
577
+     * @return string
578
+     */
579
+    public static function getAppVersion($appId, $useCache = true) {
580
+        if($useCache && isset(self::$appVersion[$appId])) {
581
+            return self::$appVersion[$appId];
582
+        }
583
+
584
+        $file = self::getAppPath($appId);
585
+        self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0';
586
+        return self::$appVersion[$appId];
587
+    }
588
+
589
+    /**
590
+     * get app's version based on it's path
591
+     *
592
+     * @param string $path
593
+     * @return string
594
+     */
595
+    public static function getAppVersionByPath($path) {
596
+        $infoFile = $path . '/appinfo/info.xml';
597
+        $appData = self::getAppInfo($infoFile, true);
598
+        return isset($appData['version']) ? $appData['version'] : '';
599
+    }
600
+
601
+
602
+    /**
603
+     * Read all app metadata from the info.xml file
604
+     *
605
+     * @param string $appId id of the app or the path of the info.xml file
606
+     * @param bool $path
607
+     * @param string $lang
608
+     * @return array|null
609
+     * @note all data is read from info.xml, not just pre-defined fields
610
+     */
611
+    public static function getAppInfo($appId, $path = false, $lang = null) {
612
+        if ($path) {
613
+            $file = $appId;
614
+        } else {
615
+            if ($lang === null && isset(self::$appInfo[$appId])) {
616
+                return self::$appInfo[$appId];
617
+            }
618
+            $appPath = self::getAppPath($appId);
619
+            if($appPath === false) {
620
+                return null;
621
+            }
622
+            $file = $appPath . '/appinfo/info.xml';
623
+        }
624
+
625
+        $parser = new InfoParser(\OC::$server->getMemCacheFactory()->createLocal('core.appinfo'));
626
+        $data = $parser->parse($file);
627
+
628
+        if (is_array($data)) {
629
+            $data = OC_App::parseAppInfo($data, $lang);
630
+        }
631
+        if(isset($data['ocsid'])) {
632
+            $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid');
633
+            if($storedId !== '' && $storedId !== $data['ocsid']) {
634
+                $data['ocsid'] = $storedId;
635
+            }
636
+        }
637
+
638
+        if ($lang === null) {
639
+            self::$appInfo[$appId] = $data;
640
+        }
641
+
642
+        return $data;
643
+    }
644
+
645
+    /**
646
+     * Returns the navigation
647
+     *
648
+     * @return array
649
+     *
650
+     * This function returns an array containing all entries added. The
651
+     * entries are sorted by the key 'order' ascending. Additional to the keys
652
+     * given for each app the following keys exist:
653
+     *   - active: boolean, signals if the user is on this navigation entry
654
+     */
655
+    public static function getNavigation() {
656
+        $entries = OC::$server->getNavigationManager()->getAll();
657
+        return self::proceedNavigation($entries);
658
+    }
659
+
660
+    /**
661
+     * Returns the Settings Navigation
662
+     *
663
+     * @return string[]
664
+     *
665
+     * This function returns an array containing all settings pages added. The
666
+     * entries are sorted by the key 'order' ascending.
667
+     */
668
+    public static function getSettingsNavigation() {
669
+        $entries = OC::$server->getNavigationManager()->getAll('settings');
670
+        return self::proceedNavigation($entries);
671
+    }
672
+
673
+    /**
674
+     * get the id of loaded app
675
+     *
676
+     * @return string
677
+     */
678
+    public static function getCurrentApp() {
679
+        $request = \OC::$server->getRequest();
680
+        $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1);
681
+        $topFolder = substr($script, 0, strpos($script, '/'));
682
+        if (empty($topFolder)) {
683
+            $path_info = $request->getPathInfo();
684
+            if ($path_info) {
685
+                $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
686
+            }
687
+        }
688
+        if ($topFolder == 'apps') {
689
+            $length = strlen($topFolder);
690
+            return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1);
691
+        } else {
692
+            return $topFolder;
693
+        }
694
+    }
695
+
696
+    /**
697
+     * @param string $type
698
+     * @return array
699
+     */
700
+    public static function getForms($type) {
701
+        $forms = array();
702
+        switch ($type) {
703
+            case 'admin':
704
+                $source = self::$adminForms;
705
+                break;
706
+            case 'personal':
707
+                $source = self::$personalForms;
708
+                break;
709
+            default:
710
+                return array();
711
+        }
712
+        foreach ($source as $form) {
713
+            $forms[] = include $form;
714
+        }
715
+        return $forms;
716
+    }
717
+
718
+    /**
719
+     * register an admin form to be shown
720
+     *
721
+     * @param string $app
722
+     * @param string $page
723
+     */
724
+    public static function registerAdmin($app, $page) {
725
+        self::$adminForms[] = $app . '/' . $page . '.php';
726
+    }
727
+
728
+    /**
729
+     * register a personal form to be shown
730
+     * @param string $app
731
+     * @param string $page
732
+     */
733
+    public static function registerPersonal($app, $page) {
734
+        self::$personalForms[] = $app . '/' . $page . '.php';
735
+    }
736
+
737
+    /**
738
+     * @param array $entry
739
+     */
740
+    public static function registerLogIn(array $entry) {
741
+        self::$altLogin[] = $entry;
742
+    }
743
+
744
+    /**
745
+     * @return array
746
+     */
747
+    public static function getAlternativeLogIns() {
748
+        return self::$altLogin;
749
+    }
750
+
751
+    /**
752
+     * get a list of all apps in the apps folder
753
+     *
754
+     * @return array an array of app names (string IDs)
755
+     * @todo: change the name of this method to getInstalledApps, which is more accurate
756
+     */
757
+    public static function getAllApps() {
758
+
759
+        $apps = array();
760
+
761
+        foreach (OC::$APPSROOTS as $apps_dir) {
762
+            if (!is_readable($apps_dir['path'])) {
763
+                \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN);
764
+                continue;
765
+            }
766
+            $dh = opendir($apps_dir['path']);
767
+
768
+            if (is_resource($dh)) {
769
+                while (($file = readdir($dh)) !== false) {
770
+
771
+                    if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
772
+
773
+                        $apps[] = $file;
774
+                    }
775
+                }
776
+            }
777
+        }
778
+
779
+        $apps = array_unique($apps);
780
+
781
+        return $apps;
782
+    }
783
+
784
+    /**
785
+     * List all apps, this is used in apps.php
786
+     *
787
+     * @return array
788
+     */
789
+    public function listAllApps() {
790
+        $installedApps = OC_App::getAllApps();
791
+
792
+        $appManager = \OC::$server->getAppManager();
793
+        //we don't want to show configuration for these
794
+        $blacklist = $appManager->getAlwaysEnabledApps();
795
+        $appList = array();
796
+        $langCode = \OC::$server->getL10N('core')->getLanguageCode();
797
+        $urlGenerator = \OC::$server->getURLGenerator();
798
+
799
+        foreach ($installedApps as $app) {
800
+            if (array_search($app, $blacklist) === false) {
801
+
802
+                $info = OC_App::getAppInfo($app, false, $langCode);
803
+                if (!is_array($info)) {
804
+                    \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR);
805
+                    continue;
806
+                }
807
+
808
+                if (!isset($info['name'])) {
809
+                    \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR);
810
+                    continue;
811
+                }
812
+
813
+                $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no');
814
+                $info['groups'] = null;
815
+                if ($enabled === 'yes') {
816
+                    $active = true;
817
+                } else if ($enabled === 'no') {
818
+                    $active = false;
819
+                } else {
820
+                    $active = true;
821
+                    $info['groups'] = $enabled;
822
+                }
823
+
824
+                $info['active'] = $active;
825
+
826
+                if ($appManager->isShipped($app)) {
827
+                    $info['internal'] = true;
828
+                    $info['level'] = self::officialApp;
829
+                    $info['removable'] = false;
830
+                } else {
831
+                    $info['internal'] = false;
832
+                    $info['removable'] = true;
833
+                }
834
+
835
+                $appPath = self::getAppPath($app);
836
+                if($appPath !== false) {
837
+                    $appIcon = $appPath . '/img/' . $app . '.svg';
838
+                    if (file_exists($appIcon)) {
839
+                        $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg');
840
+                        $info['previewAsIcon'] = true;
841
+                    } else {
842
+                        $appIcon = $appPath . '/img/app.svg';
843
+                        if (file_exists($appIcon)) {
844
+                            $info['preview'] = $urlGenerator->imagePath($app, 'app.svg');
845
+                            $info['previewAsIcon'] = true;
846
+                        }
847
+                    }
848
+                }
849
+                // fix documentation
850
+                if (isset($info['documentation']) && is_array($info['documentation'])) {
851
+                    foreach ($info['documentation'] as $key => $url) {
852
+                        // If it is not an absolute URL we assume it is a key
853
+                        // i.e. admin-ldap will get converted to go.php?to=admin-ldap
854
+                        if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) {
855
+                            $url = $urlGenerator->linkToDocs($url);
856
+                        }
857
+
858
+                        $info['documentation'][$key] = $url;
859
+                    }
860
+                }
861
+
862
+                $info['version'] = OC_App::getAppVersion($app);
863
+                $appList[] = $info;
864
+            }
865
+        }
866
+
867
+        return $appList;
868
+    }
869
+
870
+    /**
871
+     * Returns the internal app ID or false
872
+     * @param string $ocsID
873
+     * @return string|false
874
+     */
875
+    public static function getInternalAppIdByOcs($ocsID) {
876
+        if(is_numeric($ocsID)) {
877
+            $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid');
878
+            if(array_search($ocsID, $idArray)) {
879
+                return array_search($ocsID, $idArray);
880
+            }
881
+        }
882
+        return false;
883
+    }
884
+
885
+    public static function shouldUpgrade($app) {
886
+        $versions = self::getAppVersions();
887
+        $currentVersion = OC_App::getAppVersion($app);
888
+        if ($currentVersion && isset($versions[$app])) {
889
+            $installedVersion = $versions[$app];
890
+            if (!version_compare($currentVersion, $installedVersion, '=')) {
891
+                return true;
892
+            }
893
+        }
894
+        return false;
895
+    }
896
+
897
+    /**
898
+     * Adjust the number of version parts of $version1 to match
899
+     * the number of version parts of $version2.
900
+     *
901
+     * @param string $version1 version to adjust
902
+     * @param string $version2 version to take the number of parts from
903
+     * @return string shortened $version1
904
+     */
905
+    private static function adjustVersionParts($version1, $version2) {
906
+        $version1 = explode('.', $version1);
907
+        $version2 = explode('.', $version2);
908
+        // reduce $version1 to match the number of parts in $version2
909
+        while (count($version1) > count($version2)) {
910
+            array_pop($version1);
911
+        }
912
+        // if $version1 does not have enough parts, add some
913
+        while (count($version1) < count($version2)) {
914
+            $version1[] = '0';
915
+        }
916
+        return implode('.', $version1);
917
+    }
918
+
919
+    /**
920
+     * Check whether the current ownCloud version matches the given
921
+     * application's version requirements.
922
+     *
923
+     * The comparison is made based on the number of parts that the
924
+     * app info version has. For example for ownCloud 6.0.3 if the
925
+     * app info version is expecting version 6.0, the comparison is
926
+     * made on the first two parts of the ownCloud version.
927
+     * This means that it's possible to specify "requiremin" => 6
928
+     * and "requiremax" => 6 and it will still match ownCloud 6.0.3.
929
+     *
930
+     * @param string $ocVersion ownCloud version to check against
931
+     * @param array $appInfo app info (from xml)
932
+     *
933
+     * @return boolean true if compatible, otherwise false
934
+     */
935
+    public static function isAppCompatible($ocVersion, $appInfo) {
936
+        $requireMin = '';
937
+        $requireMax = '';
938
+        if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) {
939
+            $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version'];
940
+        } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) {
941
+            $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version'];
942
+        } else if (isset($appInfo['requiremin'])) {
943
+            $requireMin = $appInfo['requiremin'];
944
+        } else if (isset($appInfo['require'])) {
945
+            $requireMin = $appInfo['require'];
946
+        }
947
+
948
+        if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) {
949
+            $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version'];
950
+        } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) {
951
+            $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version'];
952
+        } else if (isset($appInfo['requiremax'])) {
953
+            $requireMax = $appInfo['requiremax'];
954
+        }
955
+
956
+        if (is_array($ocVersion)) {
957
+            $ocVersion = implode('.', $ocVersion);
958
+        }
959
+
960
+        if (!empty($requireMin)
961
+            && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<')
962
+        ) {
963
+
964
+            return false;
965
+        }
966
+
967
+        if (!empty($requireMax)
968
+            && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>')
969
+        ) {
970
+            return false;
971
+        }
972
+
973
+        return true;
974
+    }
975
+
976
+    /**
977
+     * get the installed version of all apps
978
+     */
979
+    public static function getAppVersions() {
980
+        static $versions;
981
+
982
+        if(!$versions) {
983
+            $appConfig = \OC::$server->getAppConfig();
984
+            $versions = $appConfig->getValues(false, 'installed_version');
985
+        }
986
+        return $versions;
987
+    }
988
+
989
+    /**
990
+     * @param string $app
991
+     * @param \OCP\IConfig $config
992
+     * @param \OCP\IL10N $l
993
+     * @return bool
994
+     *
995
+     * @throws Exception if app is not compatible with this version of ownCloud
996
+     * @throws Exception if no app-name was specified
997
+     */
998
+    public function installApp($app,
999
+                                \OCP\IConfig $config,
1000
+                                \OCP\IL10N $l) {
1001
+        if ($app !== false) {
1002
+            // check if the app is compatible with this version of ownCloud
1003
+            $info = self::getAppInfo($app);
1004
+            if(!is_array($info)) {
1005
+                throw new \Exception(
1006
+                    $l->t('App "%s" cannot be installed because appinfo file cannot be read.',
1007
+                        [$info['name']]
1008
+                    )
1009
+                );
1010
+            }
1011
+
1012
+            $version = \OCP\Util::getVersion();
1013
+            if (!self::isAppCompatible($version, $info)) {
1014
+                throw new \Exception(
1015
+                    $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.',
1016
+                        array($info['name'])
1017
+                    )
1018
+                );
1019
+            }
1020
+
1021
+            // check for required dependencies
1022
+            self::checkAppDependencies($config, $l, $info);
1023
+
1024
+            $config->setAppValue($app, 'enabled', 'yes');
1025
+            if (isset($appData['id'])) {
1026
+                $config->setAppValue($app, 'ocsid', $appData['id']);
1027
+            }
1028
+
1029
+            if(isset($info['settings']) && is_array($info['settings'])) {
1030
+                $appPath = self::getAppPath($app);
1031
+                self::registerAutoloading($app, $appPath);
1032
+                \OC::$server->getSettingsManager()->setupSettings($info['settings']);
1033
+            }
1034
+
1035
+            \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app));
1036
+        } else {
1037
+            if(empty($appName) ) {
1038
+                throw new \Exception($l->t("No app name specified"));
1039
+            } else {
1040
+                throw new \Exception($l->t("App '%s' could not be installed!", $appName));
1041
+            }
1042
+        }
1043
+
1044
+        return $app;
1045
+    }
1046
+
1047
+    /**
1048
+     * update the database for the app and call the update script
1049
+     *
1050
+     * @param string $appId
1051
+     * @return bool
1052
+     */
1053
+    public static function updateApp($appId) {
1054
+        $appPath = self::getAppPath($appId);
1055
+        if($appPath === false) {
1056
+            return false;
1057
+        }
1058
+        self::registerAutoloading($appId, $appPath);
1059
+
1060
+        $appData = self::getAppInfo($appId);
1061
+        self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
1062
+
1063
+        if (file_exists($appPath . '/appinfo/database.xml')) {
1064
+            OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
1065
+        } else {
1066
+            $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection());
1067
+            $ms->migrate();
1068
+        }
1069
+
1070
+        self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
1071
+        self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
1072
+        unset(self::$appVersion[$appId]);
1073
+
1074
+        // run upgrade code
1075
+        if (file_exists($appPath . '/appinfo/update.php')) {
1076
+            self::loadApp($appId);
1077
+            include $appPath . '/appinfo/update.php';
1078
+        }
1079
+        self::setupBackgroundJobs($appData['background-jobs']);
1080
+        if(isset($appData['settings']) && is_array($appData['settings'])) {
1081
+            \OC::$server->getSettingsManager()->setupSettings($appData['settings']);
1082
+        }
1083
+
1084
+        //set remote/public handlers
1085
+        if (array_key_exists('ocsid', $appData)) {
1086
+            \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
1087
+        } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
1088
+            \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
1089
+        }
1090
+        foreach ($appData['remote'] as $name => $path) {
1091
+            \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
1092
+        }
1093
+        foreach ($appData['public'] as $name => $path) {
1094
+            \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
1095
+        }
1096
+
1097
+        self::setAppTypes($appId);
1098
+
1099
+        $version = \OC_App::getAppVersion($appId);
1100
+        \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version);
1101
+
1102
+        \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent(
1103
+            ManagerEvent::EVENT_APP_UPDATE, $appId
1104
+        ));
1105
+
1106
+        return true;
1107
+    }
1108
+
1109
+    /**
1110
+     * @param string $appId
1111
+     * @param string[] $steps
1112
+     * @throws \OC\NeedsUpdateException
1113
+     */
1114
+    public static function executeRepairSteps($appId, array $steps) {
1115
+        if (empty($steps)) {
1116
+            return;
1117
+        }
1118
+        // load the app
1119
+        self::loadApp($appId);
1120
+
1121
+        $dispatcher = OC::$server->getEventDispatcher();
1122
+
1123
+        // load the steps
1124
+        $r = new Repair([], $dispatcher);
1125
+        foreach ($steps as $step) {
1126
+            try {
1127
+                $r->addStep($step);
1128
+            } catch (Exception $ex) {
1129
+                $r->emit('\OC\Repair', 'error', [$ex->getMessage()]);
1130
+                \OC::$server->getLogger()->logException($ex);
1131
+            }
1132
+        }
1133
+        // run the steps
1134
+        $r->run();
1135
+    }
1136
+
1137
+    public static function setupBackgroundJobs(array $jobs) {
1138
+        $queue = \OC::$server->getJobList();
1139
+        foreach ($jobs as $job) {
1140
+            $queue->add($job);
1141
+        }
1142
+    }
1143
+
1144
+    /**
1145
+     * @param string $appId
1146
+     * @param string[] $steps
1147
+     */
1148
+    private static function setupLiveMigrations($appId, array $steps) {
1149
+        $queue = \OC::$server->getJobList();
1150
+        foreach ($steps as $step) {
1151
+            $queue->add('OC\Migration\BackgroundRepair', [
1152
+                'app' => $appId,
1153
+                'step' => $step]);
1154
+        }
1155
+    }
1156
+
1157
+    /**
1158
+     * @param string $appId
1159
+     * @return \OC\Files\View|false
1160
+     */
1161
+    public static function getStorage($appId) {
1162
+        if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check
1163
+            if (\OC::$server->getUserSession()->isLoggedIn()) {
1164
+                $view = new \OC\Files\View('/' . OC_User::getUser());
1165
+                if (!$view->file_exists($appId)) {
1166
+                    $view->mkdir($appId);
1167
+                }
1168
+                return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1169
+            } else {
1170
+                \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR);
1171
+                return false;
1172
+            }
1173
+        } else {
1174
+            \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR);
1175
+            return false;
1176
+        }
1177
+    }
1178
+
1179
+    protected static function findBestL10NOption($options, $lang) {
1180
+        $fallback = $similarLangFallback = $englishFallback = false;
1181
+
1182
+        $lang = strtolower($lang);
1183
+        $similarLang = $lang;
1184
+        if (strpos($similarLang, '_')) {
1185
+            // For "de_DE" we want to find "de" and the other way around
1186
+            $similarLang = substr($lang, 0, strpos($lang, '_'));
1187
+        }
1188
+
1189
+        foreach ($options as $option) {
1190
+            if (is_array($option)) {
1191
+                if ($fallback === false) {
1192
+                    $fallback = $option['@value'];
1193
+                }
1194
+
1195
+                if (!isset($option['@attributes']['lang'])) {
1196
+                    continue;
1197
+                }
1198
+
1199
+                $attributeLang = strtolower($option['@attributes']['lang']);
1200
+                if ($attributeLang === $lang) {
1201
+                    return $option['@value'];
1202
+                }
1203
+
1204
+                if ($attributeLang === $similarLang) {
1205
+                    $similarLangFallback = $option['@value'];
1206
+                } else if (strpos($attributeLang, $similarLang . '_') === 0) {
1207
+                    if ($similarLangFallback === false) {
1208
+                        $similarLangFallback =  $option['@value'];
1209
+                    }
1210
+                }
1211
+            } else {
1212
+                $englishFallback = $option;
1213
+            }
1214
+        }
1215
+
1216
+        if ($similarLangFallback !== false) {
1217
+            return $similarLangFallback;
1218
+        } else if ($englishFallback !== false) {
1219
+            return $englishFallback;
1220
+        }
1221
+        return (string) $fallback;
1222
+    }
1223
+
1224
+    /**
1225
+     * parses the app data array and enhanced the 'description' value
1226
+     *
1227
+     * @param array $data the app data
1228
+     * @param string $lang
1229
+     * @return array improved app data
1230
+     */
1231
+    public static function parseAppInfo(array $data, $lang = null) {
1232
+
1233
+        if ($lang && isset($data['name']) && is_array($data['name'])) {
1234
+            $data['name'] = self::findBestL10NOption($data['name'], $lang);
1235
+        }
1236
+        if ($lang && isset($data['summary']) && is_array($data['summary'])) {
1237
+            $data['summary'] = self::findBestL10NOption($data['summary'], $lang);
1238
+        }
1239
+        if ($lang && isset($data['description']) && is_array($data['description'])) {
1240
+            $data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1241
+        } else if (isset($data['description']) && is_string($data['description'])) {
1242
+            $data['description'] = trim($data['description']);
1243
+        } else  {
1244
+            $data['description'] = '';
1245
+        }
1246
+
1247
+        return $data;
1248
+    }
1249
+
1250
+    /**
1251
+     * @param \OCP\IConfig $config
1252
+     * @param \OCP\IL10N $l
1253
+     * @param array $info
1254
+     * @throws \Exception
1255
+     */
1256
+    public static function checkAppDependencies($config, $l, $info) {
1257
+        $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
1258
+        $missing = $dependencyAnalyzer->analyze($info);
1259
+        if (!empty($missing)) {
1260
+            $missingMsg = implode(PHP_EOL, $missing);
1261
+            throw new \Exception(
1262
+                $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s',
1263
+                    [$info['name'], $missingMsg]
1264
+                )
1265
+            );
1266
+        }
1267
+    }
1268 1268
 }
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 		$apps = self::getEnabledApps();
112 112
 
113 113
 		// Add each apps' folder as allowed class path
114
-		foreach($apps as $app) {
114
+		foreach ($apps as $app) {
115 115
 			$path = self::getAppPath($app);
116
-			if($path !== false) {
116
+			if ($path !== false) {
117 117
 				self::registerAutoloading($app, $path);
118 118
 			}
119 119
 		}
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
 	public static function loadApp($app) {
139 139
 		self::$loadedApps[] = $app;
140 140
 		$appPath = self::getAppPath($app);
141
-		if($appPath === false) {
141
+		if ($appPath === false) {
142 142
 			return;
143 143
 		}
144 144
 
145 145
 		// in case someone calls loadApp() directly
146 146
 		self::registerAutoloading($app, $appPath);
147 147
 
148
-		if (is_file($appPath . '/appinfo/app.php')) {
149
-			\OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app);
148
+		if (is_file($appPath.'/appinfo/app.php')) {
149
+			\OC::$server->getEventLogger()->start('load_app_'.$app, 'Load app: '.$app);
150 150
 			self::requireAppFile($app);
151 151
 			if (self::isType($app, array('authentication'))) {
152 152
 				// since authentication apps affect the "is app enabled for group" check,
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 				// enabled for groups
156 156
 				self::$enabledAppsCache = array();
157 157
 			}
158
-			\OC::$server->getEventLogger()->end('load_app_' . $app);
158
+			\OC::$server->getEventLogger()->end('load_app_'.$app);
159 159
 		}
160 160
 
161 161
 		$info = self::getAppInfo($app);
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 			$plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ?
180 180
 				[$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin'];
181 181
 			foreach ($plugins as $plugin) {
182
-				if($plugin['@attributes']['type'] === 'collaborator-search') {
182
+				if ($plugin['@attributes']['type'] === 'collaborator-search') {
183 183
 					$pluginInfo = [
184 184
 						'shareType' => $plugin['@attributes']['share-type'],
185 185
 						'class' => $plugin['@value'],
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
 	 * @param string $path
197 197
 	 */
198 198
 	public static function registerAutoloading($app, $path) {
199
-		$key = $app . '-' . $path;
200
-		if(isset(self::$alreadyRegistered[$key])) {
199
+		$key = $app.'-'.$path;
200
+		if (isset(self::$alreadyRegistered[$key])) {
201 201
 			return;
202 202
 		}
203 203
 
@@ -207,17 +207,17 @@  discard block
 block discarded – undo
207 207
 		$appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
208 208
 		\OC::$server->registerNamespace($app, $appNamespace);
209 209
 
210
-		if (file_exists($path . '/composer/autoload.php')) {
211
-			require_once $path . '/composer/autoload.php';
210
+		if (file_exists($path.'/composer/autoload.php')) {
211
+			require_once $path.'/composer/autoload.php';
212 212
 		} else {
213
-			\OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
213
+			\OC::$composerAutoloader->addPsr4($appNamespace.'\\', $path.'/lib/', true);
214 214
 			// Register on legacy autoloader
215 215
 			\OC::$loader->addValidRoot($path);
216 216
 		}
217 217
 
218 218
 		// Register Test namespace only when testing
219 219
 		if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
220
-			\OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
220
+			\OC::$composerAutoloader->addPsr4($appNamespace.'\\Tests\\', $path.'/tests/', true);
221 221
 		}
222 222
 	}
223 223
 
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 	private static function requireAppFile($app) {
230 230
 		try {
231 231
 			// encapsulated here to avoid variable scope conflicts
232
-			require_once $app . '/appinfo/app.php';
232
+			require_once $app.'/appinfo/app.php';
233 233
 		} catch (Error $ex) {
234 234
 			\OC::$server->getLogger()->logException($ex);
235 235
 			$blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 	 */
284 284
 	public static function setAppTypes($app) {
285 285
 		$appData = self::getAppInfo($app);
286
-		if(!is_array($appData)) {
286
+		if (!is_array($appData)) {
287 287
 			return;
288 288
 		}
289 289
 
@@ -335,8 +335,8 @@  discard block
 block discarded – undo
335 335
 		} else {
336 336
 			$apps = $appManager->getEnabledAppsForUser($user);
337 337
 		}
338
-		$apps = array_filter($apps, function ($app) {
339
-			return $app !== 'files';//we add this manually
338
+		$apps = array_filter($apps, function($app) {
339
+			return $app !== 'files'; //we add this manually
340 340
 		});
341 341
 		sort($apps);
342 342
 		array_unshift($apps, 'files');
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
 		);
380 380
 		$isDownloaded = $installer->isDownloaded($appId);
381 381
 
382
-		if(!$isDownloaded) {
382
+		if (!$isDownloaded) {
383 383
 			$installer->downloadApp($appId);
384 384
 		}
385 385
 
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
 	 */
499 499
 	public static function findAppInDirectories($appId) {
500 500
 		$sanitizedAppId = self::cleanAppId($appId);
501
-		if($sanitizedAppId !== $appId) {
501
+		if ($sanitizedAppId !== $appId) {
502 502
 			return false;
503 503
 		}
504 504
 		static $app_dir = array();
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 
510 510
 		$possibleApps = array();
511 511
 		foreach (OC::$APPSROOTS as $dir) {
512
-			if (file_exists($dir['path'] . '/' . $appId)) {
512
+			if (file_exists($dir['path'].'/'.$appId)) {
513 513
 				$possibleApps[] = $dir;
514 514
 			}
515 515
 		}
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 		}
551 551
 
552 552
 		if (($dir = self::findAppInDirectories($appId)) != false) {
553
-			return $dir['path'] . '/' . $appId;
553
+			return $dir['path'].'/'.$appId;
554 554
 		}
555 555
 		return false;
556 556
 	}
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
 	 */
565 565
 	public static function getAppWebPath($appId) {
566 566
 		if (($dir = self::findAppInDirectories($appId)) != false) {
567
-			return OC::$WEBROOT . $dir['url'] . '/' . $appId;
567
+			return OC::$WEBROOT.$dir['url'].'/'.$appId;
568 568
 		}
569 569
 		return false;
570 570
 	}
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 	 * @return string
578 578
 	 */
579 579
 	public static function getAppVersion($appId, $useCache = true) {
580
-		if($useCache && isset(self::$appVersion[$appId])) {
580
+		if ($useCache && isset(self::$appVersion[$appId])) {
581 581
 			return self::$appVersion[$appId];
582 582
 		}
583 583
 
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
 	 * @return string
594 594
 	 */
595 595
 	public static function getAppVersionByPath($path) {
596
-		$infoFile = $path . '/appinfo/info.xml';
596
+		$infoFile = $path.'/appinfo/info.xml';
597 597
 		$appData = self::getAppInfo($infoFile, true);
598 598
 		return isset($appData['version']) ? $appData['version'] : '';
599 599
 	}
@@ -616,10 +616,10 @@  discard block
 block discarded – undo
616 616
 				return self::$appInfo[$appId];
617 617
 			}
618 618
 			$appPath = self::getAppPath($appId);
619
-			if($appPath === false) {
619
+			if ($appPath === false) {
620 620
 				return null;
621 621
 			}
622
-			$file = $appPath . '/appinfo/info.xml';
622
+			$file = $appPath.'/appinfo/info.xml';
623 623
 		}
624 624
 
625 625
 		$parser = new InfoParser(\OC::$server->getMemCacheFactory()->createLocal('core.appinfo'));
@@ -628,9 +628,9 @@  discard block
 block discarded – undo
628 628
 		if (is_array($data)) {
629 629
 			$data = OC_App::parseAppInfo($data, $lang);
630 630
 		}
631
-		if(isset($data['ocsid'])) {
631
+		if (isset($data['ocsid'])) {
632 632
 			$storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid');
633
-			if($storedId !== '' && $storedId !== $data['ocsid']) {
633
+			if ($storedId !== '' && $storedId !== $data['ocsid']) {
634 634
 				$data['ocsid'] = $storedId;
635 635
 			}
636 636
 		}
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
 	 * @param string $page
723 723
 	 */
724 724
 	public static function registerAdmin($app, $page) {
725
-		self::$adminForms[] = $app . '/' . $page . '.php';
725
+		self::$adminForms[] = $app.'/'.$page.'.php';
726 726
 	}
727 727
 
728 728
 	/**
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
 	 * @param string $page
732 732
 	 */
733 733
 	public static function registerPersonal($app, $page) {
734
-		self::$personalForms[] = $app . '/' . $page . '.php';
734
+		self::$personalForms[] = $app.'/'.$page.'.php';
735 735
 	}
736 736
 
737 737
 	/**
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
 
761 761
 		foreach (OC::$APPSROOTS as $apps_dir) {
762 762
 			if (!is_readable($apps_dir['path'])) {
763
-				\OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN);
763
+				\OCP\Util::writeLog('core', 'unable to read app folder : '.$apps_dir['path'], \OCP\Util::WARN);
764 764
 				continue;
765 765
 			}
766 766
 			$dh = opendir($apps_dir['path']);
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
 			if (is_resource($dh)) {
769 769
 				while (($file = readdir($dh)) !== false) {
770 770
 
771
-					if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
771
+					if ($file[0] != '.' and is_dir($apps_dir['path'].'/'.$file) and is_file($apps_dir['path'].'/'.$file.'/appinfo/info.xml')) {
772 772
 
773 773
 						$apps[] = $file;
774 774
 					}
@@ -801,12 +801,12 @@  discard block
 block discarded – undo
801 801
 
802 802
 				$info = OC_App::getAppInfo($app, false, $langCode);
803 803
 				if (!is_array($info)) {
804
-					\OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR);
804
+					\OCP\Util::writeLog('core', 'Could not read app info file for app "'.$app.'"', \OCP\Util::ERROR);
805 805
 					continue;
806 806
 				}
807 807
 
808 808
 				if (!isset($info['name'])) {
809
-					\OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR);
809
+					\OCP\Util::writeLog('core', 'App id "'.$app.'" has no name in appinfo', \OCP\Util::ERROR);
810 810
 					continue;
811 811
 				}
812 812
 
@@ -833,13 +833,13 @@  discard block
 block discarded – undo
833 833
 				}
834 834
 
835 835
 				$appPath = self::getAppPath($app);
836
-				if($appPath !== false) {
837
-					$appIcon = $appPath . '/img/' . $app . '.svg';
836
+				if ($appPath !== false) {
837
+					$appIcon = $appPath.'/img/'.$app.'.svg';
838 838
 					if (file_exists($appIcon)) {
839
-						$info['preview'] = $urlGenerator->imagePath($app, $app . '.svg');
839
+						$info['preview'] = $urlGenerator->imagePath($app, $app.'.svg');
840 840
 						$info['previewAsIcon'] = true;
841 841
 					} else {
842
-						$appIcon = $appPath . '/img/app.svg';
842
+						$appIcon = $appPath.'/img/app.svg';
843 843
 						if (file_exists($appIcon)) {
844 844
 							$info['preview'] = $urlGenerator->imagePath($app, 'app.svg');
845 845
 							$info['previewAsIcon'] = true;
@@ -873,9 +873,9 @@  discard block
 block discarded – undo
873 873
 	 * @return string|false
874 874
 	 */
875 875
 	public static function getInternalAppIdByOcs($ocsID) {
876
-		if(is_numeric($ocsID)) {
876
+		if (is_numeric($ocsID)) {
877 877
 			$idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid');
878
-			if(array_search($ocsID, $idArray)) {
878
+			if (array_search($ocsID, $idArray)) {
879 879
 				return array_search($ocsID, $idArray);
880 880
 			}
881 881
 		}
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
 	public static function getAppVersions() {
980 980
 		static $versions;
981 981
 
982
-		if(!$versions) {
982
+		if (!$versions) {
983 983
 			$appConfig = \OC::$server->getAppConfig();
984 984
 			$versions = $appConfig->getValues(false, 'installed_version');
985 985
 		}
@@ -1001,7 +1001,7 @@  discard block
 block discarded – undo
1001 1001
 		if ($app !== false) {
1002 1002
 			// check if the app is compatible with this version of ownCloud
1003 1003
 			$info = self::getAppInfo($app);
1004
-			if(!is_array($info)) {
1004
+			if (!is_array($info)) {
1005 1005
 				throw new \Exception(
1006 1006
 					$l->t('App "%s" cannot be installed because appinfo file cannot be read.',
1007 1007
 						[$info['name']]
@@ -1026,7 +1026,7 @@  discard block
 block discarded – undo
1026 1026
 				$config->setAppValue($app, 'ocsid', $appData['id']);
1027 1027
 			}
1028 1028
 
1029
-			if(isset($info['settings']) && is_array($info['settings'])) {
1029
+			if (isset($info['settings']) && is_array($info['settings'])) {
1030 1030
 				$appPath = self::getAppPath($app);
1031 1031
 				self::registerAutoloading($app, $appPath);
1032 1032
 				\OC::$server->getSettingsManager()->setupSettings($info['settings']);
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
 
1035 1035
 			\OC_Hook::emit('OC_App', 'post_enable', array('app' => $app));
1036 1036
 		} else {
1037
-			if(empty($appName) ) {
1037
+			if (empty($appName)) {
1038 1038
 				throw new \Exception($l->t("No app name specified"));
1039 1039
 			} else {
1040 1040
 				throw new \Exception($l->t("App '%s' could not be installed!", $appName));
@@ -1052,7 +1052,7 @@  discard block
 block discarded – undo
1052 1052
 	 */
1053 1053
 	public static function updateApp($appId) {
1054 1054
 		$appPath = self::getAppPath($appId);
1055
-		if($appPath === false) {
1055
+		if ($appPath === false) {
1056 1056
 			return false;
1057 1057
 		}
1058 1058
 		self::registerAutoloading($appId, $appPath);
@@ -1060,8 +1060,8 @@  discard block
 block discarded – undo
1060 1060
 		$appData = self::getAppInfo($appId);
1061 1061
 		self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
1062 1062
 
1063
-		if (file_exists($appPath . '/appinfo/database.xml')) {
1064
-			OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
1063
+		if (file_exists($appPath.'/appinfo/database.xml')) {
1064
+			OC_DB::updateDbFromStructure($appPath.'/appinfo/database.xml');
1065 1065
 		} else {
1066 1066
 			$ms = new MigrationService($appId, \OC::$server->getDatabaseConnection());
1067 1067
 			$ms->migrate();
@@ -1072,26 +1072,26 @@  discard block
 block discarded – undo
1072 1072
 		unset(self::$appVersion[$appId]);
1073 1073
 
1074 1074
 		// run upgrade code
1075
-		if (file_exists($appPath . '/appinfo/update.php')) {
1075
+		if (file_exists($appPath.'/appinfo/update.php')) {
1076 1076
 			self::loadApp($appId);
1077
-			include $appPath . '/appinfo/update.php';
1077
+			include $appPath.'/appinfo/update.php';
1078 1078
 		}
1079 1079
 		self::setupBackgroundJobs($appData['background-jobs']);
1080
-		if(isset($appData['settings']) && is_array($appData['settings'])) {
1080
+		if (isset($appData['settings']) && is_array($appData['settings'])) {
1081 1081
 			\OC::$server->getSettingsManager()->setupSettings($appData['settings']);
1082 1082
 		}
1083 1083
 
1084 1084
 		//set remote/public handlers
1085 1085
 		if (array_key_exists('ocsid', $appData)) {
1086 1086
 			\OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
1087
-		} elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
1087
+		} elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
1088 1088
 			\OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
1089 1089
 		}
1090 1090
 		foreach ($appData['remote'] as $name => $path) {
1091
-			\OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
1091
+			\OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $appId.'/'.$path);
1092 1092
 		}
1093 1093
 		foreach ($appData['public'] as $name => $path) {
1094
-			\OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
1094
+			\OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $appId.'/'.$path);
1095 1095
 		}
1096 1096
 
1097 1097
 		self::setAppTypes($appId);
@@ -1161,17 +1161,17 @@  discard block
 block discarded – undo
1161 1161
 	public static function getStorage($appId) {
1162 1162
 		if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check
1163 1163
 			if (\OC::$server->getUserSession()->isLoggedIn()) {
1164
-				$view = new \OC\Files\View('/' . OC_User::getUser());
1164
+				$view = new \OC\Files\View('/'.OC_User::getUser());
1165 1165
 				if (!$view->file_exists($appId)) {
1166 1166
 					$view->mkdir($appId);
1167 1167
 				}
1168
-				return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1168
+				return new \OC\Files\View('/'.OC_User::getUser().'/'.$appId);
1169 1169
 			} else {
1170
-				\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR);
1170
+				\OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.', user not logged in', \OCP\Util::ERROR);
1171 1171
 				return false;
1172 1172
 			}
1173 1173
 		} else {
1174
-			\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR);
1174
+			\OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.' not enabled', \OCP\Util::ERROR);
1175 1175
 			return false;
1176 1176
 		}
1177 1177
 	}
@@ -1203,9 +1203,9 @@  discard block
 block discarded – undo
1203 1203
 
1204 1204
 				if ($attributeLang === $similarLang) {
1205 1205
 					$similarLangFallback = $option['@value'];
1206
-				} else if (strpos($attributeLang, $similarLang . '_') === 0) {
1206
+				} else if (strpos($attributeLang, $similarLang.'_') === 0) {
1207 1207
 					if ($similarLangFallback === false) {
1208
-						$similarLangFallback =  $option['@value'];
1208
+						$similarLangFallback = $option['@value'];
1209 1209
 					}
1210 1210
 				}
1211 1211
 			} else {
@@ -1240,7 +1240,7 @@  discard block
 block discarded – undo
1240 1240
 			$data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1241 1241
 		} else if (isset($data['description']) && is_string($data['description'])) {
1242 1242
 			$data['description'] = trim($data['description']);
1243
-		} else  {
1243
+		} else {
1244 1244
 			$data['description'] = '';
1245 1245
 		}
1246 1246
 
Please login to merge, or discard this patch.
lib/private/legacy/template.php 2 patches
Indentation   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -45,343 +45,343 @@
 block discarded – undo
45 45
  */
46 46
 class OC_Template extends \OC\Template\Base {
47 47
 
48
-	/** @var string */
49
-	private $renderAs; // Create a full page?
50
-
51
-	/** @var string */
52
-	private $path; // The path to the template
53
-
54
-	/** @var array */
55
-	private $headers = array(); //custom headers
56
-
57
-	/** @var string */
58
-	protected $app; // app id
59
-
60
-	protected static $initTemplateEngineFirstRun = true;
61
-
62
-	/**
63
-	 * Constructor
64
-	 *
65
-	 * @param string $app app providing the template
66
-	 * @param string $name of the template file (without suffix)
67
-	 * @param string $renderAs If $renderAs is set, OC_Template will try to
68
-	 *                         produce a full page in the according layout. For
69
-	 *                         now, $renderAs can be set to "guest", "user" or
70
-	 *                         "admin".
71
-	 * @param bool $registerCall = true
72
-	 */
73
-	public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
74
-		// Read the selected theme from the config file
75
-		self::initTemplateEngine($renderAs);
76
-
77
-		$theme = OC_Util::getTheme();
78
-
79
-		$requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : '';
80
-
81
-		$parts = explode('/', $app); // fix translation when app is something like core/lostpassword
82
-		$l10n = \OC::$server->getL10N($parts[0]);
83
-		/** @var \OCP\Defaults $themeDefaults */
84
-		$themeDefaults = \OC::$server->query(\OCP\Defaults::class);
85
-
86
-		list($path, $template) = $this->findTemplate($theme, $app, $name);
87
-
88
-		// Set the private data
89
-		$this->renderAs = $renderAs;
90
-		$this->path = $path;
91
-		$this->app = $app;
92
-
93
-		parent::__construct($template, $requestToken, $l10n, $themeDefaults);
94
-	}
95
-
96
-	/**
97
-	 * @param string $renderAs
98
-	 */
99
-	public static function initTemplateEngine($renderAs) {
100
-		if (self::$initTemplateEngineFirstRun){
101
-
102
-			//apps that started before the template initialization can load their own scripts/styles
103
-			//so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
104
-			//meaning the last script/style in this list will be loaded first
105
-			if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
106
-				if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
107
-					OC_Util::addScript ( 'backgroundjobs', null, true );
108
-				}
109
-			}
110
-
111
-			OC_Util::addStyle('server', null, true);
112
-			OC_Util::addStyle('jquery-ui-fixes',null,true);
113
-			OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true);
114
-			OC_Util::addVendorStyle('select2/select2', null, true);
115
-			OC_Util::addStyle('jquery.ocdialog');
116
-			OC_Util::addTranslations("core", null, true);
117
-			OC_Util::addScript('search', 'search', true);
118
-			OC_Util::addScript('merged-template-prepend', null, true);
119
-			OC_Util::addScript('jquery-ui-fixes');
120
-			OC_Util::addScript('files/fileinfo');
121
-			OC_Util::addScript('files/client');
122
-			OC_Util::addScript('contactsmenu');
123
-
124
-			if (\OC::$server->getConfig()->getSystemValue('debug')) {
125
-				// Add the stuff we need always
126
-				// following logic will import all vendor libraries that are
127
-				// specified in core/js/core.json
128
-				$fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json');
129
-				if($fileContent !== false) {
130
-					$coreDependencies = json_decode($fileContent, true);
131
-					foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) {
132
-						//remove trailing ".js" as addVendorScript will append it
133
-						OC_Util::addVendorScript(
134
-							substr($vendorLibrary, 0, strlen($vendorLibrary) - 3),null,true);
135
-						}
136
- 				} else {
137
-					throw new \Exception('Cannot read core/js/core.json');
138
-				}
139
-			} else {
140
-				// Import all (combined) default vendor libraries
141
-				OC_Util::addVendorScript('core', null, true);
142
-			}
143
-
144
-			if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) {
145
-				// polyfill for btoa/atob for IE friends
146
-				OC_Util::addVendorScript('base64/base64');
147
-				// shim for the davclient.js library
148
-				\OCP\Util::addScript('files/iedavclient');
149
-			}
150
-
151
-			self::$initTemplateEngineFirstRun = false;
152
-		}
153
-
154
-	}
155
-
156
-
157
-	/**
158
-	 * find the template with the given name
159
-	 * @param string $name of the template file (without suffix)
160
-	 *
161
-	 * Will select the template file for the selected theme.
162
-	 * Checking all the possible locations.
163
-	 * @param string $theme
164
-	 * @param string $app
165
-	 * @return string[]
166
-	 */
167
-	protected function findTemplate($theme, $app, $name) {
168
-		// Check if it is a app template or not.
169
-		if( $app !== '' ) {
170
-			$dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
171
-		} else {
172
-			$dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
173
-		}
174
-		$locator = new \OC\Template\TemplateFileLocator( $dirs );
175
-		$template = $locator->find($name);
176
-		$path = $locator->getPath();
177
-		return array($path, $template);
178
-	}
179
-
180
-	/**
181
-	 * Add a custom element to the header
182
-	 * @param string $tag tag name of the element
183
-	 * @param array $attributes array of attributes for the element
184
-	 * @param string $text the text content for the element. If $text is null then the
185
-	 * element will be written as empty element. So use "" to get a closing tag.
186
-	 */
187
-	public function addHeader($tag, $attributes, $text=null) {
188
-		$this->headers[]= array(
189
-			'tag' => $tag,
190
-			'attributes' => $attributes,
191
-			'text' => $text
192
-		);
193
-	}
194
-
195
-	/**
196
-	 * Process the template
197
-	 * @return boolean|string
198
-	 *
199
-	 * This function process the template. If $this->renderAs is set, it
200
-	 * will produce a full page.
201
-	 */
202
-	public function fetchPage($additionalParams = null) {
203
-		$data = parent::fetchPage($additionalParams);
204
-
205
-		if( $this->renderAs ) {
206
-			$page = new TemplateLayout($this->renderAs, $this->app);
207
-
208
-			// Add custom headers
209
-			$headers = '';
210
-			foreach(OC_Util::$headers as $header) {
211
-				$headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
212
-				if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
213
-					$headers .= ' defer';
214
-				}
215
-				foreach($header['attributes'] as $name=>$value) {
216
-					$headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
217
-				}
218
-				if ($header['text'] !== null) {
219
-					$headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>';
220
-				} else {
221
-					$headers .= '/>';
222
-				}
223
-			}
224
-
225
-			$page->assign('headers', $headers);
226
-
227
-			$page->assign('content', $data);
228
-			return $page->fetchPage();
229
-		}
230
-
231
-		return $data;
232
-	}
233
-
234
-	/**
235
-	 * Include template
236
-	 *
237
-	 * @param string $file
238
-	 * @param array|null $additionalParams
239
-	 * @return string returns content of included template
240
-	 *
241
-	 * Includes another template. use <?php echo $this->inc('template'); ?> to
242
-	 * do this.
243
-	 */
244
-	public function inc( $file, $additionalParams = null ) {
245
-		return $this->load($this->path.$file.'.php', $additionalParams);
246
-	}
247
-
248
-	/**
249
-	 * Shortcut to print a simple page for users
250
-	 * @param string $application The application we render the template for
251
-	 * @param string $name Name of the template
252
-	 * @param array $parameters Parameters for the template
253
-	 * @return boolean|null
254
-	 */
255
-	public static function printUserPage( $application, $name, $parameters = array() ) {
256
-		$content = new OC_Template( $application, $name, "user" );
257
-		foreach( $parameters as $key => $value ) {
258
-			$content->assign( $key, $value );
259
-		}
260
-		print $content->printPage();
261
-	}
262
-
263
-	/**
264
-	 * Shortcut to print a simple page for admins
265
-	 * @param string $application The application we render the template for
266
-	 * @param string $name Name of the template
267
-	 * @param array $parameters Parameters for the template
268
-	 * @return bool
269
-	 */
270
-	public static function printAdminPage( $application, $name, $parameters = array() ) {
271
-		$content = new OC_Template( $application, $name, "admin" );
272
-		foreach( $parameters as $key => $value ) {
273
-			$content->assign( $key, $value );
274
-		}
275
-		return $content->printPage();
276
-	}
277
-
278
-	/**
279
-	 * Shortcut to print a simple page for guests
280
-	 * @param string $application The application we render the template for
281
-	 * @param string $name Name of the template
282
-	 * @param array|string $parameters Parameters for the template
283
-	 * @return bool
284
-	 */
285
-	public static function printGuestPage( $application, $name, $parameters = array() ) {
286
-		$content = new OC_Template( $application, $name, "guest" );
287
-		foreach( $parameters as $key => $value ) {
288
-			$content->assign( $key, $value );
289
-		}
290
-		return $content->printPage();
291
-	}
292
-
293
-	/**
294
-	 * Print a fatal error page and terminates the script
295
-	 * @param string $error_msg The error message to show
296
-	 * @param string $hint An optional hint message - needs to be properly escape
297
-	 * @suppress PhanAccessMethodInternal
298
-	 */
299
-	public static function printErrorPage( $error_msg, $hint = '' ) {
300
-		if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
301
-			\OC_App::loadApp('theming');
302
-		}
303
-
304
-
305
-		if ($error_msg === $hint) {
306
-			// If the hint is the same as the message there is no need to display it twice.
307
-			$hint = '';
308
-		}
309
-
310
-		try {
311
-			$content = new \OC_Template( '', 'error', 'error', false );
312
-			$errors = array(array('error' => $error_msg, 'hint' => $hint));
313
-			$content->assign( 'errors', $errors );
314
-			$content->printPage();
315
-		} catch (\Exception $e) {
316
-			$logger = \OC::$server->getLogger();
317
-			$logger->error("$error_msg $hint", ['app' => 'core']);
318
-			$logger->logException($e, ['app' => 'core']);
319
-
320
-			header(self::getHttpProtocol() . ' 500 Internal Server Error');
321
-			header('Content-Type: text/plain; charset=utf-8');
322
-			print("$error_msg $hint");
323
-		}
324
-		die();
325
-	}
326
-
327
-	/**
328
-	 * print error page using Exception details
329
-	 * @param Exception|Throwable $exception
330
-	 * @param bool $fetchPage
331
-	 * @return bool|string
332
-	 * @suppress PhanAccessMethodInternal
333
-	 */
334
-	public static function printExceptionErrorPage($exception, $fetchPage = false) {
335
-		try {
336
-			$request = \OC::$server->getRequest();
337
-			$content = new \OC_Template('', 'exception', 'error', false);
338
-			$content->assign('errorClass', get_class($exception));
339
-			$content->assign('errorMsg', $exception->getMessage());
340
-			$content->assign('errorCode', $exception->getCode());
341
-			$content->assign('file', $exception->getFile());
342
-			$content->assign('line', $exception->getLine());
343
-			$content->assign('trace', $exception->getTraceAsString());
344
-			$content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
345
-			$content->assign('remoteAddr', $request->getRemoteAddress());
346
-			$content->assign('requestID', $request->getId());
347
-			if ($fetchPage) {
348
-				return $content->fetchPage();
349
-			}
350
-			$content->printPage();
351
-		} catch (\Exception $e) {
352
-			$logger = \OC::$server->getLogger();
353
-			$logger->logException($exception, ['app' => 'core']);
354
-			$logger->logException($e, ['app' => 'core']);
355
-
356
-			header(self::getHttpProtocol() . ' 500 Internal Server Error');
357
-			header('Content-Type: text/plain; charset=utf-8');
358
-			print("Internal Server Error\n\n");
359
-			print("The server encountered an internal error and was unable to complete your request.\n");
360
-			print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
361
-			print("More details can be found in the server log.\n");
362
-		}
363
-		die();
364
-	}
365
-
366
-	/**
367
-	 * This is only here to reduce the dependencies in case of an exception to
368
-	 * still be able to print a plain error message.
369
-	 *
370
-	 * Returns the used HTTP protocol.
371
-	 *
372
-	 * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
373
-	 * @internal Don't use this - use AppFramework\Http\Request->getHttpProtocol instead
374
-	 */
375
-	protected static function getHttpProtocol() {
376
-		$claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']);
377
-		$validProtocols = [
378
-			'HTTP/1.0',
379
-			'HTTP/1.1',
380
-			'HTTP/2',
381
-		];
382
-		if(in_array($claimedProtocol, $validProtocols, true)) {
383
-			return $claimedProtocol;
384
-		}
385
-		return 'HTTP/1.1';
386
-	}
48
+    /** @var string */
49
+    private $renderAs; // Create a full page?
50
+
51
+    /** @var string */
52
+    private $path; // The path to the template
53
+
54
+    /** @var array */
55
+    private $headers = array(); //custom headers
56
+
57
+    /** @var string */
58
+    protected $app; // app id
59
+
60
+    protected static $initTemplateEngineFirstRun = true;
61
+
62
+    /**
63
+     * Constructor
64
+     *
65
+     * @param string $app app providing the template
66
+     * @param string $name of the template file (without suffix)
67
+     * @param string $renderAs If $renderAs is set, OC_Template will try to
68
+     *                         produce a full page in the according layout. For
69
+     *                         now, $renderAs can be set to "guest", "user" or
70
+     *                         "admin".
71
+     * @param bool $registerCall = true
72
+     */
73
+    public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
74
+        // Read the selected theme from the config file
75
+        self::initTemplateEngine($renderAs);
76
+
77
+        $theme = OC_Util::getTheme();
78
+
79
+        $requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : '';
80
+
81
+        $parts = explode('/', $app); // fix translation when app is something like core/lostpassword
82
+        $l10n = \OC::$server->getL10N($parts[0]);
83
+        /** @var \OCP\Defaults $themeDefaults */
84
+        $themeDefaults = \OC::$server->query(\OCP\Defaults::class);
85
+
86
+        list($path, $template) = $this->findTemplate($theme, $app, $name);
87
+
88
+        // Set the private data
89
+        $this->renderAs = $renderAs;
90
+        $this->path = $path;
91
+        $this->app = $app;
92
+
93
+        parent::__construct($template, $requestToken, $l10n, $themeDefaults);
94
+    }
95
+
96
+    /**
97
+     * @param string $renderAs
98
+     */
99
+    public static function initTemplateEngine($renderAs) {
100
+        if (self::$initTemplateEngineFirstRun){
101
+
102
+            //apps that started before the template initialization can load their own scripts/styles
103
+            //so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
104
+            //meaning the last script/style in this list will be loaded first
105
+            if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
106
+                if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
107
+                    OC_Util::addScript ( 'backgroundjobs', null, true );
108
+                }
109
+            }
110
+
111
+            OC_Util::addStyle('server', null, true);
112
+            OC_Util::addStyle('jquery-ui-fixes',null,true);
113
+            OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true);
114
+            OC_Util::addVendorStyle('select2/select2', null, true);
115
+            OC_Util::addStyle('jquery.ocdialog');
116
+            OC_Util::addTranslations("core", null, true);
117
+            OC_Util::addScript('search', 'search', true);
118
+            OC_Util::addScript('merged-template-prepend', null, true);
119
+            OC_Util::addScript('jquery-ui-fixes');
120
+            OC_Util::addScript('files/fileinfo');
121
+            OC_Util::addScript('files/client');
122
+            OC_Util::addScript('contactsmenu');
123
+
124
+            if (\OC::$server->getConfig()->getSystemValue('debug')) {
125
+                // Add the stuff we need always
126
+                // following logic will import all vendor libraries that are
127
+                // specified in core/js/core.json
128
+                $fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json');
129
+                if($fileContent !== false) {
130
+                    $coreDependencies = json_decode($fileContent, true);
131
+                    foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) {
132
+                        //remove trailing ".js" as addVendorScript will append it
133
+                        OC_Util::addVendorScript(
134
+                            substr($vendorLibrary, 0, strlen($vendorLibrary) - 3),null,true);
135
+                        }
136
+                    } else {
137
+                    throw new \Exception('Cannot read core/js/core.json');
138
+                }
139
+            } else {
140
+                // Import all (combined) default vendor libraries
141
+                OC_Util::addVendorScript('core', null, true);
142
+            }
143
+
144
+            if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) {
145
+                // polyfill for btoa/atob for IE friends
146
+                OC_Util::addVendorScript('base64/base64');
147
+                // shim for the davclient.js library
148
+                \OCP\Util::addScript('files/iedavclient');
149
+            }
150
+
151
+            self::$initTemplateEngineFirstRun = false;
152
+        }
153
+
154
+    }
155
+
156
+
157
+    /**
158
+     * find the template with the given name
159
+     * @param string $name of the template file (without suffix)
160
+     *
161
+     * Will select the template file for the selected theme.
162
+     * Checking all the possible locations.
163
+     * @param string $theme
164
+     * @param string $app
165
+     * @return string[]
166
+     */
167
+    protected function findTemplate($theme, $app, $name) {
168
+        // Check if it is a app template or not.
169
+        if( $app !== '' ) {
170
+            $dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
171
+        } else {
172
+            $dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
173
+        }
174
+        $locator = new \OC\Template\TemplateFileLocator( $dirs );
175
+        $template = $locator->find($name);
176
+        $path = $locator->getPath();
177
+        return array($path, $template);
178
+    }
179
+
180
+    /**
181
+     * Add a custom element to the header
182
+     * @param string $tag tag name of the element
183
+     * @param array $attributes array of attributes for the element
184
+     * @param string $text the text content for the element. If $text is null then the
185
+     * element will be written as empty element. So use "" to get a closing tag.
186
+     */
187
+    public function addHeader($tag, $attributes, $text=null) {
188
+        $this->headers[]= array(
189
+            'tag' => $tag,
190
+            'attributes' => $attributes,
191
+            'text' => $text
192
+        );
193
+    }
194
+
195
+    /**
196
+     * Process the template
197
+     * @return boolean|string
198
+     *
199
+     * This function process the template. If $this->renderAs is set, it
200
+     * will produce a full page.
201
+     */
202
+    public function fetchPage($additionalParams = null) {
203
+        $data = parent::fetchPage($additionalParams);
204
+
205
+        if( $this->renderAs ) {
206
+            $page = new TemplateLayout($this->renderAs, $this->app);
207
+
208
+            // Add custom headers
209
+            $headers = '';
210
+            foreach(OC_Util::$headers as $header) {
211
+                $headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
212
+                if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
213
+                    $headers .= ' defer';
214
+                }
215
+                foreach($header['attributes'] as $name=>$value) {
216
+                    $headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
217
+                }
218
+                if ($header['text'] !== null) {
219
+                    $headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>';
220
+                } else {
221
+                    $headers .= '/>';
222
+                }
223
+            }
224
+
225
+            $page->assign('headers', $headers);
226
+
227
+            $page->assign('content', $data);
228
+            return $page->fetchPage();
229
+        }
230
+
231
+        return $data;
232
+    }
233
+
234
+    /**
235
+     * Include template
236
+     *
237
+     * @param string $file
238
+     * @param array|null $additionalParams
239
+     * @return string returns content of included template
240
+     *
241
+     * Includes another template. use <?php echo $this->inc('template'); ?> to
242
+     * do this.
243
+     */
244
+    public function inc( $file, $additionalParams = null ) {
245
+        return $this->load($this->path.$file.'.php', $additionalParams);
246
+    }
247
+
248
+    /**
249
+     * Shortcut to print a simple page for users
250
+     * @param string $application The application we render the template for
251
+     * @param string $name Name of the template
252
+     * @param array $parameters Parameters for the template
253
+     * @return boolean|null
254
+     */
255
+    public static function printUserPage( $application, $name, $parameters = array() ) {
256
+        $content = new OC_Template( $application, $name, "user" );
257
+        foreach( $parameters as $key => $value ) {
258
+            $content->assign( $key, $value );
259
+        }
260
+        print $content->printPage();
261
+    }
262
+
263
+    /**
264
+     * Shortcut to print a simple page for admins
265
+     * @param string $application The application we render the template for
266
+     * @param string $name Name of the template
267
+     * @param array $parameters Parameters for the template
268
+     * @return bool
269
+     */
270
+    public static function printAdminPage( $application, $name, $parameters = array() ) {
271
+        $content = new OC_Template( $application, $name, "admin" );
272
+        foreach( $parameters as $key => $value ) {
273
+            $content->assign( $key, $value );
274
+        }
275
+        return $content->printPage();
276
+    }
277
+
278
+    /**
279
+     * Shortcut to print a simple page for guests
280
+     * @param string $application The application we render the template for
281
+     * @param string $name Name of the template
282
+     * @param array|string $parameters Parameters for the template
283
+     * @return bool
284
+     */
285
+    public static function printGuestPage( $application, $name, $parameters = array() ) {
286
+        $content = new OC_Template( $application, $name, "guest" );
287
+        foreach( $parameters as $key => $value ) {
288
+            $content->assign( $key, $value );
289
+        }
290
+        return $content->printPage();
291
+    }
292
+
293
+    /**
294
+     * Print a fatal error page and terminates the script
295
+     * @param string $error_msg The error message to show
296
+     * @param string $hint An optional hint message - needs to be properly escape
297
+     * @suppress PhanAccessMethodInternal
298
+     */
299
+    public static function printErrorPage( $error_msg, $hint = '' ) {
300
+        if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
301
+            \OC_App::loadApp('theming');
302
+        }
303
+
304
+
305
+        if ($error_msg === $hint) {
306
+            // If the hint is the same as the message there is no need to display it twice.
307
+            $hint = '';
308
+        }
309
+
310
+        try {
311
+            $content = new \OC_Template( '', 'error', 'error', false );
312
+            $errors = array(array('error' => $error_msg, 'hint' => $hint));
313
+            $content->assign( 'errors', $errors );
314
+            $content->printPage();
315
+        } catch (\Exception $e) {
316
+            $logger = \OC::$server->getLogger();
317
+            $logger->error("$error_msg $hint", ['app' => 'core']);
318
+            $logger->logException($e, ['app' => 'core']);
319
+
320
+            header(self::getHttpProtocol() . ' 500 Internal Server Error');
321
+            header('Content-Type: text/plain; charset=utf-8');
322
+            print("$error_msg $hint");
323
+        }
324
+        die();
325
+    }
326
+
327
+    /**
328
+     * print error page using Exception details
329
+     * @param Exception|Throwable $exception
330
+     * @param bool $fetchPage
331
+     * @return bool|string
332
+     * @suppress PhanAccessMethodInternal
333
+     */
334
+    public static function printExceptionErrorPage($exception, $fetchPage = false) {
335
+        try {
336
+            $request = \OC::$server->getRequest();
337
+            $content = new \OC_Template('', 'exception', 'error', false);
338
+            $content->assign('errorClass', get_class($exception));
339
+            $content->assign('errorMsg', $exception->getMessage());
340
+            $content->assign('errorCode', $exception->getCode());
341
+            $content->assign('file', $exception->getFile());
342
+            $content->assign('line', $exception->getLine());
343
+            $content->assign('trace', $exception->getTraceAsString());
344
+            $content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
345
+            $content->assign('remoteAddr', $request->getRemoteAddress());
346
+            $content->assign('requestID', $request->getId());
347
+            if ($fetchPage) {
348
+                return $content->fetchPage();
349
+            }
350
+            $content->printPage();
351
+        } catch (\Exception $e) {
352
+            $logger = \OC::$server->getLogger();
353
+            $logger->logException($exception, ['app' => 'core']);
354
+            $logger->logException($e, ['app' => 'core']);
355
+
356
+            header(self::getHttpProtocol() . ' 500 Internal Server Error');
357
+            header('Content-Type: text/plain; charset=utf-8');
358
+            print("Internal Server Error\n\n");
359
+            print("The server encountered an internal error and was unable to complete your request.\n");
360
+            print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
361
+            print("More details can be found in the server log.\n");
362
+        }
363
+        die();
364
+    }
365
+
366
+    /**
367
+     * This is only here to reduce the dependencies in case of an exception to
368
+     * still be able to print a plain error message.
369
+     *
370
+     * Returns the used HTTP protocol.
371
+     *
372
+     * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
373
+     * @internal Don't use this - use AppFramework\Http\Request->getHttpProtocol instead
374
+     */
375
+    protected static function getHttpProtocol() {
376
+        $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']);
377
+        $validProtocols = [
378
+            'HTTP/1.0',
379
+            'HTTP/1.1',
380
+            'HTTP/2',
381
+        ];
382
+        if(in_array($claimedProtocol, $validProtocols, true)) {
383
+            return $claimedProtocol;
384
+        }
385
+        return 'HTTP/1.1';
386
+    }
387 387
 }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	 *                         "admin".
71 71
 	 * @param bool $registerCall = true
72 72
 	 */
73
-	public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
73
+	public function __construct($app, $name, $renderAs = "", $registerCall = true) {
74 74
 		// Read the selected theme from the config file
75 75
 		self::initTemplateEngine($renderAs);
76 76
 
@@ -97,20 +97,20 @@  discard block
 block discarded – undo
97 97
 	 * @param string $renderAs
98 98
 	 */
99 99
 	public static function initTemplateEngine($renderAs) {
100
-		if (self::$initTemplateEngineFirstRun){
100
+		if (self::$initTemplateEngineFirstRun) {
101 101
 
102 102
 			//apps that started before the template initialization can load their own scripts/styles
103 103
 			//so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
104 104
 			//meaning the last script/style in this list will be loaded first
105
-			if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
106
-				if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
107
-					OC_Util::addScript ( 'backgroundjobs', null, true );
105
+			if (\OC::$server->getSystemConfig()->getValue('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
106
+				if (\OC::$server->getConfig()->getAppValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') {
107
+					OC_Util::addScript('backgroundjobs', null, true);
108 108
 				}
109 109
 			}
110 110
 
111 111
 			OC_Util::addStyle('server', null, true);
112
-			OC_Util::addStyle('jquery-ui-fixes',null,true);
113
-			OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true);
112
+			OC_Util::addStyle('jquery-ui-fixes', null, true);
113
+			OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui', null, true);
114 114
 			OC_Util::addVendorStyle('select2/select2', null, true);
115 115
 			OC_Util::addStyle('jquery.ocdialog');
116 116
 			OC_Util::addTranslations("core", null, true);
@@ -125,13 +125,13 @@  discard block
 block discarded – undo
125 125
 				// Add the stuff we need always
126 126
 				// following logic will import all vendor libraries that are
127 127
 				// specified in core/js/core.json
128
-				$fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json');
129
-				if($fileContent !== false) {
128
+				$fileContent = file_get_contents(OC::$SERVERROOT.'/core/js/core.json');
129
+				if ($fileContent !== false) {
130 130
 					$coreDependencies = json_decode($fileContent, true);
131
-					foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) {
131
+					foreach (array_reverse($coreDependencies['vendor']) as $vendorLibrary) {
132 132
 						//remove trailing ".js" as addVendorScript will append it
133 133
 						OC_Util::addVendorScript(
134
-							substr($vendorLibrary, 0, strlen($vendorLibrary) - 3),null,true);
134
+							substr($vendorLibrary, 0, strlen($vendorLibrary) - 3), null, true);
135 135
 						}
136 136
  				} else {
137 137
 					throw new \Exception('Cannot read core/js/core.json');
@@ -166,12 +166,12 @@  discard block
 block discarded – undo
166 166
 	 */
167 167
 	protected function findTemplate($theme, $app, $name) {
168 168
 		// Check if it is a app template or not.
169
-		if( $app !== '' ) {
169
+		if ($app !== '') {
170 170
 			$dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
171 171
 		} else {
172 172
 			$dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
173 173
 		}
174
-		$locator = new \OC\Template\TemplateFileLocator( $dirs );
174
+		$locator = new \OC\Template\TemplateFileLocator($dirs);
175 175
 		$template = $locator->find($name);
176 176
 		$path = $locator->getPath();
177 177
 		return array($path, $template);
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 	 * @param string $text the text content for the element. If $text is null then the
185 185
 	 * element will be written as empty element. So use "" to get a closing tag.
186 186
 	 */
187
-	public function addHeader($tag, $attributes, $text=null) {
188
-		$this->headers[]= array(
187
+	public function addHeader($tag, $attributes, $text = null) {
188
+		$this->headers[] = array(
189 189
 			'tag' => $tag,
190 190
 			'attributes' => $attributes,
191 191
 			'text' => $text
@@ -202,17 +202,17 @@  discard block
 block discarded – undo
202 202
 	public function fetchPage($additionalParams = null) {
203 203
 		$data = parent::fetchPage($additionalParams);
204 204
 
205
-		if( $this->renderAs ) {
205
+		if ($this->renderAs) {
206 206
 			$page = new TemplateLayout($this->renderAs, $this->app);
207 207
 
208 208
 			// Add custom headers
209 209
 			$headers = '';
210
-			foreach(OC_Util::$headers as $header) {
210
+			foreach (OC_Util::$headers as $header) {
211 211
 				$headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
212
-				if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
212
+				if (strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes'])))) {
213 213
 					$headers .= ' defer';
214 214
 				}
215
-				foreach($header['attributes'] as $name=>$value) {
215
+				foreach ($header['attributes'] as $name=>$value) {
216 216
 					$headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
217 217
 				}
218 218
 				if ($header['text'] !== null) {
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	 * Includes another template. use <?php echo $this->inc('template'); ?> to
242 242
 	 * do this.
243 243
 	 */
244
-	public function inc( $file, $additionalParams = null ) {
244
+	public function inc($file, $additionalParams = null) {
245 245
 		return $this->load($this->path.$file.'.php', $additionalParams);
246 246
 	}
247 247
 
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
 	 * @param array $parameters Parameters for the template
253 253
 	 * @return boolean|null
254 254
 	 */
255
-	public static function printUserPage( $application, $name, $parameters = array() ) {
256
-		$content = new OC_Template( $application, $name, "user" );
257
-		foreach( $parameters as $key => $value ) {
258
-			$content->assign( $key, $value );
255
+	public static function printUserPage($application, $name, $parameters = array()) {
256
+		$content = new OC_Template($application, $name, "user");
257
+		foreach ($parameters as $key => $value) {
258
+			$content->assign($key, $value);
259 259
 		}
260 260
 		print $content->printPage();
261 261
 	}
@@ -267,10 +267,10 @@  discard block
 block discarded – undo
267 267
 	 * @param array $parameters Parameters for the template
268 268
 	 * @return bool
269 269
 	 */
270
-	public static function printAdminPage( $application, $name, $parameters = array() ) {
271
-		$content = new OC_Template( $application, $name, "admin" );
272
-		foreach( $parameters as $key => $value ) {
273
-			$content->assign( $key, $value );
270
+	public static function printAdminPage($application, $name, $parameters = array()) {
271
+		$content = new OC_Template($application, $name, "admin");
272
+		foreach ($parameters as $key => $value) {
273
+			$content->assign($key, $value);
274 274
 		}
275 275
 		return $content->printPage();
276 276
 	}
@@ -282,10 +282,10 @@  discard block
 block discarded – undo
282 282
 	 * @param array|string $parameters Parameters for the template
283 283
 	 * @return bool
284 284
 	 */
285
-	public static function printGuestPage( $application, $name, $parameters = array() ) {
286
-		$content = new OC_Template( $application, $name, "guest" );
287
-		foreach( $parameters as $key => $value ) {
288
-			$content->assign( $key, $value );
285
+	public static function printGuestPage($application, $name, $parameters = array()) {
286
+		$content = new OC_Template($application, $name, "guest");
287
+		foreach ($parameters as $key => $value) {
288
+			$content->assign($key, $value);
289 289
 		}
290 290
 		return $content->printPage();
291 291
 	}
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 	 * @param string $hint An optional hint message - needs to be properly escape
297 297
 	 * @suppress PhanAccessMethodInternal
298 298
 	 */
299
-	public static function printErrorPage( $error_msg, $hint = '' ) {
299
+	public static function printErrorPage($error_msg, $hint = '') {
300 300
 		if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
301 301
 			\OC_App::loadApp('theming');
302 302
 		}
@@ -308,16 +308,16 @@  discard block
 block discarded – undo
308 308
 		}
309 309
 
310 310
 		try {
311
-			$content = new \OC_Template( '', 'error', 'error', false );
311
+			$content = new \OC_Template('', 'error', 'error', false);
312 312
 			$errors = array(array('error' => $error_msg, 'hint' => $hint));
313
-			$content->assign( 'errors', $errors );
313
+			$content->assign('errors', $errors);
314 314
 			$content->printPage();
315 315
 		} catch (\Exception $e) {
316 316
 			$logger = \OC::$server->getLogger();
317 317
 			$logger->error("$error_msg $hint", ['app' => 'core']);
318 318
 			$logger->logException($e, ['app' => 'core']);
319 319
 
320
-			header(self::getHttpProtocol() . ' 500 Internal Server Error');
320
+			header(self::getHttpProtocol().' 500 Internal Server Error');
321 321
 			header('Content-Type: text/plain; charset=utf-8');
322 322
 			print("$error_msg $hint");
323 323
 		}
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 			$logger->logException($exception, ['app' => 'core']);
354 354
 			$logger->logException($e, ['app' => 'core']);
355 355
 
356
-			header(self::getHttpProtocol() . ' 500 Internal Server Error');
356
+			header(self::getHttpProtocol().' 500 Internal Server Error');
357 357
 			header('Content-Type: text/plain; charset=utf-8');
358 358
 			print("Internal Server Error\n\n");
359 359
 			print("The server encountered an internal error and was unable to complete your request.\n");
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
 			'HTTP/1.1',
380 380
 			'HTTP/2',
381 381
 		];
382
-		if(in_array($claimedProtocol, $validProtocols, true)) {
382
+		if (in_array($claimedProtocol, $validProtocols, true)) {
383 383
 			return $claimedProtocol;
384 384
 		}
385 385
 		return 'HTTP/1.1';
Please login to merge, or discard this patch.
lib/public/App.php 2 patches
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -43,113 +43,113 @@
 block discarded – undo
43 43
  */
44 44
 class App {
45 45
 
46
-	/**
47
-	 * Adds an entry to the navigation
48
-	 *
49
-	 * This function adds a new entry to the navigation visible to users. $data
50
-	 * is an associative array.
51
-	 * The following keys are required:
52
-	 *   - id: unique id for this entry ('addressbook_index')
53
-	 *   - href: link to the page
54
-	 *   - name: Human readable name ('Addressbook')
55
-	 *
56
-	 * The following keys are optional:
57
-	 *   - icon: path to the icon of the app
58
-	 *   - order: integer, that influences the position of your application in
59
-	 *     the navigation. Lower values come first.
60
-	 *
61
-	 * @param array $data containing the data
62
-	 * @return boolean
63
-	 *
64
-	 * @deprecated 8.1.0 Use \OC::$server->getNavigationManager()->add() instead to
65
-	 * register a closure, this helps to speed up all requests against ownCloud
66
-	 * @since 4.0.0
67
-	 */
68
-	public static function addNavigationEntry($data) {
69
-		\OC::$server->getNavigationManager()->add($data);
70
-		return true;
71
-	}
46
+    /**
47
+     * Adds an entry to the navigation
48
+     *
49
+     * This function adds a new entry to the navigation visible to users. $data
50
+     * is an associative array.
51
+     * The following keys are required:
52
+     *   - id: unique id for this entry ('addressbook_index')
53
+     *   - href: link to the page
54
+     *   - name: Human readable name ('Addressbook')
55
+     *
56
+     * The following keys are optional:
57
+     *   - icon: path to the icon of the app
58
+     *   - order: integer, that influences the position of your application in
59
+     *     the navigation. Lower values come first.
60
+     *
61
+     * @param array $data containing the data
62
+     * @return boolean
63
+     *
64
+     * @deprecated 8.1.0 Use \OC::$server->getNavigationManager()->add() instead to
65
+     * register a closure, this helps to speed up all requests against ownCloud
66
+     * @since 4.0.0
67
+     */
68
+    public static function addNavigationEntry($data) {
69
+        \OC::$server->getNavigationManager()->add($data);
70
+        return true;
71
+    }
72 72
 
73
-	/**
74
-	 * Marks a navigation entry as active
75
-	 * @param string $id id of the entry
76
-	 * @return boolean
77
-	 *
78
-	 * This function sets a navigation entry as active and removes the 'active'
79
-	 * property from all other entries. The templates can use this for
80
-	 * highlighting the current position of the user.
81
-	 *
82
-	 * @deprecated 8.1.0 Use \OC::$server->getNavigationManager()->setActiveEntry() instead
83
-	 * @since 4.0.0
84
-	 */
85
-	public static function setActiveNavigationEntry( $id ) {
86
-		\OC::$server->getNavigationManager()->setActiveEntry($id);
87
-		return true;
88
-	}
73
+    /**
74
+     * Marks a navigation entry as active
75
+     * @param string $id id of the entry
76
+     * @return boolean
77
+     *
78
+     * This function sets a navigation entry as active and removes the 'active'
79
+     * property from all other entries. The templates can use this for
80
+     * highlighting the current position of the user.
81
+     *
82
+     * @deprecated 8.1.0 Use \OC::$server->getNavigationManager()->setActiveEntry() instead
83
+     * @since 4.0.0
84
+     */
85
+    public static function setActiveNavigationEntry( $id ) {
86
+        \OC::$server->getNavigationManager()->setActiveEntry($id);
87
+        return true;
88
+    }
89 89
 
90
-	/**
91
-	 * Register a Configuration Screen that should appear in the personal settings section.
92
-	 * @param string $app appid
93
-	 * @param string $page page to be included
94
-	 * @return void
95
-	 * @since 4.0.0
96
-	*/
97
-	public static function registerPersonal( $app, $page ) {
98
-		\OC_App::registerPersonal( $app, $page );
99
-	}
90
+    /**
91
+     * Register a Configuration Screen that should appear in the personal settings section.
92
+     * @param string $app appid
93
+     * @param string $page page to be included
94
+     * @return void
95
+     * @since 4.0.0
96
+     */
97
+    public static function registerPersonal( $app, $page ) {
98
+        \OC_App::registerPersonal( $app, $page );
99
+    }
100 100
 
101
-	/**
102
-	 * Register a Configuration Screen that should appear in the Admin section.
103
-	 * @param string $app string appid
104
-	 * @param string $page string page to be included
105
-	 * @return void
106
-	 * @since 4.0.0
107
-	 */
108
-	public static function registerAdmin( $app, $page ) {
109
-		\OC_App::registerAdmin( $app, $page );
110
-	}
101
+    /**
102
+     * Register a Configuration Screen that should appear in the Admin section.
103
+     * @param string $app string appid
104
+     * @param string $page string page to be included
105
+     * @return void
106
+     * @since 4.0.0
107
+     */
108
+    public static function registerAdmin( $app, $page ) {
109
+        \OC_App::registerAdmin( $app, $page );
110
+    }
111 111
 
112
-	/**
113
-	 * Read app metadata from the info.xml file
114
-	 * @param string $app id of the app or the path of the info.xml file
115
-	 * @param boolean $path (optional)
116
-	 * @return array|null
117
-	 * @since 4.0.0
118
-	*/
119
-	public static function getAppInfo( $app, $path=false ) {
120
-		return \OC_App::getAppInfo( $app, $path);
121
-	}
112
+    /**
113
+     * Read app metadata from the info.xml file
114
+     * @param string $app id of the app or the path of the info.xml file
115
+     * @param boolean $path (optional)
116
+     * @return array|null
117
+     * @since 4.0.0
118
+     */
119
+    public static function getAppInfo( $app, $path=false ) {
120
+        return \OC_App::getAppInfo( $app, $path);
121
+    }
122 122
 
123
-	/**
124
-	 * checks whether or not an app is enabled
125
-	 * @param string $app
126
-	 * @return boolean
127
-	 *
128
-	 * This function checks whether or not an app is enabled.
129
-	 * @since 4.0.0
130
-	 * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId)
131
-	 */
132
-	public static function isEnabled( $app ) {
133
-		return \OC::$server->getAppManager()->isEnabledForUser( $app );
134
-	}
123
+    /**
124
+     * checks whether or not an app is enabled
125
+     * @param string $app
126
+     * @return boolean
127
+     *
128
+     * This function checks whether or not an app is enabled.
129
+     * @since 4.0.0
130
+     * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId)
131
+     */
132
+    public static function isEnabled( $app ) {
133
+        return \OC::$server->getAppManager()->isEnabledForUser( $app );
134
+    }
135 135
 
136
-	/**
137
-	 * Check if the app is enabled, redirects to home if not
138
-	 * @param string $app
139
-	 * @return void
140
-	 * @since 4.0.0
141
-	 * @deprecated 9.0.0 ownCloud core will handle disabled apps and redirects to valid URLs
142
-	*/
143
-	public static function checkAppEnabled( $app ) {
144
-	}
136
+    /**
137
+     * Check if the app is enabled, redirects to home if not
138
+     * @param string $app
139
+     * @return void
140
+     * @since 4.0.0
141
+     * @deprecated 9.0.0 ownCloud core will handle disabled apps and redirects to valid URLs
142
+     */
143
+    public static function checkAppEnabled( $app ) {
144
+    }
145 145
 
146
-	/**
147
-	 * Get the last version of the app from appinfo/info.xml
148
-	 * @param string $app
149
-	 * @return string
150
-	 * @since 4.0.0
151
-	 */
152
-	public static function getAppVersion( $app ) {
153
-		return \OC_App::getAppVersion( $app );
154
-	}
146
+    /**
147
+     * Get the last version of the app from appinfo/info.xml
148
+     * @param string $app
149
+     * @return string
150
+     * @since 4.0.0
151
+     */
152
+    public static function getAppVersion( $app ) {
153
+        return \OC_App::getAppVersion( $app );
154
+    }
155 155
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	 * @deprecated 8.1.0 Use \OC::$server->getNavigationManager()->setActiveEntry() instead
83 83
 	 * @since 4.0.0
84 84
 	 */
85
-	public static function setActiveNavigationEntry( $id ) {
85
+	public static function setActiveNavigationEntry($id) {
86 86
 		\OC::$server->getNavigationManager()->setActiveEntry($id);
87 87
 		return true;
88 88
 	}
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
 	 * @return void
95 95
 	 * @since 4.0.0
96 96
 	*/
97
-	public static function registerPersonal( $app, $page ) {
98
-		\OC_App::registerPersonal( $app, $page );
97
+	public static function registerPersonal($app, $page) {
98
+		\OC_App::registerPersonal($app, $page);
99 99
 	}
100 100
 
101 101
 	/**
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 	 * @return void
106 106
 	 * @since 4.0.0
107 107
 	 */
108
-	public static function registerAdmin( $app, $page ) {
109
-		\OC_App::registerAdmin( $app, $page );
108
+	public static function registerAdmin($app, $page) {
109
+		\OC_App::registerAdmin($app, $page);
110 110
 	}
111 111
 
112 112
 	/**
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
 	 * @return array|null
117 117
 	 * @since 4.0.0
118 118
 	*/
119
-	public static function getAppInfo( $app, $path=false ) {
120
-		return \OC_App::getAppInfo( $app, $path);
119
+	public static function getAppInfo($app, $path = false) {
120
+		return \OC_App::getAppInfo($app, $path);
121 121
 	}
122 122
 
123 123
 	/**
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 	 * @since 4.0.0
130 130
 	 * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId)
131 131
 	 */
132
-	public static function isEnabled( $app ) {
133
-		return \OC::$server->getAppManager()->isEnabledForUser( $app );
132
+	public static function isEnabled($app) {
133
+		return \OC::$server->getAppManager()->isEnabledForUser($app);
134 134
 	}
135 135
 
136 136
 	/**
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	 * @since 4.0.0
141 141
 	 * @deprecated 9.0.0 ownCloud core will handle disabled apps and redirects to valid URLs
142 142
 	*/
143
-	public static function checkAppEnabled( $app ) {
143
+	public static function checkAppEnabled($app) {
144 144
 	}
145 145
 
146 146
 	/**
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 * @return string
150 150
 	 * @since 4.0.0
151 151
 	 */
152
-	public static function getAppVersion( $app ) {
153
-		return \OC_App::getAppVersion( $app );
152
+	public static function getAppVersion($app) {
153
+		return \OC_App::getAppVersion($app);
154 154
 	}
155 155
 }
Please login to merge, or discard this patch.
settings/users.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -49,18 +49,18 @@  discard block
 block discarded – undo
49 49
 $config = \OC::$server->getConfig();
50 50
 
51 51
 if ($config->getSystemValue('sort_groups_by_name', false)) {
52
-	$sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
52
+    $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
53 53
 } else {
54
-	$isLDAPUsed = false;
55
-	if ($appManager->isEnabledForUser('user_ldap')) {
56
-		$isLDAPUsed =
57
-			$groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
58
-			|| $groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy');
59
-		if ($isLDAPUsed) {
60
-			// LDAP user count can be slow, so we sort by group name here
61
-			$sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
62
-		}
63
-	}
54
+    $isLDAPUsed = false;
55
+    if ($appManager->isEnabledForUser('user_ldap')) {
56
+        $isLDAPUsed =
57
+            $groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
58
+            || $groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy');
59
+        if ($isLDAPUsed) {
60
+            // LDAP user count can be slow, so we sort by group name here
61
+            $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
62
+        }
63
+    }
64 64
 }
65 65
 
66 66
 $isAdmin = OC_User::isAdminUser(OC_User::getUser());
@@ -68,58 +68,58 @@  discard block
 block discarded – undo
68 68
 $isDisabled = !OC_User::isEnabled(OC_User::getUser());
69 69
 
70 70
 $groupsInfo = new \OC\Group\MetaData(
71
-	OC_User::getUser(),
72
-	$isAdmin,
73
-	$groupManager,
74
-	\OC::$server->getUserSession()
71
+    OC_User::getUser(),
72
+    $isAdmin,
73
+    $groupManager,
74
+    \OC::$server->getUserSession()
75 75
 );
76 76
 
77 77
 $groupsInfo->setSorting($sortGroupsBy);
78 78
 list($adminGroup, $groups) = $groupsInfo->get();
79 79
 
80 80
 $recoveryAdminEnabled = $appManager->isEnabledForUser('encryption') &&
81
-					    $config->getAppValue( 'encryption', 'recoveryAdminEnabled', '0');
81
+                        $config->getAppValue( 'encryption', 'recoveryAdminEnabled', '0');
82 82
 
83 83
 if($isAdmin) {
84
-	$subAdmins = \OC::$server->getGroupManager()->getSubAdmin()->getAllSubAdmins();
85
-	// New class returns IUser[] so convert back
86
-	$result = [];
87
-	foreach ($subAdmins as $subAdmin) {
88
-		$result[] = [
89
-			'gid' => $subAdmin['group']->getGID(),
90
-			'uid' => $subAdmin['user']->getUID(),
91
-		];
92
-	}
93
-	$subAdmins = $result;
84
+    $subAdmins = \OC::$server->getGroupManager()->getSubAdmin()->getAllSubAdmins();
85
+    // New class returns IUser[] so convert back
86
+    $result = [];
87
+    foreach ($subAdmins as $subAdmin) {
88
+        $result[] = [
89
+            'gid' => $subAdmin['group']->getGID(),
90
+            'uid' => $subAdmin['user']->getUID(),
91
+        ];
92
+    }
93
+    $subAdmins = $result;
94 94
 }else{
95
-	/* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
96
-	$gids = array();
97
-	foreach($groups as $group) {
98
-		if (isset($group['id'])) {
99
-			$gids[] = $group['id'];
100
-		}
101
-	}
102
-	$subAdmins = false;
95
+    /* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
96
+    $gids = array();
97
+    foreach($groups as $group) {
98
+        if (isset($group['id'])) {
99
+            $gids[] = $group['id'];
100
+        }
101
+    }
102
+    $subAdmins = false;
103 103
 }
104 104
 
105 105
 $disabledUsers = $isLDAPUsed ? 0 : $userManager->countDisabledUsers();
106 106
 $disabledUsersGroup = [
107
-	'id' => '_disabledUsers',
108
-	'name' => '_disabledUsers',
109
-	'usercount' => $disabledUsers
107
+    'id' => '_disabledUsers',
108
+    'name' => '_disabledUsers',
109
+    'usercount' => $disabledUsers
110 110
 ];
111 111
 
112 112
 // load preset quotas
113 113
 $quotaPreset=$config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
114 114
 $quotaPreset=explode(',', $quotaPreset);
115 115
 foreach($quotaPreset as &$preset) {
116
-	$preset=trim($preset);
116
+    $preset=trim($preset);
117 117
 }
118 118
 $quotaPreset=array_diff($quotaPreset, array('default', 'none'));
119 119
 
120 120
 $defaultQuota=$config->getAppValue('files', 'default_quota', 'none');
121 121
 $defaultQuotaIsUserDefined=array_search($defaultQuota, $quotaPreset)===false
122
-	&& array_search($defaultQuota, array('none', 'default'))===false;
122
+    && array_search($defaultQuota, array('none', 'default'))===false;
123 123
 
124 124
 \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Users::loadAdditionalScripts');
125 125
 
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
 list($adminGroup, $groups) = $groupsInfo->get();
79 79
 
80 80
 $recoveryAdminEnabled = $appManager->isEnabledForUser('encryption') &&
81
-					    $config->getAppValue( 'encryption', 'recoveryAdminEnabled', '0');
81
+					    $config->getAppValue('encryption', 'recoveryAdminEnabled', '0');
82 82
 
83
-if($isAdmin) {
83
+if ($isAdmin) {
84 84
 	$subAdmins = \OC::$server->getGroupManager()->getSubAdmin()->getAllSubAdmins();
85 85
 	// New class returns IUser[] so convert back
86 86
 	$result = [];
@@ -91,10 +91,10 @@  discard block
 block discarded – undo
91 91
 		];
92 92
 	}
93 93
 	$subAdmins = $result;
94
-}else{
94
+} else {
95 95
 	/* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
96 96
 	$gids = array();
97
-	foreach($groups as $group) {
97
+	foreach ($groups as $group) {
98 98
 		if (isset($group['id'])) {
99 99
 			$gids[] = $group['id'];
100 100
 		}
@@ -110,16 +110,16 @@  discard block
 block discarded – undo
110 110
 ];
111 111
 
112 112
 // load preset quotas
113
-$quotaPreset=$config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
114
-$quotaPreset=explode(',', $quotaPreset);
115
-foreach($quotaPreset as &$preset) {
116
-	$preset=trim($preset);
113
+$quotaPreset = $config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
114
+$quotaPreset = explode(',', $quotaPreset);
115
+foreach ($quotaPreset as &$preset) {
116
+	$preset = trim($preset);
117 117
 }
118
-$quotaPreset=array_diff($quotaPreset, array('default', 'none'));
118
+$quotaPreset = array_diff($quotaPreset, array('default', 'none'));
119 119
 
120
-$defaultQuota=$config->getAppValue('files', 'default_quota', 'none');
121
-$defaultQuotaIsUserDefined=array_search($defaultQuota, $quotaPreset)===false
122
-	&& array_search($defaultQuota, array('none', 'default'))===false;
120
+$defaultQuota = $config->getAppValue('files', 'default_quota', 'none');
121
+$defaultQuotaIsUserDefined = array_search($defaultQuota, $quotaPreset) === false
122
+	&& array_search($defaultQuota, array('none', 'default')) === false;
123 123
 
124 124
 \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Users::loadAdditionalScripts');
125 125
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 $tmpl->assign('sortGroups', $sortGroupsBy);
129 129
 $tmpl->assign('adminGroup', $adminGroup);
130 130
 $tmpl->assign('disabledUsersGroup', $disabledUsersGroup);
131
-$tmpl->assign('isAdmin', (int)$isAdmin);
131
+$tmpl->assign('isAdmin', (int) $isAdmin);
132 132
 $tmpl->assign('subadmins', $subAdmins);
133 133
 $tmpl->assign('numofgroups', count($groups) + count($adminGroup));
134 134
 $tmpl->assign('quota_preset', $quotaPreset);
Please login to merge, or discard this patch.
core/Command/Maintenance/Repair.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -37,112 +37,112 @@
 block discarded – undo
37 37
 use Symfony\Component\EventDispatcher\GenericEvent;
38 38
 
39 39
 class Repair extends Command {
40
-	/** @var \OC\Repair $repair */
41
-	protected $repair;
42
-	/** @var IConfig */
43
-	protected $config;
44
-	/** @var EventDispatcherInterface */
45
-	private $dispatcher;
46
-	/** @var ProgressBar */
47
-	private $progress;
48
-	/** @var OutputInterface */
49
-	private $output;
40
+    /** @var \OC\Repair $repair */
41
+    protected $repair;
42
+    /** @var IConfig */
43
+    protected $config;
44
+    /** @var EventDispatcherInterface */
45
+    private $dispatcher;
46
+    /** @var ProgressBar */
47
+    private $progress;
48
+    /** @var OutputInterface */
49
+    private $output;
50 50
 
51
-	/**
52
-	 * @param \OC\Repair $repair
53
-	 * @param IConfig $config
54
-	 */
55
-	public function __construct(\OC\Repair $repair, IConfig $config, EventDispatcherInterface $dispatcher) {
56
-		$this->repair = $repair;
57
-		$this->config = $config;
58
-		$this->dispatcher = $dispatcher;
59
-		parent::__construct();
60
-	}
51
+    /**
52
+     * @param \OC\Repair $repair
53
+     * @param IConfig $config
54
+     */
55
+    public function __construct(\OC\Repair $repair, IConfig $config, EventDispatcherInterface $dispatcher) {
56
+        $this->repair = $repair;
57
+        $this->config = $config;
58
+        $this->dispatcher = $dispatcher;
59
+        parent::__construct();
60
+    }
61 61
 
62
-	protected function configure() {
63
-		$this
64
-			->setName('maintenance:repair')
65
-			->setDescription('repair this installation')
66
-			->addOption(
67
-				'include-expensive',
68
-				null,
69
-				InputOption::VALUE_NONE,
70
-				'Use this option when you want to include resource and load expensive tasks');
71
-	}
62
+    protected function configure() {
63
+        $this
64
+            ->setName('maintenance:repair')
65
+            ->setDescription('repair this installation')
66
+            ->addOption(
67
+                'include-expensive',
68
+                null,
69
+                InputOption::VALUE_NONE,
70
+                'Use this option when you want to include resource and load expensive tasks');
71
+    }
72 72
 
73
-	protected function execute(InputInterface $input, OutputInterface $output) {
74
-		$includeExpensive = $input->getOption('include-expensive');
75
-		if ($includeExpensive) {
76
-			foreach ($this->repair->getExpensiveRepairSteps() as $step) {
77
-				$this->repair->addStep($step);
78
-			}
79
-		}
73
+    protected function execute(InputInterface $input, OutputInterface $output) {
74
+        $includeExpensive = $input->getOption('include-expensive');
75
+        if ($includeExpensive) {
76
+            foreach ($this->repair->getExpensiveRepairSteps() as $step) {
77
+                $this->repair->addStep($step);
78
+            }
79
+        }
80 80
 
81
-		$appManager = \OC::$server->getAppManager();
82
-		$apps = $appManager->getInstalledApps();
83
-		foreach ($apps as $app) {
84
-			if (!$appManager->isEnabledForUser($app)) {
85
-				continue;
86
-			}
87
-			$info = \OC_App::getAppInfo($app);
88
-			if (!is_array($info)) {
89
-				continue;
90
-			}
91
-			$steps = $info['repair-steps']['post-migration'];
92
-			foreach ($steps as $step) {
93
-				try {
94
-					$this->repair->addStep($step);
95
-				} catch (Exception $ex) {
96
-					$output->writeln("<error>Failed to load repair step for $app: {$ex->getMessage()}</error>");
97
-				}
98
-			}
99
-		}
81
+        $appManager = \OC::$server->getAppManager();
82
+        $apps = $appManager->getInstalledApps();
83
+        foreach ($apps as $app) {
84
+            if (!$appManager->isEnabledForUser($app)) {
85
+                continue;
86
+            }
87
+            $info = \OC_App::getAppInfo($app);
88
+            if (!is_array($info)) {
89
+                continue;
90
+            }
91
+            $steps = $info['repair-steps']['post-migration'];
92
+            foreach ($steps as $step) {
93
+                try {
94
+                    $this->repair->addStep($step);
95
+                } catch (Exception $ex) {
96
+                    $output->writeln("<error>Failed to load repair step for $app: {$ex->getMessage()}</error>");
97
+                }
98
+            }
99
+        }
100 100
 
101
-		$maintenanceMode = $this->config->getSystemValue('maintenance', false);
102
-		$this->config->setSystemValue('maintenance', true);
101
+        $maintenanceMode = $this->config->getSystemValue('maintenance', false);
102
+        $this->config->setSystemValue('maintenance', true);
103 103
 
104
-		$this->progress = new ProgressBar($output);
105
-		$this->output = $output;
106
-		$this->dispatcher->addListener('\OC\Repair::startProgress', [$this, 'handleRepairFeedBack']);
107
-		$this->dispatcher->addListener('\OC\Repair::advance', [$this, 'handleRepairFeedBack']);
108
-		$this->dispatcher->addListener('\OC\Repair::finishProgress', [$this, 'handleRepairFeedBack']);
109
-		$this->dispatcher->addListener('\OC\Repair::step', [$this, 'handleRepairFeedBack']);
110
-		$this->dispatcher->addListener('\OC\Repair::info', [$this, 'handleRepairFeedBack']);
111
-		$this->dispatcher->addListener('\OC\Repair::warning', [$this, 'handleRepairFeedBack']);
112
-		$this->dispatcher->addListener('\OC\Repair::error', [$this, 'handleRepairFeedBack']);
104
+        $this->progress = new ProgressBar($output);
105
+        $this->output = $output;
106
+        $this->dispatcher->addListener('\OC\Repair::startProgress', [$this, 'handleRepairFeedBack']);
107
+        $this->dispatcher->addListener('\OC\Repair::advance', [$this, 'handleRepairFeedBack']);
108
+        $this->dispatcher->addListener('\OC\Repair::finishProgress', [$this, 'handleRepairFeedBack']);
109
+        $this->dispatcher->addListener('\OC\Repair::step', [$this, 'handleRepairFeedBack']);
110
+        $this->dispatcher->addListener('\OC\Repair::info', [$this, 'handleRepairFeedBack']);
111
+        $this->dispatcher->addListener('\OC\Repair::warning', [$this, 'handleRepairFeedBack']);
112
+        $this->dispatcher->addListener('\OC\Repair::error', [$this, 'handleRepairFeedBack']);
113 113
 
114
-		$this->repair->run();
114
+        $this->repair->run();
115 115
 
116
-		$this->config->setSystemValue('maintenance', $maintenanceMode);
117
-	}
116
+        $this->config->setSystemValue('maintenance', $maintenanceMode);
117
+    }
118 118
 
119
-	public function handleRepairFeedBack($event) {
120
-		if (!$event instanceof GenericEvent) {
121
-			return;
122
-		}
123
-		switch ($event->getSubject()) {
124
-			case '\OC\Repair::startProgress':
125
-				$this->progress->start($event->getArgument(0));
126
-				break;
127
-			case '\OC\Repair::advance':
128
-				$this->progress->advance($event->getArgument(0));
129
-				break;
130
-			case '\OC\Repair::finishProgress':
131
-				$this->progress->finish();
132
-				$this->output->writeln('');
133
-				break;
134
-			case '\OC\Repair::step':
135
-				$this->output->writeln(' - ' . $event->getArgument(0));
136
-				break;
137
-			case '\OC\Repair::info':
138
-				$this->output->writeln('     - ' . $event->getArgument(0));
139
-				break;
140
-			case '\OC\Repair::warning':
141
-				$this->output->writeln('     - WARNING: ' . $event->getArgument(0));
142
-				break;
143
-			case '\OC\Repair::error':
144
-				$this->output->writeln('     - ERROR: ' . $event->getArgument(0));
145
-				break;
146
-		}
147
-	}
119
+    public function handleRepairFeedBack($event) {
120
+        if (!$event instanceof GenericEvent) {
121
+            return;
122
+        }
123
+        switch ($event->getSubject()) {
124
+            case '\OC\Repair::startProgress':
125
+                $this->progress->start($event->getArgument(0));
126
+                break;
127
+            case '\OC\Repair::advance':
128
+                $this->progress->advance($event->getArgument(0));
129
+                break;
130
+            case '\OC\Repair::finishProgress':
131
+                $this->progress->finish();
132
+                $this->output->writeln('');
133
+                break;
134
+            case '\OC\Repair::step':
135
+                $this->output->writeln(' - ' . $event->getArgument(0));
136
+                break;
137
+            case '\OC\Repair::info':
138
+                $this->output->writeln('     - ' . $event->getArgument(0));
139
+                break;
140
+            case '\OC\Repair::warning':
141
+                $this->output->writeln('     - WARNING: ' . $event->getArgument(0));
142
+                break;
143
+            case '\OC\Repair::error':
144
+                $this->output->writeln('     - ERROR: ' . $event->getArgument(0));
145
+                break;
146
+        }
147
+    }
148 148
 }
Please login to merge, or discard this patch.