using_permalinks() && ( 'on' == get_option('unapi_usePermalink') ) ) {
$usesPermalink = true;
$idPrefix = "";
} else {
$usesPermalink = false;
$idPrefix = get_option('unapi_idPrefix');
}
$formatsList = array(
'oai_dc',
'rss',
'marcxml',
'srw_dc',
'mods'
);
// validate format
if ( $format )
if ( !in_array($format, $formatsList) )
unapi_error(406);
// validate id
if ( $id ) {
if ( $usesPermalink ) {
$table_name = $wpdb->prefix . 'posts';
$postId = $wpdb->get_var("SELECT ID FROM " . $table_name . " WHERE guid='" . mysql_escape_string($id) . "';");
if ( !is_numeric($postId) )
unapi_error(404); // bad identifier
} else {
if ( strpos($id, $idPrefix) === 0 )
$postId = substr($id, strlen($idPrefix)); // strip off prefix, leaving id of posting
else
unapi_error(404); // bad identifier (doesn't start with prefix)
}
// fetch post
$post = get_post($postId);
if ( !is_object($post) )
unapi_error(404); // no such post
else
if ( $post->post_status != 'publish' )
unapi_error(404); // post exists but hasn't been published, so treat as non-existent
}
// create XML for responses
$xmlHeader = '' . "\n";
$formats = '' . "\n";
$formats .= '' . "\n";
$formats .= '' . "\n";
$formats .= '' . "\n";
$formats .= '' . "\n";
// main brancher: select response depending on presence/absence of identifier and format
if ( $format )
( $id ) ? unapi_type3url() : unapi_error(400);
else
( $id ) ? unapi_type2url() : unapi_type1url();
/*
* type1url (no identifier, no format): return list of formats
*
*
*/
function unapi_type1url() {
global $xmlHeader, $formats;
header('Content-type: application/xml; charset=' . get_settings('blog_charset'), true);
echo $xmlHeader .
"\n" .
$formats .
'';
} // type1url()
/*
* type2url: identifier, no format - return list of formats for this identifier
*
*
*/
function unapi_type2url() {
global $xmlHeader, $formats, $id;
header('Content-type: application/xml; charset=' . get_settings('blog_charset'), true);
header('HTTP/1.0 300 Multiple Choices');
echo $xmlHeader .
'' . "\n" .
$formats .
'';
} // type2url()
/*
* type3url: identifier and format - return status 300 and multiple links
*
* Gathers necessary information such as author and blog name, and calls
* the appropriate function to build the metadata record in the requested
* format.
*/
function unapi_type3url() {
global $xmlHeader, $formats, $id, $format, $post;
$contentType = ( 'rss' == $format ) ? 'application/rss+xml' : 'application/xml';
header('Content-type: ' . $contentType . '; charset=' . get_settings('blog_charset'), true);
echo $xmlHeader;
eval('unapi_show_' . $format . '();');
} // type3url()
/*
* error - return error in status code
*
*
*/
function unapi_error($statusCode) {
global $statusString;
$statusString[400] = 'Bad Request';
$statusString[404] = 'Not Found';
$statusString[406] = 'Not Acceptable';
header('HTTP/1.0 ' . $statusCode . ' ' . $statusString[$statusCode]);
echo $statusCode . ' ' . $statusString[$statusCode];
die();
} // error()
/*
* output an oai_dc record from a post
*
*
*
*/
function unapi_show_oai_dc() {
global $postId, $blogName;
foreach(array_merge(get_posts('include=' . $postId), get_pages('include=' . $postId)) as $post) : setup_postdata($post);
?>
text
application/xml
name == "" ) continue;
?>
name; ?>
''
-
name == "" ) continue;
echo "\t\t" . $cat->name . "\n";
}
?>
']]>
born digital
access
application/xml
text
''
name == "" ) continue;
echo ' ' . $cat->name . "\n";
}
?>
nm 22 uu 4500
s ||||||||||||||||||||||
rfc3066
''
name == "" ) continue;
$j = ( 0 == $i ) ? "a" : "x";
echo '' . $cat->name . "\n";
$i++;
}
?>
text
application/xml
''
name == "" ) continue;
echo '' . $cat->name . "\n";
}
?>