Commits

Anonymous committed da896b4

added deep linking functionality

Comments (0)

Files changed (2)

 	 * Generate poker client URL for the given operator and user.
 	 */
 	function play_url_shortcode($atts) {
-		global $wpdb;
+
+		extract(shortcode_atts(
+			array(
+				'table' => '',
+				'tournament' => ''),
+					$atts)
+			);
+		if(strlen($table)>0) {
+			return $this->play_url_table($table);
+		} else if(strlen($tournament)>0) {
+			return $this->play_url_tournament($tournament);
+		} else {
+			return $this->play_url();
+		}
+	}
+	
+	function play_url() {
+		global $wpdb;
 		$options = get_option("cs_authops");
 		// read user from cookie table
 		$table_name = cs_get_cookie_table_name();
 		$sql = "select * from " . $table_name . " where id = '" . wp_get_current_user()->ID . "'";
 		$data = $wpdb->get_row($sql, ARRAY_A);
-		$user = wp_get_current_user();
+		$user = wp_get_current_user();
 		// check if we're logged in
 		if(!$data && is_user_logged_in() && $user->ID) {
-			// ooops! logged in bu have no cookie, fix!
+			// ooops! logged in bu have no cookie, fix!
 			global $cs_logger;
 			$cs_logger->debug("Found logged in user with ID " . $user->ID . " without any token data; Forcing a log in");
 			$this->user_login($user->ID);
 			$data = $wpdb->get_row($sql, ARRAY_A);
+		}
+		if($data) {
+			// all is well
+			return 'http://csps1.cubeia.com/poker-client/poker/skin/cubeiaclassic/operator/' . $options["operatorId"] . '/token/' . $data["cookie"];   // ?operatorId=' . $options["operatorId"] . "&authCookie=" . $data["cookie"];
+		} else {
+			// what to do here, eh?
+			return '';
 		}
-		if($data) {
-			// all is well
-			return 'http://csps1.cubeia.com/poker-client/poker/skin/cubeiaclassic/operator/' . $options["operatorId"] . '/token/' . $data["cookie"];   // ?operatorId=' . $options["operatorId"] . "&authCookie=" . $data["cookie"];
-		} else {
-			// what to do here, eh?
-			return '';
+	}
+	function play_url_table($tableId) {
+		$url = $this->play_url();
+		if(strlen($url)>0) {
+			$url.= "#/table/".$tableId;
 		}
+		return $url;
+	}
+	function play_url_tournament($tournamentId) {
+		$url = $this->play_url();
+		if(strlen($url)>0) {
+			$url.= "#/tournament/".$tournamentId;
+		}
+		return $url;
 	}
 	
 	
 	/*
 	 * Add query variables to WP.
 	 */
-	function query_vars($wp_vars) {
-		return array_merge(array("cubeia-social", "cookie"), $wp_vars);
+	function query_vars($wp_vars) {
+		
+		return array_merge(array("cubeia-social", "cookie","table-id","tournament-id"), $wp_vars);
 	}
 	
 	
 		if(!$this->endsWith($base, "/")) {
 			$base = $base . "/";
 		}
+		
 		// TODO: Nicer rules?
 		$cs_api_rules = array(
-				// $base => "index.php?cubeia-social=",
-				// $base . "authenticate" => "index.php?cubeia-social=authenticate",
-				// $base . "authenticate/" => "index.php?cubeia-social=authenticate",
 				$base . "breakout" => "index.php?cubeia-social=breakout",
-				$base . "authenticate/(.+)" => "index.php?cubeia-social=authenticate&cookie=" . $wp_rewrite->preg_index(1));
+				$base . "authenticate/(.+)" => "index.php?cubeia-social=authenticate&cookie=" . $wp_rewrite->preg_index(1),
+				$base . "table/(.+)" => "index.php?cubeia-social=table&table-id=" . $wp_rewrite->preg_index(1),
+				$base . "tournament/(.+)" => "index.php?cubeia-social=tournament&tournament-id=" . $wp_rewrite->preg_index(1),
+				
+		);
 		$newRules = $cs_api_rules + $rules;
 		return $newRules;
 	}
 			// create query for action
 			if($action == "authenticate") {
 				$query = new CS_Auth_Query();
+			} else if($action == "table") {
+				$this->handle_deep_linking("table",get_query_var("table-id"));
+			} else if($action == "tournament") {
+				$this->handle_deep_linking("tournament", get_query_var("tournament-id"));
 			} else if($action == "breakout") {
 				$query = new CS_Break_Query($this);
 			}
 			exit;
 		}
 	}
+	function handle_deep_linking($type,$id){
+		if (!is_user_logged_in()) {
+			auth_redirect();
+		} else {
+			$url="";
+			if($type=="tournament") {
+				$url = $this->play_url_tournament($id);
+			} else if($type=="table"){
+				$url = $this->play_url_table($id);
+			}
+			if(strlen($url)>0) {
+				header("Location:".$url);
+				exit;
+			}
+		}
+	}
+	
+	
 }
 
 == Changelog ==
 = 0.7 =
-* added error handling when fetching leaderboard 
-* fixed parsing of avatar urls
+* Added error handling when fetching leaderboard. 
+* Fixed parsing of avatar urls.
+* 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 
+  table. The user will be sent to wp authentication page if not logged in
 
 = 0.6 =
 * Added avatar url to login response