Coder Social home page Coder Social logo

fmbbcodebundle's Introduction

FMBBCodeBundle

PHP-Decoda integration in Symfony2

A lightweight lexical string parser for BBCode styled markup.

Contributors

Code Quality Assurance

SLInsight Travis CI Gitter Coverage StyleCI
SensioLabsInsight Build Status Join the chat at https://gitter.im/helios-ag/FMBbCodeBundle Coverage Status StyleCI
Deps Status Version Downloads
Dependency Status Latest Stable Version Total Downloads

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

Using Composer, just add the following configuration to your composer.json:

Or you can use composer to install this bundle:

For symfony <3.0, use latest ~6 version

composer require helios-ag/fm-bbcode-bundle:~6

for Symfony 3

composer require helios-ag/fm-bbcode-bundle

or

composer require helios-ag/fm-bbcode-bundle:~7

Step 2: Enable the bundle

Finally, enable the bundle in the kernel:

<?php
// app/AppKernel.php

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

Step 3: Dump emoticons (optional)

To enable emoticons via emoticon hook, use the following command to copy emoticons images to public folder (web/emoticons)

    ./app/console bbcode:dump

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], [abbr], [br], [hr], [time]
BBCodes

Examples to use the extension in your Twig template

Define BBCode filter in your config.yml:

    fm_bbcode:
      filter_sets:
        my_default_filter:
          strict: false # if you want to parse attr values without quotes
          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 suppress tags, that applied by filters configuration.

Strip filter

To clear text from any bbcodes use bbcode_clean filter: example:

{{'[b]some text[/b]'|bbcode_clean}}

This filter will eliminate any known to decoda tags

Escaping and line breaks

Escaping and line breaks can be controlled via "escaping" and "line_breaks" parameters under filter configuration. Default configuration for them is 'true'. If you wish to pipeline filters, set escaping to false.

Advanced configuration

Overriding messages

Some templates and hooks, use text strings, that can be translated into different languages, the original file located under decoda/config directory, but content of this file can be overriden with messages option, under messages: node. File should be json formatted.

fm_bbcode:
    config:
      messages: @SomeBundle/Resources/config/messages.json

Adding own templates

Your own templates can be defined at templates node, the example below shows how:

    fm_bbcode:
        config:
          templates:
            - path: @SomeBundle/Resources/views/templates

Template examples can be found inside decoda library

Adding own filter

To enable a custom filter, add it as a regular service in one of your configuration, and tag it with 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 }

Your service must implement the Decoda\Filter interface.

If your service is created by a factory, you MUST correctly set the class parameter for this tag to work correctly.

Adding own hook

To enable a custom hook, add it as a regular service in one of your configuration, and tag it with 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 }

Your service must implement the Decoda\Hook interface.

If your service is created by a factory, you MUST correctly set the class parameter for this tag to work correctly.

Then enable it in your configuration:

    fm_bbcode:
      filter_sets:
        my_default_filter:
          filters: [ default ]
          hooks: [ your_hook_name ]

Customize your own emoticons

Your own emoticons can be defined at emoticon node, the example below shows how:

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:"

How to automatically dump emoticons on each deploy

Add the following commands to you projects composer.json:

# composer.json
    "scripts": {
        "post-install-cmd": [
            "FM\\BbcodeBundle\\Composer\\ScriptHandler::installEmoticons"
        ],
        "post-update-cmd": [
            "FM\\BbcodeBundle\\Composer\\ScriptHandler::installEmoticons"
        ]
    }

To customize emoticons assets folders, use path and folder node configuration:

# app/config.yml

fm_bbcode:
  emoticon:
    path:   # Default: /emoticons
    folder: # Default: %kernel.root_dir%/../vendor/mjohnson/decoda/emoticons%

fmbbcodebundle's People

Contributors

alquerci avatar bitdeli-chef avatar dependabot-preview[bot] avatar dzunke avatar fkrauthan avatar helios-ag avatar idetia avatar lgiraudel avatar mellivora-capensis avatar nelrann avatar olleyyy avatar piratadelfuturo avatar predakanga avatar slider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fmbbcodebundle's Issues

