Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dokuwiki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BRIC
dokuwiki
Commits
03293305
Commit
03293305
authored
15 years ago
by
Andreas Gohr
Browse files
Options
Downloads
Patches
Plain Diff
Changed FETCH_MEDIA_4XERROR to FETCH_MEDIA_STATUS
parent
cd98d9c3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/exe/fetch.php
+31
-23
31 additions, 23 deletions
lib/exe/fetch.php
with
31 additions
and
23 deletions
lib/exe/fetch.php
+
31
−
23
View file @
03293305
...
@@ -32,9 +32,11 @@
...
@@ -32,9 +32,11 @@
$MIME
=
'application/octet-stream'
;
$MIME
=
'application/octet-stream'
;
$DL
=
true
;
$DL
=
true
;
}
}
// prepare data for error handling / clean download handling
// check for permissions, preconditions and cache external files
list
(
$STATUS
,
$STATUSMESSAGE
)
=
check4XErrors
(
$MEDIA
,
$FILE
);
// here goes the old 4X error checking
list
(
$STATUS
,
$STATUSMESSAGE
)
=
checkFileStatus
(
$MEDIA
,
$FILE
);
// prepare data for plugin events
$data
=
array
(
'media'
=>
$MEDIA
,
$data
=
array
(
'media'
=>
$MEDIA
,
'file'
=>
$FILE
,
'file'
=>
$FILE
,
'orig'
=>
$FILE
,
'orig'
=>
$FILE
,
...
@@ -47,17 +49,26 @@
...
@@ -47,17 +49,26 @@
'status'
=>
$STATUS
,
'status'
=>
$STATUS
,
'statusmessage'
=>
$STATUSMESSAGE
,
'statusmessage'
=>
$STATUSMESSAGE
,
);
);
// handle any 4XX status messages
// handle the file status
if
(
$STATUS
>=
400
&&
$STATUSMESSAGE
<
500
)
{
$evt
=
new
Doku_Event
(
'FETCH_MEDIA_STATUS'
,
$data
);
$evt
=
new
Doku_Event
(
'FETCH_MEDIA_4XERROR'
,
$data
);
if
(
$evt
->
advise_before
()
)
{
if
(
$evt
->
advise_before
()
)
{
// redirects
if
(
$data
[
'status'
]
>
300
&&
$data
[
'status'
]
<=
304
){
send_redirect
(
$data
[
'statusmessage'
]);
}
// send any non 200 status
if
(
$data
[
'status'
]
!=
200
){
header
(
'HTTP/1.0 '
.
$data
[
'status'
]
.
' '
.
$data
[
'statusmessage'
]);
header
(
'HTTP/1.0 '
.
$data
[
'status'
]
.
' '
.
$data
[
'statusmessage'
]);
}
// die on errors
if
(
$data
[
'status'
]
>
203
){
print
$data
[
'statusmessage'
];
print
$data
[
'statusmessage'
];
exit
;
exit
;
}
}
unset
(
$evt
);
}
}
$evt
->
advise_after
();
unset
(
$evt
);
//handle image resizing/cropping
//handle image resizing/cropping
if
((
substr
(
$MIME
,
0
,
5
)
==
'image'
)
&&
$WIDTH
){
if
((
substr
(
$MIME
,
0
,
5
)
==
'image'
)
&&
$WIDTH
){
...
@@ -67,7 +78,7 @@
...
@@ -67,7 +78,7 @@
$data
[
'file'
]
=
$FILE
=
media_resize_image
(
$data
[
'file'
],
$EXT
,
$WIDTH
,
$HEIGHT
);
$data
[
'file'
]
=
$FILE
=
media_resize_image
(
$data
[
'file'
],
$EXT
,
$WIDTH
,
$HEIGHT
);
}
}
}
}
// finally send the file to the client
// finally send the file to the client
$evt
=
new
Doku_Event
(
'MEDIA_SENDFILE'
,
$data
);
$evt
=
new
Doku_Event
(
'MEDIA_SENDFILE'
,
$data
);
if
(
$evt
->
advise_before
())
{
if
(
$evt
->
advise_before
())
{
...
@@ -131,21 +142,20 @@ function sendFile($file,$mime,$dl,$cache){
...
@@ -131,21 +142,20 @@ function sendFile($file,$mime,$dl,$cache){
}
}
}
}
/*
/**
* File fetch 4XX error checker
* Check for media for preconditions and return correct status code
*
*
* Check for preconditions and return 4XX errors if needed
* READ: MEDIA, MIME, EXT, CACHE
* READ: MEDIA, MIME, EXT, CACHE
* WRITE: MEDIA, FILE, array( STATUS, STATUSMESSAGE )
* WRITE: MEDIA, FILE, array( STATUS, STATUSMESSAGE )
*
*
* @author Gerry Weissbach <gerry.w@gammaproduction.de>
* @author Gerry Weissbach <gerry.w@gammaproduction.de>
* @param $media reference to the media id
* @param $media reference to the media id
* @param $file reference to the file variable
* @param $file reference to the file variable
* @returns array(STATUS, STATUSMESSAGE)
* @returns array(STATUS, STATUSMESSAGE)
*/
*/
function
check
4XError
s
(
&
$media
,
&
$file
)
{
function
check
FileStatu
s
(
&
$media
,
&
$file
)
{
global
$MIME
,
$EXT
,
$CACHE
;
global
$MIME
,
$EXT
,
$CACHE
;
//media to local file
//media to local file
if
(
preg_match
(
'#^(https?)://#i'
,
$media
)){
if
(
preg_match
(
'#^(https?)://#i'
,
$media
)){
//check hash
//check hash
...
@@ -156,8 +166,7 @@ function check4XErrors(&$media, &$file) {
...
@@ -156,8 +166,7 @@ function check4XErrors(&$media, &$file) {
if
(
strncmp
(
$MIME
,
'image/'
,
6
)
==
0
)
$file
=
media_get_from_URL
(
$media
,
$EXT
,
$CACHE
);
if
(
strncmp
(
$MIME
,
'image/'
,
6
)
==
0
)
$file
=
media_get_from_URL
(
$media
,
$EXT
,
$CACHE
);
if
(
!
$file
){
if
(
!
$file
){
//download failed - redirect to original URL
//download failed - redirect to original URL
header
(
'Location: '
.
$media
);
return
array
(
302
,
$media
);
exit
;
}
}
}
else
{
}
else
{
$media
=
cleanID
(
$media
);
$media
=
cleanID
(
$media
);
...
@@ -174,11 +183,10 @@ function check4XErrors(&$media, &$file) {
...
@@ -174,11 +183,10 @@ function check4XErrors(&$media, &$file) {
//check file existance
//check file existance
if
(
!@
file_exists
(
$file
)){
if
(
!@
file_exists
(
$file
)){
// FIXME add some default broken image
return
array
(
404
,
'Not Found'
);
return
array
(
404
,
'Not Found'
);
}
}
return
array
(
null
,
null
);
return
array
(
200
,
null
);
}
}
/**
/**
...
...
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