public function isValid($revalidate = false) { if (!$this->validated || $revalidate) { $this->validated = true; $this->validationErrors()->reset(); if (!isset($this->params['title']) || !present($this->params['title'])) { $this->validationErrors()->add('title', 'required'); } if (count($this->params['options']) < count(array_unique($this->params['options']))) { $this->validationErrors()->add('options', '.duplicate_options'); } if (count($this->params['options']) < 2) { $this->validationErrors()->add('options', '.minimum_two_options'); } if (count($this->params['options']) > 10) { $this->validationErrors()->add('options', '.too_many_options'); } if ($this->params['max_options'] < 1) { $this->validationErrors()->add('max_options', '.minimum_one_selection'); } if ($this->params['max_options'] > count($this->params['options'])) { $this->validationErrors()->add('max_options', '.invalid_max_options'); } } return $this->validationErrors()->isAny(); }
public function getModeAttribute($value) { if (!present($value)) { return; } return Beatmap::modeStr((int) $value); }
/** * Returns a hash with contents of at least 'hash' and 'ext' if there's * image or otherwise null. * * Assumes attributes 'hash' and 'ext' of the object by default. */ public function getFileProperties() { if (present($this->hash) === false || present($this->ext) === false) { return; } return ['hash' => $this->hash, 'ext' => $this->ext]; }
public function includeAvailability(Beatmapset $beatmapset) { if (!$beatmapset->download_disabled && !present($beatmapset->download_disabled_url)) { return; } return $this->item($beatmapset, function ($beatmapset) { return ['download_disabled' => $beatmapset->download_disabled, 'more_information' => $beatmapset->download_disabled_url]; }); }
public function setAvatar($file) { if ($file === null) { $this->avatarStorage()->delete($this->user_id); } else { $filePath = $file->getRealPath(); (new ImageProcessor($filePath, [256, 256], 100000))->process(); $this->avatarStorage()->put($this->user_id, file_get_contents($filePath), 'public'); $entry = $this->user_id . '_' . time(); } if (present(config('osu.avatar.cache_purge_prefix'))) { file_get_contents(config('osu.avatar.cache_purge_prefix') . $this->user_id . '?' . time()); } return $this->update(['user_avatar' => $entry ?? null]); }
public function notifyReply($event) { $topic = $event->topic->fresh(); $userIds = model_pluck(TopicWatch::where(['topic_id' => $topic->topic_id, 'notify_status' => false]), 'user_id'); foreach (User::whereIn('user_id', $userIds)->get() as $user) { if (!present($user->user_email)) { continue; } if ($user->user_id === $topic->last_poster_id) { continue; } if (!priv_check_user($user, 'ForumTopicWatchAdd', $topic)->can()) { continue; } Mail::queue(['text' => i18n_view('emails.forum.new_reply')], compact('topic', 'user'), function ($message) use($topic, $user) { $message->to($user->user_email); $message->subject(trans('forum.email.new_reply', ['title' => $topic->topic_title])); }); TopicWatch::where(['topic_id' => $topic->topic_id, 'user_id' => $user->user_id])->update(['notify_status' => true]); } }
public function hasValidMessage() { return present($this->message); }
public function isSpecial() { return $this->user_id !== null && present($this->user_colour); }
public function verify() { if ($this->isDone()) { return $this->verified(); } $expireDate = $this->request->session()->get('verification_expire_date'); $tries = $this->request->session()->get('verification_tries'); $key = $this->request->session()->get('verification_key'); if (!present($expireDate) || !present($tries) || !present($key)) { $this->issue(); return error_popup(trans('user_verification.errors.expired')); } if ($expireDate->isPast()) { $this->issue(); return error_popup(trans('user_verification.errors.expired')); } if ($tries > config('osu.user.verification_key_tries_limit')) { $this->issue(); return error_popup(trans('user_verification.errors.retries_exceeded')); } if (str_replace(' ', '', $this->request->input('verification_key')) !== $key) { $this->request->session()->put('verification_tries', $tries + 1); return error_popup(trans('user_verification.errors.incorrect_key')); } return $this->verified(); }
public function getBeatmaps() { $since = Request::input('since'); // - return all beatmaps ranked since this date. Must be a MySQL date. $set_id = Request::input('s'); // - specify a beatmapset_id to return metadata from. $beatmap_id = Request::input('b'); // - specify a beatmap_id to return metadata from. $user_id = Request::input('u'); // - specify a user_id or a username to return metadata from. $type = Request::input('type'); // - specify if `u` is a user_id or a username. Use `string` for usernames or `id` for user_ids. Optional, default behaviour is automatic recognition (may be problematic for usernames made up of digits only). $mode = get_int(Request::input('m')); // - mode (0 = osu!, 1 = Taiko, 2 = osu!catch, 3 = osu!mania). Optional, maps of all modes are returned by default. $include_converted = intval(Request::input('a', 0)); // - specify whether converted beatmaps are included (0 = not included, 1 = included). Only has an effect if `m` is chosen and not 0. Converted maps show their converted difficulty rating. Optional, default is 0. $hash = Request::input('h'); // - the beatmap hash. It can be used, for instance, if you're trying to get what beatmap has a replay played in, as .osr replays only provide beatmap hashes (example of hash: a5b99395a42bd55bc5eb1d2411cbdf8b). Optional, by default all beatmaps are returned independently from the hash. $limit = intval(Request::input('limit', 500)); // - amount of results. Optional, default and maximum are 500. $beatmaps = new Beatmap(); $beatmaps = $beatmaps->join('osu_beatmapsets', 'osu_beatmaps.beatmapset_id', '=', 'osu_beatmapsets.beatmapset_id')->where('osu_beatmapsets.approved', '>=', -2)->where('osu_beatmapsets.active', 1)->orderBy('osu_beatmapsets.approved_date', 'desc')->limit($limit); if (present($beatmap_id)) { $beatmaps = $beatmaps->where('beatmap_id', $beatmap_id); } if (present($set_id)) { $beatmaps = $beatmaps->where('osu_beatmapsets.beatmapset_id', $set_id); } if (present($user_id)) { $user = User::lookup($user_id, $type); if (!$user) { return Response::json([]); } $beatmaps = $beatmaps->where('osu_beatmaps.user_id', $user->user_id); } if ($mode !== null && in_array($mode, array_values(Beatmap::MODES), true) === false) { return Response::json([]); } $playmodes = []; if (present($mode)) { $playmodes[] = $mode; } if (present($include_converted) && $include_converted === 1) { $playmodes[] = 0; } if (!empty($playmodes)) { $beatmaps = $beatmaps->whereIn('playmode', $playmodes); } if (present($hash)) { $beatmaps = $beatmaps->where('checksum', $hash); } if (present($since)) { $beatmaps = $beatmaps->where('approved_date', '>', $since); } return json_collection($beatmaps->with('set', 'difficulty', 'difficultyAttribs')->get(), new BeatmapTransformer()); }
<?php $values = $_POST; function present($index) { global $values; // isset() not array_key_exists() because isset() is a lot faster, and I NULL values shouldn't pass anyway. return isset($values[$index]) && !empty($values[$index]); } if (present('name') && present('email') && present('message')) { if (!mail('*****@*****.**', 'Message from opentip.org', $values['message'], 'From: ' . $values['name'] . ' <' . $values['email'] . '>')) { die('Something went wrong.'); } } else { die('Please fill in all values.'); }
public function getUserAvatarAttribute($value) { if (!present($value)) { return 'https://s.ppy.sh/images/blank.jpg'; } else { $value = str_replace('_', '?', $value); return "https://a.ppy.sh/{$value}"; } }
public static function lookup($username_or_id, $lookup_type = null, $find_all = false) { if (!present($username_or_id)) { return; } switch ($lookup_type) { case 'string': $user = self::where('username', $username_or_id)->orWhere('username_clean', $username_or_id); break; case 'id': $user = self::where('user_id', $username_or_id); break; default: if (is_numeric($username_or_id)) { $user = self::where('user_id', $username_or_id); } else { $user = self::where('username', $username_or_id)->orWhere('username_clean', $username_or_id); } break; } if (!$find_all) { $user = $user->where('user_type', 0)->where('user_warnings', 0); } return $user->first(); }
function delete_unnecessary_clusters($clusters) { global $CONFIG; set_time_limit(0); //this avoids timeouts include_once $CONFIG->path . "mod/profile_manager/views/default/profile_manager/members/classes.php"; //1 ------------------------------ sort array documents foreach ($clusters as $cluster) { usort($cluster->array_docs, "compare_guid"); } //echo "\n------------------------cl (sorted)--------------------------\n"; //print_r($clusters); //2 --------------------------------- delete clusters whose array_docs is a subset of another cluster $clusters_2 = array(); foreach ($clusters as $cluster) { if (count($cluster->array_docs) > 1) { $i = 0; foreach ($clusters as $cluster2) { if ($cluster != $cluster2) { $a = $cluster->return_docs(); sort($a); $b = $cluster2->return_docs(); sort($b); $intersection = array_intersect($a, $b); sort($intersection); if ($intersection == $a && $intersection != $b) { break; } } $i++; if ($i == count($clusters)) { $clusters_2[] = $cluster; } } } } unset($clusters); //echo "\n------------------------clusters_2--------------------------\n"; //print_r($clusters_2); //3 --------------------------------- delete clusters whose array_docs is the same of another cluster $clusters_3 = array(); foreach ($clusters_2 as $cluster) { if (!present($cluster, $clusters_3)) { $clusters_3[] = $cluster; } } unset($clusters_2); //echo "\n------------------------clusters_3--------------------------\n"; //print_r($clusters_3); return $clusters_3; }
function get_int($string) { if (present($string) === true) { return (int) $string; } }
function delete_unnecessary_clusters($clusters) { //1 ------------------------------ sort array documents foreach ($clusters as $cluster) { usort($cluster->array_docs, "compare_guid"); } //echo "\n------------------------cl (sorted)--------------------------\n"; //print_r($clusters); //2 --------------------------------- delete clusters whose array_docs is a subset of another cluster $clusters_2 = array(); foreach ($clusters as $cluster) { if (count($cluster->array_docs) > 1) { $i = 0; foreach ($clusters as $cluster2) { if ($cluster != $cluster2) { $a = $cluster->return_docs(); sort($a); $b = $cluster2->return_docs(); sort($b); $intersection = array_intersect($a, $b); sort($intersection); if ($intersection == $a && $intersection != $b) { break; } } $i++; if ($i == count($clusters)) { $clusters_2[] = $cluster; } } } } unset($clusters); //echo "\n------------------------clusters_2--------------------------\n"; //print_r($clusters_2); //3 --------------------------------- delete clusters whose array_docs is the same of another cluster $clusters_3 = array(); foreach ($clusters_2 as $cluster) { if (!present($cluster, $clusters_3)) { $clusters_3[] = $cluster; } } unset($clusters_2); //echo "\n------------------------clusters_3--------------------------\n"; //print_r($clusters_3); return $clusters_3; }