diff --git a/dist/files_opds-0.5.1.tar.gz b/dist/files_opds-0.5.1.tar.gz
new file mode 100644
index 0000000..b875627
Binary files /dev/null and b/dist/files_opds-0.5.1.tar.gz differ
diff --git a/files_opds/appinfo/info.xml b/files_opds/appinfo/info.xml
index f1f0524..2a590ca 100644
--- a/files_opds/appinfo/info.xml
+++ b/files_opds/appinfo/info.xml
@@ -4,7 +4,7 @@
OPDS catalog
Personal OPDS catalog
AGPL
- 0.5
+ 0.5.1
Frank de Lange
7.0
true
diff --git a/files_opds/lib/isbn.php b/files_opds/lib/isbn.php
index b2a3e25..5499dd7 100644
--- a/files_opds/lib/isbn.php
+++ b/files_opds/lib/isbn.php
@@ -27,45 +27,55 @@ class Isbn
/**
* @brief try to find a valid ISBN in the given text, using a cascade of
- * regexps. Can be optimized.
+ * regexps.
*
* @param string $text text to search through
* @return string $hit ISBN on success, false otherwise
*/
public static function scan($text) {
- if ($hits = preg_grep('/isbn/i',$text)) {
- foreach ($hits as $hit) {
- $hit = preg_replace('/.*ISBN(?:[ -]?1[03]:)?\s*([xX0-9-]{10,17}).*/i','$1',$hit,1);
- //$hit = preg_replace('/isbn([ -]\(?1[03]\)?)?/i','',$hit);
- $hit = preg_replace('/[^0-9X]/i','',$hit);
- if(self::validate($hit)) {
- return $hit;
+ $match = array();
+ foreach($text as $line) {
+ /* generic ISBN 10/13 pattern */
+ if(preg_match_all('/ISBN(?:[ -]?[1[03]]?)?:?\s*((97[89])?[X0-9-–]{10,14})/i',$line,$match)) {
+ foreach($match[1] as $hit) {
+ $hit = preg_replace('/[^0-9X]/i','',$hit);
+ if(self::validate($hit)) {
+ return $hit;
+ }
+ }
+ }
+
+ /* single ISBN-13 targeted pattern (canonical format) */
+ if(preg_match_all('/(97[89][ –-]?\d[ –-]?\d{4}[ –-]?\d{4}[ –-]?\d)/',$line,$match)) {
+ foreach($match[1] as $hit) {
+ $hit = preg_replace('/[^0-9]/','',$hit);
+ if(self::validate($hit)) {
+ return $hit;
+ }
+ }
+ }
+
+ /* single ISBN-13 targeted pattern (free format) */
+ if(preg_match_all('/(9[\d –-]{11,15}\d)/',$line,$match)) {
+ foreach($match[1] as $hit) {
+ $hit = preg_replace('/[^0-9]/','',$hit);
+ if(self::validate($hit)) {
+ return $hit;
+ }
+ }
+ }
+
+ /* single ISBN-10 targeted pattern */
+ if(preg_match_all('/(\d[\d –-]{8,11}[\dX])/i',$line,$match)) {
+ foreach($match[1] as $hit) {
+ $hit = preg_replace('/[^0-9X]/i','',$hit);
+ if(self::validate($hit)) {
+ return $hit;
+ }
}
}
}
- /* single ISBN-13 targeted pattern */
- if ($hits = preg_grep('/\d{3}[ -]?\d[ -]?\d{4}[ -]?\d{4}[ -]?\d/', $text)) {
- foreach ($hits as $hit) {
- $hit = preg_replace('/.*(\d{3}[ -]?\d[ -]?\d{4}[ -]?\d{4}[ -]?\d).*/','$1',$hit,1);
- $hit = preg_replace('/[^0-9]/i','',$hit);
- if(self::validate($hit)) {
- return $hit;
- }
- }
- }
-
- /* single ISBN-10 targeted pattern */
- if ($hits = preg_grep('/\d[\d -]{8,11}[\dX]/i', $text)) {
- foreach ($hits as $hit) {
- $hit = preg_replace('/.*(\d[\d -]{8,11}[\dX]).*/','$1',$hit,1);
- $hit = preg_replace('/[^0-9X]/i','',$hit);
- if(self::validate($hit)) {
- return $hit;
- }
- }
- }
-
return false;
}
@@ -115,22 +125,28 @@ class Isbn
* @return bool true if valid ISBN-10
*/
static function isIsbn10 ($isbn) {
- $checksum = 0;
- for ($i = 0; $i < 10; ++$i) {
- if (!isset($isbn{$i})) {
- return false;
- }
- if ('X' === $isbn{$i}) {
- $digit = 10;
- } elseif (ctype_digit($isbn{$i})) {
- $digit = $isbn{$i};
- } else {
- return false;
- }
- $checksum += $digit * intval(10 - $i);
- }
+ $len = strlen($isbn);
+ if ($len == 10) {
+ //Calculate check digit
+ $check = 0;
+ for ($i = 0; $i < 9; $i++) {
+ if ($isbn[$i] === "X") {
+ $check += 10 * intval(10 - $i);
+ } else {
+ $check += intval($isbn[$i]) * intval(10 - $i);
+ }
+ }
+ $check = 11 - $check % 11;
+ if ($check === 10) {
+ $check = 'X';
+ } elseif ($check === 11) {
+ $check = 0;
+ }
- return 0 === $checkSum % 11 ? true : false;
+ return ($check == $isbn{$len - 1});
+ }
+
+ return false;
}
/**
@@ -139,15 +155,25 @@ class Isbn
* @return bool true if valid ISBN-13
*/
static function isIsbn13 ($isbn) {
- $checksum = 0;
- for ($i = 0; $i < 13; $i +=2) {
- $checksum += $isbn{$i};
- }
- for ($i = 1; $i < 12; $i +=2) {
- $checksum += $isbn{$i} * 3;
- }
+ $len = strlen($isbn);
+ if ($len == 13) {
+ //Calculate check digit
+ $check = 0;
+ for ($i = 0; $i < 12; $i += 2) {
+ $check += substr($isbn, $i, 1);
+ }
+ for ($i = 1; $i < 12; $i += 2) {
+ $check += 3 * substr($isbn, $i, 1);
+ }
+ $check = 10 - $check % 10;
+ if ($check === 10) {
+ $check = 0;
+ }
- return 0 === $checkSum % 10 ? true : false;
+ return ($check == $isbn{$len - 1});
+ }
+
+ return false;
}
}
diff --git a/files_opds/lib/meta.php b/files_opds/lib/meta.php
index 1ebdca8..c0f87f8 100644
--- a/files_opds/lib/meta.php
+++ b/files_opds/lib/meta.php
@@ -119,7 +119,7 @@ class Meta
* @return array of metadata
*/
public static function get($id) {
- if (!($meta = self::load($id)) || (isset($meta['rescan']) && time() > $meta['rescan'])) {
+ if (!($meta = self::load($id)) || (isset($meta['rescan']) && time() > strtotime($meta['rescan']))) {
if(isset($meta['rescan'])) {
$meta['rescan'] = null;
}