'Show current status of theme configuration in the site.', ); $items['theme list'] = array( 'description' => 'List all the available themes for the site.', ); $items['theme info'] = array( 'description' => 'List all info about a theme.', 'arguments' => array( 'theme_name' => 'The code name of the theme', ), ); $items['theme set default'] = array( 'description' => 'Set the default theme.', 'arguments' => array( 'theme_name' => 'The code name of the theme', ), ); $items['theme set admin'] = array( 'description' => 'Set the administration theme.', 'arguments' => array( 'theme_name' => 'The code name of the theme', ), ); $items['theme enable'] = array( 'description' => 'Enable a theme.', 'arguments' => array( 'theme_name' => 'The code name of the theme', ), ); $items['theme disable'] = array( 'description' => 'Disable a theme.', 'arguments' => array( 'theme_name' => 'The code name of the theme', ), ); return $items; } /** * Implementation of hook_drush_help(). */ function theme_drush_help($section) { # TODO } /** * * */ function drush_theme_theme_status() { $theme_default = _drush_theme_get_default_theme(); $admin_theme = _drush_theme_get_admin_theme(); $enabled = _drush_theme_get_enabled_themes(); $key = array_search($theme_default, $enabled); unset($enabled[$key]); drush_print(dt("Default theme: %theme_default", array('%theme_default' => $theme_default))); drush_print(dt("Administration theme: %admin_theme", array('%admin_theme' => $admin_theme))); if (count($enabled) > 0) { drush_print(dt("Other enabled themes: ") . implode(' ', $enabled)); } } /** * * */ function drush_theme_theme_list() { $themes = _drush_theme_get_themes(); $theme_default = _drush_theme_get_default_theme(); $enabled = _drush_theme_get_enabled_themes(); $rows[] = array(dt('Name'), dt('Title'), dt('Enabled/Disabled'), dt('Default')); foreach ($themes as $theme) { $default = ($theme->name == $theme_default ? dt('Yes') : dt('No')); $status = (in_array($theme->name, $enabled) ? "enabled" : "disabled"); $rows[] = array($theme->name, $theme->info['name'], $status, $default); $pipe[] = $theme->name; } drush_print_table($rows, TRUE); drush_print_pipe(implode(' ', $pipe)); } /** * * */ function drush_theme_theme_info($theme_name) { $theme = _drush_theme_get_theme($theme_name); drush_print(dt("Name: ") . $theme->name); drush_print(dt("Title: ") . $theme->info['name']); drush_print(dt("Description: ") . $theme->info['description']); drush_print(dt("Version: ") . $theme->info['version']); drush_print(dt("Core: ") . $theme->info['core']); drush_print(dt("PHP: ") . $theme->info['php']); drush_print(dt("Engine: ") . $theme->info['engine']); drush_print(dt("Regions: ") . implode(', ', $theme->info['regions'])); drush_print(dt("Features: ") . implode(', ', $theme->info['features'])); drush_print(dt("Stylesheets: ")); foreach ($theme->info['stylesheets'] as $media => $files) { drush_print(dt("media: ") . $media, 2); drush_print(dt("files: ") . implode(', ', $files), 4); } if (count($theme->info['scripts']) > 0) { drush_print(dt("Scripts: ")); drush_print(dt("files: ") . implode(', ', $theme->info['scripts']), 2); } } /** * Implementation of command to set the default theme of the site * * This function implements the command drush theme set default «theme_name» */ function drush_theme_theme_set_default($theme_name) { _drush_theme_valid_theme_or_die($theme_name); db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' and name = '%s'", $theme_name); variable_set('theme_default', $theme_name); drush_log("Setting $theme_name as default theme", "success"); } /** * * */ function drush_theme_theme_set_admin($theme_name) { _drush_theme_valid_theme_or_die($theme_name); variable_set('admin_theme', $theme_name); drush_log("Setting $theme_name as admin theme", "success"); } /** * * */ function drush_theme_theme_enable($theme_name) { _drush_theme_valid_theme_or_die($theme_name); db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' and name = '%s'", $theme_name); drush_log("Enabling $theme_name", "success"); } /** * * */ function drush_theme_theme_disable($theme_name) { _drush_theme_valid_theme_or_die($theme_name); $theme_default = _drush_theme_get_default_theme(); if ($theme_name == $theme_default) { drush_die("$theme_name is the default theme. You must set another theme as default before trying to disable this one."); } db_query("UPDATE {system} SET status = 0 WHERE type = 'theme' and name = '%s'", $theme_name); drush_log("Disabling $theme_name", "success"); } /// HELPER FUNCTIONS /** * * */ function _drush_theme_get_themes() { drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE); $themes = list_themes(); return $themes; } /** * * */ function _drush_theme_valid_theme_or_die($theme_name) { $themes = _drush_theme_get_themes(); if (!array_key_exists($theme_name, $themes)) { drush_die("Unknown theme"); } } /** * * */ function _drush_theme_get_theme($theme_name) { _drush_theme_valid_theme_or_die($theme_name); $themes = _drush_theme_get_themes(); return $themes[$theme_name]; } /** * * */ function _drush_theme_get_default_theme() { $theme_default = variable_get('theme_default', 'garland'); return $theme_default; } /** * * */ function _drush_theme_get_admin_theme() { $theme_default = _drush_theme_get_default_theme(); $admin_theme = variable_get('admin_theme', $theme_default); return $admin_theme; } /** * * */ function _drush_theme_get_enabled_themes() { $enabled = array(); $themes = _drush_theme_get_themes(); foreach ($themes as $theme) { if ($theme->status == 1) { $enabled[] = $theme->name; } } return $enabled; }