<?php 

if (!function_exists('sv') || preg_match('#/plugins/comments/index.php#i', $_SERVER['SCRIPT_NAME']))
{
	die('no direct access');
}

/* utf8-marker = äöü
==========================================
CMSimple Plugin Comments
Version comments 4.18
Release: 2026-03
Gert Ebersbach
ge-webdesign.de
==========================================
*/

$comments_version='Comments 4.18';  //### Version: needed in new files!!
$comments_release='2026-03-14';

global $pth, $sn, $plugin_tx, $plugin_cf, $u, $s, $c, $sl, $f, $tx, $hjs, $co_author_folder;

if(!isset($_SESSION)){session_start();}

if(isset($co_author_folder))
{
	$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
}
else
{
	$content_path = './' . $plugin_cf['comments']['content_path'];
}
$upload_path=$content_path.'upload/';

if
(
isset($_SESSION['mapl_group_user' . $sn]) && $_SESSION['mapl_group_user' . $sn] == 'mod' 
&& $_SERVER['QUERY_STRING']!='&comments&admin=plugin_config&action=plugin_edit' 
) 
$plugin_cf['comments']['comments_moderate'] = "true";

/*
if(isset($_SESSION['mapl_name_user' . $sn])) echo '<br>Eingeloggter User: ' . $_SESSION['mapl_name_user' . $sn];
echo '<br>Moderation: ' . $plugin_cf['comments']['comments_moderate'];
*/

if($plugin_cf['comments']['comments_moderate'] == "true" && isset($_GET['commentsModHint']))
{
	$commModerationHint = '<div class="comments_mod_hint">' . $plugin_tx['comments']['form_success_mod'] . '</div>';
}

if($plugin_cf['comments']['comments_moderate'] != "true" && isset($_GET['commentsModHint']))
{
	$commModerationHint = '<div class="comments_success_hint">' . $plugin_tx['comments']['form_success_text'] . '</div>';
}



/* #### FUNCTIONS #### */

function commentsSafeInput($input)
{
	$input = isset($input) ? $input : '';
	stripslashes(strip_tags(htmlspecialchars($input, ENT_QUOTES, 'UTF-8')));
	return $input;
}

// comments_get_file 

$mvwd_new_file_content=$comments_version.'-,+;-admin-,+;-open-,+;--,+;--,+;--,+;--,+;-';

function comments_get_file($file_name, $file_path, $ending='txt', $create_new='a', $expand_integer=FALSE)
{
	global $plugin_pth, $mvwd_new_file_content, $pth, $content_path, $upload_path, $e, $o, $plugin_cf, $co_author_folder;
	
	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	$upload_path=$content_path.'upload/';

	if (!$file_name) 
	{ 
		echo('no Filename!!'); return false; 
	}
	if (!$file_path) 
	{ 
		$file_path=$content_path; 
	}

	if(gettype($file_name)=='integer'&&$expand_integer)
	{ 
		if ($file_name<100) 
		{ 
			$file_name='0'.$file_name; 
		}
		if ($file_name<10)
		{ 
			$file_name='0'.$file_name; 
		} 
	}

	$file_name = $file_path . $file_name . '.' . $ending;

	if (!is_dir($file_path)) 
	{ 
		mkdir($file_path); 
	}

	if (!file_exists($file_name)) 
	{ 
		$fh = fopen($file_name, $create_new);
		$o.='<p class="cmsimplecore_warning" style="text-align: center;"><b>A new file was created:</b> '.$file_name.'</p>';
		fputs($fh,$mvwd_new_file_content);
		fclose($fh); 
		chmod($file_name, 0666);
	}
	return $file_name;
}

// comments_read_file

function comments_read_file($file_name, $list_parameters, $set_array_names=TRUE) 
{
	global $pth, $content_path, $upload_path, $plugin_cf, $co_author_folder;
	
	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	$upload_path=$content_path.'upload/';
	
	if (!$file_name) 
	{ 
		echo('no Filename!!'); return false; 
	}
	if (!$list_parameters||!is_array($list_parameters)) 
	{ 
		echo('no List-Parameters!!'); return false; 
	} 

	$file_name = comments_get_file($file_name, $content_path);

	if(is_file($file_name)&&$list_parameters)  //## read from File seperated by '-,+;-'.
	{ 
		if(!$set_array_names) 
		{ 
			$list_parameters=array_keys($list_parameters); 
		} 
		
  // if not set: kill assoziative-Array an set numeric values for keys and values

		$fh = fopen($file_name, "r");
		$i=0;
		while (!feof($fh)) 
		{ 
			$line = fgets($fh);
			if (count(explode("-,+;-",$line))>count($list_parameters)) 
			{ 
				echo('More values read than declined in List-Parameters. Please contact your distributor!'); 
				return false; 
			} // check if more values than list parameters!
		
		//$file_array[$i]=explode("-,+;-",$line); //### tut; o.k.!
		$file_array[$i]=array_combine($list_parameters,explode("-,+;-",$line)); // PHP5 only, emulated with function
		$i++; 
		} 
		fclose($fh); 
	}
	else 
	{ 
		echo('Sorry, cannot open this file: '.$file_name); return false; 
	}

	if ($set_array_names)
	{ 
		foreach($file_array as $line => $content)
		{ 
			$file_array[$line]= array_combine($list_parameters, $content); 
		} 
	}
	return $file_array;
}

// comments_write_line
// write values to File seperated by '-,+;-'.

function comments_write_line($file_name, $file_path, $new_line_array, $max_size=0)   
{ 
	global $pth, $plugin_cf, $content_path, $upload_path, $co_author_folder;
	
	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	$upload_path=$content_path.'upload/';
	
	$ending='txt';
	$file_name_array=explode(".", $file_name);
	if(count($file_name_array)>1){$ending=array_pop($file_name_array);$file_name=implode(".", $file_name_array);}
	$file_name = comments_get_file($file_name, $file_path, $ending);
	if($max_size>0) 
	{ 
		comments_recreate_file($file_name, $max_size); 
	}
	if(!$new_line_array||!is_array($new_line_array))  //### if no array given, save whole line
	{ 
		if(is_file($file_name)) 
		{ 
			if (!$fh = fopen($file_name, "a")) 
			{ 
				echo('Sorry, cannot write to file: '.$file_name); return false; 
			} 
			else 
			{
				fputs($fh,$new_line_array); 
			}
			fclose($fh); 
		}
		else 
		{ 
			echo('Sorry, cannot write to file: '.$file_name); return false; 
		}
	} 
	else  //### if array given, split and separate with '-,+;-'
	{ 
		if(is_file($file_name))
		{ 
			if (!$fh = fopen($file_name, "a")) 
			{ 
				echo('Sorry, cannot write to file: '.$file_name); return false; 
			} 
			else 
			{
				if($plugin_cf['comments']['comments_moderate'] == "true") $moderated='hidden';
				$new_line="\n".$moderated.implode("-,+;-", $new_line_array); 
				fputs($fh,$new_line); 
			}
			fclose($fh); 
		}
		else 
		{ 
			echo('Sorry, cannot write to file: '.$file_name); return false; 
		} 
	}
	return true;
}

// comments_recreate_file

function comments_recreate_file($file_name, $max_size)
{ 
	global $pth, $plugin_pth, $plugin_cf, $content_path, $upload_path, $co_author_folder;
	
	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	$upload_path=$content_path.'upload/';
	
	if(filesize($file_name)>$max_size)
	{ 
		$name=comments_rename_upload(basename($file_name),$plugin_cf['comments']['logging_path']);
		rename($file_name,$plugin_cf['comments']['logging_path'].$name);
		touch($file_name); 
	}
}

// comments_create_thumb

function comments_create_thumb($name,$file,$maxwdt,$maxhgt,$dest,$quality=50,$ftype=null) 
{
	global $pth, $plugin_cf, $plugin_tx, $content_path, $upload_path, $co_author_folder;
	
	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	$upload_path=$content_path.'upload/';
	
	list($owdt,$ohgt,$otype)=getimagesize($file);

	if(!
	(
		($ftype=='image/gif'
		||$ftype=='image/jpg'
		||$ftype=='image/jpeg'
		||$ftype=='image/pjpeg'
		||$ftype=='image/x-png'
		||$ftype=='image/png'
		)
		&&
		(
			$otype=='1'
			||$otype=='2'
			||$otype=='3'
		)
	))  //## allowed MIME/types
	{ 
		return $plugin_tx['comments']['form_failure_imagetype_text'].' (Filename: '.$name.', Imagetype: unknown, Filetype: '.$ftype.'). '; 
	}
    
	switch($otype)
	{ 
		case 1:  $newimg=imagecreatefromgif($file); 
		break;
		case 2:  $newimg=imagecreatefromjpeg($file); 
		break;
		case 3:  $newimg=imagecreatefrompng($file); 
		break;
		default: return $plugin_tx['comments']['form_failure_imagetype_text'].' (Filename: '.$name.', Imagetype: unknown, Filetype: '.$ftype.'). '; 
	}
 
	if($newimg) 
	{ 
		if($maxwdt&&$maxhgt) //## resize allowed?
		{ 
			if($owdt>1500 || $ohgt>1200)
			{ 
				list($owdt, $ohgt) = comments_Resample($newimg, $owdt, $ohgt, 1024, 768, 0); 
			}
			list($newwdt, $newhgt) = comments_Resample($newimg, $owdt, $ohgt, $maxwdt, $maxhgt); 
		}
		if(!$dest) 
		{ 
			return $newimg; 
		}
		if(!is_dir(dirname($dest))) 
		{ 
			mkdir(dirname($dest, 0644)); 
		}
		if($otype==1) 
		{ 
			$name = basename($name,".gif").'.png'; 
		} // rename uploaded *.gif to *.png
   
		$name=comments_rename_upload($name);
 
		switch($otype) 
		{ 
			case 1: imagepng($newimg,$dest.$name); 
			break; // make .png from an uploaded .gif
			// case 1: imagegif($newimg,$dest.$name); break;  // deleted in cause of removed .gif-Support in gd
			case 2: imagejpeg($newimg,$dest.$name,$quality); 
			break;
			case 3: imagepng($newimg,$dest.$name); 
			break; 
		}
	}
	if(phpversion() < '8')imagedestroy($newimg);
	return array($newwdt, $newhgt, $name);
}

function comments_Resample($img, $owdt, $ohgt, $maxwdt, $maxhgt, $quality=1)
{
	global $pth, $plugin_cf, $content_path, $upload_path, $co_author_folder;
	
	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	$upload_path=$content_path.'upload/';
	
	$ratio=$owdt/$ohgt;
	if(($owdt<$maxwdt)&&($ohgt<$maxhgt)) 
	{ 
		return array($owdt, $ohgt); 
	}
	switch (true)
	{ 
		case ($ratio>1): $newwdt = $maxwdt; $newhgt = floor($maxwdt/$ratio); 
		break;
		case ($ratio<1): $newhgt = $maxhgt; $newwdt = floor($maxhgt*$ratio); 
		break;
		default: $newwdt=$maxwdt; $newhgt=$maxhgt;
		if ($maxwdt>$maxhgt) 
		{ 
			$newwdt=$maxhgt; 
		}
		else
		{ 
			$newhgt=$maxwdt; 
		} 
		break; 
	}

	$tn=imagecreatetruecolor($newwdt,$newhgt);

	if($quality) 
	{ 
		imagecopyresampled($tn,$img,0,0,0,0,$newwdt,$newhgt,$owdt,$ohgt); 
	}    
	else
	{ 
		imagecopyresized  ($tn,$img,0,0,0,0,$newwdt,$newhgt,$owdt,$ohgt); 
	}

	if(phpversion() < '8')imagedestroy($img);
	$img = $tn;
	return array($newwdt, $newhgt);
}

// comments_rename_upload

function comments_rename_upload($pic_name)
{ 
	global $pth, $plugin_pth, $plugin_cf, $content_path, $upload_path, $co_author_folder;
	
	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	$upload_path=$content_path.'upload/';

	$upload_dir=$upload_path;

	if($plugin_cf['comments']['image_max_length_filename']!="" AND is_numeric($plugin_cf['comments']['image_max_length_filename'])) 
	{ 
		$max_length = $plugin_cf['comments']['image_max_length_filename']; 
	}
	else 
	{ 
		$max_length = 8; 
	}

	//#### get pic-name without .ending:
	$pic_name = substr($pic_name, 0, -strlen($pic_ending=strrchr($pic_name, '.'))); 
	//#### cut off pic-name if length>8:
	if(strlen($pic_name)>$max_length)
	{
		$pic_name=substr($pic_name,0,$max_length);
	}
	//#### check if last 3 is_numeric and already counted by script(/user):
	$pic_name_killed = substr($pic_name, strlen($pic_name)-2, strlen($pic_name)-3);
	//#### rebuild pic-name with counting-num + original-.ending:
	if (is_numeric($pic_name_killed)) 
	{ 
		$pic_name=substr($pic_name, 0, strlen($pic_name)-3);
		$pic_name_killed++; 
	} 
	else 
	{ 
		$pic_name_killed=1; 
	}
	if ($pic_name_killed<10) 
	{
		$pic_name_killed='0'.$pic_name_killed;
	}
	while (file_exists($upload_dir.$pic_name.'~'.$pic_name_killed.$pic_ending)) 
	{
		$pic_name_killed=(int)$pic_name_killed;
		$pic_name_killed++;
		if ($pic_name_killed<10) 
		{
			$pic_name_killed='0'.$pic_name_killed;
		}
	}
	
	if
	(
		$pic_ending == '.jpg' 
		|| $pic_ending == '.jpeg' 
		|| $pic_ending == '.JPG' 
		|| $pic_ending == '.JPEG' 
		|| $pic_ending == '.gif' 
		|| $pic_ending == '.GIF' 
		|| $pic_ending == '.png' 
		|| $pic_ending == '.PNG' 
	)
	{
		$pic_name = $pic_name.'~'.$pic_name_killed.$pic_ending;
		return $pic_name;
	}
	else
	{
		die('wrong file extension or file type');
	}
} 

// comments_cleantext

function comments_cleantext($rawcode)
{
	// This will remove HTML tags, javascript sections
	// and white space. It will also convert some
	// common HTML entities to their text equivalent
	// Clever bits cut and pasted from php_manual_en.html#ref.pcre
	
	global $pth;

	$search = array (
	"'-,+;-'", // Strip out delimiter
	"'<script[^>]*?>.*?</script>'si", // Strip out javascript
	"'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
	"'<(?=[a-zA-Z])'", // Strip out pseudo-HTML tags
	"'&(amp|#38);'i", 
	"'&(lt|#60);'i",
	"'&(gt|#62);'i",
	"'&(nbsp|#160);'i",
	"'&(iexcl|#161);'i",
	"'&(cent|#162);'i",
	"'&(pound|#163);'i",
	"'&(copy|#169);'i",
	"'{{'i", // Exclude Plugin Calls
	"'#CMSimple'i"); // Exclude CMSimple-Scripting

	$replace = array (
	"", // Strip out delimiter
	"", // Strip out javascript
	"", // Strip out HTML tags
	"< ", // Strip out pseudo-HTML tags
	"&",
	"&lt;",
	"&gt;",
	" ",
	chr(161),
	chr(162),
	chr(163),
	chr(169),
	"&shy;{&shy;{&shy;", // Exclude Plugin Calls
	'#&shy;CMSimple'); // Exclude CMSimple-Scripting

	if(isset($rawcode))
	{
		// if somebody wants to play ;-)
		$rawcode = str_replace('fKLhoeeR5j90hdllenj6','',$rawcode);

		// converts clear definied html-tags to long strings
		$rawcode = str_replace('<p>','afKLhoeeR5j90hdllenj6p',$rawcode);
		$rawcode = str_replace('</p>','bfKLhoeeR5j90hdllenj6ep',$rawcode);
		$rawcode = str_replace('<strong>','cfKLhoeeR5j90hdllenj6b',$rawcode);
		$rawcode = str_replace('</strong>','dfKLhoeeR5j90hdllenj6eb',$rawcode);
		$rawcode = str_replace('<u>','efKLhoeeR5j90hdllenj6u',$rawcode);
		$rawcode = str_replace('</u>','ffKLhoeeR5j90hdllenj6eu',$rawcode);
		$rawcode = str_replace('<em>','gfKLhoeeR5j90hdllenj6k',$rawcode);
		$rawcode = str_replace('</em>','hfKLhoeeR5j90hdllenj6ek',$rawcode);
		$rawcode = str_replace('<br>','ifKLhoeeR5j90hdllenj6br',$rawcode);
		$rawcode = str_replace('<br />','jhfKLhoeeR5j90dllenj6brx',$rawcode);
		$rawcode = str_replace('<img ','kfKLhoeeR5j90hdllenj6img',$rawcode);
		$rawcode = str_replace('<blockquote>','lfKLhoeeR5j90hdllenj6qu',$rawcode);
		$rawcode = str_replace('</blockquote>','mfKLhoeeR5j90hdllenj6equ',$rawcode);
	

		// creating cleantext and strip out line breaks
		$rawcode=stripslashes($rawcode);
		$comments_cleantext = preg_replace($search, $replace, $rawcode);
		$comments_cleantext = strip_tags($comments_cleantext);
		$comments_cleantext = str_replace(chr(10),'',$comments_cleantext);
		$comments_cleantext = str_replace(chr(12),'',$comments_cleantext);
		$comments_cleantext = str_replace(chr(13),'',$comments_cleantext);
		$comments_cleantext = str_replace('<','',$comments_cleantext);
		$comments_cleantext = str_replace('<>','',$comments_cleantext);

		// reconverts the long strings to html-tags
		$comments_cleantext = str_replace('afKLhoeeR5j90hdllenj6p','<p>',$comments_cleantext);
		$comments_cleantext = str_replace('bfKLhoeeR5j90hdllenj6ep','</p>',$comments_cleantext);
		$comments_cleantext = str_replace('cfKLhoeeR5j90hdllenj6b','<strong>',$comments_cleantext);
		$comments_cleantext = str_replace('dfKLhoeeR5j90hdllenj6eb','</strong>',$comments_cleantext);
		$comments_cleantext = str_replace('efKLhoeeR5j90hdllenj6u','<u>',$comments_cleantext);
		$comments_cleantext = str_replace('ffKLhoeeR5j90hdllenj6eu','</u>',$comments_cleantext);
		$comments_cleantext = str_replace('gfKLhoeeR5j90hdllenj6k','<em>',$comments_cleantext);
		$comments_cleantext = str_replace('hfKLhoeeR5j90hdllenj6ek','</em>',$comments_cleantext);
		$comments_cleantext = str_replace('ifKLhoeeR5j90hdllenj6br','<br>',$comments_cleantext);
		$comments_cleantext = str_replace('jhfKLhoeeR5j90dllenj6brx','<br />',$comments_cleantext);
		$comments_cleantext = str_replace('kfKLhoeeR5j90hdllenj6img','<img ',$comments_cleantext);
		$comments_cleantext = str_replace('lfKLhoeeR5j90hdllenj6qu','<blockquote>',$comments_cleantext);
		$comments_cleantext = str_replace('mfKLhoeeR5j90hdllenj6equ','</blockquote>',$comments_cleantext);
		
		$comments_cleantext = str_replace('src="http://' . $_SERVER['SERVER_NAME'] . CMSIMPLE_ROOT,'src="' . $pth['folder']['base'],$comments_cleantext);
		$comments_cleantext = str_replace('src="https://' . $_SERVER['SERVER_NAME'] . CMSIMPLE_ROOT,'src="' . $pth['folder']['base'],$comments_cleantext);
	//	$comments_cleantext = str_replace('&gt;','',$comments_cleantext);

		// makes url to link
		$comments_cleantext = ' ' . $comments_cleantext;
		$comments_cleantext = str_replace('www',' www',$comments_cleantext);
		$comments_cleantext = str_replace('http://',' http://',$comments_cleantext);
		$comments_cleantext = str_replace('http:// www','http://www',$comments_cleantext);
		$comments_cleantext = str_replace('https://',' https://',$comments_cleantext);
		$comments_cleantext = str_replace('https:// www','https://www',$comments_cleantext);
		$comments_cleantext = preg_replace('`([^"=\'>])(((http|https|ftp)://|www.)[^\s<]+[^\s<\.)])`i',' <a href="$2">$2</a> ',$comments_cleantext);
		$comments_cleantext = substr($comments_cleantext, 1);
		$comments_cleantext = str_replace('href="www','href="http://www',$comments_cleantext);
	}

	return $comments_cleantext;
}

