1 |
<?php |
<?php |
2 |
$title = "Grid network summary"; |
$title = "Grid network summary"; |
3 |
|
$token = rand(); |
4 |
|
include('includes/cricket_spider.php'); |
5 |
?> |
?> |
6 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
7 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
13 |
<script type="text/javascript" src="javascripts/mapper.js"></script> |
<script type="text/javascript" src="javascripts/mapper.js"></script> |
14 |
<script type="text/javascript" src="javascripts/mapper_hacks.js"></script> |
<script type="text/javascript" src="javascripts/mapper_hacks.js"></script> |
15 |
<?php |
<?php |
|
$today = time(); |
|
|
$start_of_today = mktime(0, 0, 0, date("n", $today), date("j", $today), date("Y", $today)); |
|
|
|
|
|
$image_urls = array(); |
|
|
$page_urls = array(); |
|
|
$cache_dir = "cache"; |
|
|
$urls_cache = $cache_dir . '/' . "urls"; |
|
|
|
|
|
/* returns the two key components from the url, separated by <-> delimiter */ |
|
|
function name_from_url($url){ |
|
|
$name_parts = split("%2F", code_from_url($url)); |
|
|
return $name_parts[0] . " ↔ " . $name_parts[1]; |
|
|
} |
|
|
|
|
|
function code_from_url($url){ |
|
|
$name_string = array(); |
|
|
preg_match('/target=%2F(.*);/', $url, $name_string); |
|
|
return $name_string[1]; |
|
|
} |
|
|
|
|
|
/* checks if a given file is less than 1 day old */ |
|
|
function probe_cache($file){ |
|
|
if(@filemtime($file) >= strtotime("-1 day", $start_of_today)){ |
|
|
return true; |
|
|
} |
|
|
return false; |
|
|
} |
|
|
|
|
|
function highlight_color($data){ |
|
|
return '00ff00'; |
|
|
} |
|
|
|
|
|
function border_color($data){ |
|
|
return '008000'; |
|
|
} |
|
|
|
|
|
/* found this neat little function at: http://mobiforge.com/developing/story/lightweight-device-detection-php */ |
|
|
function is_mobile(){ |
|
|
$regex_match="/(nokia|iphone|android|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|"; |
|
|
$regex_match.="htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|"; |
|
|
$regex_match.="blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|"; |
|
|
$regex_match.="symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|"; |
|
|
$regex_match.="jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220"; |
|
|
$regex_match.=")/i"; |
|
|
return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT'])); |
|
|
} |
|
|
|
|
|
/* get a list of Cricket urls from the image_map.html file */ |
|
|
if(probe_cache($urls_cache)){ |
|
|
/* load cache */ |
|
|
$page_urls = unserialize(file_get_contents($urls_cache)); |
|
|
} else { |
|
|
/* makes a list of urls present in the image map html */ |
|
|
preg_match_all('/"(http:\/\/.+)"/', file_get_contents('image_map.html'), $page_urls); |
|
|
/* create cache */ |
|
|
file_put_contents($urls_cache, serialize($page_urls)); |
|
|
} |
|
|
|
|
|
/* create a list of urls to images from the list of Cricket urls */ |
|
|
foreach($page_urls[1] as $index => $url){ |
|
|
/* graph name */ |
|
|
$graph_code = code_from_url($url); |
|
|
$graph_url_cache = $cache_dir . '/' . $graph_code; |
|
|
|
|
|
if(probe_cache($graph_url_cache)){ |
|
|
/* load cache */ |
|
|
$image_urls[] = unserialize(file_get_contents($graph_url_cache)); |
|
|
} else { |
|
|
$local_urls = array(); |
|
|
$page = ""; |
|
|
/* apparently cricket checks the UA string and tries to display GIFs to wget, which don't work for some reason */ |
|
|
/* image links */ |
|
|
$page = shell_exec("wget -O- --user-agent=Firefox " . escapeshellarg($url)); |
|
|
preg_match_all('/<img src="(.*);rand=\d+".+/', $page, $local_urls); |
|
|
/* $local_urls holds matched items, $local_urls[1] holds the matched part between ()s. |
|
|
$local_urls[1][0] is the daily graph, $local_urls[1][1] is the weekly graph */ |
|
|
/* new_url is an array of: |
|
|
url to page |
|
|
url to graph image |
|
|
name of the graph |
|
|
*/ |
|
|
$new_url = array($url, "http://www.dutchgrid.nl/ndpf/cricket/" . $local_urls[1][0] . ";rand=" , "http://www.dutchgrid.nl/ndpf/cricket/" . $local_urls[1][1] . ";rand=", name_from_url($url)); |
|
|
/* create cache */ |
|
|
file_put_contents($graph_url_cache, serialize($new_url)); |
|
|
/* add to list */ |
|
|
$image_urls[] = $new_url; |
|
|
} |
|
|
} |
|
16 |
?> |
?> |
17 |
|
|
18 |
<script type="text/javascript"> |
<script type="text/javascript"> |
25 |
|
|
26 |
names_by_url : url -> name |
names_by_url : url -> name |
27 |
*/ |
*/ |
28 |
var daily_images_by_url = Array(); |
var snippets_by_url = Array(); |
29 |
var daily_images_pre_cache = Array(); |
var images_pre_cache = Array(); |
30 |
var weekly_images_by_url = Array(); |
var images = Array(); |
|
var weekly_images_pre_cache = Array(); |
|
|
var names_by_url = Array(); |
|
31 |
|
|
32 |
<?php |
<?php |
33 |
foreach($image_urls as $url){ |
$page_urls = get_urls_from_html_file('image_map.html'); |
34 |
?> |
$image_urls = get_images_from_absolute_and_relative_urls($page_urls[1]); |
35 |
daily_images_by_url["<?=$url[0]?>"] = "<?=$url[1] . rand()?>"; |
//print_r($image_urls); |
36 |
weekly_images_by_url["<?=$url[0]?>"] = "<?=$url[2] . rand()?>"; |
foreach($image_urls as $url => $data){ |
37 |
names_by_url["<?=$url[0]?>"] = "<?=$url[3]?>"; |
if(is_array($data[0])){ |
38 |
|
?> |
39 |
|
snippets_by_url["<?=get_absolute_url()?><?=$url?>"] = '<?=make_html_snippets($data, $token)?>'; |
40 |
|
<?php |
41 |
|
foreach($data as $index => $local_data){ |
42 |
|
?> |
43 |
|
images.push('<?=$local_data[1] . $token ?>'); |
44 |
|
images.push('<?=$local_data[2] . $token ?>'); |
45 |
|
<?php |
46 |
|
} |
47 |
|
} else { |
48 |
|
?> |
49 |
|
snippets_by_url["<?=$url?>"] = '<?=make_html_snippet($data, $token)?>'; |
50 |
|
images.push('<?=$data[1] . $token ?>'); |
51 |
|
images.push('<?=$data[2] . $token ?>'); |
52 |
<?php |
<?php |
53 |
|
|
54 |
|
} |
55 |
} |
} |
56 |
?> |
?> |
57 |
|
|
58 |
/* pre-loads all the graphs into an array that we can use to splice them back into the DOM */ |
/* pre-loads all the graphs into an array that we can use to splice them back into the DOM */ |
59 |
function pre_cache_images(){ |
function pre_cache_images(){ |
60 |
for(url in daily_images_by_url){ |
for(id in images){ |
61 |
daily_images_pre_cache[url] = new Image(); |
images_pre_cache[id] = new Image(); |
62 |
daily_images_pre_cache[url].src = daily_images_by_url[url]; |
images_pre_cache[id].src = images[id]; |
|
} |
|
|
|
|
|
for(url in weekly_images_by_url){ |
|
|
weekly_images_pre_cache[url] = new Image(); |
|
|
weekly_images_pre_cache[url].src = weekly_images_by_url[url]; |
|
63 |
} |
} |
64 |
} |
} |
65 |
|
|
66 |
/* callback for onmouseover event of areas */ |
/* callback for onmouseover event of areas */ |
67 |
function show_graph(url){ |
function show_graph(url){ |
68 |
daily_graph = document.getElementById('daily_graph'); |
//alert(url); |
69 |
daily_graph.src = daily_images_pre_cache[url].src; |
snippet = document.getElementById('graph_snippet'); |
70 |
|
snippet.innerHTML = snippets_by_url[url]; |
|
weekly_graph = document.getElementById('weekly_graph'); |
|
|
weekly_graph.src = weekly_images_pre_cache[url].src; |
|
|
|
|
|
daily_graph_link = document.getElementById('daily_graph_link'); |
|
|
daily_graph_link.href = url; |
|
|
|
|
|
weekly_graph_link = document.getElementById('weekly_graph_link'); |
|
|
weekly_graph_link.href = url; |
|
|
|
|
|
graph_name = document.getElementById('graph_name'); |
|
|
graph_name.innerHTML = names_by_url[url]; |
|
71 |
} |
} |
72 |
|
|
73 |
</script> |
</script> |
97 |
Please enable javascript to see graphs when hovering over trunks. |
Please enable javascript to see graphs when hovering over trunks. |
98 |
</p> |
</p> |
99 |
</noscript> |
</noscript> |
100 |
<h2 id="graph_name"></h2> |
<div id="graph_snippet"> |
101 |
<p> |
</div> |
|
<a id="daily_graph_link" href=""><img id="daily_graph" alt="" src=""/></a><br/> |
|
|
<a id="weekly_graph_link" href=""><img id="weekly_graph" alt="" src=""/></a> |
|
|
</p> |
|
102 |
</div> |
</div> |
103 |
<div class="clear"> </div> |
<div class="clear"> </div> |
104 |
<div class="links_div"> |
<div class="links_div"> |
105 |
<h4>Trunks listed: </h4> |
<h4>Trunks listed: </h4> |
106 |
<ul> |
<ul> |
107 |
<?php |
<?php |
108 |
foreach($image_urls as $url){ |
foreach($image_urls as $url => $data){ |
109 |
|
if(is_array($data[0])){ |
110 |
|
foreach($data as $index => $local_data){ |
111 |
|
?> |
112 |
|
<li><a href="<?=$local_data[0]?>"><?=$local_data[3]?></a></li> |
113 |
|
<?php |
114 |
|
} |
115 |
|
} else { |
116 |
?> |
?> |
117 |
<li><a href="<?=$url[0]?>"><?=$url[3]?></a></li> |
<li><a href="<?=$data[0]?>"><?=$data[3]?></a></li> |
118 |
<?php |
<?php |
119 |
|
} |
120 |
} |
} |
121 |
?> |
?> |
122 |
</ul> |
</ul> |