1
0

Move serendipiy_editor.js.tpl convertion into core

http://board.s9y.org/viewtopic.php?f=11&t=19927
This commit is contained in:
onli
2014-05-16 16:13:16 +02:00
parent 05817056e5
commit 694b446e1a
5 changed files with 33 additions and 21 deletions

View File

@@ -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;
}
}

View File

@@ -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');

View File

@@ -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;

View File

@@ -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;

View File

@@ -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