Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
55941baf
Commit
55941baf
authored
9 years ago
by
Hanne Moa
Browse files
Options
Downloads
Patches
Plain Diff
Loading templates from themes now work
parent
9fe940b8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/SimpleSAML/XHTML/Template.php
+57
-4
57 additions, 4 deletions
lib/SimpleSAML/XHTML/Template.php
with
57 additions
and
4 deletions
lib/SimpleSAML/XHTML/Template.php
+
57
−
4
View file @
55941baf
...
@@ -38,6 +38,11 @@ class SimpleSAML_XHTML_Template
...
@@ -38,6 +38,11 @@ class SimpleSAML_XHTML_Template
*/
*/
private
$template
=
'default.php'
;
private
$template
=
'default.php'
;
/*
* Main Twig namespace, to avoid misspelling it *again*
*/
private
$twig_namespace
=
\Twig_Loader_Filesystem
::
MAIN_NAMESPACE
;
/**
/**
* Constructor
* Constructor
...
@@ -97,9 +102,17 @@ class SimpleSAML_XHTML_Template
...
@@ -97,9 +102,17 @@ class SimpleSAML_XHTML_Template
$filename
=
$split
[
1
];
$filename
=
$split
[
1
];
}
}
$this
->
twig_template
=
$namespace
?
'@'
.
$namespace
.
'/'
.
$filename
:
$filename
;
$this
->
twig_template
=
$namespace
?
'@'
.
$namespace
.
'/'
.
$filename
:
$filename
;
$loader
=
new
\Twig_Loader_Filesystem
(
$this
->
configuration
->
resolvePath
(
'templates'
));
$loader
=
new
\Twig_Loader_Filesystem
();
foreach
(
$this
->
findModuleTemplateDirs
()
as
$module
=>
$templateDir
)
{
$templateDirs
=
array_merge
(
$loader
->
prependPath
(
$templateDir
,
$module
);
$this
->
findThemeTemplateDirs
(),
$this
->
findModuleTemplateDirs
()
);
// default, themeless templates are checked last
$templateDirs
[]
=
array
(
$this
->
twig_namespace
=>
$this
->
configuration
->
resolvePath
(
'templates'
)
);
foreach
(
$templateDirs
as
$entry
)
{
$loader
->
addPath
(
$entry
[
key
(
$entry
)],
key
(
$entry
));
}
}
if
(
!
$loader
->
exists
(
$this
->
twig_template
))
{
if
(
!
$loader
->
exists
(
$this
->
twig_template
))
{
return
false
;
return
false
;
...
@@ -125,7 +138,47 @@ class SimpleSAML_XHTML_Template
...
@@ -125,7 +138,47 @@ class SimpleSAML_XHTML_Template
return
true
;
return
true
;
}
}
private
function
findThemeTemplateDirs
()
{
// parse config to find theme and module theme is in, if any
$tmp
=
explode
(
':'
,
$this
->
configuration
->
getString
(
'theme.use'
,
'default'
),
2
);
if
(
count
(
$tmp
)
===
2
)
{
$themeModule
=
$tmp
[
0
];
$themeName
=
$tmp
[
1
];
}
else
{
$themeModule
=
null
;
$themeName
=
$tmp
[
0
];
}
// default theme in use, abort
if
(
$themeName
==
'default'
)
{
return
array
();
}
if
(
$themeModule
!==
null
)
{
$moduleDir
=
\SimpleSAML\Module
::
getModuleDir
(
$themeModule
);
$themeDir
=
$moduleDir
.
'/themes/'
.
$themeName
;
$files
=
scandir
(
$themeDir
);
if
(
$files
)
{
$themeTemplateDirs
=
array
();
foreach
(
$files
as
$file
)
{
if
(
$file
==
'.'
||
$file
==
'..'
)
{
continue
;
}
// set correct name for default namespace
$ns
=
$file
==
'default'
?
$this
->
twig_namespace
:
$file
;
$themeTemplateDirs
[]
=
array
(
$ns
=>
$themeDir
.
'/'
.
$file
);
}
return
$themeTemplateDirs
;
}
}
// theme not found
return
array
();
}
/*
* Which enabled modules have templates?
*
* @return an array of module => templatedir lookups
*/
private
function
findModuleTemplateDirs
()
private
function
findModuleTemplateDirs
()
{
{
$all_modules
=
\SimpleSAML\Module
::
getModules
();
$all_modules
=
\SimpleSAML\Module
::
getModules
();
...
@@ -138,7 +191,7 @@ class SimpleSAML_XHTML_Template
...
@@ -138,7 +191,7 @@ class SimpleSAML_XHTML_Template
// check if module has a /templates dir, if so, append
// check if module has a /templates dir, if so, append
$templatedir
=
$moduledir
.
'/templates'
;
$templatedir
=
$moduledir
.
'/templates'
;
if
(
is_dir
(
$templatedir
))
{
if
(
is_dir
(
$templatedir
))
{
$modules
[
$module
]
=
$templatedir
;
$modules
[
]
=
array
(
$module
=
>
$templatedir
)
;
}
}
}
}
return
$modules
;
return
$modules
;
...
...
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