['html']]),
new TwigFilter('post', [$this, 'post'], ['is_safe' => ['html']]),
];
}
public function comment($text)
{
$text = htmlspecialchars(trim($text)).' ';
$text = preg_replace_callback(
'`(s?(http|ftp|irc)+s?://[^\s\)]+)(\s|\))+`iU',
function ($data) {
return sprintf('%s%s', htmlspecialchars($data[1]), htmlspecialchars($data[1]), $data[3]);
},
$text
);
return nl2br($text);
}
public function post($text)
{
$text = str_replace('http://upload.deblan.fr', 'https://upload.deblan.org', $text);
$text = str_replace('http://dedi.geneweb.fr', 'http://kim.deblan.fr', $text);
$text = str_replace('http://mediaplayer.deblan.fr', 'https://mediaplayer.deblan.org', $text);
$text = str_replace('http://blog.deblan.fr', 'https://www.deblan.io', $text);
$text = str_replace('http://www.deblan.tv', 'https://www.deblan.io', $text);
$text = preg_replace_callback(
'`
]*)>(.*)
]*)>`isU',
function ($data) {
if (preg_match('`^[ ]+`', $data[1])) {
return ''.nl2br(trim($data[2])).'
';
}
if (isset($data[1]) && '' === $data[1]) {
return ''.nl2br(trim($data[2])).'
';
}
return $data[0];
},
$text
);
foreach (['centre', 'droite', 'flgauche', 'fldroite', 'clear'] as $tag) {
$regex = sprintf('`<%1$s>(.*)%1$s>`', $tag);
$text = preg_replace_callback(
$regex,
function ($data) {
return ''.$data[1].'
';
},
$text
);
}
foreach (['titre', 'titre'] as $k => $tag) {
$regex = sprintf('`<%1$s>(.*)%1$s>`', $tag);
$text = preg_replace_callback(
$regex,
function ($data) use ($k) {
return ''.$data[1].'
';
},
$text
);
}
foreach ([
'`([0-9]+)`isU',
'`