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
Commits
6e00b2c7
Commit
6e00b2c7
authored
3 years ago
by
Stein Magne Bjorklund
Browse files
Options
Downloads
Patches
Plain Diff
Issue 6 Reformatting old module code
- Improve readability
parent
d5fe2b0b
No related branches found
No related tags found
1 merge request
!5
add check for static dir and static/img
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
classes/modules/staticModule.php
+91
-81
91 additions, 81 deletions
classes/modules/staticModule.php
with
91 additions
and
81 deletions
classes/modules/staticModule.php
+
91
−
81
View file @
6e00b2c7
<?php
<?php
require_once
(
'abstractModule.php'
);
require_once
(
'abstractModule.php'
);
class
StaticModule
extends
abstractModule
{
class
StaticModule
extends
abstractModule
{
//Static module
public
function
match
(
$uri
)
public
function
match
(
$uri
){
{
global
$conf
;
global
$conf
;
global
$localUri
;
global
$localUri
;
global
$uri
;
global
$uri
;
global
$acceptContentType
;
global
$acceptContentType
;
global
$endpoints
;
global
$endpoints
;
global
$lodspk
;
global
$lodspk
;
$q
=
preg_replace
(
'|^'
.
$conf
[
'basedir'
]
.
'|'
,
''
,
$localUri
);
$q
=
preg_replace
(
'|^'
.
$conf
[
'basedir'
]
.
'|'
,
''
,
$localUri
);
if
(
strlen
(
$q
)
>
0
&&
file_exists
(
$conf
[
'home'
]
.
$conf
[
'static'
][
'directory'
]
.
$q
)){
return
$q
;
if
(
strlen
(
$q
)
>
0
&&
file_exists
(
$conf
[
'home'
]
.
$conf
[
'static'
][
'directory'
]
.
$q
))
{
}
return
$q
;
return
FALSE
;
}
return
FALSE
;
}
}
public
function
execute
(
$file
){
public
function
execute
(
$file
)
global
$conf
;
{
global
$localUri
;
global
$conf
;
global
$uri
;
global
$localUri
;
global
$acceptContentType
;
global
$uri
;
global
$endpoints
;
global
$acceptContentType
;
global
$lodspk
;
global
$endpoints
;
global
$lodspk
;
$this
->
validateDirectory
(
$conf
,
$file
);
$this
->
validateDirectory
(
$conf
,
$file
);
$filenamearray
=
explode
(
"."
,
$file
);
$filenamearray
=
explode
(
"."
,
$file
);
$extension
=
end
(
$filenamearray
);
$extension
=
end
(
$filenamearray
);
$ct
=
$this
->
getContentType
(
$extension
);
$ct
=
$this
->
getContentType
(
$extension
);
header
(
"Content-type: "
.
$ct
);
header
(
"Content-type: "
.
$ct
);
$uri
=
$localUri
;
$uri
=
$localUri
;
if
(
$conf
[
'debug'
]){
Logging
::
log
(
"In "
.
$conf
[
'static'
][
'directory'
]
.
" static file
$file
"
);
if
(
$conf
[
'debug'
])
{
}
Logging
::
log
(
"In "
.
$conf
[
'static'
][
'directory'
]
.
" static file
$file
"
);
$htmlExtension
=
'html'
;
}
if
(
$conf
[
'static'
][
'haanga'
]
&&
substr_compare
(
$file
,
$htmlExtension
,
-
strlen
(
$htmlExtension
),
strlen
(
$htmlExtension
))
===
0
){
$htmlExtension
=
'html'
;
$lodspk
[
'home'
]
=
$conf
[
'basedir'
];
$lodspk
[
'baseUrl'
]
=
$conf
[
'basedir'
];
if
(
$conf
[
'static'
][
'haanga'
]
&&
substr_compare
(
$file
,
$htmlExtension
,
-
strlen
(
$htmlExtension
),
strlen
(
$htmlExtension
))
===
0
)
{
$lodspk
[
'module'
]
=
'static'
;
$lodspk
[
'home'
]
=
$conf
[
'basedir'
];
$lodspk
[
'root'
]
=
$conf
[
'root'
];
$lodspk
[
'baseUrl'
]
=
$conf
[
'basedir'
];
$lodspk
[
'contentType'
]
=
$acceptContentType
;
$lodspk
[
'module'
]
=
'static'
;
$lodspk
[
'ns'
]
=
$conf
[
'ns'
];
$lodspk
[
'root'
]
=
$conf
[
'root'
];
$lodspk
[
'this'
][
'value'
]
=
$localUri
;
$lodspk
[
'contentType'
]
=
$acceptContentType
;
$lodspk
[
'this'
][
'curie'
]
=
Utils
::
uri2curie
(
$localUri
);
$lodspk
[
'ns'
]
=
$conf
[
'ns'
];
$lodspk
[
'local'
][
'value'
]
=
$localUri
;
$lodspk
[
'this'
][
'value'
]
=
$localUri
;
$lodspk
[
'local'
][
'curie'
]
=
Utils
::
uri2curie
(
$localUri
);
$lodspk
[
'this'
][
'curie'
]
=
Utils
::
uri2curie
(
$localUri
);
$lodspk
[
'contentType'
]
=
$acceptContentType
;
$lodspk
[
'local'
][
'value'
]
=
$localUri
;
$lodspk
[
'endpoint'
]
=
$conf
[
'endpoint'
];
$lodspk
[
'local'
][
'curie'
]
=
Utils
::
uri2curie
(
$localUri
);
$lodspk
[
'baseUrl'
]
=
$conf
[
'basedir'
];
$lodspk
[
'contentType'
]
=
$acceptContentType
;
$lodspk
[
'endpoint'
]
=
$conf
[
'endpoint'
];
Utils
::
processDocument
(
$conf
[
'static'
][
'directory'
]
.
$file
,
$lodspk
,
null
);
$lodspk
[
'baseUrl'
]
=
$conf
[
'basedir'
];
}
else
{
echo
file_get_contents
(
$conf
[
'static'
][
'directory'
]
.
$file
);
Utils
::
processDocument
(
$conf
[
'static'
][
'directory'
]
.
$file
,
$lodspk
,
null
);
}
}
else
{
echo
file_get_contents
(
$conf
[
'static'
][
'directory'
]
.
$file
);
}
}
}
private
function
getContentType
(
$e
){
private
function
getContentType
(
$e
)
$contentTypes
=
array
(
'html'
=>
'text/html'
,
{
'css'
=>
'text/css'
,
$contentTypes
=
[
'js'
=>
'application/javascript'
,
'html'
=>
'text/html'
,
'json'
=>
'application/json'
,
'css'
=>
'text/css'
,
'jsonp'
=>
'application/javascript'
,
'js'
=>
'application/javascript'
,
'nt'
=>
'text/plain'
,
'json'
=>
'application/json'
,
'ttl'
=>
'text/turtle'
,
'jsonp'
=>
'application/javascript'
,
'png'
=>
'image/png'
,
'nt'
=>
'text/plain'
,
'jpg'
=>
'image/jpeg'
,
'ttl'
=>
'text/turtle'
,
'gif'
=>
'image/gif'
,
'png'
=>
'image/png'
,
'bmp'
=>
'image/bmp'
,
'jpg'
=>
'image/jpeg'
,
'pdf'
=>
'application/pdf'
,
'gif'
=>
'image/gif'
,
'zip'
=>
'application/zip'
,
'bmp'
=>
'image/bmp'
,
'gz'
=>
'application/gzip'
,
'pdf'
=>
'application/pdf'
,
'svg'
=>
'image/svg+xml'
'zip'
=>
'application/zip'
,
);
'gz'
=>
'application/gzip'
,
'svg'
=>
'image/svg+xml'
,
//Add new/override existing mime types defined by user
];
if
(
isset
(
$conf
[
'static'
][
'mimetypes'
])){
foreach
(
$conf
[
'static'
][
'mimetypes'
]
as
$k
=>
$v
){
//Add new/override existing mime types defined by user.
$contentTypes
[
$k
]
=
$v
;
if
(
isset
(
$conf
[
'static'
][
'mimetypes'
]))
{
}
foreach
(
$conf
[
'static'
][
'mimetypes'
]
as
$k
=>
$v
)
{
}
$contentTypes
[
$k
]
=
$v
;
}
if
(
isset
(
$contentTypes
[
$e
])){
}
return
$contentTypes
[
$e
];
}
if
(
isset
(
$contentTypes
[
$e
]))
{
return
""
;
//empty string seems to work fine with browsers
return
$contentTypes
[
$e
];
}
return
""
;
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
Stein Magne Bjorklund
@steinmb
mentioned in merge request
!8 (merged)
·
3 years ago
mentioned in merge request
!8 (merged)
mentioned in merge request !8
Toggle commit list
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