From 90d4d3fd206ac296bea8e228a058c7fcecb58af3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Wed, 20 Jan 2021 11:04:59 +0100 Subject: [PATCH] Request: is_mobile --- SL/Request.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SL/Request.pm b/SL/Request.pm index c33b6b3e5..7c4fa7198 100644 --- a/SL/Request.pm +++ b/SL/Request.pm @@ -20,7 +20,7 @@ our @EXPORT_OK = qw(flatten unflatten); use Rose::Object::MakeMethods::Generic ( scalar => [ qw(applying_database_upgrades post_data) ], - 'scalar --get_set_init' => [ qw(cgi layout presenter is_ajax type) ], + 'scalar --get_set_init' => [ qw(cgi layout presenter is_ajax is_mobile type) ], ); sub init_cgi { @@ -39,6 +39,12 @@ sub init_is_ajax { return ($ENV{HTTP_X_REQUESTED_WITH} || '') eq 'XMLHttpRequest' ? 1 : 0; } +sub init_is_mobile { + # mobile clients will change their user agent when the user requests + # desktop version so user agent is the most reliable way to identify + return ($ENV{HTTP_USER_AGENT} || '') =~ /Mobi/ ? 1 : 0; +} + sub init_type { return 'html'; } -- 2.20.1