diff --git a/.gitignore b/.gitignore index bacb72d..51fc87a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ vendor/simplepie/* #temp files cache/* test.php +newssync.db* # Windows image file caches Thumbs.db diff --git a/bootstrap.php b/bootstrap.php index 0168e83..df0e023 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -5,6 +5,8 @@ namespace JKingWeb\NewsSync; const BASE = __DIR__.DIRECTORY_SEPARATOR; const NS_BASE = __NAMESPACE__."\\"; +if(!defined(NS_BASE."INSTALL")) define(NS_BASE."INSTALL", false); + spl_autoload_register(function ($class) { if($class=="SimplePie") return; $file = str_replace("\\", DIRECTORY_SEPARATOR, $class); @@ -14,4 +16,4 @@ spl_autoload_register(function ($class) { } }); -$conf = new Conf(); \ No newline at end of file +$data = new RuntimeData(new Conf()); \ No newline at end of file diff --git a/locale/en.php b/locale/en.php index 1a7e7dc..06d2b5b 100644 --- a/locale/en.php +++ b/locale/en.php @@ -5,4 +5,18 @@ return [ "Exception.JKingWeb/NewsSync/Lang/Exception.fileUnreadable" => "Insufficient permissions to read language file \"{0}\"", "Exception.JKingWeb/NewsSync/Lang/Exception.fileCorrupt" => "Language file \"{0}\" is corrupt or does not conform to expected format", "Exception.JKingWeb/NewsSync/Lang/Exception.stringMissing" => "Message string \"{msgID}\" missing from all loaded language files ({fileList})", + + "Exception.JKingWeb/NewsSync/Conf/Exception.fileMissing" => "Configuration file \"{0}\" does not exist", + "Exception.JKingWeb/NewsSync/Conf/Exception.fileUnreadable" => "Insufficient permissions to read configuration file \"{0}\"", + "Exception.JKingWeb/NewsSync/Conf/Exception.fileUncreatable" => "Insufficient permissions to write new configuration file \"{0}\"", + "Exception.JKingWeb/NewsSync/Conf/Exception.fileUnwritable" => "Insufficient permissions to overwrite configuration file \"{0}\"", + "Exception.JKingWeb/NewsSync/Conf/Exception.fileCorrupt" => "Configuration file \"{0}\" is corrupt or does not conform to expected format", + + "Exception.JKingWeb/NewsSync/Db/Exception.extMissing" => "Required PHP extension for driver \"{0}\" not installed", + "Exception.JKingWeb/NewsSync/Db/Exception.fileMissing" => "Database file \"{0}\" does not exist", + "Exception.JKingWeb/NewsSync/Db/Exception.fileUnreadable" => "Insufficient permissions to open database file \"{0}\" for reading", + "Exception.JKingWeb/NewsSync/Db/Exception.fileUnwritable" => "Insufficient permissions to open database file \"{0}\" for writing", + "Exception.JKingWeb/NewsSync/Db/Exception.fileUnusable" => "Insufficient permissions to open database file \"{0}\" for reading or writing", + "Exception.JKingWeb/NewsSync/Db/Exception.fileUncreatable" => "Insufficient permissions to create new database file \"{0}\"", + "Exception.JKingWeb/NewsSync/Db/Exception.fileCorrupt" => "Database file \"{0}\" is corrupt or not a valid database", ]; \ No newline at end of file diff --git a/vendor/JKingWeb/NewsSync/Auth/DriverInternal.php b/vendor/JKingWeb/NewsSync/Auth/DriverInternal.php index e1760ab..62f06be 100644 --- a/vendor/JKingWeb/NewsSync/Auth/DriverInternal.php +++ b/vendor/JKingWeb/NewsSync/Auth/DriverInternal.php @@ -1,7 +1,6 @@ import_file($import_file); + if($import_file != "") $this->importFile($import_file); } public function importFile(string $file): self { if(!file_exists($file)) throw new Conf\Exception("fileMissing"); if(!is_readable($file)) throw new Conf\Exception("fileUnreadable"); - $json = @file_get_contents($file); - if($json===false) throw new Conf\Exception("fileUnreadable"); - return $this->import($json); + $arr = (@include $file); + if(!is_array($arr)) throw new Conf\Exception("fileCorrupt"); + return $this->import($arr); } - public function import(string $json): self { - if($json=="") throw new Conf\Exception("blank"); - $json = json_decode($json, true); - if(!is_array($json)) throw new Conf\Exception("corrupt"); - foreach($json as $key => $value) { + public function import(array $arr): self { + foreach($arr as $key => $value) { $this->$$key = $value; } return $this; - } public function export(string $file = ""): string { - return json_encode($this, JSON_PRETTY_PRINT); + // TODO } public function __toString(): string { diff --git a/vendor/JKingWeb/NewsSync/Database.php b/vendor/JKingWeb/NewsSync/Database.php new file mode 100644 index 0000000..7b897ed --- /dev/null +++ b/vendor/JKingWeb/NewsSync/Database.php @@ -0,0 +1,15 @@ +dbClass; + $this->drv = new $driver($conf); + } + + static public function listDrivers() { + + } +} \ No newline at end of file diff --git a/vendor/JKingWeb/NewsSync/Db/DriverInterface.php b/vendor/JKingWeb/NewsSync/Db/DriverInterface.php new file mode 100644 index 0000000..27de3f9 --- /dev/null +++ b/vendor/JKingWeb/NewsSync/Db/DriverInterface.php @@ -0,0 +1,7 @@ +pdo = false; + } else if(class_exists("PDO") && in_array("sqlite",\PDO::getAvailableDrivers())) { + $this->pdo = true; + } else { + throw new Exception("extMissing", self::driverName()); + } + // if the file exists (or we're initializing the database), try to open it and set initial options + if((!$install && file_exists($conf->dbSQLite3File)) || $install) { + try { + $this->db = ($this->PDO) ? (new \SQLite3($conf->dbSQLite3File, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $conf->dbSQLite3Key)) : (new PDO("sqlite:".$conf->dbSQLite3File)); + //FIXME: add foreign key enforcement, WAL mode + } catch(\Throwable $e) { + // if opening the database doesn't work, check various pre-conditions to find out what the problem might be + foreach([$conf->dbSQLite3File, $conf->dbSQLite3File."-wal", $conf->dbSQLite3File."-shm"] as $file) { + if(!file_exists($file)) { + if($install && !is_writable(dirname($file))) throw new Exception("fileUncreatable", dirname($file)); + throw new Exception("fileMissing", $file); + } + if(!is_readable($file) && !is_writable($file)) throw new Exception("fileUnusable", $file); + if(!is_readable($file)) throw new Exception("fileUnreadable", $file); + if(!is_writable($file)) throw new Exception("fileUnwritable", $file); + } + // otherwise the database is probably corrupt + throw new Exception("fileCorrupt", $conf->dbSQLite3File); + } + } else { + throw new Exception("fileMissing", $conf->dbSQLite3File); + } + } + + static public function driverName(): string { + return "SQLite3"; + } +} \ No newline at end of file diff --git a/vendor/JKingWeb/NewsSync/Db/Exception.php b/vendor/JKingWeb/NewsSync/Db/Exception.php new file mode 100644 index 0000000..bf4dea1 --- /dev/null +++ b/vendor/JKingWeb/NewsSync/Db/Exception.php @@ -0,0 +1,6 @@ +conf = $conf; - //$this->db = new Database($this); + Lang::set($conf->lang); + $this->db = new Database($this->conf); //$this->auth = new Authenticator($this); } } \ No newline at end of file