// comments_check_email
function comments_check_email($email)
{
	//### RegEx begin
	$nonascii      = "\x80-\xff"; //### Non-ASCII-Chars are not allowed

	$nqtext        = "[^\\\\$nonascii\015\012\"]";
	$qchar         = "\\\\[^$nonascii]";

	$protocol      = '(?:mailto:)';

	$normuser      = '[a-zA-Z0-9][a-zA-Z0-9_.-]*';
	$quotedstring  = "\"(?:$nqtext|$qchar)+\"";
	$user_part     = "(?:$normuser|$quotedstring)";

	$dom_mainpart  = '[a-zA-Z0-9][a-zA-Z0-9._-]*\\.';
	$dom_subpart   = '(?:[a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*';
	$dom_tldpart   = '[a-zA-Z]{2,5}';
	$domain_part   = "$dom_subpart$dom_mainpart$dom_tldpart";

	$regex         = "$protocol?$user_part\@$domain_part";
	//### RegEx end

	return preg_match("/^$regex$/",$email);
}

// comments_check_uri

function comments_check_uri($uri)
{ 
	$uri_reg="'^(http\://|https\://)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}(/\S*)?$'s";
	return preg_match($uri_reg, $uri); 
}


// comments_array_combine 
if (!function_exists('array_combine')) 
{
	function array_combine( $keys, $vals ) 
	{
		$keys = array_values((array)$keys);
		$vals = array_values((array)$vals);
		$n = max(count($keys), count($vals));
		$r = array();
		for( $i=0; $i<$n; $i++ ) 
		{ 
			$r[$keys[$i]]=$vals[$i]; 
		}
		return $r;
	}
}

// comments_write_log 

function comments_write_log($new_line_array)
{ 
	global $pth, $plugin_cf, $pth, $co_author_folder;
	
	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	$upload_path=$content_path.'upload/';
	
	if($plugin_cf['comments']['logging_filename']=="")
	{
		return false;
	}
	$max_size=($plugin_cf['comments']['logging_max_filesize']=="")?0:$plugin_cf['comments']['logging_max_filesize'];
	$logging_level=array();
	switch ($plugin_cf['comments']['logging_level'])
	{ 
		case 1  : //#### Standard 
		$logging_level[]='new_entry'; 
		break;
		
		case 2  : 
		$logging_level[]='new_entry'; 
		$logging_level[]='picture_upload'; 
		break;
		
		case 3  : 
		$logging_level[]='new_entry'; 
		$logging_level[]='picture_upload'; 
		$logging_level[]='picture_failure'; 
		break;
		
		case 4  : 
		$logging_level[]='new_entry'; 
		$logging_level[]='picture_upload'; 
		$logging_level[]='picture_failure'; 
		$logging_level[]='form_failure'; 
		break;
		default : break; 
	}
	
	if (in_array($new_line_array[1], $logging_level)) 
	{ 
		$file_name=$plugin_cf['comments']['logging_filename'];
		$file_path=$pth['folder']['base'].$plugin_cf['comments']['logging_path'];
		comments_write_line($file_name,$file_path, $new_line_array, $max_size); 
	}
}

/* #### END FUNCTIONS #### */



if(isset($_POST['commentsSortDirection']) && $plugin_cf['comments']['allow_users_change_sort_direction'] == 'true') 
{
	$_SESSION['comments_sortDirection'] = $_POST['commentsSortDirection'];
}

if(isset($_SESSION['comments_sortDirection']) && $_SESSION['comments_sortDirection'] != '')
{
	$comments_entrySortDirection = $_SESSION['comments_sortDirection'];
}
else
{
	$comments_entrySortDirection = $plugin_cf['comments']['sort_direction'];
}


