You are here

function page_theme_custom_theme in Page Theme 7.2

Same name and namespace in other branches
  1. 7 page_theme.module \page_theme_custom_theme()

Implements hook_custom_theme().

File

./page_theme.module, line 106
Allows to use different themes than the site default on specific pages.

Code

function page_theme_custom_theme() {
  global $user;
  $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
  $rids = array_keys($user->roles);
  $result = db_query("SELECT DISTINCT pt.theme, pt.pages \n                        FROM {page_theme} pt LEFT JOIN {page_theme_role} ptr ON pt.ptid = ptr.ptid \n                        WHERE pt.status = 1 AND (ptr.rid IN (:rids) OR ptr.rid IS NULL) \n                        ORDER BY pt.weight, pt.theme", array(
    ':rids' => $rids,
  ));
  foreach ($result as $page_theme) {
    $pages = drupal_strtolower($page_theme->pages);
    $page_match = drupal_match_path($path, $pages);
    if ($path != $_GET['q']) {
      $page_match = $page_match || drupal_match_path($_GET['q'], $pages);
    }
    if ($page_match) {
      return $page_theme->theme;
    }
  }
}