[BETA] Smiley management

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Re: [BETA] Smiley management

Post by Merlin Sythove »

Hi Tudor,

Nice to see you're working hard... :lol:
Need custom work done? Pimp My Forum!
Peter77sx
Registered User
Posts: 3260
Joined: Wed Nov 09, 2005 2:51 pm

Re: [BETA] Smiley management

Post by Peter77sx »

Any plans for an phpbb3 Version?
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Re: [BETA] Smiley management

Post by Merlin Sythove »

No sorry, I would have expected them to copy it or something similar already.
Need custom work done? Pimp My Forum!
Peter77sx
Registered User
Posts: 3260
Joined: Wed Nov 09, 2005 2:51 pm

Re: [BETA] Smiley management

Post by Peter77sx »

Me too. maybe someday soon. Thanks anyway. :)
NWCPNE1
Registered User
Posts: 222
Joined: Sat Feb 02, 2008 8:28 pm

Re: [BETA] Smiley management

Post by NWCPNE1 »

Any one have a copy of this mod, as the download wont unzip. shame I like the look of this mod.
http://www.nwcpnefc.co.uk for PNE Fans in North Wales and Cheshire, but we welcome all, including fans from other clubs.
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Re: [BETA] Smiley management

Post by Merlin Sythove »

I just tested it, it downloads and opens fine. If you have problems, then it is not with the file to download.
Need custom work done? Pimp My Forum!
NWCPNE1
Registered User
Posts: 222
Joined: Sat Feb 02, 2008 8:28 pm

Re: [BETA] Smiley management

Post by NWCPNE1 »

ok I installed it, it seems ok, but my Smilies have gone, and I am getting Image

In posts, the Smilies have gone, but they was working before, Any ideas?
http://www.nwcpnefc.co.uk for PNE Fans in North Wales and Cheshire, but we welcome all, including fans from other clubs.
Peter77sx
Registered User
Posts: 3260
Joined: Wed Nov 09, 2005 2:51 pm

Re: [BETA] Smiley management

Post by Peter77sx »

You'll have to check the "inline" option to choose which smilies will show in the posting page.

And then add smilies to thier category for them to show. I've been running this MOD for a long time without any problems, so I've almost forgotten how to set it up... but I do not think you will lose your old :code: names.

Here is a useful quote by Merlin Sythove
Merlin Sythove wrote:The direct answer is that with eachsmiley, you can set a checkbox for "Inline" and then that smiley will be shown next to the posting text box. You will find an extensive manual to download on page 1 of this topic!
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Re: [BETA] Smiley management

Post by Merlin Sythove »

NWCPNE1 wrote:ok I installed it, it seems ok, but my Smilies have gone
First of all, don't worry, they haven't gone, they're still there. You will probably see them in posts anyway.
It looks like a folder or path name was entered incorrectly and/or another mod has done things.

Questions:
1. Did you install this with Easymod? If so, which errors did you get and ignore?
2. If not easymod, did you doublecheck and install the mod by hand again from scratch, to make sure you did not make any mistakes, did not forget lines, instructions, upload files?
3. in admin_smilies.php find
$dir = @opendir($smilies_path);
and before it add
var_dump($smilies_path);
and save the file. Then go to the ACP smiley management page and see what information you get.
Need custom work done? Pimp My Forum!
NWCPNE1
Registered User
Posts: 222
Joined: Sat Feb 02, 2008 8:28 pm

Re: [BETA] Smiley management

Post by NWCPNE1 »

when #i try to insert one manually I get this

Code: Select all

Couldn't retrieve smileys

DEBUG MODE

SQL Error : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':angry: OR number = 0 ORDER BY number' at line 2

SELECT * FROM phpbb_smilies WHERE page = 2 AND number >= :angry: OR number = 0 ORDER BY number

Line : 486
File : admin_smilies.php
http://www.nwcpnefc.co.uk for PNE Fans in North Wales and Cheshire, but we welcome all, including fans from other clubs.
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Re: [BETA] Smiley management

Post by Merlin Sythove »

I think you already posted a picture that made it clear the mod was not working properly. If you are interested in finding the errors, please go through my list of points one by one and maybe redo all the modding you did by hand to ensure you did not make any errors etc. etc. and report back.
Need custom work done? Pimp My Forum!
NWCPNE1
Registered User
Posts: 222
Joined: Sat Feb 02, 2008 8:28 pm

Re: [BETA] Smiley management

Post by NWCPNE1 »

Getting a New Error now, Easy mod won't go back so my whole forum has been killed.

Error Message
Warning: usort() [function.usort]: Invalid comparison function in /homer/nwcpne/public_html/forum/includes/bbcode.php on line 1178

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 17211971 bytes) in /homer/nwcpne/public_html/forum/includes/bbcode.php on line 1190

Code: Select all

<?php
/***************************************************************************
 *                              bbcode.php
 *                            -------------------
 *   begin                : Saturday, Feb 13, 2001
 *   copyright            : (C) 2001 The phpBB Group
 *   email                : support@phpbb.com
 *
 *   $Id: bbcode.php,v 1.36.2.41 2006/02/26 17:34:50 grahamje Exp $
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

if ( !defined('IN_PHPBB') )
{
	die("Hacking attempt");
}

define("BBCODE_UID_LEN", 10);

// global that holds loaded-and-prepared bbcode templates, so we only have to do
// that stuff once.

$bbcode_tpl = null;
// BEGIN Local Links 1.0.0 (www.phpBBDoctor.com)
// This function is used to parse urls after the first pass processing.
// If the URL is "local" (as defined by having a link to a domain on
// the same server as that hosting this phpBB board) then the code that
// opens a new window (target="_blank") is removed. That way when someone
// links internally on your board it will preserve the session, and will
// NOT open a new window. I hate that. :-)  (www.phpBBDoctor.com)
function local_urls($text)
{
	global $board_config;

	// First build the match for local URL links. If you are running
	// multiple boards on the same server, and want different boards
	// to open in new windows even though they are on the same host
	// hardware, then use the optional line designated below instead.

	// Note: strtolower() is only used for comparison, the actual text
	// of the URL is not changed.
	$server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://';
	$server_port = (( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) : '') . '/';
	$server_name = strtolower($board_config['server_name']);
	$script_path = strtolower($board_config['script_path']);

	$local_url = '<a href="' . $server_protocol . $server_name . $server_port;
	// OPTIONAL
	// Use this line if you want to include the script path as well.
	// To use this line simply remove the two / from the beginning.
	//$local_url = '<a href="' . $server_protocol . $server_name . $server_port . $script_path;

	// Now look to see if that string is found in the text. Note that
	// the first step done (in other functions) before processing the
	// post text is to add one extra space, so we don't need to worry
	// about the case where a URL might be in the very first position.
	// It won't. :-)
	$start_url = strpos(strtolower($text), $local_url);

	while ($start_url)
	{
		// First identify the end of the URL by finding the >
		$last_found_pos = $start_url + 1;
		$end_url = strpos ($text, '>', $last_found_pos);
		$url_len = $end_url - $start_url + 1;

		// Next get a copy of the URL from <a href="... to closing >
		$my_url = substr($text, $start_url, $url_len);

		// replace target wtih null string
		$my_local_url = str_replace('target="_blank"', '', $my_url);

		// Replace old URL with new URL in post text. Note that while
		// the comparison was done in lower case via the strtolower()
		// function, the actual URL text is not changed in any way.
		// Only the target.
		$text = str_replace($my_url, $my_local_url, $text);

		// Advance by length of URL minus length of "target" string
		// and check for another local URL in the same post text.
		$start_url = strpos(strtolower($text), $local_url, $last_found_pos + $url_len - 16);
	}

	return $text;
}
// END Local Links 1.0.0 (www.phpBBDoctor.com)


// MULTI BBCODE-begin
function Multi_BBCode()
{
	global $template, $lang;

	// DO NOT CHANGE THIS ARRAY
	$hotkeys = array('', 'd', 'e', 'g', 'h', 'j', 'k', 'm', 'n', 'r', 't', 'v', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0');

	// NOTE: the first element of each array must be ''   Add new elements AFTER the ''
	$EMBB_widths = array('','50','60','50', '60','30','30','40','40','55','60','45','60','45','30') ;
	$EMBB_values = array('','Flash','YouTube', 'Footnote','s','ol','sup','sub','smcaps','reverse','area','spoiler','note','hr') ;
	
	$max_rows = ((count($EMBB_values)-1)/9) ;
	$max_rows = ($max_rows*9 == count($EMBB_values)) ? $max_rows : $max_rows+1 ;
	$code_count = 1 ;
	for($i = 1; $i <= $max_rows; $i++)
	{
		$template->assign_block_vars('BBCODE_ROW', array(
			'ROW_ID' => $i,
		));
		
		for($element = 0; $element < 9; $element++)
		{
			$val = ($code_count*2)+16;
			
			if ( $code_count < count($EMBB_values))
			{			
				$help_lang = ( !empty($lang['bbcode_help'][(strtolower($EMBB_values[$code_count]))]) ) ? $lang['bbcode_help'][(strtolower($EMBB_values[$code_count]))] : $lang['bbcode_help'][$EMBB_values[$code_count]];
				
				$template->assign_block_vars('BBCODE_ROW.BBCODE', array(
					'KEY'	=> $hotkeys[$code_count],
					'NAME'	=> "addbbcode$val",
					'HELP'	=> sprintf($help_lang, $hotkeys[$code_count]), 
					'WIDTH'	=> $EMBB_widths[$code_count],
					'VALUE'	=> $EMBB_values[$code_count],
					'STYLE'	=> "bbstyle($val)",
				));
			}
			
			$code_count++ ;
		}
	}
}
// MULTI BBCODE-end


/**
 * Loads bbcode templates from the bbcode.tpl file of the current template set.
 * Creates an array, keys are bbcode names like "b_open" or "url", values
 * are the associated template.
 * Probably pukes all over the place if there's something really screwed
 * with the bbcode.tpl file.
 *
 * Nathan Codding, Sept 26 2001.
 */
function load_bbcode_template()
{
	global $template;
	$tpl_filename = $template->make_filename('bbcode.tpl');
	$tpl = fread(fopen($tpl_filename, 'r'), filesize($tpl_filename));

	// replace \ with \\ and then ' with \'.
	$tpl = str_replace('\\', '\\\\', $tpl);
	$tpl  = str_replace('\'', '\\\'', $tpl);

	// strip newlines.
	$tpl  = str_replace("\n", '', $tpl);

	// Turn template blocks into PHP assignment statements for the values of $bbcode_tpls..
	$tpl = preg_replace('#<!-- BEGIN (.*?) -->(.*?)<!-- END (.*?) -->#', "\n" . '$bbcode_tpls[\'\\1\'] = \'\\2\';', $tpl);

	$bbcode_tpls = array();

	eval($tpl);

	return $bbcode_tpls;
}


/**
 * Prepares the loaded bbcode templates for insertion into preg_replace()
 * or str_replace() calls in the bbencode_second_pass functions. This
 * means replacing template placeholders with the appropriate preg backrefs
 * or with language vars. NOTE: If you change how the regexps work in
 * bbencode_second_pass(), you MUST change this function.
 *
 * Nathan Codding, Sept 26 2001
 *
 */
