punbb/include/parser.php
author Dan
Thu, 12 Jul 2007 15:00:35 -0400
changeset 3 c0c445d4a13e
parent 0 f9ffdbd96607
permissions -rw-r--r--
Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     1
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     2
/***********************************************************************
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     3
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     4
  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     5
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     6
  This file is part of PunBB.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     7
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     8
  PunBB is free software; you can redistribute it and/or modify it
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     9
  under the terms of the GNU General Public License as published
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    10
  by the Free Software Foundation; either version 2 of the License,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    11
  or (at your option) any later version.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    12
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    13
  PunBB is distributed in the hope that it will be useful, but
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    14
  WITHOUT ANY WARRANTY; without even the implied warranty of
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    16
  GNU General Public License for more details.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    17
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    18
  You should have received a copy of the GNU General Public License
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    19
  along with this program; if not, write to the Free Software
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    20
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    21
  MA  02111-1307  USA
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    22
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    23
************************************************************************/
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    24
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    25
// Make sure no one attempts to run this script "directly"
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    26
if (!defined('PUN'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    27
	exit;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    28
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    29
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    30
// Here you can add additional smilies if you like (please note that you must escape singlequote and backslash)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    31
$smiley_text = array(':)', '=)', ':|', '=|', ':(', '=(', ':D', '=D', ':o', ':O', ';)', ':/', ':P', ':lol:', ':mad:', ':rolleyes:', ':cool:');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    32
$smiley_img = array('smile.png', 'smile.png', 'neutral.png', 'neutral.png', 'sad.png', 'sad.png', 'big_smile.png', 'big_smile.png', 'yikes.png', 'yikes.png', 'wink.png', 'hmm.png', 'tongue.png', 'lol.png', 'mad.png', 'roll.png', 'cool.png');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    33
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    34
// Uncomment the next row if you add smilies that contain any of the characters &"'<>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    35
//$smiley_text = array_map('pun_htmlspecialchars', $smiley_text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    36
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    37
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    38
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    39
// Make sure all BBCodes are lower case and do a little cleanup
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    40
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    41
function preparse_bbcode($text, &$errors, $is_signature = false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    42
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    43
	// Change all simple BBCodes to lower case
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    44
	$a = array('[B]', '[I]', '[U]', '[/B]', '[/I]', '[/U]');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    45
	$b = array('[b]', '[i]', '[u]', '[/b]', '[/i]', '[/u]');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    46
	$text = str_replace($a, $b, $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    47
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    48
	// Do the more complex BBCodes (also strip excessive whitespace and useless quotes)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    49
	$a = array( '#\[url=("|\'|)(.*?)\\1\]\s*#i',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    50
				'#\[url\]\s*#i',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    51
				'#\s*\[/url\]#i',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    52
				'#\[email=("|\'|)(.*?)\\1\]\s*#i',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    53
				'#\[email\]\s*#i',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    54
				'#\s*\[/email\]#i',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    55
				'#\[img\]\s*(.*?)\s*\[/img\]#is',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    56
				'#\[colou?r=("|\'|)(.*?)\\1\](.*?)\[/colou?r\]#is');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    57
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    58
	$b = array(	'[url=$2]',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    59
				'[url]',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    60
				'[/url]',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    61
				'[email=$2]',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    62
				'[email]',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    63
				'[/email]',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    64
				'[img]$1[/img]',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    65
				'[color=$2]$3[/color]');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    66
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    67
	if (!$is_signature)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    68
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    69
		// For non-signatures, we have to do the quote and code tags as well
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    70
		$a[] = '#\[quote=(&quot;|"|\'|)(.*?)\\1\]\s*#i';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    71
		$a[] = '#\[quote\]\s*#i';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    72
		$a[] = '#\s*\[/quote\]\s*#i';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    73
		$a[] = '#\[code\][\r\n]*(.*?)\s*\[/code\]\s*#is';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    74
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    75
		$b[] = '[quote=$1$2$1]';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    76
		$b[] = '[quote]';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    77
		$b[] = '[/quote]'."\n";
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    78
		$b[] = '[code]$1[/code]'."\n";
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    79
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    80
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    81
	// Run this baby!
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    82
	$text = preg_replace($a, $b, $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    83
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    84
	if (!$is_signature)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    85
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    86
		$overflow = check_tag_order($text, $error);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    87
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    88
		if ($error)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    89
			// A BBCode error was spotted in check_tag_order()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    90
			$errors[] = $error;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    91
		else if ($overflow)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    92
			// The quote depth level was too high, so we strip out the inner most quote(s)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    93
			$text = substr($text, 0, $overflow[0]).substr($text, $overflow[1], (strlen($text) - $overflow[0]));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    94
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    95
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    96
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    97
		global $lang_prof_reg;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    98
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    99
		if (preg_match('#\[quote=(&quot;|"|\'|)(.*)\\1\]|\[quote\]|\[/quote\]|\[code\]|\[/code\]#i', $text))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   100
			message($lang_prof_reg['Signature quote/code']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   101
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   102
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   103
	return trim($text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   104
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   105
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   106
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   107
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   108
// Parse text and make sure that [code] and [quote] syntax is correct
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   109
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   110
function check_tag_order($text, &$error)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   111
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   112
	global $lang_common;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   113
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   114
	// The maximum allowed quote depth
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   115
	$max_depth = 3;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   116
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   117
	$cur_index = 0;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   118
	$q_depth = 0;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   119
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   120
	while (true)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   121
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   122
		// Look for regular code and quote tags
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   123
		$c_start = strpos($text, '[code]');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   124
		$c_end = strpos($text, '[/code]');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   125
		$q_start = strpos($text, '[quote]');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   126
		$q_end = strpos($text, '[/quote]');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   127
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   128
		// Look for [quote=username] style quote tags
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   129
		if (preg_match('#\[quote=(&quot;|"|\'|)(.*)\\1\]#sU', $text, $matches))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   130
			$q2_start = strpos($text, $matches[0]);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   131
		else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   132
			$q2_start = 65536;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   133
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   134
		// Deal with strpos() returning false when the string is not found
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   135
		// (65536 is one byte longer than the maximum post length)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   136
		if ($c_start === false) $c_start = 65536;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   137
		if ($c_end === false) $c_end = 65536;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   138
		if ($q_start === false) $q_start = 65536;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   139
		if ($q_end === false) $q_end = 65536;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   140
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   141
		// If none of the strings were found
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   142
		if (min($c_start, $c_end, $q_start, $q_end, $q2_start) == 65536)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   143
			break;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   144
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   145
		// We are interested in the first quote (regardless of the type of quote)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   146
		$q3_start = ($q_start < $q2_start) ? $q_start : $q2_start;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   147
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   148
		// We found a [quote] or a [quote=username]
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   149
		if ($q3_start < min($q_end, $c_start, $c_end))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   150
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   151
			$step = ($q_start < $q2_start) ? 7 : strlen($matches[0]);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   152
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   153
			$cur_index += $q3_start + $step;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   154
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   155
			// Did we reach $max_depth?
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   156
			if ($q_depth == $max_depth)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   157
				$overflow_begin = $cur_index - $step;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   158
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   159
			++$q_depth;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   160
			$text = substr($text, $q3_start + $step);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   161
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   162
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   163
		// We found a [/quote]
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   164
		else if ($q_end < min($q_start, $c_start, $c_end))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   165
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   166
			if ($q_depth == 0)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   167
			{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   168
				$error = $lang_common['BBCode error'].' '.$lang_common['BBCode error 1'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   169
				return;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   170
			}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   171
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   172
			$q_depth--;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   173
			$cur_index += $q_end+8;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   174
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   175
			// Did we reach $max_depth?
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   176
			if ($q_depth == $max_depth)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   177
				$overflow_end = $cur_index;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   178
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   179
			$text = substr($text, $q_end+8);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   180
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   181
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   182
		// We found a [code]
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   183
		else if ($c_start < min($c_end, $q_start, $q_end))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   184
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   185
			// Make sure there's a [/code] and that any new [code] doesn't occur before the end tag
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   186
			$tmp = strpos($text, '[/code]');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   187
			$tmp2 = strpos(substr($text, $c_start+6), '[code]');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   188
			if ($tmp2 !== false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   189
				$tmp2 += $c_start+6;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   190
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   191
			if ($tmp === false || ($tmp2 !== false && $tmp2 < $tmp))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   192
			{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   193
				$error = $lang_common['BBCode error'].' '.$lang_common['BBCode error 2'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   194
				return;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   195
			}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   196
			else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   197
				$text = substr($text, $tmp+7);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   198
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   199
			$cur_index += $tmp+7;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   200
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   201
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   202
		// We found a [/code] (this shouldn't happen since we handle both start and end tag in the if clause above)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   203
		else if ($c_end < min($c_start, $q_start, $q_end))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   204
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   205
			$error = $lang_common['BBCode error'].' '.$lang_common['BBCode error 3'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   206
			return;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   207
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   208
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   209
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   210
	// If $q_depth <> 0 something is wrong with the quote syntax
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   211
	if ($q_depth)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   212
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   213
		$error = $lang_common['BBCode error'].' '.$lang_common['BBCode error 4'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   214
		return;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   215
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   216
	else if ($q_depth < 0)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   217
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   218
		$error = $lang_common['BBCode error'].' '.$lang_common['BBCode error 5'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   219
		return;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   220
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   221
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   222
	// If the quote depth level was higher than $max_depth we return the index for the
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   223
	// beginning and end of the part we should strip out
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   224
	if (isset($overflow_begin))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   225
		return array($overflow_begin, $overflow_end);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   226
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   227
		return null;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   228
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   229
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   230
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   231
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   232
// Split text into chunks ($inside contains all text inside $start and $end, and $outside contains all text outside)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   233
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   234
function split_text($text, $start, $end)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   235
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   236
	global $pun_config;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   237
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   238
	$tokens = explode($start, $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   239
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   240
	$outside[] = $tokens[0];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   241
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   242
	$num_tokens = count($tokens);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   243
	for ($i = 1; $i < $num_tokens; ++$i)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   244
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   245
		$temp = explode($end, $tokens[$i]);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   246
		$inside[] = $temp[0];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   247
		$outside[] = $temp[1];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   248
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   249
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   250
	if ($pun_config['o_indent_num_spaces'] != 8 && $start == '[code]')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   251
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   252
		$spaces = str_repeat(' ', $pun_config['o_indent_num_spaces']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   253
		$inside = str_replace("\t", $spaces, $inside);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   254
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   255
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   256
	return array($inside, $outside);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   257
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   258
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   259
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   260
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   261
// Truncate URL if longer than 55 characters (add http:// or ftp:// if missing)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   262
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   263
function handle_url_tag($url, $link = '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   264
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   265
	global $pun_user;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   266
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   267
	$full_url = str_replace(array(' ', '\'', '`', '"'), array('%20', '', '', ''), $url);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   268
	if (strpos($url, 'www.') === 0)			// If it starts with www, we add http://
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   269
		$full_url = 'http://'.$full_url;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   270
	else if (strpos($url, 'ftp.') === 0)	// Else if it starts with ftp, we add ftp://
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   271
		$full_url = 'ftp://'.$full_url;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   272
	else if (!preg_match('#^([a-z0-9]{3,6})://#', $url, $bah)) 	// Else if it doesn't start with abcdef://, we add http://
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   273
		$full_url = 'http://'.$full_url;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   274
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   275
	// Ok, not very pretty :-)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   276
	$link = ($link == '' || $link == $url) ? ((strlen($url) > 55) ? substr($url, 0 , 39).' &hellip; '.substr($url, -10) : $url) : stripslashes($link);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   277
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   278
	return '<a href="'.$full_url.'">'.$link.'</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   279
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   280
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   281
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   282
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   283
// Turns an URL from the [img] tag into an <img> tag or a <a href...> tag
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   284
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   285
function handle_img_tag($url, $is_signature = false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   286
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   287
	global $lang_common, $pun_config, $pun_user;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   288
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   289
	$img_tag = '<a href="'.$url.'">&lt;'.$lang_common['Image link'].'&gt;</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   290
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   291
	if ($is_signature && $pun_user['show_img_sig'] != '0')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   292
		$img_tag = '<img class="sigimage" src="'.$url.'" alt="'.htmlspecialchars($url).'" />';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   293
	else if (!$is_signature && $pun_user['show_img'] != '0')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   294
		$img_tag = '<img class="postimg" src="'.$url.'" alt="'.htmlspecialchars($url).'" />';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   295
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   296
	return $img_tag;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   297
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   298
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   299
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   300
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   301
// Convert BBCodes to their HTML equivalent
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   302
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   303
function do_bbcode($text)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   304
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   305
	global $lang_common, $pun_user;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   306
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   307
	if (strpos($text, 'quote') !== false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   308
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   309
		$text = str_replace('[quote]', '</p><blockquote><div class="incqbox"><p>', $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   310
		$text = preg_replace('#\[quote=(&quot;|"|\'|)(.*)\\1\]#seU', '"</p><blockquote><div class=\"incqbox\"><h4>".str_replace(array(\'[\', \'\\"\'), array(\'&#91;\', \'"\'), \'$2\')." ".$lang_common[\'wrote\'].":</h4><p>"', $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   311
		$text = preg_replace('#\[\/quote\]\s*#', '</p></div></blockquote><p>', $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   312
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   313
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   314
	$pattern = array('#\[b\](.*?)\[/b\]#s',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   315
					 '#\[i\](.*?)\[/i\]#s',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   316
					 '#\[u\](.*?)\[/u\]#s',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   317
					 '#\[url\]([^\[]*?)\[/url\]#e',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   318
					 '#\[url=([^\[]*?)\](.*?)\[/url\]#e',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   319
					 '#\[email\]([^\[]*?)\[/email\]#',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   320
					 '#\[email=([^\[]*?)\](.*?)\[/email\]#',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   321
					 '#\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6})](.*?)\[/color\]#s');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   322
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   323
	$replace = array('<strong>$1</strong>',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   324
					 '<em>$1</em>',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   325
					 '<span class="bbu">$1</span>',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   326
					 'handle_url_tag(\'$1\')',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   327
					 'handle_url_tag(\'$1\', \'$2\')',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   328
					 '<a href="mailto:$1">$1</a>',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   329
					 '<a href="mailto:$1">$2</a>',
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   330
					 '<span style="color: $1">$2</span>');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   331
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   332
	// This thing takes a while! :)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   333
	$text = preg_replace($pattern, $replace, $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   334
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   335
	return $text;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   336
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   337
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   338
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   339
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   340
// Make hyperlinks clickable
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   341
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   342
function do_clickable($text)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   343
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   344
	global $pun_user;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   345
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   346
	$text = ' '.$text;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   347
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   348
	$text = preg_replace('#([\s\(\)])(https?|ftp|news){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#ie', '\'$1\'.handle_url_tag(\'$2://$3\')', $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   349
	$text = preg_replace('#([\s\(\)])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#ie', '\'$1\'.handle_url_tag(\'$2.$3\', \'$2.$3\')', $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   350
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   351
	return substr($text, 1);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   352
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   353
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   354
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   355
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   356
// Convert a series of smilies to images
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   357
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   358
function do_smilies($text)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   359
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   360
	global $smiley_text, $smiley_img;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   361
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   362
	$text = ' '.$text.' ';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   363
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   364
	$num_smilies = count($smiley_text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   365
	for ($i = 0; $i < $num_smilies; ++$i)
3
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 0
diff changeset
   366
		$text = preg_replace("#(?<=.\W|\W.|^\W)".preg_quote($smiley_text[$i], '#')."(?=.\W|\W.|\W$)#m", '$1<img src="' . scriptPath . '/punbb/img/smilies/'.$smiley_img[$i].'" width="15" height="15" alt="'.substr($smiley_img[$i], 0, strrpos($smiley_img[$i], '.')).'" />$2', $text);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   367
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   368
	return substr($text, 1, -1);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   369
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   370
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   371
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   372
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   373
// Parse message text
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   374
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   375
function parse_message($text, $hide_smilies)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   376
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   377
	global $pun_config, $lang_common, $pun_user;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   378
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   379
	if ($pun_config['o_censoring'] == '1')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   380
		$text = censor_words($text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   381
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   382
	// Convert applicable characters to HTML entities
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   383
	$text = pun_htmlspecialchars($text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   384
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   385
	// If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   386
	if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   387
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   388
		list($inside, $outside) = split_text($text, '[code]', '[/code]');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   389
		$outside = array_map('ltrim', $outside);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   390
		$text = implode('<">', $outside);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   391
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   392
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   393
	if ($pun_config['o_make_links'] == '1')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   394
		$text = do_clickable($text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   395
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   396
	if ($pun_config['o_smilies'] == '1' && $pun_user['show_smilies'] == '1' && $hide_smilies == '0')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   397
		$text = do_smilies($text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   398
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   399
	if ($pun_config['p_message_bbcode'] == '1' && strpos($text, '[') !== false && strpos($text, ']') !== false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   400
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   401
		$text = do_bbcode($text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   402
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   403
		if ($pun_config['p_message_img_tag'] == '1')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   404
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   405
//			$text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\.(jpg|jpeg|png|gif)\[/img\]#e', 'handle_img_tag(\'$1$3.$4\')', $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   406
			$text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\[/img\]#e', 'handle_img_tag(\'$1$3\')', $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   407
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   408
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   409
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   410
	// Deal with newlines, tabs and multiple spaces
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   411
	$pattern = array("\n", "\t", '  ', '  ');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   412
	$replace = array('<br />', '&nbsp; &nbsp; ', '&nbsp; ', ' &nbsp;');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   413
	$text = str_replace($pattern, $replace, $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   414
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   415
	// If we split up the message before we have to concatenate it together again (code tags)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   416
	if (isset($inside))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   417
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   418
		$outside = explode('<">', $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   419
		$text = '';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   420
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   421
		$num_tokens = count($outside);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   422
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   423
		for ($i = 0; $i < $num_tokens; ++$i)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   424
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   425
			$text .= $outside[$i];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   426
			if (isset($inside[$i]))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   427
			{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   428
				$num_lines = ((substr_count($inside[$i], "\n")) + 3) * 1.5;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   429
				$height_str = ($num_lines > 35) ? '35em' : $num_lines.'em';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   430
				$text .= '</p><div class="codebox"><div class="incqbox"><h4>'.$lang_common['Code'].':</h4><div class="scrollbox" style="height: '.$height_str.'"><pre>'.$inside[$i].'</pre></div></div></div><p>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   431
			}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   432
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   433
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   434
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   435
	// Add paragraph tag around post, but make sure there are no empty paragraphs
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   436
	$text = str_replace('<p></p>', '', '<p>'.$text.'</p>');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   437
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   438
	return $text;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   439
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   440
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   441
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   442
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   443
// Parse signature text
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   444
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   445
function parse_signature($text)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   446
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   447
	global $pun_config, $lang_common, $pun_user;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   448
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   449
	if ($pun_config['o_censoring'] == '1')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   450
		$text = censor_words($text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   451
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   452
	$text = pun_htmlspecialchars($text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   453
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   454
	if ($pun_config['o_make_links'] == '1')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   455
		$text = do_clickable($text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   456
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   457
	if ($pun_config['o_smilies_sig'] == '1' && $pun_user['show_smilies'] != '0')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   458
		$text = do_smilies($text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   459
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   460
	if ($pun_config['p_sig_bbcode'] == '1' && strpos($text, '[') !== false && strpos($text, ']') !== false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   461
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   462
		$text = do_bbcode($text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   463
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   464
		if ($pun_config['p_sig_img_tag'] == '1')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   465
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   466
//			$text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\.(jpg|jpeg|png|gif)\[/img\]#e', 'handle_img_tag(\'$1$3.$4\', true)', $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   467
			$text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\[/img\]#e', 'handle_img_tag(\'$1$3\', true)', $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   468
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   469
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   470
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   471
	// Deal with newlines, tabs and multiple spaces
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   472
	$pattern = array("\n", "\t", '  ', '  ');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   473
	$replace = array('<br />', '&nbsp; &nbsp; ', '&nbsp; ', ' &nbsp;');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   474
	$text = str_replace($pattern, $replace, $text);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   475
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   476
	return $text;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   477
}