init();
class ESMM {
private $options;
public function __construct() {
register_activation_hook(__FILE__, array($this, ‘esmm_activate’));
register_deactivation_hook(__FILE__, array($this, ‘esmm_deactivation’));
}
public function init(){
add_action(‘wp_enqueue_scripts’, array($this, ‘esmm_addscripts’));
add_action(‘admin_enqueue_scripts’, array($this, ‘esmm_addscripts’));
add_action( ‘admin_menu’, array( $this, ‘esmm_add_plugin_page’ ) );
add_action( ‘admin_init’, array( $this, ‘esmm_page_init’ ) );
add_shortcode(‘esmm_matches’, array($this, ‘esmm_shortcode’));
}
public function esmm_shortcode($atts = [], $content = null, $tag = ”) {
$content = “”;
// team = $atts[‘team’]
// size = $atts[‘size’]
global $wpdb;
if($atts[‘team’] == “all”){
$results = $wpdb->get_results(“SELECT * FROM {$wpdb->prefix}esmm_match WHERE 1 ORDER BY date DESC”);
}else{
$results = $wpdb->get_results(“SELECT * FROM {$wpdb->prefix}esmm_match WHERE team_name='{$atts[‘team’]}’ ORDER BY date DESC”);
}
if($atts[‘size’] == “all”){
$atts[‘size’] = 999999;
}
$content .= ‘
if($results){
$addBtn = (sizeof($results) > $atts[‘size’]);
foreach($results as $key => $match) {
$match = (array) $match;
if($match[‘enemy_points’] == $match[‘team_points’]){
$match_result = ‘DRAW‘;
}else if($match[‘enemy_points’] < $match['team_points']){
$match_result = ‘WIN‘;
}else if($match[‘enemy_points’] > $match[‘team_points’]){
$match_result = ‘LOSS‘;
}
$content .= ‘
‘.$match[‘turnier’].’
‘.$match[‘team_points’].”:”.$match[‘enemy_points’].’
‘;
}
if($addBtn){
$content .= ‘‘;
}
}
$content .= ‘
‘;
return $content;
}
public function esmm_add_plugin_page()
{
// This page will be under “Settings”
add_menu_page(
“E-Sport Match Manager”,
“ESMM”,
“manage_options”,
“esmm_addpage”,
array( $this, ‘esmm_admin_page_contents’ )
);
}
function esmm_admin_page_contents() {
?>
Matchergebnisse hinzufügen
if(strtolower($_SERVER[‘REQUEST_METHOD’]) == “post”){
try {
if(!isset($_POST[‘enemy_name’]) || strlen($_POST[‘enemy_name’]) < 1){
throw new Exception(“Bitte fülle alle Felder aus!”);
}
if(!isset($_POST[‘url’]) || strlen($_POST[‘url’]) < 1){
throw new Exception(“Bitte fülle alle Felder aus!”);
}
if(!isset($_POST[‘type’]) || strlen($_POST[‘type’]) < 1){
throw new Exception(“Bitte fülle alle Felder aus!”);
}
if(!isset($_POST[‘team_name’]) || strlen($_POST[‘team_name’]) < 1){
throw new Exception(“Bitte fülle alle Felder aus!”);
}
if(!isset($_POST[‘team_points’]) || strlen($_POST[‘team_points’]) < 1){
throw new Exception(“Bitte fülle alle Felder aus!”);
}
if(!isset($_POST[‘enemy_points’]) || strlen($_POST[‘enemy_points’]) < 1){
throw new Exception(“Bitte fülle alle Felder aus!”);
}
if(!isset($_POST[‘turnier’]) || strlen($_POST[‘turnier’]) < 1){
throw new Exception(“Bitte fülle alle Felder aus!”);
}
if(!isset($_POST[‘date’]) || strlen($_POST[‘date’]) < 1){ throw new Exception("Bitte fülle alle Felder aus!"); } if(!isset($_FILES['team_logo']['name'])){ throw new Exception("Bitte fülle alle Felder aus!"); } $type = $_POST['type']; $file_name = $_FILES['team_logo']['name']; $file_splitted = explode('.', $file_name); $file_ending = $file_splitted[sizeof($file_splitted) - 1]; $store_to_file = realpath(dirname(__FILE__))."/files/".getRandomString(8).".".$file_ending; if(!move_uploaded_file($_FILES['team_logo']['tmp_name'], $store_to_file)){ throw new Exception("Logo konnte nicht gespeichert werden!"); } global $wpdb; $wpdb->insert(
“{$wpdb->prefix}esmm_match”,
[
“url” => $_POST[‘url’],
“date” => $_POST[‘date’],
“type” => $type,
“logofile” => $store_to_file,
“enemy_points” => $_POST[‘enemy_points’],
“enemy_name” => $_POST[‘enemy_name’],
“turnier” => $_POST[‘turnier’],
“team_name” => $_POST[‘team_name’],
“team_points” => $_POST[‘team_points’]
]
);
$query = htmlspecialchars( $wpdb->last_query, ENT_QUOTES );
if($wpdb->last_error !== ”){
throw new Exception($query);
}
?>
delete(“{$wpdb->prefix}esmm_match”, [“id” => $_GET[‘del’]]);
$query = htmlspecialchars( $wpdb->last_query, ENT_QUOTES );
if($wpdb->last_error !== ”){
throw new Exception($query);
}
}catch(Exception $ex){
}
}
$results = $wpdb->get_results(“SELECT * FROM {$wpdb->prefix}esmm_match WHERE 1 ORDER BY date DESC”);
$content = “”;
foreach($results as $match){
$match = (array) $match;
$content .= ‘
‘;
}
?>
Matches
ID | Team Name | Datum | Typ | Punkte | Gegner Name | Tunier |
---|
prefix}esmm_match` ( `id` int(11) NOT NULL AUTO_INCREMENT, `url` varchar(2048) NOT NULL, `date` date NOT NULL, `type` varchar(20) NOT NULL, `logofile` varchar(120) NOT NULL, `enemy_points` int(11) NOT NULL, `enemy_name` varchar(60) NOT NULL, `turnier` varchar(60) NOT NULL, `team_name` varchar(60) NOT NULL, `team_points` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;”;
dbDelta($sql);
}
public function esmm_deactivation(){
}
}
if(!function_exists(“getIp”)){
function getIp() {
$keys = [
‘HTTP_CLIENT_IP’,
‘HTTP_X_FORWARDED_FOR’,
‘HTTP_X_FORWARDED’,
‘HTTP_FORWARDED_FOR’,
‘HTTP_FORWARDED’,
‘REMOTE_ADDR’
];
foreach($keys as $k) {
if (isset($_SERVER[$k]) && !empty($_SERVER[$k]) && filter_var($_SERVER[$k], FILTER_VALIDATE_IP)) {
return $_SERVER[$k];
}
}
return null;
}
}
function getRandomString($length = 8) {
$characters = ‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
$string = ”;
for ($i = 0; $i < $length; $i++) {
$string .= $characters[mt_rand(0, strlen($characters) – 1)];
}
return $string;
}