Location: PHPKode > scripts > Minecraft Admin > minecraft-admin/includes/mc-core/mc-widget.php
<?php
class MC_CORE_WIDGET extends MCA
{
		public function __construct(&$MC)
		{
				$this->MC = (object) $MC;
				wp_register_sidebar_widget('MC_CORE_WIDGET_ONLINE', __('Minecraft Server Status', 'minecraft-admin'), array(
						$this,
						'widget'
				), array(
						'description' => __('This widget shows a list of online user from a minecraft server you defined.', 'minecraft-admin')
				));
				wp_register_widget_control('MC_CORE_WIDGET_ONLINE', __('Minecraft Server Status', 'minecraft-admin'), array(
						$this,
						'form'
				), array(
						'width' => 300
				));
		}
		public function widget($args)
		{
				global $blog_id;
				$args = (object) $args;
				echo $args->before_widget;
				echo $args->before_title;
				echo $args->widget_name;
				echo $args->after_title;
				$users = parse_minecraft_output(shell_exec('sh /etc/init.d/minecraft ' . $blog_id . ' ' . $this->MC->core->widget->server . ' command "list"'), false);
				$test  = str_replace("\n", "", $users);
				$test  = str_replace("\r", "", $test);
				$test  = str_replace(' ', "", $test);
				if (!empty($test)) {
						_e("The following users are online:", "minecraft-admin");
						echo $users . '<br />';
				} //!empty($test)
				else {
						_e("It seems to be no user are online :(", "minecraft-admin");
				}
				$outputs = shell_exec('sh /etc/init.d/minecraft ' . $blog_id . ' ' . $this->MC->core->widget->server . ' status');
				$outputs = explode(" ", $outputs);
				$outputs = str_replace(".", "", $outputs[1]);
				$outputs = str_replace("\n", "", $outputs);
				$outputs = str_replace("\r", "", $outputs);
				$outputs = str_replace(' ', "", $outputs);
				if ($outputs == __("runs", "minecraft-admin")) {
						echo '<a class="button" style="color:green;position: absolute;">' . $outputs . "</a>";
				} //$outputs == __("runs", "minecraft-admin")
				else {
						echo '<a class="button" style="color:red;position: absolute;">' . $outputs . "</a>";
				}
				echo $args->after_widget;
		}
		public function update($new_instance, $old_instance)
		{
				$instance          = array();
				$instance['title'] = strip_tags($new_instance['title']);
				return $instance;
		}
		public function save($parameter = "replace")
		{
				parent::save($this->MC, $parameter);
		}
		public function form()
		{
				if (isset($_POST["mc_core_server"])) {
						$this->MC->core->widget->server = (int) strip_tags(stripslashes($_POST["mc_core_server"]));
				} //isset($_POST["mc_core_server"])
		      ?><p>
		      <label for="mc_core_server">
			<?php
				_e('Server:', 'minecraft-admin');
			 ?>
		      </label>
		      <select id="mc_core_server" name="mc_core_server">
				<?php
				if (!empty($this->MC->servers)) {
						foreach ($this->MC->servers as $id => $server) {
												  ?>
				      <option value="<?php echo $id;?>" <?php if($this->MC->core->widget->server == $id) {echo "selected";}?>>
						<?php
								echo $server->name;
						?>
				      </option>
				      <?php
						} //$this->MC->servers as $id => $server
				} //!empty($this->MC->servers)
				?>
		      </select>
		</p>
		<?php
				$this->save();
		}
}
Return current item: Minecraft Admin