Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: ESFclandoteu on April 02, 2010, 06:22:42 PM

Title: odd php behavior
Post by: ESFclandoteu on April 02, 2010, 06:22:42 PM
Hi all

I'm having a very strange issue when I try to add the following to a block
<?php ssi_showPoll(); ?>

In this case I'm trying to show the poll in topic 669 so, <?php ssi_showPoll(669); ?>.

When I'm within the admin section and non forum parts of my site, the poll displays fine, but as soon as I'm out and viewing the forums it returns an error;

"Fatal error: Call to undefined function ssi_showPoll() in /home/xxxxxxxx/public_html/includefile.php(24) : eval()'d code on line 2"
This error also stops my forums from displaying.

What's more bizarre is that on the pages that don't return the error, the block I put the code in becomes unnecessarily stretched and with the poll right at the bottom of the block, this also happens if I insert the code within a page. See the attached image to understand what I mean.

I've not got an ounce of knowledge about php or ssi's apart from what I've read at ssi_examples.php within my smf installation.

If anyone could shed any light on this it would be very much appreciated.
Title: Re: odd php behavior
Post by: Arantor on April 02, 2010, 07:03:46 PM
You don't have a require or include statement calling SSI.php first.
Title: Re: odd php behavior
Post by: ESFclandoteu on April 03, 2010, 12:29:16 AM
as I previously mentioned I'm a php noob. I don't know what either of those things are??
Title: Re: odd php behavior
Post by: MultiformeIngegno on April 03, 2010, 05:09:55 AM
What do you mean by "block"? Are you using a portal?
Title: Re: odd php behavior
Post by: ESFclandoteu on April 03, 2010, 07:45:04 AM
Yes I am
Title: Re: odd php behavior
Post by: MultiformeIngegno on April 03, 2010, 08:12:55 AM
In this case if you're using a php block I don't think you need the php tags..
Title: Re: odd php behavior
Post by: Orstio on April 03, 2010, 08:35:39 AM
QuoteIn this case I'm trying to show the poll in topic 669 so, <?php ssi_showPoll(669); ?>.

When I'm within the admin section and non forum parts of my site, the poll displays fine, but as soon as I'm out and viewing the forums it returns an error;


You can't have SSI and SMF on the same page.  SSI won't load if SMF is already running.
Title: Re: odd php behavior
Post by: Arantor on April 03, 2010, 12:31:32 PM
QuoteSSI won't load if SMF is already running.

Well, that's not entirely correct... you can include the file and use the functions in it, as some portals do actually do.
Title: Re: odd php behavior
Post by: Orstio on April 03, 2010, 02:10:30 PM
Quote from: Arantor on April 03, 2010, 12:31:32 PM
QuoteSSI won't load if SMF is already running.

Well, that's not entirely correct... you can include the file and use the functions in it, as some portals do actually do.

SSI.php, lines 25-27:

// Don't do anything if SMF is already loaded.
if (defined('SMF'))
return true;


So, yes, it is entirely correct.

Title: Re: odd php behavior
Post by: Arantor on April 03, 2010, 02:48:32 PM
Then how come you can invoke SSI.php and the functions still get defined?
Title: Re: odd php behavior
Post by: Orstio on April 03, 2010, 02:51:13 PM
From SMF?  You can't.
Title: Re: odd php behavior
Post by: Arantor on April 03, 2010, 02:57:31 PM
I've seen it done where it's been included in index.template.php to use SSI functions in the theme. It was even submitted as a mod a bit back to use ssi_recentTopics.
Title: Re: odd php behavior
Post by: Orstio on April 03, 2010, 03:02:16 PM
Then I suggest you try it. :P
Title: Re: odd php behavior
Post by: Arantor on April 03, 2010, 03:08:06 PM
I modified 2.0 RC3 fresh install like so:

function template_html_below()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;

global $boarddir;
include($boarddir . '/SSI.php');
ssi_recentTopics();
echo !empty($settings['forum_width']) ? '
</div>' : '', '
</body></html>';
}


As you can see, bringing the variable in to scope to get path, then calling SSI recent topics.

I would attach it but the server runs out of memory and whitescreens on me if I do, so instead... http://www.wordowl.com/misc/smf/ssi_recent_topics.png

Now tell me it doesn't work.
Title: Re: odd php behavior
Post by: Orstio on April 03, 2010, 03:10:01 PM
And your SSI.php is not modified in any way?
Title: Re: odd php behavior
Post by: Arantor on April 03, 2010, 03:11:22 PM
Nope. Is a 2.0 RC3 fresh install just to be sure.

I suggest you try it.
Title: Re: odd php behavior
Post by: Orstio on April 03, 2010, 03:15:06 PM
Can you change it slightly to this?

function template_html_below(){
global $context, $settings, $options, $scripturl, $txt, $modSettings;
global $boarddir;
echo SMF;
include($boarddir . '/SSI.php');
echo SMF;
ssi_recentTopics();
echo !empty($settings['forum_width']) ? '</div>' : '', '</body></html>';
}
Title: Re: odd php behavior
Post by: Arantor on April 03, 2010, 03:18:03 PM
Sure, copy/paste exactly as that.

