We do{make} the RSS a tape

I believe, that practically all heard that there are news lines. But it is far from being all sajtovladel`cy use this undoubtedly useful thing. And in fact if you are an owner of a forum or a news site, rss - a piece rather necessary, she will allow your visitors to look through headings of news and to come on a site only for perusal of that it is really necessary for them and interesting. In a word, I have decided to tell shortly whenever possible about how to create the rss-tape, having taken as an example a script made by me for our forum.


For the beginning we give out correct content-type:



header (" content-type: application/rss+xml ");


Then we form heading of a tape:



<? xml version = " 1.0" encoding = "koi8-r"?>

<rss version = " 2.0" xmlns:dc = " http: // purl.org/dc/elements/1.1 / ">

<channel>

<title> recovered.info </title>

<link> http: // recovered.info / </link>

<description> recovered.info forum </description>

<language> ru-ru </language> ';


It is necessary to pay attention to the coding of the document (encoding), and also heading, the description, the link and language. Though, as shows experience, the majority rss-reader'ov shows only the name of a tape, hiding other information.


Further we actually should deduce{remove} a news line. Each recording will consist of heading (title), links (link), descriptions (description) and dates (dc:date). Obligatory parameters are the heading and the link, the rest is possible at desire to lower{omit}. Or, on the contrary, to add a name of the author, a category or still something (see the description of the standard).



<item>

<title> '.htmlspecialchars ($topic_title.) ' </title>

<link> http: // recovered.info/viewtopic.php? p = '. $ post_id. '*'. $ post_id. ' </link>

<description>

topic:

<a href = " http: // recovered.info/viewtopic.php? t = '. $ topic_id. ' "> '.

htmlspecialchars ($topic_title).

' </a>

<br/>

forum:

<a href = " http: // recovered.info/viewforum.php? f = '. $ forum_id. ' "> '.

htmlspecialchars ($forum_name).

' </a>

</description>

<category> '.

htmlspecialchars ($forum_name).

' </category>

<dc:date> '.

strftime (' %y-% m-% dt%h: % m: % s+02:00 ', $last_post_time).

' </dc:date>

</item>


Pay attention to that inside tagov should not meet spec-symbols (<>, etc.). And also on a format of time (yyyy-mm-ddthh:mm:ss+offset.) rather widespread defect of rss-tapes is an incorrect instruction{indication} of time of the publication that results in the big mess in a tape and to inconveniences at reading. By the way speaking, it is possible to specify date and using tag - in this case she should correspond{meet} rfc 822.


After a conclusion of all recordings it is necessary to close a tape only:



</channel>

</rss>


And now we shall see, as the ready script for a conclusion of a tape of messages of the forum using a cursor phpbb looks:



<? php


include (' config.php ');


header (" content-type: application/rss+xml ");


echo ' <? xml version = " 1.0" encoding = "koi8-r"?>

<rss version = " 2.0" xmlns:dc = " http: // purl.org/dc/elements/1.1 / ">

<channel>

<title> recovered.info </title>

<link> http: // recovered.info / </link>

<description> recovered.info forum </description>

<language> ru-ru </language> ';


if (! ($mysql = mysql_connect ($dbhost, $dbuser, $dbpasswd)))

return 0;


if (! ($db = mysql_select_db ($dbname)))

return 0;


$result = mysql_query (' select phpbb_posts.topic_id, max (phpbb_posts.post_id),

phpbb_topics.topic_title, phpbb_forums.forum_name,

max (phpbb_posts.post_time) as last_post_time,

phpbb_forums.forum_id

from phpbb_topics, phpbb_posts, phpbb_forums

where (phpbb_topics.topic_id = phpbb_posts.topic_id) and

(phpbb_topics.forum_id = phpbb_forums.forum_id)

group by phpbb_posts.topic_id

order by last_post_time desc

limit 15 ');


while (list ($topic_id, $post_id, $topic_title,

$forum_name, $last_post_time, $forum_id) = mysql_fetch_row ($result)) {

echo '

<item>

<title> '.htmlspecialchars ($topic_title.) ' </title>

<link> http: // recovered.info/viewtopic.php? p = '. $ post_id. '*'. $ post_id. ' </link>

<description>

topic:

<a href = " http: // recovered.info/viewtopic.php? t = '. $ topic_id. ' "> '.

htmlspecialchars ($topic_title).

' </a>

<br/>

forum:

<a href = " http: // recovered.info/viewforum.php? f = '. $ forum_id. ' "> '.

htmlspecialchars ($forum_name).

' </a>

</description>

<category> '.

htmlspecialchars ($forum_name).

' </category>

<dc:date> '.

strftime (' %y-% m-% dt%h: % m: % s+02:00 ', $last_post_time).

' </dc:date>

</item> ';


} // while - fetch rows


mysql_free_result ($result);


echo '

</channel>

</rss> ';


mysql_close ($mysql);


?>