private static function _genericPostInfo(Post $Post, array $data, array &$details) { $label = CoreUtils::capitalize($data['type']) . " #{$data['id']}"; if (!empty($Post)) { $label = $Post->toAnchor($label); } $details[] = array('Post', $label); if (empty($Post)) { $details[] = array('Still exists', false); } $EpID = (new Episode($Post))->formatTitle(AS_ARRAY, 'id'); $EpData = Episodes::parseID($EpID); $Episode = Episodes::getActual($EpData['season'], $EpData['episode'], Episodes::ALLOW_MOVIES); $details[] = array('Posted under', !empty($Episode) ? "<a href='" . $Episode->formatURL() . "'>{$EpID}</a>" : $EpID . ' (now deleted/moved)'); if (!empty($Post)) { $details[] = array(($data['type'] === 'request' ? 'Requested' : 'Reserved') . ' by', Users::get($data['type'] === 'request' ? $Post->requested_by : $Post->reserved_by)->getProfileLink()); if ($data['type'] === 'request') { if (!empty($Post->reserved_by)) { $details[] = array('Reserved by', Users::get($Post->reserved_by)->getProfileLink()); } else { $details[] = array('Reserved', false); } } } }
} }, array(Input::IS_OPTIONAL => true, Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_INVALID => 'Post type (@value) is invalid'))))->out(); if (!empty($type) && $type === 'reservation') { if (Permission::insufficient('member')) { Response::fail(); } Users::reservationLimitExceeded(); } $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));
} else { if (!$canEditID) { $isMovie = $Episode->season === 0; $insert['season'] = $isMovie ? 0 : $Episode->season; $insert['episode'] = $Episode->episode; } } $What = $isMovie ? 'Movie' : 'Episode'; $what = strtolower($What); $EpisodeChanged = true; $SeasonChanged = true; if ($editing) { $SeasonChanged = $isMovie ? false : $insert['season'] != $Episode->season; $EpisodeChanged = $insert['episode'] != $Episode->episode; if ($SeasonChanged || $EpisodeChanged) { $Target = Episodes::getActual($insert['season'] ?? $Episode->season, $insert['episode'] ?? $Episode->episode, Episodes::ALLOW_MOVIES); if (!empty($Target)) { Response::fail("There's already an episode with the same season & episode number"); } if ((new Episode($insert))->getPostCount() > 0) { Response::fail('This epsiode\'s ID cannot be changed because it already has posts and this action could break existing links'); } } } else { if ($canEditID) { $MatchingID = $Database->whereEp($insert['season'], $insert['episode'])->getOne('episodes'); if (!empty($MatchingID)) { Response::fail(($isMovie ? 'A movie' : 'An episode') . ' with the same ' . ($isMovie ? 'overall' : 'season and episode') . ' number already exists'); } } }
<?php use App\CoreUtils; use App\Episodes; use App\HTTP; use App\RegExp; if (POST_REQUEST) { HTTP::statusCode(400, AND_DIE); } /** @var $data string */ if (!preg_match(new RegExp('^(req|res)/(\\d+)$'), $data, $match)) { CoreUtils::notFound(); } $match[1] .= array('req' => 'uest', 'res' => 'ervation')[$match[1]]; /** @var $LinkedPost \App\Models\Post */ $LinkedPost = $Database->where('id', $match[2])->getOne("{$match[1]}s"); if (empty($LinkedPost)) { CoreUtils::notFound(); } $Episode = Episodes::getActual($LinkedPost->season, $LinkedPost->episode); if (empty($Episode)) { CoreUtils::notFound(); } $Episode->LinkedPost = $LinkedPost; Episodes::loadPage($Episode, false);
static function getHTML($Notifications, $wrap = true) { global $Database; $HTML = $wrap ? '<ul class="notif-list">' : ''; foreach ($Notifications as $n) { $data = !empty($n['data']) ? JSON::decode($n['data']) : null; if (preg_match(new RegExp('^post-'), $n['type'])) { /** @var $Post Post */ $Post = $Database->where('id', $data['id'])->getOne("{$data['type']}s"); $Episode = Episodes::getActual($Post->season, $Post->episode, Episodes::ALLOW_MOVIES); $EpID = $Episode->formatTitle(AS_ARRAY, 'id'); $url = $Post->toLink($Episode); } switch ($n['type']) { case "post-finished": $HTML .= self::_getNotifElem("Your <a href='{$url}'>request</a> under {$EpID} has been fulfilled", $n); break; case "post-approved": $HTML .= self::_getNotifElem("A <a href='{$url}'>post</a> you reserved under {$EpID} has been added to the club gallery", $n); break; case "post-passon": $userlink = Users::get($data['user'])->getProfileLink(); $HTML .= self::_getNotifElem("{$userlink} is interested in finishing a <a href='{$url}'>post</a> you reserved under {$EpID}. Would you like to pass the reservation to them?", $n); break; case "post-passdeny": case "post-passallow": case "post-passfree": case "post-passdel": case "post-passsnatch": case "post-passperm": $userlink = Users::get($data['by'])->getProfileLink(); $passaction = str_replace('post-pass', '', $n['type']); switch ($passaction) { case "allow": $HTML .= self::_getNotifElem("Reservation transfer status: {$userlink} <strong class='color-lightgreen'>transferred</strong> the reservation of <a href='{$url}'>this post</a> under {$EpID} to you!", $n); break; case "deny": $HTML .= self::_getNotifElem("Reservation transfer status: {$userlink} <strong class='color-lightred'>denied</strong> transferring the reservation of <a href='{$url}'>this post</a> under {$EpID} to you.", $n); break; case 'free': case 'del': case 'snatch': case 'perm': $message = Posts::TRANSFER_ATTEMPT_CLEAR_REASONS[$passaction]; $message = str_replace('post', "<a href='{$url}'>post</a>", $message); switch ($passaction) { case 'del': $message .= " by {$userlink}"; break; case "perm": $message = str_replace('the previous reserver', $userlink, $message); break; } $HTML .= self::_getNotifElem("Reservation transfer status: {$message}", $n); break; } break; default: $HTML .= "<li><code>Notification({$n['type']})#{$n['id']}</code> <span class='nobr'>– Missing handler</span></li>"; } } return $HTML . ($wrap ? '</ul>' : ''); }
/** * Returns the HTML of the "Appears in # episodes" section of appearance pages * * @param array $Appearance * @param bool $allowMovies * * @return string */ static function getRelatedEpisodesHTML($Appearance, $allowMovies = false) { global $CGDb; $EpTagsOnAppearance = $CGDb->rawQuery("SELECT t.tid\n\t\t\tFROM tagged tt\n\t\t\tLEFT JOIN tags t ON tt.tid = t.tid\n\t\t\tWHERE tt.ponyid = ? && t.type = 'ep'", array($Appearance['id'])); if (!empty($EpTagsOnAppearance)) { foreach ($EpTagsOnAppearance as $k => $row) { $EpTagsOnAppearance[$k] = $row['tid']; } $EpAppearances = $CGDb->rawQuery("SELECT DISTINCT name FROM tags WHERE tid IN (" . implode(',', $EpTagsOnAppearance) . ") ORDER BY name"); if (empty($EpAppearances)) { return ''; } $List = ''; foreach ($EpAppearances as $tag) { $name = strtoupper($tag['name']); $EpData = Episodes::parseID($name); $Ep = Episodes::getActual($EpData['season'], $EpData['episode'], $allowMovies); $List .= (empty($Ep) ? self::expandEpisodeTagName($name) : "<a href='{$Ep->formatURL()}'>" . $Ep->formatTitle() . '</a>') . ', '; } $List = rtrim($List, ', '); $N_episodes = CoreUtils::makePlural($Appearance['ishuman'] ? 'movie' : 'episode', count($EpAppearances), PREPEND_NUMBER); $hide = ''; } else { $N_episodes = 'no episodes'; $List = ''; $hide = 'style="display:none"'; } return <<<HTML \t<section id="ep-appearances" {$hide}> \t\t<h2><span class='typcn typcn-video'></span>Appears in {$N_episodes}</h2> \t\t<p>{$List}</p> \t</section> HTML; }