Skip to content

Commit

Permalink
Updated the new version for OAI
Browse files Browse the repository at this point in the history
  • Loading branch information
pgogy committed Nov 23, 2012
1 parent 9c54773 commit 4e02c82
Show file tree
Hide file tree
Showing 9 changed files with 535 additions and 16 deletions.
1 change: 1 addition & 0 deletions index.php
Expand Up @@ -217,6 +217,7 @@ function getfeed(){
?>
<div class="form_holder">
<p style="padding-top:10px">Ramanathan is an RSS parser which reads RSS feeds and then sets up submission of items from these feeds into a learning registry node</p>
<p>To submit an entire feed please see the <a href="submit_all.php">submit all page</a> or <a href="submit_all_oai.php">submit all page (OAI:DC)</a></p>
<p>Enter an RSS Feed you wish to examine - (If the feed contains "dc:rights" or "dc:subject" fields then these will be sent to the registry node)</p>
<form action = "" method ="POST" onsubmit="javascript:getfeed()">
<label>Enter RSS Feed Url</label><input id="url" type="text" size="150" />
Expand Down
14 changes: 0 additions & 14 deletions intro_ga.txt
Expand Up @@ -2,17 +2,3 @@
<head>

<link href="style.css" rel="stylesheet" type="text/css" media="all" />

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-24466610-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>
2 changes: 1 addition & 1 deletion paradata_submit_url.php
Expand Up @@ -122,7 +122,7 @@
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "http://alpha.mimas.ac.uk/publish");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50);
curl_setopt($ch, CURLOPT_USERPWD, "");
curl_setopt($ch, CURLOPT_USERPWD, "fred:flintstone");
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
Expand Down
4 changes: 4 additions & 0 deletions style.css
Expand Up @@ -284,4 +284,8 @@ div#links a{

div#links a:hover{
text-decoration:underline;
}

a img{
border:none;
}
24 changes: 24 additions & 0 deletions submit_all.php
@@ -0,0 +1,24 @@
<?PHP

echo file_get_contents("intro_ga.txt");

?>
</head>
<?PHP

echo file_get_contents("post_title.txt");

?>
<div class="form_holder">
<p style="padding-top:10px">Ramanathan is an RSS parser which reads RSS feeds and then sets up submission of items from these feeds into a learning registry node</p>
<p>This page submits an entire feed - for inidividual items please see <a href="index.php">individual rss item submission</a></p>
<p>Enter an RSS Feed you wish to submit (If the feed contains "dc:rights" or "dc:subject" fields then these will be sent to the registry node)</p>
<form action ="submit_all_feed.php" target="_blank" method ="POST" onsubmit="javascript:getfeed()">
<label>Enter RSS Feed Url</label><input id="url" name="url" type="text" size="150" />
<input type="submit" value="submit" />
</form>
</div>
<div id="links">
</div>
</body>
</html>
235 changes: 235 additions & 0 deletions submit_all_feed.php
@@ -0,0 +1,235 @@
<?PHP

echo file_get_contents("intro_ga.txt");

?>
</head>
<?PHP

echo file_get_contents("post_title.txt");

?>
<div>
<?PHP

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $_POST['url']);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);

$response = curl_exec($ch);

$data = @simplexml_load_string($response);

if($data){

if(isset($data->channel->item)){

$return = new StdClass();

foreach ($data->channel->item as $item) {

$sxe = new SimpleXMLElement("<item xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dct=\"http://purl.org/dc/terms/\"></item>");

$ns_dc = $item->children('http://purl.org/dc/elements/1.1/');

$rights = "";
$subject = "";

foreach($ns_dc as $key => $value){

@$sxe->addChild("dc:" . $key, "<![CDATA[" . $value . "]]>", "xmlns:dc=\"http://purl.org/dc/elements/1.1/\"");

if($key=="rights"){

$rights = (string)$value[0];

}

if($key=="subject"){

$subject .= $value . ",";

}

}

foreach($item as $key => $value){

@$sxe->addChild($key, "<![CDATA[" . $value . "]]>");

}

$data_object = new StdClass();

$data_object->title = (string)$item->title[0];
$data_object->rights = $rights;
$data_object->subject = substr($subject,0,(strlen($subject)-1));
$data_object->package = $sxe->asXML();

$return->{$item->link} = $data_object;

}

}else{

echo "not a valid XML Feed";

}

}else{

echo "not a valid XML Feed";

}