//### comments main-Function  ###
function comments($blog_nr,$ma_protected='open',$entry_start='') 
{
	global $cf, $adm, $sn, $su, $s, $sl, $pth, $plugin, $plugin_pth, $plugin_cf, $plugin_tx, $content_path, $upload_path, $co_author_folder,$comments_version, $mvwd_new_file_content, $co_author_folder, $entry_nr, $commentsLocation, $commModerationHint, $comments_entrySortDirection;
	
	if(!defined('CMSIMPLE_VERSION'))
	{
		return '<p>This plugin requires <b>CMSimple 4.2</b> or higher.</p><p><a href="https://www.cmsimple.org/?Downloads___CMSimple">CMSimple Download & Updates &raquo;</a></p>';
	}
	
	$GLOBALS["ma_protected"] = $ma_protected;
	
	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	$upload_path=$content_path.'upload/';
//	echo $content_path;
//	echo 'von comments: ' . $co_author_folder . '<br>';

$GLOBALS['blog_nr'] = $blog_nr;

//### Diagnosis ###
	if(($plugin_cf['comments']['debugging']=='index' || $plugin_cf['comments']['debugging']=='both') && $plugin_cf['comments']['debugging_filename']!='')
	{
		if($plugin_cf['comments']['debugging_mode']=='vis'||$plugin_cf['comments']['debugging_mode']=='both')
		{ 
			echo('<br>$_SESSION: ');
			print_r($_SESSION);
			echo('<br>$_POST: ');
			print_r($_POST); 
		}
  
		if($plugin_cf['comments']['debugging_mode']=='file'||$plugin_cf['comments']['debugging_mode']=='both')
		{ 
			$debug_file=$plugin_cf['comments']['logging_path'].$plugin_cf['comments']['debugging_filename'];
		error_log ("\n".'/*-----------------------------------------------------*/', 3, $debug_file);
		error_log ("\n".time().' - Language: '.$sl.' - Source: index - Config: '.$plugin_cf['comments']['debugging'], 3, $debug_file);
		error_log ("\n".'$_SESSION: '.serialize($_SESSION), 3, $debug_file);
		error_log ("\n".'$_POST: '.serialize($_POST), 3, $debug_file);
		ini_set("error_reporting",E_ALL); // Aktiviert alle Error Meldungen
		ini_set("display_errors",0); // Unterdrückt die Error Meldungen
		ini_set("log_errors",1); // Aktiviert Logging
		ini_set("error_log",$debug_file); /* Gibt Pfad zum LOG-File an */ 
		}
	}
	//### END: Diagnosis ###

//	$mvwd_new_file_content=$comments_version.'-,+;-admin-,+;-open-,+;--,+;--,+;--,+;--,+;-';
	$list_parameters=array('title', 'user', 'email', 'homepage', 'ipadr', 'timestamp', 'img', 'blog_text');
	$plugin=basename(dirname(__FILE__),"/");
	$plugin_pth=$pth['folder']['plugins'].$plugin;
 
	$form_failure='';
	$form_failure_css='';
	
	$blog_array = comments_read_file($blog_nr, $list_parameters);

	if (isset($_POST['comments']))
	{
		$img_maxsize = $plugin_cf['comments']['image_max_size'];
		$img_maxwdt = $plugin_cf['comments']['image_max_width'];
		$img_maxhgt = $plugin_cf['comments']['image_max_height'];
		$upl_dir = $upload_path;
		$img_qlty = $plugin_cf['comments']['image_jpg_quality'];
		$img_size = $_FILES['pic_upload']['size'];
		$upl_picname = $_FILES['pic_upload']['name'];
		$upl_pictmp = $_FILES['pic_upload']['tmp_name'];
		$img_type = $_FILES['pic_upload']['type']; 

		$new_entry_array=comments_check_form();
		if(isset($_SESSION['reload'])) 
		{ 
			if($_SESSION['reload'] == $_POST['reload']) 
			{ 
				$new_entry_array='reload'; 
			} 
		}
		$_SESSION['reload'] = $_POST['reload']; 
		if (gettype($new_entry_array)=='array')
		{
			$form_failure=2;
			if ($plugin_cf['comments']['image_allow_upload']==true && $_FILES['pic_upload']['name']) 
			{
				if ($img_size>$img_maxsize) 
				{
					$form_failure=$plugin_tx['comments']['form_failure_imagesize_text'].($img_size/1000).'kByte. Maximum: '.($img_maxsize/1000).'kByte.';
					$new_entry_array['img']='false';
					$comments_log_array = array(time(),'picture_failure',$blog_nr,$form_failure);
					comments_write_log($comments_log_array); 
				}
				else
				{ 
					$new_size = comments_create_thumb ($upl_picname,$upl_pictmp,$img_maxwdt,$img_maxhgt,$upl_dir,$img_qlty,$img_type);
					if (gettype($new_size)=='string') 
					{ 
						$form_failure=$new_size; $new_entry_array['img']='false';
						$comments_log_array = array(time(),'picture_failure',$blog_nr,$form_failure);
						comments_write_log($comments_log_array); 
					}
					
					if (gettype($new_size)=='array')
					{ 
					
						if($plugin_cf['comments']['comments_moderate'] == 'true')
						{
							$form_failure='<p>' . $plugin_tx['comments']['form_success_with_image_text'] . $new_size[0] . 'x' . $new_size[1] . 'px.</p><p><b>' . $plugin_tx['comments']['form_success_mod'] . '</b></p>';
						}
						else
						{
							$form_failure = $plugin_tx['comments']['form_success_with_image_text'] . $new_size[0] . 'x' . $new_size[1] . 'px.';
						}
						$new_entry_array['img']=$upload_path.$new_size[2];
						$comments_log_array = array(time(),'picture_upload',$blog_nr,$new_entry_array['img']);
						comments_write_log($comments_log_array); 
					} 
				}
			}
			if(isset($co_author_folder))$new_entry_array['img'] = str_replace($co_author_folder,'',$new_entry_array['img']);
			comments_write_line($blog_nr,'',$new_entry_array);
			
			$comments_content = str_replace('</p>',"\n\n",$_POST['blog_text']);
			$comments_content = str_replace('<br> ',"\n",$comments_content);
			$comments_content = str_replace('<br /> ',"\n",$comments_content);
			$comments_content = str_replace('<br>',"\n",$comments_content);
			$comments_content = str_replace('<br />',"\n",$comments_content);
			$comments_content = preg_replace("'<[\/\!]*?[^<>]*?>'si",'',$comments_content);
			$comments_content = html_entity_decode($comments_content);
			
			$commentsMailLocation = htmlspecialchars($_SERVER['QUERY_STRING'], ENT_QUOTES, 'UTF-8');
			$commentsMailLocation = str_replace('&amp;','&',$commentsMailLocation);
			$commentsMailLocation = stripslashes(strip_tags($commentsMailLocation));
			$commentsMailLocation = str_replace('commentsDTC','commentsDND',$commentsMailLocation);
			
			if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')
			{
				$prot_http = 'https://';
			}
			else
			{
				$prot_http = 'http://';
			}
			
			mail($plugin_cf['comments']['admin_info_mail'],
			$plugin_tx['comments']['email_new_comment_on'] . ' ' . $_SERVER['SERVER_NAME'] . $sn,
			$plugin_tx['comments']['email_new_comment_on'] . ' ' . $prot_http . $_SERVER['SERVER_NAME'] . $sn . '?' . $commentsMailLocation .
			"\n\n" . $plugin_tx['comments']['email_from'] . ': ' . $_POST['user'] . ', ' . $_POST['email'] . 
			"\n\n" . $comments_content,
			"From: Comments");
			
			$comments_log_array = array(time(),'new_entry',$blog_nr);
			comments_write_log($comments_log_array);
		}
		elseif ($new_entry_array=='reload') 
		{ 
			$form_failure=''; 
		}
		else 
		{ 
			$form_failure_css=$new_entry_array; 
			$form_failure=1; 
		}
		
		if($form_failure == 2 || (isset($new_size) && $form_failure == $plugin_tx['comments']['form_success_with_image_text'] . $new_size[0] . 'x' . $new_size[1] . 'px.'))
		{
			global $u, $s;
			header('Location: ?' . str_replace('&amp;','&',htmlspecialchars(strip_tags($_SERVER['QUERY_STRING']), ENT_QUOTES, 'UTF-8')) . '&commentsModHint#commentsEditAnchor');
		}
	}

	$blog_status = array_shift($blog_array);
	if (($blog_status['user']=='admin')&&(($blog_status['email']=='closed')||($blog_status['email']=='close'))) 
	{
		$blog_status='<p id="comments_sent" class="comments_blog_closed">'.$plugin_tx['comments']['form_blog_closed'].'</p>'; 
	}
	else 
	{
		$blog_status=comments_foot($form_failure); 
	}
	
	// moderation - GE 2010-11-23
	
	foreach ($blog_array as $key => $row)
	{
		if($blog_array[$key]['title'] == 'hidden' && !$adm)
		{
			unset ($blog_array[$key]);
		}
	}
	
	foreach ($blog_array as $key => $row)
	{ 
		$time[$key]=$row['timestamp']; 
	}
	if($comments_entrySortDirection=='desc') 
	{
		if(isset($time))array_multisort($time, SORT_DESC, $blog_array);
	}
	else 
	{ 
		if(isset($time))array_multisort($time, SORT_ASC, $blog_array); 
	}
	
	if(isset($_GET['next'])) $entry_start = commentsSafeInput($_GET['next']); else $entry_start = 0; 
	
/*
#########################################################################################
BEGIN direct editing of comments
#########################################################################################
*/

	$comments_entry=comments_entry($blog_array,$entry_start);
	
	isset($_GET['page']) ? $commentsGetPage = '&amp;page=' . commentsSafeInput($_GET['page']) : $commentsGetPage = '';
	isset($_GET['next']) ? $commentsGetNext = '&amp;next=' . commentsSafeInput($_GET['next']) : $commentsGetNext = '';
	isset($_GET['nbfirst']) ? $commentsGetNbfirst = '&amp;nbfirst=' . commentsSafeInput($_GET['nbfirst']) : $commentsGetNbfirst = '';
	isset($_GET['nbcat']) ? $commentsGetNbcat = '&amp;nbcat=' . commentsSafeInput($_GET['nbcat']) : $commentsGetNbcat = '';
	isset($_GET['realblogaction']) ? $commentsGetRealblogaction = '&amp;realblogaction=' . commentsSafeInput($_GET['realblogaction']) : $commentsGetRealblogaction = '';
	isset($_GET['realblogID']) ? $commentsGetRealblogID = '&amp;realblogID=' . commentsSafeInput($_GET['realblogID']) : $commentsGetRealblogID = '';
	
	if(isset($_GET['commentsDTC']) && $adm)
	{
		$editEntryNumber = commentsSafeInput($_GET['commentsDTC']);
		
		unlink($blog_array[$editEntryNumber]['img']);
		
		$commentsOldContent = file_get_contents('./content/comments/' . $blog_nr . '.txt');
		$commentsNewContent = str_replace(
		$blog_array[$editEntryNumber]['title'] . '-,+;-' . $blog_array[$editEntryNumber]['user'] . '-,+;-' . $blog_array[$editEntryNumber]['email'] . '-,+;-' . $blog_array[$editEntryNumber]['homepage'] . '-,+;-' . $blog_array[$editEntryNumber]['ipadr'] . '-,+;-' . $blog_array[$editEntryNumber]['timestamp'] . '-,+;-' . $blog_array[$editEntryNumber]['img'] . '-,+;-' . $blog_array[$editEntryNumber]['blog_text'],'',
		$commentsOldContent);
		$commentsNewContent = trim($commentsNewContent);

		$commentsFile = fopen('./content/comments/' . $blog_nr . '.txt', 'w+');
		fwrite($commentsFile, $commentsNewContent);
		fclose($commentsFile);
		
		$commentsLocation = htmlspecialchars($_SERVER['QUERY_STRING'], ENT_QUOTES, 'UTF-8');
		$commentsLocation = str_replace('&amp;','&',$commentsLocation);
		$commentsLocation = stripslashes(strip_tags($commentsLocation));
		$commentsLocation = str_replace('commentsDTC','commentsDND',$commentsLocation);
		
		header('Location: ./?' . $commentsLocation . '#commentsChangeStatus');
	}

	if(isset($_GET['commentsETC']) && $adm)
	{
		$editEntryNumber = commentsSafeInput($_GET['commentsETC']);

		if(isset($_GET['commentsDI']) && $adm)
		{
			unlink($blog_array[$editEntryNumber]['img']);
		}
		
		$form_failure_css = '';
		$comments_header = '';
		$comments_entry = '';
		$blog_status = '';
		
		$comments_entry.= '<p id="commentsEditAnchor" class="commentsEditAnchor">&nbsp;</p>
<h4>' . $plugin_tx['comments']['admin_headline_edit_comment'] . '</h4>';
		$comments_entry.= '<p><span class="commentsButtonLeft"><a href="./?' . $su . $commentsGetPage . $commentsGetNext . $commentsGetNbfirst . $commentsGetNbcat . $commentsGetRealblogaction . $commentsGetRealblogID . '#commentsChangeStatus">' . $plugin_tx['comments']['admin_button_back'] . '</a></span></p><br>
<br>';
		$comments_entry.= '<p><b>' . $plugin_tx['comments']['admin_headline_comment_image'] . '</b></p>';
		if(file_exists($blog_array[$editEntryNumber]['img']))
		{
			$comments_entry.= '<img src="' . $blog_array[$editEntryNumber]['img'] . '" alt="">';
			$comments_entry.= '<br>
<span class="commentsButtonLeft"><a href="./?' . $su . '&amp;realblogaction=view&&amp;realblogID=' . (isset($_GET['realblogID'])?$_GET['realblogID']:'') . '&amp;commentsETC=' . $editEntryNumber . '&amp;commentsDI=1#commentsEditAnchor" onClick="return confirm(\'' . $plugin_tx['comments']['admin_confirm'] . '\')">' . $plugin_tx['comments']['admin_button_delete_image'] . '</a></span>
<br>
<br>
';
		}
		else
		{
			$comments_entry.= '<p>' . $plugin_tx['comments']['admin_hint_no_image'] . '</p>';
		}
		$comments_entry.= '<hr><p><b>' . $plugin_tx['comments']['admin_headline_comment_text'] . '</b></p>';
		
		// Safe edited entry
		if(isset($_POST['commentsEditText']))
		{
			$commentSaveEntry = comments_cleantext($_POST['commentsEditText']);
		}
		else
		{
			$commentSaveEntry = '';
		}
		
		// Publish comment
		if(isset($_POST['commentsEditText']) && !isset($_POST['commentsEnableComment'])){$_POST['commentsEnableComment'] = '';}
		if(isset($_POST['commentsEnableComment'])){$commentPublicStatus = commentsSafeInput($_POST['commentsEnableComment']);}
		if(isset($_POST['commentsUser'])){$commentUser = commentsSafeInput($_POST['commentsUser']);}
		if(isset($_POST['commentsEmail'])){$commentEmail = commentsSafeInput($_POST['commentsEmail']);}
		if(isset($_POST['commentsHomepage'])){$commentHomepage = commentsSafeInput($_POST['commentsHomepage']);}
		if(isset($_POST['commentsControl'])){ header('Location: #commentsEditAnchor');}
		
		if($commentSaveEntry != '')
		{
			$commentsOldContent = file_get_contents('./content/comments/' . $blog_nr . '.txt');
			$commentsNewContent = str_replace(
			$blog_array[$editEntryNumber]['title'] . '-,+;-' . $blog_array[$editEntryNumber]['user'] . '-,+;-' . $blog_array[$editEntryNumber]['email'] . '-,+;-' . $blog_array[$editEntryNumber]['homepage'] . '-,+;-' . $blog_array[$editEntryNumber]['ipadr'] . '-,+;-' . $blog_array[$editEntryNumber]['timestamp'] . '-,+;-' . $blog_array[$editEntryNumber]['img'] . '-,+;-' . $blog_array[$editEntryNumber]['blog_text'],
			$commentPublicStatus . '-,+;-' . $commentUser . '-,+;-' . $commentEmail . '-,+;-' . $commentHomepage . '-,+;-' . $blog_array[$editEntryNumber]['ipadr'] . '-,+;-' . $blog_array[$editEntryNumber]['timestamp'] . '-,+;-' . $blog_array[$editEntryNumber]['img'] . '-,+;-' . $commentSaveEntry . "\r\n",
			$commentsOldContent);
			$commentsNewContent = trim($commentsNewContent);
			
			$commentsFile = fopen('./content/comments/' . $blog_nr . '.txt', 'w+');
			fwrite($commentsFile, $commentsNewContent);
			fclose($commentsFile);
		}
		
		// textarea and editor
		$comments_entry.= '
<script src="'.$plugin_pth.'/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>

<script>
/* <![CDATA[ */
tinyMCE.init({
theme : "advanced",';

		if($cf['xhtml']['endtags'] != "true")
		{
			$comments_entry.='element_format : "html",';
		}

		$comments_entry.='
mode : "exact",';

		if(file_exists($pth['folder']['plugins'] . 'comments/tinymce/jscripts/tiny_mce/langs/' . $sl . '.js'))
		{
			$comments_entry.='
language: "' . $sl . '",';
		}
		else
		{
			$comments_entry.='
language: "en",';
		}
		
		$comments_entry.='
elements : "commentsEditText",
theme_advanced_buttons1 : "blockquote,separator,bold,italic,underline,removeformat,separator,undo,redo,link,unlink,separator,emotions,code",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
content_css : "' . $pth['file']['stylesheet'] . '",
plugins : "emotions",
theme_advanced_toolbar_location : "' . $plugin_cf['comments']['editor_toolbar'] . '",
height : "' . $plugin_cf['comments']['editor_height'] . '",
width : "' . $plugin_cf['comments']['editor_width'] . '",
inline_styles : false,
convert_urls : false,
relative_urls : false,
remove_script_host : false,
formats : {underline : {inline : "u", exact : true}}
});
/* ]]> */
</script>
';
		
		// "edit comment" form
		$comments_entry.= '<form action="#commentsEditAnchor" method="POST">';
		
		$comments_entry.= "\n" . '<textarea id="commentsEditText" name="commentsEditText" class="commentsEditText">' . "\n";
		
		if($commentSaveEntry != '')
		{
			$comments_entry.= $commentSaveEntry;
		}
		else
		{
			$comments_entry.= $blog_array[$editEntryNumber]['blog_text'];
		}
		
		$comments_entry.= '</textarea>
';

		$comments_entry.= '<p><b><br>' . $plugin_tx['comments']['admin_headline_comment_data'] . '</b></p>
<p>' . date($plugin_cf['comments']['date_format'],$time[$key]) . ' ' . date($plugin_cf['comments']['time_format'],$time[$key]) . ' (IP: ' . $blog_array[$editEntryNumber]['ipadr'] . ')</p>';

		// Radio button "publish comment" (for moderation)
		$comments_entry.= '<p><input type="checkbox" name="commentsEnableComment" id="commentsEnableComment" value="hidden"';
		if($blog_array[$editEntryNumber]['title'] == 'hidden')
		{
			$comments_entry.= 'checked="checked"';
		}
		else
		{
			$comments_entry.= '';
		}
		$comments_entry.= '> ' . $plugin_tx['comments']['admin_label_hide_comment'] . '</p>
';
		// user
		$comments_entry.= '<br>
<div><b>' . $plugin_tx['comments']['admin_label_user'] . ' </b></div>
<input type="text" class="commentsEditInput" name="commentsUser" id="commentsUser" value="' . $blog_array[$editEntryNumber]['user'] . '">
';
		
		// email
		$comments_entry.= '<div><b>' . $plugin_tx['comments']['admin_label_email'] . ' </b></div>
<input type="text" class="commentsEditInput" name="commentsEmail" id="commentsEemail" value="' . $blog_array[$editEntryNumber]['email'] . '">
';
		
		//website
		$comments_entry.= '<div><b>' . $plugin_tx['comments']['admin_label_website'] . ' </b></div>
<input type="text" class="commentsEditInput" name="commentsHomepage" id="commentsHomepage" value="' . $blog_array[$editEntryNumber]['homepage'] . '">
';
		
		// Control
		$comments_entry.= '<input type="hidden" name="commentsControl" id="commentsControl" value="Control">
';
		
		$comments_entry.= '
<div style="clear: both; width: 100%; height: 16px;"></div>
<input type="submit" class="commentsButtonLeft" value="' . $plugin_tx['comments']['admin_button_save_changes'] . '">
<div style="clear: both; width: 100%; height: 16px;"></div>
</form>
<p><span class="commentsButtonLeft"><a href="./?' . $su . $commentsGetPage . $commentsGetNext . $commentsGetNbfirst . $commentsGetNbcat . $commentsGetRealblogaction . $commentsGetRealblogID . '#commentsChangeStatus">' . $plugin_tx['comments']['admin_button_back'] . '</a></span></p>
<div style="clear: both; width: 100%; height: 16px;"><br><br><br></div>
';
		
		return $comments_entry;
	}
	
/*
#########################################################################################
END direct editing of comments
#########################################################################################
*/
	
	// Change status
	
	$commentsArrayAdmin = comments_read_file($blog_nr, $list_parameters);
	$commentsStatusAdmin = array_shift($commentsArrayAdmin);
	$commentsStatusAdminString = implode('-,+;-',$commentsStatusAdmin);
	
	if($adm)
	{
		$commentsChangeStatus = '
<div id="commentsChangeStatus"><br><br><br></div>
<form action="#comments' . $blog_nr . '" method="POST">
<hr><p><b>' . $plugin_tx['comments']['admin_headline_comment_function'] . '</b></p>
<input type="radio" name="commentsOpen" id="commentsOpen" value="open" ' . (($commentsStatusAdmin['user']=='admin')&&($commentsStatusAdmin['email']=='opened')||($commentsStatusAdmin['email']=='open') ? 'checked="checked"' : '') . '> ' . $plugin_tx['comments']['admin_label_enabled'] . ' &nbsp; 
<input type="radio" name="commentsOpen" id="commentsOpen" value="close" ' . (($commentsStatusAdmin['user']=='admin')&&($commentsStatusAdmin['email']!='opened')&&($commentsStatusAdmin['email']!='open') ? 'checked="checked"' : '') . '> ' . $plugin_tx['comments']['admin_label_disabled'] . ' &nbsp; 

<input type="submit" class="commentsButtonInline" value="' . $plugin_tx['comments']['admin_button_save'] . '">
</form><hr>';
	}
	else
	{
		$commentsChangeStatus = '';
	}
	
	if(isset($_POST['commentsOpen']))
	{
		$commentsStatusSave = commentsSafeInput($_POST['commentsOpen']);
		
		$commentsOldStatus = file_get_contents('./content/comments/' . $blog_nr . '.txt');
		$commentsNewStatus = str_replace(implode('-,+;-',$commentsStatusAdmin),str_replace($commentsStatusAdmin['email'],commentsSafeInput($_POST['commentsOpen']),$commentsStatusAdminString),$commentsOldStatus);
		$commentsNewStatus = trim($commentsNewStatus);
		
		$commentsFile = fopen('./content/comments/' . $blog_nr . '.txt', 'w+');
		fwrite($commentsFile, $commentsNewStatus);
		fclose($commentsFile);
		
		header('Location: #commentsChangeStatus');
	}
	
	
	if // membersarea logged in users only (except newmembers group)
	(
		(
			(
				isset($_SESSION['mapl_userdata' . $sn])
			)
			&& 
			(
				$_SESSION['mapl_group_user' . $sn] != $plugin_cf['membersarea']['register_newmembers_group'] || 
				$plugin_cf['comments']['allow_newmembers_comment'] == 'true'
			)
			&& !isset($_POST['mapl_logout'])
		)
		|| $ma_protected != 'protected' 
		|| $adm
	)
	{
		return "\n" . '
<div id="commentsEditAnchor"></div>
' . $commModerationHint . '
<div class="comments_main" id="comments_' . $blog_nr . '">
' . $commentsChangeStatus . $form_failure_css . comments_header(count($blog_array),$blog_nr) . $comments_entry . $blog_status . '
</div>
'; 
	}
	else
	{
		return "\n" . '
<div id="commentsEditAnchor"></div>
' . $commModerationHint . '
<div class="comments_main" id="comments_' . $blog_nr . '">
' . $commentsChangeStatus . $form_failure_css . comments_header(count($blog_array),$blog_nr) . $comments_entry . '
<p><b>' . ($commentsStatusAdmin['email']!='open' ? $plugin_tx['comments']['form_blog_closed'] : "") . '</b></p>
</div>
'; 
	}
}
//### END: comments main-Function  ###

