Skip to content

Instantly share code, notes, and snippets.

@ricardosiri68
Created April 15, 2013 20:25
Show Gist options
  • Save ricardosiri68/5391026 to your computer and use it in GitHub Desktop.
Save ricardosiri68/5391026 to your computer and use it in GitHub Desktop.
<?php
class Embebidos{
var $servidores = array(
array("http://www.youtube.com/","youtube"),
array("http://soundcloud.com/","soundcloud")
);
var $reemplazados = array();
function __construct($post){
$this->post = $post;
}
function defaultLink($post){
return " <a href=$post class='defaultAnchor' >$post</a> ";
}
function soundcloud($post){
preg_match_all("/(\/\w)/",$post,$slashes);
$cant_slashes = count($slashes[1]);
$height = ($cant_slashes < 3) ? 450 : 166;
return "<div class='soundcloud embed' ><center><iframe width=500 height=$height src=http://w.soundcloud.com/player/?url=$post frameborder=0 allowfullscreen ></iframe><p><a href=$post class='embedAnchor'>$post</a></p></center></div>";
}
function youtube($post){
$post = preg_split("/(&)/",$post);
$post = preg_replace("/(watch\?v=)/","embed/",$post[0]);
return "<div class='youtube embed' ><center><iframe width=600 height=480 src=$post frameborder=0 allowfullscreen></iframe><p><a class='embedAnchor' href=$post >$post</a></p></center></div>";
}
function preg_cleaner($link){
$s = preg_replace("/(\/)/","\/",$link);
$s = preg_replace("/(\:)/","\:",$s);
$s = preg_replace("/(\?)/","\?",$s);
return $s;
}
function buscarEmbebido($post){
$servidores = $this->servidores;
$embebido = false;
foreach($servidores as $serv){
$s = $this->preg_cleaner($serv[0]);
if (preg_match("/(".$s.")/",$post)){
$embebido = $this->$serv[1]($post);
}
}
if($embebido){
return $embebido;
}else{
return $this->defaultLink($post);
}
}
function dBug($c){
$commands = array("r"=>array($this->reemplazados,"ENLACES REEMPLAZADOS"),
"e"=>array($this->get_explodes(),"PALABRAS PROCESADAS"),
"nl"=>array($this->newLines(),"SALTOS DE LINEA"));
if(array_key_exists($c,$commands)){
$command = $commands[$c];
}else{
return "<CENTER><P><B>EL MODO DE DEPURACION NO EXISTE</B><P><CENTER>";
}
$o = "<ol class='dbug' style='
background-color: black;
font-family: Monospace;
font-size:12px;
color: green;
padding: 12px 50px 12px 50px;
overflow:scroll;
' >
<center style='margin-bottom: 30px;' >
<u><b>{$command[1]}</b></u>
</center>";
foreach($command[0] as $reem){
$reem = preg_replace("/\t/","<b style='color: red;'>[TAB]</b>",$reem);
$reem = preg_replace("/\s/","<b style='color: white;'>[SPACE]</b>",$reem);
$reem = preg_replace("/\n/","<b style='color: gray;'>[NEWLINE]</b>",$reem);
$o .= "<li>>>> $reem</li>";
}
return $o."</ol>";
}
function newLines(){
return preg_split("/\n/",$this->post);
}
function get_reemplazado($link){
$susses = false;
foreach($this->reemplazados as $reemplazado){
if($reemplazado == $link){
$susses = true;
}
}
return $susses;
}
function set_reemplazado($link){
array_push($this->reemplazados, $link);
}
function reemplazar($p,$e,$post){
$ps = $this->preg_cleaner($p);
$expr = "/".$ps."(\s|\t|\n)/";
$post = preg_replace($expr,$e,$post);
$this->set_reemplazado($p);
return $post;
}
function get_explodes(){
/*$explodes = array();
foreach($this->newLines() as $line){
$line = " <p> $line </p> ";
foreach(preg_split("/\t|\s/",$line) as $word){
$explodes[] = $word;
}
}*/
return preg_split("/\t|\s|\n/",$this->post);
}
function getWithPharagraps($post){
$output = "";
foreach(preg_split("/\n/",$post) as $phar){
if (!($phar == null)){
$output .= " <p class='pPhar' > ".$phar." </p>";
}
}
return $output;
}
function get(){
$post = $this->post;
foreach($this->get_explodes() as $p){
if (preg_match("/^(ftp|http|https)(\:\/\/)/",$p)){
if(!($this->get_reemplazado($p))){
$e = $this->buscarEmbebido($p);
if($e){
$post = $this->reemplazar($p,$e,$post);
}
}
}
}
return $this->getWithPharagraps($post);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment