Page 1 of 2

Placing output of plugin not aside

Posted: Thu Oct 28, 2004 5:49 pm
by Thomas
Hi,

today I'd an idea for a plugin but therefore I'd like to know if it is possible to place the output between #serendipity_banner and #mainpane, for example.

Thanks, Thomas

Re: Placing output of plugin not aside

Posted: Fri Oct 29, 2004 10:53 am
by garvinhicking
You'd have to edit your layout.php file for that to be possible, and insert an event_hook there...

Regards,
Garvin

Posted: Fri Oct 29, 2004 12:27 pm
by Thomas
Ahhh ... yes .... what and how would you define as an event_hook?

Posted: Fri Oct 29, 2004 2:12 pm
by garvinhicking
Well, take your layout.php and insert

Code: Select all

serendipity_plugin_api::hook_event('tomscorner_top', $serendipity);
in the place after your #mainpane. Then create a plugin which enlists itself for the 'tomscorner_top' hook, and at the event_hook() function of your plugin, insert a case statement for what to output at that hook position. Just look at existing plugins and how they use event hooks. The karma plugin should maybe be a good pointer for you, despite of it's overload :)

Regards,
Garvin.

Posted: Fri Oct 29, 2004 3:53 pm
by Thomas
Hi,

ok, well, I made a simple example working.

There are a view questions left:
  • get_config(): the values I can give as argument to this function are restricted to the plugin only or am I able to see others as well? If yes how to find out which values can I get from get_config()?
  • Is it possible when calling a plugin through an event_hook first to get true or false back to see if the plugin is enabled or not? This is therefore to display the output of the plugin in a seperate table only then when the plugin is enabled. Otherwise an emptry table would be displayed which avtually doesn't look that nice ;)
  • Database tables: may plugins have database tables?
  • Plugin API: the docs are ok but in some cases not very helpful ;)
Regards, Thomas

Posted: Fri Oct 29, 2004 5:12 pm
by garvinhicking
Hi Thomas!
  • get_config(): the values I can give as argument to this function are restricted to the plugin only or am I able to see others as well? If yes how to find out which values can I get from get_config()?
You are righ, $this->get_config() is restricted to a single plugin. The values you are able to fetch are the ones you specify in the introspect function. (array 'configuration').
[*]Is it possible when calling a plugin through an event_hook first to get true or false back to see if the plugin is enabled or not? This is therefore to display the output of the plugin in a seperate table only then when the plugin is enabled. Otherwise an emptry table would be displayed which avtually doesn't look that nice ;)
Actually you don't use the hook_event() function to spawn a single plugin, but all plugins which listen to that event. So if there are none plugins listening to that, nothing happens. The event hook does not return a true/false, but you can set values you specify within the function ($eventData and $addData). So you can set a value flag to tell your layout.php whether a certain case has happened or not. The most easy way would be to do this:

Code: Select all

<?php
ob_start()
serendipity_plugin_api::hook_event('myevent');
$data = ob_get_contents();
ob_end_clean();

if (!empty($data) {
?>
do wicked html table stuff
<?php echo $data; ?_
end wicked html table stuff
<?php
}
?>
[*]Database tables: may plugins have database tables?
If you need it for extra data, yes. The shoutbox and karma plugins create a seperate table, for example.
[*]Plugin API: the docs are ok but in some cases not very helpful ;)
Yeah, we have our drawbacks there because it doesn't get updated frequently. We're programmers, not writers -- so we need help with someone documenting...

If you find cases where information is missing, please let me know and I try to fill in the gaps. The more precise your question is, the better I can document the answer :)

Thanks,
Garvin.

Posted: Fri Oct 29, 2004 8:26 pm
by Thomas
Hey Garvin,
You are righ, $this->get_config() is restricted to a single plugin. The values you are able to fetch are the ones you specify in the introspect function. (array 'configuration').
Question answered. :)
The event hook does not return a true/false, but you can set values you specify within the function ($eventData and $addData).
Well, can those data vars be appended at serendipity_plugin_api::hook_event('myevent')? Actually that wouldn't give any additional functionality except data strings if the function would need it. But for the layout.php there's no advantage for.

The code you added is much better and logical. Jesus, why do I lack of such ideas? That would make my idea working!
If you need it for extra data, yes. The shoutbox and karma plugins create a seperate table, for example.
Seems that I have to analyze the Karma plugin more carefully. The code there overloaded my brain already once. :mrgreen:
Yeah, we have our drawbacks there because it doesn't get updated frequently. We're programmers, not writers -- so we need help with someone documenting...

