Bingo Action
This is the development page for the bingo action.
the php code:
<?php
/**
* A simple action to create a bxxxxxxt bingo game card.
* Words are loaded from another page, called seed.
* Each line in seed starting with a letter (us-ascii +
* german umlauts) or a number is considered one word,
* all other lines are ignored, so you can use wikka-markup.
* Lines which shall be ignored, but don't start with wikka-markup
* only need a single space at the beginning.
*
* @package actions
* @name bingo
*
* @author {@link http://wikka.jsnx.com/TimoK TimoK}
* @version 0.2
*
* @param string $seed name of the page containing the word list
* @param string $joker optional; the string to use for free fields
* default: "" (empty string)
* @output a 5x5-table containing 24 words from seed and 1 joker
*
* @todo nothing?
*/
// Configuration
$bingo_delimiter =
"\n";
$bingo_joker =
"";
$bingo_validseed =
"/^[A-Z,a-z,ÄÖÜ,äöü]+[A-Z,a-z,0-9,ÄÖÜ,ßäöü]*$/s";
// Functions
function cleanup
(&
$item) {
return preg_match("/^[A-Za-z0-9ÄÖÜßäöü].*/",
$item) ?
TRUE :
FALSE;
}
function print_card
($words,
$joker) {
global $wakka;
print "<table class='bingocard'>\n";
for ($i =
0;
$i <
25;
$i++
) {
if (($i %
5) ==
0) print "<tr class='bingorow'>\n";
if ($i <
12) {
print "<td>" .
$words[$i] .
"</td>\n";
} elseif ($i ==
12) {
print "<td class='bingojoker'>" .
$wakka->
ReturnSafeHtml($joker) .
"</td>\n";
} else {
print "<td>" .
$words[$i-
1] .
"</td>\n";
}
if ((($i +
1) %
5) ==
0) print "</tr>\n";
}
print "</table>";
}
// Init & Check-Up
srand ((float
)microtime()*
1000000);
if (!
is_array($vars)) {
print "Error in action call, please refer to the documentation, aborting!";
} elseif (!
is_string($vars["seed"])) {
print "You need to specify a seed for the game card creation, aborting!";
} elseif (!
preg_match($bingo_validseed,
$vars["seed"])) {
print "The seed you supplied is no valid page name, aborting!";
} elseif (!
$this->
ExistsPage($vars["seed"])) {
print "The seed you supplied is no existing page, aborting!";
} elseif ($page =
$this->
LoadPage($vars["seed"])) {
if(is_string($vars["joker"])) {
$bingo_joker =
$vars["joker"];
}
// Get the words, clean up and shuffle
$bingo_words =
explode($bingo_delimiter,
$page["body"]);
$bingo_words =
array_filter($bingo_words,
"cleanup");
$bingo_words =
array_unique($bingo_words);
shuffle($bingo_words);
// We need an array of 24 words
$bingo_size =
sizeof($bingo_words);
if ($bingo_size <
12) {
print "Your seed contains less than 12 valid words, aborting!";
} else {
if ($bingo_size <
24) {
$bingo_words =
array_merge($bingo_words,
$bingo_words);
}
if ($bingo_size >
24) {
$bingo_words =
array_slice($bingo_words,
0,
24);
}
print_card
($bingo_words,
$bingo_joker);
}
} else {
print "Unknown Error, aborting!";
}
?>
example css
.bingocard {
border: 1px solid #000;
border-collapse: collapse;
margin: 5px;
}
.bingorow td {
border: 1px solid #000;
padding: 3px;
text-align: center;
}
.bingojoker {
background: #09d;
}
CategoryUserContributions