All pastes #739711 Raw Edit

Anonymous

public php v1 · immutable
·published 2007-10-17 12:29 UTC
rendered paste body
<?phpinclude "mysql.php";?><h1>Matches</h1><?php/* Example phpbb post:opponent: Kill or Dietime: 1192377600server: |x|.Fortress.Servertype: AFLscoreshome: 46 66 64scoresopponent: 100 106 104recording: http://kowsklan.free.fr/recordings/afl/2007Fall/Week%201/TDvsKoD-2007-10-14-AFL.aarec.zipscreenshot: http://img502.imageshack.us/img502/6132/screenshot705ha8.pngscreenshot: http://img88.imageshack.us/img88/623/screenshot706db6.pngscreenshot: http://img201.imageshack.us/img201/4426/screenshot708aj0.png*/// Give here the forum_id which contains matches postsdefine(FORUM_ID, 11);function get_matches (){ db_connect(); $matchesres = mysql_query("SELECT `post_text`,`post_id` FROM `phpbb_posts_text` WHERE `post_id` IN (SELECT `post_id` FROM `phpbb_posts` WHERE `forum_id` = ". FORUM_ID .")"); $matches; $nummatches = mysql_num_rows($matchesres); for($i = 0; $i < $nummatches; $i++) {  $match_id = mysql_result($matchesres, $i, 'post_id');  $matches[$match_id] = mysql_result($matchesres, $i); } return $matches;}function get_match ($id){ db_connect(); $matchesres = mysql_query("SELECT `post_text`,`post_id` FROM `phpbb_posts_text` WHERE `post_id` IN (SELECT `post_id` FROM `phpbb_posts` WHERE `forum_id` = " . FORUM_ID . " AND `post_id`= $id)"); $matches; $nummatches = mysql_num_rows($matchesres);  if ($nummatches = 0) return 0;   $match_id = mysql_result($matchesres, 0, 'post_id'); $matches[$match_id] = mysql_result($matchesres, 0); return $matches;}function parse_post ($postmessage, $id){ $regexp_url = "([http:\/\/|HTTP:\/\/|https:\/\/|HTTPS:\/\/][a-zA-Z.0-9-]*[\/a-zA-Z.-_]*\/[\/a-zA-Z0-9%._-]*)"; echo "<!-- $regexp_url -->"; # parse the message $opponent; $time; $server; $type; $scoreshome; $scoresopponent; $recording; $screenshots; preg_match ('@^opponent: ([^\r\n\f]+)@m', $postmessage, $opponent); preg_match ("@^time: ([0-9]+)@m", $postmessage, $time); preg_match ('@^server: ([^\r\n\f]+)@m', $postmessage, $server); preg_match ('@^type: ([^\r\n\f]+)@m', $postmessage, $type); preg_match ("@^scoreshome: ([0-9 ]+)@m", $postmessage, $scoreshome); preg_match ("@^scoresopponent: ([0-9 ]+)@m", $postmessage, $scoresopponent); preg_match ("@^recording: $regexp_url@m", $postmessage, $recording); preg_match_all ("@^screenshot: $regexp_url@m", $postmessage, $screenshots);  $match; $match['id'] = $id; $match['opponent'] = $opponent[1]; $match['time'] = $time[1]; $match['server'] = $server[1]; $match['type'] = $type[1]; $match['scoreshome'] = explode(" ", $scoreshome[1]); $match['matchescount'] = count($match['scoreshome']); $match['scoresopponent'] = explode(" ", $scoresopponent[1]); $match['recording'] = $recording[1]; $match['screenshots'] = $screenshots[1]; $match['scorehome'] = 0; $match['scoreopponent'] = 0; #determines won matches for ($i = 0;$i < $match['matchescount']; $i++) {    if($match['scoreshome'][$i] < $match['scoresopponent'][$i])   $match['scoreopponent']++;  else   $match['scorehome']++; } $match['winner'] = ($match['scorehome'] > $match['scoreopponent'])? "Tronic Donkeys" : $match['opponent'];/* echo "<!--"; var_export($match); echo "-->"; */# var_export($opponent); var_export($time); var_export($server); var_export($type); var_export($scorehome); var_export($scoreopponent); var_export($recording); var_export($screenshots); return $match; }function order_match(&$match, &$past, &$present, &$future){ if ($match['scoreshome'][0] !== "")  $past[]=$match; else if ($match['time'] < time())  $present[]=$match; else  $future[]=$match;}function compare_match_times($a, $b){ if ($a['time'] == $b['time']) return 0; return ($a['time'] > $b['time'])? 1 : -1;}function print_matches($past, $present, $future){ ?><table id="matches"> <thead>  <tr class="firstline">   <td>Opponent</td>   <td>Time</td>   <td>Server</td>   <td>Type</td>   <td>Score</td>   <td>Winner</td>  </tr> </thead> <tbody><?php if (isset($present[0])) {  echo "<tr><td class='now' colspan='6'>Current running matches</td></tr>";  foreach($present as $match)  {   echo "<tr><td>{$match['opponent']}</td><td>".date("Y/m/d H:i", $match['time'])." GMT</td><td>{$match['server']}</td><td>{$match['type']}</td><td class='noresults' colspan='2'><a href='?c=5&amp;m={$match['id']}'>No results yet</a></td></tr>";  } } if (isset($future[0])) {  echo "<tr><td class='future' colspan='6'>Next upcoming matches</td></tr>";  foreach($future as $match)  {   echo "<tr><td>{$match['opponent']}</td><td>".date("Y/m/d H:i", $match['time'])." GMT</td><td>{$match['server']}</td><td>{$match['type']}</td><td class='noresults' colspan='2'><a href='?c=5&amp;m={$match['id']}'>No results yet</a></td></tr>";  } } if (isset($past[0])) {  echo "<tr><td class='past' colspan='6'>Past matches</td></tr>";  foreach($past as $match)  {   echo "<tr><td>{$match['opponent']}</td><td>".date("Y/m/d H:i", $match['time'])." GMT</td><td>{$match['server']}</td><td>{$match['type']}</td><td><a href='?c=5&amp;m={$match['id']}'>" . $match['scorehome'] . " - " . $match['scoreopponent'] . "</a></td><td>{$match['winner']}</td></tr>";  } } ?> </tbody> </table> <?php}function print_match ($matchdata){ echo "<table>"; echo "<tr class='firstline'><td colspan='2'>Tronic Donkeys VS {$matchdata['opponent']}, the ". date("j \of F", $matchdata['time']) ."</td></tr>"; echo "<tr><td>Date</td><td>The ". date("jS \of F, Y", $matchdata['time'])  ."</td></tr>"; echo "<tr><td>Time</td><td>" . date("H:i", $matchdata['time']) . " GMT</td></tr>"; echo "<tr><td>Server</td><td>{$matchdata['server']}</td></tr>"; echo "<tr><td>Type</td><td>{$matchdata['type']}</td></tr>"; if ($matchdata['scoreshome'][0] != '') {  echo "<tr><td class='results' colspan='2'>Results</td></tr>";  for($i = 0; $i < $matchdata['matchescount']; $i++)  {   echo "<tr><td>Match ". ($i + 1) ."</td><td><a href='{$matchdata['screenshots'][$i]}'>{$matchdata['scoreshome'][$i]}-{$matchdata['scoresopponent'][$i]}</a></td></tr>";  }  echo "<tr><td>Final scores</td><td>{$matchdata['scorehome']}-{$matchdata['scoreopponent']}</td></tr>";  echo "<tr><td>Winner</td><td>{$matchdata['winner']}</td></tr>";  echo "<tr><td>Recording</td><td><a href='{$matchdata['recording']}'>Click here</a></td></tr>"; } echo "</table>";}function list_all(){ $pastmatches; $currentmatches; $upcomingmatches; $matches = get_matches(); foreach ($matches as $match_id => $match) {  $matchdata = parse_post($match, $match_id);  order_match($matchdata, $pastmatches, $currentmatches, $upcomingmatches); } @usort($pastmatches, "compare_match_times"); @usort($currentmatches, "compare_match_times"); @usort($upcomingmatches, "compare_match_times"); print_matches($pastmatches, $currentmatches, $upcomingmatches);}function match_info ($id){ $match = get_match($id); if ($match == 0) {  echo "<p>There is no such match. <a href='?c=5'>Return</a></p>";  return; } $matchdata = parse_post($match[$id], $id); print_match($matchdata); echo "<p><a href='?c=5'>Return</a></p>";}?><?phpif(isset($_GET['m'])){ match_info($_GET['m']);}else{ list_all();}?>