$Image = Posts::checkImage(Posts::validateImageURL()); if (empty($type)) { Response::done(array('preview' => $Image->preview, 'title' => $Image->title)); } $insert = array('preview' => $Image->preview, 'fullsize' => $Image->fullsize); $season = Episodes::validateSeason(Episodes::ALLOW_MOVIES); $episode = Episodes::validateEpisode(); $epdata = Episodes::getActual($season, $episode, Episodes::ALLOW_MOVIES); if (empty($epdata)) { Response::fail("The specified episode (S{$season}E{$episode}) does not exist"); } $insert['season'] = $epdata->season; $insert['episode'] = $epdata->episode; $ByID = $currentUser->id; if (Permission::sufficient('developer')) { $username = Posts::validatePostAs(); if (isset($username)) { $PostAs = Users::get($username, 'name', 'id,role'); if (empty($PostAs)) { Response::fail('The user you wanted to post as does not exist'); } if ($type === 'reservation' && !Permission::sufficient('member', $PostAs->role) && !isset($_POST['allow_nonmember'])) { Response::fail('The user you wanted to post as is not a club member, do you want to post as them anyway?', array('canforce' => true)); } $ByID = $PostAs->id; } } $insert[$type === 'reservation' ? 'reserved_by' : 'requested_by'] = $ByID; Posts::checkPostDetails($type, $insert); $PostID = $Database->insert("{$type}s", $insert, 'id'); if (!$PostID) {