forked from ppy/osu-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into artist-video
- Loading branch information
Showing
110 changed files
with
653 additions
and
484 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Libraries; | ||
|
||
class Base64Url | ||
{ | ||
public static function decode(string $value): ?string | ||
{ | ||
return null_if_false(base64_decode(strtr($value, '-_', '+/'), true)); | ||
} | ||
|
||
public static function encode(string $value): string | ||
{ | ||
// url safe base64 | ||
// reference: https://datatracker.ietf.org/doc/html/rfc4648#section-5 | ||
return rtrim(strtr(base64_encode($value), '+/', '-_'), '='); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Libraries; | ||
|
||
class SignedRandomString | ||
{ | ||
public static function create(int $randomSize): string | ||
{ | ||
$key = random_bytes($randomSize); | ||
$hmac = static::hmac($key); | ||
|
||
return Base64Url::encode($hmac.$key); | ||
} | ||
|
||
public static function isValid(string $input): bool | ||
{ | ||
$bin = Base64Url::decode($input); | ||
if ($bin === null) { | ||
return false; | ||
} | ||
|
||
// hmac size for sha1 is 20 | ||
$hmac = substr($bin, 0, 20); | ||
$key = substr($bin, 20); | ||
$expectedHmac = static::hmac($key); | ||
|
||
return hash_equals($expectedHmac, $hmac); | ||
} | ||
|
||
private static function hmac(string $key): string | ||
{ | ||
return hash_hmac('sha1', $key, \Crypt::getKey(), true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Libraries; | ||
|
||
use App\Models\Smiley; | ||
use App\Traits\Memoizes; | ||
|
||
class Smilies | ||
{ | ||
use Memoizes; | ||
|
||
public function all(): array | ||
{ | ||
return $this->memoize(__FUNCTION__, fn () => $this->fetch()); | ||
} | ||
|
||
public function replacer(): array | ||
{ | ||
return $this->memoize(__FUNCTION__, function () { | ||
$smilies = $this->all(); | ||
|
||
$patterns = []; | ||
$replacements = []; | ||
|
||
foreach ($smilies as $smiley) { | ||
$patterns[] = '#(?<=^|[\n .])'.preg_quote($smiley['code'], '#').'(?![^<>]*>)#'; | ||
$replacements[] = '<!-- s'.$smiley['code'].' --><img src="{SMILIES_PATH}/'.$smiley['smiley_url'].'" alt="'.$smiley['code'].'" title="'.$smiley['emotion'].'" /><!-- s'.$smiley['code'].' -->'; | ||
} | ||
|
||
return compact('patterns', 'replacements'); | ||
}); | ||
} | ||
|
||
private function fetch(): array | ||
{ | ||
return Smiley::orderBy(\DB::raw('LENGTH(code)'), 'desc')->get()->toArray(); | ||
} | ||
} |
Oops, something went wrong.