Вход Регистрация
Файл: hostbiter.ru/Modules/explode/view/charset.php
Строк: 143
<?
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');
}
function 
detectcharset ($content){
$charsets = array ( 'w' => 0'k' => 0'i' => 0'm' => 0'a' => 0'c' => 0'u' => );


    
// Windows-1251
$search_l_w "~([270])|([340-347])|([350-357])|([360-367])|([370-377])~s";
$search_U_w "~([250])|([300-307])|([310-317])|([320-327])|([330-337])~s";

    
// Koi8-r
$search_l_k "~([243])|([300-307])|([310-317])|([320-327])|([330-337])~s";
$search_U_k "~([263])|([340-347])|([350-357])|([360-367])|([370-377])~s";

    
// Iso-8859-5
$search_l_i "~([361])|([320-327])|([330-337])|([340-347])|([350-357])~s";
$search_U_i "~([241])|([260-267])|([270-277])|([300-307])|([310-317])~s";

    
// X-mac-cyrillic
$search_l_m "~([336])|([340-347])|([350-357])|([360-367])|([370-370])|([337])~s";
$search_U_m "~([335])|([200-207])|([210-217])|([220-227])|([230-237])~s";

    
// Ibm866
$search_l_a "~([361])|([240-247])|([250-257])|([340-347])|([350-357])~s";
$search_U_a "~([360])|([200-207])|([210-217])|([220-227])|([230-237])~s";

    
// Ibm855
$search_l_c "~([204])|([234])|([236])|([240])|([242])|([244])|([246])|([250])|".
"([252])|([254])|([265])|([267])|([275])|([306])|([320])|([322])|".
"([324])|([326])|([330])|([340])|([341])|([343])|([345])|([347])|".
"([351])|([353])|([355])|([361])|([363])|([365])|([367])|([371])|([373])~s";
$search_U_c "~([205])|([235])|([237])|([241])|([243])|([245])|([247])|([251])|".
"([253])|([255])|([266])|([270])|([276])|([307])|([321])|([323])|".
"([325])|([327])|([335])|([336])|([342])|([344])|([346])|([350])|".
"([352])|([354])|([356])|([362])|([364])|([366])|([370])|([372])|([374])~s";

    
// Utf-8
$search_l_u "~([xD1x91])|([xD1x80-x8F])|([xD0xB0-xBF])~s";
$search_U_u "~([xD0x81])|([xD0x90-x9F])|([xD0xA0-xAF])~s";

if ( 
preg_match_all ($search_l_w$content$arrPREG_PATTERN_ORDER)) { $charsets['w'] += count ($arr[0]) * 3; }
if ( 
preg_match_all ($search_U_w$content$arrPREG_PATTERN_ORDER)){ $charsets['w'] += count ($arr[0]); }

if ( 
preg_match_all ($search_l_k$content$arrPREG_PATTERN_ORDER)) { $charsets['k'] += count ($arr[0]) * 3; }
if ( 
preg_match_all ($search_U_k$content$arrPREG_PATTERN_ORDER)){ $charsets['k'] += count ($arr[0]); }

if ( 
preg_match_all ($search_l_i$content$arrPREG_PATTERN_ORDER)) { $charsets['i'] += count ($arr[0]) * 3; }
if ( 
preg_match_all ($search_U_i$content$arrPREG_PATTERN_ORDER)){ $charsets['i'] += count ($arr[0]); }

if ( 
preg_match_all ($search_l_m$content$arrPREG_PATTERN_ORDER)) { $charsets['m'] += count ($arr[0]) * 3; }
if ( 
preg_match_all ($search_U_m$content$arrPREG_PATTERN_ORDER)){ $charsets['m'] += count ($arr[0]); }

if ( 
preg_match_all ($search_l_a$content$arrPREG_PATTERN_ORDER)) { $charsets['a'] += count ($arr[0]) * 3; }
if ( 
preg_match_all ($search_U_a$content$arrPREG_PATTERN_ORDER)){ $charsets['a'] += count ($arr[0]); }

if ( 
preg_match_all ($search_l_c$content$arrPREG_PATTERN_ORDER)) { $charsets['c'] += count ($arr[0]) * 3; }
if ( 
preg_match_all ($search_U_c$content$arrPREG_PATTERN_ORDER)){ $charsets['c'] += count ($arr[0]); }

if ( 
preg_match_all ($search_l_u$content$arrPREG_PATTERN_ORDER)) { $charsets['u'] += count ($arr[0]) * 3; }
if ( 
preg_match_all ($search_U_u$content$arrPREG_PATTERN_ORDER)){ $charsets['u'] += count ($arr[0]); }

arsort ($charsets);
$key key($charsets);
if ( 
max ($charsets)==) return 'unknown';
elseif ( 
$key == 'w' ) return 'windows-1251';
elseif ( 
$key == 'k' ) return 'koi8-r'
elseif ( 
$key == 'i' ) return 'iso-8859-1'
elseif ( 
$key == 'a' ) return 'cp866';
elseif ( 
$key == 'u' ) return 'utf8'
}
$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);
$used_charset detectcharset($text_file);
if(isset(
$_GET['iconv']))
{
    
$new_charset htmlspecialchars(trim($_POST['new']));
    
$encoded_file =  iconv(strtoupper($used_charset),strtoupper($new_charset).'//TRANSLIT',$text_file);
    
file_put_contents($dirname_tmp,$encoded_file);
    if(
$_POST['type'] == 1)
    {
        
ftp_chdir($connect_ftp,'/'.dirname(decode($dir)));
        
ftp_put($connect_ftp,$fileinfo['basename'],$dirname_tmp,FTP_ASCII);
        
ftp_close($connect_ftp);
    }
    else
    {
        
ftp_chdir($connect_ftp,'/'.dirname(decode($dir)));
        
ftp_put($connect_ftp,$fileinfo['basename'].'.ftp',$dirname_tmp,FTP_ASCII);   
    }
    
unlink($dirname_tmp);
    
$_SESSION['message'] = 'Файл успешно перекодирован!';
    
header("Location: /explode?dir=".encode($fileinfo['dirname'])."");
    exit;
}
?>
<form action="/explode/view/charset.php?dir=<?=$dir?>&iconv" method="post">
    Кодировка оригинала:<br/>
    <select name="used" disabled>
        <option value="<?=$used_charset?>"><?=strtolower($used_charset)?></option>
    </select><br/>
    Новая кодировка:<br/>
    <select name="new">
        <option value="utf-8">utf-8</option>
        <option value="windows-1251">windows-1251</option>
        <option value="koi8-r">koi8-r</option>
        <option value="cp866">cp866</option>
        <option value="iso-8859-1">iso-8859-1</option>
    </select><br/>
    Тип перекодировки:<br/>
    <input type="radio" name="type" value="1">Перезаписать файл<br/>
    <input type="radio" name="type" value="2">Сохранить в новый файл.ftp<br/>
    <input type="submit" name="iconv" value="Перекодировать">
</form><br/>
<?
require ($_SERVER['DOCUMENT_ROOT'].'/Core/fmfoot.php');
?>
Онлайн: 1
Реклама