Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMS Integration #70

Open
wahke opened this issue Oct 31, 2021 · 3 comments
Open

CMS Integration #70

wahke opened this issue Oct 31, 2021 · 3 comments

Comments

@wahke
Copy link

wahke commented Oct 31, 2021

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

@tltneon tltneon added this to To do in Live game status list Nov 17, 2021
@tltneon
Copy link
Owner

tltneon commented Feb 7, 2022

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

@wahke
Copy link
Author

wahke commented Feb 20, 2024

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

@tltneon
Copy link
Owner

tltneon commented Feb 20, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants