1 |
562
|
Ruebenwurz
|
<?php
|
2 |
|
|
|
3 |
|
|
// $Id$
|
4 |
|
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
915
|
Ruebenwurz
|
Copyright (C) 2004-2009, Ryan Djurovich
|
9 |
562
|
Ruebenwurz
|
|
10 |
|
|
Website Baker is free software; you can redistribute it and/or modify
|
11 |
|
|
it under the terms of the GNU General Public License as published by
|
12 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
(at your option) any later version.
|
14 |
|
|
|
15 |
|
|
Website Baker is distributed in the hope that it will be useful,
|
16 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
GNU General Public License for more details.
|
19 |
|
|
|
20 |
|
|
You should have received a copy of the GNU General Public License
|
21 |
|
|
along with Website Baker; if not, write to the Free Software
|
22 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
|
24 |
|
|
*/
|
25 |
|
|
|
26 |
|
|
// Include config file
|
27 |
|
|
require('../../config.php');
|
28 |
|
|
|
29 |
892
|
Ruebenwurz
|
//overwrite php.ini on Apache servers for valid SESSION ID Separator
|
30 |
|
|
if(function_exists('ini_set')) {
|
31 |
|
|
ini_set('arg_separator.output', '&');
|
32 |
|
|
}
|
33 |
|
|
|
34 |
562
|
Ruebenwurz
|
require_once(WB_PATH.'/framework/class.wb.php');
|
35 |
|
|
$wb = new wb;
|
36 |
|
|
|
37 |
|
|
// Check if we should show the form or add a comment
|
38 |
656
|
thorn
|
if(isset($_GET['page_id']) AND is_numeric($_GET['page_id']) AND isset($_GET['section_id']) AND is_numeric($_GET['section_id']) AND isset($_GET['post_id']) AND is_numeric($_GET['post_id'])
|
39 |
|
|
AND (( ENABLED_ASP AND isset($_POST['c0mment_'.date('W')]) AND $_POST['c0mment_'.date('W')] != '')
|
40 |
|
|
OR (!ENABLED_ASP AND isset($_POST['comment']) AND $_POST['comment'] != ''))
|
41 |
649
|
thorn
|
) {
|
42 |
562
|
Ruebenwurz
|
|
43 |
649
|
thorn
|
if(ENABLED_ASP)
|
44 |
|
|
$comment = $_POST['c0mment_'.date('W')];
|
45 |
|
|
else
|
46 |
|
|
$comment = $_POST['comment'];
|
47 |
656
|
thorn
|
$comment = $wb->add_slashes(strip_tags($comment));
|
48 |
|
|
$title = $wb->add_slashes(strip_tags($_POST['title']));
|
49 |
|
|
$page_id = $_GET['page_id'];
|
50 |
|
|
$section_id = $_GET['section_id'];
|
51 |
|
|
$post_id = $_GET['post_id'];
|
52 |
|
|
|
53 |
562
|
Ruebenwurz
|
// Check captcha
|
54 |
656
|
thorn
|
$query_settings = $database->query("SELECT use_captcha FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'");
|
55 |
562
|
Ruebenwurz
|
if($query_settings->numRows() == 0) {
|
56 |
|
|
exit(header("Location: ".WB_URL.PAGES_DIRECTORY.""));
|
57 |
|
|
} else {
|
58 |
|
|
$settings = $query_settings->fetchRow();
|
59 |
596
|
thorn
|
$t=time();
|
60 |
|
|
if(ENABLED_ASP && ( // Advanced Spam Protection
|
61 |
|
|
($_SESSION['session_started']+ASP_SESSION_MIN_AGE > $t) OR // session too young
|
62 |
|
|
(!isset($_SESSION['comes_from_view'])) OR // user doesn't come from view.php
|
63 |
|
|
(!isset($_SESSION['comes_from_view_time']) OR $_SESSION['comes_from_view_time'] > $t-ASP_VIEW_MIN_AGE) OR // user is too fast
|
64 |
|
|
(!isset($_SESSION['submitted_when']) OR !isset($_POST['submitted_when'])) OR // faked form
|
65 |
|
|
($_SESSION['submitted_when'] != $_POST['submitted_when']) OR // faked form
|
66 |
605
|
thorn
|
($_SESSION['submitted_when'] > $t-ASP_INPUT_MIN_AGE && !isset($_SESSION['captcha_retry_news'])) OR // user too fast
|
67 |
596
|
thorn
|
($_SESSION['submitted_when'] < $t-43200) OR // form older than 12h
|
68 |
605
|
thorn
|
($_POST['email'] OR $_POST['url'] OR $_POST['homepage'] OR $_POST['comment']) // honeypot-fields
|
69 |
596
|
thorn
|
)) {
|
70 |
|
|
exit(header("Location: ".WB_URL.PAGES_DIRECTORY.""));
|
71 |
|
|
}
|
72 |
620
|
thorn
|
if(ENABLED_ASP) {
|
73 |
|
|
if(isset($_SESSION['captcha_retry_news'])) unset($_SESSION['captcha_retry_news']);
|
74 |
|
|
}
|
75 |
596
|
thorn
|
if($settings['use_captcha']) {
|
76 |
|
|
if(isset($_POST['captcha']) AND $_POST['captcha'] != '') {
|
77 |
562
|
Ruebenwurz
|
// Check for a mismatch
|
78 |
|
|
if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
|
79 |
|
|
$_SESSION['captcha_error'] = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
|
80 |
656
|
thorn
|
$_SESSION['comment_title'] = $title;
|
81 |
649
|
thorn
|
$_SESSION['comment_body'] = $comment;
|
82 |
892
|
Ruebenwurz
|
exit(header('Location: '.WB_URL."/modules/news/comment.php?id=$post_id&sid=$section_id"));
|
83 |
562
|
Ruebenwurz
|
}
|
84 |
|
|
} else {
|
85 |
|
|
$_SESSION['captcha_error'] = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
|
86 |
656
|
thorn
|
$_SESSION['comment_title'] = $title;
|
87 |
649
|
thorn
|
$_SESSION['comment_body'] = $comment;
|
88 |
892
|
Ruebenwurz
|
exit(header('Location: '.WB_URL."/modules/news/comment.php?id=$post_id&sid=$section_id"));
|
89 |
562
|
Ruebenwurz
|
}
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
|
|
if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
|
93 |
596
|
thorn
|
if(ENABLED_ASP) {
|
94 |
|
|
unset($_SESSION['comes_from_view']);
|
95 |
|
|
unset($_SESSION['comes_from_view_time']);
|
96 |
|
|
unset($_SESSION['submitted_when']);
|
97 |
|
|
}
|
98 |
|
|
|
99 |
562
|
Ruebenwurz
|
// Insert the comment into db
|
100 |
1072
|
Ruebenwurz
|
$commented_when = time();
|
101 |
562
|
Ruebenwurz
|
if($wb->is_authenticated() == true) {
|
102 |
|
|
$commented_by = $wb->get_user_id();
|
103 |
|
|
} else {
|
104 |
|
|
$commented_by = '';
|
105 |
|
|
}
|
106 |
|
|
$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')");
|
107 |
|
|
// Get page link
|
108 |
|
|
$query_page = $database->query("SELECT link FROM ".TABLE_PREFIX."mod_news_posts WHERE post_id = '$post_id'");
|
109 |
|
|
$page = $query_page->fetchRow();
|
110 |
|
|
header('Location: '.$wb->page_link($page['link']).'?id='.$post_id);
|
111 |
|
|
} else {
|
112 |
656
|
thorn
|
if(isset($_GET['post_id']) AND is_numeric($_GET['post_id']) AND isset($_GET['section_id']) AND is_numeric($_GET['section_id']))
|
113 |
892
|
Ruebenwurz
|
header('Location: '.WB_URL."/modules/news/comment.php?id={$_GET['post_id']}&sid={$_GET['section_id']}");
|
114 |
656
|
thorn
|
else
|
115 |
|
|
exit(header("Location: ".WB_URL.PAGES_DIRECTORY.""));
|
116 |
562
|
Ruebenwurz
|
}
|
117 |
|
|
|
118 |
|
|
?>
|