$content_info = array();

$content_info['resource_data_type'] = 'metadata';
$content_info['submitter'] = "ramanathan";
$content_info['curator'] = "ramanathan";
$content_info['active' ] = TRUE;
$content_info['payload_schema'] = 'DC 1.1';

$opt_id_fields = array(
'curator',
'owner',
'signer',
);

$opt_res_fields = array(
'submitter_timestamp',
'submitter_TTL',
'keys',
'resource_TTL',
'payload_schema_locator',
'payload_schema_format',
);

$opt_sig_fields = array(
'signature',
'key_server',
'key_locations',
'key_owner',
'signing_method',
);

$opt_tos_fields = array(
'tos_submission_attribution',
);

// Make some parts of the PHP data structure

$identity = new StdClass;
$resource_data = new StdClass;

$identity->submitter_type = 'ramanathan';
$identity->submitter = $content_info['submitter'];

$resource_data->doc_type = 'resource_data';
$resource_data->doc_version = '0.23.0';
$resource_data->resource_data_type = $content_info['resource_data_type'];
$resource_data->active = $content_info['active'];
$resource_data->identity = $identity;

$resource_data->payload_placement = 'inline';
$resource_data->payload_schema = array($content_info['payload_schema']);

foreach($return as $data => $value){

echo "<p>URL (" . $data . ") submitted ";

$content_info['resource_locator'] = $data;
$resource_data->resource_locator = $data;

if($value->rights==""){
$tos = "None provided";
}else{
$tos = $value->rights;
}

$content_info['tos'] = $tos;

$tos = new StdClass;

$tos->submission_TOS = $content_info['tos'];

// Optional identity values.
foreach ($opt_id_fields as $field) {
if (array_key_exists($field, $content_info)) {
$identity->$field = $content_info[$field];
}
}

// Optional resource_data values.
foreach ($opt_res_fields as $field) {
if (array_key_exists($field, $content_info)) {
$resource_data->$field = $content_info[$field];
}
}

// Optional TOS values.
foreach ($opt_tos_fields as $field) {
if (array_key_exists($field, $content_info)) {
$tos->$field = $content_info[$field];
}
}

// Now the data structure is sort of finished, so add in some extra bits

$resource_data->TOS = $tos;

$resource_data->resource_data = htmlspecialchars_decode($data_object->package);

if($data_object->subject==""){
$keys = "None provided";
}else{
$keys = $data_object->subject;
}

$resource_data->keys = explode(",",$keys);

$submission = new StdClass;

$submission->documents[] = $resource_data;

$data_to_send = json_encode($submission);

// Curl is some PHP stuff to send data across the interwebs

$ch = curl_init();

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "http://alpha.mimas.ac.uk/publish");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50);
curl_setopt($ch, CURLOPT_USERPWD, "fred:flintstone");
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_to_send);

//CURL exec sends the data

$result = curl_exec($ch);

//Traps the error if something bad happens

$error = curl_error($ch);
curl_close($ch);

// Convert the data from LR json back into PHP so we can check it

$doc_data = json_decode($result);

echo "<a target='_blank' href='http://alpha.mimas.ac.uk/obtain?by_doc_ID=true&request_ID=" . $doc_data->document_results[0]->doc_ID . "'> Document ID : " . $doc_data->document_results[0]->doc_ID . "</a></p>";

}

?>
</div>
</body>
</html>

0 comments on commit 4e02c82

Please sign in to comment.