1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category modules
|
5
|
* @package news
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
8
|
* @link http://www.websitebaker2.org/
|
9
|
* @license http://www.gnu.org/licenses/gpl.html
|
10
|
* @platform WebsiteBaker 2.8.x
|
11
|
* @requirements PHP 5.2.2 and higher
|
12
|
* @version $Id: submit_comment.php 1538 2011-12-10 15:06:15Z Luisehahne $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/tags/2.8.3/wb/modules/news/submit_comment.php $
|
14
|
* @lastmodified $Date: 2011-12-10 16:06:15 +0100 (Sat, 10 Dec 2011) $
|
15
|
*
|
16
|
*/
|
17
|
|
18
|
// Include config file
|
19
|
require('../../config.php');
|
20
|
|
21
|
/*
|
22
|
overwrite php.ini on Apache servers for valid SESSION ID Separator
|
23
|
if(function_exists('ini_set')) {
|
24
|
ini_set('arg_separator.output', '&');
|
25
|
}
|
26
|
*/
|
27
|
|
28
|
require_once(WB_PATH.'/framework/class.wb.php');
|
29
|
$wb = new wb;
|
30
|
|
31
|
/*
|
32
|
$post_id = (int)$_GET['post_id'];
|
33
|
$section_id = (int)$_GET['section_id'];
|
34
|
if (!$wb->checkFTAN())
|
35
|
{
|
36
|
$wb->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], WB_URL."/modules/news/comment.php?post_id=".$post_id."§ion_id=".$section_id);
|
37
|
}
|
38
|
*/
|
39
|
// Get page id
|
40
|
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
|
41
|
$page_id = intval(isset(${$requestMethod}['page_id'])) ? ${$requestMethod}['page_id'] : (isset($page_id) ? intval($page_id) : 0);
|
42
|
// Get post_id
|
43
|
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
|
44
|
$post_id = (intval(isset(${$requestMethod}['post_id'])) ? ${$requestMethod}['post_id'] : (isset($post_id) ? intval($post_id) : 0));
|
45
|
// Get section id if there is one
|
46
|
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
|
47
|
$section_id = intval(isset(${$requestMethod}['section_id'])) ? ${$requestMethod}['section_id'] : (isset($section_id) ? intval($section_id) : 0);
|
48
|
|
49
|
// Check if we should show the form or add a comment
|
50
|
if(isset($_GET['page_id']) AND is_numeric($_GET['page_id'])
|
51
|
AND isset($_GET['section_id']) AND is_numeric($_GET['section_id'])
|
52
|
AND isset($_GET['post_id']) AND is_numeric($_GET['post_id'])
|
53
|
AND ( ( ENABLED_ASP AND isset($_POST['comment_'.date('W')]) AND $_POST['comment_'.date('W')] != '')
|
54
|
OR ( !ENABLED_ASP AND isset($_POST['comment']) AND $_POST['comment'] != '' ) ) )
|
55
|
{
|
56
|
|
57
|
if(ENABLED_ASP){
|
58
|
$comment = $_POST['comment_'.date('W')];
|
59
|
}
|
60
|
else
|
61
|
{
|
62
|
$comment = $_POST['comment'];
|
63
|
}
|
64
|
|
65
|
$comment = $wb->add_slashes(strip_tags($comment));
|
66
|
$title = $wb->add_slashes(strip_tags($_POST['title']));
|
67
|
// do not allow droplets in user input!
|
68
|
$title = str_replace(array("[[", "]]"), array("[[", "]]"), $title);
|
69
|
$comment = str_replace(array("[[", "]]"), array("[[", "]]"), $comment);
|
70
|
|
71
|
$page_id = (int)$_GET['page_id'];
|
72
|
$section_id = (int)$_GET['section_id'];
|
73
|
$post_id = (int)$_GET['post_id'];
|
74
|
|
75
|
// Check captcha
|
76
|
$query_settings = $database->query("SELECT use_captcha FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'");
|
77
|
if( !$query_settings->numRows())
|
78
|
{
|
79
|
header("Location: ".WB_URL.PAGES_DIRECTORY."");
|
80
|
exit( 0 );
|
81
|
}
|
82
|
else
|
83
|
{
|
84
|
$settings = $query_settings->fetchRow();
|
85
|
$t=time();
|
86
|
|
87
|
// Advanced Spam Protection
|
88
|
if(ENABLED_ASP AND ( ($_SESSION['session_started']+ASP_SESSION_MIN_AGE > $t) // session too young
|
89
|
OR (!isset($_SESSION['comes_from_view']))// user doesn't come from view.php
|
90
|
OR (!isset($_SESSION['comes_from_view_time']) OR $_SESSION['comes_from_view_time'] > $t-ASP_VIEW_MIN_AGE) // user is too fast
|
91
|
OR (!isset($_SESSION['submitted_when']) OR !isset($_POST['submitted_when'])) // faked form
|
92
|
OR ($_SESSION['submitted_when'] != $_POST['submitted_when']) // faked form
|
93
|
OR ($_SESSION['submitted_when'] > $t-ASP_INPUT_MIN_AGE && !isset($_SESSION['captcha_retry_news'])) // user too fast
|
94
|
OR ($_SESSION['submitted_when'] < $t-43200) // form older than 12h
|
95
|
OR ($_POST['email'] OR $_POST['url'] OR $_POST['homepage'] OR $_POST['comment']) /* honeypot-fields */ ) )
|
96
|
{
|
97
|
header("Location: ".WB_URL.PAGES_DIRECTORY."");
|
98
|
exit( 0 );
|
99
|
}
|
100
|
|
101
|
if(ENABLED_ASP)
|
102
|
{
|
103
|
if(isset($_SESSION['captcha_retry_news']))
|
104
|
{
|
105
|
unset($_SESSION['captcha_retry_news']);
|
106
|
}
|
107
|
}
|
108
|
|
109
|
if($settings['use_captcha'])
|
110
|
{
|
111
|
if(isset($_POST['captcha']) AND $_POST['captcha'] != '')
|
112
|
{
|
113
|
// Check for a mismatch
|
114
|
if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha'])
|
115
|
{
|
116
|
$_SESSION['captcha_error'] = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
|
117
|
$_SESSION['comment_title'] = $title;
|
118
|
$_SESSION['comment_body'] = $comment;
|
119
|
header("Location: ".WB_URL."/modules/news/comment.php?post_id=".$post_id."§ion_id=".$section_id."" );
|
120
|
exit( 0 );
|
121
|
}
|
122
|
}
|
123
|
else
|
124
|
{
|
125
|
$_SESSION['captcha_error'] = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
|
126
|
$_SESSION['comment_title'] = $title;
|
127
|
$_SESSION['comment_body'] = $comment;
|
128
|
header("Location: ".WB_URL."/modules/news/comment.php?post_id=".$post_id."§ion_id=".$section_id."" );
|
129
|
exit( 0 );
|
130
|
}
|
131
|
}
|
132
|
}
|
133
|
|
134
|
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
|
135
|
|
136
|
if(ENABLED_ASP)
|
137
|
{
|
138
|
unset($_SESSION['comes_from_view']);
|
139
|
unset($_SESSION['comes_from_view_time']);
|
140
|
unset($_SESSION['submitted_when']);
|
141
|
}
|
142
|
|
143
|
// Insert the comment into db
|
144
|
$commented_when = time();
|
145
|
if($wb->is_authenticated() == true)
|
146
|
{
|
147
|
$commented_by = $wb->get_user_id();
|
148
|
}
|
149
|
else
|
150
|
{
|
151
|
$commented_by = '';
|
152
|
}
|
153
|
|
154
|
$query = $database->query("INSERT INTO ".TABLE_PREFIX."mod_news_comments (section_id,page_id,post_id,title,comment,commented_when,commented_by) VALUES ('$section_id','$page_id','$post_id','$title','$comment','$commented_when','$commented_by')");
|
155
|
// Get page link
|
156
|
$query_page = $database->query("SELECT link FROM ".TABLE_PREFIX."mod_news_posts WHERE post_id = '$post_id'");
|
157
|
$page = $query_page->fetchRow();
|
158
|
header('Location: '.$wb->page_link($page['link']).'?post_id='.$post_id.'' );
|
159
|
exit( 0 );
|
160
|
}
|
161
|
else
|
162
|
{
|
163
|
if( isset($_GET['post_id']) AND is_numeric($_GET['post_id'])
|
164
|
AND isset($_GET['section_id']) AND is_numeric($_GET['section_id']) )
|
165
|
{
|
166
|
header("Location: ".WB_URL."/modules/news/comment.php?post_id=".(int)$_GET['post_id']."§ion_id=".(int)$_GET['section_id']."" ) ;
|
167
|
exit( 0 );
|
168
|
}
|
169
|
else
|
170
|
{
|
171
|
header("Location: ".WB_URL.PAGES_DIRECTORY."");
|
172
|
exit( 0 );
|
173
|
}
|
174
|
}
|