| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Search for browser details | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * PHP Version 5 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @category  Plugins | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @package   Users | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @author    Hans-Joachim Piepereit <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @copyright 2013 cSphere Team | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @license   http://opensource.org/licenses/bsd-license Simplified BSD License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @link      http://www.csphere.eu | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  **/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | namespace csphere\plugins\users\classes; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * Search for browser details | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @category  Plugins | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @package   Users | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @author    Hans-Joachim Piepereit <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @copyright 2013 cSphere Team | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * @license   http://opensource.org/licenses/bsd-license Simplified BSD License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * @link      http://www.csphere.eu | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  **/ | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  | abstract class Agent | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      * List of known browsers, Chrome last to not match forks as Chrome | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |      **/ | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     private static $_browsers = ['Firefox' => 'Firefox', | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |                                  'Trident' => 'Internet Explorer', | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |                                  'OPR'     => 'Opera', | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |                                  'Version' => 'Safari', | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |                                  'Chrome'  => 'Chrome']; | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      * List of known systems | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      **/ | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     private static $_systems = ['Windows NT 6.3' => 'Windows 8.1', | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |                                 'Windows NT 6.2' => 'Windows 8', | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |                                 'Windows NT 6.1' => 'Windows 7', | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |                                 'Windows NT 6.0' => 'Windows Vista', | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |                                 'Windows'        => 'Windows', | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |                                 'Mac OS X'       => 'Mac OS X', | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |                                 'Linux'          => 'Linux']; | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      * Search for browser details | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      * @param string $agent User agent as a string | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |      **/ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     public static function browser($agent) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $result = 'Unknown'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $all    = count(self::$_browsers); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $web    = array_keys(self::$_browsers); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         // Run through possible browsers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         for ($i = 0; $i < $all; $i++) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             $search = strrpos($agent, $web[$i]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             // Format agent data on matches | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             if ($search > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                 $agent = substr($agent, $search); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                 $agent = explode('/', $agent)[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                 $agent = (int)explode('.', $agent)[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                 // Trident version plus four is very often IE version | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                 if ($web[$i] == 'Trident') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                     $agent += 4; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                 // Add version to browser name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                 $result = self::$_browsers[$web[$i]] . ' ' . $agent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                 $i = $all; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         return $result; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |      * Search for system details | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |      * @param string $agent User agent as a string | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |      **/ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     public static function system($agent) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $result = 'Unknown'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $all    = count(self::$_systems); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $ops    = array_keys(self::$_systems); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         // Run through possible systems | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         for ($i = 0; $i < $all; $i++) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             $search = strrpos($agent, $ops[$i]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |             // Format agent data on matches | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |             if ($search > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                 $result = self::$_systems[$ops[$i]]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |                 $i = $all; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         return $result; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 122 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 123 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 124 |  |  |  |