Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/11/2010, 23:38
Avatar de zaetoner
zaetoner
 
Fecha de Ingreso: noviembre-2007
Ubicación: La ciudad de México
Mensajes: 607
Antigüedad: 16 años, 4 meses
Puntos: 30
[APORTE] crea tu pagina de frases facebook!

hola forosdelweb, aca papi zaetoner(jeje) les trae un muuuy simple script para que sigan aprendiendo, solo crean su base de datos y ponen el codigo en index.php y crean coneccion.php.

Darme karma es una forma de agradecer, no quiero dinero!!!(bueno... no de esta forma)
Código PHP:
<?php //creado por zaetoner en la Ciudad de México
session_start();
/*
Que onda chavos!!!, este es un simple(muy simple) script para crear tu  propia pagina de "me gusta"
Lo programe yo por ocio, no intento ganar dinero, y lo dare al software libre.
si tienes dudas o aportaciones de codigo mis datos de contacto son:

twitter       @zaetoner
facebook      facebook.com/zaetoner 
correo        [email protected] (nunca me conecto al messenger!!! solo correos!!)

------------------------------INSTALACION-----------------------------
1.- Crea tu base de datos, e ingresa esta consulta:(borrado, hoy, ip, y ref no son necesarias para que funcione)

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

CREATE TABLE `megusta` (
  `id` int(7) NOT NULL auto_increment,
  `mensaje` text collate latin1_general_ci NOT NULL,
  `fecha` datetime NOT NULL,
  `hoy` varchar(10) collate latin1_general_ci NOT NULL,
  `titulo` varchar(256) collate latin1_general_ci NOT NULL,
  `tituloweb` varchar(256) collate latin1_general_ci NOT NULL,
  `borrado` varchar(2) collate latin1_general_ci NOT NULL,
  `ip` varchar(25) collate latin1_general_ci NOT NULL,
  `ref` varchar(1000) collate latin1_general_ci NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;

2.- Crea tu archivo de coneccion en coneccion.php
3.-crea un archivo llamado .htaccess e ingresa estos datos:(es para que puedas tener url amigables!! .com/tufrase/ )

RewriteBase /
Options +FollowSymLinks

RewriteEngine on


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?1=$1


4.-no es necesario nada mas 
logo.jpg --->  pones tu logo(obvio)
megusta.gif ----> pones una manita con pulgar arriba! o algo segun tu capacidad de imaginacion

El codigo esta bien comentado para que sepas como funciona, gracias por leer estas lineas!!!.

PD:El codigo esta enfocado a novatos y tiene la finalidad de enseñar UNICAMENTE!!!!!!!!

*/

