forked from easyrdf/easyrdf
-
Notifications
You must be signed in to change notification settings - Fork 5
/
dump.php
53 lines (48 loc) · 1.58 KB
/
dump.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
<?php
/**
* Display the contents of a graph
*
* Data from the chosen URI is loaded into an EasyRdf\Graph object.
* Then the graph is dumped and printed to the page using the
* $graph->dump() method.
*
* The call to preg_replace() replaces links in the page with
* links back to this dump script.
*
* @copyright Copyright (c) 2009-2014 Nicholas J Humfrey
* @license http://unlicense.org/
*/
require_once realpath(__DIR__.'/..').'/vendor/autoload.php';
require_once __DIR__.'/html_tag_helpers.php';
?>
<html>
<head><title>EasyRdf Graph Dumper</title></head>
<body>
<h1>EasyRdf Graph Dumper</h1>
<div style="margin: 10px">
<?php echo form_tag(); ?>
URI: <?php echo text_field_tag('uri', 'http://mmt.me.uk/foaf.rdf', ['size' => 80]); ?><br />
Format: <?php echo label_tag('format_html', 'HTML').' '.radio_button_tag('format', 'html', true); ?>
<?php echo label_tag('format_text', 'Text').' '.radio_button_tag('format', 'text'); ?><br />
<?php echo submit_tag(); ?>
<?php echo form_end_tag(); ?>
</div>
<?php
if (isset($_REQUEST['uri'])) {
$graph = EasyRdf\Graph::newAndLoad($_REQUEST['uri']);
if (isset($_REQUEST['format']) && 'text' == $_REQUEST['format']) {
echo '<pre>'.$graph->dump('text').'</pre>';
} else {
$dump = $graph->dump('html');
echo preg_replace_callback("/ href='([^#][^']*)'/", 'makeLinkLocal', $dump);
}
}
// Callback function to re-write links in the dump to point back to this script
function makeLinkLocal($matches)
{
$href = $matches[1];
return " href='?uri=".urlencode($href)."#$href'";
}
?>
</body>
</html>