Add the ability to apply multiple filter on a string

hello @helios-ag

I have a little problem, I'd like to apply multiple filters on a string like this:

string | bbcode_filter ('emoticons') | bbcode_filter ('layout')
or
string |bbcode_filter(['emoticons', 'layout'])

but string is automatically escaped 2 times

How can I manage this?

Thx

Bundle installation

Procedure given in the help appears to be wrong.

I'm trying to install this bundle but without any success. Case sensitive commands are present.

I cannot success in loading the bundle and their configuration parameters.

Regards.

Retrieve the emoticons list

I would like to show emoticons above textarea
it would be nice to be able to retrieve the list of emoticons contained in emoticons.json file

Is it possible to overload emoticons.json file ?

Error with LoaderInterface

PHP Fatal error: Can't inherit abstract function Symfony\Component\Config\Loader\LoaderInterface::load() (previously declared abstract in FM\BbcodeBundle\Translation\Loader\FileLoader) in /home/stardown/vendor/helios-ag/fm-bbcode-bundle/FM/BbcodeBundle/Translation/Loader/FileLoader.php on line 41

Fatal error: Can't inherit abstract function Symfony\Component\Config\Loader\LoaderInterface::load() (previously declared abstract in FM\BbcodeBundle\Translation\Loader\FileLoader) in /home/stardown/vendor/helios-ag/fm-bbcode-bundle/FM/BbcodeBundle/Translation/Loader/FileLoader.php on line 41

Strict option has no effect

when I try to put color like this: [color=#ccc] it does not work
but when I do it [color = "#ccc"] it works.

I use the strict false option

Error on cache:clear

I get the following error message with the new dev-master versions on cache:clear

Fatal error: Can't inherit abstract function Symfony\Component\Config\Loader\LoaderInterface::load()
(previously declared abstract in FM\BbcodeBundle\Translation\Loader\FileLoader)
in /var/www/symfony/vendor/helios-ag/fm-bbcode-bundle/FM/BbcodeBundle/Translation/Loader/FileLoader.php on line 41

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception

Any ideas?

Use custom smileys

I would like to override default emoticons but when I try i get

"The smiley ":)" already exists."

It would be nice to have ability to define our smileys :)

What hooks and filters must have the default decoda parser ?

Currently it is defined on Decoda\Decoda::default() with these filters and hooks:

    public function defaults() {
        $this->addFilter(new \Decoda\Filter\DefaultFilter());
        $this->addFilter(new \Decoda\Filter\EmailFilter());
        $this->addFilter(new \Decoda\Filter\ImageFilter());
        $this->addFilter(new \Decoda\Filter\UrlFilter());
        $this->addFilter(new \Decoda\Filter\TextFilter());
        $this->addFilter(new \Decoda\Filter\BlockFilter());
        $this->addFilter(new \Decoda\Filter\VideoFilter());
        $this->addFilter(new \Decoda\Filter\CodeFilter());
        $this->addFilter(new \Decoda\Filter\QuoteFilter());
        $this->addFilter(new \Decoda\Filter\ListFilter());

        $this->addHook(new \Decoda\Hook\CensorHook());
        $this->addHook(new \Decoda\Hook\ClickableHook());
    }

Sets on FM\BbcodeBundle\Decoda\DecodaManager::get()

Probably it's better to add all available filters and hooks.

Apply hook problem.

Please check: FM\BbcodeBundle\Decoda\DecodaManager.php line 129.
I think there must be: "$code->addHook($extra_hook);".

Thank you.

fm_bbcode.emoticon.path not used for img tag

Hi. When I set something like this:

fm_bbcode:
emoticon:
path: '/path/to/my/emoticons/'

I can run bbcode:dump, and the icons show up on that path. However, when applying my filter (via twig), the src of the img tag will be the default /emoticons/ path, like so:

img src="/emoticons/happy.png" alt=""

Shouldn't the fm_bbcode.emoticon.path be used here?

[broken] post-install-cmd and post-update-cmd wrong parameters

