@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | - script('updatenotification', 'admin'); |
|
2 | + script('updatenotification', 'admin'); |
|
3 | 3 | |
4 | - /** @var array $_ */ |
|
5 | - /** @var bool $isNewVersionAvailable */ |
|
6 | - $isNewVersionAvailable = $_['isNewVersionAvailable']; |
|
7 | - /** @var string $newVersionString */ |
|
8 | - $newVersionString = $_['newVersionString']; |
|
9 | - /** @var string $lastCheckedDate */ |
|
10 | - $lastCheckedDate = $_['lastChecked']; |
|
11 | - /** @var array $channels */ |
|
12 | - $channels = $_['channels']; |
|
13 | - /** @var string $currentChannel */ |
|
14 | - $currentChannel = $_['currentChannel']; |
|
4 | + /** @var array $_ */ |
|
5 | + /** @var bool $isNewVersionAvailable */ |
|
6 | + $isNewVersionAvailable = $_['isNewVersionAvailable']; |
|
7 | + /** @var string $newVersionString */ |
|
8 | + $newVersionString = $_['newVersionString']; |
|
9 | + /** @var string $lastCheckedDate */ |
|
10 | + $lastCheckedDate = $_['lastChecked']; |
|
11 | + /** @var array $channels */ |
|
12 | + $channels = $_['channels']; |
|
13 | + /** @var string $currentChannel */ |
|
14 | + $currentChannel = $_['currentChannel']; |
|
15 | 15 | ?> |
16 | 16 | <form id="oca_updatenotification_section" class="followupsection"> |
17 | 17 | <?php if($isNewVersionAvailable === true) { ?> |
@@ -37,139 +37,139 @@ |
||
37 | 37 | use OCP\Settings\ISettings; |
38 | 38 | |
39 | 39 | class AdminController extends Controller implements ISettings { |
40 | - /** @var IJobList */ |
|
41 | - private $jobList; |
|
42 | - /** @var ISecureRandom */ |
|
43 | - private $secureRandom; |
|
44 | - /** @var IConfig */ |
|
45 | - private $config; |
|
46 | - /** @var ITimeFactory */ |
|
47 | - private $timeFactory; |
|
48 | - /** @var UpdateChecker */ |
|
49 | - private $updateChecker; |
|
50 | - /** @var IL10N */ |
|
51 | - private $l10n; |
|
52 | - /** @var IDateTimeFormatter */ |
|
53 | - private $dateTimeFormatter; |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $appName |
|
57 | - * @param IRequest $request |
|
58 | - * @param IJobList $jobList |
|
59 | - * @param ISecureRandom $secureRandom |
|
60 | - * @param IConfig $config |
|
61 | - * @param ITimeFactory $timeFactory |
|
62 | - * @param IL10N $l10n |
|
63 | - * @param UpdateChecker $updateChecker |
|
64 | - * @param IDateTimeFormatter $dateTimeFormatter |
|
65 | - */ |
|
66 | - public function __construct($appName, |
|
67 | - IRequest $request, |
|
68 | - IJobList $jobList, |
|
69 | - ISecureRandom $secureRandom, |
|
70 | - IConfig $config, |
|
71 | - ITimeFactory $timeFactory, |
|
72 | - IL10N $l10n, |
|
73 | - UpdateChecker $updateChecker, |
|
74 | - IDateTimeFormatter $dateTimeFormatter) { |
|
75 | - parent::__construct($appName, $request); |
|
76 | - $this->jobList = $jobList; |
|
77 | - $this->secureRandom = $secureRandom; |
|
78 | - $this->config = $config; |
|
79 | - $this->timeFactory = $timeFactory; |
|
80 | - $this->l10n = $l10n; |
|
81 | - $this->updateChecker = $updateChecker; |
|
82 | - $this->dateTimeFormatter = $dateTimeFormatter; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @return TemplateResponse |
|
87 | - */ |
|
88 | - public function displayPanel() { |
|
89 | - $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime( |
|
90 | - $this->config->getAppValue('core', 'lastupdatedat') |
|
91 | - ); |
|
92 | - |
|
93 | - $channels = [ |
|
94 | - 'daily', |
|
95 | - 'beta', |
|
96 | - 'stable', |
|
97 | - 'production', |
|
98 | - ]; |
|
99 | - $currentChannel = \OCP\Util::getChannel(); |
|
100 | - |
|
101 | - // Remove the currently used channel from the channels list |
|
102 | - if(($key = array_search($currentChannel, $channels)) !== false) { |
|
103 | - unset($channels[$key]); |
|
104 | - } |
|
105 | - $updateState = $this->updateChecker->getUpdateState(); |
|
106 | - |
|
107 | - $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); |
|
108 | - |
|
109 | - $params = [ |
|
110 | - 'isNewVersionAvailable' => !empty($updateState['updateAvailable']), |
|
111 | - 'lastChecked' => $lastUpdateCheck, |
|
112 | - 'currentChannel' => $currentChannel, |
|
113 | - 'channels' => $channels, |
|
114 | - 'newVersionString' => (empty($updateState['updateVersion'])) ? '' : $updateState['updateVersion'], |
|
115 | - 'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'], |
|
116 | - 'updaterEnabled' => (empty($updateState['updaterEnabled'])) ? false : $updateState['updaterEnabled'], |
|
117 | - |
|
118 | - 'notify_groups' => implode('|', $notifyGroups), |
|
119 | - ]; |
|
120 | - |
|
121 | - return new TemplateResponse($this->appName, 'admin', $params, ''); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @UseSession |
|
126 | - * |
|
127 | - * @param string $channel |
|
128 | - * @return DataResponse |
|
129 | - */ |
|
130 | - public function setChannel($channel) { |
|
131 | - \OCP\Util::setChannel($channel); |
|
132 | - $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
133 | - return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @return DataResponse |
|
138 | - */ |
|
139 | - public function createCredentials() { |
|
140 | - // Create a new job and store the creation date |
|
141 | - $this->jobList->add('OCA\UpdateNotification\ResetTokenBackgroundJob'); |
|
142 | - $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()); |
|
143 | - |
|
144 | - // Create a new token |
|
145 | - $newToken = $this->secureRandom->generate(64); |
|
146 | - $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT)); |
|
147 | - |
|
148 | - return new DataResponse($newToken); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
153 | - */ |
|
154 | - public function getForm() { |
|
155 | - return $this->displayPanel(); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @return string the section ID, e.g. 'sharing' |
|
160 | - */ |
|
161 | - public function getSection() { |
|
162 | - return 'server'; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @return int whether the form should be rather on the top or bottom of |
|
167 | - * the admin section. The forms are arranged in ascending order of the |
|
168 | - * priority values. It is required to return a value between 0 and 100. |
|
169 | - * |
|
170 | - * E.g.: 70 |
|
171 | - */ |
|
172 | - public function getPriority() { |
|
173 | - return 1; |
|
174 | - } |
|
40 | + /** @var IJobList */ |
|
41 | + private $jobList; |
|
42 | + /** @var ISecureRandom */ |
|
43 | + private $secureRandom; |
|
44 | + /** @var IConfig */ |
|
45 | + private $config; |
|
46 | + /** @var ITimeFactory */ |
|
47 | + private $timeFactory; |
|
48 | + /** @var UpdateChecker */ |
|
49 | + private $updateChecker; |
|
50 | + /** @var IL10N */ |
|
51 | + private $l10n; |
|
52 | + /** @var IDateTimeFormatter */ |
|
53 | + private $dateTimeFormatter; |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $appName |
|
57 | + * @param IRequest $request |
|
58 | + * @param IJobList $jobList |
|
59 | + * @param ISecureRandom $secureRandom |
|
60 | + * @param IConfig $config |
|
61 | + * @param ITimeFactory $timeFactory |
|
62 | + * @param IL10N $l10n |
|
63 | + * @param UpdateChecker $updateChecker |
|
64 | + * @param IDateTimeFormatter $dateTimeFormatter |
|
65 | + */ |
|
66 | + public function __construct($appName, |
|
67 | + IRequest $request, |
|
68 | + IJobList $jobList, |
|
69 | + ISecureRandom $secureRandom, |
|
70 | + IConfig $config, |
|
71 | + ITimeFactory $timeFactory, |
|
72 | + IL10N $l10n, |
|
73 | + UpdateChecker $updateChecker, |
|
74 | + IDateTimeFormatter $dateTimeFormatter) { |
|
75 | + parent::__construct($appName, $request); |
|
76 | + $this->jobList = $jobList; |
|
77 | + $this->secureRandom = $secureRandom; |
|
78 | + $this->config = $config; |
|
79 | + $this->timeFactory = $timeFactory; |
|
80 | + $this->l10n = $l10n; |
|
81 | + $this->updateChecker = $updateChecker; |
|
82 | + $this->dateTimeFormatter = $dateTimeFormatter; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @return TemplateResponse |
|
87 | + */ |
|
88 | + public function displayPanel() { |
|
89 | + $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime( |
|
90 | + $this->config->getAppValue('core', 'lastupdatedat') |
|
91 | + ); |
|
92 | + |
|
93 | + $channels = [ |
|
94 | + 'daily', |
|
95 | + 'beta', |
|
96 | + 'stable', |
|
97 | + 'production', |
|
98 | + ]; |
|
99 | + $currentChannel = \OCP\Util::getChannel(); |
|
100 | + |
|
101 | + // Remove the currently used channel from the channels list |
|
102 | + if(($key = array_search($currentChannel, $channels)) !== false) { |
|
103 | + unset($channels[$key]); |
|
104 | + } |
|
105 | + $updateState = $this->updateChecker->getUpdateState(); |
|
106 | + |
|
107 | + $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); |
|
108 | + |
|
109 | + $params = [ |
|
110 | + 'isNewVersionAvailable' => !empty($updateState['updateAvailable']), |
|
111 | + 'lastChecked' => $lastUpdateCheck, |
|
112 | + 'currentChannel' => $currentChannel, |
|
113 | + 'channels' => $channels, |
|
114 | + 'newVersionString' => (empty($updateState['updateVersion'])) ? '' : $updateState['updateVersion'], |
|
115 | + 'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'], |
|
116 | + 'updaterEnabled' => (empty($updateState['updaterEnabled'])) ? false : $updateState['updaterEnabled'], |
|
117 | + |
|
118 | + 'notify_groups' => implode('|', $notifyGroups), |
|
119 | + ]; |
|
120 | + |
|
121 | + return new TemplateResponse($this->appName, 'admin', $params, ''); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @UseSession |
|
126 | + * |
|
127 | + * @param string $channel |
|
128 | + * @return DataResponse |
|
129 | + */ |
|
130 | + public function setChannel($channel) { |
|
131 | + \OCP\Util::setChannel($channel); |
|
132 | + $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
133 | + return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @return DataResponse |
|
138 | + */ |
|
139 | + public function createCredentials() { |
|
140 | + // Create a new job and store the creation date |
|
141 | + $this->jobList->add('OCA\UpdateNotification\ResetTokenBackgroundJob'); |
|
142 | + $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()); |
|
143 | + |
|
144 | + // Create a new token |
|
145 | + $newToken = $this->secureRandom->generate(64); |
|
146 | + $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT)); |
|
147 | + |
|
148 | + return new DataResponse($newToken); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
153 | + */ |
|
154 | + public function getForm() { |
|
155 | + return $this->displayPanel(); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @return string the section ID, e.g. 'sharing' |
|
160 | + */ |
|
161 | + public function getSection() { |
|
162 | + return 'server'; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @return int whether the form should be rather on the top or bottom of |
|
167 | + * the admin section. The forms are arranged in ascending order of the |
|
168 | + * priority values. It is required to return a value between 0 and 100. |
|
169 | + * |
|
170 | + * E.g.: 70 |
|
171 | + */ |
|
172 | + public function getPriority() { |
|
173 | + return 1; |
|
174 | + } |
|
175 | 175 | } |
@@ -26,48 +26,48 @@ |
||
26 | 26 | use OC\Updater\VersionCheck; |
27 | 27 | |
28 | 28 | class UpdateChecker { |
29 | - /** @var VersionCheck */ |
|
30 | - private $updater; |
|
29 | + /** @var VersionCheck */ |
|
30 | + private $updater; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @param VersionCheck $updater |
|
34 | - */ |
|
35 | - public function __construct(VersionCheck $updater) { |
|
36 | - $this->updater = $updater; |
|
37 | - } |
|
32 | + /** |
|
33 | + * @param VersionCheck $updater |
|
34 | + */ |
|
35 | + public function __construct(VersionCheck $updater) { |
|
36 | + $this->updater = $updater; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return array |
|
41 | - */ |
|
42 | - public function getUpdateState() { |
|
43 | - $data = $this->updater->check(); |
|
44 | - $result = []; |
|
39 | + /** |
|
40 | + * @return array |
|
41 | + */ |
|
42 | + public function getUpdateState() { |
|
43 | + $data = $this->updater->check(); |
|
44 | + $result = []; |
|
45 | 45 | |
46 | - if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) { |
|
47 | - $result['updateAvailable'] = true; |
|
48 | - $result['updateVersion'] = $data['versionstring']; |
|
49 | - $result['updaterEnabled'] = $data['autoupdater'] === '1'; |
|
50 | - if(substr($data['web'], 0, 8) === 'https://') { |
|
51 | - $result['updateLink'] = $data['web']; |
|
52 | - } |
|
53 | - if(substr($data['url'], 0, 8) === 'https://') { |
|
54 | - $result['downloadLink'] = $data['url']; |
|
55 | - } |
|
46 | + if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) { |
|
47 | + $result['updateAvailable'] = true; |
|
48 | + $result['updateVersion'] = $data['versionstring']; |
|
49 | + $result['updaterEnabled'] = $data['autoupdater'] === '1'; |
|
50 | + if(substr($data['web'], 0, 8) === 'https://') { |
|
51 | + $result['updateLink'] = $data['web']; |
|
52 | + } |
|
53 | + if(substr($data['url'], 0, 8) === 'https://') { |
|
54 | + $result['downloadLink'] = $data['url']; |
|
55 | + } |
|
56 | 56 | |
57 | - return $result; |
|
58 | - } |
|
57 | + return $result; |
|
58 | + } |
|
59 | 59 | |
60 | - return []; |
|
61 | - } |
|
60 | + return []; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param array $data |
|
65 | - */ |
|
66 | - public function getJavaScript(array $data) { |
|
67 | - $data['array']['oc_updateState'] = json_encode([ |
|
68 | - 'updateAvailable' => true, |
|
69 | - 'updateVersion' => $this->getUpdateState()['updateVersion'], |
|
70 | - 'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '', |
|
71 | - ]); |
|
72 | - } |
|
63 | + /** |
|
64 | + * @param array $data |
|
65 | + */ |
|
66 | + public function getJavaScript(array $data) { |
|
67 | + $data['array']['oc_updateState'] = json_encode([ |
|
68 | + 'updateAvailable' => true, |
|
69 | + 'updateVersion' => $this->getUpdateState()['updateVersion'], |
|
70 | + 'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '', |
|
71 | + ]); |
|
72 | + } |
|
73 | 73 | } |
@@ -30,27 +30,27 @@ |
||
30 | 30 | use OCP\AppFramework\IAppContainer; |
31 | 31 | |
32 | 32 | class Application extends App { |
33 | - public function __construct (array $urlParams = array()) { |
|
34 | - parent::__construct('updatenotification', $urlParams); |
|
35 | - $container = $this->getContainer(); |
|
33 | + public function __construct (array $urlParams = array()) { |
|
34 | + parent::__construct('updatenotification', $urlParams); |
|
35 | + $container = $this->getContainer(); |
|
36 | 36 | |
37 | - $container->registerService('AdminController', function(IAppContainer $c) { |
|
38 | - $updater = new \OC\Updater\VersionCheck( |
|
39 | - \OC::$server->getHTTPClientService(), |
|
40 | - \OC::$server->getConfig() |
|
41 | - ); |
|
42 | - return new AdminController( |
|
43 | - $c->query('AppName'), |
|
44 | - $c->query('Request'), |
|
45 | - $c->getServer()->getJobList(), |
|
46 | - $c->getServer()->getSecureRandom(), |
|
47 | - $c->getServer()->getConfig(), |
|
48 | - new TimeFactory(), |
|
49 | - $c->getServer()->getL10N($c->query('AppName')), |
|
50 | - new UpdateChecker($updater), |
|
51 | - $c->getServer()->getDateTimeFormatter() |
|
52 | - ); |
|
53 | - }); |
|
54 | - } |
|
37 | + $container->registerService('AdminController', function(IAppContainer $c) { |
|
38 | + $updater = new \OC\Updater\VersionCheck( |
|
39 | + \OC::$server->getHTTPClientService(), |
|
40 | + \OC::$server->getConfig() |
|
41 | + ); |
|
42 | + return new AdminController( |
|
43 | + $c->query('AppName'), |
|
44 | + $c->query('Request'), |
|
45 | + $c->getServer()->getJobList(), |
|
46 | + $c->getServer()->getSecureRandom(), |
|
47 | + $c->getServer()->getConfig(), |
|
48 | + new TimeFactory(), |
|
49 | + $c->getServer()->getL10N($c->query('AppName')), |
|
50 | + new UpdateChecker($updater), |
|
51 | + $c->getServer()->getDateTimeFormatter() |
|
52 | + ); |
|
53 | + }); |
|
54 | + } |
|
55 | 55 | |
56 | 56 | } |
@@ -34,44 +34,44 @@ |
||
34 | 34 | * @package OCA\UpdateNotification |
35 | 35 | */ |
36 | 36 | class ResetTokenBackgroundJob extends TimedJob { |
37 | - /** @var IConfig */ |
|
38 | - private $config; |
|
39 | - /** @var ITimeFactory */ |
|
40 | - private $timeFactory; |
|
37 | + /** @var IConfig */ |
|
38 | + private $config; |
|
39 | + /** @var ITimeFactory */ |
|
40 | + private $timeFactory; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param IConfig|null $config |
|
44 | - * @param ITimeFactory|null $timeFactory |
|
45 | - */ |
|
46 | - public function __construct(IConfig $config = null, |
|
47 | - ITimeFactory $timeFactory = null) { |
|
48 | - // Run all 10 minutes |
|
49 | - $this->setInterval(60 * 10); |
|
42 | + /** |
|
43 | + * @param IConfig|null $config |
|
44 | + * @param ITimeFactory|null $timeFactory |
|
45 | + */ |
|
46 | + public function __construct(IConfig $config = null, |
|
47 | + ITimeFactory $timeFactory = null) { |
|
48 | + // Run all 10 minutes |
|
49 | + $this->setInterval(60 * 10); |
|
50 | 50 | |
51 | - if ($config instanceof IConfig && $timeFactory instanceof ITimeFactory) { |
|
52 | - $this->config = $config; |
|
53 | - $this->timeFactory = $timeFactory; |
|
54 | - } else { |
|
55 | - $this->fixDIForJobs(); |
|
56 | - } |
|
57 | - } |
|
51 | + if ($config instanceof IConfig && $timeFactory instanceof ITimeFactory) { |
|
52 | + $this->config = $config; |
|
53 | + $this->timeFactory = $timeFactory; |
|
54 | + } else { |
|
55 | + $this->fixDIForJobs(); |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * DI for jobs |
|
61 | - */ |
|
62 | - private function fixDIForJobs() { |
|
63 | - $this->config = \OC::$server->getConfig(); |
|
64 | - $this->timeFactory = new TimeFactory(); |
|
65 | - } |
|
59 | + /** |
|
60 | + * DI for jobs |
|
61 | + */ |
|
62 | + private function fixDIForJobs() { |
|
63 | + $this->config = \OC::$server->getConfig(); |
|
64 | + $this->timeFactory = new TimeFactory(); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param $argument |
|
69 | - */ |
|
70 | - protected function run($argument) { |
|
71 | - // Delete old tokens after 2 days |
|
72 | - if($this->timeFactory->getTime() - $this->config->getAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()) >= 172800) { |
|
73 | - $this->config->deleteSystemValue('updater.secret'); |
|
74 | - } |
|
75 | - } |
|
67 | + /** |
|
68 | + * @param $argument |
|
69 | + */ |
|
70 | + protected function run($argument) { |
|
71 | + // Delete old tokens after 2 days |
|
72 | + if($this->timeFactory->getTime() - $this->config->getAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()) >= 172800) { |
|
73 | + $this->config->deleteSystemValue('updater.secret'); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | } |
@@ -25,6 +25,6 @@ |
||
25 | 25 | |
26 | 26 | $application = new Application(); |
27 | 27 | $application->registerRoutes($this, ['routes' => [ |
28 | - ['name' => 'Admin#createCredentials', 'url' => '/credentials', 'verb' => 'GET'], |
|
29 | - ['name' => 'Admin#setChannel', 'url' => '/channel', 'verb' => 'POST'], |
|
28 | + ['name' => 'Admin#createCredentials', 'url' => '/credentials', 'verb' => 'GET'], |
|
29 | + ['name' => 'Admin#setChannel', 'url' => '/channel', 'verb' => 'POST'], |
|
30 | 30 | ]]); |
@@ -23,33 +23,33 @@ |
||
23 | 23 | */ |
24 | 24 | |
25 | 25 | if(\OC::$server->getConfig()->getSystemValue('updatechecker', true) === true) { |
26 | - $updater = new \OC\Updater\VersionCheck( |
|
27 | - \OC::$server->getHTTPClientService(), |
|
28 | - \OC::$server->getConfig() |
|
29 | - ); |
|
30 | - $updateChecker = new \OCA\UpdateNotification\UpdateChecker( |
|
31 | - $updater |
|
32 | - ); |
|
26 | + $updater = new \OC\Updater\VersionCheck( |
|
27 | + \OC::$server->getHTTPClientService(), |
|
28 | + \OC::$server->getConfig() |
|
29 | + ); |
|
30 | + $updateChecker = new \OCA\UpdateNotification\UpdateChecker( |
|
31 | + $updater |
|
32 | + ); |
|
33 | 33 | |
34 | - $userObject = \OC::$server->getUserSession()->getUser(); |
|
35 | - if($userObject !== null) { |
|
36 | - if(\OC::$server->getGroupManager()->isAdmin($userObject->getUID()) && |
|
37 | - !\OC::$server->getAppManager()->isEnabledForUser('notifications')) { |
|
38 | - if($updateChecker->getUpdateState() !== []) { |
|
39 | - \OCP\Util::addScript('updatenotification', 'notification'); |
|
40 | - OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'getJavaScript'); |
|
41 | - } |
|
42 | - } |
|
43 | - } |
|
34 | + $userObject = \OC::$server->getUserSession()->getUser(); |
|
35 | + if($userObject !== null) { |
|
36 | + if(\OC::$server->getGroupManager()->isAdmin($userObject->getUID()) && |
|
37 | + !\OC::$server->getAppManager()->isEnabledForUser('notifications')) { |
|
38 | + if($updateChecker->getUpdateState() !== []) { |
|
39 | + \OCP\Util::addScript('updatenotification', 'notification'); |
|
40 | + OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'getJavaScript'); |
|
41 | + } |
|
42 | + } |
|
43 | + } |
|
44 | 44 | |
45 | - $manager = \OC::$server->getNotificationManager(); |
|
46 | - $manager->registerNotifier(function() use ($manager) { |
|
47 | - return \OC::$server->query(\OCA\UpdateNotification\Notification\Notifier::class); |
|
48 | - }, function() { |
|
49 | - $l = \OC::$server->getL10N('updatenotification'); |
|
50 | - return [ |
|
51 | - 'id' => 'updatenotification', |
|
52 | - 'name' => $l->t('Update notifications'), |
|
53 | - ]; |
|
54 | - }); |
|
45 | + $manager = \OC::$server->getNotificationManager(); |
|
46 | + $manager->registerNotifier(function() use ($manager) { |
|
47 | + return \OC::$server->query(\OCA\UpdateNotification\Notification\Notifier::class); |
|
48 | + }, function() { |
|
49 | + $l = \OC::$server->getL10N('updatenotification'); |
|
50 | + return [ |
|
51 | + 'id' => 'updatenotification', |
|
52 | + 'name' => $l->t('Update notifications'), |
|
53 | + ]; |
|
54 | + }); |
|
55 | 55 | } |
@@ -1,6 +1,5 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - |
|
4 | 3 | * |
5 | 4 | * @author Bjoern Schiessle <[email protected]> |
6 | 5 | * @author Jan-Christoph Borchardt <[email protected]> |
@@ -30,164 +30,164 @@ |
||
30 | 30 | |
31 | 31 | class Util { |
32 | 32 | |
33 | - /** @var IConfig */ |
|
34 | - private $config; |
|
35 | - |
|
36 | - /** @var IRootFolder */ |
|
37 | - private $rootFolder; |
|
38 | - |
|
39 | - /** @var IAppManager */ |
|
40 | - private $appManager; |
|
41 | - |
|
42 | - /** |
|
43 | - * Util constructor. |
|
44 | - * |
|
45 | - * @param IConfig $config |
|
46 | - * @param IRootFolder $rootFolder |
|
47 | - * @param IAppManager $appManager |
|
48 | - */ |
|
49 | - public function __construct(IConfig $config, IRootFolder $rootFolder, IAppManager $appManager) { |
|
50 | - $this->config = $config; |
|
51 | - $this->rootFolder = $rootFolder; |
|
52 | - $this->appManager = $appManager; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $color rgb color value |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - public function invertTextColor($color) { |
|
60 | - $l = $this->calculateLuminance($color); |
|
61 | - if($l>0.5) { |
|
62 | - return true; |
|
63 | - } else { |
|
64 | - return false; |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * get color for on-page elements: |
|
70 | - * theme color by default, grey if theme color is to bright |
|
71 | - * @param $color |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function elementColor($color) { |
|
75 | - $l = $this->calculateLuminance($color); |
|
76 | - if($l>0.8) { |
|
77 | - return '#555555'; |
|
78 | - } else { |
|
79 | - return $color; |
|
80 | - } |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @param string $color rgb color value |
|
85 | - * @return float |
|
86 | - */ |
|
87 | - public function calculateLuminance($color) { |
|
88 | - $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color); |
|
89 | - if (strlen($hex) === 3) { |
|
90 | - $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2}; |
|
91 | - } |
|
92 | - if (strlen($hex) !== 6) { |
|
93 | - return 0; |
|
94 | - } |
|
95 | - $r = hexdec(substr($hex, 0, 2)); |
|
96 | - $g = hexdec(substr($hex, 2, 2)); |
|
97 | - $b = hexdec(substr($hex, 4, 2)); |
|
98 | - return (0.299 * $r + 0.587 * $g + 0.114 * $b)/255; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @param $color |
|
103 | - * @return string base64 encoded radio button svg |
|
104 | - */ |
|
105 | - public function generateRadioButton($color) { |
|
106 | - $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' . |
|
107 | - '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>'; |
|
108 | - return base64_encode($radioButtonIcon); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @param $app string app name |
|
114 | - * @return string path to app icon / logo |
|
115 | - */ |
|
116 | - public function getAppIcon($app) { |
|
117 | - $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
118 | - try { |
|
119 | - $appPath = $this->appManager->getAppPath($app); |
|
120 | - $icon = $appPath . '/img/' . $app . '.svg'; |
|
121 | - if (file_exists($icon)) { |
|
122 | - return $icon; |
|
123 | - } |
|
124 | - $icon = $appPath . '/img/app.svg'; |
|
125 | - if (file_exists($icon)) { |
|
126 | - return $icon; |
|
127 | - } |
|
128 | - } catch (AppPathNotFoundException $e) {} |
|
129 | - |
|
130 | - if($this->config->getAppValue('theming', 'logoMime', '') !== '' && $this->rootFolder->nodeExists('/themedinstancelogo')) { |
|
131 | - return $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/themedinstancelogo'; |
|
132 | - } |
|
133 | - return \OC::$SERVERROOT . '/core/img/logo.svg'; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @param $app string app name |
|
138 | - * @param $image string relative path to image in app folder |
|
139 | - * @return string|false absolute path to image |
|
140 | - */ |
|
141 | - public function getAppImage($app, $image) { |
|
142 | - $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
143 | - $image = str_replace(array('\0', '\\', '..'), '', $image); |
|
144 | - if ($app === "core") { |
|
145 | - $icon = \OC::$SERVERROOT . '/core/img/' . $image; |
|
146 | - if (file_exists($icon)) { |
|
147 | - return $icon; |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - try { |
|
152 | - $appPath = $this->appManager->getAppPath($app); |
|
153 | - } catch (AppPathNotFoundException $e) { |
|
154 | - return false; |
|
155 | - } |
|
156 | - |
|
157 | - $icon = $appPath . '/img/' . $image; |
|
158 | - if (file_exists($icon)) { |
|
159 | - return $icon; |
|
160 | - } |
|
161 | - $icon = $appPath . '/img/' . $image . '.svg'; |
|
162 | - if (file_exists($icon)) { |
|
163 | - return $icon; |
|
164 | - } |
|
165 | - $icon = $appPath . '/img/' . $image . '.png'; |
|
166 | - if (file_exists($icon)) { |
|
167 | - return $icon; |
|
168 | - } |
|
169 | - $icon = $appPath . '/img/' . $image . '.gif'; |
|
170 | - if (file_exists($icon)) { |
|
171 | - return $icon; |
|
172 | - } |
|
173 | - $icon = $appPath . '/img/' . $image . '.jpg'; |
|
174 | - if (file_exists($icon)) { |
|
175 | - return $icon; |
|
176 | - } |
|
177 | - |
|
178 | - return false; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * replace default color with a custom one |
|
183 | - * |
|
184 | - * @param $svg string content of a svg file |
|
185 | - * @param $color string color to match |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function colorizeSvg($svg, $color) { |
|
189 | - $svg = preg_replace('/#0082c9/i', $color, $svg); |
|
190 | - return $svg; |
|
191 | - } |
|
33 | + /** @var IConfig */ |
|
34 | + private $config; |
|
35 | + |
|
36 | + /** @var IRootFolder */ |
|
37 | + private $rootFolder; |
|
38 | + |
|
39 | + /** @var IAppManager */ |
|
40 | + private $appManager; |
|
41 | + |
|
42 | + /** |
|
43 | + * Util constructor. |
|
44 | + * |
|
45 | + * @param IConfig $config |
|
46 | + * @param IRootFolder $rootFolder |
|
47 | + * @param IAppManager $appManager |
|
48 | + */ |
|
49 | + public function __construct(IConfig $config, IRootFolder $rootFolder, IAppManager $appManager) { |
|
50 | + $this->config = $config; |
|
51 | + $this->rootFolder = $rootFolder; |
|
52 | + $this->appManager = $appManager; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $color rgb color value |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + public function invertTextColor($color) { |
|
60 | + $l = $this->calculateLuminance($color); |
|
61 | + if($l>0.5) { |
|
62 | + return true; |
|
63 | + } else { |
|
64 | + return false; |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * get color for on-page elements: |
|
70 | + * theme color by default, grey if theme color is to bright |
|
71 | + * @param $color |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function elementColor($color) { |
|
75 | + $l = $this->calculateLuminance($color); |
|
76 | + if($l>0.8) { |
|
77 | + return '#555555'; |
|
78 | + } else { |
|
79 | + return $color; |
|
80 | + } |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @param string $color rgb color value |
|
85 | + * @return float |
|
86 | + */ |
|
87 | + public function calculateLuminance($color) { |
|
88 | + $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color); |
|
89 | + if (strlen($hex) === 3) { |
|
90 | + $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2}; |
|
91 | + } |
|
92 | + if (strlen($hex) !== 6) { |
|
93 | + return 0; |
|
94 | + } |
|
95 | + $r = hexdec(substr($hex, 0, 2)); |
|
96 | + $g = hexdec(substr($hex, 2, 2)); |
|
97 | + $b = hexdec(substr($hex, 4, 2)); |
|
98 | + return (0.299 * $r + 0.587 * $g + 0.114 * $b)/255; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @param $color |
|
103 | + * @return string base64 encoded radio button svg |
|
104 | + */ |
|
105 | + public function generateRadioButton($color) { |
|
106 | + $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' . |
|
107 | + '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>'; |
|
108 | + return base64_encode($radioButtonIcon); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @param $app string app name |
|
114 | + * @return string path to app icon / logo |
|
115 | + */ |
|
116 | + public function getAppIcon($app) { |
|
117 | + $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
118 | + try { |
|
119 | + $appPath = $this->appManager->getAppPath($app); |
|
120 | + $icon = $appPath . '/img/' . $app . '.svg'; |
|
121 | + if (file_exists($icon)) { |
|
122 | + return $icon; |
|
123 | + } |
|
124 | + $icon = $appPath . '/img/app.svg'; |
|
125 | + if (file_exists($icon)) { |
|
126 | + return $icon; |
|
127 | + } |
|
128 | + } catch (AppPathNotFoundException $e) {} |
|
129 | + |
|
130 | + if($this->config->getAppValue('theming', 'logoMime', '') !== '' && $this->rootFolder->nodeExists('/themedinstancelogo')) { |
|
131 | + return $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/themedinstancelogo'; |
|
132 | + } |
|
133 | + return \OC::$SERVERROOT . '/core/img/logo.svg'; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @param $app string app name |
|
138 | + * @param $image string relative path to image in app folder |
|
139 | + * @return string|false absolute path to image |
|
140 | + */ |
|
141 | + public function getAppImage($app, $image) { |
|
142 | + $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
143 | + $image = str_replace(array('\0', '\\', '..'), '', $image); |
|
144 | + if ($app === "core") { |
|
145 | + $icon = \OC::$SERVERROOT . '/core/img/' . $image; |
|
146 | + if (file_exists($icon)) { |
|
147 | + return $icon; |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + try { |
|
152 | + $appPath = $this->appManager->getAppPath($app); |
|
153 | + } catch (AppPathNotFoundException $e) { |
|
154 | + return false; |
|
155 | + } |
|
156 | + |
|
157 | + $icon = $appPath . '/img/' . $image; |
|
158 | + if (file_exists($icon)) { |
|
159 | + return $icon; |
|
160 | + } |
|
161 | + $icon = $appPath . '/img/' . $image . '.svg'; |
|
162 | + if (file_exists($icon)) { |
|
163 | + return $icon; |
|
164 | + } |
|
165 | + $icon = $appPath . '/img/' . $image . '.png'; |
|
166 | + if (file_exists($icon)) { |
|
167 | + return $icon; |
|
168 | + } |
|
169 | + $icon = $appPath . '/img/' . $image . '.gif'; |
|
170 | + if (file_exists($icon)) { |
|
171 | + return $icon; |
|
172 | + } |
|
173 | + $icon = $appPath . '/img/' . $image . '.jpg'; |
|
174 | + if (file_exists($icon)) { |
|
175 | + return $icon; |
|
176 | + } |
|
177 | + |
|
178 | + return false; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * replace default color with a custom one |
|
183 | + * |
|
184 | + * @param $svg string content of a svg file |
|
185 | + * @param $color string color to match |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function colorizeSvg($svg, $color) { |
|
189 | + $svg = preg_replace('/#0082c9/i', $color, $svg); |
|
190 | + return $svg; |
|
191 | + } |
|
192 | 192 | |
193 | 193 | } |