Completed
Pull Request — master (#4077)
by Joas
10:52
created
core/templates/layout.user.php 3 patches
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -111,8 +111,11 @@
 block discarded – undo
111 111
 								<?php foreach($_['navigation'] as $entry): ?>
112 112
 									<?php if($entry['showInHeader']): ?>
113 113
 										<li data-id="<?php p($entry['id']); ?>" class="in-header">
114
-									<?php else: ?>
115
-										<li data-id="<?php p($entry['id']); ?>">
114
+									<?php else {
115
+    : ?>
116
+										<li data-id="<?php p($entry['id']);
117
+}
118
+?>">
116 119
 									<?php endif; ?>
117 120
 									<a href="<?php print_unescaped($entry['href']); ?>" tabindex="3"
118 121
 										<?php if( $entry['active'] ): ?> class="active"<?php endif; ?>>
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -4,9 +4,9 @@
 block discarded – undo
4 4
 		<meta charset="utf-8">
5 5
 		<title>
6 6
 			<?php
7
-				p(!empty($_['application'])?$_['application'].' - ':'');
8
-				p($theme->getTitle());
9
-			?>
7
+                p(!empty($_['application'])?$_['application'].' - ':'');
8
+                p($theme->getTitle());
9
+            ?>
10 10
 		</title>
11 11
 		<meta http-equiv="X-UA-Compatible" content="IE=edge">
12 12
 		<meta name="referrer" content="never">
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 		<meta charset="utf-8">
5 5
 		<title>
6 6
 			<?php
7
-				p(!empty($_['application'])?$_['application'].' - ':'');
7
+				p(!empty($_['application']) ? $_['application'].' - ' : '');
8 8
 				p($theme->getTitle());
9 9
 			?>
10 10
 		</title>
@@ -14,16 +14,16 @@  discard block
 block discarded – undo
14 14
 		<meta name="apple-itunes-app" content="app-id=<?php p($theme->getiTunesAppId()); ?>">
15 15
 		<meta name="apple-mobile-web-app-capable" content="yes">
16 16
 		<meta name="apple-mobile-web-app-status-bar-style" content="black">
17
-		<meta name="apple-mobile-web-app-title" content="<?php p((!empty($_['application']) && $_['appid']!='files')? $_['application']:$theme->getTitle()); ?>">
17
+		<meta name="apple-mobile-web-app-title" content="<?php p((!empty($_['application']) && $_['appid'] != 'files') ? $_['application'] : $theme->getTitle()); ?>">
18 18
 		<meta name="mobile-web-app-capable" content="yes">
19 19
 		<meta name="theme-color" content="<?php p($theme->getMailHeaderColor()); ?>">
20 20
 		<link rel="icon" href="<?php print_unescaped(image_path($_['appid'], 'favicon.ico')); /* IE11+ supports png */ ?>">
21 21
 		<link rel="apple-touch-icon-precomposed" href="<?php print_unescaped(image_path($_['appid'], 'favicon-touch.png')); ?>">
22 22
 		<link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path($_['appid'], 'favicon-mask.svg')); ?>" color="#0082c9">
23
-		<?php foreach($_['cssfiles'] as $cssfile): ?>
23
+		<?php foreach ($_['cssfiles'] as $cssfile): ?>
24 24
 			<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>">
25 25
 		<?php endforeach; ?>
26
-		<?php foreach($_['printcssfiles'] as $cssfile): ?>
26
+		<?php foreach ($_['printcssfiles'] as $cssfile): ?>
27 27
 			<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="print">
28 28
 		<?php endforeach; ?>
29 29
 		<?php if (isset($_['inline_ocjs'])): ?>
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
 				<?php print_unescaped($_['inline_ocjs']); ?>
32 32
 			</script>
33 33
 		<?php endif; ?>
34
-		<?php foreach($_['jsfiles'] as $jsfile): ?>
34
+		<?php foreach ($_['jsfiles'] as $jsfile): ?>
35 35
 			<script nonce="<?php p(\OC::$server->getContentSecurityPolicyNonceManager()->getNonce()) ?>" src="<?php print_unescaped($jsfile); ?>"></script>
36 36
 		<?php endforeach; ?>
37 37
 		<?php print_unescaped($_['headers']); ?>
38 38
 	</head>
39
-	<body id="<?php p($_['bodyid']);?>">
39
+	<body id="<?php p($_['bodyid']); ?>">
40 40
 	<?php include('layout.noscript.warning.php'); ?>
41 41
 	<div id="notification-container">
42 42
 		<div id="notification"></div>
@@ -54,18 +54,18 @@  discard block
 block discarded – undo
54 54
 
55 55
 				<a href="#" class="header-appname-container menutoggle" tabindex="2">
56 56
 					<h1 class="header-appname">
57
-						<?php p(!empty($_['application'])?$_['application']: $l->t('Apps')); ?>
57
+						<?php p(!empty($_['application']) ? $_['application'] : $l->t('Apps')); ?>
58 58
 					</h1>
59 59
 					<div class="icon-caret"></div>
60 60
 				</a>
61 61
 
62 62
 				<div id="appmenu">
63 63
 					<ul>
64
-						<?php foreach($_['headernavigation'] as $entry): ?>
64
+						<?php foreach ($_['headernavigation'] as $entry): ?>
65 65
 							<li data-id="<?php p($entry['id']); ?>">
66 66
 								<a href="<?php print_unescaped($entry['href']); ?>" tabindex="3"
67
-									<?php if( $entry['active'] ): ?> class="active"<?php endif; ?>>
68
-									<img src="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>"  class="app-icon" />
67
+									<?php if ($entry['active']): ?> class="active"<?php endif; ?>>
68
+									<img src="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>"  class="app-icon" />
69 69
 									<div class="icon-loading-dark" style="display:none;"></div>
70 70
 									<span>
71 71
 								<?php p($entry['name']); ?>
@@ -85,17 +85,17 @@  discard block
 block discarded – undo
85 85
 				<nav role="navigation"><div id="navigation">
86 86
 						<div id="apps">
87 87
 							<ul>
88
-								<?php foreach($_['navigation'] as $entry): ?>
89
-									<?php if($entry['showInHeader']): ?>
88
+								<?php foreach ($_['navigation'] as $entry): ?>
89
+									<?php if ($entry['showInHeader']): ?>
90 90
 										<li data-id="<?php p($entry['id']); ?>" class="in-header">
91 91
 									<?php else: ?>
92 92
 										<li data-id="<?php p($entry['id']); ?>">
93 93
 									<?php endif; ?>
94 94
 									<a href="<?php print_unescaped($entry['href']); ?>" tabindex="3"
95
-										<?php if( $entry['active'] ): ?> class="active"<?php endif; ?>>
95
+										<?php if ($entry['active']): ?> class="active"<?php endif; ?>>
96 96
 										<svg width="32" height="32" viewBox="0 0 32 32">
97 97
 											<defs><filter id="invert-<?php p($entry['id']); ?>"><feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0"></feColorMatrix></filter></defs>
98
-											<image x="0" y="0" width="32" height="32" preserveAspectRatio="xMinYMin meet" filter="url(#invert-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>"  class="app-icon"></image>
98
+											<image x="0" y="0" width="32" height="32" preserveAspectRatio="xMinYMin meet" filter="url(#invert-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>"  class="app-icon"></image>
99 99
 										</svg>
100 100
 										<div class="icon-loading-dark" style="display:none;"></div>
101 101
 										<span>
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 			<div id="header-right">
114 114
 				<form class="searchbox" action="#" method="post" role="search" novalidate>
115 115
 					<label for="searchbox" class="hidden-visually">
116
-						<?php p($l->t('Search'));?>
116
+						<?php p($l->t('Search')); ?>
117 117
 					</label>
118 118
 					<input id="searchbox" type="search" name="query"
119 119
 						value="" required
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
 						<div class="avatardiv<?php if ($_['userAvatarSet']) { print_unescaped(' avatardiv-shown'); } else { print_unescaped('" style="display: none'); } ?>">
126 126
 							<?php if ($_['userAvatarSet']): ?>
127 127
 								<img alt="" width="32" height="32"
128
-								src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']]));?>"
129
-								srcset="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 64, 'v' => $_['userAvatarVersion']]));?> 2x, <?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 128, 'v' => $_['userAvatarVersion']]));?> 4x"
128
+								src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']])); ?>"
129
+								srcset="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 64, 'v' => $_['userAvatarVersion']])); ?> 2x, <?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 128, 'v' => $_['userAvatarVersion']])); ?> 4x"
130 130
 								>
131 131
 							<?php endif; ?>
132 132
 						</div>
@@ -135,19 +135,19 @@  discard block
 block discarded – undo
135 135
 					</div>
136 136
 					<div id="expanddiv">
137 137
 					<ul>
138
-					<?php foreach($_['settingsnavigation'] as $entry):?>
138
+					<?php foreach ($_['settingsnavigation'] as $entry):?>
139 139
 						<li>
140 140
 							<a href="<?php print_unescaped($entry['href']); ?>"
141
-								<?php if( $entry["active"] ): ?> class="active"<?php endif; ?>>
142
-								<img alt="" src="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>">
141
+								<?php if ($entry["active"]): ?> class="active"<?php endif; ?>>
142
+								<img alt="" src="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>">
143 143
 								<?php p($entry['name']) ?>
144 144
 							</a>
145 145
 						</li>
146 146
 					<?php endforeach; ?>
147 147
 						<li>
148 148
 							<a id="logout" <?php print_unescaped(OC_User::getLogoutAttribute()); ?>>
149
-								<img alt="" src="<?php print_unescaped(image_path('', 'actions/logout.svg') . '?v=' . $_['versionHash']); ?>">
150
-								<?php p($l->t('Log out'));?>
149
+								<img alt="" src="<?php print_unescaped(image_path('', 'actions/logout.svg').'?v='.$_['versionHash']); ?>">
150
+								<?php p($l->t('Log out')); ?>
151 151
 							</a>
152 152
 						</li>
153 153
 					</ul>
Please login to merge, or discard this patch.
lib/private/TemplateLayout.php 1 patch
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -41,233 +41,233 @@
 block discarded – undo
41 41
 
42 42
 class TemplateLayout extends \OC_Template {
43 43
 
44
-	private static $versionHash = '';
44
+    private static $versionHash = '';
45 45
 
46
-	/**
47
-	 * @var \OCP\IConfig
48
-	 */
49
-	private $config;
46
+    /**
47
+     * @var \OCP\IConfig
48
+     */
49
+    private $config;
50 50
 
51
-	/**
52
-	 * @param string $renderAs
53
-	 * @param string $appId application id
54
-	 */
55
-	public function __construct( $renderAs, $appId = '' ) {
51
+    /**
52
+     * @param string $renderAs
53
+     * @param string $appId application id
54
+     */
55
+    public function __construct( $renderAs, $appId = '' ) {
56 56
 
57
-		// yes - should be injected ....
58
-		$this->config = \OC::$server->getConfig();
57
+        // yes - should be injected ....
58
+        $this->config = \OC::$server->getConfig();
59 59
 
60
-		// Decide which page we show
61
-		if($renderAs == 'user') {
62
-			parent::__construct( 'core', 'layout.user' );
63
-			if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
64
-				$this->assign('bodyid', 'body-settings');
65
-			}else{
66
-				$this->assign('bodyid', 'body-user');
67
-			}
60
+        // Decide which page we show
61
+        if($renderAs == 'user') {
62
+            parent::__construct( 'core', 'layout.user' );
63
+            if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
64
+                $this->assign('bodyid', 'body-settings');
65
+            }else{
66
+                $this->assign('bodyid', 'body-user');
67
+            }
68 68
 
69
-			// Code integrity notification
70
-			$integrityChecker = \OC::$server->getIntegrityCodeChecker();
71
-			if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
72
-				\OCP\Util::addScript('core', 'integritycheck-failed-notification');
73
-			}
69
+            // Code integrity notification
70
+            $integrityChecker = \OC::$server->getIntegrityCodeChecker();
71
+            if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
72
+                \OCP\Util::addScript('core', 'integritycheck-failed-notification');
73
+            }
74 74
 
75
-			// Add navigation entry
76
-			$this->assign( 'application', '');
77
-			$this->assign( 'appid', $appId );
78
-			$navigation = \OC_App::getNavigation();
79
-			$this->assign( 'navigation', $navigation);
80
-			$navigation = \OC_App::getHeaderNavigation();
81
-			$this->assign( 'headernavigation', $navigation);
82
-			$settingsNavigation = \OC_App::getSettingsNavigation();
83
-			$this->assign( 'settingsnavigation', $settingsNavigation);
84
-			foreach($navigation as $entry) {
85
-				if ($entry['active']) {
86
-					$this->assign( 'application', $entry['name'] );
87
-					break;
88
-				}
89
-			}
75
+            // Add navigation entry
76
+            $this->assign( 'application', '');
77
+            $this->assign( 'appid', $appId );
78
+            $navigation = \OC_App::getNavigation();
79
+            $this->assign( 'navigation', $navigation);
80
+            $navigation = \OC_App::getHeaderNavigation();
81
+            $this->assign( 'headernavigation', $navigation);
82
+            $settingsNavigation = \OC_App::getSettingsNavigation();
83
+            $this->assign( 'settingsnavigation', $settingsNavigation);
84
+            foreach($navigation as $entry) {
85
+                if ($entry['active']) {
86
+                    $this->assign( 'application', $entry['name'] );
87
+                    break;
88
+                }
89
+            }
90 90
 			
91
-			foreach($settingsNavigation as $entry) {
92
-				if ($entry['active']) {
93
-					$this->assign( 'application', $entry['name'] );
94
-					break;
95
-				}
96
-			}
97
-			$userDisplayName = \OC_User::getDisplayName();
98
-			$this->assign('user_displayname', $userDisplayName);
99
-			$this->assign('user_uid', \OC_User::getUser());
91
+            foreach($settingsNavigation as $entry) {
92
+                if ($entry['active']) {
93
+                    $this->assign( 'application', $entry['name'] );
94
+                    break;
95
+                }
96
+            }
97
+            $userDisplayName = \OC_User::getDisplayName();
98
+            $this->assign('user_displayname', $userDisplayName);
99
+            $this->assign('user_uid', \OC_User::getUser());
100 100
 
101
-			if (\OC_User::getUser() === false) {
102
-				$this->assign('userAvatarSet', false);
103
-			} else {
104
-				$this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists());
105
-				$this->assign('userAvatarVersion', \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
106
-			}
101
+            if (\OC_User::getUser() === false) {
102
+                $this->assign('userAvatarSet', false);
103
+            } else {
104
+                $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists());
105
+                $this->assign('userAvatarVersion', \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
106
+            }
107 107
 
108
-		} else if ($renderAs == 'error') {
109
-			parent::__construct('core', 'layout.guest', '', false);
110
-			$this->assign('bodyid', 'body-login');
111
-		} else if ($renderAs == 'guest') {
112
-			parent::__construct('core', 'layout.guest');
113
-			$this->assign('bodyid', 'body-login');
114
-		} else {
115
-			parent::__construct('core', 'layout.base');
108
+        } else if ($renderAs == 'error') {
109
+            parent::__construct('core', 'layout.guest', '', false);
110
+            $this->assign('bodyid', 'body-login');
111
+        } else if ($renderAs == 'guest') {
112
+            parent::__construct('core', 'layout.guest');
113
+            $this->assign('bodyid', 'body-login');
114
+        } else {
115
+            parent::__construct('core', 'layout.base');
116 116
 
117
-		}
118
-		// Send the language to our layouts
119
-		$this->assign('language', \OC::$server->getL10NFactory()->findLanguage());
117
+        }
118
+        // Send the language to our layouts
119
+        $this->assign('language', \OC::$server->getL10NFactory()->findLanguage());
120 120
 
121
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
122
-			if (empty(self::$versionHash)) {
123
-				$v = \OC_App::getAppVersions();
124
-				$v['core'] = implode('.', \OCP\Util::getVersion());
125
-				self::$versionHash = md5(implode(',', $v));
126
-			}
127
-		} else {
128
-			self::$versionHash = md5('not installed');
129
-		}
121
+        if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
122
+            if (empty(self::$versionHash)) {
123
+                $v = \OC_App::getAppVersions();
124
+                $v['core'] = implode('.', \OCP\Util::getVersion());
125
+                self::$versionHash = md5(implode(',', $v));
126
+            }
127
+        } else {
128
+            self::$versionHash = md5('not installed');
129
+        }
130 130
 
