Commits

Fredrik Johansson committed 47596e7

Adding online players

Comments (0)

Files changed (6)

+syntax: glob
+
+target
+.project
+.classpath
+.settings
+.metadata
+*.log
+*.log.*
+release.properties
+pom.xml.releaseBackup
+.orig
+pom.xml.next
+pom.xml.tag
+*~
+*\#
+.DS_Store
+.idea/*
+*.idea/*
+*.iml

classes/leaderboard.php

 						'timeout' => 15,
 						'redirection' => 5,
 						'httpversion' => '1.0',
-						'blocking' => true,
-						'headers' => array('Authorization' => 'Basic ' . base64_encode("poker:pokerdemo"))
-				)
+						'blocking' => true
+						)
 				);
 				
 				if( is_wp_error( $response ) ) {

classes/online_count.php

+<?php
+
+/*
+ Copyright (C) 2013 Cubeia Ltd  <info@cubeia.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License, version 2, as
+ published by the Free Software Foundation.
+
+ 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
+*/
+
+/*
+ * This class controls the UI of tournaments on the 
+ * site. 
+ */
+class CS_ONLINE_COUNT_UI {
+	
+	function __construct() {
+		
+		function online_count_func($atts) {
+	
+			$apiKey =  cs_get_single_option("api-key", "");
+			
+			$baseUrl = 'http://csps1.cubeia.com/operator-api';
+            $online_count_url = $baseUrl."/rest/operator/players/count?apiKey=".$apiKey;
+            
+			$content = '';
+			try {
+
+				// Fetch settings from Operator Admin server
+				$response = wp_remote_get( $online_count_url , array(
+						'method' => 'GET',
+						'timeout' => 10,
+						'redirection' => 5,
+						'httpversion' => '1.0',
+						'blocking' => true
+						)
+				);
+				
+				if( is_wp_error( $response ) ) {
+					$error_message = $response->get_error_message();
+					return "Unable to fetch online_count from $online_count_url: $error_message";
+				} 
+				
+				$json = $response["body"];
+				$online_count = json_decode($json, false);
+ 
+		        $content.= $online_count->online;
+				  
+					
+			} catch(Exception $e) {
+				$content.= '<p>Unable to fetch online_count</p>';
+			}
+		
+			return $content;
+		}
+		
+		add_shortcode("cs_online_count", "online_count_func");	
+	}
+	
+	
+}
+
+
+
+
+
+

classes/online_players.php

+<?php
+
+/*
+ Copyright (C) 2013 Cubeia Ltd  <info@cubeia.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License, version 2, as
+ published by the Free Software Foundation.
+
+ 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
+*/
+
+/*
+ * This class controls the UI of tournaments on the 
+ * site. 
+ */
+class CS_ONLINE_PLAYERS_UI {
+	
+	function __construct() {
+		
+		function online_players_func($atts) {
+
+			
+			extract(shortcode_atts(
+				array(
+				'max_display_items' => '10',
+				'tables' => 'false',
+				),
+				$atts)
+				);
+				
+				
+		
+			$max_display_items_val = intval($max_display_items);
+				
+			$apiKey =  cs_get_single_option("api-key", "");
+			$integrationUrl =  cs_get_single_option("baseUrl", "");
+
+			$baseUrl = 'http://csps1.cubeia.com/operator-api';
+
+
+            // If tables=true then we fetch all tables players are sitting at as well.
+            if ($tables == 'true') {
+                $online_playersUrl = $baseUrl."/rest/operator/players/online/tables?apiKey=".$apiKey;
+            } else {
+                $online_playersUrl = $baseUrl."/rest/operator/players/online/detail?apiKey=".$apiKey;
+            }
+
+
+			$content = '';
+			try {
+
+				// Fetch settings from Operator Admin server
+				$response = wp_remote_get( $online_playersUrl , array(
+						'method' => 'GET',
+						'timeout' => 10,
+						'redirection' => 5,
+						'httpversion' => '1.0',
+						'blocking' => true
+						)
+				);
+				
+				if( is_wp_error( $response ) ) {
+					$error_message = $response->get_error_message();
+					return "Unable to fetch online_players from $baseUrl: $error_message";
+				} 
+				
+		
+				$json = $response["body"];
+				$online_players = json_decode($json, false);
+
+                $entries = $online_players->players;
+		        
+		        if ($tables == 'true') {
+		            $content.= '<table class="cs-online-players"><thead>'.
+						'<th class="cs-online-players-avatar">Pic</th>'.
+						'<th class="cs-online-players-name">Name</th>'.
+						'<th class="cs-online-players-name">Tables</th>'.
+						'</tr>'.
+						'</thead>'.
+						'<tbody>';
+		        } else {
+		            $content.= '<table class="cs-online-players">'.
+						'<th class="cs-online-players-avatar">Pic</th>'.
+						'<th class="cs-online-players-name">Name</th>'.
+						'</tr>'.
+						'</thead>'.
+						'<tbody>';
+					}
+		        
+				$pos = 1;
+		
+				foreach($entries as $e) {
+					if($pos>$max_display_items_val) {
+						break;
+					}
+					
+					$content.= '<tr>';
+					if (strlen($e->externalAvatarUrl) == 0){
+                        $content.= '<td class="cs-online-players-avatar">No Pic</td>';
+                    } else {
+                        $content.= '<td class="cs-online-players-avatar"><div class="cs-online-players-avatar" style="background:url(' . $e->externalAvatarUrl . ') no-repeat center center; background-size:auto 100%;" /></td>';
+                    }
+                    
+                    if ($e->screenname) {
+					    $content.= '<td class="cs-online-players-name">' . $e->screenname . '</td>';
+				    } else {
+				        $content.= '<td class="cs-online-players-name">' . $e->externalUsername . '</td>';
+				    }
+					
+				    
+				    // Render tables if any
+				    $tables = $e->tables;
+				    if ($tables) {
+				        $content.= '<td><table class="cs-online-players-tables">';
+                        foreach($tables as $table) {
+                            $table_link = '/'.$integrationUrl.'/table/' . $table;
+                            $content.= '<tr><td class="cs-online-players-table"><a href="' . $table_link . '">Table-' . $table . '</a></td></tr>';                               
+					   }
+					   $content.= '</table></td>';
+                    }
+						
+					$content.= '</tr>';
+						
+					$pos++;
+				}
+					
+					
+				$content.=  '</tbody>';
+				$content.= '</table>';
+					
+					
+			    
+					
+			} catch(Exception $e) {
+				$content.= '<p>Unable to fetch online_players</p>';
+			}
+		
+			return $content;
+		}
+		
+		add_shortcode("cs_online_players", "online_players_func");	
+	}
+	
+	
+}
+
+
+
+
+
+

cubeia-social.php

  Description: Plugin for integrating Cubeia Social poker into a WP installation.
  Plugin URI: http://www.cubeiasocial.com/
  License: GPLv2
- Version: 0.8
+ Version: 0.9
 */
 
 /*
 @include_once dirname(__FILE__) . "/classes/log.php";
 @include_once dirname(__FILE__) . "/classes/mtt-ui.php";
 @include_once dirname(__FILE__) . "/classes/leaderboard.php";
+@include_once dirname(__FILE__) . "/classes/online_players.php";
+@include_once dirname(__FILE__) . "/classes/online_count.php";
 
 // include global functions
 @include_once dirname(__FILE__) . "/functions.php";
 
 
 /*
- * Make the API globalk and initiate the admin and
+ * Make the API global and initiate the admin and
  * API classes which sets up further hooks. 
  */
 add_action("init", function() {
 	global $cs_api;
 	$cs_mtt_ui = new CS_MTT_UI();
 	$cs_leaderboard_ui = new CS_LEADERBOARD_UI();
+	$cs_online_players_ui = new CS_ONLINE_PLAYERS_UI();
+	$cs_count_ui = new CS_ONLINE_COUNT_UI();
 	$cs_admin = new CS_Admin();
 	$cs_api = new CS_Api();
 	
 
 == Changelog ==
 
+= 0.9 = 
+* Added shortcodes [cs_online_players max_display_items="10" tables="false"] and [cs_online_count] to display online players and count.
+
 = 0.8 = 
 * Added deep linking to tables and tournaments to the play url short code [cs_poker_client_url table="234"] or [cs_poker_client_url tournament="234"]
 * Added deep linking redirect page. Going to /cubeia-social/table/123 will redirect an authenticated user to the poker client and open the provided