Example #1
0
 public function getLogDataAttribute($value)
 {
     if (presence($value) === null) {
         return [];
     }
     return unserialize($value);
 }
Example #2
0
 public function deleteFile()
 {
     if (presence($this->hash) === null) {
         return;
     }
     return $this->storage()->deleteDirectory($this->fileDir());
 }
 public function transform(BeatmapDiscussionPost $post)
 {
     if (!priv_check('BeatmapDiscussionPostShow', $post)->can()) {
         return [];
     }
     return ['id' => $post->id, 'beatmap_discussion_id' => $post->beatmap_discussion_id, 'user_id' => $post->user_id, 'last_editor_id' => presence($post->last_editor_id, $post->user_id), 'deleted_by_id' => $post->deleted_by_id, 'system' => $post->system, 'message' => $post->message, 'created_at' => json_time($post->created_at), 'updated_at' => json_time($post->updated_at), 'deleted_at' => json_time($post->deleted_at)];
 }
Example #4
0
 public function rawMessage()
 {
     if ($this->can()) {
         return;
     }
     return presence($this->rawMessage, 'unauthorized');
 }
Example #5
0
 public function store(HttpRequest $request, $forum_id)
 {
     $this->validate($request, ['title' => 'required', 'body' => 'required']);
     $forum = Forum::findOrFail($forum_id);
     $this->authorizePost($forum, null);
     $topic = Topic::createNew(['forum' => $forum, 'title' => $request->input('title'), 'poster' => Auth::user(), 'body' => $request->input('body'), 'notifyReplies' => false, 'cover' => TopicCover::findForUse(presence($request->input('cover_id')), Auth::user())]);
     Event::fire(new TopicWasCreated($topic, $topic->posts->last(), Auth::user()));
     return ujs_redirect(route('forum.topics.show', $topic));
 }
