UIUC Fetching events from external websites, please wait...
"; echo ""; echo "

Live Rutgers Sports Calendar
"; echo "30 days worth of events automatically extracted from www.scarletknights.com.
"; echo "Hover mouse over event image for information
"; echo "Known bug: Current day always shows blank; fix coming soon

"; echo "By Sam Nelson | View script source code

"; /******************************************************************* Extact content from HTML Each of these data points is stored in an array that is returned: finalData[0] = a dataPoint; finalData[1] = another dataPoint; etc. *******************************************************************/ function getContents($in_url) { // store all data in the following array $finalData = array(); // get HTML data $sportsData = file_get_contents($in_url); // keep getting data until the end of the page while (true) { // get next ... block $start = strpos($sportsData, ""); if ($start === false) { break; } $end = strpos($sportsData, ""); $trBlock = substr($sportsData, $start, $end); // extact data from block $dataPoint = getDataPoint($trBlock); // add data to main array if valid if ($dataPoint['valid'] == true) { array_push($finalData, $dataPoint); } // get rid of the block $sportsData = substr($sportsData, $end+4, strlen($sportsData)); } // return the data array return $finalData; } /****************************************** Get data out of a ... block ******************************************/ function getDataPoint($trBlock) { $dataPoint = array(); $trArray = explode("\n",strip_tags($trBlock)); if (count($trArray) < 8 || trim($trArray[6]) == "DATE") { $dataPoint['valid'] = false; return $dataPoint; } else { $dataPoint['valid'] = true; } $offset = 0; if (preg_match('/divider/',$trBlock)) { $offset = 1; } $dataPoint['date'] = trim($trArray[3+$offset]); $dataPoint['sport'] = trim($trArray[4+$offset]); $dataPoint['opp'] = trim($trArray[5+$offset]); $dataPoint['location'] = trim($trArray[6+$offset]); $dataPoint['time'] = trim($trArray[7+$offset]); return $dataPoint; } /********************************************************** Write all sports on tempDay through the echo command **********************************************************/ function echoSportsToday($sportsData, $tempDay) { for ($i = 0; $i < count($sportsData); $i++) { $dataPoint = $sportsData[$i]; if ($dataPoint['date'] == $tempDay) { $mouseOver = $dataPoint['sport'] . " "; $mouseOver = $mouseOver . "vs. " . $dataPoint['opp'] . " "; $mouseOver = $mouseOver . "at " . $dataPoint['location'] . " "; $mouseOver = $mouseOver . "at " . $dataPoint['time']; $sport = $dataPoint['sport']; $img = "default.jpg"; if ($sport == "Baseball") { $img = "baseball.jpg"; } elseif ($sport == "Men's Basketball") { $img = "mbball.jpg"; } elseif ($sport == "Women's Basketball") { $img = "wbball.jpg"; } elseif ($sport == "Football") { $img = "football.jpg"; } elseif ($sport == "Women's Tennis") { $img = "wtennis.jpg"; } elseif ($sport == "Men's Tennis") { $img = "mtennis.jpg"; } elseif ($sport == "Softball") { $img = "softball.jpg"; } elseif ($sport == "Swimming and Diving") { $img = "swimming.jpg"; } elseif ($sport == "Women's Golf") { $img = "golf.jpg"; } elseif ($sport == "Men's Golf") { $img = "golf.jpg"; } elseif ($sport == "Men's Lacrosse") { $img = "lacrosse.jpg"; } elseif ($sport == "Women's Lacrosse") { $img = "lacrosse.jpg"; } elseif ($sport == "Men's Track") { $img = "track.jpg"; } elseif ($sport == "Women's Track") { $img = "track.jpg"; } elseif ($sport == "Gymnastics") { $img = "gym.jpg"; } elseif ($sport == "Wrestling") { $img = "wrestling.jpg"; } echo ""; } } } $sportsData = getContents('http://www.scarletknights.com/schedule/sched-30.asp'); // Days of the week $dayNames = array(0 => "S", 1 => "M", 2 => "T", 3 =>"W", 4 => "T", 5 => "F", 6 => "S"); // Determine the first and last day of the current month if (array_key_exists('month',$_GET) && array_key_exists('year',$_GET)) { $month = $_GET['month']; $year = $_GET['year']; $today = getdate(mktime(0,0,0,$month,1,$year)); $realMonth = false; } else { $today = getdate(); $realMonth = true; } $first_day = getdate(mktime(0,0,0,$today['mon'],1,$today['year'])); if ($today['mon'] != 11) $last_day = getdate(mktime(0,0,0,$today['mon']+1,0,$today['year'])); else $last_day = getdate(mktime(0,0,0,0,0,$today['year']+1)); // Print out the calendar echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; foreach ($dayNames as $dn) { echo "\n"; } echo "\n"; $dayWereOn = 0; $breakout = false; for ($week = 0; $week < 6; $week++) { echo "\n"; for ($dayofweek = 0; $dayofweek < 7; $dayofweek++) { if ($dayWereOn == 0 && $dayofweek == $first_day['wday']) $dayWereOn = 1; if ($dayWereOn == $today['mday'] && $realMonth) echo "\n"; if ($dayWereOn == $last_day['mday'] + 1) { $dayWereOn = -1; $breakout = true; } } echo "\n"; if ($breakout == true) break; } // Create bottom of calendar $prevMonth = $today['mon']-1; $prevYear = $today['year']; if ($prevMonth == 0) { $prevMonth = 12; $prevYear--; } $nextMonth = $today['mon']+1; $nextYear = $today['year']; if ($nextMonth == 13) { $nextMonth = 1; $nextYear++; } echo "\n"; echo "\n\n"; echo "\n"; echo "
" . $today['month'] . " " . $today['year'] . "
" . $dn . "
"; elseif ($dayWereOn <= 0) echo ""; else echo ""; if ($dayWereOn > 0) { echo $dayWereOn; echo "
"; $tempDay = date("F j",mktime(0,0,0,$today['mon'],$dayWereOn,$today['year'])); echoSportsToday($sportsData, $tempDay); $dayWereOn++; } else { echo " "; } echo "
"; echo "
Go To Previous Month
"; echo "
"; echo "
Go To Today: " . date("m/d/y") . "
"; echo "
"; echo "
Go To Next Month
"; echo "

\n"; ?>

UIUC Old UIUC Old UIUC Old