Page 1 of 2

Markup-Buttons for comments

Posted: Fri Feb 06, 2009 6:37 pm
by onli
I wrote a small plugin to have markup-buttons (like the ones used in this forum) above the comment area (using s9y-markup). Thought something like this already exists but couldn't find anything so I wrote it myself.

Looks like this:
Image
behaves like in this blogpost explaining the plugin (german),
can be downloaded here and depends on this jquery-plugin

Well, not ready for global publishing, but maybe someone wants to complete or use it already. Or point me to the existing alternative one ;)
sincerely


PS: If there really exists no alternative and you like it I could complete it myself, I think.

Re: Markup-Buttons for comments

Posted: Mon Feb 09, 2009 11:52 am
by garvinhicking
Hi!

I agree, I think there's no plugin for this. How about maybe merging this functionality into the livecomment plugin?

Best regards,
Garvin

Re: Markup-Buttons for comments

Posted: Mon Feb 09, 2009 2:08 pm
by onli
Hi Garvin
First I thought that's only a bad idea. But because the livecomment-plugin asks which markups are activated for the comments this could be easily combined - which makes the idea really worth thinking of.

But: I wouldn't look for this feature in a preview-plugin cause I think the feature is quite different from a preview. But maybe it could work if one let the livepreview-plugin become a "comment-improvement"-plugin.

Both ways have pros and cons - you think merging is the best way?
sincerely

Re: Markup-Buttons for comments

Posted: Mon Feb 09, 2009 2:28 pm
by garvinhicking
Hi!

I agree, we should change the labelling of the plugin. Something like "Live Preview and comment text formatting help"?

Other than that, I think as the code similarities are given, this would be a good fit...

Regards,
Garvin

Re: Markup-Buttons for comments

Posted: Mon Feb 09, 2009 10:27 pm
by onli
Hi
Think I finished the merging. One question: Shall I integrate the jquery into the plugin or shall we use the jquery-plugin as a dependency? I'd prefer the second option, looking forward to all the other plugins which maybe get created using this framework. But of course it's up to you - is the dependency-system useable enough?

Re: Markup-Buttons for comments

Posted: Tue Feb 10, 2009 10:13 am
by garvinhicking
Hi!

Yeah, the dependencies should work fine, I think. I'm in favor of the jquery plugin solution.

Regards,
Garvin

Re: Markup-Buttons for comments

Posted: Tue Feb 10, 2009 12:23 pm
by onli
Added the merged plugin as attachment.

I'm not sure if I unterstood the dependency system correctly.

Code: Select all

 $this->dependencies = array('serendipity_event_jquery' => 'remove');
added into serendipity_event_livecomment.php is enough?

The labeling is a proposal ('Enhanced Comment Area' - 'Uses JavaScript to show a live preview and markup-buttons') and I'm certain the javascript-code could be improved. By the way: The former version didn't work in opera only because one > was missing at a </div>-.- . Fixed that.
And added some options to customize (or disable) the animations.

Oh, I'll link the jquery-plugin directly: Link

Re: Markup-Buttons for comments

Posted: Tue Feb 10, 2009 1:32 pm
by garvinhicking
Hi!

Great, thanks a lot - I committed both new plugins!

Regards,
Garvin

Re: Markup-Buttons for comments

Posted: Wed Feb 11, 2009 11:10 pm
by onli
Thanks Garvin :)

I got two minor problems with the dependency system (which could become severe if it were used more often).
The first: the jQuery-Plugin is placed after the livecomment-plugin, which ain't too effective. Most of the dependencies should be loaded before the depending one - at least that's true for the jquery-plugin.
The second: I had two plugins depending on jquery, as I had the markup-plugin manually installed. After upgrading the livecomment-plugin and removing the markup-plugin, the jquery-plugin got removed, too. Seems like it didn't noticed there still was the livecomment-plugin depending on it.
sincerely

Re: Markup-Buttons for comments

Posted: Thu Feb 12, 2009 11:00 am
by garvinhicking
Hi!

We have a priority system. The serendipity_event_entryproperties plugin is an example for it, it takes care that it'S always last in queue through the 'backend_plugins_new_instance' event hook.

Maybe the jquery plugin should be set to "keep" instead of "remove" if multiple plugins depend on it.

Regards,
Garvin

Re: Markup-Buttons for comments

