-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle.php
More file actions
184 lines (158 loc) · 7.44 KB
/
article.php
File metadata and controls
184 lines (158 loc) · 7.44 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
require "includes/config.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Студенческий портал ФКН</title>
<!-- Bootstrap Grid -->
<link rel="stylesheet" type="text/css" href="/media/assets/bootstrap-grid-only/css/grid12.css">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet">
<!-- Custom -->
<link rel="stylesheet" type="text/css" href="/media/css/style.css">
</head>
<body>
<div id="wrapper">
<?php include "includes/header.php";?>
<?php
$article = mysqli_query($connection,"SELECT * FROM `articles` WHERE `id` = ".(int)$_GET['id']);
if(mysqli_num_rows($article)<= 0){
?>
<div id="content">
<div class="container">
<div class="row">
<section class="content__left col-md-8">
<div class="block">
<h3>Запись не найдена!</h3>
<div class="block__content">
<img src="/static/images/<?php echo $art['image']; ?>" style = "max-width: 100%;">
<div class="full-text">
Запрашиваемая Вами запись успешно удалена!
</div>
</div>
</div>
</section>
<section class="content__right col-md-4">
<?php include "includes/sidebar.php"; ?>
</section>
</div>
</div>
</div>
<?php
} else{
$art = mysqli_fetch_assoc($article);
mysqli_query($connection, "UPDATE `articles` SET `views` = `views`+ 1 WHERE `id` = ".(int)$art['id']);
?>
<div id="content">
<div class="container">
<div class="row">
<section class="content__left col-md-8">
<div class="block">
<a><?php echo $art['views'];?> просмотров <a>
<h3><?php echo $art['title']; ?></h3>
<div class="block__content">
<img src="/static/images/<?php echo $art['image']; ?>" style = "max-width: 100%;">
<div class="full-text">
<?php echo $art['text']; ?></div>
</div>
</div>
<div class="block">
<a href="#comment-add-form"> Добавить свой </a>
<h3>Комментарии</h3>
<div class="block__content">
<div class="articles articles__vertical">
<?php
$comments = mysqli_query($connection, "SELECT * FROM `comments` WHERE `articles_id`=" . (int) $art['id']);
if(mysqli_num_rows($comments) <= 0)
{
echo "Комментариев пока нет!";
}
while($comment = mysqli_fetch_assoc($comments)) {
?>
<article class="article">
<div class="article__image" style="background-image: url(https://www.gravatar.com/avatar/<?php echo md5($comment['email']); ?>)"></div>
<div class="article__info">
<a href="article.php?id=<?php echo $comment['articles_id']; ?>"><?php echo $comment['author']; ?></a>
<div class="article__info__meta"> </div>
<div class="article__info__preview"><?php echo $comment['text']; ?></div>
</div>
</article>
<?php
}
?>
</div>
</div>
</div>
<div class="block" id="comment-add-form">
<h3>Добавить комментарий</h3>
<div class="block__content">
<form class="form" method="POST" action="/article.php?id=<?php echo $art['id']; ?>#comment-add-form">
<?php
if (isset($_POST['do_post'])) {
$errors = array();
if($_POST['name'] == '')
{
$errors[] = 'Введите имя!';
}
if($_POST['nickname'] == '')
{
$errors[] = 'Введите Ваш никнейм!';
}
if($_POST['email'] == '')
{
$errors[] = 'Введите Email!';
}
if($_POST['text'] == '')
{
$errors[] = 'Введите текст комментария!';
}
if(empty($errors)){
#add somment
mysqli_query($connection, "INSERT INTO `comments` (`author`,`nickname`,`email`,`text`,`pubdate`,`articles_id`) VALUES ('".$_POST['name']."','".$_POST['nickname']."','".$_POST['email']."','".$_POST['text']."',NOW(),'".$art['id']."')");
echo '<span style="color: green; font-weight:bold; margin-bottom: 10px; display: block;">Комментарий успешно добавлен!</span>';
} else
{
#output error
echo '<span style="color: red; font-weight:bold; margin-bottom: 10px; display: block;">'.$errors['0'].'</span>';
}
}
?>
<div class="form__group">
<div class="row">
<div class="col-md-4">
<input type="text" class="form__control" name="name" placeholder="Имя" value="<?php echo $_POST['name']; ?>">
</div>
<div class="col-md-4">
<input type="text" class="form__control" name="nickname" placeholder="Никнейм"
value="<?php echo $_POST['nickname']; ?>">
</div>
<div class="col-md-4">
<input type="text" class="form__control" name="email" placeholder="Email (не будет показан)" value="<?php echo $_POST['email']; ?>">
</div>
</div>
</div>
<div class="form__group">
<textarea name="text" class="form__control" placeholder="Текст комментария ..."><?php echo $_POST['text'];?> </textarea>
</div>
<div class="form__group">
<input type="submit" class="form__control" name="do_post" value="Добавить комментарий">
</div>
</form>
</div>
</div>
</section>
<section class="content__right col-md-4">
<?php include "includes/sidebar.php"; ?>
</section>
</div>
</div>
</div>
<?php
}
?>
<?php include "includes/footer.php"; ?>
</div>
</body>
</html>