Page 1 of 1

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

Posted: Mon Aug 08, 2005 8:47 pm
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

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

Posted: Mon Aug 08, 2005 11:13 pm
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

Posted: Tue Aug 09, 2005 6:40 pm
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

Posted: Tue Aug 09, 2005 8:46 pm
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

Posted: Tue Aug 09, 2005 9:19 pm
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

Posted: Tue Aug 09, 2005 9:57 pm
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

Posted: Tue Aug 09, 2005 11:25 pm
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

Posted: Tue Aug 09, 2005 11:34 pm
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

Posted: Wed Aug 10, 2005 12:11 am
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

Posted: Wed Aug 10, 2005 11:09 pm
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

Posted: Thu Aug 11, 2005 12:52 pm
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

Posted: Thu Aug 11, 2005 3:36 pm
by leo
I got it.

thousands thx to mr. garvin hicking for his tips.

seeYa next time,
leo

Does it matter

Posted: Fri Sep 30, 2005 3:38 pm
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

Re: Does it matter

Posted: Fri Sep 30, 2005 4:36 pm
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