diff --git a/.idea/php.xml b/.idea/php.xml index b37ec3bb..07bc7d1c 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -119,6 +119,7 @@ + diff --git a/composer.json b/composer.json index db42c77c..ea1b436b 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "ext-iconv": "*", "friendsofsymfony/ckeditor-bundle": "^2.0", "omines/datatables-bundle": "^0.2.2", + "s9e/text-formatter": "^1.4", "sensio/framework-extra-bundle": "^5.1", "shivas/versioning-bundle": "^3.1", "symfony/asset": "4.2.*", diff --git a/composer.lock b/composer.lock index 67b3807e..cf845876 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "9226477561eef66d140fe1e9a6ccd4a1", + "content-hash": "af1eaecfa244525222a1a74e0a06a247", "packages": [ { "name": "doctrine/annotations", @@ -2160,6 +2160,71 @@ ], "time": "2017-10-23T01:57:42+00:00" }, + { + "name": "s9e/text-formatter", + "version": "1.4.1", + "source": { + "type": "git", + "url": "https://github.com/s9e/TextFormatter.git", + "reference": "45c8a3845aa791b7da720fa13e6ee18ec49bf795" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/45c8a3845aa791b7da720fa13e6ee18ec49bf795", + "reference": "45c8a3845aa791b7da720fa13e6ee18ec49bf795", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-filter": "*", + "lib-pcre": ">=7.2", + "php": ">=5.4.7" + }, + "require-dev": { + "matthiasmullie/minify": "*", + "php-coveralls/php-coveralls": "*", + "s9e/regexp-builder": "1.*" + }, + "suggest": { + "ext-curl": "Improves the performance of the MediaEmbed plugin and some JavaScript minifiers", + "ext-intl": "Allows international URLs to be accepted by the URL filter", + "ext-json": "Enables the generation of a JavaScript parser", + "ext-mbstring": "Improves the performance of the PHP renderer", + "ext-tokenizer": "Improves the performance of the PHP renderer", + "ext-xsl": "Enables the XSLT renderer", + "ext-zlib": "Enables gzip compression when scraping content via the MediaEmbed plugin" + }, + "type": "library", + "autoload": { + "psr-4": { + "s9e\\TextFormatter\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Multi-purpose text formatting and markup library. Plugins offer support for BBCodes, Markdown, emoticons, HTML, embedding media (YouTube, etc...), enhanced typography and more.", + "homepage": "https://github.com/s9e/TextFormatter/", + "keywords": [ + "bbcode", + "bbcodes", + "blog", + "censor", + "embed", + "emoji", + "emoticons", + "engine", + "forum", + "html", + "markdown", + "markup", + "media", + "parser", + "shortcodes" + ], + "time": "2019-03-09T15:49:02+00:00" + }, { "name": "sensio/framework-extra-bundle", "version": "v5.2.4", diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index cc43be73..98c3c74f 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -55,7 +55,6 @@ class PartController extends AbstractController public function show(Part $part, AttachmentFilenameService $attachmentFilenameService) { $filename = $part->getMasterPictureFilename(true); - dump($filename); return $this->render('show_part_info.html.twig', [ diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index e3433d9f..3cd0e5af 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -34,22 +34,28 @@ namespace App\Twig; use App\Entity\DBElement; use App\Services\EntityURLGenerator; +use Symfony\Component\Cache\Adapter\AdapterInterface; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; +use s9e\TextFormatter\Bundles\Forum as TextFormatter; + class AppExtension extends AbstractExtension { protected $entityURLGenerator; + protected $cache; - public function __construct(EntityURLGenerator $entityURLGenerator) + public function __construct(EntityURLGenerator $entityURLGenerator, AdapterInterface $cache) { $this->entityURLGenerator = $entityURLGenerator; + $this->cache = $cache; } public function getFilters() { return [ - new TwigFilter('entityURL', [$this, 'generateEntityURL']) + new TwigFilter('entityURL', [$this, 'generateEntityURL']), + new TwigFilter('bbCode', [$this, 'parseBBCode'], ['pre_escape' => 'html', 'is_safe' => ['html']]) ]; } @@ -67,4 +73,18 @@ class AppExtension extends AbstractExtension throw new \InvalidArgumentException('method is not supported!'); } + public function parseBBCode(string $bbcode) : string + { + if($bbcode === '') return ''; + + $item = $this->cache->getItem('bbcode_' . md5($bbcode)); + if(!$item->isHit()) { + $xml = TextFormatter::parse($bbcode); + $item->set(TextFormatter::render($xml)); + $this->cache->save($item); + } + + return $item->get(); + } + } \ No newline at end of file diff --git a/symfony.lock b/symfony.lock index aa7b5bfe..c489ebf1 100644 --- a/symfony.lock +++ b/symfony.lock @@ -162,6 +162,9 @@ "psr/simple-cache": { "version": "1.0.1" }, + "s9e/text-formatter": { + "version": "1.4.1" + }, "sensio/framework-extra-bundle": { "version": "5.2", "recipe": { diff --git a/templates/show_part_info.html.twig b/templates/show_part_info.html.twig index 763e1210..a9672ec3 100644 --- a/templates/show_part_info.html.twig +++ b/templates/show_part_info.html.twig @@ -24,7 +24,7 @@
{{ part.manufacturer.name ?? ""}}

{{ part.name }}

-
{{ part.description }}
+
{{ part.description|bbCode }}
{{ part.storelocation.fullPath ?? "-"}} @@ -44,6 +44,7 @@ {{ "TODO" }}
+ {# {% if part.comment != "" %}
@@ -51,14 +52,23 @@ {{ part.comment|nl2br }}
- {% endif %} + {% endif %} #}