From 50c68bbab3958fcf526a83f3a638a64f3f46409f Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 2 Nov 2015 08:13:15 +0000 Subject: [PATCH] added charset detection using svn:mime-type to code_file and code_blame. need to add the same code to more views --- .../src/codepot/models/subversionmodel.php | 4 +++ codepot/src/codepot/views/code_blame.php | 29 +++++++++++++++++-- codepot/src/codepot/views/code_file.php | 27 ++++++++++++++--- codepot/src/codepot/views/file_show.php | 8 ++--- codepot/src/css/file.css | 6 ++++ 5 files changed, 63 insertions(+), 11 deletions(-) diff --git a/codepot/src/codepot/models/subversionmodel.php b/codepot/src/codepot/models/subversionmodel.php index a2ada4e4..a29749b2 100644 --- a/codepot/src/codepot/models/subversionmodel.php +++ b/codepot/src/codepot/models/subversionmodel.php @@ -174,6 +174,10 @@ class SubversionModel extends Model $str = @svn_blame ($workurl, $rev); 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, $fileinfo['created_rev'], $fileinfo['created_rev'], diff --git a/codepot/src/codepot/views/code_blame.php b/codepot/src/codepot/views/code_blame.php index d9e60535..86807bf3 100644 --- a/codepot/src/codepot/views/code_blame.php +++ b/codepot/src/codepot/views/code_blame.php @@ -298,17 +298,40 @@ if ($login['settings'] != NULL && printf ('', $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++) { $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 { - print htmlspecialchars ($line['line']); + // ignore iconv error + print htmlspecialchars (@iconv($charset, 'UTF-8//IGNORE', $line['line'])); } print "\n"; } diff --git a/codepot/src/codepot/views/code_file.php b/codepot/src/codepot/views/code_file.php index cb10e934..29208a44 100644 --- a/codepot/src/codepot/views/code_file.php +++ b/codepot/src/codepot/views/code_file.php @@ -301,15 +301,34 @@ if ($login['settings'] != NULL && 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']); } - + else + { + // ignore iconv error + print htmlspecialchars(@iconv ($charset, 'UTF-8//IGNORE', $file['content'])); + } } ?> diff --git a/codepot/src/codepot/views/file_show.php b/codepot/src/codepot/views/file_show.php index 8c253138..459f3e33 100644 --- a/codepot/src/codepot/views/file_show.php +++ b/codepot/src/codepot/views/file_show.php @@ -527,11 +527,11 @@ $this->load->view ( $f = $file->file_list[$i]; $xname = $this->converter->AsciiToHex($f->filename); - print ''; - print anchor ("file/get/{$project->id}/{$xname}", htmlspecialchars($f->filename)); - print ''; + print ''; + print anchor ("file/get/{$project->id}/{$xname}", ' ' . htmlspecialchars($f->filename)); + print ''; print htmlspecialchars($f->description); - print ''; + print ''; print " {$f->md5sum}"; print ''; } diff --git a/codepot/src/css/file.css b/codepot/src/css/file.css index 296f2d17..8b651141 100644 --- a/codepot/src/css/file.css +++ b/codepot/src/css/file.css @@ -48,6 +48,12 @@ text-transform: uppercase; } +#file_show_mainarea_files td { + padding-left: 0.5em; + padding-right: 0.5em; + line-height: 1.5em; +} + #file_edit_mainarea_description { width: 100%; }