@@ -40,73 +40,73 @@ |
||
40 | 40 | |
41 | 41 | class JsController extends Controller { |
42 | 42 | |
43 | - /** @var IAppData */ |
|
44 | - protected $appData; |
|
43 | + /** @var IAppData */ |
|
44 | + protected $appData; |
|
45 | 45 | |
46 | - /** @var ITimeFactory */ |
|
47 | - protected $timeFactory; |
|
46 | + /** @var ITimeFactory */ |
|
47 | + protected $timeFactory; |
|
48 | 48 | |
49 | - public function __construct($appName, IRequest $request, Factory $appDataFactory, ITimeFactory $timeFactory) { |
|
50 | - parent::__construct($appName, $request); |
|
49 | + public function __construct($appName, IRequest $request, Factory $appDataFactory, ITimeFactory $timeFactory) { |
|
50 | + parent::__construct($appName, $request); |
|
51 | 51 | |
52 | - $this->appData = $appDataFactory->get('js'); |
|
53 | - $this->timeFactory = $timeFactory; |
|
54 | - } |
|
52 | + $this->appData = $appDataFactory->get('js'); |
|
53 | + $this->timeFactory = $timeFactory; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @PublicPage |
|
58 | - * @NoCSRFRequired |
|
59 | - * |
|
60 | - * @param string $fileName js filename with extension |
|
61 | - * @param string $appName js folder name |
|
62 | - * @return FileDisplayResponse|NotFoundResponse |
|
63 | - */ |
|
64 | - public function getJs(string $fileName, string $appName): Response { |
|
65 | - try { |
|
66 | - $folder = $this->appData->getFolder($appName); |
|
67 | - $gzip = false; |
|
68 | - $file = $this->getFile($folder, $fileName, $gzip); |
|
69 | - } catch(NotFoundException $e) { |
|
70 | - return new NotFoundResponse(); |
|
71 | - } |
|
56 | + /** |
|
57 | + * @PublicPage |
|
58 | + * @NoCSRFRequired |
|
59 | + * |
|
60 | + * @param string $fileName js filename with extension |
|
61 | + * @param string $appName js folder name |
|
62 | + * @return FileDisplayResponse|NotFoundResponse |
|
63 | + */ |
|
64 | + public function getJs(string $fileName, string $appName): Response { |
|
65 | + try { |
|
66 | + $folder = $this->appData->getFolder($appName); |
|
67 | + $gzip = false; |
|
68 | + $file = $this->getFile($folder, $fileName, $gzip); |
|
69 | + } catch(NotFoundException $e) { |
|
70 | + return new NotFoundResponse(); |
|
71 | + } |
|
72 | 72 | |
73 | - $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'application/javascript']); |
|
74 | - if ($gzip) { |
|
75 | - $response->addHeader('Content-Encoding', 'gzip'); |
|
76 | - } |
|
73 | + $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'application/javascript']); |
|
74 | + if ($gzip) { |
|
75 | + $response->addHeader('Content-Encoding', 'gzip'); |
|
76 | + } |
|
77 | 77 | |
78 | - $ttl = 31536000; |
|
79 | - $response->addHeader('Cache-Control', 'max-age='.$ttl.', immutable'); |
|
78 | + $ttl = 31536000; |
|
79 | + $response->addHeader('Cache-Control', 'max-age='.$ttl.', immutable'); |
|
80 | 80 | |
81 | - $expires = new \DateTime(); |
|
82 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
83 | - $expires->add(new \DateInterval('PT'.$ttl.'S')); |
|
84 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
85 | - $response->addHeader('Pragma', 'cache'); |
|
86 | - return $response; |
|
87 | - } |
|
81 | + $expires = new \DateTime(); |
|
82 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
83 | + $expires->add(new \DateInterval('PT'.$ttl.'S')); |
|
84 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
85 | + $response->addHeader('Pragma', 'cache'); |
|
86 | + return $response; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @param ISimpleFolder $folder |
|
91 | - * @param string $fileName |
|
92 | - * @param bool $gzip is set to true if we use the gzip file |
|
93 | - * @return ISimpleFile |
|
94 | - * |
|
95 | - * @throws NotFoundException |
|
96 | - */ |
|
97 | - private function getFile(ISimpleFolder $folder, string $fileName, bool &$gzip): ISimpleFile { |
|
98 | - $encoding = $this->request->getHeader('Accept-Encoding'); |
|
89 | + /** |
|
90 | + * @param ISimpleFolder $folder |
|
91 | + * @param string $fileName |
|
92 | + * @param bool $gzip is set to true if we use the gzip file |
|
93 | + * @return ISimpleFile |
|
94 | + * |
|
95 | + * @throws NotFoundException |
|
96 | + */ |
|
97 | + private function getFile(ISimpleFolder $folder, string $fileName, bool &$gzip): ISimpleFile { |
|
98 | + $encoding = $this->request->getHeader('Accept-Encoding'); |
|
99 | 99 | |
100 | - if (strpos($encoding, 'gzip') !== false) { |
|
101 | - try { |
|
102 | - $gzip = true; |
|
103 | - return $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz |
|
104 | - } catch (NotFoundException $e) { |
|
105 | - // continue |
|
106 | - } |
|
107 | - } |
|
100 | + if (strpos($encoding, 'gzip') !== false) { |
|
101 | + try { |
|
102 | + $gzip = true; |
|
103 | + return $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz |
|
104 | + } catch (NotFoundException $e) { |
|
105 | + // continue |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | - $gzip = false; |
|
110 | - return $folder->getFile($fileName); |
|
111 | - } |
|
109 | + $gzip = false; |
|
110 | + return $folder->getFile($fileName); |
|
111 | + } |
|
112 | 112 | } |
@@ -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 */ ?>"> |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | <?php emit_script_loading_tags($_); ?> |
26 | 26 | <?php print_unescaped($_['headers']); ?> |
27 | 27 | </head> |
28 | - <body id="<?php p($_['bodyid']);?>"> |
|
28 | + <body id="<?php p($_['bodyid']); ?>"> |
|
29 | 29 | <?php include 'layout.noscript.warning.php'; ?> |
30 | 30 | |
31 | 31 | <a href="#app-content" class="button primary skip-navigation skip-content"><?php p($l->t('Skip to main content')); ?></a> |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | id="nextcloud"> |
41 | 41 | <div class="logo logo-icon"> |
42 | 42 | <h1 class="hidden-visually"> |
43 | - <?php p($theme->getName()); ?> <?php p(!empty($_['application'])?$_['application']: $l->t('Apps')); ?> |
|
43 | + <?php p($theme->getName()); ?> <?php p(!empty($_['application']) ? $_['application'] : $l->t('Apps')); ?> |
|
44 | 44 | </h1> |
45 | 45 | </div> |
46 | 46 | </a> |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | <?php if ($_['themingInvertMenu']) { ?> |
56 | 56 | <defs><filter id="invertMenuMain-<?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" /></filter></defs> |
57 | 57 | <?php } ?> |
58 | - <image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet"<?php if ($_['themingInvertMenu']) { ?> filter="url(#invertMenuMain-<?php p($entry['id']); ?>)"<?php } ?> xlink:href="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>" class="app-icon" /> |
|
58 | + <image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet"<?php if ($_['themingInvertMenu']) { ?> filter="url(#invertMenuMain-<?php p($entry['id']); ?>)"<?php } ?> xlink:href="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>" class="app-icon" /> |
|
59 | 59 | </svg> |
60 | 60 | <div class="icon-loading-small-dark" |
61 | 61 | style="display:none;"></div> |
@@ -78,14 +78,14 @@ discard block |
||
78 | 78 | <div id="navigation" style="display: none;" aria-label="<?php p($l->t('More apps menu')); ?>"> |
79 | 79 | <div id="apps"> |
80 | 80 | <ul> |
81 | - <?php foreach($_['navigation'] as $entry): ?> |
|
81 | + <?php foreach ($_['navigation'] as $entry): ?> |
|
82 | 82 | <li data-id="<?php p($entry['id']); ?>"> |
83 | 83 | <a href="<?php print_unescaped($entry['href']); ?>" |
84 | - <?php if( $entry['active'] ): ?> class="active"<?php endif; ?> |
|
84 | + <?php if ($entry['active']): ?> class="active"<?php endif; ?> |
|
85 | 85 | aria-label="<?php p($entry['name']); ?>"> |
86 | 86 | <svg width="16" height="16" viewBox="0 0 16 16" alt=""> |
87 | 87 | <defs><filter id="invertMenuMore-<?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> |
88 | - <image x="0" y="0" width="16" height="16" preserveAspectRatio="xMinYMin meet" filter="url(#invertMenuMore-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>" class="app-icon"></image> |
|
88 | + <image x="0" y="0" width="16" height="16" preserveAspectRatio="xMinYMin meet" filter="url(#invertMenuMore-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>" class="app-icon"></image> |
|
89 | 89 | </svg> |
90 | 90 | <div class="icon-loading-small" style="display:none;"></div> |
91 | 91 | <span><?php p($entry['name']); ?></span> |
@@ -102,43 +102,43 @@ discard block |
||
102 | 102 | <div class="header-right"> |
103 | 103 | <form class="searchbox" action="#" method="post" role="search" novalidate> |
104 | 104 | <label for="searchbox" class="hidden-visually"> |
105 | - <?php p($l->t('Search'));?> |
|
105 | + <?php p($l->t('Search')); ?> |
|
106 | 106 | </label> |
107 | 107 | <input id="searchbox" type="search" name="query" |
108 | 108 | value="" required class="hidden icon-search-white" |
109 | 109 | autocomplete="off"> |
110 | - <button class="icon-close-white" type="reset"><span class="hidden-visually"><?php p($l->t('Reset search'));?></span></button> |
|
110 | + <button class="icon-close-white" type="reset"><span class="hidden-visually"><?php p($l->t('Reset search')); ?></span></button> |
|
111 | 111 | </form> |
112 | 112 | <div id="contactsmenu"> |
113 | 113 | <div class="icon-contacts menutoggle" tabindex="0" role="button" |
114 | 114 | aria-haspopup="true" aria-controls="contactsmenu-menu" aria-expanded="false"> |
115 | - <span class="hidden-visually"><?php p($l->t('Contacts'));?> |
|
115 | + <span class="hidden-visually"><?php p($l->t('Contacts')); ?> |
|
116 | 116 | </div> |
117 | 117 | <div id="contactsmenu-menu" class="menu" |
118 | - aria-label="<?php p($l->t('Contacts menu'));?>"></div> |
|
118 | + aria-label="<?php p($l->t('Contacts menu')); ?>"></div> |
|
119 | 119 | </div> |
120 | 120 | <div id="settings"> |
121 | 121 | <div id="expand" tabindex="0" role="button" class="menutoggle" |
122 | - aria-label="<?php p($l->t('Settings'));?>" |
|
122 | + aria-label="<?php p($l->t('Settings')); ?>" |
|
123 | 123 | aria-haspopup="true" aria-controls="expanddiv" aria-expanded="false"> |
124 | 124 | <div class="avatardiv<?php if ($_['userAvatarSet']) { print_unescaped(' avatardiv-shown'); } else { print_unescaped('" style="display: none'); } ?>"> |
125 | 125 | <?php if ($_['userAvatarSet']): ?> |
126 | 126 | <img alt="" width="32" height="32" |
127 | - src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']]));?>" |
|
128 | - 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" |
|
127 | + src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']])); ?>" |
|
128 | + 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" |
|
129 | 129 | > |
130 | 130 | <?php endif; ?> |
131 | 131 | </div> |
132 | 132 | <div id="expandDisplayName" class="icon-settings-white"></div> |
133 | 133 | </div> |
134 | 134 | <nav id="expanddiv" style="display:none;" |
135 | - aria-label="<?php p($l->t('Settings menu'));?>"> |
|
135 | + aria-label="<?php p($l->t('Settings menu')); ?>"> |
|
136 | 136 | <ul> |
137 | - <?php foreach($_['settingsnavigation'] as $entry):?> |
|
137 | + <?php foreach ($_['settingsnavigation'] as $entry):?> |
|
138 | 138 | <li data-id="<?php p($entry['id']); ?>"> |
139 | 139 | <a href="<?php print_unescaped($entry['href']); ?>" |
140 | - <?php if( $entry["active"] ): ?> class="active"<?php endif; ?>> |
|
141 | - <img alt="" src="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>"> |
|
140 | + <?php if ($entry["active"]): ?> class="active"<?php endif; ?>> |
|
141 | + <img alt="" src="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>"> |
|
142 | 142 | <?php p($entry['name']) ?> |
143 | 143 | </a> |
144 | 144 | </li> |
@@ -49,354 +49,354 @@ |
||
49 | 49 | use OCP\Util; |
50 | 50 | |
51 | 51 | class Manager implements IManager { |
52 | - /** @var ILogger */ |
|
53 | - private $log; |
|
54 | - /** @var IDBConnection */ |
|
55 | - private $dbc; |
|
56 | - /** @var IL10N */ |
|
57 | - private $l; |
|
58 | - /** @var IConfig */ |
|
59 | - private $config; |
|
60 | - /** @var EncryptionManager */ |
|
61 | - private $encryptionManager; |
|
62 | - /** @var IUserManager */ |
|
63 | - private $userManager; |
|
64 | - /** @var ILockingProvider */ |
|
65 | - private $lockingProvider; |
|
66 | - /** @var IRequest */ |
|
67 | - private $request; |
|
68 | - /** @var IURLGenerator */ |
|
69 | - private $url; |
|
70 | - /** @var AccountManager */ |
|
71 | - private $accountManager; |
|
72 | - /** @var IGroupManager */ |
|
73 | - private $groupManager; |
|
74 | - /** @var IFactory */ |
|
75 | - private $l10nFactory; |
|
76 | - /** @var IAppManager */ |
|
77 | - private $appManager; |
|
78 | - |
|
79 | - /** |
|
80 | - * @param ILogger $log |
|
81 | - * @param IDBConnection $dbc |
|
82 | - * @param IL10N $l |
|
83 | - * @param IConfig $config |
|
84 | - * @param EncryptionManager $encryptionManager |
|
85 | - * @param IUserManager $userManager |
|
86 | - * @param ILockingProvider $lockingProvider |
|
87 | - * @param IRequest $request |
|
88 | - * @param IURLGenerator $url |
|
89 | - * @param AccountManager $accountManager |
|
90 | - * @param IGroupManager $groupManager |
|
91 | - * @param IFactory $l10nFactory |
|
92 | - * @param IAppManager $appManager |
|
93 | - */ |
|
94 | - public function __construct( |
|
95 | - ILogger $log, |
|
96 | - IDBConnection $dbc, |
|
97 | - IL10N $l, |
|
98 | - IConfig $config, |
|
99 | - EncryptionManager $encryptionManager, |
|
100 | - IUserManager $userManager, |
|
101 | - ILockingProvider $lockingProvider, |
|
102 | - IRequest $request, |
|
103 | - IURLGenerator $url, |
|
104 | - AccountManager $accountManager, |
|
105 | - IGroupManager $groupManager, |
|
106 | - IFactory $l10nFactory, |
|
107 | - IAppManager $appManager |
|
108 | - ) { |
|
109 | - $this->log = $log; |
|
110 | - $this->dbc = $dbc; |
|
111 | - $this->l = $l; |
|
112 | - $this->config = $config; |
|
113 | - $this->encryptionManager = $encryptionManager; |
|
114 | - $this->userManager = $userManager; |
|
115 | - $this->lockingProvider = $lockingProvider; |
|
116 | - $this->request = $request; |
|
117 | - $this->url = $url; |
|
118 | - $this->accountManager = $accountManager; |
|
119 | - $this->groupManager = $groupManager; |
|
120 | - $this->l10nFactory = $l10nFactory; |
|
121 | - $this->appManager = $appManager; |
|
122 | - } |
|
123 | - |
|
124 | - /** @var array */ |
|
125 | - protected $sectionClasses = []; |
|
126 | - |
|
127 | - /** @var array */ |
|
128 | - protected $sections = []; |
|
129 | - |
|
130 | - /** |
|
131 | - * @param string $type 'admin' or 'personal' |
|
132 | - * @param string $section Class must implement OCP\Settings\ISection |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - public function registerSection(string $type, string $section) { |
|
136 | - $this->sectionClasses[$section] = $type; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $type 'admin' or 'personal' |
|
141 | - * @return ISection[] |
|
142 | - */ |
|
143 | - protected function getSections(string $type): array { |
|
144 | - if (!isset($this->sections[$type])) { |
|
145 | - $this->sections[$type] = []; |
|
146 | - } |
|
147 | - |
|
148 | - foreach ($this->sectionClasses as $class => $sectionType) { |
|
149 | - try { |
|
150 | - /** @var ISection $section */ |
|
151 | - $section = \OC::$server->query($class); |
|
152 | - } catch (QueryException $e) { |
|
153 | - $this->log->logException($e, ['level' => ILogger::INFO]); |
|
154 | - continue; |
|
155 | - } |
|
156 | - |
|
157 | - if (!$section instanceof ISection) { |
|
158 | - $this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => ILogger::INFO]); |
|
159 | - continue; |
|
160 | - } |
|
161 | - |
|
162 | - $this->sections[$sectionType][$section->getID()] = $section; |
|
163 | - |
|
164 | - unset($this->sectionClasses[$class]); |
|
165 | - } |
|
166 | - |
|
167 | - return $this->sections[$type]; |
|
168 | - } |
|
169 | - |
|
170 | - /** @var array */ |
|
171 | - protected $settingClasses = []; |
|
172 | - |
|
173 | - /** @var array */ |
|
174 | - protected $settings = []; |
|
175 | - |
|
176 | - /** |
|
177 | - * @param string $type 'admin' or 'personal' |
|
178 | - * @param string $setting Class must implement OCP\Settings\ISetting |
|
179 | - * @return void |
|
180 | - */ |
|
181 | - public function registerSetting(string $type, string $setting) { |
|
182 | - $this->settingClasses[$setting] = $type; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @param string $type 'admin' or 'personal' |
|
187 | - * @param string $section |
|
188 | - * @return ISettings[] |
|
189 | - */ |
|
190 | - protected function getSettings(string $type, string $section): array { |
|
191 | - if (!isset($this->settings[$type])) { |
|
192 | - $this->settings[$type] = []; |
|
193 | - } |
|
194 | - if (!isset($this->settings[$type][$section])) { |
|
195 | - $this->settings[$type][$section] = []; |
|
196 | - } |
|
197 | - |
|
198 | - foreach ($this->settingClasses as $class => $settingsType) { |
|
199 | - try { |
|
200 | - /** @var ISettings $setting */ |
|
201 | - $setting = \OC::$server->query($class); |
|
202 | - } catch (QueryException $e) { |
|
203 | - $this->log->logException($e, ['level' => ILogger::INFO]); |
|
204 | - continue; |
|
205 | - } |
|
206 | - |
|
207 | - if (!$setting instanceof ISettings) { |
|
208 | - $this->log->logException(new \InvalidArgumentException('Invalid settings setting registered'), ['level' => ILogger::INFO]); |
|
209 | - continue; |
|
210 | - } |
|
211 | - |
|
212 | - if (!isset($this->settings[$settingsType][$setting->getSection()])) { |
|
213 | - $this->settings[$settingsType][$setting->getSection()] = []; |
|
214 | - } |
|
215 | - $this->settings[$settingsType][$setting->getSection()][] = $setting; |
|
216 | - |
|
217 | - unset($this->settingClasses[$class]); |
|
218 | - } |
|
219 | - |
|
220 | - return $this->settings[$type][$section]; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @inheritdoc |
|
225 | - */ |
|
226 | - public function getAdminSections(): array { |
|
227 | - // built-in sections |
|
228 | - $sections = [ |
|
229 | - 0 => [new Section('overview', $this->l->t('Overview'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
230 | - 1 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
231 | - 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
232 | - 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
233 | - 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
234 | - 50 => [new Section('groupware', $this->l->t('Groupware'), 0, $this->url->imagePath('core', 'places/contacts.svg'))], |
|
235 | - 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
236 | - ]; |
|
237 | - |
|
238 | - $appSections = $this->getSections('admin'); |
|
239 | - |
|
240 | - foreach ($appSections as $section) { |
|
241 | - /** @var ISection $section */ |
|
242 | - if (!isset($sections[$section->getPriority()])) { |
|
243 | - $sections[$section->getPriority()] = []; |
|
244 | - } |
|
245 | - |
|
246 | - $sections[$section->getPriority()][] = $section; |
|
247 | - } |
|
248 | - |
|
249 | - ksort($sections); |
|
250 | - |
|
251 | - return $sections; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * @param string $section |
|
256 | - * @return ISection[] |
|
257 | - */ |
|
258 | - private function getBuiltInAdminSettings($section): array { |
|
259 | - $forms = []; |
|
260 | - |
|
261 | - if ($section === 'overview') { |
|
262 | - /** @var ISettings $form */ |
|
263 | - $form = new Admin\Overview($this->config); |
|
264 | - $forms[$form->getPriority()] = [$form]; |
|
265 | - } |
|
266 | - if ($section === 'server') { |
|
267 | - /** @var ISettings $form */ |
|
268 | - $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
269 | - $forms[$form->getPriority()] = [$form]; |
|
270 | - $form = new Admin\Mail($this->config); |
|
271 | - $forms[$form->getPriority()] = [$form]; |
|
272 | - } |
|
273 | - if ($section === 'encryption') { |
|
274 | - /** @var ISettings $form */ |
|
275 | - $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
276 | - $forms[$form->getPriority()] = [$form]; |
|
277 | - } |
|
278 | - if ($section === 'sharing') { |
|
279 | - /** @var ISettings $form */ |
|
280 | - $form = new Admin\Sharing($this->config, $this->l); |
|
281 | - $forms[$form->getPriority()] = [$form]; |
|
282 | - } |
|
283 | - |
|
284 | - return $forms; |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * @param string $section |
|
289 | - * @return ISection[] |
|
290 | - */ |
|
291 | - private function getBuiltInPersonalSettings($section): array { |
|
292 | - $forms = []; |
|
293 | - |
|
294 | - if ($section === 'personal-info') { |
|
295 | - /** @var ISettings $form */ |
|
296 | - $form = new Personal\PersonalInfo( |
|
297 | - $this->config, |
|
298 | - $this->userManager, |
|
299 | - $this->groupManager, |
|
300 | - $this->accountManager, |
|
301 | - $this->appManager, |
|
302 | - $this->l10nFactory, |
|
303 | - $this->l |
|
304 | - ); |
|
305 | - $forms[$form->getPriority()] = [$form]; |
|
306 | - $form = new Personal\ServerDevNotice(); |
|
307 | - $forms[$form->getPriority()] = [$form]; |
|
308 | - } |
|
309 | - if($section === 'security') { |
|
310 | - /** @var ISettings $form */ |
|
311 | - $form = new Personal\Security($this->userManager); |
|
312 | - $forms[$form->getPriority()] = [$form]; |
|
313 | - } |
|
314 | - if ($section === 'additional') { |
|
315 | - /** @var ISettings $form */ |
|
316 | - $form = new Personal\Additional(); |
|
317 | - $forms[$form->getPriority()] = [$form]; |
|
318 | - } |
|
319 | - |
|
320 | - return $forms; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * @inheritdoc |
|
325 | - */ |
|
326 | - public function getAdminSettings($section): array { |
|
327 | - $settings = $this->getBuiltInAdminSettings($section); |
|
328 | - $appSettings = $this->getSettings('admin', $section); |
|
329 | - |
|
330 | - foreach ($appSettings as $setting) { |
|
331 | - if (!isset($settings[$setting->getPriority()])) { |
|
332 | - $settings[$setting->getPriority()] = []; |
|
333 | - } |
|
334 | - $settings[$setting->getPriority()][] = $setting; |
|
335 | - } |
|
336 | - |
|
337 | - ksort($settings); |
|
338 | - return $settings; |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * @inheritdoc |
|
343 | - */ |
|
344 | - public function getPersonalSections(): array { |
|
345 | - $sections = [ |
|
346 | - 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
347 | - 5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
348 | - 15 => [new Section('sync-clients', $this->l->t('Mobile & desktop'), 0, $this->url->imagePath('core', 'clients/phone.svg'))], |
|
349 | - ]; |
|
350 | - |
|
351 | - $legacyForms = \OC_App::getForms('personal'); |
|
352 | - if(!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
|
353 | - $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
|
354 | - } |
|
355 | - |
|
356 | - $appSections = $this->getSections('personal'); |
|
357 | - |
|
358 | - foreach ($appSections as $section) { |
|
359 | - /** @var ISection $section */ |
|
360 | - if (!isset($sections[$section->getPriority()])) { |
|
361 | - $sections[$section->getPriority()] = []; |
|
362 | - } |
|
363 | - |
|
364 | - $sections[$section->getPriority()][] = $section; |
|
365 | - } |
|
366 | - |
|
367 | - ksort($sections); |
|
368 | - |
|
369 | - return $sections; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * @param string[] $forms |
|
374 | - * @return bool |
|
375 | - */ |
|
376 | - private function hasLegacyPersonalSettingsToRender(array $forms): bool { |
|
377 | - foreach ($forms as $form) { |
|
378 | - if(trim($form) !== '') { |
|
379 | - return true; |
|
380 | - } |
|
381 | - } |
|
382 | - return false; |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * @inheritdoc |
|
387 | - */ |
|
388 | - public function getPersonalSettings($section): array { |
|
389 | - $settings = $this->getBuiltInPersonalSettings($section); |
|
390 | - $appSettings = $this->getSettings('personal', $section); |
|
391 | - |
|
392 | - foreach ($appSettings as $setting) { |
|
393 | - if (!isset($settings[$setting->getPriority()])) { |
|
394 | - $settings[$setting->getPriority()] = []; |
|
395 | - } |
|
396 | - $settings[$setting->getPriority()][] = $setting; |
|
397 | - } |
|
398 | - |
|
399 | - ksort($settings); |
|
400 | - return $settings; |
|
401 | - } |
|
52 | + /** @var ILogger */ |
|
53 | + private $log; |
|
54 | + /** @var IDBConnection */ |
|
55 | + private $dbc; |
|
56 | + /** @var IL10N */ |
|
57 | + private $l; |
|
58 | + /** @var IConfig */ |
|
59 | + private $config; |
|
60 | + /** @var EncryptionManager */ |
|
61 | + private $encryptionManager; |
|
62 | + /** @var IUserManager */ |
|
63 | + private $userManager; |
|
64 | + /** @var ILockingProvider */ |
|
65 | + private $lockingProvider; |
|
66 | + /** @var IRequest */ |
|
67 | + private $request; |
|
68 | + /** @var IURLGenerator */ |
|
69 | + private $url; |
|
70 | + /** @var AccountManager */ |
|
71 | + private $accountManager; |
|
72 | + /** @var IGroupManager */ |
|
73 | + private $groupManager; |
|
74 | + /** @var IFactory */ |
|
75 | + private $l10nFactory; |
|
76 | + /** @var IAppManager */ |
|
77 | + private $appManager; |
|
78 | + |
|
79 | + /** |
|
80 | + * @param ILogger $log |
|
81 | + * @param IDBConnection $dbc |
|
82 | + * @param IL10N $l |
|
83 | + * @param IConfig $config |
|
84 | + * @param EncryptionManager $encryptionManager |
|
85 | + * @param IUserManager $userManager |
|
86 | + * @param ILockingProvider $lockingProvider |
|
87 | + * @param IRequest $request |
|
88 | + * @param IURLGenerator $url |
|
89 | + * @param AccountManager $accountManager |
|
90 | + * @param IGroupManager $groupManager |
|
91 | + * @param IFactory $l10nFactory |
|
92 | + * @param IAppManager $appManager |
|
93 | + */ |
|
94 | + public function __construct( |
|
95 | + ILogger $log, |
|
96 | + IDBConnection $dbc, |
|
97 | + IL10N $l, |
|
98 | + IConfig $config, |
|
99 | + EncryptionManager $encryptionManager, |
|
100 | + IUserManager $userManager, |
|
101 | + ILockingProvider $lockingProvider, |
|
102 | + IRequest $request, |
|
103 | + IURLGenerator $url, |
|
104 | + AccountManager $accountManager, |
|
105 | + IGroupManager $groupManager, |
|
106 | + IFactory $l10nFactory, |
|
107 | + IAppManager $appManager |
|
108 | + ) { |
|
109 | + $this->log = $log; |
|
110 | + $this->dbc = $dbc; |
|
111 | + $this->l = $l; |
|
112 | + $this->config = $config; |
|
113 | + $this->encryptionManager = $encryptionManager; |
|
114 | + $this->userManager = $userManager; |
|
115 | + $this->lockingProvider = $lockingProvider; |
|
116 | + $this->request = $request; |
|
117 | + $this->url = $url; |
|
118 | + $this->accountManager = $accountManager; |
|
119 | + $this->groupManager = $groupManager; |
|
120 | + $this->l10nFactory = $l10nFactory; |
|
121 | + $this->appManager = $appManager; |
|
122 | + } |
|
123 | + |
|
124 | + /** @var array */ |
|
125 | + protected $sectionClasses = []; |
|
126 | + |
|
127 | + /** @var array */ |
|
128 | + protected $sections = []; |
|
129 | + |
|
130 | + /** |
|
131 | + * @param string $type 'admin' or 'personal' |
|
132 | + * @param string $section Class must implement OCP\Settings\ISection |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + public function registerSection(string $type, string $section) { |
|
136 | + $this->sectionClasses[$section] = $type; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $type 'admin' or 'personal' |
|
141 | + * @return ISection[] |
|
142 | + */ |
|
143 | + protected function getSections(string $type): array { |
|
144 | + if (!isset($this->sections[$type])) { |
|
145 | + $this->sections[$type] = []; |
|
146 | + } |
|
147 | + |
|
148 | + foreach ($this->sectionClasses as $class => $sectionType) { |
|
149 | + try { |
|
150 | + /** @var ISection $section */ |
|
151 | + $section = \OC::$server->query($class); |
|
152 | + } catch (QueryException $e) { |
|
153 | + $this->log->logException($e, ['level' => ILogger::INFO]); |
|
154 | + continue; |
|
155 | + } |
|
156 | + |
|
157 | + if (!$section instanceof ISection) { |
|
158 | + $this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => ILogger::INFO]); |
|
159 | + continue; |
|
160 | + } |
|
161 | + |
|
162 | + $this->sections[$sectionType][$section->getID()] = $section; |
|
163 | + |
|
164 | + unset($this->sectionClasses[$class]); |
|
165 | + } |
|
166 | + |
|
167 | + return $this->sections[$type]; |
|
168 | + } |
|
169 | + |
|
170 | + /** @var array */ |
|
171 | + protected $settingClasses = []; |
|
172 | + |
|
173 | + /** @var array */ |
|
174 | + protected $settings = []; |
|
175 | + |
|
176 | + /** |
|
177 | + * @param string $type 'admin' or 'personal' |
|
178 | + * @param string $setting Class must implement OCP\Settings\ISetting |
|
179 | + * @return void |
|
180 | + */ |
|
181 | + public function registerSetting(string $type, string $setting) { |
|
182 | + $this->settingClasses[$setting] = $type; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @param string $type 'admin' or 'personal' |
|
187 | + * @param string $section |
|
188 | + * @return ISettings[] |
|
189 | + */ |
|
190 | + protected function getSettings(string $type, string $section): array { |
|
191 | + if (!isset($this->settings[$type])) { |
|
192 | + $this->settings[$type] = []; |
|
193 | + } |
|
194 | + if (!isset($this->settings[$type][$section])) { |
|
195 | + $this->settings[$type][$section] = []; |
|
196 | + } |
|
197 | + |
|
198 | + foreach ($this->settingClasses as $class => $settingsType) { |
|
199 | + try { |
|
200 | + /** @var ISettings $setting */ |
|
201 | + $setting = \OC::$server->query($class); |
|
202 | + } catch (QueryException $e) { |
|
203 | + $this->log->logException($e, ['level' => ILogger::INFO]); |
|
204 | + continue; |
|
205 | + } |
|
206 | + |
|
207 | + if (!$setting instanceof ISettings) { |
|
208 | + $this->log->logException(new \InvalidArgumentException('Invalid settings setting registered'), ['level' => ILogger::INFO]); |
|
209 | + continue; |
|
210 | + } |
|
211 | + |
|
212 | + if (!isset($this->settings[$settingsType][$setting->getSection()])) { |
|
213 | + $this->settings[$settingsType][$setting->getSection()] = []; |
|
214 | + } |
|
215 | + $this->settings[$settingsType][$setting->getSection()][] = $setting; |
|
216 | + |
|
217 | + unset($this->settingClasses[$class]); |
|
218 | + } |
|
219 | + |
|
220 | + return $this->settings[$type][$section]; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @inheritdoc |
|
225 | + */ |
|
226 | + public function getAdminSections(): array { |
|
227 | + // built-in sections |
|
228 | + $sections = [ |
|
229 | + 0 => [new Section('overview', $this->l->t('Overview'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
230 | + 1 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
231 | + 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
232 | + 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
233 | + 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
234 | + 50 => [new Section('groupware', $this->l->t('Groupware'), 0, $this->url->imagePath('core', 'places/contacts.svg'))], |
|
235 | + 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
236 | + ]; |
|
237 | + |
|
238 | + $appSections = $this->getSections('admin'); |
|
239 | + |
|
240 | + foreach ($appSections as $section) { |
|
241 | + /** @var ISection $section */ |
|
242 | + if (!isset($sections[$section->getPriority()])) { |
|
243 | + $sections[$section->getPriority()] = []; |
|
244 | + } |
|
245 | + |
|
246 | + $sections[$section->getPriority()][] = $section; |
|
247 | + } |
|
248 | + |
|
249 | + ksort($sections); |
|
250 | + |
|
251 | + return $sections; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * @param string $section |
|
256 | + * @return ISection[] |
|
257 | + */ |
|
258 | + private function getBuiltInAdminSettings($section): array { |
|
259 | + $forms = []; |
|
260 | + |
|
261 | + if ($section === 'overview') { |
|
262 | + /** @var ISettings $form */ |
|
263 | + $form = new Admin\Overview($this->config); |
|
264 | + $forms[$form->getPriority()] = [$form]; |
|
265 | + } |
|
266 | + if ($section === 'server') { |
|
267 | + /** @var ISettings $form */ |
|
268 | + $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
269 | + $forms[$form->getPriority()] = [$form]; |
|
270 | + $form = new Admin\Mail($this->config); |
|
271 | + $forms[$form->getPriority()] = [$form]; |
|
272 | + } |
|
273 | + if ($section === 'encryption') { |
|
274 | + /** @var ISettings $form */ |
|
275 | + $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
276 | + $forms[$form->getPriority()] = [$form]; |
|
277 | + } |
|
278 | + if ($section === 'sharing') { |
|
279 | + /** @var ISettings $form */ |
|
280 | + $form = new Admin\Sharing($this->config, $this->l); |
|
281 | + $forms[$form->getPriority()] = [$form]; |
|
282 | + } |
|
283 | + |
|
284 | + return $forms; |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * @param string $section |
|
289 | + * @return ISection[] |
|
290 | + */ |
|
291 | + private function getBuiltInPersonalSettings($section): array { |
|
292 | + $forms = []; |
|
293 | + |
|
294 | + if ($section === 'personal-info') { |
|
295 | + /** @var ISettings $form */ |
|
296 | + $form = new Personal\PersonalInfo( |
|
297 | + $this->config, |
|
298 | + $this->userManager, |
|
299 | + $this->groupManager, |
|
300 | + $this->accountManager, |
|
301 | + $this->appManager, |
|
302 | + $this->l10nFactory, |
|
303 | + $this->l |
|
304 | + ); |
|
305 | + $forms[$form->getPriority()] = [$form]; |
|
306 | + $form = new Personal\ServerDevNotice(); |
|
307 | + $forms[$form->getPriority()] = [$form]; |
|
308 | + } |
|
309 | + if($section === 'security') { |
|
310 | + /** @var ISettings $form */ |
|
311 | + $form = new Personal\Security($this->userManager); |
|
312 | + $forms[$form->getPriority()] = [$form]; |
|
313 | + } |
|
314 | + if ($section === 'additional') { |
|
315 | + /** @var ISettings $form */ |
|
316 | + $form = new Personal\Additional(); |
|
317 | + $forms[$form->getPriority()] = [$form]; |
|
318 | + } |
|
319 | + |
|
320 | + return $forms; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * @inheritdoc |
|
325 | + */ |
|
326 | + public function getAdminSettings($section): array { |
|
327 | + $settings = $this->getBuiltInAdminSettings($section); |
|
328 | + $appSettings = $this->getSettings('admin', $section); |
|
329 | + |
|
330 | + foreach ($appSettings as $setting) { |
|
331 | + if (!isset($settings[$setting->getPriority()])) { |
|
332 | + $settings[$setting->getPriority()] = []; |
|
333 | + } |
|
334 | + $settings[$setting->getPriority()][] = $setting; |
|
335 | + } |
|
336 | + |
|
337 | + ksort($settings); |
|
338 | + return $settings; |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * @inheritdoc |
|
343 | + */ |
|
344 | + public function getPersonalSections(): array { |
|
345 | + $sections = [ |
|
346 | + 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
347 | + 5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
348 | + 15 => [new Section('sync-clients', $this->l->t('Mobile & desktop'), 0, $this->url->imagePath('core', 'clients/phone.svg'))], |
|
349 | + ]; |
|
350 | + |
|
351 | + $legacyForms = \OC_App::getForms('personal'); |
|
352 | + if(!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
|
353 | + $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
|
354 | + } |
|
355 | + |
|
356 | + $appSections = $this->getSections('personal'); |
|
357 | + |
|
358 | + foreach ($appSections as $section) { |
|
359 | + /** @var ISection $section */ |
|
360 | + if (!isset($sections[$section->getPriority()])) { |
|
361 | + $sections[$section->getPriority()] = []; |
|
362 | + } |
|
363 | + |
|
364 | + $sections[$section->getPriority()][] = $section; |
|
365 | + } |
|
366 | + |
|
367 | + ksort($sections); |
|
368 | + |
|
369 | + return $sections; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * @param string[] $forms |
|
374 | + * @return bool |
|
375 | + */ |
|
376 | + private function hasLegacyPersonalSettingsToRender(array $forms): bool { |
|
377 | + foreach ($forms as $form) { |
|
378 | + if(trim($form) !== '') { |
|
379 | + return true; |
|
380 | + } |
|
381 | + } |
|
382 | + return false; |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * @inheritdoc |
|
387 | + */ |
|
388 | + public function getPersonalSettings($section): array { |
|
389 | + $settings = $this->getBuiltInPersonalSettings($section); |
|
390 | + $appSettings = $this->getSettings('personal', $section); |
|
391 | + |
|
392 | + foreach ($appSettings as $setting) { |
|
393 | + if (!isset($settings[$setting->getPriority()])) { |
|
394 | + $settings[$setting->getPriority()] = []; |
|
395 | + } |
|
396 | + $settings[$setting->getPriority()][] = $setting; |
|
397 | + } |
|
398 | + |
|
399 | + ksort($settings); |
|
400 | + return $settings; |
|
401 | + } |
|
402 | 402 | } |
@@ -160,1872 +160,1872 @@ |
||
160 | 160 | * TODO: hookup all manager classes |
161 | 161 | */ |
162 | 162 | class Server extends ServerContainer implements IServerContainer { |
163 | - /** @var string */ |
|
164 | - private $webRoot; |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string $webRoot |
|
168 | - * @param \OC\Config $config |
|
169 | - */ |
|
170 | - public function __construct($webRoot, \OC\Config $config) { |
|
171 | - parent::__construct(); |
|
172 | - $this->webRoot = $webRoot; |
|
173 | - |
|
174 | - // To find out if we are running from CLI or not |
|
175 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
176 | - |
|
177 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
178 | - return $c; |
|
179 | - }); |
|
180 | - |
|
181 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
182 | - $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
183 | - |
|
184 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
185 | - $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
186 | - |
|
187 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
188 | - $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
189 | - |
|
190 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
191 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
192 | - |
|
193 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
194 | - |
|
195 | - |
|
196 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
197 | - return new PreviewManager( |
|
198 | - $c->getConfig(), |
|
199 | - $c->getRootFolder(), |
|
200 | - $c->getAppDataDir('preview'), |
|
201 | - $c->getEventDispatcher(), |
|
202 | - $c->getSession()->get('user_id') |
|
203 | - ); |
|
204 | - }); |
|
205 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
206 | - |
|
207 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
208 | - return new \OC\Preview\Watcher( |
|
209 | - $c->getAppDataDir('preview') |
|
210 | - ); |
|
211 | - }); |
|
212 | - |
|
213 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
214 | - $view = new View(); |
|
215 | - $util = new Encryption\Util( |
|
216 | - $view, |
|
217 | - $c->getUserManager(), |
|
218 | - $c->getGroupManager(), |
|
219 | - $c->getConfig() |
|
220 | - ); |
|
221 | - return new Encryption\Manager( |
|
222 | - $c->getConfig(), |
|
223 | - $c->getLogger(), |
|
224 | - $c->getL10N('core'), |
|
225 | - new View(), |
|
226 | - $util, |
|
227 | - new ArrayCache() |
|
228 | - ); |
|
229 | - }); |
|
230 | - |
|
231 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
232 | - $util = new Encryption\Util( |
|
233 | - new View(), |
|
234 | - $c->getUserManager(), |
|
235 | - $c->getGroupManager(), |
|
236 | - $c->getConfig() |
|
237 | - ); |
|
238 | - return new Encryption\File( |
|
239 | - $util, |
|
240 | - $c->getRootFolder(), |
|
241 | - $c->getShareManager() |
|
242 | - ); |
|
243 | - }); |
|
244 | - |
|
245 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
246 | - $view = new View(); |
|
247 | - $util = new Encryption\Util( |
|
248 | - $view, |
|
249 | - $c->getUserManager(), |
|
250 | - $c->getGroupManager(), |
|
251 | - $c->getConfig() |
|
252 | - ); |
|
253 | - |
|
254 | - return new Encryption\Keys\Storage($view, $util); |
|
255 | - }); |
|
256 | - $this->registerService('TagMapper', function (Server $c) { |
|
257 | - return new TagMapper($c->getDatabaseConnection()); |
|
258 | - }); |
|
259 | - |
|
260 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
261 | - $tagMapper = $c->query('TagMapper'); |
|
262 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
263 | - }); |
|
264 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
265 | - |
|
266 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
267 | - $config = $c->getConfig(); |
|
268 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
269 | - return new $factoryClass($this); |
|
270 | - }); |
|
271 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
272 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
273 | - }); |
|
274 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
275 | - |
|
276 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
277 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
278 | - }); |
|
279 | - $this->registerService('RootFolder', function (Server $c) { |
|
280 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
281 | - $view = new View(); |
|
282 | - $root = new Root( |
|
283 | - $manager, |
|
284 | - $view, |
|
285 | - null, |
|
286 | - $c->getUserMountCache(), |
|
287 | - $this->getLogger(), |
|
288 | - $this->getUserManager() |
|
289 | - ); |
|
290 | - $connector = new HookConnector($root, $view); |
|
291 | - $connector->viewToNode(); |
|
292 | - |
|
293 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
294 | - $previewConnector->connectWatcher(); |
|
295 | - |
|
296 | - return $root; |
|
297 | - }); |
|
298 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
299 | - |
|
300 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
301 | - return new LazyRoot(function () use ($c) { |
|
302 | - return $c->query('RootFolder'); |
|
303 | - }); |
|
304 | - }); |
|
305 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
306 | - |
|
307 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
308 | - $config = $c->getConfig(); |
|
309 | - return new \OC\User\Manager($config); |
|
310 | - }); |
|
311 | - $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
312 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
313 | - |
|
314 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
315 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
316 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
317 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
318 | - }); |
|
319 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
320 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
321 | - }); |
|
322 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
323 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
324 | - }); |
|
325 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
326 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
327 | - }); |
|
328 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
329 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
330 | - }); |
|
331 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
332 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
333 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
334 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
335 | - }); |
|
336 | - return $groupManager; |
|
337 | - }); |
|
338 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
339 | - |
|
340 | - $this->registerService(Store::class, function (Server $c) { |
|
341 | - $session = $c->getSession(); |
|
342 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
343 | - $tokenProvider = $c->query(IProvider::class); |
|
344 | - } else { |
|
345 | - $tokenProvider = null; |
|
346 | - } |
|
347 | - $logger = $c->getLogger(); |
|
348 | - return new Store($session, $logger, $tokenProvider); |
|
349 | - }); |
|
350 | - $this->registerAlias(IStore::class, Store::class); |
|
351 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
352 | - $dbConnection = $c->getDatabaseConnection(); |
|
353 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
354 | - }); |
|
355 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
356 | - |
|
357 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
358 | - $manager = $c->getUserManager(); |
|
359 | - $session = new \OC\Session\Memory(''); |
|
360 | - $timeFactory = new TimeFactory(); |
|
361 | - // Token providers might require a working database. This code |
|
362 | - // might however be called when ownCloud is not yet setup. |
|
363 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
364 | - $defaultTokenProvider = $c->query(IProvider::class); |
|
365 | - } else { |
|
366 | - $defaultTokenProvider = null; |
|
367 | - } |
|
368 | - |
|
369 | - $dispatcher = $c->getEventDispatcher(); |
|
370 | - |
|
371 | - $userSession = new \OC\User\Session( |
|
372 | - $manager, |
|
373 | - $session, |
|
374 | - $timeFactory, |
|
375 | - $defaultTokenProvider, |
|
376 | - $c->getConfig(), |
|
377 | - $c->getSecureRandom(), |
|
378 | - $c->getLockdownManager(), |
|
379 | - $c->getLogger() |
|
380 | - ); |
|
381 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
382 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
383 | - }); |
|
384 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
385 | - /** @var $user \OC\User\User */ |
|
386 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
387 | - }); |
|
388 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
389 | - /** @var $user \OC\User\User */ |
|
390 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
391 | - $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
392 | - }); |
|
393 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
394 | - /** @var $user \OC\User\User */ |
|
395 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
396 | - }); |
|
397 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
398 | - /** @var $user \OC\User\User */ |
|
399 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
400 | - }); |
|
401 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
402 | - /** @var $user \OC\User\User */ |
|
403 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
404 | - }); |
|
405 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
406 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
407 | - }); |
|
408 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
409 | - /** @var $user \OC\User\User */ |
|
410 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
411 | - }); |
|
412 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
413 | - /** @var $user \OC\User\User */ |
|
414 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
415 | - }); |
|
416 | - $userSession->listen('\OC\User', 'logout', function () { |
|
417 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
418 | - }); |
|
419 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
420 | - /** @var $user \OC\User\User */ |
|
421 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
422 | - $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
423 | - }); |
|
424 | - return $userSession; |
|
425 | - }); |
|
426 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
427 | - |
|
428 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
429 | - |
|
430 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
431 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
432 | - |
|
433 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
434 | - return new \OC\AllConfig( |
|
435 | - $c->getSystemConfig() |
|
436 | - ); |
|
437 | - }); |
|
438 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
439 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
440 | - |
|
441 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
442 | - return new \OC\SystemConfig($config); |
|
443 | - }); |
|
444 | - |
|
445 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
446 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
447 | - }); |
|
448 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
449 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
450 | - |
|
451 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
452 | - return new \OC\L10N\Factory( |
|
453 | - $c->getConfig(), |
|
454 | - $c->getRequest(), |
|
455 | - $c->getUserSession(), |
|
456 | - \OC::$SERVERROOT |
|
457 | - ); |
|
458 | - }); |
|
459 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
460 | - |
|
461 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
462 | - $config = $c->getConfig(); |
|
463 | - $cacheFactory = $c->getMemCacheFactory(); |
|
464 | - $request = $c->getRequest(); |
|
465 | - return new \OC\URLGenerator( |
|
466 | - $config, |
|
467 | - $cacheFactory, |
|
468 | - $request |
|
469 | - ); |
|
470 | - }); |
|
471 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
472 | - |
|
473 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
474 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
475 | - |
|
476 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
477 | - return new Cache\File(); |
|
478 | - }); |
|
479 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
480 | - |
|
481 | - $this->registerService(Factory::class, function (Server $c) { |
|
482 | - |
|
483 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
484 | - ArrayCache::class, |
|
485 | - ArrayCache::class, |
|
486 | - ArrayCache::class |
|
487 | - ); |
|
488 | - $config = $c->getConfig(); |
|
489 | - $request = $c->getRequest(); |
|
490 | - $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
491 | - |
|
492 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
493 | - $v = \OC_App::getAppVersions(); |
|
494 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
495 | - $version = implode(',', $v); |
|
496 | - $instanceId = \OC_Util::getInstanceId(); |
|
497 | - $path = \OC::$SERVERROOT; |
|
498 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
499 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
500 | - $config->getSystemValue('memcache.local', null), |
|
501 | - $config->getSystemValue('memcache.distributed', null), |
|
502 | - $config->getSystemValue('memcache.locking', null) |
|
503 | - ); |
|
504 | - } |
|
505 | - return $arrayCacheFactory; |
|
506 | - |
|
507 | - }); |
|
508 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
509 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
510 | - |
|
511 | - $this->registerService('RedisFactory', function (Server $c) { |
|
512 | - $systemConfig = $c->getSystemConfig(); |
|
513 | - return new RedisFactory($systemConfig); |
|
514 | - }); |
|
515 | - |
|
516 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
517 | - return new \OC\Activity\Manager( |
|
518 | - $c->getRequest(), |
|
519 | - $c->getUserSession(), |
|
520 | - $c->getConfig(), |
|
521 | - $c->query(IValidator::class) |
|
522 | - ); |
|
523 | - }); |
|
524 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
525 | - |
|
526 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
527 | - return new \OC\Activity\EventMerger( |
|
528 | - $c->getL10N('lib') |
|
529 | - ); |
|
530 | - }); |
|
531 | - $this->registerAlias(IValidator::class, Validator::class); |
|
532 | - |
|
533 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
534 | - return new AvatarManager( |
|
535 | - $c->query(\OC\User\Manager::class), |
|
536 | - $c->getAppDataDir('avatar'), |
|
537 | - $c->getL10N('lib'), |
|
538 | - $c->getLogger(), |
|
539 | - $c->getConfig() |
|
540 | - ); |
|
541 | - }); |
|
542 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
543 | - |
|
544 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
545 | - |
|
546 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
547 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
548 | - $factory = new LogFactory($c, $this->getSystemConfig()); |
|
549 | - $logger = $factory->get($logType); |
|
550 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
551 | - |
|
552 | - return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
553 | - }); |
|
554 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
555 | - |
|
556 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
557 | - return new LogFactory($c, $this->getSystemConfig()); |
|
558 | - }); |
|
559 | - |
|
560 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
561 | - $config = $c->getConfig(); |
|
562 | - return new \OC\BackgroundJob\JobList( |
|
563 | - $c->getDatabaseConnection(), |
|
564 | - $config, |
|
565 | - new TimeFactory() |
|
566 | - ); |
|
567 | - }); |
|
568 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
569 | - |
|
570 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
571 | - $cacheFactory = $c->getMemCacheFactory(); |
|
572 | - $logger = $c->getLogger(); |
|
573 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
574 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
575 | - } else { |
|
576 | - $router = new \OC\Route\Router($logger); |
|
577 | - } |
|
578 | - return $router; |
|
579 | - }); |
|
580 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
581 | - |
|
582 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
583 | - return new Search(); |
|
584 | - }); |
|
585 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
586 | - |
|
587 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
588 | - return new \OC\Security\RateLimiting\Limiter( |
|
589 | - $this->getUserSession(), |
|
590 | - $this->getRequest(), |
|
591 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
592 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
593 | - ); |
|
594 | - }); |
|
595 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
596 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
597 | - $this->getMemCacheFactory(), |
|
598 | - new \OC\AppFramework\Utility\TimeFactory() |
|
599 | - ); |
|
600 | - }); |
|
601 | - |
|
602 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
603 | - return new SecureRandom(); |
|
604 | - }); |
|
605 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
606 | - |
|
607 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
608 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
609 | - }); |
|
610 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
611 | - |
|
612 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
613 | - return new Hasher($c->getConfig()); |
|
614 | - }); |
|
615 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
616 | - |
|
617 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
618 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
619 | - }); |
|
620 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
621 | - |
|
622 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
623 | - $systemConfig = $c->getSystemConfig(); |
|
624 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
625 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
626 | - if (!$factory->isValidType($type)) { |
|
627 | - throw new \OC\DatabaseException('Invalid database type'); |
|
628 | - } |
|
629 | - $connectionParams = $factory->createConnectionParams(); |
|
630 | - $connection = $factory->getConnection($type, $connectionParams); |
|
631 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
632 | - return $connection; |
|
633 | - }); |
|
634 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
635 | - |
|
636 | - |
|
637 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
638 | - $user = \OC_User::getUser(); |
|
639 | - $uid = $user ? $user : null; |
|
640 | - return new ClientService( |
|
641 | - $c->getConfig(), |
|
642 | - new \OC\Security\CertificateManager( |
|
643 | - $uid, |
|
644 | - new View(), |
|
645 | - $c->getConfig(), |
|
646 | - $c->getLogger(), |
|
647 | - $c->getSecureRandom() |
|
648 | - ) |
|
649 | - ); |
|
650 | - }); |
|
651 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
652 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
653 | - $eventLogger = new EventLogger(); |
|
654 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
655 | - // In debug mode, module is being activated by default |
|
656 | - $eventLogger->activate(); |
|
657 | - } |
|
658 | - return $eventLogger; |
|
659 | - }); |
|
660 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
661 | - |
|
662 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
663 | - $queryLogger = new QueryLogger(); |
|
664 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
665 | - // In debug mode, module is being activated by default |
|
666 | - $queryLogger->activate(); |
|
667 | - } |
|
668 | - return $queryLogger; |
|
669 | - }); |
|
670 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
671 | - |
|
672 | - $this->registerService(TempManager::class, function (Server $c) { |
|
673 | - return new TempManager( |
|
674 | - $c->getLogger(), |
|
675 | - $c->getConfig() |
|
676 | - ); |
|
677 | - }); |
|
678 | - $this->registerAlias('TempManager', TempManager::class); |
|
679 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
680 | - |
|
681 | - $this->registerService(AppManager::class, function (Server $c) { |
|
682 | - return new \OC\App\AppManager( |
|
683 | - $c->getUserSession(), |
|
684 | - $c->query(\OC\AppConfig::class), |
|
685 | - $c->getGroupManager(), |
|
686 | - $c->getMemCacheFactory(), |
|
687 | - $c->getEventDispatcher() |
|
688 | - ); |
|
689 | - }); |
|
690 | - $this->registerAlias('AppManager', AppManager::class); |
|
691 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
692 | - |
|
693 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
694 | - return new DateTimeZone( |
|
695 | - $c->getConfig(), |
|
696 | - $c->getSession() |
|
697 | - ); |
|
698 | - }); |
|
699 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
700 | - |
|
701 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
702 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
703 | - |
|
704 | - return new DateTimeFormatter( |
|
705 | - $c->getDateTimeZone()->getTimeZone(), |
|
706 | - $c->getL10N('lib', $language) |
|
707 | - ); |
|
708 | - }); |
|
709 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
710 | - |
|
711 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
712 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
713 | - $listener = new UserMountCacheListener($mountCache); |
|
714 | - $listener->listen($c->getUserManager()); |
|
715 | - return $mountCache; |
|
716 | - }); |
|
717 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
718 | - |
|
719 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
720 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
721 | - $mountCache = $c->query('UserMountCache'); |
|
722 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
723 | - |
|
724 | - // builtin providers |
|
725 | - |
|
726 | - $config = $c->getConfig(); |
|
727 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
728 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
729 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
730 | - |
|
731 | - return $manager; |
|
732 | - }); |
|
733 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
734 | - |
|
735 | - $this->registerService('IniWrapper', function ($c) { |
|
736 | - return new IniGetWrapper(); |
|
737 | - }); |
|
738 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
739 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
740 | - if ($busClass) { |
|
741 | - list($app, $class) = explode('::', $busClass, 2); |
|
742 | - if ($c->getAppManager()->isInstalled($app)) { |
|
743 | - \OC_App::loadApp($app); |
|
744 | - return $c->query($class); |
|
745 | - } else { |
|
746 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
747 | - } |
|
748 | - } else { |
|
749 | - $jobList = $c->getJobList(); |
|
750 | - return new CronBus($jobList); |
|
751 | - } |
|
752 | - }); |
|
753 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
754 | - return new TrustedDomainHelper($this->getConfig()); |
|
755 | - }); |
|
756 | - $this->registerService('Throttler', function (Server $c) { |
|
757 | - return new Throttler( |
|
758 | - $c->getDatabaseConnection(), |
|
759 | - new TimeFactory(), |
|
760 | - $c->getLogger(), |
|
761 | - $c->getConfig() |
|
762 | - ); |
|
763 | - }); |
|
764 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
765 | - // IConfig and IAppManager requires a working database. This code |
|
766 | - // might however be called when ownCloud is not yet setup. |
|
767 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
768 | - $config = $c->getConfig(); |
|
769 | - $appManager = $c->getAppManager(); |
|
770 | - } else { |
|
771 | - $config = null; |
|
772 | - $appManager = null; |
|
773 | - } |
|
774 | - |
|
775 | - return new Checker( |
|
776 | - new EnvironmentHelper(), |
|
777 | - new FileAccessHelper(), |
|
778 | - new AppLocator(), |
|
779 | - $config, |
|
780 | - $c->getMemCacheFactory(), |
|
781 | - $appManager, |
|
782 | - $c->getTempManager() |
|
783 | - ); |
|
784 | - }); |
|
785 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
786 | - if (isset($this['urlParams'])) { |
|
787 | - $urlParams = $this['urlParams']; |
|
788 | - } else { |
|
789 | - $urlParams = []; |
|
790 | - } |
|
791 | - |
|
792 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
793 | - && in_array('fakeinput', stream_get_wrappers()) |
|
794 | - ) { |
|
795 | - $stream = 'fakeinput://data'; |
|
796 | - } else { |
|
797 | - $stream = 'php://input'; |
|
798 | - } |
|
799 | - |
|
800 | - return new Request( |
|
801 | - [ |
|
802 | - 'get' => $_GET, |
|
803 | - 'post' => $_POST, |
|
804 | - 'files' => $_FILES, |
|
805 | - 'server' => $_SERVER, |
|
806 | - 'env' => $_ENV, |
|
807 | - 'cookies' => $_COOKIE, |
|
808 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
809 | - ? $_SERVER['REQUEST_METHOD'] |
|
810 | - : '', |
|
811 | - 'urlParams' => $urlParams, |
|
812 | - ], |
|
813 | - $this->getSecureRandom(), |
|
814 | - $this->getConfig(), |
|
815 | - $this->getCsrfTokenManager(), |
|
816 | - $stream |
|
817 | - ); |
|
818 | - }); |
|
819 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
820 | - |
|
821 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
822 | - return new Mailer( |
|
823 | - $c->getConfig(), |
|
824 | - $c->getLogger(), |
|
825 | - $c->query(Defaults::class), |
|
826 | - $c->getURLGenerator(), |
|
827 | - $c->getL10N('lib') |
|
828 | - ); |
|
829 | - }); |
|
830 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
831 | - |
|
832 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
833 | - $config = $c->getConfig(); |
|
834 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
835 | - if (is_null($factoryClass)) { |
|
836 | - throw new \Exception('ldapProviderFactory not set'); |
|
837 | - } |
|
838 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
839 | - $factory = new $factoryClass($this); |
|
840 | - return $factory->getLDAPProvider(); |
|
841 | - }); |
|
842 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
843 | - $ini = $c->getIniWrapper(); |
|
844 | - $config = $c->getConfig(); |
|
845 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
846 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
847 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
848 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
849 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
850 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
851 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
852 | - } |
|
853 | - return new DBLockingProvider( |
|
854 | - $c->getDatabaseConnection(), |
|
855 | - $c->getLogger(), |
|
856 | - new TimeFactory(), |
|
857 | - $ttl, |
|
858 | - !\OC::$CLI |
|
859 | - ); |
|
860 | - } |
|
861 | - return new NoopLockingProvider(); |
|
862 | - }); |
|
863 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
864 | - |
|
865 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
866 | - return new \OC\Files\Mount\Manager(); |
|
867 | - }); |
|
868 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
869 | - |
|
870 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
871 | - return new \OC\Files\Type\Detection( |
|
872 | - $c->getURLGenerator(), |
|
873 | - \OC::$configDir, |
|
874 | - \OC::$SERVERROOT . '/resources/config/' |
|
875 | - ); |
|
876 | - }); |
|
877 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
878 | - |
|
879 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
880 | - return new \OC\Files\Type\Loader( |
|
881 | - $c->getDatabaseConnection() |
|
882 | - ); |
|
883 | - }); |
|
884 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
885 | - $this->registerService(BundleFetcher::class, function () { |
|
886 | - return new BundleFetcher($this->getL10N('lib')); |
|
887 | - }); |
|
888 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
889 | - return new Manager( |
|
890 | - $c->query(IValidator::class) |
|
891 | - ); |
|
892 | - }); |
|
893 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
894 | - |
|
895 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
896 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
897 | - $manager->registerCapability(function () use ($c) { |
|
898 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
899 | - }); |
|
900 | - $manager->registerCapability(function () use ($c) { |
|
901 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
902 | - }); |
|
903 | - return $manager; |
|
904 | - }); |
|
905 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
906 | - |
|
907 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
908 | - $config = $c->getConfig(); |
|
909 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
910 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
911 | - $factory = new $factoryClass($this); |
|
912 | - $manager = $factory->getManager(); |
|
913 | - |
|
914 | - $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
915 | - $manager = $c->getUserManager(); |
|
916 | - $user = $manager->get($id); |
|
917 | - if(is_null($user)) { |
|
918 | - $l = $c->getL10N('core'); |
|
919 | - $displayName = $l->t('Unknown user'); |
|
920 | - } else { |
|
921 | - $displayName = $user->getDisplayName(); |
|
922 | - } |
|
923 | - return $displayName; |
|
924 | - }); |
|
925 | - |
|
926 | - return $manager; |
|
927 | - }); |
|
928 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
929 | - |
|
930 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
931 | - /* |
|
163 | + /** @var string */ |
|
164 | + private $webRoot; |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string $webRoot |
|
168 | + * @param \OC\Config $config |
|
169 | + */ |
|
170 | + public function __construct($webRoot, \OC\Config $config) { |
|
171 | + parent::__construct(); |
|
172 | + $this->webRoot = $webRoot; |
|
173 | + |
|
174 | + // To find out if we are running from CLI or not |
|
175 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
176 | + |
|
177 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
178 | + return $c; |
|
179 | + }); |
|
180 | + |
|
181 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
182 | + $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
183 | + |
|
184 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
185 | + $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
186 | + |
|
187 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
188 | + $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
189 | + |
|
190 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
191 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
192 | + |
|
193 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
194 | + |
|
195 | + |
|
196 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
197 | + return new PreviewManager( |
|
198 | + $c->getConfig(), |
|
199 | + $c->getRootFolder(), |
|
200 | + $c->getAppDataDir('preview'), |
|
201 | + $c->getEventDispatcher(), |
|
202 | + $c->getSession()->get('user_id') |
|
203 | + ); |
|
204 | + }); |
|
205 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
206 | + |
|
207 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
208 | + return new \OC\Preview\Watcher( |
|
209 | + $c->getAppDataDir('preview') |
|
210 | + ); |
|
211 | + }); |
|
212 | + |
|
213 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
214 | + $view = new View(); |
|
215 | + $util = new Encryption\Util( |
|
216 | + $view, |
|
217 | + $c->getUserManager(), |
|
218 | + $c->getGroupManager(), |
|
219 | + $c->getConfig() |
|
220 | + ); |
|
221 | + return new Encryption\Manager( |
|
222 | + $c->getConfig(), |
|
223 | + $c->getLogger(), |
|
224 | + $c->getL10N('core'), |
|
225 | + new View(), |
|
226 | + $util, |
|
227 | + new ArrayCache() |
|
228 | + ); |
|
229 | + }); |
|
230 | + |
|
231 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
232 | + $util = new Encryption\Util( |
|
233 | + new View(), |
|
234 | + $c->getUserManager(), |
|
235 | + $c->getGroupManager(), |
|
236 | + $c->getConfig() |
|
237 | + ); |
|
238 | + return new Encryption\File( |
|
239 | + $util, |
|
240 | + $c->getRootFolder(), |
|
241 | + $c->getShareManager() |
|
242 | + ); |
|
243 | + }); |
|
244 | + |
|
245 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
246 | + $view = new View(); |
|
247 | + $util = new Encryption\Util( |
|
248 | + $view, |
|
249 | + $c->getUserManager(), |
|
250 | + $c->getGroupManager(), |
|
251 | + $c->getConfig() |
|
252 | + ); |
|
253 | + |
|
254 | + return new Encryption\Keys\Storage($view, $util); |
|
255 | + }); |
|
256 | + $this->registerService('TagMapper', function (Server $c) { |
|
257 | + return new TagMapper($c->getDatabaseConnection()); |
|
258 | + }); |
|
259 | + |
|
260 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
261 | + $tagMapper = $c->query('TagMapper'); |
|
262 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
263 | + }); |
|
264 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
265 | + |
|
266 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
267 | + $config = $c->getConfig(); |
|
268 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
269 | + return new $factoryClass($this); |
|
270 | + }); |
|
271 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
272 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
273 | + }); |
|
274 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
275 | + |
|
276 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
277 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
278 | + }); |
|
279 | + $this->registerService('RootFolder', function (Server $c) { |
|
280 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
281 | + $view = new View(); |
|
282 | + $root = new Root( |
|
283 | + $manager, |
|
284 | + $view, |
|
285 | + null, |
|
286 | + $c->getUserMountCache(), |
|
287 | + $this->getLogger(), |
|
288 | + $this->getUserManager() |
|
289 | + ); |
|
290 | + $connector = new HookConnector($root, $view); |
|
291 | + $connector->viewToNode(); |
|
292 | + |
|
293 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
294 | + $previewConnector->connectWatcher(); |
|
295 | + |
|
296 | + return $root; |
|
297 | + }); |
|
298 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
299 | + |
|
300 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
301 | + return new LazyRoot(function () use ($c) { |
|
302 | + return $c->query('RootFolder'); |
|
303 | + }); |
|
304 | + }); |
|
305 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
306 | + |
|
307 | + $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
308 | + $config = $c->getConfig(); |
|
309 | + return new \OC\User\Manager($config); |
|
310 | + }); |
|
311 | + $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
312 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
313 | + |
|
314 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
315 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
316 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
317 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
318 | + }); |
|
319 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
320 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
321 | + }); |
|
322 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
323 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
324 | + }); |
|
325 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
326 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
327 | + }); |
|
328 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
329 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
330 | + }); |
|
331 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
332 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
333 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
334 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
335 | + }); |
|
336 | + return $groupManager; |
|
337 | + }); |
|
338 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
339 | + |
|
340 | + $this->registerService(Store::class, function (Server $c) { |
|
341 | + $session = $c->getSession(); |
|
342 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
343 | + $tokenProvider = $c->query(IProvider::class); |
|
344 | + } else { |
|
345 | + $tokenProvider = null; |
|
346 | + } |
|
347 | + $logger = $c->getLogger(); |
|
348 | + return new Store($session, $logger, $tokenProvider); |
|
349 | + }); |
|
350 | + $this->registerAlias(IStore::class, Store::class); |
|
351 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
352 | + $dbConnection = $c->getDatabaseConnection(); |
|
353 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
354 | + }); |
|
355 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
356 | + |
|
357 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
358 | + $manager = $c->getUserManager(); |
|
359 | + $session = new \OC\Session\Memory(''); |
|
360 | + $timeFactory = new TimeFactory(); |
|
361 | + // Token providers might require a working database. This code |
|
362 | + // might however be called when ownCloud is not yet setup. |
|
363 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
364 | + $defaultTokenProvider = $c->query(IProvider::class); |
|
365 | + } else { |
|
366 | + $defaultTokenProvider = null; |
|
367 | + } |
|
368 | + |
|
369 | + $dispatcher = $c->getEventDispatcher(); |
|
370 | + |
|
371 | + $userSession = new \OC\User\Session( |
|
372 | + $manager, |
|
373 | + $session, |
|
374 | + $timeFactory, |
|
375 | + $defaultTokenProvider, |
|
376 | + $c->getConfig(), |
|
377 | + $c->getSecureRandom(), |
|
378 | + $c->getLockdownManager(), |
|
379 | + $c->getLogger() |
|
380 | + ); |
|
381 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
382 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
383 | + }); |
|
384 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
385 | + /** @var $user \OC\User\User */ |
|
386 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
387 | + }); |
|
388 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
389 | + /** @var $user \OC\User\User */ |
|
390 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
391 | + $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
392 | + }); |
|
393 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
394 | + /** @var $user \OC\User\User */ |
|
395 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
396 | + }); |
|
397 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
398 | + /** @var $user \OC\User\User */ |
|
399 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
400 | + }); |
|
401 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
402 | + /** @var $user \OC\User\User */ |
|
403 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
404 | + }); |
|
405 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
406 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
407 | + }); |
|
408 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
409 | + /** @var $user \OC\User\User */ |
|
410 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
411 | + }); |
|
412 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
413 | + /** @var $user \OC\User\User */ |
|
414 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
415 | + }); |
|
416 | + $userSession->listen('\OC\User', 'logout', function () { |
|
417 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
418 | + }); |
|
419 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
420 | + /** @var $user \OC\User\User */ |
|
421 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
422 | + $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
423 | + }); |
|
424 | + return $userSession; |
|
425 | + }); |
|
426 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
427 | + |
|
428 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
429 | + |
|
430 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
431 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
432 | + |
|
433 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
434 | + return new \OC\AllConfig( |
|
435 | + $c->getSystemConfig() |
|
436 | + ); |
|
437 | + }); |
|
438 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
439 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
440 | + |
|
441 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
442 | + return new \OC\SystemConfig($config); |
|
443 | + }); |
|
444 | + |
|
445 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
446 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
447 | + }); |
|
448 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
449 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
450 | + |
|
451 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
452 | + return new \OC\L10N\Factory( |
|
453 | + $c->getConfig(), |
|
454 | + $c->getRequest(), |
|
455 | + $c->getUserSession(), |
|
456 | + \OC::$SERVERROOT |
|
457 | + ); |
|
458 | + }); |
|
459 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
460 | + |
|
461 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
462 | + $config = $c->getConfig(); |
|
463 | + $cacheFactory = $c->getMemCacheFactory(); |
|
464 | + $request = $c->getRequest(); |
|
465 | + return new \OC\URLGenerator( |
|
466 | + $config, |
|
467 | + $cacheFactory, |
|
468 | + $request |
|
469 | + ); |
|
470 | + }); |
|
471 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
472 | + |
|
473 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
474 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
475 | + |
|
476 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
477 | + return new Cache\File(); |
|
478 | + }); |
|
479 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
480 | + |
|
481 | + $this->registerService(Factory::class, function (Server $c) { |
|
482 | + |
|
483 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
484 | + ArrayCache::class, |
|
485 | + ArrayCache::class, |
|
486 | + ArrayCache::class |
|
487 | + ); |
|
488 | + $config = $c->getConfig(); |
|
489 | + $request = $c->getRequest(); |
|
490 | + $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
491 | + |
|
492 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
493 | + $v = \OC_App::getAppVersions(); |
|
494 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
495 | + $version = implode(',', $v); |
|
496 | + $instanceId = \OC_Util::getInstanceId(); |
|
497 | + $path = \OC::$SERVERROOT; |
|
498 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
499 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
500 | + $config->getSystemValue('memcache.local', null), |
|
501 | + $config->getSystemValue('memcache.distributed', null), |
|
502 | + $config->getSystemValue('memcache.locking', null) |
|
503 | + ); |
|
504 | + } |
|
505 | + return $arrayCacheFactory; |
|
506 | + |
|
507 | + }); |
|
508 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
509 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
510 | + |
|
511 | + $this->registerService('RedisFactory', function (Server $c) { |
|
512 | + $systemConfig = $c->getSystemConfig(); |
|
513 | + return new RedisFactory($systemConfig); |
|
514 | + }); |
|
515 | + |
|
516 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
517 | + return new \OC\Activity\Manager( |
|
518 | + $c->getRequest(), |
|
519 | + $c->getUserSession(), |
|
520 | + $c->getConfig(), |
|
521 | + $c->query(IValidator::class) |
|
522 | + ); |
|
523 | + }); |
|
524 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
525 | + |
|
526 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
527 | + return new \OC\Activity\EventMerger( |
|
528 | + $c->getL10N('lib') |
|
529 | + ); |
|
530 | + }); |
|
531 | + $this->registerAlias(IValidator::class, Validator::class); |
|
532 | + |
|
533 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
534 | + return new AvatarManager( |
|
535 | + $c->query(\OC\User\Manager::class), |
|
536 | + $c->getAppDataDir('avatar'), |
|
537 | + $c->getL10N('lib'), |
|
538 | + $c->getLogger(), |
|
539 | + $c->getConfig() |
|
540 | + ); |
|
541 | + }); |
|
542 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
543 | + |
|
544 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
545 | + |
|
546 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
547 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
548 | + $factory = new LogFactory($c, $this->getSystemConfig()); |
|
549 | + $logger = $factory->get($logType); |
|
550 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
551 | + |
|
552 | + return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
553 | + }); |
|
554 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
555 | + |
|
556 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
557 | + return new LogFactory($c, $this->getSystemConfig()); |
|
558 | + }); |
|
559 | + |
|
560 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
561 | + $config = $c->getConfig(); |
|
562 | + return new \OC\BackgroundJob\JobList( |
|
563 | + $c->getDatabaseConnection(), |
|
564 | + $config, |
|
565 | + new TimeFactory() |
|
566 | + ); |
|
567 | + }); |
|
568 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
569 | + |
|
570 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
571 | + $cacheFactory = $c->getMemCacheFactory(); |
|
572 | + $logger = $c->getLogger(); |
|
573 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
574 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
575 | + } else { |
|
576 | + $router = new \OC\Route\Router($logger); |
|
577 | + } |
|
578 | + return $router; |
|
579 | + }); |
|
580 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
581 | + |
|
582 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
583 | + return new Search(); |
|
584 | + }); |
|
585 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
586 | + |
|
587 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
588 | + return new \OC\Security\RateLimiting\Limiter( |
|
589 | + $this->getUserSession(), |
|
590 | + $this->getRequest(), |
|
591 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
592 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
593 | + ); |
|
594 | + }); |
|
595 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
596 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
597 | + $this->getMemCacheFactory(), |
|
598 | + new \OC\AppFramework\Utility\TimeFactory() |
|
599 | + ); |
|
600 | + }); |
|
601 | + |
|
602 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
603 | + return new SecureRandom(); |
|
604 | + }); |
|
605 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
606 | + |
|
607 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
608 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
609 | + }); |
|
610 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
611 | + |
|
612 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
613 | + return new Hasher($c->getConfig()); |
|
614 | + }); |
|
615 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
616 | + |
|
617 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
618 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
619 | + }); |
|
620 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
621 | + |
|
622 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
623 | + $systemConfig = $c->getSystemConfig(); |
|
624 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
625 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
626 | + if (!$factory->isValidType($type)) { |
|
627 | + throw new \OC\DatabaseException('Invalid database type'); |
|
628 | + } |
|
629 | + $connectionParams = $factory->createConnectionParams(); |
|
630 | + $connection = $factory->getConnection($type, $connectionParams); |
|
631 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
632 | + return $connection; |
|
633 | + }); |
|
634 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
635 | + |
|
636 | + |
|
637 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
638 | + $user = \OC_User::getUser(); |
|
639 | + $uid = $user ? $user : null; |
|
640 | + return new ClientService( |
|
641 | + $c->getConfig(), |
|
642 | + new \OC\Security\CertificateManager( |
|
643 | + $uid, |
|
644 | + new View(), |
|
645 | + $c->getConfig(), |
|
646 | + $c->getLogger(), |
|
647 | + $c->getSecureRandom() |
|
648 | + ) |
|
649 | + ); |
|
650 | + }); |
|
651 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
652 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
653 | + $eventLogger = new EventLogger(); |
|
654 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
655 | + // In debug mode, module is being activated by default |
|
656 | + $eventLogger->activate(); |
|
657 | + } |
|
658 | + return $eventLogger; |
|
659 | + }); |
|
660 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
661 | + |
|
662 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
663 | + $queryLogger = new QueryLogger(); |
|
664 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
665 | + // In debug mode, module is being activated by default |
|
666 | + $queryLogger->activate(); |
|
667 | + } |
|
668 | + return $queryLogger; |
|
669 | + }); |
|
670 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
671 | + |
|
672 | + $this->registerService(TempManager::class, function (Server $c) { |
|
673 | + return new TempManager( |
|
674 | + $c->getLogger(), |
|
675 | + $c->getConfig() |
|
676 | + ); |
|
677 | + }); |
|
678 | + $this->registerAlias('TempManager', TempManager::class); |
|
679 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
680 | + |
|
681 | + $this->registerService(AppManager::class, function (Server $c) { |
|
682 | + return new \OC\App\AppManager( |
|
683 | + $c->getUserSession(), |
|
684 | + $c->query(\OC\AppConfig::class), |
|
685 | + $c->getGroupManager(), |
|
686 | + $c->getMemCacheFactory(), |
|
687 | + $c->getEventDispatcher() |
|
688 | + ); |
|
689 | + }); |
|
690 | + $this->registerAlias('AppManager', AppManager::class); |
|
691 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
692 | + |
|
693 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
694 | + return new DateTimeZone( |
|
695 | + $c->getConfig(), |
|
696 | + $c->getSession() |
|
697 | + ); |
|
698 | + }); |
|
699 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
700 | + |
|
701 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
702 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
703 | + |
|
704 | + return new DateTimeFormatter( |
|
705 | + $c->getDateTimeZone()->getTimeZone(), |
|
706 | + $c->getL10N('lib', $language) |
|
707 | + ); |
|
708 | + }); |
|
709 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
710 | + |
|
711 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
712 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
713 | + $listener = new UserMountCacheListener($mountCache); |
|
714 | + $listener->listen($c->getUserManager()); |
|
715 | + return $mountCache; |
|
716 | + }); |
|
717 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
718 | + |
|
719 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
720 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
721 | + $mountCache = $c->query('UserMountCache'); |
|
722 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
723 | + |
|
724 | + // builtin providers |
|
725 | + |
|
726 | + $config = $c->getConfig(); |
|
727 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
728 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
729 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
730 | + |
|
731 | + return $manager; |
|
732 | + }); |
|
733 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
734 | + |
|
735 | + $this->registerService('IniWrapper', function ($c) { |
|
736 | + return new IniGetWrapper(); |
|
737 | + }); |
|
738 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
739 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
740 | + if ($busClass) { |
|
741 | + list($app, $class) = explode('::', $busClass, 2); |
|
742 | + if ($c->getAppManager()->isInstalled($app)) { |
|
743 | + \OC_App::loadApp($app); |
|
744 | + return $c->query($class); |
|
745 | + } else { |
|
746 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
747 | + } |
|
748 | + } else { |
|
749 | + $jobList = $c->getJobList(); |
|
750 | + return new CronBus($jobList); |
|
751 | + } |
|
752 | + }); |
|
753 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
754 | + return new TrustedDomainHelper($this->getConfig()); |
|
755 | + }); |
|
756 | + $this->registerService('Throttler', function (Server $c) { |
|
757 | + return new Throttler( |
|
758 | + $c->getDatabaseConnection(), |
|
759 | + new TimeFactory(), |
|
760 | + $c->getLogger(), |
|
761 | + $c->getConfig() |
|
762 | + ); |
|
763 | + }); |
|
764 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
765 | + // IConfig and IAppManager requires a working database. This code |
|
766 | + // might however be called when ownCloud is not yet setup. |
|
767 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
768 | + $config = $c->getConfig(); |
|
769 | + $appManager = $c->getAppManager(); |
|
770 | + } else { |
|
771 | + $config = null; |
|
772 | + $appManager = null; |
|
773 | + } |
|
774 | + |
|
775 | + return new Checker( |
|
776 | + new EnvironmentHelper(), |
|
777 | + new FileAccessHelper(), |
|
778 | + new AppLocator(), |
|
779 | + $config, |
|
780 | + $c->getMemCacheFactory(), |
|
781 | + $appManager, |
|
782 | + $c->getTempManager() |
|
783 | + ); |
|
784 | + }); |
|
785 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
786 | + if (isset($this['urlParams'])) { |
|
787 | + $urlParams = $this['urlParams']; |
|
788 | + } else { |
|
789 | + $urlParams = []; |
|
790 | + } |
|
791 | + |
|
792 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
793 | + && in_array('fakeinput', stream_get_wrappers()) |
|
794 | + ) { |
|
795 | + $stream = 'fakeinput://data'; |
|
796 | + } else { |
|
797 | + $stream = 'php://input'; |
|
798 | + } |
|
799 | + |
|
800 | + return new Request( |
|
801 | + [ |
|
802 | + 'get' => $_GET, |
|
803 | + 'post' => $_POST, |
|
804 | + 'files' => $_FILES, |
|
805 | + 'server' => $_SERVER, |
|
806 | + 'env' => $_ENV, |
|
807 | + 'cookies' => $_COOKIE, |
|
808 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
809 | + ? $_SERVER['REQUEST_METHOD'] |
|
810 | + : '', |
|
811 | + 'urlParams' => $urlParams, |
|
812 | + ], |
|
813 | + $this->getSecureRandom(), |
|
814 | + $this->getConfig(), |
|
815 | + $this->getCsrfTokenManager(), |
|
816 | + $stream |
|
817 | + ); |
|
818 | + }); |
|
819 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
820 | + |
|
821 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
822 | + return new Mailer( |
|
823 | + $c->getConfig(), |
|
824 | + $c->getLogger(), |
|
825 | + $c->query(Defaults::class), |
|
826 | + $c->getURLGenerator(), |
|
827 | + $c->getL10N('lib') |
|
828 | + ); |
|
829 | + }); |
|
830 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
831 | + |
|
832 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
833 | + $config = $c->getConfig(); |
|
834 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
835 | + if (is_null($factoryClass)) { |
|
836 | + throw new \Exception('ldapProviderFactory not set'); |
|
837 | + } |
|
838 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
839 | + $factory = new $factoryClass($this); |
|
840 | + return $factory->getLDAPProvider(); |
|
841 | + }); |
|
842 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
843 | + $ini = $c->getIniWrapper(); |
|
844 | + $config = $c->getConfig(); |
|
845 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
846 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
847 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
848 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
849 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
850 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
851 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
852 | + } |
|
853 | + return new DBLockingProvider( |
|
854 | + $c->getDatabaseConnection(), |
|
855 | + $c->getLogger(), |
|
856 | + new TimeFactory(), |
|
857 | + $ttl, |
|
858 | + !\OC::$CLI |
|
859 | + ); |
|
860 | + } |
|
861 | + return new NoopLockingProvider(); |
|
862 | + }); |
|
863 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
864 | + |
|
865 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
866 | + return new \OC\Files\Mount\Manager(); |
|
867 | + }); |
|
868 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
869 | + |
|
870 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
871 | + return new \OC\Files\Type\Detection( |
|
872 | + $c->getURLGenerator(), |
|
873 | + \OC::$configDir, |
|
874 | + \OC::$SERVERROOT . '/resources/config/' |
|
875 | + ); |
|
876 | + }); |
|
877 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
878 | + |
|
879 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
880 | + return new \OC\Files\Type\Loader( |
|
881 | + $c->getDatabaseConnection() |
|
882 | + ); |
|
883 | + }); |
|
884 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
885 | + $this->registerService(BundleFetcher::class, function () { |
|
886 | + return new BundleFetcher($this->getL10N('lib')); |
|
887 | + }); |
|
888 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
889 | + return new Manager( |
|
890 | + $c->query(IValidator::class) |
|
891 | + ); |
|
892 | + }); |
|
893 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
894 | + |
|
895 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
896 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
897 | + $manager->registerCapability(function () use ($c) { |
|
898 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
899 | + }); |
|
900 | + $manager->registerCapability(function () use ($c) { |
|
901 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
902 | + }); |
|
903 | + return $manager; |
|
904 | + }); |
|
905 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
906 | + |
|
907 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
908 | + $config = $c->getConfig(); |
|
909 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
910 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
911 | + $factory = new $factoryClass($this); |
|
912 | + $manager = $factory->getManager(); |
|
913 | + |
|
914 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
915 | + $manager = $c->getUserManager(); |
|
916 | + $user = $manager->get($id); |
|
917 | + if(is_null($user)) { |
|
918 | + $l = $c->getL10N('core'); |
|
919 | + $displayName = $l->t('Unknown user'); |
|
920 | + } else { |
|
921 | + $displayName = $user->getDisplayName(); |
|
922 | + } |
|
923 | + return $displayName; |
|
924 | + }); |
|
925 | + |
|
926 | + return $manager; |
|
927 | + }); |
|
928 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
929 | + |
|
930 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
931 | + /* |
|
932 | 932 | * Dark magic for autoloader. |
933 | 933 | * If we do a class_exists it will try to load the class which will |
934 | 934 | * make composer cache the result. Resulting in errors when enabling |
935 | 935 | * the theming app. |
936 | 936 | */ |
937 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
938 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
939 | - $classExists = true; |
|
940 | - } else { |
|
941 | - $classExists = false; |
|
942 | - } |
|
943 | - |
|
944 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
945 | - return new ThemingDefaults( |
|
946 | - $c->getConfig(), |
|
947 | - $c->getL10N('theming'), |
|
948 | - $c->getURLGenerator(), |
|
949 | - $c->getMemCacheFactory(), |
|
950 | - new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
951 | - new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
952 | - $c->getAppManager() |
|
953 | - ); |
|
954 | - } |
|
955 | - return new \OC_Defaults(); |
|
956 | - }); |
|
957 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
958 | - /** @var Factory $cacheFactory */ |
|
959 | - $cacheFactory = $c->query(Factory::class); |
|
960 | - return new SCSSCacher( |
|
961 | - $c->getLogger(), |
|
962 | - $c->query(\OC\Files\AppData\Factory::class), |
|
963 | - $c->getURLGenerator(), |
|
964 | - $c->getConfig(), |
|
965 | - $c->getThemingDefaults(), |
|
966 | - \OC::$SERVERROOT, |
|
967 | - $this->getMemCacheFactory(), |
|
968 | - $c->query(IconsCacher::class) |
|
969 | - ); |
|
970 | - }); |
|
971 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
972 | - /** @var Factory $cacheFactory */ |
|
973 | - $cacheFactory = $c->query(Factory::class); |
|
974 | - return new JSCombiner( |
|
975 | - $c->getAppDataDir('js'), |
|
976 | - $c->getURLGenerator(), |
|
977 | - $this->getMemCacheFactory(), |
|
978 | - $c->getSystemConfig(), |
|
979 | - $c->getLogger() |
|
980 | - ); |
|
981 | - }); |
|
982 | - $this->registerService(EventDispatcher::class, function () { |
|
983 | - return new EventDispatcher(); |
|
984 | - }); |
|
985 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
986 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
987 | - |
|
988 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
989 | - // FIXME: Instantiiated here due to cyclic dependency |
|
990 | - $request = new Request( |
|
991 | - [ |
|
992 | - 'get' => $_GET, |
|
993 | - 'post' => $_POST, |
|
994 | - 'files' => $_FILES, |
|
995 | - 'server' => $_SERVER, |
|
996 | - 'env' => $_ENV, |
|
997 | - 'cookies' => $_COOKIE, |
|
998 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
999 | - ? $_SERVER['REQUEST_METHOD'] |
|
1000 | - : null, |
|
1001 | - ], |
|
1002 | - $c->getSecureRandom(), |
|
1003 | - $c->getConfig() |
|
1004 | - ); |
|
1005 | - |
|
1006 | - return new CryptoWrapper( |
|
1007 | - $c->getConfig(), |
|
1008 | - $c->getCrypto(), |
|
1009 | - $c->getSecureRandom(), |
|
1010 | - $request |
|
1011 | - ); |
|
1012 | - }); |
|
1013 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1014 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1015 | - |
|
1016 | - return new CsrfTokenManager( |
|
1017 | - $tokenGenerator, |
|
1018 | - $c->query(SessionStorage::class) |
|
1019 | - ); |
|
1020 | - }); |
|
1021 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1022 | - return new SessionStorage($c->getSession()); |
|
1023 | - }); |
|
1024 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1025 | - return new ContentSecurityPolicyManager(); |
|
1026 | - }); |
|
1027 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1028 | - |
|
1029 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1030 | - return new ContentSecurityPolicyNonceManager( |
|
1031 | - $c->getCsrfTokenManager(), |
|
1032 | - $c->getRequest() |
|
1033 | - ); |
|
1034 | - }); |
|
1035 | - |
|
1036 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1037 | - $config = $c->getConfig(); |
|
1038 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1039 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1040 | - $factory = new $factoryClass($this); |
|
1041 | - |
|
1042 | - $manager = new \OC\Share20\Manager( |
|
1043 | - $c->getLogger(), |
|
1044 | - $c->getConfig(), |
|
1045 | - $c->getSecureRandom(), |
|
1046 | - $c->getHasher(), |
|
1047 | - $c->getMountManager(), |
|
1048 | - $c->getGroupManager(), |
|
1049 | - $c->getL10N('lib'), |
|
1050 | - $c->getL10NFactory(), |
|
1051 | - $factory, |
|
1052 | - $c->getUserManager(), |
|
1053 | - $c->getLazyRootFolder(), |
|
1054 | - $c->getEventDispatcher(), |
|
1055 | - $c->getMailer(), |
|
1056 | - $c->getURLGenerator(), |
|
1057 | - $c->getThemingDefaults() |
|
1058 | - ); |
|
1059 | - |
|
1060 | - return $manager; |
|
1061 | - }); |
|
1062 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1063 | - |
|
1064 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1065 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1066 | - |
|
1067 | - // register default plugins |
|
1068 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1069 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1070 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1071 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1072 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1073 | - |
|
1074 | - return $instance; |
|
1075 | - }); |
|
1076 | - $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1077 | - |
|
1078 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1079 | - |
|
1080 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1081 | - $manager = new \OC\Settings\Manager( |
|
1082 | - $c->getLogger(), |
|
1083 | - $c->getDatabaseConnection(), |
|
1084 | - $c->getL10N('lib'), |
|
1085 | - $c->getConfig(), |
|
1086 | - $c->getEncryptionManager(), |
|
1087 | - $c->getUserManager(), |
|
1088 | - $c->getLockingProvider(), |
|
1089 | - $c->getRequest(), |
|
1090 | - $c->getURLGenerator(), |
|
1091 | - $c->query(AccountManager::class), |
|
1092 | - $c->getGroupManager(), |
|
1093 | - $c->getL10NFactory(), |
|
1094 | - $c->getAppManager() |
|
1095 | - ); |
|
1096 | - return $manager; |
|
1097 | - }); |
|
1098 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1099 | - return new \OC\Files\AppData\Factory( |
|
1100 | - $c->getRootFolder(), |
|
1101 | - $c->getSystemConfig() |
|
1102 | - ); |
|
1103 | - }); |
|
1104 | - |
|
1105 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1106 | - return new LockdownManager(function () use ($c) { |
|
1107 | - return $c->getSession(); |
|
1108 | - }); |
|
1109 | - }); |
|
1110 | - |
|
1111 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1112 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1113 | - }); |
|
1114 | - |
|
1115 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1116 | - return new CloudIdManager(); |
|
1117 | - }); |
|
1118 | - |
|
1119 | - $this->registerService(IConfig::class, function (Server $c) { |
|
1120 | - return new GlobalScale\Config($c->getConfig()); |
|
1121 | - }); |
|
1122 | - |
|
1123 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1124 | - return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
1125 | - }); |
|
1126 | - |
|
1127 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1128 | - return new CloudFederationFactory(); |
|
1129 | - }); |
|
1130 | - |
|
1131 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1132 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1133 | - |
|
1134 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1135 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1136 | - |
|
1137 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1138 | - return new Defaults( |
|
1139 | - $c->getThemingDefaults() |
|
1140 | - ); |
|
1141 | - }); |
|
1142 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1143 | - |
|
1144 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1145 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1146 | - }); |
|
1147 | - |
|
1148 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1149 | - return new ShareHelper( |
|
1150 | - $c->query(\OCP\Share\IManager::class) |
|
1151 | - ); |
|
1152 | - }); |
|
1153 | - |
|
1154 | - $this->registerService(Installer::class, function(Server $c) { |
|
1155 | - return new Installer( |
|
1156 | - $c->getAppFetcher(), |
|
1157 | - $c->getHTTPClientService(), |
|
1158 | - $c->getTempManager(), |
|
1159 | - $c->getLogger(), |
|
1160 | - $c->getConfig() |
|
1161 | - ); |
|
1162 | - }); |
|
1163 | - |
|
1164 | - $this->registerService(IApiFactory::class, function(Server $c) { |
|
1165 | - return new ApiFactory($c->getHTTPClientService()); |
|
1166 | - }); |
|
1167 | - |
|
1168 | - $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1169 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
1170 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1171 | - }); |
|
1172 | - |
|
1173 | - $this->registerService(IContactsStore::class, function(Server $c) { |
|
1174 | - return new ContactsStore( |
|
1175 | - $c->getContactsManager(), |
|
1176 | - $c->getConfig(), |
|
1177 | - $c->getUserManager(), |
|
1178 | - $c->getGroupManager() |
|
1179 | - ); |
|
1180 | - }); |
|
1181 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1182 | - |
|
1183 | - $this->connectDispatcher(); |
|
1184 | - } |
|
1185 | - |
|
1186 | - /** |
|
1187 | - * @return \OCP\Calendar\IManager |
|
1188 | - */ |
|
1189 | - public function getCalendarManager() { |
|
1190 | - return $this->query('CalendarManager'); |
|
1191 | - } |
|
1192 | - |
|
1193 | - /** |
|
1194 | - * @return \OCP\Calendar\Resource\IManager |
|
1195 | - */ |
|
1196 | - public function getCalendarResourceBackendManager() { |
|
1197 | - return $this->query('CalendarResourceBackendManager'); |
|
1198 | - } |
|
1199 | - |
|
1200 | - /** |
|
1201 | - * @return \OCP\Calendar\Room\IManager |
|
1202 | - */ |
|
1203 | - public function getCalendarRoomBackendManager() { |
|
1204 | - return $this->query('CalendarRoomBackendManager'); |
|
1205 | - } |
|
1206 | - |
|
1207 | - private function connectDispatcher() { |
|
1208 | - $dispatcher = $this->getEventDispatcher(); |
|
1209 | - |
|
1210 | - // Delete avatar on user deletion |
|
1211 | - $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1212 | - $logger = $this->getLogger(); |
|
1213 | - $manager = $this->getAvatarManager(); |
|
1214 | - /** @var IUser $user */ |
|
1215 | - $user = $e->getSubject(); |
|
1216 | - |
|
1217 | - try { |
|
1218 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1219 | - $avatar->remove(); |
|
1220 | - } catch (NotFoundException $e) { |
|
1221 | - // no avatar to remove |
|
1222 | - } catch (\Exception $e) { |
|
1223 | - // Ignore exceptions |
|
1224 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1225 | - } |
|
1226 | - }); |
|
1227 | - |
|
1228 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1229 | - $manager = $this->getAvatarManager(); |
|
1230 | - /** @var IUser $user */ |
|
1231 | - $user = $e->getSubject(); |
|
1232 | - $feature = $e->getArgument('feature'); |
|
1233 | - $oldValue = $e->getArgument('oldValue'); |
|
1234 | - $value = $e->getArgument('value'); |
|
1235 | - |
|
1236 | - try { |
|
1237 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1238 | - $avatar->userChanged($feature, $oldValue, $value); |
|
1239 | - } catch (NotFoundException $e) { |
|
1240 | - // no avatar to remove |
|
1241 | - } |
|
1242 | - }); |
|
1243 | - } |
|
1244 | - |
|
1245 | - /** |
|
1246 | - * @return \OCP\Contacts\IManager |
|
1247 | - */ |
|
1248 | - public function getContactsManager() { |
|
1249 | - return $this->query('ContactsManager'); |
|
1250 | - } |
|
1251 | - |
|
1252 | - /** |
|
1253 | - * @return \OC\Encryption\Manager |
|
1254 | - */ |
|
1255 | - public function getEncryptionManager() { |
|
1256 | - return $this->query('EncryptionManager'); |
|
1257 | - } |
|
1258 | - |
|
1259 | - /** |
|
1260 | - * @return \OC\Encryption\File |
|
1261 | - */ |
|
1262 | - public function getEncryptionFilesHelper() { |
|
1263 | - return $this->query('EncryptionFileHelper'); |
|
1264 | - } |
|
1265 | - |
|
1266 | - /** |
|
1267 | - * @return \OCP\Encryption\Keys\IStorage |
|
1268 | - */ |
|
1269 | - public function getEncryptionKeyStorage() { |
|
1270 | - return $this->query('EncryptionKeyStorage'); |
|
1271 | - } |
|
1272 | - |
|
1273 | - /** |
|
1274 | - * The current request object holding all information about the request |
|
1275 | - * currently being processed is returned from this method. |
|
1276 | - * In case the current execution was not initiated by a web request null is returned |
|
1277 | - * |
|
1278 | - * @return \OCP\IRequest |
|
1279 | - */ |
|
1280 | - public function getRequest() { |
|
1281 | - return $this->query('Request'); |
|
1282 | - } |
|
1283 | - |
|
1284 | - /** |
|
1285 | - * Returns the preview manager which can create preview images for a given file |
|
1286 | - * |
|
1287 | - * @return \OCP\IPreview |
|
1288 | - */ |
|
1289 | - public function getPreviewManager() { |
|
1290 | - return $this->query('PreviewManager'); |
|
1291 | - } |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * Returns the tag manager which can get and set tags for different object types |
|
1295 | - * |
|
1296 | - * @see \OCP\ITagManager::load() |
|
1297 | - * @return \OCP\ITagManager |
|
1298 | - */ |
|
1299 | - public function getTagManager() { |
|
1300 | - return $this->query('TagManager'); |
|
1301 | - } |
|
1302 | - |
|
1303 | - /** |
|
1304 | - * Returns the system-tag manager |
|
1305 | - * |
|
1306 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1307 | - * |
|
1308 | - * @since 9.0.0 |
|
1309 | - */ |
|
1310 | - public function getSystemTagManager() { |
|
1311 | - return $this->query('SystemTagManager'); |
|
1312 | - } |
|
1313 | - |
|
1314 | - /** |
|
1315 | - * Returns the system-tag object mapper |
|
1316 | - * |
|
1317 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1318 | - * |
|
1319 | - * @since 9.0.0 |
|
1320 | - */ |
|
1321 | - public function getSystemTagObjectMapper() { |
|
1322 | - return $this->query('SystemTagObjectMapper'); |
|
1323 | - } |
|
1324 | - |
|
1325 | - /** |
|
1326 | - * Returns the avatar manager, used for avatar functionality |
|
1327 | - * |
|
1328 | - * @return \OCP\IAvatarManager |
|
1329 | - */ |
|
1330 | - public function getAvatarManager() { |
|
1331 | - return $this->query('AvatarManager'); |
|
1332 | - } |
|
1333 | - |
|
1334 | - /** |
|
1335 | - * Returns the root folder of ownCloud's data directory |
|
1336 | - * |
|
1337 | - * @return \OCP\Files\IRootFolder |
|
1338 | - */ |
|
1339 | - public function getRootFolder() { |
|
1340 | - return $this->query('LazyRootFolder'); |
|
1341 | - } |
|
1342 | - |
|
1343 | - /** |
|
1344 | - * Returns the root folder of ownCloud's data directory |
|
1345 | - * This is the lazy variant so this gets only initialized once it |
|
1346 | - * is actually used. |
|
1347 | - * |
|
1348 | - * @return \OCP\Files\IRootFolder |
|
1349 | - */ |
|
1350 | - public function getLazyRootFolder() { |
|
1351 | - return $this->query('LazyRootFolder'); |
|
1352 | - } |
|
1353 | - |
|
1354 | - /** |
|
1355 | - * Returns a view to ownCloud's files folder |
|
1356 | - * |
|
1357 | - * @param string $userId user ID |
|
1358 | - * @return \OCP\Files\Folder|null |
|
1359 | - */ |
|
1360 | - public function getUserFolder($userId = null) { |
|
1361 | - if ($userId === null) { |
|
1362 | - $user = $this->getUserSession()->getUser(); |
|
1363 | - if (!$user) { |
|
1364 | - return null; |
|
1365 | - } |
|
1366 | - $userId = $user->getUID(); |
|
1367 | - } |
|
1368 | - $root = $this->getRootFolder(); |
|
1369 | - return $root->getUserFolder($userId); |
|
1370 | - } |
|
1371 | - |
|
1372 | - /** |
|
1373 | - * Returns an app-specific view in ownClouds data directory |
|
1374 | - * |
|
1375 | - * @return \OCP\Files\Folder |
|
1376 | - * @deprecated since 9.2.0 use IAppData |
|
1377 | - */ |
|
1378 | - public function getAppFolder() { |
|
1379 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1380 | - $root = $this->getRootFolder(); |
|
1381 | - if (!$root->nodeExists($dir)) { |
|
1382 | - $folder = $root->newFolder($dir); |
|
1383 | - } else { |
|
1384 | - $folder = $root->get($dir); |
|
1385 | - } |
|
1386 | - return $folder; |
|
1387 | - } |
|
1388 | - |
|
1389 | - /** |
|
1390 | - * @return \OC\User\Manager |
|
1391 | - */ |
|
1392 | - public function getUserManager() { |
|
1393 | - return $this->query('UserManager'); |
|
1394 | - } |
|
1395 | - |
|
1396 | - /** |
|
1397 | - * @return \OC\Group\Manager |
|
1398 | - */ |
|
1399 | - public function getGroupManager() { |
|
1400 | - return $this->query('GroupManager'); |
|
1401 | - } |
|
1402 | - |
|
1403 | - /** |
|
1404 | - * @return \OC\User\Session |
|
1405 | - */ |
|
1406 | - public function getUserSession() { |
|
1407 | - return $this->query('UserSession'); |
|
1408 | - } |
|
1409 | - |
|
1410 | - /** |
|
1411 | - * @return \OCP\ISession |
|
1412 | - */ |
|
1413 | - public function getSession() { |
|
1414 | - return $this->query('UserSession')->getSession(); |
|
1415 | - } |
|
1416 | - |
|
1417 | - /** |
|
1418 | - * @param \OCP\ISession $session |
|
1419 | - */ |
|
1420 | - public function setSession(\OCP\ISession $session) { |
|
1421 | - $this->query(SessionStorage::class)->setSession($session); |
|
1422 | - $this->query('UserSession')->setSession($session); |
|
1423 | - $this->query(Store::class)->setSession($session); |
|
1424 | - } |
|
1425 | - |
|
1426 | - /** |
|
1427 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1428 | - */ |
|
1429 | - public function getTwoFactorAuthManager() { |
|
1430 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1431 | - } |
|
1432 | - |
|
1433 | - /** |
|
1434 | - * @return \OC\NavigationManager |
|
1435 | - */ |
|
1436 | - public function getNavigationManager() { |
|
1437 | - return $this->query('NavigationManager'); |
|
1438 | - } |
|
1439 | - |
|
1440 | - /** |
|
1441 | - * @return \OCP\IConfig |
|
1442 | - */ |
|
1443 | - public function getConfig() { |
|
1444 | - return $this->query('AllConfig'); |
|
1445 | - } |
|
1446 | - |
|
1447 | - /** |
|
1448 | - * @return \OC\SystemConfig |
|
1449 | - */ |
|
1450 | - public function getSystemConfig() { |
|
1451 | - return $this->query('SystemConfig'); |
|
1452 | - } |
|
1453 | - |
|
1454 | - /** |
|
1455 | - * Returns the app config manager |
|
1456 | - * |
|
1457 | - * @return \OCP\IAppConfig |
|
1458 | - */ |
|
1459 | - public function getAppConfig() { |
|
1460 | - return $this->query('AppConfig'); |
|
1461 | - } |
|
1462 | - |
|
1463 | - /** |
|
1464 | - * @return \OCP\L10N\IFactory |
|
1465 | - */ |
|
1466 | - public function getL10NFactory() { |
|
1467 | - return $this->query('L10NFactory'); |
|
1468 | - } |
|
1469 | - |
|
1470 | - /** |
|
1471 | - * get an L10N instance |
|
1472 | - * |
|
1473 | - * @param string $app appid |
|
1474 | - * @param string $lang |
|
1475 | - * @return IL10N |
|
1476 | - */ |
|
1477 | - public function getL10N($app, $lang = null) { |
|
1478 | - return $this->getL10NFactory()->get($app, $lang); |
|
1479 | - } |
|
1480 | - |
|
1481 | - /** |
|
1482 | - * @return \OCP\IURLGenerator |
|
1483 | - */ |
|
1484 | - public function getURLGenerator() { |
|
1485 | - return $this->query('URLGenerator'); |
|
1486 | - } |
|
1487 | - |
|
1488 | - /** |
|
1489 | - * @return AppFetcher |
|
1490 | - */ |
|
1491 | - public function getAppFetcher() { |
|
1492 | - return $this->query(AppFetcher::class); |
|
1493 | - } |
|
1494 | - |
|
1495 | - /** |
|
1496 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1497 | - * getMemCacheFactory() instead. |
|
1498 | - * |
|
1499 | - * @return \OCP\ICache |
|
1500 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1501 | - */ |
|
1502 | - public function getCache() { |
|
1503 | - return $this->query('UserCache'); |
|
1504 | - } |
|
1505 | - |
|
1506 | - /** |
|
1507 | - * Returns an \OCP\CacheFactory instance |
|
1508 | - * |
|
1509 | - * @return \OCP\ICacheFactory |
|
1510 | - */ |
|
1511 | - public function getMemCacheFactory() { |
|
1512 | - return $this->query('MemCacheFactory'); |
|
1513 | - } |
|
1514 | - |
|
1515 | - /** |
|
1516 | - * Returns an \OC\RedisFactory instance |
|
1517 | - * |
|
1518 | - * @return \OC\RedisFactory |
|
1519 | - */ |
|
1520 | - public function getGetRedisFactory() { |
|
1521 | - return $this->query('RedisFactory'); |
|
1522 | - } |
|
1523 | - |
|
1524 | - |
|
1525 | - /** |
|
1526 | - * Returns the current session |
|
1527 | - * |
|
1528 | - * @return \OCP\IDBConnection |
|
1529 | - */ |
|
1530 | - public function getDatabaseConnection() { |
|
1531 | - return $this->query('DatabaseConnection'); |
|
1532 | - } |
|
1533 | - |
|
1534 | - /** |
|
1535 | - * Returns the activity manager |
|
1536 | - * |
|
1537 | - * @return \OCP\Activity\IManager |
|
1538 | - */ |
|
1539 | - public function getActivityManager() { |
|
1540 | - return $this->query('ActivityManager'); |
|
1541 | - } |
|
1542 | - |
|
1543 | - /** |
|
1544 | - * Returns an job list for controlling background jobs |
|
1545 | - * |
|
1546 | - * @return \OCP\BackgroundJob\IJobList |
|
1547 | - */ |
|
1548 | - public function getJobList() { |
|
1549 | - return $this->query('JobList'); |
|
1550 | - } |
|
1551 | - |
|
1552 | - /** |
|
1553 | - * Returns a logger instance |
|
1554 | - * |
|
1555 | - * @return \OCP\ILogger |
|
1556 | - */ |
|
1557 | - public function getLogger() { |
|
1558 | - return $this->query('Logger'); |
|
1559 | - } |
|
1560 | - |
|
1561 | - /** |
|
1562 | - * @return ILogFactory |
|
1563 | - * @throws \OCP\AppFramework\QueryException |
|
1564 | - */ |
|
1565 | - public function getLogFactory() { |
|
1566 | - return $this->query(ILogFactory::class); |
|
1567 | - } |
|
1568 | - |
|
1569 | - /** |
|
1570 | - * Returns a router for generating and matching urls |
|
1571 | - * |
|
1572 | - * @return \OCP\Route\IRouter |
|
1573 | - */ |
|
1574 | - public function getRouter() { |
|
1575 | - return $this->query('Router'); |
|
1576 | - } |
|
1577 | - |
|
1578 | - /** |
|
1579 | - * Returns a search instance |
|
1580 | - * |
|
1581 | - * @return \OCP\ISearch |
|
1582 | - */ |
|
1583 | - public function getSearch() { |
|
1584 | - return $this->query('Search'); |
|
1585 | - } |
|
1586 | - |
|
1587 | - /** |
|
1588 | - * Returns a SecureRandom instance |
|
1589 | - * |
|
1590 | - * @return \OCP\Security\ISecureRandom |
|
1591 | - */ |
|
1592 | - public function getSecureRandom() { |
|
1593 | - return $this->query('SecureRandom'); |
|
1594 | - } |
|
1595 | - |
|
1596 | - /** |
|
1597 | - * Returns a Crypto instance |
|
1598 | - * |
|
1599 | - * @return \OCP\Security\ICrypto |
|
1600 | - */ |
|
1601 | - public function getCrypto() { |
|
1602 | - return $this->query('Crypto'); |
|
1603 | - } |
|
1604 | - |
|
1605 | - /** |
|
1606 | - * Returns a Hasher instance |
|
1607 | - * |
|
1608 | - * @return \OCP\Security\IHasher |
|
1609 | - */ |
|
1610 | - public function getHasher() { |
|
1611 | - return $this->query('Hasher'); |
|
1612 | - } |
|
1613 | - |
|
1614 | - /** |
|
1615 | - * Returns a CredentialsManager instance |
|
1616 | - * |
|
1617 | - * @return \OCP\Security\ICredentialsManager |
|
1618 | - */ |
|
1619 | - public function getCredentialsManager() { |
|
1620 | - return $this->query('CredentialsManager'); |
|
1621 | - } |
|
1622 | - |
|
1623 | - /** |
|
1624 | - * Get the certificate manager for the user |
|
1625 | - * |
|
1626 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1627 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1628 | - */ |
|
1629 | - public function getCertificateManager($userId = '') { |
|
1630 | - if ($userId === '') { |
|
1631 | - $userSession = $this->getUserSession(); |
|
1632 | - $user = $userSession->getUser(); |
|
1633 | - if (is_null($user)) { |
|
1634 | - return null; |
|
1635 | - } |
|
1636 | - $userId = $user->getUID(); |
|
1637 | - } |
|
1638 | - return new CertificateManager( |
|
1639 | - $userId, |
|
1640 | - new View(), |
|
1641 | - $this->getConfig(), |
|
1642 | - $this->getLogger(), |
|
1643 | - $this->getSecureRandom() |
|
1644 | - ); |
|
1645 | - } |
|
1646 | - |
|
1647 | - /** |
|
1648 | - * Returns an instance of the HTTP client service |
|
1649 | - * |
|
1650 | - * @return \OCP\Http\Client\IClientService |
|
1651 | - */ |
|
1652 | - public function getHTTPClientService() { |
|
1653 | - return $this->query('HttpClientService'); |
|
1654 | - } |
|
1655 | - |
|
1656 | - /** |
|
1657 | - * Create a new event source |
|
1658 | - * |
|
1659 | - * @return \OCP\IEventSource |
|
1660 | - */ |
|
1661 | - public function createEventSource() { |
|
1662 | - return new \OC_EventSource(); |
|
1663 | - } |
|
1664 | - |
|
1665 | - /** |
|
1666 | - * Get the active event logger |
|
1667 | - * |
|
1668 | - * The returned logger only logs data when debug mode is enabled |
|
1669 | - * |
|
1670 | - * @return \OCP\Diagnostics\IEventLogger |
|
1671 | - */ |
|
1672 | - public function getEventLogger() { |
|
1673 | - return $this->query('EventLogger'); |
|
1674 | - } |
|
1675 | - |
|
1676 | - /** |
|
1677 | - * Get the active query logger |
|
1678 | - * |
|
1679 | - * The returned logger only logs data when debug mode is enabled |
|
1680 | - * |
|
1681 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1682 | - */ |
|
1683 | - public function getQueryLogger() { |
|
1684 | - return $this->query('QueryLogger'); |
|
1685 | - } |
|
1686 | - |
|
1687 | - /** |
|
1688 | - * Get the manager for temporary files and folders |
|
1689 | - * |
|
1690 | - * @return \OCP\ITempManager |
|
1691 | - */ |
|
1692 | - public function getTempManager() { |
|
1693 | - return $this->query('TempManager'); |
|
1694 | - } |
|
1695 | - |
|
1696 | - /** |
|
1697 | - * Get the app manager |
|
1698 | - * |
|
1699 | - * @return \OCP\App\IAppManager |
|
1700 | - */ |
|
1701 | - public function getAppManager() { |
|
1702 | - return $this->query('AppManager'); |
|
1703 | - } |
|
1704 | - |
|
1705 | - /** |
|
1706 | - * Creates a new mailer |
|
1707 | - * |
|
1708 | - * @return \OCP\Mail\IMailer |
|
1709 | - */ |
|
1710 | - public function getMailer() { |
|
1711 | - return $this->query('Mailer'); |
|
1712 | - } |
|
1713 | - |
|
1714 | - /** |
|
1715 | - * Get the webroot |
|
1716 | - * |
|
1717 | - * @return string |
|
1718 | - */ |
|
1719 | - public function getWebRoot() { |
|
1720 | - return $this->webRoot; |
|
1721 | - } |
|
1722 | - |
|
1723 | - /** |
|
1724 | - * @return \OC\OCSClient |
|
1725 | - */ |
|
1726 | - public function getOcsClient() { |
|
1727 | - return $this->query('OcsClient'); |
|
1728 | - } |
|
1729 | - |
|
1730 | - /** |
|
1731 | - * @return \OCP\IDateTimeZone |
|
1732 | - */ |
|
1733 | - public function getDateTimeZone() { |
|
1734 | - return $this->query('DateTimeZone'); |
|
1735 | - } |
|
1736 | - |
|
1737 | - /** |
|
1738 | - * @return \OCP\IDateTimeFormatter |
|
1739 | - */ |
|
1740 | - public function getDateTimeFormatter() { |
|
1741 | - return $this->query('DateTimeFormatter'); |
|
1742 | - } |
|
1743 | - |
|
1744 | - /** |
|
1745 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1746 | - */ |
|
1747 | - public function getMountProviderCollection() { |
|
1748 | - return $this->query('MountConfigManager'); |
|
1749 | - } |
|
1750 | - |
|
1751 | - /** |
|
1752 | - * Get the IniWrapper |
|
1753 | - * |
|
1754 | - * @return IniGetWrapper |
|
1755 | - */ |
|
1756 | - public function getIniWrapper() { |
|
1757 | - return $this->query('IniWrapper'); |
|
1758 | - } |
|
1759 | - |
|
1760 | - /** |
|
1761 | - * @return \OCP\Command\IBus |
|
1762 | - */ |
|
1763 | - public function getCommandBus() { |
|
1764 | - return $this->query('AsyncCommandBus'); |
|
1765 | - } |
|
1766 | - |
|
1767 | - /** |
|
1768 | - * Get the trusted domain helper |
|
1769 | - * |
|
1770 | - * @return TrustedDomainHelper |
|
1771 | - */ |
|
1772 | - public function getTrustedDomainHelper() { |
|
1773 | - return $this->query('TrustedDomainHelper'); |
|
1774 | - } |
|
1775 | - |
|
1776 | - /** |
|
1777 | - * Get the locking provider |
|
1778 | - * |
|
1779 | - * @return \OCP\Lock\ILockingProvider |
|
1780 | - * @since 8.1.0 |
|
1781 | - */ |
|
1782 | - public function getLockingProvider() { |
|
1783 | - return $this->query('LockingProvider'); |
|
1784 | - } |
|
1785 | - |
|
1786 | - /** |
|
1787 | - * @return \OCP\Files\Mount\IMountManager |
|
1788 | - **/ |
|
1789 | - function getMountManager() { |
|
1790 | - return $this->query('MountManager'); |
|
1791 | - } |
|
1792 | - |
|
1793 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1794 | - function getUserMountCache() { |
|
1795 | - return $this->query('UserMountCache'); |
|
1796 | - } |
|
1797 | - |
|
1798 | - /** |
|
1799 | - * Get the MimeTypeDetector |
|
1800 | - * |
|
1801 | - * @return \OCP\Files\IMimeTypeDetector |
|
1802 | - */ |
|
1803 | - public function getMimeTypeDetector() { |
|
1804 | - return $this->query('MimeTypeDetector'); |
|
1805 | - } |
|
1806 | - |
|
1807 | - /** |
|
1808 | - * Get the MimeTypeLoader |
|
1809 | - * |
|
1810 | - * @return \OCP\Files\IMimeTypeLoader |
|
1811 | - */ |
|
1812 | - public function getMimeTypeLoader() { |
|
1813 | - return $this->query('MimeTypeLoader'); |
|
1814 | - } |
|
1815 | - |
|
1816 | - /** |
|
1817 | - * Get the manager of all the capabilities |
|
1818 | - * |
|
1819 | - * @return \OC\CapabilitiesManager |
|
1820 | - */ |
|
1821 | - public function getCapabilitiesManager() { |
|
1822 | - return $this->query('CapabilitiesManager'); |
|
1823 | - } |
|
1824 | - |
|
1825 | - /** |
|
1826 | - * Get the EventDispatcher |
|
1827 | - * |
|
1828 | - * @return EventDispatcherInterface |
|
1829 | - * @since 8.2.0 |
|
1830 | - */ |
|
1831 | - public function getEventDispatcher() { |
|
1832 | - return $this->query('EventDispatcher'); |
|
1833 | - } |
|
1834 | - |
|
1835 | - /** |
|
1836 | - * Get the Notification Manager |
|
1837 | - * |
|
1838 | - * @return \OCP\Notification\IManager |
|
1839 | - * @since 8.2.0 |
|
1840 | - */ |
|
1841 | - public function getNotificationManager() { |
|
1842 | - return $this->query('NotificationManager'); |
|
1843 | - } |
|
1844 | - |
|
1845 | - /** |
|
1846 | - * @return \OCP\Comments\ICommentsManager |
|
1847 | - */ |
|
1848 | - public function getCommentsManager() { |
|
1849 | - return $this->query('CommentsManager'); |
|
1850 | - } |
|
1851 | - |
|
1852 | - /** |
|
1853 | - * @return \OCA\Theming\ThemingDefaults |
|
1854 | - */ |
|
1855 | - public function getThemingDefaults() { |
|
1856 | - return $this->query('ThemingDefaults'); |
|
1857 | - } |
|
1858 | - |
|
1859 | - /** |
|
1860 | - * @return \OC\IntegrityCheck\Checker |
|
1861 | - */ |
|
1862 | - public function getIntegrityCodeChecker() { |
|
1863 | - return $this->query('IntegrityCodeChecker'); |
|
1864 | - } |
|
1865 | - |
|
1866 | - /** |
|
1867 | - * @return \OC\Session\CryptoWrapper |
|
1868 | - */ |
|
1869 | - public function getSessionCryptoWrapper() { |
|
1870 | - return $this->query('CryptoWrapper'); |
|
1871 | - } |
|
1872 | - |
|
1873 | - /** |
|
1874 | - * @return CsrfTokenManager |
|
1875 | - */ |
|
1876 | - public function getCsrfTokenManager() { |
|
1877 | - return $this->query('CsrfTokenManager'); |
|
1878 | - } |
|
1879 | - |
|
1880 | - /** |
|
1881 | - * @return Throttler |
|
1882 | - */ |
|
1883 | - public function getBruteForceThrottler() { |
|
1884 | - return $this->query('Throttler'); |
|
1885 | - } |
|
1886 | - |
|
1887 | - /** |
|
1888 | - * @return IContentSecurityPolicyManager |
|
1889 | - */ |
|
1890 | - public function getContentSecurityPolicyManager() { |
|
1891 | - return $this->query('ContentSecurityPolicyManager'); |
|
1892 | - } |
|
1893 | - |
|
1894 | - /** |
|
1895 | - * @return ContentSecurityPolicyNonceManager |
|
1896 | - */ |
|
1897 | - public function getContentSecurityPolicyNonceManager() { |
|
1898 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1899 | - } |
|
1900 | - |
|
1901 | - /** |
|
1902 | - * Not a public API as of 8.2, wait for 9.0 |
|
1903 | - * |
|
1904 | - * @return \OCA\Files_External\Service\BackendService |
|
1905 | - */ |
|
1906 | - public function getStoragesBackendService() { |
|
1907 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1908 | - } |
|
1909 | - |
|
1910 | - /** |
|
1911 | - * Not a public API as of 8.2, wait for 9.0 |
|
1912 | - * |
|
1913 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1914 | - */ |
|
1915 | - public function getGlobalStoragesService() { |
|
1916 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1917 | - } |
|
1918 | - |
|
1919 | - /** |
|
1920 | - * Not a public API as of 8.2, wait for 9.0 |
|
1921 | - * |
|
1922 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1923 | - */ |
|
1924 | - public function getUserGlobalStoragesService() { |
|
1925 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1926 | - } |
|
1927 | - |
|
1928 | - /** |
|
1929 | - * Not a public API as of 8.2, wait for 9.0 |
|
1930 | - * |
|
1931 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1932 | - */ |
|
1933 | - public function getUserStoragesService() { |
|
1934 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1935 | - } |
|
1936 | - |
|
1937 | - /** |
|
1938 | - * @return \OCP\Share\IManager |
|
1939 | - */ |
|
1940 | - public function getShareManager() { |
|
1941 | - return $this->query('ShareManager'); |
|
1942 | - } |
|
1943 | - |
|
1944 | - /** |
|
1945 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
1946 | - */ |
|
1947 | - public function getCollaboratorSearch() { |
|
1948 | - return $this->query('CollaboratorSearch'); |
|
1949 | - } |
|
1950 | - |
|
1951 | - /** |
|
1952 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
1953 | - */ |
|
1954 | - public function getAutoCompleteManager(){ |
|
1955 | - return $this->query(IManager::class); |
|
1956 | - } |
|
1957 | - |
|
1958 | - /** |
|
1959 | - * Returns the LDAP Provider |
|
1960 | - * |
|
1961 | - * @return \OCP\LDAP\ILDAPProvider |
|
1962 | - */ |
|
1963 | - public function getLDAPProvider() { |
|
1964 | - return $this->query('LDAPProvider'); |
|
1965 | - } |
|
1966 | - |
|
1967 | - /** |
|
1968 | - * @return \OCP\Settings\IManager |
|
1969 | - */ |
|
1970 | - public function getSettingsManager() { |
|
1971 | - return $this->query('SettingsManager'); |
|
1972 | - } |
|
1973 | - |
|
1974 | - /** |
|
1975 | - * @return \OCP\Files\IAppData |
|
1976 | - */ |
|
1977 | - public function getAppDataDir($app) { |
|
1978 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1979 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1980 | - return $factory->get($app); |
|
1981 | - } |
|
1982 | - |
|
1983 | - /** |
|
1984 | - * @return \OCP\Lockdown\ILockdownManager |
|
1985 | - */ |
|
1986 | - public function getLockdownManager() { |
|
1987 | - return $this->query('LockdownManager'); |
|
1988 | - } |
|
1989 | - |
|
1990 | - /** |
|
1991 | - * @return \OCP\Federation\ICloudIdManager |
|
1992 | - */ |
|
1993 | - public function getCloudIdManager() { |
|
1994 | - return $this->query(ICloudIdManager::class); |
|
1995 | - } |
|
1996 | - |
|
1997 | - /** |
|
1998 | - * @return \OCP\GlobalScale\IConfig |
|
1999 | - */ |
|
2000 | - public function getGlobalScaleConfig() { |
|
2001 | - return $this->query(IConfig::class); |
|
2002 | - } |
|
2003 | - |
|
2004 | - /** |
|
2005 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
2006 | - */ |
|
2007 | - public function getCloudFederationProviderManager() { |
|
2008 | - return $this->query(ICloudFederationProviderManager::class); |
|
2009 | - } |
|
2010 | - |
|
2011 | - /** |
|
2012 | - * @return \OCP\Remote\Api\IApiFactory |
|
2013 | - */ |
|
2014 | - public function getRemoteApiFactory() { |
|
2015 | - return $this->query(IApiFactory::class); |
|
2016 | - } |
|
2017 | - |
|
2018 | - /** |
|
2019 | - * @return \OCP\Federation\ICloudFederationFactory |
|
2020 | - */ |
|
2021 | - public function getCloudFederationFactory() { |
|
2022 | - return $this->query(ICloudFederationFactory::class); |
|
2023 | - } |
|
2024 | - |
|
2025 | - /** |
|
2026 | - * @return \OCP\Remote\IInstanceFactory |
|
2027 | - */ |
|
2028 | - public function getRemoteInstanceFactory() { |
|
2029 | - return $this->query(IInstanceFactory::class); |
|
2030 | - } |
|
937 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
938 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
939 | + $classExists = true; |
|
940 | + } else { |
|
941 | + $classExists = false; |
|
942 | + } |
|
943 | + |
|
944 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
945 | + return new ThemingDefaults( |
|
946 | + $c->getConfig(), |
|
947 | + $c->getL10N('theming'), |
|
948 | + $c->getURLGenerator(), |
|
949 | + $c->getMemCacheFactory(), |
|
950 | + new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
951 | + new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
952 | + $c->getAppManager() |
|
953 | + ); |
|
954 | + } |
|
955 | + return new \OC_Defaults(); |
|
956 | + }); |
|
957 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
958 | + /** @var Factory $cacheFactory */ |
|
959 | + $cacheFactory = $c->query(Factory::class); |
|
960 | + return new SCSSCacher( |
|
961 | + $c->getLogger(), |
|
962 | + $c->query(\OC\Files\AppData\Factory::class), |
|
963 | + $c->getURLGenerator(), |
|
964 | + $c->getConfig(), |
|
965 | + $c->getThemingDefaults(), |
|
966 | + \OC::$SERVERROOT, |
|
967 | + $this->getMemCacheFactory(), |
|
968 | + $c->query(IconsCacher::class) |
|
969 | + ); |
|
970 | + }); |
|
971 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
972 | + /** @var Factory $cacheFactory */ |
|
973 | + $cacheFactory = $c->query(Factory::class); |
|
974 | + return new JSCombiner( |
|
975 | + $c->getAppDataDir('js'), |
|
976 | + $c->getURLGenerator(), |
|
977 | + $this->getMemCacheFactory(), |
|
978 | + $c->getSystemConfig(), |
|
979 | + $c->getLogger() |
|
980 | + ); |
|
981 | + }); |
|
982 | + $this->registerService(EventDispatcher::class, function () { |
|
983 | + return new EventDispatcher(); |
|
984 | + }); |
|
985 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
986 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
987 | + |
|
988 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
989 | + // FIXME: Instantiiated here due to cyclic dependency |
|
990 | + $request = new Request( |
|
991 | + [ |
|
992 | + 'get' => $_GET, |
|
993 | + 'post' => $_POST, |
|
994 | + 'files' => $_FILES, |
|
995 | + 'server' => $_SERVER, |
|
996 | + 'env' => $_ENV, |
|
997 | + 'cookies' => $_COOKIE, |
|
998 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
999 | + ? $_SERVER['REQUEST_METHOD'] |
|
1000 | + : null, |
|
1001 | + ], |
|
1002 | + $c->getSecureRandom(), |
|
1003 | + $c->getConfig() |
|
1004 | + ); |
|
1005 | + |
|
1006 | + return new CryptoWrapper( |
|
1007 | + $c->getConfig(), |
|
1008 | + $c->getCrypto(), |
|
1009 | + $c->getSecureRandom(), |
|
1010 | + $request |
|
1011 | + ); |
|
1012 | + }); |
|
1013 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1014 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1015 | + |
|
1016 | + return new CsrfTokenManager( |
|
1017 | + $tokenGenerator, |
|
1018 | + $c->query(SessionStorage::class) |
|
1019 | + ); |
|
1020 | + }); |
|
1021 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
1022 | + return new SessionStorage($c->getSession()); |
|
1023 | + }); |
|
1024 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1025 | + return new ContentSecurityPolicyManager(); |
|
1026 | + }); |
|
1027 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1028 | + |
|
1029 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1030 | + return new ContentSecurityPolicyNonceManager( |
|
1031 | + $c->getCsrfTokenManager(), |
|
1032 | + $c->getRequest() |
|
1033 | + ); |
|
1034 | + }); |
|
1035 | + |
|
1036 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1037 | + $config = $c->getConfig(); |
|
1038 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1039 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1040 | + $factory = new $factoryClass($this); |
|
1041 | + |
|
1042 | + $manager = new \OC\Share20\Manager( |
|
1043 | + $c->getLogger(), |
|
1044 | + $c->getConfig(), |
|
1045 | + $c->getSecureRandom(), |
|
1046 | + $c->getHasher(), |
|
1047 | + $c->getMountManager(), |
|
1048 | + $c->getGroupManager(), |
|
1049 | + $c->getL10N('lib'), |
|
1050 | + $c->getL10NFactory(), |
|
1051 | + $factory, |
|
1052 | + $c->getUserManager(), |
|
1053 | + $c->getLazyRootFolder(), |
|
1054 | + $c->getEventDispatcher(), |
|
1055 | + $c->getMailer(), |
|
1056 | + $c->getURLGenerator(), |
|
1057 | + $c->getThemingDefaults() |
|
1058 | + ); |
|
1059 | + |
|
1060 | + return $manager; |
|
1061 | + }); |
|
1062 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1063 | + |
|
1064 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1065 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1066 | + |
|
1067 | + // register default plugins |
|
1068 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1069 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1070 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1071 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1072 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1073 | + |
|
1074 | + return $instance; |
|
1075 | + }); |
|
1076 | + $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1077 | + |
|
1078 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1079 | + |
|
1080 | + $this->registerService('SettingsManager', function (Server $c) { |
|
1081 | + $manager = new \OC\Settings\Manager( |
|
1082 | + $c->getLogger(), |
|
1083 | + $c->getDatabaseConnection(), |
|
1084 | + $c->getL10N('lib'), |
|
1085 | + $c->getConfig(), |
|
1086 | + $c->getEncryptionManager(), |
|
1087 | + $c->getUserManager(), |
|
1088 | + $c->getLockingProvider(), |
|
1089 | + $c->getRequest(), |
|
1090 | + $c->getURLGenerator(), |
|
1091 | + $c->query(AccountManager::class), |
|
1092 | + $c->getGroupManager(), |
|
1093 | + $c->getL10NFactory(), |
|
1094 | + $c->getAppManager() |
|
1095 | + ); |
|
1096 | + return $manager; |
|
1097 | + }); |
|
1098 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1099 | + return new \OC\Files\AppData\Factory( |
|
1100 | + $c->getRootFolder(), |
|
1101 | + $c->getSystemConfig() |
|
1102 | + ); |
|
1103 | + }); |
|
1104 | + |
|
1105 | + $this->registerService('LockdownManager', function (Server $c) { |
|
1106 | + return new LockdownManager(function () use ($c) { |
|
1107 | + return $c->getSession(); |
|
1108 | + }); |
|
1109 | + }); |
|
1110 | + |
|
1111 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1112 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1113 | + }); |
|
1114 | + |
|
1115 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1116 | + return new CloudIdManager(); |
|
1117 | + }); |
|
1118 | + |
|
1119 | + $this->registerService(IConfig::class, function (Server $c) { |
|
1120 | + return new GlobalScale\Config($c->getConfig()); |
|
1121 | + }); |
|
1122 | + |
|
1123 | + $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1124 | + return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
1125 | + }); |
|
1126 | + |
|
1127 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1128 | + return new CloudFederationFactory(); |
|
1129 | + }); |
|
1130 | + |
|
1131 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1132 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1133 | + |
|
1134 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1135 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1136 | + |
|
1137 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1138 | + return new Defaults( |
|
1139 | + $c->getThemingDefaults() |
|
1140 | + ); |
|
1141 | + }); |
|
1142 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1143 | + |
|
1144 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1145 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1146 | + }); |
|
1147 | + |
|
1148 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
1149 | + return new ShareHelper( |
|
1150 | + $c->query(\OCP\Share\IManager::class) |
|
1151 | + ); |
|
1152 | + }); |
|
1153 | + |
|
1154 | + $this->registerService(Installer::class, function(Server $c) { |
|
1155 | + return new Installer( |
|
1156 | + $c->getAppFetcher(), |
|
1157 | + $c->getHTTPClientService(), |
|
1158 | + $c->getTempManager(), |
|
1159 | + $c->getLogger(), |
|
1160 | + $c->getConfig() |
|
1161 | + ); |
|
1162 | + }); |
|
1163 | + |
|
1164 | + $this->registerService(IApiFactory::class, function(Server $c) { |
|
1165 | + return new ApiFactory($c->getHTTPClientService()); |
|
1166 | + }); |
|
1167 | + |
|
1168 | + $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1169 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
1170 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1171 | + }); |
|
1172 | + |
|
1173 | + $this->registerService(IContactsStore::class, function(Server $c) { |
|
1174 | + return new ContactsStore( |
|
1175 | + $c->getContactsManager(), |
|
1176 | + $c->getConfig(), |
|
1177 | + $c->getUserManager(), |
|
1178 | + $c->getGroupManager() |
|
1179 | + ); |
|
1180 | + }); |
|
1181 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1182 | + |
|
1183 | + $this->connectDispatcher(); |
|
1184 | + } |
|
1185 | + |
|
1186 | + /** |
|
1187 | + * @return \OCP\Calendar\IManager |
|
1188 | + */ |
|
1189 | + public function getCalendarManager() { |
|
1190 | + return $this->query('CalendarManager'); |
|
1191 | + } |
|
1192 | + |
|
1193 | + /** |
|
1194 | + * @return \OCP\Calendar\Resource\IManager |
|
1195 | + */ |
|
1196 | + public function getCalendarResourceBackendManager() { |
|
1197 | + return $this->query('CalendarResourceBackendManager'); |
|
1198 | + } |
|
1199 | + |
|
1200 | + /** |
|
1201 | + * @return \OCP\Calendar\Room\IManager |
|
1202 | + */ |
|
1203 | + public function getCalendarRoomBackendManager() { |
|
1204 | + return $this->query('CalendarRoomBackendManager'); |
|
1205 | + } |
|
1206 | + |
|
1207 | + private function connectDispatcher() { |
|
1208 | + $dispatcher = $this->getEventDispatcher(); |
|
1209 | + |
|
1210 | + // Delete avatar on user deletion |
|
1211 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1212 | + $logger = $this->getLogger(); |
|
1213 | + $manager = $this->getAvatarManager(); |
|
1214 | + /** @var IUser $user */ |
|
1215 | + $user = $e->getSubject(); |
|
1216 | + |
|
1217 | + try { |
|
1218 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1219 | + $avatar->remove(); |
|
1220 | + } catch (NotFoundException $e) { |
|
1221 | + // no avatar to remove |
|
1222 | + } catch (\Exception $e) { |
|
1223 | + // Ignore exceptions |
|
1224 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1225 | + } |
|
1226 | + }); |
|
1227 | + |
|
1228 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1229 | + $manager = $this->getAvatarManager(); |
|
1230 | + /** @var IUser $user */ |
|
1231 | + $user = $e->getSubject(); |
|
1232 | + $feature = $e->getArgument('feature'); |
|
1233 | + $oldValue = $e->getArgument('oldValue'); |
|
1234 | + $value = $e->getArgument('value'); |
|
1235 | + |
|
1236 | + try { |
|
1237 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1238 | + $avatar->userChanged($feature, $oldValue, $value); |
|
1239 | + } catch (NotFoundException $e) { |
|
1240 | + // no avatar to remove |
|
1241 | + } |
|
1242 | + }); |
|
1243 | + } |
|
1244 | + |
|
1245 | + /** |
|
1246 | + * @return \OCP\Contacts\IManager |
|
1247 | + */ |
|
1248 | + public function getContactsManager() { |
|
1249 | + return $this->query('ContactsManager'); |
|
1250 | + } |
|
1251 | + |
|
1252 | + /** |
|
1253 | + * @return \OC\Encryption\Manager |
|
1254 | + */ |
|
1255 | + public function getEncryptionManager() { |
|
1256 | + return $this->query('EncryptionManager'); |
|
1257 | + } |
|
1258 | + |
|
1259 | + /** |
|
1260 | + * @return \OC\Encryption\File |
|
1261 | + */ |
|
1262 | + public function getEncryptionFilesHelper() { |
|
1263 | + return $this->query('EncryptionFileHelper'); |
|
1264 | + } |
|
1265 | + |
|
1266 | + /** |
|
1267 | + * @return \OCP\Encryption\Keys\IStorage |
|
1268 | + */ |
|
1269 | + public function getEncryptionKeyStorage() { |
|
1270 | + return $this->query('EncryptionKeyStorage'); |
|
1271 | + } |
|
1272 | + |
|
1273 | + /** |
|
1274 | + * The current request object holding all information about the request |
|
1275 | + * currently being processed is returned from this method. |
|
1276 | + * In case the current execution was not initiated by a web request null is returned |
|
1277 | + * |
|
1278 | + * @return \OCP\IRequest |
|
1279 | + */ |
|
1280 | + public function getRequest() { |
|
1281 | + return $this->query('Request'); |
|
1282 | + } |
|
1283 | + |
|
1284 | + /** |
|
1285 | + * Returns the preview manager which can create preview images for a given file |
|
1286 | + * |
|
1287 | + * @return \OCP\IPreview |
|
1288 | + */ |
|
1289 | + public function getPreviewManager() { |
|
1290 | + return $this->query('PreviewManager'); |
|
1291 | + } |
|
1292 | + |
|
1293 | + /** |
|
1294 | + * Returns the tag manager which can get and set tags for different object types |
|
1295 | + * |
|
1296 | + * @see \OCP\ITagManager::load() |
|
1297 | + * @return \OCP\ITagManager |
|
1298 | + */ |
|
1299 | + public function getTagManager() { |
|
1300 | + return $this->query('TagManager'); |
|
1301 | + } |
|
1302 | + |
|
1303 | + /** |
|
1304 | + * Returns the system-tag manager |
|
1305 | + * |
|
1306 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1307 | + * |
|
1308 | + * @since 9.0.0 |
|
1309 | + */ |
|
1310 | + public function getSystemTagManager() { |
|
1311 | + return $this->query('SystemTagManager'); |
|
1312 | + } |
|
1313 | + |
|
1314 | + /** |
|
1315 | + * Returns the system-tag object mapper |
|
1316 | + * |
|
1317 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1318 | + * |
|
1319 | + * @since 9.0.0 |
|
1320 | + */ |
|
1321 | + public function getSystemTagObjectMapper() { |
|
1322 | + return $this->query('SystemTagObjectMapper'); |
|
1323 | + } |
|
1324 | + |
|
1325 | + /** |
|
1326 | + * Returns the avatar manager, used for avatar functionality |
|
1327 | + * |
|
1328 | + * @return \OCP\IAvatarManager |
|
1329 | + */ |
|
1330 | + public function getAvatarManager() { |
|
1331 | + return $this->query('AvatarManager'); |
|
1332 | + } |
|
1333 | + |
|
1334 | + /** |
|
1335 | + * Returns the root folder of ownCloud's data directory |
|
1336 | + * |
|
1337 | + * @return \OCP\Files\IRootFolder |
|
1338 | + */ |
|
1339 | + public function getRootFolder() { |
|
1340 | + return $this->query('LazyRootFolder'); |
|
1341 | + } |
|
1342 | + |
|
1343 | + /** |
|
1344 | + * Returns the root folder of ownCloud's data directory |
|
1345 | + * This is the lazy variant so this gets only initialized once it |
|
1346 | + * is actually used. |
|
1347 | + * |
|
1348 | + * @return \OCP\Files\IRootFolder |
|
1349 | + */ |
|
1350 | + public function getLazyRootFolder() { |
|
1351 | + return $this->query('LazyRootFolder'); |
|
1352 | + } |
|
1353 | + |
|
1354 | + /** |
|
1355 | + * Returns a view to ownCloud's files folder |
|
1356 | + * |
|
1357 | + * @param string $userId user ID |
|
1358 | + * @return \OCP\Files\Folder|null |
|
1359 | + */ |
|
1360 | + public function getUserFolder($userId = null) { |
|
1361 | + if ($userId === null) { |
|
1362 | + $user = $this->getUserSession()->getUser(); |
|
1363 | + if (!$user) { |
|
1364 | + return null; |
|
1365 | + } |
|
1366 | + $userId = $user->getUID(); |
|
1367 | + } |
|
1368 | + $root = $this->getRootFolder(); |
|
1369 | + return $root->getUserFolder($userId); |
|
1370 | + } |
|
1371 | + |
|
1372 | + /** |
|
1373 | + * Returns an app-specific view in ownClouds data directory |
|
1374 | + * |
|
1375 | + * @return \OCP\Files\Folder |
|
1376 | + * @deprecated since 9.2.0 use IAppData |
|
1377 | + */ |
|
1378 | + public function getAppFolder() { |
|
1379 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1380 | + $root = $this->getRootFolder(); |
|
1381 | + if (!$root->nodeExists($dir)) { |
|
1382 | + $folder = $root->newFolder($dir); |
|
1383 | + } else { |
|
1384 | + $folder = $root->get($dir); |
|
1385 | + } |
|
1386 | + return $folder; |
|
1387 | + } |
|
1388 | + |
|
1389 | + /** |
|
1390 | + * @return \OC\User\Manager |
|
1391 | + */ |
|
1392 | + public function getUserManager() { |
|
1393 | + return $this->query('UserManager'); |
|
1394 | + } |
|
1395 | + |
|
1396 | + /** |
|
1397 | + * @return \OC\Group\Manager |
|
1398 | + */ |
|
1399 | + public function getGroupManager() { |
|
1400 | + return $this->query('GroupManager'); |
|
1401 | + } |
|
1402 | + |
|
1403 | + /** |
|
1404 | + * @return \OC\User\Session |
|
1405 | + */ |
|
1406 | + public function getUserSession() { |
|
1407 | + return $this->query('UserSession'); |
|
1408 | + } |
|
1409 | + |
|
1410 | + /** |
|
1411 | + * @return \OCP\ISession |
|
1412 | + */ |
|
1413 | + public function getSession() { |
|
1414 | + return $this->query('UserSession')->getSession(); |
|
1415 | + } |
|
1416 | + |
|
1417 | + /** |
|
1418 | + * @param \OCP\ISession $session |
|
1419 | + */ |
|
1420 | + public function setSession(\OCP\ISession $session) { |
|
1421 | + $this->query(SessionStorage::class)->setSession($session); |
|
1422 | + $this->query('UserSession')->setSession($session); |
|
1423 | + $this->query(Store::class)->setSession($session); |
|
1424 | + } |
|
1425 | + |
|
1426 | + /** |
|
1427 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1428 | + */ |
|
1429 | + public function getTwoFactorAuthManager() { |
|
1430 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1431 | + } |
|
1432 | + |
|
1433 | + /** |
|
1434 | + * @return \OC\NavigationManager |
|
1435 | + */ |
|
1436 | + public function getNavigationManager() { |
|
1437 | + return $this->query('NavigationManager'); |
|
1438 | + } |
|
1439 | + |
|
1440 | + /** |
|
1441 | + * @return \OCP\IConfig |
|
1442 | + */ |
|
1443 | + public function getConfig() { |
|
1444 | + return $this->query('AllConfig'); |
|
1445 | + } |
|
1446 | + |
|
1447 | + /** |
|
1448 | + * @return \OC\SystemConfig |
|
1449 | + */ |
|
1450 | + public function getSystemConfig() { |
|
1451 | + return $this->query('SystemConfig'); |
|
1452 | + } |
|
1453 | + |
|
1454 | + /** |
|
1455 | + * Returns the app config manager |
|
1456 | + * |
|
1457 | + * @return \OCP\IAppConfig |
|
1458 | + */ |
|
1459 | + public function getAppConfig() { |
|
1460 | + return $this->query('AppConfig'); |
|
1461 | + } |
|
1462 | + |
|
1463 | + /** |
|
1464 | + * @return \OCP\L10N\IFactory |
|
1465 | + */ |
|
1466 | + public function getL10NFactory() { |
|
1467 | + return $this->query('L10NFactory'); |
|
1468 | + } |
|
1469 | + |
|
1470 | + /** |
|
1471 | + * get an L10N instance |
|
1472 | + * |
|
1473 | + * @param string $app appid |
|
1474 | + * @param string $lang |
|
1475 | + * @return IL10N |
|
1476 | + */ |
|
1477 | + public function getL10N($app, $lang = null) { |
|
1478 | + return $this->getL10NFactory()->get($app, $lang); |
|
1479 | + } |
|
1480 | + |
|
1481 | + /** |
|
1482 | + * @return \OCP\IURLGenerator |
|
1483 | + */ |
|
1484 | + public function getURLGenerator() { |
|
1485 | + return $this->query('URLGenerator'); |
|
1486 | + } |
|
1487 | + |
|
1488 | + /** |
|
1489 | + * @return AppFetcher |
|
1490 | + */ |
|
1491 | + public function getAppFetcher() { |
|
1492 | + return $this->query(AppFetcher::class); |
|
1493 | + } |
|
1494 | + |
|
1495 | + /** |
|
1496 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1497 | + * getMemCacheFactory() instead. |
|
1498 | + * |
|
1499 | + * @return \OCP\ICache |
|
1500 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1501 | + */ |
|
1502 | + public function getCache() { |
|
1503 | + return $this->query('UserCache'); |
|
1504 | + } |
|
1505 | + |
|
1506 | + /** |
|
1507 | + * Returns an \OCP\CacheFactory instance |
|
1508 | + * |
|
1509 | + * @return \OCP\ICacheFactory |
|
1510 | + */ |
|
1511 | + public function getMemCacheFactory() { |
|
1512 | + return $this->query('MemCacheFactory'); |
|
1513 | + } |
|
1514 | + |
|
1515 | + /** |
|
1516 | + * Returns an \OC\RedisFactory instance |
|
1517 | + * |
|
1518 | + * @return \OC\RedisFactory |
|
1519 | + */ |
|
1520 | + public function getGetRedisFactory() { |
|
1521 | + return $this->query('RedisFactory'); |
|
1522 | + } |
|
1523 | + |
|
1524 | + |
|
1525 | + /** |
|
1526 | + * Returns the current session |
|
1527 | + * |
|
1528 | + * @return \OCP\IDBConnection |
|
1529 | + */ |
|
1530 | + public function getDatabaseConnection() { |
|
1531 | + return $this->query('DatabaseConnection'); |
|
1532 | + } |
|
1533 | + |
|
1534 | + /** |
|
1535 | + * Returns the activity manager |
|
1536 | + * |
|
1537 | + * @return \OCP\Activity\IManager |
|
1538 | + */ |
|
1539 | + public function getActivityManager() { |
|
1540 | + return $this->query('ActivityManager'); |
|
1541 | + } |
|
1542 | + |
|
1543 | + /** |
|
1544 | + * Returns an job list for controlling background jobs |
|
1545 | + * |
|
1546 | + * @return \OCP\BackgroundJob\IJobList |
|
1547 | + */ |
|
1548 | + public function getJobList() { |
|
1549 | + return $this->query('JobList'); |
|
1550 | + } |
|
1551 | + |
|
1552 | + /** |
|
1553 | + * Returns a logger instance |
|
1554 | + * |
|
1555 | + * @return \OCP\ILogger |
|
1556 | + */ |
|
1557 | + public function getLogger() { |
|
1558 | + return $this->query('Logger'); |
|
1559 | + } |
|
1560 | + |
|
1561 | + /** |
|
1562 | + * @return ILogFactory |
|
1563 | + * @throws \OCP\AppFramework\QueryException |
|
1564 | + */ |
|
1565 | + public function getLogFactory() { |
|
1566 | + return $this->query(ILogFactory::class); |
|
1567 | + } |
|
1568 | + |
|
1569 | + /** |
|
1570 | + * Returns a router for generating and matching urls |
|
1571 | + * |
|
1572 | + * @return \OCP\Route\IRouter |
|
1573 | + */ |
|
1574 | + public function getRouter() { |
|
1575 | + return $this->query('Router'); |
|
1576 | + } |
|
1577 | + |
|
1578 | + /** |
|
1579 | + * Returns a search instance |
|
1580 | + * |
|
1581 | + * @return \OCP\ISearch |
|
1582 | + */ |
|
1583 | + public function getSearch() { |
|
1584 | + return $this->query('Search'); |
|
1585 | + } |
|
1586 | + |
|
1587 | + /** |
|
1588 | + * Returns a SecureRandom instance |
|
1589 | + * |
|
1590 | + * @return \OCP\Security\ISecureRandom |
|
1591 | + */ |
|
1592 | + public function getSecureRandom() { |
|
1593 | + return $this->query('SecureRandom'); |
|
1594 | + } |
|
1595 | + |
|
1596 | + /** |
|
1597 | + * Returns a Crypto instance |
|
1598 | + * |
|
1599 | + * @return \OCP\Security\ICrypto |
|
1600 | + */ |
|
1601 | + public function getCrypto() { |
|
1602 | + return $this->query('Crypto'); |
|
1603 | + } |
|
1604 | + |
|
1605 | + /** |
|
1606 | + * Returns a Hasher instance |
|
1607 | + * |
|
1608 | + * @return \OCP\Security\IHasher |
|
1609 | + */ |
|
1610 | + public function getHasher() { |
|
1611 | + return $this->query('Hasher'); |
|
1612 | + } |
|
1613 | + |
|
1614 | + /** |
|
1615 | + * Returns a CredentialsManager instance |
|
1616 | + * |
|
1617 | + * @return \OCP\Security\ICredentialsManager |
|
1618 | + */ |
|
1619 | + public function getCredentialsManager() { |
|
1620 | + return $this->query('CredentialsManager'); |
|
1621 | + } |
|
1622 | + |
|
1623 | + /** |
|
1624 | + * Get the certificate manager for the user |
|
1625 | + * |
|
1626 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1627 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1628 | + */ |
|
1629 | + public function getCertificateManager($userId = '') { |
|
1630 | + if ($userId === '') { |
|
1631 | + $userSession = $this->getUserSession(); |
|
1632 | + $user = $userSession->getUser(); |
|
1633 | + if (is_null($user)) { |
|
1634 | + return null; |
|
1635 | + } |
|
1636 | + $userId = $user->getUID(); |
|
1637 | + } |
|
1638 | + return new CertificateManager( |
|
1639 | + $userId, |
|
1640 | + new View(), |
|
1641 | + $this->getConfig(), |
|
1642 | + $this->getLogger(), |
|
1643 | + $this->getSecureRandom() |
|
1644 | + ); |
|
1645 | + } |
|
1646 | + |
|
1647 | + /** |
|
1648 | + * Returns an instance of the HTTP client service |
|
1649 | + * |
|
1650 | + * @return \OCP\Http\Client\IClientService |
|
1651 | + */ |
|
1652 | + public function getHTTPClientService() { |
|
1653 | + return $this->query('HttpClientService'); |
|
1654 | + } |
|
1655 | + |
|
1656 | + /** |
|
1657 | + * Create a new event source |
|
1658 | + * |
|
1659 | + * @return \OCP\IEventSource |
|
1660 | + */ |
|
1661 | + public function createEventSource() { |
|
1662 | + return new \OC_EventSource(); |
|
1663 | + } |
|
1664 | + |
|
1665 | + /** |
|
1666 | + * Get the active event logger |
|
1667 | + * |
|
1668 | + * The returned logger only logs data when debug mode is enabled |
|
1669 | + * |
|
1670 | + * @return \OCP\Diagnostics\IEventLogger |
|
1671 | + */ |
|
1672 | + public function getEventLogger() { |
|
1673 | + return $this->query('EventLogger'); |
|
1674 | + } |
|
1675 | + |
|
1676 | + /** |
|
1677 | + * Get the active query logger |
|
1678 | + * |
|
1679 | + * The returned logger only logs data when debug mode is enabled |
|
1680 | + * |
|
1681 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1682 | + */ |
|
1683 | + public function getQueryLogger() { |
|
1684 | + return $this->query('QueryLogger'); |
|
1685 | + } |
|
1686 | + |
|
1687 | + /** |
|
1688 | + * Get the manager for temporary files and folders |
|
1689 | + * |
|
1690 | + * @return \OCP\ITempManager |
|
1691 | + */ |
|
1692 | + public function getTempManager() { |
|
1693 | + return $this->query('TempManager'); |
|
1694 | + } |
|
1695 | + |
|
1696 | + /** |
|
1697 | + * Get the app manager |
|
1698 | + * |
|
1699 | + * @return \OCP\App\IAppManager |
|
1700 | + */ |
|
1701 | + public function getAppManager() { |
|
1702 | + return $this->query('AppManager'); |
|
1703 | + } |
|
1704 | + |
|
1705 | + /** |
|
1706 | + * Creates a new mailer |
|
1707 | + * |
|
1708 | + * @return \OCP\Mail\IMailer |
|
1709 | + */ |
|
1710 | + public function getMailer() { |
|
1711 | + return $this->query('Mailer'); |
|
1712 | + } |
|
1713 | + |
|
1714 | + /** |
|
1715 | + * Get the webroot |
|
1716 | + * |
|
1717 | + * @return string |
|
1718 | + */ |
|
1719 | + public function getWebRoot() { |
|
1720 | + return $this->webRoot; |
|
1721 | + } |
|
1722 | + |
|
1723 | + /** |
|
1724 | + * @return \OC\OCSClient |
|
1725 | + */ |
|
1726 | + public function getOcsClient() { |
|
1727 | + return $this->query('OcsClient'); |
|
1728 | + } |
|
1729 | + |
|
1730 | + /** |
|
1731 | + * @return \OCP\IDateTimeZone |
|
1732 | + */ |
|
1733 | + public function getDateTimeZone() { |
|
1734 | + return $this->query('DateTimeZone'); |
|
1735 | + } |
|
1736 | + |
|
1737 | + /** |
|
1738 | + * @return \OCP\IDateTimeFormatter |
|
1739 | + */ |
|
1740 | + public function getDateTimeFormatter() { |
|
1741 | + return $this->query('DateTimeFormatter'); |
|
1742 | + } |
|
1743 | + |
|
1744 | + /** |
|
1745 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1746 | + */ |
|
1747 | + public function getMountProviderCollection() { |
|
1748 | + return $this->query('MountConfigManager'); |
|
1749 | + } |
|
1750 | + |
|
1751 | + /** |
|
1752 | + * Get the IniWrapper |
|
1753 | + * |
|
1754 | + * @return IniGetWrapper |
|
1755 | + */ |
|
1756 | + public function getIniWrapper() { |
|
1757 | + return $this->query('IniWrapper'); |
|
1758 | + } |
|
1759 | + |
|
1760 | + /** |
|
1761 | + * @return \OCP\Command\IBus |
|
1762 | + */ |
|
1763 | + public function getCommandBus() { |
|
1764 | + return $this->query('AsyncCommandBus'); |
|
1765 | + } |
|
1766 | + |
|
1767 | + /** |
|
1768 | + * Get the trusted domain helper |
|
1769 | + * |
|
1770 | + * @return TrustedDomainHelper |
|
1771 | + */ |
|
1772 | + public function getTrustedDomainHelper() { |
|
1773 | + return $this->query('TrustedDomainHelper'); |
|
1774 | + } |
|
1775 | + |
|
1776 | + /** |
|
1777 | + * Get the locking provider |
|
1778 | + * |
|
1779 | + * @return \OCP\Lock\ILockingProvider |
|
1780 | + * @since 8.1.0 |
|
1781 | + */ |
|
1782 | + public function getLockingProvider() { |
|
1783 | + return $this->query('LockingProvider'); |
|
1784 | + } |
|
1785 | + |
|
1786 | + /** |
|
1787 | + * @return \OCP\Files\Mount\IMountManager |
|
1788 | + **/ |
|
1789 | + function getMountManager() { |
|
1790 | + return $this->query('MountManager'); |
|
1791 | + } |
|
1792 | + |
|
1793 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1794 | + function getUserMountCache() { |
|
1795 | + return $this->query('UserMountCache'); |
|
1796 | + } |
|
1797 | + |
|
1798 | + /** |
|
1799 | + * Get the MimeTypeDetector |
|
1800 | + * |
|
1801 | + * @return \OCP\Files\IMimeTypeDetector |
|
1802 | + */ |
|
1803 | + public function getMimeTypeDetector() { |
|
1804 | + return $this->query('MimeTypeDetector'); |
|
1805 | + } |
|
1806 | + |
|
1807 | + /** |
|
1808 | + * Get the MimeTypeLoader |
|
1809 | + * |
|
1810 | + * @return \OCP\Files\IMimeTypeLoader |
|
1811 | + */ |
|
1812 | + public function getMimeTypeLoader() { |
|
1813 | + return $this->query('MimeTypeLoader'); |
|
1814 | + } |
|
1815 | + |
|
1816 | + /** |
|
1817 | + * Get the manager of all the capabilities |
|
1818 | + * |
|
1819 | + * @return \OC\CapabilitiesManager |
|
1820 | + */ |
|
1821 | + public function getCapabilitiesManager() { |
|
1822 | + return $this->query('CapabilitiesManager'); |
|
1823 | + } |
|
1824 | + |
|
1825 | + /** |
|
1826 | + * Get the EventDispatcher |
|
1827 | + * |
|
1828 | + * @return EventDispatcherInterface |
|
1829 | + * @since 8.2.0 |
|
1830 | + */ |
|
1831 | + public function getEventDispatcher() { |
|
1832 | + return $this->query('EventDispatcher'); |
|
1833 | + } |
|
1834 | + |
|
1835 | + /** |
|
1836 | + * Get the Notification Manager |
|
1837 | + * |
|
1838 | + * @return \OCP\Notification\IManager |
|
1839 | + * @since 8.2.0 |
|
1840 | + */ |
|
1841 | + public function getNotificationManager() { |
|
1842 | + return $this->query('NotificationManager'); |
|
1843 | + } |
|
1844 | + |
|
1845 | + /** |
|
1846 | + * @return \OCP\Comments\ICommentsManager |
|
1847 | + */ |
|
1848 | + public function getCommentsManager() { |
|
1849 | + return $this->query('CommentsManager'); |
|
1850 | + } |
|
1851 | + |
|
1852 | + /** |
|
1853 | + * @return \OCA\Theming\ThemingDefaults |
|
1854 | + */ |
|
1855 | + public function getThemingDefaults() { |
|
1856 | + return $this->query('ThemingDefaults'); |
|
1857 | + } |
|
1858 | + |
|
1859 | + /** |
|
1860 | + * @return \OC\IntegrityCheck\Checker |
|
1861 | + */ |
|
1862 | + public function getIntegrityCodeChecker() { |
|
1863 | + return $this->query('IntegrityCodeChecker'); |
|
1864 | + } |
|
1865 | + |
|
1866 | + /** |
|
1867 | + * @return \OC\Session\CryptoWrapper |
|
1868 | + */ |
|
1869 | + public function getSessionCryptoWrapper() { |
|
1870 | + return $this->query('CryptoWrapper'); |
|
1871 | + } |
|
1872 | + |
|
1873 | + /** |
|
1874 | + * @return CsrfTokenManager |
|
1875 | + */ |
|
1876 | + public function getCsrfTokenManager() { |
|
1877 | + return $this->query('CsrfTokenManager'); |
|
1878 | + } |
|
1879 | + |
|
1880 | + /** |
|
1881 | + * @return Throttler |
|
1882 | + */ |
|
1883 | + public function getBruteForceThrottler() { |
|
1884 | + return $this->query('Throttler'); |
|
1885 | + } |
|
1886 | + |
|
1887 | + /** |
|
1888 | + * @return IContentSecurityPolicyManager |
|
1889 | + */ |
|
1890 | + public function getContentSecurityPolicyManager() { |
|
1891 | + return $this->query('ContentSecurityPolicyManager'); |
|
1892 | + } |
|
1893 | + |
|
1894 | + /** |
|
1895 | + * @return ContentSecurityPolicyNonceManager |
|
1896 | + */ |
|
1897 | + public function getContentSecurityPolicyNonceManager() { |
|
1898 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1899 | + } |
|
1900 | + |
|
1901 | + /** |
|
1902 | + * Not a public API as of 8.2, wait for 9.0 |
|
1903 | + * |
|
1904 | + * @return \OCA\Files_External\Service\BackendService |
|
1905 | + */ |
|
1906 | + public function getStoragesBackendService() { |
|
1907 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1908 | + } |
|
1909 | + |
|
1910 | + /** |
|
1911 | + * Not a public API as of 8.2, wait for 9.0 |
|
1912 | + * |
|
1913 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1914 | + */ |
|
1915 | + public function getGlobalStoragesService() { |
|
1916 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1917 | + } |
|
1918 | + |
|
1919 | + /** |
|
1920 | + * Not a public API as of 8.2, wait for 9.0 |
|
1921 | + * |
|
1922 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1923 | + */ |
|
1924 | + public function getUserGlobalStoragesService() { |
|
1925 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1926 | + } |
|
1927 | + |
|
1928 | + /** |
|
1929 | + * Not a public API as of 8.2, wait for 9.0 |
|
1930 | + * |
|
1931 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1932 | + */ |
|
1933 | + public function getUserStoragesService() { |
|
1934 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1935 | + } |
|
1936 | + |
|
1937 | + /** |
|
1938 | + * @return \OCP\Share\IManager |
|
1939 | + */ |
|
1940 | + public function getShareManager() { |
|
1941 | + return $this->query('ShareManager'); |
|
1942 | + } |
|
1943 | + |
|
1944 | + /** |
|
1945 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
1946 | + */ |
|
1947 | + public function getCollaboratorSearch() { |
|
1948 | + return $this->query('CollaboratorSearch'); |
|
1949 | + } |
|
1950 | + |
|
1951 | + /** |
|
1952 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
1953 | + */ |
|
1954 | + public function getAutoCompleteManager(){ |
|
1955 | + return $this->query(IManager::class); |
|
1956 | + } |
|
1957 | + |
|
1958 | + /** |
|
1959 | + * Returns the LDAP Provider |
|
1960 | + * |
|
1961 | + * @return \OCP\LDAP\ILDAPProvider |
|
1962 | + */ |
|
1963 | + public function getLDAPProvider() { |
|
1964 | + return $this->query('LDAPProvider'); |
|
1965 | + } |
|
1966 | + |
|
1967 | + /** |
|
1968 | + * @return \OCP\Settings\IManager |
|
1969 | + */ |
|
1970 | + public function getSettingsManager() { |
|
1971 | + return $this->query('SettingsManager'); |
|
1972 | + } |
|
1973 | + |
|
1974 | + /** |
|
1975 | + * @return \OCP\Files\IAppData |
|
1976 | + */ |
|
1977 | + public function getAppDataDir($app) { |
|
1978 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1979 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1980 | + return $factory->get($app); |
|
1981 | + } |
|
1982 | + |
|
1983 | + /** |
|
1984 | + * @return \OCP\Lockdown\ILockdownManager |
|
1985 | + */ |
|
1986 | + public function getLockdownManager() { |
|
1987 | + return $this->query('LockdownManager'); |
|
1988 | + } |
|
1989 | + |
|
1990 | + /** |
|
1991 | + * @return \OCP\Federation\ICloudIdManager |
|
1992 | + */ |
|
1993 | + public function getCloudIdManager() { |
|
1994 | + return $this->query(ICloudIdManager::class); |
|
1995 | + } |
|
1996 | + |
|
1997 | + /** |
|
1998 | + * @return \OCP\GlobalScale\IConfig |
|
1999 | + */ |
|
2000 | + public function getGlobalScaleConfig() { |
|
2001 | + return $this->query(IConfig::class); |
|
2002 | + } |
|
2003 | + |
|
2004 | + /** |
|
2005 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
2006 | + */ |
|
2007 | + public function getCloudFederationProviderManager() { |
|
2008 | + return $this->query(ICloudFederationProviderManager::class); |
|
2009 | + } |
|
2010 | + |
|
2011 | + /** |
|
2012 | + * @return \OCP\Remote\Api\IApiFactory |
|
2013 | + */ |
|
2014 | + public function getRemoteApiFactory() { |
|
2015 | + return $this->query(IApiFactory::class); |
|
2016 | + } |
|
2017 | + |
|
2018 | + /** |
|
2019 | + * @return \OCP\Federation\ICloudFederationFactory |
|
2020 | + */ |
|
2021 | + public function getCloudFederationFactory() { |
|
2022 | + return $this->query(ICloudFederationFactory::class); |
|
2023 | + } |
|
2024 | + |
|
2025 | + /** |
|
2026 | + * @return \OCP\Remote\IInstanceFactory |
|
2027 | + */ |
|
2028 | + public function getRemoteInstanceFactory() { |
|
2029 | + return $this->query(IInstanceFactory::class); |
|
2030 | + } |
|
2031 | 2031 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | // To find out if we are running from CLI or not |
175 | 175 | $this->registerParameter('isCLI', \OC::$CLI); |
176 | 176 | |
177 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
177 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
178 | 178 | return $c; |
179 | 179 | }); |
180 | 180 | |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
194 | 194 | |
195 | 195 | |
196 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
196 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
197 | 197 | return new PreviewManager( |
198 | 198 | $c->getConfig(), |
199 | 199 | $c->getRootFolder(), |
@@ -204,13 +204,13 @@ discard block |
||
204 | 204 | }); |
205 | 205 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
206 | 206 | |
207 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
207 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
208 | 208 | return new \OC\Preview\Watcher( |
209 | 209 | $c->getAppDataDir('preview') |
210 | 210 | ); |
211 | 211 | }); |
212 | 212 | |
213 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
213 | + $this->registerService('EncryptionManager', function(Server $c) { |
|
214 | 214 | $view = new View(); |
215 | 215 | $util = new Encryption\Util( |
216 | 216 | $view, |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | ); |
229 | 229 | }); |
230 | 230 | |
231 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
231 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
232 | 232 | $util = new Encryption\Util( |
233 | 233 | new View(), |
234 | 234 | $c->getUserManager(), |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | ); |
243 | 243 | }); |
244 | 244 | |
245 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
245 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
246 | 246 | $view = new View(); |
247 | 247 | $util = new Encryption\Util( |
248 | 248 | $view, |
@@ -253,30 +253,30 @@ discard block |
||
253 | 253 | |
254 | 254 | return new Encryption\Keys\Storage($view, $util); |
255 | 255 | }); |
256 | - $this->registerService('TagMapper', function (Server $c) { |
|
256 | + $this->registerService('TagMapper', function(Server $c) { |
|
257 | 257 | return new TagMapper($c->getDatabaseConnection()); |
258 | 258 | }); |
259 | 259 | |
260 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
260 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
261 | 261 | $tagMapper = $c->query('TagMapper'); |
262 | 262 | return new TagManager($tagMapper, $c->getUserSession()); |
263 | 263 | }); |
264 | 264 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
265 | 265 | |
266 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
266 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
267 | 267 | $config = $c->getConfig(); |
268 | 268 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
269 | 269 | return new $factoryClass($this); |
270 | 270 | }); |
271 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
271 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
272 | 272 | return $c->query('SystemTagManagerFactory')->getManager(); |
273 | 273 | }); |
274 | 274 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
275 | 275 | |
276 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
276 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
277 | 277 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
278 | 278 | }); |
279 | - $this->registerService('RootFolder', function (Server $c) { |
|
279 | + $this->registerService('RootFolder', function(Server $c) { |
|
280 | 280 | $manager = \OC\Files\Filesystem::getMountManager(null); |
281 | 281 | $view = new View(); |
282 | 282 | $root = new Root( |
@@ -297,38 +297,38 @@ discard block |
||
297 | 297 | }); |
298 | 298 | $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
299 | 299 | |
300 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
301 | - return new LazyRoot(function () use ($c) { |
|
300 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
301 | + return new LazyRoot(function() use ($c) { |
|
302 | 302 | return $c->query('RootFolder'); |
303 | 303 | }); |
304 | 304 | }); |
305 | 305 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
306 | 306 | |
307 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
307 | + $this->registerService(\OC\User\Manager::class, function(Server $c) { |
|
308 | 308 | $config = $c->getConfig(); |
309 | 309 | return new \OC\User\Manager($config); |
310 | 310 | }); |
311 | 311 | $this->registerAlias('UserManager', \OC\User\Manager::class); |
312 | 312 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
313 | 313 | |
314 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
314 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
315 | 315 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
316 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
316 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
317 | 317 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
318 | 318 | }); |
319 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
319 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
320 | 320 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
321 | 321 | }); |
322 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
322 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
323 | 323 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
324 | 324 | }); |
325 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
325 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
326 | 326 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
327 | 327 | }); |
328 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
328 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
329 | 329 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
330 | 330 | }); |
331 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
331 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
332 | 332 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
333 | 333 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
334 | 334 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | }); |
338 | 338 | $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
339 | 339 | |
340 | - $this->registerService(Store::class, function (Server $c) { |
|
340 | + $this->registerService(Store::class, function(Server $c) { |
|
341 | 341 | $session = $c->getSession(); |
342 | 342 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
343 | 343 | $tokenProvider = $c->query(IProvider::class); |
@@ -348,13 +348,13 @@ discard block |
||
348 | 348 | return new Store($session, $logger, $tokenProvider); |
349 | 349 | }); |
350 | 350 | $this->registerAlias(IStore::class, Store::class); |
351 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
351 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function(Server $c) { |
|
352 | 352 | $dbConnection = $c->getDatabaseConnection(); |
353 | 353 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
354 | 354 | }); |
355 | 355 | $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
356 | 356 | |
357 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
357 | + $this->registerService(\OCP\IUserSession::class, function(Server $c) { |
|
358 | 358 | $manager = $c->getUserManager(); |
359 | 359 | $session = new \OC\Session\Memory(''); |
360 | 360 | $timeFactory = new TimeFactory(); |
@@ -378,45 +378,45 @@ discard block |
||
378 | 378 | $c->getLockdownManager(), |
379 | 379 | $c->getLogger() |
380 | 380 | ); |
381 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
381 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
382 | 382 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
383 | 383 | }); |
384 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
384 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
385 | 385 | /** @var $user \OC\User\User */ |
386 | 386 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
387 | 387 | }); |
388 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
388 | + $userSession->listen('\OC\User', 'preDelete', function($user) use ($dispatcher) { |
|
389 | 389 | /** @var $user \OC\User\User */ |
390 | 390 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
391 | 391 | $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
392 | 392 | }); |
393 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
393 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
394 | 394 | /** @var $user \OC\User\User */ |
395 | 395 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
396 | 396 | }); |
397 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
397 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
398 | 398 | /** @var $user \OC\User\User */ |
399 | 399 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
400 | 400 | }); |
401 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
401 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
402 | 402 | /** @var $user \OC\User\User */ |
403 | 403 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
404 | 404 | }); |
405 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
405 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
406 | 406 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
407 | 407 | }); |
408 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
408 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password) { |
|
409 | 409 | /** @var $user \OC\User\User */ |
410 | 410 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
411 | 411 | }); |
412 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
412 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
413 | 413 | /** @var $user \OC\User\User */ |
414 | 414 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
415 | 415 | }); |
416 | - $userSession->listen('\OC\User', 'logout', function () { |
|
416 | + $userSession->listen('\OC\User', 'logout', function() { |
|
417 | 417 | \OC_Hook::emit('OC_User', 'logout', array()); |
418 | 418 | }); |
419 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
419 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
420 | 420 | /** @var $user \OC\User\User */ |
421 | 421 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
422 | 422 | $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
431 | 431 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
432 | 432 | |
433 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
433 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
434 | 434 | return new \OC\AllConfig( |
435 | 435 | $c->getSystemConfig() |
436 | 436 | ); |
@@ -438,17 +438,17 @@ discard block |
||
438 | 438 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
439 | 439 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
440 | 440 | |
441 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
441 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
442 | 442 | return new \OC\SystemConfig($config); |
443 | 443 | }); |
444 | 444 | |
445 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
445 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
446 | 446 | return new \OC\AppConfig($c->getDatabaseConnection()); |
447 | 447 | }); |
448 | 448 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
449 | 449 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
450 | 450 | |
451 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
451 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
452 | 452 | return new \OC\L10N\Factory( |
453 | 453 | $c->getConfig(), |
454 | 454 | $c->getRequest(), |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | }); |
459 | 459 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
460 | 460 | |
461 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
461 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
462 | 462 | $config = $c->getConfig(); |
463 | 463 | $cacheFactory = $c->getMemCacheFactory(); |
464 | 464 | $request = $c->getRequest(); |
@@ -473,12 +473,12 @@ discard block |
||
473 | 473 | $this->registerAlias('AppFetcher', AppFetcher::class); |
474 | 474 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
475 | 475 | |
476 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
476 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
477 | 477 | return new Cache\File(); |
478 | 478 | }); |
479 | 479 | $this->registerAlias('UserCache', \OCP\ICache::class); |
480 | 480 | |
481 | - $this->registerService(Factory::class, function (Server $c) { |
|
481 | + $this->registerService(Factory::class, function(Server $c) { |
|
482 | 482 | |
483 | 483 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
484 | 484 | ArrayCache::class, |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | $version = implode(',', $v); |
496 | 496 | $instanceId = \OC_Util::getInstanceId(); |
497 | 497 | $path = \OC::$SERVERROOT; |
498 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
498 | + $prefix = md5($instanceId.'-'.$version.'-'.$path); |
|
499 | 499 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
500 | 500 | $config->getSystemValue('memcache.local', null), |
501 | 501 | $config->getSystemValue('memcache.distributed', null), |
@@ -508,12 +508,12 @@ discard block |
||
508 | 508 | $this->registerAlias('MemCacheFactory', Factory::class); |
509 | 509 | $this->registerAlias(ICacheFactory::class, Factory::class); |
510 | 510 | |
511 | - $this->registerService('RedisFactory', function (Server $c) { |
|
511 | + $this->registerService('RedisFactory', function(Server $c) { |
|
512 | 512 | $systemConfig = $c->getSystemConfig(); |
513 | 513 | return new RedisFactory($systemConfig); |
514 | 514 | }); |
515 | 515 | |
516 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
516 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
517 | 517 | return new \OC\Activity\Manager( |
518 | 518 | $c->getRequest(), |
519 | 519 | $c->getUserSession(), |
@@ -523,14 +523,14 @@ discard block |
||
523 | 523 | }); |
524 | 524 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
525 | 525 | |
526 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
526 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
527 | 527 | return new \OC\Activity\EventMerger( |
528 | 528 | $c->getL10N('lib') |
529 | 529 | ); |
530 | 530 | }); |
531 | 531 | $this->registerAlias(IValidator::class, Validator::class); |
532 | 532 | |
533 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
533 | + $this->registerService(\OCP\IAvatarManager::class, function(Server $c) { |
|
534 | 534 | return new AvatarManager( |
535 | 535 | $c->query(\OC\User\Manager::class), |
536 | 536 | $c->getAppDataDir('avatar'), |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | |
544 | 544 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
545 | 545 | |
546 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
546 | + $this->registerService(\OCP\ILogger::class, function(Server $c) { |
|
547 | 547 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
548 | 548 | $factory = new LogFactory($c, $this->getSystemConfig()); |
549 | 549 | $logger = $factory->get($logType); |
@@ -553,11 +553,11 @@ discard block |
||
553 | 553 | }); |
554 | 554 | $this->registerAlias('Logger', \OCP\ILogger::class); |
555 | 555 | |
556 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
556 | + $this->registerService(ILogFactory::class, function(Server $c) { |
|
557 | 557 | return new LogFactory($c, $this->getSystemConfig()); |
558 | 558 | }); |
559 | 559 | |
560 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
560 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
561 | 561 | $config = $c->getConfig(); |
562 | 562 | return new \OC\BackgroundJob\JobList( |
563 | 563 | $c->getDatabaseConnection(), |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | }); |
568 | 568 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
569 | 569 | |
570 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
570 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
571 | 571 | $cacheFactory = $c->getMemCacheFactory(); |
572 | 572 | $logger = $c->getLogger(); |
573 | 573 | if ($cacheFactory->isLocalCacheAvailable()) { |
@@ -579,12 +579,12 @@ discard block |
||
579 | 579 | }); |
580 | 580 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
581 | 581 | |
582 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
582 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
583 | 583 | return new Search(); |
584 | 584 | }); |
585 | 585 | $this->registerAlias('Search', \OCP\ISearch::class); |
586 | 586 | |
587 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
587 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function(Server $c) { |
|
588 | 588 | return new \OC\Security\RateLimiting\Limiter( |
589 | 589 | $this->getUserSession(), |
590 | 590 | $this->getRequest(), |
@@ -592,34 +592,34 @@ discard block |
||
592 | 592 | $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
593 | 593 | ); |
594 | 594 | }); |
595 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
595 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
596 | 596 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
597 | 597 | $this->getMemCacheFactory(), |
598 | 598 | new \OC\AppFramework\Utility\TimeFactory() |
599 | 599 | ); |
600 | 600 | }); |
601 | 601 | |
602 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
602 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
603 | 603 | return new SecureRandom(); |
604 | 604 | }); |
605 | 605 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
606 | 606 | |
607 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
607 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
608 | 608 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
609 | 609 | }); |
610 | 610 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
611 | 611 | |
612 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
612 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
613 | 613 | return new Hasher($c->getConfig()); |
614 | 614 | }); |
615 | 615 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
616 | 616 | |
617 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
617 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
618 | 618 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
619 | 619 | }); |
620 | 620 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
621 | 621 | |
622 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
622 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
623 | 623 | $systemConfig = $c->getSystemConfig(); |
624 | 624 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
625 | 625 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -634,7 +634,7 @@ discard block |
||
634 | 634 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
635 | 635 | |
636 | 636 | |
637 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
637 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
638 | 638 | $user = \OC_User::getUser(); |
639 | 639 | $uid = $user ? $user : null; |
640 | 640 | return new ClientService( |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | ); |
650 | 650 | }); |
651 | 651 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
652 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
652 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
653 | 653 | $eventLogger = new EventLogger(); |
654 | 654 | if ($c->getSystemConfig()->getValue('debug', false)) { |
655 | 655 | // In debug mode, module is being activated by default |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | }); |
660 | 660 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
661 | 661 | |
662 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
662 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
663 | 663 | $queryLogger = new QueryLogger(); |
664 | 664 | if ($c->getSystemConfig()->getValue('debug', false)) { |
665 | 665 | // In debug mode, module is being activated by default |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | }); |
670 | 670 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
671 | 671 | |
672 | - $this->registerService(TempManager::class, function (Server $c) { |
|
672 | + $this->registerService(TempManager::class, function(Server $c) { |
|
673 | 673 | return new TempManager( |
674 | 674 | $c->getLogger(), |
675 | 675 | $c->getConfig() |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | $this->registerAlias('TempManager', TempManager::class); |
679 | 679 | $this->registerAlias(ITempManager::class, TempManager::class); |
680 | 680 | |
681 | - $this->registerService(AppManager::class, function (Server $c) { |
|
681 | + $this->registerService(AppManager::class, function(Server $c) { |
|
682 | 682 | return new \OC\App\AppManager( |
683 | 683 | $c->getUserSession(), |
684 | 684 | $c->query(\OC\AppConfig::class), |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | $this->registerAlias('AppManager', AppManager::class); |
691 | 691 | $this->registerAlias(IAppManager::class, AppManager::class); |
692 | 692 | |
693 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
693 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
694 | 694 | return new DateTimeZone( |
695 | 695 | $c->getConfig(), |
696 | 696 | $c->getSession() |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | }); |
699 | 699 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
700 | 700 | |
701 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
701 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
702 | 702 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
703 | 703 | |
704 | 704 | return new DateTimeFormatter( |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | }); |
709 | 709 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
710 | 710 | |
711 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
711 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
712 | 712 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
713 | 713 | $listener = new UserMountCacheListener($mountCache); |
714 | 714 | $listener->listen($c->getUserManager()); |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | }); |
717 | 717 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
718 | 718 | |
719 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
719 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
720 | 720 | $loader = \OC\Files\Filesystem::getLoader(); |
721 | 721 | $mountCache = $c->query('UserMountCache'); |
722 | 722 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -732,10 +732,10 @@ discard block |
||
732 | 732 | }); |
733 | 733 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
734 | 734 | |
735 | - $this->registerService('IniWrapper', function ($c) { |
|
735 | + $this->registerService('IniWrapper', function($c) { |
|
736 | 736 | return new IniGetWrapper(); |
737 | 737 | }); |
738 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
738 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
739 | 739 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
740 | 740 | if ($busClass) { |
741 | 741 | list($app, $class) = explode('::', $busClass, 2); |
@@ -750,10 +750,10 @@ discard block |
||
750 | 750 | return new CronBus($jobList); |
751 | 751 | } |
752 | 752 | }); |
753 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
753 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
754 | 754 | return new TrustedDomainHelper($this->getConfig()); |
755 | 755 | }); |
756 | - $this->registerService('Throttler', function (Server $c) { |
|
756 | + $this->registerService('Throttler', function(Server $c) { |
|
757 | 757 | return new Throttler( |
758 | 758 | $c->getDatabaseConnection(), |
759 | 759 | new TimeFactory(), |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | $c->getConfig() |
762 | 762 | ); |
763 | 763 | }); |
764 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
764 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
765 | 765 | // IConfig and IAppManager requires a working database. This code |
766 | 766 | // might however be called when ownCloud is not yet setup. |
767 | 767 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
@@ -782,7 +782,7 @@ discard block |
||
782 | 782 | $c->getTempManager() |
783 | 783 | ); |
784 | 784 | }); |
785 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
785 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
786 | 786 | if (isset($this['urlParams'])) { |
787 | 787 | $urlParams = $this['urlParams']; |
788 | 788 | } else { |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | }); |
819 | 819 | $this->registerAlias('Request', \OCP\IRequest::class); |
820 | 820 | |
821 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
821 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
822 | 822 | return new Mailer( |
823 | 823 | $c->getConfig(), |
824 | 824 | $c->getLogger(), |
@@ -829,7 +829,7 @@ discard block |
||
829 | 829 | }); |
830 | 830 | $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
831 | 831 | |
832 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
832 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
833 | 833 | $config = $c->getConfig(); |
834 | 834 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
835 | 835 | if (is_null($factoryClass)) { |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | $factory = new $factoryClass($this); |
840 | 840 | return $factory->getLDAPProvider(); |
841 | 841 | }); |
842 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
842 | + $this->registerService(ILockingProvider::class, function(Server $c) { |
|
843 | 843 | $ini = $c->getIniWrapper(); |
844 | 844 | $config = $c->getConfig(); |
845 | 845 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -862,49 +862,49 @@ discard block |
||
862 | 862 | }); |
863 | 863 | $this->registerAlias('LockingProvider', ILockingProvider::class); |
864 | 864 | |
865 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
865 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
866 | 866 | return new \OC\Files\Mount\Manager(); |
867 | 867 | }); |
868 | 868 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
869 | 869 | |
870 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
870 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
871 | 871 | return new \OC\Files\Type\Detection( |
872 | 872 | $c->getURLGenerator(), |
873 | 873 | \OC::$configDir, |
874 | - \OC::$SERVERROOT . '/resources/config/' |
|
874 | + \OC::$SERVERROOT.'/resources/config/' |
|
875 | 875 | ); |
876 | 876 | }); |
877 | 877 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
878 | 878 | |
879 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
879 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
880 | 880 | return new \OC\Files\Type\Loader( |
881 | 881 | $c->getDatabaseConnection() |
882 | 882 | ); |
883 | 883 | }); |
884 | 884 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
885 | - $this->registerService(BundleFetcher::class, function () { |
|
885 | + $this->registerService(BundleFetcher::class, function() { |
|
886 | 886 | return new BundleFetcher($this->getL10N('lib')); |
887 | 887 | }); |
888 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
888 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
889 | 889 | return new Manager( |
890 | 890 | $c->query(IValidator::class) |
891 | 891 | ); |
892 | 892 | }); |
893 | 893 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
894 | 894 | |
895 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
895 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
896 | 896 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
897 | - $manager->registerCapability(function () use ($c) { |
|
897 | + $manager->registerCapability(function() use ($c) { |
|
898 | 898 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
899 | 899 | }); |
900 | - $manager->registerCapability(function () use ($c) { |
|
900 | + $manager->registerCapability(function() use ($c) { |
|
901 | 901 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
902 | 902 | }); |
903 | 903 | return $manager; |
904 | 904 | }); |
905 | 905 | $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
906 | 906 | |
907 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
907 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
908 | 908 | $config = $c->getConfig(); |
909 | 909 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
910 | 910 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
@@ -914,7 +914,7 @@ discard block |
||
914 | 914 | $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
915 | 915 | $manager = $c->getUserManager(); |
916 | 916 | $user = $manager->get($id); |
917 | - if(is_null($user)) { |
|
917 | + if (is_null($user)) { |
|
918 | 918 | $l = $c->getL10N('core'); |
919 | 919 | $displayName = $l->t('Unknown user'); |
920 | 920 | } else { |
@@ -927,7 +927,7 @@ discard block |
||
927 | 927 | }); |
928 | 928 | $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
929 | 929 | |
930 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
930 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
931 | 931 | /* |
932 | 932 | * Dark magic for autoloader. |
933 | 933 | * If we do a class_exists it will try to load the class which will |
@@ -954,7 +954,7 @@ discard block |
||
954 | 954 | } |
955 | 955 | return new \OC_Defaults(); |
956 | 956 | }); |
957 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
957 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
958 | 958 | /** @var Factory $cacheFactory */ |
959 | 959 | $cacheFactory = $c->query(Factory::class); |
960 | 960 | return new SCSSCacher( |
@@ -968,7 +968,7 @@ discard block |
||
968 | 968 | $c->query(IconsCacher::class) |
969 | 969 | ); |
970 | 970 | }); |
971 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
971 | + $this->registerService(JSCombiner::class, function(Server $c) { |
|
972 | 972 | /** @var Factory $cacheFactory */ |
973 | 973 | $cacheFactory = $c->query(Factory::class); |
974 | 974 | return new JSCombiner( |
@@ -979,13 +979,13 @@ discard block |
||
979 | 979 | $c->getLogger() |
980 | 980 | ); |
981 | 981 | }); |
982 | - $this->registerService(EventDispatcher::class, function () { |
|
982 | + $this->registerService(EventDispatcher::class, function() { |
|
983 | 983 | return new EventDispatcher(); |
984 | 984 | }); |
985 | 985 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
986 | 986 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
987 | 987 | |
988 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
988 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
989 | 989 | // FIXME: Instantiiated here due to cyclic dependency |
990 | 990 | $request = new Request( |
991 | 991 | [ |
@@ -1010,7 +1010,7 @@ discard block |
||
1010 | 1010 | $request |
1011 | 1011 | ); |
1012 | 1012 | }); |
1013 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1013 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
1014 | 1014 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
1015 | 1015 | |
1016 | 1016 | return new CsrfTokenManager( |
@@ -1018,22 +1018,22 @@ discard block |
||
1018 | 1018 | $c->query(SessionStorage::class) |
1019 | 1019 | ); |
1020 | 1020 | }); |
1021 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1021 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
1022 | 1022 | return new SessionStorage($c->getSession()); |
1023 | 1023 | }); |
1024 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1024 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
1025 | 1025 | return new ContentSecurityPolicyManager(); |
1026 | 1026 | }); |
1027 | 1027 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
1028 | 1028 | |
1029 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1029 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
1030 | 1030 | return new ContentSecurityPolicyNonceManager( |
1031 | 1031 | $c->getCsrfTokenManager(), |
1032 | 1032 | $c->getRequest() |
1033 | 1033 | ); |
1034 | 1034 | }); |
1035 | 1035 | |
1036 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1036 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
1037 | 1037 | $config = $c->getConfig(); |
1038 | 1038 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
1039 | 1039 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1077,7 +1077,7 @@ discard block |
||
1077 | 1077 | |
1078 | 1078 | $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
1079 | 1079 | |
1080 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1080 | + $this->registerService('SettingsManager', function(Server $c) { |
|
1081 | 1081 | $manager = new \OC\Settings\Manager( |
1082 | 1082 | $c->getLogger(), |
1083 | 1083 | $c->getDatabaseConnection(), |
@@ -1095,36 +1095,36 @@ discard block |
||
1095 | 1095 | ); |
1096 | 1096 | return $manager; |
1097 | 1097 | }); |
1098 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1098 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
1099 | 1099 | return new \OC\Files\AppData\Factory( |
1100 | 1100 | $c->getRootFolder(), |
1101 | 1101 | $c->getSystemConfig() |
1102 | 1102 | ); |
1103 | 1103 | }); |
1104 | 1104 | |
1105 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1106 | - return new LockdownManager(function () use ($c) { |
|
1105 | + $this->registerService('LockdownManager', function(Server $c) { |
|
1106 | + return new LockdownManager(function() use ($c) { |
|
1107 | 1107 | return $c->getSession(); |
1108 | 1108 | }); |
1109 | 1109 | }); |
1110 | 1110 | |
1111 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1111 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
1112 | 1112 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
1113 | 1113 | }); |
1114 | 1114 | |
1115 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1115 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
1116 | 1116 | return new CloudIdManager(); |
1117 | 1117 | }); |
1118 | 1118 | |
1119 | - $this->registerService(IConfig::class, function (Server $c) { |
|
1119 | + $this->registerService(IConfig::class, function(Server $c) { |
|
1120 | 1120 | return new GlobalScale\Config($c->getConfig()); |
1121 | 1121 | }); |
1122 | 1122 | |
1123 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1123 | + $this->registerService(ICloudFederationProviderManager::class, function(Server $c) { |
|
1124 | 1124 | return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
1125 | 1125 | }); |
1126 | 1126 | |
1127 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1127 | + $this->registerService(ICloudFederationFactory::class, function(Server $c) { |
|
1128 | 1128 | return new CloudFederationFactory(); |
1129 | 1129 | }); |
1130 | 1130 | |
@@ -1134,18 +1134,18 @@ discard block |
||
1134 | 1134 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
1135 | 1135 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
1136 | 1136 | |
1137 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1137 | + $this->registerService(Defaults::class, function(Server $c) { |
|
1138 | 1138 | return new Defaults( |
1139 | 1139 | $c->getThemingDefaults() |
1140 | 1140 | ); |
1141 | 1141 | }); |
1142 | 1142 | $this->registerAlias('Defaults', \OCP\Defaults::class); |
1143 | 1143 | |
1144 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1144 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
1145 | 1145 | return $c->query(\OCP\IUserSession::class)->getSession(); |
1146 | 1146 | }); |
1147 | 1147 | |
1148 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1148 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
1149 | 1149 | return new ShareHelper( |
1150 | 1150 | $c->query(\OCP\Share\IManager::class) |
1151 | 1151 | ); |
@@ -1221,11 +1221,11 @@ discard block |
||
1221 | 1221 | // no avatar to remove |
1222 | 1222 | } catch (\Exception $e) { |
1223 | 1223 | // Ignore exceptions |
1224 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1224 | + $logger->info('Could not cleanup avatar of '.$user->getUID()); |
|
1225 | 1225 | } |
1226 | 1226 | }); |
1227 | 1227 | |
1228 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1228 | + $dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) { |
|
1229 | 1229 | $manager = $this->getAvatarManager(); |
1230 | 1230 | /** @var IUser $user */ |
1231 | 1231 | $user = $e->getSubject(); |
@@ -1376,7 +1376,7 @@ discard block |
||
1376 | 1376 | * @deprecated since 9.2.0 use IAppData |
1377 | 1377 | */ |
1378 | 1378 | public function getAppFolder() { |
1379 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1379 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
1380 | 1380 | $root = $this->getRootFolder(); |
1381 | 1381 | if (!$root->nodeExists($dir)) { |
1382 | 1382 | $folder = $root->newFolder($dir); |
@@ -1951,7 +1951,7 @@ discard block |
||
1951 | 1951 | /** |
1952 | 1952 | * @return \OCP\Collaboration\AutoComplete\IManager |
1953 | 1953 | */ |
1954 | - public function getAutoCompleteManager(){ |
|
1954 | + public function getAutoCompleteManager() { |
|
1955 | 1955 | return $this->query(IManager::class); |
1956 | 1956 | } |
1957 | 1957 |
@@ -66,1466 +66,1466 @@ |
||
66 | 66 | use OCP\IUser; |
67 | 67 | |
68 | 68 | class OC_Util { |
69 | - public static $scripts = array(); |
|
70 | - public static $styles = array(); |
|
71 | - public static $headers = array(); |
|
72 | - private static $rootMounted = false; |
|
73 | - private static $fsSetup = false; |
|
74 | - |
|
75 | - /** @var array Local cache of version.php */ |
|
76 | - private static $versionCache = null; |
|
77 | - |
|
78 | - protected static function getAppManager() { |
|
79 | - return \OC::$server->getAppManager(); |
|
80 | - } |
|
81 | - |
|
82 | - private static function initLocalStorageRootFS() { |
|
83 | - // mount local file backend as root |
|
84 | - $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
85 | - //first set up the local "root" storage |
|
86 | - \OC\Files\Filesystem::initMountManager(); |
|
87 | - if (!self::$rootMounted) { |
|
88 | - \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/'); |
|
89 | - self::$rootMounted = true; |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * mounting an object storage as the root fs will in essence remove the |
|
95 | - * necessity of a data folder being present. |
|
96 | - * TODO make home storage aware of this and use the object storage instead of local disk access |
|
97 | - * |
|
98 | - * @param array $config containing 'class' and optional 'arguments' |
|
99 | - * @suppress PhanDeprecatedFunction |
|
100 | - */ |
|
101 | - private static function initObjectStoreRootFS($config) { |
|
102 | - // check misconfiguration |
|
103 | - if (empty($config['class'])) { |
|
104 | - \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
105 | - } |
|
106 | - if (!isset($config['arguments'])) { |
|
107 | - $config['arguments'] = array(); |
|
108 | - } |
|
109 | - |
|
110 | - // instantiate object store implementation |
|
111 | - $name = $config['class']; |
|
112 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
113 | - $segments = explode('\\', $name); |
|
114 | - OC_App::loadApp(strtolower($segments[1])); |
|
115 | - } |
|
116 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
117 | - // mount with plain / root object store implementation |
|
118 | - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
119 | - |
|
120 | - // mount object storage as root |
|
121 | - \OC\Files\Filesystem::initMountManager(); |
|
122 | - if (!self::$rootMounted) { |
|
123 | - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
124 | - self::$rootMounted = true; |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * mounting an object storage as the root fs will in essence remove the |
|
130 | - * necessity of a data folder being present. |
|
131 | - * |
|
132 | - * @param array $config containing 'class' and optional 'arguments' |
|
133 | - * @suppress PhanDeprecatedFunction |
|
134 | - */ |
|
135 | - private static function initObjectStoreMultibucketRootFS($config) { |
|
136 | - // check misconfiguration |
|
137 | - if (empty($config['class'])) { |
|
138 | - \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
139 | - } |
|
140 | - if (!isset($config['arguments'])) { |
|
141 | - $config['arguments'] = array(); |
|
142 | - } |
|
143 | - |
|
144 | - // instantiate object store implementation |
|
145 | - $name = $config['class']; |
|
146 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
147 | - $segments = explode('\\', $name); |
|
148 | - OC_App::loadApp(strtolower($segments[1])); |
|
149 | - } |
|
150 | - |
|
151 | - if (!isset($config['arguments']['bucket'])) { |
|
152 | - $config['arguments']['bucket'] = ''; |
|
153 | - } |
|
154 | - // put the root FS always in first bucket for multibucket configuration |
|
155 | - $config['arguments']['bucket'] .= '0'; |
|
156 | - |
|
157 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
158 | - // mount with plain / root object store implementation |
|
159 | - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
160 | - |
|
161 | - // mount object storage as root |
|
162 | - \OC\Files\Filesystem::initMountManager(); |
|
163 | - if (!self::$rootMounted) { |
|
164 | - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
165 | - self::$rootMounted = true; |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Can be set up |
|
171 | - * |
|
172 | - * @param string $user |
|
173 | - * @return boolean |
|
174 | - * @description configure the initial filesystem based on the configuration |
|
175 | - * @suppress PhanDeprecatedFunction |
|
176 | - * @suppress PhanAccessMethodInternal |
|
177 | - */ |
|
178 | - public static function setupFS($user = '') { |
|
179 | - //setting up the filesystem twice can only lead to trouble |
|
180 | - if (self::$fsSetup) { |
|
181 | - return false; |
|
182 | - } |
|
183 | - |
|
184 | - \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
185 | - |
|
186 | - // If we are not forced to load a specific user we load the one that is logged in |
|
187 | - if ($user === null) { |
|
188 | - $user = ''; |
|
189 | - } else if ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
190 | - $user = OC_User::getUser(); |
|
191 | - } |
|
192 | - |
|
193 | - // load all filesystem apps before, so no setup-hook gets lost |
|
194 | - OC_App::loadApps(array('filesystem')); |
|
195 | - |
|
196 | - // the filesystem will finish when $user is not empty, |
|
197 | - // mark fs setup here to avoid doing the setup from loading |
|
198 | - // OC_Filesystem |
|
199 | - if ($user != '') { |
|
200 | - self::$fsSetup = true; |
|
201 | - } |
|
202 | - |
|
203 | - \OC\Files\Filesystem::initMountManager(); |
|
204 | - |
|
205 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
206 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
207 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
208 | - /** @var \OC\Files\Storage\Common $storage */ |
|
209 | - $storage->setMountOptions($mount->getOptions()); |
|
210 | - } |
|
211 | - return $storage; |
|
212 | - }); |
|
213 | - |
|
214 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
215 | - if (!$mount->getOption('enable_sharing', true)) { |
|
216 | - return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
217 | - 'storage' => $storage, |
|
218 | - 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
219 | - ]); |
|
220 | - } |
|
221 | - return $storage; |
|
222 | - }); |
|
223 | - |
|
224 | - // install storage availability wrapper, before most other wrappers |
|
225 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
226 | - if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
227 | - return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
228 | - } |
|
229 | - return $storage; |
|
230 | - }); |
|
231 | - |
|
232 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
233 | - if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
234 | - return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
235 | - } |
|
236 | - return $storage; |
|
237 | - }); |
|
238 | - |
|
239 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
240 | - // set up quota for home storages, even for other users |
|
241 | - // which can happen when using sharing |
|
242 | - |
|
243 | - /** |
|
244 | - * @var \OC\Files\Storage\Storage $storage |
|
245 | - */ |
|
246 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
247 | - || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
248 | - ) { |
|
249 | - /** @var \OC\Files\Storage\Home $storage */ |
|
250 | - if (is_object($storage->getUser())) { |
|
251 | - $user = $storage->getUser()->getUID(); |
|
252 | - $quota = OC_Util::getUserQuota($user); |
|
253 | - if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
254 | - return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files')); |
|
255 | - } |
|
256 | - } |
|
257 | - } |
|
258 | - |
|
259 | - return $storage; |
|
260 | - }); |
|
261 | - |
|
262 | - \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
263 | - /* |
|
69 | + public static $scripts = array(); |
|
70 | + public static $styles = array(); |
|
71 | + public static $headers = array(); |
|
72 | + private static $rootMounted = false; |
|
73 | + private static $fsSetup = false; |
|
74 | + |
|
75 | + /** @var array Local cache of version.php */ |
|
76 | + private static $versionCache = null; |
|
77 | + |
|
78 | + protected static function getAppManager() { |
|
79 | + return \OC::$server->getAppManager(); |
|
80 | + } |
|
81 | + |
|
82 | + private static function initLocalStorageRootFS() { |
|
83 | + // mount local file backend as root |
|
84 | + $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
85 | + //first set up the local "root" storage |
|
86 | + \OC\Files\Filesystem::initMountManager(); |
|
87 | + if (!self::$rootMounted) { |
|
88 | + \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/'); |
|
89 | + self::$rootMounted = true; |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * mounting an object storage as the root fs will in essence remove the |
|
95 | + * necessity of a data folder being present. |
|
96 | + * TODO make home storage aware of this and use the object storage instead of local disk access |
|
97 | + * |
|
98 | + * @param array $config containing 'class' and optional 'arguments' |
|
99 | + * @suppress PhanDeprecatedFunction |
|
100 | + */ |
|
101 | + private static function initObjectStoreRootFS($config) { |
|
102 | + // check misconfiguration |
|
103 | + if (empty($config['class'])) { |
|
104 | + \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
105 | + } |
|
106 | + if (!isset($config['arguments'])) { |
|
107 | + $config['arguments'] = array(); |
|
108 | + } |
|
109 | + |
|
110 | + // instantiate object store implementation |
|
111 | + $name = $config['class']; |
|
112 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
113 | + $segments = explode('\\', $name); |
|
114 | + OC_App::loadApp(strtolower($segments[1])); |
|
115 | + } |
|
116 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
117 | + // mount with plain / root object store implementation |
|
118 | + $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
119 | + |
|
120 | + // mount object storage as root |
|
121 | + \OC\Files\Filesystem::initMountManager(); |
|
122 | + if (!self::$rootMounted) { |
|
123 | + \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
124 | + self::$rootMounted = true; |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * mounting an object storage as the root fs will in essence remove the |
|
130 | + * necessity of a data folder being present. |
|
131 | + * |
|
132 | + * @param array $config containing 'class' and optional 'arguments' |
|
133 | + * @suppress PhanDeprecatedFunction |
|
134 | + */ |
|
135 | + private static function initObjectStoreMultibucketRootFS($config) { |
|
136 | + // check misconfiguration |
|
137 | + if (empty($config['class'])) { |
|
138 | + \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
139 | + } |
|
140 | + if (!isset($config['arguments'])) { |
|
141 | + $config['arguments'] = array(); |
|
142 | + } |
|
143 | + |
|
144 | + // instantiate object store implementation |
|
145 | + $name = $config['class']; |
|
146 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
147 | + $segments = explode('\\', $name); |
|
148 | + OC_App::loadApp(strtolower($segments[1])); |
|
149 | + } |
|
150 | + |
|
151 | + if (!isset($config['arguments']['bucket'])) { |
|
152 | + $config['arguments']['bucket'] = ''; |
|
153 | + } |
|
154 | + // put the root FS always in first bucket for multibucket configuration |
|
155 | + $config['arguments']['bucket'] .= '0'; |
|
156 | + |
|
157 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
158 | + // mount with plain / root object store implementation |
|
159 | + $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
160 | + |
|
161 | + // mount object storage as root |
|
162 | + \OC\Files\Filesystem::initMountManager(); |
|
163 | + if (!self::$rootMounted) { |
|
164 | + \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
165 | + self::$rootMounted = true; |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Can be set up |
|
171 | + * |
|
172 | + * @param string $user |
|
173 | + * @return boolean |
|
174 | + * @description configure the initial filesystem based on the configuration |
|
175 | + * @suppress PhanDeprecatedFunction |
|
176 | + * @suppress PhanAccessMethodInternal |
|
177 | + */ |
|
178 | + public static function setupFS($user = '') { |
|
179 | + //setting up the filesystem twice can only lead to trouble |
|
180 | + if (self::$fsSetup) { |
|
181 | + return false; |
|
182 | + } |
|
183 | + |
|
184 | + \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
185 | + |
|
186 | + // If we are not forced to load a specific user we load the one that is logged in |
|
187 | + if ($user === null) { |
|
188 | + $user = ''; |
|
189 | + } else if ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
190 | + $user = OC_User::getUser(); |
|
191 | + } |
|
192 | + |
|
193 | + // load all filesystem apps before, so no setup-hook gets lost |
|
194 | + OC_App::loadApps(array('filesystem')); |
|
195 | + |
|
196 | + // the filesystem will finish when $user is not empty, |
|
197 | + // mark fs setup here to avoid doing the setup from loading |
|
198 | + // OC_Filesystem |
|
199 | + if ($user != '') { |
|
200 | + self::$fsSetup = true; |
|
201 | + } |
|
202 | + |
|
203 | + \OC\Files\Filesystem::initMountManager(); |
|
204 | + |
|
205 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
206 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
207 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
208 | + /** @var \OC\Files\Storage\Common $storage */ |
|
209 | + $storage->setMountOptions($mount->getOptions()); |
|
210 | + } |
|
211 | + return $storage; |
|
212 | + }); |
|
213 | + |
|
214 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
215 | + if (!$mount->getOption('enable_sharing', true)) { |
|
216 | + return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
217 | + 'storage' => $storage, |
|
218 | + 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
219 | + ]); |
|
220 | + } |
|
221 | + return $storage; |
|
222 | + }); |
|
223 | + |
|
224 | + // install storage availability wrapper, before most other wrappers |
|
225 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
226 | + if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
227 | + return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
228 | + } |
|
229 | + return $storage; |
|
230 | + }); |
|
231 | + |
|
232 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
233 | + if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
234 | + return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
235 | + } |
|
236 | + return $storage; |
|
237 | + }); |
|
238 | + |
|
239 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
240 | + // set up quota for home storages, even for other users |
|
241 | + // which can happen when using sharing |
|
242 | + |
|
243 | + /** |
|
244 | + * @var \OC\Files\Storage\Storage $storage |
|
245 | + */ |
|
246 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
247 | + || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
248 | + ) { |
|
249 | + /** @var \OC\Files\Storage\Home $storage */ |
|
250 | + if (is_object($storage->getUser())) { |
|
251 | + $user = $storage->getUser()->getUID(); |
|
252 | + $quota = OC_Util::getUserQuota($user); |
|
253 | + if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
254 | + return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files')); |
|
255 | + } |
|
256 | + } |
|
257 | + } |
|
258 | + |
|
259 | + return $storage; |
|
260 | + }); |
|
261 | + |
|
262 | + \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
263 | + /* |
|
264 | 264 | * Do not allow any operations that modify the storage |
265 | 265 | */ |
266 | - if ($mount->getOption('readonly', false)) { |
|
267 | - return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
268 | - 'storage' => $storage, |
|
269 | - 'mask' => \OCP\Constants::PERMISSION_ALL & ~( |
|
270 | - \OCP\Constants::PERMISSION_UPDATE | |
|
271 | - \OCP\Constants::PERMISSION_CREATE | |
|
272 | - \OCP\Constants::PERMISSION_DELETE |
|
273 | - ), |
|
274 | - ]); |
|
275 | - } |
|
276 | - return $storage; |
|
277 | - }); |
|
278 | - |
|
279 | - OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user)); |
|
280 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true); |
|
281 | - |
|
282 | - //check if we are using an object storage |
|
283 | - $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
284 | - $objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null); |
|
285 | - |
|
286 | - // use the same order as in ObjectHomeMountProvider |
|
287 | - if (isset($objectStoreMultibucket)) { |
|
288 | - self::initObjectStoreMultibucketRootFS($objectStoreMultibucket); |
|
289 | - } elseif (isset($objectStore)) { |
|
290 | - self::initObjectStoreRootFS($objectStore); |
|
291 | - } else { |
|
292 | - self::initLocalStorageRootFS(); |
|
293 | - } |
|
294 | - |
|
295 | - if ($user != '' && !\OC::$server->getUserManager()->userExists($user)) { |
|
296 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
297 | - return false; |
|
298 | - } |
|
299 | - |
|
300 | - //if we aren't logged in, there is no use to set up the filesystem |
|
301 | - if ($user != "") { |
|
302 | - |
|
303 | - $userDir = '/' . $user . '/files'; |
|
304 | - |
|
305 | - //jail the user into his "home" directory |
|
306 | - \OC\Files\Filesystem::init($user, $userDir); |
|
307 | - |
|
308 | - OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); |
|
309 | - } |
|
310 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
311 | - return true; |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * check if a password is required for each public link |
|
316 | - * |
|
317 | - * @return boolean |
|
318 | - * @suppress PhanDeprecatedFunction |
|
319 | - */ |
|
320 | - public static function isPublicLinkPasswordRequired() { |
|
321 | - $enforcePassword = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_links_password', 'no'); |
|
322 | - return $enforcePassword === 'yes'; |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * check if sharing is disabled for the current user |
|
327 | - * @param IConfig $config |
|
328 | - * @param IGroupManager $groupManager |
|
329 | - * @param IUser|null $user |
|
330 | - * @return bool |
|
331 | - */ |
|
332 | - public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
333 | - if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
334 | - $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
335 | - $excludedGroups = json_decode($groupsList); |
|
336 | - if (is_null($excludedGroups)) { |
|
337 | - $excludedGroups = explode(',', $groupsList); |
|
338 | - $newValue = json_encode($excludedGroups); |
|
339 | - $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
340 | - } |
|
341 | - $usersGroups = $groupManager->getUserGroupIds($user); |
|
342 | - if (!empty($usersGroups)) { |
|
343 | - $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
344 | - // if the user is only in groups which are disabled for sharing then |
|
345 | - // sharing is also disabled for the user |
|
346 | - if (empty($remainingGroups)) { |
|
347 | - return true; |
|
348 | - } |
|
349 | - } |
|
350 | - } |
|
351 | - return false; |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * check if share API enforces a default expire date |
|
356 | - * |
|
357 | - * @return boolean |
|
358 | - * @suppress PhanDeprecatedFunction |
|
359 | - */ |
|
360 | - public static function isDefaultExpireDateEnforced() { |
|
361 | - $isDefaultExpireDateEnabled = \OC::$server->getConfig()->getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
362 | - $enforceDefaultExpireDate = false; |
|
363 | - if ($isDefaultExpireDateEnabled === 'yes') { |
|
364 | - $value = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
365 | - $enforceDefaultExpireDate = $value === 'yes'; |
|
366 | - } |
|
367 | - |
|
368 | - return $enforceDefaultExpireDate; |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Get the quota of a user |
|
373 | - * |
|
374 | - * @param string $userId |
|
375 | - * @return float Quota bytes |
|
376 | - */ |
|
377 | - public static function getUserQuota($userId) { |
|
378 | - $user = \OC::$server->getUserManager()->get($userId); |
|
379 | - if (is_null($user)) { |
|
380 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
381 | - } |
|
382 | - $userQuota = $user->getQuota(); |
|
383 | - if($userQuota === 'none') { |
|
384 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
385 | - } |
|
386 | - return OC_Helper::computerFileSize($userQuota); |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * copies the skeleton to the users /files |
|
391 | - * |
|
392 | - * @param String $userId |
|
393 | - * @param \OCP\Files\Folder $userDirectory |
|
394 | - * @throws \RuntimeException |
|
395 | - * @suppress PhanDeprecatedFunction |
|
396 | - */ |
|
397 | - public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
398 | - |
|
399 | - $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
400 | - $userLang = \OC::$server->getL10NFactory()->findLanguage(); |
|
401 | - $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory); |
|
402 | - |
|
403 | - if (!file_exists($skeletonDirectory)) { |
|
404 | - $dialectStart = strpos($userLang, '_'); |
|
405 | - if ($dialectStart !== false) { |
|
406 | - $skeletonDirectory = str_replace('{lang}', substr($userLang, 0, $dialectStart), $plainSkeletonDirectory); |
|
407 | - } |
|
408 | - if ($dialectStart === false || !file_exists($skeletonDirectory)) { |
|
409 | - $skeletonDirectory = str_replace('{lang}', 'default', $plainSkeletonDirectory); |
|
410 | - } |
|
411 | - if (!file_exists($skeletonDirectory)) { |
|
412 | - $skeletonDirectory = ''; |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
417 | - |
|
418 | - if ($instanceId === null) { |
|
419 | - throw new \RuntimeException('no instance id!'); |
|
420 | - } |
|
421 | - $appdata = 'appdata_' . $instanceId; |
|
422 | - if ($userId === $appdata) { |
|
423 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
424 | - } |
|
425 | - |
|
426 | - if (!empty($skeletonDirectory)) { |
|
427 | - \OCP\Util::writeLog( |
|
428 | - 'files_skeleton', |
|
429 | - 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), |
|
430 | - ILogger::DEBUG |
|
431 | - ); |
|
432 | - self::copyr($skeletonDirectory, $userDirectory); |
|
433 | - // update the file cache |
|
434 | - $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
435 | - } |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * copies a directory recursively by using streams |
|
440 | - * |
|
441 | - * @param string $source |
|
442 | - * @param \OCP\Files\Folder $target |
|
443 | - * @return void |
|
444 | - */ |
|
445 | - public static function copyr($source, \OCP\Files\Folder $target) { |
|
446 | - $logger = \OC::$server->getLogger(); |
|
447 | - |
|
448 | - // Verify if folder exists |
|
449 | - $dir = opendir($source); |
|
450 | - if($dir === false) { |
|
451 | - $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
452 | - return; |
|
453 | - } |
|
454 | - |
|
455 | - // Copy the files |
|
456 | - while (false !== ($file = readdir($dir))) { |
|
457 | - if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
458 | - if (is_dir($source . '/' . $file)) { |
|
459 | - $child = $target->newFolder($file); |
|
460 | - self::copyr($source . '/' . $file, $child); |
|
461 | - } else { |
|
462 | - $child = $target->newFile($file); |
|
463 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
464 | - if($sourceStream === false) { |
|
465 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
466 | - closedir($dir); |
|
467 | - return; |
|
468 | - } |
|
469 | - stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
470 | - } |
|
471 | - } |
|
472 | - } |
|
473 | - closedir($dir); |
|
474 | - } |
|
475 | - |
|
476 | - /** |
|
477 | - * @return void |
|
478 | - * @suppress PhanUndeclaredMethod |
|
479 | - */ |
|
480 | - public static function tearDownFS() { |
|
481 | - \OC\Files\Filesystem::tearDown(); |
|
482 | - \OC::$server->getRootFolder()->clearCache(); |
|
483 | - self::$fsSetup = false; |
|
484 | - self::$rootMounted = false; |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * get the current installed version of ownCloud |
|
489 | - * |
|
490 | - * @return array |
|
491 | - */ |
|
492 | - public static function getVersion() { |
|
493 | - OC_Util::loadVersion(); |
|
494 | - return self::$versionCache['OC_Version']; |
|
495 | - } |
|
496 | - |
|
497 | - /** |
|
498 | - * get the current installed version string of ownCloud |
|
499 | - * |
|
500 | - * @return string |
|
501 | - */ |
|
502 | - public static function getVersionString() { |
|
503 | - OC_Util::loadVersion(); |
|
504 | - return self::$versionCache['OC_VersionString']; |
|
505 | - } |
|
506 | - |
|
507 | - /** |
|
508 | - * @deprecated the value is of no use anymore |
|
509 | - * @return string |
|
510 | - */ |
|
511 | - public static function getEditionString() { |
|
512 | - return ''; |
|
513 | - } |
|
514 | - |
|
515 | - /** |
|
516 | - * @description get the update channel of the current installed of ownCloud. |
|
517 | - * @return string |
|
518 | - */ |
|
519 | - public static function getChannel() { |
|
520 | - OC_Util::loadVersion(); |
|
521 | - return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * @description get the build number of the current installed of ownCloud. |
|
526 | - * @return string |
|
527 | - */ |
|
528 | - public static function getBuild() { |
|
529 | - OC_Util::loadVersion(); |
|
530 | - return self::$versionCache['OC_Build']; |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * @description load the version.php into the session as cache |
|
535 | - * @suppress PhanUndeclaredVariable |
|
536 | - */ |
|
537 | - private static function loadVersion() { |
|
538 | - if (self::$versionCache !== null) { |
|
539 | - return; |
|
540 | - } |
|
541 | - |
|
542 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
543 | - require OC::$SERVERROOT . '/version.php'; |
|
544 | - /** @var $timestamp int */ |
|
545 | - self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
546 | - /** @var $OC_Version string */ |
|
547 | - self::$versionCache['OC_Version'] = $OC_Version; |
|
548 | - /** @var $OC_VersionString string */ |
|
549 | - self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
550 | - /** @var $OC_Build string */ |
|
551 | - self::$versionCache['OC_Build'] = $OC_Build; |
|
552 | - |
|
553 | - /** @var $OC_Channel string */ |
|
554 | - self::$versionCache['OC_Channel'] = $OC_Channel; |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
559 | - * |
|
560 | - * @param string $application application to get the files from |
|
561 | - * @param string $directory directory within this application (css, js, vendor, etc) |
|
562 | - * @param string $file the file inside of the above folder |
|
563 | - * @return string the path |
|
564 | - */ |
|
565 | - private static function generatePath($application, $directory, $file) { |
|
566 | - if (is_null($file)) { |
|
567 | - $file = $application; |
|
568 | - $application = ""; |
|
569 | - } |
|
570 | - if (!empty($application)) { |
|
571 | - return "$application/$directory/$file"; |
|
572 | - } else { |
|
573 | - return "$directory/$file"; |
|
574 | - } |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * add a javascript file |
|
579 | - * |
|
580 | - * @param string $application application id |
|
581 | - * @param string|null $file filename |
|
582 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
583 | - * @return void |
|
584 | - */ |
|
585 | - public static function addScript($application, $file = null, $prepend = false) { |
|
586 | - $path = OC_Util::generatePath($application, 'js', $file); |
|
587 | - |
|
588 | - // core js files need separate handling |
|
589 | - if ($application !== 'core' && $file !== null) { |
|
590 | - self::addTranslations ( $application ); |
|
591 | - } |
|
592 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * add a javascript file from the vendor sub folder |
|
597 | - * |
|
598 | - * @param string $application application id |
|
599 | - * @param string|null $file filename |
|
600 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
601 | - * @return void |
|
602 | - */ |
|
603 | - public static function addVendorScript($application, $file = null, $prepend = false) { |
|
604 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
605 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * add a translation JS file |
|
610 | - * |
|
611 | - * @param string $application application id |
|
612 | - * @param string|null $languageCode language code, defaults to the current language |
|
613 | - * @param bool|null $prepend prepend the Script to the beginning of the list |
|
614 | - */ |
|
615 | - public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
616 | - if (is_null($languageCode)) { |
|
617 | - $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
618 | - } |
|
619 | - if (!empty($application)) { |
|
620 | - $path = "$application/l10n/$languageCode"; |
|
621 | - } else { |
|
622 | - $path = "l10n/$languageCode"; |
|
623 | - } |
|
624 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
625 | - } |
|
626 | - |
|
627 | - /** |
|
628 | - * add a css file |
|
629 | - * |
|
630 | - * @param string $application application id |
|
631 | - * @param string|null $file filename |
|
632 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
633 | - * @return void |
|
634 | - */ |
|
635 | - public static function addStyle($application, $file = null, $prepend = false) { |
|
636 | - $path = OC_Util::generatePath($application, 'css', $file); |
|
637 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
638 | - } |
|
639 | - |
|
640 | - /** |
|
641 | - * add a css file from the vendor sub folder |
|
642 | - * |
|
643 | - * @param string $application application id |
|
644 | - * @param string|null $file filename |
|
645 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
646 | - * @return void |
|
647 | - */ |
|
648 | - public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
649 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
650 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
651 | - } |
|
652 | - |
|
653 | - /** |
|
654 | - * add an external resource css/js file |
|
655 | - * |
|
656 | - * @param string $application application id |
|
657 | - * @param bool $prepend prepend the file to the beginning of the list |
|
658 | - * @param string $path |
|
659 | - * @param string $type (script or style) |
|
660 | - * @return void |
|
661 | - */ |
|
662 | - private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
663 | - |
|
664 | - if ($type === "style") { |
|
665 | - if (!in_array($path, self::$styles)) { |
|
666 | - if ($prepend === true) { |
|
667 | - array_unshift ( self::$styles, $path ); |
|
668 | - } else { |
|
669 | - self::$styles[] = $path; |
|
670 | - } |
|
671 | - } |
|
672 | - } elseif ($type === "script") { |
|
673 | - if (!in_array($path, self::$scripts)) { |
|
674 | - if ($prepend === true) { |
|
675 | - array_unshift ( self::$scripts, $path ); |
|
676 | - } else { |
|
677 | - self::$scripts [] = $path; |
|
678 | - } |
|
679 | - } |
|
680 | - } |
|
681 | - } |
|
682 | - |
|
683 | - /** |
|
684 | - * Add a custom element to the header |
|
685 | - * If $text is null then the element will be written as empty element. |
|
686 | - * So use "" to get a closing tag. |
|
687 | - * @param string $tag tag name of the element |
|
688 | - * @param array $attributes array of attributes for the element |
|
689 | - * @param string $text the text content for the element |
|
690 | - * @param bool $prepend prepend the header to the beginning of the list |
|
691 | - */ |
|
692 | - public static function addHeader($tag, $attributes, $text = null, $prepend = false) { |
|
693 | - $header = array( |
|
694 | - 'tag' => $tag, |
|
695 | - 'attributes' => $attributes, |
|
696 | - 'text' => $text |
|
697 | - ); |
|
698 | - if ($prepend === true) { |
|
699 | - array_unshift (self::$headers, $header); |
|
700 | - |
|
701 | - } else { |
|
702 | - self::$headers[] = $header; |
|
703 | - } |
|
704 | - } |
|
705 | - |
|
706 | - /** |
|
707 | - * check if the current server configuration is suitable for ownCloud |
|
708 | - * |
|
709 | - * @param \OC\SystemConfig $config |
|
710 | - * @return array arrays with error messages and hints |
|
711 | - */ |
|
712 | - public static function checkServer(\OC\SystemConfig $config) { |
|
713 | - $l = \OC::$server->getL10N('lib'); |
|
714 | - $errors = array(); |
|
715 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
716 | - |
|
717 | - if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
718 | - // this check needs to be done every time |
|
719 | - $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
720 | - } |
|
721 | - |
|
722 | - // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
723 | - if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
724 | - return $errors; |
|
725 | - } |
|
726 | - |
|
727 | - $webServerRestart = false; |
|
728 | - $setup = new \OC\Setup( |
|
729 | - $config, |
|
730 | - \OC::$server->getIniWrapper(), |
|
731 | - \OC::$server->getL10N('lib'), |
|
732 | - \OC::$server->query(\OCP\Defaults::class), |
|
733 | - \OC::$server->getLogger(), |
|
734 | - \OC::$server->getSecureRandom(), |
|
735 | - \OC::$server->query(\OC\Installer::class) |
|
736 | - ); |
|
737 | - |
|
738 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
739 | - |
|
740 | - $availableDatabases = $setup->getSupportedDatabases(); |
|
741 | - if (empty($availableDatabases)) { |
|
742 | - $errors[] = array( |
|
743 | - 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
744 | - 'hint' => '' //TODO: sane hint |
|
745 | - ); |
|
746 | - $webServerRestart = true; |
|
747 | - } |
|
748 | - |
|
749 | - // Check if config folder is writable. |
|
750 | - if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
751 | - if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
752 | - $errors[] = array( |
|
753 | - 'error' => $l->t('Cannot write into "config" directory'), |
|
754 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
755 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
756 | - . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
757 | - [ $urlGenerator->linkToDocs('admin-config') ] ) |
|
758 | - ); |
|
759 | - } |
|
760 | - } |
|
761 | - |
|
762 | - // Check if there is a writable install folder. |
|
763 | - if ($config->getValue('appstoreenabled', true)) { |
|
764 | - if (OC_App::getInstallPath() === null |
|
765 | - || !is_writable(OC_App::getInstallPath()) |
|
766 | - || !is_readable(OC_App::getInstallPath()) |
|
767 | - ) { |
|
768 | - $errors[] = array( |
|
769 | - 'error' => $l->t('Cannot write into "apps" directory'), |
|
770 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the apps directory' |
|
771 | - . ' or disabling the appstore in the config file. See %s', |
|
772 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
773 | - ); |
|
774 | - } |
|
775 | - } |
|
776 | - // Create root dir. |
|
777 | - if ($config->getValue('installed', false)) { |
|
778 | - if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
779 | - $success = @mkdir($CONFIG_DATADIRECTORY); |
|
780 | - if ($success) { |
|
781 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
782 | - } else { |
|
783 | - $errors[] = [ |
|
784 | - 'error' => $l->t('Cannot create "data" directory'), |
|
785 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the root directory. See %s', |
|
786 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
787 | - ]; |
|
788 | - } |
|
789 | - } else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
790 | - //common hint for all file permissions error messages |
|
791 | - $permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.', |
|
792 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]); |
|
793 | - $errors[] = [ |
|
794 | - 'error' => 'Your data directory is not writable', |
|
795 | - 'hint' => $permissionsHint |
|
796 | - ]; |
|
797 | - } else { |
|
798 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
799 | - } |
|
800 | - } |
|
801 | - |
|
802 | - if (!OC_Util::isSetLocaleWorking()) { |
|
803 | - $errors[] = array( |
|
804 | - 'error' => $l->t('Setting locale to %s failed', |
|
805 | - array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
806 | - . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')), |
|
807 | - 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
808 | - ); |
|
809 | - } |
|
810 | - |
|
811 | - // Contains the dependencies that should be checked against |
|
812 | - // classes = class_exists |
|
813 | - // functions = function_exists |
|
814 | - // defined = defined |
|
815 | - // ini = ini_get |
|
816 | - // If the dependency is not found the missing module name is shown to the EndUser |
|
817 | - // When adding new checks always verify that they pass on Travis as well |
|
818 | - // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
819 | - $dependencies = array( |
|
820 | - 'classes' => array( |
|
821 | - 'ZipArchive' => 'zip', |
|
822 | - 'DOMDocument' => 'dom', |
|
823 | - 'XMLWriter' => 'XMLWriter', |
|
824 | - 'XMLReader' => 'XMLReader', |
|
825 | - ), |
|
826 | - 'functions' => [ |
|
827 | - 'xml_parser_create' => 'libxml', |
|
828 | - 'mb_strcut' => 'mb multibyte', |
|
829 | - 'ctype_digit' => 'ctype', |
|
830 | - 'json_encode' => 'JSON', |
|
831 | - 'gd_info' => 'GD', |
|
832 | - 'gzencode' => 'zlib', |
|
833 | - 'iconv' => 'iconv', |
|
834 | - 'simplexml_load_string' => 'SimpleXML', |
|
835 | - 'hash' => 'HASH Message Digest Framework', |
|
836 | - 'curl_init' => 'cURL', |
|
837 | - 'openssl_verify' => 'OpenSSL', |
|
838 | - ], |
|
839 | - 'defined' => array( |
|
840 | - 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
841 | - ), |
|
842 | - 'ini' => [ |
|
843 | - 'default_charset' => 'UTF-8', |
|
844 | - ], |
|
845 | - ); |
|
846 | - $missingDependencies = array(); |
|
847 | - $invalidIniSettings = []; |
|
848 | - $moduleHint = $l->t('Please ask your server administrator to install the module.'); |
|
849 | - |
|
850 | - /** |
|
851 | - * FIXME: The dependency check does not work properly on HHVM on the moment |
|
852 | - * and prevents installation. Once HHVM is more compatible with our |
|
853 | - * approach to check for these values we should re-enable those |
|
854 | - * checks. |
|
855 | - */ |
|
856 | - $iniWrapper = \OC::$server->getIniWrapper(); |
|
857 | - if (!self::runningOnHhvm()) { |
|
858 | - foreach ($dependencies['classes'] as $class => $module) { |
|
859 | - if (!class_exists($class)) { |
|
860 | - $missingDependencies[] = $module; |
|
861 | - } |
|
862 | - } |
|
863 | - foreach ($dependencies['functions'] as $function => $module) { |
|
864 | - if (!function_exists($function)) { |
|
865 | - $missingDependencies[] = $module; |
|
866 | - } |
|
867 | - } |
|
868 | - foreach ($dependencies['defined'] as $defined => $module) { |
|
869 | - if (!defined($defined)) { |
|
870 | - $missingDependencies[] = $module; |
|
871 | - } |
|
872 | - } |
|
873 | - foreach ($dependencies['ini'] as $setting => $expected) { |
|
874 | - if (is_bool($expected)) { |
|
875 | - if ($iniWrapper->getBool($setting) !== $expected) { |
|
876 | - $invalidIniSettings[] = [$setting, $expected]; |
|
877 | - } |
|
878 | - } |
|
879 | - if (is_int($expected)) { |
|
880 | - if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
881 | - $invalidIniSettings[] = [$setting, $expected]; |
|
882 | - } |
|
883 | - } |
|
884 | - if (is_string($expected)) { |
|
885 | - if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
886 | - $invalidIniSettings[] = [$setting, $expected]; |
|
887 | - } |
|
888 | - } |
|
889 | - } |
|
890 | - } |
|
891 | - |
|
892 | - foreach($missingDependencies as $missingDependency) { |
|
893 | - $errors[] = array( |
|
894 | - 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
|
895 | - 'hint' => $moduleHint |
|
896 | - ); |
|
897 | - $webServerRestart = true; |
|
898 | - } |
|
899 | - foreach($invalidIniSettings as $setting) { |
|
900 | - if(is_bool($setting[1])) { |
|
901 | - $setting[1] = $setting[1] ? 'on' : 'off'; |
|
902 | - } |
|
903 | - $errors[] = [ |
|
904 | - 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
905 | - 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
906 | - ]; |
|
907 | - $webServerRestart = true; |
|
908 | - } |
|
909 | - |
|
910 | - /** |
|
911 | - * The mbstring.func_overload check can only be performed if the mbstring |
|
912 | - * module is installed as it will return null if the checking setting is |
|
913 | - * not available and thus a check on the boolean value fails. |
|
914 | - * |
|
915 | - * TODO: Should probably be implemented in the above generic dependency |
|
916 | - * check somehow in the long-term. |
|
917 | - */ |
|
918 | - if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
919 | - $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
920 | - $errors[] = array( |
|
921 | - 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
922 | - 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
923 | - ); |
|
924 | - } |
|
925 | - |
|
926 | - if(function_exists('xml_parser_create') && |
|
927 | - LIBXML_LOADED_VERSION < 20700 ) { |
|
928 | - $version = LIBXML_LOADED_VERSION; |
|
929 | - $major = floor($version/10000); |
|
930 | - $version -= ($major * 10000); |
|
931 | - $minor = floor($version/100); |
|
932 | - $version -= ($minor * 100); |
|
933 | - $patch = $version; |
|
934 | - $errors[] = array( |
|
935 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
936 | - 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
937 | - ); |
|
938 | - } |
|
939 | - |
|
940 | - if (!self::isAnnotationsWorking()) { |
|
941 | - $errors[] = array( |
|
942 | - 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
943 | - 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
944 | - ); |
|
945 | - } |
|
946 | - |
|
947 | - if (!\OC::$CLI && $webServerRestart) { |
|
948 | - $errors[] = array( |
|
949 | - 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
950 | - 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
951 | - ); |
|
952 | - } |
|
953 | - |
|
954 | - $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
955 | - |
|
956 | - // Cache the result of this function |
|
957 | - \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
958 | - |
|
959 | - return $errors; |
|
960 | - } |
|
961 | - |
|
962 | - /** |
|
963 | - * Check the database version |
|
964 | - * |
|
965 | - * @return array errors array |
|
966 | - */ |
|
967 | - public static function checkDatabaseVersion() { |
|
968 | - $l = \OC::$server->getL10N('lib'); |
|
969 | - $errors = array(); |
|
970 | - $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
971 | - if ($dbType === 'pgsql') { |
|
972 | - // check PostgreSQL version |
|
973 | - try { |
|
974 | - $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
975 | - $data = $result->fetchRow(); |
|
976 | - if (isset($data['server_version'])) { |
|
977 | - $version = $data['server_version']; |
|
978 | - if (version_compare($version, '9.0.0', '<')) { |
|
979 | - $errors[] = array( |
|
980 | - 'error' => $l->t('PostgreSQL >= 9 required'), |
|
981 | - 'hint' => $l->t('Please upgrade your database version') |
|
982 | - ); |
|
983 | - } |
|
984 | - } |
|
985 | - } catch (\Doctrine\DBAL\DBALException $e) { |
|
986 | - $logger = \OC::$server->getLogger(); |
|
987 | - $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
988 | - $logger->logException($e); |
|
989 | - } |
|
990 | - } |
|
991 | - return $errors; |
|
992 | - } |
|
993 | - |
|
994 | - /** |
|
995 | - * Check for correct file permissions of data directory |
|
996 | - * |
|
997 | - * @param string $dataDirectory |
|
998 | - * @return array arrays with error messages and hints |
|
999 | - */ |
|
1000 | - public static function checkDataDirectoryPermissions($dataDirectory) { |
|
1001 | - if(\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) { |
|
1002 | - return []; |
|
1003 | - } |
|
1004 | - $l = \OC::$server->getL10N('lib'); |
|
1005 | - $errors = []; |
|
1006 | - $permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory' |
|
1007 | - . ' cannot be listed by other users.'); |
|
1008 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
1009 | - if (substr($perms, -1) !== '0') { |
|
1010 | - chmod($dataDirectory, 0770); |
|
1011 | - clearstatcache(); |
|
1012 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
1013 | - if ($perms[2] !== '0') { |
|
1014 | - $errors[] = [ |
|
1015 | - 'error' => $l->t('Your data directory is readable by other users'), |
|
1016 | - 'hint' => $permissionsModHint |
|
1017 | - ]; |
|
1018 | - } |
|
1019 | - } |
|
1020 | - return $errors; |
|
1021 | - } |
|
1022 | - |
|
1023 | - /** |
|
1024 | - * Check that the data directory exists and is valid by |
|
1025 | - * checking the existence of the ".ocdata" file. |
|
1026 | - * |
|
1027 | - * @param string $dataDirectory data directory path |
|
1028 | - * @return array errors found |
|
1029 | - */ |
|
1030 | - public static function checkDataDirectoryValidity($dataDirectory) { |
|
1031 | - $l = \OC::$server->getL10N('lib'); |
|
1032 | - $errors = []; |
|
1033 | - if ($dataDirectory[0] !== '/') { |
|
1034 | - $errors[] = [ |
|
1035 | - 'error' => $l->t('Your data directory must be an absolute path'), |
|
1036 | - 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
1037 | - ]; |
|
1038 | - } |
|
1039 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
1040 | - $errors[] = [ |
|
1041 | - 'error' => $l->t('Your data directory is invalid'), |
|
1042 | - 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
1043 | - ' in the root of the data directory.') |
|
1044 | - ]; |
|
1045 | - } |
|
1046 | - return $errors; |
|
1047 | - } |
|
1048 | - |
|
1049 | - /** |
|
1050 | - * Check if the user is logged in, redirects to home if not. With |
|
1051 | - * redirect URL parameter to the request URI. |
|
1052 | - * |
|
1053 | - * @return void |
|
1054 | - */ |
|
1055 | - public static function checkLoggedIn() { |
|
1056 | - // Check if we are a user |
|
1057 | - if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
1058 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
1059 | - 'core.login.showLoginForm', |
|
1060 | - [ |
|
1061 | - 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
1062 | - ] |
|
1063 | - ) |
|
1064 | - ); |
|
1065 | - exit(); |
|
1066 | - } |
|
1067 | - // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
1068 | - if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
1069 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
1070 | - exit(); |
|
1071 | - } |
|
1072 | - } |
|
1073 | - |
|
1074 | - /** |
|
1075 | - * Check if the user is a admin, redirects to home if not |
|
1076 | - * |
|
1077 | - * @return void |
|
1078 | - */ |
|
1079 | - public static function checkAdminUser() { |
|
1080 | - OC_Util::checkLoggedIn(); |
|
1081 | - if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
1082 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
1083 | - exit(); |
|
1084 | - } |
|
1085 | - } |
|
1086 | - |
|
1087 | - /** |
|
1088 | - * Check if the user is a subadmin, redirects to home if not |
|
1089 | - * |
|
1090 | - * @return null|boolean $groups where the current user is subadmin |
|
1091 | - */ |
|
1092 | - public static function checkSubAdminUser() { |
|
1093 | - OC_Util::checkLoggedIn(); |
|
1094 | - $userObject = \OC::$server->getUserSession()->getUser(); |
|
1095 | - $isSubAdmin = false; |
|
1096 | - if($userObject !== null) { |
|
1097 | - $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
1098 | - } |
|
1099 | - |
|
1100 | - if (!$isSubAdmin) { |
|
1101 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
1102 | - exit(); |
|
1103 | - } |
|
1104 | - return true; |
|
1105 | - } |
|
1106 | - |
|
1107 | - /** |
|
1108 | - * Returns the URL of the default page |
|
1109 | - * based on the system configuration and |
|
1110 | - * the apps visible for the current user |
|
1111 | - * |
|
1112 | - * @return string URL |
|
1113 | - * @suppress PhanDeprecatedFunction |
|
1114 | - */ |
|
1115 | - public static function getDefaultPageUrl() { |
|
1116 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
1117 | - // Deny the redirect if the URL contains a @ |
|
1118 | - // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
1119 | - if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
1120 | - $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
1121 | - } else { |
|
1122 | - $defaultPage = \OC::$server->getConfig()->getAppValue('core', 'defaultpage'); |
|
1123 | - if ($defaultPage) { |
|
1124 | - $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
1125 | - } else { |
|
1126 | - $appId = 'files'; |
|
1127 | - $config = \OC::$server->getConfig(); |
|
1128 | - $defaultApps = explode(',', $config->getSystemValue('defaultapp', 'files')); |
|
1129 | - // find the first app that is enabled for the current user |
|
1130 | - foreach ($defaultApps as $defaultApp) { |
|
1131 | - $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
1132 | - if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
1133 | - $appId = $defaultApp; |
|
1134 | - break; |
|
1135 | - } |
|
1136 | - } |
|
1137 | - |
|
1138 | - if($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
1139 | - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
1140 | - } else { |
|
1141 | - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
1142 | - } |
|
1143 | - } |
|
1144 | - } |
|
1145 | - return $location; |
|
1146 | - } |
|
1147 | - |
|
1148 | - /** |
|
1149 | - * Redirect to the user default page |
|
1150 | - * |
|
1151 | - * @return void |
|
1152 | - */ |
|
1153 | - public static function redirectToDefaultPage() { |
|
1154 | - $location = self::getDefaultPageUrl(); |
|
1155 | - header('Location: ' . $location); |
|
1156 | - exit(); |
|
1157 | - } |
|
1158 | - |
|
1159 | - /** |
|
1160 | - * get an id unique for this instance |
|
1161 | - * |
|
1162 | - * @return string |
|
1163 | - */ |
|
1164 | - public static function getInstanceId() { |
|
1165 | - $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
1166 | - if (is_null($id)) { |
|
1167 | - // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
1168 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
1169 | - \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
1170 | - } |
|
1171 | - return $id; |
|
1172 | - } |
|
1173 | - |
|
1174 | - /** |
|
1175 | - * Public function to sanitize HTML |
|
1176 | - * |
|
1177 | - * This function is used to sanitize HTML and should be applied on any |
|
1178 | - * string or array of strings before displaying it on a web page. |
|
1179 | - * |
|
1180 | - * @param string|array $value |
|
1181 | - * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
1182 | - */ |
|
1183 | - public static function sanitizeHTML($value) { |
|
1184 | - if (is_array($value)) { |
|
1185 | - $value = array_map(function($value) { |
|
1186 | - return self::sanitizeHTML($value); |
|
1187 | - }, $value); |
|
1188 | - } else { |
|
1189 | - // Specify encoding for PHP<5.4 |
|
1190 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
1191 | - } |
|
1192 | - return $value; |
|
1193 | - } |
|
1194 | - |
|
1195 | - /** |
|
1196 | - * Public function to encode url parameters |
|
1197 | - * |
|
1198 | - * This function is used to encode path to file before output. |
|
1199 | - * Encoding is done according to RFC 3986 with one exception: |
|
1200 | - * Character '/' is preserved as is. |
|
1201 | - * |
|
1202 | - * @param string $component part of URI to encode |
|
1203 | - * @return string |
|
1204 | - */ |
|
1205 | - public static function encodePath($component) { |
|
1206 | - $encoded = rawurlencode($component); |
|
1207 | - $encoded = str_replace('%2F', '/', $encoded); |
|
1208 | - return $encoded; |
|
1209 | - } |
|
1210 | - |
|
1211 | - |
|
1212 | - public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
1213 | - // php dev server does not support htaccess |
|
1214 | - if (php_sapi_name() === 'cli-server') { |
|
1215 | - return false; |
|
1216 | - } |
|
1217 | - |
|
1218 | - // testdata |
|
1219 | - $fileName = '/htaccesstest.txt'; |
|
1220 | - $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
1221 | - |
|
1222 | - // creating a test file |
|
1223 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
1224 | - |
|
1225 | - if (file_exists($testFile)) {// already running this test, possible recursive call |
|
1226 | - return false; |
|
1227 | - } |
|
1228 | - |
|
1229 | - $fp = @fopen($testFile, 'w'); |
|
1230 | - if (!$fp) { |
|
1231 | - throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
1232 | - 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
1233 | - } |
|
1234 | - fwrite($fp, $testContent); |
|
1235 | - fclose($fp); |
|
1236 | - |
|
1237 | - return $testContent; |
|
1238 | - } |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * Check if the .htaccess file is working |
|
1242 | - * @param \OCP\IConfig $config |
|
1243 | - * @return bool |
|
1244 | - * @throws Exception |
|
1245 | - * @throws \OC\HintException If the test file can't get written. |
|
1246 | - */ |
|
1247 | - public function isHtaccessWorking(\OCP\IConfig $config) { |
|
1248 | - |
|
1249 | - if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
1250 | - return true; |
|
1251 | - } |
|
1252 | - |
|
1253 | - $testContent = $this->createHtaccessTestFile($config); |
|
1254 | - if ($testContent === false) { |
|
1255 | - return false; |
|
1256 | - } |
|
1257 | - |
|
1258 | - $fileName = '/htaccesstest.txt'; |
|
1259 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
1260 | - |
|
1261 | - // accessing the file via http |
|
1262 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
1263 | - try { |
|
1264 | - $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
1265 | - } catch (\Exception $e) { |
|
1266 | - $content = false; |
|
1267 | - } |
|
1268 | - |
|
1269 | - // cleanup |
|
1270 | - @unlink($testFile); |
|
1271 | - |
|
1272 | - /* |
|
266 | + if ($mount->getOption('readonly', false)) { |
|
267 | + return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
268 | + 'storage' => $storage, |
|
269 | + 'mask' => \OCP\Constants::PERMISSION_ALL & ~( |
|
270 | + \OCP\Constants::PERMISSION_UPDATE | |
|
271 | + \OCP\Constants::PERMISSION_CREATE | |
|
272 | + \OCP\Constants::PERMISSION_DELETE |
|
273 | + ), |
|
274 | + ]); |
|
275 | + } |
|
276 | + return $storage; |
|
277 | + }); |
|
278 | + |
|
279 | + OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user)); |
|
280 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true); |
|
281 | + |
|
282 | + //check if we are using an object storage |
|
283 | + $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
284 | + $objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null); |
|
285 | + |
|
286 | + // use the same order as in ObjectHomeMountProvider |
|
287 | + if (isset($objectStoreMultibucket)) { |
|
288 | + self::initObjectStoreMultibucketRootFS($objectStoreMultibucket); |
|
289 | + } elseif (isset($objectStore)) { |
|
290 | + self::initObjectStoreRootFS($objectStore); |
|
291 | + } else { |
|
292 | + self::initLocalStorageRootFS(); |
|
293 | + } |
|
294 | + |
|
295 | + if ($user != '' && !\OC::$server->getUserManager()->userExists($user)) { |
|
296 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
297 | + return false; |
|
298 | + } |
|
299 | + |
|
300 | + //if we aren't logged in, there is no use to set up the filesystem |
|
301 | + if ($user != "") { |
|
302 | + |
|
303 | + $userDir = '/' . $user . '/files'; |
|
304 | + |
|
305 | + //jail the user into his "home" directory |
|
306 | + \OC\Files\Filesystem::init($user, $userDir); |
|
307 | + |
|
308 | + OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); |
|
309 | + } |
|
310 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
311 | + return true; |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * check if a password is required for each public link |
|
316 | + * |
|
317 | + * @return boolean |
|
318 | + * @suppress PhanDeprecatedFunction |
|
319 | + */ |
|
320 | + public static function isPublicLinkPasswordRequired() { |
|
321 | + $enforcePassword = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_links_password', 'no'); |
|
322 | + return $enforcePassword === 'yes'; |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * check if sharing is disabled for the current user |
|
327 | + * @param IConfig $config |
|
328 | + * @param IGroupManager $groupManager |
|
329 | + * @param IUser|null $user |
|
330 | + * @return bool |
|
331 | + */ |
|
332 | + public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
333 | + if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
334 | + $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
335 | + $excludedGroups = json_decode($groupsList); |
|
336 | + if (is_null($excludedGroups)) { |
|
337 | + $excludedGroups = explode(',', $groupsList); |
|
338 | + $newValue = json_encode($excludedGroups); |
|
339 | + $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
340 | + } |
|
341 | + $usersGroups = $groupManager->getUserGroupIds($user); |
|
342 | + if (!empty($usersGroups)) { |
|
343 | + $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
344 | + // if the user is only in groups which are disabled for sharing then |
|
345 | + // sharing is also disabled for the user |
|
346 | + if (empty($remainingGroups)) { |
|
347 | + return true; |
|
348 | + } |
|
349 | + } |
|
350 | + } |
|
351 | + return false; |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * check if share API enforces a default expire date |
|
356 | + * |
|
357 | + * @return boolean |
|
358 | + * @suppress PhanDeprecatedFunction |
|
359 | + */ |
|
360 | + public static function isDefaultExpireDateEnforced() { |
|
361 | + $isDefaultExpireDateEnabled = \OC::$server->getConfig()->getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
362 | + $enforceDefaultExpireDate = false; |
|
363 | + if ($isDefaultExpireDateEnabled === 'yes') { |
|
364 | + $value = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
365 | + $enforceDefaultExpireDate = $value === 'yes'; |
|
366 | + } |
|
367 | + |
|
368 | + return $enforceDefaultExpireDate; |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Get the quota of a user |
|
373 | + * |
|
374 | + * @param string $userId |
|
375 | + * @return float Quota bytes |
|
376 | + */ |
|
377 | + public static function getUserQuota($userId) { |
|
378 | + $user = \OC::$server->getUserManager()->get($userId); |
|
379 | + if (is_null($user)) { |
|
380 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
381 | + } |
|
382 | + $userQuota = $user->getQuota(); |
|
383 | + if($userQuota === 'none') { |
|
384 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
385 | + } |
|
386 | + return OC_Helper::computerFileSize($userQuota); |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * copies the skeleton to the users /files |
|
391 | + * |
|
392 | + * @param String $userId |
|
393 | + * @param \OCP\Files\Folder $userDirectory |
|
394 | + * @throws \RuntimeException |
|
395 | + * @suppress PhanDeprecatedFunction |
|
396 | + */ |
|
397 | + public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
398 | + |
|
399 | + $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
400 | + $userLang = \OC::$server->getL10NFactory()->findLanguage(); |
|
401 | + $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory); |
|
402 | + |
|
403 | + if (!file_exists($skeletonDirectory)) { |
|
404 | + $dialectStart = strpos($userLang, '_'); |
|
405 | + if ($dialectStart !== false) { |
|
406 | + $skeletonDirectory = str_replace('{lang}', substr($userLang, 0, $dialectStart), $plainSkeletonDirectory); |
|
407 | + } |
|
408 | + if ($dialectStart === false || !file_exists($skeletonDirectory)) { |
|
409 | + $skeletonDirectory = str_replace('{lang}', 'default', $plainSkeletonDirectory); |
|
410 | + } |
|
411 | + if (!file_exists($skeletonDirectory)) { |
|
412 | + $skeletonDirectory = ''; |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
417 | + |
|
418 | + if ($instanceId === null) { |
|
419 | + throw new \RuntimeException('no instance id!'); |
|
420 | + } |
|
421 | + $appdata = 'appdata_' . $instanceId; |
|
422 | + if ($userId === $appdata) { |
|
423 | + throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
424 | + } |
|
425 | + |
|
426 | + if (!empty($skeletonDirectory)) { |
|
427 | + \OCP\Util::writeLog( |
|
428 | + 'files_skeleton', |
|
429 | + 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), |
|
430 | + ILogger::DEBUG |
|
431 | + ); |
|
432 | + self::copyr($skeletonDirectory, $userDirectory); |
|
433 | + // update the file cache |
|
434 | + $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
435 | + } |
|
436 | + } |
|
437 | + |
|
438 | + /** |
|
439 | + * copies a directory recursively by using streams |
|
440 | + * |
|
441 | + * @param string $source |
|
442 | + * @param \OCP\Files\Folder $target |
|
443 | + * @return void |
|
444 | + */ |
|
445 | + public static function copyr($source, \OCP\Files\Folder $target) { |
|
446 | + $logger = \OC::$server->getLogger(); |
|
447 | + |
|
448 | + // Verify if folder exists |
|
449 | + $dir = opendir($source); |
|
450 | + if($dir === false) { |
|
451 | + $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
452 | + return; |
|
453 | + } |
|
454 | + |
|
455 | + // Copy the files |
|
456 | + while (false !== ($file = readdir($dir))) { |
|
457 | + if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
458 | + if (is_dir($source . '/' . $file)) { |
|
459 | + $child = $target->newFolder($file); |
|
460 | + self::copyr($source . '/' . $file, $child); |
|
461 | + } else { |
|
462 | + $child = $target->newFile($file); |
|
463 | + $sourceStream = fopen($source . '/' . $file, 'r'); |
|
464 | + if($sourceStream === false) { |
|
465 | + $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
466 | + closedir($dir); |
|
467 | + return; |
|
468 | + } |
|
469 | + stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
470 | + } |
|
471 | + } |
|
472 | + } |
|
473 | + closedir($dir); |
|
474 | + } |
|
475 | + |
|
476 | + /** |
|
477 | + * @return void |
|
478 | + * @suppress PhanUndeclaredMethod |
|
479 | + */ |
|
480 | + public static function tearDownFS() { |
|
481 | + \OC\Files\Filesystem::tearDown(); |
|
482 | + \OC::$server->getRootFolder()->clearCache(); |
|
483 | + self::$fsSetup = false; |
|
484 | + self::$rootMounted = false; |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * get the current installed version of ownCloud |
|
489 | + * |
|
490 | + * @return array |
|
491 | + */ |
|
492 | + public static function getVersion() { |
|
493 | + OC_Util::loadVersion(); |
|
494 | + return self::$versionCache['OC_Version']; |
|
495 | + } |
|
496 | + |
|
497 | + /** |
|
498 | + * get the current installed version string of ownCloud |
|
499 | + * |
|
500 | + * @return string |
|
501 | + */ |
|
502 | + public static function getVersionString() { |
|
503 | + OC_Util::loadVersion(); |
|
504 | + return self::$versionCache['OC_VersionString']; |
|
505 | + } |
|
506 | + |
|
507 | + /** |
|
508 | + * @deprecated the value is of no use anymore |
|
509 | + * @return string |
|
510 | + */ |
|
511 | + public static function getEditionString() { |
|
512 | + return ''; |
|
513 | + } |
|
514 | + |
|
515 | + /** |
|
516 | + * @description get the update channel of the current installed of ownCloud. |
|
517 | + * @return string |
|
518 | + */ |
|
519 | + public static function getChannel() { |
|
520 | + OC_Util::loadVersion(); |
|
521 | + return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * @description get the build number of the current installed of ownCloud. |
|
526 | + * @return string |
|
527 | + */ |
|
528 | + public static function getBuild() { |
|
529 | + OC_Util::loadVersion(); |
|
530 | + return self::$versionCache['OC_Build']; |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * @description load the version.php into the session as cache |
|
535 | + * @suppress PhanUndeclaredVariable |
|
536 | + */ |
|
537 | + private static function loadVersion() { |
|
538 | + if (self::$versionCache !== null) { |
|
539 | + return; |
|
540 | + } |
|
541 | + |
|
542 | + $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
543 | + require OC::$SERVERROOT . '/version.php'; |
|
544 | + /** @var $timestamp int */ |
|
545 | + self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
546 | + /** @var $OC_Version string */ |
|
547 | + self::$versionCache['OC_Version'] = $OC_Version; |
|
548 | + /** @var $OC_VersionString string */ |
|
549 | + self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
550 | + /** @var $OC_Build string */ |
|
551 | + self::$versionCache['OC_Build'] = $OC_Build; |
|
552 | + |
|
553 | + /** @var $OC_Channel string */ |
|
554 | + self::$versionCache['OC_Channel'] = $OC_Channel; |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
559 | + * |
|
560 | + * @param string $application application to get the files from |
|
561 | + * @param string $directory directory within this application (css, js, vendor, etc) |
|
562 | + * @param string $file the file inside of the above folder |
|
563 | + * @return string the path |
|
564 | + */ |
|
565 | + private static function generatePath($application, $directory, $file) { |
|
566 | + if (is_null($file)) { |
|
567 | + $file = $application; |
|
568 | + $application = ""; |
|
569 | + } |
|
570 | + if (!empty($application)) { |
|
571 | + return "$application/$directory/$file"; |
|
572 | + } else { |
|
573 | + return "$directory/$file"; |
|
574 | + } |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * add a javascript file |
|
579 | + * |
|
580 | + * @param string $application application id |
|
581 | + * @param string|null $file filename |
|
582 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
583 | + * @return void |
|
584 | + */ |
|
585 | + public static function addScript($application, $file = null, $prepend = false) { |
|
586 | + $path = OC_Util::generatePath($application, 'js', $file); |
|
587 | + |
|
588 | + // core js files need separate handling |
|
589 | + if ($application !== 'core' && $file !== null) { |
|
590 | + self::addTranslations ( $application ); |
|
591 | + } |
|
592 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * add a javascript file from the vendor sub folder |
|
597 | + * |
|
598 | + * @param string $application application id |
|
599 | + * @param string|null $file filename |
|
600 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
601 | + * @return void |
|
602 | + */ |
|
603 | + public static function addVendorScript($application, $file = null, $prepend = false) { |
|
604 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
605 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * add a translation JS file |
|
610 | + * |
|
611 | + * @param string $application application id |
|
612 | + * @param string|null $languageCode language code, defaults to the current language |
|
613 | + * @param bool|null $prepend prepend the Script to the beginning of the list |
|
614 | + */ |
|
615 | + public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
616 | + if (is_null($languageCode)) { |
|
617 | + $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
618 | + } |
|
619 | + if (!empty($application)) { |
|
620 | + $path = "$application/l10n/$languageCode"; |
|
621 | + } else { |
|
622 | + $path = "l10n/$languageCode"; |
|
623 | + } |
|
624 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
625 | + } |
|
626 | + |
|
627 | + /** |
|
628 | + * add a css file |
|
629 | + * |
|
630 | + * @param string $application application id |
|
631 | + * @param string|null $file filename |
|
632 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
633 | + * @return void |
|
634 | + */ |
|
635 | + public static function addStyle($application, $file = null, $prepend = false) { |
|
636 | + $path = OC_Util::generatePath($application, 'css', $file); |
|
637 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
638 | + } |
|
639 | + |
|
640 | + /** |
|
641 | + * add a css file from the vendor sub folder |
|
642 | + * |
|
643 | + * @param string $application application id |
|
644 | + * @param string|null $file filename |
|
645 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
646 | + * @return void |
|
647 | + */ |
|
648 | + public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
649 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
650 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
651 | + } |
|
652 | + |
|
653 | + /** |
|
654 | + * add an external resource css/js file |
|
655 | + * |
|
656 | + * @param string $application application id |
|
657 | + * @param bool $prepend prepend the file to the beginning of the list |
|
658 | + * @param string $path |
|
659 | + * @param string $type (script or style) |
|
660 | + * @return void |
|
661 | + */ |
|
662 | + private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
663 | + |
|
664 | + if ($type === "style") { |
|
665 | + if (!in_array($path, self::$styles)) { |
|
666 | + if ($prepend === true) { |
|
667 | + array_unshift ( self::$styles, $path ); |
|
668 | + } else { |
|
669 | + self::$styles[] = $path; |
|
670 | + } |
|
671 | + } |
|
672 | + } elseif ($type === "script") { |
|
673 | + if (!in_array($path, self::$scripts)) { |
|
674 | + if ($prepend === true) { |
|
675 | + array_unshift ( self::$scripts, $path ); |
|
676 | + } else { |
|
677 | + self::$scripts [] = $path; |
|
678 | + } |
|
679 | + } |
|
680 | + } |
|
681 | + } |
|
682 | + |
|
683 | + /** |
|
684 | + * Add a custom element to the header |
|
685 | + * If $text is null then the element will be written as empty element. |
|
686 | + * So use "" to get a closing tag. |
|
687 | + * @param string $tag tag name of the element |
|
688 | + * @param array $attributes array of attributes for the element |
|
689 | + * @param string $text the text content for the element |
|
690 | + * @param bool $prepend prepend the header to the beginning of the list |
|
691 | + */ |
|
692 | + public static function addHeader($tag, $attributes, $text = null, $prepend = false) { |
|
693 | + $header = array( |
|
694 | + 'tag' => $tag, |
|
695 | + 'attributes' => $attributes, |
|
696 | + 'text' => $text |
|
697 | + ); |
|
698 | + if ($prepend === true) { |
|
699 | + array_unshift (self::$headers, $header); |
|
700 | + |
|
701 | + } else { |
|
702 | + self::$headers[] = $header; |
|
703 | + } |
|
704 | + } |
|
705 | + |
|
706 | + /** |
|
707 | + * check if the current server configuration is suitable for ownCloud |
|
708 | + * |
|
709 | + * @param \OC\SystemConfig $config |
|
710 | + * @return array arrays with error messages and hints |
|
711 | + */ |
|
712 | + public static function checkServer(\OC\SystemConfig $config) { |
|
713 | + $l = \OC::$server->getL10N('lib'); |
|
714 | + $errors = array(); |
|
715 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
716 | + |
|
717 | + if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
718 | + // this check needs to be done every time |
|
719 | + $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
720 | + } |
|
721 | + |
|
722 | + // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
723 | + if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
724 | + return $errors; |
|
725 | + } |
|
726 | + |
|
727 | + $webServerRestart = false; |
|
728 | + $setup = new \OC\Setup( |
|
729 | + $config, |
|
730 | + \OC::$server->getIniWrapper(), |
|
731 | + \OC::$server->getL10N('lib'), |
|
732 | + \OC::$server->query(\OCP\Defaults::class), |
|
733 | + \OC::$server->getLogger(), |
|
734 | + \OC::$server->getSecureRandom(), |
|
735 | + \OC::$server->query(\OC\Installer::class) |
|
736 | + ); |
|
737 | + |
|
738 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
739 | + |
|
740 | + $availableDatabases = $setup->getSupportedDatabases(); |
|
741 | + if (empty($availableDatabases)) { |
|
742 | + $errors[] = array( |
|
743 | + 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
744 | + 'hint' => '' //TODO: sane hint |
|
745 | + ); |
|
746 | + $webServerRestart = true; |
|
747 | + } |
|
748 | + |
|
749 | + // Check if config folder is writable. |
|
750 | + if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
751 | + if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
752 | + $errors[] = array( |
|
753 | + 'error' => $l->t('Cannot write into "config" directory'), |
|
754 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
755 | + [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
756 | + . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
757 | + [ $urlGenerator->linkToDocs('admin-config') ] ) |
|
758 | + ); |
|
759 | + } |
|
760 | + } |
|
761 | + |
|
762 | + // Check if there is a writable install folder. |
|
763 | + if ($config->getValue('appstoreenabled', true)) { |
|
764 | + if (OC_App::getInstallPath() === null |
|
765 | + || !is_writable(OC_App::getInstallPath()) |
|
766 | + || !is_readable(OC_App::getInstallPath()) |
|
767 | + ) { |
|
768 | + $errors[] = array( |
|
769 | + 'error' => $l->t('Cannot write into "apps" directory'), |
|
770 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the apps directory' |
|
771 | + . ' or disabling the appstore in the config file. See %s', |
|
772 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
773 | + ); |
|
774 | + } |
|
775 | + } |
|
776 | + // Create root dir. |
|
777 | + if ($config->getValue('installed', false)) { |
|
778 | + if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
779 | + $success = @mkdir($CONFIG_DATADIRECTORY); |
|
780 | + if ($success) { |
|
781 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
782 | + } else { |
|
783 | + $errors[] = [ |
|
784 | + 'error' => $l->t('Cannot create "data" directory'), |
|
785 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the root directory. See %s', |
|
786 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
787 | + ]; |
|
788 | + } |
|
789 | + } else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
790 | + //common hint for all file permissions error messages |
|
791 | + $permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.', |
|
792 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]); |
|
793 | + $errors[] = [ |
|
794 | + 'error' => 'Your data directory is not writable', |
|
795 | + 'hint' => $permissionsHint |
|
796 | + ]; |
|
797 | + } else { |
|
798 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
799 | + } |
|
800 | + } |
|
801 | + |
|
802 | + if (!OC_Util::isSetLocaleWorking()) { |
|
803 | + $errors[] = array( |
|
804 | + 'error' => $l->t('Setting locale to %s failed', |
|
805 | + array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
806 | + . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')), |
|
807 | + 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
808 | + ); |
|
809 | + } |
|
810 | + |
|
811 | + // Contains the dependencies that should be checked against |
|
812 | + // classes = class_exists |
|
813 | + // functions = function_exists |
|
814 | + // defined = defined |
|
815 | + // ini = ini_get |
|
816 | + // If the dependency is not found the missing module name is shown to the EndUser |
|
817 | + // When adding new checks always verify that they pass on Travis as well |
|
818 | + // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
819 | + $dependencies = array( |
|
820 | + 'classes' => array( |
|
821 | + 'ZipArchive' => 'zip', |
|
822 | + 'DOMDocument' => 'dom', |
|
823 | + 'XMLWriter' => 'XMLWriter', |
|
824 | + 'XMLReader' => 'XMLReader', |
|
825 | + ), |
|
826 | + 'functions' => [ |
|
827 | + 'xml_parser_create' => 'libxml', |
|
828 | + 'mb_strcut' => 'mb multibyte', |
|
829 | + 'ctype_digit' => 'ctype', |
|
830 | + 'json_encode' => 'JSON', |
|
831 | + 'gd_info' => 'GD', |
|
832 | + 'gzencode' => 'zlib', |
|
833 | + 'iconv' => 'iconv', |
|
834 | + 'simplexml_load_string' => 'SimpleXML', |
|
835 | + 'hash' => 'HASH Message Digest Framework', |
|
836 | + 'curl_init' => 'cURL', |
|
837 | + 'openssl_verify' => 'OpenSSL', |
|
838 | + ], |
|
839 | + 'defined' => array( |
|
840 | + 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
841 | + ), |
|
842 | + 'ini' => [ |
|
843 | + 'default_charset' => 'UTF-8', |
|
844 | + ], |
|
845 | + ); |
|
846 | + $missingDependencies = array(); |
|
847 | + $invalidIniSettings = []; |
|
848 | + $moduleHint = $l->t('Please ask your server administrator to install the module.'); |
|
849 | + |
|
850 | + /** |
|
851 | + * FIXME: The dependency check does not work properly on HHVM on the moment |
|
852 | + * and prevents installation. Once HHVM is more compatible with our |
|
853 | + * approach to check for these values we should re-enable those |
|
854 | + * checks. |
|
855 | + */ |
|
856 | + $iniWrapper = \OC::$server->getIniWrapper(); |
|
857 | + if (!self::runningOnHhvm()) { |
|
858 | + foreach ($dependencies['classes'] as $class => $module) { |
|
859 | + if (!class_exists($class)) { |
|
860 | + $missingDependencies[] = $module; |
|
861 | + } |
|
862 | + } |
|
863 | + foreach ($dependencies['functions'] as $function => $module) { |
|
864 | + if (!function_exists($function)) { |
|
865 | + $missingDependencies[] = $module; |
|
866 | + } |
|
867 | + } |
|
868 | + foreach ($dependencies['defined'] as $defined => $module) { |
|
869 | + if (!defined($defined)) { |
|
870 | + $missingDependencies[] = $module; |
|
871 | + } |
|
872 | + } |
|
873 | + foreach ($dependencies['ini'] as $setting => $expected) { |
|
874 | + if (is_bool($expected)) { |
|
875 | + if ($iniWrapper->getBool($setting) !== $expected) { |
|
876 | + $invalidIniSettings[] = [$setting, $expected]; |
|
877 | + } |
|
878 | + } |
|
879 | + if (is_int($expected)) { |
|
880 | + if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
881 | + $invalidIniSettings[] = [$setting, $expected]; |
|
882 | + } |
|
883 | + } |
|
884 | + if (is_string($expected)) { |
|
885 | + if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
886 | + $invalidIniSettings[] = [$setting, $expected]; |
|
887 | + } |
|
888 | + } |
|
889 | + } |
|
890 | + } |
|
891 | + |
|
892 | + foreach($missingDependencies as $missingDependency) { |
|
893 | + $errors[] = array( |
|
894 | + 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
|
895 | + 'hint' => $moduleHint |
|
896 | + ); |
|
897 | + $webServerRestart = true; |
|
898 | + } |
|
899 | + foreach($invalidIniSettings as $setting) { |
|
900 | + if(is_bool($setting[1])) { |
|
901 | + $setting[1] = $setting[1] ? 'on' : 'off'; |
|
902 | + } |
|
903 | + $errors[] = [ |
|
904 | + 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
905 | + 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
906 | + ]; |
|
907 | + $webServerRestart = true; |
|
908 | + } |
|
909 | + |
|
910 | + /** |
|
911 | + * The mbstring.func_overload check can only be performed if the mbstring |
|
912 | + * module is installed as it will return null if the checking setting is |
|
913 | + * not available and thus a check on the boolean value fails. |
|
914 | + * |
|
915 | + * TODO: Should probably be implemented in the above generic dependency |
|
916 | + * check somehow in the long-term. |
|
917 | + */ |
|
918 | + if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
919 | + $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
920 | + $errors[] = array( |
|
921 | + 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
922 | + 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
923 | + ); |
|
924 | + } |
|
925 | + |
|
926 | + if(function_exists('xml_parser_create') && |
|
927 | + LIBXML_LOADED_VERSION < 20700 ) { |
|
928 | + $version = LIBXML_LOADED_VERSION; |
|
929 | + $major = floor($version/10000); |
|
930 | + $version -= ($major * 10000); |
|
931 | + $minor = floor($version/100); |
|
932 | + $version -= ($minor * 100); |
|
933 | + $patch = $version; |
|
934 | + $errors[] = array( |
|
935 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
936 | + 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
937 | + ); |
|
938 | + } |
|
939 | + |
|
940 | + if (!self::isAnnotationsWorking()) { |
|
941 | + $errors[] = array( |
|
942 | + 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
943 | + 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
944 | + ); |
|
945 | + } |
|
946 | + |
|
947 | + if (!\OC::$CLI && $webServerRestart) { |
|
948 | + $errors[] = array( |
|
949 | + 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
950 | + 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
951 | + ); |
|
952 | + } |
|
953 | + |
|
954 | + $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
955 | + |
|
956 | + // Cache the result of this function |
|
957 | + \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
958 | + |
|
959 | + return $errors; |
|
960 | + } |
|
961 | + |
|
962 | + /** |
|
963 | + * Check the database version |
|
964 | + * |
|
965 | + * @return array errors array |
|
966 | + */ |
|
967 | + public static function checkDatabaseVersion() { |
|
968 | + $l = \OC::$server->getL10N('lib'); |
|
969 | + $errors = array(); |
|
970 | + $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
971 | + if ($dbType === 'pgsql') { |
|
972 | + // check PostgreSQL version |
|
973 | + try { |
|
974 | + $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
975 | + $data = $result->fetchRow(); |
|
976 | + if (isset($data['server_version'])) { |
|
977 | + $version = $data['server_version']; |
|
978 | + if (version_compare($version, '9.0.0', '<')) { |
|
979 | + $errors[] = array( |
|
980 | + 'error' => $l->t('PostgreSQL >= 9 required'), |
|
981 | + 'hint' => $l->t('Please upgrade your database version') |
|
982 | + ); |
|
983 | + } |
|
984 | + } |
|
985 | + } catch (\Doctrine\DBAL\DBALException $e) { |
|
986 | + $logger = \OC::$server->getLogger(); |
|
987 | + $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
988 | + $logger->logException($e); |
|
989 | + } |
|
990 | + } |
|
991 | + return $errors; |
|
992 | + } |
|
993 | + |
|
994 | + /** |
|
995 | + * Check for correct file permissions of data directory |
|
996 | + * |
|
997 | + * @param string $dataDirectory |
|
998 | + * @return array arrays with error messages and hints |
|
999 | + */ |
|
1000 | + public static function checkDataDirectoryPermissions($dataDirectory) { |
|
1001 | + if(\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) { |
|
1002 | + return []; |
|
1003 | + } |
|
1004 | + $l = \OC::$server->getL10N('lib'); |
|
1005 | + $errors = []; |
|
1006 | + $permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory' |
|
1007 | + . ' cannot be listed by other users.'); |
|
1008 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
1009 | + if (substr($perms, -1) !== '0') { |
|
1010 | + chmod($dataDirectory, 0770); |
|
1011 | + clearstatcache(); |
|
1012 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
1013 | + if ($perms[2] !== '0') { |
|
1014 | + $errors[] = [ |
|
1015 | + 'error' => $l->t('Your data directory is readable by other users'), |
|
1016 | + 'hint' => $permissionsModHint |
|
1017 | + ]; |
|
1018 | + } |
|
1019 | + } |
|
1020 | + return $errors; |
|
1021 | + } |
|
1022 | + |
|
1023 | + /** |
|
1024 | + * Check that the data directory exists and is valid by |
|
1025 | + * checking the existence of the ".ocdata" file. |
|
1026 | + * |
|
1027 | + * @param string $dataDirectory data directory path |
|
1028 | + * @return array errors found |
|
1029 | + */ |
|
1030 | + public static function checkDataDirectoryValidity($dataDirectory) { |
|
1031 | + $l = \OC::$server->getL10N('lib'); |
|
1032 | + $errors = []; |
|
1033 | + if ($dataDirectory[0] !== '/') { |
|
1034 | + $errors[] = [ |
|
1035 | + 'error' => $l->t('Your data directory must be an absolute path'), |
|
1036 | + 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
1037 | + ]; |
|
1038 | + } |
|
1039 | + if (!file_exists($dataDirectory . '/.ocdata')) { |
|
1040 | + $errors[] = [ |
|
1041 | + 'error' => $l->t('Your data directory is invalid'), |
|
1042 | + 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
1043 | + ' in the root of the data directory.') |
|
1044 | + ]; |
|
1045 | + } |
|
1046 | + return $errors; |
|
1047 | + } |
|
1048 | + |
|
1049 | + /** |
|
1050 | + * Check if the user is logged in, redirects to home if not. With |
|
1051 | + * redirect URL parameter to the request URI. |
|
1052 | + * |
|
1053 | + * @return void |
|
1054 | + */ |
|
1055 | + public static function checkLoggedIn() { |
|
1056 | + // Check if we are a user |
|
1057 | + if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
1058 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
1059 | + 'core.login.showLoginForm', |
|
1060 | + [ |
|
1061 | + 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
1062 | + ] |
|
1063 | + ) |
|
1064 | + ); |
|
1065 | + exit(); |
|
1066 | + } |
|
1067 | + // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
1068 | + if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
1069 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
1070 | + exit(); |
|
1071 | + } |
|
1072 | + } |
|
1073 | + |
|
1074 | + /** |
|
1075 | + * Check if the user is a admin, redirects to home if not |
|
1076 | + * |
|
1077 | + * @return void |
|
1078 | + */ |
|
1079 | + public static function checkAdminUser() { |
|
1080 | + OC_Util::checkLoggedIn(); |
|
1081 | + if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
1082 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
1083 | + exit(); |
|
1084 | + } |
|
1085 | + } |
|
1086 | + |
|
1087 | + /** |
|
1088 | + * Check if the user is a subadmin, redirects to home if not |
|
1089 | + * |
|
1090 | + * @return null|boolean $groups where the current user is subadmin |
|
1091 | + */ |
|
1092 | + public static function checkSubAdminUser() { |
|
1093 | + OC_Util::checkLoggedIn(); |
|
1094 | + $userObject = \OC::$server->getUserSession()->getUser(); |
|
1095 | + $isSubAdmin = false; |
|
1096 | + if($userObject !== null) { |
|
1097 | + $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
1098 | + } |
|
1099 | + |
|
1100 | + if (!$isSubAdmin) { |
|
1101 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
1102 | + exit(); |
|
1103 | + } |
|
1104 | + return true; |
|
1105 | + } |
|
1106 | + |
|
1107 | + /** |
|
1108 | + * Returns the URL of the default page |
|
1109 | + * based on the system configuration and |
|
1110 | + * the apps visible for the current user |
|
1111 | + * |
|
1112 | + * @return string URL |
|
1113 | + * @suppress PhanDeprecatedFunction |
|
1114 | + */ |
|
1115 | + public static function getDefaultPageUrl() { |
|
1116 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
1117 | + // Deny the redirect if the URL contains a @ |
|
1118 | + // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
1119 | + if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
1120 | + $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
1121 | + } else { |
|
1122 | + $defaultPage = \OC::$server->getConfig()->getAppValue('core', 'defaultpage'); |
|
1123 | + if ($defaultPage) { |
|
1124 | + $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
1125 | + } else { |
|
1126 | + $appId = 'files'; |
|
1127 | + $config = \OC::$server->getConfig(); |
|
1128 | + $defaultApps = explode(',', $config->getSystemValue('defaultapp', 'files')); |
|
1129 | + // find the first app that is enabled for the current user |
|
1130 | + foreach ($defaultApps as $defaultApp) { |
|
1131 | + $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
1132 | + if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
1133 | + $appId = $defaultApp; |
|
1134 | + break; |
|
1135 | + } |
|
1136 | + } |
|
1137 | + |
|
1138 | + if($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
1139 | + $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
1140 | + } else { |
|
1141 | + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
1142 | + } |
|
1143 | + } |
|
1144 | + } |
|
1145 | + return $location; |
|
1146 | + } |
|
1147 | + |
|
1148 | + /** |
|
1149 | + * Redirect to the user default page |
|
1150 | + * |
|
1151 | + * @return void |
|
1152 | + */ |
|
1153 | + public static function redirectToDefaultPage() { |
|
1154 | + $location = self::getDefaultPageUrl(); |
|
1155 | + header('Location: ' . $location); |
|
1156 | + exit(); |
|
1157 | + } |
|
1158 | + |
|
1159 | + /** |
|
1160 | + * get an id unique for this instance |
|
1161 | + * |
|
1162 | + * @return string |
|
1163 | + */ |
|
1164 | + public static function getInstanceId() { |
|
1165 | + $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
1166 | + if (is_null($id)) { |
|
1167 | + // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
1168 | + $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
1169 | + \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
1170 | + } |
|
1171 | + return $id; |
|
1172 | + } |
|
1173 | + |
|
1174 | + /** |
|
1175 | + * Public function to sanitize HTML |
|
1176 | + * |
|
1177 | + * This function is used to sanitize HTML and should be applied on any |
|
1178 | + * string or array of strings before displaying it on a web page. |
|
1179 | + * |
|
1180 | + * @param string|array $value |
|
1181 | + * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
1182 | + */ |
|
1183 | + public static function sanitizeHTML($value) { |
|
1184 | + if (is_array($value)) { |
|
1185 | + $value = array_map(function($value) { |
|
1186 | + return self::sanitizeHTML($value); |
|
1187 | + }, $value); |
|
1188 | + } else { |
|
1189 | + // Specify encoding for PHP<5.4 |
|
1190 | + $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
1191 | + } |
|
1192 | + return $value; |
|
1193 | + } |
|
1194 | + |
|
1195 | + /** |
|
1196 | + * Public function to encode url parameters |
|
1197 | + * |
|
1198 | + * This function is used to encode path to file before output. |
|
1199 | + * Encoding is done according to RFC 3986 with one exception: |
|
1200 | + * Character '/' is preserved as is. |
|
1201 | + * |
|
1202 | + * @param string $component part of URI to encode |
|
1203 | + * @return string |
|
1204 | + */ |
|
1205 | + public static function encodePath($component) { |
|
1206 | + $encoded = rawurlencode($component); |
|
1207 | + $encoded = str_replace('%2F', '/', $encoded); |
|
1208 | + return $encoded; |
|
1209 | + } |
|
1210 | + |
|
1211 | + |
|
1212 | + public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
1213 | + // php dev server does not support htaccess |
|
1214 | + if (php_sapi_name() === 'cli-server') { |
|
1215 | + return false; |
|
1216 | + } |
|
1217 | + |
|
1218 | + // testdata |
|
1219 | + $fileName = '/htaccesstest.txt'; |
|
1220 | + $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
1221 | + |
|
1222 | + // creating a test file |
|
1223 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
1224 | + |
|
1225 | + if (file_exists($testFile)) {// already running this test, possible recursive call |
|
1226 | + return false; |
|
1227 | + } |
|
1228 | + |
|
1229 | + $fp = @fopen($testFile, 'w'); |
|
1230 | + if (!$fp) { |
|
1231 | + throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
1232 | + 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
1233 | + } |
|
1234 | + fwrite($fp, $testContent); |
|
1235 | + fclose($fp); |
|
1236 | + |
|
1237 | + return $testContent; |
|
1238 | + } |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * Check if the .htaccess file is working |
|
1242 | + * @param \OCP\IConfig $config |
|
1243 | + * @return bool |
|
1244 | + * @throws Exception |
|
1245 | + * @throws \OC\HintException If the test file can't get written. |
|
1246 | + */ |
|
1247 | + public function isHtaccessWorking(\OCP\IConfig $config) { |
|
1248 | + |
|
1249 | + if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
1250 | + return true; |
|
1251 | + } |
|
1252 | + |
|
1253 | + $testContent = $this->createHtaccessTestFile($config); |
|
1254 | + if ($testContent === false) { |
|
1255 | + return false; |
|
1256 | + } |
|
1257 | + |
|
1258 | + $fileName = '/htaccesstest.txt'; |
|
1259 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
1260 | + |
|
1261 | + // accessing the file via http |
|
1262 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
1263 | + try { |
|
1264 | + $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
1265 | + } catch (\Exception $e) { |
|
1266 | + $content = false; |
|
1267 | + } |
|
1268 | + |
|
1269 | + // cleanup |
|
1270 | + @unlink($testFile); |
|
1271 | + |
|
1272 | + /* |
|
1273 | 1273 | * If the content is not equal to test content our .htaccess |
1274 | 1274 | * is working as required |
1275 | 1275 | */ |
1276 | - return $content !== $testContent; |
|
1277 | - } |
|
1278 | - |
|
1279 | - /** |
|
1280 | - * Check if the setlocal call does not work. This can happen if the right |
|
1281 | - * local packages are not available on the server. |
|
1282 | - * |
|
1283 | - * @return bool |
|
1284 | - */ |
|
1285 | - public static function isSetLocaleWorking() { |
|
1286 | - \Patchwork\Utf8\Bootup::initLocale(); |
|
1287 | - if ('' === basename('§')) { |
|
1288 | - return false; |
|
1289 | - } |
|
1290 | - return true; |
|
1291 | - } |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * Check if it's possible to get the inline annotations |
|
1295 | - * |
|
1296 | - * @return bool |
|
1297 | - */ |
|
1298 | - public static function isAnnotationsWorking() { |
|
1299 | - $reflection = new \ReflectionMethod(__METHOD__); |
|
1300 | - $docs = $reflection->getDocComment(); |
|
1301 | - |
|
1302 | - return (is_string($docs) && strlen($docs) > 50); |
|
1303 | - } |
|
1304 | - |
|
1305 | - /** |
|
1306 | - * Check if the PHP module fileinfo is loaded. |
|
1307 | - * |
|
1308 | - * @return bool |
|
1309 | - */ |
|
1310 | - public static function fileInfoLoaded() { |
|
1311 | - return function_exists('finfo_open'); |
|
1312 | - } |
|
1313 | - |
|
1314 | - /** |
|
1315 | - * clear all levels of output buffering |
|
1316 | - * |
|
1317 | - * @return void |
|
1318 | - */ |
|
1319 | - public static function obEnd() { |
|
1320 | - while (ob_get_level()) { |
|
1321 | - ob_end_clean(); |
|
1322 | - } |
|
1323 | - } |
|
1324 | - |
|
1325 | - /** |
|
1326 | - * Checks whether the server is running on Mac OS X |
|
1327 | - * |
|
1328 | - * @return bool true if running on Mac OS X, false otherwise |
|
1329 | - */ |
|
1330 | - public static function runningOnMac() { |
|
1331 | - return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
1332 | - } |
|
1333 | - |
|
1334 | - /** |
|
1335 | - * Checks whether server is running on HHVM |
|
1336 | - * |
|
1337 | - * @return bool True if running on HHVM, false otherwise |
|
1338 | - */ |
|
1339 | - public static function runningOnHhvm() { |
|
1340 | - return defined('HHVM_VERSION'); |
|
1341 | - } |
|
1342 | - |
|
1343 | - /** |
|
1344 | - * Handles the case that there may not be a theme, then check if a "default" |
|
1345 | - * theme exists and take that one |
|
1346 | - * |
|
1347 | - * @return string the theme |
|
1348 | - */ |
|
1349 | - public static function getTheme() { |
|
1350 | - $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
1351 | - |
|
1352 | - if ($theme === '') { |
|
1353 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
1354 | - $theme = 'default'; |
|
1355 | - } |
|
1356 | - } |
|
1357 | - |
|
1358 | - return $theme; |
|
1359 | - } |
|
1360 | - |
|
1361 | - /** |
|
1362 | - * Clear a single file from the opcode cache |
|
1363 | - * This is useful for writing to the config file |
|
1364 | - * in case the opcode cache does not re-validate files |
|
1365 | - * Returns true if successful, false if unsuccessful: |
|
1366 | - * caller should fall back on clearing the entire cache |
|
1367 | - * with clearOpcodeCache() if unsuccessful |
|
1368 | - * |
|
1369 | - * @param string $path the path of the file to clear from the cache |
|
1370 | - * @return bool true if underlying function returns true, otherwise false |
|
1371 | - */ |
|
1372 | - public static function deleteFromOpcodeCache($path) { |
|
1373 | - $ret = false; |
|
1374 | - if ($path) { |
|
1375 | - // APC >= 3.1.1 |
|
1376 | - if (function_exists('apc_delete_file')) { |
|
1377 | - $ret = @apc_delete_file($path); |
|
1378 | - } |
|
1379 | - // Zend OpCache >= 7.0.0, PHP >= 5.5.0 |
|
1380 | - if (function_exists('opcache_invalidate')) { |
|
1381 | - $ret = opcache_invalidate($path); |
|
1382 | - } |
|
1383 | - } |
|
1384 | - return $ret; |
|
1385 | - } |
|
1386 | - |
|
1387 | - /** |
|
1388 | - * Clear the opcode cache if one exists |
|
1389 | - * This is necessary for writing to the config file |
|
1390 | - * in case the opcode cache does not re-validate files |
|
1391 | - * |
|
1392 | - * @return void |
|
1393 | - * @suppress PhanDeprecatedFunction |
|
1394 | - * @suppress PhanUndeclaredConstant |
|
1395 | - */ |
|
1396 | - public static function clearOpcodeCache() { |
|
1397 | - // APC |
|
1398 | - if (function_exists('apc_clear_cache')) { |
|
1399 | - apc_clear_cache(); |
|
1400 | - } |
|
1401 | - // Zend Opcache |
|
1402 | - if (function_exists('accelerator_reset')) { |
|
1403 | - accelerator_reset(); |
|
1404 | - } |
|
1405 | - // XCache |
|
1406 | - if (function_exists('xcache_clear_cache')) { |
|
1407 | - if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
1408 | - \OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', ILogger::WARN); |
|
1409 | - } else { |
|
1410 | - @xcache_clear_cache(XC_TYPE_PHP, 0); |
|
1411 | - } |
|
1412 | - } |
|
1413 | - // Opcache (PHP >= 5.5) |
|
1414 | - if (function_exists('opcache_reset')) { |
|
1415 | - opcache_reset(); |
|
1416 | - } |
|
1417 | - } |
|
1418 | - |
|
1419 | - /** |
|
1420 | - * Normalize a unicode string |
|
1421 | - * |
|
1422 | - * @param string $value a not normalized string |
|
1423 | - * @return bool|string |
|
1424 | - */ |
|
1425 | - public static function normalizeUnicode($value) { |
|
1426 | - if(Normalizer::isNormalized($value)) { |
|
1427 | - return $value; |
|
1428 | - } |
|
1429 | - |
|
1430 | - $normalizedValue = Normalizer::normalize($value); |
|
1431 | - if ($normalizedValue === null || $normalizedValue === false) { |
|
1432 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
1433 | - return $value; |
|
1434 | - } |
|
1435 | - |
|
1436 | - return $normalizedValue; |
|
1437 | - } |
|
1438 | - |
|
1439 | - /** |
|
1440 | - * A human readable string is generated based on version and build number |
|
1441 | - * |
|
1442 | - * @return string |
|
1443 | - */ |
|
1444 | - public static function getHumanVersion() { |
|
1445 | - $version = OC_Util::getVersionString(); |
|
1446 | - $build = OC_Util::getBuild(); |
|
1447 | - if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
1448 | - $version .= ' Build:' . $build; |
|
1449 | - } |
|
1450 | - return $version; |
|
1451 | - } |
|
1452 | - |
|
1453 | - /** |
|
1454 | - * Returns whether the given file name is valid |
|
1455 | - * |
|
1456 | - * @param string $file file name to check |
|
1457 | - * @return bool true if the file name is valid, false otherwise |
|
1458 | - * @deprecated use \OC\Files\View::verifyPath() |
|
1459 | - */ |
|
1460 | - public static function isValidFileName($file) { |
|
1461 | - $trimmed = trim($file); |
|
1462 | - if ($trimmed === '') { |
|
1463 | - return false; |
|
1464 | - } |
|
1465 | - if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
1466 | - return false; |
|
1467 | - } |
|
1468 | - |
|
1469 | - // detect part files |
|
1470 | - if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
1471 | - return false; |
|
1472 | - } |
|
1473 | - |
|
1474 | - foreach (str_split($trimmed) as $char) { |
|
1475 | - if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
1476 | - return false; |
|
1477 | - } |
|
1478 | - } |
|
1479 | - return true; |
|
1480 | - } |
|
1481 | - |
|
1482 | - /** |
|
1483 | - * Check whether the instance needs to perform an upgrade, |
|
1484 | - * either when the core version is higher or any app requires |
|
1485 | - * an upgrade. |
|
1486 | - * |
|
1487 | - * @param \OC\SystemConfig $config |
|
1488 | - * @return bool whether the core or any app needs an upgrade |
|
1489 | - * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
1490 | - */ |
|
1491 | - public static function needUpgrade(\OC\SystemConfig $config) { |
|
1492 | - if ($config->getValue('installed', false)) { |
|
1493 | - $installedVersion = $config->getValue('version', '0.0.0'); |
|
1494 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
1495 | - $versionDiff = version_compare($currentVersion, $installedVersion); |
|
1496 | - if ($versionDiff > 0) { |
|
1497 | - return true; |
|
1498 | - } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
|
1499 | - // downgrade with debug |
|
1500 | - $installedMajor = explode('.', $installedVersion); |
|
1501 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
1502 | - $currentMajor = explode('.', $currentVersion); |
|
1503 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
1504 | - if ($installedMajor === $currentMajor) { |
|
1505 | - // Same major, allow downgrade for developers |
|
1506 | - return true; |
|
1507 | - } else { |
|
1508 | - // downgrade attempt, throw exception |
|
1509 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
1510 | - } |
|
1511 | - } else if ($versionDiff < 0) { |
|
1512 | - // downgrade attempt, throw exception |
|
1513 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
1514 | - } |
|
1515 | - |
|
1516 | - // also check for upgrades for apps (independently from the user) |
|
1517 | - $apps = \OC_App::getEnabledApps(false, true); |
|
1518 | - $shouldUpgrade = false; |
|
1519 | - foreach ($apps as $app) { |
|
1520 | - if (\OC_App::shouldUpgrade($app)) { |
|
1521 | - $shouldUpgrade = true; |
|
1522 | - break; |
|
1523 | - } |
|
1524 | - } |
|
1525 | - return $shouldUpgrade; |
|
1526 | - } else { |
|
1527 | - return false; |
|
1528 | - } |
|
1529 | - } |
|
1276 | + return $content !== $testContent; |
|
1277 | + } |
|
1278 | + |
|
1279 | + /** |
|
1280 | + * Check if the setlocal call does not work. This can happen if the right |
|
1281 | + * local packages are not available on the server. |
|
1282 | + * |
|
1283 | + * @return bool |
|
1284 | + */ |
|
1285 | + public static function isSetLocaleWorking() { |
|
1286 | + \Patchwork\Utf8\Bootup::initLocale(); |
|
1287 | + if ('' === basename('§')) { |
|
1288 | + return false; |
|
1289 | + } |
|
1290 | + return true; |
|
1291 | + } |
|
1292 | + |
|
1293 | + /** |
|
1294 | + * Check if it's possible to get the inline annotations |
|
1295 | + * |
|
1296 | + * @return bool |
|
1297 | + */ |
|
1298 | + public static function isAnnotationsWorking() { |
|
1299 | + $reflection = new \ReflectionMethod(__METHOD__); |
|
1300 | + $docs = $reflection->getDocComment(); |
|
1301 | + |
|
1302 | + return (is_string($docs) && strlen($docs) > 50); |
|
1303 | + } |
|
1304 | + |
|
1305 | + /** |
|
1306 | + * Check if the PHP module fileinfo is loaded. |
|
1307 | + * |
|
1308 | + * @return bool |
|
1309 | + */ |
|
1310 | + public static function fileInfoLoaded() { |
|
1311 | + return function_exists('finfo_open'); |
|
1312 | + } |
|
1313 | + |
|
1314 | + /** |
|
1315 | + * clear all levels of output buffering |
|
1316 | + * |
|
1317 | + * @return void |
|
1318 | + */ |
|
1319 | + public static function obEnd() { |
|
1320 | + while (ob_get_level()) { |
|
1321 | + ob_end_clean(); |
|
1322 | + } |
|
1323 | + } |
|
1324 | + |
|
1325 | + /** |
|
1326 | + * Checks whether the server is running on Mac OS X |
|
1327 | + * |
|
1328 | + * @return bool true if running on Mac OS X, false otherwise |
|
1329 | + */ |
|
1330 | + public static function runningOnMac() { |
|
1331 | + return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
1332 | + } |
|
1333 | + |
|
1334 | + /** |
|
1335 | + * Checks whether server is running on HHVM |
|
1336 | + * |
|
1337 | + * @return bool True if running on HHVM, false otherwise |
|
1338 | + */ |
|
1339 | + public static function runningOnHhvm() { |
|
1340 | + return defined('HHVM_VERSION'); |
|
1341 | + } |
|
1342 | + |
|
1343 | + /** |
|
1344 | + * Handles the case that there may not be a theme, then check if a "default" |
|
1345 | + * theme exists and take that one |
|
1346 | + * |
|
1347 | + * @return string the theme |
|
1348 | + */ |
|
1349 | + public static function getTheme() { |
|
1350 | + $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
1351 | + |
|
1352 | + if ($theme === '') { |
|
1353 | + if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
1354 | + $theme = 'default'; |
|
1355 | + } |
|
1356 | + } |
|
1357 | + |
|
1358 | + return $theme; |
|
1359 | + } |
|
1360 | + |
|
1361 | + /** |
|
1362 | + * Clear a single file from the opcode cache |
|
1363 | + * This is useful for writing to the config file |
|
1364 | + * in case the opcode cache does not re-validate files |
|
1365 | + * Returns true if successful, false if unsuccessful: |
|
1366 | + * caller should fall back on clearing the entire cache |
|
1367 | + * with clearOpcodeCache() if unsuccessful |
|
1368 | + * |
|
1369 | + * @param string $path the path of the file to clear from the cache |
|
1370 | + * @return bool true if underlying function returns true, otherwise false |
|
1371 | + */ |
|
1372 | + public static function deleteFromOpcodeCache($path) { |
|
1373 | + $ret = false; |
|
1374 | + if ($path) { |
|
1375 | + // APC >= 3.1.1 |
|
1376 | + if (function_exists('apc_delete_file')) { |
|
1377 | + $ret = @apc_delete_file($path); |
|
1378 | + } |
|
1379 | + // Zend OpCache >= 7.0.0, PHP >= 5.5.0 |
|
1380 | + if (function_exists('opcache_invalidate')) { |
|
1381 | + $ret = opcache_invalidate($path); |
|
1382 | + } |
|
1383 | + } |
|
1384 | + return $ret; |
|
1385 | + } |
|
1386 | + |
|
1387 | + /** |
|
1388 | + * Clear the opcode cache if one exists |
|
1389 | + * This is necessary for writing to the config file |
|
1390 | + * in case the opcode cache does not re-validate files |
|
1391 | + * |
|
1392 | + * @return void |
|
1393 | + * @suppress PhanDeprecatedFunction |
|
1394 | + * @suppress PhanUndeclaredConstant |
|
1395 | + */ |
|
1396 | + public static function clearOpcodeCache() { |
|
1397 | + // APC |
|
1398 | + if (function_exists('apc_clear_cache')) { |
|
1399 | + apc_clear_cache(); |
|
1400 | + } |
|
1401 | + // Zend Opcache |
|
1402 | + if (function_exists('accelerator_reset')) { |
|
1403 | + accelerator_reset(); |
|
1404 | + } |
|
1405 | + // XCache |
|
1406 | + if (function_exists('xcache_clear_cache')) { |
|
1407 | + if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
1408 | + \OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', ILogger::WARN); |
|
1409 | + } else { |
|
1410 | + @xcache_clear_cache(XC_TYPE_PHP, 0); |
|
1411 | + } |
|
1412 | + } |
|
1413 | + // Opcache (PHP >= 5.5) |
|
1414 | + if (function_exists('opcache_reset')) { |
|
1415 | + opcache_reset(); |
|
1416 | + } |
|
1417 | + } |
|
1418 | + |
|
1419 | + /** |
|
1420 | + * Normalize a unicode string |
|
1421 | + * |
|
1422 | + * @param string $value a not normalized string |
|
1423 | + * @return bool|string |
|
1424 | + */ |
|
1425 | + public static function normalizeUnicode($value) { |
|
1426 | + if(Normalizer::isNormalized($value)) { |
|
1427 | + return $value; |
|
1428 | + } |
|
1429 | + |
|
1430 | + $normalizedValue = Normalizer::normalize($value); |
|
1431 | + if ($normalizedValue === null || $normalizedValue === false) { |
|
1432 | + \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
1433 | + return $value; |
|
1434 | + } |
|
1435 | + |
|
1436 | + return $normalizedValue; |
|
1437 | + } |
|
1438 | + |
|
1439 | + /** |
|
1440 | + * A human readable string is generated based on version and build number |
|
1441 | + * |
|
1442 | + * @return string |
|
1443 | + */ |
|
1444 | + public static function getHumanVersion() { |
|
1445 | + $version = OC_Util::getVersionString(); |
|
1446 | + $build = OC_Util::getBuild(); |
|
1447 | + if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
1448 | + $version .= ' Build:' . $build; |
|
1449 | + } |
|
1450 | + return $version; |
|
1451 | + } |
|
1452 | + |
|
1453 | + /** |
|
1454 | + * Returns whether the given file name is valid |
|
1455 | + * |
|
1456 | + * @param string $file file name to check |
|
1457 | + * @return bool true if the file name is valid, false otherwise |
|
1458 | + * @deprecated use \OC\Files\View::verifyPath() |
|
1459 | + */ |
|
1460 | + public static function isValidFileName($file) { |
|
1461 | + $trimmed = trim($file); |
|
1462 | + if ($trimmed === '') { |
|
1463 | + return false; |
|
1464 | + } |
|
1465 | + if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
1466 | + return false; |
|
1467 | + } |
|
1468 | + |
|
1469 | + // detect part files |
|
1470 | + if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
1471 | + return false; |
|
1472 | + } |
|
1473 | + |
|
1474 | + foreach (str_split($trimmed) as $char) { |
|
1475 | + if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
1476 | + return false; |
|
1477 | + } |
|
1478 | + } |
|
1479 | + return true; |
|
1480 | + } |
|
1481 | + |
|
1482 | + /** |
|
1483 | + * Check whether the instance needs to perform an upgrade, |
|
1484 | + * either when the core version is higher or any app requires |
|
1485 | + * an upgrade. |
|
1486 | + * |
|
1487 | + * @param \OC\SystemConfig $config |
|
1488 | + * @return bool whether the core or any app needs an upgrade |
|
1489 | + * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
1490 | + */ |
|
1491 | + public static function needUpgrade(\OC\SystemConfig $config) { |
|
1492 | + if ($config->getValue('installed', false)) { |
|
1493 | + $installedVersion = $config->getValue('version', '0.0.0'); |
|
1494 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
1495 | + $versionDiff = version_compare($currentVersion, $installedVersion); |
|
1496 | + if ($versionDiff > 0) { |
|
1497 | + return true; |
|
1498 | + } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
|
1499 | + // downgrade with debug |
|
1500 | + $installedMajor = explode('.', $installedVersion); |
|
1501 | + $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
1502 | + $currentMajor = explode('.', $currentVersion); |
|
1503 | + $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
1504 | + if ($installedMajor === $currentMajor) { |
|
1505 | + // Same major, allow downgrade for developers |
|
1506 | + return true; |
|
1507 | + } else { |
|
1508 | + // downgrade attempt, throw exception |
|
1509 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
1510 | + } |
|
1511 | + } else if ($versionDiff < 0) { |
|
1512 | + // downgrade attempt, throw exception |
|
1513 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
1514 | + } |
|
1515 | + |
|
1516 | + // also check for upgrades for apps (independently from the user) |
|
1517 | + $apps = \OC_App::getEnabledApps(false, true); |
|
1518 | + $shouldUpgrade = false; |
|
1519 | + foreach ($apps as $app) { |
|
1520 | + if (\OC_App::shouldUpgrade($app)) { |
|
1521 | + $shouldUpgrade = true; |
|
1522 | + break; |
|
1523 | + } |
|
1524 | + } |
|
1525 | + return $shouldUpgrade; |
|
1526 | + } else { |
|
1527 | + return false; |
|
1528 | + } |
|
1529 | + } |
|
1530 | 1530 | |
1531 | 1531 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | |
82 | 82 | private static function initLocalStorageRootFS() { |
83 | 83 | // mount local file backend as root |
84 | - $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
84 | + $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT."/data"); |
|
85 | 85 | //first set up the local "root" storage |
86 | 86 | \OC\Files\Filesystem::initMountManager(); |
87 | 87 | if (!self::$rootMounted) { |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | \OC\Files\Filesystem::initMountManager(); |
204 | 204 | |
205 | 205 | \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
206 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
206 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
207 | 207 | if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
208 | 208 | /** @var \OC\Files\Storage\Common $storage */ |
209 | 209 | $storage->setMountOptions($mount->getOptions()); |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | return $storage; |
212 | 212 | }); |
213 | 213 | |
214 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
214 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
215 | 215 | if (!$mount->getOption('enable_sharing', true)) { |
216 | 216 | return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
217 | 217 | 'storage' => $storage, |
@@ -222,21 +222,21 @@ discard block |
||
222 | 222 | }); |
223 | 223 | |
224 | 224 | // install storage availability wrapper, before most other wrappers |
225 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
225 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
226 | 226 | if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
227 | 227 | return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
228 | 228 | } |
229 | 229 | return $storage; |
230 | 230 | }); |
231 | 231 | |
232 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
232 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
233 | 233 | if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
234 | 234 | return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
235 | 235 | } |
236 | 236 | return $storage; |
237 | 237 | }); |
238 | 238 | |
239 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
239 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function($mountPoint, $storage) { |
|
240 | 240 | // set up quota for home storages, even for other users |
241 | 241 | // which can happen when using sharing |
242 | 242 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | return $storage; |
260 | 260 | }); |
261 | 261 | |
262 | - \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
262 | + \OC\Files\Filesystem::addStorageWrapper('readonly', function($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
263 | 263 | /* |
264 | 264 | * Do not allow any operations that modify the storage |
265 | 265 | */ |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | //if we aren't logged in, there is no use to set up the filesystem |
301 | 301 | if ($user != "") { |
302 | 302 | |
303 | - $userDir = '/' . $user . '/files'; |
|
303 | + $userDir = '/'.$user.'/files'; |
|
304 | 304 | |
305 | 305 | //jail the user into his "home" directory |
306 | 306 | \OC\Files\Filesystem::init($user, $userDir); |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
381 | 381 | } |
382 | 382 | $userQuota = $user->getQuota(); |
383 | - if($userQuota === 'none') { |
|
383 | + if ($userQuota === 'none') { |
|
384 | 384 | return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
385 | 385 | } |
386 | 386 | return OC_Helper::computerFileSize($userQuota); |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | */ |
397 | 397 | public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
398 | 398 | |
399 | - $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
399 | + $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT.'/core/skeleton'); |
|
400 | 400 | $userLang = \OC::$server->getL10NFactory()->findLanguage(); |
401 | 401 | $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory); |
402 | 402 | |
@@ -418,9 +418,9 @@ discard block |
||
418 | 418 | if ($instanceId === null) { |
419 | 419 | throw new \RuntimeException('no instance id!'); |
420 | 420 | } |
421 | - $appdata = 'appdata_' . $instanceId; |
|
421 | + $appdata = 'appdata_'.$instanceId; |
|
422 | 422 | if ($userId === $appdata) { |
423 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
423 | + throw new \RuntimeException('username is reserved name: '.$appdata); |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | if (!empty($skeletonDirectory)) { |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | |
448 | 448 | // Verify if folder exists |
449 | 449 | $dir = opendir($source); |
450 | - if($dir === false) { |
|
450 | + if ($dir === false) { |
|
451 | 451 | $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
452 | 452 | return; |
453 | 453 | } |
@@ -455,14 +455,14 @@ discard block |
||
455 | 455 | // Copy the files |
456 | 456 | while (false !== ($file = readdir($dir))) { |
457 | 457 | if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
458 | - if (is_dir($source . '/' . $file)) { |
|
458 | + if (is_dir($source.'/'.$file)) { |
|
459 | 459 | $child = $target->newFolder($file); |
460 | - self::copyr($source . '/' . $file, $child); |
|
460 | + self::copyr($source.'/'.$file, $child); |
|
461 | 461 | } else { |
462 | 462 | $child = $target->newFile($file); |
463 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
464 | - if($sourceStream === false) { |
|
465 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
463 | + $sourceStream = fopen($source.'/'.$file, 'r'); |
|
464 | + if ($sourceStream === false) { |
|
465 | + $logger->error(sprintf('Could not fopen "%s"', $source.'/'.$file), ['app' => 'core']); |
|
466 | 466 | closedir($dir); |
467 | 467 | return; |
468 | 468 | } |
@@ -539,8 +539,8 @@ discard block |
||
539 | 539 | return; |
540 | 540 | } |
541 | 541 | |
542 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
543 | - require OC::$SERVERROOT . '/version.php'; |
|
542 | + $timestamp = filemtime(OC::$SERVERROOT.'/version.php'); |
|
543 | + require OC::$SERVERROOT.'/version.php'; |
|
544 | 544 | /** @var $timestamp int */ |
545 | 545 | self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
546 | 546 | /** @var $OC_Version string */ |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | |
588 | 588 | // core js files need separate handling |
589 | 589 | if ($application !== 'core' && $file !== null) { |
590 | - self::addTranslations ( $application ); |
|
590 | + self::addTranslations($application); |
|
591 | 591 | } |
592 | 592 | self::addExternalResource($application, $prepend, $path, "script"); |
593 | 593 | } |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | if ($type === "style") { |
665 | 665 | if (!in_array($path, self::$styles)) { |
666 | 666 | if ($prepend === true) { |
667 | - array_unshift ( self::$styles, $path ); |
|
667 | + array_unshift(self::$styles, $path); |
|
668 | 668 | } else { |
669 | 669 | self::$styles[] = $path; |
670 | 670 | } |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | } elseif ($type === "script") { |
673 | 673 | if (!in_array($path, self::$scripts)) { |
674 | 674 | if ($prepend === true) { |
675 | - array_unshift ( self::$scripts, $path ); |
|
675 | + array_unshift(self::$scripts, $path); |
|
676 | 676 | } else { |
677 | 677 | self::$scripts [] = $path; |
678 | 678 | } |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | 'text' => $text |
697 | 697 | ); |
698 | 698 | if ($prepend === true) { |
699 | - array_unshift (self::$headers, $header); |
|
699 | + array_unshift(self::$headers, $header); |
|
700 | 700 | |
701 | 701 | } else { |
702 | 702 | self::$headers[] = $header; |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | public static function checkServer(\OC\SystemConfig $config) { |
713 | 713 | $l = \OC::$server->getL10N('lib'); |
714 | 714 | $errors = array(); |
715 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
715 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT.'/data'); |
|
716 | 716 | |
717 | 717 | if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
718 | 718 | // this check needs to be done every time |
@@ -747,14 +747,14 @@ discard block |
||
747 | 747 | } |
748 | 748 | |
749 | 749 | // Check if config folder is writable. |
750 | - if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
750 | + if (!OC_Helper::isReadOnlyConfigEnabled()) { |
|
751 | 751 | if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
752 | 752 | $errors[] = array( |
753 | 753 | 'error' => $l->t('Cannot write into "config" directory'), |
754 | 754 | 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
755 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
755 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]).'. ' |
|
756 | 756 | . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
757 | - [ $urlGenerator->linkToDocs('admin-config') ] ) |
|
757 | + [$urlGenerator->linkToDocs('admin-config')]) |
|
758 | 758 | ); |
759 | 759 | } |
760 | 760 | } |
@@ -889,15 +889,15 @@ discard block |
||
889 | 889 | } |
890 | 890 | } |
891 | 891 | |
892 | - foreach($missingDependencies as $missingDependency) { |
|
892 | + foreach ($missingDependencies as $missingDependency) { |
|
893 | 893 | $errors[] = array( |
894 | 894 | 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
895 | 895 | 'hint' => $moduleHint |
896 | 896 | ); |
897 | 897 | $webServerRestart = true; |
898 | 898 | } |
899 | - foreach($invalidIniSettings as $setting) { |
|
900 | - if(is_bool($setting[1])) { |
|
899 | + foreach ($invalidIniSettings as $setting) { |
|
900 | + if (is_bool($setting[1])) { |
|
901 | 901 | $setting[1] = $setting[1] ? 'on' : 'off'; |
902 | 902 | } |
903 | 903 | $errors[] = [ |
@@ -915,7 +915,7 @@ discard block |
||
915 | 915 | * TODO: Should probably be implemented in the above generic dependency |
916 | 916 | * check somehow in the long-term. |
917 | 917 | */ |
918 | - if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
918 | + if ($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
919 | 919 | $iniWrapper->getBool('mbstring.func_overload') === true) { |
920 | 920 | $errors[] = array( |
921 | 921 | 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
@@ -923,16 +923,16 @@ discard block |
||
923 | 923 | ); |
924 | 924 | } |
925 | 925 | |
926 | - if(function_exists('xml_parser_create') && |
|
927 | - LIBXML_LOADED_VERSION < 20700 ) { |
|
926 | + if (function_exists('xml_parser_create') && |
|
927 | + LIBXML_LOADED_VERSION < 20700) { |
|
928 | 928 | $version = LIBXML_LOADED_VERSION; |
929 | - $major = floor($version/10000); |
|
929 | + $major = floor($version / 10000); |
|
930 | 930 | $version -= ($major * 10000); |
931 | - $minor = floor($version/100); |
|
931 | + $minor = floor($version / 100); |
|
932 | 932 | $version -= ($minor * 100); |
933 | 933 | $patch = $version; |
934 | 934 | $errors[] = array( |
935 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
935 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major.'.'.$minor.'.'.$patch]), |
|
936 | 936 | 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
937 | 937 | ); |
938 | 938 | } |
@@ -998,7 +998,7 @@ discard block |
||
998 | 998 | * @return array arrays with error messages and hints |
999 | 999 | */ |
1000 | 1000 | public static function checkDataDirectoryPermissions($dataDirectory) { |
1001 | - if(\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) { |
|
1001 | + if (\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) { |
|
1002 | 1002 | return []; |
1003 | 1003 | } |
1004 | 1004 | $l = \OC::$server->getL10N('lib'); |
@@ -1036,10 +1036,10 @@ discard block |
||
1036 | 1036 | 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
1037 | 1037 | ]; |
1038 | 1038 | } |
1039 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
1039 | + if (!file_exists($dataDirectory.'/.ocdata')) { |
|
1040 | 1040 | $errors[] = [ |
1041 | 1041 | 'error' => $l->t('Your data directory is invalid'), |
1042 | - 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
1042 | + 'hint' => $l->t('Ensure there is a file called ".ocdata"'. |
|
1043 | 1043 | ' in the root of the data directory.') |
1044 | 1044 | ]; |
1045 | 1045 | } |
@@ -1055,7 +1055,7 @@ discard block |
||
1055 | 1055 | public static function checkLoggedIn() { |
1056 | 1056 | // Check if we are a user |
1057 | 1057 | if (!\OC::$server->getUserSession()->isLoggedIn()) { |
1058 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
1058 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRoute( |
|
1059 | 1059 | 'core.login.showLoginForm', |
1060 | 1060 | [ |
1061 | 1061 | 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
@@ -1066,7 +1066,7 @@ discard block |
||
1066 | 1066 | } |
1067 | 1067 | // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
1068 | 1068 | if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
1069 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
1069 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
1070 | 1070 | exit(); |
1071 | 1071 | } |
1072 | 1072 | } |
@@ -1079,7 +1079,7 @@ discard block |
||
1079 | 1079 | public static function checkAdminUser() { |
1080 | 1080 | OC_Util::checkLoggedIn(); |
1081 | 1081 | if (!OC_User::isAdminUser(OC_User::getUser())) { |
1082 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
1082 | + header('Location: '.\OCP\Util::linkToAbsolute('', 'index.php')); |
|
1083 | 1083 | exit(); |
1084 | 1084 | } |
1085 | 1085 | } |
@@ -1093,12 +1093,12 @@ discard block |
||
1093 | 1093 | OC_Util::checkLoggedIn(); |
1094 | 1094 | $userObject = \OC::$server->getUserSession()->getUser(); |
1095 | 1095 | $isSubAdmin = false; |
1096 | - if($userObject !== null) { |
|
1096 | + if ($userObject !== null) { |
|
1097 | 1097 | $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
1098 | 1098 | } |
1099 | 1099 | |
1100 | 1100 | if (!$isSubAdmin) { |
1101 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
1101 | + header('Location: '.\OCP\Util::linkToAbsolute('', 'index.php')); |
|
1102 | 1102 | exit(); |
1103 | 1103 | } |
1104 | 1104 | return true; |
@@ -1135,10 +1135,10 @@ discard block |
||
1135 | 1135 | } |
1136 | 1136 | } |
1137 | 1137 | |
1138 | - if($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
1139 | - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
1138 | + if ($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
1139 | + $location = $urlGenerator->getAbsoluteURL('/apps/'.$appId.'/'); |
|
1140 | 1140 | } else { |
1141 | - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
1141 | + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/'.$appId.'/'); |
|
1142 | 1142 | } |
1143 | 1143 | } |
1144 | 1144 | } |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | */ |
1153 | 1153 | public static function redirectToDefaultPage() { |
1154 | 1154 | $location = self::getDefaultPageUrl(); |
1155 | - header('Location: ' . $location); |
|
1155 | + header('Location: '.$location); |
|
1156 | 1156 | exit(); |
1157 | 1157 | } |
1158 | 1158 | |
@@ -1165,7 +1165,7 @@ discard block |
||
1165 | 1165 | $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
1166 | 1166 | if (is_null($id)) { |
1167 | 1167 | // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
1168 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
1168 | + $id = 'oc'.\OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
1169 | 1169 | \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
1170 | 1170 | } |
1171 | 1171 | return $id; |
@@ -1187,7 +1187,7 @@ discard block |
||
1187 | 1187 | }, $value); |
1188 | 1188 | } else { |
1189 | 1189 | // Specify encoding for PHP<5.4 |
1190 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
1190 | + $value = htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); |
|
1191 | 1191 | } |
1192 | 1192 | return $value; |
1193 | 1193 | } |
@@ -1220,7 +1220,7 @@ discard block |
||
1220 | 1220 | $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
1221 | 1221 | |
1222 | 1222 | // creating a test file |
1223 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
1223 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$fileName; |
|
1224 | 1224 | |
1225 | 1225 | if (file_exists($testFile)) {// already running this test, possible recursive call |
1226 | 1226 | return false; |
@@ -1229,7 +1229,7 @@ discard block |
||
1229 | 1229 | $fp = @fopen($testFile, 'w'); |
1230 | 1230 | if (!$fp) { |
1231 | 1231 | throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
1232 | - 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
1232 | + 'Make sure it is possible for the webserver to write to '.$testFile); |
|
1233 | 1233 | } |
1234 | 1234 | fwrite($fp, $testContent); |
1235 | 1235 | fclose($fp); |
@@ -1256,10 +1256,10 @@ discard block |
||
1256 | 1256 | } |
1257 | 1257 | |
1258 | 1258 | $fileName = '/htaccesstest.txt'; |
1259 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
1259 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$fileName; |
|
1260 | 1260 | |
1261 | 1261 | // accessing the file via http |
1262 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
1262 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT.'/data'.$fileName); |
|
1263 | 1263 | try { |
1264 | 1264 | $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
1265 | 1265 | } catch (\Exception $e) { |
@@ -1350,7 +1350,7 @@ discard block |
||
1350 | 1350 | $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
1351 | 1351 | |
1352 | 1352 | if ($theme === '') { |
1353 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
1353 | + if (is_dir(OC::$SERVERROOT.'/themes/default')) { |
|
1354 | 1354 | $theme = 'default'; |
1355 | 1355 | } |
1356 | 1356 | } |
@@ -1423,13 +1423,13 @@ discard block |
||
1423 | 1423 | * @return bool|string |
1424 | 1424 | */ |
1425 | 1425 | public static function normalizeUnicode($value) { |
1426 | - if(Normalizer::isNormalized($value)) { |
|
1426 | + if (Normalizer::isNormalized($value)) { |
|
1427 | 1427 | return $value; |
1428 | 1428 | } |
1429 | 1429 | |
1430 | 1430 | $normalizedValue = Normalizer::normalize($value); |
1431 | 1431 | if ($normalizedValue === null || $normalizedValue === false) { |
1432 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
1432 | + \OC::$server->getLogger()->warning('normalizing failed for "'.$value.'"', ['app' => 'core']); |
|
1433 | 1433 | return $value; |
1434 | 1434 | } |
1435 | 1435 | |
@@ -1445,7 +1445,7 @@ discard block |
||
1445 | 1445 | $version = OC_Util::getVersionString(); |
1446 | 1446 | $build = OC_Util::getBuild(); |
1447 | 1447 | if (!empty($build) and OC_Util::getChannel() === 'daily') { |
1448 | - $version .= ' Build:' . $build; |
|
1448 | + $version .= ' Build:'.$build; |
|
1449 | 1449 | } |
1450 | 1450 | return $version; |
1451 | 1451 | } |
@@ -1467,7 +1467,7 @@ discard block |
||
1467 | 1467 | } |
1468 | 1468 | |
1469 | 1469 | // detect part files |
1470 | - if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
1470 | + if (preg_match('/'.\OCP\Files\FileInfo::BLACKLIST_FILES_REGEX.'/', $trimmed) !== 0) { |
|
1471 | 1471 | return false; |
1472 | 1472 | } |
1473 | 1473 | |
@@ -1498,19 +1498,19 @@ discard block |
||
1498 | 1498 | } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
1499 | 1499 | // downgrade with debug |
1500 | 1500 | $installedMajor = explode('.', $installedVersion); |
1501 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
1501 | + $installedMajor = $installedMajor[0].'.'.$installedMajor[1]; |
|
1502 | 1502 | $currentMajor = explode('.', $currentVersion); |
1503 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
1503 | + $currentMajor = $currentMajor[0].'.'.$currentMajor[1]; |
|
1504 | 1504 | if ($installedMajor === $currentMajor) { |
1505 | 1505 | // Same major, allow downgrade for developers |
1506 | 1506 | return true; |
1507 | 1507 | } else { |
1508 | 1508 | // downgrade attempt, throw exception |
1509 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
1509 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from '.$installedVersion.' to '.$currentVersion.')'); |
|
1510 | 1510 | } |
1511 | 1511 | } else if ($versionDiff < 0) { |
1512 | 1512 | // downgrade attempt, throw exception |
1513 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
1513 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from '.$installedVersion.' to '.$currentVersion.')'); |
|
1514 | 1514 | } |
1515 | 1515 | |
1516 | 1516 | // also check for upgrades for apps (independently from the user) |
@@ -47,376 +47,376 @@ |
||
47 | 47 | |
48 | 48 | class SCSSCacher { |
49 | 49 | |
50 | - /** @var ILogger */ |
|
51 | - protected $logger; |
|
52 | - |
|
53 | - /** @var IAppData */ |
|
54 | - protected $appData; |
|
55 | - |
|
56 | - /** @var IURLGenerator */ |
|
57 | - protected $urlGenerator; |
|
58 | - |
|
59 | - /** @var IConfig */ |
|
60 | - protected $config; |
|
61 | - |
|
62 | - /** @var \OC_Defaults */ |
|
63 | - private $defaults; |
|
64 | - |
|
65 | - /** @var string */ |
|
66 | - protected $serverRoot; |
|
67 | - |
|
68 | - /** @var ICache */ |
|
69 | - protected $depsCache; |
|
70 | - |
|
71 | - /** @var null|string */ |
|
72 | - private $injectedVariables; |
|
73 | - |
|
74 | - /** @var ICacheFactory */ |
|
75 | - private $cacheFactory; |
|
76 | - |
|
77 | - /** @var IconsCacher */ |
|
78 | - private $iconsCacher; |
|
79 | - |
|
80 | - /** |
|
81 | - * @param ILogger $logger |
|
82 | - * @param Factory $appDataFactory |
|
83 | - * @param IURLGenerator $urlGenerator |
|
84 | - * @param IConfig $config |
|
85 | - * @param \OC_Defaults $defaults |
|
86 | - * @param string $serverRoot |
|
87 | - * @param ICacheFactory $cacheFactory |
|
88 | - * @param IconsCacher $iconsCacher |
|
89 | - */ |
|
90 | - public function __construct(ILogger $logger, |
|
91 | - Factory $appDataFactory, |
|
92 | - IURLGenerator $urlGenerator, |
|
93 | - IConfig $config, |
|
94 | - \OC_Defaults $defaults, |
|
95 | - $serverRoot, |
|
96 | - ICacheFactory $cacheFactory, |
|
97 | - IconsCacher $iconsCacher) { |
|
98 | - $this->logger = $logger; |
|
99 | - $this->appData = $appDataFactory->get('css'); |
|
100 | - $this->urlGenerator = $urlGenerator; |
|
101 | - $this->config = $config; |
|
102 | - $this->defaults = $defaults; |
|
103 | - $this->serverRoot = $serverRoot; |
|
104 | - $this->cacheFactory = $cacheFactory; |
|
105 | - $this->depsCache = $cacheFactory->createDistributed('SCSS-' . md5($this->urlGenerator->getBaseUrl())); |
|
106 | - $this->iconsCacher = $iconsCacher; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Process the caching process if needed |
|
111 | - * |
|
112 | - * @param string $root Root path to the nextcloud installation |
|
113 | - * @param string $file |
|
114 | - * @param string $app The app name |
|
115 | - * @return boolean |
|
116 | - * @throws NotPermittedException |
|
117 | - */ |
|
118 | - public function process(string $root, string $file, string $app): bool { |
|
119 | - $path = explode('/', $root . '/' . $file); |
|
120 | - |
|
121 | - $fileNameSCSS = array_pop($path); |
|
122 | - $fileNameCSS = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)), $app); |
|
123 | - |
|
124 | - $path = implode('/', $path); |
|
125 | - $webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT); |
|
126 | - |
|
127 | - try { |
|
128 | - $folder = $this->appData->getFolder($app); |
|
129 | - } catch (NotFoundException $e) { |
|
130 | - // creating css appdata folder |
|
131 | - $folder = $this->appData->newFolder($app); |
|
132 | - } |
|
133 | - |
|
134 | - if (!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) { |
|
135 | - // Inject icons vars css if any |
|
136 | - if ($this->iconsCacher->getCachedCSS() && $this->iconsCacher->getCachedCSS()->getSize() > 0) { |
|
137 | - $this->iconsCacher->injectCss(); |
|
138 | - } |
|
139 | - return true; |
|
140 | - } |
|
141 | - |
|
142 | - $cached = $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir); |
|
143 | - |
|
144 | - // Inject icons vars css if any |
|
145 | - if ($this->iconsCacher->getCachedCSS() && $this->iconsCacher->getCachedCSS()->getSize() > 0) { |
|
146 | - $this->iconsCacher->injectCss(); |
|
147 | - } |
|
148 | - |
|
149 | - return $cached; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @param $appName |
|
154 | - * @param $fileName |
|
155 | - * @return ISimpleFile |
|
156 | - */ |
|
157 | - public function getCachedCSS(string $appName, string $fileName): ISimpleFile { |
|
158 | - $folder = $this->appData->getFolder($appName); |
|
159 | - $cachedFileName = $this->prependVersionPrefix($this->prependBaseurlPrefix($fileName), $appName); |
|
160 | - |
|
161 | - return $folder->getFile($cachedFileName); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Check if the file is cached or not |
|
166 | - * @param string $fileNameCSS |
|
167 | - * @param ISimpleFolder $folder |
|
168 | - * @return boolean |
|
169 | - */ |
|
170 | - private function isCached(string $fileNameCSS, ISimpleFolder $folder) { |
|
171 | - try { |
|
172 | - $cachedFile = $folder->getFile($fileNameCSS); |
|
173 | - if ($cachedFile->getSize() > 0) { |
|
174 | - $depFileName = $fileNameCSS . '.deps'; |
|
175 | - $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName); |
|
176 | - if ($deps === null) { |
|
177 | - $depFile = $folder->getFile($depFileName); |
|
178 | - $deps = $depFile->getContent(); |
|
179 | - //Set to memcache for next run |
|
180 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
181 | - } |
|
182 | - $deps = json_decode($deps, true); |
|
183 | - |
|
184 | - foreach ((array) $deps as $file => $mtime) { |
|
185 | - if (!file_exists($file) || filemtime($file) > $mtime) { |
|
186 | - return false; |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - return true; |
|
191 | - } |
|
192 | - |
|
193 | - return false; |
|
194 | - } catch (NotFoundException $e) { |
|
195 | - return false; |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Check if the variables file has changed |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - private function variablesChanged(): bool { |
|
204 | - $injectedVariables = $this->getInjectedVariables(); |
|
205 | - if ($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { |
|
206 | - $this->resetCache(); |
|
207 | - $this->config->setAppValue('core', 'scss.variables', md5($injectedVariables)); |
|
208 | - |
|
209 | - return true; |
|
210 | - } |
|
211 | - |
|
212 | - return false; |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Cache the file with AppData |
|
217 | - * |
|
218 | - * @param string $path |
|
219 | - * @param string $fileNameCSS |
|
220 | - * @param string $fileNameSCSS |
|
221 | - * @param ISimpleFolder $folder |
|
222 | - * @param string $webDir |
|
223 | - * @return boolean |
|
224 | - * @throws NotPermittedException |
|
225 | - */ |
|
226 | - private function cache(string $path, string $fileNameCSS, string $fileNameSCSS, ISimpleFolder $folder, string $webDir) { |
|
227 | - $scss = new Compiler(); |
|
228 | - $scss->setImportPaths([ |
|
229 | - $path, |
|
230 | - $this->serverRoot . '/core/css/' |
|
231 | - ]); |
|
232 | - |
|
233 | - // Continue after throw |
|
234 | - $scss->setIgnoreErrors(true); |
|
235 | - if ($this->config->getSystemValue('debug')) { |
|
236 | - // Debug mode |
|
237 | - $scss->setFormatter(Expanded::class); |
|
238 | - $scss->setLineNumberStyle(Compiler::LINE_COMMENTS); |
|
239 | - } else { |
|
240 | - // Compression |
|
241 | - $scss->setFormatter(Crunched::class); |
|
242 | - } |
|
243 | - |
|
244 | - try { |
|
245 | - $cachedfile = $folder->getFile($fileNameCSS); |
|
246 | - } catch (NotFoundException $e) { |
|
247 | - $cachedfile = $folder->newFile($fileNameCSS); |
|
248 | - } |
|
249 | - |
|
250 | - $depFileName = $fileNameCSS . '.deps'; |
|
251 | - try { |
|
252 | - $depFile = $folder->getFile($depFileName); |
|
253 | - } catch (NotFoundException $e) { |
|
254 | - $depFile = $folder->newFile($depFileName); |
|
255 | - } |
|
256 | - |
|
257 | - // Compile |
|
258 | - try { |
|
259 | - $compiledScss = $scss->compile( |
|
260 | - '$webroot: \'' . $this->getRoutePrefix() . '\';' . |
|
261 | - '@import "variables.scss";' . |
|
262 | - '@import "functions.scss";' . |
|
263 | - $this->getInjectedVariables() . |
|
264 | - '@import "' . $fileNameSCSS . '";'); |
|
265 | - } catch (ParserException $e) { |
|
266 | - $this->logger->error($e, ['app' => 'core']); |
|
267 | - |
|
268 | - return false; |
|
269 | - } |
|
270 | - |
|
271 | - // Parse Icons and create related css variables |
|
272 | - $compiledScss = $this->iconsCacher->setIconsCss($compiledScss); |
|
273 | - |
|
274 | - // Gzip file |
|
275 | - try { |
|
276 | - $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
277 | - } catch (NotFoundException $e) { |
|
278 | - $gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
279 | - } |
|
280 | - |
|
281 | - try { |
|
282 | - $data = $this->rebaseUrls($compiledScss, $webDir); |
|
283 | - $cachedfile->putContent($data); |
|
284 | - $deps = json_encode($scss->getParsedFiles()); |
|
285 | - $depFile->putContent($deps); |
|
286 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
287 | - $gzipFile->putContent(gzencode($data, 9)); |
|
288 | - $this->logger->debug('SCSSCacher: ' . $webDir . '/' . $fileNameSCSS . ' compiled and successfully cached', ['app' => 'core']); |
|
289 | - |
|
290 | - return true; |
|
291 | - } catch (NotPermittedException $e) { |
|
292 | - $this->logger->error('SCSSCacher: unable to cache: ' . $fileNameSCSS); |
|
293 | - |
|
294 | - return false; |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Reset scss cache by deleting all generated css files |
|
300 | - * We need to regenerate all files when variables change |
|
301 | - */ |
|
302 | - public function resetCache() { |
|
303 | - $this->injectedVariables = null; |
|
304 | - $this->cacheFactory->createDistributed('SCSS-')->clear(); |
|
305 | - $appDirectory = $this->appData->getDirectoryListing(); |
|
306 | - foreach ($appDirectory as $folder) { |
|
307 | - foreach ($folder->getDirectoryListing() as $file) { |
|
308 | - try { |
|
309 | - $file->delete(); |
|
310 | - } catch (NotPermittedException $e) { |
|
311 | - $this->logger->logException($e, ['message' => 'SCSSCacher: unable to delete file: ' . $file->getName()]); |
|
312 | - } |
|
313 | - } |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * @return string SCSS code for variables from OC_Defaults |
|
319 | - */ |
|
320 | - private function getInjectedVariables(): string { |
|
321 | - if ($this->injectedVariables !== null) { |
|
322 | - return $this->injectedVariables; |
|
323 | - } |
|
324 | - $variables = ''; |
|
325 | - foreach ($this->defaults->getScssVariables() as $key => $value) { |
|
326 | - $variables .= '$' . $key . ': ' . $value . ';'; |
|
327 | - } |
|
328 | - |
|
329 | - // check for valid variables / otherwise fall back to defaults |
|
330 | - try { |
|
331 | - $scss = new Compiler(); |
|
332 | - $scss->compile($variables); |
|
333 | - $this->injectedVariables = $variables; |
|
334 | - } catch (ParserException $e) { |
|
335 | - $this->logger->error($e, ['app' => 'core']); |
|
336 | - } |
|
337 | - |
|
338 | - return $variables; |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Add the correct uri prefix to make uri valid again |
|
343 | - * @param string $css |
|
344 | - * @param string $webDir |
|
345 | - * @return string |
|
346 | - */ |
|
347 | - private function rebaseUrls(string $css, string $webDir): string { |
|
348 | - $re = '/url\([\'"]([^\/][\.\w?=\/-]*)[\'"]\)/x'; |
|
349 | - $subst = 'url(\'' . $webDir . '/$1\')'; |
|
350 | - |
|
351 | - return preg_replace($re, $subst, $css); |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Return the cached css file uri |
|
356 | - * @param string $appName the app name |
|
357 | - * @param string $fileName |
|
358 | - * @return string |
|
359 | - */ |
|
360 | - public function getCachedSCSS(string $appName, string $fileName): string { |
|
361 | - $tmpfileLoc = explode('/', $fileName); |
|
362 | - $fileName = array_pop($tmpfileLoc); |
|
363 | - $fileName = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName)), $appName); |
|
364 | - |
|
365 | - return substr($this->urlGenerator->linkToRoute('core.Css.getCss', ['fileName' => $fileName, 'appName' => $appName]), strlen(\OC::$WEBROOT) + 1); |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Prepend hashed base url to the css file |
|
370 | - * @param string $cssFile |
|
371 | - * @return string |
|
372 | - */ |
|
373 | - private function prependBaseurlPrefix(string $cssFile): string { |
|
374 | - return substr(md5($this->urlGenerator->getBaseUrl() . $this->getRoutePrefix()), 0, 4) . '-' . $cssFile; |
|
375 | - } |
|
376 | - |
|
377 | - private function getRoutePrefix() { |
|
378 | - $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
|
379 | - $prefix = \OC::$WEBROOT . '/index.php'; |
|
380 | - if ($frontControllerActive) { |
|
381 | - $prefix = \OC::$WEBROOT; |
|
382 | - } |
|
383 | - return $prefix; |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Prepend hashed app version hash |
|
388 | - * @param string $cssFile |
|
389 | - * @param string $appId |
|
390 | - * @return string |
|
391 | - */ |
|
392 | - private function prependVersionPrefix(string $cssFile, string $appId): string { |
|
393 | - $appVersion = \OC_App::getAppVersion($appId); |
|
394 | - if ($appVersion !== '0') { |
|
395 | - return substr(md5($appVersion), 0, 4) . '-' . $cssFile; |
|
396 | - } |
|
397 | - $coreVersion = \OC_Util::getVersionString(); |
|
398 | - |
|
399 | - return substr(md5($coreVersion), 0, 4) . '-' . $cssFile; |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * Get WebDir root |
|
404 | - * @param string $path the css file path |
|
405 | - * @param string $appName the app name |
|
406 | - * @param string $serverRoot the server root path |
|
407 | - * @param string $webRoot the nextcloud installation root path |
|
408 | - * @return string the webDir |
|
409 | - */ |
|
410 | - private function getWebDir(string $path, string $appName, string $serverRoot, string $webRoot): string { |
|
411 | - // Detect if path is within server root AND if path is within an app path |
|
412 | - if (strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { |
|
413 | - // Get the file path within the app directory |
|
414 | - $appDirectoryPath = explode($appName, $path)[1]; |
|
415 | - // Remove the webroot |
|
416 | - |
|
417 | - return str_replace($webRoot, '', $appWebPath . $appDirectoryPath); |
|
418 | - } |
|
419 | - |
|
420 | - return $webRoot . substr($path, strlen($serverRoot)); |
|
421 | - } |
|
50 | + /** @var ILogger */ |
|
51 | + protected $logger; |
|
52 | + |
|
53 | + /** @var IAppData */ |
|
54 | + protected $appData; |
|
55 | + |
|
56 | + /** @var IURLGenerator */ |
|
57 | + protected $urlGenerator; |
|
58 | + |
|
59 | + /** @var IConfig */ |
|
60 | + protected $config; |
|
61 | + |
|
62 | + /** @var \OC_Defaults */ |
|
63 | + private $defaults; |
|
64 | + |
|
65 | + /** @var string */ |
|
66 | + protected $serverRoot; |
|
67 | + |
|
68 | + /** @var ICache */ |
|
69 | + protected $depsCache; |
|
70 | + |
|
71 | + /** @var null|string */ |
|
72 | + private $injectedVariables; |
|
73 | + |
|
74 | + /** @var ICacheFactory */ |
|
75 | + private $cacheFactory; |
|
76 | + |
|
77 | + /** @var IconsCacher */ |
|
78 | + private $iconsCacher; |
|
79 | + |
|
80 | + /** |
|
81 | + * @param ILogger $logger |
|
82 | + * @param Factory $appDataFactory |
|
83 | + * @param IURLGenerator $urlGenerator |
|
84 | + * @param IConfig $config |
|
85 | + * @param \OC_Defaults $defaults |
|
86 | + * @param string $serverRoot |
|
87 | + * @param ICacheFactory $cacheFactory |
|
88 | + * @param IconsCacher $iconsCacher |
|
89 | + */ |
|
90 | + public function __construct(ILogger $logger, |
|
91 | + Factory $appDataFactory, |
|
92 | + IURLGenerator $urlGenerator, |
|
93 | + IConfig $config, |
|
94 | + \OC_Defaults $defaults, |
|
95 | + $serverRoot, |
|
96 | + ICacheFactory $cacheFactory, |
|
97 | + IconsCacher $iconsCacher) { |
|
98 | + $this->logger = $logger; |
|
99 | + $this->appData = $appDataFactory->get('css'); |
|
100 | + $this->urlGenerator = $urlGenerator; |
|
101 | + $this->config = $config; |
|
102 | + $this->defaults = $defaults; |
|
103 | + $this->serverRoot = $serverRoot; |
|
104 | + $this->cacheFactory = $cacheFactory; |
|
105 | + $this->depsCache = $cacheFactory->createDistributed('SCSS-' . md5($this->urlGenerator->getBaseUrl())); |
|
106 | + $this->iconsCacher = $iconsCacher; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Process the caching process if needed |
|
111 | + * |
|
112 | + * @param string $root Root path to the nextcloud installation |
|
113 | + * @param string $file |
|
114 | + * @param string $app The app name |
|
115 | + * @return boolean |
|
116 | + * @throws NotPermittedException |
|
117 | + */ |
|
118 | + public function process(string $root, string $file, string $app): bool { |
|
119 | + $path = explode('/', $root . '/' . $file); |
|
120 | + |
|
121 | + $fileNameSCSS = array_pop($path); |
|
122 | + $fileNameCSS = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)), $app); |
|
123 | + |
|
124 | + $path = implode('/', $path); |
|
125 | + $webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT); |
|
126 | + |
|
127 | + try { |
|
128 | + $folder = $this->appData->getFolder($app); |
|
129 | + } catch (NotFoundException $e) { |
|
130 | + // creating css appdata folder |
|
131 | + $folder = $this->appData->newFolder($app); |
|
132 | + } |
|
133 | + |
|
134 | + if (!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) { |
|
135 | + // Inject icons vars css if any |
|
136 | + if ($this->iconsCacher->getCachedCSS() && $this->iconsCacher->getCachedCSS()->getSize() > 0) { |
|
137 | + $this->iconsCacher->injectCss(); |
|
138 | + } |
|
139 | + return true; |
|
140 | + } |
|
141 | + |
|
142 | + $cached = $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir); |
|
143 | + |
|
144 | + // Inject icons vars css if any |
|
145 | + if ($this->iconsCacher->getCachedCSS() && $this->iconsCacher->getCachedCSS()->getSize() > 0) { |
|
146 | + $this->iconsCacher->injectCss(); |
|
147 | + } |
|
148 | + |
|
149 | + return $cached; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @param $appName |
|
154 | + * @param $fileName |
|
155 | + * @return ISimpleFile |
|
156 | + */ |
|
157 | + public function getCachedCSS(string $appName, string $fileName): ISimpleFile { |
|
158 | + $folder = $this->appData->getFolder($appName); |
|
159 | + $cachedFileName = $this->prependVersionPrefix($this->prependBaseurlPrefix($fileName), $appName); |
|
160 | + |
|
161 | + return $folder->getFile($cachedFileName); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Check if the file is cached or not |
|
166 | + * @param string $fileNameCSS |
|
167 | + * @param ISimpleFolder $folder |
|
168 | + * @return boolean |
|
169 | + */ |
|
170 | + private function isCached(string $fileNameCSS, ISimpleFolder $folder) { |
|
171 | + try { |
|
172 | + $cachedFile = $folder->getFile($fileNameCSS); |
|
173 | + if ($cachedFile->getSize() > 0) { |
|
174 | + $depFileName = $fileNameCSS . '.deps'; |
|
175 | + $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName); |
|
176 | + if ($deps === null) { |
|
177 | + $depFile = $folder->getFile($depFileName); |
|
178 | + $deps = $depFile->getContent(); |
|
179 | + //Set to memcache for next run |
|
180 | + $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
181 | + } |
|
182 | + $deps = json_decode($deps, true); |
|
183 | + |
|
184 | + foreach ((array) $deps as $file => $mtime) { |
|
185 | + if (!file_exists($file) || filemtime($file) > $mtime) { |
|
186 | + return false; |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + return true; |
|
191 | + } |
|
192 | + |
|
193 | + return false; |
|
194 | + } catch (NotFoundException $e) { |
|
195 | + return false; |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Check if the variables file has changed |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + private function variablesChanged(): bool { |
|
204 | + $injectedVariables = $this->getInjectedVariables(); |
|
205 | + if ($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { |
|
206 | + $this->resetCache(); |
|
207 | + $this->config->setAppValue('core', 'scss.variables', md5($injectedVariables)); |
|
208 | + |
|
209 | + return true; |
|
210 | + } |
|
211 | + |
|
212 | + return false; |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Cache the file with AppData |
|
217 | + * |
|
218 | + * @param string $path |
|
219 | + * @param string $fileNameCSS |
|
220 | + * @param string $fileNameSCSS |
|
221 | + * @param ISimpleFolder $folder |
|
222 | + * @param string $webDir |
|
223 | + * @return boolean |
|
224 | + * @throws NotPermittedException |
|
225 | + */ |
|
226 | + private function cache(string $path, string $fileNameCSS, string $fileNameSCSS, ISimpleFolder $folder, string $webDir) { |
|
227 | + $scss = new Compiler(); |
|
228 | + $scss->setImportPaths([ |
|
229 | + $path, |
|
230 | + $this->serverRoot . '/core/css/' |
|
231 | + ]); |
|
232 | + |
|
233 | + // Continue after throw |
|
234 | + $scss->setIgnoreErrors(true); |
|
235 | + if ($this->config->getSystemValue('debug')) { |
|
236 | + // Debug mode |
|
237 | + $scss->setFormatter(Expanded::class); |
|
238 | + $scss->setLineNumberStyle(Compiler::LINE_COMMENTS); |
|
239 | + } else { |
|
240 | + // Compression |
|
241 | + $scss->setFormatter(Crunched::class); |
|
242 | + } |
|
243 | + |
|
244 | + try { |
|
245 | + $cachedfile = $folder->getFile($fileNameCSS); |
|
246 | + } catch (NotFoundException $e) { |
|
247 | + $cachedfile = $folder->newFile($fileNameCSS); |
|
248 | + } |
|
249 | + |
|
250 | + $depFileName = $fileNameCSS . '.deps'; |
|
251 | + try { |
|
252 | + $depFile = $folder->getFile($depFileName); |
|
253 | + } catch (NotFoundException $e) { |
|
254 | + $depFile = $folder->newFile($depFileName); |
|
255 | + } |
|
256 | + |
|
257 | + // Compile |
|
258 | + try { |
|
259 | + $compiledScss = $scss->compile( |
|
260 | + '$webroot: \'' . $this->getRoutePrefix() . '\';' . |
|
261 | + '@import "variables.scss";' . |
|
262 | + '@import "functions.scss";' . |
|
263 | + $this->getInjectedVariables() . |
|
264 | + '@import "' . $fileNameSCSS . '";'); |
|
265 | + } catch (ParserException $e) { |
|
266 | + $this->logger->error($e, ['app' => 'core']); |
|
267 | + |
|
268 | + return false; |
|
269 | + } |
|
270 | + |
|
271 | + // Parse Icons and create related css variables |
|
272 | + $compiledScss = $this->iconsCacher->setIconsCss($compiledScss); |
|
273 | + |
|
274 | + // Gzip file |
|
275 | + try { |
|
276 | + $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
277 | + } catch (NotFoundException $e) { |
|
278 | + $gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
279 | + } |
|
280 | + |
|
281 | + try { |
|
282 | + $data = $this->rebaseUrls($compiledScss, $webDir); |
|
283 | + $cachedfile->putContent($data); |
|
284 | + $deps = json_encode($scss->getParsedFiles()); |
|
285 | + $depFile->putContent($deps); |
|
286 | + $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
287 | + $gzipFile->putContent(gzencode($data, 9)); |
|
288 | + $this->logger->debug('SCSSCacher: ' . $webDir . '/' . $fileNameSCSS . ' compiled and successfully cached', ['app' => 'core']); |
|
289 | + |
|
290 | + return true; |
|
291 | + } catch (NotPermittedException $e) { |
|
292 | + $this->logger->error('SCSSCacher: unable to cache: ' . $fileNameSCSS); |
|
293 | + |
|
294 | + return false; |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Reset scss cache by deleting all generated css files |
|
300 | + * We need to regenerate all files when variables change |
|
301 | + */ |
|
302 | + public function resetCache() { |
|
303 | + $this->injectedVariables = null; |
|
304 | + $this->cacheFactory->createDistributed('SCSS-')->clear(); |
|
305 | + $appDirectory = $this->appData->getDirectoryListing(); |
|
306 | + foreach ($appDirectory as $folder) { |
|
307 | + foreach ($folder->getDirectoryListing() as $file) { |
|
308 | + try { |
|
309 | + $file->delete(); |
|
310 | + } catch (NotPermittedException $e) { |
|
311 | + $this->logger->logException($e, ['message' => 'SCSSCacher: unable to delete file: ' . $file->getName()]); |
|
312 | + } |
|
313 | + } |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * @return string SCSS code for variables from OC_Defaults |
|
319 | + */ |
|
320 | + private function getInjectedVariables(): string { |
|
321 | + if ($this->injectedVariables !== null) { |
|
322 | + return $this->injectedVariables; |
|
323 | + } |
|
324 | + $variables = ''; |
|
325 | + foreach ($this->defaults->getScssVariables() as $key => $value) { |
|
326 | + $variables .= '$' . $key . ': ' . $value . ';'; |
|
327 | + } |
|
328 | + |
|
329 | + // check for valid variables / otherwise fall back to defaults |
|
330 | + try { |
|
331 | + $scss = new Compiler(); |
|
332 | + $scss->compile($variables); |
|
333 | + $this->injectedVariables = $variables; |
|
334 | + } catch (ParserException $e) { |
|
335 | + $this->logger->error($e, ['app' => 'core']); |
|
336 | + } |
|
337 | + |
|
338 | + return $variables; |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Add the correct uri prefix to make uri valid again |
|
343 | + * @param string $css |
|
344 | + * @param string $webDir |
|
345 | + * @return string |
|
346 | + */ |
|
347 | + private function rebaseUrls(string $css, string $webDir): string { |
|
348 | + $re = '/url\([\'"]([^\/][\.\w?=\/-]*)[\'"]\)/x'; |
|
349 | + $subst = 'url(\'' . $webDir . '/$1\')'; |
|
350 | + |
|
351 | + return preg_replace($re, $subst, $css); |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Return the cached css file uri |
|
356 | + * @param string $appName the app name |
|
357 | + * @param string $fileName |
|
358 | + * @return string |
|
359 | + */ |
|
360 | + public function getCachedSCSS(string $appName, string $fileName): string { |
|
361 | + $tmpfileLoc = explode('/', $fileName); |
|
362 | + $fileName = array_pop($tmpfileLoc); |
|
363 | + $fileName = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName)), $appName); |
|
364 | + |
|
365 | + return substr($this->urlGenerator->linkToRoute('core.Css.getCss', ['fileName' => $fileName, 'appName' => $appName]), strlen(\OC::$WEBROOT) + 1); |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Prepend hashed base url to the css file |
|
370 | + * @param string $cssFile |
|
371 | + * @return string |
|
372 | + */ |
|
373 | + private function prependBaseurlPrefix(string $cssFile): string { |
|
374 | + return substr(md5($this->urlGenerator->getBaseUrl() . $this->getRoutePrefix()), 0, 4) . '-' . $cssFile; |
|
375 | + } |
|
376 | + |
|
377 | + private function getRoutePrefix() { |
|
378 | + $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
|
379 | + $prefix = \OC::$WEBROOT . '/index.php'; |
|
380 | + if ($frontControllerActive) { |
|
381 | + $prefix = \OC::$WEBROOT; |
|
382 | + } |
|
383 | + return $prefix; |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Prepend hashed app version hash |
|
388 | + * @param string $cssFile |
|
389 | + * @param string $appId |
|
390 | + * @return string |
|
391 | + */ |
|
392 | + private function prependVersionPrefix(string $cssFile, string $appId): string { |
|
393 | + $appVersion = \OC_App::getAppVersion($appId); |
|
394 | + if ($appVersion !== '0') { |
|
395 | + return substr(md5($appVersion), 0, 4) . '-' . $cssFile; |
|
396 | + } |
|
397 | + $coreVersion = \OC_Util::getVersionString(); |
|
398 | + |
|
399 | + return substr(md5($coreVersion), 0, 4) . '-' . $cssFile; |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * Get WebDir root |
|
404 | + * @param string $path the css file path |
|
405 | + * @param string $appName the app name |
|
406 | + * @param string $serverRoot the server root path |
|
407 | + * @param string $webRoot the nextcloud installation root path |
|
408 | + * @return string the webDir |
|
409 | + */ |
|
410 | + private function getWebDir(string $path, string $appName, string $serverRoot, string $webRoot): string { |
|
411 | + // Detect if path is within server root AND if path is within an app path |
|
412 | + if (strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { |
|
413 | + // Get the file path within the app directory |
|
414 | + $appDirectoryPath = explode($appName, $path)[1]; |
|
415 | + // Remove the webroot |
|
416 | + |
|
417 | + return str_replace($webRoot, '', $appWebPath . $appDirectoryPath); |
|
418 | + } |
|
419 | + |
|
420 | + return $webRoot . substr($path, strlen($serverRoot)); |
|
421 | + } |
|
422 | 422 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $this->defaults = $defaults; |
103 | 103 | $this->serverRoot = $serverRoot; |
104 | 104 | $this->cacheFactory = $cacheFactory; |
105 | - $this->depsCache = $cacheFactory->createDistributed('SCSS-' . md5($this->urlGenerator->getBaseUrl())); |
|
105 | + $this->depsCache = $cacheFactory->createDistributed('SCSS-'.md5($this->urlGenerator->getBaseUrl())); |
|
106 | 106 | $this->iconsCacher = $iconsCacher; |
107 | 107 | } |
108 | 108 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * @throws NotPermittedException |
117 | 117 | */ |
118 | 118 | public function process(string $root, string $file, string $app): bool { |
119 | - $path = explode('/', $root . '/' . $file); |
|
119 | + $path = explode('/', $root.'/'.$file); |
|
120 | 120 | |
121 | 121 | $fileNameSCSS = array_pop($path); |
122 | 122 | $fileNameCSS = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)), $app); |
@@ -171,13 +171,13 @@ discard block |
||
171 | 171 | try { |
172 | 172 | $cachedFile = $folder->getFile($fileNameCSS); |
173 | 173 | if ($cachedFile->getSize() > 0) { |
174 | - $depFileName = $fileNameCSS . '.deps'; |
|
175 | - $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName); |
|
174 | + $depFileName = $fileNameCSS.'.deps'; |
|
175 | + $deps = $this->depsCache->get($folder->getName().'-'.$depFileName); |
|
176 | 176 | if ($deps === null) { |
177 | 177 | $depFile = $folder->getFile($depFileName); |
178 | 178 | $deps = $depFile->getContent(); |
179 | 179 | //Set to memcache for next run |
180 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
180 | + $this->depsCache->set($folder->getName().'-'.$depFileName, $deps); |
|
181 | 181 | } |
182 | 182 | $deps = json_decode($deps, true); |
183 | 183 | |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | $scss = new Compiler(); |
228 | 228 | $scss->setImportPaths([ |
229 | 229 | $path, |
230 | - $this->serverRoot . '/core/css/' |
|
230 | + $this->serverRoot.'/core/css/' |
|
231 | 231 | ]); |
232 | 232 | |
233 | 233 | // Continue after throw |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | $cachedfile = $folder->newFile($fileNameCSS); |
248 | 248 | } |
249 | 249 | |
250 | - $depFileName = $fileNameCSS . '.deps'; |
|
250 | + $depFileName = $fileNameCSS.'.deps'; |
|
251 | 251 | try { |
252 | 252 | $depFile = $folder->getFile($depFileName); |
253 | 253 | } catch (NotFoundException $e) { |
@@ -257,11 +257,11 @@ discard block |
||
257 | 257 | // Compile |
258 | 258 | try { |
259 | 259 | $compiledScss = $scss->compile( |
260 | - '$webroot: \'' . $this->getRoutePrefix() . '\';' . |
|
261 | - '@import "variables.scss";' . |
|
262 | - '@import "functions.scss";' . |
|
263 | - $this->getInjectedVariables() . |
|
264 | - '@import "' . $fileNameSCSS . '";'); |
|
260 | + '$webroot: \''.$this->getRoutePrefix().'\';'. |
|
261 | + '@import "variables.scss";'. |
|
262 | + '@import "functions.scss";'. |
|
263 | + $this->getInjectedVariables(). |
|
264 | + '@import "'.$fileNameSCSS.'";'); |
|
265 | 265 | } catch (ParserException $e) { |
266 | 266 | $this->logger->error($e, ['app' => 'core']); |
267 | 267 | |
@@ -273,9 +273,9 @@ discard block |
||
273 | 273 | |
274 | 274 | // Gzip file |
275 | 275 | try { |
276 | - $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
276 | + $gzipFile = $folder->getFile($fileNameCSS.'.gzip'); # Safari doesn't like .gz |
|
277 | 277 | } catch (NotFoundException $e) { |
278 | - $gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
278 | + $gzipFile = $folder->newFile($fileNameCSS.'.gzip'); # Safari doesn't like .gz |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | try { |
@@ -283,13 +283,13 @@ discard block |
||
283 | 283 | $cachedfile->putContent($data); |
284 | 284 | $deps = json_encode($scss->getParsedFiles()); |
285 | 285 | $depFile->putContent($deps); |
286 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
286 | + $this->depsCache->set($folder->getName().'-'.$depFileName, $deps); |
|
287 | 287 | $gzipFile->putContent(gzencode($data, 9)); |
288 | - $this->logger->debug('SCSSCacher: ' . $webDir . '/' . $fileNameSCSS . ' compiled and successfully cached', ['app' => 'core']); |
|
288 | + $this->logger->debug('SCSSCacher: '.$webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']); |
|
289 | 289 | |
290 | 290 | return true; |
291 | 291 | } catch (NotPermittedException $e) { |
292 | - $this->logger->error('SCSSCacher: unable to cache: ' . $fileNameSCSS); |
|
292 | + $this->logger->error('SCSSCacher: unable to cache: '.$fileNameSCSS); |
|
293 | 293 | |
294 | 294 | return false; |
295 | 295 | } |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | try { |
309 | 309 | $file->delete(); |
310 | 310 | } catch (NotPermittedException $e) { |
311 | - $this->logger->logException($e, ['message' => 'SCSSCacher: unable to delete file: ' . $file->getName()]); |
|
311 | + $this->logger->logException($e, ['message' => 'SCSSCacher: unable to delete file: '.$file->getName()]); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | } |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | } |
324 | 324 | $variables = ''; |
325 | 325 | foreach ($this->defaults->getScssVariables() as $key => $value) { |
326 | - $variables .= '$' . $key . ': ' . $value . ';'; |
|
326 | + $variables .= '$'.$key.': '.$value.';'; |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | // check for valid variables / otherwise fall back to defaults |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | */ |
347 | 347 | private function rebaseUrls(string $css, string $webDir): string { |
348 | 348 | $re = '/url\([\'"]([^\/][\.\w?=\/-]*)[\'"]\)/x'; |
349 | - $subst = 'url(\'' . $webDir . '/$1\')'; |
|
349 | + $subst = 'url(\''.$webDir.'/$1\')'; |
|
350 | 350 | |
351 | 351 | return preg_replace($re, $subst, $css); |
352 | 352 | } |
@@ -371,12 +371,12 @@ discard block |
||
371 | 371 | * @return string |
372 | 372 | */ |
373 | 373 | private function prependBaseurlPrefix(string $cssFile): string { |
374 | - return substr(md5($this->urlGenerator->getBaseUrl() . $this->getRoutePrefix()), 0, 4) . '-' . $cssFile; |
|
374 | + return substr(md5($this->urlGenerator->getBaseUrl().$this->getRoutePrefix()), 0, 4).'-'.$cssFile; |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | private function getRoutePrefix() { |
378 | 378 | $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
379 | - $prefix = \OC::$WEBROOT . '/index.php'; |
|
379 | + $prefix = \OC::$WEBROOT.'/index.php'; |
|
380 | 380 | if ($frontControllerActive) { |
381 | 381 | $prefix = \OC::$WEBROOT; |
382 | 382 | } |
@@ -392,11 +392,11 @@ discard block |
||
392 | 392 | private function prependVersionPrefix(string $cssFile, string $appId): string { |
393 | 393 | $appVersion = \OC_App::getAppVersion($appId); |
394 | 394 | if ($appVersion !== '0') { |
395 | - return substr(md5($appVersion), 0, 4) . '-' . $cssFile; |
|
395 | + return substr(md5($appVersion), 0, 4).'-'.$cssFile; |
|
396 | 396 | } |
397 | 397 | $coreVersion = \OC_Util::getVersionString(); |
398 | 398 | |
399 | - return substr(md5($coreVersion), 0, 4) . '-' . $cssFile; |
|
399 | + return substr(md5($coreVersion), 0, 4).'-'.$cssFile; |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
@@ -414,9 +414,9 @@ discard block |
||
414 | 414 | $appDirectoryPath = explode($appName, $path)[1]; |
415 | 415 | // Remove the webroot |
416 | 416 | |
417 | - return str_replace($webRoot, '', $appWebPath . $appDirectoryPath); |
|
417 | + return str_replace($webRoot, '', $appWebPath.$appDirectoryPath); |
|
418 | 418 | } |
419 | 419 | |
420 | - return $webRoot . substr($path, strlen($serverRoot)); |
|
420 | + return $webRoot.substr($path, strlen($serverRoot)); |
|
421 | 421 | } |
422 | 422 | } |
@@ -34,114 +34,114 @@ |
||
34 | 34 | |
35 | 35 | class IconsCacher { |
36 | 36 | |
37 | - /** @var ILogger */ |
|
38 | - protected $logger; |
|
39 | - |
|
40 | - /** @var IAppData */ |
|
41 | - protected $appData; |
|
42 | - |
|
43 | - /** @var ISimpleFolder */ |
|
44 | - private $folder; |
|
45 | - |
|
46 | - /** @var IURLGenerator */ |
|
47 | - protected $urlGenerator; |
|
48 | - |
|
49 | - /** @var string */ |
|
50 | - private $iconVarRE = '/--(icon-[a-z0-9-]+): url\(["\']([a-z0-9-_\~\/\?\&\=\.]+)[^;]+;/m'; |
|
51 | - |
|
52 | - /** @var string */ |
|
53 | - private $fileName = 'icons-vars.css'; |
|
54 | - |
|
55 | - /** |
|
56 | - * @param ILogger $logger |
|
57 | - * @param Factory $appDataFactory |
|
58 | - * @param IURLGenerator $urlGenerator |
|
59 | - */ |
|
60 | - public function __construct(ILogger $logger, |
|
61 | - Factory $appDataFactory, |
|
62 | - IURLGenerator $urlGenerator) { |
|
63 | - $this->logger = $logger; |
|
64 | - $this->appData = $appDataFactory->get('css'); |
|
65 | - $this->urlGenerator = $urlGenerator; |
|
66 | - |
|
67 | - try { |
|
68 | - $this->folder = $this->appData->getFolder('icons'); |
|
69 | - } catch (NotFoundException $e) { |
|
70 | - $this->folder = $this->appData->newFolder('icons'); |
|
71 | - } |
|
72 | - } |
|
73 | - |
|
74 | - private function getIconsFromCss(string $css): array{ |
|
75 | - preg_match_all($this->iconVarRE, $css, $matches, PREG_SET_ORDER); |
|
76 | - $icons = []; |
|
77 | - foreach ($matches as $icon) { |
|
78 | - $icons[$icon[1]] = $icon[2]; |
|
79 | - } |
|
80 | - |
|
81 | - return $icons; |
|
82 | - } |
|
83 | - /** |
|
84 | - * Parse and cache css |
|
85 | - * |
|
86 | - * @param string $css |
|
87 | - */ |
|
88 | - public function setIconsCss(string $css) { |
|
89 | - |
|
90 | - $cachedFile = $this->getCachedCSS(); |
|
91 | - if (!$cachedFile) { |
|
92 | - $currentData = ''; |
|
93 | - } else { |
|
94 | - $currentData = $cachedFile->getContent(); |
|
95 | - } |
|
96 | - |
|
97 | - // remove :root |
|
98 | - $currentData = str_replace([':root {', '}'], '', $currentData); |
|
99 | - |
|
100 | - $icons = $this->getIconsFromCss($currentData . $css); |
|
101 | - |
|
102 | - $data = ''; |
|
103 | - foreach ($icons as $icon => $url) { |
|
104 | - $data .= "--$icon: url('$url?v=1');"; |
|
105 | - } |
|
106 | - |
|
107 | - if (strlen($data) > 0) { |
|
108 | - if (!$cachedFile) { |
|
109 | - $cachedFile = $this->folder->newFile($this->fileName); |
|
110 | - } |
|
111 | - |
|
112 | - $data = ":root { |
|
37 | + /** @var ILogger */ |
|
38 | + protected $logger; |
|
39 | + |
|
40 | + /** @var IAppData */ |
|
41 | + protected $appData; |
|
42 | + |
|
43 | + /** @var ISimpleFolder */ |
|
44 | + private $folder; |
|
45 | + |
|
46 | + /** @var IURLGenerator */ |
|
47 | + protected $urlGenerator; |
|
48 | + |
|
49 | + /** @var string */ |
|
50 | + private $iconVarRE = '/--(icon-[a-z0-9-]+): url\(["\']([a-z0-9-_\~\/\?\&\=\.]+)[^;]+;/m'; |
|
51 | + |
|
52 | + /** @var string */ |
|
53 | + private $fileName = 'icons-vars.css'; |
|
54 | + |
|
55 | + /** |
|
56 | + * @param ILogger $logger |
|
57 | + * @param Factory $appDataFactory |
|
58 | + * @param IURLGenerator $urlGenerator |
|
59 | + */ |
|
60 | + public function __construct(ILogger $logger, |
|
61 | + Factory $appDataFactory, |
|
62 | + IURLGenerator $urlGenerator) { |
|
63 | + $this->logger = $logger; |
|
64 | + $this->appData = $appDataFactory->get('css'); |
|
65 | + $this->urlGenerator = $urlGenerator; |
|
66 | + |
|
67 | + try { |
|
68 | + $this->folder = $this->appData->getFolder('icons'); |
|
69 | + } catch (NotFoundException $e) { |
|
70 | + $this->folder = $this->appData->newFolder('icons'); |
|
71 | + } |
|
72 | + } |
|
73 | + |
|
74 | + private function getIconsFromCss(string $css): array{ |
|
75 | + preg_match_all($this->iconVarRE, $css, $matches, PREG_SET_ORDER); |
|
76 | + $icons = []; |
|
77 | + foreach ($matches as $icon) { |
|
78 | + $icons[$icon[1]] = $icon[2]; |
|
79 | + } |
|
80 | + |
|
81 | + return $icons; |
|
82 | + } |
|
83 | + /** |
|
84 | + * Parse and cache css |
|
85 | + * |
|
86 | + * @param string $css |
|
87 | + */ |
|
88 | + public function setIconsCss(string $css) { |
|
89 | + |
|
90 | + $cachedFile = $this->getCachedCSS(); |
|
91 | + if (!$cachedFile) { |
|
92 | + $currentData = ''; |
|
93 | + } else { |
|
94 | + $currentData = $cachedFile->getContent(); |
|
95 | + } |
|
96 | + |
|
97 | + // remove :root |
|
98 | + $currentData = str_replace([':root {', '}'], '', $currentData); |
|
99 | + |
|
100 | + $icons = $this->getIconsFromCss($currentData . $css); |
|
101 | + |
|
102 | + $data = ''; |
|
103 | + foreach ($icons as $icon => $url) { |
|
104 | + $data .= "--$icon: url('$url?v=1');"; |
|
105 | + } |
|
106 | + |
|
107 | + if (strlen($data) > 0) { |
|
108 | + if (!$cachedFile) { |
|
109 | + $cachedFile = $this->folder->newFile($this->fileName); |
|
110 | + } |
|
111 | + |
|
112 | + $data = ":root { |
|
113 | 113 | $data |
114 | 114 | }"; |
115 | - $cachedFile->putContent($data); |
|
116 | - } |
|
117 | - |
|
118 | - return preg_replace($this->iconVarRE, '', $css); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Get icons css file |
|
123 | - * @return ISimpleFile|boolean |
|
124 | - */ |
|
125 | - public function getCachedCSS() { |
|
126 | - try { |
|
127 | - return $this->folder->getFile($this->fileName); |
|
128 | - } catch (NotFoundException $e) { |
|
129 | - return false; |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - public function injectCss() { |
|
134 | - // Only inject once |
|
135 | - foreach (\OC_Util::$headers as $header) { |
|
136 | - if ( |
|
137 | - array_key_exists('attributes', $header) && |
|
138 | - array_key_exists('href', $header['attributes']) && |
|
139 | - strpos($header['attributes']['href'], $this->fileName) !== false) { |
|
140 | - return; |
|
141 | - } |
|
142 | - } |
|
143 | - $linkToCSS = substr($this->urlGenerator->linkToRoute('core.Css.getCss', ['appName' => 'icons', 'fileName' => $this->fileName]), strlen(\OC::$WEBROOT)); |
|
144 | - \OC_Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS], null, true); |
|
145 | - } |
|
115 | + $cachedFile->putContent($data); |
|
116 | + } |
|
117 | + |
|
118 | + return preg_replace($this->iconVarRE, '', $css); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Get icons css file |
|
123 | + * @return ISimpleFile|boolean |
|
124 | + */ |
|
125 | + public function getCachedCSS() { |
|
126 | + try { |
|
127 | + return $this->folder->getFile($this->fileName); |
|
128 | + } catch (NotFoundException $e) { |
|
129 | + return false; |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + public function injectCss() { |
|
134 | + // Only inject once |
|
135 | + foreach (\OC_Util::$headers as $header) { |
|
136 | + if ( |
|
137 | + array_key_exists('attributes', $header) && |
|
138 | + array_key_exists('href', $header['attributes']) && |
|
139 | + strpos($header['attributes']['href'], $this->fileName) !== false) { |
|
140 | + return; |
|
141 | + } |
|
142 | + } |
|
143 | + $linkToCSS = substr($this->urlGenerator->linkToRoute('core.Css.getCss', ['appName' => 'icons', 'fileName' => $this->fileName]), strlen(\OC::$WEBROOT)); |
|
144 | + \OC_Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS], null, true); |
|
145 | + } |
|
146 | 146 | |
147 | 147 | } |
148 | 148 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -declare (strict_types = 1); |
|
2 | +declare(strict_types=1); |
|
3 | 3 | /** |
4 | 4 | * @copyright Copyright (c) 2018, John Molakvoæ ([email protected]) |
5 | 5 | * |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | // remove :root |
98 | 98 | $currentData = str_replace([':root {', '}'], '', $currentData); |
99 | 99 | |
100 | - $icons = $this->getIconsFromCss($currentData . $css); |
|
100 | + $icons = $this->getIconsFromCss($currentData.$css); |
|
101 | 101 | |
102 | 102 | $data = ''; |
103 | 103 | foreach ($icons as $icon => $url) { |
@@ -30,72 +30,72 @@ |
||
30 | 30 | |
31 | 31 | class FileChanges implements IFilter { |
32 | 32 | |
33 | - /** @var IL10N */ |
|
34 | - protected $l; |
|
33 | + /** @var IL10N */ |
|
34 | + protected $l; |
|
35 | 35 | |
36 | - /** @var IURLGenerator */ |
|
37 | - protected $url; |
|
36 | + /** @var IURLGenerator */ |
|
37 | + protected $url; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param IL10N $l |
|
41 | - * @param IURLGenerator $url |
|
42 | - */ |
|
43 | - public function __construct(IL10N $l, IURLGenerator $url) { |
|
44 | - $this->l = $l; |
|
45 | - $this->url = $url; |
|
46 | - } |
|
39 | + /** |
|
40 | + * @param IL10N $l |
|
41 | + * @param IURLGenerator $url |
|
42 | + */ |
|
43 | + public function __construct(IL10N $l, IURLGenerator $url) { |
|
44 | + $this->l = $l; |
|
45 | + $this->url = $url; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return string Lowercase a-z only identifier |
|
50 | - * @since 11.0.0 |
|
51 | - */ |
|
52 | - public function getIdentifier() { |
|
53 | - return 'files'; |
|
54 | - } |
|
48 | + /** |
|
49 | + * @return string Lowercase a-z only identifier |
|
50 | + * @since 11.0.0 |
|
51 | + */ |
|
52 | + public function getIdentifier() { |
|
53 | + return 'files'; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return string A translated string |
|
58 | - * @since 11.0.0 |
|
59 | - */ |
|
60 | - public function getName() { |
|
61 | - return $this->l->t('File changes'); |
|
62 | - } |
|
56 | + /** |
|
57 | + * @return string A translated string |
|
58 | + * @since 11.0.0 |
|
59 | + */ |
|
60 | + public function getName() { |
|
61 | + return $this->l->t('File changes'); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return int |
|
66 | - * @since 11.0.0 |
|
67 | - */ |
|
68 | - public function getPriority() { |
|
69 | - return 30; |
|
70 | - } |
|
64 | + /** |
|
65 | + * @return int |
|
66 | + * @since 11.0.0 |
|
67 | + */ |
|
68 | + public function getPriority() { |
|
69 | + return 30; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return string Full URL to an icon, empty string when none is given |
|
74 | - * @since 11.0.0 |
|
75 | - */ |
|
76 | - public function getIcon() { |
|
77 | - return $this->url->getAbsoluteURL($this->url->imagePath('core', 'places/files.svg')); |
|
78 | - } |
|
72 | + /** |
|
73 | + * @return string Full URL to an icon, empty string when none is given |
|
74 | + * @since 11.0.0 |
|
75 | + */ |
|
76 | + public function getIcon() { |
|
77 | + return $this->url->getAbsoluteURL($this->url->imagePath('core', 'places/files.svg')); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param string[] $types |
|
82 | - * @return string[] An array of allowed apps from which activities should be displayed |
|
83 | - * @since 11.0.0 |
|
84 | - */ |
|
85 | - public function filterTypes(array $types) { |
|
86 | - return array_intersect([ |
|
87 | - 'file_created', |
|
88 | - 'file_changed', |
|
89 | - 'file_deleted', |
|
90 | - 'file_restored', |
|
91 | - ], $types); |
|
92 | - } |
|
80 | + /** |
|
81 | + * @param string[] $types |
|
82 | + * @return string[] An array of allowed apps from which activities should be displayed |
|
83 | + * @since 11.0.0 |
|
84 | + */ |
|
85 | + public function filterTypes(array $types) { |
|
86 | + return array_intersect([ |
|
87 | + 'file_created', |
|
88 | + 'file_changed', |
|
89 | + 'file_deleted', |
|
90 | + 'file_restored', |
|
91 | + ], $types); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return string[] An array of allowed apps from which activities should be displayed |
|
96 | - * @since 11.0.0 |
|
97 | - */ |
|
98 | - public function allowedApps() { |
|
99 | - return ['files']; |
|
100 | - } |
|
94 | + /** |
|
95 | + * @return string[] An array of allowed apps from which activities should be displayed |
|
96 | + * @since 11.0.0 |
|
97 | + */ |
|
98 | + public function allowedApps() { |
|
99 | + return ['files']; |
|
100 | + } |
|
101 | 101 | } |
@@ -30,65 +30,65 @@ |
||
30 | 30 | |
31 | 31 | class Calendar implements IFilter { |
32 | 32 | |
33 | - /** @var IL10N */ |
|
34 | - protected $l; |
|
33 | + /** @var IL10N */ |
|
34 | + protected $l; |
|
35 | 35 | |
36 | - /** @var IURLGenerator */ |
|
37 | - protected $url; |
|
36 | + /** @var IURLGenerator */ |
|
37 | + protected $url; |
|
38 | 38 | |
39 | - public function __construct(IL10N $l, IURLGenerator $url) { |
|
40 | - $this->l = $l; |
|
41 | - $this->url = $url; |
|
42 | - } |
|
39 | + public function __construct(IL10N $l, IURLGenerator $url) { |
|
40 | + $this->l = $l; |
|
41 | + $this->url = $url; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return string Lowercase a-z and underscore only identifier |
|
46 | - * @since 11.0.0 |
|
47 | - */ |
|
48 | - public function getIdentifier() { |
|
49 | - return 'calendar'; |
|
50 | - } |
|
44 | + /** |
|
45 | + * @return string Lowercase a-z and underscore only identifier |
|
46 | + * @since 11.0.0 |
|
47 | + */ |
|
48 | + public function getIdentifier() { |
|
49 | + return 'calendar'; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return string A translated string |
|
54 | - * @since 11.0.0 |
|
55 | - */ |
|
56 | - public function getName() { |
|
57 | - return $this->l->t('Calendar'); |
|
58 | - } |
|
52 | + /** |
|
53 | + * @return string A translated string |
|
54 | + * @since 11.0.0 |
|
55 | + */ |
|
56 | + public function getName() { |
|
57 | + return $this->l->t('Calendar'); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return int whether the filter should be rather on the top or bottom of |
|
62 | - * the admin section. The filters are arranged in ascending order of the |
|
63 | - * priority values. It is required to return a value between 0 and 100. |
|
64 | - * @since 11.0.0 |
|
65 | - */ |
|
66 | - public function getPriority() { |
|
67 | - return 40; |
|
68 | - } |
|
60 | + /** |
|
61 | + * @return int whether the filter should be rather on the top or bottom of |
|
62 | + * the admin section. The filters are arranged in ascending order of the |
|
63 | + * priority values. It is required to return a value between 0 and 100. |
|
64 | + * @since 11.0.0 |
|
65 | + */ |
|
66 | + public function getPriority() { |
|
67 | + return 40; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @return string Full URL to an icon, empty string when none is given |
|
72 | - * @since 11.0.0 |
|
73 | - */ |
|
74 | - public function getIcon() { |
|
75 | - return $this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar.svg')); |
|
76 | - } |
|
70 | + /** |
|
71 | + * @return string Full URL to an icon, empty string when none is given |
|
72 | + * @since 11.0.0 |
|
73 | + */ |
|
74 | + public function getIcon() { |
|
75 | + return $this->url->getAbsoluteURL($this->url->imagePath('core', 'places/calendar.svg')); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param string[] $types |
|
80 | - * @return string[] An array of allowed apps from which activities should be displayed |
|
81 | - * @since 11.0.0 |
|
82 | - */ |
|
83 | - public function filterTypes(array $types) { |
|
84 | - return array_intersect(['calendar', 'calendar_event'], $types); |
|
85 | - } |
|
78 | + /** |
|
79 | + * @param string[] $types |
|
80 | + * @return string[] An array of allowed apps from which activities should be displayed |
|
81 | + * @since 11.0.0 |
|
82 | + */ |
|
83 | + public function filterTypes(array $types) { |
|
84 | + return array_intersect(['calendar', 'calendar_event'], $types); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @return string[] An array of allowed apps from which activities should be displayed |
|
89 | - * @since 11.0.0 |
|
90 | - */ |
|
91 | - public function allowedApps() { |
|
92 | - return []; |
|
93 | - } |
|
87 | + /** |
|
88 | + * @return string[] An array of allowed apps from which activities should be displayed |
|
89 | + * @since 11.0.0 |
|
90 | + */ |
|
91 | + public function allowedApps() { |
|
92 | + return []; |
|
93 | + } |
|
94 | 94 | } |