template request hook before output in entries.tpl

Skinning and designing Serendipity (CSS, HTML, Smarty)
Post Reply
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

template request hook before output in entries.tpl

Post by Timbalu »

To Bulletproof and other template file.... authors.

Please use

Code: Select all

{serendipity_hookPlugin hook="entries_header" addData="$entry_id"}
<!-- ENTRIES START -->

{foreach from=$entries item="dategroup"}
instead of

Code: Select all

<!-- ENTRIES START -->

{serendipity_hookPlugin hook="entries_header" addData="$entry_id"}
{foreach from=$entries item="dategroup"}
to avoid output of newlines and the hidden start tag, if a plugin is generating email or download output.
I am just testing to send an ical.ics file which gets cought by this, even if working with str_replace everything around the download.tpl data.

Thank you,
Ian

:arrow: Is anybody around who knows about a way to get a plugins version number as a useable variable?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: template request hook before output in entries.tpl

Post by garvinhicking »

Hi!

I wouldn not use this event hook to generate download code. Use external_plugin or frontend_configure? entries_header etc. is only meant to create additional output, not replace actual existing output of the surroundings.
:arrow: Is anybody around who knows about a way to get a plugins version number as a useable variable?
For what exactly? You could make your plugin go set a $this->set_config('myversion', '1') variable, or also access the $propbag via introspection...

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/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: template request hook before output in entries.tpl

Post by Timbalu »

garvinhicking wrote:Hi!

I wouldn not use this event hook to generate download code. Use external_plugin or frontend_configure? entries_header etc. is only meant to create additional output, not replace actual existing output of the surroundings.
:arrow: Is anybody around who knows about a way to get a plugins version number as a useable variable?
For what exactly? You could make your plugin go set a $this->set_config('myversion', '1') variable, or also access the $propbag via introspection...

Regards,
Garvin
No, sorry, this is just the beginning of bulletproofs entries.tpl. I need the < -- foo -- > inside the hook. It has nothing to do with my download file, exept it will be generated with, if not placed after the hook.

About the version variable, how can I get it with access the $propbag via introspection? I have no idea... I just need it as a var in my plugin, eg. the download file. To set an extra config var for this, seems like a overhead for me.

Ian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: template request hook before output in entries.tpl

Post by garvinhicking »

Hi!

Yeah, but why does your download plugin use this hook? Other ones would be more suitable. You cannot rely on people changing their template like this, your plugin will then not work with many templates.
About the version variable, how can I get it with access the $propbag via introspection? I have no idea... I just need it as a var in my plugin, eg. the download file. To set an extra config var for this, seems like a overhead for me.
Should be doable like this:

Code: Select all

        $bag = new serendipity_property_bag;
        $this->introspect($bag);
        echo "Version: " . $bag->get('version');
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/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: template request: set hook before output in entries.tpl

Post by Timbalu »

Thank you Garvin.
I'll did it along this way and defined it more easily as

Code: Select all

$serendipity['plugin_eventcal_version'] = &$bag->get('version'); 
in function function event_hook, so now I can use it everywhere.

2. Well, if have got a function inside the plugin which generates and sends the ics file :

Code: Select all

         echo $icl;
         header("Content-Disposition: inline; filename=icalendar.ics");
         exit;
I am not using any hook, its just the 'header' output of entries.tpl which gets parsed until {serendipity_hookPlugin hook="entries_header" addData="$entry_id"} really starts, or in my case does not start, which is the expected behaviour. Where is my mental block? ;-)

Ian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: template request: set hook before output in entries.tpl

Post by garvinhicking »

Hi!

For the version, that's fine :)

About your hook: You should use an external hook, like external_plugin -- http://blog/plugin/BLABLA.ics for example. This is WAY MORE performant than calling the whole fetchentries logic and then offering a download file. Plus, as you can see, it doesn't work with all templates. external_plugin is invented to deal with bypassing everything :)

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/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: template request hook before output in entries.tpl

Post by Timbalu »

ok, thank you. I am going to try this. Can I use it it inside the function itself?

Ian
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: template request hook before output in entries.tpl

Post by Timbalu »

Hi Garvin

I now tried around a lot with this behaviour, even with creating all output in an external_plugin hook.
Its still the same, while it depends on echo $output. If you echo something, you get this start behaviour of templates entries.tpl. So its not recommended to do downloading content via generate string (like my try) or fopen/fread file functions, even within an external_plugin hook, while you need echo $content.
So I came around doing it this way, which is working as expected:

Code: Select all

	case 'dl': 
		if($wcal === true) { 
			$url = $_SERVER['HTTP_HOST'] . $serendipity['serendipityHTTPPath'] . 'uploads/icalendar.ics';
			if (serendipity_isResponseClean($url)) {
				header('Status: 302 Found');
				header('Location: http://' . $url);
			}
		}
		break;
Btw, crawling the web I found an interesting article about HTTP_HOST vs SERVER_NAME:
http://shiflett.org/blog/2006/mar/serve ... -http-host
and http://seancoates.com/xss-woes
Does this effect Serendipity somewhere?

Regards,
Ian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: template request hook before output in entries.tpl

Post by garvinhicking »

Hi!

Chek out the spamblock plugin, it uses external plugin to create a GIF graphic, and works perfelcty fine with omitting all other output.

I think the HOST-Thing was discussed at some point and found unproblematic, but I don't find the thread right now.

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/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: template request hook before output in entries.tpl

Post by Timbalu »

inside spamblock plugin external_plugin hook

Code: Select all

                        header('Content-Type: image/png');
                        ....
                        if (file_exists($cap)) {
                            echo file_get_contents($cap);
                        }
hmm, if I do it like this inside my external_plugin hook, just calling the ics file, which is definitely a plain ical file string with first line: BEGIN:VCALENDAR

Code: Select all

echo file_get_contents('http://' . $url); 
header("Content-Disposition: inline; filename=icalendar.ics");
exit;
it downloads as icalendar.ics

Code: Select all

<!-- ENTRIES START -->

BEGIN:VCALENDAR
VERSION:2.0
....
still the same with echo and the template entries.tpl! Is it still my very own stupidity? ;-)
Where is the difference?

Ian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: template request hook before output in entries.tpl

Post by garvinhicking »

Hi!

That can't really be...which other event plugins do you use? Maybe anyone of those uses frontend_configure or other event hooks to render smarty template files. You might want to try this on an unmodified s9y installation with only your ical pluigin enabled? It should work...

Otherwise the spamblock graphic would also contain that ENTRIES html?!

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