You are here

nitro.module in Arctica Nitro 7

Module file for Arctica Nitro.

File

nitro.module
View source
<?php

/**
 * Implements hook_menu().
 */
function nitro_menu() {
  foreach (list_themes() as $theme) {
    $items['admin/appearance/settings/' . $theme->name . '/reset'] = array(
      'title' => $theme->info['name'],
      'page callback' => array(
        'drupal_get_form',
      ),
      'page arguments' => array(
        'nitro_theme_reset_confirm',
        $theme->name,
      ),
      'type' => MENU_CALLBACK,
      'access callback' => '_system_themes_access',
      'access arguments' => array(
        $theme,
      ),
      'file' => 'includes/nitro.admin.inc',
    );
    $items['admin/appearance/settings/' . $theme->name . '/export'] = array(
      'title' => $theme->info['name'],
      'page callback' => array(
        'drupal_get_form',
      ),
      'page arguments' => array(
        'nitro_theme_export',
        $theme->name,
      ),
      'type' => MENU_CALLBACK,
      'access callback' => '_system_themes_access',
      'access arguments' => array(
        $theme,
      ),
      'file' => 'includes/nitro.admin.inc',
    );
  }
  return $items;
}

/**
 * @file
 * Module file for Arctica Nitro.
 */

/**
 * Implements hook_admin_paths().
 */
function nitro_admin_paths() {
  $paths = array();
  if (module_exists('color')) {
    $paths['admin/appearance/settings/*'] = FALSE;
  }
  return $paths;
}

/**
 * Implements hook_custom_theme().
 */
function nitro_custom_theme() {
  if (module_exists('color')) {
    if (arg(0) == 'admin' && arg(1) == 'appearance' && arg(2) == 'settings' && arg(3)) {
      $current_theme = check_plain(arg(3));
      return $current_theme;
    }
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function nitro_form_system_theme_settings_alter(&$form, &$form_state) {
  $form['#validate'][] = 'nitro_theme_settings_form_validate';
  $form['actions']['nitro_reset'] = array(
    '#type' => 'submit',
    '#value' => t('Reset to defaults'),
    '#submit' => array(
      'nitro_theme_settings_form_submit',
    ),
  );
  $form['actions']['nitro_export'] = array(
    '#type' => 'submit',
    '#value' => t('Export theme settings'),
    '#submit' => array(
      'nitro_theme_settings_form_submit',
    ),
  );
}

/**
 * @todo
 */
function nitro_theme_settings_form_validate($form, &$form_state) {
  unset($form_state['values']['nitro_reset'], $form_state['values']['nitro_export']);
}

/**
 * @todo
 */
function nitro_theme_settings_form_submit($form, &$form_state) {
  $theme = $form_state['build_info']['args'][0];
  unset($form_state['values']['nitro_reset'], $form_state['values']['nitro_export']);
  switch ($form_state['triggering_element']['#value']) {
    case t('Reset to defaults'):
      $form_state['redirect'] = 'admin/appearance/settings/' . $theme . '/reset';
      break;
    case t('Export theme settings'):
      $form_state['redirect'] = 'admin/appearance/settings/' . $theme . '/export';
      break;
  }
}

/**
 * Reverts theme settings to defaults in the .info file
 */
function nitro_revert_theme_settings($theme) {
  $themes = list_themes();
  variable_del('theme_' . $theme . '_settings');
  drupal_theme_rebuild();
  system_rebuild_theme_data();
  watchdog('theme', t('Theme settings for %theme reset to default values.', array(
    '%theme' => $themes[$theme]->info['name'],
  )));
  drupal_set_message(t('The theme settings for %theme have been removed from the database and are now being loaded from the .info file of this theme.', array(
    '%theme' => $themes[$theme]->info['name'],
  )));
}

/**
 * Builds an .info file with theme default settings
 */
function nitro_build_info_file($array, $prefix = FALSE) {
  $info = '';
  foreach ($array as $key => $value) {
    if (is_array($value)) {
      $info .= nitro_build_info_file($value, !$prefix ? $key : "{$prefix}[{$key}]");
    }
    else {
      $info .= $prefix ? "{$prefix}[" . (is_int($key) ? '' : $key) . ']' : $key;
      $info .= " = '" . str_replace("'", "\\'", $value) . "'\n";
    }
  }
  return $info;
}

Functions

Namesort descending Description
nitro_admin_paths Implements hook_admin_paths().
nitro_build_info_file Builds an .info file with theme default settings
nitro_custom_theme Implements hook_custom_theme().
nitro_form_system_theme_settings_alter Implements hook_form_FORM_ID_alter().
nitro_menu Implements hook_menu().
nitro_revert_theme_settings Reverts theme settings to defaults in the .info file
nitro_theme_settings_form_submit @todo
nitro_theme_settings_form_validate @todo