Skip to content

Instantly share code, notes, and snippets.

@johnrobertwilson
Created January 23, 2012 23:01
Show Gist options
  • Save johnrobertwilson/1666187 to your computer and use it in GitHub Desktop.
Save johnrobertwilson/1666187 to your computer and use it in GitHub Desktop.
media savw
/**
* Saves a InstagramMedia object to {drupagram}
*/
function drupagram_media_save($media) {
// Cleanse the full_name field of bad chars
if (!empty($media)) {
if (!empty($media->likes)) {
if (!empty($media->likes['data'])){
foreach ($media->likes['data'] as $index => $like_item) {
$media->likes['data'][$index]['full_name'] = stripslashes($like_item['full_name']);
}
}
}
}
$drupagram = array(
'drupagram_id' => $media->id,
'username' => $media->user->username,
'type' => $media->type,
// 'tags' => serialize($media->tags),
'images' => serialize($media->images),
'location' => serialize($media->location),
'comments' => serialize($media->comments),
'caption' => $media->caption,
'link' => $media->link,
'likes' => serialize($media->likes),
'filter' => $media->filter,
'created_at' => $media->created_time,
'created_time' => $media->created_time,
);
$drupagram = array_filter($drupagram);
db_merge('drupagram')
->key(array('drupagram_id' => $drupagram['drupagram_id']))
->fields($drupagram)
->execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment