<?php

function printVal($val,$escape=true) {
    switch (gettype($val)) {
        case 'integer':
        case 'double':
            return $val;
        case 'string':
            return "\"".(($escape !== false)?htmlspecialchars(addcslashes($val,"\\\"\$\r\n\t")):$val)."\"";
        case 'array':
            return formatArray($val);
        case 'object':
            return 'Object('.get_class($val).')';
        case 'resource':
            return 'Resource('.strstr($val, '#').')';
        break;
        case 'boolean':
            return $val ? 'true' : 'false';
        break;
        case 'NULL':
            return 'NULL';
        break;
        default:
            return 'Unknown';
    }
}

function formatArray($arr, $level=0){
    if(gettype($arr) == "array") {
        $ret="Array(";
        foreach ($arr as $name => $value){
            switch(gettype($value)){
                case "array":
                    $level++;
                    switch(strtolower($name)){
                        case "globals";
                            
                            $value = "Array (..)";
                        break;
                        default: 
                            $value = formatArray($value, $level);
                        break;
                    }
                break;
                case "string":
                        $value="\"".htmlspecialchars(addcslashes($value,"\\\"\$\r\n\t"))."\"";
                break;
                case "integer":
                break;
                case "double":
                break;
                case "boolean":
                        $value=$value?"true":"false";
                break;
                case "resource":
                        $value= 'Resource('.strstr("$value", '#').') /* '.get_resource_type($value).' */'; 
                break;
                default:
                    $value=gettype($value);
                break;
            }
            if(!is_numeric($name)) {
                $value = "\"$name\" => $value";
            }
            if($ret == "Array(") $ret.=$value; 
            else $ret.=",".$value;
        }
        $ret .= ")";
        return $ret;
    } else {
        return $arr;
    }
}

function random_string($len=5, $opt='dlu') {
    list($usec, $sec) = explode(' ', microtime());
    mt_srand(($usec*1000000)+$sec); //second seed
    $chr=""; $str="";
    if (strpos($opt,"d") !== false) for($i=48; $i<=57; $i++) $chr.=chr($i);
    if (strpos($opt,"u") !== false) for($i=65; $i<=90; $i++) $chr.=chr($i);
    if (strpos($opt,"l") !== false) for($i=97; $i<=122; $i++) $chr.=chr($i);
    for ($i=0; $i<$len;$i++) $str.=$chr[mt_rand(0,strlen($chr)-1)];
    return $str;
}

function getinfo() {
    global $ip, $host;
    return "[".date("Y-m-d H:i:s")."] [$ip".(!empty($host)?" $host":"")."]";
}

