summaryrefslogtreecommitdiff
path: root/src/web
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/web/_controller/apps/people.php41
-rw-r--r--src/web/_model/apps/people.php88
-rw-r--r--src/web/_model/format.php3
-rw-r--r--src/web/_views/apps/people/card.php35
-rw-r--r--src/web/_views/apps/people/main.php67
-rw-r--r--src/web/_views/apps/people/people.php7
-rw-r--r--src/web/_views/template/pfp.php9
-rw-r--r--src/web/_views/template/post.php2
-rw-r--r--src/web/config/aesthetic.php5
-rw-r--r--src/web/config/routes.php1
-rw-r--r--src/web/core/database.php14
-rw-r--r--src/web/lang/en_US/apps/people.php17
12 files changed, 277 insertions, 12 deletions
diff --git a/src/web/_controller/apps/people.php b/src/web/_controller/apps/people.php
new file mode 100644
index 0000000..19910ac
--- /dev/null
+++ b/src/web/_controller/apps/people.php
@@ -0,0 +1,41 @@
+<?php /* Copyright (c) 2024 Freya Murphy */
+class People_controller extends Controller {
+
+ // the people model
+ private $people_model;
+
+ // format model
+ protected $format_model;
+
+ function __construct($load) {
+ parent::__construct($load);
+ $this->people_model = $this->load->model('apps/people');
+ $this->format_model = $this->load->model('format');
+ }
+
+ public function index(): void {
+ parent::index();
+ $data = $this->people_model->get_data();
+ $this->view('header', $data);
+ $this->view('apps/people/main', $data);
+ $this->view('footer', $data);
+ }
+
+ /**
+ * @return array<string,mixed>
+ */
+ public function people(): array {
+ $data = $this->people_model->get_users();
+
+ $this->view('apps/people/people', $data);
+
+ $max = 0;
+ foreach ($data['users'] as $user) {
+ $max = max($max, $user['id']);
+ }
+
+ return $data;
+ }
+}
+
+?>
diff --git a/src/web/_model/apps/people.php b/src/web/_model/apps/people.php
new file mode 100644
index 0000000..4b6bab4
--- /dev/null
+++ b/src/web/_model/apps/people.php
@@ -0,0 +1,88 @@
+<?php /* Copyright (c) 2024 Freya Murphy */
+class People_model extends Model {
+
+ private $request_model;
+
+ function __construct($load) {
+ parent::__construct($load);
+ $this->request_model = $this->load->model('request');
+ }
+
+ private function get_filted_query($select) {
+ $filter_username = $this->request_model->get_str('filter_username', FALSE);
+ $filter_fisrt_name = $this->request_model->get_str('filter_first_name', FALSE);
+ $filter_last_name = $this->request_model->get_str('filter_last_name', FALSE);
+ $filter_email = $this->request_model->get_str('filter_email', FALSE);
+ $max = $this->request_model->get_int('max', FALSE);
+
+ $query = $this->db
+ ->select($select)
+ ->from('api.user u');
+
+ if ($filter_username) {
+ $query = $query
+ ->where('u.username')
+ ->like('%' . $filter_username . '%');
+ }
+
+ if ($filter_fisrt_name) {
+ $query = $query
+ ->where('u.first_name')
+ ->like('%'. $filter_fisrt_name . '%');
+ }
+
+ if ($filter_last_name) {
+ $query = $query
+ ->where('u.last_name')
+ ->like('%' . $filter_last_name . '%');
+ }
+
+ if ($filter_email) {
+ $query = $query
+ ->where('u.email')
+ ->like('%' . $filter_email . '%');
+ }
+
+ if ($max) {
+ $query = $query
+ ->where('u.id')
+ ->le($max);
+ }
+
+ return $query;
+ }
+
+ public function get_users(): array {
+ $page = $this->request_model->get_int('page', 0);
+ $page_size = 24;
+ $offset = $page_size * $page;
+
+ $users = $this->get_filted_query('*')
+ ->order_by('u.id', 'DESC')
+ ->offset($offset)
+ ->limit($page_size)
+ ->rows();
+
+ $count = $this->get_filted_query('COUNT(u.id) AS count')
+ ->row()['count'];
+
+ $max = 0;
+
+ foreach ($users as $user) {
+ $max = max($max, $user['id']);
+ }
+
+ return array(
+ 'users' => $users,
+ 'count' => $count,
+ 'page_size' => $page_size,
+ 'max_id' => $max
+ );
+ }
+
+ public function get_data(): array {
+ $data = parent::get_data();
+ $data['title'] = lang('title');
+ return $data;
+ }
+}
diff --git a/src/web/_model/format.php b/src/web/_model/format.php
index 52b51be..d2a3700 100644
--- a/src/web/_model/format.php
+++ b/src/web/_model/format.php
@@ -39,7 +39,8 @@ class Format_model extends Model {
* @returns the formatted date
*/
public function date($date) {
- return $date;
+ $date=date_create($date);
+ return date_format($date, "Y-m-d H:i");
}
}
diff --git a/src/web/_views/apps/people/card.php b/src/web/_views/apps/people/card.php
new file mode 100644
index 0000000..a44b0d4
--- /dev/null
+++ b/src/web/_views/apps/people/card.php
@@ -0,0 +1,35 @@
+<?php /* Copyright (c) 2024 Freya Murphy */ ?>
+<?php /* vi: syntax=php */ ?>
+<a
+ class="card profile"
+ href="/profile?id=<?=$user['id']?>"
+>
+ <div class="row">
+ <?php $this->view('template/pfp', array('user' => $user, 'link' => FALSE)); ?>
+ <div class="col ml">
+ <strong class=""><?=$this->format_model->name($user)?></strong>
+ <span class="dim"><?=lang('joined') . ' ' . $this->format_model->date($user['created'])?></span>
+ <span class="dim"><?=lang('seen') . ' ' . $this->format_model->date($user['seen'])?></span>
+ </div>
+ </div>
+ <hr>
+ <table>
+ <tr>
+ <td><?=lang('tbl_username')?></td>
+ <td><?=$user['username']?></td>
+ <tr>
+ <tr>
+ <td><?=lang('tbl_email')?></td>
+ <td><?=$user['email']?></td>
+ <tr>
+ <tr>
+ <td><?=lang('tbl_gender')?></td>
+ <td><?=$user['gender']?></td>
+ <tr>
+ <tr>
+ <td><?=lang('tbl_uid')?></td>
+ <td><?=$user['id']?></td>
+ <tr>
+ </table>
+</a>
+<?
diff --git a/src/web/_views/apps/people/main.php b/src/web/_views/apps/people/main.php
new file mode 100644
index 0000000..3b45333
--- /dev/null
+++ b/src/web/_views/apps/people/main.php
@@ -0,0 +1,67 @@
+<?php /* Copyright (c) 2024 Freya Murphy */ ?>
+<?php /* vi: syntax=php */ ?>
+<div id="main-content" class="col">
+ <h1 class="title"><?=lang('title')?></h1>
+ <h3 class="desc"><?=lang('desc')?></h3>
+ <hr>
+ <div id="people-container" class="col">
+ <?php
+ $pdata = $this->people();
+ ?>
+ </div>
+ <?php
+ $loaded = count($pdata['users']);
+ $page_size = $pdata['page_size'];
+ $total = $pdata['count'];
+ $max = $pdata['max_id'];
+ ?>
+ <?php if ($loaded >= $page_size && $page_size < $total): ?>
+ <?=ilang('action_load_users',
+ id: 'action-load-users',
+ class: 'btn btn-line btn-wide mt mb',
+ attrs: array(
+ 'loaded' => $loaded,
+ 'pageSize' => $page_size,
+ 'userCount' => $total,
+ 'userMax' => $max
+ )
+ )?>
+ <script>
+
+ var urlParams = new URLSearchParams(window.location.search).toString();
+
+ $('#action-load-users').on('click', function() {
+ let me = $(this);
+ let page = me.attr('page');
+ if (!page) {
+ page = '1';
+ }
+ let newPage = Number(page) + 1;
+ me.attr('page', newPage + '');
+
+ let loaded = Number(me.attr('loaded'));
+ let pageSize = Number(me.attr('pageSize'));
+ let userCount = Number(me.attr('userCount'));
+ let userMax = Number(me.attr('userMax'));
+
+ let url = '/people/people?page=' + page + '&max=' + userMax + '&' + urlParams;
+ $.get(url, function (data) {
+ if (data === '') {
+ me.remove();
+ return;
+ }
+
+ let container = $('#people-container');
+ container.append(data);
+
+ loaded += pageSize;
+ if (loaded >= userCount) {
+ me.remove();
+ } else {
+ me.attr('loaded', loaded + '');
+ }
+ });
+ });
+ </script>
+ <?php endif ?>
+</div>
diff --git a/src/web/_views/apps/people/people.php b/src/web/_views/apps/people/people.php
new file mode 100644
index 0000000..5fc0d17
--- /dev/null
+++ b/src/web/_views/apps/people/people.php
@@ -0,0 +1,7 @@
+<?php /* Copyright (c) 2024 Freya Murphy */ ?>
+<?php /* vi: syntax=php */ ?>
+<?php
+ foreach($users as $user) {
+ $this->view('apps/people/card', array('user' => $user));
+ }
+?>
diff --git a/src/web/_views/template/pfp.php b/src/web/_views/template/pfp.php
index 9a5a336..ebb4b5f 100644
--- a/src/web/_views/template/pfp.php
+++ b/src/web/_views/template/pfp.php
@@ -2,7 +2,16 @@
<?php /* vi: syntax=php */ ?>
<?php
$class = isset($class) ? $class : '';
+ $link = isset($link) ? $link : TRUE;
?>
+<?php if($link): ?>
<a class="image-loading pfp <?=$class?>" href="/profile?id=<?=$user['id']?>">
+<?php else: ?>
+<div class="image-loading pfp <?=$class?>">
+<?php endif; ?>
<img src="/api/rpc/profile_avatar?user_id=<?=$user['id']?>"/>
+<?php if ($link): ?>
</a>
+<?php else: ?>
+</div>
+<?php endif; ?>
diff --git a/src/web/_views/template/post.php b/src/web/_views/template/post.php
index 83a72bf..0633985 100644
--- a/src/web/_views/template/post.php
+++ b/src/web/_views/template/post.php
@@ -61,7 +61,7 @@
</div>
<?php if ($self): ?>
<div class="row pb">
- <?php $this->view('template/pfp', array('user' => $user))?>
+ <?php $this->view('template/pfp', array('user' => $self))?>
<form class="ml action-new-comment-form row">
<input
type="hidden"
diff --git a/src/web/config/aesthetic.php b/src/web/config/aesthetic.php
index 304baec..e528b09 100644
--- a/src/web/config/aesthetic.php
+++ b/src/web/config/aesthetic.php
@@ -35,6 +35,11 @@ class Aesthetic {
'css/auth.css'
],
),
+ 'people' => array(
+ 'css' => [
+ 'css/people.css'
+ ],
+ ),
);
}
/**
diff --git a/src/web/config/routes.php b/src/web/config/routes.php
index 33c871b..5bb9a1b 100644
--- a/src/web/config/routes.php
+++ b/src/web/config/routes.php
@@ -4,5 +4,6 @@ $routes = array();
$routes['home'] = 'apps/home';
$routes['error'] = 'apps/error';
$routes['auth'] = 'apps/auth';
+$routes['people'] = 'apps/people';
$routes[''] = '_index';
diff --git a/src/web/core/database.php b/src/web/core/database.php
index 81352a9..e9b8109 100644
--- a/src/web/core/database.php
+++ b/src/web/core/database.php
@@ -46,6 +46,8 @@ class DatabaseQuery {
if (!$this->where) {
$this->where = TRUE;
$this->query .= "WHERE ";
+ } else {
+ $this->query .= "AND ";
}
$this->query .= "$cond ";
return $this;
@@ -85,6 +87,8 @@ class DatabaseQuery {
if (!$this->where) {
$this->where = TRUE;
$this->query .= "WHERE ";
+ } else {
+ $this->query .= "AND ";
}
if (empty($array)) {
$this->query .= "FALSE\n";
@@ -95,16 +99,6 @@ class DatabaseQuery {
return $this;
}
- public function and() {
- $this->query .= "AND ";
- return $this;
- }
-
- public function or() {
- $this->query .= "OR ";
- return $this;
- }
-
public function join($table, $on, $type = 'LEFT') {
$this->query .= "$type JOIN $table ON $on\n";
return $this;
diff --git a/src/web/lang/en_US/apps/people.php b/src/web/lang/en_US/apps/people.php
new file mode 100644
index 0000000..2bfc240
--- /dev/null
+++ b/src/web/lang/en_US/apps/people.php
@@ -0,0 +1,17 @@
+<?php
+
+$lang['title'] = 'Directory';
+$lang['desc'] = 'Explore other people on xssbook!';
+
+$lang['joined'] = 'Joined: ';
+$lang['seen'] = 'Seen: ';
+
+$lang['tbl_username'] = 'Username';
+$lang['tbl_email'] = 'Email ';
+$lang['tbl_uid'] = 'User ID ';
+$lang['tbl_gender'] = 'Gender ';
+
+$lang['action_load_users_text'] = 'Load more users';
+$lang['action_load_users_tip'] = 'Load more users';
+
+?>