fix core to read ckeditor and handle hook-ins
This supports custom ckeditor plugins and a custom ckeditor config and reads $eventData for - normal entry form (case1) textareas, - staticpage (case2) textareas and - other nugget plugins (case3) textareas. They all are build differently, therfore we needed three cases. Please test! Based to following commits 8e26bd9 prepare core ckeditor for custom config and plugins 44ea050 fix virtual js 40609d8 add backend_footer hook References #72
This commit is contained in:
parent
8e26bd9711
commit
faae4b0533
@ -168,32 +168,23 @@ function serendipity_emit_htmlarea_code($item, $jsname, $spawnMulti = false) {
|
||||
'init' => &$init,
|
||||
'item' => &$item,
|
||||
'jsname' => &$jsname,
|
||||
'skip' => false
|
||||
'skip' => false,
|
||||
'buttons'=> array()
|
||||
);
|
||||
serendipity_plugin_api::hook_event('backend_wysiwyg', $eventData);
|
||||
|
||||
if ($eventData['skip']) {
|
||||
if ($eventData['skip'] || $init) {
|
||||
return;
|
||||
}
|
||||
|
||||
//actually we don't even need this any more...
|
||||
if (is_array($eventData['buttons'])) {
|
||||
foreach($eventData['buttons'] as $button) {
|
||||
// Sort buttons into toolbar lists for later additions
|
||||
switch($button['toolbar']) {
|
||||
case S9Y_WYSIWYG_TOOLBAR_FORMATTING:
|
||||
$toolbar[S9Y_WYSIWYG_TOOLBAR_FORMATTING][] = $button;
|
||||
break;
|
||||
case S9Y_WYSIWYG_TOOLBAR_MEDIA:
|
||||
case S9Y_WYSIWYG_TOOLBAR_WEB:
|
||||
$toolbar[S9Y_WYSIWYG_TOOLBAR_WEB][] = $button;
|
||||
break;
|
||||
default:
|
||||
$toolbar['other'][] = $button;
|
||||
break;
|
||||
}
|
||||
$toolbar['other'][] = $button;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$data = array();
|
||||
$data['init'] = $init;
|
||||
$data['spawnMulti'] = $spawnMulti;
|
||||
@ -201,6 +192,8 @@ function serendipity_emit_htmlarea_code($item, $jsname, $spawnMulti = false) {
|
||||
$data['eventData'] = $eventData;
|
||||
$data['item'] = $item;
|
||||
$data['toolbar'] = $toolbar;
|
||||
$data['jsEventData'] = 'jsEventData = '.json_encode($eventData['buttons']);
|
||||
|
||||
echo serendipity_smarty_show('admin/wysiwyg_init.tpl', $data);
|
||||
}
|
||||
$init = true;
|
||||
|
@ -166,8 +166,17 @@
|
||||
</footer>
|
||||
{/if}
|
||||
|
||||
{if $admin_vars.admin_installed}
|
||||
{serendipity_hookPlugin hook="backend_footer" hookAll="true"}
|
||||
{if $admin_vars.admin_installed}{serendipity_hookPlugin hook="backend_footer" hookAll="true"}{/if}
|
||||
{if $init === false}
|
||||
{* CKEDITOR_CCPATHFILE could also be a custom path to a templates ckekeditor_custom_config.js file *}
|
||||
<script type="text/javascript">
|
||||
CKEDITOR_CCPATHFILE = '{$serendipityHTTPPath}htmlarea/';
|
||||
CKEDITOR_CCIMGPATH = '{$serendipityHTTPPath}templates/2k11/admin/img/thumbnail.png';
|
||||
CKEDITOR_S9YPLUGPATH = '{$serendipityHTTPPath}plugins/';
|
||||
CKEDITOR_S9Y_BASEURL = '{$serendipityHTTPPath}';
|
||||
</script>
|
||||
<script src="{$serendipityHTTPPath}htmlarea/ckeditor/ckeditor.js"></script>
|
||||
<script src="{$serendipityHTTPPath}htmlarea/ckeditor_custom_plugin.js"></script>
|
||||
{/if}
|
||||
|
||||
</body>
|
||||
|
@ -52,11 +52,11 @@
|
||||
{serendipity_hookPlugin hook="backend_wysiwyg_nuggets" eventData=$ev hookAll=true}
|
||||
{if $ev['skip_nuggets'] === false}
|
||||
|
||||
<script>
|
||||
<script type="text/javascript">
|
||||
function Spawnnugget() {
|
||||
{foreach $ev['nuggets'] AS $nuggetid}
|
||||
|
||||
if (window.Spawnnuggets) Spawnnuggets('{$nuggetid}');
|
||||
if (window.Spawnnuggets) Spawnnuggets('{$nuggetid}');//case3{* plugin nuggets via function serendipity_plugin_config() eg side html nuggets *}
|
||||
|
||||
{/foreach}
|
||||
|
||||
|
@ -1,38 +1,4 @@
|
||||
{if $init == false}
|
||||
<script src="{$serendipityHTTPPath}htmlarea/ckeditor/ckeditor.js"></script>
|
||||
{/if}
|
||||
<script>
|
||||
$('document').ready(function() {
|
||||
CKEDITOR.plugins.add('s9y_medialibrary{$item}', {
|
||||
init: function( editor ) {
|
||||
editor.addCommand( 'openML', {
|
||||
exec : function( editor ) {
|
||||
serendipity.openPopup('serendipity_admin.php?serendipity[adminModule]=media&serendipity[noBanner]=true&serendipity[noSidebar]=true&serendipity[noFooter]=true&serendipity[showMediaToolbar]=false&serendipity[showUpload]=true&serendipity[textarea]={$item}');
|
||||
}
|
||||
});
|
||||
editor.ui.addButton('s9y_medialibrary{$item}', {
|
||||
label: 'Media',
|
||||
command: 'openML',
|
||||
icon: '{serendipity_getFile file="admin/img/thumbnail.png"}'
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
CKEDITOR.replace($('#'+serendipity.escapeBrackets('{$item}')).get(0), {
|
||||
extraPlugins : 's9y_medialibrary{$item}',
|
||||
toolbar: [
|
||||
{ name: 'tools', items: [ 'Maximize' ] },
|
||||
{ name: 'styles', items: [ 'Format' ] },
|
||||
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'RemoveFormat' ] },
|
||||
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote' ] },
|
||||
{ name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
|
||||
{ name: 'insert', items: [ 'Image', 's9y_medialibrary{$item}', 'Table', 'HorizontalRule', 'SpecialChar' ] },
|
||||
{ name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', '-', 'Undo', 'Redo' ] },
|
||||
{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ], items: [ 'Scayt' ] },
|
||||
{ name: 'others', items: [ '-' ] },
|
||||
{ name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source' ] },
|
||||
{ name: 'about', items: [ 'About' ] }
|
||||
]
|
||||
});
|
||||
});
|
||||
{* this is build for normal backend entry (body/extended) textareas in function serendipity_emit_htmlarea_code() *}
|
||||
<script type="text/javascript">
|
||||
{$jsEventData};{* do not use $('document').ready(function() here, since needs to happen when set *}
|
||||
</script>
|
||||
|
@ -9,12 +9,7 @@ $serendipity['smarty']->assign(array('currpage' => "http://".$_SERVER['HTTP_HOS
|
||||
if (!function_exists('serendipity_smarty_html5time')) {
|
||||
function serendipity_smarty_html5time($timestamp) { return date("c", $timestamp); }
|
||||
|
||||
if( defined('Smarty::SMARTY_VERSION') ) {
|
||||
$serendipity['smarty']->registerPlugin('modifier', 'serendipity_html5time', 'serendipity_smarty_html5time');
|
||||
} else {
|
||||
// old Smarty 2 syntax
|
||||
$serendipity['smarty']->register_modifier('serendipity_html5time', 'serendipity_smarty_html5time');
|
||||
}
|
||||
$serendipity['smarty']->registerPlugin('modifier', 'serendipity_html5time', 'serendipity_smarty_html5time');
|
||||
}
|
||||
|
||||
if (class_exists('serendipity_event_spamblock')) {
|
||||
@ -110,6 +105,20 @@ $template_global_config = array('navigation' => true);
|
||||
$template_loaded_config = serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option'], true);
|
||||
serendipity_loadGlobalThemeOptions($template_config, $template_loaded_config, $template_global_config);
|
||||
|
||||
/**
|
||||
* This adds the possibility for templates to register a central function
|
||||
* serendipity_plugin_api_event_hook() and
|
||||
* serendipity_plugin_api_pre_event_hook() that can be used to
|
||||
* use plugin API interaction WITHOUT actual plugins. So special
|
||||
* plugins can be bundled within a template, without the need to
|
||||
* seperately install them. The "pre" function is called BEFORE
|
||||
* all normal plugins are executed, the normal function is called
|
||||
* AFTER plugin execution.
|
||||
*
|
||||
* In here we use it to parse and compile serendipity_editor.js.tpl
|
||||
* and to populate serendipity.js via the new 'js' plugin hook for the frontend.
|
||||
* The bundled core JS editor - CKEDITOR - will read pre set plugin evenData in some backend hooks
|
||||
*/
|
||||
function serendipity_plugin_api_pre_event_hook($event, &$bag, &$eventData, &$addData) {
|
||||
global $serendipity;
|
||||
// Check what Event is coming in, only react to those we want.
|
||||
@ -125,6 +134,7 @@ function serendipity_plugin_api_pre_event_hook($event, &$bag, &$eventData, &$add
|
||||
break;
|
||||
|
||||
case 'js':
|
||||
// This is frontend and backend!
|
||||
// alway add \n\n for the next and start at line Col 1, to populate the (virtual) serendipity.js file
|
||||
echo "
|
||||
jQuery(function() {
|
||||
@ -136,6 +146,50 @@ jQuery(function() {
|
||||
})\n\n";
|
||||
break;
|
||||
|
||||
case 'backend_wysiwyg':
|
||||
if (preg_match('@^nugget@i', $eventData['item'])) {
|
||||
// switch to wysiwyg finisher directly, in case of nuggets
|
||||
serendipity_plugin_api::hook_event('backend_wysiwyg_finish', $bag, $eventData);
|
||||
} else {
|
||||
// this only builds textareas of normal entry forms, the possible button data will be passed to 'backend_footer' via serendipity_emit_htmlarea_code() function
|
||||
if (isset($eventData['item']) && !empty($eventData['item'])) {
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
$( document ).ready(function() {
|
||||
if (window.Spawnnuggets) Spawnnuggets('<?php echo $eventData['item']; ?>', 'entryforms<?php echo $eventData['jsname']; ?>', null);//case1;{* normal entryform textareas *}
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'backend_wysiwyg_finish':
|
||||
// pass nugget $eventData['item'] and $eventData['buttons'] into the 'backend_footer' hook
|
||||
serendipity_plugin_api::hook_event('backend_footer', $bag, $eventData);
|
||||
break;
|
||||
|
||||
case 'backend_footer':
|
||||
if ($serendipity['wysiwyg']) {
|
||||
if (isset($eventData['item']) && !empty($eventData['item'])) {
|
||||
if (isset($eventData['buttons']) && (is_array($eventData['buttons']) && !empty($eventData['buttons']))) {
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
$( document ).ready(function() {
|
||||
// send eventData as json encoded array into the javascript stream, which can be pulled by 'backend_header' hooks global Spawnnuggets() nugget function
|
||||
jsEventData = <?php echo json_encode($eventData['buttons']); ?>;//case2;{* staticpage nuggets *}
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user