-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10655 from notbakaneko/feature/opengraph-interface-2
Extract opengraph methods
- Loading branch information
Showing
41 changed files
with
410 additions
and
103 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
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,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 implements OpengraphInterface | ||
{ | ||
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, | ||
]; | ||
} | ||
} |
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,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 implements OpengraphInterface | ||
{ | ||
public function __construct(private Beatmapset $beatmapset) | ||
{ | ||
} | ||
|
||
public function get(): array | ||
{ | ||
$section = osu_trans('layout.menu.beatmaps._'); | ||
$title = "{$this->beatmapset->artist} - {$this->beatmapset->title}"; // opengraph header always intended for guest. | ||
|
||
return [ | ||
'description' => "osu! » {$section} » {$title}", | ||
'image' => $this->beatmapset->coverURL('card'), | ||
'title' => $title, | ||
]; | ||
} | ||
} |
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,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 implements OpengraphInterface | ||
{ | ||
public function __construct(private Comment $comment) | ||
{ | ||
} | ||
|
||
public function get(): array | ||
{ | ||
$user = $this->comment->user; | ||
|
||
return priv_check_user(null, 'CommentShow', $this->comment)->can() | ||
? [ | ||
'description' => blade_safe(html_excerpt($this->comment->message_html, 100)), | ||
'image' => $user->user_avatar, | ||
'title' => osu_trans('comments.ogp.title', ['user' => $user->username]), | ||
] : []; | ||
} | ||
} |
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,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 implements OpengraphInterface | ||
{ | ||
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, | ||
]; | ||
} | ||
} |
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,41 @@ | ||
<?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\Libraries\Opengraph\OpengraphInterface; | ||
use App\Models\Forum\Forum; | ||
|
||
class ForumOpengraph implements OpengraphInterface | ||
{ | ||
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(), | ||
]; | ||
} | ||
} |
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,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\Forum; | ||
|
||
use App\Libraries\Opengraph\OpengraphInterface; | ||
use App\Models\Forum\Topic; | ||
|
||
class TopicOpengraph implements OpengraphInterface | ||
{ | ||
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, | ||
]; | ||
} | ||
} |
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,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\NewsPost; | ||
|
||
class NewsPostOpengraph implements OpengraphInterface | ||
{ | ||
public function __construct(private NewsPost $post) | ||
{ | ||
} | ||
|
||
public function get(): array | ||
{ | ||
return [ | ||
'description' => $this->post->previewText(), | ||
'image' => $this->post->firstImage(true), | ||
'title' => $this->post->title(), | ||
]; | ||
} | ||
} |
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,13 @@ | ||
<?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; | ||
|
||
interface OpengraphInterface | ||
{ | ||
public function get(): array; | ||
} |
Oops, something went wrong.