From cdaec9bc62aff17617a1d0aa994602c47c1bdb3f Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sat, 1 Oct 2022 19:54:19 +0800 Subject: [PATCH] fix nfo display --- include/functions.php | 38 ++++++++++++++++++++++++++++++++++++++ public/details.php | 2 +- public/viewnfo.php | 4 ++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/include/functions.php b/include/functions.php index 11b8e8f0..808e7804 100644 --- a/include/functions.php +++ b/include/functions.php @@ -3998,6 +3998,44 @@ $s = str_replace($table437, $tablehtml, $s); return $s; } +/** + * @param $ibm_437 + * @param $view + * @return array|string|string[] + * @ref https://github.com/HDInnovations/UNIT3D-Community-Edition/blob/master/app/Helpers/Nfo.php + */ +function code_new($ibm_437, $view) +{ + $swedishmagic = false; + if ($view == "magic") { + $swedishmagic = true; + } + $cf = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 8962, 199, 252, 233, 226, 228, 224, 229, 231, 234, 235, 232, 239, 238, 236, 196, 197, 201, 230, 198, 244, 246, 242, 251, 249, 255, 214, 220, 162, 163, 165, 8359, 402, 225, 237, 243, 250, 241, 209, 170, 186, 191, 8976, 172, 189, 188, 161, 171, 187, 9617, 9618, 9619, 9474, 9508, 9569, 9570, 9558, 9557, 9571, 9553, 9559, 9565, 9564, 9563, 9488, 9492, 9524, 9516, 9500, 9472, 9532, 9566, 9567, 9562, 9556, 9577, 9574, 9568, 9552, 9580, 9575, 9576, 9572, 9573, 9561, 9560, 9554, 9555, 9579, 9578, 9496, 9484, 9608, 9604, 9612, 9616, 9600, 945, 223, 915, 960, 931, 963, 181, 964, 934, 920, 937, 948, 8734, 966, 949, 8745, 8801, 177, 8805, 8804, 8992, 8993, 247, 8776, 176, 8729, 183, 8730, 8319, 178, 9632, 160); + $s = ""; + for ($c = 0; $c < strlen($ibm_437); $c++) { // cyctle through the whole file doing a byte at a time. + $byte = $ibm_437[$c]; + $ob = ord($byte); + if ($ob >= 127) { // is it in the normal ascii range + $s .= '&#' . $cf[$ob] . ';'; + } else { + $s .= $byte; + } + } + + if ($swedishmagic) { + $s = str_replace("\345","\206",$s); + $s = str_replace("\344","\204",$s); + $s = str_replace("\366","\224",$s); + $s = preg_replace("/([ -~])\305([ -~])/", "\\1\217\\2", $s); + $s = preg_replace("/([ -~])\304([ -~])/", "\\1\216\\2", $s); + $s = preg_replace("/([ -~])\326([ -~])/", "\\1\231\\2", $s); + $s = str_replace ( "\311", "\220", $s ); // + $s = str_replace ( "\351", "\202", $s ); // + } + + return $s; +} + //Tooltip container for hot movie, classic movie, etc function create_tooltip_container($id_content_arr, $width = 400) diff --git a/public/details.php b/public/details.php index 889ca0f5..33bbeb9f 100644 --- a/public/details.php +++ b/public/details.php @@ -300,7 +300,7 @@ JS; if (user_can('viewnfo') && $CURUSER['shownfo'] != 'no' && $row["nfosz"] > 0){ if (!$nfo = $Cache->get_value('nfo_block_torrent_id_'.$id)){ - $nfo = code($row["nfo"], get_setting('torrent.nfo_view_style_default')); + $nfo = code_new($row["nfo"], get_setting('torrent.nfo_view_style_default')); $Cache->cache_value('nfo_block_torrent_id_'.$id, $nfo, 604800); } tr("\"Show/Hide\" ".$lang_details['text_nfo']."
". $lang_details['text_view_nfo']. "", "
".$nfo."
\n", 1); diff --git a/public/viewnfo.php b/public/viewnfo.php index 9efee758..6d5b7ed6 100644 --- a/public/viewnfo.php +++ b/public/viewnfo.php @@ -28,13 +28,13 @@ if ($view == "latin-1" || $view == "fonthack") { // NOTICE: TBSource specifies Latin-1 encoding in include/bittorrent.php: // stdhead() //$nfo = htmlspecialchars(($a["nfo"])); -$nfo = code($a["nfo"], $view); +$nfo = code_new($a["nfo"], $view); } else { // Convert from ibm-437 to html unicode entities. // take special care of Swedish letters if in magic view. //$nfo = code($a["nfo"], $view == "magic"); -$nfo = code($a["nfo"], $view); +$nfo = code_new($a["nfo"], $view); } stdhead($lang_viewnfo['head_view_nfo']);