Доброе время суток.
Имеется скрипт ( codepad.org/gmk94Ne3 ) - выводит список указанных стримов с сайта twitch.tv , но в порядке "хаоса", в данном скрипте выводятся следующие стримы: $members = array("gspotdota","sheevergaming"," dreadztv","dotatalktv2"); , но они не понятно как сортированы.
Как и где в этом скрипте сделать сортировку этих каналов по кол-ву зрителей?
PHP:
скопировать код в буфер обмена
<html> <head> <title>Streamlist</title> </head> <body> <?PHP /** * @version 0.1 * @copyright (C) 2012/2013 Cees Middel (Avon) www.maegis.net * @Inspired by Syi http://mushroom-mayhem.com * @license GNU/GPL v3 http://www.gnu.org/licenses/gpl.html */ /** * array with all stream names i.e. www.twitch.tv/"iksf". * To add more users just add their channel names with comma seperation * This is all there is, no futher editing required */ $members = array("gspotdota","sheevergaming","dreadztv","dotatalktv2"); // This variable becomes one long url with the channel names stringed up behind it // This url then fetches a json file from twitch with all the selected channels information $userGrab = "http://api.justin.tv/api/stream/list.json?channel="; //I use this array to compare with the members array. All users in this arrat are substracted from the members array and hence are //"offline" $checkedOnline = array (); foreach($members as $i =>$value){ $userGrab .= ","; $userGrab .= $value; } //grabs the channel data from twitch.tv streams //get's member names from stream url's and checks for online members foreach($members as $i =>$value){ $title = $json_array[$i]['channel']['channel_url']; $viewer = $json_array[$i] ['channel_count']; $login = $json_array[$i] ['streams_name']; onlinecheck($member, $viewer, $login); $checkedOnline[] = signin($member); } //checks if player streams are online function onlinecheck($online, $viewers, $login) { //If the variable online is not equal to null, there is a good change this person is currently streaming if ($online != null) { echo '<a href="http://www.twitch.tv/'.$online.'"> <strong>'.$online.'</strong>'; echo '<a href="http://www.twitch.tv/'.$online.'"> <strong>'.$login.'</strong>'; echo '  <img src="/images/online.png"><strong> Status:</strong> Online! </br>'; echo '<img src="/images/viewers.png"><strong>Viewers:</strong>  ' .$viewers.'</br>'; echo '<img src="http://static.starladder.tv/uploads/news/images/DOTA2/x3m4eg/solo.png" width="150" height="113" title="Click here to watch" />'; // Prints out an image echo '</a>'; } } //This funcion add's online channel names to the checked online array function signin($person){ if($person != null){ return $person; } else{ return null; } } ?> <hr> <?PHP //This part list all the people currently offline. Here the array with online users is compared with the total users. //online users are then removed from the total users array. foreach ($members as $i => $value1) { foreach($checkedOnline as $ii => $value2){ if($value1 == $value2){ } } } ?> </body> </html>
(Отредактировано автором: 07 Декабря, 2013 - 17:39:06)
|