loadXML( $xmlAsString ); if ( $rssDoc == null ) { sendError( "no rss doc was parssed." ); } $rssRoot = findFirstChild( $rssDoc, "statuses" ); // start output document $outDoc = new DOMDocument(); $outRoot = $outDoc->createElement("msgs"); $outDoc->appendChild( $outRoot ); $commentElement = $outDoc->createComment("url: " . $twitterUrl ); $outRoot->appendChild( $commentElement ); // read the first N entries $rssItem = findFirstChild( $rssRoot, "status" ); if (!$rssItem) { sendError( "found no status." ); } while ( $maxEntries > 0 && $rssItem ) { $rssEntryTitle = findFirstChild( $rssItem, "text" ); if ( !$rssEntryTitle ) { sendError( "found no text" ); } $comment = GetContentAsString( $rssEntryTitle ); $rssUser = findFirstChild( $rssItem, "user" ); $rssUserName = findFirstChild( $rssUser, "screen_name" ); $name = GetContentAsString( $rssUserName ); $rssIcon = findFirstChild( $rssUser, "profile_image_url" ); $iconUrl = GetContentAsString( $rssIcon ); // check the comment for the magic chars, if they are there, then // strip it, and get the username from the comment if ( strpos( $comment, $magicChars ) === 0 ) { // remove $magicChars $comment = substr( $comment, strlen($magicChars) ); $commaIndex = strpos( $comment, "," ); $name = substr( $comment, 0, $commaIndex ); $comment = substr( $comment, $commaIndex+1 ); } $outMessageElement = addTextChild($outDoc, $outRoot, "m", null ); addTextChild( $outDoc,$outMessageElement, "n", $name ); addTextChild( $outDoc,$outMessageElement, "i", $iconUrl ); addTextChild( $outDoc,$outMessageElement, "t", $comment ); // get the id $rssEntryId = findFirstChild( $rssItem, "id" ); $idText = GetContentAsString( $rssEntryId ); addTextChild( $outDoc,$outMessageElement, "g", $idText ); // get next $rssItem = findNextSib( $rssItem, "status" ); $maxEntries--; } // output the new feed echo $outDoc->saveXML(); function addTextChild( $doc, $parentTag, $tagName, $text ) { $child = $doc->createElement( $tagName ); $parentTag->appendChild( $child ); if ( $text != null ) { $textNode = $doc->createTextNode( $text ); $child->appendChild( $textNode ); } return $child; } function getPublicTwitter( $username ) { global $twitterUrl; $url = "http://twitter.com/statuses/friends_timeline/".$username.".xml"; $httpDate = gmdate("D, d M Y H:i:s", getlastmod()) . " GMT"; $url .= "?&cb=" . time() . "&since=" . urlencode( $httpDate ); $twitterUrl = $url; $ch = curl_init(); //curl_setopt($ch, CURLOPT_VERBOSE, true ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true ); curl_setopt($ch, CURLOPT_URL, $url ); curl_setopt($ch, CURLOPT_HEADER, 0 ); curl_setopt($ch, CURLOPT_TIMECONDITION, URL_TIMECOND_IFMODSINCE ); $xml = curl_exec($ch); curl_close($ch); return $xml; } function getTwitterFriendsXml($username, $password) { $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true ); $user = $username . ":" . $password; curl_setopt($ch, CURLOPT_USERPWD, $user ); curl_setopt($ch, CURLOPT_URL, "http://twitter.com/statuses/friends_timeline.xml" ); $xml = curl_exec($ch); curl_close($ch); return $xml; } function debug( $msg ) { } function sendError( $msg ) { echo $msg; die(); } function findNextSib( $element, $tagName ) { $child = $element->nextSibling; while ( $child ) { if ( $child->nodeName == $tagName ) { return $child; } $child = $child->nextSibling; } return null; } function findFirstChild( $element, $tagName ) { $child = $element->firstChild; while ( $child ) { if ( $child->nodeName == $tagName ) { return $child; } $child = $child->nextSibling; } return null; } function GetContentAsString($node) { return $node->textContent; } function findUserProfileIcon($username) { } ?>