function processXML(&$xml, &$stack, $name) { $frame = array(); $value = null; while ($xml->read()) { switch ($xml->nodeType) { case XMLReader::ELEMENT: $elementName = $xml->name; // echo str_repeat( "\t", count( $stack ) ) . $elementName . ' {' . "\n"; if (!$xml->isEmptyElement) { $stack[] =& $frame; $return = processXML($xml, $stack, $elementName); if ($return !== null) { $frame[$elementName] = $return; } array_pop($stack); } /* else echo str_repeat( "\t", count( $stack ) ) . '} //' . $elementName . "\n";*/ break; case XMLReader::END_ELEMENT: // echo str_repeat( "\t", count( $stack ) - 1 ) . '} //' . $name . "\n"; if ($name == 'Edit') { processEdit($stack, $frame); } if ($value !== null) { return $value; } return null; case XMLReader::TEXT: case XMLReader::CDATA: $value = $xml->value; } } }
function processTweet($tweet) { // who wrote the tweet? $contents = strtolower($tweet->text); // if we're testing, only allow test tweets through // (if we're not testing, don't allow test tweets through!) global $testing; if ($testing == true && strpos($contents, "#test") === false || $testing != true && strpos($contents, "#test") !== false) { return $tweet->id_str; } loginfo("Processing tweet " . $tweet->id_str . " from user " . $tweet->user->screen_name . "\n" . $contents); // Or we can adjust it, which basically just performs a delete // followed by a new insert $tweet->information = getTweetInformation($tweet); // If we're registering a new challenger! $processed = false; $register = strpos($contents, "#register"); if ($register !== false) { processRegistration($tweet); $processed = true; } // We can "delete" a tweet with the undo tag $undo = strposa($contents, array("#undo", "#delete")); if (!$processed && $undo !== false) { // basically change the 'inc_' to 'del_' processUndo($tweet); $processed = true; } // We can edit an existing tweet $edit = strposa($contents, array("#edit", "#update")); if (!$processed && $edit !== false) { processEdit($tweet); $processed = true; } // filter now for ID/Events - we can only run the following on single events if (!$processed && findEntryId($tweet) < 0) { // we count errors as processing, because we've replied replyEntryErrorTweet($tweet); $processed = true; } // If we're removing an entry $giveup = strpos($contents, "#giveup"); if (!$processed && $giveup !== false) { processGiveup($tweet); $processed = true; } // If we're processing content if (!$processed && $tweet->information->contenttype) { processContent($tweet); $processed = true; } // If we got this far and still didn't process it, there's something wrong if (!$processed) { } // After processing, return the ID if (!$testing) { return $tweet->id_str; } }