-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrowserUpdatePlugin.php
executable file
·81 lines (69 loc) · 2.36 KB
/
BrowserUpdatePlugin.php
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
<?php
/**
* BrowserUpdatePlugin.class.php
*
* To show the information bar in current browsers and reset css, supply
* parameter ?buforce
*
* Browser images (c) morcha.net
*
* @author Jan-Hendrik Willms <[email protected]>
* @copyright UOL
* @version 1.0.2
*/
class BrowserUpdatePlugin extends StudIPPlugin implements SystemPlugin {
const CONFIG_KEY = 'PLUGIN_BROWSERUPDATE_HIDDEN';
const CSS = '/assets/browser-update.css';
private static $browser_tests = array(
'~SeaMonkey/(\d+(?:\.\d+)*)~' => '0', // ignore seamonkey
'~Chrome/(\d+(?:\.\d+)*)~' => '20',
'~Firefox/(\d+(?:\.\d+)*)~' => '13',
'~MSIE (\d+(?:\.\d+)*)~' => '8',
'~Opera/(\d+(?:\.\d+)*)~' => '11',
'~Version/(\d+(?:\.\d+)*).*Safari~' => '5.1',
);
private $config;
public function __construct() {
parent::__construct();
// Get user config
$this->config = UserConfig::get($GLOBALS['auth']->auth['uid']);
$hidden = $this->config[self::CONFIG_KEY];
if ($force = isset($_GET['buforce'])) {
$this->config->delete(self::CONFIG_KEY);
}
// If not hidden by config, test for outdated browser
$valid = false;
if (!(bool)$hidden) {
foreach (self::$browser_tests as $regexp => $min_version) {
// Test regexp against user agent, returns version on match
if (preg_match($regexp, $_SERVER['HTTP_USER_AGENT'], $match)) {
$valid = true;
$hidden = version_compare($match[1], $min_version, '>=');
break;
}
}
}
// Leave if browser is not outdated
if (!$force and $valid and $hidden) {
return;
}
// Inject the information bar
$factory = new Flexi_TemplateFactory($this->getPluginPath().'/templates/');
PageLayout::addBodyElements($factory->render('browser-update', array(
'image_dir' => $this->getPluginURL().'/assets/images/',
'plugin_url' => PluginEngine::getLink($this, array(), 'hide'),
)));
// Add css to site header (create if neccessary)
if ($force or !file_exists($this->getPluginPath().self::CSS)) {
$css = $factory->render('css');
file_put_contents($this->getPluginPath().self::CSS, $css);
}
PageLayout::addStylesheet($this->getPluginURL().self::CSS);
}
public function perform($unconsumed_path) {
$this->config->store(self::CONFIG_KEY, 'hidden');
$url = Request::get('return', URLHelper::GetURL('index.php'));
Header('Location: '.$url);
die;
}
}