I know it is possible to set a specific theme for several major types of devices, but I think it would also be helpful to do something similar for redirection rules as well.

For instance my main theme is good for most content on mobile devices, with a few exceptions, so most users would be happy using the much nicer regular theme from their more powerful mobile devices. However it would also be nice to be able to access the mobile theme from those devices easily should the need arise. I was thinking a solution along the lines of replicating the same set of controls for picking themes based on device to picking redirection rules as well for situations like this.

So on the Notification/Redirection configuration screen in the Redirection options you can add some additional options, on a per device basis the admin could elect to redirect all mobile traffic, then under iphone/ipod select don't redirect automatically. In this configuration the iphone going to the normal site would not be redirected and get the normal theme, and the more screen friendly mobile theme could be chosen by the user if necessary via a link. This also allows older mobile devices which stand no chance of dealing with the full theme to be automatically redirected still instead of having the user deal with finding the view mobile link somewhere on the site.

Comments

twom’s picture

Hi,

This is a great feature request and should not be to hard to implement. I'll first try to sort out some bugs with user roles, and see what I can do.
However, you are invited to help out and maybe create this functionality. I have already done this for the theme switching. This is basically what you need to do:

/**
 * Creation of the redirect url. Special care to create the correct url that will 
 * cause the Global Redirect module not to redirect!  
 */ 
function mobile_tools_get_redirect_url() {
  include_once './includes/bootstrap.inc';
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  // add this block
  $group = $_SESSION['mobile-tools-mobile-device']['group'];
  $type = $_SESSION['mobile-tools-mobile-device']['type'];
  $mobile_detection_module = variable_get('mobile-tools-device-detection', 'mobile_tools');
  $mobile_url  = '';
  if (variable_get($mobile_detection_module . '_' . $group . '_redirect_enable', '') == 1) {
     $mobile_url = variable_get($mobile_detection_module . '_' . $group . '_redirect, '');
   else {
     $mobile_url = variable_get('mobile_tools_mobile_url', '')
   }
   if(drupal_is_front_page()) {
    return $mobile_url; // change this
   }
  
  $query = array();
  foreach ($_GET as $key => $value) {
    if ($key != 'q') {
      $query[] =  $key . '=' . $value;
    }    
  }
  $query = (count($query) > 0) ? implode('&', $query) : '';
  //create the path and reassemble
  $base = preg_replace('{/$}', '', $mobile_url); //Change this line
  return $base . url($_GET['q'], array('query' => $query));
}

and of course you will need to create the user interface in the settings page...

twom’s picture

Status: Active » Needs work
jacob.myers’s picture

I am very new to drupal, but if you don't get around to it by this weekend I believe I have some free time I can dedicate to toying around with the code and see if I can't get it at least started in the right direction and figure out the settings UI.

jacob.myers’s picture

Just messing with this a little bit I decided to take a more simplistic approach for now. I basically decided to just add an override in the redirect area for each device to disable the automatic redirection. Thus if auto redirect is enabled but a device is set to disabled it won't automatically redirect. I accomplished this via the following modifications which I tested briefly, but they seemed to work just fine:

For the UI I simply added the following in mobile_tools_configuration_form():

  $mobile_groups = module_invoke(variable_get('mobile-tools-device-detection', 'mobile_tools'), 'device_groups');
  $mobile_detection_module = variable_get('mobile-tools-device-detection', 'mobile_tools');
  foreach ($mobile_groups as $group => $group_title) {
    $form['mobile_tools_redirection'][$mobile_detection_module . '_' . $group] = array(
      '#type' => 'fieldset',
      '#title' => $group_title,
      '#collapsible' => TRUE,
    );
    $form['mobile_tools_redirection'][$mobile_detection_module . '_' . $group][$mobile_detection_module . '_' . $group . '_redirect_disable'] = array(
      '#type' => 'checkbox',
      '#title' => t('Disable automatic redirection for this device group'),
      '#default_value' => variable_get($mobile_detection_module . '_' . $group . '_redirect_disable', ''),
      '#description' => t('Choose if redirection for this device happens automatically.'),
    );
  }

To power it I added the following to mobile_tools_redirection_boot():

    //Added
    $group = $_SESSION['mobile-tools-mobile-device']['group'];
    $mobile_detection_module = variable_get('mobile-tools-device-detection', 'mobile_tools');
    if ($redirect == 'true' && variable_get($mobile_detection_module . '_' . $group . '_redirect_disable', '') == 1) {
      $redirect = 'false';
    }

    //Before this original block at the end
    if (variable_get('mobile_tools_redirect', FALSE) && $redirect == 'true' && !$page_match) {
      // The case where a mobile user is accessing the desktop site
      if ($_SESSION['mobile-tools-mobile-device']['type'] == 'mobile' && $_SESSION['mobile-tools-site-type'] == 'desktop') {
          $destination = mobile_tools_get_redirect_url();
          mobile_tools_goto($destination);
      // The case where a desktop user is accessing the mobile site
      }
      elseif ($_SESSION['mobile-tools-mobile-device']['type'] == 'desktop' && $_SESSION['mobile-tools-site-type'] == 'mobile') {
         $destination =  variable_get('mobile_tools_desktop_url', $base_url);
         mobile_tools_goto($destination);
      }
    }

twom - Does this make sense, or is the other approach better? This seemed simple enough and it seemed to do the job.

twom’s picture

Hi,

Looks good from here. I'll add it this week to the code!

Thx,
Tom

minoroffense’s picture

Status: Needs work » Closed (won't fix)

1.x is no longer supported