MyBB Community Forums

Full Version: php question.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello guys and happy holidays!

I have a technical question about the templates. I want to insert a small patch of code into the footer of the forum, but the code is in php. Basically its a simple <?php include 'xxxxx.php'; ?> to show something at the bottom of the forum which is randomly pulled from another SQL database.

The user editble templates are html / javascript only. I understand the concerns and security reasons why the general template editing does not allow php code.

FTP & editing the core files is not a problem. I can hard key the code directly in the myBB php file, but I've not had any luck. Seems the page_output() foils my attempt to do this. Maybe I'm just putting the code in the wrong place?

I tried just on the index.php file (bottom of the code I added the php include I need to add)

$forum_list = build_forumbits();
$forums = $forum_list['forum_list'];

$plugins->run_hooks("index_end");

eval("\$index = \"".$templates->get("index")."\";");
output_page($index);

include './showme.php';
?>


It didn't work.

That said, can anyone tell me how/where to add that one line of code so that it is the last thing shown on the bottom of every myBB forum page? I'm running MyBB 1.6.3

THANKS!
Maybe include it before the output_page($index);
a plugin or core edit will handle it. add a variable placeholder to the footer template where you want your content to show and wrap it in whatever formatting you want/ example:

<div class="smalltext">{$my_content}</div>

file edit method:
edit global.php and insert your line before the footer evaluation like so

include './showme.php';
eval("\$footer = \"".$templates->get("footer")."\";");

and make sure the content of your showme.php file populates a varaible matching what you added in the template, in this example

$my_content = "something I want to see.";

a plugin is little more complicated, but not too bad
Thanks pavemen!

In your example the $my_content is a variable. The include that I'm doing basically pulls from a SQL database and displays a small table of 5-8 items. So I'm not really defining a variable for output, the include is what displays the table. the "include" file actually echo's html back.

That said, if I just do the include before the eval/footer in the global.php, would that still work or would I have to somehow dump everything I'm echoing out in that include to a variable into $my_content to get it to work? (yuck).
Ok, I put the include in and it did somewhat work. My code ended up at the TOP of the page when I put the include in the footer section. It also screwed up the entire layout of the forum columns & sizes. Not good.

I guess this is not going to work as planned. I may have to put the include as the very last thing on the page itself, after the footer and myBB code. Suggestions?

http://www.stogiechat.com/forum/

Anything I put right before the "footer" eval actually goes to the top of the forum. Sad
becuase MyBB uses a template system you have to use variables. modify your showme.php file so that instead of echo'ing the table and its contents directly, store it in a variable.

basically replace any "echo" with "$my_content .= " and then it wont output any html directly, and then the footer modification you made will show the table
I started to code the module like this just before you posted back:
$myoutput = "<style type='text/css'>form{margin:0; padding:0;}</style>";
$myoutput = $myoutput."<style type='text/css'>table{table-layout:fixed;}</style>";

I see you used $my_content .= "<style type='text/css'>form{margin:0; padding:0;}</style>";
Should I use that instead? .= versus $myoutput = $myoutput."xxxxxxxx"
(2011-12-07, 02:39 AM)ebturner Wrote: [ -> ]I started to code the module like this just before you posted back:
$myoutput = "<style type='text/css'>form{margin:0; padding:0;}</style>";
$myoutput = $myoutput."<style type='text/css'>table{table-layout:fixed;}</style>";

I see you used $my_content .= "<style type='text/css'>form{margin:0; padding:0;}</style>";
Should I use that instead? .= versus $myoutput = $myoutput."xxxxxxxx"

.= is called concatenate. It's adding something to a variable without clearing the variable. Think of it like the following.
//Clearing variable
$str1 = "This is a string";
$str1 = "I've just cleared it";

//Concatenate variable
$str2 = "This is a string ";
$str2 .= "and it's continued here.";

echo $str1; //Will echo out "I've just cleared it".
echo $str2 //Will echo out "This is a string and it's continued here."

use the shorthand .= as its cleaner and easier to read
Thanks, I'm somewhat new to php. I got it working, somewhat. I'm kinda opening up cans of worms I see. When I got that working, the "List View New Posts | View Today's Posts" only shows a blank screen. If I remove the include statement in the global.php file, then things are back to normal (except then my code does not work).

I'm going to have to play around with this a bit more. At least now I have some direction with editing the right files and putting the output to a variable versus what i was trying to do at first. Now its just a matter of findout out why the include causes the other functions to not work.

Thanks guys/gals for all the help! Much appreciated!
No problem, ebturner. I hope everything works out.
Pages: 1 2