Added support for OpenGraph

- Linking to index and individual posts produces thumbs on sites like Facebook
- Thumbnails theoretically support custom sizes
This commit is contained in:
Marcin Kurczewski 2013-11-18 14:33:43 +01:00
parent a5d0a3f9ef
commit 17bd7a7572
4 changed files with 23 additions and 11 deletions

@ -1 +1 @@
Subproject commit 5008621b75431073ca8dd6537a112c9f95436e54
Subproject commit 59f80280ba23420b891d7a9a6ee05bbb30b64b0c

View file

@ -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]);
}
}

View file

@ -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)
{

View file

@ -2,18 +2,25 @@
<html>
<head>
<meta charset="utf-8"/>
<?php if (isset($this->context->subTitle)): ?>
<title><?php printf('%s&nbsp;&ndash;&nbsp;%s', $this->context->title, $this->context->subTitle) ?></title>
<?php else: ?>
<title><?php echo $this->context->title ?></title>
<?php endif ?>
<?php
$title = isset($this->context->subTitle)
? sprintf('%s&nbsp;&ndash;&nbsp;%s', $this->context->title, $this->context->subTitle)
: $this->context->title
?>
<title><?php echo $title ?></title>
<?php foreach (array_unique($this->context->stylesheets) as $name): ?>
<link rel="stylesheet" type="text/css" href="<?php echo \Chibi\UrlHelper::absoluteUrl('/media/css/' . $name) ?>"/>
<?php endforeach ?>
<?php foreach (array_unique($this->context->scripts) as $name): ?>
<script type="text/javascript" src="<?php echo \Chibi\UrlHelper::absoluteUrl('/media/js/' . $name) ?>"></script>
<?php endforeach ?>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"/>
<meta property="og:title" content="<?php echo $title ?>"/>
<meta property="og:url" content="<?php echo \Chibi\UrlHelper::currentUrl() ?>"/>
<?php if (!empty($this->context->pageThumb)): ?>
<meta property="og:image" content="<?php echo $this->context->pageThumb ?>"/>
<?php endif ?>
</head>
<body>