<?php
// main post parser
function main_post_parser($post)
{
global $db;
$post = htmlentities($post);
$post = trim($post);
// sort out new lines into breaks
$post = str_replace(array("\r\n", "\r", "\n"), "<br />", $post);
if( get_magic_quotes_gpc() )
{
$post = stripslashes($post);
}
if( !is_numeric($post) || $post[0] == '0' )
{
// $post = $db->escape($post); <-- Your version
$post = mysql_escape_string($post); // I don't have the function :) lolz
}
// check if they are a guest, if they are check if guests links get parsed
if ($_SESSION['group'] == 4)
{
if ($site_config['guest_links_parsed'] == 0)
{
// then don't parse
}
else
{
// auto-make links
// Thanks to "geirha" from ubuntu forums for his amazing work on this for me :)
$post = preg_replace("`\b(https?|ftp|file)://[^www][-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]\b`", '<a href="\0" target="_blank">\0</a>', $post);
if(preg_match("/(www\\.([a-z][a-z0-9_\\.-]*[a-z]{2,6})([a-zA-Z0-9\\/\\*-\\?&%]*))/i", $post))
{
// Yes, order matters :P First one changes http://www.*
// Second one just www.* to avoid the double parse
$post = preg_replace("`\b(https?|ftp|file)://[www][-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]\b`", '<a href="\0">\0</a>', $post);
$post = preg_replace("([^https?\\:\\/\\/|^ftp\\:\\/\\/|^file\\:\\/\\/](www\\.([a-z][a-z0-9_\\.-]*[a-z]{2,6})([a-zA-Z0-9\\/\\*-\\?&%]*)\b))", '<a href="http://$1">\0</a>', $post);
}
}
}
// they are not a guest so parse away
else if ($_SESSION['group'] != 4)
{
// auto-make links
// Thanks to "geirha" from ubuntu forums for his amazing work on this for me :)
$post = preg_replace("`\b(https?|ftp|file)://[^www][-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]\b`", '<a href="\0" target="_blank">\0</a>', $post);
if(preg_match("/(www\\.([a-z][a-z0-9_\\.-]*[a-z]{2,6})([a-zA-Z0-9\\/\\*-\\?&%]*))/i", $post))
{
// Yes, order matters :P First one changes http://www.*
// Second one just www.* to avoid the double parse
$post = preg_replace("`\b(https?|ftp|file)://[www][-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]\b`", '<a href="\0">\0</a>', $post);
$post = preg_replace("([^https?\\:\\/\\/|^ftp\\:\\/\\/|^file\\:\\/\\/](www\\.([a-z][a-z0-9_\\.-]*[a-z]{2,6})([a-zA-Z0-9\\/\\*-\\?&%]*)\b))", '<a href="http://$1">\0</a>', $post);
}
}
return $post;
}
echo main_post_parser("Check: http://test.com, check: www.test.com, check: http://www.test.com
Check line break.. w00t :)");
?>