
cyclenation News Relay
You can add cyclenation news to your website so that your visitors can read the latest cycling news.
There are two ways to do this, depending upon the effect you wish to achieve and your web programming skills. In either case, when visitors click on a news headline, they will be directed to the cyclenation site to read the full story. You can also retrieve individual news stories to display on your own site.
Simple display of news headlines
This involves inserting an iframe into your HTML page. The iframe will show the cyclenation news headlines in bulleted format within the frame.
To use this method, simply insert the following code into your page:
<iframe name="national" src="http://www.cyclenation.org.uk/newsrelay.php" width="360" height="150" frameborder="0"></iframe>
The width and height parameters may be modified to suit, but these are good default values. If the number of headlines is too many to be shown in the iframe, a scroll bar will be displayed. To achieve positioning of the iframe, you may wish to insert it within a table.
Customisable news headlines
If you wish to carry out your own formatting of the news headlines, you may retrieve them as raw data. To do this will require some knowledge of PHP (or a similar server scripting language). Sample code is as below:
<?php
$host = "www.cyclenation.org.uk";
$page = "/newsrelayraw.php";
$fp = fsockopen( "$host", 80);
if ($fp)
{
$request = "GET $page HTTP/1.0\r\n";
$request .= "Host: $host\r\n";
$request .= "Referer: http://www.yourdomain/index.php\r\n"; // INSERT YOUR DOMAIN AND CALLING PAGE HERE
$request .= "User-Agent: PHP client\r\n\r\n";
fputs ( $fp, $request );
$headlines="";
while (!feof ($fp))
{
$line = fgets($fp, 1024);
if ($line[0] == '+')
$headlines = $line;
}
fclose( $fp );
$arLines = explode ("<br>", $headlines);
for ($i=0; $i<count($arLines); $i++)
{
$arFields = explode ("|", $arLines[$i]);
if (strlen($arFields[0]))
echo '<p class="close"><img src="images/redball.gif" border="0"><a href="' . $arFields[2] .
'"> <span class="greenbold">' . $arFields[1] . '</span></a></p>';
}
}
?>
For each news headline, the array arFields contains four fields: an identifier ('+'), the headline text, a full URL to read the story, and the story key. In the example given, the resultant output formats the headline according to locally defined CSS styles ('close' and 'greenbold') and precedes each headline with a local image ('redball.gif').
The story key can be used to retrieve a single story (see below).
Retrieving a single story
This can be achieved in a similar manner to retrieving raw news headlines. Sample code is below:
<?php
$host = "www.cyclenation.org.uk";
$page = "/newsstoryraw.php";
$storyKey = "10"; // INSERT REQUIRED STORY KEY HERE
$fp = fsockopen ("$host", 80);
if ($fp)
{
$request = "GET $page?NKey=$storyKey HTTP/1.0\r\n";
$request .= "Host: $host\r\n";
$request .= "Referer: http://www.yourdomain/index.php\r\n"; // INSERT YOUR DOMAIN AND CALLING PAGE HERE
$request .= "User-Agent: PHP client\r\n\r\n";
fputs ($fp, $request);
$story="";
while (!feof ($fp))
{
$line = fgets ($fp, 16384); // LARGE ENOUGH FOR MOST STORIES
if ($line[0] == '+')
$story = $line;
}
fclose( $fp );
$arFields = explode ("|", $story);
echo '<p>' . $arFields[1] . '</p>'; // display the headline
echo '<p>' . $arFields[2] . '</p>'; // display the story
}
?>
Note that the story is returned with </p><p> pairs at paragraph breaks. You will have to modify these if you wish to apply special formatting.