function loadScripts()
{
    $skin = getSkinName();
    //Generate a list of all the current skins.
    $skins = array();
    if (($dir = opendir("assets/skins/")) !== false) {
        while (($file = readdir($dir)) !== false) {
            //Ignore directories and index.html
            if ($file == "." || $file == ".." || $file == "index.html") {
                continue;
            }
            //Gets "white" from "path/to/white.css"
            $skins[] = pathinfo($file, PATHINFO_FILENAME);
        }
        closedir($dir);
    }
    if (!empty($_SERVER["HTTPS"])) {
        //Since you're using SSL, we need the SSL server's address
        echo "\n<script type=\"text/javascript\">\n\twebchat.servers[0].port = 9192;\n\twebchat.servers[0].address = \"wss://marbleblast.com\";\n</script>";
    }
    if (array_key_exists("port", $_GET)) {
        $port = (int) $_GET["port"];
        echo "\n<script type=\"text/javascript\">\n\twebchat.servers[0].port = {$port};\n\tif (webchat.servers.length > 1)\n\t\twebchat.servers.pop(1);\n</script>";
    }
    if (array_key_exists("address", $_GET)) {
        $address = addslashes($_GET["address"]);
        echo "\n<script type=\"text/javascript\">\n\twebchat.servers[0].address = '{$address}';\n\tif (webchat.servers.length > 1)\n\t\twebchat.servers.pop(1);\n</script>";
    }
    //JSONP, should either load our user info or redirect us.
    if (array_key_exists("username", $_COOKIE) && array_key_exists("key", $_COOKIE)) {
        //If we're here, then we're on marbleblast.com/webchat/ and we _do_ have their info. Spit it out for them.
        echo "<script type=\"text/javascript\">" . getLoginJSONP("JS") . "</script>";
    } else {
        //If we're here, we're on webchat.marbleblast.com and we don't have their username. Send a JSONP request to
        // the main marbleblast.com domain (with cookies, which cannot be sent with XHR) which will return a script
        // for filling in their information (see above, user.php).
        echo "<script type=\"text/javascript\" src=\"//marbleblast.com/webchat/?getkey=JS\"></script>";
    }
    //The black skin has inverted colors by default
    if ($skin === "black") {
        echo "<script type=\"text/javascript\">webchat.setInvertColors(true);</script>";
    } else {
        echo "<script type=\"text/javascript\">webchat.setInvertColors(false);</script>";
    }
    //Dynamically generated skin list
    echo "<script type=\"text/javascript\">webchat.skins = " . json_encode($skins) . "; webchat.skin = \"{$skin}\";</script>";
}
Example #2
0
define("WEBCHAT", 1);
require "user.php";
require "scripts.php";
//JSONP - Load the user's information from marbleblast.com even though we're on the webchat.marbleblast.com domain.
// Users will request /webchat/?getkey=1 as a javascript file, and evaluate the contents. We give them a short
// line of javascript (see user.php) that fills in their user information.
if (array_key_exists("getkey", $_GET)) {
    header("Content-Type: text/javascript");
    header("Access-Control-Allow-Origin: http://webchat.marbleblast.com");
    die(getLoginJSONP($_GET["getkey"]));
}
if (array_key_exists("getkey", $_POST)) {
    header("Content-Type: text/javascript");
    header("Access-Control-Allow-Origin: http://webchat.marbleblast.com");
    die(getLoginJSONP($_POST["getkey"]));
}
?>
<html>
<head>
	<title>MarbleBlast.com Webchat</title>
	<link rel="shortcut icon" href="/favicon.ico">

	<!-- UTF-8 so we can use strange chars -->
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">

	<!-- JQuery ... Inb4 Javascript snobs -->
	<script src="//code.jquery.com/jquery-2.2.0.min.js"></script>

	<!-- Super cool icons by Font Awesome -->
	<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">