Файл: hostbiter.ru/Modules/explode/view/editor2.php
Строк: 149
<?
require ($_SERVER['DOCUMENT_ROOT'].'/Core/core.php');
require ($_SERVER['DOCUMENT_ROOT'].'/Core/fmhead.php');
if(!empty($_GET['dir']) AND $_GET['dir'] != encode('www')){
$dir = htmlspecialchars(trim($_GET['dir']));
}else{
$dir = encode('www');
}
$fileinfo = pathinfo(decode($dir));
$connect_ftp = ftp_connect($config['FTPHost'],21,300);
$ftp = $db->prepare("SELECT * FROM `ftp_users` WHERE `user` = ? LIMIT 1");
$ftp->execute([$user['id']]);
$ftp = $ftp->fetch();
ftp_login($connect_ftp,$ftp['login'],$ftp['password']);
$tmp_name = 'tmp_'.$fileinfo['basename'];
$dirname_tmp = $_SERVER['DOCUMENT_ROOT'].'/tmp_ftp/'.$tmp_name;
ftp_get($connect_ftp,$dirname_tmp,'/'.decode($dir),FTP_ASCII);
$text_file = file_get_contents($dirname_tmp);
$lines = explode("n",htmlspecialchars(trim($text_file)));
switch($_GET['case'])
{
default:
if(count($lines) == 0)
{
echo '<div class="lnk">Файл пуст</div>';
}
else
{
for($i=0;$i<count($lines);$i++)
{
$str = $i+1;
echo '<b>'.$str.'<b> <a href="/explode/view/edit2.php?dir='.$dir.'&case=edit&str='.$i.'">'.$lines[$i].'</a> <a href="/explode/view/edit2.php?dir='.$dir.'&case=new&str='.$i.'"><font color="red"><b>|</b></font></a> <a href="/explode/view/edit2.php? dir='.$dir.'&case=del&str='.$i.'"><font color="red"><b>Х</b></font></a><br/>';
}
}
break;
case 'edit':
$str = abs(intval($_GET['str']));
if(isset($_GET['edit']))
{
$string = trim($_POST['string']);
for($j=0;$j<$str;$j++)
{
$newfile[] = htmlspecialchars_decode($lines[$j]);
}
$newfile[$str] = $string;
for($k=count($newfile);$k<count($lines);$k++)
{
$newfile[] = htmlspecialchars_decode($lines[$k]);
}
$newstring = implode("n",$newfile);
file_put_contents($dirname_tmp,$newstring);
ftp_chdir($connect_ftp,'/'.dirname(decode($dir)));
ftp_put($connect_ftp,$fileinfo['basename'],$dirname_tmp,FTP_ASCII);
ftp_close($connect_ftp);
unlink($dirname_tmp);
$_SESSION['message'] = 'Строка изменена!';
header("Location: /explode/view/edit2.php?dir=".$dir);
exit;
}
?>
<form action="/explode/view/edit2.php?dir=<?=$dir?>&case=edit&str=<?=$str?>&edit" method="post">
Строка #<?=$str?><br/>
<textarea name="string">
<?=$lines[$str]?>
</textarea><br/>
<input type="submit" name="edit" value="Редактировать">
</form>
<?
break;
case 'del':
$array = explode("n",$text_file);
$str = abs(intval($_GET['str']));
unset($array[$str]);
$arr = array_values($array);
$newfile = implode("n",$arr);
file_put_contents($dirname_tmp,$newfile);
ftp_chdir($connect_ftp,'/'.dirname(decode($dir)));
ftp_put($connect_ftp,$fileinfo['basename'],$dirname_tmp,FTP_ASCII);
ftp_close($connect_ftp);
unlink($dirname_tmp);
$_SESSION['message'] = 'Строка удалена!';
header("Location: /explode/view/edit2.php?dir=".$dir);
exit;
break;
case 'new':
$str = abs(intval($_GET['str']));
if(isset($_GET['new']))
{
$string = trim($_POST['string']);
for($j=0;$j<=$str;$j++)
{
$newfile[] = htmlspecialchars_decode($lines[$j]);
}
$newfile[] = $string;
for($k=count($newfile);$k<count($lines);$k++)
{
$newfile[] = htmlspecialchars_decode($lines[$k]);
}
$newstring = implode("n",$newfile);
file_put_contents($dirname_tmp,$newstring);
ftp_chdir($connect_ftp,'/'.dirname(decode($dir)));
ftp_put($connect_ftp,$fileinfo['basename'],$dirname_tmp,FTP_ASCII);
ftp_close($connect_ftp);
unlink($dirname_tmp);
$_SESSION['message'] = 'Строка добавлена!';
header("Location: /explode/view/edit2.php?dir=".$dir);
exit;
}
?>
<form action="/explode/view/edit2.php?dir=<?=$dir?>&case=new&str=<?=$str?>&new" method="post">
Новая строка #<?=$str?>:<br/>
<textarea name="string"></textarea><br/>
<input type="submit" name="new" value="Вставить">
</form>
<?
break;
}
require ($_SERVER['DOCUMENT_ROOT'].'/Core/fmfoot.php');
?>