You are here

views_rss_itunes.module in Views RSS: iTunes Elements 6

Same filename and directory in other branches
  1. 8 views_rss_itunes.module
  2. 7 views_rss_itunes.module

Provides iTunes namespace, <channel> and <item> elements for Views RSS module.

File

views_rss_itunes.module
View source
<?php

/**
 * @file
 * Provides iTunes namespace, <channel> and <item> elements for Views RSS module.
 */

/**
 * Module installation path.
 */
define('VIEWS_RSS_ITUNES_PATH', drupal_get_path('module', 'views_rss_itunes'));

/**
 * Include file with all preprocess functions.
 */
include_once VIEWS_RSS_ITUNES_PATH . '/views_rss_itunes.inc';

/**
 * Implementation of hook_views_rss_namespaces().
 */
function views_rss_itunes_views_rss_namespaces() {
  $namespaces['itunes'] = array(
    'prefix' => 'xmlns',
    'uri' => 'http://www.itunes.com/dtds/podcast-1.0.dtd',
  );
  return $namespaces;
}

/**
 * Implementation of hook_views_rss_channel_elements().
 */
function views_rss_itunes_views_rss_channel_elements() {
  $elements['itunes:subtitle'] = array(
    'description' => t('The contents of this tag are shown in the Description column in iTunes. The subtitle displays best if it is only a few words long.'),
    'preprocess functions' => array(
      'views_rss_htmlspecialchars',
    ),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#subtitle',
  );
  $elements['itunes:summary'] = array(
    'settings form' => array(
      '#type' => 'textarea',
      '#rows' => 3,
    ),
    'preprocess functions' => array(
      'views_rss_htmlspecialchars',
    ),
    'description' => t('The contents of this tag are shown in a separate window that appears when the "circled i" in the Description column is clicked. It also appears on the iTunes page for your podcast. This field can be up to 4000 characters. If &lt;itunes:summary&gt; is not included, the contents of the &lt;description&gt; tag are used.'),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#summary',
  );
  $elements['itunes:category'] = array(
    'description' => t('Category column and in iTunes Store Browse.'),
    'settings form' => array(
      '#type' => 'select',
      '#multiple' => TRUE,
      '#size' => 3,
    ),
    'settings form options callback' => 'views_rss_itunes_get_category_options',
    'preprocess functions' => array(
      'views_rss_itunes_preprocess_channel_category',
    ),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#category',
  );
  $elements['itunes:keywords'] = array(
    'description' => t('This tag allows users to search on a maximum of 12 text keywords. Use commas to separate keywords. Not visible in iTunes.'),
    'preprocess functions' => array(
      'views_rss_htmlspecialchars',
    ),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#keywords',
  );
  $elements['itunes:image'] = array(
    'description' => t('Path to the image to be used as the artwork for your podcast, for example <em>sites/default/files/AllAboutEverything.jpg</em>. iTunes prefers square .jpg images that are at least 600 x 600 pixels. iTunes supports images in JPEG and PNG formats with a RGB color space (CMYK is not supported). If the tag is not present, iTunes will use the contents of the RSS &lt;image&gt; tag.'),
    'preprocess functions' => array(
      'views_rss_itunes_preprocess_channel_image',
    ),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#image',
  );
  $elements['itunes:author'] = array(
    'description' => t('The content of this tag is shown in the Artist column in iTunes. If the tag is not present, iTunes uses the contents of the &lt;author&gt; tag. If &lt;itunes:author&gt; is not present at the feed level, iTunes will use the contents of &lt;managingEditor&gt;.'),
    'preprocess functions' => array(
      'views_rss_htmlspecialchars',
    ),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#author',
  );
  $elements['itunes:explicit'] = array(
    'settings form' => array(
      '#type' => 'select',
      '#options' => array(
        '',
        'yes',
        'no',
        'clean',
      ),
    ),
    'description' => t('This tag should be used to indicate whether or not your podcast contains explicit material.'),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#explicit',
  );
  $elements['itunes:block'] = array(
    'settings form' => array(
      '#type' => 'select',
      '#options' => array(
        '',
        'yes',
        'no',
      ),
    ),
    'description' => t('If this tag is present and set to "yes", that means to block the feed. If the tag\'s value is any other value, including empty string, it\'s indicated as a signal to unblock the feed. If there is no block tag, then the block status of the feed is left unchanged.'),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#block',
  );
  $elements['itunes:complete'] = array(
    'settings form' => array(
      '#type' => 'select',
      '#options' => array(
        '',
        'yes',
        'no',
      ),
    ),
    'description' => t('This tag can be used to indicate the completion of a podcast. If you populate this tag with "yes", you are indicating that no more episodes will be added to the podcast. If the &lt;itunes:complete&gt; tag is present and has any other value (e.g. "no"), it will have no effect on the podcast.'),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#complete',
  );
  $elements['itunes:new-feed-url'] = array(
    'description' => t('This tag allows you to change the URL where the podcast feed is located. After adding the tag to your old feed, you should maintain the old feed for 48 hours before retiring it. At that point, iTunes will have updated the directory with the new feed URL.'),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#newfeed',
  );
  $elements['itunes:owner'] = array(
    'description' => t('This tag contains information that will be used to contact the owner of the podcast for communication specifically about their podcast. It will not be publicly displayed. Enter owner\'s email address followed by their name, separating them with comma.'),
    'preprocess functions' => array(
      'views_rss_itunes_preprocess_channel_owner',
    ),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#owner',
  );
  return $elements;
}

