You are here

function skinr_ui_export_form in Skinr 6.2

Same name and namespace in other branches
  1. 7.2 skinr_ui.admin.inc \skinr_ui_export_form()

Skinr settings export form.

1 string reference to 'skinr_ui_export_form'
skinr_ui_menu in ./skinr_ui.module
Implementation of hook_menu().

File

./skinr_ui.admin.inc, line 597
Admin page callbacks for the skinr module.

Code

function skinr_ui_export_form(&$form_state, $theme = NULL) {
  $form = array();
  $themes = list_themes();
  if ($theme) {

    // Export an individual theme.
    $theme = str_replace('-', '_', $theme);
    $skinrs = skinr_get($theme);

    // Convert classes to arrays.
    foreach ($skinrs as $module => $data) {
      foreach ($data as $sid => $skinr) {
        $skinrs[$module][$sid] = (array) $skinrs[$module][$sid];
      }
    }
    $code = '$skinrs = ' . var_export($skinrs, TRUE) . ';';
    $lines = substr_count($code, "\n") + 1;
    $form['theme'] = array(
      '#type' => 'textfield',
      '#title' => t('Theme'),
      '#value' => $themes[$theme]->info['name'],
      '#disabled' => TRUE,
    );
    $form['skinr_settings'] = array(
      '#type' => 'textarea',
      '#title' => t('Skinr settings'),
      '#default_value' => $code,
      '#rows' => min($lines, 150),
    );
  }
  else {

    // Give the option for which theme to export.
    $options = array();
    ksort($themes);
    $current_theme = skinr_current_theme(TRUE);

    // Put default theme at the top.
    $options[$current_theme] = $themes[$current_theme]->info['name'] . ' [' . t('default') . ']';
    foreach ($themes as $theme) {
      if ($theme->name == $current_theme) {

        // Do nothing.
      }
      elseif ($theme->status) {
        $options[$theme->name] = $theme->info['name'] . ' [' . t('enabled') . ']';
      }
      else {
        $options[$theme->name] = $theme->info['name'];
      }
    }
    $form['theme'] = array(
      '#type' => 'select',
      '#title' => t('Theme'),
      '#description' => t('Theme to export the skinr settings for.'),
      '#options' => $options,
      '#required' => TRUE,
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Export'),
    );
  }
  return $form;
}