Sfoglia il codice sorgente

Add support for youtube and video embeds

staging
parent
commit
24a1f8f10a
4 ha cambiato i file con 69 aggiunte e 4 eliminazioni
  1. +26
    -0
      app/BbCode/Tag/Video.php
  2. +26
    -0
      app/BbCode/Tag/Youtube.php
  3. +15
    -2
      app/Helper/BBCode.php
  4. +2
    -2
      composer.lock

+ 26
- 0
app/BbCode/Tag/Video.php Vedi File

@@ -0,0 +1,26 @@
<?php

namespace App\BbCode\Tag;

use Knockout\BbCode\Tag\TagInterface;
use Knockout\BbCode\Tokenizer\Tag as TokenTag;

class Video implements TagInterface
{

public function format(TokenTag $tokenTag): string
{
$url = $tokenTag->getText();
return "<a href=\"{$url}\" target=\"_blank\">[Video Embed]</a>";
}

public function getName(): string
{
return 'video';
}

public function getOriginalText(TokenTag $tokenTag) : string
{
return "[video]{$tokenTag->getText()}[/video]";
}
}

+ 26
- 0
app/BbCode/Tag/Youtube.php Vedi File

@@ -0,0 +1,26 @@
<?php

namespace App\BbCode\Tag;

use Knockout\BbCode\Tag\TagInterface;
use Knockout\BbCode\Tokenizer\Tag as TokenTag;

class Youtube implements TagInterface
{

public function format(TokenTag $tokenTag): string
{
$url = $tokenTag->getText();
return "<a href=\"{$url}\" target=\"_blank\">[Youtube Embed]</a>";
}

public function getName(): string
{
return 'youtube';
}

public function getOriginalText(TokenTag $tokenTag) : string
{
return "[youtube]{$tokenTag->getText()}[/youtube]";
}
}

+ 15
- 2
app/Helper/BBCode.php Vedi File

@@ -2,6 +2,7 @@

namespace App\Helper;

// formatting
use App\BbCode\Tag\Unknown;
use App\BbCode\Tag\Text;
use App\BbCode\Tag\Bold;
@@ -12,10 +13,14 @@ use App\BbCode\Tag\Spoiler;
use App\BbCode\Tag\HeadingOne;
use App\BbCode\Tag\HeadingTwo;
use App\BbCode\Tag\Link;
use App\BbCode\Tag\Image;
// quotes
use App\BbCode\Tag\Quote;
use App\BbCode\Tag\Blockquote;
// embeds
use App\BbCode\Tag\Image;
use App\BbCode\Tag\Twitter;
use App\BbCode\Tag\Youtube;
use App\BbCode\Tag\Video;

use Knockout\BbCode\BbCode as Parser;
use Knockout\BbCode\Tokenizer\Tokenizer;
@@ -66,6 +71,12 @@ class BBCode {
$twitter = new Twitter();
$parser->addTag($twitter);

$youtube = new Youtube();
$parser->addTag($youtube);

$video = new Video();
$parser->addTag($video);

$tags = [
$unknown,
$text,
@@ -77,7 +88,9 @@ class BBCode {
$link,
$quote,
$blockquote,
$twitter
$twitter,
$youtube,
$video
];

$anyChild = [


+ 2
- 2
composer.lock Vedi File

@@ -1867,7 +1867,7 @@
"source": {
"type": "git",
"url": "https://git.mos6581.com/Knockout/BBCode.git",
"reference": "c06bf463f5c701c398852b413c1a8210c5c9c165"
"reference": "038da52a9db8b061dac95a92c7b8c10d884f56e4"
},
"require": {
"php": ">=7.0"
@@ -1886,7 +1886,7 @@
"MIT"
],
"description": "php parser for bb code",
"time": "2021-01-01T23:15:08+00:00"
"time": "2021-01-02T02:58:35+00:00"
},
{
"name": "laravel/lumen-framework",


Loading…
Annulla
Salva