Page 233 - Building Digital Libraries
P. 233

<?php
              /**
              * Version 1.0
              *—initial version
              *—supports OpenSearch 1.0, http://opensearch.a9.com
              *
              * @Based on the WordPress opensearch plugin
              * @http://williamsburger.com/wb/archives/opensearch-v-1–0
              */
              function extract_description($s, $max) {
              $words = explode(“ “, htmlspecialchars($s));
              if (count($words)>$max) {
              return implode(‘ ‘,array_slice($words, 0, $max-1)) . “[ . . . ]”;
              } else {
              return $s;
              }
              }
              //Constants
              define(“CONST_TITLE,” “title”);
              define(“CONST_DESCRIPT,” “descri”);
              define(“CONST_SUBJECT,” “subjec”);
              define(“CONST_CREATOR,” “creato”);
              if (isset($_GET[“searchTerms”])) { $searchTerms = $_GET[“searchTerms”]; } else { $searchTerms = ““; }
              if (isset($_GET[“startIndex”])) { $startIndex = $_GET[“startIndex”]; } else { $startIndex = 1; }
              if (isset($_GET[“startPage”])) { $startPage = $_GET[“startPage”]; } else { $startPage = 1; }
              if (isset($_GET[“count”])) { $count = $_GET[“count”]; } else { $count = 10; }
              $records = array();
              if (!empty($searchTerms)) {
              $total = 0;
              $contents  =  file_get_contents(“https://library.osu.edu/dc/catalog?utf8=%E2%9C%93&per_page=$count&
              q=$searchTerms&format=json”);
              $contents = utf8_encode($contents);
              $contents = json_decode($contents, true);
              if (count($contents) > 0) {
              $totalResults = $contents[“total”];
              $records = $contents[“docs”];
              }
              }
              ?>
              <?php header( “Content-type: text/xml;\n\n “ , true ); ?>
              <?php echo ‘<?xml version=“1.0” encoding=“utf-8” ?’ . ‘>‘; ?>
              <rss version=“2.0”
              xmlns:content=“http://purl.org/rss/1.0/modules/content/”
              xmlns:wfw=“http://wellformedweb.org/CommentAPI/”
              xmlns:dc=“http://purl.org/dc/elements/1.1/”
              xmlns:openSearch=“http://a9.com/-/spec/opensearchrss/1.1/”
              >
              <channel>
              <title>Test Title</title>
              <link>http://reeset.net/anonymous/osu_dc.php</link>
              <description>Test Description</description>
              <pubDate><?php echo date( ‘D, d M Y H:i:s +0000’); ?></pubDate>
              <generator>OSU PHP Sample Generator</generator>
              <language>English</language>
              <openSearch:totalResults><?=$totalResults?></openSearch:totalResults>
              <openSearch:startIndex><?=$startIndex?></openSearch:startIndex>
              <openSearch:itemsPerPage><?=$count?></openSearch:itemsPerPage>
              <?php if ( $records ) {
              $items_count = 1; ?>
              <?php foreach ( $records as $record ) {?>
              <item>
              <title><?=$record[“title”][0]?></title>



            218
   228   229   230   231   232   233   234   235   236   237   238