', '>', $text); if ( 'double' === $quotes ) { $text = str_replace('"', '"', $text); } elseif ( 'single' === $quotes ) { $text = str_replace("'", ''', $text); } elseif ( $quotes ) { $text = str_replace('"', '"', $text); $text = str_replace("'", ''', $text); } return $text; } function pbprocess($m) { global $xmlrpcerruser; $x1 = $m->getParam(0); $x2 = $m->getParam(1); $pagelinkedfrom = $x1->scalarval(); # their article $pagelinkedto = $x2->scalarval(); # your article /* $fp = fopen('data.txt', 'a'); fwrite($fp, $pagelinkedfrom.' - '.$pagelinkedto.chr(10)); fclose($fp); */ // Check if the page linked to is in our site $pos1 = strpos($pagelinkedto, str_replace(array('http://www.','http://','https://www.','https://'), '', 'http://www.koreus.com')); if( !$pos1 ) return new xmlrpcresp(0, 16, "Is there no link to us?"); // Site spam // euroxis real-url.org www.hilpers.fr #post $pos1 = ((strpos($pagelinkedfrom, 'tv4foot.com')) or (strpos($pagelinkedfrom, 'news-iphone4g.com')) or (strpos($pagelinkedfrom, 'sansbouger.com')) or (strpos($pagelinkedfrom, 'topsy.com')) or (strpos($pagelinkedfrom, 'euroxis')) or (strpos($pagelinkedfrom, 'realurl.org')) or (strpos($pagelinkedfrom, 'real-url.org')) or (strpos($pagelinkedfrom, 'hilpers.fr')) or (strpos($pagelinkedfrom, '#post'))); if( $pos1!==false ) return new xmlrpcresp(0, 16, "I don't like you"); $linea = remote_fopen( $pagelinkedfrom ); if ( !$linea ) return new xmlrpcresp(0, 16, "The source URL does not exist."); // Work around bug in strip_tags(): $linea = str_replace(']*>/", "\n\n", $linea ); preg_match('|([^<]*?)|is', $linea, $matchtitle); $title = $matchtitle[1]; if ( empty( $title ) ) return new xmlrpcresp(0, 32, "We cannot find a title on that page."); $linea = strip_tags( $linea, '' ); // just keep the tag we need $p = explode( "\n\n", $linea ); $preg_target = preg_quote($pagelinkedto); foreach ( $p as $para ) { if ( strpos($para, $pagelinkedto) !== false ) { // it exists, but is it a link? preg_match("|]+?".$preg_target."[^>]*>([^>]+?)|", $para, $context); // If the URL isn't in a link context, keep looking if ( empty($context) ) continue; // We're going to use this fake tag to mark the context in a bit // the marker is needed in case the link text appears more than once in the paragraph $excerpt = preg_replace('|\|', '', $para); // prevent really long link text if ( strlen($context[1]) > 100 ) $context[1] = substr($context[1], 0, 100) . '...'; $marker = ''.$context[1].''; // set up our marker $excerpt= str_replace($context[0], $marker, $excerpt); // swap out the link for our marker $excerpt = strip_tags($excerpt, ''); // strip all tags but our context marker $excerpt = trim($excerpt); $preg_marker = preg_quote($marker); $excerpt = preg_replace("|.*?\s(.{0,100}$preg_marker.{0,100})\s.*|s", '$1', $excerpt); $excerpt = strip_tags($excerpt); // YES, again, to remove the marker wrapper break; } } if ( empty($context) ) // Link to target not found return new xmlrpcresp(0, 17, "The source URL does not contain a link to the target URL, and so cannot be used as a source."); // On test ici si la destination est un article, forum ou media. /* if (preg_match("/http:\/\/www.koreus.com\/modules\/news\/article([0-9]+).html/", $pagelinkedto, $matches)) { //echo 'Article : '.$matches[1].'
'; $dest=$matches[1]; $dest_type=0; } elseif (preg_match("/http:\/\/www.koreus.com\/modules\/newbb\/topic([0-9]+).html/", $pagelinkedto, $matches)) { //echo 'Forum : '.$matches[1].'
'; $dest=$matches[1]; $dest_type=1; } */ if (preg_match("/http:\/\/www.koreus.com\/(video|jeu|animation|image|audio)\/([a-zA-Z0-9\-_]+).html/", $pagelinkedto, $matches)) { //echo 'Media : '.$matches[2].'
'; $dest=$matches[2]; $dest_type=2; } else { //echo 'Autre : '.$matches[1].'
'; $dest=$pagelinkedto; $dest_type=3; } // if (..) { # target uri does not exist // return new xmlrpcresp(0, 32, "Target uri does not exist"); // } // Let's check that the remote site didn't already pingback this entry $sql=sprintf('SELECT * from pingback WHERE source="%s" AND dest="%s" and dest_type=%d', $pagelinkedfrom, $dest, $dest_type); $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if ( $num_rows ) // We already have a Pingback from this URL return new xmlrpcresp(0, 48, "The pingback has already been registered."); $sql=sprintf('INSERT INTO pingback (post_time, source, dest, dest_type) VALUES (NOW(), "%s", "%s", %d)', $pagelinkedfrom, $dest, $dest_type); $result = mysql_query($sql); $pingback_id=mysql_insert_id(); // EXEMPLE WORDPRESS A MODIFIER pour rajouter le PINGBACK en commentaire $title1=utf8_decode($title); $text=utf8_decode(wp_specialchars( $excerpt )); $context = chr(10).'[url='.$pagelinkedfrom.']'.$title.'[/url]'.chr(10).chr(10).'[...] ' . wp_specialchars( $excerpt ) . ' [...]'; $context = utf8_decode($context); $pagelinkedfrom = str_replace('&', '&', $pagelinkedfrom); $title='Pingback'; switch ($dest_type) { case 0 : $sql=sprintf('INSERT INTO xoops_xoopscomments (com_modid, com_itemid, com_created, com_modified, com_uid, com_ip, com_title, com_text, com_status, doxcode, dobr) VALUES (2, %s, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 2, "127.0.0.1", "%s","%s", 2,1,1)', $dest, mysql_real_escape_string($title), mysql_real_escape_string($context)); //echo $sql.'
'; $result = mysql_query($sql); break; case 1 : $sql=sprintf('SELECT post_id, forum_id from xoops_bb_posts where topic_id=%s and pid=0', $dest); //echo $sql.'
'; $result = mysql_query($sql); // Si on ne trouve pas le topic concerné, alors on retourne une erreur $num_rows = mysql_num_rows($result); if ($num_rows<>1) return new xmlrpcresp(0, 33, "Target uri cannot be used as target"); $row1 = mysql_fetch_array($result); $post_id=$row1['post_id']; $forum_id=$row1['forum_id']; $dateheure=time(); $sql=sprintf('INSERT INTO xoops_bb_posts (pid, topic_id, forum_id, post_time, uid, poster_ip, subject, doxcode, dobr) VALUES (%d, %s, %d, %d, 2, "127.0.0.1", "%s", 1,1)', $post_id, $dest, $forum_id, $dateheure, mysql_real_escape_string($title)); //echo $sql.'
'; $result = mysql_query($sql); $newpost_id=mysql_insert_id(); $sql=sprintf('INSERT INTO xoops_bb_posts_text (post_id, post_text) VALUES (%d, "%s")', $newpost_id, mysql_real_escape_string($context)); //echo $sql.'
'; $result = mysql_query($sql); $sql=sprintf('UPDATE xoops_bb_topics SET topic_last_post_id=%d, topic_time=%d, topic_replies=topic_replies+1 WHERE topic_id=%s', $newpost_id, $dateheure, $dest); //echo $sql.'
'; $result = mysql_query($sql); //$sql=sprintf('UPDATE xoops_bb_forums SET forum_last_post_id=%d, forum_posts=forum_posts+1 WHERE forum_id=%d', $newpost_id, $forum_id); //echo $sql.'
'; //$result = mysql_query($sql); break; case 2: $sql=sprintf('INSERT INTO media_pingback (filename, pb_id, title, text) VALUES ("%s", %d, "%s", "%s")', $dest, $pingback_id, mysql_real_escape_string($title1), mysql_real_escape_string($text)); //echo $sql.'
'; $result = mysql_query($sql); break; default: return new xmlrpcresp(0, 33, "Target uri cannot be used as target"); } /* if (..) { # target uri cannot be used as target return new xmlrpcresp(0, 33, "Target uri cannot be used as target"); } if (..) { # Access denied return new xmlrpcresp(0, 49, "Access denied"); } if (..) { # Could not communicate with upstream server or got error return new xmlrpcresp(0, 50, "Problem with upstream server"); } if (..) { # Generic fault code if not applicable to above return new xmlrpcresp(0, 50, "Unkown error"); } */ return new xmlrpcresp(new xmlrpcval("Pingback registered. May the force be with you.", "string")); } $connect_db = connect(); $a = array( "pingback.ping" => array( "function" => "pbprocess" )); $s = new xmlrpc_server($a, false); //$s->setdebug(3); $s->service(); close(); ?>