You are here

function commons_media_filter_parse_from_fields in Drupal Commons 7.3

Parse file references from an entity's text fields and return them as an array.

1 call to commons_media_filter_parse_from_fields()
commons_media_entity_field_count_files in modules/commons/commons_media/commons_media.private_files.inc
Utility function to get the file count in this entity

File

modules/commons/commons_media/commons_media.private_files.inc, line 94
Functions related to ensuring that the private file system is used when embedding files in private group content.

Code

function commons_media_filter_parse_from_fields($entity_type, $entity) {
  $file_references = array();
  foreach (media_wysiwyg_filter_fields_with_text_filtering($entity_type, $entity) as $field_name) {
    if ($field_items = field_get_items($entity_type, $entity, $field_name)) {
      foreach ($field_items as $field_item) {
        preg_match_all(MEDIA_WYSIWYG_TOKEN_REGEX, $field_item['value'], $matches);
        foreach ($matches[0] as $tag) {
          $tag = str_replace(array(
            '[[',
            ']]',
          ), '', $tag);
          $tag_info = drupal_json_decode($tag);
          if (isset($tag_info['fid']) && $tag_info['type'] == 'media') {
            $file_references[] = $tag_info;
          }
        }
        preg_match_all(MEDIA_WYSIWYG_TOKEN_REGEX, $field_item['value'], $matches_alt);
        foreach ($matches_alt[0] as $tag) {
          $tag = urldecode($tag);
          $tag_info = drupal_json_decode($tag);
          if (isset($tag_info['fid']) && $tag_info['type'] == 'media') {
            $file_references[] = $tag_info;
          }
        }
      }
    }
  }
  return $file_references;
}