owls

diff Includes/Bbcodeparser.inc.php @ 0:3021ce32ee14

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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Includes/Bbcodeparser.inc.php	Sun Dec 03 22:32:13 2006 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +<?php
     1.5 +
     1.6 +/**
     1.7 + *
     1.8 + * BB-Code-Parser
     1.9 + *
    1.10 + * by Meillo  r e t u r n s
    1.11 + *
    1.12 + */
    1.13 +
    1.14 +
    1.15 +  function parse_quote1($textinput,$level = 1) {                  // ohne Quelle
    1.16 +    $pattern = '#\[quote\](((?R)|(.*))*)\[/quote\]#isUe';
    1.17 +    $replacement = "'<br />[nl]<span class=\"quote0\">Zitat:</span>[nl]<div class=\"quote1\">[nl]'.parse_quote1('$1',
    1.18 +                     ". ($level + 1) ."
    1.19 +                   ).'[nl]</div>[nl]'";
    1.20 +    return preg_replace($pattern, $replacement, $textinput);
    1.21 +  }
    1.22 +  function parse_quote2($textinput,$level = 1) {                   // mit Quelle
    1.23 +    $pattern = '#\[quote\=(.*)\](((?R)|(.*))*)\[/quote\]#isUe';
    1.24 +    $replacement = "'<br />[nl]<span class=\"quote0\">Zitat: ($1)</span>[nl]<div class=\"quote2\">[nl]'.parse_quote2('$2',
    1.25 +                     ". ($level + 1) ."
    1.26 +                   ).'[nl]</div>[nl]'";
    1.27 +    return preg_replace($pattern, $replacement, $textinput);
    1.28 +  }
    1.29 +
    1.30 +  function smilies($text) {
    1.31 +    $smilieDir = 'Pics/Smilies/';  // path to smilies
    1.32 +
    1.33 +    $smilies = array( ':-)'        => 'Smile.gif',
    1.34 +                      ':)'         => 'Smile.gif',
    1.35 +                      ';-)'        => 'Wink.gif',
    1.36 +                      ';)'         => 'Wink.gif',
    1.37 +                      ':-D'        => 'Biggrin.gif',
    1.38 +                      ':D'         => 'Biggrin.gif',
    1.39 +                      ':-('        => 'Sad.gif',
    1.40 +                      ':('         => 'Sad.gif',
    1.41 +                      ':-P'        => 'Lick.gif',
    1.42 +                      ':P'         => 'Lick.gif',
    1.43 +                      ':o'         => 'Talk.gif',
    1.44 +                      ':-S'        => 'Dontknow.gif',
    1.45 +                      ':dontknow:' => 'Dontknow.gif',
    1.46 +                      ':-@'        => 'Angry.gif',
    1.47 +                      ':cool:'        => 'Cool.gif',
    1.48 +                      '(H)'        => 'Cool.gif',
    1.49 +                      '%-)'        => 'Crosseyed.gif',
    1.50 +                      '%-('        => 'Crosseyed.gif',
    1.51 +                      ':rolleyes:' => 'Rolleyes.gif',
    1.52 +                      ':eek:'      => 'Shocked.gif');
    1.53 +    while(list($key, $val) = each($smilies)) {
    1.54 +      $text = str_replace($key,'[img]'.$smilieDir.$val.'[/img]',$text);
    1.55 +    }
    1.56 +    return $text;
    1.57 +  }
    1.58 +
    1.59 +
    1.60 +  function bbcode($text, $smilies = 0, $images = 0) {
    1.61 +
    1.62 +    // smilies
    1.63 +    if ($smilies == 1) {
    1.64 +      $text = smilies($text);
    1.65 +    }
    1.66 +
    1.67 +    // new-lines
    1.68 +    $text = preg_replace("#(\r\n)|(\r)#", "\n", $text);
    1.69 +    $text = str_replace("\n", '<br />[nl]', htmlentities($text));
    1.70 +
    1.71 +    // bold
    1.72 +    $text = preg_replace("#\[b\](.*?)\[/b\]#i", "<strong>$1</strong>", $text);
    1.73 +    // italic
    1.74 +    $text = preg_replace("#\[i\](.*?)\[/i\]#i", "<i>$1</i>", $text);
    1.75 +    // links
    1.76 +    $text = preg_replace("#\[url\](.*)\[/url\]#iU", "<a href=\"$1\">$1</a>", $text);
    1.77 +    $text = preg_replace("#\[url=(.*)\](.*)\[/url\]#iU", "<a href=\"$1\">$2</a>", $text);
    1.78 +    // lists
    1.79 +      //$text = preg_replace("#\[list\]\<br /\>(.*)\[/list\]#iU", "<ul>$1</ul>", $text);
    1.80 +      //$text = preg_replace("#\[\*\](.*)\<br \/\>#iU", "<li>$1</li>", $text);
    1.81 +    // quotes
    1.82 +    $text = parse_quote1($text);
    1.83 +    $text = parse_quote2($text);
    1.84 +    // images
    1.85 +    if ($images == 1) {
    1.86 +      $text = preg_replace("#\[img\](.*?)\[/img\]#i", "<img src=\"$1\" alt=\"&lt;[Bild]&gt;\" />", $text);
    1.87 +    }
    1.88 +
    1.89 +    // remove backslashes
    1.90 +    $text = preg_replace("#\\\#is", "", $text);
    1.91 +    // new-lines
    1.92 +    $text = str_replace('[nl]', "\n", $text);
    1.93 +
    1.94 +    return $text;
    1.95 +  }
    1.96 +
    1.97 +?>
    1.98 \ No newline at end of file