Page 6 of 7

Re: [2.0] New WYSIWYG editor

Posted: Fri Mar 14, 2014 12:33 pm
by garvinhicking
Hi!
Is that really absolutely specific to 2k11 config.inc.php, or shouldn't we better move this into core somewhere?
Is this even possible to do, or is the use of serendipity_plugin_api_pre_event_hook() only doable in template configs?
If you see a way to include that into the core that doesn't have too much impact on the whole event API, please propose such a patch. I tought of this custom template event hook so that we wouldn't need to make any hardcoded calls inside the event API...

Regards,
Garvin

Re: [2.0] New WYSIWYG editor

Posted: Fri Mar 14, 2014 1:15 pm
by Timbalu
Yes, using this was a good idea, I think.
But you say this pre hook is only usable in template configs, or could it also be placed in the core, somewhere, near serendipity_emit_htmlarea_code() for example?
I thought about moving this, to make it indepent from 2k11. Just imagine we might change the default template in a year or so...?! Would it not be better to have it in core then?

Re: [2.0] New WYSIWYG editor

Posted: Fri Mar 14, 2014 1:43 pm
by garvinhicking
Hi!

I can't remember, but I think it should be usable in core files as well. Don't remember if I tested it though.
I thought about moving this, to make it indepent from 2k11. Just imagine we might change the default template in a year or so...?! Would it not be better to have it in core then?
Well we could also of course always include this in other templates as well... but I'm not fully sure I understand what you are trying to do, so it would be okay with you to go ahead and show a patch of how you'd imagine it to be...

HTH,
Garvin

Re: [2.0] New WYSIWYG editor

Posted: Fri Mar 14, 2014 2:42 pm
by Timbalu

Code: Select all

@@ -108,35 +108,8 @@ $template_config = array(
 $template_config_groups = NULL;
 $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);
 
-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.
-    switch($event) {
-        case 'external_plugin':
-            switch ($eventData) {
-                case 'admin/serendipity_editor.js':
-                    header('Content-Type: application/javascript');
-                    $data = array('token_url' => serendipity_setFormToken("url"));
-                    echo serendipity_smarty_show('admin/serendipity_editor.js.tpl', $data);
-                break;
-            }
-        case 'js':
-            echo "jQuery(function() {
-                        jQuery('input[type=\"url\"]').change(function() {
-                            if (this.value != '' && ! (this.value.substr(0,7) == 'http://' || this.value.substr(0,8) == 'https://')) {
-                                this.value = 'http://' + this.value;
-                            }
-                        });
-                })\n\n";
-            break;
-            
-        return true;
-        break;
-    }
-}
-
 if ($_SESSION['serendipityUseTemplate']) {
     $template_loaded_config['use_corenav'] = false;
 }
and

Code: Select all

