owls

diff Bbcodeparser.inc.php @ 13:3e3fa7725abb

reorganized filesystem strukture
author meillo@marmaro.de
date Sun, 27 May 2007 02:37:55 +0200
parents Includes/Bbcodeparser.inc.php@144bc36a6c27
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Bbcodeparser.inc.php	Sun May 27 02:37:55 2007 +0200
     1.3 @@ -0,0 +1,123 @@
     1.4 +<?php
     1.5 +/**
     1.6 + * BB-Code-Parser
     1.7 + *
     1.8 + * @author Meillo  r e t u r n s <meillo@marmaro.de>
     1.9 + */
    1.10 +
    1.11 +
    1.12 +  /// path to smilies
    1.13 +  define('SMILIE_DIR', 'Smilies/');
    1.14 +
    1.15 +
    1.16 +
    1.17 +  /**
    1.18 +   * parses recursive quotes without a source mentioned
    1.19 +   *
    1.20 +   * @param $textinput the bbcode-text
    1.21 +   * @param $level number of levels to go inside
    1.22 +   * @return HTML-text
    1.23 +   */
    1.24 +  function parse_quote1($textinput,$level = 1) {
    1.25 +    $pattern = '#\[quote\](((?R)|(.*))*)\[/quote\]#isUe';
    1.26 +    $replacement = "'<br />[nl]<span class=\"quote0\">Zitat:</span>[nl]<div class=\"quote1\">[nl]'.parse_quote1('$1',
    1.27 +                     ". ($level + 1) ."
    1.28 +                   ).'[nl]</div>[nl]'";
    1.29 +    return preg_replace($pattern, $replacement, $textinput);
    1.30 +  }
    1.31 +
    1.32 +  /**
    1.33 +   * parses recursive quotes with a source mentioned
    1.34 +   *
    1.35 +   * @param $textinput the bbcode-text
    1.36 +   * @param $level number of levels to go inside
    1.37 +   * @return HTML-text
    1.38 +   */
    1.39 +  function parse_quote2($textinput,$level = 1) {
    1.40 +    $pattern = '#\[quote\=(.*)\](((?R)|(.*))*)\[/quote\]#isUe';
    1.41 +    $replacement = "'<br />[nl]<span class=\"quote0\">Zitat: ($1)</span>[nl]<div class=\"quote2\">[nl]'.parse_quote2('$2',
    1.42 +                     ". ($level + 1) ."
    1.43 +                   ).'[nl]</div>[nl]'";
    1.44 +    return preg_replace($pattern, $replacement, $textinput);
    1.45 +  }
    1.46 +
    1.47 +  /**
    1.48 +   * replaces smilies
    1.49 +   *
    1.50 +   * @param $text text with ASCII-smilies
    1.51 +   * @return text with [img]-smilies
    1.52 +   */
    1.53 +  function smilies($text) {
    1.54 +    $smilies = array( ':-)'        => 'Smile.gif',
    1.55 +                      ':)'         => 'Smile.gif',
    1.56 +                      ';-)'        => 'Wink.gif',
    1.57 +                      ';)'         => 'Wink.gif',
    1.58 +                      ':-D'        => 'Biggrin.gif',
    1.59 +                      ':D'         => 'Biggrin.gif',
    1.60 +                      ':-('        => 'Sad.gif',
    1.61 +                      ':('         => 'Sad.gif',
    1.62 +                      ':-P'        => 'Lick.gif',
    1.63 +                      ':P'         => 'Lick.gif',
    1.64 +                      ':o'         => 'Talk.gif',
    1.65 +                      ':-S'        => 'Dontknow.gif',
    1.66 +                      ':dontknow:' => 'Dontknow.gif',
    1.67 +                      ':-@'        => 'Angry.gif',
    1.68 +                      ':cool:'     => 'Cool.gif',
    1.69 +                      'B-)'        => 'Cool.gif',
    1.70 +                      '%-)'        => 'Crosseyed.gif',
    1.71 +                      '%-('        => 'Crosseyed.gif',
    1.72 +                      ':rolleyes:' => 'Rolleyes.gif',
    1.73 +                      ':eek:'      => 'Shocked.gif');
    1.74 +    while(list($key, $val) = each($smilies)) {
    1.75 +      $text = str_replace($key,'[img]'. SMILIE_DIR . $val .'[/img]', $text);
    1.76 +    }
    1.77 +    return $text;
    1.78 +  }
    1.79 +
    1.80 +
    1.81 +  /**
    1.82 +   * turns bbcode in HTML
    1.83 +   *
    1.84 +   * @param $text the text with bbcode inside
    1.85 +   * @param $smilies set to 1 causes smilies to be replaced with pics
    1.86 +   * @param $images set to 1 causes images to be displayed ([img]-tag)
    1.87 +   * @return text with HTML-code
    1.88 +   */
    1.89 +  function bbcode($text, $smilies = 0, $images = 0) {
    1.90 +
    1.91 +    // smilies
    1.92 +    if ($smilies == 1) {
    1.93 +      $text = smilies($text);
    1.94 +    }
    1.95 +
    1.96 +    // new-lines
    1.97 +    $text = preg_replace("#(\r\n)|(\r)#", "\n", $text);
    1.98 +    $text = str_replace("\n", '<br />[nl]', htmlentities($text));
    1.99 +
   1.100 +    // bold
   1.101 +    $text = preg_replace("#\[b\](.*?)\[/b\]#i", "<strong>$1</strong>", $text);
   1.102 +    // italic
   1.103 +    $text = preg_replace("#\[i\](.*?)\[/i\]#i", "<i>$1</i>", $text);
   1.104 +    // links
   1.105 +    $text = preg_replace("#\[url\](.*)\[/url\]#iU", "<a href=\"$1\">$1</a>", $text);
   1.106 +    $text = preg_replace("#\[url=(.*)\](.*)\[/url\]#iU", "<a href=\"$1\">$2</a>", $text);
   1.107 +    // lists
   1.108 +      //$text = preg_replace("#\[list\]\<br /\>(.*)\[/list\]#iU", "<ul>$1</ul>", $text);
   1.109 +      //$text = preg_replace("#\[\*\](.*)\<br \/\>#iU", "<li>$1</li>", $text);
   1.110 +    // quotes
   1.111 +    $text = parse_quote1($text);
   1.112 +    $text = parse_quote2($text);
   1.113 +    // images
   1.114 +    if ($images == 1) {
   1.115 +      $text = preg_replace("#\[img\](.*?)\[/img\]#i", "<img src=\"$1\" alt=\"&lt;[Bild]&gt;\" />", $text);
   1.116 +    }
   1.117 +
   1.118 +    // remove backslashes
   1.119 +    $text = preg_replace("#\\\#is", "", $text);
   1.120 +    // new-lines
   1.121 +    $text = str_replace('[nl]', "\n", $text);
   1.122 +
   1.123 +    return $text;
   1.124 +  }
   1.125 +
   1.126 +?>