Browse Source

init users finding module

main
ghost 3 years ago
parent
commit
bed80c213b
  1. 30
      src/application/controller/api/user/random.php
  2. 3
      src/application/controller/common/module/users.php
  3. 2
      src/application/controller/home.php
  4. 19
      src/application/model/user.php
  5. 1
      src/application/view/common/module/users.phtml
  6. 1
      src/application/view/home.phtml
  7. 3
      src/bootstrap.php
  8. 2
      src/config-default.php
  9. 33
      src/public/css/template/default/module/users.css
  10. 1
      src/public/js/home.js
  11. 63
      src/public/js/module/users.js

30
src/application/controller/api/user/random.php

@ -0,0 +1,30 @@
<?php
$response = [
'success' => false,
'message' => _('Internal server error'),
'users' => [],
'total' => 0
];
$usersTotal = 0;
$users = [];
foreach ((array) $_modelUser->getLastRandomUsers(APPLICATION_MODULE_USERS_LIMIT) as $user) {
$users[] = [
'userName' => $user['username']
];
$usersTotal++;
}
$response = [
'success' => true,
'message' => _('Users received'),
'users' => $users,
'total' => $usersTotal
];
header('Content-Type: application/json; charset=utf-8');
echo json_encode($response);

3
src/application/controller/common/module/users.php

@ -0,0 +1,3 @@
<?php
require(PROJECT_DIR . '/application/view/common/module/users.phtml');

2
src/application/controller/home.php

@ -12,12 +12,14 @@ $metaStyles = [
'css/template/default/module/menu.css', 'css/template/default/module/menu.css',
'css/template/default/module/post.css', 'css/template/default/module/post.css',
'css/template/default/module/feed.css', 'css/template/default/module/feed.css',
'css/template/default/module/users.css',
]; ];
$metaScripts = [ $metaScripts = [
'js/module/menu.js', 'js/module/menu.js',
'js/module/post.js', 'js/module/post.js',
'js/module/feed.js', 'js/module/feed.js',
'js/module/users.js',
'js/home.js', 'js/home.js',
]; ];

19
src/application/model/user.php

@ -35,6 +35,25 @@ class ModelUser extends Model {
} }
} }
public function getLastRandomUsers(int $limit) {
try {
$query = $this->_db->query("SELECT * FROM `user`
JOIN `block` ON (`user`.`blockId` = `block`.`blockId`)
WHERE `block`.`time` > UNIX_TIMESTAMP(CURDATE() - interval 5 YEAR)
ORDER BY RAND()
LIMIT " . (int) $limit);
return $query->rowCount() ? $query->fetchAll() : [];
} catch (PDOException $e) {
trigger_error($e->getMessage());
return false;
}
}
public function userNameExists(string $userName) { public function userNameExists(string $userName) {
try { try {

1
src/application/view/common/module/users.phtml

@ -0,0 +1 @@
<div class="moduleUsers" id="moduleUsers"></div>

1
src/application/view/home.phtml

@ -2,6 +2,7 @@
<div class="container"> <div class="container">
<div class="right"> <div class="right">
<?php include(PROJECT_DIR . '/application/controller/common/module/menu.php') ?> <?php include(PROJECT_DIR . '/application/controller/common/module/menu.php') ?>
<?php include(PROJECT_DIR . '/application/controller/common/module/users.php') ?>
</div> </div>
<div class="left"> <div class="left">
<?php include(PROJECT_DIR . '/application/controller/common/module/post.php') ?> <?php include(PROJECT_DIR . '/application/controller/common/module/post.php') ?>

3
src/bootstrap.php

@ -89,6 +89,9 @@ if (isset($_GET['_route_'])) {
case 'api/follow/delete': case 'api/follow/delete':
require(PROJECT_DIR . '/application/controller/api/follow/delete.php'); require(PROJECT_DIR . '/application/controller/api/follow/delete.php');
break; break;
case 'api/user/random':
require(PROJECT_DIR . '/application/controller/api/user/random.php');
break;
// Multi-attribute pages // Multi-attribute pages
default: default:

2
src/config-default.php

@ -30,3 +30,5 @@ define('APPLICATION_MAX_POST_SPLIT', 5);
define('APPLICATION_MAX_POST_FEED', 50); define('APPLICATION_MAX_POST_FEED', 50);
define('APPLICATION_USER_REGISTRATION_TIMEOUT', 86400); define('APPLICATION_USER_REGISTRATION_TIMEOUT', 86400);
define('APPLICATION_MODULE_USERS_LIMIT', 5);

33
src/public/css/template/default/module/users.css

@ -0,0 +1,33 @@
.moduleUsers .item {
padding: 16px;
margin-bottom: 2px;
color: #1c1d1e;
background: rgba(238, 238, 238, 0.08);
border-radius: 3px;
}
.moduleUsers .item.active a,
.moduleUsers .item.active a:visited,
.moduleUsers .item.active a:active {
color: #1c1d1e;
}
.moduleUsers .item .avatar {
position: absolute;
top: 16px;
left: 16px;
}
.moduleUsers .item .avatar img {
border-radius: 50%;
border: 2px #fff solid;
width: 16px;
height: 16px;
}
.moduleUsers .item .info {
padding-left: 40px;
padding-right: 32px;
letter-spacing: 0.2px;
font-size: 13px;
}

1
src/public/js/home.js

@ -3,6 +3,7 @@ $(document).ready(function() {
// Init modules // Init modules
ModuleMenu.init('/'); ModuleMenu.init('/');
ModuleFeed.load('#moduleFeed', true); ModuleFeed.load('#moduleFeed', true);
ModuleUsers.load('#moduleUsers', true);
// Event listeners // Event listeners
$(document).on('ModulePost.add:success', function(/*event, response*/) { $(document).on('ModulePost.add:success', function(/*event, response*/) {

63
src/public/js/module/users.js

@ -0,0 +1,63 @@
var ModuleUsers = {
template: {
list: {
item: {
append: function(list, userName) {
$(list).append(
$('<div/>', {
'class': 'item' + (userName == $(list).data('username') ? ' active' : '')
}).append(
$('<div/>', {
'class': 'avatar'
}).append(
$('<a/>', {
'href': 'people/' + userName
}).append(
$('<img/>', {
'src': '/api/image?hash=' + userName,
'alt': '',
})
)
)
).append(
$('<div/>', {
'class': 'info'
}).append(
$('<a/>', {
'href': 'people/' + userName
}).append(userName)
)
)
);
}
}
}
},
load: function(list, reFresh) {
$.ajax({
url: 'api/user/random',
type: 'POST',
data: {},
success: function (response) {
if (response.success) {
if (reFresh) {
$(list).html('');
}
$(response.users).each(function() {
ModuleUsers.template.list.item.append(list, this.userName);
});
} else {
alert(response.message);
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
},
}
Loading…
Cancel
Save