MyBB Community Forums

Full Version: PHP inside custom php page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I'm apparantly having some issues, I have created a custom page like this

<?php

define('IN_MYBB', 1); require "./global.php";

add_breadcrumb("Portfolio", "portfolio.php"); 

eval("\$portfolio_post = \"".$templates->get("portfolio_post")."\";"); 
eval("\$postfolio_newpost = \"".$templates->get("portfolio_newpost")."\";");
eval("\$portfolio_user = \"".$templates->get("portfolio_user")."\";");
eval("\$portfolio_list= \"".$templates->get("portfolio_list")."\";");
eval("\$portfolio_newcomment = \"".$templates->get("portfolio_newcomment")."\";");

?>

The above is working and I checked output_page for all of the above templates and they're working fine, I'm using it like this because I want to just have the whole of the plugin (many pages and variations) to be just inside the portfolio.php page.

Now I want to output different template based on conditions such as 

if (isset($mybb->get_input('pshowid')) && is_numeric($mybb->get_input('pshowid'))) {
    $page2show = "show_post";
} elseif (isset($mybb->get_input('ushowid')) && is_numeric($mybb->get_input('ushowid'))) {
    $page2show = "show_user";
} elseif (isset($mybb->get_input('page')) && $mybb->get_input('page') == "newpost") {
    $page2show = "show_newpost";
} else {
    $page2show = "show_list";
}

This is just my most recent try where I used if-elseif to set a string variable whereas I later use a switch statement.

The switch statement itself should be fine, neither works though, I've tried outputting page directly through the if statement, gives me HTTP 500 Error. Obviously the PHP is interfering somehow, anything I could do?

The switch statement is here

switch ($page2show) {
    case "show_post":
    output_page($portfolio_post);
    break;

    case "show_user":
    output_page($portfolio_user);
    break;

    case "show_newpost":
    output_page($portfolio_newpost);
    break;

    default:
    output_page($portfolio_list);
}

Using only the switch and manually setting the $page2show variable works fine, alas it's the if statement that's ruining my life.

Thanks a lot.

For future reference for anyone reading this, I tried a lot of things before I looked at my code and realised, since I didn't set a variable to receive the expressions ($mybb->get_input(#)) then I can't check if an expression isset, instead I check if the result was not null like this

if (null !== $mybb->get_input['input']) { code }

Goodluck and have fun.