function showPost($topic, $text, $smile) { $text = nl2br($text); $post = ''; if (!empty($topic)) { $post .= '<b>' . replaceSmile($topic, $smile) . '</b><hr />'; } $post .= replaceAll($text, $smile); return $post; }
function replaceAll($text, $smile) { $rows = 0; while (stripos($text, '[color') !== false && stripos($text, '[/color]') !== false && stripos($text, '[color') < stripos($text, '[/color]')) { $outer_section = substr($text, stripos($text, '[color'), stripos($text, '[/color]') + 8 - stripos($text, '[color')); $outer_value = substr($outer_section, stripos($outer_section, '[color') + 7, stripos($outer_section, ']') - stripos($outer_section, '[color') - 7); $inner_text = substr($outer_section, stripos($outer_section, ']') + 1, stripos($outer_section, '[/color]') - stripos($outer_section, ']') - 1); $text = str_ireplace($outer_section, '<span style="color: ' . $outer_value . ';">' . $inner_text . '</span>', $text); } while (stripos($text, '[code]') !== false && stripos($text, '[/code]') !== false && stripos($text, '[code]') < stripos($text, '[/code]')) { $code = substr($text, stripos($text, '[code]') + 6, stripos($text, '[/code]') - stripos($text, '[code]') - 6); if (!is_int($rows / 2)) { $bgcolor = 'ABED25'; } else { $bgcolor = '23ED25'; } $rows++; $text = str_ireplace('[code]' . $code . '[/code]', '<i>Code:</i><br /><table cellpadding="0" style="background-color: #' . $bgcolor . '; width: 480px; border-style: dotted; border-color: #CCCCCC; border-width: 2px"><tr><td>' . $code . '</td></tr></table>', $text); } $rows = 0; while (stripos($text, '[quote]') !== false && stripos($text, '[/quote]') !== false && stripos($text, '[quote]') < stripos($text, '[/quote]')) { $quote = substr($text, stripos($text, '[quote]') + 7, stripos($text, '[/quote]') - stripos($text, '[quote]') - 7); if (!is_int($rows / 2)) { $bgcolor = 'AAAAAA'; } else { $bgcolor = 'CCCCCC'; } $rows++; $text = str_ireplace('[quote]' . $quote . '[/quote]', '<table cellpadding="0" style="background-color: #' . $bgcolor . '; width: 480px; border-style: dotted; border-color: #007900; border-width: 2px"><tr><td>' . $quote . '</td></tr></table>', $text); } $rows = 0; while (stripos($text, '[url]') !== false && stripos($text, '[/url]') !== false && stripos($text, '[url]') < stripos($text, '[/url]')) { $url = substr($text, stripos($text, '[url]') + 5, stripos($text, '[/url]') - stripos($text, '[url]') - 5); $text = str_ireplace('[url]' . $url . '[/url]', '<a href="' . $url . '" target="_blank">' . $url . '</a>', $text); } while (stripos($text, '[url') !== false && stripos($text, '[/url]') !== false && stripos($text, '[url') < stripos($text, '[/url]')) { $url_section = substr($text, stripos($text, '[url'), stripos($text, '[/url]') + 6 - stripos($text, '[url')); $url = substr($url_section, stripos($url_section, '[url') + 5, stripos($url_section, ']') - stripos($url_section, '[url') - 5); $anchor_name = substr($url_section, stripos($url_section, ']') + 1, stripos($url_section, '[/url]') - stripos($url_section, ']') - 1); $text = str_ireplace($url_section, '<a href="' . $url . '" target="_blank">' . $anchor_name . '</a>', $text); } while (stripos($text, '[player]') !== false && stripos($text, '[/player]') !== false && stripos($text, '[player]') < stripos($text, '[/player]')) { $player = substr($text, stripos($text, '[player]') + 8, stripos($text, '[/player]') - stripos($text, '[player]') - 8); $text = str_ireplace('[player]' . $player . '[/player]', '<a href="?subtopic=characters&name=' . urlencode($player) . '">' . $player . '</a>', $text); } while (stripos($text, '[img]') !== false && stripos($text, '[/img]') !== false && stripos($text, '[img]') < stripos($text, '[/img]')) { $img = substr($text, stripos($text, '[img]') + 5, stripos($text, '[/img]') - stripos($text, '[img]') - 5); $text = str_ireplace('[img]' . $img . '[/img]', '<img src="' . $img . '">', $text); } while (stripos($text, '[b]') !== false && stripos($text, '[/b]') !== false && stripos($text, '[b]') < stripos($text, '[/b]')) { $b = substr($text, stripos($text, '[b]') + 3, stripos($text, '[/b]') - stripos($text, '[b]') - 3); $text = str_ireplace('[b]' . $b . '[/b]', '<b>' . $b . '</b>', $text); } while (stripos($text, '[i]') !== false && stripos($text, '[/i]') !== false && stripos($text, '[i]') < stripos($text, '[/i]')) { $i = substr($text, stripos($text, '[i]') + 3, stripos($text, '[/i]') - stripos($text, '[i]') - 3); $text = str_ireplace('[i]' . $i . '[/i]', '<i>' . $i . '</i>', $text); } while (stripos($text, '[u]') !== false && stripos($text, '[/u]') !== false && stripos($text, '[u]') < stripos($text, '[/u]')) { $u = substr($text, stripos($text, '[u]') + 3, stripos($text, '[/u]') - stripos($text, '[u]') - 3); $text = str_ireplace('[u]' . $u . '[/u]', '<u>' . $u . '</u>', $text); } return replaceSmile($text, $smile); }