function config(){
    global $PHP_SELF;
    if(!file_exists("include/db.php")){
    
    $dbhost=isset($_POST['dbhost'])?$_POST['dbhost']:"localhost";
    $dbuser=isset($_POST['dbuser'])?$_POST['dbuser']:"";
    $dbpass=isset($_POST['dbpass'])?$_POST['dbpass']:"";
    $dbname=isset($_POST['dbname'])?$_POST['dbname']:"dbname";
    $dbok=false;
    if(!empty($_POST)){
        //check db
        $db_link=@mysqli_connect($dbhost, $dbuser, $dbpass);
        if($db_link){
            $dbtest=mysqli_select_db($db_link,$dbname);
            if(!$dbtest){
                echo "Error";
                $dbok=false;
            } else {
                echo "Suscefully tested connection...";
                $code="<?php\n\tif(!isset(\$newconn)) \$newconn=false;\n\t\$dbhost=\"$dbhost\";\n\t\$dbuser=\"$dbuser\";\n\t\$dbpass=\"$dbpass\";\n\t\$db=\"$dbname\";\n\t\$db_link=mysqli_connect(\$dbhost, \$dbuser, \$dbpass) or die(mysqli_connect_error());\n?".">";
                $dbok=true;
                echo "Saving db file... ";
                $file=fopen("include/db.php", "w");
                if($file) {
                    fwrite($file, $code);
                    fclose($file);
                    chmod("include/db.php", 0664);
                    echo "<a href=\"/\">Proceed</a>";
                }
            }
            mysqli_close($db_link);
        } else {
            echo "<b>Connection Error:</b> ".mysqli_connect_error();
        }
    }
    if (!$dbok){

?>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<table align="center">
<tr><td>DB Host:<td> <input type="text" name="dbhost" value="<?php echo $dbhost; ?>"></tr>
<tr><td>DB User:<td><input type="text" name="dbuser" value="<?php echo $dbuser; ?>"></tr>
<tr><td>DB Password:<td><input type="password" name="dbpass" value=""></tr>
<tr><td>DB Name:<td><input type="text" name="dbname" value="<?php echo $dbname; ?>"></tr>
<tr><td align="center" colspan="2"><input type="submit" value="Proceed">
</table>
</form>
<?php
    }

    } else {
        if(isset($_POST['main']) && ($_POST['main'] != "")) {
            $main=$_POST['main'];
            $code="<?php\n\t\$main=\"include/$main\";\n?".">\n";
            echo "Saving config file... ";
                $file=fopen("include/config.php", "w");
                if($file) {
                    fwrite($file, $code);
                    fclose($file);
                    echo "<a href=\"/\">Proceed</a>";
                }
        } else {
?>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<table align="center">
<tr><td>Main site code (design, etc): <input type="text" name="main" value="design.php"></tr>
<tr><td align="center"><input type="submit" value="Save Values">
</table>
</form>
<?php
        }
    }
} 

function loginform(){
    global $PHP_SELF;
?>
Not logged in. Please login.<hr>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<table align="center">
<tr><td>Login:<td><input type="text" name="login"></tr>
<tr><td>Pass:<td><input type="password" name="pass"></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Login"></tr>
</table>
</form>
<?php
}

function auth(){
    global $PHP_SELF, $valid, $_SESSION, $_POST;
    $action=isset($_GET['action'])?addslashes($_GET['action']):"";
    include "include/authcfg.php";
    if($action=="logout") {
        session_unset();
        header("Location: $PHP_SELF");
        exit;
    }
    if(isset($_SESSION['name'])&&($_SESSION['name']==$adm[0])&&($_SESSION['pass']==$adm[1])){
        $valid=true;
    } else {
        if(isset($_POST['login'])) {
            if(($_POST['login'] == $adm[0]) && (md5($_POST['pass']) == $adm[1]) ) {
                $_SESSION['name']=$_POST['login'];
                $_SESSION['pass']=md5($_POST['pass']);
                header("Location: $PHP_SELF");
                exit;
            } else {
                $err="Wrong login.<hr>";
            }
        } 
    }    
}

function loadmodule($file){
    global $_GET, $_POST, $_SESSION, $_COOKIE, $PHP_SELF, $module, $home, $title, $lang, $prefix;
    global $section, $login ,$valid, $admin, $rss, $rss_extra, $redir, $redurl, $bots, $evt, $timing;
    global $count_show,$count_type,$count_name,$count_ro,$count_external,$count_lang;
    //global $count_time,$count_lock;
    global $lang_exclude, $sect_exclude, $sect_hide, $sect_support, $sect_ok, $mylinks;
    global $ip, $host;
    global $db_link; //for shared connections
    global $is_mobile, $is_bot;
    //echo htmlspecialchars($txt);
    if (isset($_GET['debug'])) {
        $timing[]=Array("loadmodule($file) begin",microtime(true));
    }
    if (file_exists($file))
        include $file;
    else echo "Module file does not exist or incorrect.";
    if (isset($_GET['debug'])) {
        $timing[]=Array("loadmodule($file) end",microtime(true));
    }
}

if (!function_exists('apache_response_headers')) {
    function apache_response_headers () {
        $arh = array();
        $headers = headers_list();
        foreach ($headers as $header) {
            $header = explode(":", $header);
            $arh[array_shift($header)] = trim(implode(":", $header));
        }
        return $arh;
    }
}

include "bbparser.php";

?>

You can also check other includes below (some files are hidden as they are in exclusion list):
bbparser.php