Closed remontees closed 11 years ago
I don't use twig, so the part of the personalized Filters maybe is not compatible, I think I will have to write a little document for the personalized filters, my config looks like this:
fm_bbcode:
config:
filters:
- { classname: boom_video, class: \Boom\Bundle\FrontBundle\Decoda\Filter\BoomVideoFilter }
- { classname: boom_gallery, class: "@boom_front.gallery.decoda.filter" }
templates:
- path: %kernel.root_dir%/Resources/Decoda/templates/
filter_sets:
default:
locale: es
xhtml: true
filters: [ default, quote, url, image, boom_video, boom_gallery, list, li, olist, p]
If you see there is a section named filters
where you can pass classnames or service references.
Yes, but Filters class. How I can write them ?
For that you will have to take a look at the current filters that come from PHP-Decoda
Oh @helios-ag already wrote the tutorial, thanks :)
Because I've done this code : public function galerieParse($code) { // PARSE REGEX $code = preg_replace_callback('#[galerie][photo]\/(\w+)\/([^\/]+)\/([0-9]+).([a-z]{3})[\/photo][\/galerie]#', array($this,'photoCallback'), $code);
$code = preg_replace_callback('#\[galerie\]\[photo\]\/(\w+)\/([^\/]+)\/([0-9]+)\.([a-z]{3})\[\/photo\]\[legende\](\w+)\[\/legende\]\[\/galerie\]#', array($this,'photoCallback2'), $code);
return $code;
}
public function photoCallback($code)
{
if(file_exists(__DIR__ . '/../../../../web/uploads/galerie/' . $code[1] . '/photo_' . $code[3] . '.' . $code[4]))
{
return '<img src="/' . $code[1] . '/' . $code[2] . '/photo_' . $code[3] . '.' . $code[4] . '" alt="Galerie photo" />';
}
return __DIR__ . '/../../../../web/uploads/galerie/' . $code[1] . '/photo_' . $code[3] . '.' . $code[4];
}
public function photoCallback2($code)
{
if(file_exists($_SERVER['DOCUMENT_ROOT'] . '/' . $code[1] . '/' . $code[2] . '/photo_' . $code[3] . '.' . $code[4]))
{
return '<figure><img src="/' . $code[1] . '/' . $code[2] . '/photo_' . $code[3] . '.' . $code[4] . '" alt="' . $code[5] . '" /><figcaption>' . $code[4] . '</figcation></figure>';
}
return null;
}
But I don't know how I can integrate this to FMBbCodeBundle. The documentation doesn't tell it very well.
Here is my code :
fm_bbcode:
config:
hooks:
- { classname: galerie, class: \Rms\GalerieBundle\Service\RmsGalerieBBCode }
filter_sets:
bbcode_basic:
locale: ru
xhtml: true
filters: [ default, block ]
bbcode_forum:
locale: ru
xhtml: true
filters: [ default, block, image, list, quote, text, url ]
bbcode_reportages:
locale: ru
xhtml: true
filters: [ default, block, image, list, quote, text, url, galerie ]
But it doesn't work. galerie doesn't work. Here is my hook :
<?php
namespace Rms\GalerieBundle\Service;
use mjohnson\decoda\Decoda;
use mjohnson\decoda\hooks\HookAbstract;
/**
* Système pour parser les photos de la galerie photo
*
* @author remontees
*/
class GalerieHook extends HookAbstract
{
public function beforeParse($content)
{
return galerieParse($content);
}
/**
* Parse la photo de la galerie
*
* @param string $code
*/
public function galerieParse($code)
{
// PARSE REGEX
$code = preg_replace_callback('#\[galerie\]\[photo\]\/(\w+)\/([^\/]+)\/([0-9]+)\.([a-z]{3})\[\/photo\]\[\/galerie\]#', array($this,'photoCallback'), $code);
$code = preg_replace_callback('#\[galerie\]\[photo\]\/(\w+)\/([^\/]+)\/([0-9]+)\.([a-z]{3})\[\/photo\]\[legende\](\w+)\[\/legende\]\[\/galerie\]#', array($this,'photoCallback2'), $code);
return $code;
}
public function photoCallback($code)
{
if(file_exists(__DIR__ . '/../../../../web/uploads/galerie/' . $code[1] . '/photo_' . $code[3] . '.' . $code[4]))
{
return '<img src="/' . $code[1] . '/' . $code[2] . '/photo_' . $code[3] . '.' . $code[4] . '" alt="Galerie photo" />';
}
return __DIR__ . '/../../../../web/uploads/galerie/' . $code[1] . '/photo_' . $code[3] . '.' . $code[4];
}
public function photoCallback2($code)
{
if(file_exists($_SERVER['DOCUMENT_ROOT'] . '/' . $code[1] . '/' . $code[2] . '/photo_' . $code[3] . '.' . $code[4]))
{
return '<figure><img src="/' . $code[1] . '/' . $code[2] . '/photo_' . $code[3] . '.' . $code[4] . '" alt="' . $code[5] . '" /><figcaption>' . $code[4] . '</figcation></figure>';
}
return null;
}
}
For filter development you should read PHP-Decoda, FMBbCodeBundle uses PHP-Decoda 3.x, I think you are making a filter for 4.x
Check both packages documentation.
And where is the doc for 3.x ?
Select appropriate branch in php-decoda repository.
And i think that checking files for existence in your filter is bad idea.
Yes, but I can't find also the documentation for 3.x branch. But Hooks are the good solution to integrate my work ? You could add this in the doc, isn't it ?
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 ?