From 04d15bc32c1a08d2a7f797e17d5f8490b8d5b2c1 Mon Sep 17 00:00:00 2001 From: Stephen Griffiths Date: Tue, 24 Sep 2013 10:37:21 +0100 Subject: [PATCH] Fixed formatting bugs, typo in database_updates.sql, updated readme --- DAL.php | 11 +++-------- README.md | 24 +++++++++++++++--------- card_extractors.php | 4 ++-- database_updates.sql | 2 +- interface.htm | 16 +++++++++++++--- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/DAL.php b/DAL.php index 0bbe501..b0f545c 100644 --- a/DAL.php +++ b/DAL.php @@ -1,6 +1,6 @@ real_escape_string($s)); @@ -28,7 +28,7 @@ function DB_insert_card($name, $mana_cost, $converted_mana_cost, $types, $card_t return $id; } else { - echo " [[ " . $db->error . " ]] "; + echo " [[ {$db->error} ]] "; return false; } } @@ -47,12 +47,7 @@ function SQL_create_card($name, $mana_cost, $converted_mana_cost, $types, $card_ $rarity = sqlString($rarity, $db); $card_number = sqlString($card_number, $db); $artist = sqlString($artist, $db); - - /* - $card_text = addslashes($card_text); - $flavor_text = addslashes($flavor_text); - */ - + $SQL = "insert into $CardTable(name, mana_cost, converted_mana_cost, types, card_text, flavor_text, power_toughness, expansion, rarity, card_number, artist) values( '$name', '$mana_cost', '$converted_mana_cost', '$types', '$card_text', '$flavor_text', '$power_toughness', '$expansion', '$rarity', '$card_number', '$artist' );"; //echo $SQL; diff --git a/README.md b/README.md index 0a20f41..21cc86d 100644 --- a/README.md +++ b/README.md @@ -7,19 +7,21 @@ Popular MTG card references, such as Gatherer, feature human-readable informatio ##Features * Search for cards by name * Returns JSON object of card (see API) -* 2.5 seconds to initially fetch a card, relying on Wizards' Gatherer +* 2-10 seconds to initially fetch a card, relying on Wizards' Gatherer * 0.01 seconds to return a card from database once cached ##Setup -**Requires PHP5 with allow_url_fopen** -Put your database connection information in db.php and install all the files together in a directory. `index.php` links all the files together, so you can see the required files there. +**Requires PHP5 with `allow_url_fopen`** +Put your database connection information in `db.php` and install all the files together in a directory. `index.php` links all the files together, so you can see the required files there. ##API -For demonstration, my installation is kept at [http://stegriff.co.uk/host/magic](http://stegriff.co.uk/host/magic) +For demonstration, my installation is kept at [http://stegriff.co.uk/host/magic](http://stegriff.co.uk/host/magic). +You can try it out using the [magic-api interface](http://stegriff.co.uk/host/magic/interface). +If you are building an app using **magic-api** as a server, I recommend hosting your own instance. ###Parameters `magic?name=black lotus` or `magic?name="black lotus"` to search for a card. -`magic?name=boros recruit&metrics=true` to find out whether that card was from the cache or whether its cache insertion was successful +`magic?name=boros recruit&metrics=true` to find out whether that card was from the cache or whether its cache insertion was successful. ###Returned **magic-api** returns a JSON object, with the following possible fields. Fields with no value will not be in the returned object. @@ -39,19 +41,23 @@ For demonstration, my installation is kept at [http://stegriff.co.uk/host/magic] from_cache^, into_cache^, request_time, + error -^Fields only returned when metrics is turned on in the query string. +^Fields only returned when metrics is turned on in the query string. ###Card encoding ####Icons -Icons are encoded with {Braces}, including mana costs, `{2}{Blue}`, and the tap icon, `{Tap}`. Multi-coloured mana is represented like `{Red or White}`. These values are automatically extracted from the `alt` attribute of any images inside a field on Gatherer. +Icons are encoded with {Braces}, like mana costs (`{2}{U}`), and the tap icon, +`{Tap}`. Single coloured mana is shortened to W/U/B/R/G as is standard +(U is blue). Multi-coloured mana is represented like `{Red or White}`. These values are automatically extracted from the `alt` attribute of any images inside a field on Gatherer, and then mana symbols are shortened. `{Variable Colorless}` is also shortened, to `{X}`. + ####Line breaks Lines of card text are ended by an underscore flanked by spaces, for example: "card_text": "{Tap}: Exile target land card from a graveyard. Add one mana of any color to your mana pool. _ {Black}, {Tap}: Exile target instant or sorcery card from a graveyard. Each opponent loses 2 life. _ {Green}, {Tap}: Exile target creature card from a graveyard" ####Escaping -* The final output has been passed through `add_slashes()`, so single and double quotes appear with a backslash. -* Carriage returns in flavor text currently appear as `\r`. This is considered a bug, and should be encoded the same as card text in a later version. +* Single and double quotes appear with a backslash. +* Carriage returns (`\r`) in flavor text are replaced with a space. * The em-dash in creature type is a Unicode character but should be rendered correctly as an em-dash by your JSON parser. I recommend JSONview for Firefox or Chrome to view the returned values from **magic-api**. ----- diff --git a/card_extractors.php b/card_extractors.php index f3b63a7..681b8ff 100644 --- a/card_extractors.php +++ b/card_extractors.php @@ -1,8 +1,8 @@
', ' _ ', $l); - + $v = str_replace("
", ' _ ', $l); + //Replace all images of icons with their alt text $v = preg_replace("#\#", '{$1}', $v); diff --git a/database_updates.sql b/database_updates.sql index 26f7752..4a1f71a 100644 --- a/database_updates.sql +++ b/database_updates.sql @@ -2,4 +2,4 @@ alter table mtg_cards modify column name varchar(141) not null alter table mtg_cards -modify column name varchar(500) not null \ No newline at end of file +modify column card_text varchar(500) not null \ No newline at end of file diff --git a/interface.htm b/interface.htm index 93d2537..7225513 100644 --- a/interface.htm +++ b/interface.htm @@ -7,9 +7,10 @@ } #cardImage { float: right; + max-width: 40%; } input#name{ - width: 50%; + width: 40%; } @@ -43,6 +44,9 @@ var mcInfoExpansion = ""; //TODO Add more data here switch (magicApiExpansionName){ + case "Magic 2013 Core Set": + mcInfoExpansion = 'm14'; + break; case "Return to Ravnica": mcInfoExpansion = "rtr"; break; @@ -52,6 +56,12 @@ case "Dragon's Maze": mcInfoExpansion = 'dgm'; break; + case "Magic 2014 Core Set": + mcInfoExpansion = 'm14'; + break; + case "Theros": + mcInfoExpansion = 'ths'; + break; } var url = baseUrl + mcInfoExpansion + "/" + cardId + ".jpg"; console.log(url); @@ -63,8 +73,8 @@ -

Magic Card Retriever

+

Magic Card Retriever

@@ -75,6 +85,6 @@

-

Card images only retrieved for RtR, GTC & DGM. Please modify Javascript getImage() to reach more images.

+

Card images only retrieved for cards in standard. Modify Javascript getImage() to reach more images.

\ No newline at end of file