News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

MTG Autocard

Started by shenafu, February 07, 2010, 11:52:13 PM

Previous topic - Next topic

shenafu

Link to Mod

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 [nofollow] 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 [nofollow], starcitygames, or magiccards.info [nofollow]).

[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=! [nofollow]
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=! [nofollow]

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

Sinitive

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.

shenafu

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.

jwheels

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!

shenafu

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

shenafu

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.

Apidea

Great mod, Is It possible install to smf 1.1.12?

shenafu

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..

shenafu

Updated to v1.3

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

Moskis

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

Vestifex

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.

shenafu

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.

Vestifex

#12
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

shenafu

#13
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.

Vestifex

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].

Kindred

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';
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Kindred

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'];
      }
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

shenafu

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+


danidan

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!

Shambles

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  ::)

Advertisement: