strURL; $retCode = $this->CallNewsECS($url, 1); if ($retCode == true) { $this->DisplayNewsContent(); } } // Returns the response as a string or false on error function CallNewsECS($url, $timeout) { // Parse the URL into parameters for fsockopen $UrlArr = parse_url($url); $host = $UrlArr['host']; $port = (isset($UrlArr['port'])) ? $UrlArr['port'] : 80; $path = $UrlArr['path']; $query = (isset($UrlArr['query'])) ? '?' . $UrlArr['query'] : ''; $path .= $query; // Zero out the error response $errno = null; $errstr = ''; $this->getDataError = ''; // Open the connection to News Source $fp = @fsockopen($host, $port, $errno, $errstr, $timeout); // Failed to open the URL if (!is_resource($fp)) { $this->getDataError = "Fsockopen error number = $errno Details = $errstr"; return false; } // Send an HTTP GET header and Host header if (!(fwrite($fp, 'GET '. $path .' HTTP/1.0' . "\r\n". 'Host: ' . $host . "\r\n\r\n"))) { fclose($fp); $this->getDataError = "Fwrite error. Could not write GET and Host headers"; return false; } // Block on the socket port, waiting for response from News Source if (function_exists('socket_set_timeout')) { @socket_set_timeout($fp, $timeout); socket_set_blocking($fp, true); } // Get the HTTP response code from CNET $line = fgets($fp , 1024); if ($line == false) { fclose($fp); $this->getDataError = "Fgets error. Did not receive any data back from News Source"; return false; } // HTTP return code of 200 means success if (!(strstr($line, '200'))) { fclose($fp); $this->getDataError = "HTTP error. Did not receive 200 return code from News Source. Instead, received this: $line"; return false; } // Find blank line between header and data do { $line = fgets($fp , 1024); if ($line == false) { fclose($fp); $this->getDataError = "Fgets: did not receive enough data back from News Source"; return false; } if (strlen($line) < 3) { break; } } while (true); $xml=''; // Fetch the data from News Source while ($line = fread($fp, 8192)) { if ($line == false) { fclose($fp); $this->getDataError = "Fread: error reading data from News Source"; return false; } $xml .= $line; } fclose($fp); $this->NewsXML = $xml; return true; // echo '
';
//    echo 'News Response:';
//    echo $this->NewsXML;
//    echo '
'; } function DisplayNewsContent() { $p = xml_parser_create(); xml_parse_into_struct($p, $this->NewsXML, $this->NewsArray, $index); xml_parser_free($p); /* echo '
';
    echo "Index array\n";
    print_r($index);
    echo '
'; echo '
';
    echo "\nVals array\n";
    print_r($values);
    echo '
'; */ $this->NewsHTML .= '
' . $this->strHeaderText . '
'; $this->NewsHTML .= '
'; $newsCnt = 0; foreach ($index as $key=>$val) { if ($key == "ITEM") { $items = $val; for ($i=0; $i < count($items); $i++) { if ($newsCnt == $this->NewsLimit) { break; } if ($this->NewsArray[$items[$i]]['type'] == 'open') { $newsCnt++; $this->ParseTheNews($items[$i]); } } } else { continue; } } if ($this->blnDisplayFooter == TRUE) { $this->NewsHTML .= ''; } $this->NewsHTML .= '
'; $this->NewsHTML .= '
'; } function ParseTheNews($i) { $strSwitch = 0; $title = ''; $tmpTitle = ''; $description = ''; $category = ''; $pubdate = ''; $link = ''; for ($j=$i; $strSwitch < 1; $j++) { if ($j < count($this->NewsArray)) { switch (strtoupper($this->NewsArray[$j]['tag'])) { case 'TITLE': $tmpTitle = $this->NewsArray[$j]['value']; $title = str_replace('_', ' ', $tmpTitle); break; case 'DESCRIPTION': $description = $this->NewsArray[$j]['value']; break; case 'CATEGORY': $category = $this->NewsArray[$j]['value']; break; case 'PUBDATE': $pubdate = $this->NewsArray[$j]['value']; break; case 'LINK': $link = $this->NewsArray[$j]['value']; break; case 'ITEM': if ($this->NewsArray[$j]['type'] == 'close') { $strSwitch = 1; } break; default: break; } } else { $strSwitch = 1; } } $this->NewsHTML .= '
' . $title . '
'; $this->NewsHTML .= '
' . $description . ' more...
'; } } ?>