| 1 | <?php
 | 
  
    | 2 | 
 | 
  
    | 3 | // $Id: submit_comment.php 649 2008-01-31 13:27:23Z thorn $
 | 
  
    | 4 | 
 | 
  
    | 5 | /*
 | 
  
    | 6 | 
 | 
  
    | 7 |  Website Baker Project <http://www.websitebaker.org/>
 | 
  
    | 8 |  Copyright (C) 2004-2008, 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 | require_once(WB_PATH.'/framework/class.wb.php');
 | 
  
    | 30 | $wb = new wb;
 | 
  
    | 31 | 
 | 
  
    | 32 | // Check if we should show the form or add a comment
 | 
  
    | 33 | if(is_numeric($_GET['page_id']) AND is_numeric($_GET['section_id']) AND isset($_GET['post_id']) AND is_numeric($_GET['post_id'])
 | 
  
    | 34 | 	AND ( ENABLED_ASP AND isset($_POST['c0mment_'.date('W')]) AND $_POST['c0mment_'.date('W')] != '')
 | 
  
    | 35 | 	OR  (!ENABLED_ASP AND isset($_POST['comment']) AND $_POST['comment'] != '')
 | 
  
    | 36 | ) {
 | 
  
    | 37 | 	
 | 
  
    | 38 | 	if(ENABLED_ASP)
 | 
  
    | 39 | 		$comment = $_POST['c0mment_'.date('W')];
 | 
  
    | 40 | 	else
 | 
  
    | 41 | 		$comment = $_POST['comment'];
 | 
  
    | 42 | 	
 | 
  
    | 43 | 	// Check captcha
 | 
  
    | 44 | 	$query_settings = $database->query("SELECT use_captcha FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '".$_GET['section_id']."'");
 | 
  
    | 45 | 	if($query_settings->numRows() == 0) { 
 | 
  
    | 46 | 		exit(header("Location: ".WB_URL.PAGES_DIRECTORY.""));
 | 
  
    | 47 | 	} else {
 | 
  
    | 48 | 		$settings = $query_settings->fetchRow();
 | 
  
    | 49 | 		$t=time();
 | 
  
    | 50 | 		if(ENABLED_ASP && ( // Advanced Spam Protection
 | 
  
    | 51 | 			($_SESSION['session_started']+ASP_SESSION_MIN_AGE > $t) OR // session too young
 | 
  
    | 52 | 			(!isset($_SESSION['comes_from_view'])) OR // user doesn't come from view.php
 | 
  
    | 53 | 			(!isset($_SESSION['comes_from_view_time']) OR $_SESSION['comes_from_view_time'] > $t-ASP_VIEW_MIN_AGE) OR // user is too fast
 | 
  
    | 54 | 			(!isset($_SESSION['submitted_when']) OR !isset($_POST['submitted_when'])) OR // faked form
 | 
  
    | 55 | 			($_SESSION['submitted_when'] != $_POST['submitted_when']) OR // faked form
 | 
  
    | 56 | 			($_SESSION['submitted_when'] > $t-ASP_INPUT_MIN_AGE && !isset($_SESSION['captcha_retry_news'])) OR // user too fast
 | 
  
    | 57 | 			($_SESSION['submitted_when'] < $t-43200) OR // form older than 12h
 | 
  
    | 58 | 			($_POST['email'] OR $_POST['url'] OR $_POST['homepage'] OR $_POST['comment']) // honeypot-fields
 | 
  
    | 59 | 		)) {
 | 
  
    | 60 | 			exit(header("Location: ".WB_URL.PAGES_DIRECTORY.""));
 | 
  
    | 61 | 		}
 | 
  
    | 62 | 		if(ENABLED_ASP) {
 | 
  
    | 63 | 			if(isset($_SESSION['captcha_retry_news'])) unset($_SESSION['captcha_retry_news']);
 | 
  
    | 64 | 		}
 | 
  
    | 65 | 		if($settings['use_captcha']) {
 | 
  
    | 66 | 			if(isset($_POST['captcha']) AND $_POST['captcha'] != '') {
 | 
  
    | 67 | 				// Check for a mismatch
 | 
  
    | 68 | 				if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
 | 
  
    | 69 | 					$_SESSION['captcha_error'] = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
 | 
  
    | 70 | 					$_SESSION['comment_title'] = $_POST['title'];
 | 
  
    | 71 | 					$_SESSION['comment_body'] = $comment;
 | 
  
    | 72 | 					exit(header('Location: '.WB_URL."/modules/news/comment.php?id={$_GET['post_id']}&sid={$_GET['section_id']}"));
 | 
  
    | 73 | 				}
 | 
  
    | 74 | 			} else {
 | 
  
    | 75 | 				$_SESSION['captcha_error'] = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
 | 
  
    | 76 | 				$_SESSION['comment_title'] = $_POST['title'];
 | 
  
    | 77 | 				$_SESSION['comment_body'] = $comment;
 | 
  
    | 78 | 				exit(header('Location: '.WB_URL."/modules/news/comment.php?id={$_GET['post_id']}&sid={$_GET['section_id']}"));
 | 
  
    | 79 | 			}
 | 
  
    | 80 | 		}
 | 
  
    | 81 | 	}
 | 
  
    | 82 | 	if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
 | 
  
    | 83 | 	if(ENABLED_ASP) {
 | 
  
    | 84 | 		unset($_SESSION['comes_from_view']);
 | 
  
    | 85 | 		unset($_SESSION['comes_from_view_time']);
 | 
  
    | 86 | 		unset($_SESSION['submitted_when']);
 | 
  
    | 87 | 	}
 | 
  
    | 88 | 
 | 
  
    | 89 | 	// Insert the comment into db
 | 
  
    | 90 | 	$page_id = $_GET['page_id'];
 | 
  
    | 91 | 	$section_id = $_GET['section_id'];
 | 
  
    | 92 | 	$post_id = $_GET['post_id'];
 | 
  
    | 93 | 	$title = $wb->add_slashes(strip_tags($_POST['title']));
 | 
  
    | 94 | 	$comment = $wb->add_slashes(strip_tags($comment));
 | 
  
    | 95 | 	$commented_when = mktime();
 | 
  
    | 96 | 	if($wb->is_authenticated() == true) {
 | 
  
    | 97 | 		$commented_by = $wb->get_user_id();
 | 
  
    | 98 | 	} else {
 | 
  
    | 99 | 		$commented_by = '';
 | 
  
    | 100 | 	}
 | 
  
    | 101 | 	$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')");
 | 
  
    | 102 | 	// Get page link
 | 
  
    | 103 | 	$query_page = $database->query("SELECT link FROM ".TABLE_PREFIX."mod_news_posts WHERE post_id = '$post_id'");
 | 
  
    | 104 | 	$page = $query_page->fetchRow();
 | 
  
    | 105 | 	header('Location: '.$wb->page_link($page['link']).'?id='.$post_id);
 | 
  
    | 106 | } else {
 | 
  
    | 107 | 	header('Location: '.WB_URL."/modules/news/comment.php?id={$_GET['post_id']}&sid={$_GET['section_id']}");
 | 
  
    | 108 | }
 | 
  
    | 109 | 
 | 
  
    | 110 | ?>
 |