-
Notifications
You must be signed in to change notification settings - Fork 1
/
single-log.php
142 lines (136 loc) · 6.82 KB
/
single-log.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
132
133
134
135
136
137
138
139
140
141
142
<?php
$page_name = "single";
include "inc/head.php";
$log = new Log();
$log = $log->find_by_id($_GET["log_id"]);
$user = new User();
$user = $user->find_by_id($log->user_id);
$log->title = str_replace("\\", "", $log->title);
$log->body = str_replace("\\", "", $log->body);
$log->notes = str_replace("\\", "", $log->notes);
?>
<?php if($session->is_logged_in()): ?>
<div id="profile-workouts">
<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">
<img src="<?php echo $user->profile_picture; ?>" alt="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=single-log";
$fav_text = "Unfavorite";
} else {
$fav_url = "fav.php?log_id={$log->log_id}&from_page=single-log";
$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 -->
</div> <!-- #profile-workouts -->
<?php else: // not logged in ?>
<div id="profile-workouts">
<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">
<img src="<?php echo $user->profile_picture; ?>" alt="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 -->
<p class="log-favorite"><a href="#"><span class="glyph general">c</span> Favorites<?php echo " (" . $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">
<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 -->
</div> <!-- #profile-workouts -->
<?php endif; ?>
<?php include "inc/footer.php"; ?>