Commit fd85506f authored by Aaron Wells's avatar Aaron Wells Committed by Gerrit Code Review
Browse files

Allow plugin theme files to live under the /theme and /local directory

Bug 1231755. In order to make it easier for custom theme authors to customize
the appearance of plugins, I'm adding the /theme directory to the search path
for plugin files.

Example: smarty->display('artefact:fun:path/to/file.tpl')

Old searchpath:

/artefact/fun/theme/(themename)/path/to/file.tpl

New searchpath (in order of precedence):

1. /local/theme/artefact/fun/templates/path/to/file.tpl
2. /theme/(themename)/artefact/fun/templates/path/to/file.tpl
3. /artefact/fun/theme/(themename)/path/to/file.tpl

Further notes:

The /local directory doesn't have separate copies for separate
themes. It's a sitewide override of all themes.

For some reason theme directories under plugins don't have a "templates"
directory. The templates sit loose under the theme directory. In my new
version, plugin directories under themes DO have a "templates" directory.

Change-Id: Id90ee1d1dec0bda93a0d30e54229fd7dacbe5b96
parent c17f5da0
......@@ -52,6 +52,19 @@ class Dwoo_Template_Mahara extends Dwoo_Template_File {
// Because this is a plugin template file, we don't want to include any accidental matches against
// core template files with the same name.
$includePath = array();
// First look for a local override.
$includePath[] = get_config('docroot') . "local/theme/{$pluginpath}/templates";
// Then look for files in a custom theme
// - /theme/{themename}/{plugintype}/{pluginname}/templates
foreach ($THEME->inheritance as $theme) {
$includePath[] = get_config('docroot') . "theme/{$theme}/{$pluginpath}/templates";
}
// Lastly look for files in the plugin itself
// - /{plugintype}/{pluginname}/theme/{themename}
// (Plugin templates are loose under the theme directory, not in a "templates" subdirectory)
foreach ($THEME->inheritance as $theme) {
$includePath[] = get_config('docroot') . "{$pluginpath}/theme/{$theme}";
}
......@@ -62,4 +75,4 @@ class Dwoo_Template_Mahara extends Dwoo_Template_File {
// We let Dwoo figure out which one actually has it.
parent::__construct($file, null, null, null, $includePath);
}
}
\ No newline at end of file
}
......@@ -957,7 +957,7 @@ class Theme {
$plugindirectory = ($plugindirectory && substr($plugindirectory, -1) != '/') ? $plugindirectory . '/' : $plugindirectory;
// Local theme overrides come first
$localloc = "local/theme/static/{$filename}";
$localloc = "local/theme/{$plugindirectory}static/{$filename}";
if (is_readable(get_config('docroot') . $localloc)) {
if ($all) {
$list['local'] = $returnprefix . $localloc;
......@@ -969,12 +969,21 @@ class Theme {
// Then check each theme
foreach ($this->inheritance as $themedir) {
if (is_readable(get_config('docroot') . $plugindirectory . 'theme/' . $themedir . '/static/' . $filename)) {
if ($all) {
$list[$themedir] = $returnprefix . $plugindirectory . 'theme/' . $themedir . '/static/' . $filename;
}
else {
return $returnprefix . $plugindirectory . 'theme/' . $themedir . '/static/' . $filename;
$searchloc = array();
// Check in the /theme directory
$searchloc[] = "theme/{$themedir}/{$plugindirectory}static/{$filename}";
if ($plugindirectory) {
// Then check in the plugin's own directory
$searchloc[] = "{$plugindirectory}theme/{$themedir}/static/{$filename}";
}
foreach($searchloc as $loc) {
if (is_readable(get_config('docroot') . $loc)) {
if ($all) {
$list[$themedir] = $returnprefix . $loc;
}
else {
return $returnprefix . $loc;
}
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment