Subversion Repositories oidplus

Compare Revisions

Regard whitespace Rev 225 → Rev 226

/trunk_oldversion/plugins/search/doi.inc.php
0,0 → 1,54
<?php
 
# TODO: das kann ohne suffix auskommen: http://dx.doi.org/10.1038/
 
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.');
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
 
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php';
 
class VolcanoSearchDOI implements VolcanoSearchProvider {
public static function checkId($id) {
return self::strEqual($id, 'doi', true); // is always case insensitive
}
 
public static function calcDistance($candidate, $searchterm) {
$y = explode('/', $searchterm);
$x = explode('/', $candidate);
$dist = count($y)-count($x);
 
for ($i=0; $i<min(count($x),count($y)); $i++) {
if ($x[$i] != $y[$i]) return false;
}
 
return $dist;
}
 
protected static function strEqual($str1, $str2, $caseInsensitive = false) {
if ($caseInsensitive) {
return strtolower($str1) == strtolower($str2);
} else {
return $str1 == $str2;
}
}
}
 
require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
VolcanoDB::registerSearchProvider(new VolcanoSearchDOI());
 
# --- TEST
 
$x = new VolcanoSearchDOI();
 
assert($x->calcDistance('10.1000', '10.1000/1') == 1);
assert($x->calcDistance('10.1000/1', '10.1000') == -1);
assert($x->calcDistance('10.1000', '10.1000') == 0);
assert($x->calcDistance('10.1001', '10.1000') === false);
 
assert($x->calcDistance('10.1000/1/2/3', '10.1000/1/2/3/4/5') == 2);
assert($x->calcDistance('10.1000/1/2/3', '10.1000/1/2/3') == 0);
assert($x->calcDistance('10.1000/1/2/3/4/5', '10.1000/1/2/3') == -2);
 
assert($x->calcDistance('10.1000/1/2/x', '10.1000/1/2/3/4/5') === false);
assert($x->calcDistance('10.1000/1/2/x', '10.1000/1/2/3') === false);
assert($x->calcDistance('10.1000/1/2/x/4/5', '10.1000/1/2/3') === false);
/trunk_oldversion/plugins/search/domain.inc.php
0,0 → 1,67
<?php
 
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.');
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
 
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php';
 
class VolcanoSearchDomain implements VolcanoSearchProvider {
public static function checkId($id) {
return self::strEqual($id, 'domain', true); // is always case insensitive
}
 
protected static function tryNormalize($term) {
// TODO: also validate syntax
$ary = explode(':', $term);
$term = $ary[0];
if (substr($term, -1, 1) != '.') $term .= '.';
return $term;
}
 
public static function calcDistance($candidate, $searchterm) {
// TODO: punycode?
 
$candidate = self::tryNormalize($candidate);
$searchterm = self::tryNormalize($searchterm);
 
if (strlen($candidate) <= strlen($searchterm)) {
$cmp = substr($searchterm, strlen($searchterm)-strlen($candidate));
if (!self::strEqual($cmp, $candidate, true)) return false;
 
$subdoms = substr($searchterm, 0, strlen($searchterm)-strlen($candidate));
return substr_count($subdoms, '.');
} else {
$cmp = substr($candidate, strlen($candidate)-strlen($searchterm));
if (!self::strEqual($cmp, $searchterm, true)) return false;
 
$too_specific = substr($candidate, 0, strlen($candidate)-strlen($searchterm));
return -substr_count($too_specific, '.');
}
}
 
protected static function strEqual($str1, $str2, $caseInsensitive = false) {
if ($caseInsensitive) {
return strtolower($str1) == strtolower($str2);
} else {
return $str1 == $str2;
}
}
}
 
require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
VolcanoDB::registerSearchProvider(new VolcanoSearchDomain());
 
# --- TEST
 
/*
$x = new VolcanoSearchDomain();
assert($x->calcDistance('de.', 'viathinksoft.DE.') == 1);
assert($x->calcDistance('de.', 'viathinksoft.de.') == 1);
assert($x->calcDistance('viathinksoft.de.', 'viathinksoft.de.') == 0);
assert($x->calcDistance('viathinksoft.DE.', 'viathinksoft.de.') == 0);
assert($x->calcDistance('www.viathinksoft.de.', 'viathinksoft.de.') == -1);
 
assert($x->calcDistance('de.', 'viathinksoft.xx.') === false);
assert($x->calcDistance('viathinksoft.de.', 'viathinksoft.xx.') === false);
assert($x->calcDistance('www.viathinksoft.de.', 'viathinksoft.xx.') === false);
*/
/trunk_oldversion/plugins/search/ipv4.inc.php
0,0 → 1,45
<?php
 
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.');
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
 
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php';
require_once __DIR__ . '/../../includes/ipv4_functions.inc.php';
 
class VolcanoSearchIPv4 implements VolcanoSearchProvider {
public static function checkId($id) {
return self::strEqual($id, 'ipv4', true); // is always case insensitive
}
 
public static function calcDistance($candidate, $searchterm) {
return ipv4_distance($searchterm, $candidate); // TODO: richtig rum?
}
 
protected static function strEqual($str1, $str2, $caseInsensitive = false) {
if ($caseInsensitive) {
return strtolower($str1) == strtolower($str2);
} else {
return $str1 == $str2;
}
}
}
 
require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
VolcanoDB::registerSearchProvider(new VolcanoSearchIPv4());
 
# --- TEST
 
/*
$x = new VolcanoSearchIPv4();
 
assert($x->calcDistance('192.168.0.0/16', '192.168.64.0/18') === 2);
assert($x->calcDistance('192.168.64.0/18', '192.168.64.0/18') === 0);
assert($x->calcDistance('192.168.64.0/20', '192.168.64.0/18') === -2);
 
assert($x->calcDistance('192.168.69.200/31', '192.168.69.202/31') === false);
assert($x->calcDistance('192.168.69.200/32', '192.168.69.201/32') === false);
assert($x->calcDistance('192.168.69.200', '192.168.69.201') === false);
 
assert($x->calcDistance('95.211.38.42/32', '95.211.38.42') === 0);
assert($x->calcDistance('95.211.38.42', '95.211.38.42/32') === 0);
*/
/trunk_oldversion/plugins/search/ipv6.inc.php
0,0 → 1,42
<?php
 
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.');
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
 
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php';
require_once __DIR__ . '/../../includes/ipv6_functions.inc.php';
 
class VolcanoSearchIPv6 implements VolcanoSearchProvider {
public static function checkId($id) {
return self::strEqual($id, 'ipv6', true); // is always case insensitive
}
 
public static function calcDistance($candidate, $searchterm) {
return ipv6_distance($searchterm, $candidate); // TODO: richtig rum?
}
 
protected static function strEqual($str1, $str2, $caseInsensitive = false) {
if ($caseInsensitive) {
return strtolower($str1) == strtolower($str2);
} else {
return $str1 == $str2;
}
}
}
 
require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
VolcanoDB::registerSearchProvider(new VolcanoSearchIPv6());
 
# --- TEST
 
/*
$x = new VolcanoSearchIPv6();
assert($x->calcDistance('2001:1ae0::/27', '2001:1af8::/29') == 2);
assert($x->calcDistance('2001:1af8::/29', '2001:1af8::/29') == 0);
assert($x->calcDistance('2001:1af8::/31', '2001:1af8::/29') == -2);
 
assert($x->calcDistance('2002:1af8:4100:a061:0001::1335/127', '2001:1af8:4100:a061:0001::1336/127') === false);
assert($x->calcDistance('2001:1af8:4100:a061:0001::1337/128', '2001:1af8:4100:a061:0001::1336/128') === false);
assert($x->calcDistance('2001:1af8:4100:a061:0001::1337', '2001:1af8:4100:a061:0001::1336') === false);
*/
 
