This commit is contained in:
parent
fd34c4198c
commit
1b60dbb7ad
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
/**
|
||||
Standalone version of get_browser() in PHP
|
||||
http://www.php.net/manual/function.get-browser.php
|
||||
Detection of the capacities of a Web browser client.
|
||||
Requires a compatible browscap.ini database,
|
||||
such as php_browscap.ini on
|
||||
http://browsers.garykeith.com/downloads.asp
|
||||
|
||||
Interface:
|
||||
- function get_browser_local($user_agent=null,$return_array=false,$db='./browscap.ini',$cache=false)
|
||||
[Implied] $user_agent=null: The signature of the browser to be analysed. If this parameter is left to null, then it uses $_SERVER['HTTP_USER_AGENT'].
|
||||
[Implied] $return_array=false: When this parameter is activated, the function returns an array instead of an object.
|
||||
[Implied] $db='./browscap.ini': Allows specifying the path of the browscap.ini database, otherwise assumes that it is in the current directory.
|
||||
[Implied] $cache=false: Specify if the database can be kept in memory, to improve performances when querying this function more than once.
|
||||
Returns: An object (or an array, if asked to do so) with the capacities of the browser.
|
||||
|
||||
Typical use:
|
||||
{
|
||||
if (get_cfg_var('browscap'))
|
||||
$browser=get_browser(); //If available, use PHP native function
|
||||
else
|
||||
{
|
||||
require_once('php-local-browscap.php');
|
||||
$browser=get_browser_local();
|
||||
}
|
||||
print_r($browser);
|
||||
}
|
||||
|
||||
Version 1.5, 2010-02-06, http://alexandre.alapetite.fr/doc-alex/php-local-browscap/
|
||||
|
||||
------------------------------------------------------------------
|
||||
Written by Alexandre Alapetite, http://alexandre.alapetite.fr/cv/
|
||||
|
||||
Copyright 2005-2010, Licence: Creative Commons "Attribution-ShareAlike 2.0 France" BY-SA (FR),
|
||||
http://creativecommons.org/licenses/by-sa/2.0/fr/
|
||||
http://alexandre.alapetite.fr/divers/apropos/#by-sa
|
||||
- Attribution. You must give the original author credit
|
||||
- Share Alike. If you alter, transform, or build upon this work,
|
||||
you may distribute the resulting work only under a license identical to this one
|
||||
(Can be included in GPL/LGPL projects)
|
||||
- The French law is authoritative
|
||||
- Any of these conditions can be waived if you get permission from Alexandre Alapetite
|
||||
- Please send to Alexandre Alapetite the modifications you make,
|
||||
in order to improve this file for the benefit of everybody
|
||||
|
||||
If you want to distribute this code, please do it as a link to:
|
||||
http://alexandre.alapetite.fr/doc-alex/php-local-browscap/
|
||||
*/
|
||||
|
||||
$browscapIni=null; //Cache
|
||||
$browscapPath=''; //Cached database
|
||||
|
||||
function _sortBrowscap($a,$b)
|
||||
{
|
||||
$sa=strlen($a);
|
||||
$sb=strlen($b);
|
||||
if ($sa>$sb) return -1;
|
||||
elseif ($sa<$sb) return 1;
|
||||
else return strcasecmp($a,$b);
|
||||
}
|
||||
|
||||
function _lowerBrowscap($r) {return array_change_key_case($r,CASE_LOWER);}
|
||||
|
||||
function get_browser_local($user_agent=null,$return_array=false,$db='./browscap.ini',$cache=false)
|
||||
{//http://alexandre.alapetite.fr/doc-alex/php-local-browscap/
|
||||
//Get php_browscap.ini on http://browsers.garykeith.com/downloads.asp
|
||||
if (($user_agent==null)&&isset($_SERVER['HTTP_USER_AGENT'])) $user_agent=$_SERVER['HTTP_USER_AGENT'];
|
||||
global $browscapIni;
|
||||
global $browscapPath;
|
||||
if ((!isset($browscapIni))||(!$cache)||($browscapPath!==$db))
|
||||
{
|
||||
$browscapIni=defined('INI_SCANNER_RAW') ? parse_ini_file($db,true,INI_SCANNER_RAW) : parse_ini_file($db,true);
|
||||
$browscapPath=$db;
|
||||
uksort($browscapIni,'_sortBrowscap');
|
||||
$browscapIni=array_map('_lowerBrowscap',$browscapIni);
|
||||
}
|
||||
$cap=null;
|
||||
foreach ($browscapIni as $key=>$value)
|
||||
{
|
||||
if (($key!='*')&&(!array_key_exists('parent',$value))) continue;
|
||||
$keyEreg='^'.str_replace(
|
||||
array('\\','.','?','*','^','$','[',']','|','(',')','+','{','}','%'),
|
||||
array('\\\\','\\.','.','.*','\\^','\\$','\\[','\\]','\\|','\\(','\\)','\\+','\\{','\\}','\\%'),
|
||||
$key).'$';
|
||||
if (preg_match('%'.$keyEreg.'%i',$user_agent))
|
||||
{
|
||||
$cap=array('browser_name_regex'=>strtolower($keyEreg),'browser_name_pattern'=>$key)+$value;
|
||||
$maxDeep=8;
|
||||
while (array_key_exists('parent',$value)&&array_key_exists($parent=$value['parent'],$browscapIni)&&(--$maxDeep>0))
|
||||
$cap+=($value=$browscapIni[$parent]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$cache) $browscapIni=null;
|
||||
return $return_array ? $cap : (object)$cap;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -39,6 +39,8 @@ abstract class Map {
|
|||
|
||||
protected $requires_js = null;
|
||||
|
||||
protected $is_buggy_firefox = false;
|
||||
|
||||
public static function getName($id = null) {
|
||||
if (empty($id)) {
|
||||
return null;
|
||||
|
@ -96,11 +98,6 @@ abstract class Map {
|
|||
abstract function printJSInit();
|
||||
|
||||
public function writeJSGraph() {
|
||||
html_debug_print($this->nodes, true);
|
||||
html_debug_print($this->edges, true);
|
||||
html_debug_print(json_encode($this->nodes), true);
|
||||
html_debug_print("", true);
|
||||
html_debug_print(json_encode($this->edges), true);
|
||||
|
||||
$this->nodes = json_decode('[
|
||||
{
|
||||
|
@ -333,6 +330,27 @@ $this->edges = json_decode(
|
|||
<?php
|
||||
}
|
||||
|
||||
private function check_browser() {
|
||||
global $config;
|
||||
|
||||
$browser = get_browser_local(null, true, $config['homedir'] . '/include/browscap/php_browscap.ini');
|
||||
|
||||
switch ($browser['browser']) {
|
||||
case 'Firefox':
|
||||
// Firefox BUG
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1254159
|
||||
|
||||
$this->is_buggy_firefox = true;
|
||||
break;
|
||||
case 'Microsoft':
|
||||
// Do install a GNU/Linux.
|
||||
break;
|
||||
default:
|
||||
// The world is a wonderful place.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function show() {
|
||||
// Tooltip css
|
||||
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"include/styles/tooltipster.css\"/>" . "\n";
|
||||
|
@ -348,7 +366,9 @@ $this->edges = json_decode(
|
|||
echo "<script type='text/javascript' src='$js'></script>" . "\n";
|
||||
}
|
||||
|
||||
$this->writeJSContants();
|
||||
$this->check_browser();
|
||||
|
||||
$this->writeJSConstants();
|
||||
$this->writeJSGraph();
|
||||
|
||||
?>
|
||||
|
@ -507,8 +527,13 @@ $this->edges = json_decode(
|
|||
else {
|
||||
$height = $this->height . "px";
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" pointer-events="all" width="<?php echo $width;?>" height="<?php echo $height;?>">
|
||||
<?php
|
||||
$this->embedded_symbols_for_firefox();
|
||||
?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" pointer-events="all" width="<?php echo $width;?>" height="<?php echo $height;?>">
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
|
@ -516,7 +541,36 @@ $this->edges = json_decode(
|
|||
$this->printJSInit();
|
||||
}
|
||||
|
||||
public function writeJSContants() {
|
||||
private function embedded_symbols_for_firefox() {
|
||||
global $config;
|
||||
|
||||
if ($this->is_buggy_firefox) {
|
||||
echo "<defs>";
|
||||
// Firefox BUG
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1254159
|
||||
|
||||
$this->is_buggy_firefox = true;
|
||||
|
||||
$dir_string = $config['homedir'] . '/images/maps/';
|
||||
if ($dir = opendir($dir_string)) {
|
||||
|
||||
while (false !== ($file = readdir($dir))) {
|
||||
if (is_file($dir_string . $file)) {
|
||||
$xml = simplexml_load_file($dir_string . $file);
|
||||
$xml->registerXPathNamespace("x", "http://www.w3.org/2000/svg");
|
||||
|
||||
$symbols = $xml->xpath("//x:symbol");
|
||||
//~ $symbols = $symbols->xpath("//symbol");
|
||||
echo $symbols[0]->asXML();
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
echo "</defs>";
|
||||
}
|
||||
}
|
||||
|
||||
public function writeJSConstants() {
|
||||
$contants = array();
|
||||
$contants["ITEM_TYPE_AGENT_NETWORKMAP"] = ITEM_TYPE_AGENT_NETWORKMAP;
|
||||
$contants["ITEM_TYPE_MODULE_NETWORKMAP"] = ITEM_TYPE_MODULE_NETWORKMAP;
|
||||
|
@ -527,6 +581,7 @@ $this->edges = json_decode(
|
|||
foreach ($contants as $name => $value) {
|
||||
echo "var $name = $value \n";
|
||||
}
|
||||
echo "var is_buggy_firefox = " . ((int)$this->is_buggy_firefox) . ";\n";
|
||||
?>
|
||||
</script>
|
||||
<?php
|
||||
|
|
|
@ -168,7 +168,8 @@ MapController.prototype.init_map = function() {
|
|||
|
||||
d3.select("#map .zoom_box .zoom_out")
|
||||
.on("click", zoom_out);
|
||||
|
||||
|
||||
|
||||
self.paint_nodes();
|
||||
|
||||
this.init_events();
|
||||
|
@ -244,7 +245,9 @@ MapController.prototype.paint_nodes = function() {
|
|||
.append("circle")
|
||||
.attr("style", "fill: rgb(50, 50, 128);")
|
||||
.attr("r", "15");
|
||||
|
||||
|
||||
|
||||
|
||||
var arrow_layouts = self._viewport.selectAll(".arrow")
|
||||
.data(
|
||||
nodes
|
||||
|
@ -268,7 +271,8 @@ MapController.prototype.paint_nodes = function() {
|
|||
return self.node_from_edge(d['graph_id'])["to"];})
|
||||
.attr("data-from", function(d) {
|
||||
return self.node_from_edge(d['graph_id'])["from"];});
|
||||
|
||||
|
||||
|
||||
create_arrow(arrow_layouts);
|
||||
|
||||
/**
|
||||
|
@ -310,6 +314,7 @@ MapController.prototype.paint_nodes = function() {
|
|||
arrow_by_pieces(self._target + " svg", id_arrow, id_node_to, id_node_from);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,6 +42,10 @@ require_once('include/functions_migration.php');
|
|||
require_once('include/class/Networkmap.class.php');
|
||||
enterprise_include('include/class/NetworkmapEnterprise.class.php');
|
||||
|
||||
|
||||
|
||||
require_once('include/browscap/php-local-browscap.php');
|
||||
|
||||
$buttons['list'] = array('active' => false,
|
||||
'text' => '<a href="index.php?sec=network&sec2=operation/maps/networkmap_list">' .
|
||||
html_print_image("images/list.png", true,
|
||||
|
|
Loading…
Reference in New Issue