Labs Tidy up, depreciate old trip planner tester, promote myway balance/service alerts to main site
[busui.git] / include / common.inc.php
blob:a/include/common.inc.php -> blob:b/include/common.inc.php
--- a/include/common.inc.php
+++ b/include/common.inc.php
@@ -1,4 +1,20 @@
 <?php
+
+/*
+ *    Copyright 2010,2011 Alexander Sadleir 
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
 
 date_default_timezone_set('Australia/ACT');
 $debugOkay = Array(
@@ -32,10 +48,14 @@
 $basePath = "";
 if (strstr($_SERVER['PHP_SELF'], "labs/")
         || strstr($_SERVER['PHP_SELF'], "myway/")
+        || strstr($_SERVER['PHP_SELF'], "lib/")
+        || strstr($_SERVER['PHP_SELF'], "geo/")
+        || strstr($_SERVER['PHP_SELF'], "include/")
         || strstr($_SERVER['PHP_SELF'], "servicealerts/"))
     $basePath = "../";
 
 function isDebugServer() {
+    
     return php_sapi_name() == "cli" || isset($_SERVER['SERVER_NAME']) && ( $_SERVER['SERVER_NAME'] == "azusa" || $_SERVER['SERVER_NAME'] == "vanille"
             || $_SERVER['SERVER_NAME'] == "localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1");
 }
@@ -52,7 +72,7 @@
 
 function isAnalyticsOn() {
     $user_agent = $_SERVER['HTTP_USER_AGENT'];
-    return!isDebugServer() && !preg_match('/cloudkick/i', $user_agent) && !preg_match('/googlebot/i', $user_agent) &&
+    return !isDebugServer() && !preg_match('/cloudkick/i', $user_agent) && !preg_match('/googlebot/i', $user_agent) &&
             !preg_match('/baidu/i', $user_agent);
 }
 
@@ -65,31 +85,15 @@
     if (isDebug($debugReason))
         echo "\n<!-- " . date(DATE_RFC822) . "\n $msg -->\n";
 }
-
+function isIOSDevice() {
+   return strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPod') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPad');
+}
 function isJQueryMobileDevice() {
     // http://forum.jquery.com/topic/what-is-the-best-way-to-detect-all-useragents-which-can-handle-jquery-mobile#14737000002087897
     $user_agent = $_SERVER['HTTP_USER_AGENT'];
     return preg_match('/iphone/i', $user_agent) || preg_match('/android/i', $user_agent) || preg_match('/webos/i', $user_agent) || preg_match('/ios/i', $user_agent) || preg_match('/bada/i', $user_agent) || preg_match('/maemo/i', $user_agent) || preg_match('/meego/i', $user_agent) || preg_match('/fennec/i', $user_agent) || (preg_match('/symbian/i', $user_agent) && preg_match('/s60/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/symbian/i', $user_agent) && preg_match('/platform/i', $user_agent) && $browser['majorver'] >= 3) || (preg_match('/blackberry/i', $user_agent) && $browser['majorver'] >= 5) || (preg_match('/opera mobile/i', $user_agent) && $browser['majorver'] >= 10) || (preg_match('/opera mini/i', $user_agent) && $browser['majorver'] >= 5);
 }
 
-function isFastDevice() {
-    $ua = $_SERVER['HTTP_USER_AGENT'];
-    $fastDevices = Array(
-        "Mozilla/5.0 (X11;",
-        "Mozilla/5.0 (Windows;",
-        "Mozilla/5.0 (iP",
-        "Mozilla/5.0 (Linux; U; Android",
-        "Mozilla/4.0 (compatible; MSIE"
-    );
-    $slowDevices = Array(
-        "J2ME",
-        "MIDP",
-        "Opera/",
-        "Mozilla/2.0 (compatible;",
-        "Mozilla/3.0 (compatible;"
-    );
-    return true;
-}
 
 function array_flatten($a, $f = array()) {
     if (!$a || !is_array($a))
@@ -130,10 +134,6 @@
         return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0);
     }
     return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0);
-}
-
-function bracketsMeanNewLine($input) {
-    return str_replace(")", "</small>", str_replace("(", "<br><small>", $input));
 }
 
 function sksort(&$array, $subkey = "id", $sort_ascending = false) {
@@ -199,5 +199,6 @@
     return implode($glue, $retVal);
 }
 
+
 ?>