php include system core php pid int _GET pid result mysqli query SELEC

  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
<?php
include '../../system/core.php';
$pid = (int) $_GET['pid'];
$result = $mysqli -> query("
SELECT `author`, `title`, `text`, `time`, `is_comment`, `access` FROM `blog`
WHERE `id` = $pid LIMIT 1
");
if($result -> num_rows == 0) {
Notification::set('Запись не найдена.');
System::go('user/');
}
$post = $result -> fetch_assoc();
if($post['access'] == '2' and $post['author'] != $profile['id']) {
Notification::set('У Вас нет прав на просмотр этой записи.');
System::go('user/');
}
// Добавление комментария
if($_POST['handler'] == 'true') {
$text = $_POST['text'];
if(empty($text) or (strlen($text) > 10000) or $post['is_comment'] == 0) $error = true;
else {
$stmt = $mysqli -> prepare("
INSERT INTO `blog_comments` (`author`, `text`, `post_id`, `time`, `answer`)
VALUES (?, ?, ?, ?, 0)
");
$stmt->bind_param('isii', $profile['id'], $text, $pid, $currentTime);
$stmt->execute();
$stmt->close();
}
}
// Просмотры
if($profile and $profile['id'] != $post['author']) {
$stmt = $mysqli -> prepare("
SELECT `id` FROM `blog_views`
WHERE `post_id` = $pid AND `user_id` = $profile[id]
LIMIT 1
");
$stmt -> execute();
$stmt -> bind_result($vid);
$stmt -> fetch();
$stmt -> close();
if(empty($vid)) {
$mysqli -> query("
INSERT INTO `blog_views` (`user_id`, `post_id`, `time`)
VALUES ($profile[id], $pid, $currentTime)
");
}
}
$stmt = $mysqli -> prepare("
SELECT COUNT(*) FROM `blog_views`
WHERE `post_id` = $pid
");
$stmt -> execute();
$stmt -> bind_result($cviews);
$stmt -> fetch();
$stmt -> close();
$author = User::loginFromId($post['author']);
$stmt = $mysqli -> prepare("
SELECT COUNT(*) FROM `blog_comments`
WHERE `post_id` = $pid
");
$stmt -> execute();
$stmt -> bind_result($ccomments);
$stmt -> fetch();
$stmt -> close();
$query = "
SELECT `text`, `author`, `time`, `id`, `answer` FROM `blog_comments`
WHERE `post_id` = $pid
ORDER BY `id`
";
if($ccomments > 10) {
if($_GET['p'] == 'end') $p = $ccomments;
else $p = ($_GET['p']) ? intval($_GET['p']) : 1;
$pagination = new Pagination(10, $ccomments, $p);
$query .= $pagination -> limit;
}
$result = $mysqli -> query($query);
$page = new Page(String::filter($post['title']) . ' / Блог');
$page -> head();
?>
<?php if($error): ?>
<div class="block red b_bottom">
Ошибка. Добавление комментария невозможно. Причины:<br/>
1. Слишком длинный или пустой комментарий. Максимальная длина: 10000 символов.<br/>
2. Запись закрыта для комментирования.
</div>
<?php endif ?>
<div class="block">
<?php User::printLogin($author) ?> : <span style="color: #069;font-weight: bold"><?php echo String::filter($post['title']) ?></span>
<span style="color: gray">(<?php echo Time::prnt($post['time']) ?>)</span>
<div class="btext" style="padding: 3px">
<?php echo String::filter($post['text'], true, true, true) ?>
</div>
</div>
<div class="blue block b_top">
<a href="<?php echo Config::SITE_NAME_ADDR ?>/blog/edit/?id=<?php echo $pid ?>" class="noneline">
<img src="<?php echo Config::SITE_NAME_ADDR ?>/img/ico/edit.png" alt="edit" class="middle">
<span class="middle">Редактировать</span>
</a>
</div>
<div class="yellow block b_top" id="comments">
<?php if($cviews > 0): ?>
<a href="<?php echo Config::SITE_NAME_ADDR ?>/blog/views/?pid=<?php echo $pid ?>">
<?php echo $cviews . ' ' . String::form($cviews, 'просмотр', 'просмотра', 'просмотров') ?></a>,
<?php endif ?>
<?php echo $ccomments . ' ' . String::form($ccomments, 'комментарий', 'комментария', 'комментариев') ?>
</div>
<?php while($comment = $result -> fetch_assoc()): ?>
<div class="block b_top">
<?php echo User::printLogin(User::loginFromId($comment['author'])) ?>
<span style="color: gray">(<?php echo Time::prnt($comment['time']) ?>)</span>
<?php if($comment['answer']): ?>
ответил <span class="login"><?php echo User::loginFromId($comment['answer']) ?></span>:
<?php endif ?>
<div class="btext" style="padding: 3px">
<?php echo String::filter($comment['text'], true, true, true) ?>
</div>
<a href="<?php echo Config::SITE_NAME_ADDR ?>/blog/comment/?id=<?php echo $comment['id'] ?>">Ответить</a>
<?php if($author == $profile['login']): ?>
<span style="color: gray">|</span>
<a href="<?php echo Config::SITE_NAME_ADDR ?>/blog/comment/?id=<?php echo $comment['id'] ?>&r=comment/delete" style="color: #941515">Удалить</a>
<?php endif ?>
<span style="float: right">
<img src="<?php echo Config::SITE_NAME_ADDR ?>/img/ico/like2.png"/>
<img src="<?php echo Config::SITE_NAME_ADDR ?>/img/ico/like.png"/>
</span>
</div>
<?php endwhile ?>
<?php if($ccomments > 10) $pagination -> printPages('pid=' . $pid . '#comments') ?>
<?php if($post['is_comment'] != 0): ?>
<div class="block b_bottom b_top" style="background-color: #EBEBEB;">
<span style="color: gray">Добавить комментарий:</span>
<form action="<?php echo Config::SITE_NAME_ADDR ?>/blog/read/?pid=<?php echo $pid ?>&p=end" method="POST">
<textarea name="text" rows="4"></textarea>
<br/>
<input type="hidden" name="handler" value="true"/>
<input type="submit" value="Добавить"/>
<a href="<?php echo Config::SITE_NAME_ADDR ?>/help/smiles/">Смайлы</a> <span style="color: gray">|</span>
<a href="<?php echo Config::SITE_NAME_ADDR ?>/help/bbcode/">BBcode</a>
</form>
</div>
<?php else: ?>
<div class="block b_top b_bottom">
Запись закрыта для комментирования.
</div>
<?php endif ?>
<div class="gray block">
<a href="<?php echo Config::SITE_NAME_ADDR ?>/blog/?name=<?php echo $author ?>" class="noneline">
<img src="<?php echo Config::SITE_NAME_ADDR ?>/img/ico/back.png" alt="back">
Блог обитателя <?php echo $author ?>
</a>
</div>
<?php $page -> foot(); ?>