['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>(.*)`', $tag); $text = preg_replace_callback( $regex, function ($data) { return '
'.$data[1].'
'; }, $text ); } foreach (['titre', 'titre'] as $k => $tag) { $regex = sprintf('`<%1$s>(.*)`', $tag); $text = preg_replace_callback( $regex, function ($data) use ($k) { return '
'.$data[1].'
'; }, $text ); } foreach ([ '`([0-9]+)`isU', '``isU', '`smiley:([a-zA-Z]*)`is', '##isU', "#onclick='window\\.open\\(this\\.href\\); return false'#", '##isU', '#<timestamp>#isU', ] as $regex) { $text = preg_replace($regex, '', $text); } $text = preg_replace_callback('`
  • (.*)
  • `isU', function ($data) { return '
  • '.trim($data[1]).'
  • '; }, $text); $text = preg_replace_callback( '`(.*)`isU', function ($data) { return sprintf('

    %s

    %s

    ', nl2br(trim($data[2])), $data[1]); }, $text ); $text = preg_replace_callback( '`(.*)`isU', function ($data) { return sprintf('

    %s

    ', nl2br(trim($data[1]))); }, $text ); $text = preg_replace_callback('`(.*)`isU', function ($data) { return html_entity_decode($data[1]); }, $text); $text = preg_replace_callback('`(.*)`isU', function ($data) { return htmlspecialchars($data[1]); }, $text); $text = preg_replace('`([0-9]+)`isU', '', $text); $text = preg_replace_callback('`(.*)`isU', function () { return str_replace('
    ', '', $data[1]); }, $text); $text = preg_replace_callback( [ '#(.*)#isU', '#(.*)#isU', ], function ($data) { $lang = strtolower(str_replace( ['console', 'texte', 'apache'], ['bash', 'text', 'html'], $data[1]) ); $class = 'language-'.$lang; return sprintf('
    %s
    ', $class, trim(htmlentities($data[2]))); }, $text ); $text = preg_replace_callback('`([^<]+)`isU', function ($data) { return ''.$data[1].''; }, $text); $text = preg_replace_callback('`(.*)`isU', function ($data) { $lines = explode("\n", $data[1]); $pictures = []; foreach ($lines as $line) { $line = trim($line); if (empty($line)) { continue; } $elements = explode('|', $line); if (2 === count($elements) || 3 === count($elements)) { $pictures[] = sprintf( '
  • %3$s
  • ', $elements[0], $elements[1], isset($elements[2]) ? $elements[2] : '' ); } } if (empty($pictures)) { return ''; } return '
      '.implode('', $pictures).'
    '; }, $text); foreach (['`"http://www.youtube.com/[^"]+"`i', '`"http://www.dailymotion.com/[^"]+"`i'] as $regex) { $text = preg_replace_callback($regex, function ($data) { return str_replace('&', '&', $data[0]); }, $text); } return $text; } }