<?php
// $Id: $
/*
 * needs patch
 * http://drupal.org/files/issues/features-install-hooks_0.patch
 * from http://drupal.org/node/651084
 */

/**
 * Implementation of hook_features_api().
 */
function fe_variables_features_api() { 
  return array(
    'fe_variables' => array(
      'name' => t('Variable Settings'),
      'default_hook' => 'fe_variables_default_set',
    ),
  );
}

/**
 * Implementation of hook_features_export_options().
 */
function fe_variables_features_export_options() {
  $vars_data = variable_init();
  foreach ($vars_data as $var => $value) {
    $vars[$var] = $var;
  }
  return $vars;
}

/**
 * Implementation of hook_features_export().
 */
function fe_variables_features_export($data, &$export, $module_name = '') {
  $export['dependencies']['fe_variables'] = 'fe_variables';
  foreach ($data as $var) {
    $export['features']['fe_variables'][$var] = $var;
  }
}

/**
 * Implementation of hook_features_export_render().
 */
function fe_variables_features_export_render($module_name = '', $data) {
  $vars = array();
  foreach ($data as $var) {
    $vars[$var] = variable_get($var, FALSE);
  }
  $code = "  \$items = ". features_var_export($vars, '  ') .";\n";
  $code .= '  return $items;';
  $enable = "fe_variables_features_revert('$module_name');";
  return array(
    'fe_variables_default_set' => $code,
    'enable' => $enable
  );
}

/**
 * Implementation of hook_features_revert().
 */
function fe_variables_features_revert($module) {
  $vars = module_invoke_all('fe_variables_default_set');
  foreach ($vars as $var => $value) {
    variable_set($var, $value);
  }
} 

