]> source.dussan.org Git - nextcloud-server.git/commitdiff
add a formfactor session variable which is autodetected but can also manually overwri...
authorFrank Karlitschek <karlitschek@kde.org>
Fri, 6 Jan 2012 16:21:24 +0000 (17:21 +0100)
committerFrank Karlitschek <karlitschek@kde.org>
Fri, 6 Jan 2012 16:21:24 +0000 (17:21 +0100)
currently we have:
         * default -> the normal desktop browser interface
         * mobile -> interface for smartphones
         * tablet -> interface for tablets
         * standalone -> the default interface but without header, footer and sidebar. just the application. useful to use just a specific app on the desktop in a standalone window.
In the future we should adapt the userinterface to the specific formfactor.

lib/base.php

index 700236c96c686aa743a273fe6cd293ad732c140f..0954e3615bdb03b3e8cfb1de3b6570bc5660a225 100644 (file)
@@ -70,6 +70,31 @@ class OC{
                }
        }
 
+       /**
+        * autodetects the formfactor of the used device
+        * default -> the normal desktop browser interface
+        * mobile -> interface for smartphones
+        * tablet -> interface for tablets
+        * standalone -> the default interface but without header, footer and sidebar. just the application. useful to ue just a specific app on the desktop in a standalone window.
+        */
+       public static function detectFormfactor(){
+               // please add more useragent strings for other devices
+               if(isset($_SERVER['HTTP_USER_AGENT'])){
+                       if(stripos($_SERVER['HTTP_USER_AGENT'],'ipad')>0) {
+                               $mode='tablet';
+                       }elseif(stripos($_SERVER['HTTP_USER_AGENT'],'iphone')>0){
+                               $mode='mobile';
+                       }elseif((stripos($_SERVER['HTTP_USER_AGENT'],'N9')>0) and (stripos($_SERVER['HTTP_USER_AGENT'],'nokia')>0)){
+                               $mode='mobile';
+                       }else{
+                               $mode='default';
+                       }
+               }else{
+                       $mode='default';
+               }
+               return($mode);
+       }
+
        public static function init(){
                // register autoloader
                spl_autoload_register(array('OC','autoload'));
@@ -130,6 +155,16 @@ class OC{
                ini_set('session.cookie_httponly','1;');
                session_start();
 
+               // if the formfactor is not yet autodetected do the autodetection now. For possible forfactors check the detectFormfactor documentation
+               if(!isset($_SESSION['formfactor'])){
+                       $_SESSION['formfactor']=OC::detectFormfactor();
+               }
+               // allow manual override via GET parameter
+               if(isset($_GET['formfactor'])){
+                       $_SESSION['formfactor']=$_GET['formfactor'];
+               }
+
+
                // Add the stuff we need always
                OC_Util::addScript( "jquery-1.6.4.min" );
                OC_Util::addScript( "jquery-ui-1.8.14.custom.min" );
@@ -214,5 +249,7 @@ if(!function_exists('get_temp_dir')) {
 
 require_once('fakedirstream.php');
 
+
+
 // FROM search.php
 new OC_Search_Provider_File();