Hi,

I'm making a module that shows a warning to the user if he or she is using internet explorer 6 or worse using drupal_set_message().

I started adding drupal_set_message() to the mymodule_preprocess_page hook, but the warning didn't show until the next page (or page reload). What hook function should I use in order to set the message in time?

I tried using mymodule_theme() which actually works, but I'm not sure this is the best place to do this..

Btw. can anyone point me to a good resource showing an overview of the internal structure of drupal 6... (a flowchart or something like that)

regards

Ole

Comments

prinds’s picture

Found an answer myself. It seems a better option is to use the mymodule_init()

nicks’s picture

I followed this advice, but had a problem where the messages were sometimes being displayed twice (i.e. for some reason hook_init() was being called twice on a single page). I fixed this simply by setting the "repeat" drupal_set_message() argument to false.

Phil Wolstenholme’s picture

I'd love a module that did this! I'm trying to hard code a solution into my template but it's very hackish, a module would be much better!

prinds’s picture

I would like to share it with you (and everybody else)..

I tried to create a project page for it, but the maintainers suggested, that it should be a feature patch for the already existing project ie6 warning..

A good idea, but I'm afraid that means that I won't be able to upload it just now.. (I don't really know how to create patches, yet..)

However, the module i so basic and simple, that I can simply post the code here, and then you can use that for now.

ie6_warning_message.info

; $Id$
name=ie6_warning_message
description=Module that shows a warning message to users of internet explorer 6, encouraging them to upgrade their ancient browser.
core=6.x

ie6_warning_message.module

<?php
// $Id$
/**
 * @file
 *
 * Module that shows a warning message to users of internet explorer 6, encouraging them to upgrade their ancient browser.
 * Based on jrglasgow's IE6 Update module.
 */

/**
 * Implementation of hook_menu().
 */
function ie6_warning_message_menu() {
  $items = array();
  $items['admin/settings/ie6_warning_message'] = array(
    'title' => 'IE6 Warning Message',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('ie6_warning_message_admin_settings'),
    'access arguments' => array('administer site configuration'),
  );
  return $items;
}

/**
 * Return the module admin settings form to be rendered
 */
function ie6_warning_message_admin_settings() {
  $form = array();
  $form['ie6_warning_message_destination_url'] = array(
    '#title' => t('Destination URL'),
    '#description' => t('Where do you want the user directed when they click on the bar?'),
    '#type' => 'textfield',
    '#default_value' => variable_get('ie6_warning_message_destination_url', 'http://www.microsoft.com/windows/internet-explorer/default.aspx'),
  );
  $form['ie6_warning_message_update_bar_linktitle'] = array(
    '#title' => t('Link Title'),
    '#description' => t('The title for the update link'),
    '#type' => 'textfield',
    '#default_value' => variable_get('ie6_warning_message_update_bar_linktitle', 'Click here...'),
  );
  $form['ie6_warning_message_update_bar_message'] = array(
    '#title' => t('Update Message'),
    '#description' => t('What do you want the user to be told?'),
    '#type' => 'textfield',
    '#default_value' => variable_get('ie6_warning_message_update_bar_message', 'Your version of internet explorer is outdated. Please update to use this site.'),
  );
  return system_settings_form($form);
}
/**
 * Set browser warning if browser is internet explorer 6 or worse
 */
function ie6_warning_message_init(){ //theme($existing, $type, $theme, $path){//preprocess_page(&$vars, $hook) {
  $message = variable_get('ie6_warning_message_update_bar_message', 'Your version of internet explorer is outdated. Please update to use this site.');
  $url = variable_get('ie6_warning_message_destination_url', 'http://www.microsoft.com/windows/internet-explorer/default.aspx');
  $linktitle = variable_get('ie6_warning_message_update_bar_linktitle', 'Click here...');
  $browser = $_SERVER['HTTP_USER_AGENT'];

    //running internet explorer
    if($msie = strpos($browser, "MSIE"))
    {
        //version number
        $ver = substr($browser, $msie + 5, 3);

        if($ver < 7.0)
        {
          drupal_set_message($message . " " . l($linktitle,$url),'warning',false);
        }
    }
  return array();
  /**/
}

Enjoy..