-
Notifications
You must be signed in to change notification settings - Fork 45
/
profile.php
131 lines (129 loc) · 4.37 KB
/
profile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
session_start();
$user_id = $_SESSION['user_id'];
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=425px, user-scalable=no">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<title>Twitter-like-system-PHP</title>
</head>
<body style="margin-left:20px;width:300px;zoom:125%;">
<h3>Twitter-Like-System-PHP</h3>
<a href='.'>Go Home</a>
<?php
function getTime($t_time){
$pt = time() - $t_time;
if ($pt>=86400)
$p = date("F j, Y",$t_time);
elseif ($pt>=3600)
$p = (floor($pt/3600))."h";
elseif ($pt>=60)
$p = (floor($pt/60))."m";
else
$p = $pt."s";
return $p;
}
if($_GET['username']){
include 'connect.php';
$username = strtolower($_GET['username']);
$query = mysql_query("SELECT id, username, followers, following, tweets
FROM users
WHERE username='$username'
");
mysql_close($conn);
if(mysql_num_rows($query)>=1){
$row = mysql_fetch_assoc($query);
$id = $row['id'];
$username = $row['username'];
$tweets = $row['tweets'];
$followers = $row['followers'];
$following = $row['following'];
if($user_id){
if($user_id!=$id){
include 'connect.php';
$query2 = mysql_query("SELECT id
FROM following
WHERE user1_id='$user_id' AND user2_id='$id'
");
mysql_close($conn);
if(mysql_num_rows($query2)>=1){
echo "<a href='unfollow.php?userid=$id&username=$username' class='btn btn-default btn-xs' style='float:right;'>Unfollow</a>";
}
else{
echo "<a href='follow.php?userid=$id&username=$username' class='btn btn-info btn-xs' style='float:right;'>Follow</a>";
}
}
}
else{
echo "<a href='./register.php' class='btn btn-info btn-xs' style='float:right;'>Signup</a>";
}
echo "
<table style='margin-bottom:5px;'>
<tr>
<td>
<img src='./default.jpg' style='width:35px;'alt='display picture'/>
</td>
<td valign='top' style='padding-left:8px;'>
<h6><a href='./$username'>@$username</a>";
include 'connect.php';
$query3 = mysql_query("SELECT id
FROM following
WHERE user1_id='$id' AND user2_id='$user_id'
");
mysql_close($conn);
if(mysql_num_rows($query3)>=1){
echo " - <i>Follows You</i>";
}
echo "</h6>
<h6 style='width:300px;margin-top:-10px;'>Tweets: <a href='#'>$tweets</a> | Followers: <a href='#'>$followers</a> | Following: <a href='#'>$following</a></h6>
</td>
</tr>
</table>
";
include "connect.php";
$tweets = mysql_query("SELECT username, tweet, timestamp
FROM tweets
WHERE user_id = $id
ORDER BY timestamp DESC
LIMIT 0, 10
");
while($tweet = mysql_fetch_array($tweets)){
echo "<div class='well well-sm' style='padding-top:4px;padding-bottom:8px; margin-bottom:8px; overflow:hidden;'>";
echo "<div style='font-size:10px;float:right;'>".getTime($tweet['timestamp'])."</div>";
echo "<table>";
echo "<tr>";
echo "<td valign=top style='padding-top:4px;'>";
echo "<img src='./default.jpg' style='width:35px;'alt='display picture'/>";
echo "</td>";;
echo "<td style='padding-left:5px;word-wrap: break-word;' valign=top>";
echo "<a style='font-size:12px;' href='./".$tweet['username']."'>@".$tweet['username']."</a>";
$new_tweet = preg_replace('/@(\\w+)/','<a href=./$1>$0</a>',$tweet['tweet']);
$new_tweet = preg_replace('/#(\\w+)/','<a href=./hashtag/$1>$0</a>',$new_tweet);
echo "<div style='font-size:10px; margin-top:-3px;'>".$new_tweet."</div>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</div>";
}
mysql_close($conn);
}
else{
echo "<div class='alert alert-danger'>Sorry, this profile doesn't exist.</div>";
echo "<a href='.' style='width:300px;' class='btn btn-info'>Go Home</a>";
}
}
?>
<br>
<div class="jumbotron" style="padding:3px;">
<div class="container">
<h5>Made by <a href="http://simarsingh.com">Simar</a></h5>
<h5>This is Open Source - Fork it on <i class="fa fa-github"></i> <a href="https://github.com/iSimar/Twitter-Like-System-PHP">GitHub</a></h5>
</div>
</div>
</body>
</html>