Posted: Sat Feb 21, 2009 6:13 pm
by onli
Hi
Added italic, added elastic facebooklike-commentarea (http://plugins.jquery.com/project/elastic, default is off), fixed a severe bug with the markup-buttons (the path to the images was wrong).

Changing the jQuery-priority don't seem to work. First I tried to take the code from the entryproperties-plugin and add it to the livecomment-plugin, but jQuery remained behind it.
Then I took the code into the jQuery-plugin and reversed it:

Code: Select all

 case 'backend_plugins_new_instance':
    // Fetch minimum sort_order value. This will be the new value of our current plugin.
    $q  = "SELECT MIN(sort_order) as sort_order_min FROM {$serendipity['dbPrefix']}plugins WHERE placement = '" . $addData['default_placement'] . "'";
    $rs  = serendipity_db_query($q, true, 'num');

    // Fetch current sort_order of current plugin.
    $q   = "SELECT sort_order FROM {$serendipity['dbPrefix']}plugins WHERE name = '" . $this->instance . "'";
    $cur = serendipity_db_query($q, true, 'num');

    // Increase sort_order of all plugins before current plugin by one.
    $q = "UPDATE {$serendipity['dbPrefix']}plugins SET sort_order = sort_order + 1 WHERE placement = '" . $addData['default_placement'] . "' AND sort_order < " . intval($cur[0]);
    serendipity_db_query($q);

    // Set current plugin as first plugin in queue.
    $q = "UPDATE {$serendipity['dbPrefix']}plugins SET sort_order = " . intval($rs[0]) . " WHERE name = '" . $this->instance . "'";
    serendipity_db_query($q);
    return true;
break;
Shows no effect. Did I oversee anything?

Re: Markup-Buttons for comments

Posted: Sat Feb 21, 2009 6:34 pm
by garvinhicking
Hi!

Maybe for future revisons you could introduce a ChangeLog file? I've committed your code.

As for the tool, did you remember to register the backend_plugins_new_instance event hook? Did you use global $serendipity?

Regards,
Garvin

Re: Markup-Buttons for comments

Posted: Sat Feb 21, 2009 7:12 pm
by onli
Thanks for committing. I'll introduce the Chengelog the next time. Already started a credit.txt because of the heavy use of foreign plugins.

Think I used global $serendipity und registered the event hook:

Code: Select all

<?php # $Id: serendipity_event_jquery.php,v 1.3.1 2009/2/01 09:00:44 maltepaskuda Exp $

if (IN_serendipity !== true) {
    die ("Don't hack!");
}

// Probe for a language include with constants. Still include defines later on, if some constants were missing
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
if (file_exists($probelang)) {
    include $probelang;
}

include dirname(__FILE__) . '/lang_en.inc.php';

class serendipity_event_jquery extends serendipity_event {
    var $title = EVENT_JQUERY_TITLE;
    
    function introspect(&$propbag)
    {
        global $serendipity;
        
        $propbag->add('name',          EVENT_JQUERY_TITLE);
        $propbag->add('description',   EVENT_JQUERY_DESC);
        $propbag->add('stackable',     false);
        $propbag->add('author', 'Malte Paskuda');
        $propbag->add('requirements',  array(
            'serendipity' => '0.7',
        ));
        $propbag->add('version', '1.3.1');
        $propbag->add('event_hooks', array('frontend_header' => true,
                                           'external_plugin'  => true,
                                           'backend_plugins_new_instance'  => true
                                           ));
        $propbag->add('groups', array('BACKEND_FEATURES'));

        
    }

    function generate_content(&$title) {
        $title = $this->title;
    }

    function event_hook($event, &$bag, &$eventData, $addData = null) {
        global $serendipity;
        $hooks = &$bag->get('event_hooks');

        if (isset($hooks[$event])) {
            switch($event) {
                case 'external_plugin':
                    switch($eventData) {
                        case 'jquery.js':
                            header('Content-Type: text/javascript');
                            echo file_get_contents(dirname(__FILE__). '/jquery.js');
                            break;
                        }
                    return true;
                    break;
                
                case 'frontend_header':
                    echo '<script type="text/javascript" src="' . $serendipity['baseURL'] . 'index.php?/plugin/jquery.js"></script>'. "\n";
                    return true;
                    break;

                    
                case 'backend_plugins_new_instance':
                    // This hook will always push the jquery plugin as first in queue.
                    // Happens always when a new plugin is added.

                    // Fetch minimum sort_order value. This will be the new value of our current plugin.
                    $q  = "SELECT MIN(sort_order) as sort_order_min FROM {$serendipity['dbPrefix']}plugins WHERE placement = '" . $addData['default_placement'] . "'";
                    $rs  = serendipity_db_query($q, true, 'num');

                    // Fetch current sort_order of current plugin.
                    $q   = "SELECT sort_order FROM {$serendipity['dbPrefix']}plugins WHERE name = '" . $this->instance . "'";
                    $cur = serendipity_db_query($q, true, 'num');

                    // Increase sort_order of all plugins before current plugin by one.
                    $q = "UPDATE {$serendipity['dbPrefix']}plugins SET sort_order = sort_order + 1 WHERE placement = '" . $addData['default_placement'] . "' AND sort_order < " . intval($cur[0]);
                    serendipity_db_query($q);

                    // Set current plugin as first plugin in queue.
                    $q = "UPDATE {$serendipity['dbPrefix']}plugins SET sort_order = " . intval($rs[0]) . " WHERE name = '" . $this->instance . "'";
                    serendipity_db_query($q);
                    return true;
                    break;

                default:
                    return false;
                    break;
            }
        } else {
            return false;
        }
    }
}
?>

Re: Markup-Buttons for comments

Posted: Sat Feb 21, 2009 7:17 pm
by garvinhicking
Hi!

Did you try to debug if the event hook gets called? Try to make some output, write to a file or so, just to see if it gets called actually?! Then try to trace the steps inside the code by outputting/saving the SQL statements that are used?

Regards,
Garvin

Re: Markup-Buttons for comments

Posted: Mon Feb 23, 2009 5:15 pm
by onli
Yes, debugging was the answer - leading to simple better testing, which worked itself ;)
'backend_plugins_new_instance' of the jquery-plugin only gets called when another plugin is added. Cause the plugin's default position is at the end, this has no effect on the entryproperties-plugin.
Is there a hook that gets executed immediately after or while the plugin itself is added? I'm sure there is, but I can't find it in the plugin-api. Misusing introspect_config_item (adding a fake config-option and calling the function containing the order-code, which works correctly at the backend_plugins_new_instance) didn't work (the old order remains).