fluxcms /inc/popoon/classes/browser.php

Language PHP Lines 258
MD5 Hash 5f57a7eef076540d8b833ec902b29f8d
Repository https://github.com/chregu/fluxcms.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
    

class popoon_classes_browser {
        
    static private $BrowserName = "Unknown";
    static private $BrowserSubName = "None";
    static private $Version = "Unknown";
    static private $Platform = "Unknown";
    static private $UserAgent = "Not reported";
    static private $isMobile = null;
    
    static private $initialized = false;
    static private $parsed = false;
    
    private function __construct() {}
    
    static function init() {
        if (!self::$initialized) {
            if (isset( $_SERVER['HTTP_USER_AGENT'])) {
                self::$UserAgent = $_SERVER['HTTP_USER_AGENT'];
            }
            self::$initialized = true;
        }
    }
    
    
    static function isMozilla() {
        return( self::getName() == "mozilla");
    }
    
    static function isMozillaAndHasMidas() {
        if (self::getName() == "mozilla") {
            if (stripos(self::$UserAgent,"camino/0.8.")) {
                return false;
            } else {
                return true;
            }
        }
        return false;
    }
    
    static function hasContentEditable() {
        return (self::isMozillaAndHasMidas() || self::isMSIEWin());
           
    }
    
    
    
    
    static function hasBadCss() {
           self::init();
           $name = self::getName();
           $version = self::getVersion();
           if ($name == "opera" && $version < 8) {
               return true;
           }
           if ($name == "mozilla" && $version < 5) {
               return true;
           }
           return false;
           
    }
    static function isPalm() {
        return (self::getPlatform()=="palm");
    }
    
    static function isMobile() {
        // creating the WURFL object
        if (self::$isMobile === null) {
            require_once(BX_INCLUDE_DIR.'/wurfl_config.php');
            require_once(BX_INCLUDE_DIR.'/wurfl_class.php');
            
            $myDevice = new wurfl_class($wurfl, $wurfl_agents);
            $myDevice->GetDeviceCapabilitiesFromAgent($_SERVER["HTTP_USER_AGENT"]);
            if($myDevice->capabilities['xhtml_ui']['html_wi_w3_xhtmlbasic']){
                self::$isMobile = true;
            }
            else{
                self::$isMobile = false;
            }
        }
        return self::$isMobile;
    }
    
    static function supportedByFCK() {
        
        return (self::isMozilla() || self::isMSIEWin() || self::isSafari3() || self::isOpera95());
    }

    static function isMSIEWin() {
        return( self::getName() == "msie" && self::getPlatform()=="windows");
    }
    
    static function isSafari() {
        return( self::getName() == "safari" );
    }
    
    static function isSafari3() {
        return( self::getName() == "safari" && self::getVersion() >= 3);
    }
    
    static function isOpera8() {
        return( self::getName() == "opera"  && self::getVersion() >= 8);
    }
     static function isOpera95() {
        return( self::getName() == "opera"  && self::getVersion() >= 9.5);
    }
    
    
    static function isKonqueror34() {
        return( self::getName() == "konqueror"  && self::getVersion() >= 3.4);
    }
    
    static function getName() {
        self::parse();
        return self::$BrowserName;
    }
    static function getSubName() {
        self::parse();
        return self::$BrowserSubName;
    }
    
    static function getVersion() {
        self::parse();
        return self::$Version;
    }
    
    static function getPlatform() {
        self::parse();
        return self::$Platform;
    }
    
    static function getAgent() {
        self::init();
        return self::$UserAgent;
    }
    
