Вход Регистрация
Файл: bb.php
Строк: 52
<?

$colors 
= array(
        
"darkred" => 1,
        
"red" => 1,
        
"orange" => 1,
        
"brown" => 1,
        
"yellow" => 1,
        
"green" => 1,
        
"olive" => 1,
        
"cyan" => 1,
        
"cyan" => 1,
        
"blue" => 1,
        
"darkblue" => 1,
        
"indigo" => 1,
        
"violet" => 1,
        
"white" => 1,
        
"silver" => 1,
        
"gray" => 1,
        
"black" => 1);

function 
bb_codes ($text)
// Обработка BB-кодов:
{
    global 
$colors;
    
$text str_replace ("`""'"$text);
    
$codes = array();
    
$cnum 0;
    
$res "";
    
$p 0;
    while ( 
true )
    {
        if ( (
$l strpos ($text"["$p)) === false )
        {
            
$res .= substr ($text$p);
            break;
        }
        if ( (
$r strpos ($text"]"$l)) === false )
        {
            
$res .= substr ($text$p);
            break;
        }
        
$res .= substr ($text$p$l $p);
        
$tag substr ($text$l 1$r $l 1);
        if ( (
$e strpos ($tag"=")) !== false )
        {
            
$val substr ($tag$e 1);
            
$tag substr ($tag0$e);
        } else 
$val "";
        
$c $p $r;
        while ( (
$c strpos ($text"[/$tag]"$c 1)) !== false &&
            (
$p strpos ($text"[$tag]"$p 1)) !== false && $p $c );
        if ( 
$c === false )
        {
            
$res .= "[";
            
$p $l 1;
            continue;
        }
        
$con substr ($text$r 1$c $r 1);
        
$err true;

        if ( 
$tag === "b" )
        { 
// Жирный:
            
$con "<b class="bb">" bb_codes ($con$smiles) . "</b>";
            
$err false;
        } elseif ( 
$tag === "i" )
        { 
// Курсив:
            
$con "<i class="bb">" bb_codes ($con$smiles) . "</i>";
            
$err false;
        } elseif ( 
$tag === "u" )
        { 
// Подчеркнутый:
            
$con "<u class="bb">" bb_codes ($con$smiles) . "</u>";
            
$err false;
        }    elseif ( 
$tag === "no" )
        { 
// Не обрабатывать BB-коды:
            
$con nl2br (protection ($con));
            
$err false;
        } elseif ( 
$tag === "code" )
        { 
// Исходный код:
            
if ( ! empty ($con) )
            {
                
$comment protection (( empty ($val) ) ? "Code:" "Code ($val):");
                
$con protection ($con);
                
$con "<table width="90%" class="code"><tr><th>$comment</th></tr><tr><td><pre class="bb">$con</pre></td></tr></table>";
            }
            
$err false;
        } elseif ( 
$tag === "quote" )
        { 
// Цитата:
            
if (! empty ($con) )
            {
                
$comment = ( empty ($val) ) ? "Цитата:" "$val писал:";
                
$con "<table  class="contur"><tr><th>$comment</th></tr><tr><td>" .
                    
bb_codes ($con$smiles) . "</td></tr></table>";
            }
            
$err false;
        }
        if ( 
$err === true )
        {
            
$res .= "[";
            
$p $l 1;
            continue;
        }

        
$cd "`" . (++$cnum) . "`";
        
$codes[$cd] = $con;
        
$res .= $cd;
        
$p $c strlen ($tag) + 3;
    }

     return 
str_replace (array_keys ($codes), array_values ($codes), nl2br ($res));
}
function 
wml_valid ($text)
// WML валидация....
{
$text str_replace("<font color="yellow">","",$text);
$text str_replace("</font>","",$text);
$text str_replace("<font color="red">","",$text);
$text str_replace("<ul>","",$text);
$text str_replace("</ul>","<br/>",$text);
$text str_replace("<li>","",$text);
$text str_replace("</li>","<br/>",$text); return $text;
}
?>
Онлайн: 0
Реклама