This commit is contained in:
Marcin Kurczewski 2013-10-14 10:22:53 +02:00
parent c6cdc1d945
commit 23f430f41c
8 changed files with 206 additions and 7 deletions

View file

@ -42,7 +42,6 @@ listPosts=anonymous
listPosts.sketchy=registered
listPosts.unsafe=registered
listPosts.hidden=nobody
listUsers=registered
viewPost=anonymous
viewPost.sketchy=registered
viewPost.unsafe=registered
@ -59,5 +58,7 @@ hidePost.own=moderator
hidePost.all=moderator
deletePost.own=moderator
deletePost.all=moderator
listUsers=registered
viewUser=registered
listComments=anonymous
listTags=anonymous

View file

@ -0,0 +1,33 @@
#sidebar {
width: 200px;
}
.details .key {
margin-right: 0.5em;
}
.tabs ul {
list-style-type: none;
margin: 0 0 1em 0;
padding: 0;
border-bottom: 1px solid #eee;
}
.tabs li {
display: inline-block;
}
.tabs li a {
display: inline-block;
padding: 0.5em 1em;
margin-bottom: -1px;
}
.tabs li.active a {
border: 1px solid #eee;
border-bottom: 1px solid white;
}
.tabs li.inactive a {
border: 1px solid white;
border-bottom: 1px solid #eee;
color: silver;
}

View file

@ -136,6 +136,7 @@ class AuthController
$dbUser->pass_salt = md5(mt_rand() . uniqid());
$dbUser->pass_hash = self::hashPassword($suppliedPass1, $dbUser->pass_salt);
$dbUser->email = $suppliedEmail;
$dbUser->join_date = time();
$dbUser->staff_confirmed = $staffActivation ? false : true;
$dbUser->email_confirmed = $emailActivation ? false : true;
$dbUser->access_rank = R::findOne('user') === null ? AccessRank::Admin : AccessRank::Registered;

View file

@ -262,7 +262,7 @@ class PostController
};
$countDbQuery = R::$f->begin();
$countDbQuery->select('COUNT(1) AS count');
$countDbQuery->select('COUNT(1)')->as('count');
$buildDbQuery($countDbQuery, $query);
$postCount = intval($countDbQuery->get('row')['count']);
$pageCount = ceil($postCount / $postsPerPage);

View file

@ -1,6 +1,16 @@
<?php
class UserController
{
private static function locateUser($key)
{
$user = R::findOne('user', 'name = ?', [$key]);
if (!$user)
throw new SimpleException('Invalid user name "' . $key . '"');
return $user;
}
/**
* @route /users
*/
@ -10,16 +20,101 @@ class UserController
throw new SimpleException('Not implemented');
}
/**
* @route /user/{name}
* @route /user/{name}/{tab}/{page}
* @validate name [^\/]+
* @validate tab favs|uploads
* @validate page \d*
*/
public function viewAction($name)
public function viewAction($name, $tab, $page)
{
$this->context->stylesheets []= 'user-view.css';
$this->context->stylesheets []= 'post-list.css';
$this->context->stylesheets []= 'paginator.css';
if ($this->config->browsing->endlessScrolling)
$this->context->scripts []= 'paginator-endless.js';
$this->context->subTitle = $name;
throw new SimpleException('Not implemented');
PrivilegesHelper::confirmWithException($this->context->user, Privilege::ViewUser);
$postsPerPage = intval($this->config->browsing->postsPerPage);
$user = self::locateUser($name);
if ($tab === null)
$tab = 'favs';
if ($page === null)
$page = 1;
$buildDbQuery = function($dbQuery, $user, $tab)
{
$dbQuery->from('post');
/* safety */
$allowedSafety = array_filter(PostSafety::getAll(), function($safety)
{
return PrivilegesHelper::confirm($this->context->user, Privilege::ListPosts, PostSafety::toString($safety)) and
$this->context->user->hasEnabledSafety($safety);
});
$dbQuery->where('safety IN (' . R::genSlots($allowedSafety) . ')');
foreach ($allowedSafety as $s)
$dbQuery->put($s);
/* hidden */
if (!PrivilegesHelper::confirm($this->context->user, Privilege::ListPosts, 'hidden'))
$dbQuery->andNot('hidden');
/* tab */
switch ($tab)
{
case 'uploads':
$dbQuery
->and('uploader_id = ?')
->put($user->id);
break;
case 'favs':
$dbQuery
->and()
->exists()
->open()
->select('1')
->from('favoritee')
->where('post_id = post.id')
->and('favoritee.user_id = ?')
->put($user->id)
->close();
break;
}
};
$countDbQuery = R::$f->begin()->select('COUNT(*)')->as('count');
$buildDbQuery($countDbQuery, $user, $tab);
$postCount = intval($countDbQuery->get('row')['count']);
$pageCount = ceil($postCount / $postsPerPage);
$page = max(1, min($pageCount, $page));
$searchDbQuery = R::$f->begin()->select('*');
$buildDbQuery($searchDbQuery, $user, $tab);
$searchDbQuery->orderBy('id DESC')
->limit('?')
->put($postsPerPage)
->offset('?')
->put(($page - 1) * $postsPerPage);
$posts = $searchDbQuery->get();
$this->context->transport->user = $user;
$this->context->transport->tab = $tab;
$this->context->transport->page = $page;
$this->context->transport->postCount = $postCount;
$this->context->transport->pageCount = $pageCount;
$this->context->transport->posts = $posts;
}
/**
* @route /user/toggle-safety/{safety}
*/

View file

@ -13,6 +13,8 @@ class Privilege extends Enum
const DeletePost = 10;
const ListUsers = 11;
const ListComments = 12;
const ListTags = 13;
const ViewUser = 12;
const ListComments = 13;
const ListTags = 14;
}

View file

@ -52,7 +52,7 @@
<div class="uploader">
<span class="key">Uploader:</span>
<span class="value">
<a href="<?php echo \Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->transport->post->uploader->id]) ?>">
<a href="<?php echo \Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->transport->post->uploader->name]) ?>">
<?php echo $this->context->transport->post->uploader->name ?>
</a>
</span>

67
src/Views/user-view.phtml Normal file
View file

@ -0,0 +1,67 @@
<div id="sidebar">
<div class="avatar-wrapper">
<a href="<?php echo \Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->transport->user->name]) ?>">
<img src="<?php echo $this->context->transport->user->getAvatarUrl(140) ?>" alt="<?php echo $this->context->transport->user->name ?>">
</a>
<h1><?php echo $this->context->transport->user->name ?></h1>
</div>
<div class="sidebar-unit details">
<div class="join-date">
<span class="key">Joined:</span>
<span class="value"><?php echo date('Y-m-d', $this->context->transport->user->join_date) ?></span>
</div>
<div class="access-rank">
<span class="key">Access rank:</span>
<span class="value"><?php echo strtolower(AccessRank::toString($this->context->transport->user->access_rank)) ?></span>
</div>
</div>
</div>
<div id="inner-content">
<div class="tabs">
<nav>
<ul>
<?php if ($this->context->transport->tab == 'favs'): ?>
<li class="active">
<?php else: ?>
<li class="inactive">
<?php endif ?>
<a href="<?php echo \Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->transport->user->name, 'tab' => 'favs', 'page' => 1]) ?>">
Favs
</a>
</li>
<?php if ($this->context->transport->tab == 'uploads'): ?>
<li class="active">
<?php else: ?>
<li class="inactive">
<?php endif ?>
<a href="<?php echo \Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->transport->user->name, 'tab' => 'uploads', 'page' => 1]) ?>">
Uploads
</a>
</li>
</ul>
</nav>
</div>
<?php
/* heh, what a stupid hack */
function pageUrl($page)
{
$context = \Chibi\Registry::getContext();
$controller = $context->route->simpleControllerName;
$action = $context->route->simpleActionName;
$page = max(1, $page);
$page = min($context->transport->pageCount, $page);
$params = [];
$params['page'] = $page;
$params['tab'] = $context->transport->tab;
$params['name'] = $context->transport->user->name;
return \Chibi\UrlHelper::route($controller, $action, $params);
}
?>
<?php $this->renderFile('post-list') ?>
</div>