proof-of-concept .js.tpl: Added fallback for serendipity_editor.js.tpl as serendipity_editor.js to default-template, and changed serendipity_get_file to react to .js.tpl-files in template-directories

This commit is contained in:
onli 2013-03-06 14:55:21 +01:00
parent e1526d87b8
commit 0cd974fa6d
6 changed files with 28 additions and 38 deletions

View File

@ -10,7 +10,7 @@
var view_full = '{$CONST.VIEW_FULL}';
var view_hide = '{$CONST.HIDE}';
</script>
<script src="{$serendipityBaseURL}index.php?/plugin/serendipity_editor.js"></script>
<script src="{serendipity_getFile file='admin/serendipity_editor.js'}"></script>
<h2>{$CONST.COMMENTS}</h2>

View File

@ -282,6 +282,11 @@ function serendipity_getTemplateFile($file, $key = 'serendipityHTTPPath') {
if (file_exists($serendipity['serendipityPath'] . $templateFile)) {
return $serendipity[$key] . $templateFile;
}
if (file_exists($serendipity['serendipityPath'] . $templateFile . ".tpl")) {
# catch .js.tpl files served via the template-plugin-api
return $serendipity['baseURL'] . 'index.php?/plugin/' . $file;
}
}
if (preg_match('@\.(tpl|css|php)@i', $file) && !stristr($file, 'plugin')) {
@ -2246,4 +2251,14 @@ function serendipity_passwordhash($cleartext_password) {
}
}
//function serendipity_registerHandler($handler, $link) {
//global $serendipity;
//
//if ( ! is_array($serendipity["handler"])) {
//$serendipity["handler"] = array();
//}
//$serendipity["handler"][$link] = $handler;
//
//}
/* vim: set sts=4 ts=4 expandtab : */

View File

@ -363,6 +363,15 @@ if (preg_match(PAT_ARCHIVES, $uri, $matches) || isset($serendipity['GET']['range
print $data;
exit;
} else if (preg_match(PAT_PLUGIN, $uri, $matches)) {
$serendipity['view'] = 'plugin';
include(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
#echo $serendipity["handler"]["test.js"];
serendipity_plugin_api::hook_event('external_plugin', $matches[2]);
if (!defined('NO_EXIT')) {
exit;
}
} else if (preg_match(PAT_ADMIN, $uri)) {
$serendipity['view'] = 'admin';
$base = $serendipity['baseURL'];
@ -398,15 +407,6 @@ if (preg_match(PAT_ARCHIVES, $uri, $matches) || isset($serendipity['GET']['range
}
include(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
} else if (preg_match(PAT_PLUGIN, $uri, $matches)) {
$serendipity['view'] = 'plugin';
include(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
#echo $serendipity["handler"]["test.js"];
serendipity_plugin_api::hook_event('external_plugin', $matches[2]);
if (!defined('NO_EXIT')) {
exit;
}
} else if ($is_multicat || preg_match(PAT_PERMALINK_CATEGORIES, $uri, $matches)) {
$serendipity['view'] = 'categories';

View File

@ -103,9 +103,10 @@ function serendipity_plugin_api_pre_event_hook($event, &$bag, &$eventData, &$add
// Check what Event is coming in, only react to those we want.
switch($event) {
case 'external_plugin':
echo $eventData;
switch ($eventData) {
case 'serendipity_editor.js':
smarty_show('serendipity_editor.js.tpl');
case 'admin/serendipity_editor.js':
serendipity_smarty_show('admin/serendipity_editor.js.tpl');
break;
}
return true;
@ -113,31 +114,5 @@ function serendipity_plugin_api_pre_event_hook($event, &$bag, &$eventData, &$add
}
}
/* Render a smarty-template
* $template: path to the template-file
* $data: map with the variables to assign
* */
function smarty_show($template, $data = null) {
global $serendipity;
if (!is_object($serendipity['smarty'])) {
serendipity_smarty_init();
}
$serendipity['smarty']->assign($data);
$tfile = serendipity_getTemplateFile($template, 'serendipityPath');
if ($tfile == $template) {
$tfile = dirname(__FILE__) . "/$template";
}
$inclusion = $serendipity['smarty']->security_settings[INCLUDE_ANY];
$serendipity['smarty']->security_settings[INCLUDE_ANY] = true;
$content = $serendipity['smarty']->fetch('file:'. $tfile);
$serendipity['smarty']->security_settings[INCLUDE_ANY] = $inclusion;
echo $content;
}
//echo "registering link to js-handler";
//serendipity_registerHandler(dirname(__FILE__). '/test.php', 'test.js');