* @version 0.1 */ if (!file_exists("xmlrpc.php")) die("Este script requiere The Inutio XML-RPC Library (http://scripts.incutio.com/xmlrpc/)"); require_once("xmlrpc.php"); if (file_exists("Akismet.class.php")) require_once("Akismet.class.php"); /** * Constantes necesarias para Akismet */ define('AKISMETURL','AKISMET_URL'); define('AKISMETKEY','AKISMET_KEY'); /** * wpComment * * Clase encargada de conectar con el API */ class wpComment { var $user = null; var $pass = null; var $blogurl = null; /** * __construct() * * Constructor de la clase. * @param String $blogurl * @param String $user * @param String $pass */ function __construct($blogurl = "", $user = "", $pass = "") { if (empty($blogurl)) die("Necesito una URL para funcionar"); $this->blogurl = $this->cleanString($blogurl); $this->user = $this->cleanString($user); $this->pass = $this->cleanString($pass); } /** * insert() * * Inserta un comentario en el blog deseado. * @param String $post_link * @param String $author * @param String $author_email * @param String $author_url * @param String $content * @return integer|comment_id */ function insert($post_link = "", $author = "", $author_email = "", $author_url = "", $content = ""){ if (empty($post_link) || empty($author) || empty($author_email) || empty($author_url) || empty($content)) die("Faltan datos"); $post_link = $this->cleanString($post_link); $autor = $this->cleanString($author); $author_email = $this->cleanString($author_email); $author_url = $this->cleanString($author_url); $content = $this->cleanString($content); if (class_exists('Akismet')) { $akismet = new Akismet(AKISMETURL, AKISMETKEY); $akismet->setCommentAuthor($author); $akismet->setCommentAuthorEmail($author_email); $akismet->setCommentAuthorURL($author_url); $akismet->setCommentContent($content); $akismet->setPermalink($post_link); if($akismet->isCommentSpam()) $this->SPAM(); } return $this->send('wp.newComment', array( $post_link, array ( 'author' => $author, 'author_email' => $author_email, 'author_url' => $author_url, 'content' => $content ) )); } /** * getComments() * * Devuelve los comentarios del blog. * @param Array $options * @return Array|comments */ function getComments($options =""){ $default = array('post_id' => '', 'status' => '', 'offset' => '', 'number' => ''); $options = array_merge( $default, $options); return $this->send('wp.getComments', array( array( 'post_id' => $options['post_id'], 'status' => $options['status'], 'offset' => $options['offset'], 'number' => $options['number'] ) )); } /** * getComments() * * Devuelve un array con la información del comentario solicitado. * @param int $comment_id * @return Array|comment */ function getComment($comment_id = ''){ if (empty($comment_id)) die("Error, el ID del comentario no es válido"); return $this->send('wp.getComment', array(intval($comment_id))); } /** * send() * * Método encargado de enviar la petición * @param String $type * @param Array $options * @return Object|response */ function send($type = "", $options = ""){ if (!class_exists('IXR_Client')) die("Falta IXR_Client"); $default = array(1, $this->user, $this->pass); $options = array_merge( $default, $options); $client = new IXR_Client($this->blogurl); if (!$client->query($type,$options)){ die('Ha saltado un error - '.$client->getErrorCode().":".$client->getErrorMessage()); } return $client->getResponse(); } /** * cleanString() * * Método que limpia cadenas * @param String $str * @return String|str */ function cleanString($str){ return trim(addslashes(strip_tags($str))); } /** * SPAM() * * Mata la ejecución del proceso por SPAM */ function SPAM(){ die("Akismet lo ha detectado como SPAM"); } } ?>