-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.php
157 lines (144 loc) · 4.61 KB
/
report.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
$filename = 'index.html';
@ini_set('error_reporting', E_ALL);
include_once('Ckan_client-PHP/Ckan_client.php');
$ckan = new Ckan_client();
echo "Fetching dataset list ... ";
$group_description = $ckan->get_group_entity('lodcloud');
echo "OK (" . count($group_description->packages) . " datasets)\n";
$datasets = array();
foreach ($group_description->packages as $package_id) {
echo "Fetching dataset $package_id ... ";
$package = $ckan->get_package_entity($package_id);
echo $package->name . "\n";
$datasets[$package->name] = $package;
}
$datasets_with_links = array();
$datasets_without_links = array();
$broken_links = array();
foreach ($datasets as $package => $details) {
$datasets[$package]->inlinks = array();
}
foreach ($datasets as $package => $details) {
$datasets[$package]->outlinks = array();
$extras = get_object_vars($details->extras);
foreach ($extras as $key => $value) {
if (!preg_match('/^links:(.*)/', $key, $match)) continue;
$target = $match[1];
$datasets[$package]->outlinks[$target] = (int) $value;
if (!in_array($package, $datasets_with_links)) {
$datasets_with_links[] = $package;
}
if (array_key_exists($target, $datasets)) {
$datasets[$target]->inlinks[$package] = (int) $value;
if (!in_array($target, $datasets_with_links)) {
$datasets_with_links[] = $target;
}
} else {
if (!array_key_exists($target, $broken_links)) {
$broken_links[$target] = array();
}
if (!in_array($package, $broken_links[$target])) {
$broken_links[$target][] = $package;
}
}
}
ksort($datasets[$package]->outlinks);
}
foreach (array_keys($datasets) as $package) {
if (!in_array($package, $datasets_with_links)) {
$datasets_without_links[] = $package;
}
ksort($datasets[$package]->inlinks);
}
foreach (array_keys($broken_links) as $package) {
sort($broken_links[$package]);
}
sort($datasets_with_links);
sort($datasets_without_links);
ksort($broken_links);
ob_start();
echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xml:lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:dc="http://purl.org/dc/terms/">
<head>
<title>LOD Cloud data in CKAN</title>
<style type="text/css">
body { margin: 1 2 3; }
dt { font-weight: bold; }
dd { margin-bottom: 0.7em; }
dt h3 { margin-bottom: 0; }
.missing { color: red; }
a.package { text-decoration: none; }
</style>
</head>
<body>
<h1>LOD Cloud data in CKAN</h1>
<p><a href="http://ckan.net/group/lodcloud"><tt>lodcloud</tt> group in CKAN</a></p>
<h2>Datasets with links</h2>
<?php if ($datasets_with_links) { ?>
<dl>
<?php foreach ($datasets_with_links as $package) { ?>
<dt><h3><?php echo package_link($package); ?>: <?php echo $datasets[$package]->title; ?></h3></dt>
<dd>
<strong>Outlinks</strong>: <?php
$fragments = array();
foreach ($datasets[$package]->outlinks as $target => $link_count) {
$fragments[] = package_link($target, array_key_exists($target, $datasets));
}
echo $fragments ? join(', ', $fragments) : 'none';
?><br />
<strong>Inlinks</strong>: <?php
$fragments = array();
foreach ($datasets[$package]->inlinks as $target => $link_count) {
$fragments[] = package_link($target, array_key_exists($target, $datasets));
}
echo $fragments ? join(', ', $fragments) : 'none';
?><br />
</dd>
<?php } ?>
</dl>
<?php } else { ?>
<p>None.</p>
<?php } ?>
<h2>Datasets without links</h2>
<?php if ($datasets_without_links) { ?>
<dl>
<?php foreach ($datasets_without_links as $package) { ?>
<dt><h3><?php echo package_link($package); ?>: <?php echo $datasets[$package]->title; ?></h3></dt>
<?php } ?>
</dl>
<?php } else { ?>
<p>None.</p>
<?php } ?>
<h2>Datasets linked from above that are not in the <tt>lodcloud</tt> group</h2>
<?php if ($broken_links) { ?>
<ul>
<?php foreach ($broken_links as $broken_link => $referrer) { ?>
<li><strong><?php echo package_link($broken_link, false); ?></strong> (referred from <?php
$fragments = array();
foreach ($referrer as $package) {
$fragments[] = package_link($package);
}
echo join(", ", $fragments);
?>)
</li>
<?php } ?>
</ul>
<?php } else { ?>
<p>None.</p>
<?php } ?>
</body>
</html><?php
$html = ob_get_contents();
ob_end_clean();
echo "Writing to file $filename ... ";
$file = fopen($filename, 'w');
fputs($file, $html);
fclose($file);
echo "OK\n";
function package_link($package, $exists = true) {
return "<a href=\"http://ckan.net/package/$package\" class=\"package" . ($exists ? '' : ' missing') . "\">$package</a>";
}