131
-		// Add the js files
132
-		$jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
133
-		$this->assign('jsfiles', array());
134
-		if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
135
-			if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
136
-				$jsConfigHelper = new JSConfigHelper(
137
-					\OC::$server->getL10N('core'),
138
-					\OC::$server->getThemingDefaults(),
139
-					\OC::$server->getAppManager(),
140
-					\OC::$server->getSession(),
141
-					\OC::$server->getUserSession()->getUser(),
142
-					\OC::$server->getConfig(),
143
-					\OC::$server->getGroupManager(),
144
-					\OC::$server->getIniWrapper(),
145
-					\OC::$server->getURLGenerator()
146
-				);
147
-				$this->assign('inline_ocjs', $jsConfigHelper->getConfig());
148
-			} else {
149
-				$this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
150
-			}
151
-		}
152
-		foreach($jsFiles as $info) {
153
-			$web = $info[1];
154
-			$file = $info[2];
155
-			$this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
156
-		}
131
+        // Add the js files
132
+        $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
133
+        $this->assign('jsfiles', array());
134
+        if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
135
+            if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
136
+                $jsConfigHelper = new JSConfigHelper(
137
+                    \OC::$server->getL10N('core'),
138
+                    \OC::$server->getThemingDefaults(),
139
+                    \OC::$server->getAppManager(),
140
+                    \OC::$server->getSession(),
141
+                    \OC::$server->getUserSession()->getUser(),
142
+                    \OC::$server->getConfig(),
143
+                    \OC::$server->getGroupManager(),
144
+                    \OC::$server->getIniWrapper(),
145
+                    \OC::$server->getURLGenerator()
146
+                );
147
+                $this->assign('inline_ocjs', $jsConfigHelper->getConfig());
148
+            } else {
149
+                $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
150
+            }
151
+        }
152
+        foreach($jsFiles as $info) {
153
+            $web = $info[1];
154
+            $file = $info[2];
155
+            $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
156
+        }
157 157
 
158
-		try {
159
-			$pathInfo = \OC::$server->getRequest()->getPathInfo();
160
-		} catch (\Exception $e) {
161
-			$pathInfo = '';
162
-		}
158
+        try {
159
+            $pathInfo = \OC::$server->getRequest()->getPathInfo();
160
+        } catch (\Exception $e) {
161
+            $pathInfo = '';
162
+        }
163 163
 
164
-		// Do not initialise scss appdata until we have a fully installed instance
165
-		// Do not load scss for update, errors, installation or login page
166
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)
167
-			&& !\OCP\Util::needUpgrade()
168
-			&& $pathInfo !== ''
169
-			&& !preg_match('/^\/login/', $pathInfo)) {
170
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
171
-		} else {
172
-			// If we ignore the scss compiler,
173
-			// we need to load the guest css fallback
174
-			\OC_Util::addStyle('guest');
175
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
176
-		}
164
+        // Do not initialise scss appdata until we have a fully installed instance
165
+        // Do not load scss for update, errors, installation or login page
166
+        if(\OC::$server->getSystemConfig()->getValue('installed', false)
167
+            && !\OCP\Util::needUpgrade()
168
+            && $pathInfo !== ''
169
+            && !preg_match('/^\/login/', $pathInfo)) {
170
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
171
+        } else {
172
+            // If we ignore the scss compiler,
173
+            // we need to load the guest css fallback
174
+            \OC_Util::addStyle('guest');
175
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
176
+        }
177 177
 
178
-		$this->assign('cssfiles', array());
179
-		$this->assign('printcssfiles', []);
180
-		$this->assign('versionHash', self::$versionHash);
181
-		foreach($cssFiles as $info) {
182
-			$web = $info[1];
183
-			$file = $info[2];
178
+        $this->assign('cssfiles', array());
179
+        $this->assign('printcssfiles', []);
180
+        $this->assign('versionHash', self::$versionHash);
181
+        foreach($cssFiles as $info) {
182
+            $web = $info[1];
183
+            $file = $info[2];
184 184
 
185
-			if (substr($file, -strlen('print.css')) === 'print.css') {
186
-				$this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
187
-			} else {
188
-				$this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix()  );
189
-			}
190
-		}
191
-	}
185
+            if (substr($file, -strlen('print.css')) === 'print.css') {
186
+                $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
187
+            } else {
188
+                $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix()  );
189
+            }
190
+        }
191
+    }
192 192
 
193
-	protected function getVersionHashSuffix() {
194
-		if(\OC::$server->getConfig()->getSystemValue('debug', false)) {
195
-			// allows chrome workspace mapping in debug mode
196
-			return "";
197
-		}
193
+    protected function getVersionHashSuffix() {
194
+        if(\OC::$server->getConfig()->getSystemValue('debug', false)) {
195
+            // allows chrome workspace mapping in debug mode
196
+            return "";
197
+        }
198 198
 
199
-		return '?v=' . self::$versionHash;
200
-	}
199
+        return '?v=' . self::$versionHash;
200
+    }
201 201
 
202
-	/**
203
-	 * @param array $styles
204
-	 * @return array
205
-	 */
206
-	static public function findStylesheetFiles($styles, $compileScss = true) {
207
-		// Read the selected theme from the config file
208
-		$theme = \OC_Util::getTheme();
202
+    /**
203
+     * @param array $styles
204
+     * @return array
205
+     */
206
+    static public function findStylesheetFiles($styles, $compileScss = true) {
207
+        // Read the selected theme from the config file
208
+        $theme = \OC_Util::getTheme();
209 209
 
210
-		if($compileScss) {
211
-			/** @var \OC\Memcache\Factory $cache */
212
-			$cache = \OC::$server->query('MemCacheFactory');
213
-			$SCSSCacher = new SCSSCacher(
214
-				\OC::$server->getLogger(),
215
-				\OC::$server->getAppDataDir('css'),
216
-				\OC::$server->getURLGenerator(),
217
-				\OC::$server->getConfig(),
218
-				\OC::$SERVERROOT,
219
-				$cache->createLocal('SCSS')
220
-			);
221
-		} else {
222
-			$SCSSCacher = null;
223
-		}
210
+        if($compileScss) {
211
+            /** @var \OC\Memcache\Factory $cache */
212
+            $cache = \OC::$server->query('MemCacheFactory');
213
+            $SCSSCacher = new SCSSCacher(
214
+                \OC::$server->getLogger(),
215
+                \OC::$server->getAppDataDir('css'),
216
+                \OC::$server->getURLGenerator(),
217
+                \OC::$server->getConfig(),
218
+                \OC::$SERVERROOT,
219
+                $cache->createLocal('SCSS')
220
+            );
221
+        } else {
222
+            $SCSSCacher = null;
223
+        }
224 224
 
225
-		$locator = new \OC\Template\CSSResourceLocator(
226
-			\OC::$server->getLogger(),
227
-			$theme,
228
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
229
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
230
-			$SCSSCacher);
231
-		$locator->find($styles);
232
-		return $locator->getResources();
233
-	}
225
+        $locator = new \OC\Template\CSSResourceLocator(
226
+            \OC::$server->getLogger(),
227
+            $theme,
228
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
229
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
230
+            $SCSSCacher);
231
+        $locator->find($styles);
232
+        return $locator->getResources();
233
+    }
234 234
 
235
-	/**
236
-	 * @param array $scripts
237
-	 * @return array
238
-	 */
239
-	static public function findJavascriptFiles($scripts) {
240
-		// Read the selected theme from the config file
241
-		$theme = \OC_Util::getTheme();
235
+    /**
236
+     * @param array $scripts
237
+     * @return array
238
+     */
239
+    static public function findJavascriptFiles($scripts) {
240
+        // Read the selected theme from the config file
241
+        $theme = \OC_Util::getTheme();
242 242
 
243
-		$locator = new \OC\Template\JSResourceLocator(
244
-			\OC::$server->getLogger(),
245
-			$theme,
246
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
247
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
248
-			new JSCombiner(
249
-				\OC::$server->getAppDataDir('js'),
250
-				\OC::$server->getURLGenerator(),
251
-				\OC::$server->getMemCacheFactory()->create('JS'),
252
-				\OC::$server->getSystemConfig()
253
-			)
254
-			);
255
-		$locator->find($scripts);
256
-		return $locator->getResources();
257
-	}
243
+        $locator = new \OC\Template\JSResourceLocator(
244
+            \OC::$server->getLogger(),
245
+            $theme,
246
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
247
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
248
+            new JSCombiner(
249
+                \OC::$server->getAppDataDir('js'),
250
+                \OC::$server->getURLGenerator(),
251
+                \OC::$server->getMemCacheFactory()->create('JS'),
252
+                \OC::$server->getSystemConfig()
253
+            )
254
+            );
255
+        $locator->find($scripts);
256
+        return $locator->getResources();
257
+    }
258 258
 
259
-	/**
260
-	 * Converts the absolute file path to a relative path from \OC::$SERVERROOT
261
-	 * @param string $filePath Absolute path
262
-	 * @return string Relative path
263
-	 * @throws \Exception If $filePath is not under \OC::$SERVERROOT
264
-	 */
265
-	public static function convertToRelativePath($filePath) {
266
-		$relativePath = explode(\OC::$SERVERROOT, $filePath);
267
-		if(count($relativePath) !== 2) {
268
-			throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
269
-		}
259
+    /**
260
+     * Converts the absolute file path to a relative path from \OC::$SERVERROOT
261
+     * @param string $filePath Absolute path
262
+     * @return string Relative path
263
+     * @throws \Exception If $filePath is not under \OC::$SERVERROOT
264
+     */
265
+    public static function convertToRelativePath($filePath) {
266
+        $relativePath = explode(\OC::$SERVERROOT, $filePath);
267
+        if(count($relativePath) !== 2) {
268
+            throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
269
+        }
270 270
 
271
-		return $relativePath[1];
272
-	}
271
+        return $relativePath[1];
272
+    }
273 273
 }
Please login to merge, or discard this patch.
lib/private/legacy/app.php 2 patches
Indentation   +1328 added lines, -1328 removed lines patch added patch discarded remove patch
@@ -61,1332 +61,1332 @@
 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
