how to include a random header php script into the index.tpl

Skinning and designing Serendipity (CSS, HTML, Smarty)
Post Reply
leo
Regular
Posts: 24
Joined: Thu Aug 04, 2005 11:56 am

how to include a random header php script into the index.tpl

Post by leo »

hey guys.


after a bit playing with the different themes I like to include a random header php script into the index.tpl template file.
I tried it with "{include_php}" but there comes errors and errors.
so is here somebody who can give a tip?

thanks for your help.
leo
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: how to include a random header php script into the index

Post by garvinhicking »

If you tell us the errors, we might tell you what's wrong.:)

There are some plugins that take care of random blog descriptions or kubrick headers files. If you're brave, you can also try the suggestions from http://www.s9y.org/index.php?node=78

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/
leo
Regular
Posts: 24
Joined: Thu Aug 04, 2005 11:56 am

Post by leo »

hey guys.

when I trie to include a .php file into the index.tpl with this code:

Code: Select all

<table id="mainpane">
<tr>
	<td>{include_php file="/serendipity_083/plugins/serendipity_event_rotateheader/index.php"}</td>
</tr>

this error message showes up:
Warning: Smarty error: unable to read resource: "" in E:\www\projekte\leo_serendipity_blog\serendipity_083\bundled-libs\Smarty\libs\Smarty.class.php on line 1088
So I am a newbie in smarty and php and I hope somebody can give me a tip.

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

Post by garvinhicking »

By default the security settings of Smarty do not allow to use the include_php method.

There are two ways to fix this. Both include creating a "config.inc.php" file inside your template directory.

Inside that file you can put:

1. Disable the smarty security settings:

Code: Select all

<?php
$serendipity['smarty']->security = false;
$serendipity['smarty']->security_settings = false;
?>
2. Or you can include your functions via that config file:

Code: Select all

<?php
ob_start();
include your_php_file.php
$data = ob_get_contents();
ob_end_clean();
$serendipity['smarty']->assign('my_content', $data);
?>

Inside your template you can then put {$my_content} where you need it.

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/
leo
Regular
Posts: 24
Joined: Thu Aug 04, 2005 11:56 am

Post by leo »

hey garvin.

that sounds easy, but how does the index.tpl know that there is a config.inc.php file?


thanks for your help.
leo
leo
Regular
Posts: 24
Joined: Thu Aug 04, 2005 11:56 am

Post by leo »

ok, maybe I am too stupid.

I created a config.inc.php file in my template directory (/templates/leo) with this code inside:

Code: Select all

<?php
ob_start();
include('/projekte/leo_serendipity_blog/serendipity_083/plugins/serendipity_event_rotateheader/rotateheader.php');
$data = ob_get_contents();
ob_end_clean();
$serendipity['smarty']->assign('my_content', $data);
?> 
then I inserted this code line {$my_content} into my index.tpl file, because I thought that's a variable which includes the link to my php rotateheader script

but nothing happends, no errors and no rotating header....
where's my fault?

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

Post by garvinhicking »

First off, the serendipity API logic searches for a "config.inc.php" file. :)

Second off, $my_content contains the OUTPUT of your inclusion script.

To see if it actually get's executed, change your config.inc.php snippet like this:

Code: Select all

<?php
ob_start();
include('/projekte/leo_serendipity_blog/serendipity_083/plugins/serendipity_event_rotateheader/rotateheader.php');
$data = ob_get_contents();
ob_end_clean();
$serendipity['smarty']->assign('my_content', "Mein inhalt ist: $data");
?> 
Then you should see a "Mein inhalt ist:" string in your template output.

Are you sure that the path /projekte/leo_.../ is the right path? You used an absolute path, usually on webservers you have something like "/www/htdocs/leo/..."...?

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/
leo
Regular
Posts: 24
Joined: Thu Aug 04, 2005 11:56 am

Post by leo »

ok.

there is an ouput: Mein Inhalt ist:

so I think there is something wrong in my script.
but if I test yust the script it works.

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

Post by garvinhicking »

Are you sure the path of the include is right?

Create a simple "test.php" script in your s9y root wherer you just put this:

Code: Select all

<?php
include('/projekte/leo_serendipity_blog/serendipity_083/plugins/serendipity_event_rotateheader/rotateheader.php'); 
And then check if you get any output?

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/
leo
Regular
Posts: 24
Joined: Thu Aug 04, 2005 11:56 am

Post by leo »

ok, you are right. I had a mistake in my path.
but now comes another error.

my rotateheader script includes a config_ini file

Code: Select all

$IMG_CONFIG_FILE = 'images.ini';
and I get this mistake now:
Unable to read ini file.
so is there something in the serendipity config that disables .ini files?

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

Post by garvinhicking »

It seems your script tries to read the file frmo the current path, but the current path is Serendipity. You need to try to pass the full path of the ini file to your script.

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/
leo
Regular
Posts: 24
Joined: Thu Aug 04, 2005 11:56 am

Post by leo »

I got it.

thousands thx to mr. garvin hicking for his tips.

seeYa next time,
leo
Guest

Does it matter

Post by Guest »

Hi Gavin,

Is there a major risk in turning off the security settings? Is one method better than the other?

If one wants to include multiple functions, do we just repeat the code in the config.inc.php file, or is there a more efficient way?

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

Re: Does it matter

Post by garvinhicking »

It's only a major risk, if other people have FTP access to your blog and if you don't want them to mangle with your templates.

It is better to use the config.inc.php setting for security, because you don'T need to patch include/functions_smarty.inc.php that way every time.

You can include multiple functions by just duplicating the call in config.inc.php, yes. :)

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