Help with adding code to Fucntion_Posting.PHP.

This forum is now closed as part of retiring phpBB2
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
yo_bee
Registered User
Posts: 42
Joined: Fri Aug 24, 2007 12:17 am

Help with adding code to Fucntion_Posting.PHP.

Post by yo_bee »

I am looking to search $message field for five matching charactors and replace them prior to submitting to the database.

I found a section of code in the FUCNTION_POSTING.PHP. I was wondering if I add a few lines of $preg_match and $preg_replace to replace the characters?

It seems pretty straight forward, but I am having trouble with this.

Code: Select all

// This function will prepare a posted message for
// entry into the database.
//
function prepare_message($message, $html_on, $bbcode_on, $smile_on, $bbcode_uid = 0)
{
	global $board_config, $html_entities_match, $html_entities_replace;

	//
	// Clean up the message
	//
	$message = trim($message);

	if ($html_on)
	{
		// If HTML is on, we try to make it safe
		// This approach is quite agressive and anything that does not look like a valid tag
		// is going to get converted to HTML entities
		$message = stripslashes($message);
		$html_match = '#<[^\w<]*(\w+)((?:"[^"]*"|\'[^\']*\'|[^<>\'"])+)?>#';
		$matches = array();

		$message_split = preg_split($html_match, $message);
		preg_match_all($html_match, $message, $matches);

		$message = '';

		foreach ($message_split as $part)
		{
			$tag = array(array_shift($matches[0]), array_shift($matches[1]), array_shift($matches[2]));
			$message .= preg_replace($html_entities_match, $html_entities_replace, $part) . clean_html($tag);
		}

		$message = addslashes($message);
		$message = str_replace('"', '\"', $message);
	}
	else
	{
		$message = preg_replace($html_entities_match, $html_entities_replace, $message);
	}

	if($bbcode_on && $bbcode_uid != '')
	{
		$message = bbencode_first_pass($message, $bbcode_uid);
	}
		
	
	return $message;
	
}

function unprepare_message($message)
{
	global $unhtml_specialchars_match, $unhtml_specialchars_replace;

	return preg_replace($unhtml_specialchars_match, $unhtml_specialchars_replace, $message);
}
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52169
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Help with adding code to Fucntion_Posting.PHP.

Post by Brf »

yo_bee wrote:I am looking to search $message field for five matching charactors and replace them prior to submitting to the database.
How about using the word censor?
yo_bee
Registered User
Posts: 42
Joined: Fri Aug 24, 2007 12:17 am

Re: Help with adding code to Fucntion_Posting.PHP.

Post by yo_bee »

Tried that, but it does not work the way I want it to.

The purpose of the word change it to represent a image.

so I want Ac to be replaced with :Ac: so it can reference :Ac: in the PHPBB_SMILES table.

If I use the word censor it just will post the text and not convert the image.

So I want All Ac, Ah, As, Ad and Th to be changed prior to submitting to the database

Does that make sense?
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52169
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Help with adding code to Fucntion_Posting.PHP.

Post by Brf »

Well then... You can just put those strings into the smilies page.
yo_bee
Registered User
Posts: 42
Joined: Fri Aug 24, 2007 12:17 am

Re: Help with adding code to Fucntion_Posting.PHP.

Post by yo_bee »

Brf wrote:Well then... You can just put those strings into the smilies page.
Not into the Function_Posting.PHP page? :?:
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52169
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Help with adding code to Fucntion_Posting.PHP.

Post by Brf »

I am talking about doing it without a mod.
Just enter those strings as smilies.
yo_bee
Registered User
Posts: 42
Joined: Fri Aug 24, 2007 12:17 am

Re: Help with adding code to Fucntion_Posting.PHP.

Post by yo_bee »

Brf wrote:I am talking about doing it without a mod.
Just enter those strings as smilies.
Ok. Thanks for your help.

I am pretty new to the whole scripting thing. Can you give me some assistance with this.

I was looking at preg_match and preg_replace. Is that correct?
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52169
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Help with adding code to Fucntion_Posting.PHP.

Post by Brf »

No.

You are trying to replace simple strings with images within the text, correct?

Then you do not have to edit any code.

Simply upload your images to the smilies directory and enter your strings as smilie codes on the smilies page of the ACP.
yo_bee
Registered User
Posts: 42
Joined: Fri Aug 24, 2007 12:17 am

Re: Help with adding code to Fucntion_Posting.PHP.

Post by yo_bee »

Brf wrote:No.

You are trying to replace simple strings with images within the text, correct?

Then you do not have to edit any code.

Simply upload your images to the smilies directory and enter your strings as smilie codes on the smilies page of the ACP.
The problem that I am facing is this:

There are five basic exact text that I want to represent an image, but the code treats all instances and will replace the text with the image.

i.e. I need Th to be represented by an image of a playing card of Ten of Hearts Image, but it replace The with Imagee. So I want to change the Th to :Th:. The reason for this is that the members of the BB copy and paste large bodys of poker Hand Histories.

