summaryrefslogtreecommitdiff
path: root/src/web
diff options
context:
space:
mode:
Diffstat (limited to 'src/web')
-rw-r--r--src/web/_model/apps/people.php6
-rw-r--r--src/web/_model/apps/profile.php28
-rw-r--r--src/web/_views/apps/home/main.php2
-rw-r--r--src/web/_views/apps/profile/main.php254
-rw-r--r--src/web/helper/lang.php4
-rw-r--r--src/web/lang/en_US/apps/profile.php9
6 files changed, 227 insertions, 76 deletions
diff --git a/src/web/_model/apps/people.php b/src/web/_model/apps/people.php
index ade59d3..4287094 100644
--- a/src/web/_model/apps/people.php
+++ b/src/web/_model/apps/people.php
@@ -24,13 +24,15 @@ class People_model extends Model {
case 'follower': {
$query = $query
->join('admin.follow f', 'f.follower_id = u.id AND f.followee_id', 'INNER')
- ->eq($filter_uid);
+ ->eq($filter_uid)
+ ->where('f.value = TRUE');
} break;
case 'followee': {
$query = $query
->join('admin.follow f', 'f.followee_id = u.id AND f.follower_id', 'INNER')
- ->eq($filter_uid);
+ ->eq($filter_uid)
+ ->where('f.value = TRUE');
} break;
}
}
diff --git a/src/web/_model/apps/profile.php b/src/web/_model/apps/profile.php
index 592fbcb..97b0150 100644
--- a/src/web/_model/apps/profile.php
+++ b/src/web/_model/apps/profile.php
@@ -29,8 +29,36 @@ class Profile_model extends Model {
return NULL;
}
+ $following = FALSE;
+ $followed = FALSE;
+ $follow_id = NULL;
+
+ if ($this->main->session) {
+ $sid = $this->main->user()['id'];
+ $res = $this->db->select('f.value, f.id')
+ ->from('admin.follow f')
+ ->where('f.follower_id')
+ ->eq($sid)
+ ->where('f.followee_id')
+ ->eq($uid)
+ ->row();
+ $following = $res ? $res['value'] : FALSE;
+ $follow_id = $res ? $res['id'] : NULL;
+ $res = $this->db->select('f.value')
+ ->from('admin.follow f')
+ ->where('f.follower_id')
+ ->eq($uid)
+ ->where('f.followee_id')
+ ->eq($sid)
+ ->row();
+ $followed = $res ? $res['value'] : FALSE;
+ }
+
$data = parent::get_data();
$data['user'] = $user;
+ $data['following'] = $following;
+ $data['followed'] = $followed;
+ $data['follow_id'] = $follow_id;
$data['title'] = lang('title', sub: [$user['first_name']]);
return $data;
}
diff --git a/src/web/_views/apps/home/main.php b/src/web/_views/apps/home/main.php
index 735e3d8..60c3eb9 100644
--- a/src/web/_views/apps/home/main.php
+++ b/src/web/_views/apps/home/main.php
@@ -1,6 +1,6 @@
<?php /* Copyright (c) 2024 Freya Murphy */ ?>
<?php /* vi: syntax=php */ ?>
-<div id="main-content">
+<div id="main-content" class="container">
<?php if ($self): ?>
<div id="new-post" class="card">
<div class="row grow">
diff --git a/src/web/_views/apps/profile/main.php b/src/web/_views/apps/profile/main.php
index e3d65b5..6671d87 100644
--- a/src/web/_views/apps/profile/main.php
+++ b/src/web/_views/apps/profile/main.php
@@ -8,9 +8,116 @@
<div class="pfp-wrapper">
<?=pfp($user)?>
</div>
- <div class="col content">
- <strong class="name"><?=$this->format_model->name($user)?></strong>
- <span class="dim"><?=$user['follower_count'] . ' ' . lang('followers')?></span>
+ <div class="col content grow">
+ <div class="row grow">
+ <div class="col">
+ <strong class="name"><?=$this->format_model->name($user)?></strong>
+ <span class="dim"><?=$user['follower_count'] . ' ' . lang('followers')?></span>
+ </div>
+ <?php if (!isset($self) || $self['id'] != $user['id']): ?>
+ <div id="follow-container">
+ <?=ilang(
+ 'action_follow',
+ id: 'action-follow-follow',
+ class: 'btn btn-alt',
+ style: (!$following && !$followed) ? '' : 'display: none',
+ sub: [$user['first_name']]
+ )?>
+ <?=ilang(
+ 'action_follow_back',
+ id: 'action-follow-follow-back',
+ class: 'btn btn-alt',
+ style: (!$following && $followed) ? '' : 'display: none',
+ sub: [$user['first_name']]
+ )?>
+ <?=ilang(
+ 'action_following',
+ id: 'action-follow-following',
+ class: 'btn btn-alt btn-blue',
+ style: ($following && !$followed) ? '' : 'display: none',
+ sub: [$user['first_name']]
+ )?>
+ <?=ilang(
+ 'action_friends',
+ id: 'action-follow-friends',
+ class: 'btn btn-alt btn-blue',
+ style: ($following && $followed) ? '' : 'display: none',
+ sub: [$user['first_name']]
+ )?>
+ </div>
+ <script>
+ let following = <?=json_encode($following)?>;
+ let followed = <?=json_encode($followed)?>;
+ let followId = <?=json_encode($follow_id)?>;
+ let followee_id = <?=json_encode($user['id'])?>;
+ let btns = {};
+
+ const disableBtn = (btn) => {
+ btn.css('display', 'none');
+ };
+
+ const enableBtn = (btn) => {
+ btn.css('display', '');
+ };
+
+ const updateFollow = () => {
+ for (let btn of Object.values(btns)) {
+ disableBtn(btn);
+ }
+ if (!following && !followed) {
+ enableBtn(btns['follow']);
+ } else if (!following && followed) {
+ enableBtn(btns['follow-back']);
+ } else if (following && !followed) {
+ enableBtn(btns['following']);
+ } else if (following && followed) {
+ enableBtn(btns['friends']);
+ }
+ }
+
+ const onPatchFollow = (data) => {
+ following = data[0].value;
+ updateFollow();
+ }
+
+ const onPostFollow = (data) => {
+ followId = data[0].id;
+ following = true;
+ updateFollow();
+ }
+
+ const onClickFollow = () => {
+ if (followId) {
+ $.ajax({
+ url: '/api/follow?id=eq.' + followId,
+ method: 'PATCH',
+ data: JSON.stringify({ followee_id, value: !following }),
+ success: onPatchFollow
+ });
+ } else {
+ $.ajax({
+ url: '/api/follow',
+ method: 'POST',
+ data: JSON.stringify({ followee_id, value: !following }),
+ success: onPostFollow,
+ });
+ }
+ }
+
+ const loadBtn = (name) => {
+ let btn = $('#action-follow-' + name);
+ btn.on('click', onClickFollow);
+
+ btns[name] = btn;
+ };
+
+ loadBtn('follow');
+ loadBtn('follow-back');
+ loadBtn('following');
+ loadBtn('friends');
+ </script>
+ <?php endif; ?>
+ </div>
<?php if(strlen($user['profile_bio']) > 0): ?>
<br>
<strong><?=lang('bio')?></strong>
@@ -43,78 +150,79 @@
</div>
</div>
</div>
- <div id="tab-posts" class="tab">
+ <div id="tab-container" class="container">
+ <div id="tab-posts" class="tab">
+ <?php
+ $_GET['user_id'] = $user['id'];
+ $this->post_controller->index();
+ ?>
+ </div>
+ <div id="tab-about" class="tab card">
+ <h1><?=lang('about_general')?></h1>
+ <table>
+ <tr>
+ <td><strong><?=lang('about_general_username')?></strong></td>
+ <td><?=$user['username']?></td>
+ </tr>
+ <tr>
+ <td><strong><?=lang('about_general_full_name')?></strong></td>
+ <td><?=$user['first_name'] . ' ' . $user['last_name']?></td>
+ </tr>
+ <tr>
+ <td><strong><?=lang('about_general_email')?></strong></td>
+ <td><?=$user['email']?></td>
+ </tr>
+ <tr>
+ <td><strong><?=lang('about_general_gender')?></strong></td>
+ <td><?=$user['gender']?></td>
+ </tr>
+ <tr>
+ <td><strong><?=lang('about_general_birth_date')?></strong></td>
+ <td><?=$user['birth_date']?></td>
+ </tr>
+ </table>
+ <h1><?=lang('about_stats')?></h1>
+ <table>
+ <tr>
+ <td><strong><?=lang('about_stats_posts')?></strong></td>
+ <td><?=$user['post_count']?></td>
+ </tr>
+ <tr>
+ <td><strong><?=lang('about_stats_like')?></strong></td>
+ <td><?=$user['like_count']?></td>
+ </tr>
+ <tr>
+ <td><strong><?=lang('about_stats_comments')?></strong></td>
+ <td><?=$user['comment_count']?></td>
+ </tr>
+ <tr>
+ <td><strong><?=lang('about_stats_following')?></strong></td>
+ <td><?=$user['followed_count']?></td>
+ </tr>
+ <tr>
+ <td><strong><?=lang('about_stats_joined')?></strong></td>
+ <td><?=$user['created']?></td>
+ </tr>
+ <tr>
+ <td><strong><?=lang('about_stats_seen')?></strong></td>
+ <td><?=$user['seen']?></td>
+ </tr>
+ </table>
+ </div>
+ <div id="tab-followers" class="tab">
<?php
- $_GET['user_id'] = $user['id'];
- $this->post_controller->index();
+ $_GET['filter'] = 'follower';
+ $_GET['uid'] = $user['id'];
+ $this->people_controller->content();
?>
- </div>
- <div id="tab-about" class="tab">
- <h1><?=lang('about_general')?></h1>
- <table>
- <tr>
- <td><strong><?=lang('about_general_username')?></strong></td>
- <td><?=$user['username']?></td>
- </tr>
- <tr>
- <td><strong><?=lang('about_general_full_name')?></strong></td>
- <td><?=$user['first_name'] . ' ' . $user['last_name']?></td>
- </tr>
- <tr>
- <td><strong><?=lang('about_general_email')?></strong></td>
- <td><?=$user['email']?></td>
- </tr>
- <tr>
- <td><strong><?=lang('about_general_gender')?></strong></td>
- <td><?=$user['gender']?></td>
- </tr>
- <tr>
- <td><strong><?=lang('about_general_birth_date')?></strong></td>
- <td><?=$user['birth_date']?></td>
- </tr>
- </table>
- <h1><?=lang('about_stats')?></h1>
- <table>
- <tr>
- <td><strong><?=lang('about_stats_posts')?></strong></td>
- <td><?=$user['post_count']?></td>
- </tr>
- <tr>
- <td><strong><?=lang('about_stats_like')?></strong></td>
- <td><?=$user['like_count']?></td>
- </tr>
- <tr>
- <td><strong><?=lang('about_stats_comments')?></strong></td>
- <td><?=$user['comment_count']?></td>
- </tr>
- <tr>
- <td><strong><?=lang('about_stats_following')?></strong></td>
- <td><?=$user['followed_count']?></td>
- </tr>
- <tr>
- <td><strong><?=lang('about_stats_joined')?></strong></td>
- <td><?=$user['created']?></td>
- </tr>
- <tr>
- <td><strong><?=lang('about_stats_seen')?></strong></td>
- <td><?=$user['seen']?></td>
- </tr>
- </table>
- </div>
- <div id="tab-followers" class="tab">
- <?php
- $_GET['filter'] = 'follower';
- $_GET['uid'] = $user['id'];
- $this->people_controller->content();
- ?>
- </div>
- <div id="tab-following" class="tab">
- <?php
- $_GET['filter'] = 'followee';
- $_GET['uid'] = $user['id'];
- $this->people_controller->content();
- ?>
- </div>
+ </div>
+ <div id="tab-following" class="tab">
+ <?php
+ $_GET['filter'] = 'followee';
+ $_GET['uid'] = $user['id'];
+ $this->people_controller->content();
+ ?>
+ </div>
</div>
<script>
let tabs = {};
diff --git a/src/web/helper/lang.php b/src/web/helper/lang.php
index 9c694a1..b0638a6 100644
--- a/src/web/helper/lang.php
+++ b/src/web/helper/lang.php
@@ -18,6 +18,7 @@ function lang($key, $default = NULL, $sub = NULL) {
function ilang($key,
$class = NULL,
+ $style = NULL,
$id = NULL,
$href = NULL,
$click = NULL,
@@ -42,6 +43,9 @@ function ilang($key,
if ($class) {
echo 'class="' . $class . '" ';
}
+ if ($style) {
+ echo 'style="' . $style . '" ';
+ }
if ($id) {
echo 'id="' . $id . '" ';
}
diff --git a/src/web/lang/en_US/apps/profile.php b/src/web/lang/en_US/apps/profile.php
index 43a3247..bb91e02 100644
--- a/src/web/lang/en_US/apps/profile.php
+++ b/src/web/lang/en_US/apps/profile.php
@@ -16,6 +16,15 @@ $lang['action_followers_tip'] = 'View %s\'s followres';
$lang['action_following_text'] = 'Following';
$lang['action_following_tip'] = 'View who %s is following';
+$lang['action_follow_text'] = 'Follow';
+$lang['action_follow_tip'] = 'Follow %s';
+$lang['action_follow_back_text'] = 'Follow Back';
+$lang['action_follow_back_tip'] = 'Follow %s';
+$lang['action_following_text'] = 'Followed';
+$lang['action_following_tip'] = 'Unfollow %s';
+$lang['action_friends_text'] = 'Friends';
+$lang['action_friends_tip'] = 'Unfollow %s';
+
$lang['action_load_posts_text'] = 'Load more posts';
$lang['action_load_posts_tip'] = 'Load more posts';