Ver Mensaje Individual
  #2 (permalink)  
Antiguo 18/02/2012, 15:40
Avatar de Naahuel
Naahuel
 
Fecha de Ingreso: marzo-2011
Ubicación: localhost
Mensajes: 796
Antigüedad: 13 años, 1 mes
Puntos: 192
Respuesta: Uso los comentarios de facebook en mi wordpress, como se que alguien ha co

Uf, yo estuve en esas. Te explico lo que yo hice. Lo hice hace un tiempo luego de frustrarme buscando alguna solución más eficaz y sencilla.

Nota: Para hacer esto necesitás acceso al servidor por FTP y modificar archivos del theme.

Creá un archivo javascript con este contenido. Llamalo como quieras. notificacionesFacebook.js por ejemplo.

Código Javascript:
Ver original
  1. /*
  2.     Notificaciones de email para comentarios de facebook.
  3.     Nahuel Jose
  4.     http://www.nahueljose.com.ar
  5.  */
  6.  
  7. function fbCommNotificar(sendPath) {
  8.     FB.Event.subscribe('comment.create', function(response) {
  9.  
  10.         // Nombre de la pagina
  11.         var siteName =  $('title').html();
  12.        
  13.         // Titulo de la pagina
  14.         var pageTitle =  $('title').html();
  15.  
  16.         // Url de la pagina
  17.         var pageURL =  document.location.href;
  18.  
  19.         // obtener los ultimos comentarios de la pagina
  20.         $.ajax({
  21.             url:'https://graph.facebook.com/comments/?ids=' + pageURL + '&' + Math.floor(Math.random()*101),
  22.             dataType: 'json',
  23.             success: function(results){
  24.                 allResults = results[pageURL].data;
  25.                 lastResult = allResults[allResults.length-1];
  26.                
  27.                 // enviar el email
  28.                 $.post(sendPath,{ name: lastResult.from.name, message : lastResult.message, page_url : pageURL, page_title : pageTitle});
  29.             }
  30.         });
  31.     });
  32. }

Ahora en header.php, incluye jQuery (si es que no está ya) y ese script.
Luego ubicá esta línea (la tenés que haber incluido a la hora de insertar el plugin de facebook comments:
Código Javascript:
Ver original
  1. FB.init({appId: 'ID-DE-TU-APP', status: true, cookie: true, xfbml: true});
Y debajo colocá:
Código Javascript:
Ver original
  1. fbCommNotificar('<?php bloginfo('template_directory') ?>/comentarios.php');};

Ambas líneas deberían estar dentro de una función algo así:

Código Javascript:
Ver original
  1. window.fbAsyncInit = function() {
  2.     FB.init({appId: 'ID-DE-TU-APP', status: true, cookie: true, xfbml: true});
  3.     fbCommNotificar('<?php bloginfo('template_directory') ?>/comentarios.php');
  4. };

fbCommNotificar() es una función en javascript que recibe como parámetro un archivo php (en mi caso comentarios.php) que obtiene los datos que se le está pasando y los manda por mail.

Cuando se crea un comentario, la api de facebook dispara un evento (comment.create). Lo que hacemos es suscribirnos a ese evento y cuando se dispara, enviar un email.

Ojo!: Para obtener el último comentario uso $.ajax() para leer un objeto json. Si alguien responde a un comentario, vas a recibir notificación del comentario padre (otra vez). O sea, te llega un mail, pero el comentario que figura es al que se ha respondido, no la respuesta. Esto es porque no me tomé el trabajo de analizar esos casos.

Ejemplo de archivo PHP para enviar comentarios:

Código PHP:
Ver original
  1. <?php
  2.     $recipient  = "[email protected]";
  3.     $from       = "Quien Manda <[email protected]>";
  4.    
  5.     $name       = urldecode($_REQUEST['name']);
  6.     $message    = urldecode($_REQUEST['message']);
  7.     $page_url   = urldecode($_REQUEST['page_url']);
  8.     $page_title = urldecode($_REQUEST['page_title']);
  9.    
  10.    
  11.     $subject    = $name . " hizo un comentario en Tu Sitio";
  12.    
  13.     if($name=='' || $message == ''){
  14.         die('<h1>Forbidden</h1>');
  15.     }
  16.    
  17.     $HTML = '<html><body style="text-align:center; padding:20px;">';
  18.     $HTML.= '<h1>' . $subject . '</h1>';
  19.     $HTML.= '<table align="center" width="500" style="text-align:left; vertical-align:top;">';
  20.     $HTML.= "<tr><td style='vertical-align:top; color:#000; width:20%;'><strong>Nombre</strong></td><td>$name</td></tr>";
  21.     $HTML.= "<tr><td style='vertical-align:top; color:#000; width:20%;'><strong>Mensaje</strong></td><td>$message</td></tr>";
  22.     $HTML.= "<tr><td style='vertical-align:top; color:#000; width:20%;'><strong>P&aacute;gina</strong></td><td>$page_url</td></tr>";
  23.     $HTML.= "<tr><td style='vertical-align:top; color:#000; width:20%;'><strong>T&iacute;tulo</strong></td><td>$page_title</td></tr>";
  24.     $HTML.= "</table>";
  25.     $HTML.= "<hr />";
  26.     $HTML.= "<p><a href='$page_url'#encargar>Revis&aacute; siempre que recibas este mail que no halla m&aacute;s comentarios! Click ac&aacute;.</a></p>";
  27.     $HTML.= "</body></html>";
  28.    
  29.     if(sendHTMLemail($HTML,$from, "$name <$email>", $recipient, $subject)){
  30.         echo 'Exito';
  31.     }
  32.     die;
  33.    
  34.     function sendHTMLemail($HTML,$from,$reply_to,$to,$subject)
  35.     {
  36.         $headers = "From: $from\r\n";
  37.         $headers .= "Reply-To:$reply_to\r\n";
  38.         $headers .= "Return-Path:$reply_to\r\n";
  39.         $headers .= "MIME-Version: 1.0\r\n";
  40.         $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
  41.        return mail($to,$subject,$HTML,$headers);
  42.     }
  43. ?>
__________________
nahueljose.com.ar