You are here

function skinr_ui_export_form in Skinr 7.2

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

Form builder for the Skinr settings export form.

Parameters

$theme: (optional) The name of the theme to export Skinr settings for. If no theme name is provided a theme selector is shown.

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

File

./skinr_ui.admin.inc, line 954
Admin page callbacks for the Skinr UI module.

Code

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

    // Export an individual theme.
    $theme = str_replace('-', '_', $theme);
    $params = array(
      'theme' => $theme,
    );
    $skins = skinr_skin_load_multiple(skinr_skin_get_sids($params));
    $form['#skins'] = $skins;

    // Convert classes to arrays.
    $code = array();
    foreach ($skins as $skin) {
      $code[] = skinr_skin_export($skin);
    }
    $code = implode("\n", $code);
    $lines = substr_count($code, "\n") + 1;
    $form['theme'] = array(
      '#type' => 'textfield',
      '#title' => t('Theme'),
      '#value' => $themes[$theme]->info['name'],
      '#disabled' => TRUE,
      '#weight' => 0,
    );
    $form['skinr_skins'] = array(
      '#type' => 'textarea',
      '#title' => t('Skin configurations'),
      '#default_value' => $code,
      '#rows' => min($lines, 80),
      '#weight' => 10,
    );
  }
  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 (!empty($theme->info['hidden'])) {
        continue;
      }
      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;
}