<?

/*
Backlinks via Technorati
Idee von Peter Schink am 22.10.2006
Version 0.1
Quelle: http://www.blogh.de/654
*/

/* ------------ VARIABLEN ------------- */

$db_host "localhost";
$db_user "mysql_user";
$db_password "mysql_password";

$db_posts "blogtexte";
$db_comments "blogkommentare";


/* ------------ DATENBANK CONNECT ------------- */

$link mysql_connect($db_host$db_user$db_password);
if (!
$link) {
   die(
'Could not connect: ' mysql_error());
}
echo 
'Connected successfully';


/* ------------ GET YOUR PERMALINKS, TECHNORATI NEEDS THEM ------------- */

$id mysql_query("SELECT id,permalink FROM $db_posts ORDER BY id DESC");

while (
$eintrag = @mysql_fetch_array($id))
{
hole_feed($eintrag[id], $eintrag[permalink]);
}


/* ------------ ASK TECHNORATI FOR LINKS, POST BY POST ------------- */


function hole_feed($id$permalink)
{
global 
$db_comments;
echo 
"<h4>Your Post, ID $id</h4>";

  
$url "http://feeds.technorati.com/search/" $permalink;
  
$feed join(''file($url));
  @
preg_match_all("=<item>.*<title>(.*)</title>.*<link>(.*)</link>.*<description>(.*)</description>.*</item>=siU",$feed$result);

  if (
sizeof($result) > 1)
  { 
  for(
$i=0$i sizeof($result[1]); $i++)
    {
    
$title $result[1][$i];
    
$link  $result[2][$i];
    
$text  $result[3][$i];

    if (!
eregi('de$|net$|com$|org$|info$|blog$'$link)) // Technorati-Fehler ausschließen
       

       
$vorhanden mysql_query("SELECT id FROM $db_comments WHERE textid = '$id' AND url = '$link' LIMIT 1");  // bereits erledigte Einträge ausschließen
       
$vorhanden = @mysql_result($vorhanden0); 
       if (
$vorhanden 1)
          {
          
mysql_query("INSERT INTO $db_comments SET textid = '$id', url = '$link', autor = '$title', text = '$text', trackback = '1'");
          echo 
"<p><a href=\"$link\" title=\"zum Blogeintrag\">$link</a></p>\n";
          }
       }
    }
  }
}

?>