Project

General

Profile

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 1425 2011-02-03 23:16:12Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/submit_comment.php $
15
 * @lastmodified    $Date: 2011-02-04 00:16:12 +0100 (Fri, 04 Feb 2011) $
16
 *
17
 */
18

    
19
// Include config file
20
require('../../config.php');
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
$wb = new wb;
30
$post_id = (int)$_GET['post_id'];
31
$section_id = (int)$_GET['section_id'];
32
if (!$wb->checkFTAN())
33
{
34
	$wb->print_error('SC5::'.$MESSAGE['GENERIC_SECURITY_ACCESS'], WB_URL."/modules/news/comment.php?post_id=".$post_id."&section_id=".$section_id);
35
	exit();
36
}
37

    
38
// Check if we should show the form or add a comment
39
if(isset($_GET['page_id']) AND is_numeric($_GET['page_id'])
40
    AND isset($_GET['section_id']) AND is_numeric($_GET['section_id'])
41
        AND isset($_GET['post_id']) AND is_numeric($_GET['post_id'])
42
            AND ( ( ENABLED_ASP AND isset($_POST['comment_'.date('W')]) AND $_POST['comment_'.date('W')] != '')
43
            OR ( !ENABLED_ASP AND isset($_POST['comment']) AND $_POST['comment'] != '' ) ) )
44
{
45

    
46
	if(ENABLED_ASP){
47
        $comment = $_POST['comment_'.date('W')];
48
	}
49
	else
50
    {
51
        $comment = $_POST['comment'];
52
	}
53

    
54
	$comment = $wb->add_slashes(strip_tags($comment));
55
	$title = $wb->add_slashes(strip_tags($_POST['title']));
56
	// do not allow droplets in user input!
57
	$title = str_replace(array("[[", "]]"), array("&#91;&#91;", "&#93;&#93;"), $title);
58
	$comment = str_replace(array("[[", "]]"), array("&#91;&#91;", "&#93;&#93;"), $comment);
59
	$page_id = (int)$_GET['page_id'];
60
	$section_id = (int)$_GET['section_id'];
61
	$post_id = (int)$_GET['post_id'];
62

    
63
	// Check captcha
64
	$query_settings = $database->query("SELECT use_captcha FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'");
65
	if( !$query_settings->numRows())
66
    {
67
		header("Location: ".WB_URL.PAGES_DIRECTORY."");
68
	    exit( 0 );
69
	}
70
    else
71
    {
72
		$settings = $query_settings->fetchRow();
73
		$t=time();
74

    
75
        // Advanced Spam Protection
76
	    if(ENABLED_ASP AND ( ($_SESSION['session_started']+ASP_SESSION_MIN_AGE > $t)  // session too young
77
            OR (!isset($_SESSION['comes_from_view']))// user doesn't come from view.php
78
            OR (!isset($_SESSION['comes_from_view_time']) OR $_SESSION['comes_from_view_time'] > $t-ASP_VIEW_MIN_AGE) // user is too fast
79
            OR (!isset($_SESSION['submitted_when']) OR !isset($_POST['submitted_when'])) // faked form
80
            OR ($_SESSION['submitted_when'] != $_POST['submitted_when']) // faked form
81
            OR ($_SESSION['submitted_when'] > $t-ASP_INPUT_MIN_AGE && !isset($_SESSION['captcha_retry_news'])) // user too fast
82
            OR ($_SESSION['submitted_when'] < $t-43200) // form older than 12h
83
            OR ($_POST['email'] OR $_POST['url'] OR $_POST['homepage'] OR $_POST['comment']) /* honeypot-fields */ ) )
84
        {
85
            header("Location: ".WB_URL.PAGES_DIRECTORY."");
86
	        exit( 0 );
87
		}
88

    
89
		if(ENABLED_ASP)
90
        {
91
			if(isset($_SESSION['captcha_retry_news']))
92
            {
93
              unset($_SESSION['captcha_retry_news']);
94
            }
95
		}
96

    
97
		if($settings['use_captcha'])
98
        {
99
			if(isset($_POST['captcha']) AND $_POST['captcha'] != '')
100
            {
101
				// Check for a mismatch
102
				if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha'])
103
                {
104
					$_SESSION['captcha_error'] = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
105
					$_SESSION['comment_title'] = $title;
106
					$_SESSION['comment_body'] = $comment;
107
					header("Location: ".WB_URL."/modules/news/comment.php?post_id=".$post_id."&section_id=".$section_id."" );
108
	                exit( 0 );
109
				}
110
			}
111
            else
112
            {
113
				$_SESSION['captcha_error'] = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
114
				$_SESSION['comment_title'] = $title;
115
				$_SESSION['comment_body'] = $comment;
116
				header("Location: ".WB_URL."/modules/news/comment.php?post_id=".$post_id."&section_id=".$section_id."" );
117
	            exit( 0 );
118
			}
119
		}
120
	}
121

    
122
	if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
123

    
124
	if(ENABLED_ASP)
125
    {
126
		unset($_SESSION['comes_from_view']);
127
		unset($_SESSION['comes_from_view_time']);
128
		unset($_SESSION['submitted_when']);
129
	}
130

    
131
	// Insert the comment into db
132
	$commented_when = time();
133
	if($wb->is_authenticated() == true)
134
    {
135
		$commented_by = $wb->get_user_id();
136
	}
137
    else
138
    {
139
		$commented_by = '';
140
	}
141

    
142
	$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')");
143
	// Get page link
144
	$query_page = $database->query("SELECT link FROM ".TABLE_PREFIX."mod_news_posts WHERE post_id = '$post_id'");
145
	$page = $query_page->fetchRow();
146
	header('Location: '.$wb->page_link($page['link']).'?post_id='.$post_id.'' );
147
	exit( 0 );
148
}
149
else
150
{
151
	if( isset($_GET['post_id']) AND is_numeric($_GET['post_id'])
152
        AND isset($_GET['section_id']) AND is_numeric($_GET['section_id']) )
153
    {
154
 		header("Location: ".WB_URL."/modules/news/comment.php?post_id=".(int)$_GET['post_id']."&section_id=".(int)$_GET['section_id']."" ) ;
155
	    exit( 0 );
156
    }
157
	else
158
    {
159
		header("Location: ".WB_URL.PAGES_DIRECTORY."");
160
	    exit( 0 );
161
    }
162
}
163

    
164
?>
(28-28/31)