//### comments_check_form  ###

function comments_check_form()  
{
	global $pth, $plugin_cf, $plugin_pth, $blog_nr, $content_path, $upload_path, $co_author_folder;
	
	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	$upload_path=$content_path.'upload/';

	$img = ($_FILES['pic_upload']['name']) ? $upload_path.$_FILES['pic_upload']['name'] : 'false';

	$uri='';
	$form_failure=false;
	$form_failure_css='';
	$form_failure_head='<style type="text/css">';
	$form_failure_color = ($plugin_cf['comments']['form_failure_color']) ?$plugin_cf['comments']['form_failure_color'] : 'red';
	$form_failure_style='{border:1px solid '.$form_failure_color.';}';

	if ($_POST['homepage']) 
	{ 
		$uri=commentsSafeInput($_POST['homepage']);
		$sub8=substr($uri, 0, 8);
		$sub7=substr($uri, 0, 7);
		$sub6=substr($uri, 0, 6);
		if ($sub8!='https://'&&$sub7!='http://'&&$sub6!='ftp://') 
		{ 
			$uri='http://'.$uri; 
		}

//		echo('vorCheck:'.$uri);

		if(!comments_check_uri($uri)) 
		{ 
			$form_failure_css.=(!$form_failure)?$form_failure_head:''; 
			$form_failure_css.=' .comments_form_input input'.$form_failure_style;
			$form_failure='true'; 
		}
	}
	if ($_POST['email']) 
	{ 
		if(!comments_check_email($_POST['email'])) 
		{ 
		$form_failure_css.=(!$form_failure)?$form_failure_head:''; 
		$form_failure_css.=' #comments_form_input_email input'.$form_failure_style; 
		$form_failure='true'; 
		}
	}
	if (!$_POST['email']&&$plugin_cf['comments']['require_email']=='true') 
	{ 
		$form_failure_css.=(!$form_failure)?$form_failure_head:''; 
		$form_failure_css.=' #comments_form_input_email input'.$form_failure_style; 
		$form_failure=true; 
	}
	if (!$_POST['title'] && $plugin_cf['comments']['require_title']=='true') 
	{ 
		$form_failure_css.=(!$form_failure)?$form_failure_head:''; 
		$form_failure_css.=' #comments_form_input_title input'.$form_failure_style; 
		$form_failure=true; 
	}
	if (!$_POST['user']&&$plugin_cf['comments']['require_user']=='true') 
	{ 
		$form_failure_css.=(!$form_failure)?$form_failure_head:''; 
		$form_failure_css.=' #comments_form_input_user input'.$form_failure_style; 
		$form_failure=true; 
	}
	if (!$_POST['blog_text']) 
	{ 
		$form_failure_css.=(!$form_failure)?$form_failure_head:''; 
		$form_failure_css.=' #comments_form_input_blog_text textarea'.$form_failure_style; 
		$form_failure=true; 
	}
	if ($plugin_cf['comments']['use_captcha'] == 'true')
	{
		if(!isset($_SESSION)){session_start();}   //## only necessary if using captcha-Function
		if (!isset($_POST['captcha']) || (isset($_POST['captcha']) && strtoupper($_POST['captcha'])!=strtoupper($_SESSION['captcha']))) 
		{ 
			$form_failure_css.=(!$form_failure)?$form_failure_head:''; 
			$form_failure_css.=' #comments_form_captcha input'.$form_failure_style; 
			$form_failure_css.=' #comments_form_captcha img'.$form_failure_style; 
			$form_failure=true; 
		}
	}

	$form_failure_css.=($form_failure)?'</style>':''; 

	if (!$form_failure_css)
	{
		$new_entry_array = array(
		'title'=>comments_cleantext($_POST['title']), 
		'user'=>comments_cleantext($_POST['user']), 
		'email'=>commentsSafeInput($_POST['email']), 
		'homepage'=>$uri, 
		'ipadr'=>$_SERVER['REMOTE_ADDR'], 
		'timestamp'=>time(), 
		'img'=>$img,
		'blog_text'=>comments_cleantext($_POST['blog_text'])
		);
		return $new_entry_array;
	}
	else
	{
		$comments_log_array = array(time(),'form_failure',$blog_nr,str_replace('</style>','',str_replace('<style type="text/css"> ','',$form_failure_css)));
		comments_write_log($comments_log_array);
		return $form_failure_css;
	}
} 
//### END: comments_check_form  ###


