Merge branch 'master' of https://github.com/easysoft/zentaopms
This commit is contained in:
@@ -75,4 +75,40 @@ class helper extends baseHelper
|
||||
$replacements = array("\\\\", "\\/", "\\\"", "\'", "\\n", "\\r", "\\t", "\\f", "\\b", "\\u");
|
||||
return str_replace($escapers, $replacements, $json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert encoding.
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $fromEncoding
|
||||
* @param string $toEncoding
|
||||
* @static
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
static public function convertEncoding($string, $fromEncoding, $toEncoding = 'utf-8')
|
||||
{
|
||||
$toEncoding = str_replace('utf8', 'utf-8', $toEncoding);
|
||||
if($fromEncoding == $toEncoding) return $string;
|
||||
if(function_exists('mb_convert_encoding'))
|
||||
{
|
||||
/* Remove like utf-8//TRANSLIT. */
|
||||
$position = strpos($toEncoding, '//');
|
||||
if($position !== false) $toEncoding = substr($toEncoding, 0, $position);
|
||||
|
||||
/* Check string encoding. */
|
||||
$encoding = strtolower(mb_detect_encoding($string, array('ASCII','UTF-8','GB2312','GBK','BIG5')));
|
||||
if($encoding == $toEncoding) return $string;
|
||||
return mb_convert_encoding($string, $toEncoding, $fromEncoding);
|
||||
}
|
||||
elseif(function_exists('iconv'))
|
||||
{
|
||||
$convertString = @iconv($fromEncoding, $toEncoding, $string);
|
||||
/* iconv error then return original. */
|
||||
if(!$convertString) return $string;
|
||||
return $convertString;
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-11
@@ -166,17 +166,7 @@ class file extends control
|
||||
$this->view->fields = $this->post->fields;
|
||||
$this->view->rows = $this->post->rows;
|
||||
$output = $this->parse('file', 'export2csv');
|
||||
if( $this->post->encode != "utf-8")
|
||||
{
|
||||
if(function_exists('mb_convert_encoding'))
|
||||
{
|
||||
$output = @mb_convert_encoding($output, $this->post->encode, 'utf-8');
|
||||
}
|
||||
elseif(function_exists('iconv'))
|
||||
{
|
||||
$output = @iconv('utf-8', $this->post->encode . '//TRANSLIT', $output);
|
||||
}
|
||||
}
|
||||
if($this->post->encode != "utf-8") $output = helper::convertEncoding($output, 'utf-8', $this->post->encode . '//TRANSLIT');
|
||||
|
||||
$this->sendDownHeader($this->post->fileName, 'csv', $output);
|
||||
}
|
||||
|
||||
@@ -488,14 +488,7 @@ class fileModel extends model
|
||||
{
|
||||
if($uploadFile['folder']) continue;
|
||||
$fileName = $uploadFile['filename'];
|
||||
if(function_exists('iconv'))
|
||||
{
|
||||
$fileName = iconv('gbk', 'utf-8//TRANSLIT', $fileName);
|
||||
}
|
||||
elseif(function_exists('mb_convert_encoding'))
|
||||
{
|
||||
$fileName = mb_convert_encoding($fileName, 'utf-8', 'gbk');
|
||||
}
|
||||
$fileName = helper::convertEncoding($fileName, 'gbk', 'utf-8//TRANSLIT');
|
||||
if(($pos = strrpos($fileName, '/')) !== false) $fileName = substr($fileName, $pos + 1);
|
||||
|
||||
$file = array();
|
||||
|
||||
@@ -397,7 +397,7 @@ class gitModel extends model
|
||||
foreach($encodings as $encoding)
|
||||
{
|
||||
if($encoding == 'utf-8') continue;
|
||||
$result = @mb_convert_encoding($comment, 'utf-8', $encoding);
|
||||
$result = helper::convertEncoding($comment, $encoding, 'utf-8');
|
||||
if($result) return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1074,18 +1074,7 @@ class testcase extends control
|
||||
{
|
||||
$fc = file_get_contents($fileName);
|
||||
$encode = $this->post->encode != "utf-8" ? $this->post->encode : 'gbk';
|
||||
if(function_exists('mb_convert_encoding'))
|
||||
{
|
||||
$fc = @mb_convert_encoding($fc, 'utf-8', $encode);
|
||||
}
|
||||
elseif(function_exists('iconv'))
|
||||
{
|
||||
$fc = @iconv($encode, 'utf-8', $fc);
|
||||
}
|
||||
else
|
||||
{
|
||||
die(js::alert($this->lang->testcase->noFunction));
|
||||
}
|
||||
$fc = helper::convertEncoding($fc, $encode, 'utf-8');
|
||||
file_put_contents($fileName, $fc);
|
||||
|
||||
$rows = $this->file->parseCSV($fileName);
|
||||
|
||||
Reference in New Issue
Block a user