View source
<?php
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;
}
}
}
}
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();
}
}
}
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']);
}
}