[Beta] MOD Playing cards

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

[Beta] MOD Playing cards

Post by Merlin Sythove » Fri Sep 07, 2007 12:58 pm

This is a simple mod, that translates playing card codes such as
[9d Ah 7d]
for 9 of Diamonds, Ace of Hearts and 7 of Diamonds
into their corresponding card image files.

The codes must be between square brackets and consist of 2 letters each.
They are NOT limited to playing cards, anything that can be coded with 2 letters like this can be converted to images, such as dice for example.

Code: Select all

##############################################################
## MOD Title: MOD Playing cards
## MOD Author: Merlin Sythove <Merlin@silvercircle.org> Dennis www.pimpmyforum.nl
## MOD Description: Display playing cards from BBCode-like playing card codes
## MOD Version: 0.9.0
##
## Installation Level: Easy
## Installation Time: 5 Minutes
## Files To Edit:
##    includes/bbcode.php,
##    includes/topic_review.php,
##    search.php
##    posting.php
##    viewtopic.php
## Included Files: N/A

##############################################################
## Author Notes:
##  This mod changes the playing card codes to card images just prior to displaying a post.
##  Card codes look like [9d Ah 7d] i.e. enclosed in square brackets are n 2-letter codes.
##  Codes consist of A 2-9 T K Q J (Ace, 2-9, Ten, King, Queen, Knight) for the first letter
##  and c h d s for clubs hearts diamonds spades for the second letter.
##  For each card and each code there must be 1 image, Ace of hearts is Ah so 
##  in the folder /images/cards/Ah.gif must exist. Please note the capitalisation.
##  So put 52 images in a new folder called images/cards.
##
##############################################################
The mod consists of 1 simple subroutine that does the translation process from codes to cards.
In a few files, a single line is added to call this routine.
The posts themselves are unaltered and contain the codes at all times (like [9d Ah 7d]) - it is only when the post is displayed on screen, that the codes are translated to images.

Download the MOD file

Playing cards
Some people have posted playing card images links below, I'll add those here for completeness:
http://www.jfitz.com/cards/
http://www.istartedsomething.com/wp-con ... igns_l.jpg
http://pankwindu.com/images/PwBbbCardModSample.png
http://www.csee.umbc.edu/~squire/downlo ... ard_gl.jpg
http://math.hws.edu/javanotes/c12/cards.png
http://cache.eb.com/eb/image?id=97352&rendTypeId=4
http://politicalcomment.blogspot.com/Du ... s%20up.gif (scanning is an option... :-))
Last edited by Merlin Sythove on Sat Sep 08, 2007 9:49 am, edited 3 times in total.
Need custom work done? Pimp My Forum!

User avatar
Jleagle
Registered User
Posts: 340
Joined: Tue Jun 24, 2003 7:40 pm
Location: England
Contact:

Re: [Beta] MOD Playing cards

Post by Jleagle » Fri Sep 07, 2007 2:02 pm

Great mod, love the idea.

User avatar
beggers
Registered User
Posts: 1257
Joined: Fri Nov 23, 2001 8:19 pm
Location: Las Vegas
Contact:

Re: [Beta] MOD Playing cards

Post by beggers » Sat Sep 08, 2007 7:41 am

It's a cool idea. I'll probably try it if anyone can provide some card images.

User avatar
3Di
Former Team Member
Posts: 14477
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: [Beta] MOD Playing cards

Post by 3Di » Sat Sep 08, 2007 8:54 am

Great idea :)

About the cards: http://www.jfitz.com/cards/

regards
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
✒️ Black Friday 2019 @ The Studio ▪️◾️

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

Re: [Beta] MOD Playing cards

Post by Merlin Sythove » Sat Sep 08, 2007 9:24 am

Thanks, I'll start adding links to sets in the first post above.

You can also use the mod for mah yong tiles in a mah yong discussion forum, or for dice etc.

To resize the images find this in the mod file or in includes/bbcode.php

Code: Select all

<img src="images/cards/\\1.gif" 
and after it, inline, insert

Code: Select all

 width=20 height=40
or whatever the size of the images must be.
Of course you can also resize the images manually in a paint program, so the files will be smaller and the page will load faster.
Need custom work done? Pimp My Forum!

