new \Twig_Filter_Method($this, 'comment', array('is_safe' => array('html'))), 'post' => new \Twig_Filter_Method($this, 'post', array('is_safe' => array('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 = preg_replace('`(.*)`isU', '', $text); $text = preg_replace_callback( '`]*)>(.*)]*)>`isU', function($data) { if(preg_match('`^[ ]+`', $data[1])) { return ''.nl2br(trim($data[2])).'

'; } elseif(isset($data[1]) && $data[1] === '') { return '

'.nl2br(trim($data[2])).'

'; } else { return $data[0]; } }, $text ); $text = preg_replace_callback('`(.*)`isU', function($data) { return '
'.$data[1].'
'; }, $text); $text = preg_replace_callback('`(.*)`isU', function($data) { return '
'.$data[1].'
'; }, $text); $text = preg_replace_callback('`(.*)`isU', function($data) { return '
'.$data[1].'
'; }, $text); $text = preg_replace_callback('`(.*)`isU', function($data) { return '
'.$data[1].'
'; }, $text); $text = preg_replace_callback('`(.*)`isU', function($data) { return '

'.trim($data[1]).'

'; }, $text); $text = preg_replace_callback('`(.*)`isU', function($data) { return '

'.trim($data[1]).'

'; }, $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

    %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 sprintf('', ' data-dimension="destroy" '.(trim($data[1]))); }, $text ); $text = preg_replace_callback( '``isU', function($data) { return sprintf('', ' data-dimension="destroy" '.(trim($data[1]))); }, $text ); $text = preg_replace_callback( '``isU', function($data) { return sprintf('', ' data-dimension="destroy" '.(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('``isU', '', $text); $text = preg_replace('`smiley:([a-zA-Z]*)`is', '', $text); $text = preg_replace_callback( array( '`(.*)`isU', '`(.*)`isU', ), function($data) { $lang = strtolower(str_replace( array('console', 'texte', 'apache'), array('shell', 'text', 'html'), $data[1]) ); $class = 'brush: '.$lang.'; gutter: false'; $html = sprintf('
    Afficher/masquer le code
    %s
    ', $class, trim(htmlentities($data[2]))); return $html; }, $text ); $text = preg_replace_callback('`(.*)`isU', function($data) { return ''.$data[1].''; }, $text); $text = preg_replace_callback('`([^<]+)`isU', function ($data) { return ''.$data[1].''; }, $text); $text = preg_replace_callback('`(.*)`isU', function($data) { '
    '.$data[1].'
    '; }, $text); $text = preg_replace_callback('`"http://www.youtube.com/[^"]+"`i', function($data) { return str_replace('&', '&', $data[0]); }, $text); $text = preg_replace_callback('`"http://www.dailymotion.com/[^"]+"`i', function($data) { return str_replace('&', '&', $data[0]); }, $text); $text = str_replace('', time(), $text); $text = str_replace('<timestamp>', time(), $text); $text = str_replace('', '', $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("onclick='window.open(this.href); return false'", '', $text); return $text; } }