After I added this line in post-install-cmd and post-update-cmd :
"FM\BbcodeBundle\Composer\ScriptHandler::installEmoticons"

I get this error :
[ErrorException]
Argument 1 passed to Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::getOptions() must be an instance of Composer\Script\CommandEvent, instance of Composer\Script\Event given, called in ...\vendor\helios-ag\fm-bbcode-bundle\Composer\ScriptHandler.php on line 16 and defined

Quote and Code tags do not seem to work.

Is there an issue with using code and quote tags, or some kind of special use case?

Same for smilies, i see it in the readme, but its not really documented.

I added it to my white list. But it just spits out the tag as it was put in.

# app/config/config.yml
fm_bbcode:
    filter_sets:
        forum_post_filter:
            locale: en
            xhtml: true
            filters: [ default ]
            whitelist: [ default, b, u, i, list, quote, code, text, url, email, image, video ]
{{ post.getBody | bbcode_filter('forum_post_filter') }}

Input examples.

code

[code]foo[/code]

[CODE]foo[/CODE]

[CODE=C++]#include std:io[/CODE]

quote

[QUOTE=Reece] blah blah blah blah...[/QUOTE]

[QUOTE]foo and bar[/QUOTE]

[quote]foo bar[/quote]

Comes out same as it went in. Bold, Italics and Underline seem to be working just fine though.

Otherwise, if everything works fine, then is there a means to define your own tags and its counter part html?

Add strict option

It is possible to add strict mode in option ?

Thx !

http://milesj.me/code/php/decoda

fm_bbcode:
filter_sets:
my_default_filter:
strict: true/false
xhtml: true

Strict Mode
When strict mode is enabled, all tag attributes will be required to use double quotes. When disabled, attributes with and without wrapping double quotes will be parsed.

$code->setStrict(true);

class 'FM\BbCodeBundle\Decoda\Decoda' does not have a method '_loadFile'

Hi!
Recently I upgraded Symfony2 to version 2.0.9 and Doctrine2 to version 2.2.0 - and started receiving errors:

An exception has been thrown during the rendering of a template ("Passed array does not specify an existing method (class 'FM\BbCodeBundle\Decoda\Decoda' does not have a method '_loadFile')") in Ser5FooBundle:Div:list.html.twig at line 16.

I tried to change this line
spl_autoload_register(array($this, '_loadFile'));
to
spl_autoload_register(array($this, 'loadFile'));
and everything went fine.

BTW, thanks for a nice bundle =)

Fresh install via composer does not find decoda

I hate this issue as this error is there since the first release of the FMBbCodeBundle.

I get:

PHP Fatal error:  Class 'mjohnson\decoda\Decoda' not found in /Users/ck/Private/proj1/vendor/helios-ag/fm-bbcode-bundle/FM/BbcodeBundle/Decoda/Decoda.php on line 9

Fatal error: Class 'mjohnson\decoda\Decoda' not found in /Users/ck/Private/proj1/vendor/helios-ag/fm-bbcode-bundle/FM/BbcodeBundle/Decoda/Decoda.php on line 9

After installing via composer.

../composer.phar update
Loading composer repositories with package information
Updating dependencies
  - Installing mjohnson/decoda (dev-master 62e3161)
    Cloning 62e316134eeb457c0fafc8cdc6ff0810922732ae

  - Installing helios-ag/fm-bbcode-bundle (dev-master 4ff68d5)
    Cloning 4ff68d52796e52cc466dbc01b68531cc8f2f8bb3

[Insight] The Symfony Dependency Injection Container should not be passed as an argument - in Decoda/Hook/EmoticonHook.php, line 56

in Decoda/Hook/EmoticonHook.php, line 56