yo_bee
Registered User
Posts: 42
Joined: Fri Aug 24, 2007 12:17 am

Re: [Beta] MOD Playing cards

Post by yo_bee » Mon Sep 10, 2007 12:29 pm

Thank you for all your help Merlin Sythove. I have one more request.

If possible is there a way to also address previous post that were modified manually to properly show the images.
i.e. :Ac: = <img=ac.gif>

I want to remove all instances : before and after :Ac:, :Ah:, :Ad:, :As:, :Th: prior to viewing.

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

Re: [Beta] MOD Playing cards

Post by Merlin Sythove » Mon Sep 10, 2007 1:05 pm

yo_bee wrote:I want to remove all instances : before and after :Ac:, :Ah:, :Ad:, :As:, :Th: prior to viewing.
You should be able to remove those using an SQL query.

To test it, first find a post that you made with those combinations in it and note down the post ID (put the mouse on the little icon at the top of the post and note down the number at the end of the URL there).

Then use this SQL query in your database window (in phpMyAdmin on your host, of course)

Code: Select all

UPDATE `phpbb_posts_text`  
SET `post_text` = REPLACE( `post_text` , ":Ah:", "Ah")
WHERE `post_id` = test_id
To test the workings of your SQL statement, fill in the test_id number so you limit the SQL to just a single post, for quick verification and damage limitation :D Think very carefully if the codes are really only ever used for your cards.

Once it works, use just this:

Code: Select all

UPDATE `phpbb_posts_text`  
SET `post_text` = REPLACE( `post_text` , ":Ah:", "Ah")
and run this query once for each code you have, so replace Ah by Th for the next code and so on.

Of course you can put such an SQL statement in a php code page and run that. Bit more work.
Need custom work done? Pimp My Forum!

yo_bee
Registered User
Posts: 42
Joined: Fri Aug 24, 2007 12:17 am

Re: [Beta] MOD Playing cards

Post by yo_bee » Thu Sep 13, 2007 10:33 pm

going to apply this to the live site every soon.

I will keep this posted.


Thank you once again.

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

Re: [Beta] MOD Playing cards

Post by Merlin Sythove » Wed Sep 19, 2007 6:26 pm

I came across a few variations in the why other sites post their Hand Histories.

One of them uses () instead of []
(board: 6d Kc Tc):
and then there is this strange one.

[6s 3s 8h 4d 2d 5d 6d - B:2d,P:3s,B:4d,B:5d,B:6d]

Not sure if this can he easily rectified.
First question is of course how important it is to cater for these variations. And what the second variation means. Writing the replace routines is quite time consuming. The first version looks easy, the second may require quite a bit of tinkering.
Need custom work done? Pimp My Forum!

yo_bee
Registered User
Posts: 42
Joined: Fri Aug 24, 2007 12:17 am

Re: [Beta] MOD Playing cards

Post by yo_bee » Wed Sep 19, 2007 6:45 pm

First Variation is the key

The second one I am really not to concerned with.

() is more important.

Thanks

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

Re: [Beta] MOD Playing cards

Post by Merlin Sythove » Thu Sep 20, 2007 6:55 am

I came across a few variations in the why other sites post their Hand Histories.

One of them uses () instead of []
(board: 6d Kc Tc):
In order to replace this type of code, after installing this mod, open includes/bbcode.php
FIND

Code: Select all

