/* Common actions used when posting/modifying a News Post */
function replace($what, $replace)
{
global $Settings;
/* Trim whitespace at Beginning and End of post */
$what = trim($what);
// REMOVED THIS FOR NOW FROM COMMENTS!
if($Settings['enablebbcode'] == 1)
{
/* Convert HTML Special Chars */
// $what = htmlentities($what, ENT_NOQUOTES);
}
else
{
/* Remove Disallowed Code */
// $what = preg_replace('/<script.+?<\\/script>/i', '', $what);
}
$what = shy($what, 50);
if($replace == 1)
{
$what = str_replace("\r\n", '<br />', $what);
}
if ($replace == 2) {
$what = str_replace('<br />', "\r\n", $what);
}
return $what;
}
/* Inserts the * thingie into certain posts */
function shy($text, $max, $char = "*")
{
if($max > 0)
{
$words = explode(' ', $text);
foreach($words as $key => $word)
{
$length = strlen($word);
if($length > $max)
{
$word = chunk_split($word, floor($length/ceil($length/$max)), $char);
}
$words[$key] = $word;
}
return implode(' ', $words);
}
else
{
return $text;
}
}
/* Parses Code */
function parseCode($news)
{
global $Settings;
/* Parse the BBCode */
if($Settings['enablebbcode'] == 1)
{
// Search for this...
$replacewhat = array(
'/\[url\](.+?)\[\/url\]/is',
'/\[url=(.+?)\](.+?)\[\/url\]/is',
'/\[ftp\](.+?)\[\/ftp\]/is',
'/\[ftp=(.+?)\](.+?)\[\/ftp\]/is',
'/\[b\](.+?)\[\/b\]/is',
'/\[i\](.+?)\[\/i\]/is',
'/\[u\](.+?)\[\/u\]/is',
'/\[del\](.+?)\[\/del\]/is',
'/\[img\](.+?)\[\/img\]/i',
'/\[img width=([0-9]+) height=([0-9]+)\s*\](.+?)\[\/img\]/i',
'/\[img width=([0-9]+)\s*\](.+?)\[\/img\]/i',
'/\[img height=([0-9]+) width=([0-9]+)\s*\](.+?)\[\/img\]/i',
'/\[img height=([0-9]+)\s*\](.+?)\[\/img\]/i',
'/\[email\](.+?)\[\/email\]/is',
'/\[email=(.+?)\](.+?)\[\/email\]/is',
'/(\/|=|"mailto:)?([a-z0-9_-][a-z0-9\._-]*@[a-z0-9_-]+(\.[a-z0-9_-]+)+)(\/|<)?/eis',
);
// ...and replace it with this
$replacewith = array(
'<a href="\\1">\\1</a>',
'<a href="\\1">\\2</a>',
'<a href="\\1">\\1</a>',
'<a href="\\1">\\2</a>',
'<b>\\1</b>',
'<i>\\1</i>',
'<u>\\1</u>',
'<del>\\1</del>',
'<img src="\\1" alt="" border="0" />',
'<img src="\\3" alt="" border="0" width="\\1" height="\\2" />',
'<img src="\\2" alt="" border="0" width="\\1" />',
'<img src="\\3" alt="" border="0" width="\\2" height="\\1" />',
'<img src="\\2" alt="" border="0" height="\\1" />',
'<a href="mailto:\\1">\\1</a>',
'<a href="mailto:\\1">\\2</a>',
"('\\4' == '' && '\\1' == '' ? '<a href=\"mailto:\\2\">\\2</a>' : stripslashes('\\1\\2\\4'))",
);
$news = preg_replace($replacewhat, $replacewith, $news);
}
/* Parse the Smilies */
if($Settings['enablesmilies'] == 1)
{
static $smileyfromcache, $smileytocache;
/* If the smiley array hasn't been set, do it now */
if (!is_array($smileyfromcache))
{
$smiliesfrom = array(':rolleyes:', ':angry:', ':smiley:', ':wink:', ':cheesy:', ':grin:', ':sad:', ':shocked:', ':cool:', ':tongue:', ':huh:', ':embarassed:', ':lipsrsealed:', ':kiss:', ':cry:', ':undecided:', ':laugh:');
$smiliesto = array('rolleyes', 'angry', 'smiley', 'wink', 'cheesy', 'grin', 'sad', 'shocked', 'cool', 'tongue', 'huh', 'embarassed', 'lipsrsealed', 'kiss', 'cry', 'undecided', 'laugh');
for ($i = 0; $i < count($smiliesfrom); $i++)
{
$smileyfromcache[] = $smiliesfrom[$i];
$smileytocache[] = '<img src="' . $Settings['phpnewsurl'] . 'images/smilies/' . $smiliesto[$i] . '.gif" alt="' . $smiliesto[$i] . '" border="0" />';
}
/* Now unneeded */
unset($smiliesfrom);
unset($smiliesto);
}
/* Replace away! */
$news = str_replace($smileyfromcache, $smileytocache, $news);
}
return $news;
}
/* Censors Comments */
function censor($text)
{
global $Settings;
static $goodword, $badword;
/* Checks if good/bad words list has already been done (stored in static variable to increase speed) */
if (!is_array($goodword))
{
$badword = array();
$goodword = array();
/* Format the censor list */
$array = explode('|', $Settings['censorlist']);
/* Put the list of words in Arrays */
foreach ($array as $i)
{
list($badword[], $goodword[]) = explode('=', $i);
}
}
/* Replace bad words with clean words */
for($i = 0; $i < count($goodword); $i++)
{
$text = preg_replace('/' . preg_quote($badword[$i], '/') . '/i', $goodword[$i], $text);
}
/* Return the censored text */
return $text;
}
/* Checks Banned IPs */
function checkUserIP($ip)
{
global $db_prefix;
/* Search the 'banned' table for occurences of this IP */
$query = mysql_query('SELECT isbanned FROM ' . $db_prefix . 'banned WHERE ip = \'' . $ip . '\'');
$request = mysql_fetch_assoc($query);
/* If the User is banned, return a 1 */
if ($request['isbanned'] == 1)
{
return 1;
}
else
{
return 0;
}
}
?>
<!-- (c) 2003 PHPNews - http://newsphp.sourceforge.net/ -->