-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTournamentRip.php
More file actions
51 lines (44 loc) · 1.59 KB
/
TournamentRip.php
File metadata and controls
51 lines (44 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
include_once "Snoopy.class.php";
function get_string_between($string, $start, $end){
$string = ' ' . $string;
$ini = strpos($string, $start);
if ($ini == 0) return '';
$ini += strlen($start);
$len = strpos($string, $end, $ini) - $ini;
return substr($string, $ini, $len);
}
function isJson($string) {
json_decode($string);
return (json_last_error() == JSON_ERROR_NONE);
}
/**
* Returns a complex associative array with a data dump from challonge
* @param string $url The base url to the challonge tournament
* @return array
*/
function getTournamentData($url) {
$snoopy = new Snoopy;
$snoopy->user = "joe";
$snoopy->pass = "bloe";
if($snoopy->fetch($url))
{
$html = $snoopy->results;
$data = get_string_between($html, "['TournamentStore'] = ", "; window.");
if ($data == "")
echo "error retreiving tournament data. Perhaps Challonge updated the formatting?";
else
{
if (!isJson($data))
echo "error parsing JSON Data. Maybe Challonge ruined the script?";
$data = json_decode($data, true);
/*echo "<pre>";
print_r($data);
echo "</pre>";*/
return $data;
}
}
else
echo "error fetching document: ".$snoopy->error."\n";
}
?>