/* TrackBack Counter cogdogblog http://cogdogblog.com/alan/archives/000097.html The script will walk the Trackback XML files (tb_rss/*.xml) using the filename (*) to identify the item ID, and counting ITEM tags in the XML to get a proper count */ function trackbackCount($filetrack) { /* <g;tiphat> http://www.movabletype.org/trackback/archives/000668.html </tiphat> Slightly modified from original to simply (use ++ for increment, un-needed else statement) function expects path to .xml file to be counted as input param */ $numero = 0; if (file_exists($filetrack)) { $fichero = "$filetrack"; $fxml = fopen( $fichero,"r"); while (!feof($fxml)) { $xmlreg = fgets($fxml, 4096); $item = substr($xmlreg,0,6); if ($item == "") $numero++; } fclose($fxml); } return $numero; } // relative path to directory for Trackback XML files $tb_dir = "../tb_rss"; // try and open the directory for reading file names if ($handle = opendir($tb_dir)) { // array to hold data file names $tb_files = array(); // read in file names to array, skip the directory // items while (($file = readdir($handle))!==false) { if ( $file != "." && $file != "..") { $tb_files[] = $file; } } closedir($handle); // walk the XMl files, count pings, and update foreach ($tb_files as $item) { // extract the TB id number from the file name (drop the ".xml") $pk = substr($item, 0, -4); // count the pings $tb_count = trackbackCount("$tb_dir/$item"); // feedback just for testing purposes echo "tb id#$pk (count=$tb_count)\n"; } }