You are here

function oembed_entity_insert in oEmbed 7.0

Implements hook_entity_insert().

1 call to oembed_entity_insert()
oembed_entity_update in ./oembed.filter.inc

File

./oembed.filter.inc, line 351
Input filter that enhances oEmbed enabled URLs with extra content

Code

function oembed_entity_insert($entity, $entity_type) {
  if (module_exists('file_entity')) {
    list($id, , ) = entity_extract_ids($entity_type, $entity);
    $uris = array();
    foreach (_oembed_field_extract_urls($entity_type, $entity) as $items) {
      foreach ($items as $item) {
        foreach ($item as $urls) {
          foreach ($urls as $url) {
            $uris[$url] = isset($uris[$url]) ? $uris[$url] + 1 : 1;
          }
        }
      }
    }
    foreach ($uris as $url => $count) {
      $file = oembed_url_to_file($url, TRUE);
      file_usage_delete($file, 'oembed', $entity_type, $id, 0);
      file_usage_add($file, 'oembed', $entity_type, $id, $count);
    }
  }
}