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

Re: Help with adding code to Fucntion_Posting.PHP.

Post by yo_bee »

Code: Select all

43	Tc	10c.gif	10c
44	Td	10d.gif	10d
45	:Th:	10h.gif	10h
46	Ts	10s.gif	10s
48	2c	2c.gif	2c
49	2d	2d.gif	2d
50	2h	2h.gif	2h
51	2s	2s.gif	2s
52	3c	3c.gif	3c
53	3d	3d.gif	3d
54	3h	3h.gif	3h
55	3s	3s.gif	3s
56	4c	4c.gif	4c
57	4d	4d.gif	4d
58	4h	4h.gif	4h
59	4s	4s.gif	4s
60	5c	5c.gif	5c
61	5d	5d.gif	5d
62	5h	5h.gif	5h
63	5s	5s.gif	5s
64	6c	6c.gif	6c
65	6d	6d.gif	6d
66	6h	6h.gif	6h
67	6s	6s.gif	6s
68	7c	7c.gif	7c
69	7d	7d.gif	7d
70	7h	7h.gif	7h
71	7s	7s.gif	7s
72	8c	8c.gif	8c
73	8d	8d.gif	8d
74	8h	8h.gif	8h
75	8s	8s.gif	8s
76	9c	9c.gif	9c
77	9d	9d.gif	9d
78	9h	9h.gif	9h
79	9s	9s.gif	9s
80	:Ac:	Ac.gif	Ac
81	:Ad:	Ad.gif	Ad
82	:Ah:	Ah.gif	:Ah:
83	:As:	As.gif	As
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 »

Suits cdhs
Cards 2-9 T and A only?
I've added KQB - feel free to edit below.

This is my solution:
yo_bee wrote:I have a slight delemia with posting. ....

*** FLOP *** [9d Ah 7d] <--------- The problem that I have is the Ah, As, Ac, Ad and Th
First of all, you already have posts with this particular format.
So ideally, you do not want to change the way the posts are saved at all, the only thing you want is for the posts to change the way they are displayed. You want to show a card instead of "Ah", and you do not care how this is accomplished. Correct?

You would need images. Create a folder in your forum images folder called cards, and put one image per card there, for example Ah.gif. Make sure the file names are all exactly the same as the code in the message will be (upper and lower case!!). And all gif, no mix of extensions, and no changes from Th to 10h, just rename the files so they have the same name as the card codes..

Once you have all your images in place, you need to add code:

Find in viewtopic.php near the end

Code: Select all

	//
	// Again this will be handled by the templating
	// code at some point
	//
	$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
	$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
BEFORE, add:

Code: Select all

//Translate all card codes to image files:
//Card codes look like [9d Ah 7d] i.e. enclosed in square brackets are 2-letter codes
//Need folder in images folder called cards, and for Ah you need Ah.gif image to be present (note capitals)
	//Whilst testing only bother the admin with problems
	//If all works fine, put // in front of this line so all users will see the card images as well.
	if ($userdata['user_level'] == ADMIN) 
	{
		//If your cards are jpg, change gif to jpg in this line.
		$message = preg_replace("/(\[.*)([2-9TAKQB][cdhs])(.*\])/", "\\1<img src='/images/cards/\\2.gif' alt='card' title='\\2' border='0' />\\3", $message);
		//Pattern syntax notes. Split the text into 3 pattern sections:
		// (\[.*) 		start: [, then 0-n unknown characters
		// ([A2-9TBQK][cdhs])	the pattern consisting of 1 character chosen from each option list (between [])
		// (.*\])		end: 0-n unknown characters, then closed with ]
		// The pattern number 2 is replaced with the image html code.
		// s = newline included in . (don't use here, the pattern must be on a single line)
		// i = case insensitive (not used, the cards are expected to use the correct case so the image file names match)
		
		//Get rid of the enclosing [] in the message around any images, 
		$message = preg_replace("/\[(<img.*\/>)\]/", "\\1", $message);
	}

Test this bit until it really works!!

When it all works, go on with the rest of the mod:
In includes/topic_review.php find:

Code: Select all

			//
			// Again this will be handled by the templating
			// code at some point
			//
			$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
			$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
BEFORE, add

Code: Select all