A Symfony dependency injection container has been found as an argument.

     *
     * @param LoaderInterface $loader   A LoaderInterface instance
     * @param mixed           $resource The main resource to load
     * @param array           $options  An array of options
     */
    public function __construct(LoaderInterface $loader, ContainerInterface $container, array $options = array())
    {
        $this->loader    = $loader;
        $this->container = $container;
        $this->setOptions($options);

Posted from SensioLabsInsight

[url] bbcode requires quotes to be filtered

It seems that the URL filter requires the bbcode to use quotes to mark it as a URL correctly.

For example:

[url=www.google.com]www.google.com[/url] - does not work
[url="www.google.com"]www.google.com[/url] - works!

Per all bbcode standards I have seen, the url bbcode does not require quotations.

http://www.bbcode.org/examples/?id=9

Is there a way to use the more standard url bbcode syntax or am I doing something wrong?

EDIT: The reason I need this is that I am doing a forum migration from an old platform to symfony and all of the old post use the non-quoted url bbcode.

Thanks!

Incompatible composer.json with Symfony 2.5

When running composer update I get the following error:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - helios-ag/fm-bbcode-bundle dev-master requires sensio/distribution-bundle ~2.1 -> no matching package found.
    - helios-ag/fm-bbcode-bundle dev-master requires sensio/distribution-bundle ~2.1 -> no matching package found.
    - helios-ag/fm-bbcode-bundle dev-master requires sensio/distribution-bundle ~2.1 -> no matching package found.
    - Installation request for helios-ag/fm-bbcode-bundle dev-master -> satisfiable by helios-ag/fm-bbcode-bundle[dev-master].

This seems to be because the bundle has a hard require on version 2.1 of the distribution bundle and Symfony 2.5 upgraded the distribution bundle to 3.0.

Problem loading emoticons

When I use master branch on the first page loading (without cache) I get my emoticons with getEmoticonCollection function.

But when I reload the page the function returns an empty array.

How to use bbcode_clean directly in controller ?

Hello,
I have a new question about your bundle !
I would like to use the bbcode_clean filter directly in a controller, without using any twig view.
I think there is a proper way to call it in a Symfony controller...

bbcode_clean escape all HTML

{{ post.text | bbcode_filter('forum') | bbcode_clean | raw }}

It parse bbcode and clear other bbcode I don't want to support yet it returns plain HTML as text

problem recognizing decoda Class

i get a fatal error when pasting some testcode into my base.twig.html
{{'[b]Bold text[/b]'|BBCode}}

Fatal error: Class 'Decoda' not found in C:\Program Files (x86)\Zend\Apache2\htdocs\myproject\vendor\bundles\FM\BbCodeBundle\Twig\Extension\BbCodeHelperExtension.php on line 92

the class Decoda is inside the autoload.php and recognized well using my IDE (Zend Studio/Ecplise PDT).

Dump emoticons on install bundle

When install bundle, we are forced to dump the emoticons, so, to each deployment, I raise.

is it possible to automate this?

thank you

Create personalised filters

Hello,

I tried to use a personalised filter to FMBbCodeBundle, but my Twig Filter don't run with your bundle. And in the doc, there is no documentation to create personalised Filters for this bundle. What can I do ?

List of availableBBCodes

Hi,

I would like to see the list of all available BBCodes.Where are they located?
Can anyone tell, I looked for them in the repository but didn't find anything.

Thanks for your help :)

Error with new PHPDecoda

Hello,

I've updated FMBbCodeBundle this afternoon. When I go to a view who use this bundle, I've this error : Fatal error: Class 'mjohnson\decoda\Decoda' not found in /var/www/Symfony/vendor/helios-ag/fm-bbcode-bundle/FM/BbcodeBundle/Decoda/Decoda.php on line 8

What's it ? It's a little bug ?

Thanks,

remontees

Error with Emoticons

PHP Fatal error: Class 'Decoda\Hook\EmoticonHook' not found in /var/www/Symfony2.1/vendor/helios-ag/fm-bbcode-bundle/FM/BbcodeBundle/Decoda/Hook/EmoticonHook.php on line 28

Fatal error: Class 'Decoda\Hook\EmoticonHook' not found in /var/www/Symfony2.1/vendor/helios-ag/fm-bbcode-bundle/FM/BbcodeBundle/Decoda/Hook/EmoticonHook.php on line 28

Emoticons error