function prepare_bbcode_template($bbcode_tpl)
{
	global $lang;

	$bbcode_tpl['olist_open'] = str_replace('{LIST_TYPE}', '\\1', $bbcode_tpl['olist_open']);

	$bbcode_tpl['glow_open'] = str_replace('{GLOW}', '\\1', $bbcode_tpl['glow_open']);

	$bbcode_tpl['shadow_open'] = str_replace('{SHADOW}', '\\1', $bbcode_tpl['shadow_open']);

	$bbcode_tpl['color_open'] = str_replace('{COLOR}', '\\1', $bbcode_tpl['color_open']);

	$bbcode_tpl['size_open'] = str_replace('{SIZE}', '\\1', $bbcode_tpl['size_open']);

	$bbcode_tpl['quote_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_open']);

	$bbcode_tpl['quote_username_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_username_open']);
	$bbcode_tpl['quote_username_open'] = str_replace('{L_WROTE}', $lang['wrote'], $bbcode_tpl['quote_username_open']);
	$bbcode_tpl['quote_username_open'] = str_replace('{USERNAME}', '\\1', $bbcode_tpl['quote_username_open']);

	$bbcode_tpl['code_open'] = str_replace('{L_CODE}', $lang['Code'], $bbcode_tpl['code_open']);

	$bbcode_tpl['img'] = str_replace('{URL}', '\\1', $bbcode_tpl['img']);

	// We do URLs in several different ways..
	$bbcode_tpl['url1'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
	$bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url1']);

	$bbcode_tpl['url2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
	$bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']);

	$bbcode_tpl['url3'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
	$bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url3']);

	$bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
	$bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url4']);

	$bbcode_tpl['email'] = str_replace('{EMAIL}', '\\1', $bbcode_tpl['email']);
	// Begin Flash MOD
	$bbcode_tpl['flash'] = str_replace('{WIDTH}', '\\1', $bbcode_tpl['flash']);
	$bbcode_tpl['flash'] = str_replace('{HEIGHT}', '\\2', $bbcode_tpl['flash']);
	$bbcode_tpl['flash'] = str_replace('{LOOP}', '\\3', $bbcode_tpl['flash']);
	$bbcode_tpl['flash'] = str_replace('{URL}', '\\4', $bbcode_tpl['flash']);
	$bbcode_tpl['cf'] = str_replace('{URL}', '\\1', $bbcode_tpl['cf']);
	// End   Flash MOD
	// mod : Misc. BBcode : add
	
	// [area] and [/area] for borders/areas
	$bbcode_tpl['area1_open'] = str_replace('{AREA}', '\\1', $bbcode_tpl['area1_open']);
	
	// [note] and [/note] for putting notes in posts
	$bbcode_tpl['note'] = str_replace('{NOTE}', '\\1', $bbcode_tpl['note']);

	// [hr] and [/hr] for horizontal rules
	$bbcode_tpl['hr'] = str_replace('{HR}', '\\1', $bbcode_tpl['hr']);	
	
	// [font] and [/font] for changing the font
	$bbcode_tpl['font_open'] = str_replace('{FONT}', '\\1', $bbcode_tpl['font_open']);
	
	
	// mod : Misc. BBcode : end

                $bbcode_tpl['youtube'] = str_replace('{YOUTUBEID}', '\\1', $bbcode_tpl['youtube']);
                $bbcode_tpl['youtube'] = str_replace('{YOUTUBELINK}', $lang['youtube_link'], $bbcode_tpl['youtube']);


	// Align BBCode MOD
	$bbcode_tpl['align_open'] = str_replace('{ALIGN}', '\\1', $bbcode_tpl['align_open']);


	define("BBCODE_TPL_READY", true);

	return $bbcode_tpl;
}


/**
 * Does second-pass bbencoding. This should be used before displaying the message in
 * a thread. Assumes the message is already first-pass encoded, and we are given the
 * correct UID as used in first-pass encoding.
 */
function bbencode_second_pass($text, $uid)
{
	global $lang, $bbcode_tpl;

	$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1&#058;", $text);

	// pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
	// This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
	$text = " " . $text;

	// First: If there isn't a "[" and a "]" in the message, don't bother.
	if (! (strpos($text, "[") && strpos($text, "]")) )
	{
		// Remove padding, return.
		$text = substr($text, 1);
		return $text;
	}

	// Only load the templates ONCE..
	if (!defined("BBCODE_TPL_READY"))
	{
		// load templates from file into array.
		$bbcode_tpl = load_bbcode_template();

		// prepare array for use in regexps.
		$bbcode_tpl = prepare_bbcode_template($bbcode_tpl);
	}

	// [CODE] and 
for posting code (HTML, PHP, C etc etc) in your posts.
$text = bbencode_second_pass_code($text, $uid, $bbcode_tpl);

// [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
$text = bbencode_second_pass_quote($text, $uid, $bbcode_tpl);
// $text = str_replace("[quote:$uid]", $bbcode_tpl['quote_open'], $text);
// $text = str_replace("[/quote:$uid]", $bbcode_tpl['quote_close'], $text);

// New one liner to deal with opening quotes with usernames...
// replaces the two line version that I had here before..
$text = preg_replace("/\[quote:$uid=\"(.*?)\"\]/si", $bbcode_tpl['quote_username_open'], $text);

//
  • and
    • for (un)ordered lists.
      // unordered lists
      $text = str_replace("[list:$uid]", $bbcode_tpl['ulist_open'], $text);
      // li tags
      $text = str_replace("[*:$uid]", $bbcode_tpl['listitem'], $text);
      // ending tags
      $text = str_replace("[/list:u:$uid]", $bbcode_tpl['ulist_close'], $text);
      $text = str_replace("[/list:o:$uid]", $bbcode_tpl['olist_close'], $text);
      // Ordered lists
      $text = preg_replace("/\
      • ):$uid\]/si", $bbcode_tpl['olist_open'], $text);

        // glow
        $text = preg_replace("/\[glow=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['glow_open'], $text);
        $text = str_replace("[/glow:$uid]", $bbcode_tpl['glow_close'], $text);

        // shadow
        $text = preg_replace("/\[shadow=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['shadow_open'], $text);
        $text = str_replace("[/shadow:$uid]", $bbcode_tpl['shadow_close'], $text);


        // colours
        $text = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['color_open'], $text);
        $text = str_replace("[/color:$uid]", $bbcode_tpl['color_close'], $text);

        // size
        $text = preg_replace("/\[size=([1-2]?[0-9]):$uid\]/si", $bbcode_tpl['size_open'], $text);
        $text = str_replace("[/size:$uid]", $bbcode_tpl['size_close'], $text);

        // Align BBCode MOD
        $text = preg_replace("/\[align=(left|center|right):$uid\]/si", $bbcode_tpl['align_open'], $text);
        $text = str_replace("[/align:$uid]", $bbcode_tpl['align_close'], $text);


        // and for bolding text.
        $text = str_replace("[b:$uid]", $bbcode_tpl['b_open'], $text);
        $text = str_replace("[/b:$uid]", $bbcode_tpl['b_close'], $text);

        // and for underlining text.
        $text = str_replace("[u:$uid]", $bbcode_tpl['u_open'], $text);
        $text = str_replace("[/u:$uid]", $bbcode_tpl['u_close'], $text);

        // and for italicizing text.
        $text = str_replace("[i:$uid]", $bbcode_tpl['i_open'], $text);
        $text = str_replace("[/i:$uid]", $bbcode_tpl['i_close'], $text);

        // mod : Misc. BBcode : add

        // and for strikethrough text
        $text = str_replace("[s:$uid]", $bbcode_tpl['s_open'], $text);
        $text = str_replace("[/s:$uid]", $bbcode_tpl['s_close'], $text);

        // [ol] and [/ol] for overline text
        $text = str_replace("[ol:$uid]", $bbcode_tpl['ol_open'], $text);
        $text = str_replace("[/ol:$uid]", $bbcode_tpl['ol_close'], $text);

        // [sup] and [/sup] for superscript text
        $text = str_replace("[sup:$uid]", $bbcode_tpl['sup_open'], $text);
        $text = str_replace("[/sup:$uid]", $bbcode_tpl['sup_close'], $text);

        // [sub] and [/sub] for subscript text
        $text = str_replace("[sub:$uid]", $bbcode_tpl['sub_open'], $text);
        $text = str_replace("[/sub:$uid]", $bbcode_tpl['sub_close'], $text);

        // [smcaps] and [/smcaps] for small caps text
        $text = str_replace("[smcaps:$uid]", $bbcode_tpl['smcaps_open'], $text);
        $text = str_replace("[/smcaps:$uid]", $bbcode_tpl['smcaps_close'], $text);

        // [reverse] and [/reverse] for reversed text
        $text = str_replace("[reverse:$uid]", $bbcode_tpl['reverse_open'], $text);
        $text = str_replace("[/reverse:$uid]", $bbcode_tpl['reverse_close'], $text);

        // [area] and [/area] for borders/areas
        $text = str_replace("[area:$uid]", $bbcode_tpl['area_open'], $text);
        $text = str_replace("[/area:$uid]", $bbcode_tpl['area_close'], $text);

        // [area=] and [/area] for borders/areas
        $text = preg_replace("/\[area=(.*?):$uid\]/si", $bbcode_tpl['area1_open'], $text);
        $text = str_replace("[/area:$uid]", $bbcode_tpl['area1_close'], $text);

        // [spoiler] and [/spoiler] for marking possible spoilers
        $text = str_replace("[spoiler:$uid]", $bbcode_tpl['spoiler_open'], $text);
        $text = str_replace("[/spoiler:$uid]", $bbcode_tpl['spoiler_close'], $text);

        // [font] and [/font] for changing the font
        $text = preg_replace("/\[font=(Arial|Arial Black|Arial Narrow|Century Gothic|Comic Sans MS|Courier New|Georgia|Lucida Console|Lucida Handwriting|Microsoft Sans Serif|Symbol|Tahoma|Trebuchet MS|Times New Roman|Verdana):$uid\]/si", $bbcode_tpl['font_open'], $text);
        $text = str_replace("[/font:$uid]", $bbcode_tpl['font_close'], $text);


        // [align] and [/align] for changing the text alignment
        $text = preg_replace("/\[align=(left|right|center|justify):$uid\]/si", $bbcode_tpl['align_open'], $text);
        $text = str_replace("[/align:$uid]", $bbcode_tpl['align_close'], $text);


        // mod : Misc. BBcode : end

        // Patterns and replacements for URL and email tags..
        $patterns = array();
        $replacements = array();

        // [img]image_url_here[/img] code..
        // This one gets first-passed..
        $patterns[] = "#\[img:$uid\]([^?](?:[^\[]+|\[(?!url))*?)\[/img:$uid\]#i";
        $replacements[] = $bbcode_tpl['img'];

        // matches a [url]xxxx://www.phpbb.com[/url] code..
        $patterns[] = "#\[url\]([\w]+?://([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is";
        $replacements[] = $bbcode_tpl['url1'];

        // www.phpbb.com code.. (no xxxx:// prefix).
        $patterns[] = "#\[url\]((www|ftp)\.([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is";
        $replacements[] = $bbcode_tpl['url2'];

        // [url=xxxx://www.phpbb.com]phpBB[/url] code..
        $patterns[] = "#\+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";
        $replacements[] = $bbcode_tpl['url3'];

        // [url=www.phpbb.com]phpBB
        code.. (no xxxx:// prefix).
        $patterns[] = "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";
        $replacements[] = $bbcode_tpl['url4'];

        // user@domain.tld code..
        $patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si";
        $replacements[] = $bbcode_tpl['email'];
        // Begin Flash MOD
        //[flash width= height= loop= ]and[/flash]code..
        $patterns[] = "#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-5]?[0-9]?[0-9]) loop=(true|false):$uid\](.*?)\[/flash:$uid\]#si";
        $replacements[] = $bbcode_tpl[flash];
        //[flash]and[/flash]code..
        $patterns[] = "#\[flash:$uid\](.*?)\[/flash:$uid\]#si";
        $replacements[] = $bbcode_tpl[cf];
        // End Flash MOD

        // mod : Misc. BBcode : add

        // [note] and [/note] for putting notes in posts
        $patterns[] = "#\[note:$uid\](.*?)\[/note:$uid\]#i";
        $replacements[] = $bbcode_tpl['note'];

        // [hr] and [/hr] for horizontal rules
        $patterns[] = "#\[hr:$uid\]([0-9]?[0-9])\[/hr:$uid\]#i";
        $replacements[] = $bbcode_tpl['hr'];
        // mod : Misc. BBcode : end

        // code..
        $patterns[] = "#\[youtube\]http://(?:www\.)?youtube.com/watch\?v=([0-9A-Za-z-_]{11})[^[]*\[/youtube\]#is";
        $replacements[] = $bbcode_tpl['youtube'];



        $text = preg_replace($patterns, $replacements, $text);

        // BEGIN Local Links 1.0.0 (www.phpBBDoctor.com)
        $text = local_urls($text);
        // END Local Links 1.0.0 (www.phpBBDoctor.com)

        // Remove our padding from the string..
        $text = substr($text, 1);

        return $text;

        } // bbencode_second_pass()


        // Need to initialize the random numbers only ONCE
        mt_srand( (double) microtime() * 1000000);

        function make_bbcode_uid()
        {
        // Unique ID for this message..

        $uid = dss_rand();
        $uid = substr($uid, 0, BBCODE_UID_LEN);

        return $uid;
        }

        function bbencode_first_pass($text, $uid)
        {
        // pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
        // This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
        $text = " " . $text;

        //

        Code: Select all

         and 
        for posting code (HTML, PHP, C etc etc) in your posts.
        $text = bbencode_first_pass_pda($text, $uid, '

        Code: Select all

        ', '
        ', '', true, '');

        // [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
        $text = bbencode_first_pass_pda($text, $uid, '[quote]', '[/quote]', '', false, '');
        $text = bbencode_first_pass_pda($text, $uid, '/\[quote=\\\\"(.*?)\\\\"\]/is', '[/quote]', '', false, '', "[quote:$uid=\\\"\\1\\\"]");

        //
        • and
          • for (un)ordered lists.
            $open_tag = array();
            $open_tag[0] = "
            • ";

              // unordered..
              $text = bbencode_first_pass_pda($text, $uid, $open_tag, "
            ", "[/list:u]", false, 'replace_listitems');

            $open_tag[0] = "
            1. ";
              $open_tag[1] = "
              1. ";

                // ordered.
                $text = bbencode_first_pass_pda($text, $uid, $open_tag, "
              ", "[/list:o]", false, 'replace_listitems');

              // [glow] and [/glow] for setting glowing text
              $text = preg_replace("#\[glow=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/glow\]#si", "[glow=\\1:$uid]\\2[/glow:$uid]", $text);

              // [shadow] and [/shadow] for setting shadowing text
              $text = preg_replace("#\[shadow=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/shadow\]#si", "[shadow=\\1:$uid]\\2[/shadow:$uid]", $text);


              // [color] and [/color] for setting text color
              $text = preg_replace("#\[color=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]#si", "[color=\\1:$uid]\\2[/color:$uid]", $text);

              // [size] and [/size] for setting text size
              $text = preg_replace("#\[size=([1-2]?[0-9])\](.*?)\[/size\]#si", "[size=\\1:$uid]\\2[/size:$uid]", $text);
              // Align BBCode MOD - [align] [/align]
              $text = preg_replace("#\[align=(left|center|right)\](.*?)\[/align\]#si", "[align=\\1:$uid]\\2[/align:$uid]", $text);


              // [footnote] and [/footnote] for hiding spoiler text
              $text = preg_replace("#\[footnote\](.*?)\[/footnote\]#si", "[footnote:$uid]\\1[/footnote:$uid]", $text);


              // and for bolding text.
              $text = preg_replace("#\[b\](.*?)\[/b\]#si", "[b:$uid]\\1[/b:$uid]", $text);


              // and for underlining text.
              $text = preg_replace("#\[u\](.*?)\[/u\]#si", "[u:$uid]\\1[/u:$uid]", $text);

              // and for italicizing text.
              $text = preg_replace("#\[i\](.*?)\[/i\]#si", "[i:$uid]\\1[/i:$uid]", $text);

              // mod : Misc. BBcode : add

              // and for strikethrough text
              $text = preg_replace("#\[s\](.*?)\[/s\]#si", "[s:$uid]\\1[/s:$uid]", $text);

              // [ol] and [/ol] for overline text
              $text = preg_replace("#\[ol\](.*?)\[/ol\]#si", "[ol:$uid]\\1[/ol:$uid]", $text);

              // [sup] and [/sup] for superscript text
              $text = preg_replace("#\[sup\](.*?)\[/sup\]#si", "[sup:$uid]\\1[/sup:$uid]", $text);

              // [sub] and [/sub] for subscript text
              $text = preg_replace("#\[sub\](.*?)\[/sub\]#si", "[sub:$uid]\\1[/sub:$uid]", $text);

              // [smcaps] and [/smcaps] for small caps text
              $text = preg_replace("#\[smcaps\](.*?)\[/smcaps\]#si", "[smcaps:$uid]\\1[/smcaps:$uid]", $text);

              // [reverse] and [/reverse] for reversed text
              $text = preg_replace("#\[reverse\](.*?)\[/reverse\]#si", "[reverse:$uid]\\1[/reverse:$uid]", $text);

              // [area] and [/area] for borders/areas
              $text = preg_replace("#\[area\](.*?)\[/area\]#si", "[area:$uid]\\1[/area:$uid]", $text);

              // [area=] and [/area] for borders/areas
              $text = preg_replace("#\[area=(.*?)\](.*?)\[/area\]#si", "[area=\\1:$uid]\\2[/area:$uid]", $text);

              // [spoiler] and [/spoiler] for marking possible spoilers
              $text = preg_replace("#\[spoiler\](.*?)\[/spoiler\]#si", "[spoiler:$uid]\\1[/spoiler:$uid]", $text);

              // [note] and [/note] for putting notes in posts
              $text = preg_replace("#\[note\](.*?)\[/note\]#si", "[note:$uid]\\1[/note:$uid]", $text);

              // [hr] and [/hr] for horizontal rules
              $text = preg_replace("#\[hr\]([0-9]?[0-9])\[/hr\]#si", "[hr:$uid]\\1[/hr:$uid]", $text);

              // [font] and [/font] for changing the font
              $text = preg_replace("#\[font=(Arial|Arial Black|Arial Narrow|Century Gothic|Comic Sans MS|Courier New|Georgia|Lucida Console|Lucida Handwriting|Microsoft Sans Serif|Symbol|Tahoma|Trebuchet MS|Times New Roman|Verdana)\](.*?)\[/font\]#si", "[font=\\1:$uid]\\2[/font:$uid]", $text);


              // [align] and [/align] for changing the text alignment
              $text = preg_replace("#\[align=(left|right|center|justify)\](.*?)\[/align\]#si", "[align=\\1:$uid]\\2[/align:$uid]", $text);


              // mod : Misc. BBcode : end

              // [img]image_url_here[/img] code..
              $text = preg_replace("#\[img\]((http|ftp|https|ftps)://)([^ \?&=\#\"\n\r\t<]*?(\.(jpg|jpeg|gif|png)))\[/img\]#sie", "'[img:$uid]\\1' . str_replace(' ', '%20', '\\3') . '[/img:$uid]'", $text);
              // Begin Flash MOD
              //[flash width= heigth= loop=] and[ /flash ]
              $text = preg_replace("#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-5]?[0-9]) loop=(true|false)\](([a-z]+?)://([^, \n\r]+))\[\/flash\]#si","[flash width=\\1 height=\\2 loop=\\3:$uid\]\\4[/flash:$uid]", $text);
              $text = preg_replace("#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-5]?[0-9])\](([a-z]+?)://([^, \n\r]+))\[\/flash\]#si","[flash width=\\1 height=\\2 loop=false:$uid\]\\3[/flash:$uid]", $text);
              $text = preg_replace("#\[flash\](([a-z]+?)://([^, \n\r]+))\[\/flash\]#si","[flash:$uid\]\\1[/flash:$uid]", $text);
              // End Flash MOD



              // Remove our padding from the string..
              return substr($text, 1);;

              } // bbencode_first_pass()

              /**
              * $text - The text to operate on.
              * $uid - The UID to add to matching tags.
              * $open_tag - The opening tag to match. Can be an array of opening tags.
              * $close_tag - The closing tag to match.
              * $close_tag_new - The closing tag to replace with.
              * $mark_lowest_level - boolean - should we specially mark the tags that occur
              * at the lowest level of nesting? (useful for

              Code: Select all

              , because
               *						we need to match these tags first and transform HTML tags
               *						in their contents..
               * $func - This variable should contain a string that is the name of a function.
               *				That function will be called when a match is found, and passed 2
               *				parameters: ($text, $uid). The function should return a string.
               *				This is used when some transformation needs to be applied to the
               *				text INSIDE a pair of matching tags. If this variable is FALSE or the
               *				empty string, it will not be executed.
               * If open_tag is an array, then the pda will try to match pairs consisting of
               * any element of open_tag followed by close_tag. This allows us to match things
               * like [list=A]...[/list] and [list=1]...[/list] in one pass of the PDA.
               *
               * NOTES:	- this function assumes the first character of $text is a space.
               *				- every opening tag and closing tag must be of the [...] format.
               */
              function bbencode_first_pass_pda($text, $uid, $open_tag, $close_tag, $close_tag_new, $mark_lowest_level, $func, $open_regexp_replace = false)
              {
              	$open_tag_count = 0;
              
              	if (!$close_tag_new || ($close_tag_new == ''))
              	{
              		$close_tag_new = $close_tag;
              	}
              
              	$close_tag_length = strlen($close_tag);
              	$close_tag_new_length = strlen($close_tag_new);
              	$uid_length = strlen($uid);
              
              	$use_function_pointer = ($func && ($func != ''));
              
              	$stack = array();
              
              	if (is_array($open_tag))
              	{
              		if (0 == count($open_tag))
              		{
              			// No opening tags to match, so return.
              			return $text;
              		}
              		$open_tag_count = count($open_tag);
              	}
              	else
              	{
              		// only one opening tag. make it into a 1-element array.
              		$open_tag_temp = $open_tag;
              		$open_tag = array();
              		$open_tag[0] = $open_tag_temp;
              		$open_tag_count = 1;
              	}
              
              	$open_is_regexp = false;
              
              	if ($open_regexp_replace)
              	{
              		$open_is_regexp = true;
              		if (!is_array($open_regexp_replace))
              		{
              			$open_regexp_temp = $open_regexp_replace;
              			$open_regexp_replace = array();
              			$open_regexp_replace[0] = $open_regexp_temp;
              		}
              	}
              
              	if ($mark_lowest_level && $open_is_regexp)
              	{
              		message_die(GENERAL_ERROR, "Unsupported operation for bbcode_first_pass_pda().");
              	}
              
              	// Start at the 2nd char of the string, looking for opening tags.
              	$curr_pos = 1;
              	while ($curr_pos && ($curr_pos < strlen($text)))
              	{
              		$curr_pos = strpos($text, "[", $curr_pos);
              
              		// If not found, $curr_pos will be 0, and the loop will end.
              		if ($curr_pos)
              		{
              			// We found a [. It starts at $curr_pos.
              			// check if it's a starting or ending tag.
              			$found_start = false;
              			$which_start_tag = "";
              			$start_tag_index = -1;
              
              			for ($i = 0; $i < $open_tag_count; $i++)
              			{
              				// Grab everything until the first "]"...
              				$possible_start = substr($text, $curr_pos, strpos($text, ']', $curr_pos + 1) - $curr_pos + 1);
              
              				//
              				// We're going to try and catch usernames with "[' characters.
              				//
              				if( preg_match('#\[quote=\\\"#si', $possible_start, $match) && !preg_match('#\[quote=\\\"(.*?)\\\"\]#si', $possible_start) )
              				{
              					// OK we are in a quote tag that probably contains a ] bracket.
              					// Grab a bit more of the string to hopefully get all of it..
              					if ($close_pos = strpos($text, '"]', $curr_pos + 14))
              					{
              						if (strpos(substr($text, $curr_pos + 14, $close_pos - ($curr_pos + 14)), '[quote') === false)
              						{
              							$possible_start = substr($text, $curr_pos, $close_pos - $curr_pos + 7);
              						}
              					}
              				}
              
              				// Now compare, either using regexp or not.
              				if ($open_is_regexp)
              				{
              					$match_result = array();
              					if (preg_match($open_tag[$i], $possible_start, $match_result))
              					{
              						$found_start = true;
              						$which_start_tag = $match_result[0];
              						$start_tag_index = $i;
              						break;
              					}
              				}
              				else
              				{
              					// straightforward string comparison.
              					if (0 == strcasecmp($open_tag[$i], $possible_start))
              					{
              						$found_start = true;
              						$which_start_tag = $open_tag[$i];
              						$start_tag_index = $i;
              						break;
              					}
              				}
              			}
              
              			if ($found_start)
              			{
              				// We have an opening tag.
              				// Push its position, the text we matched, and its index in the open_tag array on to the stack, and then keep going to the right.
              				$match = array("pos" => $curr_pos, "tag" => $which_start_tag, "index" => $start_tag_index);
              				array_push($stack, $match);
              				//
              				// Rather than just increment $curr_pos
              				// Set it to the ending of the tag we just found
              				// Keeps error in nested tag from breaking out
              				// of table structure..
              				//
              				$curr_pos += strlen($possible_start);
              			}
              			else
              			{
              				// check for a closing tag..
              				$possible_end = substr($text, $curr_pos, $close_tag_length);
              				if (0 == strcasecmp($close_tag, $possible_end))
              				{
              					// We have an ending tag.
              					// Check if we've already found a matching starting tag.
              					if (sizeof($stack) > 0)
              					{
              						// There exists a starting tag.
              						$curr_nesting_depth = sizeof($stack);
              						// We need to do 2 replacements now.
              						$match = array_pop($stack);
              						$start_index = $match['pos'];
              						$start_tag = $match['tag'];
              						$start_length = strlen($start_tag);
              						$start_tag_index = $match['index'];
              
              						if ($open_is_regexp)
              						{
              							$start_tag = preg_replace($open_tag[$start_tag_index], $open_regexp_replace[$start_tag_index], $start_tag);
              						}
              
              						// everything before the opening tag.
              						$before_start_tag = substr($text, 0, $start_index);
              
              						// everything after the opening tag, but before the closing tag.
              						$between_tags = substr($text, $start_index + $start_length, $curr_pos - $start_index - $start_length);
              
              						// Run the given function on the text between the tags..
              						if ($use_function_pointer)
              						{
              							$between_tags = $func($between_tags, $uid);
              						}
              
              						// everything after the closing tag.
              						$after_end_tag = substr($text, $curr_pos + $close_tag_length);
              
              						// Mark the lowest nesting level if needed.
              						if ($mark_lowest_level && ($curr_nesting_depth == 1))
              						{
              							if ($open_tag[0] == '[code]')
              							{
              								$code_entities_match = array('#<#', '#>#', '#"#', '#:#', '#\[#', '#\]#', '#\(#', '#\)#', '#\{#', '#\}#');
              								$code_entities_replace = array('<', '>', '"', '&#58;', '&#91;', '&#93;', '&#40;', '&#41;', '&#123;', '&#125;');
              								$between_tags = preg_replace($code_entities_match, $code_entities_replace, $between_tags);
              							}
              							$text = $before_start_tag . substr($start_tag, 0, $start_length - 1) . ":$curr_nesting_depth:$uid]";
              							$text .= $between_tags . substr($close_tag_new, 0, $close_tag_new_length - 1) . ":$curr_nesting_depth:$uid]";
              						}
              						else
              						{
              							if ($open_tag[0] == '[code]')
              							{
              								$text = $before_start_tag . '&#91;code&#93;';
              								$text .= $between_tags . '&#91;/code&#93;';
              							}
              							else
              							{
              								if ($open_is_regexp)
              								{
              									$text = $before_start_tag . $start_tag;
              								}
              								else
              								{
              									$text = $before_start_tag . substr($start_tag, 0, $start_length - 1) . ":$uid]";
              								}
              								$text .= $between_tags . substr($close_tag_new, 0, $close_tag_new_length - 1) . ":$uid]";
              							}
              						}
              
              						$text .= $after_end_tag;
              
              						// Now.. we've screwed up the indices by changing the length of the string.
              						// So, if there's anything in the stack, we want to resume searching just after it.
              						// otherwise, we go back to the start.
              						if (sizeof($stack) > 0)
              						{
              							$match = array_pop($stack);
              							$curr_pos = $match['pos'];
              //							bbcode_array_push($stack, $match);
              //							++$curr_pos;
              						}
              						else
              						{
              							$curr_pos = 1;
              						}
              					}
              					else
              					{
              						// No matching start tag found. Increment pos, keep going.
              						++$curr_pos;
              					}
              				}
              				else
              				{
              					// No starting tag or ending tag.. Increment pos, keep looping.,
              					++$curr_pos;
              				}
              			}
              		}
              	} // while
              
              	return $text;
              
              } // bbencode_first_pass_pda()
              
              /**
               * Does second-pass bbencoding of the [code] tags. This includes
               * running htmlspecialchars() over the text contained between
               * any pair of [code] tags that are at the first level of
               * nesting. Tags at the first level of nesting are indicated
               * by this format: [code:1:$uid] ... [/code:1:$uid]
               * Other tags are in this format: [code:$uid] ... [/code:$uid]
               */
              function bbencode_second_pass_code($text, $uid, $bbcode_tpl)
              {
              	global $lang;
              
              	$code_start_html = $bbcode_tpl['code_open'];
              	$code_end_html =  $bbcode_tpl['code_close'];
              
              	// First, do all the 1st-level matches. These need an htmlspecialchars() run,
              	// so they have to be handled differently.
              	$match_count = preg_match_all("#\[code:1:$uid\](.*?)\[/code:1:$uid\]#si", $text, $matches);
              
              	for ($i = 0; $i < $match_count; $i++)
              	{
              		$before_replace = $matches[1][$i];
              		$after_replace = $matches[1][$i];
              
              		// Replace 2 spaces with "&nbsp; " so non-tabbed code indents without making huge long lines.
              		$after_replace = str_replace("  ", "&nbsp; ", $after_replace);
              		// now Replace 2 spaces with " &nbsp;" to catch odd #s of spaces.
              		$after_replace = str_replace("  ", " &nbsp;", $after_replace);
              
              		// Replace tabs with "&nbsp; &nbsp;" so tabbed code indents sorta right without making huge long lines.
              		$after_replace = str_replace("\t", "&nbsp; &nbsp;", $after_replace);
              
              		// now Replace space occurring at the beginning of a line
              		$after_replace = preg_replace("/^ {1}/m", '&nbsp;', $after_replace);
              
              		$str_to_match = "[code:1:$uid]" . $before_replace . "[/code:1:$uid]";
              
              		$replacement = $code_start_html;
              		$replacement .= $after_replace;
              		$replacement .= $code_end_html;
              
              		$text = str_replace($str_to_match, $replacement, $text);
              	}
              
              	// Now, do all the non-first-level matches. These are simple.
              	$text = str_replace("[code:$uid]", $code_start_html, $text);
              	$text = str_replace("[/code:$uid]", $code_end_html, $text);
              
              	return $text;
              
              } // bbencode_second_pass_code()
              
              /**
               * Does second-pass bbencoding of the [quote] tags. This includes
               * seperating out any [footnote] tags there may be in any pair of 
               * [quote] tags.
               */
              function bbencode_second_pass_quote($text, $uid, $bbcode_tpl)
              {
              	// determine if any quotes are in the text a make nda recursive call on it if there is
              	preg_match("#\[quote:$uid(=\".*\")?\](.*?)\[/quote:$uid\]#si", substr($text, 1), $match);
              
              	if( $match[0] )
              	{
              		$start_pos = strpos($text, $match[0], 1);
              		$text = substr($text, 0, $start_pos) . bbencode_second_pass_quote(substr($text, $start_pos), $uid, $bbcode_tpl);
              	}
              	
              	$end_text = "";
              	$end_pos = strpos($text, "[/quote:$uid]");
              	
              	
              	// select just the quote itself and strip the closing quote tag (if there is a quote in the text)
              	if( $end_pos )
              	{
              		$end_text = substr($text, ($end_pos + strlen("[/quote:$uid]")));
              		$text = substr($text, 0, ($end_pos + strlen("[/quote:$uid]")));
              		
              		$text = str_replace("[/quote:$uid]", "", $text);
              
              	}
              
              	// [footnote] and [/footnote] for hiding spoiler text
              	preg_match_all("#\[footnote:$uid\](.*?)\[/footnote:$uid\]#si", $text, $footnotes, PREG_PATTERN_ORDER);
              	
              	if(count($footnotes[1]) != 0)
              	{
              		$count = 1;
              		$text .= $bbcode_tpl['footnote_open'];
              	
              		foreach($footnotes[1] as $key => $note)
              		{
              			$text = str_replace($footnotes[0][$key], $bbcode_tpl['super_open'].$count.$bbcode_tpl['super_close'], $text);
              			$text .= "<br />".$bbcode_tpl['super_open'].$count.$bbcode_tpl['super_close']." ".$note;
              			$count++;
              		}
              
              		$text .= $bbcode_tpl['footnote_close'];
              	}
              
              	// add the closing quote tag again (if this was a quote)
              	if( $end_pos )
              	{
              		$text .= $bbcode_tpl['quote_close'];
              	}
              	
              	// substiture the opening quote tag with the correct template code
              	$text = str_replace("[quote:$uid]", $bbcode_tpl['quote_open'], $text);
              	$text = preg_replace("/\[quote:$uid=\"(.*?)\"\]/si", $bbcode_tpl['quote_username_open'], $text);
              
              	// place the quote back into the main text
              	$text .= $end_text;
              
              	return $text;
              }
              
              /**
               * Rewritten by Nathan Codding - Feb 6, 2001.
               * - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking
               * 	to that URL
               * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking
               * 	to http://www.xxxx.yyyy[/zzzz]
               * - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking
               *		to that email address
               * - Only matches these 2 patterns either after a space, or at the beginning of a line
               *
               * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe
               * have it require something like xxxx@yyyy.zzzz or such. We'll see.
               */
              function make_clickable($text)
              {
              	$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1&#058;", $text);
              
              	// pad it with a space so we can match things at the start of the 1st line.
              	$ret = ' ' . $text;
              
              	// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
              	// xxxx can only be alpha characters.
              	// yyyy is anything up to the first space, newline, comma, double quote or <
              	$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
              
              	// matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
              	// Must contain at least 2 dots. xxxx contains either alphanum, or "-"
              	// zzzz is optional.. will contain everything up to the first space, newline, 
              	// comma, double quote or <.
              	$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
              	
              	// matches an email@domain type address at the start of a line, or after a space.
              	// Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
                    $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
              	
              
              // BEGIN Local Links 1.0.0 (www.phpBBDoctor.com)
              	$ret = local_urls ($ret);
              	// END Local Links 1.0.0 (www.phpBBDoctor.com)
              
              	// Remove our padding..
              	$ret = substr($ret, 1);
              
              	return($ret);
              }
              
              /**
               * Chunk long urls to avoid page stretching. This function splits a
               * long url into chunks, then glues it back together with a couple
               * of dots. This gaggle of code could be boiled down to fewer lines,
               * but it would make it hard to read.
               */
              function chunk_url(&$ret)
              {
                 /**
                  * Split the string into an array. Then loop through
                  * the array and process each link separately.
                  */
                 $links = explode('<a', $ret);
                 $countlinks = count($links);
                 for ($i = 0; $i < $countlinks; $i++)
                 {
                    $link = $links[$i];
              
                    /**
                     * If the array element is a hyperlink then put the missing
                     * '<a' back in, as we will not be imploding...
                     */
                    $link = (preg_match('#(.*)(href=")#is', $link)) ? '<a' . $link : $link;
              
                    $begin = strpos($link, '>') + 1;
                    $end = strpos($link, '<', $begin);
                    $length = $end - $begin;
                    $urlname = substr($link, $begin, $length);
              
                    /**
                     * We chunk urls that are longer than 50 characters. Just change
                     * '50' to a value that suits your taste. We are not chunking the link
                     * text unless if begins with 'http://', 'ftp://', or 'www.'
                     */
                    $shorturlname = (strlen($urlname) > 50 && preg_match('#^(http://|ftp://|www\.)#is', $urlname)) ? substr_replace($urlname, '.....', 30, -10) : $urlname;
                    $ret = str_replace('>' . $urlname . '<', '>' . $shorturlname . '<', $ret);
                 }
              }
              
              
              /**
               * Nathan Codding - Feb 6, 2001
               * Reverses the effects of make_clickable(), for use in editpost.
               * - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs.
               *
               */
              function undo_make_clickable($text)
              {
              	$text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text);
              	$text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text);
              
              	return $text;
              
              }
              
              /**
               * Nathan Codding - August 24, 2000.
               * Takes a string, and does the reverse of the PHP standard function
               * htmlspecialchars().
               */
              function undo_htmlspecialchars($input)
              {
              	$input = preg_replace("/>/i", ">", $input);
              	$input = preg_replace("/</i", "<", $input);
              	$input = preg_replace("/"/i", "\"", $input);
              	$input = preg_replace("/&/i", "&", $input);
              
              	return $input;
              }
              
              /**
               * This is used to change a [*] tag into a [*:$uid] tag as part
               * of the first-pass bbencoding of [list] tags. It fits the
               * standard required in order to be passed as a variable
               * function into bbencode_first_pass_pda().
               */
              function replace_listitems($text, $uid)
              {
              	$text = str_replace("[*]", "[*:$uid]", $text);
              
              	return $text;
              }
              
              /**
               * Escapes the "/" character with "\/". This is useful when you need
               * to stick a runtime string into a PREG regexp that is being delimited
               * with slashes.
               */
              function escape_slashes($input)
              {
              	$output = str_replace('/', '\/', $input);
              	return $output;
              }
              
              /**
               * This function does exactly what the PHP4 function array_push() does
               * however, to keep phpBB compatable with PHP 3 we had to come up with our own
               * method of doing it.
               * This function was deprecated in phpBB 2.0.18
               */
              function bbcode_array_push(&$stack, $value)
              {
                 $stack[] = $value;
                 return(sizeof($stack));
              }
              
              /**
               * This function does exactly what the PHP4 function array_pop() does
               * however, to keep phpBB compatable with PHP 3 we had to come up with our own
               * method of doing it.
               * This function was deprecated in phpBB 2.0.18
               */
              function bbcode_array_pop(&$stack)
              {
                 $arrSize = count($stack);
                 $x = 1;
              
                 while(list($key, $val) = each($stack))
                 {
                    if($x < count($stack))
                    {
              	 		$tmpArr[] = $val;
                    }
                    else
                    {
              	 		$return_val = $val;
                    }
                    $x++;
                 }
                 $stack = $tmpArr;
              
                 return($return_val);
              }
              
              //
              // Smilies code ... would this be better tagged on to the end of bbcode.php?
              // Probably so and I'll move it before B2
              //
              function smilies_pass($message)
              {
              	static $orig, $repl;
              
              	if (!isset($orig))
              	{
              		global $db, $board_config;
              		$orig = $repl = array();
              
              		$sql = 'SELECT * FROM ' . SMILIES_TABLE;
              		if( !$result = $db->sql_query($sql) )
              		{
              			message_die(GENERAL_ERROR, "Couldn't obtain smilies data", "", __LINE__, __FILE__, $sql);
              		}
              		$smilies = $db->sql_fetchrowset($result);
              
              		if (count($smilies))
              		{
              			usort($smilies, 'smiley_sort');
              		}
              
              		for ($i = 0; $i < count($smilies); $i++)
              		{
              			$orig[] = "/(?<=.\W|\W.|^\W)" . preg_quote($smilies[$i]['code'], "/") . "(?=.\W|\W.|\W$)/";
              			$repl[] = '<img src="'. $board_config['smilies_path'] . '/' . $smilies[$i]['smile_url'] . '" alt="' . $smilies[$i]['emoticon'] . '" border="0" />';
              		}
              	}
              
              	if (count($orig))
              	{
              		$message = preg_replace($orig, $repl, ' ' . $message . ' ');
              		$message = substr($message, 1, -1);
              	}
              	
              	return $message;
              }
              
              ?>
              
              Anyone help?
http://www.nwcpnefc.co.uk for PNE Fans in North Wales and Cheshire, but we welcome all, including fans from other clubs.
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Re: [BETA] Smiley management

Post by Merlin Sythove »

NWCPNE1 wrote:Getting a New Error now, Easy mod won't go back so my whole forum has been killed.

Error Message
Warning: usort() [function.usort]: Invalid comparison function in /homer/nwcpne/public_html/forum/includes/bbcode.php on line 1178
I'm not surprised because your second post above already indicated that you had made serious mistakes in implementing the mod. This is my third and last offer: I've given you a checklist. I suggest you start by putting your backed up files back, and start from scratch, using the checklist I gave you about installing the mod, to wit: use Easymod, and if you can't or won't, triple check everything you do. If you still get errors, supply the required information as I specified above.
Need custom work done? Pimp My Forum!
NWCPNE1
Registered User
Posts: 222
Joined: Sat Feb 02, 2008 8:28 pm

Re: [BETA] Smiley management

Post by NWCPNE1 »

I getting the same error when Easy mods puts the files back. So I have put them back again and the errors are still there, the forum was fine until this mod.

Code: Select all

<?php
/***************************************************************************
 *                              bbcode.php
 *                            -------------------
 *   begin                : Saturday, Feb 13, 2001
 *   copyright            : (C) 2001 The phpBB Group
 *   email                : support@phpbb.com
 *
 *   $Id: bbcode.php,v 1.36.2.41 2006/02/26 17:34:50 grahamje Exp $
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

if ( !defined('IN_PHPBB') )
{
	die("Hacking attempt");
}

define("BBCODE_UID_LEN", 10);

// global that holds loaded-and-prepared bbcode templates, so we only have to do
// that stuff once.

$bbcode_tpl = null;
// BEGIN Local Links 1.0.0 (www.phpBBDoctor.com)
// This function is used to parse urls after the first pass processing.
// If the URL is "local" (as defined by having a link to a domain on
// the same server as that hosting this phpBB board) then the code that
// opens a new window (target="_blank") is removed. That way when someone
// links internally on your board it will preserve the session, and will
// NOT open a new window. I hate that. :-)  (www.phpBBDoctor.com)
function local_urls($text)
{
	global $board_config;

	// First build the match for local URL links. If you are running
	// multiple boards on the same server, and want different boards
	// to open in new windows even though they are on the same host
	// hardware, then use the optional line designated below instead.

	// Note: strtolower() is only used for comparison, the actual text
	// of the URL is not changed.
	$server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://';
	$server_port = (( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) : '') . '/';
	$server_name = strtolower($board_config['server_name']);
	$script_path = strtolower($board_config['script_path']);

	$local_url = '<a href="' . $server_protocol . $server_name . $server_port;
	// OPTIONAL
	// Use this line if you want to include the script path as well.
	// To use this line simply remove the two / from the beginning.
	//$local_url = '<a href="' . $server_protocol . $server_name . $server_port . $script_path;

	// Now look to see if that string is found in the text. Note that
	// the first step done (in other functions) before processing the
	// post text is to add one extra space, so we don't need to worry
	// about the case where a URL might be in the very first position.
	// It won't. :-)
	$start_url = strpos(strtolower($text), $local_url);

	while ($start_url)
	{
		// First identify the end of the URL by finding the >
		$last_found_pos = $start_url + 1;
		$end_url = strpos ($text, '>', $last_found_pos);
		$url_len = $end_url - $start_url + 1;

		// Next get a copy of the URL from <a href="... to closing >
		$my_url = substr($text, $start_url, $url_len);

		// replace target wtih null string
		$my_local_url = str_replace('target="_blank"', '', $my_url);

		// Replace old URL with new URL in post text. Note that while
		// the comparison was done in lower case via the strtolower()
		// function, the actual URL text is not changed in any way.
		// Only the target.
		$text = str_replace($my_url, $my_local_url, $text);

		// Advance by length of URL minus length of "target" string
		// and check for another local URL in the same post text.
		$start_url = strpos(strtolower($text), $local_url, $last_found_pos + $url_len - 16);
	}

	return $text;
}
// END Local Links 1.0.0 (www.phpBBDoctor.com)


// MULTI BBCODE-begin
function Multi_BBCode()
{
	global $template, $lang;

	// DO NOT CHANGE THIS ARRAY
	$hotkeys = array('', 'd', 'e', 'g', 'h', 'j', 'k', 'm', 'n', 'r', 't', 'v', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0');

	// NOTE: the first element of each array must be ''   Add new elements AFTER the ''
	$EMBB_widths = array('','50','60','50', '60','30','30','40','40','55','60','45','60','45','30') ;
	$EMBB_values = array('','Flash','YouTube', 'Footnote','s','ol','sup','sub','smcaps','reverse','area','spoiler','note','hr') ;
	
	$max_rows = ((count($EMBB_values)-1)/9) ;
	$max_rows = ($max_rows*9 == count($EMBB_values)) ? $max_rows : $max_rows+1 ;
	$code_count = 1 ;
	for($i = 1; $i <= $max_rows; $i++)
	{
		$template->assign_block_vars('BBCODE_ROW', array(
			'ROW_ID' => $i,
		));
		
		for($element = 0; $element < 9; $element++)
		{
			$val = ($code_count*2)+16;
			
			if ( $code_count < count($EMBB_values))
			{			
				$help_lang = ( !empty($lang['bbcode_help'][(strtolower($EMBB_values[$code_count]))]) ) ? $lang['bbcode_help'][(strtolower($EMBB_values[$code_count]))] : $lang['bbcode_help'][$EMBB_values[$code_count]];
				
				$template->assign_block_vars('BBCODE_ROW.BBCODE', array(
					'KEY'	=> $hotkeys[$code_count],
					'NAME'	=> "addbbcode$val",
					'HELP'	=> sprintf($help_lang, $hotkeys[$code_count]), 
					'WIDTH'	=> $EMBB_widths[$code_count],
					'VALUE'	=> $EMBB_values[$code_count],
					'STYLE'	=> "bbstyle($val)",
				));
			}
			
			$code_count++ ;
		}
	}
}
// MULTI BBCODE-end


/**
 * Loads bbcode templates from the bbcode.tpl file of the current template set.
 * Creates an array, keys are bbcode names like "b_open" or "url", values
 * are the associated template.
 * Probably pukes all over the place if there's something really screwed
 * with the bbcode.tpl file.
 *
 * Nathan Codding, Sept 26 2001.
 */
function load_bbcode_template()
{
	global $template;
	$tpl_filename = $template->make_filename('bbcode.tpl');
	$tpl = fread(fopen($tpl_filename, 'r'), filesize($tpl_filename));

	// replace \ with \\ and then ' with \'.
	$tpl = str_replace('\\', '\\\\', $tpl);
	$tpl  = str_replace('\'', '\\\'', $tpl);

	// strip newlines.
	$tpl  = str_replace("\n", '', $tpl);

	// Turn template blocks into PHP assignment statements for the values of $bbcode_tpls..
	$tpl = preg_replace('#<!-- BEGIN (.*?) -->(.*?)<!-- END (.*?) -->#', "\n" . '$bbcode_tpls[\'\\1\'] = \'\\2\';', $tpl);

	$bbcode_tpls = array();

	eval($tpl);

	return $bbcode_tpls;
}


/**
 * Prepares the loaded bbcode templates for insertion into preg_replace()
 * or str_replace() calls in the bbencode_second_pass functions. This
 * means replacing template placeholders with the appropriate preg backrefs
 * or with language vars. NOTE: If you change how the regexps work in
 * bbencode_second_pass(), you MUST change this function.
 *
 * Nathan Codding, Sept 26 2001
 *
 */
function prepare_bbcode_template($bbcode_tpl)
{
	global $lang;

	$bbcode_tpl['olist_open'] = str_replace('{LIST_TYPE}', '\\1', $bbcode_tpl['olist_open']);

	$bbcode_tpl['glow_open'] = str_replace('{GLOW}', '\\1', $bbcode_tpl['glow_open']);

	$bbcode_tpl['shadow_open'] = str_replace('{SHADOW}', '\\1', $bbcode_tpl['shadow_open']);

	$bbcode_tpl['color_open'] = str_replace('{COLOR}', '\\1', $bbcode_tpl['color_open']);

	$bbcode_tpl['size_open'] = str_replace('{SIZE}', '\\1', $bbcode_tpl['size_open']);

	$bbcode_tpl['quote_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_open']);

	$bbcode_tpl['quote_username_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_username_open']);
	$bbcode_tpl['quote_username_open'] = str_replace('{L_WROTE}', $lang['wrote'], $bbcode_tpl['quote_username_open']);
	$bbcode_tpl['quote_username_open'] = str_replace('{USERNAME}', '\\1', $bbcode_tpl['quote_username_open']);

	$bbcode_tpl['code_open'] = str_replace('{L_CODE}', $lang['Code'], $bbcode_tpl['code_open']);

	$bbcode_tpl['img'] = str_replace('{URL}', '\\1', $bbcode_tpl['img']);

	// We do URLs in several different ways..
	$bbcode_tpl['url1'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
	$bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url1']);

	$bbcode_tpl['url2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
	$bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']);

	$bbcode_tpl['url3'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
	$bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url3']);

	$bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
	$bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url4']);

	$bbcode_tpl['email'] = str_replace('{EMAIL}', '\\1', $bbcode_tpl['email']);
	// Begin Flash MOD
	$bbcode_tpl['flash'] = str_replace('{WIDTH}', '\\1', $bbcode_tpl['flash']);
	$bbcode_tpl['flash'] = str_replace('{HEIGHT}', '\\2', $bbcode_tpl['flash']);
	$bbcode_tpl['flash'] = str_replace('{LOOP}', '\\3', $bbcode_tpl['flash']);
	$bbcode_tpl['flash'] = str_replace('{URL}', '\\4', $bbcode_tpl['flash']);
	$bbcode_tpl['cf'] = str_replace('{URL}', '\\1', $bbcode_tpl['cf']);
	// End   Flash MOD
	// mod : Misc. BBcode : add
	
	// [area] and [/area] for borders/areas
	$bbcode_tpl['area1_open'] = str_replace('{AREA}', '\\1', $bbcode_tpl['area1_open']);
	
	// [note] and [/note] for putting notes in posts
	$bbcode_tpl['note'] = str_replace('{NOTE}', '\\1', $bbcode_tpl['note']);

	// [hr] and [/hr] for horizontal rules
	$bbcode_tpl['hr'] = str_replace('{HR}', '\\1', $bbcode_tpl['hr']);	
	
	// [font] and [/font] for changing the font
	$bbcode_tpl['font_open'] = str_replace('{FONT}', '\\1', $bbcode_tpl['font_open']);
	
	
	// mod : Misc. BBcode : end

                $bbcode_tpl['youtube'] = str_replace('{YOUTUBEID}', '\\1', $bbcode_tpl['youtube']);
                $bbcode_tpl['youtube'] = str_replace('{YOUTUBELINK}', $lang['youtube_link'], $bbcode_tpl['youtube']);


	// Align BBCode MOD
	$bbcode_tpl['align_open'] = str_replace('{ALIGN}', '\\1', $bbcode_tpl['align_open']);


	define("BBCODE_TPL_READY", true);

	return $bbcode_tpl;
}


/**
 * Does second-pass bbencoding. This should be used before displaying the message in
 * a thread. Assumes the message is already first-pass encoded, and we are given the
 * correct UID as used in first-pass encoding.
 */
function bbencode_second_pass($text, $uid)
{
	global $lang, $bbcode_tpl;

	$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1&#058;", $text);

	// pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
	// This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
	$text = " " . $text;

	// First: If there isn't a "[" and a "]" in the message, don't bother.
	if (! (strpos($text, "[") && strpos($text, "]")) )
	{
		// Remove padding, return.
		$text = substr($text, 1);
		return $text;
	}

	// Only load the templates ONCE..
	if (!defined("BBCODE_TPL_READY"))
	{
		// load templates from file into array.
		$bbcode_tpl = load_bbcode_template();

		// prepare array for use in regexps.
		$bbcode_tpl = prepare_bbcode_template($bbcode_tpl);
	}

	// [CODE] and 
for posting code (HTML, PHP, C etc etc) in your posts.
$text = bbencode_second_pass_code($text, $uid, $bbcode_tpl);

// [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
$text = bbencode_second_pass_quote($text, $uid, $bbcode_tpl);
// $text = str_replace("[quote:$uid]", $bbcode_tpl['quote_open'], $text);
// $text = str_replace("[/quote:$uid]", $bbcode_tpl['quote_close'], $text);

// New one liner to deal with opening quotes with usernames...
// replaces the two line version that I had here before..
$text = preg_replace("/\[quote:$uid=\"(.*?)\"\]/si", $bbcode_tpl['quote_username_open'], $text);

//
  • and
    • for (un)ordered lists.
      // unordered lists
      $text = str_replace("[list:$uid]", $bbcode_tpl['ulist_open'], $text);
      // li tags
      $text = str_replace("[*:$uid]", $bbcode_tpl['listitem'], $text);
      // ending tags
      $text = str_replace("[/list:u:$uid]", $bbcode_tpl['ulist_close'], $text);
      $text = str_replace("[/list:o:$uid]", $bbcode_tpl['olist_close'], $text);
      // Ordered lists
      $text = preg_replace("/\
      • ):$uid\]/si", $bbcode_tpl['olist_open'], $text);

        // glow
        $text = preg_replace("/\[glow=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['glow_open'], $text);
        $text = str_replace("[/glow:$uid]", $bbcode_tpl['glow_close'], $text);

        // shadow
        $text = preg_replace("/\[shadow=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['shadow_open'], $text);
        $text = str_replace("[/shadow:$uid]", $bbcode_tpl['shadow_close'], $text);


        // colours
        $text = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['color_open'], $text);
        $text = str_replace("[/color:$uid]", $bbcode_tpl['color_close'], $text);

        // size
        $text = preg_replace("/\[size=([1-2]?[0-9]):$uid\]/si", $bbcode_tpl['size_open'], $text);
        $text = str_replace("[/size:$uid]", $bbcode_tpl['size_close'], $text);

        // Align BBCode MOD
        $text = preg_replace("/\[align=(left|center|right):$uid\]/si", $bbcode_tpl['align_open'], $text);
        $text = str_replace("[/align:$uid]", $bbcode_tpl['align_close'], $text);


        // and for bolding text.
        $text = str_replace("[b:$uid]", $bbcode_tpl['b_open'], $text);
        $text = str_replace("[/b:$uid]", $bbcode_tpl['b_close'], $text);

        // and for underlining text.
        $text = str_replace("[u:$uid]", $bbcode_tpl['u_open'], $text);
        $text = str_replace("[/u:$uid]", $bbcode_tpl['u_close'], $text);

        // and for italicizing text.
        $text = str_replace("[i:$uid]", $bbcode_tpl['i_open'], $text);
        $text = str_replace("[/i:$uid]", $bbcode_tpl['i_close'], $text);

        // mod : Misc. BBcode : add

        // and for strikethrough text
        $text = str_replace("[s:$uid]", $bbcode_tpl['s_open'], $text);
        $text = str_replace("[/s:$uid]", $bbcode_tpl['s_close'], $text);

        // [ol] and [/ol] for overline text
        $text = str_replace("[ol:$uid]", $bbcode_tpl['ol_open'], $text);
        $text = str_replace("[/ol:$uid]", $bbcode_tpl['ol_close'], $text);

        // [sup] and [/sup] for superscript text
        $text = str_replace("[sup:$uid]", $bbcode_tpl['sup_open'], $text);
        $text = str_replace("[/sup:$uid]", $bbcode_tpl['sup_close'], $text);

        // [sub] and [/sub] for subscript text
        $text = str_replace("[sub:$uid]", $bbcode_tpl['sub_open'], $text);
        $text = str_replace("[/sub:$uid]", $bbcode_tpl['sub_close'], $text);

        // [smcaps] and [/smcaps] for small caps text
        $text = str_replace("[smcaps:$uid]", $bbcode_tpl['smcaps_open'], $text);
        $text = str_replace("[/smcaps:$uid]", $bbcode_tpl['smcaps_close'], $text);

        // [reverse] and [/reverse] for reversed text
        $text = str_replace("[reverse:$uid]", $bbcode_tpl['reverse_open'], $text);
        $text = str_replace("[/reverse:$uid]", $bbcode_tpl['reverse_close'], $text);

        // [area] and [/area] for borders/areas
        $text = str_replace("[area:$uid]", $bbcode_tpl['area_open'], $text);
        $text = str_replace("[/area:$uid]", $bbcode_tpl['area_close'], $text);

        // [area=] and [/area] for borders/areas
        $text = preg_replace("/\[area=(.*?):$uid\]/si", $bbcode_tpl['area1_open'], $text);
        $text = str_replace("[/area:$uid]", $bbcode_tpl['area1_close'], $text);

        // [spoiler] and [/spoiler] for marking possible spoilers
        $text = str_replace("[spoiler:$uid]", $bbcode_tpl['spoiler_open'], $text);
        $text = str_replace("[/spoiler:$uid]", $bbcode_tpl['spoiler_close'], $text);

        // [font] and [/font] for changing the font
        $text = preg_replace("/\[font=(Arial|Arial Black|Arial Narrow|Century Gothic|Comic Sans MS|Courier New|Georgia|Lucida Console|Lucida Handwriting|Microsoft Sans Serif|Symbol|Tahoma|Trebuchet MS|Times New Roman|Verdana):$uid\]/si", $bbcode_tpl['font_open'], $text);
        $text = str_replace("[/font:$uid]", $bbcode_tpl['font_close'], $text);


        // [align] and [/align] for changing the text alignment
        $text = preg_replace("/\[align=(left|right|center|justify):$uid\]/si", $bbcode_tpl['align_open'], $text);
        $text = str_replace("[/align:$uid]", $bbcode_tpl['align_close'], $text);


        // mod : Misc. BBcode : end

        // Patterns and replacements for URL and email tags..
        $patterns = array();
        $replacements = array();

        // [img]image_url_here[/img] code..
        // This one gets first-passed..
        $patterns[] = "#\[img:$uid\]([^?](?:[^\[]+|\[(?!url))*?)\[/img:$uid\]#i";
        $replacements[] = $bbcode_tpl['img'];

        // matches a [url]xxxx://www.phpbb.com[/url] code..
        $patterns[] = "#\[url\]([\w]+?://([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is";
        $replacements[] = $bbcode_tpl['url1'];

        // www.phpbb.com code.. (no xxxx:// prefix).
        $patterns[] = "#\[url\]((www|ftp)\.([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is";
        $replacements[] = $bbcode_tpl['url2'];

        // [url=xxxx://www.phpbb.com]phpBB[/url] code..
        $patterns[] = "#\+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";
        $replacements[] = $bbcode_tpl['url3'];

        // [url=www.phpbb.com]phpBB
        code.. (no xxxx:// prefix).
        $patterns[] = "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";
        $replacements[] = $bbcode_tpl['url4'];

        // user@domain.tld code..
        $patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si";
        $replacements[] = $bbcode_tpl['email'];
        // Begin Flash MOD
        //[flash width= height= loop= ]and[/flash]code..
        $patterns[] = "#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-5]?[0-9]?[0-9]) loop=(true|false):$uid\](.*?)\[/flash:$uid\]#si";
        $replacements[] = $bbcode_tpl[flash];
        //[flash]and[/flash]code..
        $patterns[] = "#\[flash:$uid\](.*?)\[/flash:$uid\]#si";
        $replacements[] = $bbcode_tpl[cf];
        // End Flash MOD

        // mod : Misc. BBcode : add

        // [note] and [/note] for putting notes in posts
        $patterns[] = "#\[note:$uid\](.*?)\[/note:$uid\]#i";
        $replacements[] = $bbcode_tpl['note'];

        // [hr] and [/hr] for horizontal rules
        $patterns[] = "#\[hr:$uid\]([0-9]?[0-9])\[/hr:$uid\]#i";
        $replacements[] = $bbcode_tpl['hr'];
        // mod : Misc. BBcode : end

        // code..
        $patterns[] = "#\[youtube\]http://(?:www\.)?youtube.com/watch\?v=([0-9A-Za-z-_]{11})[^[]*\[/youtube\]#is";
        $replacements[] = $bbcode_tpl['youtube'];



        $text = preg_replace($patterns, $replacements, $text);

        // BEGIN Local Links 1.0.0 (www.phpBBDoctor.com)
        $text = local_urls($text);
        // END Local Links 1.0.0 (www.phpBBDoctor.com)

        // Remove our padding from the string..
        $text = substr($text, 1);

        return $text;

        } // bbencode_second_pass()


        // Need to initialize the random numbers only ONCE
        mt_srand( (double) microtime() * 1000000);

        function make_bbcode_uid()
        {
        // Unique ID for this message..

        $uid = dss_rand();
        $uid = substr($uid, 0, BBCODE_UID_LEN);

        return $uid;
        }

        function bbencode_first_pass($text, $uid)
        {
        // pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
        // This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
        $text = " " . $text;

        //

        Code: Select all

         and 
        for posting code (HTML, PHP, C etc etc) in your posts.
        $text = bbencode_first_pass_pda($text, $uid, '

        Code: Select all

        ', '
        ', '', true, '');

        // [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
        $text = bbencode_first_pass_pda($text, $uid, '[quote]', '[/quote]', '', false, '');
        $text = bbencode_first_pass_pda($text, $uid, '/\[quote=\\\\"(.*?)\\\\"\]/is', '[/quote]', '', false, '', "[quote:$uid=\\\"\\1\\\"]");

        //
        • and
          • for (un)ordered lists.
            $open_tag = array();
            $open_tag[0] = "
            • ";

              // unordered..
              $text = bbencode_first_pass_pda($text, $uid, $open_tag, "
            ", "[/list:u]", false, 'replace_listitems');

            $open_tag[0] = "
            1. ";
              $open_tag[1] = "
              1. ";

                // ordered.
                $text = bbencode_first_pass_pda($text, $uid, $open_tag, "
              ", "[/list:o]", false, 'replace_listitems');

              // [glow] and [/glow] for setting glowing text
              $text = preg_replace("#\[glow=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/glow\]#si", "[glow=\\1:$uid]\\2[/glow:$uid]", $text);

              // [shadow] and [/shadow] for setting shadowing text
              $text = preg_replace("#\[shadow=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/shadow\]#si", "[shadow=\\1:$uid]\\2[/shadow:$uid]", $text);


              // [color] and [/color] for setting text color
              $text = preg_replace("#\[color=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]#si", "[color=\\1:$uid]\\2[/color:$uid]", $text);

              // [size] and [/size] for setting text size
              $text = preg_replace("#\[size=([1-2]?[0-9])\](.*?)\[/size\]#si", "[size=\\1:$uid]\\2[/size:$uid]", $text);
              // Align BBCode MOD - [align] [/align]
              $text = preg_replace("#\[align=(left|center|right)\](.*?)\[/align\]#si", "[align=\\1:$uid]\\2[/align:$uid]", $text);


              // [footnote] and [/footnote] for hiding spoiler text
              $text = preg_replace("#\[footnote\](.*?)\[/footnote\]#si", "[footnote:$uid]\\1[/footnote:$uid]", $text);


              // and for bolding text.
              $text = preg_replace("#\[b\](.*?)\[/b\]#si", "[b:$uid]\\1[/b:$uid]", $text);


              // and for underlining text.
              $text = preg_replace("#\[u\](.*?)\[/u\]#si", "[u:$uid]\\1[/u:$uid]", $text);

              // and for italicizing text.
              $text = preg_replace("#\[i\](.*?)\[/i\]#si", "[i:$uid]\\1[/i:$uid]", $text);

              // mod : Misc. BBcode : add

              // and for strikethrough text
              $text = preg_replace("#\[s\](.*?)\[/s\]#si", "[s:$uid]\\1[/s:$uid]", $text);

              // [ol] and [/ol] for overline text
              $text = preg_replace("#\[ol\](.*?)\[/ol\]#si", "[ol:$uid]\\1[/ol:$uid]", $text);

              // [sup] and [/sup] for superscript text
              $text = preg_replace("#\[sup\](.*?)\[/sup\]#si", "[sup:$uid]\\1[/sup:$uid]", $text);

              // [sub] and [/sub] for subscript text
              $text = preg_replace("#\[sub\](.*?)\[/sub\]#si", "[sub:$uid]\\1[/sub:$uid]", $text);

              // [smcaps] and [/smcaps] for small caps text
              $text = preg_replace("#\[smcaps\](.*?)\[/smcaps\]#si", "[smcaps:$uid]\\1[/smcaps:$uid]", $text);

              // [reverse] and [/reverse] for reversed text
              $text = preg_replace("#\[reverse\](.*?)\[/reverse\]#si", "[reverse:$uid]\\1[/reverse:$uid]", $text);

              // [area] and [/area] for borders/areas
              $text = preg_replace("#\[area\](.*?)\[/area\]#si", "[area:$uid]\\1[/area:$uid]", $text);

              // [area=] and [/area] for borders/areas
              $text = preg_replace("#\[area=(.*?)\](.*?)\[/area\]#si", "[area=\\1:$uid]\\2[/area:$uid]", $text);

              // [spoiler] and [/spoiler] for marking possible spoilers
              $text = preg_replace("#\[spoiler\](.*?)\[/spoiler\]#si", "[spoiler:$uid]\\1[/spoiler:$uid]", $text);

              // [note] and [/note] for putting notes in posts
              $text = preg_replace("#\[note\](.*?)\[/note\]#si", "[note:$uid]\\1[/note:$uid]", $text);

              // [hr] and [/hr] for horizontal rules
              $text = preg_replace("#\[hr\]([0-9]?[0-9])\[/hr\]#si", "[hr:$uid]\\1[/hr:$uid]", $text);

              // [font] and [/font] for changing the font
              $text = preg_replace("#\[font=(Arial|Arial Black|Arial Narrow|Century Gothic|Comic Sans MS|Courier New|Georgia|Lucida Console|Lucida Handwriting|Microsoft Sans Serif|Symbol|Tahoma|Trebuchet MS|Times New Roman|Verdana)\](.*?)\[/font\]#si", "[font=\\1:$uid]\\2[/font:$uid]", $text);


              // [align] and [/align] for changing the text alignment
              $text = preg_replace("#\[align=(left|right|center|justify)\](.*?)\[/align\]#si", "[align=\\1:$uid]\\2[/align:$uid]", $text);


              // mod : Misc. BBcode : end

              // [img]image_url_here[/img] code..
              $text = preg_replace("#\[img\]((http|ftp|https|ftps)://)([^ \?&=\#\"\n\r\t<]*?(\.(jpg|jpeg|gif|png)))\[/img\]#sie", "'[img:$uid]\\1' . str_replace(' ', '%20', '\\3') . '[/img:$uid]'", $text);
              // Begin Flash MOD
              //[flash width= heigth= loop=] and[ /flash ]
              $text = preg_replace("#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-5]?[0-9]) loop=(true|false)\](([a-z]+?)://([^, \n\r]+))\[\/flash\]#si","[flash width=\\1 height=\\2 loop=\\3:$uid\]\\4[/flash:$uid]", $text);
              $text = preg_replace("#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-5]?[0-9])\](([a-z]+?)://([^, \n\r]+))\[\/flash\]#si","[flash width=\\1 height=\\2 loop=false:$uid\]\\3[/flash:$uid]", $text);
              $text = preg_replace("#\[flash\](([a-z]+?)://([^, \n\r]+))\[\/flash\]#si","[flash:$uid\]\\1[/flash:$uid]", $text);
              // End Flash MOD



              // Remove our padding from the string..
              return substr($text, 1);;

              } // bbencode_first_pass()

              /**
              * $text - The text to operate on.
              * $uid - The UID to add to matching tags.
              * $open_tag - The opening tag to match. Can be an array of opening tags.
              * $close_tag - The closing tag to match.
              * $close_tag_new - The closing tag to replace with.
              * $mark_lowest_level - boolean - should we specially mark the tags that occur
              * at the lowest level of nesting? (useful for

              Code: Select all

              , because
               *						we need to match these tags first and transform HTML tags
               *						in their contents..
               * $func - This variable should contain a string that is the name of a function.
               *				That function will be called when a match is found, and passed 2
               *				parameters: ($text, $uid). The function should return a string.
               *				This is used when some transformation needs to be applied to the
               *				text INSIDE a pair of matching tags. If this variable is FALSE or the
               *				empty string, it will not be executed.
               * If open_tag is an array, then the pda will try to match pairs consisting of
               * any element of open_tag followed by close_tag. This allows us to match things
               * like [list=A]...[/list] and [list=1]...[/list] in one pass of the PDA.
               *
               * NOTES:	- this function assumes the first character of $text is a space.
               *				- every opening tag and closing tag must be of the [...] format.
               */
              function bbencode_first_pass_pda($text, $uid, $open_tag, $close_tag, $close_tag_new, $mark_lowest_level, $func, $open_regexp_replace = false)
              {
              	$open_tag_count = 0;
              
              	if (!$close_tag_new || ($close_tag_new == ''))
              	{
              		$close_tag_new = $close_tag;
              	}
              
              	$close_tag_length = strlen($close_tag);
              	$close_tag_new_length = strlen($close_tag_new);
              	$uid_length = strlen($uid);
              
              	$use_function_pointer = ($func && ($func != ''));
              
              	$stack = array();
              
              	if (is_array($open_tag))
              	{
              		if (0 == count($open_tag))
              		{
              			// No opening tags to match, so return.
              			return $text;
              		}
              		$open_tag_count = count($open_tag);
              	}
              	else
              	{
              		// only one opening tag. make it into a 1-element array.
              		$open_tag_temp = $open_tag;
              		$open_tag = array();
              		$open_tag[0] = $open_tag_temp;
              		$open_tag_count = 1;
              	}
              
              	$open_is_regexp = false;
              
              	if ($open_regexp_replace)
              	{
              		$open_is_regexp = true;
              		if (!is_array($open_regexp_replace))
              		{
              			$open_regexp_temp = $open_regexp_replace;
              			$open_regexp_replace = array();
              			$open_regexp_replace[0] = $open_regexp_temp;
              		}
              	}
              
              	if ($mark_lowest_level && $open_is_regexp)
              	{
              		message_die(GENERAL_ERROR, "Unsupported operation for bbcode_first_pass_pda().");
              	}
              
              	// Start at the 2nd char of the string, looking for opening tags.
              	$curr_pos = 1;
              	while ($curr_pos && ($curr_pos < strlen($text)))
              	{
              		$curr_pos = strpos($text, "[", $curr_pos);
              
              		// If not found, $curr_pos will be 0, and the loop will end.
              		if ($curr_pos)
              		{
              			// We found a [. It starts at $curr_pos.
              			// check if it's a starting or ending tag.
              			$found_start = false;
              			$which_start_tag = "";
              			$start_tag_index = -1;
              
              			for ($i = 0; $i < $open_tag_count; $i++)
              			{
              				// Grab everything until the first "]"...
              				$possible_start = substr($text, $curr_pos, strpos($text, ']', $curr_pos + 1) - $curr_pos + 1);
              
              				//
              				// We're going to try and catch usernames with "[' characters.
              				//
              				if( preg_match('#\[quote=\\\"#si', $possible_start, $match) && !preg_match('#\[quote=\\\"(.*?)\\\"\]#si', $possible_start) )
              				{
              					// OK we are in a quote tag that probably contains a ] bracket.
              					// Grab a bit more of the string to hopefully get all of it..
              					if ($close_pos = strpos($text, '"]', $curr_pos + 14))
              					{
              						if (strpos(substr($text, $curr_pos + 14, $close_pos - ($curr_pos + 14)), '[quote') === false)
              						{
              							$possible_start = substr($text, $curr_pos, $close_pos - $curr_pos + 7);
              						}
              					}
              				}
              
              				// Now compare, either using regexp or not.
              				if ($open_is_regexp)
              				{
              					$match_result = array();
              					if (preg_match($open_tag[$i], $possible_start, $match_result))
              					{
              						$found_start = true;
              						$which_start_tag = $match_result[0];
              						$start_tag_index = $i;
              						break;
              					}
              				}
              				else
              				{
              					// straightforward string comparison.
              					if (0 == strcasecmp($open_tag[$i], $possible_start))
              					{
              						$found_start = true;
              						$which_start_tag = $open_tag[$i];
              						$start_tag_index = $i;
              						break;
              					}
              				}
              			}
              
              			if ($found_start)
              			{
              				// We have an opening tag.
              				// Push its position, the text we matched, and its index in the open_tag array on to the stack, and then keep going to the right.
              				$match = array("pos" => $curr_pos, "tag" => $which_start_tag, "index" => $start_tag_index);
              				array_push($stack, $match);
              				//
              				// Rather than just increment $curr_pos
              				// Set it to the ending of the tag we just found
              				// Keeps error in nested tag from breaking out
              				// of table structure..
              				//
              				$curr_pos += strlen($possible_start);
              			}
              			else
              			{
              				// check for a closing tag..
              				$possible_end = substr($text, $curr_pos, $close_tag_length);
              				if (0 == strcasecmp($close_tag, $possible_end))
              				{
              					// We have an ending tag.
              					// Check if we've already found a matching starting tag.
              					if (sizeof($stack) > 0)
              					{
              						// There exists a starting tag.
              						$curr_nesting_depth = sizeof($stack);
              						// We need to do 2 replacements now.
              						$match = array_pop($stack);
              						$start_index = $match['pos'];
              						$start_tag = $match['tag'];
              						$start_length = strlen($start_tag);
              						$start_tag_index = $match['index'];
              
              						if ($open_is_regexp)
              						{
              							$start_tag = preg_replace($open_tag[$start_tag_index], $open_regexp_replace[$start_tag_index], $start_tag);
              						}
              
              						// everything before the opening tag.
              						$before_start_tag = substr($text, 0, $start_index);
              
              						// everything after the opening tag, but before the closing tag.
              						$between_tags = substr($text, $start_index + $start_length, $curr_pos - $start_index - $start_length);
              
              						// Run the given function on the text between the tags..
              						if ($use_function_pointer)
              						{
              							$between_tags = $func($between_tags, $uid);
              						}
              
              						// everything after the closing tag.
              						$after_end_tag = substr($text, $curr_pos + $close_tag_length);
              
              						// Mark the lowest nesting level if needed.
              						if ($mark_lowest_level && ($curr_nesting_depth == 1))
              						{
              							if ($open_tag[0] == '[code]')
              							{
              								$code_entities_match = array('#<#', '#>#', '#"#', '#:#', '#\[#', '#\]#', '#\(#', '#\)#', '#\{#', '#\}#');
              								$code_entities_replace = array('<', '>', '"', '&#58;', '&#91;', '&#93;', '&#40;', '&#41;', '&#123;', '&#125;');
              								$between_tags = preg_replace($code_entities_match, $code_entities_replace, $between_tags);
              							}
              							$text = $before_start_tag . substr($start_tag, 0, $start_length - 1) . ":$curr_nesting_depth:$uid]";
              							$text .= $between_tags . substr($close_tag_new, 0, $close_tag_new_length - 1) . ":$curr_nesting_depth:$uid]";
              						}
              						else
              						{
              							if ($open_tag[0] == '[code]')
              							{
              								$text = $before_start_tag . '&#91;code&#93;';
              								$text .= $between_tags . '&#91;/code&#93;';
              							}
              							else
              							{
              								if ($open_is_regexp)
              								{
              									$text = $before_start_tag . $start_tag;
              								}
              								else
              								{
              									$text = $before_start_tag . substr($start_tag, 0, $start_length - 1) . ":$uid]";
              								}
              								$text .= $between_tags . substr($close_tag_new, 0, $close_tag_new_length - 1) . ":$uid]";
              							}
              						}
              
              						$text .= $after_end_tag;
              
              						// Now.. we've screwed up the indices by changing the length of the string.
              						// So, if there's anything in the stack, we want to resume searching just after it.
              						// otherwise, we go back to the start.
              						if (sizeof($stack) > 0)
              						{
              							$match = array_pop($stack);
              							$curr_pos = $match['pos'];
              //							bbcode_array_push($stack, $match);
              //							++$curr_pos;
              						}
              						else
              						{
              							$curr_pos = 1;
              						}
              					}
              					else
              					{
              						// No matching start tag found. Increment pos, keep going.
              						++$curr_pos;
              					}
              				}
              				else
              				{
              					// No starting tag or ending tag.. Increment pos, keep looping.,
              					++$curr_pos;
              				}
              			}
              		}
              	} // while
              
              	return $text;
              
              } // bbencode_first_pass_pda()
              
              /**
               * Does second-pass bbencoding of the [code] tags. This includes
               * running htmlspecialchars() over the text contained between
               * any pair of [code] tags that are at the first level of
               * nesting. Tags at the first level of nesting are indicated
               * by this format: [code:1:$uid] ... [/code:1:$uid]
               * Other tags are in this format: [code:$uid] ... [/code:$uid]
               */
              function bbencode_second_pass_code($text, $uid, $bbcode_tpl)
              {
              	global $lang;
              
              	$code_start_html = $bbcode_tpl['code_open'];
              	$code_end_html =  $bbcode_tpl['code_close'];
              
              	// First, do all the 1st-level matches. These need an htmlspecialchars() run,
              	// so they have to be handled differently.
              	$match_count = preg_match_all("#\[code:1:$uid\](.*?)\[/code:1:$uid\]#si", $text, $matches);
              
              	for ($i = 0; $i < $match_count; $i++)
              	{
              		$before_replace = $matches[1][$i];
              		$after_replace = $matches[1][$i];
              
              		// Replace 2 spaces with "&nbsp; " so non-tabbed code indents without making huge long lines.
              		$after_replace = str_replace("  ", "&nbsp; ", $after_replace);
              		// now Replace 2 spaces with " &nbsp;" to catch odd #s of spaces.
              		$after_replace = str_replace("  ", " &nbsp;", $after_replace);
              
              		// Replace tabs with "&nbsp; &nbsp;" so tabbed code indents sorta right without making huge long lines.
              		$after_replace = str_replace("\t", "&nbsp; &nbsp;", $after_replace);
              
              		// now Replace space occurring at the beginning of a line
              		$after_replace = preg_replace("/^ {1}/m", '&nbsp;', $after_replace);
              
              		$str_to_match = "[code:1:$uid]" . $before_replace . "[/code:1:$uid]";
              
              		$replacement = $code_start_html;
              		$replacement .= $after_replace;
              		$replacement .= $code_end_html;
              
              		$text = str_replace($str_to_match, $replacement, $text);
              	}
              
              	// Now, do all the non-first-level matches. These are simple.
              	$text = str_replace("[code:$uid]", $code_start_html, $text);
              	$text = str_replace("[/code:$uid]", $code_end_html, $text);
              
              	return $text;
              
              } // bbencode_second_pass_code()
              
              /**
               * Does second-pass bbencoding of the [quote] tags. This includes
               * seperating out any [footnote] tags there may be in any pair of 
               * [quote] tags.
               */
              function bbencode_second_pass_quote($text, $uid, $bbcode_tpl)
              {
              	// determine if any quotes are in the text a make nda recursive call on it if there is
              	preg_match("#\[quote:$uid(=\".*\")?\](.*?)\[/quote:$uid\]#si", substr($text, 1), $match);
              
              	if( $match[0] )
              	{
              		$start_pos = strpos($text, $match[0], 1);
              		$text = substr($text, 0, $start_pos) . bbencode_second_pass_quote(substr($text, $start_pos), $uid, $bbcode_tpl);
              	}
              	
              	$end_text = "";
              	$end_pos = strpos($text, "[/quote:$uid]");
              	
              	
              	// select just the quote itself and strip the closing quote tag (if there is a quote in the text)
              	if( $end_pos )
              	{
              		$end_text = substr($text, ($end_pos + strlen("[/quote:$uid]")));
              		$text = substr($text, 0, ($end_pos + strlen("[/quote:$uid]")));
              		
              		$text = str_replace("[/quote:$uid]", "", $text);
              
              	}
              
              	// [footnote] and [/footnote] for hiding spoiler text
              	preg_match_all("#\[footnote:$uid\](.*?)\[/footnote:$uid\]#si", $text, $footnotes, PREG_PATTERN_ORDER);
              	
              	if(count($footnotes[1]) != 0)
              	{
              		$count = 1;
              		$text .= $bbcode_tpl['footnote_open'];
              	
              		foreach($footnotes[1] as $key => $note)
              		{
              			$text = str_replace($footnotes[0][$key], $bbcode_tpl['super_open'].$count.$bbcode_tpl['super_close'], $text);
              			$text .= "<br />".$bbcode_tpl['super_open'].$count.$bbcode_tpl['super_close']." ".$note;
              			$count++;
              		}
              
              		$text .= $bbcode_tpl['footnote_close'];
              	}
              
              	// add the closing quote tag again (if this was a quote)
              	if( $end_pos )
              	{
              		$text .= $bbcode_tpl['quote_close'];
              	}
              	
              	// substiture the opening quote tag with the correct template code
              	$text = str_replace("[quote:$uid]", $bbcode_tpl['quote_open'], $text);
              	$text = preg_replace("/\[quote:$uid=\"(.*?)\"\]/si", $bbcode_tpl['quote_username_open'], $text);
              
              	// place the quote back into the main text
              	$text .= $end_text;
              
              	return $text;
              }
              
              /**
               * Rewritten by Nathan Codding - Feb 6, 2001.
               * - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking
               * 	to that URL
               * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking
               * 	to http://www.xxxx.yyyy[/zzzz]
               * - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking
               *		to that email address
               * - Only matches these 2 patterns either after a space, or at the beginning of a line
               *
               * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe
               * have it require something like xxxx@yyyy.zzzz or such. We'll see.
               */
              function make_clickable($text)
              {
              	$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1&#058;", $text);
              
              	// pad it with a space so we can match things at the start of the 1st line.
              	$ret = ' ' . $text;
              
              	// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
              	// xxxx can only be alpha characters.
              	// yyyy is anything up to the first space, newline, comma, double quote or <
              	$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
              
              	// matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
              	// Must contain at least 2 dots. xxxx contains either alphanum, or "-"
              	// zzzz is optional.. will contain everything up to the first space, newline, 
              	// comma, double quote or <.
              	$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
              	
              	// matches an email@domain type address at the start of a line, or after a space.
              	// Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
                    $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
              	
              
              // BEGIN Local Links 1.0.0 (www.phpBBDoctor.com)
              	$ret = local_urls ($ret);
              	// END Local Links 1.0.0 (www.phpBBDoctor.com)
              
              	// Remove our padding..
              	$ret = substr($ret, 1);
              
              	return($ret);
              }
              
              /**
               * Chunk long urls to avoid page stretching. This function splits a
               * long url into chunks, then glues it back together with a couple
               * of dots. This gaggle of code could be boiled down to fewer lines,
               * but it would make it hard to read.
               */
              function chunk_url(&$ret)
              {
                 /**
                  * Split the string into an array. Then loop through
                  * the array and process each link separately.
                  */
                 $links = explode('<a', $ret);
                 $countlinks = count($links);
                 for ($i = 0; $i < $countlinks; $i++)
                 {
                    $link = $links[$i];
              
                    /**
                     * If the array element is a hyperlink then put the missing
                     * '<a' back in, as we will not be imploding...
                     */
                    $link = (preg_match('#(.*)(href=")#is', $link)) ? '<a' . $link : $link;
              
                    $begin = strpos($link, '>') + 1;
                    $end = strpos($link, '<', $begin);
                    $length = $end - $begin;
                    $urlname = substr($link, $begin, $length);
              
                    /**
                     * We chunk urls that are longer than 50 characters. Just change
                     * '50' to a value that suits your taste. We are not chunking the link
                     * text unless if begins with 'http://', 'ftp://', or 'www.'
                     */
                    $shorturlname = (strlen($urlname) > 50 && preg_match('#^(http://|ftp://|www\.)#is', $urlname)) ? substr_replace($urlname, '.....', 30, -10) : $urlname;
                    $ret = str_replace('>' . $urlname . '<', '>' . $shorturlname . '<', $ret);
                 }
              }
              
              
              /**
               * Nathan Codding - Feb 6, 2001
               * Reverses the effects of make_clickable(), for use in editpost.
               * - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs.
               *
               */
              function undo_make_clickable($text)
              {
              	$text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text);
              	$text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text);
              
              	return $text;
              
              }
              
              /**
               * Nathan Codding - August 24, 2000.
               * Takes a string, and does the reverse of the PHP standard function
               * htmlspecialchars().
               */
              function undo_htmlspecialchars($input)
              {
              	$input = preg_replace("/>/i", ">", $input);
              	$input = preg_replace("/</i", "<", $input);
              	$input = preg_replace("/"/i", "\"", $input);
              	$input = preg_replace("/&/i", "&", $input);
              
              	return $input;
              }
              
              /**
               * This is used to change a [*] tag into a [*:$uid] tag as part
               * of the first-pass bbencoding of [list] tags. It fits the
               * standard required in order to be passed as a variable
               * function into bbencode_first_pass_pda().
               */
              function replace_listitems($text, $uid)
              {
              	$text = str_replace("[*]", "[*:$uid]", $text);
              
              	return $text;
              }
              
              /**
               * Escapes the "/" character with "\/". This is useful when you need
               * to stick a runtime string into a PREG regexp that is being delimited
               * with slashes.
               */
              function escape_slashes($input)
              {
              	$output = str_replace('/', '\/', $input);
              	return $output;
              }
              
              /**
               * This function does exactly what the PHP4 function array_push() does
               * however, to keep phpBB compatable with PHP 3 we had to come up with our own
               * method of doing it.
               * This function was deprecated in phpBB 2.0.18
               */
              function bbcode_array_push(&$stack, $value)
              {
                 $stack[] = $value;
                 return(sizeof($stack));
              }
              
              /**
               * This function does exactly what the PHP4 function array_pop() does
               * however, to keep phpBB compatable with PHP 3 we had to come up with our own
               * method of doing it.
               * This function was deprecated in phpBB 2.0.18
               */
              function bbcode_array_pop(&$stack)
              {
                 $arrSize = count($stack);
                 $x = 1;
              
                 while(list($key, $val) = each($stack))
                 {
                    if($x < count($stack))
                    {
              	 		$tmpArr[] = $val;
                    }
                    else
                    {
              	 		$return_val = $val;
                    }
                    $x++;
                 }
                 $stack = $tmpArr;
              
                 return($return_val);
              }
              
              //
              // Smilies code ... would this be better tagged on to the end of bbcode.php?
              // Probably so and I'll move it before B2
              //
              function smilies_pass($message)
              {
              	static $orig, $repl;
              
              	if (!isset($orig))
              	{
              		global $db, $board_config;
              		$orig = $repl = array();
              
              		$sql = 'SELECT * FROM ' . SMILIES_TABLE;
              		if( !$result = $db->sql_query($sql) )
              		{
              			message_die(GENERAL_ERROR, "Couldn't obtain smilies data", "", __LINE__, __FILE__, $sql);
              		}
              		$smilies = $db->sql_fetchrowset($result);
              
              		if (count($smilies))
              		{
              			usort($smilies, 'smiley_sort');
              		}
              
              		for ($i = 0; $i < count($smilies); $i++)
              		{
              			$orig[] = "/(?<=.\W|\W.|^\W)" . preg_quote($smilies[$i]['code'], "/") . "(?=.\W|\W.|\W$)/";
              			$repl[] = '<img src="'. $board_config['smilies_path'] . '/' . $smilies[$i]['smile_url'] . '" alt="' . $smilies[$i]['emoticon'] . '" border="0" />';
              		}
              	}
              
              	if (count($orig))
              	{
              		$message = preg_replace($orig, $repl, ' ' . $message . ' ');
              		$message = substr($message, 1, -1);
              	}
              	
              	return $message;
              }
              
              ?>
              
              I got a feeling this is the end of my forum.
http://www.nwcpnefc.co.uk for PNE Fans in North Wales and Cheshire, but we welcome all, including fans from other clubs.
Mickey14
Registered User
Posts: 88
Joined: Sat Mar 05, 2005 10:45 am

Re: [BETA] Smiley management

Post by Mickey14 »

In the BBCode.php file you attached, this is still the original "smilies_pass($message)" function. If the Smiley Management MOD is only partially installed, it can lead to that kind of problems.
Post Reply

Return to “[2.0.x] MODs in Development”