bnware/cakephp-bbcode

BBCode Parser

Installs: 74

Dependents: 0

Suggesters: 0

Security: 0

Type:cakephp-plugin

1.2.1 2016-03-23 14:02 UTC

This package is auto-updated.

Last update: 2024-09-17 10:11:13 UTC


README

License

A CakePHP plugin for Parsing BBCode tags

Installing via composer

You can install this plugin into your CakePHP application using composer. For existing applications you can add the following to your composer.json file:

"require": {
    "bnware/cakephp-bbcode": "*"
}

And run php composer.phar update

In your config\bootstrap.php:

Plugin::load('BBCode', ['bootstrap' => true]);

Using Internationalization & Localization

All error messages are able to be localized. You just have to use the template file in src/Locale/BBCode.pot.

Customizing tag rendering

The tags are rendered by an view cell. You can customize the rendering by defining an own view cell. The cell must contain one action for each tag. The name of the action must be the tag name with an optional preceding underscore.

You can extend the predefined tags by inheriting your view cell from the predefined one or you can define your own set of tags. To use some rendering utils, you can use the TagRendererTrait.

To configure the view cell to use, add BBCode.renderCell to your config. The value can be a class name in plugin syntax or a full qualified class name.

Calling the parser

The parser can be used in views by using the `php BBCodeHelper::render($bbCode)` method. You just have to add the BBCodeHelper in your controller:

$this->helpers[] = 'BBCode.BBCode';

You can also use the BBCodeValidator to check if user input is valid BBCode syntax. You just have to define it as validation provider and define a validation rule using this provider:

$validator->provider('BBCode', 'BBCode\Validation\BBCodeValidator');  
$validator->add('<field>', '<name>', ['provider' => 'BBCode', 'rule' => 'validate']);