Sidebar plugins emit css via event hook?

Creating and modifying plugins.
Post Reply
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Sidebar plugins emit css via event hook?

Post by Don Chambers »

I've seen a number of event plugins that emit css via the event hook css. Is something like this possible in sidebar plugins?
=Don=
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sidebar plugins emit css via event hook?

Post by garvinhicking »

Hi!

Only event plugins can hook into events. So you need to create a bundled event plugin for that, or emit inline CSS, or use javascript to inject CSS into the DOM.

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/
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Sidebar plugins emit css via event hook?

Post by Don Chambers »

I thought it would be a good idea NOT to use inline css, but do you think a bundled event plugin exclusively to emit css is ridiculous? If not, wow exactly do I "bundle" it with the sidebar plugin?
=Don=
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sidebar plugins emit css via event hook?

Post by garvinhicking »

Hi!

If you're simply wanting to "get it done", I'd go for the inline CSS, since all browsers parse that. You could make the plugin read a serendipity_getTemplateFile('bla.css') file that users could customize. Creating a bundled event plugi would be an overhead that for me would not be the most beneficial solution. Going that route would be somewhat along the lines of the serendipity_event/plugin_login plugin. Just create a plugin and in the introspect() method use $this->dependencies...

HTH,
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/
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Sidebar plugins emit css via event hook?

Post by Don Chambers »

Thanks Garvin. I think serendipity_getTemplateFile('bla.css') makes the most sense... but that assumes the file will be in the template folder. Is there a plugin folder equivalent, or do I need to hard code the path?
=Don=
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sidebar plugins emit css via event hook?

Post by garvinhicking »

Hi!

Plugins use this as a code to prefer template files, but fallback to the plugin directory:

Code: Select all

        $filename = 'blah.css'; // Set filename
        $tfile = serendipity_getTemplateFile($filename, 'serendipityPath'); // Try to get file path from template directory
        if (!$tfile || $tfile == $filename) { // If not found, use current directory
            $tfile = dirname(__FILE__) . '/' . $filename;
        }
        echo file_get_contents($tfile);
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/
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Sidebar plugins emit css via event hook?

Post by Don Chambers »

Thanks Garvin. But if it just echo's the file's contents, isn't that just going to appear within the sidebar plugin, and not included in serendipity.css? Can you think of a sidebar plugin that does this so I can see the code as an example?
=Don=
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sidebar plugins emit css via event hook?

Post by garvinhicking »

Hi!

Yes, that's what I call inline CSS! Just echo '<style type="text/css">...</style>';...

As I mentioned, sidebar plugins are not event plugins and thus cannot hook into events.

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/
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Sidebar plugins emit css via event hook?

Post by Don Chambers »

I thought there would still be some way to load it into serendipity.css. I had already done what you suggested:

Code: Select all

        // load plugin stylesheet
        $filename = 'serendipity_plugin_custom.css'; // Set filename
        $tfile = serendipity_getTemplateFile($filename, 'serendipityPath'); // Try to get file path from template directory
        if (!$tfile || $tfile == $filename) { // If not found, use current directory
            $tfile = dirname(__FILE__) . '/' . $filename;
        }
        echo '<style type="text/css">', file_get_contents($tfile), '</style>';
I'm not sure if I gained anything over simply going inline or embedded directly in the plugin as:

Code: Select all

print <<<EOT
<style type="text/css">
/* all my style stuff here */
</style>
EOT;
Any of these methods will still require !important to override via a template or user stylesheet.
=Don=
Post Reply