hisorange / bbcoder
此包已被放弃,不再维护。未建议替代包。
此包最新版本(dev-master)没有可用的许可信息。
将开发良好的 Decoda 仓库添加到 Laravel 4。
dev-master
2014-01-23 02:06 UTC
Requires
- php: >=5.3.0
- illuminate/support: 4.*
- mjohnson/decoda: 6.*
This package is auto-updated.
Last update: 2021-06-13 21:26:48 UTC
README
将开发良好的 Decoda 仓库添加到 Laravel 4,进行了一些小修改。仓库包含 Decoda 的基本功能,并扩展了配置配置文件。
查看使用方法
// Simply convert the string with the default profile. echo BBCoder::convert('This is an [b]example[/b]! But [i]this[/i] is just the beggining...'); // Conver the string with a differnt profile initialized. echo BBCoder::convert('In the forum [quote]quote[/quote] tags are allowed.', 'forum');
创建配置文件
// config/packages/hisorange/bbcoder/config <?php return array( 'profiles' => array( 'default' => array( // ... ), // Comments profile. 'comments' => array( // Under the 'comments' profile only the <u> <i> <b> html tags will be allowed. 'whitelist' => array('u', 'i', 'b'), // You can overwrite which filters being loaded. 'filters' => array( 'Decoda\Filter\DefaultFilter', 'Decoda\Filter\TextFilter', ), ), ), );
配置文件继承默认配置的值。当你创建新的配置文件时请小心,因为配置不会递归合并。这意味着当你创建一个配置文件,例如:pageedit
错误方式
'parser' => array( 'open' => '{', 'close' => '}', ),
这将覆盖默认配置的 'parser' 值,但会删除其他键。
正确方式
'parser' => array( 'open' => '{', 'close' => '}', 'locale' => 'en-us', 'disabled' => false, 'shorthandLinks' => false, 'xhtmlOutput' => false, 'escapeHtml' => true, 'strictMode' => true, 'maxNewlines' => 3, 'lineBreaks' => true, 'removeEmpty' => false ),
这是必要的,因为在需要仅添加 'b' 标签到白名单的情况下,但如果默认允许 'quote' 标签,则 array_merge 可能会导致数组('b', 'quote'),而你只想允许 'b' 标签。
配置文件继承默认的 config.php 值。
额外的配置文件
在配置目录中可以找到 censored.php、emoticons.php、messages.php,它们的工作方式与 Decoda 描述的完全相同。
重置/使用默认配置
// Use the forum profile for the converting. echo BBCoder::convert('[spoiler]Do not show me, I am naked![/spoiler]', 'forum'); // To reset back to the original profile simply use the null. // But if the null is not passed the script will use the last used profiled 'forum' in this case. echo BBCoder::convert('[spoiler]Do not show me, I am naked![/spoiler]', null);
与 Decoda\Decoda 对象一起工作
如果你需要与原始类交互,只需在 BBCoder 上调用它即可。
BBCoder::getHook('Emoticon');
安装/Composer
将以下行添加到你的 composer.json 中
"require": { "hisorange/bbcoder": "dev-master" }
将 ServiceProvider 添加到配置目录中的 app.php
'providers' => array( // .. other providers .. 'hisorange\bbcoder\Providers\BBCoderServiceProvider', )
此包将自动将 BBCoder 别名注册到你的应用程序中。
别忘了发布包配置。
php artisan config:publish hisorange/bbcoder
有关 BB Code 解析器配置的更多信息,请参阅 milesj/decoda 仓库 <3