@@ -4,7 +4,7 @@ discard block |
||
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,7 +14,7 @@ discard block |
||
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->getColorPrimary()); ?>"> |
20 | 20 | <link rel="icon" href="<?php print_unescaped(image_path($_['appid'], 'favicon.ico')); /* IE11+ supports png */ ?>"> |
@@ -26,18 +26,18 @@ discard block |
||
26 | 26 | <?php print_unescaped($_['inline_ocjs']); ?> |
27 | 27 | </script> |
28 | 28 | <?php endif; ?> |
29 | - <?php foreach($_['cssfiles'] as $cssfile): ?> |
|
29 | + <?php foreach ($_['cssfiles'] as $cssfile): ?> |
|
30 | 30 | <link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>"> |
31 | 31 | <?php endforeach; ?> |
32 | - <?php foreach($_['printcssfiles'] as $cssfile): ?> |
|
32 | + <?php foreach ($_['printcssfiles'] as $cssfile): ?> |
|
33 | 33 | <link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="print"> |
34 | 34 | <?php endforeach; ?> |
35 | - <?php foreach($_['jsfiles'] as $jsfile): ?> |
|
35 | + <?php foreach ($_['jsfiles'] as $jsfile): ?> |
|
36 | 36 | <script nonce="<?php p(\OC::$server->getContentSecurityPolicyNonceManager()->getNonce()) ?>" src="<?php print_unescaped($jsfile); ?>"></script> |
37 | 37 | <?php endforeach; ?> |
38 | 38 | <?php print_unescaped($_['headers']); ?> |
39 | 39 | </head> |
40 | - <body id="<?php p($_['bodyid']);?>"> |
|
40 | + <body id="<?php p($_['bodyid']); ?>"> |
|
41 | 41 | <?php include('layout.noscript.warning.php'); ?> |
42 | 42 | <div id="notification-container"> |
43 | 43 | <div id="notification"></div> |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | <a href="#" class="header-appname-container menutoggle" tabindex="2"> |
57 | 57 | <h1 class="header-appname"> |
58 | - <?php p(!empty($_['application'])?$_['application']: $l->t('Apps')); ?> |
|
58 | + <?php p(!empty($_['application']) ? $_['application'] : $l->t('Apps')); ?> |
|
59 | 59 | </h1> |
60 | 60 | <div class="icon-caret"></div> |
61 | 61 | </a> |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | <a href="<?php print_unescaped($entry['href']); ?>" |
67 | 67 | tabindex="3" |
68 | 68 | <?php if ($entry['active']): ?> class="active"<?php endif; ?>> |
69 | - <img src="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>" |
|
69 | + <img src="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>" |
|
70 | 70 | class="app-icon"/> |
71 | 71 | <div class="icon-loading-small-dark" |
72 | 72 | style="display:none;"></div> |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | <div id="navigation"> |
89 | 89 | <div id="apps"> |
90 | 90 | <ul> |
91 | - <?php foreach($_['navigation'] as $entry): ?> |
|
91 | + <?php foreach ($_['navigation'] as $entry): ?> |
|
92 | 92 | <li data-id="<?php p($entry['id']); ?>"> |
93 | 93 | <a href="<?php print_unescaped($entry['href']); ?>" tabindex="3" |
94 | - <?php if( $entry['active'] ): ?> class="active"<?php endif; ?>> |
|
94 | + <?php if ($entry['active']): ?> class="active"<?php endif; ?>> |
|
95 | 95 | <svg width="16" height="16" viewBox="0 0 16 16"> |
96 | 96 | <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> |
97 | - <image x="0" y="0" width="16" height="16" preserveAspectRatio="xMinYMin meet" filter="url(#invert-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>" class="app-icon"></image> |
|
97 | + <image x="0" y="0" width="16" height="16" preserveAspectRatio="xMinYMin meet" filter="url(#invert-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>" class="app-icon"></image> |
|
98 | 98 | </svg> |
99 | 99 | <div class="icon-loading-small-dark" style="display:none;"></div> |
100 | 100 | <span><?php p($entry['name']); ?></span> |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | <div id="header-right"> |
112 | 112 | <form class="searchbox" action="#" method="post" role="search" novalidate> |
113 | 113 | <label for="searchbox" class="hidden-visually"> |
114 | - <?php p($l->t('Search'));?> |
|
114 | + <?php p($l->t('Search')); ?> |
|
115 | 115 | </label> |
116 | 116 | <input id="searchbox" type="search" name="query" |
117 | 117 | value="" required |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | <div class="avatardiv<?php if ($_['userAvatarSet']) { print_unescaped(' avatardiv-shown'); } else { print_unescaped('" style="display: none'); } ?>"> |
124 | 124 | <?php if ($_['userAvatarSet']): ?> |
125 | 125 | <img alt="" width="32" height="32" |
126 | - src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']]));?>" |
|
127 | - 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" |
|
126 | + src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']])); ?>" |
|
127 | + 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 | 128 | > |
129 | 129 | <?php endif; ?> |
130 | 130 | </div> |
@@ -132,11 +132,11 @@ discard block |
||
132 | 132 | </div> |
133 | 133 | <div id="expanddiv"> |
134 | 134 | <ul> |
135 | - <?php foreach($_['settingsnavigation'] as $entry):?> |
|
135 | + <?php foreach ($_['settingsnavigation'] as $entry):?> |
|
136 | 136 | <li> |
137 | 137 | <a href="<?php print_unescaped($entry['href']); ?>" |
138 | - <?php if( $entry["active"] ): ?> class="active"<?php endif; ?>> |
|
139 | - <img alt="" src="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>"> |
|
138 | + <?php if ($entry["active"]): ?> class="active"<?php endif; ?>> |
|
139 | + <img alt="" src="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>"> |
|
140 | 140 | <?php p($entry['name']) ?> |
141 | 141 | </a> |
142 | 142 | </li> |
@@ -61,1212 +61,1212 @@ |
||
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 | - // This is private as well. It simply works, so don't ask for more details |
|
461 | - private static function proceedNavigation($list) { |
|
462 | - usort($list, function($a, $b) { |
|
463 | - if (isset($a['order']) && isset($b['order'])) { |
|
464 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
465 | - } else if (isset($a['order']) || isset($b['order'])) { |
|
466 | - return isset($a['order']) ? -1 : 1; |
|
467 | - } else { |
|
468 | - return ($a['name'] < $b['name']) ? -1 : 1; |
|
469 | - } |
|
470 | - }); |
|
471 | - |
|
472 | - $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
473 | - foreach ($list as $index => &$navEntry) { |
|
474 | - if ($navEntry['id'] == $activeApp) { |
|
475 | - $navEntry['active'] = true; |
|
476 | - } else { |
|
477 | - $navEntry['active'] = false; |
|
478 | - } |
|
479 | - } |
|
480 | - unset($navEntry); |
|
481 | - |
|
482 | - return $list; |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * Get the path where to install apps |
|
487 | - * |
|
488 | - * @return string|false |
|
489 | - */ |
|
490 | - public static function getInstallPath() { |
|
491 | - if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
492 | - return false; |
|
493 | - } |
|
494 | - |
|
495 | - foreach (OC::$APPSROOTS as $dir) { |
|
496 | - if (isset($dir['writable']) && $dir['writable'] === true) { |
|
497 | - return $dir['path']; |
|
498 | - } |
|
499 | - } |
|
500 | - |
|
501 | - \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
502 | - return null; |
|
503 | - } |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * search for an app in all app-directories |
|
508 | - * |
|
509 | - * @param string $appId |
|
510 | - * @return false|string |
|
511 | - */ |
|
512 | - public static function findAppInDirectories($appId) { |
|
513 | - $sanitizedAppId = self::cleanAppId($appId); |
|
514 | - if($sanitizedAppId !== $appId) { |
|
515 | - return false; |
|
516 | - } |
|
517 | - static $app_dir = array(); |
|
518 | - |
|
519 | - if (isset($app_dir[$appId])) { |
|
520 | - return $app_dir[$appId]; |
|
521 | - } |
|
522 | - |
|
523 | - $possibleApps = array(); |
|
524 | - foreach (OC::$APPSROOTS as $dir) { |
|
525 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
526 | - $possibleApps[] = $dir; |
|
527 | - } |
|
528 | - } |
|
529 | - |
|
530 | - if (empty($possibleApps)) { |
|
531 | - return false; |
|
532 | - } elseif (count($possibleApps) === 1) { |
|
533 | - $dir = array_shift($possibleApps); |
|
534 | - $app_dir[$appId] = $dir; |
|
535 | - return $dir; |
|
536 | - } else { |
|
537 | - $versionToLoad = array(); |
|
538 | - foreach ($possibleApps as $possibleApp) { |
|
539 | - $version = self::getAppVersionByPath($possibleApp['path']); |
|
540 | - if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
541 | - $versionToLoad = array( |
|
542 | - 'dir' => $possibleApp, |
|
543 | - 'version' => $version, |
|
544 | - ); |
|
545 | - } |
|
546 | - } |
|
547 | - $app_dir[$appId] = $versionToLoad['dir']; |
|
548 | - return $versionToLoad['dir']; |
|
549 | - //TODO - write test |
|
550 | - } |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Get the directory for the given app. |
|
555 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
556 | - * |
|
557 | - * @param string $appId |
|
558 | - * @return string|false |
|
559 | - */ |
|
560 | - public static function getAppPath($appId) { |
|
561 | - if ($appId === null || trim($appId) === '') { |
|
562 | - return false; |
|
563 | - } |
|
564 | - |
|
565 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
566 | - return $dir['path'] . '/' . $appId; |
|
567 | - } |
|
568 | - return false; |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Get the path for the given app on the access |
|
573 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
574 | - * |
|
575 | - * @param string $appId |
|
576 | - * @return string|false |
|
577 | - */ |
|
578 | - public static function getAppWebPath($appId) { |
|
579 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
580 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
581 | - } |
|
582 | - return false; |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * get the last version of the app from appinfo/info.xml |
|
587 | - * |
|
588 | - * @param string $appId |
|
589 | - * @param bool $useCache |
|
590 | - * @return string |
|
591 | - */ |
|
592 | - public static function getAppVersion($appId, $useCache = true) { |
|
593 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
594 | - return self::$appVersion[$appId]; |
|
595 | - } |
|
596 | - |
|
597 | - $file = self::getAppPath($appId); |
|
598 | - self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
599 | - return self::$appVersion[$appId]; |
|
600 | - } |
|
601 | - |
|
602 | - /** |
|
603 | - * get app's version based on it's path |
|
604 | - * |
|
605 | - * @param string $path |
|
606 | - * @return string |
|
607 | - */ |
|
608 | - public static function getAppVersionByPath($path) { |
|
609 | - $infoFile = $path . '/appinfo/info.xml'; |
|
610 | - $appData = self::getAppInfo($infoFile, true); |
|
611 | - return isset($appData['version']) ? $appData['version'] : ''; |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * Read all app metadata from the info.xml file |
|
617 | - * |
|
618 | - * @param string $appId id of the app or the path of the info.xml file |
|
619 | - * @param bool $path |
|
620 | - * @param string $lang |
|
621 | - * @return array|null |
|
622 | - * @note all data is read from info.xml, not just pre-defined fields |
|
623 | - */ |
|
624 | - public static function getAppInfo($appId, $path = false, $lang = null) { |
|
625 | - if ($path) { |
|
626 | - $file = $appId; |
|
627 | - } else { |
|
628 | - if ($lang === null && isset(self::$appInfo[$appId])) { |
|
629 | - return self::$appInfo[$appId]; |
|
630 | - } |
|
631 | - $appPath = self::getAppPath($appId); |
|
632 | - if($appPath === false) { |
|
633 | - return null; |
|
634 | - } |
|
635 | - $file = $appPath . '/appinfo/info.xml'; |
|
636 | - } |
|
637 | - |
|
638 | - $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
|
639 | - $data = $parser->parse($file); |
|
640 | - |
|
641 | - if (is_array($data)) { |
|
642 | - $data = OC_App::parseAppInfo($data, $lang); |
|
643 | - } |
|
644 | - if(isset($data['ocsid'])) { |
|
645 | - $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
646 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
647 | - $data['ocsid'] = $storedId; |
|
648 | - } |
|
649 | - } |
|
650 | - |
|
651 | - if ($lang === null) { |
|
652 | - self::$appInfo[$appId] = $data; |
|
653 | - } |
|
654 | - |
|
655 | - return $data; |
|
656 | - } |
|
657 | - |
|
658 | - /** |
|
659 | - * Returns the navigation |
|
660 | - * |
|
661 | - * @return array |
|
662 | - * |
|
663 | - * This function returns an array containing all entries added. The |
|
664 | - * entries are sorted by the key 'order' ascending. Additional to the keys |
|
665 | - * given for each app the following keys exist: |
|
666 | - * - active: boolean, signals if the user is on this navigation entry |
|
667 | - */ |
|
668 | - public static function getNavigation() { |
|
669 | - $entries = OC::$server->getNavigationManager()->getAll(); |
|
670 | - return self::proceedNavigation($entries); |
|
671 | - } |
|
672 | - |
|
673 | - /** |
|
674 | - * Returns the Settings Navigation |
|
675 | - * |
|
676 | - * @return string[] |
|
677 | - * |
|
678 | - * This function returns an array containing all settings pages added. The |
|
679 | - * entries are sorted by the key 'order' ascending. |
|
680 | - */ |
|
681 | - public static function getSettingsNavigation() { |
|
682 | - $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
683 | - return self::proceedNavigation($entries); |
|
684 | - } |
|
685 | - |
|
686 | - /** |
|
687 | - * get the id of loaded app |
|
688 | - * |
|
689 | - * @return string |
|
690 | - */ |
|
691 | - public static function getCurrentApp() { |
|
692 | - $request = \OC::$server->getRequest(); |
|
693 | - $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
694 | - $topFolder = substr($script, 0, strpos($script, '/')); |
|
695 | - if (empty($topFolder)) { |
|
696 | - $path_info = $request->getPathInfo(); |
|
697 | - if ($path_info) { |
|
698 | - $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
699 | - } |
|
700 | - } |
|
701 | - if ($topFolder == 'apps') { |
|
702 | - $length = strlen($topFolder); |
|
703 | - return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
704 | - } else { |
|
705 | - return $topFolder; |
|
706 | - } |
|
707 | - } |
|
708 | - |
|
709 | - /** |
|
710 | - * @param string $type |
|
711 | - * @return array |
|
712 | - */ |
|
713 | - public static function getForms($type) { |
|
714 | - $forms = array(); |
|
715 | - switch ($type) { |
|
716 | - case 'admin': |
|
717 | - $source = self::$adminForms; |
|
718 | - break; |
|
719 | - case 'personal': |
|
720 | - $source = self::$personalForms; |
|
721 | - break; |
|
722 | - default: |
|
723 | - return array(); |
|
724 | - } |
|
725 | - foreach ($source as $form) { |
|
726 | - $forms[] = include $form; |
|
727 | - } |
|
728 | - return $forms; |
|
729 | - } |
|
730 | - |
|
731 | - /** |
|
732 | - * register an admin form to be shown |
|
733 | - * |
|
734 | - * @param string $app |
|
735 | - * @param string $page |
|
736 | - */ |
|
737 | - public static function registerAdmin($app, $page) { |
|
738 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
739 | - } |
|
740 | - |
|
741 | - /** |
|
742 | - * register a personal form to be shown |
|
743 | - * @param string $app |
|
744 | - * @param string $page |
|
745 | - */ |
|
746 | - public static function registerPersonal($app, $page) { |
|
747 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
748 | - } |
|
749 | - |
|
750 | - /** |
|
751 | - * @param array $entry |
|
752 | - */ |
|
753 | - public static function registerLogIn(array $entry) { |
|
754 | - self::$altLogin[] = $entry; |
|
755 | - } |
|
756 | - |
|
757 | - /** |
|
758 | - * @return array |
|
759 | - */ |
|
760 | - public static function getAlternativeLogIns() { |
|
761 | - return self::$altLogin; |
|
762 | - } |
|
763 | - |
|
764 | - /** |
|
765 | - * get a list of all apps in the apps folder |
|
766 | - * |
|
767 | - * @return array an array of app names (string IDs) |
|
768 | - * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
769 | - */ |
|
770 | - public static function getAllApps() { |
|
771 | - |
|
772 | - $apps = array(); |
|
773 | - |
|
774 | - foreach (OC::$APPSROOTS as $apps_dir) { |
|
775 | - if (!is_readable($apps_dir['path'])) { |
|
776 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
777 | - continue; |
|
778 | - } |
|
779 | - $dh = opendir($apps_dir['path']); |
|
780 | - |
|
781 | - if (is_resource($dh)) { |
|
782 | - while (($file = readdir($dh)) !== false) { |
|
783 | - |
|
784 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
785 | - |
|
786 | - $apps[] = $file; |
|
787 | - } |
|
788 | - } |
|
789 | - } |
|
790 | - } |
|
791 | - |
|
792 | - return $apps; |
|
793 | - } |
|
794 | - |
|
795 | - /** |
|
796 | - * List all apps, this is used in apps.php |
|
797 | - * |
|
798 | - * @return array |
|
799 | - */ |
|
800 | - public function listAllApps() { |
|
801 | - $installedApps = OC_App::getAllApps(); |
|
802 | - |
|
803 | - //we don't want to show configuration for these |
|
804 | - $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
805 | - $appList = array(); |
|
806 | - $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
807 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
808 | - |
|
809 | - foreach ($installedApps as $app) { |
|
810 | - if (array_search($app, $blacklist) === false) { |
|
811 | - |
|
812 | - $info = OC_App::getAppInfo($app, false, $langCode); |
|
813 | - if (!is_array($info)) { |
|
814 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
815 | - continue; |
|
816 | - } |
|
817 | - |
|
818 | - if (!isset($info['name'])) { |
|
819 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
820 | - continue; |
|
821 | - } |
|
822 | - |
|
823 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
824 | - $info['groups'] = null; |
|
825 | - if ($enabled === 'yes') { |
|
826 | - $active = true; |
|
827 | - } else if ($enabled === 'no') { |
|
828 | - $active = false; |
|
829 | - } else { |
|
830 | - $active = true; |
|
831 | - $info['groups'] = $enabled; |
|
832 | - } |
|
833 | - |
|
834 | - $info['active'] = $active; |
|
835 | - |
|
836 | - if (self::isShipped($app)) { |
|
837 | - $info['internal'] = true; |
|
838 | - $info['level'] = self::officialApp; |
|
839 | - $info['removable'] = false; |
|
840 | - } else { |
|
841 | - $info['internal'] = false; |
|
842 | - $info['removable'] = true; |
|
843 | - } |
|
844 | - |
|
845 | - $appPath = self::getAppPath($app); |
|
846 | - if($appPath !== false) { |
|
847 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
848 | - if (file_exists($appIcon)) { |
|
849 | - $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg'); |
|
850 | - $info['previewAsIcon'] = true; |
|
851 | - } else { |
|
852 | - $appIcon = $appPath . '/img/app.svg'; |
|
853 | - if (file_exists($appIcon)) { |
|
854 | - $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg'); |
|
855 | - $info['previewAsIcon'] = true; |
|
856 | - } |
|
857 | - } |
|
858 | - } |
|
859 | - // fix documentation |
|
860 | - if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
861 | - foreach ($info['documentation'] as $key => $url) { |
|
862 | - // If it is not an absolute URL we assume it is a key |
|
863 | - // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
864 | - if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
865 | - $url = $urlGenerator->linkToDocs($url); |
|
866 | - } |
|
867 | - |
|
868 | - $info['documentation'][$key] = $url; |
|
869 | - } |
|
870 | - } |
|
871 | - |
|
872 | - $info['version'] = OC_App::getAppVersion($app); |
|
873 | - $appList[] = $info; |
|
874 | - } |
|
875 | - } |
|
876 | - |
|
877 | - return $appList; |
|
878 | - } |
|
879 | - |
|
880 | - /** |
|
881 | - * Returns the internal app ID or false |
|
882 | - * @param string $ocsID |
|
883 | - * @return string|false |
|
884 | - */ |
|
885 | - public static function getInternalAppIdByOcs($ocsID) { |
|
886 | - if(is_numeric($ocsID)) { |
|
887 | - $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
|
888 | - if(array_search($ocsID, $idArray)) { |
|
889 | - return array_search($ocsID, $idArray); |
|
890 | - } |
|
891 | - } |
|
892 | - return false; |
|
893 | - } |
|
894 | - |
|
895 | - public static function shouldUpgrade($app) { |
|
896 | - $versions = self::getAppVersions(); |
|
897 | - $currentVersion = OC_App::getAppVersion($app); |
|
898 | - if ($currentVersion && isset($versions[$app])) { |
|
899 | - $installedVersion = $versions[$app]; |
|
900 | - if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
901 | - return true; |
|
902 | - } |
|
903 | - } |
|
904 | - return false; |
|
905 | - } |
|
906 | - |
|
907 | - /** |
|
908 | - * Adjust the number of version parts of $version1 to match |
|
909 | - * the number of version parts of $version2. |
|
910 | - * |
|
911 | - * @param string $version1 version to adjust |
|
912 | - * @param string $version2 version to take the number of parts from |
|
913 | - * @return string shortened $version1 |
|
914 | - */ |
|
915 | - private static function adjustVersionParts($version1, $version2) { |
|
916 | - $version1 = explode('.', $version1); |
|
917 | - $version2 = explode('.', $version2); |
|
918 | - // reduce $version1 to match the number of parts in $version2 |
|
919 | - while (count($version1) > count($version2)) { |
|
920 | - array_pop($version1); |
|
921 | - } |
|
922 | - // if $version1 does not have enough parts, add some |
|
923 | - while (count($version1) < count($version2)) { |
|
924 | - $version1[] = '0'; |
|
925 | - } |
|
926 | - return implode('.', $version1); |
|
927 | - } |
|
928 | - |
|
929 | - /** |
|
930 | - * Check whether the current ownCloud version matches the given |
|
931 | - * application's version requirements. |
|
932 | - * |
|
933 | - * The comparison is made based on the number of parts that the |
|
934 | - * app info version has. For example for ownCloud 6.0.3 if the |
|
935 | - * app info version is expecting version 6.0, the comparison is |
|
936 | - * made on the first two parts of the ownCloud version. |
|
937 | - * This means that it's possible to specify "requiremin" => 6 |
|
938 | - * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
939 | - * |
|
940 | - * @param string $ocVersion ownCloud version to check against |
|
941 | - * @param array $appInfo app info (from xml) |
|
942 | - * |
|
943 | - * @return boolean true if compatible, otherwise false |
|
944 | - */ |
|
945 | - public static function isAppCompatible($ocVersion, $appInfo) { |
|
946 | - $requireMin = ''; |
|
947 | - $requireMax = ''; |
|
948 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
949 | - $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
950 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
951 | - $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
952 | - } else if (isset($appInfo['requiremin'])) { |
|
953 | - $requireMin = $appInfo['requiremin']; |
|
954 | - } else if (isset($appInfo['require'])) { |
|
955 | - $requireMin = $appInfo['require']; |
|
956 | - } |
|
957 | - |
|
958 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
959 | - $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
960 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
961 | - $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
962 | - } else if (isset($appInfo['requiremax'])) { |
|
963 | - $requireMax = $appInfo['requiremax']; |
|
964 | - } |
|
965 | - |
|
966 | - if (is_array($ocVersion)) { |
|
967 | - $ocVersion = implode('.', $ocVersion); |
|
968 | - } |
|
969 | - |
|
970 | - if (!empty($requireMin) |
|
971 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
972 | - ) { |
|
973 | - |
|
974 | - return false; |
|
975 | - } |
|
976 | - |
|
977 | - if (!empty($requireMax) |
|
978 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
979 | - ) { |
|
980 | - return false; |
|
981 | - } |
|
982 | - |
|
983 | - return true; |
|
984 | - } |
|
985 | - |
|
986 | - /** |
|
987 | - * get the installed version of all apps |
|
988 | - */ |
|
989 | - public static function getAppVersions() { |
|
990 | - static $versions; |
|
991 | - |
|
992 | - if(!$versions) { |
|
993 | - $appConfig = \OC::$server->getAppConfig(); |
|
994 | - $versions = $appConfig->getValues(false, 'installed_version'); |
|
995 | - } |
|
996 | - return $versions; |
|
997 | - } |
|
998 | - |
|
999 | - /** |
|
1000 | - * @param string $app |
|
1001 | - * @param \OCP\IConfig $config |
|
1002 | - * @param \OCP\IL10N $l |
|
1003 | - * @return bool |
|
1004 | - * |
|
1005 | - * @throws Exception if app is not compatible with this version of ownCloud |
|
1006 | - * @throws Exception if no app-name was specified |
|
1007 | - */ |
|
1008 | - public function installApp($app, |
|
1009 | - \OCP\IConfig $config, |
|
1010 | - \OCP\IL10N $l) { |
|
1011 | - if ($app !== false) { |
|
1012 | - // check if the app is compatible with this version of ownCloud |
|
1013 | - $info = self::getAppInfo($app); |
|
1014 | - if(!is_array($info)) { |
|
1015 | - throw new \Exception( |
|
1016 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
1017 | - [$info['name']] |
|
1018 | - ) |
|
1019 | - ); |
|
1020 | - } |
|
1021 | - |
|
1022 | - $version = \OCP\Util::getVersion(); |
|
1023 | - if (!self::isAppCompatible($version, $info)) { |
|
1024 | - throw new \Exception( |
|
1025 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
1026 | - array($info['name']) |
|
1027 | - ) |
|
1028 | - ); |
|
1029 | - } |
|
1030 | - |
|
1031 | - // check for required dependencies |
|
1032 | - self::checkAppDependencies($config, $l, $info); |
|
1033 | - |
|
1034 | - $config->setAppValue($app, 'enabled', 'yes'); |
|
1035 | - if (isset($appData['id'])) { |
|
1036 | - $config->setAppValue($app, 'ocsid', $appData['id']); |
|
1037 | - } |
|
1038 | - |
|
1039 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
1040 | - $appPath = self::getAppPath($app); |
|
1041 | - self::registerAutoloading($app, $appPath); |
|
1042 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
1043 | - } |
|
1044 | - |
|
1045 | - \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
1046 | - } else { |
|
1047 | - if(empty($appName) ) { |
|
1048 | - throw new \Exception($l->t("No app name specified")); |
|
1049 | - } else { |
|
1050 | - throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
1051 | - } |
|
1052 | - } |
|
1053 | - |
|
1054 | - return $app; |
|
1055 | - } |
|
1056 | - |
|
1057 | - /** |
|
1058 | - * update the database for the app and call the update script |
|
1059 | - * |
|
1060 | - * @param string $appId |
|
1061 | - * @return bool |
|
1062 | - */ |
|
1063 | - public static function updateApp($appId) { |
|
1064 | - $appPath = self::getAppPath($appId); |
|
1065 | - if($appPath === false) { |
|
1066 | - return false; |
|
1067 | - } |
|
1068 | - $appData = self::getAppInfo($appId); |
|
1069 | - self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1070 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1071 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1072 | - } |
|
1073 | - self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1074 | - self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1075 | - unset(self::$appVersion[$appId]); |
|
1076 | - // run upgrade code |
|
1077 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
1078 | - self::loadApp($appId); |
|
1079 | - include $appPath . '/appinfo/update.php'; |
|
1080 | - } |
|
1081 | - self::setupBackgroundJobs($appData['background-jobs']); |
|
1082 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1083 | - $appPath = self::getAppPath($appId); |
|
1084 | - self::registerAutoloading($appId, $appPath); |
|
1085 | - \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
1086 | - } |
|
1087 | - |
|
1088 | - //set remote/public handlers |
|
1089 | - if (array_key_exists('ocsid', $appData)) { |
|
1090 | - \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1091 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1092 | - \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1093 | - } |
|
1094 | - foreach ($appData['remote'] as $name => $path) { |
|
1095 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1096 | - } |
|
1097 | - foreach ($appData['public'] as $name => $path) { |
|
1098 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1099 | - } |
|
1100 | - |
|
1101 | - self::setAppTypes($appId); |
|
1102 | - |
|
1103 | - $version = \OC_App::getAppVersion($appId); |
|
1104 | - \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
1105 | - |
|
1106 | - \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1107 | - ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1108 | - )); |
|
1109 | - |
|
1110 | - return true; |
|
1111 | - } |
|
1112 | - |
|
1113 | - /** |
|
1114 | - * @param string $appId |
|
1115 | - * @param string[] $steps |
|
1116 | - * @throws \OC\NeedsUpdateException |
|
1117 | - */ |
|
1118 | - public static function executeRepairSteps($appId, array $steps) { |
|
1119 | - if (empty($steps)) { |
|
1120 | - return; |
|
1121 | - } |
|
1122 | - // load the app |
|
1123 | - self::loadApp($appId); |
|
1124 | - |
|
1125 | - $dispatcher = OC::$server->getEventDispatcher(); |
|
1126 | - |
|
1127 | - // load the steps |
|
1128 | - $r = new Repair([], $dispatcher); |
|
1129 | - foreach ($steps as $step) { |
|
1130 | - try { |
|
1131 | - $r->addStep($step); |
|
1132 | - } catch (Exception $ex) { |
|
1133 | - $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1134 | - \OC::$server->getLogger()->logException($ex); |
|
1135 | - } |
|
1136 | - } |
|
1137 | - // run the steps |
|
1138 | - $r->run(); |
|
1139 | - } |
|
1140 | - |
|
1141 | - public static function setupBackgroundJobs(array $jobs) { |
|
1142 | - $queue = \OC::$server->getJobList(); |
|
1143 | - foreach ($jobs as $job) { |
|
1144 | - $queue->add($job); |
|
1145 | - } |
|
1146 | - } |
|
1147 | - |
|
1148 | - /** |
|
1149 | - * @param string $appId |
|
1150 | - * @param string[] $steps |
|
1151 | - */ |
|
1152 | - private static function setupLiveMigrations($appId, array $steps) { |
|
1153 | - $queue = \OC::$server->getJobList(); |
|
1154 | - foreach ($steps as $step) { |
|
1155 | - $queue->add('OC\Migration\BackgroundRepair', [ |
|
1156 | - 'app' => $appId, |
|
1157 | - 'step' => $step]); |
|
1158 | - } |
|
1159 | - } |
|
1160 | - |
|
1161 | - /** |
|
1162 | - * @param string $appId |
|
1163 | - * @return \OC\Files\View|false |
|
1164 | - */ |
|
1165 | - public static function getStorage($appId) { |
|
1166 | - if (OC_App::isEnabled($appId)) { //sanity check |
|
1167 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1168 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1169 | - if (!$view->file_exists($appId)) { |
|
1170 | - $view->mkdir($appId); |
|
1171 | - } |
|
1172 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1173 | - } else { |
|
1174 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1175 | - return false; |
|
1176 | - } |
|
1177 | - } else { |
|
1178 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1179 | - return false; |
|
1180 | - } |
|
1181 | - } |
|
1182 | - |
|
1183 | - protected static function findBestL10NOption($options, $lang) { |
|
1184 | - $fallback = $similarLangFallback = $englishFallback = false; |
|
1185 | - |
|
1186 | - $lang = strtolower($lang); |
|
1187 | - $similarLang = $lang; |
|
1188 | - if (strpos($similarLang, '_')) { |
|
1189 | - // For "de_DE" we want to find "de" and the other way around |
|
1190 | - $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1191 | - } |
|
1192 | - |
|
1193 | - foreach ($options as $option) { |
|
1194 | - if (is_array($option)) { |
|
1195 | - if ($fallback === false) { |
|
1196 | - $fallback = $option['@value']; |
|
1197 | - } |
|
1198 | - |
|
1199 | - if (!isset($option['@attributes']['lang'])) { |
|
1200 | - continue; |
|
1201 | - } |
|
1202 | - |
|
1203 | - $attributeLang = strtolower($option['@attributes']['lang']); |
|
1204 | - if ($attributeLang === $lang) { |
|
1205 | - return $option['@value']; |
|
1206 | - } |
|
1207 | - |
|
1208 | - if ($attributeLang === $similarLang) { |
|
1209 | - $similarLangFallback = $option['@value']; |
|
1210 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1211 | - if ($similarLangFallback === false) { |
|
1212 | - $similarLangFallback = $option['@value']; |
|
1213 | - } |
|
1214 | - } |
|
1215 | - } else { |
|
1216 | - $englishFallback = $option; |
|
1217 | - } |
|
1218 | - } |
|
1219 | - |
|
1220 | - if ($similarLangFallback !== false) { |
|
1221 | - return $similarLangFallback; |
|
1222 | - } else if ($englishFallback !== false) { |
|
1223 | - return $englishFallback; |
|
1224 | - } |
|
1225 | - return (string) $fallback; |
|
1226 | - } |
|
1227 | - |
|
1228 | - /** |
|
1229 | - * parses the app data array and enhanced the 'description' value |
|
1230 | - * |
|
1231 | - * @param array $data the app data |
|
1232 | - * @param string $lang |
|
1233 | - * @return array improved app data |
|
1234 | - */ |
|
1235 | - public static function parseAppInfo(array $data, $lang = null) { |
|
1236 | - |
|
1237 | - if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1238 | - $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1239 | - } |
|
1240 | - if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1241 | - $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1242 | - } |
|
1243 | - if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1244 | - $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1245 | - } else if (isset($data['description']) && is_string($data['description'])) { |
|
1246 | - $data['description'] = trim($data['description']); |
|
1247 | - } else { |
|
1248 | - $data['description'] = ''; |
|
1249 | - } |
|
1250 | - |
|
1251 | - return $data; |
|
1252 | - } |
|
1253 | - |
|
1254 | - /** |
|
1255 | - * @param \OCP\IConfig $config |
|
1256 | - * @param \OCP\IL10N $l |
|
1257 | - * @param array $info |
|
1258 | - * @throws \Exception |
|
1259 | - */ |
|
1260 | - protected static function checkAppDependencies($config, $l, $info) { |
|
1261 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1262 | - $missing = $dependencyAnalyzer->analyze($info); |
|
1263 | - if (!empty($missing)) { |
|
1264 | - $missingMsg = join(PHP_EOL, $missing); |
|
1265 | - throw new \Exception( |
|
1266 | - $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1267 | - [$info['name'], $missingMsg] |
|
1268 | - ) |
|
1269 | - ); |
|
1270 | - } |
|
1271 | - } |
|
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 | + // This is private as well. It simply works, so don't ask for more details |
|
461 | + private static function proceedNavigation($list) { |
|
462 | + usort($list, function($a, $b) { |
|
463 | + if (isset($a['order']) && isset($b['order'])) { |
|
464 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
465 | + } else if (isset($a['order']) || isset($b['order'])) { |
|
466 | + return isset($a['order']) ? -1 : 1; |
|
467 | + } else { |
|
468 | + return ($a['name'] < $b['name']) ? -1 : 1; |
|
469 | + } |
|
470 | + }); |
|
471 | + |
|
472 | + $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
473 | + foreach ($list as $index => &$navEntry) { |
|
474 | + if ($navEntry['id'] == $activeApp) { |
|
475 | + $navEntry['active'] = true; |
|
476 | + } else { |
|
477 | + $navEntry['active'] = false; |
|
478 | + } |
|
479 | + } |
|
480 | + unset($navEntry); |
|
481 | + |
|
482 | + return $list; |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * Get the path where to install apps |
|
487 | + * |
|
488 | + * @return string|false |
|
489 | + */ |
|
490 | + public static function getInstallPath() { |
|
491 | + if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
492 | + return false; |
|
493 | + } |
|
494 | + |
|
495 | + foreach (OC::$APPSROOTS as $dir) { |
|
496 | + if (isset($dir['writable']) && $dir['writable'] === true) { |
|
497 | + return $dir['path']; |
|
498 | + } |
|
499 | + } |
|
500 | + |
|
501 | + \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
502 | + return null; |
|
503 | + } |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * search for an app in all app-directories |
|
508 | + * |
|
509 | + * @param string $appId |
|
510 | + * @return false|string |
|
511 | + */ |
|
512 | + public static function findAppInDirectories($appId) { |
|
513 | + $sanitizedAppId = self::cleanAppId($appId); |
|
514 | + if($sanitizedAppId !== $appId) { |
|
515 | + return false; |
|
516 | + } |
|
517 | + static $app_dir = array(); |
|
518 | + |
|
519 | + if (isset($app_dir[$appId])) { |
|
520 | + return $app_dir[$appId]; |
|
521 | + } |
|
522 | + |
|
523 | + $possibleApps = array(); |
|
524 | + foreach (OC::$APPSROOTS as $dir) { |
|
525 | + if (file_exists($dir['path'] . '/' . $appId)) { |
|
526 | + $possibleApps[] = $dir; |
|
527 | + } |
|
528 | + } |
|
529 | + |
|
530 | + if (empty($possibleApps)) { |
|
531 | + return false; |
|
532 | + } elseif (count($possibleApps) === 1) { |
|
533 | + $dir = array_shift($possibleApps); |
|
534 | + $app_dir[$appId] = $dir; |
|
535 | + return $dir; |
|
536 | + } else { |
|
537 | + $versionToLoad = array(); |
|
538 | + foreach ($possibleApps as $possibleApp) { |
|
539 | + $version = self::getAppVersionByPath($possibleApp['path']); |
|
540 | + if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
541 | + $versionToLoad = array( |
|
542 | + 'dir' => $possibleApp, |
|
543 | + 'version' => $version, |
|
544 | + ); |
|
545 | + } |
|
546 | + } |
|
547 | + $app_dir[$appId] = $versionToLoad['dir']; |
|
548 | + return $versionToLoad['dir']; |
|
549 | + //TODO - write test |
|
550 | + } |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Get the directory for the given app. |
|
555 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
556 | + * |
|
557 | + * @param string $appId |
|
558 | + * @return string|false |
|
559 | + */ |
|
560 | + public static function getAppPath($appId) { |
|
561 | + if ($appId === null || trim($appId) === '') { |
|
562 | + return false; |
|
563 | + } |
|
564 | + |
|
565 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
566 | + return $dir['path'] . '/' . $appId; |
|
567 | + } |
|
568 | + return false; |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Get the path for the given app on the access |
|
573 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
574 | + * |
|
575 | + * @param string $appId |
|
576 | + * @return string|false |
|
577 | + */ |
|
578 | + public static function getAppWebPath($appId) { |
|
579 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
580 | + return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
581 | + } |
|
582 | + return false; |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * get the last version of the app from appinfo/info.xml |
|
587 | + * |
|
588 | + * @param string $appId |
|
589 | + * @param bool $useCache |
|
590 | + * @return string |
|
591 | + */ |
|
592 | + public static function getAppVersion($appId, $useCache = true) { |
|
593 | + if($useCache && isset(self::$appVersion[$appId])) { |
|
594 | + return self::$appVersion[$appId]; |
|
595 | + } |
|
596 | + |
|
597 | + $file = self::getAppPath($appId); |
|
598 | + self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
599 | + return self::$appVersion[$appId]; |
|
600 | + } |
|
601 | + |
|
602 | + /** |
|
603 | + * get app's version based on it's path |
|
604 | + * |
|
605 | + * @param string $path |
|
606 | + * @return string |
|
607 | + */ |
|
608 | + public static function getAppVersionByPath($path) { |
|
609 | + $infoFile = $path . '/appinfo/info.xml'; |
|
610 | + $appData = self::getAppInfo($infoFile, true); |
|
611 | + return isset($appData['version']) ? $appData['version'] : ''; |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * Read all app metadata from the info.xml file |
|
617 | + * |
|
618 | + * @param string $appId id of the app or the path of the info.xml file |
|
619 | + * @param bool $path |
|
620 | + * @param string $lang |
|
621 | + * @return array|null |
|
622 | + * @note all data is read from info.xml, not just pre-defined fields |
|
623 | + */ |
|
624 | + public static function getAppInfo($appId, $path = false, $lang = null) { |
|
625 | + if ($path) { |
|
626 | + $file = $appId; |
|
627 | + } else { |
|
628 | + if ($lang === null && isset(self::$appInfo[$appId])) { |
|
629 | + return self::$appInfo[$appId]; |
|
630 | + } |
|
631 | + $appPath = self::getAppPath($appId); |
|
632 | + if($appPath === false) { |
|
633 | + return null; |
|
634 | + } |
|
635 | + $file = $appPath . '/appinfo/info.xml'; |
|
636 | + } |
|
637 | + |
|
638 | + $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
|
639 | + $data = $parser->parse($file); |
|
640 | + |
|
641 | + if (is_array($data)) { |
|
642 | + $data = OC_App::parseAppInfo($data, $lang); |
|
643 | + } |
|
644 | + if(isset($data['ocsid'])) { |
|
645 | + $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
646 | + if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
647 | + $data['ocsid'] = $storedId; |
|
648 | + } |
|
649 | + } |
|
650 | + |
|
651 | + if ($lang === null) { |
|
652 | + self::$appInfo[$appId] = $data; |
|
653 | + } |
|
654 | + |
|
655 | + return $data; |
|
656 | + } |
|
657 | + |
|
658 | + /** |
|
659 | + * Returns the navigation |
|
660 | + * |
|
661 | + * @return array |
|
662 | + * |
|
663 | + * This function returns an array containing all entries added. The |
|
664 | + * entries are sorted by the key 'order' ascending. Additional to the keys |
|
665 | + * given for each app the following keys exist: |
|
666 | + * - active: boolean, signals if the user is on this navigation entry |
|
667 | + */ |
|
668 | + public static function getNavigation() { |
|
669 | + $entries = OC::$server->getNavigationManager()->getAll(); |
|
670 | + return self::proceedNavigation($entries); |
|
671 | + } |
|
672 | + |
|
673 | + /** |
|
674 | + * Returns the Settings Navigation |
|
675 | + * |
|
676 | + * @return string[] |
|
677 | + * |
|
678 | + * This function returns an array containing all settings pages added. The |
|
679 | + * entries are sorted by the key 'order' ascending. |
|
680 | + */ |
|
681 | + public static function getSettingsNavigation() { |
|
682 | + $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
683 | + return self::proceedNavigation($entries); |
|
684 | + } |
|
685 | + |
|
686 | + /** |
|
687 | + * get the id of loaded app |
|
688 | + * |
|
689 | + * @return string |
|
690 | + */ |
|
691 | + public static function getCurrentApp() { |
|
692 | + $request = \OC::$server->getRequest(); |
|
693 | + $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
694 | + $topFolder = substr($script, 0, strpos($script, '/')); |
|
695 | + if (empty($topFolder)) { |
|
696 | + $path_info = $request->getPathInfo(); |
|
697 | + if ($path_info) { |
|
698 | + $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
699 | + } |
|
700 | + } |
|
701 | + if ($topFolder == 'apps') { |
|
702 | + $length = strlen($topFolder); |
|
703 | + return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
704 | + } else { |
|
705 | + return $topFolder; |
|
706 | + } |
|
707 | + } |
|
708 | + |
|
709 | + /** |
|
710 | + * @param string $type |
|
711 | + * @return array |
|
712 | + */ |
|
713 | + public static function getForms($type) { |
|
714 | + $forms = array(); |
|
715 | + switch ($type) { |
|
716 | + case 'admin': |
|
717 | + $source = self::$adminForms; |
|
718 | + break; |
|
719 | + case 'personal': |
|
720 | + $source = self::$personalForms; |
|
721 | + break; |
|
722 | + default: |
|
723 | + return array(); |
|
724 | + } |
|
725 | + foreach ($source as $form) { |
|
726 | + $forms[] = include $form; |
|
727 | + } |
|
728 | + return $forms; |
|
729 | + } |
|
730 | + |
|
731 | + /** |
|
732 | + * register an admin form to be shown |
|
733 | + * |
|
734 | + * @param string $app |
|
735 | + * @param string $page |
|
736 | + */ |
|
737 | + public static function registerAdmin($app, $page) { |
|
738 | + self::$adminForms[] = $app . '/' . $page . '.php'; |
|
739 | + } |
|
740 | + |
|
741 | + /** |
|
742 | + * register a personal form to be shown |
|
743 | + * @param string $app |
|
744 | + * @param string $page |
|
745 | + */ |
|
746 | + public static function registerPersonal($app, $page) { |
|
747 | + self::$personalForms[] = $app . '/' . $page . '.php'; |
|
748 | + } |
|
749 | + |
|
750 | + /** |
|
751 | + * @param array $entry |
|
752 | + */ |
|
753 | + public static function registerLogIn(array $entry) { |
|
754 | + self::$altLogin[] = $entry; |
|
755 | + } |
|
756 | + |
|
757 | + /** |
|
758 | + * @return array |
|
759 | + */ |
|
760 | + public static function getAlternativeLogIns() { |
|
761 | + return self::$altLogin; |
|
762 | + } |
|
763 | + |
|
764 | + /** |
|
765 | + * get a list of all apps in the apps folder |
|
766 | + * |
|
767 | + * @return array an array of app names (string IDs) |
|
768 | + * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
769 | + */ |
|
770 | + public static function getAllApps() { |
|
771 | + |
|
772 | + $apps = array(); |
|
773 | + |
|
774 | + foreach (OC::$APPSROOTS as $apps_dir) { |
|
775 | + if (!is_readable($apps_dir['path'])) { |
|
776 | + \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
777 | + continue; |
|
778 | + } |
|
779 | + $dh = opendir($apps_dir['path']); |
|
780 | + |
|
781 | + if (is_resource($dh)) { |
|
782 | + while (($file = readdir($dh)) !== false) { |
|
783 | + |
|
784 | + if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
785 | + |
|
786 | + $apps[] = $file; |
|
787 | + } |
|
788 | + } |
|
789 | + } |
|
790 | + } |
|
791 | + |
|
792 | + return $apps; |
|
793 | + } |
|
794 | + |
|
795 | + /** |
|
796 | + * List all apps, this is used in apps.php |
|
797 | + * |
|
798 | + * @return array |
|
799 | + */ |
|
800 | + public function listAllApps() { |
|
801 | + $installedApps = OC_App::getAllApps(); |
|
802 | + |
|
803 | + //we don't want to show configuration for these |
|
804 | + $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
805 | + $appList = array(); |
|
806 | + $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
807 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
808 | + |
|
809 | + foreach ($installedApps as $app) { |
|
810 | + if (array_search($app, $blacklist) === false) { |
|
811 | + |
|
812 | + $info = OC_App::getAppInfo($app, false, $langCode); |
|
813 | + if (!is_array($info)) { |
|
814 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
815 | + continue; |
|
816 | + } |
|
817 | + |
|
818 | + if (!isset($info['name'])) { |
|
819 | + \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
820 | + continue; |
|
821 | + } |
|
822 | + |
|
823 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
824 | + $info['groups'] = null; |
|
825 | + if ($enabled === 'yes') { |
|
826 | + $active = true; |
|
827 | + } else if ($enabled === 'no') { |
|
828 | + $active = false; |
|
829 | + } else { |
|
830 | + $active = true; |
|
831 | + $info['groups'] = $enabled; |
|
832 | + } |
|
833 | + |
|
834 | + $info['active'] = $active; |
|
835 | + |
|
836 | + if (self::isShipped($app)) { |
|
837 | + $info['internal'] = true; |
|
838 | + $info['level'] = self::officialApp; |
|
839 | + $info['removable'] = false; |
|
840 | + } else { |
|
841 | + $info['internal'] = false; |
|
842 | + $info['removable'] = true; |
|
843 | + } |
|
844 | + |
|
845 | + $appPath = self::getAppPath($app); |
|
846 | + if($appPath !== false) { |
|
847 | + $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
848 | + if (file_exists($appIcon)) { |
|
849 | + $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg'); |
|
850 | + $info['previewAsIcon'] = true; |
|
851 | + } else { |
|
852 | + $appIcon = $appPath . '/img/app.svg'; |
|
853 | + if (file_exists($appIcon)) { |
|
854 | + $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg'); |
|
855 | + $info['previewAsIcon'] = true; |
|
856 | + } |
|
857 | + } |
|
858 | + } |
|
859 | + // fix documentation |
|
860 | + if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
861 | + foreach ($info['documentation'] as $key => $url) { |
|
862 | + // If it is not an absolute URL we assume it is a key |
|
863 | + // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
864 | + if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
865 | + $url = $urlGenerator->linkToDocs($url); |
|
866 | + } |
|
867 | + |
|
868 | + $info['documentation'][$key] = $url; |
|
869 | + } |
|
870 | + } |
|
871 | + |
|
872 | + $info['version'] = OC_App::getAppVersion($app); |
|
873 | + $appList[] = $info; |
|
874 | + } |
|
875 | + } |
|
876 | + |
|
877 | + return $appList; |
|
878 | + } |
|
879 | + |
|
880 | + /** |
|
881 | + * Returns the internal app ID or false |
|
882 | + * @param string $ocsID |
|
883 | + * @return string|false |
|
884 | + */ |
|
885 | + public static function getInternalAppIdByOcs($ocsID) { |
|
886 | + if(is_numeric($ocsID)) { |
|
887 | + $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
|
888 | + if(array_search($ocsID, $idArray)) { |
|
889 | + return array_search($ocsID, $idArray); |
|
890 | + } |
|
891 | + } |
|
892 | + return false; |
|
893 | + } |
|
894 | + |
|
895 | + public static function shouldUpgrade($app) { |
|
896 | + $versions = self::getAppVersions(); |
|
897 | + $currentVersion = OC_App::getAppVersion($app); |
|
898 | + if ($currentVersion && isset($versions[$app])) { |
|
899 | + $installedVersion = $versions[$app]; |
|
900 | + if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
901 | + return true; |
|
902 | + } |
|
903 | + } |
|
904 | + return false; |
|
905 | + } |
|
906 | + |
|
907 | + /** |
|
908 | + * Adjust the number of version parts of $version1 to match |
|
909 | + * the number of version parts of $version2. |
|
910 | + * |
|
911 | + * @param string $version1 version to adjust |
|
912 | + * @param string $version2 version to take the number of parts from |
|
913 | + * @return string shortened $version1 |
|
914 | + */ |
|
915 | + private static function adjustVersionParts($version1, $version2) { |
|
916 | + $version1 = explode('.', $version1); |
|
917 | + $version2 = explode('.', $version2); |
|
918 | + // reduce $version1 to match the number of parts in $version2 |
|
919 | + while (count($version1) > count($version2)) { |
|
920 | + array_pop($version1); |
|
921 | + } |
|
922 | + // if $version1 does not have enough parts, add some |
|
923 | + while (count($version1) < count($version2)) { |
|
924 | + $version1[] = '0'; |
|
925 | + } |
|
926 | + return implode('.', $version1); |
|
927 | + } |
|
928 | + |
|
929 | + /** |
|
930 | + * Check whether the current ownCloud version matches the given |
|
931 | + * application's version requirements. |
|
932 | + * |
|
933 | + * The comparison is made based on the number of parts that the |
|
934 | + * app info version has. For example for ownCloud 6.0.3 if the |
|
935 | + * app info version is expecting version 6.0, the comparison is |
|
936 | + * made on the first two parts of the ownCloud version. |
|
937 | + * This means that it's possible to specify "requiremin" => 6 |
|
938 | + * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
939 | + * |
|
940 | + * @param string $ocVersion ownCloud version to check against |
|
941 | + * @param array $appInfo app info (from xml) |
|
942 | + * |
|
943 | + * @return boolean true if compatible, otherwise false |
|
944 | + */ |
|
945 | + public static function isAppCompatible($ocVersion, $appInfo) { |
|
946 | + $requireMin = ''; |
|
947 | + $requireMax = ''; |
|
948 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
949 | + $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
950 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
951 | + $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
952 | + } else if (isset($appInfo['requiremin'])) { |
|
953 | + $requireMin = $appInfo['requiremin']; |
|
954 | + } else if (isset($appInfo['require'])) { |
|
955 | + $requireMin = $appInfo['require']; |
|
956 | + } |
|
957 | + |
|
958 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
959 | + $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
960 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
961 | + $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
962 | + } else if (isset($appInfo['requiremax'])) { |
|
963 | + $requireMax = $appInfo['requiremax']; |
|
964 | + } |
|
965 | + |
|
966 | + if (is_array($ocVersion)) { |
|
967 | + $ocVersion = implode('.', $ocVersion); |
|
968 | + } |
|
969 | + |
|
970 | + if (!empty($requireMin) |
|
971 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
972 | + ) { |
|
973 | + |
|
974 | + return false; |
|
975 | + } |
|
976 | + |
|
977 | + if (!empty($requireMax) |
|
978 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
979 | + ) { |
|
980 | + return false; |
|
981 | + } |
|
982 | + |
|
983 | + return true; |
|
984 | + } |
|
985 | + |
|
986 | + /** |
|
987 | + * get the installed version of all apps |
|
988 | + */ |
|
989 | + public static function getAppVersions() { |
|
990 | + static $versions; |
|
991 | + |
|
992 | + if(!$versions) { |
|
993 | + $appConfig = \OC::$server->getAppConfig(); |
|
994 | + $versions = $appConfig->getValues(false, 'installed_version'); |
|
995 | + } |
|
996 | + return $versions; |
|
997 | + } |
|
998 | + |
|
999 | + /** |
|
1000 | + * @param string $app |
|
1001 | + * @param \OCP\IConfig $config |
|
1002 | + * @param \OCP\IL10N $l |
|
1003 | + * @return bool |
|
1004 | + * |
|
1005 | + * @throws Exception if app is not compatible with this version of ownCloud |
|
1006 | + * @throws Exception if no app-name was specified |
|
1007 | + */ |
|
1008 | + public function installApp($app, |
|
1009 | + \OCP\IConfig $config, |
|
1010 | + \OCP\IL10N $l) { |
|
1011 | + if ($app !== false) { |
|
1012 | + // check if the app is compatible with this version of ownCloud |
|
1013 | + $info = self::getAppInfo($app); |
|
1014 | + if(!is_array($info)) { |
|
1015 | + throw new \Exception( |
|
1016 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
1017 | + [$info['name']] |
|
1018 | + ) |
|
1019 | + ); |
|
1020 | + } |
|
1021 | + |
|
1022 | + $version = \OCP\Util::getVersion(); |
|
1023 | + if (!self::isAppCompatible($version, $info)) { |
|
1024 | + throw new \Exception( |
|
1025 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
1026 | + array($info['name']) |
|
1027 | + ) |
|
1028 | + ); |
|
1029 | + } |
|
1030 | + |
|
1031 | + // check for required dependencies |
|
1032 | + self::checkAppDependencies($config, $l, $info); |
|
1033 | + |
|
1034 | + $config->setAppValue($app, 'enabled', 'yes'); |
|
1035 | + if (isset($appData['id'])) { |
|
1036 | + $config->setAppValue($app, 'ocsid', $appData['id']); |
|
1037 | + } |
|
1038 | + |
|
1039 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
1040 | + $appPath = self::getAppPath($app); |
|
1041 | + self::registerAutoloading($app, $appPath); |
|
1042 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
1043 | + } |
|
1044 | + |
|
1045 | + \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
1046 | + } else { |
|
1047 | + if(empty($appName) ) { |
|
1048 | + throw new \Exception($l->t("No app name specified")); |
|
1049 | + } else { |
|
1050 | + throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
1051 | + } |
|
1052 | + } |
|
1053 | + |
|
1054 | + return $app; |
|
1055 | + } |
|
1056 | + |
|
1057 | + /** |
|
1058 | + * update the database for the app and call the update script |
|
1059 | + * |
|
1060 | + * @param string $appId |
|
1061 | + * @return bool |
|
1062 | + */ |
|
1063 | + public static function updateApp($appId) { |
|
1064 | + $appPath = self::getAppPath($appId); |
|
1065 | + if($appPath === false) { |
|
1066 | + return false; |
|
1067 | + } |
|
1068 | + $appData = self::getAppInfo($appId); |
|
1069 | + self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1070 | + if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1071 | + OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1072 | + } |
|
1073 | + self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1074 | + self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1075 | + unset(self::$appVersion[$appId]); |
|
1076 | + // run upgrade code |
|
1077 | + if (file_exists($appPath . '/appinfo/update.php')) { |
|
1078 | + self::loadApp($appId); |
|
1079 | + include $appPath . '/appinfo/update.php'; |
|
1080 | + } |
|
1081 | + self::setupBackgroundJobs($appData['background-jobs']); |
|
1082 | + if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1083 | + $appPath = self::getAppPath($appId); |
|
1084 | + self::registerAutoloading($appId, $appPath); |
|
1085 | + \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
1086 | + } |
|
1087 | + |
|
1088 | + //set remote/public handlers |
|
1089 | + if (array_key_exists('ocsid', $appData)) { |
|
1090 | + \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1091 | + } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1092 | + \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1093 | + } |
|
1094 | + foreach ($appData['remote'] as $name => $path) { |
|
1095 | + \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1096 | + } |
|
1097 | + foreach ($appData['public'] as $name => $path) { |
|
1098 | + \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1099 | + } |
|
1100 | + |
|
1101 | + self::setAppTypes($appId); |
|
1102 | + |
|
1103 | + $version = \OC_App::getAppVersion($appId); |
|
1104 | + \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
1105 | + |
|
1106 | + \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1107 | + ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1108 | + )); |
|
1109 | + |
|
1110 | + return true; |
|
1111 | + } |
|
1112 | + |
|
1113 | + /** |
|
1114 | + * @param string $appId |
|
1115 | + * @param string[] $steps |
|
1116 | + * @throws \OC\NeedsUpdateException |
|
1117 | + */ |
|
1118 | + public static function executeRepairSteps($appId, array $steps) { |
|
1119 | + if (empty($steps)) { |
|
1120 | + return; |
|
1121 | + } |
|
1122 | + // load the app |
|
1123 | + self::loadApp($appId); |
|
1124 | + |
|
1125 | + $dispatcher = OC::$server->getEventDispatcher(); |
|
1126 | + |
|
1127 | + // load the steps |
|
1128 | + $r = new Repair([], $dispatcher); |
|
1129 | + foreach ($steps as $step) { |
|
1130 | + try { |
|
1131 | + $r->addStep($step); |
|
1132 | + } catch (Exception $ex) { |
|
1133 | + $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1134 | + \OC::$server->getLogger()->logException($ex); |
|
1135 | + } |
|
1136 | + } |
|
1137 | + // run the steps |
|
1138 | + $r->run(); |
|
1139 | + } |
|
1140 | + |
|
1141 | + public static function setupBackgroundJobs(array $jobs) { |
|
1142 | + $queue = \OC::$server->getJobList(); |
|
1143 | + foreach ($jobs as $job) { |
|
1144 | + $queue->add($job); |
|
1145 | + } |
|
1146 | + } |
|
1147 | + |
|
1148 | + /** |
|
1149 | + * @param string $appId |
|
1150 | + * @param string[] $steps |
|
1151 | + */ |
|
1152 | + private static function setupLiveMigrations($appId, array $steps) { |
|
1153 | + $queue = \OC::$server->getJobList(); |
|
1154 | + foreach ($steps as $step) { |
|
1155 | + $queue->add('OC\Migration\BackgroundRepair', [ |
|
1156 | + 'app' => $appId, |
|
1157 | + 'step' => $step]); |
|
1158 | + } |
|
1159 | + } |
|
1160 | + |
|
1161 | + /** |
|
1162 | + * @param string $appId |
|
1163 | + * @return \OC\Files\View|false |
|
1164 | + */ |
|
1165 | + public static function getStorage($appId) { |
|
1166 | + if (OC_App::isEnabled($appId)) { //sanity check |
|
1167 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1168 | + $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1169 | + if (!$view->file_exists($appId)) { |
|
1170 | + $view->mkdir($appId); |
|
1171 | + } |
|
1172 | + return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1173 | + } else { |
|
1174 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1175 | + return false; |
|
1176 | + } |
|
1177 | + } else { |
|
1178 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1179 | + return false; |
|
1180 | + } |
|
1181 | + } |
|
1182 | + |
|
1183 | + protected static function findBestL10NOption($options, $lang) { |
|
1184 | + $fallback = $similarLangFallback = $englishFallback = false; |
|
1185 | + |
|
1186 | + $lang = strtolower($lang); |
|
1187 | + $similarLang = $lang; |
|
1188 | + if (strpos($similarLang, '_')) { |
|
1189 | + // For "de_DE" we want to find "de" and the other way around |
|
1190 | + $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1191 | + } |
|
1192 | + |
|
1193 | + foreach ($options as $option) { |
|
1194 | + if (is_array($option)) { |
|
1195 | + if ($fallback === false) { |
|
1196 | + $fallback = $option['@value']; |
|
1197 | + } |
|
1198 | + |
|
1199 | + if (!isset($option['@attributes']['lang'])) { |
|
1200 | + continue; |
|
1201 | + } |
|
1202 | + |
|
1203 | + $attributeLang = strtolower($option['@attributes']['lang']); |
|
1204 | + if ($attributeLang === $lang) { |
|
1205 | + return $option['@value']; |
|
1206 | + } |
|
1207 | + |
|
1208 | + if ($attributeLang === $similarLang) { |
|
1209 | + $similarLangFallback = $option['@value']; |
|
1210 | + } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1211 | + if ($similarLangFallback === false) { |
|
1212 | + $similarLangFallback = $option['@value']; |
|
1213 | + } |
|
1214 | + } |
|
1215 | + } else { |
|
1216 | + $englishFallback = $option; |
|
1217 | + } |
|
1218 | + } |
|
1219 | + |
|
1220 | + if ($similarLangFallback !== false) { |
|
1221 | + return $similarLangFallback; |
|
1222 | + } else if ($englishFallback !== false) { |
|
1223 | + return $englishFallback; |
|
1224 | + } |
|
1225 | + return (string) $fallback; |
|
1226 | + } |
|
1227 | + |
|
1228 | + /** |
|
1229 | + * parses the app data array and enhanced the 'description' value |
|
1230 | + * |
|
1231 | + * @param array $data the app data |
|
1232 | + * @param string $lang |
|
1233 | + * @return array improved app data |
|
1234 | + */ |
|
1235 | + public static function parseAppInfo(array $data, $lang = null) { |
|
1236 | + |
|
1237 | + if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1238 | + $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1239 | + } |
|
1240 | + if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1241 | + $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1242 | + } |
|
1243 | + if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1244 | + $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1245 | + } else if (isset($data['description']) && is_string($data['description'])) { |
|
1246 | + $data['description'] = trim($data['description']); |
|
1247 | + } else { |
|
1248 | + $data['description'] = ''; |
|
1249 | + } |
|
1250 | + |
|
1251 | + return $data; |
|
1252 | + } |
|
1253 | + |
|
1254 | + /** |
|
1255 | + * @param \OCP\IConfig $config |
|
1256 | + * @param \OCP\IL10N $l |
|
1257 | + * @param array $info |
|
1258 | + * @throws \Exception |
|
1259 | + */ |
|
1260 | + protected static function checkAppDependencies($config, $l, $info) { |
|
1261 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1262 | + $missing = $dependencyAnalyzer->analyze($info); |
|
1263 | + if (!empty($missing)) { |
|
1264 | + $missingMsg = join(PHP_EOL, $missing); |
|
1265 | + throw new \Exception( |
|
1266 | + $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1267 | + [$info['name'], $missingMsg] |
|
1268 | + ) |
|
1269 | + ); |
|
1270 | + } |
|
1271 | + } |
|
1272 | 1272 | } |
@@ -111,9 +111,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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']); |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | */ |
512 | 512 | public static function findAppInDirectories($appId) { |
513 | 513 | $sanitizedAppId = self::cleanAppId($appId); |
514 | - if($sanitizedAppId !== $appId) { |
|
514 | + if ($sanitizedAppId !== $appId) { |
|
515 | 515 | return false; |
516 | 516 | } |
517 | 517 | static $app_dir = array(); |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | |
523 | 523 | $possibleApps = array(); |
524 | 524 | foreach (OC::$APPSROOTS as $dir) { |
525 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
525 | + if (file_exists($dir['path'].'/'.$appId)) { |
|
526 | 526 | $possibleApps[] = $dir; |
527 | 527 | } |
528 | 528 | } |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | } |
564 | 564 | |
565 | 565 | if (($dir = self::findAppInDirectories($appId)) != false) { |
566 | - return $dir['path'] . '/' . $appId; |
|
566 | + return $dir['path'].'/'.$appId; |
|
567 | 567 | } |
568 | 568 | return false; |
569 | 569 | } |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | */ |
578 | 578 | public static function getAppWebPath($appId) { |
579 | 579 | if (($dir = self::findAppInDirectories($appId)) != false) { |
580 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
580 | + return OC::$WEBROOT.$dir['url'].'/'.$appId; |
|
581 | 581 | } |
582 | 582 | return false; |
583 | 583 | } |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | * @return string |
591 | 591 | */ |
592 | 592 | public static function getAppVersion($appId, $useCache = true) { |
593 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
593 | + if ($useCache && isset(self::$appVersion[$appId])) { |
|
594 | 594 | return self::$appVersion[$appId]; |
595 | 595 | } |
596 | 596 | |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | * @return string |
607 | 607 | */ |
608 | 608 | public static function getAppVersionByPath($path) { |
609 | - $infoFile = $path . '/appinfo/info.xml'; |
|
609 | + $infoFile = $path.'/appinfo/info.xml'; |
|
610 | 610 | $appData = self::getAppInfo($infoFile, true); |
611 | 611 | return isset($appData['version']) ? $appData['version'] : ''; |
612 | 612 | } |
@@ -629,10 +629,10 @@ discard block |
||
629 | 629 | return self::$appInfo[$appId]; |
630 | 630 | } |
631 | 631 | $appPath = self::getAppPath($appId); |
632 | - if($appPath === false) { |
|
632 | + if ($appPath === false) { |
|
633 | 633 | return null; |
634 | 634 | } |
635 | - $file = $appPath . '/appinfo/info.xml'; |
|
635 | + $file = $appPath.'/appinfo/info.xml'; |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
@@ -641,9 +641,9 @@ discard block |
||
641 | 641 | if (is_array($data)) { |
642 | 642 | $data = OC_App::parseAppInfo($data, $lang); |
643 | 643 | } |
644 | - if(isset($data['ocsid'])) { |
|
644 | + if (isset($data['ocsid'])) { |
|
645 | 645 | $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
646 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
646 | + if ($storedId !== '' && $storedId !== $data['ocsid']) { |
|
647 | 647 | $data['ocsid'] = $storedId; |
648 | 648 | } |
649 | 649 | } |
@@ -735,7 +735,7 @@ discard block |
||
735 | 735 | * @param string $page |
736 | 736 | */ |
737 | 737 | public static function registerAdmin($app, $page) { |
738 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
738 | + self::$adminForms[] = $app.'/'.$page.'.php'; |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | /** |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | * @param string $page |
745 | 745 | */ |
746 | 746 | public static function registerPersonal($app, $page) { |
747 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
747 | + self::$personalForms[] = $app.'/'.$page.'.php'; |
|
748 | 748 | } |
749 | 749 | |
750 | 750 | /** |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | |
774 | 774 | foreach (OC::$APPSROOTS as $apps_dir) { |
775 | 775 | if (!is_readable($apps_dir['path'])) { |
776 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
776 | + \OCP\Util::writeLog('core', 'unable to read app folder : '.$apps_dir['path'], \OCP\Util::WARN); |
|
777 | 777 | continue; |
778 | 778 | } |
779 | 779 | $dh = opendir($apps_dir['path']); |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | if (is_resource($dh)) { |
782 | 782 | while (($file = readdir($dh)) !== false) { |
783 | 783 | |
784 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
784 | + if ($file[0] != '.' and is_dir($apps_dir['path'].'/'.$file) and is_file($apps_dir['path'].'/'.$file.'/appinfo/info.xml')) { |
|
785 | 785 | |
786 | 786 | $apps[] = $file; |
787 | 787 | } |
@@ -811,12 +811,12 @@ discard block |
||
811 | 811 | |
812 | 812 | $info = OC_App::getAppInfo($app, false, $langCode); |
813 | 813 | if (!is_array($info)) { |
814 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
814 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "'.$app.'"', \OCP\Util::ERROR); |
|
815 | 815 | continue; |
816 | 816 | } |
817 | 817 | |
818 | 818 | if (!isset($info['name'])) { |
819 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
819 | + \OCP\Util::writeLog('core', 'App id "'.$app.'" has no name in appinfo', \OCP\Util::ERROR); |
|
820 | 820 | continue; |
821 | 821 | } |
822 | 822 | |
@@ -843,13 +843,13 @@ discard block |
||
843 | 843 | } |
844 | 844 | |
845 | 845 | $appPath = self::getAppPath($app); |
846 | - if($appPath !== false) { |
|
847 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
846 | + if ($appPath !== false) { |
|
847 | + $appIcon = $appPath.'/img/'.$app.'.svg'; |
|
848 | 848 | if (file_exists($appIcon)) { |
849 | - $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg'); |
|
849 | + $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app.'.svg'); |
|
850 | 850 | $info['previewAsIcon'] = true; |
851 | 851 | } else { |
852 | - $appIcon = $appPath . '/img/app.svg'; |
|
852 | + $appIcon = $appPath.'/img/app.svg'; |
|
853 | 853 | if (file_exists($appIcon)) { |
854 | 854 | $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg'); |
855 | 855 | $info['previewAsIcon'] = true; |
@@ -883,9 +883,9 @@ discard block |
||
883 | 883 | * @return string|false |
884 | 884 | */ |
885 | 885 | public static function getInternalAppIdByOcs($ocsID) { |
886 | - if(is_numeric($ocsID)) { |
|
886 | + if (is_numeric($ocsID)) { |
|
887 | 887 | $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
888 | - if(array_search($ocsID, $idArray)) { |
|
888 | + if (array_search($ocsID, $idArray)) { |
|
889 | 889 | return array_search($ocsID, $idArray); |
890 | 890 | } |
891 | 891 | } |
@@ -989,7 +989,7 @@ discard block |
||
989 | 989 | public static function getAppVersions() { |
990 | 990 | static $versions; |
991 | 991 | |
992 | - if(!$versions) { |
|
992 | + if (!$versions) { |
|
993 | 993 | $appConfig = \OC::$server->getAppConfig(); |
994 | 994 | $versions = $appConfig->getValues(false, 'installed_version'); |
995 | 995 | } |
@@ -1011,7 +1011,7 @@ discard block |
||
1011 | 1011 | if ($app !== false) { |
1012 | 1012 | // check if the app is compatible with this version of ownCloud |
1013 | 1013 | $info = self::getAppInfo($app); |
1014 | - if(!is_array($info)) { |
|
1014 | + if (!is_array($info)) { |
|
1015 | 1015 | throw new \Exception( |
1016 | 1016 | $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
1017 | 1017 | [$info['name']] |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | $config->setAppValue($app, 'ocsid', $appData['id']); |
1037 | 1037 | } |
1038 | 1038 | |
1039 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
1039 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
1040 | 1040 | $appPath = self::getAppPath($app); |
1041 | 1041 | self::registerAutoloading($app, $appPath); |
1042 | 1042 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -1044,7 +1044,7 @@ discard block |
||
1044 | 1044 | |
1045 | 1045 | \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
1046 | 1046 | } else { |
1047 | - if(empty($appName) ) { |
|
1047 | + if (empty($appName)) { |
|
1048 | 1048 | throw new \Exception($l->t("No app name specified")); |
1049 | 1049 | } else { |
1050 | 1050 | throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
@@ -1062,24 +1062,24 @@ discard block |
||
1062 | 1062 | */ |
1063 | 1063 | public static function updateApp($appId) { |
1064 | 1064 | $appPath = self::getAppPath($appId); |
1065 | - if($appPath === false) { |
|
1065 | + if ($appPath === false) { |
|
1066 | 1066 | return false; |
1067 | 1067 | } |
1068 | 1068 | $appData = self::getAppInfo($appId); |
1069 | 1069 | self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
1070 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1071 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1070 | + if (file_exists($appPath.'/appinfo/database.xml')) { |
|
1071 | + OC_DB::updateDbFromStructure($appPath.'/appinfo/database.xml'); |
|
1072 | 1072 | } |
1073 | 1073 | self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
1074 | 1074 | self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
1075 | 1075 | unset(self::$appVersion[$appId]); |
1076 | 1076 | // run upgrade code |
1077 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
1077 | + if (file_exists($appPath.'/appinfo/update.php')) { |
|
1078 | 1078 | self::loadApp($appId); |
1079 | - include $appPath . '/appinfo/update.php'; |
|
1079 | + include $appPath.'/appinfo/update.php'; |
|
1080 | 1080 | } |
1081 | 1081 | self::setupBackgroundJobs($appData['background-jobs']); |
1082 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1082 | + if (isset($appData['settings']) && is_array($appData['settings'])) { |
|
1083 | 1083 | $appPath = self::getAppPath($appId); |
1084 | 1084 | self::registerAutoloading($appId, $appPath); |
1085 | 1085 | \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
@@ -1088,14 +1088,14 @@ discard block |
||
1088 | 1088 | //set remote/public handlers |
1089 | 1089 | if (array_key_exists('ocsid', $appData)) { |
1090 | 1090 | \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
1091 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1091 | + } elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1092 | 1092 | \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
1093 | 1093 | } |
1094 | 1094 | foreach ($appData['remote'] as $name => $path) { |
1095 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1095 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $appId.'/'.$path); |
|
1096 | 1096 | } |
1097 | 1097 | foreach ($appData['public'] as $name => $path) { |
1098 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1098 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $appId.'/'.$path); |
|
1099 | 1099 | } |
1100 | 1100 | |
1101 | 1101 | self::setAppTypes($appId); |
@@ -1165,17 +1165,17 @@ discard block |
||
1165 | 1165 | public static function getStorage($appId) { |
1166 | 1166 | if (OC_App::isEnabled($appId)) { //sanity check |
1167 | 1167 | if (\OC::$server->getUserSession()->isLoggedIn()) { |
1168 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1168 | + $view = new \OC\Files\View('/'.OC_User::getUser()); |
|
1169 | 1169 | if (!$view->file_exists($appId)) { |
1170 | 1170 | $view->mkdir($appId); |
1171 | 1171 | } |
1172 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1172 | + return new \OC\Files\View('/'.OC_User::getUser().'/'.$appId); |
|
1173 | 1173 | } else { |
1174 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1174 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.', user not logged in', \OCP\Util::ERROR); |
|
1175 | 1175 | return false; |
1176 | 1176 | } |
1177 | 1177 | } else { |
1178 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1178 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.' not enabled', \OCP\Util::ERROR); |
|
1179 | 1179 | return false; |
1180 | 1180 | } |
1181 | 1181 | } |
@@ -1207,9 +1207,9 @@ discard block |
||
1207 | 1207 | |
1208 | 1208 | if ($attributeLang === $similarLang) { |
1209 | 1209 | $similarLangFallback = $option['@value']; |
1210 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1210 | + } else if (strpos($attributeLang, $similarLang.'_') === 0) { |
|
1211 | 1211 | if ($similarLangFallback === false) { |
1212 | - $similarLangFallback = $option['@value']; |
|
1212 | + $similarLangFallback = $option['@value']; |
|
1213 | 1213 | } |
1214 | 1214 | } |
1215 | 1215 | } else { |
@@ -1244,7 +1244,7 @@ discard block |
||
1244 | 1244 | $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
1245 | 1245 | } else if (isset($data['description']) && is_string($data['description'])) { |
1246 | 1246 | $data['description'] = trim($data['description']); |
1247 | - } else { |
|
1247 | + } else { |
|
1248 | 1248 | $data['description'] = ''; |
1249 | 1249 | } |
1250 | 1250 |
@@ -42,226 +42,226 @@ |
||
42 | 42 | |
43 | 43 | class TemplateLayout extends \OC_Template { |
44 | 44 | |
45 | - private static $versionHash = ''; |
|
45 | + private static $versionHash = ''; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @var \OCP\IConfig |
|
49 | - */ |
|
50 | - private $config; |
|
47 | + /** |
|
48 | + * @var \OCP\IConfig |
|
49 | + */ |
|
50 | + private $config; |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param string $renderAs |
|
54 | - * @param string $appId application id |
|
55 | - */ |
|
56 | - public function __construct( $renderAs, $appId = '' ) { |
|
52 | + /** |
|
53 | + * @param string $renderAs |
|
54 | + * @param string $appId application id |
|
55 | + */ |
|
56 | + public function __construct( $renderAs, $appId = '' ) { |
|
57 | 57 | |
58 | - // yes - should be injected .... |
|
59 | - $this->config = \OC::$server->getConfig(); |
|
58 | + // yes - should be injected .... |
|
59 | + $this->config = \OC::$server->getConfig(); |
|
60 | 60 | |
61 | 61 | |
62 | - // Decide which page we show |
|
63 | - if($renderAs == 'user') { |
|
64 | - parent::__construct( 'core', 'layout.user' ); |
|
65 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
66 | - $this->assign('bodyid', 'body-settings'); |
|
67 | - }else{ |
|
68 | - $this->assign('bodyid', 'body-user'); |
|
69 | - } |
|
62 | + // Decide which page we show |
|
63 | + if($renderAs == 'user') { |
|
64 | + parent::__construct( 'core', 'layout.user' ); |
|
65 | + if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
66 | + $this->assign('bodyid', 'body-settings'); |
|
67 | + }else{ |
|
68 | + $this->assign('bodyid', 'body-user'); |
|
69 | + } |
|
70 | 70 | |
71 | - // Code integrity notification |
|
72 | - $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
73 | - if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
74 | - \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
75 | - } |
|
71 | + // Code integrity notification |
|
72 | + $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
73 | + if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
74 | + \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
75 | + } |
|
76 | 76 | |
77 | - // Add navigation entry |
|
78 | - $this->assign( 'application', ''); |
|
79 | - $this->assign( 'appid', $appId ); |
|
80 | - $navigation = \OC_App::getNavigation(); |
|
81 | - $this->assign( 'navigation', $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 | - } |
|
77 | + // Add navigation entry |
|
78 | + $this->assign( 'application', ''); |
|
79 | + $this->assign( 'appid', $appId ); |
|
80 | + $navigation = \OC_App::getNavigation(); |
|
81 | + $this->assign( 'navigation', $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->query(Defaults::class), |
|
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->query(Defaults::class), |
|
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 | - } |
|
198 | - if ($this->config->getSystemValue('installed', false) && \OC::$server->getAppManager()->isInstalled('theming')) { |
|
199 | - return '?v=' . self::$versionHash . '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
200 | - } |
|
201 | - return '?v=' . self::$versionHash; |
|
202 | - } |
|
193 | + protected function getVersionHashSuffix() { |
|
194 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
195 | + // allows chrome workspace mapping in debug mode |
|
196 | + return ""; |
|
197 | + } |
|
198 | + if ($this->config->getSystemValue('installed', false) && \OC::$server->getAppManager()->isInstalled('theming')) { |
|
199 | + return '?v=' . self::$versionHash . '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
200 | + } |
|
201 | + return '?v=' . self::$versionHash; |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * @param array $styles |
|
206 | - * @return array |
|
207 | - */ |
|
208 | - static public function findStylesheetFiles($styles, $compileScss = true) { |
|
209 | - // Read the selected theme from the config file |
|
210 | - $theme = \OC_Util::getTheme(); |
|
204 | + /** |
|
205 | + * @param array $styles |
|
206 | + * @return array |
|
207 | + */ |
|
208 | + static public function findStylesheetFiles($styles, $compileScss = true) { |
|
209 | + // Read the selected theme from the config file |
|
210 | + $theme = \OC_Util::getTheme(); |
|
211 | 211 | |
212 | - if($compileScss) { |
|
213 | - $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
214 | - } else { |
|
215 | - $SCSSCacher = null; |
|
216 | - } |
|
212 | + if($compileScss) { |
|
213 | + $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
214 | + } else { |
|
215 | + $SCSSCacher = null; |
|
216 | + } |
|
217 | 217 | |
218 | - $locator = new \OC\Template\CSSResourceLocator( |
|
219 | - \OC::$server->getLogger(), |
|
220 | - $theme, |
|
221 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
222 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
223 | - $SCSSCacher |
|
224 | - ); |
|
225 | - $locator->find($styles); |
|
226 | - return $locator->getResources(); |
|
227 | - } |
|
218 | + $locator = new \OC\Template\CSSResourceLocator( |
|
219 | + \OC::$server->getLogger(), |
|
220 | + $theme, |
|
221 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
222 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
223 | + $SCSSCacher |
|
224 | + ); |
|
225 | + $locator->find($styles); |
|
226 | + return $locator->getResources(); |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * @param array $scripts |
|
231 | - * @return array |
|
232 | - */ |
|
233 | - static public function findJavascriptFiles($scripts) { |
|
234 | - // Read the selected theme from the config file |
|
235 | - $theme = \OC_Util::getTheme(); |
|
229 | + /** |
|
230 | + * @param array $scripts |
|
231 | + * @return array |
|
232 | + */ |
|
233 | + static public function findJavascriptFiles($scripts) { |
|
234 | + // Read the selected theme from the config file |
|
235 | + $theme = \OC_Util::getTheme(); |
|
236 | 236 | |
237 | - $locator = new \OC\Template\JSResourceLocator( |
|
238 | - \OC::$server->getLogger(), |
|
239 | - $theme, |
|
240 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
241 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
242 | - new JSCombiner( |
|
243 | - \OC::$server->getAppDataDir('js'), |
|
244 | - \OC::$server->getURLGenerator(), |
|
245 | - \OC::$server->getMemCacheFactory()->create('JS'), |
|
246 | - \OC::$server->getSystemConfig() |
|
247 | - ) |
|
248 | - ); |
|
249 | - $locator->find($scripts); |
|
250 | - return $locator->getResources(); |
|
251 | - } |
|
237 | + $locator = new \OC\Template\JSResourceLocator( |
|
238 | + \OC::$server->getLogger(), |
|
239 | + $theme, |
|
240 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
241 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
242 | + new JSCombiner( |
|
243 | + \OC::$server->getAppDataDir('js'), |
|
244 | + \OC::$server->getURLGenerator(), |
|
245 | + \OC::$server->getMemCacheFactory()->create('JS'), |
|
246 | + \OC::$server->getSystemConfig() |
|
247 | + ) |
|
248 | + ); |
|
249 | + $locator->find($scripts); |
|
250 | + return $locator->getResources(); |
|
251 | + } |
|
252 | 252 | |
253 | - /** |
|
254 | - * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
255 | - * @param string $filePath Absolute path |
|
256 | - * @return string Relative path |
|
257 | - * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
258 | - */ |
|
259 | - public static function convertToRelativePath($filePath) { |
|
260 | - $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
261 | - if(count($relativePath) !== 2) { |
|
262 | - throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
263 | - } |
|
253 | + /** |
|
254 | + * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
255 | + * @param string $filePath Absolute path |
|
256 | + * @return string Relative path |
|
257 | + * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
258 | + */ |
|
259 | + public static function convertToRelativePath($filePath) { |
|
260 | + $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
261 | + if(count($relativePath) !== 2) { |
|
262 | + throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
263 | + } |
|
264 | 264 | |
265 | - return $relativePath[1]; |
|
266 | - } |
|
265 | + return $relativePath[1]; |
|
266 | + } |
|
267 | 267 | } |
@@ -53,44 +53,44 @@ discard block |
||
53 | 53 | * @param string $renderAs |
54 | 54 | * @param string $appId application id |
55 | 55 | */ |
56 | - public function __construct( $renderAs, $appId = '' ) { |
|
56 | + public function __construct($renderAs, $appId = '') { |
|
57 | 57 | |
58 | 58 | // yes - should be injected .... |
59 | 59 | $this->config = \OC::$server->getConfig(); |
60 | 60 | |
61 | 61 | |
62 | 62 | // Decide which page we show |
63 | - if($renderAs == 'user') { |
|
64 | - parent::__construct( 'core', 'layout.user' ); |
|
65 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
63 | + if ($renderAs == 'user') { |
|
64 | + parent::__construct('core', 'layout.user'); |
|
65 | + if (in_array(\OC_App::getCurrentApp(), ['settings', 'admin', 'help']) !== false) { |
|
66 | 66 | $this->assign('bodyid', 'body-settings'); |
67 | - }else{ |
|
67 | + } else { |
|
68 | 68 | $this->assign('bodyid', 'body-user'); |
69 | 69 | } |
70 | 70 | |
71 | 71 | // Code integrity notification |
72 | 72 | $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
73 | - if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
73 | + if (\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
74 | 74 | \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
75 | 75 | } |
76 | 76 | |
77 | 77 | // Add navigation entry |
78 | - $this->assign( 'application', ''); |
|
79 | - $this->assign( 'appid', $appId ); |
|
78 | + $this->assign('application', ''); |
|
79 | + $this->assign('appid', $appId); |
|
80 | 80 | $navigation = \OC_App::getNavigation(); |
81 | - $this->assign( 'navigation', $navigation); |
|
81 | + $this->assign('navigation', $navigation); |
|
82 | 82 | $settingsNavigation = \OC_App::getSettingsNavigation(); |
83 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
84 | - foreach($navigation as $entry) { |
|
83 | + $this->assign('settingsnavigation', $settingsNavigation); |
|
84 | + foreach ($navigation as $entry) { |
|
85 | 85 | if ($entry['active']) { |
86 | - $this->assign( 'application', $entry['name'] ); |
|
86 | + $this->assign('application', $entry['name']); |
|
87 | 87 | break; |
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | - foreach($settingsNavigation as $entry) { |
|
91 | + foreach ($settingsNavigation as $entry) { |
|
92 | 92 | if ($entry['active']) { |
93 | - $this->assign( 'application', $entry['name'] ); |
|
93 | + $this->assign('application', $entry['name']); |
|
94 | 94 | break; |
95 | 95 | } |
96 | 96 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | // Send the language to our layouts |
119 | 119 | $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
120 | 120 | |
121 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
121 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
122 | 122 | if (empty(self::$versionHash)) { |
123 | 123 | $v = \OC_App::getAppVersions(); |
124 | 124 | $v['core'] = implode('.', \OCP\Util::getVersion()); |
@@ -149,10 +149,10 @@ discard block |
||
149 | 149 | $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
150 | 150 | } |
151 | 151 | } |
152 | - foreach($jsFiles as $info) { |
|
152 | + foreach ($jsFiles as $info) { |
|
153 | 153 | $web = $info[1]; |
154 | 154 | $file = $info[2]; |
155 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
155 | + $this->append('jsfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | try { |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | |
164 | 164 | // Do not initialise scss appdata until we have a fully installed instance |
165 | 165 | // Do not load scss for update, errors, installation or login page |
166 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
166 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) |
|
167 | 167 | && !\OCP\Util::needUpgrade() |
168 | 168 | && $pathInfo !== '' |
169 | 169 | && !preg_match('/^\/login/', $pathInfo)) { |
@@ -178,27 +178,27 @@ discard block |
||
178 | 178 | $this->assign('cssfiles', array()); |
179 | 179 | $this->assign('printcssfiles', []); |
180 | 180 | $this->assign('versionHash', self::$versionHash); |
181 | - foreach($cssFiles as $info) { |
|
181 | + foreach ($cssFiles as $info) { |
|
182 | 182 | $web = $info[1]; |
183 | 183 | $file = $info[2]; |
184 | 184 | |
185 | 185 | if (substr($file, -strlen('print.css')) === 'print.css') { |
186 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
186 | + $this->append('printcssfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
187 | 187 | } else { |
188 | - $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
188 | + $this->append('cssfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | } |
192 | 192 | |
193 | 193 | protected function getVersionHashSuffix() { |
194 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
194 | + if (\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
195 | 195 | // allows chrome workspace mapping in debug mode |
196 | 196 | return ""; |
197 | 197 | } |
198 | 198 | if ($this->config->getSystemValue('installed', false) && \OC::$server->getAppManager()->isInstalled('theming')) { |
199 | - return '?v=' . self::$versionHash . '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
199 | + return '?v='.self::$versionHash.'-'.$this->config->getAppValue('theming', 'cachebuster', '0'); |
|
200 | 200 | } |
201 | - return '?v=' . self::$versionHash; |
|
201 | + return '?v='.self::$versionHash; |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | // Read the selected theme from the config file |
210 | 210 | $theme = \OC_Util::getTheme(); |
211 | 211 | |
212 | - if($compileScss) { |
|
212 | + if ($compileScss) { |
|
213 | 213 | $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
214 | 214 | } else { |
215 | 215 | $SCSSCacher = null; |
@@ -218,8 +218,8 @@ discard block |
||
218 | 218 | $locator = new \OC\Template\CSSResourceLocator( |
219 | 219 | \OC::$server->getLogger(), |
220 | 220 | $theme, |
221 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
222 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
221 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
222 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
223 | 223 | $SCSSCacher |
224 | 224 | ); |
225 | 225 | $locator->find($styles); |
@@ -237,8 +237,8 @@ discard block |
||
237 | 237 | $locator = new \OC\Template\JSResourceLocator( |
238 | 238 | \OC::$server->getLogger(), |
239 | 239 | $theme, |
240 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
241 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
240 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
241 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
242 | 242 | new JSCombiner( |
243 | 243 | \OC::$server->getAppDataDir('js'), |
244 | 244 | \OC::$server->getURLGenerator(), |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | */ |
259 | 259 | public static function convertToRelativePath($filePath) { |
260 | 260 | $relativePath = explode(\OC::$SERVERROOT, $filePath); |
261 | - if(count($relativePath) !== 2) { |
|
261 | + if (count($relativePath) !== 2) { |
|
262 | 262 | throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
263 | 263 | } |
264 | 264 |