@@ -36,52 +36,52 @@ discard block |
||
36 | 36 | |
37 | 37 | $application = new Application(); |
38 | 38 | $application->registerRoutes($this, [ |
39 | - 'routes' => [ |
|
40 | - ['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'], |
|
41 | - ['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'], |
|
42 | - ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'], |
|
43 | - ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'], |
|
44 | - ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'], |
|
45 | - ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'], |
|
46 | - ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'], |
|
47 | - ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'], |
|
48 | - ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'], |
|
49 | - ['name' => 'CSRFToken#index', 'url' => '/csrftoken', 'verb' => 'GET'], |
|
50 | - ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'], |
|
51 | - ['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'], |
|
52 | - ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'], |
|
53 | - ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'], |
|
54 | - ['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'], |
|
55 | - ['name' => 'ClientFlowLogin#redirectPage', 'url' => '/login/flow/redirect', 'verb' => 'GET'], |
|
56 | - ['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'], |
|
57 | - ['name' => 'ClientFlowLogin#grantPage', 'url' => '/login/flow/grant', 'verb' => 'GET'], |
|
58 | - ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'], |
|
59 | - ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'], |
|
60 | - ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'], |
|
61 | - ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'], |
|
62 | - ['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'], |
|
63 | - ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'], |
|
64 | - ['name' => 'Svg#getSvgFromCore', 'url' => '/svg/core/{folder}/{fileName}/{color}', 'verb' => 'GET'], |
|
65 | - ['name' => 'Svg#getSvgFromSettings', 'url' => '/svg/settings/{folder}/{fileName}/{color}', 'verb' => 'GET'], |
|
66 | - ['name' => 'Svg#getSvgFromApp', 'url' => '/svg/{app}/{fileName}/{color}', 'verb' => 'GET'], |
|
67 | - ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'], |
|
68 | - ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'], |
|
69 | - ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'], |
|
70 | - ['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'], |
|
71 | - ['name' => 'WalledGarden#get', 'url' => '/204', 'verb' => 'GET'], |
|
72 | - ['name' => 'Search#search', 'url' => '/core/search', 'verb' => 'GET'], |
|
73 | - ], |
|
74 | - 'ocs' => [ |
|
75 | - ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], |
|
76 | - ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'], |
|
77 | - ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'], |
|
78 | - ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'], |
|
79 | - ['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'], |
|
80 | - ['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'], |
|
81 | - ['root' => '/core', 'name' => 'AutoComplete#get', 'url' => '/autocomplete/get', 'verb' => 'GET'], |
|
82 | - ['root' => '/core', 'name' => 'WhatsNew#get', 'url' => '/whatsnew', 'verb' => 'GET'], |
|
83 | - ['root' => '/core', 'name' => 'WhatsNew#dismiss', 'url' => '/whatsnew', 'verb' => 'POST'], |
|
84 | - ], |
|
39 | + 'routes' => [ |
|
40 | + ['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'], |
|
41 | + ['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'], |
|
42 | + ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'], |
|
43 | + ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'], |
|
44 | + ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'], |
|
45 | + ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'], |
|
46 | + ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'], |
|
47 | + ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'], |
|
48 | + ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'], |
|
49 | + ['name' => 'CSRFToken#index', 'url' => '/csrftoken', 'verb' => 'GET'], |
|
50 | + ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'], |
|
51 | + ['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'], |
|
52 | + ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'], |
|
53 | + ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'], |
|
54 | + ['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'], |
|
55 | + ['name' => 'ClientFlowLogin#redirectPage', 'url' => '/login/flow/redirect', 'verb' => 'GET'], |
|
56 | + ['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'], |
|
57 | + ['name' => 'ClientFlowLogin#grantPage', 'url' => '/login/flow/grant', 'verb' => 'GET'], |
|
58 | + ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'], |
|
59 | + ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'], |
|
60 | + ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'], |
|
61 | + ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'], |
|
62 | + ['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'], |
|
63 | + ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'], |
|
64 | + ['name' => 'Svg#getSvgFromCore', 'url' => '/svg/core/{folder}/{fileName}/{color}', 'verb' => 'GET'], |
|
65 | + ['name' => 'Svg#getSvgFromSettings', 'url' => '/svg/settings/{folder}/{fileName}/{color}', 'verb' => 'GET'], |
|
66 | + ['name' => 'Svg#getSvgFromApp', 'url' => '/svg/{app}/{fileName}/{color}', 'verb' => 'GET'], |
|
67 | + ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'], |
|
68 | + ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'], |
|
69 | + ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'], |
|
70 | + ['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'], |
|
71 | + ['name' => 'WalledGarden#get', 'url' => '/204', 'verb' => 'GET'], |
|
72 | + ['name' => 'Search#search', 'url' => '/core/search', 'verb' => 'GET'], |
|
73 | + ], |
|
74 | + 'ocs' => [ |
|
75 | + ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], |
|
76 | + ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'], |
|
77 | + ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'], |
|
78 | + ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'], |
|
79 | + ['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'], |
|
80 | + ['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'], |
|
81 | + ['root' => '/core', 'name' => 'AutoComplete#get', 'url' => '/autocomplete/get', 'verb' => 'GET'], |
|
82 | + ['root' => '/core', 'name' => 'WhatsNew#get', 'url' => '/whatsnew', 'verb' => 'GET'], |
|
83 | + ['root' => '/core', 'name' => 'WhatsNew#dismiss', 'url' => '/whatsnew', 'verb' => 'POST'], |
|
84 | + ], |
|
85 | 85 | ]); |
86 | 86 | |
87 | 87 | // Post installation check |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | // Core ajax actions |
91 | 91 | // Routing |
92 | 92 | $this->create('core_ajax_update', '/core/ajax/update.php') |
93 | - ->actionInclude('core/ajax/update.php'); |
|
93 | + ->actionInclude('core/ajax/update.php'); |
|
94 | 94 | |
95 | 95 | // File routes |
96 | 96 | $this->create('files.viewcontroller.showFile', '/f/{fileid}')->action(function($urlParams) { |
97 | - $app = new \OCA\Files\AppInfo\Application($urlParams); |
|
98 | - $app->dispatch('ViewController', 'index'); |
|
97 | + $app = new \OCA\Files\AppInfo\Application($urlParams); |
|
98 | + $app->dispatch('ViewController', 'index'); |
|
99 | 99 | }); |
100 | 100 | |
101 | 101 | // Call routes |
@@ -104,12 +104,12 @@ discard block |
||
104 | 104 | * @suppress PhanUndeclaredClassMethod |
105 | 105 | */ |
106 | 106 | $this->create('spreed.pagecontroller.showCall', '/call/{token}')->action(function($urlParams) { |
107 | - if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) { |
|
108 | - $app = new \OCA\Spreed\AppInfo\Application($urlParams); |
|
109 | - $app->dispatch('PageController', 'index'); |
|
110 | - } else { |
|
111 | - throw new \OC\HintException('App spreed is not enabled'); |
|
112 | - } |
|
107 | + if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) { |
|
108 | + $app = new \OCA\Spreed\AppInfo\Application($urlParams); |
|
109 | + $app->dispatch('PageController', 'index'); |
|
110 | + } else { |
|
111 | + throw new \OC\HintException('App spreed is not enabled'); |
|
112 | + } |
|
113 | 113 | }); |
114 | 114 | |
115 | 115 | // OCM routes |
@@ -118,12 +118,12 @@ discard block |
||
118 | 118 | * @suppress PhanUndeclaredClassMethod |
119 | 119 | */ |
120 | 120 | $this->create('cloud_federation_api.requesthandlercontroller.addShare', '/ocm/shares')->post()->action(function($urlParams) { |
121 | - if (class_exists(\OCA\CloudFederationAPI\AppInfo\Application::class, false)) { |
|
122 | - $app = new \OCA\CloudFederationAPI\AppInfo\Application($urlParams); |
|
123 | - $app->dispatch('RequestHandlerController', 'addShare'); |
|
124 | - } else { |
|
125 | - throw new \OC\HintException('Cloud Federation API not enabled'); |
|
126 | - } |
|
121 | + if (class_exists(\OCA\CloudFederationAPI\AppInfo\Application::class, false)) { |
|
122 | + $app = new \OCA\CloudFederationAPI\AppInfo\Application($urlParams); |
|
123 | + $app->dispatch('RequestHandlerController', 'addShare'); |
|
124 | + } else { |
|
125 | + throw new \OC\HintException('Cloud Federation API not enabled'); |
|
126 | + } |
|
127 | 127 | }); |
128 | 128 | |
129 | 129 | /** |
@@ -131,53 +131,53 @@ discard block |
||
131 | 131 | * @suppress PhanUndeclaredClassMethod |
132 | 132 | */ |
133 | 133 | $this->create('cloud_federation_api.requesthandlercontroller.receiveNotification', '/ocm/notifications')->post()->action(function($urlParams) { |
134 | - if (class_exists(\OCA\CloudFederationAPI\AppInfo\Application::class, false)) { |
|
135 | - $app = new \OCA\CloudFederationAPI\AppInfo\Application($urlParams); |
|
136 | - $app->dispatch('RequestHandlerController', 'receiveNotification'); |
|
137 | - } else { |
|
138 | - throw new \OC\HintException('Cloud Federation API not enabled'); |
|
139 | - } |
|
134 | + if (class_exists(\OCA\CloudFederationAPI\AppInfo\Application::class, false)) { |
|
135 | + $app = new \OCA\CloudFederationAPI\AppInfo\Application($urlParams); |
|
136 | + $app->dispatch('RequestHandlerController', 'receiveNotification'); |
|
137 | + } else { |
|
138 | + throw new \OC\HintException('Cloud Federation API not enabled'); |
|
139 | + } |
|
140 | 140 | }); |
141 | 141 | |
142 | 142 | |
143 | 143 | // Sharing routes |
144 | 144 | $this->create('files_sharing.sharecontroller.showShare', '/s/{token}')->action(function($urlParams) { |
145 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
146 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
147 | - $app->dispatch('ShareController', 'showShare'); |
|
148 | - } else { |
|
149 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
150 | - } |
|
145 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
146 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
147 | + $app->dispatch('ShareController', 'showShare'); |
|
148 | + } else { |
|
149 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
150 | + } |
|
151 | 151 | }); |
152 | 152 | $this->create('files_sharing.sharecontroller.authenticate', '/s/{token}/authenticate/{redirect}')->post()->action(function($urlParams) { |
153 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
154 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
155 | - $app->dispatch('ShareController', 'authenticate'); |
|
156 | - } else { |
|
157 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
158 | - } |
|
153 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
154 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
155 | + $app->dispatch('ShareController', 'authenticate'); |
|
156 | + } else { |
|
157 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
158 | + } |
|
159 | 159 | }); |
160 | 160 | $this->create('files_sharing.sharecontroller.showAuthenticate', '/s/{token}/authenticate/{redirect}')->get()->action(function($urlParams) { |
161 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
162 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
163 | - $app->dispatch('ShareController', 'showAuthenticate'); |
|
164 | - } else { |
|
165 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
166 | - } |
|
161 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
162 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
163 | + $app->dispatch('ShareController', 'showAuthenticate'); |
|
164 | + } else { |
|
165 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
166 | + } |
|
167 | 167 | }); |
168 | 168 | $this->create('files_sharing.sharecontroller.downloadShare', '/s/{token}/download')->get()->action(function($urlParams) { |
169 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
170 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
171 | - $app->dispatch('ShareController', 'downloadShare'); |
|
172 | - } else { |
|
173 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
174 | - } |
|
169 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
170 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
171 | + $app->dispatch('ShareController', 'downloadShare'); |
|
172 | + } else { |
|
173 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
174 | + } |
|
175 | 175 | }); |
176 | 176 | $this->create('files_sharing.publicpreview.directLink', '/s/{token}/preview')->get()->action(function($urlParams) { |
177 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
178 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
179 | - $app->dispatch('PublicPreviewController', 'directLink'); |
|
180 | - } else { |
|
181 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
182 | - } |
|
177 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
178 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
179 | + $app->dispatch('PublicPreviewController', 'directLink'); |
|
180 | + } else { |
|
181 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
182 | + } |
|
183 | 183 | }); |
@@ -35,110 +35,110 @@ |
||
35 | 35 | |
36 | 36 | class SvgController extends Controller { |
37 | 37 | |
38 | - /** @var string */ |
|
39 | - protected $serverRoot; |
|
40 | - |
|
41 | - /** @var ITimeFactory */ |
|
42 | - protected $timeFactory; |
|
43 | - |
|
44 | - /** @var IAppManager */ |
|
45 | - protected $appManager; |
|
46 | - |
|
47 | - public function __construct(string $appName, |
|
48 | - IRequest $request, |
|
49 | - ITimeFactory $timeFactory, |
|
50 | - IAppManager $appManager) { |
|
51 | - parent::__construct($appName, $request); |
|
52 | - |
|
53 | - $this->serverRoot = \OC::$SERVERROOT; |
|
54 | - $this->timeFactory = $timeFactory; |
|
55 | - $this->appManager = $appManager; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @NoAdminRequired |
|
60 | - * @NoCSRFRequired |
|
61 | - * |
|
62 | - * Generate svg from filename with the requested color |
|
63 | - * |
|
64 | - * @param string $folder |
|
65 | - * @param string $fileName |
|
66 | - * @param string $color |
|
67 | - * @return DataDisplayResponse|NotFoundResponse |
|
68 | - */ |
|
69 | - public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') { |
|
70 | - $path = $this->serverRoot . "/core/img/$folder/$fileName.svg"; |
|
71 | - return $this->getSvg($path, $color, $fileName); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @NoAdminRequired |
|
76 | - * @NoCSRFRequired |
|
77 | - * |
|
78 | - * Generate svg from filename with the requested color |
|
79 | - * |
|
80 | - * @param string $app |
|
81 | - * @param string $fileName |
|
82 | - * @param string $color |
|
83 | - * @return DataDisplayResponse|NotFoundResponse |
|
84 | - */ |
|
85 | - public function getSvgFromApp(string $app, string $fileName, string $color = 'ffffff') { |
|
86 | - |
|
87 | - if ($app === 'settings') { |
|
88 | - $path = $this->serverRoot . "/settings/img/$fileName.svg"; |
|
89 | - return $this->getSvg($path, $color, $fileName); |
|
90 | - } |
|
91 | - |
|
92 | - $appRootPath = $this->appManager->getAppPath($app); |
|
93 | - $appPath = substr($appRootPath, strlen($this->serverRoot)); |
|
38 | + /** @var string */ |
|
39 | + protected $serverRoot; |
|
40 | + |
|
41 | + /** @var ITimeFactory */ |
|
42 | + protected $timeFactory; |
|
43 | + |
|
44 | + /** @var IAppManager */ |
|
45 | + protected $appManager; |
|
46 | + |
|
47 | + public function __construct(string $appName, |
|
48 | + IRequest $request, |
|
49 | + ITimeFactory $timeFactory, |
|
50 | + IAppManager $appManager) { |
|
51 | + parent::__construct($appName, $request); |
|
52 | + |
|
53 | + $this->serverRoot = \OC::$SERVERROOT; |
|
54 | + $this->timeFactory = $timeFactory; |
|
55 | + $this->appManager = $appManager; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @NoAdminRequired |
|
60 | + * @NoCSRFRequired |
|
61 | + * |
|
62 | + * Generate svg from filename with the requested color |
|
63 | + * |
|
64 | + * @param string $folder |
|
65 | + * @param string $fileName |
|
66 | + * @param string $color |
|
67 | + * @return DataDisplayResponse|NotFoundResponse |
|
68 | + */ |
|
69 | + public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') { |
|
70 | + $path = $this->serverRoot . "/core/img/$folder/$fileName.svg"; |
|
71 | + return $this->getSvg($path, $color, $fileName); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @NoAdminRequired |
|
76 | + * @NoCSRFRequired |
|
77 | + * |
|
78 | + * Generate svg from filename with the requested color |
|
79 | + * |
|
80 | + * @param string $app |
|
81 | + * @param string $fileName |
|
82 | + * @param string $color |
|
83 | + * @return DataDisplayResponse|NotFoundResponse |
|
84 | + */ |
|
85 | + public function getSvgFromApp(string $app, string $fileName, string $color = 'ffffff') { |
|
86 | + |
|
87 | + if ($app === 'settings') { |
|
88 | + $path = $this->serverRoot . "/settings/img/$fileName.svg"; |
|
89 | + return $this->getSvg($path, $color, $fileName); |
|
90 | + } |
|
91 | + |
|
92 | + $appRootPath = $this->appManager->getAppPath($app); |
|
93 | + $appPath = substr($appRootPath, strlen($this->serverRoot)); |
|
94 | 94 | |
95 | - if (!$appPath) { |
|
96 | - return new NotFoundResponse(); |
|
97 | - } |
|
98 | - $path = $this->serverRoot . $appPath ."/img/$fileName.svg"; |
|
99 | - return $this->getSvg($path, $color, $fileName); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Generate svg from filename with the requested color |
|
105 | - * |
|
106 | - * @param string $path |
|
107 | - * @param string $color |
|
108 | - * @return DataDisplayResponse|NotFoundResponse |
|
109 | - */ |
|
110 | - private function getSvg(string $path, string $color, string $fileName) { |
|
111 | - if (!file_exists($path)) { |
|
112 | - return new NotFoundResponse(); |
|
113 | - } |
|
114 | - |
|
115 | - $svg = file_get_contents($path); |
|
116 | - |
|
117 | - if (is_null($svg)) { |
|
118 | - return new NotFoundResponse(); |
|
119 | - } |
|
120 | - |
|
121 | - // add fill (fill is not present on black elements) |
|
122 | - $fillRe = '/<((circle|rect|path)((?!fill)[a-z0-9 =".\-#():;])+)\/>/mi'; |
|
123 | - |
|
124 | - $svg = preg_replace($fillRe, '<$1 fill="#' . $color . '"/>', $svg); |
|
125 | - |
|
126 | - // replace any fill or stroke colors |
|
127 | - $svg = preg_replace('/stroke="#([a-z0-9]{3,6})"/mi', 'stroke="#' . $color . '"', $svg); |
|
128 | - $svg = preg_replace('/fill="#([a-z0-9]{3,6})"/mi', 'fill="#' . $color . '"', $svg); |
|
129 | - |
|
130 | - $response = new DataDisplayResponse($svg, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
|
131 | - |
|
132 | - // Set cache control |
|
133 | - $ttl = 31536000; |
|
134 | - $response->cacheFor($ttl); |
|
135 | - $response->addHeader('Content-Disposition', 'inline; filename="' . $fileName . '.svg"'); |
|
136 | - $expires = new \DateTime(); |
|
137 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
138 | - $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
139 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
140 | - $response->addHeader('Pragma', 'cache'); |
|
141 | - |
|
142 | - return $response; |
|
143 | - } |
|
95 | + if (!$appPath) { |
|
96 | + return new NotFoundResponse(); |
|
97 | + } |
|
98 | + $path = $this->serverRoot . $appPath ."/img/$fileName.svg"; |
|
99 | + return $this->getSvg($path, $color, $fileName); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Generate svg from filename with the requested color |
|
105 | + * |
|
106 | + * @param string $path |
|
107 | + * @param string $color |
|
108 | + * @return DataDisplayResponse|NotFoundResponse |
|
109 | + */ |
|
110 | + private function getSvg(string $path, string $color, string $fileName) { |
|
111 | + if (!file_exists($path)) { |
|
112 | + return new NotFoundResponse(); |
|
113 | + } |
|
114 | + |
|
115 | + $svg = file_get_contents($path); |
|
116 | + |
|
117 | + if (is_null($svg)) { |
|
118 | + return new NotFoundResponse(); |
|
119 | + } |
|
120 | + |
|
121 | + // add fill (fill is not present on black elements) |
|
122 | + $fillRe = '/<((circle|rect|path)((?!fill)[a-z0-9 =".\-#():;])+)\/>/mi'; |
|
123 | + |
|
124 | + $svg = preg_replace($fillRe, '<$1 fill="#' . $color . '"/>', $svg); |
|
125 | + |
|
126 | + // replace any fill or stroke colors |
|
127 | + $svg = preg_replace('/stroke="#([a-z0-9]{3,6})"/mi', 'stroke="#' . $color . '"', $svg); |
|
128 | + $svg = preg_replace('/fill="#([a-z0-9]{3,6})"/mi', 'fill="#' . $color . '"', $svg); |
|
129 | + |
|
130 | + $response = new DataDisplayResponse($svg, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
|
131 | + |
|
132 | + // Set cache control |
|
133 | + $ttl = 31536000; |
|
134 | + $response->cacheFor($ttl); |
|
135 | + $response->addHeader('Content-Disposition', 'inline; filename="' . $fileName . '.svg"'); |
|
136 | + $expires = new \DateTime(); |
|
137 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
138 | + $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
139 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
140 | + $response->addHeader('Pragma', 'cache'); |
|
141 | + |
|
142 | + return $response; |
|
143 | + } |
|
144 | 144 | } |
145 | 145 | \ 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 | * |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @return DataDisplayResponse|NotFoundResponse |
68 | 68 | */ |
69 | 69 | public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') { |
70 | - $path = $this->serverRoot . "/core/img/$folder/$fileName.svg"; |
|
70 | + $path = $this->serverRoot."/core/img/$folder/$fileName.svg"; |
|
71 | 71 | return $this->getSvg($path, $color, $fileName); |
72 | 72 | } |
73 | 73 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | public function getSvgFromApp(string $app, string $fileName, string $color = 'ffffff') { |
86 | 86 | |
87 | 87 | if ($app === 'settings') { |
88 | - $path = $this->serverRoot . "/settings/img/$fileName.svg"; |
|
88 | + $path = $this->serverRoot."/settings/img/$fileName.svg"; |
|
89 | 89 | return $this->getSvg($path, $color, $fileName); |
90 | 90 | } |
91 | 91 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | if (!$appPath) { |
96 | 96 | return new NotFoundResponse(); |
97 | 97 | } |
98 | - $path = $this->serverRoot . $appPath ."/img/$fileName.svg"; |
|
98 | + $path = $this->serverRoot.$appPath."/img/$fileName.svg"; |
|
99 | 99 | return $this->getSvg($path, $color, $fileName); |
100 | 100 | } |
101 | 101 | |
@@ -121,21 +121,21 @@ discard block |
||
121 | 121 | // add fill (fill is not present on black elements) |
122 | 122 | $fillRe = '/<((circle|rect|path)((?!fill)[a-z0-9 =".\-#():;])+)\/>/mi'; |
123 | 123 | |
124 | - $svg = preg_replace($fillRe, '<$1 fill="#' . $color . '"/>', $svg); |
|
124 | + $svg = preg_replace($fillRe, '<$1 fill="#'.$color.'"/>', $svg); |
|
125 | 125 | |
126 | 126 | // replace any fill or stroke colors |
127 | - $svg = preg_replace('/stroke="#([a-z0-9]{3,6})"/mi', 'stroke="#' . $color . '"', $svg); |
|
128 | - $svg = preg_replace('/fill="#([a-z0-9]{3,6})"/mi', 'fill="#' . $color . '"', $svg); |
|
127 | + $svg = preg_replace('/stroke="#([a-z0-9]{3,6})"/mi', 'stroke="#'.$color.'"', $svg); |
|
128 | + $svg = preg_replace('/fill="#([a-z0-9]{3,6})"/mi', 'fill="#'.$color.'"', $svg); |
|
129 | 129 | |
130 | 130 | $response = new DataDisplayResponse($svg, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
131 | 131 | |
132 | 132 | // Set cache control |
133 | 133 | $ttl = 31536000; |
134 | 134 | $response->cacheFor($ttl); |
135 | - $response->addHeader('Content-Disposition', 'inline; filename="' . $fileName . '.svg"'); |
|
135 | + $response->addHeader('Content-Disposition', 'inline; filename="'.$fileName.'.svg"'); |
|
136 | 136 | $expires = new \DateTime(); |
137 | 137 | $expires->setTimestamp($this->timeFactory->getTime()); |
138 | - $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
138 | + $expires->add(new \DateInterval('PT'.$ttl.'S')); |
|
139 | 139 | $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
140 | 140 | $response->addHeader('Pragma', 'cache'); |
141 | 141 |