include("coneccion.php");
$v1=$_GET['1'];//recuperamos la primer variable estara en .com/estaeslavariable/
$megusta=$_POST['megusta'];//En caso de que el usuario escriba una frase aqui la recibiremos
$se=$_POST['se'];//para evitar un poco a los robots
$tucompu=$_POST['tucompu'];//si es un bot de spam, esto estara con info, y no procedemos!
$dominio=$_SERVER['HTTP_HOST'];//haci no tendras que escribir tu dominio en todos los links!!!
if($megusta and !$tucompu){//si el usuario escribio una frase y no es un bot de spam
    
    //combiamos acentos por letras sin acentos
$tofind "ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ";
$replac "AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn";
$sinacentos=strtr($megusta,$tofind,$replac);

//quitamos cualquier cosa que no sean los siguientes caracteres A-Za-z0-9,?!:;.)-¬(#
$megustatitulosubstr(ereg_replace("[^A-Za-z0-9,?!:;.)-¬(#]"" "$sinacentos),0,256);
//quitamos codigo html
$megustatitulo=htmlentities($megustatitulo);
//cambiamos por un guion los caractes que no sean A-Za-z0-9
$megustatitulowebsubstr(ereg_replace("[^A-Za-z0-9]""-"$sinacentos),0,50);
$megustatituloweb=htmlentities($megustatituloweb);
$megustat=htmlentities($sinacentos);

//revisamos si hay algun registro con el mismo url
$ctw=mysql_query("SELECT id FROM megusta WHERE tituloweb='$megustatituloweb'");
// $ntw es el numero de registros, normalmente es igual a 0
$ntw=mysql_num_rows($ctw);

    if(
$se==$_SESSION['se']){//esta es otra medida antibots
    
        
if($ntw==1){
        
//el registro ya existe,
        //seguro dio actualizar la pagina
        //no hay pex simplemente no guardamos
        
echo $se."|".$_SESSION['se'];echo $megustatituloweb;
        
        }else{
        
//baneas palabras que no quieras que salgan
            
if(
               
eregi(".com/",$megustat)
            or 
eregi("idiota",$megustat)
            or 
eregi("http",$megustat)
            or 
eregi("://",$megustat)
            or 
is_numeric($megustat)
            or 
eregi("href",$megustat)
            or 
eregi("index",$megustat)
            or 
eregi("Joder",$megustat)
            or 
eregi("Puto",$megustat)
            or 
eregi("WeBoOoOsss",$megustat) ){
            
            
            }else{
            
//guardamos
            
mysql_query("INSERT INTO megusta (mensaje, titulo,tituloweb, fecha,hoy,ip,ref)
            VALUES 
            ('$megustat','$megustatitulo','$megustatituloweb',NOW(),'$hoyes','"
.$_SERVER['REMOTE_ADDR']."','".$_SERVER['HTTP_REFERER']."')");
            
            
//mandamos al usuario a la pagina donde estara su frase para que haga click en "megusta"
            
header("Location: http://".$dominio."/".$megustatituloweb."/");
            }
        }
    }
        

}
if(!empty(
$v1)){//si el usuario quiere ver una frase, la consultamos!
$c=mysql_query("SELECT * FROM megusta WHERE borrado='' and tituloweb='$v1' ");
$a=mysql_fetch_array($c);
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta property="og:site_name" content="Ver Mas!"/> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><? echo $a['titulo']; if(!$a){ echo "Frases de Me Gusta en ".$dominio;} ?></title>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-18737586-2']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>
<style media="all" type="text/css">
body{font-family:TAHOMA}
.t {left: -9999em; position:absolute; }
#tucompu{ display:none}
.l{ width:580px; height:auto; float:left; font-family:TAHOMA; font-size:36px; color:#FFFFFF}
</style>
<body>
<div style="width:600px; height:auto; margin-left:auto; margin-right:auto">
<div style="width:600px; background-color:#3B5998; height:90px; float:left; ">
<h1 id="logo" title="me gusta">
<a href="http://<? echo $dominio;?>/">
<img alt="me gusta" src="http://<? echo $dominio;?>/logo.jpg" border="0" />
<span class="t">me gusta</span>
</a>
</h1>
</div>
<div style="width:580px; height:auto; margin-top:10px; font-family:TAHOMA; font-size:22px;  margin-left:10px; background-color:#FFFFFF; float:left; ">
Pon una frase que le pueda gustar a tus amigos!
<?
mt_srand
(time());//una medida antibots
        
$se=mt_rand(100000,900000);//una medida antibots
        
$_SESSION['se']=$se;//una medida antibots
        
        /*
        per, url, self y pro son solo para romperle las pelotas a los spammers
        
        'se' si es importante, si lo quitas el script no funciona
        */
        
?>

<form action="http://<? echo $dominio;?>/" method="post">
<input type="hidden" name="se" value="<?=$se?>">
 <input type="text" name="tucompu" id="tucompu" value="">
 <input type="hidden" name="per" value="<? $_SESSION['time']=time(); echo $_SESSION['time'];?>">
 <input type="hidden" name="url" value="<? $_SESSION['time']=time()/4; echo $_SESSION['time'];?>">
 <input type="hidden" name="self" value="<? $_SESSION['time']=time()/8000; echo $_SESSION['time'];?>">
 <input type="hidden" name="pro" value="<? $_SESSION['time']=time()/780000; echo $_SESSION['time'];?>">
<input type="text" name="megusta" style="font-size:18px; width:550px; margin-left:15px; color:#666666" />
<input type="submit" value="crear" style="font-size:18px; margin-left:200px; width:150px" />
</form>
</div>
<?

if(empty($v1)){//si el usuario esta en la pagina de inicio, consultamos las frases, igual puedes añadir aqui LIMIT 0,30
    
$c=mysql_query("SELECT * FROM megusta WHERE borrado='' ORDER BY fecha DESC LIMIT 0,30 ");
    while(
$a=mysql_fetch_array($c)){//creamos un bucle para que aparescan todas las frases de la consulta
    
?>
    <div style="width:600px; height:auto; margin-top:10px; ; float:left; background-color:#ECEFF5">
    <div style="width:100px; height:30px; float:left; margin-left:10px; margin-top:10px">
    <iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2F<? echo $dominio;?>%2F<?=$a['tituloweb']?>%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=30" scrolling="no" frameborder="0" style="border:none; float:left; overflow:hidden; margin-top:2px; width:100px; height:30px; " allowTransparency="true">
      </iframe>
    </div>
    <a href="http://<? echo $dominio;?>/<? echo $a['tituloweb'];?>/" style="width:450px; margin-left:10px; margin-top:10px; height:auto; float:left; color:#000000;">
    <? echo $a['titulo'];?>
    </a>
    </div>
    <?
    
}

}

continua en el siguiente post... no me deja poner mas de 10000  caracteres
__________________
...