/**
 * Implementation of hook_views_rss_item_elements().
 */
function views_rss_itunes_views_rss_item_elements() {
  $elements['itunes:subtitle'] = array(
    'description' => t('The contents of this tag are shown in the Description column in iTunes. The subtitle displays best if it is only a few words long.'),
    'preprocess functions' => array(
      'views_rss_htmlspecialchars',
    ),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#subtitle',
  );
  $elements['itunes:summary'] = array(
    'description' => t('The contents of this tag are shown in a separate window that appears when the "circled i" in the Description column is clicked. It also appears on the iTunes page for your podcast. This field can be up to 4000 characters. If &lt;itunes:summary&gt; is not included, the contents of the &lt;description&gt; tag are used.'),
    'preprocess functions' => array(
      'views_rss_htmlspecialchars',
    ),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#summary',
  );
  $elements['itunes:duration'] = array(
    'description' => t('The content of this tag is shown in the Time column in iTunes.'),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#duration',
  );
  $elements['itunes:keywords'] = array(
    'description' => t('This tag allows users to search on a maximum of 12 text keywords. Use commas to separate keywords. Not visible in iTunes.'),
    'preprocess functions' => array(
      'views_rss_htmlspecialchars',
    ),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#keywords',
  );
  $elements['itunes:image'] = array(
    'description' => t('This tag specifies the artwork for your podcast. iTunes prefers square .jpg images that are at least 600 x 600 pixels. iTunes supports images in JPEG and PNG formats with a RGB color space (CMYK is not supported). If the tag is not present, iTunes will use the contents of the RSS &lt;image&gt; tag.'),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#image',
  );
  $elements['itunes:author'] = array(
    'description' => t('The content of this tag is shown in the Artist column in iTunes. If the tag is not present, iTunes uses the contents of the &lt;author&gt; tag. If &lt;itunes:author&gt; is not present at the feed level, iTunes will use the contents of &lt;managingEditor&gt;.'),
    'preprocess functions' => array(
      'views_rss_htmlspecialchars',
    ),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#author',
  );
  $elements['itunes:isClosedCaptioned'] = array(
    'description' => t('This tag should be used if your podcast includes a video episode with embedded closed captioning support. The two values for this tag are "yes" and "no".'),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#isClosedCaptioned',
  );
  $elements['itunes:explicit'] = array(
    'description' => t('This tag should be used to indicate whether or not your podcast contains explicit material.'),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#explicit',
  );
  $elements['itunes:block'] = array(
    'description' => t('If this tag is present and set to "yes", that means to block the episode. If the tag\'s value is any other value, including empty string, it\'s indicated as a signal to unblock the episode. If there is no block tag, it is the same as if a block=no were present.'),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#block',
  );
  $elements['itunes:order'] = array(
    'description' => t('This tag can be used to override the default ordering of episodes on the store. This tag is used at an &lt;item&gt; level by populating with the number value in which you would like the episode to appear on the store.'),
    'help' => 'http://www.apple.com/itunes/podcasts/specs.html#order',
  );
  return $elements;
}

