Skip to content

Commit 787a8cf

Browse files
committed
wip
2 parents 151e94f + c7269ef commit 787a8cf

File tree

107 files changed

+1280
-3227
lines changed

Some content is hidden

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

107 files changed

+1280
-3227
lines changed

.env.example

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ APP_ENV=local
33
APP_KEY=
44
APP_DEBUG=true
55
APP_TIMEZONE=UTC
6-
APP_URL=http://laravel.io.test
7-
8-
APP_LOCALE=en
9-
APP_FALLBACK_LOCALE=en
10-
APP_FAKER_LOCALE=en_US
6+
APP_HOST=laravel.io.test
7+
APP_URL=http://${APP_HOST}
118

129
APP_MAINTENANCE_DRIVER=file
1310
APP_MAINTENANCE_STORE=database
1411

12+
CACHE_STORE=file
13+
SESSION_DRIVER=file
14+
1515
BCRYPT_ROUNDS=12
1616

1717
DB_DATABASE=laravel

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
/.vscode
1414
.env
1515
.phpunit.result.cache
16+
!database/schema/*.sql

app/Http/Middleware/SiteIndexing.php

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

app/Jobs/GenerateSocialShareImage.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ final class GenerateSocialShareImage
2121

2222
const TEMPLATE = 'social-share-template.png';
2323

24-
const CACHE_LIFETIME = 43200;
25-
2624
public function __construct(private Article $article)
2725
{
2826
}
@@ -31,13 +29,12 @@ public function handle(ImageManager $image): mixed
3129
{
3230
$text = wordwrap($this->article->title(), self::CHARACTERS_PER_LINE);
3331

34-
return $image->cache(function ($image) use ($text) {
35-
$image->make(resource_path('images/'.self::TEMPLATE))
36-
->text($text, self::TEXT_X_POSITION, self::TEXT_Y_POSITION, function ($font) {
37-
$font->file(resource_path('fonts/'.self::FONT));
38-
$font->size(self::FONT_SIZE);
39-
$font->color(self::TEXT_COLOUR);
40-
});
41-
}, self::CACHE_LIFETIME, true)->response('png');
32+
return $image->make(resource_path('images/'.self::TEMPLATE))
33+
->text($text, self::TEXT_X_POSITION, self::TEXT_Y_POSITION, function ($font) {
34+
$font->file(resource_path('fonts/'.self::FONT));
35+
$font->size(self::FONT_SIZE);
36+
$font->color(self::TEXT_COLOUR);
37+
})
38+
->response('png');
4239
}
4340
}

app/Livewire/Editor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function getUsers($query): array
7373

7474
public function getPreviewProperty(): string
7575
{
76-
return replace_links(md_to_html($this->body ?: ''));
76+
return md_to_html($this->body ?: '');
7777
}
7878

7979
public function preview(): void

app/Markdown/LeagueConverter.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
final class LeagueConverter implements Converter
88
{
9-
public function __construct(
10-
private MarkdownConverter $converter
11-
) {
9+
public function __construct(private MarkdownConverter $converter)
10+
{
1211
}
1312

1413
public function toHtml(string $markdown): string

app/Markdown/MarkdownServiceProvider.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Illuminate\Support\ServiceProvider;
66
use League\CommonMark\Environment\Environment;
77
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
8+
use League\CommonMark\Extension\ExternalLink\ExternalLinkExtension;
9+
use League\CommonMark\Extension\GithubFlavoredMarkdownExtension;
810
use League\CommonMark\Extension\Mention\MentionExtension;
911
use League\CommonMark\MarkdownConverter;
1012

@@ -15,17 +17,26 @@ public function register(): void
1517
$this->app->singleton(Converter::class, function () {
1618
$environment = new Environment([
1719
'html_input' => 'escape',
20+
'max_nesting_level' => 10,
21+
'allow_unsafe_links' => false,
1822
'mentions' => [
1923
'username' => [
2024
'prefix' => '@',
2125
'pattern' => '[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}(?!\w)',
2226
'generator' => config('app.url').'/user/%s',
2327
],
2428
],
29+
'external_link' => [
30+
'internal_hosts' => config('app.host'),
31+
'open_in_new_window' => true,
32+
'nofollow' => 'external',
33+
],
2534
]);
2635

2736
$environment->addExtension(new CommonMarkCoreExtension);
37+
$environment->addExtension(new GithubFlavoredMarkdownExtension);
2838
$environment->addExtension(new MentionExtension);
39+
$environment->addExtension(new ExternalLinkExtension);
2940

3041
return new LeagueConverter(new MarkdownConverter($environment));
3142
});

app/Providers/AppServiceProvider.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
use Illuminate\Support\Facades\DB;
1818
use Illuminate\Support\Facades\Notification;
1919
use Illuminate\Support\Facades\RateLimiter;
20-
use Illuminate\Support\Facades\Request;
21-
use Illuminate\Support\Facades\Route;
20+
use Illuminate\Support\Facades\Request as RequestFacade;
2221
use Illuminate\Support\ServiceProvider;
2322
use Laravel\Horizon\Horizon;
2423

@@ -77,7 +76,7 @@ private function bootSlowQueryLogging()
7776
new SlowQueryLogged(
7877
$event->sql,
7978
$event->time,
80-
Request::url(),
79+
RequestFacade::url(),
8180
),
8281
);
8382
});

app/Rules/DoesNotContainUrlRule.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
namespace App\Rules;
44

5-
use Illuminate\Contracts\Validation\Rule;
5+
use Closure;
6+
use Illuminate\Contracts\Validation\ValidationRule;
67
use Illuminate\Validation\Concerns\ValidatesAttributes;
78

8-
final class DoesNotContainUrlRule implements Rule
9+
final class DoesNotContainUrlRule implements ValidationRule
910
{
1011
use ValidatesAttributes;
1112

12-
public function passes($attribute, $value): bool
13+
public function validate(string $attribute, mixed $value, Closure $fail): void
1314
{
14-
return ! collect(explode(' ', $value))->contains(function ($word) {
15+
$fails = collect(explode(' ', $value))->contains(function ($word) {
1516
return $this->validateRequired('word', $word) && $this->validateUrl('word', $word);
1617
});
17-
}
18-
19-
public function message(): string
20-
{
21-
return 'The :attribute field cannot contain an url.';
18+
19+
if ($fails) {
20+
$fail('The :attribute field cannot contain an url.');
21+
}
2222
}
2323
}

app/Rules/HttpImageRule.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22

33
namespace App\Rules;
44

5-
use Illuminate\Contracts\Validation\Rule;
5+
use Closure;
6+
use Illuminate\Contracts\Validation\ValidationRule;
67

78
/**
89
* This rule validates Markdown for non-HTTPS image links.
910
*/
10-
final class HttpImageRule implements Rule
11+
final class HttpImageRule implements ValidationRule
1112
{
12-
public function passes($attribute, $value): bool
13+
public function validate(string $attribute, mixed $value, Closure $fail): void
1314
{
14-
return ! preg_match('/!\[.*\]\(http:\/\/.*\)/', $value);
15-
}
16-
17-
public function message(): string
18-
{
19-
return 'The :attribute field contains at least one image with an HTTP link.';
15+
if (preg_match('/!\[.*\]\(http:\/\/.*\)/', $value)) {
16+
$fail('The :attribute field contains at least one image with an HTTP link.');
17+
}
2018
}
2119
}

app/Rules/InvalidMentionRule.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22

33
namespace App\Rules;
44

5-
use Illuminate\Contracts\Validation\Rule;
5+
use Closure;
6+
use Illuminate\Contracts\Validation\ValidationRule;
67

78
/**
89
* This rule validates links are not diguised as mentions.
910
*/
10-
final class InvalidMentionRule implements Rule
11+
final class InvalidMentionRule implements ValidationRule
1112
{
12-
public function passes($attribute, $value): bool
13+
public function validate(string $attribute, mixed $value, Closure $fail): void
1314
{
14-
return ! preg_match('/\[@.*\]\(http.*\)/', $value);
15-
}
16-
17-
public function message(): string
18-
{
19-
return 'The :attribute field contains an invalid mention.';
15+
if (preg_match('/\[@.*\]\(http.*\)/', $value)) {
16+
$fail('The :attribute field contains an invalid mention.');
17+
}
2018
}
2119
}

app/Rules/PasscheckRule.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
namespace App\Rules;
44

5-
use Illuminate\Contracts\Validation\Rule;
5+
use Closure;
6+
use Illuminate\Contracts\Validation\ValidationRule;
67
use Illuminate\Support\Facades\Auth;
78
use Illuminate\Support\Facades\Hash;
89

9-
final class PasscheckRule implements Rule
10+
final class PasscheckRule implements ValidationRule
1011
{
11-
public function passes($attribute, $value): bool
12+
public function validate(string $attribute, mixed $value, Closure $fail): void
1213
{
13-
return Hash::check($value, Auth::user()->getAuthPassword());
14-
}
15-
16-
public function message(): string
17-
{
18-
return 'Your current password is incorrect.';
14+
if (! Hash::check($value, Auth::user()->getAuthPassword())) {
15+
$fail('Your current password is incorrect.');
16+
}
1917
}
2018
}