@@ -1,6 +1,6 @@
-<?php # $Id$
+<?php #
 # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
 # All rights reserved.  See LICENSE file for licensing details
 
 if (IN_serendipity !== true) {
     die ("Don't hack!");
@@ -29,26 +29,56 @@ serendipity_smarty_init($serendipity['plugindata']['smartyvars']);
 $leftSidebarElements  = serendipity_plugin_api::count_plugins('left');
 $rightSidebarElements = serendipity_plugin_api::count_plugins('right');
 $serendipity['smarty']->assignByRef('leftSidebarElements', $leftSidebarElements);
 $serendipity['smarty']->assignByRef('rightSidebarElements', $rightSidebarElements);
 
+// use the pre event hook to create serendipity_edor.js by a template file and hook in plugin data into serendipity.js file
+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.
+    switch($event) {
+        case 'external_plugin':
+            switch ($eventData) {
+                case 'admin/serendipity_editor.js':
+                    header('Content-Type: application/javascript');
+                    $data = array('token_url' => serendipity_setFormToken("url"));
+                    echo serendipity_smarty_show('admin/serendipity_editor.js.tpl', $data);
+                break;
+            }
+
+        case 'js':
+            echo "
+jQuery(function() { 
+    jQuery('input[type=\"url\"]').change(function() { 
+        if (this.value != '' && ! (this.value.substr(0,7) == 'http://' || this.value.substr(0,8) == 'https://')) { 
+            this.value = 'http://' + this.value;
+        }
+    });
+})\n\n";
+            break;
+
+        return true;
+        break;
+    }
+}
+
 
 switch ($serendipity['GET']['action']) {
     // User wants to read the diary
     case 'read':
         if (isset($serendipity['GET']['id'])) {
             $entry = array(serendipity_fetchEntry('id', $serendipity['GET']['id']));
             if (!is_array($entry) || count($entry) < 1 || !is_array($entry[0])) {
                 unset($serendipity['GET']['id']);
                 $entry = array(array());
-                $serendipity['head_title'] = htmlspecialchars($serendipity['blogTitle']); 
-                $serendipity['head_subtitle'] = ''; 
-                $serendipity['smarty']->assign('head_title', $serendipity['head_title']); 
-                $serendipity['smarty']->assign('head_subtitle', $serendipity['head_subtitle']); 
+                $serendipity['head_title'] = htmlspecialchars($serendipity['blogTitle']);
+                $serendipity['head_subtitle'] = '';
+                $serendipity['smarty']->assign('head_title', $serendipity['head_title']);
+                $serendipity['smarty']->assign('head_subtitle', $serendipity['head_subtitle']);
                 $serendipity['view'] = '404';
-                serendipity_header('HTTP/1.0 404 Not found');                    
-                serendipity_header('Status: 404 Not found');                    
+                serendipity_header('HTTP/1.0 404 Not found');
+                serendipity_header('Status: 404 Not found');
             }
 
             serendipity_printEntries($entry, 1);
         } else {
             serendipity_printEntries(serendipity_fetchEntries($serendipity['range'], true, $serendipity['fetchLimit']));
@@ -104,12 +134,12 @@ switch ($serendipity['GET']['action']) {
 
         break;
 
     // Show the archive
     case 'archives':
-        $serendipity['head_subtitle'] = ARCHIVES; 
-        $serendipity['smarty']->assign('head_subtitle', $serendipity['head_subtitle']); 
+        $serendipity['head_subtitle'] = ARCHIVES;
+        $serendipity['smarty']->assign('head_subtitle', $serendipity['head_subtitle']);
         serendipity_printArchives();
         break;
 
 
     case 'custom':
as a concrete "move into core" suggestion.
If you gona ask if this has been tested with the new 'js' hook, by example freetag, I'd say: "YES this has been tested and works well!".

Re: [2.0] New WYSIWYG editor

Posted: Fri Mar 14, 2014 2:50 pm
by onli
I don't say that the config.inc.php is the perfect place. But at least it connects the tempalte-functionality with the template. To move that into genpage.inc.php feels wrong.

In any case, the 'js'-event has no place there. That is template-, even 2k11-, specific.

Sicne this is a bigger thing and it has nothing to do with the wysiwyg-editor as far as I can see, please move this into an own thread. Maybe we can find there a more generic mechanism.

Re: [2.0] New WYSIWYG editor

Posted: Fri Mar 14, 2014 3:28 pm
by Timbalu
Garvin wanted me to show the move in a diff.
And it definitely has to do with ckeditor, even if I haven't extended it to use the hook, within that diff yet.
onli wrote:To move that into genpage.inc.php feels wrong.
Not it does not, in my eyes, see /index.php:

Code: Select all

} elseif (preg_match(PAT_JS, $uri, $matches)) {
    $serendipity['view'] = 'js';
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
        header('Cache-Control: no-cache');
    } else {
        header('Cache-Control:');
        header('Pragma:');
        header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time()+3600));
    }

    header('Content-type: application/javascript; charset=' . LANG_CHARSET);

    $out = "";
    include(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
    serendipity_plugin_api::hook_event('js', $out);
    echo $out;
    exit;
which is very much closer to run as a 'pre' event hook in there, since later by the templates config.inc.php file.
onli wrote:In any case, the 'js'-event has no place there.
What do you mean exactly?
As I already said: Freetag 'js' hook-in is working like expected and that is all about, isn't it.

Re: [2.0] New WYSIWYG editor

Posted: Fri Mar 14, 2014 5:49 pm
by Timbalu
No worry! I have made some more tests in the meantime, and even though it is working for the js hook, I do not get access to some further backend hooks I will need in there, since genpage seems too early in the scope. So for the moment that will have to stay and get extended in templates config.

Re: [2.0] New WYSIWYG editor

Posted: Sat Mar 15, 2014 3:56 pm
by Timbalu
While I mostly solved my problems with core ckeditor for staticpage nuggets and other issues, I discovered a strange behaviour, I would not have expected. I'd call it a 'bug', but maybe it is a feature being intended by M&M, I just do not understand by yet.

The serendipty.js file is populated via the 'js' hook in plugins and the configs serendipity_plugin_api_pre_event_hook() function, ending as:

Code: Select all

<script src="http://test.ng.net/index.php?/plugin/admin/serendipity_editor.js"></script>
<script src="http://test.ng.net/serendipity.js&v=1371994335"></script>
in the head.

Now, the unexpected behaviour is the following:
the content of serendipity.js&v=1371994335 is also appended to the end of serendipity_editor.js.
In that case we wouldn't even need the serendipity.js file, wouldn't we?!

To solve this 'issue', I will add a

Code: Select all

break;
to https://github.com/s9y/Serendipity/blob ... c.php#L125, when I soon push my changes.

But this may be worth to have been discussed before. Do we want and need to have the hooked-in javascript to be seperated by a serendipity (hook).js file.

Re: [2.0] New WYSIWYG editor

Posted: Sat Mar 15, 2014 5:06 pm
by onli
Good catch. It is certainly not intended, and the break there should fix it.

Re: [2.0] New WYSIWYG editor

Posted: Sat Mar 15, 2014 5:15 pm
by Timbalu
And you even thought about maybe having all in serendipity_editor.js instead?
I do not favour this I think, but it could be done...

Re: [2.0] New WYSIWYG editor

Posted: Sat Mar 15, 2014 5:18 pm
by onli
No, it's code for the frontend, and it would be unnecessary load to add the serendipity_editor.js there. That's why it is in the js-hook.

Re: [2.0] New WYSIWYG editor

Posted: Sat Mar 15, 2014 7:15 pm
by Timbalu
Ok.
I posted my solution for custom ckeditor plugins and a custom ckeditor config, which reads every backend generated toolbar data and supports any backend/plugin generated textarea.
(Staticpage will need a tiny update, but we have to touch it for 2.0 anyway. *)
Please test before discuss! :)

