As per many mobile websites, it's nice to include a link in the footer that can override the theme to the main site.

Could achieve this with a link in the footer that would set a session variable indicating the override.
Then on future page inits it'd check for this, and if none set - fall back on the mobile theme.

Usually this is achieved with having a mobile subdomain or something similar... but this can't be a solution here.

Great and easy module though!

Comments

robloach’s picture

Sounds like a neat feature. Would it be a flag in the query string URL that would indicate to use the mobile theme?

simplyray’s picture

Priority: Normal » Major

Would be interested in this feature - too. Espacially on tablets (e.g. iPad) this would be an really interesting and useful feature. Anyone already implemented/hooked "mobile theme" regarding this issue?

simplyray’s picture

Quick and dirty:

mobile_theme.module

<?php

/**
 * Check to see if the user is running on a mobile browser.
 */
function mobile_theme_init() {
  $browser = browscap_get_browser();
  if (isset($browser['ismobiledevice']) && !isset($_SESSION['force_default_theme'])) {
    if ($browser['ismobiledevice']) {
      $theme = variable_get('mobile_theme_selection', 'default');
      if ($theme != 'default') {
        global $custom_theme;
        $custom_theme = $theme;
      }
    }
  }
}

/**
 * Forces system to use default theme
 */
function toggle_mobile_theme() {
	if($_SESSION['force_default_theme']) {
		unset($_SESSION['force_default_theme']);
	} else {
		$_SESSION['force_default_theme'] = true;
	}
	
	header('Location: '.request_uri());
}

/**
 * Checks if current browser is mobile device
 */
function is_mobile_device() {
	$browser = browscap_get_browser();
	if (isset($browser['ismobiledevice']) && $browser['ismobiledevice'] == true) {
		return true;
	} else {
		return false;
	}
}

/**
 * Alter the system theme settings form to add the mobile theme settings.
 */
function mobile_theme_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'system_theme_settings') {
    if ($form['var']['#value'] == 'theme_settings') {
      $themes = array('default' => t('Default'));
      $options = list_themes();
      foreach ($options as $name => $attr) {
        if ($attr->status) {
          $themes[$name] = $attr->info['name'];
        }
      }
      $form['mobile_theme'] = array(
        '#type' => 'fieldset',
        '#prefix' => '<div class="theme-settings-right">',
        '#suffix' => '</div>',
        '#title' => t('Mobile theme'),
        '#description' => t('Choose which theme will be used when the user is on a mobile device. Please note that <em>Browscap</em> must be <a href="@browscapconfigruation">configured properly</a>.', array('@browscapconfigruation' => url('admin/settings/browscap'))),
        'mobile_theme_selection' => array(
          '#type' => 'select',
          '#title' => 'Mobile theme',
          '#description' => t('The theme to use when serving a mobile device.'),
          '#options' => $themes,
          '#default_value' => variable_get('mobile_theme_selection', 'default'),
        ),
        '#weight' => -4,
      );
      $form['#submit'][] = 'mobile_theme_settings_submit';
    }
  }
}

/**
 * Submit handler on the theme settings to save the mobile theme.
 */
function mobile_theme_settings_submit($form, $form_state) {
  if (isset($form_state['values']['mobile_theme_selection'])) {
    variable_set('mobile_theme_selection', $form_state['values']['mobile_theme_selection']);
  }
}
?>

For Frontend Module:

/* Mobile theme toggle */
if(isset($_POST['toggle_mobile'])) {
	toggle_mobile_theme();
}

[...]

<?php if (is_mobile_device()) {
	$browser = browscap_get_browser();
	print '	<form method="post">';
	print '		Für dein '.$browser['browser'].' ist eine Mobile Version verfügbar. ';
	print '		<input type="submit" value="Mobile Version aktivieren!"/>';
	print '		<input type="hidden" name="toggle_mobile" value="1" />';
	print '	</form>';
} ?>
lance.gliser’s picture

Status: Active » Needs review
StatusFileSize
new3.76 KB

Good afternoon everyone. I've worked up a patch that creates a block which can be used for switching back and forth between the mobile theme, and the default. Your mobile users will be able to use the switcher automatically if you put the block on the screen. A permission has also been created that will allow administrators to use the theme switcher as well if desired.

Try it out!

jschrab’s picture

Applying this patch fails for me (using Netbeans 7.0 to apply it) on Mobile Theme 1.2

lance.gliser’s picture

I made an additional enhancement to this code here to allow page cache to be disabled, and put the whole zip file up for the author's review at: http://drupal.org/node/1264504

Hopefully he'll take some action and tweak it all to his liking so we can get this in the next release.

MakeOnlineShop’s picture

Issue summary: View changes

Hello,

Can I know if this function now exists in the module ?

Thank you.