//Translate all card codes to image files - see notes in viewtopic.php
	$message = preg_replace("/(\[.*)([2-9TAKQB][cdhs])(.*\])/", "\\1<img src='/images/cards/\\2.gif' alt='card' title='\\2' border='0' />\\3", $message);
	$message = preg_replace("/\[(<img.*\/>)\]/", "\\1", $message);
in search.php find:

Code: Select all

				$template->assign_block_vars("searchresults", array( 
BEFORE, add

Code: Select all

//Translate all card codes to image files - see notes in viewtopic.php
	$message = preg_replace("/(\[.*)([2-9TAKQB][cdhs])(.*\])/", "\\1<img src='/images/cards/\\2.gif' alt='card' title='\\2' border='0' />\\3", $message);
	$message = preg_replace("/\[(<img.*\/>)\]/", "\\1", $message);
The last two find and add_before may need altering if it turns out there is a mistake in the first bit.

Tidy up to do when everything works:
You should remove at least 1 card from your smilies, and test for that card, to see that all is working.
Then remove all the cards and smilies that you have made in your smilies system, you won't need them anymore.
And update any posts that use :Th: etc. to use the new system.
Need custom work done? Pimp My Forum!
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 will let you know how it works.


Thank you so much.


Mike
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 »

Here is how I added the code

Code: Select all

//Translate all card codes to image files:
//Card codes look like [9d Ah 7d] i.e. enclosed in square brackets are 2-letter codes
//Need folder in images folder called cards, and for Ah you need Ah.gif image to be present (note capitals)
   //Whilst testing only bother the admin with problems
   //If all works fine, put // in front of this line so all users will see the card images as well.
  // if ($userdata['user_level'] == ADMIN) 
   {
      //If your cards are jpg, change gif to jpg in this line.
      $message = preg_replace("/(\[.*)([2-9TAKQB][cdhs])(.*\])/", "\\1<img src='/images/cards/\\2.gif' alt='card' title='\\2' border='0' />\\3", $message);
      //Pattern syntax notes. Split the text into 3 pattern sections:
      // (\[.*)       start: [, then 0-n unknown characters
      // ([A2-9TBQK][cdhs])   the pattern consisting of 1 character chosen from each option list (between [])
      // (.*\])      end: 0-n unknown characters, then closed with ]
      // The pattern number 2 is replaced with the image html code.
      // s = newline included in . (don't use here, the pattern must be on a single line)
      // i = case insensitive (not used, the cards are expected to use the correct case so the image file names match)
      
      //Get rid of the enclosing [] in the message around any images, 
      $message = preg_replace("/\[(<img.*\/>)\]/", "\\1", $message);
   }

	//
	// Again this will be handled by the templating
	// code at some point
	//
	$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
	$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];

I get nothing, but the text accept for the last character.

Image
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 figured out the reason for the image not displaying.
  • //If your cards are jpg, change gif to jpg in this line.
    $message = preg_replace("/(\[.*)([2-9TAKQB][cdhs])(.*\])/", "\\1<img src='/images/cards/\\2.gif' alt='card' title='\\2' border='0' />\\3", $message);
  • //If your cards are jpg, change gif to jpg in this line.
    $message = preg_replace("/(\[.*)([2-9TAKQB][cdhs])(.*\])/", "\\1<img src='./images/cards/\\2.gif' alt='card' title='\\2' border='0' />\\3", $message);
Image

Also what is the B for in TAKQB
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 »

yo_bee wrote:I figured out the reason for the image not displaying.
Brilliant, change all the lines like that.
Also what is the B for in TAKQB
King Queen and whatever you use for Knave, obviously not a K or maybe a lower case k? I'm Dutch and the only cards I use are Tarot cards so I'm not the person to ask... :lol: Anyway, change the B to whatever you use.

I'll rework it into a proper full MOD file with a subroutine that would make changes easier to implement.
Just let me know what the final replacement line is for you.
I suggest that src='images.... works as well as src='./images.....
Need custom work done? Pimp My Forum!
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 »

Merlin Sythove wrote: I'll rework it into a proper full MOD file with a subroutine that would make changes easier to implement.
Just let me know what the final replacement line is for you.
I suggest that src='images.... works as well as src='./images.....
When you ask "The Final replacement line" you mean what all the characters will be.

[2-9] [TJQKA] [csdh]

As you can see it only addresses the final group of characters within []. It is working for the Th and only referencing the Th and not all words that contain Th.

You are so much help.

Thank you.

Mike
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 »

This is what the line should be to replace card codes by card images:

Code: Select all

$message = preg_replace("/(\[.*)([A2-9TKQJ][cdhs])(.*\])/", "\\1<img src='images/cards/\\2.gif' alt='card' title='\\2' border='0' />\\3", $message);
yo_bee wrote:As you can see it only addresses the final group of characters within [].
Hmmm, I was afraid of that. The alternative is to replace ALL words all over with images, but that means that if someone writes "Ah, I understand you" the Ah would be replaced by an image of a card. It IS possible to do whole words only so "The" is not changed into a card plus "e", but card codes that are whole normal words as well are more difficult. I'll see if I can come up with a replacement that does better.
In the mean time, try this one:

Code: Select all

$message = preg_replace("/(\[.*?)([A2-9TKQJ][cdhs])(.*?\])/", "\\1<img src='images/cards/\\2.gif' alt='card' title='\\2' border='0' />\\3", $message);
Need custom work done? Pimp My Forum!
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 »

Now why is that it only addresses the final group of characters in the string.

FYI for you and maybe this will shed some light on your research.

The forum is using PHPBB 2.0.2

When the card images are in the SMILES <dir> and you added the five characters to the cencored wordlist to be changed from Th to :Th:. During the preview option the five characters are treated and replaced, but once the viewtopic.php is used the word censor table will just replace the text with the replacement text instead of the image.

I hope this makes sense.
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 »

No the problem is inside the function preg_replace, it works as specified, not the way I thought it might.
I've tested replacing whole words but it makes mistakes there too. Back to the drawing board.
Need custom work done? Pimp My Forum!
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 »

Merlin Sythove wrote:No the problem is inside the function preg_replace, it works as specified, not the way I thought it might.
I've tested replacing whole words but it makes mistakes there too. Back to the drawing board.
Nice.

:(

Did my example with the word censor statement make sense?
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 »

I've solved it, thanks to some help by Very Powerful Friends... :lol:

Just try this in viewtopic.php:
Find in viewtopic.php near the end

Code: Select all

	//
	// Again this will be handled by the templating
	// code at some point
	//
	$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
	$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
BEFORE, add:

Code: Select all

//Replace card codes by images
	$regexp = '([A2-9TKQJ][cdhs])(?=[A2-9TKQJ cdhs]*\])';
	$message = preg_replace('/' . $regexp . '/', '<img src="images/cards/\\1.gif" />', $message);
//Get rid of the enclosing [] in the message around any card images
	$message = preg_replace('/\[(<img src="images\/cards\/.*\/>)\]/', '\\1', $message);


When it works properly, I will post the complete mod in a separate topic, making it a proper subroutine etc. It can be used to replace any 2-letter code by images, so useful for cards, dice, etc.
Need custom work done? Pimp My Forum!
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 »

It worked.

You are the man.

:D :lol: :o ;) :P :mrgreen:

Edit: I tested against a new post and had the results that I am looking for, but I went back to some older post that were edited for post (i.e. Ac was replaced with :Ac:). When the line of code see the :Ac: it does not replace the text with an image and it ignores the previous Card text also. I guess we can do global search and replace in the DATADASE.
    • Edit: I added : to the
      Original:

      Code: Select all

      $regexp = '([A2-9TKQJ][cdhs])(?=[A2-9TKQJ cdhs]*\])';
      Modified:

      Code: Select all

      $regexp = '([:A2-9TKQJ][cdhs])(?=[:A2-9TKQJ cdhs]*\])';
      This works, but It shows the :. Can you remove the : also from previous postings?
I am testing on a MSSQL db, but the live is on a MYSQL db.
Last edited by yo_bee on Fri Sep 07, 2007 12:53 pm, edited 1 time in total.
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 »

Glad to hear it worked. And yes, old existing posts that have words like :Ah: in it should be changed.
Need custom work done? Pimp My Forum!
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 »

I have made a new topic with the full MOD in it

[Beta] MOD Playing cards

I will no longer be watching this current topic.
Need custom work done? Pimp My Forum!
Post Reply

Return to “[2.0.x] MOD Requests”

cron