chat // [21:04] chat // }}} // // 수정 내역: // 0.2 2026-07-30 hyacinth: 줄 단위 루프와 규칙 테이블 재생성을 제거. // - patterns/replacements 두 배열을 pattern => replacement 맵 하나로 // 합쳐 _irccolor_rules()로 옮기고 static에 담아 요청당 한 번만 만든다. // - $value[0]/$value[1] 접근을 substr()로, $out/$line 미초기화 사용을 // 정리해 undefined offset/variable 경고를 없앤다. // 0.1 2015-02-26 hyacinth: 최초 작성. // // $Id: irccolor.php,v 0.2 2026/07/30 13:51:22 hyacinth Exp $ // IRC control codes: \x02 bold, \x03 color, \x08 backspace (HexChat wraps // log nicks in them), \x0f reset. Rules are applied in order, so the // client specific formats come first and the bare color codes last. function _irccolor_rules() { $B = "\x02"; $C = "\x03"; $H = "\x08"; $O = "\x0f"; return array( "/(\[\d\d:\d\d\]) (\*.*)/" => "$1 $2", // timestamped action // HexChat "/{$C}20{$H}<{$H}(.*){$H}>{$H}{$O}{$C}30/" => "<$1>", // Me "/{$C}18{$H}<{$H}(.*){$C}18{$H}>{$H}{$O}/" => "<$1>", // Oper "/{$C}23(.*){$C}23(.*)/" => "$1$2", // Joined "/{$C}24(.*)/" => "$1$2 ", // Quit "/{$C}22(.[^ {$O}]*){$O}? {$C}26(.[^ {$O}]*){$O}? (.*){$C}18(.*){$O}?/" => "$1 $2 $3$4 ", // Mode Changed "/(\d){$B}{$B}/" => "$1", "/{$C}18(.[^{$O}]*){$O}/" => "$1", "/{$C}19(.[^{$O}]*){$O}/" => "$1", "/{$C}20(.[^{$O}]*){$O}/" => "$1", "/{$C}22(.[^{$O}]*){$O}/" => "$1", "/{$C}26(.[^{$O}]*){$O}/" => "$1", // mIRC "/<(@.[^>]*)>/" => "<$1>", // op "/<(\+.[^>]*)>/" => "<$1>", // voiced "/{$C}02(.[^{$O}]*){$O}/" => "$1", "/{$C}05(.[^{$O}]*){$O}/" => "$1", "/{$C}04(.[^{$O}]*){$O}/" => "$1", "/{$O}(.[^{$O}]*){$O}/" => "$1", "/{$B}(.[^{$B}]*){$B}/" => "$1", "/{$C}10(.*)/" => "$1 ", "/{$C}11(.*)/" => "$1 ", "/{$C}12(.*)/" => "$1 ", "/{$C}13(.*)/" => "$1 ", "/{$C}14(.*)/" => "$1 ", "/{$C}15(.*)/" => "$1 ", "/{$C}0?1([^\d].*)/" => "$1 ", "/{$C}0?2(.*)/" => "$1 ", "/{$C}0?3(.*)/" => "$1 ", "/{$C}0?4(.*)/" => "$1 ", "/{$C}0?5(.*)/" => "$1 ", "/{$C}0?6(.*)/" => "$1 ", "/{$C}0?7(.*)/" => "$1 ", "/{$C}0?8(.*)/" => "$1 ", "/{$C}0?9(.*)/" => "$1 ", // strip whatever control codes are left over "/{$C}\d?\d/" => "", "/{$C}{$B}|{$O}|{$C}/" => "", ); } function processor_irccolor($formatter, $value = '', $options = array()) { static $patterns = null; static $replacements = null; if ($patterns === null) { $rules = _irccolor_rules(); $patterns = array_keys($rules); $replacements = array_values($rules); } // drop the leading "#!irccolor ..." processor line if (substr($value, 0, 2) == '#!') { $tmp = explode("\n", $value, 2); $value = isset($tmp[1]) ? $tmp[1] : ''; } $lines = explode("\n", $value); // drop the literal "0?" that follows a color code in some logs $lines = str_replace("\x03".'0?', "\x03", $lines); $lines = preg_replace($patterns, $replacements, $lines); return implode('
', $lines).'
'; } // vim:et:sts=4:sw=4: ?>