|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Joas Schilling <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
6
|
|
|
* @license AGPL-3.0 |
|
7
|
|
|
* |
|
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
10
|
|
|
* as published by the Free Software Foundation. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OCA\Notifications\AppInfo; |
|
23
|
|
|
|
|
24
|
|
|
use OC\Authentication\Token\IProvider; |
|
25
|
|
|
use OCA\Notifications\App; |
|
26
|
|
|
use OCA\Notifications\Capabilities; |
|
27
|
|
|
use OCA\Notifications\Notifier\AdminNotifications; |
|
28
|
|
|
use OCP\AppFramework\IAppContainer; |
|
29
|
|
|
use OCP\Util; |
|
30
|
|
|
|
|
31
|
|
|
class Application extends \OCP\AppFramework\App { |
|
32
|
16 |
|
public function __construct() { |
|
33
|
16 |
|
parent::__construct('notifications'); |
|
34
|
16 |
|
$container = $this->getContainer(); |
|
35
|
|
|
|
|
36
|
16 |
|
$container->registerCapability(Capabilities::class); |
|
37
|
|
|
|
|
38
|
|
|
// FIXME this is for automatic DI because it is not in DIContainer |
|
39
|
16 |
|
$container->registerService(IProvider::class, function(IAppContainer $c) { |
|
40
|
6 |
|
return $c->getServer()->query(IProvider::class); |
|
41
|
16 |
|
}); |
|
42
|
16 |
|
} |
|
43
|
|
|
|
|
44
|
6 |
|
public function register() { |
|
45
|
6 |
|
$this->registerNotificationApp(); |
|
46
|
6 |
|
$this->registerAdminNotifications(); |
|
47
|
6 |
|
$this->registerUserInterface(); |
|
48
|
6 |
|
} |
|
49
|
|
|
|
|
50
|
6 |
|
protected function registerNotificationApp() { |
|
51
|
6 |
|
$container = $this->getContainer(); |
|
52
|
6 |
|
$container->getServer()->getNotificationManager()->registerApp(function() use($container) { |
|
53
|
1 |
|
return $container->query(App::class); |
|
54
|
6 |
|
}); |
|
55
|
6 |
|
} |
|
56
|
|
|
protected function registerAdminNotifications() { |
|
57
|
|
|
$this->getContainer()->getServer()->getNotificationManager()->registerNotifier(function() { |
|
58
|
|
|
return $this->getContainer()->query(AdminNotifications::class); |
|
59
|
|
|
}, function() { |
|
60
|
|
|
$l = $this->getContainer()->getServer()->getL10NFactory()->get('notifications'); |
|
61
|
|
|
return [ |
|
62
|
|
|
'id' => 'admin_notifications', |
|
63
|
|
|
'name' => $l->t('Admin notifications'), |
|
64
|
|
|
]; |
|
65
|
6 |
|
}); |
|
66
|
6 |
|
} |
|
67
|
|
|
|
|
68
|
6 |
|
protected function registerUserInterface() { |
|
69
|
|
|
// Only display the app on index.php except for public shares |
|
70
|
6 |
|
$server = $this->getContainer()->getServer(); |
|
71
|
6 |
|
$request = $server->getRequest(); |
|
72
|
|
|
|
|
73
|
6 |
|
if ($server->getUserSession()->getUser() !== null |
|
74
|
6 |
|
&& strpos($request->getPathInfo(), '/s/') !== 0 |
|
75
|
6 |
|
&& strpos($request->getPathInfo(), '/login/') !== 0 |
|
76
|
6 |
|
&& substr($request->getScriptName(), 0 - \strlen('/index.php')) === '/index.php') { |
|
77
|
|
|
|
|
78
|
1 |
|
Util::addScript('notifications', 'notifications'); |
|
79
|
1 |
|
Util::addStyle('notifications', 'styles'); |
|
80
|
|
|
} |
|
81
|
6 |
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|