-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
136 lines (114 loc) · 3.43 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
<?php
error_reporting(E_ALL & ~E_NOTICE);
// Add DB config.
require_once("config/config.php");
require_once("utils/utils.print_page.php");
// Forms config.
require_once("config/class.config.dmn.php");
// Add mini framework.
// require_once("config/class.config.php");
// Top page template.
require_once ("templates/top.php");
$title = "Comments";
$keywords = "comments";
if(empty($_POST)) {
$_REQUEST['hide'] = true;
}
$body = new field_textarea("body", "", true, $_POST['body']);
$page = new field_hidden_int("page", "", true, $_REQUEST['page']);
try {
$form = new form(array(
"body" => $body,
"page" => $page
),
"Send",
"field");
}
catch(ExceptionObject $exc) {
// todo catch exception
}
$date = date('Y-m-d H:i:s');
// Catching form...
if(!empty($_POST)) {
try {
// FIXME
//$error = $form->check();
$error = null;
if(empty($error)) {
// SQL insert query for comment.
$query = "INSERT INTO $tbl_comments
VALUES (NULL,
'{$characters[array_rand($characters)]}',
'{$form->fields[body]->value}',
'{$date}'
)";
$core = Core::getInstance();
$stmt = $core->dbh->prepare($query);
$stmt->execute();
// Redirect back.
header("Location: index.php");
exit();
}
}
catch(ExceptionMySQL $exc) {
$a = 123;
// todo catch MYSQL exception
}
}
// Show form error.
if(!empty($error))
{
foreach($error as $err)
{
echo "<span style=\"color:red\">$err</span><br>";
}
}
// Show form.
$form->print_form();
/** Show comments */
if(empty($_GET['id_news'])) {
// Simple sql injection check
$_GET['page'] = intval($_GET['page']);
// Number of comments
$pnumber = 10;
$page_link = 3;
// Call object of page navigation.
$obj = new pager_mysql($tbl_comments,
"",
"ORDER BY putdate DESC",
$pnumber,
$page_link);
// Get content of current page.
$comments = $obj->get_page();
// Если имеется хотя бы одна запись - выводим
if(!empty($comments))
{
echo '<div>';
// Deprecated code
error_reporting(E_ALL & ~E_NOTICE);
$patt = array("[b]", "[/b]", "[i]", "[/i]");
$repl = array("", "", "", "");
$pattern_url = "|\[url[^\]]*\]|";
$pattern_b_url = "|\[/url[^\]]*\]|";
for($i = 0; $i < count($comments); $i++)
{
if(strlen($comments[$i]['body']) > 100)
{
$comments[$i]['body'] = substr($comments[$i]['body'], 0, 100)."...";
$comments[$i]['body'] = str_replace($patt, $repl, $comments[$i]['body']);
$comments[$i]['body'] = preg_replace($pattern_url, "", $comments[$i]['body']);
$comments[$i]['body'] = preg_replace($pattern_b_url, "", $comments[$i]['body']);
}
// Print comment data.
echo '<div class="container"><a href="" class="icon-link"><img src="/files/' . $comments[$i]['name'] . '.png" class="icon"></a><span class="name">' .
print_page($comments[$i]['name']) . '</span><span class="date">' . $comments[$i]['putdate'] .
'</span><span class="body">' . $comments[$i]['body'] . "</span></div>";
}
echo "</div>";
echo "<div class=rightpanel_txt>";
echo $obj;
echo "</div>";
}
}
// Bottom page template.
require_once("utils/bottom.php");