-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmdi-profile-names.php
71 lines (58 loc) · 2.09 KB
/
cmdi-profile-names.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
<?php
#@--------------------------------------------------------------------------------------
#@ By Junte Zhang <[email protected]> in 2013
#@ Distributed under the GNU General Public Licence
#@
#@ This script extracts the CMDI profile names for display purposes
#@--------------------------------------------------------------------------------------
$data = file_get_contents("./schemas.tmp");
$schemas_arr = explode("\n", $data);
# delete last empty element
array_pop($schemas_arr);
# output file
$out = 'schemasNames.tmp';
# start a new file
file_put_contents($out, "");
foreach($schemas_arr as $val)
{
$file = preg_replace("/.*\/(.+)\/xsd$/", "$1", $val);
if(preg_match("/clarin/", $file))
{
$xml_url = 'http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/' . $file . '/xml';
$ch = curl_init();
$header = array("Content-type:text/xml; charset=utf-8");
curl_setopt($ch, CURLOPT_URL, $xml_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0"); # had Lysander dit maar gedaan
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_TIMEOUT, 0); # timeout in seconds
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 0);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
if ($response === false || $info['http_code'] != 200)
{
$response = "No cURL data returned for $xml_url [". $info['http_code']. "]\n";
echo $response;
die("No cUrl data returned. Exiting script...");
}
else
{
$dom = new DOMDocument();
$dom->loadXML($response);
$xpath = new DOMXPath($dom);
$profile_name = $xpath->query("//Header/Name");
if($profile_name->length != 1)
{
;
}
else
{
$line = $val . "\t" . $profile_name->item(0)->nodeValue . "\n";
file_put_contents($out, $line, FILE_APPEND);
}
}
}
}
?>