-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
171 lines (152 loc) · 5.13 KB
/
index.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
include_once 'php/inc/config.php';
session_start();
//check if your sign in
if(!$_SESSION['id']){
header("location: sign-in");
}
?>
<!----header -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./css/core.css" />
<!----header css--->
<link rel="stylesheet" href="./css/components/header.css" />
<!----add post css--->
<link rel="stylesheet" href="./css/components/add-post.css" />
<!----posts css--->
<link rel="stylesheet" href="./css/home.css" />
<title>Home</title>
</head>
<body>
<div class="header">
<nav>
<ul>
<a href="./" class="a-active">Home</a>
<a href="user/<?php echo $_SESSION['id']?>">Profile</a>
</ul>
</nav>
<button class=log-out>log out</button>
</div>
<!---END Header -->
<!---add new post form-->
<form class="add-post" enctype=multipart/form-data>
<!--add-post-header--->
<div class="add-post-header">
<h2>Add New Post</h2>
</div>
<!--add-post-header--->
<!---post-context-->
<textarea class="post-context" role="textbox" contenteditable name="context"></textarea>
<!---post-context END-->
<!---button -->
<div class="buttons">
<button id=submit>Publish</button>
<input type="file" class="input-image" name=image />
</div>
<!---button END-->
</form>
<!---add new post form END-->
<!-----add-post-action----->
<div class="add-post-action">
<!------action----->
<div class="action">
<p></p>
<button></button>
</div>
<!------action-END---->
</div>
<!-----add-post-action-END---->
<!------"container-post---->
<div class="container-post">
<?php
//get post from databacse
$posts= mysqli_query($conn,'SELECT * FROM posts ORDER BY id_post DESC');
$posts_data= mysqli_fetch_all($posts,MYSQLI_ASSOC);
if(!empty($posts_data)){
// start forech
foreach ($posts_data as $post){?>
<!---post-->
<div class="post">
<!-----post-header--->
<div class="post-header">
<?php //get author info
$get_author= mysqli_query($conn,"SELECT * FROM users WHERE id ={$post['id_author']}");
// check if come data from db
if(mysqli_num_rows($get_author) > 0){
// get all data author
while($author = mysqli_fetch_object($get_author)){
$name_author= $author -> firstName.' '.$author -> lastName; //echo name author
$img_author=$author ->url_img;
}
}
?>
<a href='user/<?php echo $post['id_author'] ?>' class=author-name>
<img src="php/image-user/<?php
if($img_author != NULL){
echo $img_author;
}else{
echo 'default.png';
}
?>" alt="">
<?php echo $name_author?> </a>
<span class=date-post>
<?php echo htmlspecialchars($post['date_post'])?>
</span>
</div>
<!------post-header END------->
<!-----post-content--->
<section class=content-post>
<!---context ---->
<?php
if($post['context'] != null){?>
<p> <?php echo substr(htmlspecialchars($post['context']),0,30). '...'?>
</p>
<?php
}
?>
<!---context END ---->
<!---image post ----->
<?php
// cheak if post have image will show div image
if($post['url_img'] != null){
?>
<div class="image-post">
<img src="php/image-post/<?php echo $post['url_img']?>" alt="">
</div>
<?php
}
?>
<!---image post ----->
<a href="post/<?php echo $post['id_post']?>" class="readmore">Read More</a>
</section>
<!-----post-content END--->
<form class="footer-post">
<button class="like <?php
$is_liked=mysqli_query($conn,"SELECT * FROM like_post WHERE id_user = {$_SESSION['id']} AND id_post={$post['id_post']}");
if(mysqli_num_rows($is_liked) > 0){
echo "like-active";
$like="liked";
}else{$like="like";}?>" ><?echo$like?></button>
<input type="hidden" name="id-post" value="<?php echo $post['id_post'] ?>">
<button class=comments>comments</button>
</form>
</div>
<!---post-->
<?php
}///end forech
}//end if have post
?>
</div>
<!----container-post---->
<!---Footer -->
</body>
<script src="./js/components/add-post.js"></script>
<script src="js/like-post.js"></script>
<script src="js/log-out.js"></script>
</html>
<!---END Footer -->