ProfesseurCraft

Exemple présentation class PHP MinecraftQuery

Jul 18th, 2013
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.14 KB | None | 0 0
  1. <?php
  2.     // Edit this ->
  3.     define( 'MQ_SERVER_ADDR', 'localhost' ); //remplacez 'localhost' par l'adresse de votre serveur
  4.     define( 'MQ_SERVER_PORT', 25565 ); //remplacez 25565 par le port de votre serveur
  5.     define( 'MQ_TIMEOUT', 1 );
  6.     // Edit this <-
  7.  
  8.     // Display everything in browser, because some people can't look in logs for errors
  9.     Error_Reporting( E_ALL | E_STRICT );
  10.     Ini_Set( 'display_errors', true );
  11.  
  12.     require __DIR__ . '/MinecraftQuery.class.php'; //ligne qui inclut la class MinecraftQuery
  13.  
  14.     $Timer = MicroTime( true );
  15.     $Query = new MinecraftQuery( );
  16.  
  17.     try
  18.     {
  19.         $Query->Connect( MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_TIMEOUT );
  20.     }
  21.     catch( MinecraftQueryException $e )
  22.     {
  23.         $Error = $e->getMessage( );
  24.     }
  25. ?>
  26. <!DOCTYPE html>
  27. <html lang="en">
  28. <head>
  29.     <meta charset="utf-8">
  30.     <title>Minecraft Query PHP Class</title>
  31.    
  32.     <link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
  33.     <style type="text/css">
  34.         footer {
  35.             margin-top: 45px;
  36.             padding: 35px 0 36px;
  37.             border-top: 1px solid #e5e5e5;
  38.         }
  39.         footer p {
  40.             margin-bottom: 0;
  41.             color: #555;
  42.         }
  43.     </style>
  44. </head>
  45.  
  46. <body>
  47.     <div class="container">
  48.         <div class="page-header">
  49.             <h1>Minecraft Query PHP Class</h1>
  50.         </div>
  51.  
  52. <?php if( isset( $Error ) ): ?>
  53.         <div class="alert alert-info">
  54.             <h4 class="alert-heading">Exception:</h4>
  55.             <?php echo htmlspecialchars( $Error ); ?>
  56.         </div>
  57. <?php else: ?>
  58.         <div class="row">
  59.             <div class="span6">
  60.                 <table class="table table-bordered table-striped">
  61.                     <thead>
  62.                         <tr>
  63.                             <th colspan="2">Server info</th>
  64.                         </tr>
  65.                     </thead>
  66.                     <tbody>
  67. <?php if( ( $Info = $Query->GetInfo( ) ) !== false ): ?>
  68. <?php foreach( $Info as $InfoKey => $InfoValue ): ?>
  69.                         <tr>
  70.                             <td><?php echo htmlspecialchars( $InfoKey ); ?></td>
  71.                             <td><?php
  72.     if( Is_Array( $InfoValue ) )
  73.     {
  74.         echo "<pre>";
  75.         print_r( $InfoValue );
  76.         echo "</pre>";
  77.     }
  78.     else
  79.     {
  80.         echo htmlspecialchars( $InfoValue );
  81.     }
  82. ?></td>
  83.                         </tr>
  84. <?php endforeach; ?>
  85. <?php endif; ?>
  86.                     </tbody>
  87.                 </table>
  88.             </div>
  89.             <div class="span6">
  90.                 <table class="table table-bordered table-striped">
  91.                     <thead>
  92.                         <tr>
  93.                             <th>Players</th>
  94.                         </tr>
  95.                     </thead>
  96.                     <tbody>
  97. <?php if( ( $Players = $Query->GetPlayers( ) ) !== false ): ?>
  98. <?php foreach( $Players as $Player ): ?>
  99.                         <tr>
  100.                             <td><?php echo htmlspecialchars( $Player ); ?></td>
  101.                         </tr>
  102. <?php endforeach; ?>
  103. <?php else: ?>
  104.                         <tr>
  105.                             <td>No players in da house!</td>
  106.                         </tr>
  107. <?php endif; ?>
  108.                     </tbody>
  109.                 </table>
  110.             </div>
  111.         </div>
  112. <?php endif; ?>
  113.         <footer>
  114.             <p class="pull-right">Generated in <span class="badge badge-success"><?php echo Number_Format( ( MicroTime( true ) - $Timer ), 4, '.', '' ); ?>s</span></p>
  115.            
  116.             <p>Written by <a href="http://xpaw.ru" target="_blank">xPaw</a></p>
  117.             <p>Code licensed under the <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" target="_blank">CC BY-NC-SA 3.0</a></p>
  118.             <p>Sourcecode available on <a href="https://github.com/xPaw/PHP-Minecraft-Query" target="_blank">GitHub</a></p>
  119.         </footer>
  120.     </div>
  121. </body>
  122. </html>
Advertisement
Add Comment
Please, Sign In to add comment