Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
fc0e6218
Unverified
Commit
fc0e6218
authored
6 years ago
by
John Molakvoæ
Browse files
Options
Downloads
Patches
Plain Diff
Fixed webroot detection
Signed-off-by:
John Molakvoæ (skjnldsv)
<
skjnldsv@protonmail.com
>
parent
1aa7fd89
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/accessibility/css/themedark.scss
+2
-1
2 additions, 1 deletion
apps/accessibility/css/themedark.scss
apps/accessibility/lib/Controller/AccessibilityController.php
+59
-3
59 additions, 3 deletions
.../accessibility/lib/Controller/AccessibilityController.php
with
61 additions
and
4 deletions
apps/accessibility/css/themedark.scss
+
2
−
1
View file @
fc0e6218
...
@@ -18,6 +18,7 @@ $color-border: lighten($color-main-background, 7%);
...
@@ -18,6 +18,7 @@ $color-border: lighten($color-main-background, 7%);
$color-border-dark
:
lighten
(
$color-main-background
,
14%
);
$color-border-dark
:
lighten
(
$color-main-background
,
14%
);
#app-navigation
>
ul
>
li
>
a
:first-child
img
,
#app-navigation
>
ul
>
li
>
a
:first-child
img
,
#app-navigation
>
ul
>
li
>
ul
>
li
>
a
:first-child
img
{
#app-navigation
>
ul
>
li
>
ul
>
li
>
a
:first-child
img
,
#expanddiv
a
img
{
filter
:
invert
(
100%
);
filter
:
invert
(
100%
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
apps/accessibility/lib/Controller/AccessibilityController.php
+
59
−
3
View file @
fc0e6218
...
@@ -111,8 +111,9 @@ class AccessibilityController extends Controller {
...
@@ -111,8 +111,9 @@ class AccessibilityController extends Controller {
public
function
getCss
():
DataDisplayResponse
{
public
function
getCss
():
DataDisplayResponse
{
$css
=
''
;
$css
=
''
;
$imports
=
''
;
$imports
=
''
;
$userValues
=
$this
->
getUserValues
();
foreach
(
$
this
->
getU
serValues
()
as
$key
=>
$scssFile
)
{
foreach
(
$
u
serValues
as
$key
=>
$scssFile
)
{
if
(
$scssFile
!==
false
)
{
if
(
$scssFile
!==
false
)
{
$imports
.
=
'@import "'
.
$scssFile
.
'";'
;
$imports
.
=
'@import "'
.
$scssFile
.
'";'
;
}
}
...
@@ -144,6 +145,16 @@ class AccessibilityController extends Controller {
...
@@ -144,6 +145,16 @@ class AccessibilityController extends Controller {
// We don't want to override vars with url since path is different
// We don't want to override vars with url since path is different
$css
=
$this
->
filterOutRule
(
'/--[a-z-:]+url\([^;]+\)/mi'
,
$css
);
$css
=
$this
->
filterOutRule
(
'/--[a-z-:]+url\([^;]+\)/mi'
,
$css
);
// Calculate exact absolute path to file
$path
=
$this
->
urlGenerator
->
linkToRoute
(
$this
->
appName
.
'.accessibility.getCss'
,
[
'md5'
=>
md5
(
implode
(
'-'
,
$userValues
))]);
$path
=
explode
(
'/'
,
$this
->
serverRoot
.
$path
);
array_pop
(
$path
);
$path
=
implode
(
'/'
,
$path
);
$webDir
=
$this
->
getWebDir
(
$path
,
$this
->
appName
,
$this
->
serverRoot
,
\OC
::
$WEBROOT
);
// Rebase all urls
$css
=
$this
->
rebaseUrls
(
$css
,
$webDir
);
$response
=
new
DataDisplayResponse
(
$css
,
Http
::
STATUS_OK
,
[
'Content-Type'
=>
'text/css'
]);
$response
=
new
DataDisplayResponse
(
$css
,
Http
::
STATUS_OK
,
[
'Content-Type'
=>
'text/css'
]);
// Set cache control
// Set cache control
...
@@ -158,15 +169,60 @@ class AccessibilityController extends Controller {
...
@@ -158,15 +169,60 @@ class AccessibilityController extends Controller {
return
$response
;
return
$response
;
}
}
private
function
getUserValues
()
{
/**
* Return an array with the user theme & font settings
*
* @return array
*/
private
function
getUserValues
():
array
{
$userTheme
=
$this
->
config
->
getUserValue
(
$this
->
userSession
->
getUser
()
->
getUID
(),
$this
->
appName
,
'theme'
,
false
);
$userTheme
=
$this
->
config
->
getUserValue
(
$this
->
userSession
->
getUser
()
->
getUID
(),
$this
->
appName
,
'theme'
,
false
);
$userFont
=
$this
->
config
->
getUserValue
(
$this
->
userSession
->
getUser
()
->
getUID
(),
$this
->
appName
,
'font'
,
false
);
$userFont
=
$this
->
config
->
getUserValue
(
$this
->
userSession
->
getUser
()
->
getUID
(),
$this
->
appName
,
'font'
,
false
);
return
[
$userTheme
,
$userFont
];
return
[
$userTheme
,
$userFont
];
}
}
private
function
filterOutRule
(
string
$rule
,
string
$css
)
{
/**
* Remove all matches from the $rule regex
*
* @param string $rule regex to match
* @param string $css string to parse
* @return string
*/
private
function
filterOutRule
(
string
$rule
,
string
$css
):
string
{
return
preg_replace
(
$rule
,
''
,
$css
);
return
preg_replace
(
$rule
,
''
,
$css
);
}
}
/**
* Add the correct uri prefix to make uri valid again
*
* @param string $css
* @param string $webDir
* @return string
*/
private
function
rebaseUrls
(
string
$css
,
string
$webDir
):
string
{
$re
=
'/url\([\'"]([^\/][\.\w?=\/-]*)[\'"]\)/x'
;
$subst
=
'url(\''
.
$webDir
.
'/$1\')'
;
return
preg_replace
(
$re
,
$subst
,
$css
);
}
/**
* Get WebDir root
* @param string $path the css file path
* @param string $appName the app name
* @param string $serverRoot the server root path
* @param string $webRoot the nextcloud installation root path
* @return string the webDir
*/
private
function
getWebDir
(
string
$path
,
string
$appName
,
string
$serverRoot
,
string
$webRoot
):
string
{
// Detect if path is within server root AND if path is within an app path
if
(
strpos
(
$path
,
$serverRoot
)
===
false
&&
$appWebPath
=
\OC_App
::
getAppWebPath
(
$appName
))
{
// Get the file path within the app directory
$appDirectoryPath
=
explode
(
$appName
,
$path
)[
1
];
// Remove the webroot
return
str_replace
(
$webRoot
,
''
,
$appWebPath
.
$appDirectoryPath
);
}
return
$webRoot
.
substr
(
$path
,
strlen
(
$serverRoot
));
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment