Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: shenafu on February 07, 2010, 11:52:13 PM

Title: MTG Autocard
Post by: shenafu on February 07, 2010, 11:52:13 PM
Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=2364)

MTG Autocard
mod for SMF forums
by Xay Voong
v1.8

PURPOSE: Allows BBC tags that create links to autocard, make and export decklists for Magic: the Gathering, and display mana symbols.

COMPATIBILITY: For SMF Forums 2.0.11+

INSTRUCTIONS:
See http://shenafu.com/smf/index.php?topic=4.0 for full instructions and examples.

[card]cardname[/card] will turn the cardname into an anchor/link that points to an outside source (e.g. wizards.com, starcitygames, or magiccards.info).

[card=realname]nickname[/card] where realname is the card's real name and nickname is what appears with the rest of the post.

[deck=deckname]list of cards[/deck] will create a nice table for your decklist. Users can export them into various formats, such as Apprentice's .dec.
Note that this mod copies a file called deck.php into your SMF root directory. The installation script automatically chmods it to 0755 after installation. Otherwise you may get 500 errors when a user tries to download a decklist. You may also try other values like 0666 or 0777 depending on your server's settings.
Note that the images for the deck-export icons are found under the icons folder. They are copied to the default theme's images folder. You must manually copy them to other themes' images folders for them to be usable in nondefault themes.

[mana]mana cost[/mana] will be replaced with respective icons for the given mana cost.

These are the valid letters, numbers, and hybrids that can be used within the mana tags:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 i
w u b r g c x y z s t q p k
w/u u/w u/b b/u b/r r/b r/g g/r w/b b/w u/r r/u b/g g/b r/w w/r g/u u/g
2/w w/2 2/u u/2 2/b b/2 2/r r/2 2/g g/2
p/w w/p p/u u/p p/b b/p p/r r/p p/g g/p p/c c/p

c for colorless (diamond) mana
s for snow
t for tap
q for untap
p for planeswalk
k for chaos/planechase
i for infinite

MOD SETTINGS:
You can modify a few settings under
ADMIN -> CONFIGURATION -> MODIFICATION SETTINGS -> MISCELLANEOUS.

