Skip to content

Commit 3a5a4ae

Browse files
committed
Merge remote-tracking branch 'origin/develop' into release/2.2.4
2 parents a1ee7ef + 24b4bfd commit 3a5a4ae

File tree

278 files changed

+6762
-14421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

278 files changed

+6762
-14421
lines changed

.github/CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ Here are some things you should know when contributing:
3838
```console
3939
vendor/bin/phinx migrate -c core/migrations/phinx.php
4040
```
41+
- To test emails locally, we reccommend using [MailHog](https://github.com/mailhog/MailHog) - it allows you to view emails sent from your local server without actually sending them to a recipient.
42+
- Tweak your `core/config.php` file to use MailHog as the SMTP server:
43+
```php
44+
'email' => [
45+
'email' => '<some address, outgoing>',
46+
'username' => '',
47+
'password' => '',
48+
'name' => '',
49+
'host' => 'localhost',
50+
'port' => 1025,
51+
'smtp_auth' => false,
52+
'secure' => '',
53+
],
54+
```
4155

4256
## Versioning
4357
As of NamelessMC 2.0.0, we use a unique versioning system.

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
operating-system: ["ubuntu-latest"]
11-
php-versions: ["7.4", "8.0", "8.1", "8.2", "8.3", "8.4"]
11+
php-versions: ["8.2", "8.3", "8.4"]
1212
steps:
1313
- uses: actions/checkout@v2
1414

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
.valet-env.php
99
/vendor
1010
/core/assets/vendor
11-
/uploads/avatars/**
12-
/uploads/logos/**
11+
/uploads/**
1312
/node_modules/
1413
composer.lock
1514
checksums.json

.styleci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
risky: false
2-
version: 7.4
2+
version: 8.2
33
preset: recommended
44
monolithic: true
55
finder:
@@ -10,4 +10,4 @@ disabled:
1010
- concat_without_spaces
1111
- include
1212
- die_to_exit
13-
- phpdoc_separation
13+
- phpdoc_separation

composer.json

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,40 @@
55
"license": "MIT",
66
"config": {
77
"platform": {
8-
"php": "7.4"
8+
"php": "8.2"
99
}
1010
},
1111
"require": {
12-
"php": ">=7.4",
12+
"php": ">=8.2",
1313
"jdorn/sql-formatter": "^1.2.17",
1414
"smarty/smarty": "^4.3",
1515
"ezyang/htmlpurifier": "^4.16",
16-
"samayo/bulletproof": "^4.0.1",
16+
"samayo/bulletproof": "^5.0",
1717
"phpmailer/phpmailer": "^6.7.1",
1818
"evert/sitemap-php": "^1.2",
19-
"robthree/twofactorauth": "^1.8.2",
19+
"robthree/twofactorauth": "^3.0",
2020
"league/oauth2-client": "^2.6.1",
2121
"wohali/oauth2-discord-new": "^1.2.1",
2222
"league/oauth2-google": "^4.0",
2323
"guzzlehttp/guzzle": "^7.5",
2424
"xpaw/php-minecraft-query": "^4.0.1",
2525
"games647/minecraft-banner-generator": "^0.4.1",
26-
"symfony/polyfill-php80": "^v1.25",
27-
"ircmaxell/password-compat": "^1.0.4",
2826
"astrotomic/php-twemoji": "^0.2.2",
2927
"samerton/i18next": "^1.0.1",
30-
"robmorgan/phinx": "^0.13.4",
31-
"symfony/http-foundation": "^5.4.17",
32-
"joypixels/emoji-toolkit": "^7.0",
33-
"geoip2/geoip2": "^2.13",
28+
"robmorgan/phinx": "^0.16.0",
29+
"symfony/http-foundation": "^7.2",
30+
"joypixels/emoji-toolkit": "^9.0",
31+
"geoip2/geoip2": "^3.0",
3432
"jenssegers/agent": "^2.6",
35-
"php-di/php-di": "^6.4",
33+
"php-di/php-di": "^7.0",
3634
"twig/twig": "^3.0"
3735
},
3836
"require-dev": {
3937
"phpstan/phpstan": "1.6.9",
40-
"maximebf/debugbar": "^1.18.1",
4138
"junker/debugbar-smarty": "^0.2.1",
42-
"hannesvdvreken/guzzle-debugbar": "^3.0.1",
43-
"fakerphp/faker": "^1.21"
39+
"hannesvdvreken/guzzle-debugbar": "^4.0.1",
40+
"fakerphp/faker": "^1.21",
41+
"php-debugbar/php-debugbar": "^2.1"
4442
},
4543
"autoload": {
4644
"classmap": [

core/avatar/LICENSE.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

core/avatar/cache/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

core/avatar/cache/.gitkeep

Whitespace-only changes.

core/avatar/face.php

Lines changed: 0 additions & 102 deletions
This file was deleted.

core/classes/Avatars/AvatarSource.php

Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function getAvatarFromUUID(string $uuid, int $size = 128): string
4242
public static function getAvatarFromUserData(object $data, bool $allow_gifs = false, int $size = 128, bool $full = false): string
4343
{
4444
// If custom avatars are enabled, first check if they have gravatar enabled, and then fallback to normal image
45-
if (defined('CUSTOM_AVATARS')) {
45+
if (Settings::get('custom_avatars')) {
4646
if ($data->gravatar) {
4747
return 'https://secure.gravatar.com/avatar/' . md5(strtolower(trim($data->email))) . '?s=' . $size;
4848
}
@@ -64,10 +64,10 @@ public static function getAvatarFromUserData(object $data, bool $allow_gifs = fa
6464
}
6565

6666
// Fallback to default avatar image if it is set and the avatar type is custom
67-
if (defined('DEFAULT_AVATAR_TYPE') && DEFAULT_AVATAR_TYPE == 'custom' && DEFAULT_AVATAR_IMAGE !== '') {
68-
if (file_exists(ROOT_PATH . '/uploads/avatars/defaults/' . DEFAULT_AVATAR_IMAGE)) {
67+
if (Settings::get('default_avatar_type') === 'custom' && Settings::get('default_avatar_image') !== '') {
68+
if (file_exists(ROOT_PATH . '/uploads/avatars/defaults/' . Settings::get('default_avatar_image'))) {
6969
// We don't check the validity here since we know the file exists for sure
70-
return ($full ? rtrim(URL::getSelfURL(), '/') : '') . ((defined('CONFIG_PATH')) ? CONFIG_PATH . '/' : '/') . 'uploads/avatars/defaults/' . DEFAULT_AVATAR_IMAGE;
70+
return ($full ? rtrim(URL::getSelfURL(), '/') : '') . ((defined('CONFIG_PATH')) ? CONFIG_PATH . '/' : '/') . 'uploads/avatars/defaults/' . Settings::get('default_avatar_image');
7171
}
7272
}
7373

@@ -106,50 +106,41 @@ private static function validImageUrl(string $url): bool
106106
$cache = new Cache(['name' => 'nameless', 'extension' => '.cache', 'path' => ROOT_PATH . '/cache/']);
107107
$cache->setCache('avatar_validity');
108108

109-
if ($cache->isCached($url)) {
110-
return $cache->retrieve($url);
111-
}
112-
113-
$is_valid = false;
114-
115-
try {
116-
$response = HttpClient::createClient()->head($url);
117-
$headers = $response->getHeaders();
118-
if (isset($headers['Content-Type']) && $headers['Content-Type'][0] === 'image/png') {
119-
$is_valid = true;
109+
return $cache->fetch($url, function () use ($url) {
110+
$is_valid = false;
111+
112+
try {
113+
$response = HttpClient::createClient()->head($url, [
114+
// https://vzge.me requires a user agent
115+
'headers' => [
116+
'User-Agent' => 'NamelessMC/' . NAMELESS_VERSION . ' (https://namelessmc.com)',
117+
],
118+
]);
119+
$headers = $response->getHeaders();
120+
if (isset($headers['Content-Type']) && $headers['Content-Type'][0] === 'image/png') {
121+
$is_valid = true;
122+
}
123+
} catch (Exception $ignored) {
120124
}
121-
} catch (Exception $ignored) {
122-
}
123125

124-
$cache->store($url, $is_valid, 3600);
125-
126-
return $is_valid;
126+
return $is_valid;
127+
}, 3600);
127128
}
128129

129130
/**
130131
* Get the currently active avatar source.
131132
*
132133
* @return AvatarSourceBase The active source.
133134
*/
134-
public static function getActiveSource(): AvatarSourceBase
135+
private static function getActiveSource(): AvatarSourceBase
135136
{
136-
return self::$_active_source;
137-
}
138-
139-
/**
140-
* Set the active source to the source by name.
141-
* Fallsback to Cravatar if name was not found.
142-
*
143-
* @param string $name Name of source to set as active.
144-
*/
145-
public static function setActiveSource(string $name): void
146-
{
147-
$source = self::getSourceByName($name);
148-
if ($source === null) {
149-
$source = self::getSourceByName('cravatar');
137+
// Compatibility with old built-in source, can be removed in 2.3.0
138+
$setting = Settings::get('default_avatar_source', 'cravatar');
139+
if ($setting === 'Nameless') {
140+
$setting = 'cravatar';
150141
}
151142

152-
self::$_active_source = $source;
143+
return self::$_active_source ??= self::getSourceByName($setting);
153144
}
154145

155146
/**
@@ -159,11 +150,7 @@ public static function setActiveSource(string $name): void
159150
*/
160151
private static function getDefaultPerspective(): string
161152
{
162-
if (defined('DEFAULT_AVATAR_PERSPECTIVE')) {
163-
return DEFAULT_AVATAR_PERSPECTIVE;
164-
}
165-
166-
return 'face';
153+
return Settings::get('default_avatar_perspective', 'face');
167154
}
168155

169156
/**
@@ -199,13 +186,6 @@ public static function getAllSources(): iterable
199186
*/
200187
public static function getUrlToFormat(): string
201188
{
202-
// Default to Cravatar
203-
if (!isset(self::$_active_source)) {
204-
require_once(ROOT_PATH . '/modules/Core/classes/Avatars/CravatarAvatarSource.php');
205-
206-
return (new CravatarAvatarSource())->getUrlToFormat(self::getDefaultPerspective());
207-
}
208-
209189
return self::getActiveSource()->getUrlToFormat(self::getDefaultPerspective());
210190
}
211191

0 commit comments

Comments
 (0)