added charset detection using svn:mime-type to code_file and code_blame. need to add the same code to more views

This commit is contained in:
hyung-hwan 2015-11-02 08:13:15 +00:00
parent 7d5e336664
commit 50c68bbab3
5 changed files with 63 additions and 11 deletions

View File

@ -174,6 +174,10 @@ class SubversionModel extends Model
$str = @svn_blame ($workurl, $rev); $str = @svn_blame ($workurl, $rev);
if ($str === FALSE) return FALSE; if ($str === FALSE) return FALSE;
$prop = @svn_proplist ($workurl, FALSE, $rev);
if ($prop === FALSE) return FALSE;
$fileinfo['properties'] = array_key_exists($orgurl, $prop)? $prop[$orgurl]: NULL;
$log = @svn_log ($workurl, $log = @svn_log ($workurl,
$fileinfo['created_rev'], $fileinfo['created_rev'],
$fileinfo['created_rev'], $fileinfo['created_rev'],

View File

@ -298,17 +298,40 @@ if ($login['settings'] != NULL &&
printf ('<code class="line-numbered-code prettyprint %s %s" id="code_blame_mainarea_result_code">', $prettyprint_linenums, $prettyprint_lang); printf ('<code class="line-numbered-code prettyprint %s %s" id="code_blame_mainarea_result_code">', $prettyprint_linenums, $prettyprint_lang);
$charset = '';
if (array_key_exists('properties', $file) && count($file['properties']) > 0)
{
$p = &$file['properties'];
if (array_key_exists('svn:mime-type', $p))
{
if (@preg_match('|\s*[\w/+]+;\s*charset=(\S+)|i', $p['svn:mime-type'], $matches))
{
$charset = $matches[1];
}
}
}
if ($charset == '')
{
if (property_exists($project, 'codecharset') && strlen($project->codecharset))
$charset = $project->codecharset;
}
for ($i = 0; $i < $len; $i++) for ($i = 0; $i < $len; $i++)
{ {
$line = &$content[$i]; $line = &$content[$i];
if (property_exists($project, 'codecharset') && strlen($project->codecharset)) if ($charset == '')
{ {
print htmlspecialchars (iconv($project->codecharset, 'UTF-8//IGNORE', $line['line'])); print htmlspecialchars ($line['line']);
} }
else else
{ {
print htmlspecialchars ($line['line']); // ignore iconv error
print htmlspecialchars (@iconv($charset, 'UTF-8//IGNORE', $line['line']));
} }
print "\n"; print "\n";
} }

View File

@ -301,15 +301,34 @@ if ($login['settings'] != NULL &&
if (!$is_image_stream) if (!$is_image_stream)
{ {
if (property_exists($project, 'codecharset') && strlen($project->codecharset)) $charset = '';
if (array_key_exists('properties', $file) && count($file['properties']) > 0)
{ {
print htmlspecialchars(iconv ($project->codecharset, 'UTF-8//IGNORE', $file['content'])); $p = &$file['properties'];
if (array_key_exists('svn:mime-type', $p))
{
if (@preg_match('|\s*[\w/+]+;\s*charset=(\S+)|i', $p['svn:mime-type'], $matches))
{
$charset = $matches[1];
}
}
} }
else
if ($charset == '')
{
if (property_exists($project, 'codecharset') && strlen($project->codecharset))
$charset = $project->codecharset;
}
if ($charset == '')
{ {
print htmlspecialchars($file['content']); print htmlspecialchars($file['content']);
} }
else
{
// ignore iconv error
print htmlspecialchars(@iconv ($charset, 'UTF-8//IGNORE', $file['content']));
}
} }
?> ?>
</pre> </pre>

View File

@ -527,11 +527,11 @@ $this->load->view (
$f = $file->file_list[$i]; $f = $file->file_list[$i];
$xname = $this->converter->AsciiToHex($f->filename); $xname = $this->converter->AsciiToHex($f->filename);
print '<tr><td>'; print '<tr><td class="file-name-td">';
print anchor ("file/get/{$project->id}/{$xname}", htmlspecialchars($f->filename)); print anchor ("file/get/{$project->id}/{$xname}", '<i class="fa fa-download" /> ' . htmlspecialchars($f->filename));
print '</td><td>'; print '</td><td class="file-description-td">';
print htmlspecialchars($f->description); print htmlspecialchars($f->description);
print '</td><td>'; print '</td><td class="file-md5sum-td">';
print " <tt>{$f->md5sum}</tt>"; print " <tt>{$f->md5sum}</tt>";
print '</td></tr>'; print '</td></tr>';
} }

View File

@ -48,6 +48,12 @@
text-transform: uppercase; text-transform: uppercase;
} }
#file_show_mainarea_files td {
padding-left: 0.5em;
padding-right: 0.5em;
line-height: 1.5em;
}
#file_edit_mainarea_description { #file_edit_mainarea_description {
width: 100%; width: 100%;
} }