mobile_switch_handler_filter.inc in Mobile Switch 7.2
mobile_switch_handler_filter_ismobile.inc
File
views/mobile_switch_handler_filter.inc
View source
<?php
class mobile_switch_handler_filter extends views_handler_filter {
function value_form(&$form, &$form_state) {
if (variable_get('mobile_switch_mobile_theme', 'none') === 'none') {
$form['message'] = array(
'#markup' => t('Please configure the !basic-settings of Mobile Switch with a supported operating mode.', array(
'!basic-settings' => l(t('Basic settings'), 'admin/config/user-interface/mobile-switch'),
)),
);
}
$form['operator'] = array(
'#type' => 'select',
'#title' => t('Display only'),
'#default_value' => isset($this->operator['value']) ? $this->operator['value'] : NULL,
'#options' => mobile_switch_handler_filter_options(),
);
return $form;
}
function can_expose() {
return FALSE;
}
function show_operator_form(&$form, &$form_state) {
$this
->operator_form($form, $form_state);
$form['operator']['#prefix'] = '<div class="views-group-box views-left-30">';
$form['operator']['#suffix'] = '</div>';
}
function admin_summary() {
$options = mobile_switch_handler_filter_options();
$message = '';
if (variable_get('mobile_switch_mobile_theme', 'none') === 'none') {
$message = ' - ' . t('The used operating mode is not supported.');
}
return check_plain((string) $options[$this->operator['value']] . $message);
}
function query() {
$get['op_mode'] = variable_get('mobile_switch_mobile_theme', 'none');
if ($get['op_mode'] === 'none') {
return;
}
$get['tablet_usage'] = (bool) variable_get('mobile_switch_tablet_usage', TRUE);
$get['prevent_devices'] = (bool) variable_get('mobile_switch_prevent_devices', FALSE);
$detect = mobile_switch_mobile_detect();
$ismobile = $detect['ismobiledevice'] ? $detect['ismobiledevice'] : 0;
if ($get['prevent_devices'] === TRUE && $detect['prevent_device'] === TRUE || $get['tablet_usage'] === FALSE && $detect['istablet'] === TRUE) {
return;
}
if ($get['op_mode'] != 'detectonly' && $get['op_mode'] != 'redirect') {
$theme_switch = mobile_switch_handler_filter_check_theme_switch();
switch ($this->operator) {
case '0':
if ($theme_switch == 'standard' || $theme_switch == 'standard-rm') {
return;
}
break;
case '1':
if ($ismobile == 1 && ($theme_switch == 'standard' || $theme_switch == 'standard-rm')) {
$this->operator == 'dummy';
break;
}
break;
}
}
$this
->ensure_my_table();
$join = new views_join();
$this->query
->add_where($this->options['group'], $ismobile, $this->operator, '=');
}
}
function mobile_switch_handler_filter_check_theme_switch() {
static $theme_switch;
if (!$theme_switch) {
$name = 'mobile_switch_mode';
$theme_cookie = isset($_COOKIE[$name]) ? $_COOKIE[$name] : FALSE;
if (isset($_GET['mobile_switch'])) {
switch ($_GET['mobile_switch']) {
case 'standard':
$theme_switch = 'standard';
break;
case 'standard-rm':
$theme_switch = 'standard-rm';
break;
case 'mobile':
$theme_switch = 'mobile';
break;
case 'mobile-rm':
$theme_switch = 'mobile-rm';
break;
}
}
elseif ($theme_cookie) {
switch ($theme_cookie) {
case 'standard':
$theme_switch = 'standard';
break;
case 'standard-rm':
$theme_switch = 'standard-rm';
break;
case 'mobile':
$theme_switch = 'mobile';
break;
case 'mobile-rm':
$theme_switch = 'mobile-rm';
break;
}
}
else {
$theme_switch = FALSE;
}
}
return $theme_switch;
}
function mobile_switch_handler_filter_options() {
return array(
0 => t('Is not mobile'),
1 => t('Is mobile'),
);
}