forked from MCNewsTools/MCServerStatus-WordPressWidget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.php
123 lines (103 loc) · 3.59 KB
/
widget.php
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
<?php
/*
Plugin Name: Server Status For Minecraft PC & PE (MCServerStatus)
Plugin URI: https://github.com/MCServerStatus/MCServerStatus-WordPressWidget
Description: Server Status For Minecraft PC & PE is a WordPress Widget, show Minecraft PC & PE server data.
Version: 1.1.1
Author: 旋風之音 GoneTone
Author URI: https://www.facebook.com/TPGoneTone/
Author email: p29022716@gmail.com
License: GPL 2
Donate URI: https://qr.allpay.com.tw/ffSH4
Text Domain: mcserverstatus
Domain Path: /lang
*/
/* Copyright 2016 GoneTone (email: p29022716@gmail.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// load localization
load_plugin_textdomain('mcserverstatus', false, dirname( plugin_basename( __FILE__ ) ) . '/lang');
require dirname(__FILE__) . '/libs/Widgetize.php';
require dirname(__FILE__) . '/libs/ApiClient.php';
require dirname(__FILE__) . '/libs/MinecraftQuery.php';
class MCServerStatus_Widget extends Widgetize
{
/**
* Construct
*/
public function __construct()
{
parent::__construct('MCServerStatus', array(
'title' => 'MCServerStatus',
'host' => '127.0.0.1',
'port' => '25565',
'show_players_avatar' => 'on',
'avatar-size' => '20',
'show_server_motd' => 'on',
'show_status' => 'on',
'show_host' => 'on',
'show_port' => 'on',
'show_server_platform' => 'on',
'show_server_software' => 'on',
'show_game_version' => 'on',
'show_players' => 'on',
'show_auto_players' => '',
'show_plugins' => '',
'minotar_size' => '25',
'auto_update_status' => '',
'set_seconds' => '15',
'show_donate_info' => ''
));
}
/**
* @param array $args
* @param array $instance
*/
public function widget(array $args, array $instance)
{
$instance = $this->hydrate($instance);
// Get ip if localhost
if (in_array($instance['host'], array('127.0.0.1', 'localhost'))) {
$instance['host'] = $_SERVER['SERVER_ADDR'];
}
$client = new ApiClient($instance['host'], $instance['port']);
$server = $client->call();
require dirname(__FILE__) . '/templates/widget.phtml';
}
/**
* @param array $instance
* @return string|void
*/
public function form(array $instance)
{
$instance = $this->hydrate($instance);
require dirname(__FILE__) . '/templates/form.phtml';
}
/**
* @param $newInstance
* @param $oldInstance
* @return array
*/
public function update($newInstance, $oldInstance)
{
$instance = array();
foreach ($newInstance as $option => $value) {
if((int) $value > 0 && !in_array($option, array('host'))) {
$value = (int) $value;
}
$instance[$option] = strip_tags(trim($value));
}
return $instance;
}
}
Widgetize::add('MCServerStatus_Widget');