You are here

function drupagram_media_save in Drupagram 6

Same name and namespace in other branches
  1. 7 drupagram.inc \drupagram_media_save()

Saves a InstagramMedia object to {drupagram}

1 call to drupagram_media_save()
drupagram_fetch_recent_items in ./drupagram.inc
Fetches a user's recent items.

File

./drupagram.inc, line 147
Instagram API functions

Code

function drupagram_media_save($media) {
  $drupagram = array(
    'drupagram_id' => check_plain($media->id),
    'username' => drupagram_emoji($media->user->username),
    'type' => filter_xss($media->type),
    'images' => serialize($media->images),
    'location' => serialize($media->location),
    'comments' => serialize(drupagram_emoji($media->comments)),
    'caption' => serialize(drupagram_emoji($media->caption)),
    'link' => drupagram_emoji($media->link),
    'likes' => serialize(drupagram_emoji($media->likes)),
    'filter' => filter_xss($media->filter),
    'created_at' => format_date($media->created_time, 'long'),
    'created_time' => $media->created_time,
    'endpoint_type' => t("user_recent"),
  );
  $drupagram_media_count = db_result(db_query("SELECT count(da.drupagram_id) FROM {drupagram} da WHERE da.drupagram_id = '%s'", $drupagram['drupagram_id']));
  $drupagram = (object) $drupagram;
  if ($drupagram_media_count) {
    drupal_write_record("drupagram", $drupagram, "drupagram_id");
  }
  else {
    drupal_write_record("drupagram", $drupagram);
  }
}