Jump to content

Server stats PHP widget


Recommended Posts


Trying to get a better hold of PHP and decided to make a little Xenforo widget for personal use/fun. Obligatory disclaimer: I'm not a coder whatsoever and only accomplished this thanks to @msmcpeake's cURL code (TY!!!).


If anyone has suggestions about the code, feel free.


namespace tomnjerry\EmbyStats;

class LibraryTotals
    public static function showTotals()
		$apikey = 'API KEY HERE';
		$url = 'https://website.com/emby/Items/Counts?api_key=' . $apikey;
		$movieurl = 'https://website.com/web/index.html#!/videos?serverId=a8976f868223845793&parentId=98qy8954uy3298ruf';
		$seriesurl = 'https://website.com/web/index.html#!/tv?serverId=a8976f868223845793&parentId=j9f834uj98f4u98f';
		$musicurl = 'https://website.com/web/index.html#!/music?serverId=a8976f868223845793&parentId=93482758934uf894u';

		$ch = curl_init();

		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_HTTPGET, true);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

		$headers = array();
		$headers[] = 'Accept: application/json';
		$headers[] = 'Content-Type: application/json';
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		$result = curl_exec($ch);

		if (curl_errno($ch)) {
			echo 'Error:' . curl_error($ch);

		$json = json_decode($result, true);
		echo '<dl class="pairs pairs--justified"><dt><i class="fas fa-fw fa-ticket-alt"></i> Movies</dt><dd><a target="_blank" href="' . $movieurl . '&tab=movies">' . number_format($json['MovieCount']) . '</a></dd></dl>
				<dl class="pairs pairs--justified"><dt><i class="fas fa-fw fa-tv-retro"></i> TV Shows</dt><dd><a target="_blank" href="' . $seriesurl . '&tab=shows">' . number_format($json['SeriesCount']) . '</a></dd></dl>
				<dl class="pairs pairs--justified"><dt><i class="fad fa-fw fa-tv-retro"></i> Episodes</dt><dd><a target="_blank" href="' . $seriesurl . '&tab=episodes">' . number_format($json['EpisodeCount']) . '</a></dd></dl>
				<dl class="pairs pairs--justified"><dt><i class="fas fa-fw fa-album"></i> Albums</dt><dd><a target="_blank" href="' . $musicurl . '&tab=albums">' . number_format($json['AlbumCount']) . '</a></dd></dl>
				<dl class="pairs pairs--justified"><dt><i class="fas fa-fw fa-music"></i> Songs</dt><dd><a target="_blank" href="' . $musicurl . '&tab=songs">' . number_format($json['SongCount']) . '</a></dd></dl>';


Edited by tomnjerry74
  • Like 1
Link to comment
Share on other sites

7 hours ago, Taurec said:

Hello tomnjerry74

and how to use ?

(path, filename etc?)

Using Xenforo 2.2:

  1. Put code in file located in \src\addons\tomnjerry\EmbyStats\LibraryTotals.php
    1. Edit your API key, website URLs, etc
  2. In Xenforo ACP,  create a new widget and choose Custom HTML
  3. Style the container however you'd like, but use this to callback the PHP where you'd like the data to be displayed:
<xf:callback class="tomnjerry\EmbyStats\LibraryTotals" method="showTotals"></xf:callback>


  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...