If you find cases where information is missing, please let me know and I try to fill in the gaps. The more precise your question is, the better I can document the answer
Here I have a problem: since I do not know what functions or additional information should be added I cannot suggest you to add someting. ;)
For example some internal information about special functionalities which might be also used outside the class (I mean private and public functions as they're called so in PHP5).

I think I'll take some time in reading through a couple scripts. :)

I really salute you and your team. It's really amazing how you can maintain and grow your project. I had once a PHP project as well but stumbled finally across my own laziness and the lost ability to maintain the code. <applaus> Gratulations at this point </applaus>

Posted: Tue Nov 02, 2004 10:43 am
by garvinhicking
Hi Thomas!
The event hook does not return a true/false, but you can set values you specify within the function ($eventData and $addData).
Well, can those data vars be appended at serendipity_plugin_api::hook_event('myevent')? Actually that wouldn't give any additional functionality except data strings if the function would need it. But for the layout.php there's no advantage for.
Hm, what do you mean? Yes, you can modify contents of $eventData and $addData, as they are passed as references...?
Seems that I have to analyze the Karma plugin more carefully. The code there overloaded my brain already once. :mrgreen:
Well, yes - I do agree it's a bit complicated; but mighty, mighty, in the end :)
Here I have a problem: since I do not know what functions or additional information should be added I cannot suggest you to add someting. ;)
For example some internal information about special functionalities which might be also used outside the class (I mean private and public functions as they're called so in PHP5).
Well, we have the serendipity_plugin_api.php file which documents all available functions, maybe that is a help for you? But yes, there is a lack of PHP-code documentation, but I think someone took onto that job somewhen..
I think I'll take some time in reading through a couple scripts. :)
that's actually the best way to do things :-)
I really salute you and your team. It's really amazing how you can maintain and grow your project. I had once a PHP project as well but stumbled finally across my own laziness and the lost ability to maintain the code. <applaus> Gratulations at this point </applaus>
Thanks a lot, this is much appreciated! :-)

Posted: Tue Nov 02, 2004 11:36 am
by Thomas
garvinhicking wrote:Hm, what do you mean? Yes, you can modify contents of $eventData and $addData, as they are passed as references...?
Well, what $eventData is I know already. But what is $addData for?
Well, we have the serendipity_plugin_api.php file which documents all available functions, maybe that is a help for you? But yes, there is a lack of PHP-code documentation, but I think someone took onto that job somewhen..
It seems that I have to read more and more ... :shock:
Thanks a lot, this is much appreciated! :-)
You're welcome :mrgreen:

Posted: Tue Nov 02, 2004 12:12 pm
by garvinhicking
Hi Thomas!
Well, what $eventData is I know already. But what is $addData for?
It's for "additional Data", or flags/variables you want to pass to the function, but are not part of $eventData. At some point it got needed because of various reasons and was better for compatibility and speed to create a second variable. Thinking about it, I just found out, that $addData is not passed by reference. :-)

top of content

Posted: Tue Mar 01, 2005 5:24 pm
by efurban
I am trying to make the shoutbox to show on top of all entries instead of the side bar.
jsut wondering where I should put this serendipity_plugin_api::hook_event('tomscorner_top', $serendipity) hook event if I use 0.8 version?

Thanks.

Re: top of content

Posted: Tue Mar 01, 2005 5:35 pm
by garvinhicking
You can place that hook in your templates/XXX/index.tpl file. Look at how the sidebars are implemented. If you don't use the right sidebar, you should use that as your top-sidebar and place it via HTML where you want the output. Then only assign the shoutbox plugin the the right side, and all others to the left side and you're done.

Regards,
Garvin

sidebar

Posted: Wed Mar 02, 2005 7:27 pm
by efurban
I am gonna use the sidebars (both left and right) .
so, let me try to get this right.

1st, I need to add a event hook in the index.tpl file
2nd, in the shoutbox plugin, add and event_hook() function and insert a case statement for what to output at that hook position

how does the invocation work ?
sorry I am a very newbie of s9y and still learning about how s9y works.

Re: sidebar

Posted: Thu Mar 03, 2005 10:42 am
by garvinhicking
Yesterday I committed the possibility to place this code anywhere in your *.tpl files of your template:

{serendipity_showPlugin class="serendipity_plugin_shoutbox"}

This should then show the shoutbox at the place. :-)

Regards,
Garvin

Posted: Thu Mar 03, 2005 9:16 pm
by efurban
thk you very much.
but how do I get this? should I get the newest cvs version of the s9y ?