Esempio n. 1
0
    }
}
//Page actions!
switch ($page) {
    case "login":
        if (IsLoggedIn()) {
            $page = "main";
        }
        break;
    case "logout":
        LogOut();
        $page = "main";
        break;
}
//Create lists of jams and jam entries
$filesToParse = GetSortedJamFileList();
$authors = array();
$firstJam = true;
$jamFromStart = 1;
foreach ($filesToParse as $fileLoc) {
    //Read data about the jam
    $data = json_decode(file_get_contents($fileLoc), true);
    $newData = array();
    $newData["jam_number"] = htmlspecialchars($data["jam_number"], ENT_QUOTES);
    $newData["jam_number_ordinal"] = htmlspecialchars(Ordinal($data["jam_number"]), ENT_QUOTES);
    $newData["theme"] = htmlspecialchars($data["theme"], ENT_QUOTES);
    $newData["date"] = htmlspecialchars($data["date"], ENT_QUOTES);
    $newData["time"] = htmlspecialchars($data["time"], ENT_QUOTES);
    $newData["entries"] = array();
    $newData["first_jam"] = $firstJam;
    $newData["entries_visible"] = $jamFromStart <= 2;
Esempio n. 2
0
function SubmitEntry($gameName, $gameURL, $screenshotURL)
{
    $gameName = trim($gameName);
    $gameURL = trim($gameURL);
    $screenshotURL = trim($screenshotURL);
    //Authorize user
    if (IsLoggedIn() === false) {
        die("Not logged in.");
    }
    //Validate game name
    if (strlen($gameName) < 1) {
        die("Game name not provided");
    }
    //Validate Game URL
    if (SanitizeURL($gameURL) === false) {
        die("Invalid game URL");
    }
    //Validate Screenshot URL
    if ($screenshotURL == "") {
        $screenshotURL = "logo.png";
    } else {
        if (SanitizeURL($screenshotURL) === false) {
            die("Invalid screenshot URL. Leave blank for default.");
        }
    }
    $filesToParse = GetSortedJamFileList();
    if (count($filesToParse) < 1) {
        die("No jam to submit your entry to");
    }
    //First on the list is the current jam.
    $currentJamFile = $filesToParse[count($filesToParse) - 1];
    $currentJam = json_decode(file_get_contents($currentJamFile), true);
    if (isset($currentJam["entries"])) {
        $entryUpdated = false;
        foreach ($currentJam["entries"] as $i => $entry) {
            if ($entry["author"] == IsLoggedIn()) {
                //Updating existing entry
                $currentJam["entries"][$i] = array("title" => "{$gameName}", "author" => "" . IsLoggedIn(), "url" => "{$gameURL}", "screenshot_url" => "{$screenshotURL}");
                file_put_contents($currentJamFile, json_encode($currentJam));
                $entryUpdated = true;
            }
        }
        if (!$entryUpdated) {
            //Submitting new entry
            $currentJam["entries"][] = array("title" => "{$gameName}", "author" => "" . IsLoggedIn(), "url" => "{$gameURL}", "screenshot_url" => "{$screenshotURL}");
            file_put_contents($currentJamFile, json_encode($currentJam));
        }
    }
}