function conv_content($content, $html, $filter = true) { global $config, $board; if ($html) { $source = array(); $target = array(); $source[] = "//"; $target[] = ""; if ($html == 2) { // 자동 줄바꿈 $source[] = "/\n/"; $target[] = "<br/>"; } // 테이블 태그의 개수를 세어 테이블이 깨지지 않도록 한다. $table_begin_count = substr_count(strtolower($content), "<table"); $table_end_count = substr_count(strtolower($content), "</table"); for ($i = $table_end_count; $i < $table_begin_count; $i++) { $content .= "</table>"; } $content = preg_replace($source, $target, $content); if ($filter) { $content = html_purifier($content); } } else { // & 처리 : & 등의 코드를 정상 출력함 $content = html_symbol($content); // 공백 처리 //$content = preg_replace("/ /", " ", $content); $content = str_replace(" ", " ", $content); $content = str_replace("\n ", "\n ", $content); $content = get_text($content, 1); $content = url_auto_link($content); } return $content; }
/** * * 문법 분석 * * @param array &$view 그누보드 write_table 의 한 row * @return string HTML */ public function parse(&$view) { $this->init(); foreach($this->plugins as $p) { $p->init(); } $this->view = &$view; $text = $this->_wikiTxt($view['wr_content']); $this->output = array(); // nowiki 와 nowiki_block 저장 $text = preg_replace_callback('/<pre>(.*?)<\/pre>/si',array($this,"_savePre"),$text); $text = preg_replace_callback('/<nowiki>(.*?)<\/nowiki>/si',array($this,"_saveNoWiki"),$text); // block parser 실행 foreach($this->blockParsers as $id => $p) { $this->currentBlockParser = $p; $text = preg_replace_callback('/'.$p['start_regx'].'(.*?)'.$p['end_regx'].'/si', array($this, "do_block_parser"), $text); } // 라인별로 파싱 $lines = explode("\n",$text); foreach ($lines as $k=>$line) { $this->current_row = $k; $line = $this->parse_line($line); array_push($this->output, $line); } // 출력 버퍼 병합 $output_string = implode(" ", $this->output); // URL 자동 링크 $output_string = str_replace("HREF=", "class='wiki_external_link' href=", url_auto_link($output_string)); $output_string = $this->emoticons($output_string); // 이벤트 $this->trigger_event(EVENT_AFTER_PARSING_ALL, array("lines"=>&$this->output, "output"=>&$output_string, "parser"=>&$this, "view"=>$this->view, "plugins"=>&$this->plugins)); $output_string = preg_replace($this->ele, "", $output_string); // nowiki 복원 $output_string = preg_replace_callback('/<pre><\/pre>/i', array($this,"_restorePre"), $output_string); $output_string = preg_replace_callback('/<nowiki><\/nowiki>/i', array($this,"_restoreNoWiki"), $output_string); $output_string = "<div class='narin_contents'>".$output_string."</div>"; return $output_string; }
function conv_content($content, $html) { global $config, $board; if ($html) { $source = array(); $target = array(); $source[] = "//"; $target[] = ""; if ($html == 2) { // 자동 줄바꿈 $source[] = "/\n/"; $target[] = "<br/>"; } // 테이블 태그의 갯수를 세어 테이블이 깨지지 않도록 한다. $table_begin_count = substr_count(strtolower($content), "<table"); $table_end_count = substr_count(strtolower($content), "</table"); for ($i = $table_end_count; $i < $table_begin_count; $i++) { $content .= "</table>"; } $content = preg_replace($source, $target, $content); $content = bad_tag_convert($content); // XSS (Cross Site Script) 막기 // 완벽한 XSS 방지는 없다. // object 태그에서 javascript 코드 막기 $content = preg_replace_callback("#<object([^>]+)>#i", "bad120422", $content); // 081022 : CSRF 방지 //$content = preg_replace("/(on)(abort|blur|change|click|dblclick|dragdrop|error|focus|keydown|keypress|keyup|load|mousedown|mousemove|mouseout|mouseover|mouseup|mouseenter|mouseleave|move|reset|resize|select|submit|unload)/i", "$1<!-- XSS Filter -->$2", $content); //$content = preg_replace("/(on)([^\=]+)/i", "on$2", $content); // 이런 경우를 방지함 <IMG STYLE="xss:expr/*XSS*/ession(alert('XSS'))"> $content = preg_replace("#\\/\\*.*\\*\\/#iU", "", $content); $content = preg_replace("/(on)([a-z]+)([^a-z]*)(\\=)/i", "on\$2\$3\$4", $content); $content = preg_replace("/(dy)(nsrc)/i", "dy\$2", $content); $content = preg_replace("/(lo)(wsrc)/i", "lo\$2", $content); $content = preg_replace("/(sc)(ript)/i", "sc\$2", $content); //$content = preg_replace("/(ex)(pression)/i", "ex$2", $content); $content = preg_replace("/\\<(\\w|\\s|\\?)*(xml)/i", "", $content); // 이미지 태그의 src 속성에 삭제등의 링크가 있는 경우 게시물을 확인하는 것만으로도 데이터의 위변조가 가능하므로 이것을 막음 $content = preg_replace("/<(img[^>]+delete\\.php[^>]+bo_table[^>]+)/i", "*** CSRF 감지 : <\$1", $content); $content = preg_replace("/<(img[^>]+delete_comment\\.php[^>]+bo_table[^>]+)/i", "*** CSRF 감지 : <\$1", $content); $content = preg_replace("/<(img[^>]+logout\\.php[^>]+)/i", "*** CSRF 감지 : <\$1", $content); $content = preg_replace("/<(img[^>]+download\\.php[^>]+bo_table[^>]+)/i", "*** CSRF 감지 : <\$1", $content); // 이런 경우를 방지함 <IMG STYLE="xss:expr/*XSS*/ession(alert('XSS'))"> //$content = preg_replace("#\/\*.*\*\/#iU", "", $content); // 이 코드를 위로 올립니다. $pattern = ""; $pattern .= "(e|&#(x65|101);?)"; $pattern .= "(x|&#(x78|120);?)"; $pattern .= "(p|&#(x70|112);?)"; $pattern .= "(r|&#(x72|114);?)"; $pattern .= "(e|&#(x65|101);?)"; $pattern .= "(s|&#(x73|115);?)"; $pattern .= "(s|&#(x73|115);?)"; $pattern .= "(i|&#(x6a|105);?)"; $pattern .= "(o|&#(x6f|111);?)"; $pattern .= "(n|&#(x6e|110);?)"; $content = preg_replace("/" . $pattern . "/i", "__EXPRESSION__", $content); /* $content = preg_replace("/\#/", "#", $content); $content = preg_replace("/\</", "<", $content); $content = preg_replace("/\>/", ">", $content); $content = preg_replace("/\(/", "(", $content); $content = preg_replace("/\)/", ")", $content); */ } else { // & 처리 : & 등의 코드를 정상 출력함 $content = html_symbol($content); // 공백 처리 $content = str_replace(" ", " ", $content); $content = str_replace("\n ", "\n ", $content); $content = get_text($content, 1); $content = url_auto_link($content); } return $content; }
function display_html_content($content = '', $html = '', $thumb_width = 700, $autolink = false, $popup = false, $writer_is_admin = false) { if (empty($html)) { $content = nl2br(html_escape($content)); if ($autolink) { $content = url_auto_link($content, $popup); } $content = preg_replace("/\\[<a\\s*href\\=\"(http|https|ftp)\\:\\/\\/([^[:space:]]+)\\.(gif|png|jpg|jpeg|bmp).*<\\/a>(\\s\\]|\\]|)/i", "<img src=\"\$1://\$2.\$3\" alt=\"\" style=\"max-width:100%;border:0;\">", $content); $content = preg_replace("/{지도\\:([^}]*)}/ie", "get_google_map('\\1', '{$thumb_width}')", $content); // Google Map return $content; } $source = array(); $target = array(); $source[] = '//'; $target[] = ''; $source[] = "/<\\?xml:namespace prefix = o ns = \"urn:schemas-microsoft-com:office:office\" \\/>/"; $target[] = ''; // 테이블 태그의 갯수를 세어 테이블이 깨지지 않도록 한다. $table_begin_count = substr_count(strtolower($content), '<table'); $table_end_count = substr_count(strtolower($content), '</table'); for ($i = $table_end_count; $i < $table_begin_count; $i++) { $content .= '</table>'; } $content = preg_replace($source, $target, $content); if ($autolink) { $content = url_auto_link($content, $popup); } if ($writer_is_admin === false) { $content = html_purifier($content); } $content = get_view_thumbnail($content, $thumb_width); $content = preg_replace("/{지도\\:([^}]*)}/ie", "get_google_map('\\1', '{$thumb_width}')", $content); // Google Map return $content; }
$sql .= " order by wr_good desc, wr_datetime asc limit {$mw_basic['cf_comment_best']} "; $qry = sql_query($sql); while ($row = sql_fetch_array($qry)) { // ============================= 베플 루프 시작 ============================= $is_comment_best[] = $row[wr_id]; if ($mw_basic[cf_comment_best_point]) { insert_point($row[mb_id], $mw_basic[cf_comment_best_point], '베플 선정', $bo_table, $row[wr_id], '베플'); } $tmp_name = get_text(cut_str($row[wr_name], $config[cf_cut_name])); // 설정된 자리수 만큼만 이름 출력 if ($board[bo_use_sideview]) { $row[name] = get_sideview($row[mb_id], $tmp_name, $row[wr_email], $row[wr_homepage]); } else { $row[name] = "<span class='" . ($row[mb_id] ? 'member' : 'guest') . "'>{$tmp_name}</span>"; } $row[trackback] = url_auto_link($row[wr_trackback]); $row[datetime] = substr($row[wr_datetime], 2, 14); $row[ip] = $row[wr_ip]; if (!$is_admin) { $row[ip] = preg_replace("/([0-9]+).([0-9]+).([0-9]+).([0-9]+)/", "\\1.♡.\\3.\\4", $row[wr_ip]); } else { if ($row[mb_id] == $config[cf_admin]) { $row[ip] = ""; } } include "{$board_skin_path}/view_comment_head.skin.php"; ?> <div class="mw_basic_comment_best"> <table width=100% cellpadding=0 cellspacing=0> <tr>
$tmp_name = get_text(cut_str($row[wr_name], $config[cf_cut_name])); // 설정된 자리수 만큼만 이름 출력 if ($board[bo_use_sideview]) { $list[$i][name] = get_sideview($row[mb_id], $tmp_name, $row[wr_email], $row[wr_homepage]); } else { $list[$i][name] = "<span class='" . ($row[mb_id] ? 'member' : 'guest') . "'>{$tmp_name}</span>"; } // 공백없이 연속 입력한 문자 자르기 (way 보드 참고. way.co.kr) //$list[$i][content] = eregi_replace("[^ \n<>]{130}", "\\0\n", $row[wr_content]); $list[$i][content] = $list[$i][content1] = "비밀글 입니다."; if (!strstr($row[wr_option], "secret") || $is_admin || $write[mb_id] == $member[mb_id] && $member[mb_id] || $row[mb_id] == $member[mb_id] && $member[mb_id]) { $list[$i][content1] = $row[wr_content]; $list[$i][content] = conv_content($row[wr_content], 0, 'wr_content'); $list[$i][content] = search_font($stx, $list[$i][content]); } $list[$i][trackback] = url_auto_link($row[wr_trackback]); $list[$i][datetime] = substr($row[wr_datetime], 2, 14); // 관리자가 아니라면 중간 IP 주소를 감춘후 보여줍니다. $list[$i][ip] = $row[wr_ip]; if (!$is_admin) { $list[$i][ip] = preg_replace("/([0-9]+).([0-9]+).([0-9]+).([0-9]+)/", "\\1.♡.\\3.\\4", $row[wr_ip]); } $list[$i][is_reply] = false; $list[$i][is_edit] = false; $list[$i][is_del] = false; if ($is_comment_write || $is_admin) { if ($member[mb_id]) { if ($row[mb_id] == $member[mb_id] || $is_admin) { $list[$i][del_link] = "./delete_comment.php?bo_table={$bo_table}&comment_id={$row['wr_id']}&token={$token}&page={$page}" . $qstr; $list[$i][is_edit] = true; $list[$i][is_del] = true;