From 17bd7a7572b3e74d6cb9772732f1a01e6a17ce47 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Mon, 18 Nov 2013 14:33:43 +0100 Subject: [PATCH] Added support for OpenGraph - Linking to index and individual posts produces thumbs on sites like Facebook - Thumbnails theoretically support custom sizes --- lib/chibi-core | 2 +- src/Controllers/IndexController.php | 1 + src/Controllers/PostController.php | 12 ++++++++---- src/Views/layout-normal.phtml | 19 +++++++++++++------ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/chibi-core b/lib/chibi-core index 5008621b..59f80280 160000 --- a/lib/chibi-core +++ b/lib/chibi-core @@ -1 +1 @@ -Subproject commit 5008621b75431073ca8dd6537a112c9f95436e54 +Subproject commit 59f80280ba23420b891d7a9a6ee05bbb30b64b0c diff --git a/src/Controllers/IndexController.php b/src/Controllers/IndexController.php index a360f305..399d5f38 100644 --- a/src/Controllers/IndexController.php +++ b/src/Controllers/IndexController.php @@ -41,6 +41,7 @@ class IndexController $this->context->featuredPost = $featuredPost; $this->context->featuredPostUser = $featuredPostUser; $this->context->featuredPostDate = $featuredPostDate; + $this->context->pageThumb = \Chibi\UrlHelper::route('post', 'thumb', ['name' => $featuredPost->name]); } } diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index f9521066..3b860e86 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -733,6 +733,7 @@ class PostController $flagged = in_array(TextHelper::reprPost($post), SessionHelper::get('flagged', [])); + $this->context->pageThumb = \Chibi\UrlHelper::route('post', 'thumb', ['name' => $post->name]); $this->context->stylesheets []= 'post-view.css'; $this->context->stylesheets []= 'comment-small.css'; $this->context->scripts []= 'post-view.js'; @@ -752,13 +753,18 @@ class PostController * Action that renders the thumbnail of the requested file and sends it to user. * @route /post/{name}/thumb */ - public function thumbAction($name) + public function thumbAction($name, $width = null, $height = null) { + $dstWidth = $width === null ? $this->config->browsing->thumbWidth : $width; + $dstHeight = $height === null ? $this->config->browsing->thumbHeight : $height; + $dstWidth = min(1000, max(1, $dstWidth)); + $dstHeight = min(1000, max(1, $dstHeight)); + $this->context->layoutName = 'layout-file'; $path = $this->config->main->thumbsPath . DS . $name . '.custom'; if (!file_exists($path)) - $path = $this->config->main->thumbsPath . DS . $name . '.default'; + $path = $this->config->main->thumbsPath . DS . $name . '-' . $dstWidth . 'x' . $dstHeight . '.default'; if (!file_exists($path)) { $post = Model_Post::locate($name); @@ -766,8 +772,6 @@ class PostController PrivilegesHelper::confirmWithException(Privilege::ListPosts); PrivilegesHelper::confirmWithException(Privilege::ListPosts, PostSafety::toString($post->safety)); $srcPath = $this->config->main->filesPath . DS . $post->name; - $dstWidth = $this->config->browsing->thumbWidth; - $dstHeight = $this->config->browsing->thumbHeight; if ($post->type == PostType::Youtube) { diff --git a/src/Views/layout-normal.phtml b/src/Views/layout-normal.phtml index 4e259005..b4078de8 100644 --- a/src/Views/layout-normal.phtml +++ b/src/Views/layout-normal.phtml @@ -2,18 +2,25 @@ - context->subTitle)): ?> - <?php printf('%s – %s', $this->context->title, $this->context->subTitle) ?> - - <?php echo $this->context->title ?> - + context->subTitle) + ? sprintf('%s – %s', $this->context->title, $this->context->subTitle) + : $this->context->title + ?> + <?php echo $title ?> context->stylesheets) as $name): ?> context->scripts) as $name): ?> - + + + + + context->pageThumb)): ?> + +