From 8e26bd9711cfabdbe0760d46448fb92089dcac7e Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 15 Mar 2014 17:48:29 +0100 Subject: [PATCH] prepare core ckeditor for custom config and plugins --- .../mediaembed/icons/hidpi/mediaembed.png | Bin 0 -> 680 bytes .../plugins/mediaembed/icons/mediaembed.png | Bin 0 -> 369 bytes .../ckeditor/plugins/mediaembed/plugin.js | 62 ++++++ .../plugins/procurator/images/procurator.png | Bin 0 -> 1320 bytes .../ckeditor/plugins/procurator/plugin.js | 145 +++++++++++++ htmlarea/ckeditor_custom_config.js | 106 ++++++++++ htmlarea/ckeditor_custom_plugin.js | 200 ++++++++++++++++++ 7 files changed, 513 insertions(+) create mode 100644 htmlarea/ckeditor/plugins/mediaembed/icons/hidpi/mediaembed.png create mode 100644 htmlarea/ckeditor/plugins/mediaembed/icons/mediaembed.png create mode 100644 htmlarea/ckeditor/plugins/mediaembed/plugin.js create mode 100644 htmlarea/ckeditor/plugins/procurator/images/procurator.png create mode 100644 htmlarea/ckeditor/plugins/procurator/plugin.js create mode 100644 htmlarea/ckeditor_custom_config.js create mode 100644 htmlarea/ckeditor_custom_plugin.js diff --git a/htmlarea/ckeditor/plugins/mediaembed/icons/hidpi/mediaembed.png b/htmlarea/ckeditor/plugins/mediaembed/icons/hidpi/mediaembed.png new file mode 100644 index 0000000000000000000000000000000000000000..ab7112ca8a9d6ae2acd2e4d92efb3bb44f2291c7 GIT binary patch literal 680 zcmV;Z0$2TsP)NgRxba50xw!IBm zs|Ay{H@^q+*H@U2$8bFuD5m}MbLA1EW5w7FuC59kwz1(Su%Hy)=kr3JTI(j_+DSc) zV?P1m+9*m>IO_G(7l?IGpc*?Hr)t~E1mwd>BAG0K^jSzuMel3hE@dYvM0n==GAOS2+R277B z{2qgJ{%@Y$CL zFr5W|Z*P_U$3M#qY4r}T{$7oB>wpiZ?19B%rH=Lh5+|txIB2)s7zh#{PGt}htB*tIvE8*7 zGsnaL6HP?6&c}xbHRL*^B^x^%h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PH}t1 zgvWoPemzxpepC2)zw_C;_*v1gg(^p)>L@()jf0@4DS@b%f0@R*}MRR f)Nl1OFf+_NE%wE3U)@$ comments via the dataFilter rule element. + // This is why we have to fake it by comment dataFilter rule first + + // The dataProcessor handles data coming in to the editor and out from the editor. + var dataProcessor = editor.dataProcessor; + + // The dataProcessor.dataFilter handles incoming data, like pasting: + // filter applied to the input data when transforming it to HTML to be loaded into the editor ("on input"). + // Ckeditor in this state is enabled. + var dataFilter = dataProcessor && dataProcessor.dataFilter; + + // The dataProcessor.htmlFilter handles outgoing data, like saving, viewing the source button, or generally calling updateElement on the editor: + // filter applied to the HTML available in the editor when transforming it on the XHTML outputted by the editor ("on output"). + // If you have a rule within the htmlFilter that strips out the href attribute, then on save it will be stripped. + // Ckeditor in this state is disabled. + // var htmlFilter = dataProcessor && dataProcessor.htmlFilter; + + // var writer = editor.dataProcessor.writer; + // The way to close self closing tags inside add rules, like + // writer.selfClosingEnd = '>'; + + if (dataFilter) { + // Here we want to add a new filter rule... if the source matches this property, it will be converted + // Note the num at the end, which defines the filter priority. Higher number = higher Priority. + dataFilter.addRules({ + // comment reads html comments and adds fakes to the income-data to be displayed in wysiwyg-mode, + // which was already filtered by ckeditor - see script, noscript (and php?) tags as example + comment : function( elString, elObject ) { + var protectedSourceMarker = '{cke_protected}'; + if ( elString.substr( 0, protectedSourceMarker.length ) == protectedSourceMarker ) { + var displayName = 'protected'; + var realData = elString.replace(/\{cke_protected\}([\s\S]+?)/g, "$1"); // cuts the snippet from {cke_protected}(.*) to preserve + var tagName = realData.replace( /([%3C|%3C%3F|%7B]?([a-z]+))%+(.*)$/, "$1"); // get the real tag name to set as real tag name title to object fakeElement.attributes + tagName = tagName.replace( '%3C', '' ).replace( '%3F', '' ); // tweak a little more, since this upper regex drives me crazy + if ( tagName.substr( 0, 3) == '%7B' ) tagName = 'smarty'; // []{ + if ( !tagName.match("script|mediainsert|audio|smarty") ) tagName = 'unknown'; + var fakeWrapper = new CKEDITOR.htmlParser.element( displayName ); // creates the new object + fakeWrapper.name = tagName; // to give this to createFakeElement(), set name value to displayName, else it is the cke_protected script value + var fakeElement = createFakeElement(editor, fakeWrapper); // take the way to editor.createFakeParserElement( fakeWrapper, 'cke_procurator', displayName, false ); + // by here I had issues that the realelement data returned twice and falsely encoded, + // or returned to be like "%3Cprotected%3E%3C%2Fprotected%3E" only, + // so we workaround this weird issues and just set the value back to the realData! :) + fakeElement.attributes['data-cke-realelement'] = realData; + //alert(elObject.value); + //alert(fakeElement.attributes['data-cke-realelement']); + if ( fakeElement ) { + delete elObject.value; + return fakeElement; + } + } + return elObject.value; + }, + // this are real tag elements only + elements: { + /* + 'protected': function (element) { + var fake = createFakeElement(editor, element); + if ( element.attributes.src ) { + fake.attributes.alt = element.attributes.src; + fake.attributes["data-cke-realelement"] = fake.attributes["data-cke-realelement"].replace(/%26amp%3B/gi, '%26'); //fix double encoding on ampersands in src + } + return fake; + },*/ + } + }, 16); // This is ckeditor priority [1-10] and ACF [11-14], but set to 1 does not conflict here, since we don't hit internal priority rules + // http://docs.ckeditor.com/?_escaped_fragment_=/api/CKEDITOR.editor-event-toDataFormat#!/api/CKEDITOR.editor-event-toDataFormat + // toHtml( evt ) + // This event is fired by the CKEDITOR.htmlDataProcessor when input HTML is to be purified by the CKEDITOR.htmlDataProcessor.toHtml method. + // By adding listeners with different priorities it is possible to process input HTML on different stages: + // 1-4: Data is available in the original string format. + // 5: Data is initially filtered with regexp patterns and parsed to CKEDITOR.htmlParser.fragment CKEDITOR.htmlParser.element. + // 5-9: Data is available in the parsed format, but CKEDITOR.htmlDataProcessor.dataFilter is not applied yet. + // 10: Data is filtered with CKEDITOR.htmlDataProcessor.dataFilter. + // 10-14: Data is available in the parsed format and CKEDITOR.htmlDataProcessor.dataFilter has already been applied. + // 15: Data is written back to an HTML string. + // 15-*: Data is available in an HTML string. + // Available since: 4.1 + } + } + }); + +})('procurator'); diff --git a/htmlarea/ckeditor_custom_config.js b/htmlarea/ckeditor_custom_config.js new file mode 100644 index 00000000..9c564aad --- /dev/null +++ b/htmlarea/ckeditor_custom_config.js @@ -0,0 +1,106 @@ +/** + * @fileOverview A Serendipity CKEDITOR custom config file: ckeditor_custom_config.js, v. 1.0, 2014-03-14, Ian + */ + +/** + * Substitute every config option to CKEDITOR in here + */ +CKEDITOR.editorConfig = function( config ) { + + // Advanced Content Filter ACF works in two modes: + // automatic – the filter is configured by editor features (like plugins, buttons, and commands) that are enabled with configuration options + // such as CKEDITOR.config.plugins, CKEDITOR.config.extraPlugins, and CKEDITOR.config.toolbar, + // custom – the filter is configured by the CKEDITOR.config.allowedContent option and only features that match this setting are activated. + // In both modes it is possible to extend the filter configuration by using the CKEDITOR.config.extraAllowedContent setting. + // If you want to disable Advanced Content Filter, set CKEDITOR.config.allowedContent to true. All available editor features will be activated and input data will not be filtered. + // Allowed content rules. This setting is used when instantiating CKEDITOR.editor.filter. + // The following values are accepted: + // CKEDITOR.filter.allowedContentRules – defined rules will be added to the CKEDITOR.editor.filter. + // true – will disable the filter (data will not be filtered, all features will be activated). + // default – the filter will be configured by loaded features (toolbar items, commands, etc.). + // In all cases filter configuration may be extended by extraAllowedContent. This option may be especially useful when you want to use the default allowedContent value along with some additional rules. + // + // config.allowedContent = CONFIG_ACF_OFF; + + // List of regular expressions to be executed on ***input HTML***, indicating HTML source code that, when matched, must not be available in the WYSIWYG mode for editing. + + // allow