PDA

View Full Version : PHP Code


Patrick Lucas
12-30-2002, 11:26 PM
Is there a hack so you can put PHP code into a template? :)

That'd be really helpful :) I know PHP... but I dont' know my way well enough around vB to hack it like normal people :(

Sebastian
12-31-2002, 12:59 AM
No, you can't put php in templates, some variables yes. however, Logician made a hack that allows you to put conditionals in the templates, this will be a feature in vb3. https://vborg.vbsupport.ru/showthread.php?s=&threadid=43325

Chris M
12-31-2002, 11:16 AM
Yes you can put PHP in a special template, called the phpinclude template - It acts like global.php, but just is a template:)

Satan

Xenon
12-31-2002, 12:37 PM
phpinclude is the onlyone.
this couldn't be hacked in easily, because all templates are just handled as strings (except phpinclude):

$blabla = gettemplate("templatename");

so you have to rewrite every file you want to use php-templates :)
however, in customtemplates you can use php if you call em like phpinclude (see example in global.php)

Chris M
12-31-2002, 12:40 PM
Yup:)

You could make a new template called "lolarama", as long as you find the line:

// parse PHP include ##################
eval(gettemplate('phpinclude',0,0));
and add:
eval(gettemplate('lolarama',0,0));
directly beneath it:)

Satan

Xenon
12-31-2002, 12:46 PM
eval(gettemplate('lolarama',0,0));

can be in every php-file you use, not just in global.php :)

Chris M
12-31-2002, 12:49 PM
It can can it?

Thanks;) Now I can sort the "conditionals" thingy out without having to get anybody to use Logician's hack:)

Satan

Xenon
12-31-2002, 01:26 PM
just create your own conditionals like me :)
ok, not so comfortable like logicians, but easier to use with experience ;)

Chris M
12-31-2002, 01:33 PM
I think I might actually;)

I won't release it though;) Logician's is good for commercial use, as all of his most recent hacks allow conditional use:)

Satan

Boofo
12-31-2002, 03:02 PM
Originally posted by Xenon
just create your own conditionals like me :)
ok, not so comfortable like logicians, but easier to use with experience ;)

But can you use your conditionals in templates easily? If so, I'd like to know how you do it if you aren't using Logician's hack. :)

Xenon
12-31-2002, 03:07 PM
yes, can be used easily, but you have to take care when using strings in conditions :)

there are no securitychecks in, so parse errors can occur very easy :)

maybe i'm telling you tommorro, i'll go now :)

Chris M
12-31-2002, 03:19 PM
Heh...

I think I know how, but I'll wait till Master Xenon tells us:p

Satan

Xenon
01-01-2003, 06:47 PM
ok, well here it is, as i said, it's not a released hack, no support is given :)

open admin functions.php
in function gettemplate find this:
if ($escape==1) {
$template=addslashes($template);
$template=str_replace("\\'","'",$template);
}

below just add:
// conditionals
$template=str_replace("<if>","\".iif(",$template);
$template=str_replace("<then>",",\"",$template);
$template=str_replace("<else>","\",\"",$template);
$template=str_replace("</if>","\").\"",$template);

then in templates you have to use <if><then><else></if> constructions:

Example:
Hello <if>$bbuserinfo[userid]>0<then>$bbuserinfo[username]<else>Guest, please register</if>

as said, be carefule, it can easily produce parseerrors if you use wrong conditions :)
It just fits my needs, not any checks ;)

Sebastian
01-01-2003, 07:06 PM
said by hellsatan
Yes you can put PHP in a special template, called the phpinclude template


well, how do you know that is what he wants.. maybe he wants to put something like this in a template:


if ($bbuserinfo['userid']!=0) {
echo "member";
} else {
echo "guest";
}


which will not work.. or am i missing something here? sure you can use the phpinclude template.... but we don't know if that is what he wants to do.. my guess is he wants to put full php code in the templates ;)

Xenon
01-01-2003, 07:10 PM
@sebastian: look my post 8 posts above of yours, there's described how he can use full php-code in the templates also (but not HTML anymore :))

The conditional thing i just posted, because boofo wnated it :)

Sebastian
01-01-2003, 07:12 PM
now we're talking, i didn't see that :)

Boofo
01-01-2003, 08:16 PM
Xenon, that conditional code looks interesting. Right now, I am using Logicians hack for this (which I thank you for pointing me in that direction :)). There's certain instances that you can't use conditionals (like the ismoderator instance). Will yours allow that?

Chris M
01-01-2003, 09:06 PM
@Xenon - Those conditions rock:D

Is there an <elseif> one?

Satan

Xenon
01-01-2003, 10:27 PM
@boofo: yes, normally you can use the ismoderator() function.
you should be able to use every php function in the conditions by me :)

@satan: you can build it so by nested if's:
<if>$a==1<then>Hello<else><if>$a==2<then>Hello 2<else>Hello 3</if></if>

But remembe every single condition needs <if><then><else></if>
you cannot use it without the else :)
it just uses the iif-function from vb, so you are limited to this limits

Chris M
01-02-2003, 09:09 AM
I see...:)

Thanks for sharing:D

Satan

Boofo
01-02-2003, 09:30 AM
Originally posted by Xenon
@boofo: yes, normally you can use the ismoderator() function.
you should be able to use every php function in the conditions by me :)

@satan: you can build it so by nested if's:
<if>$a==1<then>Hello<else><if>$a==2<then>Hello 2<else>Hello 3</if></if>

But remembe every single condition needs <if><then><else></if>
you cannot use it without the else :)
it just uses the iif-function from vb, so you are limited to this limits

Can I use this along with Logician's hack then or do I have to use one or the other? And how would I do the ismoderator caneditposts call?

Xenon
01-02-2003, 01:38 PM
@chris: :) no problem, your welcome :)

@boofo: yes you can use both hacks
correct syntax:
<if>ismoderator($threadinfo[forumid],"caneditposts")<then>Editlink<else></if>
but remember, all variables you want to use have to be globalized in the calling template, so i'm not sure if $threadinfo[forumid] would work in postbittemplate

gmarik
06-14-2003, 11:42 AM
Xenon, and how with PHP mixed up with HTML, is it possible?
Maybe there is a solution in vB3?

Xenon
06-14-2003, 12:54 PM
nope php in templates isn't possible.

but you can mix up php and html within the condition part, but just as far as you can do it within a normal if condition of php.

i don't know how's in vb3, i don't have had enough time to look at the code closer

gmarik
06-14-2003, 06:03 PM
It's the most important part,
And nobody can give me the full info.

So I can insert if and else anywhere I want?
And how about other statemetns?! Anybody seen vB3?!

Xenon
06-14-2003, 10:51 PM
just download it yourself and install it on a local board so you can play around and test yourself what's possible and what not ;)