Prerequisites: having a separate admin section template enabled

When I click a popup link that loads a page outside of admin section, certain elements of the page change to match the default template, while others remain like the admin template -- it seems the CSS from the popup window is getting applied to the whole page (so you end up with a mishmash). There should be a way for the popup CSS to be limited to just the window (like it should in an IFRAME).

Screenshot here: http://screencast.com/t/8wIK4Goim6OM
(upload form wouldn't work)

Using Firefox 3.5.3, Drupal 6 latest, Popups 6.x-2.0-alpha5

Simon.

Comments

zoo33’s picture

Same thing happens when using the Sections module and the popup and the referrer page aren't in the same section. I've finally solved this with a custom hook_init() implementation. See code below. A corresponding implementation for the case of a separate admin theme should be a lot simpler. Hope this helps someone.

<?php
mymodule_init() {
  // Find out if this request is to be displayed in a popup.
  if ($_SERVER['HTTP_X_DRUPAL_RENDER_MODE'] == 'json/popups') {

    // We need the theme of this page to be the same as the referrer's theme,
    // otherwise conflicting CSS declaration will bring chaos and disorder.

    // Find the referrer's path.
    $q = str_replace(url(NULL, array('absolute' => TRUE)), '', $_SERVER['HTTP_REFERER']);
    $q_parts = explode('?', $q);
    $q = array_shift($q_parts);
    if (empty($q)) {
      $q = variable_get('site_frontpage', 'node');
    }

    // Check if this path is in a section ( taken from _sections_in_section() ).
    $section = NULL;
    global $user;
    $rids = array_keys($user->roles);
    $res = db_query(db_rewrite_sql('SELECT DISTINCT s.* FROM {sections_data} s LEFT JOIN {sections_roles} r ON s.sid = r.sid WHERE s.status = 1 AND (r.rid IN ('. db_placeholders($rids) .') OR r.rid IS NULL) ORDER BY s.weight', 's', 'sid'), $rids);
    while ($row = db_fetch_object($res)) {
      if ($row->visibility < 2) {
        $path = drupal_get_path_alias($_GET['q']);
        // Compare with the internal and path alias (if any).
        $page_match = drupal_match_path($path, $row->path);
        if ($path != $q) {
          $page_match = $page_match || drupal_match_path($q, $row->path);
        }
        // When $row->visibility has a value of 0, the block is displayed on
        // all pages except those listed in $row->path. When set to 1, it
        // is displayed only on those pages listed in $row->path. Prevent
        // the admin theme switching on block admin pages.
        if ($page_match = !($row->visibility xor $page_match) && !(drupal_match_path($path, "admin/build/block\nadmin/build/block/list/*"))) {
          $section = $row;
        }
      }
      else {
        if (drupal_eval($row->path)) {
          $section = $row;
        }
      }
    }
    
    global $custom_theme;
    if ($section) {
      // Set the theme to the referrer's section's theme.
      $custom_theme = $section->theme;
    }
    else {
      // Use the default theme if there is no section. (This popup may also
      // belong to a section.)
      $custom_theme = variable_get('theme_default', null);
    }
  }
}
?>