Project

General

Profile

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 1868 2013-02-19 21:07:19Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/submit_comment.php $
14
 * @lastmodified    $Date: 2013-02-19 22:07:19 +0100 (Tue, 19 Feb 2013) $
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', '&amp;');
25
}
26
*/
27

    
28
require_once(WB_PATH.'/framework/class.wb.php');
29
if( !(isset($wb) && is_object($wb)) ) { $wb = new wb(); }
30
include_once (WB_PATH.'/framework/functions.php');
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."&section_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("&#91;&#91;", "&#93;&#93;"), $title);
69
	$comment = str_replace(array("[[", "]]"), array("&#91;&#91;", "&#93;&#93;"), $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
			$aServerEmail = (defined('SERVER_EMAIL') && SERVER_EMAIL != '' ? SERVER_EMAIL : $_SERVER['SERVER_NAME']);
112
			$replace = array('SERVER_EMAIL' => $aServerEmail );
113
			$MESSAGE['MOD_FORM_INCORRECT_CAPTCHA'] = replace_vars($MESSAGE['MOD_FORM_INCORRECT_CAPTCHA'], $replace);
114
			if(isset($_POST['captcha']) AND $_POST['captcha'] != '')
115
            {
116
				// Check for a mismatch
117
				if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha'])
118
                {
119
					$_SESSION['captcha_error'] = $MESSAGE['MOD_FORM_INCORRECT_CAPTCHA'];
120
					$_SESSION['comment_title'] = $title;
121
					$_SESSION['comment_body'] = $comment;
122
					header("Location: ".WB_URL."/modules/news/comment.php?post_id=".$post_id."&section_id=".$section_id."" );
123
	                exit( 0 );
124
				}
125
			}
126
            else
127
            {
128
				$_SESSION['captcha_error'] = $MESSAGE['MOD_FORM_INCORRECT_CAPTCHA'];
129
				$_SESSION['comment_title'] = $title;
130
				$_SESSION['comment_body'] = $comment;
131
				header("Location: ".WB_URL."/modules/news/comment.php?post_id=".$post_id."&section_id=".$section_id."" );
132
	            exit( 0 );
133
			}
134
		}
135
	}
136

    
137
	if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
138

    
139
	if(ENABLED_ASP)
140
    {
141
		unset($_SESSION['comes_from_view']);
142
		unset($_SESSION['comes_from_view_time']);
143
		unset($_SESSION['submitted_when']);
144
	}
145

    
146
	// Insert the comment into db
147
	$commented_when = time();
148
	if($wb->is_authenticated() == true)
149
    {
150
		$commented_by = $wb->get_user_id();
151
	}
152
    else
153
    {
154
		$commented_by = '';
155
	}
156

    
157
	$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')");
158
	// Get page link
159
	$query_page = $database->query("SELECT link FROM ".TABLE_PREFIX."mod_news_posts WHERE post_id = '$post_id'");
160
	$page = $query_page->fetchRow();
161
	header('Location: '.$wb->page_link($page['link']).'?post_id='.$post_id.'' );
162
	exit( 0 );
163
}
164
else
165
{
166
	if( isset($_GET['post_id']) AND is_numeric($_GET['post_id'])
167
        AND isset($_GET['section_id']) AND is_numeric($_GET['section_id']) )
168
    {
169
 		header("Location: ".WB_URL."/modules/news/comment.php?post_id=".(int)$_GET['post_id']."&section_id=".(int)$_GET['section_id']."" ) ;
170
	    exit( 0 );
171
    }
172
	else
173
    {
174
		header("Location: ".WB_URL.PAGES_DIRECTORY."");
175
	    exit( 0 );
176
    }
177
}
(31-31/34)