//### comments_header  ###

function comments_header($comments_count,$blog_nr)
{
	global $pth, $plugin_cf, $plugin_tx, $content_path, $upload_path, $co_author_folder, $comments_entrySortDirection;

	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	$upload_path=$content_path.'upload/';

	// function output
	$header = '<div id="comments_entries" class="comments_number_of">
<h4>'.$plugin_tx['comments']['blog_heading'].' '.$comments_count.'</h4>
</div>
';

	if($plugin_cf['comments']['allow_users_change_sort_direction'] == 'true' && $comments_count > 0)
	{
		$header.= '
<form method="post" action="#commentsEditAnchor">' . "\n";
		$header.='<select name="commentsSortDirection" onchange="this.form.submit()" class="comments_selectSortDirection">' . "\n";

		if($comments_entrySortDirection == 'desc')
		{
			$header.='<option class="comments_sortDirectionOption" selected="selected" value="desc">' . $plugin_tx['comments']['sort_direction_newest_first'] . '</option>' . "\n";
		}
		else
		{
			$header.='<option class="comments_sortDirectionOption" value="desc">' . $plugin_tx['comments']['sort_direction_newest_first'] . '</option>' . "\n";
		}

		if($comments_entrySortDirection == 'asc')
		{
			$header.='<option class="comments_sortDirectionOption" selected="selected" value="asc">' . $plugin_tx['comments']['sort_direction_oldest_first'] . '</option>' . "\n";
		}
		else
		{
			$header.='<option class="comments_sortDirectionOption" value="asc">' . $plugin_tx['comments']['sort_direction_oldest_first'] . '</option>' . "\n";
		}

		$header.= '</select>' . "\n";
		$header.= '</form>' . "\n";
	}

	return $header;
}

//### END: comments_header  ###



//### functions for RealBlog  ###

function number_of_comments($comments_count,$blog_nr)
{
	global $pth, $plugin_cf, $plugin_tx, $content_path, $upload_path, $co_author_folder;
	
	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	$upload_path=$content_path.'upload/';
	
	$header_realblog = $plugin_tx['comments']['blog_heading'].' '.$comments_count;
	return $header_realblog;
}

function comments_nr($blog_nr,$entry_start='') 
{
	global $pth, $plugin, $plugin_pth, $plugin_cf, $plugin_tx, $content_path, $upload_path, $comments_version, $mvwd_new_file_content, $co_author_folder, $blog_array;
	
	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	$upload_path=$content_path.'upload/';

	$list_parameters=array('title', 'user', 'email', 'homepage', 'ipadr', 'timestamp', 'img', 'blog_text');

	$blog_array = comments_read_file($blog_nr, $list_parameters);
	$blog_status = array_shift($blog_array);
	
	// moderation - GE 2010-11-23
	
	foreach ($blog_array as $key => $row)
	{
		if($blog_array[$key]['title'] == 'hidden')
		{
			unset ($blog_array[$key]);
		}
	}
	
	if(count($blog_array) > 0)
	{
		return number_of_comments(count($blog_array),$blog_nr);
	}
}

//### END: functions for RealBlog  ###


//### comments_entry  ###

