Browse Source

implement follow page, fix bugs

main
ghost 3 years ago
parent
commit
c40e0176f3
  1. 11
      src/application/controller/common/module/feed.php
  2. 11
      src/application/controller/common/module/following.php
  3. 10
      src/application/controller/follow.php
  4. 2
      src/application/view/common/module/feed.phtml
  5. 4
      src/application/view/common/module/following.phtml
  6. 19
      src/bootstrap.php
  7. 1
      src/public/css/template/default/app.css
  8. 29
      src/public/css/template/default/module/following.css
  9. 3
      src/public/js/follow.js
  10. 8
      src/public/js/module/feed.js
  11. 10
      src/public/js/module/following.js

11
src/application/controller/common/module/feed.php

@ -1,3 +1,14 @@
<?php <?php
$userName = false;
if (isset($_GET['_route_'])) {
$route = explode('/', $_GET['_route_']);
if (isset($route[1])) {
$userName = filter::userName($route[1]);
}
}
require(PROJECT_DIR . '/application/view/common/module/feed.phtml'); require(PROJECT_DIR . '/application/view/common/module/feed.phtml');

11
src/application/controller/common/module/following.php

@ -1,3 +1,14 @@
<?php <?php
$userName = false;
if (isset($_GET['_route_'])) {
$route = explode('/', $_GET['_route_']);
if (isset($route[1])) {
$userName = filter::userName($route[1]);
}
}
require(PROJECT_DIR . '/application/view/common/module/following.phtml'); require(PROJECT_DIR . '/application/view/common/module/following.phtml');

10
src/application/controller/follow.php

@ -23,4 +23,14 @@ $metaScripts = [
'js/follow.js', 'js/follow.js',
]; ];
// Auto-following
if (isset($_GET['_route_'])) {
$route = explode('/', $_GET['_route_']);
if (isset($route[1])) {
$_twister->follow($_SESSION['userName'], [filter::userName($route[1])]);
}
}
require(PROJECT_DIR . '/application/view/follow.phtml'); require(PROJECT_DIR . '/application/view/follow.phtml');

2
src/application/view/common/module/feed.phtml

@ -1 +1 @@
<div class="moduleFeed" id="moduleFeed"></div> <div class="moduleFeed" id="moduleFeed" data-username="<?php echo $userName ?>"></div>

4
src/application/view/common/module/following.phtml

@ -1,3 +1 @@
<div class="moduleFollowing" id="moduleFollowing"> <div class="moduleFollowing" id="moduleFollowing" data-username="<?php echo $userName ?>"></div>
</div>

19
src/bootstrap.php

