<?php
// +------------------------------------------------------------------------+
// | PHP Melody version 1.6.7 ( www.phpsugar.com )
// +------------------------------------------------------------------------+
// | PHP Melody IS NOT FREE SOFTWARE
// | If you have downloaded this software from a website other
// | than www.phpsugar.com or if you have received
// | this software from someone who is not a representative of
// | phpSugar, you are involved in an illegal activity.
// | ---
// | In such case, please contact: support@phpsugar.com.
// +------------------------------------------------------------------------+
// | Developed by: phpSugar (www.phpsugar.com) / support@phpsugar.com
// | Copyright: (c) 2004-2011 PhpSugar.com. All rights reserved.
// +------------------------------------------------------------------------+

$showm = '4';
include('header.php');

$list = ''; 
$content = '';
$words = '';
$words_list = array();

$list = $_GET['list'];

if($list == ''){
	$list = 'censor_words';
}

switch($list){ 
	default:
	case 'censored':
		$file = '../censor_words.txt';
		$title = 'Censored words';
	break;
	
	case 'blacklist':		
		$file = '../blacklist.txt';
		$title = 'Blacklist';
	break;
}//	end switch

if($_POST['Submit'] == "Save"){
	$words = $_POST['words'];
	
	$temp_arr = explode("\n", $words);
	
	for($i = 0; $i < count($temp_arr); $i++){
		if(trim($temp_arr[$i]) != '' && strlen($temp_arr[$i]) > 1) 
			$words_list[] = $temp_arr[$i];
	}	
	$fp = fopen($file, "w");
	if(!$fp) { 
		echo "Could not open file <strong>".$file."</strong>";
		include('footer.php');
		exit();
	}
	$line = '';
	for($i = 0; $i < count($words_list); $i++){
		if($i != count($words_list)-1)
			$line = $words_list[$i]."\n";
		else
			$line = $words_list[$i];
		fwrite($fp, $line, strlen($line));
	}
	fclose($fp);
	$info_msg = '<div class="info_msg_ok">The list has been updated.</div>';
}
else{
	$fp = @fopen($file, "r");
	if(!$fp) { 
		echo 'Could not open file <strong>'.$file.'</strong>';
		include('footer.php');
		exit;
	}
	while( !feof($fp)){
		$content .= fread($fp, 4096);
	}
	fclose($fp);
if(empty($content)) $info_msg = '<div class="info_msg_err">The list is currently blank.<br /></div>';
}

?>
<div id="sub_menu">
<li><a href="comments.php">Manage comments</a></li>
<li><a href="blacklist.php?list=censored">Censored words</a></li>
<li><a href="blacklist.php?list=blacklist">Blacklisted words</a></li>
</div>
<div id="content">
<h2><?php echo $title; ?> manager</h2>
<?php
if($info_msg) {
echo $info_msg; } else {
?>
<div class="info_msg">
You should prevent unwanted comments from being posted on your site.<br /> <br />
<strong>Blacklist manager</strong> - Comment containing any of the blacklisted words won't be posted at all.<br />
<strong>Censored words</strong> - Censored words will be replaced with '***'.<br />
</div>
<?php
} 
if($_POST['Submit'] != 'Save')
{
?>
<form name="form" method="post" action="<?php "blacklist.php?list=".$_GET['list']; ?>">
	<textarea name="words" cols="80" rows="15"><?php echo $content; ?></textarea>
    <br />
	<input type="submit" name="Submit" value="Save" class="inputbutton" />
</form>
<?php
}
?>
<br />
</div>
<?php
include('footer.php');
?>