mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-15 19:19:28 +00:00
112 lines
3.9 KiB
PHP
112 lines
3.9 KiB
PHP
<div class="bootstrap-widget-header">
|
|
<i class="icon-home icon-white"></i><h3>Converter</h3>
|
|
</div>
|
|
<div class="bootstrap-widget-content">
|
|
<div class="container">
|
|
<div class="pull-left">
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<?php
|
|
/**
|
|
* Convert RDF from one format to another
|
|
*
|
|
* The source RDF data can either be fetched from the web
|
|
* or typed into the Input box.
|
|
*
|
|
* The first thing that this script does is make a list the names of the
|
|
* supported input and output formats. These options are then
|
|
* displayed on the HTML form.
|
|
*
|
|
* The input data is loaded or parsed into an EasyRdf_Graph.
|
|
* That graph is than outputted again in the desired output format.
|
|
*
|
|
* @package EasyRdf
|
|
* @copyright Copyright (c) 2009-2013 Nicholas J Humfrey
|
|
* @license http://unlicense.org/
|
|
*/
|
|
|
|
// set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
|
|
|
|
echo $this->load->view('rdf/html_tag_helpers');
|
|
|
|
$input_format_options = array('Guess' => 'guess');
|
|
$output_format_options = array();
|
|
foreach (EasyRdf_Format::getFormats() as $format) {
|
|
if ($format->getSerialiserClass()) {
|
|
$output_format_options[$format->getLabel()] = $format->getName();
|
|
}
|
|
if ($format->getParserClass()) {
|
|
$input_format_options[$format->getLabel()] = $format->getName();
|
|
}
|
|
}
|
|
|
|
// Stupid PHP :(
|
|
if (get_magic_quotes_gpc() and isset($_REQUEST['data'])) {
|
|
$_REQUEST['data'] = stripslashes($_REQUEST['data']);
|
|
}
|
|
|
|
// Default to Guess input and Turtle output
|
|
if (!isset($_REQUEST['output_format'])) {
|
|
$_REQUEST['output_format'] = 'turtle';
|
|
}
|
|
if (!isset($_REQUEST['input_format'])) {
|
|
$_REQUEST['input_format'] = 'guess';
|
|
}
|
|
|
|
// Display the form, if raw option isn't set
|
|
if (!isset($_REQUEST['raw'])) {
|
|
print "<html>\n";
|
|
print "<head><title>EasyRdf Converter</title></head>\n";
|
|
print "<body>\n";
|
|
print "<h1>EasyRdf Converter</h1>\n";
|
|
|
|
print "<div style='margin: 10px'>\n";
|
|
print form_tag();
|
|
print label_tag('data', 'Input Data: ').'<br />'.text_area_tag('data', '', array('cols'=>30, 'rows'=>10)) . "<br />\n";
|
|
print label_tag('uri', 'or Uri: ').text_field_tag('uri', 'http://www.dajobe.org/foaf.rdf', array('size'=>80)) . "<br />\n";
|
|
print label_tag('input_format', 'Input Format: ').select_tag('input_format', $input_format_options) . "<br />\n";
|
|
print label_tag('output_format', 'Output Format: ').select_tag('output_format', $output_format_options) . "<br />\n";
|
|
print label_tag('raw', 'Raw Output: ').check_box_tag('raw') . "<br />\n";
|
|
print reset_tag() . submit_tag();
|
|
print form_end_tag();
|
|
print "</div>\n";
|
|
}
|
|
|
|
if (isset($_REQUEST['uri']) or isset($_REQUEST['data'])) {
|
|
// Parse the input
|
|
$graph = new EasyRdf_Graph($_REQUEST['uri']);
|
|
if (empty($_REQUEST['data'])) {
|
|
$graph->load($_REQUEST['uri'], $_REQUEST['input_format']);
|
|
} else {
|
|
$graph->parse($_REQUEST['data'], $_REQUEST['input_format'], $_REQUEST['uri']);
|
|
}
|
|
|
|
// Lookup the output format
|
|
$format = EasyRdf_Format::getFormat($_REQUEST['output_format']);
|
|
|
|
// Serialise to the new output format
|
|
$output = $graph->serialise($format);
|
|
if (!is_scalar($output)) {
|
|
$output = var_export($output, true);
|
|
}
|
|
|
|
// Send the output back to the client
|
|
if (isset($_REQUEST['raw'])) {
|
|
header('Content-Type: '.$format->getDefaultMimeType());
|
|
print $output;
|
|
} else {
|
|
print '<pre>'.htmlspecialchars($output).'</pre>';
|
|
}
|
|
}
|
|
|
|
if (!isset($_REQUEST['raw'])) {
|
|
print "</body>\n";
|
|
print "</html>\n";
|
|
}
|
|
|
|
?>
|
|
</div>
|