Пример #1
0
     $epdata = (new Input('epid', 'epid', array(Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Episode identifier is missing', Input::ERROR_INVALID => 'Episode identifier (@value) is invalid'))))->out();
     $epdata = Episodes::getActual($epdata['season'], $epdata['episode']);
     if (empty($epdata)) {
         Response::fail('The specified episode does not exist');
     }
     $insert['season'] = $epdata->season;
     $insert['episode'] = $epdata->episode;
     $insert['finished_at'] = date('c');
     $postid = $Database->insert('reservations', $insert, 'id');
     if (!is_int($postid)) {
         Response::dbError();
     }
     if (!empty($insert['lock'])) {
         Logs::action('post_lock', array('type' => 'reservation', 'id' => $postid));
     }
     Response::success('Reservation added');
 } else {
     if (preg_match(new RegExp('^set-(request|reservation)-image/(\\d+)$'), $data, $_match)) {
         $thing = $_match[1];
         $Post = $Database->where('id', $_match[2])->getOne("{$thing}s");
         if (empty($Post)) {
             Response::fail("The specified {$thing} does not exist");
         }
         if ($Post->lock) {
             Response::fail('This post is locked, its image cannot be changed.');
         }
         if (Permission::insufficient('staff')) {
             switch ($thing) {
                 case 'request':
                     if ($Post->requested_by !== $currentUser->id || !empty($Post->reserved_by)) {
                         Response::fail();
Пример #2
0
<?php

use App\Cookie;
use App\CSRFProtection;
use App\DeviantArt;
use App\Exceptions\CURLRequestException;
use App\Permission;
use App\Response;
use App\Users;
use App\Models\User;
/** @var $signedIn bool */
if (!$signedIn) {
    Response::success("You've already signed out");
}
CSRFProtection::protect();
if (isset($_REQUEST['unlink'])) {
    try {
        DeviantArt::request('https://www.deviantart.com/oauth2/revoke', null, array('token' => $currentUser->Session['access']));
    } catch (CURLRequestException $e) {
        Response::fail("Coulnd not revoke the site's access: {$e->getMessage()} (HTTP {$e->getCode()})");
    }
}
if (isset($_REQUEST['unlink']) || isset($_REQUEST['everywhere'])) {
    $col = 'user';
    $val = $currentUser->id;
    $username = Users::validateName('username', null, true);
    if (isset($username)) {
        if (!Permission::sufficient('staff') || isset($_REQUEST['unlink'])) {
            Response::fail();
        }
        /** @var $TargetUser User */
Пример #3
0
 case "brokenvideos":
     /** @var $videos EpisodeVideo[] */
     $videos = $Database->whereEp($Episode)->get('episodes__videos');
     $removed = 0;
     foreach ($videos as $video) {
         if (!$video->isBroken()) {
             continue;
         }
         $removed++;
         $Database->whereEp($Episode)->where('provider', $video->provider)->where('id', $video->id)->delete('episodes__videos');
         Logs::action('video_broken', array('season' => $Episode->season, 'episode' => $Episode->episode, 'provider' => $video->provider, 'id' => $video->id));
     }
     if ($removed === 0) {
         return Response::success('No broken videos found under this ' . ($Episode->isMovie ? 'movie' : 'episode') . '.');
     }
     Response::success("{$removed} video link" . ($removed === 1 ? ' has' : 's have') . " been removed from the site. Thank you for letting us know.", array('epsection' => Episodes::getVideosHTML($Episode, NOWRAP)));
     break;
 case "getcgrelations":
     $CheckTag = array();
     $EpTagIDs = Episodes::getTagIDs($Episode);
     if (empty($EpTagIDs)) {
         Response::fail('The episode has no associated tag(s)!');
     }
     $TaggedAppearanceIDs = array();
     foreach ($EpTagIDs as $tid) {
         $AppearanceIDs = $CGDb->where('tid', $tid)->get('tagged', null, 'ponyid');
         foreach ($AppearanceIDs as $id) {
             $TaggedAppearanceIDs[$id['ponyid']] = true;
         }
     }
     $Appearances = $CGDb->where('ishuman', $Episode->isMovie)->where('"id" != 0')->orderBy('label', 'ASC')->get('appearances', null, 'id,label');
Пример #4
0
     }
     $GroupID = intval($_match[2], 10);
     $Group = $CGDb->where('groupid', $GroupID)->getOne('colorgroups');
     if (empty($GroupID)) {
         Response::fail("There's no {$color} group with the ID of {$GroupID}");
     }
     if ($action === 'get') {
         $Group['Colors'] = ColorGroups::getColors($Group['groupid']);
         Response::done($Group);
     }
     if ($action === 'del') {
         if (!$CGDb->where('groupid', $Group['groupid'])->delete('colorgroups')) {
             Response::dbError();
         }
         Logs::action('cgs', array('action' => 'del', 'groupid' => $Group['groupid'], 'ponyid' => $Group['ponyid'], 'label' => $Group['label'], 'order' => $Group['order'] ?? null));
         Response::success("{$Color} group deleted successfully");
     }
 }
 $data = array();
 $data['label'] = (new Input('label', 'string', array(Input::IN_RANGE => [2, 30], Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Please specify a group name', Input::ERROR_RANGE => 'The group name must be between @min and @max characters in length'))))->out();
 CoreUtils::checkStringValidity($data['label'], "{$Color} group name", INVERSE_PRINTABLE_ASCII_PATTERN, true);
 $major = isset($_POST['major']);
 if ($major) {
     $reason = (new Input('reason', 'string', array(Input::IN_RANGE => [null, 255], Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Please specify a reason for the changes', Input::ERROR_RANGE => 'The reason cannot be longer than @max characters'))))->out();
     CoreUtils::checkStringValidity($reason, "Change reason", INVERSE_PRINTABLE_ASCII_PATTERN);
 }
 if ($adding) {
     $AppearanceID = (new Input('ponyid', 'int', array(Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Missing appearance ID'))))->out();
     $Appearance = $CGDb->where('id', $AppearanceID)->where('ishuman', $EQG)->getOne('appearances');
     if (empty($Appearance)) {
         Response::fail('The specified appearance odes not exist');
Пример #5
0
            if (Permission::sufficient('staff', $targetUser->role)) {
                Response::fail("You cannot {$action} people within the assistant or any higher group");
            }
            if ($action == 'banish' && $targetUser->role === 'ban' || $action == 'un-banish' && $targetUser->role !== 'ban') {
                Response::fail("This user has already been {$action}ed");
            }
            $reason = (new Input('reason', 'string', array(Input::IN_RANGE => [5, 255], Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Please specify a reason', Input::ERROR_RANGE => 'Reason length must be between @min and @max characters'))))->out();
            $changes = array('role' => $action == 'banish' ? 'ban' : 'user');
            $Database->where('id', $targetUser->id)->update('users', $changes);
            Logs::action($action, array('target' => $targetUser->id, 'reason' => $reason));
            $changes['role'] = Permission::ROLES_ASSOC[$changes['role']];
            $changes['badge'] = Permission::labelInitials($changes['role']);
            if ($action == 'banish') {
                Response::done($changes);
            }
            Response::success("We welcome {$targetUser->name} back with open hooves!", $changes);
        } else {
            CoreUtils::notFound();
        }
    }
}
if (strtolower($data) === 'immortalsexgod') {
    $data = 'DJDavid98';
}
if (empty($data)) {
    if ($signedIn) {
        $un = $currentUser->name;
    } else {
        $MSG = 'Sign in to view your settings';
    }
} else {
Пример #6
0
 static function reindex()
 {
     global $CGDb;
     $elasticClient = CoreUtils::elasticClient();
     try {
         $elasticClient->indices()->delete(CGUtils::ELASTIC_BASE);
     } catch (ElasticMissing404Exception $e) {
         $message = JSON::decode($e->getMessage());
         // Eat exception if the index we're re-creating does not exist yet
         if ($message['error']['type'] !== 'index_not_found_exception' || $message['error']['index'] !== CGUtils::ELASTIC_BASE['index']) {
             throw $e;
         }
     } catch (ElasticNoNodesAvailableException $e) {
         Response::fail('Re-index failed, ElasticSearch server is down!');
     }
     $params = array_merge(CGUtils::ELASTIC_BASE, ["body" => ["mappings" => ["entry" => ["_all" => ["enabled" => false], "properties" => ["label" => ["type" => "text", "analyzer" => "overkill"], "order" => ["type" => "integer"], "ishuman" => ["type" => "boolean"], "private" => ["type" => "boolean"], "tags" => ["type" => "text", "analyzer" => "overkill"]]]], "settings" => ["analysis" => ["analyzer" => ["overkill" => ["type" => "custom", "tokenizer" => "overkill", "filter" => ["lowercase"]]], "tokenizer" => ["overkill" => ["type" => "edge_ngram", "min_gram" => 2, "max_gram" => 6, "token_chars" => ["letter", "digit"]]]]]]]);
     $elasticClient->indices()->create(array_merge($params));
     $Appearances = $CGDb->where('id != 0')->get('appearances', null, self::ELASTIC_COLUMNS);
     $params = array('body' => []);
     foreach ($Appearances as $i => $a) {
         $meta = self::getElasticMeta($a);
         $params['body'][] = ['index' => ['_index' => $meta['index'], '_type' => $meta['type'], '_id' => $meta['id']]];
         $params['body'][] = self::getElasticBody($a);
         if ($i % 100 == 0) {
             $elasticClient->bulk($params);
             $params = ['body' => []];
         }
     }
     if (!empty($params['body'])) {
         $elasticClient->bulk($params);
     }
     Response::success('Re-index completed');
 }