From: Michael S. <sta...@us...> - 2005-10-04 22:59:42
|
Update of /cvsroot/archive-access/archive-access/projects/wera/src/webapps/wera/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23369/wera/src/webapps/wera/lib Added Files: asearch_collections.inc asearch_languages.inc config.inc config.inc.template documentLocator.inc httpUtils.inc init.inc nls.inc time.inc timeline.inc url.inc Log Message: First time add of wera. Moved here from nwa.nb.no. --- NEW FILE: url.inc --- <?php /* * This file is part of WERA. * * Copyright (C) 2001-2002 Royal Library in Stockholm, * Royal Library in Copenhagen, * Helsinki University Library of Finland, * National Library of Norway, * National and University Library of Iceland. * * WERA is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * WERA is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with WERA; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * $Id: url.inc,v 1.1 2005/10/04 22:59:27 stack-sf Exp $ */ // Various functions for manipulating urls // string stripPort(string $url) - strips portnumber from url if it is 80 (default) // string stripProtocol(string $url) - strips protocol from url http:// only // boolean isAbsolute(string $url) - returns true if url is absolute // boolean isRelative(string $url) - returns true if relative to path, false if relative to domain // string getDocname(string $url) - gets document name from url // string getDomain(string $url) - get domain from url // string getPath(string $url) - get path from url // string combineUrl(string $orig_url, string $url) - combines an absolute url with a relative link // Strips portnumber if 80 function stripPort($url) { $url = str_replace(":80/","/",$url); return $url; } // Strips http:// function stripProtocol($url) { $url = eregi_replace ("^http://","",$url); return $url; } // Example url: http://www.domain.com/path/index.html // returns true if it is :] function isAbsolute($url) { if (eregi ("^http://", $url) ) { return true; } else { return false; } } // Returns document name: index.html function getDocname($url) { eregi ("[^/]*$", $url, $matches); if ($matches != "") { #print "Matches: " . $matches[0] . "<br>\n"; return $matches[0]; } else return false; } // Returns domain-name: www.domain.com // !! Only if the URL starts with http:// function getDomain($url) { if (isAbsolute($url)) { $url = eregi_replace ("^http://", "", $url); eregi ("^[^/]*", $url, $matches); return $matches[0]; } else { return false;} } // Returns path: /path/ usage: getDomain("someurl"[,true|false][,true|false]) // Set nostartslash to true if you don't want the start slash returned // Set noendslash to true if you don't want the end slash returned // Otherwise, don't pass the the two last parameters function getPath($url,$nostartslash=FALSE, $noendslash=FALSE) { //If url field is empty - return a null field. if ($url==""){return $url;} $domain = getDomain($url); $docname = getDocname($url); #print "Domain: $domain<br>\n"; #print "Docname: $docname<br>\n"; $url = eregi_replace ( "^http://", "", $url); $url = eregi_replace ( "$domain", "", $url); if ($docname) $url = eregi_replace ( "$docname", "", $url); if ($nostartslash) { $url = eregi_replace ( "^/*", "", $url ); } if ($noendslash) { $url = eregi_replace ( "/*$", "", $url ); } #print "Returned path: $url<br>\n"; return $url; } // Returns: // -1 If absolute // 0 If url is relative to domain (starts with /) // 1 If url is relative to domain/path (doesn't start with /) function isRelative($url) { if (isAbsolute($url)) { return -1; } elseif ( eregi ( "^/", $url)) { return false; } else { return true;} } // Takes original url and a relative url and combines them to an absolute url function combineUrl($l_url,$o_url) { $query = $l_url; if (!isAbsolute($l_url)) // If relative { // Her m� det gj�res litt av hvert for � f� rett streng til s�ket. if (isRelative($l_url)) // Relative to domain/path/ { $domain = getDomain($o_url); #print "Parameter for getPath: $o_url<br>\n"; $orig_path = getPath($o_url); #print "Orig_path: $orig_path<br>\n"; while ( eregi ("^\.\.\/", $l_url)) { #print $orig_path; $orig_path = eregi_replace ("[^/]*\/$","",$orig_path); $orig_path = $orig_path . "/"; $orig_path = eregi_replace ("\/{2}","/",$orig_path); $l_url = eregi_replace ("^\.\.\/", "", $l_url); #print " -> " . $orig_path; } $l_url = eregi_replace ("^(\.\/)(\.\/)*", "", $l_url); $query = "http://" . $domain . $orig_path . $l_url; #print $query; } else // It is relative to domain only { $domain = getDomain($o_url); $orig_path = getPath($o_url); $query = "http://" . $domain . $l_url; } } return $query; } ?> --- NEW FILE: timeline.inc --- <?php /* * This file is part of WERA. * * Copyright (C) 2001-2002 Royal Library in Stockholm, * Royal Library in Copenhagen, * Helsinki University Library of Finland, * National Library of Norway, * National and University Library of Iceland. * * WERA is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * WERA is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with WERA; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ include_once ($conf_includepath."/time.inc"); include_once ($conf_index_file); include_once ($conf_includepath."/documentLocator.inc"); /** * Class for generating the necessary data for displaying a timeline * with the versions (with links) marked along the line * * $Id: timeline.inc,v 1.1 2005/10/04 22:59:27 stack-sf Exp $ */ class timeline { var $dates_to_display = array (), $chosen_date, $timeline_array = array (), $resolution, $url, $encoded_url, $conf_index_class, $previous_version, $next_version, $first_version, $last_version, $number_of_versions; /** * Constructor * * @param string Resolution. Legal values: 6 (auto), 5 (years), 4 (months), 3 (days), 2 (hours), 1 (minutes), 0 (seconds) * @param string The chosen date on the timeline. Format: 'YYYYMMDDHHMISS' * @param array Url of the document to find all versions of */ function timeline($resolution = 6, $chosen_date, $url, $index_class) { $this->conf_index_class = $index_class; $this->url = $url; $this->encoded_url = index_encode($this->url); $this->resolution = $resolution; $versions = $this->getVersions(); $this->first_version = $versions[1][archival_time]; $this->last_version = $versions[$this->number_of_versions][archival_time]; if ($chosen_date == "") { $chosen_date = $this->last_version; } if ($resolution == 6) { $this->autoresolution = 'on'; $this->resolution = 5; } do { $buildstatus = $this->buildTimeline($chosen_date, $versions); if ($buildstatus == "drilldown" and $this->autoresolution == 'on') { $this->resolution--; } } while ($buildstatus == "drilldown" and $this->autoresolution == 'on'); } /** * Get data necessary to display the timeline * * @return array Timeline data */ function getTimelineData() { return $this->timeline_array; } /** * Get current resolution * If resolution is set to auto when instanciating the timeline * the method will return the resolution that the constructor drilled * down to. * * @return integer Resolution */ function getResolution() { return $this->resolution; } /** * Get number of versions * * @return integer Number of versions */ function getNumberOfVersions() { return $this->number_of_versions; } /** * Get the timestamp of the version before the chosen timestamp * * @return string timestamp (Format: 'YYYYMMDDHHMISS') */ function getPreviousVersionTimestamp() { return $this->previous_version; } /** * Get the timestamp of the version after the chosen timestamp * * @return string timestamp (Format: 'YYYYMMDDHHMISS') */ function getNextVersionTimestamp() { return $this->next_version; } /** * Get the timestamp of the first version * * @return string timestamp (Format: 'YYYYMMDDHHMISS') */ function getFirstVersionTimestamp() { return $this->first_version; } /** * Get the timestamp of the last version * * @return string timestamp (Format: 'YYYYMMDDHHMISS') */ function getLastVersionTimestamp() { return $this->last_version; } /** * Get the key of the version nearest before or equal to the * chosen timestamp * * @return string timestamp (Format: 'YYYYMMDDHHMISS') */ function getKeyOfCurrentVersion() { return $this->key_of_version_nearest_before; } // Private methods /** * Get all veresions of a given URL * * * @return array Resultset */ function getVersions() { $search = new $this->conf_index_class(); $docloc = new documentLocator(); $docloc->initialize($search, $this->url, false, 0, 'ALL'); $this->number_of_versions = $docloc->findVersions(); return $docloc->getResultSet(); } /** * Calculates the number of units on the timeline * * @return array Units to display on the timeline (units before the chosen date, and units after the chosen date) */ function getNumberOfUnitsOnTimeline() { //adapt this one to use parameters from a config file instead of the hardcoded values(?) switch ($this->resolution) { case '4' : //months $units[before] = 30; $units[after] = 30; break; case '3' : // days $units[before] = 30; $units[after] = 30; break; case '2' : // hours $units[before] = 30; $units[after] = 30; break; case '1' : // minutes $units[before] = 30; $units[after] = 30; break; case '0' : //seconds $units[before] = 30; $units[after] = 30; break; default : // years $units[before] = 5; $units[after] = 5; } return $units; } /** * Explode human date into an array * Typical retrun value (the resolution in the example below was 3): * * [base] => 20010924131555 * [second] => 55 * [minute] => 15 * [hour] => 13 * [day] => 24 * [month] => 09 * [year] => 2001 * [resolution_dependent_format] => 2001-09-24 * * @param string Timeline resolution * @param string Date to explode (Format: 'YYYYMMDDHHMISS') * @return array Exploded date */ function dateToArray($resolution, $indate) { $return_date[base] = $indate; $return_date[second] = substr($indate, 12, 2); $return_date[minute] = substr($indate, 10, 2); $return_date[hour] = substr($indate, 8, 2); $return_date[day] = substr($indate, 6, 2); $return_date[month] = substr($indate, 4, 2); $return_date[year] = substr($indate, 0, 4); switch ($resolution) { case '4' : // months $return_date[resolution_dependent_format] = $return_date[year]."-".$return_date[month]; break; case '3' : // days $return_date[resolution_dependent_format] = $return_date[year]."-".$return_date[month]."-".$return_date[day]; break; case '2' : // hours $return_date[resolution_dependent_format] = $return_date[year]."-".$return_date[month]."-".$return_date[day]." ".$return_date[hour]; break; case '1' : // minutes $return_date[resolution_dependent_format] = $return_date[year]."-".$return_date[month]."-".$return_date[day]." ".$return_date[hour].":".$return_date[minute]; break; case '0' : // seconds $return_date[resolution_dependent_format] = $return_date[year]."-".$return_date[month]."-".$return_date[day]." ".$return_date[hour].":".$return_date[minute].":".$return_date[second]; break; default : // years $return_date[resolution_dependent_format] = $return_date[year]; } return $return_date; } /** * Build the timeline * * @param string Chosen date * @versions array All the versions for the given URL * @return array Timeline data */ function buildTimeline($chosen_date, $versions) { unset ($this->chosen_date); unset ($this->timeline_array); $this->dates_to_display = $versions; $this->chosen_date = $this->dateToArray($this->resolution, $chosen_date); if (!empty ($versions)) { foreach ($this->dates_to_display as $key => $val) { $this->dates_to_display[$key] = $this->dateToArray($this->resolution, $this->dates_to_display[$key][archival_time]); } $units = $this->getNumberOfUnitsOnTimeline(); for ($n = - $units[before]; $n <= $units[after]; $n ++) { switch ($this->resolution) { case '4' : // months $unixtime = gmmktime(0, 0, 0, $this->chosen_date[month] + $n, 01, $this->chosen_date[year]); $timeformat = 'Y-m'; break; case '3' : // days $unixtime = gmmktime(0, 0, 0, $this->chosen_date[month], $this->chosen_date[day] + $n, $this->chosen_date[year]); $timeformat = 'Y-m-d'; break; case '2' : // hours $unixtime = gmmktime($this->chosen_date[hour] + $n, 0, 0, $this->chosen_date[month], $this->chosen_date[day], $this->chosen_date[year]); $timeformat = 'Y-m-d H'; break; case '1' : // minutes $unixtime = gmmktime($this->chosen_date[hour], $this->chosen_date[minute] + $n, 0, $this->chosen_date[month], $this->chosen_date[day], $this->chosen_date[year]); $timeformat = 'Y-m-d H:i'; break; case '0' : // seconds $unixtime = gmmktime($this->chosen_date[hour], $this->chosen_date[minute], $this->chosen_date[second] + $n, $this->chosen_date[month], $this->chosen_date[day], $this->chosen_date[year]); $timeformat = 'Y-m-d H:i:s'; break; default : // years $unixtime = gmmktime(0, 0, 0, 01, 01, $this->chosen_date[year] + $n); $timeformat = 'Y'; } $this->timeline_array[$n][resolution_dependent_format] = gmdate($timeformat, $unixtime); $this->timeline_array[$n][linkvalue] = gmdate('YmdHis', $unixtime); $this->timeline_array[$n][versions] = 0; foreach ($this->dates_to_display as $key => $val) { if ($this->dates_to_display[$key][resolution_dependent_format] == $this->timeline_array[$n][resolution_dependent_format]) { // There are one or more versions in this timeframe $this->timeline_array[$n][versions] = $this->timeline_array[$n][versions] + 1; $this->timeline_array[$n][version][$key] = $this->dates_to_display[$key][base]; // svb $this->timeline_array[$n][linkvalue] = $this->dates_to_display[$key][base]; if ($this->dates_to_display[$key][resolution_dependent_format] <= $this->chosen_date[resolution_dependent_format]) { $this->previous_version = $this->dates_to_display[$key -1][base]; $this->next_version = $this->dates_to_display[$key +1][base]; $this->key_of_version_nearest_before = $key; } } if ($this->timeline_array[$n][versions] > 1 and $this->timeline_array[$n][resolution_dependent_format] == $this->chosen_date[resolution_dependent_format]) { $retval = "drilldown"; } } } if ($timeline_array[$n][versions] > 0) { $this->timeline_array[$n][linkvalue] = $this->timeline_array[$n][version][1]; //svb } } if ($chosen_date < $this->dates_to_display[1]['base']) { $this->previous_version = ""; if ($this->number_of_versions > 1) { $this->next_version = $this->dates_to_display[2][base]; } else { $this->next_version = ""; } $this->key_of_version_nearest_before = ""; } return $retval; } } ?> --- NEW FILE: httpUtils.inc --- <?php /* * This file is part of WERA. * * Copyright (C) 2001-2002 Royal Library in Stockholm, * Royal Library in Copenhagen, * Helsinki University Library of Finland, * National Library of Norway, * National and University Library of Iceland. * * WERA is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * WERA is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with WERA; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * * $Id: httpUtils.inc,v 1.1 2005/10/04 22:59:27 stack-sf Exp $ */ /** * This function is meant for url fetching and display. * Ensures that the mime type is relayed properly, * which is not the case when using fopen and print. * * $Id: httpUtils.inc,v 1.1 2005/10/04 22:59:27 stack-sf Exp $ */ function fetchAndPrintUrl( $url ) { $url_parsed = parse_url($url); $host = $url_parsed["host"]; $port = $url_parsed["port"]; if ($port==0) { $port = 80; } $path = $url_parsed["path"]; if ($url_parsed["query"] != "") { $path .= "?".$url_parsed["query"]; } $out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n"; $fp = fsockopen($host, $port, $errno, $errstr, 30); fwrite($fp, $out); $body = false; while (!feof($fp)) { $s = fgets($fp, 1024); if ( $body ) { $in .= $s; } else { if (stristr($s, 'content-type')) { header($s); } } if ( $s == "\r\n" ) { $body = true; } } fclose($fp); print $in; } ?> --- NEW FILE: asearch_languages.inc --- <?php /* * This file is part of WERA. * * Copyright (C) 2001-2002 Royal Library in Stockholm, * Royal Library in Copenhagen, * Helsinki University Library of Finland, * National Library of Norway, * National and University Library of Iceland. * * WERA is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * WERA is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with WERA; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * $Id: asearch_languages.inc,v 1.1 2005/10/04 22:59:27 stack-sf Exp $ */ $languages = array ( "Czech" => "cs", "Danish" => "dk", "English" => "en", "Finish" => "fi", "Icelandic" => "is", "Italian" => "it", "Norwegian" => "n*", "Swedish" => "se" ); ?> --- NEW FILE: nls.inc --- <?php /* * This file is part of WERA. * * Copyright (C) 2001-2002 Royal Library in Stockholm, * Royal Library in Copenhagen, * Helsinki University Library of Finland, * National Library of Norway, * National and University Library of Iceland. * * WERA is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * WERA is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with WERA; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * Functions for National Language Support (NLS) * * $Id: nls.inc,v 1.1 2005/10/04 22:59:27 stack-sf Exp $ */ if(!isset($NLS_LOCALE)) { $NLS_LOCALE = ""; } if(!isset($NLS_CONTEXT)) { $NLS_CONTEXT = ""; } if(!isset($NLS_PATH)) { $NLS_PATH = "$conf_includepath/nls"; } /** * Translates a string to the current locale. * * @param string String to translate * @param context Overrides current context. * @param locale Overrides current locale. * @returns Returns the translated string or $string if no translation was found. */ function nls ($string, $context="", $locale="") { global $NLS_LOCALE, $NLS_PATH, $NLS_LANGUAGE_ARRAY; $context = nls_getcontext($context); $localelist = nls_getlocale($locale); $localenum = count($localelist); for($i=0; $i<$localenum; $i++) { $NLS_FILES[$i] = $NLS_PATH . "/" . $localelist[$i] . "/" . $context . ".nls"; $arrayindex[$i] = $context . '�' . $localelist[$i]; } for($i=0; $i<$localenum; $i++) { if ($NLS_LANGUAGE_ARRAY[$arrayindex[$i]] == "" && file_exists($NLS_FILES[$i])) { eval("\$NLS_LANGUAGE_ARRAY['" . $arrayindex[$i] . "'] = array (" . (join(', ', array_unique(file($NLS_FILES[$i])))) . ");"); } if (isset($NLS_LANGUAGE_ARRAY[$arrayindex[$i]][$string])) { return $NLS_LANGUAGE_ARRAY[$arrayindex[$i]][$string]; } } if($i == $localenum) { return $string; } } /** * Translates a string to the current locale. * * @param string String to translate * @param varlist array of parameters to substitute for placeholders * @param context Overrides current context. * @param locale Overrides current locale. * @returns Returns the translated string or $string if no translation was found. */ function nlsf ($string, $varlist, $context="", $locale="") { $string = nls($string, $context, $locale); $pattern = '/(?<!\\\)%([^;]*);/e'; $subst = "_format_data('$1', \$varlist)"; $string = preg_replace($pattern, $subst, $string); return $string; } /** * Format = %itx; * i = index * t = type (s = string, d = date, n = number, c = currency) * x = extra data */ function _format_data($command, $varlist) { preg_match('/([0-9]*)(\w)(.*)/', $command, $parts); if($parts[1] == '' || $parts[2] == '') { return ("ERROR"); } $value = $varlist[$parts[1]-1]; switch($parts[2]) { case 's': // String $result = $value; break; case 'n': // Number $result = $value; break; default: $result = 'ERROR'; } return $result; } /** * Find current locale. * Locales are searched for in the following order: * * parameter to this function. * * parameter set with nls_setlocale(). * * locale set in browser. */ function nls_getlocale ($locale="") { global $NLS_LOCALE, $HTTP_SERVER_VARS; if ($locale != "") { $result = $locale; } elseif ($NLS_LOCALE != "") { $result = $NLS_LOCALE; } else { $result = $HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"]; } $result = explode(',', $result); $locale = array(); while($element = array_shift($result)) { $element = substr($element, 0, strcspn($element, ';')); $locale[] = $element; $language = nls_getlanguage($element); if($element != $language) { $locale[] = $language; } } return $locale; } /** * Set which locale to use */ function nls_setlocale ($locale) { global $NLS_LOCALE; $NLS_LOCALE = $locale; } /** * Returns the lowercase language code (ISO 639) from a locale */ function nls_getlanguage ($locale) { return strtolower(substr($locale, 0, 2)); } /** * Returns the uppercase country code (ISO 3166) from a locale */ function nls_getcountry ($locale) { return strtolower(substr($locale, 3, 2)); } /** * */ function nls_getcontext ($context="") { global $NLS_CONTEXT; if ($context != "") { return $context; } elseif ($NLS_CONTEXT != "") { return $NLS_CONTEXT; } else { return basename($_SERVER['PHP_SELF']); } } /** * */ function nls_setcontext ($context) { global $NLS_CONTEXT; $NLS_CONTEXT = $context; } ?> --- NEW FILE: init.inc --- <?php /* * This file is part of WERA. * * Copyright (C) 2001-2002 Royal Library in Stockholm, * Royal Library in Copenhagen, * Helsinki University Library of Finland, * National Library of Norway, * National and University Library of Iceland. * * WERA is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * WERA is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with WERA; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * $Id: init.inc,v 1.1 2005/10/04 22:59:27 stack-sf Exp $ */ if(isset($conf_includepath)) { ini_set("include_path",$conf_includepath.":".$conf_index_path); } // Modules that always should be included include_once("$conf_includepath/nls.inc"); ?> --- NEW FILE: config.inc.template --- <?php /* * This file is part of WERA. * * Copyright (C) 2001-2002 Royal Library in Stockholm, * Royal Library in Copenhagen, * Helsinki University Library of Finland, * National Library of Norway, * National and University Library of Iceland. * * WERA is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * WERA is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with WERA; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * File: config.inc.template * * This is the template file for the config.inc file which is included first in all .php files. * Copy this file to config.inc * * $Id: config.inc.template,v 1.1 2005/10/04 22:59:27 stack-sf Exp $ */ $conf_debug = 0; // Print out some debug info // Path to includefiles $conf_rootpath = "@guiInstallDir@"; $conf_includepath = "$conf_rootpath/lib"; $conf_searchenginepath = "$conf_includepath/seal"; // What search engine to use $conf_searchengine = "@searchEngine@"; $conf_searchengine_url = "@searchEngineUrl@"; //$conf_searchengine = "fast"; //$conf_searchengine_url = "http://utvikling1.nb.no:15100/cgi-bin/asearch"; $conf_index_file = $conf_searchenginepath . "/" . $conf_searchengine . ".inc"; $conf_index_class = $conf_searchengine . "Search"; // Static texts to prepend/append to the Archive identifier returned from the // search engine. In the case of using nutchwax and the standard ARC retriever // the prefix would be the path to where the ARC files are stored and the suffix // the files extension (e.g. .arc.gz) // // TODO : Move this into the ARC Retriever $conf_aid_prefix = "@aidPrefix@/"; $conf_aid_suffix = "@aidSuffix@"; // Prefix to document retriever $document_retriever = "@retrieverUrl@"; $conf_document_retriever = "$document_retriever?reqtype=getfile&aid="; // URL of gui installation $conf_http_host = "@guiUrl@"; // Logo $conf_logo ="$conf_http_host/images/wera.png"; // URL to resultpage $conf_result_page = "$conf_http_host/result.php"; $conf_document_dispatcher = "$conf_http_host/documentDispatcher.php"; // URL of search interfaces $conf_simple_search = "$conf_http_host/index.php"; $conf_advanced_search = "$conf_http_host/asearch.php"; // GUI stylesheet $conf_gui_style = "$conf_http_host/css/style.css"; // Dummy image to display when not archived $conf_defaultimage = "$conf_rootpath/nwa/browser/html/nwa_notavail.gif"; // Mapping of MIME-types to document handler url's. The extra parameter indicates if this document-handler rewrites links or not. $conf_document_handler = array( "text/html" => "$conf_http_host/handlers/html_javascript.php parselinks", "image" => "$conf_http_host/handlers/passthrough.php nolinks", "default" => "$conf_http_host/handlers/passthrough.php nolinks"); // Site information // Location of this site $conf_location_code = "@collection@"; // Mapping to collections reciding at other hosts // Not needed when all of the indexed material is served by this installation // $conf_locations["ext1"] = "http://somewhereelse1.com/nwatoolset/result.php"; // $conf_locations["ext2"] = "http://somewhereelse2.com/nwatoolset/result.php"; // JavaScript disable/enabled for archived pages viewed in Archive Document View // values can be "on" or "off" $conf_javascript = "off"; //Help file links $conf_helplinks['search'] = array("name" =>'Help', "file" =>'help.php'); // Initialize include_once("$conf_includepath/init.inc"); ?> --- NEW FILE: time.inc --- <?php /* * This file is part of WERA. * * Copyright (C) 2001-2002 Royal Library in Stockholm, * Royal Library in Copenhagen, * Helsinki University Library of Finland, * National Library of Norway, * National and University Library of Iceland. * * WERA is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * WERA is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with WERA; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * $Id: time.inc,v 1.1 2005/10/04 22:59:27 stack-sf Exp $ * * function(s) for converting time-variables * * converts a string of format * YYYY/MM/DD/HH/MM/SS-YYYY/MM/DD/HH/SS * into an ..array containing * 2 numbers.(unix-time) */ function time2one($string) { $time_array = explode ("-",$string); return $time_array; } function time2num($string) { $time_array = explode ("/",$string); return mktime($time_array[3],$time_array[4],$time_array[5],$time_array[1],$time_array[2],$time_array[0]); } // deprecated. for historical reasons :] function time2numeric($string) { $two_dates = time2one($string); $date_one = time2num($two_dates[0]); $date_two = time2num($two_dates[1]); $return_array = array($date_one, $date_two); return $return_array; } function time2str($unixtime) { return date("D, d M Y H:i:s \C\E\T", $unixtime); } function time2str_field($unixtime) { return date("Y/m/d", $unixtime); } function unix2human($unixtime) { return date("Y/m/d H:i:s", $unixtime); } --- NEW FILE: config.inc --- <?php /* * This file is part of WERA. * * Copyright (C) 2001-2002 Royal Library in Stockholm, * Royal Library in Copenhagen, * Helsinki University Library of Finland, * National Library of Norway, * National and University Library of Iceland. * * WERA is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * WERA is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with WERA; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * File: config.inc.template * * This is the template file for the config.inc file which is included first in all .php files. * Copy this file to config.inc * * $Id: config.inc,v 1.1 2005/10/04 22:59:27 stack-sf Exp $ */ $conf_debug = 0; // Print out some debug info // Path to includefiles $conf_rootpath = "/opt/lampp/htdocs/werawork"; $conf_includepath = "$conf_rootpath/lib"; $conf_searchenginepath = "$conf_includepath/seal"; // What search engine to use $conf_searchengine = "nutch"; $conf_searchengine_url = "http://fast3.nb.no:8080/nutchwax/opensearch"; //$conf_searchengine = "fast"; //$conf_searchengine_url = "http://utvikling1.nb.no:15100/cgi-bin/asearch"; $conf_index_file = $conf_searchenginepath . "/" . $conf_searchengine . ".inc"; $conf_index_class = $conf_searchengine . "Search"; // Static texts to prepend/append to the Archive identifier returned from the // search engine. In the case of using nutchwax and the standard ARC retriever // the prefix would be the path to where the ARC files are stored and the suffix // the files extension (e.g. .arc.gz) // // TODO : Move this into the ARC Retriever $conf_aid_prefix = "/home/wera/arcs/"; $conf_aid_suffix = ".arc.gz"; // Prefix to document retriever $document_retriever = "http://fast3.nb.no:8080/ArcRetriever/ArcRetriever"; $conf_document_retriever = "$document_retriever?reqtype=getfile&aid="; // URL of gui installation $conf_http_host = "http://localhost/WERA/gui"; // Logo $conf_logo ="$conf_http_host/images/wera.png"; // URL to resultpage $conf_result_page = "$conf_http_host/result.php"; $conf_document_dispatcher = "$conf_http_host/documentDispatcher.php"; // URL of search interfaces $conf_simple_search = "$conf_http_host/index.php"; $conf_advanced_search = "$conf_http_host/asearch.php"; // GUI stylesheet $conf_gui_style = "$conf_http_host/css/style.css"; // Dummy image to display when not archived $conf_defaultimage = "$conf_rootpath/nwa/browser/html/nwa_notavail.gif"; // Mapping of MIME-types to document handler url's. The extra parameter indicates if this document-handler rewrites links or not. $conf_document_handler = array( "text/html" => "$conf_http_host/handlers/html_javascript.php parselinks", "image" => "$conf_http_host/handlers/passthrough.php nolinks", "default" => "$conf_http_host/handlers/passthrough.php nolinks"); // Site information // Location of this site $conf_location_code = "test"; // Mapping to collections reciding at other hosts // Not needed when all of the indexed material is served by this installation // $conf_locations["ext1"] = "http://somewhereelse1.com/nwatoolset/result.php"; // $conf_locations["ext2"] = "http://somewhereelse2.com/nwatoolset/result.php"; // JavaScript disable/enabled for archived pages viewed in Archive Document View // values can be "on" or "off" $conf_javascript = "off"; //Help file links $conf_helplinks['search'] = array("name" =>'Help', "file" =>'help.php'); // Initialize include_once("$conf_includepath/init.inc"); ?> --- NEW FILE: asearch_collections.inc --- <?php /* * This file is part of WERA. * * Copyright (C) 2001-2002 Royal Library in Stockholm, * Royal Library in Copenhagen, * Helsinki University Library of Finland, * National Library of Norway, * National and University Library of Iceland. * * WERA is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * WERA is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with WERA; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * $Id: asearch_collections.inc,v 1.1 2005/10/04 22:59:27 stack-sf Exp $ */ $collections = array ( "Norway" => "no", "Norway - Election 2001" => "no paradigma", "Norway - nb.no 2002" => "no nbvev2002", "Denmark" => "dk", "Finland" => "fi", "Iceland" => "is", "Sweden" => "se" ); ?> --- NEW FILE: documentLocator.inc --- <?php /* * This file is part of WERA. * * Copyright (C) 2001-2002 Royal Library in Stockholm, * Royal Library in Copenhagen, * Helsinki University Library of Finland, * National Library of Norway, * National and University Library of Iceland. * * WERA is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * WERA is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with WERA; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * Class for finding version(s) of a * document in the index. * * $Id: documentLocator.inc,v 1.1 2005/10/04 22:59:27 stack-sf Exp $ */ class documentLocator { var $indexDriver; var $url; var $urlextend; var $time; var $querymode; var $resultset = array(); var $errormessage; var $query; /** * Initialize * * The following query modes are valid: * * EXACT - Will produce a result if, and only if exact match on time input * NEAR - Returns the match nearest to the time input * BEFORE - Returns the match nearest before or equal to the time input * AFTER - Returns the match nearest after or equal to the time input * FIRST - Returns the first match in time regardless of time input * LAST - Returns the latest match in time regardless of time input * ALL - Returns all matches regardless of time input (default) * * * @param object subclass of indexSearch * @param string url of document to find * @param boolean urlextend i.e. if true also query for url."/" (if "/" not already present at end of url) * @param string timestamp in number of seconds since the Unix Epoch * @param string query mode i.e. what the document locator should return */ function initialize($indexDriver, $url, $urlextend, $time, $querymode) { $this->indexDriver = $indexDriver; $this->url = $url; $this->urlextend = $urlextend; $this->time = $time; $this->querymode = $querymode; } /** * Execute the query * * This method builds the query string, executes * the query and populates the resultset array * (resultset[1][archiveurl], resultset[1][dcdate], resultset[1][encoding], resultset[2][archiveurl], ... * If the method returns -1 use getErrorMessage to determine why * * @return integer Number of hits, -1 if something wrong */ function findVersions() { $query_start = "nwa.url:" . $this->url; if ($this->urlextend) { if (substr($this->url,-1)!="/") { $query_start = $query_start . " ". $query_start . "/"; } } $sizeofresultset = 1; if ($this->querymode != 'NEAR') { switch ($this->querymode) { case 'EXACT': $query_end = "nwa.archival_time:" . $this->time; $sortorder = 'ascending'; break; case 'BEFORE': $query_end = sprintf("nwa.archival_time:[;%s]", $this->time); $sortorder = 'descending'; break; case 'AFTER': $query_end = sprintf("nwa.archival_time:[%s;]", $this->time); $sortorder = 'ascending'; break; case 'FIRST': $query_end = ""; $sortorder = 'ascending'; break; case 'LAST': $query_end = ""; $sortorder = 'descending'; break; default: // 'ALL' or anything else than the above $query_end = ""; $sortorder = 'ascending'; $sizeofresultset = 1000; } $this->query = $query_end . " +(" . $query_start . ")"; #print "\nQuery : " . $this->query; $this->indexDriver->setQuery($this->query); $this->indexDriver->setSortorder($sortorder); $this->indexDriver->setSizeOfResultSet($sizeofresultset); $this->indexDriver->setFieldsInResult("archival_time dcformat url encoding archiveidentifier collection"); if ($this->indexDriver->doQuery()) { $numhits = $this->indexDriver->getnumhits(); $this->resultset = $this->indexDriver->getResultSet(); } else { $numhits = -1; } #print "Queryurl: " . $this->indexDriver->queryurl; } else { // querymode = 'NEAR' $tmpdoc = new documentLocator(); $tmpdoc->initialize($this->indexDriver, $this->url, $this->urlextend, $this->time, 'BEFORE'); $numhits_before = $tmpdoc->findVersions(); if ( $numhits_before > 0) { $resultset_before = $tmpdoc->getResultSet(); } $tmpdoc->initialize($this->indexDriver, $this->url, $this->urlextend, $this->time, 'AFTER'); $numhits_after = $tmpdoc->findVersions(); if ( $numhits_after > 0) { $resultset_after = $tmpdoc->getResultSet(); } $numhits = 1; if (($numhits_before == 0) and ($numhits_after == 0)) { $numhits = 0; } elseif (($numhits_before > 0) and ($numhits_after > 0)) { if (($resultset_after[1][archival_time] - $this->time) < ($this->time - $resultset_before[1][archival_time])) { $this->resultset = $resultset_after; } else { $this->resultset = $resultset_before; } } elseif ( $numhits_before > 0 ) { $this->resultset = $resultset_before; } elseif ( $numhits_after > 0 ) { $this->resultset = $resultset_after; } else { $numhits = -1; } } return $numhits; } /** * Get the archive URI and mime class * * @return array resultset containing archiveurl, dcdate and encoding */ function getResultSet() { return $this->resultset; } /** * Get error message * * @return string error message */ function getErrorMessage() { return $this->indexDriver->getErrorMessage(); } } ?> |