<?
/*
* phpNTVMSNBC-0.1.php
*
* (GPL) 2002, 2003, 2004 by Hidayet Dogan (hide@address.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#
# If your connection is too slow, increase time out limit
#
$timeout = 10; # seconds
$category[NEWS] = "Haberler";
$category[COM] = "Ýþ Dünyasý";
$category[LIV] = "Kültür Sanat";
$category[YASAM] = "Yaþam";
$category[TECH] = "Teknoloji";
$category[SPT] = "Spor";
$category[HEALTH] = "Saðlýk";
$category[WEA] = "Hava";
$category[DUNYA] = "Dünyadan";
$fp = @fsockopen("www.ntvmsnbc.com", 80, $errno, $errstr, $timeout);
if (!$fp)
die("ERROR ($errno): $errstr");
fputs($fp, "GET /news/alert2.txt HTTP/1.0\r\n");
fputs($fp, "HOST: www.ntvmsnbc.com\r\n");
fputs($fp, "ACCEPT: */*\r\n");
fputs($fp, "User-Agent: MSNBC-News-Alert/3.0\r\n\r\n");
$i = 0;
while (!feof($fp)) {
$line = fgets($fp, 8192);
$line = trim($line);
if (empty($line))
continue;
$data = explode("=", $line, 2);
switch ($data[0]) {
case "GMT":
preg_match("#(\d+)\.(\d+)\.(\d+) (\d+)\.(\d+)#si",
$data[1], $date);
$gmt = mktime($date[4], $date[5], 0, $date[2], $date[3],
$date[1]);
break;
case "VER":
$version = $data[1];
case "U":
$news[$i][url] = str_replace("./", "", $data[1]);
$news[$i][url] = str_replace("http://www.ntvmsnbc.com", "", $news[$i][url]);
$news[$i][url] = "http://www.ntvmsnbc.com".$news[$i][url];
break;
case "H":
$news[$i][subject] = $data[1];
break;
case "A":
$news[$i][summary] = $data[1];
break;
case "S":
$news[$i][category] = $category[$data[1]];
break;
case "T":
$news[$i][sub] = $data[1];
break;
case "P":
$year = substr($data[1], 0, 4);
$month = substr($data[1], 4, 2);
$day = substr($data[1], 6, 2);
$hour = substr($data[1], 8, 2);
$minute = substr($data[1], 10, 2);
$second = substr($data[1], 12, 2);
$news[$i][publish] = date("l, F d, Y g:i a", mktime($hour, $minute,
$second, $month, $day, $year));
break;
case "E":
$i++;
break;
}
}
fclose($fp);
?>
<b>phpNTVMSNBC 0.1.beta sample output:</b>
<hr>
<?
foreach ($category as $val) {
echo "<b>$val</b>\n<ul>\n";
foreach ($news as $item) {
if ($item[category] == $val)
echo "<li>".((!empty($item[sub])) ? "<b>$item[sub]:</b> " : "").
"<a href=\"$item[url]\">$item[subject]</a> ($item[publish])".
"<br>\n$item[summary]</li>\n";
}
echo "</ul>\n";
}
?>