HTML Nugget backend description

Creating and modifying plugins.
Post Reply
n2ition
Regular
Posts: 58
Joined: Sun Mar 20, 2005 8:43 pm
Location: Dallas, TX
Contact:

HTML Nugget backend description

Post by n2ition » Wed Apr 27, 2005 2:19 am

I LOVE the html nugget plugin and use it frequently. Here's the problem I run into. I have 3 or 4 of these nuggets in my side bars, some of them need titles however the nuggets that I don't want a title to show in the sidebar I am forced to leave the title in the backend blank. This creates a problem in the plugin configuration screen if I have several HTML nuggets untitled. They all just show HTML Nugget in the configuration screens so I have to actually go in to each one to figure which one is which for editing. Is there anyway to have a "backend title" that shows only in the config screens but not in the sidebar?
The good news is the bad news is wrong! Random Kindness Project

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: HTML Nugget backend description

Post by garvinhicking » Wed Apr 27, 2005 2:44 pm

I've created a patch for the nugget.

You can edit your include/plugins_internal.inc.php file and replace the html_nugget plugin class with this snippet:

Code: Select all

@define('BACKEND_TITLE', 'Additional information in Plugin Configuration screen'); // Translate
@define('BACKEND_TITLE_FOR_NUGGET', 'Here you can define a custom string which is displayed in the Plugin Configuration screen together with the description of the HTML Nugget plugin. If you have multiple HTML nuggets with an empty title, this helps to distinct the plugins from another.'); // Translate
class serendipity_html_nugget_plugin extends serendipity_plugin {
    var $title = HTML_NUGGET;

    function introspect(&$propbag)
    {
        $this->title = $this->get_config('title', $this->title);
        $subtitle    = $this->get_config('backend_title', '');
        if (!empty($subtitle)) {
            $desc    = '(' . $subtitle . ') ' . HOLDS_A_BLAHBLAH;
        } else {
            $desc        = HOLDS_A_BLAHBLAH;
        }
       
        $propbag->add('name',          HTML_NUGGET);
        $propbag->add('description',   $desc);
        $propbag->add('stackable',     true);
        $propbag->add('author',        'Serendipity Team');
        $propbag->add('version',       '1.0');
        $propbag->add('configuration', array(
                                        'title',
                                        'backend_title',
                                        'content',
                                        'markup',
                                        'show_where'
                                       )
        );

        $this->protected = TRUE; // If set to TRUE, only allows the owner of the plugin to modify its configuration
    }

    function introspect_config_item($name, &$propbag)
    {
        switch($name) {
            case 'title':
                $propbag->add('type',        'string');
                $propbag->add('name',        TITLE);
                $propbag->add('description', TITLE_FOR_NUGGET);
                $propbag->add('default',     '');
                break;

            case 'backend_title':
                $propbag->add('type',        'string');
                $propbag->add('name',        BACKEND_TITLE);
                $propbag->add('description', BACKEND_TITLE_FOR_NUGGET);
                $propbag->add('default',     '');
                break;

            case 'content':
                $propbag->add('type',        'html');
                $propbag->add('name',        CONTENT);
                $propbag->add('description', THE_NUGGET);
                $propbag->add('default',     '');
                break;

            case 'markup':
                $propbag->add('type',        'boolean');
                $propbag->add('name',        DO_MARKUP);
                $propbag->add('description', DO_MARKUP_DESCRIPTION);
                $propbag->add('default',     'true');
                break;

            case 'show_where':
                $select = array('extended' => PLUGIN_ITEM_DISPLAY_EXTENDED, 'overview' => PLUGIN_ITEM_DISPLAY_OVERVIEW, 'both' => PLUGIN_ITEM_DISPLAY_BOTH);
                $propbag->add('type',        'select');
                $propbag->add('select_values', $select);
                $propbag->add('name',        PLUGIN_ITEM_DISPLAY);
                $propbag->add('description', '');
                $propbag->add('default',     'both');
                break;

            default:
                return false;
        }
        return true;
    }

    function generate_content(&$title)
    {
        global $serendipity;

        $title = $this->get_config('title') . '!';
        $show_where = $this->get_config('show_where', 'both');

        if ($show_where == 'extended' && (!isset($serendipity['GET']['id']) || !is_numeric($serendipity['GET']['id']))) {
            return false;
        } else if ($show_where == 'overview' && isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id'])) {
            return false;
        }

        if ($this->get_config('markup', 'true') == 'true') {
            $entry = array('html_nugget' => $this->get_config('content'));
            serendipity_plugin_api::hook_event('frontend_display', $entry);
            echo $entry['html_nugget'];
        } else {
            echo $this->get_config('content');
        }
    }
}


The patch itself is committed to our 0.9 source repository, and will most likely not backported to a maintenace release for 0.8.x...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

n2ition
Regular
Posts: 58
Joined: Sun Mar 20, 2005 8:43 pm
Location: Dallas, TX
Contact:

Post by n2ition » Wed Apr 27, 2005 7:52 pm

So my next question is:

Is there anything you can't do?

My Hero! :D
The good news is the bad news is wrong! Random Kindness Project

n2ition
Regular
Posts: 58
Joined: Sun Mar 20, 2005 8:43 pm
Location: Dallas, TX
Contact:

Post by n2ition » Wed Apr 27, 2005 8:00 pm

Oops...just ran across an issue. Now that the patch has been installed all of my html nugget plugins have a ! where their titles would normally appear on the sidebar. If they have titles it appears after the title...if they don't have titles it appears where the title would be if they had one.

I went through and the only thing I could find that might create the problem was this on line 929

$title = $this->get_config('title') . '!';


I changed it to:

$title = $this->get_config('title') ;


I don't know if it was right but it seemed to remove the problem. I don't know really anything about PHP but it seemed the logical step to take. Let me know if I have done something by removing it that might cause the plugin to fail.

Thanks again for all your help.
The good news is the bad news is wrong! Random Kindness Project

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Thu Apr 28, 2005 12:54 pm

n2ition, yes - you'Re right. That "!" debugging exclamation mark slipped my attention. It was fixed in our 0.9 branch already though.

And thanks for your appreciation. This really puts a smile on my face, it's great you enjoy using our system. :-)

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

Post Reply