Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/config/packages/http_client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ framework:
Content-Type: 'application/json'
http_client.bluesky:
base_uri: 'https://bsky.social'
http_client.bluesky_embed:
base_uri: 'https://embed.bsky.app'
13 changes: 13 additions & 0 deletions db/migrations/20260421000000_talk_bluesky_posts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

class TalkBlueskyPosts extends AbstractMigration
{
public function change(): void
{
$this->execute("ALTER TABLE `afup_sessions` ADD `bluesky_posts` text DEFAULT NULL AFTER `tweets`");
}
}
1 change: 1 addition & 0 deletions db/seeds/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function run(): void
'joindin' => 24138,
'date_publication' => (new \DateTime())->modify('-1 days')->format('Y-m-d H:i:s'),
'has_allowed_to_sharing_with_local_offices' => 1,
'bluesky_posts' => 'https://bsky.app/profile/afup.org/post/3mjk3hmqxxe2d',
],
[
'session_id' => 3,
Expand Down
4 changes: 4 additions & 0 deletions sources/AppBundle/Event/Form/TalkAdminType.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => 'Tweets',
'required' => false,
])
->add('blueskyPosts', TextareaType::class, [
'label' => 'Posts Bluesky',
'required' => false,
])
->add('submittedOn', DateTimeType::class, [
'label' => 'Date de soumission',
])
Expand Down
5 changes: 5 additions & 0 deletions sources/AppBundle/Event/Model/Repository/TalkRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,11 @@ public static function initMetadata(SerializerFactoryInterface $serializerFactor
'fieldName' => 'tweets',
'type' => 'string',
])
->addField([
'columnName' => 'bluesky_posts',
'fieldName' => 'blueskyPosts',
'type' => 'string',
])
->addField([
'columnName' => 'transcript',
'fieldName' => 'transcript',
Expand Down
36 changes: 36 additions & 0 deletions sources/AppBundle/Event/Model/Talk.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Talk implements NotifyPropertyInterface

private ?string $tweets = null;

private ?string $blueskyPosts = null;

private ?string $transcript = null;

private ?string $verbatim = null;
Expand Down Expand Up @@ -615,6 +617,40 @@ public function getTweetsHasArray(): array
return $returnedTweets;
}

public function getBlueskyPosts(): ?string
{
return $this->blueskyPosts;
}

public function setBlueskyPosts(?string $blueskyPosts): self
{
$this->propertyChanged('blueskyPosts', $this->blueskyPosts, $blueskyPosts);
$this->blueskyPosts = $blueskyPosts;

return $this;
}

/**
* @return array<string>
*/
public function getBlueskyPostsAsArray(): array
{
if (!$this->getBlueskyPosts()) {
return [];
}
$returnedPosts = [];
foreach (explode(PHP_EOL, $this->getBlueskyPosts()) as $post) {
$post = trim($post);
if ($post === '' || $post === '0') {
continue;
}

$returnedPosts[] = $post;
}

return $returnedPosts;
}

public function getHasAllowedToSharingWithLocalOffices(): bool
{
return $this->hasAllowedToSharingWithLocalOffices;
Expand Down
42 changes: 42 additions & 0 deletions sources/AppBundle/SocialNetwork/Bluesky/BlueskyOembedClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace AppBundle\SocialNetwork\Bluesky;

use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Contracts\HttpClient\HttpClientInterface;

final readonly class BlueskyOembedClient
{
public function __construct(
#[Autowire('@http_client.bluesky_embed')]
private HttpClientInterface $httpClient,
#[Autowire('@cache.system')]
private CacheItemPoolInterface $cache,
) {}

public function getEmbedHtml(string $url): string
{
$cacheItem = $this->cache->getItem('bluesky_oembed_' . md5($url));

if (!$cacheItem->isHit()) {
try {
$response = $this->httpClient->request('GET', '/oembed', [
'query' => ['url' => $url, 'format' => 'json'],
]);
$data = $response->toArray();
// Strip the embed.js <script> tag — we output it once in the template
$html = preg_replace('/<script\b[^>]*embed\.bsky\.app[^>]*><\/script>/', '', $data['html'] ?? '');
} catch (\Throwable) {
$html = '';
}

$cacheItem->set($html);
$this->cache->save($cacheItem);
}

return (string) $cacheItem->get();
}
}
6 changes: 6 additions & 0 deletions sources/AppBundle/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace AppBundle\Twig;

use AppBundle\SocialNetwork\Bluesky\BlueskyOembedClient;
use Parsedown;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Twig\Extension\AbstractExtension;
Expand All @@ -16,6 +17,7 @@ class TwigExtension extends AbstractExtension implements GlobalsInterface
public function __construct(
private readonly Parsedown $parsedown,
private readonly Parsedown $emailParsedown,
private readonly BlueskyOembedClient $blueskyOembedClient,
#[Autowire(env: 'bool:GOOGLE_ANALYTICS_ENABLED')]
private readonly bool $googleAnalyticsEnabled,
#[Autowire(env: 'GOOGLE_ANALYTICS_ID')]
Expand All @@ -35,6 +37,10 @@ public function getFunctions(): array
}
return '';
}, ['is_safe' => ['html']]),
new TwigFunction('bluesky_oembed', function (string $url): string {
$html = $this->blueskyOembedClient->getEmbedHtml($url);
return $html ?: '<a href="' . htmlspecialchars($url) . '">' . htmlspecialchars($url) . '</a>';
}, ['is_safe' => ['html']]),
];
}