These are their default values:
MTG Autocard URL: http://magiccards.info/query?q=!
MTG Decklist Pattern: /^\s*(\/\/.*|SB: )?(?:x?(?=\d))?(\d+)?\s*(\s?x |\*|\[\w+?])?\s*([^{]*?)\s*?({.*}|--.*)?\s*$/


DISCLAIMER:
I wrote the code myself. However, all the code inside this zip is for public domain. So no need to ask for permission if you want to use it for whatever purpose. Images are copyrighted by WotC or respective parties, most likely.


Changelog
v1.8
added colorless (diamond) mana, using letter c
added infinite mana, using letter i
changed chaos letter to k
used png instead of gif

v1.7
changed decklist pattern: to include ranges of numbers before cardnames

v1.6
chmod deck.php to 0755 post-installation
changed decklist pattern to take into account SB: and // comments from MWS decklists

v1.5
changed decklist pattern: to consider 'x' before count; e.g. x4 Zap

v1.4
deck download now converts HTML entities to normal characters (e.g. quotes)

v1.3
added phyrexian hybrid mana symbols
changed MTG Autocard URL: http://magiccards.info/query?q=!

v1.2
export and download decklists to various formats (i.e. Apprentice, MTGO)

v1.1
$sourcesdir/Subs.php: BBC tag for mana
$sourcedir/Subs-Editor.php: added BBC buttons (card, mana, deck) to post editor
Smileys for mana symbols => Smileys/mana
Icons for editor buttons => Themes/default/images/bbc

v1.0.3
error Undefined offset: 4 in Subs.php: function AUTOCARD_REPLACE_CALLBACK()

v1.0.2
Localization search position="end"

v1.0.1
2010-01-06
modSettings variable names match up in all files


v1.0.0
2010-01-05
$sourcesdir/Subs.php: modified to contain autocard and deck functions and tags
$sourcesdir/ManageSettings.php: miscellaneous settings
$languagedir/Modifications.english.php: localized text
Title: Re: MTG Autocard
Post by: Sinitive on February 18, 2010, 04:21:07 AM
Great mod Shenafu,

I've read on your site that you have added mana symbols and quick buttons for tags when writting posts, is that something we might be able to get as release?

Thanks for a great release.
Title: Re: MTG Autocard
Post by: shenafu on April 15, 2010, 07:43:18 PM
new version 1.0.3 is up. fixed a minor bug

@Sinitive

ya my forums used to have those buttons before the upgrade when they changed the default theme. I was too lazy to put them back in. (kind of a hassle since I much prefer the classic YaBB look.) But since you showed interest in this, I'll try to put aside some time to include them in this mod.
Title: Re: MTG Autocard
Post by: jwheels on April 26, 2010, 11:10:24 PM
I could not get this to work.  Where do you actually see these default values:

MOD SETTINGS:
You can modify a few settings under miscellaneous. These are their default values:
MTG Autocard URL: hxxp:sales.starcitygames.com/cardsearch.php?singlesearch= [nonactive]
MTG Decklist Pattern: /^\s*(\d+)?\s*(\s?x |\*|\[\w+?])?\s*([^{]*?)\s*?({.*}|--.*)?\s*$/

After installation, it tries to find the card using my forum URL.

Thanks!
Title: Re: MTG Autocard
Post by: shenafu on May 06, 2010, 05:17:12 PM
Quote from: jwheels on April 26, 2010, 11:10:24 PM
I could not get this to work.  Where do you actually see these default values:

MOD SETTINGS:
You can modify a few settings under miscellaneous. These are their default values:
MTG Autocard URL: hxxp:sales.starcitygames.com/cardsearch.php?singlesearch= [nonactive]
MTG Decklist Pattern: /^\s*(\d+)?\s*(\s?x |\*|\[\w+?])?\s*([^{]*?)\s*?({.*}|--.*)?\s*$/

After installation, it tries to find the card using my forum URL.

Thanks!

ADMIN -> CONFIGURATION -> MODIFICATION SETTINGS -> MISCELLANEOUS
Title: Re: MTG Autocard
Post by: shenafu on May 07, 2010, 12:43:37 AM
Quote from: Sinitive on February 18, 2010, 04:21:07 AM
Great mod Shenafu,

I've read on your site that you have added mana symbols and quick buttons for tags when writting posts, is that something we might be able to get as release?

Thanks for a great release.

I uploaded version 1.1 which has the things you wanted.
Title: Re: MTG Autocard
Post by: Apidea on February 08, 2011, 05:46:49 AM
Great mod, Is It possible install to smf 1.1.12?
Title: Re: MTG Autocard
Post by: shenafu on February 09, 2011, 09:51:35 PM
I don't have 1.1.2 forum, so I wouldn't be able to test it. However, you can download the mod and extract the source code. Mainly you need the new functions and new BBC codes inserted into the array. Pay attention to the global variables which might be different between 1.x and 2.x; i.e. $modSettings, $settings, $context, etc..
Title: Re: MTG Autocard
Post by: shenafu on April 20, 2011, 02:53:58 AM
Updated to v1.3

added phyrexian hybrid mana symbols
changed MTG Autocard URL: http://magiccards.info/query?q=!
Title: Re: MTG Autocard
Post by: Moskis on June 24, 2011, 09:47:38 AM
Great mod, thx for doing it.

I installed it in a RC5 forum and only one thing doesn't work, the deck download.

When anyone uses the deck tag in a post, it throws 5 undefined index/variable errors in the error log.

This is the deck function in subs.php:

// function to create deck lists

function AUTOCARD_REPLACE_CALLBACK($matches) {
global $modSettings;
$AUTOCARD_URL = $modSettings['MTGAutocard_URL'];
$retval = ($matches[1]? "{$matches[1]} " : '') . "<a class=\"card\" href=\"$AUTOCARD_URL{$matches[3]}\" rel=\"{$matches[3]}\" target=\"_blank\">{$matches[3]}</a> " . (isset($matches[4])? "{$matches[4]} " : '');
return $retval;
}
function Parse_Deck_List($decklist, $decktitle) {
global $modSettings, $settings, $context;
$AUTOCARD_PATTERN = $modSettings['MTGAutocard_Decklist_Pattern'];
if (isset($context['msgid'])) {
$postid = $context['msgid'];
$deckid = $context['deckid'];
}

// step 1: convert cards to links
$decklist = preg_replace('/(<br \/>){3,}/', '<br /><br />', $decklist);

// replace special characters
// change nbsp to normal space
$decklist = preg_replace('/&nbsp;/', ' ', $decklist);
// change apostrophe to &#39;
$decklist = preg_replace('/\'/', '&#39;', $decklist);

// iterate lines and remove amount, set ID via pattern
$decklist = explode('<br />', $decklist);
foreach ($decklist as $key => $value) {
$matcharray = array();
if ($decklist[$key] == '') {
// empty line
}
elseif (preg_match($AUTOCARD_PATTERN, $decklist[$key], $matcharray) && $matcharray[3] != '') {
$decklist[$key] = preg_replace_callback($AUTOCARD_PATTERN, 'AUTOCARD_REPLACE_CALLBACK', $decklist[$key], 1);
}
} // end foreach

// step 2: create sideboard
$sideboard = array();
$sideindex = count($decklist);
for ($i =0; $i<count($decklist); $i++) {
if (preg_match('/sideboard/', strtolower($decklist[$i]))) {
$sideindex = $i;
break;
}
}

// split sideboard from main decklist
if ($sideindex < count($decklist)) {
for (;$sideindex < count($decklist);$sideindex++) {
$sideboard[] = $decklist[$sideindex];
$decklist[$sideindex] = '';
}
}

// step 3: split maindeck into two columns with equal sections

// remove extra blank lines
$decklist = implode('<br />', $decklist);
$decklist = preg_replace('/^(<br \/>)+/', '', $decklist);
$decklist = preg_replace('/(<br \/>)+$/', '', $decklist);
$decklist = explode('<br />', $decklist);

// count number of breaks that divide into sections
$sections = array();
foreach($decklist as $key => $value) {
if ($value == '') {
$sections[] = $key;
}
}
$cutoff = floor((count($sections))/2);
$decklistB = array();
if (!empty($sections)) {
for ($i=$sections[$cutoff]+1; $i < count($decklist); $i++) {
$decklistB[] = $decklist[$i];
$decklist[$i] = '';
}
}

// step 4: deck download
$deckdl = " <div style=\"float:right;margin-left: 20px;\"> <a href=\"deck.php?post=$postid&deckid=$deckid&format=apprentice\"><img src=\"{$settings['images_url']}/icons/apprentice.png\" alt=\"Apprentice\" /></a> <a href=\"deck.php?post=$postid&deckid=$deckid&format=mtgo\"><img src=\"{$settings['images_url']}/icons/mtgo.png\" alt=\"MTGO\" /></a> </div> ";

// step 5: final output
$decklist = implode('<br />', $decklist);
$decklist = preg_replace('/(<br \/>)+$/', '', $decklist);
$deckhtml = "<table style=\"border:2px solid black; padding:5px\"><tr><td colspan=\"3\" style=\"border-bottom:2px solid black\">$deckdl $decktitle </td></tr>";
$deckhtml .= '<tr>';
$deckhtml .= "<td style=\"vertical-align:top;padding:5px\">$decklist</td>";
if (!empty($decklistB)) {
$decklistB = implode('<br />', $decklistB);
$decklistB = preg_replace('/(<br \/>)+$/', '', $decklistB);
$deckhtml .= "<td style=\"border-left:2px solid black;vertical-align:top;padding:5px\">$decklistB</td>";
}
if (!empty($sideboard)) {
$sideboard = implode('<br />', $sideboard);
$sideboard = preg_replace('/(<br \/>)+$/', '', $sideboard);
$deckhtml .= "<td style=\"border-left:2px solid black;vertical-align:top;padding:5px\">$sideboard</td>";
}
$deckhtml .= '</tr>';
$deckhtml .= '</table>';

$context['deckid']++;

return $deckhtml;
}


First it gives "Undefined index: deckid" in this line near the end:

$context['deckid']++;

Then it throws 2 undeined variables for deckid and postid from line:

$deckdl = " <div style=\"float:right;margin-left: 20px;\"> <a href=\"deck.php?post=$postid&deckid=$deckid&format=apprentice\"><img src=\"{$settings['images_url']}/icons/apprentice.png\" alt=\"Apprentice\" /></a> <a href=\"deck.php?post=$postid&deckid=$deckid&format=mtgo\"><img src=\"{$settings['images_url']}/icons/mtgo.png\" alt=\"MTGO\" /></a> </div> ";

Any idea what might be wrong or is there any more info i can provide?

Thanks
Title: Re: MTG Autocard
Post by: Vestifex on June 25, 2011, 10:31:22 AM
Will you update your mod for 2.0 final?

I´m running a local game forum with a lot of magic players, they would love the mod.
Title: Re: MTG Autocard
Post by: shenafu on July 09, 2011, 05:21:39 PM
Updated to v1.5

changed decklist pattern: to consider 'x' before count; e.g. x4 Zap
Use this pattern:

MTG Decklist Pattern:
/^\s*(?:x?(?=\d))?(\d+)?\s*(\s?x |\*|\[\w+?])?\s*([^{]*?)\s*?({.*}|--.*)?\s*$/


It works for 2.0 final just fine.

If deck download causes an error, CHMOD deck.php file permissions to 664.
Title: Re: MTG Autocard
Post by: Vestifex on July 11, 2011, 03:38:28 PM
Unfortunately I can´t sign up at your forum, it shows me that Guest is banned as SpamBot, so here are some more questions:

I´m getting the same deckid and postid errors like Moskis if somebody posts a decklist.

Any idea how to fix it?

I have CHMOD deck.php file permissions to 664, but it did not solve the error.


Also can the search pattern be adjusted that it works with MWS (Magic Workstation) files, so you can do a simple copy and paste.
MWS files are like this:

Quote// Lands
    3 [R] Tropical Island
    2 [R] Bayou
    1 [R] Underground Sea
    1 [FUT] Dryad Arbor
    1 [SH] Volrath's Stronghold
    1 [TE] Wasteland
    4 [ZEN] Misty Rainforest
    3 [ON] Polluted Delta
    1 [ZEN] Verdant Catacombs
    1 [CS] Snow-Covered Island
    1 [CS] Snow-Covered Forest
    1 [CS] Snow-Covered Swamp

// Creatures
    4 [CFX] Noble Hierarch
    3 [FUT] Tarmogoyf
    2 [FD] Eternal Witness
    1 [CFX] Progenitus

// Spells
    3 [WWK] Jace, the Mind Sculptor
    3 [VI] Natural Order
    3 [MBS] Green Sun's Zenith
    4 [AL] Force of Will
    4 [NPH] Mental Misstep
    4 [IA] Brainstorm
    2 [TE] Intuition
    1 [RAV] Life from the Loam
    3 [NPH] Dismember
    2 [MBS] Go for the Throat
    1 [ARB] Maelstrom Pulse

// Sideboard
SB: 3 [AP] Pernicious Deed
SB: 4 [PLC] Extirpate
SB: 2 [ZEN] Spell Pierce
SB: 3 [TSP] Krosan Grip
SB: 3 [MR] Damping Matrix
Title: Re: MTG Autocard
Post by: shenafu on November 24, 2011, 05:57:33 PM
New version 1.6

changelog
v1.6
chmod deck.php to 0755 post-installation
changed decklist pattern to take into account SB: and // comments from MWS decklists




Quote from: Vestifex on July 11, 2011, 03:38:28 PM
I have CHMOD deck.php file permissions to 664, but it did not solve the error.

Try 0755 instead. (should be safe, all SMF are 755 on my server.) or other values depending on your server, such as 0666 or 0777.

Quote
Also can the search pattern be adjusted that it works with MWS (Magic Workstation) files, so you can do a simple copy and paste.

The only part that's not affected is the sideboard cards and comments. Shouldn't be too hard to fix.
Title: Re: MTG Autocard
Post by: Vestifex on January 08, 2012, 10:12:01 AM
I installed the update, the support for MWS works fine.

But now I get an error in subs.php:
8: Undefined offset: 4

==>256:       elseif (preg_match($AUTOCARD_PATTERN, $decklist[$key], $matcharray) && $matcharray[4] != '') {

I think has to do something with the matcharray[4].
Title: Re: MTG Autocard
Post by: Kindred on February 02, 2012, 08:15:30 AM
hmmm.... I don't get the undefined offset.

However, I did notice that subs-editor.php adds the three BBC array additions (deck, card, mana) but never defines the $txt['deck'], etc despite using them.

add to file
/Themes/default/languages/Modifications.english.php

$txt['deck'] = 'Deck';
$txt['mana'] = 'Mana';
$txt['card'] = 'Card';
Title: Re: MTG Autocard
Post by: Kindred on February 08, 2012, 11:49:11 AM
ok....  now, with some more testing:

Subs.php is throwing all sorts of undefined errors based around postid and deckid.
The following code is suspect.... because it seems that neither deckid nor postid ever actually gets set.




      if (isset($context['msgid'])) {
        $postid = $context['msgid'];
        $deckid = $context['deckid'];
      }
Title: Re: MTG Autocard
Post by: shenafu on January 22, 2016, 12:17:09 AM
mod updated

v1.8
added colorless (diamond) mana, using letter c
added infinite mana, using letter i
changed chaos letter to k
added more numeric mana
used png instead of gif

COMPATIBILITY: For SMF Forums 2.0.11+

Title: Re: MTG Autocard
Post by: danidan on August 20, 2017, 04:23:59 PM
Hello!

Realy cool but i have so many error on ligne 307 on Subs.php

$deckdl = " <div style=\"float:right;margin-left: 20px;\"> <a href=\"deck.php?post=$postid&deckid=$deckid&format=apprentice\"><img src=\"{$settings['images_url']}/icons/apprentice.png\" alt=\"Apprentice\" /></a> <a href=\"deck.php?post=$postid&deckid=$deckid&format=mtgo\"><img src=\"{$settings['images_url']}/icons/mtgo.png\" alt=\"MTGO\" /></a> </div> ";

You can help me?

Thanks!
Title: Re: MTG Autocard
Post by: Shambles on August 20, 2017, 04:59:00 PM
Quote from: danidan on August 20, 2017, 04:23:59 PM
Realy cool but i have so many error on ligne 307 on Subs.php

Care to quote one of those errors?

Seems a bit daft to say you have an error but not say what it is  ::)
Title: Re: MTG Autocard
Post by: danidan on August 20, 2017, 05:09:44 PM
Sorry, i don't speek good englisch.  :laugh:

8: Undefined index: deckid
8: Undefined variable: postid
8: Undefined index: deck
8: Undefined index: mana
8: Undefined index: card

I thik the same of other user on the top of post. I have change permission and the error change un lite bit.