konyvleltar/web/store.inc
2021-12-20 12:50:53 +01:00

52 lines
1.4 KiB
PHP

<?php
include ('../vendor/autoload.php');
use Biblys\Isbn\Isbn;
class Store{
const DATAFILE = '/opt/konyvleltar/data/isbn.txt';
const ERRORFILE = '/opt/konyvleltar/data/isbn-error.txt';
public static function save($v,$manual=false){
if (Isbn::isParsable($v)){
$outputfile = self::DATAFILE;
$ret = 'OK';
}else{
$outputfile = self::ERRORFILE;
$ret = 'ERROR';
}
$o = self::sanitize($v);
file_put_contents($outputfile,$o."\n",FILE_APPEND);
if ($manual) { header("Location: /index.php?ret=$ret");}
else { print $ret;}
}
public static function sanitize($string){
$sx = preg_replace("/\.$/", "X", $string);
return preg_replace("/[^a-zA-Z0-9-]/", "", $sx);
}
}
class StoreMoly extends Store{
const DATAFILE = '/opt/konyvleltar/data/moly.txt';
const ERRORFILE = '/opt/konyvleltar/data/moly-error.txt';
public static function save($v,$manual=false){
$outputfile = self::DATAFILE;
$ret = 'OK';
$o = self::sanitize($v);
file_put_contents($outputfile,$o."\n",FILE_APPEND);
if ($manual) { header("Location: /index.php?ret=$ret");}
else { print $ret;}
}
public static function sanitize($string){
$sx = preg_replace("/\.$/", "X", $string);
return preg_replace("/[^a-zA-Z0-9-]/", "", $sx);
}
}