2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay & Joel Kronenberg */
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
13 // $Id: merlot_rest.php 6614 2006-09-27 19:32:29Z greg $
15 require("classes/MerlotResultParser.class.php");
17 $keywords = trim($_REQUEST['keywords']);
18 $title = trim($_REQUEST['title']);
19 $description = trim($_REQUEST['description']);
20 $author = trim($_REQUEST['author']);
21 $results_per_page = intval(trim($_REQUEST['results_per_page']));
23 if($keywords <> "" || $title <> "" || $description <> "" || $author <> "" || $_REQUEST["creativeCommons"] == "true")
25 $page = intval($_REQUEST['p']);
30 if ($results_per_page > $default_results_per_page || $results_per_page == 0)
31 $results_per_page = $default_results_per_page;
33 $page_str = "results_per_page=".$results_per_page;
34 $url_search = "&size=".$results_per_page."&firstRecNumber=".$results_per_page*($page - 1);
38 $page_str .= SEP."keywords=".urlencode($keywords);
39 $url_search .= "&keywords=".urlencode($keywords);
43 $page_str .= SEP."title=".urlencode($title);
44 $url_search .= "&title=".urlencode($title);
46 if ($description <> "")
48 $page_str .= SEP. "description=".urlencode($description);
49 $url_search .= "&description=".urlencode($description);
53 $page_str .= SEP. "author=".urlencode($author);
54 $url_search .= "&author=".urlencode($author);
57 if (isset($_REQUEST["search_type"]))
58 $page_str .= SEP."search_type=".$_REQUEST["search_type"];
60 if ($_REQUEST["search_type"] == 0) $url_search .= "&allKeyWords=true";
61 if ($_REQUEST["search_type"] == 1) $url_search .= "&anyKeyWords=true";
62 if ($_REQUEST["search_type"] == 2) $url_search .= "&exactPhraseKeyWords=true";
63 if ($_REQUEST["creativeCommons"] == "true")
65 $page_str .= SEP. "creativeCommons=true";
66 $url_search .= "&creativeCommons=true";
69 $url = $_config['merlot_location']."?licenseKey=".$_config['merlot_key'].$url_search;
71 $xml_results = file_get_contents($url);
75 $infos = array('CANNOT_CONNECT_SERVER', $_config['merlot_location']);
76 $msg->addInfo($infos);
80 $MerlotResultParser =& new MerlotResultParser();
81 $MerlotResultParser->parse($xml_results);
82 $result_list = $MerlotResultParser->getParsedArray();
84 if ($result_list['status'] == 'failed') // failed, display error
85 echo "<span style='color:red'>"._AT('error').": ".$result_list['error']."</span>";
86 else // success, display results
88 if (is_array($result_list))
90 $num_results = $result_list["summary"]["totalCount"];
91 $num_pages = max(ceil($num_results / $results_per_page), 1);
93 echo ' <div id="search_results">';
94 echo " <h2>". _AT('results')." <small>(".$result_list["summary"]["resultCount"]." out of ".$num_results.")</small></h2>";
96 print_paginator($page, $num_results, htmlspecialchars($page_str), $results_per_page);
98 foreach ($result_list as $key=>$result)
104 <dl class="browse-result">
107 <dd><h3><a href="<?php echo $result['detailURL']; ?>"><?php echo htmlspecialchars($result['title']); ?></a></h3></dd>
109 <dt><?php echo _AT("author"); ?></dt>
110 <dd><?php if ($result['authorName']=='') echo _AT('unknown'); else echo htmlspecialchars($result['authorName']); ?></dd>
112 <dt><?php echo _AT("merlot_creation_date"); ?></dt>
113 <dd><?php echo date('M j, Y', round($result['creationDate']/1000)); ?></dd>
115 <dt><?php echo _AT("description"); ?></dt>
116 <dd><?php if ($result['description']=='') echo _AT('na'); else if (strlen($result['description']) > 120) echo substr(htmlspecialchars($result['description']), 0, 120). "..."; else echo htmlspecialchars($result['description']); ?></dd>
118 <dt><?php echo _AT("merlot_creative_commons"); ?></dt>
119 <dd><?php if ($result['creativeCommons'] == "true") echo _AT('yes'); else echo _AT('no'); ?></dd>