I've dumped the emoticons with the command.
And he can't found the image with the url who are generated.

It's always Not Found.

Bug on translation BBCode to Xhtml

Hello,

I've tried to parse this BBCode :

[h1]Titototo[/h1]
[h2]Tutu[/h2]
[center][i]Youpi[/i]
[list]
[*]Tralala
[*]Liluolo
[list]
[*]Trululu[/list][/list][/center]

And the XHTML response :

 <p></p><h1>Titototo</h1><br>
 <h2>Tutu</h2><br>
 <div class="align-center"><em>Youpi</em><br>
 <ul class="decoda-list"></ul></div><p></p>

The list were not parsed.

Bug adding custom hooks?

I have had an exception while trying to add a custom hook method so I can have a separate censored.txt - not one hardcoded from the CONFIG define.
I have the following in config:
fm_bbcode:
config:
hooks:
mensor:
class: WR\CommentBundle\Markup\Censor
classname: Censora
filter_sets:
my_forum_filter:
locale: en
xhtml: true
filters: [ default, quote ]
whitelist: [ b, quote ]
my_comment_filter:
locale: en
xhtml: true
filters: [ default, block, code, list, quote, text, url, link, color ]
hooks: [ Censora ]

I have copied and modified Censor Hook but I get: Catchable Fatal Error: Argument 1 passed to Decoda::addFilter() must be an instance of DecodaFilter, instance of WR\CommentBundle\Markup\Censor given, called in /home/valqk/projects/mysite.com/vendor/bundles/FM/BbcodeBundle/Decoda/DecodaManager.php on line 114 and defined in /home/valqk/projects/mysite.com/vendor/php-decoda/decoda/Decoda.php line 193

after changing line 193 from:
$code->addFilter(new static::$extra_hooks$hook);
to
$code->addHook(new static::$extra_hooks$hook);
it started working.
I suppose it's just a typo but anyway...

exception

An exception has been thrown during the rendering of a template ("Warning: file_get_contents(../Resources/config/messages.json): failed to open stream: No such file or directory in /home/toinou/Sites/rencontre/vendor/helios-ag/fm-bbcode-bundle/FM/BbcodeBundle/Decoda/Decoda.php line 49")

fm_bbcode:
filter_sets:
profile:
xhtml: true
strict: false
filters: [default, block, code, email, image, list, quote, text, url, video ]

Locale configuration

By default, the locale configuration is set to "ru-ru", i had to set it to "fr-fr" in the configuration to get it working in my language.

First, "xx-xx" is a weird format for a locale.

Second, can't the bundle just use the current SF locale ?

My best workaround for now is :

fm_bbcode:
    filter_sets:
        forum:
            locale: %locale%-%locale%

But i think the bundle should be able to do that automatically.

How to use the template option ?

Hello everyone, I don't know if I'm posting this message in the right place...
But I would like to know how to use the template option in the config.yml file.
For example, I would like to overwrite the video.php template provided by decoda and we have only the ability to add a template file according to the documentation. I think some options are missing.
Any help would be appreciated !

Bug on translation BBCode to Xhtml

Hello,

I've tried to parse this BBCode :

[h1]Titototo[/h1]
[h2]Tutu[/h2]
[center][i]Youpi[/i]
[list]
[*]Tralala
[*]Liluolo
[list]
[*]Trululu[/list][/list][/center]

And the XHTML response :

 <p></p><h1>Titototo</h1><br>
 <h2>Tutu</h2><br>
 <div class="align-center"><em>Youpi</em><br>
 <ul class="decoda-list"></ul></div><p></p>

The list were not parsed.

helper missing namespaces use

It seems there is an error with the namespace usage:

Fatal error: Class 'FM\BbcodeBundle\Templating\Helper\Decoda' not found in /Users/daniel/Sites/sevenboom/Src/symfony/vendor/helios-ag/fm-bbcode-bundle/FM/BbcodeBundle/Templating/Helper/BbcodeHelper.php on line 32

This should be added:

use FM\BbcodeBundle\Decoda;
use FM\BbcodeBundle\DecodaManager;

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.