/trunk_oldversion/plugins/search/str.inc.php
0,0 → 1,37
<?php
 
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.');
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
 
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php';
 
class VolcanoSearchStr implements VolcanoSearchProvider {
public static function checkId($id) {
return self::strEqual($id, 'str', true); // is always case insensitive
}
 
public static function calcDistance($candidate, $searchterm) {
return (self::strEqual($candidate, $searchterm, false)) ? 0 : -1;
}
 
protected static function strEqual($str1, $str2, $caseInsensitive = false) {
if ($caseInsensitive) {
return strtolower($str1) == strtolower($str2);
} else {
return $str1 == $str2;
}
}
}
 
require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
VolcanoDB::registerSearchProvider(new VolcanoSearchStr());
 
# --- TEST
 
/*
$x = new VolcanoSearchStr();
assert($x->calcDistance('a', 'a') == 0);
assert($x->calcDistance('a', 'A') == -1);
assert($x->calcDistance('a', 'b') == -1);
*/
 
/trunk_oldversion/plugins/search/stri.inc.php
0,0 → 1,37
<?php
 
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.');
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
 
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php';
 
class VolcanoSearchStrI implements VolcanoSearchProvider {
public static function checkId($id) {
return self::strEqual($id, 'stri', true); // is always case insensitive
}
 
public static function calcDistance($candidate, $searchterm) {
return (self::strEqual($candidate, $searchterm, true)) ? 0 : -1;
}
 
protected static function strEqual($str1, $str2, $caseInsensitive = false) {
if ($caseInsensitive) {
return strtolower($str1) == strtolower($str2);
} else {
return $str1 == $str2;
}
}
}
 
require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
VolcanoDB::registerSearchProvider(new VolcanoSearchStrI());
 
# --- TEST
 
/*
$x = new VolcanoSearchStrI();
assert($x->calcDistance('a', 'a') == 0);
assert($x->calcDistance('a', 'A') == 0);
assert($x->calcDistance('a', 'b') == -1);
*/
 
/trunk_oldversion/plugins/search/uuid.inc.php
0,0 → 1,54
<?php
 
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.');
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
 
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php';
 
class VolcanoSearchUUID implements VolcanoSearchProvider {
public static function checkId($id) {
return self::strEqual($id, 'guid', true) || self::strEqual($id, 'uuid', true); // is always case insensitive
}
 
protected static function tryNormalize($term) {
// TODO: also validate syntax
$term = str_replace('{', '', $term);
$term = str_replace('}', '', $term);
$term = strtolower($term);
return $term;
}
 
public static function calcDistance($candidate, $searchterm) {
$candidate = self::tryNormalize($candidate);
$searchterm = self::tryNormalize($searchterm);
 
if ($candidate == $searchterm) {
return 0;
} else {
return false;
}
}
 
protected static function strEqual($str1, $str2, $caseInsensitive = false) {
if ($caseInsensitive) {
return strtolower($str1) == strtolower($str2);
} else {
return $str1 == $str2;
}
}
}
 
require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
VolcanoDB::registerSearchProvider(new VolcanoSearchUUID());
 
# --- TEST
 
/*
$x = new VolcanoSearchUUID();
 
assert($x->calcDistance('fd3c657c-0728-4769-b608-db5ece442c97', '8338af1c-61ea-41c1-aded-c836846ae22d') === false);
assert($x->calcDistance('fd3c657c-0728-4769-b608-db5ece442c97', 'fd3c657c-0728-4769-b608-db5ece442c97') === 0);
assert($x->calcDistance('fd3c657c-0728-4769-b608-db5ece442c97', '{FD3c657c-0728-4769-b608-db5ece442C97}') === 0);
assert($x->calcDistance('{fd3C657C-0728-4769-b608-db5ece442c97}', 'fd3c657c-0728-4769-b608-db5ece442c97') === 0);
*/