Example #1
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));
        }
    }
}
function EditEntry($jamNumber, $author, $title, $gameURL, $screenshotURL)
{
    global $jams;
    //Authorize user (is admin)
    if (IsAdmin() === false) {
        die("Only admins can edit entries.");
    }
    $author = trim($author);
    $title = trim($title);
    $gameURL = trim($gameURL);
    $screenshotURL = trim($screenshotURL);
    //Validate values
    $jamNumber = intval($jamNumber);
    if ($jamNumber <= 0) {
        die("invalid jam number");
        return;
    }
    //Validate title
    if (strlen($title) <= 0) {
        die("invalid title");
        return;
    }
    //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.");
        }
    }
    if (count($jams) == 0) {
        return;
        //No jams exist
    }
    foreach ($jams as $i => $jam) {
        if (intval($jam["jam_number"]) == $jamNumber) {
            foreach ($jam["entries"] as $j => $entry) {
                if ($entry["author"] == $author) {
                    $jam["entries"][$j]["title"] = $title;
                    $jam["entries"][$j]["url"] = $gameURL;
                    $jam["entries"][$j]["screenshot_url"] = $screenshotURL;
                    file_put_contents("data/jams/jam_{$jamNumber}.json", json_encode($jam));
                    break;
                }
            }
            break;
        }
    }
}