Powered By Blogger

Wednesday, July 24, 2013

New Stream Code

<?php
class streamer
{
public $streamID;
public $name;
public $race;
public $raceImage;
public $online;

public function __construct($nName, $nRace, $nStreamID) {
$this->name = $nName;
$this->race = $nRace;
$this->streamID = $nStreamID;
$this->race = strtolower($this->race);
switch($this->race) {
case "t":
$this->raceImage = "http://all-inspiration.com/wp-content/uploads/2013/06/Ticon_small.png";
break;
case "p":
$this->raceImage = "http://all-inspiration.com/wp-content/uploads/2013/06/Picon_small.png";
break;
case "z":
$this->raceImage = "http://all-inspiration.com/wp-content/uploads/2013/06/Zicon_small.png";
break;
case "r":
$this->raceImage = "http://all-inspiration.com/wp-content/uploads/2013/06/sRandomIcon.png";
break;
}

$id = $this->streamID;
$json_file = file_get_contents("http://api.justin.tv/api/stream/list.json?channel={$id}", 0, null, null);
$json_array = json_decode($json_file, true);
if ($json_array[0]['name'] == "live_user_{$id}") {
$this->online = true;
}
else {
$this->online = false;
}
}

// Sort function
static function cmp_obj($a, $b)
{
$al = strtolower($a->name);
$bl = strtolower($b->name);
if ($al == $bl) {
return 0;
}
return ($al > $bl) ? +1 : -1;
}
}

$streams = array(
new streamer("AllinTang", "z", "tangsc"),
new streamer("AllinHyJynX", "z", "myaurasc2"),
new streamer("AllinSinistar", "z", "SinistarTV"),
new streamer("AllinElijah", "z","tacowtf"),
new streamer("AllinCrossi", "z","crossi36"),
new streamer("AllinArcanine", "p","Leafs4Lyfe23"),
new streamer("AllinMonda", "p","mondadon"),
);

//usort($streams, cmp_obj);

echo "<ul>";

foreach($streams as $stream)
{
echo "<li>";
if ($stream->online)
{ ?>
<img src = "http://all-inspiration.com/wp-content/uploads/2013/06/icon-online.png" />
<?php }
else
{ ?>
<img src = "http://all-inspiration.com/wp-content/uploads/2013/06/icon-offline.png" />
<?php } ?>
<img src = "<?php echo $stream->raceImage; ?>" />
<?php
//changes begin

//original line
//echo $stream->name;

//new line
echo "<a href='http://www.twitch.tv/".$stream->streamID."'>".$stream->name."</a>";

//changes end
echo "</li>";

}

echo "</ul>";
?>

No comments:

Post a Comment