| 1 |
<?php |
| 2 |
namespace MaxButtons; |
| 3 |
|
| 4 |
class supportController extends MaxController |
| 5 |
{ |
| 6 |
protected $view_template = 'maxbuttons-support'; |
| 7 |
|
| 8 |
public function view() |
| 9 |
{ |
| 10 |
$this->loadView(); |
| 11 |
parent::view(); |
| 12 |
} |
| 13 |
|
| 14 |
protected function loadView() |
| 15 |
{ |
| 16 |
$this->view->browser = $this->maxbuttons_get_browser(); |
| 17 |
$this->view->theme = \wp_get_theme(); |
| 18 |
$this->view->plugins = get_plugins(); |
| 19 |
$this->view->active_plugins = get_option('active_plugins', array()); |
| 20 |
} |
| 21 |
|
| 22 |
public function handlePost() |
| 23 |
{ |
| 24 |
return true; // no posts here. |
| 25 |
} |
| 26 |
|
| 27 |
// http://www.php.net/manual/en/function.get-browser.php#101125. |
| 28 |
// Cleaned up a bit, but overall it's the same. |
| 29 |
protected function maxbuttons_get_browser() { |
| 30 |
$user_agent = $_SERVER['HTTP_USER_AGENT']; |
| 31 |
$browser_name = 'Unknown'; |
| 32 |
$platform = 'Unknown'; |
| 33 |
$version= ""; |
| 34 |
|
| 35 |
// First get the platform |
| 36 |
if (preg_match('/linux/i', $user_agent)) { |
| 37 |
$platform = 'Linux'; |
| 38 |
} |
| 39 |
elseif (preg_match('/macintosh|mac os x/i', $user_agent)) { |
| 40 |
$platform = 'Mac'; |
| 41 |
} |
| 42 |
elseif (preg_match('/windows|win32/i', $user_agent)) { |
| 43 |
$platform = 'Windows'; |
| 44 |
} |
| 45 |
|
| 46 |
// Next get the name of the user agent yes seperately and for good reason |
| 47 |
if (preg_match('/MSIE/i', $user_agent) && !preg_match('/Opera/i', $user_agent)) { |
| 48 |
$browser_name = 'Internet Explorer'; |
| 49 |
$browser_name_short = "MSIE"; |
| 50 |
} |
| 51 |
elseif (preg_match('/Firefox/i', $user_agent)) { |
| 52 |
$browser_name = 'Mozilla Firefox'; |
| 53 |
$browser_name_short = "Firefox"; |
| 54 |
} |
| 55 |
elseif (preg_match('/Chrome/i', $user_agent)) { |
| 56 |
$browser_name = 'Google Chrome'; |
| 57 |
$browser_name_short = "Chrome"; |
| 58 |
} |
| 59 |
elseif (preg_match('/Safari/i', $user_agent)) { |
| 60 |
$browser_name = 'Apple Safari'; |
| 61 |
$browser_name_short = "Safari"; |
| 62 |
} |
| 63 |
elseif (preg_match('/Opera/i', $user_agent)) { |
| 64 |
$browser_name = 'Opera'; |
| 65 |
$browser_name_short = "Opera"; |
| 66 |
} |
| 67 |
elseif (preg_match('/Netscape/i', $user_agent)) { |
| 68 |
$browser_name = 'Netscape'; |
| 69 |
$browser_name_short = "Netscape"; |
| 70 |
} |
| 71 |
|
| 72 |
// Finally get the correct version number |
| 73 |
$known = array('Version', $browser_name_short, 'other'); |
| 74 |
$pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#'; |
| 75 |
if (!preg_match_all($pattern, $user_agent, $matches)) { |
| 76 |
// We have no matching number just continue |
| 77 |
} |
| 78 |
|
| 79 |
// See how many we have |
| 80 |
$i = count($matches['browser']); |
| 81 |
if ($i != 1) { |
| 82 |
// We will have two since we are not using 'other' argument yet |
| 83 |
// See if version is before or after the name |
| 84 |
if (strripos($user_agent, "Version") < strripos($user_agent, $browser_name_short)){ |
| 85 |
$version= $matches['version'][0]; |
| 86 |
} |
| 87 |
else { |
| 88 |
$version= $matches['version'][1]; |
| 89 |
} |
| 90 |
} |
| 91 |
else { |
| 92 |
$version= $matches['version'][0]; |
| 93 |
} |
| 94 |
|
| 95 |
// Check if we have a number |
| 96 |
if ($version == null || $version == "") { $version = "?"; } |
| 97 |
|
| 98 |
return array( |
| 99 |
'user_agent' => $user_agent, |
| 100 |
'name' => $browser_name, |
| 101 |
'version' => $version, |
| 102 |
'platform' => $platform, |
| 103 |
'pattern' => $pattern |
| 104 |
); |
| 105 |
} |
| 106 |
|
| 107 |
} // controller. |
| 108 |
|