function decode_playing_cards ($message)
{
ADD AFTER

Code: Select all

//Change this type of coding (board: XX XX XX) into [XX XX XX]
	$regexp = '\(board:([A2-9TKQJ cdhs]*)\)';
	$message = preg_replace('/' . $regexp . '/', '[\\1]', $message);
Let me know if that does the trick.
If it does not work, then after these 3lines that you have just inserted add
return $message;
so no further processing is done and you can see what just these two lines accomplish.

And in case it is cryptic: the new board code like (board: 6d Kc Tc): is changed to a standard board code first, like [6d Kc Tc]: and after that it is processed as all the other board code.
Need custom work done? Pimp My Forum!

yo_bee
Registered User
Posts: 42
Joined: Fri Aug 24, 2007 12:17 am

Re: [Beta] MOD Playing cards

Post by yo_bee » Thu Sep 20, 2007 3:37 pm

That worked great. Now I am trying to address another pattern.

I attempted to modify your new addition to the code to [xx, xx, xx] into [xx xx xx] and also xx xx into image, but had no luck.

These are the things that I am coming across with the various Poker sites out there.

Here are my variations:

[xx xx]
[xx xx xx]
[xx xx xx] [xx]
[xx xx xx] [xx] [xx]

xx xx
[xx, xx, xx]
[xx]
[xx]

(board: xx xx xx):
(board: xx xx xx xx):
(board: xx xx xx xx xx):

Merlin Sythove,

I was also thinking of the word censor table or something similar to that. When I started messing around with this (prior to speak to you) I put the five text/words into the PHPBB_WORDS table and put the Replacement characters that were associated with the phpbb_smiles table hoping that it would then replace the text with the image. It just replace the characters, but did not associate the image from the Smiles Table. The reason I am asking this is that I do not want to us any [] () type as delimiters, but rather search for two characters text exact match and replace.

Sorry for being such a pain about this. I am truly thankful for your assistance with this mod.

I

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

Re: [Beta] MOD Playing cards

Post by Merlin Sythove » Thu Sep 20, 2007 4:45 pm

The main problem if you try to change ONLY the two letter codes, without checking for brackets, that you will translate perfectly normal words like "Ah" into a card image. I'll see if I can make a list, eventually you'll get the idea of how things work.
Need custom work done? Pimp My Forum!

yo_bee
Registered User
Posts: 42
Joined: Fri Aug 24, 2007 12:17 am

Re: [Beta] MOD Playing cards

Post by yo_bee » Thu Sep 20, 2007 5:07 pm

All those / ? \ * are all so confusing.

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

Re: [Beta] MOD Playing cards

Post by Merlin Sythove » Thu Sep 20, 2007 6:44 pm

OK here are some examples to try:

A: Change this type of coding (board: XX XX XX): into [XX XX XX]

Code: Select all

	$regexp = '\(board:([A2-9TKQJ cdhs]*)\):*';
	$message = preg_replace('/' . $regexp . '/', '[\\1]', $message);
B: Replace card codes like [XX XX XX] by images, IF followed by (more card code characters or spaces and) a closing ]

Code: Select all

//Allow for optional separating comma's
	$regexp = '([A2-9TKQJ][cdhs],*)(?=[A2-9TKQJ, cdhs]*\])';
	$message = preg_replace('/' . $regexp . '/', '<img src="images/cards/\\1.gif" border=0 />', $message);
C: Replace 2-character card codes like XX by images anywhere

Code: Select all

	$regexp = '\b([A2-9TKQJ][cdhs])\b';
	$message = preg_replace('/' . $regexp . '/', '<img src="images/cards/\\1.gif" border=0 />', $message);
Please note that C will not only replace Ah with an image, but also Ts and 9d and many other combinations that MAY occur in normal text or addresses, since the required closing bracket check has been removed. Although it will only do 2-character words.

Combine A plus B, or A plus C, or B or C only, depending on the codes in use. I would advise A plus B, C is too general. The full function in bbcode.php would then look like:

Code: Select all

function decode_playing_cards ($message)
{
//A: Change this type of coding [color=red](board: XX XX XX): [/color]into [color=#FF0000][XX XX XX][/color]
	$regexp = '\(board:([A2-9TKQJ cdhs]*)\):*';
	$message = preg_replace('/' . $regexp . '/', '[\\1]', $message);
//B: Replace card codes like [color=#FF0000][XX XX XX][/color] by images, IF followed by (more card code characters or spaces and) a closing ]
//Allow for optional separating comma's
	$regexp = '([A2-9TKQJ][cdhs],*)(?=[A2-9TKQJ, cdhs]*\])';
	$message = preg_replace('/' . $regexp . '/', '<img src="images/cards/\\1.gif" border=0 />', $message);
//Get rid of the enclosing [] in the message around any card images
	$message = preg_replace('/\[(<img src="images\/cards\/.*\/>)\]/', '\\1', $message);
	return $message;
}
Need custom work done? Pimp My Forum!

Post Reply

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