diff --git a/src/Bootstrap.php b/src/Bootstrap.php index bafdc3b1..ef68c7cc 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -6,7 +6,12 @@ class Bootstrap $this->context->loggedIn = false; if (isset($_SESSION['user-id'])) { - $this->context->user = R::findOne('user', 'id = ?', [$_SESSION['user-id']]); + if (!isset($_SESSION['user'])) + { + $dbUser = R::findOne('user', 'id = ?', [$_SESSION['user-id']]); + $_SESSION['user'] = serialize($dbUser); + } + $this->context->user = unserialize($_SESSION['user']); if (!empty($this->context->user)) { $this->context->loggedIn = true; diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index 5163f889..d07b60b4 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -23,6 +23,7 @@ class AuthController PrivilegesHelper::confirmEmail($dbUser); $_SESSION['user-id'] = $dbUser->id; + $_SESSION['user'] = serialize($dbUser); \Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index')); return $dbUser; } diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 2f8917c3..9656e5ed 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -557,19 +557,19 @@ class PostController /** * Action that renders the thumbnail of the requested file and sends it to user. - * @route /post/{id}/thumb + * @route /post/{name}/thumb */ - public function thumbAction($id) + public function thumbAction($name) { $this->context->layoutName = 'layout-file'; - $post = Model_Post::locate($id); - PrivilegesHelper::confirmWithException(Privilege::ViewPost); - PrivilegesHelper::confirmWithException(Privilege::ViewPost, PostSafety::toString($post->safety)); - - $path = $this->config->main->thumbsPath . DS . $post->name; + $path = $this->config->main->thumbsPath . DS . $name; if (!file_exists($path)) { + $post = Model_Post::locate($id); + + PrivilegesHelper::confirmWithException(Privilege::ViewPost); + PrivilegesHelper::confirmWithException(Privilege::ViewPost, PostSafety::toString($post->safety)); $srcPath = $this->config->main->filesPath . DS . $post->name; $dstPath = $path; $dstWidth = $this->config->browsing->thumbWidth; @@ -623,17 +623,17 @@ class PostController { $path = $this->config->main->mediaPath . DS . 'img' . DS . 'thumb.png'; } + + if (isset($tmpPath)) + unlink($tmpPath); } if (!is_readable($path)) throw new SimpleException('Thumbnail file is not readable'); $this->context->transport->cacheDaysToLive = 30; $this->context->transport->mimeType = 'image/png'; - $this->context->transport->fileHash = 'thumb' . md5($post->file_hash . filemtime($path)); + $this->context->transport->fileHash = 'thumb' . md5($name . filemtime($path)); $this->context->transport->filePath = $path; - - if (isset($tmpPath)) - unlink($tmpPath); } diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index 4ba2a7cd..d19b9c13 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -246,7 +246,10 @@ class UserController R::store($user); $this->context->transport->user = $user; if ($this->context->user->id == $user->id) + { $this->context->user = $user; + unset($_SESSION['user']); + } $this->context->transport->success = true; } } diff --git a/src/Views/post-small.phtml b/src/Views/post-small.phtml index bd58bc45..6b2280f7 100644 --- a/src/Views/post-small.phtml +++ b/src/Views/post-small.phtml @@ -1,6 +1,6 @@
- @<?php echo $this->context->post->id ?> + @<?php echo $this->context->post->id ?>
context->post->countOwn('comment') ?>