You are here

function mediafront_add_media in MediaFront 6

Same name and namespace in other branches
  1. 6.2 mediafront.module \mediafront_add_media()
  2. 7 mediafront.module \mediafront_add_media()

Function that will add media to the $additions array

3 calls to mediafront_add_media()
mediafront_audio_playlist_node in plugins/mediafront_audio/mediafront_audio.module
Implementation of hook_playlist_node
mediafront_emfield_playlist_node in plugins/mediafront_emfield/mediafront_emfield.module
Implementation of hook_playlist_node
mediafront_playlist_node in ./mediafront.module
Implementation of hook_playlist_node()

File

./mediafront.module, line 780

Code

function mediafront_add_media(&$additions, $file) {
  $media_added = false;

  // Only continue if the file exists.
  if ($file) {

    // Convert the file to an object.
    $file = is_array($file) ? mediafront_array_to_object($file) : $file;

    // If the file exists.
    if ($media_file = mediafront_get_media_file($file)) {
      if ($media_file->class && $media_file->mediaType) {
        if ($media_file->mediaType != "image" && isset($additions["mediafiles"][$media_file->class][$media_file->mediaType])) {
          $media = $additions["mediafiles"][$media_file->class][$media_file->mediaType];
          $files = is_array($media) ? $media : array(
            $media,
          );
          array_push($files, $media_file);
          $additions["mediafiles"][$media_file->class][$media_file->mediaType] = $files;
          $media_added = true;
        }
        else {
          $additions["mediafiles"][$media_file->class][$media_file->mediaType] = $media_file;
          $media_added = true;
        }
      }
    }
  }
  return $media_added;
}