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
378325f9
Commit
378325f9
authored
13 years ago
by
Andreas Gohr
Browse files
Options
Downloads
Patches
Plain Diff
made the tpl_getMediaFile() function more flexible
parent
27833958
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inc/template.php
+41
-15
41 additions, 15 deletions
inc/template.php
with
41 additions
and
15 deletions
inc/template.php
+
41
−
15
View file @
378325f9
...
...
@@ -1459,22 +1459,44 @@ function tpl_flush(){
}
/**
* Returns link to media file from data/media root directory if it exists,
* otherwise the one in the template's image directory.
* Tries to find a ressource file in the given locations.
*
* @param string $fileName - file name of icon
* @param bool $abs - if to use absolute URL
* @author Anika Henke <anika@selfthinker.org>
* If a given location starts with a colon it is assumed to be a media
* file, otherwise it is assumed to be relative to the current template
*
* @param array $search locations to look at
* @param bool $abs if to use absolute URL
* @param arrayref $imginfo filled with getimagesize()
* @author Andreas Gohr <andi@splitbrain.org>
*/
function
tpl_getMediaFile
(
$fileName
,
$abs
=
false
)
{
if
(
file_exists
(
mediaFN
(
$fileName
)))
{
return
ml
(
$fileName
,
''
,
true
,
''
,
$abs
);
function
tpl_getMediaFile
(
$search
,
$abs
=
false
,
&
$imginfo
=
null
){
// loop through candidates until a match was found:
foreach
(
$search
as
$img
){
if
(
substr
(
$img
,
0
,
1
)
==
':'
){
$file
=
mediaFN
(
$img
);
$ismedia
=
true
;
}
else
{
$file
=
DOKU_TPLINC
.
$img
;
$ismedia
=
false
;
}
if
(
file_exists
(
$file
))
break
;
}
if
(
$abs
)
{
return
DOKU_URL
.
substr
(
DOKU_TPL
.
'images/'
.
$fileName
,
strlen
(
DOKU_REL
));
// fetch image data if requested
if
(
!
is_null
(
$imginfo
)){
$imginfo
=
getimagesize
(
$file
);
}
return
DOKU_TPL
.
'images/'
.
$fileName
;
// build URL
if
(
$ismedia
){
$url
=
ml
(
$img
,
''
,
true
,
''
,
$abs
);
}
else
{
$url
=
DOKU_TPL
.
$img
;
if
(
$abs
)
$url
=
DOKU_URL
.
substr
(
$url
,
strlen
(
DOKU_REL
));
}
return
$url
;
}
/**
...
...
@@ -1485,7 +1507,8 @@ function tpl_getMediaFile($fileName, $abs=false) {
* @author Anika Henke <anika@selfthinker.org>
*/
function
tpl_getFavicon
(
$abs
=
false
,
$fileName
=
'favicon.ico'
)
{
return
tpl_getMediaFile
(
$fileName
,
$abs
);
$look
=
array
(
":wiki:
$fileName
"
,
":
$fileName
"
,
"images/
$fileName
"
);
return
tpl_getMediaFile
(
$look
,
$abs
);
}
/**
...
...
@@ -1501,14 +1524,17 @@ function tpl_favicon($types=array('favicon')) {
foreach
(
$types
as
$type
)
{
switch
(
$type
)
{
case
'favicon'
:
$return
.
=
'<link rel="shortcut icon" href="'
.
tpl_getMediaFile
(
'favicon.ico'
)
.
'" />'
.
NL
;
$look
=
array
(
':wiki:favicon.ico'
,
':favicon.ico'
,
'images/favicon.ico'
);
$return
.
=
'<link rel="shortcut icon" href="'
.
tpl_getMediaFile
(
$look
)
.
'" />'
.
NL
;
break
;
case
'mobile'
:
$return
.
=
'<link rel="apple-touch-icon" href="'
.
tpl_getMediaFile
(
'apple-touch-icon.png'
)
.
'" />'
.
NL
;
$look
=
array
(
':wiki:apple-touch-icon.png'
,
':apple-touch-icon.png'
,
'images/apple-touch-icon.ico'
);
$return
.
=
'<link rel="apple-touch-icon" href="'
.
tpl_getMediaFile
(
$look
)
.
'" />'
.
NL
;
break
;
case
'generic'
:
// ideal world solution, which doesn't work in any browser yet
$return
.
=
'<link rel="icon" href="'
.
tpl_getMediaFile
(
'icon.svg'
)
.
'" type="image/svg+xml" />'
.
NL
;
$look
=
array
(
':wiki:favicon.svg'
,
':favicon.svg'
,
'images/favicon.svg'
);
$return
.
=
'<link rel="icon" href="'
.
tpl_getMediaFile
(
$look
)
.
'" type="image/svg+xml" />'
.
NL
;
break
;
}
}
...
...
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