/**
 * Implementation of hook_theme().
 */
function views_rss_itunes_theme() {
  $theme = array(
    // CCK field formatters.
    'views_rss_itunes_formatter_itunes_duration' => array(
      'arguments' => array(
        'element' => NULL,
      ),
      'function' => 'views_rss_itunes_field_formatter_view',
    ),
    'views_rss_itunes_formatter_itunes_image' => array(
      'arguments' => array(
        'element' => NULL,
      ),
      'function' => 'views_rss_itunes_field_formatter_view',
    ),
  );
  if (module_exists('imagecache')) {
    foreach (imagecache_presets() as $preset) {
      $theme['views_rss_itunes_formatter_itunes_image' . $preset['presetname']] = array(
        'arguments' => array(
          'element' => NULL,
        ),
        'function' => 'views_rss_itunes_field_formatter_view',
      );
    }
  }
  return $theme;
}

/**
 * Implements hook_field_formatter_info().
 */
function views_rss_itunes_field_formatter_info() {
  $formatters = array(
    'itunes_duration' => array(
      'label' => t('RSS <itunes:duration> element'),
      'field types' => array(
        'filefield',
      ),
    ),
    'itunes_image' => array(
      'label' => t('RSS <itunes:image> element: original size'),
      'field types' => array(
        'image',
        'filefield',
      ),
    ),
  );

  // Additional formatters for imagecache module.
  if (module_exists('imagecache')) {
    foreach (imagecache_presets() as $preset) {

      // Imagecache image formatter for <enclosure> element.
      $formatters['itunes_image' . $preset['presetname']] = array(
        'label' => t('RSS <itunes:image> element: @preset', array(
          '@preset' => $preset['presetname'],
        )),
        'field types' => array(
          'image',
          'filefield',
        ),
      );
    }
  }
  return $formatters;
}

/**
 * No, this is not an implementation of hook_field_formatter_view(). This hook
 * does not exist in D6. This function only more or less simulates it.
 */
function views_rss_itunes_field_formatter_view($variables) {
  $element = NULL;

  // Inside a view $element may contain NULL data. In that case, just return.
  if (empty($variables['#item']['fid'])) {
    return;
  }
  $uri = url($variables['#item']['filepath'], array(
    'absolute' => TRUE,
  ));

  // #formatter could have values like "itunes_image<preset>".
  if (strpos($variables['#formatter'], 'itunes_image') !== FALSE) {

    // Get full image URI based on provided imagecache preset.
    $preset_name = str_replace('itunes_image', '', $variables['#formatter']);
    if (!empty($preset_name) && ($preset = imagecache_preset_by_name($preset_name))) {
      $uri = imagecache_create_url($preset_name, $variables['#item']['filepath']);

      // Make sure that imagecache preset file has already been created.
      $path = imagecache_create_path($preset_name, $variables['#item']['filepath']);
      if (!file_exists(realpath($path))) {
        imagecache_build_derivative($preset['actions'], $variables['#item']['filepath'], $path);
      }
    }
  }

  // Return values to generate XML element.
  if (strpos($variables['#formatter'], 'itunes_image') !== FALSE) {
    $element = 'serialized:' . serialize(array(
      'arguments' => array(
        'href' => $uri,
      ),
    ));
  }
  elseif ($variables['#formatter'] == 'itunes_duration') {
    $file_info = views_rss_itunes_get_file_info($variables['#item']['filepath']);
    if (isset($file_info['playtime_string'])) {
      $element = $file_info['playtime_string'];
    }
  }
  return $element;
}

Functions

Namesort descending Description
views_rss_itunes_field_formatter_info Implements hook_field_formatter_info().
views_rss_itunes_field_formatter_view No, this is not an implementation of hook_field_formatter_view(). This hook does not exist in D6. This function only more or less simulates it.
views_rss_itunes_theme Implementation of hook_theme().
views_rss_itunes_views_rss_channel_elements Implementation of hook_views_rss_channel_elements().
views_rss_itunes_views_rss_item_elements Implementation of hook_views_rss_item_elements().
views_rss_itunes_views_rss_namespaces Implementation of hook_views_rss_namespaces().

Constants

Namesort descending Description
VIEWS_RSS_ITUNES_PATH Module installation path.