You are here

function zenophile_create in Zenophile 6.2

Same name and namespace in other branches
  1. 6 zenophile.module \zenophile_create()
  2. 7 zenophile.module \zenophile_create()

Form to create the subtheme. drupal_get_form() callback.

2 string references to 'zenophile_create'
zenophile_callback in ./zenophile.drush.inc
Drush command callback.
zenophile_menu in ./zenophile.module
Implementation of hook_menu().

File

./zenophile.module, line 47
Creates Zen subthemes quickly and easily.

Code

function zenophile_create() {
  global $base_url;

  // Check for Zen
  $zen_loc = drupal_get_path('theme', 'zen');
  if ($zen_loc === '') {
    drupal_set_message(t('The <a href="!zen">Zen theme</a> could not be found. Please verify that it is properly installed.', array(
      '!zen' => 'http://drupal.org/project/zen',
    )), 'error');
    return array();
  }

  // Get Zen details
  $zen_info = drupal_parse_info_file($zen_loc . '/zen.info');
  preg_match('/^\\d+\\.x-([\\d\\.]+)/', $zen_info['version'], $matches);
  if (isset($matches[1])) {
    $zen_vers = floatval($matches[1]);
  }
  else {
    $zen_vers = 2;
    drupal_set_message(t('Zenophile could not determine the Zen theme&rsquo;s version by reading its .info file. The most likely cause for this is that this copy of Zen was checked out from CVS, so the version number was not added by the Drupal.org packaging system. Zenophile will assume that this is Zen version 2.0 and continue, but things will not work as expected if this assumption is incorrect.'), 'warning');
  }
  $zen_info['vers_float'] = $zen_vers;
  if ($zen_vers < 1.1) {
    drupal_set_message(t('Zenophile is no longer compatible with versions of Zen earlier than %earliest (%vers currently installed). Please <a href="!zen">upgrade Zen</a>.', array(
      '%earliest' => '6.x-1.1',
      '%vers' => $zen_info['version'],
      '!zen' => 'http://drupal.org/project/zen',
    )), 'error');
    return array();
  }
  elseif ($zen_vers > 2) {
    drupal_set_message(t('Zenophile has not been tested with versions of Zen later than %latest (%vers currently installed), and may not create the new theme correctly. Success not guaranteed.', array(
      '%latest' => '6.x-2.0',
      '%vers' => $info['version'],
    )), 'warning');
  }
  $zen_based = array();

  // Check for STARTERKIT
  if ($zen_vers >= 2) {
    $sk_loc = $zen_loc . '/STARTERKIT';
  }
  else {
    $sk_loc = $zen_loc . '/../STARTERKIT';
  }
  if (file_exists($sk_loc)) {
    $zen_based['STARTERKIT'] = t('Zen Sub-theme Starter Kit (@tsname)', array(
      '@tsname' => $sk_loc,
    ));
  }
  else {
    drupal_set_message(t('The STARTERKIT directory was not found. Zenophile will most likely not behave as expected.'), 'warning');
  }
  foreach (list_themes(TRUE) as $theme) {
    if (isset($theme->base_theme) && $theme->base_theme === 'zen') {
      $zen_based[$theme->name] = t('@tname (@tsname)', array(
        '@tname' => $theme->info['name'],
        '@tsname' => str_replace("/{$theme->name}.info", '', $theme->filename),
      ));
    }
  }

  // Create a default system name based on $base_url
  $default_sysname = preg_replace(array(
    '~https?://~',
    '/[^abcdefghijklmnopqrstuvwxyz_\\d]/',
  ), array(
    '',
    '_',
  ), $base_url);

  // Two consecutive underscores is a decent simple heuerstic to determine if
  // what we just created is too stupid to show the user. (This could easily
  // happen for UTF-8 domain names.) Better to show a blank.
  if (strpos($default_sysname, '__') !== FALSE) {
    $default_sysname = '';
  }
  return array(
    'zen_info' => array(
      '#type' => 'value',
      '#value' => $zen_info,
    ),
    'sysname' => array(
      '#title' => t('System name'),
      '#description' => t('The machine-compatible name of the new theme. This name may only consist of lowercase letters plus the underscore character.'),
      '#type' => 'textfield',
      '#default_value' => $default_sysname,
      '#required' => TRUE,
      '#weight' => 10,
    ),
    'friendly' => array(
      '#title' => t('Human name'),
      '#description' => t('A human-friendly name for the new theme. This name may contain uppercase letters, spaces, punctuation, etc.'),
      '#type' => 'textfield',
      '#default_value' => variable_get('site_name', ''),
      '#required' => TRUE,
      '#weight' => 20,
    ),
    'description' => array(
      '#title' => t('Description'),
      '#description' => t('A short description of this theme.'),
      '#type' => 'textfield',
      '#default_value' => t("@sitename's theme", array(
        '@sitename' => variable_get('site_name', ''),
      )),
      '#required' => TRUE,
      '#weight' => 30,
    ),
    'site' => array(
      '#title' => t('Site directory'),
      '#description' => t('Which site directory will the new theme to be placed in? If in doubt, select &ldquo;all&rdquo;.'),
      '#type' => 'select',
      '#options' => _zenophile_find_sites(),
      '#default_value' => array(
        'all',
      ),
      '#required' => TRUE,
      '#weight' => 50,
    ),
    'advanced_fset' => array(
      '#title' => t('More options'),
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#weight' => 60,
      'version' => array(
        '#type' => 'item',
        '#title' => t('Zen version'),
        '#value' => t('Zen version %vers found at %path.', array(
          '%vers' => isset($zen_info['version']) ? $zen_info['version'] : t('(undefined)'),
          '%path' => $zen_loc,
        )),
        '#weight' => -10,
      ),
      'parent' => array(
        '#title' => t('Starter theme'),
        '#description' => t('The parent theme for the new theme. If in doubt, select &ldquo;Zen Sub-theme Starter Kit&rdquo;.'),
        '#type' => 'select',
        '#options' => $zen_based,
        '#default_value' => 'STARTERKIT',
        '#required' => TRUE,
        '#weight' => 0,
      ),
      'layout' => array(
        '#title' => t('Layout type'),
        '#description' => t('Fixed layouts are always the same width. Liquid layouts adjust their width to fit the browser window. If in doubt, try a fixed layout.'),
        '#type' => 'radios',
        '#options' => array(
          'fixed' => t('Fixed'),
          'liquid' => t('Liquid'),
        ),
        '#default_value' => 'fixed',
        '#required' => TRUE,
        '#weight' => 10,
      ),
      'fresh' => array(
        '#title' => t('Create fresh CSS file'),
        '#description' => $zen_vers >= 2 ? t('If checked, Zenophile will add a blank CSS file named &ldquo;fresh.css&rdquo; to the new theme. Some themers prefer to start with a blank CSS file rather than adapt the pre-created CSS files which will be copied over from the parent theme directory.') : t('If checked, Zenophile will add a blank CSS file named &ldquo;[theme_name]-fresh.css&rdquo; to the new theme. Some themers prefer to start with a blank CSS file rather than adapt the pre-created CSS files which will be copied over from the parent theme directory.'),
        '#type' => 'checkbox',
        '#default_value' => FALSE,
        '#weight' => 30,
      ),
      'switch' => array(
        '#title' => t('Switch to theme after creation'),
        '#description' => t('If checked, Zenophile will automatically enable the new theme and make it the default theme. You may not notice the change if you are using a non-default <a href="!atheme">administration theme</a>. Also, this will not be attempted if something other than &ldquo;all&rdquo; or this site&rsquo;s directory is selected in the &ldquo;Site directory&rdquo; menu above.', array(
          '!atheme' => url('admin/settings/admin'),
        )),
        '#type' => 'checkbox',
        '#default_value' => FALSE,
        '#weight' => 40,
      ),
    ),
    'submit' => array(
      '#type' => 'submit',
      '#value' => t('Submit'),
      '#weight' => 1000,
    ),
  );
}