    static function parse(){
        
        if (!self::$parsed) {
            self::init();
            $agent = self::$UserAgent;
            // initialize properties
            $bd['platform'] = "Unknown";
            $bd['browser'] = "Unknown";
            $bd['version'] = "Unknown";

            // find operating system
            $OSs = array(
                'win' => 'windows',
                'mac' => 'macintosh',
                'linux' => 'linux',
                'os/2' => 'os/2',
                'beos' => 'beos',
                'palm' => 'palm',
            );
            foreach ($OSs as $OS => $OSname) {
                if (stripos($agent, $OS) !== false) {
                    $bd['platform'] = $OSname;
                    break;
                }
            }

            // test for Opera
            if ($val = stristr($agent, "opera")) {
                if (stripos($val, '/') !== false) {
                    $val = explode("/",$val);
                    $bd['browser'] = $val[0];
                    $val = explode(" ",$val[1]);
                    $bd['version'] = $val[0];
                }else{
                    $val = explode(" ",stristr($val,"opera"));
                    $bd['browser'] = $val[0];
                    $bd['version'] = $val[1];
                }

                // test for WebTV
            }elseif(stripos($agent, 'msie') !== false){
                $val = explode(" ",stristr($agent,"msie"));
                $bd['browser'] = $val[0];
                $bd['version'] = $val[1];

            }elseif(stripos($agent, 'galeon') !== false){
                $val = explode(" ",stristr($agent,"galeon"));
                $val = explode("/",$val[0]);
                $bd['browser'] = "Mozilla";
                $bd['version'] = $val[1];
                $bd['subbrowser']=$val[0];

                // test for Konqueror
            }elseif(stripos($agent, 'konqueror') !== false){
                $val = explode(" ",stristr($agent,"Konqueror"));
                $val = explode("/",$val[0]);
                $bd['browser'] = $val[0];
                $bd['version'] = $val[1];

            }elseif(stripos($agent, 'firebird') !== false){
                $bd['browser']="Mozilla";
                $bd['subbrowser']="Firefox";
                $val = stristr($agent, "Firebird");
                $val = explode("/",$val);
                $bd['version'] = $val[1];

                // test for Firefox
            }elseif(stripos($agent, 'firefox') !== false){
                $bd['browser']="Mozilla";
                $bd['subbrowser'] = "Firefox";
                $val = stristr($agent, "Firefox");

                $val = explode("/",$val);
                $bd['version'] = $val[1];
            }elseif(stripos($agent, 'mozilla') !== false && preg_match('/rv:[0-9]\.[0-9]/i', $agent) && stripos($agent, 'netscape' === false)){
                $bd['browser'] = "Mozilla";
                $bd['subbrowser'] = "Mozilla";
                $val = explode(" ",stristr($agent,"rv:"));
                preg_match('/rv:[0-9]\.[0-9]\.[0-9]/i',$agent, $val);
                $bd['version'] = str_replace("rv:","",$val[0]);

            }elseif(stripos($agent, 'safari') !== false){
                $bd['browser'] = "Safari";
                $val = substr($agent,strpos($agent,"Safari/") + 7);
                $bd['version'] = $val;

                // remaining two tests are for Netscape
            }elseif(stripos($agent, 'netscape') !== false){
                $val = explode(" ",stristr($agent,"netscape"));
                $val = explode("/",$val[0]);
                $bd['browser'] = $val[0];
                $bd['version'] = $val[1];

            }elseif(stripos($agent, 'mozilla') !== false && !preg_match('/rv:[0-9]\.[0-9]\.[0-9]/i', $agent)){
                $val = explode(" ",stristr($agent,"mozilla"));
                $val = explode("/",$val[0]);
                $bd['browser'] = "Mozilla";
                $bd['subbrowser'] = "Netscape";
                if (isset($val[1])) {
                    $bd['version'] = $val[1];
                }
            }

            // clean up extraneous garbage that may be in the name
            $bd['browser'] = preg_replace('/[^a-zA-Z]/', '', $bd['browser']);
            // clean up extraneous garbage that may be in the version
            $bd['version'] = preg_replace('/[^0-9.a-zA-Z]/', '', $bd['version']);

            // finally assign our properties
            self::$BrowserName = strtolower($bd['browser']);
            if (isset($bd['subbrowser'])) {
                self::$BrowserSubName = strtolower($bd['subbrowser']);
            }
            self::$Version = $bd['version'];
            self::$Platform = $bd['platform'];
            self::$parsed = true;
        }
    }
}
Back to Top