Cytat
Kamelon: Cos chyba wyparowal poprzedni kod (chyba wiesz o co mi chozi

)

Wiem, zauważyłem wczoraj mały błąd i musiałem go poprawić...
No więc tak....
To fakt, że
php ma wbudowaną funkcję kolorowania składni, ale jest ona szczerze mówiąc jeszcze niedopracowana... Trzeba pod nią
dokładnie przygotować grunt i po wykorzystaniu poprawić wiele błędów.
Np. Funckje
highlight_*() nie biorą pod uwagę znaków htmlspecialchars()...
Tzn. traktują osobno
& i
nbsp; oraz mnoza nieskonczenie spacje, przy wykorzystaniu TAB. To prowadzi np. właśnie do rozciągania tabel.
Długo się zastanawiałem jak pozamieniać błędy za jednym zamachem, ale niestety nie ma takiej możliwosci. Trzeba stosować zamianę znaków po skończeniu poprzedniej...
Zawijanie wierszy jest dosyć proste. Zastosowałem zawijanie tylko w przypadku dlugiego wiersza, który nie zawiera żadnej spacji. Reszta jest sterowana przerwami między wyrażeniami lub po przecinkach.
Już wczoraj podałem kod tej funkcji, ale jak zauważył
Seth usunąłem posta. Dlaczego?
Przeglądnijcie kod tej funkcji, a zauważycie, że w funkcjach
str_replace() jest tylko "&".
Oczywiście powinny być
& nbsp; (bez spacji) i
& amp; (bez spacji).
Myślałem, że to wina mojej funkcji, ale nie :wink:
phpBB obcina takie znaki podczas dodawania posta, co oczywiście jest następną rzeczą do poprawy...
Wogóle to
phpBB zawiera kupę błędów, które oczywiście mam zamiar poprawić.
Nawet nie wyobrażacie sobie ile kopii zmiennych i tablic tworzy silnik forum podczas generowania stron... Dlatego m.in. dodałem referencje w argumentach funkcji...
To spłodziłem:
[php:1:9dd391a294]<?php
/**
* Does second-pass bbencoding of the php tags. This includes
* running htmlspecialchars() over the text contained between
* any pair of php tags that are at the first level of
* nesting. Tags at the first level of nesting are indicated
* by this format: [php:1:$uid] ... [/php:1:$uid]
* Other tags are in this format: [php:$uid] ... [/php:$uid]
*
* Original code/function by phpBB Group
* Modified by KaMeLeOn <kameleon@php.pl>
*/
function bbencode_second_pass_php($text, &$uid, &$bbcode_tpl)
{
global $lang;
$php_start_html = $bbcode_tpl['php_open'];
$php_start_html = str_replace('<td class="code">', '<td class="code" style="font-size:12px;">', $php_start_html);
$php_end_html = $bbcode_tpl['php_close'];
$match_count = preg_match_all("#[php:1:$uid](.*?)[/php:1:$uid]#si", $text, $matches);
for( $i=0 ; $i<$match_count ; $i++ )
{
$before_replace = $matches[1][$i];
$after_replace = trim($matches[1][$i]);
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
$after_replace = strtr($after_replace, $trans_tbl);
if( (substr($after_replace, 0, 2) != '<?') && !(strpos($after_replace, '<?')) )
{
$after_replace = "<?phpn" . $after_replace;
}
if( (substr($after_replace, -2, 2) != '?>') && !(strpos($after_replace, '?>')) )
{
$after_replace = $after_replace . "n?>";
}
$after_replace = str_replace(' ', ' &', $after_replace);
$after_replace = str_replace("t", '&&', $after_replace);
$after_replace = str_replace(',', ', ', $after_replace);
$after_replace = str_replace(', ', ', ', $after_replace);
$lines = explode("n", $after_replace);
for( $q=0 ; $q < count($lines) ; $q++ )
{
$lines[$q] = trim($lines[$q]);
if( (strlen($lines[$q]) > 80) && !strstr($lines[$q], '&') && !strstr($lines[$q], ' ') )
{
$lines[$q] = wordwrap($lines[$q], 80, "n", 1);
}
$lines[$q] = $lines[$q] . "rn";
}
$after_replace = trim(implode('', $lines));
// highlight string
$after_replace = highlight_string($after_replace, TRUE);
$replacement = $php_start_html;
$replacement .= $after_replace;
$replacement .= $php_end_html;
$str_to_match = "[php:1:$uid]" . $before_replace . "[/php:1:$uid]";
$text = str_replace($str_to_match, $replacement, $text);
}
$text = str_replace("[php:$uid]", $php_start_html, $text);
$text = str_replace("[/php:$uid]", $php_end_html, $text);
$text = str_replace('&', '&', $text);
$text = str_replace('&</font><font color="#0000CC">nbsp</font><font color="#006600">;', '&', $text);
$text = str_replace('&</font><font color="#0000BB">nbsp</font><font color="#007700">;', '&', $text);
$text = str_replace(',&', ', ', $text);
$text = str_replace('&&', ' &', $text);
$text = str_replace($php_start_html."<code><font color="#000000">n", $php_start_html.'<font color="#000000">', $text);
$text = str_replace("</font>n</code>".$php_end_html, "</font>".$php_end_html, $text);
$font[1] = "#<font color="(.*?)">#si";
$font_replace[1] = "<font color="1"><code>";
$font[2] = "#</font>#si";
$font_replace[2] = "</code></font>";
$text = preg_replace($font, $font_replace, $text);
$text = str_replace('&</code>', ' </code>', $text);
$text = str_replace(' </code>', '& </code>', $text);
return $text;
} // bbencode_second_pass_php()
?>[/php:1:9dd391a294]