sgrodzicki / fm-bbcode-bundle
Symfony FMBbCodeBundle
Requires
- php: >=5.3.2
- mjohnson/decoda: 5.*
- symfony/assetic-bundle: >=2.1,<3.0
- symfony/config: >=2.1,<3.0
- symfony/console: >=2.1,<3.0
- symfony/dependency-injection: >=2.1,<3.0
- symfony/framework-bundle: >=2.1,<3.0
- symfony/http-foundation: >=2.1,<3.0
- symfony/http-kernel: >=2.1,<3.0
- symfony/process: >=2.1,<3.0
- symfony/templating: >=2.1,<3.0
- symfony/twig-bundle: >=2.1,<3.0
- symfony/yaml: >=2.1,<3.0
Requires (Dev)
- symfony/symfony: >=2.1,<3.0
This package is not auto-updated.
Last update: 2024-09-14 14:50:17 UTC
README
PHP-Decoda 集成到 Symfony2
BBCode 风格标记的轻量级词法字符串解析器。
安装
要安装此包,您需要 Decoda 库和此包。安装取决于您的项目配置。
步骤 1:安装
使用 Composer,只需将以下配置添加到您的 composer.json
或者您可以使用 composer 安装此包:在您的 composer.json 中添加 FMBbcodeBundle
{ "require": { "helios-ag/fm-bbcode-bundle": "dev-master" } }
现在运行以下命令让 composer 下载此包
$ php composer.phar update helios-ag/fm-bbcode-bundle
步骤 2:启用包
最后,在内核中启用此包。
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new FM\BbcodeBundle\FMBbcodeBundle(), ); }
步骤 3:导出表情符号(可选)
要启用表情符号钩子,使用以下命令将表情符号图像复制到 public 文件夹(web/emoticons)
./app/console bbcode:dump
基本配置
通过更新配置使 Twig 扩展可用
By default only "default" filter enabled, which provide support
for [b], [i], [u], [s], [sub], [sup], [abbr], [br], [hr], [time]
BBCodes
在您的 Twig 模板中使用扩展的示例
在您的 config.yml 中定义 BBCode 过滤器
fm_bbcode: filter_sets: my_default_filter: locale: ru xhtml: true filters: [ default ]
然后您可以这样做
{{'[b]Bold text[/b]'|bbcode_filter('my_default_filter')}} {{'[u]Underlined text[/u]'|bbcode_filter('my_default_filter')}} {{'[i]Italic text[/i]'|bbcode_filter('my_default_filter')}}
fm_bbcode: filter_sets: my_default_filter: locale: ru xhtml: true filters: [ default, quote ] whitelist: [ b, quote ]
启用 "quote" 过滤器后,您可以这样做
{{'[quote="helios"]My quote[/quote]'|bbcode_filter('my_default_filter')}}
您还可以在 filter_sets 参数下定义多个过滤器集合,如下所示
fm_bbcode: filter_sets: my_forum_filter: locale: ru xhtml: true filters: [ default, quote ] whitelist: [ b, quote ] my_comment_filter: locale: ru xhtml: true filters: [ default, block, code, email, image, list, quote, text, url, video ]
{{'[quote="helios"]My quote[/quote]'|bbcode_filter('my_forum_filter')}} {{'[code]My source code[/code]'|bbcode_filter('my_comment_filter')}}
请注意,白名单标签将抑制过滤器配置中应用的标签。
清除过滤器
要清除文本中的任何 BBCodes,请使用 bbcode_clean 过滤器:示例
{{'[b]some text[/b]'|bbcode_clean}}
此过滤器将消除所有已知给 Decoda 的标签。
高级配置
覆盖消息
一些模板和钩子使用可以翻译成不同语言的文本字符串,原始文件位于 decoda/config 目录下,但此文件的内容可以用 messages 选项下的消息覆盖,文件应为 json 格式。
fm_bbcode: config: messages: @SomeBundle/Resources/config/messages.json
添加自己的模板
您可以在 templates 节下定义自己的模板,下面的示例展示了如何做
fm_bbcode: config: templates: - path: @SomeBundle/Resources/views/templates
模板示例可以在 decoda 库内部找到
添加自己的过滤器
要启用自定义过滤器,将其作为常规服务添加到您的配置之一,并使用 fm_bbcode.decoda.filter
标签
services: acme_demo.decoda.filter.your_filter_name: class: Fully\Qualified\Filter\Class\Name tags: - { name: fm_bbcode.decoda.filter, id: your_filter_name }
您的服务必须实现 Decoda\Filter
接口。
如果您的服务是通过工厂创建的,您必须正确设置此标签的 class 参数,以确保其正确工作。
添加自己的钩子
要启用自定义钩子,将其作为常规服务添加到您的配置之一,并使用 fm_bbcode.decoda.hook
标签
services: acme_demo.decoda.hook.your_hook_name: class: Fully\Qualified\Hook\Class\Name tags: - { name: fm_bbcode.decoda.hook, id: your_hook_name }
您的服务必须实现 Decoda\Hook
接口。
如果您的服务是通过工厂创建的,您必须正确设置此标签的 class 参数,以确保其正确工作。
自定义表情符号
您可以在 emoticon
节下定义自己的表情符号,下面的示例展示了如何做
fm_bbcode: emoticon: resource: path/to/emoticons.yml
# path/to/emoticons.yml imports: - { resource: path/to/another/emoticons.yml } emoticons: my_emoticon: url: # Default: %fm_bbcode.emoticon.path%/my_emoticon.png html: # Default: <img src="%fm_bbcode.emoticon.path%/my_emoticon.png" alt="" > xHtml: # Default: <img src="%fm_bbcode.emoticon.path%/my_emoticon.png" alt="" /> smilies: - ":my_emoticon:"
贡献者
- Gaiffe Antoine toinouu
- Luis Íñiguez idetia
- Sebastian slider
- olleyyy
- Dirk Olbertz dolbertz
- Florian Krauthan fkrauthan
- predakanga
- Dan piratadelfuturo
- 亚历山大·奎西亚 alquerci