app/Rules/UniqueGitHubUser.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,33 @@
44

55
use App\Concerns\SendsAlerts;
66
use App\Models\User;
7-
use Illuminate\Contracts\Validation\Rule;
7+
use Closure;
8+
use Illuminate\Contracts\Validation\ValidationRule;
89
use Illuminate\Database\Eloquent\ModelNotFoundException;
910

10-
final class UniqueGitHubUser implements Rule
11+
final class UniqueGitHubUser implements ValidationRule
1112
{
1213
use SendsAlerts;
1314

14-
private User $user;
15-
16-
public function passes($attribute, $value): bool
15+
public function validate(string $attribute, mixed $value, Closure $fail): void
1716
{
1817
try {
19-
$this->user = User::findByGitHubId($value);
18+
$user = User::findByGitHubId($value);
2019
} catch (ModelNotFoundException) {
21-
return true;
20+
//
2221
}
2322

24-
return false;
23+
$message = $this->message($user);
24+
25+
$this->error($message);
26+
27+
$fail($message);
2528
}
2629

27-
public function message()
30+
public function message(User $user): string
2831
{
29-
$this->error('We already found a user with the given GitHub account (:username). Would you like to <a href=":login">login</a> instead?', [
30-
'username' => '@'.$this->user->githubUsername(),
32+
return __('We already found a user with the given GitHub account (:username). Would you like to <a href=":login">login</a> instead?', [
33+
'username' => '@'.$user->githubUsername(),
3134
'login' => route('login'),
3235
]);
3336
}

bootstrap/app.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Foundation\Configuration\Middleware;
1010
use Illuminate\Session\TokenMismatchException;
1111
use Illuminate\Validation\ValidationException;
12+
use Sentry\Laravel\Integration;
1213
use Symfony\Component\HttpKernel\Exception\HttpException;
1314

1415
return Application::configure(basePath: dirname(__DIR__))
@@ -25,8 +26,9 @@
2526
$middleware->redirectUsersTo(AppServiceProvider::HOME);
2627

2728
$middleware->web([
28-
\App\Http\Middleware\DisableFloc::class,
2929
\App\Http\Middleware\RedirectIfBanned::class,
30+
], [
31+
\App\Http\Middleware\DisableFloc::class,
3032
]);
3133

3234
$middleware->throttleApi();
@@ -41,9 +43,5 @@
4143
ValidationException::class,
4244
]);
4345

44-
$exceptions->reportable(function (Throwable $e) {
45-
if (app()->bound('sentry')) {
46-
app('sentry')->captureException($e);
47-
}
48-
});
46+
Integration::handles($exceptions);
4947
})->create();

composer.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
"blade-ui-kit/blade-ui-kit": "^0.6",
1212
"blade-ui-kit/blade-zondicons": "^1.5",
1313
"codeat3/blade-simple-icons": "^3.3",
14-
"doctrine/dbal": "^3.5",
1514
"guzzlehttp/guzzle": "^7.2",
1615
"intervention/image": "^2.7",
17-
"intervention/imagecache": "^2.5",
1816
"laravel-notification-channels/telegram": "^5.0",
1917
"laravel-notification-channels/twitter": "^8.1.1",
2018
"laravel/framework": "^11.5",
@@ -32,12 +30,10 @@
3230
"sentry/sentry-laravel": "^4.3",
3331
"spatie/laravel-feed": "^4.4",
3432
"spatie/laravel-ignition": "^2.4",
35-
"spatie/laravel-robots-middleware": "^1.4",
3633
"spatie/laravel-schedule-monitor": "^3.7",
3734
"spatie/laravel-sitemap": "^7.2",
3835
"symfony/http-client": "^7.0",
39-
"symfony/mailgun-mailer": "^7.0",
40-
"yarri/link-finder": "^2.5"
36+
"symfony/mailgun-mailer": "^7.0"
4137
},
4238
"require-dev": {
4339
"fakerphp/faker": "^1.23",

0 commit comments

Comments
 (0)