i made this little widget to display the top gamers and the “gamemaster” in wordpress for the really cool “myarcade Plugin”. myarcade adds a aracde center to your wordpress blog. you can see an example of the widget on www.pukepals.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
<?php function random_color(){ mt_srand((double)microtime()*1000000); $c = ''; while(strlen($c)<6){ $c .= sprintf("%02X", mt_rand(0, 255)); } return $c; } require_once('./wp-includes/wp-db.php'); global $wpdb; $game = ''; $start=true; $highscore=0; $info = $wpdb->get_results( " SELECT name as game, MAX(CONVERT(score, SIGNED)) as highscore, display_name as user, post_name as link from wp_myarcadegames LEFT JOIN wp_myarcadescores ON (wp_myarcadescores.game_tag = wp_myarcadegames.game_tag) LEFT JOIN wp_users ON (wp_users.ID = wp_myarcadescores.user_id) LEFT JOIN wp_posts ON (wp_posts.ID = wp_myarcadegames.postid) where wp_myarcadegames.status = 'published' and wp_myarcadegames.postid <> 0 and score > 0 group by display_name, name order by name, score "); ?> <style> .execphpwidget > div > table { border-collapse: separate; border-spacing: 2px; border: 2px solid #70CCFF; font-size: 8pt; } .execphpwidget > div > table > tbody > tr > td { border-spacing: 2px; padding: 2px 3px 2px 3px; border: 1px solid grey; } .execphpwidget > div > table > thead > tr > th { text-align: left; color: #70CCFF; } </style> <div align="center"> <table class = "irgendwas"> <thead> <tr> <th>Game</th> <th>Score</th> <th>Gamer</th> </tr> </thead> <tbody> <?php $html=''; $gameSum=0; foreach($info as $value) { if (!$start && $game <> $value->game) { if ($gamerColor[$winner] == NULL) { $gamerColor[$winner] = '#'.random_color(); } $html.= '<tr><td><a href=http://<your site>/'.$link.'>'.$game.'</a></td><td align="right">'.$winnerscore.'</td><td align="center"><span style="color:'.$gamerColor[$winner].';">'.$winner.'</span></td></tr>'; $highscore=0; $gameSum++; $leader[$winner]++; } if ($highscore < $value->highscore) { $winner = $value->user; $winnerscore = $value->highscore; $highscore = $winnerscore; $link = $value->link; } $game = $value->game; $start = false; } if ($gamerColor[$winner] == NULL) { $gamerColor[$winner] == '#'.random_color(); } $html.= '<tr><td><a href=http://<your site>/'.$link.'>'.$game.'</a></td><td align="right">'.$winnerscore.'</td><td align="center"><span style="color:'.$gamerColor[$winner].';">'.$winner.'</span></td></tr>'; $gameSum++; $leader[$winner]++; $leaderMax=0; foreach ($leader as $key=>$value) { if ($value > $leaderMax) { $winner = $key; $scoreId = $key; } else if ($value == $leaderMax) { $winner = $winner.' ex aequo '.$key; $scoreId = $key; } $leaderMax = $value; } echo ('Game Master: <strong><span style="color: #70CCFF">'. $winner.'</span></strong> - Wins: <strong><span style="color: #70CCFF">'.$leader[$scoreId].'/'.$gameSum.'</span></strong>'); echo ($html); ?> </tbody> </table> </div> |