2013-10-05 19:24:08 +02:00
|
|
|
<?php
|
2013-10-05 21:24:20 +02:00
|
|
|
class IndexController
|
2013-10-05 19:24:08 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @route /
|
|
|
|
* @route /index
|
|
|
|
*/
|
2013-10-05 21:22:28 +02:00
|
|
|
public function indexAction()
|
2013-10-05 19:24:08 +02:00
|
|
|
{
|
2013-10-05 21:22:28 +02:00
|
|
|
$this->context->subTitle = 'home';
|
2013-10-19 13:38:20 +02:00
|
|
|
$this->context->stylesheets []= 'index-index.css';
|
|
|
|
$this->context->transport->postCount = R::$f->begin()->select('count(1)')->as('count')->from('post')->get('row')['count'];
|
|
|
|
|
2013-11-10 11:18:00 +01:00
|
|
|
$featuredPostRotationTime = $this->config->misc->featuredPostMaxDays * 24 * 3600;
|
2013-10-19 13:38:20 +02:00
|
|
|
|
|
|
|
$featuredPostId = Model_Property::get(Model_Property::FeaturedPostId);
|
|
|
|
$featuredPostUserId = Model_Property::get(Model_Property::FeaturedPostUserId);
|
|
|
|
$featuredPostDate = Model_Property::get(Model_Property::FeaturedPostDate);
|
|
|
|
if (!$featuredPostId or $featuredPostDate + $featuredPostRotationTime < time())
|
|
|
|
{
|
|
|
|
$featuredPostId = R::$f->begin()
|
|
|
|
->select('id')
|
|
|
|
->from('post')
|
|
|
|
->where('type = ?')->put(PostType::Image)
|
|
|
|
->and('safety = ?')->put(PostSafety::Safe)
|
|
|
|
->orderBy('random()')
|
|
|
|
->desc()
|
|
|
|
->get('row')['id'];
|
|
|
|
$featuredPostUserId = null;
|
|
|
|
$featuredPostDate = time();
|
|
|
|
Model_Property::set(Model_Property::FeaturedPostId, $featuredPostId);
|
|
|
|
Model_Property::set(Model_Property::FeaturedPostUserId, $featuredPostUserId);
|
|
|
|
Model_Property::set(Model_Property::FeaturedPostDate, $featuredPostDate);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($featuredPostId !== null)
|
|
|
|
{
|
|
|
|
$featuredPost = Model_Post::locate($featuredPostId);
|
|
|
|
R::preload($featuredPost, ['user', 'comment', 'favoritee']);
|
|
|
|
$featuredPostUser = R::findOne('user', 'id = ?', [$featuredPostUserId]);
|
|
|
|
$this->context->featuredPost = $featuredPost;
|
|
|
|
$this->context->featuredPostUser = $featuredPostUser;
|
|
|
|
$this->context->featuredPostDate = $featuredPostDate;
|
2013-11-18 14:33:43 +01:00
|
|
|
$this->context->pageThumb = \Chibi\UrlHelper::route('post', 'thumb', ['name' => $featuredPost->name]);
|
2013-10-19 13:38:20 +02:00
|
|
|
}
|
2013-10-05 19:24:08 +02:00
|
|
|
}
|
2013-10-07 20:44:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @route /help
|
2013-11-21 15:16:27 +01:00
|
|
|
* @route /help/{tab}
|
2013-10-07 20:44:14 +02:00
|
|
|
*/
|
2013-11-21 15:16:27 +01:00
|
|
|
public function helpAction($tab = null)
|
2013-10-07 20:44:14 +02:00
|
|
|
{
|
2013-11-21 15:16:27 +01:00
|
|
|
if (empty($this->config->help->paths) or empty($this->config->help->title))
|
|
|
|
throw new SimpleException('Help is disabled');
|
|
|
|
$tab = $tab ?: array_keys($this->config->help->subTitles)[0];
|
|
|
|
if (!isset($this->config->help->paths[$tab]))
|
|
|
|
throw new SimpleException('Invalid tab');
|
|
|
|
$this->context->path = $this->config->help->paths[$tab];
|
2013-10-25 17:20:11 +02:00
|
|
|
$this->context->stylesheets []= 'index-help.css';
|
2013-11-21 15:16:27 +01:00
|
|
|
$this->context->stylesheets []= 'tabs.css';
|
2013-10-07 20:44:14 +02:00
|
|
|
$this->context->subTitle = 'help';
|
2013-11-21 15:16:27 +01:00
|
|
|
$this->context->tab = $tab;
|
2013-10-07 20:44:14 +02:00
|
|
|
}
|
2013-10-05 19:24:08 +02:00
|
|
|
}
|