Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
marcus-lodspeakr
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
uib-ub
Spesialsamlingene
marcus-lodspeakr
Merge requests
!12
Get best content type
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Get best content type
getBestContentType
into
master
Overview
0
Commits
3
Pipelines
0
Changes
8
Merged
Stein Magne Bjorklund
requested to merge
getBestContentType
into
master
3 years ago
Overview
0
Commits
3
Pipelines
0
Changes
8
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
9cb1729c
3 commits,
3 years ago
8 files
+
206
−
27
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
8
Search (e.g. *.vue) (Ctrl+P)
classes/Utils.php
+
32
−
19
Options
@@ -124,39 +124,50 @@ class Utils
return
$obj
;
}
public
static
function
getExtension
(
$accept_string
)
public
static
function
getExtension
(
$accept_string
,
array
$configuration
):
string
{
global
$conf
;
$extension
=
"html"
;
foreach
(
$conf
[
'http_accept'
]
as
$ext
=>
$accept_arr
)
{
if
(
in_array
(
$accept_string
,
$accept_arr
))
{
$extension
=
$ext
;
foreach
(
$configuration
as
$extension
=>
$extensions
)
{
if
(
in_array
(
$accept_string
,
$extensions
,
true
))
{
return
$extension
;
}
}
return
$extension
;
return
'html'
;
}
public
static
function
getBestContentType
(
$accept_string
)
/**
* header from the current request, if there is one.
*
* @param $accept_string
* Contents of the Accept: header from the current request.
* @param array $configuration
* @return int|string
*/
public
static
function
getBestContentType
(
$accept_string
,
array
$configuration
)
{
global
$conf
;
$a
=
explode
(
","
,
$accept_string
);
$b
=
array
();
if
(
$a
[
0
]
===
'text/html'
||
$a
[
0
]
===
'text/css'
||
$a
[
0
]
===
'*/*'
)
{
return
'text/html'
;
}
$b
=
[];
foreach
(
$a
as
$v
)
{
foreach
(
$conf
[
'http_accept'
]
as
$formatTypeArray
)
{
if
(
str
str
(
$v
,
";"
))
{
$aux
=
explode
(
";"
,
$v
);
foreach
(
$conf
iguration
as
$formatTypeArray
)
{
if
(
str
pos
(
$v
,
";"
)
!==
false
)
{
$aux
=
explode
(
';'
,
$v
);
$aux
[
0
]
=
trim
(
$aux
[
0
]);
if
(
in_array
(
$aux
[
0
],
$formatTypeArray
))
{
$b
[
$aux
[
0
]]
=
float
val
(
trim
(
str_replace
(
"q="
,
""
,
$aux
[
1
]))
)
;
if
(
in_array
(
$aux
[
0
],
$formatTypeArray
,
true
))
{
$b
[
$aux
[
0
]]
=
(
float
)
trim
(
str_replace
(
"q="
,
""
,
$aux
[
1
]));
}
}
else
{
$value
=
trim
(
$v
);
if
(
in_array
(
$value
,
$formatTypeArray
))
{
if
(
in_array
(
$value
,
$formatTypeArray
,
true
))
{
$b
[
$value
]
=
1.0
;
}
}
}
}
$a
=
$b
;
arsort
(
$a
);
$ct
=
'text/html'
;
@@ -164,9 +175,11 @@ class Utils
$ct
=
$k
;
break
;
}
if
(
$ct
==
null
||
$ct
==
""
||
$ct
==
"*/*"
)
{
$ct
=
'text/html'
;
if
(
$ct
===
null
||
$ct
===
""
||
$ct
===
"*/*"
)
{
return
'text/html'
;
}
return
$ct
;
}
@@ -250,7 +263,7 @@ class Utils
global
$conf
;
global
$lodspk
;
$contentType
=
$lodspk
[
'contentType'
];
$extension
=
Utils
::
getExtension
(
$contentType
);
$extension
=
Utils
::
getExtension
(
$contentType
,
$conf
[
'http_accept'
]
);
header
(
'Content-Type: '
.
$contentType
);
if
(
isset
(
$lodspk
[
'resultRdf'
])
&&
$lodspk
[
'resultRdf'
]
==
true
)
{
Loading