-	}
178
-
179
-	/**
180
-	 * @internal
181
-	 * @param string $app
182
-	 * @param string $path
183
-	 */
184
-	public static function registerAutoloading($app, $path) {
185
-		$key = $app . '-' . $path;
186
-		if(isset(self::$alreadyRegistered[$key])) {
187
-			return;
188
-		}
189
-		self::$alreadyRegistered[$key] = true;
190
-		// Register on PSR-4 composer autoloader
191
-		$appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
192
-		\OC::$server->registerNamespace($app, $appNamespace);
193
-		\OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
194
-		if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
195
-			\OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
196
-		}
197
-
198
-		// Register on legacy autoloader
199
-		\OC::$loader->addValidRoot($path);
200
-	}
201
-
202
-	/**
203
-	 * Load app.php from the given app
204
-	 *
205
-	 * @param string $app app name
206
-	 */
207
-	private static function requireAppFile($app) {
208
-		try {
209
-			// encapsulated here to avoid variable scope conflicts
210
-			require_once $app . '/appinfo/app.php';
211
-		} catch (Error $ex) {
212
-			\OC::$server->getLogger()->logException($ex);
213
-			$blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
214
-			if (!in_array($app, $blacklist)) {
215
-				self::disable($app);
216
-			}
217
-		}
218
-	}
219
-
220
-	/**
221
-	 * check if an app is of a specific type
222
-	 *
223
-	 * @param string $app
224
-	 * @param string|array $types
225
-	 * @return bool
226
-	 */
227
-	public static function isType($app, $types) {
228
-		if (is_string($types)) {
229
-			$types = array($types);
230
-		}
231
-		$appTypes = self::getAppTypes($app);
232
-		foreach ($types as $type) {
233
-			if (array_search($type, $appTypes) !== false) {
234
-				return true;
235
-			}
236
-		}
237
-		return false;
238
-	}
239
-
240
-	/**
241
-	 * get the types of an app
242
-	 *
243
-	 * @param string $app
244
-	 * @return array
245
-	 */
246
-	private static function getAppTypes($app) {
247
-		//load the cache
248
-		if (count(self::$appTypes) == 0) {
249
-			self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types');
250
-		}
251
-
252
-		if (isset(self::$appTypes[$app])) {
253
-			return explode(',', self::$appTypes[$app]);
254
-		} else {
255
-			return array();
256
-		}
257
-	}
258
-
259
-	/**
260
-	 * read app types from info.xml and cache them in the database
261
-	 */
262
-	public static function setAppTypes($app) {
263
-		$appData = self::getAppInfo($app);
264
-		if(!is_array($appData)) {
265
-			return;
266
-		}
267
-
268
-		if (isset($appData['types'])) {
269
-			$appTypes = implode(',', $appData['types']);
270
-		} else {
271
-			$appTypes = '';
272
-			$appData['types'] = [];
273
-		}
274
-
275
-		\OC::$server->getAppConfig()->setValue($app, 'types', $appTypes);
276
-
277
-		if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) {
278
-			$enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes');
279
-			if ($enabled !== 'yes' && $enabled !== 'no') {
280
-				\OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes');
281
-			}
282
-		}
283
-	}
284
-
285
-	/**
286
-	 * check if app is shipped
287
-	 *
288
-	 * @param string $appId the id of the app to check
289
-	 * @return bool
290
-	 *
291
-	 * Check if an app that is installed is a shipped app or installed from the appstore.
292
-	 */
293
-	public static function isShipped($appId) {
294
-		return \OC::$server->getAppManager()->isShipped($appId);
295
-	}
296
-
297
-	/**
298
-	 * get all enabled apps
299
-	 */
300
-	protected static $enabledAppsCache = array();
301
-
302
-	/**
303
-	 * Returns apps enabled for the current user.
304
-	 *
305
-	 * @param bool $forceRefresh whether to refresh the cache
306
-	 * @param bool $all whether to return apps for all users, not only the
307
-	 * currently logged in one
308
-	 * @return string[]
309
-	 */
310
-	public static function getEnabledApps($forceRefresh = false, $all = false) {
311
-		if (!\OC::$server->getSystemConfig()->getValue('installed', false)) {
312
-			return array();
313
-		}
314
-		// in incognito mode or when logged out, $user will be false,
315
-		// which is also the case during an upgrade
316
-		$appManager = \OC::$server->getAppManager();
317
-		if ($all) {
318
-			$user = null;
319
-		} else {
320
-			$user = \OC::$server->getUserSession()->getUser();
321
-		}
322
-
323
-		if (is_null($user)) {
324
-			$apps = $appManager->getInstalledApps();
325
-		} else {
326
-			$apps = $appManager->getEnabledAppsForUser($user);
327
-		}
328
-		$apps = array_filter($apps, function ($app) {
329
-			return $app !== 'files';//we add this manually
330
-		});
331
-		sort($apps);
332
-		array_unshift($apps, 'files');
333
-		return $apps;
334
-	}
335
-
336
-	/**
337
-	 * checks whether or not an app is enabled
338
-	 *
339
-	 * @param string $app app
340
-	 * @return bool
341
-	 *
342
-	 * This function checks whether or not an app is enabled.
343
-	 */
344
-	public static function isEnabled($app) {
345
-		return \OC::$server->getAppManager()->isEnabledForUser($app);
346
-	}
347
-
348
-	/**
349
-	 * enables an app
350
-	 *
351
-	 * @param string $appId
352
-	 * @param array $groups (optional) when set, only these groups will have access to the app
353
-	 * @throws \Exception
354
-	 * @return void
355
-	 *
356
-	 * This function set an app as enabled in appconfig.
357
-	 */
358
-	public function enable($appId,
359
-						   $groups = null) {
360
-		self::$enabledAppsCache = []; // flush
361
-		$l = \OC::$server->getL10N('core');
362
-		$config = \OC::$server->getConfig();
363
-
364
-		// Check if app is already downloaded
365
-		$installer = new Installer(
366
-			\OC::$server->getAppFetcher(),
367
-			\OC::$server->getHTTPClientService(),
368
-			\OC::$server->getTempManager(),
369
-			\OC::$server->getLogger()
370
-		);
371
-		$isDownloaded = $installer->isDownloaded($appId);
372
-
373
-		if(!$isDownloaded) {
374
-			$installer->downloadApp($appId);
375
-		}
376
-
377
-		if (!Installer::isInstalled($appId)) {
378
-			$appId = self::installApp(
379
-				$appId,
380
-				$config,
381
-				$l
382
-			);
383
-			$appPath = self::getAppPath($appId);
384
-			self::registerAutoloading($appId, $appPath);
385
-			$installer->installApp($appId);
386
-		} else {
387
-			// check for required dependencies
388
-			$info = self::getAppInfo($appId);
389
-			self::checkAppDependencies($config, $l, $info);
390
-			$appPath = self::getAppPath($appId);
391
-			self::registerAutoloading($appId, $appPath);
392
-			$installer->installApp($appId);
393
-		}
394
-
395
-		$appManager = \OC::$server->getAppManager();
396
-		if (!is_null($groups)) {
397
-			$groupManager = \OC::$server->getGroupManager();
398
-			$groupsList = [];
399
-			foreach ($groups as $group) {
400
-				$groupItem = $groupManager->get($group);
401
-				if ($groupItem instanceof \OCP\IGroup) {
402
-					$groupsList[] = $groupManager->get($group);
403
-				}
404
-			}
405
-			$appManager->enableAppForGroups($appId, $groupsList);
406
-		} else {
407
-			$appManager->enableApp($appId);
408
-		}
409
-
410
-		$info = self::getAppInfo($appId);
411
-		if(isset($info['settings']) && is_array($info['settings'])) {
412
-			$appPath = self::getAppPath($appId);
413
-			self::registerAutoloading($appId, $appPath);
414
-			\OC::$server->getSettingsManager()->setupSettings($info['settings']);
415
-		}
416
-	}
417
-
418
-	/**
419
-	 * @param string $app
420
-	 * @return bool
421
-	 */
422
-	public static function removeApp($app) {
423
-		if (self::isShipped($app)) {
424
-			return false;
425
-		}
426
-
427
-		$installer = new Installer(
428
-			\OC::$server->getAppFetcher(),
429
-			\OC::$server->getHTTPClientService(),
430
-			\OC::$server->getTempManager(),
431
-			\OC::$server->getLogger()
432
-		);
433
-		return $installer->removeApp($app);
434
-	}
435
-
436
-	/**
437
-	 * This function set an app as disabled in appconfig.
438
-	 *
439
-	 * @param string $app app
440
-	 * @throws Exception
441
-	 */
442
-	public static function disable($app) {
443
-		// flush
444
-		self::$enabledAppsCache = array();
445
-
446
-		// run uninstall steps
447
-		$appData = OC_App::getAppInfo($app);
448
-		if (!is_null($appData)) {
449
-			OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']);
450
-		}
451
-
452
-		// emit disable hook - needed anymore ?
453
-		\OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app));
454
-
455
-		// finally disable it
456
-		$appManager = \OC::$server->getAppManager();
457
-		$appManager->disableApp($app);
458
-	}
459
-
460
-	/**
461
-	 * Returns the Settings Navigation
462
-	 *
463
-	 * @return string[]
464
-	 *
465
-	 * This function returns an array containing all settings pages added. The
466
-	 * entries are sorted by the key 'order' ascending.
467
-	 */
468
-	public static function getSettingsNavigation() {
469
-		$l = \OC::$server->getL10N('lib');
470
-		$urlGenerator = \OC::$server->getURLGenerator();
471
-
472
-		$settings = array();
473
-		// by default, settings only contain the help menu
474
-		if (\OC::$server->getSystemConfig()->getValue('knowledgebaseenabled', true)) {
475
-			$settings = array(
476
-				array(
477
-					"id" => "help",
478
-					"order" => 4,
479
-					"href" => $urlGenerator->linkToRoute('settings_help'),
480
-					"name" => $l->t("Help"),
481
-					"icon" => $urlGenerator->imagePath("settings", "help.svg")
482
-				)
483
-			);
484
-		}
485
-
486
-		// if the user is logged-in
487
-		if (\OC::$server->getUserSession()->isLoggedIn()) {
488
-			// personal menu
489
-			$settings[] = array(
490
-				"id" => "personal",
491
-				"order" => 1,
492
-				"href" => $urlGenerator->linkToRoute('settings_personal'),
493
-				"name" => $l->t("Personal"),
494
-				"icon" => $urlGenerator->imagePath("settings", "personal.svg")
495
-			);
496
-
497
-			//SubAdmins are also allowed to access user management
498
-			$userObject = \OC::$server->getUserSession()->getUser();
499
-			$isSubAdmin = false;
500
-			if($userObject !== null) {
501
-				$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
502
-			}
503
-			if ($isSubAdmin) {
504
-				// admin users menu
505
-				$settings[] = array(
506
-					"id" => "core_users",
507
-					"order" => 3,
508
-					"href" => $urlGenerator->linkToRoute('settings_users'),
509
-					"name" => $l->t("Users"),
510
-					"icon" => $urlGenerator->imagePath("settings", "users.svg")
511
-				);
512
-			}
513
-
514
-			// if the user is an admin
515
-			if (OC_User::isAdminUser(OC_User::getUser())) {
516
-				// admin settings
517
-				$settings[] = array(
518
-					"id" => "admin",
519
-					"order" => 2,
520
-					"href" => $urlGenerator->linkToRoute('settings.AdminSettings.index'),
521
-					"name" => $l->t("Admin"),
522
-					"icon" => $urlGenerator->imagePath("settings", "admin.svg")
523
-				);
524
-			}
525
-		}
526
-
527
-		$navigation = self::proceedNavigation($settings);
528
-		return $navigation;
529
-	}
530
-
531
-	// This is private as well. It simply works, so don't ask for more details
532
-	private static function proceedNavigation($list) {
533
-		$headerIconCount = 8;
534
-		usort($list, function($a, $b) {
535
-			if (isset($a['order']) && isset($b['order'])) {
536
-				return ($a['order'] < $b['order']) ? -1 : 1;
537
-			} else if (isset($a['order']) || isset($b['order'])) {
538
-				return isset($a['order']) ? -1 : 1;
539
-			} else {
540
-				return ($a['name'] < $b['name']) ? -1 : 1;
541
-			}
542
-		});
543
-
544
-		$activeAppIndex = -1;
545
-		$activeApp = OC::$server->getNavigationManager()->getActiveEntry();
546
-		foreach ($list as $index => &$navEntry) {
547
-			if ($navEntry['id'] == $activeApp) {
548
-				$navEntry['active'] = true;
549
-				$activeAppIndex = $index;
550
-			} else {
551
-				$navEntry['active'] = false;
552
-			}
553
-		}
554
-		unset($navEntry);
555
-
556
-		if($activeAppIndex > ($headerIconCount-1)) {
557
-			$active = $list[$activeAppIndex];
558
-			$lastInHeader = $list[$headerIconCount-1];
559
-			$list[$headerIconCount-1] = $active;
560
-			$list[$activeAppIndex] = $lastInHeader;
561
-		}
562
-
563
-		foreach ($list as $index => &$navEntry) {
564
-			$navEntry['showInHeader'] = false;
565
-			if($index < $headerIconCount) {
566
-				$navEntry['showInHeader'] = true;
567
-			}
568
-		}
569
-
570
-
571
-
572
-		return $list;
573
-	}
574
-
575
-	public static function proceedAppNavigation($entries) {
576
-		$headerIconCount = 8;
577
-		$activeAppIndex = -1;
578
-		$list = self::proceedNavigation($entries);
579
-
580
-		$activeApp = OC::$server->getNavigationManager()->getActiveEntry();
581
-		foreach ($list as $index => &$navEntry) {
582
-			if ($navEntry['id'] == $activeApp) {
583
-				$navEntry['active'] = true;
584
-				$activeAppIndex = $index;
585
-			} else {
586
-				$navEntry['active'] = false;
587
-			}
588
-		}
589
-		// move active item to last position
590
-		if($activeAppIndex > ($headerIconCount-1)) {
591
-			$active = $list[$activeAppIndex];
592
-			$lastInHeader = $list[$headerIconCount-1];
593
-			$list[$headerIconCount-1] = $active;
594
-			$list[$activeAppIndex] = $lastInHeader;
595
-		}
596
-		$list = array_slice($list, 0, $headerIconCount);
597
-
598
-		return $list;
599
-	}
600
-
601
-	/**
602
-	 * Get the path where to install apps
603
-	 *
604
-	 * @return string|false
605
-	 */
606
-	public static function getInstallPath() {
607
-		if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) {
608
-			return false;
609
-		}
610
-
611
-		foreach (OC::$APPSROOTS as $dir) {
612
-			if (isset($dir['writable']) && $dir['writable'] === true) {
613
-				return $dir['path'];
614
-			}
615
-		}
616
-
617
-		\OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR);
618
-		return null;
619
-	}
620
-
621
-
622
-	/**
623
-	 * search for an app in all app-directories
624
-	 *
625
-	 * @param string $appId
626
-	 * @return false|string
627
-	 */
628
-	public static function findAppInDirectories($appId) {
629
-		$sanitizedAppId = self::cleanAppId($appId);
630
-		if($sanitizedAppId !== $appId) {
631
-			return false;
632
-		}
633
-		static $app_dir = array();
634
-
635
-		if (isset($app_dir[$appId])) {
636
-			return $app_dir[$appId];
637
-		}
638
-
639
-		$possibleApps = array();
640
-		foreach (OC::$APPSROOTS as $dir) {
641
-			if (file_exists($dir['path'] . '/' . $appId)) {
642
-				$possibleApps[] = $dir;
643
-			}
644
-		}
645
-
646
-		if (empty($possibleApps)) {
647
-			return false;
648
-		} elseif (count($possibleApps) === 1) {
649
-			$dir = array_shift($possibleApps);
650
-			$app_dir[$appId] = $dir;
651
-			return $dir;
652
-		} else {
653
-			$versionToLoad = array();
654
-			foreach ($possibleApps as $possibleApp) {
655
-				$version = self::getAppVersionByPath($possibleApp['path']);
656
-				if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) {
657
-					$versionToLoad = array(
658
-						'dir' => $possibleApp,
659
-						'version' => $version,
660
-					);
661
-				}
662
-			}
663
-			$app_dir[$appId] = $versionToLoad['dir'];
664
-			return $versionToLoad['dir'];
665
-			//TODO - write test
666
-		}
667
-	}
668
-
669
-	/**
670
-	 * Get the directory for the given app.
671
-	 * If the app is defined in multiple directories, the first one is taken. (false if not found)
672
-	 *
673
-	 * @param string $appId
674
-	 * @return string|false
675
-	 */
676
-	public static function getAppPath($appId) {
677
-		if ($appId === null || trim($appId) === '') {
678
-			return false;
679
-		}
680
-
681
-		if (($dir = self::findAppInDirectories($appId)) != false) {
682
-			return $dir['path'] . '/' . $appId;
683
-		}
684
-		return false;
685
-	}
686
-
687
-	/**
688
-	 * Get the path for the given app on the access
689
-	 * If the app is defined in multiple directories, the first one is taken. (false if not found)
690
-	 *
691
-	 * @param string $appId
692
-	 * @return string|false
693
-	 */
694
-	public static function getAppWebPath($appId) {
695
-		if (($dir = self::findAppInDirectories($appId)) != false) {
696
-			return OC::$WEBROOT . $dir['url'] . '/' . $appId;
697
-		}
698
-		return false;
699
-	}
700
-
701
-	/**
702
-	 * get the last version of the app from appinfo/info.xml
703
-	 *
704
-	 * @param string $appId
705
-	 * @param bool $useCache
706
-	 * @return string
707
-	 */
708
-	public static function getAppVersion($appId, $useCache = true) {
709
-		if($useCache && isset(self::$appVersion[$appId])) {
710
-			return self::$appVersion[$appId];
711
-		}
712
-
713
-		$file = self::getAppPath($appId);
714
-		self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0';
715
-		return self::$appVersion[$appId];
716
-	}
717
-
718
-	/**
719
-	 * get app's version based on it's path
720
-	 *
721
-	 * @param string $path
722
-	 * @return string
723
-	 */
724
-	public static function getAppVersionByPath($path) {
725
-		$infoFile = $path . '/appinfo/info.xml';
726
-		$appData = self::getAppInfo($infoFile, true);
727
-		return isset($appData['version']) ? $appData['version'] : '';
728
-	}
729
-
730
-
731
-	/**
732
-	 * Read all app metadata from the info.xml file
733
-	 *
734
-	 * @param string $appId id of the app or the path of the info.xml file
735
-	 * @param bool $path
736
-	 * @param string $lang
737
-	 * @return array|null
738
-	 * @note all data is read from info.xml, not just pre-defined fields
739
-	 */
740
-	public static function getAppInfo($appId, $path = false, $lang = null) {
741
-		if ($path) {
742
-			$file = $appId;
743
-		} else {
744
-			if ($lang === null && isset(self::$appInfo[$appId])) {
745
-				return self::$appInfo[$appId];
746
-			}
747
-			$appPath = self::getAppPath($appId);
748
-			if($appPath === false) {
749
-				return null;
750
-			}
751
-			$file = $appPath . '/appinfo/info.xml';
752
-		}
753
-
754
-		$parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo'));
755
-		$data = $parser->parse($file);
756
-
757
-		if (is_array($data)) {
758
-			$data = OC_App::parseAppInfo($data, $lang);
759
-		}
760
-		if(isset($data['ocsid'])) {
761
-			$storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid');
762
-			if($storedId !== '' && $storedId !== $data['ocsid']) {
763
-				$data['ocsid'] = $storedId;
764
-			}
765
-		}
766
-
767
-		if ($lang === null) {
768
-			self::$appInfo[$appId] = $data;
769
-		}
770
-
771
-		return $data;
772
-	}
773
-
774
-	/**
775
-	 * Returns the navigation
776
-	 *
777
-	 * @return array
778
-	 *
779
-	 * This function returns an array containing all entries added. The
780
-	 * entries are sorted by the key 'order' ascending. Additional to the keys
781
-	 * given for each app the following keys exist:
782
-	 *   - active: boolean, signals if the user is on this navigation entry
783
-	 */
784
-	public static function getNavigation() {
785
-		$entries = OC::$server->getNavigationManager()->getAll();
786
-		$navigation = self::proceedNavigation($entries);
787
-		return $navigation;
788
-	}
789
-
790
-	/**
791
-	 * Returns the navigation inside the header bar
792
-	 *
793
-	 * @return array
794
-	 *
795
-	 * This function returns an array containing all entries added. The
796
-	 * entries are sorted by the key 'order' ascending. Additional to the keys
797
-	 * given for each app the following keys exist:
798
-	 *   - active: boolean, signals if the user is on this navigation entry
799
-	 */
800
-	public static function getHeaderNavigation() {
801
-		$entries = OC::$server->getNavigationManager()->getAll();
802
-		$navigation = self::proceedAppNavigation($entries);
803
-		return $navigation;
804
-	}
805
-
806
-	/**
807
-	 * get the id of loaded app
808
-	 *
809
-	 * @return string
810
-	 */
811
-	public static function getCurrentApp() {
812
-		$request = \OC::$server->getRequest();
813
-		$script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1);
814
-		$topFolder = substr($script, 0, strpos($script, '/'));
815
-		if (empty($topFolder)) {
816
-			$path_info = $request->getPathInfo();
817
-			if ($path_info) {
818
-				$topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
819
-			}
820
-		}
821
-		if ($topFolder == 'apps') {
822
-			$length = strlen($topFolder);
823
-			return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1);
824
-		} else {
825
-			return $topFolder;
826
-		}
827
-	}
828
-
829
-	/**
830
-	 * @param string $type
831
-	 * @return array
832
-	 */
833
-	public static function getForms($type) {
834
-		$forms = array();
835
-		switch ($type) {
836
-			case 'admin':
837
-				$source = self::$adminForms;
838
-				break;
839
-			case 'personal':
840
-				$source = self::$personalForms;
841
-				break;
842
-			default:
843
-				return array();
844
-		}
845
-		foreach ($source as $form) {
846
-			$forms[] = include $form;
847
-		}
848
-		return $forms;
849
-	}
850
-
851
-	/**
852
-	 * register an admin form to be shown
853
-	 *
854
-	 * @param string $app
855
-	 * @param string $page
856
-	 */
857
-	public static function registerAdmin($app, $page) {
858
-		self::$adminForms[] = $app . '/' . $page . '.php';
859
-	}
860
-
861
-	/**
862
-	 * register a personal form to be shown
863
-	 * @param string $app
864
-	 * @param string $page
865
-	 */
866
-	public static function registerPersonal($app, $page) {
867
-		self::$personalForms[] = $app . '/' . $page . '.php';
868
-	}
869
-
870
-	/**
871
-	 * @param array $entry
872
-	 */
873
-	public static function registerLogIn(array $entry) {
874
-		self::$altLogin[] = $entry;
875
-	}
876
-
877
-	/**
878
-	 * @return array
879
-	 */
880
-	public static function getAlternativeLogIns() {
881
-		return self::$altLogin;
882
-	}
883
-
884
-	/**
885
-	 * get a list of all apps in the apps folder
886
-	 *
887
-	 * @return array an array of app names (string IDs)
888
-	 * @todo: change the name of this method to getInstalledApps, which is more accurate
889
-	 */
890
-	public static function getAllApps() {
891
-
892
-		$apps = array();
893
-
894
-		foreach (OC::$APPSROOTS as $apps_dir) {
895
-			if (!is_readable($apps_dir['path'])) {
896
-				\OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN);
897
-				continue;
898
-			}
899
-			$dh = opendir($apps_dir['path']);
900
-
901
-			if (is_resource($dh)) {
902
-				while (($file = readdir($dh)) !== false) {
903
-
904
-					if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
905
-
906
-						$apps[] = $file;
907
-					}
908
-				}
909
-			}
910
-		}
911
-
912
-		return $apps;
913
-	}
914
-
915
-	/**
916
-	 * List all apps, this is used in apps.php
917
-	 *
918
-	 * @return array
919
-	 */
920
-	public function listAllApps() {
921
-		$installedApps = OC_App::getAllApps();
922
-
923
-		//we don't want to show configuration for these
924
-		$blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
925
-		$appList = array();
926
-		$langCode = \OC::$server->getL10N('core')->getLanguageCode();
927
-		$urlGenerator = \OC::$server->getURLGenerator();
928
-
929
-		foreach ($installedApps as $app) {
930
-			if (array_search($app, $blacklist) === false) {
931
-
932
-				$info = OC_App::getAppInfo($app, false, $langCode);
933
-				if (!is_array($info)) {
934
-					\OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR);
935
-					continue;
936
-				}
937
-
938
-				if (!isset($info['name'])) {
939
-					\OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR);
940
-					continue;
941
-				}
942
-
943
-				$enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no');
944
-				$info['groups'] = null;
945
-				if ($enabled === 'yes') {
946
-					$active = true;
947
-				} else if ($enabled === 'no') {
948
-					$active = false;
949
-				} else {
950
-					$active = true;
951
-					$info['groups'] = $enabled;
952
-				}
953
-
954
-				$info['active'] = $active;
955
-
956
-				if (self::isShipped($app)) {
957
-					$info['internal'] = true;
958
-					$info['level'] = self::officialApp;
959
-					$info['removable'] = false;
960
-				} else {
961
-					$info['internal'] = false;
962
-					$info['removable'] = true;
963
-				}
964
-
965
-				$appPath = self::getAppPath($app);
966
-				if($appPath !== false) {
967
-					$appIcon = $appPath . '/img/' . $app . '.svg';
968
-					if (file_exists($appIcon)) {
969
-						$info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg');
970
-						$info['previewAsIcon'] = true;
971
-					} else {
972
-						$appIcon = $appPath . '/img/app.svg';
973
-						if (file_exists($appIcon)) {
974
-							$info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg');
975
-							$info['previewAsIcon'] = true;
976
-						}
977
-					}
978
-				}
979
-				// fix documentation
980
-				if (isset($info['documentation']) && is_array($info['documentation'])) {
981
-					foreach ($info['documentation'] as $key => $url) {
982
-						// If it is not an absolute URL we assume it is a key
983
-						// i.e. admin-ldap will get converted to go.php?to=admin-ldap
984
-						if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) {
985
-							$url = $urlGenerator->linkToDocs($url);
986
-						}
987
-
988
-						$info['documentation'][$key] = $url;
989
-					}
990
-				}
991
-
992
-				$info['version'] = OC_App::getAppVersion($app);
993
-				$appList[] = $info;
994
-			}
995
-		}
996
-
997
-		return $appList;
998
-	}
999
-
1000
-	/**
1001
-	 * Returns the internal app ID or false
1002
-	 * @param string $ocsID
1003
-	 * @return string|false
1004
-	 */
1005
-	public static function getInternalAppIdByOcs($ocsID) {
1006
-		if(is_numeric($ocsID)) {
1007
-			$idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid');
1008
-			if(array_search($ocsID, $idArray)) {
1009
-				return array_search($ocsID, $idArray);
1010
-			}
1011
-		}
1012
-		return false;
1013
-	}
1014
-
1015
-	public static function shouldUpgrade($app) {
1016
-		$versions = self::getAppVersions();
1017
-		$currentVersion = OC_App::getAppVersion($app);
1018
-		if ($currentVersion && isset($versions[$app])) {
1019
-			$installedVersion = $versions[$app];
1020
-			if (!version_compare($currentVersion, $installedVersion, '=')) {
1021
-				return true;
1022
-			}
1023
-		}
1024
-		return false;
1025
-	}
1026
-
1027
-	/**
1028
-	 * Adjust the number of version parts of $version1 to match
1029
-	 * the number of version parts of $version2.
1030
-	 *
1031
-	 * @param string $version1 version to adjust
1032
-	 * @param string $version2 version to take the number of parts from
1033
-	 * @return string shortened $version1
1034
-	 */
1035
-	private static function adjustVersionParts($version1, $version2) {
1036
-		$version1 = explode('.', $version1);
1037
-		$version2 = explode('.', $version2);
1038
-		// reduce $version1 to match the number of parts in $version2
1039
-		while (count($version1) > count($version2)) {
1040
-			array_pop($version1);
1041
-		}
1042
-		// if $version1 does not have enough parts, add some
1043
-		while (count($version1) < count($version2)) {
1044
-			$version1[] = '0';
1045
-		}
1046
-		return implode('.', $version1);
1047
-	}
1048
-
1049
-	/**
1050
-	 * Check whether the current ownCloud version matches the given
1051
-	 * application's version requirements.
1052
-	 *
1053
-	 * The comparison is made based on the number of parts that the
1054
-	 * app info version has. For example for ownCloud 6.0.3 if the
1055
-	 * app info version is expecting version 6.0, the comparison is
1056
-	 * made on the first two parts of the ownCloud version.
1057
-	 * This means that it's possible to specify "requiremin" => 6
1058
-	 * and "requiremax" => 6 and it will still match ownCloud 6.0.3.
1059
-	 *
1060
-	 * @param string $ocVersion ownCloud version to check against
1061
-	 * @param array $appInfo app info (from xml)
1062
-	 *
1063
-	 * @return boolean true if compatible, otherwise false
1064
-	 */
1065
-	public static function isAppCompatible($ocVersion, $appInfo) {
1066
-		$requireMin = '';
1067
-		$requireMax = '';
1068
-		if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) {
1069
-			$requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version'];
1070
-		} elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) {
1071
-			$requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version'];
1072
-		} else if (isset($appInfo['requiremin'])) {
1073
-			$requireMin = $appInfo['requiremin'];
1074
-		} else if (isset($appInfo['require'])) {
1075
-			$requireMin = $appInfo['require'];
1076
-		}
1077
-
1078
-		if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) {
1079
-			$requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version'];
1080
-		} elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) {
1081
-			$requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version'];
1082
-		} else if (isset($appInfo['requiremax'])) {
1083
-			$requireMax = $appInfo['requiremax'];
1084
-		}
1085
-
1086
-		if (is_array($ocVersion)) {
1087
-			$ocVersion = implode('.', $ocVersion);
1088
-		}
1089
-
1090
-		if (!empty($requireMin)
1091
-			&& version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<')
1092
-		) {
1093
-
1094
-			return false;
1095
-		}
1096
-
1097
-		if (!empty($requireMax)
1098
-			&& version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>')
1099
-		) {
1100
-			return false;
1101
-		}
1102
-
1103
-		return true;
1104
-	}
1105
-
1106
-	/**
1107
-	 * get the installed version of all apps
1108
-	 */
1109
-	public static function getAppVersions() {
1110
-		static $versions;
1111
-
1112
-		if(!$versions) {
1113
-			$appConfig = \OC::$server->getAppConfig();
1114
-			$versions = $appConfig->getValues(false, 'installed_version');
1115
-		}
1116
-		return $versions;
1117
-	}
1118
-
1119
-	/**
1120
-	 * @param string $app
1121
-	 * @param \OCP\IConfig $config
1122
-	 * @param \OCP\IL10N $l
1123
-	 * @return bool
1124
-	 *
1125
-	 * @throws Exception if app is not compatible with this version of ownCloud
1126
-	 * @throws Exception if no app-name was specified
1127
-	 */
1128
-	public function installApp($app,
1129
-							   \OCP\IConfig $config,
1130
-							   \OCP\IL10N $l) {
1131
-		if ($app !== false) {
1132
-			// check if the app is compatible with this version of ownCloud
1133
-			$info = self::getAppInfo($app);
1134
-			if(!is_array($info)) {
1135
-				throw new \Exception(
1136
-					$l->t('App "%s" cannot be installed because appinfo file cannot be read.',
1137
-						[$info['name']]
1138
-					)
1139
-				);
1140
-			}
1141
-
1142
-			$version = \OCP\Util::getVersion();
1143
-			if (!self::isAppCompatible($version, $info)) {
1144
-				throw new \Exception(
1145
-					$l->t('App "%s" cannot be installed because it is not compatible with this version of the server.',
1146
-						array($info['name'])
1147
-					)
1148
-				);
1149
-			}
1150
-
1151
-			// check for required dependencies
1152
-			self::checkAppDependencies($config, $l, $info);
1153
-
1154
-			$config->setAppValue($app, 'enabled', 'yes');
1155
-			if (isset($appData['id'])) {
1156
-				$config->setAppValue($app, 'ocsid', $appData['id']);
1157
-			}
1158
-
1159
-			if(isset($info['settings']) && is_array($info['settings'])) {
1160
-				$appPath = self::getAppPath($app);
1161
-				self::registerAutoloading($app, $appPath);
1162
-				\OC::$server->getSettingsManager()->setupSettings($info['settings']);
1163
-			}
1164
-
1165
-			\OC_Hook::emit('OC_App', 'post_enable', array('app' => $app));
1166
-		} else {
1167
-			if(empty($appName) ) {
1168
-				throw new \Exception($l->t("No app name specified"));
1169
-			} else {
1170
-				throw new \Exception($l->t("App '%s' could not be installed!", $appName));
1171
-			}
1172
-		}
1173
-
1174
-		return $app;
1175
-	}
1176
-
1177
-	/**
1178
-	 * update the database for the app and call the update script
1179
-	 *
1180
-	 * @param string $appId
1181
-	 * @return bool
1182
-	 */
1183
-	public static function updateApp($appId) {
1184
-		$appPath = self::getAppPath($appId);
1185
-		if($appPath === false) {
1186
-			return false;
1187
-		}
1188
-		$appData = self::getAppInfo($appId);
1189
-		self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
1190
-		if (file_exists($appPath . '/appinfo/database.xml')) {
1191
-			OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
1192
-		}
1193
-		self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
1194
-		self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
1195
-		unset(self::$appVersion[$appId]);
1196
-		// run upgrade code
1197
-		if (file_exists($appPath . '/appinfo/update.php')) {
1198
-			self::loadApp($appId);
1199
-			include $appPath . '/appinfo/update.php';
1200
-		}
1201
-		self::setupBackgroundJobs($appData['background-jobs']);
1202
-		if(isset($appData['settings']) && is_array($appData['settings'])) {
1203
-			$appPath = self::getAppPath($appId);
1204
-			self::registerAutoloading($appId, $appPath);
1205
-			\OC::$server->getSettingsManager()->setupSettings($appData['settings']);
1206
-		}
1207
-
1208
-		//set remote/public handlers
1209
-		if (array_key_exists('ocsid', $appData)) {
1210
-			\OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
1211
-		} elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
1212
-			\OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
1213
-		}
1214
-		foreach ($appData['remote'] as $name => $path) {
1215
-			\OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
1216
-		}
1217
-		foreach ($appData['public'] as $name => $path) {
1218
-			\OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
1219
-		}
1220
-
1221
-		self::setAppTypes($appId);
1222
-
1223
-		$version = \OC_App::getAppVersion($appId);
1224
-		\OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version);
1225
-
1226
-		\OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent(
1227
-			ManagerEvent::EVENT_APP_UPDATE, $appId
1228
-		));
1229
-
1230
-		return true;
1231
-	}
1232
-
1233
-	/**
1234
-	 * @param string $appId
1235
-	 * @param string[] $steps
1236
-	 * @throws \OC\NeedsUpdateException
1237
-	 */
1238
-	public static function executeRepairSteps($appId, array $steps) {
1239
-		if (empty($steps)) {
1240
-			return;
1241
-		}
1242
-		// load the app
1243
-		self::loadApp($appId);
1244
-
1245
-		$dispatcher = OC::$server->getEventDispatcher();
1246
-
1247
-		// load the steps
1248
-		$r = new Repair([], $dispatcher);
1249
-		foreach ($steps as $step) {
1250
-			try {
1251
-				$r->addStep($step);
1252
-			} catch (Exception $ex) {
1253
-				$r->emit('\OC\Repair', 'error', [$ex->getMessage()]);
1254
-				\OC::$server->getLogger()->logException($ex);
1255
-			}
1256
-		}
1257
-		// run the steps
1258
-		$r->run();
1259
-	}
1260
-
1261
-	public static function setupBackgroundJobs(array $jobs) {
1262
-		$queue = \OC::$server->getJobList();
1263
-		foreach ($jobs as $job) {
1264
-			$queue->add($job);
1265
-		}
1266
-	}
1267
-
1268
-	/**
1269
-	 * @param string $appId
1270
-	 * @param string[] $steps
1271
-	 */
1272
-	private static function setupLiveMigrations($appId, array $steps) {
1273
-		$queue = \OC::$server->getJobList();
1274
-		foreach ($steps as $step) {
1275
-			$queue->add('OC\Migration\BackgroundRepair', [
1276
-				'app' => $appId,
1277
-				'step' => $step]);
1278
-		}
1279
-	}
1280
-
1281
-	/**
1282
-	 * @param string $appId
1283
-	 * @return \OC\Files\View|false
1284
-	 */
1285
-	public static function getStorage($appId) {
1286
-		if (OC_App::isEnabled($appId)) { //sanity check
1287
-			if (\OC::$server->getUserSession()->isLoggedIn()) {
1288
-				$view = new \OC\Files\View('/' . OC_User::getUser());
1289
-				if (!$view->file_exists($appId)) {
1290
-					$view->mkdir($appId);
1291
-				}
1292
-				return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1293
-			} else {
1294
-				\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR);
1295
-				return false;
1296
-			}
1297
-		} else {
1298
-			\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR);
1299
-			return false;
1300
-		}
1301
-	}
1302
-
1303
-	protected static function findBestL10NOption($options, $lang) {
1304
-		$fallback = $similarLangFallback = $englishFallback = false;
1305
-
1306
-		$lang = strtolower($lang);
1307
-		$similarLang = $lang;
1308
-		if (strpos($similarLang, '_')) {
1309
-			// For "de_DE" we want to find "de" and the other way around
1310
-			$similarLang = substr($lang, 0, strpos($lang, '_'));
1311
-		}
1312
-
1313
-		foreach ($options as $option) {
1314
-			if (is_array($option)) {
1315
-				if ($fallback === false) {
1316
-					$fallback = $option['@value'];
1317
-				}
1318
-
1319
-				if (!isset($option['@attributes']['lang'])) {
1320
-					continue;
1321
-				}
1322
-
1323
-				$attributeLang = strtolower($option['@attributes']['lang']);
1324
-				if ($attributeLang === $lang) {
1325
-					return $option['@value'];
1326
-				}
1327
-
1328
-				if ($attributeLang === $similarLang) {
1329
-					$similarLangFallback = $option['@value'];
1330
-				} else if (strpos($attributeLang, $similarLang . '_') === 0) {
1331
-					if ($similarLangFallback === false) {
1332
-						$similarLangFallback =  $option['@value'];
1333
-					}
1334
-				}
1335
-			} else {
1336
-				$englishFallback = $option;
1337
-			}
1338
-		}
1339
-
1340
-		if ($similarLangFallback !== false) {
1341
-			return $similarLangFallback;
1342
-		} else if ($englishFallback !== false) {
1343
-			return $englishFallback;
1344
-		}
1345
-		return (string) $fallback;
1346
-	}
1347
-
1348
-	/**
1349
-	 * parses the app data array and enhanced the 'description' value
1350
-	 *
1351
-	 * @param array $data the app data
1352
-	 * @param string $lang
1353
-	 * @return array improved app data
1354
-	 */
1355
-	public static function parseAppInfo(array $data, $lang = null) {
1356
-
1357
-		if ($lang && isset($data['name']) && is_array($data['name'])) {
1358
-			$data['name'] = self::findBestL10NOption($data['name'], $lang);
1359
-		}
1360
-		if ($lang && isset($data['summary']) && is_array($data['summary'])) {
1361
-			$data['summary'] = self::findBestL10NOption($data['summary'], $lang);
1362
-		}
1363
-		if ($lang && isset($data['description']) && is_array($data['description'])) {
1364
-			$data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1365
-		} else if (isset($data['description']) && is_string($data['description'])) {
1366
-			$data['description'] = trim($data['description']);
1367
-		} else  {
1368
-			$data['description'] = '';
1369
-		}
1370
-
1371
-		return $data;
1372
-	}
1373
-
1374
-	/**
1375
-	 * @param \OCP\IConfig $config
1376
-	 * @param \OCP\IL10N $l
1377
-	 * @param array $info
1378
-	 * @throws \Exception
1379
-	 */
1380
-	protected static function checkAppDependencies($config, $l, $info) {
1381
-		$dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
1382
-		$missing = $dependencyAnalyzer->analyze($info);
1383
-		if (!empty($missing)) {
1384
-			$missingMsg = join(PHP_EOL, $missing);
1385
-			throw new \Exception(
1386
-				$l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s',
1387
-					[$info['name'], $missingMsg]
1388
-				)
1389
-			);
1390
-		}
1391
-	}
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
+    }
178
+
179
+    /**
180
+     * @internal
181
+     * @param string $app
182
+     * @param string $path
183
+     */
184
+    public static function registerAutoloading($app, $path) {
185
+        $key = $app . '-' . $path;
186
+        if(isset(self::$alreadyRegistered[$key])) {
187
+            return;
188
+        }
189
+        self::$alreadyRegistered[$key] = true;
190
+        // Register on PSR-4 composer autoloader
191
+        $appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
192
+        \OC::$server->registerNamespace($app, $appNamespace);
193
+        \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
194
+        if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
195
+            \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
196
+        }
197
+
198
+        // Register on legacy autoloader
199
+        \OC::$loader->addValidRoot($path);
200
+    }
201
+
202
+    /**
203
+     * Load app.php from the given app
204
+     *
205
+     * @param string $app app name
206
+     */
207
+    private static function requireAppFile($app) {
208
+        try {
209
+            // encapsulated here to avoid variable scope conflicts
210
+            require_once $app . '/appinfo/app.php';
211
+        } catch (Error $ex) {
212
+            \OC::$server->getLogger()->logException($ex);
213
+            $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
214
+            if (!in_array($app, $blacklist)) {
215
+                self::disable($app);
216
+            }
217
+        }
218
+    }
219
+
220
+    /**
221
+     * check if an app is of a specific type
222
+     *
223
+     * @param string $app
224
+     * @param string|array $types
225
+     * @return bool
226
+     */
227
+    public static function isType($app, $types) {
228
+        if (is_string($types)) {
229
+            $types = array($types);
230
+        }
231
+        $appTypes = self::getAppTypes($app);
232
+        foreach ($types as $type) {
233
+            if (array_search($type, $appTypes) !== false) {
234
+                return true;
235
+            }
236
+        }
237
+        return false;
238
+    }
239
+
240
+    /**
241
+     * get the types of an app
242
+     *
243
+     * @param string $app
244
+     * @return array
245
+     */
246
+    private static function getAppTypes($app) {
247
+        //load the cache
248
+        if (count(self::$appTypes) == 0) {
249
+            self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types');
250
+        }
251
+
252
+        if (isset(self::$appTypes[$app])) {
253
+            return explode(',', self::$appTypes[$app]);
254
+        } else {
255
+            return array();
256
+        }
257
+    }
258
+
259
+    /**
260
+     * read app types from info.xml and cache them in the database
261
+     */
262
+    public static function setAppTypes($app) {
263
+        $appData = self::getAppInfo($app);
264
+        if(!is_array($appData)) {
265
+            return;
266
+        }
267
+
268
+        if (isset($appData['types'])) {
269
+            $appTypes = implode(',', $appData['types']);
270
+        } else {
271
+            $appTypes = '';
272
+            $appData['types'] = [];
273
+        }
274
+
275
+        \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes);
276
+
277
+        if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) {
278
+            $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes');
279
+            if ($enabled !== 'yes' && $enabled !== 'no') {
280
+                \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes');
281
+            }
282
+        }
283
+    }
284
+
285
+    /**
286
+     * check if app is shipped
287
+     *
288
+     * @param string $appId the id of the app to check
289
+     * @return bool
290
+     *
291
+     * Check if an app that is installed is a shipped app or installed from the appstore.
292
+     */
293
+    public static function isShipped($appId) {
294
+        return \OC::$server->getAppManager()->isShipped($appId);
295
+    }
296
+
297
+    /**
298
+     * get all enabled apps
299
+     */
300
+    protected static $enabledAppsCache = array();
301
+
302
+    /**
303
+     * Returns apps enabled for the current user.
304
+     *
305
+     * @param bool $forceRefresh whether to refresh the cache
306
+     * @param bool $all whether to return apps for all users, not only the
307
+     * currently logged in one
308
+     * @return string[]
309
+     */
310
+    public static function getEnabledApps($forceRefresh = false, $all = false) {
311
+        if (!\OC::$server->getSystemConfig()->getValue('installed', false)) {
312
+            return array();
313
+        }
314
+        // in incognito mode or when logged out, $user will be false,
315
+        // which is also the case during an upgrade
316
+        $appManager = \OC::$server->getAppManager();
317
+        if ($all) {
318
+            $user = null;
319
+        } else {
320
+            $user = \OC::$server->getUserSession()->getUser();
321
+        }
322
+
323
+        if (is_null($user)) {
324
+            $apps = $appManager->getInstalledApps();
325
+        } else {
326
+            $apps = $appManager->getEnabledAppsForUser($user);
327
+        }
328
+        $apps = array_filter($apps, function ($app) {
329
+            return $app !== 'files';//we add this manually
330
+        });
331
+        sort($apps);
332
+        array_unshift($apps, 'files');
333
+        return $apps;
334
+    }
335
+
336
+    /**
337
+     * checks whether or not an app is enabled
338
+     *
339
+     * @param string $app app
340
+     * @return bool
341
+     *
342
+     * This function checks whether or not an app is enabled.
343
+     */
344
+    public static function isEnabled($app) {
345
+        return \OC::$server->getAppManager()->isEnabledForUser($app);
346
+    }
347
+
348
+    /**
349
+     * enables an app
350
+     *
351
+     * @param string $appId
352
+     * @param array $groups (optional) when set, only these groups will have access to the app
353
+     * @throws \Exception
354
+     * @return void
355
+     *
356
+     * This function set an app as enabled in appconfig.
357
+     */
358
+    public function enable($appId,
359
+                            $groups = null) {
360
+        self::$enabledAppsCache = []; // flush
361
+        $l = \OC::$server->getL10N('core');
362
+        $config = \OC::$server->getConfig();
363
+
364
+        // Check if app is already downloaded
365
+        $installer = new Installer(
366
+            \OC::$server->getAppFetcher(),
367
+            \OC::$server->getHTTPClientService(),
368
+            \OC::$server->getTempManager(),
369
+            \OC::$server->getLogger()
370
+        );
371
+        $isDownloaded = $installer->isDownloaded($appId);
372
+
373
+        if(!$isDownloaded) {
374
+            $installer->downloadApp($appId);
375
+        }
376
+
377
+        if (!Installer::isInstalled($appId)) {
378
+            $appId = self::installApp(
379
+                $appId,
380
+                $config,
381
+                $l
382
+            );
383
+            $appPath = self::getAppPath($appId);
384
+            self::registerAutoloading($appId, $appPath);
385
+            $installer->installApp($appId);
386
+        } else {
387
+            // check for required dependencies
388
+            $info = self::getAppInfo($appId);
389
+            self::checkAppDependencies($config, $l, $info);
390
+            $appPath = self::getAppPath($appId);
391
+            self::registerAutoloading($appId, $appPath);
392
+            $installer->installApp($appId);
393
+        }
394
+
395
+        $appManager = \OC::$server->getAppManager();
396
+        if (!is_null($groups)) {
397
+            $groupManager = \OC::$server->getGroupManager();
398
+            $groupsList = [];
399
+            foreach ($groups as $group) {
400
+                $groupItem = $groupManager->get($group);
401
+                if ($groupItem instanceof \OCP\IGroup) {
402
+                    $groupsList[] = $groupManager->get($group);
403
+                }
404
+            }
405
+            $appManager->enableAppForGroups($appId, $groupsList);
406
+        } else {
407
+            $appManager->enableApp($appId);
408
+        }
409
+
410
+        $info = self::getAppInfo($appId);
411
+        if(isset($info['settings']) && is_array($info['settings'])) {
412
+            $appPath = self::getAppPath($appId);
413
+            self::registerAutoloading($appId, $appPath);
414
+            \OC::$server->getSettingsManager()->setupSettings($info['settings']);
415
+        }
416
+    }
417
+
418
+    /**
419
+     * @param string $app
420
+     * @return bool
421
+     */
422
+    public static function removeApp($app) {
423
+        if (self::isShipped($app)) {
424
+            return false;
425
+        }
426
+
427
+        $installer = new Installer(
428
+            \OC::$server->getAppFetcher(),
429
+            \OC::$server->getHTTPClientService(),
430
+            \OC::$server->getTempManager(),
431
+            \OC::$server->getLogger()
432
+        );
433
+        return $installer->removeApp($app);
434
+    }
435
+
436
+    /**
437
+     * This function set an app as disabled in appconfig.
438
+     *
439
+     * @param string $app app
440
+     * @throws Exception
441
+     */
442
+    public static function disable($app) {
443
+        // flush
444
+        self::$enabledAppsCache = array();
445
+
446
+        // run uninstall steps
447
+        $appData = OC_App::getAppInfo($app);
448
+        if (!is_null($appData)) {
449
+            OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']);
450
+        }
451
+
452
+        // emit disable hook - needed anymore ?
453
+        \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app));
454
+
455
+        // finally disable it
456
+        $appManager = \OC::$server->getAppManager();
457
+        $appManager->disableApp($app);
458
+    }
459
+
460
+    /**
461
+     * Returns the Settings Navigation
462
+     *
463
+     * @return string[]
464
+     *
465
+     * This function returns an array containing all settings pages added. The
466
+     * entries are sorted by the key 'order' ascending.
467
+     */
468
+    public static function getSettingsNavigation() {
469
+        $l = \OC::$server->getL10N('lib');
470
+        $urlGenerator = \OC::$server->getURLGenerator();
471
+
472
+        $settings = array();
473
+        // by default, settings only contain the help menu
474
+        if (\OC::$server->getSystemConfig()->getValue('knowledgebaseenabled', true)) {
475
+            $settings = array(
476
+                array(
477
+                    "id" => "help",
478
+                    "order" => 4,
479
+                    "href" => $urlGenerator->linkToRoute('settings_help'),
480
+                    "name" => $l->t("Help"),
481
+                    "icon" => $urlGenerator->imagePath("settings", "help.svg")
482
+                )
483
+            );
484
+        }
485
+
486
+        // if the user is logged-in
487
+        if (\OC::$server->getUserSession()->isLoggedIn()) {
488
+            // personal menu
489
+            $settings[] = array(
490
+                "id" => "personal",
491
+                "order" => 1,
492
+                "href" => $urlGenerator->linkToRoute('settings_personal'),
493
+                "name" => $l->t("Personal"),
494
+                "icon" => $urlGenerator->imagePath("settings", "personal.svg")
495
+            );
496
+
497
+            //SubAdmins are also allowed to access user management
498
+            $userObject = \OC::$server->getUserSession()->getUser();
499
+            $isSubAdmin = false;
500
+            if($userObject !== null) {
501
+                $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
502
+            }
503
+            if ($isSubAdmin) {
504
+                // admin users menu
505
+                $settings[] = array(
506
+                    "id" => "core_users",
507
+                    "order" => 3,
508
+                    "href" => $urlGenerator->linkToRoute('settings_users'),
509
+                    "name" => $l->t("Users"),
510
+                    "icon" => $urlGenerator->imagePath("settings", "users.svg")
511
+                );
512
+            }
513
+
514
+            // if the user is an admin
515
+            if (OC_User::isAdminUser(OC_User::getUser())) {
516
+                // admin settings
517
+                $settings[] = array(
518
+                    "id" => "admin",
519
+                    "order" => 2,
520
+                    "href" => $urlGenerator->linkToRoute('settings.AdminSettings.index'),
521
+                    "name" => $l->t("Admin"),
522
+                    "icon" => $urlGenerator->imagePath("settings", "admin.svg")
523
+                );
524
+            }
525
+        }
526
+
527
+        $navigation = self::proceedNavigation($settings);
528
+        return $navigation;
529
+    }
530
+
531
+    // This is private as well. It simply works, so don't ask for more details
532
+    private static function proceedNavigation($list) {
533
+        $headerIconCount = 8;
534
+        usort($list, function($a, $b) {
535
+            if (isset($a['order']) && isset($b['order'])) {
536
+                return ($a['order'] < $b['order']) ? -1 : 1;
537
+            } else if (isset($a['order']) || isset($b['order'])) {
538
+                return isset($a['order']) ? -1 : 1;
539
+            } else {
540
+                return ($a['name'] < $b['name']) ? -1 : 1;
541
+            }
542
+        });
543
+
544
+        $activeAppIndex = -1;
545
+        $activeApp = OC::$server->getNavigationManager()->getActiveEntry();
546
+        foreach ($list as $index => &$navEntry) {
547
+            if ($navEntry['id'] == $activeApp) {
548
+                $navEntry['active'] = true;
549
+                $activeAppIndex = $index;
550
+            } else {
551
+                $navEntry['active'] = false;
552
+            }
553
+        }
554
+        unset($navEntry);
555
+
556
+        if($activeAppIndex > ($headerIconCount-1)) {
557
+            $active = $list[$activeAppIndex];
558
+            $lastInHeader = $list[$headerIconCount-1];
559
+            $list[$headerIconCount-1] = $active;
560
+            $list[$activeAppIndex] = $lastInHeader;
561
+        }
562
+
563
+        foreach ($list as $index => &$navEntry) {
564
+            $navEntry['showInHeader'] = false;
565
+            if($index < $headerIconCount) {
566
+                $navEntry['showInHeader'] = true;
567
+            }
568
+        }
569
+
570
+
571
+
572
+        return $list;
573
+    }
574
+
575
+    public static function proceedAppNavigation($entries) {
576
+        $headerIconCount = 8;
577
+        $activeAppIndex = -1;
578
+        $list = self::proceedNavigation($entries);
579
+
580
+        $activeApp = OC::$server->getNavigationManager()->getActiveEntry();
581
+        foreach ($list as $index => &$navEntry) {
582
+            if ($navEntry['id'] == $activeApp) {
583
+                $navEntry['active'] = true;
584
+                $activeAppIndex = $index;
585
+            } else {
586
+                $navEntry['active'] = false;
587
+            }
588
+        }
589
+        // move active item to last position
590
+        if($activeAppIndex > ($headerIconCount-1)) {
591
+            $active = $list[$activeAppIndex];
592
+            $lastInHeader = $list[$headerIconCount-1];
593
+            $list[$headerIconCount-1] = $active;
594
+            $list[$activeAppIndex] = $lastInHeader;
595
+        }
596
+        $list = array_slice($list, 0, $headerIconCount);
597
+
598
+        return $list;
599
+    }
600
+
601
+    /**
602
+     * Get the path where to install apps
603
+     *
604
+     * @return string|false
605
+     */
606
+    public static function getInstallPath() {
607
+        if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) {
608
+            return false;
609
+        }
610
+
611
+        foreach (OC::$APPSROOTS as $dir) {
612
+            if (isset($dir['writable']) && $dir['writable'] === true) {
613
+                return $dir['path'];
614
+            }
615
+        }
616
+
617
+        \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR);
618
+        return null;
619
+    }
620
+
621
+
622
+    /**
623
+     * search for an app in all app-directories
624
+     *
625
+     * @param string $appId
626
+     * @return false|string
627
+     */
628
+    public static function findAppInDirectories($appId) {
629
+        $sanitizedAppId = self::cleanAppId($appId);
630
+        if($sanitizedAppId !== $appId) {
631
+            return false;
632
+        }
633
+        static $app_dir = array();
634
+
635
+        if (isset($app_dir[$appId])) {
636
+            return $app_dir[$appId];
637
+        }
638
+
639
+        $possibleApps = array();
640
+        foreach (OC::$APPSROOTS as $dir) {
641
+            if (file_exists($dir['path'] . '/' . $appId)) {
642
+                $possibleApps[] = $dir;
643
+            }
644
+        }
645
+
646
+        if (empty($possibleApps)) {
647
+            return false;
648
+        } elseif (count($possibleApps) === 1) {
649
+            $dir = array_shift($possibleApps);
650
+            $app_dir[$appId] = $dir;
651
+            return $dir;
652
+        } else {
653
+            $versionToLoad = array();
654
+            foreach ($possibleApps as $possibleApp) {
655
+                $version = self::getAppVersionByPath($possibleApp['path']);
656
+                if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) {
657
+                    $versionToLoad = array(
658
+                        'dir' => $possibleApp,
659
+                        'version' => $version,
660
+                    );
661
+                }
662
+            }
663
+            $app_dir[$appId] = $versionToLoad['dir'];
664
+            return $versionToLoad['dir'];
665
+            //TODO - write test
666
+        }
667
+    }
668
+
669
+    /**
670
+     * Get the directory for the given app.
671
+     * If the app is defined in multiple directories, the first one is taken. (false if not found)
672
+     *
673
+     * @param string $appId
674
+     * @return string|false
675
+     */
676
+    public static function getAppPath($appId) {
677
+        if ($appId === null || trim($appId) === '') {
678
+            return false;
679
+        }
680
+
681
+        if (($dir = self::findAppInDirectories($appId)) != false) {
682
+            return $dir['path'] . '/' . $appId;
683
+        }
684
+        return false;
685
+    }
686
+
687
+    /**
688
+     * Get the path for the given app on the access
689
+     * If the app is defined in multiple directories, the first one is taken. (false if not found)
690
+     *
691
+     * @param string $appId
692
+     * @return string|false
693
+     */
694
+    public static function getAppWebPath($appId) {
695
+        if (($dir = self::findAppInDirectories($appId)) != false) {
696
+            return OC::$WEBROOT . $dir['url'] . '/' . $appId;
697
+        }
698
+        return false;
699
+    }
700
+
701
+    /**
702
+     * get the last version of the app from appinfo/info.xml
703
+     *
704
+     * @param string $appId
705
+     * @param bool $useCache
706
+     * @return string
707
+     */
708
+    public static function getAppVersion($appId, $useCache = true) {
709
+        if($useCache && isset(self::$appVersion[$appId])) {
710
+            return self::$appVersion[$appId];
711
+        }
712
+
713
+        $file = self::getAppPath($appId);
714
+        self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0';
715
+        return self::$appVersion[$appId];
716
+    }
717
+
718
+    /**
719
+     * get app's version based on it's path
720
+     *
721
+     * @param string $path
722
+     * @return string
723
+     */
724
+    public static function getAppVersionByPath($path) {
725
+        $infoFile = $path . '/appinfo/info.xml';
726
+        $appData = self::getAppInfo($infoFile, true);
727
+        return isset($appData['version']) ? $appData['version'] : '';
728
+    }
729
+
730
+
731
+    /**
732
+     * Read all app metadata from the info.xml file
733
+     *
734
+     * @param string $appId id of the app or the path of the info.xml file
735
+     * @param bool $path
736
+     * @param string $lang
737
+     * @return array|null
738
+     * @note all data is read from info.xml, not just pre-defined fields
739
+     */
740
+    public static function getAppInfo($appId, $path = false, $lang = null) {
741
+        if ($path) {
742
+            $file = $appId;
743
+        } else {
744
+            if ($lang === null && isset(self::$appInfo[$appId])) {
745
+                return self::$appInfo[$appId];
746
+            }
747
+            $appPath = self::getAppPath($appId);
748
+            if($appPath === false) {
749
+                return null;
750
+            }
751
+            $file = $appPath . '/appinfo/info.xml';
752
+        }
753
+
754
+        $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo'));
755
+        $data = $parser->parse($file);
756
+
757
+        if (is_array($data)) {
758
+            $data = OC_App::parseAppInfo($data, $lang);
759
+        }
760
+        if(isset($data['ocsid'])) {
761
+            $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid');
762
+            if($storedId !== '' && $storedId !== $data['ocsid']) {
763
+                $data['ocsid'] = $storedId;
764
+            }
765
+        }
766
+
767
+        if ($lang === null) {
768
+            self::$appInfo[$appId] = $data;
769
+        }
770
+
771
+        return $data;
772
+    }
773
+
774
+    /**
775
+     * Returns the navigation
776
+     *
777
+     * @return array
778
+     *
779
+     * This function returns an array containing all entries added. The
780
+     * entries are sorted by the key 'order' ascending. Additional to the keys
781
+     * given for each app the following keys exist:
782
+     *   - active: boolean, signals if the user is on this navigation entry
783
+     */
784
+    public static function getNavigation() {
785
+        $entries = OC::$server->getNavigationManager()->getAll();
786
+        $navigation = self::proceedNavigation($entries);
787
+        return $navigation;
788
+    }
789
+
790
+    /**
791
+     * Returns the navigation inside the header bar
792
+     *
793
+     * @return array
794
+     *
795
+     * This function returns an array containing all entries added. The
796
+     * entries are sorted by the key 'order' ascending. Additional to the keys
797
+     * given for each app the following keys exist:
798
+     *   - active: boolean, signals if the user is on this navigation entry
799
+     */
800
+    public static function getHeaderNavigation() {
801
+        $entries = OC::$server->getNavigationManager()->getAll();
802
+        $navigation = self::proceedAppNavigation($entries);
803
+        return $navigation;
804
+    }
805
+
806
+    /**
807
+     * get the id of loaded app
808
+     *
809
+     * @return string
810
+     */
811
+    public static function getCurrentApp() {
812
+        $request = \OC::$server->getRequest();
813
+        $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1);
814
+        $topFolder = substr($script, 0, strpos($script, '/'));
815
+        if (empty($topFolder)) {
816
+            $path_info = $request->getPathInfo();
817
+            if ($path_info) {
818
+                $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
819
+            }
820
+        }
821
+        if ($topFolder == 'apps') {
822
+            $length = strlen($topFolder);
823
+            return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1);
824
+        } else {
825
+            return $topFolder;
826
+        }
827
+    }
828
+
829
+    /**
830
+     * @param string $type
831
+     * @return array
832
+     */
833
+    public static function getForms($type) {
834
+        $forms = array();
835
+        switch ($type) {
836
+            case 'admin':
837
+                $source = self::$adminForms;
838
+                break;
839
+            case 'personal':
840
+                $source = self::$personalForms;
841
+                break;
842
+            default:
843
+                return array();
844
+        }
845
+        foreach ($source as $form) {
846
+            $forms[] = include $form;
847
+        }
848
+        return $forms;
849
+    }
850
+
851
+    /**
852
+     * register an admin form to be shown
853
+     *
854
+     * @param string $app
855
+     * @param string $page
856
+     */
857
+    public static function registerAdmin($app, $page) {
858
+        self::$adminForms[] = $app . '/' . $page . '.php';
859
+    }
860
+
861
+    /**
862
+     * register a personal form to be shown
863
+     * @param string $app
864
+     * @param string $page
865
+     */
866
+    public static function registerPersonal($app, $page) {
867
+        self::$personalForms[] = $app . '/' . $page . '.php';
868
+    }
869
+
870
+    /**
871
+     * @param array $entry
872
+     */
873
+    public static function registerLogIn(array $entry) {
874
+        self::$altLogin[] = $entry;
875
+    }
876
+
877
+    /**
878
+     * @return array
879
+     */
880
+    public static function getAlternativeLogIns() {
881
+        return self::$altLogin;
882
+    }
883
+
884
+    /**
885
+     * get a list of all apps in the apps folder
886
+     *
887
+     * @return array an array of app names (string IDs)
888
+     * @todo: change the name of this method to getInstalledApps, which is more accurate
889
+     */
890
+    public static function getAllApps() {
891
+
892
+        $apps = array();
893
+
894
+        foreach (OC::$APPSROOTS as $apps_dir) {
895
+            if (!is_readable($apps_dir['path'])) {
896
+                \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN);
897
+                continue;
898
+            }
899
+            $dh = opendir($apps_dir['path']);
900
+
901
+            if (is_resource($dh)) {
902
+                while (($file = readdir($dh)) !== false) {
903
+
904
+                    if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
905
+
906
+                        $apps[] = $file;
907
+                    }
908
+                }
909
+            }
910
+        }
911
+
912
+        return $apps;
913
+    }
914
+
915
+    /**
916
+     * List all apps, this is used in apps.php
917
+     *
918
+     * @return array
919
+     */
920
+    public function listAllApps() {
921
+        $installedApps = OC_App::getAllApps();
922
+
923
+        //we don't want to show configuration for these
924
+        $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
925
+        $appList = array();
926
+        $langCode = \OC::$server->getL10N('core')->getLanguageCode();
927
+        $urlGenerator = \OC::$server->getURLGenerator();
928
+
929
+        foreach ($installedApps as $app) {
930
+            if (array_search($app, $blacklist) === false) {
931
+
932
+                $info = OC_App::getAppInfo($app, false, $langCode);
933
+                if (!is_array($info)) {
934
+                    \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR);
935
+                    continue;
936
+                }
937
+
938
+                if (!isset($info['name'])) {
939
+                    \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR);
940
+                    continue;
941
+                }
942
+
943
+                $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no');
944
+                $info['groups'] = null;
945
+                if ($enabled === 'yes') {
946
+                    $active = true;
947
+                } else if ($enabled === 'no') {
948
+                    $active = false;
949
+                } else {
950
+                    $active = true;
951
+                    $info['groups'] = $enabled;
952
+                }
953
+
954
+                $info['active'] = $active;
955
+
956
+                if (self::isShipped($app)) {
957
+                    $info['internal'] = true;
958
+                    $info['level'] = self::officialApp;
959
+                    $info['removable'] = false;
960
+                } else {
961
+                    $info['internal'] = false;
962
+                    $info['removable'] = true;
963
+                }
964
+
965
+                $appPath = self::getAppPath($app);
966
+                if($appPath !== false) {
967
+                    $appIcon = $appPath . '/img/' . $app . '.svg';
968
+                    if (file_exists($appIcon)) {
969
+                        $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg');
970
+                        $info['previewAsIcon'] = true;
971
+                    } else {
972
+                        $appIcon = $appPath . '/img/app.svg';
973
+                        if (file_exists($appIcon)) {
974
+                            $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg');
975
+                            $info['previewAsIcon'] = true;
976
+                        }
977
+                    }
978
+                }
979
+                // fix documentation
980
+                if (isset($info['documentation']) && is_array($info['documentation'])) {
981
+                    foreach ($info['documentation'] as $key => $url) {
982
+                        // If it is not an absolute URL we assume it is a key
983
+                        // i.e. admin-ldap will get converted to go.php?to=admin-ldap
984
+                        if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) {
985
+                            $url = $urlGenerator->linkToDocs($url);
986
+                        }
987
+
988
+                        $info['documentation'][$key] = $url;
989
+                    }
990
+                }
991
+
992
+                $info['version'] = OC_App::getAppVersion($app);
993
+                $appList[] = $info;
994
+            }
995
+        }
996
+
997
+        return $appList;
998
+    }
999
+
1000
+    /**
1001
+     * Returns the internal app ID or false
1002
+     * @param string $ocsID
1003
+     * @return string|false
1004
+     */
1005
+    public static function getInternalAppIdByOcs($ocsID) {
1006
+        if(is_numeric($ocsID)) {
1007
+            $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid');
1008
+            if(array_search($ocsID, $idArray)) {
1009
+                return array_search($ocsID, $idArray);
1010
+            }
1011
+        }
1012
+        return false;
1013
+    }
1014
+
1015
+    public static function shouldUpgrade($app) {
1016
+        $versions = self::getAppVersions();
1017
+        $currentVersion = OC_App::getAppVersion($app);
1018
+        if ($currentVersion && isset($versions[$app])) {
1019
+            $installedVersion = $versions[$app];
1020
+            if (!version_compare($currentVersion, $installedVersion, '=')) {
1021
+                return true;
1022
+            }
1023
+        }
1024
+        return false;
1025
+    }
1026
+
1027
+    /**
1028
+     * Adjust the number of version parts of $version1 to match
1029
+     * the number of version parts of $version2.
1030
+     *
1031
+     * @param string $version1 version to adjust
1032
+     * @param string $version2 version to take the number of parts from
1033
+     * @return string shortened $version1
1034
+     */
1035
+    private static function adjustVersionParts($version1, $version2) {
1036
+        $version1 = explode('.', $version1);
1037
+        $version2 = explode('.', $version2);
1038
+        // reduce $version1 to match the number of parts in $version2
1039
+        while (count($version1) > count($version2)) {
1040
+            array_pop($version1);
1041
+        }
1042
+        // if $version1 does not have enough parts, add some
1043
+        while (count($version1) < count($version2)) {
1044
+            $version1[] = '0';
1045
+        }
1046
+        return implode('.', $version1);
1047
+    }
1048
+
1049
+    /**
1050
+     * Check whether the current ownCloud version matches the given
1051
+     * application's version requirements.
1052
+     *
1053
+     * The comparison is made based on the number of parts that the
1054
+     * app info version has. For example for ownCloud 6.0.3 if the
1055
+     * app info version is expecting version 6.0, the comparison is
1056
+     * made on the first two parts of the ownCloud version.
1057
+     * This means that it's possible to specify "requiremin" => 6
1058
+     * and "requiremax" => 6 and it will still match ownCloud 6.0.3.
1059
+     *
1060
+     * @param string $ocVersion ownCloud version to check against
1061
+     * @param array $appInfo app info (from xml)
1062
+     *
1063
+     * @return boolean true if compatible, otherwise false
1064
+     */
1065
+    public static function isAppCompatible($ocVersion, $appInfo) {
1066
+        $requireMin = '';
1067
+        $requireMax = '';
1068
+        if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) {
1069
+            $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version'];
1070
+        } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) {
1071
+            $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version'];
1072
+        } else if (isset($appInfo['requiremin'])) {
1073
+            $requireMin = $appInfo['requiremin'];
1074
+        } else if (isset($appInfo['require'])) {
1075
+            $requireMin = $appInfo['require'];
1076
+        }
1077
+
1078
+        if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) {
1079
+            $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version'];
1080
+        } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) {
1081
+            $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version'];
1082
+        } else if (isset($appInfo['requiremax'])) {
1083
+            $requireMax = $appInfo['requiremax'];
1084
+        }
1085
+
1086
+        if (is_array($ocVersion)) {
1087
+            $ocVersion = implode('.', $ocVersion);
1088
+        }
1089
+
1090
+        if (!empty($requireMin)
1091
+            && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<')
1092
+        ) {
1093
+
1094
+            return false;
1095
+        }
1096
+
1097
+        if (!empty($requireMax)
1098
+            && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>')
1099
+        ) {
1100
+            return false;
1101
+        }
1102
+
1103
+        return true;
1104
+    }
1105
+
1106
+    /**
1107
+     * get the installed version of all apps
1108
+     */
1109
+    public static function getAppVersions() {
1110
+        static $versions;
1111
+
1112
+        if(!$versions) {
1113
+            $appConfig = \OC::$server->getAppConfig();
1114
+            $versions = $appConfig->getValues(false, 'installed_version');
1115
+        }
1116
+        return $versions;
1117
+    }
1118
+
1119
+    /**
1120
+     * @param string $app
1121
+     * @param \OCP\IConfig $config
1122
+     * @param \OCP\IL10N $l
1123
+     * @return bool
1124
+     *
1125
+     * @throws Exception if app is not compatible with this version of ownCloud
1126
+     * @throws Exception if no app-name was specified
1127
+     */
1128
+    public function installApp($app,
1129
+                                \OCP\IConfig $config,
1130
+                                \OCP\IL10N $l) {
1131
+        if ($app !== false) {
1132
+            // check if the app is compatible with this version of ownCloud
1133
+            $info = self::getAppInfo($app);
1134
+            if(!is_array($info)) {
1135
+                throw new \Exception(
1136
+                    $l->t('App "%s" cannot be installed because appinfo file cannot be read.',
1137
+                        [$info['name']]
1138
+                    )
1139
+                );
1140
+            }
1141
+
1142
+            $version = \OCP\Util::getVersion();
1143
+            if (!self::isAppCompatible($version, $info)) {
1144
+                throw new \Exception(
1145
+                    $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.',
1146
+                        array($info['name'])
1147
+                    )
1148
+                );
1149
+            }
1150
+
1151
+            // check for required dependencies
1152
+            self::checkAppDependencies($config, $l, $info);
1153
+
1154
+            $config->setAppValue($app, 'enabled', 'yes');
1155
+            if (isset($appData['id'])) {
1156
+                $config->setAppValue($app, 'ocsid', $appData['id']);
1157
+            }
1158
+
1159
+            if(isset($info['settings']) && is_array($info['settings'])) {
1160
+                $appPath = self::getAppPath($app);
1161
+                self::registerAutoloading($app, $appPath);
1162
+                \OC::$server->getSettingsManager()->setupSettings($info['settings']);
1163
+            }
1164
+
1165
+            \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app));
1166
+        } else {
1167
+            if(empty($appName) ) {
1168
+                throw new \Exception($l->t("No app name specified"));
1169
+            } else {
1170
+                throw new \Exception($l->t("App '%s' could not be installed!", $appName));
1171
+            }
1172
+        }
1173
+
1174
+        return $app;
1175
+    }
1176
+
1177
+    /**
1178
+     * update the database for the app and call the update script
1179
+     *
1180
+     * @param string $appId
1181
+     * @return bool
1182
+     */
1183
+    public static function updateApp($appId) {
1184
+        $appPath = self::getAppPath($appId);
1185
+        if($appPath === false) {
1186
+            return false;
1187
+        }
1188
+        $appData = self::getAppInfo($appId);
1189
+        self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
1190
+        if (file_exists($appPath . '/appinfo/database.xml')) {
1191
+            OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
1192
+        }
1193
+        self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
1194
+        self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
1195
+        unset(self::$appVersion[$appId]);
1196
+        // run upgrade code
1197
+        if (file_exists($appPath . '/appinfo/update.php')) {
1198
+            self::loadApp($appId);
1199
+            include $appPath . '/appinfo/update.php';
1200
+        }
1201
+        self::setupBackgroundJobs($appData['background-jobs']);
1202
+        if(isset($appData['settings']) && is_array($appData['settings'])) {
1203
+            $appPath = self::getAppPath($appId);
1204
+            self::registerAutoloading($appId, $appPath);
1205
+            \OC::$server->getSettingsManager()->setupSettings($appData['settings']);
1206
+        }
1207
+
1208
+        //set remote/public handlers
1209
+        if (array_key_exists('ocsid', $appData)) {
1210
+            \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
1211
+        } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
1212
+            \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
1213
+        }
1214
+        foreach ($appData['remote'] as $name => $path) {
1215
+            \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
1216
+        }
1217
+        foreach ($appData['public'] as $name => $path) {
1218
+            \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
1219
+        }
1220
+
1221
+        self::setAppTypes($appId);
1222
+
1223
+        $version = \OC_App::getAppVersion($appId);
1224
+        \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version);
1225
+
1226
+        \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent(
1227
+            ManagerEvent::EVENT_APP_UPDATE, $appId
1228
+        ));
1229
+
1230
+        return true;
1231
+    }
1232
+
1233
+    /**
1234
+     * @param string $appId
1235
+     * @param string[] $steps
1236
+     * @throws \OC\NeedsUpdateException
1237
+     */
1238
+    public static function executeRepairSteps($appId, array $steps) {
1239
+        if (empty($steps)) {
1240
+            return;
1241
+        }
1242
+        // load the app
1243
+        self::loadApp($appId);
1244
+
1245
+        $dispatcher = OC::$server->getEventDispatcher();
1246
+
1247
+        // load the steps
1248
+        $r = new Repair([], $dispatcher);
1249
+        foreach ($steps as $step) {
1250
+            try {
1251
+                $r->addStep($step);
1252
+            } catch (Exception $ex) {
1253
+                $r->emit('\OC\Repair', 'error', [$ex->getMessage()]);
1254
+                \OC::$server->getLogger()->logException($ex);
1255
+            }
1256
+        }
1257
+        // run the steps
1258
+        $r->run();
1259
+    }
1260
+
1261
+    public static function setupBackgroundJobs(array $jobs) {
1262
+        $queue = \OC::$server->getJobList();
1263
+        foreach ($jobs as $job) {
1264
+            $queue->add($job);
1265
+        }
1266
+    }
1267
+
1268
+    /**
1269
+     * @param string $appId
1270
+     * @param string[] $steps
1271
+     */
1272
+    private static function setupLiveMigrations($appId, array $steps) {
1273
+        $queue = \OC::$server->getJobList();
1274
+        foreach ($steps as $step) {
1275
+            $queue->add('OC\Migration\BackgroundRepair', [
1276
+                'app' => $appId,
1277
+                'step' => $step]);
1278
+        }
1279
+    }
1280
+
1281
+    /**
1282
+     * @param string $appId
1283
+     * @return \OC\Files\View|false
1284
+     */
1285
+    public static function getStorage($appId) {
1286
+        if (OC_App::isEnabled($appId)) { //sanity check
1287
+            if (\OC::$server->getUserSession()->isLoggedIn()) {
1288
+                $view = new \OC\Files\View('/' . OC_User::getUser());
1289
+                if (!$view->file_exists($appId)) {
1290
+                    $view->mkdir($appId);
1291
+                }
1292
+                return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1293
+            } else {
1294
+                \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR);
1295
+                return false;
1296
+            }
1297
+        } else {
1298
+            \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR);
1299
+            return false;
1300
+        }
1301
+    }
1302
+
1303
+    protected static function findBestL10NOption($options, $lang) {
1304
+        $fallback = $similarLangFallback = $englishFallback = false;
1305
+
1306
+        $lang = strtolower($lang);
1307
+        $similarLang = $lang;
1308
+        if (strpos($similarLang, '_')) {
1309
+            // For "de_DE" we want to find "de" and the other way around
1310
+            $similarLang = substr($lang, 0, strpos($lang, '_'));
1311
+        }
1312
+
1313
+        foreach ($options as $option) {
1314
+            if (is_array($option)) {
1315
+                if ($fallback === false) {
1316
+                    $fallback = $option['@value'];
1317
+                }
1318
+
1319
+                if (!isset($option['@attributes']['lang'])) {
1320
+                    continue;
1321
+                }
1322
+
1323
+                $attributeLang = strtolower($option['@attributes']['lang']);
1324
+                if ($attributeLang === $lang) {
1325
+                    return $option['@value'];
1326
+                }
1327
+
1328
+                if ($attributeLang === $similarLang) {
1329
+                    $similarLangFallback = $option['@value'];
1330
+                } else if (strpos($attributeLang, $similarLang . '_') === 0) {
1331
+                    if ($similarLangFallback === false) {
1332
+                        $similarLangFallback =  $option['@value'];
1333
+                    }
1334
+                }
1335
+            } else {
1336
+                $englishFallback = $option;
1337
+            }
1338
+        }
1339
+
1340
+        if ($similarLangFallback !== false) {
1341
+            return $similarLangFallback;
1342
+        } else if ($englishFallback !== false) {
1343
+            return $englishFallback;
1344
+        }
1345
+        return (string) $fallback;
1346
+    }
1347
+
1348
+    /**
1349
+     * parses the app data array and enhanced the 'description' value
1350
+     *
1351
+     * @param array $data the app data
1352
+     * @param string $lang
1353
+     * @return array improved app data
1354
+     */
1355
+    public static function parseAppInfo(array $data, $lang = null) {
1356
+
1357
+        if ($lang && isset($data['name']) && is_array($data['name'])) {
1358
+            $data['name'] = self::findBestL10NOption($data['name'], $lang);
1359
+        }
1360
+        if ($lang && isset($data['summary']) && is_array($data['summary'])) {
1361
+            $data['summary'] = self::findBestL10NOption($data['summary'], $lang);
1362
+        }
1363
+        if ($lang && isset($data['description']) && is_array($data['description'])) {
1364
+            $data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1365
+        } else if (isset($data['description']) && is_string($data['description'])) {
1366
+            $data['description'] = trim($data['description']);
1367
+        } else  {
1368
+            $data['description'] = '';
1369
+        }
1370
+
1371
+        return $data;
1372
+    }
1373
+
1374
+    /**
1375
+     * @param \OCP\IConfig $config
1376
+     * @param \OCP\IL10N $l
1377
+     * @param array $info
1378
+     * @throws \Exception
1379
+     */
1380
+    protected static function checkAppDependencies($config, $l, $info) {
1381
+        $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
1382
+        $missing = $dependencyAnalyzer->analyze($info);
1383
+        if (!empty($missing)) {
1384
+            $missingMsg = join(PHP_EOL, $missing);
1385
+            throw new \Exception(
1386
+                $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s',
1387
+                    [$info['name'], $missingMsg]
1388
+                )
1389
+            );
1390
+        }
1391
+    }
1392 1392
 }
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 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);
@@ -182,17 +182,17 @@  discard block
 block discarded – undo
