diff --git a/include/functions_config.inc.php b/include/functions_config.inc.php index 203d0e52..5413814e 100644 --- a/include/functions_config.inc.php +++ b/include/functions_config.inc.php @@ -288,9 +288,8 @@ function serendipity_getTemplateFile($file, $key = 'serendipityHTTPPath') { return $serendipity[$key] . $templateFile; } - if (file_exists($serendipity['serendipityPath'] . $templateFile . ".tpl") && $serendipity['template'] . '/' == $directory && IS_installed) { - # catch .js.tpl files served via the template-plugin-api, but only if that template is active as well, so config.inc.php is loaded - # this won't work in the installer + if (file_exists($serendipity['serendipityPath'] . $templateFile . ".tpl")) { + # catch *.tpl files, used by the backend for serendipity_editor.js.tpl return $serendipity['baseURL'] . 'index.php?/plugin/' . $file; } } diff --git a/include/functions_smarty.inc.php b/include/functions_smarty.inc.php index 23fe73d0..447fe4b3 100644 --- a/include/functions_smarty.inc.php +++ b/include/functions_smarty.inc.php @@ -625,6 +625,21 @@ function serendipity_smarty_getFile($params, &$smarty) { return serendipity_getTemplateFile($params['file']); } +function serendipity_smarty_getConfigVar($params, &$smarty) { + if ( !isset($params['key']) ) { + trigger_error("Smarty Error: " . __FUNCTION__ .": missing 'key' parameter", E_USER_WARNING); + return; + } + return serendipity_get_config_var($params['key']); +} + +function serendipity_smarty_setFormToken($params, &$smarty) { + if ( isset($params['type']) ) { + return serendipity_setFormToken($params['type']); + } + return serendipity_setFormToken(); +} + /** * Smarty Function: Picks a specified key from an array and returns it @@ -938,6 +953,8 @@ function serendipity_smarty_init($vars = array()) { $serendipity['smarty']->registerPlugin('function', 'pickKey', 'serendipity_smarty_pickKey'); $serendipity['smarty']->registerPlugin('function', 'serendipity_showCommentForm', 'serendipity_smarty_showCommentForm'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getImageSize', 'serendipity_smarty_getImageSize'); + $serendipity['smarty']->registerPlugin('function', 'serendipity_getConfigVar', 'serendipity_smarty_getConfigVar'); + $serendipity['smarty']->registerPlugin('function', 'serendipity_setFormToken', 'serendipity_smarty_setFormToken'); $serendipity['smarty']->registerFilter('pre', 'serendipity_replaceSmartyVars'); diff --git a/include/plugin_api.inc.php b/include/plugin_api.inc.php index 1a85498d..dd97ee52 100644 --- a/include/plugin_api.inc.php +++ b/include/plugin_api.inc.php @@ -75,6 +75,17 @@ function errorHandlerCreateDOM(htmlStr) { } \n"; } break; + + case 'external_plugin': + switch ($eventData) { + case 'admin/serendipity_editor.js': + header('Content-Type: application/javascript'); + global $serendipity; + + echo serendipity_smarty_show('admin/serendipity_editor.js.tpl'); + break; + } + break; return true; break; diff --git a/templates/2k11/admin/serendipity_editor.js.tpl b/templates/2k11/admin/serendipity_editor.js.tpl index 8ce6a726..3cd062d0 100644 --- a/templates/2k11/admin/serendipity_editor.js.tpl +++ b/templates/2k11/admin/serendipity_editor.js.tpl @@ -1304,7 +1304,7 @@ $(function() { } // minify images before upload, approach taken from https://github.com/joelvardy/javascript-image-upload/ - {if $uploadResize && ($maxImgWidth > 0 || $maxImgHeight > 0)} + {if {serendipity_getConfigVar key='uploadResize'} && ({serendipity_getConfigVar key='maxImgWidth'} > 0 || {serendipity_getConfigVar key='maxImgHeight'} > 0)} if ($('#uploadform').length > 0) { $('input[name="go_properties"]').hide(); var progressIcon = document.createElement('span'); @@ -1321,8 +1321,8 @@ $(function() { var file = this.file; image.onload = function (imageEvent) { var canvas = document.createElement('canvas'), - max_width = {if $maxImgWidth}{$maxImgWidth}{else}0{/if}, - max_height = {if $maxImgHeight}{$maxImgHeight}{else}0{/if}, + max_width = {if {serendipity_getConfigVar key='maxImgWidth'}}{serendipity_getConfigVar key='maxImgWidth'}{else}0{/if}, + max_height = {if {serendipity_getConfigVar key='maxImgHeight'}}{serendipity_getConfigVar key='maxImgHeight'}{else}0{/if}, width = image.width, height = image.height; diff --git a/templates/2k11/config.inc.php b/templates/2k11/config.inc.php index 061c42e3..845c2429 100644 --- a/templates/2k11/config.inc.php +++ b/templates/2k11/config.inc.php @@ -108,21 +108,6 @@ serendipity_loadGlobalThemeOptions($template_config, $template_loaded_config, $t function serendipity_plugin_api_pre_event_hook($event, &$bag, &$eventData, &$addData) { // Check what Event is coming in, only react to those we want. switch($event) { - case 'external_plugin': - switch ($eventData) { - case 'admin/serendipity_editor.js': - header('Content-Type: application/javascript'); - global $serendipity; - $data = array( 'token_url' => serendipity_setFormToken("url"), - 'uploadResize' => $serendipity['uploadResize'], - 'maxImgWidth' => $serendipity['maxImgWidth'], - 'maxImgHeight' => $serendipity['maxImgHeight'] - ); - echo serendipity_smarty_show('admin/serendipity_editor.js.tpl', $data); - break; - } - break; - case 'js': // always add newlines to the end of last element, in case of other plugins using this hook and // always start at line Col 1, to populate the (virtual) serendipity.js file