Project

General

Profile

1
<?php
2

    
3
// $Id: submit_comment.php 1157 2009-10-09 21:54:57Z Luisehahne $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, Ryan Djurovich
9

    
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
/*overwrite php.ini on Apache servers for valid SESSION ID Separator
30
if(function_exists('ini_set')) {
31
	ini_set('arg_separator.output', '&amp;');
32
}
33
*/
34
require_once(WB_PATH.'/framework/class.wb.php');
35
$wb = new wb;
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
	$page_id = $_GET['page_id'];
57
	$section_id = $_GET['section_id'];
58
	$post_id = $_GET['post_id'];
59

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

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

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

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

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

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

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

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

    
161
?>
(28-28/31)