PHP code example of datlechin / flarum-link-preview
1. Go to this page and download the library: Download datlechin/flarum-link-preview library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
datlechin / flarum-link-preview example snippets
use Datlechin\LinkPreview\Extend\LinkPreview;
use Flarum\Extend;
return [
(new Extend\Conditional())
->whenExtensionEnabled('datlechin-link-preview', fn () => [
(new LinkPreview())->route('acme-recipes.show', RecipeCard::class),
]),
];
use Datlechin\LinkPreview\Internal\Card;
use Datlechin\LinkPreview\Internal\MatchedRoute;
use Datlechin\LinkPreview\Internal\Meta;
use Datlechin\LinkPreview\Internal\RouteCard;
use Flarum\User\User;
class RecipeCard implements RouteCard
{
public function card(MatchedRoute $route, User $actor): ?Card
{
$recipe = Recipe::whereVisibleTo($actor)->find($route->parameter('id'));
if (! $recipe) {
return null;
}
return new Card(
title: $recipe->title,
description: $recipe->summary,
image: $recipe->photo_url,
meta: [
Meta::user($recipe->user->username),
Meta::count('acme-recipes.forum.link_preview.steps', $recipe->step_count),
Meta::date($recipe->created_at),
],
);
}
}
use Flarum\Foundation\AbstractServiceProvider;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class LinkPreviewProxyProvider extends AbstractServiceProvider
{
public function register(): void
{
$this->container->extend(
'datlechin-link-preview.transport',
fn (HttpClientInterface $client) => $client->withOptions(['proxy' => 'http://proxy.example.com:3128']),
);
}
}
sh
composer update datlechin/flarum-link-preview:"*"
php flarum migrate
php flarum cache:clear
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.