You are here

function mediafront_playlist_node in MediaFront 6

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

Implementation of hook_playlist_node()

File

./mediafront.module, line 834

Code

function mediafront_playlist_node($node) {
  $media_added = false;
  $additions = array();
  $field_additions = array();

  // Iterate through the files.
  if (isset($node->files) && $node->files && is_array($node->files)) {
    foreach ($node->files as $fid => $file) {
      $media_added |= mediafront_add_media($additions, $file);
    }
  }

  // If they provide the field_mediafront_image field.
  if ($field = _mediafront_get_field($node, 'field_dashplayer_media', 0)) {
    $media_added = true;
    $additions["mediafiles"]["media"]["media"] = $field['value'];
  }

  // If they provide the field_mediafront_image field.
  if ($field = _mediafront_get_field($node, 'field_dashplayer_image', 0)) {
    $media_added = true;
    $additions["mediafiles"]["images"]["image"] = $field['value'];
  }

  // If they provide the field_mediafront_media field.
  if ($field = _mediafront_get_field($node, 'field_mediafront_media', 0)) {
    $media_added = true;
    $additions["mediafiles"]["media"]["media"] = $field['value'];
  }

  // If they provide the field_mediafront_image field.
  if ($field = _mediafront_get_field($node, 'field_mediafront_image', 0)) {
    $media_added = true;
    $additions["mediafiles"]["images"]["image"] = $field['value'];
  }

  // Now look for any CCK fields.
  foreach ($node as $fieldname => $field) {

    // This is a CCK filefield.
    if ($field = _mediafront_get_field($node, $fieldname)) {

      // This is a text field.
      if (isset($field[0]['value']) && is_string($field[0]['value'])) {
        $field_additions[$fieldname] = $field[0]['value'];
      }

      // This is a file field.
      if (isset($field[0]['filename'])) {

        // Get the media type for this field.
        $media_field = mediafront_filefield_get($node->type, $fieldname);

        // See if we would like to include this field.
        if (!$media_field || !empty($media_field->media_type) && $media_field->media_type != 'none' || !($media_field->node_preset == 'none' && $media_field->thumb_preset == 'none')) {

          // Iterate through the file field instances.
          foreach ($field as $index => $instance) {

            // If this instance has a data struct...
            if (isset($instance['data']) && $instance['data']) {

              // Merge the file data with the file info.
              $fileData = $instance['data'];
              unset($instance['data']);
              $file = array_merge($instance, $fileData);
            }
            else {
              $file = $instance;
            }

            // Set the media type for this file.
            $file['mediaType'] = $media_field ? $media_field->media_type : '';

            // Add this media to our struct.
            $media_added |= mediafront_add_media($additions, $file);
          }

          // If the media field is defined.
          if ($media_field) {

            // Get the filename.
            $filename = basename($field[0]['filepath']);

            // If this is a preview image.
            if ($media_field->node_preset && $media_field->node_preset != 'mediafront_original') {
              $file = array();
              $file['path'] = mediafront_get_image($media_field->node_preset, $filename);
              $file['class'] = 'images';
              $file['mediaType'] = 'preview';
              $media_added |= mediafront_add_media($additions, $file);
            }

            // This is a thumbnail image.
            if ($media_field->thumb_preset && $media_field->thumb_preset != 'mediafront_original') {
              $file = array();
              $file['path'] = mediafront_get_image($media_field->thumb_preset, $filename);
              $file['class'] = 'images';
              $file['mediaType'] = 'thumbnail';
              $media_added |= mediafront_add_media($additions, $file);
            }
          }
        }
      }
    }
  }

  // Only if media was added should we add the node info.
  $additions['nid'] = $node->nid;
  $additions['title'] = $node->title;
  $additions['description'] = $node->body;

  // Now add the CCK fields.
  foreach ($field_additions as $field => $value) {
    $additions[$field] = $value;
  }

  // Return our additions...
  return $additions;
}