diff --git a/src/application/controller/api/user/random.php b/src/application/controller/api/user/random.php new file mode 100644 index 0000000..9892a16 --- /dev/null +++ b/src/application/controller/api/user/random.php @@ -0,0 +1,30 @@ + 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); \ No newline at end of file diff --git a/src/application/controller/common/module/users.php b/src/application/controller/common/module/users.php new file mode 100644 index 0000000..2534019 --- /dev/null +++ b/src/application/controller/common/module/users.php @@ -0,0 +1,3 @@ +_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) { try { diff --git a/src/application/view/common/module/users.phtml b/src/application/view/common/module/users.phtml new file mode 100644 index 0000000..7820c30 --- /dev/null +++ b/src/application/view/common/module/users.phtml @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/src/application/view/home.phtml b/src/application/view/home.phtml index aee893a..eb87ac6 100644 --- a/src/application/view/home.phtml +++ b/src/application/view/home.phtml @@ -2,6 +2,7 @@
+
diff --git a/src/bootstrap.php b/src/bootstrap.php index 6ec7c37..3f2d658 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -89,6 +89,9 @@ if (isset($_GET['_route_'])) { case 'api/follow/delete': require(PROJECT_DIR . '/application/controller/api/follow/delete.php'); break; + case 'api/user/random': + require(PROJECT_DIR . '/application/controller/api/user/random.php'); + break; // Multi-attribute pages default: diff --git a/src/config-default.php b/src/config-default.php index 96af268..f8aedf0 100644 --- a/src/config-default.php +++ b/src/config-default.php @@ -29,4 +29,6 @@ define('APPLICATION_FOLLOW_ON_REGISTRATION', []); define('APPLICATION_MAX_POST_SPLIT', 5); define('APPLICATION_MAX_POST_FEED', 50); -define('APPLICATION_USER_REGISTRATION_TIMEOUT', 86400); \ No newline at end of file +define('APPLICATION_USER_REGISTRATION_TIMEOUT', 86400); + +define('APPLICATION_MODULE_USERS_LIMIT', 5); \ No newline at end of file diff --git a/src/public/css/template/default/module/users.css b/src/public/css/template/default/module/users.css new file mode 100644 index 0000000..1b01817 --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/src/public/js/home.js b/src/public/js/home.js index 3fbe5d7..9790a05 100644 --- a/src/public/js/home.js +++ b/src/public/js/home.js @@ -3,6 +3,7 @@ $(document).ready(function() { // Init modules ModuleMenu.init('/'); ModuleFeed.load('#moduleFeed', true); + ModuleUsers.load('#moduleUsers', true); // Event listeners $(document).on('ModulePost.add:success', function(/*event, response*/) { diff --git a/src/public/js/module/users.js b/src/public/js/module/users.js new file mode 100644 index 0000000..6f23f81 --- /dev/null +++ b/src/public/js/module/users.js @@ -0,0 +1,63 @@ +var ModuleUsers = { + template: { + list: { + item: { + append: function(list, userName) { + $(list).append( + $('
', { + 'class': 'item' + (userName == $(list).data('username') ? ' active' : '') + }).append( + $('
', { + 'class': 'avatar' + }).append( + $('', { + 'href': 'people/' + userName + }).append( + $('', { + 'src': '/api/image?hash=' + userName, + 'alt': '', + }) + ) + ) + ).append( + $('
', { + 'class': 'info' + }).append( + $('', { + '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); + } + }); + }, +} \ No newline at end of file