/[pdpsoft]/trunk/nl.nikhef.ndpf.tools/network-stats-mashup/index.php
ViewVC logotype

Contents of /trunk/nl.nikhef.ndpf.tools/network-stats-mashup/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1270 - (show annotations) (download) (as text)
Thu Dec 10 15:03:02 2009 UTC (12 years, 8 months ago) by aramv
File MIME type: text/x-php
File size: 4672 byte(s)
Moved php code into include, added logic to handle meta-trunks described in local html files
1 <?php
2 $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">
7 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
8 <head>
9 <title><?=$title?></title>
10 <link rel="stylesheet" href="stylesheets/style.css" type="text/css" media="screen" charset="utf-8"/>
11 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
12 <script type="text/javascript" src="javascripts/wz_jsgraphics.js"></script>
13 <script type="text/javascript" src="javascripts/mapper.js"></script>
14 <script type="text/javascript" src="javascripts/mapper_hacks.js"></script>
15 <?php
16 ?>
17
18 <script type="text/javascript">
19 /* associative arrays.
20 daily_images_by_url : url -> image_link
21 daily_images_pre_cache : url -> image object
22
23 weekly_images_by_url : url -> image_link
24 weekly_images_pre_cache : url -> image object
25
26 names_by_url : url -> name
27 */
28 var snippets_by_url = Array();
29 var images_pre_cache = Array();
30 var images = Array();
31
32 <?php
33 $page_urls = get_urls_from_html_file('image_map.html');
34 $image_urls = get_images_from_absolute_and_relative_urls($page_urls[1]);
35 //print_r($image_urls);
36 foreach($image_urls as $url => $data){
37 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
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 */
59 function pre_cache_images(){
60 for(id in images){
61 images_pre_cache[id] = new Image();
62 images_pre_cache[id].src = images[id];
63 }
64 }
65
66 /* callback for onmouseover event of areas */
67 function show_graph(url){
68 //alert(url);
69 snippet = document.getElementById('graph_snippet');
70 snippet.innerHTML = snippets_by_url[url];
71 }
72
73 </script>
74 </head>
75 <body>
76 <div id="wrapper">
77 <div class="header">
78 <h1><?=$title?></h1>
79 </div>
80 <div class="image_div">
81 <p>
82 <?php
83 /* read in GIMP output and set class attributes to enable fancy javascript features */
84 $image_map = preg_replace('/<img (.+) border="0" (.+)\/>/', '<img \1 \2 id="network_graph" class="mapper noborder" alt="" />', file_get_contents('image_map.html'));
85 /* xhtml fix - map needs an id attribute but GIMP can't edit imagemaps that have it */
86 $image_map = preg_replace('/<map(.*)>/','<map\1 id="map">', $image_map);
87 /* add some more info to the areas, based on their status */
88 /* I tried referencing the mathces[2] twice to get a prober alt tag using the name_from_url() function. However, this doesn't seem to work :( */
89 $image_map = preg_replace_callback('/<area (.+) href="(.+)" \/>/', create_function('$matches', 'return "<area ". $matches[1] . " href=\"" . $matches[2] . "\" alt=\"\" onmouseover=\"show_graph(this.href);\" class=\"icolor" . highlight_color($matches[1]) . " iborder" . border_color($matches[1]) . "\" />";'), $image_map);
90 echo $image_map;
91 ?>
92 </p>
93 </div>
94 <div class="graph_div">
95 <noscript>
96 <p>
97 Please enable javascript to see graphs when hovering over trunks.
98 </p>
99 </noscript>
100 <div id="graph_snippet">
101 </div>
102 </div>
103 <div class="clear">&nbsp;</div>
104 <div class="links_div">
105 <h4>Trunks listed: </h4>
106 <ul>
107 <?php
108 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="<?=$data[0]?>"><?=$data[3]?></a></li>
118 <?php
119 }
120 }
121 ?>
122 </ul>
123 </div>
124 </div>
125 <script type="text/javascript">
126 pre_cache_images();
127 <?php
128 /* make double clicks work as clicks for mobile browsers and disable regular clicks*/
129 if(is_mobile()){
130 ?>
131 var loader_chain = window.onload;
132 window.onload = function(){
133 var areas = document.getElementsByTagName('area');
134 for(idx in areas){
135 areas[idx].onclick = new Function('return false;');
136 areas[idx].ondblclick = new Function('window.location = "' + areas[idx].href+'";');
137 }
138 loader_chain();
139 }
140 <?php
141 }
142 ?>
143 </script>
144 </body>
145 </html>

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28