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 @@ @@ -1,3 +1,14 @@
<?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');

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

@ -1,3 +1,14 @@ @@ -1,3 +1,14 @@
<?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');

10
src/application/controller/follow.php

@ -23,4 +23,14 @@ $metaScripts = [ @@ -23,4 +23,14 @@ $metaScripts = [
'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');

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

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

19
src/bootstrap.php

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

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

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

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

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

3
src/public/js/follow.js

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

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

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

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

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

Loading…
Cancel
Save