Example:
  • Full Tilt Poker Game #3288532339: $5 + $0.50 Sit & Go (25149656), Table 1 - 15/30 - No Limit Hold'em - 8:49:18 ET - 2007/08/18
    The button is in seat #9
    *** HOLE CARDS ***
    Dealt to yo_bee [5c 4c]ImageImage
    yo_bee raises to 105
    RedFred folds
    bres13 calls 105
    straightmoney7 folds
    xmorbidx5 folds
    jtac84 folds
    sharky46 calls 105
    billc08002 folds
    cask23 folds
    *** FLOP *** [9d Ah 7d]ImageImageImage
    yo_bee checks
    bres13 checks
    sharky46 checks
    *** TURN *** [9d Ah 7d] [Td]]ImageImageImageImage

    yo_bee checks
    bres13 bets 90
    sharky46 folds
    yo_bee has 15 seconds left to act
    yo_bee folds
    Uncalled bet of 90 returned to bres13
    bres13 mucks
    bres13 wins the pot (360)
    *** SUMMARY ***
    Total pot 360 | Rake 0
    Board: [9d Ah 7d Td]
    Seat 1: billc08002 (small blind) folded before the Flop
    Seat 2: cask23 (big blind) folded before the Flop
    Seat 3: yo_bee folded on the Turn
    Seat 4: RedFred didn't bet (folded)
    Seat 5: bres13 collected (360), mucked
    Seat 6: straightmoney7 didn't bet (folded)
    Seat 7: xmorbidx5 didn't bet (folded)
    Seat 8: jtac84 didn't bet (folded)
    Seat 9: sharky46 (button) folded on the Turn
some blind fool
Registered User
Posts: 409
Joined: Sat Aug 19, 2006 5:28 pm

Re: Help with adding code to Fucntion_Posting.PHP.

Post by some blind fool »

yo_bee wrote:I need Th to be represented by an image of a playing card of Ten of Hearts Image, but it replace The with Imagee. So I want to change the Th to :Th:. The reason for this is that the members of the BB copy and paste large bodys of poker Hand Histories.
if i'm reading this right...
if you set the code to convert just 'th' to ':th:', wouldn't it then change 'the' to ':th:e'? so you would instead need to use 'th ' or ' th ', and replace it with ':th: ' or ' :th: ', which should then convert to the image you want.
yo_bee
Registered User
Posts: 42
Joined: Fri Aug 24, 2007 12:17 am

Re: Help with adding code to Fucntion_Posting.PHP.

Post by yo_bee »

some blind fool wrote:
yo_bee wrote:I need Th to be represented by an image of a playing card of Ten of Hearts Image, but it replace The with Imagee. So I want to change the Th to :Th:. The reason for this is that the members of the BB copy and paste large bodys of poker Hand Histories.
if i'm reading this right...
if you set the code to convert just 'th' to ':th:', wouldn't it then change 'the' to ':th:e'? so you would instead need to use 'th ' or ' th ', and replace it with ':th: ' or ' :th: ', which should then convert to the image you want.
Yea, I do what to replace all match Th. Nothing else. So I want to do an exact match and replace.

Not just any Th.
What about this code?

Code: Select all

<?php
/* The \b in the pattern indicates a word boundary, so only the distinct
 * word "web" is matched, and not a word partial like "webbing" or "cobweb" */
if (preg_match("/\bweb\b/i", "PHP is the web scripting language of choice.")) {
    echo "A match was found.";
} else {
    echo "A match was not found.";
}

if (preg_match("/\bweb\b/i", "PHP is the website scripting language of choice.")) {
    echo "A match was found.";
} else {
    echo "A match was not found.";
}
?> 
yo_bee
Registered User
Posts: 42
Joined: Fri Aug 24, 2007 12:17 am

Re: Help with adding code to Fucntion_Posting.PHP.

Post by yo_bee »

Let me clear this up a bit.

I want to search $message prior to submitting to the database. I want to search for exact text (Ac, As, Ah, Ad and Th) If found replace with :Ac:, :As:, :Ah:, :Ad:, and :Th:.

I would like to have this process happen upon submitting.

So the database record will have :Ac: instead of Ac. This will achieve my goal. If the database record has :Ac: instead of Ac it will represent the image.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52169
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Help with adding code to Fucntion_Posting.PHP.

Post by Brf »

Maybe you should make a bbcode for it. That might work better.
yo_bee
Registered User
Posts: 42
Joined: Fri Aug 24, 2007 12:17 am

Re: Help with adding code to Fucntion_Posting.PHP.

Post by yo_bee »

I am new to programming so please forgive me.

I am looking through all the php code in the PHPBB 2 and I am not having any luck figuring it out.

so some help would be great.

Thank You
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Re: Help with adding code to Fucntion_Posting.PHP.

Post by Merlin Sythove »

Technically, you want to change any post that has [Th] in it, to show a card, not only the posts that are made after you implement this mod, correct? This is a display functionality, the choice of showing [Th] or the card image, nothing to do with the post that is made or saved.

(Changing Th to :Th: may change :Th: to ::Th:: in a quoted message so avoid this path if possible)

I may have the solution but I need the full range of possible card codes first.
Need custom work done? Pimp My Forum!
Post Reply

Return to “[2.0.x] MOD Requests”