view Includes/Bbcodeparser.inc.php @ 0:3021ce32ee14 owls-0.5

begin of using hg for owls
author "Meillo r e t u r n s <meillo@marmaro.de>"
date Sun, 03 Dec 2006 22:32:13 +0100
parents
children ab74e95a8040
line wrap: on
line source

<?php

/**
 *
 * BB-Code-Parser
 *
 * by Meillo  r e t u r n s
 *
 */


  function parse_quote1($textinput,$level = 1) {                  // ohne Quelle
    $pattern = '#\[quote\](((?R)|(.*))*)\[/quote\]#isUe';
    $replacement = "'<br />[nl]<span class=\"quote0\">Zitat:</span>[nl]<div class=\"quote1\">[nl]'.parse_quote1('$1',
                     ". ($level + 1) ."
                   ).'[nl]</div>[nl]'";
    return preg_replace($pattern, $replacement, $textinput);
  }
  function parse_quote2($textinput,$level = 1) {                   // mit Quelle
    $pattern = '#\[quote\=(.*)\](((?R)|(.*))*)\[/quote\]#isUe';
    $replacement = "'<br />[nl]<span class=\"quote0\">Zitat: ($1)</span>[nl]<div class=\"quote2\">[nl]'.parse_quote2('$2',
                     ". ($level + 1) ."
                   ).'[nl]</div>[nl]'";
    return preg_replace($pattern, $replacement, $textinput);
  }

  function smilies($text) {
    $smilieDir = 'Pics/Smilies/';  // path to smilies

    $smilies = array( ':-)'        => 'Smile.gif',
                      ':)'         => 'Smile.gif',
                      ';-)'        => 'Wink.gif',
                      ';)'         => 'Wink.gif',
                      ':-D'        => 'Biggrin.gif',
                      ':D'         => 'Biggrin.gif',
                      ':-('        => 'Sad.gif',
                      ':('         => 'Sad.gif',
                      ':-P'        => 'Lick.gif',
                      ':P'         => 'Lick.gif',
                      ':o'         => 'Talk.gif',
                      ':-S'        => 'Dontknow.gif',
                      ':dontknow:' => 'Dontknow.gif',
                      ':-@'        => 'Angry.gif',
                      ':cool:'        => 'Cool.gif',
                      '(H)'        => 'Cool.gif',
                      '%-)'        => 'Crosseyed.gif',
                      '%-('        => 'Crosseyed.gif',
                      ':rolleyes:' => 'Rolleyes.gif',
                      ':eek:'      => 'Shocked.gif');
    while(list($key, $val) = each($smilies)) {
      $text = str_replace($key,'[img]'.$smilieDir.$val.'[/img]',$text);
    }
    return $text;
  }


  function bbcode($text, $smilies = 0, $images = 0) {

    // smilies
    if ($smilies == 1) {
      $text = smilies($text);
    }

    // new-lines
    $text = preg_replace("#(\r\n)|(\r)#", "\n", $text);
    $text = str_replace("\n", '<br />[nl]', htmlentities($text));

    // bold
    $text = preg_replace("#\[b\](.*?)\[/b\]#i", "<strong>$1</strong>", $text);
    // italic
    $text = preg_replace("#\[i\](.*?)\[/i\]#i", "<i>$1</i>", $text);
    // links
    $text = preg_replace("#\[url\](.*)\[/url\]#iU", "<a href=\"$1\">$1</a>", $text);
    $text = preg_replace("#\[url=(.*)\](.*)\[/url\]#iU", "<a href=\"$1\">$2</a>", $text);
    // lists
      //$text = preg_replace("#\[list\]\<br /\>(.*)\[/list\]#iU", "<ul>$1</ul>", $text);
      //$text = preg_replace("#\[\*\](.*)\<br \/\>#iU", "<li>$1</li>", $text);
    // quotes
    $text = parse_quote1($text);
    $text = parse_quote2($text);
    // images
    if ($images == 1) {
      $text = preg_replace("#\[img\](.*?)\[/img\]#i", "<img src=\"$1\" alt=\"&lt;[Bild]&gt;\" />", $text);
    }

    // remove backslashes
    $text = preg_replace("#\\\#is", "", $text);
    // new-lines
    $text = str_replace('[nl]', "\n", $text);

    return $text;
  }

?>