Skip to content

Instantly share code, notes, and snippets.

@shadda
Created August 14, 2013 09:19
Show Gist options
  • Select an option

  • Save shadda/6229321 to your computer and use it in GitHub Desktop.

Select an option

Save shadda/6229321 to your computer and use it in GitHub Desktop.
<?php
class TileMaker
{
public static function getDataPool($data, $max_entries)
{
$len = count($data);
$results = array();
if($len >= $max_entries)
{
$pool = array();
$pools = (int) ceil( $len / $max_entries );
for($i = 0; $i < $pools; $i++)
{
$min = $max_entries * $i;
$pool = array_slice($data, $min, $max_entries);
if(count($pool) > 0)
{
$results[] = $pool;
}
}
}
else if($len > 0)
{
$results[] = array($data);
}
return $results;
}
public static function sendTheShizzle(array $tiles)
{
$datapool = self::getDataPool($tiles, 10);
foreach($datapool as $pool)
{
$post_data = array('tile_data' => json_encode($pool));
$post_data = http_build_query($post_data);
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $post_data
)
);
$context = stream_context_create($opts);
echo file_get_contents('http://gilgamesh.synful.us/map.importtiledata.ajax', false, $context), "\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment