Renamed IndexController class and methods

This commit is contained in:
Marcin Kurczewski 2014-05-02 22:30:14 +02:00
parent e857032a73
commit aeb73e2a5c
10 changed files with 24 additions and 18 deletions

View file

@ -45,6 +45,11 @@ $context->simpleActionName = null;
$context->simpleActionName);
});
\Chibi\Router::register(['StaticPagesController', 'mainPageView'], 'GET', '');
\Chibi\Router::register(['StaticPagesController', 'mainPageView'], 'GET', '/index');
\Chibi\Router::register(['StaticPagesController', 'helpView'], 'GET', '/help');
\Chibi\Router::register(['StaticPagesController', 'helpView'], 'GET', '/help/{tab}');
\Chibi\Router::register(['AuthController', 'loginView'], 'GET', '/auth/login');
\Chibi\Router::register(['AuthController', 'loginAction'], 'POST', '/auth/login');
\Chibi\Router::register(['AuthController', 'logoutAction'], 'POST', '/auth/logout');
@ -81,10 +86,6 @@ $postValidation =
foreach (['GET', 'POST'] as $method)
{
\Chibi\Router::register(['IndexController', 'indexAction'], $method, '');
\Chibi\Router::register(['IndexController', 'indexAction'], $method, '/index');
\Chibi\Router::register(['IndexController', 'helpAction'], $method, '/help');
\Chibi\Router::register(['IndexController', 'helpAction'], $method, '/help/{tab}');
\Chibi\Router::register(['LogController', 'listAction'], $method, '/logs');
\Chibi\Router::register(['LogController', 'viewAction'], $method, '/log/{name}', ['name' => '[0-9a-zA-Z._-]+']);
\Chibi\Router::register(['LogController', 'viewAction'], $method, '/log/{name}/{page}', ['name' => '[0-9a-zA-Z._-]+', 'page' => '\d*']);

View file

@ -46,6 +46,6 @@ class AuthController
unset($_SESSION['login-redirect-url']);
return;
}
\Chibi\Util\Url::forward(\Chibi\Router::linkTo(['IndexController', 'indexAction']));
\Chibi\Util\Url::forward(\Chibi\Router::linkTo(['StaticPagesController', 'mainPageView']));
}
}

View file

@ -1,10 +1,11 @@
<?php
class IndexController
class StaticPagesController
{
public function indexAction()
public function mainPageView()
{
$context = getContext();
$context->transport->postCount = PostModel::getCount();
$context->viewName = 'static-main';
$featuredPost = $this->getFeaturedPost();
if ($featuredPost)
@ -17,15 +18,19 @@ class IndexController
}
}
public function helpAction($tab = null)
public function helpView($tab = null)
{
$config = getConfig();
$context = getContext();
if (empty($config->help->paths) or empty($config->help->title))
throw new SimpleException('Help is disabled');
$tab = $tab ?: array_keys($config->help->subTitles)[0];
if (!isset($config->help->paths[$tab]))
throw new SimpleException('Invalid tab');
$context->viewName = 'static-help';
$context->path = TextHelper::absolutePath($config->help->paths[$tab]);
$context->tab = $tab;
}

View file

@ -126,7 +126,7 @@ class UserController
if ($oldId == Auth::getCurrentUser()->id)
Auth::logOut();
\Chibi\Util\Url::forward(\Chibi\Router::linkTo(['IndexController', 'indexAction']));
\Chibi\Util\Url::forward(\Chibi\Router::linkTo(['StaticPagesController', 'mainPageView']));
LogHelper::log('{user} removed {subject}\'s account', ['subject' => TextHelper::reprUser($name)]);
}
@ -347,7 +347,7 @@ class UserController
//check if already logged in
if (Auth::isLoggedIn())
{
\Chibi\Util\Url::forward(\Chibi\Router::linkTo(['IndexController', 'indexAction']));
\Chibi\Util\Url::forward(\Chibi\Router::linkTo(['StaticPagesController', 'mainPageView']));
return;
}

View file

@ -283,7 +283,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
['PostController', 'featureAction'],
['id' => $this->context->transport->post->id]),
'data-confirm-text' => 'Are you sure you want to feature this post on the main page?',
'data-redirect-url' => \Chibi\Router::linkTo(['IndexController', 'indexAction']),
'data-redirect-url' => \Chibi\Router::linkTo(['StaticPagesController', 'mainPageView']),
];
}

View file

@ -1,6 +1,6 @@
<?php
Assets::setSubtitle('help');
Assets::addStylesheet('index-help.css');
Assets::addStylesheet('static-help.css');
$tabs = getConfig()->help->subTitles;
$firstTab = !empty($tabs) ? array_keys($tabs)[0] : null;
@ -17,7 +17,7 @@ $showTabs = count($tabs) > 1;
<li class="<?= $tab ?>">
<?php endif ?>
<a href="<?= \Chibi\Router::linkTo(
['IndexController', 'helpAction'],
['StaticPagesController', 'helpView'],
$tab == $firstTab ? [] : ['tab' => $tab]) ?>">
<?= $text ?>
</a>

View file

@ -1,6 +1,6 @@
<?php
Assets::setSubtitle('home');
Assets::addStylesheet('index-index.css');
Assets::addStylesheet('static-main.css');
?>
<div id="welcome">

View file

@ -15,8 +15,8 @@
$registerNavItem(
'Home',
\Chibi\Router::linkTo(['IndexController', 'indexAction']),
$activeController == 'index' and $activeAction == 'index');
\Chibi\Router::linkTo(['StaticPagesController', 'mainPageView']),
$activeController == 'static-pages' and $activeAction == 'main-page');
if (Access::check(Privilege::ListPosts))
{
@ -89,8 +89,8 @@
{
$registerNavItem(
getConfig()->help->title,
\Chibi\Router::linkTo(['IndexController', 'helpAction']),
$activeController == 'index' and $activeAction == 'help');
\Chibi\Router::linkTo(['StaticPagesController', 'helpView']),
$activeController == 'static-pages' and $activeAction == 'help');
}
foreach ($nav as $navItem)