Example #6
0
 /**
  * Add turbolinks-redirect header if previous request
  * was a redirect.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $isTurbolinks = presence($request->header('Turbolinks-Referrer'));
     $response = $next($request);
     // symphony responder (debug error page) doesn't have header method
     $isNormalResponse = method_exists($response, 'header');
     if ($isTurbolinks && $isNormalResponse) {
         return $response->header('Turbolinks-Location', $request->fullUrl());
     }
     return $response;
 }
Example #7
0
 public function includeArtMeta(ContestEntry $entry)
 {
     if ($entry->contest->type !== 'art' || !presence($entry->entry_url)) {
         return $this->item($entry, function ($entry) {
             return [];
         });
     }
     return $this->item($entry, function ($entry) {
         $size = fast_imagesize($entry->entry_url);
         return ['width' => $size[0], 'height' => $size[1]];
     });
 }
Example #8
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     $locale = presence($request->input('locale')) ?? presence($request->cookie('locale')) ?? locale_accept_from_http($request->server('HTTP_ACCEPT_LANGUAGE'));
     $locale = get_valid_locale($locale);
     App::setLocale($locale);
     $response = $next($request);
     if (method_exists($response, 'withCookie')) {
         return $response->withCookie(cookie()->forever('locale', $locale));
     } else {
         return $response;
     }
 }
 public function featured()
 {
     $featuredStreamId = presence((string) Cache::get(static::FEATURED_CACHE_KEY));
     if ($featuredStreamId !== null) {
         foreach ($this->all() as $stream) {
             if ((string) $stream->_id !== $featuredStreamId) {
                 continue;
             }
             $featuredStream = $stream;
             break;
         }
     }
     return $featuredStream ?? null;
 }
 public function verify($username, $password)
 {
     $hash = Request::input('hash');
     $credentials = ['username' => $username, 'password' => $password];
     if (presence($hash) && $hash === 'md5') {
         // prehashed, we want to skip the md5 step of OsuHasher
         $user = User::where('username', $username)->first();
         if (password_verify($password, $user->getAuthPassword())) {
             return $user->user_id;
         }
     } else {
         if (Auth::once($credentials)) {
             return Auth::user()->user_id;
         }
     }
     return false;
 }
 public function store()
 {
     if (Request::hasFile('cover_file') !== true) {
         abort(422);
     }
     $topic = null;
     if (presence(Request::input('topic_id')) !== null) {
         $topic = Topic::findOrFail(Request::input('topic_id'));
         priv_check('ForumTopicEdit', $topic)->ensureCan();
         if ($topic->cover !== null) {
             abort(422);
         }
     }
     try {
         $cover = TopicCover::upload(Request::file('cover_file')->getRealPath(), Auth::user(), $topic);
     } catch (ImageProcessorException $e) {
         return error_popup($e->getMessage());
     }
     return json_item($cover, new TopicCoverTransformer());
 }
Example #12
0
 public function search()
 {
     $current_user = Auth::user();
     $params = [];
     if (is_null($current_user)) {
         $params = ['page' => Request::input('page')];
     } else {
         $params = ['query' => Request::input('q'), 'mode' => Request::input('m'), 'status' => Request::input('s'), 'genre' => Request::input('g'), 'language' => Request::input('l'), 'extra' => array_filter(explode('-', Request::input('e')), 'strlen'), 'rank' => array_filter(explode('-', Request::input('r')), 'strlen'), 'page' => Request::input('page'), 'sort' => explode('_', Request::input('sort'))];
         if (!$current_user->isSupporter()) {
             unset($params['rank']);
         }
     }
     $params = array_filter($params, function ($v, $k) {
         if (is_array($v)) {
             return !empty($v);
         } else {
             return presence($v) !== null;
         }
     }, ARRAY_FILTER_USE_BOTH);
     $beatmaps = BeatmapSet::search($params);
     return fractal_collection_array($beatmaps, new BeatmapSetTransformer(), 'difficulties');
 }
Example #13
0
 public function store()
 {
     if (Request::hasFile('cover_file') !== true) {
         abort(422);
     }
     $topic = null;
     if (presence(Request::input('topic_id')) !== null) {
         $topic = Topic::findOrFail(Request::input('topic_id'));
         $this->authorizePost($topic->forum, $topic);
         if ($topic->canBeEditedBy(Auth::user()) !== true) {
             abort(403);
         }
         if ($topic->cover !== null) {
             abort(422);
         }
     }
     try {
         $cover = TopicCover::upload(Request::file('cover_file')->getRealPath(), Auth::user(), $topic);
     } catch (ImageProcessorException $e) {
         return error_popup($e->getMessage());
     }
     return fractal_item_array($cover, new TopicCoverTransformer());
 }
Example #14
0
 public function search()
 {
     $current_user = Auth::user();
     if (is_null($current_user)) {
         $data = new Collection([]);
     } else {
         $params = ['query' => Request::input('q'), 'mode' => Request::input('m'), 'status' => Request::input('s'), 'genre' => Request::input('g'), 'language' => Request::input('l'), 'extra' => array_filter(explode('-', Request::input('e')), 'strlen'), 'rank' => array_filter(explode('-', Request::input('r')), 'strlen'), 'page' => Request::input('page'), 'sort' => explode('_', Request::input('sort'))];
         if (!$current_user->isSupporter()) {
             unset($params['rank']);
         }
         $params = array_filter($params, function ($v, $k) {
             if (is_array($v)) {
                 return !empty($v);
             } else {
                 return presence($v) !== null;
             }
         }, ARRAY_FILTER_USE_BOTH);
         $data = new Collection(BeatmapSet::search($params), new BeatmapSetTransformer());
     }
     $fractal = new Manager();
     $beatmaps = $fractal->createData($data)->toArray();
     return $beatmaps;
 }
Example #15
0
 public function arrayBeatmapSet($matches)
 {
     $beatmapSetTitle = presence($matches['beatmapSetTitle'], '(no title)');
     return ['title' => html_entity_decode($beatmapSetTitle), 'url' => html_entity_decode($matches['beatmapSetUrl'])];
 }
Example #16
0
function get_param_value($input, $type)
{
    switch ($type) {
        case 'bool':
            return get_bool($input);
            break;
        case 'int':
            return get_int($input);
            break;
        case 'file':
            return get_file($input);
            break;
        case 'string_split':
            return get_arr(explode("\r\n", $input), 'presence');
            break;
        case 'string[]':
            return get_arr($input, 'presence');
            break;
        case 'int[]':
            return get_arr($input, 'get_int');
            break;
        default:
            return presence((string) $input);
    }
}
Example #17
0
 public function store(HttpRequest $request)
 {
     $forum = Forum::findOrFail($request->get('forum_id'));
     priv_check('ForumTopicStore', $forum)->ensureCan();
     $this->validate($request, ['title' => 'required', 'body' => 'required']);
     if (get_bool($request->get('with_poll'))) {
         $pollParams = get_params($request, 'forum_topic_poll', ['length_days:int', 'max_options:int', 'options:string_split', 'title', 'vote_change:bool']);
         $poll = (new TopicPoll())->fill($pollParams);
         if (!$poll->isValid()) {
             return error_popup(implode(' ', $poll->validationErrors()->allMessages()));
         }
     }
     $params = ['title' => $request->get('title'), 'user' => Auth::user(), 'body' => $request->get('body'), 'cover' => TopicCover::findForUse(presence($request->input('cover_id')), Auth::user())];
     $topic = Topic::createNew($forum, $params, $poll ?? null);
     if ($topic->topic_id !== null) {
         Event::fire(new TopicWasCreated($topic, $topic->posts->last(), Auth::user()));
         return ujs_redirect(route('forum.topics.show', $topic));
     } else {
         abort(422);
     }
 }
Example #18
0
 /**
  * Returns array which keys are id of this forum's parents and values are
  * their names and types. Sorted from topmost parent to immediate parent.
  *
  * This method isn't intended to be directly called but through Laravel's
  * attribute accessor method (in this case, `$forum->forum_parents`)
  *
  * warning: don't access this attribute (forum_parents) without selecting
  * parent_id otherwise returned value may be wrong.
  *
  * @param string $value
  * @return array
  */
 public function getForumParentsAttribute($value)
 {
     if ($this->parent_id === 0) {
         return [];
     }
     if (presence($value) === null && $this->parentForum !== null) {
         $parentsArray = $this->parentForum->forum_parents;
         $parentsArray[$this->parentForum->forum_id] = [$this->parentForum->forum_name, $this->parentForum->forum_type];
         $this->update(['forum_parents' => $parentsArray]);
         return $parentsArray;
     } else {
         return unserialize($value);
     }
 }
