Foros del Web » Programando para Internet » PHP »

Duda con BBCode

Estas en el tema de Duda con BBCode en el foro de PHP en Foros del Web. He encontrado esta clase en phpclasses.org pero no se como usarla con botones como los de FDW. Código PHP: <?php function  begtoend ( $htmltag ){ ...
  #1 (permalink)  
Antiguo 07/04/2004, 07:09
Avatar de Reynier  
Fecha de Ingreso: noviembre-2002
Ubicación: Por ahí en algún sitio
Mensajes: 1.844
Antigüedad: 21 años, 4 meses
Puntos: 1
Duda con BBCode

He encontrado esta clase en phpclasses.org pero no se como usarla con botones como los de FDW.
Código PHP:
<?php
function begtoend($htmltag){
    return 
preg_replace('/<([A-Za-z]+)>/','</$1>',$htmltag);
}
function 
replace_pcre_array($text,$array){
    
$pattern array_keys($array);
    
$replace array_values($array);
    
$text preg_replace($pattern,$replace,$text);
    return 
$text;
}
class 
bbcode{
    var 
$tags;
    var 
$settings;
    function 
bbcode(){
        
$this->tags = array();
        
$this->settings = array('enced'=>true);
    }
    function 
get_data($name,$cfa ''){
        if(!
array_key_exists($name,$this->tags)) return '';
        
$data $this->tags[$name];
        if(
$cfa$sbc $cfa; else $sbc $name;
        if(!
is_array($data)){
            
$data preg_replace('/^ALIAS(.+)$/','$1',$data);
            return 
$this->get_data($data,$sbc);
        }else{
            
$data['Name'] = $sbc;
            return 
$data;
        }
    }
    function 
change_setting($name,$value){
        
$this->settings[$name] = $value;
    }
    function 
add_alias($name,$aliasof){
        if(!
array_key_exists($aliasof,$this->tags) or array_key_exists($name,$this->tags)) return false;
        
$this->tags[$name] = 'ALIAS'.$aliasof;
        return 
true;
    }
    function 
onparam($param,$regexarray){
        
$param replace_pcre_array($param,$regexarray);
        if(!
$this->settings['enced']){
            
$param htmlentities($param);
        }
        return 
$param;
    }
    function 
export_definition(){
        return 
serialize($this->tags);
    }
    function 
import_definiton($definition,$mode 'append'){
        switch(
$mode){
            case 
'append':
            
$array unserialize($definition);
            
$this->tags $array $this->tags;
            break;
            case 
'prepend':
            
$array unserialize($definition);
            
$this->tags $this->tags $array;
            break;
            case 
'overwrite':
            
$this->tags unserialize($definition);
            break;
            default:
            return 
false;
        }
        return 
true;
    }
    function 
add_tag($params){
        if(!
is_array($params)) return 'Paramater array not an array.';
        if(!
array_key_exists('Name',$params) or empty($params['Name'])) return 'Name parameter is required.';
        if(
preg_match('/[^A-Za-z]/',$params['Name'])) return 'Name can only contain letters.';
        if(!
array_key_exists('HasParam',$params)) $params['HasParam'] = false;
        if(!
array_key_exists('HtmlBegin',$params)) return 'HtmlBegin paremater not specified!';
        if(!
array_key_exists('HtmlEnd',$params)){
             if(
preg_match('/^(<[A-Za-z]>)+$/',$params['HtmlBegin'])){
                 
$params['HtmlEnd'] = begtoend($params['HtmlBegin']);
             }else{
                 return 
'You didn\'t specify the HtmlEnd parameter, and your HtmlBegin parameter is too complex to change to an HtmlEnd parameter.  Please specify HtmlEnd.';
             }
        }
        if(!
array_key_exists('ParamRegexReplace',$params)) $params['ParamRegexReplace'] = array();
        if(!
array_key_exists('ParamRegex',$params)) $params['ParamRegex'] = '[^\\]]+';
        if(!
array_key_exists('HasEnd',$params)) $params['HasEnd'] = true;
        if(
array_key_exists($params['Name'],$this->tags)) return 'The name you specified is already in use.';
        
$this->tags[$params['Name']] = $params;
        return 
'';
    }
    function 
parse_bbcode($text){
        foreach(
$this->tags as $tagname => $tagdata){
            if(!
is_array($tagdata)) $tagdata $this->get_data($tagname);
            
$startfind "/\\[{$tagdata['Name']}";
            if(
$tagdata['HasParam']){
                
$startfind.= '=('.$tagdata['ParamRegex'].')';
            }
            
$startfind.= '\\]/';
            if(
$tagdata['HasEnd']){
                
$endfind "[/{$tagdata['Name']}]";
                
$starttags preg_match_all($startfind,$text,$ignore);
                
$endtags substr_count($text,$endfind);
                if(
$endtags $starttags){
                    
$text.= str_repeat($endfind,$starttags $endtags);
                }
                
$text str_replace($endfind,$tagdata['HtmlEnd'],$text);
            }
            
$replace str_replace(array('%%P%%','%%p%%'),'\'.$this->onparam(\'$1\',$tagdata[\'ParamRegexReplace\']).\'','\''.$tagdata['HtmlBegin'].'\'');
            
$text preg_replace($startfind.'e',$replace,$text);
        }
        return 
$text;
    }
}
?>
Me dan alguna idea?

Salu2
__________________
Ing. Reynier Pérez Mira
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:27.