-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract opengraph methods #10655
Extract opengraph methods #10655
Changes from 24 commits
7df0115
6a3bf2b
3e84b70
13d0101
d0c15f0
12bb5cb
e96033d
c24c508
83d9ac4
72fd995
6c50026
92cb2fb
1f6c85a
23f63d0
efe5cda
7dbb641
5927427
cfdf270
32e692f
991b6e2
c2b393f
bb95035
911d0f4
bde5e30
0bf535b
078e18f
6b5cef0
6188225
ada79a7
6560b14
9a9fc1d
fb6f795
0bb17e0
68451af
d2b1930
25afc43
7a7967f
6f52526
5c466b7
b2f6727
6911367
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?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\Opengraph; | ||
|
||
use App\Models\Artist; | ||
|
||
class ArtistOpengraph | ||
{ | ||
public function __construct(private Artist $artist) | ||
{ | ||
} | ||
|
||
public function get(): array | ||
{ | ||
return [ | ||
'description' => first_paragraph(markdown_plain($this->artist->description)), | ||
'image' => $this->artist->cover_url, | ||
'title' => $this->artist->name, | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?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\Opengraph; | ||
|
||
use App\Models\Beatmapset; | ||
|
||
class BeatmapsetOpengraph | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
public function __construct(private Beatmapset $beatmapset) | ||
{ | ||
} | ||
|
||
public function get(): array | ||
{ | ||
$section = osu_trans('layout.menu.beatmaps._'); | ||
$title = "{$this->beatmapset->artist} - {$this->beatmapset->title}"; // opengrah header always intended for guest. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh right, opengraph missing p |
||
|
||
return [ | ||
'description' => "osu! » {$section} » {$title}", | ||
'image' => $this->beatmapset->coverURL('card'), | ||
'title' => $title, | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?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\Opengraph; | ||
|
||
use App\Models\Comment; | ||
|
||
class CommentOpengraph | ||
{ | ||
public function __construct(private Comment $comment) | ||
{ | ||
} | ||
|
||
public function get(): array | ||
{ | ||
$user = $this->comment->user; | ||
|
||
return priv_check('CommentShow', $this->comment)->can() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. priv_check_user with null user? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. originally, I had everything assume opengrapgh would be viewed only by |
||
? [ | ||
'description' => html_excerpt($this->comment->message_html, 100), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
although I noticed discord double unescape description by default 🤔 and twitter is even worse |
||
'image' => $user->user_avatar, | ||
'title' => osu_trans('comments.ogp.title', ['user' => $user->username]), | ||
] : []; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?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\Opengraph; | ||
|
||
use App\Models\Contest; | ||
|
||
class ContestOpengraph | ||
{ | ||
public function __construct(private Contest $contest) | ||
{ | ||
} | ||
|
||
public function get(): array | ||
{ | ||
return [ | ||
'description' => strip_tags(markdown($this->contest->currentDescription())), | ||
'image' => $this->contest->header_url, | ||
'title' => $this->contest->name, | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?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\Opengraph\Forum; | ||
|
||
use App\Models\Forum\Forum; | ||
|
||
class ForumOpengraph | ||
{ | ||
public function __construct(private Forum $forum) | ||
{ | ||
} | ||
|
||
// Reminder to update Topic::toOpengraph() as necessary if this value changes. | ||
public function description(): string | ||
{ | ||
$stack = [osu_trans('forum.title')]; | ||
foreach ($this->forum->forum_parents as $forumId => $forumData) { | ||
$stack[] = $forumData[0]; | ||
} | ||
|
||
$stack[] = $this->forum->forum_name; | ||
|
||
return implode(' » ', $stack); | ||
} | ||
|
||
public function get(): array | ||
{ | ||
|
||
return [ | ||
'description' => $this->description(), | ||
'title' => $this->forum->forum_name, | ||
'image' => $this->forum->cover?->fileUrl(), | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?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\Opengraph\Forum; | ||
|
||
use App\Models\Forum\Topic; | ||
|
||
class TopicOpengraph | ||
{ | ||
public function __construct(private Topic $topic) | ||
{ | ||
} | ||
|
||
public function get(): array | ||
{ | ||
$forumDescription = (new ForumOpengraph($this->topic->forum))->description(); | ||
|
||
return [ | ||
'description' => "{$forumDescription} » {$this->topic->topic_title}", | ||
'image' => $this->topic->cover?->fileUrl() ?? $this->topic->forum->cover?->defaultTopicCover->fileUrl(), | ||
'title' => $this->topic->topic_title, | ||
]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with first two paragraphs may not even contain actual content I wonder if it's better to just show first 100 characters instead.