diff --git a/Lib/Logger.php b/Lib/Logger.php index 1b1f4d6..23068e7 100644 --- a/Lib/Logger.php +++ b/Lib/Logger.php @@ -87,4 +87,38 @@ class Logger { public static function data() { return self::$data; } -} \ No newline at end of file + + public static function getLastLogs($offset = null) { + $file = Configuration::get('log.file'); + if(! file_exists($file)) { + return 'No log yet !'; + } + + $f = fopen($file, 'r'); + + $len = 1024; + + fseek($f, 0, SEEK_END); + $size = ftell($f); + if(is_null($offset) || $offset > $size) { + $offset = $size - $len; + } + $offset = max(0, $offset); + + fseek($f, $offset); + + // remove the first line that may be incomplete + $buffer = fread($f, $len); + $buffer = explode("\n", $buffer); + array_shift($buffer); + $buffer = implode("\n", $buffer); + // continue reading until the end of the file + while(! feof($f)) { + $buffer .= fread($f, $len); + } + + fclose($f); + + return $buffer; + } +} diff --git a/Lib/autoloader.php b/Lib/autoloader.php new file mode 100644 index 0000000..4e59e59 --- /dev/null +++ b/Lib/autoloader.php @@ -0,0 +1,17 @@ +CheckSession(); - return reset($this->AddBookData(BookSearch::GetBooks(array($code)))); + $books = $this->AddBookData(BookSearch::GetBooks(array($code))); + return reset($books); } /** diff --git a/index.php b/index.php index 52d5653..1158010 100644 --- a/index.php +++ b/index.php @@ -2,20 +2,7 @@ namespace BSR; -ini_set('display_errors', 'On'); - -// register an autoloader to automatically load classes -// the namespace for the class must begin with BSR and -// otherwise respect the PSR-4 standard -spl_autoload_register(function ($class) { - $class = substr($class, strlen('BSR')); - $path = sprintf('%s/%s.php', __DIR__, str_replace('\\', '/', $class)); - - if (file_exists($path)) { - /** @noinspection PhpIncludeInspection */ - require $path; - } -}); +require_once('Lib/autoloader.php'); $web = new NetBiblio(); $web->Run(); diff --git a/logs.php b/logs.php new file mode 100644 index 0000000..8ebbe03 --- /dev/null +++ b/logs.php @@ -0,0 +1,15 @@ + 'Logs', + 'content' => "
$logs
", +)); diff --git a/templates/layout.html b/templates/layout.html index 40bbeb6..f680de0 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -23,7 +23,8 @@