Expand Down
1 change: 1 addition & 0 deletions templates/admin/talk/form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
{{ form_row(form.interviewUrl) }}
{{ form_row(form.languageCode) }}
{{ form_row(form.tweets) }}
{{ form_row(form.blueskyPosts) }}
{{ form_row(form.verbatim, {attr: {class: 'simplemde'}}) }}
</div>
<div class="ui segment">
Expand Down
24 changes: 24 additions & 0 deletions templates/site/talks/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,30 @@
</div>
{% endif %}

{% if talk.getBlueskyPostsAsArray|length > 0 %}
<div class="container">
<div class="col-md-12">
<div class="container comments-title-container">
<div class="col-md-12">
<h2>Posts Bluesky</h2>
</div>
</div>

{% for posts_batch in talk.getBlueskyPostsAsArray|batch(4) %}
<div class="container">
{% for post in posts_batch %}
<div class="col-md-3">
{{ bluesky_oembed(post) }}
</div>
{% endfor %}
</div>
{% endfor %}

</div>
<script async src="https://embed.bsky.app/static/embed.js" charset="utf-8"></script>
</div>
{% endif %}

{% if comments|length > 0 %}
{% include 'common/star.html.twig' %}
<div class="container">
Expand Down
12 changes: 12 additions & 0 deletions tests/behat/features/Admin/Events/Conferences.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ Feature: Administration - Évènements - Conférences
And I should see "Une autre conference"
And I should see "Adrien Gallou"

@reloadDbWithTestData
Scenario: Ajout de posts Bluesky à une conférence
Given I am logged in as admin and on the Administration
And I follow "Conférences"
When I follow the button of tooltip "Modifier la conférence Jouons tous ensemble à un petit jeu"
Then I fill in "talk_admin[blueskyPosts]" with "https://bsky.app/profile/afup.org/post/3mjmmwpp34f2r"
And I press "Soumettre"
Then I should see "La conférence a été modifiée"
When I go to "/talks/1-jouons-tous-ensemble-a-un-petit-jeu"
Then I should see "Posts Bluesky"
And the response should contain "3mjmmwpp34f2r"

@reloadDbWithTestData
Scenario: Modification d'une conférence
Given I am logged in as admin and on the Administration
Expand Down
6 changes: 6 additions & 0 deletions tests/behat/features/PublicSite/Talks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ Feature: Site Public - Talks
And the response should contain "<link rel=\"canonical\" href=\"https://apachephptest:80/talks/?fR%5Bevent.title%5D%5B0%5D=AFUP%20Day%202019%20Lyon\" />"


@reloadDbWithTestData
Scenario: Affichage des posts Bluesky sur la page d'un talk
When I go to "/talks/2-rest-ou-graphql-exemples-illustres-avec-symfony-et-api-platform"
Then I should see "Posts Bluesky"
And the response should contain "3mjk3hmqxxe2d"

@reloadDbWithTestData
Scenario: Accès à la liste des vidéos d'un speaker
When I go to "/talks/?fR[speakers.label][0]=Un Speaker"
Expand Down
Loading