182 182
 	 * @param string $path
183 183
 	 */
184 184
 	public static function registerAutoloading($app, $path) {
185
-		$key = $app . '-' . $path;
186
-		if(isset(self::$alreadyRegistered[$key])) {
185
+		$key = $app.'-'.$path;
186
+		if (isset(self::$alreadyRegistered[$key])) {
187 187
 			return;
188 188
 		}
189 189
 		self::$alreadyRegistered[$key] = true;
190 190
 		// Register on PSR-4 composer autoloader
191 191
 		$appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
192 192
 		\OC::$server->registerNamespace($app, $appNamespace);
193
-		\OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
193
+		\OC::$composerAutoloader->addPsr4($appNamespace.'\\', $path.'/lib/', true);
194 194
 		if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
195
-			\OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
195
+			\OC::$composerAutoloader->addPsr4($appNamespace.'\\Tests\\', $path.'/tests/', true);
196 196
 		}
197 197
 
198 198
 		// Register on legacy autoloader
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	private static function requireAppFile($app) {
208 208
 		try {
209 209
 			// encapsulated here to avoid variable scope conflicts
210
-			require_once $app . '/appinfo/app.php';
210
+			require_once $app.'/appinfo/app.php';
211 211
 		} catch (Error $ex) {
212 212
 			\OC::$server->getLogger()->logException($ex);
213 213
 			$blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 	 */
262 262
 	public static function setAppTypes($app) {
263 263
 		$appData = self::getAppInfo($app);
264
-		if(!is_array($appData)) {
264
+		if (!is_array($appData)) {
265 265
 			return;
266 266
 		}
267 267
 
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 		} else {
326 326
 			$apps = $appManager->getEnabledAppsForUser($user);
327 327
 		}
328
-		$apps = array_filter($apps, function ($app) {
329
-			return $app !== 'files';//we add this manually
328
+		$apps = array_filter($apps, function($app) {
329
+			return $app !== 'files'; //we add this manually
330 330
 		});
331 331
 		sort($apps);
332 332
 		array_unshift($apps, 'files');
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 		);
371 371
 		$isDownloaded = $installer->isDownloaded($appId);
372 372
 
373
-		if(!$isDownloaded) {
373
+		if (!$isDownloaded) {
374 374
 			$installer->downloadApp($appId);
375 375
 		}
376 376
 
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 		}
409 409
 
410 410
 		$info = self::getAppInfo($appId);
411
-		if(isset($info['settings']) && is_array($info['settings'])) {
411
+		if (isset($info['settings']) && is_array($info['settings'])) {
412 412
 			$appPath = self::getAppPath($appId);
413 413
 			self::registerAutoloading($appId, $appPath);
414 414
 			\OC::$server->getSettingsManager()->setupSettings($info['settings']);
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 			//SubAdmins are also allowed to access user management
498 498
 			$userObject = \OC::$server->getUserSession()->getUser();
499 499
 			$isSubAdmin = false;
500
-			if($userObject !== null) {
500
+			if ($userObject !== null) {
501 501
 				$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
502 502
 			}
503 503
 			if ($isSubAdmin) {
@@ -553,16 +553,16 @@  discard block
 block discarded – undo
553 553
 		}
554 554
 		unset($navEntry);
555 555
 
556
-		if($activeAppIndex > ($headerIconCount-1)) {
556
+		if ($activeAppIndex > ($headerIconCount - 1)) {
557 557
 			$active = $list[$activeAppIndex];
558
-			$lastInHeader = $list[$headerIconCount-1];
559
-			$list[$headerIconCount-1] = $active;
558
+			$lastInHeader = $list[$headerIconCount - 1];
559
+			$list[$headerIconCount - 1] = $active;
560 560
 			$list[$activeAppIndex] = $lastInHeader;
561 561
 		}
562 562
 
563 563
 		foreach ($list as $index => &$navEntry) {
564 564
 			$navEntry['showInHeader'] = false;
565
-			if($index < $headerIconCount) {
565
+			if ($index < $headerIconCount) {
566 566
 				$navEntry['showInHeader'] = true;
567 567
 			}
568 568
 		}
@@ -587,10 +587,10 @@  discard block
 block discarded – undo
587 587
 			}
588 588
 		}
589 589
 		// move active item to last position
590
-		if($activeAppIndex > ($headerIconCount-1)) {
590
+		if ($activeAppIndex > ($headerIconCount - 1)) {
591 591
 			$active = $list[$activeAppIndex];
592
-			$lastInHeader = $list[$headerIconCount-1];
593
-			$list[$headerIconCount-1] = $active;
592
+			$lastInHeader = $list[$headerIconCount - 1];
593
+			$list[$headerIconCount - 1] = $active;
594 594
 			$list[$activeAppIndex] = $lastInHeader;
595 595
 		}
596 596
 		$list = array_slice($list, 0, $headerIconCount);
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 	 */
628 628
 	public static function findAppInDirectories($appId) {
629 629
 		$sanitizedAppId = self::cleanAppId($appId);
630
-		if($sanitizedAppId !== $appId) {
630
+		if ($sanitizedAppId !== $appId) {
631 631
 			return false;
632 632
 		}
633 633
 		static $app_dir = array();
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 
639 639
 		$possibleApps = array();
640 640
 		foreach (OC::$APPSROOTS as $dir) {
641
-			if (file_exists($dir['path'] . '/' . $appId)) {
641
+			if (file_exists($dir['path'].'/'.$appId)) {
642 642
 				$possibleApps[] = $dir;
643 643
 			}
644 644
 		}
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
 		}
680 680
 
681 681
 		if (($dir = self::findAppInDirectories($appId)) != false) {
682
-			return $dir['path'] . '/' . $appId;
682
+			return $dir['path'].'/'.$appId;
683 683
 		}
684 684
 		return false;
685 685
 	}
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
 	 */
694 694
 	public static function getAppWebPath($appId) {
695 695
 		if (($dir = self::findAppInDirectories($appId)) != false) {
696
-			return OC::$WEBROOT . $dir['url'] . '/' . $appId;
696
+			return OC::$WEBROOT.$dir['url'].'/'.$appId;
697 697
 		}
698 698
 		return false;
699 699
 	}
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
 	 * @return string
707 707
 	 */
708 708
 	public static function getAppVersion($appId, $useCache = true) {
709
-		if($useCache && isset(self::$appVersion[$appId])) {
709
+		if ($useCache && isset(self::$appVersion[$appId])) {
710 710
 			return self::$appVersion[$appId];
711 711
 		}
712 712
 
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
 	 * @return string
723 723
 	 */
724 724
 	public static function getAppVersionByPath($path) {
725
-		$infoFile = $path . '/appinfo/info.xml';
725
+		$infoFile = $path.'/appinfo/info.xml';
726 726
 		$appData = self::getAppInfo($infoFile, true);
727 727
 		return isset($appData['version']) ? $appData['version'] : '';
728 728
 	}
@@ -745,10 +745,10 @@  discard block
 block discarded – undo
745 745
 				return self::$appInfo[$appId];
746 746
 			}
747 747
 			$appPath = self::getAppPath($appId);
748
-			if($appPath === false) {
748
+			if ($appPath === false) {
749 749
 				return null;
750 750
 			}
751
-			$file = $appPath . '/appinfo/info.xml';
751
+			$file = $appPath.'/appinfo/info.xml';
752 752
 		}
753 753
 
754 754
 		$parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo'));
@@ -757,9 +757,9 @@  discard block
 block discarded – undo
757 757
 		if (is_array($data)) {
758 758
 			$data = OC_App::parseAppInfo($data, $lang);
759 759
 		}
760
-		if(isset($data['ocsid'])) {
760
+		if (isset($data['ocsid'])) {
761 761
 			$storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid');
762
-			if($storedId !== '' && $storedId !== $data['ocsid']) {
762
+			if ($storedId !== '' && $storedId !== $data['ocsid']) {
763 763
 				$data['ocsid'] = $storedId;
764 764
 			}
765 765
 		}
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
 	 * @param string $page
856 856
 	 */
857 857
 	public static function registerAdmin($app, $page) {
858
-		self::$adminForms[] = $app . '/' . $page . '.php';
858
+		self::$adminForms[] = $app.'/'.$page.'.php';
859 859
 	}
860 860
 
861 861
 	/**
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
 	 * @param string $page
865 865
 	 */
866 866
 	public static function registerPersonal($app, $page) {
867
-		self::$personalForms[] = $app . '/' . $page . '.php';
867
+		self::$personalForms[] = $app.'/'.$page.'.php';
868 868
 	}
869 869
 
870 870
 	/**
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 
894 894
 		foreach (OC::$APPSROOTS as $apps_dir) {
895 895
 			if (!is_readable($apps_dir['path'])) {
896
-				\OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN);
896
+				\OCP\Util::writeLog('core', 'unable to read app folder : '.$apps_dir['path'], \OCP\Util::WARN);
897 897
 				continue;
898 898
 			}
899 899
 			$dh = opendir($apps_dir['path']);
@@ -901,7 +901,7 @@  discard block
 block discarded – undo
901 901
 			if (is_resource($dh)) {
902 902
 				while (($file = readdir($dh)) !== false) {
903 903
 
904
-					if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
904
+					if ($file[0] != '.' and is_dir($apps_dir['path'].'/'.$file) and is_file($apps_dir['path'].'/'.$file.'/appinfo/info.xml')) {
905 905
 
906 906
 						$apps[] = $file;
907 907
 					}
@@ -931,12 +931,12 @@  discard block
 block discarded – undo
931 931
 
932 932
 				$info = OC_App::getAppInfo($app, false, $langCode);
933 933
 				if (!is_array($info)) {
934
-					\OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR);
934
+					\OCP\Util::writeLog('core', 'Could not read app info file for app "'.$app.'"', \OCP\Util::ERROR);
935 935
 					continue;
936 936
 				}
937 937
 
938 938
 				if (!isset($info['name'])) {
939
-					\OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR);
939
+					\OCP\Util::writeLog('core', 'App id "'.$app.'" has no name in appinfo', \OCP\Util::ERROR);
940 940
 					continue;
941 941
 				}
942 942
 
@@ -963,13 +963,13 @@  discard block
 block discarded – undo
963 963
 				}
964 964
 
965 965
 				$appPath = self::getAppPath($app);
966
-				if($appPath !== false) {
967
-					$appIcon = $appPath . '/img/' . $app . '.svg';
966
+				if ($appPath !== false) {
967
+					$appIcon = $appPath.'/img/'.$app.'.svg';
968 968
 					if (file_exists($appIcon)) {
969
-						$info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg');
969
+						$info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app.'.svg');
970 970
 						$info['previewAsIcon'] = true;
971 971
 					} else {
972
-						$appIcon = $appPath . '/img/app.svg';
972
+						$appIcon = $appPath.'/img/app.svg';
973 973
 						if (file_exists($appIcon)) {
974 974
 							$info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg');
975 975
 							$info['previewAsIcon'] = true;
@@ -1003,9 +1003,9 @@  discard block
 block discarded – undo
1003 1003
 	 * @return string|false
1004 1004
 	 */
1005 1005
 	public static function getInternalAppIdByOcs($ocsID) {
1006
-		if(is_numeric($ocsID)) {
1006
+		if (is_numeric($ocsID)) {
1007 1007
 			$idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid');
1008
-			if(array_search($ocsID, $idArray)) {
1008
+			if (array_search($ocsID, $idArray)) {
1009 1009
 				return array_search($ocsID, $idArray);
1010 1010
 			}
1011 1011
 		}
@@ -1109,7 +1109,7 @@  discard block
 block discarded – undo
1109 1109
 	public static function getAppVersions() {
1110 1110
 		static $versions;
1111 1111
 
1112
-		if(!$versions) {
1112
+		if (!$versions) {
1113 1113
 			$appConfig = \OC::$server->getAppConfig();
1114 1114
 			$versions = $appConfig->getValues(false, 'installed_version');
1115 1115
 		}
@@ -1131,7 +1131,7 @@  discard block
 block discarded – undo
1131 1131
 		if ($app !== false) {
1132 1132
 			// check if the app is compatible with this version of ownCloud
1133 1133
 			$info = self::getAppInfo($app);
1134
-			if(!is_array($info)) {
1134
+			if (!is_array($info)) {
1135 1135
 				throw new \Exception(
1136 1136
 					$l->t('App "%s" cannot be installed because appinfo file cannot be read.',
1137 1137
 						[$info['name']]
@@ -1156,7 +1156,7 @@  discard block
 block discarded – undo
1156 1156
 				$config->setAppValue($app, 'ocsid', $appData['id']);
1157 1157
 			}
1158 1158
 
1159
-			if(isset($info['settings']) && is_array($info['settings'])) {
1159
+			if (isset($info['settings']) && is_array($info['settings'])) {
1160 1160
 				$appPath = self::getAppPath($app);
1161 1161
 				self::registerAutoloading($app, $appPath);
1162 1162
 				\OC::$server->getSettingsManager()->setupSettings($info['settings']);
@@ -1164,7 +1164,7 @@  discard block
 block discarded – undo
1164 1164
 
1165 1165
 			\OC_Hook::emit('OC_App', 'post_enable', array('app' => $app));
1166 1166
 		} else {
1167
-			if(empty($appName) ) {
1167
+			if (empty($appName)) {
1168 1168
 				throw new \Exception($l->t("No app name specified"));
1169 1169
 			} else {
1170 1170
 				throw new \Exception($l->t("App '%s' could not be installed!", $appName));
@@ -1182,24 +1182,24 @@  discard block
 block discarded – undo
1182 1182
 	 */
1183 1183
 	public static function updateApp($appId) {
1184 1184
 		$appPath = self::getAppPath($appId);
1185
-		if($appPath === false) {
1185
+		if ($appPath === false) {
1186 1186
 			return false;
1187 1187
 		}
1188 1188
 		$appData = self::getAppInfo($appId);
1189 1189
 		self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
1190
-		if (file_exists($appPath . '/appinfo/database.xml')) {
1191
-			OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
1190
+		if (file_exists($appPath.'/appinfo/database.xml')) {
1191
+			OC_DB::updateDbFromStructure($appPath.'/appinfo/database.xml');
1192 1192
 		}
1193 1193
 		self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
1194 1194
 		self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
1195 1195
 		unset(self::$appVersion[$appId]);
1196 1196
 		// run upgrade code
1197
-		if (file_exists($appPath . '/appinfo/update.php')) {
1197
+		if (file_exists($appPath.'/appinfo/update.php')) {
1198 1198
 			self::loadApp($appId);
1199
-			include $appPath . '/appinfo/update.php';
1199
+			include $appPath.'/appinfo/update.php';
1200 1200
 		}
1201 1201
 		self::setupBackgroundJobs($appData['background-jobs']);
1202
-		if(isset($appData['settings']) && is_array($appData['settings'])) {
1202
+		if (isset($appData['settings']) && is_array($appData['settings'])) {
1203 1203
 			$appPath = self::getAppPath($appId);
1204 1204
 			self::registerAutoloading($appId, $appPath);
1205 1205
 			\OC::$server->getSettingsManager()->setupSettings($appData['settings']);
@@ -1208,14 +1208,14 @@  discard block
 block discarded – undo
1208 1208
 		//set remote/public handlers
1209 1209
 		if (array_key_exists('ocsid', $appData)) {
1210 1210
 			\OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
1211
-		} elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
1211
+		} elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
1212 1212
 			\OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
1213 1213
 		}
1214 1214
 		foreach ($appData['remote'] as $name => $path) {
1215
-			\OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
1215
+			\OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $appId.'/'.$path);
1216 1216
 		}
1217 1217
 		foreach ($appData['public'] as $name => $path) {
1218
-			\OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
1218
+			\OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $appId.'/'.$path);
1219 1219
 		}
1220 1220
 
1221 1221
 		self::setAppTypes($appId);
@@ -1285,17 +1285,17 @@  discard block
 block discarded – undo
1285 1285
 	public static function getStorage($appId) {
1286 1286
 		if (OC_App::isEnabled($appId)) { //sanity check
1287 1287
 			if (\OC::$server->getUserSession()->isLoggedIn()) {
1288
-				$view = new \OC\Files\View('/' . OC_User::getUser());
1288
+				$view = new \OC\Files\View('/'.OC_User::getUser());
1289 1289
 				if (!$view->file_exists($appId)) {
1290 1290
 					$view->mkdir($appId);
1291 1291
 				}
1292
-				return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1292
+				return new \OC\Files\View('/'.OC_User::getUser().'/'.$appId);
1293 1293
 			} else {
1294
-				\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR);
1294
+				\OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.', user not logged in', \OCP\Util::ERROR);
1295 1295
 				return false;
1296 1296
 			}
1297 1297
 		} else {
1298
-			\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR);
1298
+			\OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.' not enabled', \OCP\Util::ERROR);
1299 1299
 			return false;
1300 1300
 		}
1301 1301
 	}
@@ -1327,9 +1327,9 @@  discard block
 block discarded – undo
1327 1327
 
1328 1328
 				if ($attributeLang === $similarLang) {
1329 1329
 					$similarLangFallback = $option['@value'];
1330
-				} else if (strpos($attributeLang, $similarLang . '_') === 0) {
1330
+				} else if (strpos($attributeLang, $similarLang.'_') === 0) {
1331 1331
 					if ($similarLangFallback === false) {
1332
-						$similarLangFallback =  $option['@value'];
1332
+						$similarLangFallback = $option['@value'];
1333 1333
 					}
1334 1334
 				}
1335 1335
 			} else {
@@ -1364,7 +1364,7 @@  discard block
 block discarded – undo
1364 1364
 			$data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1365 1365
 		} else if (isset($data['description']) && is_string($data['description'])) {
1366 1366
 			$data['description'] = trim($data['description']);
1367
-		} else  {
1367
+		} else {
1368 1368
 			$data['description'] = '';
1369 1369
 		}
1370 1370
 
Please login to merge, or discard this patch.
lib/private/NavigationManager.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -39,164 +39,164 @@
 block discarded – undo
39 39
  */
40 40
 
41 41
 class NavigationManager implements INavigationManager {
42
-	protected $entries = [];
43
-	protected $closureEntries = [];
44
-	protected $activeEntry;
45
-	/** @var bool */
46
-	protected $init = false;
47
-	/** @var IAppManager|AppManager */
48
-	protected $appManager;
49
-	/** @var IURLGenerator */
50
-	private $urlGenerator;
51
-	/** @var IFactory */
52
-	private $l10nFac;
53
-	/** @var IUserSession */
54
-	private $userSession;
55
-	/** @var IGroupManager */
56
-	private $groupManager;
57
-
58
-	public function __construct(IAppManager $appManager = null,
59
-						 IURLGenerator $urlGenerator = null,
60
-						 IFactory $l10nFac = null,
61
-						 IUserSession $userSession = null,
62
-						 IGroupManager$groupManager = null) {
63
-		$this->appManager = $appManager;
64
-		$this->urlGenerator = $urlGenerator;
65
-		$this->l10nFac = $l10nFac;
66
-		$this->userSession = $userSession;
67
-		$this->groupManager = $groupManager;
68
-	}
69
-
70
-	/**
71
-	 * Creates a new navigation entry
72
-	 *
73
-	 * @param array|\Closure $entry Array containing: id, name, order, icon and href key
74
-	 *					The use of a closure is preferred, because it will avoid
75
-	 * 					loading the routing of your app, unless required.
76
-	 * @return void
77
-	 */
78
-	public function add($entry) {
79
-		if ($entry instanceof \Closure) {
80
-			$this->closureEntries[] = $entry;
81
-			return;
82
-		}
83
-
84
-		$entry['active'] = false;
85
-		if(!isset($entry['icon'])) {
86
-			$entry['icon'] = '';
87
-		}
88
-		$this->entries[] = $entry;
89
-	}
90
-
91
-	/**
92
-	 * returns all the added Menu entries
93
-	 * @return array an array of the added entries
94
-	 */
95
-	public function getAll() {
96
-		$this->init();
97
-		foreach ($this->closureEntries as $c) {
98
-			$this->add($c());
99
-		}
100
-		$this->closureEntries = array();
101
-		return $this->entries;
102
-	}
103
-
104
-	/**
105
-	 * removes all the entries
106
-	 */
107
-	public function clear() {
108
-		$this->entries = [];
109
-		$this->closureEntries = [];
110
-		$this->init = false;
111
-	}
112
-
113
-	/**
114
-	 * Sets the current navigation entry of the currently running app
115
-	 * @param string $id of the app entry to activate (from added $entry)
116
-	 */
117
-	public function setActiveEntry($id) {
118
-		$this->activeEntry = $id;
119
-	}
120
-
121
-	/**
122
-	 * gets the active Menu entry
123
-	 * @return string id or empty string
124
-	 *
125
-	 * This function returns the id of the active navigation entry (set by
126
-	 * setActiveEntry
127
-	 */
128
-	public function getActiveEntry() {
129
-		return $this->activeEntry;
130
-	}
131
-
132
-	private function init() {
133
-		if ($this->init) {
134
-			return;
135
-		}
136
-		$this->init = true;
137
-		if (is_null($this->appManager)) {
138
-			return;
139
-		}
140
-		foreach ($this->appManager->getInstalledApps() as $app) {
141
-			// load plugins and collections from info.xml
142
-			$info = $this->appManager->getAppInfo($app);
143
-			if (!isset($info['navigation'])) {
144
-				continue;
145
-			}
146
-			$nav = $info['navigation'];
147
-			if (!isset($nav['name'])) {
148
-				continue;
149
-			}
150
-			if (!isset($nav['route'])) {
151
-				continue;
152
-			}
153
-			$role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
154
-			if ($role === 'admin' && !$this->isAdmin()) {
155
-				continue;
156
-			}
157
-			$l = $this->l10nFac->get($app);
158
-			$order = isset($nav['order']) ? $nav['order'] : 100;
159
-			$route = $this->urlGenerator->linkToRoute($nav['route']);
160
-			$icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
161
-			foreach ([$icon, "$app.svg"] as $i) {
162
-				try {
163
-					$icon = $this->urlGenerator->imagePath($app, $i);
164
-					break;
165
-				} catch (\RuntimeException $ex) {
166
-					// no icon? - ignore it then
167
-				}
168
-			}
169
-			if (is_null($icon)) {
170
-				$icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
171
-			}
172
-
173
-			$this->add([
174
-				'id' => $app,
175
-				'order' => $order,
176
-				'href' => $route,
177
-				'icon' => $icon,
178
-				'name' => $l->t($nav['name']),
179
-			]);
180
-		}
181
-
182
-		if ($this->isAdmin()) {
183
-			$l = $this->l10nFac->get('settings');
184
-			$this->add([
185
-				'id' => 'core_apps',
186
-				'order' => 9999,
187
-				'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
188
-				'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
189
-				'name' => $l->t('Apps'),
190
-			]);
191
-		}
192
-	}
193
-
194
-	private function isAdmin() {
195
-		$user = $this->userSession->getUser();
196
-		if ($user !== null) {
197
-			return $this->groupManager->isAdmin($user->getUID());
198
-		}
199
-		return false;
200
-	}
42
+    protected $entries = [];
43
+    protected $closureEntries = [];
44
+    protected $activeEntry;
45
+    /** @var bool */
46
+    protected $init = false;
47
+    /** @var IAppManager|AppManager */
48
+    protected $appManager;
49
+    /** @var IURLGenerator */
50
+    private $urlGenerator;
51
+    /** @var IFactory */
52
+    private $l10nFac;
53
+    /** @var IUserSession */
54
+    private $userSession;
55
+    /** @var IGroupManager */
56
+    private $groupManager;
57
+
58
+    public function __construct(IAppManager $appManager = null,
59
+                            IURLGenerator $urlGenerator = null,
60
+                            IFactory $l10nFac = null,
61
+                            IUserSession $userSession = null,
62
+                            IGroupManager$groupManager = null) {
63
+        $this->appManager = $appManager;
64
+        $this->urlGenerator = $urlGenerator;
65
+        $this->l10nFac = $l10nFac;
66
+        $this->userSession = $userSession;
67
+        $this->groupManager = $groupManager;
68
+    }
69
+
70
+    /**
71
+     * Creates a new navigation entry
72
+     *
73
+     * @param array|\Closure $entry Array containing: id, name, order, icon and href key
74
+     *					The use of a closure is preferred, because it will avoid
75
+     * 					loading the routing of your app, unless required.
76
+     * @return void
77
+     */
78
+    public function add($entry) {
79
+        if ($entry instanceof \Closure) {
80
+            $this->closureEntries[] = $entry;
81
+            return;
82
+        }
83
+
84
+        $entry['active'] = false;
85
+        if(!isset($entry['icon'])) {
86
+            $entry['icon'] = '';
87
+        }
88
+        $this->entries[] = $entry;
89
+    }
90
+
91
+    /**
92
+     * returns all the added Menu entries
93
+     * @return array an array of the added entries
94
+     */
95
+    public function getAll() {
96
+        $this->init();
97
+        foreach ($this->closureEntries as $c) {
98
+            $this->add($c());
99
+        }
100
+        $this->closureEntries = array();
101
+        return $this->entries;
102
+    }
103
+
104
+    /**
105
+     * removes all the entries
106
+     */
107
+    public function clear() {
108
+        $this->entries = [];
109
+        $this->closureEntries = [];
110
+        $this->init = false;
111
+    }
112
+
113
+    /**
114
+     * Sets the current navigation entry of the currently running app
115
+     * @param string $id of the app entry to activate (from added $entry)
116
+     */
117
+    public function setActiveEntry($id) {
118
+        $this->activeEntry = $id;
119
+    }
120
+
121
+    /**
122
+     * gets the active Menu entry
123
+     * @return string id or empty string
124
+     *
125
+     * This function returns the id of the active navigation entry (set by
126
+     * setActiveEntry
127
+     */
128
+    public function getActiveEntry() {
129
+        return $this->activeEntry;
130
+    }
131
+
132
+    private function init() {
133
+        if ($this->init) {
134
+            return;
135
+        }
136
+        $this->init = true;
137
+        if (is_null($this->appManager)) {
138
+            return;
139
+        }
140
+        foreach ($this->appManager->getInstalledApps() as $app) {
141
+            // load plugins and collections from info.xml
142
+            $info = $this->appManager->getAppInfo($app);
143
+            if (!isset($info['navigation'])) {
144
+                continue;
145
+            }
146
+            $nav = $info['navigation'];
147
+            if (!isset($nav['name'])) {
148
+                continue;
149
+            }
150
+            if (!isset($nav['route'])) {
151
+                continue;
152
+            }
153
+            $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
154
+            if ($role === 'admin' && !$this->isAdmin()) {
155
+                continue;
156
+            }
157
+            $l = $this->l10nFac->get($app);
158
+            $order = isset($nav['order']) ? $nav['order'] : 100;
159
+            $route = $this->urlGenerator->linkToRoute($nav['route']);
160
+            $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
161
+            foreach ([$icon, "$app.svg"] as $i) {
162
+                try {
163
+                    $icon = $this->urlGenerator->imagePath($app, $i);
164
+                    break;
165
+                } catch (\RuntimeException $ex) {
166
+                    // no icon? - ignore it then
167
+                }
168
+            }
169
+            if (is_null($icon)) {
170
+                $icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
171
+            }
172
+
173
+            $this->add([
174
+                'id' => $app,
175
+                'order' => $order,
176
+                'href' => $route,
177
+                'icon' => $icon,
178
+                'name' => $l->t($nav['name']),
179
+            ]);
180
+        }
181
+
182
+        if ($this->isAdmin()) {
183
+            $l = $this->l10nFac->get('settings');
184
+            $this->add([
185
+                'id' => 'core_apps',
186
+                'order' => 9999,
187
+                'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
188
+                'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
189
+                'name' => $l->t('Apps'),
190
+            ]);
191
+        }
192
+    }
193
+
194
+    private function isAdmin() {
195
+        $user = $this->userSession->getUser();
196
+        if ($user !== null) {
197
+            return $this->groupManager->isAdmin($user->getUID());
198
+        }
199
+        return false;
200
+    }
201 201
 
202 202
 }
Please login to merge, or discard this patch.