mirror of
https://github.com/twisterarmy/cloud-server.git
synced 2025-03-12 13:31:04 +00:00
implement profiles details on the People page
This commit is contained in:
parent
2fdd59338c
commit
5596992e58
Binary file not shown.
89
src/application/controller/api/user/profile.php
Normal file
89
src/application/controller/api/user/profile.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
$response = [
|
||||
'success' => false,
|
||||
'message' => _('Internal server error'),
|
||||
'profile' => []
|
||||
];
|
||||
|
||||
if (isset($_SESSION['userName'])) {
|
||||
|
||||
$userName = isset($_POST['userName']) ? Filter::userName($_POST['userName']) : $_SESSION['userName'];
|
||||
|
||||
if ($userProfileVersions = $_twister->getDHT($userName, 'profile', 's')) {
|
||||
|
||||
// Check user exists
|
||||
if ($userId = $_modelUser->getUserId($userName)) {
|
||||
|
||||
// Add DHT version if not exists
|
||||
foreach ($userProfileVersions as $userProfileVersion) {
|
||||
|
||||
if (!$_modelProfile->versionExists($userId,
|
||||
$userProfileVersion['p']['height'],
|
||||
$userProfileVersion['p']['seq'])) {
|
||||
|
||||
$profile = $userProfileVersion['p']['v'];
|
||||
|
||||
$_modelProfile->add($userId,
|
||||
$userProfileVersion['p']['height'],
|
||||
$userProfileVersion['p']['seq'],
|
||||
$userProfileVersion['p']['time'],
|
||||
|
||||
isset($profile['fullname']) ? $profile['fullname'] : '',
|
||||
isset($profile['bio']) ? $profile['bio'] : '',
|
||||
isset($profile['location']) ? $profile['location'] : '',
|
||||
isset($profile['url']) ? $profile['url'] : '',
|
||||
isset($profile['bitmessage']) ? $profile['bitmessage'] : '',
|
||||
isset($profile['tox']) ? $profile['tox'] : '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get latest version available
|
||||
if ($profileInfo = $_modelProfile->get($userId)) {
|
||||
|
||||
$response = [
|
||||
'success' => true,
|
||||
'message' => _('Profile successfully received'),
|
||||
'profile' => [
|
||||
'userName' => $userName,
|
||||
'fullName' => $profileInfo['fullName'],
|
||||
'location' => $profileInfo['location'],
|
||||
'url' => $profileInfo['url'],
|
||||
'bitMessage' => $profileInfo['bitMessage'],
|
||||
'tox' => $profileInfo['tox'],
|
||||
'bio' => nl2br($profileInfo['bio']),
|
||||
]
|
||||
];
|
||||
|
||||
} else {
|
||||
|
||||
$response = [
|
||||
'success' => false,
|
||||
'message' => _('Profile data not available'),
|
||||
'profile' => []
|
||||
];
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$response = [
|
||||
'success' => false,
|
||||
'message' => _('Could not receive profile details'),
|
||||
'profile' => []
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$response = [
|
||||
'success' => false,
|
||||
'message' => _('Session expired. Please, reload the page.'),
|
||||
'profile' => []
|
||||
];
|
||||
}
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($response);
|
87
src/application/model/profile.php
Normal file
87
src/application/model/profile.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
class ModelProfile extends Model {
|
||||
|
||||
public function get(int $userId) {
|
||||
|
||||
try {
|
||||
|
||||
$query = $this->_db->prepare("SELECT * FROM `profile`
|
||||
WHERE `userId` = ?
|
||||
|
||||
ORDER BY `seq` DESC
|
||||
LIMIT 1");
|
||||
|
||||
$query->execute([$userId]);
|
||||
|
||||
return $query->fetch();
|
||||
|
||||
} catch (PDOException $e) {
|
||||
|
||||
trigger_error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function versionExists(int $userId, int $blockId, int $seq) {
|
||||
|
||||
try {
|
||||
|
||||
$query = $this->_db->prepare("SELECT COUNT(*) AS `total` FROM `profile`
|
||||
WHERE `userId` = ? AND `blockId` = ? AND `seq` = ?");
|
||||
|
||||
$query->execute([$userId, $blockId, $seq]);
|
||||
|
||||
return $query->fetch()['total'];
|
||||
|
||||
} catch (PDOException $e) {
|
||||
|
||||
trigger_error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function add(int $userId,
|
||||
int $blockId,
|
||||
int $seq,
|
||||
int $time,
|
||||
string $fullName,
|
||||
string $bio,
|
||||
string $location,
|
||||
string $url,
|
||||
string $bitMessage,
|
||||
string $tox) {
|
||||
|
||||
try {
|
||||
|
||||
$query = $this->_db->prepare("INSERT INTO `profile` SET `userId` = ?,
|
||||
`blockId` = ?,
|
||||
`seq` = ?,
|
||||
`time` = ?,
|
||||
`fullName` = ?,
|
||||
`bio` = ?,
|
||||
`location` = ?,
|
||||
`url` = ?,
|
||||
`bitMessage` = ?,
|
||||
`tox` = ?");
|
||||
|
||||
$query->execute([$userId,
|
||||
$blockId,
|
||||
$seq,
|
||||
$time,
|
||||
$fullName,
|
||||
$bio,
|
||||
$location,
|
||||
$url,
|
||||
$bitMessage,
|
||||
$tox]);
|
||||
|
||||
return $this->_db->lastInsertId();
|
||||
|
||||
} catch (PDOException $e) {
|
||||
|
||||
trigger_error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ require('config.php');
|
||||
require(PROJECT_DIR . '/application/model/model.php');
|
||||
require(PROJECT_DIR . '/application/model/block.php');
|
||||
require(PROJECT_DIR . '/application/model/user.php');
|
||||
require(PROJECT_DIR . '/application/model/profile.php');
|
||||
|
||||
require(PROJECT_DIR . '/system/curl.php');
|
||||
require(PROJECT_DIR . '/system/twister.php');
|
||||
@ -35,6 +36,14 @@ $_modelUser = new ModelUser(
|
||||
DB_PASSWORD
|
||||
);
|
||||
|
||||
$_modelProfile = new ModelProfile(
|
||||
DB_DATABASE,
|
||||
DB_HOST,
|
||||
DB_PORT,
|
||||
DB_USER,
|
||||
DB_PASSWORD
|
||||
);
|
||||
|
||||
$_modelBlock = new ModelBlock(
|
||||
DB_DATABASE,
|
||||
DB_HOST,
|
||||
@ -92,6 +101,9 @@ if (isset($_GET['_route_'])) {
|
||||
case 'api/user/random':
|
||||
require(PROJECT_DIR . '/application/controller/api/user/random.php');
|
||||
break;
|
||||
case 'api/user/profile':
|
||||
require(PROJECT_DIR . '/application/controller/api/user/profile.php');
|
||||
break;
|
||||
|
||||
// Multi-attribute pages
|
||||
default:
|
||||
|
@ -1,7 +1,7 @@
|
||||
.moduleFollowing .item {
|
||||
padding: 16px;
|
||||
margin: 0 2px 2px 2px;
|
||||
color: #1c1d1e;
|
||||
color: #fff;
|
||||
background: rgba(238, 238, 238, 0.08);
|
||||
border-radius: 3px;
|
||||
}
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
.moduleFollowing .item .avatar {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
top: 18px;
|
||||
left: 16px;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
|
||||
.moduleFollowing .item .action {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
top: 13px;
|
||||
right: 16px;
|
||||
}
|
||||
|
||||
@ -57,4 +57,38 @@
|
||||
padding-right: 32px;
|
||||
letter-spacing: 0.2px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.moduleFollowing .item .info .username {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.moduleFollowing .item .info .username a {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.moduleFollowing .item .info .location {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.moduleFollowing .item .info .bio {
|
||||
font-style: italic;
|
||||
margin-top: 4px;
|
||||
color: #c3c8ce
|
||||
}
|
||||
|
||||
.moduleFollowing .item.active .info .bio {
|
||||
color: #515457
|
||||
}
|
||||
|
||||
.moduleFollowing .item .info .url,
|
||||
.moduleFollowing .item .info .tox,
|
||||
.moduleFollowing .item .info .bitMessage {
|
||||
display: inline-block;
|
||||
margin-right: 4px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.moduleFollowing .item .info .tox {
|
||||
font-size: 10px
|
||||
}
|
@ -5,7 +5,8 @@ var ModuleFollowing = {
|
||||
append: function(list, userName) {
|
||||
$(list).append(
|
||||
$('<div/>', {
|
||||
'class': 'item' + (userName == $(list).data('username') ? ' active' : '')
|
||||
'class': 'item' + (userName == $(list).data('username') ? ' active' : ''),
|
||||
'data-username': userName
|
||||
}).append(
|
||||
$('<div/>', {
|
||||
'class': 'avatar'
|
||||
@ -23,9 +24,33 @@ var ModuleFollowing = {
|
||||
$('<div/>', {
|
||||
'class': 'info'
|
||||
}).append(
|
||||
$('<a/>', {
|
||||
'href': 'people/' + userName
|
||||
}).append(userName)
|
||||
$('<div/>', {
|
||||
'class': 'username'
|
||||
}).append(
|
||||
$('<a/>', {
|
||||
'href': 'people/' + userName
|
||||
}).append(userName)
|
||||
)
|
||||
).append(
|
||||
$('<div/>', {
|
||||
'class': 'location'
|
||||
})
|
||||
).append(
|
||||
$('<div/>', {
|
||||
'class': 'bio'
|
||||
})
|
||||
).append(
|
||||
$('<div/>', {
|
||||
'class': 'url'
|
||||
})
|
||||
).append(
|
||||
$('<div/>', {
|
||||
'class': 'tox'
|
||||
})
|
||||
).append(
|
||||
$('<div/>', {
|
||||
'class': 'bitmessage'
|
||||
})
|
||||
)
|
||||
).append(
|
||||
$('<div/>', {
|
||||
@ -43,6 +68,36 @@ var ModuleFollowing = {
|
||||
}
|
||||
}
|
||||
},
|
||||
loadProfile: function(list, userName) {
|
||||
$.ajax({
|
||||
url: 'api/user/profile',
|
||||
type: 'POST',
|
||||
data: {
|
||||
userName: userName
|
||||
},
|
||||
success: function (response) {
|
||||
|
||||
if (response.success) {
|
||||
|
||||
$(list).find('div[data-username="' + userName + '"] .username > a').html(response.profile.fullName ? response.profile.fullName : response.profile.userName);
|
||||
$(list).find('div[data-username="' + userName + '"] .location').html(response.profile.location);
|
||||
$(list).find('div[data-username="' + userName + '"] .url').html($('<a/>',{'href':response.profile.url,'class':'bi bi-link','title':'Website'}));
|
||||
$(list).find('div[data-username="' + userName + '"] .bio').html(response.profile.bio);
|
||||
$(list).find('div[data-username="' + userName + '"] .bitMessage').html(response.profile.bitMessage == '' ? '' : $('<a/>',{'href':'bitmessage:' + response.profile.bitMessage,'class':'bi bi-send','title':'BitMessage'}));
|
||||
$(list).find('div[data-username="' + userName + '"] .tox').html(response.profile.tox == '' ? '' : $('<a/>',{'href':'tox:' + response.profile.tox,'class':'bi bi-chat-square-dots','title':'TOX'}));
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
console.log(response.message);
|
||||
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
console.log(textStatus, errorThrown);
|
||||
}
|
||||
});
|
||||
},
|
||||
load: function(list, reFresh) {
|
||||
$.ajax({
|
||||
url: 'api/follow/get',
|
||||
@ -57,11 +112,12 @@ var ModuleFollowing = {
|
||||
|
||||
$(response.users).each(function() {
|
||||
ModuleFollowing.template.list.item.append(list, this.userName);
|
||||
ModuleFollowing.loadProfile(list, this.userName);
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
alert(response.message);
|
||||
console.log(response.message);
|
||||
|
||||
}
|
||||
},
|
||||
@ -88,7 +144,7 @@ var ModuleFollowing = {
|
||||
|
||||
} else {
|
||||
|
||||
alert(response.message);
|
||||
console.log(response.message);
|
||||
|
||||
}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user