You are here

mobile_theme.module in Mobile Theme 5

Same filename and directory in other branches
  1. 6 mobile_theme.module
  2. 7 mobile_theme.module

File

mobile_theme.module
View source
<?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'])) {
    if ($browser['ismobiledevice']) {
      $theme = variable_get('mobile_theme_selection', 'default');
      if ($theme != 'default') {
        global $custom_theme;
        $custom_theme = $theme;
      }
    }
  }
}

/**
 * Alter the system theme settings form to add the mobile theme settings.
 */
function mobile_theme_form_alter($form_id, &$form) {
  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->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'] = array();

      // '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['mobile_theme_selection'])) {
    variable_set('mobile_theme_selection', $form_state['mobile_theme_selection']);
  }
}

Functions

Namesort descending Description
mobile_theme_form_alter Alter the system theme settings form to add the mobile theme settings.
mobile_theme_init Check to see if the user is running on a mobile browser.
mobile_theme_settings_submit Submit handler on the theme settings to save the mobile theme.