query($path, $node); if ($nodes->length > 0) { return $nodes->item(0)->nodeValue; } return "NONE"; } function filterDocument(&$doc, &$xpath) { $summaries = $xpath->query( "//item/description | ". "//atom03:entry/atom03:summary | ". "//atom03:entry/atom03:content[@type='text/html'] | ". "//rss10:item/content:encoded" ); $api_url = "http://api.technorati.com/cosmos?key=".TECHNORATI_KEY."&url="; foreach ($summaries as $summary) { $link_path = '../link | ../rss10:link | ../atom03:link/@href | ../atom10:link/@href'; $link = $this->xpathVal($xpath, $link_path, $summary); $out = array(); $cache =& new HTTPCache($api_url.urlencode($link)); $api_doc = new DOMDocument(); $api_doc->loadXML($cache->fetch()); $api_xpath = new DOMXPath($api_doc); $api_nodes = $api_xpath->query('//weblog'); if ($api_nodes->length > 0) { foreach ($api_nodes as $api_node) { $api_name = $this->xpathVal($api_xpath, './name', $api_node); $api_link = $this->xpathVal($api_xpath, '../nearestpermalink', $api_node); array_push($out, "$api_name"); } } if ($out) { $cn = $doc->createCDATASection("
". "Technorati Related Links:
"); $summary->appendChild($cn); } } return $doc; } } // Instantiate and run the filter only when not being used as an include. if (strpos(basename(__FILE__), basename($_SERVER['SCRIPT_FILENAME'])) !== false) { processFilter(new TechnoratiFilter()); } ?>