-
Notifications
You must be signed in to change notification settings - Fork 1
/
profile.php
128 lines (122 loc) · 6.17 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
<?php
$page_name = "profile";
include "inc/head.php";
$user = new User();
$user = $user->find_by_id($_GET["user_id"]);
$logs = new Log();
$logs = $logs->find_by_sql("SELECT log_id, title, body, notes, time FROM logs, users WHERE logs.user_id = users.user_id AND users.user_id = {$user->user_id} ORDER BY log_id DESC");
?>
<div id="profile" class="clearfix">
<?php if($user->user_id == $session->user_id): ?>
<a href="upload-picture.php">
<div class="profile-picture" style="background-image: url('<?php echo $user->profile_picture; ?>');"></div>
</a>
<?php else: ?>
<div class="profile-picture" style="background-image: url('<?php echo $user->profile_picture; ?>');"></div>
<?php endif; ?>
<div class="profile-name">
<h3><?php echo $user->username; ?></h3>
</div>
<div class="social-activity">
<p><span class="workouts"><?php echo $user->find_number_of_logs($user->user_id); ?></span>Workouts</p>
<a href="followers.php?user_id=<?php echo $user->user_id; ?>"><span class="followers"><?php echo $user->find_number_of_followers($user->user_id); ?></span>Followers</a>
<a href="following.php?user_id=<?php echo $user->user_id; ?>"><span class="following"><?php echo $user->find_number_of_following($user->user_id); ?></span>Following</a>
</div>
</div>
<div class="profile-follow clearfix">
<?php if($session->user_id == $user->user_id): ?>
<?php if($user->profile_picture == "/uploads/default.png"): ?>
<p>You can change your profile picture by clicking on it!</p>
<?php endif; ?>
<?php elseif($user->is_following($user->user_id, $session->user_id)): ?>
<a href="unfollow.php?user_id=<?php echo $user->user_id; ?>" class="unfollow">Unfollow</a>
<?php else: ?>
<a href="follow.php?user_id=<?php echo $user->user_id; ?>" class="follow">Follow</a>
<?php endif; ?>
</div>
<?php if(empty($logs)): ?>
<div id="no-profile-workouts">
<p>Sadly, <?php echo $user->username; ?> hasn't logged any workouts yet.</p>
</div><!-- #profile-workouts -->
<?php else: ?>
<div id="profile-workouts">
<?php
foreach($logs as $log):
$log->title = str_replace("\\", "", $log->title);
$log->body = str_replace("\\", "", $log->body);
$log->notes = str_replace("\\", "", $log->notes);
?>
<div class="log clearfix">
<div class="log-header clearfix">
<div class="log-time">
<p><?php echo $log->time; ?></p>
</div> <!-- .log-time -->
<div class="profile-picture" style="background-image: url('<?php echo $user->profile_picture; ?>');">
</div> <!-- .profile-picture -->
<div class="log-title">
<p class="profile-name"><?php echo $user->username; ?></p>
<p><?php echo $log->title; ?></p>
</div> <!-- .log-title -->
</div> <!-- .log-header -->
<div class="log-footer">
<span class="log-expand <?php if(isset($_GET["log_id_commented_on"]) && $_GET["log_id_commented_on"] == $log->log_id){ echo "open"; } ?>">Show more!</span>
<div class="expanded-log">
<div class="expanded-log-text clearfix">
<?php echo $log->body; ?>
</div> <!-- .expanded-log-text -->
<?php if(strlen($log->notes) > 1): ?>
<div class="expanded-log-text clearfix">
<strong>Notes</strong>
<p>
<?php echo $log->notes; ?>
</p>
</div> <!-- .expanded-log-text -->
<?php endif; ?>
<?php
$fav_url = "";
$fav_text = "";
if($log->is_faved()){
$fav_url = "unfav.php?log_id={$log->log_id}&from_page=timeline";
$fav_text = "Unfavorite";
} else {
$fav_url = "fav.php?log_id={$log->log_id}&from_page=timeline";
$fav_text = "Favorite";
}
?>
<p class="log-favorite <?php if($log->is_faved()){ echo "faved"; } ?>"><a href="<?php echo $fav_url; ?>"><span class="glyph general">c</span> <?php echo $fav_text . " (" . $log->number_of_favs() . ")"; ?></a></p>
<p class="log-comment"><a href=""><span class="glyph social">w</span> Comment (<?php echo $log->number_of_comments(); ?>)</a></p>
<div class="commenting-log clearfix">
<form action="comment.php" method="post">
<input type="text" name="comment" placeholder="Write you comment here" id="writing-comment-log">
<input type="hidden" name="log_id" value="<?php echo $log->log_id; ?>">
<input type="hidden" name="user_id" value="<?php echo $user->user_id; ?>">
<input type="hidden" name="from_page" value="profile">
</form>
<div class="log-comments-list">
<?php
$comments = new Comment();
$comments = $comments->find_by_sql("SELECT comment.body, comment.time, comment.user_id, users.username FROM comment, users, logs WHERE logs.log_id = {$log->log_id} AND comment.log_id = logs.log_id AND users.user_id = comment.user_id");
?>
<?php if(empty($comments)): ?>
Nothing to see here.
<?php else: ?>
<h4>Comments</h4>
<?php
foreach($comments as $comment):
$comment->body = str_replace("\\", "", $comment->body);
?>
<div class="log-single-comment">
<span class="comment-time"><?php echo $comment->time; ?></span><a href="profile.php?user_id=<?php echo $comment->user_id; ?>"><a href="profile.php?user_id=<?php echo $comment->user_id; ?>"><?php echo $comment->username; ?></a></a>
<p><?php echo $comment->body; ?></p>
</div> <!-- .log-single-comment -->
<?php endforeach; ?>
<?php endif; ?>
</div> <!-- .log-comments-lits -->
</div> <!-- .commenting-log -->
</div> <!-- .expanded-log -->
</div> <!-- .log-footer -->
</div> <!-- .log -->
<?php endforeach; ?>
</div> <!-- #profile-workouts -->
<?php endif; ?>
<?php include "inc/footer.php"; ?>