tltneon / lgsl

LGSL v6.2.1/v7.0.0 for PHP 5.4-8.3+ (Live Game Server List): online status for CS2 (Source Query), Discord, FiveM, Rust, SA:MP, GMOD, Minecraft, Teamspeak and 200+ more games!
GNU General Public License v3.0
144 stars 44 forks source link

CMS Integration #70

Open wahke opened 2 years ago

wahke commented 2 years ago

Hello, maybe you could think about an integration with Wordpress?

tltneon commented 2 years ago

Hello. I have thoughts about it, thanks. Dunno how to write wp plugins but I'll take a look

wahke commented 5 months ago

Hello, anything change about a Wordpress Plugin ? Maybe with your new API its more easy ?

tltneon commented 5 months ago

Hey @wahke I may suggest something like that:

<?php
/**
 * @package LGSL
 * @version 0.0.1
 */
/*
Plugin Name: LGSL Plugin (Live Game Server List)
Plugin URI: https://github.com/tltneon/lgsl/
Description: This is just a plugin to parsing data from LGSL 
Author: tltneon
Version: 0.0.1
Author URI: https://github.com/tltneon
*/

function getLgslPath() {
    return "http://lgsl7.test";
}

function getLgslServers() {
    $response = wp_remote_retrieve_body(wp_remote_get(getLgslPath() . "/src/lgsl_feed.php")) ?? "[]";
    return json_decode($response, true);
}

function lgsl() {
    $servers = getLgslServers();
    $out = "<div class='card-wrapper w-full' id='lgsl'><article class='card card-list'><div class='card-content flex-grow'><h2 class='entry-title'>Live Game Server List</h2><table class='wp-list-table widefat striped table-view-list posts'>";
        $out .= "
        <tr>
            <th>Name</th>
            <th>IP</th>
            <th>Port</th>
            <th>Game</th>
            <th>Map</th>
            <th>Players</th>
            <th>Status</th>
        </tr>";
    foreach ($servers as $server) {
        $isOnline = $server['online'] ? 'online' : 'offline';
        $out .= "
        <tr>
            <td><a href='" . getLgslPath() . "/?ip={$server['ip']}&port={$server['port']}' target='_blank' class='link'>{$server['name']}</a></td>
            <td>{$server['ip']}</td>
            <td>{$server['port']}</td>
            <td>{$server['game']}</td>
            <td>{$server['map']}</td>
            <td>{$server['players']}/{$server['maxplayers']}</td>
            <td>{$isOnline}</td>
        </tr>";
    }
    $out .= "</table></div></article></div>";
    print($out);
}
add_action( 'get_footer', 'lgsl');

function lgslCss() {
    echo "
    <style type='text/css'>
    #lgsl div.card-content {
        margin: auto;
    }
    </style>
    ";
}
add_action( 'get_footer', 'lgslCss' );

function wporg_options_page() {
    add_menu_page(
        'LGSL Page',
        'LGSL Page',
        'manage_options',
        'lgsl',
        'lgsl_page_html'
    );
}
add_action( 'admin_menu', 'wporg_options_page' );

function lgsl_page_html() {
    lgsl();
}

It able to show table with servers in the footer of page. image I can't figure out how to save string setting so just replace http://lgsl7.test with your lgsl link