Page 1 of 1

Plugin 'css' event hook

Posted: Wed Nov 30, 2005 9:24 pm
by judebert
I'm still working on that newsbox plugin (like 10 minutes every night :( ) and I've discovered something interesting about the 'css' event hook. The plugin is stackable; I've got two enabled. When each of them gets the css hook, it checks for "newsbox" anywhere in $eventData, and adds CSS if it doesn't exist. But the CSS is getting added twice.

My first attempt just broke out of php and contained the CSS, just like in Garvin's examples. My most recent attempt actually modifies the $eventData variable, because I figure it's a reference, so it should be modified by the time the second plugin gets to it. But Nooooo...

Here's an example:

Code: Select all

                case 'css':
                    if (strpos('newsbox', $eventData) !== false)
                    {
                      // This CSS is already newsbox-aware.
                      return true;
                    }
                    $eventData = $eventData . '
.newsbox
{
  border: 1px solid black;
  padding: 2px;
  margin-bottom: 4px;
}
.newsbox_container
{
  border: 1px solid black;
  padding: 2px;
  margin-bottom: 4px;
  text-align: center;
  margin: 2px auto;
}
.newsbox_container .newsbox
{
  border: none;
  width: 48%;
  float: left;
  text-align: left;
  margin: 2px;
  display: inline;
}
                    ';
                    return true;
                    break;
I've also tried using stristr(), and checking $addData instead of $eventData. Still getting added on twice. What the heck? :?:

Still using 0.9, PHP 4.4.1. I swear I installed 0.9.1, but that's what my admin screen says.

Re: Plugin 'css' event hook

Posted: Thu Dec 01, 2005 11:47 am
by garvinhicking
A classical problem of haystack vs. needle PHP documentation.

Replace this:

Code: Select all

                    if (strpos('newsbox', $eventData) !== false)
with this:

Code: Select all

                    if (strpos($eventData, 'newsbox') !== false)
:)

Where in the code did you find the example above? Then I could fix that.

Regards,
Garvin

Posted: Thu Dec 01, 2005 8:49 pm
by judebert
Oh, blush. :oops:

I can't remember what I copied the thing from; probably the static pages plugin. I'll see if I can figure it out when I get home today.

But I know I searched the forums. That might be where I copied it from, and in that case it would've been easy for me to have performed the transposition.

Ooh, ooh, no, it's you! :wink:

http://www.s9y.org/forums/viewtopic.php ... ntdata+css
http://www.s9y.org/forums/viewtopic.php ... ntdata+css

I'm so relieved. I'm usually pretty anal about these things, but I do get confused after the 30th iteration or so.