Autor Tema: Ayuda Colorear código PHP insertar a [CLASS BBCODE]  (Leído 413 veces)

Desconectado classes

  • PHPerit@
  • *
  • Mensajes: 1
  • Karma: 0
  • Nuev@ PHPer@
    • Ver Perfil
Ayuda Colorear código PHP insertar a [CLASS BBCODE]
« en: 28 de Abril de 2012, 00:39:25 am »
Hola amigos de phperos, pues vengo a pedir su ayuda para lograr colorear los codigos php, les dejo el class, lo que pido porfavor, esque me agregen la funcion  para colorearlo:

Código: [Seleccionar]
<?php
class bbcode
{
function __construct() {
array(
"EMOTICONS_DIR" => "/img/emoticons/"
);
}
        
// Enviar todo el texto que se analiza aquí!
function coverpass($text)
{
//Comprueba si hay algún BBcode
$istag strrpos($text"]");
if($istag != 0)
{
$text $this->parsetags($text); // Yup, Parse Them
}

return nl2br($text);
}

function parsetags($text)
{

// Aka haremos todo para que muestre, ejemplo de uso:
//$text = str_replace("[algo]", "Continuara...", $text);

######## BBcodes Importantes! ########
$text preg_replace("(\[b\](.+?)\[\/b\])is", &#39;<span style="font-weight:bold;">$1</span>&#39;, $text); // Bold
$text preg_replace("(\[i\](.+?)\[\/i\])is", &#39;<i>$1</i>&#39;, $text); // Italics
$text preg_replace("(\[u\](.+?)\[\/u\])is", &#39;<u>$1</u>&#39;, $text); // Underline
$text preg_replace("(\[s\](.+?)\[\/s\])is", &#39;<span class="bbcode_strikethrough">$1</span>&#39;, $text); // Strike through
$text preg_replace("(\[o\](.+?)\[\/o\])is", &#39;<span class="bbcode_overline">$1</span>&#39;, $text); // Overline
$text preg_replace("(\[font=(.+?)\](.+?)\[\/font\])", &#39;<span style="font-family: $1;">$2</span>&#39;, $text); // Font
$text preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is", &#39;<span style="color: $1">$2</span>&#39;, $text); // Color
$text preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is", &#39;<span style="font-size: $1px">$2</span>&#39;, $text); // Font-Size
$text preg_replace("/\[list\](.+?)\[\/list\]/is", &#39;<ul>$1</ul>&#39;, $text); // List
$text str_replace("[*]""<li>"$text); // List-Item
######## //Codigo de code y citar ########
$text preg_replace("(\[code\](.+?)\[\/code\])is", &#39;<code>$1</code>&#39;, $text); // Code
$text preg_replace("(\[citar\](.+?)\[\/citar\])is", &#39;<blockquote><div class="cita">Cita:</div><br><div class="citacuerpo">$1<br></div></blockquote>&#39;, $text); // Quote

######## //Permitir imagenes, links, mails, videos????? ########
$permitir_imagenes true;
$permitir_links true;
$permitir_mails true;
$permitir_youtube true;
######## //Permitir imagenes, links, mails, videos????? ########

// Se permite imagenes?

if($permitir_imagenes == true)
{
$text preg_replace("/\[img\](.+?)\[\/img\]/", &#39;<img src="$1" class="bbcode_img" />&#39;, $text); // Image
$text preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", &#39;<img src="$3" class="bbcode_img" height="$2" width="$1" />&#39;, $text); //Image with width and height
}
else
{
$text preg_replace("/\[img\](.+?)\[\/img\]/", &#39;El administrador ha bloqueado las im&aacute;genes!&#39;, $text); // Image
$text preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", &#39;El administrador ha bloqueado las im&aacute;genes!&#39;, $text); //Image with width and height
}

// Se permite links?
if($permitir_links == true)
{
$text preg_replace("/\[url\]([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\&#39;]*)\[\/url\]/", &#39;<a target="_blank" rel="nofollow" href="$1" class="bbcode_a">$1</a>&#39;, $text); // Url
        
$text preg_replace("(\[url\=([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\&#39;]*)\](.+?)\[/url\])", &#39;<a target="_blank"  rel="nofollow" href="$1" class="bbcode_a">$2</a>&#39;, $text); // Url with text
}
else
{
$text preg_replace("/\[url\]([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\&#39;]*)\[\/url\]/", &#39;El administrador ha bloqueado los links!&#39;, $text); // Url
        
$text preg_replace("(\[url\=([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\&#39;]*)\](.+?)\[/url\])", &#39;El administrador ha bloqueado los links!&#39;, $text); // Url with text
}

// Se permite emails?
if($permitir_mails == true)
{
$text preg_replace("(\[mail\]([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\&#39; a-zA-Z0-9\.@]*)\[/mail\])", &#39;<a href="mailto:$1" class="bbcode_a">$1</a>&#39;, $text); // Mail
        
$text preg_replace("/\[mail\=([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\&#39; a-zA-Z0-9\.@]*)\](.+?)\[\/mail\]/", &#39;<a href="mailto:$1" class="bbcode_a">$2</a>&#39;, $text); // Mail with text
}
else
{
$text preg_replace("(\[mail\]([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\&#39; a-zA-Z0-9\.@]*)\[/mail\])", &#39;El administrador ha bloqueado los correo links!&#39;, $text); // Mail
        
$text preg_replace("/\[mail\=([ a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\&#39; a-zA-Z0-9\.@]*)\](.+?)\[\/mail\]/", &#39;El administrador ha bloqueado los links!&#39;, $text); // Mail with text

// Se permite videos?
if($permitir_youtube == true)
{
$youtube_replacement = &#39;<object style="width:425px; height:350px;">
<param name="movie" value="http://www.youtube.com/v/$1"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://www.youtube.com/v/$1" wmode="transparent" type="application/x-shockwave-flash" style="width:425px; height:350px;"></embed>
</object>&#39;;
$text preg_replace("/\[youtube\](.+?)\[\/youtube\]/"$youtube_replacement$text); // YouTube

$youtube_replacement = &#39;<object style="width:$1px; height:$2px;">
<param name="movie" value="http://www.youtube.com/v/$3"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://www.youtube.com/v/$3" wmode="transparent" type="application/x-shockwave-flash" style="width:$1px; height:$2px;"></embed>
</object>&#39;;
$text preg_replace("/\[youtube=([0-9]*)x([0-9]*)\](.+?)\[\/youtube\]/"$youtube_replacement$text); // YouTube with width/height

$googlevid_replacement = &#39;<object style="width:400px; height:326px;">
<param name="movie" value=http://video.google.com/googleplayer.swf?docId=$1"></param>
<embed src="http://video.google.com/googleplayer.swf?docId=$1" wmode="transparent" style="width:400px; height:326px;" 
id="VideoPlayback" type="application/x-shockwave-flash" flashvars=""></embed>&#39;;
$text preg_replace("/\[googlevid\](.+?)\[\/googlevid\]/"$googlevid_replacement$text); // Google Video

$googlevid_replacement = &#39;<object style="width:$1px; height:$2px;">
<param name="movie" value=http://video.google.com/googleplayer.swf?docId=$3"></param>
<embed src="http://video.google.com/googleplayer.swf?docId=$3" wmode="transparent" style="width:$1px; height:$2px;" 
id="VideoPlayback" type="application/x-shockwave-flash" flashvars=""></embed>&#39;;
$text preg_replace("/\[googlevid=([0-9]*)x([0-9]*)\](.+?)\[\/googlevid\]/"$googlevid_replacement$text); // Google Video tamaño
}
else
{
$text preg_replace("/\[youtube\](.+?)\[\/youtube\]/", &#39;El administrador ha bloqueado los videos!&#39;, $text); // YouTube
$text preg_replace("/\[youtube=([0-9]*)x([0-9]*)\](.+?)\[\/youtube\]/", &#39;El administrador ha bloqueado los videos!&#39;, $text); // YouTube Video tamaño
$text preg_replace("/\[googlevid\](.+?)\[\/googlevid\]/", &#39;El administrador ha bloqueado los videos!&#39;, $text); // Google Video
$text preg_replace("/\[googlevid=([0-9]*)x([0-9]*)\](.+?)\[\/googlevid\]/", &#39;El administrador ha bloqueado los videos!&#39;, $text); // Google tamañ
}
return $text;

}
}
?>


como veran ya tengo la funcion [*//code][*///code]

me poddrian hacer el favor de agregar [*//php][*///php] y que lo coloree porfavor, gracias por su atención.

Saludos

Comunidad PHPeros

Ayuda Colorear código PHP insertar a [CLASS BBCODE]
« en: 28 de Abril de 2012, 00:39:25 am »

Desconectado Slipknot

  • PHPer@
  • **
  • Mensajes: 60
  • Karma: 0
  • Sexo: Masculino
    • Ver Perfil
Re:Ayuda Colorear código PHP insertar a [CLASS BBCODE]
« Respuesta #1 en: 17 de Mayo de 2012, 18:17:10 pm »
La funcion highlight_string() te servira ;)
"He omitido intencionalmente los acentos en la mayoría de mis mensajes"