Created
November 17, 2008 17:32
-
-
Save ahutchings/25834 to your computer and use it in GitHub Desktop.
Gnip Push Recipient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Database connection information | |
$host = 'localhost'; | |
$user = 'gnip'; | |
$pass = 'gnip'; | |
$db = 'gnip'; | |
$table = 'activity'; | |
// Read raw post data | |
$input = fopen('php://input','rb'); | |
$xml = stream_get_contents($input); | |
fclose($input); | |
// Parse the posted XML activity feed & exit if no info was posted | |
if (!$activities = simplexml_load_string($xml)) { | |
exit(); | |
} | |
try { | |
// Create database connection | |
$pdo = new PDO("mysql:host=$host;dbname=$db", $user, $pass); | |
// Prepare the insert statement | |
$insert = $pdo->prepare('INSERT INTO ' . $table | |
. ' (time, uid, type, guid, publisher_name) ' | |
. ' VALUES ' | |
. '( :time, :uid, :type, :guid, :publisher_name )' | |
); | |
// Insert the activities into the database | |
foreach ($activities as $activity) { | |
$insert->bindValue(':time', $activity['at']); | |
$insert->bindValue(':uid', $activity['uid']); | |
$insert->bindValue(':type', $activity['type']); | |
$insert->bindValue(':guid', $activity['guid']); | |
$insert->bindValue(':publisher_name', $activity['publisher.name']); | |
$insert->execute(); | |
} | |
} catch (PDOException $e) { | |
// You'll probably want to log this message instead of echoing it | |
echo $e->getMessage(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment