From e788102b9aa05d1a37f7f0886d9235b51b0ad483 Mon Sep 17 00:00:00 2001 From: ghost Date: Thu, 30 Dec 2021 23:54:09 +0200 Subject: [PATCH] implement following module --- src/application/controller/api/follow/get.php | 45 +++++++++++ .../controller/common/module/following.php | 3 + src/application/controller/follow.php | 16 +--- src/application/controller/home.php | 1 + src/application/view/common/header/user.phtml | 1 - .../view/common/module/following.phtml | 3 + src/application/view/follow.phtml | 16 ++-- src/bootstrap.php | 3 + .../css/template/default/module/following.css | 47 +++++++++++ src/public/js/follow.js | 7 ++ src/public/js/module/following.js | 79 +++++++++++++++++++ 11 files changed, 197 insertions(+), 24 deletions(-) create mode 100644 src/application/controller/common/module/following.php create mode 100644 src/application/view/common/module/following.phtml create mode 100644 src/public/css/template/default/module/following.css create mode 100644 src/public/js/follow.js create mode 100644 src/public/js/module/following.js diff --git a/src/application/controller/api/follow/get.php b/src/application/controller/api/follow/get.php index e69de29..5a35e5e 100644 --- a/src/application/controller/api/follow/get.php +++ b/src/application/controller/api/follow/get.php @@ -0,0 +1,45 @@ + false, + 'message' => _('Internal server error'), + 'users' => [], + 'total' => 0 +]; + +if (isset($_SESSION['userName'])) { + + $userName = isset($_POST['userName']) ? $_POST['userName'] : $_SESSION['userName']; + + $followingUsersTotal = 0; + $followingUsers = []; + + foreach ((array) $_twister->getFollowing($_SESSION['userName']) as $followingUserName) { + + $followingUsers[] = [ + 'userName' => $followingUserName + ]; + + $followingUsersTotal++; + } + + $response = [ + 'success' => true, + 'message' => _('Follow totals received'), + 'users' => $followingUsers, + 'total' => $followingUsersTotal + ]; + +} else { + + $response = [ + 'success' => false, + 'message' => _('Session expired. Please, reload the page.'), + 'users' => [], + 'total' => 0 + ]; + +} + +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/following.php b/src/application/controller/common/module/following.php new file mode 100644 index 0000000..697015c --- /dev/null +++ b/src/application/controller/common/module/following.php @@ -0,0 +1,3 @@ +getFollowing($_SESSION['userName']) as $followingUserName) { - - $followingUsers[] = [ - 'name' => $followingUserName - ]; - - $followingUsersTotal++; -} - require(PROJECT_DIR . '/application/view/follow.phtml'); \ No newline at end of file diff --git a/src/application/controller/home.php b/src/application/controller/home.php index 2539640..108fb68 100644 --- a/src/application/controller/home.php +++ b/src/application/controller/home.php @@ -18,6 +18,7 @@ $metaScripts = [ 'js/module/menu.js', 'js/module/post.js', 'js/module/feed.js', + 'js/home.js', ]; require(PROJECT_DIR . '/application/view/home.phtml'); \ No newline at end of file diff --git a/src/application/view/common/header/user.phtml b/src/application/view/common/header/user.phtml index 9ef7366..352a8ae 100644 --- a/src/application/view/common/header/user.phtml +++ b/src/application/view/common/header/user.phtml @@ -17,7 +17,6 @@ -
diff --git a/src/application/view/common/module/following.phtml b/src/application/view/common/module/following.phtml new file mode 100644 index 0000000..bce16b7 --- /dev/null +++ b/src/application/view/common/module/following.phtml @@ -0,0 +1,3 @@ +
+ +
\ No newline at end of file diff --git a/src/application/view/follow.phtml b/src/application/view/follow.phtml index 64ac317..3545c20 100644 --- a/src/application/view/follow.phtml +++ b/src/application/view/follow.phtml @@ -1,14 +1,10 @@
-
-
- -
- @ -
- -

-
+
+ + +
+
+
-
\ No newline at end of file diff --git a/src/bootstrap.php b/src/bootstrap.php index ac3f479..73922c6 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -76,6 +76,9 @@ if (isset($_GET['_route_'])) { case 'api/post/get': require(PROJECT_DIR . '/application/controller/api/post/get.php'); break; + case 'api/follow/get': + require(PROJECT_DIR . '/application/controller/api/follow/get.php'); + break; default: require(PROJECT_DIR . '/application/controller/error/404.php'); } diff --git a/src/public/css/template/default/module/following.css b/src/public/css/template/default/module/following.css new file mode 100644 index 0000000..a8a64ba --- /dev/null +++ b/src/public/css/template/default/module/following.css @@ -0,0 +1,47 @@ +.moduleFollowing .item { + padding: 16px; + margin-bottom: 2px; + color: #1c1d1e; + background: rgba(238, 238, 238, 0.08); + border-radius: 3px; + min-height: 84px; +} +.moduleFollowing .item:hover .action i { + opacity: 1 +} + +.moduleFollowing .item .avatar { + position: absolute; + top: 19px; + left: 19px; +} + +.moduleFollowing .item .avatar img { + border-radius: 50%; + border: 2px #fff solid; +} + +.moduleFollowing .item .action { + position: absolute; + top: 19px; + right: 19px; +} + +.moduleFollowing .item .action i { + color: #96a0b4; + cursor: pointer; + margin-bottom: 8px; + display: block; + opacity: 0 +} + +.moduleFollowing .item .action i:hover { + color: #fff; +} + +.moduleFollowing .item .info { + padding-left: 73px; + padding-right: 32px; + letter-spacing: 0.2px; + font-size: 13px; +} \ No newline at end of file diff --git a/src/public/js/follow.js b/src/public/js/follow.js new file mode 100644 index 0000000..f4206ca --- /dev/null +++ b/src/public/js/follow.js @@ -0,0 +1,7 @@ +$(document).ready(function() { + + // Init modules + ModuleMenu.init('follow'); + ModuleFollowing.load('#moduleFollowing', true); + +}); \ No newline at end of file diff --git a/src/public/js/module/following.js b/src/public/js/module/following.js new file mode 100644 index 0000000..2669422 --- /dev/null +++ b/src/public/js/module/following.js @@ -0,0 +1,79 @@ +var ModuleFollowing = { + template: { + list: { + item: { + append: function(list, userName) { + $(list).append( + $('
', { + 'class': 'item' + }).append( + $('
', { + 'class': 'avatar' + }).append( + $('', { + 'href': 'follow/' + userName + }).append( + $('', { + 'src': '/api/image?hash=' + userName, + 'alt': '', + }) + ) + ) + ).append( + $('
', { + 'class': 'info' + }).append( + $('', { + 'href': 'follow/' + userName + }).append(userName) + ) + ).append( + $('
', { + 'class': 'action' + }).append( + $('', { + 'class': 'bi bi-envelope', + 'title': 'Direct Message', + 'onclick': '', + }) + ).append( + $('', { + 'class': 'bi bi-x-circle', + 'title': 'Unfollow', + 'onclick': '', + }) + ) + ) + ); + } + } + } + }, + load: function(list, reFresh) { + $.ajax({ + url: 'api/follow/get', + type: 'POST', + data: {}, + success: function (response) { + if (response.success) { + + if (reFresh) { + $(list).html(''); + } + + $(response.users).each(function() { + ModuleFollowing.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