Result is http://www.wordowl.com/misc/smf/ssi_recent_topics2.png
Title: Re: odd php behavior
Post by: Orstio on April 03, 2010, 03:22:42 PM
Well, as I expect, I get absolutely no results except for the "11".

http://www.everything-science.com/forum/
Title: Re: odd php behavior
Post by: Arantor on April 03, 2010, 03:26:56 PM
OK, so let's get down and dirty.

I'm using PHP 5.2.6 on Windows + Apache 2.2.something. Related?
Title: Re: odd php behavior
Post by: Orstio on April 03, 2010, 03:34:19 PM
PHP 5.2.11, Linux, Apache 2.2.14

Are you running this locally?  I'd be concerned about it running live on the web this way.  If it is executing scripts despite the check for 'SMF' failing, then it would do the same for the security check in all the Sources files.

i.e, if this doesn't stop SSI.php from running when the constant 'SMF' is already defined with a value of '1':

// Don't do anything if SMF is already loaded.
if (defined('SMF'))
return true;


then this won't stop Subs.php from running either:

if (!defined('SMF'))
die('Hacking attempt...');
Title: Re: odd php behavior
Post by: Arantor on April 03, 2010, 03:37:33 PM
I am running it locally, yes.

The security check for Sources files still works as it's supposed to.
Title: Re: odd php behavior
Post by: ESFclandoteu on April 03, 2010, 03:38:04 PM
Hi guys sorry to interrupt your truly fascinating discussion/debate but what do I need to do/enter into a block to get it to show a specific poll?

Or cant I?
Title: Re: odd php behavior
Post by: Arantor on April 03, 2010, 03:39:10 PM
We're getting into that; what we're talking about is directly relevant to why you shouldn't be able to do it a really easy way.
Title: Re: odd php behavior
Post by: Orstio on April 03, 2010, 03:40:46 PM
Quote from: ESFclandoteu on April 03, 2010, 03:38:04 PM
Hi guys sorry to interrupt your truly fascinating discussion/debate but what do I need to do/enter into a block to get it to show a specific poll?

Or cant I?

Open SSI.php.

Copy the function you want from it.  In your case, ssi_showPoll().  Make sure to get the entire function right to the last curly bracket.

Open Sources/Subs.php.

Paste the function into it, just above the closing PHP tag ( ?> ).

Now go ahead and call the function from wherever you want.
Title: Re: odd php behavior
Post by: Orstio on April 03, 2010, 03:42:12 PM
Quote from: Arantor on April 03, 2010, 03:37:33 PM
I am running it locally, yes.

The security check for Sources files still works as it's supposed to.

I'm wondering if this is something Windows-related, in particular with the return command outside a function.  :-\
Title: Re: odd php behavior
Post by: Arantor on April 03, 2010, 03:46:19 PM
It's entirely possible, I'll have to retest that on my Linux VPS shortly.
Title: Re: odd php behavior
Post by: MultiformeIngegno on April 03, 2010, 03:59:02 PM
A genius war, god saves us!!
I can see a weird and unseen light coming from your swords!! Your cloaks are in the ground, the battle is beginning!

Arantor vs. Orstio, soon at simplemachines.org!
Title: Re: odd php behavior
Post by: Arantor on April 03, 2010, 04:39:16 PM
I'm not a genius, Orstio is more than for writing parts of SMF... haven't had chance to test this yet.
Title: Re: odd php behavior
Post by: MultiformeIngegno on April 03, 2010, 06:40:11 PM
I was joking!! :D
Title: Re: odd php behavior
Post by: ESFclandoteu on April 04, 2010, 10:14:02 AM
Quote from: Orstio on April 03, 2010, 03:40:46 PM
Quote from: ESFclandoteu on April 03, 2010, 03:38:04 PM
Hi guys sorry to interrupt your truly fascinating discussion/debate but what do I need to do/enter into a block to get it to show a specific poll?

Or cant I?

Open SSI.php.

Copy the function you want from it.  In your case, ssi_showPoll().  Make sure to get the entire function right to the last curly bracket.

Open Sources/Subs.php.

Paste the function into it, just above the closing PHP tag ( ?> ).

Now go ahead and call the function from wherever you want.

Hi, thanks for your reply, I've done this and I get this error
Fatal error: Cannot redeclare ssi_showpoll() (previously declared in /home/_____/public_html/forums/SSI.php:880) in /home/_____/public_html/forums/Sources/Subs.php on line 4421

I did as you said so I'm kinda confuzzled.

I've attached my subs file just incase it's something I've missed.

I should also say that I get this error when going to my admin page, not anywhere else on the site
Title: Re: odd php behavior
Post by: Orstio on April 04, 2010, 02:25:43 PM
OK, re-reading your initial post, I see that you're wanting to use SSI from outside SMF as well as inside SMF.

Rename the function in Subs.php to ssi_showPoll2, and then change all of your calls to that as well.
Title: Re: odd php behavior
Post by: Norv on May 10, 2010, 06:11:46 AM
About using SSI inside SMF: if SMF is loaded, it won't do the entire initialization part. That's all, the functions can be called just fine, since they are defined when the file was included. It simply doesn't execute the rest of the initialization statements.
(http://www.php.net/manual/en/function.include.php)
Quote
If there are functions defined in the included file, they can be used in the main file independent if they are before return() or after.