<?php

/**
 * @file
 * (Un)installation functions for Views RSS: Media Elements module.
 */

/**
 * Required minimum Views RSS module build.
 */
define('VIEWS_RSS_MEDIA_REQUIRED_BUILD', '7.x-2.x-dev-20120314');

/**
 * Implements hook_requirements().
 */
function views_rss_media_requirements($phase) {
  $requirements = array();
  $t = get_t();
  if (!defined('VIEWS_RSS_BUILD')) {
    $requirements['views_rss_media'] = array(
      'title' => $t('Views RSS: Media (MRSS) Elements'),
      'description' => $t('<a href="@views_rss_url">Views RSS</a> module does not seem to be enabled. Please make sure it is enabled before enabling <em>Views RSS: Media (MRSS) Elements</em> module.', array(
        '@views_rss_url' => url('http://drupal.org/project/views_rss'),
      )),
      'severity' => REQUIREMENT_ERROR,
      'value' => NULL,
    );
  }
  elseif (array_pop(explode('-', VIEWS_RSS_BUILD)) < array_pop(explode('-', VIEWS_RSS_MEDIA_REQUIRED_BUILD))) {
    $requirements['views_rss_media'] = array(
      'title' => $t('Views RSS: Media (MRSS) Elements'),
      'description' => $t('Your current build of <a href="@views_rss_url">Views RSS</a> module (!views_rss_build) is too old for this version of <em>Views RSS: Media (MRSS) Elements</em> module to work properly. Minimum version required is <strong>!views_rss_required</strong>. Please upgrade.', array(
        '@views_rss_url' => url('http://drupal.org/project/views_rss'),
        '!views_rss_build' => VIEWS_RSS_BUILD,
        '!views_rss_required' => VIEWS_RSS_MEDIA_REQUIRED_BUILD,
      )),
      'severity' => REQUIREMENT_ERROR,
      'value' => NULL,
    );
  }
  return $requirements;
}

/**
 * Implements hook_install().
 */
function views_rss_media_install() {
  // Clear Views cache to force-rebuild namespaces and feed elements.
  cache_clear_all('views_rss:', 'cache_views', TRUE);
}

/**
 * Implements hook_uninstall().
 */
function views_rss_media_uninstall() {
  if (db_table_exists('cache_views')) {
    cache_clear_all('views_rss:', 'cache_views', TRUE);
  }
}
