You are here

content_theme_debugger.module in Content Theme 6

Same filename and directory in other branches
  1. 7 content_theme_debugger/content_theme_debugger.module

This module displays a list of modules which override the system default theme sorted by module's call-up.

File

content_theme_debugger/content_theme_debugger.module
View source
<?php

/**
 * @file
 * This module displays a list of modules which override the system default
 * theme sorted by module's call-up.
 */

/**
 * Implementation of hook_help().
 */
function content_theme_debugger_help($path, $arg) {
  switch ($path) {
    case 'admin/help#content_theme_debugger':
      $output = '<p>' . t('The Content Theme Debugger module displays a list of modules which override the system default theme sorted by module\'s call-up.') . '</p>';
      $output .= '<p>' . t('For more information, see the online handbook entry for <a href="@content_theme">Content Theme module</a>.', array(
        '@content_theme' => 'http://drupal.org/project/content_theme',
      )) . '</p>';
      return $output;
  }
}

/**
 * Implementation of hook_block().
 */
function content_theme_debugger_block($op = 'list', $delta = '', $edit = array()) {
  switch ($op) {
    case 'list':
      return _content_theme_debugger_block_list();
    case 'configure':
      return _content_theme_debugger_block_configure($delta);
    case 'save':
      _content_theme_debugger_block_save($delta, $edit);
      return;
    case 'view':
      return _content_theme_debugger_block_view($delta);
  }
}
function _content_theme_debugger_block_list() {
  $info = array();
  $info['content_theme_debugger'] = array(
    'info' => t('Content Theme Debugger'),
    'cache' => BLOCK_NO_CACHE,
  );
  return $info;
}
function _content_theme_debugger_block_configure($delta = '') {
  $form = array();
  if ($delta == 'content_themedebugger') {
    $form['content_theme_debugger_blacklist'] = array(
      '#type' => 'textarea',
      '#title' => t('Blacklist'),
      '#description' => t('Enter one module per line of each modules that should not execute <em>hook_custom_theme()</em>. Example modules are <em>og</em> for the Organic Groups module and <em>views</em> for the Views module.'),
      '#default_value' => variable_get('content_theme_debugger_blacklist', "ctools\nog\nviews"),
    );
  }
  return $form;
}
function _content_theme_debugger_block_save($delta = '', $edit = array()) {
  if ($delta == 'content_theme_debugger') {
    variable_set('content_theme_debugger_blacklist', $edit['content_theme_debugger_blacklist']);
  }
}
function _content_theme_debugger_block_view($delta = '') {
  $block = array();
  if ($delta == 'content_theme_debugger') {
    global $custom_theme;
    $content_theme_debugger_blacklist = variable_get('content_theme_debugger_blacklist', "ctools\nog\nviews");
    $blacklist = preg_split("/\r\n|\n|\r|\\s/", $content_theme_debugger_blacklist, -1, PREG_SPLIT_NO_EMPTY);
    $items = array();
    $items[] = t('Default theme: %theme', array(
      '%theme' => content_theme_get_themes(variable_get('theme_default', 'garland')),
    ));
    $custom_theme_original = $custom_theme;
    foreach (module_implements('init') as $module) {
      if (!in_array($module, $blacklist)) {
        $custom_theme = '-test_custom_theme_test-';
        module_invoke($module, 'init');
        if ($custom_theme != '-test_custom_theme_test-') {
          $items[] = t('Theme %theme is set by %module', array(
            '%theme' => content_theme_get_themes($custom_theme),
            '%module' => $module . '_init()',
          ));
        }
      }
    }
    $custom_theme = $custom_theme_original;
    $block['subject'] = t('Content Theme Debugger');
    $block['content'] = theme('item_list', $items);
  }
  return $block;
}