'."\n";*/
//add title for name of api query
$queryTitle = 'Article, Book and Journal Resources from Montana State University Libraries';
//search query or keyword - default query selects all items in database sorted by date added limited to 10 items/page
if (!isset($_GET['search'])) {
$search = 'default';
} else {
$search = $_GET['search'];
}
//sort by date or score (relevance)
if (!isset($_GET['sort'])) {
$sort = 'score';
} else {
$sort = $_GET['sort'];
}
//number of results to display
if (!isset($_GET['limit'])) {
$limit = '10';
} else {
$limit = $_GET['limit'];
}
//text format of output file - rss, atom, json
if (!isset($_GET['form'])) {
$form = 'rss';
} else {
$form = $_GET['form'];
}
/* possible future criteria for dynamic rss
//user name or id
if (!isset($_GET['user'])) {
$user = 'terraadmin';
} else {
$user = $_GET['user'];
}
//primary file format of media - flash, itunes, ipod, mp3, flv, m4v
//when switching to dynamic rss query format should be 'itunes' otherwise format is 'm4v'
if (!isset($_GET['media'])) {
$media = 'itunes ';
} else {
$media = $_GET['format'];
}
*/
//bring database parameters and functions onto page
include_once 'YOUR DATABASE PARAMETERS HERE';
//retrieve items from database - variables can be passed into query
if ($search == 'default') {
$query="SELECT resource_id,dc_title,dc_description,UNIX_TIMESTAMP(dc_date) AS date
FROM resources.resource
WHERE resource_status='a'
GROUP BY resource_id
ORDER BY date DESC
LIMIT 0,$limit";
} else {
$query="SELECT resource_id,dc_title,dc_description,UNIX_TIMESTAMP(dc_date) AS date,
MATCH (dc_title) AGAINST ('+$search*' IN BOOLEAN MODE) AS score
FROM resources.resource
WHERE MATCH (dc_title,dc_description)
AGAINST ('+$search*' IN BOOLEAN MODE) AND resource_status='a'
GROUP BY resource_id
ORDER BY $sort DESC
LIMIT 0,$limit";
}
$request = @mysql_query($query,$connectResources);
//get count of total results in database
$getTotal = @mysql_query('SELECT * FROM resources.resource',$connectResources);
$total = mysql_num_rows($getTotal);
//set switch control structure to shift form of resources based on value in url
switch($form)
{
case 'rss':
global $queryTitle;
global $total;
global $limit;
global $request;
{
header('Content-Type:application/rss+xml; charset=utf-8');
echo ''."\n";
echo ''."\n";
echo ''."\n";
echo ''.$queryTitle.''."\n";
echo 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).'/'."\n";
echo ''."\n";
echo 'List of recently added library resources (databases, datasets, indexes) from Montana State University. Showing '.$limit.' results out of '.$total.' total results.'."\n";
echo ''.substr(date("r"),0,-5).date("T").''."\n";
echo 'jaclark@montana.edu (Jason Clark)'."\n";
echo 'Copyright '.date("Y").'. Montana State University Libraries'."\n";
//store items in array, strip out html tags, generate valid date stamp
while($row=mysql_fetch_array($request)) {
$id=$row['resource_id'];
$title=stripslashes(strip_tags($row['dc_title']));
$description=stripslashes(htmlentities(strip_tags(substr($row['dc_description'],0,600))));
$dateIssued=strftime("%a, %d %b %Y %H:%M:%S MST",$row['date']);
echo ''."\n";
echo ''.$title.''."\n";
echo 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).'/about.php?id='.$id.''."\n";
echo ''.$description.' ...'."\n";
echo 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).'/about.php?id='.$id.''."\n";
echo ''.$dateIssued.''."\n";
echo ''."\n";
}
echo ''."\n";
echo ''."\n";
}
break;
case 'atom':
global $queryTitle;
global $total;
global $limit;
global $request;
{
header('Content-Type:application/xml; charset=utf-8');
echo ''."\n";
echo ''."\n";
echo ''.$queryTitle.''."\n";
echo 'List of recently added library resources (databases, datasets, indexes) from Montana State University. Showing '.$limit.' results out of '.$total.' total results.'."\n";
echo ''."\n";
echo ''."\n";
echo 'Montana State University Libraries'."\n";
echo 'jaclark@montana.edu'."\n";
echo ''."\n";
echo 'http://'.urlencode($_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']).''."\n";
echo ''.date("Y-m-d").'T'.date("H:i:s").'Z'."\n";
echo 'Copyright '.date("Y").'. Montana State University Libraries'."\n";
//store items in array, strip out html tags, generate valid date stamp
while($row=mysql_fetch_array($request)) {
$id=$row['resource_id'];
$title=stripslashes(strip_tags($row['dc_title']));
$description=stripslashes(htmlentities(strip_tags(substr($row['dc_description'],0,600))));
$dateIssued=strftime("%Y-%m-%dT%H:%M:%SZ",$row['date']);
echo ''."\n";
echo ''.$title.''."\n";
echo ''."\n";
echo ''.$description.' ...'."\n";
echo 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).'/about.php?id='.$id.''."\n";
echo ''.$dateIssued.''."\n";
echo ''."\n";
}
echo ''."\n";
}
break;
case 'opensearch':
global $queryTitle;
global $total;
global $limit;
global $search;
global $request;
/*
*/
{
header('Content-Type:application/xml; charset=utf-8');
echo ''."\n";
echo ''."\n";
echo ''.$queryTitle.''."\n";
echo 'List of recently added library resources (databases, datasets, indexes) from Montana State University. Showing '.$limit.' results out of '.$total.' total results.'."\n";
echo ''."\n";
echo ''."\n";
echo 'Montana State University Libraries'."\n";
echo 'jaclark@montana.edu'."\n";
echo ''."\n";
echo 'http://'.urlencode($_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']).''."\n";
echo ''.date("Y-m-d").'T'.date("H:i:s").'Z'."\n";
echo 'Copyright '.date("Y").'. Montana State University Libraries'."\n";
echo ''.$total.''."\n";
echo '1'."\n";
echo ''.$limit.''."\n";
echo ''."\n";
echo ''."\n";
echo ''."\n";
echo ''."\n";
echo ''."\n";
//store items in array, strip out html tags, generate valid date stamp
while($row=mysql_fetch_array($request)) {
$id=$row['resource_id'];
$title=stripslashes(strip_tags($row['dc_title']));
$description=stripslashes(htmlentities(strip_tags(substr($row['dc_description'],0,600))));
$dateIssued=strftime("%Y-%m-%dT%H:%M:%SZ",$row['date']);
echo ''."\n";
echo ''.$title.''."\n";
echo ''."\n";
echo ''.$description.' ...'."\n";
echo 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).'/about.php?id='.$id.''."\n";
echo ''.$dateIssued.''."\n";
echo ''."\n";
}
echo ''."\n";
}
break;
case 'json':
global $queryTitle;
global $total;
global $limit;
global $request;
{
header('Content-Type:text/javascript; charset=utf-8');
echo '{"ResultSet":{'."\n";
echo '"ResultSetTitle":"'.$queryTitle.'",'."\n";
echo '"totalResultsAvailable":"'.$total.'",'."\n";
echo '"totalResultsReturned": "'.$limit.'",'."\n";
echo '"Result":['."\n";
while($row = mysql_fetch_array($request)) {
$id = $row['resource_id'];
$title = stripslashes(strip_tags($row['dc_title']));
$description = stripslashes(htmlentities(strip_tags(substr($row['dc_description'],0,600))));
$link = 'http://'.urlencode($_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF'])).'/about.php%3Fid%3D'.$id.'';
$dateIssued = strftime("%a, %d %b %Y %H:%M:%S MST",$row['date']);
//combine variables into json string
$data.= '{"title":"'.$title.'","link":"'.$link.'","description":"'.$description.'","guid":"'.$id.'","updated":"'.$dateIssued.'"}, ';
}
$data = rtrim($data, ', ');
echo $data."\n";
echo ']'."\n";
echo '}'."\n";
echo '}'."\n";
}
break;
case 'sitemap':
global $limit;
global $request;
{
header('Content-Type:application/xml; charset=utf-8');
echo ''."\n";
echo ''."\n";
while($row=mysql_fetch_array($request)) {
$id = $row['resource_id'];
$link = 'http://'.urlencode($_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF'])).'/item.php%3Fid%3D'.$id.'';
$dateIssued = strftime("%Y-%m-%d",$row['date']);
echo ''."\n";
echo ''.$link.''."\n";
echo ''.$dateIssued.''."\n";
echo 'weekly'."\n";
echo '0.8'."\n";
echo ''."\n";
}
echo ''."\n";
}
}
?>