(*) there still is the urgent need to fix the noWysiwygAdd() for or in some Plugins, eg linktrimmer etc

Re: [2.0] New WYSIWYG editor

Posted: Sun Mar 16, 2014 12:57 pm
by onli
I moved the serendipity_editor.js.tpl-discussion to http://board.s9y.org/viewtopic.php?f=11&t=19810

Re: [2.0] New WYSIWYG editor

Posted: Wed Mar 19, 2014 10:11 am
by Timbalu
Timbalu wrote:Adding an option to the serendipity_emit_htmlarea_code() function, to also check for a custom config file in custom template, is nothing bad to have, if we say "use at your own risk"!

Else, anybody is able to just easy replace the shipped standard htmlarea/ckeditor package with an extended or less functional "mini" package, without needing to change anything else.
Now that my solution has been proofed some days, we could discuss this:

I thought of giving up /htmlarea directory at all and move the ckeditor lib into /bundled-libs/js/, since it is a bundled lib after all.

First I thought this was a great idea, but now I got some doubts about it. Making an easy custom config js file available in a custom template would need us to check for serendipity_getFile(), which is kind of bad to do, since it needs to be called in the custom plugin js file. So moving to bundled-libs and giving access to a custom config via templates, would need some changes making a simple and lightweighted approach for the most of us a little more difficult.

I personally tend to leave it as is, in /htmlarea, which is easy accessible and reachable (*), and suggest any of those users Garvin had in mind to change /htmlarea content in case of any custom enhancements. (I know this would need them to do this after each Serendipity release upgrade, but I think for this few, this wouldn' be that bad, since just a copy and paste/upload issue.)

Any thoughts?

(*) btw, does htmlarea now need any changes in permissions?

Re: [2.0] New WYSIWYG editor

Posted: Wed Mar 19, 2014 10:43 am
by garvinhicking
Hi!
I thought of giving up /htmlarea directory at all and move the ckeditor lib into /bundled-libs/js/, since it is a bundled lib after all.
It would also be bad for shared installations, so htmlarea should keep its place (even though the name is misleading, but I think we can live with it)
btw, does htmlarea now need any changes in permissions?
Don't think so...

Regards,
Garvin