Advertisement
coffeehedake

MCStatusWidget

Sep 1st, 2012
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: MCStatusWidget
  4. Plugin URI: Waiting for URI
  5. Description: Display Minecraft Server Status of all types.
  6. Version: 1.1
  7. Author: WhiteSK
  8. Author URI: Waiting for URI
  9. License: GPL3
  10. */
  11.  
  12. /*
  13. * MCStatusWidget
  14. * Copyright (C) 2012 WhiteSK.
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation, either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29.  
  30. if (!class_exists('MinecraftQuery')) {
  31. require('statusclass.php');
  32. }
  33.  
  34. defined('ABSPATH') or die("Cannot access pages directly.");
  35.  
  36. add_action( 'widgets_init', create_function( '', 'register_widget("MCStatusWidget");' ) );
  37.  
  38. class MCStatusWidget extends WP_Widget
  39. {
  40. function MCStatusWidget() {
  41. $widget_ops = array(
  42. 'classname' => 'MCStatusWidget',
  43. 'description' => 'Minecraft server status...'
  44. );
  45. $this->WP_Widget( 'MCStatusWidget', 'MCStatusWidget', $widget_ops );
  46. }
  47.  
  48. function widget($args, $instance) {
  49. extract( $args );
  50. $title = apply_filters('widget_title', $instance['title'] );
  51. $mq_ip = $instance['mq_ip'];
  52. $mq_port = $instance['mq_port'];
  53. echo "
  54. <script type='text/javascript'>
  55. function togluj(id) {
  56. $('#' + id).toggle('slow');
  57. }
  58.  
  59. </script>";
  60. echo $before_widget;
  61. $mc = new MinecraftQuery();
  62. $mc->connect($mq_ip,$mq_port);
  63. $info = $mc->GetInfo();
  64. $players = $mc->GetPlayers();
  65. if(empty($title) || $info) echo $before_title . $info['HostName'] . $after_title;
  66. else echo $before_title . $title . $after_title;
  67. echo "<table>";
  68. if (!$info) {
  69. echo"<tr><td>Status: &nbsp;</td><td><b><font style='color:red;'>Offline</font></b></td></tr>";
  70. echo"<tr><td>IP Port: &nbsp;</td><td><b>{$mq_ip}:{$mq_port}</b></td></tr>";
  71. } else {
  72. echo"<tr><td>Status: &nbsp;</td><td><b><font style='color:green;'>Online</font></b></td></tr>";
  73. echo"<tr><td>IP Port: &nbsp;</td><td><b>{$mq_ip}:{$mq_port}</b></td></tr>";
  74. echo "<tr><td>Verze: &nbsp;</td><td><b>{$info['Version']}</b></td></tr>";
  75. echo "<tr><td>Odozva: &nbsp;</td><td><b>{$info['Latency']} ms</b></td></tr>";
  76. echo "<tr><td>Mapa: &nbsp;</td><td><b>{$info['Map']}</b></td></tr>";
  77. echo("<tr><td>Hráči: &nbsp;</td><td><b>{$info['Players']} / {$info['MaxPlayers']}</b></td></tr>");
  78. }
  79. echo "</table>";
  80. if($info) {
  81. ?>
  82. <a href='javascript:void(0)' onClick='togluj("<?=$mq_port?>")'>Hráči Online / Pluginy</a>
  83. <?php
  84. echo "<div id='{$mq_port}' style='display: none; font-weight: bold;'>";
  85. if($info['Players'] == 0) echo "Žádny hráči na serveru..<br>";
  86. else {
  87. foreach($players as $player):
  88. echo "- $player <br>";
  89. endforeach;
  90. }
  91. echo "<br> Pluginy: <br><i>";
  92. foreach($info['Plugins'] as $plugin) {
  93. echo "$plugin, ";
  94. }
  95. echo "</i>";
  96. echo "</div>";
  97. }
  98. echo $after_widget;
  99. }
  100.  
  101.  
  102. function form( $instance ) {
  103. $defaults = array( 'title' => 'Survival', 'mq_ip' => 'mine-crafters.eu', 'mq_port' => '25566', 'mq_portas' => '25565');
  104. $instance = wp_parse_args( (array) $instance, $defaults );
  105. ?>
  106. <p>
  107. <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title</label>
  108. <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
  109. </p>
  110.  
  111. <p>
  112. <label for="<?php echo $this->get_field_id( 'mq_ip' ); ?>">Server IP</label>
  113. <input id="<?php echo $this->get_field_id( 'mq_ip' ); ?>" name="<?php echo $this->get_field_name( 'mq_ip' ); ?>" value="<?php echo $instance['mq_ip']; ?>" style="width:100%;" />
  114. </p>
  115. <p>
  116. <label for="<?php echo $this->get_field_id( 'mq_port' ); ?>">Port Serveru</label>
  117. <input id="<?php echo $this->get_field_id( 'mq_port' ); ?>" name="<?php echo $this->get_field_name( 'mq_port' ); ?>" value="<?php echo $instance['mq_port']; ?>" style="width:100%;" />
  118. </p>
  119. <?php
  120. }
  121.  
  122. function update( $new_instance, $old_instance ) {
  123. $instance = $old_instance;
  124. $instance['title'] = strip_tags( $new_instance['title'] );
  125. $instance['mq_ip'] = strip_tags( $new_instance['mq_ip'] );
  126. $instance['mq_port'] = strip_tags( $new_instance['mq_port'] );
  127. return $instance;
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement