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 1383 2011-01-15 14:09:11Z FrankH $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/submit_comment.php $
15
 * @lastmodified    $Date: 2011-01-15 15:09:11 +0100 (Sat, 15 Jan 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
require_once(WB_PATH.'/framework/class.wb.php');
28
$wb = new wb;
29
         /*  */
30

    
31
if (!$wb->checkFTAN())
32
{
33
	$wb->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], WB_URL);
34
	exit();
35
}
36

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

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

    
53
	$comment = $wb->add_slashes(strip_tags($comment));
54
	$title = $wb->add_slashes(strip_tags($_POST['title']));
55
	$page_id = $_GET['page_id'];
56
	$section_id = $_GET['section_id'];
57
	$post_id = $_GET['post_id'];
58

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

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

    
85
		if(ENABLED_ASP)
86
        {
87
			if(isset($_SESSION['captcha_retry_news']))
88
            {
89
              unset($_SESSION['captcha_retry_news']);
90
            }
91
		}
92

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

    
118
	if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
119

    
120
	if(ENABLED_ASP)
121
    {
122
		unset($_SESSION['comes_from_view']);
123
		unset($_SESSION['comes_from_view_time']);
124
		unset($_SESSION['submitted_when']);
125
	}
126

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

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

    
160
?>
(28-28/31)