Giter Site home page Giter Site logo

fmbbcodebundle's Introduction

PHP-Decoda integration in Symfony2

A lightweight lexical string parser for BBCode styled markup.

Installation

To install this bundle, you'll need both the Decoda library and this bundle. Installation depends on how your project is setup:

Step 1: Installation

Add the following lines to your deps file

[php-decoda]
    git=http://github.com/milesj/php-decoda.git

[FMBbcodeBundle]
    git=http://github.com/helios-ag/FMBbCodeBundle.git
    target=bundles/FM/BbcodeBundle

Run the vendors script::

./bin/vendors install

Or you can use composer to install this bundle: Add FMBbcodeBundle in your composer.json:

{
    "require": {
        "helios-ag/fm-bbcode-bundle": "*"
    }
}

Now tell composer to download the bundle by running the command:

$ php composer.phar update helios-ag/fm-bbcode-bundle

Step 2: Configure the autoloader

Add the following entries to your autoloader:

<?php
// app/autoload.php

$loader->registerNamespaces(array(
    // ...
       'FM' => __DIR__.'/../vendor/bundles',
        // your other namespaces
    ));

$loader->registerPrefixes(array(
    //...
       'Decoda' => __DIR__.'/../vendor/php-decoda/decoda',
    // your other libraries
    ));

Step 3: Enable the bundle

Finally, enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new FM\BbcodeBundle\FMBbcodeBundle(),
    );
}

Basic configuration

Make the Twig extensions available by updating your configuration:

By default only "default" filter enabled, which provide support
for [b], [i], [u], [s], [sub], [sup] BBCodes

Examples to use the extension in your Twig template

Define BBCode filter in your config.yml:

    fm_bbcode:
      filter_sets:
        my_default_filter:
          locale: ru
          xhtml: true
          filters: [ default ]

And you can do the following:

     {{'[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 ]

After enabling "quote" filter, you can do such things:

      {{'[quote="helios"]My quote[/quote]'|bbcode_filter('my_default_filter')}}

Also you can define multiple filter sets under filter_sets parameter like this:

    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')}}

Please keep in mind, that whitelist tags overrides filters configuration.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.