suggested fix for the Serendipity fallback chaining

This fixes the plugin tpl fallback for all plugins, already using the parseTemplate() method. All others, which may still follow the themes fallback (like contactform etc), would need to always be part of the user template $serendipity['template'], or be fixed later on.

This also fixes the backend chaining, which now simply follows the force with a possible engine and then uses $serendipity['template_backend'] (2k11), $serendipity['defaultTemplate'] (2k11), 'default'.

As a third, this now uses the correct preview_iframe.tpl file on save and checks for a correct set jquery_backend.js in the user theme $serendipity['template'].

Please double check this approach for cases I did not find yet. Thanks! :)


References #343
This commit is contained in:
Ian 2015-08-16 18:05:59 +02:00
parent 6b9f08a1fe
commit d5eae21a9c
4 changed files with 27 additions and 20 deletions

View File

@ -254,18 +254,16 @@ function serendipity_set_user_var($name, $val, $authorid, $copy_to_s9y = true) {
* @access public
* @param string The filename to search for in the selected template
* @param string The path selector that tells whether to return a HTTP or realpath
* @param bool Enable to include frontend template fallback chaining (used for wysiwyg Editor custom config files)
* @param bool Enable to include frontend template fallback chaining (used for wysiwyg Editor custom config files, emoticons, etc)
* @param bool Enable to check into $serendipity['template'] or its engine, then fall back to $this->pluginFile dir (used by plugins via parseTemplate() method)
* @return string The full path+filename to the requested file
*/
function serendipity_getTemplateFile($file, $key = 'serendipityHTTPPath', $force_frontend_fallback = false) {
function serendipity_getTemplateFile($file, $key = 'serendipityHTTPPath', $force_frontend_fallback = false, $simple_plugin_fallback = false) {
global $serendipity;
$directories = array();
if (defined('IN_serendipity_admin') && $serendipity['smarty_preview'] == false) {
// Backend will always use our default backend (=defaultTemplate) as fallback.
$directories[] = isset($serendipity['template_backend']) ? $serendipity['template_backend'] . '/' : '';
if ($force_frontend_fallback) {
// If enabled, even when within the admin suite it will be possible to reference files that
// reside within a frontend-only template directory.
@ -278,8 +276,12 @@ function serendipity_getTemplateFile($file, $key = 'serendipityHTTPPath', $force
}
}
$directories[] = $serendipity['defaultTemplate'] .'/';
$directories[] = 'default/';
if (!$simple_plugin_fallback) {
// Backend will always use our default backend (=defaultTemplate) as fallback.
$directories[] = isset($serendipity['template_backend']) ? $serendipity['template_backend'] . '/' : '';
$directories[] = $serendipity['defaultTemplate'] .'/';
$directories[] = 'default/';
}
} else {
$directories[] = isset($serendipity['template']) ? $serendipity['template'] . '/' : '';
if (isset($serendipity['template_engine']) && $serendipity['template_engine'] != null) {
@ -289,11 +291,13 @@ function serendipity_getTemplateFile($file, $key = 'serendipityHTTPPath', $force
}
}
// Frontend templates currently need to fall back to "default" (see "idea"), so that they get the
// output they desire. If templates are based on 2k11, the need to set "Engine: 2k11" in their info.txt
// file.
$directories[] = 'default/';
$directories[] = $serendipity['defaultTemplate'] .'/';
if (!$simple_plugin_fallback) {
// Frontend templates currently need to fall back to "default" (see "idea"), so that they get the
// output they desire. If templates are based on 2k11, they need to set "Engine: 2k11" in their info.txt
// file.
$directories[] = 'default/';
$directories[] = $serendipity['defaultTemplate'] .'/';
}
}
foreach ($directories as $directory) {

View File

@ -144,7 +144,9 @@ function serendipity_printEntryForm($targetURL, $hiddens = array(), $entry = arr
$template_vars['entry_template'] = serendipity_getTemplateFile('admin/entries.tpl', 'serendipityPath');
serendipity_smarty_init();
if (!is_object($serendipity['smarty'])) {
serendipity_smarty_init();
}
$serendipity['smarty']->registerPlugin('modifier', 'emit_htmlarea_code', 'serendipity_emit_htmlarea_code');
$serendipity['smarty']->assign('admin_view', 'entryform');
serendipity_plugin_api::hook_event('backend_entryform_smarty', $template_vars);
@ -153,7 +155,7 @@ function serendipity_printEntryForm($targetURL, $hiddens = array(), $entry = arr
}
function serendipity_emit_htmlarea_code($item, $jsname, $spawnMulti = false) {
# init == true when already editor was already initialized
# init == true when editor was already initialized
static $init = false;
global $serendipity;

View File

@ -1215,7 +1215,7 @@ function serendipity_smarty_show($template, $data = null, $debugtype = null, $de
$serendipity['smarty']->assign($data);
$tplfile = serendipity_getTemplateFile($template, 'serendipityPath');
$tplfile = ($template == 'preview_iframe.tpl') ? serendipity_getTemplateFile($template, 'serendipityPath', true) : serendipity_getTemplateFile($template, 'serendipityPath');
if ($debug !== null) {
if ($debugtype == "HTML") {
$debug = "<!-- Dynamically fetched " . htmlspecialchars(str_replace($serendipity['serendipityPath'], '', $tplfile)) . " on " . date('Y-m-d H:i') . ", called from: " . $debug . " -->\n";
@ -1224,5 +1224,5 @@ function serendipity_smarty_show($template, $data = null, $debugtype = null, $de
}
}
return $debug . $serendipity['smarty']->fetch($tplfile);
return $debug . $serendipity['smarty']->fetch('file:'. $tplfile);
}

View File

@ -46,11 +46,11 @@ function serendipity_plugin_api_frontend_header($event_name, &$bag, &$eventData,
function serendipity_plugin_api_backend_header($event_name, &$bag, &$eventData, $addData) {
global $serendipity;
// Only execute if current template does not have its own jquery.js file
// Only execute if current template does not have its own backend_jquery.js file
// jquery can be disabled if a template's config.inc.php or a plugin sets
// $serendipity['capabilities']['jquery'] = false
$check = serendipity_getTemplateFile('jquery_backend.js');
$check = serendipity_getTemplateFile('jquery_backend.js', 'serendipityPath', true);
if (!$check && $serendipity['capabilities']['jquery_backend']) {
?>
<script src="<?php echo $serendipity['serendipityHTTPPath']; ?>templates/jquery.js"></script>
@ -1636,13 +1636,14 @@ class serendipity_plugin
*
* @access public
* @param string template filename (no directory!)
* @param bool Called by a plugin (defaults true), since we do not have a theme using it yet
* @return string Parsed Smarty return
*/
function &parseTemplate($filename) {
function &parseTemplate($filename, $plugin = true) {
global $serendipity;
$filename = basename($filename);
$tfile = serendipity_getTemplateFile($filename, 'serendipityPath');
$tfile = serendipity_getTemplateFile($filename, 'serendipityPath', true, $plugin); // use the simple plugin fallback stairway
if (!$tfile || $tfile == $filename) {
$tfile = dirname($this->pluginFile) . '/' . $filename;
}