[BUG] Caching Framework destroys mobile view 69/15469/1
authorBastian Bringenberg <mail@bastian-bringenberg.de>
Wed, 10 Oct 2012 00:23:38 +0000 (02:23 +0200)
committerBastian Bringenberg <mail@bastian-bringenberg.de>
Wed, 10 Oct 2012 00:23:38 +0000 (02:23 +0200)
Created Tempfile for moƃbile version

Change-Id: I6f0593c29083a706bf118b612deb7e7449e4bb12
Fixes: #40942 @0h05

index.php

index e054e09..768dce6 100644 (file)
--- a/index.php
+++ b/index.php
@@ -4,7 +4,9 @@ require_once("ZabbixAPI.class.php");
 require('config.inc.php');
 $temp_ajax = 'temp/ajax.html';
 $temp_all = 'temp/all.html';
-$cachingTime = 120;
+$temp_mobile = 'temp/mobile.html';
+
+       $cachingTime = 120;
 
 /**
  * @todo generate checkServerErrorAcknowledged - Method
@@ -15,12 +17,33 @@ function checkServerErrorAcknowledged($hostid){
        return true;
 }
 
+function isMobile(){
+          try{
+                  if((bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad')) throw new Exception('iPad found');
+                  if((bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPhone')) throw new Exception('iPhone found');
+                  if((bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPod')) throw new Exception('iPod found');
+                  if((bool) strpos($_SERVER['HTTP_USER_AGENT'],'Android')) throw new Exception('Android found');
+                  if((bool) strpos($_SERVER['HTTP_USER_AGENT'],'webOS')) throw new Exception('webOS');
+                  if((bool) strpos($_SERVER['HTTP_USER_AGENT'],'BlackBerry')) throw new Exception('BlackBerry');
+                  if((bool) strpos($_SERVER['HTTP_USER_AGENT'],'Nokia')) throw new Exception('Nokia');
+                  return FALSE;
+          }catch(Exception $e){
+                       return TRUE;
+          }
+}
+
 if(isset($_GET['ajax']) && $_GET['ajax'] == 1){
     if(file_exists($temp_ajax) && time() - filemtime($temp_ajax) < $cachingTime){
         $tmp = file_get_contents($temp_ajax);
         echo $tmp;
         die();
     }
+}elseif(isMobile()){
+       if(file_exists($temp_mobile) && time() - filemtime($temp_mobile) < $cachingTime){
+               $tmp = file_get_contents($temp_mobile);
+               echo $tmp;
+               die();
+       }
 }else{
     if(file_exists($temp_all) &&  time() - filemtime($temp_all) < $cachingTime){
         $tmp = file_get_contents($temp_all);
@@ -87,23 +110,21 @@ if(isset($_GET['ajax']) && $_GET['ajax'] == 1){
     $content = file_get_contents('static/indexTemplate.html');
     $content = str_replace('{statusDiv}', $statusDiv, $content);
 
-       $twitterTheme = '';
-       $styleSheet = 'static/style_mobile.css';
-       try{
-               if((bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad')) throw new Exception('iPad found');
-               if((bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPhone')) throw new Exception('iPhone found');
-               if((bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPod')) throw new Exception('iPod found');
-               if((bool) strpos($_SERVER['HTTP_USER_AGENT'],'Android')) throw new Exception('Android found');
-               if((bool) strpos($_SERVER['HTTP_USER_AGENT'],'webOS')) throw new Exception('webOS');
-               if((bool) strpos($_SERVER['HTTP_USER_AGENT'],'BlackBerry')) throw new Exception('BlackBerry');
-               if((bool) strpos($_SERVER['HTTP_USER_AGENT'],'Nokia')) throw new Exception('Nokia');
+
+        if(!isMobile()){
                $twitterTheme = file_get_contents('static/twitterTheme.html');
                $styleSheet = 'static/style.css';
-       }catch(Exception $e){
+               $content = str_replace('{twitterDiv}', $twitterTheme, $content);
+               $content = str_replace('{styleSheet}', $styleSheet, $content);
+               file_put_contents($temp_all, $content);
+        }else{
+               $twitterTheme = '';
+               $styleSheet = 'static/style_mobile.css';
+               $content = str_replace('{twitterDiv}', $twitterTheme, $content);
+               $content = str_replace('{styleSheet}', $styleSheet, $content);
+               file_put_contents($temp_mobile, $content);
        }
-       $content = str_replace('{twitterDiv}', $twitterTheme, $content);
-       $content = str_replace('{styleSheet}', $styleSheet, $content);
-    file_put_contents($temp_all, $content);
+
 }
 
 echo $content;