} elseif (isset($_GET['fave'])) { if (empty($_GET['fave']) || !is_numeric($_GET['fave'])) { header('Content-Type: image/png'); readfile('images/frown.png'); exit; } $trainer = (int) $_GET['fave']; $userdata = userdata($trainer); if (empty($userdata[0]['fave'])) { header('Content-Type: image/png'); readfile('images/nopoke.png'); } else { header('Content-Type: image/gif'); readfile('img/anim2/' . (is_shiny($userdata[0]['fave']) ? 'shiny/' : '') . sprintf("%03d", round($userdata[0]['fave'])) . '.gif'); } } elseif (isset($_GET['faveback'])) { if (empty($_GET['faveback']) || !is_numeric($_GET['faveback'])) { header('Content-Type: image/png'); readfile('images/frown.png'); exit; } $trainer = (int) $_GET['faveback']; $userdata = userdata($trainer); if (empty($userdata[0]['fave'])) { header('Content-Type: image/png'); readfile('images/nopoke.png'); } else { header('Content-Type: image/png'); readfile('img/back/' . (is_shiny($userdata[0]['fave']) ? 'shiny/' : '') . sprintf("%03d", round($userdata[0]['fave'])) . '.png'); } }
function release_pokemon($id, $release) { //Accepts either a single string ID or a single / multi element array of pokemon to remove. Removes those pokemon from the trainer's inventory and, if neccessary, removes that trainer from (each) pokemon's trainer inventory. If successful, returns a results array of each pokemon deleted and each (if any) pokemon orphaned. If fails, returns a string error message. global $pokemon, $file_db; if (empty($id) || empty($release)) { return 'Missing parameters'; } //It may be that a single pokemon is still submitted in an array form, for example from the release page. Fix these to be actual strings. if (count($release) === 1) { $release = $release[0]; } //First, get our user's info. From release page to releasing this shouldn't be different, but they may have been trying silly duplication tricks such as a simultaneous trade and release. $userdata = $file_db->query('SELECT pokemon FROM trainers WHERE id=' . $id . '')->fetchAll(); if (empty($userdata)) { return 'No pokemon to deal with'; } //What pokemon does this trainer currently own? $owned_pokemon = explode(',', $userdata[0]['pokemon']); $previous_pokemon = $owned_pokemon; //Store a copy of their current (or now, previous) pokemon for later. //First, remove the pokemon(s?) from the trainer's inventory. It may be that after our deleting is done the trainer may still own one of the pokemon in question. //If they're only deleting a single pokemon, we'll go through the user's pokemon and if we come across the one they wish to delete, drop it. if (!is_array($release)) { foreach ($owned_pokemon as $key => $value) { //Even if a user only has one pokemon, it's still represented as a single-entry array. if ($value == $release) { unset($owned_pokemon[$key]); $releasedp[] = $release; break; //If left, would delete all pokemon with that #. Just one please. } } } else { //The user wishes to delete multiple pokemon. foreach ($release as $release_pokemon) { //Largely the same, just go through each item and do the same as above foreach ($owned_pokemon as $key => $value) { if ($value == $release_pokemon) { unset($owned_pokemon[$key]); $releasedp[] = $release_pokemon; break; } } } } //Whatever we did, we need to compare their previous and new pokemon collection to find out which pokemon are not owned at all by that trainer any more. $orphaned_pokemon = array_diff($previous_pokemon, $owned_pokemon); //Deleting multiple of a certain pokemon to exhaustion will cumulatively trigger duplicate orphan entries. We don't want that. $orphaned_pokemon = array_unique($orphaned_pokemon); //These are our strings, ready to put back in the database. $previous_pokemon_string = implode(',', $previous_pokemon); //We don't actually need this one, except for debugging! $owned_pokemon_string = implode(',', $owned_pokemon); //We're done with the trainer, now on to the pokemon. That is, if there are any orphaned pokemon. if (!empty($orphaned_pokemon)) { //A shiny pokemon (eg 25.3) is stored under the key 25, so we must round our elements. If they are emptying both all their shiny and non-shiny of a pokemon though, we would end up with duplicates. $qorphaned_pokemon = array_map('round', $orphaned_pokemon); $qorphaned_pokemon = array_unique($qorphaned_pokemon); //The following mess queries all our relevant orphaned pokemon data, formatted in a nice array of [#pokemon] => [owners] / [shiny_owners], each containing our user strings. $imporphan = implode(' OR id=', $qorphaned_pokemon); $orphandataquery = 'SELECT id, owners, shiny_owners FROM pokemon WHERE id=' . $imporphan . ' ORDER BY ID ASC'; $orphandata = $file_db->query($orphandataquery)->fetchAll(PDO::FETCH_GROUP | PDO::FETCH_ASSOC); $orphandata = array_map('reset', $orphandata); } //At this point, we've finished all our querying. It's time to start writing. As we're potentially making a lot of write queries, we should include them all in one transaction for speed. $file_db->beginTransaction(); $file_db->query("UPDATE trainers SET pokemon='" . $owned_pokemon_string . "' WHERE id=" . $id . ""); //Update the trainer's pokemon inventory. if (!empty($orphaned_pokemon)) { foreach ($orphaned_pokemon as $orphan) { //Loop through our orphaned pokemon and, for each one, remove our trainer from its owner list. Shiny, or not, or both. if (is_shiny($orphan)) { //shiny_owners pls. $sotrainers = explode(',', $orphandata[round($orphan)]['shiny_owners']); foreach ($sotrainers as $key => $value) { if ($value == $id) { unset($sotrainers[$key]); break; //We'll only have one trainer entry, but no need to continue looping once we've found them. } } $query = "UPDATE pokemon SET shiny_owners = '" . implode(',', $sotrainers) . "' WHERE id=" . round($orphan) . ""; $file_db->exec($query); } else { //Normal pokemon. $ntrainers = explode(',', $orphandata[round($orphan)]['owners']); foreach ($ntrainers as $key => $value) { if ($value == $id) { unset($ntrainers[$key]); break; } } $query = "UPDATE pokemon SET owners = '" . implode(',', $ntrainers) . "' WHERE id=" . $orphan . ""; $file_db->exec($query); } unset($query); //Be on the safe side. } } //Now we're done, commit our writes. $file_db->commit(); //Build our status array to return to the requesting page or function. if (isset($releasedp)) { $status['released'] = $releasedp; } if (!empty($orphaned_pokemon)) { $status['orphaned'] = $orphaned_pokemon; } return $status; }
function cprite($poke, $link = false) { //Outputs a CSS-based sprite of the pokemon given. Auto detects shiny or not, and defaults to 96x96 base image. Optionally makes the sprite clickable, as a link to the pokemon's page. global $pokemon; //First off, which sprite sheet does this poke refer to? $pid = round($poke); if ($pid >= 0 && $pid <= 251) { $sheet = 'g12'; } elseif ($pid >= 252 && $pid <= 493) { $sheet = 'g34'; } elseif ($pid >= 494 && $pid <= 719) { $sheet = 'g56'; } else { die('<!-- WARNING - Unknown Pokemon For CSS Sprite! -->'); } //Is this pokemon shiny? if (is_shiny($poke)) { $suffix = 's'; } else { $suffix = 'n'; } //Finally, zero pad our poke. $p = sprintf("%03d", $poke); if ($link) { echo ' <a class="cprite ' . $sheet . $suffix . ' p' . $p . '" href="?pokemon=' . $pid . ';' . $pokemon[$pid] . '"></a>'; } else { echo ' <div class="cprite ' . $sheet . $suffix . ' p' . $p . '"></div>'; } }
if (empty($userdata[0]['pokemon'])) { die('This trainer has no pokemon'); } $owned_pokemon = explode(',', $userdata[0]['pokemon']); sort($owned_pokemon); //We only wish to show each pokemon once, but still recognise duplicates. $dupe_check = array_count_values($owned_pokemon); echo $ajaxnotice . '<div style="height: 20px;clear:both;"></div><div style="clear:both;padding: 20px 0px; text-align: center; border-top: 5px dashed #555;">Owned Pokemon:</div>'; foreach ($owned_pokemon as $poke) { if (isset($dupe_shown)) { if (in_array($poke, $dupe_shown)) { continue; } } echo '<div class="pbox pokeborder' . (is_shiny($poke) ? ' shiny' : '') . '"><div class="pokenumber">#', round($poke), '</div><a href="?pokemon=' . round($poke) . '"><img src="' . $baseurl . 'img/' . (is_shiny($poke) ? 'shiny/' : '') . sprintf("%03d", round($poke)) . '.png" /></a><br> <span' . (is_shiny($poke) ? ' class="shiny">' : '>') . $pokemon[round($poke)] . '</span>', $dupe_check[$poke] > 1 ? '<div class="multipoke"><img src="' . $baseurl . 'images/pokeballsmall.png" />' . $dupe_check[$poke] . '</div>' : '', '</div>'; if ($dupe_check[$poke] > 1) { $dupe_shown[] = $poke; } } } elseif ($_REQUEST['type'] == "dex") { //This could still be the case. if (empty($userdata[0]['dex'])) { die('This trainer\'s pokedex is empty'); } $dex_pokemon = explode(',', $userdata[0]['dex']); sort($dex_pokemon); echo $ajaxnotice . '<div style="height: 20px;clear:both;"></div><div style="clear:both;padding: 20px 0px; text-align: center; border-top: 5px dashed #555;">Pokedex Entries:</div>'; foreach ($dex_pokemon as $poke) { echo '<div class="pbox pokeborder"><div class="pokenumber">#', round($poke), '</div><a href="?pokemon=' . round($poke) . '"><img src="' . $baseurl . 'img/' . sprintf("%03d", round($poke)) . '.png" /></a><br> <span>', $pokemon[round($poke)], '</span></div>';
} empty($owned_pokemon) ? $trainer['total_pokemon'] = 0 : ($trainer['total_pokemon'] = count($owned_pokemon)); empty($seen_pokemon) ? $trainer['total_seen'] = 0 : ($trainer['total_seen'] = count($seen_pokemon)); empty($dex_pokemon) ? $trainer['total_dex'] = 0 : ($trainer['total_dex'] = count($dex_pokemon)); if (!empty($owned_pokemon)) { $trainer['pokemon']['string'] = $userdata['pokemon']; $trainer['pokemon']['raw'] = $owned_pokemon; foreach ($owned_pokemon as $opoke) { $trainer['pokemon']['named'][$opoke] = $pokemon[round($opoke)] . (is_shiny($opoke) ? ' (Shiny)' : ''); } } if (!empty($seen_pokemon)) { $trainer['seen']['string'] = $userdata['seen']; $trainer['seen']['raw'] = $seen_pokemon; foreach ($seen_pokemon as $opoke) { $trainer['seen']['named'][$opoke] = $pokemon[round($opoke)] . (is_shiny($opoke) ? ' (Shiny)' : ''); } } if (!empty($dex_pokemon)) { $trainer['dex']['string'] = $userdata['dex']; $trainer['dex']['raw'] = $dex_pokemon; foreach ($dex_pokemon as $opoke) { $trainer['dex']['named'][$opoke] = $pokemon[$opoke]; } $trainer['dex']['percentage'] = round(count($dex_pokemon) / count($pokemon) * 100, 2); } if (isset($_GET['html'])) { echo '<pre>'; } if (isset($_GET['raw'])) { echo json_encode($trainer);
function trainer_box($id) { global $file_db, $userdata, $context, $smf_userdata, $admin_users, $baseurl, $pcfg, $pokemon; if (isset($userdata)) { if ($id != $userdata[0]['id']) { $userdata = userdata($id); echo '<!-- ID mismatch, reloaded userdata for trainerbox -->'; } } $smf_userdata = pokemon_fetchMember($member_ids = $id, $output_method = 'array'); echo ' <div class="trainer_box pokeborder"> ' . (empty($userdata[0]['version']) ? '' : '<span style="color:' . $pcfg['color' . $userdata[0]['version']] . ';" title="' . $pcfg['version' . $userdata[0]['version']] . '">•</span>') . '', $smf_userdata[$id]['name'], ' <a href="http://rmrk.net/?action=profile;u=' . $id . '"><img src="images/rmrk_link.png" alt="RMRK Profile" /></a><hr> ', isset($userdata[0]['fave']) ? '<p class="trainerfave">' : '', ' <img src="images/trainers/', $userdata[0]['trainerpic'], '.gif" class="trainerpic"/>'; if (isset($userdata[0]['fave'])) { echo '<img class="trainer_fave_pokemon" src="' . $baseurl . 'img/anim2/' . (is_shiny($userdata[0]['fave']) ? 'shiny/' : '') . sprintf("%03d", round($userdata[0]['fave'])) . '.gif" />'; } echo ' ', isset($userdata[0]['fave']) ? '</p>' : '', ''; if (!empty($userdata[0]['extrafave'])) { echo '<br>'; $userfaves = explode(',', $userdata[0]['extrafave']); foreach ($userfaves as $ufave) { echo '<img src="' . $baseurl . 'img/small/' . (is_shiny($ufave) ? 'shiny/' : '') . sprintf("%03d", round($ufave)) . '.png" style="background:url(images/team_ball.png) center center no-repeat;" title="' . $pokemon[round($ufave)] . (is_shiny($ufave) ? ' (Shiny)' : '') . '">'; } } echo ' <hr>'; badge_strip($id, $userdata); echo ' ', empty($userdata[0]['lastcaught']) ? '' : '<div>Last Caught:<span> ' . date('M jS, Y', $userdata[0]['lastcaught']) . '</span></div>', ' <div>Trainer Since:<span>', date('M jS, Y', $userdata[0]['starttime']), '</span></div><br><br><hr> ', empty($userdata[0]['seen']) ? '' : '<div>Pokemon Seen:<span> ' . count(explode(',', $userdata[0]['seen'])) . '</span></div>', ' ', empty($userdata[0]['pokemon']) ? '' : '<div>Pokemon Owned:<span> ' . count(explode(',', $userdata[0]['pokemon'])) . '</span></div>', ' ', empty($userdata[0]['dex']) ? '' : '<div>Pokedex Entries:<span> ' . count(explode(',', $userdata[0]['dex'])) . '</span></div>', ''; if ($context['user']['id'] == $id || $pcfg['is_admin'] == true || ($userdata[0]['opentrade'] == 1 || in_array($context['user']['id'], $smf_userdata[$id]['buddies'])) && $context['user']['is_logged']) { echo '<br><br><br><hr>'; if ($context['user']['id'] == $id || $pcfg['is_admin'] == true) { echo '<a style="margin: 0px auto;" href="?release=' . $id . '"><img src="images/releasep.png" title="Release Pokemon" /></a> '; } if (($userdata[0]['opentrade'] == 1 || in_array($context['user']['id'], $smf_userdata[$id]['buddies'])) && $id != $context['user']['id']) { echo ' <a style="margin: 0px auto;" href="?trade;open=' . $id . '"><img src="images/tradeball.png" title="Trade with ', $smf_userdata[$id]['name'], '" /></a>'; } if (!empty($userdata[0]['pokemon']) && $context['user']['id'] != $id) { echo ' <a href="?compare=' . $id . '"><img src="images/poke_diff.png" title="Compare Pokemon" /></a>'; } } echo '</div>'; }