function comments_entry($blog_array,$entry_start=0)
{
	global $adm, $pth, $plugin_pth, $plugin_cf, $plugin_tx, $cf, $sl, $sn, $su, $content_path, $upload_path, $co_author_folder, $ma_protected, $blog_nr, $comments_entrySortDirection;
	
	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	$upload_path=$content_path.'upload/';
	
	$split_foot='';
	$split_array=array();
	$entry='';
	$img='';
	$title='';
	$user='';
	$email='';
	$homepage='';
	$timestamp='';
	$ip='';

	$m=$plugin_cf['comments']['split_mode'];
	if($plugin_cf['comments']['split_entries']!=''&&$plugin_cf['comments']['split_entries']>0&&$plugin_cf['comments']['split_entries']<count($blog_array)&&($m=='arrow'|$m=='arrows'|$m=='link'|$m=='links'|$m=='page'|$m=='pages'))
	{ 
		$step=$plugin_cf['comments']['split_entries'];
		for($i=0;$i<=count($blog_array)-1;$i+=$step) 
		{ 
			$split_array[]=$i; 
		}
		$split_foot=
		'<div class="comments_entry_split">'
		.$plugin_tx['comments']['blog_entry_split_label'];
		$q=(($_SERVER['QUERY_STRING']=="")||(strpos($_SERVER['REQUEST_URI'], '?next=')))?'?':'&amp;';

		if($m=='arrow'||$m=='arrows') //### arrows
		{ 
			$split_foot.=($entry_start!=0)?'<a href="'.preg_replace('/[\&|\?](next=)[0-9]+/', '', $_SERVER['REQUEST_URI']).$q.'next='.($split_array[0]).'#comments_entries">|<<</a>':'';
			$split_foot.=($entry_start!=0)?'<a href="'.preg_replace('/[\&|\?](next=)[0-9]+/', '', $_SERVER['REQUEST_URI']).$q.'next='.($entry_start-$step).'#comments_entries"><</a>':'';
			$split_foot.='<span>'.($entry_start+1).'-'.($entry_start+$step).'</span>';
			$split_foot.=($entry_start!=$split_array[count($split_array)-1])?'<a href="'.preg_replace('/[\&|\?](next=)[0-9]+/', '', $_SERVER['REQUEST_URI']).$q.'next='.($entry_start+$step).'#comments_entries">></a>':'';
			$split_foot.=($entry_start!=$split_array[count($split_array)-1])?'<a href="'.preg_replace('/[\&|\?](next=)[0-9]+/', '', $_SERVER['REQUEST_URI']).$q.'next='.($split_array[count($split_array)-1]).'#comments_entries">>>|</a>':''; 
		}
		elseif ($m=='link'||$m=='links') //### links 1-5 6-10...
		{ 
			for ($i=0; $i<count($split_array); $i++)
			{ 
				$step=$plugin_cf['comments']['split_entries']; $ct=0;
				if ($plugin_cf['comments']['split_mode_links_reduce']=='true')
				{ 
					for($i;$i<$entry_start/$step-1;$i++)
					{ 
						if($i>0) 
						{ 
							if($ct==0) 
							{ 
								$split_foot.='<span>...</span>'; $ct++; 
							} 
						} 
						else 
						{ 
						$split_foot.='<a href="'.preg_replace('/[\&|\?](next=)[0-9]+/', '', $_SERVER['REQUEST_URI']).$q.'next='.($split_array[$i]).'#comments_entries">'.($split_array[$i]+1).'-'.($split_array[$i]+$step).'</a>'; 
						} 
					}
					$ct=0;
					for($i;$i<(count($split_array)-1)&&$i>$entry_start/$step+1;$i++)
					{ 
					if($i>$entry_start/$step+1) 
						{ 
							if($ct==0) 
							{ 
								$split_foot.='<span>...</span>'; $ct++; 
							} 
						} 
						else 
						{ $split_foot.='<a href="'.preg_replace('/[\&|\?](next=)[0-9]+/', '', $_SERVER['REQUEST_URI']).$q.'next='.($split_array[$i]).'#comments_entries">'.($split_array[$i]+1).'-'.($split_array[$i]+$step).'</a>'; 
						} 
					} 
				}
				if(($split_array[$i]+$step)>count($blog_array))
				{
					$step=count($blog_array)-$split_array[$i]; 
				}
				if($split_array[$i]!=$entry_start) 
				{ 
					$split_foot.='<a href="'.preg_replace('/[\&|\?](next=)[0-9]+/', '', $_SERVER['REQUEST_URI']).$q.'next='.($split_array[$i]).'#comments_entries">'.($split_array[$i]+1).'-'.($split_array[$i]+$step).'</a>'; 
				}
				else 
				{
					$split_foot.='<span>'.($split_array[$i]+1).'-'.($split_array[$i]+$step).'</span>'; 
				} 
			} 
		} 
		elseif ($m=='page'||$m=='pages') //### pages 1 2 3...
		{ 
			for ($i=0; $i<count($split_array); $i++)
			{ 
				$step=$plugin_cf['comments']['split_entries']; $ct=0;
				if ($plugin_cf['comments']['split_mode_links_reduce']=='true')
				{ 
					for($i;$i<$entry_start/$step-1;$i++)
					{ 
						if($i>0) 
						{ 
							if($ct==0) 
							{ 
								$split_foot.='<span>...</span>'; $ct++; 
							} 
						} 
						else 
						{ 
							$split_foot.='<a href="'.preg_replace('/[\&|\?](next=)[0-9]+/', '', $_SERVER['REQUEST_URI']).$q.'next='.($split_array[$i]).'#comments_entries">'.($i+1).'</a>'; 
						} 
					}
					$ct=0;
					for($i;$i<(count($split_array)-1)&&$i>$entry_start/$step+1;$i++)
					{ 
						if($i>$entry_start/$step+1) 
						{ 
							if($ct==0) 
							{ 
								$split_foot.='<span>...</span>'; $ct++; 
							} 
						} 
						else 
						{ 
							$split_foot.='<a href="'.preg_replace('/[\&|\?](next=)[0-9]+/', '', $_SERVER['REQUEST_URI']).$q.'next='.($split_array[$i]).'#comments_entries">'.($i+1).'</a>'; 
						} 
					} 
				}
				if(($split_array[$i]+$step)>count($blog_array))
				{
					$step=count($blog_array)-$split_array[$i]; 
				}
				if($split_array[$i]!=$entry_start) 
				{ 
					$split_foot.='<a href="'.preg_replace('/[\&|\?](next=)[0-9]+/', '', $_SERVER['REQUEST_URI']).$q.'next='.($split_array[$i]).'#comments_entries">'.($i+1).'</a>'; 
				}
				else 
				{ 
					$split_foot.='<span>'.($i+1).'</span>'; 
				} 
			} 
		} 
		$split_foot.= '</div>';
	}
	
	foreach($blog_array as $entry_nr => $value)
	{
		// shows image in entry
		if ($value['img'] != '') 
		{ 
			$img_name_array = explode('/', $value['img']);

			$img_name = array_pop($img_name_array);

			$value['img'] = str_replace('../','',$value['img']);
			$value['img'] = str_replace('./','',$value['img']);
			if(isset($co_author_folder)) $value['img'] = str_replace($co_author_folder,'',$value['img']);

			$img = '<img class="comments_entry_image" alt="' . $img_name . '" title="' . $img_name . '" src="' . $pth['folder']['base'] . $co_author_folder . $value['img'] . '">';
			if(!isset($co_author_folder)) 
			{
				$img = '<img class="comments_entry_image" alt="' . $img_name . '" title="' . $img_name . '" src="./' . $value['img'] . '">';
			}
		}
		if ($value['img'] == 'false') $img = '';

		if($comments_entrySortDirection == 'desc') 
		{
			$number = ($plugin_cf['comments']['show_entry_number']=='true') ? 
			'<div class="comments_entry_head_number">'
			.(count($blog_array)-($entry_nr)).
			'</div>' . "\n" 
			:'';
		}
		else
		{
			$number = ($plugin_cf['comments']['show_entry_number']=='true') ? 
			'<div class="comments_entry_head_number">'
			.($entry_nr+1).
			'</div>' . "\n" 
			:'';
		}

		$user = ($value['user']) ? '<div class="comments_entry_head_item_bold">' . '<img src="'.$plugin_pth.'/images/user.gif" alt="User" title="User">' . $value['user'].'</div>' . "\n" : '';

		$email = ($plugin_cf['comments']['show_email']=='true') || $adm ? '
<div class="comments_entry_head_item">
<img src="' . $plugin_pth . '/images/email.gif" alt="email" title="email">
<a href="mailto:' . $value['email'] . '" target="_blank">' . $value['email'] . '</a>
</div>' . "\n" : '';

		$timestamp = ($value['timestamp']) ? '<div class="comments_entry_head_item">
<img src="' . $plugin_pth . '/images/timestamp.gif" alt="Date / Time" title="Date / Time">' . date($plugin_cf['comments']['date_format'],$value['timestamp']) . ' '  . date($plugin_cf['comments']['time_format'], $value['timestamp']) . '</div>' . "\n" : '';

		if(stristr($value['homepage'],'http://') || stristr($value['homepage'],'https://'))
		{
			$homepageOutput = strip_tags($value['homepage']);
		}
		else
		{
			$homepageOutput = strip_tags('http://' . $value['homepage']);
		}

		$homepage = ($plugin_cf['comments']['show_homepage_adress']=='true') ? $homepage = ($value['homepage']) ? '
<div class="comments_entry_head_item">
<img src="' . $plugin_pth . '/images/homepage.gif" alt="Homepage" title="Homepage">
<a href="' . $homepageOutput . '" target="_blank">' . $value['homepage'] . '</a>
</div>' . "\n" : '' : '';

		$text = $value['blog_text'];

		if (($plugin_cf['comments']['split_entries']!=''&&$plugin_cf['comments']['split_entries']>0)&&$entry_nr>=($entry_start+intval($plugin_cf['comments']['split_entries'])))
		{ 
			return $entry.$split_foot;
		}

		if ($entry_start<=$entry_nr) 
		{ 
			if
			(
				(
					($plugin_cf['comments']['show_form_link'] == 'true' && $ma_protected != 'protected') || 
					($plugin_cf['comments']['show_form_link'] == 'true' && isset($_SESSION['mapl_userdata' . $sn]))
				)
				&& $plugin_cf['comments']['comments_allow_global'] == 'true' || $adm
			)
			{
				$entry.='

<div class="comments_form_link">
<p><a href="#comments_sent">' . $plugin_tx['comments']['form_link_text'] . '</a></p>
</div>
';
			}
			
			$entry.='
<div class="comments_entry">
<div class="comments_entry_head">
'.
			$number.
//			$title.
			$user.
			$email.
			$timestamp.
			$homepage.
			$ip.
			'
<div style="clear: both;"></div>
</div>

<div class="comments_entry_content">
<div class="comments_entry_image">
'.$img.'
</div>
<div style="clear: both;"></div>
'.$text.'
<div style="clear: both;"></div>
</div>
';

/*
#########################################################################################
BEGIN direct editing of comments
#########################################################################################
*/

			isset($_GET['page']) ? $commentsGetPage = '&amp;page=' . commentsSafeInput($_GET['page']) : $commentsGetPage = '';
			isset($_GET['next']) ? $commentsGetNext = '&amp;next=' . commentsSafeInput($_GET['next']) : $commentsGetNext = '';
			isset($_GET['nbfirst']) ? $commentsGetNbfirst = '&amp;nbfirst=' . commentsSafeInput($_GET['nbfirst']) : $commentsGetNbfirst = '';
			isset($_GET['nbcat']) ? $commentsGetNbcat = '&amp;nbcat=' . commentsSafeInput($_GET['nbcat']) : $commentsGetNbcat = '';
			isset($_GET['realblogaction']) ? $commentsGetRealblogaction = '&amp;realblogaction=' . commentsSafeInput($_GET['realblogaction']) : $commentsGetRealblogaction = '';
			isset($_GET['realblogID']) ? $commentsGetRealblogID = '&amp;realblogID=' . commentsSafeInput($_GET['realblogID']) : $commentsGetRealblogID = '';

			if($adm)
			{
				if($value['title'] == 'hidden')
				{
					$entry .= '<p class="commentsImportantHint">' . $plugin_tx['comments']['admin_hint_comment_not_published'] . '</p>';
				}
				
				$entry.='<p style="padding: 0; margin: 0 0 16px 0;">';

				if(isset($_GET['realblogID']))
				{
					if(file_exists('./content/comments/' . $blog_nr . '.txt'))
					{
						$entry.='
<span class="commentsButtonLeft"><a href="./?' . $su . '&amp;realblogaction=view&amp;realblogID=' . commentsSafeInput($_GET['realblogID']) . '&amp;commentsETC=' . $entry_nr . $commentsGetPage . $commentsGetNext . $commentsGetNbfirst . $commentsGetNbcat . $commentsGetRealblogaction . $commentsGetRealblogID . '#commentsEditAnchor">' . $plugin_tx['comments']['admin_button_edit_comment'] . '</a></span>  
<span class="commentsButtonLeft"><a href="./?' . $su . '&amp;realblogaction=view&amp;realblogID=' . commentsSafeInput($_GET['realblogID'])  . '&amp;commentsDTC=' . $entry_nr . $commentsGetPage . $commentsGetNext . $commentsGetNbfirst . $commentsGetNbcat . $commentsGetRealblogaction . $commentsGetRealblogID . '#commentsChangeStatus" onClick="return confirm(\'' . $plugin_tx['comments']['admin_confirm'] . '\')">' . $plugin_tx['comments']['admin_button_delete_comment'] . '</a></span>';
					}
					else $entry.= '<p style="background: #910; color: #fff; text-align: center; font-weight: 700; padding: 9px 16px;">No editing possible.</p>';
				}
				else
				{
					if(file_exists('./content/comments/' . $blog_nr . '.txt'))
					{
						$entry.='
<span class="commentsButtonLeft"><a href="./?' . $su . '&amp;commentsETC=' . $entry_nr . $commentsGetPage . $commentsGetNext . $commentsGetNbfirst . $commentsGetNbcat . $commentsGetRealblogaction . $commentsGetRealblogID . '#commentsEditAnchor">' . $plugin_tx['comments']['admin_button_edit_comment'] . '</a></span>  
<span class="commentsButtonLeft"><a href="./?' . $su . '&amp;commentsDTC=' . $entry_nr . $commentsGetPage . $commentsGetNext . $commentsGetNbfirst . $commentsGetNbcat . $commentsGetRealblogaction . $commentsGetRealblogID . '#commentsChangeStatus" onClick="return confirm(\'' . $plugin_tx['comments']['admin_confirm'] . '\')">' . $plugin_tx['comments']['admin_button_delete_comment'] . '</a></span>';
					}
					else $entry.= '<p style="background: #910; color: #fff; text-align: center; font-weight: 700; padding: 9px 16px;">No editing possible.</p>';
				}
				$entry.= '
</p>
<br>
';
			}

/*
#########################################################################################
END direct editing of comments
#########################################################################################
*/
	
			$entry.='</div>
';
		}
		
		if (($plugin_cf['comments']['split_entries']!='' && $plugin_cf['comments']['split_entries']>0) && $entry_nr==count($blog_array)-1)
		{ 
			return $entry.$split_foot; 
		}

	} //### END: foreach
	
	return $entry;
} 
//### END: comments_entry  ###



//### comments_foot  ###

function comments_foot($form_failure)
{
	global $sn, $su, $plugin_pth, $pth, $plugin_cf, $plugin_tx, $DocType, $ccp, $css, $fckpath, $content_path, $upload_path, $co_author_folder, $commModerationHint;
	
	if(isset($co_author_folder))
	{
		$content_path = $pth['folder']['base'] . $co_author_folder . $plugin_cf['comments']['content_path'];
	}
	else
	{
		$content_path = './' . $plugin_cf['comments']['content_path'];
	}
	
	$upload_path=$content_path.'upload/';
	
	$reload = md5(uniqid('reload'));
	$title=''; 
	$user=''; 
	$email=''; 
	$homepage=''; 
	$blog_text=''; 
	
	
	if ($plugin_cf['comments']['comments_allow_global'] == 'true')
	{
		if ($form_failure==1) 
		{
			$title = commentsSafeInput($_POST['title']); 
			$user = commentsSafeInput($_POST['user']); 
			$email = commentsSafeInput($_POST['email']); 
			$homepage = commentsSafeInput($_POST['homepage']); 
			$blog_text = comments_cleantext($_POST['blog_text']); 
			$form_failure = $plugin_tx['comments']['form_failure_text']; 
		}
		elseif ($form_failure==2) 
		{ 
			if($plugin_cf['comments']['comments_moderate'] == 'true')
			{
				$form_failure = '<p>' . $plugin_tx['comments']['form_success_text'] . '</p><p><b>' . $plugin_tx['comments']['form_success_mod'] . '</b></p>';
			}
			else
			{			
				$form_failure = '<p>' . $plugin_tx['comments']['form_success_text'] . '</p>';
			}
		}
	
		$form_failure_color = ($plugin_cf['comments']['form_failure_color']) ?$plugin_cf ['comments']['form_failure_color'] : 'red';
//		$require_title = ($plugin_cf['comments']['require_title']=='true') ? '* ' : '&nbsp;&nbsp;';
		$require_user = ($plugin_cf['comments']['require_user']=='true') ? '* ' : '&nbsp;&nbsp;';
		$require_email = ($plugin_cf['comments']['require_email']=='true') ? '* ' : '&nbsp;&nbsp;';
		$picture_upload = ($plugin_cf['comments']['image_allow_upload']=='true') ? ' 
<div class="comments_form_input" id="comments_form_input_pic_upload">' . $plugin_tx['comments']['form_label_image_upload'] . '
<br>
jpg - jpeg - gif - png &nbsp; (max. ' . $plugin_cf['comments']['image_max_size']/1000000 . ' MByte)
<br>
<input name="pic_upload" type="file">
</div>' : '' ;

		if($plugin_cf['comments']['use_captcha'] == 'true')
		{
			$use_captcha = ' ' . $plugin_tx['comments']['form_label_captcha'].'<sup>*</sup><br><div style="margin: 0;"><img src="' . $plugin_pth . '/captcha.php" class="commentsCcaptcha" title="Captcha" alt="Captcha">';

			if($plugin_cf['comments']['use_graphic_captcha'] == 'true')
			{
				$use_captcha.= '<input name="comments" type="submit" class="commentsCaptchaReload" value="&nbsp;">' . "\n\n";
			}

			$use_captcha.= '<br>
<input class="comments_input_field" name="captcha" type="text" maxlength="6" style="clear: both; float: left; width: 6em; font-family: verdana, sans-serif; font-size: 114%; margin: 5px 0;">
</div>
';
		}
		else
		{
			$use_captcha = '';
		}
		


		// Moderation - GE 12/2010

		$show_homepage = ($plugin_cf['comments']['show_homepage_adress']=='true') ? ' 
<div class="comments_form_input">' . $plugin_tx['comments']['form_label_homepage'] . '<br>
<input class="comments_input_field" name="homepage" type="text" size="40" value="'.$homepage.'">
</div>
' : '<input name="homepage" type="hidden" value="">
';

		$foot = '

<div id="comments_sent" class="comments_form">
<div class="comments_form_in">

<form action="#comments_form_input_blog_text" name="comments_form" method="post" enctype="multipart/form-data">
<h4>'.$plugin_tx['comments']['form_heading'].'</h4>';

		if(isset($_SESSION['mapl_userdata' . $sn]))
		{
			$foot.= '
<div class="comments_form_hint" style="display: none;">'.$plugin_tx['comments']['form_hint'].'</div>';

			if(isset($_GET['commentsModHint']))
			{
				$foot.= $commModerationHint;
			}

			$foot.= '<div id="comments_form_hint_last_div"></div>

<div class="comments_form_input" id="comments_form_input_user" style="display: none;">' . $plugin_tx['comments']['form_label_user'] . $require_user . '
<br>
<input class="comments_input_field" name="user" type="text" size="40" value="'.$_SESSION['mapl_name_user' . $sn].'">
</div>

<div class="comments_form_input" id="comments_form_input_email" style="display: none;">' . $plugin_tx['comments']['form_label_email'].$require_email . '
<br>
<input class="comments_input_field" name="email" type="text" size="40" value="'.$_SESSION['mapl_email_user' . $sn].'">
</div>
';
		}
		else
		{
			$foot.= '<div class="comments_form_hint">' . $plugin_tx['comments']['form_hint'] . '</div>';
			
			if(isset($_GET['commentsModHint']))
			{
				$foot.= $commModerationHint;
			}

			$foot.= '<div id="comments_form_hint_last_div"></div>
<div class="comments_form_input" id="comments_form_input_user">
<b>' . $plugin_tx['comments']['form_label_user'] . '</b>' . $require_user . '<br>
<input class="comments_input_field" name="user" type="text" size="40" value="'.$user.'">
</div>

<div class="comments_form_input" id="comments_form_input_email">
<b>' .$plugin_tx['comments']['form_label_email'] . '</b>' . $require_email . '<br>
<input class="comments_input_field" name="email" type="text" size="40" value="'.$email.'">
</div>
';
		}
		
		$foot.= $show_homepage . '
		' . $picture_upload . '
		<div id="comments_form_input_blog_text">' . "\n" 
		. '<b>' . $plugin_tx['comments']['form_label_blog_text'].'</b>&nbsp;*<br>' . "\n";
	
		if ($plugin_cf['comments']['image_allow_upload'] == 'true')
		{
			$foot.= $plugin_tx['comments']['form_label_blog_text2'] . '<br>' . "\n";
		}

		// hides textarea if javascript is disabled in the browser of the user - GE 2010-11-15
		$foot.= '
<script>
/* <![CDATA[ */
document.write(' . "'" . '<textarea id="comments_form" class="comments_form" name="blog_text" cols="50" rows="10">' . $blog_text . '<\/textarea>' . "'" . ');
/* ]]> */
</script>
<noscript>
<div class="comments_nojs">'.$plugin_tx['comments']['form_nojs'].'</div>
</noscript>

</div>
<div style="color:'.$form_failure_color.';" class="comments_form_failure_description">'
.$form_failure.'&nbsp;
</div><div class="comments_form_captcha">
'.$use_captcha.'
<input name="reload" type="hidden" value="'.$reload.'">
</div>
<div style="clear: both;"></div>';

if($plugin_cf['comments']['comments_moderate'] == 'true') $foot.= '<div><b>' . $plugin_tx['comments']['form_success_mod'] . '</b></div>';

$foot.= '<div id="comments_form_submit">
<input name="comments" type="submit" class="commentsButtonLeft" value="'.$plugin_tx['comments']['form_label_submit_button'].'">
</div>
</form>

<div style="clear: both;"></div>';


// TinyMCE Integration - GE 2011-11

global $pth, $cf, $sl, $co_author_folder;
		$foot.='
<script src="'.$plugin_pth.'/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>

<script>
tinyMCE.init({
theme : "advanced",';

		if($cf['xhtml']['endtags'] != "true")
		{
			$foot.='element_format : "html",';
		}

		$foot.='
mode : "exact",';

		if(file_exists($pth['folder']['plugins'] . 'comments/tinymce/jscripts/tiny_mce/langs/' . $sl . '.js'))
		{
			$foot.='
language: "' . $sl . '",';
		}
		else
		{
			$foot.='
language: "en",';
		}

		$foot.='
elements : "comments_form",
theme_advanced_buttons1 : "blockquote,separator,bold,italic,underline,removeformat,separator,undo,redo,separator,emotions",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
content_css : "' . $pth['file']['stylesheet'] . '",
plugins : "emotions",
theme_advanced_toolbar_location : "' . $plugin_cf['comments']['editor_toolbar'] . '",
height : "' . $plugin_cf['comments']['editor_height'] . '",
width : "' . $plugin_cf['comments']['editor_width'] . '",
inline_styles : false,
convert_urls : false,
relative_urls : false,
remove_script_host : false,
formats : {underline : {inline : "u", exact : true}}
});
</script>
';

// END Editor Integration - GE 2010-11

	}
	else
	{
		$foot='<p class="comments_blog_closed">'.$plugin_tx['comments']['form_blog_closed_global'].'</p>';
	}

	if ($plugin_cf['comments']['comments_allow_global'] == 'true')
	{
		$foot.= '
		</div>
		</div>';
	}
	
	$foot.= '
<div style="clear: both;"></div>'."\n";
	
return $foot;
}

if(isset($_POST['commentsSortDirection'])) header('Location: #commentsEditAnchor');

//### END: comments_foot  #################################################################/
?>