| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 | <?php/** * @file * Enable the administration theme on more pages, * then possible with Drupal's default administration page. *//** * Implements hook_permission(). */function admin_theme_permission() {  return array(    'access admin theme' => array(      'title' => t('Access administration theme'),      'description' => t('View pages using the administration theme'),    )  );}/** * Get the variable name for a certain option. * * @param string $module *   Module that defines this option. * @param string $params *   Name of the option. *  * @return string *   Variable name for the option. */function admin_theme_variable_name($module, $option) {  return 'admin_theme_' . $module . '_' . $option;}/** * Get all module defined options. * * @return array *   All options. */function admin_theme_list() {  $options = array();  foreach (module_list() as $module) {    $module_options = module_invoke($module, 'admin_theme_info');    if ($module_options && count($module_options) > 0) {      foreach ($module_options as $option => $info) {        $info['option'] = $option;        $info['module'] = $module;        $options[] = $info;      }    }  }  return $options;}/** * Implements hook_form_alter(). */function admin_theme_form_system_themes_admin_form_alter(&$form, $form_state) {  // Define a fieldset for the page selection.  $form['admin_theme']['pages'] = array(    '#type' => 'fieldset',    '#title' => t('Pages'),    '#collapsible' => TRUE,    '#description' => t('Choose which pages should be displayed with the administration theme.'),  );  // Add the content editing option to the pages fieldset and change the title.  $form['admin_theme']['pages']['node_admin_theme'] = $form['admin_theme']['node_admin_theme'];  $form['admin_theme']['pages']['node_admin_theme']['#title'] = t('Content editing');  unset($form['admin_theme']['node_admin_theme']);  // Add all options as checkboxes to the admin theme settings form.  $list = admin_theme_list();  foreach ($list as $info) {    $var = admin_theme_variable_name($info['module'], $info['option']);    $form['admin_theme']['pages'][$var] = array(      '#type' => 'checkbox',      '#title' => array_key_exists('title', $info) ? $info['title'] : NULL,      '#description' => array_key_exists('description', $info) ? $info['description'] : NULL,      '#default_value' => variable_get($var, '0'),    );  }  // Allow the user to define a set of pages where the admin theme should,  // or should not be applied to.  $form['admin_theme']['pages']['custom'] = array(    '#type' => 'fieldset',    '#title' => t('Custom'),    '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),    '#collapsible' => TRUE,    '#collapsed' => TRUE,    '#weight' => 9,  );  $form['admin_theme']['pages']['custom']['admin_theme_path'] = array(    '#type' => 'textarea',    '#title' => t('Use administration theme on the following pages'),    '#default_value' => variable_get('admin_theme_path', ''),  );  $form['admin_theme']['pages']['custom']['admin_theme_path_disallow'] = array(    '#type' => 'textarea',    '#title' => t('Do not use administration theme on the following pages'),    '#description' => t('If a path appears here, the administration theme is not shown even if all above options apply.'),    '#default_value' => variable_get('admin_theme_path_disallow', ''),  );    $form['#submit'][] = 'admin_theme_form_system_themes_form_alter_submit';    $form['admin_theme']['actions']['#weight'] = 10;}/** * Process system_themes_form additions submissions. */function admin_theme_form_system_themes_form_alter_submit($form, &$form_state) {  // Module options.  $list = admin_theme_list();  foreach ($list as $info) {    $var = admin_theme_variable_name($info['module'], $info['option']);    if (isset($form_state['values'][$var])) {      variable_set($var, $form_state['values'][$var]);    }  }    // Custom page options.  variable_set('admin_theme_path', $form_state['values']['admin_theme_path']);  variable_set('admin_theme_path_disallow', $form_state['values']['admin_theme_path_disallow']);}/** * Implements hook_custom_theme(). */function admin_theme_custom_theme() {  $admin_theme_disallow = FALSE;  $admin_theme = FALSE;    // Check if some paths are disallow to get the theme.  if (trim(variable_get('admin_theme_path_disallow', '')) != '') {    // Pages that are defined by their normal path.    $admin_theme_disallow = drupal_match_path($_GET['q'], variable_get('admin_theme_path_disallow', ''));        // Pages that are defined with their alias.    $alias = drupal_get_path_alias($_GET['q']);    if ($alias != $_GET['q']) {      $admin_theme_disallow = $admin_theme || drupal_match_path($alias, variable_get('admin_theme_path_disallow', ''));    }  }  // We should not show the admin theme if the user has no access,  // or the path is in the disallow list.  if (!user_access('access admin theme') || $admin_theme_disallow) {    return;  }    // Check if an option is enabled and if it results to TRUE.  $list = admin_theme_list();  foreach ($list as $info) {    $var = admin_theme_variable_name($info['module'], $info['option']);    if ((bool)variable_get($var, '0') && module_invoke($info['module'], 'admin_theme', 'check', $info['option'])) {      $admin_theme = TRUE;    }  }    // Some custom defined pages should get admin theme.  if (trim(variable_get('admin_theme_path', '')) != '') {    // Pages that are defined by their normal path.    $admin_theme = $admin_theme || drupal_match_path($_GET['q'], variable_get('admin_theme_path', ''));    // Pages that are defined with their alias.    $alias = drupal_get_path_alias($_GET['q']);    if ($alias != $_GET['q']) {      $admin_theme = $admin_theme || drupal_match_path($alias, variable_get('admin_theme_path', ''));    }  }  // Use the admin theme for the current request (if global admin theme setting is checked).  if ($admin_theme) {    return variable_get('admin_theme');  }    return;}/** * Implements hook_admin_theme_info(). */function admin_theme_admin_theme_info() {  $options = array();  $options['batch'] = array(    'title' => t('Batch processing'),    'description' => t('Use the administration theme when executing batch operations.'),  );  if (module_exists('img_assist')) {    $options['img_assist'] = array(      'title' => t('Image assist'),      'description' => t('Use the administration theme when viewing the Image assist popup window.'),    );  }  if (module_exists('coder')) {    $options['coder'] = array(      'title' => t('Code reviews'),      'description' => t('Use the administration theme when viewing Coder code reviews.'),    );  }  if (module_exists('devel')) {    $options['devel'] = array(      'title' => t('Devel pages.'),      'description' => t('Use the administration theme when viewing pages of the devel module (hook_elements(), Dev render, Dev load, Session viewer, Theme registery, Variable editor, ...).'),    );  }  if (module_exists('service_attachments')) {    $options['service_attachments'] = array(      'title' => t('Service attachments form on nodes.'),      'description' => t('Use the administration theme when viewing service attachments on nodes.'),    );  }  if (module_exists('webform')) {    $options['webform_results'] = array(      'title' => t('Webform submissions.'),      'description' => t('Use the administration theme when viewing webform submissions.'),    );  }  if (module_exists('statistics')) {    $options['statistics'] = array(      'title' => t('Pages defined by the statistics module.'),      'description' => t('Use the administration theme when viewing pages of the statistics module.'),    );  }  return $options;}/** * Implements hook_admin_theme_check(). */function admin_theme_admin_theme_check($option = NULL) {  switch ($option) {    case 'img_assist':      return arg(0) == 'img_assist';    case 'coder':      return arg(0) == 'coder';    case 'devel':      return arg(0) == 'devel' || (arg(0) == 'node' && arg(2) == 'devel');    case 'batch':      return arg(0) == 'batch';    case 'service_attachments':      return arg(0) == 'node' && arg(2) == 'service_attachments';    case 'webform_results':      return arg(0) == 'node' && arg(2) == 'webform-results';    case 'statistics':      return (arg(0) == 'node' || arg(0) == 'user') && arg(2) == 'track';  }}
 |