@ -52,6 +52,8 @@ if (!session_id()) {
if (isset($_GET['_route_'])) { if (isset($_GET['_route_'])) {
switch ($_GET['_route_']) { switch ($_GET['_route_']) {
// Pages
case '': case '':
require(PROJECT_DIR . '/application/controller/home.php'); require(PROJECT_DIR . '/application/controller/home.php');
break; break;
@ -61,12 +63,16 @@ if (isset($_GET['_route_'])) {
case 'logout': case 'logout':
require(PROJECT_DIR . '/application/controller/logout.php'); require(PROJECT_DIR . '/application/controller/logout.php');
break; break;
/*
case 'follow': case 'follow':
require(PROJECT_DIR . '/application/controller/follow.php'); require(PROJECT_DIR . '/application/controller/follow.php');
break; break;
*/
case 'register': case 'register':
require(PROJECT_DIR . '/application/controller/register.php'); require(PROJECT_DIR . '/application/controller/register.php');
break; break;
// API calls
case 'api/image': case 'api/image':
require(PROJECT_DIR . '/application/controller/api/image.php'); require(PROJECT_DIR . '/application/controller/api/image.php');
break; break;
@ -88,9 +94,22 @@ 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;
// Multi-attribute pages
default:
switch (true) {
// Pages
case preg_match('|^follow[/\w_]?|i', $_GET['_route_']):
require(PROJECT_DIR . '/application/controller/follow.php');
break;
// 404
default: default:
require(PROJECT_DIR . '/application/controller/error/404.php'); require(PROJECT_DIR . '/application/controller/error/404.php');
} }
}
} else { } else {
require(PROJECT_DIR . '/application/controller/home.php'); require(PROJECT_DIR . '/application/controller/home.php');

1
src/public/css/template/default/app.css

@ -23,6 +23,7 @@ a:active {
.container > .left { .container > .left {
position: fixed; position: fixed;
z-index: 99; z-index: 99;
width: 360px
} }
.container > .right { .container > .right {

29
src/public/css/template/default/module/following.css

@ -4,43 +4,56 @@
color: #1c1d1e; color: #1c1d1e;
background: rgba(238, 238, 238, 0.08); background: rgba(238, 238, 238, 0.08);
border-radius: 3px; border-radius: 3px;
min-height: 84px;
} }
.moduleFollowing .item.active {
color: #1c1d1e;
background: rgb(238, 238, 238);
}
.moduleFollowing .item.active a,
.moduleFollowing .item.active a:visited,
.moduleFollowing .item.active a:active {
color: #1c1d1e;
}
.moduleFollowing .item:hover .action i { .moduleFollowing .item:hover .action i {
opacity: 1 opacity: 1
} }
.moduleFollowing .item .avatar { .moduleFollowing .item .avatar {
position: absolute; position: absolute;
top: 19px; top: 16px;
left: 19px; left: 16px;
} }
.moduleFollowing .item .avatar img { .moduleFollowing .item .avatar img {
border-radius: 50%; border-radius: 50%;
border: 2px #fff solid; border: 2px #fff solid;
width: 16px;
height: 16px;
} }
.moduleFollowing .item .action { .moduleFollowing .item .action {
position: absolute; position: absolute;
top: 19px; top: 16px;
right: 19px; right: 16px;
} }
.moduleFollowing .item .action i { .moduleFollowing .item .action i {
color: #96a0b4; color: #96a0b4;
cursor: pointer; cursor: pointer;
margin-bottom: 8px; margin-bottom: 8px;
display: block; display: inline-block;
opacity: 0 opacity: 0
} }
.moduleFollowing .item .action i:hover { .moduleFollowing .item .action i:hover {
color: #fff; color: #cc8989;
} }
.moduleFollowing .item .info { .moduleFollowing .item .info {
padding-left: 73px; padding-left: 40px;
padding-right: 32px; padding-right: 32px;
letter-spacing: 0.2px; letter-spacing: 0.2px;
font-size: 13px; font-size: 13px;

3
src/public/js/follow.js

@ -3,9 +3,12 @@ $(document).ready(function() {
// Init modules // Init modules
ModuleMenu.init('follow'); ModuleMenu.init('follow');
ModuleFollowing.load('#moduleFollowing', true); ModuleFollowing.load('#moduleFollowing', true);
ModuleFeed.load('#moduleFeed', true);
// Event listeners // Event listeners
$(document).on('ModuleFollowing.unFollow:success', function(/*event, response*/) { $(document).on('ModuleFollowing.unFollow:success', function(/*event, response*/) {
ModuleMenu.init('follow'); ModuleMenu.init('follow');
ModuleFollowing.load('#moduleFollowing', true);
ModuleFeed.load('#moduleFeed', true);
}); });
}); });

8
src/public/js/module/feed.js

@ -14,7 +14,7 @@ var ModuleFeed = {
'class': 'info' 'class': 'info'
}).append( }).append(
$('<a/>', { $('<a/>', {
'href': 'follow/' + userName 'href': 'follow/' + reTwist.userName
}).append(reTwist.userName) }).append(reTwist.userName)
).append( ).append(
$('<span/>', { $('<span/>', {
@ -74,7 +74,9 @@ var ModuleFeed = {
$.ajax({ $.ajax({
url: 'api/post/get', url: 'api/post/get',
type: 'POST', type: 'POST',
data: {}, data: {
userName: $(feed).data('username')
},
success: function (response) { success: function (response) {
if (response.success) { if (response.success) {
@ -88,7 +90,7 @@ var ModuleFeed = {
} else { } else {
alert(response.message); console.log(response.message);
} }
}, },

10
src/public/js/module/following.js

@ -5,7 +5,7 @@ var ModuleFollowing = {
append: function(list, userName) { append: function(list, userName) {
$(list).append( $(list).append(
$('<div/>', { $('<div/>', {
'class': 'item' 'class': 'item' + (userName == $(list).data('username') ? ' active' : '')
}).append( }).append(
$('<div/>', { $('<div/>', {
'class': 'avatar' 'class': 'avatar'
@ -31,16 +31,10 @@ var ModuleFollowing = {
$('<div/>', { $('<div/>', {
'class': 'action' 'class': 'action'
}).append( }).append(
$('<i/>', {
'class': 'bi bi-envelope',
'title': 'Direct Message',
'onclick': '',
})
).append(
$('<i/>', { $('<i/>', {
'class': 'bi bi-x-circle', 'class': 'bi bi-x-circle',
'title': 'Unfollow', 'title': 'Unfollow',
'onclick': 'ModuleFollowing.unFollow(\'' + list + '\', \'' + userName + '\', true)', 'onclick': 'ModuleFollowing.unFollow(\'' + list + '\', \'' + userName + '\', false)',
}) })
) )
) )

Loading…
Cancel
Save