mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Render Comment and description as BBCode.
This commit is contained in:
parent
daad7ec60a
commit
3da6b03b23
7 changed files with 114 additions and 8 deletions
1
.idea/php.xml
generated
1
.idea/php.xml
generated
|
@ -119,6 +119,7 @@
|
|||
<path value="$PROJECT_DIR$/vendor/nikolaposa/version" />
|
||||
<path value="$PROJECT_DIR$/vendor/shivas/versioning-bundle" />
|
||||
<path value="$PROJECT_DIR$/vendor/friendsofsymfony/ckeditor-bundle" />
|
||||
<path value="$PROJECT_DIR$/vendor/s9e/text-formatter" />
|
||||
</include_path>
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="7.1" />
|
||||
|
|
|
@ -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.*",
|
||||
|
|
67
composer.lock
generated
67
composer.lock
generated
|
@ -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",
|
||||
|
|
|
@ -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',
|
||||
[
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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": {
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<div class="col-md-9">
|
||||
<h5 class="text-muted pt-2" title="{% trans %}manufacturer.label{% endtrans %}">{{ part.manufacturer.name ?? ""}}</h5>
|
||||
<h3>{{ part.name }} <a href="{{ part|entityURL('edit') }}"><i class="fas fa-fw fa-sm fa-edit"></i></a></h3>
|
||||
<h6 class="text-muted"><span title="{% trans %}description.label{% endtrans %}">{{ part.description }}</span></h6>
|
||||
<h6 class="text-muted"><span title="{% trans %}description.label{% endtrans %}">{{ part.description|bbCode }}</span></h6>
|
||||
<h6 class="" title="{% trans %}storelocation.label{% endtrans %}">
|
||||
<i class="fas fa-cube fa-fw"></i>
|
||||
<span class="text-muted">{{ part.storelocation.fullPath ?? "-"}}</span>
|
||||
|
@ -44,6 +44,7 @@
|
|||
<i class="fas fa-money-bill-alt fa-fw"></i>
|
||||
<span class="text-muted">{{ "TODO" }}</span>
|
||||
</h6>
|
||||
{#
|
||||
{% if part.comment != "" %}
|
||||
<h6 title="{% trans %}comment.label{% endtrans %}">
|
||||
<i class="fas fa-comment-alt fa-fw"></i>
|
||||
|
@ -51,14 +52,23 @@
|
|||
<span class="text-muted">{{ part.comment|nl2br }}</span>
|
||||
</div>
|
||||
</h6>
|
||||
{% endif %}
|
||||
{% endif %} #}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
<ul class="nav nav-tabs" id="partTab" role="tablist">
|
||||
{% if part.comment is not empty %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" id="attachment-tab" data-toggle="tab"
|
||||
href="#comment" role="tab" aria-controls="home" aria-selected="true">
|
||||
<i class="fas fa-comment-alt fa-fw"></i>
|
||||
{% trans %}comment.label{% endtrans %}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if part.comment is empty%} active{% endif %}" id="attachment-tab" data-toggle="tab"
|
||||
href="#attachments" role="tab" aria-controls="home" aria-selected="true">
|
||||
<i class="fas fa-paperclip fa-fw"></i>
|
||||
{% trans %}attachment.labelp{% endtrans %}
|
||||
|
@ -84,8 +94,15 @@
|
|||
</li>
|
||||
</ul>
|
||||
<div class="tab-content" id="myTabContent">
|
||||
<div class="tab-pane fade show active" id="attachments" role="tabpanel" aria-labelledby="home-tab">
|
||||
|
||||
{% if part.comment is not empty %}
|
||||
<div class="tab-pane fade show active" id="comment" role="tabpanel" aria-labelledby="home-tab">
|
||||
<div class="container-fluid mt-2">
|
||||
{{ part.comment|bbCode }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="tab-pane fade {% if part.comment is empty %} show active{% endif %}" id="attachments" role="tabpanel" aria-labelledby="profile-tab">
|
||||
Test
|
||||
</div>
|
||||
<div class="tab-pane fade" id="suppliers" role="tabpanel" aria-labelledby="profile-tab">
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue