profile page
This commit is contained in:
parent
7e2553646c
commit
740df27069
19 changed files with 201 additions and 44 deletions
|
@ -61,6 +61,7 @@ class Post_controller extends Controller {
|
||||||
$page = $this->request_model->get_int('page', 0);
|
$page = $this->request_model->get_int('page', 0);
|
||||||
$max = $this->request_model->get_int('max');
|
$max = $this->request_model->get_int('max');
|
||||||
$offset = $page * $this->page_size;
|
$offset = $page * $this->page_size;
|
||||||
|
$filter_uid = $this->request_model->get_int('user_id', FALSE);
|
||||||
|
|
||||||
$user = $this->main->user();
|
$user = $this->main->user();
|
||||||
$uid = isset($user) ? $user['id'] : NULL;
|
$uid = isset($user) ? $user['id'] : NULL;
|
||||||
|
@ -78,6 +79,11 @@ class Post_controller extends Controller {
|
||||||
->where('p.id')->le($max);
|
->where('p.id')->le($max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($uid) {
|
||||||
|
$query = $query
|
||||||
|
->where('p.user_id')->eq($uid);
|
||||||
|
}
|
||||||
|
|
||||||
$posts = $query
|
$posts = $query
|
||||||
->order_by('p.id', 'DESC')
|
->order_by('p.id', 'DESC')
|
||||||
->limit($this->page_size)
|
->limit($this->page_size)
|
||||||
|
@ -96,9 +102,16 @@ class Post_controller extends Controller {
|
||||||
$this->view('template/post', $data);
|
$this->view('template/post', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$pc = $this->db
|
$query = $this->db
|
||||||
->select('COUNT(p.id) as pc')
|
->select('COUNT(p.id) as pc')
|
||||||
->from('api.post p')
|
->from('api.post p');
|
||||||
|
|
||||||
|
if ($uid) {
|
||||||
|
$query = $query
|
||||||
|
->where('p.user_id')->eq($uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pc = $query
|
||||||
->row()['pc'];
|
->row()['pc'];
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
@ -106,6 +119,7 @@ class Post_controller extends Controller {
|
||||||
'total' => $pc,
|
'total' => $pc,
|
||||||
'page_size' => $this->page_size,
|
'page_size' => $this->page_size,
|
||||||
'max' => $max,
|
'max' => $max,
|
||||||
|
'filter_uid' => $filter_uid
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
35
src/web/_controller/apps/profile.php
Normal file
35
src/web/_controller/apps/profile.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php /* Copyright (c) 2024 Freya Murphy */
|
||||||
|
class Profile_controller extends Controller {
|
||||||
|
|
||||||
|
// the home model
|
||||||
|
private $profile_model;
|
||||||
|
|
||||||
|
// the format model
|
||||||
|
protected $format_model;
|
||||||
|
|
||||||
|
// the post model
|
||||||
|
protected $post_controller;
|
||||||
|
|
||||||
|
function __construct($load) {
|
||||||
|
parent::__construct($load);
|
||||||
|
$this->profile_model = $this->load->model('apps/profile');
|
||||||
|
$this->format_model = $this->load->model('format');
|
||||||
|
$this->post_controller = $this->load->controller('_util/post');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index(): void {
|
||||||
|
parent::index();
|
||||||
|
$data = $this->profile_model->get_data();
|
||||||
|
|
||||||
|
if (!$data) {
|
||||||
|
$this->error(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->view('header', $data);
|
||||||
|
$this->view('apps/profile/main', $data);
|
||||||
|
$this->view('footer', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -5,7 +5,7 @@ class Auth_model extends Model {
|
||||||
parent::__construct($load);
|
parent::__construct($load);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_data(): array {
|
public function get_data(): ?array {
|
||||||
$data = parent::get_data();
|
$data = parent::get_data();
|
||||||
$data['title'] = lang('login');
|
$data['title'] = lang('login');
|
||||||
return $data;
|
return $data;
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Error_model extends Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_data(): array {
|
public function get_data(): ?array {
|
||||||
$data = parent::get_data();
|
$data = parent::get_data();
|
||||||
$this->get_msg($data);
|
$this->get_msg($data);
|
||||||
return $data;
|
return $data;
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Home_model extends Model {
|
||||||
->rows();
|
->rows();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_data(): array {
|
public function get_data(): ?array {
|
||||||
$data = parent::get_data();
|
$data = parent::get_data();
|
||||||
$data['title'] = lang('title');
|
$data['title'] = lang('title');
|
||||||
$data['posts'] = $this->get_posts();
|
$data['posts'] = $this->get_posts();
|
||||||
|
|
|
@ -80,7 +80,7 @@ class People_model extends Model {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_data(): array {
|
public function get_data(): ?array {
|
||||||
$data = parent::get_data();
|
$data = parent::get_data();
|
||||||
$data['title'] = lang('title');
|
$data['title'] = lang('title');
|
||||||
return $data;
|
return $data;
|
||||||
|
|
37
src/web/_model/apps/profile.php
Normal file
37
src/web/_model/apps/profile.php
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?php /* Copyright (c) 2024 Freya Murphy */
|
||||||
|
class Profile_model extends Model {
|
||||||
|
|
||||||
|
private $request_model;
|
||||||
|
|
||||||
|
function __construct($load) {
|
||||||
|
parent::__construct($load);
|
||||||
|
$this->request_model = $this->load->model('request');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_data(): ?array {
|
||||||
|
$uid = $this->request_model->get_int('id', FALSE);
|
||||||
|
if ($uid === FALSE) {
|
||||||
|
if ($this->main->session) {
|
||||||
|
$uid = $this->main->user()['id'];
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->db
|
||||||
|
->select('*')
|
||||||
|
->from('api.user u')
|
||||||
|
->where('u.id')
|
||||||
|
->eq($uid)
|
||||||
|
->row();
|
||||||
|
|
||||||
|
if (!$user) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = parent::get_data();
|
||||||
|
$data['user'] = $user;
|
||||||
|
$data['title'] = lang('title', sub: [$user['first_name']]);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
|
@ -49,7 +49,7 @@
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
var onLogin = function(data) {
|
var onLogin = function(data) {
|
||||||
let jwt = data.token;
|
var jwt = data.token;
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/auth/update',
|
url: '/auth/update',
|
||||||
|
@ -66,13 +66,13 @@
|
||||||
|
|
||||||
$('#action-login').on('submit', function(e) {
|
$('#action-login').on('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let username = $('#login-username').val();
|
var username = $('#login-username').val();
|
||||||
let password = $('#login-password').val();
|
var password = $('#login-password').val();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/api/rpc/login',
|
url: '/api/rpc/login',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: JSON.stringify({ username, password }),
|
data: JSON.stringify({ username: username, password: password }),
|
||||||
success: onLogin
|
success: onLogin
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<?php if ($loaded >= $page_size && $page_size < $total): ?>
|
<?php if ($loaded >= $page_size && $page_size < $total): ?>
|
||||||
<?=ilang('action_load_users',
|
<?=ilang('action_load_users',
|
||||||
id: 'action-load-users',
|
id: 'action-load-users',
|
||||||
class: 'btn btn-line btn-wide mt mb',
|
class: 'btn btn-line btn-wide mb',
|
||||||
attrs: array(
|
attrs: array(
|
||||||
'loaded' => $loaded,
|
'loaded' => $loaded,
|
||||||
'pageSize' => $page_size,
|
'pageSize' => $page_size,
|
||||||
|
@ -31,27 +31,27 @@
|
||||||
var urlParams = new URLSearchParams(window.location.search).toString();
|
var urlParams = new URLSearchParams(window.location.search).toString();
|
||||||
|
|
||||||
$('#action-load-users').on('click', function() {
|
$('#action-load-users').on('click', function() {
|
||||||
let me = $(this);
|
var me = $(this);
|
||||||
let page = me.attr('page');
|
var page = me.attr('page');
|
||||||
if (!page) {
|
if (!page) {
|
||||||
page = '1';
|
page = '1';
|
||||||
}
|
}
|
||||||
let newPage = Number(page) + 1;
|
var newPage = Number(page) + 1;
|
||||||
me.attr('page', newPage + '');
|
me.attr('page', newPage + '');
|
||||||
|
|
||||||
let loaded = Number(me.attr('loaded'));
|
var loaded = Number(me.attr('loaded'));
|
||||||
let pageSize = Number(me.attr('pageSize'));
|
var pageSize = Number(me.attr('pageSize'));
|
||||||
let userCount = Number(me.attr('userCount'));
|
var userCount = Number(me.attr('userCount'));
|
||||||
let userMax = Number(me.attr('userMax'));
|
var userMax = Number(me.attr('userMax'));
|
||||||
|
|
||||||
let url = '/people/people?page=' + page + '&max=' + userMax + '&' + urlParams;
|
var url = '/people/people?page=' + page + '&max=' + userMax + '&' + urlParams;
|
||||||
$.get(url, function (data) {
|
$.get(url, function (data) {
|
||||||
if (data === '') {
|
if (data === '') {
|
||||||
me.remove();
|
me.remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let container = $('#people-container');
|
var container = $('#people-container');
|
||||||
container.append(data);
|
container.append(data);
|
||||||
|
|
||||||
loaded += pageSize;
|
loaded += pageSize;
|
||||||
|
|
37
src/web/_views/apps/profile/main.php
Normal file
37
src/web/_views/apps/profile/main.php
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<div id="main-content">
|
||||||
|
<div id="profile-header" class="col">
|
||||||
|
<div class="banner image-loading">
|
||||||
|
<img src="/api/rpc/profile_banner?user_id=<?=$user['id']?>">
|
||||||
|
</div>
|
||||||
|
<div class="info row">
|
||||||
|
<div class="pfp-wrapper">
|
||||||
|
<?php $this->view('template/pfp', array('user' => $user)); ?>
|
||||||
|
</div>
|
||||||
|
<div class="col content">
|
||||||
|
<strong class="name"><?=$this->format_model->name($user)?></strong>
|
||||||
|
<span class="dim"><?=lang('joined') . $this->format_model->date($user['created'])?></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
<div class="row options">
|
||||||
|
<?=ilang('action_posts',
|
||||||
|
sub: [$user['first_name']],
|
||||||
|
class: 'btn'
|
||||||
|
)?>
|
||||||
|
<?=ilang('action_about',
|
||||||
|
sub: [$user['first_name']],
|
||||||
|
class: 'btn'
|
||||||
|
)?>
|
||||||
|
<?=ilang('action_friends',
|
||||||
|
sub: [$user['first_name']],
|
||||||
|
class: 'btn'
|
||||||
|
)?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="#tab-posts">
|
||||||
|
<?php
|
||||||
|
$_GET['user_id'] = $user['id'];
|
||||||
|
$this->post_controller->index();
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -55,7 +55,7 @@
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
$('#action-hamburger').on('click', function() {
|
$('#action-hamburger').on('click', function() {
|
||||||
let menu = $('.nav-center');
|
var menu = $('.nav-center');
|
||||||
menu.toggleClass('visible');
|
menu.toggleClass('visible');
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -31,18 +31,18 @@
|
||||||
<script>
|
<script>
|
||||||
$('#new-post-form').submit(function(e) {
|
$('#new-post-form').submit(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let content = $('#new-post-content').val();
|
var content = $('#new-post-content').val();
|
||||||
let me = $(this);
|
var me = $(this);
|
||||||
|
|
||||||
const getPost = function(data) {
|
var getPost = function(data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
$('#post-container').prepend(data);
|
$('#post-container').prepend(data);
|
||||||
}
|
}
|
||||||
me.closest('.modal-container').remove();
|
me.closest('.modal-container').remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
const onPost = function(data) {
|
var onPost = function(data) {
|
||||||
let id = data[0].id;
|
var id = data[0].id;
|
||||||
$.get({
|
$.get({
|
||||||
url: '/_util/post/post?id=' + id,
|
url: '/_util/post/post?id=' + id,
|
||||||
success: getPost
|
success: getPost
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/api/post',
|
url: '/api/post',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: JSON.stringify({ content }),
|
data: JSON.stringify({ content: content }),
|
||||||
success: onPost
|
success: onPost
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -133,28 +133,28 @@
|
||||||
$('#register-form').submit(function(e) {
|
$('#register-form').submit(function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const form = event.target;
|
var form = event.target;
|
||||||
const formFields = form.elements;
|
var formFields = form.elements;
|
||||||
|
|
||||||
let first_name = formFields.first_name.value.trim();
|
var first_name = formFields.first_name.value.trim();
|
||||||
let last_name = formFields.last_name.value.trim();
|
var last_name = formFields.last_name.value.trim();
|
||||||
let username = formFields.username.value.trim();
|
var username = formFields.username.value.trim();
|
||||||
let password = formFields.password.value.trim();
|
var password = formFields.password.value.trim();
|
||||||
let email = formFields.email.value.trim();
|
var email = formFields.email.value.trim();
|
||||||
let birth_date = formFields.birth_date.value.trim();
|
var birth_date = formFields.birth_date.value.trim();
|
||||||
let gender = formFields.gender.value.trim();
|
var gender = formFields.gender.value.trim();
|
||||||
|
|
||||||
if(birth_date === '') {
|
if(birth_date === '') {
|
||||||
errorToast('toast_date_empty');
|
errorToast('toast_date_empty');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const onSuccess = () => {
|
var onSuccess = function() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/api/rpc/login',
|
url: '/api/rpc/login',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
username, password
|
username: username, password: password
|
||||||
}),
|
}),
|
||||||
success: onLogin
|
success: onLogin
|
||||||
});
|
});
|
||||||
|
@ -164,8 +164,13 @@
|
||||||
url: '/api/user',
|
url: '/api/user',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
first_name, last_name, username, password,
|
first_name: first_name,
|
||||||
email, birth_date, gender
|
last_name: last_name,
|
||||||
|
username: username,
|
||||||
|
password: password,
|
||||||
|
email: email,
|
||||||
|
birth_date: birth_date,
|
||||||
|
gender: gender
|
||||||
}),
|
}),
|
||||||
success: onSuccess
|
success: onSuccess
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,16 +6,18 @@
|
||||||
$page_size = $pdata['page_size'];
|
$page_size = $pdata['page_size'];
|
||||||
$total = $pdata['total'];
|
$total = $pdata['total'];
|
||||||
$max = $pdata['max'];
|
$max = $pdata['max'];
|
||||||
|
$filterUid = $pdata['filter_uid'];
|
||||||
|
|
||||||
if ($loaded >= $page_size && $page_size < $total) {
|
if ($loaded >= $page_size && $page_size < $total) {
|
||||||
ilang('action_load_posts',
|
ilang('action_load_posts',
|
||||||
id: 'action-load-posts',
|
id: 'action-load-posts',
|
||||||
class: 'btn btn-line btn-wide mb',
|
class: 'btn btn-line btn-wide mb mt',
|
||||||
attrs: array(
|
attrs: array(
|
||||||
'loaded' => $loaded,
|
'loaded' => $loaded,
|
||||||
'pageSize' => $page_size,
|
'pageSize' => $page_size,
|
||||||
'postCount' => $total,
|
'postCount' => $total,
|
||||||
'postMax' => $max,
|
'postMax' => $max,
|
||||||
|
'userId' => $filterUid
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ class Aesthetic {
|
||||||
),
|
),
|
||||||
'home' => array(
|
'home' => array(
|
||||||
'js' => [
|
'js' => [
|
||||||
'js/routes/home.js',
|
|
||||||
'js/post.js',
|
'js/post.js',
|
||||||
],
|
],
|
||||||
'css' => [
|
'css' => [
|
||||||
|
@ -40,6 +39,15 @@ class Aesthetic {
|
||||||
'css/people.css'
|
'css/people.css'
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
'profile' => array(
|
||||||
|
'js' => [
|
||||||
|
'js/post.js',
|
||||||
|
],
|
||||||
|
'css' => [
|
||||||
|
'css/profile.css',
|
||||||
|
'css/post.css'
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,5 +5,6 @@ $routes['home'] = 'apps/home';
|
||||||
$routes['error'] = 'apps/error';
|
$routes['error'] = 'apps/error';
|
||||||
$routes['auth'] = 'apps/auth';
|
$routes['auth'] = 'apps/auth';
|
||||||
$routes['people'] = 'apps/people';
|
$routes['people'] = 'apps/people';
|
||||||
|
$routes['profile'] = 'apps/profile';
|
||||||
|
|
||||||
$routes[''] = '_index';
|
$routes[''] = '_index';
|
||||||
|
|
|
@ -24,7 +24,7 @@ abstract class Model {
|
||||||
/**
|
/**
|
||||||
* @returns the base model data
|
* @returns the base model data
|
||||||
*/
|
*/
|
||||||
public function get_data(): array {
|
public function get_data(): ?array {
|
||||||
$data = array();
|
$data = array();
|
||||||
$data['self'] = $this->main->user();
|
$data['self'] = $this->main->user();
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ function ilang($key,
|
||||||
$button = FALSE,
|
$button = FALSE,
|
||||||
) {
|
) {
|
||||||
$text = lang($key . "_text", FALSE, sub: $sub);
|
$text = lang($key . "_text", FALSE, sub: $sub);
|
||||||
$tip = lang($key . "_tip", FALSE);
|
$tip = lang($key . "_tip", FALSE, sub: $sub);
|
||||||
$icon = lang($key . "_icon", FALSE);
|
$icon = lang($key . "_icon", FALSE);
|
||||||
$content = lang($key . "_content", FALSE);
|
$content = lang($key . "_content", FALSE);
|
||||||
|
|
||||||
|
|
18
src/web/lang/en_US/apps/profile.php
Normal file
18
src/web/lang/en_US/apps/profile.php
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$lang['title'] = '%s\'s profile';
|
||||||
|
|
||||||
|
$lang['joined'] = 'Joined: ';
|
||||||
|
$lang['seen'] = 'Seen: ';
|
||||||
|
|
||||||
|
$lang['action_posts_text'] = 'Posts';
|
||||||
|
$lang['action_posts_tip'] = 'View %s\'s posts';
|
||||||
|
$lang['action_about_text'] = 'About';
|
||||||
|
$lang['action_about_tip'] = 'View %s\'s information';
|
||||||
|
$lang['action_friends_text'] = 'Friends';
|
||||||
|
$lang['action_friends_tip'] = 'View %s\'s friends';
|
||||||
|
|
||||||
|
$lang['action_load_posts_text'] = 'Load more posts';
|
||||||
|
$lang['action_load_posts_tip'] = 'Load more posts';
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in a new issue