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