Example #19
0
function get_int($string)
{
    $val = presence($string);
    if ($val !== null) {
        $val = intval($val);
    }
    return $val;
}
 public function transform(BeatmapDiscussionPost $post)
 {
     return ['id' => $post->id, 'beatmap_discussion_id' => $post->beatmap_discussion_id, 'user_id' => $post->user_id, 'last_editor_id' => presence($post->last_editor_id, $post->user_id), 'system' => $post->system, 'message' => $post->message, 'created_at' => json_time($post->created_at), 'updated_at' => json_time($post->updated_at)];
 }
Example #21
0
 public function parseMatchesBeatmapSetUpload($matches)
 {
     $beatmapSetTitle = presence($matches['beatmapSetTitle'], '(no title)');
     return ['beatmapSet' => ['title' => $beatmapSetTitle, 'url' => $matches['beatmapSetUrl']], 'user' => ['username' => $matches['userName'], 'url' => $matches['userUrl']]];
 }
Example #22
0
<?php

// osu config~
return ['bbcode' => ['uid' => '1337'], 'beatmaps' => ['max' => 50, 'max-scores' => 50], 'beatmap_processor' => ['mirrors_to_use' => array_map('intval', explode(' ', env('BM_PROCESSOR_MIRRORS', '1'))), 'thumbnailer' => env('BM_PROCESSOR_THUMBNAILER', 'http://*****:*****@ppy.sh'], 'forum' => ['admin_forum_id' => intval(env('ADMIN_FORUM_ID', 28)), 'help_forum_ids' => array_map('intval', explode(' ', env('HELP_FORUM_IDS', '4 5 29 30 101'))), 'double_post_time' => ['normal' => 72, 'author' => 24], 'feature_forum_id' => get_int(env('FEATURE_FORUM_ID')), 'slack_watch' => ['forum_ids' => array_map('intval', explode(' ', env('SLACK_WATCH_FORUM_IDS', '5 29 101 4 30 2'))), 'topic_ids' => array_map('intval', explode(' ', env('SLACK_WATCH_TOPIC_IDS', '259747')))]], 'mp-history' => ['event-count' => 500], 'legacy' => ['shared_cookie_secret' => env('SHARED_COOKIE_SECRET', '')], 'store' => ['delayed_shipping_order_threshold' => env('DELAYED_SHIPPING_ORDER_THRESHOLD', 100), 'delayed_shipping_order_message' => env('DELAYED_SHIPPING_ORDER_MESSAGE'), 'notice' => presence(str_replace('\\n', "\n", env('STORE_NOTICE')))], 'twitch_client_id' => env('TWITCH_CLIENT_ID'), 'urls' => ['base' => 'https://osu.ppy.sh', 'smilies' => '/forum/images/smilies', 'support-the-game' => '/p/support#transactionarea', 'legal' => ['dmca' => '/p/copyright', 'tos' => '/p/terms'], 'social' => ['facebook' => 'https://facebook.com/osugame', 'twitter' => '/p/twitter'], 'status' => ['osustatus' => 'https://twitter.com/osustatus', 'server' => 'http://stat.ppy.sh/'], 'user' => ['kudosu' => '/wiki/Kudosu', 'recover' => '/p/forgot-email', 'rules' => '/wiki/Osu!:Rules', 'signup' => '/p/register'], 'ranking' => ['overall' => '/p/pp', 'charts' => '/p/chart', 'country' => '/p/countryranking', 'mapper' => '/p/kudosu'], 'home' => ['changelog' => '/p/changelog', 'download' => '/p/download'], 'help' => ['wiki' => '/wiki/Main_Page', 'faq' => '/wiki/FAQ', 'support' => 'http://help.ppy.sh/']], 'user' => ['user_page_forum_id' => intval(env('USER_PAGE_FORUM_ID', 70)), 'verification_key_length_hex' => 8, 'verification_key_tries_limit' => 8]];
Example #23
0
 public static function searchES(array $params = [])
 {
     extract($params);
     $count = config('osu.beatmaps.max', 50);
     $offset = max(0, $page - 1) * $count;
     $searchParams['index'] = env('ES_INDEX', 'osu');
     $searchParams['type'] = 'beatmaps';
     $searchParams['size'] = $count;
     $searchParams['from'] = $offset;
     $searchParams['body']['sort'] = [$sort_field => ['order' => $sort_order]];
     $searchParams['fields'] = ['id'];
     $matchParams = [];
     if (presence($genre) !== null) {
         $matchParams[] = ['match' => ['genre_id' => (int) $genre]];
     }
     if (presence($language) !== null) {
         $matchParams[] = ['match' => ['language_id' => (int) $language]];
     }
     if (is_array($extra) && !empty($extra)) {
         foreach ($extra as $val) {
             switch ($val) {
                 case 0:
                     // video
                     $matchParams[] = ['match' => ['video' => 1]];
                     break;
                 case 1:
                     // storyboard
                     $matchParams[] = ['match' => ['storyboard' => 1]];
                     break;
             }
         }
     }
     if (presence($query) !== null) {
         $matchParams[] = ['query_string' => ['query' => $query]];
     }
     if (!empty($rank)) {
         $klass = presence($mode) !== null ? Score\Best\Model::getClass(intval($mode)) : Score\Best\Combined::class;
         $scores = $klass::forUser(Auth::user())->whereIn('rank', $rank)->get()->lists('beatmapset_id');
         $matchParams[] = ['ids' => ['type' => 'beatmaps', 'values' => $scores]];
     }
     if (presence($mode) !== null && presence($rank) === null) {
         $matchParams[] = ['match' => ['playmode' => (int) $mode]];
     }
     if (!empty($matchParams)) {
         $searchParams['body']['query']['bool']['must'] = $matchParams;
     }
     try {
         $results = Es::search($searchParams);
         $beatmap_ids = array_map(function ($e) {
             return $e['_id'];
         }, $results['hits']['hits']);
     } catch (\Exception $e) {
         $beatmap_ids = [];
     }
     return $beatmap_ids;
 }
Example #24
0
 public function getCountryAcronymAttribute($value)
 {
     return presence($value);
 }
Example #25
0
 public function getUserMsnmAttribute($value)
 {
     return presence($value);
 }
Example #26
0
 public static function searchES(array $params = [])
 {
     extract($params);
     $count = config('osu.beatmaps.max', 50);
     $offset = max(0, $page - 1) * $count;
     $current_user = Auth::user();
     $searchParams['index'] = config('osu.elasticsearch.index');
     $searchParams['type'] = 'beatmaps';
     $searchParams['size'] = $count;
     $searchParams['from'] = $offset;
     $searchParams['body']['sort'] = [$sort_field => ['order' => $sort_order]];
     $searchParams['fields'] = ['id'];
     $matchParams = [];
     $shouldParams = [];
     if (presence($genre) !== null) {
         $matchParams[] = ['match' => ['genre_id' => (int) $genre]];
     }
     if (presence($language) !== null) {
         $matchParams[] = ['match' => ['language_id' => (int) $language]];
     }
     if (is_array($extra) && !empty($extra)) {
         foreach ($extra as $val) {
             switch ($val) {
                 case 0:
                     // video
                     $matchParams[] = ['match' => ['video' => 1]];
                     break;
                 case 1:
                     // storyboard
                     $matchParams[] = ['match' => ['storyboard' => 1]];
                     break;
             }
         }
     }
     if (presence($query) !== null) {
         $matchParams[] = ['query_string' => ['query' => $query]];
     }
     if (!empty($rank)) {
         $klass = presence($mode) !== null ? Score\Best\Model::getClass(intval($mode)) : Score\Best\Combined::class;
         $scores = model_pluck($klass::forUser($current_user)->whereIn('rank', $rank), 'beatmapset_id');
         $matchParams[] = ['ids' => ['type' => 'beatmaps', 'values' => $scores]];
     }
     // TODO: This logic probably shouldn't be at the model level... maybe?
     if (presence($status) !== null) {
         switch ((int) $status) {
             case 0:
                 // Ranked & Approved
                 $shouldParams[] = [['match' => ['approved' => self::STATES['ranked']]], ['match' => ['approved' => self::STATES['approved']]]];
                 break;
             case 1:
                 // Approved
                 $matchParams[] = ['match' => ['approved' => self::STATES['approved']]];
                 break;
             case 2:
                 // Favourites
                 $favs = model_pluck($current_user->favouriteBeatmapsets(), 'beatmapset_id');
                 $matchParams[] = ['ids' => ['type' => 'beatmaps', 'values' => $favs]];
                 break;
             case 3:
                 // Mod Requests
                 $maps = model_pluck(ModQueue::select(), 'beatmapset_id');
                 $matchParams[] = ['ids' => ['type' => 'beatmaps', 'values' => $maps]];
                 $matchParams[] = ['match' => ['approved' => self::STATES['pending']]];
                 break;
             case 4:
                 // Pending
                 $shouldParams[] = [['match' => ['approved' => self::STATES['wip']]], ['match' => ['approved' => self::STATES['pending']]]];
                 break;
             case 5:
                 // Graveyard
                 $matchParams[] = ['match' => ['approved' => self::STATES['graveyard']]];
                 break;
             case 6:
                 // My Maps
                 $maps = model_pluck($current_user->beatmapsets(), 'beatmapset_id');
                 $matchParams[] = ['ids' => ['type' => 'beatmaps', 'values' => $maps]];
                 break;
             case 7:
                 // Explicit Any
                 break;
             default:
                 // null, etc
                 break;
         }
     } else {
         $matchParams[] = ['range' => ['approved' => ['gte' => self::STATES['pending']]]];
     }
     if (presence($mode) !== null) {
         $matchParams[] = ['match' => ['playmode' => (int) $mode]];
     }
     if (!empty($matchParams)) {
         $searchParams['body']['query']['bool']['must'] = $matchParams;
     }
     if (!empty($shouldParams)) {
         $searchParams['body']['query']['bool']['should'] = $shouldParams;
         $searchParams['body']['query']['bool']['minimum_should_match'] = 1;
     }
     try {
         $results = Es::search($searchParams);
         $beatmap_ids = array_map(function ($e) {
             return $e['_id'];
         }, $results['hits']['hits']);
     } catch (\Exception $e) {
         $beatmap_ids = [];
     }
     return $beatmap_ids;
 }
Example #27
0
File: Rank.php Project: ppy/osu-web
 public function getRankTitleAttribute($value)
 {
     return presence($value);
 }
Example #28
0
function user_colour_style($colour, $style)
{
    if (presence($colour) === null) {
        return "";
    }
    $colour = e($colour);
    return "{$style}: #{$colour};";
}
Example #29
0
function dispatchPresence($op)
{
    switch ($op) {
        case 'presence':
        default:
            presence();
            break;
    }
}